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,41 @@
|
|
|
1
|
+
import type { Path } from "./pathTypes";
|
|
2
|
+
/**
|
|
3
|
+
* Iterates through all the parents (from the nearest until the root)
|
|
4
|
+
* until one of them matches the given predicate.
|
|
5
|
+
* If the predicate is matched it will return the found node.
|
|
6
|
+
* If none is found it will return undefined.
|
|
7
|
+
*
|
|
8
|
+
* @typeparam T Parent object type.
|
|
9
|
+
* @param child Target object.
|
|
10
|
+
* @param predicate Function that will be run for every parent of the target object, from immediate parent to the root.
|
|
11
|
+
* @param maxDepth Max depth, or 0 for infinite.
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function findParent<T extends object = any>(child: object, predicate: (parentNode: object) => boolean, maxDepth?: number): T | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Result of `findParentPath`.
|
|
17
|
+
*/
|
|
18
|
+
export interface FoundParentPath<T extends object> {
|
|
19
|
+
/**
|
|
20
|
+
* Found parent object.
|
|
21
|
+
*/
|
|
22
|
+
readonly parent: T;
|
|
23
|
+
/**
|
|
24
|
+
* Path from the found parent to the child.
|
|
25
|
+
*/
|
|
26
|
+
readonly path: Path;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Iterates through all the parents (from the nearest until the root)
|
|
30
|
+
* until one of them matches the given predicate.
|
|
31
|
+
* If the predicate is matched it will return the found node plus the
|
|
32
|
+
* path to get from the parent to the child.
|
|
33
|
+
* If none is found it will return undefined.
|
|
34
|
+
*
|
|
35
|
+
* @typeparam T Parent object type.
|
|
36
|
+
* @param child Target object.
|
|
37
|
+
* @param predicate Function that will be run for every parent of the target object, from immediate parent to the root.
|
|
38
|
+
* @param maxDepth Max depth, or 0 for infinite.
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export declare function findParentPath<T extends object = any>(child: object, predicate: (parentNode: object) => boolean, maxDepth?: number): FoundParentPath<T> | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns all the children objects (this is, excluding primitives) of an object.
|
|
3
|
+
*
|
|
4
|
+
* @param node Object to get the list of children from.
|
|
5
|
+
* @param [options] An optional object with the `deep` option (defaults to false) to true to get
|
|
6
|
+
* the children deeply or false to get them shallowly.
|
|
7
|
+
* @returns A readonly observable set with the children.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getChildrenObjects(node: object, options?: {
|
|
10
|
+
deep?: boolean;
|
|
11
|
+
}): ReadonlySet<object>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./detach";
|
|
2
|
+
export * from "./findChildren";
|
|
3
|
+
export * from "./findParent";
|
|
4
|
+
export * from "./getChildrenObjects";
|
|
5
|
+
export * from "./onChildAttachedTo";
|
|
6
|
+
export * from "./path";
|
|
7
|
+
export * from "./path2";
|
|
8
|
+
export * from "./pathTypes";
|
|
9
|
+
export * from "./walkTree";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs a callback everytime a new object is attached to a given node.
|
|
3
|
+
* The callback can optionally return a disposer which will be run when the child is detached.
|
|
4
|
+
*
|
|
5
|
+
* The optional options parameter accepts and object with the following options:
|
|
6
|
+
* - `deep: boolean` (default: `false`) - true if the callback should be run for all children deeply
|
|
7
|
+
* or false if it it should only run for shallow children.
|
|
8
|
+
* - `fireForCurrentChildren: boolean` (default: `true`) - true if the callback should be immediately
|
|
9
|
+
* called for currently attached children, false if only for future attachments.
|
|
10
|
+
*
|
|
11
|
+
* Returns a disposer, which has a boolean parameter which should be true if pending detachment
|
|
12
|
+
* callbacks should be run or false otherwise.
|
|
13
|
+
*
|
|
14
|
+
* @param target Function that returns the object whose children should be tracked.
|
|
15
|
+
* @param fn Callback called when a child is attached to the target object.
|
|
16
|
+
* @param [options]
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare function onChildAttachedTo(target: () => object, fn: (child: object) => (() => void) | void, options?: {
|
|
20
|
+
deep?: boolean;
|
|
21
|
+
fireForCurrentChildren?: boolean;
|
|
22
|
+
}): (runDetachDisposers: boolean) => void;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Path, PathElement } from "./pathTypes";
|
|
2
|
+
/**
|
|
3
|
+
* Path from an object to its immediate parent.
|
|
4
|
+
*
|
|
5
|
+
* @typeparam T Parent object type.
|
|
6
|
+
*/
|
|
7
|
+
export interface ParentPath<T extends object> {
|
|
8
|
+
/**
|
|
9
|
+
* Parent object.
|
|
10
|
+
*/
|
|
11
|
+
readonly parent: T;
|
|
12
|
+
/**
|
|
13
|
+
* Property name (if the parent is an object) or index number (if the parent is an array).
|
|
14
|
+
*/
|
|
15
|
+
readonly path: PathElement;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Path from an object to its root.
|
|
19
|
+
*
|
|
20
|
+
* @typeparam T Root object type.
|
|
21
|
+
*/
|
|
22
|
+
export interface RootPath<T extends object> {
|
|
23
|
+
/**
|
|
24
|
+
* Root object.
|
|
25
|
+
*/
|
|
26
|
+
readonly root: T;
|
|
27
|
+
/**
|
|
28
|
+
* Path from the root to the given target, as a string array.
|
|
29
|
+
* If the target is a root itself then the array will be empty.
|
|
30
|
+
*/
|
|
31
|
+
readonly path: Path;
|
|
32
|
+
/**
|
|
33
|
+
* Objects in the path, from root (included) until target (included).
|
|
34
|
+
* If the target is a root then only the target will be included.
|
|
35
|
+
*/
|
|
36
|
+
readonly pathObjects: ReadonlyArray<unknown>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns the parent of the target plus the path from the parent to the target, or undefined if it has no parent.
|
|
40
|
+
*
|
|
41
|
+
* @typeparam T Parent object type.
|
|
42
|
+
* @param value Target object.
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export declare function getParentPath<T extends object = any>(value: object): ParentPath<T> | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the parent object of the target object, or undefined if there's no parent.
|
|
48
|
+
*
|
|
49
|
+
* @typeparam T Parent object type.
|
|
50
|
+
* @param value Target object.
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
export declare function getParent<T extends object = any>(value: object): T | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Returns if a given object is a model interim data object (`$`).
|
|
56
|
+
*
|
|
57
|
+
* @param value Object to check.
|
|
58
|
+
* @returns true if it is, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
export declare function isModelDataObject(value: object): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the root of the target plus the path from the root to get to the target.
|
|
63
|
+
*
|
|
64
|
+
* @typeparam T Root object type.
|
|
65
|
+
* @param value Target object.
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
export declare function getRootPath<T extends object = any>(value: object): RootPath<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the root of the target object, or itself if the target is a root.
|
|
71
|
+
*
|
|
72
|
+
* @typeparam T Root object type.
|
|
73
|
+
* @param value Target object.
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
export declare function getRoot<T extends object = any>(value: object): T;
|
|
77
|
+
/**
|
|
78
|
+
* Returns if a given object is a root object.
|
|
79
|
+
*
|
|
80
|
+
* @param value Target object.
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
export declare function isRoot(value: object): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Tries to resolve a path from an object.
|
|
86
|
+
*
|
|
87
|
+
* @typeparam T Returned value type.
|
|
88
|
+
* @param pathRootObject Object that serves as path root.
|
|
89
|
+
* @param path Path as an string or number array.
|
|
90
|
+
* @returns An object with `{ resolved: true, value: T }` or `{ resolved: false }`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolvePath<T = any>(pathRootObject: object, path: Path): {
|
|
93
|
+
resolved: true;
|
|
94
|
+
value: T;
|
|
95
|
+
} | {
|
|
96
|
+
resolved: false;
|
|
97
|
+
value?: undefined;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Gets the path to get from a parent to a given child.
|
|
101
|
+
* Returns an empty array if the child is actually the given parent or undefined if the child is not a child of the parent.
|
|
102
|
+
*
|
|
103
|
+
* @param fromParent
|
|
104
|
+
* @param toChild
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
export declare function getParentToChildPath(fromParent: object, toChild: object): Path | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns if the target is a "child" of the tree of the given "parent" object.
|
|
3
|
+
*
|
|
4
|
+
* @param child Target object.
|
|
5
|
+
* @param parent Parent object.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function isChildOfParent(child: object, parent: object): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returns if the target is a "parent" that has in its tree the given "child" object.
|
|
11
|
+
*
|
|
12
|
+
* @param parent Target object.
|
|
13
|
+
* @param child Child object.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function isParentOfChild(parent: object, child: object): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Property name (if the parent is an object) or index number (if the parent is an array).
|
|
3
|
+
*/
|
|
4
|
+
export declare type PathElement = string | number;
|
|
5
|
+
/**
|
|
6
|
+
* Path from a parent to a child.
|
|
7
|
+
*/
|
|
8
|
+
export declare type Path = ReadonlyArray<string | number>;
|
|
9
|
+
/**
|
|
10
|
+
* Path from a parent to a child (writable).
|
|
11
|
+
*/
|
|
12
|
+
export declare type WritablePath = (string | number)[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mode for the `walkTree` method.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum WalkTreeMode {
|
|
5
|
+
/**
|
|
6
|
+
* The walk will be done parent (roots) first, then children.
|
|
7
|
+
*/
|
|
8
|
+
ParentFirst = "parentFirst",
|
|
9
|
+
/**
|
|
10
|
+
* The walk will be done children (leafs) first, then parents.
|
|
11
|
+
*/
|
|
12
|
+
ChildrenFirst = "childrenFirst"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Walks a tree, running the predicate function for each node.
|
|
16
|
+
* If the predicate function returns something other than undefined,
|
|
17
|
+
* then the walk will be stopped and the function will return the returned value.
|
|
18
|
+
*
|
|
19
|
+
* @typeparam T Returned object type, defaults to void.
|
|
20
|
+
* @param root Subtree root object.
|
|
21
|
+
* @param visit Function that will be run for each node of the tree.
|
|
22
|
+
* @param mode Mode to walk the tree, as defined in `WalkTreeMode`.
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function walkTree<T = void>(root: object, visit: (node: object) => T | undefined, mode: WalkTreeMode): T | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Path } from "../parent/pathTypes";
|
|
2
|
+
export declare type Patch = PatchAddOperation<any> | PatchRemoveOperation | PatchReplaceOperation<any>;
|
|
3
|
+
export interface PatchBaseOperation {
|
|
4
|
+
path: Path;
|
|
5
|
+
}
|
|
6
|
+
export interface PatchAddOperation<T> extends PatchBaseOperation {
|
|
7
|
+
op: "add";
|
|
8
|
+
value: T;
|
|
9
|
+
}
|
|
10
|
+
export interface PatchRemoveOperation extends PatchBaseOperation {
|
|
11
|
+
op: "remove";
|
|
12
|
+
}
|
|
13
|
+
export interface PatchReplaceOperation<T> extends PatchBaseOperation {
|
|
14
|
+
op: "replace";
|
|
15
|
+
value: T;
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Patch } from "../patch/Patch";
|
|
2
|
+
/**
|
|
3
|
+
* Applies the given patches to the given target object.
|
|
4
|
+
*
|
|
5
|
+
* @param node Target object.
|
|
6
|
+
* @param patches List of patches to apply.
|
|
7
|
+
* @param reverse Whether patches are applied in reverse order.
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyPatches(node: object, patches: ReadonlyArray<Patch> | ReadonlyArray<ReadonlyArray<Patch>>, reverse?: boolean): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Patch } from "./Patch";
|
|
2
|
+
/**
|
|
3
|
+
* A function that gets called when a patch is emitted.
|
|
4
|
+
*/
|
|
5
|
+
export declare type OnPatchesListener = (patches: Patch[], inversePatches: Patch[]) => void;
|
|
6
|
+
/**
|
|
7
|
+
* A function that gets called when a global patch is emitted.
|
|
8
|
+
*/
|
|
9
|
+
export declare type OnGlobalPatchesListener = (target: object, patches: Patch[], inversePatches: Patch[]) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Disposer function to stop listening to patches.
|
|
12
|
+
*/
|
|
13
|
+
export declare type OnPatchesDisposer = () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Adds a listener that will be called every time a patch is generated for the tree of the given target object.
|
|
16
|
+
*
|
|
17
|
+
* @param subtreeRoot Subtree root object of the patch listener.
|
|
18
|
+
* @param listener The listener function that will be called everytime a patch is generated for the object or its children.
|
|
19
|
+
* @returns A disposer to stop listening to patches.
|
|
20
|
+
*/
|
|
21
|
+
export declare function onPatches(subtreeRoot: object, listener: OnPatchesListener): OnPatchesDisposer;
|
|
22
|
+
/**
|
|
23
|
+
* Adds a listener that will be called every time a patch is generated anywhere.
|
|
24
|
+
* Usually prefer using `onPatches`.
|
|
25
|
+
*
|
|
26
|
+
* @param listener The listener function that will be called everytime a patch is generated anywhere.
|
|
27
|
+
* @returns A disposer to stop listening to patches.
|
|
28
|
+
*/
|
|
29
|
+
export declare function onGlobalPatches(listener: OnGlobalPatchesListener): OnPatchesDisposer;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Path } from "../parent/pathTypes";
|
|
2
|
+
import type { Patch } from "./Patch";
|
|
3
|
+
export declare type JsonPatch = JsonPatchAddOperation<any> | JsonPatchRemoveOperation | JsonPatchReplaceOperation<any>;
|
|
4
|
+
export interface JsonPatchBaseOperation {
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export interface JsonPatchAddOperation<T> extends JsonPatchBaseOperation {
|
|
8
|
+
op: "add";
|
|
9
|
+
value: T;
|
|
10
|
+
}
|
|
11
|
+
export interface JsonPatchRemoveOperation extends JsonPatchBaseOperation {
|
|
12
|
+
op: "remove";
|
|
13
|
+
}
|
|
14
|
+
export interface JsonPatchReplaceOperation<T> extends JsonPatchBaseOperation {
|
|
15
|
+
op: "replace";
|
|
16
|
+
value: T;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Converts a path into a JSON pointer.
|
|
20
|
+
*
|
|
21
|
+
* @param path Path to convert.
|
|
22
|
+
* @returns Converted JSON pointer.
|
|
23
|
+
*/
|
|
24
|
+
export declare function pathToJsonPointer(path: Path): string;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a JSON pointer into a path.
|
|
27
|
+
*
|
|
28
|
+
* @param jsonPointer JSON pointer to convert.
|
|
29
|
+
* @returns Converted path.
|
|
30
|
+
*/
|
|
31
|
+
export declare function jsonPointerToPath(jsonPointer: string): Path;
|
|
32
|
+
/**
|
|
33
|
+
* Convert a patch into a JSON patch.
|
|
34
|
+
*
|
|
35
|
+
* @param patch A patch.
|
|
36
|
+
* @returns A JSON patch.
|
|
37
|
+
*/
|
|
38
|
+
export declare function patchToJsonPatch(patch: Patch): JsonPatch;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a JSON patch into a patch.
|
|
41
|
+
*
|
|
42
|
+
* @param jsonPatch A JSON patch.
|
|
43
|
+
* @returns A patch.
|
|
44
|
+
*/
|
|
45
|
+
export declare function jsonPatchToPatch(jsonPatch: JsonPatch): Patch;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { OnPatchesListener } from "./emitPatch";
|
|
2
|
+
import type { Patch } from "./Patch";
|
|
3
|
+
/**
|
|
4
|
+
* Patch recorder event.
|
|
5
|
+
*/
|
|
6
|
+
export interface PatchRecorderEvent {
|
|
7
|
+
/**
|
|
8
|
+
* Target object.
|
|
9
|
+
*/
|
|
10
|
+
readonly target: object;
|
|
11
|
+
/**
|
|
12
|
+
* Recorded patches.
|
|
13
|
+
*/
|
|
14
|
+
readonly patches: Patch[];
|
|
15
|
+
/**
|
|
16
|
+
* Recorded inverse patches.
|
|
17
|
+
*/
|
|
18
|
+
readonly inversePatches: Patch[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Patch recorder interface.
|
|
22
|
+
*/
|
|
23
|
+
export interface PatchRecorder {
|
|
24
|
+
/**
|
|
25
|
+
* Gets/sets if the patch recorder is currently recording.
|
|
26
|
+
*/
|
|
27
|
+
recording: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Observable array of patching events.
|
|
30
|
+
*/
|
|
31
|
+
readonly events: PatchRecorderEvent[];
|
|
32
|
+
/**
|
|
33
|
+
* Dispose of the patch recorder.
|
|
34
|
+
*/
|
|
35
|
+
dispose(): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Patch recorder options.
|
|
39
|
+
*/
|
|
40
|
+
export interface PatchRecorderOptions {
|
|
41
|
+
/**
|
|
42
|
+
* If the patch recorder is initially recording when created.
|
|
43
|
+
*/
|
|
44
|
+
recording?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* An optional callback filter to select wich patches to record/skip.
|
|
47
|
+
* It will be executed before the event is added to the events list.
|
|
48
|
+
*
|
|
49
|
+
* @param patches Patches about to be recorded.
|
|
50
|
+
* @param inversePatches Inverse patches about to be recorded.
|
|
51
|
+
* @returns `true` to record the patch, `false` to skip it.
|
|
52
|
+
*/
|
|
53
|
+
filter?(patches: Patch[], inversePatches: Patch[]): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* An optional callback run once a patch is recorded.
|
|
56
|
+
* It will be executed after the event is added to the events list.
|
|
57
|
+
*
|
|
58
|
+
* @param patches Patches just recorded.
|
|
59
|
+
* @param inversePatches Inverse patches just recorded.
|
|
60
|
+
*/
|
|
61
|
+
onPatches?: OnPatchesListener;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a patch recorder.
|
|
65
|
+
*
|
|
66
|
+
* @param subtreeRoot
|
|
67
|
+
* @param [opts]
|
|
68
|
+
* @returns The patch recorder.
|
|
69
|
+
*/
|
|
70
|
+
export declare function patchRecorder(subtreeRoot: object, opts?: PatchRecorderOptions): PatchRecorder;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connects a tree node to a redux dev tools instance.
|
|
3
|
+
*
|
|
4
|
+
* @param remotedevPackage The remotedev package (usually the result of `require("remoteDev")`) (https://www.npmjs.com/package/remotedev).
|
|
5
|
+
* @param remotedevConnection The result of a connect method from the remotedev package (usually the result of `remoteDev.connectViaExtension(...)`).
|
|
6
|
+
* @param target Object to use as root.
|
|
7
|
+
* @param storeName Name to be shown in the redux dev tools.
|
|
8
|
+
* @param [options] Optional options object. `logArgsNearName` if it should show the arguments near the action name (default is `true`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function connectReduxDevTools(remotedevPackage: any, remotedevConnection: any, target: object, options?: {
|
|
11
|
+
logArgsNearName?: boolean;
|
|
12
|
+
}): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ActionCall } from "../action";
|
|
2
|
+
import { OnSnapshotDisposer, OnSnapshotListener } from "../snapshot/onSnapshot";
|
|
3
|
+
import type { SnapshotOutOf } from "../snapshot/SnapshotOf";
|
|
4
|
+
export declare const reduxActionType = "applyAction";
|
|
5
|
+
/**
|
|
6
|
+
* A redux action for mobx-keystone.
|
|
7
|
+
*/
|
|
8
|
+
export interface ReduxAction {
|
|
9
|
+
readonly type: typeof reduxActionType;
|
|
10
|
+
readonly payload: ActionCall;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Transforms an action call into a redux action.
|
|
14
|
+
*
|
|
15
|
+
* @param actionCall Action call.
|
|
16
|
+
* @returns A redux action.
|
|
17
|
+
*/
|
|
18
|
+
export declare function actionCallToReduxAction(actionCall: ActionCall): ReduxAction;
|
|
19
|
+
/**
|
|
20
|
+
* A redux store for mobx-keystone.
|
|
21
|
+
*/
|
|
22
|
+
export interface ReduxStore<T> {
|
|
23
|
+
getState(): SnapshotOutOf<T>;
|
|
24
|
+
dispatch(action: ReduxAction): ReduxAction;
|
|
25
|
+
subscribe(listener: OnSnapshotListener<T>): OnSnapshotDisposer;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A redux runner for mobx-keystone.
|
|
29
|
+
*/
|
|
30
|
+
export interface ReduxRunner<T> {
|
|
31
|
+
(next: ReduxStore<T>["dispatch"]): (action: ReduxAction) => ReduxAction;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A redux middleware for mobx-keystone.
|
|
35
|
+
*/
|
|
36
|
+
export interface ReduxMiddleware<T> {
|
|
37
|
+
(store: ReduxStore<T>): ReduxRunner<T>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generates a redux compatible store out of a mobx-keystone object.
|
|
41
|
+
*
|
|
42
|
+
* @typeparam T Object type.
|
|
43
|
+
* @param target Root object.
|
|
44
|
+
* @param middlewares Optional list of redux middlewares.
|
|
45
|
+
* @returns A redux compatible store.
|
|
46
|
+
*/
|
|
47
|
+
export declare function asReduxStore<T extends object>(target: T, ...middlewares: ReduxMiddleware<T>[]): ReduxStore<T>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ModelClass } from "../modelShared/BaseModelShared";
|
|
2
|
+
declare const Ref_base: import("../model/Model")._Model<unknown, {
|
|
3
|
+
/**
|
|
4
|
+
* Reference id.
|
|
5
|
+
*/
|
|
6
|
+
id: import("..").MaybeOptionalModelProp<string>;
|
|
7
|
+
}, never, never>;
|
|
8
|
+
/**
|
|
9
|
+
* A reference model base type.
|
|
10
|
+
* Use `customRef` to create a custom ref constructor.
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class Ref<T extends object> extends Ref_base {
|
|
13
|
+
protected abstract resolve(): T | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The object this reference points to, or `undefined` if the reference is currently invalid.
|
|
16
|
+
*/
|
|
17
|
+
get maybeCurrent(): T | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* If the reference is currently valid.
|
|
20
|
+
*/
|
|
21
|
+
get isValid(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The object this reference points to, or throws if invalid.
|
|
24
|
+
*/
|
|
25
|
+
get current(): T;
|
|
26
|
+
/**
|
|
27
|
+
* Ensures back references for this ref are up to date.
|
|
28
|
+
* This only needs to be called if you need to get the most up to date
|
|
29
|
+
* back references while both still inside an action and while the reference
|
|
30
|
+
* is not a child of the same root than the target.
|
|
31
|
+
*/
|
|
32
|
+
abstract forceUpdateBackRefs(): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @ignore
|
|
36
|
+
*/
|
|
37
|
+
export declare const customRefTypeSymbol: unique symbol;
|
|
38
|
+
/** A ref constructor for custom refs */
|
|
39
|
+
export interface RefConstructor<T extends object> {
|
|
40
|
+
<TE extends T>(valueOrID: TE | string): Ref<TE>;
|
|
41
|
+
refClass: ModelClass<Ref<T>>;
|
|
42
|
+
[customRefTypeSymbol]: T;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Checks if a ref object is of a given ref type.
|
|
46
|
+
*
|
|
47
|
+
* @typeparam T Referenced object type.
|
|
48
|
+
* @param ref Reference object.
|
|
49
|
+
* @param refType Reference type.
|
|
50
|
+
* @returns `true` if it is of the given type, false otherwise.
|
|
51
|
+
*/
|
|
52
|
+
export declare function isRefOfType<T extends object>(ref: Ref<object>, refType: RefConstructor<T>): ref is Ref<T>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ObservableSet } from "mobx";
|
|
2
|
+
import { Ref, RefConstructor } from "./Ref";
|
|
3
|
+
/**
|
|
4
|
+
* Reference resolver type.
|
|
5
|
+
*/
|
|
6
|
+
export declare type RefResolver<T extends object> = (ref: Ref<T>) => T | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Reference ID resolver type.
|
|
9
|
+
*/
|
|
10
|
+
export declare type RefIdResolver = (target: object) => string | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Type for the callback called when a reference resolved value changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare type RefOnResolvedValueChange<T extends object> = (ref: Ref<T>, newValue: T | undefined, oldValue: T | undefined) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Uses a model `getRefId()` method whenever possible to get a reference ID.
|
|
17
|
+
* If the model does not have an implementation of that method it returns `undefined`.
|
|
18
|
+
* If the model has an implementation, but that implementation returns anything other than
|
|
19
|
+
* a `string` it will throw.
|
|
20
|
+
*
|
|
21
|
+
* @param target Target object to get the ID from.
|
|
22
|
+
* @returns The string ID or `undefined`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getModelRefId(target: object): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves a node given its ID.
|
|
27
|
+
*
|
|
28
|
+
* @typeparam T Target object type.
|
|
29
|
+
* @param root Node where to start the search. The search will be done on it and all its children.
|
|
30
|
+
* @param id ID to search for.
|
|
31
|
+
* @param getId Function that will be used to get the ID from an object (`getModelRefId` by default).
|
|
32
|
+
* @returns The node found or `undefined` if none.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveId<T extends object>(root: object, id: string, getId?: RefIdResolver): T | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Gets all references that resolve to a given object.
|
|
37
|
+
*
|
|
38
|
+
* @typeparam T Referenced object type.
|
|
39
|
+
* @param target Node the references point to.
|
|
40
|
+
* @param refType Pass it to filter by only references of a given type, or omit / pass `undefined` to get references of any type.
|
|
41
|
+
* @param options Options.
|
|
42
|
+
* @returns An observable set with all reference objects that point to the given object.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getRefsResolvingTo<T extends object>(target: T, refType?: RefConstructor<T>, options?: {
|
|
45
|
+
updateAllRefsIfNeeded?: boolean;
|
|
46
|
+
}): ObservableSet<Ref<T>>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RefIdResolver, RefOnResolvedValueChange, RefResolver } from "./core";
|
|
2
|
+
import type { RefConstructor } from "./Ref";
|
|
3
|
+
/**
|
|
4
|
+
* Custom reference options.
|
|
5
|
+
*/
|
|
6
|
+
export interface CustomRefOptions<T extends object> {
|
|
7
|
+
/**
|
|
8
|
+
* Must return the resolution for the given reference object.
|
|
9
|
+
*
|
|
10
|
+
* @param ref Reference object.
|
|
11
|
+
* @returns The resolved object or undefined if it could not be resolved.
|
|
12
|
+
*/
|
|
13
|
+
resolve: RefResolver<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Must return the ID associated to the given target object, or `undefined` if it has no ID.
|
|
16
|
+
* If not provided it will try to get the reference id from the model `getRefId()` method.
|
|
17
|
+
*
|
|
18
|
+
* @param target Target object.
|
|
19
|
+
*/
|
|
20
|
+
getId?: RefIdResolver;
|
|
21
|
+
/**
|
|
22
|
+
* What should happen when the resolved value changes.
|
|
23
|
+
*
|
|
24
|
+
* @param ref Reference object.
|
|
25
|
+
* @param newValue New resolved value.
|
|
26
|
+
* @param oldValue Old resolved value.
|
|
27
|
+
*/
|
|
28
|
+
onResolvedValueChange?: RefOnResolvedValueChange<T>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a custom ref to an object, which in its snapshot form has an id.
|
|
32
|
+
*
|
|
33
|
+
* @typeparam T Target object type.
|
|
34
|
+
* @param modelTypeId Unique model type id.
|
|
35
|
+
* @param options Custom reference options.
|
|
36
|
+
* @returns A function that allows you to construct that type of custom reference.
|
|
37
|
+
*/
|
|
38
|
+
export declare const customRef: <T extends object>(modelTypeId: string, options: CustomRefOptions<T>) => RefConstructor<T>;
|