@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,201 @@
|
|
|
1
|
+
import { ProxyDraft } from './interface';
|
|
2
|
+
import { dataTypes, iteratorPrototype, iteratorSymbol } from './constant';
|
|
3
|
+
import { internal } from './internal';
|
|
4
|
+
import {
|
|
5
|
+
assertDraftActive,
|
|
6
|
+
ensureShallowCopy,
|
|
7
|
+
getProxyDraft,
|
|
8
|
+
getSetMap,
|
|
9
|
+
isDraftable,
|
|
10
|
+
iterateSet,
|
|
11
|
+
latest,
|
|
12
|
+
markChanged,
|
|
13
|
+
markFinalization,
|
|
14
|
+
setItemValue,
|
|
15
|
+
} from './utils';
|
|
16
|
+
import { checkReadable } from './unsafe';
|
|
17
|
+
|
|
18
|
+
// A Set draft adds and deletes items in its copy, which holds the items in
|
|
19
|
+
// order. `setMap` maps the original items that an iterator drafted to their
|
|
20
|
+
// drafts, and the objects that the recipe added, drafts among them, to
|
|
21
|
+
// themselves. Finalization replaces the drafts with their final values.
|
|
22
|
+
|
|
23
|
+
const getNextIterator =
|
|
24
|
+
(
|
|
25
|
+
target: ProxyDraft<any>,
|
|
26
|
+
iterator: IterableIterator<any>,
|
|
27
|
+
isValuesIterator: boolean
|
|
28
|
+
) =>
|
|
29
|
+
() => {
|
|
30
|
+
const result = iterator.next();
|
|
31
|
+
if (result.done) return result;
|
|
32
|
+
assertDraftActive(target);
|
|
33
|
+
const key = result.value as any;
|
|
34
|
+
let value = setItemValue(target, key);
|
|
35
|
+
const currentDraft = getProxyDraft(value);
|
|
36
|
+
const mutable =
|
|
37
|
+
target.options.mark?.(value, dataTypes) === dataTypes.mutable;
|
|
38
|
+
if (target.options.strict) {
|
|
39
|
+
checkReadable(key, target.options, mutable);
|
|
40
|
+
}
|
|
41
|
+
// Only an original item still mapped to itself needs a draft. Preserve
|
|
42
|
+
// copies when this mapping has already been finalized.
|
|
43
|
+
if (
|
|
44
|
+
!mutable &&
|
|
45
|
+
!currentDraft &&
|
|
46
|
+
value === key &&
|
|
47
|
+
isDraftable(key, target.options) &&
|
|
48
|
+
!target.finalized &&
|
|
49
|
+
target.original!.has(key)
|
|
50
|
+
) {
|
|
51
|
+
// draft a draftable original set item
|
|
52
|
+
const proxy = internal.createDraft(
|
|
53
|
+
key,
|
|
54
|
+
target,
|
|
55
|
+
key,
|
|
56
|
+
target.finalities,
|
|
57
|
+
target.options
|
|
58
|
+
);
|
|
59
|
+
getSetMap(target).set(key, proxy);
|
|
60
|
+
value = proxy;
|
|
61
|
+
} else if (currentDraft) {
|
|
62
|
+
// drafted
|
|
63
|
+
value = currentDraft.proxy;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
done: false,
|
|
67
|
+
value: isValuesIterator ? value : [value, value],
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const setHandler = {
|
|
72
|
+
get size() {
|
|
73
|
+
return latest(getProxyDraft(this)!).size;
|
|
74
|
+
},
|
|
75
|
+
has(value: any) {
|
|
76
|
+
const items: Set<any> = latest(getProxyDraft(this)!);
|
|
77
|
+
let valueProxyDraft: ProxyDraft | null;
|
|
78
|
+
// The value itself, which may be a draft that its producer revoked, or the
|
|
79
|
+
// item that a draft of it stands for.
|
|
80
|
+
return (
|
|
81
|
+
items.has(value) ||
|
|
82
|
+
(!!(valueProxyDraft = getProxyDraft(value)) &&
|
|
83
|
+
items.has(valueProxyDraft.original))
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
add(value: any) {
|
|
87
|
+
const target = getProxyDraft(this)!;
|
|
88
|
+
if (!this.has(value)) {
|
|
89
|
+
ensureShallowCopy(target);
|
|
90
|
+
markChanged(target);
|
|
91
|
+
target.assignedMap!.set(value, true);
|
|
92
|
+
target.copy!.add(value);
|
|
93
|
+
// An added draft is replaced by its final value when finalizing, and an
|
|
94
|
+
// added object is finalized for the drafts it may hold.
|
|
95
|
+
if (value && typeof value === 'object')
|
|
96
|
+
getSetMap(target).set(value, value);
|
|
97
|
+
markFinalization(target, value, value);
|
|
98
|
+
}
|
|
99
|
+
return this;
|
|
100
|
+
},
|
|
101
|
+
delete(value: any): boolean {
|
|
102
|
+
if (!this.has(value)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const target = getProxyDraft(this)!;
|
|
106
|
+
ensureShallowCopy(target);
|
|
107
|
+
markChanged(target);
|
|
108
|
+
const copy: Set<any> = target.copy!;
|
|
109
|
+
const valueProxyDraft = getProxyDraft(value);
|
|
110
|
+
// A draft of an item stands for the item; an added draft is an item.
|
|
111
|
+
const item =
|
|
112
|
+
valueProxyDraft && copy.has(valueProxyDraft.original)
|
|
113
|
+
? valueProxyDraft.original
|
|
114
|
+
: value;
|
|
115
|
+
if (valueProxyDraft && item === value) {
|
|
116
|
+
// reassigned
|
|
117
|
+
target.assignedMap!.delete(value);
|
|
118
|
+
} else {
|
|
119
|
+
target.assignedMap!.set(item, false);
|
|
120
|
+
}
|
|
121
|
+
if (target.setMap) target.setMap.delete(item);
|
|
122
|
+
return copy.delete(item);
|
|
123
|
+
},
|
|
124
|
+
clear() {
|
|
125
|
+
if (!this.size) return;
|
|
126
|
+
const target = getProxyDraft(this)!;
|
|
127
|
+
ensureShallowCopy(target);
|
|
128
|
+
markChanged(target);
|
|
129
|
+
for (const value of target.original) {
|
|
130
|
+
target.assignedMap!.set(value, false);
|
|
131
|
+
}
|
|
132
|
+
if (target.setMap) target.setMap.clear();
|
|
133
|
+
target.copy!.clear();
|
|
134
|
+
},
|
|
135
|
+
values(): IterableIterator<any> {
|
|
136
|
+
const target = getProxyDraft(this)!;
|
|
137
|
+
ensureShallowCopy(target);
|
|
138
|
+
const iterator = iterateSet(target.copy!);
|
|
139
|
+
return {
|
|
140
|
+
__proto__: iteratorPrototype,
|
|
141
|
+
next: getNextIterator(target, iterator, true),
|
|
142
|
+
} as any;
|
|
143
|
+
},
|
|
144
|
+
entries(): IterableIterator<[any, any]> {
|
|
145
|
+
const target = getProxyDraft(this)!;
|
|
146
|
+
ensureShallowCopy(target);
|
|
147
|
+
const iterator = iterateSet(target.copy!);
|
|
148
|
+
return {
|
|
149
|
+
__proto__: iteratorPrototype,
|
|
150
|
+
next: getNextIterator(
|
|
151
|
+
target,
|
|
152
|
+
iterator,
|
|
153
|
+
false
|
|
154
|
+
) as () => IteratorReturnResult<any>,
|
|
155
|
+
} as any;
|
|
156
|
+
},
|
|
157
|
+
keys(): IterableIterator<any> {
|
|
158
|
+
return this.values();
|
|
159
|
+
},
|
|
160
|
+
[iteratorSymbol]() {
|
|
161
|
+
return this.values();
|
|
162
|
+
},
|
|
163
|
+
forEach(callback: any, thisArg?: any) {
|
|
164
|
+
const iterator = this.values();
|
|
165
|
+
let result = iterator.next();
|
|
166
|
+
while (!result.done) {
|
|
167
|
+
callback.call(thisArg, result.value, result.value, this);
|
|
168
|
+
result = iterator.next();
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if ('difference' in Set.prototype) {
|
|
174
|
+
// for compatibility with new Set methods
|
|
175
|
+
// https://github.com/tc39/proposal-set-methods
|
|
176
|
+
// And `https://github.com/tc39/proposal-set-methods/blob/main/details.md#symbolspecies` has some details about the `@@species` symbol.
|
|
177
|
+
// So we can't use SubSet instance constructor to get the constructor of the SubSet instance.
|
|
178
|
+
(
|
|
179
|
+
[
|
|
180
|
+
'intersection',
|
|
181
|
+
'union',
|
|
182
|
+
'difference',
|
|
183
|
+
'symmetricDifference',
|
|
184
|
+
'isSubsetOf',
|
|
185
|
+
'isSupersetOf',
|
|
186
|
+
'isDisjointFrom',
|
|
187
|
+
] as const
|
|
188
|
+
).forEach((method) => {
|
|
189
|
+
(setHandler as any)[method] = function (
|
|
190
|
+
this: Set<any>,
|
|
191
|
+
other: ReadonlySetLike<any>
|
|
192
|
+
) {
|
|
193
|
+
return (Set.prototype[method] as Function).call(
|
|
194
|
+
new Set(this.values()),
|
|
195
|
+
other
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export const setHandlerKeys = Reflect.ownKeys(setHandler);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Options } from './interface';
|
|
2
|
+
import { isDraftable } from './utils';
|
|
3
|
+
import { die, ErrorCode } from './error';
|
|
4
|
+
|
|
5
|
+
let readable = false;
|
|
6
|
+
|
|
7
|
+
export const checkReadable = (
|
|
8
|
+
value: any,
|
|
9
|
+
options: Options<any, any>,
|
|
10
|
+
ignoreCheckDraftable = false
|
|
11
|
+
) => {
|
|
12
|
+
if (
|
|
13
|
+
typeof value === 'object' &&
|
|
14
|
+
value !== null &&
|
|
15
|
+
(!isDraftable(value, options) || ignoreCheckDraftable) &&
|
|
16
|
+
!readable
|
|
17
|
+
) {
|
|
18
|
+
die(ErrorCode.StrictModeAccess);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Whether reads from drafts are checked now: in strict mode, outside
|
|
23
|
+
// `unsafe()`.
|
|
24
|
+
export const checksReads = (options: Options<any, any>) =>
|
|
25
|
+
!!options.strict && !readable;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `unsafe(callback)` to access mutable data directly in strict mode.
|
|
29
|
+
*
|
|
30
|
+
* ## Example
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { create, unsafe } from 'mutative';
|
|
34
|
+
*
|
|
35
|
+
* class Foobar {
|
|
36
|
+
* bar = 1;
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* const baseState = { foobar: new Foobar() };
|
|
40
|
+
* const state = create(
|
|
41
|
+
* baseState,
|
|
42
|
+
* (draft) => {
|
|
43
|
+
* unsafe(() => {
|
|
44
|
+
* draft.foobar.bar = 2;
|
|
45
|
+
* });
|
|
46
|
+
* },
|
|
47
|
+
* {
|
|
48
|
+
* strict: true,
|
|
49
|
+
* }
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* expect(state).toBe(baseState);
|
|
53
|
+
* expect(state.foobar).toBe(baseState.foobar);
|
|
54
|
+
* expect(state.foobar.bar).toBe(2);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function unsafe<T>(callback: () => T): T {
|
|
58
|
+
// A nested call hands the outer call's access back when it ends.
|
|
59
|
+
const previous = readable;
|
|
60
|
+
readable = true;
|
|
61
|
+
try {
|
|
62
|
+
return callback();
|
|
63
|
+
} finally {
|
|
64
|
+
readable = previous;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Draft, Immutable } from '../interface';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cast a value to its draft type; it returns the value as it is.
|
|
5
|
+
*/
|
|
6
|
+
export function castDraft<T>(value: T): Draft<T> {
|
|
7
|
+
return value as any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Cast a value to its immutable type, without freezing it.
|
|
12
|
+
*/
|
|
13
|
+
export function castImmutable<T>(value: T): Immutable<T> {
|
|
14
|
+
return value as any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Cast a draft to the type of its base state.
|
|
19
|
+
*/
|
|
20
|
+
export function castMutable<T>(draft: Draft<T>): T {
|
|
21
|
+
return draft as any;
|
|
22
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type { Options, ProxyDraft } from '../interface';
|
|
2
|
+
import { dataTypes } from '../constant';
|
|
3
|
+
import { getValue, isDraft, isDraftable, iterateSet } from './draft';
|
|
4
|
+
import { isBaseMapInstance, isBaseSetInstance, isPlainArray } from './proto';
|
|
5
|
+
import { die, ErrorCode } from '../error';
|
|
6
|
+
|
|
7
|
+
function strictCopy(target: any) {
|
|
8
|
+
const copy = Object.create(Object.getPrototypeOf(target));
|
|
9
|
+
Reflect.ownKeys(target).forEach((key: any) => {
|
|
10
|
+
let desc = Reflect.getOwnPropertyDescriptor(target, key)!;
|
|
11
|
+
// An assignment to `__proto__` would set the prototype of the copy, so an
|
|
12
|
+
// own `__proto__` key, as `JSON.parse()` creates one, is defined instead.
|
|
13
|
+
if (
|
|
14
|
+
key !== '__proto__' &&
|
|
15
|
+
desc.enumerable &&
|
|
16
|
+
desc.configurable &&
|
|
17
|
+
desc.writable
|
|
18
|
+
) {
|
|
19
|
+
copy[key] = target[key];
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// for freeze
|
|
23
|
+
if (!desc.writable) {
|
|
24
|
+
desc.writable = true;
|
|
25
|
+
desc.configurable = true;
|
|
26
|
+
}
|
|
27
|
+
if (desc.get || desc.set)
|
|
28
|
+
desc = {
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
enumerable: desc.enumerable,
|
|
32
|
+
value: target[key],
|
|
33
|
+
};
|
|
34
|
+
Reflect.defineProperty(copy, key, desc);
|
|
35
|
+
});
|
|
36
|
+
return copy;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Plain objects with at most this many own enumerable string keys are copied
|
|
43
|
+
* with object spread, which V8 clones in one step. Wider objects are copied
|
|
44
|
+
* key by key into a dictionary-mode object: a map transition per key is far
|
|
45
|
+
* slower there, and whether V8 stays in fast mode depends on transitions that
|
|
46
|
+
* other code may have created for the same key sequence.
|
|
47
|
+
*/
|
|
48
|
+
const SPREAD_KEY_LIMIT = 128;
|
|
49
|
+
|
|
50
|
+
function copyPlainObject(original: any) {
|
|
51
|
+
const keys = Object.keys(original);
|
|
52
|
+
if (keys.length <= SPREAD_KEY_LIMIT) {
|
|
53
|
+
// Own enumerable string and symbol keys, like the loop below.
|
|
54
|
+
return { ...original };
|
|
55
|
+
}
|
|
56
|
+
const copy: Record<string | symbol, any> = {};
|
|
57
|
+
// Deleting a property that is not the last one switches the object to
|
|
58
|
+
// dictionary mode, so the wide copy inserts in constant time per key.
|
|
59
|
+
copy.a = 1;
|
|
60
|
+
copy.b = 1;
|
|
61
|
+
delete copy.a;
|
|
62
|
+
delete copy.b;
|
|
63
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
64
|
+
const key = keys[index];
|
|
65
|
+
if (key === '__proto__') {
|
|
66
|
+
// An own `__proto__` key (e.g. from JSON.parse) must stay a data
|
|
67
|
+
// property instead of changing the copy's prototype.
|
|
68
|
+
Object.defineProperty(copy, key, {
|
|
69
|
+
value: original[key],
|
|
70
|
+
writable: true,
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
copy[key] = original[key];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const symbols = Object.getOwnPropertySymbols(original);
|
|
79
|
+
for (let index = 0; index < symbols.length; index += 1) {
|
|
80
|
+
const key = symbols[index];
|
|
81
|
+
if (propIsEnum.call(original, key)) {
|
|
82
|
+
copy[key] = original[key];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return copy;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Copies an array with `concat`, which keeps holes and creates the copy
|
|
89
|
+
// through `Symbol.species`. `concat` puts an array whose
|
|
90
|
+
// `Symbol.isConcatSpreadable` is false into the copy as one element instead,
|
|
91
|
+
// so such an array is copied with `slice`.
|
|
92
|
+
function concatCopy(original: any[]) {
|
|
93
|
+
const copy = Array.prototype.concat.call(original);
|
|
94
|
+
return copy.length === 1 && copy[0] === original
|
|
95
|
+
? Array.prototype.slice.call(original)
|
|
96
|
+
: copy;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const arrayValues = Array.prototype[Symbol.iterator];
|
|
100
|
+
const arrayIterator = Object.getPrototypeOf(arrayValues.call([]));
|
|
101
|
+
const arrayIteratorNext = arrayIterator.next;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* `concat` leaves V8's fast path for frozen, sealed and non-extensible arrays
|
|
105
|
+
* and takes about ten times as long as a spread there. A spread copies a
|
|
106
|
+
* plain array the same way when it has no holes and none of the iterators it
|
|
107
|
+
* calls has been replaced. Holes read as `undefined`, so arrays that hold
|
|
108
|
+
* `undefined` keep `concat`.
|
|
109
|
+
*/
|
|
110
|
+
function copyLockedArray(original: any[]) {
|
|
111
|
+
return isPlainArray(original) &&
|
|
112
|
+
!Object.prototype.hasOwnProperty.call(original, Symbol.iterator) &&
|
|
113
|
+
Array.prototype[Symbol.iterator] === arrayValues &&
|
|
114
|
+
arrayIterator.next === arrayIteratorNext &&
|
|
115
|
+
!Array.prototype.includes.call(original, undefined)
|
|
116
|
+
? [...original]
|
|
117
|
+
: concatCopy(original);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function shallowCopy(original: any, options?: Options<any, any>) {
|
|
121
|
+
let markResult: any;
|
|
122
|
+
if (Array.isArray(original)) {
|
|
123
|
+
// With auto-freeze, the arrays of a state are frozen; otherwise checking
|
|
124
|
+
// for that would cost more than it saves.
|
|
125
|
+
return options?.enableAutoFreeze && !Object.isExtensible(original)
|
|
126
|
+
? copyLockedArray(original)
|
|
127
|
+
: concatCopy(original);
|
|
128
|
+
} else if (original instanceof Set) {
|
|
129
|
+
if (!isBaseSetInstance(original)) {
|
|
130
|
+
const SubClass = Object.getPrototypeOf(original).constructor;
|
|
131
|
+
const copy = new SubClass(original.values());
|
|
132
|
+
// The copy of a Set draft holds the original items in their order,
|
|
133
|
+
// whatever the subclass's constructor or `add` does with them.
|
|
134
|
+
Set.prototype.clear.call(copy);
|
|
135
|
+
for (const item of iterateSet(original))
|
|
136
|
+
Set.prototype.add.call(copy, item);
|
|
137
|
+
return copy;
|
|
138
|
+
}
|
|
139
|
+
// The Set draft of an outer create() call has no Set internals.
|
|
140
|
+
return !isDraft(original) && Set.prototype.difference
|
|
141
|
+
? Set.prototype.difference.call(original, new Set())
|
|
142
|
+
: new Set(original.values());
|
|
143
|
+
} else if (original instanceof Map) {
|
|
144
|
+
if (!isBaseMapInstance(original)) {
|
|
145
|
+
const SubClass = Object.getPrototypeOf(original).constructor;
|
|
146
|
+
return new SubClass(original);
|
|
147
|
+
}
|
|
148
|
+
return new Map(original);
|
|
149
|
+
} else if (
|
|
150
|
+
options?.mark &&
|
|
151
|
+
((markResult = options.mark(original, dataTypes)),
|
|
152
|
+
markResult !== undefined) &&
|
|
153
|
+
markResult !== dataTypes.mutable
|
|
154
|
+
) {
|
|
155
|
+
if (markResult === dataTypes.immutable) {
|
|
156
|
+
return strictCopy(original);
|
|
157
|
+
} else if (typeof markResult === 'function') {
|
|
158
|
+
if (__DEV__ && (options.enablePatches || options.enableAutoFreeze)) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`You can't use mark and patches or auto freeze together.`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return markResult();
|
|
164
|
+
}
|
|
165
|
+
die(ErrorCode.UnsupportedMarkResult, markResult);
|
|
166
|
+
} else if (
|
|
167
|
+
typeof original === 'object' &&
|
|
168
|
+
Object.getPrototypeOf(original) === Object.prototype
|
|
169
|
+
) {
|
|
170
|
+
return copyPlainObject(original);
|
|
171
|
+
} else {
|
|
172
|
+
die(ErrorCode.InvalidMark);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function ensureShallowCopy(target: ProxyDraft) {
|
|
177
|
+
if (target.copy) return;
|
|
178
|
+
target.copy = shallowCopy(target.original, target.options)!;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function deepClone<T>(target: T): T;
|
|
182
|
+
function deepClone(target: any) {
|
|
183
|
+
if (!isDraftable(target)) return getValue(target);
|
|
184
|
+
if (Array.isArray(target)) return target.map(deepClone);
|
|
185
|
+
if (target instanceof Map) {
|
|
186
|
+
const iterable = Array.from(target.entries()).map(([k, v]) => [
|
|
187
|
+
k,
|
|
188
|
+
deepClone(v),
|
|
189
|
+
]) as Iterable<readonly [any, any]>;
|
|
190
|
+
if (!isBaseMapInstance(target)) {
|
|
191
|
+
const SubClass = Object.getPrototypeOf(target).constructor;
|
|
192
|
+
return new SubClass(iterable);
|
|
193
|
+
}
|
|
194
|
+
return new Map(iterable);
|
|
195
|
+
}
|
|
196
|
+
if (target instanceof Set) {
|
|
197
|
+
const iterable = Array.from(target).map(deepClone);
|
|
198
|
+
if (!isBaseSetInstance(target)) {
|
|
199
|
+
const SubClass = Object.getPrototypeOf(target).constructor;
|
|
200
|
+
return new SubClass(iterable);
|
|
201
|
+
}
|
|
202
|
+
return new Set(iterable);
|
|
203
|
+
}
|
|
204
|
+
// Own enumerable string and symbol keys, as drafts copy plain objects. The
|
|
205
|
+
// spread keeps an own `__proto__` key a data property, and assignments to
|
|
206
|
+
// the copy's own keys cannot change its prototype.
|
|
207
|
+
const copy = { ...target };
|
|
208
|
+
for (const key in copy) {
|
|
209
|
+
const value = copy[key];
|
|
210
|
+
if (typeof value === 'object' && value !== null) {
|
|
211
|
+
copy[key] = deepClone(value);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const symbols = Object.getOwnPropertySymbols(copy);
|
|
215
|
+
for (let index = 0; index < symbols.length; index += 1) {
|
|
216
|
+
const value = copy[symbols[index]];
|
|
217
|
+
if (typeof value === 'object' && value !== null) {
|
|
218
|
+
copy[symbols[index]] = deepClone(value);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return copy;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { deepClone };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { DraftType } from '../interface';
|
|
2
|
+
import { getType, isDraft } from './draft';
|
|
3
|
+
import { die, ErrorCode } from '../error';
|
|
4
|
+
|
|
5
|
+
function throwFrozenError() {
|
|
6
|
+
die(ErrorCode.CannotModifyFrozenObject);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isFreezable(value: any) {
|
|
10
|
+
return (
|
|
11
|
+
__DEV__ || (value && typeof value === 'object' && !Object.isFrozen(value))
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function deepFreeze(
|
|
16
|
+
target: any,
|
|
17
|
+
subKey?: any,
|
|
18
|
+
stack?: any[],
|
|
19
|
+
keys?: any[]
|
|
20
|
+
) {
|
|
21
|
+
if (__DEV__) {
|
|
22
|
+
stack = stack ?? [];
|
|
23
|
+
keys = keys ?? [];
|
|
24
|
+
// A cycle is an object that holds itself through its values. The copy of a
|
|
25
|
+
// changed draft is a different object from its original, so a copy that
|
|
26
|
+
// holds its original, as `draft.prev = original(draft)` makes it, is no
|
|
27
|
+
// cycle, and neither is a shared object reached through another path.
|
|
28
|
+
if (stack.length > 0) {
|
|
29
|
+
const index = stack.indexOf(target);
|
|
30
|
+
if (target && typeof target === 'object' && index !== -1) {
|
|
31
|
+
if (stack[0] === target) {
|
|
32
|
+
throw new Error(`Forbids circular reference`);
|
|
33
|
+
}
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Forbids circular reference: ~/${keys
|
|
36
|
+
.slice(0, index)
|
|
37
|
+
.map((key, index) => {
|
|
38
|
+
if (typeof key === 'symbol') return `[${key.toString()}]`;
|
|
39
|
+
const parent = stack![index];
|
|
40
|
+
if (
|
|
41
|
+
typeof key === 'object' &&
|
|
42
|
+
(parent instanceof Map || parent instanceof Set)
|
|
43
|
+
)
|
|
44
|
+
return Array.from(parent.keys()).indexOf(key);
|
|
45
|
+
return key;
|
|
46
|
+
})
|
|
47
|
+
.join('/')}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
stack.push(target);
|
|
51
|
+
keys.push(subKey);
|
|
52
|
+
} else {
|
|
53
|
+
stack.push(target);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (Object.isFrozen(target) || isDraft(target)) {
|
|
57
|
+
if (__DEV__) {
|
|
58
|
+
stack!.pop();
|
|
59
|
+
keys!.pop();
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const type = getType(target);
|
|
64
|
+
// Like other objects, a Map or Set is frozen before its contents, so that a
|
|
65
|
+
// later freeze skips it and a circular reference ends the walk. Freezing
|
|
66
|
+
// leaves its entries mutable, which the guards installed first prevent.
|
|
67
|
+
switch (type) {
|
|
68
|
+
case DraftType.Map:
|
|
69
|
+
target.set = target.clear = target.delete = throwFrozenError;
|
|
70
|
+
Object.freeze(target);
|
|
71
|
+
for (const [key, value] of target) {
|
|
72
|
+
if (isFreezable(key)) deepFreeze(key, key, stack, keys);
|
|
73
|
+
if (isFreezable(value)) deepFreeze(value, key, stack, keys);
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case DraftType.Set:
|
|
77
|
+
target.add = target.clear = target.delete = throwFrozenError;
|
|
78
|
+
Object.freeze(target);
|
|
79
|
+
for (const value of target) {
|
|
80
|
+
if (isFreezable(value)) deepFreeze(value, value, stack, keys);
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
case DraftType.Array:
|
|
84
|
+
Object.freeze(target);
|
|
85
|
+
let index = 0;
|
|
86
|
+
for (const value of target) {
|
|
87
|
+
if (isFreezable(value)) deepFreeze(value, index, stack, keys);
|
|
88
|
+
index += 1;
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
Object.freeze(target);
|
|
93
|
+
// ignore non-enumerable or symbol properties
|
|
94
|
+
Object.keys(target).forEach((name) => {
|
|
95
|
+
const value = target[name];
|
|
96
|
+
if (isFreezable(value)) deepFreeze(value, name, stack, keys);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (__DEV__) {
|
|
100
|
+
stack!.pop();
|
|
101
|
+
keys!.pop();
|
|
102
|
+
}
|
|
103
|
+
}
|