@astrogate/sdk 0.0.0-stage → 0.1.0
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/README.md +6 -2
- package/THIRD_PARTY_NOTICES.md +17 -0
- package/dist/browser.d.ts +85 -0
- package/dist/browser.js +16 -0
- package/dist/database-binding.d.ts +7 -0
- package/dist/database-binding.js +11 -0
- package/dist/hosted-session.d.ts +1 -0
- package/dist/hosted-session.js +11 -0
- package/dist/http.d.ts +24 -0
- package/dist/http.js +92 -0
- package/dist/inventory.d.ts +7 -0
- package/dist/inventory.js +18 -0
- package/dist/management-read.d.ts +17 -0
- package/dist/management-read.js +104 -0
- package/dist/management.d.ts +347 -0
- package/dist/management.js +137 -0
- package/dist/operator.d.ts +136 -0
- package/dist/operator.js +53 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.js +10 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.js +30 -0
- package/dist/services.d.ts +7 -0
- package/dist/services.js +53 -0
- package/dist/storage.d.ts +68 -0
- package/dist/storage.js +30 -0
- package/dist/tasks.d.ts +42 -0
- package/dist/tasks.js +24 -0
- package/dist/wire.gen.d.ts +7107 -0
- package/dist/wire.gen.js +5 -0
- package/native-provenance.json +15 -0
- package/node_modules/@instantdb/admin/LICENSE +202 -0
- package/node_modules/@instantdb/admin/dist/esm/index.d.ts +607 -0
- package/node_modules/@instantdb/admin/dist/esm/index.js +1036 -0
- package/node_modules/@instantdb/admin/dist/esm/polyfill.d.ts +16 -0
- package/node_modules/@instantdb/admin/dist/esm/polyfill.js +21 -0
- package/node_modules/@instantdb/admin/dist/esm/subscribe.d.ts +38 -0
- package/node_modules/@instantdb/admin/dist/esm/subscribe.js +301 -0
- package/node_modules/@instantdb/admin/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/admin/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/admin/package.json +23 -0
- package/node_modules/@instantdb/core/LICENSE +202 -0
- package/node_modules/@instantdb/core/dist/esm/Connection.d.ts +92 -0
- package/node_modules/@instantdb/core/dist/esm/Connection.js +188 -0
- package/node_modules/@instantdb/core/dist/esm/InMemoryStorage.d.ts +10 -0
- package/node_modules/@instantdb/core/dist/esm/InMemoryStorage.js +25 -0
- package/node_modules/@instantdb/core/dist/esm/IndexedDBStorage.d.ts +17 -0
- package/node_modules/@instantdb/core/dist/esm/IndexedDBStorage.js +309 -0
- package/node_modules/@instantdb/core/dist/esm/InstantError.d.ts +6 -0
- package/node_modules/@instantdb/core/dist/esm/InstantError.js +23 -0
- package/node_modules/@instantdb/core/dist/esm/Reactor.d.ts +430 -0
- package/node_modules/@instantdb/core/dist/esm/Reactor.js +2369 -0
- package/node_modules/@instantdb/core/dist/esm/StorageAPI.d.ts +39 -0
- package/node_modules/@instantdb/core/dist/esm/StorageAPI.js +65 -0
- package/node_modules/@instantdb/core/dist/esm/Stream.d.ts +120 -0
- package/node_modules/@instantdb/core/dist/esm/Stream.js +811 -0
- package/node_modules/@instantdb/core/dist/esm/SyncTable.d.ts +144 -0
- package/node_modules/@instantdb/core/dist/esm/SyncTable.js +523 -0
- package/node_modules/@instantdb/core/dist/esm/WindowNetworkListener.d.ts +4 -0
- package/node_modules/@instantdb/core/dist/esm/WindowNetworkListener.js +19 -0
- package/node_modules/@instantdb/core/dist/esm/attrTypes.d.ts +25 -0
- package/node_modules/@instantdb/core/dist/esm/attrTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/authAPI.d.ts +64 -0
- package/node_modules/@instantdb/core/dist/esm/authAPI.js +103 -0
- package/node_modules/@instantdb/core/dist/esm/clientTypes.d.ts +40 -0
- package/node_modules/@instantdb/core/dist/esm/clientTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/coreTypes.d.ts +33 -0
- package/node_modules/@instantdb/core/dist/esm/coreTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/createRouteHandler.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/createRouteHandler.js +51 -0
- package/node_modules/@instantdb/core/dist/esm/datalog.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/datalog.js +99 -0
- package/node_modules/@instantdb/core/dist/esm/devtool.d.ts +3 -0
- package/node_modules/@instantdb/core/dist/esm/devtool.js +144 -0
- package/node_modules/@instantdb/core/dist/esm/framework.d.ts +80 -0
- package/node_modules/@instantdb/core/dist/esm/framework.js +243 -0
- package/node_modules/@instantdb/core/dist/esm/helperTypes.d.ts +75 -0
- package/node_modules/@instantdb/core/dist/esm/helperTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/index.d.ts +597 -0
- package/node_modules/@instantdb/core/dist/esm/index.js +649 -0
- package/node_modules/@instantdb/core/dist/esm/infiniteQuery.d.ts +25 -0
- package/node_modules/@instantdb/core/dist/esm/infiniteQuery.js +430 -0
- package/node_modules/@instantdb/core/dist/esm/instaml.d.ts +17 -0
- package/node_modules/@instantdb/core/dist/esm/instaml.js +576 -0
- package/node_modules/@instantdb/core/dist/esm/instaql.d.ts +12 -0
- package/node_modules/@instantdb/core/dist/esm/instaql.js +632 -0
- package/node_modules/@instantdb/core/dist/esm/instatx.d.ts +127 -0
- package/node_modules/@instantdb/core/dist/esm/instatx.js +93 -0
- package/node_modules/@instantdb/core/dist/esm/model/instaqlResult.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/model/instaqlResult.js +24 -0
- package/node_modules/@instantdb/core/dist/esm/parseSchemaFromJSON.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/parseSchemaFromJSON.js +142 -0
- package/node_modules/@instantdb/core/dist/esm/presence.d.ts +50 -0
- package/node_modules/@instantdb/core/dist/esm/presence.js +50 -0
- package/node_modules/@instantdb/core/dist/esm/presenceTypes.d.ts +9 -0
- package/node_modules/@instantdb/core/dist/esm/presenceTypes.js +3 -0
- package/node_modules/@instantdb/core/dist/esm/queryTypes.d.ts +271 -0
- package/node_modules/@instantdb/core/dist/esm/queryTypes.js +3 -0
- package/node_modules/@instantdb/core/dist/esm/queryValidation.d.ts +5 -0
- package/node_modules/@instantdb/core/dist/esm/queryValidation.js +287 -0
- package/node_modules/@instantdb/core/dist/esm/reactorTypes.d.ts +29 -0
- package/node_modules/@instantdb/core/dist/esm/reactorTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/routeHandlerProtocol.d.ts +19 -0
- package/node_modules/@instantdb/core/dist/esm/routeHandlerProtocol.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/rulesTypes.d.ts +85 -0
- package/node_modules/@instantdb/core/dist/esm/rulesTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/sanityCheckQueries.d.ts +18 -0
- package/node_modules/@instantdb/core/dist/esm/sanityCheckQueries.js +152 -0
- package/node_modules/@instantdb/core/dist/esm/schema.d.ts +72 -0
- package/node_modules/@instantdb/core/dist/esm/schema.js +128 -0
- package/node_modules/@instantdb/core/dist/esm/schemaTypes.d.ts +244 -0
- package/node_modules/@instantdb/core/dist/esm/schemaTypes.js +106 -0
- package/node_modules/@instantdb/core/dist/esm/store.d.ts +89 -0
- package/node_modules/@instantdb/core/dist/esm/store.js +722 -0
- package/node_modules/@instantdb/core/dist/esm/transactionValidation.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/transactionValidation.js +130 -0
- package/node_modules/@instantdb/core/dist/esm/utils/Deferred.d.ts +8 -0
- package/node_modules/@instantdb/core/dist/esm/utils/Deferred.js +17 -0
- package/node_modules/@instantdb/core/dist/esm/utils/PersistedObject.d.ts +80 -0
- package/node_modules/@instantdb/core/dist/esm/utils/PersistedObject.js +448 -0
- package/node_modules/@instantdb/core/dist/esm/utils/dates.d.ts +1 -0
- package/node_modules/@instantdb/core/dist/esm/utils/dates.js +211 -0
- package/node_modules/@instantdb/core/dist/esm/utils/error.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/utils/error.js +8 -0
- package/node_modules/@instantdb/core/dist/esm/utils/fetch.d.ts +125 -0
- package/node_modules/@instantdb/core/dist/esm/utils/fetch.js +31 -0
- package/node_modules/@instantdb/core/dist/esm/utils/flags.d.ts +4 -0
- package/node_modules/@instantdb/core/dist/esm/utils/flags.js +10 -0
- package/node_modules/@instantdb/core/dist/esm/utils/id.d.ts +3 -0
- package/node_modules/@instantdb/core/dist/esm/utils/id.js +25 -0
- package/node_modules/@instantdb/core/dist/esm/utils/linkIndex.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/utils/linkIndex.js +17 -0
- package/node_modules/@instantdb/core/dist/esm/utils/log.d.ts +6 -0
- package/node_modules/@instantdb/core/dist/esm/utils/log.js +13 -0
- package/node_modules/@instantdb/core/dist/esm/utils/object.d.ts +16 -0
- package/node_modules/@instantdb/core/dist/esm/utils/object.js +143 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pgtime.d.ts +197 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pgtime.js +197 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pick.d.ts +1 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pick.js +9 -0
- package/node_modules/@instantdb/core/dist/esm/utils/strings.d.ts +1 -0
- package/node_modules/@instantdb/core/dist/esm/utils/strings.js +15 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHash.d.ts +15 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHash.js +71 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHashLegacy.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHashLegacy.js +72 -0
- package/node_modules/@instantdb/core/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/core/dist/esm/warningToggle.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/warningToggle.js +4 -0
- package/node_modules/@instantdb/core/package.json +20 -0
- package/node_modules/@instantdb/eventsource/LICENSE +22 -0
- package/node_modules/@instantdb/eventsource/README.md +226 -0
- package/node_modules/@instantdb/eventsource/dist/index.cjs +279 -0
- package/node_modules/@instantdb/eventsource/dist/index.cjs.map +1 -0
- package/node_modules/@instantdb/eventsource/dist/index.d.cts +346 -0
- package/node_modules/@instantdb/eventsource/dist/index.d.ts +346 -0
- package/node_modules/@instantdb/eventsource/dist/index.js +279 -0
- package/node_modules/@instantdb/eventsource/dist/index.js.map +1 -0
- package/node_modules/@instantdb/eventsource/package.json +128 -0
- package/node_modules/@instantdb/eventsource/src/EventSource.ts +614 -0
- package/node_modules/@instantdb/eventsource/src/errors.ts +141 -0
- package/node_modules/@instantdb/eventsource/src/index.ts +3 -0
- package/node_modules/@instantdb/eventsource/src/types.ts +164 -0
- package/node_modules/@instantdb/react/LICENSE +202 -0
- package/node_modules/@instantdb/react/dist/esm/Cursors.d.ts +18 -0
- package/node_modules/@instantdb/react/dist/esm/Cursors.js +103 -0
- package/node_modules/@instantdb/react/dist/esm/InstantReactWebDatabase.d.ts +5 -0
- package/node_modules/@instantdb/react/dist/esm/InstantReactWebDatabase.js +5 -0
- package/node_modules/@instantdb/react/dist/esm/index.d.ts +6 -0
- package/node_modules/@instantdb/react/dist/esm/index.js +22 -0
- package/node_modules/@instantdb/react/dist/esm/init.d.ts +40 -0
- package/node_modules/@instantdb/react/dist/esm/init.js +49 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/HydrationStreamProvider.d.ts +65 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/HydrationStreamProvider.js +96 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantNextDatabase.d.ts +11 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantNextDatabase.js +31 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantSuspenseProvider.d.ts +24 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantSuspenseProvider.js +162 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/getUserFromInstantCookie.d.ts +9 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/getUserFromInstantCookie.js +16 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/htmlescape.d.ts +2 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/htmlescape.js +20 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/index.d.ts +29 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/index.js +34 -0
- package/node_modules/@instantdb/react/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/react/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/react/package.json +24 -0
- package/node_modules/@instantdb/react-common/LICENSE +202 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactAbstractDatabase.d.ts +282 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactAbstractDatabase.js +386 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactRoom.d.ts +182 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactRoom.js +280 -0
- package/node_modules/@instantdb/react-common/dist/esm/index.d.ts +4 -0
- package/node_modules/@instantdb/react-common/dist/esm/index.js +3 -0
- package/node_modules/@instantdb/react-common/dist/esm/useInfiniteQuerySubscription.d.ts +27 -0
- package/node_modules/@instantdb/react-common/dist/esm/useInfiniteQuerySubscription.js +53 -0
- package/node_modules/@instantdb/react-common/dist/esm/useQuery.d.ts +6 -0
- package/node_modules/@instantdb/react-common/dist/esm/useQuery.js +75 -0
- package/node_modules/@instantdb/react-common/dist/esm/useTimeout.d.ts +4 -0
- package/node_modules/@instantdb/react-common/dist/esm/useTimeout.js +17 -0
- package/node_modules/@instantdb/react-common/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/react-common/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/react-common/package.json +22 -0
- package/node_modules/@instantdb/version/LICENSE +202 -0
- package/node_modules/@instantdb/version/dist/esm/index.d.ts +2 -0
- package/node_modules/@instantdb/version/dist/esm/index.js +2 -0
- package/node_modules/@instantdb/version/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/version/dist/esm/version.js +5 -0
- package/node_modules/@instantdb/version/package.json +16 -0
- package/node_modules/@instantdb/webhooks/LICENSE +202 -0
- package/node_modules/@instantdb/webhooks/dist/esm/index.d.ts +587 -0
- package/node_modules/@instantdb/webhooks/dist/esm/index.js +748 -0
- package/node_modules/@instantdb/webhooks/package.json +18 -0
- package/node_modules/cookie/LICENSE +24 -0
- package/node_modules/cookie/README.md +295 -0
- package/node_modules/cookie/dist/index.d.ts +143 -0
- package/node_modules/cookie/dist/index.js +355 -0
- package/node_modules/cookie/dist/index.js.map +1 -0
- package/node_modules/cookie/package.json +57 -0
- package/node_modules/eventsource/LICENSE +22 -0
- package/node_modules/eventsource/README.md +252 -0
- package/node_modules/eventsource/dist/EventSource.d.ts +128 -0
- package/node_modules/eventsource/dist/EventSource.d.ts.map +1 -0
- package/node_modules/eventsource/dist/EventSource.js +556 -0
- package/node_modules/eventsource/dist/EventSource.js.map +1 -0
- package/node_modules/eventsource/dist/errors.d.ts +53 -0
- package/node_modules/eventsource/dist/errors.d.ts.map +1 -0
- package/node_modules/eventsource/dist/errors.js +120 -0
- package/node_modules/eventsource/dist/errors.js.map +1 -0
- package/node_modules/eventsource/dist/index.d.ts +4 -0
- package/node_modules/eventsource/dist/index.d.ts.map +1 -0
- package/node_modules/eventsource/dist/index.js +3 -0
- package/node_modules/eventsource/dist/index.js.map +1 -0
- package/node_modules/eventsource/dist/types.d.ts +156 -0
- package/node_modules/eventsource/dist/types.d.ts.map +1 -0
- package/node_modules/eventsource/dist/types.js +2 -0
- package/node_modules/eventsource/dist/types.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/LICENSE +21 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/README.md +177 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.d.ts +35 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.js +16 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.d.ts +4 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.js +3 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.d.ts +12 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.js +509 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.d.ts +76 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.js +59 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.d.ts +130 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.js +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/package.json +96 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/errors.ts +44 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/index.ts +3 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/parse.ts +576 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/stream.ts +118 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/types.ts +138 -0
- package/node_modules/eventsource/package.json +103 -0
- package/node_modules/eventsource/src/EventSource.ts +844 -0
- package/node_modules/eventsource/src/errors.ts +141 -0
- package/node_modules/eventsource/src/index.ts +3 -0
- package/node_modules/eventsource/src/types.ts +166 -0
- package/node_modules/eventsource-parser/LICENSE +21 -0
- package/node_modules/eventsource-parser/README.md +157 -0
- package/node_modules/eventsource-parser/dist/index.cjs +177 -0
- package/node_modules/eventsource-parser/dist/index.cjs.map +1 -0
- package/node_modules/eventsource-parser/dist/index.d.cts +169 -0
- package/node_modules/eventsource-parser/dist/index.d.ts +169 -0
- package/node_modules/eventsource-parser/dist/index.js +177 -0
- package/node_modules/eventsource-parser/dist/index.js.map +1 -0
- package/node_modules/eventsource-parser/dist/stream.cjs +29 -0
- package/node_modules/eventsource-parser/dist/stream.cjs.map +1 -0
- package/node_modules/eventsource-parser/dist/stream.d.cts +134 -0
- package/node_modules/eventsource-parser/dist/stream.d.ts +134 -0
- package/node_modules/eventsource-parser/dist/stream.js +30 -0
- package/node_modules/eventsource-parser/dist/stream.js.map +1 -0
- package/node_modules/eventsource-parser/package.json +92 -0
- package/node_modules/eventsource-parser/src/errors.ts +44 -0
- package/node_modules/eventsource-parser/src/index.ts +8 -0
- package/node_modules/eventsource-parser/src/parse.ts +439 -0
- package/node_modules/eventsource-parser/src/stream.ts +107 -0
- package/node_modules/eventsource-parser/src/types.ts +122 -0
- package/node_modules/eventsource-parser/stream.js +2 -0
- package/node_modules/mutative/LICENSE +21 -0
- package/node_modules/mutative/README.md +870 -0
- package/node_modules/mutative/dist/apply.d.ts +31 -0
- package/node_modules/mutative/dist/array.d.ts +45 -0
- package/node_modules/mutative/dist/constant.d.ts +8 -0
- package/node_modules/mutative/dist/create.d.ts +46 -0
- package/node_modules/mutative/dist/current.d.ts +23 -0
- package/node_modules/mutative/dist/draft.d.ts +3 -0
- package/node_modules/mutative/dist/draftify.d.ts +2 -0
- package/node_modules/mutative/dist/error.d.ts +54 -0
- package/node_modules/mutative/dist/index.d.mts +1 -0
- package/node_modules/mutative/dist/index.d.ts +12 -0
- package/node_modules/mutative/dist/index.js +8 -0
- package/node_modules/mutative/dist/index.mjs +3 -0
- package/node_modules/mutative/dist/interface.d.ts +200 -0
- package/node_modules/mutative/dist/internal.d.ts +4 -0
- package/node_modules/mutative/dist/makeCreator.d.ts +54 -0
- package/node_modules/mutative/dist/map.d.ts +15 -0
- package/node_modules/mutative/dist/mutative.cjs.development.js +2126 -0
- package/node_modules/mutative/dist/mutative.cjs.development.js.map +1 -0
- package/node_modules/mutative/dist/mutative.cjs.production.min.js +2 -0
- package/node_modules/mutative/dist/mutative.cjs.production.min.js.map +1 -0
- package/node_modules/mutative/dist/mutative.esm.js +2123 -0
- package/node_modules/mutative/dist/mutative.esm.js.map +1 -0
- package/node_modules/mutative/dist/mutative.esm.mjs +2123 -0
- package/node_modules/mutative/dist/mutative.esm.mjs.map +1 -0
- package/node_modules/mutative/dist/mutative.esm.production.min.mjs +2 -0
- package/node_modules/mutative/dist/mutative.esm.production.min.mjs.map +1 -0
- package/node_modules/mutative/dist/mutative.umd.development.js +2132 -0
- package/node_modules/mutative/dist/mutative.umd.development.js.map +1 -0
- package/node_modules/mutative/dist/mutative.umd.production.min.js +2 -0
- package/node_modules/mutative/dist/mutative.umd.production.min.js.map +1 -0
- package/node_modules/mutative/dist/original.d.ts +19 -0
- package/node_modules/mutative/dist/patch.d.ts +2 -0
- package/node_modules/mutative/dist/rawReturn.d.ts +19 -0
- package/node_modules/mutative/dist/set.d.ts +14 -0
- package/node_modules/mutative/dist/unsafe.d.ts +34 -0
- package/node_modules/mutative/dist/utils/cast.d.ts +13 -0
- package/node_modules/mutative/dist/utils/copy.d.ts +5 -0
- package/node_modules/mutative/dist/utils/deepFreeze.d.ts +1 -0
- package/node_modules/mutative/dist/utils/draft.d.ts +27 -0
- package/node_modules/mutative/dist/utils/finalize.d.ts +13 -0
- package/node_modules/mutative/dist/utils/forEach.d.ts +1 -0
- package/node_modules/mutative/dist/utils/index.d.ts +7 -0
- package/node_modules/mutative/dist/utils/mark.d.ts +2 -0
- package/node_modules/mutative/dist/utils/marker.d.ts +5 -0
- package/node_modules/mutative/dist/utils/proto.d.ts +10 -0
- package/node_modules/mutative/package.json +142 -0
- package/node_modules/mutative/src/apply.ts +239 -0
- package/node_modules/mutative/src/array.ts +679 -0
- package/node_modules/mutative/src/constant.ts +17 -0
- package/node_modules/mutative/src/create.ts +27 -0
- package/node_modules/mutative/src/current.ts +206 -0
- package/node_modules/mutative/src/draft.ts +489 -0
- package/node_modules/mutative/src/draftify.ts +57 -0
- package/node_modules/mutative/src/error.ts +129 -0
- package/node_modules/mutative/src/index.ts +21 -0
- package/node_modules/mutative/src/interface.ts +321 -0
- package/node_modules/mutative/src/internal.ts +5 -0
- package/node_modules/mutative/src/makeCreator.ts +382 -0
- package/node_modules/mutative/src/map.ts +160 -0
- package/node_modules/mutative/src/original.ts +28 -0
- package/node_modules/mutative/src/patch.ts +386 -0
- package/node_modules/mutative/src/rawReturn.ts +41 -0
- package/node_modules/mutative/src/set.ts +201 -0
- package/node_modules/mutative/src/unsafe.ts +66 -0
- package/node_modules/mutative/src/utils/cast.ts +22 -0
- package/node_modules/mutative/src/utils/copy.ts +224 -0
- package/node_modules/mutative/src/utils/deepFreeze.ts +103 -0
- package/node_modules/mutative/src/utils/draft.ts +189 -0
- package/node_modules/mutative/src/utils/finalize.ts +232 -0
- package/node_modules/mutative/src/utils/forEach.ts +24 -0
- package/node_modules/mutative/src/utils/index.ts +7 -0
- package/node_modules/mutative/src/utils/mark.ts +11 -0
- package/node_modules/mutative/src/utils/marker.ts +34 -0
- package/node_modules/mutative/src/utils/proto.ts +38 -0
- package/node_modules/uuid/LICENSE.md +9 -0
- package/node_modules/uuid/README.md +491 -0
- package/node_modules/uuid/dist/index.d.ts +15 -0
- package/node_modules/uuid/dist/index.js +14 -0
- package/node_modules/uuid/dist/max.d.ts +2 -0
- package/node_modules/uuid/dist/max.js +1 -0
- package/node_modules/uuid/dist/md5.d.ts +2 -0
- package/node_modules/uuid/dist/md5.js +135 -0
- package/node_modules/uuid/dist/nil.d.ts +2 -0
- package/node_modules/uuid/dist/nil.js +1 -0
- package/node_modules/uuid/dist/parse.d.ts +3 -0
- package/node_modules/uuid/dist/parse.js +9 -0
- package/node_modules/uuid/dist/regex.d.ts +2 -0
- package/node_modules/uuid/dist/regex.js +1 -0
- package/node_modules/uuid/dist/rng.d.ts +1 -0
- package/node_modules/uuid/dist/rng.js +4 -0
- package/node_modules/uuid/dist/sha1.d.ts +2 -0
- package/node_modules/uuid/dist/sha1.js +70 -0
- package/node_modules/uuid/dist/stringify.d.ts +3 -0
- package/node_modules/uuid/dist/stringify.js +35 -0
- package/node_modules/uuid/dist/types.d.ts +22 -0
- package/node_modules/uuid/dist/types.js +1 -0
- package/node_modules/uuid/dist/uuid-bin.d.ts +1 -0
- package/node_modules/uuid/dist/uuid-bin.js +70 -0
- package/node_modules/uuid/dist/v1.d.ts +11 -0
- package/node_modules/uuid/dist/v1.js +87 -0
- package/node_modules/uuid/dist/v1ToV6.d.ts +3 -0
- package/node_modules/uuid/dist/v1ToV6.js +10 -0
- package/node_modules/uuid/dist/v3.d.ts +9 -0
- package/node_modules/uuid/dist/v3.js +9 -0
- package/node_modules/uuid/dist/v35.d.ts +7 -0
- package/node_modules/uuid/dist/v35.js +39 -0
- package/node_modules/uuid/dist/v4.d.ts +4 -0
- package/node_modules/uuid/dist/v4.js +29 -0
- package/node_modules/uuid/dist/v5.d.ts +9 -0
- package/node_modules/uuid/dist/v5.js +9 -0
- package/node_modules/uuid/dist/v6.d.ts +4 -0
- package/node_modules/uuid/dist/v6.js +20 -0
- package/node_modules/uuid/dist/v6ToV1.d.ts +2 -0
- package/node_modules/uuid/dist/v6ToV1.js +10 -0
- package/node_modules/uuid/dist/v7.d.ts +9 -0
- package/node_modules/uuid/dist/v7.js +68 -0
- package/node_modules/uuid/dist/validate.d.ts +2 -0
- package/node_modules/uuid/dist/validate.js +5 -0
- package/node_modules/uuid/dist/version.d.ts +2 -0
- package/node_modules/uuid/dist/version.js +8 -0
- package/node_modules/uuid/dist-node/bin/uuid +2 -0
- package/node_modules/uuid/dist-node/index.js +14 -0
- package/node_modules/uuid/dist-node/max.js +1 -0
- package/node_modules/uuid/dist-node/md5.js +11 -0
- package/node_modules/uuid/dist-node/nil.js +1 -0
- package/node_modules/uuid/dist-node/parse.js +9 -0
- package/node_modules/uuid/dist-node/regex.js +1 -0
- package/node_modules/uuid/dist-node/rng.js +4 -0
- package/node_modules/uuid/dist-node/sha1.js +11 -0
- package/node_modules/uuid/dist-node/stringify.js +35 -0
- package/node_modules/uuid/dist-node/types.js +1 -0
- package/node_modules/uuid/dist-node/uuid-bin.js +70 -0
- package/node_modules/uuid/dist-node/v1.js +87 -0
- package/node_modules/uuid/dist-node/v1ToV6.js +10 -0
- package/node_modules/uuid/dist-node/v3.js +9 -0
- package/node_modules/uuid/dist-node/v35.js +39 -0
- package/node_modules/uuid/dist-node/v4.js +29 -0
- package/node_modules/uuid/dist-node/v5.js +9 -0
- package/node_modules/uuid/dist-node/v6.js +20 -0
- package/node_modules/uuid/dist-node/v6ToV1.js +10 -0
- package/node_modules/uuid/dist-node/v7.js +68 -0
- package/node_modules/uuid/dist-node/validate.js +5 -0
- package/node_modules/uuid/dist-node/version.js +8 -0
- package/node_modules/uuid/package.json +115 -0
- package/package.json +80 -4
- package/release.json +78 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
2
|
+
import { useTimeout } from './useTimeout.js';
|
|
3
|
+
export const defaultActivityStopTimeout = 1_000;
|
|
4
|
+
// ------
|
|
5
|
+
// Topics
|
|
6
|
+
/**
|
|
7
|
+
* Listen for broadcasted events given a room and topic.
|
|
8
|
+
*
|
|
9
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
10
|
+
* @example
|
|
11
|
+
* function App({ roomId }) {
|
|
12
|
+
* const room = db.room('chats', roomId);
|
|
13
|
+
* db.rooms.useTopicEffect(room, 'emoji', (message, peer) => {
|
|
14
|
+
* console.log(peer.name, 'sent', message);
|
|
15
|
+
* });
|
|
16
|
+
* // ...
|
|
17
|
+
* }
|
|
18
|
+
*/
|
|
19
|
+
export function useTopicEffect(room, topic, onEvent) {
|
|
20
|
+
const onEventRef = useRef(onEvent);
|
|
21
|
+
onEventRef.current = onEvent;
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const unsub = room.core._reactor.subscribeTopic(room.type, room.id, topic, (event, peer) => {
|
|
24
|
+
onEventRef.current(event, peer);
|
|
25
|
+
});
|
|
26
|
+
return unsub;
|
|
27
|
+
}, [room.id, topic]);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Broadcast an event to a room.
|
|
31
|
+
*
|
|
32
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
33
|
+
* @example
|
|
34
|
+
* function App({ roomId }) {
|
|
35
|
+
* const room = db.room('chat', roomId);
|
|
36
|
+
* const publishTopic = db.rooms.usePublishTopic(room, "emoji");
|
|
37
|
+
*
|
|
38
|
+
* return (
|
|
39
|
+
* <button onClick={() => publishTopic({ emoji: "🔥" })}>Send emoji</button>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
export function usePublishTopic(room, topic) {
|
|
45
|
+
useEffect(() => room.core._reactor.joinRoom(room.type, room.id), [room.id]);
|
|
46
|
+
const publishTopic = useCallback((data) => {
|
|
47
|
+
room.core._reactor.publishTopic({
|
|
48
|
+
roomType: room.type,
|
|
49
|
+
roomId: room.id,
|
|
50
|
+
topic,
|
|
51
|
+
data,
|
|
52
|
+
});
|
|
53
|
+
}, [room.id, topic]);
|
|
54
|
+
return publishTopic;
|
|
55
|
+
}
|
|
56
|
+
// ---------
|
|
57
|
+
// Presence
|
|
58
|
+
/**
|
|
59
|
+
* Listen for peer's presence data in a room, and publish the current user's presence.
|
|
60
|
+
*
|
|
61
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
62
|
+
* @example
|
|
63
|
+
* function App({ roomId }) {
|
|
64
|
+
* const {
|
|
65
|
+
* peers,
|
|
66
|
+
* publishPresence
|
|
67
|
+
* } = db.room(roomType, roomId).usePresence({ keys: ["name", "avatar"] });
|
|
68
|
+
*
|
|
69
|
+
* // ...
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
export function usePresence(room, opts = {}) {
|
|
73
|
+
const [state, setState] = useState(() => {
|
|
74
|
+
return (room.core._reactor.getPresence(room.type, room.id, opts) ?? {
|
|
75
|
+
peers: {},
|
|
76
|
+
isLoading: true,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const unsub = room.core._reactor.subscribePresence(room.type, room.id, opts, (data) => {
|
|
81
|
+
setState(data);
|
|
82
|
+
});
|
|
83
|
+
return unsub;
|
|
84
|
+
}, [room.id, opts.user, opts.peers?.join(), opts.keys?.join()]);
|
|
85
|
+
const publishPresence = useCallback((data) => {
|
|
86
|
+
room.core._reactor.publishPresence(room.type, room.id, data);
|
|
87
|
+
}, [room.type, room.id]);
|
|
88
|
+
const ret = useMemo(() => {
|
|
89
|
+
return {
|
|
90
|
+
...state,
|
|
91
|
+
publishPresence,
|
|
92
|
+
};
|
|
93
|
+
}, [state, publishPresence]);
|
|
94
|
+
return ret;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Publishes presence data to a room
|
|
98
|
+
*
|
|
99
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
100
|
+
* @example
|
|
101
|
+
* function App({ roomId, nickname }) {
|
|
102
|
+
* const room = db.room('chat', roomId);
|
|
103
|
+
* db.rooms.useSyncPresence(room, { nickname });
|
|
104
|
+
* }
|
|
105
|
+
*/
|
|
106
|
+
export function useSyncPresence(room, data, deps) {
|
|
107
|
+
useEffect(() => room.core._reactor.joinRoom(room.type, room.id, data), [room.id]);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
return room.core._reactor.publishPresence(room.type, room.id, data);
|
|
110
|
+
}, [room.type, room.id, deps ?? JSON.stringify(data)]);
|
|
111
|
+
}
|
|
112
|
+
// -----------------
|
|
113
|
+
// Typing Indicator
|
|
114
|
+
/**
|
|
115
|
+
* Manage typing indicator state
|
|
116
|
+
*
|
|
117
|
+
* @see https://instantdb.com/docs/presence-and-topics
|
|
118
|
+
* @example
|
|
119
|
+
* function App({ roomId }) {
|
|
120
|
+
* const room = db.room('chat', roomId);
|
|
121
|
+
* const {
|
|
122
|
+
* active,
|
|
123
|
+
* setActive,
|
|
124
|
+
* inputProps,
|
|
125
|
+
* } = db.rooms.useTypingIndicator(room, "chat-input");
|
|
126
|
+
*
|
|
127
|
+
* return <input {...inputProps} />;
|
|
128
|
+
* }
|
|
129
|
+
*/
|
|
130
|
+
export function useTypingIndicator(room, inputName, opts = {}) {
|
|
131
|
+
const timeout = useTimeout();
|
|
132
|
+
const observedPresence = rooms.usePresence(room, {
|
|
133
|
+
keys: [inputName],
|
|
134
|
+
});
|
|
135
|
+
const active = useMemo(() => {
|
|
136
|
+
const presenceSnapshot = room._core._reactor.getPresence(room.type, room.id);
|
|
137
|
+
return opts?.writeOnly
|
|
138
|
+
? []
|
|
139
|
+
: Object.values(presenceSnapshot?.peers ?? {}).filter((p) => p[inputName] === true);
|
|
140
|
+
}, [opts?.writeOnly, observedPresence]);
|
|
141
|
+
const setActive = useCallback((isActive) => {
|
|
142
|
+
room.core._reactor.publishPresence(room.type, room.id, {
|
|
143
|
+
[inputName]: isActive,
|
|
144
|
+
});
|
|
145
|
+
if (!isActive)
|
|
146
|
+
return;
|
|
147
|
+
if (opts?.timeout === null || opts?.timeout === 0)
|
|
148
|
+
return;
|
|
149
|
+
timeout.set(opts?.timeout ?? defaultActivityStopTimeout, () => {
|
|
150
|
+
room.core._reactor.publishPresence(room.type, room.id, {
|
|
151
|
+
[inputName]: null,
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}, [room.type, room.id, inputName, opts?.timeout, timeout]);
|
|
155
|
+
const onKeyDown = useCallback((e) => {
|
|
156
|
+
const isEnter = opts?.stopOnEnter && e.key === 'Enter';
|
|
157
|
+
const isActive = !isEnter;
|
|
158
|
+
setActive(isActive);
|
|
159
|
+
}, [opts.stopOnEnter, setActive]);
|
|
160
|
+
const onBlur = useCallback(() => {
|
|
161
|
+
setActive(false);
|
|
162
|
+
}, [setActive]);
|
|
163
|
+
const inputProps = useMemo(() => {
|
|
164
|
+
return { onKeyDown, onBlur };
|
|
165
|
+
}, [onKeyDown, onBlur]);
|
|
166
|
+
return {
|
|
167
|
+
active,
|
|
168
|
+
setActive,
|
|
169
|
+
inputProps,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// --------------
|
|
173
|
+
// Hooks
|
|
174
|
+
export const rooms = {
|
|
175
|
+
useTopicEffect,
|
|
176
|
+
usePublishTopic,
|
|
177
|
+
usePresence,
|
|
178
|
+
useSyncPresence,
|
|
179
|
+
useTypingIndicator,
|
|
180
|
+
};
|
|
181
|
+
// ------------
|
|
182
|
+
// Class
|
|
183
|
+
export class InstantReactRoom {
|
|
184
|
+
core;
|
|
185
|
+
/** @deprecated use `core` instead */
|
|
186
|
+
_core;
|
|
187
|
+
type;
|
|
188
|
+
id;
|
|
189
|
+
constructor(core, type, id) {
|
|
190
|
+
this.core = core;
|
|
191
|
+
this._core = this.core;
|
|
192
|
+
this.type = type;
|
|
193
|
+
this.id = id;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* @deprecated
|
|
197
|
+
* `db.room(...).useTopicEffect` is deprecated. You can replace it with `db.rooms.useTopicEffect`.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
*
|
|
201
|
+
* // Before
|
|
202
|
+
* const room = db.room('chat', 'room-id');
|
|
203
|
+
* room.useTopicEffect('emoji', (message, peer) => { });
|
|
204
|
+
*
|
|
205
|
+
* // After
|
|
206
|
+
* const room = db.room('chat', 'room-id');
|
|
207
|
+
* db.rooms.useTopicEffect(room, 'emoji', (message, peer) => { });
|
|
208
|
+
*/
|
|
209
|
+
useTopicEffect = (topic, onEvent) => {
|
|
210
|
+
rooms.useTopicEffect(this, topic, onEvent);
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* @deprecated
|
|
214
|
+
* `db.room(...).usePublishTopic` is deprecated. You can replace it with `db.rooms.usePublishTopic`.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
*
|
|
218
|
+
* // Before
|
|
219
|
+
* const room = db.room('chat', 'room-id');
|
|
220
|
+
* const publish = room.usePublishTopic('emoji');
|
|
221
|
+
*
|
|
222
|
+
* // After
|
|
223
|
+
* const room = db.room('chat', 'room-id');
|
|
224
|
+
* const publish = db.rooms.usePublishTopic(room, 'emoji');
|
|
225
|
+
*/
|
|
226
|
+
usePublishTopic = (topic) => {
|
|
227
|
+
return rooms.usePublishTopic(this, topic);
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* @deprecated
|
|
231
|
+
* `db.room(...).usePresence` is deprecated. You can replace it with `db.rooms.usePresence`.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
*
|
|
235
|
+
* // Before
|
|
236
|
+
* const room = db.room('chat', 'room-id');
|
|
237
|
+
* const { peers } = room.usePresence({ keys: ["name", "avatar"] });
|
|
238
|
+
*
|
|
239
|
+
* // After
|
|
240
|
+
* const room = db.room('chat', 'room-id');
|
|
241
|
+
* const { peers } = db.rooms.usePresence(room, { keys: ["name", "avatar"] });
|
|
242
|
+
*/
|
|
243
|
+
usePresence = (opts = {}) => {
|
|
244
|
+
return rooms.usePresence(this, opts);
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* @deprecated
|
|
248
|
+
* `db.room(...).useSyncPresence` is deprecated. You can replace it with `db.rooms.useSyncPresence`.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
*
|
|
252
|
+
* // Before
|
|
253
|
+
* const room = db.room('chat', 'room-id');
|
|
254
|
+
* room.useSyncPresence(room, { nickname });
|
|
255
|
+
*
|
|
256
|
+
* // After
|
|
257
|
+
* const room = db.room('chat', 'room-id');
|
|
258
|
+
* db.rooms.useSyncPresence(room, { nickname });
|
|
259
|
+
*/
|
|
260
|
+
useSyncPresence = (data, deps) => {
|
|
261
|
+
return rooms.useSyncPresence(this, data, deps);
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* @deprecated
|
|
265
|
+
* `db.room(...).useTypingIndicator` is deprecated. You can replace it with `db.rooms.useTypingIndicator`.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
*
|
|
269
|
+
* // Before
|
|
270
|
+
* const room = db.room('chat', 'room-id');
|
|
271
|
+
* const typing = room.useTypingIndiactor(room, 'chat-input');
|
|
272
|
+
*
|
|
273
|
+
* // After
|
|
274
|
+
* const room = db.room('chat', 'room-id');
|
|
275
|
+
* const typing = db.rooms.useTypingIndiactor(room, 'chat-input');
|
|
276
|
+
*/
|
|
277
|
+
useTypingIndicator = (inputName, opts = {}) => {
|
|
278
|
+
return rooms.useTypingIndicator(this, inputName, opts);
|
|
279
|
+
};
|
|
280
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import InstantReactAbstractDatabase from './InstantReactAbstractDatabase.tsx';
|
|
2
|
+
import type { InstantReactRoom } from './InstantReactRoom.ts';
|
|
3
|
+
import { useQueryInternal } from './useQuery.ts';
|
|
4
|
+
export { InstantReactAbstractDatabase, type InstantReactRoom, useQueryInternal, };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type InstantCoreDatabase, type InstantSchemaDef, type InstaQLOptions, InstaQLResponse, ValidQuery } from '@instantdb/core';
|
|
2
|
+
export type InfiniteQueryResult<Schema extends InstantSchemaDef<any, any, any>, Q extends ValidQuery<Q, Schema>, UseDates extends boolean> = {
|
|
3
|
+
error: {
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
data: undefined;
|
|
7
|
+
isLoading: false;
|
|
8
|
+
canLoadNextPage: boolean;
|
|
9
|
+
loadNextPage: () => void;
|
|
10
|
+
} | {
|
|
11
|
+
error: undefined;
|
|
12
|
+
data: undefined;
|
|
13
|
+
isLoading: true;
|
|
14
|
+
canLoadNextPage: boolean;
|
|
15
|
+
loadNextPage: () => void;
|
|
16
|
+
} | {
|
|
17
|
+
error: undefined;
|
|
18
|
+
data: InstaQLResponse<Schema, Q, UseDates>;
|
|
19
|
+
isLoading: false;
|
|
20
|
+
canLoadNextPage: boolean;
|
|
21
|
+
loadNextPage: () => void;
|
|
22
|
+
};
|
|
23
|
+
export declare function useInfiniteQuerySubscription<Schema extends InstantSchemaDef<any, any, any>, Q extends ValidQuery<Q, Schema>, UseDates extends boolean>({ core, query, opts, }: {
|
|
24
|
+
core: InstantCoreDatabase<Schema, UseDates>;
|
|
25
|
+
query: Q | null;
|
|
26
|
+
opts?: InstaQLOptions;
|
|
27
|
+
}): InfiniteQueryResult<Schema, Q, UseDates>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { weakHash, getInfiniteQueryInitialSnapshot, } from '@instantdb/core';
|
|
2
|
+
import { useCallback, useRef, useSyncExternalStore } from 'react';
|
|
3
|
+
const defaultState = {
|
|
4
|
+
error: undefined,
|
|
5
|
+
data: undefined,
|
|
6
|
+
isLoading: true,
|
|
7
|
+
canLoadNextPage: false,
|
|
8
|
+
};
|
|
9
|
+
export function useInfiniteQuerySubscription({ core, query, opts, }) {
|
|
10
|
+
const subRef = useRef(null);
|
|
11
|
+
const queryHash = weakHash(query);
|
|
12
|
+
const optsHash = weakHash(opts);
|
|
13
|
+
const snapshot = getInfiniteQueryInitialSnapshot(core, query, opts);
|
|
14
|
+
const stateCacheRef = useRef({
|
|
15
|
+
...snapshot,
|
|
16
|
+
isLoading: !snapshot.data && !snapshot.error,
|
|
17
|
+
});
|
|
18
|
+
const subscribe = useCallback((cb) => {
|
|
19
|
+
subRef.current = null;
|
|
20
|
+
const nextSnapshot = getInfiniteQueryInitialSnapshot(core, query, opts);
|
|
21
|
+
stateCacheRef.current = {
|
|
22
|
+
...nextSnapshot,
|
|
23
|
+
isLoading: !nextSnapshot.data && !nextSnapshot.error,
|
|
24
|
+
};
|
|
25
|
+
cb();
|
|
26
|
+
if (!query) {
|
|
27
|
+
return () => { };
|
|
28
|
+
}
|
|
29
|
+
const sub = core.subscribeInfiniteQuery(query, (resp) => {
|
|
30
|
+
stateCacheRef.current = {
|
|
31
|
+
...resp,
|
|
32
|
+
isLoading: false,
|
|
33
|
+
};
|
|
34
|
+
cb();
|
|
35
|
+
}, opts);
|
|
36
|
+
subRef.current = sub;
|
|
37
|
+
return () => {
|
|
38
|
+
sub.unsubscribe();
|
|
39
|
+
if (subRef.current === sub) {
|
|
40
|
+
subRef.current = null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}, [queryHash, optsHash]);
|
|
44
|
+
const state = useSyncExternalStore(subscribe, () => stateCacheRef.current, () => defaultState);
|
|
45
|
+
const loadNextPage = () => {
|
|
46
|
+
subRef.current?.loadNextPage();
|
|
47
|
+
};
|
|
48
|
+
// @ts-expect-error union type
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
loadNextPage,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type InstaQLOptions, InstantCoreDatabase, InstaQLLifecycleState, InstantSchemaDef, ValidQuery } from '@instantdb/core';
|
|
2
|
+
export declare function useQueryInternal<Q extends ValidQuery<Q, Schema>, Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean>(_core: InstantCoreDatabase<Schema, UseDates>, _query: null | Q, _opts?: InstaQLOptions, serverSnapshot?: () => InstaQLLifecycleState<Schema, Q, UseDates> | undefined): {
|
|
3
|
+
state: InstaQLLifecycleState<Schema, Q, UseDates>;
|
|
4
|
+
query: any;
|
|
5
|
+
queryHash: string;
|
|
6
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { weakHash, coerceQuery, } from '@instantdb/core';
|
|
3
|
+
import { useCallback, useRef, useSyncExternalStore } from 'react';
|
|
4
|
+
const defaultState = {
|
|
5
|
+
isLoading: true,
|
|
6
|
+
data: undefined,
|
|
7
|
+
pageInfo: undefined,
|
|
8
|
+
error: undefined,
|
|
9
|
+
};
|
|
10
|
+
function stateForResult(result) {
|
|
11
|
+
return {
|
|
12
|
+
isLoading: !Boolean(result),
|
|
13
|
+
data: undefined,
|
|
14
|
+
pageInfo: undefined,
|
|
15
|
+
error: undefined,
|
|
16
|
+
...(result ? result : {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function useQueryInternal(_core, _query, _opts, serverSnapshot) {
|
|
20
|
+
if (_query && _opts && 'ruleParams' in _opts) {
|
|
21
|
+
_query = { $$ruleParams: _opts['ruleParams'], ..._query };
|
|
22
|
+
}
|
|
23
|
+
const query = _query ? coerceQuery(_query) : null;
|
|
24
|
+
const queryHash = weakHash(query);
|
|
25
|
+
// We use a ref to store the result of the query.
|
|
26
|
+
// This is becuase `useSyncExternalStore` uses `Object.is`
|
|
27
|
+
// to compare the previous and next state.
|
|
28
|
+
// If we don't use a ref, the state will always be considered different, so
|
|
29
|
+
// the component will always re-render.
|
|
30
|
+
const resultCacheRef = useRef(stateForResult(_core._reactor.getPreviousResult(query)));
|
|
31
|
+
// Cache the server snapshot to satisfy useSyncExternalStore's requirement
|
|
32
|
+
// that getServerSnapshot returns the same reference across calls.
|
|
33
|
+
const serverSnapshotCacheRef = useRef(defaultState);
|
|
34
|
+
// Similar to `resultCacheRef`, `useSyncExternalStore` will unsubscribe
|
|
35
|
+
// if `subscribe` changes, so we use `useCallback` to memoize the function.
|
|
36
|
+
const subscribe = useCallback((cb) => {
|
|
37
|
+
// Update the ref when the query changes to avoid showing stale data
|
|
38
|
+
resultCacheRef.current = stateForResult(_core._reactor.getPreviousResult(query));
|
|
39
|
+
// before the subscribeQuery is connected and calls it's own callback,
|
|
40
|
+
// we might have data in the store via SSR, we need to notify useSyncExternalStore that
|
|
41
|
+
// the data has changed.
|
|
42
|
+
cb();
|
|
43
|
+
// Don't subscribe if query is null
|
|
44
|
+
if (!query) {
|
|
45
|
+
const unsubscribe = () => { };
|
|
46
|
+
return unsubscribe;
|
|
47
|
+
}
|
|
48
|
+
const unsubscribe = _core.subscribeQuery(query, (result) => {
|
|
49
|
+
resultCacheRef.current = {
|
|
50
|
+
isLoading: !Boolean(result),
|
|
51
|
+
// @ts-expect-error: ts thinks this will always be overwritten
|
|
52
|
+
data: undefined,
|
|
53
|
+
// @ts-expect-error: ts thinks this will always be overwritten
|
|
54
|
+
pageInfo: undefined,
|
|
55
|
+
// @ts-expect-error: ts thinks this will always be overwritten
|
|
56
|
+
error: undefined,
|
|
57
|
+
...result,
|
|
58
|
+
};
|
|
59
|
+
cb();
|
|
60
|
+
});
|
|
61
|
+
return unsubscribe;
|
|
62
|
+
},
|
|
63
|
+
// Build a new subscribe function if the query changes
|
|
64
|
+
[queryHash]);
|
|
65
|
+
const state = useSyncExternalStore(subscribe, () => resultCacheRef.current, () => {
|
|
66
|
+
if (serverSnapshot && serverSnapshotCacheRef.current === defaultState) {
|
|
67
|
+
const result = serverSnapshot();
|
|
68
|
+
if (result) {
|
|
69
|
+
serverSnapshotCacheRef.current = result;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return serverSnapshotCacheRef.current;
|
|
73
|
+
});
|
|
74
|
+
return { state, query, queryHash };
|
|
75
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
export function useTimeout() {
|
|
3
|
+
const timeoutRef = useRef(null);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
clear();
|
|
6
|
+
}, []);
|
|
7
|
+
function set(delay, fn) {
|
|
8
|
+
clear();
|
|
9
|
+
timeoutRef.current = setTimeout(fn, delay);
|
|
10
|
+
}
|
|
11
|
+
function clear() {
|
|
12
|
+
if (timeoutRef.current) {
|
|
13
|
+
clearTimeout(timeoutRef.current);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return { set, clear };
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@instantdb/react-common",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/esm/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@instantdb/core": "0.0.0",
|
|
17
|
+
"@instantdb/version": "0.0.0"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"react": ">=16"
|
|
21
|
+
}
|
|
22
|
+
}
|