mobx-state-tree 3.12.2 → 3.15.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 (46) hide show
  1. package/README.md +103 -23
  2. package/dist/core/action.d.ts +50 -48
  3. package/dist/core/actionContext.d.ts +27 -0
  4. package/dist/core/flow.d.ts +14 -30
  5. package/dist/core/json-patch.d.ts +36 -36
  6. package/dist/core/mst-operations.d.ts +451 -444
  7. package/dist/core/node/BaseNode.d.ts +1 -1
  8. package/dist/core/node/Hook.d.ts +17 -1
  9. package/dist/core/node/create-node.d.ts +1 -1
  10. package/dist/core/node/identifier-cache.d.ts +1 -1
  11. package/dist/core/node/livelinessChecking.d.ts +37 -37
  12. package/dist/core/node/node-utils.d.ts +28 -28
  13. package/dist/core/node/object-node.d.ts +1 -1
  14. package/dist/core/node/scalar-node.d.ts +1 -1
  15. package/dist/core/process.d.ts +45 -45
  16. package/dist/core/type/type-checker.d.ts +30 -30
  17. package/dist/core/type/type.d.ts +162 -177
  18. package/dist/index.d.ts +3 -3
  19. package/dist/internal.d.ts +37 -35
  20. package/dist/middlewares/create-action-tracking-middleware.d.ts +24 -22
  21. package/dist/middlewares/createActionTrackingMiddleware2.d.ts +34 -0
  22. package/dist/middlewares/on-action.d.ts +87 -79
  23. package/dist/mobx-state-tree.js +6285 -5985
  24. package/dist/mobx-state-tree.min.js +16 -1
  25. package/dist/mobx-state-tree.module.js +6234 -5938
  26. package/dist/mobx-state-tree.umd.js +6263 -5985
  27. package/dist/mobx-state-tree.umd.min.js +16 -1
  28. package/dist/types/complex-types/array.d.ts +52 -51
  29. package/dist/types/complex-types/map.d.ts +80 -79
  30. package/dist/types/complex-types/model.d.ts +133 -125
  31. package/dist/types/index.d.ts +29 -29
  32. package/dist/types/primitives.d.ts +81 -81
  33. package/dist/types/utility-types/custom.d.ts +60 -60
  34. package/dist/types/utility-types/enumeration.d.ts +5 -5
  35. package/dist/types/utility-types/frozen.d.ts +11 -11
  36. package/dist/types/utility-types/identifier.d.ts +44 -44
  37. package/dist/types/utility-types/late.d.ts +10 -10
  38. package/dist/types/utility-types/literal.d.ts +25 -25
  39. package/dist/types/utility-types/maybe.d.ts +26 -26
  40. package/dist/types/utility-types/optional.d.ts +20 -20
  41. package/dist/types/utility-types/reference.d.ts +41 -47
  42. package/dist/types/utility-types/refinement.d.ts +10 -10
  43. package/dist/types/utility-types/snapshotProcessor.d.ts +61 -61
  44. package/dist/types/utility-types/union.d.ts +55 -55
  45. package/dist/utils.d.ts +4 -4
  46. package/package.json +16 -12
@@ -1,177 +1,162 @@
1
- import { IValidationContext, IValidationResult, IStateTreeNode, ModelPrimitive } from "../../internal";
2
- /**
3
- * Name of the properties of an object that can't be set to undefined
4
- * @hidden
5
- */
6
- export declare type DefinablePropsNames<T> = {
7
- [K in keyof T]: Extract<T[K], undefined> extends never ? K : never;
8
- }[keyof T];
9
- /**
10
- * Checks if a type is any or unknown
11
- * @hidden
12
- */
13
- export declare type IsTypeAnyOrUnknown<T> = unknown extends T ? true : false;
14
- declare type WithoutUndefined<T> = T extends undefined ? never : T;
15
- /**
16
- * Checks if a type is optional (its creation snapshot can be undefined) or not.
17
- * @hidden
18
- *
19
- * Examples:
20
- * - string = false
21
- * - undefined = true
22
- * - string | undefined = true
23
- * - string & undefined = true
24
- * - any = true
25
- * - unknown = true
26
- */
27
- export declare type IsOptionalType<IT extends IAnyType> = ExtractC<IT> extends WithoutUndefined<ExtractC<IT>> ? IsTypeAnyOrUnknown<ExtractC<IT>> : true;
28
- /**
29
- * Checks if a type supports an empty create() function
30
- * Basically !any, !unknown, X | undefined, objects with all properties being optional
31
- * @hidden
32
- */
33
- export declare type IsEmptyCreationType<O> = IsTypeAnyOrUnknown<O> extends true ? true : Extract<O, undefined> extends never ? (DefinablePropsNames<O> extends never | undefined ? true : false) : true;
34
- /**
35
- * Chooses a create function based on the creation type.
36
- * @hidden
37
- */
38
- export declare type CreateParams<C> = IsEmptyCreationType<C> extends false ? [C, any?] : [C?, any?];
39
- /**
40
- * @hidden
41
- */
42
- export declare type STNValue<T, IT extends IAnyType> = T extends object ? T & IStateTreeNode<IT> : T;
43
- /**
44
- * A type, either complex or simple.
45
- */
46
- export interface IType<C, S, T> {
47
- /**
48
- * Friendly type name.
49
- */
50
- name: string;
51
- /**
52
- * Name of the dentifier attribute or null if none.
53
- */
54
- readonly identifierAttribute?: string;
55
- create(...args: CreateParams<C>): STNValue<T, this>;
56
- /**
57
- * Creates an instance for the type given an snapshot input.
58
- *
59
- * @returns An instance of that type.
60
- */
61
- create(snapshot: C, env?: any): STNValue<T, this>;
62
- /**
63
- * Checks if a given snapshot / instance is of the given type.
64
- *
65
- * @param thing Snapshot or instance to be checked.
66
- * @returns true if the value is of the current type, false otherwise.
67
- */
68
- is(thing: any): thing is C | STNValue<T, this>;
69
- /**
70
- * Run's the type's typechecker on the given value with the given validation context.
71
- *
72
- * @param thing Value to be checked, either a snapshot or an instance.
73
- * @param context Validation context, an array of { subpaths, subtypes } that should be validated
74
- * @returns The validation result, an array with the list of validation errors.
75
- */
76
- validate(thing: C, context: IValidationContext): IValidationResult;
77
- /**
78
- * Gets the textual representation of the type as a string.
79
- */
80
- describe(): string;
81
- /**
82
- * @deprecated use `Instance<typeof MyType>` instead.
83
- * @hidden
84
- */
85
- readonly Type: STNValue<T, this>;
86
- /**
87
- * @deprecated use `SnapshotOut<typeof MyType>` instead.
88
- * @hidden
89
- */
90
- readonly SnapshotType: S;
91
- /**
92
- * @deprecated use `SnapshotIn<typeof MyType>` instead.
93
- * @hidden
94
- */
95
- readonly CreationType: C;
96
- }
97
- /**
98
- * Any kind of type.
99
- */
100
- export declare type IAnyType = IType<any, any, any>;
101
- /**
102
- * A simple type, this is, a type where the instance and the snapshot representation are the same.
103
- */
104
- export interface ISimpleType<T> extends IType<T, T, T> {
105
- }
106
- /** @hidden */
107
- export declare type Primitives = ModelPrimitive | null | undefined;
108
- /**
109
- * A complex type.
110
- * @deprecated just for compatibility with old versions, could be deprecated on the next major version
111
- * @hidden
112
- */
113
- export interface IComplexType<C, S, T> extends IType<C, S, T & object> {
114
- }
115
- /**
116
- * Any kind of complex type.
117
- */
118
- export declare type IAnyComplexType = IType<any, any, object>;
119
- /** @hidden */
120
- export declare type ExtractC<T extends IAnyType> = T extends IType<infer C, any, any> ? C : never;
121
- /** @hidden */
122
- export declare type ExtractS<T extends IAnyType> = T extends IType<any, infer S, any> ? S : never;
123
- /** @hidden */
124
- export declare type ExtractTWithoutSTN<T extends IAnyType> = T extends IType<any, any, infer X> ? X : never;
125
- /** @hidden */
126
- export declare type ExtractTWithSTN<T extends IAnyType> = T extends IType<any, any, infer X> ? X extends object ? X & IStateTreeNode<T> : X : never;
127
- /** @hidden */
128
- export declare type ExtractCSTWithoutSTN<IT extends IAnyType> = IT extends IType<infer C, infer S, infer T> ? C | S | T : never;
129
- /** @hidden */
130
- export declare type ExtractCSTWithSTN<IT extends IAnyType> = IT extends IType<infer C, infer S, infer T> ? C | S | ExtractTWithSTN<IT> : never;
131
- /**
132
- * The instance representation of a given type.
133
- */
134
- export declare type Instance<T> = T extends IType<any, any, infer TT> ? (TT extends object ? TT & IStateTreeNode<T> : TT) : T;
135
- /**
136
- * The input (creation) snapshot representation of a given type.
137
- */
138
- export declare type SnapshotIn<T> = T extends IStateTreeNode<IType<infer STNC, any, any>> ? STNC : T extends IType<infer TC, any, any> ? TC : T;
139
- /**
140
- * The output snapshot representation of a given type.
141
- */
142
- export declare type SnapshotOut<T> = T extends IStateTreeNode<IType<any, infer STNS, any>> ? STNS : T extends IType<any, infer TS, any> ? TS : T;
143
- /**
144
- * A type which is equivalent to the union of SnapshotIn and Instance types of a given typeof TYPE or typeof VARIABLE.
145
- * For primitives it defaults to the primitive itself.
146
- *
147
- * For example:
148
- * - `SnapshotOrInstance<typeof ModelA> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`
149
- * - `SnapshotOrInstance<typeof self.a (where self.a is a ModelA)> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`
150
- *
151
- * Usually you might want to use this when your model has a setter action that sets a property.
152
- *
153
- * Example:
154
- * ```ts
155
- * const ModelA = types.model({
156
- * n: types.number
157
- * })
158
- *
159
- * const ModelB = types.model({
160
- * innerModel: ModelA
161
- * }).actions(self => ({
162
- * // this will accept as property both the snapshot and the instance, whichever is preferred
163
- * setInnerModel(m: SnapshotOrInstance<typeof self.innerModel>) {
164
- * self.innerModel = cast(m)
165
- * }
166
- * }))
167
- * ```
168
- */
169
- export declare type SnapshotOrInstance<T> = SnapshotIn<T> | Instance<T>;
170
- /**
171
- * Returns if a given value represents a type.
172
- *
173
- * @param value Value to check.
174
- * @returns `true` if the value is a type.
175
- */
176
- export declare function isType(value: any): value is IAnyType;
177
- export {};
1
+ import { IValidationContext, IValidationResult, IStateTreeNode, ModelPrimitive } from "../../internal";
2
+ /**
3
+ * A state tree node value.
4
+ * @hidden
5
+ */
6
+ export declare type STNValue<T, IT extends IAnyType> = T extends object ? T & IStateTreeNode<IT> : T;
7
+ /** @hidden */
8
+ declare const $type: unique symbol;
9
+ /**
10
+ * A type, either complex or simple.
11
+ */
12
+ export interface IType<C, S, T> {
13
+ /** @hidden */
14
+ readonly [$type]: undefined;
15
+ /**
16
+ * Friendly type name.
17
+ */
18
+ name: string;
19
+ /**
20
+ * Name of the identifier attribute or null if none.
21
+ */
22
+ readonly identifierAttribute?: string;
23
+ /**
24
+ * Creates an instance for the type given an snapshot input.
25
+ *
26
+ * @returns An instance of that type.
27
+ */
28
+ create(snapshot?: C, env?: any): this["Type"];
29
+ /**
30
+ * Checks if a given snapshot / instance is of the given type.
31
+ *
32
+ * @param thing Snapshot or instance to be checked.
33
+ * @returns true if the value is of the current type, false otherwise.
34
+ */
35
+ is(thing: any): thing is C | this["Type"];
36
+ /**
37
+ * Run's the type's typechecker on the given value with the given validation context.
38
+ *
39
+ * @param thing Value to be checked, either a snapshot or an instance.
40
+ * @param context Validation context, an array of { subpaths, subtypes } that should be validated
41
+ * @returns The validation result, an array with the list of validation errors.
42
+ */
43
+ validate(thing: C, context: IValidationContext): IValidationResult;
44
+ /**
45
+ * Gets the textual representation of the type as a string.
46
+ */
47
+ describe(): string;
48
+ /**
49
+ * @deprecated use `Instance<typeof MyType>` instead.
50
+ * @hidden
51
+ */
52
+ readonly Type: STNValue<T, this>;
53
+ /**
54
+ * @deprecated do not use.
55
+ * @hidden
56
+ */
57
+ readonly TypeWithoutSTN: T;
58
+ /**
59
+ * @deprecated use `SnapshotOut<typeof MyType>` instead.
60
+ * @hidden
61
+ */
62
+ readonly SnapshotType: S;
63
+ /**
64
+ * @deprecated use `SnapshotIn<typeof MyType>` instead.
65
+ * @hidden
66
+ */
67
+ readonly CreationType: C;
68
+ }
69
+ /**
70
+ * Any kind of type.
71
+ */
72
+ export interface IAnyType extends IType<any, any, any> {
73
+ }
74
+ /**
75
+ * A simple type, this is, a type where the instance and the snapshot representation are the same.
76
+ */
77
+ export interface ISimpleType<T> extends IType<T, T, T> {
78
+ }
79
+ /** @hidden */
80
+ export declare type Primitives = ModelPrimitive | null | undefined;
81
+ /**
82
+ * A complex type.
83
+ * @deprecated just for compatibility with old versions, could be deprecated on the next major version
84
+ * @hidden
85
+ */
86
+ export interface IComplexType<C, S, T> extends IType<C, S, T & object> {
87
+ }
88
+ /**
89
+ * Any kind of complex type.
90
+ */
91
+ export interface IAnyComplexType extends IType<any, any, object> {
92
+ }
93
+ /** @hidden */
94
+ export declare type ExtractCSTWithoutSTN<IT extends {
95
+ [$type]: undefined;
96
+ CreationType: any;
97
+ SnapshotType: any;
98
+ TypeWithoutSTN: any;
99
+ }> = IT["CreationType"] | IT["SnapshotType"] | IT["TypeWithoutSTN"];
100
+ /** @hidden */
101
+ export declare type ExtractCSTWithSTN<IT extends {
102
+ [$type]: undefined;
103
+ CreationType: any;
104
+ SnapshotType: any;
105
+ Type: any;
106
+ }> = IT["CreationType"] | IT["SnapshotType"] | IT["Type"];
107
+ /**
108
+ * The instance representation of a given type.
109
+ */
110
+ export declare type Instance<T> = T extends {
111
+ [$type]: undefined;
112
+ Type: any;
113
+ } ? T["Type"] : T;
114
+ /**
115
+ * The input (creation) snapshot representation of a given type.
116
+ */
117
+ export declare type SnapshotIn<T> = T extends {
118
+ [$type]: undefined;
119
+ CreationType: any;
120
+ } ? T["CreationType"] : T extends IStateTreeNode<infer IT> ? IT["CreationType"] : T;
121
+ /**
122
+ * The output snapshot representation of a given type.
123
+ */
124
+ export declare type SnapshotOut<T> = T extends {
125
+ [$type]: undefined;
126
+ SnapshotType: any;
127
+ } ? T["SnapshotType"] : T extends IStateTreeNode<infer IT> ? IT["SnapshotType"] : T;
128
+ /**
129
+ * A type which is equivalent to the union of SnapshotIn and Instance types of a given typeof TYPE or typeof VARIABLE.
130
+ * For primitives it defaults to the primitive itself.
131
+ *
132
+ * For example:
133
+ * - `SnapshotOrInstance<typeof ModelA> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`
134
+ * - `SnapshotOrInstance<typeof self.a (where self.a is a ModelA)> = SnapshotIn<typeof ModelA> | Instance<typeof ModelA>`
135
+ *
136
+ * Usually you might want to use this when your model has a setter action that sets a property.
137
+ *
138
+ * Example:
139
+ * ```ts
140
+ * const ModelA = types.model({
141
+ * n: types.number
142
+ * })
143
+ *
144
+ * const ModelB = types.model({
145
+ * innerModel: ModelA
146
+ * }).actions(self => ({
147
+ * // this will accept as property both the snapshot and the instance, whichever is preferred
148
+ * setInnerModel(m: SnapshotOrInstance<typeof self.innerModel>) {
149
+ * self.innerModel = cast(m)
150
+ * }
151
+ * }))
152
+ * ```
153
+ */
154
+ export declare type SnapshotOrInstance<T> = SnapshotIn<T> | Instance<T>;
155
+ /**
156
+ * Returns if a given value represents a type.
157
+ *
158
+ * @param value Value to check.
159
+ * @returns `true` if the value is a type.
160
+ */
161
+ export declare function isType(value: any): value is IAnyType;
162
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { IModelType, IAnyModelType, IDisposer, IMSTMap, IMapType, IMSTArray, IArrayType, IType, IAnyType, ISimpleType, IComplexType, IAnyComplexType, IReferenceType, _CustomCSProcessor, _CustomOrOther, _CustomJoin, _NotCustomized, typecheck, escapeJsonPath, unescapeJsonPath, joinJsonPath, splitJsonPath, IJsonPatch, IReversibleJsonPatch, decorate, addMiddleware, IMiddlewareEvent, IMiddlewareHandler, IMiddlewareEventType, process, isStateTreeNode, IStateTreeNode, IAnyStateTreeNode, flow, castFlowReturn, applyAction, onAction, IActionRecorder, ISerializedActionCall, recordActions, createActionTrackingMiddleware, setLivelinessChecking, getLivelinessChecking, LivelinessMode, setLivelynessChecking, // to be deprecated
2
- LivelynessMode, // to be deprecated
3
- ModelSnapshotType, ModelCreationType, ModelSnapshotType2, ModelCreationType2, ModelInstanceType, ModelInstanceTypeProps, ModelPropertiesDeclarationToProperties, ModelProperties, ModelPropertiesDeclaration, ModelActions, ITypeUnion, CustomTypeOptions, UnionOptions, Instance, SnapshotIn, SnapshotOut, SnapshotOrInstance, TypeOrStateTreeNodeToStateTreeNode, UnionStringArray, getType, getChildType, onPatch, onSnapshot, applyPatch, IPatchRecorder, recordPatches, protect, unprotect, isProtected, applySnapshot, getSnapshot, hasParent, getParent, hasParentOfType, getParentOfType, getRoot, getPath, getPathParts, isRoot, resolvePath, resolveIdentifier, getIdentifier, tryResolve, getRelativePath, clone, detach, destroy, isAlive, addDisposer, getEnv, walk, IModelReflectionData, IModelReflectionPropertiesData, IMaybeIType, IMaybe, IMaybeNull, IOptionalIType, OptionalDefaultValueOrFunction, ValidOptionalValue, ValidOptionalValues, getMembers, getPropertyMembers, TypeOfValue, cast, castToSnapshot, castToReferenceSnapshot, isType, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, IsOptionalType, isPrimitiveType, isReferenceType, isRefinementType, isUnionType, tryReference, isValidReference, OnReferenceInvalidated, OnReferenceInvalidatedEvent, ReferenceOptions, ReferenceOptionsGetSet, ReferenceOptionsOnInvalidated, ReferenceIdentifier, ISnapshotProcessor, ISnapshotProcessors, getNodeId, types } from "./internal";
1
+ export { IModelType, IAnyModelType, IDisposer, IMSTMap, IMapType, IMSTArray, IArrayType, IType, IAnyType, ModelPrimitive, ISimpleType, IComplexType, IAnyComplexType, IReferenceType, _CustomCSProcessor, _CustomOrOther, _CustomJoin, _NotCustomized, typecheck, escapeJsonPath, unescapeJsonPath, joinJsonPath, splitJsonPath, IJsonPatch, IReversibleJsonPatch, decorate, addMiddleware, IMiddlewareEvent, IActionTrackingMiddleware2Call, IMiddlewareHandler, IMiddlewareEventType, IActionTrackingMiddlewareHooks, IActionTrackingMiddleware2Hooks, process, isStateTreeNode, IStateTreeNode, IAnyStateTreeNode, flow, castFlowReturn, applyAction, onAction, IActionRecorder, ISerializedActionCall, recordActions, createActionTrackingMiddleware, createActionTrackingMiddleware2, setLivelinessChecking, getLivelinessChecking, LivelinessMode, setLivelynessChecking, // to be deprecated
2
+ LivelynessMode, // to be deprecated
3
+ ModelSnapshotType, ModelCreationType, ModelSnapshotType2, ModelCreationType2, ModelInstanceType, ModelInstanceTypeProps, ModelPropertiesDeclarationToProperties, ModelProperties, ModelPropertiesDeclaration, ModelActions, ITypeUnion, CustomTypeOptions, UnionOptions, Instance, SnapshotIn, SnapshotOut, SnapshotOrInstance, TypeOrStateTreeNodeToStateTreeNode, UnionStringArray, getType, getChildType, onPatch, onSnapshot, applyPatch, IPatchRecorder, recordPatches, protect, unprotect, isProtected, applySnapshot, getSnapshot, hasParent, getParent, hasParentOfType, getParentOfType, getRoot, getPath, getPathParts, isRoot, resolvePath, resolveIdentifier, getIdentifier, tryResolve, getRelativePath, clone, detach, destroy, isAlive, addDisposer, getEnv, walk, IModelReflectionData, IModelReflectionPropertiesData, IMaybeIType, IMaybe, IMaybeNull, IOptionalIType, OptionalDefaultValueOrFunction, ValidOptionalValue, ValidOptionalValues, getMembers, getPropertyMembers, TypeOfValue, cast, castToSnapshot, castToReferenceSnapshot, isType, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isReferenceType, isRefinementType, isUnionType, tryReference, isValidReference, OnReferenceInvalidated, OnReferenceInvalidatedEvent, ReferenceOptions, ReferenceOptionsGetSet, ReferenceOptionsOnInvalidated, ReferenceIdentifier, ISnapshotProcessor, ISnapshotProcessors, getNodeId, IActionContext, getRunningActionContext, isActionContextChildOf, isActionContextThisOrChildOf, types } from "./internal";
@@ -1,35 +1,37 @@
1
- export * from "./core/node/livelinessChecking";
2
- export * from "./core/node/Hook";
3
- export * from "./core/mst-operations";
4
- export * from "./core/node/BaseNode";
5
- export * from "./core/node/scalar-node";
6
- export * from "./core/node/object-node";
7
- export * from "./core/type/type";
8
- export * from "./middlewares/create-action-tracking-middleware";
9
- export * from "./middlewares/on-action";
10
- export * from "./core/action";
11
- export * from "./core/type/type-checker";
12
- export * from "./core/node/identifier-cache";
13
- export * from "./core/node/create-node";
14
- export * from "./core/node/node-utils";
15
- export * from "./core/process";
16
- export * from "./core/flow";
17
- export * from "./core/json-patch";
18
- export * from "./utils";
19
- export * from "./types/utility-types/snapshotProcessor";
20
- export * from "./types/complex-types/map";
21
- export * from "./types/complex-types/array";
22
- export * from "./types/complex-types/model";
23
- export * from "./types/primitives";
24
- export * from "./types/utility-types/literal";
25
- export * from "./types/utility-types/refinement";
26
- export * from "./types/utility-types/enumeration";
27
- export * from "./types/utility-types/union";
28
- export * from "./types/utility-types/optional";
29
- export * from "./types/utility-types/maybe";
30
- export * from "./types/utility-types/late";
31
- export * from "./types/utility-types/frozen";
32
- export * from "./types/utility-types/reference";
33
- export * from "./types/utility-types/identifier";
34
- export * from "./types/utility-types/custom";
35
- export * from "./types";
1
+ export * from "./core/node/livelinessChecking";
2
+ export * from "./core/node/Hook";
3
+ export * from "./core/mst-operations";
4
+ export * from "./core/node/BaseNode";
5
+ export * from "./core/node/scalar-node";
6
+ export * from "./core/node/object-node";
7
+ export * from "./core/type/type";
8
+ export * from "./middlewares/create-action-tracking-middleware";
9
+ export * from "./middlewares/createActionTrackingMiddleware2";
10
+ export * from "./middlewares/on-action";
11
+ export * from "./core/action";
12
+ export * from "./core/actionContext";
13
+ export * from "./core/type/type-checker";
14
+ export * from "./core/node/identifier-cache";
15
+ export * from "./core/node/create-node";
16
+ export * from "./core/node/node-utils";
17
+ export * from "./core/process";
18
+ export * from "./core/flow";
19
+ export * from "./core/json-patch";
20
+ export * from "./utils";
21
+ export * from "./types/utility-types/snapshotProcessor";
22
+ export * from "./types/complex-types/map";
23
+ export * from "./types/complex-types/array";
24
+ export * from "./types/complex-types/model";
25
+ export * from "./types/primitives";
26
+ export * from "./types/utility-types/literal";
27
+ export * from "./types/utility-types/refinement";
28
+ export * from "./types/utility-types/enumeration";
29
+ export * from "./types/utility-types/union";
30
+ export * from "./types/utility-types/optional";
31
+ export * from "./types/utility-types/maybe";
32
+ export * from "./types/utility-types/late";
33
+ export * from "./types/utility-types/frozen";
34
+ export * from "./types/utility-types/reference";
35
+ export * from "./types/utility-types/identifier";
36
+ export * from "./types/utility-types/custom";
37
+ export * from "./types";
@@ -1,22 +1,24 @@
1
- import { IMiddlewareEvent, IMiddlewareHandler } from "../internal";
2
- export interface IActionTrackingMiddlewareHooks<T> {
3
- filter?: (call: IMiddlewareEvent) => boolean;
4
- onStart: (call: IMiddlewareEvent) => T;
5
- onResume: (call: IMiddlewareEvent, context: T) => void;
6
- onSuspend: (call: IMiddlewareEvent, context: T) => void;
7
- onSuccess: (call: IMiddlewareEvent, context: T, result: any) => void;
8
- onFail: (call: IMiddlewareEvent, context: T, error: any) => void;
9
- }
10
- /**
11
- * Convenience utility to create action based middleware that supports async processes more easily.
12
- * All hooks are called for both synchronous and asynchronous actions. Except that either `onSuccess` or `onFail` is called
13
- *
14
- * The create middleware tracks the process of an action (assuming it passes the `filter`).
15
- * `onResume` can return any value, which will be passed as second argument to any other hook. This makes it possible to keep state during a process.
16
- *
17
- * See the `atomic` middleware for an example
18
- *
19
- * @param hooks
20
- * @returns
21
- */
22
- export declare function createActionTrackingMiddleware<T = any>(hooks: IActionTrackingMiddlewareHooks<T>): IMiddlewareHandler;
1
+ import { IMiddlewareEvent, IMiddlewareHandler } from "../internal";
2
+ export interface IActionTrackingMiddlewareHooks<T> {
3
+ filter?: (call: IMiddlewareEvent) => boolean;
4
+ onStart: (call: IMiddlewareEvent) => T;
5
+ onResume: (call: IMiddlewareEvent, context: T) => void;
6
+ onSuspend: (call: IMiddlewareEvent, context: T) => void;
7
+ onSuccess: (call: IMiddlewareEvent, context: T, result: any) => void;
8
+ onFail: (call: IMiddlewareEvent, context: T, error: any) => void;
9
+ }
10
+ /**
11
+ * Note: Consider migrating to `createActionTrackingMiddleware2`, it is easier to use.
12
+ *
13
+ * Convenience utility to create action based middleware that supports async processes more easily.
14
+ * All hooks are called for both synchronous and asynchronous actions. Except that either `onSuccess` or `onFail` is called
15
+ *
16
+ * The create middleware tracks the process of an action (assuming it passes the `filter`).
17
+ * `onResume` can return any value, which will be passed as second argument to any other hook. This makes it possible to keep state during a process.
18
+ *
19
+ * See the `atomic` middleware for an example
20
+ *
21
+ * @param hooks
22
+ * @returns
23
+ */
24
+ export declare function createActionTrackingMiddleware<T = any>(hooks: IActionTrackingMiddlewareHooks<T>): IMiddlewareHandler;
@@ -0,0 +1,34 @@
1
+ import { IMiddlewareHandler, IActionContext } from "../internal";
2
+ export interface IActionTrackingMiddleware2Call<TEnv> extends Readonly<IActionContext> {
3
+ env: TEnv | undefined;
4
+ readonly parentCall?: IActionTrackingMiddleware2Call<TEnv>;
5
+ }
6
+ export interface IActionTrackingMiddleware2Hooks<TEnv> {
7
+ filter?: (call: IActionTrackingMiddleware2Call<TEnv>) => boolean;
8
+ onStart: (call: IActionTrackingMiddleware2Call<TEnv>) => void;
9
+ onFinish: (call: IActionTrackingMiddleware2Call<TEnv>, error?: any) => void;
10
+ }
11
+ /**
12
+ * Convenience utility to create action based middleware that supports async processes more easily.
13
+ * The flow is like this:
14
+ * - for each action: if filter passes -> `onStart` -> (inner actions recursively) -> `onFinish`
15
+ *
16
+ * Example: if we had an action `a` that called inside an action `b1`, then `b2` the flow would be:
17
+ * - `filter(a)`
18
+ * - `onStart(a)`
19
+ * - `filter(b1)`
20
+ * - `onStart(b1)`
21
+ * - `onFinish(b1)`
22
+ * - `filter(b2)`
23
+ * - `onStart(b2)`
24
+ * - `onFinish(b2)`
25
+ * - `onFinish(a)`
26
+ *
27
+ * The flow is the same no matter if the actions are sync or async.
28
+ *
29
+ * See the `atomic` middleware for an example
30
+ *
31
+ * @param hooks
32
+ * @returns
33
+ */
34
+ export declare function createActionTrackingMiddleware2<TEnv = any>(middlewareHooks: IActionTrackingMiddleware2Hooks<TEnv>): IMiddlewareHandler;