mobx-keystone 1.24.0 → 1.24.1
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 +4 -0
- package/LICENSE +21 -21
- package/README.md +11 -10
- package/dist/mobx-keystone.esm.js +76 -84
- package/dist/mobx-keystone.esm.mjs +76 -84
- package/dist/mobx-keystone.umd.js +76 -84
- package/dist/types/modelShared/BaseModelShared.d.ts +7 -1
- package/dist/types/modelShared/prop.d.ts +5 -0
- package/dist/types/types/TypeChecker.d.ts +79 -0
- package/dist/types/types/schemas.d.ts +15 -0
- package/package.json +7 -6
- package/src/modelShared/BaseModelShared.ts +1 -1
- package/src/modelShared/prop.ts +1 -1
- package/src/types/TypeChecker.ts +6 -6
- package/src/types/schemas.ts +2 -2
|
@@ -2,7 +2,7 @@ import { AnyDataModel } from '../dataModel/BaseDataModel';
|
|
|
2
2
|
import { AnyModel } from '../model/BaseModel';
|
|
3
3
|
import { modelTypeKey } from '../model/metadata';
|
|
4
4
|
import { Flatten, IsNeverType } from '../utils/types';
|
|
5
|
-
import { ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData, ModelPropsToUntransformedCreationData } from './prop';
|
|
5
|
+
import { ModelProps, ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData, ModelPropsToUntransformedCreationData } from './prop';
|
|
6
6
|
/**
|
|
7
7
|
* @ignore
|
|
8
8
|
*/
|
|
@@ -27,6 +27,12 @@ export interface ModelClass<M extends AnyModel | AnyDataModel> {
|
|
|
27
27
|
* Extracts the instance type of an abstract model class.
|
|
28
28
|
*/
|
|
29
29
|
export type AbstractModelClass<M extends AnyModel | AnyDataModel> = abstract new (initialData: any) => M;
|
|
30
|
+
/**
|
|
31
|
+
* @ignore
|
|
32
|
+
*/
|
|
33
|
+
export interface ModelWithProps {
|
|
34
|
+
[propsTypeSymbol]: ModelProps;
|
|
35
|
+
}
|
|
30
36
|
/**
|
|
31
37
|
* The props of a model.
|
|
32
38
|
*/
|
|
@@ -7,6 +7,11 @@ import { Flatten, IsNeverType, IsOptionalValue } from '../utils/types';
|
|
|
7
7
|
export declare const noDefaultValue: unique symbol;
|
|
8
8
|
type SetterMode = boolean | "assign";
|
|
9
9
|
export type ModelPropSetterValueTransform<T> = (value: T) => T;
|
|
10
|
+
/** @ignore */
|
|
11
|
+
export interface FullModelPropTransform {
|
|
12
|
+
transform: (original: unknown, model: object, propName: PropertyKey, setOriginalValue: (newOriginalValue: unknown) => void) => unknown;
|
|
13
|
+
untransform: (transformed: unknown, model: object, propName: PropertyKey) => unknown;
|
|
14
|
+
}
|
|
10
15
|
/**
|
|
11
16
|
* A model property.
|
|
12
17
|
*/
|
|
@@ -1,4 +1,78 @@
|
|
|
1
|
+
import { Path } from '../parent/pathTypes';
|
|
1
2
|
import { AnyStandardType } from './schemas';
|
|
3
|
+
import { TypeCheckError } from './TypeCheckError';
|
|
4
|
+
type CheckFunction = (value: any, path: Path, typeCheckedValue: any) => TypeCheckError | null;
|
|
5
|
+
/** @ignore */
|
|
6
|
+
export type SnapshotProcessor = (snapshot: any) => unknown;
|
|
7
|
+
/**
|
|
8
|
+
* A lazily discovered snapshot-processor node. Dependencies are deliberately
|
|
9
|
+
* TypeCheckers rather than processors so recursive graphs can be discovered
|
|
10
|
+
* before any processor body is compiled.
|
|
11
|
+
*
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
export interface SnapshotProcessorPlan {
|
|
15
|
+
readonly intrinsic?: boolean;
|
|
16
|
+
readonly getDependencies: () => ReadonlyArray<TypeChecker>;
|
|
17
|
+
readonly compile: (dependencyProcessors: ReadonlyArray<SnapshotProcessor | undefined>) => SnapshotProcessor | undefined;
|
|
18
|
+
}
|
|
19
|
+
type SnapshotProcessorSource = SnapshotProcessor | SnapshotProcessorPlan | undefined;
|
|
20
|
+
type SnapshotProcessorDirection = "from" | "to";
|
|
21
|
+
/** @ignore */
|
|
22
|
+
export declare class SnapshotProcessorPlanNode {
|
|
23
|
+
private readonly owner;
|
|
24
|
+
private readonly direction;
|
|
25
|
+
private readonly source;
|
|
26
|
+
private presence;
|
|
27
|
+
private dependencies;
|
|
28
|
+
private discovering;
|
|
29
|
+
private compiling;
|
|
30
|
+
private compiled;
|
|
31
|
+
private compiledProcessor;
|
|
32
|
+
private forwardingProcessor;
|
|
33
|
+
constructor(owner: TypeChecker | undefined, direction: SnapshotProcessorDirection, source: SnapshotProcessorSource);
|
|
34
|
+
resolve(): SnapshotProcessor | undefined;
|
|
35
|
+
private discover;
|
|
36
|
+
private compile;
|
|
37
|
+
private compileForDependency;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @ignore
|
|
41
|
+
*/
|
|
42
|
+
export declare enum TypeCheckerBaseType {
|
|
43
|
+
Object = "object",
|
|
44
|
+
Array = "array",
|
|
45
|
+
Primitive = "primitive",
|
|
46
|
+
Any = "any"
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @ignore
|
|
50
|
+
*/
|
|
51
|
+
export declare class TypeChecker {
|
|
52
|
+
unchecked: boolean;
|
|
53
|
+
skipCheck: boolean;
|
|
54
|
+
readonly baseType: TypeCheckerBaseType;
|
|
55
|
+
private readonly _check;
|
|
56
|
+
readonly getTypeName: (...recursiveTypeCheckers: TypeChecker[]) => string;
|
|
57
|
+
readonly typeInfoGen: TypeInfoGen;
|
|
58
|
+
readonly snapshotType: (sn: unknown) => TypeChecker | null;
|
|
59
|
+
private readonly fromSnapshotProcessorSource;
|
|
60
|
+
private readonly toSnapshotProcessorSource;
|
|
61
|
+
private fromSnapshotProcessorPlanNode;
|
|
62
|
+
private toSnapshotProcessorPlanNode;
|
|
63
|
+
check(value: any, path: Path, typeCheckedValue: any): TypeCheckError | null;
|
|
64
|
+
private _cachedTypeInfoGen;
|
|
65
|
+
get typeInfo(): TypeInfo;
|
|
66
|
+
constructor(baseType: TypeCheckerBaseType, _check: CheckFunction | null, getTypeName: (...recursiveTypeCheckers: TypeChecker[]) => string, typeInfoGen: TypeInfoGen, snapshotType: (sn: unknown) => TypeChecker | null, fromSnapshotProcessor: SnapshotProcessorSource, toSnapshotProcessor: SnapshotProcessorSource);
|
|
67
|
+
getSnapshotProcessorPlanNode(direction: SnapshotProcessorDirection): SnapshotProcessorPlanNode;
|
|
68
|
+
private resolveSnapshotProcessor;
|
|
69
|
+
getFromSnapshotProcessor(): SnapshotProcessor | undefined;
|
|
70
|
+
getToSnapshotProcessor(): SnapshotProcessor | undefined;
|
|
71
|
+
fromSnapshotProcessor: (sn: any) => unknown;
|
|
72
|
+
private readonly _toSnapshotProcessorCache;
|
|
73
|
+
invalidateSnapshotProcessorCachedResult(obj: object): void;
|
|
74
|
+
toSnapshotProcessor: (sn: any) => unknown;
|
|
75
|
+
}
|
|
2
76
|
/**
|
|
3
77
|
* Type info base class.
|
|
4
78
|
*/
|
|
@@ -7,3 +81,8 @@ export declare class TypeInfo {
|
|
|
7
81
|
readonly thisType: AnyStandardType;
|
|
8
82
|
constructor(thisType: AnyStandardType);
|
|
9
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* @ignore
|
|
86
|
+
*/
|
|
87
|
+
export type TypeInfoGen = (t: AnyStandardType) => TypeInfo;
|
|
88
|
+
export {};
|
|
@@ -3,6 +3,7 @@ import { AnyDataModel } from '../dataModel/BaseDataModel';
|
|
|
3
3
|
import { AnyModel } from '../model/BaseModel';
|
|
4
4
|
import { ModelClass } from '../modelShared/BaseModelShared';
|
|
5
5
|
import { SnapshotInOf, SnapshotOutOf } from '../snapshot/SnapshotOf';
|
|
6
|
+
import { IsOptionalValue } from '../utils/types';
|
|
6
7
|
export interface Type<Name, Data> {
|
|
7
8
|
/** @ignore */
|
|
8
9
|
$$type: Name;
|
|
@@ -36,6 +37,20 @@ export interface ObjectOfTypes {
|
|
|
36
37
|
/** @ignore */
|
|
37
38
|
[k: string]: AnyType;
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Name of the properties of an object that can be set to undefined, any or unknown.
|
|
42
|
+
* @ignore
|
|
43
|
+
*/
|
|
44
|
+
export type UndefinablePropsNames<T> = {
|
|
45
|
+
[K in keyof T]: IsOptionalValue<T[K], K, never>;
|
|
46
|
+
}[keyof T];
|
|
47
|
+
/**
|
|
48
|
+
* Computes the optional keys for an object type schema.
|
|
49
|
+
* @ignore
|
|
50
|
+
*/
|
|
51
|
+
export type ObjectOptionalKeys<S> = UndefinablePropsNames<{
|
|
52
|
+
[k in keyof S]: TypeToDataOpt<S[k]> extends infer R ? R : never;
|
|
53
|
+
}>;
|
|
39
54
|
type ObjectData<S> = O.Optional<{
|
|
40
55
|
[k in keyof S]: TypeToData<S[k]> extends infer R ? R : never;
|
|
41
56
|
}, ObjectOptionalKeys<S>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-keystone",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.1",
|
|
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",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"quick-build": "tsc",
|
|
55
55
|
"quick-build-tests": "tsc -p test",
|
|
56
56
|
"copy-root-files": "shx cp ../../README.md . && shx cp ../../LICENSE . && shx cp ../../CHANGELOG.md .",
|
|
57
|
-
"build": "pnpm run quick-build && pnpm run copy-root-files && shx rm -rf dist && vite build && shx cp dist/mobx-keystone.esm.mjs dist/mobx-keystone.esm.js",
|
|
57
|
+
"build": "pnpm run quick-build && pnpm run copy-root-files && shx rm -rf dist && vite build && pnpm run check-declarations && shx cp dist/mobx-keystone.esm.mjs dist/mobx-keystone.esm.js",
|
|
58
|
+
"check-declarations": "tsc -p scripts/tsconfig.check-declarations.json",
|
|
58
59
|
"test": "vitest run",
|
|
59
60
|
"test:ci": "vitest run --coverage",
|
|
60
61
|
"test:perf": "pnpm run build && pnpm run test:perf:run",
|
|
@@ -68,13 +69,13 @@
|
|
|
68
69
|
"devDependencies": {
|
|
69
70
|
"@babel/core": "^8.0.1",
|
|
70
71
|
"@babel/plugin-proposal-decorators": "^8.0.2",
|
|
71
|
-
"@babel/plugin-transform-class-static-block": "^8.0.1",
|
|
72
72
|
"@babel/plugin-transform-class-properties": "^8.0.1",
|
|
73
|
+
"@babel/plugin-transform-class-static-block": "^8.0.1",
|
|
73
74
|
"@babel/plugin-transform-typescript": "^8.0.1",
|
|
74
75
|
"@babel/preset-env": "^8.0.2",
|
|
75
|
-
"@swc/core": "^1.
|
|
76
|
+
"@swc/core": "^1.16.0",
|
|
76
77
|
"@types/babel__core": "^7.20.5",
|
|
77
|
-
"@types/node": "^26.
|
|
78
|
+
"@types/node": "^26.2.0",
|
|
78
79
|
"@typescript/typescript6": "^6.0.2",
|
|
79
80
|
"@vitest/coverage-v8": "^4.1.10",
|
|
80
81
|
"mobx-v4": "npm:mobx@^4.15.7",
|
|
@@ -86,7 +87,7 @@
|
|
|
86
87
|
"ts-node": "^10.9.2",
|
|
87
88
|
"typedoc": "^0.28.20",
|
|
88
89
|
"typescript": "^7.0.2",
|
|
89
|
-
"vite": "^8.1
|
|
90
|
+
"vite": "^8.2.1",
|
|
90
91
|
"vite-plugin-dts": "^5.0.3",
|
|
91
92
|
"vitest": "^4.1.10"
|
|
92
93
|
},
|
package/src/modelShared/prop.ts
CHANGED
package/src/types/TypeChecker.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { TypeCheckError } from "./TypeCheckError"
|
|
|
6
6
|
|
|
7
7
|
type CheckFunction = (value: any, path: Path, typeCheckedValue: any) => TypeCheckError | null
|
|
8
8
|
|
|
9
|
-
/** @
|
|
9
|
+
/** @ignore */
|
|
10
10
|
export type SnapshotProcessor = (snapshot: any) => unknown
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -14,7 +14,7 @@ export type SnapshotProcessor = (snapshot: any) => unknown
|
|
|
14
14
|
* TypeCheckers rather than processors so recursive graphs can be discovered
|
|
15
15
|
* before any processor body is compiled.
|
|
16
16
|
*
|
|
17
|
-
* @
|
|
17
|
+
* @ignore
|
|
18
18
|
*/
|
|
19
19
|
export interface SnapshotProcessorPlan {
|
|
20
20
|
readonly intrinsic?: boolean
|
|
@@ -36,7 +36,7 @@ export function snapshotProcessorPlan(
|
|
|
36
36
|
type SnapshotProcessorSource = SnapshotProcessor | SnapshotProcessorPlan | undefined
|
|
37
37
|
type SnapshotProcessorDirection = "from" | "to"
|
|
38
38
|
|
|
39
|
-
/** @
|
|
39
|
+
/** @ignore */
|
|
40
40
|
export class SnapshotProcessorPlanNode {
|
|
41
41
|
private readonly owner: TypeChecker | undefined
|
|
42
42
|
private readonly direction: SnapshotProcessorDirection
|
|
@@ -196,7 +196,7 @@ export class SnapshotProcessorPlanNode {
|
|
|
196
196
|
const absentSnapshotProcessorPlanNode = new SnapshotProcessorPlanNode(undefined, "from", undefined)
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
* @
|
|
199
|
+
* @ignore
|
|
200
200
|
*/
|
|
201
201
|
export enum TypeCheckerBaseType {
|
|
202
202
|
Object = "object",
|
|
@@ -243,7 +243,7 @@ export function invalidateCachedToSnapshotProcessorResult(obj: object) {
|
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
/**
|
|
246
|
-
* @
|
|
246
|
+
* @ignore
|
|
247
247
|
*/
|
|
248
248
|
export class TypeChecker {
|
|
249
249
|
unchecked: boolean
|
|
@@ -443,6 +443,6 @@ export class TypeInfo {
|
|
|
443
443
|
}
|
|
444
444
|
|
|
445
445
|
/**
|
|
446
|
-
* @
|
|
446
|
+
* @ignore
|
|
447
447
|
*/
|
|
448
448
|
export type TypeInfoGen = (t: AnyStandardType) => TypeInfo
|
package/src/types/schemas.ts
CHANGED
|
@@ -64,7 +64,7 @@ export interface ObjectOfTypes {
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Name of the properties of an object that can be set to undefined, any or unknown.
|
|
67
|
-
* @
|
|
67
|
+
* @ignore
|
|
68
68
|
*/
|
|
69
69
|
export type UndefinablePropsNames<T> = {
|
|
70
70
|
[K in keyof T]: IsOptionalValue<T[K], K, never>
|
|
@@ -72,7 +72,7 @@ export type UndefinablePropsNames<T> = {
|
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Computes the optional keys for an object type schema.
|
|
75
|
-
* @
|
|
75
|
+
* @ignore
|
|
76
76
|
*/
|
|
77
77
|
export type ObjectOptionalKeys<S> = UndefinablePropsNames<{
|
|
78
78
|
[k in keyof S]: TypeToDataOpt<S[k]> extends infer R ? R : never
|