@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,yCAKoB;AACpB,8CAAgC;AAChC,8DAAmC;AAEnC,uDAAuD;AAE1C,QAAA,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,IAAI,UAAU,CAAC;AAuB9E,MAAa,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,gBAAQ,EAAE,CAAC;gBACd,iDAAiD;gBACjD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;oBAC5B,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,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GAAG,MAAM,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EASrB,CAAC;IACN,CAAC;CAkPF;AAxRD,0CAwRC","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,yCAKoB;AACpB,8CAAgC;AAChC,8DAAmC;AAEnC,uDAAuD;AAE1C,QAAA,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,IAAI,UAAU,CAAC;AAuB9E,MAAa,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,CAAC,CAAC;IAC7C,CAAC,CAAC;IAEF,oDAAoD;IAC7C,cAAc,GAAG,CAAC,QAAgB,EAAE,KAAU,EAAE,EAAE;QACvD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE;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KAAK,CAC9B,6CAA6C,CAC9C,CAAC;YACF,cAAc,CAAC,KAAK,GAAG,GAAG,CAAC;YAC3B,MAAM,cAAc,CAAC;QACvB,CAAC;IACH,CAAC,CAAC;CACH;AAvRD,0CAuRC","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/commonjs/index.js
CHANGED
|
@@ -55,14 +55,12 @@ const defaultConfig = {
|
|
|
55
55
|
};
|
|
56
56
|
// hmr
|
|
57
57
|
function initSchemaHashStore() {
|
|
58
|
-
var _a;
|
|
59
58
|
globalThis.__instantDbSchemaHashStore =
|
|
60
|
-
|
|
59
|
+
globalThis.__instantDbSchemaHashStore ?? new WeakMap();
|
|
61
60
|
return globalThis.__instantDbSchemaHashStore;
|
|
62
61
|
}
|
|
63
62
|
function initGlobalInstantCoreStore() {
|
|
64
|
-
|
|
65
|
-
globalThis.__instantDbStore = (_a = globalThis.__instantDbStore) !== null && _a !== void 0 ? _a : {};
|
|
63
|
+
globalThis.__instantDbStore = globalThis.__instantDbStore ?? {};
|
|
66
64
|
return globalThis.__instantDbStore;
|
|
67
65
|
}
|
|
68
66
|
function reactorKey(config) {
|
|
@@ -86,198 +84,200 @@ const schemaHashStore = initSchemaHashStore();
|
|
|
86
84
|
* @see https://instantdb.com/docs/auth
|
|
87
85
|
*/
|
|
88
86
|
class Auth {
|
|
87
|
+
db;
|
|
89
88
|
constructor(db) {
|
|
90
89
|
this.db = db;
|
|
91
|
-
/**
|
|
92
|
-
* Sends a magic code to the user's email address.
|
|
93
|
-
*
|
|
94
|
-
* Once you send the magic code, see {@link auth.signInWithMagicCode} to let the
|
|
95
|
-
* user verify.
|
|
96
|
-
*
|
|
97
|
-
* @see https://instantdb.com/docs/auth
|
|
98
|
-
* @example
|
|
99
|
-
* db.auth.sendMagicCode({email: "example@gmail.com"})
|
|
100
|
-
* .catch((err) => console.error(err.body?.message))
|
|
101
|
-
*/
|
|
102
|
-
this.sendMagicCode = (params) => {
|
|
103
|
-
return this.db.sendMagicCode(params);
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* Verify a magic code that was sent to the user's email address.
|
|
107
|
-
*
|
|
108
|
-
* @see https://instantdb.com/docs/auth
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* db.auth.signInWithMagicCode({email: "example@gmail.com", code: "123456"})
|
|
112
|
-
* .catch((err) => console.error(err.body?.message))
|
|
113
|
-
*/
|
|
114
|
-
this.signInWithMagicCode = (params) => {
|
|
115
|
-
return this.db.signInWithMagicCode(params);
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Sign in a user with a refresh token
|
|
119
|
-
*
|
|
120
|
-
* @see https://instantdb.com/docs/backend#frontend-auth-sign-in-with-token
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* // Get the token from your backend
|
|
124
|
-
* const token = await fetch('/signin', ...);
|
|
125
|
-
* //Sign in
|
|
126
|
-
* db.auth.signInWithToken(token);
|
|
127
|
-
*/
|
|
128
|
-
this.signInWithToken = (token) => {
|
|
129
|
-
return this.db.signInWithCustomToken(token);
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* Sign in as guest, creating a new user without email
|
|
133
|
-
*
|
|
134
|
-
* @see https://instantdb.com/docs/auth
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* db.auth.signInAsGuest();
|
|
138
|
-
*/
|
|
139
|
-
this.signInAsGuest = () => {
|
|
140
|
-
return this.db.signInAsGuest();
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Create an authorization url to sign in with an external provider.
|
|
144
|
-
*
|
|
145
|
-
* @see https://instantdb.com/docs/auth
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* // Get the authorization url from your backend
|
|
149
|
-
* const url = db.auth.createAuthorizationUrl({
|
|
150
|
-
* clientName: "google",
|
|
151
|
-
* redirectURL: window.location.href,
|
|
152
|
-
* });
|
|
153
|
-
*
|
|
154
|
-
* // Put it in a sign in link
|
|
155
|
-
* <a href={url}>Log in with Google</a>
|
|
156
|
-
*/
|
|
157
|
-
this.createAuthorizationURL = (params) => {
|
|
158
|
-
return this.db.createAuthorizationURL(params);
|
|
159
|
-
};
|
|
160
|
-
/**
|
|
161
|
-
* Sign in with the id_token from an external provider like Google
|
|
162
|
-
*
|
|
163
|
-
* @see https://instantdb.com/docs/auth
|
|
164
|
-
* @example
|
|
165
|
-
* db.auth
|
|
166
|
-
* .signInWithIdToken({
|
|
167
|
-
* // Token from external service
|
|
168
|
-
* idToken: id_token,
|
|
169
|
-
* // The name you gave the client when you registered it with Instant
|
|
170
|
-
* clientName: "google",
|
|
171
|
-
* // The nonce, if any, that you used when you initiated the auth flow
|
|
172
|
-
* // with the external service.
|
|
173
|
-
* nonce: your_nonce
|
|
174
|
-
* })
|
|
175
|
-
* .catch((err) => console.error(err.body?.message));
|
|
176
|
-
*
|
|
177
|
-
*/
|
|
178
|
-
this.signInWithIdToken = (params) => {
|
|
179
|
-
return this.db.signInWithIdToken(params);
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Sign in with the id_token from an external provider like Google
|
|
183
|
-
*
|
|
184
|
-
* @see https://instantdb.com/docs/auth
|
|
185
|
-
* @example
|
|
186
|
-
* db.auth
|
|
187
|
-
* .exchangeOAuthCode({
|
|
188
|
-
* // code received in redirect from OAuth callback
|
|
189
|
-
* code: code
|
|
190
|
-
* // The PKCE code_verifier, if any, that you used when you
|
|
191
|
-
* // initiated the auth flow
|
|
192
|
-
* codeVerifier: your_code_verifier
|
|
193
|
-
* })
|
|
194
|
-
* .catch((err) => console.error(err.body?.message));
|
|
195
|
-
*
|
|
196
|
-
*/
|
|
197
|
-
this.exchangeOAuthCode = (params) => {
|
|
198
|
-
return this.db.exchangeCodeForToken(params);
|
|
199
|
-
};
|
|
200
|
-
/**
|
|
201
|
-
* OpenID Discovery path for use with tools like
|
|
202
|
-
* expo-auth-session that use auto-discovery of
|
|
203
|
-
* OAuth parameters.
|
|
204
|
-
*
|
|
205
|
-
* @see https://instantdb.com/docs/auth
|
|
206
|
-
* @example
|
|
207
|
-
* const discovery = useAutoDiscovery(
|
|
208
|
-
* db.auth.issuerURI()
|
|
209
|
-
* );
|
|
210
|
-
*/
|
|
211
|
-
this.issuerURI = () => {
|
|
212
|
-
return this.db.issuerURI();
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* Sign out the current user
|
|
216
|
-
*/
|
|
217
|
-
this.signOut = (opts = { invalidateToken: true }) => {
|
|
218
|
-
return this.db.signOut(opts);
|
|
219
|
-
};
|
|
220
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Sends a magic code to the user's email address.
|
|
93
|
+
*
|
|
94
|
+
* Once you send the magic code, see {@link auth.signInWithMagicCode} to let the
|
|
95
|
+
* user verify.
|
|
96
|
+
*
|
|
97
|
+
* @see https://instantdb.com/docs/auth
|
|
98
|
+
* @example
|
|
99
|
+
* db.auth.sendMagicCode({email: "example@gmail.com"})
|
|
100
|
+
* .catch((err) => console.error(err.body?.message))
|
|
101
|
+
*/
|
|
102
|
+
sendMagicCode = (params) => {
|
|
103
|
+
return this.db.sendMagicCode(params);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Verify a magic code that was sent to the user's email address.
|
|
107
|
+
*
|
|
108
|
+
* @see https://instantdb.com/docs/auth
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* db.auth.signInWithMagicCode({email: "example@gmail.com", code: "123456"})
|
|
112
|
+
* .catch((err) => console.error(err.body?.message))
|
|
113
|
+
*/
|
|
114
|
+
signInWithMagicCode = (params) => {
|
|
115
|
+
return this.db.signInWithMagicCode(params);
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Sign in a user with a refresh token
|
|
119
|
+
*
|
|
120
|
+
* @see https://instantdb.com/docs/backend#frontend-auth-sign-in-with-token
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // Get the token from your backend
|
|
124
|
+
* const token = await fetch('/signin', ...);
|
|
125
|
+
* //Sign in
|
|
126
|
+
* db.auth.signInWithToken(token);
|
|
127
|
+
*/
|
|
128
|
+
signInWithToken = (token) => {
|
|
129
|
+
return this.db.signInWithCustomToken(token);
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Sign in as guest, creating a new user without email
|
|
133
|
+
*
|
|
134
|
+
* @see https://instantdb.com/docs/auth
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* db.auth.signInAsGuest();
|
|
138
|
+
*/
|
|
139
|
+
signInAsGuest = () => {
|
|
140
|
+
return this.db.signInAsGuest();
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Create an authorization url to sign in with an external provider.
|
|
144
|
+
*
|
|
145
|
+
* @see https://instantdb.com/docs/auth
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* // Get the authorization url from your backend
|
|
149
|
+
* const url = db.auth.createAuthorizationUrl({
|
|
150
|
+
* clientName: "google",
|
|
151
|
+
* redirectURL: window.location.href,
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* // Put it in a sign in link
|
|
155
|
+
* <a href={url}>Log in with Google</a>
|
|
156
|
+
*/
|
|
157
|
+
createAuthorizationURL = (params) => {
|
|
158
|
+
return this.db.createAuthorizationURL(params);
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Sign in with the id_token from an external provider like Google
|
|
162
|
+
*
|
|
163
|
+
* @see https://instantdb.com/docs/auth
|
|
164
|
+
* @example
|
|
165
|
+
* db.auth
|
|
166
|
+
* .signInWithIdToken({
|
|
167
|
+
* // Token from external service
|
|
168
|
+
* idToken: id_token,
|
|
169
|
+
* // The name you gave the client when you registered it with Instant
|
|
170
|
+
* clientName: "google",
|
|
171
|
+
* // The nonce, if any, that you used when you initiated the auth flow
|
|
172
|
+
* // with the external service.
|
|
173
|
+
* nonce: your_nonce
|
|
174
|
+
* })
|
|
175
|
+
* .catch((err) => console.error(err.body?.message));
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
178
|
+
signInWithIdToken = (params) => {
|
|
179
|
+
return this.db.signInWithIdToken(params);
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Sign in with the id_token from an external provider like Google
|
|
183
|
+
*
|
|
184
|
+
* @see https://instantdb.com/docs/auth
|
|
185
|
+
* @example
|
|
186
|
+
* db.auth
|
|
187
|
+
* .exchangeOAuthCode({
|
|
188
|
+
* // code received in redirect from OAuth callback
|
|
189
|
+
* code: code
|
|
190
|
+
* // The PKCE code_verifier, if any, that you used when you
|
|
191
|
+
* // initiated the auth flow
|
|
192
|
+
* codeVerifier: your_code_verifier
|
|
193
|
+
* })
|
|
194
|
+
* .catch((err) => console.error(err.body?.message));
|
|
195
|
+
*
|
|
196
|
+
*/
|
|
197
|
+
exchangeOAuthCode = (params) => {
|
|
198
|
+
return this.db.exchangeCodeForToken(params);
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* OpenID Discovery path for use with tools like
|
|
202
|
+
* expo-auth-session that use auto-discovery of
|
|
203
|
+
* OAuth parameters.
|
|
204
|
+
*
|
|
205
|
+
* @see https://instantdb.com/docs/auth
|
|
206
|
+
* @example
|
|
207
|
+
* const discovery = useAutoDiscovery(
|
|
208
|
+
* db.auth.issuerURI()
|
|
209
|
+
* );
|
|
210
|
+
*/
|
|
211
|
+
issuerURI = () => {
|
|
212
|
+
return this.db.issuerURI();
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Sign out the current user
|
|
216
|
+
*/
|
|
217
|
+
signOut = (opts = { invalidateToken: true }) => {
|
|
218
|
+
return this.db.signOut(opts);
|
|
219
|
+
};
|
|
221
220
|
}
|
|
222
221
|
exports.Auth = Auth;
|
|
223
222
|
/**
|
|
224
223
|
* Functions to manage file storage.
|
|
225
224
|
*/
|
|
226
225
|
class Storage {
|
|
226
|
+
db;
|
|
227
227
|
constructor(db) {
|
|
228
228
|
this.db = db;
|
|
229
|
-
/**
|
|
230
|
-
* Uploads file at the provided path.
|
|
231
|
-
*
|
|
232
|
-
* @see https://instantdb.com/docs/storage
|
|
233
|
-
* @example
|
|
234
|
-
* const [file] = e.target.files; // result of file input
|
|
235
|
-
* const data = await db.storage.uploadFile('photos/demo.png', file);
|
|
236
|
-
*/
|
|
237
|
-
this.uploadFile = (path, file, opts = {}) => {
|
|
238
|
-
return this.db.uploadFile(path, file, opts);
|
|
239
|
-
};
|
|
240
|
-
/**
|
|
241
|
-
* Deletes a file by path name.
|
|
242
|
-
*
|
|
243
|
-
* @see https://instantdb.com/docs/storage
|
|
244
|
-
* @example
|
|
245
|
-
* await db.storage.delete('photos/demo.png');
|
|
246
|
-
*/
|
|
247
|
-
this.delete = (pathname) => {
|
|
248
|
-
return this.db.deleteFile(pathname);
|
|
249
|
-
};
|
|
250
|
-
// Deprecated Storage API (Jan 2025)
|
|
251
|
-
// ---------------------------------
|
|
252
|
-
/**
|
|
253
|
-
* @deprecated. Use `db.storage.uploadFile` instead
|
|
254
|
-
* remove in the future.
|
|
255
|
-
*/
|
|
256
|
-
this.upload = (pathname, file) => {
|
|
257
|
-
return this.db.upload(pathname, file);
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* @deprecated Use `db.storage.uploadFile` instead
|
|
261
|
-
*/
|
|
262
|
-
this.put = this.upload;
|
|
263
|
-
/**
|
|
264
|
-
* @deprecated. getDownloadUrl will be removed in the future.
|
|
265
|
-
* Use `useQuery` instead to query and fetch for valid urls
|
|
266
|
-
*
|
|
267
|
-
* db.useQuery({
|
|
268
|
-
* $files: {
|
|
269
|
-
* $: {
|
|
270
|
-
* where: {
|
|
271
|
-
* path: "moop.png"
|
|
272
|
-
* }
|
|
273
|
-
* }
|
|
274
|
-
* }
|
|
275
|
-
* })
|
|
276
|
-
*/
|
|
277
|
-
this.getDownloadUrl = (pathname) => {
|
|
278
|
-
return this.db.getDownloadUrl(pathname);
|
|
279
|
-
};
|
|
280
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Uploads file at the provided path.
|
|
232
|
+
*
|
|
233
|
+
* @see https://instantdb.com/docs/storage
|
|
234
|
+
* @example
|
|
235
|
+
* const [file] = e.target.files; // result of file input
|
|
236
|
+
* const data = await db.storage.uploadFile('photos/demo.png', file);
|
|
237
|
+
*/
|
|
238
|
+
uploadFile = (path, file, opts = {}) => {
|
|
239
|
+
return this.db.uploadFile(path, file, opts);
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Deletes a file by path name.
|
|
243
|
+
*
|
|
244
|
+
* @see https://instantdb.com/docs/storage
|
|
245
|
+
* @example
|
|
246
|
+
* await db.storage.delete('photos/demo.png');
|
|
247
|
+
*/
|
|
248
|
+
delete = (pathname) => {
|
|
249
|
+
return this.db.deleteFile(pathname);
|
|
250
|
+
};
|
|
251
|
+
// Deprecated Storage API (Jan 2025)
|
|
252
|
+
// ---------------------------------
|
|
253
|
+
/**
|
|
254
|
+
* @deprecated. Use `db.storage.uploadFile` instead
|
|
255
|
+
* remove in the future.
|
|
256
|
+
*/
|
|
257
|
+
upload = (pathname, file) => {
|
|
258
|
+
return this.db.upload(pathname, file);
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* @deprecated Use `db.storage.uploadFile` instead
|
|
262
|
+
*/
|
|
263
|
+
put = this.upload;
|
|
264
|
+
/**
|
|
265
|
+
* @deprecated. getDownloadUrl will be removed in the future.
|
|
266
|
+
* Use `useQuery` instead to query and fetch for valid urls
|
|
267
|
+
*
|
|
268
|
+
* db.useQuery({
|
|
269
|
+
* $files: {
|
|
270
|
+
* $: {
|
|
271
|
+
* where: {
|
|
272
|
+
* path: "moop.png"
|
|
273
|
+
* }
|
|
274
|
+
* }
|
|
275
|
+
* }
|
|
276
|
+
* })
|
|
277
|
+
*/
|
|
278
|
+
getDownloadUrl = (pathname) => {
|
|
279
|
+
return this.db.getDownloadUrl(pathname);
|
|
280
|
+
};
|
|
281
281
|
}
|
|
282
282
|
exports.Storage = Storage;
|
|
283
283
|
// util
|
|
@@ -286,8 +286,11 @@ function coerceQuery(o) {
|
|
|
286
286
|
return JSON.parse(JSON.stringify(o));
|
|
287
287
|
}
|
|
288
288
|
class InstantCoreDatabase {
|
|
289
|
+
_reactor;
|
|
290
|
+
auth;
|
|
291
|
+
storage;
|
|
292
|
+
tx = (0, instatx_js_1.txInit)();
|
|
289
293
|
constructor(reactor) {
|
|
290
|
-
this.tx = (0, instatx_js_1.txInit)();
|
|
291
294
|
this._reactor = reactor;
|
|
292
295
|
this.auth = new Auth(this._reactor);
|
|
293
296
|
this.storage = new Storage(this._reactor);
|
|
@@ -421,7 +424,7 @@ class InstantCoreDatabase {
|
|
|
421
424
|
* room.leaveRoom();
|
|
422
425
|
*/
|
|
423
426
|
joinRoom(roomType = '_defaultRoomType', roomId = '_defaultRoomId', opts) {
|
|
424
|
-
const leaveRoom = this._reactor.joinRoom(roomId, opts
|
|
427
|
+
const leaveRoom = this._reactor.joinRoom(roomId, opts?.initialPresence);
|
|
425
428
|
return {
|
|
426
429
|
leaveRoom,
|
|
427
430
|
subscribeTopic: (topic, onEvent) => this._reactor.subscribeTopic(roomId, topic, onEvent),
|
|
@@ -506,8 +509,11 @@ function init(
|
|
|
506
509
|
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
507
510
|
// as a non-nullable in the InstantConfig type.
|
|
508
511
|
config, Storage, NetworkListener, versions, EventSourceImpl) {
|
|
509
|
-
|
|
510
|
-
|
|
512
|
+
const configStrict = {
|
|
513
|
+
...config,
|
|
514
|
+
appId: config.appId?.trim(),
|
|
515
|
+
useDateObjects: (config.useDateObjects ?? false),
|
|
516
|
+
};
|
|
511
517
|
const existingClient = globalInstantCoreStore[reactorKey(configStrict)];
|
|
512
518
|
if (existingClient) {
|
|
513
519
|
if (schemaChanged(existingClient, configStrict.schema)) {
|
|
@@ -515,7 +521,11 @@ config, Storage, NetworkListener, versions, EventSourceImpl) {
|
|
|
515
521
|
}
|
|
516
522
|
return existingClient;
|
|
517
523
|
}
|
|
518
|
-
const reactor = new Reactor_js_1.default(
|
|
524
|
+
const reactor = new Reactor_js_1.default({
|
|
525
|
+
...defaultConfig,
|
|
526
|
+
...configStrict,
|
|
527
|
+
cardinalityInference: configStrict.schema ? true : false,
|
|
528
|
+
}, Storage || IndexedDBStorage_ts_1.default, NetworkListener || WindowNetworkListener_js_1.default, { ...(versions || {}), '@instantdb/core': version_ts_1.default }, EventSourceImpl);
|
|
519
529
|
const client = new InstantCoreDatabase(reactor);
|
|
520
530
|
globalInstantCoreStore[reactorKey(configStrict)] = client;
|
|
521
531
|
handleDevtool(configStrict.appId, configStrict.devtool);
|
|
@@ -530,7 +540,11 @@ function handleDevtool(appId, devtool) {
|
|
|
530
540
|
if (typeof devtool === 'boolean' && !devtool) {
|
|
531
541
|
return;
|
|
532
542
|
}
|
|
533
|
-
const config =
|
|
543
|
+
const config = {
|
|
544
|
+
position: 'bottom-right',
|
|
545
|
+
allowedHosts: ['localhost'],
|
|
546
|
+
...(typeof devtool === 'object' ? devtool : {}),
|
|
547
|
+
};
|
|
534
548
|
if (!config.allowedHosts.includes(window.location.hostname)) {
|
|
535
549
|
return;
|
|
536
550
|
}
|