@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,321 @@
|
|
|
1
|
+
import { dataTypes } from './constant';
|
|
2
|
+
|
|
3
|
+
export const enum DraftType {
|
|
4
|
+
Object,
|
|
5
|
+
Array,
|
|
6
|
+
Map,
|
|
7
|
+
Set,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Operation = {
|
|
11
|
+
Remove: 'remove',
|
|
12
|
+
Replace: 'replace',
|
|
13
|
+
Add: 'add',
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export type DataType = keyof typeof dataTypes;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The `enablePatches` option: `true` or an object generates patches, `false`
|
|
20
|
+
* does not.
|
|
21
|
+
*/
|
|
22
|
+
export type PatchesOptions =
|
|
23
|
+
| boolean
|
|
24
|
+
| {
|
|
25
|
+
/**
|
|
26
|
+
* Whether a patch path is an array of keys, as by default, or a JSON
|
|
27
|
+
* Pointer string, such as `/list/0`.
|
|
28
|
+
*/
|
|
29
|
+
pathAsArray?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether an array that gets shorter gets a `replace` patch of its
|
|
32
|
+
* `length`, as by default, or a `remove` patch for each index that it
|
|
33
|
+
* loses, as JSON Patch requires.
|
|
34
|
+
* Recreating holes in a sparse array still uses length patches;
|
|
35
|
+
* JSON cannot represent holes.
|
|
36
|
+
*/
|
|
37
|
+
arrayLengthAssignment?: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type FinalizeCallback = (
|
|
41
|
+
patches?: Patches,
|
|
42
|
+
inversePatches?: Patches
|
|
43
|
+
) => void;
|
|
44
|
+
|
|
45
|
+
export interface Finalities {
|
|
46
|
+
// Draft nodes and deferred callbacks, finalized in reverse order.
|
|
47
|
+
draft: (ProxyDraft | FinalizeCallback)[];
|
|
48
|
+
revoke: (() => void)[];
|
|
49
|
+
handledSet: WeakSet<any>;
|
|
50
|
+
// Whether the producer runs a recipe inside `create`, which then sees it end
|
|
51
|
+
// and releases module-level references to its drafts. False for drafts
|
|
52
|
+
// returned by `create(base)` without a recipe.
|
|
53
|
+
scoped: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ProxyDraft<T = any> {
|
|
57
|
+
type: DraftType;
|
|
58
|
+
operated: boolean;
|
|
59
|
+
finalized: boolean;
|
|
60
|
+
original: T;
|
|
61
|
+
copy: T | null;
|
|
62
|
+
proxy: T | null;
|
|
63
|
+
finalities: Finalities;
|
|
64
|
+
options: Options<any, any>;
|
|
65
|
+
parent: ProxyDraft | null;
|
|
66
|
+
key: string | number | symbol | undefined;
|
|
67
|
+
// The drafts of a Set draft's items and the objects it added, with its items
|
|
68
|
+
// in order once finalization rebuilt it.
|
|
69
|
+
setMap: (Map<any, any> & { items?: any[] }) | undefined;
|
|
70
|
+
assignedMap: Map<any, boolean> | undefined;
|
|
71
|
+
callbacks: FinalizeCallback[] | undefined;
|
|
72
|
+
// Child drafts created by this draft, by key.
|
|
73
|
+
children: any;
|
|
74
|
+
child: any;
|
|
75
|
+
childKey: any;
|
|
76
|
+
// Bookkeeping of array methods that ran natively, created on demand.
|
|
77
|
+
arrayState: ArrayState | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ArrayState {
|
|
81
|
+
// Elements may have moved away from their original index.
|
|
82
|
+
relocated: boolean;
|
|
83
|
+
// Index range whose contents may have changed; patch generation compares
|
|
84
|
+
// it in full.
|
|
85
|
+
diffStart: number;
|
|
86
|
+
diffEnd: number;
|
|
87
|
+
// Original index by element of the original array, built lazily.
|
|
88
|
+
baseRefs: Map<any, number> | null;
|
|
89
|
+
// How far the last native move shifted the elements it moved, when it
|
|
90
|
+
// shifted all of them alike.
|
|
91
|
+
delta: number | undefined;
|
|
92
|
+
// Original indices looked up by searching before `baseRefs` is built.
|
|
93
|
+
lookups: number;
|
|
94
|
+
// Whether no element can be drafted; null until checked.
|
|
95
|
+
inert: boolean | null;
|
|
96
|
+
// Whether the array has no holes; null until checked.
|
|
97
|
+
dense: boolean | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface IPatch {
|
|
101
|
+
op: (typeof Operation)[keyof typeof Operation];
|
|
102
|
+
value?: any;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* An `add`, `remove` or `replace` operation at a path, as `create()` generates
|
|
107
|
+
* it with `enablePatches` and `apply()` applies it. The path is an array of
|
|
108
|
+
* keys, or a JSON Pointer string with `pathAsArray: false`.
|
|
109
|
+
*/
|
|
110
|
+
export type Patch<P extends PatchesOptions = any> = P extends {
|
|
111
|
+
pathAsArray: false;
|
|
112
|
+
}
|
|
113
|
+
? IPatch & {
|
|
114
|
+
path: string;
|
|
115
|
+
}
|
|
116
|
+
: P extends true | object
|
|
117
|
+
? IPatch & {
|
|
118
|
+
path: (string | number)[];
|
|
119
|
+
}
|
|
120
|
+
: IPatch & {
|
|
121
|
+
path: string | (string | number)[];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Patches in the order in which `apply()` applies them.
|
|
126
|
+
*/
|
|
127
|
+
export type Patches<P extends PatchesOptions = any> = Patch<P>[];
|
|
128
|
+
|
|
129
|
+
export type Result<
|
|
130
|
+
T extends any,
|
|
131
|
+
O extends PatchesOptions,
|
|
132
|
+
F extends boolean,
|
|
133
|
+
> = O extends true | object
|
|
134
|
+
? [F extends true ? Immutable<T> : T, Patches<O>, Patches<O>]
|
|
135
|
+
: F extends true
|
|
136
|
+
? Immutable<T>
|
|
137
|
+
: T;
|
|
138
|
+
|
|
139
|
+
export type CreateResult<
|
|
140
|
+
T extends any,
|
|
141
|
+
O extends PatchesOptions,
|
|
142
|
+
F extends boolean,
|
|
143
|
+
R extends void | Promise<void> | T | Promise<T>,
|
|
144
|
+
> = R extends Promise<void> | Promise<T>
|
|
145
|
+
? Promise<Result<T, O, F>>
|
|
146
|
+
: Result<T, O, F>;
|
|
147
|
+
|
|
148
|
+
type BaseMark = null | undefined | DataType;
|
|
149
|
+
type MarkWithCopy = BaseMark | (() => any);
|
|
150
|
+
|
|
151
|
+
export type Mark<O extends PatchesOptions, F extends boolean> = (
|
|
152
|
+
target: any,
|
|
153
|
+
types: typeof dataTypes
|
|
154
|
+
) => O extends true | object
|
|
155
|
+
? BaseMark
|
|
156
|
+
: F extends true
|
|
157
|
+
? BaseMark
|
|
158
|
+
: MarkWithCopy;
|
|
159
|
+
|
|
160
|
+
export interface ApplyMutableOptions {
|
|
161
|
+
/**
|
|
162
|
+
* If it's `true`, the state will be mutated directly.
|
|
163
|
+
*/
|
|
164
|
+
mutable?: boolean;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface Options<O extends PatchesOptions, F extends boolean> {
|
|
168
|
+
/**
|
|
169
|
+
* In strict mode, reading an object that cannot be drafted from a draft,
|
|
170
|
+
* such as a class instance that no mark makes draftable, or a value that
|
|
171
|
+
* `mark` makes mutable, throws unless the read happens inside `unsafe()`.
|
|
172
|
+
* A value returned with `rawReturn()` is still searched for drafts, which
|
|
173
|
+
* development builds report with a warning. Development builds also warn
|
|
174
|
+
* once when a recipe leaves 1,000 or more drafts unchanged.
|
|
175
|
+
*/
|
|
176
|
+
strict?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Generate patches: the result is then
|
|
179
|
+
* `[state, patches, inversePatches]`.
|
|
180
|
+
*/
|
|
181
|
+
enablePatches?: O;
|
|
182
|
+
/**
|
|
183
|
+
* Freeze the next state deeply, also the parts that it shares with the base
|
|
184
|
+
* state. Development builds also throw for an object that holds itself.
|
|
185
|
+
*/
|
|
186
|
+
enableAutoFreeze?: F;
|
|
187
|
+
/**
|
|
188
|
+
* Decide how values are drafted: a mark returns `immutable` to make a value
|
|
189
|
+
* draftable, such as a class instance, `mutable` to keep it out of drafts so
|
|
190
|
+
* that the recipe changes it in place, or a function that returns a shallow
|
|
191
|
+
* copy of the value, which needs patches and auto-freeze off. With several
|
|
192
|
+
* marks, the first one that returns a value decides.
|
|
193
|
+
*/
|
|
194
|
+
mark?: Mark<O, F>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface ExternalOptions<O extends PatchesOptions, F extends boolean> {
|
|
198
|
+
/**
|
|
199
|
+
* In strict mode, reading an object that cannot be drafted from a draft,
|
|
200
|
+
* such as a class instance that no mark makes draftable, or a value that
|
|
201
|
+
* `mark` makes mutable, throws unless the read happens inside `unsafe()`.
|
|
202
|
+
* A value returned with `rawReturn()` is still searched for drafts, which
|
|
203
|
+
* development builds report with a warning. Development builds also warn
|
|
204
|
+
* once when a recipe leaves 1,000 or more drafts unchanged.
|
|
205
|
+
*/
|
|
206
|
+
strict?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Generate patches: the result is then
|
|
209
|
+
* `[state, patches, inversePatches]`.
|
|
210
|
+
*/
|
|
211
|
+
enablePatches?: O;
|
|
212
|
+
/**
|
|
213
|
+
* Freeze the next state deeply, also the parts that it shares with the base
|
|
214
|
+
* state. Development builds also throw for an object that holds itself.
|
|
215
|
+
*/
|
|
216
|
+
enableAutoFreeze?: F;
|
|
217
|
+
/**
|
|
218
|
+
* Decide how values are drafted: a mark returns `immutable` to make a value
|
|
219
|
+
* draftable, such as a class instance, `mutable` to keep it out of drafts so
|
|
220
|
+
* that the recipe changes it in place, or a function that returns a shallow
|
|
221
|
+
* copy of the value, which needs patches and auto-freeze off. With several
|
|
222
|
+
* marks, the first one that returns a value decides.
|
|
223
|
+
*/
|
|
224
|
+
mark?: Mark<O, F>[] | Mark<O, F>;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Exclude `symbol`
|
|
228
|
+
type Primitive = string | number | bigint | boolean | null | undefined;
|
|
229
|
+
|
|
230
|
+
type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>;
|
|
231
|
+
type ImmutableSet<T> = ReadonlySet<Immutable<T>>;
|
|
232
|
+
type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> };
|
|
233
|
+
|
|
234
|
+
export type IfAvailable<T, Fallback = void> = true | false extends (
|
|
235
|
+
T extends never ? true : false
|
|
236
|
+
)
|
|
237
|
+
? Fallback
|
|
238
|
+
: keyof T extends never
|
|
239
|
+
? Fallback
|
|
240
|
+
: T;
|
|
241
|
+
type WeakReferences =
|
|
242
|
+
| IfAvailable<WeakMap<any, any>>
|
|
243
|
+
| IfAvailable<WeakSet<any>>;
|
|
244
|
+
type AtomicObject = Function | Promise<any> | Date | RegExp;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* A deeply readonly `T`, the type of a state that `enableAutoFreeze` freezes:
|
|
248
|
+
* Maps and Sets become `ReadonlyMap` and `ReadonlySet`, and functions,
|
|
249
|
+
* Promises, dates and regular expressions keep their types.
|
|
250
|
+
*/
|
|
251
|
+
export type Immutable<T> = T extends Primitive | AtomicObject
|
|
252
|
+
? T
|
|
253
|
+
: T extends IfAvailable<ReadonlyMap<infer K, infer V>>
|
|
254
|
+
? ImmutableMap<K, V>
|
|
255
|
+
: T extends IfAvailable<ReadonlySet<infer V>>
|
|
256
|
+
? ImmutableSet<V>
|
|
257
|
+
: T extends WeakReferences
|
|
258
|
+
? T
|
|
259
|
+
: T extends object
|
|
260
|
+
? ImmutableObject<T>
|
|
261
|
+
: T;
|
|
262
|
+
|
|
263
|
+
type DraftedMap<K, V> = Map<K, Draft<V>>;
|
|
264
|
+
type DraftedSet<T> = Set<Draft<T>>;
|
|
265
|
+
/**
|
|
266
|
+
* The draft of an object type: writable properties whose values are drafts.
|
|
267
|
+
*/
|
|
268
|
+
export type DraftedObject<T> = {
|
|
269
|
+
-readonly [K in keyof T]: Draft<T[K]>;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The type of a draft of `T`: its objects, arrays, Maps and Sets without
|
|
274
|
+
* `readonly`, deeply, so that a recipe can change them. Functions, Promises,
|
|
275
|
+
* dates and regular expressions keep their types.
|
|
276
|
+
*/
|
|
277
|
+
export type Draft<T> = T extends Primitive | AtomicObject
|
|
278
|
+
? T
|
|
279
|
+
: T extends IfAvailable<ReadonlyMap<infer K, infer V>>
|
|
280
|
+
? DraftedMap<K, V>
|
|
281
|
+
: T extends IfAvailable<ReadonlySet<infer V>>
|
|
282
|
+
? DraftedSet<V>
|
|
283
|
+
: T extends WeakReferences
|
|
284
|
+
? T
|
|
285
|
+
: T extends object
|
|
286
|
+
? DraftedObject<T>
|
|
287
|
+
: T;
|
|
288
|
+
|
|
289
|
+
export type ApplyImmutableOptions<F extends boolean> = Pick<
|
|
290
|
+
Options<boolean, F>,
|
|
291
|
+
Exclude<keyof Options<boolean, F>, 'enablePatches'>
|
|
292
|
+
> & { mutable?: false };
|
|
293
|
+
|
|
294
|
+
export type ApplyOptions<F extends boolean> =
|
|
295
|
+
| ApplyImmutableOptions<F>
|
|
296
|
+
| ApplyMutableOptions;
|
|
297
|
+
|
|
298
|
+
// Distribute over boolean and undefined so optional or widened freeze flags
|
|
299
|
+
// keep both possible states instead of silently promising a writable result.
|
|
300
|
+
type ApplyFrozenState<T, F> = F extends true ? Immutable<T> : T;
|
|
301
|
+
|
|
302
|
+
type ApplyState<T, F extends boolean, A> = F extends true
|
|
303
|
+
? Immutable<T>
|
|
304
|
+
: 'enableAutoFreeze' extends keyof A
|
|
305
|
+
? ApplyFrozenState<T, A['enableAutoFreeze']>
|
|
306
|
+
: T;
|
|
307
|
+
|
|
308
|
+
// `apply()` changes the state in place and returns nothing with `mutable`,
|
|
309
|
+
// and returns a frozen state with `enableAutoFreeze`, as `create()` does.
|
|
310
|
+
// A boolean or optional `mutable` flag can also select the void result.
|
|
311
|
+
export type ApplyResult<
|
|
312
|
+
T extends object,
|
|
313
|
+
F extends boolean = false,
|
|
314
|
+
A extends ApplyOptions<boolean> | undefined = ApplyImmutableOptions<F>,
|
|
315
|
+
> = A extends { mutable: true }
|
|
316
|
+
? void
|
|
317
|
+
: 'mutable' extends keyof A
|
|
318
|
+
? true extends A['mutable']
|
|
319
|
+
? ApplyState<T, F, A> | void
|
|
320
|
+
: ApplyState<T, F, A>
|
|
321
|
+
: ApplyState<T, F, A>;
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreateResult,
|
|
3
|
+
Draft,
|
|
4
|
+
Mark,
|
|
5
|
+
Options,
|
|
6
|
+
ExternalOptions,
|
|
7
|
+
PatchesOptions,
|
|
8
|
+
Result,
|
|
9
|
+
} from './interface';
|
|
10
|
+
import { draftify } from './draftify';
|
|
11
|
+
import { releaseArrayMethods } from './array';
|
|
12
|
+
import {
|
|
13
|
+
getProxyDraft,
|
|
14
|
+
isDraft,
|
|
15
|
+
isDraftable,
|
|
16
|
+
isEqual,
|
|
17
|
+
revokeProxy,
|
|
18
|
+
} from './utils';
|
|
19
|
+
import { current, handleReturnValue } from './current';
|
|
20
|
+
import { RAW_RETURN_SYMBOL, dataTypes } from './constant';
|
|
21
|
+
import { die, ErrorCode } from './error';
|
|
22
|
+
|
|
23
|
+
// TypeScript infers no type parameter from this deferred indexed access, so T
|
|
24
|
+
// keeps its default, never, unless the call supplies the state type.
|
|
25
|
+
type ExplicitState<T> = [T][T extends any ? 0 : never];
|
|
26
|
+
|
|
27
|
+
type ExplicitReturn<T> = void | ExplicitState<T> | Draft<ExplicitState<T>>;
|
|
28
|
+
|
|
29
|
+
// An async recipe widens the literals it returns unless a Promise is among
|
|
30
|
+
// the return types of the first overload that checks it, and a literal that
|
|
31
|
+
// it returns directly needs a Promise as the whole return type. Actual
|
|
32
|
+
// Promises lack the impossible field and still select the async overload.
|
|
33
|
+
type AsyncRecipeContext<T> = Promise<ExplicitReturn<T>> & {
|
|
34
|
+
readonly __mutativeAsyncContext: never;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type IsExplicitPrimitive<T> = [ExplicitState<T>] extends [
|
|
38
|
+
string | number | bigint | boolean | symbol | null | undefined,
|
|
39
|
+
]
|
|
40
|
+
? true
|
|
41
|
+
: false;
|
|
42
|
+
|
|
43
|
+
type ExplicitSyncReturn<T> =
|
|
44
|
+
IsExplicitPrimitive<T> extends true
|
|
45
|
+
? AsyncRecipeContext<T>
|
|
46
|
+
: ExplicitReturn<T> | AsyncRecipeContext<T>;
|
|
47
|
+
|
|
48
|
+
type ExplicitRecipe<T, P extends any[], R> = [T] extends [never]
|
|
49
|
+
? never
|
|
50
|
+
: (draft: Draft<ExplicitState<T>>, ...args: P) => R;
|
|
51
|
+
|
|
52
|
+
// The first overload only gives the async recipes of a primitive state their
|
|
53
|
+
// context, so its synchronous recipes take this one, which comes before the
|
|
54
|
+
// overload of a recipe that may or may not return a Promise.
|
|
55
|
+
type ExplicitPrimitiveRecipe<T, P extends any[]> =
|
|
56
|
+
IsExplicitPrimitive<T> extends true
|
|
57
|
+
? ExplicitRecipe<T, P, ExplicitReturn<T>>
|
|
58
|
+
: never;
|
|
59
|
+
|
|
60
|
+
/** @inline */ type MakeCreator = <
|
|
61
|
+
_F extends boolean = false,
|
|
62
|
+
_O extends PatchesOptions = false,
|
|
63
|
+
>(
|
|
64
|
+
options?: ExternalOptions<_O, _F>
|
|
65
|
+
) => {
|
|
66
|
+
// With an explicit state type, TypeScript infers no other type argument, and
|
|
67
|
+
// the default return type `void` of the overloads below also accepts an
|
|
68
|
+
// async recipe. These overloads tell async recipes apart by their return
|
|
69
|
+
// type; an inferred call leaves T at never and skips them.
|
|
70
|
+
<T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
|
|
71
|
+
base: ExplicitState<T>,
|
|
72
|
+
mutate: ExplicitRecipe<T, [], ExplicitSyncReturn<T>>,
|
|
73
|
+
options?: ExternalOptions<O, F>
|
|
74
|
+
): Result<ExplicitState<T>, O, F>;
|
|
75
|
+
<T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
|
|
76
|
+
base: ExplicitState<T>,
|
|
77
|
+
mutate: ExplicitRecipe<T, [], Promise<ExplicitReturn<T>>>,
|
|
78
|
+
options?: ExternalOptions<O, F>
|
|
79
|
+
): Promise<Result<ExplicitState<T>, O, F>>;
|
|
80
|
+
// A synchronous recipe of a primitive state.
|
|
81
|
+
<T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
|
|
82
|
+
base: ExplicitState<T>,
|
|
83
|
+
mutate: ExplicitPrimitiveRecipe<T, []>,
|
|
84
|
+
options?: ExternalOptions<O, F>
|
|
85
|
+
): Result<ExplicitState<T>, O, F>;
|
|
86
|
+
// A recipe that may or may not return a Promise gives either result.
|
|
87
|
+
<T = never, F extends boolean = _F, O extends PatchesOptions = _O>(
|
|
88
|
+
base: ExplicitState<T>,
|
|
89
|
+
mutate: ExplicitRecipe<
|
|
90
|
+
T,
|
|
91
|
+
[],
|
|
92
|
+
ExplicitReturn<T> | Promise<ExplicitReturn<T>>
|
|
93
|
+
>,
|
|
94
|
+
options?: ExternalOptions<O, F>
|
|
95
|
+
): Result<ExplicitState<T>, O, F> | Promise<Result<ExplicitState<T>, O, F>>;
|
|
96
|
+
<
|
|
97
|
+
T extends any,
|
|
98
|
+
F extends boolean = _F,
|
|
99
|
+
O extends PatchesOptions = _O,
|
|
100
|
+
R extends void | Promise<void> | T | Promise<T> = void,
|
|
101
|
+
>(
|
|
102
|
+
base: T,
|
|
103
|
+
mutate: (draft: Draft<T>) => R,
|
|
104
|
+
options?: ExternalOptions<O, F>
|
|
105
|
+
): CreateResult<T, O, F, R>;
|
|
106
|
+
<
|
|
107
|
+
T extends any,
|
|
108
|
+
F extends boolean = _F,
|
|
109
|
+
O extends PatchesOptions = _O,
|
|
110
|
+
R extends void | Promise<void> = void,
|
|
111
|
+
>(
|
|
112
|
+
base: T,
|
|
113
|
+
mutate: (draft: T) => R,
|
|
114
|
+
options?: ExternalOptions<O, F>
|
|
115
|
+
): CreateResult<T, O, F, R>;
|
|
116
|
+
<
|
|
117
|
+
T = never,
|
|
118
|
+
P extends any[] = [],
|
|
119
|
+
F extends boolean = _F,
|
|
120
|
+
O extends PatchesOptions = _O,
|
|
121
|
+
>(
|
|
122
|
+
mutate: ExplicitRecipe<T, P, ExplicitSyncReturn<T>>,
|
|
123
|
+
options?: ExternalOptions<O, F>
|
|
124
|
+
): (base: ExplicitState<T>, ...args: P) => Result<ExplicitState<T>, O, F>;
|
|
125
|
+
<
|
|
126
|
+
T = never,
|
|
127
|
+
P extends any[] = [],
|
|
128
|
+
F extends boolean = _F,
|
|
129
|
+
O extends PatchesOptions = _O,
|
|
130
|
+
>(
|
|
131
|
+
mutate: ExplicitRecipe<T, P, Promise<ExplicitReturn<T>>>,
|
|
132
|
+
options?: ExternalOptions<O, F>
|
|
133
|
+
): (
|
|
134
|
+
base: ExplicitState<T>,
|
|
135
|
+
...args: P
|
|
136
|
+
) => Promise<Result<ExplicitState<T>, O, F>>;
|
|
137
|
+
<
|
|
138
|
+
T = never,
|
|
139
|
+
P extends any[] = [],
|
|
140
|
+
F extends boolean = _F,
|
|
141
|
+
O extends PatchesOptions = _O,
|
|
142
|
+
>(
|
|
143
|
+
mutate: ExplicitPrimitiveRecipe<T, P>,
|
|
144
|
+
options?: ExternalOptions<O, F>
|
|
145
|
+
): (base: ExplicitState<T>, ...args: P) => Result<ExplicitState<T>, O, F>;
|
|
146
|
+
<
|
|
147
|
+
T = never,
|
|
148
|
+
P extends any[] = [],
|
|
149
|
+
F extends boolean = _F,
|
|
150
|
+
O extends PatchesOptions = _O,
|
|
151
|
+
>(
|
|
152
|
+
mutate: ExplicitRecipe<
|
|
153
|
+
T,
|
|
154
|
+
P,
|
|
155
|
+
ExplicitReturn<T> | Promise<ExplicitReturn<T>>
|
|
156
|
+
>,
|
|
157
|
+
options?: ExternalOptions<O, F>
|
|
158
|
+
): (
|
|
159
|
+
base: ExplicitState<T>,
|
|
160
|
+
...args: P
|
|
161
|
+
) => Result<ExplicitState<T>, O, F> | Promise<Result<ExplicitState<T>, O, F>>;
|
|
162
|
+
<
|
|
163
|
+
T extends any,
|
|
164
|
+
P extends any[] = [],
|
|
165
|
+
F extends boolean = _F,
|
|
166
|
+
O extends PatchesOptions = _O,
|
|
167
|
+
R extends void | Promise<void> | T | Promise<T> = void,
|
|
168
|
+
>(
|
|
169
|
+
mutate: (draft: Draft<T>, ...args: P) => R,
|
|
170
|
+
options?: ExternalOptions<O, F>
|
|
171
|
+
): (base: T, ...args: P) => CreateResult<T, O, F, R>;
|
|
172
|
+
// A recipe that annotates its draft with the state type itself, such as a
|
|
173
|
+
// type parameter, which TypeScript cannot match against `Draft<T>`.
|
|
174
|
+
<
|
|
175
|
+
T extends any,
|
|
176
|
+
P extends any[] = [],
|
|
177
|
+
F extends boolean = _F,
|
|
178
|
+
O extends PatchesOptions = _O,
|
|
179
|
+
R extends void | Promise<void> | T | Promise<T> = void,
|
|
180
|
+
>(
|
|
181
|
+
mutate: (draft: T, ...args: P) => R,
|
|
182
|
+
options?: ExternalOptions<O, F>
|
|
183
|
+
): (base: T, ...args: P) => CreateResult<T, O, F, R>;
|
|
184
|
+
<T extends any, O extends PatchesOptions = _O, F extends boolean = _F>(
|
|
185
|
+
base: T,
|
|
186
|
+
options?: ExternalOptions<O, F>
|
|
187
|
+
): [Draft<T>, () => Result<T, O, F>];
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Development builds warn once about a draft base, see `makeCreator`.
|
|
191
|
+
let draftBaseWarned = false;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* `makeCreator(options)` to make a creator function.
|
|
195
|
+
*
|
|
196
|
+
* ## Example
|
|
197
|
+
*
|
|
198
|
+
* ```ts
|
|
199
|
+
* import { makeCreator } from 'mutative';
|
|
200
|
+
*
|
|
201
|
+
* const baseState = { foo: { bar: 'str' }, arr: [] };
|
|
202
|
+
* const create = makeCreator({ enableAutoFreeze: true });
|
|
203
|
+
* const state = create(
|
|
204
|
+
* baseState,
|
|
205
|
+
* (draft) => {
|
|
206
|
+
* draft.foo.bar = 'str2';
|
|
207
|
+
* },
|
|
208
|
+
* );
|
|
209
|
+
*
|
|
210
|
+
* expect(state).toEqual({ foo: { bar: 'str2' }, arr: [] });
|
|
211
|
+
* expect(state).not.toBe(baseState);
|
|
212
|
+
* expect(state.foo).not.toBe(baseState.foo);
|
|
213
|
+
* expect(state.arr).toBe(baseState.arr);
|
|
214
|
+
* expect(Object.isFrozen(state)).toBeTruthy();
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export const makeCreator: MakeCreator = (arg) => {
|
|
218
|
+
if (
|
|
219
|
+
__DEV__ &&
|
|
220
|
+
arg !== undefined &&
|
|
221
|
+
Object.prototype.toString.call(arg) !== '[object Object]'
|
|
222
|
+
) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Invalid options: ${String(arg)}, 'options' should be an object.`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
return function create(arg0: any, arg1: any, arg2?: any): any {
|
|
228
|
+
if (typeof arg0 === 'function' && typeof arg1 !== 'function') {
|
|
229
|
+
return function (this: any, base: any, ...args: any[]) {
|
|
230
|
+
return create(
|
|
231
|
+
base,
|
|
232
|
+
(draft: any) => arg0.call(this, draft, ...args),
|
|
233
|
+
arg1
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const base = arg0;
|
|
238
|
+
const mutate = arg1 as (...args: any[]) => any;
|
|
239
|
+
let options = arg2;
|
|
240
|
+
if (typeof arg1 !== 'function') {
|
|
241
|
+
options = arg1;
|
|
242
|
+
}
|
|
243
|
+
if (
|
|
244
|
+
__DEV__ &&
|
|
245
|
+
options !== undefined &&
|
|
246
|
+
Object.prototype.toString.call(options) !== '[object Object]'
|
|
247
|
+
) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
`Invalid options: ${options}, 'options' should be an object.`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
options = {
|
|
253
|
+
...arg,
|
|
254
|
+
...options,
|
|
255
|
+
};
|
|
256
|
+
const draftBase = isDraft(base);
|
|
257
|
+
// A draft base is drafted as `current(draft)`, so the values that the
|
|
258
|
+
// recipe leaves unchanged are objects of the base state.
|
|
259
|
+
if (
|
|
260
|
+
__DEV__ &&
|
|
261
|
+
draftBase &&
|
|
262
|
+
typeof arg1 === 'function' &&
|
|
263
|
+
!draftBaseWarned
|
|
264
|
+
) {
|
|
265
|
+
draftBaseWarned = true;
|
|
266
|
+
console.warn(
|
|
267
|
+
`create() received a draft as its base and drafts current(draft), unlike Immer's produce: the values that its recipe leaves unchanged are objects of the base state, so changing them after the result is assigned back changes the base state. Make such changes in the recipe or before calling create(); see https://mutative.js.org/docs/api-reference/create#create-on-a-draft`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const state = draftBase ? current(base) : base;
|
|
271
|
+
const mark = Array.isArray(options.mark)
|
|
272
|
+
? (((value: unknown, types: typeof dataTypes) => {
|
|
273
|
+
for (const mark of options.mark as Mark<any, any>[]) {
|
|
274
|
+
if (__DEV__ && typeof mark !== 'function') {
|
|
275
|
+
throw new Error(
|
|
276
|
+
`Invalid mark: ${mark}, 'mark' should be a function.`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
const result = mark(value, types);
|
|
280
|
+
if (result) {
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}) as Mark<any, any>)
|
|
286
|
+
: options.mark;
|
|
287
|
+
const enablePatches = options.enablePatches ?? false;
|
|
288
|
+
const strict = options.strict ?? false;
|
|
289
|
+
const enableAutoFreeze = options.enableAutoFreeze ?? false;
|
|
290
|
+
const _options: Options<any, any> = {
|
|
291
|
+
enableAutoFreeze,
|
|
292
|
+
mark,
|
|
293
|
+
strict,
|
|
294
|
+
enablePatches,
|
|
295
|
+
};
|
|
296
|
+
if (
|
|
297
|
+
!isDraftable(state, _options) &&
|
|
298
|
+
typeof state === 'object' &&
|
|
299
|
+
state !== null
|
|
300
|
+
) {
|
|
301
|
+
die(ErrorCode.InvalidBaseState);
|
|
302
|
+
}
|
|
303
|
+
const [draft, finalize, finalities] = draftify(state, _options);
|
|
304
|
+
if (typeof arg1 !== 'function') {
|
|
305
|
+
if (!isDraftable(state, _options)) {
|
|
306
|
+
die(ErrorCode.InvalidBaseState);
|
|
307
|
+
}
|
|
308
|
+
finalities.scoped = false;
|
|
309
|
+
return [draft, finalize];
|
|
310
|
+
}
|
|
311
|
+
// A failed producer revokes its drafts, without reading the root draft,
|
|
312
|
+
// which finalization may already have revoked, and releases the array
|
|
313
|
+
// method cache, which must not keep it alive.
|
|
314
|
+
function fail(error: unknown): never {
|
|
315
|
+
revokeProxy(finalities);
|
|
316
|
+
releaseArrayMethods(finalities.revoke);
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
let result: any;
|
|
320
|
+
try {
|
|
321
|
+
result = mutate(draft);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
fail(error);
|
|
324
|
+
}
|
|
325
|
+
const returnValue = (value: any) => {
|
|
326
|
+
const proxyDraft = getProxyDraft(draft)!;
|
|
327
|
+
if (!isDraft(value)) {
|
|
328
|
+
if (
|
|
329
|
+
value !== undefined &&
|
|
330
|
+
!isEqual(value, draft) &&
|
|
331
|
+
proxyDraft?.operated
|
|
332
|
+
) {
|
|
333
|
+
die(ErrorCode.MutateAndReturn);
|
|
334
|
+
}
|
|
335
|
+
const rawReturnValue = value?.[RAW_RETURN_SYMBOL] as [any] | undefined;
|
|
336
|
+
if (rawReturnValue) {
|
|
337
|
+
const _value = rawReturnValue[0];
|
|
338
|
+
if (_options.strict && typeof value === 'object' && value !== null) {
|
|
339
|
+
handleReturnValue(proxyDraft, value, true);
|
|
340
|
+
}
|
|
341
|
+
return finalize([_value]);
|
|
342
|
+
}
|
|
343
|
+
if (value !== undefined) {
|
|
344
|
+
if (typeof value === 'object' && value !== null) {
|
|
345
|
+
handleReturnValue(proxyDraft, value);
|
|
346
|
+
}
|
|
347
|
+
return finalize([value]);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (value === draft || value === undefined) {
|
|
351
|
+
return finalize([]);
|
|
352
|
+
}
|
|
353
|
+
const returnedProxyDraft = getProxyDraft(value)!;
|
|
354
|
+
if (_options === returnedProxyDraft.options) {
|
|
355
|
+
if (returnedProxyDraft.operated) {
|
|
356
|
+
die(ErrorCode.CannotReturnModifiedChildDraft);
|
|
357
|
+
}
|
|
358
|
+
return finalize([current(value)]);
|
|
359
|
+
}
|
|
360
|
+
return finalize([value]);
|
|
361
|
+
};
|
|
362
|
+
// Returned values are checked and finalized after the recipe, and a
|
|
363
|
+
// failure there ends the producer like an error in the recipe does.
|
|
364
|
+
const finish = (value: any) => {
|
|
365
|
+
try {
|
|
366
|
+
return returnValue(value);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
return fail(error);
|
|
369
|
+
} finally {
|
|
370
|
+
releaseArrayMethods(finalities.revoke);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
try {
|
|
374
|
+
// Classifying a returned Proxy, or reading/calling an overridden then,
|
|
375
|
+
// can throw before a Promise has registered the failure handler.
|
|
376
|
+
if (result instanceof Promise) return result.then(finish, fail);
|
|
377
|
+
} catch (error) {
|
|
378
|
+
return fail(error);
|
|
379
|
+
}
|
|
380
|
+
return finish(result);
|
|
381
|
+
};
|
|
382
|
+
};
|