@converse/skeletor 3.1.6 → 4.0.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/CHANGES.md +50 -0
- package/dist/skeletor.d.ts +36 -14
- package/dist/skeletor.esm.js +291 -174
- package/dist/skeletor.esm.js.map +1 -1
- package/dist/skeletor.js +291 -173
- package/dist/skeletor.js.map +1 -1
- package/dist/skeletor.min.js +4 -4
- package/dist/skeletor.node.d.ts +36 -14
- package/dist/skeletor.node.js +291 -173
- package/dist/skeletor.node.mjs +291 -174
- package/package.json +1 -1
- package/src/collection.ts +68 -78
- package/src/helpers.ts +135 -25
- package/src/index.ts +4 -2
- package/src/model.ts +43 -48
package/dist/skeletor.node.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ export declare class Collection<T extends Model = Model> extends EventEmitterObj
|
|
|
136
136
|
min(): number;
|
|
137
137
|
drop(n?: number): T[];
|
|
138
138
|
some(pred: ((attrs: ModelAttributes) => boolean) | Options): boolean;
|
|
139
|
-
sortBy(iteratee: string | ((model: T) => any)): T[];
|
|
139
|
+
sortBy(iteratee: string | ((model: T) => any) | Partial<ModelAttributes>): T[];
|
|
140
140
|
isEmpty(): boolean;
|
|
141
141
|
keyBy(iteratee: string | ((model: T) => string)): Record<string, T>;
|
|
142
142
|
each(callback: (model: T, index: number, array: T[]) => void, thisArg?: any): void;
|
|
@@ -144,7 +144,7 @@ export declare class Collection<T extends Model = Model> extends EventEmitterObj
|
|
|
144
144
|
includes(item: T): boolean;
|
|
145
145
|
size(): number;
|
|
146
146
|
countBy(f: string | ((model: T) => string) | Partial<ModelAttributes>): Record<string, number>;
|
|
147
|
-
groupBy(pred: string | ((model: T) => string | number)): Record<string, T[]>;
|
|
147
|
+
groupBy(pred: string | ((model: T) => string | number) | Partial<ModelAttributes>): Record<string, T[]>;
|
|
148
148
|
indexOf(model: T, fromIndex?: number): number;
|
|
149
149
|
findLastIndex(pred: ((model: T) => boolean) | string | Partial<ModelAttributes>, fromIndex?: number): number;
|
|
150
150
|
lastIndexOf(model: T, fromIndex?: number): number;
|
|
@@ -487,6 +487,17 @@ export declare type FetchOrCreateOptions = Options & {
|
|
|
487
487
|
*/
|
|
488
488
|
export declare function getStorage(obj: Model<any> | Collection<any> | null | undefined): PersistentStorage | undefined;
|
|
489
489
|
|
|
490
|
+
/**
|
|
491
|
+
* The error the default `sync` hands to `options.error`, and rejects with, for
|
|
492
|
+
* a response outside the 2xx range.
|
|
493
|
+
* @public
|
|
494
|
+
*/
|
|
495
|
+
export declare class HTTPError extends Error {
|
|
496
|
+
readonly status: number;
|
|
497
|
+
readonly response: Response;
|
|
498
|
+
constructor(response: Response, method: string, url: string);
|
|
499
|
+
}
|
|
500
|
+
|
|
490
501
|
/**
|
|
491
502
|
* @public
|
|
492
503
|
*/
|
|
@@ -634,9 +645,17 @@ export declare class Model<T extends ModelAttributes = ModelAttributes> extends
|
|
|
634
645
|
*/
|
|
635
646
|
has(attr: keyof T): boolean;
|
|
636
647
|
/**
|
|
637
|
-
*
|
|
648
|
+
* Returns `true` if the model's attributes satisfy `attrs`.
|
|
649
|
+
*
|
|
650
|
+
* An attributes object is compared with lodash's `isMatch`: a partial, deep
|
|
651
|
+
* comparison, so `{ form: { type: 'hidden' } }` matches a `form` attribute
|
|
652
|
+
* that has `type: 'hidden'` alongside other keys. A function is called with
|
|
653
|
+
* the attributes and its result coerced to a boolean.
|
|
654
|
+
*
|
|
655
|
+
* To scan a collection, prefer `Collection#find`, `filter` or `where`. They
|
|
656
|
+
* build their matcher once per scan instead of once per model.
|
|
638
657
|
*/
|
|
639
|
-
matches(attrs: Partial<T>): boolean;
|
|
658
|
+
matches(attrs: Partial<T> | ((attrs: T) => any)): boolean;
|
|
640
659
|
/**
|
|
641
660
|
* Set a hash of model attributes on the object, firing `"change"`. This is
|
|
642
661
|
* the core primitive operation of a model, updating the data and notifying
|
|
@@ -881,6 +900,7 @@ export declare interface SkeletorType {
|
|
|
881
900
|
EventEmitter: typeof EventEmitter;
|
|
882
901
|
Model: typeof Model;
|
|
883
902
|
sync: typeof sync;
|
|
903
|
+
HTTPError: typeof HTTPError;
|
|
884
904
|
VERSION?: string;
|
|
885
905
|
noConflict?: () => SkeletorType;
|
|
886
906
|
}
|
|
@@ -918,18 +938,20 @@ export declare interface StorageDriver {
|
|
|
918
938
|
export declare type StoreType = 'local' | 'session' | 'indexed' | 'in_memory' | 'node';
|
|
919
939
|
|
|
920
940
|
/**
|
|
921
|
-
*
|
|
922
|
-
*
|
|
923
|
-
*
|
|
924
|
-
* to
|
|
941
|
+
* The default `sync`: a JSON request over `fetch()` to the model's `url()`.
|
|
942
|
+
* Override it (or `Model.sync`/`Collection.sync`) to change how models are
|
|
943
|
+
* persisted, for instance to batch rapid-fire updates with `setTimeout`, to
|
|
944
|
+
* talk over WebSockets, or to write to browser storage.
|
|
925
945
|
*
|
|
926
|
-
*
|
|
946
|
+
* It honours both contracts a `sync` may use. On a 2xx response the JSON body
|
|
947
|
+
* (`null` when the body is empty) is passed to `options.success` and the
|
|
948
|
+
* returned promise resolves with it. On a non-2xx response, a network failure
|
|
949
|
+
* or an unparsable body, `options.error` receives the error (an `HTTPError`
|
|
950
|
+
* for the first) and the promise rejects with it.
|
|
927
951
|
*
|
|
928
|
-
*
|
|
929
|
-
*
|
|
930
|
-
*
|
|
931
|
-
*/
|
|
932
|
-
/**
|
|
952
|
+
* `options.data` is sent as query parameters on GET, which may not carry a
|
|
953
|
+
* body, and as a JSON body otherwise. For create, update and patch the body
|
|
954
|
+
* defaults to `options.attrs` or the model's `toJSON()`.
|
|
933
955
|
* @public
|
|
934
956
|
*/
|
|
935
957
|
export declare function sync(method: SyncOperation, model: Model | Collection<any>, options?: SyncOptions): Promise<any>;
|