@instantdb/core 0.22.93-experimental.drewh-ssr.20383114333.1 → 0.22.93-experimental.drewh-ssr.20384561223.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.
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- function createUserSyncResponse(user, config) {
10
+ function createUserSyncResponse(config, user) {
11
11
  if (user && user.refresh_token) {
12
12
  return new Response(JSON.stringify({ ok: true }), {
13
13
  headers: {
@@ -52,7 +52,7 @@ export const createInstantRouteHandler = (config) => {
52
52
  }
53
53
  switch (body.type) {
54
54
  case 'sync-user':
55
- return createUserSyncResponse((_a = body.user) !== null && _a !== void 0 ? _a : null, config);
55
+ return createUserSyncResponse(config, (_a = body.user) !== null && _a !== void 0 ? _a : null);
56
56
  default:
57
57
  return errorResponse(400, `Unknown type: ${body.type}`);
58
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createRouteHandler.js","sourceRoot":"","sources":["../../src/createRouteHandler.ts"],"names":[],"mappings":";;;;;;;;;AAMA,SAAS,sBAAsB,CAC7B,IAAiB,EACjB,MAAgC;IAEhC,IAAI,IAAI,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QAC/B,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;YAChD,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,eAAe;gBACf,YAAY,EAAE,gBAAgB,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,6DAA6D;aAChI;SACF,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;Y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H,CAAC,CAAA;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { User } from './clientTypes.js';\n\ntype CreateRouteHandlerConfig = {\n appId: string;\n};\n\nfunction createUserSyncResponse(\n user: User | null,\n config: CreateRouteHandlerConfig,\n) {\n if (user && user.refresh_token) {\n return new Response(JSON.stringify({ ok: true }), {\n headers: {\n 'Content-Type': 'application/json',\n // 7 day expiry\n 'Set-Cookie': `instant_user_${config.appId}=${JSON.stringify(user)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,\n },\n });\n } else {\n return new Response(JSON.stringify({ ok: true }), {\n headers: {\n 'Content-Type': 'application/json',\n // remove the cookie (some browsers)\n 'Set-Cookie': `instant_user_${config.appId}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`,\n },\n });\n }\n}\n\nfunction errorResponse(status: number, message: string) {\n return new Response(JSON.stringify({ ok: false, error: message }), {\n status,\n headers: { 'Content-Type': 'application/json' },\n });\n}\n\nexport const createInstantRouteHandler = (config: CreateRouteHandlerConfig) => {\n return {\n POST: async (req: Request) => {\n let body: { type?: string; appId?: string; user?: User | null };\n try {\n body = await req.json();\n } catch {\n return errorResponse(400, 'Invalid JSON body');\n }\n\n if (!body.type) {\n return errorResponse(400, 'Missing \"type\" field');\n }\n\n if (body.appId !== config.appId) {\n return errorResponse(403, 'App ID mismatch');\n }\n\n switch (body.type) {\n case 'sync-user':\n return createUserSyncResponse(body.user ?? null, config);\n default:\n return errorResponse(400, `Unknown type: ${body.type}`);\n }\n },\n };\n};\n"]}
1
+ {"version":3,"file":"createRouteHandler.js","sourceRoot":"","sources":["../../src/createRouteHandler.ts"],"names":[],"mappings":";;;;;;;;;AAMA,SAAS,sBAAsB,CAC7B,MAAgC,EAChC,IAAiB;IAEjB,IAAI,IAAI,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;QAC/B,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI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AO,aAAa,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;YAC/C,CAAC;YAED,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,KAAK,WAAW;oBACd,OAAO,sBAAsB,CAAC,MAAM,EAAE,MAAA,IAAI,CAAC,IAAI,mCAAI,IAAI,CAAC,CAAC;gBAC3D;oBACE,OAAO,aAAa,CAAC,GAAG,EAAE,iBAAiB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC,CAAA;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { User } from './clientTypes.js';\n\ntype CreateRouteHandlerConfig = {\n appId: string;\n};\n\nfunction createUserSyncResponse(\n config: CreateRouteHandlerConfig,\n user: User | null,\n) {\n if (user && user.refresh_token) {\n return new Response(JSON.stringify({ ok: true }), {\n headers: {\n 'Content-Type': 'application/json',\n // 7 day expiry\n 'Set-Cookie': `instant_user_${config.appId}=${JSON.stringify(user)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,\n },\n });\n } else {\n return new Response(JSON.stringify({ ok: true }), {\n headers: {\n 'Content-Type': 'application/json',\n // remove the cookie (some browsers)\n 'Set-Cookie': `instant_user_${config.appId}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`,\n },\n });\n }\n}\n\nfunction errorResponse(status: number, message: string) {\n return new Response(JSON.stringify({ ok: false, error: message }), {\n status,\n headers: { 'Content-Type': 'application/json' },\n });\n}\n\nexport const createInstantRouteHandler = (config: CreateRouteHandlerConfig) => {\n return {\n POST: async (req: Request) => {\n let body: { type?: string; appId?: string; user?: User | null };\n try {\n body = await req.json();\n } catch {\n return errorResponse(400, 'Invalid JSON body');\n }\n\n if (!body.type) {\n return errorResponse(400, 'Missing \"type\" field');\n }\n\n if (body.appId !== config.appId) {\n return errorResponse(403, 'App ID mismatch');\n }\n\n switch (body.type) {\n case 'sync-user':\n return createUserSyncResponse(config, body.user ?? null);\n default:\n return errorResponse(400, `Unknown type: ${body.type}`);\n }\n },\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"framework.d.ts","sourceRoot":"","sources":["../../src/framework.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,aAAa,EAEd,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,eAAO,MAAM,QAAQ,SAAwD,CAAC;AAE9E,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,EAAE,EAAE,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CACnC,CAAC;AAIF,KAAK,YAAY,GACb;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,EAAE,GAAG,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEN,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,EAAE,CAAgC;IAInC,SAAS,EAAE,GAAG,CACnB,MAAM,EACN;QACE,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;QACxC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;QACvC,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,GAAG,CAAC;KACb,CACF,CAAa;IAEd,OAAO,CAAC,sBAAsB,CAMX;gBAEP,MAAM,EAAE,eAAe;IAe5B,SAAS,GACd,UAAU,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,GAAG,CAAC;QACb,KAA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ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ // The FrameworkClient class is a mini version of a query store that allows making queries on both the frontend and backend
11
+ // you can register queries, await their results and serialize them over a server/client boundary.
12
+ // The class is generic so that it can be a good starting off point to make other ssr adapters.
10
13
  import { coerceQuery, weakHash, } from "./index.js";
11
14
  import * as s from './store.js';
12
15
  import instaql from './instaql.js';
@@ -1 +1 @@
1
- {"version":3,"file":"framework.js","sourceRoot":"","sources":["../../src/framework.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,WAAW,EAGX,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAChC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,IAAI,UAAU,CAAC;AAuB9E,MAAM,OAAO,eAAe;IAyB1B,YAAY,MAAuB;QArBnC,6DAA6D;QAC7D,wFAAwF;QACjF,cAAS,GASZ,IAAI,GAAG,EAAE,CAAC;QAEN,2BAAsB,GAMd,EAAE,CAAC;QAiBZ,cAAS,GAAG,CACjB,QAKU,EACV,EAAE;YACF,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC,CAAC;QAEF,oDAAoD;QAC7C,mBAAc,GAAG,CAAC,QAAgB,EAAE,KAAU,EAAE,EAAE;YACvD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE;gBAC3B,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,MAAM,EAAE,SAAS;gBACjB,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YACH,gCAAgC;YAChC,IAAI,CAAC,QAAQ,EAAE,CA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AAC;gBAC3B,MAAM,cAAc,CAAC;YACvB,CAAC;QACH,CAAC,CAAA,CAAC;QA7PA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EASrB,CAAC;IACN,CAAC;CAkPF","sourcesContent":["import {\n coerceQuery,\n InstantCoreDatabase,\n InstantDBAttr,\n weakHash,\n} from './index.ts';\nimport * as s from './store.js';\nimport instaql from './instaql.js';\nimport { RuleParams } from './schemaTypes.ts';\nimport { createLinkIndex } from './utils/linkIndex.ts';\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in globalThis;\n\nexport type FrameworkConfig = {\n token?: string | null;\n db: InstantCoreDatabase<any, any>;\n};\n\n// represents an eventual result from running a query\n// either via ssr or by using the existing websocket connection.\ntype QueryPromise =\n | {\n type: 'http';\n triples: any;\n attrs: any;\n queryHash: any;\n query: any;\n pageInfo?: any;\n }\n | {\n type: 'session';\n queryResult: any;\n };\n\nexport class FrameworkClient {\n private params: FrameworkConfig;\n private db: InstantCoreDatabase<any, any>;\n\n // stores all of the query promises so that ssr can read them\n // and send the relevant results alongside the html that resulted in the query resolving\n public resultMap: Map<\n string,\n {\n status: 'pending' | 'success' | 'error';\n type: 'http' | 'session';\n promise?: Promise<QueryPromise> | null;\n data?: any;\n error?: any;\n }\n > = new Map();\n\n private queryResolvedCallbacks: ((result: {\n triples: any;\n attrs: any;\n queryHash: any;\n query: any;\n pageInfo?: any;\n }) => void)[] = [];\n\n constructor(params: FrameworkConfig) {\n this.params = params;\n this.db = params.db;\n this.resultMap = new Map<\n string,\n {\n type: 'http' | 'session';\n status: 'pending' | 'success' | 'error';\n promise?: Promise<QueryPromise>;\n data?: any;\n error?: any;\n }\n >();\n }\n\n public subscribe = (\n callback: (result: {\n triples: any;\n attrs: any;\n queryHash: string;\n pageInfo?: any;\n }) => void,\n ) => {\n this.queryResolvedCallbacks.push(callback);\n };\n\n // Runs on the client when ssr gets html script tags\n public addQueryResult = (queryKey: string, value: any) => {\n this.resultMap.set(queryKey, {\n type: value.type,\n status: 'success',\n data: value,\n promise: null,\n error: null,\n });\n // send the result to the client\n if (!isServer) {\n // make sure the attrs are there to create stores\n if (!this.db._reactor.attrs) {\n this.db._reactor._setAttrs(value.attrs);\n }\n this.db._reactor._addQueryData(\n value.query,\n value,\n !!this.db._reactor.config.schema,\n );\n }\n };\n\n // creates an entry in the results map\n // and returns the same thing added to the map\n public query = (\n _query: any,\n opts?: {\n ruleParams: RuleParams;\n },\n ): {\n type: 'http' | 'session';\n status: 'pending' | 'success' | 'error';\n promise?: Promise<QueryPromise>;\n data?: any;\n error?: any;\n } => {\n const { hash, query } = this.hashQuery(_query, opts);\n\n if (this.db._reactor.status === 'authenticated') {\n const promise = this.db.queryOnce(_query, opts);\n let entry = {\n status: 'pending' as 'pending' | 'success' | 'error',\n type: 'session' as 'http' | 'session',\n data: undefined as any,\n error: undefined as any,\n promise: promise as any,\n };\n promise.then((result) => {\n entry.status = 'success';\n entry.data = result;\n entry.promise = null;\n });\n promise.catch((error) => {\n entry.status = 'error';\n entry.error = error;\n entry.promise = null;\n });\n this.resultMap.set(hash, entry);\n return entry as any;\n }\n\n const promise = this.getTriplesAndAttrsForQuery(query);\n let entry = {\n status: 'pending' as 'pending' | 'success' | 'error',\n type: 'http' as 'http' | 'session',\n data: undefined as any,\n error: undefined as any,\n promise: promise as any,\n };\n\n promise.then((result) => {\n entry.status = 'success';\n entry.data = result;\n entry.promise = null;\n });\n promise.catch((error) => {\n entry.status = 'error';\n entry.error = error;\n entry.promise = null;\n });\n\n promise.then((result) => {\n this.queryResolvedCallbacks.forEach((callback) => {\n callback({\n queryHash: hash,\n query: query,\n attrs: result.attrs,\n triples: result.triples,\n pageInfo: result.pageInfo,\n });\n });\n });\n\n this.resultMap.set(hash, entry);\n return entry;\n };\n\n public getExistingResultForQuery = (\n _query: any,\n opts?: {\n ruleParams: RuleParams;\n },\n ) => {\n const { hash } = this.hashQuery(_query, opts);\n return this.resultMap.get(hash);\n };\n\n // creates a query result from a set of triples, query, and attrs\n // can be run server side or client side\n public completeIsomorphic = (\n query: any,\n triples: any[],\n attrs: InstantDBAttr[],\n pageInfo?: any,\n ) => {\n const attrMap = {};\n attrs.forEach((attr) => {\n attrMap[attr.id] = attr;\n });\n\n const enableCardinalityInference =\n Boolean(this.db?._reactor?.config?.schema) &&\n ('cardinalityInference' in this.db?._reactor?.config\n ? Boolean(this.db?._reactor.config?.cardinalityInference)\n : true);\n\n const attrsStore = new s.AttrsStoreClass(\n attrs.reduce((acc, attr) => {\n acc[attr.id] = attr;\n return acc;\n }, {}),\n createLinkIndex(this.db?._reactor.config.schema),\n );\n\n const store = s.createStore(\n attrsStore,\n triples,\n enableCardinalityInference,\n this.params.db._reactor.config.useDateObjects || false,\n );\n const resp = instaql(\n {\n store: store,\n attrsStore: attrsStore,\n pageInfo: pageInfo,\n aggregate: undefined,\n },\n query,\n );\n return resp;\n };\n\n public hashQuery = (\n _query: any,\n opts?: {\n ruleParams: RuleParams;\n },\n ): { hash: string; query: any } => {\n if (_query && opts && 'ruleParams' in opts) {\n _query = { $$ruleParams: opts['ruleParams'], ..._query };\n }\n const query = _query ? coerceQuery(_query) : null;\n return { hash: weakHash(query), query: query };\n };\n\n // Run by the server to get triples and attrs\n public getTriplesAndAttrsForQuery = async (\n query: any,\n ): Promise<{\n triples: any[];\n attrs: InstantDBAttr[];\n query: any;\n queryHash: string;\n type: 'http';\n pageInfo?: any;\n }> => {\n try {\n const response = await fetch(\n `${this.db._reactor.config.apiURI}/runtime/framework/query`,\n {\n method: 'POST',\n headers: {\n 'app-id': this.params.db._reactor.config.appId,\n 'Content-Type': 'application/json',\n Authorization: this.params.token\n ? `Bearer ${this.params.token}`\n : undefined,\n } as Record<string, string>,\n body: JSON.stringify({\n query: query,\n }),\n },\n );\n\n if (!response.ok) {\n throw new Error('Error getting triples from server');\n }\n\n const data = await response.json();\n\n const attrs = data?.attrs;\n if (!attrs) {\n throw new Error('No attrs');\n }\n\n // TODO: make safer\n const triples =\n data.result?.[0].data?.['datalog-result']?.['join-rows'][0];\n\n const pageInfo = data.result?.[0]?.data?.['page-info'];\n\n return {\n attrs,\n triples,\n type: 'http',\n queryHash: this.hashQuery(query).hash,\n query,\n pageInfo,\n };\n } catch (err: any) {\n const errWithMessage = new Error(\n 'Error getting triples from framework client',\n );\n // @ts-expect-error pre es2022\n errWithMessage.cause = err;\n throw errWithMessage;\n }\n };\n}\n"]}
1
+ {"version":3,"file":"framework.js","sourceRoot":"","sources":["../../src/framework.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2HAA2H;AAC3H,kGAAkG;AAClG,+FAA+F;AAC/F,OAAO,EACL,WAAW,EAGX,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,CAAC,MAAM,YAAY,CAAC;AAChC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,IAAI,UAAU,CAAC;AAuB9E,MAAM,OAAO,eAAe;IAyB1B,YAAY,MAAuB;QArBnC,6DAA6D;QAC7D,wFAAwF;QACjF,cAAS,GASZ,IAAI,GAAG,EAAE,CAAC;QAEN,2BAAsB,GAMd,EAAE,CAAC;QAiBZ,cAAS,GAAG,CACjB,QAKU,EACV,EAAE;YACF,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC,CAAC;QAEF,oDAAoD;QAC7C,mBAAc,GAAG,CAAC,QAAgB,EAAE,KAAU,EAAE,EAAE;YACvD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE;gBAC3B,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,MAAM,EAAE,SAAS;gBACjB,IAAI,EAAE,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BAClB,MAAM,cAAc,GAAG,IAAI,KAAK,CAC9B,6CAA6C,CAC9C,CAAC;gBACF,8BAA8B;gBAC9B,cAAc,CAAC,KAAK,GAAG,GAAG,CAAC;gBAC3B,MAAM,cAAc,CAAC;YACvB,CAAC;QACH,CAAC,CAAA,CAAC;QA7PA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EASrB,CAAC;IACN,CAAC;CAkPF","sourcesContent":["// The FrameworkClient class is a mini version of a query store that allows making queries on both the frontend and backend\n// you can register queries, await their results and serialize them over a server/client boundary.\n// The class is generic so that it can be a good starting off point to make other ssr adapters.\nimport {\n coerceQuery,\n InstantCoreDatabase,\n InstantDBAttr,\n weakHash,\n} from './index.ts';\nimport * as s from './store.js';\nimport instaql from './instaql.js';\nimport { RuleParams } from './schemaTypes.ts';\nimport { createLinkIndex } from './utils/linkIndex.ts';\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in globalThis;\n\nexport type FrameworkConfig = {\n token?: string | null;\n db: InstantCoreDatabase<any, any>;\n};\n\n// represents an eventual result from running a query\n// either via ssr or by using the existing websocket connection.\ntype QueryPromise =\n | {\n type: 'http';\n triples: any;\n attrs: any;\n queryHash: any;\n query: any;\n pageInfo?: any;\n }\n | {\n type: 'session';\n queryResult: any;\n };\n\nexport class FrameworkClient {\n private params: FrameworkConfig;\n private db: InstantCoreDatabase<any, any>;\n\n // stores all of the query promises so that ssr can read them\n // and send the relevant results alongside the html that resulted in the query resolving\n public resultMap: Map<\n string,\n {\n status: 'pending' | 'success' | 'error';\n type: 'http' | 'session';\n promise?: Promise<QueryPromise> | null;\n data?: any;\n error?: any;\n }\n > = new Map();\n\n private queryResolvedCallbacks: ((result: {\n triples: any;\n attrs: any;\n queryHash: any;\n query: any;\n pageInfo?: any;\n }) => void)[] = [];\n\n constructor(params: FrameworkConfig) {\n this.params = params;\n this.db = params.db;\n this.resultMap = new Map<\n string,\n {\n type: 'http' | 'session';\n status: 'pending' | 'success' | 'error';\n promise?: Promise<QueryPromise>;\n data?: any;\n error?: any;\n }\n >();\n }\n\n public subscribe = (\n callback: (result: {\n triples: any;\n attrs: any;\n queryHash: string;\n pageInfo?: any;\n }) => void,\n ) => {\n this.queryResolvedCallbacks.push(callback);\n };\n\n // Runs on the client when ssr gets html script tags\n public addQueryResult = (queryKey: string, value: any) => {\n this.resultMap.set(queryKey, {\n type: value.type,\n status: 'success',\n data: value,\n promise: null,\n error: null,\n });\n // send the result to the client\n if (!isServer) {\n // make sure the attrs are there to create stores\n if (!this.db._reactor.attrs) {\n this.db._reactor._setAttrs(value.attrs);\n }\n this.db._reactor._addQueryData(\n value.query,\n value,\n !!this.db._reactor.config.schema,\n );\n }\n };\n\n // creates an entry in the results map\n // and returns the same thing added to the map\n public query = (\n _query: any,\n opts?: {\n ruleParams: RuleParams;\n },\n ): {\n type: 'http' | 'session';\n status: 'pending' | 'success' | 'error';\n promise?: Promise<QueryPromise>;\n data?: any;\n error?: any;\n } => {\n const { hash, query } = this.hashQuery(_query, opts);\n\n if (this.db._reactor.status === 'authenticated') {\n const promise = this.db.queryOnce(_query, opts);\n let entry = {\n status: 'pending' as 'pending' | 'success' | 'error',\n type: 'session' as 'http' | 'session',\n data: undefined as any,\n error: undefined as any,\n promise: promise as any,\n };\n promise.then((result) => {\n entry.status = 'success';\n entry.data = result;\n entry.promise = null;\n });\n promise.catch((error) => {\n entry.status = 'error';\n entry.error = error;\n entry.promise = null;\n });\n this.resultMap.set(hash, entry);\n return entry as any;\n }\n\n const promise = this.getTriplesAndAttrsForQuery(query);\n let entry = {\n status: 'pending' as 'pending' | 'success' | 'error',\n type: 'http' as 'http' | 'session',\n data: undefined as any,\n error: undefined as any,\n promise: promise as any,\n };\n\n promise.then((result) => {\n entry.status = 'success';\n entry.data = result;\n entry.promise = null;\n });\n promise.catch((error) => {\n entry.status = 'error';\n entry.error = error;\n entry.promise = null;\n });\n\n promise.then((result) => {\n this.queryResolvedCallbacks.forEach((callback) => {\n callback({\n queryHash: hash,\n query: query,\n attrs: result.attrs,\n triples: result.triples,\n pageInfo: result.pageInfo,\n });\n });\n });\n\n this.resultMap.set(hash, entry);\n return entry;\n };\n\n public getExistingResultForQuery = (\n _query: any,\n opts?: {\n ruleParams: RuleParams;\n },\n ) => {\n const { hash } = this.hashQuery(_query, opts);\n return this.resultMap.get(hash);\n };\n\n // creates a query result from a set of triples, query, and attrs\n // can be run server side or client side\n public completeIsomorphic = (\n query: any,\n triples: any[],\n attrs: InstantDBAttr[],\n pageInfo?: any,\n ) => {\n const attrMap = {};\n attrs.forEach((attr) => {\n attrMap[attr.id] = attr;\n });\n\n const enableCardinalityInference =\n Boolean(this.db?._reactor?.config?.schema) &&\n ('cardinalityInference' in this.db?._reactor?.config\n ? Boolean(this.db?._reactor.config?.cardinalityInference)\n : true);\n\n const attrsStore = new s.AttrsStoreClass(\n attrs.reduce((acc, attr) => {\n acc[attr.id] = attr;\n return acc;\n }, {}),\n createLinkIndex(this.db?._reactor.config.schema),\n );\n\n const store = s.createStore(\n attrsStore,\n triples,\n enableCardinalityInference,\n this.params.db._reactor.config.useDateObjects || false,\n );\n const resp = instaql(\n {\n store: store,\n attrsStore: attrsStore,\n pageInfo: pageInfo,\n aggregate: undefined,\n },\n query,\n );\n return resp;\n };\n\n public hashQuery = (\n _query: any,\n opts?: {\n ruleParams: RuleParams;\n },\n ): { hash: string; query: any } => {\n if (_query && opts && 'ruleParams' in opts) {\n _query = { $$ruleParams: opts['ruleParams'], ..._query };\n }\n const query = _query ? coerceQuery(_query) : null;\n return { hash: weakHash(query), query: query };\n };\n\n // Run by the server to get triples and attrs\n public getTriplesAndAttrsForQuery = async (\n query: any,\n ): Promise<{\n triples: any[];\n attrs: InstantDBAttr[];\n query: any;\n queryHash: string;\n type: 'http';\n pageInfo?: any;\n }> => {\n try {\n const response = await fetch(\n `${this.db._reactor.config.apiURI}/runtime/framework/query`,\n {\n method: 'POST',\n headers: {\n 'app-id': this.params.db._reactor.config.appId,\n 'Content-Type': 'application/json',\n Authorization: this.params.token\n ? `Bearer ${this.params.token}`\n : undefined,\n } as Record<string, string>,\n body: JSON.stringify({\n query: query,\n }),\n },\n );\n\n if (!response.ok) {\n throw new Error('Error getting triples from server');\n }\n\n const data = await response.json();\n\n const attrs = data?.attrs;\n if (!attrs) {\n throw new Error('No attrs');\n }\n\n // TODO: make safer\n const triples =\n data.result?.[0].data?.['datalog-result']?.['join-rows'][0];\n\n const pageInfo = data.result?.[0]?.data?.['page-info'];\n\n return {\n attrs,\n triples,\n type: 'http',\n queryHash: this.hashQuery(query).hash,\n query,\n pageInfo,\n };\n } catch (err: any) {\n const errWithMessage = new Error(\n 'Error getting triples from framework client',\n );\n // @ts-expect-error pre es2022\n errWithMessage.cause = err;\n throw errWithMessage;\n }\n };\n}\n"]}
@@ -2450,7 +2450,7 @@ function Ze(n, e, t) {
2450
2450
  }
2451
2451
  });
2452
2452
  }
2453
- function No(n, e) {
2453
+ function Fo(n, e) {
2454
2454
  return `lookup__${n}__${JSON.stringify(e)}`;
2455
2455
  }
2456
2456
  function Ce(n) {
@@ -2484,7 +2484,7 @@ function Cn() {
2484
2484
  }
2485
2485
  );
2486
2486
  }
2487
- const Fo = Cn();
2487
+ const qo = Cn();
2488
2488
  function Ns(n) {
2489
2489
  return n.__ops;
2490
2490
  }
@@ -3639,7 +3639,7 @@ function rt(n) {
3639
3639
  }, e;
3640
3640
  }, {});
3641
3641
  }
3642
- const Un = "v0.22.93-experimental.drewh-ssr.20383114333.1";
3642
+ const Un = "v0.22.93-experimental.drewh-ssr.20384561223.1";
3643
3643
  function ji(n, e) {
3644
3644
  return {
3645
3645
  info: n ? (...t) => console.info(...t, e()) : () => {
@@ -4749,11 +4749,11 @@ const W = {
4749
4749
  AUTHENTICATED: "authenticated",
4750
4750
  CLOSED: "closed",
4751
4751
  ERRORED: "errored"
4752
- }, Yi = 3e4, Zi = 3e4, Xi = 200, eo = {
4752
+ }, Yi = 3e4, Zi = 3e4, Xi = 200, eo = 1e3 * 60, to = {
4753
4753
  apiURI: "https://api.instantdb.com",
4754
4754
  websocketURI: "wss://api.instantdb.com/runtime/session"
4755
4755
  }, qe = "_instant_oauth_redirect", oe = "currentUser";
4756
- function to({
4756
+ function no({
4757
4757
  transportType: n,
4758
4758
  appId: e,
4759
4759
  apiURI: t,
@@ -4774,7 +4774,7 @@ function to({
4774
4774
  throw new Error("Unknown transport type " + n);
4775
4775
  }
4776
4776
  }
4777
- function no() {
4777
+ function ro() {
4778
4778
  return typeof window < "u" || typeof chrome < "u";
4779
4779
  }
4780
4780
  const Zt = {
@@ -4783,7 +4783,7 @@ const Zt = {
4783
4783
  "refresh-presence": !0,
4784
4784
  "patch-presence": !0
4785
4785
  };
4786
- function ro(n, e) {
4786
+ function so(n, e) {
4787
4787
  var r;
4788
4788
  const t = typeof n == "string" ? JSON.parse(n) : n;
4789
4789
  if ((r = t == null ? void 0 : t.result) != null && r.store) {
@@ -4801,7 +4801,7 @@ function ro(n, e) {
4801
4801
  }
4802
4802
  return t;
4803
4803
  }
4804
- function so(n, e) {
4804
+ function io(n, e) {
4805
4805
  const { result: t, ...r } = e, s = (
4806
4806
  /** @type {import('./reactorTypes.ts').QuerySubInStorage} */
4807
4807
  r
@@ -4816,7 +4816,7 @@ function so(n, e) {
4816
4816
  }
4817
4817
  return s;
4818
4818
  }
4819
- function io(n, e) {
4819
+ function oo(n, e) {
4820
4820
  switch (n) {
4821
4821
  case "pendingMutations":
4822
4822
  return new Map(typeof e == "string" ? JSON.parse(e) : e);
@@ -4824,7 +4824,7 @@ function io(n, e) {
4824
4824
  return e;
4825
4825
  }
4826
4826
  }
4827
- function oo(n, e) {
4827
+ function ao(n, e) {
4828
4828
  switch (n) {
4829
4829
  case "pendingMutations":
4830
4830
  return [...e.entries()];
@@ -4832,7 +4832,7 @@ function oo(n, e) {
4832
4832
  return e;
4833
4833
  }
4834
4834
  }
4835
- function ao(n, e, t) {
4835
+ function co(n, e, t) {
4836
4836
  const r = e == null ? void 0 : e.result, s = t == null ? void 0 : t.result;
4837
4837
  return r && !s && t && (t.result = r), t || e;
4838
4838
  }
@@ -4842,7 +4842,7 @@ function Xt(n) {
4842
4842
  return a == c ? r < i ? -1 : r > i ? 1 : 0 : a - c;
4843
4843
  });
4844
4844
  }
4845
- class co {
4845
+ class uo {
4846
4846
  constructor(e, t = jn, r = $n, s, i) {
4847
4847
  /** @type {s.AttrsStore | undefined} */
4848
4848
  T(this, "attrs");
@@ -5078,10 +5078,10 @@ class co {
5078
5078
  this._reconnectTimeoutMs
5079
5079
  ), this._scheduleReconnect();
5080
5080
  });
5081
- if (this._EventSource = i, this.config = { ...eo, ...e }, this.queryCacheLimit = this.config.queryCacheLimit ?? 10, this._pendingTxCleanupTimeout = this.config.pendingTxCleanupTimeout ?? Zi, this._pendingMutationCleanupThreshold = this.config.pendingMutationCleanupThreshold ?? Xi, this._log = ji(
5081
+ if (this._EventSource = i, this.config = { ...to, ...e }, this.queryCacheLimit = this.config.queryCacheLimit ?? 10, this._pendingTxCleanupTimeout = this.config.pendingTxCleanupTimeout ?? Zi, this._pendingMutationCleanupThreshold = this.config.pendingMutationCleanupThreshold ?? Xi, this._log = ji(
5082
5082
  e.verbose || _t || Dn,
5083
5083
  () => this._reactorStats()
5084
- ), this.versions = { ...s || {}, "@instantdb/core": Un }, this.config.schema && (this._linkIndex = rt(this.config.schema)), !!no()) {
5084
+ ), this.versions = { ...s || {}, "@instantdb/core": Un }, this.config.schema && (this._linkIndex = rt(this.config.schema)), !!ro()) {
5085
5085
  if (!e.appId)
5086
5086
  throw new Error("Instant must be initialized with an appId.");
5087
5087
  if (!re(e.appId))
@@ -5117,7 +5117,7 @@ class co {
5117
5117
  }), setInterval(async () => {
5118
5118
  const o = await this.getCurrentUser();
5119
5119
  this.syncUserToEndpoint(o.user);
5120
- }, 1e3 * 60), r.getIsOnline().then((o) => {
5120
+ }, eo), r.getIsOnline().then((o) => {
5121
5121
  this._isOnline = o, this._startSocket(), r.listen((a) => {
5122
5122
  a !== this._isOnline && (this._log.info("[network] online =", a), this._isOnline = a, this._isOnline ? this._startSocket() : (this._log.info(
5123
5123
  "Changing status from",
@@ -5154,9 +5154,9 @@ class co {
5154
5154
  _initStorage(e) {
5155
5155
  this.querySubs = new nt({
5156
5156
  persister: new e(this.config.appId, "querySubs"),
5157
- merge: ao,
5158
- serialize: so,
5159
- parse: (t, r) => ro(r, this.config.useDateObjects),
5157
+ merge: co,
5158
+ serialize: io,
5159
+ parse: (t, r) => so(r, this.config.useDateObjects),
5160
5160
  // objectSize
5161
5161
  objectSize: (t) => {
5162
5162
  var r, s, i;
@@ -5175,8 +5175,8 @@ class co {
5175
5175
  }), this.querySubs.onKeyLoaded = (t) => this._onQuerySubLoaded(t), this.kv = new nt({
5176
5176
  persister: new e(this.config.appId, "kv"),
5177
5177
  merge: this._onMergeKv,
5178
- serialize: oo,
5179
- parse: io,
5178
+ serialize: ao,
5179
+ parse: oo,
5180
5180
  objectSize: () => 0,
5181
5181
  logger: this._log,
5182
5182
  saveThrottleMs: 100,
@@ -5830,7 +5830,7 @@ class co {
5830
5830
  return;
5831
5831
  }
5832
5832
  const e = this._transport;
5833
- this._transport = to({
5833
+ this._transport = no({
5834
5834
  transportType: this._transportType,
5835
5835
  appId: this.config.appId,
5836
5836
  apiURI: this.config.apiURI,
@@ -6352,7 +6352,7 @@ class co {
6352
6352
  });
6353
6353
  }
6354
6354
  }
6355
- function uo(n, e) {
6355
+ function lo(n, e) {
6356
6356
  return new De(
6357
6357
  Vn(n, e),
6358
6358
  // (XXX): LinksDef<any> stems from TypeScript’s inability to reconcile the
@@ -6364,25 +6364,25 @@ function uo(n, e) {
6364
6364
  void 0
6365
6365
  );
6366
6366
  }
6367
- function lo(n) {
6367
+ function fo(n) {
6368
6368
  return new $e(n, {});
6369
6369
  }
6370
- function fo() {
6370
+ function ho() {
6371
6371
  return new D("string", !0, !1);
6372
6372
  }
6373
- function ho() {
6373
+ function po() {
6374
6374
  return new D("number", !0, !1);
6375
6375
  }
6376
- function po() {
6376
+ function yo() {
6377
6377
  return new D("boolean", !0, !1);
6378
6378
  }
6379
- function yo() {
6379
+ function bo() {
6380
6380
  return new D("date", !0, !1);
6381
6381
  }
6382
- function bo() {
6382
+ function go() {
6383
6383
  return new D("json", !0, !1);
6384
6384
  }
6385
- function go() {
6385
+ function _o() {
6386
6386
  return new D("json", !0, !1);
6387
6387
  }
6388
6388
  function Vn(n, e) {
@@ -6406,7 +6406,7 @@ function Vn(n, e) {
6406
6406
  ])
6407
6407
  );
6408
6408
  }
6409
- function _o({
6409
+ function wo({
6410
6410
  entities: n,
6411
6411
  links: e,
6412
6412
  rooms: t
@@ -6425,21 +6425,21 @@ function _o({
6425
6425
  }
6426
6426
  const E = {
6427
6427
  // constructs
6428
- graph: uo,
6429
- schema: _o,
6430
- entity: lo,
6428
+ graph: lo,
6429
+ schema: wo,
6430
+ entity: fo,
6431
6431
  // value types
6432
- string: fo,
6433
- number: ho,
6434
- boolean: po,
6435
- date: yo,
6436
- json: bo,
6437
- any: go
6432
+ string: ho,
6433
+ number: po,
6434
+ boolean: yo,
6435
+ date: bo,
6436
+ json: go,
6437
+ any: _o
6438
6438
  };
6439
6439
  let Te;
6440
- function wo(n, e) {
6440
+ function To(n, e) {
6441
6441
  Te == null || Te.dispose();
6442
- const t = vo(e), r = So(e, a), s = mo(To(n));
6442
+ const t = ko(e), r = Ao(e, a), s = So(mo(n));
6443
6443
  function i(l) {
6444
6444
  var f;
6445
6445
  l.source === s.element.contentWindow && ((f = l.data) == null ? void 0 : f.type) === "close" && t.isVisible() && a();
@@ -6461,10 +6461,10 @@ function wo(n, e) {
6461
6461
  }
6462
6462
  return u();
6463
6463
  }
6464
- function To(n) {
6464
+ function mo(n) {
6465
6465
  return `${_t || Rn ? "http://localhost:3000" : "https://instantdb.com"}/_devtool?appId=${n}`;
6466
6466
  }
6467
- function mo(n) {
6467
+ function So(n) {
6468
6468
  const e = document.createElement("iframe");
6469
6469
  return e.src = n, e.className = "instant-devtool-iframe", Object.assign(e.style, {
6470
6470
  width: "100%",
@@ -6473,7 +6473,7 @@ function mo(n) {
6473
6473
  border: "none"
6474
6474
  }), { element: e };
6475
6475
  }
6476
- function So(n, e) {
6476
+ function Ao(n, e) {
6477
6477
  const t = `
6478
6478
  <svg width="32" height="32" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
6479
6479
  <rect width="512" height="512" fill="black"/>
@@ -6483,7 +6483,7 @@ function So(n, e) {
6483
6483
  return r.innerHTML = t, r.className = "instant-devtool-toggler", Object.assign(r.style, {
6484
6484
  // pos
6485
6485
  position: "fixed",
6486
- ...Ao(n.position),
6486
+ ...Oo(n.position),
6487
6487
  height: "32px",
6488
6488
  width: "32px",
6489
6489
  // layout
@@ -6498,7 +6498,7 @@ function So(n, e) {
6498
6498
  cursor: "pointer"
6499
6499
  }), r.addEventListener("click", e), { element: r };
6500
6500
  }
6501
- function Ao(n) {
6501
+ function Oo(n) {
6502
6502
  switch (n) {
6503
6503
  case "bottom-left":
6504
6504
  return { bottom: "24px", left: "24px" };
@@ -6510,7 +6510,7 @@ function Ao(n) {
6510
6510
  return { top: "24px", left: "24px" };
6511
6511
  }
6512
6512
  }
6513
- function Oo(n) {
6513
+ function vo(n) {
6514
6514
  switch (n) {
6515
6515
  case "bottom-left":
6516
6516
  return { bottom: "24px", right: "24px", left: "60px", top: "72px" };
@@ -6522,11 +6522,11 @@ function Oo(n) {
6522
6522
  return { top: "24px", right: "24px", left: "60px", bottom: "72px" };
6523
6523
  }
6524
6524
  }
6525
- function vo(n) {
6525
+ function ko(n) {
6526
6526
  const e = document.createElement("div");
6527
6527
  Object.assign(e.style, {
6528
6528
  position: "fixed",
6529
- ...Oo(n.position),
6529
+ ...vo(n.position),
6530
6530
  display: "block",
6531
6531
  borderRadius: "4px",
6532
6532
  border: "1px #ccc solid",
@@ -6539,18 +6539,18 @@ function vo(n) {
6539
6539
  }
6540
6540
  return { element: e, isVisible: t };
6541
6541
  }
6542
- function ko(n, e) {
6543
- return n && n.refresh_token ? new Response(JSON.stringify({ ok: !0 }), {
6542
+ function Eo(n, e) {
6543
+ return e && e.refresh_token ? new Response(JSON.stringify({ ok: !0 }), {
6544
6544
  headers: {
6545
6545
  "Content-Type": "application/json",
6546
6546
  // 7 day expiry
6547
- "Set-Cookie": `instant_user_${e.appId}=${JSON.stringify(n)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`
6547
+ "Set-Cookie": `instant_user_${n.appId}=${JSON.stringify(e)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`
6548
6548
  }
6549
6549
  }) : new Response(JSON.stringify({ ok: !0 }), {
6550
6550
  headers: {
6551
6551
  "Content-Type": "application/json",
6552
6552
  // remove the cookie (some browsers)
6553
- "Set-Cookie": `instant_user_${e.appId}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`
6553
+ "Set-Cookie": `instant_user_${n.appId}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`
6554
6554
  }
6555
6555
  });
6556
6556
  }
@@ -6560,7 +6560,7 @@ function me(n, e) {
6560
6560
  headers: { "Content-Type": "application/json" }
6561
6561
  });
6562
6562
  }
6563
- const qo = (n) => ({
6563
+ const Ko = (n) => ({
6564
6564
  POST: async (e) => {
6565
6565
  let t;
6566
6566
  try {
@@ -6574,12 +6574,12 @@ const qo = (n) => ({
6574
6574
  return me(403, "App ID mismatch");
6575
6575
  switch (t.type) {
6576
6576
  case "sync-user":
6577
- return ko(t.user ?? null, n);
6577
+ return Eo(n, t.user ?? null);
6578
6578
  default:
6579
6579
  return me(400, `Unknown type: ${t.type}`);
6580
6580
  }
6581
6581
  }
6582
- }), Ko = (n) => {
6582
+ }), zo = (n) => {
6583
6583
  var i, o, a, c, u, l;
6584
6584
  const e = {};
6585
6585
  for (const [f, d] of Object.entries(n.entities)) {
@@ -6680,8 +6680,8 @@ const qo = (n) => ({
6680
6680
  links: t,
6681
6681
  rooms: r
6682
6682
  });
6683
- }, Eo = typeof window > "u" || "Deno" in globalThis;
6684
- class zo {
6683
+ }, Io = typeof window > "u" || "Deno" in globalThis;
6684
+ class Vo {
6685
6685
  constructor(e) {
6686
6686
  this.resultMap = /* @__PURE__ */ new Map(), this.queryResolvedCallbacks = [], this.subscribe = (t) => {
6687
6687
  this.queryResolvedCallbacks.push(t);
@@ -6692,7 +6692,7 @@ class zo {
6692
6692
  data: r,
6693
6693
  promise: null,
6694
6694
  error: null
6695
- }), Eo || (this.db._reactor.attrs || this.db._reactor._setAttrs(r.attrs), this.db._reactor._addQueryData(
6695
+ }), Io || (this.db._reactor.attrs || this.db._reactor._setAttrs(r.attrs), this.db._reactor._addQueryData(
6696
6696
  r.query,
6697
6697
  r,
6698
6698
  !!this.db._reactor.config.schema
@@ -6766,7 +6766,7 @@ class zo {
6766
6766
  );
6767
6767
  }, this.hashQuery = (t, r) => {
6768
6768
  t && r && "ruleParams" in r && (t = { $$ruleParams: r.ruleParams, ...t });
6769
- const s = t ? $o(t) : null;
6769
+ const s = t ? Do(t) : null;
6770
6770
  return { hash: M(s), query: s };
6771
6771
  }, this.getTriplesAndAttrsForQuery = async (t) => {
6772
6772
  var r, s, i, o, a, c;
@@ -6808,37 +6808,37 @@ class zo {
6808
6808
  }, this.params = e, this.db = e.db, this.resultMap = /* @__PURE__ */ new Map();
6809
6809
  }
6810
6810
  }
6811
- const Io = {
6811
+ const Co = {
6812
6812
  apiURI: "https://api.instantdb.com",
6813
6813
  websocketURI: "wss://api.instantdb.com/runtime/session"
6814
6814
  };
6815
- function Co() {
6815
+ function Mo() {
6816
6816
  return globalThis.__instantDbSchemaHashStore = globalThis.__instantDbSchemaHashStore ?? /* @__PURE__ */ new WeakMap(), globalThis.__instantDbSchemaHashStore;
6817
6817
  }
6818
- function Mo() {
6818
+ function Po() {
6819
6819
  return globalThis.__instantDbStore = globalThis.__instantDbStore ?? {}, globalThis.__instantDbStore;
6820
6820
  }
6821
6821
  function st(n) {
6822
6822
  const e = n.__adminToken;
6823
6823
  return n.appId + "_" + (n.websocketURI || "default_ws_uri") + "_" + (n.apiURI || "default_api_uri") + "_" + (e || "client_only") + "_" + n.useDateObjects;
6824
6824
  }
6825
- const it = Mo(), en = Co();
6826
- class Po {
6825
+ const it = Po(), en = Mo();
6826
+ class jo {
6827
6827
  constructor(e) {
6828
6828
  this.db = e, this.sendMagicCode = (t) => this.db.sendMagicCode(t), this.signInWithMagicCode = (t) => this.db.signInWithMagicCode(t), this.signInWithToken = (t) => this.db.signInWithCustomToken(t), this.signInAsGuest = () => this.db.signInAsGuest(), this.createAuthorizationURL = (t) => this.db.createAuthorizationURL(t), this.signInWithIdToken = (t) => this.db.signInWithIdToken(t), this.exchangeOAuthCode = (t) => this.db.exchangeCodeForToken(t), this.issuerURI = () => this.db.issuerURI(), this.signOut = (t = { invalidateToken: !0 }) => this.db.signOut(t);
6829
6829
  }
6830
6830
  }
6831
- class jo {
6831
+ class $o {
6832
6832
  constructor(e) {
6833
6833
  this.db = e, this.uploadFile = (t, r, s = {}) => this.db.uploadFile(t, r, s), this.delete = (t) => this.db.deleteFile(t), this.upload = (t, r) => this.db.upload(t, r), this.put = this.upload, this.getDownloadUrl = (t) => this.db.getDownloadUrl(t);
6834
6834
  }
6835
6835
  }
6836
- function $o(n) {
6836
+ function Do(n) {
6837
6837
  return JSON.parse(JSON.stringify(n));
6838
6838
  }
6839
- class Do {
6839
+ class Ro {
6840
6840
  constructor(e) {
6841
- this.tx = Cn(), this._reactor = e, this.auth = new Po(this._reactor), this.storage = new jo(this._reactor);
6841
+ this.tx = Cn(), this._reactor = e, this.auth = new jo(this._reactor), this.storage = new $o(this._reactor);
6842
6842
  }
6843
6843
  /**
6844
6844
  * Use this to write data! You can create, update, delete, and link objects
@@ -7021,10 +7021,10 @@ function tn(n) {
7021
7021
  const t = M(n);
7022
7022
  return en.set(n, t), t;
7023
7023
  }
7024
- function Ro(n, e) {
7024
+ function xo(n, e) {
7025
7025
  return tn(n._reactor.config.schema) !== tn(e);
7026
7026
  }
7027
- function xo(n, e, t, r, s) {
7027
+ function Uo(n, e, t, r, s) {
7028
7028
  var u;
7029
7029
  const i = {
7030
7030
  ...n,
@@ -7032,10 +7032,10 @@ function xo(n, e, t, r, s) {
7032
7032
  useDateObjects: n.useDateObjects ?? !1
7033
7033
  }, o = it[st(i)];
7034
7034
  if (o)
7035
- return Ro(o, i.schema) && o._reactor.updateSchema(i.schema), o;
7036
- const a = new co(
7035
+ return xo(o, i.schema) && o._reactor.updateSchema(i.schema), o;
7036
+ const a = new uo(
7037
7037
  {
7038
- ...Io,
7038
+ ...Co,
7039
7039
  ...i,
7040
7040
  cardinalityInference: !!i.schema
7041
7041
  },
@@ -7043,10 +7043,10 @@ function xo(n, e, t, r, s) {
7043
7043
  t || $n,
7044
7044
  { ...r || {}, "@instantdb/core": Un },
7045
7045
  s
7046
- ), c = new Do(a);
7047
- return it[st(i)] = c, Uo(i.appId, i.devtool), c;
7046
+ ), c = new Ro(a);
7047
+ return it[st(i)] = c, Lo(i.appId, i.devtool), c;
7048
7048
  }
7049
- function Uo(n, e) {
7049
+ function Lo(n, e) {
7050
7050
  if (typeof window > "u" || typeof window.location > "u" || typeof document > "u" || typeof e == "boolean" && !e)
7051
7051
  return;
7052
7052
  const t = {
@@ -7054,33 +7054,33 @@ function Uo(n, e) {
7054
7054
  allowedHosts: ["localhost"],
7055
7055
  ...typeof e == "object" ? e : {}
7056
7056
  };
7057
- t.allowedHosts.includes(window.location.hostname) && wo(n, t);
7057
+ t.allowedHosts.includes(window.location.hostname) && To(n, t);
7058
7058
  }
7059
- const Vo = xo;
7059
+ const Qo = Uo;
7060
7060
  export {
7061
- Po as Auth,
7062
- zo as FrameworkClient,
7061
+ jo as Auth,
7062
+ Vo as FrameworkClient,
7063
7063
  jn as IndexedDBStorage,
7064
7064
  je as InstantAPIError,
7065
- Do as InstantCoreDatabase,
7065
+ Ro as InstantCoreDatabase,
7066
7066
  pe as InstantError,
7067
7067
  k as QueryValidationError,
7068
- jo as Storage,
7068
+ $o as Storage,
7069
7069
  di as StorageInterface,
7070
7070
  Hi as SyncTableCallbackEventType,
7071
7071
  q as TransactionValidationError,
7072
7072
  $n as WindowNetworkListener,
7073
- $o as coerceQuery,
7073
+ Do as coerceQuery,
7074
7074
  Me as coerceToDate,
7075
- qo as createInstantRouteHandler,
7075
+ Ko as createInstantRouteHandler,
7076
7076
  Ns as getOps,
7077
7077
  E as i,
7078
7078
  P as id,
7079
- xo as init,
7080
- Vo as init_experimental,
7081
- No as lookup,
7082
- Ko as parseSchemaFromJSON,
7083
- Fo as tx,
7079
+ Uo as init,
7080
+ Qo as init_experimental,
7081
+ Fo as lookup,
7082
+ zo as parseSchemaFromJSON,
7083
+ qo as tx,
7084
7084
  Cn as txInit,
7085
7085
  Wt as validateQuery,
7086
7086
  qi as validateTransactions,