Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobx-keystone

Package Overview
Dependencies
Maintainers
1
Versions
195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobx-keystone - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

5

CHANGELOG.md
# Change Log
## 1.2.0
- TypeCheckError now includes a new `message` field, a new `typeCheckedValue` field and no longer requires a parameter for the `throw()` method.
- Type checking error messages will now include the actual value that failed validation in the error message.
## 1.1.1

@@ -4,0 +9,0 @@

2

dist/types/action/applyMethodCall.d.ts

@@ -1,2 +0,2 @@

declare type AnyFunction = (...args: any[]) => any;
type AnyFunction = (...args: any[]) => any;
/**

@@ -3,0 +3,0 @@ * Calls an object method wrapped in an action.

@@ -24,3 +24,3 @@ import type { ActionContext } from "./context";

*/
export declare type ActionMiddlewareDisposer = () => void;
export type ActionMiddlewareDisposer = () => void;
/**

@@ -27,0 +27,0 @@ * Adds a global action middleware to be run when an action is performed.

@@ -7,7 +7,7 @@ import type { ActionMiddlewareDisposer } from "../action/middleware";

*/
export declare type UndoEventWithoutAttachedState = UndoSingleEvent | UndoEventGroup;
export type UndoEventWithoutAttachedState = UndoSingleEvent | UndoEventGroup;
/**
* An undo/redo event.
*/
export declare type UndoEvent = UndoEventWithoutAttachedState & {
export type UndoEvent = UndoEventWithoutAttachedState & {
/**

@@ -14,0 +14,0 @@ * The state saved before the event actions started / after the event actions finished.

@@ -41,3 +41,3 @@ import { propsTypeSymbol } from "../modelShared/BaseModelShared";

*/
export declare type BaseDataModelKeys = keyof AnyDataModel | "onLazyInit";
export type BaseDataModelKeys = keyof AnyDataModel | "onLazyInit";
/**

@@ -51,4 +51,4 @@ * Any kind of data model instance.

*/
export declare type DataModelClassDeclaration<BaseModelClass, ModelInterface> = BaseModelClass & {
export type DataModelClassDeclaration<BaseModelClass, ModelInterface> = BaseModelClass & {
(...args: any[]): ModelInterface;
};
import type { AbstractModelClass, ModelCreationData, ModelUntransformedCreationData } from "../modelShared/BaseModelShared";
import type { ModelProps, ModelPropsToSetter, ModelPropsToTransformedCreationData, ModelPropsToTransformedData, ModelPropsToUntransformedCreationData } from "../modelShared/prop";
import type { AnyDataModel, BaseDataModel, BaseDataModelKeys } from "./BaseDataModel";
export declare type _ComposedData<SuperModel, TProps extends ModelProps> = SuperModel extends AnyDataModel ? (ModelPropsToUntransformedCreationData<TProps> & ModelUntransformedCreationData<SuperModel>) | (ModelPropsToTransformedCreationData<TProps> & ModelCreationData<SuperModel>) : ModelPropsToUntransformedCreationData<TProps> | ModelPropsToTransformedCreationData<TProps>;
export type _ComposedData<SuperModel, TProps extends ModelProps> = SuperModel extends AnyDataModel ? (ModelPropsToUntransformedCreationData<TProps> & ModelUntransformedCreationData<SuperModel>) | (ModelPropsToTransformedCreationData<TProps> & ModelCreationData<SuperModel>) : ModelPropsToUntransformedCreationData<TProps> | ModelPropsToTransformedCreationData<TProps>;
export interface _DataModel<SuperModel, TProps extends ModelProps> {

@@ -6,0 +6,0 @@ new (data: _ComposedData<SuperModel, TProps>): SuperModel & BaseDataModel<TProps> & Omit<ModelPropsToTransformedData<TProps>, BaseDataModelKeys> & ModelPropsToSetter<TProps>;

@@ -13,3 +13,3 @@ import { fromSnapshotOverrideTypeSymbol, ModelClass, propsTypeSymbol, toSnapshotOverrideTypeSymbol } from "../modelShared/BaseModelShared";

*/
export declare type ModelIdPropertyType<TProps extends ModelProps, ModelIdPropertyName extends string> = [
export type ModelIdPropertyType<TProps extends ModelProps, ModelIdPropertyName extends string> = [
ModelIdPropertyName

@@ -86,3 +86,3 @@ ] extends [never] ? never : ModelPropsToUntransformedData<Pick<TProps, ModelIdPropertyName>>[ModelIdPropertyName];

*/
export declare type BaseModelKeys = keyof AnyModel | "onInit" | "onAttachedToRootStore";
export type BaseModelKeys = keyof AnyModel | "onInit" | "onAttachedToRootStore";
/**

@@ -107,3 +107,3 @@ * Any kind of model instance.

*/
export declare type ModelIdPropertyName<M extends AnyModel> = M[typeof modelIdPropertyNameSymbol];
export type ModelIdPropertyName<M extends AnyModel> = M[typeof modelIdPropertyNameSymbol];
/**

@@ -132,4 +132,4 @@ * Add missing model metadata to a model creation snapshot to generate a proper model snapshot.

*/
export declare type ModelClassDeclaration<BaseModelClass, ModelInterface> = BaseModelClass & {
export type ModelClassDeclaration<BaseModelClass, ModelInterface> = BaseModelClass & {
new (...args: any[]): ModelInterface;
};
import type { AbstractModelClass, ModelCreationData } from "../modelShared/BaseModelShared";
import type { ModelProps, ModelPropsToSetter, ModelPropsToSnapshotCreationData, ModelPropsToSnapshotData, ModelPropsToTransformedCreationData, ModelPropsToTransformedData } from "../modelShared/prop";
import type { AnyModel, BaseModel, BaseModelKeys, ModelIdPropertyName } from "./BaseModel";
export declare type _ComposedCreationData<SuperModel, TProps extends ModelProps> = SuperModel extends AnyModel ? ModelPropsToTransformedCreationData<TProps> & ModelCreationData<SuperModel> : ModelPropsToTransformedCreationData<TProps>;
export type _ComposedCreationData<SuperModel, TProps extends ModelProps> = SuperModel extends AnyModel ? ModelPropsToTransformedCreationData<TProps> & ModelCreationData<SuperModel> : ModelPropsToTransformedCreationData<TProps>;
/**
* The default type used by fromSnapshot before processors are applied.
*/
export declare type FromSnapshotDefaultType<TProps extends ModelProps> = ModelPropsToSnapshotCreationData<TProps>;
export type FromSnapshotDefaultType<TProps extends ModelProps> = ModelPropsToSnapshotCreationData<TProps>;
/**
* The default type used by getSnapshot before processors are applied.
*/
export declare type ToSnapshotDefaultType<TProps extends ModelProps> = ModelPropsToSnapshotData<TProps>;
export declare type _ModelId<SuperModel, TProps extends ModelProps> = SuperModel extends AnyModel ? ModelIdPropertyName<SuperModel> : ExtractModelIdProp<TProps> & string;
export type ToSnapshotDefaultType<TProps extends ModelProps> = ModelPropsToSnapshotData<TProps>;
export type _ModelId<SuperModel, TProps extends ModelProps> = SuperModel extends AnyModel ? ModelIdPropertyName<SuperModel> : ExtractModelIdProp<TProps> & string;
export interface _Model<SuperModel, TProps extends ModelProps, FromSnapshotOverride extends Record<string, any>, ToSnapshotOverride extends Record<string, any>> {

@@ -20,3 +20,3 @@ new (data: _ComposedCreationData<SuperModel, TProps>): SuperModel & BaseModel<TProps, FromSnapshotOverride, ToSnapshotOverride, _ModelId<SuperModel, TProps>> & Omit<ModelPropsToTransformedData<TProps>, BaseModelKeys> & ModelPropsToSetter<TProps>;

*/
export declare type ExtractModelIdProp<TProps extends ModelProps> = {
export type ExtractModelIdProp<TProps extends ModelProps> = {
[K in keyof TProps]: TProps[K]["_internal"]["$isId"] extends true ? K : never;

@@ -23,0 +23,0 @@ }[keyof TProps];

@@ -21,3 +21,3 @@ import type { AnyDataModel } from "../dataModel/BaseDataModel";

*/
export declare type ModelClass<M extends AnyModel | AnyDataModel> = {
export type ModelClass<M extends AnyModel | AnyDataModel> = {
new (initialData: any): M;

@@ -30,23 +30,23 @@ fromSnapshotProcessor?(sn: any): any;

*/
export declare type AbstractModelClass<M extends AnyModel | AnyDataModel> = abstract new (initialData: any) => M;
export type AbstractModelClass<M extends AnyModel | AnyDataModel> = abstract new (initialData: any) => M;
/**
* The props of a model.
*/
export declare type ModelPropsOf<M extends AnyModel | AnyDataModel> = M[typeof propsTypeSymbol];
export type ModelPropsOf<M extends AnyModel | AnyDataModel> = M[typeof propsTypeSymbol];
/**
* The data type of a model, without transformations applied.
*/
export declare type ModelUntransformedData<M extends AnyModel | AnyDataModel> = Flatten<M["$"]>;
export type ModelUntransformedData<M extends AnyModel | AnyDataModel> = Flatten<M["$"]>;
/**
* The creation data type of a model, without transformations applied.
*/
export declare type ModelUntransformedCreationData<M extends AnyModel | AnyDataModel> = ModelPropsToUntransformedCreationData<ModelPropsOf<M>>;
export type ModelUntransformedCreationData<M extends AnyModel | AnyDataModel> = ModelPropsToUntransformedCreationData<ModelPropsOf<M>>;
/**
* The data type of a model, with transformations applied.
*/
export declare type ModelData<M extends AnyModel | AnyDataModel> = ModelPropsToTransformedData<ModelPropsOf<M>>;
export type ModelData<M extends AnyModel | AnyDataModel> = ModelPropsToTransformedData<ModelPropsOf<M>>;
/**
* The creation data type of a model, with transformations applied.
*/
export declare type ModelCreationData<M extends AnyModel | AnyDataModel> = ModelPropsToTransformedCreationData<ModelPropsOf<M>>;
export type ModelCreationData<M extends AnyModel | AnyDataModel> = ModelPropsToTransformedCreationData<ModelPropsOf<M>>;
/**

@@ -57,3 +57,3 @@ * The from snapshot type of a model.

*/
export declare type ModelFromSnapshot<M extends AnyModel> = IsNeverType<M[typeof fromSnapshotOverrideTypeSymbol], ModelPropsToSnapshotCreationData<ModelPropsOf<M>>, M[typeof fromSnapshotOverrideTypeSymbol]> & {
export type ModelFromSnapshot<M extends AnyModel> = IsNeverType<M[typeof fromSnapshotOverrideTypeSymbol], ModelPropsToSnapshotCreationData<ModelPropsOf<M>>, M[typeof fromSnapshotOverrideTypeSymbol]> & {
[modelTypeKey]?: string;

@@ -66,3 +66,3 @@ };

*/
export declare type ModelToSnapshot<M extends AnyModel> = IsNeverType<M[typeof toSnapshotOverrideTypeSymbol], ModelPropsToSnapshotData<ModelPropsOf<M>>, M[typeof toSnapshotOverrideTypeSymbol]> & {
export type ModelToSnapshot<M extends AnyModel> = IsNeverType<M[typeof toSnapshotOverrideTypeSymbol], ModelPropsToSnapshotData<ModelPropsOf<M>>, M[typeof toSnapshotOverrideTypeSymbol]> & {
[modelTypeKey]?: string;

@@ -69,0 +69,0 @@ };

@@ -55,7 +55,7 @@ import type { SnapshotInOf, SnapshotOutOf } from "../snapshot/SnapshotOf";

*/
export declare type ModelPropFromSnapshot<MP extends AnyModelProp> = IsNeverType<MP["_internal"]["$fromSnapshotOverride"], SnapshotInOf<MP["_internal"]["$creationValueType"]>, MP["_internal"]["$fromSnapshotOverride"]>;
export type ModelPropFromSnapshot<MP extends AnyModelProp> = IsNeverType<MP["_internal"]["$fromSnapshotOverride"], SnapshotInOf<MP["_internal"]["$creationValueType"]>, MP["_internal"]["$fromSnapshotOverride"]>;
/**
* The snapshot out type of a model property.
*/
export declare type ModelPropToSnapshot<MP extends AnyModelProp> = IsNeverType<MP["_internal"]["$toSnapshotOverride"], SnapshotOutOf<MP["_internal"]["$valueType"]>, MP["_internal"]["$toSnapshotOverride"]>;
export type ModelPropToSnapshot<MP extends AnyModelProp> = IsNeverType<MP["_internal"]["$toSnapshotOverride"], SnapshotOutOf<MP["_internal"]["$valueType"]>, MP["_internal"]["$toSnapshotOverride"]>;
/**

@@ -78,3 +78,3 @@ * A model prop transform.

*/
export declare type AnyModelProp = ModelProp<any, any, any, any, any, any, any, any, any>;
export type AnyModelProp = ModelProp<any, any, any, any, any, any, any, any, any>;
/**

@@ -86,12 +86,12 @@ * Model properties.

}
export declare type RequiredModelProps<MP extends ModelProps> = {
export type RequiredModelProps<MP extends ModelProps> = {
[K in keyof MP]: MP[K]["_internal"]["$isRequired"] & K;
}[keyof MP];
export declare type ModelPropsToUntransformedData<MP extends ModelProps> = Flatten<{
export type ModelPropsToUntransformedData<MP extends ModelProps> = Flatten<{
[k in keyof MP]: MP[k]["_internal"]["$valueType"];
}>;
export declare type ModelPropsToSnapshotData<MP extends ModelProps> = Flatten<{
export type ModelPropsToSnapshotData<MP extends ModelProps> = Flatten<{
[k in keyof MP]: ModelPropToSnapshot<MP[k]> extends infer R ? R : never;
}>;
export declare type ModelPropsToUntransformedCreationData<MP extends ModelProps> = {
export type ModelPropsToUntransformedCreationData<MP extends ModelProps> = {
[k in keyof MP]?: MP[k]["_internal"]["$creationValueType"];

@@ -101,3 +101,3 @@ } & {

};
export declare type ModelPropsToSnapshotCreationData<MP extends ModelProps> = Flatten<{
export type ModelPropsToSnapshotCreationData<MP extends ModelProps> = Flatten<{
[k in keyof MP]?: ModelPropFromSnapshot<MP[k]> extends infer R ? R : never;

@@ -110,6 +110,6 @@ } & {

}>;
export declare type ModelPropsToTransformedData<MP extends ModelProps> = Flatten<{
export type ModelPropsToTransformedData<MP extends ModelProps> = Flatten<{
[k in keyof MP]: MP[k]["_internal"]["$transformedValueType"];
}>;
export declare type ModelPropsToTransformedCreationData<MP extends ModelProps> = {
export type ModelPropsToTransformedCreationData<MP extends ModelProps> = {
[k in keyof MP]?: MP[k]["_internal"]["$transformedCreationValueType"];

@@ -119,6 +119,6 @@ } & {

};
export declare type ModelPropsToSetter<MP extends ModelProps> = Flatten<{
export type ModelPropsToSetter<MP extends ModelProps> = Flatten<{
[k in keyof MP as MP[k]["_internal"]["$hasSetter"] & `set${Capitalize<k & string>}`]: (value: MP[k]["_internal"]["$transformedValueType"]) => void;
}>;
export declare type ModelIdProp<T extends string = string> = ModelProp<T, T | undefined, T, T | undefined, never, // not required
export type ModelIdProp<T extends string = string> = ModelProp<T, T | undefined, T, T | undefined, never, // not required
true>;

@@ -139,11 +139,11 @@ /**

*/
export declare type OnlyPrimitives<T> = Exclude<T, object>;
export type OnlyPrimitives<T> = Exclude<T, object>;
/**
* A model prop that maybe / maybe not is optional, depending on if the value can take undefined.
*/
export declare type MaybeOptionalModelProp<TPropValue> = ModelProp<TPropValue, TPropValue, TPropValue, TPropValue, IsOptionalValue<TPropValue, never, string>>;
export type MaybeOptionalModelProp<TPropValue> = ModelProp<TPropValue, TPropValue, TPropValue, TPropValue, IsOptionalValue<TPropValue, never, string>>;
/**
* A model prop that is definitely optional.
*/
export declare type OptionalModelProp<TPropValue> = ModelProp<TPropValue, TPropValue | null | undefined, TPropValue, TPropValue | null | undefined, never>;
export type OptionalModelProp<TPropValue> = ModelProp<TPropValue, TPropValue | null | undefined, TPropValue, TPropValue | null | undefined, never>;
/**

@@ -150,0 +150,0 @@ * Defines a model property, with an optional function to generate a default value

@@ -5,4 +5,4 @@ import { AnyDataModel } from "../dataModel/BaseDataModel";

import { ModelProps } from "./prop";
declare type FromSnapshotProcessorFn = (sn: any) => any;
declare type ToSnapshotProcessorFn = (sn: any, instance: any) => any;
type FromSnapshotProcessorFn = (sn: any) => any;
type ToSnapshotProcessorFn = (sn: any, instance: any) => any;
export declare function sharedInternalModel<TProps extends ModelProps, TBaseModel extends AnyModel | AnyDataModel>({ modelProps, baseModel, type, valueType, fromSnapshotProcessor, toSnapshotProcessor, }: {

@@ -9,0 +9,0 @@ modelProps: TProps;

/**
* Property name (if the parent is an object) or index number (if the parent is an array).
*/
export declare type PathElement = string | number;
export type PathElement = string | number;
/**
* Path from a parent to a child.
*/
export declare type Path = ReadonlyArray<string | number>;
export type Path = ReadonlyArray<string | number>;
/**
* Path from a parent to a child (writable).
*/
export declare type WritablePath = (string | number)[];
export type WritablePath = (string | number)[];

@@ -5,11 +5,11 @@ import type { Patch } from "./Patch";

*/
export declare type OnPatchesListener = (patches: Patch[], inversePatches: Patch[]) => void;
export type OnPatchesListener = (patches: Patch[], inversePatches: Patch[]) => void;
/**
* A function that gets called when a global patch is emitted.
*/
export declare type OnGlobalPatchesListener = (target: object, patches: Patch[], inversePatches: Patch[]) => void;
export type OnGlobalPatchesListener = (target: object, patches: Patch[], inversePatches: Patch[]) => void;
/**
* Disposer function to stop listening to patches.
*/
export declare type OnPatchesDisposer = () => void;
export type OnPatchesDisposer = () => void;
/**

@@ -16,0 +16,0 @@ * Adds a listener that will be called every time a patch is generated for the tree of the given target object.

import type { Path } from "../parent/pathTypes";
import type { Patch } from "./Patch";
export declare type JsonPatch = JsonPatchAddOperation<any> | JsonPatchRemoveOperation | JsonPatchReplaceOperation<any>;
export type JsonPatch = JsonPatchAddOperation<any> | JsonPatchRemoveOperation | JsonPatchReplaceOperation<any>;
export interface JsonPatchBaseOperation {

@@ -5,0 +5,0 @@ path: string;

import type { Path } from "../parent/pathTypes";
export declare type Patch = PatchAddOperation<any> | PatchRemoveOperation | PatchReplaceOperation<any>;
export type Patch = PatchAddOperation<any> | PatchRemoveOperation | PatchReplaceOperation<any>;
export interface PatchBaseOperation {

@@ -4,0 +4,0 @@ path: Path;

@@ -6,11 +6,11 @@ import { ObservableSet } from "mobx";

*/
export declare type RefResolver<T extends object> = (ref: Ref<T>) => T | undefined;
export type RefResolver<T extends object> = (ref: Ref<T>) => T | undefined;
/**
* Reference ID resolver type.
*/
export declare type RefIdResolver = (target: object) => string | undefined;
export type RefIdResolver = (target: object) => string | undefined;
/**
* Type for the callback called when a reference resolved value changes.
*/
export declare type RefOnResolvedValueChange<T extends object> = (ref: Ref<T>, newValue: T | undefined, oldValue: T | undefined) => void;
export type RefOnResolvedValueChange<T extends object> = (ref: Ref<T>, newValue: T | undefined, oldValue: T | undefined) => void;
/**

@@ -17,0 +17,0 @@ * Uses a model `getRefId()` method whenever possible to get a reference ID.

@@ -5,7 +5,7 @@ import type { SnapshotOutOf } from "./SnapshotOf";

*/
export declare type OnSnapshotListener<T> = (sn: SnapshotOutOf<T>, prevSn: SnapshotOutOf<T>) => void;
export type OnSnapshotListener<T> = (sn: SnapshotOutOf<T>, prevSn: SnapshotOutOf<T>) => void;
/**
* Disposer function for onSnapshot.
*/
export declare type OnSnapshotDisposer = () => void;
export type OnSnapshotDisposer = () => void;
/**

@@ -12,0 +12,0 @@ * Adds a reaction that will trigger every time an snapshot changes.

@@ -6,7 +6,7 @@ import type { Frozen, frozenKey } from "../frozen/Frozen";

import type { ArraySet, ObjectMap } from "../wrappers";
export declare type SnapshotOutOfObject<T> = {
export type SnapshotOutOfObject<T> = {
[k in keyof T]: SnapshotOutOf<T[k]> extends infer R ? R : never;
};
export declare type SnapshotOutOfModel<M extends AnyModel> = ModelToSnapshot<M>;
export declare type SnapshotOutOfFrozen<F extends Frozen<any>> = {
export type SnapshotOutOfModel<M extends AnyModel> = ModelToSnapshot<M>;
export type SnapshotOutOfFrozen<F extends Frozen<any>> = {
[frozenKey]: true;

@@ -27,8 +27,8 @@ data: F["data"];

}
export declare type SnapshotOutOf<T> = T extends ObjectMap<infer V> ? SnapshotOutOfObjectMap<V> extends infer R ? R : never : T extends ArraySet<infer V> ? SnapshotOutOfArraySet<V> extends infer R ? R : never : T extends AnyModel ? SnapshotOutOfModel<T> extends infer R ? R : never : T extends Frozen<any> ? SnapshotOutOfFrozen<T> extends infer R ? R : never : T extends object ? SnapshotOutOfObject<T> extends infer R ? R : never : T;
export declare type SnapshotInOfObject<T> = {
export type SnapshotOutOf<T> = T extends ObjectMap<infer V> ? SnapshotOutOfObjectMap<V> extends infer R ? R : never : T extends ArraySet<infer V> ? SnapshotOutOfArraySet<V> extends infer R ? R : never : T extends AnyModel ? SnapshotOutOfModel<T> extends infer R ? R : never : T extends Frozen<any> ? SnapshotOutOfFrozen<T> extends infer R ? R : never : T extends object ? SnapshotOutOfObject<T> extends infer R ? R : never : T;
export type SnapshotInOfObject<T> = {
[k in keyof T]: SnapshotInOf<T[k]> extends infer R ? R : never;
};
export declare type SnapshotInOfModel<M extends AnyModel> = ModelFromSnapshot<M>;
export declare type SnapshotInOfFrozen<F extends Frozen<any>> = {
export type SnapshotInOfModel<M extends AnyModel> = ModelFromSnapshot<M>;
export type SnapshotInOfFrozen<F extends Frozen<any>> = {
[frozenKey]: true;

@@ -49,2 +49,2 @@ data: F["data"];

}
export declare type SnapshotInOf<T> = T extends ObjectMap<infer V> ? SnapshotInOfObjectMap<V> extends infer R ? R : never : T extends ArraySet<infer V> ? SnapshotInOfArraySet<V> extends infer R ? R : never : T extends AnyModel ? SnapshotInOfModel<T> extends infer R ? R : never : T extends Frozen<any> ? SnapshotInOfFrozen<T> extends infer R ? R : never : T extends object ? SnapshotInOfObject<T> extends infer R ? R : never : T;
export type SnapshotInOf<T> = T extends ObjectMap<infer V> ? SnapshotInOfObjectMap<V> extends infer R ? R : never : T extends ArraySet<infer V> ? SnapshotInOfArraySet<V> extends infer R ? R : never : T extends AnyModel ? SnapshotInOfModel<T> extends infer R ? R : never : T extends Frozen<any> ? SnapshotInOfFrozen<T> extends infer R ? R : never : T extends object ? SnapshotInOfObject<T> extends infer R ? R : never : T;

@@ -18,3 +18,3 @@ /**

*/
export declare type WithSandboxCallback<T extends readonly [object, ...object[]], R> = (...nodes: T) => boolean | {
export type WithSandboxCallback<T extends readonly [object, ...object[]], R> = (...nodes: T) => boolean | {
commit: boolean;

@@ -21,0 +21,0 @@ return: R;

@@ -5,4 +5,4 @@ import type { AnyDataModel } from "../../dataModel/BaseDataModel";

import { TypeInfo } from "../TypeChecker";
declare type _Class<T> = abstract new (...args: any[]) => T;
declare type _ClassOrObject<M, K> = K extends M ? object : _Class<K> | (() => _Class<K>);
type _Class<T> = abstract new (...args: any[]) => T;
type _ClassOrObject<M, K> = K extends M ? object : _Class<K> | (() => _Class<K>);
/**

@@ -9,0 +9,0 @@ * A type that represents a data model data.

@@ -5,4 +5,4 @@ import type { AnyModel } from "../../model/BaseModel";

import { TypeInfo } from "../TypeChecker";
declare type _Class<T> = abstract new (...args: any[]) => T;
declare type _ClassOrObject<M, K> = K extends M ? object : _Class<K> | (() => _Class<K>);
type _Class<T> = abstract new (...args: any[]) => T;
type _ClassOrObject<M, K> = K extends M ? object : _Class<K> | (() => _Class<K>);
/**

@@ -9,0 +9,0 @@ * A type that represents a model. The type referenced in the model decorator will be used for type checking.

@@ -14,3 +14,3 @@ import type { IdentityType } from "../schemas";

*/
export declare type EnumValues<E extends EnumLike> = E extends Record<infer _K, // eslint-disable-line @typescript-eslint/no-unused-vars
export type EnumValues<E extends EnumLike> = E extends Record<infer _K, // eslint-disable-line @typescript-eslint/no-unused-vars
infer V> ? V : never;

@@ -17,0 +17,0 @@ /**

@@ -27,3 +27,3 @@ import type { O } from "ts-toolbelt";

*/
declare type UndefinablePropsNames<T> = {
type UndefinablePropsNames<T> = {
[K in keyof T]: IsOptionalValue<T[K], K, never>;

@@ -44,12 +44,12 @@ }[keyof T];

}
export declare type AnyStandardType = IdentityType<any> | ModelType<any> | ArrayType<any> | ObjectType<any> | RecordType<any> | ObjectTypeFunction;
export declare type AnyType = null | undefined | AnyNonValueType;
export declare type AnyNonValueType = ModelClass<AnyModel> | StringConstructor | NumberConstructor | BooleanConstructor | AnyStandardType;
export declare type TypeToData<S> = S extends ObjectTypeFunction ? ObjectType<ReturnType<S>>["$$data"] extends infer R ? R : never : S extends {
export type AnyStandardType = IdentityType<any> | ModelType<any> | ArrayType<any> | ObjectType<any> | RecordType<any> | ObjectTypeFunction;
export type AnyType = null | undefined | AnyNonValueType;
export type AnyNonValueType = ModelClass<AnyModel> | StringConstructor | NumberConstructor | BooleanConstructor | AnyStandardType;
export type TypeToData<S> = S extends ObjectTypeFunction ? ObjectType<ReturnType<S>>["$$data"] extends infer R ? R : never : S extends {
$$data: infer D;
} ? D : S extends ModelClass<infer M> ? M : S extends StringConstructor ? string : S extends NumberConstructor ? number : S extends BooleanConstructor ? boolean : S extends null ? null : S extends undefined ? undefined : never;
/** @ignore */
export declare type TypeToDataOpt<S> = S extends {
export type TypeToDataOpt<S> = S extends {
$$data: infer D;
} ? D & undefined : never;
export {};

@@ -9,15 +9,19 @@ import { Path } from "../parent/pathTypes";

readonly actualValue: any;
readonly typeCheckedValue?: any;
/**
* The type check error message.
*/
readonly message: string;
/**
* Creates an instance of TypeError.
* @param path Sub-path where the error occured.
* @param path Sub-path (where the root is the value being type checked) where the error occured.
* @param expectedTypeName Name of the expected type.
* @param actualValue Actual value.
* @param typeCheckedValue The value where the type check was invoked.
*/
constructor(path: Path, expectedTypeName: string, actualValue: any);
constructor(path: Path, expectedTypeName: string, actualValue: any, typeCheckedValue?: any);
/**
* Throws the type check error as an actual error.
*
* @param typeCheckedValue Usually the value where the type check was invoked.
*/
throw(typeCheckedValue: any): never;
throw(): never;
}

@@ -6,3 +6,3 @@ /**

*/
export declare type PrimitiveValue = undefined | null | boolean | number | string | bigint;
export type PrimitiveValue = undefined | null | boolean | number | string | bigint;
/**

@@ -13,3 +13,3 @@ * @ignore

*/
export declare type JSONPrimitiveValue = null | boolean | number | string;
export type JSONPrimitiveValue = null | boolean | number | string;
/**

@@ -31,12 +31,12 @@ * @ignore

*/
export declare type IsOptionalValue<C, TV, FV> = IsNeverType<Extract<C, undefined>, FV, TV>;
export type IsOptionalValue<C, TV, FV> = IsNeverType<Extract<C, undefined>, FV, TV>;
/**
* @ignore
*/
export declare type IsNeverType<T, IfNever, IfNotNever> = [T] extends [never] ? IfNever : IfNotNever;
export type IsNeverType<T, IfNever, IfNotNever> = [T] extends [never] ? IfNever : IfNotNever;
/**
* @ignore
*/
export declare type Flatten<T> = T extends Record<any, any> ? {
export type Flatten<T> = T extends Record<any, any> ? {
[P in keyof T]: T[P];
} : T;
{
"name": "mobx-keystone",
"version": "1.1.1",
"version": "1.2.0",
"description": "A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more",

@@ -68,14 +68,14 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.19.3",
"@babel/core": "^7.20.2",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.19.3",
"@babel/preset-env": "^7.19.3",
"@babel/plugin-proposal-decorators": "^7.20.2",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@swc/core": "^1.3.5",
"@swc/core": "^1.3.17",
"@swc/jest": "^0.2.23",
"@types/jest": "^29.1.2",
"@types/node": "^18.8.3",
"babel-jest": "^29.1.2",
"jest": "^29.1.2",
"mobx": "^6.6.2",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"babel-jest": "^29.3.1",
"jest": "^29.3.1",
"mobx": "^6.7.0",
"mobx-v4": "npm:mobx@^4.15.7",

@@ -88,5 +88,5 @@ "mobx-v5": "npm:mobx@^5.15.7",

"ts-node": "^10.9.1",
"typedoc": "^0.23.15",
"typescript": "^4.8.4",
"vite": "^3.1.6"
"typedoc": "^0.23.21",
"typescript": "^4.9.3",
"vite": "^3.2.4"
},

@@ -97,3 +97,3 @@ "dependencies": {

"ts-toolbelt": "^9.6.0",
"tslib": "^2.4.0"
"tslib": "^2.4.1"
},

@@ -100,0 +100,0 @@ "directories": {

@@ -49,3 +49,3 @@ import { action } from "mobx"

if (err) {
err.throw(modelObj)
err.throw()
}

@@ -52,0 +52,0 @@ }

@@ -142,3 +142,3 @@ import { action, set } from "mobx"

if (err) {
err.throw(modelObj)
err.throw()
}

@@ -145,0 +145,0 @@ }

@@ -13,3 +13,12 @@ import { isObservableObject } from "mobx"

import { assertTweakedObject } from "../tweaker/core"
import { assertIsObject, failure, inDevMode, isArray, isPlainObject, lazy } from "../utils"
import {
assertIsObject,
failure,
inDevMode,
isArray,
isMap,
isPlainObject,
isSet,
lazy,
} from "../utils"
import { ModelPool } from "../utils/ModelPool"

@@ -128,2 +137,10 @@ import { reconcileSnapshot } from "./reconcileSnapshot"

if (isMap(sn)) {
throw failure("a snapshot must not contain maps")
}
if (isSet(sn)) {
throw failure("a snapshot must not contain sets")
}
throw failure(`unsupported snapshot - ${sn}`)

@@ -130,0 +147,0 @@ }

@@ -60,3 +60,3 @@ import { action } from "mobx"

if (errors) {
errors.throw(value)
errors.throw()
}

@@ -63,0 +63,0 @@ }

@@ -43,3 +43,3 @@ import { isModelAutoTypeCheckingEnabled } from "../globalConfig/globalConfig"

// at the end of apply patches it will be type checked again and its result cached once more
err.throw(parentModelWithTypeChecker)
err.throw()
}

@@ -46,0 +46,0 @@ }

@@ -38,5 +38,5 @@ import { isArray } from "../../utils"

(array, path) => {
(array, path, typeCheckedValue) => {
if (!isArray(array)) {
return new TypeCheckError(path, getTypeName(thisTc), array)
return new TypeCheckError(path, getTypeName(thisTc), array, typeCheckedValue)
}

@@ -46,3 +46,3 @@

for (let i = 0; i < array.length; i++) {
const itemError = itemChecker.check(array[i], [...path, i])
const itemError = itemChecker.check(array[i], [...path, i], typeCheckedValue)
if (itemError) {

@@ -49,0 +49,0 @@ return itemError

@@ -46,9 +46,9 @@ import { isArray, lazy } from "../../utils"

(array, path) => {
(array, path, typeCheckedValue) => {
if (!isArray(array) || array.length !== itemTypes.length) {
return new TypeCheckError(path, getTypeName(thisTc), array)
return new TypeCheckError(path, getTypeName(thisTc), array, typeCheckedValue)
}
for (let i = 0; i < array.length; i++) {
const itemError = checkers[i].check(array[i], [...path, i])
const itemError = checkers[i].check(array[i], [...path, i], typeCheckedValue)
if (itemError) {

@@ -55,0 +55,0 @@ return itemError

@@ -49,9 +49,9 @@ import { modelTypeKey } from "../../model/metadata"

(obj, path) => {
(obj, path, typeCheckedValue) => {
if (!(obj instanceof ArraySet)) {
return new TypeCheckError(path, getTypeName(thisTc), obj)
return new TypeCheckError(path, getTypeName(thisTc), obj, typeCheckedValue)
}
const resolvedTc = resolveTypeChecker(dataTypeChecker)
return resolvedTc.check(obj.$, path)
return resolvedTc.check(obj.$, path, typeCheckedValue)
},

@@ -58,0 +58,0 @@

@@ -88,4 +88,4 @@ import type { O } from "ts-toolbelt"

(value, path) => {
return resolvedDataTypeChecker.check(value, path)
(value, path, typeCheckedValue) => {
return resolvedDataTypeChecker.check(value, path, typeCheckedValue)
},

@@ -92,0 +92,0 @@

@@ -72,9 +72,9 @@ import type { O } from "ts-toolbelt"

(value, path) => {
(value, path, typeCheckedValue) => {
if (!(value instanceof modelClazz)) {
return new TypeCheckError(path, typeName, value)
return new TypeCheckError(path, typeName, value, typeCheckedValue)
}
if (resolvedDataTypeChecker) {
return resolvedDataTypeChecker.check(value.$, path)
return resolvedDataTypeChecker.check(value.$, path, typeCheckedValue)
}

@@ -81,0 +81,0 @@

@@ -72,5 +72,5 @@ import type { O } from "ts-toolbelt"

(obj, path) => {
(obj, path, typeCheckedValue) => {
if (!isObject(obj) || (frozen && !(obj instanceof Frozen))) {
return new TypeCheckError(path, getTypeName(thisTc), obj)
return new TypeCheckError(path, getTypeName(thisTc), obj, typeCheckedValue)
}

@@ -83,3 +83,3 @@

const valueError = tc.check(objVal, [...path, k])
const valueError = tc.check(objVal, [...path, k], typeCheckedValue)
if (valueError) {

@@ -86,0 +86,0 @@ return valueError

@@ -52,8 +52,8 @@ import { modelTypeKey } from "../../model/metadata"

(obj, path) => {
(obj, path, typeCheckedValue) => {
if (!(obj instanceof ObjectMap)) {
return new TypeCheckError(path, getTypeName(thisTc), obj)
return new TypeCheckError(path, getTypeName(thisTc), obj, typeCheckedValue)
}
return resolvedDataTypeChecker.check(obj.$, path)
return resolvedDataTypeChecker.check(obj.$, path, typeCheckedValue)
},

@@ -60,0 +60,0 @@

@@ -59,5 +59,5 @@ import { isObject } from "../../utils"

(obj, path) => {
(obj, path, typeCheckedValue) => {
if (!isObject(obj)) {
return new TypeCheckError(path, getTypeName(thisTc), obj)
return new TypeCheckError(path, getTypeName(thisTc), obj, typeCheckedValue)
}

@@ -70,3 +70,3 @@

const v = obj[k]
const valueError = valueChecker.check(v, [...path, k])
const valueError = valueChecker.check(v, [...path, k], typeCheckedValue)
if (valueError) {

@@ -73,0 +73,0 @@ return valueError

@@ -38,8 +38,8 @@ import { modelTypeKey } from "../../model/metadata"

(value, path) => {
(value, path, typeCheckedValue) => {
if (!(value instanceof Ref)) {
return new TypeCheckError(path, typeName, value)
return new TypeCheckError(path, typeName, value, typeCheckedValue)
}
return refDataTypeChecker.check(value.$, path)
return refDataTypeChecker.check(value.$, path, typeCheckedValue)
},

@@ -46,0 +46,0 @@

@@ -43,3 +43,4 @@ import { assertIsPrimitive, identityFn } from "../../utils"

(value, path) => (value === literal ? null : new TypeCheckError(path, typeName, value)),
(value, path, typeCheckedValue) =>
value === literal ? null : new TypeCheckError(path, typeName, value, typeCheckedValue),

@@ -100,3 +101,6 @@ () => typeName,

(value, path) => (typeof value === "boolean" ? null : new TypeCheckError(path, "boolean", value)),
(value, path, typeCheckedValue) =>
typeof value === "boolean"
? null
: new TypeCheckError(path, "boolean", value, typeCheckedValue),

@@ -128,3 +132,4 @@ () => "boolean",

(value, path) => (typeof value === "number" ? null : new TypeCheckError(path, "number", value)),
(value, path, typeCheckedValue) =>
typeof value === "number" ? null : new TypeCheckError(path, "number", value, typeCheckedValue),

@@ -156,3 +161,4 @@ () => "number",

(value, path) => (typeof value === "string" ? null : new TypeCheckError(path, "string", value)),
(value, path, typeCheckedValue) =>
typeof value === "string" ? null : new TypeCheckError(path, "string", value, typeCheckedValue),

@@ -159,0 +165,0 @@ () => "string",

@@ -19,4 +19,4 @@ import { resolveTypeChecker } from "./resolveTypeChecker"

} else {
return typeChecker.check(value, [])
return typeChecker.check(value, [], value)
}
}

@@ -9,3 +9,3 @@ import { fastGetParentIncludingDataObjects } from "../parent/path"

type CheckFunction = (value: any, path: Path) => TypeCheckError | null
type CheckFunction = (value: any, path: Path, typeCheckedValue: any) => TypeCheckError | null

@@ -108,3 +108,3 @@ const emptyPath: Path = []

check(value: any, path: Path): TypeCheckError | null {
check(value: any, path: Path, typeCheckedValue: any): TypeCheckError | null {
if (this.unchecked) {

@@ -115,3 +115,3 @@ return null

if (!isTweakedObject(value, true)) {
return this._check!(value, path)
return this._check!(value, path, typeCheckedValue)
}

@@ -124,4 +124,4 @@

if (cachedResult === undefined) {
// we set the path empty since the result could be used for paths other than this base
cachedResult = this._check!(value, emptyPath)
// we set the path empty and no parent, since the result could be used for paths other than this base
cachedResult = this._check!(value, emptyPath, undefined)
this.setCachedResult(value, cachedResult)

@@ -134,3 +134,4 @@ }

cachedResult.expectedTypeName,
cachedResult.actualValue
cachedResult.actualValue,
typeCheckedValue
)

@@ -137,0 +138,0 @@ } else {

import { getRootPath } from "../parent/path"
import { Path } from "../parent/pathTypes"
import { getSnapshot } from "../snapshot/getSnapshot"
import { isTweakedObject } from "../tweaker/core"

@@ -11,27 +12,41 @@ import { failure } from "../utils"

/**
* The type check error message.
*/
readonly message: string
/**
* Creates an instance of TypeError.
* @param path Sub-path where the error occured.
* @param path Sub-path (where the root is the value being type checked) where the error occured.
* @param expectedTypeName Name of the expected type.
* @param actualValue Actual value.
* @param typeCheckedValue The value where the type check was invoked.
*/
constructor(readonly path: Path, readonly expectedTypeName: string, readonly actualValue: any) {}
/**
* Throws the type check error as an actual error.
*
* @param typeCheckedValue Usually the value where the type check was invoked.
*/
throw(typeCheckedValue: any): never {
let msg = "TypeCheckError: "
constructor(
readonly path: Path,
readonly expectedTypeName: string,
readonly actualValue: any,
readonly typeCheckedValue?: any
) {
let rootPath: Path = []
if (isTweakedObject(typeCheckedValue, true)) {
rootPath = getRootPath(typeCheckedValue).path
if (this.typeCheckedValue && isTweakedObject(this.typeCheckedValue, true)) {
rootPath = getRootPath(this.typeCheckedValue).path
}
msg += "[/" + [...rootPath, ...this.path].join("/") + "] "
const actualValueSnapshot = isTweakedObject(this.actualValue, true)
? getSnapshot(this.actualValue)
: this.actualValue
msg += "Expected: " + this.expectedTypeName
this.message = `TypeCheckError: [/${[...rootPath, ...this.path].join(
"/"
)}] Expected a value of type <${this.expectedTypeName}> but got the value <${JSON.stringify(
actualValueSnapshot
)}> instead`
}
throw failure(msg)
/**
* Throws the type check error as an actual error.
*/
throw(): never {
throw failure(this.message)
}
}

@@ -104,8 +104,8 @@ import { failure, lazy } from "../../utils"

(value, path) => {
const someMatchingType = checkers.some((tc) => !tc.check(value, path))
(value, path, typeCheckedValue) => {
const someMatchingType = checkers.some((tc) => !tc.check(value, path, typeCheckedValue))
if (someMatchingType) {
return null
} else {
return new TypeCheckError(path, getTypeName(thisTc), value)
return new TypeCheckError(path, getTypeName(thisTc), value, typeCheckedValue)
}

@@ -112,0 +112,0 @@ },

@@ -58,4 +58,4 @@ import { getTypeInfo } from "../getTypeInfo"

(data, path) => {
const baseErr = baseChecker.check(data, path)
(data, path, typeCheckedValue) => {
const baseErr = baseChecker.check(data, path, typeCheckedValue)
if (baseErr) {

@@ -67,8 +67,14 @@ return baseErr

if (refinementErr === true) {
if (refinementErr === true || refinementErr == null) {
return null
} else if (refinementErr === false) {
return new TypeCheckError(path, getTypeName(thisTc), data)
return new TypeCheckError(path, getTypeName(thisTc), data, typeCheckedValue)
} else {
return refinementErr ?? null
// override typeCheckedValue
return new TypeCheckError(
refinementErr.path,
refinementErr.expectedTypeName,
refinementErr.actualValue,
typeCheckedValue
)
}

@@ -75,0 +81,0 @@ },

@@ -52,3 +52,3 @@ import { getTypeInfo } from "../getTypeInfo"

baseChecker.baseType,
(data, path) => baseChecker.check(data, path),
(data, path, typeCheckedValue) => baseChecker.check(data, path, typeCheckedValue),
getTypeName,

@@ -55,0 +55,0 @@ typeInfoGen,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc