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.
Files changed (205) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/mobx-keystone.esm.js +3737 -2722
  3. package/dist/mobx-keystone.esm.mjs +3737 -2722
  4. package/dist/mobx-keystone.umd.js +3750 -2721
  5. package/dist/types/action/CallKind.d.ts +29 -0
  6. package/dist/types/action/applyAction.d.ts +8 -2
  7. package/dist/types/action/applyMethodCall.d.ts +1 -1
  8. package/dist/types/action/index.d.ts +13 -12
  9. package/dist/types/action/isModelAction.d.ts +1 -1
  10. package/dist/types/action/middleware.d.ts +1 -1
  11. package/dist/types/action/resolveCallName.d.ts +1 -0
  12. package/dist/types/actionMiddlewares/actionSerialization/actionSerialization.d.ts +17 -3
  13. package/dist/types/actionMiddlewares/actionSerialization/applySerializedAction.d.ts +8 -2
  14. package/dist/types/actionMiddlewares/actionSerialization/arraySerializer.d.ts +2 -2
  15. package/dist/types/actionMiddlewares/actionSerialization/core.d.ts +7 -0
  16. package/dist/types/actionMiddlewares/actionSerialization/dateSerializer.d.ts +1 -1
  17. package/dist/types/actionMiddlewares/actionSerialization/index.d.ts +3 -3
  18. package/dist/types/actionMiddlewares/actionSerialization/mapSerializer.d.ts +2 -2
  19. package/dist/types/actionMiddlewares/actionSerialization/objectPathSerializer.d.ts +2 -2
  20. package/dist/types/actionMiddlewares/actionSerialization/objectSnapshotSerializer.d.ts +1 -1
  21. package/dist/types/actionMiddlewares/actionSerialization/plainObjectSerializer.d.ts +1 -1
  22. package/dist/types/actionMiddlewares/actionSerialization/primitiveSerializer.d.ts +1 -1
  23. package/dist/types/actionMiddlewares/actionSerialization/setSerializer.d.ts +2 -2
  24. package/dist/types/actionMiddlewares/actionTrackingMiddleware.d.ts +3 -3
  25. package/dist/types/actionMiddlewares/index.d.ts +6 -6
  26. package/dist/types/actionMiddlewares/onActionMiddleware.d.ts +3 -3
  27. package/dist/types/actionMiddlewares/readonlyMiddleware.d.ts +1 -1
  28. package/dist/types/actionMiddlewares/transactionMiddleware.d.ts +2 -2
  29. package/dist/types/actionMiddlewares/undoMiddleware.d.ts +8 -8
  30. package/dist/types/computedTree/index.d.ts +1 -1
  31. package/dist/types/context/index.d.ts +1 -1
  32. package/dist/types/dataModel/BaseDataModel.d.ts +3 -3
  33. package/dist/types/dataModel/DataModel.d.ts +3 -3
  34. package/dist/types/dataModel/getDataModelMetadata.d.ts +3 -3
  35. package/dist/types/dataModel/index.d.ts +4 -4
  36. package/dist/types/dataModel/utils.d.ts +1 -1
  37. package/dist/types/deepChange/index.d.ts +1 -1
  38. package/dist/types/deepChange/onDeepChange.d.ts +1 -1
  39. package/dist/types/frozen/Frozen.d.ts +1 -1
  40. package/dist/types/frozen/index.d.ts +1 -1
  41. package/dist/types/globalConfig/index.d.ts +1 -1
  42. package/dist/types/index.d.ts +25 -24
  43. package/dist/types/model/BaseModel.d.ts +5 -5
  44. package/dist/types/model/Model.d.ts +3 -3
  45. package/dist/types/model/getModelMetadata.d.ts +3 -3
  46. package/dist/types/model/index.d.ts +6 -6
  47. package/dist/types/model/mixins.d.ts +4 -4
  48. package/dist/types/model/utils.d.ts +4 -4
  49. package/dist/types/modelShared/BaseModelShared.d.ts +5 -5
  50. package/dist/types/modelShared/index.d.ts +4 -4
  51. package/dist/types/modelShared/modelDecorator.d.ts +3 -3
  52. package/dist/types/modelShared/modelInfo.d.ts +3 -3
  53. package/dist/types/modelShared/newModel.d.ts +3 -3
  54. package/dist/types/modelShared/prop.d.ts +3 -3
  55. package/dist/types/modelShared/sharedInternalModel.d.ts +4 -4
  56. package/dist/types/parent/findParent.d.ts +1 -1
  57. package/dist/types/parent/index.d.ts +9 -9
  58. package/dist/types/parent/path.d.ts +1 -1
  59. package/dist/types/patch/Patch.d.ts +1 -1
  60. package/dist/types/patch/applyPatches.d.ts +1 -1
  61. package/dist/types/patch/emitPatch.d.ts +7 -1
  62. package/dist/types/patch/index.d.ts +5 -5
  63. package/dist/types/patch/jsonPatch.d.ts +2 -2
  64. package/dist/types/patch/patchRecorder.d.ts +2 -2
  65. package/dist/types/redux/index.d.ts +2 -2
  66. package/dist/types/redux/redux.d.ts +3 -3
  67. package/dist/types/ref/Ref.d.ts +3 -3
  68. package/dist/types/ref/core.d.ts +2 -2
  69. package/dist/types/ref/customRef.d.ts +2 -2
  70. package/dist/types/ref/index.d.ts +4 -4
  71. package/dist/types/ref/rootRef.d.ts +2 -2
  72. package/dist/types/rootStore/index.d.ts +1 -1
  73. package/dist/types/serialization/Call.d.ts +55 -0
  74. package/dist/types/serialization/CallError.d.ts +96 -0
  75. package/dist/types/serialization/JsonValue.d.ts +6 -0
  76. package/dist/types/serialization/Serializer.d.ts +84 -0
  77. package/dist/types/serialization/ValueSerializer.d.ts +88 -0
  78. package/dist/types/serialization/applyCall.d.ts +54 -0
  79. package/dist/types/serialization/builtinSerializers.d.ts +49 -0
  80. package/dist/types/serialization/codec.d.ts +1 -0
  81. package/dist/types/serialization/index.d.ts +8 -0
  82. package/dist/types/serialization/references.d.ts +74 -0
  83. package/dist/types/serialization/resolvedCall.d.ts +1 -0
  84. package/dist/types/snapshot/SnapshotOf.d.ts +5 -5
  85. package/dist/types/snapshot/SnapshotProcessingError.d.ts +2 -2
  86. package/dist/types/snapshot/applySnapshot.d.ts +1 -1
  87. package/dist/types/snapshot/cloneTreeValue.d.ts +1 -1
  88. package/dist/types/snapshot/fromSnapshot.d.ts +2 -2
  89. package/dist/types/snapshot/getSnapshot.d.ts +2 -2
  90. package/dist/types/snapshot/index.d.ts +8 -8
  91. package/dist/types/snapshot/onSnapshot.d.ts +1 -1
  92. package/dist/types/standardActions/index.d.ts +3 -3
  93. package/dist/types/standardActions/objectActions.d.ts +1 -1
  94. package/dist/types/transforms/asMap.d.ts +1 -1
  95. package/dist/types/transforms/asSet.d.ts +2 -2
  96. package/dist/types/transforms/bigint.d.ts +1 -1
  97. package/dist/types/transforms/date.d.ts +1 -1
  98. package/dist/types/transforms/index.d.ts +4 -4
  99. package/dist/types/treeUtils/draft.d.ts +1 -1
  100. package/dist/types/treeUtils/index.d.ts +3 -3
  101. package/dist/types/tweaker/index.d.ts +2 -2
  102. package/dist/types/tweaker/tweak.d.ts +1 -1
  103. package/dist/types/types/SnapshotTypeMismatchError.d.ts +2 -2
  104. package/dist/types/types/TypeCheckError.d.ts +2 -2
  105. package/dist/types/types/TypeChecker.d.ts +3 -3
  106. package/dist/types/types/arrayBased/typesArray.d.ts +2 -2
  107. package/dist/types/types/arrayBased/typesTuple.d.ts +2 -2
  108. package/dist/types/types/getTypeInfo.d.ts +2 -2
  109. package/dist/types/types/index.d.ts +7 -7
  110. package/dist/types/types/objectBased/typesArraySet.d.ts +3 -3
  111. package/dist/types/types/objectBased/typesDataModelData.d.ts +4 -4
  112. package/dist/types/types/objectBased/typesModel.d.ts +4 -4
  113. package/dist/types/types/objectBased/typesObject.d.ts +3 -3
  114. package/dist/types/types/objectBased/typesObjectMap.d.ts +3 -3
  115. package/dist/types/types/objectBased/typesRecord.d.ts +2 -2
  116. package/dist/types/types/objectBased/typesRef.d.ts +3 -3
  117. package/dist/types/types/primitiveBased/typesEnum.d.ts +1 -1
  118. package/dist/types/types/primitiveBased/typesPrimitive.d.ts +3 -3
  119. package/dist/types/types/primitiveBased/typesRefinedPrimitive.d.ts +2 -2
  120. package/dist/types/types/schemas.d.ts +5 -5
  121. package/dist/types/types/tProp.d.ts +4 -4
  122. package/dist/types/types/typeCheck.d.ts +2 -2
  123. package/dist/types/types/types.d.ts +39 -39
  124. package/dist/types/types/utility/typeToStoredData.d.ts +2 -2
  125. package/dist/types/types/utility/typesBigInt.d.ts +1 -1
  126. package/dist/types/types/utility/typesCodec.d.ts +6 -6
  127. package/dist/types/types/utility/typesCodecCore.d.ts +4 -4
  128. package/dist/types/types/utility/typesCodecSupport.d.ts +4 -4
  129. package/dist/types/types/utility/typesDate.d.ts +2 -2
  130. package/dist/types/types/utility/typesMap.d.ts +2 -2
  131. package/dist/types/types/utility/typesMaybe.d.ts +1 -1
  132. package/dist/types/types/utility/typesOr.d.ts +2 -2
  133. package/dist/types/types/utility/typesRefinement.d.ts +3 -3
  134. package/dist/types/types/utility/typesSet.d.ts +3 -3
  135. package/dist/types/types/utility/typesSkipCheck.d.ts +2 -2
  136. package/dist/types/types/utility/typesTag.d.ts +2 -2
  137. package/dist/types/types/utility/typesUnchecked.d.ts +2 -2
  138. package/dist/types/utils/ModelPool.d.ts +1 -1
  139. package/dist/types/wrappers/ArraySet.d.ts +1 -1
  140. package/dist/types/wrappers/ObjectMap.d.ts +1 -1
  141. package/dist/types/wrappers/asMap.d.ts +1 -1
  142. package/dist/types/wrappers/asSet.d.ts +1 -1
  143. package/dist/types/wrappers/index.d.ts +4 -4
  144. package/package.json +5 -18
  145. package/src/action/CallKind.ts +29 -0
  146. package/src/action/applyAction.ts +22 -49
  147. package/src/action/applySet.ts +21 -1
  148. package/src/action/index.ts +1 -0
  149. package/src/action/modelAction.ts +1 -1
  150. package/src/action/modelFlow.ts +1 -1
  151. package/src/action/resolveCallName.ts +207 -0
  152. package/src/actionMiddlewares/actionSerialization/actionSerialization.ts +14 -0
  153. package/src/actionMiddlewares/actionSerialization/applySerializedAction.ts +6 -0
  154. package/src/actionMiddlewares/actionSerialization/core.ts +7 -0
  155. package/src/actionMiddlewares/actionSerialization/index.ts +2 -0
  156. package/src/actionMiddlewares/actionSerialization/objectPathSerializer.ts +3 -2
  157. package/src/dataModel/BaseDataModel.ts +5 -5
  158. package/src/index.ts +1 -0
  159. package/src/model/BaseModel.ts +7 -6
  160. package/src/model/mixins.ts +1 -1
  161. package/src/model/newModel.ts +1 -1
  162. package/src/modelShared/modelDecorator.ts +4 -6
  163. package/src/modelShared/modelInfo.ts +2 -1
  164. package/src/modelShared/sharedInternalModel.ts +1 -1
  165. package/src/parent/path.ts +45 -12
  166. package/src/patch/emitPatch.ts +6 -0
  167. package/src/ref/Ref.ts +1 -1
  168. package/src/serialization/Call.ts +58 -0
  169. package/src/serialization/CallError.ts +153 -0
  170. package/src/serialization/JsonValue.ts +12 -0
  171. package/src/serialization/Serializer.ts +321 -0
  172. package/src/serialization/ValueSerializer.ts +98 -0
  173. package/src/serialization/applyCall.ts +190 -0
  174. package/src/serialization/builtinSerializers.ts +261 -0
  175. package/src/serialization/codec.ts +338 -0
  176. package/src/serialization/index.ts +15 -0
  177. package/src/serialization/references.ts +225 -0
  178. package/src/serialization/resolvedCall.ts +169 -0
  179. package/src/snapshot/SnapshotterAndReconcilerPriority.ts +2 -1
  180. package/src/snapshot/fromModelSnapshot.ts +1 -1
  181. package/src/snapshot/fromSnapshot.ts +1 -1
  182. package/src/standardActions/actions.ts +11 -3
  183. package/src/transforms/ImmutableDate.ts +19 -19
  184. package/src/tweaker/tweakArray.ts +1 -1
  185. package/src/tweaker/tweakFrozen.ts +1 -1
  186. package/src/tweaker/tweakModel.ts +1 -1
  187. package/src/tweaker/tweakPlainObject.ts +1 -1
  188. package/src/types/arrayBased/typesArray.ts +1 -1
  189. package/src/types/arrayBased/typesTuple.ts +1 -1
  190. package/src/types/objectBased/typesArraySet.ts +1 -1
  191. package/src/types/objectBased/typesModel.ts +2 -2
  192. package/src/types/objectBased/typesObject.ts +1 -1
  193. package/src/types/objectBased/typesObjectMap.ts +1 -1
  194. package/src/types/objectBased/typesRecord.ts +1 -1
  195. package/src/types/objectBased/typesRef.ts +2 -2
  196. package/src/types/primitiveBased/typesPrimitive.ts +1 -1
  197. package/src/types/schemas.ts +1 -1
  198. package/src/types/utility/typesCodecCore.ts +1 -1
  199. package/src/types/utility/typesCodecSupport.ts +2 -0
  200. package/src/types/utility/typesOr.ts +2 -2
  201. package/src/types/utility/typesRefinement.ts +1 -1
  202. package/src/utils/errorDiagnostics.ts +9 -4
  203. package/src/utils/index.ts +20 -13
  204. package/src/wrappers/ArraySet.ts +3 -5
  205. package/src/wrappers/ObjectMap.ts +3 -5
@@ -1,33 +1,33 @@
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, ModelTypeInfoProps, typesModel } from './objectBased/typesModel';
6
- import { FrozenTypeInfo, ObjectTypeInfo, 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 { 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';
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('./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>;
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('./schemas').IdentityType<number>;
48
- nonEmptyString: import('./schemas').IdentityType<string>;
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('.').CodecFromEncoded<StringConstructor, bigint>;
53
- dateAsTimestamp: import('.').CodecFromEncoded<NumberConstructor, Date>;
54
- dateAsIsoString: import('.').CodecFromEncoded<StringConstructor, Date>;
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('./schemas').ArrayType<import('./schemas').ArrayType<[import('./schemas').IdentityType<string>, T]>[]>;
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('./schemas').ArrayType<T[]>;
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('./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[]>, Set<import('./schemas').TypeToData<T>> | import('mobx').ObservableSet<import('./schemas').TypeToData<T>>>;
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('./schemas').IdentityType<string>;
73
+ dateString: import("./schemas").IdentityType<string>;
74
74
  /**
75
75
  * @deprecated Prefer `types.dateAsTimestamp` instead.
76
76
  */
77
- dateTimestamp: import('./schemas').IdentityType<number>;
77
+ dateTimestamp: import("./schemas").IdentityType<number>;
78
78
  };
@@ -1,5 +1,5 @@
1
- import { SimplifyObject } from '../../utils/types';
2
- import { ArrayType, ObjectOptionalKeys, ObjectType, ObjectTypeFunction, RecordType, TypeToData } from '../schemas';
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('./typesCodecCore').CodecFromEncoded<StringConstructor, bigint>;
1
+ export declare const typesBigInt: import("./typesCodecCore").CodecFromEncoded<StringConstructor, bigint>;
@@ -1,7 +1,7 @@
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';
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 '../../modelShared/prop';
2
- import { AnyStandardType, AnyType, CodecType, TypeToData, TypeToSnapshotIn, TypeToSnapshotOut } from '../schemas';
3
- import { TypeCheckerBaseType, TypeInfo } from '../TypeChecker';
4
- import { TypeToStoredData } from './typeToStoredData';
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 '../../modelShared/prop';
2
- import { AnyStandardType, AnyType } from '../schemas';
3
- import { ResolvedCodecSupport } from './typesCodecCore';
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('../TypeChecker').TypeChecker;
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('./typesCodecCore').CodecFromEncoded<NumberConstructor, Date>;
2
- export declare const typesDateAsIsoString: import('./typesCodecCore').CodecFromEncoded<StringConstructor, Date>;
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 '../schemas';
2
- import { CodecFromEncoded } from './typesCodecCore';
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,4 +1,4 @@
1
- import { AnyType, IdentityType } from '../schemas';
1
+ import type { AnyType, IdentityType } from "../schemas";
2
2
  /**
3
3
  * A type that represents either a type or undefined.
4
4
  * Syntactic sugar for `types.or(baseType, types.undefined)`
@@ -1,5 +1,5 @@
1
- import { AnyStandardType, AnyType } from '../schemas';
2
- import { TypeInfo } from '../TypeChecker';
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 '../schemas';
2
- import { TypeCheckError } from '../TypeCheckError';
3
- import { TypeInfo } from '../TypeChecker';
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 'mobx';
2
- import { AnyType, ArrayType, TypeToData } from '../schemas';
3
- import { CodecFromEncoded } from './typesCodecCore';
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 '../schemas';
2
- import { TypeInfo } from '../TypeChecker';
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 '../schemas';
2
- import { TypeInfo } from '../TypeChecker';
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 '../schemas';
2
- import { TypeInfo } from '../TypeChecker';
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
- import { AnyModel } from '../model/BaseModel';
1
+ import type { AnyModel } from "../model/BaseModel";
2
2
  /**
3
3
  * A view of the models under a node, as they were when the pool was created.
4
4
  * Must be released once no longer used.
@@ -1,4 +1,4 @@
1
- import { AnyModel } from '../model/BaseModel';
1
+ import type { AnyModel } from "../model/BaseModel";
2
2
  declare const arraySetBase: abstract new (data: any) => AnyModel & {
3
3
  readonly $: {
4
4
  items: any[];
@@ -1,4 +1,4 @@
1
- import { AnyModel } from '../model/BaseModel';
1
+ import type { AnyModel } from "../model/BaseModel";
2
2
  declare const objectMapBase: abstract new (data: any) => AnyModel & {
3
3
  readonly $: {
4
4
  items: Record<string, any>;
@@ -1,4 +1,4 @@
1
- import { ObservableMap } from 'mobx';
1
+ import { type ObservableMap } from "mobx";
2
2
  type Ts6MapExtras<K, V> = {
3
3
  getOrInsert(key: K, defaultValue: V): V;
4
4
  getOrInsertComputed(key: K, callback: (key: K) => V): V;
@@ -1,4 +1,4 @@
1
- import { ObservableSet } from 'mobx';
1
+ import { type ObservableSet } from "mobx";
2
2
  /**
3
3
  * Wraps an observable array to offer a set like interface.
4
4
  *
@@ -1,4 +1,4 @@
1
- export * from './ArraySet';
2
- export * from './asMap';
3
- export * from './asSet';
4
- export * from './ObjectMap';
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.0",
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": "^5.0.1",
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": "^8.3.1",
93
- "vite-plugin-dts": "^5.1.1",
94
- "vitest": "^5.0.1"
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 type { AnyFunction } from "../utils/AnyFunction"
11
- import { applyDelete } from "./applyDelete"
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
- * If you intend to apply serialized actions check one of the `applySerializedAction` methods instead.
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
- if (isBuiltInAction(call.actionName)) {
92
- const fnToCall = builtInActionToFunction[call.actionName] as AnyFunction | undefined
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
- const dataModelAction = getDataModelAction(call.actionName)
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
- const standaloneAction = getStandaloneAction(call.actionName)
111
- if (standaloneAction) {
112
- return standaloneAction.apply(current, call.args as any)
113
- }
86
+ switch (resolution.kind) {
87
+ case CallKind.View:
88
+ throw failure(`action '${call.actionName}' is not a model action`)
114
89
 
115
- const actionFn = (current as any)[call.actionName]
116
- if (typeof actionFn !== "function") {
117
- throw failure(`action '${call.actionName}' could not be resolved to a function`)
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
- if (!isModelAction(actionFn) && !isModelFlow(actionFn)) {
121
- throw failure(`action '${call.actionName}' is not a model action`)
95
+ default:
96
+ return resolution.run(call.args) as TRet
122
97
  }
123
-
124
- return actionFn.apply(current, call.args)
125
98
  }
@@ -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,
@@ -3,6 +3,7 @@ export * from "./applyDelete"
3
3
  export * from "./applyMethodCall"
4
4
  export * from "./applySet"
5
5
  export * from "./builtInActions"
6
+ export * from "./CallKind"
6
7
  export * from "./context"
7
8
  export * from "./hookActions"
8
9
  export * from "./isModelAction"
@@ -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
- // biome-ignore lint/correctness/noVoidTypeReturn: proper way to declare a decorator
11
+ // Proper way to declare a decorator
12
12
  return decorateWrapMethodOrField("modelAction", args, (data, fn) => {
13
13
  if (isModelAction(fn)) {
14
14
  return fn
@@ -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
- // biome-ignore lint/correctness/noVoidTypeReturn: proper way to declare a decorator
166
+ // Proper way to declare a decorator
167
167
  return decorateWrapMethodOrField("modelFlow", args, (data, fn) => {
168
168
  if (isModelFlow(fn)) {
169
169
  return fn