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,8 +1,8 @@
1
- import { AnyDataModel } from '../dataModel/BaseDataModel';
2
- import { AnyModel } from '../model/BaseModel';
3
- import { modelTypeKey } from '../model/metadata';
4
- import { Flatten, IsNeverType } from '../utils/types';
5
- import { ModelProps, ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData, ModelPropsToUntransformedCreationData } from './prop';
1
+ import type { AnyDataModel } from "../dataModel/BaseDataModel";
2
+ import type { AnyModel } from "../model/BaseModel";
3
+ import type { modelTypeKey } from "../model/metadata";
4
+ import type { Flatten, IsNeverType } from "../utils/types";
5
+ import type { ModelProps, ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData, ModelPropsToUntransformedCreationData } from "./prop";
6
6
  /**
7
7
  * @ignore
8
8
  */
@@ -1,4 +1,4 @@
1
- export * from './BaseModelShared';
2
- export * from './modelDecorator';
3
- export * from './modelInfo';
4
- export * from './prop';
1
+ export * from "./BaseModelShared";
2
+ export * from "./modelDecorator";
3
+ export * from "./modelInfo";
4
+ export * from "./prop";
@@ -1,6 +1,6 @@
1
- import { AnyDataModel } from '../dataModel/BaseDataModel';
2
- import { AnyModel } from '../model/BaseModel';
3
- import { AnyFunction } from '../utils/AnyFunction';
1
+ import type { AnyDataModel } from "../dataModel/BaseDataModel";
2
+ import type { AnyModel } from "../model/BaseModel";
3
+ import type { AnyFunction } from "../utils/AnyFunction";
4
4
  /**
5
5
  * Decorator that marks this class (which MUST inherit from the `Model` or `DataModel` abstract classes)
6
6
  * as a model.
@@ -1,6 +1,6 @@
1
- import { AnyDataModel } from '../dataModel/BaseDataModel';
2
- import { AnyModel } from '../model/BaseModel';
3
- import { ModelClass } from './BaseModelShared';
1
+ import type { AnyDataModel } from "../dataModel/BaseDataModel";
2
+ import type { AnyModel } from "../model/BaseModel";
3
+ import type { ModelClass } from "./BaseModelShared";
4
4
  /**
5
5
  * Information about a registered model.
6
6
  */
@@ -1,4 +1,4 @@
1
- import { AnyDataModel } from '../dataModel/BaseDataModel';
2
- import { AnyModel } from '../model/BaseModel';
3
- import { ModelClass } from '../modelShared/BaseModelShared';
1
+ import type { AnyDataModel } from "../dataModel/BaseDataModel";
2
+ import type { AnyModel } from "../model/BaseModel";
3
+ import type { ModelClass } from "../modelShared/BaseModelShared";
4
4
  export declare function applyModelInitializers(modelClass: ModelClass<AnyModel | AnyDataModel>, modelObj: any): void;
@@ -1,6 +1,6 @@
1
- import { SnapshotInOf, SnapshotOutOf } from '../snapshot/SnapshotOf';
2
- import { AnyStandardType } from '../types/schemas';
3
- import { IsNeverType, IsOptionalValue, SimplifyObject } from '../utils/types';
1
+ import type { SnapshotInOf, SnapshotOutOf } from "../snapshot/SnapshotOf";
2
+ import type { AnyStandardType } from "../types/schemas";
3
+ import type { IsNeverType, IsOptionalValue, SimplifyObject } from "../utils/types";
4
4
  /**
5
5
  * @ignore
6
6
  */
@@ -1,7 +1,7 @@
1
- import { AnyDataModel } from '../dataModel/BaseDataModel';
2
- import { AnyModel } from '../model/BaseModel';
3
- import { ModelClass } from './BaseModelShared';
4
- import { ModelProps } from './prop';
1
+ import { type AnyDataModel } from "../dataModel/BaseDataModel";
2
+ import { type AnyModel } from "../model/BaseModel";
3
+ import { type ModelClass } from "./BaseModelShared";
4
+ import { type ModelProps } from "./prop";
5
5
  type FromSnapshotProcessorFn = (sn: any) => any;
6
6
  type ToSnapshotProcessorFn = (sn: any, instance: any) => any;
7
7
  export declare function sharedInternalModel<TProps extends ModelProps, TBaseModel extends AnyModel | AnyDataModel>({ modelProps, baseModel, type, valueType, fromSnapshotProcessor, toSnapshotProcessor, }: {
@@ -1,4 +1,4 @@
1
- import { Path } from './pathTypes';
1
+ import type { Path } from "./pathTypes";
2
2
  /**
3
3
  * Iterates through all the parents (from the nearest until the root)
4
4
  * until one of them matches the given predicate.
@@ -1,9 +1,9 @@
1
- export * from './detach';
2
- export * from './findChildren';
3
- export * from './findParent';
4
- export * from './getChildrenObjects';
5
- export * from './onChildAttachedTo';
6
- export * from './path';
7
- export * from './path2';
8
- export * from './pathTypes';
9
- export * from './walkTree';
1
+ export * from "./detach";
2
+ export * from "./findChildren";
3
+ export * from "./findParent";
4
+ export * from "./getChildrenObjects";
5
+ export * from "./onChildAttachedTo";
6
+ export * from "./path";
7
+ export * from "./path2";
8
+ export * from "./pathTypes";
9
+ export * from "./walkTree";
@@ -1,4 +1,4 @@
1
- import { Path, PathElement } from './pathTypes';
1
+ import type { Path, PathElement } from "./pathTypes";
2
2
  /**
3
3
  * Path from an object to its immediate parent.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { Path } from '../parent/pathTypes';
1
+ import type { Path } from "../parent/pathTypes";
2
2
  export type Patch = PatchAddOperation<any> | PatchRemoveOperation | PatchReplaceOperation<any>;
3
3
  export interface PatchBaseOperation {
4
4
  path: Path;
@@ -1,4 +1,4 @@
1
- import { Patch } from '../patch/Patch';
1
+ import type { Patch } from "../patch/Patch";
2
2
  /**
3
3
  * Applies the given patches to the given target object.
4
4
  * Automatic type checking validates the completed batch, including nested lists.
@@ -1,4 +1,4 @@
1
- import { Patch } from './Patch';
1
+ import type { Patch } from "./Patch";
2
2
  /**
3
3
  * A function that gets called when a patch is emitted.
4
4
  */
@@ -14,6 +14,9 @@ export type OnPatchesDisposer = () => void;
14
14
  /**
15
15
  * Adds a listener that will be called every time a patch is generated for the tree of the given target object.
16
16
  *
17
+ * The listener runs inside the action that made the change, so `getCurrentActionContext()` returns
18
+ * that action's context: its `rootContext` is the top-level action (for a flow step, the flow).
19
+ *
17
20
  * @param subtreeRoot Subtree root object of the patch listener.
18
21
  * @param listener The listener function that will be called everytime a patch is generated for the object or its children.
19
22
  * @returns A disposer to stop listening to patches.
@@ -23,6 +26,9 @@ export declare function onPatches(subtreeRoot: object, listener: OnPatchesListen
23
26
  * Adds a listener that will be called every time a patch is generated anywhere.
24
27
  * Usually prefer using `onPatches`.
25
28
  *
29
+ * The listener runs inside the action that made the change, so `getCurrentActionContext()` returns
30
+ * that action's context: its `rootContext` is the top-level action (for a flow step, the flow).
31
+ *
26
32
  * @param listener The listener function that will be called everytime a patch is generated anywhere.
27
33
  * @returns A disposer to stop listening to patches.
28
34
  */
@@ -1,5 +1,5 @@
1
- export * from './applyPatches';
2
- export * from './emitPatch';
3
- export * from './jsonPatch';
4
- export * from './Patch';
5
- export * from './patchRecorder';
1
+ export * from "./applyPatches";
2
+ export * from "./emitPatch";
3
+ export * from "./jsonPatch";
4
+ export * from "./Patch";
5
+ export * from "./patchRecorder";
@@ -1,5 +1,5 @@
1
- import { Path } from '../parent/pathTypes';
2
- import { Patch } from './Patch';
1
+ import type { Path } from "../parent/pathTypes";
2
+ import type { Patch } from "./Patch";
3
3
  export type JsonPatch = JsonPatchAddOperation<any> | JsonPatchRemoveOperation | JsonPatchReplaceOperation<any>;
4
4
  export interface JsonPatchBaseOperation {
5
5
  path: string;
@@ -1,5 +1,5 @@
1
- import { OnPatchesListener } from './emitPatch';
2
- import { Patch } from './Patch';
1
+ import { type OnPatchesListener } from "./emitPatch";
2
+ import type { Patch } from "./Patch";
3
3
  /**
4
4
  * Patch recorder event.
5
5
  */
@@ -1,2 +1,2 @@
1
- export * from './connectReduxDevTools';
2
- export * from './redux';
1
+ export * from "./connectReduxDevTools";
2
+ export * from "./redux";
@@ -1,6 +1,6 @@
1
- import { ActionCall } from '../action';
2
- import { OnSnapshotDisposer, OnSnapshotListener } from '../snapshot/onSnapshot';
3
- import { SnapshotOutOf } from '../snapshot/SnapshotOf';
1
+ import { type ActionCall } from "../action";
2
+ import { type OnSnapshotDisposer, type OnSnapshotListener } from "../snapshot/onSnapshot";
3
+ import type { SnapshotOutOf } from "../snapshot/SnapshotOf";
4
4
  export declare const reduxActionType = "applyAction";
5
5
  /**
6
6
  * A redux action for mobx-keystone.
@@ -1,9 +1,9 @@
1
- import { ModelClass } from '../modelShared/BaseModelShared';
2
- declare const Ref_base: import('..')._Model<unknown, {
1
+ import type { ModelClass } from "../modelShared/BaseModelShared";
2
+ declare const Ref_base: import("..")._Model<unknown, {
3
3
  /**
4
4
  * Reference id.
5
5
  */
6
- id: import('..').TypedMaybeOptionalModelProp<import('..').IdentityType<string>>;
6
+ id: import("..").TypedMaybeOptionalModelProp<import("..").IdentityType<string>>;
7
7
  }, never, never>;
8
8
  /**
9
9
  * A reference model base type.
@@ -1,5 +1,5 @@
1
- import { ObservableSet } from 'mobx';
2
- import { Ref, RefConstructor } from './Ref';
1
+ import { type ObservableSet } from "mobx";
2
+ import { Ref, type RefConstructor } from "./Ref";
3
3
  /**
4
4
  * Reference resolver type.
5
5
  */
@@ -1,5 +1,5 @@
1
- import { RefIdResolver, RefOnResolvedValueChange, RefResolver } from './core';
2
- import { RefConstructor } from './Ref';
1
+ import { type RefIdResolver, type RefOnResolvedValueChange, type RefResolver } from "./core";
2
+ import type { RefConstructor } from "./Ref";
3
3
  /**
4
4
  * Custom reference options.
5
5
  */
@@ -1,4 +1,4 @@
1
- export * from './core';
2
- export * from './customRef';
3
- export * from './Ref';
4
- export * from './rootRef';
1
+ export * from "./core";
2
+ export * from "./customRef";
3
+ export * from "./Ref";
4
+ export * from "./rootRef";
@@ -1,5 +1,5 @@
1
- import { RefIdResolver, RefOnResolvedValueChange } from './core';
2
- import { RefConstructor } from './Ref';
1
+ import { type RefIdResolver, type RefOnResolvedValueChange } from "./core";
2
+ import type { RefConstructor } from "./Ref";
3
3
  /**
4
4
  * Custom reference options.
5
5
  */
@@ -1 +1 @@
1
- export * from './rootStore';
1
+ export * from "./rootStore";
@@ -0,0 +1,55 @@
1
+ import type { CallKind } from "../action/CallKind";
2
+ import type { JsonValue } from "./JsonValue";
3
+ /**
4
+ * A call as JSON, as `Serializer.encodeCall` returns it and `Serializer.decodeCall` takes it.
5
+ */
6
+ export interface EncodedCall {
7
+ /**
8
+ * A reference to the node the call runs on; for a standalone action, its first argument.
9
+ */
10
+ target: JsonValue;
11
+ /**
12
+ * Name of the action or view.
13
+ */
14
+ name: string;
15
+ /**
16
+ * Encoded arguments; left out to read a getter.
17
+ */
18
+ args?: JsonValue[];
19
+ }
20
+ /**
21
+ * A call to an action or a view of a node.
22
+ */
23
+ export interface Call {
24
+ /**
25
+ * The node the call runs on; for a standalone action, its first argument.
26
+ */
27
+ target: object;
28
+ /**
29
+ * Name of the action or view.
30
+ */
31
+ name: string;
32
+ /**
33
+ * Arguments (for a standalone action, without the target); left out to read a getter.
34
+ */
35
+ args?: unknown[];
36
+ }
37
+ /**
38
+ * A call whose target and name are resolved, as `Serializer.decodeCall` returns it and `canCall`
39
+ * gets it.
40
+ */
41
+ export interface ResolvedCall extends Readonly<Call> {
42
+ /**
43
+ * What `name` resolved to on the target.
44
+ */
45
+ readonly kind: CallKind;
46
+ /**
47
+ * Whether it is a `@modelFlow` or a `standaloneFlow`, which needs `applyCallAsync`.
48
+ */
49
+ readonly isFlow: boolean;
50
+ /**
51
+ * The arguments as JSON, only on a call returned by `decodeCall`. Reading `args` decodes them
52
+ * (once).
53
+ */
54
+ readonly rawArgs?: JsonValue[];
55
+ }
@@ -0,0 +1,96 @@
1
+ import type { Path } from "../parent/pathTypes";
2
+ import { MobxKeystoneError } from "../utils";
3
+ /**
4
+ * The reason a call failed.
5
+ */
6
+ export declare enum CallErrorCode {
7
+ /**
8
+ * The target, or a reference in the arguments, doesn't resolve.
9
+ */
10
+ NotFound = "notFound",
11
+ /**
12
+ * Nothing by that name can be called on the target.
13
+ */
14
+ UnknownName = "unknownName",
15
+ /**
16
+ * The name exists, but can't be used as asked (e.g. a method read without `args`).
17
+ */
18
+ WrongKind = "wrongKind",
19
+ /**
20
+ * Refused by `canCall`.
21
+ */
22
+ Forbidden = "forbidden",
23
+ /**
24
+ * An argument (or any other value being decoded) failed to decode.
25
+ */
26
+ BadArgument = "badArgument",
27
+ /**
28
+ * A value (usually the result) can't be encoded.
29
+ */
30
+ CannotEncode = "cannotEncode"
31
+ }
32
+ /**
33
+ * What a `CallError` is built from, e.g. by a custom `ValueSerializer` that wants to choose the
34
+ * code (a `CallError` it throws passes through as it is; any other error is wrapped).
35
+ */
36
+ export interface CallErrorData {
37
+ /**
38
+ * The reason.
39
+ */
40
+ code: CallErrorCode;
41
+ /**
42
+ * The message, without the path and value preview the error adds to it.
43
+ */
44
+ message: string;
45
+ /**
46
+ * Path relative to the call or value, e.g. `["args", 1, "items", 3]`.
47
+ * Defaults to where the value being encoded or decoded is.
48
+ */
49
+ path?: Path;
50
+ /**
51
+ * The value the error is about, shown in the message.
52
+ */
53
+ previewValue?: unknown;
54
+ /**
55
+ * The error that caused it, if any. Its message is added to `message`, but left out of
56
+ * `toJSON()`, since it may hold the server's data.
57
+ */
58
+ cause?: unknown;
59
+ }
60
+ /**
61
+ * The JSON form of a `CallError`, safe to send back to the caller.
62
+ */
63
+ export interface CallErrorJson {
64
+ code: CallErrorCode;
65
+ message: string;
66
+ path: Path;
67
+ }
68
+ /**
69
+ * Thrown when a call or a value can't be decoded, resolved, allowed, run or encoded
70
+ * (extends `MobxKeystoneError`). Errors thrown by the action or view being called are not
71
+ * `CallError`s: they are rethrown as they are.
72
+ *
73
+ * Use `instanceof CallError` to distinguish call errors from other
74
+ * `MobxKeystoneError` instances.
75
+ */
76
+ export declare class CallError extends MobxKeystoneError {
77
+ /**
78
+ * The reason.
79
+ */
80
+ readonly code: CallErrorCode;
81
+ /**
82
+ * Where in the call or value the error is, e.g. `["args", 1]`.
83
+ */
84
+ readonly path: Path;
85
+ /**
86
+ * The error that caused it, if any.
87
+ */
88
+ readonly cause?: unknown;
89
+ private readonly jsonMessage;
90
+ constructor(data: CallErrorData);
91
+ /**
92
+ * The error as JSON, for RPC and tool layers. It leaves out the cause's message, and the value
93
+ * preview of a `CannotEncode` error, since they may hold the server's data.
94
+ */
95
+ toJSON(): CallErrorJson;
96
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A JSON value: what `JSON.parse` can return.
3
+ */
4
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
5
+ [key: string]: JsonValue;
6
+ };
@@ -0,0 +1,84 @@
1
+ import type { ActionCall } from "../action/applyAction";
2
+ import type { Call, EncodedCall, ResolvedCall } from "./Call";
3
+ import type { JsonValue } from "./JsonValue";
4
+ import type { ValueSerializer } from "./ValueSerializer";
5
+ /**
6
+ * Encodes and decodes values and calls against a tree, with a list of value serializers.
7
+ * Created with `createSerializer`.
8
+ *
9
+ * Every operation takes the root of the tree as its first argument; it must be a tree root.
10
+ */
11
+ export interface Serializer {
12
+ /**
13
+ * The list of value serializers it was created with, without the built-ins.
14
+ */
15
+ readonly serializers: readonly ValueSerializer[];
16
+ /**
17
+ * Encodes a value as JSON. Nodes of the tree go as references when a reference serializer in
18
+ * the list claims them.
19
+ *
20
+ * @param root Root of the tree.
21
+ * @param value Value to encode.
22
+ * @returns The encoded value.
23
+ */
24
+ encodeValue(root: object, value: unknown): JsonValue;
25
+ /**
26
+ * Decodes a value encoded with `encodeValue`. References are resolved against the tree;
27
+ * snapshots become new instances.
28
+ *
29
+ * @param root Root of the tree.
30
+ * @param json Value to decode.
31
+ * @returns The decoded value.
32
+ */
33
+ decodeValue(root: object, json: JsonValue): unknown;
34
+ /**
35
+ * Encodes a call (an `ActionCall`, e.g. from `onActionMiddleware`'s `onStart`, or a `Call`)
36
+ * as JSON. The target always goes as a reference; for a standalone action, it isn't repeated
37
+ * in the arguments.
38
+ *
39
+ * Encode an `ActionCall` before the action runs (e.g. in `onStart`), so its arguments are
40
+ * encoded against the tree the receiver has.
41
+ *
42
+ * @param root Root of the tree.
43
+ * @param call The call.
44
+ * @returns The encoded call.
45
+ */
46
+ encodeCall(root: object, call: ActionCall | Call): EncodedCall;
47
+ /**
48
+ * Decodes a call encoded with `encodeCall`: the target is resolved and the name resolved on
49
+ * it, nothing is run. The arguments are decoded when `args` is first read.
50
+ *
51
+ * @param root Root of the tree.
52
+ * @param json The encoded call.
53
+ * @returns The resolved call, to pass to `applyCall` or `applyCallAsync`.
54
+ */
55
+ decodeCall(root: object, json: EncodedCall | JsonValue): ResolvedCall;
56
+ }
57
+ /**
58
+ * Options of `createSerializer`.
59
+ */
60
+ export interface SerializerOptions {
61
+ /**
62
+ * Value serializers, tried in order before the built-ins when encoding.
63
+ */
64
+ serializers?: readonly ValueSerializer[];
65
+ /**
66
+ * Whether to append the built-in serializers (`builtinSerializers`) to the list.
67
+ * Defaults to `true`.
68
+ */
69
+ builtins?: boolean;
70
+ }
71
+ /**
72
+ * Creates a serializer from a list of value serializers. When encoding, a value goes through the
73
+ * first serializer whose `is` accepts it, then the built-ins (unless `builtins` is `false`),
74
+ * then as plain JSON; decoding picks the serializer by tag.
75
+ *
76
+ * @param options Options.
77
+ * @returns The serializer.
78
+ */
79
+ export declare function createSerializer(options?: SerializerOptions): Serializer;
80
+ /**
81
+ * The default serializer: nodes of the tree as path references (`pathRefs()`, value-type models
82
+ * excepted), plus the built-ins.
83
+ */
84
+ export declare const defaultSerializer: Serializer;
@@ -0,0 +1,88 @@
1
+ import type { PathElement } from "../parent/pathTypes";
2
+ import type { JsonValue } from "./JsonValue";
3
+ /**
4
+ * The key that marks a special value in the encoded JSON:
5
+ * `{ "$mobxKeystone": <tag>, "v": <payload> }`.
6
+ */
7
+ export declare const serializationMarkerKey = "$mobxKeystone";
8
+ /**
9
+ * Context passed to `ValueSerializer.is` and `ValueSerializer.encode`.
10
+ */
11
+ export interface EncodeContext {
12
+ /**
13
+ * Root of the tree the value is encoded against.
14
+ */
15
+ readonly root: object;
16
+ /**
17
+ * Encodes a nested value with the same serializer.
18
+ *
19
+ * @param value Value to encode.
20
+ * @param key Where the value is inside its parent, for error paths.
21
+ * @returns The encoded value.
22
+ */
23
+ encode(value: unknown, key?: PathElement): JsonValue;
24
+ }
25
+ /**
26
+ * Context passed to `ValueSerializer.decode`.
27
+ */
28
+ export interface DecodeContext {
29
+ /**
30
+ * Root of the tree the value is decoded against.
31
+ */
32
+ readonly root: object;
33
+ /**
34
+ * Decodes a nested value with the same serializer.
35
+ *
36
+ * @param json Value to decode.
37
+ * @param key Where the value is inside its parent, for error paths.
38
+ * @returns The decoded value.
39
+ */
40
+ decode(json: JsonValue, key?: PathElement): unknown;
41
+ }
42
+ /**
43
+ * Handles one kind of value: encodes it as `{ "$mobxKeystone": tag, "v": payload }` and decodes
44
+ * it back. `createSerializer` composes a list of them into a `Serializer`.
45
+ *
46
+ * @template T Type of the values it handles.
47
+ * @template J Type of the encoded payload (`undefined` to carry none).
48
+ */
49
+ export interface ValueSerializer<T = any, J extends JsonValue | undefined = any> {
50
+ /**
51
+ * Unique, e.g. `"geom/Polygon"`; the `$mobxKeystone` of the encoded value.
52
+ */
53
+ readonly tag: string;
54
+ /**
55
+ * Whether this serializer encodes `value`.
56
+ *
57
+ * @param value Value to check.
58
+ * @param ctx Encoding context; `ctx.root` is the tree the value is encoded against.
59
+ */
60
+ is(value: unknown, ctx: EncodeContext): value is T;
61
+ /**
62
+ * Encodes a value `is` accepted. Use `ctx.encode(child)` for nested values.
63
+ *
64
+ * @param value Value to encode.
65
+ * @param ctx Encoding context.
66
+ * @returns The payload (`v`), or `undefined` to carry none.
67
+ */
68
+ encode(value: T, ctx: EncodeContext): J;
69
+ /**
70
+ * Decodes a payload back into a value. Use `ctx.decode(child)` for nested values.
71
+ *
72
+ * @param json The payload (`v`).
73
+ * @param ctx Decoding context.
74
+ * @returns The decoded value.
75
+ */
76
+ decode(json: J, ctx: DecodeContext): T;
77
+ /**
78
+ * Only for reference serializers: whether this serializer references `value`, a node of the
79
+ * tree, when it is a call's target. Unlike `is`, it ignores options such as `when`, since the
80
+ * call must run on the node itself. A call's target goes through the first serializer whose
81
+ * `claimsTarget` accepts it (else as a `pathRef`), and only serializers with `claimsTarget`
82
+ * decode it.
83
+ *
84
+ * @param value The call's target.
85
+ * @param ctx Encoding context.
86
+ */
87
+ claimsTarget?(value: object, ctx: EncodeContext): boolean;
88
+ }
@@ -0,0 +1,54 @@
1
+ import type { Call, ResolvedCall } from "./Call";
2
+ /**
3
+ * Options of `applyCall` and `applyCallAsync`.
4
+ */
5
+ export interface ApplyCallOptions {
6
+ /**
7
+ * Decides whether a call may run, after its target and name are resolved and before anything
8
+ * runs. Returning false throws a `CallError` with code `Forbidden`; an error it throws passes
9
+ * through as it is. Reading `call.args` decodes the arguments (once).
10
+ *
11
+ * Defaults to `allowModelActions`.
12
+ */
13
+ canCall?(call: ResolvedCall): boolean;
14
+ }
15
+ /**
16
+ * The default `canCall`: allows model actions (`CallKind.ModelAction`) only.
17
+ *
18
+ * @param call The call.
19
+ * @returns Whether it is a model action.
20
+ */
21
+ export declare function allowModelActions(call: ResolvedCall): boolean;
22
+ /**
23
+ * A `canCall` that allows every call, for calls from a source that is trusted.
24
+ *
25
+ * @param _call The call.
26
+ * @returns `true`.
27
+ */
28
+ export declare function allowAnyCall(_call: ResolvedCall): boolean;
29
+ /**
30
+ * Runs a call (as returned by `Serializer.decodeCall`, or built in process) on a tree and returns
31
+ * its result as is. Flows are refused (`call.isFlow`); use `applyCallAsync` for them.
32
+ *
33
+ * The call's name is resolved on its target (see `CallKind`), then `canCall` decides whether it
34
+ * may run (by default only model actions may). Errors about the call are `CallError`s; errors
35
+ * thrown by the action or view are rethrown as they are.
36
+ *
37
+ * @template TRet Return type.
38
+ * @param root Root of the tree.
39
+ * @param call The call.
40
+ * @param options Options.
41
+ * @returns The result of the call.
42
+ */
43
+ export declare function applyCall<TRet = unknown>(root: object, call: Call | ResolvedCall, options?: ApplyCallOptions): TRet;
44
+ /**
45
+ * Like `applyCall`, but accepts flows too and always returns a promise, which resolves to the
46
+ * result once the call (or the flow) ends. Every error is a rejection.
47
+ *
48
+ * @template TRet Return type.
49
+ * @param root Root of the tree.
50
+ * @param call The call.
51
+ * @param options Options.
52
+ * @returns A promise of the result of the call.
53
+ */
54
+ export declare function applyCallAsync<TRet = unknown>(root: object, call: Call | ResolvedCall, options?: ApplyCallOptions): Promise<TRet>;