@astrogate/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/THIRD_PARTY_NOTICES.md +17 -0
- package/dist/browser.d.ts +85 -0
- package/dist/browser.js +16 -0
- package/dist/database-binding.d.ts +7 -0
- package/dist/database-binding.js +11 -0
- package/dist/hosted-session.d.ts +1 -0
- package/dist/hosted-session.js +11 -0
- package/dist/http.d.ts +24 -0
- package/dist/http.js +92 -0
- package/dist/inventory.d.ts +7 -0
- package/dist/inventory.js +18 -0
- package/dist/management-read.d.ts +17 -0
- package/dist/management-read.js +104 -0
- package/dist/management.d.ts +347 -0
- package/dist/management.js +137 -0
- package/dist/operator.d.ts +136 -0
- package/dist/operator.js +53 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.js +10 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.js +30 -0
- package/dist/services.d.ts +7 -0
- package/dist/services.js +53 -0
- package/dist/storage.d.ts +68 -0
- package/dist/storage.js +30 -0
- package/dist/tasks.d.ts +42 -0
- package/dist/tasks.js +24 -0
- package/dist/wire.gen.d.ts +7107 -0
- package/dist/wire.gen.js +5 -0
- package/native-provenance.json +15 -0
- package/node_modules/@instantdb/admin/LICENSE +202 -0
- package/node_modules/@instantdb/admin/dist/esm/index.d.ts +607 -0
- package/node_modules/@instantdb/admin/dist/esm/index.js +1036 -0
- package/node_modules/@instantdb/admin/dist/esm/polyfill.d.ts +16 -0
- package/node_modules/@instantdb/admin/dist/esm/polyfill.js +21 -0
- package/node_modules/@instantdb/admin/dist/esm/subscribe.d.ts +38 -0
- package/node_modules/@instantdb/admin/dist/esm/subscribe.js +301 -0
- package/node_modules/@instantdb/admin/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/admin/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/admin/package.json +23 -0
- package/node_modules/@instantdb/core/LICENSE +202 -0
- package/node_modules/@instantdb/core/dist/esm/Connection.d.ts +92 -0
- package/node_modules/@instantdb/core/dist/esm/Connection.js +188 -0
- package/node_modules/@instantdb/core/dist/esm/InMemoryStorage.d.ts +10 -0
- package/node_modules/@instantdb/core/dist/esm/InMemoryStorage.js +25 -0
- package/node_modules/@instantdb/core/dist/esm/IndexedDBStorage.d.ts +17 -0
- package/node_modules/@instantdb/core/dist/esm/IndexedDBStorage.js +309 -0
- package/node_modules/@instantdb/core/dist/esm/InstantError.d.ts +6 -0
- package/node_modules/@instantdb/core/dist/esm/InstantError.js +23 -0
- package/node_modules/@instantdb/core/dist/esm/Reactor.d.ts +430 -0
- package/node_modules/@instantdb/core/dist/esm/Reactor.js +2369 -0
- package/node_modules/@instantdb/core/dist/esm/StorageAPI.d.ts +39 -0
- package/node_modules/@instantdb/core/dist/esm/StorageAPI.js +65 -0
- package/node_modules/@instantdb/core/dist/esm/Stream.d.ts +120 -0
- package/node_modules/@instantdb/core/dist/esm/Stream.js +811 -0
- package/node_modules/@instantdb/core/dist/esm/SyncTable.d.ts +144 -0
- package/node_modules/@instantdb/core/dist/esm/SyncTable.js +523 -0
- package/node_modules/@instantdb/core/dist/esm/WindowNetworkListener.d.ts +4 -0
- package/node_modules/@instantdb/core/dist/esm/WindowNetworkListener.js +19 -0
- package/node_modules/@instantdb/core/dist/esm/attrTypes.d.ts +25 -0
- package/node_modules/@instantdb/core/dist/esm/attrTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/authAPI.d.ts +64 -0
- package/node_modules/@instantdb/core/dist/esm/authAPI.js +103 -0
- package/node_modules/@instantdb/core/dist/esm/clientTypes.d.ts +40 -0
- package/node_modules/@instantdb/core/dist/esm/clientTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/coreTypes.d.ts +33 -0
- package/node_modules/@instantdb/core/dist/esm/coreTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/createRouteHandler.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/createRouteHandler.js +51 -0
- package/node_modules/@instantdb/core/dist/esm/datalog.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/datalog.js +99 -0
- package/node_modules/@instantdb/core/dist/esm/devtool.d.ts +3 -0
- package/node_modules/@instantdb/core/dist/esm/devtool.js +144 -0
- package/node_modules/@instantdb/core/dist/esm/framework.d.ts +80 -0
- package/node_modules/@instantdb/core/dist/esm/framework.js +243 -0
- package/node_modules/@instantdb/core/dist/esm/helperTypes.d.ts +75 -0
- package/node_modules/@instantdb/core/dist/esm/helperTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/index.d.ts +597 -0
- package/node_modules/@instantdb/core/dist/esm/index.js +649 -0
- package/node_modules/@instantdb/core/dist/esm/infiniteQuery.d.ts +25 -0
- package/node_modules/@instantdb/core/dist/esm/infiniteQuery.js +430 -0
- package/node_modules/@instantdb/core/dist/esm/instaml.d.ts +17 -0
- package/node_modules/@instantdb/core/dist/esm/instaml.js +576 -0
- package/node_modules/@instantdb/core/dist/esm/instaql.d.ts +12 -0
- package/node_modules/@instantdb/core/dist/esm/instaql.js +632 -0
- package/node_modules/@instantdb/core/dist/esm/instatx.d.ts +127 -0
- package/node_modules/@instantdb/core/dist/esm/instatx.js +93 -0
- package/node_modules/@instantdb/core/dist/esm/model/instaqlResult.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/model/instaqlResult.js +24 -0
- package/node_modules/@instantdb/core/dist/esm/parseSchemaFromJSON.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/parseSchemaFromJSON.js +142 -0
- package/node_modules/@instantdb/core/dist/esm/presence.d.ts +50 -0
- package/node_modules/@instantdb/core/dist/esm/presence.js +50 -0
- package/node_modules/@instantdb/core/dist/esm/presenceTypes.d.ts +9 -0
- package/node_modules/@instantdb/core/dist/esm/presenceTypes.js +3 -0
- package/node_modules/@instantdb/core/dist/esm/queryTypes.d.ts +271 -0
- package/node_modules/@instantdb/core/dist/esm/queryTypes.js +3 -0
- package/node_modules/@instantdb/core/dist/esm/queryValidation.d.ts +5 -0
- package/node_modules/@instantdb/core/dist/esm/queryValidation.js +287 -0
- package/node_modules/@instantdb/core/dist/esm/reactorTypes.d.ts +29 -0
- package/node_modules/@instantdb/core/dist/esm/reactorTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/routeHandlerProtocol.d.ts +19 -0
- package/node_modules/@instantdb/core/dist/esm/routeHandlerProtocol.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/rulesTypes.d.ts +85 -0
- package/node_modules/@instantdb/core/dist/esm/rulesTypes.js +1 -0
- package/node_modules/@instantdb/core/dist/esm/sanityCheckQueries.d.ts +18 -0
- package/node_modules/@instantdb/core/dist/esm/sanityCheckQueries.js +152 -0
- package/node_modules/@instantdb/core/dist/esm/schema.d.ts +72 -0
- package/node_modules/@instantdb/core/dist/esm/schema.js +128 -0
- package/node_modules/@instantdb/core/dist/esm/schemaTypes.d.ts +244 -0
- package/node_modules/@instantdb/core/dist/esm/schemaTypes.js +106 -0
- package/node_modules/@instantdb/core/dist/esm/store.d.ts +89 -0
- package/node_modules/@instantdb/core/dist/esm/store.js +722 -0
- package/node_modules/@instantdb/core/dist/esm/transactionValidation.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/transactionValidation.js +130 -0
- package/node_modules/@instantdb/core/dist/esm/utils/Deferred.d.ts +8 -0
- package/node_modules/@instantdb/core/dist/esm/utils/Deferred.js +17 -0
- package/node_modules/@instantdb/core/dist/esm/utils/PersistedObject.d.ts +80 -0
- package/node_modules/@instantdb/core/dist/esm/utils/PersistedObject.js +448 -0
- package/node_modules/@instantdb/core/dist/esm/utils/dates.d.ts +1 -0
- package/node_modules/@instantdb/core/dist/esm/utils/dates.js +211 -0
- package/node_modules/@instantdb/core/dist/esm/utils/error.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/utils/error.js +8 -0
- package/node_modules/@instantdb/core/dist/esm/utils/fetch.d.ts +125 -0
- package/node_modules/@instantdb/core/dist/esm/utils/fetch.js +31 -0
- package/node_modules/@instantdb/core/dist/esm/utils/flags.d.ts +4 -0
- package/node_modules/@instantdb/core/dist/esm/utils/flags.js +10 -0
- package/node_modules/@instantdb/core/dist/esm/utils/id.d.ts +3 -0
- package/node_modules/@instantdb/core/dist/esm/utils/id.js +25 -0
- package/node_modules/@instantdb/core/dist/esm/utils/linkIndex.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/utils/linkIndex.js +17 -0
- package/node_modules/@instantdb/core/dist/esm/utils/log.d.ts +6 -0
- package/node_modules/@instantdb/core/dist/esm/utils/log.js +13 -0
- package/node_modules/@instantdb/core/dist/esm/utils/object.d.ts +16 -0
- package/node_modules/@instantdb/core/dist/esm/utils/object.js +143 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pgtime.d.ts +197 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pgtime.js +197 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pick.d.ts +1 -0
- package/node_modules/@instantdb/core/dist/esm/utils/pick.js +9 -0
- package/node_modules/@instantdb/core/dist/esm/utils/strings.d.ts +1 -0
- package/node_modules/@instantdb/core/dist/esm/utils/strings.js +15 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHash.d.ts +15 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHash.js +71 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHashLegacy.d.ts +7 -0
- package/node_modules/@instantdb/core/dist/esm/utils/weakHashLegacy.js +72 -0
- package/node_modules/@instantdb/core/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/core/dist/esm/warningToggle.d.ts +2 -0
- package/node_modules/@instantdb/core/dist/esm/warningToggle.js +4 -0
- package/node_modules/@instantdb/core/package.json +20 -0
- package/node_modules/@instantdb/eventsource/LICENSE +22 -0
- package/node_modules/@instantdb/eventsource/README.md +226 -0
- package/node_modules/@instantdb/eventsource/dist/index.cjs +279 -0
- package/node_modules/@instantdb/eventsource/dist/index.cjs.map +1 -0
- package/node_modules/@instantdb/eventsource/dist/index.d.cts +346 -0
- package/node_modules/@instantdb/eventsource/dist/index.d.ts +346 -0
- package/node_modules/@instantdb/eventsource/dist/index.js +279 -0
- package/node_modules/@instantdb/eventsource/dist/index.js.map +1 -0
- package/node_modules/@instantdb/eventsource/package.json +128 -0
- package/node_modules/@instantdb/eventsource/src/EventSource.ts +614 -0
- package/node_modules/@instantdb/eventsource/src/errors.ts +141 -0
- package/node_modules/@instantdb/eventsource/src/index.ts +3 -0
- package/node_modules/@instantdb/eventsource/src/types.ts +164 -0
- package/node_modules/@instantdb/react/LICENSE +202 -0
- package/node_modules/@instantdb/react/dist/esm/Cursors.d.ts +18 -0
- package/node_modules/@instantdb/react/dist/esm/Cursors.js +103 -0
- package/node_modules/@instantdb/react/dist/esm/InstantReactWebDatabase.d.ts +5 -0
- package/node_modules/@instantdb/react/dist/esm/InstantReactWebDatabase.js +5 -0
- package/node_modules/@instantdb/react/dist/esm/index.d.ts +6 -0
- package/node_modules/@instantdb/react/dist/esm/index.js +22 -0
- package/node_modules/@instantdb/react/dist/esm/init.d.ts +40 -0
- package/node_modules/@instantdb/react/dist/esm/init.js +49 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/HydrationStreamProvider.d.ts +65 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/HydrationStreamProvider.js +96 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantNextDatabase.d.ts +11 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantNextDatabase.js +31 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantSuspenseProvider.d.ts +24 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/InstantSuspenseProvider.js +162 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/getUserFromInstantCookie.d.ts +9 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/getUserFromInstantCookie.js +16 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/htmlescape.d.ts +2 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/htmlescape.js +20 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/index.d.ts +29 -0
- package/node_modules/@instantdb/react/dist/esm/next-ssr/index.js +34 -0
- package/node_modules/@instantdb/react/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/react/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/react/package.json +24 -0
- package/node_modules/@instantdb/react-common/LICENSE +202 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactAbstractDatabase.d.ts +282 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactAbstractDatabase.js +386 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactRoom.d.ts +182 -0
- package/node_modules/@instantdb/react-common/dist/esm/InstantReactRoom.js +280 -0
- package/node_modules/@instantdb/react-common/dist/esm/index.d.ts +4 -0
- package/node_modules/@instantdb/react-common/dist/esm/index.js +3 -0
- package/node_modules/@instantdb/react-common/dist/esm/useInfiniteQuerySubscription.d.ts +27 -0
- package/node_modules/@instantdb/react-common/dist/esm/useInfiniteQuerySubscription.js +53 -0
- package/node_modules/@instantdb/react-common/dist/esm/useQuery.d.ts +6 -0
- package/node_modules/@instantdb/react-common/dist/esm/useQuery.js +75 -0
- package/node_modules/@instantdb/react-common/dist/esm/useTimeout.d.ts +4 -0
- package/node_modules/@instantdb/react-common/dist/esm/useTimeout.js +17 -0
- package/node_modules/@instantdb/react-common/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/react-common/dist/esm/version.js +2 -0
- package/node_modules/@instantdb/react-common/package.json +22 -0
- package/node_modules/@instantdb/version/LICENSE +202 -0
- package/node_modules/@instantdb/version/dist/esm/index.d.ts +2 -0
- package/node_modules/@instantdb/version/dist/esm/index.js +2 -0
- package/node_modules/@instantdb/version/dist/esm/version.d.ts +2 -0
- package/node_modules/@instantdb/version/dist/esm/version.js +5 -0
- package/node_modules/@instantdb/version/package.json +16 -0
- package/node_modules/@instantdb/webhooks/LICENSE +202 -0
- package/node_modules/@instantdb/webhooks/dist/esm/index.d.ts +587 -0
- package/node_modules/@instantdb/webhooks/dist/esm/index.js +748 -0
- package/node_modules/@instantdb/webhooks/package.json +18 -0
- package/node_modules/cookie/LICENSE +24 -0
- package/node_modules/cookie/README.md +295 -0
- package/node_modules/cookie/dist/index.d.ts +143 -0
- package/node_modules/cookie/dist/index.js +355 -0
- package/node_modules/cookie/dist/index.js.map +1 -0
- package/node_modules/cookie/package.json +57 -0
- package/node_modules/eventsource/LICENSE +22 -0
- package/node_modules/eventsource/README.md +252 -0
- package/node_modules/eventsource/dist/EventSource.d.ts +128 -0
- package/node_modules/eventsource/dist/EventSource.d.ts.map +1 -0
- package/node_modules/eventsource/dist/EventSource.js +556 -0
- package/node_modules/eventsource/dist/EventSource.js.map +1 -0
- package/node_modules/eventsource/dist/errors.d.ts +53 -0
- package/node_modules/eventsource/dist/errors.d.ts.map +1 -0
- package/node_modules/eventsource/dist/errors.js +120 -0
- package/node_modules/eventsource/dist/errors.js.map +1 -0
- package/node_modules/eventsource/dist/index.d.ts +4 -0
- package/node_modules/eventsource/dist/index.d.ts.map +1 -0
- package/node_modules/eventsource/dist/index.js +3 -0
- package/node_modules/eventsource/dist/index.js.map +1 -0
- package/node_modules/eventsource/dist/types.d.ts +156 -0
- package/node_modules/eventsource/dist/types.d.ts.map +1 -0
- package/node_modules/eventsource/dist/types.js +2 -0
- package/node_modules/eventsource/dist/types.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/LICENSE +21 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/README.md +177 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.d.ts +35 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.js +16 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/errors.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.d.ts +4 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.js +3 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/index.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.d.ts +12 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.js +509 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/parse.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.d.ts +76 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.js +59 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/stream.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.d.ts +130 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.d.ts.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.js +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/dist/types.js.map +1 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/package.json +96 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/errors.ts +44 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/index.ts +3 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/parse.ts +576 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/stream.ts +118 -0
- package/node_modules/eventsource/node_modules/eventsource-parser/src/types.ts +138 -0
- package/node_modules/eventsource/package.json +103 -0
- package/node_modules/eventsource/src/EventSource.ts +844 -0
- package/node_modules/eventsource/src/errors.ts +141 -0
- package/node_modules/eventsource/src/index.ts +3 -0
- package/node_modules/eventsource/src/types.ts +166 -0
- package/node_modules/eventsource-parser/LICENSE +21 -0
- package/node_modules/eventsource-parser/README.md +157 -0
- package/node_modules/eventsource-parser/dist/index.cjs +177 -0
- package/node_modules/eventsource-parser/dist/index.cjs.map +1 -0
- package/node_modules/eventsource-parser/dist/index.d.cts +169 -0
- package/node_modules/eventsource-parser/dist/index.d.ts +169 -0
- package/node_modules/eventsource-parser/dist/index.js +177 -0
- package/node_modules/eventsource-parser/dist/index.js.map +1 -0
- package/node_modules/eventsource-parser/dist/stream.cjs +29 -0
- package/node_modules/eventsource-parser/dist/stream.cjs.map +1 -0
- package/node_modules/eventsource-parser/dist/stream.d.cts +134 -0
- package/node_modules/eventsource-parser/dist/stream.d.ts +134 -0
- package/node_modules/eventsource-parser/dist/stream.js +30 -0
- package/node_modules/eventsource-parser/dist/stream.js.map +1 -0
- package/node_modules/eventsource-parser/package.json +92 -0
- package/node_modules/eventsource-parser/src/errors.ts +44 -0
- package/node_modules/eventsource-parser/src/index.ts +8 -0
- package/node_modules/eventsource-parser/src/parse.ts +439 -0
- package/node_modules/eventsource-parser/src/stream.ts +107 -0
- package/node_modules/eventsource-parser/src/types.ts +122 -0
- package/node_modules/eventsource-parser/stream.js +2 -0
- package/node_modules/mutative/LICENSE +21 -0
- package/node_modules/mutative/README.md +870 -0
- package/node_modules/mutative/dist/apply.d.ts +31 -0
- package/node_modules/mutative/dist/array.d.ts +45 -0
- package/node_modules/mutative/dist/constant.d.ts +8 -0
- package/node_modules/mutative/dist/create.d.ts +46 -0
- package/node_modules/mutative/dist/current.d.ts +23 -0
- package/node_modules/mutative/dist/draft.d.ts +3 -0
- package/node_modules/mutative/dist/draftify.d.ts +2 -0
- package/node_modules/mutative/dist/error.d.ts +54 -0
- package/node_modules/mutative/dist/index.d.mts +1 -0
- package/node_modules/mutative/dist/index.d.ts +12 -0
- package/node_modules/mutative/dist/index.js +8 -0
- package/node_modules/mutative/dist/index.mjs +3 -0
- package/node_modules/mutative/dist/interface.d.ts +200 -0
- package/node_modules/mutative/dist/internal.d.ts +4 -0
- package/node_modules/mutative/dist/makeCreator.d.ts +54 -0
- package/node_modules/mutative/dist/map.d.ts +15 -0
- package/node_modules/mutative/dist/mutative.cjs.development.js +2126 -0
- package/node_modules/mutative/dist/mutative.cjs.development.js.map +1 -0
- package/node_modules/mutative/dist/mutative.cjs.production.min.js +2 -0
- package/node_modules/mutative/dist/mutative.cjs.production.min.js.map +1 -0
- package/node_modules/mutative/dist/mutative.esm.js +2123 -0
- package/node_modules/mutative/dist/mutative.esm.js.map +1 -0
- package/node_modules/mutative/dist/mutative.esm.mjs +2123 -0
- package/node_modules/mutative/dist/mutative.esm.mjs.map +1 -0
- package/node_modules/mutative/dist/mutative.esm.production.min.mjs +2 -0
- package/node_modules/mutative/dist/mutative.esm.production.min.mjs.map +1 -0
- package/node_modules/mutative/dist/mutative.umd.development.js +2132 -0
- package/node_modules/mutative/dist/mutative.umd.development.js.map +1 -0
- package/node_modules/mutative/dist/mutative.umd.production.min.js +2 -0
- package/node_modules/mutative/dist/mutative.umd.production.min.js.map +1 -0
- package/node_modules/mutative/dist/original.d.ts +19 -0
- package/node_modules/mutative/dist/patch.d.ts +2 -0
- package/node_modules/mutative/dist/rawReturn.d.ts +19 -0
- package/node_modules/mutative/dist/set.d.ts +14 -0
- package/node_modules/mutative/dist/unsafe.d.ts +34 -0
- package/node_modules/mutative/dist/utils/cast.d.ts +13 -0
- package/node_modules/mutative/dist/utils/copy.d.ts +5 -0
- package/node_modules/mutative/dist/utils/deepFreeze.d.ts +1 -0
- package/node_modules/mutative/dist/utils/draft.d.ts +27 -0
- package/node_modules/mutative/dist/utils/finalize.d.ts +13 -0
- package/node_modules/mutative/dist/utils/forEach.d.ts +1 -0
- package/node_modules/mutative/dist/utils/index.d.ts +7 -0
- package/node_modules/mutative/dist/utils/mark.d.ts +2 -0
- package/node_modules/mutative/dist/utils/marker.d.ts +5 -0
- package/node_modules/mutative/dist/utils/proto.d.ts +10 -0
- package/node_modules/mutative/package.json +142 -0
- package/node_modules/mutative/src/apply.ts +239 -0
- package/node_modules/mutative/src/array.ts +679 -0
- package/node_modules/mutative/src/constant.ts +17 -0
- package/node_modules/mutative/src/create.ts +27 -0
- package/node_modules/mutative/src/current.ts +206 -0
- package/node_modules/mutative/src/draft.ts +489 -0
- package/node_modules/mutative/src/draftify.ts +57 -0
- package/node_modules/mutative/src/error.ts +129 -0
- package/node_modules/mutative/src/index.ts +21 -0
- package/node_modules/mutative/src/interface.ts +321 -0
- package/node_modules/mutative/src/internal.ts +5 -0
- package/node_modules/mutative/src/makeCreator.ts +382 -0
- package/node_modules/mutative/src/map.ts +160 -0
- package/node_modules/mutative/src/original.ts +28 -0
- package/node_modules/mutative/src/patch.ts +386 -0
- package/node_modules/mutative/src/rawReturn.ts +41 -0
- package/node_modules/mutative/src/set.ts +201 -0
- package/node_modules/mutative/src/unsafe.ts +66 -0
- package/node_modules/mutative/src/utils/cast.ts +22 -0
- package/node_modules/mutative/src/utils/copy.ts +224 -0
- package/node_modules/mutative/src/utils/deepFreeze.ts +103 -0
- package/node_modules/mutative/src/utils/draft.ts +189 -0
- package/node_modules/mutative/src/utils/finalize.ts +232 -0
- package/node_modules/mutative/src/utils/forEach.ts +24 -0
- package/node_modules/mutative/src/utils/index.ts +7 -0
- package/node_modules/mutative/src/utils/mark.ts +11 -0
- package/node_modules/mutative/src/utils/marker.ts +34 -0
- package/node_modules/mutative/src/utils/proto.ts +38 -0
- package/node_modules/uuid/LICENSE.md +9 -0
- package/node_modules/uuid/README.md +491 -0
- package/node_modules/uuid/dist/index.d.ts +15 -0
- package/node_modules/uuid/dist/index.js +14 -0
- package/node_modules/uuid/dist/max.d.ts +2 -0
- package/node_modules/uuid/dist/max.js +1 -0
- package/node_modules/uuid/dist/md5.d.ts +2 -0
- package/node_modules/uuid/dist/md5.js +135 -0
- package/node_modules/uuid/dist/nil.d.ts +2 -0
- package/node_modules/uuid/dist/nil.js +1 -0
- package/node_modules/uuid/dist/parse.d.ts +3 -0
- package/node_modules/uuid/dist/parse.js +9 -0
- package/node_modules/uuid/dist/regex.d.ts +2 -0
- package/node_modules/uuid/dist/regex.js +1 -0
- package/node_modules/uuid/dist/rng.d.ts +1 -0
- package/node_modules/uuid/dist/rng.js +4 -0
- package/node_modules/uuid/dist/sha1.d.ts +2 -0
- package/node_modules/uuid/dist/sha1.js +70 -0
- package/node_modules/uuid/dist/stringify.d.ts +3 -0
- package/node_modules/uuid/dist/stringify.js +35 -0
- package/node_modules/uuid/dist/types.d.ts +22 -0
- package/node_modules/uuid/dist/types.js +1 -0
- package/node_modules/uuid/dist/uuid-bin.d.ts +1 -0
- package/node_modules/uuid/dist/uuid-bin.js +70 -0
- package/node_modules/uuid/dist/v1.d.ts +11 -0
- package/node_modules/uuid/dist/v1.js +87 -0
- package/node_modules/uuid/dist/v1ToV6.d.ts +3 -0
- package/node_modules/uuid/dist/v1ToV6.js +10 -0
- package/node_modules/uuid/dist/v3.d.ts +9 -0
- package/node_modules/uuid/dist/v3.js +9 -0
- package/node_modules/uuid/dist/v35.d.ts +7 -0
- package/node_modules/uuid/dist/v35.js +39 -0
- package/node_modules/uuid/dist/v4.d.ts +4 -0
- package/node_modules/uuid/dist/v4.js +29 -0
- package/node_modules/uuid/dist/v5.d.ts +9 -0
- package/node_modules/uuid/dist/v5.js +9 -0
- package/node_modules/uuid/dist/v6.d.ts +4 -0
- package/node_modules/uuid/dist/v6.js +20 -0
- package/node_modules/uuid/dist/v6ToV1.d.ts +2 -0
- package/node_modules/uuid/dist/v6ToV1.js +10 -0
- package/node_modules/uuid/dist/v7.d.ts +9 -0
- package/node_modules/uuid/dist/v7.js +68 -0
- package/node_modules/uuid/dist/validate.d.ts +2 -0
- package/node_modules/uuid/dist/validate.js +5 -0
- package/node_modules/uuid/dist/version.d.ts +2 -0
- package/node_modules/uuid/dist/version.js +8 -0
- package/node_modules/uuid/dist-node/bin/uuid +2 -0
- package/node_modules/uuid/dist-node/index.js +14 -0
- package/node_modules/uuid/dist-node/max.js +1 -0
- package/node_modules/uuid/dist-node/md5.js +11 -0
- package/node_modules/uuid/dist-node/nil.js +1 -0
- package/node_modules/uuid/dist-node/parse.js +9 -0
- package/node_modules/uuid/dist-node/regex.js +1 -0
- package/node_modules/uuid/dist-node/rng.js +4 -0
- package/node_modules/uuid/dist-node/sha1.js +11 -0
- package/node_modules/uuid/dist-node/stringify.js +35 -0
- package/node_modules/uuid/dist-node/types.js +1 -0
- package/node_modules/uuid/dist-node/uuid-bin.js +70 -0
- package/node_modules/uuid/dist-node/v1.js +87 -0
- package/node_modules/uuid/dist-node/v1ToV6.js +10 -0
- package/node_modules/uuid/dist-node/v3.js +9 -0
- package/node_modules/uuid/dist-node/v35.js +39 -0
- package/node_modules/uuid/dist-node/v4.js +29 -0
- package/node_modules/uuid/dist-node/v5.js +9 -0
- package/node_modules/uuid/dist-node/v6.js +20 -0
- package/node_modules/uuid/dist-node/v6ToV1.js +10 -0
- package/node_modules/uuid/dist-node/v7.js +68 -0
- package/node_modules/uuid/dist-node/validate.js +5 -0
- package/node_modules/uuid/dist-node/version.js +8 -0
- package/node_modules/uuid/package.json +115 -0
- package/package.json +80 -4
- package/release.json +78 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import type { EntitiesDef, IContainEntitiesAndLinks, InstantGraph, LinkAttrDef, RuleParams, ResolveAttrs, ResolveEntityAttrs, DataAttrDef, AttrsDefs, EntityDefFromSchema, InstantUnknownSchemaDef } from './schemaTypes.ts';
|
|
2
|
+
type BuiltIn = Date | Function | Error | RegExp;
|
|
3
|
+
type Primitive = string | number | boolean | symbol | null | undefined;
|
|
4
|
+
export type Expand<T> = T extends BuiltIn | Primitive ? T : T extends object ? T extends infer O ? {
|
|
5
|
+
[K in keyof O]: Expand<O[K]>;
|
|
6
|
+
} : never : T;
|
|
7
|
+
export type NonEmpty<T> = {
|
|
8
|
+
[K in keyof T]-?: Required<Pick<T, K>>;
|
|
9
|
+
}[keyof T];
|
|
10
|
+
type BaseWhereClauseValueComplex<V> = {
|
|
11
|
+
/** @deprecated use `$in` instead of `in` */
|
|
12
|
+
in?: V[];
|
|
13
|
+
$in?: V[];
|
|
14
|
+
/** @deprecated use `$ne` instead of `not` */
|
|
15
|
+
$not?: V;
|
|
16
|
+
$ne?: V;
|
|
17
|
+
$gt?: V;
|
|
18
|
+
$lt?: V;
|
|
19
|
+
$gte?: V;
|
|
20
|
+
$lte?: V;
|
|
21
|
+
};
|
|
22
|
+
type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
|
|
23
|
+
type WhereClauseValueComplex<V, R, I> = BaseWhereClauseValueComplex<V> & (IsAny<V> extends true ? {
|
|
24
|
+
$ilike?: string;
|
|
25
|
+
$like?: string;
|
|
26
|
+
$isNull?: boolean;
|
|
27
|
+
} : (V extends string ? {
|
|
28
|
+
$like?: string;
|
|
29
|
+
} : {}) & (R extends false ? {
|
|
30
|
+
$isNull?: boolean;
|
|
31
|
+
} : {}) & (I extends true ? {
|
|
32
|
+
$ilike?: string;
|
|
33
|
+
} : {}));
|
|
34
|
+
type WhereClauseValue<D extends DataAttrDef<string | number | boolean, boolean, boolean, boolean>> = D extends DataAttrDef<infer V, infer R, infer I, boolean> ? (IsAny<V> extends true ? string | number | boolean : V) | NonEmpty<WhereClauseValueComplex<V, R, I>> : never;
|
|
35
|
+
type WhereClauseColumnEntries<T extends {
|
|
36
|
+
[key: string]: DataAttrDef<any, boolean, boolean, boolean>;
|
|
37
|
+
}> = {
|
|
38
|
+
[key in keyof T]?: WhereClauseValue<T[key]>;
|
|
39
|
+
};
|
|
40
|
+
type WhereClauseComboEntries<T extends Record<any, DataAttrDef<any, boolean, boolean, boolean>>> = {
|
|
41
|
+
or?: WhereClauses<T>[] | WhereClauseValue<DataAttrDef<any, false, true, boolean>>;
|
|
42
|
+
and?: WhereClauses<T>[] | WhereClauseValue<DataAttrDef<any, false, true, boolean>>;
|
|
43
|
+
};
|
|
44
|
+
type WhereClauses<T extends Record<any, DataAttrDef<any, boolean, boolean, boolean>>> = (WhereClauseComboEntries<T> | (WhereClauseComboEntries<T> & WhereClauseColumnEntries<T>)) & {
|
|
45
|
+
id?: WhereClauseValue<DataAttrDef<string, false, true, boolean>>;
|
|
46
|
+
[key: `${string}.${string}`]: WhereClauseValue<DataAttrDef<any, false, true, boolean>>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* A tuple representing a cursor.
|
|
50
|
+
* These should not be constructed manually. The current format
|
|
51
|
+
* is an implementation detail that may change in the future.
|
|
52
|
+
* Use the `endCursor` or `startCursor` from the PageInfoResponse as the
|
|
53
|
+
* `before` or `after` field in the query options.
|
|
54
|
+
*/
|
|
55
|
+
type Cursor = [string, string, any, number];
|
|
56
|
+
type Direction = 'asc' | 'desc';
|
|
57
|
+
type IndexedKeys<Attrs extends AttrsDefs> = {
|
|
58
|
+
[K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, any, infer IsIndexed, boolean> ? IsIndexed extends true ? K : never : never;
|
|
59
|
+
}[keyof Attrs];
|
|
60
|
+
export type Order<Schema extends IContainEntitiesAndLinks<any, any>, EntityName extends keyof Schema['entities']> = IndexedKeys<Schema['entities'][EntityName]['attrs']> extends never ? {
|
|
61
|
+
serverCreatedAt?: Direction;
|
|
62
|
+
} : {
|
|
63
|
+
[K in IndexedKeys<Schema['entities'][EntityName]['attrs']>]?: Direction;
|
|
64
|
+
} & {
|
|
65
|
+
serverCreatedAt?: Direction;
|
|
66
|
+
};
|
|
67
|
+
type $Option<S extends IContainEntitiesAndLinks<any, any>, K extends keyof S['entities']> = {
|
|
68
|
+
$?: {
|
|
69
|
+
where?: WhereClauses<EntityDefFromSchema<S, K>>;
|
|
70
|
+
order?: Order<S, K>;
|
|
71
|
+
limit?: number;
|
|
72
|
+
last?: number;
|
|
73
|
+
first?: number;
|
|
74
|
+
offset?: number;
|
|
75
|
+
after?: Cursor;
|
|
76
|
+
afterInclusive?: boolean;
|
|
77
|
+
before?: Cursor;
|
|
78
|
+
beforeInclusive?: boolean;
|
|
79
|
+
fields?: InstaQLFields<S, K>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
type NamespaceVal = $Option<IContainEntitiesAndLinks<any, any>, keyof EntitiesDef> | ($Option<IContainEntitiesAndLinks<any, any>, keyof EntitiesDef> & Subquery);
|
|
83
|
+
type Subquery = {
|
|
84
|
+
[namespace: string]: NamespaceVal;
|
|
85
|
+
};
|
|
86
|
+
interface Query {
|
|
87
|
+
[namespace: string]: NamespaceVal;
|
|
88
|
+
}
|
|
89
|
+
type InstantObject = {
|
|
90
|
+
id: string;
|
|
91
|
+
[prop: string]: any;
|
|
92
|
+
};
|
|
93
|
+
type ResponseObject<K, Schema> = K extends keyof Schema ? {
|
|
94
|
+
id: string;
|
|
95
|
+
} & Schema[K] : InstantObject;
|
|
96
|
+
type IsEmptyObject<T> = T extends Record<string, never> ? true : false;
|
|
97
|
+
type ResponseOf<Q, Schema> = {
|
|
98
|
+
[K in keyof Q]: IsEmptyObject<Q[K]> extends true ? ResponseObject<K, Schema>[] : (ResponseOf<Q[K], Schema> & ResponseObject<K, Schema>)[];
|
|
99
|
+
};
|
|
100
|
+
type Remove$<T> = T extends object ? {
|
|
101
|
+
[K in keyof T as Exclude<K, '$'>]: Remove$<T[K]>;
|
|
102
|
+
} : T;
|
|
103
|
+
type Remove$NonRecursive<T> = T extends object ? {
|
|
104
|
+
[K in keyof T as Exclude<K, '$'>]: T[K];
|
|
105
|
+
} : T;
|
|
106
|
+
type QueryResponse<Q, Schema, WithCardinalityInference extends boolean = false, UseDates extends boolean = false> = Schema extends InstantGraph<infer E, any> ? InstaQLQueryResult<E, Q, WithCardinalityInference, UseDates> : ResponseOf<{
|
|
107
|
+
[K in keyof Q]: Remove$<Q[K]>;
|
|
108
|
+
}, Schema>;
|
|
109
|
+
type InstaQLResponse<Schema, Q, UseDates extends boolean = false> = Schema extends IContainEntitiesAndLinks<any, any> ? Q extends InstaQLParams<Schema> | undefined ? InstaQLResult<Schema, Q, UseDates> : never : never;
|
|
110
|
+
type PageInfoResponse<T> = {
|
|
111
|
+
[K in keyof T]: {
|
|
112
|
+
startCursor: Cursor;
|
|
113
|
+
endCursor: Cursor;
|
|
114
|
+
hasNextPage: boolean;
|
|
115
|
+
hasPreviousPage: boolean;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* (XXX)
|
|
120
|
+
* https://github.com/microsoft/TypeScript/issues/26051
|
|
121
|
+
*
|
|
122
|
+
* TypeScript can permit extra keys when a generic extends a type.
|
|
123
|
+
*
|
|
124
|
+
* For some reason, it makes it possible to write a query like so:
|
|
125
|
+
*
|
|
126
|
+
* dummyQuery({
|
|
127
|
+
* users: {
|
|
128
|
+
* $: { where: { "foo": 1 } },
|
|
129
|
+
* posts: {
|
|
130
|
+
* $: { "far": {} }
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* The problem: $: { "far": {} }
|
|
135
|
+
*
|
|
136
|
+
* This passes, when it should in reality fail. I don't know why
|
|
137
|
+
* adding `Exactly` fixes this, but it does.
|
|
138
|
+
*
|
|
139
|
+
* */
|
|
140
|
+
type Exactly<Parent, Child> = Parent & {
|
|
141
|
+
[K in keyof Child]: K extends keyof Parent ? Child[K] : never;
|
|
142
|
+
};
|
|
143
|
+
type SafeLookup<T, K extends readonly PropertyKey[]> = K extends [
|
|
144
|
+
infer First,
|
|
145
|
+
...infer Rest extends readonly PropertyKey[]
|
|
146
|
+
] ? First extends keyof NonNullable<T> ? SafeLookup<NonNullable<T>[First], Rest> | (T extends null | undefined ? undefined : never) : undefined : T;
|
|
147
|
+
type InstaQLEntitySubqueryResult<Schema extends IContainEntitiesAndLinks<EntitiesDef, any>, EntityName extends keyof Schema['entities'], Query extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {}, UseDates extends boolean = false> = {
|
|
148
|
+
[QueryPropName in keyof Query]: Schema['entities'][EntityName]['links'][QueryPropName] extends LinkAttrDef<infer Cardinality, infer LinkedEntityName> ? LinkedEntityName extends keyof Schema['entities'] ? Cardinality extends 'one' ? InstaQLEntity<Schema, LinkedEntityName, Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>, SafeLookup<Query, [QueryPropName, '$', 'fields']>, UseDates> | undefined : InstaQLEntity<Schema, LinkedEntityName, Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>, SafeLookup<Query, [QueryPropName, '$', 'fields']>, UseDates>[] : never : never;
|
|
149
|
+
};
|
|
150
|
+
type InstaQLQueryEntityLinksResult<Entities extends EntitiesDef, EntityName extends keyof Entities, Query extends {
|
|
151
|
+
[LinkAttrName in keyof Entities[EntityName]['links']]?: any;
|
|
152
|
+
}, WithCardinalityInference extends boolean, UseDates extends boolean = false> = {
|
|
153
|
+
[QueryPropName in keyof Query]: Entities[EntityName]['links'][QueryPropName] extends LinkAttrDef<infer Cardinality, infer LinkedEntityName> ? LinkedEntityName extends keyof Entities ? WithCardinalityInference extends true ? Cardinality extends 'one' ? InstaQLQueryEntityResult<Entities, LinkedEntityName, Query[QueryPropName], WithCardinalityInference, UseDates> | undefined : InstaQLQueryEntityResult<Entities, LinkedEntityName, Query[QueryPropName], WithCardinalityInference, UseDates>[] : InstaQLQueryEntityResult<Entities, LinkedEntityName, Query[QueryPropName], WithCardinalityInference, UseDates>[] : never : never;
|
|
154
|
+
};
|
|
155
|
+
type DistributePick<T, K extends string> = T extends any ? {
|
|
156
|
+
[P in K]: P extends keyof T ? T[P] : never;
|
|
157
|
+
} : never;
|
|
158
|
+
type InstaQLFields<S extends IContainEntitiesAndLinks<any, any>, K extends keyof S['entities']> = (Extract<keyof ResolveEntityAttrs<S['entities'][K]>, string> | 'id')[];
|
|
159
|
+
type ComputeAttrs<AllAttrs, Fields extends readonly string[] | undefined> = Fields extends readonly string[] ? DistributePick<AllAttrs, Exclude<Fields[number], 'id'>> : AllAttrs;
|
|
160
|
+
type InstaQLEntity<Schema extends IContainEntitiesAndLinks<EntitiesDef, any>, EntityName extends keyof Schema['entities'], Subquery extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {}, Fields extends InstaQLFields<Schema, EntityName> | undefined = undefined, UseDates extends boolean = false> = Expand<{
|
|
161
|
+
id: string;
|
|
162
|
+
} & ComputeAttrs<ResolveEntityAttrs<Schema['entities'][EntityName], UseDates>, Fields> & InstaQLEntitySubqueryResult<Schema, EntityName, Subquery, UseDates>>;
|
|
163
|
+
export type InstaQLQueryEntityResult<Entities extends EntitiesDef, EntityName extends keyof Entities, Query extends {
|
|
164
|
+
[QueryPropName in keyof Entities[EntityName]['links']]?: any;
|
|
165
|
+
}, WithCardinalityInference extends boolean, UseDates extends boolean> = {
|
|
166
|
+
id: string;
|
|
167
|
+
} & ResolveAttrs<Entities, EntityName, UseDates> & InstaQLQueryEntityLinksResult<Entities, EntityName, Query, WithCardinalityInference, UseDates>;
|
|
168
|
+
type InstaQLQueryResult<Entities extends EntitiesDef, Query, WithCardinalityInference extends boolean, UseDates extends boolean> = {
|
|
169
|
+
[QueryPropName in keyof Query]: QueryPropName extends keyof Entities ? InstaQLQueryEntityResult<Entities, QueryPropName, Query[QueryPropName], WithCardinalityInference, UseDates>[] : never;
|
|
170
|
+
};
|
|
171
|
+
type InstaQLResult<Schema extends IContainEntitiesAndLinks<EntitiesDef, any>, Query extends InstaQLParams<Schema> | undefined, UseDates extends boolean = false> = Expand<{
|
|
172
|
+
[QueryPropName in keyof Query]: QueryPropName extends keyof Schema['entities'] ? InstaQLEntity<Schema, QueryPropName, Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>, SafeLookup<Query, [QueryPropName, '$', 'fields']>, UseDates>[] : never;
|
|
173
|
+
}>;
|
|
174
|
+
type InstaQLEntitySubquery<Schema extends IContainEntitiesAndLinks<EntitiesDef, any>, EntityName extends keyof Schema['entities']> = {
|
|
175
|
+
[QueryPropName in keyof Schema['entities'][EntityName]['links']]?: $Option<Schema, EntityName> | ($Option<Schema, EntityName> & InstaQLEntitySubquery<Schema, Schema['entities'][EntityName]['links'][QueryPropName]['entityName']>);
|
|
176
|
+
};
|
|
177
|
+
type InstaQLQuerySubqueryParams<S extends IContainEntitiesAndLinks<any, any>, E extends keyof S['entities']> = {
|
|
178
|
+
[K in keyof S['entities'][E]['links']]?: $Option<S, S['entities'][E]['links'][K]['entityName']> | ($Option<S, S['entities'][E]['links'][K]['entityName']> & InstaQLQuerySubqueryParams<S, S['entities'][E]['links'][K]['entityName']>);
|
|
179
|
+
};
|
|
180
|
+
type InstaQLParams<S extends IContainEntitiesAndLinks<any, any>> = {
|
|
181
|
+
[K in keyof S['entities']]?: $Option<S, K> | ($Option<S, K> & InstaQLQuerySubqueryParams<S, K>);
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* @deprecated
|
|
185
|
+
* `InstaQLQueryParams` is deprecated. Use `InstaQLParams` instead.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* // Before
|
|
189
|
+
* const myQuery = {...} satisfies InstaQLQueryParams<Schema>
|
|
190
|
+
* // After
|
|
191
|
+
* const myQuery = {...} satisfies InstaQLParams<Schema>
|
|
192
|
+
*/
|
|
193
|
+
type InstaQLQueryParams<S extends IContainEntitiesAndLinks<any, any>> = InstaQLParams<S>;
|
|
194
|
+
type InstaQLOptions = {
|
|
195
|
+
ruleParams: RuleParams;
|
|
196
|
+
};
|
|
197
|
+
type ValidQueryObject<T extends Record<string, any>, Schema extends IContainEntitiesAndLinks<any, any>, EntityName extends keyof Schema['entities'], TopLevel extends boolean> = keyof T extends keyof Schema['entities'][EntityName]['links'] | '$' ? {
|
|
198
|
+
[K in keyof Schema['entities'][EntityName]['links']]?: ValidQueryObject<T[K], Schema, Schema['entities'][EntityName]['links'][K]['entityName'], false>;
|
|
199
|
+
} & {
|
|
200
|
+
$?: ValidDollarSignQuery<T['$'], Schema, EntityName, TopLevel>;
|
|
201
|
+
} : never;
|
|
202
|
+
type PaginationKeys = 'limit' | 'last' | 'first' | 'offset' | 'after' | 'afterInclusive' | 'before' | 'beforeInclusive';
|
|
203
|
+
type AllowedDollarSignKeys<TopLevel extends boolean> = TopLevel extends true ? PaginationKeys | 'where' | 'fields' | 'order' : 'where' | 'fields' | 'order' | 'limit';
|
|
204
|
+
type ValidFieldNames<S extends IContainEntitiesAndLinks<any, any>, EntityName extends keyof S['entities']> = Extract<keyof ResolveEntityAttrs<S['entities'][EntityName]>, string> | 'id';
|
|
205
|
+
type ValidDollarSignQuery<Input extends {
|
|
206
|
+
[key: string]: any;
|
|
207
|
+
}, Schema extends IContainEntitiesAndLinks<any, any>, EntityName extends keyof Schema['entities'], TopLevel extends boolean> = keyof Input extends AllowedDollarSignKeys<TopLevel> ? {
|
|
208
|
+
where?: ValidWhereObject<Input['where'], Schema, EntityName>;
|
|
209
|
+
fields?: ValidFieldNames<Schema, EntityName>[];
|
|
210
|
+
order?: Order<Schema, EntityName>;
|
|
211
|
+
limit?: number;
|
|
212
|
+
} & (TopLevel extends true ? {
|
|
213
|
+
last?: number;
|
|
214
|
+
first?: number;
|
|
215
|
+
offset?: number;
|
|
216
|
+
after?: Cursor;
|
|
217
|
+
afterInclusive?: boolean;
|
|
218
|
+
before?: Cursor;
|
|
219
|
+
beforeInclusive?: boolean;
|
|
220
|
+
} : {}) : never;
|
|
221
|
+
type StringifiableKey<T> = Extract<T, string | number | bigint | boolean>;
|
|
222
|
+
type ValidWhereNestedPath<T, K extends string | number | symbol, Schema extends IContainEntitiesAndLinks<any, any>> = T extends object ? K extends keyof T ? K : K extends `${infer K0}.${infer KR}` ? K0 extends keyof T ? T[K0] extends keyof Schema['entities'] ? `${K0}.${ValidWhereNestedPath<{
|
|
223
|
+
[K in keyof Schema['entities'][T[K0]]['links']]: Schema['entities'][T[K0]]['links'][K]['entityName'];
|
|
224
|
+
}, KR, Schema> | StringifiableKey<keyof Schema['entities'][T[K0]]['attrs']> | 'id'}` : string & keyof T : string & keyof T : string & keyof T : never;
|
|
225
|
+
type ValidDotPath<Input extends string | number | symbol, Schema extends IContainEntitiesAndLinks<any, any>, EntityName extends keyof Schema['entities']> = ValidWhereNestedPath<{
|
|
226
|
+
[K in keyof Schema['entities'][EntityName]['links']]: Schema['entities'][EntityName]['links'][K]['entityName'];
|
|
227
|
+
}, Input, Schema>;
|
|
228
|
+
type WhereOperatorObject<Input, V, R, I> = keyof Input extends keyof BaseWhereClauseValueComplex<V> | '$ilike' | '$like' | '$isNull' ? BaseWhereClauseValueComplex<V> & (IsAny<V> extends true ? {
|
|
229
|
+
$ilike?: string;
|
|
230
|
+
$like?: string;
|
|
231
|
+
$isNull?: boolean;
|
|
232
|
+
} : (V extends string ? {
|
|
233
|
+
$like?: string;
|
|
234
|
+
} : {}) & (R extends false ? {
|
|
235
|
+
$isNull?: boolean;
|
|
236
|
+
} : {}) & (I extends true ? {
|
|
237
|
+
$ilike?: string;
|
|
238
|
+
} : {})) : never;
|
|
239
|
+
type ValidWhereValue<Input, AttrDef extends DataAttrDef<any, any, any, boolean>> = AttrDef extends DataAttrDef<infer V, infer R, infer I, boolean> ? Input extends V ? V : NonEmpty<WhereOperatorObject<Input, V, R, I>> : never;
|
|
240
|
+
type NoDistribute<T> = [T] extends [any] ? T : never;
|
|
241
|
+
type ValidWhereObject<Input extends {
|
|
242
|
+
[key: string]: any;
|
|
243
|
+
} | undefined, Schema extends IContainEntitiesAndLinks<any, any>, EntityName extends keyof Schema['entities']> = Input extends undefined ? undefined : keyof Input extends ValidDotPath<keyof Input, Schema, EntityName> | keyof Schema['entities'][EntityName]['attrs'] | 'and' | 'or' | 'id' ? {
|
|
244
|
+
[K in ValidDotPath<keyof Input, Schema, EntityName>]?: ValidWhereValue<Input[K], ExtractAttrFromDotPath<K, Schema, EntityName>>;
|
|
245
|
+
} & {
|
|
246
|
+
[K in keyof Schema['entities'][EntityName]['attrs']]?: ValidWhereValue<Input[K], Schema['entities'][EntityName]['attrs'][K]>;
|
|
247
|
+
} & {
|
|
248
|
+
and?: Input extends {
|
|
249
|
+
and: Array<infer Item extends {
|
|
250
|
+
[key: string]: any;
|
|
251
|
+
} | undefined>;
|
|
252
|
+
} ? ValidWhereObject<NoDistribute<Item>, Schema, EntityName>[] : never;
|
|
253
|
+
or?: Input extends {
|
|
254
|
+
or: Array<infer Item extends {
|
|
255
|
+
[key: string]: any;
|
|
256
|
+
} | undefined>;
|
|
257
|
+
} ? ValidWhereObject<NoDistribute<Item>, Schema, EntityName>[] : never;
|
|
258
|
+
} & {
|
|
259
|
+
id?: ValidWhereValue<SafeLookup<Input, ['id']>, DataAttrDef<string, false, false, boolean>>;
|
|
260
|
+
} : never;
|
|
261
|
+
/**
|
|
262
|
+
* Extracts the attribute definition from a valid dot path.
|
|
263
|
+
* Given a dot path like "user.posts.title", this will resolve to the type of the "title" attribute.
|
|
264
|
+
* If the path is just a link name (e.g., "posts"), it defaults to the id field.
|
|
265
|
+
* Returns DataAttrDef or never
|
|
266
|
+
*/
|
|
267
|
+
type ExtractAttrFromDotPath<Path extends string | number | symbol, Schema extends IContainEntitiesAndLinks<any, any>, EntityName extends keyof Schema['entities']> = Path extends keyof Schema['entities'][EntityName]['attrs'] ? Schema['entities'][EntityName]['attrs'][Path] : Path extends 'id' ? DataAttrDef<string, false, false, boolean> : Path extends `${infer LinkName}.${infer RestPath}` ? LinkName extends keyof Schema['entities'][EntityName]['links'] ? ExtractAttrFromDotPath<RestPath, Schema, Schema['entities'][EntityName]['links'][LinkName]['entityName']> : never : Path extends keyof Schema['entities'][EntityName]['links'] ? DataAttrDef<string, false, false, boolean> : never;
|
|
268
|
+
type ValidQuery<Q extends Record<string, any>, S extends IContainEntitiesAndLinks<any, any>> = S extends InstantUnknownSchemaDef ? InstaQLParams<S> : keyof Q extends keyof S['entities'] ? {
|
|
269
|
+
[K in keyof S['entities']]?: ValidQueryObject<Q[K], S, K, true>;
|
|
270
|
+
} : never;
|
|
271
|
+
export { Query, QueryResponse, InstaQLResponse, PageInfoResponse, InstantObject, Exactly, Remove$, ValidQuery, InstaQLQueryResult, InstaQLParams, InstaQLOptions, InstaQLEntitySubquery, InstaQLEntity, InstaQLResult, InstaQLFields, Cursor, InstaQLQueryParams, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IContainEntitiesAndLinks } from './schemaTypes.ts';
|
|
2
|
+
export declare class QueryValidationError extends Error {
|
|
3
|
+
constructor(message: string, path?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare const validateQuery: (q: unknown, schema?: IContainEntitiesAndLinks<any, any>) => void;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { DataAttrDef, } from './schemaTypes.js';
|
|
2
|
+
import { validate as validateUUID } from 'uuid';
|
|
3
|
+
export class QueryValidationError extends Error {
|
|
4
|
+
constructor(message, path) {
|
|
5
|
+
const fullMessage = path ? `At path '${path}': ${message}` : message;
|
|
6
|
+
super(fullMessage);
|
|
7
|
+
this.name = 'QueryValidationError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const dollarSignKeys = [
|
|
11
|
+
'where',
|
|
12
|
+
'order',
|
|
13
|
+
'limit',
|
|
14
|
+
'last',
|
|
15
|
+
'first',
|
|
16
|
+
'offset',
|
|
17
|
+
'after',
|
|
18
|
+
'afterInclusive',
|
|
19
|
+
'before',
|
|
20
|
+
'beforeInclusive',
|
|
21
|
+
'fields',
|
|
22
|
+
'aggregate',
|
|
23
|
+
];
|
|
24
|
+
const getAttrType = (attrDef) => {
|
|
25
|
+
return attrDef.valueType || 'unknown';
|
|
26
|
+
};
|
|
27
|
+
const isValidValueForType = (value, expectedType, isAnyType = false) => {
|
|
28
|
+
if (isAnyType)
|
|
29
|
+
return true;
|
|
30
|
+
if (value === null || value === undefined)
|
|
31
|
+
return true;
|
|
32
|
+
switch (expectedType) {
|
|
33
|
+
case 'string':
|
|
34
|
+
return typeof value === 'string';
|
|
35
|
+
case 'number':
|
|
36
|
+
return typeof value === 'number' && !isNaN(value);
|
|
37
|
+
case 'boolean':
|
|
38
|
+
return typeof value === 'boolean';
|
|
39
|
+
case 'date':
|
|
40
|
+
return (value instanceof Date ||
|
|
41
|
+
typeof value === 'string' ||
|
|
42
|
+
typeof value === 'number');
|
|
43
|
+
default:
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const validateOperator = (op, opValue, expectedType, attrName, entityName, attrDef, path) => {
|
|
48
|
+
const isAnyType = attrDef.valueType === 'json';
|
|
49
|
+
const assertValidValue = (op, expectedType, opValue) => {
|
|
50
|
+
if (!isValidValueForType(opValue, expectedType, isAnyType)) {
|
|
51
|
+
throw new QueryValidationError(`Invalid value for operator '${op}' on attribute '${attrName}' in entity '${entityName}'. Expected ${expectedType}, but received: ${typeof opValue}`, path);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
switch (op) {
|
|
55
|
+
case 'in':
|
|
56
|
+
case '$in':
|
|
57
|
+
if (!Array.isArray(opValue)) {
|
|
58
|
+
throw new QueryValidationError(`Operator '${op}' for attribute '${attrName}' in entity '${entityName}' must be an array, but received: ${typeof opValue}`, path);
|
|
59
|
+
}
|
|
60
|
+
for (const item of opValue) {
|
|
61
|
+
assertValidValue(op, expectedType, item);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case '$not':
|
|
65
|
+
case '$ne':
|
|
66
|
+
case '$gt':
|
|
67
|
+
case '$lt':
|
|
68
|
+
case '$gte':
|
|
69
|
+
case '$lte':
|
|
70
|
+
assertValidValue(op, expectedType, opValue);
|
|
71
|
+
break;
|
|
72
|
+
case '$like':
|
|
73
|
+
case '$ilike':
|
|
74
|
+
assertValidValue(op, 'string', opValue);
|
|
75
|
+
if (op === '$ilike') {
|
|
76
|
+
if (!attrDef.isIndexed) {
|
|
77
|
+
throw new QueryValidationError(`Operator '${op}' can only be used with indexed attributes, but '${attrName}' in entity '${entityName}' is not indexed`, path);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
case '$isNull':
|
|
82
|
+
assertValidValue(op, 'boolean', opValue);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
throw new QueryValidationError(`Unknown operator '${op}' for attribute '${attrName}' in entity '${entityName}'`, path);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const validateWhereClauseValue = (value, attrName, attrDef, entityName, path) => {
|
|
89
|
+
const expectedType = getAttrType(attrDef);
|
|
90
|
+
const isAnyType = attrDef.valueType === 'json';
|
|
91
|
+
const isComplexObject = typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
92
|
+
if (isComplexObject) {
|
|
93
|
+
// For any type, allow complex objects without treating them as operators
|
|
94
|
+
if (isAnyType) {
|
|
95
|
+
return; // Any type accepts any value, including complex objects
|
|
96
|
+
}
|
|
97
|
+
const operators = value;
|
|
98
|
+
for (const [op, opValue] of Object.entries(operators)) {
|
|
99
|
+
validateOperator(op, opValue, expectedType, attrName, entityName, attrDef, `${path}.${op}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
if (!isValidValueForType(value, expectedType, isAnyType)) {
|
|
104
|
+
throw new QueryValidationError(`Invalid value for attribute '${attrName}' in entity '${entityName}'. Expected ${expectedType}, but received: ${typeof value}`, path);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const validateDotNotationAttribute = (dotPath, value, startEntityName, schema, path) => {
|
|
109
|
+
const pathParts = dotPath.split('.');
|
|
110
|
+
if (pathParts.length < 2) {
|
|
111
|
+
throw new QueryValidationError(`Invalid dot notation path '${dotPath}'. Must contain at least one dot.`, path);
|
|
112
|
+
}
|
|
113
|
+
let currentEntityName = startEntityName;
|
|
114
|
+
// Traverse all path parts except the last one (which should be an attribute)
|
|
115
|
+
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
116
|
+
const linkName = pathParts[i];
|
|
117
|
+
const currentEntity = schema.entities[currentEntityName];
|
|
118
|
+
if (!currentEntity) {
|
|
119
|
+
throw new QueryValidationError(`Entity '${currentEntityName}' does not exist in schema while traversing dot notation path '${dotPath}'.`, path);
|
|
120
|
+
}
|
|
121
|
+
const link = currentEntity.links[linkName];
|
|
122
|
+
if (!link) {
|
|
123
|
+
const availableLinks = Object.keys(currentEntity.links);
|
|
124
|
+
throw new QueryValidationError(`Link '${linkName}' does not exist on entity '${currentEntityName}' in dot notation path '${dotPath}'. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`, path);
|
|
125
|
+
}
|
|
126
|
+
currentEntityName = link.entityName;
|
|
127
|
+
}
|
|
128
|
+
// Validate the final attribute
|
|
129
|
+
const finalAttrName = pathParts[pathParts.length - 1];
|
|
130
|
+
const finalEntity = schema.entities[currentEntityName];
|
|
131
|
+
if (!finalEntity) {
|
|
132
|
+
throw new QueryValidationError(`Target entity '${currentEntityName}' does not exist in schema for dot notation path '${dotPath}'.`, path);
|
|
133
|
+
}
|
|
134
|
+
// Handle 'id' field specially - every entity has an id field
|
|
135
|
+
if (finalAttrName === 'id') {
|
|
136
|
+
if (typeof value == 'string' && !validateUUID(value)) {
|
|
137
|
+
throw new QueryValidationError(`Invalid value for id field in entity '${currentEntityName}'. Expected a UUID, but received: ${value}`, path);
|
|
138
|
+
}
|
|
139
|
+
validateWhereClauseValue(value, dotPath, new DataAttrDef('string', false, true), startEntityName, path);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const attrDef = finalEntity.attrs[finalAttrName];
|
|
143
|
+
if (Object.keys(finalEntity.links).includes(finalAttrName)) {
|
|
144
|
+
if (typeof value === 'string' && !validateUUID(value)) {
|
|
145
|
+
throw new QueryValidationError(`Invalid value for link '${finalAttrName}' in entity '${currentEntityName}'. Expected a UUID, but received: ${value}`, path);
|
|
146
|
+
}
|
|
147
|
+
validateWhereClauseValue(value, dotPath, new DataAttrDef('string', false, true), startEntityName, path);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (!attrDef) {
|
|
151
|
+
const availableAttrs = Object.keys(finalEntity.attrs);
|
|
152
|
+
throw new QueryValidationError(`Attribute '${finalAttrName}' does not exist on entity '${currentEntityName}' in dot notation path '${dotPath}'. Available attributes: ${availableAttrs.length > 0 ? availableAttrs.join(', ') + ', id' : 'id'}`, path);
|
|
153
|
+
}
|
|
154
|
+
// Validate the value against the attribute type
|
|
155
|
+
validateWhereClauseValue(value, dotPath, attrDef, startEntityName, path);
|
|
156
|
+
};
|
|
157
|
+
const validateWhereClause = (whereClause, entityName, schema, path) => {
|
|
158
|
+
for (const [key, value] of Object.entries(whereClause)) {
|
|
159
|
+
if (key === 'or' || key === 'and') {
|
|
160
|
+
if (Array.isArray(value)) {
|
|
161
|
+
for (const clause of value) {
|
|
162
|
+
if (typeof clause === 'object' && clause !== null) {
|
|
163
|
+
validateWhereClause(clause, entityName, schema, `${path}.${key}[${clause}]`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (key === 'id') {
|
|
170
|
+
validateWhereClauseValue(value, 'id', new DataAttrDef('string', false, true), entityName, `${path}.id`);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (key.includes('.')) {
|
|
174
|
+
validateDotNotationAttribute(key, value, entityName, schema, `${path}.${key}`);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const entityDef = schema.entities[entityName];
|
|
178
|
+
if (!entityDef)
|
|
179
|
+
continue;
|
|
180
|
+
const attrDef = entityDef.attrs[key];
|
|
181
|
+
const linkDef = entityDef.links[key];
|
|
182
|
+
if (!attrDef && !linkDef) {
|
|
183
|
+
const availableAttrs = Object.keys(entityDef.attrs);
|
|
184
|
+
const availableLinks = Object.keys(entityDef.links);
|
|
185
|
+
throw new QueryValidationError(`Attribute or link '${key}' does not exist on entity '${entityName}'. Available attributes: ${availableAttrs.length > 0 ? availableAttrs.join(', ') : 'none'}. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`, `${path}.${key}`);
|
|
186
|
+
}
|
|
187
|
+
if (attrDef) {
|
|
188
|
+
validateWhereClauseValue(value, key, attrDef, entityName, `${path}.${key}`);
|
|
189
|
+
}
|
|
190
|
+
else if (linkDef) {
|
|
191
|
+
// For links, we expect the value to be a string (ID of the linked entity)
|
|
192
|
+
// Create a synthetic string attribute definition for validation
|
|
193
|
+
if (typeof value === 'string' && !validateUUID(value)) {
|
|
194
|
+
throw new QueryValidationError(`Invalid value for link '${key}' in entity '${entityName}'. Expected a UUID, but received: ${value}`, `${path}.${key}`);
|
|
195
|
+
}
|
|
196
|
+
const syntheticAttrDef = new DataAttrDef('string', false, true);
|
|
197
|
+
validateWhereClauseValue(value, key, syntheticAttrDef, entityName, `${path}.${key}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const validateDollarObject = (dollarObj, entityName, schema, path, depth = 0) => {
|
|
202
|
+
for (const key of Object.keys(dollarObj)) {
|
|
203
|
+
if (!dollarSignKeys.includes(key)) {
|
|
204
|
+
throw new QueryValidationError(`Invalid query parameter '${key}' in $ object. Valid parameters are: ${dollarSignKeys.join(', ')}. Found: ${key}`, path);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Validate that pagination parameters are only used at top-level
|
|
208
|
+
const paginationParams = [
|
|
209
|
+
// 'limit', // only supported client side
|
|
210
|
+
'offset',
|
|
211
|
+
'before',
|
|
212
|
+
'beforeInclusive',
|
|
213
|
+
'after',
|
|
214
|
+
'afterInclusive',
|
|
215
|
+
'first',
|
|
216
|
+
'last',
|
|
217
|
+
];
|
|
218
|
+
for (const param of paginationParams) {
|
|
219
|
+
if (dollarObj[param] !== undefined && depth > 0) {
|
|
220
|
+
throw new QueryValidationError(`'${param}' can only be used on top-level namespaces. It cannot be used in nested queries.`, path);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (dollarObj.where && schema) {
|
|
224
|
+
if (typeof dollarObj.where !== 'object' || dollarObj.where === null) {
|
|
225
|
+
throw new QueryValidationError(`'where' clause must be an object in entity '${entityName}', but received: ${typeof dollarObj.where}`, path ? `${path}.where` : undefined);
|
|
226
|
+
}
|
|
227
|
+
validateWhereClause(dollarObj.where, entityName, schema, path ? `${path}.where` : 'where');
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const validateEntityInQuery = (queryPart, entityName, schema, path, depth = 0) => {
|
|
231
|
+
if (!queryPart || typeof queryPart !== 'object') {
|
|
232
|
+
throw new QueryValidationError(`Query part for entity '${entityName}' must be an object, but received: ${typeof queryPart}`, path);
|
|
233
|
+
}
|
|
234
|
+
for (const key of Object.keys(queryPart)) {
|
|
235
|
+
if (key !== '$') {
|
|
236
|
+
// Validate link exists
|
|
237
|
+
if (schema && !(key in schema.entities[entityName].links)) {
|
|
238
|
+
const availableLinks = Object.keys(schema.entities[entityName].links);
|
|
239
|
+
throw new QueryValidationError(`Link '${key}' does not exist on entity '${entityName}'. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`, `${path}.${key}`);
|
|
240
|
+
}
|
|
241
|
+
// Recursively validate nested query
|
|
242
|
+
const nestedQuery = queryPart[key];
|
|
243
|
+
if (typeof nestedQuery === 'object' && nestedQuery !== null) {
|
|
244
|
+
const linkedEntityName = schema?.entities[entityName].links[key]?.entityName;
|
|
245
|
+
if (linkedEntityName) {
|
|
246
|
+
validateEntityInQuery(nestedQuery, linkedEntityName, schema, `${path}.${key}`, depth + 1);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
// Validate $ object
|
|
252
|
+
const dollarObj = queryPart[key];
|
|
253
|
+
if (typeof dollarObj !== 'object' || dollarObj === null) {
|
|
254
|
+
throw new QueryValidationError(`Query parameter '$' must be an object in entity '${entityName}', but received: ${typeof dollarObj}`, `${path}.$`);
|
|
255
|
+
}
|
|
256
|
+
validateDollarObject(dollarObj, entityName, schema, `${path}.$`, depth);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
export const validateQuery = (q, schema) => {
|
|
261
|
+
if (typeof q !== 'object' || q === null) {
|
|
262
|
+
throw new QueryValidationError(`Query must be an object, but received: ${typeof q}${q === null ? ' (null)' : ''}`);
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(q)) {
|
|
265
|
+
throw new QueryValidationError(`Query must be an object, but received: ${typeof q}`);
|
|
266
|
+
}
|
|
267
|
+
const queryObj = q;
|
|
268
|
+
for (const topLevelKey of Object.keys(queryObj)) {
|
|
269
|
+
if (Array.isArray(q[topLevelKey])) {
|
|
270
|
+
throw new QueryValidationError(`Query keys must be strings, but found key of type: ${typeof topLevelKey}`, topLevelKey);
|
|
271
|
+
}
|
|
272
|
+
if (typeof topLevelKey !== 'string') {
|
|
273
|
+
throw new QueryValidationError(`Query keys must be strings, but found key of type: ${typeof topLevelKey}`, topLevelKey);
|
|
274
|
+
}
|
|
275
|
+
if (topLevelKey === '$$ruleParams') {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
// Check if the key is top level entity
|
|
279
|
+
if (schema) {
|
|
280
|
+
if (!schema.entities[topLevelKey]) {
|
|
281
|
+
const availableEntities = Object.keys(schema.entities);
|
|
282
|
+
throw new QueryValidationError(`Entity '${topLevelKey}' does not exist in schema. Available entities: ${availableEntities.length > 0 ? availableEntities.join(', ') : 'none'}`, topLevelKey);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
validateEntityInQuery(queryObj[topLevelKey], topLevelKey, schema, topLevelKey, 0);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PageInfoResponse } from './queryTypes.ts';
|
|
2
|
+
import { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';
|
|
3
|
+
export type QuerySubResult = {
|
|
4
|
+
store: Store;
|
|
5
|
+
attrsStore: AttrsStore;
|
|
6
|
+
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
7
|
+
aggregate?: any;
|
|
8
|
+
processedTxId?: number;
|
|
9
|
+
isExternal?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type QuerySub = {
|
|
12
|
+
q: Object;
|
|
13
|
+
eventId?: string;
|
|
14
|
+
lastAccessed?: number | null | undefined;
|
|
15
|
+
result?: QuerySubResult;
|
|
16
|
+
};
|
|
17
|
+
export type QuerySubResultInStorage = {
|
|
18
|
+
store: StoreJson;
|
|
19
|
+
attrsStore: AttrsStoreJson;
|
|
20
|
+
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
21
|
+
aggregate?: any;
|
|
22
|
+
processedTxId?: number;
|
|
23
|
+
};
|
|
24
|
+
export type QuerySubInStorage = {
|
|
25
|
+
q: Object;
|
|
26
|
+
eventId?: string;
|
|
27
|
+
lastAccessed?: number | null | undefined;
|
|
28
|
+
result?: QuerySubResultInStorage;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { User } from './clientTypes.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Known payloads sent to `firstPartyPath` and handled by
|
|
4
|
+
* `createInstantRouteHandler`.
|
|
5
|
+
*/
|
|
6
|
+
export type InstantRouteHandlerPayloadByType = {
|
|
7
|
+
'sync-user': {
|
|
8
|
+
appId: string;
|
|
9
|
+
user: User | null;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Known `type` values for Instant route handler request bodies. */
|
|
13
|
+
export type InstantRouteHandlerType = keyof InstantRouteHandlerPayloadByType;
|
|
14
|
+
/** A valid request body for Instant's first-party route handler protocol. */
|
|
15
|
+
export type InstantRouteHandlerBody<Type extends InstantRouteHandlerType = InstantRouteHandlerType> = {
|
|
16
|
+
[KnownType in Type]: {
|
|
17
|
+
type: KnownType;
|
|
18
|
+
} & InstantRouteHandlerPayloadByType[KnownType];
|
|
19
|
+
}[Type];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|