@sidekickdb/core 0.0.0 → 2.0.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/.tshy/build.json +8 -0
- package/.tshy/commonjs.json +16 -0
- package/.tshy/esm.json +15 -0
- package/LICENSE.md +202 -0
- package/NOTICE +27 -0
- package/README.md +25 -2
- package/__example__/standalone.esm.html +23 -0
- package/__example__/standalone.umd.html +21 -0
- package/__tests__/src/Reactor.test.ts +480 -0
- package/__tests__/src/auth-extra-fields.e2e.test.ts +160 -0
- package/__tests__/src/cookieSync.e2e.test.ts +165 -0
- package/__tests__/src/data/movies/attrs.json +145 -0
- package/__tests__/src/data/movies/triples.json +1507 -0
- package/__tests__/src/data/zeneca/attrs.json +251 -0
- package/__tests__/src/data/zeneca/triples.json +15854 -0
- package/__tests__/src/dataForQueryMemo.test.ts +136 -0
- package/__tests__/src/datalog.test.ts +175 -0
- package/__tests__/src/devtool.test.ts +48 -0
- package/__tests__/src/endpoints.test.ts +228 -0
- package/__tests__/src/infiniteQuery.e2e.test.ts +454 -0
- package/__tests__/src/instaml.test.ts +1593 -0
- package/__tests__/src/instaql.bench.ts +34 -0
- package/__tests__/src/instaql.test.ts +1388 -0
- package/__tests__/src/instaqlInference.test.ts +243 -0
- package/__tests__/src/notifyScope.test.ts +1145 -0
- package/__tests__/src/queryValidation.test.ts +1033 -0
- package/__tests__/src/schema.test.ts +641 -0
- package/__tests__/src/serializeSchema.test.ts +123 -0
- package/__tests__/src/simple.e2e.test.ts +10 -0
- package/__tests__/src/storageUpload.test.ts +70 -0
- package/__tests__/src/store.test.ts +718 -0
- package/__tests__/src/transactionValidation.test.ts +450 -0
- package/__tests__/src/typeUtils.ts +39 -0
- package/__tests__/src/utils/PersistedObject.test.ts +529 -0
- package/__tests__/src/utils/dates.test.ts +82 -0
- package/__tests__/src/utils/e2e.ts +95 -0
- package/__tests__/src/utils/msw.ts +3 -0
- package/__tests__/src/utils/object.test.ts +78 -0
- package/__tests__/src/utils/weakHash.test.ts +68 -0
- package/__tests__/src/utils/weakHashLegacy.test.ts +22 -0
- package/__tests__/src/vite.env.d.ts +1 -0
- package/dist/commonjs/Connection.d.ts +93 -0
- package/dist/commonjs/Connection.d.ts.map +1 -0
- package/dist/commonjs/Connection.js +194 -0
- package/dist/commonjs/Connection.js.map +1 -0
- package/dist/commonjs/InMemoryStorage.d.ts +11 -0
- package/dist/commonjs/InMemoryStorage.d.ts.map +1 -0
- package/dist/commonjs/InMemoryStorage.js +29 -0
- package/dist/commonjs/InMemoryStorage.js.map +1 -0
- package/dist/commonjs/IndexedDBStorage.d.ts +18 -0
- package/dist/commonjs/IndexedDBStorage.d.ts.map +1 -0
- package/dist/commonjs/IndexedDBStorage.js +341 -0
- package/dist/commonjs/IndexedDBStorage.js.map +1 -0
- package/dist/commonjs/InstantError.d.ts +7 -0
- package/dist/commonjs/InstantError.d.ts.map +1 -0
- package/dist/commonjs/InstantError.js +28 -0
- package/dist/commonjs/InstantError.js.map +1 -0
- package/dist/commonjs/Reactor.d.ts +445 -0
- package/dist/commonjs/Reactor.d.ts.map +1 -0
- package/dist/commonjs/Reactor.js +2471 -0
- package/dist/commonjs/Reactor.js.map +1 -0
- package/dist/commonjs/StorageAPI.d.ts +40 -0
- package/dist/commonjs/StorageAPI.d.ts.map +1 -0
- package/dist/commonjs/StorageAPI.js +82 -0
- package/dist/commonjs/StorageAPI.js.map +1 -0
- package/dist/commonjs/Stream.d.ts +121 -0
- package/dist/commonjs/Stream.d.ts.map +1 -0
- package/dist/commonjs/Stream.js +819 -0
- package/dist/commonjs/Stream.js.map +1 -0
- package/dist/commonjs/SyncTable.d.ts +145 -0
- package/dist/commonjs/SyncTable.d.ts.map +1 -0
- package/dist/commonjs/SyncTable.js +564 -0
- package/dist/commonjs/SyncTable.js.map +1 -0
- package/dist/commonjs/WindowNetworkListener.d.ts +5 -0
- package/dist/commonjs/WindowNetworkListener.d.ts.map +1 -0
- package/dist/commonjs/WindowNetworkListener.js +23 -0
- package/dist/commonjs/WindowNetworkListener.js.map +1 -0
- package/dist/commonjs/__types__/fieldsTypeTest.d.ts +2 -0
- package/dist/commonjs/__types__/fieldsTypeTest.d.ts.map +1 -0
- package/dist/commonjs/__types__/fieldsTypeTest.js +68 -0
- package/dist/commonjs/__types__/fieldsTypeTest.js.map +1 -0
- package/dist/commonjs/__types__/typeUtils.d.ts +20 -0
- package/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
- package/dist/commonjs/__types__/typeUtils.js +5 -0
- package/dist/commonjs/__types__/typeUtils.js.map +1 -0
- package/dist/commonjs/__types__/useDatesTypeTest.d.ts +2 -0
- package/dist/commonjs/__types__/useDatesTypeTest.d.ts.map +1 -0
- package/dist/commonjs/__types__/useDatesTypeTest.js +55 -0
- package/dist/commonjs/__types__/useDatesTypeTest.js.map +1 -0
- package/dist/commonjs/attrTypes.d.ts +26 -0
- package/dist/commonjs/attrTypes.d.ts.map +1 -0
- package/dist/commonjs/attrTypes.js +3 -0
- package/dist/commonjs/attrTypes.js.map +1 -0
- package/dist/commonjs/authAPI.d.ts +65 -0
- package/dist/commonjs/authAPI.d.ts.map +1 -0
- package/dist/commonjs/authAPI.js +114 -0
- package/dist/commonjs/authAPI.js.map +1 -0
- package/dist/commonjs/clientTypes.d.ts +41 -0
- package/dist/commonjs/clientTypes.d.ts.map +1 -0
- package/dist/commonjs/clientTypes.js +3 -0
- package/dist/commonjs/clientTypes.js.map +1 -0
- package/dist/commonjs/coreTypes.d.ts +34 -0
- package/dist/commonjs/coreTypes.d.ts.map +1 -0
- package/dist/commonjs/coreTypes.js +3 -0
- package/dist/commonjs/coreTypes.js.map +1 -0
- package/dist/commonjs/createRouteHandler.d.ts +8 -0
- package/dist/commonjs/createRouteHandler.d.ts.map +1 -0
- package/dist/commonjs/createRouteHandler.js +56 -0
- package/dist/commonjs/createRouteHandler.js.map +1 -0
- package/dist/commonjs/datalog.d.ts +8 -0
- package/dist/commonjs/datalog.d.ts.map +1 -0
- package/dist/commonjs/datalog.js +106 -0
- package/dist/commonjs/datalog.js.map +1 -0
- package/dist/commonjs/devtool.d.ts +4 -0
- package/dist/commonjs/devtool.d.ts.map +1 -0
- package/dist/commonjs/devtool.js +191 -0
- package/dist/commonjs/devtool.js.map +1 -0
- package/dist/commonjs/endpoints.d.ts +35 -0
- package/dist/commonjs/endpoints.d.ts.map +1 -0
- package/dist/commonjs/endpoints.js +80 -0
- package/dist/commonjs/endpoints.js.map +1 -0
- package/dist/commonjs/framework.d.ts +81 -0
- package/dist/commonjs/framework.d.ts.map +1 -0
- package/dist/commonjs/framework.js +284 -0
- package/dist/commonjs/framework.js.map +1 -0
- package/dist/commonjs/helperTypes.d.ts +76 -0
- package/dist/commonjs/helperTypes.d.ts.map +1 -0
- package/dist/commonjs/helperTypes.js +3 -0
- package/dist/commonjs/helperTypes.js.map +1 -0
- package/dist/commonjs/index.d.ts +614 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +677 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/infiniteQuery.d.ts +26 -0
- package/dist/commonjs/infiniteQuery.d.ts.map +1 -0
- package/dist/commonjs/infiniteQuery.js +438 -0
- package/dist/commonjs/infiniteQuery.js.map +1 -0
- package/dist/commonjs/instaml.d.ts +18 -0
- package/dist/commonjs/instaml.d.ts.map +1 -0
- package/dist/commonjs/instaml.js +584 -0
- package/dist/commonjs/instaml.js.map +1 -0
- package/dist/commonjs/instaql.d.ts +13 -0
- package/dist/commonjs/instaql.d.ts.map +1 -0
- package/dist/commonjs/instaql.js +670 -0
- package/dist/commonjs/instaql.js.map +1 -0
- package/dist/commonjs/instatx.d.ts +128 -0
- package/dist/commonjs/instatx.d.ts.map +1 -0
- package/dist/commonjs/instatx.js +102 -0
- package/dist/commonjs/instatx.js.map +1 -0
- package/dist/commonjs/model/instaqlResult.d.ts +8 -0
- package/dist/commonjs/model/instaqlResult.d.ts.map +1 -0
- package/dist/commonjs/model/instaqlResult.js +28 -0
- package/dist/commonjs/model/instaqlResult.js.map +1 -0
- package/dist/commonjs/notifyScope.d.ts +32 -0
- package/dist/commonjs/notifyScope.d.ts.map +1 -0
- package/dist/commonjs/notifyScope.js +306 -0
- package/dist/commonjs/notifyScope.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/parseSchemaFromJSON.d.ts +3 -0
- package/dist/commonjs/parseSchemaFromJSON.d.ts.map +1 -0
- package/dist/commonjs/parseSchemaFromJSON.js +147 -0
- package/dist/commonjs/parseSchemaFromJSON.js.map +1 -0
- package/dist/commonjs/presence.d.ts +51 -0
- package/dist/commonjs/presence.d.ts.map +1 -0
- package/dist/commonjs/presence.js +55 -0
- package/dist/commonjs/presence.js.map +1 -0
- package/dist/commonjs/presenceTypes.d.ts +10 -0
- package/dist/commonjs/presenceTypes.d.ts.map +1 -0
- package/dist/commonjs/presenceTypes.js +5 -0
- package/dist/commonjs/presenceTypes.js.map +1 -0
- package/dist/commonjs/queryTypes.d.ts +272 -0
- package/dist/commonjs/queryTypes.d.ts.map +1 -0
- package/dist/commonjs/queryTypes.js +5 -0
- package/dist/commonjs/queryTypes.js.map +1 -0
- package/dist/commonjs/queryValidation.d.ts +6 -0
- package/dist/commonjs/queryValidation.d.ts.map +1 -0
- package/dist/commonjs/queryValidation.js +293 -0
- package/dist/commonjs/queryValidation.js.map +1 -0
- package/dist/commonjs/reactorTypes.d.ts +30 -0
- package/dist/commonjs/reactorTypes.d.ts.map +1 -0
- package/dist/commonjs/reactorTypes.js +3 -0
- package/dist/commonjs/reactorTypes.js.map +1 -0
- package/dist/commonjs/routeHandlerProtocol.d.ts +20 -0
- package/dist/commonjs/routeHandlerProtocol.d.ts.map +1 -0
- package/dist/commonjs/routeHandlerProtocol.js +3 -0
- package/dist/commonjs/routeHandlerProtocol.js.map +1 -0
- package/dist/commonjs/rulesTypes.d.ts +86 -0
- package/dist/commonjs/rulesTypes.d.ts.map +1 -0
- package/dist/commonjs/rulesTypes.js +3 -0
- package/dist/commonjs/rulesTypes.js.map +1 -0
- package/dist/commonjs/sanityCheckQueries.d.ts +19 -0
- package/dist/commonjs/sanityCheckQueries.d.ts.map +1 -0
- package/dist/commonjs/sanityCheckQueries.js +156 -0
- package/dist/commonjs/sanityCheckQueries.js.map +1 -0
- package/dist/commonjs/schema.d.ts +73 -0
- package/dist/commonjs/schema.d.ts.map +1 -0
- package/dist/commonjs/schema.js +132 -0
- package/dist/commonjs/schema.js.map +1 -0
- package/dist/commonjs/schemaTypes.d.ts +245 -0
- package/dist/commonjs/schemaTypes.d.ts.map +1 -0
- package/dist/commonjs/schemaTypes.js +116 -0
- package/dist/commonjs/schemaTypes.js.map +1 -0
- package/dist/commonjs/store.d.ts +90 -0
- package/dist/commonjs/store.d.ts.map +1 -0
- package/dist/commonjs/store.js +745 -0
- package/dist/commonjs/store.js.map +1 -0
- package/dist/commonjs/transactionValidation.d.ts +8 -0
- package/dist/commonjs/transactionValidation.d.ts.map +1 -0
- package/dist/commonjs/transactionValidation.js +137 -0
- package/dist/commonjs/transactionValidation.js.map +1 -0
- package/dist/commonjs/utils/Deferred.d.ts +9 -0
- package/dist/commonjs/utils/Deferred.d.ts.map +1 -0
- package/dist/commonjs/utils/Deferred.js +22 -0
- package/dist/commonjs/utils/Deferred.js.map +1 -0
- package/dist/commonjs/utils/PersistedObject.d.ts +81 -0
- package/dist/commonjs/utils/PersistedObject.d.ts.map +1 -0
- package/dist/commonjs/utils/PersistedObject.js +469 -0
- package/dist/commonjs/utils/PersistedObject.js.map +1 -0
- package/dist/commonjs/utils/dates.d.ts +2 -0
- package/dist/commonjs/utils/dates.d.ts.map +1 -0
- package/dist/commonjs/utils/dates.js +215 -0
- package/dist/commonjs/utils/dates.js.map +1 -0
- package/dist/commonjs/utils/error.d.ts +3 -0
- package/dist/commonjs/utils/error.d.ts.map +1 -0
- package/dist/commonjs/utils/error.js +13 -0
- package/dist/commonjs/utils/error.js.map +1 -0
- package/dist/commonjs/utils/fetch.d.ts +126 -0
- package/dist/commonjs/utils/fetch.d.ts.map +1 -0
- package/dist/commonjs/utils/fetch.js +37 -0
- package/dist/commonjs/utils/fetch.js.map +1 -0
- package/dist/commonjs/utils/flags.d.ts +5 -0
- package/dist/commonjs/utils/flags.d.ts.map +1 -0
- package/dist/commonjs/utils/flags.js +16 -0
- package/dist/commonjs/utils/flags.js.map +1 -0
- package/dist/commonjs/utils/id.d.ts +4 -0
- package/dist/commonjs/utils/id.d.ts.map +1 -0
- package/dist/commonjs/utils/id.js +29 -0
- package/dist/commonjs/utils/id.js.map +1 -0
- package/dist/commonjs/utils/linkIndex.d.ts +8 -0
- package/dist/commonjs/utils/linkIndex.d.ts.map +1 -0
- package/dist/commonjs/utils/linkIndex.js +21 -0
- package/dist/commonjs/utils/linkIndex.js.map +1 -0
- package/dist/commonjs/utils/log.d.ts +7 -0
- package/dist/commonjs/utils/log.d.ts.map +1 -0
- package/dist/commonjs/utils/log.js +17 -0
- package/dist/commonjs/utils/log.js.map +1 -0
- package/dist/commonjs/utils/object.d.ts +17 -0
- package/dist/commonjs/utils/object.d.ts.map +1 -0
- package/dist/commonjs/utils/object.js +157 -0
- package/dist/commonjs/utils/object.js.map +1 -0
- package/dist/commonjs/utils/pgtime.d.ts +198 -0
- package/dist/commonjs/utils/pgtime.d.ts.map +1 -0
- package/dist/commonjs/utils/pgtime.js +201 -0
- package/dist/commonjs/utils/pgtime.js.map +1 -0
- package/dist/commonjs/utils/pick.d.ts +2 -0
- package/dist/commonjs/utils/pick.d.ts.map +1 -0
- package/dist/commonjs/utils/pick.js +13 -0
- package/dist/commonjs/utils/pick.js.map +1 -0
- package/dist/commonjs/utils/strings.d.ts +2 -0
- package/dist/commonjs/utils/strings.d.ts.map +1 -0
- package/dist/commonjs/utils/strings.js +19 -0
- package/dist/commonjs/utils/strings.js.map +1 -0
- package/dist/commonjs/utils/weakHash.d.ts +16 -0
- package/dist/commonjs/utils/weakHash.d.ts.map +1 -0
- package/dist/commonjs/utils/weakHash.js +75 -0
- package/dist/commonjs/utils/weakHash.js.map +1 -0
- package/dist/commonjs/utils/weakHashLegacy.d.ts +8 -0
- package/dist/commonjs/utils/weakHashLegacy.d.ts.map +1 -0
- package/dist/commonjs/utils/weakHashLegacy.js +76 -0
- package/dist/commonjs/utils/weakHashLegacy.js.map +1 -0
- package/dist/commonjs/version.d.ts +3 -0
- package/dist/commonjs/version.d.ts.map +1 -0
- package/dist/commonjs/version.js +5 -0
- package/dist/commonjs/version.js.map +1 -0
- package/dist/commonjs/warningToggle.d.ts +3 -0
- package/dist/commonjs/warningToggle.d.ts.map +1 -0
- package/dist/commonjs/warningToggle.js +9 -0
- package/dist/commonjs/warningToggle.js.map +1 -0
- package/dist/esm/Connection.d.ts +93 -0
- package/dist/esm/Connection.d.ts.map +1 -0
- package/dist/esm/Connection.js +189 -0
- package/dist/esm/Connection.js.map +1 -0
- package/dist/esm/InMemoryStorage.d.ts +11 -0
- package/dist/esm/InMemoryStorage.d.ts.map +1 -0
- package/dist/esm/InMemoryStorage.js +26 -0
- package/dist/esm/InMemoryStorage.js.map +1 -0
- package/dist/esm/IndexedDBStorage.d.ts +18 -0
- package/dist/esm/IndexedDBStorage.d.ts.map +1 -0
- package/dist/esm/IndexedDBStorage.js +338 -0
- package/dist/esm/IndexedDBStorage.js.map +1 -0
- package/dist/esm/InstantError.d.ts +7 -0
- package/dist/esm/InstantError.d.ts.map +1 -0
- package/dist/esm/InstantError.js +24 -0
- package/dist/esm/InstantError.js.map +1 -0
- package/dist/esm/Reactor.d.ts +445 -0
- package/dist/esm/Reactor.d.ts.map +1 -0
- package/dist/esm/Reactor.js +2431 -0
- package/dist/esm/Reactor.js.map +1 -0
- package/dist/esm/StorageAPI.d.ts +40 -0
- package/dist/esm/StorageAPI.d.ts.map +1 -0
- package/dist/esm/StorageAPI.js +75 -0
- package/dist/esm/StorageAPI.js.map +1 -0
- package/dist/esm/Stream.d.ts +121 -0
- package/dist/esm/Stream.d.ts.map +1 -0
- package/dist/esm/Stream.js +812 -0
- package/dist/esm/Stream.js.map +1 -0
- package/dist/esm/SyncTable.d.ts +145 -0
- package/dist/esm/SyncTable.d.ts.map +1 -0
- package/dist/esm/SyncTable.js +524 -0
- package/dist/esm/SyncTable.js.map +1 -0
- package/dist/esm/WindowNetworkListener.d.ts +5 -0
- package/dist/esm/WindowNetworkListener.d.ts.map +1 -0
- package/dist/esm/WindowNetworkListener.js +20 -0
- package/dist/esm/WindowNetworkListener.js.map +1 -0
- package/dist/esm/__types__/fieldsTypeTest.d.ts +2 -0
- package/dist/esm/__types__/fieldsTypeTest.d.ts.map +1 -0
- package/dist/esm/__types__/fieldsTypeTest.js +66 -0
- package/dist/esm/__types__/fieldsTypeTest.js.map +1 -0
- package/dist/esm/__types__/typeUtils.d.ts +20 -0
- package/dist/esm/__types__/typeUtils.d.ts.map +1 -0
- package/dist/esm/__types__/typeUtils.js +4 -0
- package/dist/esm/__types__/typeUtils.js.map +1 -0
- package/dist/esm/__types__/useDatesTypeTest.d.ts +2 -0
- package/dist/esm/__types__/useDatesTypeTest.d.ts.map +1 -0
- package/dist/esm/__types__/useDatesTypeTest.js +53 -0
- package/dist/esm/__types__/useDatesTypeTest.js.map +1 -0
- package/dist/esm/attrTypes.d.ts +26 -0
- package/dist/esm/attrTypes.d.ts.map +1 -0
- package/dist/esm/attrTypes.js +2 -0
- package/dist/esm/attrTypes.js.map +1 -0
- package/dist/esm/authAPI.d.ts +65 -0
- package/dist/esm/authAPI.d.ts.map +1 -0
- package/dist/esm/authAPI.js +104 -0
- package/dist/esm/authAPI.js.map +1 -0
- package/dist/esm/clientTypes.d.ts +41 -0
- package/dist/esm/clientTypes.d.ts.map +1 -0
- package/dist/esm/clientTypes.js +2 -0
- package/dist/esm/clientTypes.js.map +1 -0
- package/dist/esm/coreTypes.d.ts +34 -0
- package/dist/esm/coreTypes.d.ts.map +1 -0
- package/dist/esm/coreTypes.js +2 -0
- package/dist/esm/coreTypes.js.map +1 -0
- package/dist/esm/createRouteHandler.d.ts +8 -0
- package/dist/esm/createRouteHandler.d.ts.map +1 -0
- package/dist/esm/createRouteHandler.js +52 -0
- package/dist/esm/createRouteHandler.js.map +1 -0
- package/dist/esm/datalog.d.ts +8 -0
- package/dist/esm/datalog.d.ts.map +1 -0
- package/dist/esm/datalog.js +100 -0
- package/dist/esm/datalog.js.map +1 -0
- package/dist/esm/devtool.d.ts +4 -0
- package/dist/esm/devtool.d.ts.map +1 -0
- package/dist/esm/devtool.js +154 -0
- package/dist/esm/devtool.js.map +1 -0
- package/dist/esm/endpoints.d.ts +35 -0
- package/dist/esm/endpoints.d.ts.map +1 -0
- package/dist/esm/endpoints.js +73 -0
- package/dist/esm/endpoints.js.map +1 -0
- package/dist/esm/framework.d.ts +81 -0
- package/dist/esm/framework.d.ts.map +1 -0
- package/dist/esm/framework.js +244 -0
- package/dist/esm/framework.js.map +1 -0
- package/dist/esm/helperTypes.d.ts +76 -0
- package/dist/esm/helperTypes.d.ts.map +1 -0
- package/dist/esm/helperTypes.js +2 -0
- package/dist/esm/helperTypes.js.map +1 -0
- package/dist/esm/index.d.ts +614 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +655 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/infiniteQuery.d.ts +26 -0
- package/dist/esm/infiniteQuery.d.ts.map +1 -0
- package/dist/esm/infiniteQuery.js +433 -0
- package/dist/esm/infiniteQuery.js.map +1 -0
- package/dist/esm/instaml.d.ts +18 -0
- package/dist/esm/instaml.d.ts.map +1 -0
- package/dist/esm/instaml.js +577 -0
- package/dist/esm/instaml.js.map +1 -0
- package/dist/esm/instaql.d.ts +13 -0
- package/dist/esm/instaql.d.ts.map +1 -0
- package/dist/esm/instaql.js +633 -0
- package/dist/esm/instaql.js.map +1 -0
- package/dist/esm/instatx.d.ts +128 -0
- package/dist/esm/instatx.d.ts.map +1 -0
- package/dist/esm/instatx.js +94 -0
- package/dist/esm/instatx.js.map +1 -0
- package/dist/esm/model/instaqlResult.d.ts +8 -0
- package/dist/esm/model/instaqlResult.d.ts.map +1 -0
- package/dist/esm/model/instaqlResult.js +25 -0
- package/dist/esm/model/instaqlResult.js.map +1 -0
- package/dist/esm/notifyScope.d.ts +32 -0
- package/dist/esm/notifyScope.d.ts.map +1 -0
- package/dist/esm/notifyScope.js +300 -0
- package/dist/esm/notifyScope.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parseSchemaFromJSON.d.ts +3 -0
- package/dist/esm/parseSchemaFromJSON.d.ts.map +1 -0
- package/dist/esm/parseSchemaFromJSON.js +143 -0
- package/dist/esm/parseSchemaFromJSON.js.map +1 -0
- package/dist/esm/presence.d.ts +51 -0
- package/dist/esm/presence.d.ts.map +1 -0
- package/dist/esm/presence.js +51 -0
- package/dist/esm/presence.js.map +1 -0
- package/dist/esm/presenceTypes.d.ts +10 -0
- package/dist/esm/presenceTypes.d.ts.map +1 -0
- package/dist/esm/presenceTypes.js +4 -0
- package/dist/esm/presenceTypes.js.map +1 -0
- package/dist/esm/queryTypes.d.ts +272 -0
- package/dist/esm/queryTypes.d.ts.map +1 -0
- package/dist/esm/queryTypes.js +4 -0
- package/dist/esm/queryTypes.js.map +1 -0
- package/dist/esm/queryValidation.d.ts +6 -0
- package/dist/esm/queryValidation.d.ts.map +1 -0
- package/dist/esm/queryValidation.js +288 -0
- package/dist/esm/queryValidation.js.map +1 -0
- package/dist/esm/reactorTypes.d.ts +30 -0
- package/dist/esm/reactorTypes.d.ts.map +1 -0
- package/dist/esm/reactorTypes.js +2 -0
- package/dist/esm/reactorTypes.js.map +1 -0
- package/dist/esm/routeHandlerProtocol.d.ts +20 -0
- package/dist/esm/routeHandlerProtocol.d.ts.map +1 -0
- package/dist/esm/routeHandlerProtocol.js +2 -0
- package/dist/esm/routeHandlerProtocol.js.map +1 -0
- package/dist/esm/rulesTypes.d.ts +86 -0
- package/dist/esm/rulesTypes.d.ts.map +1 -0
- package/dist/esm/rulesTypes.js +2 -0
- package/dist/esm/rulesTypes.js.map +1 -0
- package/dist/esm/sanityCheckQueries.d.ts +19 -0
- package/dist/esm/sanityCheckQueries.d.ts.map +1 -0
- package/dist/esm/sanityCheckQueries.js +153 -0
- package/dist/esm/sanityCheckQueries.js.map +1 -0
- package/dist/esm/schema.d.ts +73 -0
- package/dist/esm/schema.d.ts.map +1 -0
- package/dist/esm/schema.js +129 -0
- package/dist/esm/schema.js.map +1 -0
- package/dist/esm/schemaTypes.d.ts +245 -0
- package/dist/esm/schemaTypes.d.ts.map +1 -0
- package/dist/esm/schemaTypes.js +107 -0
- package/dist/esm/schemaTypes.js.map +1 -0
- package/dist/esm/store.d.ts +90 -0
- package/dist/esm/store.d.ts.map +1 -0
- package/dist/esm/store.js +723 -0
- package/dist/esm/store.js.map +1 -0
- package/dist/esm/transactionValidation.d.ts +8 -0
- package/dist/esm/transactionValidation.d.ts.map +1 -0
- package/dist/esm/transactionValidation.js +131 -0
- package/dist/esm/transactionValidation.js.map +1 -0
- package/dist/esm/utils/Deferred.d.ts +9 -0
- package/dist/esm/utils/Deferred.d.ts.map +1 -0
- package/dist/esm/utils/Deferred.js +18 -0
- package/dist/esm/utils/Deferred.js.map +1 -0
- package/dist/esm/utils/PersistedObject.d.ts +81 -0
- package/dist/esm/utils/PersistedObject.d.ts.map +1 -0
- package/dist/esm/utils/PersistedObject.js +464 -0
- package/dist/esm/utils/PersistedObject.js.map +1 -0
- package/dist/esm/utils/dates.d.ts +2 -0
- package/dist/esm/utils/dates.d.ts.map +1 -0
- package/dist/esm/utils/dates.js +212 -0
- package/dist/esm/utils/dates.js.map +1 -0
- package/dist/esm/utils/error.d.ts +3 -0
- package/dist/esm/utils/error.d.ts.map +1 -0
- package/dist/esm/utils/error.js +9 -0
- package/dist/esm/utils/error.js.map +1 -0
- package/dist/esm/utils/fetch.d.ts +126 -0
- package/dist/esm/utils/fetch.d.ts.map +1 -0
- package/dist/esm/utils/fetch.js +32 -0
- package/dist/esm/utils/fetch.js.map +1 -0
- package/dist/esm/utils/flags.d.ts +5 -0
- package/dist/esm/utils/flags.d.ts.map +1 -0
- package/dist/esm/utils/flags.js +11 -0
- package/dist/esm/utils/flags.js.map +1 -0
- package/dist/esm/utils/id.d.ts +4 -0
- package/dist/esm/utils/id.d.ts.map +1 -0
- package/dist/esm/utils/id.js +26 -0
- package/dist/esm/utils/id.js.map +1 -0
- package/dist/esm/utils/linkIndex.d.ts +8 -0
- package/dist/esm/utils/linkIndex.d.ts.map +1 -0
- package/dist/esm/utils/linkIndex.js +18 -0
- package/dist/esm/utils/linkIndex.js.map +1 -0
- package/dist/esm/utils/log.d.ts +7 -0
- package/dist/esm/utils/log.d.ts.map +1 -0
- package/dist/esm/utils/log.js +14 -0
- package/dist/esm/utils/log.js.map +1 -0
- package/dist/esm/utils/object.d.ts +17 -0
- package/dist/esm/utils/object.d.ts.map +1 -0
- package/dist/esm/utils/object.js +144 -0
- package/dist/esm/utils/object.js.map +1 -0
- package/dist/esm/utils/pgtime.d.ts +198 -0
- package/dist/esm/utils/pgtime.d.ts.map +1 -0
- package/dist/esm/utils/pgtime.js +198 -0
- package/dist/esm/utils/pgtime.js.map +1 -0
- package/dist/esm/utils/pick.d.ts +2 -0
- package/dist/esm/utils/pick.d.ts.map +1 -0
- package/dist/esm/utils/pick.js +10 -0
- package/dist/esm/utils/pick.js.map +1 -0
- package/dist/esm/utils/strings.d.ts +2 -0
- package/dist/esm/utils/strings.d.ts.map +1 -0
- package/dist/esm/utils/strings.js +16 -0
- package/dist/esm/utils/strings.js.map +1 -0
- package/dist/esm/utils/weakHash.d.ts +16 -0
- package/dist/esm/utils/weakHash.d.ts.map +1 -0
- package/dist/esm/utils/weakHash.js +72 -0
- package/dist/esm/utils/weakHash.js.map +1 -0
- package/dist/esm/utils/weakHashLegacy.d.ts +8 -0
- package/dist/esm/utils/weakHashLegacy.d.ts.map +1 -0
- package/dist/esm/utils/weakHashLegacy.js +73 -0
- package/dist/esm/utils/weakHashLegacy.js.map +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/warningToggle.d.ts +3 -0
- package/dist/esm/warningToggle.d.ts.map +1 -0
- package/dist/esm/warningToggle.js +5 -0
- package/dist/esm/warningToggle.js.map +1 -0
- package/dist/standalone/index.js +8740 -0
- package/dist/standalone/index.umd.cjs +7 -0
- package/package.json +81 -3
- package/src/Connection.ts +277 -0
- package/src/InMemoryStorage.ts +34 -0
- package/src/IndexedDBStorage.ts +387 -0
- package/src/InstantError.ts +28 -0
- package/src/Reactor.js +2921 -0
- package/src/StorageAPI.ts +156 -0
- package/src/Stream.ts +1164 -0
- package/src/SyncTable.ts +919 -0
- package/src/WindowNetworkListener.js +19 -0
- package/src/__types__/fieldsTypeTest.ts +113 -0
- package/src/__types__/typeUtils.ts +39 -0
- package/src/__types__/useDatesTypeTest.ts +69 -0
- package/src/attrTypes.ts +29 -0
- package/src/authAPI.ts +205 -0
- package/src/clientTypes.ts +28 -0
- package/src/coreTypes.ts +58 -0
- package/src/createRouteHandler.ts +66 -0
- package/src/datalog.js +116 -0
- package/src/devtool.ts +186 -0
- package/src/endpoints.ts +101 -0
- package/src/framework.ts +395 -0
- package/src/helperTypes.ts +115 -0
- package/src/index.ts +1283 -0
- package/src/infiniteQuery.ts +602 -0
- package/src/instaml.ts +714 -0
- package/src/instaql.ts +952 -0
- package/src/instatx.ts +265 -0
- package/src/model/instaqlResult.js +25 -0
- package/src/notifyScope.ts +343 -0
- package/src/parseSchemaFromJSON.ts +176 -0
- package/src/presence.ts +123 -0
- package/src/presenceTypes.ts +19 -0
- package/src/queryTypes.ts +721 -0
- package/src/queryValidation.ts +535 -0
- package/src/reactorTypes.ts +33 -0
- package/src/routeHandlerProtocol.ts +24 -0
- package/src/rulesTypes.ts +122 -0
- package/src/sanityCheckQueries.ts +189 -0
- package/src/schema.ts +194 -0
- package/src/schemaTypes.ts +642 -0
- package/src/store.ts +949 -0
- package/src/transactionValidation.ts +204 -0
- package/src/utils/Deferred.ts +20 -0
- package/src/utils/PersistedObject.ts +589 -0
- package/src/utils/dates.ts +258 -0
- package/src/utils/error.ts +9 -0
- package/src/utils/fetch.ts +129 -0
- package/src/utils/flags.ts +14 -0
- package/src/utils/id.ts +28 -0
- package/src/utils/linkIndex.ts +33 -0
- package/src/utils/log.ts +23 -0
- package/src/utils/object.js +176 -0
- package/src/utils/pgtime.ts +199 -0
- package/src/utils/pick.js +9 -0
- package/src/utils/strings.ts +19 -0
- package/src/utils/weakHash.ts +77 -0
- package/src/utils/weakHashLegacy.ts +75 -0
- package/src/version.ts +3 -0
- package/src/warningToggle.ts +5 -0
- package/tsconfig.cjs.dev.json +15 -0
- package/tsconfig.dev.json +14 -0
- package/tsconfig.json +13 -0
- package/tsconfig.test.json +5 -0
- package/vite.config.ts +19 -0
- package/vitest.config.ts +75 -0
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import {
|
|
2
|
+
coerceQuery,
|
|
3
|
+
QueryValidationError,
|
|
4
|
+
type InstantCoreDatabase,
|
|
5
|
+
type ValidQuery,
|
|
6
|
+
} from './index.ts';
|
|
7
|
+
import {
|
|
8
|
+
InstaQLResponse,
|
|
9
|
+
InstaQLOptions,
|
|
10
|
+
Cursor,
|
|
11
|
+
Order,
|
|
12
|
+
} from './queryTypes.ts';
|
|
13
|
+
import { InstantSchemaDef } from './schemaTypes.ts';
|
|
14
|
+
import { assert } from './utils/error.ts';
|
|
15
|
+
|
|
16
|
+
// Example for {order: {value: "asc"}}
|
|
17
|
+
//
|
|
18
|
+
// 0
|
|
19
|
+
// <------------------|------------------------------------------------------>
|
|
20
|
+
// <- starter sub ->
|
|
21
|
+
//
|
|
22
|
+
// Bootstrap phase: until the limit (4 in this example) items are reached, the
|
|
23
|
+
// starter subscription is the only subscription and it writes to the forwardChunks map with the key PRE_BOOTSTRAP_CURSOR.
|
|
24
|
+
//
|
|
25
|
+
// When the limit is reached it automatically becomes a real forward chunk and has a definite start and end.
|
|
26
|
+
// A new reverse chunk gets added to watch for any new items at the start of the list.
|
|
27
|
+
//
|
|
28
|
+
// 0 1 2 3
|
|
29
|
+
// <------------------|------------------------------------------------------>
|
|
30
|
+
// <- starter sub ->
|
|
31
|
+
//
|
|
32
|
+
// ↓ BECOMES ↓
|
|
33
|
+
//
|
|
34
|
+
// 0 1 2 3
|
|
35
|
+
// <------------------|------------------------------------------------------>
|
|
36
|
+
// <-reverse chunk][forward chunk ]
|
|
37
|
+
//
|
|
38
|
+
// 0 1 2 3 4
|
|
39
|
+
// <------------------|------------------------------------------------------>
|
|
40
|
+
// <-reverse chunk][forward chunk ]
|
|
41
|
+
// When item 4 is added, the forward chunk subscription gets updated so that
|
|
42
|
+
// hasNextPage is `true`. This tells the user that a new page can be loaded.
|
|
43
|
+
//
|
|
44
|
+
// User clicks: loadNextPage
|
|
45
|
+
// 0 1 2 3 4
|
|
46
|
+
// <------------------|------------------------------------------------------>
|
|
47
|
+
// <-reverse chunk][ frozen forward chunk ][ new forward chunk ]
|
|
48
|
+
//
|
|
49
|
+
// More numbers get added
|
|
50
|
+
// 0 1 2 3 4 5 6 7 8
|
|
51
|
+
// <------------------|------------------------------------------------------>
|
|
52
|
+
// <-reverse chunk][ frozen forward chunk ][ forward chunk ] ^
|
|
53
|
+
// hasNextPage=true^
|
|
54
|
+
//
|
|
55
|
+
//
|
|
56
|
+
// User clicks: loadNextPage
|
|
57
|
+
//
|
|
58
|
+
// 0 1 2 3 4 5 6 7 8
|
|
59
|
+
// <------------------|------------------------------------------------------>
|
|
60
|
+
// <-reverse chunk][ frozen forward chunk ][ frozen forward chunk ][ new chunk
|
|
61
|
+
//
|
|
62
|
+
// The reverse chunks work in the same way as the forward chunks but the order in the query is reversed.
|
|
63
|
+
// When a reverse chunks recieves an update it will check to see if more can be loaded and it will
|
|
64
|
+
// automatically freeze the chunk and add a new one. i.e. : works the same as if
|
|
65
|
+
// loadNextPage was automatically clicked when hasNextPage became true.
|
|
66
|
+
//
|
|
67
|
+
// Chunks are indexed by their starting point cursor, for forward chunks this is the "[" point.
|
|
68
|
+
// Their starting point cursor is inclusive in the query and exclusive from the following query
|
|
69
|
+
|
|
70
|
+
const makeCursorKey = (cursor: Cursor) => JSON.stringify(cursor);
|
|
71
|
+
const makeChunkKey = (cursor: Cursor, afterInclusive = false) =>
|
|
72
|
+
JSON.stringify([cursor, afterInclusive]);
|
|
73
|
+
const parseChunkKey = (chunkKey: string) => {
|
|
74
|
+
const [cursor, afterInclusive] = JSON.parse(chunkKey) as [Cursor, boolean];
|
|
75
|
+
return { cursor, afterInclusive };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Chunk sub key is used to create keys to keep track of the subscriptions
|
|
79
|
+
// while chunk maps are keyed by [cursor, afterInclusive], we still distinguish
|
|
80
|
+
// between forward and reverse to avoid clashes that can share the same key.
|
|
81
|
+
const chunkSubKey = (
|
|
82
|
+
direction: 'forward' | 'reverse',
|
|
83
|
+
cursor: Cursor,
|
|
84
|
+
afterInclusive = false,
|
|
85
|
+
) => `${direction}:${makeChunkKey(cursor, afterInclusive)}`;
|
|
86
|
+
|
|
87
|
+
export type ChunkStatus = 'pre-bootstrap' | 'bootstrapping' | 'frozen';
|
|
88
|
+
type Chunk = {
|
|
89
|
+
status: ChunkStatus;
|
|
90
|
+
data: any[];
|
|
91
|
+
hasMore?: boolean;
|
|
92
|
+
endCursor?: Cursor;
|
|
93
|
+
afterInclusive?: boolean;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
type ChunkWithEndCursor = Chunk & { endCursor: Cursor };
|
|
97
|
+
|
|
98
|
+
const chunkHasEndCursor = (chunk: Chunk): chunk is ChunkWithEndCursor => {
|
|
99
|
+
return !!chunk.endCursor;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export interface InfiniteQuerySubscription {
|
|
103
|
+
unsubscribe: () => void;
|
|
104
|
+
loadNextPage: () => void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const readCanLoadNextPage = (forwardChunks: Map<string, Chunk>) => {
|
|
108
|
+
const chunksInOrder = Array.from(forwardChunks.values());
|
|
109
|
+
if (chunksInOrder.length === 0) return false;
|
|
110
|
+
return chunksInOrder[chunksInOrder.length - 1]?.hasMore || false;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const reverseOrder = <
|
|
114
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
115
|
+
Entity extends keyof Schema['entities'],
|
|
116
|
+
>(
|
|
117
|
+
order?: Order<Schema, Entity>,
|
|
118
|
+
): Order<Schema, Entity> => {
|
|
119
|
+
if (!order) {
|
|
120
|
+
return {
|
|
121
|
+
serverCreatedAt: 'asc',
|
|
122
|
+
} satisfies Order<Schema, Entity>;
|
|
123
|
+
}
|
|
124
|
+
const key = Object.keys(order)[0];
|
|
125
|
+
if (!key) {
|
|
126
|
+
return {
|
|
127
|
+
serverCreatedAt: 'asc',
|
|
128
|
+
} satisfies Order<Schema, Entity>;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
[key]: order[key as keyof typeof order] === 'asc' ? 'desc' : 'asc',
|
|
132
|
+
} as Order<Schema, Entity>;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const resolveOrder = <
|
|
136
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
137
|
+
Entity extends keyof Schema['entities'],
|
|
138
|
+
>(
|
|
139
|
+
order?: Order<Schema, Entity>,
|
|
140
|
+
): Order<Schema, Entity> => {
|
|
141
|
+
if (order && Object.keys(order).length > 0) return order;
|
|
142
|
+
// serverCreatedAt: 'asc' is the implicit order in queries without an `order`
|
|
143
|
+
// field. We need this to be explicit, because when doing `reverse` queries, we rely
|
|
144
|
+
// on inverting this order.
|
|
145
|
+
return {
|
|
146
|
+
serverCreatedAt: 'asc',
|
|
147
|
+
} satisfies Order<Schema, Entity>;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const normalizeChunks = (
|
|
151
|
+
forwardChunks: Map<string, Chunk>,
|
|
152
|
+
reverseChunks: Map<string, Chunk>,
|
|
153
|
+
): { chunks: Chunk[]; data: any[] } => {
|
|
154
|
+
const chunks = [
|
|
155
|
+
...Array.from(reverseChunks.values()).slice().reverse(),
|
|
156
|
+
...Array.from(forwardChunks.values()),
|
|
157
|
+
];
|
|
158
|
+
|
|
159
|
+
const data = [
|
|
160
|
+
...Array.from(reverseChunks.values())
|
|
161
|
+
.slice()
|
|
162
|
+
.reverse()
|
|
163
|
+
.flatMap((chunk) => chunk.data.slice().reverse()),
|
|
164
|
+
...Array.from(forwardChunks.values()).flatMap((chunk) => chunk.data),
|
|
165
|
+
];
|
|
166
|
+
return { chunks, data };
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const PRE_BOOTSTRAP_CURSOR: Cursor = ['bootstrap', 'bootstrap', 'bootstrap', 1];
|
|
170
|
+
|
|
171
|
+
export type InfiniteQueryCallbackResponse<
|
|
172
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
173
|
+
Query extends Record<string, any>,
|
|
174
|
+
UseDatesLocal extends boolean,
|
|
175
|
+
> =
|
|
176
|
+
| {
|
|
177
|
+
error: { message: string };
|
|
178
|
+
data: undefined;
|
|
179
|
+
canLoadNextPage: boolean;
|
|
180
|
+
}
|
|
181
|
+
| {
|
|
182
|
+
error: undefined;
|
|
183
|
+
data: InstaQLResponse<Schema, Query, UseDatesLocal>;
|
|
184
|
+
canLoadNextPage: boolean;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export const subscribeInfiniteQuery = <
|
|
188
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
189
|
+
Q extends ValidQuery<Q, Schema>,
|
|
190
|
+
UseDates extends boolean,
|
|
191
|
+
>(
|
|
192
|
+
db: InstantCoreDatabase<Schema, UseDates>,
|
|
193
|
+
fullQuery: Q,
|
|
194
|
+
cb: (resp: InfiniteQueryCallbackResponse<Schema, Q, UseDates>) => void,
|
|
195
|
+
opts?: InstaQLOptions,
|
|
196
|
+
): InfiniteQuerySubscription => {
|
|
197
|
+
const { entityName, entityQuery: query } = splitAndValidateQuery(fullQuery);
|
|
198
|
+
|
|
199
|
+
const pageSize = query.$?.limit || 10;
|
|
200
|
+
const entity = entityName;
|
|
201
|
+
const order = resolveOrder(query.$?.order);
|
|
202
|
+
|
|
203
|
+
const forwardChunks = new Map<string, Chunk>();
|
|
204
|
+
const reverseChunks = new Map<string, Chunk>();
|
|
205
|
+
// Keeps track of all subscriptions (besides starter sub)
|
|
206
|
+
const allUnsubs = new Map<string, () => void>();
|
|
207
|
+
|
|
208
|
+
let hasKickstarted = false;
|
|
209
|
+
let isActive = true;
|
|
210
|
+
let lastReverseAdvancedChunkKey: string | null = null;
|
|
211
|
+
let starterUnsub: (() => void) | null = null;
|
|
212
|
+
|
|
213
|
+
const sendError = (err: { message: string }) => {
|
|
214
|
+
cb({ error: err, data: undefined, canLoadNextPage: false });
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const pushUpdate = () => {
|
|
218
|
+
if (!isActive) return;
|
|
219
|
+
|
|
220
|
+
const { chunks, data } = normalizeChunks(forwardChunks, reverseChunks);
|
|
221
|
+
cb({
|
|
222
|
+
data: { [entity]: data } as InstaQLResponse<
|
|
223
|
+
Schema,
|
|
224
|
+
typeof query,
|
|
225
|
+
UseDates
|
|
226
|
+
>,
|
|
227
|
+
// @ts-expect-error hidden debug variable
|
|
228
|
+
chunks,
|
|
229
|
+
canLoadNextPage: readCanLoadNextPage(forwardChunks),
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const setForwardChunk = (startCursor: Cursor, chunk: Chunk) => {
|
|
234
|
+
forwardChunks.set(makeChunkKey(startCursor, chunk.afterInclusive), chunk);
|
|
235
|
+
pushUpdate();
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const setReverseChunk = (startCursor: Cursor, chunk: Chunk) => {
|
|
239
|
+
reverseChunks.set(makeChunkKey(startCursor), chunk);
|
|
240
|
+
maybeAdvanceReverse();
|
|
241
|
+
pushUpdate();
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const freezeReverse = (chunkKey: string, chunk: ChunkWithEndCursor) => {
|
|
245
|
+
const { cursor: startCursor } = parseChunkKey(chunkKey);
|
|
246
|
+
const currentSub = allUnsubs.get(chunkSubKey('reverse', startCursor));
|
|
247
|
+
currentSub?.();
|
|
248
|
+
|
|
249
|
+
const nextSub = db.subscribeQuery(
|
|
250
|
+
{
|
|
251
|
+
[entity]: {
|
|
252
|
+
...query,
|
|
253
|
+
$: {
|
|
254
|
+
after: startCursor,
|
|
255
|
+
before: chunk.endCursor,
|
|
256
|
+
beforeInclusive: true,
|
|
257
|
+
where: query.$?.where,
|
|
258
|
+
fields: query.$?.fields,
|
|
259
|
+
order: reverseOrder(order),
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
} as unknown as Q,
|
|
263
|
+
(frozenData) => {
|
|
264
|
+
if (frozenData.error) {
|
|
265
|
+
return sendError(frozenData.error);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const rows = frozenData.data[entity];
|
|
269
|
+
const pageInfo = frozenData.pageInfo[entity];
|
|
270
|
+
assert(
|
|
271
|
+
rows && pageInfo,
|
|
272
|
+
'Expected query subscription to contain rows and pageInfo',
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
setReverseChunk(startCursor, {
|
|
276
|
+
data: rows,
|
|
277
|
+
status: 'frozen',
|
|
278
|
+
hasMore: pageInfo.hasNextPage,
|
|
279
|
+
endCursor: pageInfo.endCursor,
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
opts,
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
allUnsubs.set(chunkSubKey('reverse', startCursor), nextSub);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const pushNewReverse = (startCursor: Cursor) => {
|
|
289
|
+
const querySub = db.subscribeQuery(
|
|
290
|
+
{
|
|
291
|
+
[entity]: {
|
|
292
|
+
...query,
|
|
293
|
+
$: {
|
|
294
|
+
limit: pageSize,
|
|
295
|
+
after: startCursor,
|
|
296
|
+
where: query.$?.where,
|
|
297
|
+
fields: query.$?.fields,
|
|
298
|
+
order: reverseOrder(order),
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
} as unknown as Q,
|
|
302
|
+
(windowData) => {
|
|
303
|
+
if (windowData.error) {
|
|
304
|
+
return sendError(windowData.error);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const rows = windowData.data[entity];
|
|
308
|
+
const pageInfo = windowData.pageInfo[entity];
|
|
309
|
+
assert(rows && pageInfo, 'Expected rows and pageInfo');
|
|
310
|
+
|
|
311
|
+
setReverseChunk(startCursor, {
|
|
312
|
+
data: rows,
|
|
313
|
+
status: 'bootstrapping',
|
|
314
|
+
hasMore: pageInfo.hasNextPage,
|
|
315
|
+
endCursor: pageInfo.endCursor,
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
opts,
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
allUnsubs.set(chunkSubKey('reverse', startCursor), querySub);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const pushNewForward = (startCursor: Cursor, afterInclusive = false) => {
|
|
325
|
+
const querySub = db.subscribeQuery(
|
|
326
|
+
{
|
|
327
|
+
[entity]: {
|
|
328
|
+
...query,
|
|
329
|
+
$: {
|
|
330
|
+
limit: pageSize,
|
|
331
|
+
after: startCursor,
|
|
332
|
+
afterInclusive,
|
|
333
|
+
where: query.$?.where,
|
|
334
|
+
fields: query.$?.fields,
|
|
335
|
+
order,
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
} as unknown as Q,
|
|
339
|
+
(windowData) => {
|
|
340
|
+
if (windowData.error) {
|
|
341
|
+
return sendError(windowData.error);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const rows = windowData.data[entity];
|
|
345
|
+
const pageInfo = windowData.pageInfo[entity];
|
|
346
|
+
assert(rows && pageInfo, 'Page info and rows');
|
|
347
|
+
|
|
348
|
+
setForwardChunk(startCursor, {
|
|
349
|
+
data: rows,
|
|
350
|
+
status: 'bootstrapping',
|
|
351
|
+
hasMore: pageInfo.hasNextPage,
|
|
352
|
+
endCursor: pageInfo.endCursor,
|
|
353
|
+
afterInclusive,
|
|
354
|
+
});
|
|
355
|
+
},
|
|
356
|
+
opts,
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
allUnsubs.set(
|
|
360
|
+
chunkSubKey('forward', startCursor, afterInclusive),
|
|
361
|
+
querySub,
|
|
362
|
+
);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const freezeForward = (startCursor: Cursor, afterInclusive = false) => {
|
|
366
|
+
const key = makeChunkKey(startCursor, afterInclusive);
|
|
367
|
+
const currentSub = allUnsubs.get(
|
|
368
|
+
chunkSubKey('forward', startCursor, afterInclusive),
|
|
369
|
+
);
|
|
370
|
+
currentSub?.();
|
|
371
|
+
|
|
372
|
+
const chunk = forwardChunks.get(key);
|
|
373
|
+
if (!chunk?.endCursor) return;
|
|
374
|
+
|
|
375
|
+
const nextSub = db.subscribeQuery(
|
|
376
|
+
{
|
|
377
|
+
[entity]: {
|
|
378
|
+
...query,
|
|
379
|
+
$: {
|
|
380
|
+
after: startCursor,
|
|
381
|
+
afterInclusive: chunk.afterInclusive,
|
|
382
|
+
before: chunk.endCursor,
|
|
383
|
+
beforeInclusive: true,
|
|
384
|
+
where: query.$?.where,
|
|
385
|
+
fields: query.$?.fields,
|
|
386
|
+
order,
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
} as unknown as Q,
|
|
390
|
+
(frozenData) => {
|
|
391
|
+
if (frozenData.error) {
|
|
392
|
+
return sendError(frozenData.error);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const rows = frozenData.data[entity];
|
|
396
|
+
const pageInfo = frozenData.pageInfo[entity];
|
|
397
|
+
assert(rows && pageInfo, 'Expected rows and pageInfo');
|
|
398
|
+
|
|
399
|
+
setForwardChunk(startCursor, {
|
|
400
|
+
data: rows,
|
|
401
|
+
status: 'frozen',
|
|
402
|
+
hasMore: pageInfo.hasNextPage,
|
|
403
|
+
endCursor: pageInfo.endCursor,
|
|
404
|
+
afterInclusive: chunk.afterInclusive,
|
|
405
|
+
});
|
|
406
|
+
},
|
|
407
|
+
opts,
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
allUnsubs.set(chunkSubKey('forward', startCursor, afterInclusive), nextSub);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// Consider order: {val: "asc"} with pageItems = 4
|
|
414
|
+
// A reverse chunk captures all the new items coming in before us.
|
|
415
|
+
// If we hit 4 then we freeze the current chunk and create a new reverse chunk
|
|
416
|
+
const maybeAdvanceReverse = () => {
|
|
417
|
+
const reverseEntries = Array.from(reverseChunks.entries());
|
|
418
|
+
const tailEntry = reverseEntries[reverseEntries.length - 1];
|
|
419
|
+
if (!tailEntry) return;
|
|
420
|
+
|
|
421
|
+
const [chunkKey, chunk] = tailEntry;
|
|
422
|
+
|
|
423
|
+
// If a chunk has more, then it must have an endCursor
|
|
424
|
+
if (!chunk?.hasMore) return;
|
|
425
|
+
if (!chunkHasEndCursor(chunk)) return;
|
|
426
|
+
|
|
427
|
+
// maybeAdvanceReverse can run multiple times if multiple changes are made
|
|
428
|
+
// to the reverse chunk
|
|
429
|
+
// This prevents adding the same new reverse frame twice
|
|
430
|
+
const advanceKey = `${chunkKey}:${makeCursorKey(chunk.endCursor)}`;
|
|
431
|
+
if (advanceKey == lastReverseAdvancedChunkKey) return;
|
|
432
|
+
lastReverseAdvancedChunkKey = advanceKey;
|
|
433
|
+
|
|
434
|
+
freezeReverse(chunkKey, chunk);
|
|
435
|
+
pushNewReverse(chunk.endCursor);
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const loadNextPage = () => {
|
|
439
|
+
const forwardEntries = Array.from(forwardChunks.entries());
|
|
440
|
+
const tailEntry = forwardEntries[forwardEntries.length - 1];
|
|
441
|
+
if (!tailEntry) return;
|
|
442
|
+
|
|
443
|
+
const [chunkKey, chunk] = tailEntry;
|
|
444
|
+
|
|
445
|
+
// If the chunk has more items after it, it must have an end cursor, and we can
|
|
446
|
+
// load more items
|
|
447
|
+
// if (!chunk?.hasMore) return;
|
|
448
|
+
if (!chunk.endCursor) return;
|
|
449
|
+
|
|
450
|
+
const { cursor: startCursor, afterInclusive } = parseChunkKey(chunkKey);
|
|
451
|
+
freezeForward(startCursor, afterInclusive);
|
|
452
|
+
pushNewForward(chunk.endCursor);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
starterUnsub = db.subscribeQuery(
|
|
456
|
+
{
|
|
457
|
+
[entity]: {
|
|
458
|
+
...query,
|
|
459
|
+
$: {
|
|
460
|
+
limit: pageSize,
|
|
461
|
+
where: query.$?.where,
|
|
462
|
+
fields: query.$?.fields,
|
|
463
|
+
order,
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
} as unknown as Q,
|
|
467
|
+
async (starterData) => {
|
|
468
|
+
if (hasKickstarted) return;
|
|
469
|
+
if (starterData.error) {
|
|
470
|
+
return sendError(starterData.error);
|
|
471
|
+
}
|
|
472
|
+
const pageInfo = starterData.pageInfo[entity];
|
|
473
|
+
|
|
474
|
+
const rows = starterData?.data?.[entity];
|
|
475
|
+
assert(rows && pageInfo, 'Expected rows and pageInfo');
|
|
476
|
+
|
|
477
|
+
if (rows.length < pageSize) {
|
|
478
|
+
// If the rows are less than the page size, then we don't need to
|
|
479
|
+
// create forward and reverse chunks.
|
|
480
|
+
// We just treat the starter query as a forward chunk
|
|
481
|
+
setForwardChunk(PRE_BOOTSTRAP_CURSOR, {
|
|
482
|
+
data: rows,
|
|
483
|
+
status: 'pre-bootstrap',
|
|
484
|
+
});
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Consider a query with no items; the server will return a result with
|
|
489
|
+
// no start cursor. If we add {pageSize} optimistic updates we can
|
|
490
|
+
// get here and still have no startCursor.
|
|
491
|
+
// For now we treat the data we currently have like a pre boostrap
|
|
492
|
+
// state.
|
|
493
|
+
const initialForwardCursor = pageInfo.startCursor;
|
|
494
|
+
if (!initialForwardCursor) {
|
|
495
|
+
setForwardChunk(PRE_BOOTSTRAP_CURSOR, {
|
|
496
|
+
data: rows,
|
|
497
|
+
status: 'pre-bootstrap',
|
|
498
|
+
});
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
forwardChunks.delete(makeChunkKey(PRE_BOOTSTRAP_CURSOR));
|
|
503
|
+
|
|
504
|
+
pushNewForward(initialForwardCursor, true);
|
|
505
|
+
pushNewReverse(pageInfo.startCursor);
|
|
506
|
+
hasKickstarted = true;
|
|
507
|
+
},
|
|
508
|
+
opts,
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
const unsubscribe = () => {
|
|
512
|
+
if (!isActive) return;
|
|
513
|
+
isActive = false;
|
|
514
|
+
starterUnsub?.();
|
|
515
|
+
starterUnsub = null;
|
|
516
|
+
for (const unsub of allUnsubs.values()) {
|
|
517
|
+
unsub?.();
|
|
518
|
+
}
|
|
519
|
+
allUnsubs.clear();
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
unsubscribe,
|
|
524
|
+
loadNextPage,
|
|
525
|
+
};
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
export const getInfiniteQueryInitialSnapshot = <
|
|
529
|
+
Schema extends InstantSchemaDef<any, any, any>,
|
|
530
|
+
Q extends ValidQuery<Q, Schema>,
|
|
531
|
+
UseDates extends boolean,
|
|
532
|
+
>(
|
|
533
|
+
db: InstantCoreDatabase<Schema, UseDates>,
|
|
534
|
+
fullQuery: Q | null,
|
|
535
|
+
opts?: InstaQLOptions,
|
|
536
|
+
):
|
|
537
|
+
| InfiniteQueryCallbackResponse<Schema, Q, UseDates>
|
|
538
|
+
| {
|
|
539
|
+
canLoadNextPage: false;
|
|
540
|
+
data: undefined;
|
|
541
|
+
error: undefined;
|
|
542
|
+
} => {
|
|
543
|
+
if (!fullQuery) {
|
|
544
|
+
return {
|
|
545
|
+
canLoadNextPage: false,
|
|
546
|
+
data: undefined,
|
|
547
|
+
error: undefined,
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
const { entityName, entityQuery } = splitAndValidateQuery(fullQuery);
|
|
551
|
+
|
|
552
|
+
const pageSize = entityQuery.$?.limit || 10;
|
|
553
|
+
const order = resolveOrder(entityQuery.$?.order);
|
|
554
|
+
|
|
555
|
+
let coercedQuery = fullQuery
|
|
556
|
+
? coerceQuery({
|
|
557
|
+
[entityName]: {
|
|
558
|
+
...entityQuery,
|
|
559
|
+
$: {
|
|
560
|
+
limit: pageSize,
|
|
561
|
+
where: entityQuery.$?.where,
|
|
562
|
+
fields: entityQuery.$?.fields,
|
|
563
|
+
order,
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
})
|
|
567
|
+
: null;
|
|
568
|
+
|
|
569
|
+
if (opts && 'ruleParams' in opts) {
|
|
570
|
+
coercedQuery = {
|
|
571
|
+
$$ruleParams: opts.ruleParams,
|
|
572
|
+
...coercedQuery,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
const queryResult = db._reactor.getPreviousResult(coercedQuery);
|
|
576
|
+
|
|
577
|
+
return {
|
|
578
|
+
canLoadNextPage: false,
|
|
579
|
+
data: queryResult?.data || undefined,
|
|
580
|
+
error: undefined,
|
|
581
|
+
};
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* @throws QueryValidationError
|
|
586
|
+
* @param fullQuery a ValidQuery with one key (entity)
|
|
587
|
+
*/
|
|
588
|
+
const splitAndValidateQuery = (fullQuery: Record<string, any>) => {
|
|
589
|
+
const entityNames = Object.keys(fullQuery);
|
|
590
|
+
if (entityNames.length !== 1) {
|
|
591
|
+
throw new QueryValidationError(
|
|
592
|
+
'subscribeInfiniteQuery expects exactly one entity',
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const [entityName, entityQuery] = Object.entries(fullQuery)[0];
|
|
597
|
+
|
|
598
|
+
if (!entityName || !entityQuery) {
|
|
599
|
+
throw new QueryValidationError('No query provided for infinite query');
|
|
600
|
+
}
|
|
601
|
+
return { entityName, entityQuery };
|
|
602
|
+
};
|