@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,844 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createParser,
|
|
3
|
+
type EventSourceMessage,
|
|
4
|
+
type EventSourceParser,
|
|
5
|
+
type ParseError,
|
|
6
|
+
} from 'eventsource-parser'
|
|
7
|
+
|
|
8
|
+
import {ErrorEvent, flattenError, syntaxError} from './errors.ts'
|
|
9
|
+
import type {
|
|
10
|
+
AddEventListenerOptions,
|
|
11
|
+
EventListenerOptions,
|
|
12
|
+
EventListenerOrEventListenerObject,
|
|
13
|
+
EventSourceEventMap,
|
|
14
|
+
EventSourceFetchInit,
|
|
15
|
+
EventSourceInit,
|
|
16
|
+
FetchLike,
|
|
17
|
+
FetchLikeResponse,
|
|
18
|
+
} from './types.ts'
|
|
19
|
+
|
|
20
|
+
const DEFAULT_MAX_BUFFER_SIZE = 100 * 1024 * 1024
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* An `EventSource` instance opens a persistent connection to an HTTP server, which sends events
|
|
24
|
+
* in `text/event-stream` format. The connection remains open until closed by calling `.close()`.
|
|
25
|
+
*
|
|
26
|
+
* Deliberately an `interface` and not a `class`: it lets consumers pass the native `EventSource`,
|
|
27
|
+
* a mock, or any other implementation wherever this type is expected.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
* @example
|
|
31
|
+
* ```js
|
|
32
|
+
* const eventSource = new EventSource('https://example.com/stream')
|
|
33
|
+
* eventSource.addEventListener('error', (error) => {
|
|
34
|
+
* console.error(error)
|
|
35
|
+
* })
|
|
36
|
+
* eventSource.addEventListener('message', (event) => {
|
|
37
|
+
* console.log('Received message:', event.data)
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export interface EventSource extends EventTarget {
|
|
42
|
+
/**
|
|
43
|
+
* ReadyState representing an EventSource currently trying to connect
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
readonly CONNECTING: 0
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* ReadyState representing an EventSource connection that is open (eg connected)
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
readonly OPEN: 1
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* ReadyState representing an EventSource connection that is closed (eg disconnected)
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
readonly CLOSED: 2
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns the state of this EventSource object's connection. It can have the values described below.
|
|
65
|
+
*
|
|
66
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
|
|
67
|
+
*
|
|
68
|
+
* Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
|
|
69
|
+
* defined in the TypeScript `dom` library.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
readonly readyState: number
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns the URL providing the event stream.
|
|
77
|
+
*
|
|
78
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
readonly url: string
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
|
|
86
|
+
*
|
|
87
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
readonly withCredentials: boolean
|
|
92
|
+
|
|
93
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
|
|
94
|
+
onerror: ((this: EventSource, ev: ErrorEvent) => unknown) | null
|
|
95
|
+
|
|
96
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
|
|
97
|
+
onmessage: ((this: EventSource, ev: MessageEvent) => unknown) | null
|
|
98
|
+
|
|
99
|
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
|
|
100
|
+
onopen: ((this: EventSource, ev: Event) => unknown) | null
|
|
101
|
+
|
|
102
|
+
addEventListener<K extends keyof EventSourceEventMap>(
|
|
103
|
+
type: K,
|
|
104
|
+
listener: (this: EventSource, ev: EventSourceEventMap[K]) => unknown,
|
|
105
|
+
options?: boolean | AddEventListenerOptions,
|
|
106
|
+
): void
|
|
107
|
+
addEventListener(
|
|
108
|
+
type: string,
|
|
109
|
+
listener: (this: EventSource, event: MessageEvent) => unknown,
|
|
110
|
+
options?: boolean | AddEventListenerOptions,
|
|
111
|
+
): void
|
|
112
|
+
addEventListener(
|
|
113
|
+
type: string,
|
|
114
|
+
listener: EventListenerOrEventListenerObject,
|
|
115
|
+
options?: boolean | AddEventListenerOptions,
|
|
116
|
+
): void
|
|
117
|
+
|
|
118
|
+
removeEventListener<K extends keyof EventSourceEventMap>(
|
|
119
|
+
type: K,
|
|
120
|
+
listener: (this: EventSource, ev: EventSourceEventMap[K]) => unknown,
|
|
121
|
+
options?: boolean | EventListenerOptions,
|
|
122
|
+
): void
|
|
123
|
+
removeEventListener(
|
|
124
|
+
type: string,
|
|
125
|
+
listener: (this: EventSource, event: MessageEvent) => unknown,
|
|
126
|
+
options?: boolean | EventListenerOptions,
|
|
127
|
+
): void
|
|
128
|
+
removeEventListener(
|
|
129
|
+
type: string,
|
|
130
|
+
listener: EventListenerOrEventListenerObject,
|
|
131
|
+
options?: boolean | EventListenerOptions,
|
|
132
|
+
): void
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
|
|
136
|
+
*
|
|
137
|
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
close(): void
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The `EventSource` constructor. Mirrors the shape of the native one, so the two can be used
|
|
146
|
+
* interchangeably - eg for functions that take an implementation to construct.
|
|
147
|
+
*
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
export interface EventSourceConstructor {
|
|
151
|
+
readonly prototype: EventSource
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Constructs a new `EventSource` instance, which immediately starts connecting.
|
|
155
|
+
*
|
|
156
|
+
* @param url - The URL to connect to
|
|
157
|
+
* @param eventSourceInitDict - Options for the connection
|
|
158
|
+
*/
|
|
159
|
+
new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource
|
|
160
|
+
|
|
161
|
+
/** ReadyState representing an EventSource currently trying to connect */
|
|
162
|
+
readonly CONNECTING: 0
|
|
163
|
+
|
|
164
|
+
/** ReadyState representing an EventSource connection that is open (eg connected) */
|
|
165
|
+
readonly OPEN: 1
|
|
166
|
+
|
|
167
|
+
/** ReadyState representing an EventSource connection that is closed (eg disconnected) */
|
|
168
|
+
readonly CLOSED: 2
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Implementation of the `EventSource` interface.
|
|
173
|
+
*
|
|
174
|
+
* Intentionally not exported: TypeScript emits a `#private` brand into declaration files for any
|
|
175
|
+
* class holding hard-private (`#`) fields, which makes the emitted type nominal. Exporting the
|
|
176
|
+
* interface and const instead keeps the public type structural, while the implementation keeps
|
|
177
|
+
* its actual, runtime-enforced private state.
|
|
178
|
+
*
|
|
179
|
+
* Public members are documented on the `EventSource` interface, which is what consumers see.
|
|
180
|
+
*
|
|
181
|
+
* @internal
|
|
182
|
+
*/
|
|
183
|
+
class EventSourceImpl extends EventTarget implements EventSource {
|
|
184
|
+
static CONNECTING = 0 as const
|
|
185
|
+
static OPEN = 1 as const
|
|
186
|
+
static CLOSED = 2 as const
|
|
187
|
+
|
|
188
|
+
readonly CONNECTING = 0 as const
|
|
189
|
+
readonly OPEN = 1 as const
|
|
190
|
+
readonly CLOSED = 2 as const
|
|
191
|
+
|
|
192
|
+
public get readyState(): number {
|
|
193
|
+
return this.#readyState
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public get url(): string {
|
|
197
|
+
return this.#url.href
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
public get withCredentials(): boolean {
|
|
201
|
+
return this.#withCredentials
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public get onerror(): ((this: EventSource, ev: ErrorEvent) => unknown) | null {
|
|
205
|
+
return this.#onError
|
|
206
|
+
}
|
|
207
|
+
public set onerror(value: ((this: EventSource, ev: ErrorEvent) => unknown) | null) {
|
|
208
|
+
if (this.#onError) {
|
|
209
|
+
this.removeEventListener('error', this.#onError)
|
|
210
|
+
}
|
|
211
|
+
this.#onError = value
|
|
212
|
+
if (value) {
|
|
213
|
+
this.addEventListener('error', value)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public get onmessage(): ((this: EventSource, ev: MessageEvent) => unknown) | null {
|
|
218
|
+
return this.#onMessage
|
|
219
|
+
}
|
|
220
|
+
public set onmessage(value: ((this: EventSource, ev: MessageEvent) => unknown) | null) {
|
|
221
|
+
if (this.#onMessage) {
|
|
222
|
+
this.removeEventListener('message', this.#onMessage)
|
|
223
|
+
}
|
|
224
|
+
this.#onMessage = value
|
|
225
|
+
if (value) {
|
|
226
|
+
this.addEventListener('message', value)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public get onopen(): ((this: EventSource, ev: Event) => unknown) | null {
|
|
231
|
+
return this.#onOpen
|
|
232
|
+
}
|
|
233
|
+
public set onopen(value: ((this: EventSource, ev: Event) => unknown) | null) {
|
|
234
|
+
if (this.#onOpen) {
|
|
235
|
+
this.removeEventListener('open', this.#onOpen)
|
|
236
|
+
}
|
|
237
|
+
this.#onOpen = value
|
|
238
|
+
if (value) {
|
|
239
|
+
this.addEventListener('open', value)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
override addEventListener<K extends keyof EventSourceEventMap>(
|
|
244
|
+
type: K,
|
|
245
|
+
listener: (this: EventSource, ev: EventSourceEventMap[K]) => unknown,
|
|
246
|
+
options?: boolean | AddEventListenerOptions,
|
|
247
|
+
): void
|
|
248
|
+
override addEventListener(
|
|
249
|
+
type: string,
|
|
250
|
+
listener: (this: EventSource, event: MessageEvent) => unknown,
|
|
251
|
+
options?: boolean | AddEventListenerOptions,
|
|
252
|
+
): void
|
|
253
|
+
override addEventListener(
|
|
254
|
+
type: string,
|
|
255
|
+
listener: EventListenerOrEventListenerObject,
|
|
256
|
+
options?: boolean | AddEventListenerOptions,
|
|
257
|
+
): void
|
|
258
|
+
override addEventListener(
|
|
259
|
+
type: string,
|
|
260
|
+
listener:
|
|
261
|
+
| ((this: EventSource, event: MessageEvent) => unknown)
|
|
262
|
+
| EventListenerOrEventListenerObject,
|
|
263
|
+
options?: boolean | AddEventListenerOptions,
|
|
264
|
+
): void {
|
|
265
|
+
const listen = listener as (this: EventSource, event: Event) => unknown
|
|
266
|
+
super.addEventListener(type, listen, options)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
override removeEventListener<K extends keyof EventSourceEventMap>(
|
|
270
|
+
type: K,
|
|
271
|
+
listener: (this: EventSource, ev: EventSourceEventMap[K]) => unknown,
|
|
272
|
+
options?: boolean | EventListenerOptions,
|
|
273
|
+
): void
|
|
274
|
+
override removeEventListener(
|
|
275
|
+
type: string,
|
|
276
|
+
listener: (this: EventSource, event: MessageEvent) => unknown,
|
|
277
|
+
options?: boolean | EventListenerOptions,
|
|
278
|
+
): void
|
|
279
|
+
override removeEventListener(
|
|
280
|
+
type: string,
|
|
281
|
+
listener: EventListenerOrEventListenerObject,
|
|
282
|
+
options?: boolean | EventListenerOptions,
|
|
283
|
+
): void
|
|
284
|
+
override removeEventListener(
|
|
285
|
+
type: string,
|
|
286
|
+
listener:
|
|
287
|
+
| ((this: EventSource, event: MessageEvent) => unknown)
|
|
288
|
+
| EventListenerOrEventListenerObject,
|
|
289
|
+
options?: boolean | EventListenerOptions,
|
|
290
|
+
): void {
|
|
291
|
+
const listen = listener as (this: EventSource, event: Event) => unknown
|
|
292
|
+
super.removeEventListener(type, listen, options)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
constructor(url: string | URL, eventSourceInitDict?: EventSourceInit) {
|
|
296
|
+
super()
|
|
297
|
+
|
|
298
|
+
try {
|
|
299
|
+
if (url instanceof URL) {
|
|
300
|
+
this.#url = url
|
|
301
|
+
} else if (typeof url === 'string') {
|
|
302
|
+
this.#url = new URL(url, getBaseURL())
|
|
303
|
+
} else {
|
|
304
|
+
throw new Error('Invalid URL')
|
|
305
|
+
}
|
|
306
|
+
} catch {
|
|
307
|
+
throw syntaxError('An invalid or illegal string was specified')
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
this.#parser = createParser({
|
|
311
|
+
maxBufferSize: eventSourceInitDict?.maxBufferSize ?? DEFAULT_MAX_BUFFER_SIZE,
|
|
312
|
+
onEvent: this.#onEvent,
|
|
313
|
+
onError: this.#onParseError,
|
|
314
|
+
onId: this.#onIdChange,
|
|
315
|
+
onRetry: this.#onRetryChange,
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
this.#readyState = this.CONNECTING
|
|
319
|
+
this.#reconnectInterval = 3000
|
|
320
|
+
this.#fetch = eventSourceInitDict?.fetch ?? globalThis.fetch
|
|
321
|
+
this.#withCredentials = eventSourceInitDict?.withCredentials ?? false
|
|
322
|
+
|
|
323
|
+
this.#connect()
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
close(): void {
|
|
327
|
+
if (this.#reconnectTimer) clearTimeout(this.#reconnectTimer)
|
|
328
|
+
if (this.#readyState === this.CLOSED) return
|
|
329
|
+
if (this.#controller) this.#controller.abort()
|
|
330
|
+
this.#readyState = this.CLOSED
|
|
331
|
+
this.#controller = undefined
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// PRIVATES FOLLOW
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Current connection state
|
|
338
|
+
*
|
|
339
|
+
* @internal
|
|
340
|
+
*/
|
|
341
|
+
#readyState: number
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Original URL used to connect.
|
|
345
|
+
*
|
|
346
|
+
* Note that this will stay the same even after a redirect.
|
|
347
|
+
*
|
|
348
|
+
* @internal
|
|
349
|
+
*/
|
|
350
|
+
#url: URL
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The destination URL after a redirect. Is reset on reconnection.
|
|
354
|
+
*
|
|
355
|
+
* @internal
|
|
356
|
+
*/
|
|
357
|
+
#redirectUrl: URL | undefined
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Whether to include credentials in the request
|
|
361
|
+
*
|
|
362
|
+
* @internal
|
|
363
|
+
*/
|
|
364
|
+
#withCredentials: boolean
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* The fetch implementation to use
|
|
368
|
+
*
|
|
369
|
+
* @internal
|
|
370
|
+
*/
|
|
371
|
+
#fetch: FetchLike
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The reconnection time in milliseconds
|
|
375
|
+
*
|
|
376
|
+
* @internal
|
|
377
|
+
*/
|
|
378
|
+
#reconnectInterval: number
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Reference to an ongoing reconnect attempt, if any
|
|
382
|
+
*
|
|
383
|
+
* @internal
|
|
384
|
+
*/
|
|
385
|
+
#reconnectTimer: ReturnType<typeof setTimeout> | undefined
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* The last event ID seen by the EventSource, which will be sent as `Last-Event-ID` in the
|
|
389
|
+
* request headers on a reconnection attempt.
|
|
390
|
+
*
|
|
391
|
+
* @internal
|
|
392
|
+
*/
|
|
393
|
+
#lastEventId: string | null = null
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The AbortController instance used to abort the fetch request
|
|
397
|
+
*
|
|
398
|
+
* @internal
|
|
399
|
+
*/
|
|
400
|
+
#controller: AbortController | undefined
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Instance of an EventSource parser (`eventsource-parser` npm module)
|
|
404
|
+
*
|
|
405
|
+
* @internal
|
|
406
|
+
*/
|
|
407
|
+
#parser: EventSourceParser
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Holds the current error handler, attached through `onerror` property directly.
|
|
411
|
+
* Note that `addEventListener('error', …)` will not be stored here.
|
|
412
|
+
*
|
|
413
|
+
* @internal
|
|
414
|
+
*/
|
|
415
|
+
#onError: ((this: EventSource, ev: ErrorEvent) => unknown) | null = null
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Holds the current message handler, attached through `onmessage` property directly.
|
|
419
|
+
* Note that `addEventListener('message', …)` will not be stored here.
|
|
420
|
+
*
|
|
421
|
+
* @internal
|
|
422
|
+
*/
|
|
423
|
+
#onMessage: ((this: EventSource, ev: MessageEvent) => unknown) | null = null
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Holds the current open handler, attached through `onopen` property directly.
|
|
427
|
+
* Note that `addEventListener('open', …)` will not be stored here.
|
|
428
|
+
*
|
|
429
|
+
* @internal
|
|
430
|
+
*/
|
|
431
|
+
#onOpen: ((this: EventSource, ev: Event) => unknown) | null = null
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Connect to the given URL and start receiving events
|
|
435
|
+
*
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
#connect() {
|
|
439
|
+
this.#readyState = this.CONNECTING
|
|
440
|
+
this.#controller = new AbortController()
|
|
441
|
+
|
|
442
|
+
// Browser tests are failing if we directly call `this.#fetch()`, thus the indirection.
|
|
443
|
+
const fetch = this.#fetch
|
|
444
|
+
fetch(this.#url, this.#getRequestOptions())
|
|
445
|
+
.then(this.#onFetchResponse)
|
|
446
|
+
.catch(this.#onFetchError)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Handles the fetch response
|
|
451
|
+
*
|
|
452
|
+
* @param response - The Fetch(ish) response
|
|
453
|
+
* @internal
|
|
454
|
+
*/
|
|
455
|
+
#onFetchResponse = async (response: FetchLikeResponse) => {
|
|
456
|
+
this.#parser.reset()
|
|
457
|
+
|
|
458
|
+
const {body, redirected, status, headers} = response
|
|
459
|
+
|
|
460
|
+
// [spec] a client can be told to stop reconnecting using the HTTP 204 No Content response code.
|
|
461
|
+
if (status === 204) {
|
|
462
|
+
// We still need to emit an error event - this mirrors the browser behavior,
|
|
463
|
+
// and without it there is no way to tell the user that the connection was closed.
|
|
464
|
+
this.#failConnection('Server sent HTTP 204, not reconnecting', 204)
|
|
465
|
+
this.close()
|
|
466
|
+
return
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// [spec] …Event stream requests can be redirected using HTTP 301 and 307 redirects as with
|
|
470
|
+
// [spec] normal HTTP requests.
|
|
471
|
+
// Spec does not say anything about other redirect codes (302, 308), but this seems an
|
|
472
|
+
// unintended omission, rather than a feature. Browsers will happily redirect on other 3xxs's.
|
|
473
|
+
if (redirected) {
|
|
474
|
+
this.#redirectUrl = new URL(response.url)
|
|
475
|
+
} else {
|
|
476
|
+
this.#redirectUrl = undefined
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// [spec] if res's status is not 200, …, then fail the connection.
|
|
480
|
+
if (status !== 200) {
|
|
481
|
+
this.#failConnection(`Non-200 status code (${status})`, status)
|
|
482
|
+
return
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// [spec] …or if res's `Content-Type` is not `text/event-stream`, then fail the connection.
|
|
486
|
+
const contentType = headers.get('content-type') || ''
|
|
487
|
+
if (!/^[\t\n\r ]*text\/event-stream[\t\n\r ]*(?:;|$)/i.test(contentType)) {
|
|
488
|
+
this.#failConnection('Invalid content type, expected "text/event-stream"', status)
|
|
489
|
+
return
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// [spec] …if the readyState attribute is set to a value other than CLOSED…
|
|
493
|
+
if (this.#readyState === this.CLOSED) {
|
|
494
|
+
return
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// [spec] …sets the readyState attribute to OPEN and fires an event
|
|
498
|
+
// [spec] …named open at the EventSource object.
|
|
499
|
+
this.#readyState = this.OPEN
|
|
500
|
+
|
|
501
|
+
const openEvent = new Event('open')
|
|
502
|
+
this.dispatchEvent(openEvent)
|
|
503
|
+
|
|
504
|
+
// Ensure that the response stream is a web stream
|
|
505
|
+
if (typeof body !== 'object' || !body || !('getReader' in body)) {
|
|
506
|
+
this.#failConnection('Invalid response body, expected a web ReadableStream', status)
|
|
507
|
+
this.close() // This should only happen if `fetch` provided is "faulty" - don't reconnect
|
|
508
|
+
return
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const decoder = new TextDecoder()
|
|
512
|
+
|
|
513
|
+
const reader = body.getReader()
|
|
514
|
+
let open = true
|
|
515
|
+
|
|
516
|
+
do {
|
|
517
|
+
const {done, value} = await reader.read()
|
|
518
|
+
if (this.#readyState === this.CLOSED) {
|
|
519
|
+
open = false
|
|
520
|
+
break
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (value) {
|
|
524
|
+
this.#parser.feed(decoder.decode(value, {stream: !done}))
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (!done) {
|
|
528
|
+
continue
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
open = false
|
|
532
|
+
this.#parser.reset()
|
|
533
|
+
|
|
534
|
+
this.#scheduleReconnect()
|
|
535
|
+
} while (open)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Handles rejected requests for the EventSource endpoint
|
|
540
|
+
*
|
|
541
|
+
* @param err - The error from `fetch()`
|
|
542
|
+
* @internal
|
|
543
|
+
*/
|
|
544
|
+
#onFetchError = (err: Error & {type?: string}) => {
|
|
545
|
+
this.#controller = undefined
|
|
546
|
+
|
|
547
|
+
// We expect abort errors when the user manually calls `close()` - ignore those
|
|
548
|
+
if (err.name === 'AbortError' || err.type === 'aborted') {
|
|
549
|
+
return
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
this.#scheduleReconnect(flattenError(err))
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Get request options for the `fetch()` request
|
|
557
|
+
*
|
|
558
|
+
* @returns The request options
|
|
559
|
+
* @internal
|
|
560
|
+
*/
|
|
561
|
+
#getRequestOptions(): EventSourceFetchInit {
|
|
562
|
+
// [spec] If the last event ID string is not the empty string, set `Last-Event-ID` to the last
|
|
563
|
+
// event ID string, encoded as UTF-8.
|
|
564
|
+
// workerd's native fetch encodes header values as UTF-8 itself.
|
|
565
|
+
const lastEvent = this.#lastEventId
|
|
566
|
+
? {
|
|
567
|
+
'Last-Event-ID':
|
|
568
|
+
this.#fetch === globalThis.fetch &&
|
|
569
|
+
globalThis.navigator?.userAgent === 'Cloudflare-Workers'
|
|
570
|
+
? this.#lastEventId
|
|
571
|
+
: utf8ToByteString(this.#lastEventId),
|
|
572
|
+
}
|
|
573
|
+
: undefined
|
|
574
|
+
|
|
575
|
+
const init: EventSourceFetchInit = {
|
|
576
|
+
// [spec] Let `corsAttributeState` be `Anonymous`…
|
|
577
|
+
// [spec] …will have their mode set to "cors"…
|
|
578
|
+
mode: 'cors',
|
|
579
|
+
redirect: 'follow',
|
|
580
|
+
headers: {Accept: 'text/event-stream', ...lastEvent},
|
|
581
|
+
cache: 'no-store',
|
|
582
|
+
signal: this.#controller?.signal,
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Some environments crash if attempting to set `credentials` where it is not supported,
|
|
586
|
+
// eg on Cloudflare Workers. To avoid this, we only set it in browser-like environments.
|
|
587
|
+
if ('window' in globalThis) {
|
|
588
|
+
// [spec] …and their credentials mode set to "same-origin"
|
|
589
|
+
// [spec] …if the `withCredentials` attribute is `true`, set the credentials mode to "include"…
|
|
590
|
+
init.credentials = this.withCredentials ? 'include' : 'same-origin'
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
return init
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Called by EventSourceParser when a blank line ends a block containing a valid `id` field.
|
|
598
|
+
* This runs before `#onEvent` when the same block also contains data.
|
|
599
|
+
*
|
|
600
|
+
* @param value - The value of the `id` field
|
|
601
|
+
* @internal
|
|
602
|
+
*/
|
|
603
|
+
#onIdChange = (value: string) => {
|
|
604
|
+
this.#lastEventId = value
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Called by EventSourceParser instance when an event has successfully been parsed
|
|
609
|
+
* and is ready to be processed.
|
|
610
|
+
*
|
|
611
|
+
* @param event - The parsed event
|
|
612
|
+
* @internal
|
|
613
|
+
*/
|
|
614
|
+
#onEvent = (event: EventSourceMessage) => {
|
|
615
|
+
// A listener can close the connection while the parser is still processing this chunk.
|
|
616
|
+
if (this.#readyState === this.CLOSED) {
|
|
617
|
+
return
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const origin = this.#redirectUrl ? this.#redirectUrl.origin : this.#url.origin
|
|
621
|
+
// [spec] The `lastEventId` attribute is the last event ID string of the event
|
|
622
|
+
// source, i.e. the persisted buffer (`#lastEventId`) - not the current event's `id`.
|
|
623
|
+
// The buffer is only updated by an explicit `id` field and must survive an
|
|
624
|
+
// event that omits `id`.
|
|
625
|
+
const lastEventId = this.#lastEventId ?? ''
|
|
626
|
+
|
|
627
|
+
const messageEvent = new MessageEvent(event.event || 'message', {
|
|
628
|
+
data: event.data,
|
|
629
|
+
origin,
|
|
630
|
+
lastEventId,
|
|
631
|
+
})
|
|
632
|
+
|
|
633
|
+
// workerd (Cloudflare Workers) accepts `data` but silently drops `origin` and `lastEventId`
|
|
634
|
+
// from the constructor init, yielding `null` and `''`. Both are plain own properties there
|
|
635
|
+
// rather than prototype getters, so they can be assigned after the fact. Elsewhere the
|
|
636
|
+
// constructor honours them and this is skipped, so no runtime pays for it unnecessarily.
|
|
637
|
+
if (messageEvent.origin !== origin) {
|
|
638
|
+
defineEventProperty(messageEvent, 'origin', origin)
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (messageEvent.lastEventId !== lastEventId) {
|
|
642
|
+
defineEventProperty(messageEvent, 'lastEventId', lastEventId)
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// The `onmessage` property only triggers on messages without an `event` field, or ones that
|
|
646
|
+
// explicitly set `message`. This is handled automatically: the event is dispatched with type
|
|
647
|
+
// `event.event || 'message'`, and `onmessage` is registered as a `message` event listener.
|
|
648
|
+
this.dispatchEvent(messageEvent)
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Called by EventSourceParser instance when a new reconnection interval is received
|
|
653
|
+
* from the EventSource endpoint.
|
|
654
|
+
*
|
|
655
|
+
* @param value - The new reconnection interval in milliseconds
|
|
656
|
+
* @internal
|
|
657
|
+
*/
|
|
658
|
+
#onRetryChange = (value: number) => {
|
|
659
|
+
this.#reconnectInterval = value
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Called by EventSourceParser instance when a parse error occurs.
|
|
664
|
+
*
|
|
665
|
+
* @param error - The parser error
|
|
666
|
+
* @internal
|
|
667
|
+
*/
|
|
668
|
+
#onParseError = (error: ParseError) => {
|
|
669
|
+
if (error.type !== 'max-buffer-size-exceeded') {
|
|
670
|
+
return
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
this.close()
|
|
674
|
+
this.#failConnection(error.message)
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Handles the process referred to in the EventSource specification as "failing a connection".
|
|
679
|
+
*
|
|
680
|
+
* @param error - The error causing the connection to fail
|
|
681
|
+
* @param code - The HTTP status code, if available
|
|
682
|
+
* @internal
|
|
683
|
+
*/
|
|
684
|
+
#failConnection(message?: string, code?: number) {
|
|
685
|
+
// [spec] …if the readyState attribute is set to a value other than CLOSED,
|
|
686
|
+
// [spec] sets the readyState attribute to CLOSED…
|
|
687
|
+
// Release the request before reporting failure, including responses with an unread body.
|
|
688
|
+
this.close()
|
|
689
|
+
|
|
690
|
+
// [spec] …and fires an event named `error` at the `EventSource` object.
|
|
691
|
+
// [spec] Once the user agent has failed the connection, it does not attempt to reconnect.
|
|
692
|
+
// [spec] > Implementations are especially encouraged to report detailed information
|
|
693
|
+
// [spec] > to their development consoles whenever an error event is fired, since little
|
|
694
|
+
// [spec] > to no information can be made available in the events themselves.
|
|
695
|
+
// Printing to console is not very programatically helpful, though, so we emit a custom event.
|
|
696
|
+
const errorEvent = new ErrorEvent('error', {code, message})
|
|
697
|
+
this.dispatchEvent(errorEvent)
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Schedules a reconnection attempt against the EventSource endpoint.
|
|
702
|
+
*
|
|
703
|
+
* @param message - The error causing the connection to fail
|
|
704
|
+
* @param code - The HTTP status code, if available
|
|
705
|
+
* @internal
|
|
706
|
+
*/
|
|
707
|
+
#scheduleReconnect(message?: string, code?: number) {
|
|
708
|
+
// [spec] If the readyState attribute is set to CLOSED, abort the task.
|
|
709
|
+
if (this.#readyState === this.CLOSED) {
|
|
710
|
+
return
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// [spec] Set the readyState attribute to CONNECTING.
|
|
714
|
+
this.#readyState = this.CONNECTING
|
|
715
|
+
|
|
716
|
+
// [spec] Fire an event named `error` at the EventSource object.
|
|
717
|
+
const errorEvent = new ErrorEvent('error', {code, message})
|
|
718
|
+
this.dispatchEvent(errorEvent)
|
|
719
|
+
|
|
720
|
+
// [spec] Wait a delay equal to the reconnection time of the event source.
|
|
721
|
+
const timer = setTimeout(this.#reconnect, this.#reconnectInterval)
|
|
722
|
+
|
|
723
|
+
// In Node.js (and Bun), a pending timer keeps the event loop alive, preventing the
|
|
724
|
+
// process from exiting while we wait to reconnect. `unref()` opts out of that. Browsers
|
|
725
|
+
// and Deno return a numeric handle with no `unref()`, so only call it when available.
|
|
726
|
+
if (typeof timer === 'object' && timer !== null && 'unref' in timer) {
|
|
727
|
+
timer.unref()
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
this.#reconnectTimer = timer
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Reconnects to the EventSource endpoint after a disconnect/failure
|
|
735
|
+
*
|
|
736
|
+
* @internal
|
|
737
|
+
*/
|
|
738
|
+
#reconnect = () => {
|
|
739
|
+
this.#reconnectTimer = undefined
|
|
740
|
+
|
|
741
|
+
// [spec] If the EventSource's readyState attribute is not set to CONNECTING, then return.
|
|
742
|
+
if (this.#readyState !== this.CONNECTING) {
|
|
743
|
+
return
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
this.#connect()
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// The class is named `EventSourceImpl` to leave the `EventSource` name free for the interface and
|
|
751
|
+
// the const below. Restore the public name, so neither `EventSource.name` nor inspected instances
|
|
752
|
+
// (eg `console.log(eventSource)`) leak the implementation name.
|
|
753
|
+
Object.defineProperty(EventSourceImpl, 'name', {value: 'EventSource'})
|
|
754
|
+
|
|
755
|
+
// Provides a way to detect that the EventSource implementation supports passing `fetch`
|
|
756
|
+
// that can be used to customize the request, eg custom headers and similar.
|
|
757
|
+
Object.defineProperty(EventSourceImpl, Symbol.for('eventsource.supports-fetch-override'), {
|
|
758
|
+
value: true,
|
|
759
|
+
writable: false,
|
|
760
|
+
configurable: false,
|
|
761
|
+
enumerable: false,
|
|
762
|
+
})
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* An `EventSource` instance opens a persistent connection to an HTTP server, which sends events
|
|
766
|
+
* in `text/event-stream` format. The connection remains open until closed by calling `.close()`.
|
|
767
|
+
*
|
|
768
|
+
* @public
|
|
769
|
+
* @example
|
|
770
|
+
* ```js
|
|
771
|
+
* const eventSource = new EventSource('https://example.com/stream')
|
|
772
|
+
* eventSource.addEventListener('error', (error) => {
|
|
773
|
+
* console.error(error)
|
|
774
|
+
* })
|
|
775
|
+
* eventSource.addEventListener('message', (event) => {
|
|
776
|
+
* console.log('Received message:', event.data)
|
|
777
|
+
* })
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
export const EventSource: EventSourceConstructor = EventSourceImpl
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* According to spec, when constructing a URL:
|
|
784
|
+
* > 1. Let baseURL be environment's base URL, if environment is a Document object
|
|
785
|
+
* > 2. Return the result of applying the URL parser to url, with baseURL.
|
|
786
|
+
*
|
|
787
|
+
* Thus we should use `document.baseURI` if available, since it can be set through a base tag.
|
|
788
|
+
*
|
|
789
|
+
* @returns The base URL, if available - otherwise `undefined`
|
|
790
|
+
* @internal
|
|
791
|
+
*/
|
|
792
|
+
function getBaseURL(): string | undefined {
|
|
793
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
794
|
+
const doc = 'document' in globalThis ? (globalThis as any).document : undefined
|
|
795
|
+
return doc && typeof doc === 'object' && 'baseURI' in doc && typeof doc.baseURI === 'string'
|
|
796
|
+
? doc.baseURI
|
|
797
|
+
: undefined
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Assigns a `MessageEvent` property that the constructor's init dictionary was supposed to have
|
|
802
|
+
* set, for runtimes that ignore it.
|
|
803
|
+
*
|
|
804
|
+
* Defined rather than assigned because on the runtimes that do implement the property as a
|
|
805
|
+
* prototype getter, a plain assignment would throw in strict mode. `enumerable` and
|
|
806
|
+
* `configurable` mirror how a spec-compliant implementation exposes it.
|
|
807
|
+
*
|
|
808
|
+
* @param event - The message event to define the property on
|
|
809
|
+
* @param property - The property to define
|
|
810
|
+
* @param value - The value the constructor should have set
|
|
811
|
+
* @internal
|
|
812
|
+
*/
|
|
813
|
+
function defineEventProperty(
|
|
814
|
+
event: MessageEvent,
|
|
815
|
+
property: 'origin' | 'lastEventId',
|
|
816
|
+
value: string,
|
|
817
|
+
): void {
|
|
818
|
+
Object.defineProperty(event, property, {
|
|
819
|
+
value,
|
|
820
|
+
enumerable: true,
|
|
821
|
+
configurable: true,
|
|
822
|
+
})
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Encodes a string as UTF-8 and returns those bytes as a "byte string": one character per byte,
|
|
827
|
+
* each in the range U+0000 to U+00FF.
|
|
828
|
+
*
|
|
829
|
+
* Header values are byte strings. `fetch()` throws a `TypeError` for any character above U+00FF,
|
|
830
|
+
* and sends a character in U+0080 to U+00FF as a single Latin-1 byte, rather than as its UTF-8
|
|
831
|
+
* encoding. Passing the UTF-8 bytes through as characters makes `fetch()` put exactly those
|
|
832
|
+
* bytes on the wire.
|
|
833
|
+
*
|
|
834
|
+
* @param value - The string to encode
|
|
835
|
+
* @returns The UTF-8 bytes of `value`, one per character
|
|
836
|
+
* @internal
|
|
837
|
+
*/
|
|
838
|
+
function utf8ToByteString(value: string): string {
|
|
839
|
+
let byteString = ''
|
|
840
|
+
for (const byte of new TextEncoder().encode(value)) {
|
|
841
|
+
byteString += String.fromCharCode(byte)
|
|
842
|
+
}
|
|
843
|
+
return byteString
|
|
844
|
+
}
|