Merge pull request #1599 from strongloop/fix/typings
Fix type definitions for PersistedModel API
This commit is contained in:
commit
3ac18e4e06
|
@ -18,7 +18,7 @@ export type Options = AnyObject<any>;
|
||||||
/**
|
/**
|
||||||
* Type alias for Node.js callback functions
|
* Type alias for Node.js callback functions
|
||||||
*/
|
*/
|
||||||
export type Callback<T = any> = (err: any, result?: T) => void;
|
export type Callback<T = any> = (err?: any | null, result?: T) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return export type for promisified Node.js async methods.
|
* Return export type for promisified Node.js async methods.
|
||||||
|
|
|
@ -242,8 +242,14 @@ export declare class ModelBuilder extends EventEmitter {
|
||||||
): ModelBaseClass;
|
): ModelBaseClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extension of the built-in Partial<T> type which allows partial values
|
||||||
|
* in deeply nested properties too.
|
||||||
|
*/
|
||||||
|
export type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]>; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Union export type for model instance or plain object representing the model
|
* Union export type for model instance or plain object representing the model
|
||||||
* instance
|
* instance
|
||||||
*/
|
*/
|
||||||
export type ModelData<T extends ModelBase = ModelBase> = T | AnyObject;
|
export type ModelData<T extends ModelBase = ModelBase> = T | DeepPartial<T>;
|
||||||
|
|
|
@ -38,8 +38,14 @@ export declare class PersistedModel extends ModelBase {
|
||||||
static create(
|
static create(
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
|
static create(
|
||||||
|
data: PersistedData[],
|
||||||
|
options?: Options,
|
||||||
|
callback?: Callback<PersistedModel[]>,
|
||||||
|
): PromiseOrVoid<PersistedModel[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update or insert a model instance
|
* Update or insert a model instance
|
||||||
|
@ -51,20 +57,20 @@ export declare class PersistedModel extends ModelBase {
|
||||||
static upsert(
|
static upsert(
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
static updateOrCreate(
|
static updateOrCreate(
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
static patchOrCreate(
|
static patchOrCreate(
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update or insert a model instance based on the search criteria.
|
* Update or insert a model instance based on the search criteria.
|
||||||
|
@ -86,15 +92,15 @@ export declare class PersistedModel extends ModelBase {
|
||||||
where: Where,
|
where: Where,
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
static patchOrCreateWithWhere(
|
static patchOrCreateWithWhere(
|
||||||
where: Where,
|
where: Where,
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace or insert a model instance; replace existing record if one is found,
|
* Replace or insert a model instance; replace existing record if one is found,
|
||||||
|
@ -110,8 +116,8 @@ export declare class PersistedModel extends ModelBase {
|
||||||
static replaceOrCreate(
|
static replaceOrCreate(
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds one record matching the optional filter object. If not found, creates
|
* Finds one record matching the optional filter object. If not found, creates
|
||||||
|
@ -147,8 +153,8 @@ export declare class PersistedModel extends ModelBase {
|
||||||
filter: Filter,
|
filter: Filter,
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a model instance exists in database.
|
* Check whether a model instance exists in database.
|
||||||
|
@ -183,7 +189,7 @@ export declare class PersistedModel extends ModelBase {
|
||||||
filter?: Filter,
|
filter?: Filter,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<boolean>,
|
callback?: Callback<boolean>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all model instances that match `filter` specification.
|
* Find all model instances that match `filter` specification.
|
||||||
|
@ -215,8 +221,8 @@ export declare class PersistedModel extends ModelBase {
|
||||||
static find(
|
static find(
|
||||||
filter?: Filter,
|
filter?: Filter,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData[]>;
|
): PromiseOrVoid<PersistedModel[]>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find one model instance that matches `filter` specification.
|
* Find one model instance that matches `filter` specification.
|
||||||
|
@ -246,8 +252,8 @@ export declare class PersistedModel extends ModelBase {
|
||||||
static findOne(
|
static findOne(
|
||||||
filter?: Filter,
|
filter?: Filter,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy all model instances that match the optional `where` specification.
|
* Destroy all model instances that match the optional `where` specification.
|
||||||
|
@ -362,8 +368,8 @@ export declare class PersistedModel extends ModelBase {
|
||||||
id: any,
|
id: any,
|
||||||
data: PersistedData,
|
data: PersistedData,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of records that match the optional "where" filter.
|
* Return the number of records that match the optional "where" filter.
|
||||||
|
@ -479,8 +485,8 @@ export declare class PersistedModel extends ModelBase {
|
||||||
*/
|
*/
|
||||||
reload(
|
reload(
|
||||||
options?: Options,
|
options?: Options,
|
||||||
callback?: Callback<PersistedData>,
|
callback?: Callback<PersistedModel>,
|
||||||
): PromiseOrVoid<PersistedData>;
|
): PromiseOrVoid<PersistedModel>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the correct `id` property for the `PersistedModel`. Uses the `setId` method if the model is attached to
|
* Set the correct `id` property for the `PersistedModel`. Uses the `setId` method if the model is attached to
|
||||||
|
|
Loading…
Reference in New Issue