mobx-keystone 0.67.4 → 0.68.1-alpha
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/CHANGELOG.md +8 -0
- package/dist/_virtual/_tslib.mjs +12 -0
- package/dist/mobx-keystone.umd.js +5339 -5261
- package/dist/model/utils.d.ts +1 -1
- package/dist/node_modules/fast-deep-equal/es6/index.mjs +68 -0
- package/dist/node_modules/nanoid/non-secure/index.mjs +11 -0
- package/dist/snapshot/index.d.ts +0 -8
- package/dist/{dataModel/_BaseDataModel.d.ts → snapshot/registerDefaultReconcilers.d.ts} +0 -0
- package/dist/{model/_BaseModel.d.ts → snapshot/registerDefaultSnapshotters.d.ts} +0 -0
- package/dist/src/action/actionDecoratorUtils.mjs +25 -0
- package/dist/src/action/applyAction.mjs +54 -0
- package/dist/src/action/applyDelete.mjs +20 -0
- package/dist/src/action/applyMethodCall.mjs +19 -0
- package/dist/src/action/applySet.mjs +25 -0
- package/dist/src/action/builtInActions.mjs +15 -0
- package/dist/src/action/context.mjs +22 -0
- package/dist/src/action/hookActions.mjs +13 -0
- package/dist/src/action/isModelAction.mjs +6 -0
- package/dist/src/action/middleware.mjs +84 -0
- package/dist/src/action/modelAction.mjs +34 -0
- package/dist/src/action/modelFlow.mjs +251 -0
- package/dist/src/action/pendingActions.mjs +30 -0
- package/dist/src/action/protection.mjs +19 -0
- package/dist/src/action/runUnprotected.mjs +24 -0
- package/dist/src/action/wrapInAction.mjs +90 -0
- package/dist/src/actionMiddlewares/actionSerialization/actionSerialization.mjs +131 -0
- package/dist/src/actionMiddlewares/actionSerialization/applySerializedAction.mjs +110 -0
- package/dist/src/actionMiddlewares/actionSerialization/arraySerializer.mjs +15 -0
- package/dist/src/actionMiddlewares/actionSerialization/core.mjs +3 -0
- package/dist/src/actionMiddlewares/actionSerialization/dateSerializer.mjs +15 -0
- package/dist/src/actionMiddlewares/actionSerialization/mapSerializer.mjs +32 -0
- package/dist/src/actionMiddlewares/actionSerialization/objectPathSerializer.mjs +33 -0
- package/dist/src/actionMiddlewares/actionSerialization/objectSnapshotSerializer.mjs +18 -0
- package/dist/src/actionMiddlewares/actionSerialization/plainObjectSerializer.mjs +27 -0
- package/dist/src/actionMiddlewares/actionSerialization/primitiveSerializer.mjs +39 -0
- package/dist/src/actionMiddlewares/actionSerialization/setSerializer.mjs +29 -0
- package/dist/src/actionMiddlewares/actionTrackingMiddleware.mjs +239 -0
- package/dist/src/actionMiddlewares/onActionMiddleware.mjs +44 -0
- package/dist/src/actionMiddlewares/readonlyMiddleware.mjs +49 -0
- package/dist/src/actionMiddlewares/transactionMiddleware.mjs +69 -0
- package/dist/src/actionMiddlewares/undoMiddleware.mjs +472 -0
- package/dist/src/actionMiddlewares/utils.mjs +25 -0
- package/dist/src/computedTree/computedTree.mjs +63 -0
- package/dist/src/context/context.mjs +141 -0
- package/dist/src/dataModel/BaseDataModel.mjs +108 -0
- package/dist/src/dataModel/DataModel.mjs +32 -0
- package/dist/src/dataModel/actions.mjs +12 -0
- package/dist/src/dataModel/getDataModelMetadata.mjs +14 -0
- package/dist/src/dataModel/newDataModel.mjs +31 -0
- package/dist/src/dataModel/utils.mjs +29 -0
- package/dist/src/frozen/Frozen.mjs +68 -0
- package/dist/src/globalConfig/globalConfig.mjs +57 -0
- package/dist/src/index.mjs +97 -0
- package/dist/src/model/BaseModel.mjs +118 -0
- package/dist/src/model/Model.mjs +36 -0
- package/dist/src/model/getModelMetadata.mjs +19 -0
- package/dist/src/model/metadata.mjs +7 -0
- package/dist/src/model/newModel.mjs +95 -0
- package/dist/src/model/utils.mjs +33 -0
- package/dist/src/modelShared/BaseModelShared.mjs +9 -0
- package/dist/src/modelShared/Model.mjs +249 -0
- package/dist/src/modelShared/checkModelDecoratorArgs.mjs +21 -0
- package/dist/src/modelShared/modelClassInitializer.mjs +14 -0
- package/dist/src/modelShared/modelDecorator.mjs +117 -0
- package/dist/src/modelShared/modelInfo.mjs +7 -0
- package/dist/src/modelShared/modelPropsInfo.mjs +9 -0
- package/dist/src/modelShared/modelSymbols.mjs +5 -0
- package/dist/src/modelShared/newModel.mjs +13 -0
- package/dist/src/modelShared/prop.mjs +138 -0
- package/dist/src/modelShared/utils.mjs +10 -0
- package/dist/src/parent/core.mjs +34 -0
- package/dist/src/parent/coreObjectChildren.mjs +98 -0
- package/dist/src/parent/detach.mjs +32 -0
- package/dist/src/parent/findChildren.mjs +16 -0
- package/dist/src/parent/findParent.mjs +30 -0
- package/dist/src/parent/getChildrenObjects.mjs +12 -0
- package/dist/src/parent/onChildAttachedTo.mjs +101 -0
- package/dist/src/parent/path.mjs +149 -0
- package/dist/src/parent/path2.mjs +12 -0
- package/dist/src/parent/setParent.mjs +83 -0
- package/dist/src/parent/walkTree.mjs +104 -0
- package/dist/src/patch/applyPatches.mjs +118 -0
- package/dist/src/patch/emitPatch.mjs +100 -0
- package/dist/src/patch/jsonPatch.mjs +60 -0
- package/dist/src/patch/patchRecorder.mjs +75 -0
- package/dist/src/redux/connectReduxDevTools.mjs +153 -0
- package/dist/src/redux/redux.mjs +60 -0
- package/dist/src/ref/Ref.mjs +38 -0
- package/dist/src/ref/core.mjs +179 -0
- package/dist/src/ref/customRef.mjs +9 -0
- package/dist/src/ref/rootRef.mjs +34 -0
- package/dist/src/rootStore/attachDetach.mjs +53 -0
- package/dist/src/rootStore/rootStore.mjs +50 -0
- package/dist/src/snapshot/SnapshotterAndReconcilerPriority.mjs +9 -0
- package/dist/src/snapshot/applySnapshot.mjs +92 -0
- package/dist/src/snapshot/clone.mjs +29 -0
- package/dist/src/snapshot/fromArraySnapshot.mjs +23 -0
- package/dist/src/snapshot/fromFrozenSnapshot.mjs +13 -0
- package/dist/src/snapshot/fromModelSnapshot.mjs +38 -0
- package/dist/src/snapshot/fromPlainObjectSnapshot.mjs +26 -0
- package/dist/src/snapshot/fromSnapshot.mjs +91 -0
- package/dist/src/snapshot/getSnapshot.mjs +27 -0
- package/dist/src/snapshot/internal.mjs +97 -0
- package/dist/src/snapshot/onSnapshot.mjs +16 -0
- package/dist/src/snapshot/reconcileArraySnapshot.mjs +40 -0
- package/dist/src/snapshot/reconcileFrozenSnapshot.mjs +19 -0
- package/dist/src/snapshot/reconcileModelSnapshot.mjs +77 -0
- package/dist/src/snapshot/reconcilePlainObjectSnapshot.mjs +47 -0
- package/dist/src/snapshot/reconcileSnapshot.mjs +49 -0
- package/dist/src/snapshot/registerDefaultReconcilers.mjs +17 -0
- package/dist/src/snapshot/registerDefaultSnapshotters.mjs +17 -0
- package/dist/src/standardActions/actions.mjs +35 -0
- package/dist/src/standardActions/arrayActions.mjs +66 -0
- package/dist/src/standardActions/objectActions.mjs +36 -0
- package/dist/src/standardActions/standaloneActions.mjs +9 -0
- package/dist/src/transforms/ImmutableDate.mjs +51 -0
- package/dist/src/transforms/asMap.mjs +29 -0
- package/dist/src/transforms/asSet.mjs +12 -0
- package/dist/src/transforms/bigint.mjs +14 -0
- package/dist/src/transforms/date.mjs +27 -0
- package/dist/src/treeUtils/deepEquals.mjs +40 -0
- package/dist/src/treeUtils/draft.mjs +116 -0
- package/dist/src/treeUtils/sandbox.mjs +158 -0
- package/dist/src/tweaker/TweakerPriority.mjs +9 -0
- package/dist/src/tweaker/core.mjs +38 -0
- package/dist/src/tweaker/registerDefaultTweakers.mjs +17 -0
- package/dist/src/tweaker/tweak.mjs +109 -0
- package/dist/src/tweaker/tweakArray.mjs +272 -0
- package/dist/src/tweaker/tweakFrozen.mjs +28 -0
- package/dist/src/tweaker/tweakModel.mjs +26 -0
- package/dist/src/tweaker/tweakPlainObject.mjs +205 -0
- package/dist/src/tweaker/typeChecking.mjs +46 -0
- package/dist/src/tweaker/withoutTypeChecking.mjs +15 -0
- package/dist/src/types/TypeCheckError.mjs +31 -0
- package/dist/src/types/TypeChecker.mjs +165 -0
- package/dist/src/types/arrayBased/array.mjs +68 -0
- package/dist/src/types/arrayBased/tuple.mjs +71 -0
- package/dist/src/types/getTypeInfo.mjs +12 -0
- package/dist/src/types/objectBased/arraySet.mjs +83 -0
- package/dist/src/types/objectBased/dataModelData.mjs +95 -0
- package/dist/src/types/objectBased/model.mjs +133 -0
- package/dist/src/types/objectBased/object.mjs +119 -0
- package/dist/src/types/objectBased/objectMap.mjs +90 -0
- package/dist/src/types/objectBased/record.mjs +80 -0
- package/dist/src/types/objectBased/ref.mjs +62 -0
- package/dist/src/types/primitiveBased/enum.mjs +20 -0
- package/dist/src/types/primitiveBased/primitives.mjs +59 -0
- package/dist/src/types/primitiveBased/refinedPrimitives.mjs +6 -0
- package/dist/src/types/registerDefaultStandardTypeResolvers.mjs +13 -0
- package/dist/src/types/resolveTypeChecker.mjs +52 -0
- package/dist/src/types/tProp.mjs +53 -0
- package/dist/src/types/typeCheck.mjs +11 -0
- package/dist/src/types/types.mjs +69 -0
- package/dist/src/types/utility/maybe.mjs +10 -0
- package/dist/src/types/utility/or.mjs +99 -0
- package/dist/src/types/utility/refinement.mjs +52 -0
- package/dist/src/types/utility/unchecked.mjs +10 -0
- package/dist/src/utils/ModelPool.mjs +50 -0
- package/dist/src/utils/chainFns.mjs +15 -0
- package/dist/src/utils/index.mjs +228 -0
- package/dist/src/utils/mapUtils.mjs +10 -0
- package/dist/src/utils/tag.mjs +16 -0
- package/dist/src/wrappers/ArraySet.mjs +85 -0
- package/dist/src/wrappers/ObjectMap.mjs +96 -0
- package/dist/src/wrappers/asMap.mjs +181 -0
- package/dist/src/wrappers/asSet.mjs +97 -0
- package/dist/tweaker/index.d.ts +0 -4
- package/dist/tweaker/registerDefaultTweakers.d.ts +1 -0
- package/dist/types/registerDefaultStandardTypeResolvers.d.ts +1 -0
- package/package.json +12 -14
- package/src/actionMiddlewares/actionSerialization/actionSerialization.ts +24 -9
- package/src/dataModel/BaseDataModel.ts +0 -3
- package/src/dataModel/utils.ts +4 -4
- package/src/dist/action/actionDecoratorUtils.d.ts +5 -0
- package/src/dist/action/applyAction.d.ts +36 -0
- package/src/dist/action/applyDelete.d.ts +7 -0
- package/src/dist/action/applyMethodCall.d.ts +9 -0
- package/src/dist/action/applySet.d.ts +8 -0
- package/src/dist/action/builtInActions.d.ts +39 -0
- package/src/dist/action/context.d.ts +85 -0
- package/src/dist/action/hookActions.d.ts +32 -0
- package/src/dist/action/index.d.ts +12 -0
- package/src/dist/action/isModelAction.d.ts +7 -0
- package/src/dist/action/middleware.d.ts +34 -0
- package/src/dist/action/modelAction.d.ts +9 -0
- package/src/dist/action/modelFlow.d.ts +34 -0
- package/src/dist/action/pendingActions.d.ts +1 -0
- package/src/dist/action/protection.d.ts +1 -0
- package/src/dist/action/runUnprotected.d.ts +19 -0
- package/src/dist/action/wrapInAction.d.ts +1 -0
- package/src/dist/actionMiddlewares/actionSerialization/actionSerialization.d.ts +84 -0
- package/src/dist/actionMiddlewares/actionSerialization/applySerializedAction.d.ts +45 -0
- package/src/dist/actionMiddlewares/actionSerialization/arraySerializer.d.ts +3 -0
- package/src/dist/actionMiddlewares/actionSerialization/core.d.ts +28 -0
- package/src/dist/actionMiddlewares/actionSerialization/dateSerializer.d.ts +2 -0
- package/src/dist/actionMiddlewares/actionSerialization/index.d.ts +3 -0
- package/src/dist/actionMiddlewares/actionSerialization/mapSerializer.d.ts +6 -0
- package/src/dist/actionMiddlewares/actionSerialization/objectPathSerializer.d.ts +8 -0
- package/src/dist/actionMiddlewares/actionSerialization/objectSnapshotSerializer.d.ts +2 -0
- package/src/dist/actionMiddlewares/actionSerialization/plainObjectSerializer.d.ts +2 -0
- package/src/dist/actionMiddlewares/actionSerialization/primitiveSerializer.d.ts +2 -0
- package/src/dist/actionMiddlewares/actionSerialization/setSerializer.d.ts +3 -0
- package/src/dist/actionMiddlewares/actionTrackingMiddleware.d.ts +122 -0
- package/src/dist/actionMiddlewares/index.d.ts +6 -0
- package/src/dist/actionMiddlewares/onActionMiddleware.d.ts +26 -0
- package/src/dist/actionMiddlewares/readonlyMiddleware.d.ts +35 -0
- package/src/dist/actionMiddlewares/transactionMiddleware.d.ts +21 -0
- package/src/dist/actionMiddlewares/undoMiddleware.d.ts +283 -0
- package/src/dist/actionMiddlewares/utils.d.ts +1 -0
- package/src/dist/computedTree/computedTree.d.ts +16 -0
- package/src/dist/computedTree/index.d.ts +1 -0
- package/src/dist/context/context.d.ts +84 -0
- package/src/dist/context/index.d.ts +1 -0
- package/src/dist/dataModel/BaseDataModel.d.ts +52 -0
- package/src/dist/dataModel/DataModel.d.ts +47 -0
- package/src/dist/dataModel/DataModelConstructorOptions.d.ts +1 -0
- package/src/dist/dataModel/actions.d.ts +1 -0
- package/src/dist/dataModel/getDataModelMetadata.d.ts +19 -0
- package/src/dist/dataModel/index.d.ts +4 -0
- package/src/dist/dataModel/newDataModel.d.ts +1 -0
- package/src/dist/dataModel/utils.d.ts +8 -0
- package/src/dist/frozen/Frozen.d.ts +50 -0
- package/src/dist/frozen/index.d.ts +1 -0
- package/src/dist/globalConfig/globalConfig.d.ts +51 -0
- package/src/dist/globalConfig/index.d.ts +1 -0
- package/src/dist/index.d.ts +23 -0
- package/src/dist/mobx-keystone.umd.js +8201 -0
- package/src/dist/model/BaseModel.d.ts +125 -0
- package/src/dist/model/Model.d.ts +94 -0
- package/src/dist/model/ModelConstructorOptions.d.ts +1 -0
- package/src/dist/model/getModelMetadata.d.ts +27 -0
- package/src/dist/model/index.d.ts +5 -0
- package/src/dist/model/metadata.d.ts +8 -0
- package/src/dist/model/newModel.d.ts +1 -0
- package/src/dist/model/utils.d.ts +8 -0
- package/src/dist/modelShared/BaseModelShared.d.ts +76 -0
- package/src/dist/modelShared/Model.d.ts +15 -0
- package/src/dist/modelShared/checkModelDecoratorArgs.d.ts +1 -0
- package/src/dist/modelShared/index.d.ts +3 -0
- package/src/dist/modelShared/modelClassInitializer.d.ts +1 -0
- package/src/dist/modelShared/modelDecorator.d.ts +24 -0
- package/src/dist/modelShared/modelInfo.d.ts +1 -0
- package/src/dist/modelShared/modelPropsInfo.d.ts +1 -0
- package/src/dist/modelShared/modelSymbols.d.ts +3 -0
- package/src/dist/modelShared/newModel.d.ts +4 -0
- package/src/dist/modelShared/prop.d.ts +179 -0
- package/src/dist/modelShared/utils.d.ts +1 -0
- package/src/dist/parent/core.d.ts +1 -0
- package/src/dist/parent/coreObjectChildren.d.ts +1 -0
- package/src/dist/parent/detach.d.ts +9 -0
- package/src/dist/parent/findChildren.d.ts +13 -0
- package/src/dist/parent/findParent.d.ts +41 -0
- package/src/dist/parent/getChildrenObjects.d.ts +11 -0
- package/src/dist/parent/index.d.ts +9 -0
- package/src/dist/parent/onChildAttachedTo.d.ts +22 -0
- package/src/dist/parent/path.d.ts +107 -0
- package/src/dist/parent/path2.d.ts +16 -0
- package/src/dist/parent/pathTypes.d.ts +12 -0
- package/src/dist/parent/setParent.d.ts +1 -0
- package/src/dist/parent/walkTree.d.ts +25 -0
- package/src/dist/patch/Patch.d.ts +16 -0
- package/src/dist/patch/applyPatches.d.ts +9 -0
- package/src/dist/patch/emitPatch.d.ts +29 -0
- package/src/dist/patch/index.d.ts +5 -0
- package/src/dist/patch/jsonPatch.d.ts +45 -0
- package/src/dist/patch/patchRecorder.d.ts +70 -0
- package/src/dist/redux/connectReduxDevTools.d.ts +12 -0
- package/src/dist/redux/index.d.ts +2 -0
- package/src/dist/redux/redux.d.ts +47 -0
- package/src/dist/ref/Ref.d.ts +53 -0
- package/src/dist/ref/core.d.ts +46 -0
- package/src/dist/ref/customRef.d.ts +38 -0
- package/src/dist/ref/index.d.ts +4 -0
- package/src/dist/ref/rootRef.d.ts +33 -0
- package/src/dist/rootStore/attachDetach.d.ts +1 -0
- package/src/dist/rootStore/index.d.ts +1 -0
- package/src/dist/rootStore/rootStore.d.ts +33 -0
- package/src/dist/snapshot/SnapshotOf.d.ts +47 -0
- package/src/dist/snapshot/SnapshotterAndReconcilerPriority.d.ts +1 -0
- package/src/dist/snapshot/applySnapshot.d.ts +17 -0
- package/src/dist/snapshot/clone.d.ts +18 -0
- package/src/dist/snapshot/fromArraySnapshot.d.ts +1 -0
- package/src/dist/snapshot/fromFrozenSnapshot.d.ts +1 -0
- package/src/dist/snapshot/fromModelSnapshot.d.ts +1 -0
- package/src/dist/snapshot/fromPlainObjectSnapshot.d.ts +1 -0
- package/src/dist/snapshot/fromSnapshot.d.ts +36 -0
- package/src/dist/snapshot/getSnapshot.d.ts +22 -0
- package/src/dist/snapshot/index.d.ts +6 -0
- package/src/dist/snapshot/internal.d.ts +1 -0
- package/src/dist/snapshot/onSnapshot.d.ts +18 -0
- package/src/dist/snapshot/reconcileArraySnapshot.d.ts +1 -0
- package/src/dist/snapshot/reconcileFrozenSnapshot.d.ts +1 -0
- package/src/dist/snapshot/reconcileModelSnapshot.d.ts +1 -0
- package/src/dist/snapshot/reconcilePlainObjectSnapshot.d.ts +1 -0
- package/src/dist/snapshot/reconcileSnapshot.d.ts +1 -0
- package/src/dist/snapshot/registerDefaultReconcilers.d.ts +1 -0
- package/src/dist/snapshot/registerDefaultSnapshotters.d.ts +1 -0
- package/src/dist/standardActions/actions.d.ts +1 -0
- package/src/dist/standardActions/arrayActions.d.ts +18 -0
- package/src/dist/standardActions/index.d.ts +3 -0
- package/src/dist/standardActions/objectActions.d.ts +7 -0
- package/src/dist/standardActions/standaloneActions.d.ts +16 -0
- package/src/dist/transforms/ImmutableDate.d.ts +1 -0
- package/src/dist/transforms/asMap.d.ts +3 -0
- package/src/dist/transforms/asSet.d.ts +2 -0
- package/src/dist/transforms/bigint.d.ts +2 -0
- package/src/dist/transforms/date.d.ts +3 -0
- package/src/dist/transforms/index.d.ts +4 -0
- package/src/dist/treeUtils/deepEquals.d.ts +20 -0
- package/src/dist/treeUtils/draft.d.ts +70 -0
- package/src/dist/treeUtils/index.d.ts +3 -0
- package/src/dist/treeUtils/sandbox.d.ts +85 -0
- package/src/dist/tweaker/TweakerPriority.d.ts +1 -0
- package/src/dist/tweaker/core.d.ts +14 -0
- package/src/dist/tweaker/index.d.ts +2 -0
- package/src/dist/tweaker/registerDefaultTweakers.d.ts +1 -0
- package/src/dist/tweaker/tweak.d.ts +22 -0
- package/src/dist/tweaker/tweakArray.d.ts +1 -0
- package/src/dist/tweaker/tweakFrozen.d.ts +1 -0
- package/src/dist/tweaker/tweakModel.d.ts +1 -0
- package/src/dist/tweaker/tweakPlainObject.d.ts +1 -0
- package/src/dist/tweaker/typeChecking.d.ts +1 -0
- package/src/dist/tweaker/withoutTypeChecking.d.ts +2 -0
- package/src/dist/types/TypeCheckError.d.ts +22 -0
- package/src/dist/types/TypeChecker.d.ts +8 -0
- package/src/dist/types/arrayBased/array.d.ts +23 -0
- package/src/dist/types/arrayBased/tuple.d.ts +24 -0
- package/src/dist/types/getTypeInfo.d.ts +9 -0
- package/src/dist/types/index.d.ts +5 -0
- package/src/dist/types/objectBased/arraySet.d.ts +24 -0
- package/src/dist/types/objectBased/dataModelData.d.ts +44 -0
- package/src/dist/types/objectBased/model.d.ts +43 -0
- package/src/dist/types/objectBased/object.d.ts +63 -0
- package/src/dist/types/objectBased/objectMap.d.ts +24 -0
- package/src/dist/types/objectBased/record.d.ts +24 -0
- package/src/dist/types/objectBased/ref.d.ts +21 -0
- package/src/dist/types/primitiveBased/enum.d.ts +34 -0
- package/src/dist/types/primitiveBased/primitives.d.ts +81 -0
- package/src/dist/types/primitiveBased/refinedPrimitives.d.ts +18 -0
- package/src/dist/types/registerDefaultStandardTypeResolvers.d.ts +1 -0
- package/src/dist/types/resolveTypeChecker.d.ts +1 -0
- package/src/dist/types/schemas.d.ts +53 -0
- package/src/dist/types/tProp.d.ts +92 -0
- package/src/dist/types/typeCheck.d.ts +11 -0
- package/src/dist/types/types.d.ts +51 -0
- package/src/dist/types/utility/maybe.d.ts +29 -0
- package/src/dist/types/utility/or.d.ts +35 -0
- package/src/dist/types/utility/refinement.d.ts +45 -0
- package/src/dist/types/utility/unchecked.d.ts +22 -0
- package/src/dist/utils/ModelPool.d.ts +7 -0
- package/src/dist/utils/chainFns.d.ts +1 -0
- package/src/dist/utils/index.d.ts +6 -0
- package/src/dist/utils/mapUtils.d.ts +2 -0
- package/src/dist/utils/tag.d.ts +13 -0
- package/src/dist/utils/types.d.ts +39 -0
- package/src/dist/wrappers/ArraySet.d.ts +29 -0
- package/src/dist/wrappers/ObjectMap.d.ts +32 -0
- package/src/dist/wrappers/asMap.d.ts +29 -0
- package/src/dist/wrappers/asSet.d.ts +15 -0
- package/src/dist/wrappers/index.d.ts +4 -0
- package/src/model/BaseModel.ts +0 -3
- package/src/model/utils.ts +4 -5
- package/src/modelShared/checkModelDecoratorArgs.ts +6 -6
- package/src/parent/setParent.ts +2 -2
- package/src/rootStore/attachDetach.ts +2 -3
- package/src/snapshot/fromArraySnapshot.ts +11 -6
- package/src/snapshot/fromFrozenSnapshot.ts +11 -6
- package/src/snapshot/fromModelSnapshot.ts +11 -6
- package/src/snapshot/fromPlainObjectSnapshot.ts +11 -6
- package/src/snapshot/fromSnapshot.ts +3 -0
- package/src/snapshot/index.ts +0 -10
- package/src/snapshot/reconcileArraySnapshot.ts +11 -6
- package/src/snapshot/reconcileFrozenSnapshot.ts +11 -6
- package/src/snapshot/reconcileModelSnapshot.ts +11 -6
- package/src/snapshot/reconcilePlainObjectSnapshot.ts +11 -6
- package/src/snapshot/reconcileSnapshot.ts +3 -0
- package/src/snapshot/registerDefaultReconcilers.ts +21 -0
- package/src/snapshot/registerDefaultSnapshotters.ts +21 -0
- package/src/tweaker/index.ts +0 -6
- package/src/tweaker/registerDefaultTweakers.ts +21 -0
- package/src/tweaker/tweak.ts +3 -0
- package/src/tweaker/tweakArray.ts +406 -401
- package/src/tweaker/tweakFrozen.ts +11 -6
- package/src/tweaker/tweakModel.ts +11 -6
- package/src/tweaker/tweakPlainObject.ts +288 -283
- package/src/types/objectBased/model.ts +6 -1
- package/src/types/objectBased/ref.ts +1 -1
- package/src/types/primitiveBased/primitives.ts +177 -166
- package/src/types/registerDefaultStandardTypeResolvers.ts +17 -0
- package/src/types/resolveTypeChecker.ts +7 -1
- package/dist/mobx-keystone.es.js +0 -7856
- package/dist/mobx-keystone.es.mjs +0 -7856
- package/src/dataModel/_BaseDataModel.ts +0 -15
- package/src/model/_BaseModel.ts +0 -15
|
@@ -29,9 +29,14 @@ export function tweakFrozen<T extends Frozen<any>>(
|
|
|
29
29
|
return frozenObj
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export function registerFrozenTweaker() {
|
|
36
|
+
registerTweaker(TweakerPriority.Frozen, (value, parentPath) => {
|
|
37
|
+
if (value instanceof Frozen) {
|
|
38
|
+
return tweakFrozen(value, parentPath)
|
|
39
|
+
}
|
|
40
|
+
return undefined
|
|
41
|
+
})
|
|
42
|
+
}
|
|
@@ -24,9 +24,14 @@ export function tweakModel<T extends object>(value: T, parentPath: ParentPath<an
|
|
|
24
24
|
return value
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export function registerModelTweaker() {
|
|
31
|
+
registerTweaker(TweakerPriority.Model, (value, parentPath) => {
|
|
32
|
+
if (isModel(value)) {
|
|
33
|
+
return tweakModel(value, parentPath)
|
|
34
|
+
}
|
|
35
|
+
return undefined
|
|
36
|
+
})
|
|
37
|
+
}
|
|
@@ -1,283 +1,288 @@
|
|
|
1
|
-
import {
|
|
2
|
-
intercept,
|
|
3
|
-
IObjectDidChange,
|
|
4
|
-
IObjectWillChange,
|
|
5
|
-
isObservableObject,
|
|
6
|
-
observable,
|
|
7
|
-
observe,
|
|
8
|
-
set,
|
|
9
|
-
} from "mobx"
|
|
10
|
-
import { assertCanWrite } from "../action/protection"
|
|
11
|
-
import type { AnyModel } from "../model/BaseModel"
|
|
12
|
-
import { modelTypeKey } from "../model/metadata"
|
|
13
|
-
import type { ModelClass } from "../modelShared/BaseModelShared"
|
|
14
|
-
import { getModelInfoForName } from "../modelShared/modelInfo"
|
|
15
|
-
import { dataToModelNode } from "../parent/core"
|
|
16
|
-
import type { ParentPath } from "../parent/path"
|
|
17
|
-
import { setParent } from "../parent/setParent"
|
|
18
|
-
import { InternalPatchRecorder } from "../patch/emitPatch"
|
|
19
|
-
import {
|
|
20
|
-
freezeInternalSnapshot,
|
|
21
|
-
getInternalSnapshot,
|
|
22
|
-
setNewInternalSnapshot,
|
|
23
|
-
SnapshotTransformFn,
|
|
24
|
-
updateInternalSnapshot,
|
|
25
|
-
} from "../snapshot/internal"
|
|
26
|
-
import { failure, isPlainObject, isPrimitive } from "../utils"
|
|
27
|
-
import { runningWithoutSnapshotOrPatches, tweakedObjects } from "./core"
|
|
28
|
-
import { registerTweaker, tryUntweak, tweak } from "./tweak"
|
|
29
|
-
import { TweakerPriority } from "./TweakerPriority"
|
|
30
|
-
import { runTypeCheckingAfterChange } from "./typeChecking"
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
export function tweakPlainObject<T extends Record<string, any>>(
|
|
36
|
-
value: T,
|
|
37
|
-
parentPath: ParentPath<any> | undefined,
|
|
38
|
-
snapshotModelType: string | undefined,
|
|
39
|
-
doNotTweakChildren: boolean,
|
|
40
|
-
isDataObject: boolean
|
|
41
|
-
): T {
|
|
42
|
-
const originalObj: Record<string, any> = value
|
|
43
|
-
const tweakedObj = isObservableObject(originalObj)
|
|
44
|
-
? originalObj
|
|
45
|
-
: observable.object({}, undefined, observableOptions)
|
|
46
|
-
|
|
47
|
-
let interceptDisposer: () => void
|
|
48
|
-
let observeDisposer: () => void
|
|
49
|
-
|
|
50
|
-
const untweak = () => {
|
|
51
|
-
interceptDisposer()
|
|
52
|
-
observeDisposer()
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
tweakedObjects.set(tweakedObj, untweak)
|
|
56
|
-
setParent({
|
|
57
|
-
value: tweakedObj,
|
|
58
|
-
parentPath,
|
|
59
|
-
indexChangeAllowed: false,
|
|
60
|
-
isDataObject,
|
|
61
|
-
// an object shouldn't be cloned
|
|
62
|
-
cloneIfApplicable: false,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
let untransformedSn: any = {}
|
|
66
|
-
|
|
67
|
-
// substitute initial values by tweaked values
|
|
68
|
-
const originalObjKeys = Object.keys(originalObj)
|
|
69
|
-
const originalObjKeysLen = originalObjKeys.length
|
|
70
|
-
for (let i = 0; i < originalObjKeysLen; i++) {
|
|
71
|
-
const k = originalObjKeys[i]
|
|
72
|
-
const v = originalObj[k]
|
|
73
|
-
|
|
74
|
-
if (isPrimitive(v)) {
|
|
75
|
-
if (!doNotTweakChildren) {
|
|
76
|
-
set(tweakedObj, k, v)
|
|
77
|
-
}
|
|
78
|
-
untransformedSn[k] = v
|
|
79
|
-
} else {
|
|
80
|
-
const path = { parent: tweakedObj, path: k }
|
|
81
|
-
|
|
82
|
-
let tweakedValue
|
|
83
|
-
if (doNotTweakChildren) {
|
|
84
|
-
tweakedValue = v
|
|
85
|
-
setParent({
|
|
86
|
-
value: tweakedValue,
|
|
87
|
-
parentPath: path,
|
|
88
|
-
indexChangeAllowed: false,
|
|
89
|
-
isDataObject: false,
|
|
90
|
-
// the value is already a new value (the result of a fromSnapshot)
|
|
91
|
-
cloneIfApplicable: false,
|
|
92
|
-
})
|
|
93
|
-
} else {
|
|
94
|
-
tweakedValue = tweak(v, path)
|
|
95
|
-
set(tweakedObj, k, tweakedValue)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const valueSn = getInternalSnapshot(tweakedValue)!
|
|
99
|
-
untransformedSn[k] = valueSn.transformed
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
let transformFn: SnapshotTransformFn | undefined
|
|
104
|
-
if (snapshotModelType) {
|
|
105
|
-
untransformedSn[modelTypeKey] = snapshotModelType
|
|
106
|
-
|
|
107
|
-
const modelInfo = getModelInfoForName(snapshotModelType)
|
|
108
|
-
if (!modelInfo) {
|
|
109
|
-
throw failure(`model with name "${snapshotModelType}" not found in the registry`)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const originalTransformFn = (modelInfo.class as ModelClass<AnyModel>).toSnapshotProcessor
|
|
113
|
-
if (originalTransformFn) {
|
|
114
|
-
transformFn = (sn) => originalTransformFn(sn, dataToModelNode(tweakedObj))
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
setNewInternalSnapshot(
|
|
119
|
-
isDataObject ? dataToModelNode(tweakedObj) : tweakedObj,
|
|
120
|
-
untransformedSn,
|
|
121
|
-
transformFn
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
interceptDisposer = intercept(tweakedObj, interceptObjectMutation)
|
|
125
|
-
observeDisposer = observe(tweakedObj, objectDidChange)
|
|
126
|
-
|
|
127
|
-
return tweakedObj as any
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const observableOptions = {
|
|
131
|
-
deep: false,
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function objectDidChange(change: IObjectDidChange): void {
|
|
135
|
-
const obj = change.object
|
|
136
|
-
const actualNode = dataToModelNode(obj)
|
|
137
|
-
let { untransformed: oldUntransformedSn } = getInternalSnapshot(actualNode)!
|
|
138
|
-
|
|
139
|
-
const patchRecorder = new InternalPatchRecorder()
|
|
140
|
-
|
|
141
|
-
let mutate: ((sn: any) => void) | undefined
|
|
142
|
-
|
|
143
|
-
switch (change.type) {
|
|
144
|
-
case "add":
|
|
145
|
-
case "update":
|
|
146
|
-
{
|
|
147
|
-
const k = change.name
|
|
148
|
-
const val = change.newValue
|
|
149
|
-
|
|
150
|
-
const oldVal = oldUntransformedSn[k]
|
|
151
|
-
|
|
152
|
-
let newVal: any
|
|
153
|
-
if (isPrimitive(val)) {
|
|
154
|
-
newVal = val
|
|
155
|
-
} else {
|
|
156
|
-
const valueSn = getInternalSnapshot(val)!
|
|
157
|
-
newVal = valueSn.transformed
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
mutate = (sn) => {
|
|
161
|
-
sn[k] = newVal
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const path = [k as string]
|
|
165
|
-
if (change.type === "add") {
|
|
166
|
-
patchRecorder.record(
|
|
167
|
-
[
|
|
168
|
-
{
|
|
169
|
-
op: "add",
|
|
170
|
-
path,
|
|
171
|
-
value: freezeInternalSnapshot(newVal),
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
[
|
|
175
|
-
{
|
|
176
|
-
op: "remove",
|
|
177
|
-
path,
|
|
178
|
-
},
|
|
179
|
-
]
|
|
180
|
-
)
|
|
181
|
-
} else {
|
|
182
|
-
patchRecorder.record(
|
|
183
|
-
[
|
|
184
|
-
{
|
|
185
|
-
op: "replace",
|
|
186
|
-
path,
|
|
187
|
-
value: freezeInternalSnapshot(newVal),
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
[
|
|
191
|
-
{
|
|
192
|
-
op: "replace",
|
|
193
|
-
path,
|
|
194
|
-
value: freezeInternalSnapshot(oldVal),
|
|
195
|
-
},
|
|
196
|
-
]
|
|
197
|
-
)
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
break
|
|
201
|
-
|
|
202
|
-
case "remove":
|
|
203
|
-
{
|
|
204
|
-
const k = change.name
|
|
205
|
-
const oldVal = oldUntransformedSn[k]
|
|
206
|
-
mutate = (sn) => {
|
|
207
|
-
delete sn[k]
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const path = [k as string]
|
|
211
|
-
|
|
212
|
-
patchRecorder.record(
|
|
213
|
-
[
|
|
214
|
-
{
|
|
215
|
-
op: "remove",
|
|
216
|
-
path,
|
|
217
|
-
},
|
|
218
|
-
],
|
|
219
|
-
[
|
|
220
|
-
{
|
|
221
|
-
op: "add",
|
|
222
|
-
path,
|
|
223
|
-
value: freezeInternalSnapshot(oldVal),
|
|
224
|
-
},
|
|
225
|
-
]
|
|
226
|
-
)
|
|
227
|
-
}
|
|
228
|
-
break
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
runTypeCheckingAfterChange(obj, patchRecorder)
|
|
232
|
-
|
|
233
|
-
if (!runningWithoutSnapshotOrPatches && mutate!) {
|
|
234
|
-
updateInternalSnapshot(actualNode, mutate)
|
|
235
|
-
patchRecorder.emit(actualNode)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function interceptObjectMutation(change: IObjectWillChange) {
|
|
240
|
-
assertCanWrite()
|
|
241
|
-
|
|
242
|
-
if (typeof change.name === "symbol") {
|
|
243
|
-
throw failure("symbol properties are not supported")
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
switch (change.type) {
|
|
247
|
-
case "add":
|
|
248
|
-
change.newValue = tweak(change.newValue, {
|
|
249
|
-
parent: change.object,
|
|
250
|
-
path: "" + change.name,
|
|
251
|
-
})
|
|
252
|
-
break
|
|
253
|
-
|
|
254
|
-
case "remove": {
|
|
255
|
-
const oldVal = change.object[change.name]
|
|
256
|
-
tweak(oldVal, undefined)
|
|
257
|
-
tryUntweak(oldVal)
|
|
258
|
-
break
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
case "update": {
|
|
262
|
-
const oldVal = change.object[change.name]
|
|
263
|
-
tweak(oldVal, undefined)
|
|
264
|
-
tryUntweak(oldVal)
|
|
265
|
-
|
|
266
|
-
change.newValue = tweak(change.newValue, {
|
|
267
|
-
parent: change.object,
|
|
268
|
-
path: "" + change.name,
|
|
269
|
-
})
|
|
270
|
-
break
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return change
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
1
|
+
import {
|
|
2
|
+
intercept,
|
|
3
|
+
IObjectDidChange,
|
|
4
|
+
IObjectWillChange,
|
|
5
|
+
isObservableObject,
|
|
6
|
+
observable,
|
|
7
|
+
observe,
|
|
8
|
+
set,
|
|
9
|
+
} from "mobx"
|
|
10
|
+
import { assertCanWrite } from "../action/protection"
|
|
11
|
+
import type { AnyModel } from "../model/BaseModel"
|
|
12
|
+
import { modelTypeKey } from "../model/metadata"
|
|
13
|
+
import type { ModelClass } from "../modelShared/BaseModelShared"
|
|
14
|
+
import { getModelInfoForName } from "../modelShared/modelInfo"
|
|
15
|
+
import { dataToModelNode } from "../parent/core"
|
|
16
|
+
import type { ParentPath } from "../parent/path"
|
|
17
|
+
import { setParent } from "../parent/setParent"
|
|
18
|
+
import { InternalPatchRecorder } from "../patch/emitPatch"
|
|
19
|
+
import {
|
|
20
|
+
freezeInternalSnapshot,
|
|
21
|
+
getInternalSnapshot,
|
|
22
|
+
setNewInternalSnapshot,
|
|
23
|
+
SnapshotTransformFn,
|
|
24
|
+
updateInternalSnapshot,
|
|
25
|
+
} from "../snapshot/internal"
|
|
26
|
+
import { failure, isPlainObject, isPrimitive } from "../utils"
|
|
27
|
+
import { runningWithoutSnapshotOrPatches, tweakedObjects } from "./core"
|
|
28
|
+
import { registerTweaker, tryUntweak, tweak } from "./tweak"
|
|
29
|
+
import { TweakerPriority } from "./TweakerPriority"
|
|
30
|
+
import { runTypeCheckingAfterChange } from "./typeChecking"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export function tweakPlainObject<T extends Record<string, any>>(
|
|
36
|
+
value: T,
|
|
37
|
+
parentPath: ParentPath<any> | undefined,
|
|
38
|
+
snapshotModelType: string | undefined,
|
|
39
|
+
doNotTweakChildren: boolean,
|
|
40
|
+
isDataObject: boolean
|
|
41
|
+
): T {
|
|
42
|
+
const originalObj: Record<string, any> = value
|
|
43
|
+
const tweakedObj = isObservableObject(originalObj)
|
|
44
|
+
? originalObj
|
|
45
|
+
: observable.object({}, undefined, observableOptions)
|
|
46
|
+
|
|
47
|
+
let interceptDisposer: () => void
|
|
48
|
+
let observeDisposer: () => void
|
|
49
|
+
|
|
50
|
+
const untweak = () => {
|
|
51
|
+
interceptDisposer()
|
|
52
|
+
observeDisposer()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
tweakedObjects.set(tweakedObj, untweak)
|
|
56
|
+
setParent({
|
|
57
|
+
value: tweakedObj,
|
|
58
|
+
parentPath,
|
|
59
|
+
indexChangeAllowed: false,
|
|
60
|
+
isDataObject,
|
|
61
|
+
// an object shouldn't be cloned
|
|
62
|
+
cloneIfApplicable: false,
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
let untransformedSn: any = {}
|
|
66
|
+
|
|
67
|
+
// substitute initial values by tweaked values
|
|
68
|
+
const originalObjKeys = Object.keys(originalObj)
|
|
69
|
+
const originalObjKeysLen = originalObjKeys.length
|
|
70
|
+
for (let i = 0; i < originalObjKeysLen; i++) {
|
|
71
|
+
const k = originalObjKeys[i]
|
|
72
|
+
const v = originalObj[k]
|
|
73
|
+
|
|
74
|
+
if (isPrimitive(v)) {
|
|
75
|
+
if (!doNotTweakChildren) {
|
|
76
|
+
set(tweakedObj, k, v)
|
|
77
|
+
}
|
|
78
|
+
untransformedSn[k] = v
|
|
79
|
+
} else {
|
|
80
|
+
const path = { parent: tweakedObj, path: k }
|
|
81
|
+
|
|
82
|
+
let tweakedValue
|
|
83
|
+
if (doNotTweakChildren) {
|
|
84
|
+
tweakedValue = v
|
|
85
|
+
setParent({
|
|
86
|
+
value: tweakedValue,
|
|
87
|
+
parentPath: path,
|
|
88
|
+
indexChangeAllowed: false,
|
|
89
|
+
isDataObject: false,
|
|
90
|
+
// the value is already a new value (the result of a fromSnapshot)
|
|
91
|
+
cloneIfApplicable: false,
|
|
92
|
+
})
|
|
93
|
+
} else {
|
|
94
|
+
tweakedValue = tweak(v, path)
|
|
95
|
+
set(tweakedObj, k, tweakedValue)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const valueSn = getInternalSnapshot(tweakedValue)!
|
|
99
|
+
untransformedSn[k] = valueSn.transformed
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let transformFn: SnapshotTransformFn | undefined
|
|
104
|
+
if (snapshotModelType) {
|
|
105
|
+
untransformedSn[modelTypeKey] = snapshotModelType
|
|
106
|
+
|
|
107
|
+
const modelInfo = getModelInfoForName(snapshotModelType)
|
|
108
|
+
if (!modelInfo) {
|
|
109
|
+
throw failure(`model with name "${snapshotModelType}" not found in the registry`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const originalTransformFn = (modelInfo.class as ModelClass<AnyModel>).toSnapshotProcessor
|
|
113
|
+
if (originalTransformFn) {
|
|
114
|
+
transformFn = (sn) => originalTransformFn(sn, dataToModelNode(tweakedObj))
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setNewInternalSnapshot(
|
|
119
|
+
isDataObject ? dataToModelNode(tweakedObj) : tweakedObj,
|
|
120
|
+
untransformedSn,
|
|
121
|
+
transformFn
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
interceptDisposer = intercept(tweakedObj, interceptObjectMutation)
|
|
125
|
+
observeDisposer = observe(tweakedObj, objectDidChange)
|
|
126
|
+
|
|
127
|
+
return tweakedObj as any
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const observableOptions = {
|
|
131
|
+
deep: false,
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function objectDidChange(change: IObjectDidChange): void {
|
|
135
|
+
const obj = change.object
|
|
136
|
+
const actualNode = dataToModelNode(obj)
|
|
137
|
+
let { untransformed: oldUntransformedSn } = getInternalSnapshot(actualNode)!
|
|
138
|
+
|
|
139
|
+
const patchRecorder = new InternalPatchRecorder()
|
|
140
|
+
|
|
141
|
+
let mutate: ((sn: any) => void) | undefined
|
|
142
|
+
|
|
143
|
+
switch (change.type) {
|
|
144
|
+
case "add":
|
|
145
|
+
case "update":
|
|
146
|
+
{
|
|
147
|
+
const k = change.name
|
|
148
|
+
const val = change.newValue
|
|
149
|
+
|
|
150
|
+
const oldVal = oldUntransformedSn[k]
|
|
151
|
+
|
|
152
|
+
let newVal: any
|
|
153
|
+
if (isPrimitive(val)) {
|
|
154
|
+
newVal = val
|
|
155
|
+
} else {
|
|
156
|
+
const valueSn = getInternalSnapshot(val)!
|
|
157
|
+
newVal = valueSn.transformed
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
mutate = (sn) => {
|
|
161
|
+
sn[k] = newVal
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const path = [k as string]
|
|
165
|
+
if (change.type === "add") {
|
|
166
|
+
patchRecorder.record(
|
|
167
|
+
[
|
|
168
|
+
{
|
|
169
|
+
op: "add",
|
|
170
|
+
path,
|
|
171
|
+
value: freezeInternalSnapshot(newVal),
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
[
|
|
175
|
+
{
|
|
176
|
+
op: "remove",
|
|
177
|
+
path,
|
|
178
|
+
},
|
|
179
|
+
]
|
|
180
|
+
)
|
|
181
|
+
} else {
|
|
182
|
+
patchRecorder.record(
|
|
183
|
+
[
|
|
184
|
+
{
|
|
185
|
+
op: "replace",
|
|
186
|
+
path,
|
|
187
|
+
value: freezeInternalSnapshot(newVal),
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
{
|
|
192
|
+
op: "replace",
|
|
193
|
+
path,
|
|
194
|
+
value: freezeInternalSnapshot(oldVal),
|
|
195
|
+
},
|
|
196
|
+
]
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
break
|
|
201
|
+
|
|
202
|
+
case "remove":
|
|
203
|
+
{
|
|
204
|
+
const k = change.name
|
|
205
|
+
const oldVal = oldUntransformedSn[k]
|
|
206
|
+
mutate = (sn) => {
|
|
207
|
+
delete sn[k]
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const path = [k as string]
|
|
211
|
+
|
|
212
|
+
patchRecorder.record(
|
|
213
|
+
[
|
|
214
|
+
{
|
|
215
|
+
op: "remove",
|
|
216
|
+
path,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
[
|
|
220
|
+
{
|
|
221
|
+
op: "add",
|
|
222
|
+
path,
|
|
223
|
+
value: freezeInternalSnapshot(oldVal),
|
|
224
|
+
},
|
|
225
|
+
]
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
break
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
runTypeCheckingAfterChange(obj, patchRecorder)
|
|
232
|
+
|
|
233
|
+
if (!runningWithoutSnapshotOrPatches && mutate!) {
|
|
234
|
+
updateInternalSnapshot(actualNode, mutate)
|
|
235
|
+
patchRecorder.emit(actualNode)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function interceptObjectMutation(change: IObjectWillChange) {
|
|
240
|
+
assertCanWrite()
|
|
241
|
+
|
|
242
|
+
if (typeof change.name === "symbol") {
|
|
243
|
+
throw failure("symbol properties are not supported")
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
switch (change.type) {
|
|
247
|
+
case "add":
|
|
248
|
+
change.newValue = tweak(change.newValue, {
|
|
249
|
+
parent: change.object,
|
|
250
|
+
path: "" + change.name,
|
|
251
|
+
})
|
|
252
|
+
break
|
|
253
|
+
|
|
254
|
+
case "remove": {
|
|
255
|
+
const oldVal = change.object[change.name]
|
|
256
|
+
tweak(oldVal, undefined)
|
|
257
|
+
tryUntweak(oldVal)
|
|
258
|
+
break
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
case "update": {
|
|
262
|
+
const oldVal = change.object[change.name]
|
|
263
|
+
tweak(oldVal, undefined)
|
|
264
|
+
tryUntweak(oldVal)
|
|
265
|
+
|
|
266
|
+
change.newValue = tweak(change.newValue, {
|
|
267
|
+
parent: change.object,
|
|
268
|
+
path: "" + change.name,
|
|
269
|
+
})
|
|
270
|
+
break
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return change
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @internal
|
|
279
|
+
*/
|
|
280
|
+
export function registerPlainObjectTweaker() {
|
|
281
|
+
registerTweaker(TweakerPriority.PlainObject, (value, parentPath) => {
|
|
282
|
+
// plain object
|
|
283
|
+
if (isObservableObject(value) || isPlainObject(value)) {
|
|
284
|
+
return tweakPlainObject(value as Record<string, any>, parentPath, undefined, false, false)
|
|
285
|
+
}
|
|
286
|
+
return undefined
|
|
287
|
+
})
|
|
288
|
+
}
|
|
@@ -188,4 +188,9 @@ export class ModelTypeInfo extends TypeInfo {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
/**
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
export function registerModelStandardTypeResolver() {
|
|
195
|
+
registerStandardTypeResolver((v) => (isModelClass(v) ? typesModel(v) : undefined))
|
|
196
|
+
}
|
|
@@ -24,7 +24,7 @@ import { typesObject } from "./object"
|
|
|
24
24
|
export function typesRef<O extends object>(refConstructor: RefConstructor<O>): ModelType<Ref<O>> {
|
|
25
25
|
const typeName = "Ref"
|
|
26
26
|
|
|
27
|
-
const modelInfo = modelInfoByClass.get(refConstructor
|
|
27
|
+
const modelInfo = modelInfoByClass.get(refConstructor.refClass)!
|
|
28
28
|
|
|
29
29
|
const refDataTypeChecker = resolveTypeChecker(
|
|
30
30
|
typesObject(() => ({
|