@jbrowse/mobx-state-tree 5.6.3 → 5.6.9

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 (126) hide show
  1. package/dist/core/action.d.ts +87 -0
  2. package/dist/core/action.js +228 -0
  3. package/dist/core/action.js.map +1 -0
  4. package/dist/core/actionContext.d.ts +27 -0
  5. package/dist/core/actionContext.js +42 -0
  6. package/dist/core/actionContext.js.map +1 -0
  7. package/dist/core/flow.d.ts +69 -0
  8. package/dist/core/flow.js +180 -0
  9. package/dist/core/flow.js.map +1 -0
  10. package/dist/core/json-patch.d.ts +46 -0
  11. package/dist/core/json-patch.js +133 -0
  12. package/dist/core/json-patch.js.map +1 -0
  13. package/dist/core/mst-operations.d.ts +459 -0
  14. package/dist/core/mst-operations.js +885 -0
  15. package/dist/core/mst-operations.js.map +1 -0
  16. package/dist/core/node/BaseNode.d.ts +62 -0
  17. package/dist/core/node/BaseNode.js +152 -0
  18. package/dist/core/node/BaseNode.js.map +1 -0
  19. package/dist/core/node/Hook.d.ts +17 -0
  20. package/dist/core/node/Hook.js +15 -0
  21. package/dist/core/node/Hook.js.map +1 -0
  22. package/dist/core/node/create-node.d.ts +16 -0
  23. package/dist/core/node/create-node.js +41 -0
  24. package/dist/core/node/create-node.js.map +1 -0
  25. package/dist/core/node/identifier-cache.d.ts +19 -0
  26. package/dist/core/node/identifier-cache.js +115 -0
  27. package/dist/core/node/identifier-cache.js.map +1 -0
  28. package/dist/core/node/livelinessChecking.d.ts +37 -0
  29. package/dist/core/node/livelinessChecking.js +38 -0
  30. package/dist/core/node/livelinessChecking.js.map +1 -0
  31. package/dist/core/node/node-utils.d.ts +83 -0
  32. package/dist/core/node/node-utils.js +165 -0
  33. package/dist/core/node/node-utils.js.map +1 -0
  34. package/dist/core/node/object-node.d.ts +99 -0
  35. package/dist/core/node/object-node.js +545 -0
  36. package/dist/core/node/object-node.js.map +1 -0
  37. package/dist/core/node/scalar-node.d.ts +19 -0
  38. package/dist/core/node/scalar-node.js +89 -0
  39. package/dist/core/node/scalar-node.js.map +1 -0
  40. package/dist/core/process.d.ts +50 -0
  41. package/dist/core/process.js +39 -0
  42. package/dist/core/process.js.map +1 -0
  43. package/dist/core/type/type-checker.d.ts +69 -0
  44. package/dist/core/type/type-checker.js +154 -0
  45. package/dist/core/type/type-checker.js.map +1 -0
  46. package/dist/core/type/type.d.ts +317 -0
  47. package/dist/core/type/type.js +251 -0
  48. package/dist/core/type/type.js.map +1 -0
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.js +85 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/internal.d.ts +39 -0
  53. package/dist/internal.js +60 -0
  54. package/dist/internal.js.map +1 -0
  55. package/dist/middlewares/create-action-tracking-middleware.d.ts +24 -0
  56. package/dist/middlewares/create-action-tracking-middleware.js +81 -0
  57. package/dist/middlewares/create-action-tracking-middleware.js.map +1 -0
  58. package/dist/middlewares/createActionTrackingMiddleware2.d.ts +34 -0
  59. package/dist/middlewares/createActionTrackingMiddleware2.js +133 -0
  60. package/dist/middlewares/createActionTrackingMiddleware2.js.map +1 -0
  61. package/dist/middlewares/on-action.d.ts +87 -0
  62. package/dist/middlewares/on-action.js +215 -0
  63. package/dist/middlewares/on-action.js.map +1 -0
  64. package/dist/mobx-state-tree.js +85 -0
  65. package/dist/mobx-state-tree.module.js +83 -0
  66. package/dist/types/complex-types/array.d.ts +80 -0
  67. package/dist/types/complex-types/array.js +352 -0
  68. package/dist/types/complex-types/array.js.map +1 -0
  69. package/dist/types/complex-types/map.d.ts +110 -0
  70. package/dist/types/complex-types/map.js +361 -0
  71. package/dist/types/complex-types/map.js.map +1 -0
  72. package/dist/types/complex-types/model.d.ts +192 -0
  73. package/dist/types/complex-types/model.js +477 -0
  74. package/dist/types/complex-types/model.js.map +1 -0
  75. package/dist/types/index.d.ts +33 -0
  76. package/dist/types/index.js +38 -0
  77. package/dist/types/index.js.map +1 -0
  78. package/dist/types/primitives.d.ts +124 -0
  79. package/dist/types/primitives.js +182 -0
  80. package/dist/types/primitives.js.map +1 -0
  81. package/dist/types/utility-types/custom.d.ts +74 -0
  82. package/dist/types/utility-types/custom.js +110 -0
  83. package/dist/types/utility-types/custom.js.map +1 -0
  84. package/dist/types/utility-types/enumeration.d.ts +5 -0
  85. package/dist/types/utility-types/enumeration.js +34 -0
  86. package/dist/types/utility-types/enumeration.js.map +1 -0
  87. package/dist/types/utility-types/frozen.d.ts +23 -0
  88. package/dist/types/utility-types/frozen.js +97 -0
  89. package/dist/types/utility-types/frozen.js.map +1 -0
  90. package/dist/types/utility-types/identifier.d.ts +86 -0
  91. package/dist/types/utility-types/identifier.js +129 -0
  92. package/dist/types/utility-types/identifier.js.map +1 -0
  93. package/dist/types/utility-types/late.d.ts +10 -0
  94. package/dist/types/utility-types/late.js +109 -0
  95. package/dist/types/utility-types/late.js.map +1 -0
  96. package/dist/types/utility-types/lazy.d.ts +22 -0
  97. package/dist/types/utility-types/lazy.js +76 -0
  98. package/dist/types/utility-types/lazy.js.map +1 -0
  99. package/dist/types/utility-types/literal.d.ts +37 -0
  100. package/dist/types/utility-types/literal.js +63 -0
  101. package/dist/types/utility-types/literal.js.map +1 -0
  102. package/dist/types/utility-types/maybe.d.ts +26 -0
  103. package/dist/types/utility-types/maybe.js +30 -0
  104. package/dist/types/utility-types/maybe.js.map +1 -0
  105. package/dist/types/utility-types/optional.d.ts +41 -0
  106. package/dist/types/utility-types/optional.js +140 -0
  107. package/dist/types/utility-types/optional.js.map +1 -0
  108. package/dist/types/utility-types/reference.d.ts +89 -0
  109. package/dist/types/utility-types/reference.js +392 -0
  110. package/dist/types/utility-types/reference.js.map +1 -0
  111. package/dist/types/utility-types/refinement.d.ts +10 -0
  112. package/dist/types/utility-types/refinement.js +85 -0
  113. package/dist/types/utility-types/refinement.js.map +1 -0
  114. package/dist/types/utility-types/resilient.d.ts +18 -0
  115. package/dist/types/utility-types/resilient.js +120 -0
  116. package/dist/types/utility-types/resilient.js.map +1 -0
  117. package/dist/types/utility-types/snapshotProcessor.d.ts +63 -0
  118. package/dist/types/utility-types/snapshotProcessor.js +161 -0
  119. package/dist/types/utility-types/snapshotProcessor.js.map +1 -0
  120. package/dist/types/utility-types/union.d.ts +77 -0
  121. package/dist/types/utility-types/union.js +245 -0
  122. package/dist/types/utility-types/union.js.map +1 -0
  123. package/dist/utils.d.ts +230 -0
  124. package/dist/utils.js +483 -0
  125. package/dist/utils.js.map +1 -0
  126. package/package.json +2 -2
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OptionalValue = void 0;
4
+ exports.optional = optional;
5
+ exports.isOptionalType = isOptionalType;
6
+ const internal_ts_1 = require("../../internal.js");
7
+ /**
8
+ * @hidden
9
+ * @internal
10
+ */
11
+ class OptionalValue extends internal_ts_1.BaseType {
12
+ _subtype;
13
+ _defaultValue;
14
+ optionalValues;
15
+ get flags() {
16
+ return this._subtype.flags | internal_ts_1.TypeFlags.Optional;
17
+ }
18
+ constructor(_subtype, _defaultValue, optionalValues) {
19
+ super(_subtype.name);
20
+ this._subtype = _subtype;
21
+ this._defaultValue = _defaultValue;
22
+ this.optionalValues = optionalValues;
23
+ }
24
+ describe() {
25
+ return this._subtype.describe() + "?";
26
+ }
27
+ instantiate(parent, subpath, environment, initialValue) {
28
+ if (this.optionalValues.indexOf(initialValue) >= 0) {
29
+ const defaultInstanceOrSnapshot = this.getDefaultInstanceOrSnapshot();
30
+ return this._subtype.instantiate(parent, subpath, environment, defaultInstanceOrSnapshot);
31
+ }
32
+ return this._subtype.instantiate(parent, subpath, environment, initialValue);
33
+ }
34
+ reconcile(current, newValue, parent, subpath) {
35
+ return this._subtype.reconcile(current, this.optionalValues.indexOf(newValue) < 0 && this._subtype.is(newValue)
36
+ ? newValue
37
+ : this.getDefaultInstanceOrSnapshot(), parent, subpath);
38
+ }
39
+ getDefaultInstanceOrSnapshot() {
40
+ const defaultInstanceOrSnapshot = typeof this._defaultValue === "function"
41
+ ? this._defaultValue()
42
+ : this._defaultValue;
43
+ // while static values are already snapshots and checked on types.optional
44
+ // generator functions must always be rechecked just in case
45
+ if (typeof this._defaultValue === "function") {
46
+ (0, internal_ts_1.typecheckInternal)(this, defaultInstanceOrSnapshot);
47
+ }
48
+ return defaultInstanceOrSnapshot;
49
+ }
50
+ isValidSnapshot(value, context) {
51
+ // defaulted values can be skipped
52
+ if (this.optionalValues.indexOf(value) >= 0) {
53
+ return (0, internal_ts_1.typeCheckSuccess)();
54
+ }
55
+ // bounce validation to the sub-type
56
+ return this._subtype.validate(value, context);
57
+ }
58
+ isAssignableFrom(type) {
59
+ return this._subtype.isAssignableFrom(type);
60
+ }
61
+ getSubTypes() {
62
+ return this._subtype;
63
+ }
64
+ }
65
+ exports.OptionalValue = OptionalValue;
66
+ function checkOptionalPreconditions(type, defaultValueOrFunction) {
67
+ // make sure we never pass direct instances
68
+ if (typeof defaultValueOrFunction !== "function" &&
69
+ (0, internal_ts_1.isStateTreeNode)(defaultValueOrFunction)) {
70
+ throw (0, internal_ts_1.fail)("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead");
71
+ }
72
+ (0, internal_ts_1.assertIsType)(type, 1);
73
+ if ((0, internal_ts_1.devMode)()) {
74
+ // we only check default values if they are passed directly
75
+ // if they are generator functions they will be checked once they are generated
76
+ // we don't check generator function results here to avoid generating a node just for type-checking purposes
77
+ // which might generate side-effects
78
+ if (typeof defaultValueOrFunction !== "function") {
79
+ (0, internal_ts_1.typecheckInternal)(type, defaultValueOrFunction);
80
+ }
81
+ }
82
+ }
83
+ /**
84
+ * `types.optional` - Can be used to create a property with a default value.
85
+ *
86
+ * Depending on the third argument (`optionalValues`) there are two ways of operation:
87
+ * - If the argument is not provided, then if a value is not provided in the snapshot (`undefined` or missing),
88
+ * it will default to the provided `defaultValue`
89
+ * - If the argument is provided, then if the value in the snapshot matches one of the optional values inside the array then it will
90
+ * default to the provided `defaultValue`. Additionally, if one of the optional values inside the array is `undefined` then a missing
91
+ * property is also valid.
92
+ *
93
+ * Note that it is also possible to include values of the same type as the intended subtype as optional values,
94
+ * in this case the optional value will be transformed into the `defaultValue` (e.g. `types.optional(types.string, "unnamed", [undefined, ""])`
95
+ * will transform the snapshot values `undefined` (and therefore missing) and empty strings into the string `"unnamed"` when it gets
96
+ * instantiated).
97
+ *
98
+ * If `defaultValue` is a function, the function will be invoked for every new instance.
99
+ * Applying a snapshot in which the optional value is one of the optional values (or `undefined`/_not_ present if none are provided) causes the
100
+ * value to be reset.
101
+ *
102
+ * Example:
103
+ * ```ts
104
+ * const Todo = types.model({
105
+ * title: types.string,
106
+ * subtitle1: types.optional(types.string, "", [null]),
107
+ * subtitle2: types.optional(types.string, "", [null, undefined]),
108
+ * done: types.optional(types.boolean, false),
109
+ * created: types.optional(types.Date, () => new Date()),
110
+ * })
111
+ *
112
+ * // if done is missing / undefined it will become false
113
+ * // if created is missing / undefined it will get a freshly generated timestamp
114
+ * // if subtitle1 is null it will default to "", but it cannot be missing or undefined
115
+ * // if subtitle2 is null or undefined it will default to ""; since it can be undefined it can also be missing
116
+ * const todo = Todo.create({ title: "Get coffee", subtitle1: null })
117
+ * ```
118
+ *
119
+ * @param type
120
+ * @param defaultValueOrFunction
121
+ * @param optionalValues an optional array with zero or more primitive values (string, number, boolean, null or undefined)
122
+ * that will be converted into the default. `[ undefined ]` is assumed when none is provided
123
+ * @returns
124
+ */
125
+ function optional(type, defaultValueOrFunction, optionalValues) {
126
+ checkOptionalPreconditions(type, defaultValueOrFunction);
127
+ return new OptionalValue(type, defaultValueOrFunction, optionalValues ? optionalValues : undefinedAsOptionalValues);
128
+ }
129
+ const undefinedAsOptionalValues = [undefined];
130
+ /**
131
+ * Returns if a value represents an optional type.
132
+ *
133
+ * @template IT
134
+ * @param type
135
+ * @returns
136
+ */
137
+ function isOptionalType(type) {
138
+ return (0, internal_ts_1.isType)(type) && (type.flags & internal_ts_1.TypeFlags.Optional) > 0;
139
+ }
140
+ //# sourceMappingURL=optional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../src/types/utility-types/optional.ts"],"names":[],"mappings":";;;AAgOA,4BAeC;AAWD,wCAEC;AA5PD,mDAgB0B;AAY1B;;;GAGG;AACH,MAAa,aAGX,SAAQ,sBAIT;IAMoB;IACA;IAIR;IAVX,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,uBAAS,CAAC,QAAQ,CAAA;IACjD,CAAC;IAED,YACmB,QAAY,EACZ,aAGhB,EACQ,cAA4B;QAErC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAPH,aAAQ,GAAR,QAAQ,CAAI;QACZ,kBAAa,GAAb,aAAa,CAG7B;QACQ,mBAAc,GAAd,cAAc,CAAc;IAGvC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,GAAG,CAAA;IACvC,CAAC;IAED,WAAW,CACT,MAA4B,EAC5B,OAAe,EACf,WAAgB,EAChB,YAAmC;QAEnC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,yBAAyB,GAAG,IAAI,CAAC,4BAA4B,EAAE,CAAA;YACrE,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAC9B,MAAM,EACN,OAAO,EACP,WAAW,EACX,yBAAyB,CAC1B,CAAA;QACH,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAA;IAC9E,CAAC;IAED,SAAS,CACP,OAAkB,EAClB,QAA+B,EAC/B,MAAqB,EACrB,OAAe;QAEf,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAC5B,OAAO,EACP,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,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AA;IACH,CAAC;IACD,IAAA,0BAAY,EAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACrB,IAAI,IAAA,qBAAO,GAAE,EAAE,CAAC;QACd,2DAA2D;QAC3D,+EAA+E;QAC/E,4GAA4G;QAC5G,oCAAoC;QACpC,IAAI,OAAO,sBAAsB,KAAK,UAAU,EAAE,CAAC;YACjD,IAAA,+BAAiB,EAAC,IAAI,EAAE,sBAAsB,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;AACH,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,SAAgB,QAAQ,CAItB,IAAQ,EACR,sBAA0D,EAC1D,cAA6B;IAE7B,0BAA0B,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAA;IAExD,OAAO,IAAI,aAAa,CACtB,IAAI,EACJ,sBAAsB,EACtB,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,yBAAyB,CAC5D,CAAA;AACH,CAAC;AAED,MAAM,yBAAyB,GAAgB,CAAC,SAAS,CAAC,CAAA;AAE1D;;;;;;GAMG;AACH,SAAgB,cAAc,CAAsB,IAAQ;IAC1D,OAAO,IAAA,oBAAM,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,uBAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAC9D,CAAC"}
@@ -0,0 +1,89 @@
1
+ import { type AnyObjectNode, type IAnyComplexType, type IAnyStateTreeNode, type IAnyType, type IMaybe, type IStateTreeNode, type IType, type IValidationContext, type IValidationResult, type ReferenceIdentifier, SimpleType, TypeFlags } from "../../internal.ts";
2
+ export type OnReferenceInvalidatedEvent<STN extends IAnyStateTreeNode> = {
3
+ parent: IAnyStateTreeNode;
4
+ invalidTarget: STN | undefined;
5
+ invalidId: ReferenceIdentifier;
6
+ replaceRef: (newRef: STN | null | undefined) => void;
7
+ removeRef: () => void;
8
+ cause: "detach" | "destroy" | "invalidSnapshotReference";
9
+ };
10
+ export type OnReferenceInvalidated<STN extends IAnyStateTreeNode> = (event: OnReferenceInvalidatedEvent<STN>) => void;
11
+ /** @hidden */
12
+ export type ReferenceT<IT extends IAnyType> = IT["TypeWithoutSTN"] & IStateTreeNode<IReferenceType<IT>>;
13
+ /**
14
+ * @internal
15
+ * @hidden
16
+ */
17
+ export declare class InvalidReferenceError extends Error {
18
+ constructor(m: string);
19
+ }
20
+ /**
21
+ * @internal
22
+ * @hidden
23
+ */
24
+ export declare abstract class BaseReferenceType<IT extends IAnyComplexType> extends SimpleType<ReferenceIdentifier, ReferenceIdentifier, IT["TypeWithoutSTN"]> {
25
+ protected readonly targetType: IT;
26
+ private readonly onInvalidated?;
27
+ readonly flags = TypeFlags.Reference;
28
+ constructor(targetType: IT, onInvalidated?: OnReferenceInvalidated<ReferenceT<IT>> | undefined);
29
+ describe(): string;
30
+ isAssignableFrom(type: IAnyType): boolean;
31
+ isValidSnapshot(value: this["C"], context: IValidationContext): IValidationResult;
32
+ private fireInvalidated;
33
+ private addTargetNodeWatcher;
34
+ protected watchTargetNodeForInvalidations(storedRefNode: this["N"], identifier: ReferenceIdentifier, customGetSet: ReferenceOptionsGetSet<IT> | undefined): void;
35
+ }
36
+ /**
37
+ * @internal
38
+ * @hidden
39
+ */
40
+ export declare class IdentifierReferenceType<IT extends IAnyComplexType> extends BaseReferenceType<IT> {
41
+ constructor(targetType: IT, onInvalidated?: OnReferenceInvalidated<ReferenceT<IT>>);
42
+ getValue(storedRefNode: this["N"]): any;
43
+ getSnapshot(storedRefNode: this["N"]): ReferenceIdentifier;
44
+ instantiate(parent: AnyObjectNode | null, subpath: string, environment: any, initialValue: this["C"] | this["T"]): this["N"];
45
+ reconcile(current: this["N"], newValue: this["C"] | this["T"], parent: AnyObjectNode, subpath: string): this["N"];
46
+ }
47
+ /**
48
+ * @internal
49
+ * @hidden
50
+ */
51
+ export declare class CustomReferenceType<IT extends IAnyComplexType> extends BaseReferenceType<IT> {
52
+ private readonly options;
53
+ constructor(targetType: IT, options: ReferenceOptionsGetSet<IT>, onInvalidated?: OnReferenceInvalidated<ReferenceT<IT>>);
54
+ getValue(storedRefNode: this["N"]): any;
55
+ getSnapshot(storedRefNode: this["N"]): any;
56
+ instantiate(parent: AnyObjectNode | null, subpath: string, environment: any, newValue: this["C"] | this["T"]): this["N"];
57
+ reconcile(current: this["N"], newValue: this["C"] | this["T"], parent: AnyObjectNode, subpath: string): this["N"];
58
+ }
59
+ export interface ReferenceOptionsGetSet<IT extends IAnyComplexType> {
60
+ get(identifier: ReferenceIdentifier, parent: IAnyStateTreeNode | null): ReferenceT<IT>;
61
+ set(value: ReferenceT<IT>, parent: IAnyStateTreeNode | null): ReferenceIdentifier;
62
+ }
63
+ export interface ReferenceOptionsOnInvalidated<IT extends IAnyComplexType> {
64
+ onInvalidated: OnReferenceInvalidated<ReferenceT<IT>>;
65
+ }
66
+ export type ReferenceOptions<IT extends IAnyComplexType> = ReferenceOptionsGetSet<IT> | ReferenceOptionsOnInvalidated<IT> | (ReferenceOptionsGetSet<IT> & ReferenceOptionsOnInvalidated<IT>);
67
+ /** @hidden */
68
+ export interface IReferenceType<IT extends IAnyComplexType> extends IType<ReferenceIdentifier, ReferenceIdentifier, IT["TypeWithoutSTN"]> {
69
+ }
70
+ /**
71
+ * `types.reference` - Creates a reference to another type, which should have defined an identifier.
72
+ * See also the [reference and identifiers](https://github.com/mobxjs/mobx-state-tree#references-and-identifiers) section.
73
+ */
74
+ export declare function reference<IT extends IAnyComplexType>(subType: IT, options?: ReferenceOptions<IT>): IReferenceType<IT>;
75
+ /**
76
+ * Returns if a given value represents a reference type.
77
+ *
78
+ * @param type
79
+ * @returns
80
+ */
81
+ export declare function isReferenceType<IT extends IReferenceType<any>>(type: IT): type is IT;
82
+ export declare function safeReference<IT extends IAnyComplexType>(subType: IT, options: (ReferenceOptionsGetSet<IT> | object) & {
83
+ acceptsUndefined: false;
84
+ onInvalidated?: OnReferenceInvalidated<ReferenceT<IT>>;
85
+ }): IReferenceType<IT>;
86
+ export declare function safeReference<IT extends IAnyComplexType>(subType: IT, options?: (ReferenceOptionsGetSet<IT> | object) & {
87
+ acceptsUndefined?: boolean;
88
+ onInvalidated?: OnReferenceInvalidated<ReferenceT<IT>>;
89
+ }): IMaybe<IReferenceType<IT>>;
@@ -0,0 +1,392 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomReferenceType = exports.IdentifierReferenceType = exports.BaseReferenceType = exports.InvalidReferenceError = void 0;
4
+ exports.reference = reference;
5
+ exports.isReferenceType = isReferenceType;
6
+ exports.safeReference = safeReference;
7
+ const internal_ts_1 = require("../../internal.js");
8
+ function getInvalidationCause(hook) {
9
+ switch (hook) {
10
+ case internal_ts_1.Hook.beforeDestroy:
11
+ return "destroy";
12
+ case internal_ts_1.Hook.beforeDetach:
13
+ return "detach";
14
+ default:
15
+ return undefined;
16
+ }
17
+ }
18
+ class StoredReference {
19
+ targetType;
20
+ identifier;
21
+ node;
22
+ resolvedReference;
23
+ constructor(value, targetType) {
24
+ this.targetType = targetType;
25
+ if ((0, internal_ts_1.isValidIdentifier)(value)) {
26
+ this.identifier = value;
27
+ }
28
+ else if ((0, internal_ts_1.isStateTreeNode)(value)) {
29
+ const targetNode = (0, internal_ts_1.getStateTreeNode)(value);
30
+ if (!targetNode.identifierAttribute) {
31
+ throw (0, internal_ts_1.fail)(`Can only store references with a defined identifier attribute.`);
32
+ }
33
+ const id = targetNode.unnormalizedIdentifier;
34
+ if (id === null || id === undefined) {
35
+ throw (0, internal_ts_1.fail)(`Can only store references to tree nodes with a defined identifier.`);
36
+ }
37
+ this.identifier = id;
38
+ }
39
+ else {
40
+ throw (0, internal_ts_1.fail)(`Can only store references to tree nodes or identifiers, got: '${value}'`);
41
+ }
42
+ }
43
+ updateResolvedReference(node) {
44
+ const normalizedId = (0, internal_ts_1.normalizeIdentifier)(this.identifier);
45
+ const root = node.root;
46
+ const lastCacheModification = root.identifierCache.getLastCacheModificationPerId(normalizedId);
47
+ if (!this.resolvedReference ||
48
+ this.resolvedReference.lastCacheModification !== lastCacheModification) {
49
+ const { targetType } = this;
50
+ // reference was initialized with the identifier of the target
51
+ const target = root.identifierCache.resolve(targetType, normalizedId);
52
+ if (!target) {
53
+ throw new InvalidReferenceError(`[mobx-state-tree] Failed to resolve reference '${this.identifier}' to type '${this.targetType.name}' (from node: ${node.path})`);
54
+ }
55
+ this.resolvedReference = {
56
+ node: target,
57
+ lastCacheModification: lastCacheModification
58
+ };
59
+ }
60
+ }
61
+ get resolvedValue() {
62
+ this.updateResolvedReference(this.node);
63
+ return this.resolvedReference.node.value;
64
+ }
65
+ }
66
+ /**
67
+ * @internal
68
+ * @hidden
69
+ */
70
+ class InvalidReferenceError extends Error {
71
+ constructor(m) {
72
+ super(m);
73
+ Object.setPrototypeOf(this, InvalidReferenceError.prototype);
74
+ }
75
+ }
76
+ exports.InvalidReferenceError = InvalidReferenceError;
77
+ /**
78
+ * @internal
79
+ * @hidden
80
+ */
81
+ class BaseReferenceType extends internal_ts_1.SimpleType {
82
+ targetType;
83
+ onInvalidated;
84
+ flags = internal_ts_1.TypeFlags.Reference;
85
+ constructor(targetType, onInvalidated) {
86
+ super(`reference(${targetType.name})`);
87
+ this.targetType = targetType;
88
+ this.onInvalidated = onInvalidated;
89
+ }
90
+ describe() {
91
+ return this.name;
92
+ }
93
+ isAssignableFrom(type) {
94
+ return this.targetType.isAssignableFrom(type);
95
+ }
96
+ isValidSnapshot(value, context) {
97
+ return (0, internal_ts_1.isValidIdentifier)(value)
98
+ ? (0, internal_ts_1.typeCheckSuccess)()
99
+ : (0, internal_ts_1.typeCheckFailure)(context, value, "Value is not a valid identifier, which is a string or a number");
100
+ }
101
+ fireInvalidated(cause, storedRefNode, referenceId, refTargetNode) {
102
+ // to actually invalidate a reference we need an alive parent,
103
+ // since it is a scalar value (immutable-ish) and we need to change it
104
+ // from the parent
105
+ const storedRefParentNode = storedRefNode.parent;
106
+ if (!storedRefParentNode || !storedRefParentNode.isAlive) {
107
+ return;
108
+ }
109
+ const storedRefParentValue = storedRefParentNode.storedValue;
110
+ if (!storedRefParentValue) {
111
+ return;
112
+ }
113
+ this.onInvalidated({
114
+ cause,
115
+ parent: storedRefParentValue,
116
+ invalidTarget: refTargetNode ? refTargetNode.storedValue : undefined,
117
+ invalidId: referenceId,
118
+ replaceRef(newRef) {
119
+ (0, internal_ts_1.applyPatch)(storedRefNode.root.storedValue, {
120
+ op: "replace",
121
+ value: newRef,
122
+ path: storedRefNode.path
123
+ });
124
+ },
125
+ removeRef() {
126
+ if ((0, internal_ts_1.isModelType)(storedRefParentNode.type)) {
127
+ this.replaceRef(undefined);
128
+ }
129
+ else {
130
+ (0, internal_ts_1.applyPatch)(storedRefNode.root.storedValue, {
131
+ op: "remove",
132
+ path: storedRefNode.path
133
+ });
134
+ }
135
+ }
136
+ });
137
+ }
138
+ addTargetNodeWatcher(storedRefNode, referenceId) {
139
+ // this will make sure the target node becomes created
140
+ const refTargetValue = this.getValue(storedRefNode);
141
+ if (!refTargetValue) {
142
+ return undefined;
143
+ }
144
+ const refTargetNode = (0, internal_ts_1.getStateTreeNode)(refTargetValue);
145
+ const hookHandler = (_, refTargetNodeHook) => {
146
+ const cause = getInvalidationCause(refTargetNodeHook);
147
+ if (!cause) {
148
+ return;
149
+ }
150
+ this.fireInvalidated(cause, storedRefNode, referenceId, refTargetNode);
151
+ };
152
+ const refTargetDetachHookDisposer = refTargetNode.registerHook(internal_ts_1.Hook.beforeDetach, hookHandler);
153
+ const refTargetDestroyHookDisposer = refTargetNode.registerHook(internal_ts_1.Hook.beforeDestroy, hookHandler);
154
+ return () => {
155
+ refTargetDetachHookDisposer();
156
+ refTargetDestroyHookDisposer();
157
+ };
158
+ }
159
+ watchTargetNodeForInvalidations(storedRefNode, identifier, customGetSet) {
160
+ if (!this.onInvalidated) {
161
+ return;
162
+ }
163
+ let onRefTargetDestroyedHookDisposer;
164
+ // get rid of the watcher hook when the stored ref node is destroyed
165
+ // detached is ignored since scalar nodes (where the reference resides) cannot be detached
166
+ storedRefNode.registerHook(internal_ts_1.Hook.beforeDestroy, () => {
167
+ if (onRefTargetDestroyedHookDisposer) {
168
+ onRefTargetDestroyedHookDisposer();
169
+ }
170
+ });
171
+ const startWatching = (sync) => {
172
+ // re-create hook in case the stored ref gets reattached
173
+ if (onRefTargetDestroyedHookDisposer) {
174
+ onRefTargetDestroyedHookDisposer();
175
+ }
176
+ // make sure the target node is actually there and initialized
177
+ const storedRefParentNode = storedRefNode.parent;
178
+ const storedRefParentValue = storedRefParentNode && storedRefParentNode.storedValue;
179
+ if (storedRefParentNode &&
180
+ storedRefParentNode.isAlive &&
181
+ storedRefParentValue) {
182
+ let refTargetNodeExists;
183
+ if (customGetSet) {
184
+ refTargetNodeExists = !!customGetSet.get(identifier, storedRefParentValue);
185
+ }
186
+ else {
187
+ refTargetNodeExists = storedRefNode.root.identifierCache.has(this.targetType, (0, internal_ts_1.normalizeIdentifier)(identifier));
188
+ }
189
+ if (!refTargetNodeExists) {
190
+ // we cannot change the reference in sync mode
191
+ // since we are in the middle of a reconciliation/instantiation and the change would be overwritten
192
+ // for those cases just let the wrong reference be assigned and fail upon usage
193
+ // (like current references do)
194
+ // this means that effectively this code will only run when it is created from a snapshot
195
+ if (!sync) {
196
+ this.fireInvalidated("invalidSnapshotReference", storedRefNode, identifier, null);
197
+ }
198
+ }
199
+ else {
200
+ onRefTargetDestroyedHookDisposer = this.addTargetNodeWatcher(storedRefNode, identifier);
201
+ }
202
+ }
203
+ };
204
+ if (storedRefNode.state === internal_ts_1.NodeLifeCycle.FINALIZED) {
205
+ // already attached, so the whole tree is ready
206
+ startWatching(true);
207
+ }
208
+ else {
209
+ if (!storedRefNode.isRoot) {
210
+ // start watching once the whole tree is ready
211
+ storedRefNode.root.registerHook(internal_ts_1.Hook.afterCreationFinalization, () => {
212
+ // make sure to attach it so it can start listening
213
+ if (storedRefNode.parent) {
214
+ storedRefNode.parent.createObservableInstanceIfNeeded();
215
+ }
216
+ });
217
+ }
218
+ // start watching once the node is attached somewhere / parent changes
219
+ storedRefNode.registerHook(internal_ts_1.Hook.afterAttach, () => {
220
+ startWatching(false);
221
+ });
222
+ }
223
+ }
224
+ }
225
+ exports.BaseReferenceType = BaseReferenceType;
226
+ /**
227
+ * @internal
228
+ * @hidden
229
+ */
230
+ class IdentifierReferenceType extends BaseReferenceType {
231
+ constructor(targetType, onInvalidated) {
232
+ super(targetType, onInvalidated);
233
+ }
234
+ getValue(storedRefNode) {
235
+ if (!storedRefNode.isAlive) {
236
+ return undefined;
237
+ }
238
+ const storedRef = storedRefNode.storedValue;
239
+ return storedRef.resolvedValue;
240
+ }
241
+ getSnapshot(storedRefNode) {
242
+ const ref = storedRefNode.storedValue;
243
+ return ref.identifier;
244
+ }
245
+ instantiate(parent, subpath, environment, initialValue) {
246
+ const identifier = (0, internal_ts_1.isStateTreeNode)(initialValue)
247
+ ? (0, internal_ts_1.getIdentifier)(initialValue)
248
+ : initialValue;
249
+ const storedRef = new StoredReference(initialValue, this.targetType);
250
+ const storedRefNode = (0, internal_ts_1.createScalarNode)(this, parent, subpath, environment, storedRef);
251
+ storedRef.node = storedRefNode;
252
+ this.watchTargetNodeForInvalidations(storedRefNode, identifier, undefined);
253
+ return storedRefNode;
254
+ }
255
+ reconcile(current, newValue, parent, subpath) {
256
+ if (!current.isDetaching && current.type === this) {
257
+ const compareByValue = (0, internal_ts_1.isStateTreeNode)(newValue);
258
+ const ref = current.storedValue;
259
+ if ((!compareByValue && ref.identifier === newValue) ||
260
+ (compareByValue && ref.resolvedValue === newValue)) {
261
+ current.setParent(parent, subpath);
262
+ return current;
263
+ }
264
+ }
265
+ const newNode = this.instantiate(parent, subpath, undefined, newValue);
266
+ current.die(); // noop if detaching
267
+ return newNode;
268
+ }
269
+ }
270
+ exports.IdentifierReferenceType = IdentifierReferenceType;
271
+ /**
272
+ * @internal
273
+ * @hidden
274
+ */
275
+ class CustomReferenceType extends BaseReferenceType {
276
+ options;
277
+ constructor(targetType, options, onInvalidated) {
278
+ super(targetType, onInvalidated);
279
+ this.options = options;
280
+ }
281
+ getValue(storedRefNode) {
282
+ if (!storedRefNode.isAlive) {
283
+ return undefined;
284
+ }
285
+ const referencedNode = this.options.get(storedRefNode.storedValue, storedRefNode.parent ? storedRefNode.parent.storedValue : null);
286
+ return referencedNode;
287
+ }
288
+ getSnapshot(storedRefNode) {
289
+ return storedRefNode.storedValue;
290
+ }
291
+ instantiate(parent, subpath, environment, newValue) {
292
+ const identifier = (0, internal_ts_1.isStateTreeNode)(newValue)
293
+ ? this.options.set(newValue, parent ? parent.storedValue : null)
294
+ : newValue;
295
+ const storedRefNode = (0, internal_ts_1.createScalarNode)(this, parent, subpath, environment, identifier);
296
+ this.watchTargetNodeForInvalidations(storedRefNode, identifier, this.options);
297
+ return storedRefNode;
298
+ }
299
+ reconcile(current, newValue, parent, subpath) {
300
+ const newIdentifier = (0, internal_ts_1.isStateTreeNode)(newValue)
301
+ ? this.options.set(newValue, current ? current.storedValue : null)
302
+ : newValue;
303
+ if (!current.isDetaching &&
304
+ current.type === this &&
305
+ current.storedValue === newIdentifier) {
306
+ current.setParent(parent, subpath);
307
+ return current;
308
+ }
309
+ const newNode = this.instantiate(parent, subpath, undefined, newIdentifier);
310
+ current.die(); // noop if detaching
311
+ return newNode;
312
+ }
313
+ }
314
+ exports.CustomReferenceType = CustomReferenceType;
315
+ /**
316
+ * `types.reference` - Creates a reference to another type, which should have defined an identifier.
317
+ * See also the [reference and identifiers](https://github.com/mobxjs/mobx-state-tree#references-and-identifiers) section.
318
+ */
319
+ function reference(subType, options) {
320
+ (0, internal_ts_1.assertIsType)(subType, 1);
321
+ if ((0, internal_ts_1.devMode)()) {
322
+ if (options && typeof options === "string") {
323
+ // istanbul ignore next
324
+ throw (0, internal_ts_1.fail)("References with base path are no longer supported. Please remove the base path.");
325
+ }
326
+ }
327
+ const getSetOptions = options
328
+ ? options
329
+ : undefined;
330
+ const onInvalidated = options
331
+ ? options.onInvalidated
332
+ : undefined;
333
+ if (getSetOptions && (getSetOptions.get || getSetOptions.set)) {
334
+ if ((0, internal_ts_1.devMode)()) {
335
+ if (!getSetOptions.get || !getSetOptions.set) {
336
+ throw (0, internal_ts_1.fail)("reference options must either contain both a 'get' and a 'set' method or none of them");
337
+ }
338
+ }
339
+ return new CustomReferenceType(subType, {
340
+ get: getSetOptions.get,
341
+ set: getSetOptions.set
342
+ }, onInvalidated);
343
+ }
344
+ else {
345
+ return new IdentifierReferenceType(subType, onInvalidated);
346
+ }
347
+ }
348
+ /**
349
+ * Returns if a given value represents a reference type.
350
+ *
351
+ * @param type
352
+ * @returns
353
+ */
354
+ function isReferenceType(type) {
355
+ return (type.flags & internal_ts_1.TypeFlags.Reference) > 0;
356
+ }
357
+ /**
358
+ * `types.safeReference` - A safe reference is like a standard reference, except that it accepts the undefined value by default
359
+ * and automatically sets itself to undefined (when the parent is a model) / removes itself from arrays and maps
360
+ * when the reference it is pointing to gets detached/destroyed.
361
+ *
362
+ * The optional options parameter object accepts a parameter named `acceptsUndefined`, which is set to true by default, so it is suitable
363
+ * for model properties.
364
+ * When used inside collections (arrays/maps), it is recommended to set this option to false so it can't take undefined as value,
365
+ * which is usually the desired in those cases.
366
+ * Additionally, the optional options parameter object accepts a parameter named `onInvalidated`, which will be called when the reference target node that the reference is pointing to is about to be detached/destroyed
367
+ *
368
+ * Strictly speaking it is a `types.maybe(types.reference(X))` (when `acceptsUndefined` is set to true, the default) and
369
+ * `types.reference(X)` (when `acceptsUndefined` is set to false), both of them with a customized `onInvalidated` option.
370
+ *
371
+ * @param subType
372
+ * @param options
373
+ * @returns
374
+ */
375
+ function safeReference(subType, options) {
376
+ const refType = reference(subType, {
377
+ ...options,
378
+ onInvalidated(ev) {
379
+ if (options && options.onInvalidated) {
380
+ options.onInvalidated(ev);
381
+ }
382
+ ev.removeRef();
383
+ }
384
+ });
385
+ if (options && options.acceptsUndefined === false) {
386
+ return refType;
387
+ }
388
+ else {
389
+ return (0, internal_ts_1.maybe)(refType);
390
+ }
391
+ }
392
+ //# sourceMappingURL=reference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference.js","sourceRoot":"","sources":["../../../src/types/utility-types/reference.ts"],"names":[],"mappings":";;;AAuhBA,8BAyCC;AAQD,0CAIC;AAkCD,sCAsBC;AApoBD,mDA+B0B;AAe1B,SAAS,oBAAoB,CAAC,IAAU;IACtC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAI,CAAC,aAAa;YACrB,OAAO,SAAS,CAAA;QAClB,KAAK,kBAAI,CAAC,YAAY;YACpB,OAAO,QAAQ,CAAA;QACjB;YACE,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC;AAMD,MAAM,eAAe;IAWA;IAVV,UAAU,CAAsB;IACzC,IAAI,CAAU;IAEN,iBAAiB,CAGxB;IAED,YACE,KAA2C,EAC1B,UAAc;QAAd,eAAU,GAAV,UAAU,CAAI;QAE/B,IAAI,IAAA,+BAAiB,EAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAA;QACzB,CAAC;aAAM,IAAI,IAAA,6BAAe,EAAC,KAAK,CAAC,EAAE,CAAC;YAClC,MAAM,UAAU,GAAG,IAAA,8BAAgB,EAAC,KAAK,CAAC,CAAA;YAC1C,IAAI,CAAC,UAAU,CAAC,mBAAmB,EAAE,CAAC;gBACpC,MAAM,IAAA,kBAAI,EACR,gEAAgE,CACjE,CAAA;YACH,CAAC;YACD,MAAM,EAAE,GAAG,UAAU,CAAC,sBAAsB,CAAA;YAC5C,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;gBACpC,MAAM,IAAA,kBAAI,EACR,oEAAoE,CACrE,CAAA;YACH,CAAC;YACD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;QACtB,CAAC;aAAM,CAAC;YACN,MAAM,IAAA,kBAAI,EACR,iEAAiE,KAAK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IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type IAnyType } from "../../internal.ts";
2
+ export declare function refinement<IT extends IAnyType>(name: string, type: IT, predicate: (snapshot: IT["CreationType"]) => boolean, message?: string | ((v: IT["CreationType"]) => string)): IT;
3
+ export declare function refinement<IT extends IAnyType>(type: IT, predicate: (snapshot: IT["CreationType"]) => boolean, message?: string | ((v: IT["CreationType"]) => string)): IT;
4
+ /**
5
+ * Returns if a given value is a refinement type.
6
+ *
7
+ * @param type
8
+ * @returns
9
+ */
10
+ export declare function isRefinementType<IT extends IAnyType>(type: IT): type is IT;