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,22 @@
|
|
|
1
|
+
import { Path } from "../parent/pathTypes";
|
|
2
|
+
/**
|
|
3
|
+
* A type checking error.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TypeCheckError {
|
|
6
|
+
readonly path: Path;
|
|
7
|
+
readonly expectedTypeName: string;
|
|
8
|
+
readonly actualValue: any;
|
|
9
|
+
/**
|
|
10
|
+
* Creates an instance of TypeError.
|
|
11
|
+
* @param path Sub-path where the error occured.
|
|
12
|
+
* @param expectedTypeName Name of the expected type.
|
|
13
|
+
* @param actualValue Actual value.
|
|
14
|
+
*/
|
|
15
|
+
constructor(path: Path, expectedTypeName: string, actualValue: any);
|
|
16
|
+
/**
|
|
17
|
+
* Throws the type check error as an actual error.
|
|
18
|
+
*
|
|
19
|
+
* @param typeCheckedValue Usually the value where the type check was invoked.
|
|
20
|
+
*/
|
|
21
|
+
throw(typeCheckedValue: any): never;
|
|
22
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AnyStandardType, AnyType, ArrayType } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
|
+
/**
|
|
4
|
+
* A type that represents an array of values of a given type.
|
|
5
|
+
*
|
|
6
|
+
* Example:
|
|
7
|
+
* ```ts
|
|
8
|
+
* const numberArrayType = types.array(types.number)
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @typeparam T Item type.
|
|
12
|
+
* @param itemType Type of inner items.
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function typesArray<T extends AnyType>(itemType: T): ArrayType<T[]>;
|
|
16
|
+
/**
|
|
17
|
+
* `types.array` type info.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ArrayTypeInfo extends TypeInfo {
|
|
20
|
+
readonly itemType: AnyStandardType;
|
|
21
|
+
get itemTypeInfo(): TypeInfo;
|
|
22
|
+
constructor(thisType: AnyStandardType, itemType: AnyStandardType);
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnyStandardType, AnyType, ArrayType } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
|
+
/**
|
|
4
|
+
* A type that represents an tuple of values of a given type.
|
|
5
|
+
*
|
|
6
|
+
* Example:
|
|
7
|
+
* ```ts
|
|
8
|
+
* const stringNumberTupleType = types.tuple(types.string, types.number)
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @typeparam T Item types.
|
|
12
|
+
* @param itemType Type of inner items.
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function typesTuple<T extends AnyType[]>(...itemTypes: T): ArrayType<T>;
|
|
16
|
+
/**
|
|
17
|
+
* `types.tuple` type info.
|
|
18
|
+
*/
|
|
19
|
+
export declare class TupleTypeInfo extends TypeInfo {
|
|
20
|
+
readonly itemTypes: ReadonlyArray<AnyStandardType>;
|
|
21
|
+
private _itemTypeInfos;
|
|
22
|
+
get itemTypeInfos(): ReadonlyArray<TypeInfo>;
|
|
23
|
+
constructor(thisType: AnyStandardType, itemTypes: ReadonlyArray<AnyStandardType>);
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyType } from "./schemas";
|
|
2
|
+
import type { TypeInfo } from "./TypeChecker";
|
|
3
|
+
/**
|
|
4
|
+
* Gets the type info of a given type.
|
|
5
|
+
*
|
|
6
|
+
* @param type Type to get the info from.
|
|
7
|
+
* @returns The type info.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTypeInfo(type: AnyType): TypeInfo;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ArraySet } from "../../wrappers/ArraySet";
|
|
2
|
+
import type { AnyStandardType, AnyType, ModelType, TypeToData } from "../schemas";
|
|
3
|
+
import { TypeInfo } from "../TypeChecker";
|
|
4
|
+
/**
|
|
5
|
+
* A type that represents an array backed set ArraySet.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```ts
|
|
9
|
+
* const numberSetType = types.arraySet(types.number)
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @typeparam T Value type.
|
|
13
|
+
* @param valueType Value type.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function typesArraySet<T extends AnyType>(valueType: T): ModelType<ArraySet<TypeToData<T>>>;
|
|
17
|
+
/**
|
|
18
|
+
* `types.arraySet` type info.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ArraySetTypeInfo extends TypeInfo {
|
|
21
|
+
readonly valueType: AnyStandardType;
|
|
22
|
+
get valueTypeInfo(): TypeInfo;
|
|
23
|
+
constructor(originalType: AnyStandardType, valueType: AnyStandardType);
|
|
24
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AnyDataModel } from "../../dataModel/BaseDataModel";
|
|
2
|
+
import type { ModelClass, ModelData } from "../../modelShared/BaseModelShared";
|
|
3
|
+
import type { AnyStandardType, IdentityType } from "../schemas";
|
|
4
|
+
import { TypeInfo } from "../TypeChecker";
|
|
5
|
+
declare type _Class<T> = abstract new (...args: any[]) => T;
|
|
6
|
+
declare type _ClassOrObject<M, K> = K extends M ? object : _Class<K> | (() => _Class<K>);
|
|
7
|
+
/**
|
|
8
|
+
* A type that represents a data model data.
|
|
9
|
+
* The type referenced in the model decorator will be used for type checking.
|
|
10
|
+
*
|
|
11
|
+
* Example:
|
|
12
|
+
* ```ts
|
|
13
|
+
* const someDataModelDataType = types.dataModelData(SomeModel)
|
|
14
|
+
* // or for recursive models
|
|
15
|
+
* const someDataModelDataType = types.dataModelData<SomeModel>(() => SomeModel)
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @typeparam M Data model type.
|
|
19
|
+
* @param modelClass Model class.
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function typesDataModelData<M = never, K = M>(modelClass: _ClassOrObject<M, K>): IdentityType<ModelData<K extends M ? (M extends AnyDataModel ? M : never) : K extends AnyDataModel ? K : never>>;
|
|
23
|
+
/**
|
|
24
|
+
* `types.dataModelData` type info for a model props.
|
|
25
|
+
*/
|
|
26
|
+
export interface DataModelDataTypeInfoProps {
|
|
27
|
+
readonly [propName: string]: Readonly<{
|
|
28
|
+
type: AnyStandardType | undefined;
|
|
29
|
+
typeInfo: TypeInfo | undefined;
|
|
30
|
+
hasDefault: boolean;
|
|
31
|
+
default: any;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `types.dataModelData` type info.
|
|
36
|
+
*/
|
|
37
|
+
export declare class DataModelDataTypeInfo extends TypeInfo {
|
|
38
|
+
readonly modelClass: ModelClass<AnyDataModel>;
|
|
39
|
+
private _props;
|
|
40
|
+
get props(): DataModelDataTypeInfoProps;
|
|
41
|
+
get modelType(): string;
|
|
42
|
+
constructor(thisType: AnyStandardType, modelClass: ModelClass<AnyDataModel>);
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AnyModel } from "../../model/BaseModel";
|
|
2
|
+
import type { ModelClass } from "../../modelShared/BaseModelShared";
|
|
3
|
+
import type { AnyStandardType, ModelType } from "../schemas";
|
|
4
|
+
import { TypeInfo } from "../TypeChecker";
|
|
5
|
+
declare type _Class<T> = abstract new (...args: any[]) => T;
|
|
6
|
+
declare type _ClassOrObject<M, K> = K extends M ? object : _Class<K> | (() => _Class<K>);
|
|
7
|
+
/**
|
|
8
|
+
* A type that represents a model. The type referenced in the model decorator will be used for type checking.
|
|
9
|
+
*
|
|
10
|
+
* Example:
|
|
11
|
+
* ```ts
|
|
12
|
+
* const someModelType = types.model(SomeModel)
|
|
13
|
+
* // or for recursive models
|
|
14
|
+
* const someModelType = types.model<SomeModel>(() => SomeModel)
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @typeparam M Model type.
|
|
18
|
+
* @param modelClass Model class.
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function typesModel<M = never, K = M>(modelClass: _ClassOrObject<M, K>): ModelType<K>;
|
|
22
|
+
/**
|
|
23
|
+
* `types.model` type info for a model props.
|
|
24
|
+
*/
|
|
25
|
+
export interface ModelTypeInfoProps {
|
|
26
|
+
readonly [propName: string]: Readonly<{
|
|
27
|
+
type: AnyStandardType | undefined;
|
|
28
|
+
typeInfo: TypeInfo | undefined;
|
|
29
|
+
hasDefault: boolean;
|
|
30
|
+
default: any;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `types.model` type info.
|
|
35
|
+
*/
|
|
36
|
+
export declare class ModelTypeInfo extends TypeInfo {
|
|
37
|
+
readonly modelClass: ModelClass<AnyModel>;
|
|
38
|
+
private _props;
|
|
39
|
+
get props(): ModelTypeInfoProps;
|
|
40
|
+
get modelType(): string;
|
|
41
|
+
constructor(thisType: AnyStandardType, modelClass: ModelClass<AnyModel>);
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Frozen } from "../../frozen/Frozen";
|
|
2
|
+
import type { AnyStandardType, AnyType, ModelType, ObjectTypeFunction, TypeToData } from "../schemas";
|
|
3
|
+
import { TypeInfo } from "../TypeChecker";
|
|
4
|
+
/**
|
|
5
|
+
* A type that represents a plain object.
|
|
6
|
+
* Note that the parameter must be a function that returns an object. This is done so objects can support self / cross types.
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
* ```ts
|
|
10
|
+
* // notice the ({ ... }), not just { ... }
|
|
11
|
+
* const pointType = types.object(() => ({
|
|
12
|
+
* x: types.number,
|
|
13
|
+
* y: types.number
|
|
14
|
+
* }))
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @typeparam T Type.
|
|
18
|
+
* @param objectFunction Function that generates an object with types.
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function typesObject<T>(objectFunction: T): T;
|
|
22
|
+
/**
|
|
23
|
+
* `types.object` type info for an object props.
|
|
24
|
+
*/
|
|
25
|
+
export interface ObjectTypeInfoProps {
|
|
26
|
+
readonly [propName: string]: Readonly<{
|
|
27
|
+
type: AnyStandardType;
|
|
28
|
+
typeInfo: TypeInfo;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `types.object` type info.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ObjectTypeInfo extends TypeInfo {
|
|
35
|
+
private _objTypeFn;
|
|
36
|
+
private _props;
|
|
37
|
+
get props(): ObjectTypeInfoProps;
|
|
38
|
+
constructor(thisType: AnyStandardType, _objTypeFn: ObjectTypeFunction);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A type that represents frozen data.
|
|
42
|
+
*
|
|
43
|
+
* Example:
|
|
44
|
+
* ```ts
|
|
45
|
+
* const frozenNumberType = types.frozen(types.number)
|
|
46
|
+
* const frozenAnyType = types.frozen(types.unchecked<any>())
|
|
47
|
+
* const frozenNumberArrayType = types.frozen(types.array(types.number))
|
|
48
|
+
* const frozenUncheckedNumberArrayType = types.frozen(types.unchecked<number[]>())
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @typeparam T Type.
|
|
52
|
+
* @param dataType Type of the frozen data.
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export declare function typesFrozen<T extends AnyType>(dataType: T): ModelType<Frozen<TypeToData<T>>>;
|
|
56
|
+
/**
|
|
57
|
+
* `types.frozen` type info.
|
|
58
|
+
*/
|
|
59
|
+
export declare class FrozenTypeInfo extends TypeInfo {
|
|
60
|
+
readonly dataType: AnyStandardType;
|
|
61
|
+
get dataTypeInfo(): TypeInfo;
|
|
62
|
+
constructor(thisType: AnyStandardType, dataType: AnyStandardType);
|
|
63
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ObjectMap } from "../../wrappers/ObjectMap";
|
|
2
|
+
import type { AnyStandardType, AnyType, ModelType, TypeToData } from "../schemas";
|
|
3
|
+
import { TypeInfo } from "../TypeChecker";
|
|
4
|
+
/**
|
|
5
|
+
* A type that represents an object-like map ObjectMap.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```ts
|
|
9
|
+
* const numberMapType = types.objectMap(types.number)
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @typeparam T Value type.
|
|
13
|
+
* @param valueType Value type.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function typesObjectMap<T extends AnyType>(valueType: T): ModelType<ObjectMap<TypeToData<T>>>;
|
|
17
|
+
/**
|
|
18
|
+
* `types.objectMap` type info.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ObjectMapTypeInfo extends TypeInfo {
|
|
21
|
+
readonly valueType: AnyStandardType;
|
|
22
|
+
get valueTypeInfo(): TypeInfo;
|
|
23
|
+
constructor(thisType: AnyStandardType, valueType: AnyStandardType);
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnyStandardType, AnyType, RecordType } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
|
+
/**
|
|
4
|
+
* A type that represents an object-like map, an object with string keys and values all of a same given type.
|
|
5
|
+
*
|
|
6
|
+
* Example:
|
|
7
|
+
* ```ts
|
|
8
|
+
* // { [k: string]: number }
|
|
9
|
+
* const numberMapType = types.record(types.number)
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @typeparam T Type.
|
|
13
|
+
* @param valueType Type of the values of the object-like map.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function typesRecord<T extends AnyType>(valueType: T): RecordType<T>;
|
|
17
|
+
/**
|
|
18
|
+
* `types.record` type info.
|
|
19
|
+
*/
|
|
20
|
+
export declare class RecordTypeInfo extends TypeInfo {
|
|
21
|
+
readonly valueType: AnyStandardType;
|
|
22
|
+
get valueTypeInfo(): TypeInfo;
|
|
23
|
+
constructor(thisType: AnyStandardType, valueType: AnyStandardType);
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Ref, RefConstructor } from "../../ref/Ref";
|
|
2
|
+
import type { ModelType } from "../schemas";
|
|
3
|
+
import { TypeInfo } from "../TypeChecker";
|
|
4
|
+
/**
|
|
5
|
+
* A type that represents a reference to an object or model.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```ts
|
|
9
|
+
* const refToSomeObject = types.ref(SomeObject)
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @typeparam O Object or model type.
|
|
13
|
+
* @param refConstructor Ref object type.
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function typesRef<O extends object>(refConstructor: RefConstructor<O>): ModelType<Ref<O>>;
|
|
17
|
+
/**
|
|
18
|
+
* `types.ref` type info.
|
|
19
|
+
*/
|
|
20
|
+
export declare class RefTypeInfo extends TypeInfo {
|
|
21
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IdentityType } from "../schemas";
|
|
2
|
+
/**
|
|
3
|
+
* @ignore
|
|
4
|
+
* Enum like object.
|
|
5
|
+
*/
|
|
6
|
+
export interface EnumLike {
|
|
7
|
+
[k: string]: number | string;
|
|
8
|
+
[v: number]: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
* Extract enum values out of a enum object.
|
|
13
|
+
*/
|
|
14
|
+
export declare type EnumValues<E extends EnumLike> = E extends Record<infer _K, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
15
|
+
infer V> ? V : never;
|
|
16
|
+
/**
|
|
17
|
+
* An enum type, based on a TypeScript alike enum object.
|
|
18
|
+
* Syntactic sugar for `types.or(...enum_values.map(types.literal))`
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* ```ts
|
|
22
|
+
* enum Color {
|
|
23
|
+
* Red = "red",
|
|
24
|
+
* Green = "green"
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* const colorType = types.enum(Color)
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @typeparam E Enum type.
|
|
31
|
+
* @param enumObject
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function typesEnum<E extends EnumLike>(enumObject: E): IdentityType<EnumValues<E>>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { PrimitiveValue } from "../../utils/types";
|
|
2
|
+
import type { AnyStandardType, IdentityType } from "../schemas";
|
|
3
|
+
import { TypeInfo } from "../TypeChecker";
|
|
4
|
+
/**
|
|
5
|
+
* A type that represents a certain value of a primitive (for example an *exact* number or string).
|
|
6
|
+
*
|
|
7
|
+
* Example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const hiType = types.literal("hi") // the string with value "hi"
|
|
10
|
+
* const number5Type = types.literal(5) // the number with value 5
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @typeparam T Literal value type.
|
|
14
|
+
* @param literal Literal value.
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function typesLiteral<T extends PrimitiveValue>(literal: T): IdentityType<T>;
|
|
18
|
+
/**
|
|
19
|
+
* `types.literal` type info.
|
|
20
|
+
*/
|
|
21
|
+
export declare class LiteralTypeInfo extends TypeInfo {
|
|
22
|
+
readonly literal: PrimitiveValue;
|
|
23
|
+
constructor(thisType: AnyStandardType, literal: PrimitiveValue);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A type that represents the value undefined.
|
|
27
|
+
* Syntactic sugar for `types.literal(undefined)`.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* types.undefined
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const typesUndefined: IdentityType<undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* A type that represents the value null.
|
|
36
|
+
* Syntactic sugar for `types.literal(null)`.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* types.null
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const typesNull: IdentityType<null>;
|
|
43
|
+
/**
|
|
44
|
+
* A type that represents any boolean value.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* types.boolean
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const typesBoolean: IdentityType<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* `types.boolean` type info.
|
|
53
|
+
*/
|
|
54
|
+
export declare class BooleanTypeInfo extends TypeInfo {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A type that represents any number value.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* types.number
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const typesNumber: IdentityType<number>;
|
|
64
|
+
/**
|
|
65
|
+
* `types.number` type info.
|
|
66
|
+
*/
|
|
67
|
+
export declare class NumberTypeInfo extends TypeInfo {
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A type that represents any string value.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* types.string
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare const typesString: IdentityType<string>;
|
|
77
|
+
/**
|
|
78
|
+
* `types.string` type info.
|
|
79
|
+
*/
|
|
80
|
+
export declare class StringTypeInfo extends TypeInfo {
|
|
81
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type that represents any integer number value.
|
|
3
|
+
* Syntactic sugar for `types.refinement(types.number, n => Number.isInteger(n), "integer")`
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* types.integer
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare const typesInteger: import("..").IdentityType<number>;
|
|
10
|
+
/**
|
|
11
|
+
* A type that represents any string value other than "".
|
|
12
|
+
* Syntactic sugar for `types.refinement(types.string, s => s !== "", "nonEmpty")`
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* types.nonEmptyString
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const typesNonEmptyString: import("..").IdentityType<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { O } from "ts-toolbelt";
|
|
2
|
+
import type { AnyModel } from "../model/BaseModel";
|
|
3
|
+
import type { ModelClass } from "../modelShared/BaseModelShared";
|
|
4
|
+
import type { IsOptionalValue } from "../utils/types";
|
|
5
|
+
export interface Type<Name, Data> {
|
|
6
|
+
/** @ignore */
|
|
7
|
+
$$type: Name;
|
|
8
|
+
/** @ignore */
|
|
9
|
+
$$data: Data;
|
|
10
|
+
}
|
|
11
|
+
export interface IdentityType<Data> extends Type<"identity", Data> {
|
|
12
|
+
}
|
|
13
|
+
export interface ModelType<Model> extends Type<"model", Model> {
|
|
14
|
+
}
|
|
15
|
+
export interface ArrayType<S>// e.g. S = someType[] or [someType, someType]
|
|
16
|
+
extends Type<"array", {
|
|
17
|
+
[k in keyof S]: TypeToData<S[k]> extends infer R ? R : never;
|
|
18
|
+
}> {
|
|
19
|
+
}
|
|
20
|
+
export interface ObjectOfTypes {
|
|
21
|
+
/** @ignore */
|
|
22
|
+
[k: string]: AnyType;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Name of the properties of an object that can be set to undefined, any or unknown
|
|
26
|
+
*/
|
|
27
|
+
declare type UndefinablePropsNames<T> = {
|
|
28
|
+
[K in keyof T]: IsOptionalValue<T[K], K, never>;
|
|
29
|
+
}[keyof T];
|
|
30
|
+
export interface ObjectType<S> extends Type<"object", O.Optional<{
|
|
31
|
+
[k in keyof S]: TypeToData<S[k]> extends infer R ? R : never;
|
|
32
|
+
}, UndefinablePropsNames<{
|
|
33
|
+
[k in keyof S]: TypeToDataOpt<S[k]> extends infer R ? R : never;
|
|
34
|
+
}>>> {
|
|
35
|
+
}
|
|
36
|
+
export interface ObjectTypeFunction {
|
|
37
|
+
(): ObjectOfTypes;
|
|
38
|
+
}
|
|
39
|
+
export interface RecordType<S> extends Type<"record", {
|
|
40
|
+
[k: string]: TypeToData<S> extends infer R ? R : never;
|
|
41
|
+
}> {
|
|
42
|
+
}
|
|
43
|
+
export declare type AnyStandardType = IdentityType<any> | ModelType<any> | ArrayType<any> | ObjectType<any> | RecordType<any> | ObjectTypeFunction;
|
|
44
|
+
export declare type AnyType = null | undefined | AnyNonValueType;
|
|
45
|
+
export declare type AnyNonValueType = ModelClass<AnyModel> | StringConstructor | NumberConstructor | BooleanConstructor | AnyStandardType;
|
|
46
|
+
export declare type TypeToData<S> = S extends ObjectTypeFunction ? ObjectType<ReturnType<S>>["$$data"] extends infer R ? R : never : S extends {
|
|
47
|
+
$$data: infer D;
|
|
48
|
+
} ? D : S extends ModelClass<infer M> ? M : S extends StringConstructor ? string : S extends NumberConstructor ? number : S extends BooleanConstructor ? boolean : S extends null ? null : S extends undefined ? undefined : never;
|
|
49
|
+
/** @ignore */
|
|
50
|
+
export declare type TypeToDataOpt<S> = S extends {
|
|
51
|
+
$$data: infer D;
|
|
52
|
+
} ? D & undefined : never;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { MaybeOptionalModelProp, OptionalModelProp } from "../modelShared/prop";
|
|
2
|
+
import type { AnyType, TypeToData } from "./schemas";
|
|
3
|
+
/**
|
|
4
|
+
* Defines a string model property with a default value.
|
|
5
|
+
* Equivalent to `tProp(types.string, defaultValue)`.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```ts
|
|
9
|
+
* x: tProp("foo") // an optional string that will take the value `"foo"` when undefined.
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param defaultValue Default value.
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function tProp(defaultValue: string): OptionalModelProp<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Defines a number model property with a default value.
|
|
18
|
+
* Equivalent to `tProp(types.number, defaultValue)`.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* ```ts
|
|
22
|
+
* x: tProp(42) // an optional number that will take the value `42` when undefined.
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param defaultValue Default value.
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare function tProp(defaultValue: number): OptionalModelProp<number>;
|
|
29
|
+
/**
|
|
30
|
+
* Defines a boolean model property with a default value.
|
|
31
|
+
* Equivalent to `tProp(types.boolean, defaultValue)`.
|
|
32
|
+
*
|
|
33
|
+
* Example:
|
|
34
|
+
* ```ts
|
|
35
|
+
* x: tProp(true) // an optional boolean that will take the value `true` when undefined.
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param defaultValue Default value.
|
|
39
|
+
* @param options Model property options.
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
export declare function tProp(defaultValue: boolean): OptionalModelProp<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Defines a model property, with an optional function to generate a default value
|
|
45
|
+
* if the input snapshot / model creation data is `null` or `undefined` and with an associated type checker.
|
|
46
|
+
*
|
|
47
|
+
* Example:
|
|
48
|
+
* ```ts
|
|
49
|
+
* x: tProp(types.number, () => 10) // an optional number, with a default value of 10
|
|
50
|
+
* x: tProp(types.array(types.number), () => []) // an optional number array, with a default empty array
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @typeparam TType Type checker type.
|
|
54
|
+
*
|
|
55
|
+
* @param type Type checker.
|
|
56
|
+
* @param defaultFn Default value generator function.
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export declare function tProp<TType extends AnyType>(type: TType, defaultFn: () => TypeToData<TType>): OptionalModelProp<TypeToData<TType>>;
|
|
60
|
+
/**
|
|
61
|
+
* Defines a model property, with an optional default value
|
|
62
|
+
* if the input snapshot / model creation data is `null` or `undefined` and with an associated type checker.
|
|
63
|
+
* You should only use this with primitive values and never with object values
|
|
64
|
+
* (array, model, object, etc).
|
|
65
|
+
*
|
|
66
|
+
* Example:
|
|
67
|
+
* ```ts
|
|
68
|
+
* x: tProp(types.number, 10) // an optional number, with a default value of 10
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @typeparam TType Type checker type.
|
|
72
|
+
*
|
|
73
|
+
* @param type Type checker.
|
|
74
|
+
* @param defaultValue Default value generator function.
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
export declare function tProp<TType extends AnyType>(type: TType, defaultValue: TypeToData<TType>): OptionalModelProp<TypeToData<TType>>;
|
|
78
|
+
/**
|
|
79
|
+
* Defines a model property with no default value and an associated type checker.
|
|
80
|
+
*
|
|
81
|
+
* Example:
|
|
82
|
+
* ```ts
|
|
83
|
+
* x: tProp(types.number) // a required number
|
|
84
|
+
* x: tProp(types.maybe(types.number)) // an optional number, which defaults to undefined
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @typeparam TType Type checker type.
|
|
88
|
+
*
|
|
89
|
+
* @param type Type checker.
|
|
90
|
+
* @returns
|
|
91
|
+
*/
|
|
92
|
+
export declare function tProp<TType extends AnyType>(type: TType): MaybeOptionalModelProp<TypeToData<TType>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnyType, TypeToData } from "./schemas";
|
|
2
|
+
import type { TypeCheckError } from "./TypeCheckError";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a value conforms to a given type.
|
|
5
|
+
*
|
|
6
|
+
* @typeparam T Type.
|
|
7
|
+
* @param type Type to check for.
|
|
8
|
+
* @param value Value to check.
|
|
9
|
+
* @returns A TypeError if the check fails or null if no error.
|
|
10
|
+
*/
|
|
11
|
+
export declare function typeCheck<T extends AnyType>(type: T, value: TypeToData<T>): TypeCheckError | null;
|