@instantdb/core 0.22.97 → 0.22.98-experimental.drewh-ts-target.20762041587.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.
- package/dist/commonjs/Connection.js +50 -51
- package/dist/commonjs/Connection.js.map +1 -1
- package/dist/commonjs/InMemoryStorage.js +13 -32
- package/dist/commonjs/InMemoryStorage.js.map +1 -1
- package/dist/commonjs/IndexedDBStorage.js +193 -217
- package/dist/commonjs/IndexedDBStorage.js.map +1 -1
- package/dist/commonjs/InstantError.js +1 -0
- package/dist/commonjs/InstantError.js.map +1 -1
- package/dist/commonjs/Reactor.js +566 -610
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/StorageAPI.js +51 -70
- package/dist/commonjs/StorageAPI.js.map +1 -1
- package/dist/commonjs/SyncTable.js +68 -81
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/WindowNetworkListener.js +2 -13
- package/dist/commonjs/WindowNetworkListener.js.map +1 -1
- package/dist/commonjs/__types__/fieldsTypeTest.js +8 -16
- package/dist/commonjs/__types__/fieldsTypeTest.js.map +1 -1
- package/dist/commonjs/__types__/useDatesTypeTest.js +3 -6
- package/dist/commonjs/__types__/useDatesTypeTest.js.map +1 -1
- package/dist/commonjs/authAPI.js +62 -79
- package/dist/commonjs/authAPI.js.map +1 -1
- package/dist/commonjs/createRouteHandler.js +5 -15
- package/dist/commonjs/createRouteHandler.js.map +1 -1
- package/dist/commonjs/datalog.js +1 -1
- package/dist/commonjs/datalog.js.map +1 -1
- package/dist/commonjs/devtool.js +26 -8
- package/dist/commonjs/devtool.js.map +1 -1
- package/dist/commonjs/framework.d.ts.map +1 -1
- package/dist/commonjs/framework.js +142 -152
- package/dist/commonjs/framework.js.map +1 -1
- package/dist/commonjs/index.js +204 -190
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/instaml.js +44 -30
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.js +25 -33
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/parseSchemaFromJSON.js +6 -7
- package/dist/commonjs/parseSchemaFromJSON.js.map +1 -1
- package/dist/commonjs/presence.js +7 -8
- package/dist/commonjs/presence.js.map +1 -1
- package/dist/commonjs/queryValidation.js +1 -2
- package/dist/commonjs/queryValidation.js.map +1 -1
- package/dist/commonjs/schema.js +8 -6
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/schemaTypes.js +22 -3
- package/dist/commonjs/schemaTypes.js.map +1 -1
- package/dist/commonjs/store.js +29 -38
- package/dist/commonjs/store.js.map +1 -1
- package/dist/commonjs/transactionValidation.js +1 -2
- package/dist/commonjs/transactionValidation.js.map +1 -1
- package/dist/commonjs/utils/Deferred.js +3 -0
- package/dist/commonjs/utils/Deferred.js.map +1 -1
- package/dist/commonjs/utils/PersistedObject.js +216 -233
- package/dist/commonjs/utils/PersistedObject.js.map +1 -1
- package/dist/commonjs/utils/fetch.js +9 -19
- package/dist/commonjs/utils/fetch.js.map +1 -1
- package/dist/commonjs/utils/linkIndex.js +2 -4
- package/dist/commonjs/utils/linkIndex.js.map +1 -1
- package/dist/commonjs/utils/object.js +1 -1
- package/dist/commonjs/utils/object.js.map +1 -1
- package/dist/esm/Connection.js +50 -51
- package/dist/esm/Connection.js.map +1 -1
- package/dist/esm/InMemoryStorage.js +13 -32
- package/dist/esm/InMemoryStorage.js.map +1 -1
- package/dist/esm/IndexedDBStorage.js +193 -217
- package/dist/esm/IndexedDBStorage.js.map +1 -1
- package/dist/esm/InstantError.js +1 -0
- package/dist/esm/InstantError.js.map +1 -1
- package/dist/esm/Reactor.js +566 -610
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/StorageAPI.js +51 -70
- package/dist/esm/StorageAPI.js.map +1 -1
- package/dist/esm/SyncTable.js +68 -81
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/WindowNetworkListener.js +2 -13
- package/dist/esm/WindowNetworkListener.js.map +1 -1
- package/dist/esm/__types__/fieldsTypeTest.js +8 -16
- package/dist/esm/__types__/fieldsTypeTest.js.map +1 -1
- package/dist/esm/__types__/useDatesTypeTest.js +3 -6
- package/dist/esm/__types__/useDatesTypeTest.js.map +1 -1
- package/dist/esm/authAPI.js +62 -79
- package/dist/esm/authAPI.js.map +1 -1
- package/dist/esm/createRouteHandler.js +5 -15
- package/dist/esm/createRouteHandler.js.map +1 -1
- package/dist/esm/datalog.js +1 -1
- package/dist/esm/datalog.js.map +1 -1
- package/dist/esm/devtool.js +26 -8
- package/dist/esm/devtool.js.map +1 -1
- package/dist/esm/framework.d.ts.map +1 -1
- package/dist/esm/framework.js +142 -152
- package/dist/esm/framework.js.map +1 -1
- package/dist/esm/index.js +204 -190
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instaml.js +44 -30
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.js +25 -33
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/parseSchemaFromJSON.js +6 -7
- package/dist/esm/parseSchemaFromJSON.js.map +1 -1
- package/dist/esm/presence.js +7 -8
- package/dist/esm/presence.js.map +1 -1
- package/dist/esm/queryValidation.js +1 -2
- package/dist/esm/queryValidation.js.map +1 -1
- package/dist/esm/schema.js +8 -6
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/schemaTypes.js +22 -3
- package/dist/esm/schemaTypes.js.map +1 -1
- package/dist/esm/store.js +29 -38
- package/dist/esm/store.js.map +1 -1
- package/dist/esm/transactionValidation.js +1 -2
- package/dist/esm/transactionValidation.js.map +1 -1
- package/dist/esm/utils/Deferred.js +3 -0
- package/dist/esm/utils/Deferred.js.map +1 -1
- package/dist/esm/utils/PersistedObject.js +216 -233
- package/dist/esm/utils/PersistedObject.js.map +1 -1
- package/dist/esm/utils/fetch.js +9 -19
- package/dist/esm/utils/fetch.js.map +1 -1
- package/dist/esm/utils/linkIndex.js +2 -4
- package/dist/esm/utils/linkIndex.js.map +1 -1
- package/dist/esm/utils/object.js +1 -1
- package/dist/esm/utils/object.js.map +1 -1
- package/dist/standalone/index.js +2610 -2367
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/framework.ts +0 -1
|
@@ -1 +1 @@
|
|
|
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,KAAK;gBACX,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;YACH,gCAAgC;YAChC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,iDAAiD;gBACjD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,Q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AC;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"]}
|
|
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;IAClB,MAAM,CAAkB;IACxB,EAAE,CAAgC;IAE1C,6DAA6D;IAC7D,wFAAwF;IACjF,SAAS,GASZ,IAAI,GAAG,EAAE,CAAC;IAEN,sBAAsB,GAMd,EAAE,CAAC;IAEnB,YAAY,MAAuB;QACjC,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;IAEM,SAAS,GAAG,CACjB,QAKU,EACV,EAAE;QACF,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,QAAQ,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AAC,CAAC,IAAI;gBACrC,KAAK;gBACL,QAAQ;aACT,CAAC;QACJ,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,cAAc,GAAG,IAAI,KAAK,CAC9B,6CAA6C,CAC9C,CAAC;YACF,cAAc,CAAC,KAAK,GAAG,GAAG,CAAC;YAC3B,MAAM,cAAc,CAAC;QACvB,CAAC;IACH,CAAC,CAAC;CACH","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 errWithMessage.cause = err;\n throw errWithMessage;\n }\n };\n}\n"]}
|
package/dist/esm/index.js
CHANGED
|
@@ -25,14 +25,12 @@ const defaultConfig = {
|
|
|
25
25
|
};
|
|
26
26
|
// hmr
|
|
27
27
|
function initSchemaHashStore() {
|
|
28
|
-
var _a;
|
|
29
28
|
globalThis.__instantDbSchemaHashStore =
|
|
30
|
-
|
|
29
|
+
globalThis.__instantDbSchemaHashStore ?? new WeakMap();
|
|
31
30
|
return globalThis.__instantDbSchemaHashStore;
|
|
32
31
|
}
|
|
33
32
|
function initGlobalInstantCoreStore() {
|
|
34
|
-
|
|
35
|
-
globalThis.__instantDbStore = (_a = globalThis.__instantDbStore) !== null && _a !== void 0 ? _a : {};
|
|
33
|
+
globalThis.__instantDbStore = globalThis.__instantDbStore ?? {};
|
|
36
34
|
return globalThis.__instantDbStore;
|
|
37
35
|
}
|
|
38
36
|
function reactorKey(config) {
|
|
@@ -56,197 +54,199 @@ const schemaHashStore = initSchemaHashStore();
|
|
|
56
54
|
* @see https://instantdb.com/docs/auth
|
|
57
55
|
*/
|
|
58
56
|
class Auth {
|
|
57
|
+
db;
|
|
59
58
|
constructor(db) {
|
|
60
59
|
this.db = db;
|
|
61
|
-
/**
|
|
62
|
-
* Sends a magic code to the user's email address.
|
|
63
|
-
*
|
|
64
|
-
* Once you send the magic code, see {@link auth.signInWithMagicCode} to let the
|
|
65
|
-
* user verify.
|
|
66
|
-
*
|
|
67
|
-
* @see https://instantdb.com/docs/auth
|
|
68
|
-
* @example
|
|
69
|
-
* db.auth.sendMagicCode({email: "example@gmail.com"})
|
|
70
|
-
* .catch((err) => console.error(err.body?.message))
|
|
71
|
-
*/
|
|
72
|
-
this.sendMagicCode = (params) => {
|
|
73
|
-
return this.db.sendMagicCode(params);
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Verify a magic code that was sent to the user's email address.
|
|
77
|
-
*
|
|
78
|
-
* @see https://instantdb.com/docs/auth
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* db.auth.signInWithMagicCode({email: "example@gmail.com", code: "123456"})
|
|
82
|
-
* .catch((err) => console.error(err.body?.message))
|
|
83
|
-
*/
|
|
84
|
-
this.signInWithMagicCode = (params) => {
|
|
85
|
-
return this.db.signInWithMagicCode(params);
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Sign in a user with a refresh token
|
|
89
|
-
*
|
|
90
|
-
* @see https://instantdb.com/docs/backend#frontend-auth-sign-in-with-token
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* // Get the token from your backend
|
|
94
|
-
* const token = await fetch('/signin', ...);
|
|
95
|
-
* //Sign in
|
|
96
|
-
* db.auth.signInWithToken(token);
|
|
97
|
-
*/
|
|
98
|
-
this.signInWithToken = (token) => {
|
|
99
|
-
return this.db.signInWithCustomToken(token);
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Sign in as guest, creating a new user without email
|
|
103
|
-
*
|
|
104
|
-
* @see https://instantdb.com/docs/auth
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* db.auth.signInAsGuest();
|
|
108
|
-
*/
|
|
109
|
-
this.signInAsGuest = () => {
|
|
110
|
-
return this.db.signInAsGuest();
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Create an authorization url to sign in with an external provider.
|
|
114
|
-
*
|
|
115
|
-
* @see https://instantdb.com/docs/auth
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* // Get the authorization url from your backend
|
|
119
|
-
* const url = db.auth.createAuthorizationUrl({
|
|
120
|
-
* clientName: "google",
|
|
121
|
-
* redirectURL: window.location.href,
|
|
122
|
-
* });
|
|
123
|
-
*
|
|
124
|
-
* // Put it in a sign in link
|
|
125
|
-
* <a href={url}>Log in with Google</a>
|
|
126
|
-
*/
|
|
127
|
-
this.createAuthorizationURL = (params) => {
|
|
128
|
-
return this.db.createAuthorizationURL(params);
|
|
129
|
-
};
|
|
130
|
-
/**
|
|
131
|
-
* Sign in with the id_token from an external provider like Google
|
|
132
|
-
*
|
|
133
|
-
* @see https://instantdb.com/docs/auth
|
|
134
|
-
* @example
|
|
135
|
-
* db.auth
|
|
136
|
-
* .signInWithIdToken({
|
|
137
|
-
* // Token from external service
|
|
138
|
-
* idToken: id_token,
|
|
139
|
-
* // The name you gave the client when you registered it with Instant
|
|
140
|
-
* clientName: "google",
|
|
141
|
-
* // The nonce, if any, that you used when you initiated the auth flow
|
|
142
|
-
* // with the external service.
|
|
143
|
-
* nonce: your_nonce
|
|
144
|
-
* })
|
|
145
|
-
* .catch((err) => console.error(err.body?.message));
|
|
146
|
-
*
|
|
147
|
-
*/
|
|
148
|
-
this.signInWithIdToken = (params) => {
|
|
149
|
-
return this.db.signInWithIdToken(params);
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Sign in with the id_token from an external provider like Google
|
|
153
|
-
*
|
|
154
|
-
* @see https://instantdb.com/docs/auth
|
|
155
|
-
* @example
|
|
156
|
-
* db.auth
|
|
157
|
-
* .exchangeOAuthCode({
|
|
158
|
-
* // code received in redirect from OAuth callback
|
|
159
|
-
* code: code
|
|
160
|
-
* // The PKCE code_verifier, if any, that you used when you
|
|
161
|
-
* // initiated the auth flow
|
|
162
|
-
* codeVerifier: your_code_verifier
|
|
163
|
-
* })
|
|
164
|
-
* .catch((err) => console.error(err.body?.message));
|
|
165
|
-
*
|
|
166
|
-
*/
|
|
167
|
-
this.exchangeOAuthCode = (params) => {
|
|
168
|
-
return this.db.exchangeCodeForToken(params);
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* OpenID Discovery path for use with tools like
|
|
172
|
-
* expo-auth-session that use auto-discovery of
|
|
173
|
-
* OAuth parameters.
|
|
174
|
-
*
|
|
175
|
-
* @see https://instantdb.com/docs/auth
|
|
176
|
-
* @example
|
|
177
|
-
* const discovery = useAutoDiscovery(
|
|
178
|
-
* db.auth.issuerURI()
|
|
179
|
-
* );
|
|
180
|
-
*/
|
|
181
|
-
this.issuerURI = () => {
|
|
182
|
-
return this.db.issuerURI();
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* Sign out the current user
|
|
186
|
-
*/
|
|
187
|
-
this.signOut = (opts = { invalidateToken: true }) => {
|
|
188
|
-
return this.db.signOut(opts);
|
|
189
|
-
};
|
|
190
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Sends a magic code to the user's email address.
|
|
63
|
+
*
|
|
64
|
+
* Once you send the magic code, see {@link auth.signInWithMagicCode} to let the
|
|
65
|
+
* user verify.
|
|
66
|
+
*
|
|
67
|
+
* @see https://instantdb.com/docs/auth
|
|
68
|
+
* @example
|
|
69
|
+
* db.auth.sendMagicCode({email: "example@gmail.com"})
|
|
70
|
+
* .catch((err) => console.error(err.body?.message))
|
|
71
|
+
*/
|
|
72
|
+
sendMagicCode = (params) => {
|
|
73
|
+
return this.db.sendMagicCode(params);
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Verify a magic code that was sent to the user's email address.
|
|
77
|
+
*
|
|
78
|
+
* @see https://instantdb.com/docs/auth
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* db.auth.signInWithMagicCode({email: "example@gmail.com", code: "123456"})
|
|
82
|
+
* .catch((err) => console.error(err.body?.message))
|
|
83
|
+
*/
|
|
84
|
+
signInWithMagicCode = (params) => {
|
|
85
|
+
return this.db.signInWithMagicCode(params);
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Sign in a user with a refresh token
|
|
89
|
+
*
|
|
90
|
+
* @see https://instantdb.com/docs/backend#frontend-auth-sign-in-with-token
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* // Get the token from your backend
|
|
94
|
+
* const token = await fetch('/signin', ...);
|
|
95
|
+
* //Sign in
|
|
96
|
+
* db.auth.signInWithToken(token);
|
|
97
|
+
*/
|
|
98
|
+
signInWithToken = (token) => {
|
|
99
|
+
return this.db.signInWithCustomToken(token);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Sign in as guest, creating a new user without email
|
|
103
|
+
*
|
|
104
|
+
* @see https://instantdb.com/docs/auth
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* db.auth.signInAsGuest();
|
|
108
|
+
*/
|
|
109
|
+
signInAsGuest = () => {
|
|
110
|
+
return this.db.signInAsGuest();
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Create an authorization url to sign in with an external provider.
|
|
114
|
+
*
|
|
115
|
+
* @see https://instantdb.com/docs/auth
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* // Get the authorization url from your backend
|
|
119
|
+
* const url = db.auth.createAuthorizationUrl({
|
|
120
|
+
* clientName: "google",
|
|
121
|
+
* redirectURL: window.location.href,
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // Put it in a sign in link
|
|
125
|
+
* <a href={url}>Log in with Google</a>
|
|
126
|
+
*/
|
|
127
|
+
createAuthorizationURL = (params) => {
|
|
128
|
+
return this.db.createAuthorizationURL(params);
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Sign in with the id_token from an external provider like Google
|
|
132
|
+
*
|
|
133
|
+
* @see https://instantdb.com/docs/auth
|
|
134
|
+
* @example
|
|
135
|
+
* db.auth
|
|
136
|
+
* .signInWithIdToken({
|
|
137
|
+
* // Token from external service
|
|
138
|
+
* idToken: id_token,
|
|
139
|
+
* // The name you gave the client when you registered it with Instant
|
|
140
|
+
* clientName: "google",
|
|
141
|
+
* // The nonce, if any, that you used when you initiated the auth flow
|
|
142
|
+
* // with the external service.
|
|
143
|
+
* nonce: your_nonce
|
|
144
|
+
* })
|
|
145
|
+
* .catch((err) => console.error(err.body?.message));
|
|
146
|
+
*
|
|
147
|
+
*/
|
|
148
|
+
signInWithIdToken = (params) => {
|
|
149
|
+
return this.db.signInWithIdToken(params);
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Sign in with the id_token from an external provider like Google
|
|
153
|
+
*
|
|
154
|
+
* @see https://instantdb.com/docs/auth
|
|
155
|
+
* @example
|
|
156
|
+
* db.auth
|
|
157
|
+
* .exchangeOAuthCode({
|
|
158
|
+
* // code received in redirect from OAuth callback
|
|
159
|
+
* code: code
|
|
160
|
+
* // The PKCE code_verifier, if any, that you used when you
|
|
161
|
+
* // initiated the auth flow
|
|
162
|
+
* codeVerifier: your_code_verifier
|
|
163
|
+
* })
|
|
164
|
+
* .catch((err) => console.error(err.body?.message));
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
exchangeOAuthCode = (params) => {
|
|
168
|
+
return this.db.exchangeCodeForToken(params);
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* OpenID Discovery path for use with tools like
|
|
172
|
+
* expo-auth-session that use auto-discovery of
|
|
173
|
+
* OAuth parameters.
|
|
174
|
+
*
|
|
175
|
+
* @see https://instantdb.com/docs/auth
|
|
176
|
+
* @example
|
|
177
|
+
* const discovery = useAutoDiscovery(
|
|
178
|
+
* db.auth.issuerURI()
|
|
179
|
+
* );
|
|
180
|
+
*/
|
|
181
|
+
issuerURI = () => {
|
|
182
|
+
return this.db.issuerURI();
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Sign out the current user
|
|
186
|
+
*/
|
|
187
|
+
signOut = (opts = { invalidateToken: true }) => {
|
|
188
|
+
return this.db.signOut(opts);
|
|
189
|
+
};
|
|
191
190
|
}
|
|
192
191
|
/**
|
|
193
192
|
* Functions to manage file storage.
|
|
194
193
|
*/
|
|
195
194
|
class Storage {
|
|
195
|
+
db;
|
|
196
196
|
constructor(db) {
|
|
197
197
|
this.db = db;
|
|
198
|
-
/**
|
|
199
|
-
* Uploads file at the provided path.
|
|
200
|
-
*
|
|
201
|
-
* @see https://instantdb.com/docs/storage
|
|
202
|
-
* @example
|
|
203
|
-
* const [file] = e.target.files; // result of file input
|
|
204
|
-
* const data = await db.storage.uploadFile('photos/demo.png', file);
|
|
205
|
-
*/
|
|
206
|
-
this.uploadFile = (path, file, opts = {}) => {
|
|
207
|
-
return this.db.uploadFile(path, file, opts);
|
|
208
|
-
};
|
|
209
|
-
/**
|
|
210
|
-
* Deletes a file by path name.
|
|
211
|
-
*
|
|
212
|
-
* @see https://instantdb.com/docs/storage
|
|
213
|
-
* @example
|
|
214
|
-
* await db.storage.delete('photos/demo.png');
|
|
215
|
-
*/
|
|
216
|
-
this.delete = (pathname) => {
|
|
217
|
-
return this.db.deleteFile(pathname);
|
|
218
|
-
};
|
|
219
|
-
// Deprecated Storage API (Jan 2025)
|
|
220
|
-
// ---------------------------------
|
|
221
|
-
/**
|
|
222
|
-
* @deprecated. Use `db.storage.uploadFile` instead
|
|
223
|
-
* remove in the future.
|
|
224
|
-
*/
|
|
225
|
-
this.upload = (pathname, file) => {
|
|
226
|
-
return this.db.upload(pathname, file);
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* @deprecated Use `db.storage.uploadFile` instead
|
|
230
|
-
*/
|
|
231
|
-
this.put = this.upload;
|
|
232
|
-
/**
|
|
233
|
-
* @deprecated. getDownloadUrl will be removed in the future.
|
|
234
|
-
* Use `useQuery` instead to query and fetch for valid urls
|
|
235
|
-
*
|
|
236
|
-
* db.useQuery({
|
|
237
|
-
* $files: {
|
|
238
|
-
* $: {
|
|
239
|
-
* where: {
|
|
240
|
-
* path: "moop.png"
|
|
241
|
-
* }
|
|
242
|
-
* }
|
|
243
|
-
* }
|
|
244
|
-
* })
|
|
245
|
-
*/
|
|
246
|
-
this.getDownloadUrl = (pathname) => {
|
|
247
|
-
return this.db.getDownloadUrl(pathname);
|
|
248
|
-
};
|
|
249
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Uploads file at the provided path.
|
|
201
|
+
*
|
|
202
|
+
* @see https://instantdb.com/docs/storage
|
|
203
|
+
* @example
|
|
204
|
+
* const [file] = e.target.files; // result of file input
|
|
205
|
+
* const data = await db.storage.uploadFile('photos/demo.png', file);
|
|
206
|
+
*/
|
|
207
|
+
uploadFile = (path, file, opts = {}) => {
|
|
208
|
+
return this.db.uploadFile(path, file, opts);
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Deletes a file by path name.
|
|
212
|
+
*
|
|
213
|
+
* @see https://instantdb.com/docs/storage
|
|
214
|
+
* @example
|
|
215
|
+
* await db.storage.delete('photos/demo.png');
|
|
216
|
+
*/
|
|
217
|
+
delete = (pathname) => {
|
|
218
|
+
return this.db.deleteFile(pathname);
|
|
219
|
+
};
|
|
220
|
+
// Deprecated Storage API (Jan 2025)
|
|
221
|
+
// ---------------------------------
|
|
222
|
+
/**
|
|
223
|
+
* @deprecated. Use `db.storage.uploadFile` instead
|
|
224
|
+
* remove in the future.
|
|
225
|
+
*/
|
|
226
|
+
upload = (pathname, file) => {
|
|
227
|
+
return this.db.upload(pathname, file);
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* @deprecated Use `db.storage.uploadFile` instead
|
|
231
|
+
*/
|
|
232
|
+
put = this.upload;
|
|
233
|
+
/**
|
|
234
|
+
* @deprecated. getDownloadUrl will be removed in the future.
|
|
235
|
+
* Use `useQuery` instead to query and fetch for valid urls
|
|
236
|
+
*
|
|
237
|
+
* db.useQuery({
|
|
238
|
+
* $files: {
|
|
239
|
+
* $: {
|
|
240
|
+
* where: {
|
|
241
|
+
* path: "moop.png"
|
|
242
|
+
* }
|
|
243
|
+
* }
|
|
244
|
+
* }
|
|
245
|
+
* })
|
|
246
|
+
*/
|
|
247
|
+
getDownloadUrl = (pathname) => {
|
|
248
|
+
return this.db.getDownloadUrl(pathname);
|
|
249
|
+
};
|
|
250
250
|
}
|
|
251
251
|
// util
|
|
252
252
|
function coerceQuery(o) {
|
|
@@ -254,8 +254,11 @@ function coerceQuery(o) {
|
|
|
254
254
|
return JSON.parse(JSON.stringify(o));
|
|
255
255
|
}
|
|
256
256
|
class InstantCoreDatabase {
|
|
257
|
+
_reactor;
|
|
258
|
+
auth;
|
|
259
|
+
storage;
|
|
260
|
+
tx = txInit();
|
|
257
261
|
constructor(reactor) {
|
|
258
|
-
this.tx = txInit();
|
|
259
262
|
this._reactor = reactor;
|
|
260
263
|
this.auth = new Auth(this._reactor);
|
|
261
264
|
this.storage = new Storage(this._reactor);
|
|
@@ -389,7 +392,7 @@ class InstantCoreDatabase {
|
|
|
389
392
|
* room.leaveRoom();
|
|
390
393
|
*/
|
|
391
394
|
joinRoom(roomType = '_defaultRoomType', roomId = '_defaultRoomId', opts) {
|
|
392
|
-
const leaveRoom = this._reactor.joinRoom(roomId, opts
|
|
395
|
+
const leaveRoom = this._reactor.joinRoom(roomId, opts?.initialPresence);
|
|
393
396
|
return {
|
|
394
397
|
leaveRoom,
|
|
395
398
|
subscribeTopic: (topic, onEvent) => this._reactor.subscribeTopic(roomId, topic, onEvent),
|
|
@@ -473,8 +476,11 @@ function init(
|
|
|
473
476
|
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
474
477
|
// as a non-nullable in the InstantConfig type.
|
|
475
478
|
config, Storage, NetworkListener, versions, EventSourceImpl) {
|
|
476
|
-
|
|
477
|
-
|
|
479
|
+
const configStrict = {
|
|
480
|
+
...config,
|
|
481
|
+
appId: config.appId?.trim(),
|
|
482
|
+
useDateObjects: (config.useDateObjects ?? false),
|
|
483
|
+
};
|
|
478
484
|
const existingClient = globalInstantCoreStore[reactorKey(configStrict)];
|
|
479
485
|
if (existingClient) {
|
|
480
486
|
if (schemaChanged(existingClient, configStrict.schema)) {
|
|
@@ -482,7 +488,11 @@ config, Storage, NetworkListener, versions, EventSourceImpl) {
|
|
|
482
488
|
}
|
|
483
489
|
return existingClient;
|
|
484
490
|
}
|
|
485
|
-
const reactor = new Reactor(
|
|
491
|
+
const reactor = new Reactor({
|
|
492
|
+
...defaultConfig,
|
|
493
|
+
...configStrict,
|
|
494
|
+
cardinalityInference: configStrict.schema ? true : false,
|
|
495
|
+
}, Storage || IndexedDBStorage, NetworkListener || WindowNetworkListener, { ...(versions || {}), '@instantdb/core': version }, EventSourceImpl);
|
|
486
496
|
const client = new InstantCoreDatabase(reactor);
|
|
487
497
|
globalInstantCoreStore[reactorKey(configStrict)] = client;
|
|
488
498
|
handleDevtool(configStrict.appId, configStrict.devtool);
|
|
@@ -497,7 +507,11 @@ function handleDevtool(appId, devtool) {
|
|
|
497
507
|
if (typeof devtool === 'boolean' && !devtool) {
|
|
498
508
|
return;
|
|
499
509
|
}
|
|
500
|
-
const config =
|
|
510
|
+
const config = {
|
|
511
|
+
position: 'bottom-right',
|
|
512
|
+
allowedHosts: ['localhost'],
|
|
513
|
+
...(typeof devtool === 'object' ? devtool : {}),
|
|
514
|
+
};
|
|
501
515
|
if (!config.allowedHosts.includes(window.location.hostname)) {
|
|
502
516
|
return;
|
|
503
517
|
}
|