@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,722 @@
|
|
|
1
|
+
import { create } from 'mutative';
|
|
2
|
+
import { immutableDeepMerge } from './utils/object.js';
|
|
3
|
+
import { coerceToDate } from './utils/dates.js';
|
|
4
|
+
export class AttrsStoreClass {
|
|
5
|
+
attrs;
|
|
6
|
+
linkIndex;
|
|
7
|
+
_blobAttrs = null;
|
|
8
|
+
_primaryKeys = null;
|
|
9
|
+
_forwardIdents = null;
|
|
10
|
+
_revIdents = null;
|
|
11
|
+
constructor(attrs, linkIndex) {
|
|
12
|
+
this.attrs = attrs;
|
|
13
|
+
this.linkIndex = linkIndex;
|
|
14
|
+
}
|
|
15
|
+
resetAttrIndexes() {
|
|
16
|
+
this._blobAttrs = null;
|
|
17
|
+
this._primaryKeys = null;
|
|
18
|
+
this._forwardIdents = null;
|
|
19
|
+
this._revIdents = null;
|
|
20
|
+
}
|
|
21
|
+
addAttr(attr) {
|
|
22
|
+
this.attrs[attr.id] = attr;
|
|
23
|
+
this.resetAttrIndexes();
|
|
24
|
+
}
|
|
25
|
+
deleteAttr(attrId) {
|
|
26
|
+
delete this.attrs[attrId];
|
|
27
|
+
this.resetAttrIndexes();
|
|
28
|
+
}
|
|
29
|
+
updateAttr(partialAttr) {
|
|
30
|
+
const attr = this.attrs[partialAttr.id];
|
|
31
|
+
if (!attr)
|
|
32
|
+
return;
|
|
33
|
+
this.attrs[partialAttr.id] = { ...attr, ...partialAttr };
|
|
34
|
+
this.resetAttrIndexes();
|
|
35
|
+
}
|
|
36
|
+
getAttr(id) {
|
|
37
|
+
return this.attrs[id];
|
|
38
|
+
}
|
|
39
|
+
get blobAttrs() {
|
|
40
|
+
if (this._blobAttrs) {
|
|
41
|
+
return this._blobAttrs;
|
|
42
|
+
}
|
|
43
|
+
this._blobAttrs = new Map();
|
|
44
|
+
for (const attr of Object.values(this.attrs)) {
|
|
45
|
+
if (isBlob(attr)) {
|
|
46
|
+
const [_, fwdEtype, fwdLabel] = attr['forward-identity'];
|
|
47
|
+
setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return this._blobAttrs;
|
|
51
|
+
}
|
|
52
|
+
get primaryKeys() {
|
|
53
|
+
if (this._primaryKeys) {
|
|
54
|
+
return this._primaryKeys;
|
|
55
|
+
}
|
|
56
|
+
this._primaryKeys = new Map();
|
|
57
|
+
for (const attr of Object.values(this.attrs)) {
|
|
58
|
+
if (attr['primary?']) {
|
|
59
|
+
const [_, fwdEtype] = attr['forward-identity'];
|
|
60
|
+
setInMap(this._primaryKeys, [fwdEtype], attr);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return this._primaryKeys;
|
|
64
|
+
}
|
|
65
|
+
get forwardIdents() {
|
|
66
|
+
if (this._forwardIdents) {
|
|
67
|
+
return this._forwardIdents;
|
|
68
|
+
}
|
|
69
|
+
this._forwardIdents = new Map();
|
|
70
|
+
for (const attr of Object.values(this.attrs)) {
|
|
71
|
+
const fwdIdent = attr['forward-identity'];
|
|
72
|
+
const [_, fwdEtype, fwdLabel] = fwdIdent;
|
|
73
|
+
setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);
|
|
74
|
+
}
|
|
75
|
+
return this._forwardIdents;
|
|
76
|
+
}
|
|
77
|
+
get revIdents() {
|
|
78
|
+
if (this._revIdents) {
|
|
79
|
+
return this._revIdents;
|
|
80
|
+
}
|
|
81
|
+
this._revIdents = new Map();
|
|
82
|
+
for (const attr of Object.values(this.attrs)) {
|
|
83
|
+
const revIdent = attr['reverse-identity'];
|
|
84
|
+
if (revIdent) {
|
|
85
|
+
const [_, revEtype, revLabel] = revIdent;
|
|
86
|
+
setInMap(this._revIdents, [revEtype, revLabel], attr);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return this._revIdents;
|
|
90
|
+
}
|
|
91
|
+
toJSON() {
|
|
92
|
+
return { attrs: this.attrs, linkIndex: this.linkIndex };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function hasEA(attr) {
|
|
96
|
+
return attr['cardinality'] === 'one';
|
|
97
|
+
}
|
|
98
|
+
function isRef(attr) {
|
|
99
|
+
return attr['value-type'] === 'ref';
|
|
100
|
+
}
|
|
101
|
+
export function isBlob(attr) {
|
|
102
|
+
return attr['value-type'] === 'blob';
|
|
103
|
+
}
|
|
104
|
+
function getAttr(attrs, attrId) {
|
|
105
|
+
return attrs[attrId];
|
|
106
|
+
}
|
|
107
|
+
export function getInMap(obj, path) {
|
|
108
|
+
return path.reduce((acc, key) => acc && acc.get(key), obj);
|
|
109
|
+
}
|
|
110
|
+
function deleteInMap(m, path) {
|
|
111
|
+
if (path.length === 0)
|
|
112
|
+
throw new Error('path must have at least one element');
|
|
113
|
+
if (path.length === 1) {
|
|
114
|
+
m.delete(path[0]);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const [head, ...tail] = path;
|
|
118
|
+
if (!m.has(head))
|
|
119
|
+
return;
|
|
120
|
+
deleteInMap(m.get(head), tail);
|
|
121
|
+
}
|
|
122
|
+
function setInMap(m, path, value) {
|
|
123
|
+
let current = m;
|
|
124
|
+
const lastI = path.length - 1;
|
|
125
|
+
for (let i = 0; i < lastI; i++) {
|
|
126
|
+
const part = path[i];
|
|
127
|
+
let nextMap = current.get(part);
|
|
128
|
+
if (nextMap === undefined) {
|
|
129
|
+
nextMap = new Map();
|
|
130
|
+
current.set(part, nextMap);
|
|
131
|
+
}
|
|
132
|
+
current = nextMap;
|
|
133
|
+
}
|
|
134
|
+
if (lastI > -1) {
|
|
135
|
+
current.set(path[lastI], value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function isDateAttr(attr) {
|
|
139
|
+
return attr['checked-data-type'] === 'date';
|
|
140
|
+
}
|
|
141
|
+
function createTripleIndexes(attrsStore, triples, useDateObjects) {
|
|
142
|
+
const eav = new Map();
|
|
143
|
+
const aev = new Map();
|
|
144
|
+
const vae = new Map();
|
|
145
|
+
for (const triple of triples) {
|
|
146
|
+
let [eid, aid, v] = triple;
|
|
147
|
+
const attr = attrsStore.getAttr(aid);
|
|
148
|
+
if (!attr) {
|
|
149
|
+
console.warn('no such attr', aid, eid);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (attr['checked-data-type'] === 'date' && useDateObjects) {
|
|
153
|
+
v = coerceToDate(v);
|
|
154
|
+
triple[2] = v;
|
|
155
|
+
}
|
|
156
|
+
if (isRef(attr)) {
|
|
157
|
+
setInMap(vae, [v, aid, eid], triple);
|
|
158
|
+
}
|
|
159
|
+
setInMap(eav, [eid, aid, v], triple);
|
|
160
|
+
setInMap(aev, [aid, eid, v], triple);
|
|
161
|
+
}
|
|
162
|
+
return { eav, aev, vae };
|
|
163
|
+
}
|
|
164
|
+
function createAttrIndexes(attrs) {
|
|
165
|
+
const blobAttrs = new Map();
|
|
166
|
+
const primaryKeys = new Map();
|
|
167
|
+
const forwardIdents = new Map();
|
|
168
|
+
const revIdents = new Map();
|
|
169
|
+
for (const attr of Object.values(attrs)) {
|
|
170
|
+
const fwdIdent = attr['forward-identity'];
|
|
171
|
+
const [_, fwdEtype, fwdLabel] = fwdIdent;
|
|
172
|
+
const revIdent = attr['reverse-identity'];
|
|
173
|
+
setInMap(forwardIdents, [fwdEtype, fwdLabel], attr);
|
|
174
|
+
if (isBlob(attr)) {
|
|
175
|
+
setInMap(blobAttrs, [fwdEtype, fwdLabel], attr);
|
|
176
|
+
}
|
|
177
|
+
if (attr['primary?']) {
|
|
178
|
+
setInMap(primaryKeys, [fwdEtype], attr);
|
|
179
|
+
}
|
|
180
|
+
if (revIdent) {
|
|
181
|
+
const [_, revEtype, revLabel] = revIdent;
|
|
182
|
+
setInMap(revIdents, [revEtype, revLabel], attr);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return { blobAttrs, primaryKeys, forwardIdents, revIdents };
|
|
186
|
+
}
|
|
187
|
+
export function toJSON(store) {
|
|
188
|
+
return {
|
|
189
|
+
triples: allMapValues(store.eav, 3),
|
|
190
|
+
cardinalityInference: store.cardinalityInference,
|
|
191
|
+
useDateObjects: store.useDateObjects,
|
|
192
|
+
version: 1,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export function fromJSON(attrsStore, storeJSON) {
|
|
196
|
+
return createStore(attrsStore, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.useDateObjects);
|
|
197
|
+
}
|
|
198
|
+
export function attrsStoreFromJSON(attrsStoreJSON, storeJSON) {
|
|
199
|
+
if (attrsStoreJSON) {
|
|
200
|
+
return new AttrsStoreClass(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
|
|
201
|
+
}
|
|
202
|
+
if (storeJSON && '__type' in storeJSON) {
|
|
203
|
+
return new AttrsStoreClass(storeJSON.attrs, storeJSON.linkIndex);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export function hasTriple(store, [e, a, v]) {
|
|
207
|
+
return getInMap(store.eav, [e, a, v]) !== undefined;
|
|
208
|
+
}
|
|
209
|
+
export function hasEntity(store, e) {
|
|
210
|
+
return getInMap(store.eav, [e]) !== undefined;
|
|
211
|
+
}
|
|
212
|
+
export function createStore(attrsStore, triples, enableCardinalityInference, useDateObjects) {
|
|
213
|
+
const store = createTripleIndexes(attrsStore, triples, useDateObjects);
|
|
214
|
+
store.cardinalityInference = enableCardinalityInference;
|
|
215
|
+
store.useDateObjects = useDateObjects;
|
|
216
|
+
return store;
|
|
217
|
+
}
|
|
218
|
+
// We may have local triples with lookup refs in them,
|
|
219
|
+
// we need to convert those lookup refs to eids to insert them
|
|
220
|
+
// into the store. If we can't find the lookup ref locally,
|
|
221
|
+
// then we drop the triple and have to wait for the server response
|
|
222
|
+
// to see the optimistic updates.
|
|
223
|
+
function resolveLookupRefs(store, triple) {
|
|
224
|
+
let eid;
|
|
225
|
+
// Check if `e` is a lookup ref
|
|
226
|
+
if (Array.isArray(triple[0])) {
|
|
227
|
+
const [a, v] = triple[0];
|
|
228
|
+
const eMaps = store.aev.get(a);
|
|
229
|
+
if (!eMaps) {
|
|
230
|
+
// We don't have the attr, so don't try to add the
|
|
231
|
+
// triple to the store
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
// This would be a lot more efficient with a ave index
|
|
235
|
+
const triples = allMapValues(eMaps, 2);
|
|
236
|
+
eid = triples.find((x) => x[2] === v)?.[0];
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
eid = triple[0];
|
|
240
|
+
}
|
|
241
|
+
if (!eid) {
|
|
242
|
+
// We don't know the eid that the ref refers to, so
|
|
243
|
+
// we can't add the triple to the store.
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
// Check if v is a lookup ref
|
|
247
|
+
const lookupV = triple[2];
|
|
248
|
+
if (Array.isArray(lookupV) &&
|
|
249
|
+
lookupV.length === 2 &&
|
|
250
|
+
store.aev.get(lookupV[0])) {
|
|
251
|
+
const [a, v] = lookupV;
|
|
252
|
+
const eMaps = store.aev.get(a);
|
|
253
|
+
if (!eMaps) {
|
|
254
|
+
// We don't have the attr, so don't try to add the
|
|
255
|
+
// triple to the store
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const triples = allMapValues(eMaps, 2);
|
|
259
|
+
const value = triples.find((x) => x[2] === v)?.[0];
|
|
260
|
+
if (!value) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
const [_e, aid, _v, ...rest] = triple;
|
|
264
|
+
return [eid, aid, value, ...rest];
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
const [_, ...rest] = triple;
|
|
268
|
+
return [eid, ...rest];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export function retractTriple(store, attrsStore, rawTriple) {
|
|
272
|
+
const triple = resolveLookupRefs(store, rawTriple);
|
|
273
|
+
if (!triple) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const [eid, aid, v] = triple;
|
|
277
|
+
const attr = attrsStore.getAttr(aid);
|
|
278
|
+
if (!attr) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
deleteInMap(store.eav, [eid, aid, v]);
|
|
282
|
+
deleteInMap(store.aev, [aid, eid, v]);
|
|
283
|
+
if (isRef(attr)) {
|
|
284
|
+
deleteInMap(store.vae, [v, aid, eid]);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
let _seed = 0;
|
|
288
|
+
function getCreatedAt(store, attr, triple) {
|
|
289
|
+
const [eid, aid, v] = triple;
|
|
290
|
+
let createdAt;
|
|
291
|
+
const t = getInMap(store.eav, [eid, aid, v]);
|
|
292
|
+
if (t) {
|
|
293
|
+
createdAt = t[3];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* (XXX)
|
|
297
|
+
* Two hacks here, for generating a `createdAt`
|
|
298
|
+
*
|
|
299
|
+
* 1. We multiply Date.now() by 10, to make sure that
|
|
300
|
+
* `createdAt` is always greater than anything the server
|
|
301
|
+
* could return
|
|
302
|
+
*
|
|
303
|
+
* We do this because right now we know we _only_ insert
|
|
304
|
+
* triples as optimistic updates.
|
|
305
|
+
*
|
|
306
|
+
* 2. We increment by `_seed`, to make sure there are no
|
|
307
|
+
* two triples with the same `createdAt`. This is
|
|
308
|
+
* done to make tests more predictable.
|
|
309
|
+
*
|
|
310
|
+
* We may need to rethink this. Because we * 10, we can't
|
|
311
|
+
* use this value as an _actual_ `createdAt` timestamp.
|
|
312
|
+
* Eventually we may want too though; For example, we could
|
|
313
|
+
* use `createdAt` for each triple, to infer a `createdAt` and
|
|
314
|
+
* `updatedAt` value for each object.
|
|
315
|
+
*/
|
|
316
|
+
return createdAt || Date.now() * 10 + _seed++;
|
|
317
|
+
}
|
|
318
|
+
export function addTriple(store, attrsStore, rawTriple) {
|
|
319
|
+
const triple = resolveLookupRefs(store, rawTriple);
|
|
320
|
+
if (!triple) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
let [eid, aid, v] = triple;
|
|
324
|
+
const attr = attrsStore.getAttr(aid);
|
|
325
|
+
if (!attr) {
|
|
326
|
+
// (XXX): Due to the way we're handling attrs, it's
|
|
327
|
+
// possible to enter a state where we receive a triple without an attr.
|
|
328
|
+
// See: https://github.com/jsventures/instant-local/pull/132 for details.
|
|
329
|
+
// For now, if we receive a command without an attr, we no-op.
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (attr['checked-data-type'] === 'date' && store.useDateObjects) {
|
|
333
|
+
v = coerceToDate(v);
|
|
334
|
+
}
|
|
335
|
+
const existingTriple = getInMap(store.eav, [eid, aid, v]);
|
|
336
|
+
// Reuse the created_at for a triple if it's already in the store.
|
|
337
|
+
// Prevents updates from temporarily pushing an entity to the top
|
|
338
|
+
// while waiting for the server response.
|
|
339
|
+
const t = existingTriple?.[3] ?? getCreatedAt(store, attr, triple);
|
|
340
|
+
const enhancedTriple = [eid, aid, v, t];
|
|
341
|
+
if (hasEA(attr)) {
|
|
342
|
+
setInMap(store.eav, [eid, aid], new Map([[v, enhancedTriple]]));
|
|
343
|
+
setInMap(store.aev, [aid, eid], new Map([[v, enhancedTriple]]));
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
setInMap(store.eav, [eid, aid, v], enhancedTriple);
|
|
347
|
+
setInMap(store.aev, [aid, eid, v], enhancedTriple);
|
|
348
|
+
}
|
|
349
|
+
if (isRef(attr)) {
|
|
350
|
+
setInMap(store.vae, [v, aid, eid], enhancedTriple);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function mergeTriple(store, attrsStore, rawTriple) {
|
|
354
|
+
const triple = resolveLookupRefs(store, rawTriple);
|
|
355
|
+
if (!triple) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const [eid, aid, update] = triple;
|
|
359
|
+
const attr = attrsStore.getAttr(aid);
|
|
360
|
+
if (!attr)
|
|
361
|
+
return;
|
|
362
|
+
if (!isBlob(attr))
|
|
363
|
+
throw new Error('merge operation is not supported for links');
|
|
364
|
+
const eavValuesMap = getInMap(store.eav, [eid, aid]);
|
|
365
|
+
if (!eavValuesMap)
|
|
366
|
+
return;
|
|
367
|
+
const currentTriple = eavValuesMap.values().next()?.value;
|
|
368
|
+
if (!currentTriple)
|
|
369
|
+
return;
|
|
370
|
+
const currentValue = currentTriple[2];
|
|
371
|
+
const updatedValue = immutableDeepMerge(currentValue, update);
|
|
372
|
+
const enhancedTriple = [
|
|
373
|
+
eid,
|
|
374
|
+
aid,
|
|
375
|
+
updatedValue,
|
|
376
|
+
getCreatedAt(store, attr, currentTriple),
|
|
377
|
+
];
|
|
378
|
+
setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
|
|
379
|
+
setInMap(store.aev, [aid, eid], new Map([[updatedValue, enhancedTriple]]));
|
|
380
|
+
}
|
|
381
|
+
function deleteEntity(store, attrsStore, args) {
|
|
382
|
+
const [lookup, etype] = args;
|
|
383
|
+
const triple = resolveLookupRefs(store, [lookup]);
|
|
384
|
+
if (!triple) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const [id] = triple;
|
|
388
|
+
// delete forward links and attributes + cardinality one links
|
|
389
|
+
const eMap = store.eav.get(id);
|
|
390
|
+
if (eMap) {
|
|
391
|
+
for (const a of eMap.keys()) {
|
|
392
|
+
const attr = attrsStore.getAttr(a);
|
|
393
|
+
// delete cascade refs
|
|
394
|
+
if (attr && attr['on-delete-reverse'] === 'cascade') {
|
|
395
|
+
allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => deleteEntity(store, attrsStore, [v, attr['reverse-identity']?.[1]]));
|
|
396
|
+
}
|
|
397
|
+
if (
|
|
398
|
+
// Fall back to deleting everything if we've rehydrated tx-steps from
|
|
399
|
+
// the store that didn't set `etype` in deleteEntity
|
|
400
|
+
!etype ||
|
|
401
|
+
// If we don't know about the attr, let's just get rid of it
|
|
402
|
+
!attr ||
|
|
403
|
+
// Make sure it matches the etype
|
|
404
|
+
attr['forward-identity']?.[1] === etype) {
|
|
405
|
+
deleteInMap(store.aev, [a, id]);
|
|
406
|
+
deleteInMap(store.eav, [id, a]);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// Clear out the eav index for `id` if we deleted all of the attributes
|
|
410
|
+
if (eMap.size === 0) {
|
|
411
|
+
deleteInMap(store.eav, [id]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// delete reverse links
|
|
415
|
+
const vaeTriples = store.vae.get(id) && allMapValues(store.vae.get(id), 2);
|
|
416
|
+
if (vaeTriples) {
|
|
417
|
+
vaeTriples.forEach((triple) => {
|
|
418
|
+
const [e, a, v] = triple;
|
|
419
|
+
const attr = attrsStore.getAttr(a);
|
|
420
|
+
if (!etype || !attr || attr['reverse-identity']?.[1] === etype) {
|
|
421
|
+
deleteInMap(store.eav, [e, a, v]);
|
|
422
|
+
deleteInMap(store.aev, [a, e, v]);
|
|
423
|
+
deleteInMap(store.vae, [v, a, e]);
|
|
424
|
+
}
|
|
425
|
+
if (attr &&
|
|
426
|
+
attr['on-delete'] === 'cascade' &&
|
|
427
|
+
attr['reverse-identity']?.[1] === etype) {
|
|
428
|
+
deleteEntity(store, attrsStore, [e, attr['forward-identity']?.[1]]);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
// Clear out vae index for `id` if we deleted all the reverse attributes
|
|
433
|
+
if (store.vae.get(id)?.size === 0) {
|
|
434
|
+
deleteInMap(store.vae, [id]);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
// (XXX): Whenever we change/delete attrs,
|
|
438
|
+
// We indiscriminately reset the index map.
|
|
439
|
+
// There are lots of opportunities for optimization:
|
|
440
|
+
// * We _only_ need to run this indexes change. We could detect that
|
|
441
|
+
// * We could batch this reset at the end
|
|
442
|
+
// * We could add an ave index for all triples, so removing the
|
|
443
|
+
// right triples is easy and fast.
|
|
444
|
+
function resetIndexMap(store, attrsStore, newTriples) {
|
|
445
|
+
const newIndexMap = createTripleIndexes(attrsStore, newTriples, store.useDateObjects);
|
|
446
|
+
Object.keys(newIndexMap).forEach((key) => {
|
|
447
|
+
store[key] = newIndexMap[key];
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
function addAttr(attrsStore, [attr]) {
|
|
451
|
+
attrsStore.addAttr(attr);
|
|
452
|
+
}
|
|
453
|
+
function getAllTriples(store) {
|
|
454
|
+
return allMapValues(store.eav, 3);
|
|
455
|
+
}
|
|
456
|
+
function deleteAttr(store, attrsStore, [id]) {
|
|
457
|
+
if (!attrsStore.getAttr(id))
|
|
458
|
+
return;
|
|
459
|
+
const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
|
|
460
|
+
attrsStore.deleteAttr(id);
|
|
461
|
+
resetIndexMap(store, attrsStore, newTriples);
|
|
462
|
+
}
|
|
463
|
+
function updateAttr(store, attrsStore, [partialAttr]) {
|
|
464
|
+
const attr = attrsStore.getAttr(partialAttr.id);
|
|
465
|
+
if (!attr)
|
|
466
|
+
return;
|
|
467
|
+
attrsStore.updateAttr(partialAttr);
|
|
468
|
+
resetIndexMap(store, attrsStore, getAllTriples(store));
|
|
469
|
+
}
|
|
470
|
+
function applyTxStep(store, attrsStore, txStep) {
|
|
471
|
+
const [action, ...args] = txStep;
|
|
472
|
+
switch (action) {
|
|
473
|
+
case 'add-triple':
|
|
474
|
+
addTriple(store, attrsStore, args);
|
|
475
|
+
break;
|
|
476
|
+
case 'deep-merge-triple':
|
|
477
|
+
mergeTriple(store, attrsStore, args);
|
|
478
|
+
break;
|
|
479
|
+
case 'retract-triple':
|
|
480
|
+
retractTriple(store, attrsStore, args);
|
|
481
|
+
break;
|
|
482
|
+
case 'delete-entity':
|
|
483
|
+
deleteEntity(store, attrsStore, args);
|
|
484
|
+
break;
|
|
485
|
+
case 'add-attr':
|
|
486
|
+
addAttr(attrsStore, args);
|
|
487
|
+
break;
|
|
488
|
+
case 'delete-attr':
|
|
489
|
+
deleteAttr(store, attrsStore, args);
|
|
490
|
+
break;
|
|
491
|
+
case 'update-attr':
|
|
492
|
+
updateAttr(store, attrsStore, args);
|
|
493
|
+
break;
|
|
494
|
+
case 'restore-attr':
|
|
495
|
+
break;
|
|
496
|
+
case 'rule-params':
|
|
497
|
+
break;
|
|
498
|
+
default:
|
|
499
|
+
throw new Error(`unhandled transaction action: ${action}`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
export function allMapValues(m, level, res = []) {
|
|
503
|
+
if (!m) {
|
|
504
|
+
return res;
|
|
505
|
+
}
|
|
506
|
+
if (level === 0) {
|
|
507
|
+
return res;
|
|
508
|
+
}
|
|
509
|
+
if (level === 1) {
|
|
510
|
+
for (const v of m.values()) {
|
|
511
|
+
res.push(v);
|
|
512
|
+
}
|
|
513
|
+
return res;
|
|
514
|
+
}
|
|
515
|
+
for (const v of m.values()) {
|
|
516
|
+
allMapValues(v, level - 1, res);
|
|
517
|
+
}
|
|
518
|
+
return res;
|
|
519
|
+
}
|
|
520
|
+
function triplesByValue(store, m, v) {
|
|
521
|
+
const res = [];
|
|
522
|
+
if (v?.hasOwnProperty('$not')) {
|
|
523
|
+
for (const candidate of m.keys()) {
|
|
524
|
+
if (v.$not !== candidate) {
|
|
525
|
+
res.push(m.get(candidate));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return res;
|
|
529
|
+
}
|
|
530
|
+
if (v?.hasOwnProperty('$isNull')) {
|
|
531
|
+
const { attrId, isNull, reverse } = v.$isNull;
|
|
532
|
+
if (reverse) {
|
|
533
|
+
for (const candidate of m.keys()) {
|
|
534
|
+
const vMap = store.vae.get(candidate);
|
|
535
|
+
const isValNull = !vMap || !vMap.get(attrId);
|
|
536
|
+
if (isNull ? isValNull : !isValNull) {
|
|
537
|
+
res.push(m.get(candidate));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
const aMap = store.aev.get(attrId);
|
|
543
|
+
for (const candidate of m.keys()) {
|
|
544
|
+
const isValNull = !aMap || aMap.get(candidate)?.get(null) || !aMap.get(candidate);
|
|
545
|
+
if (isNull ? isValNull : !isValNull) {
|
|
546
|
+
res.push(m.get(candidate));
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return res;
|
|
551
|
+
}
|
|
552
|
+
if (v?.$comparator) {
|
|
553
|
+
// TODO: A sorted index would be nice here
|
|
554
|
+
return allMapValues(m, 1).filter(v.$op);
|
|
555
|
+
}
|
|
556
|
+
const values = v.in || v.$in || [v];
|
|
557
|
+
for (const value of values) {
|
|
558
|
+
const triple = m.get(value);
|
|
559
|
+
if (triple) {
|
|
560
|
+
res.push(triple);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return res;
|
|
564
|
+
}
|
|
565
|
+
// A poor man's pattern matching
|
|
566
|
+
// Returns either eav, ea, ev, av, v, or ''
|
|
567
|
+
function whichIdx(e, a, v) {
|
|
568
|
+
let res = '';
|
|
569
|
+
if (e !== undefined) {
|
|
570
|
+
res += 'e';
|
|
571
|
+
}
|
|
572
|
+
if (a !== undefined) {
|
|
573
|
+
res += 'a';
|
|
574
|
+
}
|
|
575
|
+
if (v !== undefined) {
|
|
576
|
+
res += 'v';
|
|
577
|
+
}
|
|
578
|
+
return res;
|
|
579
|
+
}
|
|
580
|
+
export function getTriples(store, [e, a, v]) {
|
|
581
|
+
const idx = whichIdx(e, a, v);
|
|
582
|
+
switch (idx) {
|
|
583
|
+
case 'e': {
|
|
584
|
+
const eMap = store.eav.get(e);
|
|
585
|
+
return allMapValues(eMap, 2);
|
|
586
|
+
}
|
|
587
|
+
case 'ea': {
|
|
588
|
+
const aMap = store.eav.get(e)?.get(a);
|
|
589
|
+
return allMapValues(aMap, 1);
|
|
590
|
+
}
|
|
591
|
+
case 'eav': {
|
|
592
|
+
const aMap = store.eav.get(e)?.get(a);
|
|
593
|
+
if (!aMap) {
|
|
594
|
+
return [];
|
|
595
|
+
}
|
|
596
|
+
return triplesByValue(store, aMap, v);
|
|
597
|
+
}
|
|
598
|
+
case 'ev': {
|
|
599
|
+
const eMap = store.eav.get(e);
|
|
600
|
+
if (!eMap) {
|
|
601
|
+
return [];
|
|
602
|
+
}
|
|
603
|
+
const res = [];
|
|
604
|
+
for (const aMap of eMap.values()) {
|
|
605
|
+
res.push(...triplesByValue(store, aMap, v));
|
|
606
|
+
}
|
|
607
|
+
return res;
|
|
608
|
+
}
|
|
609
|
+
case 'a': {
|
|
610
|
+
const aMap = store.aev.get(a);
|
|
611
|
+
return allMapValues(aMap, 2);
|
|
612
|
+
}
|
|
613
|
+
case 'av': {
|
|
614
|
+
const aMap = store.aev.get(a);
|
|
615
|
+
if (!aMap) {
|
|
616
|
+
return [];
|
|
617
|
+
}
|
|
618
|
+
const res = [];
|
|
619
|
+
for (const eMap of aMap.values()) {
|
|
620
|
+
res.push(...triplesByValue(store, eMap, v));
|
|
621
|
+
}
|
|
622
|
+
return res;
|
|
623
|
+
}
|
|
624
|
+
case 'v': {
|
|
625
|
+
const res = [];
|
|
626
|
+
for (const eMap of store.eav.values()) {
|
|
627
|
+
for (const aMap of eMap.values()) {
|
|
628
|
+
res.push(...triplesByValue(store, aMap, v));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return res;
|
|
632
|
+
}
|
|
633
|
+
default: {
|
|
634
|
+
return allMapValues(store.eav, 3);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
export function getAsObject(store, attrs, e) {
|
|
639
|
+
const obj = {};
|
|
640
|
+
if (!attrs) {
|
|
641
|
+
return obj;
|
|
642
|
+
}
|
|
643
|
+
for (const [label, attr] of attrs.entries()) {
|
|
644
|
+
const aMap = store.eav.get(e)?.get(attr.id);
|
|
645
|
+
const triples = allMapValues(aMap, 1);
|
|
646
|
+
for (const triple of triples) {
|
|
647
|
+
obj[label] = triple[2];
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return obj;
|
|
651
|
+
}
|
|
652
|
+
export function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
|
|
653
|
+
return attrsStore.forwardIdents.get(inputEtype)?.get(inputLabel);
|
|
654
|
+
}
|
|
655
|
+
export function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
|
|
656
|
+
return attrsStore.revIdents.get(inputEtype)?.get(inputLabel);
|
|
657
|
+
}
|
|
658
|
+
export function getBlobAttrs(attrsStore, etype) {
|
|
659
|
+
return attrsStore.blobAttrs.get(etype);
|
|
660
|
+
}
|
|
661
|
+
export function getPrimaryKeyAttr(attrsStore, etype) {
|
|
662
|
+
const fromPrimary = attrsStore.primaryKeys.get(etype);
|
|
663
|
+
if (fromPrimary) {
|
|
664
|
+
return fromPrimary;
|
|
665
|
+
}
|
|
666
|
+
return attrsStore.forwardIdents.get(etype)?.get('id');
|
|
667
|
+
}
|
|
668
|
+
function findTriple(store, attrsStore, rawTriple) {
|
|
669
|
+
const triple = resolveLookupRefs(store, rawTriple);
|
|
670
|
+
if (!triple) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
const [eid, aid, v] = triple;
|
|
674
|
+
const attr = attrsStore.getAttr(aid);
|
|
675
|
+
if (!attr) {
|
|
676
|
+
// (XXX): Due to the way we're handling attrs, it's
|
|
677
|
+
// possible to enter a state where we receive a triple without an attr.
|
|
678
|
+
// See: https://github.com/jsventures/instant-local/pull/132 for details.
|
|
679
|
+
// For now, if we receive a command without an attr, we no-op.
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
return getInMap(store.eav, [eid, aid]);
|
|
683
|
+
}
|
|
684
|
+
export function transact(store, attrsStore, txSteps) {
|
|
685
|
+
const txStepsFiltered = txSteps.filter(([action, eid, attrId, value, opts]) => {
|
|
686
|
+
if (action !== 'add-triple' && action !== 'deep-merge-triple') {
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
const mode = opts?.mode;
|
|
690
|
+
if (mode !== 'create' && mode !== 'update') {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
let exists = false;
|
|
694
|
+
const attr = attrsStore.getAttr(attrId);
|
|
695
|
+
if (attr) {
|
|
696
|
+
const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
|
|
697
|
+
exists = !!findTriple(store, attrsStore, [
|
|
698
|
+
eid,
|
|
699
|
+
idAttr?.id,
|
|
700
|
+
eid,
|
|
701
|
+
]);
|
|
702
|
+
}
|
|
703
|
+
if (mode === 'create' && exists) {
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
if (mode === 'update' && !exists) {
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
return true;
|
|
710
|
+
});
|
|
711
|
+
return create({ store, attrsStore }, (draft) => {
|
|
712
|
+
txStepsFiltered.forEach((txStep) => {
|
|
713
|
+
applyTxStep(draft.store, draft.attrsStore, txStep);
|
|
714
|
+
});
|
|
715
|
+
}, {
|
|
716
|
+
mark: (target) => {
|
|
717
|
+
if (target instanceof AttrsStoreClass) {
|
|
718
|
+
return 'immutable';
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
});
|
|
722
|
+
}
|