@instantdb/core 0.22.58 → 0.22.59-experimental.drewh-explorer-export.19553074787.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,10 +44,12 @@ class WSConnection {
44
44
  this.conn.close();
45
45
  }
46
46
  isOpen() {
47
- return this.conn.readyState === WebSocket.OPEN;
47
+ var _a;
48
+ return this.conn.readyState === ((_a = WebSocket.OPEN) !== null && _a !== void 0 ? _a : 1);
48
49
  }
49
50
  isConnecting() {
50
- return this.conn.readyState === WebSocket.CONNECTING;
51
+ var _a;
52
+ return this.conn.readyState === ((_a = WebSocket.CONNECTING) !== null && _a !== void 0 ? _a : 0);
51
53
  }
52
54
  send(msg) {
53
55
  return this.conn.send(JSON.stringify(msg));
@@ -1 +1 @@
1
- {"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;;;;;;;;;;AAkBA,IAAI,OAAO,GAAG,CAAC,CAAC;AA+ChB,MAAa,YAAY;IAQvB,YAAY,GAAW;QAPvB,SAAI,GAAkB,IAAI,CAAC;QAQzB,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,EAAE;YACxB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAChC,CAAC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,EAAE;YAC1B,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACnB,IAAI,CAAC,SAAS,CAAC;oBACb,MAAM,EAAE,IAAI;oBACZ,OAAO,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AK,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,CACpE,CAAC;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;CACF;AA1ID,sCA0IC","sourcesContent":["export interface EventSourceType {\n readonly url: string;\n readonly readyState: number;\n\n onopen: ((this: EventSourceType, ev: Event) => any) | null;\n onmessage: ((this: EventSourceType, ev: MessageEvent) => any) | null;\n onerror: ((this: EventSourceType, ev: Event) => any) | null;\n\n close(): void;\n}\n\nexport interface EventSourceConstructor {\n OPEN: number;\n CONNECTING: number;\n CLOSED: number;\n new (url: string): EventSourceType;\n}\n\nlet _connId = 0;\n\ntype Conn = EventSourceType | WebSocket;\n\ntype OpenEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ntype MessageData = {\n op: string;\n [key: string]: any;\n};\n\ntype SendMessageData = {\n 'client-event-id': string;\n [key: string]: any;\n};\n\ntype MsgEvent<T extends Conn> = {\n target: Connection<T>;\n message: MessageData;\n};\n\ntype CloseEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ninterface ErrorEvent<T extends Conn> {\n target: Connection<T>;\n}\n\nexport type TransportType = 'ws' | 'sse';\n\nexport interface Connection<T extends Conn> {\n conn: T;\n type: 'ws' | 'sse';\n id: string;\n close(): void;\n isOpen(): boolean;\n isConnecting(): boolean;\n send(msg: SendMessageData): void;\n onopen: ((event: OpenEvent<T>) => void) | null;\n onmessage: ((event: MsgEvent<T>) => void) | null;\n onclose: ((event: CloseEvent<T>) => void) | null;\n onerror: ((event: ErrorEvent<T>) => void) | null;\n}\n\nexport class WSConnection implements Connection<WebSocket> {\n type: TransportType = 'ws';\n conn: WebSocket;\n id: string;\n onopen: (event: OpenEvent<WebSocket>) => void;\n onmessage: (event: MsgEvent<WebSocket>) => void;\n onclose: (event: CloseEvent<WebSocket>) => void;\n onerror: (event: ErrorEvent<WebSocket>) => void;\n constructor(url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.conn = new WebSocket(url);\n this.conn.onopen = (_e) => {\n if (this.onopen) {\n this.onopen({ target: this });\n }\n };\n this.conn.onmessage = (e) => {\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: JSON.parse(e.data.toString()),\n });\n }\n };\n this.conn.onclose = (_e) => {\n if (this.onclose) {\n this.onclose({ target: this });\n }\n };\n this.conn.onerror = (_e) => {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n };\n }\n\n close() {\n this.conn.close();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === WebSocket.OPEN;\n }\n\n isConnecting(): boolean {\n return this.conn.readyState === WebSocket.CONNECTING;\n }\n\n send(msg: SendMessageData) {\n return this.conn.send(JSON.stringify(msg));\n }\n}\n\ntype SSEInitParams = {\n machineId: string;\n sessionId: string;\n sseToken: string;\n};\n\nexport class SSEConnection implements Connection<EventSourceType> {\n type: TransportType = 'sse';\n private initParams: SSEInitParams | null = null;\n private sendQueue: any[] = [];\n private sendPromise: Promise<void> | null;\n private closeFired: boolean = false;\n private sseInitTimeout: NodeJS.Timeout | null = null;\n private ES: EventSourceConstructor;\n conn: EventSourceType;\n url: string;\n id: string;\n onopen: (event: OpenEvent<EventSourceType>) => void;\n onmessage: (event: MsgEvent<EventSourceType>) => void;\n onclose: (event: CloseEvent<EventSourceType>) => void;\n onerror: (event: ErrorEvent<EventSourceType>) => void;\n\n constructor(ES: EventSourceConstructor, url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.url = url;\n this.ES = ES;\n this.conn = new ES(url);\n\n // Close the connection if we didn't get an init within 10 seconds\n this.sseInitTimeout = setTimeout(() => {\n if (!this.initParams) {\n this.handleError();\n }\n }, 10000);\n\n this.conn.onmessage = (e) => {\n const msg = JSON.parse(e.data);\n if (msg.op === 'sse-init') {\n this.initParams = {\n machineId: msg['machine-id'],\n sessionId: msg['session-id'],\n sseToken: msg['sse-token'],\n };\n if (this.onopen) {\n this.onopen({ target: this });\n }\n clearTimeout(this.sseInitTimeout);\n return;\n }\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: msg,\n });\n }\n };\n\n this.conn.onerror = (e) => {\n this.handleError();\n };\n }\n\n // Runs the onerror and closes the connection\n private handleError() {\n try {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n } finally {\n this.handleClose();\n }\n }\n\n private handleClose() {\n this.conn.close();\n if (this.onclose && !this.closeFired) {\n this.closeFired = true;\n this.onclose({ target: this });\n }\n }\n\n private async postMessages(messages: any[]): Promise<void> {\n try {\n const resp = await fetch(this.url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n machine_id: this.initParams.machineId,\n session_id: this.initParams.sessionId,\n sse_token: this.initParams.sseToken,\n messages,\n }),\n });\n if (!resp.ok) {\n this.handleError();\n }\n } catch (e) {\n this.handleError();\n }\n }\n\n private async flushQueue() {\n if (this.sendPromise || !this.sendQueue.length) return;\n\n const messages = this.sendQueue;\n this.sendQueue = [];\n const sendPromise = this.postMessages(messages);\n this.sendPromise = sendPromise;\n sendPromise.then(() => {\n this.sendPromise = null;\n this.flushQueue();\n });\n }\n\n send(msg: SendMessageData) {\n if (!this.isOpen() || !this.initParams) {\n if (this.isConnecting()) {\n throw new Error(\n `Failed to execute 'send' on 'EventSource': Still in CONNECTING state.`,\n );\n }\n if (this.conn.readyState === this.ES.CLOSED) {\n throw new Error(`EventSource is already in CLOSING or CLOSED state.`);\n }\n throw new Error(`EventSource is in invalid state.`);\n }\n this.sendQueue.push(msg);\n this.flushQueue();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === this.ES.OPEN && this.initParams !== null;\n }\n\n isConnecting(): boolean {\n return (\n this.conn.readyState === this.ES.CONNECTING ||\n (this.conn.readyState === this.ES.OPEN && this.initParams === null)\n );\n }\n\n close() {\n this.handleClose();\n }\n}\n"]}
1
+ {"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;;;;;;;;;;AAkBA,IAAI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IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAC;YACJ,CAAC;YACD,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACxE,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC;IAC3E,CAAC;IAED,YAAY;QACV,OAAO,CACL,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC,UAAU;YAC3C,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,CACpE,CAAC;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;CACF;AA1ID,sCA0IC","sourcesContent":["export interface EventSourceType {\n readonly url: string;\n readonly readyState: number;\n\n onopen: ((this: EventSourceType, ev: Event) => any) | null;\n onmessage: ((this: EventSourceType, ev: MessageEvent) => any) | null;\n onerror: ((this: EventSourceType, ev: Event) => any) | null;\n\n close(): void;\n}\n\nexport interface EventSourceConstructor {\n OPEN: number;\n CONNECTING: number;\n CLOSED: number;\n new (url: string): EventSourceType;\n}\n\nlet _connId = 0;\n\ntype Conn = EventSourceType | WebSocket;\n\ntype OpenEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ntype MessageData = {\n op: string;\n [key: string]: any;\n};\n\ntype SendMessageData = {\n 'client-event-id': string;\n [key: string]: any;\n};\n\ntype MsgEvent<T extends Conn> = {\n target: Connection<T>;\n message: MessageData;\n};\n\ntype CloseEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ninterface ErrorEvent<T extends Conn> {\n target: Connection<T>;\n}\n\nexport type TransportType = 'ws' | 'sse';\n\nexport interface Connection<T extends Conn> {\n conn: T;\n type: 'ws' | 'sse';\n id: string;\n close(): void;\n isOpen(): boolean;\n isConnecting(): boolean;\n send(msg: SendMessageData): void;\n onopen: ((event: OpenEvent<T>) => void) | null;\n onmessage: ((event: MsgEvent<T>) => void) | null;\n onclose: ((event: CloseEvent<T>) => void) | null;\n onerror: ((event: ErrorEvent<T>) => void) | null;\n}\n\nexport class WSConnection implements Connection<WebSocket> {\n type: TransportType = 'ws';\n conn: WebSocket;\n id: string;\n onopen: (event: OpenEvent<WebSocket>) => void;\n onmessage: (event: MsgEvent<WebSocket>) => void;\n onclose: (event: CloseEvent<WebSocket>) => void;\n onerror: (event: ErrorEvent<WebSocket>) => void;\n constructor(url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.conn = new WebSocket(url);\n this.conn.onopen = (_e) => {\n if (this.onopen) {\n this.onopen({ target: this });\n }\n };\n this.conn.onmessage = (e) => {\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: JSON.parse(e.data.toString()),\n });\n }\n };\n this.conn.onclose = (_e) => {\n if (this.onclose) {\n this.onclose({ target: this });\n }\n };\n this.conn.onerror = (_e) => {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n };\n }\n\n close() {\n this.conn.close();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === (WebSocket.OPEN ?? 1);\n }\n\n isConnecting(): boolean {\n return this.conn.readyState === (WebSocket.CONNECTING ?? 0);\n }\n\n send(msg: SendMessageData) {\n return this.conn.send(JSON.stringify(msg));\n }\n}\n\ntype SSEInitParams = {\n machineId: string;\n sessionId: string;\n sseToken: string;\n};\n\nexport class SSEConnection implements Connection<EventSourceType> {\n type: TransportType = 'sse';\n private initParams: SSEInitParams | null = null;\n private sendQueue: any[] = [];\n private sendPromise: Promise<void> | null;\n private closeFired: boolean = false;\n private sseInitTimeout: NodeJS.Timeout | null = null;\n private ES: EventSourceConstructor;\n conn: EventSourceType;\n url: string;\n id: string;\n onopen: (event: OpenEvent<EventSourceType>) => void;\n onmessage: (event: MsgEvent<EventSourceType>) => void;\n onclose: (event: CloseEvent<EventSourceType>) => void;\n onerror: (event: ErrorEvent<EventSourceType>) => void;\n\n constructor(ES: EventSourceConstructor, url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.url = url;\n this.ES = ES;\n this.conn = new ES(url);\n\n // Close the connection if we didn't get an init within 10 seconds\n this.sseInitTimeout = setTimeout(() => {\n if (!this.initParams) {\n this.handleError();\n }\n }, 10000);\n\n this.conn.onmessage = (e) => {\n const msg = JSON.parse(e.data);\n if (msg.op === 'sse-init') {\n this.initParams = {\n machineId: msg['machine-id'],\n sessionId: msg['session-id'],\n sseToken: msg['sse-token'],\n };\n if (this.onopen) {\n this.onopen({ target: this });\n }\n clearTimeout(this.sseInitTimeout);\n return;\n }\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: msg,\n });\n }\n };\n\n this.conn.onerror = (e) => {\n this.handleError();\n };\n }\n\n // Runs the onerror and closes the connection\n private handleError() {\n try {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n } finally {\n this.handleClose();\n }\n }\n\n private handleClose() {\n this.conn.close();\n if (this.onclose && !this.closeFired) {\n this.closeFired = true;\n this.onclose({ target: this });\n }\n }\n\n private async postMessages(messages: any[]): Promise<void> {\n try {\n const resp = await fetch(this.url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n machine_id: this.initParams.machineId,\n session_id: this.initParams.sessionId,\n sse_token: this.initParams.sseToken,\n messages,\n }),\n });\n if (!resp.ok) {\n this.handleError();\n }\n } catch (e) {\n this.handleError();\n }\n }\n\n private async flushQueue() {\n if (this.sendPromise || !this.sendQueue.length) return;\n\n const messages = this.sendQueue;\n this.sendQueue = [];\n const sendPromise = this.postMessages(messages);\n this.sendPromise = sendPromise;\n sendPromise.then(() => {\n this.sendPromise = null;\n this.flushQueue();\n });\n }\n\n send(msg: SendMessageData) {\n if (!this.isOpen() || !this.initParams) {\n if (this.isConnecting()) {\n throw new Error(\n `Failed to execute 'send' on 'EventSource': Still in CONNECTING state.`,\n );\n }\n if (this.conn.readyState === this.ES.CLOSED) {\n throw new Error(`EventSource is already in CLOSING or CLOSED state.`);\n }\n throw new Error(`EventSource is in invalid state.`);\n }\n this.sendQueue.push(msg);\n this.flushQueue();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === this.ES.OPEN && this.initParams !== null;\n }\n\n isConnecting(): boolean {\n return (\n this.conn.readyState === this.ES.CONNECTING ||\n (this.conn.readyState === this.ES.OPEN && this.initParams === null)\n );\n }\n\n close() {\n this.handleClose();\n }\n}\n"]}
@@ -41,10 +41,12 @@ export class WSConnection {
41
41
  this.conn.close();
42
42
  }
43
43
  isOpen() {
44
- return this.conn.readyState === WebSocket.OPEN;
44
+ var _a;
45
+ return this.conn.readyState === ((_a = WebSocket.OPEN) !== null && _a !== void 0 ? _a : 1);
45
46
  }
46
47
  isConnecting() {
47
- return this.conn.readyState === WebSocket.CONNECTING;
48
+ var _a;
49
+ return this.conn.readyState === ((_a = WebSocket.CONNECTING) !== null && _a !== void 0 ? _a : 0);
48
50
  }
49
51
  send(msg) {
50
52
  return this.conn.send(JSON.stringify(msg));
@@ -1 +1 @@
1
- {"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;;;;;;;AAkBA,IAAI,OAAO,GAAG,CAAC,CAAC;AA+ChB,MAAM,OAAO,YAAY;IAQvB,YAAY,GAAW;QAPvB,SAAI,GAAkB,IAAI,CAAC;QAQzB,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CA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,oDAAoD,CAAC,CAAC;YACxE,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC;IAC3E,CAAC;IAED,YAAY;QACV,OAAO,CACL,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC,UAAU;YAC3C,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC,CACpE,CAAC;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;CACF","sourcesContent":["export interface EventSourceType {\n readonly url: string;\n readonly readyState: number;\n\n onopen: ((this: EventSourceType, ev: Event) => any) | null;\n onmessage: ((this: EventSourceType, ev: MessageEvent) => any) | null;\n onerror: ((this: EventSourceType, ev: Event) => any) | null;\n\n close(): void;\n}\n\nexport interface EventSourceConstructor {\n OPEN: number;\n CONNECTING: number;\n CLOSED: number;\n new (url: string): EventSourceType;\n}\n\nlet _connId = 0;\n\ntype Conn = EventSourceType | WebSocket;\n\ntype OpenEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ntype MessageData = {\n op: string;\n [key: string]: any;\n};\n\ntype SendMessageData = {\n 'client-event-id': string;\n [key: string]: any;\n};\n\ntype MsgEvent<T extends Conn> = {\n target: Connection<T>;\n message: MessageData;\n};\n\ntype CloseEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ninterface ErrorEvent<T extends Conn> {\n target: Connection<T>;\n}\n\nexport type TransportType = 'ws' | 'sse';\n\nexport interface Connection<T extends Conn> {\n conn: T;\n type: 'ws' | 'sse';\n id: string;\n close(): void;\n isOpen(): boolean;\n isConnecting(): boolean;\n send(msg: SendMessageData): void;\n onopen: ((event: OpenEvent<T>) => void) | null;\n onmessage: ((event: MsgEvent<T>) => void) | null;\n onclose: ((event: CloseEvent<T>) => void) | null;\n onerror: ((event: ErrorEvent<T>) => void) | null;\n}\n\nexport class WSConnection implements Connection<WebSocket> {\n type: TransportType = 'ws';\n conn: WebSocket;\n id: string;\n onopen: (event: OpenEvent<WebSocket>) => void;\n onmessage: (event: MsgEvent<WebSocket>) => void;\n onclose: (event: CloseEvent<WebSocket>) => void;\n onerror: (event: ErrorEvent<WebSocket>) => void;\n constructor(url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.conn = new WebSocket(url);\n this.conn.onopen = (_e) => {\n if (this.onopen) {\n this.onopen({ target: this });\n }\n };\n this.conn.onmessage = (e) => {\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: JSON.parse(e.data.toString()),\n });\n }\n };\n this.conn.onclose = (_e) => {\n if (this.onclose) {\n this.onclose({ target: this });\n }\n };\n this.conn.onerror = (_e) => {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n };\n }\n\n close() {\n this.conn.close();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === WebSocket.OPEN;\n }\n\n isConnecting(): boolean {\n return this.conn.readyState === WebSocket.CONNECTING;\n }\n\n send(msg: SendMessageData) {\n return this.conn.send(JSON.stringify(msg));\n }\n}\n\ntype SSEInitParams = {\n machineId: string;\n sessionId: string;\n sseToken: string;\n};\n\nexport class SSEConnection implements Connection<EventSourceType> {\n type: TransportType = 'sse';\n private initParams: SSEInitParams | null = null;\n private sendQueue: any[] = [];\n private sendPromise: Promise<void> | null;\n private closeFired: boolean = false;\n private sseInitTimeout: NodeJS.Timeout | null = null;\n private ES: EventSourceConstructor;\n conn: EventSourceType;\n url: string;\n id: string;\n onopen: (event: OpenEvent<EventSourceType>) => void;\n onmessage: (event: MsgEvent<EventSourceType>) => void;\n onclose: (event: CloseEvent<EventSourceType>) => void;\n onerror: (event: ErrorEvent<EventSourceType>) => void;\n\n constructor(ES: EventSourceConstructor, url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.url = url;\n this.ES = ES;\n this.conn = new ES(url);\n\n // Close the connection if we didn't get an init within 10 seconds\n this.sseInitTimeout = setTimeout(() => {\n if (!this.initParams) {\n this.handleError();\n }\n }, 10000);\n\n this.conn.onmessage = (e) => {\n const msg = JSON.parse(e.data);\n if (msg.op === 'sse-init') {\n this.initParams = {\n machineId: msg['machine-id'],\n sessionId: msg['session-id'],\n sseToken: msg['sse-token'],\n };\n if (this.onopen) {\n this.onopen({ target: this });\n }\n clearTimeout(this.sseInitTimeout);\n return;\n }\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: msg,\n });\n }\n };\n\n this.conn.onerror = (e) => {\n this.handleError();\n };\n }\n\n // Runs the onerror and closes the connection\n private handleError() {\n try {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n } finally {\n this.handleClose();\n }\n }\n\n private handleClose() {\n this.conn.close();\n if (this.onclose && !this.closeFired) {\n this.closeFired = true;\n this.onclose({ target: this });\n }\n }\n\n private async postMessages(messages: any[]): Promise<void> {\n try {\n const resp = await fetch(this.url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n machine_id: this.initParams.machineId,\n session_id: this.initParams.sessionId,\n sse_token: this.initParams.sseToken,\n messages,\n }),\n });\n if (!resp.ok) {\n this.handleError();\n }\n } catch (e) {\n this.handleError();\n }\n }\n\n private async flushQueue() {\n if (this.sendPromise || !this.sendQueue.length) return;\n\n const messages = this.sendQueue;\n this.sendQueue = [];\n const sendPromise = this.postMessages(messages);\n this.sendPromise = sendPromise;\n sendPromise.then(() => {\n this.sendPromise = null;\n this.flushQueue();\n });\n }\n\n send(msg: SendMessageData) {\n if (!this.isOpen() || !this.initParams) {\n if (this.isConnecting()) {\n throw new Error(\n `Failed to execute 'send' on 'EventSource': Still in CONNECTING state.`,\n );\n }\n if (this.conn.readyState === this.ES.CLOSED) {\n throw new Error(`EventSource is already in CLOSING or CLOSED state.`);\n }\n throw new Error(`EventSource is in invalid state.`);\n }\n this.sendQueue.push(msg);\n this.flushQueue();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === this.ES.OPEN && this.initParams !== null;\n }\n\n isConnecting(): boolean {\n return (\n this.conn.readyState === this.ES.CONNECTING ||\n (this.conn.readyState === this.ES.OPEN && this.initParams === null)\n );\n }\n\n close() {\n this.handleClose();\n }\n}\n"]}
1
+ {"version":3,"file":"Connection.js","sourceRoot":"","sources":["../../src/Connection.ts"],"names":[],"mappings":";;;;;;;;;AAkBA,IAAI,OAAO,GAAG,CAAC,CAAC;AA+ChB,MAAM,OAAO,YAAY;IAQvB,YAAY,GAAW;QAPvB,SAAI,GAAkB,IAAI,CAAC;QAQzB,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,EAAE,EAAE,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,EAAE;YACxB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAChC,CAAC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,EAAE;YAC1B,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;gBACnB,IAAI,CAAC,SAAS,CAAC;oBACb,MAAM,EAAE,IAAI;oBACZ,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;iBACvC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC;QAC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AI,CAAC,CACpE,CAAC;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;CACF","sourcesContent":["export interface EventSourceType {\n readonly url: string;\n readonly readyState: number;\n\n onopen: ((this: EventSourceType, ev: Event) => any) | null;\n onmessage: ((this: EventSourceType, ev: MessageEvent) => any) | null;\n onerror: ((this: EventSourceType, ev: Event) => any) | null;\n\n close(): void;\n}\n\nexport interface EventSourceConstructor {\n OPEN: number;\n CONNECTING: number;\n CLOSED: number;\n new (url: string): EventSourceType;\n}\n\nlet _connId = 0;\n\ntype Conn = EventSourceType | WebSocket;\n\ntype OpenEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ntype MessageData = {\n op: string;\n [key: string]: any;\n};\n\ntype SendMessageData = {\n 'client-event-id': string;\n [key: string]: any;\n};\n\ntype MsgEvent<T extends Conn> = {\n target: Connection<T>;\n message: MessageData;\n};\n\ntype CloseEvent<T extends Conn> = {\n target: Connection<T>;\n};\n\ninterface ErrorEvent<T extends Conn> {\n target: Connection<T>;\n}\n\nexport type TransportType = 'ws' | 'sse';\n\nexport interface Connection<T extends Conn> {\n conn: T;\n type: 'ws' | 'sse';\n id: string;\n close(): void;\n isOpen(): boolean;\n isConnecting(): boolean;\n send(msg: SendMessageData): void;\n onopen: ((event: OpenEvent<T>) => void) | null;\n onmessage: ((event: MsgEvent<T>) => void) | null;\n onclose: ((event: CloseEvent<T>) => void) | null;\n onerror: ((event: ErrorEvent<T>) => void) | null;\n}\n\nexport class WSConnection implements Connection<WebSocket> {\n type: TransportType = 'ws';\n conn: WebSocket;\n id: string;\n onopen: (event: OpenEvent<WebSocket>) => void;\n onmessage: (event: MsgEvent<WebSocket>) => void;\n onclose: (event: CloseEvent<WebSocket>) => void;\n onerror: (event: ErrorEvent<WebSocket>) => void;\n constructor(url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.conn = new WebSocket(url);\n this.conn.onopen = (_e) => {\n if (this.onopen) {\n this.onopen({ target: this });\n }\n };\n this.conn.onmessage = (e) => {\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: JSON.parse(e.data.toString()),\n });\n }\n };\n this.conn.onclose = (_e) => {\n if (this.onclose) {\n this.onclose({ target: this });\n }\n };\n this.conn.onerror = (_e) => {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n };\n }\n\n close() {\n this.conn.close();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === (WebSocket.OPEN ?? 1);\n }\n\n isConnecting(): boolean {\n return this.conn.readyState === (WebSocket.CONNECTING ?? 0);\n }\n\n send(msg: SendMessageData) {\n return this.conn.send(JSON.stringify(msg));\n }\n}\n\ntype SSEInitParams = {\n machineId: string;\n sessionId: string;\n sseToken: string;\n};\n\nexport class SSEConnection implements Connection<EventSourceType> {\n type: TransportType = 'sse';\n private initParams: SSEInitParams | null = null;\n private sendQueue: any[] = [];\n private sendPromise: Promise<void> | null;\n private closeFired: boolean = false;\n private sseInitTimeout: NodeJS.Timeout | null = null;\n private ES: EventSourceConstructor;\n conn: EventSourceType;\n url: string;\n id: string;\n onopen: (event: OpenEvent<EventSourceType>) => void;\n onmessage: (event: MsgEvent<EventSourceType>) => void;\n onclose: (event: CloseEvent<EventSourceType>) => void;\n onerror: (event: ErrorEvent<EventSourceType>) => void;\n\n constructor(ES: EventSourceConstructor, url: string) {\n this.id = `${this.type}_${_connId++}`;\n this.url = url;\n this.ES = ES;\n this.conn = new ES(url);\n\n // Close the connection if we didn't get an init within 10 seconds\n this.sseInitTimeout = setTimeout(() => {\n if (!this.initParams) {\n this.handleError();\n }\n }, 10000);\n\n this.conn.onmessage = (e) => {\n const msg = JSON.parse(e.data);\n if (msg.op === 'sse-init') {\n this.initParams = {\n machineId: msg['machine-id'],\n sessionId: msg['session-id'],\n sseToken: msg['sse-token'],\n };\n if (this.onopen) {\n this.onopen({ target: this });\n }\n clearTimeout(this.sseInitTimeout);\n return;\n }\n if (this.onmessage) {\n this.onmessage({\n target: this,\n message: msg,\n });\n }\n };\n\n this.conn.onerror = (e) => {\n this.handleError();\n };\n }\n\n // Runs the onerror and closes the connection\n private handleError() {\n try {\n if (this.onerror) {\n this.onerror({ target: this });\n }\n } finally {\n this.handleClose();\n }\n }\n\n private handleClose() {\n this.conn.close();\n if (this.onclose && !this.closeFired) {\n this.closeFired = true;\n this.onclose({ target: this });\n }\n }\n\n private async postMessages(messages: any[]): Promise<void> {\n try {\n const resp = await fetch(this.url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n machine_id: this.initParams.machineId,\n session_id: this.initParams.sessionId,\n sse_token: this.initParams.sseToken,\n messages,\n }),\n });\n if (!resp.ok) {\n this.handleError();\n }\n } catch (e) {\n this.handleError();\n }\n }\n\n private async flushQueue() {\n if (this.sendPromise || !this.sendQueue.length) return;\n\n const messages = this.sendQueue;\n this.sendQueue = [];\n const sendPromise = this.postMessages(messages);\n this.sendPromise = sendPromise;\n sendPromise.then(() => {\n this.sendPromise = null;\n this.flushQueue();\n });\n }\n\n send(msg: SendMessageData) {\n if (!this.isOpen() || !this.initParams) {\n if (this.isConnecting()) {\n throw new Error(\n `Failed to execute 'send' on 'EventSource': Still in CONNECTING state.`,\n );\n }\n if (this.conn.readyState === this.ES.CLOSED) {\n throw new Error(`EventSource is already in CLOSING or CLOSED state.`);\n }\n throw new Error(`EventSource is in invalid state.`);\n }\n this.sendQueue.push(msg);\n this.flushQueue();\n }\n\n isOpen(): boolean {\n return this.conn.readyState === this.ES.OPEN && this.initParams !== null;\n }\n\n isConnecting(): boolean {\n return (\n this.conn.readyState === this.ES.CONNECTING ||\n (this.conn.readyState === this.ES.OPEN && this.initParams === null)\n );\n }\n\n close() {\n this.handleClose();\n }\n}\n"]}
@@ -114,7 +114,7 @@ function Q(t, e) {
114
114
  function pe(t, e, n) {
115
115
  Z(t) === 2 ? t.set(e, n) : t[e] = n;
116
116
  }
117
- function Re(t, e) {
117
+ function xe(t, e) {
118
118
  const n = S(t);
119
119
  return (n ? U(n) : t)[e];
120
120
  }
@@ -678,7 +678,7 @@ const ir = Reflect.ownKeys(Ae), an = /* @__PURE__ */ new WeakSet(), cn = {
678
678
  const c = a[e];
679
679
  if (t.options.strict && ve(c, t.options), t.finalized || !K(c, t.options))
680
680
  return c;
681
- if (c === Re(t.original, e)) {
681
+ if (c === xe(t.original, e)) {
682
682
  if (j(t), t.copy[e] = dt({
683
683
  original: t.original[e],
684
684
  parentDraft: t,
@@ -703,7 +703,7 @@ const ir = Reflect.ownKeys(Ae), an = /* @__PURE__ */ new WeakSet(), cn = {
703
703
  const i = Ot(U(t), e);
704
704
  if (i != null && i.set)
705
705
  return i.set.call(t.proxy, n), !0;
706
- const o = Re(U(t), e), a = S(o);
706
+ const o = xe(U(t), e), a = S(o);
707
707
  return a && W(a.original, n) ? (t.copy[e] = n, t.assignedMap = (r = t.assignedMap) !== null && r !== void 0 ? r : /* @__PURE__ */ new Map(), t.assignedMap.set(e, !1), !0) : (W(n, o) && (n !== void 0 || ue(t.original, e)) || (j(t), z(t), ue(t.original, e) && W(n, t.original[e]) ? t.assignedMap.delete(e) : t.assignedMap.set(e, !0), t.copy[e] = n, ft(t, e, n, de)), !0);
708
708
  },
709
709
  has(t, e) {
@@ -732,7 +732,7 @@ const ir = Reflect.ownKeys(Ae), an = /* @__PURE__ */ new WeakSet(), cn = {
732
732
  },
733
733
  deleteProperty(t, e) {
734
734
  var n;
735
- return t.type === 1 ? cn.set.call(this, t, e, void 0, t.proxy) : (Re(t.original, e) !== void 0 || e in t.original ? (j(t), z(t), t.assignedMap.set(e, !1)) : (t.assignedMap = (n = t.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), t.assignedMap.delete(e)), t.copy && delete t.copy[e], !0);
735
+ return t.type === 1 ? cn.set.call(this, t, e, void 0, t.proxy) : (xe(t.original, e) !== void 0 || e in t.original ? (j(t), z(t), t.assignedMap.set(e, !1)) : (t.assignedMap = (n = t.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), t.assignedMap.delete(e)), t.copy && delete t.copy[e], !0);
736
736
  }
737
737
  };
738
738
  function dt(t) {
@@ -1398,7 +1398,7 @@ function yn(t) {
1398
1398
  return {
1399
1399
  __type: t.__type,
1400
1400
  attrs: t.attrs,
1401
- triples: R(t.eav, 3),
1401
+ triples: x(t.eav, 3),
1402
1402
  cardinalityInference: t.cardinalityInference,
1403
1403
  linkIndex: t.linkIndex,
1404
1404
  useDateObjects: t.useDateObjects
@@ -1430,7 +1430,7 @@ function ye(t, e) {
1430
1430
  const [o, a] = e[0], c = t.aev.get(o);
1431
1431
  if (!c)
1432
1432
  return null;
1433
- n = (s = R(c, 2).find((l) => l[2] === a)) == null ? void 0 : s[0];
1433
+ n = (s = x(c, 2).find((l) => l[2] === a)) == null ? void 0 : s[0];
1434
1434
  } else
1435
1435
  n = e[0];
1436
1436
  if (!n)
@@ -1440,7 +1440,7 @@ function ye(t, e) {
1440
1440
  const [o, a] = r, c = t.aev.get(o);
1441
1441
  if (!c)
1442
1442
  return null;
1443
- const l = (i = R(c, 2).find((y) => y[2] === a)) == null ? void 0 : i[0];
1443
+ const l = (i = x(c, 2).find((y) => y[2] === a)) == null ? void 0 : i[0];
1444
1444
  if (!l)
1445
1445
  return null;
1446
1446
  const [d, f, h, ...p] = e;
@@ -1506,7 +1506,7 @@ function Be(t, e) {
1506
1506
  if (o) {
1507
1507
  for (const l of o.keys()) {
1508
1508
  const d = t.attrs[l];
1509
- d && d["on-delete-reverse"] === "cascade" && R(o.get(l), 1).forEach(
1509
+ d && d["on-delete-reverse"] === "cascade" && x(o.get(l), 1).forEach(
1510
1510
  ([f, h, p]) => {
1511
1511
  var y;
1512
1512
  return Be(t, [p, (y = d["reverse-identity"]) == null ? void 0 : y[1]]);
@@ -1519,7 +1519,7 @@ function Be(t, e) {
1519
1519
  }
1520
1520
  o.size === 0 && N(t.eav, [i]);
1521
1521
  }
1522
- const a = t.vae.get(i) && R(t.vae.get(i), 2);
1522
+ const a = t.vae.get(i) && x(t.vae.get(i), 2);
1523
1523
  a && a.forEach((l) => {
1524
1524
  var y, _, b;
1525
1525
  const [d, f, h] = l, p = t.attrs[f];
@@ -1540,7 +1540,7 @@ function Pr(t, [e]) {
1540
1540
  t.attrs[e.id] = e, bt(t);
1541
1541
  }
1542
1542
  function mn(t) {
1543
- return R(t.eav, 3);
1543
+ return x(t.eav, 3);
1544
1544
  }
1545
1545
  function jr(t, [e]) {
1546
1546
  if (!t.attrs[e]) return;
@@ -1583,7 +1583,7 @@ function Dr(t, e) {
1583
1583
  throw new Error(`unhandled transaction action: ${n}`);
1584
1584
  }
1585
1585
  }
1586
- function R(t, e, n = []) {
1586
+ function x(t, e, n = []) {
1587
1587
  if (!t || e === 0)
1588
1588
  return n;
1589
1589
  if (e === 1) {
@@ -1592,7 +1592,7 @@ function R(t, e, n = []) {
1592
1592
  return n;
1593
1593
  }
1594
1594
  for (const r of t.values())
1595
- R(r, e - 1, n);
1595
+ x(r, e - 1, n);
1596
1596
  return n;
1597
1597
  }
1598
1598
  function be(t, e, n) {
@@ -1620,7 +1620,7 @@ function be(t, e, n) {
1620
1620
  return r;
1621
1621
  }
1622
1622
  if (n != null && n.$comparator)
1623
- return R(e, 1).filter(n.$op);
1623
+ return x(e, 1).filter(n.$op);
1624
1624
  const s = n.in || n.$in || [n];
1625
1625
  for (const a of s) {
1626
1626
  const c = e.get(a);
@@ -1628,20 +1628,20 @@ function be(t, e, n) {
1628
1628
  }
1629
1629
  return r;
1630
1630
  }
1631
- function Rr(t, e, n) {
1631
+ function xr(t, e, n) {
1632
1632
  let r = "";
1633
1633
  return t !== void 0 && (r += "e"), e !== void 0 && (r += "a"), n !== void 0 && (r += "v"), r;
1634
1634
  }
1635
- function xr(t, [e, n, r]) {
1635
+ function Rr(t, [e, n, r]) {
1636
1636
  var i, o;
1637
- switch (Rr(e, n, r)) {
1637
+ switch (xr(e, n, r)) {
1638
1638
  case "e": {
1639
1639
  const a = t.eav.get(e);
1640
- return R(a, 2);
1640
+ return x(a, 2);
1641
1641
  }
1642
1642
  case "ea": {
1643
1643
  const a = (i = t.eav.get(e)) == null ? void 0 : i.get(n);
1644
- return R(a, 1);
1644
+ return x(a, 1);
1645
1645
  }
1646
1646
  case "eav": {
1647
1647
  const a = (o = t.eav.get(e)) == null ? void 0 : o.get(n);
@@ -1658,7 +1658,7 @@ function xr(t, [e, n, r]) {
1658
1658
  }
1659
1659
  case "a": {
1660
1660
  const a = t.aev.get(n);
1661
- return R(a, 2);
1661
+ return x(a, 2);
1662
1662
  }
1663
1663
  case "av": {
1664
1664
  const a = t.aev.get(n);
@@ -1677,14 +1677,14 @@ function xr(t, [e, n, r]) {
1677
1677
  return a;
1678
1678
  }
1679
1679
  default:
1680
- return R(t.eav, 3);
1680
+ return x(t.eav, 3);
1681
1681
  }
1682
1682
  }
1683
1683
  function Ur(t, e, n) {
1684
1684
  var s;
1685
1685
  const r = {};
1686
1686
  for (const [i, o] of e.entries()) {
1687
- const a = (s = t.eav.get(n)) == null ? void 0 : s.get(o.id), c = R(a, 1);
1687
+ const a = (s = t.eav.get(n)) == null ? void 0 : s.get(o.id), c = x(a, 1);
1688
1688
  for (const u of c)
1689
1689
  r[i] = u[2];
1690
1690
  }
@@ -1797,7 +1797,7 @@ function Hr(t, { find: e, where: n }) {
1797
1797
  return He(t, n).map((s) => _t(s, e));
1798
1798
  }
1799
1799
  function Jr(t, e, n) {
1800
- return xr(t, _t(n, e));
1800
+ return Rr(t, _t(n, e));
1801
1801
  }
1802
1802
  const Yr = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
1803
1803
  function te(t) {
@@ -1809,15 +1809,15 @@ for (let t = 0; t < 256; ++t)
1809
1809
  function Zr(t, e = 0) {
1810
1810
  return (C[t[e + 0]] + C[t[e + 1]] + C[t[e + 2]] + C[t[e + 3]] + "-" + C[t[e + 4]] + C[t[e + 5]] + "-" + C[t[e + 6]] + C[t[e + 7]] + "-" + C[t[e + 8]] + C[t[e + 9]] + "-" + C[t[e + 10]] + C[t[e + 11]] + C[t[e + 12]] + C[t[e + 13]] + C[t[e + 14]] + C[t[e + 15]]).toLowerCase();
1811
1811
  }
1812
- let xe;
1812
+ let Re;
1813
1813
  const Xr = new Uint8Array(16);
1814
1814
  function es() {
1815
- if (!xe) {
1815
+ if (!Re) {
1816
1816
  if (typeof crypto > "u" || !crypto.getRandomValues)
1817
1817
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1818
- xe = crypto.getRandomValues.bind(crypto);
1818
+ Re = crypto.getRandomValues.bind(crypto);
1819
1819
  }
1820
- return xe(Xr);
1820
+ return Re(Xr);
1821
1821
  }
1822
1822
  const ts = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Pt = { randomUUID: ts };
1823
1823
  function ns(t, e, n) {
@@ -2060,7 +2060,7 @@ function gs(t, e, n) {
2060
2060
  return e == i ? i : `${i}-${n}`;
2061
2061
  };
2062
2062
  }
2063
- function Rt(t, e, n, r, s, i) {
2063
+ function xt(t, e, n, r, s, i) {
2064
2064
  const o = t(r, s), a = i.map((c, u) => {
2065
2065
  const l = gs(t, o, u);
2066
2066
  return kn(l, n, r, s, c);
@@ -2073,7 +2073,7 @@ function ws(t) {
2073
2073
  e.push(t.slice(0, n));
2074
2074
  return e;
2075
2075
  }
2076
- function xt(t, e, n, r, s) {
2076
+ function Rt(t, e, n, r, s) {
2077
2077
  return ws(s).map(
2078
2078
  (i) => Je(t, e, n, r, i, { $isNull: !0 })
2079
2079
  );
@@ -2081,14 +2081,14 @@ function xt(t, e, n, r, s) {
2081
2081
  function kn(t, e, n, r, s) {
2082
2082
  return Object.entries(s).flatMap(([i, o]) => {
2083
2083
  if (bs([i, o]))
2084
- return Rt(t, "or", e, n, r, o);
2084
+ return xt(t, "or", e, n, r, o);
2085
2085
  if (_s([i, o]))
2086
- return Rt(t, "and", e, n, r, o);
2086
+ return xt(t, "and", e, n, r, o);
2087
2087
  if (i === "$entityIdStartsWith")
2088
2088
  return [];
2089
2089
  const a = i.split(".");
2090
2090
  if (o != null && o.hasOwnProperty("$ne") && (o = { ...o, $not: o.$ne }, delete o.$ne), o != null && o.hasOwnProperty("$not")) {
2091
- const c = Je(t, e, n, r, a, o), u = xt(
2091
+ const c = Je(t, e, n, r, a, o), u = Rt(
2092
2092
  t,
2093
2093
  e,
2094
2094
  n,
@@ -2107,7 +2107,7 @@ function kn(t, e, n, r, s) {
2107
2107
  return o != null && o.hasOwnProperty("$isNull") && o.$isNull === !0 && a.length > 1 ? [
2108
2108
  {
2109
2109
  or: {
2110
- patterns: xt(
2110
+ patterns: Rt(
2111
2111
  t,
2112
2112
  e,
2113
2113
  n,
@@ -2312,7 +2312,7 @@ function Cn({ store: t, pageInfo: e, aggregate: n }, r) {
2312
2312
  }, {}) };
2313
2313
  return e && (i.pageInfo = Ds(e)), n && (i.aggregate = n), i;
2314
2314
  }
2315
- function Rs() {
2315
+ function xs() {
2316
2316
  const e = {
2317
2317
  __etype: 1,
2318
2318
  __ops: 1,
@@ -2326,7 +2326,7 @@ function Rs() {
2326
2326
  };
2327
2327
  return new Set(Object.keys(e));
2328
2328
  }
2329
- const xs = Rs();
2329
+ const Rs = xs();
2330
2330
  function Ze(t, e, n) {
2331
2331
  const r = {
2332
2332
  __etype: t,
@@ -2336,7 +2336,7 @@ function Ze(t, e, n) {
2336
2336
  get: (s, i) => {
2337
2337
  if (i === "__ops") return n;
2338
2338
  if (i === "__etype") return t;
2339
- if (xs.has(i))
2339
+ if (Rs.has(i))
2340
2340
  return (o, a) => Ze(t, e, [
2341
2341
  ...n,
2342
2342
  a ? [i, t, e, o, a] : [i, t, e, o]
@@ -2447,7 +2447,7 @@ function Ks(t, e, n) {
2447
2447
  function tt(t) {
2448
2448
  return typeof t == "string" && !Me(t) ? null : typeof t == "string" && Me(t) ? In(t) : Ns(t);
2449
2449
  }
2450
- function x(t, e, n) {
2450
+ function R(t, e, n) {
2451
2451
  const r = tt(n);
2452
2452
  if (r === null)
2453
2453
  return n;
@@ -2457,7 +2457,7 @@ function x(t, e, n) {
2457
2457
  return [o.id, i];
2458
2458
  }
2459
2459
  function jn(t, e, n, r) {
2460
- const s = x(t, e, n);
2460
+ const s = R(t, e, n);
2461
2461
  return Array.isArray(s) ? [[
2462
2462
  "add-triple",
2463
2463
  s,
@@ -2470,14 +2470,14 @@ function qs({ attrs: t }, [e, n, r]) {
2470
2470
  const a = Array.isArray(o) ? o : [o], c = I(t, e, i), u = J(t, e, i);
2471
2471
  return a.map((l) => c ? [
2472
2472
  "add-triple",
2473
- x(t, e, n),
2473
+ R(t, e, n),
2474
2474
  c.id,
2475
- x(t, c["reverse-identity"][1], l)
2475
+ R(t, c["reverse-identity"][1], l)
2476
2476
  ] : [
2477
2477
  "add-triple",
2478
- x(t, u["forward-identity"][1], l),
2478
+ R(t, u["forward-identity"][1], l),
2479
2479
  u.id,
2480
- x(t, e, n)
2480
+ R(t, e, n)
2481
2481
  ]);
2482
2482
  });
2483
2483
  return jn(t, e, n, s);
@@ -2487,14 +2487,14 @@ function zs({ attrs: t }, [e, n, r]) {
2487
2487
  const a = Array.isArray(o) ? o : [o], c = I(t, e, i), u = J(t, e, i);
2488
2488
  return a.map((l) => c ? [
2489
2489
  "retract-triple",
2490
- x(t, e, n),
2490
+ R(t, e, n),
2491
2491
  c.id,
2492
- x(t, c["reverse-identity"][1], l)
2492
+ R(t, c["reverse-identity"][1], l)
2493
2493
  ] : [
2494
2494
  "retract-triple",
2495
- x(t, u["forward-identity"][1], l),
2495
+ R(t, u["forward-identity"][1], l),
2496
2496
  u.id,
2497
- x(t, e, n)
2497
+ R(t, e, n)
2498
2498
  ]);
2499
2499
  });
2500
2500
  return jn(t, e, n, s);
@@ -2505,7 +2505,7 @@ function Vs(t, e, n) {
2505
2505
  for (const i of t || []) {
2506
2506
  const o = i == null ? void 0 : i.aev.get(r);
2507
2507
  if (o) {
2508
- for (const [a, c, u] of R(o, 2))
2508
+ for (const [a, c, u] of x(o, 2))
2509
2509
  if (u === s)
2510
2510
  return !0;
2511
2511
  }
@@ -2525,14 +2525,14 @@ function $n({ stores: t, attrs: e }, [n, r, s, i]) {
2525
2525
  return (i == null ? void 0 : i.upsert) === !1 ? { mode: "update" } : (i == null ? void 0 : i.upsert) === !0 ? null : Vs(t, n, r) ? { mode: "update" } : null;
2526
2526
  }
2527
2527
  function Ws(t, e) {
2528
- const { attrs: n } = t, [r, s, i, o] = e, a = ht(i), c = x(n, r, s);
2528
+ const { attrs: n } = t, [r, s, i, o] = e, a = ht(i), c = R(n, r, s);
2529
2529
  return [["id", c]].concat(Object.entries(a)).map(([l, d]) => {
2530
2530
  const f = I(n, r, l);
2531
2531
  return f["checked-data-type"] === "date" && t.useDateObjects && (d = Ce(d)), ["add-triple", c, f.id, d, { mode: "create" }];
2532
2532
  });
2533
2533
  }
2534
2534
  function Qs(t, e) {
2535
- const { attrs: n } = t, [r, s, i, o] = e, a = ht(i), c = x(n, r, s), u = $n(t, [r, c, i, o]);
2535
+ const { attrs: n } = t, [r, s, i, o] = e, a = ht(i), c = R(n, r, s), u = $n(t, [r, c, i, o]);
2536
2536
  return [["id", c]].concat(Object.entries(a)).map(([d, f]) => {
2537
2537
  const h = I(n, r, d);
2538
2538
  return h["checked-data-type"] === "date" && t.useDateObjects && (f = Ce(f)), [
@@ -2545,10 +2545,10 @@ function Qs(t, e) {
2545
2545
  });
2546
2546
  }
2547
2547
  function Gs({ attrs: t }, [e, n]) {
2548
- return [["delete-entity", x(t, e, n), e]];
2548
+ return [["delete-entity", R(t, e, n), e]];
2549
2549
  }
2550
2550
  function Bs(t, e) {
2551
- const { attrs: n } = t, [r, s, i, o] = e, a = ht(i), c = x(n, r, s), u = $n(t, [r, c, i, o]), l = Object.entries(a).map(([f, h]) => {
2551
+ const { attrs: n } = t, [r, s, i, o] = e, a = ht(i), c = R(n, r, s), u = $n(t, [r, c, i, o]), l = Object.entries(a).map(([f, h]) => {
2552
2552
  const p = I(n, r, f);
2553
2553
  return [
2554
2554
  "deep-merge-triple",
@@ -2567,7 +2567,7 @@ function Bs(t, e) {
2567
2567
  ]].concat(l);
2568
2568
  }
2569
2569
  function Hs({ attrs: t }, [e, n, r]) {
2570
- return [["rule-params", x(t, e, n), e, r]];
2570
+ return [["rule-params", R(t, e, n), e, r]];
2571
2571
  }
2572
2572
  function Js(t) {
2573
2573
  const [e, n, r, s, i] = t;
@@ -3194,7 +3194,7 @@ class Dn extends li {
3194
3194
  });
3195
3195
  }
3196
3196
  }
3197
- class Rn {
3197
+ class xn {
3198
3198
  static async getIsOnline() {
3199
3199
  return navigator.onLine;
3200
3200
  }
@@ -3432,8 +3432,8 @@ async function Ei({
3432
3432
  );
3433
3433
  return s;
3434
3434
  }
3435
- let gt = !1, xn = !1, Un = !1;
3436
- typeof window < "u" && typeof window.localStorage < "u" && (gt = !!window.localStorage.getItem("devBackend"), xn = !!window.localStorage.getItem("__instantLogging"), Un = !!window.localStorage.getItem("__devtoolLocalDash"));
3435
+ let gt = !1, Rn = !1, Un = !1;
3436
+ typeof window < "u" && typeof window.localStorage < "u" && (gt = !!window.localStorage.getItem("devBackend"), Rn = !!window.localStorage.getItem("__instantLogging"), Un = !!window.localStorage.getItem("__devtoolLocalDash"));
3437
3437
  function qt(t, e) {
3438
3438
  if (!e) return t;
3439
3439
  const n = {};
@@ -3507,7 +3507,7 @@ function Wt(t) {
3507
3507
  }, e;
3508
3508
  }, {});
3509
3509
  }
3510
- const Fn = "v0.22.58";
3510
+ const Fn = "v0.22.59-experimental.drewh-explorer-export.19553074787.1";
3511
3511
  function Ii(t, e) {
3512
3512
  return {
3513
3513
  info: t ? (...n) => console.info(...n, e()) : () => {
@@ -3965,7 +3965,7 @@ class F extends Error {
3965
3965
  super(e), this.name = "TransactionValidationError";
3966
3966
  }
3967
3967
  }
3968
- const zn = (t) => t.length > 0 ? t.join(", ") : "none", Ri = (t, e) => new F(
3968
+ const zn = (t) => t.length > 0 ? t.join(", ") : "none", xi = (t, e) => new F(
3969
3969
  `Entity '${t}' does not exist in schema. Available entities: ${zn(e)}`
3970
3970
  ), Ue = {
3971
3971
  string: (t) => typeof t == "string",
@@ -3973,13 +3973,13 @@ const zn = (t) => t.length > 0 ? t.join(", ") : "none", Ri = (t, e) => new F(
3973
3973
  boolean: (t) => typeof t == "boolean",
3974
3974
  date: (t) => t instanceof Date || typeof t == "string" || typeof t == "number",
3975
3975
  json: () => !0
3976
- }, xi = (t, e) => {
3976
+ }, Ri = (t, e) => {
3977
3977
  var n;
3978
3978
  return t == null ? !0 : ((n = Ue[e.valueType]) == null ? void 0 : n.call(Ue, t)) ?? !1;
3979
3979
  }, Vn = (t, e) => {
3980
3980
  const n = e.entities[t];
3981
3981
  if (!n)
3982
- throw Ri(t, Object.keys(e.entities));
3982
+ throw xi(t, Object.keys(e.entities));
3983
3983
  return n;
3984
3984
  }, Le = (t, e, n) => {
3985
3985
  const r = Vn(t, n);
@@ -3990,7 +3990,7 @@ const zn = (t) => t.length > 0 ? t.join(", ") : "none", Ri = (t, e) => new F(
3990
3990
  for (const [s, i] of Object.entries(e)) {
3991
3991
  if (s === "id") continue;
3992
3992
  const o = r.attrs[s];
3993
- if (o && !xi(i, o))
3993
+ if (o && !Ri(i, o))
3994
3994
  throw new F(
3995
3995
  `Invalid value for attribute '${s}' in entity '${t}'. Expected ${o.valueType}, but received: ${typeof i}`
3996
3996
  );
@@ -4082,10 +4082,10 @@ class Jt {
4082
4082
  this.conn.close();
4083
4083
  }
4084
4084
  isOpen() {
4085
- return this.conn.readyState === WebSocket.OPEN;
4085
+ return this.conn.readyState === (WebSocket.OPEN ?? 1);
4086
4086
  }
4087
4087
  isConnecting() {
4088
- return this.conn.readyState === WebSocket.CONNECTING;
4088
+ return this.conn.readyState === (WebSocket.CONNECTING ?? 0);
4089
4089
  }
4090
4090
  send(e) {
4091
4091
  return this.conn.send(JSON.stringify(e));
@@ -4654,7 +4654,7 @@ function en(t) {
4654
4654
  });
4655
4655
  }
4656
4656
  class io {
4657
- constructor(e, n = Dn, r = Rn, s, i) {
4657
+ constructor(e, n = Dn, r = xn, s, i) {
4658
4658
  w(this, "attrs");
4659
4659
  w(this, "_isOnline", !0);
4660
4660
  w(this, "_isShutdown", !1);
@@ -4880,7 +4880,7 @@ class io {
4880
4880
  ), this._scheduleReconnect();
4881
4881
  });
4882
4882
  if (this._EventSource = i, this.config = { ...Yi, ...e }, this.queryCacheLimit = this.config.queryCacheLimit ?? 10, this._pendingTxCleanupTimeout = this.config.pendingTxCleanupTimeout ?? Hi, this._pendingMutationCleanupThreshold = this.config.pendingMutationCleanupThreshold ?? Ji, this._log = Ii(
4883
- e.verbose || gt || xn,
4883
+ e.verbose || gt || Rn,
4884
4884
  () => this._reactorStats()
4885
4885
  ), this.versions = { ...s || {}, "@instantdb/core": Fn }, this.config.schema && (this._linkIndex = Wt(this.config.schema)), !!Xi()) {
4886
4886
  if (!e.appId)
@@ -6116,7 +6116,7 @@ function yo({
6116
6116
  s
6117
6117
  );
6118
6118
  }
6119
- const Ro = {
6119
+ const xo = {
6120
6120
  // constructs
6121
6121
  graph: oo,
6122
6122
  schema: yo,
@@ -6257,7 +6257,7 @@ class Eo {
6257
6257
  this.db = e, this.uploadFile = (n, r, s = {}) => this.db.uploadFile(n, r, s), this.delete = (n) => this.db.deleteFile(n), this.upload = (n, r) => this.db.upload(n, r), this.put = this.upload, this.getDownloadUrl = (n) => this.db.getDownloadUrl(n);
6258
6258
  }
6259
6259
  }
6260
- function xo(t) {
6260
+ function Ro(t) {
6261
6261
  return JSON.parse(JSON.stringify(t));
6262
6262
  }
6263
6263
  class Mo {
@@ -6458,7 +6458,7 @@ function Io(t, e, n, r, s) {
6458
6458
  cardinalityInference: !!t.schema
6459
6459
  },
6460
6460
  e || Dn,
6461
- n || Rn,
6461
+ n || xn,
6462
6462
  { ...r || {}, "@instantdb/core": Fn },
6463
6463
  s
6464
6464
  ), a = new Mo(
@@ -6488,11 +6488,11 @@ export {
6488
6488
  li as StorageInterface,
6489
6489
  Qi as SyncTableCallbackEventType,
6490
6490
  F as TransactionValidationError,
6491
- Rn as WindowNetworkListener,
6492
- xo as coerceQuery,
6491
+ xn as WindowNetworkListener,
6492
+ Ro as coerceQuery,
6493
6493
  Ce as coerceToDate,
6494
6494
  Ls as getOps,
6495
- Ro as i,
6495
+ xo as i,
6496
6496
  M as id,
6497
6497
  Io as init,
6498
6498
  Uo as init_experimental,