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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare type AnyFunction = (...args: any[]) => any;
|
|
2
|
+
/**
|
|
3
|
+
* Calls an object method wrapped in an action.
|
|
4
|
+
*
|
|
5
|
+
* @param node Target object.
|
|
6
|
+
* @param methodName Method name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function applyMethodCall<O extends object, K extends keyof O, FN extends O[K]>(node: O, methodName: K, ...args: FN extends AnyFunction ? Parameters<FN> : never): FN extends AnyFunction ? ReturnType<FN> : never;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets an object field wrapped in an action.
|
|
3
|
+
*
|
|
4
|
+
* @param node Target object.
|
|
5
|
+
* @param fieldName Field name.
|
|
6
|
+
* @param value Value to set.
|
|
7
|
+
*/
|
|
8
|
+
export declare function applySet<O extends object, K extends keyof O, V extends O[K]>(node: O, fieldName: K, value: V): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A built-in action.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum BuiltInAction {
|
|
5
|
+
/**
|
|
6
|
+
* applyPatches
|
|
7
|
+
*/
|
|
8
|
+
ApplyPatches = "$$applyPatches",
|
|
9
|
+
/**
|
|
10
|
+
* applySnapshot
|
|
11
|
+
*/
|
|
12
|
+
ApplySnapshot = "$$applySnapshot",
|
|
13
|
+
/**
|
|
14
|
+
* detach
|
|
15
|
+
*/
|
|
16
|
+
Detach = "$$detach",
|
|
17
|
+
/**
|
|
18
|
+
* applySet
|
|
19
|
+
*/
|
|
20
|
+
ApplySet = "$$applySet",
|
|
21
|
+
/**
|
|
22
|
+
* applyDelete
|
|
23
|
+
*/
|
|
24
|
+
ApplyDelete = "$$applyDelete",
|
|
25
|
+
/**
|
|
26
|
+
* applyMethodCall
|
|
27
|
+
*/
|
|
28
|
+
ApplyMethodCall = "$$applyMethodCall"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns if a given action name is a built-in action, this is, one of:
|
|
32
|
+
* - applyPatches()
|
|
33
|
+
* - applySnapshot()
|
|
34
|
+
* - detach()
|
|
35
|
+
*
|
|
36
|
+
* @param actionName Action name to check.
|
|
37
|
+
* @returns true if it is a built-in action, false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isBuiltInAction(actionName: string): actionName is BuiltInAction;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { AnyModel } from "../model/BaseModel";
|
|
2
|
+
/**
|
|
3
|
+
* Low level action context.
|
|
4
|
+
*/
|
|
5
|
+
export interface ActionContext {
|
|
6
|
+
/**
|
|
7
|
+
* Action name
|
|
8
|
+
*/
|
|
9
|
+
readonly actionName: string;
|
|
10
|
+
/**
|
|
11
|
+
* Action type, sync or async.
|
|
12
|
+
*/
|
|
13
|
+
readonly type: ActionContextActionType;
|
|
14
|
+
/**
|
|
15
|
+
* Action target object.
|
|
16
|
+
*/
|
|
17
|
+
readonly target: AnyModel;
|
|
18
|
+
/**
|
|
19
|
+
* Array of action arguments.
|
|
20
|
+
*/
|
|
21
|
+
readonly args: ReadonlyArray<any>;
|
|
22
|
+
/**
|
|
23
|
+
* Parent action context, if any.
|
|
24
|
+
*/
|
|
25
|
+
readonly parentContext?: ActionContext;
|
|
26
|
+
/**
|
|
27
|
+
* Root action context, or itself if the root.
|
|
28
|
+
*/
|
|
29
|
+
readonly rootContext: ActionContext;
|
|
30
|
+
/**
|
|
31
|
+
* Previous async step context, undefined for sync actions or the first action of a flow.
|
|
32
|
+
*/
|
|
33
|
+
readonly previousAsyncStepContext?: ActionContext;
|
|
34
|
+
/**
|
|
35
|
+
* Spawn async step context, undefined for sync actions.
|
|
36
|
+
*/
|
|
37
|
+
readonly spawnAsyncStepContext?: ActionContext;
|
|
38
|
+
/**
|
|
39
|
+
* Async step type, or undefined for sync actions.
|
|
40
|
+
*/
|
|
41
|
+
readonly asyncStepType?: ActionContextAsyncStepType;
|
|
42
|
+
/**
|
|
43
|
+
* Custom data for the action context to be set by middlewares, an object.
|
|
44
|
+
* Symbols must be used as keys to avoid name clashing between middlewares.
|
|
45
|
+
*/
|
|
46
|
+
readonly data: Record<symbol, any>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Action type, sync or async.
|
|
50
|
+
*/
|
|
51
|
+
export declare enum ActionContextActionType {
|
|
52
|
+
Sync = "sync",
|
|
53
|
+
Async = "async"
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* An async step type.
|
|
57
|
+
*/
|
|
58
|
+
export declare enum ActionContextAsyncStepType {
|
|
59
|
+
/**
|
|
60
|
+
* The flow is about to start.
|
|
61
|
+
*/
|
|
62
|
+
Spawn = "spawn",
|
|
63
|
+
/**
|
|
64
|
+
* The flow is about to return (finish).
|
|
65
|
+
*/
|
|
66
|
+
Return = "return",
|
|
67
|
+
/**
|
|
68
|
+
* The flow is about to continue.
|
|
69
|
+
*/
|
|
70
|
+
Resume = "resume",
|
|
71
|
+
/**
|
|
72
|
+
* The flow yield just threw, which might be recovered (caught) or not.
|
|
73
|
+
*/
|
|
74
|
+
ResumeError = "resumeError",
|
|
75
|
+
/**
|
|
76
|
+
* The flow is about to throw an error to the flow caller.
|
|
77
|
+
*/
|
|
78
|
+
Throw = "throw"
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets the currently running action context, or undefined if none.
|
|
82
|
+
*
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
export declare function getCurrentActionContext(): ActionContext | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A hook action.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum HookAction {
|
|
5
|
+
/**
|
|
6
|
+
* onInit hook
|
|
7
|
+
*/
|
|
8
|
+
OnInit = "$$onInit",
|
|
9
|
+
/**
|
|
10
|
+
* onLazyInit hook
|
|
11
|
+
*/
|
|
12
|
+
OnLazyInit = "$$onLazyInit",
|
|
13
|
+
/**
|
|
14
|
+
* onAttachedToRootStore hook
|
|
15
|
+
*/
|
|
16
|
+
OnAttachedToRootStore = "$$onAttachedToRootStore",
|
|
17
|
+
/**
|
|
18
|
+
* disposer for onAttachedToRootStore hook
|
|
19
|
+
*/
|
|
20
|
+
OnAttachedToRootStoreDisposer = "$$onAttachedToRootStoreDisposer"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns if a given action name corresponds to a hook, this is, one of:
|
|
24
|
+
* - onInit() hook
|
|
25
|
+
* - onLazyInit() hook
|
|
26
|
+
* - onAttachedToRootStore() hook
|
|
27
|
+
* - disposer returned by a onAttachedToRootStore() hook
|
|
28
|
+
*
|
|
29
|
+
* @param actionName Action name to check.
|
|
30
|
+
* @returns true if it is a hook, false otherwise.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isHookAction(actionName: string): actionName is HookAction;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./applyAction";
|
|
2
|
+
export * from "./applyDelete";
|
|
3
|
+
export * from "./applyMethodCall";
|
|
4
|
+
export * from "./applySet";
|
|
5
|
+
export * from "./builtInActions";
|
|
6
|
+
export * from "./context";
|
|
7
|
+
export * from "./hookActions";
|
|
8
|
+
export * from "./isModelAction";
|
|
9
|
+
export * from "./middleware";
|
|
10
|
+
export * from "./modelAction";
|
|
11
|
+
export * from "./modelFlow";
|
|
12
|
+
export * from "./runUnprotected";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ActionContext } from "./context";
|
|
2
|
+
/**
|
|
3
|
+
* An action middleware.
|
|
4
|
+
*/
|
|
5
|
+
export interface ActionMiddleware {
|
|
6
|
+
/**
|
|
7
|
+
* Subtree root object (object and child objects) this middleware will run for.
|
|
8
|
+
* This target "filter" will be run before the custom filter.
|
|
9
|
+
*/
|
|
10
|
+
readonly subtreeRoot: object;
|
|
11
|
+
/**
|
|
12
|
+
* A filter function to decide if an action middleware function should be run or not.
|
|
13
|
+
*/
|
|
14
|
+
filter?(ctx: ActionContext): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* An action middleware function.
|
|
17
|
+
* Rember to `return next()` if you want to continue the action or throw if you want to cancel it.
|
|
18
|
+
*/
|
|
19
|
+
middleware(ctx: ActionContext, next: () => any): any;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The disposer of an action middleware.
|
|
23
|
+
*/
|
|
24
|
+
export declare type ActionMiddlewareDisposer = () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Adds a global action middleware to be run when an action is performed.
|
|
27
|
+
* It is usually preferable to use `onActionMiddleware` instead to limit it to a given tree and only to topmost level actions
|
|
28
|
+
* or `actionTrackingMiddleware` for a simplified middleware.
|
|
29
|
+
*
|
|
30
|
+
* @param mware Action middleware to be run.
|
|
31
|
+
* @returns A disposer to cancel the middleware. Note that if you don't plan to do an early disposal of the middleware
|
|
32
|
+
* calling this function becomes optional.
|
|
33
|
+
*/
|
|
34
|
+
export declare function addActionMiddleware(mware: ActionMiddleware): ActionMiddlewareDisposer;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorator that turns a function into a model action.
|
|
3
|
+
*
|
|
4
|
+
* @param target
|
|
5
|
+
* @param propertyKey
|
|
6
|
+
* @param [baseDescriptor]
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function modelAction(target: any, propertyKey: string, baseDescriptor?: PropertyDescriptor): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns if the given function is a model flow or not.
|
|
3
|
+
*
|
|
4
|
+
* @param fn Function to check.
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function isModelFlow(fn: unknown): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Decorator that turns a function generator into a model flow.
|
|
10
|
+
*
|
|
11
|
+
* @param target
|
|
12
|
+
* @param propertyKey
|
|
13
|
+
* @param [baseDescriptor]
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function modelFlow(target: any, propertyKey: string, baseDescriptor?: PropertyDescriptor): void;
|
|
17
|
+
/**
|
|
18
|
+
* Tricks the TS compiler into thinking that a model flow generator function can be awaited
|
|
19
|
+
* (is a promise).
|
|
20
|
+
*
|
|
21
|
+
* @typeparam A Function arguments.
|
|
22
|
+
* @typeparam R Return value.
|
|
23
|
+
* @param fn Flow function.
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare function _async<A extends any[], R>(fn: (...args: A) => Generator<any, R, any>): (...args: A) => Promise<R>;
|
|
27
|
+
/**
|
|
28
|
+
* Makes a promise a flow, so it can be awaited with yield*.
|
|
29
|
+
*
|
|
30
|
+
* @typeparam T Promise return type.
|
|
31
|
+
* @param promise Promise.
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function _await<T>(promise: Promise<T>): Generator<Promise<T>, T, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs a block in unprocted mode, as if it were run inside a model action.
|
|
3
|
+
* Consider using a proper model action instead since these kind of actions are not recorded.
|
|
4
|
+
*
|
|
5
|
+
* @typeparam T Return type.
|
|
6
|
+
* @param name Mobx action name.
|
|
7
|
+
* @param fn Action block.
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function runUnprotected<T>(name: string, fn: () => T): T;
|
|
11
|
+
/**
|
|
12
|
+
* Runs a block in unprocted mode, as if it were run inside a model action.
|
|
13
|
+
* Consider using a proper model action instead since these kind of actions are not recorded.
|
|
14
|
+
*
|
|
15
|
+
* @typeparam T Return type.
|
|
16
|
+
* @param fn Action block.
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare function runUnprotected<T>(fn: () => T): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ActionCall } from "../../action/applyAction";
|
|
2
|
+
import type { JSONPrimitiveValue } from "../../utils/types";
|
|
3
|
+
import { ActionCallArgumentSerializer } from "./core";
|
|
4
|
+
/**
|
|
5
|
+
* Registers a new action call argument serializers.
|
|
6
|
+
* Serializers are called in the inverse order they are registered, meaning the
|
|
7
|
+
* latest one registered will be called first.
|
|
8
|
+
*
|
|
9
|
+
* @param serializer Serializer to register.
|
|
10
|
+
* @returns A disposer to unregister the serializer.
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerActionCallArgumentSerializer(serializer: ActionCallArgumentSerializer<any, any>): () => void;
|
|
13
|
+
/**
|
|
14
|
+
* Serialized action call argument.
|
|
15
|
+
*/
|
|
16
|
+
export interface SerializedActionCallArgument {
|
|
17
|
+
/**
|
|
18
|
+
* Serializer id.
|
|
19
|
+
*/
|
|
20
|
+
readonly $mobxKeystoneSerializer: string;
|
|
21
|
+
/**
|
|
22
|
+
* Serialized value.
|
|
23
|
+
*/
|
|
24
|
+
readonly value: any;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A serialized action call.
|
|
28
|
+
*/
|
|
29
|
+
export interface SerializedActionCall extends Omit<ActionCall, "serialized"> {
|
|
30
|
+
/**
|
|
31
|
+
* Serialized action arguments.
|
|
32
|
+
*/
|
|
33
|
+
readonly args: ReadonlyArray<SerializedActionCallArgument | JSONPrimitiveValue>;
|
|
34
|
+
/**
|
|
35
|
+
* Marks this action call as serialized.
|
|
36
|
+
*/
|
|
37
|
+
serialized: true;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Transforms an action call argument by returning a `SerializedActionCallArgument`.
|
|
41
|
+
* The following are supported out of the box:
|
|
42
|
+
* - Primitives.
|
|
43
|
+
* - Nodes that are under the same root node as the target root (when provided) will be serialized
|
|
44
|
+
* as a path.
|
|
45
|
+
* - Nodes that are not under the same root node as the target root will be serialized as their snapshot.
|
|
46
|
+
* - Arrays (observable or not).
|
|
47
|
+
* - Dates.
|
|
48
|
+
* - Maps (observable or not).
|
|
49
|
+
* - Sets (observable or not).
|
|
50
|
+
* - Plain objects (observable or not).
|
|
51
|
+
*
|
|
52
|
+
* If the value cannot be serialized it will throw an exception.
|
|
53
|
+
*
|
|
54
|
+
* @param argValue Argument value to be transformed into its serializable form.
|
|
55
|
+
* @param [targetRoot] Target root node of the model where this action is being performed.
|
|
56
|
+
* @returns The serializable form of the passed value.
|
|
57
|
+
*/
|
|
58
|
+
export declare function serializeActionCallArgument(argValue: any, targetRoot?: object): SerializedActionCallArgument | JSONPrimitiveValue;
|
|
59
|
+
/**
|
|
60
|
+
* Ensures that an action call is serializable by mapping the action arguments into its
|
|
61
|
+
* serializable version by using `serializeActionCallArgument`.
|
|
62
|
+
*
|
|
63
|
+
* @param actionCall Action call to convert.
|
|
64
|
+
* @param [targetRoot] Target root node of the model where this action is being performed.
|
|
65
|
+
* @returns The serializable action call.
|
|
66
|
+
*/
|
|
67
|
+
export declare function serializeActionCall(actionCall: ActionCall, targetRoot?: object): SerializedActionCall;
|
|
68
|
+
/**
|
|
69
|
+
* Transforms an action call argument by returning its deserialized equivalent.
|
|
70
|
+
*
|
|
71
|
+
* @param argValue Argument value to be transformed into its deserialized form.
|
|
72
|
+
* @param [targetRoot] Target root node of the model where this action is being performed.
|
|
73
|
+
* @returns The deserialized form of the passed value.
|
|
74
|
+
*/
|
|
75
|
+
export declare function deserializeActionCallArgument(argValue: SerializedActionCallArgument | JSONPrimitiveValue, targetRoot?: object): any;
|
|
76
|
+
/**
|
|
77
|
+
* Ensures that an action call is deserialized by mapping the action arguments into its
|
|
78
|
+
* deserialized version by using `deserializeActionCallArgument`.
|
|
79
|
+
*
|
|
80
|
+
* @param actionCall Action call to convert.
|
|
81
|
+
* @param [targetRoot] Target root node of the model where this action is being performed.
|
|
82
|
+
* @returns The deserialized action call.
|
|
83
|
+
*/
|
|
84
|
+
export declare function deserializeActionCall(actionCall: SerializedActionCall, targetRoot?: object): ActionCall;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Patch } from "../../patch/Patch";
|
|
2
|
+
import { SerializedActionCall } from "./actionSerialization";
|
|
3
|
+
/**
|
|
4
|
+
* Serialized action call with model ID overrides.
|
|
5
|
+
* Can be generated with `applySerializedActionAndTrackNewModelIds`.
|
|
6
|
+
* To be applied with `applySerializedActionAndSyncNewModelIds`.
|
|
7
|
+
*/
|
|
8
|
+
export interface SerializedActionCallWithModelIdOverrides extends SerializedActionCall {
|
|
9
|
+
/**
|
|
10
|
+
* Model Id overrides to be applied at the end of applying the action.
|
|
11
|
+
*/
|
|
12
|
+
readonly modelIdOverrides: ReadonlyArray<Patch>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Applies (runs) a serialized action over a target object.
|
|
16
|
+
* In this mode newly generated / modified model IDs will be tracked
|
|
17
|
+
* so they can be later synchronized when applying it on another machine
|
|
18
|
+
* via `applySerializedActionAndSyncNewModelIds`.
|
|
19
|
+
* This means this method is usually used on the server side.
|
|
20
|
+
*
|
|
21
|
+
* If you intend to apply non-serialized actions check `applyAction` instead.
|
|
22
|
+
*
|
|
23
|
+
* @param subtreeRoot Subtree root target object to run the action over.
|
|
24
|
+
* @param call The serialized action, usually as coming from the server/client.
|
|
25
|
+
* @returns The return value of the action, if any, plus a new serialized action
|
|
26
|
+
* with model overrides.
|
|
27
|
+
*/
|
|
28
|
+
export declare function applySerializedActionAndTrackNewModelIds<TRet = any>(subtreeRoot: object, call: SerializedActionCall): {
|
|
29
|
+
returnValue: TRet;
|
|
30
|
+
serializedActionCall: SerializedActionCallWithModelIdOverrides;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Applies (runs) a serialized action over a target object.
|
|
34
|
+
* In this mode newly generated / modified model IDs previously tracked
|
|
35
|
+
* by `applySerializedActionAndTrackNewModelIds` will be synchronized after
|
|
36
|
+
* the action is applied.
|
|
37
|
+
* This means this method is usually used on the client side.
|
|
38
|
+
*
|
|
39
|
+
* If you intend to apply non-serialized actions check `applyAction` instead.
|
|
40
|
+
*
|
|
41
|
+
* @param subtreeRoot Subtree root target object to run the action over.
|
|
42
|
+
* @param call The serialized action, usually as coming from the server/client.
|
|
43
|
+
* @returns The return value of the action, if any.
|
|
44
|
+
*/
|
|
45
|
+
export declare function applySerializedActionAndSyncNewModelIds<TRet = any>(subtreeRoot: object, call: SerializedActionCallWithModelIdOverrides): TRet;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const cannotSerialize: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* Serializer of action call arguments.
|
|
4
|
+
*/
|
|
5
|
+
export interface ActionCallArgumentSerializer<TOriginal, TSerialized> {
|
|
6
|
+
/**
|
|
7
|
+
* Serializer ID, must be unique.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* Serializes an action call argument, returning `cannotSerialize` if not possible.
|
|
12
|
+
*
|
|
13
|
+
* @param value Value to serialize.
|
|
14
|
+
* @param targetRoot Target root, if provided.
|
|
15
|
+
* @param serializeChild Serialize a child.
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
serialize(value: unknown, serializeChild: (v: unknown) => unknown, targetRoot: object | undefined): TSerialized | typeof cannotSerialize;
|
|
19
|
+
/**
|
|
20
|
+
* Deserializes an action call argument.
|
|
21
|
+
*
|
|
22
|
+
* @param value Value to deserialize.
|
|
23
|
+
* @param targetRoot Target root, if provided.
|
|
24
|
+
* @param deserializeChild Deserialize a child.
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
deserialize(value: TSerialized, deserializeChild: (v: unknown) => unknown, targetRoot: object | undefined): TOriginal;
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Path } from "../../parent/pathTypes";
|
|
2
|
+
import { ActionCallArgumentSerializer } from "./core";
|
|
3
|
+
interface ObjectPath {
|
|
4
|
+
targetPath: Path;
|
|
5
|
+
targetPathIds: (string | null)[];
|
|
6
|
+
}
|
|
7
|
+
export declare const objectPathSerializer: ActionCallArgumentSerializer<object, ObjectPath>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ActionContext, ActionContextActionType } from "../action/context";
|
|
2
|
+
import { ActionMiddlewareDisposer } from "../action/middleware";
|
|
3
|
+
import type { AnyModel } from "../model/BaseModel";
|
|
4
|
+
/**
|
|
5
|
+
* Simplified version of action context.
|
|
6
|
+
*/
|
|
7
|
+
export interface SimpleActionContext {
|
|
8
|
+
/**
|
|
9
|
+
* Action name
|
|
10
|
+
*/
|
|
11
|
+
readonly actionName: string;
|
|
12
|
+
/**
|
|
13
|
+
* Action type, sync or async.
|
|
14
|
+
*/
|
|
15
|
+
readonly type: ActionContextActionType;
|
|
16
|
+
/**
|
|
17
|
+
* Action target model instance.
|
|
18
|
+
*/
|
|
19
|
+
readonly target: AnyModel;
|
|
20
|
+
/**
|
|
21
|
+
* Array of action arguments.
|
|
22
|
+
*/
|
|
23
|
+
readonly args: ReadonlyArray<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Parent action context, if any.
|
|
26
|
+
*/
|
|
27
|
+
readonly parentContext?: SimpleActionContext;
|
|
28
|
+
/**
|
|
29
|
+
* Root action context, or itself if the root.
|
|
30
|
+
*/
|
|
31
|
+
readonly rootContext: SimpleActionContext;
|
|
32
|
+
/**
|
|
33
|
+
* Custom data for the action context to be set by middlewares, an object.
|
|
34
|
+
* Symbols must be used as keys to avoid name clashing between middlewares.
|
|
35
|
+
*/
|
|
36
|
+
readonly data: Record<symbol, any>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Action tracking middleware finish result.
|
|
40
|
+
*/
|
|
41
|
+
export declare enum ActionTrackingResult {
|
|
42
|
+
/**
|
|
43
|
+
* The action returned normally (without throwing).
|
|
44
|
+
*/
|
|
45
|
+
Return = "return",
|
|
46
|
+
/**
|
|
47
|
+
* The action threw an error.
|
|
48
|
+
*/
|
|
49
|
+
Throw = "throw"
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Action tracking middleware hooks.
|
|
53
|
+
*/
|
|
54
|
+
export interface ActionTrackingMiddleware {
|
|
55
|
+
/**
|
|
56
|
+
* Filter function called whenever each action starts, and only then.
|
|
57
|
+
*
|
|
58
|
+
* If the action is accepted then `onStart`, `onResume`, `onSuspend` and `onFinish`
|
|
59
|
+
* for that particular action will be called.
|
|
60
|
+
*
|
|
61
|
+
* All actions are accepted by default if no filter function is present.
|
|
62
|
+
*
|
|
63
|
+
* @param ctx Simplified action context.
|
|
64
|
+
* @returns true to accept the action, false to skip it.
|
|
65
|
+
*/
|
|
66
|
+
filter?(ctx: SimpleActionContext): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Called when an action just started.
|
|
69
|
+
*
|
|
70
|
+
* @param ctx Simplified action context.
|
|
71
|
+
* @returns Can optionally return a result that will cancel the original action and finish it
|
|
72
|
+
* with the returned value / error to be thrown. In either case case resume / suspend / finish will
|
|
73
|
+
* still be called normally.
|
|
74
|
+
*/
|
|
75
|
+
onStart?(ctx: SimpleActionContext): void | ActionTrackingReturn;
|
|
76
|
+
/**
|
|
77
|
+
* Called when an action just resumed a synchronous piece of code execution.
|
|
78
|
+
* Gets called once for sync actions and multiple times for flows.
|
|
79
|
+
*
|
|
80
|
+
* @param ctx Simplified action context.
|
|
81
|
+
*/
|
|
82
|
+
onResume?(ctx: SimpleActionContext): void;
|
|
83
|
+
/**
|
|
84
|
+
* Called when an action just finished a synchronous pice of code execution.
|
|
85
|
+
* Note that this doesn't necessarily mean the action is finished.
|
|
86
|
+
* Gets called once for sync actions and multiple times for flows.
|
|
87
|
+
*
|
|
88
|
+
* @param ctx Simplified action context.
|
|
89
|
+
*/
|
|
90
|
+
onSuspend?(ctx: SimpleActionContext): void;
|
|
91
|
+
/**
|
|
92
|
+
* Called when an action just finished, either by returning normally or by throwing an error.
|
|
93
|
+
*
|
|
94
|
+
* @param ctx Simplified action context.
|
|
95
|
+
* @param ret Action return result.
|
|
96
|
+
* @returns Can optionally return a new result that will override the original one.
|
|
97
|
+
*/
|
|
98
|
+
onFinish?(ctx: SimpleActionContext, ret: ActionTrackingReturn): void | ActionTrackingReturn;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Return result of an action.
|
|
102
|
+
*/
|
|
103
|
+
export interface ActionTrackingReturn {
|
|
104
|
+
result: ActionTrackingResult;
|
|
105
|
+
value: any;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates an action tracking middleware, which is a simplified version
|
|
109
|
+
* of the standard action middleware.
|
|
110
|
+
*
|
|
111
|
+
* @param subtreeRoot Subtree root target object.
|
|
112
|
+
* @param hooks Middleware hooks.
|
|
113
|
+
* @returns The middleware disposer.
|
|
114
|
+
*/
|
|
115
|
+
export declare function actionTrackingMiddleware(subtreeRoot: object, hooks: ActionTrackingMiddleware): ActionMiddlewareDisposer;
|
|
116
|
+
/**
|
|
117
|
+
* Simplifies an action context by converting an async call hierarchy into a simpler one.
|
|
118
|
+
*
|
|
119
|
+
* @param ctx Action context to convert.
|
|
120
|
+
* @returns Simplified action context.
|
|
121
|
+
*/
|
|
122
|
+
export declare function simplifyActionContext(ctx: ActionContext): SimpleActionContext;
|