repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
tango
github_2023
NetEase
typescript
JsViewFile.insertChild
insertChild( targetNodeId: string, newNode: t.JSXElement, position: InsertChildPositionType = 'last', ) { this.ast = appendChildToJSXElement(this.ast, targetNodeId, newNode, position); return this; }
/** * 插入子节点的最后面 * @param targetNodeId * @param newNode * @param position * @returns */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/js-view-file.ts#L361-L368
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
JsViewFile.replaceNode
replaceNode(targetNodeId: string, newNode: t.JSXElement) { this.ast = replaceJSXElement(this.ast, targetNodeId, newNode); return this; }
/** * 替换目标节点为新节点 * @param targetNodeId * @param newNode */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/js-view-file.ts#L385-L388
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
JsViewFile.replaceViewChildren
replaceViewChildren( childrenNodes: t.JSXElement[], importDeclarations?: IImportDeclarationPayload[], ) { if (childrenNodes.length) { this.ast = replaceRootJSXElementChildren(this.ast, childrenNodes); } if (importDeclarations?.length) { importDeclarations.forEach((item) => { t...
/** * 替换 jsx 跟结点的子元素 * @deprecated 不推荐使用 */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/js-view-file.ts#L394-L409
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
SelectSource.selected
get selected() { return toJS(this._items); }
/** * 选中的结点数据 NodeData */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/select-source.ts#L51-L53
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
SelectSource.isSelected
get isSelected() { return !!this.selected.length; }
/** * 是否选中了结点 */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/select-source.ts#L58-L60
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
SelectSource.file
get file(): IViewFile { return this.firstNode?.file; }
/** * 选中结点位于的文件 */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/select-source.ts#L65-L67
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
SelectSource.nodes
get nodes() { return this._items .map((item) => this.workspace.getNode(item.id, item.filename)) .filter((node) => !!node); }
/** * 选中的结点 Nodes */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/select-source.ts#L72-L76
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
SelectSource.add
add() {}
// 增加一个选中项
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/select-source.ts#L98-L98
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
SelectSource.remove
remove() {}
// 移除一个选中项
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/select-source.ts#L101-L101
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
SelectSource.selectParent
selectParent() { const parents = this.first?.parents || []; if (parents.length) { const [parent, ...rest] = parents; this.select({ ...parent, parents: rest, }); } }
/** * 选中当前选中节点的父节点 */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/select-source.ts#L116-L125
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
JsxViewNode.cloneRawNode
cloneRawNode(overrideProps?: Dict) { return cloneJSXElement(this.rawNode, overrideProps); }
/** * 返回克隆后的 ast 节点 * @param overrideProps 额外设置给克隆节点的属性 * @returns */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/core/src/models/view-node.ts#L25-L27
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
handleAdd
const handleAdd = () => { // 提前校验上一个是否有 key const last = data[data.length - 1]; setValidate(true); if (data.length > 0 && !last.key) { return; } counter.current++; const newData = data.concat([{ index: counter.current }]); _updateData(newData); };
// 点击添加的回调
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/components/input-kv.tsx#L72-L87
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
handleDelete
const handleDelete = (index: number, item: any) => { const newData = [...data]; // delete newData.splice(index, 1); _updateData(newData); !newData.length && setValidate(false); };
// 点击删除的回调
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/components/input-kv.tsx#L90-L98
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
renderRow
const renderRow = () => data?.map((item: any, index: number) => ( <> <Box key={item.index} css={rowCss}> <Input allowClear placeholder="请输入 Key" {...keyInputProps} value={item.key} onChange={(ev) => { handleInput('key'...
// render
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/components/input-kv.tsx#L122-L152
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
formatValue
const formatValue = ({ format, data }: IFormatValueConfig) => { if (format === 'original') { if (!data) return [{ index: 0 }]; const list = Array.isArray(data) ? data : Object.keys(data).map((key) => ({ key, value: data[key] })); return list.map((item, idx) => ({ ...item, index: idx - list.l...
// 格式化value
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/components/input-kv.tsx#L185-L199
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
DndQuery.isSeparated
get isSeparated() { if (this.context && 'defaultView' in this.context) { return true; } return false; }
/** * 是否是隔离的沙箱环境,目前仅 iframe 环境为隔离沙箱 */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/dnd/dnd-query.ts#L58-L63
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
DndQuery.window
get window() { if (this.context && 'defaultView' in this.context) { return (this.context as unknown as Document).defaultView; } // 否则返回当前的 window return window; }
/** * 沙箱内的 window 对象 */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/dnd/dnd-query.ts#L68-L74
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
DndQuery.scrollTop
get scrollTop() { if (this.context && 'documentElement' in this.context) { return (this.context as unknown as Document).documentElement.scrollTop; } return 0; }
/** * 沙箱内的全局滚动偏移 */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/dnd/dnd-query.ts#L79-L85
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
DndQuery.getRelativePoint
getRelativePoint(point: MousePoint) { return getRelativePoint(point, this.container); }
/** * 获取相对容器的位置 * @param point */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/dnd/dnd-query.ts#L117-L119
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
DndQuery.getDraggableDescendants
getDraggableDescendants(selector: Selector, descendantSelector: string = DRAGGABLE_SELECTOR) { return this.get(selector).find(descendantSelector).get(); }
/** * 获取可拖拽的子元素 * @param selector * @param locateSelector * @returns */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/dnd/dnd-query.ts#L144-L146
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
DndQuery.getDraggableElementsDataByArea
getDraggableElementsDataByArea(selector: Selector, startPoint: MousePoint, endPoint: MousePoint) { const firstChildElement = this.get(selector) .closest(DRAGGABLE_SELECTOR) .find(DRAGGABLE_SELECTOR) .get(0); if (!firstChildElement) { return []; } let children = this.get(firstChil...
/** * 获得最近的一个可拖拽的父结点的所有子结点 * @param selector * @param startPoint * @returns */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/dnd/dnd-query.ts#L174-L193
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
onScroll
const onScroll = () => { if (!sandboxQuery.context) { return; } if (selectSource.isSelected) { if (timer) { cancelAnimationFrame(timer); } // TIP: 这里根据沙箱的滚动去修正选中框的位置 timer = requestAnimationFrame(() => { // 重新获取选中元素的外观数据 selectSource.selected.forEach((i...
// 目前只有 iframe 的沙箱需要监听
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/dnd/use-dnd.ts#L366-L388
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
getIsActive
const getIsActive = () => isPreview === designer.isPreview;
// 组件不一定会立即刷新,因此 isActive 需要实时获取
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/sandbox/sandbox.tsx#L74-L74
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
pushExternalResources
const pushExternalResources = (list: string[], tokenMap?: { [x: string]: any }) => { const result = list.map((item) => item.replace(/{{(.*?)}}/g, (matched, token) => { return tokenMap?.[token] || matched; }), ); externalResources.push(...result); };
// 追加 umd 资源,并替换 url 中的 token,如版本号等
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/sandbox/sandbox.tsx#L488-L495
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
pushExternals
const pushExternals = (name: string, library?: string) => { if (library) { externals[name] = library; } };
// 追加 externals
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/designer/src/sandbox/sandbox.tsx#L497-L501
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
IFrameProtocol.register
register(): void { if (!this.iframe.contentWindow) { return; } this.iframe.contentWindow.postMessage( { type: 'register-frame', origin: document.location.origin, id: this.channelId, }, this.origin, ); }
// so the iframe can start listening for messages (based on the id)
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/sandbox/src/code-sandbox/iframe-protocol.ts#L42-L55
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
IFrameProtocol.dispatch
dispatch(message: SandpackMessage): void { if (!this.iframe.contentWindow) { return; } this.iframe.contentWindow.postMessage( { $id: this.channelId, codesandbox: true, origin: document.location.origin, ...message, }, this.origin, ); }
// Messages are dispatched from the client directly to the instance iframe
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/sandbox/src/code-sandbox/iframe-protocol.ts#L58-L72
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
IFrameProtocol.globalListen
globalListen(listener: ListenerFunction): UnsubscribeFunction { if (typeof listener !== 'function') { return (): void => { return; }; } const listenerId = this.globalListenersCount; this.globalListeners[listenerId] = listener; this.globalListenersCount++; return (): void => ...
// This is needed for the `initialize` message which comes without a channelId
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/sandbox/src/code-sandbox/iframe-protocol.ts#L76-L89
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
IFrameProtocol.channelListen
channelListen(listener: ListenerFunction): UnsubscribeFunction { if (typeof listener !== 'function') { return (): void => { return; }; } const listenerId = this.channelListenersCount; this.channelListeners[listenerId] = listener; this.channelListenersCount++; return (): void...
// All other messages (eg: from other iframes) are ignored
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/sandbox/src/code-sandbox/iframe-protocol.ts#L93-L106
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
IFrameProtocol.eventListener
private eventListener(evt: MessageEvent): void { // skip events originating from different iframes if (evt.source !== this.iframe.contentWindow) { return; } const message = evt.data; if (!message.codesandbox) { return; } Object.values(this.globalListeners).forEach((listener) =>...
// Handles message windows coming from iframes
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/sandbox/src/code-sandbox/iframe-protocol.ts#L109-L127
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
CodeSandbox.updateFiles
setupFrame = (el: HTMLIFrameElement) => { if (el) { this.iframe = el; this.manager = new Manager( el, { files: createMissingPackageJSON( this.props.files, this.props.dependencies, this.props.entry, ), template: this.props...
// 当给 HTML 元素添加 ref 属性时,ref 回调接收了底层的 DOM 元素作为参数
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/sandbox/src/code-sandbox/index.tsx
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
getShowToggleCodeButton
function getShowToggleCodeButton(disableVariableSetter = options.disableVariableSetter) { if (setterType === 'code') { // codeSetter 无需切换按钮 return false; } // 如果用户设置了 disableVariableSetter,则不显示切换按钮 return !disableVariableSetter; }
// 设置器的模式
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/setting-form/src/form-item.tsx#L169-L176
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
injectStyleToBody
const injectStyleToBody = () => { const id = 'react-draggable-transparent-selection'; if (document.getElementById(id)) { return; } const style = document.createElement('style'); style.id = id; style.innerHTML = ` /* Prevent iframes from stealing drag events */ .react-draggable-transparent-selection ...
// Dragging over an iframe stops dragging when moving the mouse too fast #613
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/ui/src/drag-panel.tsx#L10-L24
c48a49961a3b0e8b49f8a617d893e0b4f047147f
tango
github_2023
NetEase
typescript
buildAutoComplete
function buildAutoComplete(scope: any = window, customOptions: Array<{ label: string }> = []) { /** * @see context https://codemirror.net/docs/ref/#autocomplete.CompletionContext */ return function completeFromGlobalScope(context: CompletionContext) { const nodeBefore = syntaxTree(context.state).resolveIn...
/** * * @param scope 预测的补全上下文 * @param customOptions 自定义补全选项列表 * @returns */
https://github.com/NetEase/tango/blob/c48a49961a3b0e8b49f8a617d893e0b4f047147f/packages/ui/src/input-code.tsx#L52-L99
c48a49961a3b0e8b49f8a617d893e0b4f047147f
CMSaasStarter
github_2023
CriticalMoments
typescript
authGuard
const authGuard: Handle = async ({ event, resolve }) => { const { session, user } = await event.locals.safeGetSession() event.locals.session = session event.locals.user = user return resolve(event) }
// Not called for prerendered marketing pages so generally okay to call on ever server request
https://github.com/CriticalMoments/CMSaasStarter/blob/38831593b8f0327fc23474512e1097da72cd09b7/src/hooks.server.ts#L89-L95
38831593b8f0327fc23474512e1097da72cd09b7
bedrock-claude-chat
github_2023
aws-samples
typescript
Frontend.getDomainZoneName
private getDomainZoneName(domainName: string): string { const parts = domainName.split('.'); if (parts.length <= 2) return domainName; return parts.slice(-2).join('.'); }
/** * Extracts the parent domain from a full domain name * e.g., 'chat.example.com' -> 'example.com' */
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/cdk/lib/constructs/frontend.ts#L158-L162
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
Frontend.shouldSkipAccessLogging
private shouldSkipAccessLogging(): boolean { const skipLoggingRegions = [ "af-south-1", "ap-east-1", "ap-south-2", "ap-southeast-3", "ap-southeast-4", "ca-west-1", "eu-south-1", "eu-south-2", "eu-central-2", "il-central-1", "me-central-1", ]; ...
/** * CloudFront does not support access log delivery in the following regions * @see https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html#access-logs-choosing-s3-bucket */
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/cdk/lib/constructs/frontend.ts#L252-L267
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
onResize
const onResize = () => { if (isMobile) { return; } // 狭い画面のDrawerが表示されていて、画面サイズが大きくなったら状態を更新 if (!smallDrawer.current?.checkVisibility() && opened) { switchOpen(); } };
// リサイズイベントを拾って状態を更新する
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/components/ChatListDrawer.tsx#L273-L282
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
handleClickOutside
const handleClickOutside = (event: any) => { // メニューボタンとメニュー以外をクリックしていたらメニューを閉じる if ( menuRef.current && !menuRef.current.contains(event.target) && !buttonRef.current?.contains(event.target) ) { setIsOpen(false); } };
// メニューの外側をクリックした際のハンドリング
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/components/Menu.tsx#L25-L34
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
pushNewMessage
const pushNewMessage = ( parentMessageId: string | null, messageContent: MessageContent ) => { pushMessage( conversationId ?? '', parentMessageId, NEW_MESSAGE_ID.USER, messageContent ); pushMessage( conversationId ?? '', NEW_MESSAGE_ID.USER, NEW_MESSAGE_ID...
// 画面に即時反映させるために、Stateを更新する処理
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/hooks/useChat.ts#L295-L323
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
continueGenerate
const continueGenerate = (params?: { messageId?: string; bot?: BotInputType; }) => { setPostingMessage(true); const messageContent: MessageContent = { content: [], model: getPostedModel(), role: 'user', feedback: null, usedChunks: null, thinkingLog: null, }; ...
/** * Continue to generate */
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/hooks/useChat.ts#L472-L518
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
regenerate
const regenerate = (props?: { content?: string; messageId?: string; bot?: BotInputType; }) => { let index: number = -1; // messageIdが指定されている場合は、指定されたメッセージをベースにする if (props?.messageId) { index = messages.findIndex((m) => m.id === props.messageId); } // 最新のメッセージがUSERの場合は、エラーとして処理す...
/** * 再生成 * @param props content: 内容を上書きしたい場合に設定 messageId: 再生成対象のmessageId botId: ボットの場合は設定する */
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/hooks/useChat.ts#L524-L618
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
fetcfWithParams
const fetcfWithParams = ([url, params]: [string, Record<string, any>]) => { return api .get(url, { params, }) .then((res) => res.data); };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/hooks/useHttp.ts#L27-L33
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
useHttp
const useHttp = () => { // const alert = useAlertSnackbar(); return { /** * GET Request * Implemented with SWR * @param url * @returns */ // eslint-disable-next-line @typescript-eslint/no-explicit-any get: <Data = any, Error = any>( url: string | [string, ...unknown[]] | ...
// const getErrorMessage = (error: AxiosError<any>): string => {
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/hooks/useHttp.ts#L45-L209
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
bedrock-claude-chat
github_2023
aws-samples
typescript
usePreviousBotId
const usePreviousBotId = (botId: string | null | undefined) => { const ref = useRef<string | null | undefined>(); useEffect(() => { ref.current = botId; }, [botId]); return ref.current; };
// Store the Previous BotId
https://github.com/aws-samples/bedrock-claude-chat/blob/1c2c365ee0a7ada8cf430b6bbdae651abcad4985/frontend/src/hooks/useModel.ts#L42-L50
1c2c365ee0a7ada8cf430b6bbdae651abcad4985
rivet
github_2023
paradigmxyz
typescript
AccountsChangedEmitter
function AccountsChangedEmitter() { const { account, getAccounts } = useAccountStore() const { sessions } = useSessionsStore() const prevAccounts = useRef<AccountState['accounts']>() useEffect(() => { if (!account) { prevAccounts.current = [] return } let accounts_ = getAccounts({ rpcU...
/** Emits EIP-1193 `accountsChanged` Event */
https://github.com/paradigmxyz/rivet/blob/65d03c76decdae0ac08157c907ad9f158a096f76/src/app.tsx#L179-L206
65d03c76decdae0ac08157c907ad9f158a096f76
rivet
github_2023
paradigmxyz
typescript
NetworkChangedEmitter
function NetworkChangedEmitter() { const { network } = useNetworkStore() const { sessions } = useSessionsStore() const prevNetwork = useRef<NetworkState['network']>() useEffect(() => { if (!network.chainId) return if (prevNetwork.current && prevNetwork.current.chainId !== network.chainId) inpage...
/** Emits EIP-1193 `chainChanged` Event */
https://github.com/paradigmxyz/rivet/blob/65d03c76decdae0ac08157c907ad9f158a096f76/src/app.tsx#L209-L227
65d03c76decdae0ac08157c907ad9f158a096f76
rivet
github_2023
paradigmxyz
typescript
SyncBlockNumber
function SyncBlockNumber() { const { data: block } = usePendingBlock() useSnapshot({ blockNumber: block?.number }) return null }
/** Keeps block number in sync. */
https://github.com/paradigmxyz/rivet/blob/65d03c76decdae0ac08157c907ad9f158a096f76/src/app.tsx#L230-L234
65d03c76decdae0ac08157c907ad9f158a096f76
rivet
github_2023
paradigmxyz
typescript
SyncJsonRpcAccounts
function SyncJsonRpcAccounts() { const { data: chainId } = useNetworkStatus() const client = useClient() const { getAccounts, setJsonRpcAccounts } = useAccountStore() useEffect(() => { ;(async () => { const addresses = await client.getAddresses() setJsonRpcAccounts({ addresses, rpcUrl: client.r...
/** Keeps accounts in sync with network. */
https://github.com/paradigmxyz/rivet/blob/65d03c76decdae0ac08157c907ad9f158a096f76/src/app.tsx#L237-L250
65d03c76decdae0ac08157c907ad9f158a096f76
rivet
github_2023
paradigmxyz
typescript
SyncNetwork
function SyncNetwork() { const client = useClient() const { data: listening } = useNetworkStatus() const prevListening = usePrevious(listening) useEffect(() => { // Reset stale queries that are dependent on the client when node comes back online. if (prevListening === false && listening) { queryC...
/** Keeps network in sync (+ ensure chain id is up-to-date). */
https://github.com/paradigmxyz/rivet/blob/65d03c76decdae0ac08157c907ad9f158a096f76/src/app.tsx#L253-L270
65d03c76decdae0ac08157c907ad9f158a096f76
rivet
github_2023
paradigmxyz
typescript
execute
async function execute(rpcClient: HttpRpcClient, request: RpcRequest) { // Anvil doesn't support `personal_sign` – use `eth_sign` instead. if (request.method === 'personal_sign') { request.method = 'eth_sign' as any request.params = [request.params[1], request.params[0]] } const response = (await (() =...
/////////////////////////////////////////////////////////////////////////////////
https://github.com/paradigmxyz/rivet/blob/65d03c76decdae0ac08157c907ad9f158a096f76/src/entries/background/rpc.ts#L288-L323
65d03c76decdae0ac08157c907ad9f158a096f76
rivet
github_2023
paradigmxyz
typescript
getContractAbi
function getContractAbi({ contracts, contract, }: { contract: Partial<Contract>; contracts: ContractsState['contracts'] }) { if (contract.abi) return contract const allContracts = Object.values(contracts).flat() const contracts_ = allContracts.filter( (c) => c?.abi && c.bytecode && cont...
///////////////////////////////////////////////////////////////
https://github.com/paradigmxyz/rivet/blob/65d03c76decdae0ac08157c907ad9f158a096f76/src/zustand/contracts.ts#L217-L237
65d03c76decdae0ac08157c907ad9f158a096f76
cosmo
github_2023
wundergraph
typescript
getLatestPRCommit
function getLatestPRCommit(): string | undefined { try { const event = process.env.GITHUB_EVENT_PATH ? JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')) : undefined; if (event && event.pull_request) { return event.pull_request.head.sha; } } catch { return undefined; ...
// https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/cli/src/github.ts#L10-L22
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
prepare
const prepare = () => { // resets e.g. ProxyAgent mock state between describes vi.resetModules(); vi.resetAllMocks(); delete process.env.HTTPS_PROXY; delete process.env.HTTP_PROXY; };
// ensure all env variables and spies are cleaned up after each test
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/cli/test/proxy.test.ts#L26-L33
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
replaceType
function replaceType<T extends GraphQLType>(type: T): T { if (isListType(type)) { // @ts-expect-error return new GraphQLList(replaceType(type.ofType)); } if (isNonNullType(type)) { // @ts-expect-error return new GraphQLNonNull(replaceType(type.ofType)); } // @ts-expect-error ...
// Below are functions used for producing this schema that have closed over
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/buildASTSchema/extendSchema.ts#L283-L294
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
getDeprecationReason
function getDeprecationReason( node: EnumValueDefinitionNode | FieldDefinitionNode | InputValueDefinitionNode, ): Maybe<string> { const deprecated = getDirectiveValues(GraphQLDeprecatedDirective, node); // @ts-expect-error validated by `getDirectiveValues` return deprecated?.reason; }
/** * Given a field or enum value node, returns the string value for the * deprecation reason. */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/buildASTSchema/extendSchema.ts#L715-L721
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
getSpecifiedByURL
function getSpecifiedByURL(node: ScalarTypeDefinitionNode | ScalarTypeExtensionNode): Maybe<string> { const specifiedBy = getDirectiveValues(GraphQLSpecifiedByDirective, node); // @ts-expect-error validated by `getDirectiveValues` return specifiedBy?.url; }
/** * Given a scalar node, returns the string value for the specifiedByURL. */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/buildASTSchema/extendSchema.ts#L726-L730
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FederationFactory.upsertInputValueData
upsertInputValueData( inputValueDataByValueName: Map<string, InputValueData>, incomingData: InputValueData, path?: string, ) { const existingData = inputValueDataByValueName.get(incomingData.name); const baseData = existingData || incomingData; extractPersistedDirectives( baseData.persis...
// To facilitate the splitting of tag paths, field arguments do not use the renamedPath property for tagNamesByPath
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/federation/federation-factory.ts#L587-L637
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FederationFactory.federateInternalSubgraphData
federateInternalSubgraphData() { let subgraphNumber = 0; let shouldSkipPersistedExecutableDirectives = false; for (const internalSubgraph of this.internalSubgraphBySubgraphName.values()) { subgraphNumber += 1; this.currentSubgraphName = internalSubgraph.name; this.isVersionTwo ||= internal...
/* federateInternalSubgraphData is responsible for merging each subgraph TypeScript representation of a GraphQL type * into a single representation. * This method is always necessary, regardless of whether federating a source graph or contract graph. * */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/federation/federation-factory.ts#L1357-L1387
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
NormalizationFactory.getAuthorizationData
getAuthorizationData(node: InterfaceTypeNode | ObjectTypeNode): AuthorizationData | undefined { const parentTypeName = this.renamedParentTypeName || this.originalParentTypeName; let authorizationData = this.authorizationDataByParentTypeName.get(parentTypeName); resetAuthorizationData(authorizationData); ...
// Note that directive validation errors are handled elsewhere
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/normalization/normalization-factory.ts#L479-L557
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
NormalizationFactory.getNodeExtensionType
getNodeExtensionType( isRealExtension: boolean, directivesByDirectiveName: Map<string, ConstDirectiveNode[]>, isRootType = false, ): ExtensionType { // If the extend keyword is present, it's simply an extension if (isRealExtension) { return ExtensionType.REAL; } /* * @extends is...
/* ExtensionType uses a trichotomy rather than a boolean because @extends is still a definition. * A definition and another definition with @extends would still be an error, so it cannot be treated * as a regular extension. * V1 definitions with @extends need a base type. */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/normalization/normalization-factory.ts#L871-L891
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
NormalizationFactory.addDirectiveDefinitionDataByNode
addDirectiveDefinitionDataByNode(node: DirectiveDefinitionNode): boolean { const name = node.name.value; if (this.definedDirectiveNames.has(name)) { this.errors.push(duplicateDirectiveDefinitionError(name)); return false; } this.definedDirectiveNames.add(name); this.directiveDefinitionBy...
// returns true if the directive is custom; otherwise, false
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/normalization/normalization-factory.ts#L1124-L1158
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
Graph.visitEdge
visitEdge(edge: Edge, fieldPath: string): boolean { if (edge.isInaccessible || edge.node.isInaccessible) { return false; } if (!add(edge.visitedIndices, this.walkerIndex) || edge.node.isLeaf) { return true; } if (edge.node.isAbstract) { this.validateAbstractNode(edge.node, `${field...
// Returns true if the edge is visited and false otherwise (e.g., inaccessible)
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/resolvability-graph/graph.ts#L293-L306
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
Walker.visitEntityRelatedEdge
visitEntityRelatedEdge(edge: Edge, fieldPath: string) { if (edge.isInaccessible || edge.node.isInaccessible) { return false; } if (!add(edge.visitedIndices, this.walkerIndex) || edge.node.isLeaf) { return true; } if (edge.node.hasEntitySiblings) { getValueOrDefault( this.en...
// Returns true if the edge is visited and false if it's inaccessible
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/composition/src/resolvability-graph/graph.ts#L430-L451
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
AuthUtils.logout
logout(res: FastifyReply, idToken: string) { const authorizationUrl = new URL(this.opts.oauth.openIdFrontendUrl + '/protocol/openid-connect/logout'); authorizationUrl.searchParams.set('id_token_hint', idToken); authorizationUrl.searchParams.set('post_logout_redirect_uri', this.opts.oauth.logoutRedirectUri);...
// https://www.keycloak.org/docs/latest/upgrading/index.html#openid-connect-logout
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/auth-utils.ts#L59-L64
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
AuthUtils.renewSession
public async renewSession(req: FastifyRequest, res: FastifyReply) { // Will throw an error if the cookie is invalid or not present const { sessionId } = await this.parseUserSessionCookie(req); const userSessions = await this.db.select().from(sessions).where(eq(sessions.id, sessionId)).limit(1).execute(); ...
/** * renewSession renews the user session if the access token is expired. * If the refresh token is expired, an error is thrown. */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/auth-utils.ts#L294-L358
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient.constructor
constructor(private options?: ClickHouseClientOptions) { this.options = this.options ? Object.assign(new ClickHouseClientOptions(), this.options) : new ClickHouseClientOptions(); if (!this.options.dsn) { throw new Error('ClickHouse DSN is required'); } const url = new URL(this.option...
/** * ClickHouse Service */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L32-L45
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._validateInsert
private _validateInsert<T = any>(table: string, data: T[]) { // validate table if (!table || table.trim() === '') { throw new Error('Table name is required'); } // validate data array if (!Array.isArray(data)) { throw new TypeError('Data must be an array'); } if (Array.isArray(...
/** * Validate insert parameters */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L50-L64
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._validateQuery
private _validateQuery<T = any>(query: string) { if (this.options?.format && !Object.values(ClickHouseDataFormat).includes(this.options.format)) { throw new Error(`${this.options?.format} is not supported.`); } // validate query if (!query || query.trim() === '') { throw new Error('Query is...
/** * Validate query parameters */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L69-L78
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._handleObservableError
private _handleObservableError<T>(reason: AxiosError<any>, subscriber?: Subscriber<T>) { if (reason && reason.response) { let err = ''; reason.response.data .on('data', (chunk: any) => { err += chunk.toString('utf8'); }) .on('end', () => { this.options?.logge...
/** * Handle ClickHouse HTTP errors (for Observable) */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L83-L107
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._handlePromiseError
private _handlePromiseError<T>(reason: AxiosError<any>) { if (reason && reason.response) { this.options?.logger?.error(reason.response.data); } else { this.options?.logger?.error(reason); } }
/** * Handle ClickHouse HTTP errors (for Promise) */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L112-L118
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._getRequestOptions
private _getRequestOptions( query: string, queryParams: Record<string, string | number | boolean> = {}, withoutFormat = false, ): AxiosRequestConfig<any> { if (!withoutFormat) { query = `${query.trimEnd()} FORMAT ${this.options?.format}`; } const rawParams: Record<string, string> = { ...
/** * Prepare request options */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L123-L155
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._getHeaders
private _getHeaders() { const headers: { 'Accept-Encoding'?: 'gzip' | 'deflate' | 'br' } = {}; switch (this.options?.httpConfig?.compression) { case ClickHouseCompressionMethod.GZIP: { headers['Accept-Encoding'] = 'gzip'; break; } case ClickHouseCompressionMethod.DEFLATE: { ...
/** * Prepare headers for request */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L160-L178
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._queryPromise
private _queryPromise<T = string>(query: string, params?: Record<string, string | number | boolean>) { return new Promise<T extends string ? string | T[] : T[]>((resolve, reject) => { axios .request({ ...this._getRequestOptions(query, params), responseType: 'text', }) ...
/** * Promise based query * @private */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L184-L209
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient._queryObservable
private _queryObservable<T = any>(query: string, params?: Record<string, string | number>) { return new Observable<T | string>((subscriber) => { axios .request(this._getRequestOptions(query, params)) .then((response) => { const stream: IncomingMessage = response.data; swit...
/** * Observable based query * @private */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L215-L263
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient.query
public query<T = any>(query: string, params?: Record<string, string | number>) { this._validateQuery<T>(query); return this._queryObservable<T>(query, params); }
/** * Observable based query */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L268-L272
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient.queryPromise
public queryPromise<T = any>(query: string, params?: Record<string, string | number | boolean>) { this._validateQuery<T>(query); return this._queryPromise<T>(query, params); }
/** * Promise based query */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L277-L281
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient.insert
public insert<T = any>(table: string, data: T[]) { this._validateInsert<T>(table, data); return new Observable<void>((subscriber) => { let query = `INSERT INTO ${table}`; /** * @todo: data type should not be `any` */ let _data: any; switch (this.options?.format) { ...
/** * Insert data to table (Observable) */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L286-L330
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient.insertPromise
public insertPromise<T = any>(table: string, data: T[]) { this._validateInsert<T>(table, data); return new Promise<void>((resolve, reject) => { this.insert<T>(table, data).subscribe({ error: (error) => { return reject(error); }, next: (row) => { // currently no...
/** * Insert data to table (Promise) */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L335-L353
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClient.ping
public ping(timeout = 30_000) { return new Promise<boolean>((resolve, reject) => { axios .get(`${this.endpoint}/ping`, { timeout, httpAgent: this.options?.httpConfig?.httpAgent, httpsAgent: this.options?.httpConfig?.httpsAgent, }) .then((response) => { ...
/** * Pings the clickhouse server * * @param timeout timeout in milliseconds, defaults to 30000. */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/ClickHouseClient.ts#L360-L379
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
ClickHouseClientOptions.constructor
constructor() { if (this.settings) { this.settings = Object.assign(new ClickHouseSettings(), this.settings); } if (this.httpConfig) { this.httpConfig = Object.assign(new ClickHouseHttpConfig(), this.httpConfig); } }
/** * ClickHouse Connection Options */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/clickhouse/client/interfaces/ClickHouseClientOptions.ts#L136-L144
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
Composer.saveComposition
async saveComposition({ composedGraph, composedById, isFeatureFlagComposition, federatedSchemaVersionId, routerExecutionConfig, featureFlagId, }: { composedGraph: ComposedFederatedGraph; composedById: string; isFeatureFlagComposition: boolean; federatedSchemaVersionId: UUID; ...
/** * Create a new schema version for the composition and stores a diff and changelog between the * previous and current schema as changelog. */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/composition/composer.ts#L442-L507
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
Composer.composeWithProposedSDL
composeWithProposedSDL( subgraphLabels: Label[], subgraphName: string, namespaceId: string, subgraphSchemaSDL: string, ) { return this.composeWithLabels(subgraphLabels, namespaceId, (subgraphs) => { const subgraphsToBeComposed: Array<Subgraph> = []; for (const subgraph of subgraphs) {...
/** * Same as compose, but the proposed schemaSDL of the subgraph is not updated to the table, so it is passed to the function */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/composition/composer.ts#L602-L629
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
AuditLogRepository.addAuditLog
public addAuditLog(...inputs: AddAuditLogInput[]) { return this.db .insert(schema.auditLogs) .values( inputs.map((input) => ({ organizationId: input.organizationId, actorId: input.actorId, targetId: input.targetId, targetType: input.targetType, t...
/** * Add a new audit log entry. * Schema: {Actor} do {Action} on {Target *Optional*} + {With Auditable information} */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/AuditLogRepository.ts#L33-L54
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
CacheWarmerRepository.deleteComputedCacheWarmerOperations
public async deleteComputedCacheWarmerOperations({ organizationId, federatedGraphId, }: { organizationId: string; federatedGraphId: string; }) { await this.db .delete(cacheWarmerOperations) .where( and( eq(cacheWarmerOperations.organizationId, organizationId), ...
// The manually added ones will not be deleted.
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/CacheWarmerRepository.ts#L412-L428
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
DiscussionRepository.deleteComment
public async deleteComment(input: { discussionId: string; commentId: string }): Promise<{ success: boolean }> { const discussion = await this.db.query.discussions.findFirst({ where: eq(schema.discussions.id, input.discussionId), with: { thread: { limit: 1, orderBy: asc(schema...
/* Deleting the opening comment, results in the discussion being deleted. Deleting a reply in the thread only soft deletes that comment. */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/DiscussionRepository.ts#L161-L192
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getBaseSubgraphByFeatureSubgraphId
public async getBaseSubgraphByFeatureSubgraphId({ id }: { id: string }): Promise<SubgraphDTO | undefined> { const baseSubgraph = await this.db .select({ subgraphId: featureSubgraphsToBaseSubgraphs.baseSubgraphId, }) .from(featureSubgraphsToBaseSubgraphs) .where(eq(featureSubgraphsToB...
// returns the base subgraph based on the feature subgraph id
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L423-L437
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureSubgraphsByBaseSubgraphId
public getFeatureSubgraphsByBaseSubgraphId({ baseSubgraphId }: { baseSubgraphId: string }) { return this.db .select({ id: featureSubgraphsToBaseSubgraphs.featureSubgraphId, }) .from(featureSubgraphsToBaseSubgraphs) .where(eq(featureSubgraphsToBaseSubgraphs.baseSubgraphId, baseSubgrap...
// returns all the feature subgraph ids associated with the base subgraph
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L440-L447
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.deleteFeatureSubgraphsByBaseSubgraphId
public deleteFeatureSubgraphsByBaseSubgraphId({ subgraphId, namespaceId, }: { subgraphId: string; namespaceId: string; }) { return this.db.transaction(async (tx) => { const subgraphRepo = new SubgraphRepository(this.logger, tx, this.organizationId); const ffs = await tx .sele...
// deletes all the feature subgraphs associated with the base subgraph
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L450-L487
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureFlagsByFederatedGraph
public async getFeatureFlagsByFederatedGraph({ namespaceId, federatedGraph, }: { namespaceId: string; federatedGraph: FederatedGraphDTO; }): Promise<FeatureFlagDTO[]> { const fetaureFlags: FeatureFlagDTO[] = []; const subgraphRepo = new SubgraphRepository(this.logger, this.db, this.organizat...
// returns all the feature flags associated with the federated graph
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L490-L527
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFederatedGraphsByFeatureFlag
public async getFederatedGraphsByFeatureFlag({ featureFlagId, namespaceId, excludeDisabled, includeContracts, }: { featureFlagId: string; namespaceId: string; excludeDisabled: boolean; includeContracts?: boolean; }): Promise<FederatedGraphDTO[]> { const federatedGraphs: Federated...
// returns all the federated graphs associated with the feature flag
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L530-L582
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getMatchedFeatureFlags
public getMatchedFeatureFlags({ namespaceId, fedGraphLabelMatchers, excludeDisabled, }: { namespaceId: string; fedGraphLabelMatchers: string[]; excludeDisabled: boolean; }) { const groupedLabels: Label[][] = []; for (const lm of fedGraphLabelMatchers) { const labels = lm.split(...
// returns all the feature flags which match the federated graph's label matchers
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L585-L630
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureFlagsByBaseSubgraphId
public async getFeatureFlagsByBaseSubgraphId({ baseSubgraphId, namespaceId, excludeDisabled, }: { baseSubgraphId: string; namespaceId: string; excludeDisabled: boolean; }) { const conditions: SQL<unknown>[] = [ eq(featureSubgraphsToBaseSubgraphs.baseSubgraphId, baseSubgraphId), ...
// returns all the feature flags which contain feature subgraphs whose base subgraph is the same as the input base subgraph
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L633-L673
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureSubgraphsByFeatureFlagId
public async getFeatureSubgraphsByFeatureFlagId({ featureFlagId, namespaceId, }: { featureFlagId: string; namespaceId: string; }): Promise<FeatureSubgraphDTO[]> { const subgraphRepo = new SubgraphRepository(this.logger, this.db, this.organizationId); const fgs = await this.db .select({...
// input: feature flag id, namespace id
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L677-L759
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureFlagsByBaseSubgraphIdAndLabelMatchers
public async getFeatureFlagsByBaseSubgraphIdAndLabelMatchers({ baseSubgraphId, namespaceId, baseSubgraphNames, fedGraphLabelMatchers, excludeDisabled, }: { baseSubgraphId: string; namespaceId: string; baseSubgraphNames: string[]; fedGraphLabelMatchers: string[]; excludeDisabled...
// evaluates all the feature flags which have fgs whose base subgraph id and fed graph label matchers are passed as input and returns the feature flags that should be composed
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L762-L821
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getSubgraphsToCompose
public async getSubgraphsToCompose({ baseSubgraphs, fedGraphLabelMatchers, baseCompositionSubgraphs, }: { baseSubgraphs: SubgraphDTO[]; fedGraphLabelMatchers: string[]; baseCompositionSubgraphs: Subgraph[]; }): Promise<Array<SubgraphsToCompose>> { // Always include the base graph con...
/* Returns an array of subgraphs to compose into a federated graph * At least one of the constituent subgraphs are impacted by a change including any feature flags * */
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L859-L901
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureFlagCompositionsByBaseSchemaVersion
public async getFeatureFlagCompositionsByBaseSchemaVersion({ baseSchemaVersionId, namespaceId, }: { baseSchemaVersionId: string; namespaceId: string; }) { const featureFlagCompositions: FeatureFlagCompositionDTO[] = []; const compositions = await this.db .select({ id: graphComp...
// input: base schema version id, namespace id
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L905-L962
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureFlagSchemaVersionsByBaseSchemaVersion
public async getFeatureFlagSchemaVersionsByBaseSchemaVersion({ baseSchemaVersionId, }: { baseSchemaVersionId: string; }) { const ffSchemaVersions = await this.db .select({ id: federatedGraphsToFeatureFlagSchemaVersions.composedSchemaVersionId, featureFlagId: federatedGraphsToFeatur...
// input: base schema version id
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L966-L985
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FeatureFlagRepository.getFeatureFlagSchemaVersionByBaseSchemaVersion
public async getFeatureFlagSchemaVersionByBaseSchemaVersion({ baseSchemaVersionId, featureFlagId, }: { baseSchemaVersionId: string; featureFlagId: string; }) { const schemaVersion = await this.db .select({ id: federatedGraphsToFeatureFlagSchemaVersions.composedSchemaVersionId, ...
// input: base schema version id and feature flag id
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FeatureFlagRepository.ts#L989-L1017
40cfc416cc2869546b08978e922dabf4276964cc
cosmo
github_2023
wundergraph
typescript
FederatedGraphRepository.count
public async count(): Promise<number> { const result = await this.db .select({ count: sql<number>`cast(count( ${targets.id} ) as int )`, }) .from(schema.targets) .where(and(eq(schema.targets.type, 'federated'), eq(schema.targets.organizationId,...
// Returns count of federated graphs across all namespaces
https://github.com/wundergraph/cosmo/blob/40cfc416cc2869546b08978e922dabf4276964cc/controlplane/src/core/repositories/FederatedGraphRepository.ts#L497-L512
40cfc416cc2869546b08978e922dabf4276964cc