@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,160 @@
|
|
|
1
|
+
import type { ProxyDraft } from './interface';
|
|
2
|
+
import { dataTypes, iteratorPrototype, iteratorSymbol } from './constant';
|
|
3
|
+
import { internal } from './internal';
|
|
4
|
+
import { checkReadable } from './unsafe';
|
|
5
|
+
import {
|
|
6
|
+
assertDraftActive,
|
|
7
|
+
ensureShallowCopy,
|
|
8
|
+
getProxyDraft,
|
|
9
|
+
isDraftable,
|
|
10
|
+
isEqual,
|
|
11
|
+
latest,
|
|
12
|
+
markChanged,
|
|
13
|
+
markFinalization,
|
|
14
|
+
} from './utils';
|
|
15
|
+
|
|
16
|
+
// The value at `key` as `get()` returns it: a draft of a draftable value of
|
|
17
|
+
// the original Map. Iteration calls this with the draft state it looked up
|
|
18
|
+
// once, instead of calling `get()` through the proxy, which binds a new
|
|
19
|
+
// function for every entry.
|
|
20
|
+
function getEntry(target: ProxyDraft, key: any) {
|
|
21
|
+
const value = latest(target).get(key);
|
|
22
|
+
const mutable = target.options.mark?.(value, dataTypes) === dataTypes.mutable;
|
|
23
|
+
if (target.options.strict) {
|
|
24
|
+
checkReadable(value, target.options, mutable);
|
|
25
|
+
}
|
|
26
|
+
if (mutable) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
if (target.finalized || !isDraftable(value, target.options)) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
// drafted or reassigned
|
|
33
|
+
if (value !== target.original.get(key)) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
const draft = internal.createDraft(
|
|
37
|
+
value,
|
|
38
|
+
target,
|
|
39
|
+
key,
|
|
40
|
+
target.finalities,
|
|
41
|
+
target.options
|
|
42
|
+
);
|
|
43
|
+
ensureShallowCopy(target);
|
|
44
|
+
target.copy.set(key, draft);
|
|
45
|
+
return draft;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const mapHandler = {
|
|
49
|
+
get size() {
|
|
50
|
+
const current: Map<any, any> = latest(getProxyDraft(this)!);
|
|
51
|
+
return current.size;
|
|
52
|
+
},
|
|
53
|
+
has(key: any): boolean {
|
|
54
|
+
return latest(getProxyDraft(this)!).has(key);
|
|
55
|
+
},
|
|
56
|
+
set(key: any, value: any) {
|
|
57
|
+
// Map keys are used as they are, and a draft is revoked when its producer
|
|
58
|
+
// ends, so a Map would keep a key that throws when it is read.
|
|
59
|
+
if (__DEV__) {
|
|
60
|
+
let isDraftKey = false;
|
|
61
|
+
try {
|
|
62
|
+
isDraftKey = !!getProxyDraft(key);
|
|
63
|
+
} catch {
|
|
64
|
+
// Map keys are compared by identity only, so a key can also be a Proxy
|
|
65
|
+
// that rejects reading the symbol of drafts, or a revoked one.
|
|
66
|
+
}
|
|
67
|
+
if (isDraftKey) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`A draft cannot be a Map key: its producer revokes it when it ends. Use original(key), current(key) or an id as the key; see https://mutative.js.org/docs/extra-topics/faq`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const target = getProxyDraft(this)!;
|
|
74
|
+
const source = latest(target);
|
|
75
|
+
if (!source.has(key) || !isEqual(source.get(key), value)) {
|
|
76
|
+
ensureShallowCopy(target);
|
|
77
|
+
markChanged(target);
|
|
78
|
+
target.assignedMap!.set(key, true);
|
|
79
|
+
target.copy.set(key, value);
|
|
80
|
+
markFinalization(target, key, value);
|
|
81
|
+
}
|
|
82
|
+
return this;
|
|
83
|
+
},
|
|
84
|
+
delete(key: any): boolean {
|
|
85
|
+
if (!this.has(key)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const target = getProxyDraft(this)!;
|
|
89
|
+
ensureShallowCopy(target);
|
|
90
|
+
markChanged(target);
|
|
91
|
+
if (target.original.has(key)) {
|
|
92
|
+
target.assignedMap!.set(key, false);
|
|
93
|
+
} else {
|
|
94
|
+
target.assignedMap!.delete(key);
|
|
95
|
+
}
|
|
96
|
+
target.copy.delete(key);
|
|
97
|
+
return true;
|
|
98
|
+
},
|
|
99
|
+
clear() {
|
|
100
|
+
const target = getProxyDraft(this)!;
|
|
101
|
+
if (!this.size) return;
|
|
102
|
+
ensureShallowCopy(target);
|
|
103
|
+
markChanged(target);
|
|
104
|
+
target.assignedMap = new Map();
|
|
105
|
+
for (const [key] of target.original) {
|
|
106
|
+
target.assignedMap.set(key, false);
|
|
107
|
+
}
|
|
108
|
+
target.copy!.clear();
|
|
109
|
+
},
|
|
110
|
+
forEach(callback: (value: any, key: any, self: any) => void, thisArg?: any) {
|
|
111
|
+
const target = getProxyDraft(this)!;
|
|
112
|
+
latest(target).forEach((_value: any, key: any) => {
|
|
113
|
+
assertDraftActive(target);
|
|
114
|
+
callback.call(thisArg, getEntry(target, key), key, this);
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
get(key: any): any {
|
|
118
|
+
return getEntry(getProxyDraft(this)!, key);
|
|
119
|
+
},
|
|
120
|
+
keys(): IterableIterator<any> {
|
|
121
|
+
return latest(getProxyDraft(this)!).keys();
|
|
122
|
+
},
|
|
123
|
+
values(): IterableIterator<any> {
|
|
124
|
+
const target = getProxyDraft(this)!;
|
|
125
|
+
const iterator = this.keys();
|
|
126
|
+
return {
|
|
127
|
+
__proto__: iteratorPrototype,
|
|
128
|
+
next: () => {
|
|
129
|
+
const result = iterator.next();
|
|
130
|
+
if (result.done) return result;
|
|
131
|
+
assertDraftActive(target);
|
|
132
|
+
return {
|
|
133
|
+
done: false,
|
|
134
|
+
value: getEntry(target, result.value),
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
} as any;
|
|
138
|
+
},
|
|
139
|
+
entries(): IterableIterator<[any, any]> {
|
|
140
|
+
const target = getProxyDraft(this)!;
|
|
141
|
+
const iterator = this.keys();
|
|
142
|
+
return {
|
|
143
|
+
__proto__: iteratorPrototype,
|
|
144
|
+
next: () => {
|
|
145
|
+
const result = iterator.next();
|
|
146
|
+
if (result.done) return result;
|
|
147
|
+
assertDraftActive(target);
|
|
148
|
+
return {
|
|
149
|
+
done: false,
|
|
150
|
+
value: [result.value, getEntry(target, result.value)],
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
} as any;
|
|
154
|
+
},
|
|
155
|
+
[iteratorSymbol]() {
|
|
156
|
+
return this.entries();
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const mapHandlerKeys = Reflect.ownKeys(mapHandler);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getProxyDraft } from './utils';
|
|
2
|
+
import { die, ErrorCode } from './error';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `original(draft)` to get original state in the draft mutation function.
|
|
6
|
+
*
|
|
7
|
+
* ## Example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { create, original } from 'mutative';
|
|
11
|
+
*
|
|
12
|
+
* const baseState = { foo: { bar: 'str' }, arr: [] };
|
|
13
|
+
* const state = create(
|
|
14
|
+
* baseState,
|
|
15
|
+
* (draft) => {
|
|
16
|
+
* draft.foo.bar = 'str2';
|
|
17
|
+
* expect(original(draft.foo)).toEqual({ bar: 'str' });
|
|
18
|
+
* }
|
|
19
|
+
* );
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function original<T>(target: T): T {
|
|
23
|
+
const proxyDraft = getProxyDraft(target);
|
|
24
|
+
if (!proxyDraft) {
|
|
25
|
+
die(ErrorCode.OriginalOnNonDraft, target);
|
|
26
|
+
}
|
|
27
|
+
return proxyDraft.original;
|
|
28
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { DraftType, Operation, Patches, ProxyDraft } from './interface';
|
|
2
|
+
import {
|
|
3
|
+
checkPathKey,
|
|
4
|
+
escapePath,
|
|
5
|
+
get,
|
|
6
|
+
getProxyDraft,
|
|
7
|
+
getType,
|
|
8
|
+
has,
|
|
9
|
+
isEqual,
|
|
10
|
+
} from './utils';
|
|
11
|
+
import { current } from './current';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Patch values must not contain drafts. A draft that is still present when its
|
|
15
|
+
* container generates patches is represented by its original object when it
|
|
16
|
+
* was not modified, or by a snapshot of its current state otherwise.
|
|
17
|
+
*/
|
|
18
|
+
function cloneIfNeeded<T>(target: T): T {
|
|
19
|
+
const proxyDraft = getProxyDraft(target);
|
|
20
|
+
if (!proxyDraft) return target;
|
|
21
|
+
return proxyDraft.operated ? current(target as any) : proxyDraft.original;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const hasOwn = Object.prototype.hasOwnProperty;
|
|
25
|
+
|
|
26
|
+
// In Node.js 24, checking an index takes about 7 ns, or 30 ns in a
|
|
27
|
+
// dictionary-mode array, and enumerating an own key about 150 ns. A suffix is
|
|
28
|
+
// checked index by index until this many holes have passed, and the rest of a
|
|
29
|
+
// long gap is crossed by enumerating own keys.
|
|
30
|
+
const SPARSE_HOLE_LIMIT = 65536;
|
|
31
|
+
|
|
32
|
+
// Patches that restore the own indices of `to` from `start` on, including
|
|
33
|
+
// non-enumerable ones. `indices`, if given, holds all of them, among others,
|
|
34
|
+
// in ascending order.
|
|
35
|
+
function restoreSuffix(
|
|
36
|
+
to: any[],
|
|
37
|
+
start: number,
|
|
38
|
+
indices: number[] | null,
|
|
39
|
+
basePath: any[],
|
|
40
|
+
result: Patches,
|
|
41
|
+
pathAsArray: boolean
|
|
42
|
+
) {
|
|
43
|
+
const restore = (index: number) =>
|
|
44
|
+
result.push({
|
|
45
|
+
op: Operation.Replace,
|
|
46
|
+
path: escapePath(basePath.concat([index]), pathAsArray),
|
|
47
|
+
value: cloneIfNeeded(to[index]),
|
|
48
|
+
});
|
|
49
|
+
if (indices !== null) {
|
|
50
|
+
for (let position = 0; position < indices.length; position += 1) {
|
|
51
|
+
const index = indices[position];
|
|
52
|
+
if (index >= start && index < to.length && hasOwn.call(to, index)) {
|
|
53
|
+
restore(index);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let index = start;
|
|
59
|
+
let holes = 0;
|
|
60
|
+
while (index < to.length && holes <= SPARSE_HOLE_LIMIT) {
|
|
61
|
+
if (hasOwn.call(to, index)) restore(index);
|
|
62
|
+
else holes += 1;
|
|
63
|
+
index += 1;
|
|
64
|
+
}
|
|
65
|
+
if (index === to.length) return;
|
|
66
|
+
// Array indices only, not length or custom properties such as '1.5'.
|
|
67
|
+
for (const key of Object.getOwnPropertyNames(to)) {
|
|
68
|
+
const own = Number(key);
|
|
69
|
+
if (
|
|
70
|
+
Number.isInteger(own) &&
|
|
71
|
+
own >= index &&
|
|
72
|
+
own < to.length &&
|
|
73
|
+
String(own) === key
|
|
74
|
+
) {
|
|
75
|
+
restore(own);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Index patches carry values, so neither an undefined value nor an index
|
|
81
|
+
// removal can represent a hole. Patches that turn an own index of `from` into
|
|
82
|
+
// a hole of `to` rebuild the suffix from there: they truncate it, grow the
|
|
83
|
+
// length to leave holes, then restore only own indices. Filling a hole takes
|
|
84
|
+
// an index patch, so only that direction rebuilds. Keeping the array itself
|
|
85
|
+
// supports mutable application and arrays inside Sets. `indices`, when known,
|
|
86
|
+
// holds every own index that `to` has from `start` on.
|
|
87
|
+
function rebuildSuffix(
|
|
88
|
+
from: any[],
|
|
89
|
+
to: any[],
|
|
90
|
+
start: number,
|
|
91
|
+
indices: number[] | null,
|
|
92
|
+
basePath: any[],
|
|
93
|
+
result: Patches,
|
|
94
|
+
pathAsArray: boolean,
|
|
95
|
+
arrayLengthAssignment: boolean
|
|
96
|
+
) {
|
|
97
|
+
const lengthPath = escapePath(basePath.concat(['length']), pathAsArray);
|
|
98
|
+
const cut = Math.min(start, to.length);
|
|
99
|
+
if (arrayLengthAssignment) {
|
|
100
|
+
if (from.length > cut) {
|
|
101
|
+
result.push({ op: Operation.Replace, path: lengthPath, value: cut });
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
for (let index = from.length - 1; index >= cut; index -= 1) {
|
|
105
|
+
result.push({
|
|
106
|
+
op: Operation.Remove,
|
|
107
|
+
path: escapePath(basePath.concat([index]), pathAsArray),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (to.length <= cut) return;
|
|
112
|
+
// JSON cannot encode holes. Growing a sparse array needs a length patch
|
|
113
|
+
// even when shrinking arrays use per-index removals.
|
|
114
|
+
result.push({
|
|
115
|
+
op: Operation.Replace,
|
|
116
|
+
path: lengthPath,
|
|
117
|
+
value: to.length,
|
|
118
|
+
});
|
|
119
|
+
restoreSuffix(to, cut, indices, basePath, result, pathAsArray);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function generateArrayPatches(
|
|
123
|
+
proxyState: ProxyDraft<Array<any>>,
|
|
124
|
+
basePath: any[],
|
|
125
|
+
patches: Patches,
|
|
126
|
+
inversePatches: Patches,
|
|
127
|
+
pathAsArray: boolean
|
|
128
|
+
) {
|
|
129
|
+
let { original, assignedMap, options } = proxyState;
|
|
130
|
+
let copy = proxyState.copy!;
|
|
131
|
+
const { arrayLengthAssignment = true } = options.enablePatches;
|
|
132
|
+
const shorter = copy.length < original.length;
|
|
133
|
+
if (shorter) {
|
|
134
|
+
[original, copy] = [copy, original];
|
|
135
|
+
[patches, inversePatches] = [inversePatches, patches];
|
|
136
|
+
}
|
|
137
|
+
// Only assigned indices and the range touched by native array operations
|
|
138
|
+
// can differ, so visit those in ascending order instead of scanning every
|
|
139
|
+
// element of a possibly very large array.
|
|
140
|
+
const arrayState = proxyState.arrayState;
|
|
141
|
+
const diffStart = arrayState === null ? 0 : arrayState.diffStart;
|
|
142
|
+
const diffEnd = arrayState === null ? 0 : arrayState.diffEnd;
|
|
143
|
+
const assigned: number[] = [];
|
|
144
|
+
assignedMap!.forEach((flag, key) => {
|
|
145
|
+
if (flag && key !== 'length') {
|
|
146
|
+
const index = Number(key);
|
|
147
|
+
if (index < diffStart || index >= diffEnd) assigned.push(index);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
assigned.sort((a, b) => a - b);
|
|
151
|
+
// Assigned indices below the range, the range itself, then the rest.
|
|
152
|
+
const indices: number[] = [];
|
|
153
|
+
let position = 0;
|
|
154
|
+
for (
|
|
155
|
+
;
|
|
156
|
+
position < assigned.length && assigned[position] < diffStart;
|
|
157
|
+
position += 1
|
|
158
|
+
) {
|
|
159
|
+
indices.push(assigned[position]);
|
|
160
|
+
}
|
|
161
|
+
for (let index = diffStart; index < diffEnd; index += 1) indices.push(index);
|
|
162
|
+
for (; position < assigned.length; position += 1)
|
|
163
|
+
indices.push(assigned[position]);
|
|
164
|
+
// The first index at which each direction turns an own index into a hole.
|
|
165
|
+
let forward = -1;
|
|
166
|
+
let inverse = -1;
|
|
167
|
+
for (let position = 0; position < indices.length; position += 1) {
|
|
168
|
+
const index = indices[position];
|
|
169
|
+
if (index >= original.length) break;
|
|
170
|
+
const value = copy[index];
|
|
171
|
+
const previous = original[index];
|
|
172
|
+
// A hole reads as `undefined`.
|
|
173
|
+
let inCopy = true;
|
|
174
|
+
let inOriginal = true;
|
|
175
|
+
if (value === undefined || previous === undefined) {
|
|
176
|
+
inCopy = hasOwn.call(copy, index);
|
|
177
|
+
inOriginal = hasOwn.call(original, index);
|
|
178
|
+
}
|
|
179
|
+
// As the set trap compares, so 0 and -0 differ and NaN equals itself.
|
|
180
|
+
if (inCopy !== inOriginal || !isEqual(value, previous)) {
|
|
181
|
+
const _path = basePath.concat([index]);
|
|
182
|
+
const path = escapePath(_path, pathAsArray);
|
|
183
|
+
if (forward === -1) {
|
|
184
|
+
if (inCopy) {
|
|
185
|
+
patches.push({
|
|
186
|
+
op: Operation.Replace,
|
|
187
|
+
path,
|
|
188
|
+
value: cloneIfNeeded(value),
|
|
189
|
+
});
|
|
190
|
+
} else {
|
|
191
|
+
forward = index;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (inverse === -1) {
|
|
195
|
+
if (inOriginal) {
|
|
196
|
+
inversePatches.push({
|
|
197
|
+
op: Operation.Replace,
|
|
198
|
+
path,
|
|
199
|
+
value: cloneIfNeeded(previous),
|
|
200
|
+
});
|
|
201
|
+
} else {
|
|
202
|
+
inverse = index;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (forward !== -1 && inverse !== -1) break;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (forward === -1) {
|
|
209
|
+
for (let index = original.length; index < copy.length; index += 1) {
|
|
210
|
+
const value = copy[index];
|
|
211
|
+
if (value === undefined && !hasOwn.call(copy, index)) {
|
|
212
|
+
forward = index;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
const _path = basePath.concat([index]);
|
|
216
|
+
const path = escapePath(_path, pathAsArray);
|
|
217
|
+
patches.push({
|
|
218
|
+
op: Operation.Add,
|
|
219
|
+
path,
|
|
220
|
+
// If it is a draft, it needs to be deep cloned, and it may also be non-draft.
|
|
221
|
+
value: cloneIfNeeded(value),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (forward !== -1) {
|
|
226
|
+
// Every index that the copy has past the end of the original was set by
|
|
227
|
+
// the recipe, so `indices` holds it. A shorter copy was swapped, which
|
|
228
|
+
// makes `copy` the original array.
|
|
229
|
+
rebuildSuffix(
|
|
230
|
+
original,
|
|
231
|
+
copy,
|
|
232
|
+
forward,
|
|
233
|
+
shorter || forward < original.length ? null : indices,
|
|
234
|
+
basePath,
|
|
235
|
+
patches,
|
|
236
|
+
pathAsArray,
|
|
237
|
+
arrayLengthAssignment
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (inverse !== -1) {
|
|
241
|
+
rebuildSuffix(
|
|
242
|
+
copy,
|
|
243
|
+
original,
|
|
244
|
+
inverse,
|
|
245
|
+
null,
|
|
246
|
+
basePath,
|
|
247
|
+
inversePatches,
|
|
248
|
+
pathAsArray,
|
|
249
|
+
arrayLengthAssignment
|
|
250
|
+
);
|
|
251
|
+
} else if (original.length < copy.length) {
|
|
252
|
+
// https://www.rfc-editor.org/rfc/rfc6902#appendix-A.4
|
|
253
|
+
// For performance, here we only generate an operation that replaces the length of the array,
|
|
254
|
+
// which is inconsistent with JSON Patch specification
|
|
255
|
+
if (arrayLengthAssignment) {
|
|
256
|
+
const _path = basePath.concat(['length']);
|
|
257
|
+
const path = escapePath(_path, pathAsArray);
|
|
258
|
+
inversePatches.push({
|
|
259
|
+
op: Operation.Replace,
|
|
260
|
+
path,
|
|
261
|
+
value: original.length,
|
|
262
|
+
});
|
|
263
|
+
} else {
|
|
264
|
+
for (let index = copy.length; original.length < index; index -= 1) {
|
|
265
|
+
const _path = basePath.concat([index - 1]);
|
|
266
|
+
const path = escapePath(_path, pathAsArray);
|
|
267
|
+
inversePatches.push({
|
|
268
|
+
op: Operation.Remove,
|
|
269
|
+
path,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function generatePatchesFromAssigned(
|
|
277
|
+
{ original, copy, assignedMap }: ProxyDraft<Record<string, any>>,
|
|
278
|
+
basePath: any[],
|
|
279
|
+
patches: Patches,
|
|
280
|
+
inversePatches: Patches,
|
|
281
|
+
pathAsArray: boolean
|
|
282
|
+
) {
|
|
283
|
+
assignedMap!.forEach((assignedValue, key) => {
|
|
284
|
+
const originalValue = get(original, key);
|
|
285
|
+
const value = cloneIfNeeded(get(copy, key));
|
|
286
|
+
const op = !assignedValue
|
|
287
|
+
? Operation.Remove
|
|
288
|
+
: has(original, key)
|
|
289
|
+
? Operation.Replace
|
|
290
|
+
: Operation.Add;
|
|
291
|
+
if (isEqual(originalValue, value) && op === Operation.Replace) return;
|
|
292
|
+
if (__DEV__) checkPathKey(getType(original), key, pathAsArray);
|
|
293
|
+
// A Map key can be an array, which stays one path segment.
|
|
294
|
+
const _path = basePath.concat([key]);
|
|
295
|
+
const path = escapePath(_path, pathAsArray);
|
|
296
|
+
patches.push(op === Operation.Remove ? { op, path } : { op, path, value });
|
|
297
|
+
inversePatches.push(
|
|
298
|
+
op === Operation.Add
|
|
299
|
+
? { op: Operation.Remove, path }
|
|
300
|
+
: op === Operation.Remove
|
|
301
|
+
? { op: Operation.Add, path, value: originalValue }
|
|
302
|
+
: { op: Operation.Replace, path, value: originalValue }
|
|
303
|
+
);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function generateSetPatches(
|
|
308
|
+
{ original, copy }: ProxyDraft<Set<any>>,
|
|
309
|
+
basePath: any[],
|
|
310
|
+
patches: Patches,
|
|
311
|
+
inversePatches: Patches,
|
|
312
|
+
pathAsArray: boolean
|
|
313
|
+
) {
|
|
314
|
+
let index = 0;
|
|
315
|
+
original.forEach((value: any) => {
|
|
316
|
+
if (!copy!.has(value)) {
|
|
317
|
+
const _path = basePath.concat([index]);
|
|
318
|
+
const path = escapePath(_path, pathAsArray);
|
|
319
|
+
patches.push({
|
|
320
|
+
op: Operation.Remove,
|
|
321
|
+
path,
|
|
322
|
+
value,
|
|
323
|
+
});
|
|
324
|
+
inversePatches.unshift({
|
|
325
|
+
op: Operation.Add,
|
|
326
|
+
path,
|
|
327
|
+
value,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
index += 1;
|
|
331
|
+
});
|
|
332
|
+
index = 0;
|
|
333
|
+
copy!.forEach((value: any) => {
|
|
334
|
+
if (!original.has(value)) {
|
|
335
|
+
const _path = basePath.concat([index]);
|
|
336
|
+
const path = escapePath(_path, pathAsArray);
|
|
337
|
+
patches.push({
|
|
338
|
+
op: Operation.Add,
|
|
339
|
+
path,
|
|
340
|
+
value,
|
|
341
|
+
});
|
|
342
|
+
inversePatches.unshift({
|
|
343
|
+
op: Operation.Remove,
|
|
344
|
+
path,
|
|
345
|
+
value,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
index += 1;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function generatePatches(
|
|
353
|
+
proxyState: ProxyDraft,
|
|
354
|
+
basePath: any[],
|
|
355
|
+
patches: Patches,
|
|
356
|
+
inversePatches: Patches
|
|
357
|
+
) {
|
|
358
|
+
const { pathAsArray = true } = proxyState.options.enablePatches;
|
|
359
|
+
switch (proxyState.type) {
|
|
360
|
+
case DraftType.Object:
|
|
361
|
+
case DraftType.Map:
|
|
362
|
+
return generatePatchesFromAssigned(
|
|
363
|
+
proxyState,
|
|
364
|
+
basePath,
|
|
365
|
+
patches,
|
|
366
|
+
inversePatches,
|
|
367
|
+
pathAsArray
|
|
368
|
+
);
|
|
369
|
+
case DraftType.Array:
|
|
370
|
+
return generateArrayPatches(
|
|
371
|
+
proxyState,
|
|
372
|
+
basePath,
|
|
373
|
+
patches,
|
|
374
|
+
inversePatches,
|
|
375
|
+
pathAsArray
|
|
376
|
+
);
|
|
377
|
+
case DraftType.Set:
|
|
378
|
+
return generateSetPatches(
|
|
379
|
+
proxyState,
|
|
380
|
+
basePath,
|
|
381
|
+
patches,
|
|
382
|
+
inversePatches,
|
|
383
|
+
pathAsArray
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RAW_RETURN_SYMBOL } from './constant';
|
|
2
|
+
import { die, ErrorCode } from './error';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Use rawReturn() to wrap the return value to skip the draft check and thus improve performance.
|
|
6
|
+
*
|
|
7
|
+
* ## Example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { create, rawReturn } from 'mutative';
|
|
11
|
+
*
|
|
12
|
+
* const baseState = { foo: { bar: 'str' }, arr: [] };
|
|
13
|
+
* const state = create(
|
|
14
|
+
* baseState,
|
|
15
|
+
* (draft) => {
|
|
16
|
+
* return rawReturn(baseState);
|
|
17
|
+
* },
|
|
18
|
+
* );
|
|
19
|
+
* expect(state).toBe(baseState);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function rawReturn<T extends object | undefined>(value: T): T {
|
|
23
|
+
if (arguments.length === 0) {
|
|
24
|
+
die(ErrorCode.RawReturnWithoutValue);
|
|
25
|
+
}
|
|
26
|
+
if (arguments.length > 1) {
|
|
27
|
+
die(ErrorCode.RawReturnWithExtraArguments);
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
__DEV__ &&
|
|
31
|
+
value !== undefined &&
|
|
32
|
+
(typeof value !== 'object' || value === null)
|
|
33
|
+
) {
|
|
34
|
+
console.warn(
|
|
35
|
+
'rawReturn() must be called with an object(including plain object, arrays, Set, Map, etc.) or `undefined`, other types do not need to be returned via rawReturn().'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
[RAW_RETURN_SYMBOL]: [value],
|
|
40
|
+
} as never;
|
|
41
|
+
}
|