@instantdb/core 0.22.93 → 0.22.94
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/__tests__/src/serializeSchema.test.ts +123 -0
- package/dist/commonjs/Reactor.d.ts +13 -1
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +72 -5
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/createRouteHandler.d.ts +8 -0
- package/dist/commonjs/createRouteHandler.d.ts.map +1 -0
- package/dist/commonjs/createRouteHandler.js +66 -0
- package/dist/commonjs/createRouteHandler.js.map +1 -0
- package/dist/commonjs/framework.d.ts +77 -0
- package/dist/commonjs/framework.d.ts.map +1 -0
- package/dist/commonjs/framework.js +228 -0
- package/dist/commonjs/framework.js.map +1 -0
- package/dist/commonjs/index.d.ts +5 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +7 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/parseSchemaFromJSON.d.ts +3 -0
- package/dist/commonjs/parseSchemaFromJSON.d.ts.map +1 -0
- package/dist/commonjs/parseSchemaFromJSON.js +148 -0
- package/dist/commonjs/parseSchemaFromJSON.js.map +1 -0
- package/dist/commonjs/reactorTypes.d.ts +5 -4
- package/dist/commonjs/reactorTypes.d.ts.map +1 -1
- package/dist/commonjs/reactorTypes.js.map +1 -1
- package/dist/esm/Reactor.d.ts +13 -1
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +72 -5
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/createRouteHandler.d.ts +8 -0
- package/dist/esm/createRouteHandler.d.ts.map +1 -0
- package/dist/esm/createRouteHandler.js +62 -0
- package/dist/esm/createRouteHandler.js.map +1 -0
- package/dist/esm/framework.d.ts +77 -0
- package/dist/esm/framework.d.ts.map +1 -0
- package/dist/esm/framework.js +188 -0
- package/dist/esm/framework.js.map +1 -0
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parseSchemaFromJSON.d.ts +3 -0
- package/dist/esm/parseSchemaFromJSON.d.ts.map +1 -0
- package/dist/esm/parseSchemaFromJSON.js +144 -0
- package/dist/esm/parseSchemaFromJSON.js.map +1 -0
- package/dist/esm/reactorTypes.d.ts +5 -4
- package/dist/esm/reactorTypes.d.ts.map +1 -1
- package/dist/esm/reactorTypes.js.map +1 -1
- package/dist/standalone/index.js +2730 -2395
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +83 -6
- package/src/createRouteHandler.ts +63 -0
- package/src/framework.ts +318 -0
- package/src/index.ts +9 -0
- package/src/parseSchemaFromJSON.ts +176 -0
- package/src/reactorTypes.ts +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAg4BE,oBAAI;AAmBJ,kCAAW;AAn5Bb,8DAAmC;AACnC,6CAOsB;AA23BpB,mFAj4BA,eAAE,OAi4BA;AACF,uFAj4BA,mBAAM,OAi4BA;AACN,uFAj4BA,mBAAM,OAi4BA;AAaN,uFA74BA,mBAAM,OA64BA;AAz4BR,sEAA2C;AA24BzC,mBA34BK,qBAAQ,CA24BL;AA14BV,0DAA+B;AAw3B7B,aAx3BK,eAAE,CAw3BL;AAv3BJ,gFAAqD;AA24BnD,2BA34BK,6BAAgB,CA24BL;AA14BlB,+CAAgD;AAy4B9C,6FAz4BO,uBAAY,OAy4BP;AAx4Bd,0FAA+D;AA04B7D,gCA14BK,kCAAqB,CA04BL;AAz4BvB,2CAAgC;AAi4B9B,kFAj4BO,aAAC,OAi4BP;AAh4BH,6CAA6C;AAC7C,8DAAmC;AA24BjC,kBA34BK,oBAAO,CA24BL;AA14BT,6DAA2E;AAq3BzE,8FAr3BO,kCAAa,OAq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D,OAAO;IACT,CAAC;IAED,IAAA,0BAAa,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAK7B,8CAAiB","sourcesContent":["import Reactor from './Reactor.js';\nimport {\n tx,\n txInit,\n lookup,\n getOps,\n type TxChunk,\n type TransactionChunk,\n} from './instatx.js';\nimport weakHash from './utils/weakHash.js';\nimport id from './utils/id.ts';\nimport IndexedDBStorage from './IndexedDBStorage.ts';\nimport { coerceToDate } from './utils/dates.js';\nimport WindowNetworkListener from './WindowNetworkListener.js';\nimport { i } from './schema.js';\nimport { createDevtool } from './devtool.js';\nimport version from './version.ts';\nimport { validateQuery, QueryValidationError } from './queryValidation.ts';\nimport {\n validateTransactions,\n TransactionValidationError,\n} from './transactionValidation.ts';\nimport {\n StorageInterface,\n type StorageInterfaceStoreName,\n} from './utils/PersistedObject.ts';\n\nimport type {\n PresenceOpts,\n PresenceResponse,\n PresenceSlice,\n RoomSchemaShape,\n} from './presence.ts';\nimport type {\n DevtoolConfig,\n IDatabase,\n IInstantDatabase,\n StrictDevtoolConfig,\n} from './coreTypes.ts';\nimport type {\n Query,\n QueryResponse,\n InstaQLResponse,\n PageInfoResponse,\n Exactly,\n InstantObject,\n InstaQLParams,\n InstaQLOptions,\n InstaQLQueryParams,\n InstaQLEntity,\n InstaQLEntitySubquery,\n InstaQLResult,\n InstaQLFields,\n ValidQuery,\n} from './queryTypes.ts';\nimport type { PresencePeer } from './presenceTypes.ts';\nimport type {\n AuthState,\n User,\n AuthResult,\n ConnectionStatus,\n} from './clientTypes.ts';\nimport type {\n InstantQuery,\n InstantQueryResult,\n InstantSchema,\n InstantEntity,\n InstantSchemaDatabase,\n} from './helperTypes.ts';\nimport type {\n InstantDBAttr,\n InstantDBAttrOnDelete,\n InstantDBCheckedDataType,\n InstantDBIdent,\n InstantDBInferredType,\n} from './attrTypes.ts';\nimport type {\n AttrsDefs,\n CardinalityKind,\n DataAttrDef,\n EntitiesDef,\n EntitiesWithLinks,\n EntityDef,\n RoomsDef,\n InstantSchemaDef,\n InstantGraph,\n LinkAttrDef,\n LinkDef,\n LinksDef,\n PresenceOf,\n ResolveAttrs,\n RoomsOf,\n TopicsOf,\n TopicOf,\n ValueTypes,\n InstantUnknownSchema,\n InstantUnknownSchemaDef,\n BackwardsCompatibleSchema,\n UpdateParams,\n LinkParams,\n CreateParams,\n RuleParams,\n} from './schemaTypes.ts';\nimport type { InstantRules } from './rulesTypes.ts';\nimport type { UploadFileResponse, DeleteFileResponse } from './StorageAPI.ts';\n\nimport type {\n ExchangeCodeForTokenParams,\n SendMagicCodeParams,\n SendMagicCodeResponse,\n SignInWithIdTokenParams,\n VerifyMagicCodeParams,\n VerifyResponse,\n} from './authAPI.ts';\n\nimport { InstantAPIError, type InstantIssue } from './utils/fetch.js';\nimport { InstantError } from './InstantError.ts';\nimport { EventSourceType } from './Connection.ts';\nimport { CallbackEventType as SyncTableCallbackEventType } from './SyncTable.ts';\nimport type {\n SyncTableCallback,\n CallbackEvent as SyncTableCallbackEvent,\n InitialSyncBatch as SyncTableInitialSyncBatch,\n InitialSyncComplete as SyncTableInitialSyncComplete,\n SyncTransaction as SyncTableSyncTransaction,\n LoadFromStorage as SyncTableLoadFromStorage,\n SetupError as SyncTableSetupError,\n} from './SyncTable.ts';\n\nconst defaultOpenDevtool = true;\n\n// types\n\ntype ExactlyOne<T> = {\n [K in keyof T]: Pick<T, K> & Partial<Record<Exclude<keyof T, K>, never>>;\n}[keyof T];\n\nexport type Config = {\n appId: string;\n websocketURI?: string;\n apiURI?: string;\n devtool?: boolean | DevtoolConfig;\n verbose?: boolean;\n queryCacheLimit?: number;\n useDateObjects: boolean;\n disableValidation?: boolean;\n};\n\nexport type InstantConfig<\n S extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean = false,\n> = {\n appId: string;\n schema?: S;\n websocketURI?: string;\n apiURI?: string;\n devtool?: boolean | DevtoolConfig;\n verbose?: boolean;\n queryCacheLimit?: number;\n useDateObjects: UseDates;\n disableValidation?: boolean;\n};\n\nexport type ConfigWithSchema<S extends InstantGraph<any, any>> = Config & {\n schema: S;\n};\n\nexport type TransactionResult = {\n status: 'synced' | 'enqueued';\n clientId: string;\n};\n\nexport type PublishTopic<TopicsByKey> = <Key extends keyof TopicsByKey>(\n topic: Key,\n data: TopicsByKey[Key],\n) => void;\n\nexport type SubscribeTopic<PresenceShape, TopicsByKey> = <\n Key extends keyof TopicsByKey,\n>(\n topic: Key,\n onEvent: (event: TopicsByKey[Key], peer: PresenceShape) => void,\n) => () => void;\n\nexport type GetPresence<PresenceShape> = <Keys extends keyof PresenceShape>(\n opts: PresenceOpts<PresenceShape, Keys>,\n) => PresenceResponse<PresenceShape, Keys> | null;\n\nexport type SubscribePresence<PresenceShape> = <\n Keys extends keyof PresenceShape,\n>(\n opts: PresenceOpts<PresenceShape, Keys>,\n onChange: (slice: PresenceResponse<PresenceShape, Keys>) => void,\n) => () => void;\n\nexport type RoomHandle<PresenceShape, TopicsByKey> = {\n leaveRoom: () => void;\n publishTopic: PublishTopic<TopicsByKey>;\n subscribeTopic: SubscribeTopic<PresenceShape, TopicsByKey>;\n publishPresence: (data: Partial<PresenceShape>) => void;\n getPresence: GetPresence<PresenceShape>;\n subscribePresence: SubscribePresence<PresenceShape>;\n};\n\ntype AuthToken = string;\n\ntype SubscriptionState<Q, Schema, WithCardinalityInference extends boolean> =\n | { error: { message: string }; data: undefined; pageInfo: undefined }\n | {\n error: undefined;\n data: QueryResponse<Q, Schema, WithCardinalityInference>;\n pageInfo: PageInfoResponse<Q>;\n };\n\ntype InstaQLSubscriptionState<Schema, Q, UseDates extends boolean> =\n | { error: { message: string }; data: undefined; pageInfo: undefined }\n | {\n error: undefined;\n data: InstaQLResponse<Schema, Q, UseDates>;\n pageInfo: PageInfoResponse<Q>;\n };\n\ntype LifecycleSubscriptionState<\n Q,\n Schema,\n WithCardinalityInference extends boolean,\n> = SubscriptionState<Q, Schema, WithCardinalityInference> & {\n isLoading: boolean;\n};\n\ntype InstaQLLifecycleState<Schema, Q, UseDates extends boolean = false> =\n | (InstaQLSubscriptionState<Schema, Q, UseDates> & {\n isLoading: boolean;\n })\n | {\n isLoading: true;\n data: undefined;\n pageInfo: undefined;\n error: undefined;\n };\n\ntype UnsubscribeFn = () => void;\n\n// consts\n\nconst defaultConfig = {\n apiURI: 'https://api.instantdb.com',\n websocketURI: 'wss://api.instantdb.com/runtime/session',\n};\n\n// hmr\nfunction initSchemaHashStore(): WeakMap<any, string> {\n globalThis.__instantDbSchemaHashStore =\n globalThis.__instantDbSchemaHashStore ?? new WeakMap<any, string>();\n return globalThis.__instantDbSchemaHashStore;\n}\n\nfunction initGlobalInstantCoreStore(): Record<string, any> {\n globalThis.__instantDbStore = globalThis.__instantDbStore ?? {};\n return globalThis.__instantDbStore;\n}\n\nfunction reactorKey(config: InstantConfig<any, boolean>): string {\n // @ts-expect-error\n const adminToken = config.__adminToken;\n return (\n config.appId +\n '_' +\n (config.websocketURI || 'default_ws_uri') +\n '_' +\n (config.apiURI || 'default_api_uri') +\n '_' +\n (adminToken || 'client_only') +\n '_' +\n config.useDateObjects\n );\n}\n\nconst globalInstantCoreStore = initGlobalInstantCoreStore();\nconst schemaHashStore = initSchemaHashStore();\n\ntype SignoutOpts = {\n invalidateToken?: boolean;\n};\n\n/**\n * Functions to log users in and out.\n *\n * @see https://instantdb.com/docs/auth\n */\nclass Auth {\n constructor(private db: Reactor) {}\n\n /**\n * Sends a magic code to the user's email address.\n *\n * Once you send the magic code, see {@link auth.signInWithMagicCode} to let the\n * user verify.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * db.auth.sendMagicCode({email: \"example@gmail.com\"})\n * .catch((err) => console.error(err.body?.message))\n */\n sendMagicCode = (\n params: SendMagicCodeParams,\n ): Promise<SendMagicCodeResponse> => {\n return this.db.sendMagicCode(params);\n };\n\n /**\n * Verify a magic code that was sent to the user's email address.\n *\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * db.auth.signInWithMagicCode({email: \"example@gmail.com\", code: \"123456\"})\n * .catch((err) => console.error(err.body?.message))\n */\n signInWithMagicCode = (\n params: VerifyMagicCodeParams,\n ): Promise<VerifyResponse> => {\n return this.db.signInWithMagicCode(params);\n };\n\n /**\n * Sign in a user with a refresh token\n *\n * @see https://instantdb.com/docs/backend#frontend-auth-sign-in-with-token\n *\n * @example\n * // Get the token from your backend\n * const token = await fetch('/signin', ...);\n * //Sign in\n * db.auth.signInWithToken(token);\n */\n signInWithToken = (token: AuthToken): Promise<VerifyResponse> => {\n return this.db.signInWithCustomToken(token);\n };\n\n /**\n * Sign in as guest, creating a new user without email\n *\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * db.auth.signInAsGuest();\n */\n signInAsGuest = (): Promise<VerifyResponse> => {\n return this.db.signInAsGuest();\n };\n\n /**\n * Create an authorization url to sign in with an external provider.\n *\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * // Get the authorization url from your backend\n * const url = db.auth.createAuthorizationUrl({\n * clientName: \"google\",\n * redirectURL: window.location.href,\n * });\n *\n * // Put it in a sign in link\n * <a href={url}>Log in with Google</a>\n */\n createAuthorizationURL = (params: {\n clientName: string;\n redirectURL: string;\n }): string => {\n return this.db.createAuthorizationURL(params);\n };\n\n /**\n * Sign in with the id_token from an external provider like Google\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * db.auth\n * .signInWithIdToken({\n * // Token from external service\n * idToken: id_token,\n * // The name you gave the client when you registered it with Instant\n * clientName: \"google\",\n * // The nonce, if any, that you used when you initiated the auth flow\n * // with the external service.\n * nonce: your_nonce\n * })\n * .catch((err) => console.error(err.body?.message));\n *\n */\n signInWithIdToken = (\n params: SignInWithIdTokenParams,\n ): Promise<VerifyResponse> => {\n return this.db.signInWithIdToken(params);\n };\n\n /**\n * Sign in with the id_token from an external provider like Google\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * db.auth\n * .exchangeOAuthCode({\n * // code received in redirect from OAuth callback\n * code: code\n * // The PKCE code_verifier, if any, that you used when you\n * // initiated the auth flow\n * codeVerifier: your_code_verifier\n * })\n * .catch((err) => console.error(err.body?.message));\n *\n */\n exchangeOAuthCode = (params: ExchangeCodeForTokenParams) => {\n return this.db.exchangeCodeForToken(params);\n };\n\n /**\n * OpenID Discovery path for use with tools like\n * expo-auth-session that use auto-discovery of\n * OAuth parameters.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const discovery = useAutoDiscovery(\n * db.auth.issuerURI()\n * );\n */\n issuerURI = (): string => {\n return this.db.issuerURI();\n };\n\n /**\n * Sign out the current user\n */\n signOut = (opts: SignoutOpts = { invalidateToken: true }): Promise<void> => {\n return this.db.signOut(opts);\n };\n}\n\ntype FileOpts = {\n contentType?: string;\n contentDisposition?: string;\n fileSize?: number; // Required for streaming uploads\n};\n\n/**\n * Functions to manage file storage.\n */\nclass Storage {\n constructor(private db: Reactor) {}\n\n /**\n * Uploads file at the provided path.\n *\n * @see https://instantdb.com/docs/storage\n * @example\n * const [file] = e.target.files; // result of file input\n * const data = await db.storage.uploadFile('photos/demo.png', file);\n */\n uploadFile = (\n path: string,\n file: File | Blob,\n opts: FileOpts = {},\n ): Promise<UploadFileResponse> => {\n return this.db.uploadFile(path, file, opts);\n };\n\n /**\n * Deletes a file by path name.\n *\n * @see https://instantdb.com/docs/storage\n * @example\n * await db.storage.delete('photos/demo.png');\n */\n delete = (pathname: string) => {\n return this.db.deleteFile(pathname);\n };\n\n // Deprecated Storage API (Jan 2025)\n // ---------------------------------\n\n /**\n * @deprecated. Use `db.storage.uploadFile` instead\n * remove in the future.\n */\n upload = (pathname: string, file: File) => {\n return this.db.upload(pathname, file);\n };\n\n /**\n * @deprecated Use `db.storage.uploadFile` instead\n */\n put = this.upload;\n\n /**\n * @deprecated. getDownloadUrl will be removed in the future.\n * Use `useQuery` instead to query and fetch for valid urls\n *\n * db.useQuery({\n * $files: {\n * $: {\n * where: {\n * path: \"moop.png\"\n * }\n * }\n * }\n * })\n */\n getDownloadUrl = (pathname: string) => {\n return this.db.getDownloadUrl(pathname);\n };\n}\n\n// util\n\nfunction coerceQuery(o: any) {\n // stringify and parse to remove undefined values\n return JSON.parse(JSON.stringify(o));\n}\n\nclass InstantCoreDatabase<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean = false,\n> implements IInstantDatabase<Schema>\n{\n public _reactor: Reactor<RoomsOf<Schema>>;\n public auth: Auth;\n public storage: Storage;\n\n public tx = txInit<Schema>();\n\n constructor(reactor: Reactor<RoomsOf<Schema>>) {\n this._reactor = reactor;\n this.auth = new Auth(this._reactor);\n this.storage = new Storage(this._reactor);\n }\n\n /**\n * Use this to write data! You can create, update, delete, and link objects\n *\n * @see https://instantdb.com/docs/instaml\n *\n * @example\n * // Create a new object in the `goals` namespace\n * const goalId = id();\n * db.transact(db.tx.goals[goalId].update({title: \"Get fit\"}))\n *\n * // Update the title\n * db.transact(db.tx.goals[goalId].update({title: \"Get super fit\"}))\n *\n * // Delete it\n * db.transact(db.tx.goals[goalId].delete())\n *\n * // Or create an association:\n * todoId = id();\n * db.transact([\n * db.tx.todos[todoId].update({ title: 'Go on a run' }),\n * db.tx.goals[goalId].link({todos: todoId}),\n * ])\n */\n transact(\n chunks: TransactionChunk<any, any> | TransactionChunk<any, any>[],\n ): Promise<TransactionResult> {\n return this._reactor.pushTx(chunks);\n }\n\n getLocalId(name: string): Promise<string> {\n return this._reactor.getLocalId(name);\n }\n\n /**\n * Use this to query your data!\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n * // listen to all goals\n * db.subscribeQuery({ goals: {} }, (resp) => {\n * console.log(resp.data.goals)\n * })\n *\n * // goals where the title is \"Get Fit\"\n * db.subscribeQuery(\n * { goals: { $: { where: { title: \"Get Fit\" } } } },\n * (resp) => {\n * console.log(resp.data.goals)\n * }\n * )\n *\n * // all goals, _alongside_ their todos\n * db.subscribeQuery({ goals: { todos: {} } }, (resp) => {\n * console.log(resp.data.goals)\n * });\n */\n subscribeQuery<\n Q extends ValidQuery<Q, Schema>,\n UseDatesLocal extends boolean = UseDates,\n >(\n query: Q,\n cb: (resp: InstaQLSubscriptionState<Schema, Q, UseDatesLocal>) => void,\n opts?: InstaQLOptions,\n ) {\n return this._reactor.subscribeQuery(query, cb, opts);\n }\n\n /**\n * Listen for the logged in state. This is useful\n * for deciding when to show a login screen.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const unsub = db.subscribeAuth((auth) => {\n * if (auth.user) {\n * console.log('logged in as', auth.user.email)\n * } else {\n * console.log('logged out')\n * }\n * })\n */\n subscribeAuth(cb: (auth: AuthResult) => void): UnsubscribeFn {\n return this._reactor.subscribeAuth(cb);\n }\n\n /**\n * One time query for the logged in state. This is useful\n * for scenarios where you want to know the current auth\n * state without subscribing to changes.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const user = await db.getAuth();\n * console.log('logged in as', user.email)\n */\n getAuth(): Promise<User | null> {\n return this._reactor.getAuth();\n }\n\n /**\n * Listen for connection status changes to Instant. This is useful\n * for building things like connectivity indicators\n *\n * @see https://www.instantdb.com/docs/patterns#connection-status\n * @example\n * const unsub = db.subscribeConnectionStatus((status) => {\n * const connectionState =\n * status === 'connecting' || status === 'opened'\n * ? 'authenticating'\n * : status === 'authenticated'\n * ? 'connected'\n * : status === 'closed'\n * ? 'closed'\n * : status === 'errored'\n * ? 'errored'\n * : 'unexpected state';\n *\n * console.log('Connection status:', connectionState);\n * });\n */\n subscribeConnectionStatus(\n cb: (status: ConnectionStatus) => void,\n ): UnsubscribeFn {\n return this._reactor.subscribeConnectionStatus(cb);\n }\n\n /**\n * Join a room to publish and subscribe to topics and presence.\n *\n * @see https://instantdb.com/docs/presence-and-topics\n * @example\n * // init\n * const db = init();\n * const room = db.joinRoom(roomType, roomId);\n * // usage\n * const unsubscribeTopic = room.subscribeTopic(\"foo\", console.log);\n * const unsubscribePresence = room.subscribePresence({}, console.log);\n * room.publishTopic(\"hello\", { message: \"hello world!\" });\n * room.publishPresence({ name: \"joe\" });\n * // later\n * unsubscribePresence();\n * unsubscribeTopic();\n * room.leaveRoom();\n */\n joinRoom<RoomType extends keyof RoomsOf<Schema>>(\n roomType: RoomType = '_defaultRoomType' as RoomType,\n roomId: string = '_defaultRoomId',\n opts?: {\n initialPresence?: Partial<PresenceOf<Schema, RoomType>>;\n },\n ): RoomHandle<PresenceOf<Schema, RoomType>, TopicsOf<Schema, RoomType>> {\n const leaveRoom = this._reactor.joinRoom(roomId, opts?.initialPresence);\n\n return {\n leaveRoom,\n subscribeTopic: (topic, onEvent) =>\n this._reactor.subscribeTopic(roomId, topic, onEvent),\n subscribePresence: (opts, onChange) =>\n this._reactor.subscribePresence(roomType, roomId, opts, onChange),\n publishTopic: (topic, data) =>\n this._reactor.publishTopic({ roomType, roomId, topic, data }),\n publishPresence: (data) =>\n this._reactor.publishPresence(roomType, roomId, data),\n getPresence: (opts) => this._reactor.getPresence(roomType, roomId, opts),\n };\n }\n\n shutdown() {\n delete globalInstantCoreStore[reactorKey(this._reactor.config)];\n this._reactor.shutdown();\n }\n\n /**\n * Use this for one-off queries.\n * Returns local data if available, otherwise fetches from the server.\n * Because we want to avoid stale data, this method will throw an error\n * if the user is offline or there is no active connection to the server.\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n *\n * const resp = await db.queryOnce({ goals: {} });\n * console.log(resp.data.goals)\n */\n queryOnce<Q extends ValidQuery<Q, Schema>>(\n query: Q,\n opts?: InstaQLOptions,\n ): Promise<{\n data: InstaQLResponse<Schema, Q, UseDates>;\n pageInfo: PageInfoResponse<Q>;\n }> {\n return this._reactor.queryOnce(query, opts);\n }\n\n /**\n * @deprecated This is an experimental function that is not yet ready for production use.\n * Use this function to sync an entire namespace.\n * It has many limitations that will be removed in the future:\n * 1. Must be used with an admin token\n * 2. Does not support permissions\n * 3. Does not support where clauses\n * 4. Does not support links\n * It also does not support multiple top-level namespaces. For example,\n * {posts: {}, users: {}} is invalid. Only `posts` or `users` is allowed, but not both.\n */\n _syncTableExperimental<Q extends ValidQuery<Q, Schema>>(\n query: ExactlyOne<Q>,\n cb: SyncTableCallback<Schema, Q, UseDates>,\n ): (\n opts?: { keepSubscription: boolean | null | undefined } | null | undefined,\n ) => void {\n return this._reactor.subscribeTable(query, cb);\n }\n}\n\nfunction schemaHash(schema?: InstantSchemaDef<any, any, any>): string {\n if (!schema) {\n return '0';\n }\n\n const fromStore = schemaHashStore.get(schema);\n if (fromStore) {\n return fromStore;\n }\n const hash = weakHash(schema);\n schemaHashStore.set(schema, hash);\n return hash;\n}\n\nfunction schemaChanged(\n existingClient: InstantCoreDatabase<any, boolean>,\n newSchema?: InstantSchemaDef<any, any, any>,\n): boolean {\n return (\n schemaHash(existingClient._reactor.config.schema) !== schemaHash(newSchema)\n );\n}\n\n/**\n *\n * The first step: init your application!\n *\n * Visit https://instantdb.com/dash to get your `appId` :)\n *\n * @example\n * import { init } from \"@instantdb/core\"\n *\n * const db = init({ appId: \"my-app-id\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@instantdb/core\"\n * import schema from \"\"../instant.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", schema })\n *\n * // To learn more: https://instantdb.com/docs/modeling-data\n */\nfunction init<\n Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,\n UseDates extends boolean = false,\n>(\n // Allows config with missing `useDateObjects`, but keeps `UseDates`\n // as a non-nullable in the InstantConfig type.\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n Storage?: any,\n NetworkListener?: any,\n versions?: { [key: string]: string },\n EventSourceImpl?: any,\n): InstantCoreDatabase<Schema, UseDates> {\n const configStrict = {\n ...config,\n appId: config.appId?.trim(),\n useDateObjects: (config.useDateObjects ?? false) as UseDates,\n };\n const existingClient = globalInstantCoreStore[\n reactorKey(configStrict)\n ] as InstantCoreDatabase<any, UseDates>;\n\n if (existingClient) {\n if (schemaChanged(existingClient, configStrict.schema)) {\n existingClient._reactor.updateSchema(configStrict.schema);\n }\n return existingClient;\n }\n\n const reactor = new Reactor<RoomsOf<Schema>>(\n {\n ...defaultConfig,\n ...configStrict,\n cardinalityInference: configStrict.schema ? true : false,\n },\n Storage || IndexedDBStorage,\n NetworkListener || WindowNetworkListener,\n { ...(versions || {}), '@instantdb/core': version },\n EventSourceImpl,\n );\n\n const client = new InstantCoreDatabase<any, UseDates>(reactor);\n globalInstantCoreStore[reactorKey(configStrict)] = client;\n\n handleDevtool(configStrict.appId, configStrict.devtool);\n\n return client;\n}\n\nfunction handleDevtool(\n appId: string,\n devtool: boolean | DevtoolConfig | null | undefined,\n) {\n if (\n typeof window === 'undefined' ||\n typeof window.location === 'undefined' ||\n typeof document === 'undefined'\n ) {\n return;\n }\n\n if (typeof devtool === 'boolean' && !devtool) {\n return;\n }\n\n const config: StrictDevtoolConfig = {\n position: 'bottom-right' as const,\n allowedHosts: ['localhost'],\n ...(typeof devtool === 'object' ? devtool : {}),\n };\n\n if (!config.allowedHosts.includes(window.location.hostname)) {\n return;\n }\n\n createDevtool(appId, config);\n}\n\n/**\n * @deprecated\n * `init_experimental` is deprecated. You can replace it with `init`.\n *\n * @example\n *\n * // Before\n * import { init_experimental } from \"@instantdb/core\"\n * const db = init_experimental({ ... });\n *\n * // After\n * import { init } from \"@instantdb/core\"\n * const db = init({ ... });\n */\nconst init_experimental = init;\n\nexport {\n // bada bing bada boom\n init,\n init_experimental,\n id,\n tx,\n txInit,\n lookup,\n validateQuery,\n QueryValidationError,\n validateTransactions,\n TransactionValidationError,\n\n // error\n InstantAPIError,\n\n // cli\n i,\n\n // util\n getOps,\n coerceQuery,\n weakHash,\n coerceToDate,\n IndexedDBStorage,\n WindowNetworkListener,\n InstantCoreDatabase,\n Auth,\n Storage,\n version,\n InstantError,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // og types\n type IDatabase,\n type RoomSchemaShape,\n type Query,\n type QueryResponse,\n type InstaQLResponse,\n type PageInfoResponse,\n type InstantObject,\n type Exactly,\n type TransactionChunk,\n type AuthState,\n type ConnectionStatus,\n type User,\n type AuthToken,\n type TxChunk,\n type SubscriptionState,\n type InstaQLSubscriptionState,\n type LifecycleSubscriptionState,\n type InstaQLLifecycleState,\n\n // presence types\n type PresenceOpts,\n type PresenceSlice,\n type PresenceResponse,\n type PresencePeer,\n\n // new query types\n type InstaQLParams,\n type ValidQuery,\n type InstaQLOptions,\n type InstaQLQueryParams,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantEntity,\n type InstantSchemaDatabase,\n type InstaQLFields,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type InstantUnknownSchemaDef,\n type EntitiesWithLinks,\n type EntityDef,\n type RoomsDef,\n type InstantGraph,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type RoomsOf,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type InstantSchemaDef,\n type InstantUnknownSchema,\n type IInstantDatabase,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\n type RuleParams,\n\n // attr types\n type InstantDBAttr,\n type InstantDBAttrOnDelete,\n type InstantDBCheckedDataType,\n type InstantDBIdent,\n type InstantDBInferredType,\n\n // auth types\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // SSE\n type EventSourceType,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n\n // error types\n type InstantIssue,\n\n // storage (e.g. indexeddb) interface\n StorageInterface,\n type StorageInterfaceStoreName,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAq4BE,oBAAI;AAqBJ,kCAAW;AA15Bb,8DAAmC;AACnC,6CAOsB;AAg4BpB,mFAt4BA,eAAE,OAs4BA;AACF,uFAt4BA,mBAAM,OAs4BA;AACN,uFAt4BA,mBAAM,OAs4BA;AAeN,uFAp5BA,mBAAM,OAo5BA;AAh5BR,sEAA2C;AAk5BzC,mBAl5BK,qBAAQ,CAk5BL;AAj5BV,0DAA+B;AA63B7B,aA73BK,eAAE,CA63BL;AA53BJ,gFAAqD;AAk5BnD,2BAl5BK,6BAAgB,CAk5BL;AAj5BlB,+CAAgD;AAg5B9C,6FAh5BO,uBAAY,OAg5BP;AA/4Bd,0FAA+D;AAi5B7D,gCAj5BK,kCAAqB,CAi5BL;AAh5BvB,2CAAgC;AAw4B9B,kFAx4BO,aAAC,OAw4BP;AAv4BH,6CAA6C;AAC7C,8DAAmC;AAk5BjC,kBAl5BK,oBAAO,CAk5BL;AAj5BT,6DAA2E;AA03BzE,8FA13BO,kCAAa,OA03BP;AACb,qGA33BsB,yCAAoB,OA23BtB;AA13BtB,yEAGoC;AAw3BlC,qGA13BA,+CAAoB,OA03BA;AAEpB,2GA33BA,qDAA0B,OA23BA;AAx3B5B,mEAGoC;AAy/BlC,iGA3/BA,qCAAgB,OA2/BA;AAx/BlB,mEAAoE;AA0/BlE,0GA1/BO,iDAAyB,OA0/BP;AAz/B3B,qEAA+D;AAk3B7D,oGAl3BO,4CAAmB,OAk3BP;AAlyBrB,iDAAuE;AAoyBrE,gGApyBO,8BAAe,OAoyBP;AAzxBjB,+CAAsE;AA4xBpE,gGA5xBO,0BAAe,OA4xBP;AA3xBjB,uDAAiD;AA2yB/C,6FA3yBO,8BAAY,OA2yBP;AAzyBd,iDAAiF;AA4yB/E,2GA5yB4B,gCA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AqB,kCACnC,CAAC,QAAQ,IAAI,EAAE,CAAC,KAAE,iBAAiB,EAAE,oBAAO,KACjD,eAAe,CAChB,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAgB,OAAO,CAAC,CAAC;IAC/D,sBAAsB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC;IAE1D,aAAa,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAExD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CACpB,KAAa,EACb,OAAmD;IAEnD,IACE,OAAO,MAAM,KAAK,WAAW;QAC7B,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;QACtC,OAAO,QAAQ,KAAK,WAAW,EAC/B,CAAC;QACD,OAAO;IACT,CAAC;IAED,IAAI,OAAO,OAAO,KAAK,SAAS,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7C,OAAO;IACT,CAAC;IAED,MAAM,MAAM,mBACV,QAAQ,EAAE,cAAuB,EACjC,YAAY,EAAE,CAAC,WAAW,CAAC,IACxB,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAChD,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5D,OAAO;IACT,CAAC;IAED,IAAA,0BAAa,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAK7B,8CAAiB","sourcesContent":["import Reactor from './Reactor.js';\nimport {\n tx,\n txInit,\n lookup,\n getOps,\n type TxChunk,\n type TransactionChunk,\n} from './instatx.js';\nimport weakHash from './utils/weakHash.js';\nimport id from './utils/id.ts';\nimport IndexedDBStorage from './IndexedDBStorage.ts';\nimport { coerceToDate } from './utils/dates.js';\nimport WindowNetworkListener from './WindowNetworkListener.js';\nimport { i } from './schema.js';\nimport { createDevtool } from './devtool.js';\nimport version from './version.ts';\nimport { validateQuery, QueryValidationError } from './queryValidation.ts';\nimport {\n validateTransactions,\n TransactionValidationError,\n} from './transactionValidation.ts';\n\nimport {\n StorageInterface,\n type StorageInterfaceStoreName,\n} from './utils/PersistedObject.ts';\nimport { createInstantRouteHandler } from './createRouteHandler.ts';\nimport { parseSchemaFromJSON } from './parseSchemaFromJSON.ts';\n\nimport type {\n PresenceOpts,\n PresenceResponse,\n PresenceSlice,\n RoomSchemaShape,\n} from './presence.ts';\nimport type {\n DevtoolConfig,\n IDatabase,\n IInstantDatabase,\n StrictDevtoolConfig,\n} from './coreTypes.ts';\nimport type {\n Query,\n QueryResponse,\n InstaQLResponse,\n PageInfoResponse,\n Exactly,\n InstantObject,\n InstaQLParams,\n InstaQLOptions,\n InstaQLQueryParams,\n InstaQLEntity,\n InstaQLEntitySubquery,\n InstaQLResult,\n InstaQLFields,\n ValidQuery,\n} from './queryTypes.ts';\nimport type { PresencePeer } from './presenceTypes.ts';\nimport type {\n AuthState,\n User,\n AuthResult,\n ConnectionStatus,\n} from './clientTypes.ts';\nimport type {\n InstantQuery,\n InstantQueryResult,\n InstantSchema,\n InstantEntity,\n InstantSchemaDatabase,\n} from './helperTypes.ts';\nimport type {\n InstantDBAttr,\n InstantDBAttrOnDelete,\n InstantDBCheckedDataType,\n InstantDBIdent,\n InstantDBInferredType,\n} from './attrTypes.ts';\nimport type {\n AttrsDefs,\n CardinalityKind,\n DataAttrDef,\n EntitiesDef,\n EntitiesWithLinks,\n EntityDef,\n RoomsDef,\n InstantSchemaDef,\n InstantGraph,\n LinkAttrDef,\n LinkDef,\n LinksDef,\n PresenceOf,\n ResolveAttrs,\n RoomsOf,\n TopicsOf,\n TopicOf,\n ValueTypes,\n InstantUnknownSchema,\n InstantUnknownSchemaDef,\n BackwardsCompatibleSchema,\n UpdateParams,\n LinkParams,\n CreateParams,\n RuleParams,\n} from './schemaTypes.ts';\nimport type { InstantRules } from './rulesTypes.ts';\nimport type { UploadFileResponse, DeleteFileResponse } from './StorageAPI.ts';\nimport { FrameworkClient, type FrameworkConfig } from './framework.ts';\n\nimport type {\n ExchangeCodeForTokenParams,\n SendMagicCodeParams,\n SendMagicCodeResponse,\n SignInWithIdTokenParams,\n VerifyMagicCodeParams,\n VerifyResponse,\n} from './authAPI.ts';\n\nimport { InstantAPIError, type InstantIssue } from './utils/fetch.js';\nimport { InstantError } from './InstantError.ts';\nimport { EventSourceType } from './Connection.ts';\nimport { CallbackEventType as SyncTableCallbackEventType } from './SyncTable.ts';\nimport type {\n SyncTableCallback,\n CallbackEvent as SyncTableCallbackEvent,\n InitialSyncBatch as SyncTableInitialSyncBatch,\n InitialSyncComplete as SyncTableInitialSyncComplete,\n SyncTransaction as SyncTableSyncTransaction,\n LoadFromStorage as SyncTableLoadFromStorage,\n SetupError as SyncTableSetupError,\n} from './SyncTable.ts';\n\nconst defaultOpenDevtool = true;\n\n// types\n\ntype ExactlyOne<T> = {\n [K in keyof T]: Pick<T, K> & Partial<Record<Exclude<keyof T, K>, never>>;\n}[keyof T];\n\nexport type Config = {\n appId: string;\n websocketURI?: string;\n apiURI?: string;\n devtool?: boolean | DevtoolConfig;\n verbose?: boolean;\n queryCacheLimit?: number;\n useDateObjects: boolean;\n disableValidation?: boolean;\n};\n\nexport type InstantConfig<\n S extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean = false,\n> = {\n appId: string;\n schema?: S;\n websocketURI?: string;\n firstPartyPath?: string;\n apiURI?: string;\n devtool?: boolean | DevtoolConfig;\n verbose?: boolean;\n queryCacheLimit?: number;\n useDateObjects: UseDates;\n disableValidation?: boolean;\n};\n\nexport type ConfigWithSchema<S extends InstantGraph<any, any>> = Config & {\n schema: S;\n};\n\nexport type TransactionResult = {\n status: 'synced' | 'enqueued';\n clientId: string;\n};\n\nexport type PublishTopic<TopicsByKey> = <Key extends keyof TopicsByKey>(\n topic: Key,\n data: TopicsByKey[Key],\n) => void;\n\nexport type SubscribeTopic<PresenceShape, TopicsByKey> = <\n Key extends keyof TopicsByKey,\n>(\n topic: Key,\n onEvent: (event: TopicsByKey[Key], peer: PresenceShape) => void,\n) => () => void;\n\nexport type GetPresence<PresenceShape> = <Keys extends keyof PresenceShape>(\n opts: PresenceOpts<PresenceShape, Keys>,\n) => PresenceResponse<PresenceShape, Keys> | null;\n\nexport type SubscribePresence<PresenceShape> = <\n Keys extends keyof PresenceShape,\n>(\n opts: PresenceOpts<PresenceShape, Keys>,\n onChange: (slice: PresenceResponse<PresenceShape, Keys>) => void,\n) => () => void;\n\nexport type RoomHandle<PresenceShape, TopicsByKey> = {\n leaveRoom: () => void;\n publishTopic: PublishTopic<TopicsByKey>;\n subscribeTopic: SubscribeTopic<PresenceShape, TopicsByKey>;\n publishPresence: (data: Partial<PresenceShape>) => void;\n getPresence: GetPresence<PresenceShape>;\n subscribePresence: SubscribePresence<PresenceShape>;\n};\n\ntype AuthToken = string;\n\ntype SubscriptionState<Q, Schema, WithCardinalityInference extends boolean> =\n | { error: { message: string }; data: undefined; pageInfo: undefined }\n | {\n error: undefined;\n data: QueryResponse<Q, Schema, WithCardinalityInference>;\n pageInfo: PageInfoResponse<Q>;\n };\n\ntype InstaQLSubscriptionState<Schema, Q, UseDates extends boolean> =\n | { error: { message: string }; data: undefined; pageInfo: undefined }\n | {\n error: undefined;\n data: InstaQLResponse<Schema, Q, UseDates>;\n pageInfo: PageInfoResponse<Q>;\n };\n\ntype LifecycleSubscriptionState<\n Q,\n Schema,\n WithCardinalityInference extends boolean,\n> = SubscriptionState<Q, Schema, WithCardinalityInference> & {\n isLoading: boolean;\n};\n\ntype InstaQLLifecycleState<Schema, Q, UseDates extends boolean = false> =\n | (InstaQLSubscriptionState<Schema, Q, UseDates> & {\n isLoading: boolean;\n })\n | {\n isLoading: true;\n data: undefined;\n pageInfo: undefined;\n error: undefined;\n };\n\ntype UnsubscribeFn = () => void;\n\n// consts\n\nconst defaultConfig = {\n apiURI: 'https://api.instantdb.com',\n websocketURI: 'wss://api.instantdb.com/runtime/session',\n};\n\n// hmr\nfunction initSchemaHashStore(): WeakMap<any, string> {\n globalThis.__instantDbSchemaHashStore =\n globalThis.__instantDbSchemaHashStore ?? new WeakMap<any, string>();\n return globalThis.__instantDbSchemaHashStore;\n}\n\nfunction initGlobalInstantCoreStore(): Record<string, any> {\n globalThis.__instantDbStore = globalThis.__instantDbStore ?? {};\n return globalThis.__instantDbStore;\n}\n\nfunction reactorKey(config: InstantConfig<any, boolean>): string {\n // @ts-expect-error\n const adminToken = config.__adminToken;\n return (\n config.appId +\n '_' +\n (config.websocketURI || 'default_ws_uri') +\n '_' +\n (config.apiURI || 'default_api_uri') +\n '_' +\n (adminToken || 'client_only') +\n '_' +\n config.useDateObjects\n );\n}\n\nconst globalInstantCoreStore = initGlobalInstantCoreStore();\nconst schemaHashStore = initSchemaHashStore();\n\ntype SignoutOpts = {\n invalidateToken?: boolean;\n};\n\n/**\n * Functions to log users in and out.\n *\n * @see https://instantdb.com/docs/auth\n */\nclass Auth {\n constructor(private db: Reactor) {}\n\n /**\n * Sends a magic code to the user's email address.\n *\n * Once you send the magic code, see {@link auth.signInWithMagicCode} to let the\n * user verify.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * db.auth.sendMagicCode({email: \"example@gmail.com\"})\n * .catch((err) => console.error(err.body?.message))\n */\n sendMagicCode = (\n params: SendMagicCodeParams,\n ): Promise<SendMagicCodeResponse> => {\n return this.db.sendMagicCode(params);\n };\n\n /**\n * Verify a magic code that was sent to the user's email address.\n *\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * db.auth.signInWithMagicCode({email: \"example@gmail.com\", code: \"123456\"})\n * .catch((err) => console.error(err.body?.message))\n */\n signInWithMagicCode = (\n params: VerifyMagicCodeParams,\n ): Promise<VerifyResponse> => {\n return this.db.signInWithMagicCode(params);\n };\n\n /**\n * Sign in a user with a refresh token\n *\n * @see https://instantdb.com/docs/backend#frontend-auth-sign-in-with-token\n *\n * @example\n * // Get the token from your backend\n * const token = await fetch('/signin', ...);\n * //Sign in\n * db.auth.signInWithToken(token);\n */\n signInWithToken = (token: AuthToken): Promise<VerifyResponse> => {\n return this.db.signInWithCustomToken(token);\n };\n\n /**\n * Sign in as guest, creating a new user without email\n *\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * db.auth.signInAsGuest();\n */\n signInAsGuest = (): Promise<VerifyResponse> => {\n return this.db.signInAsGuest();\n };\n\n /**\n * Create an authorization url to sign in with an external provider.\n *\n * @see https://instantdb.com/docs/auth\n *\n * @example\n * // Get the authorization url from your backend\n * const url = db.auth.createAuthorizationUrl({\n * clientName: \"google\",\n * redirectURL: window.location.href,\n * });\n *\n * // Put it in a sign in link\n * <a href={url}>Log in with Google</a>\n */\n createAuthorizationURL = (params: {\n clientName: string;\n redirectURL: string;\n }): string => {\n return this.db.createAuthorizationURL(params);\n };\n\n /**\n * Sign in with the id_token from an external provider like Google\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * db.auth\n * .signInWithIdToken({\n * // Token from external service\n * idToken: id_token,\n * // The name you gave the client when you registered it with Instant\n * clientName: \"google\",\n * // The nonce, if any, that you used when you initiated the auth flow\n * // with the external service.\n * nonce: your_nonce\n * })\n * .catch((err) => console.error(err.body?.message));\n *\n */\n signInWithIdToken = (\n params: SignInWithIdTokenParams,\n ): Promise<VerifyResponse> => {\n return this.db.signInWithIdToken(params);\n };\n\n /**\n * Sign in with the id_token from an external provider like Google\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * db.auth\n * .exchangeOAuthCode({\n * // code received in redirect from OAuth callback\n * code: code\n * // The PKCE code_verifier, if any, that you used when you\n * // initiated the auth flow\n * codeVerifier: your_code_verifier\n * })\n * .catch((err) => console.error(err.body?.message));\n *\n */\n exchangeOAuthCode = (params: ExchangeCodeForTokenParams) => {\n return this.db.exchangeCodeForToken(params);\n };\n\n /**\n * OpenID Discovery path for use with tools like\n * expo-auth-session that use auto-discovery of\n * OAuth parameters.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const discovery = useAutoDiscovery(\n * db.auth.issuerURI()\n * );\n */\n issuerURI = (): string => {\n return this.db.issuerURI();\n };\n\n /**\n * Sign out the current user\n */\n signOut = (opts: SignoutOpts = { invalidateToken: true }): Promise<void> => {\n return this.db.signOut(opts);\n };\n}\n\ntype FileOpts = {\n contentType?: string;\n contentDisposition?: string;\n fileSize?: number; // Required for streaming uploads\n};\n\n/**\n * Functions to manage file storage.\n */\nclass Storage {\n constructor(private db: Reactor) {}\n\n /**\n * Uploads file at the provided path.\n *\n * @see https://instantdb.com/docs/storage\n * @example\n * const [file] = e.target.files; // result of file input\n * const data = await db.storage.uploadFile('photos/demo.png', file);\n */\n uploadFile = (\n path: string,\n file: File | Blob,\n opts: FileOpts = {},\n ): Promise<UploadFileResponse> => {\n return this.db.uploadFile(path, file, opts);\n };\n\n /**\n * Deletes a file by path name.\n *\n * @see https://instantdb.com/docs/storage\n * @example\n * await db.storage.delete('photos/demo.png');\n */\n delete = (pathname: string) => {\n return this.db.deleteFile(pathname);\n };\n\n // Deprecated Storage API (Jan 2025)\n // ---------------------------------\n\n /**\n * @deprecated. Use `db.storage.uploadFile` instead\n * remove in the future.\n */\n upload = (pathname: string, file: File) => {\n return this.db.upload(pathname, file);\n };\n\n /**\n * @deprecated Use `db.storage.uploadFile` instead\n */\n put = this.upload;\n\n /**\n * @deprecated. getDownloadUrl will be removed in the future.\n * Use `useQuery` instead to query and fetch for valid urls\n *\n * db.useQuery({\n * $files: {\n * $: {\n * where: {\n * path: \"moop.png\"\n * }\n * }\n * }\n * })\n */\n getDownloadUrl = (pathname: string) => {\n return this.db.getDownloadUrl(pathname);\n };\n}\n\n// util\n\nfunction coerceQuery(o: any) {\n // stringify and parse to remove undefined values\n return JSON.parse(JSON.stringify(o));\n}\n\nclass InstantCoreDatabase<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean = false,\n> implements IInstantDatabase<Schema>\n{\n public _reactor: Reactor<RoomsOf<Schema>>;\n public auth: Auth;\n public storage: Storage;\n\n public tx = txInit<Schema>();\n\n constructor(reactor: Reactor<RoomsOf<Schema>>) {\n this._reactor = reactor;\n this.auth = new Auth(this._reactor);\n this.storage = new Storage(this._reactor);\n }\n\n /**\n * Use this to write data! You can create, update, delete, and link objects\n *\n * @see https://instantdb.com/docs/instaml\n *\n * @example\n * // Create a new object in the `goals` namespace\n * const goalId = id();\n * db.transact(db.tx.goals[goalId].update({title: \"Get fit\"}))\n *\n * // Update the title\n * db.transact(db.tx.goals[goalId].update({title: \"Get super fit\"}))\n *\n * // Delete it\n * db.transact(db.tx.goals[goalId].delete())\n *\n * // Or create an association:\n * todoId = id();\n * db.transact([\n * db.tx.todos[todoId].update({ title: 'Go on a run' }),\n * db.tx.goals[goalId].link({todos: todoId}),\n * ])\n */\n transact(\n chunks: TransactionChunk<any, any> | TransactionChunk<any, any>[],\n ): Promise<TransactionResult> {\n return this._reactor.pushTx(chunks);\n }\n\n getLocalId(name: string): Promise<string> {\n return this._reactor.getLocalId(name);\n }\n\n /**\n * Use this to query your data!\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n * // listen to all goals\n * db.subscribeQuery({ goals: {} }, (resp) => {\n * console.log(resp.data.goals)\n * })\n *\n * // goals where the title is \"Get Fit\"\n * db.subscribeQuery(\n * { goals: { $: { where: { title: \"Get Fit\" } } } },\n * (resp) => {\n * console.log(resp.data.goals)\n * }\n * )\n *\n * // all goals, _alongside_ their todos\n * db.subscribeQuery({ goals: { todos: {} } }, (resp) => {\n * console.log(resp.data.goals)\n * });\n */\n subscribeQuery<\n Q extends ValidQuery<Q, Schema>,\n UseDatesLocal extends boolean = UseDates,\n >(\n query: Q,\n cb: (resp: InstaQLSubscriptionState<Schema, Q, UseDatesLocal>) => void,\n opts?: InstaQLOptions,\n ) {\n return this._reactor.subscribeQuery(query, cb, opts);\n }\n\n /**\n * Listen for the logged in state. This is useful\n * for deciding when to show a login screen.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const unsub = db.subscribeAuth((auth) => {\n * if (auth.user) {\n * console.log('logged in as', auth.user.email)\n * } else {\n * console.log('logged out')\n * }\n * })\n */\n subscribeAuth(cb: (auth: AuthResult) => void): UnsubscribeFn {\n return this._reactor.subscribeAuth(cb);\n }\n\n /**\n * One time query for the logged in state. This is useful\n * for scenarios where you want to know the current auth\n * state without subscribing to changes.\n *\n * @see https://instantdb.com/docs/auth\n * @example\n * const user = await db.getAuth();\n * console.log('logged in as', user.email)\n */\n getAuth(): Promise<User | null> {\n return this._reactor.getAuth();\n }\n\n /**\n * Listen for connection status changes to Instant. This is useful\n * for building things like connectivity indicators\n *\n * @see https://www.instantdb.com/docs/patterns#connection-status\n * @example\n * const unsub = db.subscribeConnectionStatus((status) => {\n * const connectionState =\n * status === 'connecting' || status === 'opened'\n * ? 'authenticating'\n * : status === 'authenticated'\n * ? 'connected'\n * : status === 'closed'\n * ? 'closed'\n * : status === 'errored'\n * ? 'errored'\n * : 'unexpected state';\n *\n * console.log('Connection status:', connectionState);\n * });\n */\n subscribeConnectionStatus(\n cb: (status: ConnectionStatus) => void,\n ): UnsubscribeFn {\n return this._reactor.subscribeConnectionStatus(cb);\n }\n\n /**\n * Join a room to publish and subscribe to topics and presence.\n *\n * @see https://instantdb.com/docs/presence-and-topics\n * @example\n * // init\n * const db = init();\n * const room = db.joinRoom(roomType, roomId);\n * // usage\n * const unsubscribeTopic = room.subscribeTopic(\"foo\", console.log);\n * const unsubscribePresence = room.subscribePresence({}, console.log);\n * room.publishTopic(\"hello\", { message: \"hello world!\" });\n * room.publishPresence({ name: \"joe\" });\n * // later\n * unsubscribePresence();\n * unsubscribeTopic();\n * room.leaveRoom();\n */\n joinRoom<RoomType extends keyof RoomsOf<Schema>>(\n roomType: RoomType = '_defaultRoomType' as RoomType,\n roomId: string = '_defaultRoomId',\n opts?: {\n initialPresence?: Partial<PresenceOf<Schema, RoomType>>;\n },\n ): RoomHandle<PresenceOf<Schema, RoomType>, TopicsOf<Schema, RoomType>> {\n const leaveRoom = this._reactor.joinRoom(roomId, opts?.initialPresence);\n\n return {\n leaveRoom,\n subscribeTopic: (topic, onEvent) =>\n this._reactor.subscribeTopic(roomId, topic, onEvent),\n subscribePresence: (opts, onChange) =>\n this._reactor.subscribePresence(roomType, roomId, opts, onChange),\n publishTopic: (topic, data) =>\n this._reactor.publishTopic({ roomType, roomId, topic, data }),\n publishPresence: (data) =>\n this._reactor.publishPresence(roomType, roomId, data),\n getPresence: (opts) => this._reactor.getPresence(roomType, roomId, opts),\n };\n }\n\n shutdown() {\n delete globalInstantCoreStore[reactorKey(this._reactor.config)];\n this._reactor.shutdown();\n }\n\n /**\n * Use this for one-off queries.\n * Returns local data if available, otherwise fetches from the server.\n * Because we want to avoid stale data, this method will throw an error\n * if the user is offline or there is no active connection to the server.\n *\n * @see https://instantdb.com/docs/instaql\n *\n * @example\n *\n * const resp = await db.queryOnce({ goals: {} });\n * console.log(resp.data.goals)\n */\n queryOnce<Q extends ValidQuery<Q, Schema>>(\n query: Q,\n opts?: InstaQLOptions,\n ): Promise<{\n data: InstaQLResponse<Schema, Q, UseDates>;\n pageInfo: PageInfoResponse<Q>;\n }> {\n return this._reactor.queryOnce(query, opts);\n }\n\n /**\n * @deprecated This is an experimental function that is not yet ready for production use.\n * Use this function to sync an entire namespace.\n * It has many limitations that will be removed in the future:\n * 1. Must be used with an admin token\n * 2. Does not support permissions\n * 3. Does not support where clauses\n * 4. Does not support links\n * It also does not support multiple top-level namespaces. For example,\n * {posts: {}, users: {}} is invalid. Only `posts` or `users` is allowed, but not both.\n */\n _syncTableExperimental<Q extends ValidQuery<Q, Schema>>(\n query: ExactlyOne<Q>,\n cb: SyncTableCallback<Schema, Q, UseDates>,\n ): (\n opts?: { keepSubscription: boolean | null | undefined } | null | undefined,\n ) => void {\n return this._reactor.subscribeTable(query, cb);\n }\n}\n\nfunction schemaHash(schema?: InstantSchemaDef<any, any, any>): string {\n if (!schema) {\n return '0';\n }\n\n const fromStore = schemaHashStore.get(schema);\n if (fromStore) {\n return fromStore;\n }\n const hash = weakHash(schema);\n schemaHashStore.set(schema, hash);\n return hash;\n}\n\nfunction schemaChanged(\n existingClient: InstantCoreDatabase<any, boolean>,\n newSchema?: InstantSchemaDef<any, any, any>,\n): boolean {\n return (\n schemaHash(existingClient._reactor.config.schema) !== schemaHash(newSchema)\n );\n}\n\n/**\n *\n * The first step: init your application!\n *\n * Visit https://instantdb.com/dash to get your `appId` :)\n *\n * @example\n * import { init } from \"@instantdb/core\"\n *\n * const db = init({ appId: \"my-app-id\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@instantdb/core\"\n * import schema from \"\"../instant.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", schema })\n *\n * // To learn more: https://instantdb.com/docs/modeling-data\n */\nfunction init<\n Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,\n UseDates extends boolean = false,\n>(\n // Allows config with missing `useDateObjects`, but keeps `UseDates`\n // as a non-nullable in the InstantConfig type.\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n Storage?: any,\n NetworkListener?: any,\n versions?: { [key: string]: string },\n EventSourceImpl?: any,\n): InstantCoreDatabase<Schema, UseDates> {\n const configStrict = {\n ...config,\n appId: config.appId?.trim(),\n useDateObjects: (config.useDateObjects ?? false) as UseDates,\n };\n const existingClient = globalInstantCoreStore[\n reactorKey(configStrict)\n ] as InstantCoreDatabase<any, UseDates>;\n\n if (existingClient) {\n if (schemaChanged(existingClient, configStrict.schema)) {\n existingClient._reactor.updateSchema(configStrict.schema);\n }\n return existingClient;\n }\n\n const reactor = new Reactor<RoomsOf<Schema>>(\n {\n ...defaultConfig,\n ...configStrict,\n cardinalityInference: configStrict.schema ? true : false,\n },\n Storage || IndexedDBStorage,\n NetworkListener || WindowNetworkListener,\n { ...(versions || {}), '@instantdb/core': version },\n EventSourceImpl,\n );\n\n const client = new InstantCoreDatabase<any, UseDates>(reactor);\n globalInstantCoreStore[reactorKey(configStrict)] = client;\n\n handleDevtool(configStrict.appId, configStrict.devtool);\n\n return client;\n}\n\nfunction handleDevtool(\n appId: string,\n devtool: boolean | DevtoolConfig | null | undefined,\n) {\n if (\n typeof window === 'undefined' ||\n typeof window.location === 'undefined' ||\n typeof document === 'undefined'\n ) {\n return;\n }\n\n if (typeof devtool === 'boolean' && !devtool) {\n return;\n }\n\n const config: StrictDevtoolConfig = {\n position: 'bottom-right' as const,\n allowedHosts: ['localhost'],\n ...(typeof devtool === 'object' ? devtool : {}),\n };\n\n if (!config.allowedHosts.includes(window.location.hostname)) {\n return;\n }\n\n createDevtool(appId, config);\n}\n\n/**\n * @deprecated\n * `init_experimental` is deprecated. You can replace it with `init`.\n *\n * @example\n *\n * // Before\n * import { init_experimental } from \"@instantdb/core\"\n * const db = init_experimental({ ... });\n *\n * // After\n * import { init } from \"@instantdb/core\"\n * const db = init({ ... });\n */\nconst init_experimental = init;\n\nexport {\n // bada bing bada boom\n init,\n init_experimental,\n id,\n tx,\n txInit,\n lookup,\n validateQuery,\n QueryValidationError,\n validateTransactions,\n parseSchemaFromJSON,\n TransactionValidationError,\n FrameworkClient,\n\n // error\n InstantAPIError,\n\n // cli\n i,\n\n // util\n getOps,\n coerceQuery,\n weakHash,\n coerceToDate,\n IndexedDBStorage,\n WindowNetworkListener,\n InstantCoreDatabase,\n Auth,\n Storage,\n version,\n InstantError,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // og types\n type IDatabase,\n type RoomSchemaShape,\n type Query,\n type QueryResponse,\n type InstaQLResponse,\n type PageInfoResponse,\n type InstantObject,\n type Exactly,\n type TransactionChunk,\n type AuthState,\n type ConnectionStatus,\n type User,\n type AuthToken,\n type TxChunk,\n type SubscriptionState,\n type InstaQLSubscriptionState,\n type LifecycleSubscriptionState,\n type InstaQLLifecycleState,\n\n // presence types\n type PresenceOpts,\n type PresenceSlice,\n type PresenceResponse,\n type PresencePeer,\n\n // new query types\n type InstaQLParams,\n type ValidQuery,\n type InstaQLOptions,\n type InstaQLQueryParams,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantEntity,\n type InstantSchemaDatabase,\n type InstaQLFields,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type InstantUnknownSchemaDef,\n type EntitiesWithLinks,\n type EntityDef,\n type RoomsDef,\n type InstantGraph,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type RoomsOf,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type InstantSchemaDef,\n type InstantUnknownSchema,\n type IInstantDatabase,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\n type RuleParams,\n\n // attr types\n type InstantDBAttr,\n type InstantDBAttrOnDelete,\n type InstantDBCheckedDataType,\n type InstantDBIdent,\n type InstantDBInferredType,\n\n // auth types\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // SSE\n type EventSourceType,\n type FrameworkConfig,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n\n // error types\n type InstantIssue,\n\n // storage (e.g. indexeddb) interface\n StorageInterface,\n type StorageInterfaceStoreName,\n createInstantRouteHandler,\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseSchemaFromJSON.d.ts","sourceRoot":"","sources":["../../src/parseSchemaFromJSON.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEjE,eAAO,MAAM,mBAAmB,GAC9B,GAAG,GAAG,KACL,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CA0KhC,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseSchemaFromJSON = void 0;
|
|
4
|
+
const schema_ts_1 = require("./schema.js");
|
|
5
|
+
const parseSchemaFromJSON = (s) => {
|
|
6
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7
|
+
// Parse entities
|
|
8
|
+
const entities = {};
|
|
9
|
+
for (const [entityName, entityInfo] of Object.entries(s.entities)) {
|
|
10
|
+
const entityDef = entityInfo;
|
|
11
|
+
const attrs = {};
|
|
12
|
+
// Parse attributes
|
|
13
|
+
for (const [attrName, attrInfo] of Object.entries(entityDef.attrs)) {
|
|
14
|
+
const attrDef = attrInfo;
|
|
15
|
+
let attr;
|
|
16
|
+
// Create the appropriate attribute type
|
|
17
|
+
switch (attrDef.valueType) {
|
|
18
|
+
case 'string':
|
|
19
|
+
attr = schema_ts_1.i.string();
|
|
20
|
+
break;
|
|
21
|
+
case 'number':
|
|
22
|
+
attr = schema_ts_1.i.number();
|
|
23
|
+
break;
|
|
24
|
+
case 'boolean':
|
|
25
|
+
attr = schema_ts_1.i.boolean();
|
|
26
|
+
break;
|
|
27
|
+
case 'date':
|
|
28
|
+
attr = schema_ts_1.i.date();
|
|
29
|
+
break;
|
|
30
|
+
case 'json':
|
|
31
|
+
attr = schema_ts_1.i.json();
|
|
32
|
+
break;
|
|
33
|
+
default:
|
|
34
|
+
attr = schema_ts_1.i.json();
|
|
35
|
+
}
|
|
36
|
+
// Apply modifiers
|
|
37
|
+
if (!attrDef.required) {
|
|
38
|
+
attr = attr.optional();
|
|
39
|
+
}
|
|
40
|
+
if ((_a = attrDef.config) === null || _a === void 0 ? void 0 : _a.indexed) {
|
|
41
|
+
attr = attr.indexed();
|
|
42
|
+
}
|
|
43
|
+
if ((_b = attrDef.config) === null || _b === void 0 ? void 0 : _b.unique) {
|
|
44
|
+
attr = attr.unique();
|
|
45
|
+
}
|
|
46
|
+
attrs[attrName] = attr;
|
|
47
|
+
}
|
|
48
|
+
entities[entityName] = schema_ts_1.i.entity(attrs);
|
|
49
|
+
}
|
|
50
|
+
// Parse links
|
|
51
|
+
const links = s.links || {};
|
|
52
|
+
// Parse rooms
|
|
53
|
+
const rooms = {};
|
|
54
|
+
if (s.rooms) {
|
|
55
|
+
for (const [roomName, roomInfo] of Object.entries(s.rooms)) {
|
|
56
|
+
const roomDef = roomInfo;
|
|
57
|
+
// Parse presence
|
|
58
|
+
const presenceAttrs = {};
|
|
59
|
+
for (const [attrName, attrInfo] of Object.entries(roomDef.presence.attrs)) {
|
|
60
|
+
const attrDef = attrInfo;
|
|
61
|
+
let attr;
|
|
62
|
+
switch (attrDef.valueType) {
|
|
63
|
+
case 'string':
|
|
64
|
+
attr = schema_ts_1.i.string();
|
|
65
|
+
break;
|
|
66
|
+
case 'number':
|
|
67
|
+
attr = schema_ts_1.i.number();
|
|
68
|
+
break;
|
|
69
|
+
case 'boolean':
|
|
70
|
+
attr = schema_ts_1.i.boolean();
|
|
71
|
+
break;
|
|
72
|
+
case 'date':
|
|
73
|
+
attr = schema_ts_1.i.date();
|
|
74
|
+
break;
|
|
75
|
+
case 'json':
|
|
76
|
+
attr = schema_ts_1.i.json();
|
|
77
|
+
break;
|
|
78
|
+
default:
|
|
79
|
+
attr = schema_ts_1.i.json();
|
|
80
|
+
}
|
|
81
|
+
if (!attrDef.required) {
|
|
82
|
+
attr = attr.optional();
|
|
83
|
+
}
|
|
84
|
+
if ((_c = attrDef.config) === null || _c === void 0 ? void 0 : _c.indexed) {
|
|
85
|
+
attr = attr.indexed();
|
|
86
|
+
}
|
|
87
|
+
if ((_d = attrDef.config) === null || _d === void 0 ? void 0 : _d.unique) {
|
|
88
|
+
attr = attr.unique();
|
|
89
|
+
}
|
|
90
|
+
presenceAttrs[attrName] = attr;
|
|
91
|
+
}
|
|
92
|
+
// Parse topics
|
|
93
|
+
const topics = {};
|
|
94
|
+
if (roomDef.topics) {
|
|
95
|
+
for (const [topicName, topicInfo] of Object.entries(roomDef.topics)) {
|
|
96
|
+
const topicDef = topicInfo;
|
|
97
|
+
const topicAttrs = {};
|
|
98
|
+
for (const [attrName, attrInfo] of Object.entries(topicDef.attrs)) {
|
|
99
|
+
const attrDef = attrInfo;
|
|
100
|
+
let attr;
|
|
101
|
+
switch (attrDef.valueType) {
|
|
102
|
+
case 'string':
|
|
103
|
+
attr = schema_ts_1.i.string();
|
|
104
|
+
break;
|
|
105
|
+
case 'number':
|
|
106
|
+
attr = schema_ts_1.i.number();
|
|
107
|
+
break;
|
|
108
|
+
case 'boolean':
|
|
109
|
+
attr = schema_ts_1.i.boolean();
|
|
110
|
+
break;
|
|
111
|
+
case 'date':
|
|
112
|
+
attr = schema_ts_1.i.date();
|
|
113
|
+
break;
|
|
114
|
+
case 'json':
|
|
115
|
+
attr = schema_ts_1.i.json();
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
attr = schema_ts_1.i.json();
|
|
119
|
+
}
|
|
120
|
+
if (!attrDef.required) {
|
|
121
|
+
attr = attr.optional();
|
|
122
|
+
}
|
|
123
|
+
if ((_e = attrDef.config) === null || _e === void 0 ? void 0 : _e.indexed) {
|
|
124
|
+
attr = attr.indexed();
|
|
125
|
+
}
|
|
126
|
+
if ((_f = attrDef.config) === null || _f === void 0 ? void 0 : _f.unique) {
|
|
127
|
+
attr = attr.unique();
|
|
128
|
+
}
|
|
129
|
+
topicAttrs[attrName] = attr;
|
|
130
|
+
}
|
|
131
|
+
topics[topicName] = schema_ts_1.i.entity(topicAttrs);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
rooms[roomName] = {
|
|
135
|
+
presence: schema_ts_1.i.entity(presenceAttrs),
|
|
136
|
+
topics,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const resultingSchema = schema_ts_1.i.schema({
|
|
141
|
+
entities,
|
|
142
|
+
links,
|
|
143
|
+
rooms,
|
|
144
|
+
});
|
|
145
|
+
return resultingSchema;
|
|
146
|
+
};
|
|
147
|
+
exports.parseSchemaFromJSON = parseSchemaFromJSON;
|
|
148
|
+
//# sourceMappingURL=parseSchemaFromJSON.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseSchemaFromJSON.js","sourceRoot":"","sources":["../../src/parseSchemaFromJSON.ts"],"names":[],"mappings":";;;AAAA,2CAAgC;AAGzB,MAAM,mBAAmB,GAAG,CACjC,CAAM,EAC2B,EAAE;;IACnC,iBAAiB;IACjB,MAAM,QAAQ,GAAwB,EAAE,CAAC;IAEzC,KAAK,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClE,MAAM,SAAS,GAAG,UAAiB,CAAC;QACpC,MAAM,KAAK,GAAwB,EAAE,CAAC;QAEtC,mBAAmB;QACnB,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACnE,MAAM,OAAO,GAAG,QAAe,CAAC;YAChC,IAAI,IAAgC,CAAC;YAErC,wCAAwC;YACxC,QAAQ,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC1B,KAAK,QAAQ;oBACX,IAAI,GAAG,aAAC,CAAC,MAAM,EAAE,CAAC;oBAClB,MAAM;gBACR,KAAK,QAAQ;oBACX,IAAI,GAAG,aAAC,CAAC,MAAM,EAAE,CAAC;oBAClB,MAAM;gBACR,KAAK,SAAS;oBACZ,IAAI,GAAG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B,CAAC;oBAED,MAAM,CAAC,SAAS,CAAC,GAAG,aAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAC3C,CAAC;YACH,CAAC;YAED,KAAK,CAAC,QAAQ,CAAC,GAAG;gBAChB,QAAQ,EAAE,aAAC,CAAC,MAAM,CAAC,aAAa,CAAC;gBACjC,MAAM;aACP,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,eAAe,GAAG,aAAC,CAAC,MAAM,CAAC;QAC/B,QAAQ;QACR,KAAK;QACL,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AA5KW,QAAA,mBAAmB,uBA4K9B","sourcesContent":["import { i } from './schema.ts';\nimport { DataAttrDef, InstantSchemaDef } from './schemaTypes.ts';\n\nexport const parseSchemaFromJSON = (\n s: any,\n): InstantSchemaDef<any, any, any> => {\n // Parse entities\n const entities: Record<string, any> = {};\n\n for (const [entityName, entityInfo] of Object.entries(s.entities)) {\n const entityDef = entityInfo as any;\n const attrs: Record<string, any> = {};\n\n // Parse attributes\n for (const [attrName, attrInfo] of Object.entries(entityDef.attrs)) {\n const attrDef = attrInfo as any;\n let attr: DataAttrDef<any, any, any>;\n\n // Create the appropriate attribute type\n switch (attrDef.valueType) {\n case 'string':\n attr = i.string();\n break;\n case 'number':\n attr = i.number();\n break;\n case 'boolean':\n attr = i.boolean();\n break;\n case 'date':\n attr = i.date();\n break;\n case 'json':\n attr = i.json();\n break;\n default:\n attr = i.json();\n }\n\n // Apply modifiers\n if (!attrDef.required) {\n attr = attr.optional();\n }\n\n if (attrDef.config?.indexed) {\n attr = attr.indexed();\n }\n\n if (attrDef.config?.unique) {\n attr = attr.unique();\n }\n\n attrs[attrName] = attr;\n }\n\n entities[entityName] = i.entity(attrs);\n }\n\n // Parse links\n const links: Record<string, any> = s.links || {};\n\n // Parse rooms\n const rooms: Record<string, any> = {};\n\n if (s.rooms) {\n for (const [roomName, roomInfo] of Object.entries(s.rooms)) {\n const roomDef = roomInfo as any;\n\n // Parse presence\n const presenceAttrs: Record<string, any> = {};\n for (const [attrName, attrInfo] of Object.entries(\n roomDef.presence.attrs,\n )) {\n const attrDef = attrInfo as any;\n let attr: DataAttrDef<any, any, any>;\n\n switch (attrDef.valueType) {\n case 'string':\n attr = i.string();\n break;\n case 'number':\n attr = i.number();\n break;\n case 'boolean':\n attr = i.boolean();\n break;\n case 'date':\n attr = i.date();\n break;\n case 'json':\n attr = i.json();\n break;\n default:\n attr = i.json();\n }\n\n if (!attrDef.required) {\n attr = attr.optional();\n }\n\n if (attrDef.config?.indexed) {\n attr = attr.indexed();\n }\n\n if (attrDef.config?.unique) {\n attr = attr.unique();\n }\n\n presenceAttrs[attrName] = attr;\n }\n\n // Parse topics\n const topics: Record<string, any> = {};\n if (roomDef.topics) {\n for (const [topicName, topicInfo] of Object.entries(roomDef.topics)) {\n const topicDef = topicInfo as any;\n const topicAttrs: Record<string, any> = {};\n\n for (const [attrName, attrInfo] of Object.entries(topicDef.attrs)) {\n const attrDef = attrInfo as any;\n let attr: DataAttrDef<any, any, any>;\n\n switch (attrDef.valueType) {\n case 'string':\n attr = i.string();\n break;\n case 'number':\n attr = i.number();\n break;\n case 'boolean':\n attr = i.boolean();\n break;\n case 'date':\n attr = i.date();\n break;\n case 'json':\n attr = i.json();\n break;\n default:\n attr = i.json();\n }\n\n if (!attrDef.required) {\n attr = attr.optional();\n }\n\n if (attrDef.config?.indexed) {\n attr = attr.indexed();\n }\n\n if (attrDef.config?.unique) {\n attr = attr.unique();\n }\n\n topicAttrs[attrName] = attr;\n }\n\n topics[topicName] = i.entity(topicAttrs);\n }\n }\n\n rooms[roomName] = {\n presence: i.entity(presenceAttrs),\n topics,\n };\n }\n }\n\n const resultingSchema = i.schema({\n entities,\n links,\n rooms,\n });\n\n return resultingSchema;\n};\n"]}
|
|
@@ -5,11 +5,12 @@ export type QuerySubResult = {
|
|
|
5
5
|
attrsStore: AttrsStore;
|
|
6
6
|
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
7
7
|
aggregate?: any;
|
|
8
|
-
processedTxId
|
|
8
|
+
processedTxId?: number;
|
|
9
|
+
isExternal?: boolean;
|
|
9
10
|
};
|
|
10
11
|
export type QuerySub = {
|
|
11
12
|
q: Object;
|
|
12
|
-
eventId
|
|
13
|
+
eventId?: string;
|
|
13
14
|
lastAccessed?: number | null | undefined;
|
|
14
15
|
result?: QuerySubResult;
|
|
15
16
|
};
|
|
@@ -18,11 +19,11 @@ export type QuerySubResultInStorage = {
|
|
|
18
19
|
attrsStore: AttrsStoreJson;
|
|
19
20
|
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
20
21
|
aggregate?: any;
|
|
21
|
-
processedTxId
|
|
22
|
+
processedTxId?: number;
|
|
22
23
|
};
|
|
23
24
|
export type QuerySubInStorage = {
|
|
24
25
|
q: Object;
|
|
25
|
-
eventId
|
|
26
|
+
eventId?: string;
|
|
26
27
|
lastAccessed?: number | null | undefined;
|
|
27
28
|
result?: QuerySubResultInStorage;
|
|
28
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactorTypes.d.ts","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"reactorTypes.d.ts","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,cAAc,CAAC;IAC3B,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactorTypes.js","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"","sourcesContent":["import { PageInfoResponse } from './queryTypes.ts';\nimport { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';\n\nexport type QuerySubResult = {\n store: Store;\n attrsStore: AttrsStore;\n pageInfo?: PageInfoResponse<any> | null | undefined;\n aggregate?: any;\n processedTxId
|
|
1
|
+
{"version":3,"file":"reactorTypes.js","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"","sourcesContent":["import { PageInfoResponse } from './queryTypes.ts';\nimport { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';\n\nexport type QuerySubResult = {\n store: Store;\n attrsStore: AttrsStore;\n pageInfo?: PageInfoResponse<any> | null | undefined;\n aggregate?: any;\n processedTxId?: number;\n isExternal?: boolean;\n};\n\nexport type QuerySub = {\n q: Object;\n eventId?: string;\n lastAccessed?: number | null | undefined;\n result?: QuerySubResult;\n};\n\nexport type QuerySubResultInStorage = {\n store: StoreJson;\n attrsStore: AttrsStoreJson;\n pageInfo?: PageInfoResponse<any> | null | undefined;\n aggregate?: any;\n processedTxId?: number;\n};\n\nexport type QuerySubInStorage = {\n q: Object;\n eventId?: string;\n lastAccessed?: number | null | undefined;\n result?: QuerySubResultInStorage;\n};\n"]}
|
package/dist/esm/Reactor.d.ts
CHANGED
|
@@ -102,6 +102,17 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
102
102
|
_setStatus(status: any, err: any): void;
|
|
103
103
|
_onMergeKv: (key: any, storageV: any, inMemoryV: any) => any;
|
|
104
104
|
_flushEnqueuedRoomData(roomId: any): void;
|
|
105
|
+
/**
|
|
106
|
+
* Does the same thing as add-query-ok
|
|
107
|
+
* but called as a result of receiving query info from ssr
|
|
108
|
+
* @param {any} q
|
|
109
|
+
* @param {{ triples: any; pageInfo: any; }} result
|
|
110
|
+
* @param {boolean} enableCardinalityInference
|
|
111
|
+
*/
|
|
112
|
+
_addQueryData(q: any, result: {
|
|
113
|
+
triples: any;
|
|
114
|
+
pageInfo: any;
|
|
115
|
+
}, enableCardinalityInference: boolean): void;
|
|
105
116
|
_handleReceive(connId: any, msg: any): void;
|
|
106
117
|
_sessionId: any;
|
|
107
118
|
_pendingMutations(): any;
|
|
@@ -154,7 +165,7 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
154
165
|
*/
|
|
155
166
|
optimisticAttrs(): s.AttrsStore;
|
|
156
167
|
/** Runs instaql on a query and a store */
|
|
157
|
-
dataForQuery(hash: any): any;
|
|
168
|
+
dataForQuery(hash: any, applyOptimistic?: boolean): any;
|
|
158
169
|
_applyOptimisticUpdates(store: any, attrsStore: any, mutations: any, processedTxId: any): {
|
|
159
170
|
store: any;
|
|
160
171
|
attrsStore: any;
|
|
@@ -260,6 +271,7 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
260
271
|
}>;
|
|
261
272
|
_hasCurrentUser(): Promise<boolean>;
|
|
262
273
|
changeCurrentUser(newUser: any): Promise<void>;
|
|
274
|
+
syncUserToEndpoint(user: any): Promise<void>;
|
|
263
275
|
updateUser(newUser: any): void;
|
|
264
276
|
sendMagicCode({ email }: {
|
|
265
277
|
email: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"AA0MA;;GAEG;AACH,6BAFwD,UAAU,SAArD,OAAQ,eAAe,EAAE,eAAgB;IAmEpD,8KAwHC;IAxLD,uCAAuC;IACvC,OADW,CAAC,CAAC,UAAU,GAAG,SAAS,CAC7B;IACN,mBAAiB;IACjB,qBAAoB;IACpB,eAA2B;IAE3B,mEAAmE;IACnE,WADW,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CACrD;IAEV,8BAA8B;IAC9B,mCAAG;IAEH,wBAAwB;IACxB,YADW,SAAS,CACT;IAEX,wEAAwE;IACxE,UADW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;;OAOG;IACH,oDAJG;QAAuB,UAAU,EAAzB,MAAM;QACS,WAAW,EAA1B,MAAM;KACd,GAAU,MAAM,CAKlB;IAED;;;;OAIG;IACH,6CAHG;QAAuB,IAAI,EAAnB,MAAM;QACU,YAAY;KACtC,mCAaA;IAED,oBAGC;IAED;;;;;OAKG;IACH,kDAJG;QAAuB,UAAU,EAAzB,MAAM;QACS,OAAO,EAAtB,MAAM;QAC6B,KAAK,GAAxC,MAAM,GAAG,IAAI,GAAG,SAAS;KACnC,mCAeA;IAKD;;;;OAIG;IACH,iBAJW,MAAM,oBACN,GAAG,GAAG,IAAI,GAAG,SAAS,cA4BhC;IAED,gCAiBC;IAMD;;;;;;;;;;;aAUC;IAGD,oEAsBC;IAED,8CAMC;IAED,2CAGC;IAED,iCAEC;IAED,0DAKC;IAGD,8EAuBC;IAED,uCAIC;IAED,oDAaC;IAED,mDAyBC;IAED,gDAWC;IAKD;;;;;aAeC;IAED,uEAQC;IAED,6DAoBC;IAED,4DAWC;IAKD,oFAWC;IAED,8DAWC;IAKD,+CAaC;IAED,wCAWC;CACF;qBA38Ea,OAAO,gBAAgB,EAAE,MAAM;;4BAE/B,OAAO,iBAAiB,EAAE,aAAa;qCACvC,OAAO,iBAAiB,EAAE,sBAAsB;uBAChD,OAAO,mBAAmB,EAAE,QAAQ;gCACpC,OAAO,mBAAmB,EAAE,iBAAiB;mBAnCxC,YAAY;gCASC,4BAA4B;0BAmBlC,gBAAgB;yBApBjB,qBAAqB;yBAJrB,cAAc;4BACX,iBAAiB;6BAHhB,uBAAuB;kCAClB,4BAA4B"}
|
package/dist/esm/Reactor.js
CHANGED
|
@@ -61,6 +61,7 @@ const STATUS = {
|
|
|
61
61
|
const QUERY_ONCE_TIMEOUT = 30000;
|
|
62
62
|
const PENDING_TX_CLEANUP_TIMEOUT = 30000;
|
|
63
63
|
const PENDING_MUTATION_CLEANUP_THRESHOLD = 200;
|
|
64
|
+
const ONE_MIN_MS = 1000 * 60;
|
|
64
65
|
const defaultConfig = {
|
|
65
66
|
apiURI: 'https://api.instantdb.com',
|
|
66
67
|
websocketURI: 'wss://api.instantdb.com/runtime/session',
|
|
@@ -449,7 +450,13 @@ export default class Reactor {
|
|
|
449
450
|
}, () => this.ensureAttrs());
|
|
450
451
|
this._oauthCallbackResponse = this._oauthLoginInit();
|
|
451
452
|
// kick off a request to cache it
|
|
452
|
-
this.getCurrentUser()
|
|
453
|
+
this.getCurrentUser().then((userInfo) => {
|
|
454
|
+
this.syncUserToEndpoint(userInfo.user);
|
|
455
|
+
});
|
|
456
|
+
setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
457
|
+
const currentUser = yield this.getCurrentUser();
|
|
458
|
+
this.syncUserToEndpoint(currentUser.user);
|
|
459
|
+
}), ONE_MIN_MS);
|
|
453
460
|
NetworkListener.getIsOnline().then((isOnline) => {
|
|
454
461
|
this._isOnline = isOnline;
|
|
455
462
|
this._startSocket();
|
|
@@ -601,6 +608,37 @@ export default class Reactor {
|
|
|
601
608
|
}
|
|
602
609
|
}
|
|
603
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* Does the same thing as add-query-ok
|
|
613
|
+
* but called as a result of receiving query info from ssr
|
|
614
|
+
* @param {any} q
|
|
615
|
+
* @param {{ triples: any; pageInfo: any; }} result
|
|
616
|
+
* @param {boolean} enableCardinalityInference
|
|
617
|
+
*/
|
|
618
|
+
_addQueryData(q, result, enableCardinalityInference) {
|
|
619
|
+
if (!this.attrs) {
|
|
620
|
+
throw new Error('Attrs in reactor have not been set');
|
|
621
|
+
}
|
|
622
|
+
const queryHash = weakHash(q);
|
|
623
|
+
const attrsStore = this.ensureAttrs();
|
|
624
|
+
const store = s.createStore(this.attrs, result.triples, enableCardinalityInference, this.config.useDateObjects);
|
|
625
|
+
this.querySubs.updateInPlace((prev) => {
|
|
626
|
+
prev[queryHash] = {
|
|
627
|
+
result: {
|
|
628
|
+
store,
|
|
629
|
+
attrsStore,
|
|
630
|
+
pageInfo: result.pageInfo,
|
|
631
|
+
processedTxId: undefined,
|
|
632
|
+
isExternal: true,
|
|
633
|
+
},
|
|
634
|
+
q,
|
|
635
|
+
};
|
|
636
|
+
});
|
|
637
|
+
this._cleanupPendingMutationsQueries();
|
|
638
|
+
this.notifyOne(queryHash);
|
|
639
|
+
this.notifyOneQueryOnce(queryHash);
|
|
640
|
+
this._cleanupPendingMutationsTimeout();
|
|
641
|
+
}
|
|
604
642
|
_handleReceive(connId, msg) {
|
|
605
643
|
var _a, _b, _c, _d, _e, _f;
|
|
606
644
|
// opt-out, enabled by default if schema
|
|
@@ -1142,7 +1180,7 @@ export default class Reactor {
|
|
|
1142
1180
|
return new s.AttrsStoreClass(attrs, this._linkIndex);
|
|
1143
1181
|
}
|
|
1144
1182
|
/** Runs instaql on a query and a store */
|
|
1145
|
-
dataForQuery(hash) {
|
|
1183
|
+
dataForQuery(hash, applyOptimistic = true) {
|
|
1146
1184
|
const errorMessage = this._errorMessage;
|
|
1147
1185
|
if (errorMessage) {
|
|
1148
1186
|
return { error: errorMessage };
|
|
@@ -1164,10 +1202,16 @@ export default class Reactor {
|
|
|
1164
1202
|
pendingMutationsVersion === cached.pendingMutationsVersion) {
|
|
1165
1203
|
return cached;
|
|
1166
1204
|
}
|
|
1167
|
-
|
|
1205
|
+
let store = result.store;
|
|
1206
|
+
let attrsStore = result.attrsStore;
|
|
1207
|
+
const { pageInfo, aggregate, processedTxId } = result;
|
|
1168
1208
|
const mutations = this._rewriteMutationsSorted(attrsStore, pendingMutations);
|
|
1169
|
-
|
|
1170
|
-
|
|
1209
|
+
if (applyOptimistic) {
|
|
1210
|
+
const optimisticResult = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
1211
|
+
store = optimisticResult.store;
|
|
1212
|
+
attrsStore = optimisticResult.attrsStore;
|
|
1213
|
+
}
|
|
1214
|
+
const resp = instaql({ store: store, attrsStore: attrsStore, pageInfo, aggregate }, q);
|
|
1171
1215
|
return { data: resp, querySubVersion, pendingMutationsVersion };
|
|
1172
1216
|
}
|
|
1173
1217
|
_applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
|
|
@@ -1633,7 +1677,30 @@ export default class Reactor {
|
|
|
1633
1677
|
}
|
|
1634
1678
|
});
|
|
1635
1679
|
}
|
|
1680
|
+
syncUserToEndpoint(user) {
|
|
1681
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1682
|
+
if (!this.config.firstPartyPath)
|
|
1683
|
+
return;
|
|
1684
|
+
try {
|
|
1685
|
+
fetch(this.config.firstPartyPath + '/', {
|
|
1686
|
+
method: 'POST',
|
|
1687
|
+
body: JSON.stringify({
|
|
1688
|
+
type: 'sync-user',
|
|
1689
|
+
appId: this.config.appId,
|
|
1690
|
+
user: user,
|
|
1691
|
+
}),
|
|
1692
|
+
headers: {
|
|
1693
|
+
'Content-Type': 'application/json',
|
|
1694
|
+
},
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
catch (error) {
|
|
1698
|
+
this._log.error('Error syncing user with external endpoint', error);
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1636
1702
|
updateUser(newUser) {
|
|
1703
|
+
this.syncUserToEndpoint(newUser);
|
|
1637
1704
|
const newV = { error: undefined, user: newUser };
|
|
1638
1705
|
this._currentUserCached = Object.assign({ isLoading: false }, newV);
|
|
1639
1706
|
this._dataForQueryCache = {};
|