@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,7 @@
|
|
|
1
|
+
import { TransactionChunk } from './instatx.ts';
|
|
2
|
+
import { IContainEntitiesAndLinks } from './schemaTypes.ts';
|
|
3
|
+
export declare const isValidEntityId: (value: unknown) => boolean;
|
|
4
|
+
export declare class TransactionValidationError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare const validateTransactions: (inputChunks: TransactionChunk<any, any> | TransactionChunk<any, any>[], schema?: IContainEntitiesAndLinks<any, any>) => void;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { isLookup } from './instatx.js';
|
|
2
|
+
import { validate as validateUUID } from 'uuid';
|
|
3
|
+
export const isValidEntityId = (value) => {
|
|
4
|
+
if (typeof value !== 'string') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (isLookup(value)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return validateUUID(value);
|
|
11
|
+
};
|
|
12
|
+
export class TransactionValidationError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'TransactionValidationError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const formatAvailableOptions = (items) => items.length > 0 ? items.join(', ') : 'none';
|
|
19
|
+
const createEntityNotFoundError = (entityName, availableEntities) => new TransactionValidationError(`Entity '${entityName}' does not exist in schema. Available entities: ${formatAvailableOptions(availableEntities)}`);
|
|
20
|
+
const TYPE_VALIDATORS = {
|
|
21
|
+
string: (value) => typeof value === 'string',
|
|
22
|
+
number: (value) => typeof value === 'number' && !isNaN(value),
|
|
23
|
+
boolean: (value) => typeof value === 'boolean',
|
|
24
|
+
date: (value) => value instanceof Date ||
|
|
25
|
+
typeof value === 'string' ||
|
|
26
|
+
typeof value === 'number',
|
|
27
|
+
json: () => true,
|
|
28
|
+
};
|
|
29
|
+
const isValidValueForAttr = (value, attrDef) => {
|
|
30
|
+
if (value === null || value === undefined)
|
|
31
|
+
return true;
|
|
32
|
+
return TYPE_VALIDATORS[attrDef.valueType]?.(value) ?? false;
|
|
33
|
+
};
|
|
34
|
+
const validateEntityExists = (entityName, schema) => {
|
|
35
|
+
const entityDef = schema.entities[entityName];
|
|
36
|
+
if (!entityDef) {
|
|
37
|
+
throw createEntityNotFoundError(entityName, Object.keys(schema.entities));
|
|
38
|
+
}
|
|
39
|
+
return entityDef;
|
|
40
|
+
};
|
|
41
|
+
const validateDataOperation = (entityName, data, schema) => {
|
|
42
|
+
const entityDef = validateEntityExists(entityName, schema);
|
|
43
|
+
if (typeof data !== 'object' || data === null) {
|
|
44
|
+
throw new TransactionValidationError(`Arguments for data operation on entity '${entityName}' must be an object, but received: ${typeof data}`);
|
|
45
|
+
}
|
|
46
|
+
for (const [attrName, value] of Object.entries(data)) {
|
|
47
|
+
if (attrName === 'id')
|
|
48
|
+
continue; // id is handled specially
|
|
49
|
+
const attrDef = entityDef.attrs[attrName];
|
|
50
|
+
if (attrDef) {
|
|
51
|
+
if (!isValidValueForAttr(value, attrDef)) {
|
|
52
|
+
throw new TransactionValidationError(`Invalid value for attribute '${attrName}' in entity '${entityName}'. Expected ${attrDef.valueType}, but received: ${typeof value}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const validateLinkOperation = (entityName, links, schema) => {
|
|
58
|
+
const entityDef = validateEntityExists(entityName, schema);
|
|
59
|
+
if (typeof links !== 'object' || links === null) {
|
|
60
|
+
throw new TransactionValidationError(`Arguments for link operation on entity '${entityName}' must be an object, but received: ${typeof links}`);
|
|
61
|
+
}
|
|
62
|
+
for (const [linkName, linkValue] of Object.entries(links)) {
|
|
63
|
+
const link = entityDef.links[linkName];
|
|
64
|
+
if (!link) {
|
|
65
|
+
const availableLinks = Object.keys(entityDef.links);
|
|
66
|
+
throw new TransactionValidationError(`Link '${linkName}' does not exist on entity '${entityName}'. Available links: ${formatAvailableOptions(availableLinks)}`);
|
|
67
|
+
}
|
|
68
|
+
// Validate UUID format for link values
|
|
69
|
+
if (linkValue !== null && linkValue !== undefined) {
|
|
70
|
+
if (Array.isArray(linkValue)) {
|
|
71
|
+
// Handle array of UUIDs
|
|
72
|
+
for (const linkReference of linkValue) {
|
|
73
|
+
if (!isValidEntityId(linkReference)) {
|
|
74
|
+
throw new TransactionValidationError(`Invalid entity ID in link '${linkName}' for entity '${entityName}'. Expected a UUID or a lookup, but received: ${linkReference}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Handle single UUID
|
|
80
|
+
if (!isValidEntityId(linkValue)) {
|
|
81
|
+
throw new TransactionValidationError(`Invalid UUID in link '${linkName}' for entity '${entityName}'. Expected a UUID, but received: ${linkValue}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const VALIDATION_STRATEGIES = {
|
|
88
|
+
create: validateDataOperation,
|
|
89
|
+
update: validateDataOperation,
|
|
90
|
+
merge: validateDataOperation,
|
|
91
|
+
link: validateLinkOperation,
|
|
92
|
+
unlink: validateLinkOperation,
|
|
93
|
+
delete: () => { },
|
|
94
|
+
};
|
|
95
|
+
const validateOp = (op, schema) => {
|
|
96
|
+
if (!schema)
|
|
97
|
+
return;
|
|
98
|
+
const [action, entityName, _id, args] = op;
|
|
99
|
+
// _id should be a uuid
|
|
100
|
+
if (!Array.isArray(_id)) {
|
|
101
|
+
const isUuid = validateUUID(_id);
|
|
102
|
+
if (!isUuid) {
|
|
103
|
+
throw new TransactionValidationError(`Invalid id for entity '${entityName}'. Expected a UUID, but received: ${_id}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (typeof entityName !== 'string') {
|
|
107
|
+
throw new TransactionValidationError(`Entity name must be a string, but received: ${typeof entityName}`);
|
|
108
|
+
}
|
|
109
|
+
const validator = VALIDATION_STRATEGIES[action];
|
|
110
|
+
if (validator && args !== undefined) {
|
|
111
|
+
validator(entityName, args, schema);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export const validateTransactions = (inputChunks, schema) => {
|
|
115
|
+
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
|
|
116
|
+
for (const txStep of chunks) {
|
|
117
|
+
if (!txStep || typeof txStep !== 'object') {
|
|
118
|
+
throw new TransactionValidationError(`Transaction chunk must be an object, but received: ${typeof txStep}`);
|
|
119
|
+
}
|
|
120
|
+
if (!Array.isArray(txStep.__ops)) {
|
|
121
|
+
throw new TransactionValidationError(`Transaction chunk must have __ops array, but received: ${typeof txStep.__ops}`);
|
|
122
|
+
}
|
|
123
|
+
for (const op of txStep.__ops) {
|
|
124
|
+
if (!Array.isArray(op)) {
|
|
125
|
+
throw new TransactionValidationError(`Transaction operation must be an array, but received: ${typeof op}`);
|
|
126
|
+
}
|
|
127
|
+
validateOp(op, schema);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class Deferred {
|
|
2
|
+
promise;
|
|
3
|
+
_resolve;
|
|
4
|
+
_reject;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.promise = new Promise((resolve, reject) => {
|
|
7
|
+
this._resolve = resolve;
|
|
8
|
+
this._reject = reject;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
resolve(value) {
|
|
12
|
+
this._resolve(value);
|
|
13
|
+
}
|
|
14
|
+
reject(reason) {
|
|
15
|
+
this._reject(reason);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Logger } from './log.ts';
|
|
2
|
+
export declare const META_KEY = "__meta";
|
|
3
|
+
export type ObjectMeta = {
|
|
4
|
+
createdAt: number;
|
|
5
|
+
updatedAt: number;
|
|
6
|
+
size: number;
|
|
7
|
+
};
|
|
8
|
+
export type Meta<K extends string> = {
|
|
9
|
+
objects: Record<K, ObjectMeta>;
|
|
10
|
+
};
|
|
11
|
+
export type StoreInterfaceStoreName = 'kv' | 'querySubs' | 'syncSubs';
|
|
12
|
+
export declare abstract class StoreInterface {
|
|
13
|
+
constructor(appId: string, storeName: StoreInterfaceStoreName);
|
|
14
|
+
abstract getItem(key: string): Promise<any>;
|
|
15
|
+
abstract removeItem(key: string): Promise<void>;
|
|
16
|
+
abstract multiSet(keyValuePairs: Array<[string, any]>): Promise<void>;
|
|
17
|
+
abstract getAllKeys(): Promise<string[]>;
|
|
18
|
+
}
|
|
19
|
+
export type StoreInterfaceClass = new (appId: string, storeName: StoreInterfaceStoreName) => StoreInterface;
|
|
20
|
+
export type GCOpts = {
|
|
21
|
+
maxSize: number;
|
|
22
|
+
maxAgeMs: number;
|
|
23
|
+
maxEntries: number;
|
|
24
|
+
};
|
|
25
|
+
export type Opts<K, T, SerializedT> = {
|
|
26
|
+
persister: StoreInterface;
|
|
27
|
+
/**
|
|
28
|
+
* Merges data from storage with in-memory value on load.
|
|
29
|
+
* The value returned from merge will become the current value.
|
|
30
|
+
*/
|
|
31
|
+
merge: (key: K, fromStorage: T | null | undefined, inMemoryValue: T | null | undefined) => T;
|
|
32
|
+
serialize: (key: K, input: T) => SerializedT;
|
|
33
|
+
parse: (key: K, value: SerializedT) => T;
|
|
34
|
+
objectSize: (x: SerializedT) => number;
|
|
35
|
+
logger: Logger;
|
|
36
|
+
gc: GCOpts | null | undefined;
|
|
37
|
+
saveThrottleMs?: number | null | undefined;
|
|
38
|
+
idleCallbackMaxWaitMs?: number | null | undefined;
|
|
39
|
+
preloadEntryCount?: number | null | undefined;
|
|
40
|
+
};
|
|
41
|
+
export declare class PersistedObject<K extends string, T, SerializedT> {
|
|
42
|
+
currentValue: Record<K, T>;
|
|
43
|
+
private _subs;
|
|
44
|
+
private _persister;
|
|
45
|
+
private _merge;
|
|
46
|
+
private serialize;
|
|
47
|
+
private parse;
|
|
48
|
+
private _saveThrottleMs;
|
|
49
|
+
private _idleCallbackMaxWaitMs;
|
|
50
|
+
private _nextSave;
|
|
51
|
+
private _nextGc;
|
|
52
|
+
private _pendingSaveKeys;
|
|
53
|
+
private _loadedKeys;
|
|
54
|
+
private _loadingKeys;
|
|
55
|
+
private _objectSize;
|
|
56
|
+
private _log;
|
|
57
|
+
onKeyLoaded: (key: string) => void | null | undefined;
|
|
58
|
+
private _version;
|
|
59
|
+
private _meta;
|
|
60
|
+
private _gcOpts;
|
|
61
|
+
constructor(opts: Opts<K, T, SerializedT>);
|
|
62
|
+
private _initMeta;
|
|
63
|
+
private _getMeta;
|
|
64
|
+
private _refreshMeta;
|
|
65
|
+
private _preloadEntries;
|
|
66
|
+
private _getFromStorage;
|
|
67
|
+
waitForKeyToLoad(k: K): Promise<Record<K, T>[K]>;
|
|
68
|
+
waitForMetaToLoad(): Promise<Meta<K> | null>;
|
|
69
|
+
unloadKey(k: K): void;
|
|
70
|
+
private _loadKey;
|
|
71
|
+
private _writeToStorage;
|
|
72
|
+
flush(): Promise<number | undefined>;
|
|
73
|
+
private _gc;
|
|
74
|
+
gc(): void;
|
|
75
|
+
private _enqueuePersist;
|
|
76
|
+
version(): number;
|
|
77
|
+
updateInPlace(f: (prev: Record<string, T>) => void): Record<string, T>;
|
|
78
|
+
subscribe(cb: (value: Record<K, T>) => void): () => void;
|
|
79
|
+
clearUnloadedKeys(): Promise<void>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
// PersistedObjects save data outside of memory.
|
|
2
|
+
//
|
|
3
|
+
// When we load a persisted object, it's possible we call `set`
|
|
4
|
+
// before we finish loading. To address we handle set in two ways:
|
|
5
|
+
//
|
|
6
|
+
// 1. Before load
|
|
7
|
+
// We simply update currentValue in memory
|
|
8
|
+
//
|
|
9
|
+
// 2. After load
|
|
10
|
+
// We update currentValue in memory and in storage
|
|
11
|
+
//
|
|
12
|
+
// Each PersistedObject provides it's own `onMerge`
|
|
13
|
+
// function to handle the merge of data from storage and memory
|
|
14
|
+
// on load
|
|
15
|
+
// Uses `requestIdleCallback` if available, otherwise calls the
|
|
16
|
+
// callback immediately
|
|
17
|
+
import { create } from 'mutative';
|
|
18
|
+
function safeIdleCallback(cb, timeout) {
|
|
19
|
+
if (typeof requestIdleCallback === 'undefined') {
|
|
20
|
+
cb();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
requestIdleCallback(cb, { timeout });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export const META_KEY = '__meta';
|
|
27
|
+
export class StoreInterface {
|
|
28
|
+
constructor(appId, storeName) { }
|
|
29
|
+
}
|
|
30
|
+
export class PersistedObject {
|
|
31
|
+
currentValue;
|
|
32
|
+
_subs = [];
|
|
33
|
+
_persister;
|
|
34
|
+
_merge;
|
|
35
|
+
serialize;
|
|
36
|
+
parse;
|
|
37
|
+
_saveThrottleMs;
|
|
38
|
+
_idleCallbackMaxWaitMs;
|
|
39
|
+
_nextSave = null;
|
|
40
|
+
_nextGc = null;
|
|
41
|
+
_pendingSaveKeys = new Set();
|
|
42
|
+
_loadedKeys = new Set();
|
|
43
|
+
_loadingKeys;
|
|
44
|
+
_objectSize;
|
|
45
|
+
_log;
|
|
46
|
+
onKeyLoaded;
|
|
47
|
+
_version = 0;
|
|
48
|
+
_meta = {
|
|
49
|
+
isLoading: true,
|
|
50
|
+
onLoadCbs: [],
|
|
51
|
+
value: null,
|
|
52
|
+
error: null,
|
|
53
|
+
attempts: 0,
|
|
54
|
+
};
|
|
55
|
+
_gcOpts;
|
|
56
|
+
constructor(opts) {
|
|
57
|
+
this._persister = opts.persister;
|
|
58
|
+
this._merge = opts.merge;
|
|
59
|
+
this.serialize = opts.serialize;
|
|
60
|
+
this.parse = opts.parse;
|
|
61
|
+
this._objectSize = opts.objectSize;
|
|
62
|
+
this._log = opts.logger;
|
|
63
|
+
this._saveThrottleMs = opts.saveThrottleMs ?? 100;
|
|
64
|
+
this._idleCallbackMaxWaitMs = opts.idleCallbackMaxWaitMs ?? 1000;
|
|
65
|
+
this._gcOpts = opts.gc;
|
|
66
|
+
this.currentValue = {};
|
|
67
|
+
this._loadedKeys = new Set();
|
|
68
|
+
this._loadingKeys = {};
|
|
69
|
+
this._initMeta();
|
|
70
|
+
if (opts.preloadEntryCount) {
|
|
71
|
+
this._preloadEntries(opts.preloadEntryCount);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async _initMeta() {
|
|
75
|
+
if (this._meta.loadingPromise) {
|
|
76
|
+
await this._meta.loadingPromise;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const p = this._persister.getItem(META_KEY);
|
|
80
|
+
this._meta.loadingPromise = p;
|
|
81
|
+
const v = await p;
|
|
82
|
+
this._meta.isLoading = false;
|
|
83
|
+
this._meta.error = null;
|
|
84
|
+
this._meta.loadingPromise = null;
|
|
85
|
+
this._meta.attempts = 0;
|
|
86
|
+
const existingObjects = this._meta.value?.objects ?? {};
|
|
87
|
+
const value = v ?? {};
|
|
88
|
+
const objects = value.objects ?? {};
|
|
89
|
+
// Merge the values from storage with in-memory values
|
|
90
|
+
this._meta.value = {
|
|
91
|
+
...value,
|
|
92
|
+
objects: { ...existingObjects, ...objects },
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
this._meta.error = e;
|
|
97
|
+
this._meta.attempts++;
|
|
98
|
+
this._meta.loadingPromise = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async _getMeta() {
|
|
102
|
+
if (this._meta.value) {
|
|
103
|
+
return this._meta.value;
|
|
104
|
+
}
|
|
105
|
+
if (this._meta.loadingPromise) {
|
|
106
|
+
await this._meta.loadingPromise;
|
|
107
|
+
return this._meta.value;
|
|
108
|
+
}
|
|
109
|
+
this._initMeta();
|
|
110
|
+
await this._meta.loadingPromise;
|
|
111
|
+
return this._meta.value;
|
|
112
|
+
}
|
|
113
|
+
async _refreshMeta() {
|
|
114
|
+
await this._initMeta();
|
|
115
|
+
return this._meta.value;
|
|
116
|
+
}
|
|
117
|
+
async _preloadEntries(n) {
|
|
118
|
+
const meta = await this.waitForMetaToLoad();
|
|
119
|
+
if (!meta)
|
|
120
|
+
return;
|
|
121
|
+
const entries = Object.entries(meta.objects);
|
|
122
|
+
entries.sort(([_k_a, a_meta], [_k_b, b_meta]) => {
|
|
123
|
+
return b_meta.updatedAt - a_meta.updatedAt;
|
|
124
|
+
});
|
|
125
|
+
for (const [k] of entries.slice(0, n)) {
|
|
126
|
+
this._loadKey(k);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async _getFromStorage(key) {
|
|
130
|
+
try {
|
|
131
|
+
const data = await this._persister.getItem(key);
|
|
132
|
+
if (!data) {
|
|
133
|
+
return data;
|
|
134
|
+
}
|
|
135
|
+
const parsed = this.parse(key, data);
|
|
136
|
+
return parsed;
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
console.error(`Unable to read from storage for key=${key}`, e);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async waitForKeyToLoad(k) {
|
|
144
|
+
if (this._loadedKeys.has(k)) {
|
|
145
|
+
return this.currentValue[k];
|
|
146
|
+
}
|
|
147
|
+
await (this._loadingKeys[k] || this._loadKey(k));
|
|
148
|
+
return this.currentValue[k];
|
|
149
|
+
}
|
|
150
|
+
// Used for tests
|
|
151
|
+
async waitForMetaToLoad() {
|
|
152
|
+
return this._getMeta();
|
|
153
|
+
}
|
|
154
|
+
// Unloads the key so that it can be garbage collected, but does not
|
|
155
|
+
// delete it. Removes the key from currentValue.
|
|
156
|
+
unloadKey(k) {
|
|
157
|
+
this._loadedKeys.delete(k);
|
|
158
|
+
delete this._loadingKeys[k];
|
|
159
|
+
delete this.currentValue[k];
|
|
160
|
+
}
|
|
161
|
+
async _loadKey(k) {
|
|
162
|
+
if (this._loadedKeys.has(k) || k in this._loadingKeys)
|
|
163
|
+
return;
|
|
164
|
+
const p = this._getFromStorage(k);
|
|
165
|
+
this._loadingKeys[k] = p;
|
|
166
|
+
const value = await p;
|
|
167
|
+
delete this._loadingKeys[k];
|
|
168
|
+
this._loadedKeys.add(k);
|
|
169
|
+
if (value) {
|
|
170
|
+
const merged = this._merge(k, value, this.currentValue[k]);
|
|
171
|
+
if (merged) {
|
|
172
|
+
this.currentValue[k] = merged;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
this.onKeyLoaded && this.onKeyLoaded(k);
|
|
176
|
+
}
|
|
177
|
+
// Returns a promise with a number so that we can wait for flush
|
|
178
|
+
// to finish in the tests. The number is the number of operations
|
|
179
|
+
// it performed, but it's mostly there so that typescript will warn
|
|
180
|
+
// us if we forget to retun the promise from the function.
|
|
181
|
+
_writeToStorage(opts) {
|
|
182
|
+
const promises = [];
|
|
183
|
+
const skipGc = opts?.skipGc;
|
|
184
|
+
if (this._meta.isLoading) {
|
|
185
|
+
// Wait for meta to load and try again, give it a delay so that
|
|
186
|
+
// we don't spend too much time retrying
|
|
187
|
+
const p = new Promise((resolve, reject) => {
|
|
188
|
+
setTimeout(() => this._enqueuePersist(opts
|
|
189
|
+
? { ...opts, attempts: (opts.attempts || 0) + 1 }
|
|
190
|
+
: { attempts: 1 })
|
|
191
|
+
.then(resolve)
|
|
192
|
+
.catch(reject), 10 + (opts?.attempts ?? 0) * 1000);
|
|
193
|
+
});
|
|
194
|
+
promises.push(p);
|
|
195
|
+
return Promise.all(promises).then((vs) => vs.reduce((acc, x) => acc + x, 0));
|
|
196
|
+
}
|
|
197
|
+
const metaValue = this._meta.value;
|
|
198
|
+
if (!metaValue) {
|
|
199
|
+
// If it's not loading and we don't have the data, then there
|
|
200
|
+
// must be an error and we're not going to be able to save until
|
|
201
|
+
// the error is resolved elsewhere.
|
|
202
|
+
return Promise.resolve(0);
|
|
203
|
+
}
|
|
204
|
+
const keysToDelete = [];
|
|
205
|
+
const keysToUpdate = [];
|
|
206
|
+
for (const k of this._pendingSaveKeys) {
|
|
207
|
+
if (!(k in this.currentValue)) {
|
|
208
|
+
keysToDelete.push(k);
|
|
209
|
+
delete metaValue.objects[k];
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
keysToUpdate.push(k);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
for (const k of keysToDelete) {
|
|
216
|
+
const p = this._persister.removeItem(k);
|
|
217
|
+
promises.push(p.then(() => 1));
|
|
218
|
+
this._loadedKeys.delete(k);
|
|
219
|
+
this._pendingSaveKeys.delete(k);
|
|
220
|
+
}
|
|
221
|
+
const keysToLoad = [];
|
|
222
|
+
const kvPairs = [[META_KEY, metaValue]];
|
|
223
|
+
const metaObjects = metaValue.objects ?? {};
|
|
224
|
+
metaValue.objects = metaObjects;
|
|
225
|
+
for (const k of keysToUpdate) {
|
|
226
|
+
if (this._loadedKeys.has(k)) {
|
|
227
|
+
const serializedV = this.serialize(k, this.currentValue[k]);
|
|
228
|
+
kvPairs.push([k, serializedV]);
|
|
229
|
+
const size = this._objectSize(serializedV);
|
|
230
|
+
const m = metaObjects[k] ?? {
|
|
231
|
+
createdAt: Date.now(),
|
|
232
|
+
updatedAt: Date.now(),
|
|
233
|
+
size,
|
|
234
|
+
};
|
|
235
|
+
m.updatedAt = Date.now();
|
|
236
|
+
m.size = size;
|
|
237
|
+
metaObjects[k] = m;
|
|
238
|
+
this._pendingSaveKeys.delete(k);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
keysToLoad.push(k);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const p = this._persister.multiSet(kvPairs);
|
|
245
|
+
promises.push(p.then(() => 1));
|
|
246
|
+
// For the keys that haven't loaded, load the key then try
|
|
247
|
+
// persisting again. We don't want to do any async work here
|
|
248
|
+
// or else we might end up saving older copies of the data to
|
|
249
|
+
// the store.
|
|
250
|
+
for (const k of keysToLoad) {
|
|
251
|
+
const p = this._loadKey(k).then(() => this._enqueuePersist(opts));
|
|
252
|
+
promises.push(p);
|
|
253
|
+
}
|
|
254
|
+
if (!skipGc) {
|
|
255
|
+
this.gc();
|
|
256
|
+
}
|
|
257
|
+
return Promise.all(promises).then((vs) => {
|
|
258
|
+
return vs.reduce((acc, x) => acc + x, 0);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
async flush() {
|
|
262
|
+
if (!this._nextSave) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
clearTimeout(this._nextSave);
|
|
266
|
+
this._nextSave = null;
|
|
267
|
+
const p = this._writeToStorage();
|
|
268
|
+
return p;
|
|
269
|
+
}
|
|
270
|
+
async _gc() {
|
|
271
|
+
if (!this._gcOpts) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const keys = new Set(await this._persister.getAllKeys());
|
|
275
|
+
keys.delete(META_KEY);
|
|
276
|
+
// Keys we can't delete
|
|
277
|
+
const sacredKeys = new Set(Object.keys(this.currentValue));
|
|
278
|
+
for (const k of Object.keys(this._loadingKeys)) {
|
|
279
|
+
sacredKeys.add(k);
|
|
280
|
+
}
|
|
281
|
+
for (const k of this._loadedKeys) {
|
|
282
|
+
sacredKeys.add(k);
|
|
283
|
+
}
|
|
284
|
+
// Refresh meta from the store so that we're less likely to
|
|
285
|
+
// clobber data from other tabs
|
|
286
|
+
const meta = await this._refreshMeta();
|
|
287
|
+
if (!meta) {
|
|
288
|
+
this._log.info('Could not gc because we were not able to load meta');
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const promises = [];
|
|
292
|
+
const deets = {
|
|
293
|
+
gcOpts: this._gcOpts,
|
|
294
|
+
keys,
|
|
295
|
+
sacredKeys,
|
|
296
|
+
removed: [],
|
|
297
|
+
metaRemoved: [],
|
|
298
|
+
removedMissingCount: 0,
|
|
299
|
+
removedOldCount: 0,
|
|
300
|
+
removedThresholdCount: 0,
|
|
301
|
+
removedSizeCount: 0,
|
|
302
|
+
};
|
|
303
|
+
// First, remove all keys we don't know about
|
|
304
|
+
for (const key of keys) {
|
|
305
|
+
if (sacredKeys.has(key) || key in meta.objects) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
this._log.info('Lost track of key in meta', key);
|
|
309
|
+
promises.push(this._persister.removeItem(key));
|
|
310
|
+
deets.removed.push(key);
|
|
311
|
+
deets.removedMissingCount++;
|
|
312
|
+
}
|
|
313
|
+
// Remove anything over the max age
|
|
314
|
+
const now = Date.now();
|
|
315
|
+
for (const [k, m] of Object.entries(meta.objects)) {
|
|
316
|
+
if (!sacredKeys.has(k) &&
|
|
317
|
+
m.updatedAt < now - this._gcOpts.maxAgeMs) {
|
|
318
|
+
promises.push(this._persister.removeItem(k));
|
|
319
|
+
delete meta.objects[k];
|
|
320
|
+
deets.removed.push(k);
|
|
321
|
+
deets.removedOldCount++;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// Keep queries under max queries
|
|
325
|
+
const maxEntries = Object.entries(meta.objects);
|
|
326
|
+
maxEntries.sort(([_k_a, a_meta], [_k_b, b_meta]) => {
|
|
327
|
+
return a_meta.updatedAt - b_meta.updatedAt;
|
|
328
|
+
});
|
|
329
|
+
const deletableMaxEntries = maxEntries.filter(([x]) => !sacredKeys.has(x));
|
|
330
|
+
if (maxEntries.length > this._gcOpts.maxEntries) {
|
|
331
|
+
for (const [k] of deletableMaxEntries.slice(0, maxEntries.length - this._gcOpts.maxEntries)) {
|
|
332
|
+
promises.push(this._persister.removeItem(k));
|
|
333
|
+
delete meta.objects[k];
|
|
334
|
+
deets.removed.push(k);
|
|
335
|
+
deets.removedThresholdCount++;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Remove oldest entries until we are under max size
|
|
339
|
+
const delEntries = Object.entries(meta.objects);
|
|
340
|
+
delEntries.sort(([_k_a, a_meta], [_k_b, b_meta]) => {
|
|
341
|
+
return a_meta.updatedAt - b_meta.updatedAt;
|
|
342
|
+
});
|
|
343
|
+
const deletableDelEntries = delEntries.filter(([x]) => !sacredKeys.has(x));
|
|
344
|
+
let currentSize = delEntries.reduce((acc, [_k, m]) => {
|
|
345
|
+
return acc + m.size;
|
|
346
|
+
}, 0);
|
|
347
|
+
while (currentSize > 0 &&
|
|
348
|
+
currentSize > this._gcOpts.maxSize &&
|
|
349
|
+
deletableDelEntries.length) {
|
|
350
|
+
const [[k, m]] = deletableDelEntries.splice(0, 1);
|
|
351
|
+
currentSize -= m.size;
|
|
352
|
+
promises.push(this._persister.removeItem(k));
|
|
353
|
+
delete meta.objects[k];
|
|
354
|
+
deets.removed.push(k);
|
|
355
|
+
deets.removedSizeCount++;
|
|
356
|
+
}
|
|
357
|
+
// Update meta to remove keys that are no longer in the store
|
|
358
|
+
for (const k of Object.keys(meta.objects)) {
|
|
359
|
+
if (!keys.has(k) && !sacredKeys.has(k)) {
|
|
360
|
+
delete meta.objects[k];
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (deets.removed.length || deets.metaRemoved.length) {
|
|
364
|
+
// Trigger a flush of the meta
|
|
365
|
+
promises.push(this._enqueuePersist({ skipGc: true }));
|
|
366
|
+
}
|
|
367
|
+
this._log.info('Completed GC', deets);
|
|
368
|
+
await Promise.all(promises);
|
|
369
|
+
return deets;
|
|
370
|
+
}
|
|
371
|
+
// Schedules a GC to run in one minute (unless it is already scheduled)
|
|
372
|
+
gc() {
|
|
373
|
+
if (this._nextGc) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
this._nextGc = setTimeout(() => {
|
|
377
|
+
safeIdleCallback(() => {
|
|
378
|
+
this._nextGc = null;
|
|
379
|
+
this._gc().catch((e) => this._log.error('Persisted Object GC Failed:', e));
|
|
380
|
+
}, 30 * 1000);
|
|
381
|
+
},
|
|
382
|
+
// 1 minute + some jitter to keep multiple tabs from running at same time
|
|
383
|
+
1000 * 60 + Math.random() * 500);
|
|
384
|
+
}
|
|
385
|
+
_enqueuePersist(opts) {
|
|
386
|
+
return new Promise((resolve, reject) => {
|
|
387
|
+
if (this._nextSave) {
|
|
388
|
+
resolve(0);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
this._nextSave = setTimeout(() => {
|
|
392
|
+
safeIdleCallback(() => {
|
|
393
|
+
this._nextSave = null;
|
|
394
|
+
this._writeToStorage(opts).then(resolve).catch(reject);
|
|
395
|
+
}, this._idleCallbackMaxWaitMs);
|
|
396
|
+
}, this._saveThrottleMs);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
version() {
|
|
400
|
+
return this._version;
|
|
401
|
+
}
|
|
402
|
+
// Takes a function that updates the store in place.
|
|
403
|
+
// Uses `mutative` to get a list of keys that were changed
|
|
404
|
+
// so that we know which entries we need to persist to the store.
|
|
405
|
+
updateInPlace(f) {
|
|
406
|
+
this._version++;
|
|
407
|
+
const [state, patches] = create(this.currentValue, f, {
|
|
408
|
+
enablePatches: true,
|
|
409
|
+
});
|
|
410
|
+
for (const patch of patches) {
|
|
411
|
+
const k = patch.path[0];
|
|
412
|
+
if (k && typeof k === 'string') {
|
|
413
|
+
this._pendingSaveKeys.add(k);
|
|
414
|
+
if (!this._loadedKeys.has(k)) {
|
|
415
|
+
this._loadKey(k);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
this.currentValue = state;
|
|
420
|
+
this._enqueuePersist();
|
|
421
|
+
for (const cb of this._subs) {
|
|
422
|
+
cb(this.currentValue);
|
|
423
|
+
}
|
|
424
|
+
return state;
|
|
425
|
+
}
|
|
426
|
+
subscribe(cb) {
|
|
427
|
+
this._subs.push(cb);
|
|
428
|
+
cb(this.currentValue);
|
|
429
|
+
return () => {
|
|
430
|
+
this._subs = this._subs.filter((x) => x !== cb);
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
// Removes any keys that we haven't loaded--used when
|
|
434
|
+
// changing users to make sure we clean out all user data
|
|
435
|
+
async clearUnloadedKeys() {
|
|
436
|
+
let needsPersist = false;
|
|
437
|
+
for (const key of await this._persister.getAllKeys()) {
|
|
438
|
+
if (key === META_KEY || key in this.currentValue) {
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
this._pendingSaveKeys.add(key);
|
|
442
|
+
needsPersist = true;
|
|
443
|
+
}
|
|
444
|
+
if (needsPersist) {
|
|
445
|
+
await this._enqueuePersist();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function coerceToDate(x: unknown): Date | null | undefined;
|