@sidekickdb/core 0.0.0 → 2.0.1
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,718 @@
|
|
|
1
|
+
import { test, expect } from 'vitest';
|
|
2
|
+
import zenecaAttrs from './data/zeneca/attrs.json';
|
|
3
|
+
import zenecaTriples from './data/zeneca/triples.json';
|
|
4
|
+
import {
|
|
5
|
+
createStore,
|
|
6
|
+
allMapValues,
|
|
7
|
+
toJSON,
|
|
8
|
+
fromJSON,
|
|
9
|
+
transact,
|
|
10
|
+
AttrsStoreClass,
|
|
11
|
+
getAttrByFwdIdentName,
|
|
12
|
+
Store,
|
|
13
|
+
AttrsStore,
|
|
14
|
+
attrsStoreFromJSON,
|
|
15
|
+
} from '../../src/store';
|
|
16
|
+
import query from '../../src/instaql';
|
|
17
|
+
import uuid from '../../src/utils/id';
|
|
18
|
+
import { tx } from '../../src/instatx';
|
|
19
|
+
import * as instaml from '../../src/instaml';
|
|
20
|
+
import * as datalog from '../../src/datalog';
|
|
21
|
+
import * as instatx from '../../src/instatx';
|
|
22
|
+
import { i, id } from '../../src';
|
|
23
|
+
import { createLinkIndex } from '../../src/utils/linkIndex';
|
|
24
|
+
|
|
25
|
+
const zenecaAttrsStore = new AttrsStoreClass(
|
|
26
|
+
zenecaAttrs.reduce((res, x) => {
|
|
27
|
+
res[x.id] = x;
|
|
28
|
+
return res;
|
|
29
|
+
}, {}),
|
|
30
|
+
null,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const store = createStore(
|
|
34
|
+
zenecaAttrsStore,
|
|
35
|
+
zenecaTriples as [string, string, any, number][],
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
function checkIndexIntegrity({
|
|
39
|
+
store,
|
|
40
|
+
attrsStore,
|
|
41
|
+
}: {
|
|
42
|
+
store: Store;
|
|
43
|
+
attrsStore: AttrsStore;
|
|
44
|
+
}) {
|
|
45
|
+
const tripleSort = (a, b) => {
|
|
46
|
+
const [e_a, aid_a, v_a, t_a] = a;
|
|
47
|
+
const [e_b, aid_b, v_b, t_b] = b;
|
|
48
|
+
|
|
49
|
+
const e_compare = e_a.localeCompare(e_b);
|
|
50
|
+
if (e_compare !== 0) {
|
|
51
|
+
return e_compare;
|
|
52
|
+
}
|
|
53
|
+
const a_compare = aid_a.localeCompare(aid_b);
|
|
54
|
+
if (a_compare !== 0) {
|
|
55
|
+
return a_compare;
|
|
56
|
+
}
|
|
57
|
+
const v_compare = JSON.stringify(v_a).localeCompare(JSON.stringify(v_b));
|
|
58
|
+
if (v_compare !== 0) {
|
|
59
|
+
return v_compare;
|
|
60
|
+
}
|
|
61
|
+
return t_a - t_b;
|
|
62
|
+
};
|
|
63
|
+
const eavTriples = allMapValues(store.eav, 3).sort(tripleSort);
|
|
64
|
+
const aevTriples = allMapValues(store.aev, 3).sort(tripleSort);
|
|
65
|
+
const vaeTriples = allMapValues(store.vae, 3);
|
|
66
|
+
|
|
67
|
+
// Check eav and aev have all the same triples
|
|
68
|
+
for (let i = 0; i < eavTriples.length; i++) {
|
|
69
|
+
const et = eavTriples[i];
|
|
70
|
+
const at = aevTriples[i];
|
|
71
|
+
expect(et).toEqual(at);
|
|
72
|
+
}
|
|
73
|
+
expect(eavTriples.length).toEqual(aevTriples.length);
|
|
74
|
+
|
|
75
|
+
// Check vae doesn't have extra triples
|
|
76
|
+
for (const triple of vaeTriples) {
|
|
77
|
+
const [e, a, v] = triple;
|
|
78
|
+
expect(store.eav.get(e)?.get(a)?.get(v)).toEqual(triple);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Check vae has all of the triples it should have
|
|
82
|
+
for (const triple of eavTriples) {
|
|
83
|
+
const [e, a, v] = triple;
|
|
84
|
+
const attr = attrsStore.getAttr(a)!;
|
|
85
|
+
if (attr['value-type'] === 'ref') {
|
|
86
|
+
expect(store.vae.get(v)?.get(a)?.get(e)).toEqual(triple);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
test('simple add', () => {
|
|
92
|
+
const id = uuid();
|
|
93
|
+
const chunk = tx.users[id].update({ handle: 'bobby' });
|
|
94
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
95
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
96
|
+
expect(query(newCtx, { users: {} }).data.users.map((x) => x.handle)).contains(
|
|
97
|
+
'bobby',
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
checkIndexIntegrity(newCtx);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('cardinality-one add', () => {
|
|
104
|
+
const id = uuid();
|
|
105
|
+
const chunk = tx.users[id]
|
|
106
|
+
.update({ handle: 'bobby' })
|
|
107
|
+
.update({ handle: 'bob' });
|
|
108
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
109
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
110
|
+
const ret = datalog
|
|
111
|
+
.query(newCtx.store, {
|
|
112
|
+
find: ['?v'],
|
|
113
|
+
where: [[id, '?attr', '?v']],
|
|
114
|
+
})
|
|
115
|
+
.flatMap((vec) => vec[0]);
|
|
116
|
+
expect(ret).contains('bob');
|
|
117
|
+
expect(ret).not.contains('bobby');
|
|
118
|
+
checkIndexIntegrity(newCtx);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('link/unlink', () => {
|
|
122
|
+
const bookshelfId = uuid();
|
|
123
|
+
const userId = uuid();
|
|
124
|
+
const userChunk = tx.users[userId]
|
|
125
|
+
.update({ handle: 'bobby' })
|
|
126
|
+
.link({ bookshelves: bookshelfId });
|
|
127
|
+
const bookshelfChunk = tx.bookshelves[bookshelfId].update({
|
|
128
|
+
name: 'my books',
|
|
129
|
+
});
|
|
130
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
131
|
+
userChunk,
|
|
132
|
+
bookshelfChunk,
|
|
133
|
+
]);
|
|
134
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
135
|
+
expect(
|
|
136
|
+
query(newCtx, {
|
|
137
|
+
users: {
|
|
138
|
+
$: { where: { handle: 'bobby' } },
|
|
139
|
+
bookshelves: {},
|
|
140
|
+
},
|
|
141
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
142
|
+
).toEqual([['bobby', ['my books']]]);
|
|
143
|
+
checkIndexIntegrity(newCtx);
|
|
144
|
+
|
|
145
|
+
const secondBookshelfId = uuid();
|
|
146
|
+
const secondBookshelfChunk = tx.bookshelves[secondBookshelfId].update({
|
|
147
|
+
name: 'my second books',
|
|
148
|
+
});
|
|
149
|
+
const unlinkFirstChunk = tx.users[userId]
|
|
150
|
+
.unlink({
|
|
151
|
+
bookshelves: bookshelfId,
|
|
152
|
+
})
|
|
153
|
+
.link({ bookshelves: secondBookshelfId });
|
|
154
|
+
const secondTxSteps = instaml.transform({ attrsStore: newCtx.attrsStore }, [
|
|
155
|
+
unlinkFirstChunk,
|
|
156
|
+
secondBookshelfChunk,
|
|
157
|
+
]);
|
|
158
|
+
const secondCtx = transact(newCtx.store, newCtx.attrsStore, secondTxSteps);
|
|
159
|
+
expect(
|
|
160
|
+
query(secondCtx, {
|
|
161
|
+
users: {
|
|
162
|
+
$: { where: { handle: 'bobby' } },
|
|
163
|
+
bookshelves: {},
|
|
164
|
+
},
|
|
165
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
166
|
+
).toEqual([['bobby', ['my second books']]]);
|
|
167
|
+
checkIndexIntegrity(secondCtx);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('link/unlink multi', () => {
|
|
171
|
+
const bookshelfId1 = uuid();
|
|
172
|
+
const bookshelfId2 = uuid();
|
|
173
|
+
const userId = uuid();
|
|
174
|
+
const userChunk = tx.users[userId]
|
|
175
|
+
.update({ handle: 'bobby' })
|
|
176
|
+
.link({ bookshelves: [bookshelfId1, bookshelfId2] });
|
|
177
|
+
|
|
178
|
+
const bookshelf1Chunk = tx.bookshelves[bookshelfId1].update({
|
|
179
|
+
name: 'my books 1',
|
|
180
|
+
});
|
|
181
|
+
const bookshelf2Chunk = tx.bookshelves[bookshelfId2].update({
|
|
182
|
+
name: 'my books 2',
|
|
183
|
+
});
|
|
184
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
185
|
+
userChunk,
|
|
186
|
+
bookshelf1Chunk,
|
|
187
|
+
bookshelf2Chunk,
|
|
188
|
+
]);
|
|
189
|
+
|
|
190
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
191
|
+
expect(
|
|
192
|
+
query(newCtx, {
|
|
193
|
+
users: {
|
|
194
|
+
$: { where: { handle: 'bobby' } },
|
|
195
|
+
bookshelves: {},
|
|
196
|
+
},
|
|
197
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
198
|
+
).toEqual([['bobby', ['my books 1', 'my books 2']]]);
|
|
199
|
+
checkIndexIntegrity(newCtx);
|
|
200
|
+
|
|
201
|
+
const bookshelfId3 = uuid();
|
|
202
|
+
const bookshelf3Chunk = tx.bookshelves[bookshelfId3].update({
|
|
203
|
+
name: 'my books 3',
|
|
204
|
+
});
|
|
205
|
+
const unlinkChunk = tx.users[userId]
|
|
206
|
+
.unlink({
|
|
207
|
+
bookshelves: [bookshelfId1, bookshelfId2],
|
|
208
|
+
})
|
|
209
|
+
.link({ bookshelves: bookshelfId3 });
|
|
210
|
+
const secondTxSteps = instaml.transform({ attrsStore: newCtx.attrsStore }, [
|
|
211
|
+
unlinkChunk,
|
|
212
|
+
bookshelf3Chunk,
|
|
213
|
+
]);
|
|
214
|
+
const secondCtx = transact(newCtx.store, newCtx.attrsStore, secondTxSteps);
|
|
215
|
+
expect(
|
|
216
|
+
query(secondCtx, {
|
|
217
|
+
users: {
|
|
218
|
+
$: { where: { handle: 'bobby' } },
|
|
219
|
+
bookshelves: {},
|
|
220
|
+
},
|
|
221
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
222
|
+
).toEqual([['bobby', ['my books 3']]]);
|
|
223
|
+
checkIndexIntegrity(secondCtx);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('link/unlink without update', () => {
|
|
227
|
+
const bookshelfId = uuid();
|
|
228
|
+
const userId = uuid();
|
|
229
|
+
const userChunk = tx.users[userId].update({ handle: 'bobby' });
|
|
230
|
+
const bookshelfChunk = tx.bookshelves[bookshelfId].update({
|
|
231
|
+
name: 'my books',
|
|
232
|
+
});
|
|
233
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
234
|
+
userChunk,
|
|
235
|
+
bookshelfChunk,
|
|
236
|
+
]);
|
|
237
|
+
const ctx2 = transact(store, zenecaAttrsStore, txSteps);
|
|
238
|
+
|
|
239
|
+
const linkChunk = tx.users[userId].link({ bookshelves: bookshelfId });
|
|
240
|
+
const ctx3 = transact(
|
|
241
|
+
ctx2.store,
|
|
242
|
+
ctx2.attrsStore,
|
|
243
|
+
instaml.transform(ctx2, [linkChunk]),
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
expect(
|
|
247
|
+
query(ctx3, {
|
|
248
|
+
users: {
|
|
249
|
+
$: { where: { handle: 'bobby' } },
|
|
250
|
+
bookshelves: {},
|
|
251
|
+
},
|
|
252
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
253
|
+
).toEqual([['bobby', ['my books']]]);
|
|
254
|
+
checkIndexIntegrity(ctx3);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test('delete entity', () => {
|
|
258
|
+
const bookshelfId = uuid();
|
|
259
|
+
const userId = uuid();
|
|
260
|
+
const userChunk = tx.users[userId]
|
|
261
|
+
.update({ handle: 'bobby' })
|
|
262
|
+
.link({ bookshelves: bookshelfId });
|
|
263
|
+
const bookshelfChunk = tx.bookshelves[bookshelfId].update({
|
|
264
|
+
name: 'my books',
|
|
265
|
+
});
|
|
266
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
267
|
+
userChunk,
|
|
268
|
+
bookshelfChunk,
|
|
269
|
+
]);
|
|
270
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
271
|
+
checkIndexIntegrity(newCtx);
|
|
272
|
+
|
|
273
|
+
const retOne = datalog
|
|
274
|
+
.query(newCtx.store, {
|
|
275
|
+
find: ['?v'],
|
|
276
|
+
where: [[bookshelfId, '?attr', '?v']],
|
|
277
|
+
})
|
|
278
|
+
.flatMap((vec) => vec[0]);
|
|
279
|
+
const retTwo = datalog
|
|
280
|
+
.query(newCtx.store, {
|
|
281
|
+
find: ['?v'],
|
|
282
|
+
where: [['?v', '?attr', bookshelfId]],
|
|
283
|
+
})
|
|
284
|
+
.flatMap((vec) => vec[0]);
|
|
285
|
+
expect(retOne).contains('my books');
|
|
286
|
+
expect(retTwo).contains(userId);
|
|
287
|
+
|
|
288
|
+
const txStepsTwo = instaml.transform(
|
|
289
|
+
newCtx,
|
|
290
|
+
tx.bookshelves[bookshelfId].delete(),
|
|
291
|
+
);
|
|
292
|
+
const newCtxTwo = transact(newCtx.store, newCtx.attrsStore, txStepsTwo);
|
|
293
|
+
const retThree = datalog
|
|
294
|
+
.query(newCtxTwo.store, {
|
|
295
|
+
find: ['?v'],
|
|
296
|
+
where: [[bookshelfId, '?attr', '?v']],
|
|
297
|
+
})
|
|
298
|
+
.flatMap((vec) => vec[0]);
|
|
299
|
+
const retFour = datalog
|
|
300
|
+
.query(newCtxTwo.store, {
|
|
301
|
+
find: ['?v'],
|
|
302
|
+
where: [['?v', '?attr', bookshelfId]],
|
|
303
|
+
})
|
|
304
|
+
.flatMap((vec) => vec[0]);
|
|
305
|
+
|
|
306
|
+
expect(retThree).toEqual([]);
|
|
307
|
+
expect(retFour).toEqual([]);
|
|
308
|
+
checkIndexIntegrity(newCtxTwo);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test('on-delete cascade', () => {
|
|
312
|
+
const book1 = uuid();
|
|
313
|
+
const book2 = uuid();
|
|
314
|
+
const book3 = uuid();
|
|
315
|
+
const chunk1 = tx.books[book1].update({
|
|
316
|
+
title: 'book1',
|
|
317
|
+
description: 'series',
|
|
318
|
+
});
|
|
319
|
+
const chunk2 = tx.books[book2]
|
|
320
|
+
.update({ title: 'book2', description: 'series' })
|
|
321
|
+
.link({ prequel: book1 });
|
|
322
|
+
const chunk3 = tx.books[book3]
|
|
323
|
+
.update({ title: 'book3', description: 'series' })
|
|
324
|
+
.link({ prequel: book2 });
|
|
325
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
326
|
+
chunk1,
|
|
327
|
+
chunk2,
|
|
328
|
+
chunk3,
|
|
329
|
+
]);
|
|
330
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
331
|
+
checkIndexIntegrity(newCtx);
|
|
332
|
+
expect(
|
|
333
|
+
query(newCtx, {
|
|
334
|
+
books: { $: { where: { description: 'series' } } },
|
|
335
|
+
}).data.books.map((x) => x.title),
|
|
336
|
+
).toEqual(['book1', 'book2', 'book3']);
|
|
337
|
+
|
|
338
|
+
const txStepsTwo = instaml.transform(newCtx, tx.books[book1].delete());
|
|
339
|
+
const newCtxTwo = transact(newCtx.store, newCtx.attrsStore, txStepsTwo);
|
|
340
|
+
expect(
|
|
341
|
+
query(newCtxTwo, {
|
|
342
|
+
books: { $: { where: { description: 'series' } } },
|
|
343
|
+
}).data.books.map((x) => x.title),
|
|
344
|
+
).toEqual([]);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('on-delete-reverse cascade', () => {
|
|
348
|
+
const book1 = uuid();
|
|
349
|
+
const book2 = uuid();
|
|
350
|
+
const book3 = uuid();
|
|
351
|
+
|
|
352
|
+
const chunk2 = tx.books[book2].update({
|
|
353
|
+
title: 'book2',
|
|
354
|
+
description: 'series',
|
|
355
|
+
});
|
|
356
|
+
const chunk3 = tx.books[book3].update({
|
|
357
|
+
title: 'book3',
|
|
358
|
+
description: 'series',
|
|
359
|
+
});
|
|
360
|
+
const chunk1 = tx.books[book1]
|
|
361
|
+
.update({
|
|
362
|
+
title: 'book1',
|
|
363
|
+
description: 'series',
|
|
364
|
+
})
|
|
365
|
+
.link({ next: [book2, book3] });
|
|
366
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
367
|
+
chunk2,
|
|
368
|
+
chunk3,
|
|
369
|
+
chunk1,
|
|
370
|
+
]);
|
|
371
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
372
|
+
checkIndexIntegrity(newCtx);
|
|
373
|
+
expect(
|
|
374
|
+
query(newCtx, {
|
|
375
|
+
books: { $: { where: { description: 'series' } } },
|
|
376
|
+
}).data.books.map((x) => x.title),
|
|
377
|
+
).toEqual(['book2', 'book3', 'book1']);
|
|
378
|
+
|
|
379
|
+
const txStepsTwo = instaml.transform(newCtx, tx.books[book1].delete());
|
|
380
|
+
const newCtxTwo = transact(newCtx.store, newCtx.attrsStore, txStepsTwo);
|
|
381
|
+
expect(
|
|
382
|
+
query(newCtxTwo, {
|
|
383
|
+
books: { $: { where: { description: 'series' } } },
|
|
384
|
+
}).data.books.map((x) => x.title),
|
|
385
|
+
).toEqual([]);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test('new attrs', () => {
|
|
389
|
+
const colorId = uuid();
|
|
390
|
+
const userId = uuid();
|
|
391
|
+
const userChunk = tx.users[userId]
|
|
392
|
+
.update({ handle: 'bobby' })
|
|
393
|
+
.link({ colors: colorId });
|
|
394
|
+
const colorChunk = tx.colors[colorId].update({ name: 'red' });
|
|
395
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
396
|
+
userChunk,
|
|
397
|
+
colorChunk,
|
|
398
|
+
]);
|
|
399
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
400
|
+
expect(
|
|
401
|
+
query(newCtx, {
|
|
402
|
+
users: {
|
|
403
|
+
$: { where: { handle: 'bobby' } },
|
|
404
|
+
colors: {},
|
|
405
|
+
},
|
|
406
|
+
}).data.users.map((x) => [x.handle, x.colors.map((x) => x.name)]),
|
|
407
|
+
).toEqual([['bobby', ['red']]]);
|
|
408
|
+
|
|
409
|
+
checkIndexIntegrity(newCtx);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test('delete attr', () => {
|
|
413
|
+
expect(
|
|
414
|
+
query(
|
|
415
|
+
{ store, attrsStore: zenecaAttrsStore },
|
|
416
|
+
{ users: {} },
|
|
417
|
+
).data.users.map((x) => [x.handle, x.fullName]),
|
|
418
|
+
).toEqual([
|
|
419
|
+
['joe', 'Joe Averbukh'],
|
|
420
|
+
['alex', 'Alex'],
|
|
421
|
+
['stopa', 'Stepan Parunashvili'],
|
|
422
|
+
['nicolegf', 'Nicole'],
|
|
423
|
+
]);
|
|
424
|
+
const fullNameAttr = getAttrByFwdIdentName(
|
|
425
|
+
zenecaAttrsStore,
|
|
426
|
+
'users',
|
|
427
|
+
'fullName',
|
|
428
|
+
);
|
|
429
|
+
const newCtx = transact(store, zenecaAttrsStore, [
|
|
430
|
+
['delete-attr', fullNameAttr!.id],
|
|
431
|
+
]);
|
|
432
|
+
expect(
|
|
433
|
+
query(newCtx, { users: {} }).data.users.map((x) => [x.handle, x.fullName]),
|
|
434
|
+
).toEqual([
|
|
435
|
+
['joe', undefined],
|
|
436
|
+
['alex', undefined],
|
|
437
|
+
['stopa', undefined],
|
|
438
|
+
['nicolegf', undefined],
|
|
439
|
+
]);
|
|
440
|
+
|
|
441
|
+
checkIndexIntegrity(newCtx);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test('update attr', () => {
|
|
445
|
+
expect(
|
|
446
|
+
query(
|
|
447
|
+
{ store, attrsStore: zenecaAttrsStore },
|
|
448
|
+
{ users: {} },
|
|
449
|
+
).data.users.map((x) => [x.handle, x.fullName]),
|
|
450
|
+
).toEqual([
|
|
451
|
+
['joe', 'Joe Averbukh'],
|
|
452
|
+
['alex', 'Alex'],
|
|
453
|
+
['stopa', 'Stepan Parunashvili'],
|
|
454
|
+
['nicolegf', 'Nicole'],
|
|
455
|
+
]);
|
|
456
|
+
const fullNameAttr = getAttrByFwdIdentName(
|
|
457
|
+
zenecaAttrsStore,
|
|
458
|
+
'users',
|
|
459
|
+
'fullName',
|
|
460
|
+
);
|
|
461
|
+
const fwdIdent = fullNameAttr!['forward-identity'];
|
|
462
|
+
const newCtx = transact(store, zenecaAttrsStore, [
|
|
463
|
+
[
|
|
464
|
+
'update-attr',
|
|
465
|
+
{
|
|
466
|
+
id: fullNameAttr!.id,
|
|
467
|
+
'forward-identity': [fwdIdent[0], 'users', 'fullNamez'],
|
|
468
|
+
},
|
|
469
|
+
],
|
|
470
|
+
]);
|
|
471
|
+
expect(
|
|
472
|
+
query(newCtx, { users: {} }).data.users.map((x) => [x.handle, x.fullNamez]),
|
|
473
|
+
).toEqual([
|
|
474
|
+
['joe', 'Joe Averbukh'],
|
|
475
|
+
['alex', 'Alex'],
|
|
476
|
+
['stopa', 'Stepan Parunashvili'],
|
|
477
|
+
['nicolegf', 'Nicole'],
|
|
478
|
+
]);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test('JSON serialization round-trips', () => {
|
|
482
|
+
const newStore = fromJSON(zenecaAttrsStore, toJSON(store));
|
|
483
|
+
expect(store).toEqual(newStore);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
test('ruleParams no-ops', () => {
|
|
487
|
+
const id = uuid();
|
|
488
|
+
const chunk = tx.users[id]
|
|
489
|
+
.ruleParams({ guestId: 'bobby' })
|
|
490
|
+
.update({ handle: 'bobby' });
|
|
491
|
+
|
|
492
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
493
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
494
|
+
expect(query(newCtx, { users: {} }).data.users.map((x) => x.handle)).contains(
|
|
495
|
+
'bobby',
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
checkIndexIntegrity(newCtx);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test('deepMerge', () => {
|
|
502
|
+
const gameId = uuid();
|
|
503
|
+
const gameCtx = transact(
|
|
504
|
+
store,
|
|
505
|
+
zenecaAttrsStore,
|
|
506
|
+
instaml.transform(
|
|
507
|
+
{ attrsStore: zenecaAttrsStore },
|
|
508
|
+
tx.games[gameId].update({
|
|
509
|
+
state: {
|
|
510
|
+
score: 100,
|
|
511
|
+
playerStats: { health: 50, mana: 30, ambitions: { win: true } },
|
|
512
|
+
inventory: ['sword', 'potion'],
|
|
513
|
+
locations: ['forest', 'castle'],
|
|
514
|
+
level: 2,
|
|
515
|
+
},
|
|
516
|
+
}),
|
|
517
|
+
),
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
checkIndexIntegrity(gameCtx);
|
|
521
|
+
|
|
522
|
+
const updatedCtx = transact(
|
|
523
|
+
gameCtx.store,
|
|
524
|
+
gameCtx.attrsStore,
|
|
525
|
+
instaml.transform(
|
|
526
|
+
gameCtx,
|
|
527
|
+
tx.games[gameId].merge({
|
|
528
|
+
state: {
|
|
529
|
+
// Objects update deeply
|
|
530
|
+
playerStats: {
|
|
531
|
+
mana: 40,
|
|
532
|
+
stamina: 20,
|
|
533
|
+
ambitions: { acquireWisdom: true, find: ['love'] },
|
|
534
|
+
},
|
|
535
|
+
// arrays overwrite
|
|
536
|
+
inventory: ['shield'],
|
|
537
|
+
// null removes the key
|
|
538
|
+
score: null,
|
|
539
|
+
// undefined is ignored
|
|
540
|
+
level: undefined,
|
|
541
|
+
// undefined is kept in arrays
|
|
542
|
+
locations: ['forest', undefined, 'castle'],
|
|
543
|
+
},
|
|
544
|
+
}),
|
|
545
|
+
),
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
const updatedGame = query(updatedCtx, {
|
|
549
|
+
games: { $: { where: { id: gameId } } },
|
|
550
|
+
}).data.games[0];
|
|
551
|
+
expect(updatedGame.state).toEqual({
|
|
552
|
+
playerStats: {
|
|
553
|
+
health: 50,
|
|
554
|
+
mana: 40,
|
|
555
|
+
stamina: 20,
|
|
556
|
+
ambitions: { win: true, acquireWisdom: true, find: ['love'] },
|
|
557
|
+
},
|
|
558
|
+
level: 2,
|
|
559
|
+
inventory: ['shield'],
|
|
560
|
+
locations: ['forest', undefined, 'castle'],
|
|
561
|
+
});
|
|
562
|
+
checkIndexIntegrity(updatedCtx);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
test('recursive links w same id', () => {
|
|
566
|
+
const schema = i.schema({
|
|
567
|
+
entities: {
|
|
568
|
+
$files: i.entity({
|
|
569
|
+
path: i.string().unique().indexed(),
|
|
570
|
+
url: i.string(),
|
|
571
|
+
}),
|
|
572
|
+
fakeUsers: i.entity({
|
|
573
|
+
email: i.string().unique().indexed().optional(),
|
|
574
|
+
}),
|
|
575
|
+
todos: i.entity({
|
|
576
|
+
completed: i.boolean().optional(),
|
|
577
|
+
title: i.string().optional(),
|
|
578
|
+
}),
|
|
579
|
+
},
|
|
580
|
+
links: {
|
|
581
|
+
todosCreatedBy: {
|
|
582
|
+
forward: {
|
|
583
|
+
on: 'todos',
|
|
584
|
+
has: 'one',
|
|
585
|
+
label: 'createdBy',
|
|
586
|
+
onDelete: 'cascade',
|
|
587
|
+
},
|
|
588
|
+
reverse: {
|
|
589
|
+
on: 'fakeUsers',
|
|
590
|
+
has: 'many',
|
|
591
|
+
label: 'todos',
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
const sameId = id();
|
|
597
|
+
const ops = [
|
|
598
|
+
instatx.tx.todos[sameId].update({
|
|
599
|
+
title: 'todo',
|
|
600
|
+
completed: false,
|
|
601
|
+
}),
|
|
602
|
+
instatx.tx.fakeUsers[sameId].update({
|
|
603
|
+
email: 'test@test.com',
|
|
604
|
+
}),
|
|
605
|
+
instatx.tx.todos[sameId].link({
|
|
606
|
+
createdBy: sameId,
|
|
607
|
+
}),
|
|
608
|
+
];
|
|
609
|
+
|
|
610
|
+
const attrsStore = new AttrsStoreClass({}, createLinkIndex(schema));
|
|
611
|
+
const steps = instaml.transform({ attrsStore, schema }, ops);
|
|
612
|
+
const store = createStore(attrsStore, [], true, !!schema);
|
|
613
|
+
const newCtx = transact(store, attrsStore, steps);
|
|
614
|
+
|
|
615
|
+
const result = query(newCtx, {
|
|
616
|
+
todos: {},
|
|
617
|
+
fakeUsers: {},
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
expect(result.data.todos.length).toBe(1);
|
|
621
|
+
expect(result.data.fakeUsers.length).toBe(1);
|
|
622
|
+
|
|
623
|
+
const removeOp = [instatx.tx.todos[sameId].delete()];
|
|
624
|
+
|
|
625
|
+
const removeSteps = instaml.transform(newCtx, removeOp);
|
|
626
|
+
const postRemoveCtx = transact(newCtx.store, newCtx.attrsStore, removeSteps);
|
|
627
|
+
|
|
628
|
+
const removeResult = query(postRemoveCtx, {
|
|
629
|
+
todos: {},
|
|
630
|
+
fakeUsers: {},
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
expect(removeResult.data.todos.length).toBe(0);
|
|
634
|
+
expect(removeResult.data.fakeUsers.length).toBe(1);
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
test('date conversion', () => {
|
|
638
|
+
expect(() => {
|
|
639
|
+
const schema = i.schema({
|
|
640
|
+
entities: {
|
|
641
|
+
todos: i.entity({
|
|
642
|
+
completed: i.boolean().optional(),
|
|
643
|
+
createdAt: i.date().optional(),
|
|
644
|
+
title: i.string().optional(),
|
|
645
|
+
}),
|
|
646
|
+
},
|
|
647
|
+
});
|
|
648
|
+
const sameId = id();
|
|
649
|
+
const ops = [
|
|
650
|
+
instatx.tx.todos[sameId].update({
|
|
651
|
+
title: 'todo',
|
|
652
|
+
completed: false,
|
|
653
|
+
createdAt: new Date(),
|
|
654
|
+
}),
|
|
655
|
+
];
|
|
656
|
+
|
|
657
|
+
const attrsStore = new AttrsStoreClass({}, null);
|
|
658
|
+
const steps = instaml.transform({ attrsStore, schema }, ops);
|
|
659
|
+
const store = createStore(attrsStore, [], true, true);
|
|
660
|
+
const newCtx = transact(store, attrsStore, steps);
|
|
661
|
+
|
|
662
|
+
const result = query(newCtx, {
|
|
663
|
+
todos: {},
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
expect(result.data.todos.length).toBe(1);
|
|
667
|
+
expect(result.data.todos[0].createdAt).toBeInstanceOf(Date);
|
|
668
|
+
}).not.toThrow();
|
|
669
|
+
|
|
670
|
+
expect(() => {
|
|
671
|
+
const schema = i.schema({
|
|
672
|
+
entities: {
|
|
673
|
+
todos: i.entity({
|
|
674
|
+
completed: i.boolean().optional(),
|
|
675
|
+
createdAt: i.date().optional(),
|
|
676
|
+
title: i.string().optional(),
|
|
677
|
+
}),
|
|
678
|
+
},
|
|
679
|
+
});
|
|
680
|
+
const sameId = id();
|
|
681
|
+
const ops = [
|
|
682
|
+
instatx.tx.todos[sameId].update({
|
|
683
|
+
title: 'todo',
|
|
684
|
+
completed: false,
|
|
685
|
+
createdAt: 99999999999999,
|
|
686
|
+
}),
|
|
687
|
+
];
|
|
688
|
+
|
|
689
|
+
const attrsStore = new AttrsStoreClass({}, null);
|
|
690
|
+
const steps = instaml.transform({ attrsStore, schema }, ops);
|
|
691
|
+
const store = createStore(attrsStore, [], true, false);
|
|
692
|
+
const newCtx = transact(store, attrsStore, steps);
|
|
693
|
+
|
|
694
|
+
const result = query(newCtx, {
|
|
695
|
+
todos: {},
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
expect(result.data.todos.length).toBe(1);
|
|
699
|
+
expect(result.data.todos[0].createdAt).toBeTypeOf('number');
|
|
700
|
+
}).not.toThrow();
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
test('v0 store restores', () => {
|
|
704
|
+
function toJSONOld(store) {
|
|
705
|
+
return {
|
|
706
|
+
__type: store.__type,
|
|
707
|
+
attrs: store.attrs,
|
|
708
|
+
triples: allMapValues(store.eav, 3),
|
|
709
|
+
cardinalityInference: store.cardinalityInference,
|
|
710
|
+
linkIndex: store.linkIndex,
|
|
711
|
+
useDateObjects: store.useDateObjects,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
const v0Json = toJSONOld({ ...store, attrs: zenecaAttrsStore.attrs });
|
|
715
|
+
const attrsStore = attrsStoreFromJSON(null, v0Json);
|
|
716
|
+
const restored = fromJSON(attrsStore!, v0Json);
|
|
717
|
+
expect(restored).toEqual(store);
|
|
718
|
+
});
|