mobx-keystone 1.20.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +864 -853
- package/README.md +61 -61
- package/dist/mobx-keystone.esm.js +11336 -11148
- package/dist/mobx-keystone.esm.mjs +11336 -11148
- package/dist/mobx-keystone.umd.js +12229 -11738
- package/dist/types/actionMiddlewares/undoMiddleware.d.ts +1 -1
- package/dist/types/modelShared/prop.d.ts +5 -0
- package/dist/types/redux/connectReduxDevTools.d.ts +17 -4
- package/dist/types/ref/Ref.d.ts +1 -1
- package/dist/types/treeUtils/sandbox.d.ts +1 -1
- package/dist/types/types/TypeChecker.d.ts +1 -1
- package/dist/types/types/arrayBased/typesArray.d.ts +1 -1
- package/dist/types/types/arrayBased/typesTuple.d.ts +1 -1
- package/dist/types/types/objectBased/typesArraySet.d.ts +1 -1
- package/dist/types/types/objectBased/typesDataModelData.d.ts +1 -1
- package/dist/types/types/objectBased/typesModel.d.ts +1 -1
- package/dist/types/types/objectBased/typesObject.d.ts +3 -3
- package/dist/types/types/objectBased/typesObjectMap.d.ts +1 -1
- package/dist/types/types/objectBased/typesRecord.d.ts +1 -1
- package/dist/types/types/primitiveBased/typesPrimitive.d.ts +1 -1
- package/dist/types/types/types.d.ts +3 -3
- package/dist/types/types/utility/typesCodec.d.ts +1 -6
- package/dist/types/types/utility/typesCodecCore.d.ts +1 -1
- package/dist/types/types/utility/typesOr.d.ts +1 -1
- package/dist/types/types/utility/typesRefinement.d.ts +1 -1
- package/dist/types/types/utility/typesSkipCheck.d.ts +1 -1
- package/dist/types/types/utility/typesTag.d.ts +1 -1
- package/dist/types/wrappers/ObjectMap.d.ts +2 -0
- package/dist/types/wrappers/asMap.d.ts +10 -6
- package/package.json +14 -12
- package/src/action/applyAction.ts +125 -114
- package/src/action/applyMethodCall.ts +37 -37
- package/src/action/isModelAction.ts +16 -16
- package/src/action/middleware.ts +137 -137
- package/src/action/modelFlow.ts +240 -240
- package/src/action/modelFlowPromiseGenerator.ts +127 -125
- package/src/action/pendingActions.ts +42 -42
- package/src/action/wrapInAction.ts +156 -156
- package/src/actionMiddlewares/actionSerialization/actionSerialization.ts +1 -1
- package/src/actionMiddlewares/actionSerialization/applySerializedAction.ts +172 -172
- package/src/actionMiddlewares/actionSerialization/arraySerializer.ts +20 -20
- package/src/actionMiddlewares/actionSerialization/dateSerializer.ts +17 -17
- package/src/actionMiddlewares/actionSerialization/mapSerializer.ts +42 -42
- package/src/actionMiddlewares/actionSerialization/objectPathSerializer.ts +50 -50
- package/src/actionMiddlewares/actionSerialization/objectSnapshotSerializer.ts +21 -21
- package/src/actionMiddlewares/actionSerialization/plainObjectSerializer.ts +24 -32
- package/src/actionMiddlewares/actionSerialization/primitiveSerializer.ts +51 -51
- package/src/actionMiddlewares/actionSerialization/setSerializer.ts +37 -37
- package/src/actionMiddlewares/actionTrackingMiddleware.ts +3 -3
- package/src/actionMiddlewares/onActionMiddleware.ts +2 -2
- package/src/actionMiddlewares/readonlyMiddleware.ts +2 -2
- package/src/actionMiddlewares/transactionMiddleware.ts +4 -4
- package/src/actionMiddlewares/undoMiddleware.ts +804 -796
- package/src/actionMiddlewares/utils.ts +2 -2
- package/src/computedTree/computedTree.ts +143 -143
- package/src/context/context.ts +1 -1
- package/src/dataModel/BaseDataModel.ts +194 -192
- package/src/dataModel/actions.ts +1 -1
- package/src/dataModel/newDataModel.ts +57 -57
- package/src/deepChange/index.ts +1 -1
- package/src/deepChange/onDeepChange.ts +244 -244
- package/src/frozen/Frozen.ts +146 -146
- package/src/globalConfig/globalConfig.ts +107 -107
- package/src/index.ts +24 -24
- package/src/model/BaseModel.ts +275 -273
- package/src/model/ModelConstructorOptions.ts +15 -15
- package/src/model/getModelMetadata.ts +51 -51
- package/src/model/index.ts +6 -6
- package/src/model/mixins.ts +288 -288
- package/src/model/newModel.ts +301 -301
- package/src/model/utils.ts +249 -249
- package/src/modelShared/modelDecorator.ts +260 -253
- package/src/modelShared/modelInfo.ts +50 -50
- package/src/modelShared/modelSymbols.ts +3 -3
- package/src/modelShared/newModel.ts +25 -25
- package/src/modelShared/prop.ts +713 -684
- package/src/modelShared/sharedInternalModel.ts +427 -417
- package/src/modelShared/utils.ts +24 -24
- package/src/parent/core.ts +65 -65
- package/src/parent/coreObjectChildren.ts +180 -180
- package/src/parent/detach.ts +47 -47
- package/src/parent/findParent.ts +1 -1
- package/src/parent/getChildrenObjects.ts +25 -25
- package/src/parent/path.ts +386 -381
- package/src/parent/setParent.ts +149 -149
- package/src/parent/walkTree.ts +1 -1
- package/src/patch/applyPatches.ts +187 -187
- package/src/patch/jsonPatch.ts +108 -108
- package/src/patch/patchRecorder.ts +6 -1
- package/src/redux/connectReduxDevTools.ts +39 -7
- package/src/redux/redux.ts +6 -2
- package/src/ref/Ref.ts +1 -1
- package/src/ref/core.ts +339 -345
- package/src/ref/customRef.ts +3 -3
- package/src/ref/rootRef.ts +100 -100
- package/src/rootStore/attachDetach.ts +89 -89
- package/src/rootStore/rootStore.ts +1 -1
- package/src/snapshot/SnapshotOf.ts +104 -104
- package/src/snapshot/SnapshotProcessingError.ts +45 -45
- package/src/snapshot/applySnapshot.ts +177 -181
- package/src/snapshot/cloneTreeValue.ts +30 -30
- package/src/snapshot/fromArraySnapshot.ts +27 -33
- package/src/snapshot/fromModelSnapshot.ts +70 -70
- package/src/snapshot/fromPlainObjectSnapshot.ts +47 -42
- package/src/snapshot/fromSnapshot.ts +198 -198
- package/src/snapshot/getSnapshot.ts +80 -79
- package/src/snapshot/index.ts +8 -8
- package/src/snapshot/internal.ts +230 -230
- package/src/snapshot/reconcileArraySnapshot.ts +70 -70
- package/src/snapshot/reconcileModelSnapshot.ts +155 -150
- package/src/snapshot/reconcilePlainObjectSnapshot.ts +72 -72
- package/src/snapshot/reconcileSnapshot.ts +88 -88
- package/src/standardActions/actions.ts +64 -64
- package/src/standardActions/objectActions.ts +60 -60
- package/src/transforms/ImmutableDate.ts +93 -93
- package/src/transforms/asMap.ts +50 -50
- package/src/transforms/asSet.ts +22 -22
- package/src/transforms/bigint.ts +20 -20
- package/src/transforms/date.ts +40 -40
- package/src/treeUtils/deepEquals.ts +55 -55
- package/src/treeUtils/sandbox.ts +6 -3
- package/src/tweaker/TweakerPriority.ts +9 -9
- package/src/tweaker/tweak.ts +4 -3
- package/src/tweaker/tweakArray.ts +530 -475
- package/src/tweaker/tweakFrozen.ts +42 -42
- package/src/tweaker/tweakModel.ts +1 -1
- package/src/tweaker/tweakPlainObject.ts +355 -355
- package/src/tweaker/typeChecking.ts +101 -101
- package/src/types/SnapshotTypeMismatchError.ts +46 -46
- package/src/types/TypeCheckError.ts +183 -184
- package/src/types/TypeChecker.ts +202 -185
- package/src/types/arrayBased/typesArray.ts +136 -137
- package/src/types/arrayBased/typesTuple.ts +138 -139
- package/src/types/createPerEntryCachedCheck.ts +166 -160
- package/src/types/index.ts +6 -6
- package/src/types/objectBased/typesArraySet.ts +133 -134
- package/src/types/objectBased/typesDataModelData.ts +203 -204
- package/src/types/objectBased/typesModel.ts +220 -221
- package/src/types/objectBased/typesObject.ts +308 -310
- package/src/types/objectBased/typesObjectMap.ts +142 -143
- package/src/types/objectBased/typesRecord.ts +156 -157
- package/src/types/objectBased/typesRef.ts +89 -89
- package/src/types/primitiveBased/typesEnum.ts +63 -63
- package/src/types/primitiveBased/typesPrimitive.ts +219 -220
- package/src/types/registerDefaultStandardTypeResolvers.ts +21 -21
- package/src/types/resolveTypeChecker.ts +78 -78
- package/src/types/schemas.ts +208 -208
- package/src/types/tProp.ts +277 -268
- package/src/types/typeCheck.ts +21 -21
- package/src/types/typeCheckErrorUtils.ts +23 -23
- package/src/types/types.ts +142 -142
- package/src/types/utility/typeToStoredData.ts +37 -37
- package/src/types/utility/typesBigInt.ts +15 -15
- package/src/types/utility/typesCodec.ts +41 -38
- package/src/types/utility/typesCodecCore.ts +178 -178
- package/src/types/utility/typesCodecSupport.ts +806 -806
- package/src/types/utility/typesDate.ts +27 -27
- package/src/types/utility/typesMap.ts +253 -222
- package/src/types/utility/typesOr.ts +263 -259
- package/src/types/utility/typesRefinement.ts +131 -125
- package/src/types/utility/typesSet.ts +110 -110
- package/src/types/utility/typesSkipCheck.ts +69 -70
- package/src/types/utility/typesTag.ts +88 -82
- package/src/types/utility/typesUnchecked.ts +40 -40
- package/src/utils/AnyFunction.ts +4 -4
- package/src/utils/ModelPool.ts +59 -59
- package/src/utils/chainFns.ts +18 -18
- package/src/utils/decorators.ts +274 -274
- package/src/utils/errorDiagnostics.ts +204 -204
- package/src/utils/index.ts +443 -372
- package/src/wrappers/ArraySet.ts +156 -156
- package/src/wrappers/ObjectMap.ts +155 -136
- package/src/wrappers/asMap.ts +65 -30
- package/src/wrappers/asSet.ts +3 -3
|
@@ -74,7 +74,7 @@ export interface UndoEventGroup {
|
|
|
74
74
|
*/
|
|
75
75
|
readonly events: ReadonlyArray<UndoEventWithoutAttachedState>;
|
|
76
76
|
}
|
|
77
|
-
declare const UndoStore_base: import('
|
|
77
|
+
declare const UndoStore_base: import('..')._Model<unknown, {
|
|
78
78
|
undoEvents: import('..').OptionalModelProp<UndoEvent[]> & {
|
|
79
79
|
$storedValueType: UndoEvent[];
|
|
80
80
|
$storedCreationValueType: UndoEvent[] | null | undefined;
|
|
@@ -22,6 +22,7 @@ export interface ModelProp<TPropValue, TPropCreationValue, TTransformedValue, TT
|
|
|
22
22
|
$toSnapshotOverride: TToSnapshotOverride;
|
|
23
23
|
_defaultFn: (() => TPropValue) | typeof noDefaultValue;
|
|
24
24
|
_defaultValue: TPropValue | typeof noDefaultValue;
|
|
25
|
+
_defaultValueIsTransformed: boolean;
|
|
25
26
|
_typeChecker: AnyStandardType | undefined;
|
|
26
27
|
_setter: SetterMode;
|
|
27
28
|
_setterValueTransform: ((value: unknown) => unknown) | undefined;
|
|
@@ -241,4 +242,8 @@ export declare function prop<TValue>(): MaybeOptionalModelProp<TValue>;
|
|
|
241
242
|
* @ignore
|
|
242
243
|
*/
|
|
243
244
|
export declare function getModelPropDefaultValue(propData: AnyModelProp): unknown | typeof noDefaultValue;
|
|
245
|
+
/**
|
|
246
|
+
* @ignore
|
|
247
|
+
*/
|
|
248
|
+
export declare function getModelPropStoredDefaultValue(propData: AnyModelProp, model: object, propName: string): unknown | typeof noDefaultValue;
|
|
244
249
|
export {};
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
export interface ConnectReduxDevToolsOptions {
|
|
2
|
+
/**
|
|
3
|
+
* If it should show the arguments near the action name.
|
|
4
|
+
*
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
logArgsNearName?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* If it should log child actions when they run inside another action tracked
|
|
10
|
+
* by the same target tree.
|
|
11
|
+
*
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
logChildActions?: boolean;
|
|
15
|
+
}
|
|
1
16
|
/**
|
|
2
17
|
* Connects a tree node to a redux dev tools instance.
|
|
3
18
|
*
|
|
4
19
|
* @param remotedevPackage The remotedev package (usually the result of `require("remoteDev")`) (https://www.npmjs.com/package/remotedev).
|
|
5
20
|
* @param remotedevConnection The result of a connect method from the remotedev package (usually the result of `remoteDev.connectViaExtension(...)`).
|
|
6
21
|
* @param target Object to use as root.
|
|
7
|
-
* @param [options] Optional options object.
|
|
22
|
+
* @param [options] Optional options object.
|
|
8
23
|
*/
|
|
9
|
-
export declare function connectReduxDevTools(remotedevPackage: any, remotedevConnection: any, target: object, options?:
|
|
10
|
-
logArgsNearName?: boolean;
|
|
11
|
-
}): void;
|
|
24
|
+
export declare function connectReduxDevTools(remotedevPackage: any, remotedevConnection: any, target: object, options?: ConnectReduxDevToolsOptions): void;
|
package/dist/types/ref/Ref.d.ts
CHANGED
|
@@ -24,7 +24,6 @@ export type WithSandboxCallback<T extends readonly [object, ...object[]], R> = (
|
|
|
24
24
|
* original subtree and apply them to the original subtree or reject them.
|
|
25
25
|
*/
|
|
26
26
|
export declare class SandboxManager {
|
|
27
|
-
private readonly subtreeRoot;
|
|
28
27
|
/**
|
|
29
28
|
* The sandbox copy of the original subtree.
|
|
30
29
|
*/
|
|
@@ -47,6 +46,7 @@ export declare class SandboxManager {
|
|
|
47
46
|
* Whether changes made in the sandbox are currently being committed to the original subtree.
|
|
48
47
|
*/
|
|
49
48
|
private isCommitting;
|
|
49
|
+
private readonly subtreeRoot;
|
|
50
50
|
/**
|
|
51
51
|
* Creates an instance of `SandboxManager`.
|
|
52
52
|
* Do not use directly, use `sandbox` instead.
|
|
@@ -17,8 +17,8 @@ export declare function typesArray<T extends AnyType>(itemType: T): ArrayType<T[
|
|
|
17
17
|
* `types.array` type info.
|
|
18
18
|
*/
|
|
19
19
|
export declare class ArrayTypeInfo extends TypeInfo {
|
|
20
|
-
readonly itemType: AnyStandardType;
|
|
21
20
|
readonly kind = "array";
|
|
21
|
+
readonly itemType: AnyStandardType;
|
|
22
22
|
get itemTypeInfo(): TypeInfo;
|
|
23
23
|
constructor(thisType: AnyStandardType, itemType: AnyStandardType);
|
|
24
24
|
}
|
|
@@ -17,8 +17,8 @@ export declare function typesTuple<T extends AnyType[]>(...itemTypes: T): ArrayT
|
|
|
17
17
|
* `types.tuple` type info.
|
|
18
18
|
*/
|
|
19
19
|
export declare class TupleTypeInfo extends TypeInfo {
|
|
20
|
-
readonly itemTypes: ReadonlyArray<AnyStandardType>;
|
|
21
20
|
readonly kind = "tuple";
|
|
21
|
+
readonly itemTypes: ReadonlyArray<AnyStandardType>;
|
|
22
22
|
private _itemTypeInfos;
|
|
23
23
|
get itemTypeInfos(): ReadonlyArray<TypeInfo>;
|
|
24
24
|
constructor(thisType: AnyStandardType, itemTypes: ReadonlyArray<AnyStandardType>);
|
|
@@ -18,8 +18,8 @@ export declare function typesArraySet<T extends AnyType>(valueType: T): ModelTyp
|
|
|
18
18
|
* `types.arraySet` type info.
|
|
19
19
|
*/
|
|
20
20
|
export declare class ArraySetTypeInfo extends TypeInfo {
|
|
21
|
-
readonly valueType: AnyStandardType;
|
|
22
21
|
readonly kind = "arraySet";
|
|
22
|
+
readonly valueType: AnyStandardType;
|
|
23
23
|
get valueTypeInfo(): TypeInfo;
|
|
24
24
|
constructor(originalType: AnyStandardType, valueType: AnyStandardType);
|
|
25
25
|
}
|
|
@@ -35,8 +35,8 @@ export interface DataModelDataTypeInfoProps {
|
|
|
35
35
|
* `types.dataModelData` type info.
|
|
36
36
|
*/
|
|
37
37
|
export declare class DataModelDataTypeInfo extends TypeInfo {
|
|
38
|
-
readonly modelClass: ModelClass<AnyDataModel>;
|
|
39
38
|
readonly kind = "dataModelData";
|
|
39
|
+
readonly modelClass: ModelClass<AnyDataModel>;
|
|
40
40
|
private _props;
|
|
41
41
|
get props(): DataModelDataTypeInfoProps;
|
|
42
42
|
get modelType(): string;
|
|
@@ -34,8 +34,8 @@ export interface ModelTypeInfoProps {
|
|
|
34
34
|
* `types.model` type info.
|
|
35
35
|
*/
|
|
36
36
|
export declare class ModelTypeInfo extends TypeInfo {
|
|
37
|
-
readonly modelClass: ModelClass<AnyModel>;
|
|
38
37
|
readonly kind = "model";
|
|
38
|
+
readonly modelClass: ModelClass<AnyModel>;
|
|
39
39
|
private _props;
|
|
40
40
|
get props(): ModelTypeInfoProps;
|
|
41
41
|
get modelType(): string;
|
|
@@ -32,11 +32,11 @@ export interface ObjectTypeInfoProps {
|
|
|
32
32
|
* `types.object` type info.
|
|
33
33
|
*/
|
|
34
34
|
export declare class ObjectTypeInfo extends TypeInfo {
|
|
35
|
-
private _objTypeFn;
|
|
36
35
|
readonly kind = "object";
|
|
36
|
+
private readonly _objTypeFn;
|
|
37
37
|
private _props;
|
|
38
38
|
get props(): ObjectTypeInfoProps;
|
|
39
|
-
constructor(thisType: AnyStandardType,
|
|
39
|
+
constructor(thisType: AnyStandardType, objTypeFn: ObjectTypeFunction);
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* A type that represents frozen data.
|
|
@@ -58,8 +58,8 @@ export declare function typesFrozen<T extends AnyType>(dataType: T): ModelType<F
|
|
|
58
58
|
* `types.frozen` type info.
|
|
59
59
|
*/
|
|
60
60
|
export declare class FrozenTypeInfo extends TypeInfo {
|
|
61
|
-
readonly dataType: AnyStandardType;
|
|
62
61
|
readonly kind = "frozen";
|
|
62
|
+
readonly dataType: AnyStandardType;
|
|
63
63
|
get dataTypeInfo(): TypeInfo;
|
|
64
64
|
constructor(thisType: AnyStandardType, dataType: AnyStandardType);
|
|
65
65
|
}
|
|
@@ -18,8 +18,8 @@ export declare function typesObjectMap<T extends AnyType>(valueType: T): ModelTy
|
|
|
18
18
|
* `types.objectMap` type info.
|
|
19
19
|
*/
|
|
20
20
|
export declare class ObjectMapTypeInfo extends TypeInfo {
|
|
21
|
-
readonly valueType: AnyStandardType;
|
|
22
21
|
readonly kind = "objectMap";
|
|
22
|
+
readonly valueType: AnyStandardType;
|
|
23
23
|
get valueTypeInfo(): TypeInfo;
|
|
24
24
|
constructor(thisType: AnyStandardType, valueType: AnyStandardType);
|
|
25
25
|
}
|
|
@@ -18,8 +18,8 @@ export declare function typesRecord<T extends AnyType>(valueType: T): RecordType
|
|
|
18
18
|
* `types.record` type info.
|
|
19
19
|
*/
|
|
20
20
|
export declare class RecordTypeInfo extends TypeInfo {
|
|
21
|
-
readonly valueType: AnyStandardType;
|
|
22
21
|
readonly kind = "record";
|
|
22
|
+
readonly valueType: AnyStandardType;
|
|
23
23
|
get valueTypeInfo(): TypeInfo;
|
|
24
24
|
constructor(thisType: AnyStandardType, valueType: AnyStandardType);
|
|
25
25
|
}
|
|
@@ -19,8 +19,8 @@ export declare function typesLiteral<T extends PrimitiveValue>(literal: T): Iden
|
|
|
19
19
|
* `types.literal` type info.
|
|
20
20
|
*/
|
|
21
21
|
export declare class LiteralTypeInfo extends TypeInfo {
|
|
22
|
-
readonly literal: PrimitiveValue;
|
|
23
22
|
readonly kind = "literal";
|
|
23
|
+
readonly literal: PrimitiveValue;
|
|
24
24
|
constructor(thisType: AnyStandardType, literal: PrimitiveValue);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -19,8 +19,8 @@ import { TagTypeInfo, typesTag } from './utility/typesTag';
|
|
|
19
19
|
import { typesUnchecked, UncheckedTypeInfo } from './utility/typesUnchecked';
|
|
20
20
|
export { getTypeInfo } from './getTypeInfo';
|
|
21
21
|
export { TypeInfo } from './TypeChecker';
|
|
22
|
-
export type {
|
|
23
|
-
export {
|
|
22
|
+
export type { ModelTypeInfoProps, ObjectTypeInfoProps };
|
|
23
|
+
export { ArraySetTypeInfo, ArrayTypeInfo, BooleanTypeInfo, CodecTypeInfo, FrozenTypeInfo, LiteralTypeInfo, ModelTypeInfo, NumberTypeInfo, ObjectMapTypeInfo, ObjectTypeInfo, OrTypeInfo, RecordTypeInfo, RefinementTypeInfo, RefTypeInfo, SkipCheckTypeInfo, StringTypeInfo, TagTypeInfo, TupleTypeInfo, UncheckedTypeInfo, };
|
|
24
24
|
export declare const types: {
|
|
25
25
|
literal: typeof typesLiteral;
|
|
26
26
|
undefined: import('./schemas').IdentityType<undefined>;
|
|
@@ -66,7 +66,7 @@ export declare const types: {
|
|
|
66
66
|
mapObject<T extends AnyType>(valueType: T): import('./schemas').RecordType<T>;
|
|
67
67
|
mapFromObject<T extends AnyType>(valueType: T): import('./utility/typesCodecCore').CodecFromEncoded<import('./schemas').RecordType<T>, Map<string, import('./schemas').TypeToData<T>>>;
|
|
68
68
|
mapFromArray<TKeyType extends AnyType, TValueType extends AnyType>(keyType: TKeyType, valueType: TValueType): import('./utility/typesCodecCore').CodecFromEncoded<import('./schemas').ArrayType<import('./schemas').ArrayType<[TKeyType, TValueType]>[]>, Map<import('./schemas').TypeToData<TKeyType>, import('./schemas').TypeToData<TValueType>>>;
|
|
69
|
-
setFromArray<T extends AnyType>(valueType: T): import('./utility/typesCodecCore').CodecFromEncoded<import('./schemas').ArrayType<T[]>, Set<import('./schemas').TypeToData<T>> | import('mobx
|
|
69
|
+
setFromArray<T extends AnyType>(valueType: T): import('./utility/typesCodecCore').CodecFromEncoded<import('./schemas').ArrayType<T[]>, Set<import('./schemas').TypeToData<T>> | import('mobx').ObservableSet<import('./schemas').TypeToData<T>>>;
|
|
70
70
|
/**
|
|
71
71
|
* @deprecated Prefer `types.dateAsIsoString` instead.
|
|
72
72
|
*/
|
|
@@ -4,9 +4,4 @@ import { createCodecPropTransform, resolveCodecSupport, resolveStoredType, resol
|
|
|
4
4
|
import { typesDateAsIsoString, typesDateAsTimestamp } from './typesDate';
|
|
5
5
|
import { typesMapFromArray, typesMapFromObject } from './typesMap';
|
|
6
6
|
import { typesSetFromArray } from './typesSet';
|
|
7
|
-
export { CodecTypeInfo, typesCodec };
|
|
8
|
-
export { createCodecPropTransform, resolveCodecSupport, resolveStoredType, resolveStoredTypeChecker, };
|
|
9
|
-
export { typesBigInt };
|
|
10
|
-
export { typesDateAsIsoString, typesDateAsTimestamp };
|
|
11
|
-
export { typesMapFromArray, typesMapFromObject };
|
|
12
|
-
export { typesSetFromArray };
|
|
7
|
+
export { CodecTypeInfo, createCodecPropTransform, resolveCodecSupport, resolveStoredType, resolveStoredTypeChecker, typesBigInt, typesCodec, typesDateAsIsoString, typesDateAsTimestamp, typesMapFromArray, typesMapFromObject, typesSetFromArray, };
|
|
@@ -34,9 +34,9 @@ export declare const identityRuntimeAdapter: RuntimeAdapter<any, any>;
|
|
|
34
34
|
* `types.codec` type info.
|
|
35
35
|
*/
|
|
36
36
|
export declare class CodecTypeInfo extends TypeInfo {
|
|
37
|
+
readonly kind = "codec";
|
|
37
38
|
readonly typeName: string;
|
|
38
39
|
readonly encodedType: AnyStandardType;
|
|
39
|
-
readonly kind = "codec";
|
|
40
40
|
get encodedTypeInfo(): TypeInfo;
|
|
41
41
|
constructor(thisType: AnyStandardType, typeName: string, encodedType: AnyStandardType);
|
|
42
42
|
}
|
|
@@ -28,9 +28,9 @@ export declare function typesOr<T extends AnyType[]>(...orTypes: T): T[number];
|
|
|
28
28
|
* `types.or` type info.
|
|
29
29
|
*/
|
|
30
30
|
export declare class OrTypeInfo extends TypeInfo {
|
|
31
|
+
readonly kind = "or";
|
|
31
32
|
readonly orTypes: ReadonlyArray<AnyStandardType>;
|
|
32
33
|
readonly dispatcher: ((sn: any) => AnyType) | undefined;
|
|
33
|
-
readonly kind = "or";
|
|
34
34
|
private _orTypeInfos;
|
|
35
35
|
get orTypeInfos(): ReadonlyArray<TypeInfo>;
|
|
36
36
|
constructor(thisType: AnyStandardType, orTypes: ReadonlyArray<AnyStandardType>, dispatcher: ((sn: any) => AnyType) | undefined);
|
|
@@ -41,10 +41,10 @@ export declare function typesRefinement<T extends AnyType>(baseType: T, checkFn:
|
|
|
41
41
|
* `types.refinement` type info.
|
|
42
42
|
*/
|
|
43
43
|
export declare class RefinementTypeInfo extends TypeInfo {
|
|
44
|
+
readonly kind = "refinement";
|
|
44
45
|
readonly baseType: AnyStandardType;
|
|
45
46
|
readonly checkFunction: (data: any) => TypeCheckError | null | boolean;
|
|
46
47
|
readonly typeName: string | undefined;
|
|
47
|
-
readonly kind = "refinement";
|
|
48
48
|
get baseTypeInfo(): TypeInfo;
|
|
49
49
|
constructor(thisType: AnyStandardType, baseType: AnyStandardType, checkFunction: (data: any) => TypeCheckError | null | boolean, typeName: string | undefined);
|
|
50
50
|
}
|
|
@@ -27,8 +27,8 @@ export declare function typesSkipCheck<T extends AnyType>(baseType: T): T;
|
|
|
27
27
|
* `types.skipCheck` type info.
|
|
28
28
|
*/
|
|
29
29
|
export declare class SkipCheckTypeInfo extends TypeInfo {
|
|
30
|
-
readonly baseType: AnyStandardType;
|
|
31
30
|
readonly kind = "skipCheck";
|
|
31
|
+
readonly baseType: AnyStandardType;
|
|
32
32
|
get baseTypeInfo(): TypeInfo;
|
|
33
33
|
constructor(thisType: AnyStandardType, baseType: AnyStandardType);
|
|
34
34
|
}
|
|
@@ -36,10 +36,10 @@ export declare function typesTag<T extends AnyType, A>(baseType: T, tag: A, type
|
|
|
36
36
|
* `types.tag` type info.
|
|
37
37
|
*/
|
|
38
38
|
export declare class TagTypeInfo<A> extends TypeInfo {
|
|
39
|
+
readonly kind = "tag";
|
|
39
40
|
readonly baseType: AnyStandardType;
|
|
40
41
|
readonly tag: A;
|
|
41
42
|
readonly typeName: string | undefined;
|
|
42
|
-
readonly kind = "tag";
|
|
43
43
|
get baseTypeInfo(): TypeInfo;
|
|
44
44
|
constructor(thisType: AnyStandardType, baseType: AnyStandardType, tag: A, typeName: string | undefined);
|
|
45
45
|
}
|
|
@@ -14,6 +14,8 @@ export declare class ObjectMap<V> extends objectMapBase implements Map<string, V
|
|
|
14
14
|
delete(key: string): boolean;
|
|
15
15
|
forEach(callbackfn: (value: V, key: string, map: Map<string, V>) => void, thisArg?: any): void;
|
|
16
16
|
get(key: string): V | undefined;
|
|
17
|
+
getOrInsert(key: string, defaultValue: V): V;
|
|
18
|
+
getOrInsertComputed(key: string, callback: (key: string) => V): V;
|
|
17
19
|
has(key: string): boolean;
|
|
18
20
|
set(key: string, value: V): this;
|
|
19
21
|
get size(): number;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { ObservableMap } from 'mobx';
|
|
2
|
+
type Ts6MapExtras<K, V> = {
|
|
3
|
+
getOrInsert(key: K, defaultValue: V): V;
|
|
4
|
+
getOrInsertComputed(key: K, callback: (key: K) => V): V;
|
|
5
|
+
};
|
|
6
|
+
type ObservableMapWithDataObject<K, V, TDataObject> = ObservableMap<K, V> & Ts6MapExtras<K, V> & {
|
|
7
|
+
dataObject: TDataObject;
|
|
8
|
+
};
|
|
2
9
|
/**
|
|
3
10
|
* Wraps an observable object or a tuple array to offer a map like interface.
|
|
4
11
|
*
|
|
5
12
|
* @param array Array.
|
|
6
13
|
*/
|
|
7
|
-
export declare function asMap<K, V>(array: Array<[K, V]>):
|
|
8
|
-
dataObject: Array<[K, V]>;
|
|
9
|
-
};
|
|
14
|
+
export declare function asMap<K, V>(array: Array<[K, V]>): ObservableMapWithDataObject<K, V, Array<[K, V]>>;
|
|
10
15
|
/**
|
|
11
16
|
* Wraps an observable object or a tuple array to offer a map like interface.
|
|
12
17
|
*
|
|
13
18
|
* @param object Object.
|
|
14
19
|
*/
|
|
15
|
-
export declare function asMap<T>(object: Record<string, T>):
|
|
16
|
-
dataObject: Record<string, T>;
|
|
17
|
-
};
|
|
20
|
+
export declare function asMap<T>(object: Record<string, T>): ObservableMapWithDataObject<string, T, Record<string, T>>;
|
|
18
21
|
/**
|
|
19
22
|
* Converts a map to an object. If the map is a collection wrapper it will return the backed object.
|
|
20
23
|
*
|
|
@@ -27,3 +30,4 @@ export declare function mapToObject<T>(map: Pick<Map<string, T>, "forEach">): Re
|
|
|
27
30
|
* @param map
|
|
28
31
|
*/
|
|
29
32
|
export declare function mapToArray<K, V>(map: Pick<Map<K, V>, "forEach">): Array<[K, V]>;
|
|
33
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-keystone",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mobx",
|
|
@@ -66,23 +66,25 @@
|
|
|
66
66
|
"mobx": "^6.0.0 || ^5.0.0 || ^4.0.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@babel/core": "^
|
|
70
|
-
"@babel/plugin-proposal-
|
|
71
|
-
"@babel/plugin-
|
|
72
|
-
"@babel/
|
|
73
|
-
"@babel/preset-
|
|
74
|
-
"@swc/core": "^1.15.
|
|
69
|
+
"@babel/core": "^8.0.1",
|
|
70
|
+
"@babel/plugin-proposal-decorators": "^8.0.2",
|
|
71
|
+
"@babel/plugin-transform-class-properties": "^8.0.1",
|
|
72
|
+
"@babel/plugin-transform-typescript": "^8.0.1",
|
|
73
|
+
"@babel/preset-env": "^8.0.2",
|
|
74
|
+
"@swc/core": "^1.15.43",
|
|
75
75
|
"@types/babel__core": "^7.20.5",
|
|
76
|
-
"@types/node": "^
|
|
77
|
-
"@vitest/coverage-v8": "^4.
|
|
76
|
+
"@types/node": "^26.0.1",
|
|
77
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
78
78
|
"mobx-v4": "npm:mobx@^4.15.7",
|
|
79
79
|
"mobx-v5": "npm:mobx@^5.15.7",
|
|
80
80
|
"shx": "^0.4.0",
|
|
81
81
|
"spec.ts": "^1.1.3",
|
|
82
82
|
"ts-node": "^10.9.2",
|
|
83
|
-
"typedoc": "^0.28.
|
|
84
|
-
"typescript": "^
|
|
85
|
-
"
|
|
83
|
+
"typedoc": "^0.28.19",
|
|
84
|
+
"typescript": "^6.0.3",
|
|
85
|
+
"vite": "^8.1.0",
|
|
86
|
+
"vite-plugin-dts": "^5.0.3",
|
|
87
|
+
"vitest": "^4.1.9"
|
|
86
88
|
},
|
|
87
89
|
"dependencies": {
|
|
88
90
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -1,114 +1,125 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { applyDelete } from "./applyDelete"
|
|
12
|
-
import { applyMethodCall } from "./applyMethodCall"
|
|
13
|
-
import { applySet } from "./applySet"
|
|
14
|
-
import { BuiltInAction, isBuiltInAction } from "./builtInActions"
|
|
15
|
-
import { isHookAction } from "./hookActions"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
[BuiltInAction.
|
|
51
|
-
[BuiltInAction.
|
|
52
|
-
[BuiltInAction.
|
|
53
|
-
[BuiltInAction.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
)}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
1
|
+
import { getDataModelAction } from "../dataModel/actions"
|
|
2
|
+
import { detach } from "../parent/detach"
|
|
3
|
+
import { resolvePathCheckingIds } from "../parent/path"
|
|
4
|
+
import type { Path } from "../parent/pathTypes"
|
|
5
|
+
import { applyPatches } from "../patch/applyPatches"
|
|
6
|
+
import { applySnapshot } from "../snapshot/applySnapshot"
|
|
7
|
+
import { getStandaloneAction } from "../standardActions/actions"
|
|
8
|
+
import { assertTweakedObject } from "../tweaker/core"
|
|
9
|
+
import { failure } from "../utils"
|
|
10
|
+
import type { AnyFunction } from "../utils/AnyFunction"
|
|
11
|
+
import { applyDelete } from "./applyDelete"
|
|
12
|
+
import { applyMethodCall } from "./applyMethodCall"
|
|
13
|
+
import { applySet } from "./applySet"
|
|
14
|
+
import { BuiltInAction, isBuiltInAction } from "./builtInActions"
|
|
15
|
+
import { isHookAction } from "./hookActions"
|
|
16
|
+
import { isModelAction } from "./isModelAction"
|
|
17
|
+
import { isModelFlow } from "./modelFlow"
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An action call.
|
|
21
|
+
*/
|
|
22
|
+
export interface ActionCall {
|
|
23
|
+
/**
|
|
24
|
+
* Action name (name of the function).
|
|
25
|
+
*/
|
|
26
|
+
readonly actionName: string
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Action arguments.
|
|
30
|
+
*/
|
|
31
|
+
readonly args: ReadonlyArray<any>
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Path to the model where the action will be run, as an array of string | number.
|
|
35
|
+
*/
|
|
36
|
+
readonly targetPath: Path
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Ids of models along the path to the target, null if it is not a model.
|
|
40
|
+
*/
|
|
41
|
+
readonly targetPathIds: ReadonlyArray<string | null>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Marks this action call as non-serialized.
|
|
45
|
+
*/
|
|
46
|
+
readonly serialized?: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const builtInActionToFunction = {
|
|
50
|
+
[BuiltInAction.ApplySnapshot]: applySnapshot,
|
|
51
|
+
[BuiltInAction.ApplyPatches]: applyPatches,
|
|
52
|
+
[BuiltInAction.Detach]: detach,
|
|
53
|
+
[BuiltInAction.ApplySet]: applySet,
|
|
54
|
+
[BuiltInAction.ApplyDelete]: applyDelete,
|
|
55
|
+
[BuiltInAction.ApplyMethodCall]: applyMethodCall,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Applies (runs) an action over a target object.
|
|
60
|
+
*
|
|
61
|
+
* If you intend to apply serialized actions check one of the `applySerializedAction` methods instead.
|
|
62
|
+
*
|
|
63
|
+
* @param subtreeRoot Subtree root target object to run the action over.
|
|
64
|
+
* @param call The action, usually as coming from `onActionMiddleware`.
|
|
65
|
+
* @returns The return value of the action, if any.
|
|
66
|
+
*/
|
|
67
|
+
export function applyAction<TRet = any>(subtreeRoot: object, call: ActionCall): TRet {
|
|
68
|
+
if (call.serialized) {
|
|
69
|
+
throw failure(
|
|
70
|
+
"cannot apply a serialized action call, use one of the 'applySerializedAction' methods instead"
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
assertTweakedObject(subtreeRoot, "subtreeRoot")
|
|
75
|
+
|
|
76
|
+
// resolve path while checking ids
|
|
77
|
+
const { value: current, resolved } = resolvePathCheckingIds(
|
|
78
|
+
subtreeRoot,
|
|
79
|
+
call.targetPath,
|
|
80
|
+
call.targetPathIds
|
|
81
|
+
)
|
|
82
|
+
if (!resolved) {
|
|
83
|
+
throw failure(
|
|
84
|
+
`object at path ${JSON.stringify(call.targetPath)} with ids ${JSON.stringify(
|
|
85
|
+
call.targetPathIds
|
|
86
|
+
)} could not be resolved`
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
assertTweakedObject(current, `resolved ${current}`, true)
|
|
90
|
+
|
|
91
|
+
if (isBuiltInAction(call.actionName)) {
|
|
92
|
+
const fnToCall = builtInActionToFunction[call.actionName] as AnyFunction | undefined
|
|
93
|
+
if (!fnToCall) {
|
|
94
|
+
throw failure(`assertion failed: unknown built-in action - ${call.actionName}`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return fnToCall.apply(current, [current, ...call.args])
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (isHookAction(call.actionName)) {
|
|
101
|
+
throw failure(`calls to hooks (${call.actionName}) cannot be applied`)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const dataModelAction = getDataModelAction(call.actionName)
|
|
105
|
+
if (dataModelAction) {
|
|
106
|
+
const instance: any = new dataModelAction.modelClass(current)
|
|
107
|
+
return instance[dataModelAction.fnName](...call.args)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const standaloneAction = getStandaloneAction(call.actionName)
|
|
111
|
+
if (standaloneAction) {
|
|
112
|
+
return standaloneAction.apply(current, call.args as any)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const actionFn = (current as any)[call.actionName]
|
|
116
|
+
if (typeof actionFn !== "function") {
|
|
117
|
+
throw failure(`action '${call.actionName}' could not be resolved to a function`)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!isModelAction(actionFn) && !isModelFlow(actionFn)) {
|
|
121
|
+
throw failure(`action '${call.actionName}' is not a model action`)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return actionFn.apply(current, call.args)
|
|
125
|
+
}
|