mobx-keystone 2.3.0 → 2.4.0
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 +20 -0
- package/dist/mobx-keystone.esm.js +3737 -2722
- package/dist/mobx-keystone.esm.mjs +3737 -2722
- package/dist/mobx-keystone.umd.js +3750 -2721
- package/dist/types/action/CallKind.d.ts +29 -0
- package/dist/types/action/applyAction.d.ts +8 -2
- package/dist/types/action/applyMethodCall.d.ts +1 -1
- package/dist/types/action/index.d.ts +13 -12
- package/dist/types/action/isModelAction.d.ts +1 -1
- package/dist/types/action/middleware.d.ts +1 -1
- package/dist/types/action/resolveCallName.d.ts +1 -0
- package/dist/types/actionMiddlewares/actionSerialization/actionSerialization.d.ts +17 -3
- package/dist/types/actionMiddlewares/actionSerialization/applySerializedAction.d.ts +8 -2
- package/dist/types/actionMiddlewares/actionSerialization/arraySerializer.d.ts +2 -2
- package/dist/types/actionMiddlewares/actionSerialization/core.d.ts +7 -0
- package/dist/types/actionMiddlewares/actionSerialization/dateSerializer.d.ts +1 -1
- package/dist/types/actionMiddlewares/actionSerialization/index.d.ts +3 -3
- package/dist/types/actionMiddlewares/actionSerialization/mapSerializer.d.ts +2 -2
- package/dist/types/actionMiddlewares/actionSerialization/objectPathSerializer.d.ts +2 -2
- package/dist/types/actionMiddlewares/actionSerialization/objectSnapshotSerializer.d.ts +1 -1
- package/dist/types/actionMiddlewares/actionSerialization/plainObjectSerializer.d.ts +1 -1
- package/dist/types/actionMiddlewares/actionSerialization/primitiveSerializer.d.ts +1 -1
- package/dist/types/actionMiddlewares/actionSerialization/setSerializer.d.ts +2 -2
- package/dist/types/actionMiddlewares/actionTrackingMiddleware.d.ts +3 -3
- package/dist/types/actionMiddlewares/index.d.ts +6 -6
- package/dist/types/actionMiddlewares/onActionMiddleware.d.ts +3 -3
- package/dist/types/actionMiddlewares/readonlyMiddleware.d.ts +1 -1
- package/dist/types/actionMiddlewares/transactionMiddleware.d.ts +2 -2
- package/dist/types/actionMiddlewares/undoMiddleware.d.ts +8 -8
- package/dist/types/computedTree/index.d.ts +1 -1
- package/dist/types/context/index.d.ts +1 -1
- package/dist/types/dataModel/BaseDataModel.d.ts +3 -3
- package/dist/types/dataModel/DataModel.d.ts +3 -3
- package/dist/types/dataModel/getDataModelMetadata.d.ts +3 -3
- package/dist/types/dataModel/index.d.ts +4 -4
- package/dist/types/dataModel/utils.d.ts +1 -1
- package/dist/types/deepChange/index.d.ts +1 -1
- package/dist/types/deepChange/onDeepChange.d.ts +1 -1
- package/dist/types/frozen/Frozen.d.ts +1 -1
- package/dist/types/frozen/index.d.ts +1 -1
- package/dist/types/globalConfig/index.d.ts +1 -1
- package/dist/types/index.d.ts +25 -24
- package/dist/types/model/BaseModel.d.ts +5 -5
- package/dist/types/model/Model.d.ts +3 -3
- package/dist/types/model/getModelMetadata.d.ts +3 -3
- package/dist/types/model/index.d.ts +6 -6
- package/dist/types/model/mixins.d.ts +4 -4
- package/dist/types/model/utils.d.ts +4 -4
- package/dist/types/modelShared/BaseModelShared.d.ts +5 -5
- package/dist/types/modelShared/index.d.ts +4 -4
- package/dist/types/modelShared/modelDecorator.d.ts +3 -3
- package/dist/types/modelShared/modelInfo.d.ts +3 -3
- package/dist/types/modelShared/newModel.d.ts +3 -3
- package/dist/types/modelShared/prop.d.ts +3 -3
- package/dist/types/modelShared/sharedInternalModel.d.ts +4 -4
- package/dist/types/parent/findParent.d.ts +1 -1
- package/dist/types/parent/index.d.ts +9 -9
- package/dist/types/parent/path.d.ts +1 -1
- package/dist/types/patch/Patch.d.ts +1 -1
- package/dist/types/patch/applyPatches.d.ts +1 -1
- package/dist/types/patch/emitPatch.d.ts +7 -1
- package/dist/types/patch/index.d.ts +5 -5
- package/dist/types/patch/jsonPatch.d.ts +2 -2
- package/dist/types/patch/patchRecorder.d.ts +2 -2
- package/dist/types/redux/index.d.ts +2 -2
- package/dist/types/redux/redux.d.ts +3 -3
- package/dist/types/ref/Ref.d.ts +3 -3
- package/dist/types/ref/core.d.ts +2 -2
- package/dist/types/ref/customRef.d.ts +2 -2
- package/dist/types/ref/index.d.ts +4 -4
- package/dist/types/ref/rootRef.d.ts +2 -2
- package/dist/types/rootStore/index.d.ts +1 -1
- package/dist/types/serialization/Call.d.ts +55 -0
- package/dist/types/serialization/CallError.d.ts +96 -0
- package/dist/types/serialization/JsonValue.d.ts +6 -0
- package/dist/types/serialization/Serializer.d.ts +84 -0
- package/dist/types/serialization/ValueSerializer.d.ts +88 -0
- package/dist/types/serialization/applyCall.d.ts +54 -0
- package/dist/types/serialization/builtinSerializers.d.ts +49 -0
- package/dist/types/serialization/codec.d.ts +1 -0
- package/dist/types/serialization/index.d.ts +8 -0
- package/dist/types/serialization/references.d.ts +74 -0
- package/dist/types/serialization/resolvedCall.d.ts +1 -0
- package/dist/types/snapshot/SnapshotOf.d.ts +5 -5
- package/dist/types/snapshot/SnapshotProcessingError.d.ts +2 -2
- package/dist/types/snapshot/applySnapshot.d.ts +1 -1
- package/dist/types/snapshot/cloneTreeValue.d.ts +1 -1
- package/dist/types/snapshot/fromSnapshot.d.ts +2 -2
- package/dist/types/snapshot/getSnapshot.d.ts +2 -2
- package/dist/types/snapshot/index.d.ts +8 -8
- package/dist/types/snapshot/onSnapshot.d.ts +1 -1
- package/dist/types/standardActions/index.d.ts +3 -3
- package/dist/types/standardActions/objectActions.d.ts +1 -1
- package/dist/types/transforms/asMap.d.ts +1 -1
- package/dist/types/transforms/asSet.d.ts +2 -2
- package/dist/types/transforms/bigint.d.ts +1 -1
- package/dist/types/transforms/date.d.ts +1 -1
- package/dist/types/transforms/index.d.ts +4 -4
- package/dist/types/treeUtils/draft.d.ts +1 -1
- package/dist/types/treeUtils/index.d.ts +3 -3
- package/dist/types/tweaker/index.d.ts +2 -2
- package/dist/types/tweaker/tweak.d.ts +1 -1
- package/dist/types/types/SnapshotTypeMismatchError.d.ts +2 -2
- package/dist/types/types/TypeCheckError.d.ts +2 -2
- package/dist/types/types/TypeChecker.d.ts +3 -3
- package/dist/types/types/arrayBased/typesArray.d.ts +2 -2
- package/dist/types/types/arrayBased/typesTuple.d.ts +2 -2
- package/dist/types/types/getTypeInfo.d.ts +2 -2
- package/dist/types/types/index.d.ts +7 -7
- package/dist/types/types/objectBased/typesArraySet.d.ts +3 -3
- package/dist/types/types/objectBased/typesDataModelData.d.ts +4 -4
- package/dist/types/types/objectBased/typesModel.d.ts +4 -4
- package/dist/types/types/objectBased/typesObject.d.ts +3 -3
- package/dist/types/types/objectBased/typesObjectMap.d.ts +3 -3
- package/dist/types/types/objectBased/typesRecord.d.ts +2 -2
- package/dist/types/types/objectBased/typesRef.d.ts +3 -3
- package/dist/types/types/primitiveBased/typesEnum.d.ts +1 -1
- package/dist/types/types/primitiveBased/typesPrimitive.d.ts +3 -3
- package/dist/types/types/primitiveBased/typesRefinedPrimitive.d.ts +2 -2
- package/dist/types/types/schemas.d.ts +5 -5
- package/dist/types/types/tProp.d.ts +4 -4
- package/dist/types/types/typeCheck.d.ts +2 -2
- package/dist/types/types/types.d.ts +39 -39
- package/dist/types/types/utility/typeToStoredData.d.ts +2 -2
- package/dist/types/types/utility/typesBigInt.d.ts +1 -1
- package/dist/types/types/utility/typesCodec.d.ts +6 -6
- package/dist/types/types/utility/typesCodecCore.d.ts +4 -4
- package/dist/types/types/utility/typesCodecSupport.d.ts +4 -4
- package/dist/types/types/utility/typesDate.d.ts +2 -2
- package/dist/types/types/utility/typesMap.d.ts +2 -2
- package/dist/types/types/utility/typesMaybe.d.ts +1 -1
- package/dist/types/types/utility/typesOr.d.ts +2 -2
- package/dist/types/types/utility/typesRefinement.d.ts +3 -3
- package/dist/types/types/utility/typesSet.d.ts +3 -3
- package/dist/types/types/utility/typesSkipCheck.d.ts +2 -2
- package/dist/types/types/utility/typesTag.d.ts +2 -2
- package/dist/types/types/utility/typesUnchecked.d.ts +2 -2
- package/dist/types/utils/ModelPool.d.ts +1 -1
- package/dist/types/wrappers/ArraySet.d.ts +1 -1
- package/dist/types/wrappers/ObjectMap.d.ts +1 -1
- package/dist/types/wrappers/asMap.d.ts +1 -1
- package/dist/types/wrappers/asSet.d.ts +1 -1
- package/dist/types/wrappers/index.d.ts +4 -4
- package/package.json +5 -18
- package/src/action/CallKind.ts +29 -0
- package/src/action/applyAction.ts +22 -49
- package/src/action/applySet.ts +21 -1
- package/src/action/index.ts +1 -0
- package/src/action/modelAction.ts +1 -1
- package/src/action/modelFlow.ts +1 -1
- package/src/action/resolveCallName.ts +207 -0
- package/src/actionMiddlewares/actionSerialization/actionSerialization.ts +14 -0
- package/src/actionMiddlewares/actionSerialization/applySerializedAction.ts +6 -0
- package/src/actionMiddlewares/actionSerialization/core.ts +7 -0
- package/src/actionMiddlewares/actionSerialization/index.ts +2 -0
- package/src/actionMiddlewares/actionSerialization/objectPathSerializer.ts +3 -2
- package/src/dataModel/BaseDataModel.ts +5 -5
- package/src/index.ts +1 -0
- package/src/model/BaseModel.ts +7 -6
- package/src/model/mixins.ts +1 -1
- package/src/model/newModel.ts +1 -1
- package/src/modelShared/modelDecorator.ts +4 -6
- package/src/modelShared/modelInfo.ts +2 -1
- package/src/modelShared/sharedInternalModel.ts +1 -1
- package/src/parent/path.ts +45 -12
- package/src/patch/emitPatch.ts +6 -0
- package/src/ref/Ref.ts +1 -1
- package/src/serialization/Call.ts +58 -0
- package/src/serialization/CallError.ts +153 -0
- package/src/serialization/JsonValue.ts +12 -0
- package/src/serialization/Serializer.ts +321 -0
- package/src/serialization/ValueSerializer.ts +98 -0
- package/src/serialization/applyCall.ts +190 -0
- package/src/serialization/builtinSerializers.ts +261 -0
- package/src/serialization/codec.ts +338 -0
- package/src/serialization/index.ts +15 -0
- package/src/serialization/references.ts +225 -0
- package/src/serialization/resolvedCall.ts +169 -0
- package/src/snapshot/SnapshotterAndReconcilerPriority.ts +2 -1
- package/src/snapshot/fromModelSnapshot.ts +1 -1
- package/src/snapshot/fromSnapshot.ts +1 -1
- package/src/standardActions/actions.ts +11 -3
- package/src/transforms/ImmutableDate.ts +19 -19
- package/src/tweaker/tweakArray.ts +1 -1
- package/src/tweaker/tweakFrozen.ts +1 -1
- package/src/tweaker/tweakModel.ts +1 -1
- package/src/tweaker/tweakPlainObject.ts +1 -1
- package/src/types/arrayBased/typesArray.ts +1 -1
- package/src/types/arrayBased/typesTuple.ts +1 -1
- package/src/types/objectBased/typesArraySet.ts +1 -1
- package/src/types/objectBased/typesModel.ts +2 -2
- package/src/types/objectBased/typesObject.ts +1 -1
- package/src/types/objectBased/typesObjectMap.ts +1 -1
- package/src/types/objectBased/typesRecord.ts +1 -1
- package/src/types/objectBased/typesRef.ts +2 -2
- package/src/types/primitiveBased/typesPrimitive.ts +1 -1
- package/src/types/schemas.ts +1 -1
- package/src/types/utility/typesCodecCore.ts +1 -1
- package/src/types/utility/typesCodecSupport.ts +2 -0
- package/src/types/utility/typesOr.ts +2 -2
- package/src/types/utility/typesRefinement.ts +1 -1
- package/src/utils/errorDiagnostics.ts +9 -4
- package/src/utils/index.ts +20 -13
- package/src/wrappers/ArraySet.ts +3 -5
- package/src/wrappers/ObjectMap.ts +3 -5
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { ArrayTypeInfo, typesArray } from
|
|
2
|
-
import { TupleTypeInfo, typesTuple } from
|
|
3
|
-
import { ArraySetTypeInfo, typesArraySet } from
|
|
4
|
-
import { typesDataModelData } from
|
|
5
|
-
import { ModelTypeInfo, ModelTypeInfoProps, typesModel } from
|
|
6
|
-
import { FrozenTypeInfo, ObjectTypeInfo, ObjectTypeInfoProps, typesFrozen, typesObject } from
|
|
7
|
-
import { ObjectMapTypeInfo, typesObjectMap } from
|
|
8
|
-
import { RecordTypeInfo, typesRecord } from
|
|
9
|
-
import { RefTypeInfo, typesRef } from
|
|
10
|
-
import { typesEnum } from
|
|
11
|
-
import { BooleanTypeInfo, LiteralTypeInfo, NumberTypeInfo, StringTypeInfo, typesLiteral } from
|
|
12
|
-
import { AnyType } from
|
|
13
|
-
import { CodecTypeInfo, typesCodec } from
|
|
14
|
-
import { typesMaybe, typesMaybeNull } from
|
|
15
|
-
import { OrTypeInfo, typesOr } from
|
|
16
|
-
import { RefinementTypeInfo, typesRefinement } from
|
|
17
|
-
import { SkipCheckTypeInfo, typesSkipCheck } from
|
|
18
|
-
import { TagTypeInfo, typesTag } from
|
|
19
|
-
import { typesUnchecked, UncheckedTypeInfo } from
|
|
20
|
-
export { getTypeInfo } from
|
|
21
|
-
export { TypeInfo } from
|
|
1
|
+
import { ArrayTypeInfo, typesArray } from "./arrayBased/typesArray";
|
|
2
|
+
import { TupleTypeInfo, typesTuple } from "./arrayBased/typesTuple";
|
|
3
|
+
import { ArraySetTypeInfo, typesArraySet } from "./objectBased/typesArraySet";
|
|
4
|
+
import { typesDataModelData } from "./objectBased/typesDataModelData";
|
|
5
|
+
import { ModelTypeInfo, type ModelTypeInfoProps, typesModel } from "./objectBased/typesModel";
|
|
6
|
+
import { FrozenTypeInfo, ObjectTypeInfo, type ObjectTypeInfoProps, typesFrozen, typesObject } from "./objectBased/typesObject";
|
|
7
|
+
import { ObjectMapTypeInfo, typesObjectMap } from "./objectBased/typesObjectMap";
|
|
8
|
+
import { RecordTypeInfo, typesRecord } from "./objectBased/typesRecord";
|
|
9
|
+
import { RefTypeInfo, typesRef } from "./objectBased/typesRef";
|
|
10
|
+
import { typesEnum } from "./primitiveBased/typesEnum";
|
|
11
|
+
import { BooleanTypeInfo, LiteralTypeInfo, NumberTypeInfo, StringTypeInfo, typesLiteral } from "./primitiveBased/typesPrimitive";
|
|
12
|
+
import type { AnyType } from "./schemas";
|
|
13
|
+
import { CodecTypeInfo, typesCodec } from "./utility/typesCodec";
|
|
14
|
+
import { typesMaybe, typesMaybeNull } from "./utility/typesMaybe";
|
|
15
|
+
import { OrTypeInfo, typesOr } from "./utility/typesOr";
|
|
16
|
+
import { RefinementTypeInfo, typesRefinement } from "./utility/typesRefinement";
|
|
17
|
+
import { SkipCheckTypeInfo, typesSkipCheck } from "./utility/typesSkipCheck";
|
|
18
|
+
import { TagTypeInfo, typesTag } from "./utility/typesTag";
|
|
19
|
+
import { typesUnchecked, UncheckedTypeInfo } from "./utility/typesUnchecked";
|
|
20
|
+
export { getTypeInfo } from "./getTypeInfo";
|
|
21
|
+
export { TypeInfo } from "./TypeChecker";
|
|
22
22
|
export type { ModelTypeInfoProps, ObjectTypeInfoProps };
|
|
23
23
|
export { ArraySetTypeInfo, ArrayTypeInfo, BooleanTypeInfo, CodecTypeInfo, FrozenTypeInfo, LiteralTypeInfo, ModelTypeInfo, NumberTypeInfo, ObjectMapTypeInfo, ObjectTypeInfo, OrTypeInfo, RecordTypeInfo, RefinementTypeInfo, RefTypeInfo, SkipCheckTypeInfo, StringTypeInfo, TagTypeInfo, TupleTypeInfo, UncheckedTypeInfo, };
|
|
24
24
|
export declare const types: {
|
|
25
25
|
literal: typeof typesLiteral;
|
|
26
|
-
undefined: import(
|
|
27
|
-
null: import(
|
|
28
|
-
boolean: import(
|
|
29
|
-
number: import(
|
|
30
|
-
string: import(
|
|
26
|
+
undefined: import("./schemas").IdentityType<undefined>;
|
|
27
|
+
null: import("./schemas").IdentityType<null>;
|
|
28
|
+
boolean: import("./schemas").IdentityType<boolean>;
|
|
29
|
+
number: import("./schemas").IdentityType<number>;
|
|
30
|
+
string: import("./schemas").IdentityType<string>;
|
|
31
31
|
or: typeof typesOr;
|
|
32
32
|
maybe: typeof typesMaybe;
|
|
33
33
|
maybeNull: typeof typesMaybeNull;
|
|
@@ -44,35 +44,35 @@ export declare const types: {
|
|
|
44
44
|
tag: typeof typesTag;
|
|
45
45
|
refinement: typeof typesRefinement;
|
|
46
46
|
codec: typeof typesCodec;
|
|
47
|
-
integer: import(
|
|
48
|
-
nonEmptyString: import(
|
|
47
|
+
integer: import("./schemas").IdentityType<number>;
|
|
48
|
+
nonEmptyString: import("./schemas").IdentityType<string>;
|
|
49
49
|
objectMap: typeof typesObjectMap;
|
|
50
50
|
arraySet: typeof typesArraySet;
|
|
51
51
|
tuple: typeof typesTuple;
|
|
52
|
-
bigint: import(
|
|
53
|
-
dateAsTimestamp: import(
|
|
54
|
-
dateAsIsoString: import(
|
|
52
|
+
bigint: import(".").CodecFromEncoded<StringConstructor, bigint>;
|
|
53
|
+
dateAsTimestamp: import(".").CodecFromEncoded<NumberConstructor, Date>;
|
|
54
|
+
dateAsIsoString: import(".").CodecFromEncoded<StringConstructor, Date>;
|
|
55
55
|
/**
|
|
56
56
|
* @deprecated Prefer `types.mapFromArray(...)` for runtime `Map` values.
|
|
57
57
|
*/
|
|
58
|
-
mapArray<T extends AnyType>(valueType: T): import(
|
|
58
|
+
mapArray<T extends AnyType>(valueType: T): import("./schemas").ArrayType<import("./schemas").ArrayType<[import("./schemas").IdentityType<string>, T]>[]>;
|
|
59
59
|
/**
|
|
60
60
|
* @deprecated Prefer `types.setFromArray(...)` for runtime `Set` values.
|
|
61
61
|
*/
|
|
62
|
-
setArray<T extends AnyType>(valueType: T): import(
|
|
62
|
+
setArray<T extends AnyType>(valueType: T): import("./schemas").ArrayType<T[]>;
|
|
63
63
|
/**
|
|
64
64
|
* @deprecated Prefer `types.mapFromObject(...)` for runtime `Map` values.
|
|
65
65
|
*/
|
|
66
|
-
mapObject<T extends AnyType>(valueType: T): import(
|
|
67
|
-
mapFromObject<T extends AnyType>(valueType: T): import(
|
|
68
|
-
mapFromArray<TKeyType extends AnyType, TValueType extends AnyType>(keyType: TKeyType, valueType: TValueType): import(
|
|
69
|
-
setFromArray<T extends AnyType>(valueType: T): import(
|
|
66
|
+
mapObject<T extends AnyType>(valueType: T): import("./schemas").RecordType<T>;
|
|
67
|
+
mapFromObject<T extends AnyType>(valueType: T): import(".").CodecFromEncoded<import("./schemas").RecordType<T>, Map<string, import("./schemas").TypeToData<T>>>;
|
|
68
|
+
mapFromArray<TKeyType extends AnyType, TValueType extends AnyType>(keyType: TKeyType, valueType: TValueType): import(".").CodecFromEncoded<import("./schemas").ArrayType<import("./schemas").ArrayType<[TKeyType, TValueType]>[]>, Map<import("./schemas").TypeToData<TKeyType>, import("./schemas").TypeToData<TValueType>>>;
|
|
69
|
+
setFromArray<T extends AnyType>(valueType: T): import(".").CodecFromEncoded<import("./schemas").ArrayType<T[]>, import("mobx").ObservableSet<import("./schemas").TypeToData<T>> | Set<import("./schemas").TypeToData<T>>>;
|
|
70
70
|
/**
|
|
71
71
|
* @deprecated Prefer `types.dateAsIsoString` instead.
|
|
72
72
|
*/
|
|
73
|
-
dateString: import(
|
|
73
|
+
dateString: import("./schemas").IdentityType<string>;
|
|
74
74
|
/**
|
|
75
75
|
* @deprecated Prefer `types.dateAsTimestamp` instead.
|
|
76
76
|
*/
|
|
77
|
-
dateTimestamp: import(
|
|
77
|
+
dateTimestamp: import("./schemas").IdentityType<number>;
|
|
78
78
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SimplifyObject } from
|
|
2
|
-
import { ArrayType, ObjectOptionalKeys, ObjectType, ObjectTypeFunction, RecordType, TypeToData } from
|
|
1
|
+
import type { SimplifyObject } from "../../utils/types";
|
|
2
|
+
import type { ArrayType, ObjectOptionalKeys, ObjectType, ObjectTypeFunction, RecordType, TypeToData } from "../schemas";
|
|
3
3
|
type ArrayStoredData<S extends readonly unknown[]> = number extends S["length"] ? Array<TypeToStoredData<S[number]>> : {
|
|
4
4
|
[k in keyof S]: TypeToStoredData<S[k]>;
|
|
5
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const typesBigInt: import(
|
|
1
|
+
export declare const typesBigInt: import("./typesCodecCore").CodecFromEncoded<StringConstructor, bigint>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { typesBigInt } from
|
|
2
|
-
import { CodecTypeInfo, typesCodec } from
|
|
3
|
-
import { createCodecPropTransform, resolveCodecSupport, resolveStoredType, resolveStoredTypeChecker } from
|
|
4
|
-
import { typesDateAsIsoString, typesDateAsTimestamp } from
|
|
5
|
-
import { typesMapFromArray, typesMapFromObject } from
|
|
6
|
-
import { typesSetFromArray } from
|
|
1
|
+
import { typesBigInt } from "./typesBigInt";
|
|
2
|
+
import { CodecTypeInfo, typesCodec } from "./typesCodecCore";
|
|
3
|
+
import { createCodecPropTransform, resolveCodecSupport, resolveStoredType, resolveStoredTypeChecker } from "./typesCodecSupport";
|
|
4
|
+
import { typesDateAsIsoString, typesDateAsTimestamp } from "./typesDate";
|
|
5
|
+
import { typesMapFromArray, typesMapFromObject } from "./typesMap";
|
|
6
|
+
import { typesSetFromArray } from "./typesSet";
|
|
7
7
|
export { CodecTypeInfo, createCodecPropTransform, resolveCodecSupport, resolveStoredType, resolveStoredTypeChecker, typesBigInt, typesCodec, typesDateAsIsoString, typesDateAsTimestamp, typesMapFromArray, typesMapFromObject, typesSetFromArray, };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ModelPropTransform } from
|
|
2
|
-
import { AnyStandardType, AnyType, CodecType, TypeToData, TypeToSnapshotIn, TypeToSnapshotOut } from
|
|
3
|
-
import { TypeCheckerBaseType, TypeInfo } from
|
|
4
|
-
import { TypeToStoredData } from
|
|
1
|
+
import type { ModelPropTransform } from "../../modelShared/prop";
|
|
2
|
+
import type { AnyStandardType, AnyType, CodecType, TypeToData, TypeToSnapshotIn, TypeToSnapshotOut } from "../schemas";
|
|
3
|
+
import { TypeCheckerBaseType, TypeInfo } from "../TypeChecker";
|
|
4
|
+
import type { TypeToStoredData } from "./typeToStoredData";
|
|
5
5
|
export interface RuntimeAdapter<Stored, Runtime> {
|
|
6
6
|
toRuntime(stored: Stored, setStored?: (stored: Stored) => void): Runtime;
|
|
7
7
|
toStored(runtime: Runtime): Stored;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ModelPropTransform } from
|
|
2
|
-
import { AnyStandardType, AnyType } from
|
|
3
|
-
import { ResolvedCodecSupport } from
|
|
1
|
+
import type { ModelPropTransform } from "../../modelShared/prop";
|
|
2
|
+
import type { AnyStandardType, AnyType } from "../schemas";
|
|
3
|
+
import { type ResolvedCodecSupport } from "./typesCodecCore";
|
|
4
4
|
export declare function resolveCodecSupport(type: AnyType): ResolvedCodecSupport;
|
|
5
5
|
export declare function resolveStoredType(type: AnyType): AnyStandardType;
|
|
6
|
-
export declare function resolveStoredTypeChecker(type: AnyType): import(
|
|
6
|
+
export declare function resolveStoredTypeChecker(type: AnyType): import("../TypeChecker").TypeChecker;
|
|
7
7
|
export declare function createCodecPropTransform(type: AnyType): ModelPropTransform<any, unknown>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const typesDateAsTimestamp: import(
|
|
2
|
-
export declare const typesDateAsIsoString: import(
|
|
1
|
+
export declare const typesDateAsTimestamp: import("./typesCodecCore").CodecFromEncoded<NumberConstructor, Date>;
|
|
2
|
+
export declare const typesDateAsIsoString: import("./typesCodecCore").CodecFromEncoded<StringConstructor, Date>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyType, ArrayType, RecordType, TypeToData } from
|
|
2
|
-
import { CodecFromEncoded } from
|
|
1
|
+
import type { AnyType, ArrayType, RecordType, TypeToData } from "../schemas";
|
|
2
|
+
import type { CodecFromEncoded } from "./typesCodecCore";
|
|
3
3
|
export declare function typesMapFromObject<TValueType extends AnyType>(valueType: TValueType): CodecFromEncoded<RecordType<TValueType>, Map<string, TypeToData<TValueType>>>;
|
|
4
4
|
export declare function typesMapFromArray<TKeyType extends AnyType, TValueType extends AnyType>(keyType: TKeyType, valueType: TValueType): CodecFromEncoded<ArrayType<ArrayType<[TKeyType, TValueType]>[]>, Map<TypeToData<TKeyType>, TypeToData<TValueType>>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyStandardType, AnyType } from
|
|
2
|
-
import { TypeInfo } from
|
|
1
|
+
import type { AnyStandardType, AnyType } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
3
|
/**
|
|
4
4
|
* A type that represents the union of several other types (a | b | c | ...).
|
|
5
5
|
* Accepts a dispatcher that, given a snapshot, returns the type
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnyStandardType, AnyType, TypeToData } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { AnyStandardType, AnyType, TypeToData } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
|
+
import { TypeCheckError } from "../TypeCheckError";
|
|
4
4
|
/**
|
|
5
5
|
* A refinement over a given type. This allows you to do extra checks
|
|
6
6
|
* over models, ensure numbers are integers, etc.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObservableSet } from
|
|
2
|
-
import { AnyType, ArrayType, TypeToData } from
|
|
3
|
-
import { CodecFromEncoded } from
|
|
1
|
+
import type { ObservableSet } from "mobx";
|
|
2
|
+
import type { AnyType, ArrayType, TypeToData } from "../schemas";
|
|
3
|
+
import type { CodecFromEncoded } from "./typesCodecCore";
|
|
4
4
|
export declare function typesSetFromArray<TValueType extends AnyType>(valueType: TValueType): CodecFromEncoded<ArrayType<TValueType[]>, Set<TypeToData<TValueType>> | ObservableSet<TypeToData<TValueType>>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyStandardType, AnyType } from
|
|
2
|
-
import { TypeInfo } from
|
|
1
|
+
import type { AnyStandardType, AnyType } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
3
|
/**
|
|
4
4
|
* A type that wraps another type but skips runtime validation.
|
|
5
5
|
* Unlike `types.unchecked()`, this preserves the wrapped type's
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyStandardType, AnyType } from
|
|
2
|
-
import { TypeInfo } from
|
|
1
|
+
import type { AnyStandardType, AnyType } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
3
|
/**
|
|
4
4
|
* Wrap a given type with tag information.
|
|
5
5
|
* This allows you to associate metadata with the type of a prop that
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IdentityType } from
|
|
2
|
-
import { TypeInfo } from
|
|
1
|
+
import type { IdentityType } from "../schemas";
|
|
2
|
+
import { TypeInfo } from "../TypeChecker";
|
|
3
3
|
/**
|
|
4
4
|
* A type that represents a given value that won't be type checked.
|
|
5
5
|
* This is basically a way to bail out of the runtime type checking system.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./ArraySet";
|
|
2
|
+
export * from "./asMap";
|
|
3
|
+
export * from "./asSet";
|
|
4
|
+
export * from "./ObjectMap";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-keystone",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mobx",
|
|
@@ -50,19 +50,6 @@
|
|
|
50
50
|
"CHANGELOG.md",
|
|
51
51
|
"README.md"
|
|
52
52
|
],
|
|
53
|
-
"scripts": {
|
|
54
|
-
"quick-build": "tsc",
|
|
55
|
-
"quick-build-tests": "tsc -p test",
|
|
56
|
-
"copy-root-files": "shx cp ../../README.md . && shx cp ../../LICENSE . && shx cp ../../CHANGELOG.md .",
|
|
57
|
-
"build": "pnpm run quick-build && pnpm run copy-root-files && shx rm -rf dist && vite build && pnpm run check-declarations && shx cp dist/mobx-keystone.esm.mjs dist/mobx-keystone.esm.js",
|
|
58
|
-
"check-declarations": "tsc -p scripts/tsconfig.check-declarations.json",
|
|
59
|
-
"test": "vitest run",
|
|
60
|
-
"test:ci": "vitest run --coverage",
|
|
61
|
-
"test:perf": "pnpm run build && pnpm run test:perf:run",
|
|
62
|
-
"test:perf:run": "cd perf_bench && NODE_ENV=production TS_NODE_COMPILER=@typescript/typescript6 /usr/bin/time node --expose-gc --require ts-node/register ./report.ts",
|
|
63
|
-
"memtest": "cd perf_bench && NODE_ENV=production TS_NODE_COMPILER=@typescript/typescript6 node --expose-gc --require ts-node/register ./memtest.ts",
|
|
64
|
-
"build-docs": "shx rm -rf ../../apps/site/generated-api && node --import ./scripts/typedoc-typescript6-register.mjs ./node_modules/typedoc/dist/cli.js --options ./typedocconfig.js src/index.ts"
|
|
65
|
-
},
|
|
66
53
|
"peerDependencies": {
|
|
67
54
|
"mobx": "^7.0.0 || ^6.0.0 || ^5.0.0 || ^4.0.0"
|
|
68
55
|
},
|
|
@@ -77,7 +64,7 @@
|
|
|
77
64
|
"@types/babel__core": "^7.20.5",
|
|
78
65
|
"@types/node": "^26.6.2",
|
|
79
66
|
"@typescript/typescript6": "^6.0.2",
|
|
80
|
-
"@vitest/coverage-v8": "
|
|
67
|
+
"@vitest/coverage-v8": "catalog:",
|
|
81
68
|
"expect-type": "^1.4.0",
|
|
82
69
|
"mobx-v4": "npm:mobx@^4.15.7",
|
|
83
70
|
"mobx-v5": "npm:mobx@^5.15.7",
|
|
@@ -89,9 +76,9 @@
|
|
|
89
76
|
"typedoc-docusaurus-theme": "^1.4.3",
|
|
90
77
|
"typedoc-plugin-markdown": "^4.13.1",
|
|
91
78
|
"typescript": "^7.0.2",
|
|
92
|
-
"vite": "
|
|
93
|
-
"vite-
|
|
94
|
-
"vitest": "
|
|
79
|
+
"vite": "catalog:",
|
|
80
|
+
"vite-plus": "catalog:",
|
|
81
|
+
"vitest": "catalog:"
|
|
95
82
|
},
|
|
96
83
|
"dependencies": {
|
|
97
84
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a call's name resolved to on its target.
|
|
3
|
+
*/
|
|
4
|
+
export enum CallKind {
|
|
5
|
+
/**
|
|
6
|
+
* An action declared on a class: a model's `@modelAction` / `@modelFlow` (including
|
|
7
|
+
* `withSetter()` setters), or a data model's action.
|
|
8
|
+
*/
|
|
9
|
+
ModelAction = "modelAction",
|
|
10
|
+
/**
|
|
11
|
+
* An action the app defines with `standaloneAction` / `standaloneFlow`, under a global name.
|
|
12
|
+
*/
|
|
13
|
+
StandaloneAction = "standaloneAction",
|
|
14
|
+
/**
|
|
15
|
+
* A standalone action the library ships for editing any array or plain object
|
|
16
|
+
* (`arrayActions`, `objectActions`).
|
|
17
|
+
*/
|
|
18
|
+
StandardAction = "standardAction",
|
|
19
|
+
/**
|
|
20
|
+
* A built-in action, as library functions record when they change a node: `$$applySnapshot`,
|
|
21
|
+
* `$$applyPatches`, `$$detach`, `$$applySet`, `$$applyDelete`, `$$applyMethodCall` (see
|
|
22
|
+
* `BuiltInAction`).
|
|
23
|
+
*/
|
|
24
|
+
BuiltInAction = "builtInAction",
|
|
25
|
+
/**
|
|
26
|
+
* Not an action: a method, getter or function field of a model's or data model's own classes.
|
|
27
|
+
*/
|
|
28
|
+
View = "view",
|
|
29
|
+
}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import { getDataModelAction } from "../dataModel/actions"
|
|
2
|
-
import { detach } from "../parent/detach"
|
|
3
1
|
import { resolvePathCheckingIds } from "../parent/path"
|
|
4
2
|
import type { Path } from "../parent/pathTypes"
|
|
5
|
-
import { applyPatches } from "../patch/applyPatches"
|
|
6
|
-
import { applySnapshot } from "../snapshot/applySnapshot"
|
|
7
3
|
import { getStandaloneAction } from "../standardActions/actions"
|
|
8
4
|
import { assertTweakedObject } from "../tweaker/core"
|
|
9
5
|
import { failure } from "../utils"
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import { applyMethodCall } from "./applyMethodCall"
|
|
13
|
-
import { applySet } from "./applySet"
|
|
14
|
-
import { BuiltInAction, isBuiltInAction } from "./builtInActions"
|
|
15
|
-
import { isHookAction } from "./hookActions"
|
|
16
|
-
import { isModelAction } from "./isModelAction"
|
|
17
|
-
import { isModelFlow } from "./modelFlow"
|
|
6
|
+
import { CallKind } from "./CallKind"
|
|
7
|
+
import { resolveCallName } from "./resolveCallName"
|
|
18
8
|
|
|
19
9
|
/**
|
|
20
10
|
* An action call.
|
|
@@ -42,23 +32,20 @@ export interface ActionCall {
|
|
|
42
32
|
|
|
43
33
|
/**
|
|
44
34
|
* Marks this action call as non-serialized.
|
|
35
|
+
*
|
|
36
|
+
* @deprecated Not needed with `createSerializer`: a `Call` is never serialized, an
|
|
37
|
+
* `EncodedCall` always is.
|
|
45
38
|
*/
|
|
46
39
|
readonly serialized?: boolean
|
|
47
40
|
}
|
|
48
41
|
|
|
49
|
-
const builtInActionToFunction = {
|
|
50
|
-
[BuiltInAction.ApplySnapshot]: applySnapshot,
|
|
51
|
-
[BuiltInAction.ApplyPatches]: applyPatches,
|
|
52
|
-
[BuiltInAction.Detach]: detach,
|
|
53
|
-
[BuiltInAction.ApplySet]: applySet,
|
|
54
|
-
[BuiltInAction.ApplyDelete]: applyDelete,
|
|
55
|
-
[BuiltInAction.ApplyMethodCall]: applyMethodCall,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
42
|
/**
|
|
59
43
|
* Applies (runs) an action over a target object.
|
|
60
44
|
*
|
|
61
|
-
*
|
|
45
|
+
* It runs any kind of action (built-in, standalone, model actions and flows), but not views.
|
|
46
|
+
* To apply calls that come from outside (e.g. as JSON), decode them with a serializer
|
|
47
|
+
* (`defaultSerializer.decodeCall`) and use `applyCall` / `applyCallAsync` instead, which check
|
|
48
|
+
* what may be called.
|
|
62
49
|
*
|
|
63
50
|
* @param subtreeRoot Subtree root target object to run the action over.
|
|
64
51
|
* @param call The action, usually as coming from `onActionMiddleware`.
|
|
@@ -88,38 +75,24 @@ export function applyAction<TRet = any>(subtreeRoot: object, call: ActionCall):
|
|
|
88
75
|
}
|
|
89
76
|
assertTweakedObject(current, "resolved target", true)
|
|
90
77
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (!fnToCall) {
|
|
94
|
-
throw failure(`assertion failed: unknown built-in action - ${call.actionName}`)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return fnToCall.apply(current, [current, ...call.args])
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (isHookAction(call.actionName)) {
|
|
78
|
+
const resolution = resolveCallName(current, call.actionName)
|
|
79
|
+
if (resolution === "hook") {
|
|
101
80
|
throw failure(`calls to hooks (${call.actionName}) cannot be applied`)
|
|
102
81
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (dataModelAction) {
|
|
106
|
-
const instance: any = new dataModelAction.modelClass(current)
|
|
107
|
-
return instance[dataModelAction.fnName](...call.args)
|
|
82
|
+
if (resolution === "unknown") {
|
|
83
|
+
throw failure(`action '${call.actionName}' could not be resolved to a function`)
|
|
108
84
|
}
|
|
109
85
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
86
|
+
switch (resolution.kind) {
|
|
87
|
+
case CallKind.View:
|
|
88
|
+
throw failure(`action '${call.actionName}' is not a model action`)
|
|
114
89
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
90
|
+
case CallKind.StandaloneAction:
|
|
91
|
+
case CallKind.StandardAction:
|
|
92
|
+
// the target is already the first argument
|
|
93
|
+
return getStandaloneAction(call.actionName)!.fn(...call.args)
|
|
119
94
|
|
|
120
|
-
|
|
121
|
-
|
|
95
|
+
default:
|
|
96
|
+
return resolution.run(call.args) as TRet
|
|
122
97
|
}
|
|
123
|
-
|
|
124
|
-
return actionFn.apply(current, call.args)
|
|
125
98
|
}
|
package/src/action/applySet.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isObservable } from "mobx"
|
|
2
2
|
import { isModel } from "../model/utils"
|
|
3
3
|
import { assertTweakedObject } from "../tweaker/core"
|
|
4
|
-
import { lazy } from "../utils"
|
|
4
|
+
import { failure, hasOwnProp, lazy } from "../utils"
|
|
5
5
|
import { setIfDifferent } from "../utils/setIfDifferent"
|
|
6
6
|
import { BuiltInAction } from "./builtInActions"
|
|
7
7
|
import { ActionContextActionType } from "./context"
|
|
@@ -30,10 +30,30 @@ function internalApplySet<O extends object>(this: O, fieldName: string | number,
|
|
|
30
30
|
if (!isModel(this) && isObservable(this)) {
|
|
31
31
|
setIfDifferent(this, fieldName, value)
|
|
32
32
|
} else {
|
|
33
|
+
// assigning '__proto__' would replace the prototype of the model instead of setting a field,
|
|
34
|
+
// and assigning an inherited method (e.g. an action) would shadow it on this instance
|
|
35
|
+
if (fieldName === "__proto__" || isInheritedDataProp(this, fieldName)) {
|
|
36
|
+
throw failure(`applySet cannot set '${String(fieldName)}' on a model`)
|
|
37
|
+
}
|
|
33
38
|
;(this as any)[fieldName] = value
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
|
|
42
|
+
function isInheritedDataProp(obj: object, fieldName: string | number): boolean {
|
|
43
|
+
if (hasOwnProp(obj, fieldName)) {
|
|
44
|
+
return false
|
|
45
|
+
}
|
|
46
|
+
let proto = Object.getPrototypeOf(obj)
|
|
47
|
+
while (proto) {
|
|
48
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, fieldName)
|
|
49
|
+
if (descriptor) {
|
|
50
|
+
return !descriptor.get && !descriptor.set
|
|
51
|
+
}
|
|
52
|
+
proto = Object.getPrototypeOf(proto)
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
37
57
|
const wrappedInternalApplySet = lazy(() =>
|
|
38
58
|
wrapInAction({
|
|
39
59
|
nameOrNameFn: BuiltInAction.ApplySet,
|
package/src/action/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { wrapInAction } from "./wrapInAction"
|
|
|
8
8
|
* Decorator that turns a function into a model action.
|
|
9
9
|
*/
|
|
10
10
|
export function modelAction(...args: any[]): void {
|
|
11
|
-
//
|
|
11
|
+
// Proper way to declare a decorator
|
|
12
12
|
return decorateWrapMethodOrField("modelAction", args, (data, fn) => {
|
|
13
13
|
if (isModelAction(fn)) {
|
|
14
14
|
return fn
|
package/src/action/modelFlow.ts
CHANGED
|
@@ -163,7 +163,7 @@ export function isModelFlow(fn: unknown) {
|
|
|
163
163
|
* Decorator that turns a function generator into a model flow.
|
|
164
164
|
*/
|
|
165
165
|
export function modelFlow(...args: any[]): void {
|
|
166
|
-
//
|
|
166
|
+
// Proper way to declare a decorator
|
|
167
167
|
return decorateWrapMethodOrField("modelFlow", args, (data, fn) => {
|
|
168
168
|
if (isModelFlow(fn)) {
|
|
169
169
|
return fn
|