@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,811 @@
|
|
|
1
|
+
import uuid from './utils/id.js';
|
|
2
|
+
import { STATUS } from './Reactor.js';
|
|
3
|
+
import { InstantError } from './InstantError.js';
|
|
4
|
+
function createWriteStream({ WStream, opts, startStream, appendStream, registerStream, }) {
|
|
5
|
+
const clientId = opts.clientId;
|
|
6
|
+
let streamId_ = null;
|
|
7
|
+
let error_ = null;
|
|
8
|
+
let controller_ = null;
|
|
9
|
+
const reconnectToken = uuid();
|
|
10
|
+
let isDone = false;
|
|
11
|
+
let closed = false;
|
|
12
|
+
const closeCbs = [];
|
|
13
|
+
const streamIdCbs = [];
|
|
14
|
+
const completeCbs = [];
|
|
15
|
+
let disconnected = false;
|
|
16
|
+
// Chunks that we haven't been notified are flushed to disk
|
|
17
|
+
let bufferOffset = 0;
|
|
18
|
+
let bufferByteSize = 0;
|
|
19
|
+
const buffer = [];
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
function markClosed() {
|
|
22
|
+
closed = true;
|
|
23
|
+
for (const cb of closeCbs) {
|
|
24
|
+
cb(error_ ?? undefined);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function addCloseCb(cb) {
|
|
28
|
+
closeCbs.push(cb);
|
|
29
|
+
if (closed) {
|
|
30
|
+
cb(error_ ?? undefined);
|
|
31
|
+
}
|
|
32
|
+
return () => {
|
|
33
|
+
const i = closeCbs.indexOf(cb);
|
|
34
|
+
if (i !== -1) {
|
|
35
|
+
closeCbs.splice(i, 1);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function addCompleteCb(cb) {
|
|
40
|
+
completeCbs.push(cb);
|
|
41
|
+
return () => {
|
|
42
|
+
const i = completeCbs.indexOf(cb);
|
|
43
|
+
if (i !== -1) {
|
|
44
|
+
completeCbs.splice(i, 1);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (opts.waitUntil) {
|
|
49
|
+
opts.waitUntil(new Promise((resolve) => {
|
|
50
|
+
completeCbs.push(resolve);
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
function runCompleteCbs() {
|
|
54
|
+
for (const cb of completeCbs) {
|
|
55
|
+
try {
|
|
56
|
+
// cb could be provided by the user in the waitUntil,
|
|
57
|
+
// so protect against errors.
|
|
58
|
+
cb();
|
|
59
|
+
}
|
|
60
|
+
catch (_e) { }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function addStreamIdCb(cb) {
|
|
64
|
+
streamIdCbs.push(cb);
|
|
65
|
+
if (streamId_) {
|
|
66
|
+
cb(streamId_);
|
|
67
|
+
}
|
|
68
|
+
return () => {
|
|
69
|
+
const i = streamIdCbs.indexOf(cb);
|
|
70
|
+
if (i !== -1) {
|
|
71
|
+
streamIdCbs.splice(i, 1);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function setStreamId(streamId) {
|
|
76
|
+
streamId_ = streamId;
|
|
77
|
+
for (const cb of streamIdCbs) {
|
|
78
|
+
cb(streamId_);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function onDisconnect() {
|
|
82
|
+
disconnected = true;
|
|
83
|
+
}
|
|
84
|
+
// Clears data from our buffer after it has been flushed to a file
|
|
85
|
+
function discardFlushed(offset) {
|
|
86
|
+
let chunkOffset = bufferOffset;
|
|
87
|
+
let segmentsToDrop = 0;
|
|
88
|
+
let droppedSegmentsByteLen = 0;
|
|
89
|
+
for (const { byteLen } of buffer) {
|
|
90
|
+
const nextChunkOffset = chunkOffset + byteLen;
|
|
91
|
+
if (nextChunkOffset > offset) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
chunkOffset = nextChunkOffset;
|
|
95
|
+
segmentsToDrop++;
|
|
96
|
+
droppedSegmentsByteLen += byteLen;
|
|
97
|
+
}
|
|
98
|
+
if (segmentsToDrop > 0) {
|
|
99
|
+
bufferOffset += droppedSegmentsByteLen;
|
|
100
|
+
bufferByteSize -= droppedSegmentsByteLen;
|
|
101
|
+
buffer.splice(0, segmentsToDrop);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function error(controller, e) {
|
|
105
|
+
error_ = e;
|
|
106
|
+
markClosed();
|
|
107
|
+
controller.error(e);
|
|
108
|
+
runCompleteCbs();
|
|
109
|
+
}
|
|
110
|
+
async function onConnectionReconnect() {
|
|
111
|
+
const result = await startStream({
|
|
112
|
+
clientId,
|
|
113
|
+
reconnectToken,
|
|
114
|
+
ruleParams: opts.ruleParams,
|
|
115
|
+
});
|
|
116
|
+
switch (result.type) {
|
|
117
|
+
case 'ok': {
|
|
118
|
+
const { streamId, offset } = result;
|
|
119
|
+
streamId_ = streamId;
|
|
120
|
+
discardFlushed(offset);
|
|
121
|
+
if (buffer.length) {
|
|
122
|
+
appendStream({
|
|
123
|
+
streamId: streamId,
|
|
124
|
+
chunks: buffer.map((b) => b.chunk),
|
|
125
|
+
offset: bufferOffset,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
disconnected = false;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case 'disconnect': {
|
|
132
|
+
onDisconnect();
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'error': {
|
|
136
|
+
if (controller_) {
|
|
137
|
+
error(controller_, result.error);
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// When the append fails, we'll just try to reconnect and start again
|
|
144
|
+
function onAppendFailed() {
|
|
145
|
+
onDisconnect();
|
|
146
|
+
onConnectionReconnect();
|
|
147
|
+
}
|
|
148
|
+
function onFlush({ offset, done }) {
|
|
149
|
+
discardFlushed(offset);
|
|
150
|
+
if (done) {
|
|
151
|
+
isDone = true;
|
|
152
|
+
runCompleteCbs();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function ensureSetup(controller) {
|
|
156
|
+
if (isDone) {
|
|
157
|
+
error(controller, new InstantError('Stream has been closed.'));
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (!streamId_) {
|
|
161
|
+
error(controller, new InstantError('Stream has not been initialized.'));
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return streamId_;
|
|
165
|
+
}
|
|
166
|
+
async function start(controller) {
|
|
167
|
+
controller_ = controller;
|
|
168
|
+
let tryAgain = true;
|
|
169
|
+
let attempts = 0;
|
|
170
|
+
while (tryAgain) {
|
|
171
|
+
// rate-limit after the first few failed connects
|
|
172
|
+
let nextAttempt = Date.now() + Math.min(15000, 500 * (attempts - 1));
|
|
173
|
+
tryAgain = false;
|
|
174
|
+
const result = await startStream({
|
|
175
|
+
clientId: opts.clientId,
|
|
176
|
+
reconnectToken,
|
|
177
|
+
ruleParams: opts.ruleParams,
|
|
178
|
+
});
|
|
179
|
+
switch (result.type) {
|
|
180
|
+
case 'ok': {
|
|
181
|
+
const { streamId, offset } = result;
|
|
182
|
+
if (offset !== 0) {
|
|
183
|
+
const e = new InstantError('Write stream is corrupted');
|
|
184
|
+
error(controller, e);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
setStreamId(streamId);
|
|
188
|
+
registerStream(streamId, {
|
|
189
|
+
onDisconnect,
|
|
190
|
+
onFlush,
|
|
191
|
+
onConnectionReconnect,
|
|
192
|
+
onAppendFailed,
|
|
193
|
+
});
|
|
194
|
+
disconnected = false;
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
case 'disconnect': {
|
|
198
|
+
tryAgain = true;
|
|
199
|
+
onDisconnect();
|
|
200
|
+
attempts++;
|
|
201
|
+
await new Promise((resolve) => {
|
|
202
|
+
// Try again immediately for the first two attempts, then back off
|
|
203
|
+
setTimeout(resolve, Math.max(0, nextAttempt - Date.now()));
|
|
204
|
+
});
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
case 'error': {
|
|
208
|
+
error(controller, result.error);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
class WStreamEnhanced extends WStream {
|
|
215
|
+
constructor(sink, strategy) {
|
|
216
|
+
super(sink, strategy);
|
|
217
|
+
}
|
|
218
|
+
async streamId() {
|
|
219
|
+
if (streamId_) {
|
|
220
|
+
return streamId_;
|
|
221
|
+
}
|
|
222
|
+
return new Promise((resolve, reject) => {
|
|
223
|
+
const cleanupFns = [];
|
|
224
|
+
const cleanup = () => {
|
|
225
|
+
for (const f of cleanupFns) {
|
|
226
|
+
f();
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const resolveCb = (streamId) => {
|
|
230
|
+
resolve(streamId);
|
|
231
|
+
cleanup();
|
|
232
|
+
};
|
|
233
|
+
const rejectCb = (e) => {
|
|
234
|
+
reject(e || new InstantError('Stream is closed.'));
|
|
235
|
+
cleanup();
|
|
236
|
+
};
|
|
237
|
+
cleanupFns.push(addStreamIdCb(resolveCb));
|
|
238
|
+
cleanupFns.push(addCloseCb(rejectCb));
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const stream = new WStreamEnhanced({
|
|
243
|
+
// TODO(dww): accept a storage so that write streams can survive across
|
|
244
|
+
// browser restarts
|
|
245
|
+
async start(controller) {
|
|
246
|
+
try {
|
|
247
|
+
await start(controller);
|
|
248
|
+
}
|
|
249
|
+
catch (e) {
|
|
250
|
+
error(controller, e);
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
write(chunk, controller) {
|
|
254
|
+
const streamId = ensureSetup(controller);
|
|
255
|
+
if (streamId) {
|
|
256
|
+
const byteLen = encoder.encode(chunk).length;
|
|
257
|
+
buffer.push({ chunk, byteLen });
|
|
258
|
+
const offset = bufferOffset + bufferByteSize;
|
|
259
|
+
bufferByteSize += byteLen;
|
|
260
|
+
if (!disconnected) {
|
|
261
|
+
appendStream({ streamId, chunks: [chunk], offset });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
close() {
|
|
266
|
+
if (streamId_) {
|
|
267
|
+
appendStream({
|
|
268
|
+
streamId: streamId_,
|
|
269
|
+
chunks: [],
|
|
270
|
+
offset: bufferOffset + bufferByteSize,
|
|
271
|
+
isDone: true,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
runCompleteCbs();
|
|
276
|
+
}
|
|
277
|
+
markClosed();
|
|
278
|
+
},
|
|
279
|
+
abort(reason) {
|
|
280
|
+
if (streamId_) {
|
|
281
|
+
appendStream({
|
|
282
|
+
streamId: streamId_,
|
|
283
|
+
chunks: [],
|
|
284
|
+
offset: bufferOffset + bufferByteSize,
|
|
285
|
+
isDone: true,
|
|
286
|
+
abortReason: reason,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
runCompleteCbs();
|
|
291
|
+
}
|
|
292
|
+
markClosed();
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
stream,
|
|
297
|
+
addCompleteCb,
|
|
298
|
+
closed() {
|
|
299
|
+
return closed;
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
class StreamIterator {
|
|
304
|
+
items = [];
|
|
305
|
+
resolvers = [];
|
|
306
|
+
isClosed = false;
|
|
307
|
+
constructor() { }
|
|
308
|
+
push(item) {
|
|
309
|
+
if (this.isClosed)
|
|
310
|
+
return;
|
|
311
|
+
const resolve = this.resolvers.shift();
|
|
312
|
+
if (resolve) {
|
|
313
|
+
resolve({ value: item, done: false });
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
this.items.push(item);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
close() {
|
|
320
|
+
this.isClosed = true;
|
|
321
|
+
while (this.resolvers.length > 0) {
|
|
322
|
+
const resolve = this.resolvers.shift();
|
|
323
|
+
resolve({ value: undefined, done: true });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async *[Symbol.asyncIterator]() {
|
|
327
|
+
while (true) {
|
|
328
|
+
if (this.items.length > 0) {
|
|
329
|
+
yield this.items.shift();
|
|
330
|
+
}
|
|
331
|
+
else if (this.isClosed) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
const { value, done } = await new Promise((resolve) => {
|
|
336
|
+
this.resolvers.push(resolve);
|
|
337
|
+
});
|
|
338
|
+
if (done || !value) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
yield value;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function createReadStream({ RStream, opts, startStream, cancelStream, }) {
|
|
347
|
+
let seenOffset = opts.byteOffset || 0;
|
|
348
|
+
let canceled = false;
|
|
349
|
+
const decoder = new TextDecoder('utf-8');
|
|
350
|
+
const encoder = new TextEncoder();
|
|
351
|
+
let eventId;
|
|
352
|
+
let closed = false;
|
|
353
|
+
const closeCbs = [];
|
|
354
|
+
const streamIdCbs = [];
|
|
355
|
+
// Resolved stream id from the server
|
|
356
|
+
let streamId_ = null;
|
|
357
|
+
let error_ = null;
|
|
358
|
+
function markClosed(error) {
|
|
359
|
+
closed = true;
|
|
360
|
+
for (const cb of closeCbs) {
|
|
361
|
+
cb(error);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function addCloseCb(cb) {
|
|
365
|
+
closeCbs.push(cb);
|
|
366
|
+
return () => {
|
|
367
|
+
const i = closeCbs.indexOf(cb);
|
|
368
|
+
if (i !== -1) {
|
|
369
|
+
closeCbs.splice(i, 1);
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function addStreamIdCb(cb) {
|
|
374
|
+
streamIdCbs.push(cb);
|
|
375
|
+
if (streamId_) {
|
|
376
|
+
cb(streamId_);
|
|
377
|
+
}
|
|
378
|
+
return () => {
|
|
379
|
+
const i = streamIdCbs.indexOf(cb);
|
|
380
|
+
if (i !== -1) {
|
|
381
|
+
streamIdCbs.splice(i, 1);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function error(controller, e) {
|
|
386
|
+
error_ = e;
|
|
387
|
+
controller.error(e);
|
|
388
|
+
markClosed(e);
|
|
389
|
+
}
|
|
390
|
+
let fetchFailures = 0;
|
|
391
|
+
async function runStartStream(opts, controller) {
|
|
392
|
+
eventId = uuid();
|
|
393
|
+
const streamOpts = { ...(opts || {}), eventId };
|
|
394
|
+
for await (const item of startStream(streamOpts)) {
|
|
395
|
+
if (canceled) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (item.type === 'reconnect') {
|
|
399
|
+
return { retry: true };
|
|
400
|
+
}
|
|
401
|
+
if (item.type === 'error') {
|
|
402
|
+
error(controller, item.error);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (item.offset > seenOffset) {
|
|
406
|
+
error(controller, new InstantError('Stream is corrupted.'));
|
|
407
|
+
canceled = true;
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
streamId_ = item.streamId;
|
|
411
|
+
for (const cb of streamIdCbs) {
|
|
412
|
+
cb(streamId_);
|
|
413
|
+
}
|
|
414
|
+
let discardLen = seenOffset - item.offset;
|
|
415
|
+
if (item.files && item.files.length) {
|
|
416
|
+
const fetchAbort = new AbortController();
|
|
417
|
+
let nextFetch = fetch(item.files[0].url, {
|
|
418
|
+
signal: fetchAbort.signal,
|
|
419
|
+
});
|
|
420
|
+
for (let i = 0; i < item.files.length; i++) {
|
|
421
|
+
const nextFile = item.files[i + 1];
|
|
422
|
+
const thisFetch = nextFetch;
|
|
423
|
+
const res = await thisFetch;
|
|
424
|
+
if (nextFile) {
|
|
425
|
+
nextFetch = fetch(nextFile.url, { signal: fetchAbort.signal });
|
|
426
|
+
}
|
|
427
|
+
if (!res.ok) {
|
|
428
|
+
fetchFailures++;
|
|
429
|
+
if (fetchFailures > 10) {
|
|
430
|
+
error(controller, new InstantError('Unable to process stream.'));
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
return { retry: true };
|
|
434
|
+
}
|
|
435
|
+
if (res.body) {
|
|
436
|
+
const reader = res.body.getReader();
|
|
437
|
+
try {
|
|
438
|
+
while (true) {
|
|
439
|
+
const { done, value: bodyChunk } = await reader.read();
|
|
440
|
+
if (done) {
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
if (canceled) {
|
|
444
|
+
fetchAbort.abort();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
let chunk = bodyChunk;
|
|
448
|
+
if (discardLen > 0) {
|
|
449
|
+
chunk = bodyChunk.subarray(discardLen);
|
|
450
|
+
discardLen -= bodyChunk.length - chunk.length;
|
|
451
|
+
}
|
|
452
|
+
if (!chunk.length) {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
seenOffset += chunk.length;
|
|
456
|
+
const s = decoder.decode(chunk);
|
|
457
|
+
controller.enqueue(s);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
finally {
|
|
461
|
+
reader.releaseLock();
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
else {
|
|
465
|
+
// RN doesn't support request.body
|
|
466
|
+
const bodyChunk = await res.arrayBuffer();
|
|
467
|
+
let chunk = bodyChunk;
|
|
468
|
+
if (canceled) {
|
|
469
|
+
fetchAbort.abort();
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (discardLen > 0) {
|
|
473
|
+
chunk = new Uint8Array(bodyChunk).subarray(discardLen);
|
|
474
|
+
discardLen -= bodyChunk.byteLength - chunk.length;
|
|
475
|
+
}
|
|
476
|
+
if (!chunk.byteLength) {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
seenOffset += chunk.byteLength;
|
|
480
|
+
const s = decoder.decode(chunk);
|
|
481
|
+
controller.enqueue(s);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
fetchFailures = 0;
|
|
486
|
+
if (item.content) {
|
|
487
|
+
let content = item.content;
|
|
488
|
+
let encoded = encoder.encode(item.content);
|
|
489
|
+
if (discardLen > 0) {
|
|
490
|
+
const remaining = encoded.subarray(discardLen);
|
|
491
|
+
discardLen -= encoded.length - remaining.length;
|
|
492
|
+
if (!remaining.length) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
encoded = remaining;
|
|
496
|
+
content = decoder.decode(remaining);
|
|
497
|
+
}
|
|
498
|
+
seenOffset += encoded.length;
|
|
499
|
+
controller.enqueue(content);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
async function start(controller) {
|
|
504
|
+
let retry = true;
|
|
505
|
+
let attempts = 0;
|
|
506
|
+
while (retry) {
|
|
507
|
+
retry = false;
|
|
508
|
+
let nextAttempt = Date.now() + Math.min(15000, 500 * (attempts - 1));
|
|
509
|
+
const res = await runStartStream({ ...opts, offset: seenOffset }, controller);
|
|
510
|
+
if (res?.retry) {
|
|
511
|
+
retry = true;
|
|
512
|
+
attempts++;
|
|
513
|
+
if (nextAttempt < Date.now() - 300000) {
|
|
514
|
+
// reset attempts if we last tried 5 minutes ago
|
|
515
|
+
attempts = 0;
|
|
516
|
+
}
|
|
517
|
+
await new Promise((resolve) => {
|
|
518
|
+
setTimeout(resolve, Math.max(0, nextAttempt - Date.now()));
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (!canceled && !closed) {
|
|
523
|
+
controller.close();
|
|
524
|
+
markClosed();
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
class RStreamEnhanced extends RStream {
|
|
528
|
+
constructor(source, strategy) {
|
|
529
|
+
super(source, strategy);
|
|
530
|
+
}
|
|
531
|
+
async streamId() {
|
|
532
|
+
if (streamId_) {
|
|
533
|
+
return streamId_;
|
|
534
|
+
}
|
|
535
|
+
if (error_) {
|
|
536
|
+
throw error_;
|
|
537
|
+
}
|
|
538
|
+
return new Promise((resolve, reject) => {
|
|
539
|
+
const cleanupFns = [];
|
|
540
|
+
const cleanup = () => {
|
|
541
|
+
for (const f of cleanupFns) {
|
|
542
|
+
f();
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
const resolveCb = (streamId) => {
|
|
546
|
+
resolve(streamId);
|
|
547
|
+
cleanup();
|
|
548
|
+
};
|
|
549
|
+
const rejectCb = (e) => {
|
|
550
|
+
reject(e || new InstantError('Stream is closed.'));
|
|
551
|
+
cleanup();
|
|
552
|
+
};
|
|
553
|
+
cleanupFns.push(addStreamIdCb(resolveCb));
|
|
554
|
+
cleanupFns.push(addCloseCb(rejectCb));
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
const stream = new RStreamEnhanced({
|
|
559
|
+
start(controller) {
|
|
560
|
+
start(controller);
|
|
561
|
+
},
|
|
562
|
+
cancel(_reason) {
|
|
563
|
+
canceled = true;
|
|
564
|
+
if (eventId) {
|
|
565
|
+
cancelStream({ eventId });
|
|
566
|
+
}
|
|
567
|
+
markClosed();
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
return {
|
|
571
|
+
stream,
|
|
572
|
+
addCloseCb,
|
|
573
|
+
closed() {
|
|
574
|
+
return closed;
|
|
575
|
+
},
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
export class InstantStream {
|
|
579
|
+
trySend;
|
|
580
|
+
WStream;
|
|
581
|
+
RStream;
|
|
582
|
+
writeStreams = {};
|
|
583
|
+
startWriteStreamCbs = {};
|
|
584
|
+
readStreamIterators = {};
|
|
585
|
+
log;
|
|
586
|
+
activeStreams = new Set();
|
|
587
|
+
constructor({ WStream, RStream, trySend, log, }) {
|
|
588
|
+
this.WStream = WStream;
|
|
589
|
+
this.RStream = RStream;
|
|
590
|
+
this.trySend = trySend;
|
|
591
|
+
this.log = log;
|
|
592
|
+
}
|
|
593
|
+
createWriteStream(opts) {
|
|
594
|
+
const { stream, addCompleteCb } = createWriteStream({
|
|
595
|
+
WStream: this.WStream,
|
|
596
|
+
startStream: this.startWriteStream.bind(this),
|
|
597
|
+
appendStream: this.appendStream.bind(this),
|
|
598
|
+
registerStream: this.registerWriteStream.bind(this),
|
|
599
|
+
opts,
|
|
600
|
+
});
|
|
601
|
+
this.activeStreams.add(stream);
|
|
602
|
+
addCompleteCb(() => {
|
|
603
|
+
this.activeStreams.delete(stream);
|
|
604
|
+
});
|
|
605
|
+
return stream;
|
|
606
|
+
}
|
|
607
|
+
createReadStream(opts) {
|
|
608
|
+
const { stream, addCloseCb } = createReadStream({
|
|
609
|
+
RStream: this.RStream,
|
|
610
|
+
opts,
|
|
611
|
+
startStream: this.startReadStream.bind(this),
|
|
612
|
+
cancelStream: this.cancelReadStream.bind(this),
|
|
613
|
+
});
|
|
614
|
+
this.activeStreams.add(stream);
|
|
615
|
+
addCloseCb(() => {
|
|
616
|
+
this.activeStreams.delete(stream);
|
|
617
|
+
});
|
|
618
|
+
return stream;
|
|
619
|
+
}
|
|
620
|
+
startWriteStream(opts) {
|
|
621
|
+
const eventId = uuid();
|
|
622
|
+
let resolve = null;
|
|
623
|
+
const promise = new Promise((r) => {
|
|
624
|
+
resolve = r;
|
|
625
|
+
});
|
|
626
|
+
this.startWriteStreamCbs[eventId] = resolve;
|
|
627
|
+
const msg = {
|
|
628
|
+
op: 'start-stream',
|
|
629
|
+
'client-id': opts.clientId,
|
|
630
|
+
'reconnect-token': opts.reconnectToken,
|
|
631
|
+
};
|
|
632
|
+
if (opts.ruleParams) {
|
|
633
|
+
msg['rule-params'] = opts.ruleParams;
|
|
634
|
+
}
|
|
635
|
+
this.trySend(eventId, msg);
|
|
636
|
+
return promise;
|
|
637
|
+
}
|
|
638
|
+
registerWriteStream(streamId, cbs) {
|
|
639
|
+
this.writeStreams[streamId] = cbs;
|
|
640
|
+
}
|
|
641
|
+
appendStream({ streamId, chunks, isDone, offset, abortReason, }) {
|
|
642
|
+
const msg = {
|
|
643
|
+
op: 'append-stream',
|
|
644
|
+
'stream-id': streamId,
|
|
645
|
+
chunks,
|
|
646
|
+
offset,
|
|
647
|
+
done: !!isDone,
|
|
648
|
+
};
|
|
649
|
+
if (abortReason) {
|
|
650
|
+
msg['abort-reason'] = abortReason;
|
|
651
|
+
}
|
|
652
|
+
this.trySend(uuid(), msg);
|
|
653
|
+
}
|
|
654
|
+
onAppendFailed(msg) {
|
|
655
|
+
const cbs = this.writeStreams[msg['stream-id']];
|
|
656
|
+
if (cbs) {
|
|
657
|
+
cbs.onAppendFailed();
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
onStartStreamOk(msg) {
|
|
661
|
+
const cb = this.startWriteStreamCbs[msg['client-event-id']];
|
|
662
|
+
if (!cb) {
|
|
663
|
+
this.log.info('No stream for start-stream-ok', msg);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
cb({ type: 'ok', streamId: msg['stream-id'], offset: msg.offset });
|
|
667
|
+
delete this.startWriteStreamCbs[msg['client-event-id']];
|
|
668
|
+
}
|
|
669
|
+
onStreamFlushed(msg) {
|
|
670
|
+
const streamId = msg['stream-id'];
|
|
671
|
+
const cbs = this.writeStreams[streamId];
|
|
672
|
+
if (!cbs) {
|
|
673
|
+
this.log.info('No stream cbs for stream-flushed', msg);
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
cbs.onFlush({ offset: msg.offset, done: msg.done });
|
|
677
|
+
if (msg.done) {
|
|
678
|
+
delete this.writeStreams[streamId];
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
startReadStream({ eventId, clientId, streamId, offset, ruleParams, }) {
|
|
682
|
+
const msg = { op: 'subscribe-stream' };
|
|
683
|
+
if (!streamId && !clientId) {
|
|
684
|
+
throw new Error('Must provide one of streamId or clientId to subscribe to the stream.');
|
|
685
|
+
}
|
|
686
|
+
if (streamId) {
|
|
687
|
+
msg['stream-id'] = streamId;
|
|
688
|
+
}
|
|
689
|
+
if (clientId) {
|
|
690
|
+
msg['client-id'] = clientId;
|
|
691
|
+
}
|
|
692
|
+
if (offset) {
|
|
693
|
+
msg['offset'] = offset;
|
|
694
|
+
}
|
|
695
|
+
if (ruleParams) {
|
|
696
|
+
msg['rule-params'] = ruleParams;
|
|
697
|
+
}
|
|
698
|
+
const iterator = new StreamIterator();
|
|
699
|
+
this.readStreamIterators[eventId] = iterator;
|
|
700
|
+
this.trySend(eventId, msg);
|
|
701
|
+
return iterator;
|
|
702
|
+
}
|
|
703
|
+
cancelReadStream({ eventId }) {
|
|
704
|
+
const msg = {
|
|
705
|
+
op: 'unsubscribe-stream',
|
|
706
|
+
'subscribe-event-id': eventId,
|
|
707
|
+
};
|
|
708
|
+
this.trySend(uuid(), msg);
|
|
709
|
+
delete this.readStreamIterators[eventId];
|
|
710
|
+
}
|
|
711
|
+
onStreamAppend(msg) {
|
|
712
|
+
const eventId = msg['client-event-id'];
|
|
713
|
+
const iterator = this.readStreamIterators[eventId];
|
|
714
|
+
if (!iterator) {
|
|
715
|
+
this.log.info('No iterator for read stream', msg);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
if (msg.error) {
|
|
719
|
+
if (msg.retry) {
|
|
720
|
+
iterator.push({ type: 'reconnect' });
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
iterator.push({
|
|
724
|
+
type: 'error',
|
|
725
|
+
error: new InstantError(msg.error),
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
iterator.close();
|
|
729
|
+
delete this.readStreamIterators[eventId];
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
iterator.push({
|
|
733
|
+
type: 'append',
|
|
734
|
+
offset: msg.offset,
|
|
735
|
+
files: msg.files,
|
|
736
|
+
content: msg.content,
|
|
737
|
+
streamId: msg['stream-id'],
|
|
738
|
+
});
|
|
739
|
+
if (msg.done) {
|
|
740
|
+
iterator.close();
|
|
741
|
+
delete this.readStreamIterators[eventId];
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
onConnectionStatusChange(status) {
|
|
745
|
+
// Tell the writers to retry:
|
|
746
|
+
for (const cb of Object.values(this.startWriteStreamCbs)) {
|
|
747
|
+
cb({ type: 'disconnect' });
|
|
748
|
+
}
|
|
749
|
+
this.startWriteStreamCbs = {};
|
|
750
|
+
if (status !== STATUS.AUTHENTICATED) {
|
|
751
|
+
// Notify the writers that they've been disconnected
|
|
752
|
+
for (const { onDisconnect } of Object.values(this.writeStreams)) {
|
|
753
|
+
onDisconnect();
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
// Notify the writers that they need to reconnect
|
|
758
|
+
for (const { onConnectionReconnect } of Object.values(this.writeStreams)) {
|
|
759
|
+
onConnectionReconnect();
|
|
760
|
+
}
|
|
761
|
+
// Notify the readers that they need to reconnect
|
|
762
|
+
for (const iterator of Object.values(this.readStreamIterators)) {
|
|
763
|
+
iterator.push({ type: 'reconnect' });
|
|
764
|
+
iterator.close();
|
|
765
|
+
}
|
|
766
|
+
this.readStreamIterators = {};
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
onRecieveError(msg) {
|
|
770
|
+
const ev = msg['original-event'];
|
|
771
|
+
switch (ev.op) {
|
|
772
|
+
case 'append-stream': {
|
|
773
|
+
const streamId = ev['stream-id'];
|
|
774
|
+
const cbs = this.writeStreams[streamId];
|
|
775
|
+
cbs?.onAppendFailed();
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
case 'start-stream': {
|
|
779
|
+
const eventId = msg['client-event-id'];
|
|
780
|
+
const cb = this.startWriteStreamCbs[eventId];
|
|
781
|
+
if (cb) {
|
|
782
|
+
cb({
|
|
783
|
+
type: 'error',
|
|
784
|
+
error: new InstantError(msg.message || 'Unknown error', msg.hint),
|
|
785
|
+
});
|
|
786
|
+
delete this.startWriteStreamCbs[eventId];
|
|
787
|
+
}
|
|
788
|
+
break;
|
|
789
|
+
}
|
|
790
|
+
case 'subscribe-stream': {
|
|
791
|
+
const eventId = msg['client-event-id'];
|
|
792
|
+
const iterator = this.readStreamIterators[eventId];
|
|
793
|
+
if (iterator) {
|
|
794
|
+
iterator.push({
|
|
795
|
+
type: 'error',
|
|
796
|
+
error: new InstantError(msg.message || 'Unknown error', msg.hint),
|
|
797
|
+
});
|
|
798
|
+
iterator.close();
|
|
799
|
+
delete this.readStreamIterators[eventId];
|
|
800
|
+
}
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
case 'unsubscribe-stream': {
|
|
804
|
+
break;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
hasActiveStreams() {
|
|
809
|
+
return this.activeStreams.size > 0;
|
|
810
|
+
}
|
|
811
|
+
}
|