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,125 @@
|
|
|
1
|
+
import { fromSnapshotOverrideTypeSymbol, ModelClass, propsTypeSymbol, toSnapshotOverrideTypeSymbol } from "../modelShared/BaseModelShared";
|
|
2
|
+
import type { ModelProps, ModelPropsToData, ModelPropsToTransformedCreationData } from "../modelShared/prop";
|
|
3
|
+
import type { SnapshotInOfModel, SnapshotOutOfModel } from "../snapshot/SnapshotOf";
|
|
4
|
+
import type { TypeCheckError } from "../types/TypeCheckError";
|
|
5
|
+
import { modelIdKey, modelTypeKey } from "./metadata";
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
export declare const modelIdPropertyNameSymbol: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* Base abstract class for models. Use `Model` instead when extending.
|
|
12
|
+
*
|
|
13
|
+
* Never override the constructor, use `onInit` or `onAttachedToRootStore` instead.
|
|
14
|
+
*
|
|
15
|
+
* @typeparam Data Data type.
|
|
16
|
+
* @typeparam CreationData Creation data type.
|
|
17
|
+
* @typeparam ModelIdPropertyName Model id property name.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class BaseModel<TProps extends ModelProps, FromSnapshotOverride extends Record<string, any>, ToSnapshotOverride extends Record<string, any>, ModelIdPropertyName extends string = never> {
|
|
20
|
+
[propsTypeSymbol]: TProps;
|
|
21
|
+
[fromSnapshotOverrideTypeSymbol]: FromSnapshotOverride;
|
|
22
|
+
[toSnapshotOverrideTypeSymbol]: ToSnapshotOverride;
|
|
23
|
+
[modelIdPropertyNameSymbol]: ModelIdPropertyName;
|
|
24
|
+
/**
|
|
25
|
+
* Model type name.
|
|
26
|
+
*/
|
|
27
|
+
readonly [modelTypeKey]: string;
|
|
28
|
+
/**
|
|
29
|
+
* Model internal id. Can be modified inside a model action.
|
|
30
|
+
* It will return `undefined` if there's no id prop set.
|
|
31
|
+
*/
|
|
32
|
+
get [modelIdKey](): [ModelIdPropertyName] extends [never] ? never : string;
|
|
33
|
+
set [modelIdKey](newId: [ModelIdPropertyName] extends [never] ? never : string);
|
|
34
|
+
/**
|
|
35
|
+
* Can be overridden to offer a reference id to be used in reference resolution.
|
|
36
|
+
* By default it will use the `idProp` if available or return `undefined` otherwise.
|
|
37
|
+
*/
|
|
38
|
+
getRefId(): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Called after the model has been created.
|
|
41
|
+
*/
|
|
42
|
+
protected onInit?(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Data part of the model, which is observable and will be serialized in snapshots.
|
|
45
|
+
* Use it if one of the data properties matches one of the model properties/functions.
|
|
46
|
+
*/
|
|
47
|
+
readonly $: ModelPropsToData<TProps>;
|
|
48
|
+
/**
|
|
49
|
+
* Optional hook that will run once this model instance is attached to the tree of a model marked as
|
|
50
|
+
* root store via `registerRootStore`.
|
|
51
|
+
* Basically this is the place where you know the full root store is complete and where things such as
|
|
52
|
+
* middlewares, effects (reactions, etc), and other side effects should be registered, since it means
|
|
53
|
+
* that the model is now part of the active application state.
|
|
54
|
+
*
|
|
55
|
+
* It can return a disposer that will be run once this model instance is detached from such root store tree.
|
|
56
|
+
*
|
|
57
|
+
* @param rootStore
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
protected onAttachedToRootStore?(rootStore: object): (() => void) | void;
|
|
61
|
+
/**
|
|
62
|
+
* Performs a type check over the model instance.
|
|
63
|
+
* For this to work a data type has to be declared as part of the model properties.
|
|
64
|
+
*
|
|
65
|
+
* @returns A `TypeCheckError` or `null` if there is no error.
|
|
66
|
+
*/
|
|
67
|
+
typeCheck(): TypeCheckError | null;
|
|
68
|
+
/**
|
|
69
|
+
* Creates an instance of a model.
|
|
70
|
+
*/
|
|
71
|
+
constructor(data: ModelPropsToTransformedCreationData<TProps>);
|
|
72
|
+
toString(options?: {
|
|
73
|
+
withData?: boolean;
|
|
74
|
+
}): string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @ignore
|
|
78
|
+
*/
|
|
79
|
+
export declare type BaseModelKeys = keyof AnyModel | "onInit" | "onAttachedToRootStore";
|
|
80
|
+
/**
|
|
81
|
+
* Any kind of model instance.
|
|
82
|
+
*/
|
|
83
|
+
export interface AnyModel extends BaseModel<any, any, any, any> {
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Should not be needed anymore.
|
|
87
|
+
*
|
|
88
|
+
* Tricks TypeScript into accepting abstract classes as a parameter for `ExtendedModel`.
|
|
89
|
+
* Does nothing in runtime.
|
|
90
|
+
*
|
|
91
|
+
* @typeparam T Abstract model class type.
|
|
92
|
+
* @param type Abstract model class.
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
export declare function abstractModelClass<T>(type: T): T & Object;
|
|
96
|
+
/**
|
|
97
|
+
* The model id property name.
|
|
98
|
+
*/
|
|
99
|
+
export declare type ModelIdPropertyName<M extends AnyModel> = M[typeof modelIdPropertyNameSymbol];
|
|
100
|
+
/**
|
|
101
|
+
* Add missing model metadata to a model creation snapshot to generate a proper model snapshot.
|
|
102
|
+
* Usually used alongside `fromSnapshot`.
|
|
103
|
+
*
|
|
104
|
+
* @typeparam M Model type.
|
|
105
|
+
* @param modelClass Model class.
|
|
106
|
+
* @param snapshot Model creation snapshot without metadata.
|
|
107
|
+
* @returns The model snapshot (including metadata).
|
|
108
|
+
*/
|
|
109
|
+
export declare function modelSnapshotInWithMetadata<M extends AnyModel>(modelClass: ModelClass<M>, snapshot: Omit<SnapshotInOfModel<M>, typeof modelTypeKey>): SnapshotInOfModel<M>;
|
|
110
|
+
/**
|
|
111
|
+
* Add missing model metadata to a model output snapshot to generate a proper model snapshot.
|
|
112
|
+
* Usually used alongside `applySnapshot`.
|
|
113
|
+
*
|
|
114
|
+
* @typeparam M Model type.
|
|
115
|
+
* @param modelClass Model class.
|
|
116
|
+
* @param snapshot Model output snapshot without metadata.
|
|
117
|
+
* @returns The model snapshot (including metadata).
|
|
118
|
+
*/
|
|
119
|
+
export declare function modelSnapshotOutWithMetadata<M extends AnyModel>(modelClass: ModelClass<M>, snapshot: Omit<SnapshotOutOfModel<M>, typeof modelTypeKey>): SnapshotOutOfModel<M>;
|
|
120
|
+
/**
|
|
121
|
+
* A model class declaration, made of a base model and the model interface.
|
|
122
|
+
*/
|
|
123
|
+
export declare type ModelClassDeclaration<BaseModelClass, ModelInterface> = BaseModelClass & {
|
|
124
|
+
new (...args: any[]): ModelInterface;
|
|
125
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { AbstractModelClass, ModelTransformedCreationData } from "../modelShared/BaseModelShared";
|
|
2
|
+
import type { ModelProps, ModelPropsToSetter, ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData } from "../modelShared/prop";
|
|
3
|
+
import type { AnyModel, BaseModel, BaseModelKeys, ModelIdPropertyName } from "./BaseModel";
|
|
4
|
+
export declare type _ComposedCreationData<SuperModel, TProps extends ModelProps> = SuperModel extends AnyModel ? ModelPropsToTransformedCreationData<TProps> & ModelTransformedCreationData<SuperModel> : ModelPropsToTransformedCreationData<TProps>;
|
|
5
|
+
/**
|
|
6
|
+
* The default type used by fromSnapshot before processors are applied.
|
|
7
|
+
*/
|
|
8
|
+
export declare type FromSnapshotDefaultType<TProps extends ModelProps> = ModelPropsToSnapshotCreationData<TProps>;
|
|
9
|
+
/**
|
|
10
|
+
* The default type used by getSnapshot before processors are applied.
|
|
11
|
+
*/
|
|
12
|
+
export declare type ToSnapshotDefaultType<TProps extends ModelProps> = ModelPropsToSnapshotData<TProps>;
|
|
13
|
+
export declare type _ModelId<SuperModel, TProps extends ModelProps> = SuperModel extends AnyModel ? ModelIdPropertyName<SuperModel> : ExtractModelIdProp<TProps> & string;
|
|
14
|
+
export interface _Model<SuperModel, TProps extends ModelProps, FromSnapshotOverride extends Record<string, any>, ToSnapshotOverride extends Record<string, any>> {
|
|
15
|
+
new (data: _ComposedCreationData<SuperModel, TProps>): SuperModel & BaseModel<TProps, FromSnapshotOverride, ToSnapshotOverride, _ModelId<SuperModel, TProps>> & Omit<ModelPropsToTransformedData<TProps>, BaseModelKeys> & ModelPropsToSetter<TProps>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extract the model id property from the model props.
|
|
19
|
+
*/
|
|
20
|
+
export declare type ExtractModelIdProp<TProps extends ModelProps> = {
|
|
21
|
+
[K in keyof TProps]: TProps[K]["_internal"]["$isId"] extends true ? K : never;
|
|
22
|
+
}[keyof TProps];
|
|
23
|
+
/**
|
|
24
|
+
* Base abstract class for models that extends another model.
|
|
25
|
+
*
|
|
26
|
+
* @typeparam TProps New model properties type.
|
|
27
|
+
* @typeparam TModelClass Model class type.
|
|
28
|
+
* @param genFn Function that returns the base model and model properties.
|
|
29
|
+
* @param modelOptions Model options.
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare function ExtendedModel<TProps extends ModelProps, TModelClass extends AbstractModelClass<AnyModel>, A extends [], FS extends Record<string, any> = never, TS extends Record<string, any> = never>(genFn: (...args: A) => {
|
|
33
|
+
baseModel: TModelClass;
|
|
34
|
+
props: TProps;
|
|
35
|
+
}, modelOptions?: ModelOptions<TProps, FS, TS>): _Model<InstanceType<TModelClass>, TProps, FS, TS>;
|
|
36
|
+
/**
|
|
37
|
+
* Base abstract class for models that extends another model.
|
|
38
|
+
*
|
|
39
|
+
* @typeparam TProps New model properties type.
|
|
40
|
+
* @typeparam TModelClass Model class type.
|
|
41
|
+
* @param baseModel Base model type.
|
|
42
|
+
* @param modelProps Model properties.
|
|
43
|
+
* @param modelOptions Model options.
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
export declare function ExtendedModel<TProps extends ModelProps, TModelClass extends AbstractModelClass<AnyModel>, FS extends Record<string, any> = never, TS extends Record<string, any> = never>(baseModel: TModelClass, modelProps: TProps, modelOptions?: ModelOptions<TProps, FS, TS>): _Model<InstanceType<TModelClass>, TProps, FS, TS> & {
|
|
47
|
+
[P in Exclude<keyof TModelClass, "prototype">]: TModelClass[P];
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Base abstract class for models.
|
|
51
|
+
*
|
|
52
|
+
* Never override the constructor, use `onInit` or `onAttachedToRootStore` instead.
|
|
53
|
+
*
|
|
54
|
+
* @typeparam TProps Model properties type.
|
|
55
|
+
* @param fnModelProps Function that generates model properties.
|
|
56
|
+
* @param modelOptions Model options.
|
|
57
|
+
*/
|
|
58
|
+
export declare function Model<TProps extends ModelProps, A extends [], FS extends Record<string, any> = never, TS extends Record<string, any> = never>(fnModelProps: (...args: A) => TProps, modelOptions?: ModelOptions<TProps, FS, TS>): _Model<unknown, TProps, FS, TS>;
|
|
59
|
+
/**
|
|
60
|
+
* Base abstract class for models.
|
|
61
|
+
*
|
|
62
|
+
* Never override the constructor, use `onInit` or `onAttachedToRootStore` instead.
|
|
63
|
+
*
|
|
64
|
+
* @typeparam TProps Model properties type.
|
|
65
|
+
* @param modelProps Model properties.
|
|
66
|
+
* @param modelOptions Model options.
|
|
67
|
+
*/
|
|
68
|
+
export declare function Model<TProps extends ModelProps, FS extends Record<string, any> = never, TS extends Record<string, any> = never>(modelProps: TProps, modelOptions?: ModelOptions<TProps, FS, TS>): _Model<unknown, TProps, FS, TS>;
|
|
69
|
+
/**
|
|
70
|
+
* Model options.
|
|
71
|
+
*/
|
|
72
|
+
export interface ModelOptions<TProps extends ModelProps, FS, TS> {
|
|
73
|
+
/**
|
|
74
|
+
* A value type will be cloned automatically when being attached to a new tree.
|
|
75
|
+
* The default is `false`.
|
|
76
|
+
*/
|
|
77
|
+
valueType?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Optional transformation that will be run when converting from a snapshot to the data part of the model.
|
|
80
|
+
* Useful for example to do versioning and keep the data part up to date with the latest version of the model.
|
|
81
|
+
*
|
|
82
|
+
* @param sn The custom input snapshot.
|
|
83
|
+
* @returns An input snapshot that must match the expected model input snapshot.
|
|
84
|
+
*/
|
|
85
|
+
fromSnapshotProcessor?(sn: FS): FromSnapshotDefaultType<TProps>;
|
|
86
|
+
/**
|
|
87
|
+
* Optional transformation that will be run when converting the data part of the model into a snapshot.
|
|
88
|
+
*
|
|
89
|
+
* @param sn The output snapshot.
|
|
90
|
+
* @param modelInstance The model instance.
|
|
91
|
+
* @returns a custom output snapshot.
|
|
92
|
+
*/
|
|
93
|
+
toSnapshotProcessor?(sn: ToSnapshotDefaultType<TProps>, modelInstance: any): TS;
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ModelClass } from "../modelShared/BaseModelShared";
|
|
2
|
+
import type { AnyType } from "../types/schemas";
|
|
3
|
+
import type { AnyModel } from "./BaseModel";
|
|
4
|
+
/**
|
|
5
|
+
* Associated model metadata.
|
|
6
|
+
*/
|
|
7
|
+
export interface ModelMetadata {
|
|
8
|
+
/**
|
|
9
|
+
* Associated data type for runtime checking (if any).
|
|
10
|
+
*/
|
|
11
|
+
dataType?: AnyType;
|
|
12
|
+
/**
|
|
13
|
+
* Property used as model id.
|
|
14
|
+
*/
|
|
15
|
+
modelIdProperty: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* A value type will be cloned automatically when being attached to a new tree.
|
|
18
|
+
*/
|
|
19
|
+
valueType: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the associated metadata for a model instance or class.
|
|
23
|
+
*
|
|
24
|
+
* @param modelClassOrInstance Model class or instance.
|
|
25
|
+
* @returns The associated metadata.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getModelMetadata(modelClassOrInstance: AnyModel | ModelClass<AnyModel>): ModelMetadata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AnyDataModel } from "../dataModel/BaseDataModel";
|
|
2
|
+
import type { AnyModel } from "../model/BaseModel";
|
|
3
|
+
import type { modelTypeKey } from "../model/metadata";
|
|
4
|
+
import type { Flatten, IsNeverType } from "../utils/types";
|
|
5
|
+
import type { ModelPropsToCreationData, ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData } from "./prop";
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
9
|
+
export declare const propsTypeSymbol: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
export declare const fromSnapshotOverrideTypeSymbol: unique symbol;
|
|
14
|
+
/**
|
|
15
|
+
* @ignore
|
|
16
|
+
*/
|
|
17
|
+
export declare const toSnapshotOverrideTypeSymbol: unique symbol;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the instance type of a model class.
|
|
20
|
+
*/
|
|
21
|
+
export declare type ModelClass<M extends AnyModel | AnyDataModel> = {
|
|
22
|
+
new (initialData: any): M;
|
|
23
|
+
fromSnapshotProcessor?(sn: any): any;
|
|
24
|
+
toSnapshotProcessor?(sn: any, modelInstance: any): any;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Extracts the instance type of an abstract model class.
|
|
28
|
+
*/
|
|
29
|
+
export declare type AbstractModelClass<M extends AnyModel | AnyDataModel> = abstract new (initialData: any) => M;
|
|
30
|
+
/**
|
|
31
|
+
* The props of a model.
|
|
32
|
+
*/
|
|
33
|
+
export declare type ModelPropsOf<M extends AnyModel | AnyDataModel> = M[typeof propsTypeSymbol];
|
|
34
|
+
/**
|
|
35
|
+
* The data type of a model.
|
|
36
|
+
*/
|
|
37
|
+
export declare type ModelData<M extends AnyModel | AnyDataModel> = Flatten<M["$"]>;
|
|
38
|
+
/**
|
|
39
|
+
* The creation data type of a model.
|
|
40
|
+
*/
|
|
41
|
+
export declare type ModelCreationData<M extends AnyModel | AnyDataModel> = ModelPropsToCreationData<ModelPropsOf<M>>;
|
|
42
|
+
/**
|
|
43
|
+
* The transformed data type of a model.
|
|
44
|
+
*/
|
|
45
|
+
export declare type ModelTransformedData<M extends AnyModel | AnyDataModel> = ModelPropsToTransformedData<ModelPropsOf<M>>;
|
|
46
|
+
/**
|
|
47
|
+
* The transformed creation data type of a model.
|
|
48
|
+
*/
|
|
49
|
+
export declare type ModelTransformedCreationData<M extends AnyModel | AnyDataModel> = ModelPropsToTransformedCreationData<ModelPropsOf<M>>;
|
|
50
|
+
/**
|
|
51
|
+
* The from snapshot type of a model.
|
|
52
|
+
*
|
|
53
|
+
* @deprecated Use SnapshotInOf<Model> instead.
|
|
54
|
+
*/
|
|
55
|
+
export declare type ModelFromSnapshot<M extends AnyModel> = IsNeverType<M[typeof fromSnapshotOverrideTypeSymbol], ModelPropsToSnapshotCreationData<ModelPropsOf<M>>, M[typeof fromSnapshotOverrideTypeSymbol]> & {
|
|
56
|
+
[modelTypeKey]?: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The to snapshot type of a model.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Use SnapshotOutOf<Model> instead.
|
|
62
|
+
*/
|
|
63
|
+
export declare type ModelToSnapshot<M extends AnyModel> = IsNeverType<M[typeof toSnapshotOverrideTypeSymbol], ModelPropsToSnapshotData<ModelPropsOf<M>>, M[typeof toSnapshotOverrideTypeSymbol]> & {
|
|
64
|
+
[modelTypeKey]?: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Tricks TypeScript into accepting a particular kind of generic class as a parameter for `ExtendedModel`.
|
|
68
|
+
* Does nothing in runtime.
|
|
69
|
+
*
|
|
70
|
+
* @typeparam T Generic model class type.
|
|
71
|
+
* @param type Generic model class.
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
export declare function modelClass<T extends AnyModel | AnyDataModel>(type: {
|
|
75
|
+
prototype: T;
|
|
76
|
+
}): ModelClass<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AnyDataModel } from "../dataModel/BaseDataModel";
|
|
2
|
+
import { AnyModel } from "../model/BaseModel";
|
|
3
|
+
import { ModelClass } from "./BaseModelShared";
|
|
4
|
+
import { ModelProps } from "./prop";
|
|
5
|
+
declare type FromSnapshotProcessorFn = (sn: any) => any;
|
|
6
|
+
declare type ToSnapshotProcessorFn = (sn: any, instance: any) => any;
|
|
7
|
+
export declare function sharedInternalModel<TProps extends ModelProps, TBaseModel extends AnyModel | AnyDataModel>({ modelProps, baseModel, type, valueType, fromSnapshotProcessor, toSnapshotProcessor, }: {
|
|
8
|
+
modelProps: TProps;
|
|
9
|
+
baseModel: ModelClass<TBaseModel> | undefined;
|
|
10
|
+
type: "class" | "data";
|
|
11
|
+
valueType: boolean;
|
|
12
|
+
fromSnapshotProcessor: FromSnapshotProcessorFn | undefined;
|
|
13
|
+
toSnapshotProcessor: ToSnapshotProcessorFn | undefined;
|
|
14
|
+
}): any;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnyDataModel } from "../dataModel/BaseDataModel";
|
|
2
|
+
import type { AnyModel } from "../model/BaseModel";
|
|
3
|
+
import { ModelClass } from "../modelShared/BaseModelShared";
|
|
4
|
+
/**
|
|
5
|
+
* Decorator that marks this class (which MUST inherit from the `Model` or `DataModel` abstract classes)
|
|
6
|
+
* as a model.
|
|
7
|
+
*
|
|
8
|
+
* @param name Unique name for the model type. Note that this name must be unique for your whole
|
|
9
|
+
* application, so it is usually a good idea to use some prefix unique to your application domain.
|
|
10
|
+
*/
|
|
11
|
+
export declare const model: (name: string) => <MC extends ModelClass<AnyModel | AnyDataModel>>(clazz: MC) => MC;
|
|
12
|
+
/**
|
|
13
|
+
* Marks a class (which MUST inherit from the `Model` abstract class)
|
|
14
|
+
* as a model and decorates some of its methods/properties.
|
|
15
|
+
*
|
|
16
|
+
* @param name Unique name for the model type. Note that this name must be unique for your whole
|
|
17
|
+
* application, so it is usually a good idea to use some prefix unique to your application domain.
|
|
18
|
+
* If you don't want to assign a name yet (e.g. for a base model) pass `undefined`.
|
|
19
|
+
* @param clazz Model class.
|
|
20
|
+
* @param decorators Decorators.
|
|
21
|
+
*/
|
|
22
|
+
export declare function decoratedModel<M, MC extends abstract new (...ags: any) => M>(name: string | undefined, clazz: MC, decorators: {
|
|
23
|
+
[k in keyof M]?: ((...args: any[]) => any) | ReadonlyArray<(...args: any[]) => any>;
|
|
24
|
+
}): MC;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AnyDataModel } from "../dataModel/BaseDataModel";
|
|
2
|
+
import type { AnyModel } from "../model/BaseModel";
|
|
3
|
+
import type { ModelClass } from "../modelShared/BaseModelShared";
|
|
4
|
+
export declare function applyModelInitializers(modelClass: ModelClass<AnyModel | AnyDataModel>, modelObj: any): void;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type { SnapshotInOf, SnapshotOutOf } from "../snapshot/SnapshotOf";
|
|
2
|
+
import type { LateTypeChecker, TypeChecker } from "../types/TypeChecker";
|
|
3
|
+
import type { Flatten, IsNeverType, IsOptionalValue } from "../utils/types";
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export declare const noDefaultValue: unique symbol;
|
|
8
|
+
/**
|
|
9
|
+
* A model property.
|
|
10
|
+
*/
|
|
11
|
+
export interface ModelProp<TPropValue, TPropCreationValue, TTransformedValue, TTransformedCreationValue, TIsRequired, TIsId extends boolean = false, THasSetter = never, TFromSnapshotOverride = never, TToSnapshotOverride = never> {
|
|
12
|
+
_internal: {
|
|
13
|
+
$valueType: TPropValue;
|
|
14
|
+
$creationValueType: TPropCreationValue;
|
|
15
|
+
$transformedValueType: TTransformedValue;
|
|
16
|
+
$transformedCreationValueType: TTransformedCreationValue;
|
|
17
|
+
$isRequired: TIsRequired;
|
|
18
|
+
$isId: TIsId;
|
|
19
|
+
$hasSetter: THasSetter;
|
|
20
|
+
$fromSnapshotOverride: TFromSnapshotOverride;
|
|
21
|
+
$toSnapshotOverride: TToSnapshotOverride;
|
|
22
|
+
defaultFn: (() => TPropValue) | typeof noDefaultValue;
|
|
23
|
+
defaultValue: TPropValue | typeof noDefaultValue;
|
|
24
|
+
typeChecker: TypeChecker | LateTypeChecker | undefined;
|
|
25
|
+
setter: boolean | "assign";
|
|
26
|
+
isId: boolean;
|
|
27
|
+
transform: {
|
|
28
|
+
transform(original: unknown, model: object, propName: PropertyKey, setOriginalValue: (newOriginalValue: unknown) => void): unknown;
|
|
29
|
+
untransform(transformed: unknown, model: object, propName: PropertyKey): unknown;
|
|
30
|
+
} | undefined;
|
|
31
|
+
fromSnapshotProcessor?(sn: unknown): unknown;
|
|
32
|
+
toSnapshotProcessor?(sn: unknown): unknown;
|
|
33
|
+
};
|
|
34
|
+
withSetter(): ModelProp<TPropValue, TPropCreationValue, TTransformedValue, TTransformedCreationValue, TIsRequired, TIsId, string, TFromSnapshotOverride, TToSnapshotOverride>;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated Setter methods are preferred.
|
|
37
|
+
*/
|
|
38
|
+
withSetter(mode: "assign"): ModelProp<TPropValue, TPropCreationValue, TTransformedValue, TTransformedCreationValue, TIsRequired, TIsId, string, TFromSnapshotOverride, TToSnapshotOverride>;
|
|
39
|
+
/**
|
|
40
|
+
* Sets a transform for the property instance value.
|
|
41
|
+
*
|
|
42
|
+
* @typeparam TTV Transformed value type.
|
|
43
|
+
* @param transform Transform to be used.
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
withTransform<TTV>(transform: ModelPropTransform<NonNullable<TPropValue>, TTV>): ModelProp<TPropValue, TPropCreationValue, TTV | Extract<TPropValue, null | undefined>, TTV | Extract<TPropCreationValue, null | undefined>, TIsRequired, TIsId, THasSetter, TFromSnapshotOverride, TToSnapshotOverride>;
|
|
47
|
+
withSnapshotProcessor<FS = TFromSnapshotOverride, TS = TToSnapshotOverride, This extends AnyModelProp = this>(processor: {
|
|
48
|
+
fromSnapshot?(sn: FS): ModelPropFromSnapshot<This>;
|
|
49
|
+
toSnapshot?(sn: ModelPropToSnapshot<This>): TS;
|
|
50
|
+
}): ModelProp<TPropValue, TPropCreationValue, TTransformedValue, TTransformedCreationValue, TIsRequired, TIsId, THasSetter, FS, TS>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The snapshot in type of a model property.
|
|
54
|
+
*/
|
|
55
|
+
export declare type ModelPropFromSnapshot<MP extends AnyModelProp> = IsNeverType<MP["_internal"]["$fromSnapshotOverride"], SnapshotInOf<MP["_internal"]["$creationValueType"]>, MP["_internal"]["$fromSnapshotOverride"]>;
|
|
56
|
+
/**
|
|
57
|
+
* The snapshot out type of a model property.
|
|
58
|
+
*/
|
|
59
|
+
export declare type ModelPropToSnapshot<MP extends AnyModelProp> = IsNeverType<MP["_internal"]["$toSnapshotOverride"], SnapshotOutOf<MP["_internal"]["$valueType"]>, MP["_internal"]["$toSnapshotOverride"]>;
|
|
60
|
+
/**
|
|
61
|
+
* A model prop transform.
|
|
62
|
+
*/
|
|
63
|
+
export interface ModelPropTransform<TOriginal, TTransformed> {
|
|
64
|
+
transform(params: {
|
|
65
|
+
originalValue: TOriginal;
|
|
66
|
+
cachedTransformedValue: TTransformed | undefined;
|
|
67
|
+
setOriginalValue(value: TOriginal): void;
|
|
68
|
+
}): TTransformed;
|
|
69
|
+
untransform(params: {
|
|
70
|
+
transformedValue: TTransformed;
|
|
71
|
+
cacheTransformedValue(): void;
|
|
72
|
+
}): TOriginal;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Any model property.
|
|
76
|
+
*/
|
|
77
|
+
export declare type AnyModelProp = ModelProp<any, any, any, any, any, any, any, any, any>;
|
|
78
|
+
/**
|
|
79
|
+
* Model properties.
|
|
80
|
+
*/
|
|
81
|
+
export interface ModelProps {
|
|
82
|
+
[k: string]: AnyModelProp;
|
|
83
|
+
}
|
|
84
|
+
export declare type RequiredModelProps<MP extends ModelProps> = {
|
|
85
|
+
[K in keyof MP]: MP[K]["_internal"]["$isRequired"] & K;
|
|
86
|
+
}[keyof MP];
|
|
87
|
+
export declare type ModelPropsToData<MP extends ModelProps> = Flatten<{
|
|
88
|
+
[k in keyof MP]: MP[k]["_internal"]["$valueType"];
|
|
89
|
+
}>;
|
|
90
|
+
export declare type ModelPropsToSnapshotData<MP extends ModelProps> = Flatten<{
|
|
91
|
+
[k in keyof MP]: ModelPropToSnapshot<MP[k]> extends infer R ? R : never;
|
|
92
|
+
}>;
|
|
93
|
+
export declare type ModelPropsToCreationData<MP extends ModelProps> = {
|
|
94
|
+
[k in keyof MP]?: MP[k]["_internal"]["$creationValueType"];
|
|
95
|
+
} & {
|
|
96
|
+
[k in RequiredModelProps<MP>]: MP[k]["_internal"]["$creationValueType"];
|
|
97
|
+
};
|
|
98
|
+
export declare type ModelPropsToSnapshotCreationData<MP extends ModelProps> = Flatten<{
|
|
99
|
+
[k in keyof MP]?: ModelPropFromSnapshot<MP[k]> extends infer R ? R : never;
|
|
100
|
+
} & {
|
|
101
|
+
[k in {
|
|
102
|
+
[K in keyof MP]: IsNeverType<MP[K]["_internal"]["$fromSnapshotOverride"], MP[K]["_internal"]["$isRequired"] & K, // no override
|
|
103
|
+
IsOptionalValue<MP[K]["_internal"]["$fromSnapshotOverride"], never, K>>;
|
|
104
|
+
}[keyof MP]]: ModelPropFromSnapshot<MP[k]> extends infer R ? R : never;
|
|
105
|
+
}>;
|
|
106
|
+
export declare type ModelPropsToTransformedData<MP extends ModelProps> = Flatten<{
|
|
107
|
+
[k in keyof MP]: MP[k]["_internal"]["$transformedValueType"];
|
|
108
|
+
}>;
|
|
109
|
+
export declare type ModelPropsToTransformedCreationData<MP extends ModelProps> = {
|
|
110
|
+
[k in keyof MP]?: MP[k]["_internal"]["$transformedCreationValueType"];
|
|
111
|
+
} & {
|
|
112
|
+
[k in RequiredModelProps<MP>]: MP[k]["_internal"]["$transformedCreationValueType"];
|
|
113
|
+
};
|
|
114
|
+
export declare type ModelPropsToSetter<MP extends ModelProps> = Flatten<{
|
|
115
|
+
[k in keyof MP as MP[k]["_internal"]["$hasSetter"] & `set${Capitalize<k & string>}`]: (value: MP[k]["_internal"]["$transformedValueType"]) => void;
|
|
116
|
+
}>;
|
|
117
|
+
export declare type ModelIdProp = ModelProp<string, string | undefined, string, string | undefined, never, // not required
|
|
118
|
+
true>;
|
|
119
|
+
/**
|
|
120
|
+
* A property that will be used as model id, accessible through $modelId.
|
|
121
|
+
* Can only be used in models and there can be only one per model.
|
|
122
|
+
*/
|
|
123
|
+
export declare const idProp: ModelIdProp;
|
|
124
|
+
/**
|
|
125
|
+
* @ignore
|
|
126
|
+
*/
|
|
127
|
+
export declare type OnlyPrimitives<T> = Exclude<T, object>;
|
|
128
|
+
/**
|
|
129
|
+
* A model prop that maybe / maybe not is optional, depending on if the value can take undefined.
|
|
130
|
+
*/
|
|
131
|
+
export declare type MaybeOptionalModelProp<TPropValue> = ModelProp<TPropValue, TPropValue, TPropValue, TPropValue, IsOptionalValue<TPropValue, never, string>>;
|
|
132
|
+
/**
|
|
133
|
+
* A model prop that is definitely optional.
|
|
134
|
+
*/
|
|
135
|
+
export declare type OptionalModelProp<TPropValue> = ModelProp<TPropValue, TPropValue | null | undefined, TPropValue, TPropValue | null | undefined, never>;
|
|
136
|
+
/**
|
|
137
|
+
* Defines a model property, with an optional function to generate a default value
|
|
138
|
+
* if the input snapshot / model creation data is `null` or `undefined`.
|
|
139
|
+
*
|
|
140
|
+
* Example:
|
|
141
|
+
* ```ts
|
|
142
|
+
* x: prop(() => 10) // an optional number, with a default value of 10
|
|
143
|
+
* x: prop<number[]>(() => []) // an optional number array, with a default empty array
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @typeparam TValue Value type.
|
|
147
|
+
* @param defaultFn Default value generator function.
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
150
|
+
export declare function prop<TValue>(defaultFn: () => TValue): OptionalModelProp<TValue>;
|
|
151
|
+
/**
|
|
152
|
+
* Defines a model property, with an optional default value
|
|
153
|
+
* if the input snapshot / model creation data is `null` or `undefined`.
|
|
154
|
+
* You should only use this with primitive values and never with object values
|
|
155
|
+
* (array, model, object, etc).
|
|
156
|
+
*
|
|
157
|
+
* Example:
|
|
158
|
+
* ```ts
|
|
159
|
+
* x: prop(10) // an optional number, with a default value of 10
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @typeparam TValue Value type.
|
|
163
|
+
* @param defaultValue Default primitive value.
|
|
164
|
+
* @returns
|
|
165
|
+
*/
|
|
166
|
+
export declare function prop<TValue>(defaultValue: OnlyPrimitives<TValue>): OptionalModelProp<TValue>;
|
|
167
|
+
/**
|
|
168
|
+
* Defines a model property with no default value.
|
|
169
|
+
*
|
|
170
|
+
* Example:
|
|
171
|
+
* ```ts
|
|
172
|
+
* x: prop<number>() // a required number
|
|
173
|
+
* x: prop<number | undefined>() // an optional number, which defaults to undefined
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @typeparam TValue Value type.
|
|
177
|
+
* @returns
|
|
178
|
+
*/
|
|
179
|
+
export declare function prop<TValue>(): MaybeOptionalModelProp<TValue>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detaches a given object from a tree.
|
|
3
|
+
* If the parent is an object / model, detaching will delete the property.
|
|
4
|
+
* If the parent is an array detaching will remove the node by splicing it.
|
|
5
|
+
* If there's no parent it will throw.
|
|
6
|
+
*
|
|
7
|
+
* @param node Object to be detached.
|
|
8
|
+
*/
|
|
9
|
+
export declare function detach(node: object): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterates through all children and collects them in a set if the
|
|
3
|
+
* given predicate matches.
|
|
4
|
+
*
|
|
5
|
+
* @param root Root object to get the matching children from.
|
|
6
|
+
* @param predicate Function that will be run for every child of the root object.
|
|
7
|
+
* @param [options] An optional object with the `deep` option (defaults to `false`) set to `true` to
|
|
8
|
+
* get the children deeply or `false` to get them shallowly.
|
|
9
|
+
* @returns A readonly observable set with the matching children.
|
|
10
|
+
*/
|
|
11
|
+
export declare function findChildren<T extends object = any>(root: object, predicate: (node: object) => boolean, options?: {
|
|
12
|
+
deep?: boolean;
|
|
13
|
+
}): ReadonlySet<T>;
|