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 0.52.0 to 0.53.0

5

dist/actionMiddlewares/actionSerialization/mapSerializer.d.ts
import { ObservableMap } from "mobx";
import { ActionCallArgumentSerializer } from "./core";
export declare const mapSerializer: ActionCallArgumentSerializer<Map<any, any> | ObservableMap<any, any>, [any, any][]>;
export declare const mapSerializer: ActionCallArgumentSerializer<Map<any, any> | ObservableMap<any, any>, [
any,
any
][]>;

2

dist/actionMiddlewares/undoMiddleware.d.ts

@@ -63,3 +63,3 @@ import { ActionMiddlewareDisposer } from "../action/middleware";

} & {
$modelId: import("..").ModelProp<string, string, string, string, string, true>;
$modelId: import("..").ModelProp<string, string, string, string, string, true, never>;
}>;

@@ -66,0 +66,0 @@ /**

import { AnyStandardType, TypeToData } from "../typeChecking/schemas";
import { FnModelActions, FnModelActionsDef } from "./actions";
import { FnModelFn } from "./core";
import { FnModelFlowActions, FnModelFlowActionsDef } from "./flowActions";
import { FnModelSetterActions, FnModelSetterActionsDef } from "./setterActions";
import { FnModelViews, FnModelViewsDef } from "./views";

@@ -47,3 +47,3 @@ declare const dataTypeSymbol: unique symbol;

*/
setterActions<SA extends FnModelSetterActionsDef<Data>>(setterActions: ThisType<Data> & SA): FnModel<Data, Extra & FnModelSetterActions<Data, SA>>;
setterActions<SA extends FnModelSetterActionsArrayDef<Data>>(...setterActions: SA): FnModel<Data, Extra & FnModelSetterActionsArray<Data, SA>>;
}

@@ -75,2 +75,12 @@ /**

export declare function fnModel<Data extends object>(namespace: string): FnModel<Data, {}>;
/**
* An array with functional model setter action definitions.
*/
export declare type FnModelSetterActionsArrayDef<Data> = ReadonlyArray<keyof Data & string>;
/**
* Array to functional model setter actions.
*/
export declare type FnModelSetterActionsArray<Data extends object, SetterActionsDef extends FnModelSetterActionsArrayDef<Data>> = {
[K in SetterActionsDef[number] as `set${Capitalize<K>}`]: FnModelFn<Data, (value: Data[K]) => void>;
};
export {};

@@ -6,3 +6,2 @@ export * from "./actions";

export * from "./fnObject";
export * from "./setterActions";
export * from "./views";

@@ -126,2 +126,6 @@ import { O } from "ts-toolbelt";

/**
* Extracts the instance type of an abstract model class.
*/
export declare type AbstractModelClass<M extends AnyModel> = abstract new (initialData: any) => M;
/**
* A model class declaration, made of a base model and the model interface.

@@ -128,0 +132,0 @@ */

@@ -1,4 +0,4 @@

import { AnyModel, BaseModel, ModelClass } from "./BaseModel";
import { AbstractModelClass, AnyModel, BaseModel } from "./BaseModel";
import { modelTypeKey } from "./metadata";
import { idProp, ModelProps, ModelPropsToInstanceCreationData, ModelPropsToInstanceData, ModelPropsToPropsCreationData, ModelPropsToPropsData } from "./prop";
import { idProp, ModelProps, ModelPropsToInstanceCreationData, ModelPropsToInstanceData, ModelPropsToPropsCreationData, ModelPropsToPropsData, ModelPropsToSetterActions } from "./prop";
declare const propsDataSymbol: unique symbol;

@@ -19,3 +19,3 @@ declare const instanceDataSymbol: unique symbol;

[composedInstanceCreationDataSymbol]: SuperModel extends BaseModel<any, any, any, infer ICD, any> ? this[typeof instanceCreationDataSymbol] & ICD : this[typeof instanceCreationDataSymbol];
new (data: this[typeof composedInstanceCreationDataSymbol]): SuperModel & BaseModel<this[typeof propsDataSymbol], this[typeof propsCreationDataSymbol], this[typeof instanceDataSymbol], this[typeof instanceCreationDataSymbol], ExtractModelIdProp<TProps> & string> & Omit<this[typeof instanceDataSymbol], keyof AnyModel>;
new (data: this[typeof composedInstanceCreationDataSymbol]): SuperModel & BaseModel<this[typeof propsDataSymbol], this[typeof propsCreationDataSymbol], this[typeof instanceDataSymbol], this[typeof instanceCreationDataSymbol], ExtractModelIdProp<TProps> & string> & Omit<this[typeof instanceDataSymbol], keyof AnyModel> & ModelPropsToSetterActions<TProps>;
}

@@ -39,3 +39,3 @@ /**

* @typeparam TProps New model properties type.
* @typeparam TBaseModelClass Base class type.
* @typeparam TModel Model type.
* @param baseModel Base model type.

@@ -45,3 +45,3 @@ * @param modelProps Model properties.

*/
export declare function ExtendedModel<TProps extends ModelProps, TBaseModelClass>(baseModel: TBaseModelClass, modelProps: TProps): _Model<TBaseModelClass & Object extends ModelClass<infer M> ? M : never, AddModelIdPropIfNeeded<TProps>>;
export declare function ExtendedModel<TProps extends ModelProps, TModel extends AnyModel>(baseModel: AbstractModelClass<TModel>, modelProps: TProps): _Model<TModel, AddModelIdPropIfNeeded<TProps>>;
/**

@@ -48,0 +48,0 @@ * Base abstract class for models.

@@ -10,7 +10,17 @@ import { O } from "ts-toolbelt";

/**
* Set to `true` to automatically wrap the property setter in a model action (defaults to `false`).
* Set to `true` to automatically generate a property setter in a model action (defaults to `false`).
* Set to `assign` to get the old behaviour of making the property assignable.
*/
readonly setterAction?: boolean;
readonly setterAction?: boolean | "assign";
}
/**
* Model property options with setterAction set to true.
*/
export interface ModelPropOptionsWithSetterAction extends ModelPropOptions {
/**
* Set to `true` to automatically generate a property setter in a model action (defaults to `false`).
*/
readonly setterAction: true;
}
/**
* @ignore

@@ -22,3 +32,3 @@ */

*/
export interface ModelProp<TPropValue, TPropCreationValue, TIsOptional, TInstanceValue = TPropValue, TInstanceCreationValue = TPropCreationValue, TIsId extends boolean = false> {
export interface ModelProp<TPropValue, TPropCreationValue, TIsOptional, TInstanceValue = TPropValue, TInstanceCreationValue = TPropCreationValue, TIsId extends boolean = false, THasSetterAction = never> {
$propValueType: TPropValue;

@@ -30,2 +40,3 @@ $propCreationValueType: TPropCreationValue;

$isId: TIsId;
$hasSetterAction: THasSetterAction;
defaultFn: (() => TPropValue) | typeof noDefaultValue;

@@ -38,6 +49,10 @@ defaultValue: TPropValue | typeof noDefaultValue;

/**
* Any model property.
*/
export declare type AnyModelProp = ModelProp<any, any, any, any, any, any, any>;
/**
* Model properties.
*/
export interface ModelProps {
[k: string]: ModelProp<any, any, any, any, any, any>;
[k: string]: AnyModelProp;
}

@@ -59,2 +74,5 @@ export declare type OptionalModelProps<MP extends ModelProps> = {

}, OptionalModelProps<MP>>;
export declare type ModelPropsToSetterActions<MP extends ModelProps> = {
[k in keyof MP as MP[k]["$hasSetterAction"] & `set${Capitalize<k & string>}`]: (value: MP[k]["$instanceValueType"]) => void;
};
/**

@@ -64,3 +82,3 @@ * A property that will be used as model id, replacing $modelId.

*/
export declare const idProp: ModelProp<string, string, string, string, string, true>;
export declare const idProp: ModelProp<string, string, string, string, string, true, never>;
/**

@@ -75,2 +93,6 @@ * @ignore

/**
* A model prop that maybe / maybe not is optional, depending on if the value can take undefined, with a setter action.
*/
export declare type MaybeOptionalModelPropWithSetterAction<TPropValue, TInstanceValue = TPropValue> = ModelProp<TPropValue, TPropValue, IsOptionalValue<TPropValue, string, never>, TInstanceValue, TInstanceValue, false, string>;
/**
* A model prop that is definitely optional.

@@ -80,2 +102,6 @@ */

/**
* A model prop that is definitely optional, with a setter action.
*/
export declare type OptionalModelPropWithSetterAction<TPropValue, TInstanceValue = TPropValue> = ModelProp<TPropValue, TPropValue | null | undefined, string, TInstanceValue, TInstanceValue | null | undefined, false, string>;
/**
* Defines a model property, with an optional function to generate a default value

@@ -95,2 +121,18 @@ * if the input snapshot / model creation data is `null` or `undefined`.

*/
export declare function prop<TValue>(defaultFn: () => TValue, options: ModelPropOptionsWithSetterAction): OptionalModelPropWithSetterAction<TValue>;
/**
* Defines a model property, with an optional function to generate a default value
* if the input snapshot / model creation data is `null` or `undefined`.
*
* Example:
* ```ts
* x: prop(() => 10) // an optional number, with a default value of 10
* x: prop<number[]>(() => []) // an optional number array, with a default empty array
* ```
*
* @typeparam TValue Value type.
* @param defaultFn Default value generator function.
* @param options Model property options.
* @returns
*/
export declare function prop<TValue>(defaultFn: () => TValue, options?: ModelPropOptions): OptionalModelProp<TValue>;

@@ -113,2 +155,19 @@ /**

*/
export declare function prop<TValue>(defaultValue: OnlyPrimitives<TValue>, options: ModelPropOptionsWithSetterAction): OptionalModelPropWithSetterAction<TValue>;
/**
* Defines a model property, with an optional default value
* if the input snapshot / model creation data is `null` or `undefined`.
* You should only use this with primitive values and never with object values
* (array, model, object, etc).
*
* Example:
* ```ts
* x: prop(10) // an optional number, with a default value of 10
* ```
*
* @typeparam TValue Value type.
* @param defaultValue Default primitive value.
* @param options Model property options.
* @returns
*/
export declare function prop<TValue>(defaultValue: OnlyPrimitives<TValue>, options?: ModelPropOptions): OptionalModelProp<TValue>;

@@ -128,2 +187,16 @@ /**

*/
export declare function prop<TValue>(options: ModelPropOptionsWithSetterAction): MaybeOptionalModelPropWithSetterAction<TValue>;
/**
* Defines a model property with no default value.
*
* Example:
* ```ts
* x: prop<number>() // a required number
* x: prop<number | undefined>() // an optional number, which defaults to undefined
* ```
*
* @typeparam TValue Value type.
* @param options Model property options.
* @returns
*/
export declare function prop<TValue>(options?: ModelPropOptions): MaybeOptionalModelProp<TValue>;

@@ -8,3 +8,3 @@ import { ModelClass } from "../model/BaseModel";

} & {
$modelId: import("..").ModelProp<string, string, string, string, string, true>;
$modelId: import("..").ModelProp<string, string, string, string, string, true, never>;
}>;

@@ -11,0 +11,0 @@ /**

@@ -47,2 +47,6 @@ /**

/**
* Whether changes made in the sandbox are currently being committed to the original subtree.
*/
private isCommitting;
/**
* Creates an instance of `SandboxManager`.

@@ -49,0 +53,0 @@ * Do not use directly, use `sandbox` instead.

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

import { MaybeOptionalModelProp, ModelPropOptions, OnlyPrimitives, OptionalModelProp } from "../model/prop";
import { MaybeOptionalModelProp, MaybeOptionalModelPropWithSetterAction, ModelPropOptions, ModelPropOptionsWithSetterAction, OnlyPrimitives, OptionalModelProp, OptionalModelPropWithSetterAction } from "../model/prop";
import { AnyType, TypeToData } from "./schemas";

@@ -16,2 +16,16 @@ /**

*/
export declare function tProp(defaultValue: string, options: ModelPropOptionsWithSetterAction): OptionalModelPropWithSetterAction<string>;
/**
* Defines a string model property with a default value.
* Equivalent to `tProp(types.string, defaultValue)`.
*
* Example:
* ```ts
* x: tProp("foo") // an optional string that will take the value `"foo"` when undefined.
* ```
*
* @param defaultValue Default value.
* @param options Model property options.
* @returns
*/
export declare function tProp(defaultValue: string, options?: ModelPropOptions): OptionalModelProp<string>;

@@ -31,2 +45,16 @@ /**

*/
export declare function tProp(defaultValue: number, options: ModelPropOptionsWithSetterAction): OptionalModelPropWithSetterAction<number>;
/**
* Defines a number model property with a default value.
* Equivalent to `tProp(types.number, defaultValue)`.
*
* Example:
* ```ts
* x: tProp(42) // an optional number that will take the value `42` when undefined.
* ```
*
* @param defaultValue Default value.
* @param options Model property options.
* @returns
*/
export declare function tProp(defaultValue: number, options?: ModelPropOptions): OptionalModelProp<number>;

@@ -46,2 +74,16 @@ /**

*/
export declare function tProp(defaultValue: boolean, options: ModelPropOptionsWithSetterAction): OptionalModelPropWithSetterAction<boolean>;
/**
* Defines a boolean model property with a default value.
* Equivalent to `tProp(types.boolean, defaultValue)`.
*
* Example:
* ```ts
* x: tProp(true) // an optional boolean that will take the value `true` when undefined.
* ```
*
* @param defaultValue Default value.
* @param options Model property options.
* @returns
*/
export declare function tProp(defaultValue: boolean, options?: ModelPropOptions): OptionalModelProp<boolean>;

@@ -64,2 +106,20 @@ /**

*/
export declare function tProp<TType extends AnyType>(type: TType, defaultFn: () => TypeToData<TType>, options: ModelPropOptionsWithSetterAction): OptionalModelPropWithSetterAction<TypeToData<TType>>;
/**
* Defines a model property, with an optional function to generate a default value
* if the input snapshot / model creation data is `null` or `undefined` and with an associated type checker.
*
* Example:
* ```ts
* x: tProp(types.number, () => 10) // an optional number, with a default value of 10
* x: tProp(types.array(types.number), () => []) // an optional number array, with a default empty array
* ```
*
* @typeparam TType Type checker type.
*
* @param type Type checker.
* @param defaultFn Default value generator function.
* @param options Model property options.
* @returns
*/
export declare function tProp<TType extends AnyType>(type: TType, defaultFn: () => TypeToData<TType>, options?: ModelPropOptions): OptionalModelProp<TypeToData<TType>>;

@@ -83,2 +143,21 @@ /**

*/
export declare function tProp<TType extends AnyType>(type: TType, defaultValue: OnlyPrimitives<TypeToData<TType>>, options: ModelPropOptionsWithSetterAction): OptionalModelPropWithSetterAction<TypeToData<TType>>;
/**
* Defines a model property, with an optional default value
* if the input snapshot / model creation data is `null` or `undefined` and with an associated type checker.
* You should only use this with primitive values and never with object values
* (array, model, object, etc).
*
* Example:
* ```ts
* x: tProp(types.number, 10) // an optional number, with a default value of 10
* ```
*
* @typeparam TType Type checker type.
*
* @param type Type checker.
* @param defaultValue Default value generator function.
* @param options Model property options.
* @returns
*/
export declare function tProp<TType extends AnyType>(type: TType, defaultValue: OnlyPrimitives<TypeToData<TType>>, options?: ModelPropOptions): OptionalModelProp<TypeToData<TType>>;

@@ -99,2 +178,18 @@ /**

*/
export declare function tProp<TType extends AnyType>(type: TType, options: ModelPropOptionsWithSetterAction): MaybeOptionalModelPropWithSetterAction<TypeToData<TType>>;
/**
* Defines a model property with no default value and an associated type checker.
*
* Example:
* ```ts
* x: tProp(types.number) // a required number
* x: tProp(types.maybe(types.number)) // an optional number, which defaults to undefined
* ```
*
* @typeparam TType Type checker type.
*
* @param type Type checker.
* @param options Model property options.
* @returns
*/
export declare function tProp<TType extends AnyType>(type: TType, options?: ModelPropOptions): MaybeOptionalModelProp<TypeToData<TType>>;
declare const ArraySet_base: import("../model/Model")._Model<unknown, {
items: import("..").OptionalModelProp<any[], any[]>;
} & {
$modelId: import("..").ModelProp<string, string, string, string, string, true>;
$modelId: import("..").ModelProp<string, string, string, string, string, true, never>;
}>;

@@ -6,0 +6,0 @@ /**

@@ -8,3 +8,3 @@ declare const ObjectMap_base: import("../model/Model")._Model<unknown, {

} & {
$modelId: import("..").ModelProp<string, string, string, string, string, true>;
$modelId: import("..").ModelProp<string, string, string, string, string, true, never>;
}>;

@@ -11,0 +11,0 @@ /**

{
"name": "mobx-keystone",
"version": "0.52.0",
"version": "0.53.0",
"description": "A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more",

@@ -52,2 +52,4 @@ "keywords": [

"eslint": "^7.12.1",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-jest": "^24.1.0",
"eslint-webpack-plugin": "^2.1.0",

@@ -61,7 +63,7 @@ "mobx": "^6.0.1",

"typedoc": "^0.20.5",
"typescript": "^4.0.2"
"typescript": "^4.2.2"
},
"dependencies": {
"fast-deep-equal": "^3.1.1",
"ts-toolbelt": "^6.1.4",
"ts-toolbelt": "^9.3.12",
"tslib": "^2.0.0",

@@ -68,0 +70,0 @@ "uuid": "^8.1.0"

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

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