@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,1388 @@
|
|
|
1
|
+
import { test, expect, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import zenecaAttrs from './data/zeneca/attrs.json';
|
|
4
|
+
import zenecaTriples from './data/zeneca/triples.json';
|
|
5
|
+
import {
|
|
6
|
+
createStore,
|
|
7
|
+
transact,
|
|
8
|
+
AttrsStoreClass,
|
|
9
|
+
Store,
|
|
10
|
+
AttrsStore,
|
|
11
|
+
} from '../../src/store';
|
|
12
|
+
import query from '../../src/instaql';
|
|
13
|
+
import { tx, lookup } from '../../src/instatx';
|
|
14
|
+
import { i } from '../../src/index';
|
|
15
|
+
import * as instaml from '../../src/instaml';
|
|
16
|
+
import { randomUUID } from 'crypto';
|
|
17
|
+
|
|
18
|
+
const zenecaAttrsStore = new AttrsStoreClass(
|
|
19
|
+
zenecaAttrs.reduce((res, x) => {
|
|
20
|
+
res[x.id] = x;
|
|
21
|
+
return res;
|
|
22
|
+
}, {}),
|
|
23
|
+
null,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const store = createStore(
|
|
27
|
+
zenecaAttrsStore,
|
|
28
|
+
zenecaTriples as [string, string, any, number][],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const ctx = { store, attrsStore: zenecaAttrsStore };
|
|
32
|
+
|
|
33
|
+
test('Simple Query Without Where', () => {
|
|
34
|
+
expect(
|
|
35
|
+
query(ctx, { users: {} })
|
|
36
|
+
.data.users.map((x) => x.handle)
|
|
37
|
+
.sort(),
|
|
38
|
+
).toEqual(['alex', 'joe', 'nicolegf', 'stopa']);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('Simple Where', () => {
|
|
42
|
+
expect(
|
|
43
|
+
query(ctx, { users: { $: { where: { handle: 'joe' } } } })
|
|
44
|
+
.data.users.map((x) => x.handle)
|
|
45
|
+
.sort(),
|
|
46
|
+
).toEqual(['joe']);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('Simple Where has expected keys', () => {
|
|
50
|
+
expect(
|
|
51
|
+
Object.keys(
|
|
52
|
+
query(ctx, { users: { $: { where: { handle: 'joe' } } } }).data.users[0],
|
|
53
|
+
).sort(),
|
|
54
|
+
).toEqual(['createdAt', 'email', 'fullName', 'handle', 'id']);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('Simple Where with multiple clauses', () => {
|
|
58
|
+
expect(
|
|
59
|
+
query(ctx, {
|
|
60
|
+
users: {
|
|
61
|
+
$: {
|
|
62
|
+
where: {
|
|
63
|
+
'bookshelves.books.title': 'The Count of Monte Cristo',
|
|
64
|
+
handle: 'stopa',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
.data.users.map((x) => x.handle)
|
|
70
|
+
.sort(),
|
|
71
|
+
).toEqual(['stopa']);
|
|
72
|
+
|
|
73
|
+
expect(
|
|
74
|
+
query(ctx, {
|
|
75
|
+
users: {
|
|
76
|
+
$: {
|
|
77
|
+
where: {
|
|
78
|
+
'bookshelves.books.title': 'Title nobody has',
|
|
79
|
+
handle: 'stopa',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
.data.users.map((x) => x.handle)
|
|
85
|
+
.sort(),
|
|
86
|
+
).toEqual([]);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('Where in', () => {
|
|
90
|
+
expect(
|
|
91
|
+
query(ctx, {
|
|
92
|
+
users: {
|
|
93
|
+
$: {
|
|
94
|
+
where: {
|
|
95
|
+
handle: { in: ['stopa', 'joe'] },
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
})
|
|
100
|
+
.data.users.map((x) => x.handle)
|
|
101
|
+
.sort(),
|
|
102
|
+
).toEqual(['joe', 'stopa']);
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
query(ctx, {
|
|
106
|
+
users: {
|
|
107
|
+
$: {
|
|
108
|
+
where: {
|
|
109
|
+
handle: { $in: ['stopa', 'joe'] },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
.data.users.map((x) => x.handle)
|
|
115
|
+
.sort(),
|
|
116
|
+
).toEqual(['joe', 'stopa']);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('Where %like%', () => {
|
|
120
|
+
expect(
|
|
121
|
+
query(ctx, {
|
|
122
|
+
users: {
|
|
123
|
+
$: {
|
|
124
|
+
where: {
|
|
125
|
+
handle: { $like: '%o%' },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
.data.users.map((x) => x.handle)
|
|
131
|
+
.sort(),
|
|
132
|
+
).toEqual(['joe', 'nicolegf', 'stopa']);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('Where like equality', () => {
|
|
136
|
+
expect(
|
|
137
|
+
query(ctx, {
|
|
138
|
+
users: {
|
|
139
|
+
$: {
|
|
140
|
+
where: {
|
|
141
|
+
handle: { $like: 'joe' },
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
.data.users.map((x) => x.handle)
|
|
147
|
+
.sort(),
|
|
148
|
+
).toEqual(['joe']);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('Where startsWith deep', () => {
|
|
152
|
+
expect(
|
|
153
|
+
query(ctx, {
|
|
154
|
+
users: {
|
|
155
|
+
$: {
|
|
156
|
+
where: {
|
|
157
|
+
'bookshelves.books.title': { $like: '%Monte Cristo' },
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
.data.users.map((x) => x.handle)
|
|
163
|
+
.sort(),
|
|
164
|
+
).toEqual(['nicolegf', 'stopa']);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('Where endsWith deep', () => {
|
|
168
|
+
expect(
|
|
169
|
+
query(ctx, {
|
|
170
|
+
users: {
|
|
171
|
+
$: {
|
|
172
|
+
where: {
|
|
173
|
+
'bookshelves.books.title': { $like: 'Anti%' },
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
})
|
|
178
|
+
.data.users.map((x) => x.handle)
|
|
179
|
+
.sort(),
|
|
180
|
+
).toEqual(['alex', 'nicolegf', 'stopa']);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('like case sensitivity', () => {
|
|
184
|
+
function runQuery(where) {
|
|
185
|
+
return query(ctx, {
|
|
186
|
+
users: {
|
|
187
|
+
$: {
|
|
188
|
+
where: {
|
|
189
|
+
fullName: where,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
})
|
|
194
|
+
.data.users.map((x) => x.fullName)
|
|
195
|
+
.sort();
|
|
196
|
+
}
|
|
197
|
+
expect(runQuery({ $like: '%O%' })).toEqual([]);
|
|
198
|
+
expect(runQuery({ $ilike: '%O%' })).toEqual(['Joe Averbukh', 'Nicole']);
|
|
199
|
+
expect(runQuery({ $like: '%j%' })).toEqual([]);
|
|
200
|
+
expect(runQuery({ $ilike: '%j%' })).toEqual(['Joe Averbukh']);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('like special regex characters', () => {
|
|
204
|
+
// Special characters that need escaping in regex
|
|
205
|
+
const specialChars = [
|
|
206
|
+
['(', 'Stopa (The Hacker)'],
|
|
207
|
+
[')', 'The Hacker (Stopa)'],
|
|
208
|
+
['[', 'Stopa [Hacker]'],
|
|
209
|
+
[']', '[Hacker] Stopa'],
|
|
210
|
+
['{', 'Stopa {Hacker}'],
|
|
211
|
+
['}', '{Hacker} Stopa'],
|
|
212
|
+
['*', 'Stopa * Hacker'],
|
|
213
|
+
['+', 'Stopa + Hacker'],
|
|
214
|
+
['?', 'Stopa? Yes!'],
|
|
215
|
+
['^', 'Stopa ^ Hacker'],
|
|
216
|
+
['$', 'Stopa $ Hacker'],
|
|
217
|
+
['|', 'Stopa | Hacker'],
|
|
218
|
+
['\\', 'Stopa \\ Hacker'],
|
|
219
|
+
['.', 'Mr. Stopa'],
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
function renameStopa(store, newName) {
|
|
223
|
+
const chunk = tx.users[lookup('handle', 'stopa')].update({
|
|
224
|
+
fullName: newName,
|
|
225
|
+
});
|
|
226
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
227
|
+
return transact(store, zenecaAttrsStore, txSteps);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const [char, newName] of specialChars) {
|
|
231
|
+
const newCtx = renameStopa(store, newName);
|
|
232
|
+
const res = query(newCtx, {
|
|
233
|
+
users: {
|
|
234
|
+
$: { where: { fullName: { $like: `%${char}%` } } },
|
|
235
|
+
},
|
|
236
|
+
}).data.users;
|
|
237
|
+
expect(res[0]?.fullName).toBe(newName);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('Where and', () => {
|
|
242
|
+
expect(
|
|
243
|
+
query(ctx, {
|
|
244
|
+
users: {
|
|
245
|
+
$: {
|
|
246
|
+
where: {
|
|
247
|
+
and: [
|
|
248
|
+
{ 'bookshelves.books.title': 'The Count of Monte Cristo' },
|
|
249
|
+
{ 'bookshelves.books.title': 'Antifragile' },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
})
|
|
255
|
+
.data.users.map((x) => x.handle)
|
|
256
|
+
.sort(),
|
|
257
|
+
).toEqual(['nicolegf', 'stopa']);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test.each([
|
|
261
|
+
[
|
|
262
|
+
'multiple OR matches',
|
|
263
|
+
{
|
|
264
|
+
or: [{ handle: 'stopa' }, { handle: 'joe' }],
|
|
265
|
+
},
|
|
266
|
+
['joe', 'stopa'],
|
|
267
|
+
],
|
|
268
|
+
[
|
|
269
|
+
'mix of matching and non-matching',
|
|
270
|
+
{
|
|
271
|
+
or: [{ handle: 'nobody' }, { handle: 'stopa' }, { handle: 'everybody' }],
|
|
272
|
+
},
|
|
273
|
+
['stopa'],
|
|
274
|
+
],
|
|
275
|
+
[
|
|
276
|
+
'with and',
|
|
277
|
+
{
|
|
278
|
+
'bookshelves.books.title': 'The Count of Monte Cristo',
|
|
279
|
+
or: [{ handle: 'joe' }, { handle: 'stopa' }],
|
|
280
|
+
},
|
|
281
|
+
['stopa'],
|
|
282
|
+
],
|
|
283
|
+
[
|
|
284
|
+
'with references',
|
|
285
|
+
{
|
|
286
|
+
or: [
|
|
287
|
+
{ handle: 'joe' },
|
|
288
|
+
{
|
|
289
|
+
handle: 'stopa',
|
|
290
|
+
'bookshelves.books.title': 'The Count of Monte Cristo',
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
['joe', 'stopa'],
|
|
295
|
+
],
|
|
296
|
+
[
|
|
297
|
+
'with references in both `or` & `and` clauses, no matches',
|
|
298
|
+
{
|
|
299
|
+
'bookshelves.books.title': 'Unknown',
|
|
300
|
+
or: [
|
|
301
|
+
{ handle: 'joe' },
|
|
302
|
+
{
|
|
303
|
+
handle: 'stopa',
|
|
304
|
+
'bookshelves.books.title': 'The Count of Monte Cristo',
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
[],
|
|
309
|
+
],
|
|
310
|
+
[
|
|
311
|
+
'with references in both `or` & `and` clauses, with matches',
|
|
312
|
+
{
|
|
313
|
+
'bookshelves.books.title': 'A Promised Land',
|
|
314
|
+
or: [
|
|
315
|
+
{
|
|
316
|
+
handle: 'stopa',
|
|
317
|
+
'bookshelves.books.title': 'The Count of Monte Cristo',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
handle: 'joe',
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
},
|
|
324
|
+
['joe'],
|
|
325
|
+
],
|
|
326
|
+
[
|
|
327
|
+
'with nested ors',
|
|
328
|
+
{
|
|
329
|
+
or: [
|
|
330
|
+
{ or: [{ handle: 'stopa' }] },
|
|
331
|
+
{
|
|
332
|
+
handle: 'joe',
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
['joe', 'stopa'],
|
|
337
|
+
],
|
|
338
|
+
[
|
|
339
|
+
'with ands in ors',
|
|
340
|
+
{
|
|
341
|
+
or: [
|
|
342
|
+
{
|
|
343
|
+
or: [
|
|
344
|
+
{
|
|
345
|
+
and: [
|
|
346
|
+
{ or: [{ handle: 'stopa' }, { handle: 'joe' }] },
|
|
347
|
+
{ email: 'stopa@instantdb.com' },
|
|
348
|
+
],
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
handle: 'joe',
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
},
|
|
357
|
+
['joe', 'stopa'],
|
|
358
|
+
],
|
|
359
|
+
[
|
|
360
|
+
'with ands in ors in ands',
|
|
361
|
+
{
|
|
362
|
+
and: [
|
|
363
|
+
{ or: [{ and: [{ handle: 'stopa' }] }] },
|
|
364
|
+
{ or: [{ and: [{ or: [{ handle: 'stopa' }] }] }] },
|
|
365
|
+
],
|
|
366
|
+
},
|
|
367
|
+
['stopa'],
|
|
368
|
+
],
|
|
369
|
+
])('Where OR %s', (_, whereQuery, expected) => {
|
|
370
|
+
expect(
|
|
371
|
+
query(ctx, {
|
|
372
|
+
users: {
|
|
373
|
+
$: {
|
|
374
|
+
where: whereQuery,
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
})
|
|
378
|
+
.data.users.map((x) => x.handle)
|
|
379
|
+
.sort(),
|
|
380
|
+
).toEqual(expected);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('Get association', () => {
|
|
384
|
+
expect(
|
|
385
|
+
query(ctx, {
|
|
386
|
+
users: {
|
|
387
|
+
bookshelves: {},
|
|
388
|
+
$: { where: { handle: 'alex' } },
|
|
389
|
+
},
|
|
390
|
+
}).data.users.map((x) => [
|
|
391
|
+
x.handle,
|
|
392
|
+
x.bookshelves.map((x) => x.name).sort(),
|
|
393
|
+
]),
|
|
394
|
+
).toEqual([['alex', ['Nonfiction', 'Short Stories']]]);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test('Get reverse association', () => {
|
|
398
|
+
expect(
|
|
399
|
+
query(ctx, {
|
|
400
|
+
bookshelves: {
|
|
401
|
+
users: {},
|
|
402
|
+
$: { where: { name: 'Short Stories' } },
|
|
403
|
+
},
|
|
404
|
+
}).data.bookshelves.map((x) => [
|
|
405
|
+
x.name,
|
|
406
|
+
x.users.map((x) => x.handle).sort(),
|
|
407
|
+
]),
|
|
408
|
+
).toEqual([['Short Stories', ['alex']]]);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test('Get deep association', () => {
|
|
412
|
+
expect(
|
|
413
|
+
query(ctx, {
|
|
414
|
+
users: {
|
|
415
|
+
bookshelves: { books: {} },
|
|
416
|
+
$: { where: { handle: 'alex' } },
|
|
417
|
+
},
|
|
418
|
+
})
|
|
419
|
+
.data.users.flatMap((x) => x.bookshelves)
|
|
420
|
+
.flatMap((x) => x.books)
|
|
421
|
+
.map((x) => x.title),
|
|
422
|
+
).toEqual([
|
|
423
|
+
`"Surely You're Joking, Mr. Feynman!": Adventures of a Curious Character`,
|
|
424
|
+
'"What Do You Care What Other People Think?": Further Adventures of a Curious Character',
|
|
425
|
+
'The Spy and the Traitor',
|
|
426
|
+
'Antifragile',
|
|
427
|
+
'Atomic Habits',
|
|
428
|
+
'Catch and Kill',
|
|
429
|
+
'The Paper Menagerie and Other Stories',
|
|
430
|
+
'Stories of Your Life and Others',
|
|
431
|
+
"Aesop's Fables",
|
|
432
|
+
]);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test('Nested wheres', () => {
|
|
436
|
+
expect(
|
|
437
|
+
query(ctx, {
|
|
438
|
+
users: {
|
|
439
|
+
bookshelves: {
|
|
440
|
+
books: {},
|
|
441
|
+
$: { where: { name: 'Short Stories' } },
|
|
442
|
+
},
|
|
443
|
+
$: { where: { handle: 'alex' } },
|
|
444
|
+
},
|
|
445
|
+
})
|
|
446
|
+
.data.users.flatMap((x) => x.bookshelves)
|
|
447
|
+
.flatMap((x) => x.books)
|
|
448
|
+
.map((x) => x.title),
|
|
449
|
+
).toEqual([
|
|
450
|
+
'The Paper Menagerie and Other Stories',
|
|
451
|
+
'Stories of Your Life and Others',
|
|
452
|
+
"Aesop's Fables",
|
|
453
|
+
]);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
test('Nested wheres with OR queries', () => {
|
|
457
|
+
expect(
|
|
458
|
+
query(ctx, {
|
|
459
|
+
users: {
|
|
460
|
+
bookshelves: {
|
|
461
|
+
books: {},
|
|
462
|
+
$: {
|
|
463
|
+
where: { or: [{ name: 'Short Stories' }] },
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
$: { where: { handle: 'alex' } },
|
|
467
|
+
},
|
|
468
|
+
})
|
|
469
|
+
.data.users.flatMap((x) => x.bookshelves)
|
|
470
|
+
.flatMap((x) => x.books)
|
|
471
|
+
.map((x) => x.title),
|
|
472
|
+
).toEqual([
|
|
473
|
+
'The Paper Menagerie and Other Stories',
|
|
474
|
+
'Stories of Your Life and Others',
|
|
475
|
+
"Aesop's Fables",
|
|
476
|
+
]);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
test('Nested wheres with AND queries', () => {
|
|
480
|
+
expect(
|
|
481
|
+
query(ctx, {
|
|
482
|
+
users: {
|
|
483
|
+
bookshelves: {
|
|
484
|
+
books: {},
|
|
485
|
+
$: {
|
|
486
|
+
where: { and: [{ name: 'Short Stories' }, { order: 0 }] },
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
$: { where: { handle: 'alex' } },
|
|
490
|
+
},
|
|
491
|
+
})
|
|
492
|
+
.data.users.flatMap((x) => x.bookshelves)
|
|
493
|
+
.flatMap((x) => x.books)
|
|
494
|
+
.map((x) => x.title),
|
|
495
|
+
).toEqual([
|
|
496
|
+
'The Paper Menagerie and Other Stories',
|
|
497
|
+
'Stories of Your Life and Others',
|
|
498
|
+
"Aesop's Fables",
|
|
499
|
+
]);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
test('Deep where', () => {
|
|
503
|
+
expect(
|
|
504
|
+
query(ctx, {
|
|
505
|
+
users: {
|
|
506
|
+
$: { where: { 'bookshelves.books.title': "Aesop's Fables" } },
|
|
507
|
+
},
|
|
508
|
+
}).data.users.map((x) => x.handle),
|
|
509
|
+
).toEqual(['alex']);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
test('Missing etype', () => {
|
|
513
|
+
expect(query(ctx, { moopy: {} }).data).toEqual({ moopy: [] });
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
test('Missing inner etype', () => {
|
|
517
|
+
expect(
|
|
518
|
+
query(ctx, {
|
|
519
|
+
users: {
|
|
520
|
+
moopy: {},
|
|
521
|
+
$: { where: { handle: 'joe' } },
|
|
522
|
+
},
|
|
523
|
+
})
|
|
524
|
+
.data.users.map((x) => [x.handle, x.moopy])
|
|
525
|
+
.sort(),
|
|
526
|
+
).toEqual([['joe', []]]);
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
test('Missing filter attr', () => {
|
|
530
|
+
expect(
|
|
531
|
+
query(ctx, {
|
|
532
|
+
users: {
|
|
533
|
+
$: { where: { 'bookshelves.moopy': 'joe' } },
|
|
534
|
+
},
|
|
535
|
+
}).data,
|
|
536
|
+
).toEqual({ users: [] });
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
test('multiple connections', () => {
|
|
540
|
+
expect(
|
|
541
|
+
query(ctx, {
|
|
542
|
+
bookshelves: {
|
|
543
|
+
books: {},
|
|
544
|
+
users: {},
|
|
545
|
+
$: { where: { name: 'Short Stories' } },
|
|
546
|
+
},
|
|
547
|
+
}).data.bookshelves.map((x) => [
|
|
548
|
+
x.name,
|
|
549
|
+
x.users.map((x) => x.handle).sort(),
|
|
550
|
+
x.books.map((x) => x.title).sort(),
|
|
551
|
+
]),
|
|
552
|
+
).toEqual([
|
|
553
|
+
[
|
|
554
|
+
'Short Stories',
|
|
555
|
+
['alex'],
|
|
556
|
+
[
|
|
557
|
+
"Aesop's Fables",
|
|
558
|
+
'Stories of Your Life and Others',
|
|
559
|
+
'The Paper Menagerie and Other Stories',
|
|
560
|
+
],
|
|
561
|
+
],
|
|
562
|
+
]);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
test('query forward references work with and without id', () => {
|
|
566
|
+
const bookshelf = query(ctx, {
|
|
567
|
+
bookshelves: {
|
|
568
|
+
$: { where: { 'users.handle': 'stopa' } },
|
|
569
|
+
},
|
|
570
|
+
}).data.bookshelves[0];
|
|
571
|
+
|
|
572
|
+
const usersByBookshelfId = query(ctx, {
|
|
573
|
+
users: {
|
|
574
|
+
$: { where: { 'bookshelves.id': bookshelf.id } },
|
|
575
|
+
},
|
|
576
|
+
}).data.users.map((x) => x.handle);
|
|
577
|
+
|
|
578
|
+
const usersByBookshelfLinkFIeld = query(ctx, {
|
|
579
|
+
users: {
|
|
580
|
+
$: { where: { bookshelves: bookshelf.id } },
|
|
581
|
+
},
|
|
582
|
+
}).data.users.map((x) => x.handle);
|
|
583
|
+
|
|
584
|
+
expect(usersByBookshelfId).toEqual(['stopa']);
|
|
585
|
+
expect(usersByBookshelfLinkFIeld).toEqual(['stopa']);
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
test('query reverse references work with and without id', () => {
|
|
589
|
+
const stopa = query(ctx, {
|
|
590
|
+
users: {
|
|
591
|
+
$: { where: { handle: 'stopa' } },
|
|
592
|
+
},
|
|
593
|
+
}).data.users[0];
|
|
594
|
+
|
|
595
|
+
const stopaBookshelvesByHandle = query(ctx, {
|
|
596
|
+
bookshelves: {
|
|
597
|
+
$: { where: { 'users.handle': 'stopa' } },
|
|
598
|
+
},
|
|
599
|
+
}).data.bookshelves;
|
|
600
|
+
|
|
601
|
+
const stopaBookshelvesById = query(ctx, {
|
|
602
|
+
bookshelves: {
|
|
603
|
+
$: { where: { 'users.id': stopa.id } },
|
|
604
|
+
},
|
|
605
|
+
}).data.bookshelves;
|
|
606
|
+
|
|
607
|
+
const stopaBookshelvesByLinkField = query(ctx, {
|
|
608
|
+
bookshelves: {
|
|
609
|
+
$: { where: { users: stopa.id } },
|
|
610
|
+
},
|
|
611
|
+
}).data.bookshelves;
|
|
612
|
+
|
|
613
|
+
expect(stopaBookshelvesByHandle.length).toBe(16);
|
|
614
|
+
|
|
615
|
+
expect(stopaBookshelvesByHandle).toEqual(stopaBookshelvesById);
|
|
616
|
+
expect(stopaBookshelvesByHandle).toEqual(stopaBookshelvesByLinkField);
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
test('objects are created by etype', () => {
|
|
620
|
+
const stopa = query(ctx, {
|
|
621
|
+
users: {
|
|
622
|
+
$: { where: { handle: 'stopa' } },
|
|
623
|
+
},
|
|
624
|
+
}).data.users[0];
|
|
625
|
+
expect(stopa.email).toEqual('stopa@instantdb.com');
|
|
626
|
+
const chunk = tx.not_users[stopa.id].update({
|
|
627
|
+
email: 'this-should-not-change-users-stopa@gmail.com',
|
|
628
|
+
});
|
|
629
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
630
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
631
|
+
const newStopa = query(newCtx, {
|
|
632
|
+
users: {
|
|
633
|
+
$: { where: { handle: 'stopa' } },
|
|
634
|
+
},
|
|
635
|
+
}).data.users[0];
|
|
636
|
+
expect(newStopa.email).toEqual('stopa@instantdb.com');
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test('create and update triples in one tx', () => {
|
|
640
|
+
const userId = randomUUID();
|
|
641
|
+
|
|
642
|
+
const getUser = (ctx: { store: Store; attrsStore: AttrsStore }) =>
|
|
643
|
+
query(ctx, { users: { $: { where: { id: userId } } } }).data.users[0];
|
|
644
|
+
|
|
645
|
+
const chunk1 = tx.users[userId].create({
|
|
646
|
+
email: 'e@mail',
|
|
647
|
+
handle: 'handle',
|
|
648
|
+
});
|
|
649
|
+
const ctx1 = transact(
|
|
650
|
+
store,
|
|
651
|
+
zenecaAttrsStore,
|
|
652
|
+
instaml.transform({ attrsStore: zenecaAttrsStore }, chunk1),
|
|
653
|
+
);
|
|
654
|
+
const user1 = getUser(ctx1);
|
|
655
|
+
expect(user1.email).toEqual('e@mail');
|
|
656
|
+
expect(user1.fullName).toEqual(undefined);
|
|
657
|
+
|
|
658
|
+
const chunk2 = tx.users[userId].update(
|
|
659
|
+
{
|
|
660
|
+
email: 'e@mail 2',
|
|
661
|
+
fullName: 'Full Name',
|
|
662
|
+
},
|
|
663
|
+
{ upsert: false },
|
|
664
|
+
);
|
|
665
|
+
const ctx2 = transact(
|
|
666
|
+
ctx1.store,
|
|
667
|
+
ctx1.attrsStore,
|
|
668
|
+
instaml.transform({ attrsStore: zenecaAttrsStore }, chunk2),
|
|
669
|
+
);
|
|
670
|
+
const user2 = getUser(ctx2);
|
|
671
|
+
expect(user2.email).toEqual('e@mail 2');
|
|
672
|
+
expect(user2.fullName).toEqual('Full Name');
|
|
673
|
+
});
|
|
674
|
+
|
|
675
|
+
test('object values', () => {
|
|
676
|
+
const stopa = query(ctx, {
|
|
677
|
+
users: {
|
|
678
|
+
$: { where: { handle: 'stopa' } },
|
|
679
|
+
},
|
|
680
|
+
}).data.users[0];
|
|
681
|
+
expect(stopa.email).toEqual('stopa@instantdb.com');
|
|
682
|
+
const chunk = tx.users[stopa.id].update({
|
|
683
|
+
jsonField: { hello: 'world' },
|
|
684
|
+
otherJsonField: { world: 'hello' },
|
|
685
|
+
});
|
|
686
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
687
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
688
|
+
const newStopa = query(newCtx, {
|
|
689
|
+
users: {
|
|
690
|
+
$: { where: { handle: 'stopa' } },
|
|
691
|
+
},
|
|
692
|
+
}).data.users[0];
|
|
693
|
+
|
|
694
|
+
expect(newStopa.jsonField).toEqual({ hello: 'world' });
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
test('pagination limit', () => {
|
|
698
|
+
const books = query(ctx, {
|
|
699
|
+
books: {
|
|
700
|
+
$: {
|
|
701
|
+
limit: 10,
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
}).data.books;
|
|
705
|
+
|
|
706
|
+
expect(books.length).toEqual(10);
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
test('nested limit works but warns', () => {
|
|
710
|
+
const warnMock = vi
|
|
711
|
+
.spyOn(console, 'warn')
|
|
712
|
+
.mockImplementation(() => undefined);
|
|
713
|
+
|
|
714
|
+
const result = query(ctx, {
|
|
715
|
+
bookshelves: {
|
|
716
|
+
books: {
|
|
717
|
+
$: {
|
|
718
|
+
limit: 4,
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
},
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
expect(result.data.bookshelves.length).toEqual(45);
|
|
725
|
+
// Should be "6" but is limited to 4
|
|
726
|
+
expect(result.data.bookshelves[1].books.length).toEqual(4);
|
|
727
|
+
// Warning
|
|
728
|
+
expect(warnMock).toHaveBeenCalled();
|
|
729
|
+
|
|
730
|
+
warnMock.mockRestore();
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
test('pagination offset waits for pageInfo', () => {
|
|
734
|
+
// If we don't have the pageInfo from the server, we have to
|
|
735
|
+
// wait to know which items in the store we should return.
|
|
736
|
+
// Otherwise, we might render optimistic changes for items
|
|
737
|
+
// that aren't in our range.
|
|
738
|
+
const booksWithOffset = query(ctx, {
|
|
739
|
+
books: {
|
|
740
|
+
$: {
|
|
741
|
+
offset: 10,
|
|
742
|
+
limit: 5,
|
|
743
|
+
},
|
|
744
|
+
},
|
|
745
|
+
}).data.books;
|
|
746
|
+
|
|
747
|
+
expect(booksWithOffset.length).toEqual(0);
|
|
748
|
+
|
|
749
|
+
const booksWithPageInfo = query(
|
|
750
|
+
{
|
|
751
|
+
store,
|
|
752
|
+
attrsStore: zenecaAttrsStore,
|
|
753
|
+
pageInfo: {
|
|
754
|
+
books: {
|
|
755
|
+
'start-cursor': [
|
|
756
|
+
'000212ec-fe77-473d-9494-d29898c53b7a',
|
|
757
|
+
'6eebf15a-ed3c-4442-8869-a44a7c85a1be',
|
|
758
|
+
'000212ec-fe77-473d-9494-d29898c53b7a',
|
|
759
|
+
1718118155976,
|
|
760
|
+
],
|
|
761
|
+
'end-cursor': [
|
|
762
|
+
'0270a27f-1363-4f6d-93c0-39cc43d92a78',
|
|
763
|
+
'6eebf15a-ed3c-4442-8869-a44a7c85a1be',
|
|
764
|
+
'0270a27f-1363-4f6d-93c0-39cc43d92a78',
|
|
765
|
+
1718118151976,
|
|
766
|
+
],
|
|
767
|
+
},
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
books: {
|
|
772
|
+
$: {
|
|
773
|
+
offset: 10,
|
|
774
|
+
limit: 5,
|
|
775
|
+
order: { serverCreatedAt: 'desc' },
|
|
776
|
+
},
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
).data.books;
|
|
780
|
+
|
|
781
|
+
expect(booksWithPageInfo.map((b) => b.title)).toEqual([
|
|
782
|
+
'Norse Mythology',
|
|
783
|
+
'Love-at-Arms',
|
|
784
|
+
'The Young Lions',
|
|
785
|
+
'The Hounds of God',
|
|
786
|
+
'Which Comes First, Cardio or Weights?',
|
|
787
|
+
]);
|
|
788
|
+
|
|
789
|
+
const booksWithPageInfoAsc = query(
|
|
790
|
+
{
|
|
791
|
+
store,
|
|
792
|
+
attrsStore: zenecaAttrsStore,
|
|
793
|
+
pageInfo: {
|
|
794
|
+
books: {
|
|
795
|
+
'start-cursor': [
|
|
796
|
+
'f11c998f-d951-426b-b2b1-ffcb8d17bac5',
|
|
797
|
+
'6eebf15a-ed3c-4442-8869-a44a7c85a1be',
|
|
798
|
+
'f11c998f-d951-426b-b2b1-ffcb8d17bac5',
|
|
799
|
+
1718117715976,
|
|
800
|
+
],
|
|
801
|
+
'end-cursor': [
|
|
802
|
+
'f1c15604-93cd-4189-bb9a-d4ee97b95f32',
|
|
803
|
+
'6eebf15a-ed3c-4442-8869-a44a7c85a1be',
|
|
804
|
+
'f1c15604-93cd-4189-bb9a-d4ee97b95f32',
|
|
805
|
+
1718117721976,
|
|
806
|
+
],
|
|
807
|
+
},
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
books: {
|
|
812
|
+
$: {
|
|
813
|
+
offset: 10,
|
|
814
|
+
limit: 5,
|
|
815
|
+
order: { serverCreatedAt: 'asc' },
|
|
816
|
+
},
|
|
817
|
+
},
|
|
818
|
+
},
|
|
819
|
+
).data.books;
|
|
820
|
+
|
|
821
|
+
expect(booksWithPageInfoAsc.map((b) => b.title)).toEqual([
|
|
822
|
+
'Sum',
|
|
823
|
+
'Insurgent',
|
|
824
|
+
'The Rational Male',
|
|
825
|
+
'The Restaurant at the End of the Universe',
|
|
826
|
+
'Bardelys the Magnificent',
|
|
827
|
+
]);
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
test('pagination last', () => {
|
|
831
|
+
const books = query(ctx, {
|
|
832
|
+
books: {
|
|
833
|
+
$: {
|
|
834
|
+
last: 10,
|
|
835
|
+
},
|
|
836
|
+
},
|
|
837
|
+
}).data.books;
|
|
838
|
+
|
|
839
|
+
expect(books.length).toEqual(10);
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
test('pagination first', () => {
|
|
843
|
+
const books = query(ctx, {
|
|
844
|
+
books: {
|
|
845
|
+
$: {
|
|
846
|
+
first: 10,
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
}).data.books;
|
|
850
|
+
|
|
851
|
+
expect(books.length).toEqual(10);
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
test('Leading queries should ignore the start cursor', () => {
|
|
855
|
+
function storeWithUpdatedNicole() {
|
|
856
|
+
const chunk = tx.users[lookup('handle', 'nicolegf')].update({
|
|
857
|
+
createdAt: '2025-09-05 18:53:07.993689',
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
861
|
+
return transact(store, zenecaAttrsStore, txSteps);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function storeWithBob() {
|
|
865
|
+
const chunk = tx.users[randomUUID()].update({
|
|
866
|
+
fullName: 'bob',
|
|
867
|
+
email: 'bob@instantdb.com',
|
|
868
|
+
handle: 'bob',
|
|
869
|
+
createdAt: '2025-09-05 18:53:07.993689',
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
873
|
+
return transact(store, zenecaAttrsStore, txSteps);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// Existing pageInfo from server: starts at Nicole (2021-02-05), ends at Alex (2021-01-09)
|
|
877
|
+
const pageInfo = {
|
|
878
|
+
users: {
|
|
879
|
+
'start-cursor': [
|
|
880
|
+
'0f3d67fc-8b37-4b03-ac47-29fec4edc4f7',
|
|
881
|
+
'2ffdf0fc-1561-4fc5-96db-2210a41adfa6',
|
|
882
|
+
'2021-02-05 22:35:23.754264',
|
|
883
|
+
1718118127976,
|
|
884
|
+
],
|
|
885
|
+
'end-cursor': [
|
|
886
|
+
'ad45e100-777a-4de8-8978-aa13200a4824',
|
|
887
|
+
'2ffdf0fc-1561-4fc5-96db-2210a41adfa6',
|
|
888
|
+
'2021-01-09 18:53:07.993689',
|
|
889
|
+
1718117855976,
|
|
890
|
+
],
|
|
891
|
+
},
|
|
892
|
+
};
|
|
893
|
+
const existingUsers = query(
|
|
894
|
+
{ store, attrsStore: zenecaAttrsStore, pageInfo },
|
|
895
|
+
{
|
|
896
|
+
users: {
|
|
897
|
+
$: {
|
|
898
|
+
limit: 2,
|
|
899
|
+
order: {
|
|
900
|
+
createdAt: 'desc',
|
|
901
|
+
},
|
|
902
|
+
},
|
|
903
|
+
},
|
|
904
|
+
},
|
|
905
|
+
).data.users.map((x) => x.handle);
|
|
906
|
+
expect(existingUsers).toEqual(['nicolegf', 'alex']);
|
|
907
|
+
|
|
908
|
+
// Let's update Nicole's createdAt to be later.
|
|
909
|
+
// She should _still_ show up,
|
|
910
|
+
// even though the cursor says otherwise
|
|
911
|
+
const usersWithUpdatedNicole = query(
|
|
912
|
+
{ ...storeWithUpdatedNicole(), pageInfo },
|
|
913
|
+
{
|
|
914
|
+
users: {
|
|
915
|
+
$: {
|
|
916
|
+
limit: 2,
|
|
917
|
+
order: {
|
|
918
|
+
createdAt: 'desc',
|
|
919
|
+
},
|
|
920
|
+
},
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
).data.users.map((x) => x.handle);
|
|
924
|
+
expect(usersWithUpdatedNicole).toEqual(['nicolegf', 'alex']);
|
|
925
|
+
|
|
926
|
+
// Let's add Bob.
|
|
927
|
+
// Bob _should_ show up,
|
|
928
|
+
// even though the cursor says otherwise
|
|
929
|
+
const usersWithBob = query(
|
|
930
|
+
{ ...storeWithBob(), pageInfo },
|
|
931
|
+
{
|
|
932
|
+
users: {
|
|
933
|
+
$: {
|
|
934
|
+
limit: 2,
|
|
935
|
+
order: {
|
|
936
|
+
createdAt: 'desc',
|
|
937
|
+
},
|
|
938
|
+
},
|
|
939
|
+
},
|
|
940
|
+
},
|
|
941
|
+
).data.users.map((x) => x.handle);
|
|
942
|
+
expect(usersWithBob).toEqual(['bob', 'nicolegf']);
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
test('Leading queries should ignore the end cursor for optimistic adds', () => {
|
|
946
|
+
// Simulates the offline optimistic add bug:
|
|
947
|
+
// 1. Server returns data with an end-cursor (last entity in asc order)
|
|
948
|
+
// 2. Client optimistically adds a new entity with a value beyond the end-cursor
|
|
949
|
+
// 3. The new entity should still appear (leading queries have no bounds)
|
|
950
|
+
|
|
951
|
+
// pageInfo with end-cursor pointing to nicolegf (last in asc createdAt order)
|
|
952
|
+
const pageInfo = {
|
|
953
|
+
users: {
|
|
954
|
+
'start-cursor': [
|
|
955
|
+
'a55a5231-5c4d-4033-b859-7790c45c22d5', // stopa (first in asc)
|
|
956
|
+
'2ffdf0fc-1561-4fc5-96db-2210a41adfa6', // createdAt attr id
|
|
957
|
+
'2021-01-07 18:50:43.447955',
|
|
958
|
+
1718117867976,
|
|
959
|
+
],
|
|
960
|
+
'end-cursor': [
|
|
961
|
+
'0f3d67fc-8b37-4b03-ac47-29fec4edc4f7', // nicolegf (last in asc)
|
|
962
|
+
'2ffdf0fc-1561-4fc5-96db-2210a41adfa6', // createdAt attr id
|
|
963
|
+
'2021-02-05 22:35:23.754264',
|
|
964
|
+
1718118127976,
|
|
965
|
+
],
|
|
966
|
+
},
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
// Optimistically add a new user with a createdAt AFTER the end cursor
|
|
970
|
+
const chunk = tx.users[randomUUID()].update({
|
|
971
|
+
fullName: 'New User',
|
|
972
|
+
email: 'new@instantdb.com',
|
|
973
|
+
handle: 'newuser',
|
|
974
|
+
createdAt: '2025-09-05 18:53:07.993689',
|
|
975
|
+
});
|
|
976
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
977
|
+
const { store: newStore, attrsStore: newAttrsStore } = transact(
|
|
978
|
+
store,
|
|
979
|
+
zenecaAttrsStore,
|
|
980
|
+
txSteps,
|
|
981
|
+
);
|
|
982
|
+
|
|
983
|
+
// Leading query (no offset/before/after) with ascending order
|
|
984
|
+
const result = query(
|
|
985
|
+
{ store: newStore, attrsStore: newAttrsStore, pageInfo },
|
|
986
|
+
{
|
|
987
|
+
users: {
|
|
988
|
+
$: {
|
|
989
|
+
order: { createdAt: 'asc' },
|
|
990
|
+
},
|
|
991
|
+
},
|
|
992
|
+
},
|
|
993
|
+
);
|
|
994
|
+
|
|
995
|
+
const handles = result.data.users.map((x) => x.handle);
|
|
996
|
+
expect(handles).toContain('newuser');
|
|
997
|
+
expect(handles).toEqual(['stopa', 'joe', 'alex', 'nicolegf', 'newuser']);
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
test('arbitrary ordering', () => {
|
|
1001
|
+
const books = query(ctx, {
|
|
1002
|
+
books: { $: { first: 10, order: { title: 'asc' } } },
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
const titles = books.data.books.map((x) => x.title);
|
|
1006
|
+
expect(titles).toEqual([
|
|
1007
|
+
`"Surely You're Joking, Mr. Feynman!": Adventures of a Curious Character`,
|
|
1008
|
+
'"What Do You Care What Other People Think?": Further Adventures of a Curious Character',
|
|
1009
|
+
'12 Rules for Life',
|
|
1010
|
+
'1984',
|
|
1011
|
+
'21 Lessons for the 21st Century',
|
|
1012
|
+
'A Conflict of Visions',
|
|
1013
|
+
'A Damsel in Distress',
|
|
1014
|
+
'A Guide to the Good Life',
|
|
1015
|
+
'A Hero Of Our Time',
|
|
1016
|
+
'A History of Private Life: From pagan Rome to Byzantium',
|
|
1017
|
+
]);
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
test('arbitrary ordering with dates', () => {
|
|
1021
|
+
const schema = i.schema({
|
|
1022
|
+
entities: {
|
|
1023
|
+
tests: i.entity({
|
|
1024
|
+
field: i.any(),
|
|
1025
|
+
date: i.date().indexed(),
|
|
1026
|
+
num: i.number().indexed(),
|
|
1027
|
+
}),
|
|
1028
|
+
},
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
const txSteps: any[] = [];
|
|
1032
|
+
let id = 0;
|
|
1033
|
+
for (let i = -5; i < 5; i++) {
|
|
1034
|
+
txSteps.push(
|
|
1035
|
+
tx.tests[randomUUID()].update({
|
|
1036
|
+
field: id++,
|
|
1037
|
+
date: i,
|
|
1038
|
+
num: i,
|
|
1039
|
+
}),
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
// Add a null date
|
|
1043
|
+
txSteps.push(
|
|
1044
|
+
// Use predefined uuid so we can predict ordering
|
|
1045
|
+
tx.tests['00000000-0000-0000-0000-000000000000'].update({
|
|
1046
|
+
field: id++,
|
|
1047
|
+
date: null,
|
|
1048
|
+
num: null,
|
|
1049
|
+
}),
|
|
1050
|
+
);
|
|
1051
|
+
// Add a missing date
|
|
1052
|
+
txSteps.push(
|
|
1053
|
+
tx.tests['00000000-0000-0000-0000-000000000001'].update({
|
|
1054
|
+
field: id++,
|
|
1055
|
+
}),
|
|
1056
|
+
);
|
|
1057
|
+
// Another null date
|
|
1058
|
+
txSteps.push(
|
|
1059
|
+
tx.tests['00000000-0000-0000-0000-000000000002'].update({
|
|
1060
|
+
date: null,
|
|
1061
|
+
num: null,
|
|
1062
|
+
field: id++,
|
|
1063
|
+
}),
|
|
1064
|
+
);
|
|
1065
|
+
// Another missing date
|
|
1066
|
+
txSteps.push(
|
|
1067
|
+
tx.tests['00000000-0000-0000-0000-000000000003'].update({
|
|
1068
|
+
field: id++,
|
|
1069
|
+
}),
|
|
1070
|
+
);
|
|
1071
|
+
|
|
1072
|
+
const newCtx = transact(
|
|
1073
|
+
store,
|
|
1074
|
+
zenecaAttrsStore,
|
|
1075
|
+
instaml.transform(
|
|
1076
|
+
{ attrsStore: zenecaAttrsStore, schema: schema },
|
|
1077
|
+
txSteps,
|
|
1078
|
+
),
|
|
1079
|
+
);
|
|
1080
|
+
|
|
1081
|
+
const descRes = query(newCtx, {
|
|
1082
|
+
tests: { $: { order: { date: 'desc' } } },
|
|
1083
|
+
}).data.tests.map((x) => x.date);
|
|
1084
|
+
|
|
1085
|
+
const numDescRes = query(newCtx, {
|
|
1086
|
+
tests: { $: { order: { num: 'desc' } } },
|
|
1087
|
+
}).data.tests.map((x) => x.num);
|
|
1088
|
+
|
|
1089
|
+
const descExpected = [
|
|
1090
|
+
4,
|
|
1091
|
+
3,
|
|
1092
|
+
2,
|
|
1093
|
+
1,
|
|
1094
|
+
0,
|
|
1095
|
+
-1,
|
|
1096
|
+
-2,
|
|
1097
|
+
-3,
|
|
1098
|
+
-4,
|
|
1099
|
+
-5,
|
|
1100
|
+
undefined,
|
|
1101
|
+
null,
|
|
1102
|
+
undefined,
|
|
1103
|
+
null,
|
|
1104
|
+
];
|
|
1105
|
+
|
|
1106
|
+
expect(descRes).toEqual(descExpected);
|
|
1107
|
+
|
|
1108
|
+
expect(numDescRes).toEqual(descExpected);
|
|
1109
|
+
|
|
1110
|
+
const ascRes = query(newCtx, {
|
|
1111
|
+
tests: { $: { order: { date: 'asc' } } },
|
|
1112
|
+
}).data.tests.map((x) => x.date);
|
|
1113
|
+
|
|
1114
|
+
const numAscRes = query(newCtx, {
|
|
1115
|
+
tests: { $: { order: { num: 'asc' } } },
|
|
1116
|
+
}).data.tests.map((x) => x.num);
|
|
1117
|
+
|
|
1118
|
+
const ascExpected = [
|
|
1119
|
+
null,
|
|
1120
|
+
undefined,
|
|
1121
|
+
null,
|
|
1122
|
+
undefined,
|
|
1123
|
+
-5,
|
|
1124
|
+
-4,
|
|
1125
|
+
-3,
|
|
1126
|
+
-2,
|
|
1127
|
+
-1,
|
|
1128
|
+
0,
|
|
1129
|
+
1,
|
|
1130
|
+
2,
|
|
1131
|
+
3,
|
|
1132
|
+
4,
|
|
1133
|
+
];
|
|
1134
|
+
|
|
1135
|
+
expect(ascRes).toEqual(ascExpected);
|
|
1136
|
+
expect(numAscRes).toEqual(ascExpected);
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
test('arbitrary ordering with strings', () => {
|
|
1140
|
+
const schema = i.schema({
|
|
1141
|
+
entities: {
|
|
1142
|
+
tests: i.entity({
|
|
1143
|
+
string: i.string().indexed(),
|
|
1144
|
+
}),
|
|
1145
|
+
},
|
|
1146
|
+
});
|
|
1147
|
+
|
|
1148
|
+
const txSteps: any[] = [];
|
|
1149
|
+
const vs = ['10', '2', 'a0', 'Zz'];
|
|
1150
|
+
for (const v of vs) {
|
|
1151
|
+
txSteps.push(
|
|
1152
|
+
tx.tests[randomUUID()].update({
|
|
1153
|
+
string: v,
|
|
1154
|
+
}),
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
const newCtx = transact(
|
|
1159
|
+
store,
|
|
1160
|
+
zenecaAttrsStore,
|
|
1161
|
+
instaml.transform(
|
|
1162
|
+
{ attrsStore: zenecaAttrsStore, schema: schema },
|
|
1163
|
+
txSteps,
|
|
1164
|
+
),
|
|
1165
|
+
);
|
|
1166
|
+
|
|
1167
|
+
const ascRes = query(newCtx, {
|
|
1168
|
+
tests: { $: { order: { string: 'asc' } } },
|
|
1169
|
+
}).data.tests.map((x) => x.string);
|
|
1170
|
+
|
|
1171
|
+
expect(ascRes).toEqual(vs);
|
|
1172
|
+
|
|
1173
|
+
const descRes = query(newCtx, {
|
|
1174
|
+
tests: { $: { order: { string: 'desc' } } },
|
|
1175
|
+
}).data.tests.map((x) => x.string);
|
|
1176
|
+
|
|
1177
|
+
// @ts-expect-error: doesn't like toReversed()
|
|
1178
|
+
expect(descRes).toEqual(vs.toReversed());
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
test('$isNull', () => {
|
|
1182
|
+
const q = { books: { $: { where: { title: { $isNull: true } } } } };
|
|
1183
|
+
expect(query(ctx, q).data.books.length).toEqual(0);
|
|
1184
|
+
const chunks = [
|
|
1185
|
+
tx.books[randomUUID()].update({ title: null }),
|
|
1186
|
+
tx.books[randomUUID()].update({ pageCount: 20 }),
|
|
1187
|
+
];
|
|
1188
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunks);
|
|
1189
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
1190
|
+
expect(query(newCtx, q).data.books.map((x) => x.title)).toEqual([
|
|
1191
|
+
null,
|
|
1192
|
+
undefined,
|
|
1193
|
+
]);
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
test('$isNull with relations', () => {
|
|
1197
|
+
const q = { users: { $: { where: { bookshelves: { $isNull: true } } } } };
|
|
1198
|
+
expect(query(ctx, q).data.users.length).toEqual(0);
|
|
1199
|
+
const chunks = [tx.users[randomUUID()].update({ handle: 'dww' })];
|
|
1200
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunks);
|
|
1201
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
1202
|
+
expect(query(newCtx, q).data.users.map((x) => x.handle)).toEqual(['dww']);
|
|
1203
|
+
|
|
1204
|
+
const bookId = query(ctx, {
|
|
1205
|
+
books: { $: { where: { title: 'The Count of Monte Cristo' } } },
|
|
1206
|
+
}).data.books[0].id;
|
|
1207
|
+
|
|
1208
|
+
const usersWithBook = query(ctx, {
|
|
1209
|
+
users: {
|
|
1210
|
+
$: {
|
|
1211
|
+
where: { 'bookshelves.books.title': 'The Count of Monte Cristo' },
|
|
1212
|
+
},
|
|
1213
|
+
},
|
|
1214
|
+
}).data.users.map((x) => x.handle);
|
|
1215
|
+
|
|
1216
|
+
const ctxWithNullTitle = transact(
|
|
1217
|
+
newCtx.store,
|
|
1218
|
+
newCtx.attrsStore,
|
|
1219
|
+
instaml.transform(newCtx, [tx.books[bookId].update({ title: null })]),
|
|
1220
|
+
);
|
|
1221
|
+
|
|
1222
|
+
const usersWithNullTitle = query(ctxWithNullTitle, {
|
|
1223
|
+
users: {
|
|
1224
|
+
$: {
|
|
1225
|
+
where: { 'bookshelves.books.title': { $isNull: true } },
|
|
1226
|
+
},
|
|
1227
|
+
},
|
|
1228
|
+
}).data.users.map((x) => x.handle);
|
|
1229
|
+
|
|
1230
|
+
expect(usersWithNullTitle).toEqual([...usersWithBook, 'dww']);
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
test('$isNull with reverse relations', () => {
|
|
1234
|
+
const q = {
|
|
1235
|
+
bookshelves: { $: { where: { 'users.id': { $isNull: true } } }, users: {} },
|
|
1236
|
+
};
|
|
1237
|
+
expect(query(ctx, q).data.bookshelves.length).toBe(0);
|
|
1238
|
+
|
|
1239
|
+
const chunks = [
|
|
1240
|
+
tx.bookshelves[randomUUID()].update({ name: 'Lonely shelf' }),
|
|
1241
|
+
];
|
|
1242
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunks);
|
|
1243
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
1244
|
+
expect(query(newCtx, q).data.bookshelves.map((x) => x.name)).toEqual([
|
|
1245
|
+
'Lonely shelf',
|
|
1246
|
+
]);
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
test('$not and $ne', () => {
|
|
1250
|
+
const qNot = { tests: { $: { where: { val: { $not: 'a' } } } } };
|
|
1251
|
+
const qNe = { tests: { $: { where: { val: { $ne: 'a' } } } } };
|
|
1252
|
+
const chunks = [
|
|
1253
|
+
tx.tests[randomUUID()].update({ val: 'a' }),
|
|
1254
|
+
tx.tests[randomUUID()].update({ val: 'b' }),
|
|
1255
|
+
tx.tests[randomUUID()].update({ val: 'c' }),
|
|
1256
|
+
tx.tests[randomUUID()].update({ val: null }),
|
|
1257
|
+
tx.tests[randomUUID()].update({ undefinedVal: 'd' }),
|
|
1258
|
+
];
|
|
1259
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunks);
|
|
1260
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
1261
|
+
const expected = ['b', 'c', null, undefined];
|
|
1262
|
+
expect(query(newCtx, qNot).data.tests.map((x) => x.val)).toEqual(expected);
|
|
1263
|
+
expect(query(newCtx, qNe).data.tests.map((x) => x.val)).toEqual(expected);
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1266
|
+
test('comparators', () => {
|
|
1267
|
+
const schema = i.schema({
|
|
1268
|
+
entities: {
|
|
1269
|
+
tests: i.entity({
|
|
1270
|
+
string: i.string().indexed(),
|
|
1271
|
+
number: i.number().indexed(),
|
|
1272
|
+
date: i.date().indexed(),
|
|
1273
|
+
boolean: i.boolean().indexed(),
|
|
1274
|
+
}),
|
|
1275
|
+
},
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
const txSteps: any[] = [];
|
|
1279
|
+
for (let i = 0; i < 5; i++) {
|
|
1280
|
+
txSteps.push(
|
|
1281
|
+
tx.tests[randomUUID()].update({
|
|
1282
|
+
string: `${i}`,
|
|
1283
|
+
number: i,
|
|
1284
|
+
date: i,
|
|
1285
|
+
boolean: i % 2 === 0,
|
|
1286
|
+
}),
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
const newCtx = transact(
|
|
1291
|
+
store,
|
|
1292
|
+
zenecaAttrsStore,
|
|
1293
|
+
instaml.transform(
|
|
1294
|
+
{ attrsStore: zenecaAttrsStore, schema: schema },
|
|
1295
|
+
txSteps,
|
|
1296
|
+
),
|
|
1297
|
+
);
|
|
1298
|
+
|
|
1299
|
+
function runQuery(dataType, op, value) {
|
|
1300
|
+
const res = query(newCtx, {
|
|
1301
|
+
tests: {
|
|
1302
|
+
$: { where: { [dataType]: { [op]: value } } },
|
|
1303
|
+
},
|
|
1304
|
+
});
|
|
1305
|
+
return res.data.tests.map((x) => x[dataType]);
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
expect(runQuery('string', '$gt', '2')).toEqual(['3', '4']);
|
|
1309
|
+
expect(runQuery('string', '$gte', '2')).toEqual(['2', '3', '4']);
|
|
1310
|
+
expect(runQuery('string', '$lt', '2')).toEqual(['0', '1']);
|
|
1311
|
+
expect(runQuery('string', '$lte', '2')).toEqual(['0', '1', '2']);
|
|
1312
|
+
|
|
1313
|
+
expect(runQuery('number', '$gt', 2)).toEqual([3, 4]);
|
|
1314
|
+
expect(runQuery('number', '$gte', 2)).toEqual([2, 3, 4]);
|
|
1315
|
+
expect(runQuery('number', '$lt', 2)).toEqual([0, 1]);
|
|
1316
|
+
expect(runQuery('number', '$lte', 2)).toEqual([0, 1, 2]);
|
|
1317
|
+
|
|
1318
|
+
expect(runQuery('date', '$gt', 2)).toEqual([3, 4]);
|
|
1319
|
+
expect(runQuery('date', '$gte', 2)).toEqual([2, 3, 4]);
|
|
1320
|
+
expect(runQuery('date', '$lt', 2)).toEqual([0, 1]);
|
|
1321
|
+
expect(runQuery('date', '$lte', 2)).toEqual([0, 1, 2]);
|
|
1322
|
+
|
|
1323
|
+
// Accepts string dates
|
|
1324
|
+
expect(
|
|
1325
|
+
runQuery('date', '$lt', JSON.parse(JSON.stringify(new Date()))),
|
|
1326
|
+
).toEqual([0, 1, 2, 3, 4]);
|
|
1327
|
+
expect(
|
|
1328
|
+
runQuery('date', '$gt', JSON.parse(JSON.stringify(new Date()))),
|
|
1329
|
+
).toEqual([]);
|
|
1330
|
+
|
|
1331
|
+
expect(runQuery('boolean', '$gt', true)).toEqual([]);
|
|
1332
|
+
expect(runQuery('boolean', '$gte', true)).toEqual([true, true, true]);
|
|
1333
|
+
expect(runQuery('boolean', '$lt', true)).toEqual([false, false]);
|
|
1334
|
+
expect(runQuery('boolean', '$lte', true)).toEqual([
|
|
1335
|
+
true,
|
|
1336
|
+
false,
|
|
1337
|
+
true,
|
|
1338
|
+
false,
|
|
1339
|
+
true,
|
|
1340
|
+
]);
|
|
1341
|
+
});
|
|
1342
|
+
|
|
1343
|
+
test('fields', () => {
|
|
1344
|
+
expect(query(ctx, { users: { $: { fields: ['handle'] } } }).data).toEqual({
|
|
1345
|
+
users: [
|
|
1346
|
+
{ handle: 'joe', id: 'ce942051-2d74-404a-9c7d-4aa3f2d54ae4' },
|
|
1347
|
+
{ handle: 'alex', id: 'ad45e100-777a-4de8-8978-aa13200a4824' },
|
|
1348
|
+
{ handle: 'stopa', id: 'a55a5231-5c4d-4033-b859-7790c45c22d5' },
|
|
1349
|
+
{ handle: 'nicolegf', id: '0f3d67fc-8b37-4b03-ac47-29fec4edc4f7' },
|
|
1350
|
+
],
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
expect(
|
|
1354
|
+
query(ctx, {
|
|
1355
|
+
users: {
|
|
1356
|
+
$: { where: { handle: 'alex' }, fields: ['handle'] },
|
|
1357
|
+
bookshelves: { $: { fields: ['name'] } },
|
|
1358
|
+
},
|
|
1359
|
+
}).data,
|
|
1360
|
+
).toEqual({
|
|
1361
|
+
users: [
|
|
1362
|
+
{
|
|
1363
|
+
handle: 'alex',
|
|
1364
|
+
id: 'ad45e100-777a-4de8-8978-aa13200a4824',
|
|
1365
|
+
bookshelves: [
|
|
1366
|
+
{
|
|
1367
|
+
name: 'Nonfiction',
|
|
1368
|
+
id: '8164fb78-6fa3-4aab-8b92-80e706bae93a',
|
|
1369
|
+
},
|
|
1370
|
+
{
|
|
1371
|
+
name: 'Short Stories',
|
|
1372
|
+
id: '4ad10e00-1353-437e-9fee-2a89eb53575d',
|
|
1373
|
+
},
|
|
1374
|
+
],
|
|
1375
|
+
},
|
|
1376
|
+
],
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
// id is always included
|
|
1380
|
+
expect(query(ctx, { users: { $: { fields: [] } } }).data).toEqual({
|
|
1381
|
+
users: [
|
|
1382
|
+
{ id: 'ce942051-2d74-404a-9c7d-4aa3f2d54ae4' },
|
|
1383
|
+
{ id: 'ad45e100-777a-4de8-8978-aa13200a4824' },
|
|
1384
|
+
{ id: 'a55a5231-5c4d-4033-b859-7790c45c22d5' },
|
|
1385
|
+
{ id: '0f3d67fc-8b37-4b03-ac47-29fec4edc4f7' },
|
|
1386
|
+
],
|
|
1387
|
+
});
|
|
1388
|
+
});
|