@converse/skeletor 4.0.0 → 4.0.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.
@@ -1,953 +1,922 @@
1
- import localForage from 'localforage';
2
-
3
- /**
4
- * @deprecated Use `PersistentStorage` instead.
5
- * @public
6
- */
7
- export declare const BrowserStorage: typeof PersistentStorage;
8
-
9
- /**
10
- * @public
11
- */
12
- export declare type ClassConstructor<T = any> = new (...args: any[]) => T;
13
-
14
- /**
15
- * @public
16
- * If models tend to represent a single row of data, a Collection is
17
- * more analogous to a table full of data ... or a small slice or page of that
18
- * table, or a collection of rows that belong together for a particular reason
19
- * -- all of the messages in this particular folder, all of the documents
20
- * belonging to this particular author, and so on. Collections maintain
21
- * indexes of their models, both in order, and for lookup by `id`.
22
- */
23
- export declare class Collection<T extends Model = Model> extends EventEmitterObject {
24
- #private;
25
- [key: symbol]: () => CollectionIterator<T>;
26
- _storage?: PersistentStorage;
27
- _comparator?: Comparator<T>;
28
- _url: string;
29
- hydrated?: Promise<void>;
30
- models: T[];
31
- protected _byId: Record<string, T>;
32
- protected _model?: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T;
33
- /**
34
- * Create a new **Collection**, perhaps to contain a specific type of `model`.
35
- * If a `comparator` is specified, the Collection will maintain
36
- * its models in sort order, as they're added and removed.
37
- */
38
- constructor(models?: T[] | ModelAttributes[] | T | ModelAttributes, options?: CollectionOptions<T>);
39
- get comparator(): Comparator<T>;
40
- set comparator(c: Comparator<T>);
41
- /**
42
- * The canonical storage accessor. Set to a `PersistentStorage` instance
43
- * to enable local persistence for this collection.
44
- */
45
- get storage(): PersistentStorage | undefined;
46
- set storage(s: PersistentStorage);
47
- /**
48
- * @deprecated Use `storage` instead.
49
- */
50
- get browserStorage(): PersistentStorage | undefined;
51
- set browserStorage(s: PersistentStorage);
52
- /**
53
- * Override to return `true` to automatically load the collection from
54
- * storage on construction. Await `hydrated` to know when hydration
55
- * is complete.
56
- *
57
- * Note: collection `autoSync` is hydrate-only. Unlike `Model`, it does
58
- * **not** schedule auto-saves when the collection changes (`add`/`remove`/
59
- * `reset`). Persisting members is each model's responsibility — enable
60
- * `autoSync` on the contained model class and every model writes its own
61
- * record. A collection-level write would be redundant with that.
62
- */
63
- get autoSync(): boolean;
64
- /**
65
- * The default model for a collection is just a **Model**.
66
- * This should be overridden in most cases.
67
- */
68
- get model(): new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T | Model;
69
- set model(model: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T);
70
- get length(): number;
71
- get url(): string;
72
- set url(url: string);
73
- /**
74
- * preinitialize is an empty function by default. You can override it with a function
75
- * or object. preinitialize will run before any instantiation logic is run in the Collection.
76
- */
77
- preinitialize(..._args: any[]): void;
78
- /**
79
- * Initialize is an empty function by default. Override it with your own
80
- * initialization logic.
81
- */
82
- initialize(..._args: any[]): void;
83
- /**
84
- * The JSON representation of a Collection is an array of the
85
- * models' attributes.
86
- */
87
- toJSON(): any[];
88
- sync(method: SyncOperation, model: Model | Collection<any>, options?: Options): any;
89
- /**
90
- * Add a model, or list of models to the set. `models` may be
91
- * Models or raw JavaScript objects to be converted to Models, or any
92
- * combination of the two.
93
- */
94
- add(models: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
95
- /**
96
- * Remove a model, or a list of models from the set.
97
- */
98
- remove(models: T | ObjectWithId | (T | ObjectWithId)[], options?: Options): T | T[];
99
- /**
100
- * Update a collection by `set`-ing a new list of models, adding new ones,
101
- * removing models that are no longer present, and merging models that
102
- * already exist in the collection, as necessary. Similar to **Model#set**,
103
- * the core operation for updating the data contained by the collection.
104
- */
105
- set(models: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
106
- clearStore(options?: Options, filter?: (model: T) => boolean): Promise<void>;
107
- /**
108
- * When you have more items than you want to add or remove individually,
109
- * you can reset the entire set with a new list of models, without firing
110
- * any granular `add` or `remove` events. Fires `reset` when finished.
111
- * Useful for bulk operations and optimizations.
112
- */
113
- reset(models?: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
114
- /**
115
- * Add a model to the end of the collection.
116
- */
117
- push(model: T | ModelAttributes, options?: Options): T;
118
- /**
119
- * Remove a model from the end of the collection.
120
- */
121
- pop(options?: Options): T | undefined;
122
- /**
123
- * Add a model to the beginning of the collection.
124
- */
125
- unshift(model: T | ModelAttributes, options?: Options): T;
126
- /**
127
- * Remove a model from the beginning of the collection.
128
- */
129
- shift(options?: Options): T | undefined;
130
- /** Slice out a sub-array of models from the collection. */
131
- slice(start?: number, end?: number): T[];
132
- filter(callback: ((model: T) => boolean) | string | Partial<ModelAttributes>, thisArg?: any): T[];
133
- every(pred: ((attrs: ModelAttributes) => boolean) | Options): boolean;
134
- difference(values: T[]): T[];
135
- max(): number;
136
- min(): number;
137
- drop(n?: number): T[];
138
- some(pred: ((attrs: ModelAttributes) => boolean) | Options): boolean;
139
- sortBy(iteratee: string | ((model: T) => any) | Partial<ModelAttributes>): T[];
140
- isEmpty(): boolean;
141
- keyBy(iteratee: string | ((model: T) => string)): Record<string, T>;
142
- each(callback: (model: T, index: number, array: T[]) => void, thisArg?: any): void;
143
- forEach(callback: (model: T, index: number, array: T[]) => void, thisArg?: any): void;
144
- includes(item: T): boolean;
145
- size(): number;
146
- countBy(f: string | ((model: T) => string) | Partial<ModelAttributes>): Record<string, number>;
147
- groupBy(pred: string | ((model: T) => string | number) | Partial<ModelAttributes>): Record<string, T[]>;
148
- indexOf(model: T, fromIndex?: number): number;
149
- findLastIndex(pred: ((model: T) => boolean) | string | Partial<ModelAttributes>, fromIndex?: number): number;
150
- lastIndexOf(model: T, fromIndex?: number): number;
151
- findIndex(pred: ((model: T) => boolean) | string | Partial<ModelAttributes>): number;
152
- last(): T | undefined;
153
- head(): T | undefined;
154
- first(): T | undefined;
155
- map<U>(cb: string | ((model: T) => U) | Partial<ModelAttributes>, thisArg?: any): U[];
156
- reduce<U = T>(callback: (accumulator: U, model: T, index: number, array: T[]) => U, initialValue?: U): U | T;
157
- reduceRight<U = T>(callback: (accumulator: U, model: T, index: number, array: T[]) => U, initialValue?: U): U | T;
158
- toArray(): T[];
159
- /**
160
- * Get a model from the set by id, cid, model object with id or cid
161
- * properties, or an attributes object that is transformed through modelId.
162
- */
163
- get(obj?: string | number | ModelAttributes | T | null): T | undefined;
164
- /**
165
- * Returns `true` if the model is in the collection.
166
- */
167
- has(obj: string | number | ModelAttributes | T | null): boolean;
168
- /**
169
- * Get the model at the given index.
170
- */
171
- at(index: number): T | undefined;
172
- /**
173
- * Return models with matching attributes. Useful for simple cases of
174
- * `filter`.
175
- */
176
- where(attrs: ModelAttributes | Partial<ModelAttributes>, first?: boolean): T[] | T | undefined;
177
- /**
178
- * Return the first model with matching attributes. Useful for simple cases
179
- * of `find`.
180
- */
181
- findWhere(attrs: ModelAttributes): T | undefined;
182
- find(predicate: ((model: T) => boolean) | Partial<ModelAttributes> | string, fromIndex?: number): T | undefined;
183
- /**
184
- * Force the collection to re-sort itself. You don't need to call this under
185
- * normal circumstances, as the set will maintain sort order as each item
186
- * is added.
187
- */
188
- sort(options?: Options): this;
189
- /**
190
- * Pluck an attribute from each model in the collection.
191
- */
192
- pluck(attr: string): any[];
193
- /**
194
- * Fetch the default set of models for this collection, resetting the
195
- * collection when they arrive. If `reset: true` is passed, the response
196
- * data will be passed through the `reset` method instead of `set`.
197
- */
198
- fetch(options?: Options): Promise<any> | any;
199
- /**
200
- * Create a new instance of a model in this collection. Add the model to the
201
- * collection immediately, unless `wait: true` is passed, in which case we
202
- * wait for the server to agree.
203
- */
204
- create(model: T | ModelAttributes, options?: FetchOrCreateOptions): Promise<T> | T;
205
- /**
206
- * Subscribe to collection changes (add, remove, reset, sort, update).
207
- * Returns an unsubscribe function.
208
- *
209
- * `collection.subscribe(callback)` — fires once per operation on add/remove/reset/sort (via `update`, `reset`, `sort` events).
210
- * `collection.subscribe(event, callback)` — subscribe to a specific event (base EventEmitter form).
211
- *
212
- * Compatible with React's `useSyncExternalStore` and other store-style APIs.
213
- */
214
- subscribe(event: string, callback: EventCallback, context?: unknown): () => void;
215
- subscribe(callback: (collection: this) => void): () => void;
216
- /**
217
- * **parse** converts a response into a list of models to be added to the
218
- * collection. The default implementation is just to pass it through.
219
- */
220
- parse(resp: any, _options?: Options): any;
221
- /**
222
- * Define how to uniquely identify models in the collection.
223
- */
224
- modelId(attrs: ModelAttributes): string | number | undefined;
225
- /** Get an iterator of all models in this collection. */
226
- values(): CollectionIterator<T>;
227
- /**
228
- * @public
229
- * Enable for...of iteration over the collection.
230
- */
231
- [Symbol.iterator]: () => CollectionIterator<T>;
232
- /** Get an iterator of all model IDs in this collection. */
233
- keys(): CollectionIterator<T>;
234
- /** Get an iterator of all [ID, model] tuples in this collection. */
235
- entries(): CollectionIterator<T>;
236
- /**
237
- * Private method to reset all internal state. Called when the collection
238
- * is first initialized or reset.
239
- */
240
- _reset(): void;
241
- createModel(attrs: ModelAttributes, options?: Options): T;
242
- /**
243
- * Prepare a hash of attributes (or other model) to be added to this
244
- * collection.
245
- */
246
- _prepareModel(attrs: ModelAttributes | T, options?: Options): T | null;
247
- /**
248
- * Internal method called by both remove and set.
249
- */
250
- _removeModels(models: (T | ObjectWithId)[], options?: Options): T[];
251
- /**
252
- * Method for checking whether an object should be considered a model for
253
- * the purposes of adding to the collection.
254
- */
255
- _isModel(model: any): model is T;
256
- /**
257
- * Internal method to create a model's ties to a collection.
258
- */
259
- _addReference(model: T, _options?: Options): void;
260
- /**
261
- * Internal method to sever a model's ties to a collection.
262
- */
263
- _removeReference(model: T, _options?: Options): void;
264
- /**
265
- * Internal method called every time a model in the set fires an event.
266
- * Sets need to update their indexes when models change ids. All other
267
- * events simply proxy through. "add" and "remove" events that originate
268
- * in other collections are ignored.
269
- */
270
- _onModelEvent(event: string, model: T, collection: Collection<T>, options?: Options): void;
271
- }
272
-
273
- /**
274
- * @public
275
- */
276
- export declare class CollectionIterator<T extends Model> {
277
- private _collection;
278
- private _kind;
279
- private _index;
280
- /**
281
- * A CollectionIterator implements JavaScript's Iterator protocol, allowing the
282
- * use of `for of` loops in modern browsers and interoperation between
283
- * Collection and other JavaScript functions and third-party libraries
284
- * which can operate on Iterables.
285
- */
286
- constructor(collection: Collection<T>, kind: number);
287
- next(): IteratorResult<any>;
288
- [Symbol.iterator](): IterableIterator<any>;
289
- }
290
-
291
- /**
292
- * @public
293
- */
294
- export declare type CollectionOptions<T extends Model = Model> = Options & {
295
- model?: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T;
296
- comparator?: Comparator<T>;
297
- previousModels?: Model[];
298
- };
299
-
300
- /**
301
- * @public
302
- */
303
- export declare type Comparator<T extends Model = Model> = string | boolean | ((a: T, b: T) => number) | ((a?: T) => string);
304
-
305
- /**
306
- * @public
307
- */
308
- export declare type ComputedProperties<M> = Record<string, ComputedProperty<M>>;
309
-
310
- /**
311
- * @public
312
- */
313
- export declare type ComputedProperty<M> = {
314
- deps: string[];
315
- fn: (model: M) => any;
316
- };
317
-
318
- /**
319
- * @public
320
- */
321
- export declare type EventCallback = (...args: any[]) => void;
322
-
323
- /**
324
- * @public
325
- */
326
- export declare type EventCallbackMap = Record<string, EventCallback>;
327
-
328
- /**
329
- * @public
330
- */
331
- export declare type EventContext = unknown;
332
-
333
- /**
334
- * @public
335
- */
336
- export declare function EventEmitter<T extends ClassConstructor>(Base: T): {
337
- new (...args: any[]): {
338
- [x: string]: any;
339
- _events?: EventHandlersMap;
340
- _listeners?: EventListenerMap;
341
- _listeningTo?: EventListenerMap;
342
- _listenId?: string;
343
- /**
344
- * Bind an event to a `callback` function. Passing `"all"` will bind
345
- * the callback to all events fired.
346
- */
347
- on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
348
- /**
349
- * Inversion-of-control versions of `on`. Tell *this* object to listen to
350
- * an event in another object... keeping track of what it's listening to
351
- * for easier unbinding later.
352
- */
353
- listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
354
- /**
355
- * Remove one or many callbacks. If `context` is null, removes all
356
- * callbacks with that function. If `callback` is null, removes all
357
- * callbacks for the event. If `name` is null, removes all bound
358
- * callbacks for all events.
359
- */
360
- off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): /*elided*/ any;
361
- /**
362
- * Tell this object to stop listening to either specific events ... or
363
- * to every object it's currently listening to.
364
- */
365
- stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
366
- /**
367
- * Bind an event to only be triggered a single time. After the first time
368
- * the callback is invoked, its listener will be removed. If multiple events
369
- * are passed in using the space-separated syntax, the handler will fire
370
- * once for each event, not once for a combination of all events.
371
- */
372
- once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
373
- /**
374
- * Inversion-of-control versions of `once`.
375
- */
376
- listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
377
- /**
378
- * Trigger one or many events, firing all bound callbacks. Callbacks are
379
- * passed the same arguments as `trigger` is, apart from the event name
380
- * (unless you're listening on `"all"`, which will cause your callback to
381
- * receive the true name of the event as the first argument).
382
- */
383
- trigger(name: string, ...args: any[]): /*elided*/ any;
384
- /**
385
- * Subscribe to an event. Returns an unsubscribe function.
386
- * Compatible with `useSyncExternalStore` and other store-style APIs.
387
- */
388
- subscribe(event: string, callback: EventCallback, context?: EventContext): () => void;
389
- };
390
- } & T;
391
-
392
- /**
393
- * @public
394
- */
395
- export declare const EventEmitterObject: {
396
- new (...args: any[]): {
397
- [x: string]: any;
398
- _events?: EventHandlersMap;
399
- _listeners?: EventListenerMap;
400
- _listeningTo?: EventListenerMap;
401
- _listenId?: string;
402
- /**
403
- * Bind an event to a `callback` function. Passing `"all"` will bind
404
- * the callback to all events fired.
405
- */
406
- on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
407
- /**
408
- * Inversion-of-control versions of `on`. Tell *this* object to listen to
409
- * an event in another object... keeping track of what it's listening to
410
- * for easier unbinding later.
411
- */
412
- listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
413
- /**
414
- * Remove one or many callbacks. If `context` is null, removes all
415
- * callbacks with that function. If `callback` is null, removes all
416
- * callbacks for the event. If `name` is null, removes all bound
417
- * callbacks for all events.
418
- */
419
- off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): /*elided*/ any;
420
- /**
421
- * Tell this object to stop listening to either specific events ... or
422
- * to every object it's currently listening to.
423
- */
424
- stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
425
- /**
426
- * Bind an event to only be triggered a single time. After the first time
427
- * the callback is invoked, its listener will be removed. If multiple events
428
- * are passed in using the space-separated syntax, the handler will fire
429
- * once for each event, not once for a combination of all events.
430
- */
431
- once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
432
- /**
433
- * Inversion-of-control versions of `once`.
434
- */
435
- listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
436
- /**
437
- * Trigger one or many events, firing all bound callbacks. Callbacks are
438
- * passed the same arguments as `trigger` is, apart from the event name
439
- * (unless you're listening on `"all"`, which will cause your callback to
440
- * receive the true name of the event as the first argument).
441
- */
442
- trigger(name: string, ...args: any[]): /*elided*/ any;
443
- /**
444
- * Subscribe to an event. Returns an unsubscribe function.
445
- * Compatible with `useSyncExternalStore` and other store-style APIs.
446
- */
447
- subscribe(event: string, callback: EventCallback, context?: EventContext): () => void;
448
- };
449
- } & ObjectConstructor;
450
-
451
- /**
452
- * @public
453
- */
454
- export declare interface EventHandler {
455
- callback: EventCallback;
456
- context: any;
457
- ctx: any;
458
- listening?: ListeningType | null;
459
- }
460
-
461
- /**
462
- * @public
463
- */
464
- export declare interface EventHandlersMap {
465
- all?: EventHandler[];
466
- [name: string]: EventHandler[];
467
- }
468
-
469
- /**
470
- * @public
471
- */
472
- export declare type EventListenerMap = Record<string, ListeningType>;
473
-
474
- /**
475
- * @public
476
- */
477
- export declare type FetchOrCreateOptions = Options & {
478
- promise?: boolean;
479
- success?: (m: Model, resp: any, callbackOpts: Options) => void;
480
- };
481
-
482
- /**
483
- * Return the PersistentStorage instance configured on `obj`, checking both
484
- * the canonical `storage` accessor and the deprecated `browserStorage` alias
485
- * so that subclasses that still override `get browserStorage()` continue to work.
486
- * @public
487
- */
488
- export declare function getStorage(obj: Model<any> | Collection<any> | null | undefined): PersistentStorage | undefined;
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
-
501
- /**
502
- * @public
503
- */
504
- export declare interface IEventEmitter {
505
- _events?: Record<string, any>;
506
- _listeners?: ListeningMap;
507
- _listeningTo?: ListeningMap;
508
- _listenId?: string;
509
- on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
510
- off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): this;
511
- trigger(name: string, ...args: any[]): this;
512
- stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): this;
513
- once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
514
- listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): this;
515
- listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): this;
516
- }
517
-
518
- /**
519
- * @public
520
- */
521
- export declare type ListeningMap = Record<string, ListeningType>;
522
-
523
- /**
524
- * @public
525
- */
526
- export declare interface ListeningType {
527
- _events?: EventCallbackMap;
528
- cleanup(): void;
529
- count: number;
530
- id: string;
531
- interop: boolean;
532
- listener: IEventEmitter;
533
- obj: any;
534
- start(name: string | EventCallbackMap, callback: EventCallback, context: any, _listening: ListeningType): this;
535
- stop(name: string | EventCallbackMap, callback: EventCallback): void;
536
- }
537
-
538
- /**
539
- * @public
540
- * **Models** are the basic data object in the framework --
541
- * frequently representing a row in a table in a database on your server.
542
- * A discrete chunk of data and a bunch of useful, related methods for
543
- * performing computations and transformations on that data.
544
- */
545
- export declare class Model<T extends ModelAttributes = ModelAttributes> extends EventEmitterObject {
546
- #private;
547
- _storage?: PersistentStorage;
548
- _changing: boolean;
549
- _pending: boolean | ModelOptions;
550
- _previousAttributes?: T;
551
- _url: string;
552
- _urlRoot: string;
553
- attrs: T;
554
- attributes: T;
555
- changed: Partial<T>;
556
- cid: string;
557
- collection?: Collection;
558
- id: string | number;
559
- hydrated?: Promise<void>;
560
- validationError: string | number | null;
561
- /**
562
- * Create a new model with the specified attributes. A client id (`cid`)
563
- * is automatically generated and assigned for you.
564
- */
565
- constructor(attributes?: Partial<T>, options?: ModelOptions);
566
- /**
567
- * The canonical storage accessor. Set to a `PersistentStorage` instance
568
- * to enable local persistence for this model.
569
- */
570
- get storage(): PersistentStorage | undefined;
571
- set storage(s: PersistentStorage);
572
- /**
573
- * @deprecated Use `storage` instead.
574
- */
575
- get browserStorage(): PersistentStorage | undefined;
576
- set browserStorage(s: PersistentStorage);
577
- /**
578
- * Override to enable automatic persistence. When true, any `set()` call
579
- * that changes attributes will schedule a debounced save to `storage`, and
580
- * the model will auto-hydrate from storage on construction.
581
- */
582
- get autoSync(): boolean;
583
- /**
584
- * Debounce delay (ms) for auto-save writes. Override to tune.
585
- */
586
- get autoSyncDelay(): number;
587
- /**
588
- * The default name for the JSON `id` attribute is `"id"`. MongoDB and
589
- * CouchDB users may want to set this to `"_id"` (by overriding this getter
590
- * in a subclass).
591
- */
592
- get idAttribute(): string;
593
- /**
594
- * The prefix is used to create the client id which is used to identify models locally.
595
- * You may want to override this if you're experiencing name clashes with model ids.
596
- */
597
- get cidPrefix(): string;
598
- /**
599
- * preinitialize is an empty function by default. You can override it with a function
600
- * or object. preinitialize will run before any instantiation logic is run in the Model.
601
- */
602
- preinitialize(...args: any[]): void;
603
- /**
604
- * Initialize is an empty function by default. Override it with your own
605
- * initialization logic.
606
- */
607
- initialize(attrs?: Partial<T>, options?: ModelOptions): void;
608
- validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): string | number | null | void;
609
- /**
610
- * Return a hash of defaults for the model's attributes.
611
- */
612
- defaults(): Partial<T>;
613
- /**
614
- * Declare computed properties. Override in subclasses to define properties
615
- * that derive their value from other attributes. Each entry specifies the
616
- * attribute keys it depends on (`deps`) and a function (`fn`) that receives
617
- * the model and returns the computed value. The value is cached and
618
- * recalculated automatically when any dep changes, firing a `change:key`
619
- * event.
620
- */
621
- get computed(): ComputedProperties<this>;
622
- /**
623
- * Return a copy of the model's `attributes` object.
624
- */
625
- toJSON(): T;
626
- /**
627
- * Override this if you need custom syncing semantics for *this* particular model.
628
- */
629
- sync(method: SyncOperation, model: Model<any>, options: Options): any;
630
- /**
631
- * Get the value of an attribute, or a computed property.
632
- */
633
- get<K extends keyof T>(attr: K): T[K];
634
- keys(): string[];
635
- values(): T[keyof T][];
636
- pairs(): [keyof T, T[keyof T]][];
637
- entries(): [keyof T, T[keyof T]][];
638
- invert(): Record<string, keyof T>;
639
- pick<K extends keyof T>(...args: K[]): Pick<T, K>;
640
- omit<K extends keyof T>(...args: K[]): Omit<T, K>;
641
- isEmpty(): boolean;
642
- /**
643
- * Returns `true` if the attribute contains a value that is not null
644
- * or undefined.
645
- */
646
- has(attr: keyof T): boolean;
647
- /**
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.
657
- */
658
- matches(attrs: Partial<T> | ((attrs: T) => any)): boolean;
659
- /**
660
- * Set a hash of model attributes on the object, firing `"change"`. This is
661
- * the core primitive operation of a model, updating the data and notifying
662
- * anyone who needs to know about the change in state. The heart of the beast.
663
- */
664
- set(key: string | Partial<T> | ObjectWithId, val?: any, options?: ModelOptions): this;
665
- /**
666
- * Remove an attribute from the model, firing `"change"`. `unset` is a noop
667
- * if the attribute doesn't exist.
668
- */
669
- unset(attr: keyof T, options?: ModelOptions): this;
670
- /**
671
- * Clear all attributes on the model, firing `"change"`.
672
- */
673
- clear(options?: ModelOptions): this;
674
- /**
675
- * Determine if the model has changed since the last `"change"` event.
676
- * If you specify an attribute name, determine if that attribute has changed.
677
- */
678
- hasChanged(attr?: keyof T): boolean;
679
- /**
680
- * Return an object containing all the attributes that have changed, or
681
- * false if there are no changed attributes. Useful for determining what
682
- * parts of a view need to be updated and/or what attributes need to be
683
- * persisted to the server. Unset attributes will be set to undefined.
684
- * You can also pass an attributes object to diff against the model,
685
- * determining if there *would be* a change.
686
- */
687
- changedAttributes(diff?: Partial<T>): Partial<T> | false;
688
- /**
689
- * Get the previous value of an attribute, recorded at the time the last
690
- * `"change"` event was fired.
691
- */
692
- previous<K extends keyof T>(attr: K): T[K] | null;
693
- /**
694
- * Get all of the attributes of the model at the time of the previous
695
- * `"change"` event.
696
- */
697
- previousAttributes(): T | undefined;
698
- /**
699
- * Fetch the model from the server, merging the response with the model's
700
- * local attributes. Any changed attributes will trigger a "change" event.
701
- */
702
- fetch(options?: Options): any;
703
- /**
704
- * Set a hash of model attributes, and sync the model to the server.
705
- * If the server returns an attributes hash that differs, the model's
706
- * state will be `set` again.
707
- */
708
- save(key?: string | null | Partial<T>, val?: any, options?: ModelOptions): any;
709
- /**
710
- * Destroy this model on the server if it was already persisted.
711
- * Optimistically removes the model from its collection, if it has one.
712
- * If `wait: true` is passed, waits for the server to respond before removal.
713
- */
714
- destroy(options?: ModelOptions): any;
715
- get urlRoot(): string;
716
- set urlRoot(root: string);
717
- /**
718
- * Default URL for the model's representation on the server -- if you're
719
- * using Backbone's restful methods, override this to change the endpoint
720
- * that will be called.
721
- */
722
- get url(): string;
723
- set url(url: string);
724
- /**
725
- * **parse** converts a response into the hash of attributes to be `set` on
726
- * the model. The default implementation is just to pass the response along.
727
- */
728
- parse(resp: any, options?: ModelOptions): Partial<T> | null | void;
729
- /**
730
- * A model is new if it has never been saved to the server, and lacks an id.
731
- */
732
- isNew(): boolean;
733
- /**
734
- * Check if the model is currently in a valid state.
735
- */
736
- isValid(options?: ModelOptions): boolean;
737
- /**
738
- * Subscribe to model changes. Returns an unsubscribe function.
739
- *
740
- * `model.subscribe(callback)` — fires on any attribute change, receives `(model, changed)`.
741
- * `model.subscribe(event, callback)` — subscribe to a specific event (base EventEmitter form).
742
- *
743
- * Compatible with React's `useSyncExternalStore` and other store-style APIs.
744
- */
745
- subscribe(event: string, callback: EventCallback, context?: unknown): () => void;
746
- subscribe(callback: (model: this, changed: Partial<T>) => void): () => void;
747
- /**
748
- * Run validation against the next complete set of model attributes,
749
- * returning `true` if all is well. Otherwise, fire an `"invalid"` event.
750
- */
751
- _validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): boolean;
752
- }
753
-
754
- /**
755
- * @public
756
- */
757
- export declare type ModelAttributes = Record<string | number, any> & {
758
- id?: string | number;
759
- };
760
-
761
- /**
762
- * @public
763
- */
764
- export declare type ModelOptions = Options & {
765
- collection?: Collection;
766
- parse?: boolean;
767
- unset?: boolean;
768
- silent?: boolean;
769
- validate?: boolean;
770
- /** Suppress the auto-save triggered by set() on autoSync models. */
771
- noAutoSave?: boolean;
772
- /** Mark a set() call as originating from a storage read; suppresses auto-save. */
773
- fromStorage?: boolean;
774
- };
775
-
776
- /**
777
- * @public
778
- */
779
- export declare function noConflict(): any;
780
-
781
- /**
782
- * Constructor for a Node.js-only storage driver. Registered by the
783
- * `@converse/skeletor/node` entry point via {@link PersistentStorage.nodeStorage}.
784
- * @public
785
- */
786
- export declare type NodeStorageConstructor = new (name: string, storageDir?: string, inMemory?: boolean) => StorageDriver;
787
-
788
- /**
789
- * @public
790
- */
791
- export declare type ObjectListenedTo = object & {
792
- _listenId?: string;
793
- };
794
-
795
- /**
796
- * @public
797
- */
798
- export declare type ObjectWithId = Record<string, any> & {
799
- id: string | number;
800
- };
801
-
802
- /**
803
- * @public
804
- */
805
- export declare type Options = Record<string, any>;
806
-
807
- /**
808
- * @public
809
- */
810
- export declare class PersistentStorage {
811
- storeInitialized: Promise<void>;
812
- storeReady: boolean;
813
- store: StorageDriver;
814
- name: string;
815
- static sessionStorageInitialized: Promise<void>;
816
- static localForage: typeof localForage;
817
- static nodeStorage: NodeStorageConstructor | null;
818
- /**
819
- * Directory the `'node'` store type writes its database files to. The driver's
820
- * own default is relative, so it resolves against `process.cwd()` and a process
821
- * started from two directories ends up with two separate sets of state. Set an
822
- * absolute path (`$XDG_STATE_HOME/<app>`, say) to pin it. Left `null`, the
823
- * driver's default applies.
824
- *
825
- * Only the `'node'` string store type reads this; passing a driver instance to
826
- * the constructor means you've already chosen a directory yourself.
827
- * @public
828
- */
829
- static nodeStorageDir: string | null;
830
- /** Register a storage instance with a weak reference. @public */
831
- static register(instance: PersistentStorage): void;
832
- /**
833
- * Flush the debounced write buffer of every registered PersistentStorage
834
- * instance. Called automatically on pagehide/visibilitychange when autoSync
835
- * is in use; can also be called manually.
836
- * @public
837
- */
838
- static flushAll(): void;
839
- constructor(id: string, type: StoreType | StorageDriver, batchedWrites?: boolean);
840
- /**
841
- * @param type - The storage type: 'local', 'session', 'indexed', 'node', or 'in_memory'
842
- * @param batchedWrites - Whether to enable batched writes
843
- */
844
- initStore(type: StoreType, batchedWrites: boolean): Promise<void>;
845
- flush(): void;
846
- clear(): Promise<void>;
847
- sync(): {
848
- (method: SyncOperation, model: Model, options: SyncOptions): Promise<void>;
849
- __name__: string;
850
- };
851
- removeCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
852
- addCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
853
- getCollectionReferenceData(model: Model): Record<string, string[]>;
854
- save(model: Model): Promise<any>;
855
- create(model: Model, options: SyncOptions): Promise<any>;
856
- update(model: Model): Promise<any>;
857
- find(model: Model): Promise<any>;
858
- findAll(): Promise<any[]>;
859
- destroy(model: Model, collection: Collection | undefined): Promise<Model>;
860
- getStorageSize(): Promise<number>;
861
- getItemName(id: string | number): string;
862
- }
863
-
864
- /**
865
- * @public
866
- */
867
- declare const skeletor: SkeletorType;
868
- export default skeletor;
869
-
870
- /**
871
- * @public
872
- */
873
- export declare interface SkeletorType {
874
- Collection: typeof Collection;
875
- EventEmitter: typeof EventEmitter;
876
- Model: typeof Model;
877
- sync: typeof sync;
878
- HTTPError: typeof HTTPError;
879
- VERSION?: string;
880
- noConflict?: () => SkeletorType;
881
- }
882
-
883
- /**
884
- * Storage driver interface for key-value persistence.
885
- * @public
886
- */
887
- export declare interface StorageDriver {
888
- ready(): Promise<void>;
889
- setItem(key: string, value: any): Promise<any>;
890
- getItem(key: string): Promise<any>;
891
- removeItem(key: string): Promise<void>;
892
- clear(): Promise<void>;
893
- length(): Promise<number>;
894
- key(keyIndex: number): Promise<string | null>;
895
- keys(): Promise<string[]>;
896
- /**
897
- * Write several items in one go. A successful write is signalled by the
898
- * promise settling, not by what it resolves with: drivers may resolve with
899
- * the written items (localForage does) or with nothing, and callers must
900
- * treat both as success.
901
- */
902
- setItems?(items: Record<string, any>): Promise<Record<string, any> | void>;
903
- getItems?(keys: string[]): Promise<Record<string, any>>;
904
- debouncedSetItems?: {
905
- (items: Record<string, any>): Promise<Record<string, any> | void>;
906
- flush?: () => void;
907
- };
908
- }
909
-
910
- /**
911
- * @public
912
- */
913
- export declare type StoreType = 'local' | 'session' | 'indexed' | 'in_memory' | 'node';
914
-
915
- /**
916
- * The default `sync`: a JSON request over `fetch()` to the model's `url()`.
917
- * Override it (or `Model.sync`/`Collection.sync`) to change how models are
918
- * persisted, for instance to batch rapid-fire updates with `setTimeout`, to
919
- * talk over WebSockets, or to write to browser storage.
920
- *
921
- * It honours both contracts a `sync` may use. On a 2xx response the JSON body
922
- * (`null` when the body is empty) is passed to `options.success` and the
923
- * returned promise resolves with it. On a non-2xx response, a network failure
924
- * or an unparsable body, `options.error` receives the error (an `HTTPError`
925
- * for the first) and the promise rejects with it.
926
- *
927
- * `options.data` is sent as query parameters on GET, which may not carry a
928
- * body, and as a JSON body otherwise. For create, update and patch the body
929
- * defaults to `options.attrs` or the model's `toJSON()`.
930
- * @public
931
- */
932
- export declare function sync(method: SyncOperation, model: Model | Collection<any>, options?: SyncOptions): Promise<any>;
933
-
934
- /**
935
- * @public
936
- */
937
- export declare type SyncOperation = 'create' | 'update' | 'patch' | 'delete' | 'read';
938
-
939
- /**
940
- * @public
941
- */
942
- export declare interface SyncOptions {
943
- url?: string;
944
- data?: any;
945
- attrs?: any;
946
- success?: (data?: any, options?: SyncOptions) => void;
947
- error?: (error: any) => void;
948
- xhr?: any;
949
- wait?: boolean;
950
- collection?: Collection;
951
- }
952
-
953
- export { }
1
+ import localForage from 'localforage';
2
+
3
+ /**
4
+ * @public
5
+ * **Models** are the basic data object in the framework --
6
+ * frequently representing a row in a table in a database on your server.
7
+ * A discrete chunk of data and a bunch of useful, related methods for
8
+ * performing computations and transformations on that data.
9
+ */
10
+ declare class Model<T extends ModelAttributes = ModelAttributes> extends EventEmitterObject {
11
+ _storage?: PersistentStorage;
12
+ _changing: boolean;
13
+ _pending: boolean | ModelOptions;
14
+ _previousAttributes?: T;
15
+ _url: string;
16
+ _urlRoot: string;
17
+ attrs: T;
18
+ attributes: T;
19
+ changed: Partial<T>;
20
+ cid: string;
21
+ collection?: Collection;
22
+ id: string | number;
23
+ hydrated?: Promise<void>;
24
+ validationError: string | number | null;
25
+ /**
26
+ * Create a new model with the specified attributes. A client id (`cid`)
27
+ * is automatically generated and assigned for you.
28
+ */
29
+ constructor(attributes?: Partial<T>, options?: ModelOptions);
30
+ /**
31
+ * The canonical storage accessor. Set to a `PersistentStorage` instance
32
+ * to enable local persistence for this model.
33
+ */
34
+ get storage(): PersistentStorage | undefined;
35
+ set storage(s: PersistentStorage);
36
+ /**
37
+ * @deprecated Use `storage` instead.
38
+ */
39
+ get browserStorage(): PersistentStorage | undefined;
40
+ set browserStorage(s: PersistentStorage);
41
+ /**
42
+ * Override to enable automatic persistence. When true, any `set()` call
43
+ * that changes attributes will schedule a debounced save to `storage`, and
44
+ * the model will auto-hydrate from storage on construction.
45
+ */
46
+ get autoSync(): boolean;
47
+ /**
48
+ * Debounce delay (ms) for auto-save writes. Override to tune.
49
+ */
50
+ get autoSyncDelay(): number;
51
+ /**
52
+ * The default name for the JSON `id` attribute is `"id"`. MongoDB and
53
+ * CouchDB users may want to set this to `"_id"` (by overriding this getter
54
+ * in a subclass).
55
+ */
56
+ get idAttribute(): string;
57
+ /**
58
+ * The prefix is used to create the client id which is used to identify models locally.
59
+ * You may want to override this if you're experiencing name clashes with model ids.
60
+ */
61
+ get cidPrefix(): string;
62
+ /**
63
+ * preinitialize is an empty function by default. You can override it with a function
64
+ * or object. preinitialize will run before any instantiation logic is run in the Model.
65
+ */
66
+ preinitialize(...args: any[]): void;
67
+ /**
68
+ * Initialize is an empty function by default. Override it with your own
69
+ * initialization logic.
70
+ */
71
+ initialize(attrs?: Partial<T>, options?: ModelOptions): void;
72
+ validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): string | number | null | void;
73
+ /**
74
+ * Return a hash of defaults for the model's attributes.
75
+ */
76
+ defaults(): Partial<T>;
77
+ /**
78
+ * Declare computed properties. Override in subclasses to define properties
79
+ * that derive their value from other attributes. Each entry specifies the
80
+ * attribute keys it depends on (`deps`) and a function (`fn`) that receives
81
+ * the model and returns the computed value. The value is cached and
82
+ * recalculated automatically when any dep changes, firing a `change:key`
83
+ * event.
84
+ */
85
+ get computed(): ComputedProperties<this>;
86
+ /**
87
+ * Return a copy of the model's `attributes` object.
88
+ */
89
+ toJSON(): T;
90
+ /**
91
+ * Override this if you need custom syncing semantics for *this* particular model.
92
+ */
93
+ sync(method: SyncOperation, model: Model<any>, options: Options): any;
94
+ /**
95
+ * Get the value of an attribute, or a computed property.
96
+ */
97
+ get<K extends keyof T>(attr: K): T[K];
98
+ keys(): string[];
99
+ values(): T[keyof T][];
100
+ pairs(): [keyof T, T[keyof T]][];
101
+ entries(): [keyof T, T[keyof T]][];
102
+ invert(): Record<string, keyof T>;
103
+ pick<K extends keyof T>(...args: K[]): Pick<T, K>;
104
+ omit<K extends keyof T>(...args: K[]): Omit<T, K>;
105
+ isEmpty(): boolean;
106
+ /**
107
+ * Returns `true` if the attribute contains a value that is not null
108
+ * or undefined.
109
+ */
110
+ has(attr: keyof T): boolean;
111
+ /**
112
+ * Returns `true` if the model's attributes satisfy `attrs`.
113
+ *
114
+ * An attributes object is compared with lodash's `isMatch`: a partial, deep
115
+ * comparison, so `{ form: { type: 'hidden' } }` matches a `form` attribute
116
+ * that has `type: 'hidden'` alongside other keys. A function is called with
117
+ * the attributes and its result coerced to a boolean.
118
+ *
119
+ * To scan a collection, prefer `Collection#find`, `filter` or `where`. They
120
+ * build their matcher once per scan instead of once per model.
121
+ */
122
+ matches(attrs: Partial<T> | ((attrs: T) => any)): boolean;
123
+ /**
124
+ * Set a hash of model attributes on the object, firing `"change"`. This is
125
+ * the core primitive operation of a model, updating the data and notifying
126
+ * anyone who needs to know about the change in state. The heart of the beast.
127
+ */
128
+ set(key: string | Partial<T> | ObjectWithId, val?: any, options?: ModelOptions): this;
129
+ /**
130
+ * Remove an attribute from the model, firing `"change"`. `unset` is a noop
131
+ * if the attribute doesn't exist.
132
+ */
133
+ unset(attr: keyof T, options?: ModelOptions): this;
134
+ /**
135
+ * Clear all attributes on the model, firing `"change"`.
136
+ */
137
+ clear(options?: ModelOptions): this;
138
+ /**
139
+ * Determine if the model has changed since the last `"change"` event.
140
+ * If you specify an attribute name, determine if that attribute has changed.
141
+ */
142
+ hasChanged(attr?: keyof T): boolean;
143
+ /**
144
+ * Return an object containing all the attributes that have changed, or
145
+ * false if there are no changed attributes. Useful for determining what
146
+ * parts of a view need to be updated and/or what attributes need to be
147
+ * persisted to the server. Unset attributes will be set to undefined.
148
+ * You can also pass an attributes object to diff against the model,
149
+ * determining if there *would be* a change.
150
+ */
151
+ changedAttributes(diff?: Partial<T>): Partial<T> | false;
152
+ /**
153
+ * Get the previous value of an attribute, recorded at the time the last
154
+ * `"change"` event was fired.
155
+ */
156
+ previous<K extends keyof T>(attr: K): T[K] | null;
157
+ /**
158
+ * Get all of the attributes of the model at the time of the previous
159
+ * `"change"` event.
160
+ */
161
+ previousAttributes(): T | undefined;
162
+ /**
163
+ * Fetch the model from the server, merging the response with the model's
164
+ * local attributes. Any changed attributes will trigger a "change" event.
165
+ */
166
+ fetch(options?: Options): any;
167
+ /**
168
+ * Set a hash of model attributes, and sync the model to the server.
169
+ * If the server returns an attributes hash that differs, the model's
170
+ * state will be `set` again.
171
+ */
172
+ save(key?: string | null | Partial<T>, val?: any, options?: ModelOptions): any;
173
+ /**
174
+ * Destroy this model on the server if it was already persisted.
175
+ * Optimistically removes the model from its collection, if it has one.
176
+ * If `wait: true` is passed, waits for the server to respond before removal.
177
+ */
178
+ destroy(options?: ModelOptions): any;
179
+ get urlRoot(): string;
180
+ set urlRoot(root: string);
181
+ /**
182
+ * Default URL for the model's representation on the server -- if you're
183
+ * using Backbone's restful methods, override this to change the endpoint
184
+ * that will be called.
185
+ */
186
+ get url(): string;
187
+ set url(url: string);
188
+ /**
189
+ * **parse** converts a response into the hash of attributes to be `set` on
190
+ * the model. The default implementation is just to pass the response along.
191
+ */
192
+ parse(resp: any, options?: ModelOptions): Partial<T> | null | void;
193
+ /**
194
+ * A model is new if it has never been saved to the server, and lacks an id.
195
+ */
196
+ isNew(): boolean;
197
+ /**
198
+ * Check if the model is currently in a valid state.
199
+ */
200
+ isValid(options?: ModelOptions): boolean;
201
+ /**
202
+ * Subscribe to model changes. Returns an unsubscribe function.
203
+ *
204
+ * `model.subscribe(callback)` — fires on any attribute change, receives `(model, changed)`.
205
+ * `model.subscribe(event, callback)` — subscribe to a specific event (base EventEmitter form).
206
+ *
207
+ * Compatible with React's `useSyncExternalStore` and other store-style APIs.
208
+ */
209
+ subscribe(event: string, callback: EventCallback, context?: unknown): () => void;
210
+ subscribe(callback: (model: this, changed: Partial<T>) => void): () => void;
211
+ /**
212
+ * Run validation against the next complete set of model attributes,
213
+ * returning `true` if all is well. Otherwise, fire an `"invalid"` event.
214
+ */
215
+ _validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): boolean;
216
+ }
217
+
218
+ /**
219
+ * Storage driver interface for key-value persistence.
220
+ * @public
221
+ */
222
+ interface StorageDriver {
223
+ ready(): Promise<void>;
224
+ setItem(key: string, value: any): Promise<any>;
225
+ getItem(key: string): Promise<any>;
226
+ removeItem(key: string): Promise<void>;
227
+ clear(): Promise<void>;
228
+ length(): Promise<number>;
229
+ key(keyIndex: number): Promise<string | null>;
230
+ keys(): Promise<string[]>;
231
+ /**
232
+ * Write several items in one go. A successful write is signalled by the
233
+ * promise settling, not by what it resolves with: drivers may resolve with
234
+ * the written items (localForage does) or with nothing, and callers must
235
+ * treat both as success.
236
+ */
237
+ setItems?(items: Record<string, any>): Promise<Record<string, any> | void>;
238
+ getItems?(keys: string[]): Promise<Record<string, any>>;
239
+ debouncedSetItems?: {
240
+ (items: Record<string, any>): Promise<Record<string, any> | void>;
241
+ flush?: () => void;
242
+ };
243
+ }
244
+ /**
245
+ * @public
246
+ */
247
+ type StoreType = 'local' | 'session' | 'indexed' | 'in_memory' | 'node';
248
+
249
+ /**
250
+ * Constructor for a Node.js-only storage driver. Registered by the
251
+ * `@converse/skeletor/node` entry point via {@link PersistentStorage.nodeStorage}.
252
+ * @public
253
+ */
254
+ type NodeStorageConstructor = new (name: string, storageDir?: string, inMemory?: boolean) => StorageDriver;
255
+ /**
256
+ * @public
257
+ */
258
+ declare class PersistentStorage {
259
+ storeInitialized: Promise<void>;
260
+ storeReady: boolean;
261
+ store: StorageDriver;
262
+ name: string;
263
+ static sessionStorageInitialized: Promise<void>;
264
+ static localForage: typeof localForage;
265
+ static nodeStorage: NodeStorageConstructor | null;
266
+ /**
267
+ * Directory the `'node'` store type writes its database files to. The driver's
268
+ * own default is relative, so it resolves against `process.cwd()` and a process
269
+ * started from two directories ends up with two separate sets of state. Set an
270
+ * absolute path (`$XDG_STATE_HOME/<app>`, say) to pin it. Left `null`, the
271
+ * driver's default applies.
272
+ *
273
+ * Only the `'node'` string store type reads this; passing a driver instance to
274
+ * the constructor means you've already chosen a directory yourself.
275
+ * @public
276
+ */
277
+ static nodeStorageDir: string | null;
278
+ /** Register a storage instance with a weak reference. @public */
279
+ static register(instance: PersistentStorage): void;
280
+ /**
281
+ * Flush the debounced write buffer of every registered PersistentStorage
282
+ * instance. Called automatically on pagehide/visibilitychange when autoSync
283
+ * is in use; can also be called manually.
284
+ * @public
285
+ */
286
+ static flushAll(): void;
287
+ constructor(id: string, type: StoreType | StorageDriver, batchedWrites?: boolean);
288
+ /**
289
+ * @param type - The storage type: 'local', 'session', 'indexed', 'node', or 'in_memory'
290
+ * @param batchedWrites - Whether to enable batched writes
291
+ */
292
+ initStore(type: StoreType, batchedWrites: boolean): Promise<void>;
293
+ flush(): void;
294
+ clear(): Promise<void>;
295
+ sync(): {
296
+ (method: SyncOperation, model: Model, options: SyncOptions): Promise<void>;
297
+ __name__: string;
298
+ };
299
+ removeCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
300
+ addCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
301
+ getCollectionReferenceData(model: Model): Record<string, string[]>;
302
+ save(model: Model): Promise<any>;
303
+ create(model: Model, options: SyncOptions): Promise<any>;
304
+ update(model: Model): Promise<any>;
305
+ find(model: Model): Promise<any>;
306
+ findAll(): Promise<any[]>;
307
+ destroy(model: Model, collection: Collection | undefined): Promise<Model>;
308
+ getStorageSize(): Promise<number>;
309
+ getItemName(id: string | number): string;
310
+ }
311
+
312
+ /**
313
+ * @public
314
+ * If models tend to represent a single row of data, a Collection is
315
+ * more analogous to a table full of data ... or a small slice or page of that
316
+ * table, or a collection of rows that belong together for a particular reason
317
+ * -- all of the messages in this particular folder, all of the documents
318
+ * belonging to this particular author, and so on. Collections maintain
319
+ * indexes of their models, both in order, and for lookup by `id`.
320
+ */
321
+ declare class Collection<T extends Model = Model> extends EventEmitterObject {
322
+ [key: symbol]: () => CollectionIterator<T>;
323
+ _storage?: PersistentStorage;
324
+ _comparator?: Comparator<T>;
325
+ _url: string;
326
+ hydrated?: Promise<void>;
327
+ models: T[];
328
+ protected _byId: Record<string, T>;
329
+ protected _model?: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T;
330
+ /**
331
+ * Create a new **Collection**, perhaps to contain a specific type of `model`.
332
+ * If a `comparator` is specified, the Collection will maintain
333
+ * its models in sort order, as they're added and removed.
334
+ */
335
+ constructor(models?: T[] | ModelAttributes[] | T | ModelAttributes, options?: CollectionOptions<T>);
336
+ get comparator(): Comparator<T>;
337
+ set comparator(c: Comparator<T>);
338
+ /**
339
+ * The canonical storage accessor. Set to a `PersistentStorage` instance
340
+ * to enable local persistence for this collection.
341
+ */
342
+ get storage(): PersistentStorage | undefined;
343
+ set storage(s: PersistentStorage);
344
+ /**
345
+ * @deprecated Use `storage` instead.
346
+ */
347
+ get browserStorage(): PersistentStorage | undefined;
348
+ set browserStorage(s: PersistentStorage);
349
+ /**
350
+ * Override to return `true` to automatically load the collection from
351
+ * storage on construction. Await `hydrated` to know when hydration
352
+ * is complete.
353
+ *
354
+ * Note: collection `autoSync` is hydrate-only. Unlike `Model`, it does
355
+ * **not** schedule auto-saves when the collection changes (`add`/`remove`/
356
+ * `reset`). Persisting members is each model's responsibility — enable
357
+ * `autoSync` on the contained model class and every model writes its own
358
+ * record. A collection-level write would be redundant with that.
359
+ */
360
+ get autoSync(): boolean;
361
+ /**
362
+ * The default model for a collection is just a **Model**.
363
+ * This should be overridden in most cases.
364
+ */
365
+ get model(): new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T | Model;
366
+ set model(model: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T);
367
+ get length(): number;
368
+ get url(): string;
369
+ set url(url: string);
370
+ /**
371
+ * preinitialize is an empty function by default. You can override it with a function
372
+ * or object. preinitialize will run before any instantiation logic is run in the Collection.
373
+ */
374
+ preinitialize(..._args: any[]): void;
375
+ /**
376
+ * Initialize is an empty function by default. Override it with your own
377
+ * initialization logic.
378
+ */
379
+ initialize(..._args: any[]): void;
380
+ /**
381
+ * The JSON representation of a Collection is an array of the
382
+ * models' attributes.
383
+ */
384
+ toJSON(): any[];
385
+ sync(method: SyncOperation, model: Model | Collection<any>, options?: Options): any;
386
+ /**
387
+ * Add a model, or list of models to the set. `models` may be
388
+ * Models or raw JavaScript objects to be converted to Models, or any
389
+ * combination of the two.
390
+ */
391
+ add(models: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
392
+ /**
393
+ * Remove a model, or a list of models from the set.
394
+ */
395
+ remove(models: T | ObjectWithId | (T | ObjectWithId)[], options?: Options): T | T[];
396
+ /**
397
+ * Update a collection by `set`-ing a new list of models, adding new ones,
398
+ * removing models that are no longer present, and merging models that
399
+ * already exist in the collection, as necessary. Similar to **Model#set**,
400
+ * the core operation for updating the data contained by the collection.
401
+ */
402
+ set(models: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
403
+ clearStore(options?: Options, filter?: (model: T) => boolean): Promise<void>;
404
+ /**
405
+ * When you have more items than you want to add or remove individually,
406
+ * you can reset the entire set with a new list of models, without firing
407
+ * any granular `add` or `remove` events. Fires `reset` when finished.
408
+ * Useful for bulk operations and optimizations.
409
+ */
410
+ reset(models?: T[] | T | ModelAttributes | ModelAttributes[], options?: Options): T | T[];
411
+ /**
412
+ * Add a model to the end of the collection.
413
+ */
414
+ push(model: T | ModelAttributes, options?: Options): T;
415
+ /**
416
+ * Remove a model from the end of the collection.
417
+ */
418
+ pop(options?: Options): T | undefined;
419
+ /**
420
+ * Add a model to the beginning of the collection.
421
+ */
422
+ unshift(model: T | ModelAttributes, options?: Options): T;
423
+ /**
424
+ * Remove a model from the beginning of the collection.
425
+ */
426
+ shift(options?: Options): T | undefined;
427
+ /** Slice out a sub-array of models from the collection. */
428
+ slice(start?: number, end?: number): T[];
429
+ filter(callback: ((model: T) => boolean) | string | Partial<ModelAttributes>, thisArg?: any): T[];
430
+ every(pred: ((attrs: ModelAttributes) => boolean) | Options): boolean;
431
+ difference(values: T[]): T[];
432
+ max(): number;
433
+ min(): number;
434
+ drop(n?: number): T[];
435
+ some(pred: ((attrs: ModelAttributes) => boolean) | Options): boolean;
436
+ sortBy(iteratee: string | ((model: T) => any) | Partial<ModelAttributes>): T[];
437
+ isEmpty(): boolean;
438
+ keyBy(iteratee: string | ((model: T) => string)): Record<string, T>;
439
+ each(callback: (model: T, index: number, array: T[]) => void, thisArg?: any): void;
440
+ forEach(callback: (model: T, index: number, array: T[]) => void, thisArg?: any): void;
441
+ includes(item: T): boolean;
442
+ size(): number;
443
+ countBy(f: string | ((model: T) => string) | Partial<ModelAttributes>): Record<string, number>;
444
+ groupBy(pred: string | ((model: T) => string | number) | Partial<ModelAttributes>): Record<string, T[]>;
445
+ indexOf(model: T, fromIndex?: number): number;
446
+ findLastIndex(pred: ((model: T) => boolean) | string | Partial<ModelAttributes>, fromIndex?: number): number;
447
+ lastIndexOf(model: T, fromIndex?: number): number;
448
+ findIndex(pred: ((model: T) => boolean) | string | Partial<ModelAttributes>): number;
449
+ last(): T | undefined;
450
+ head(): T | undefined;
451
+ first(): T | undefined;
452
+ map<U>(cb: string | ((model: T) => U) | Partial<ModelAttributes>, thisArg?: any): U[];
453
+ reduce<U = T>(callback: (accumulator: U, model: T, index: number, array: T[]) => U, initialValue?: U): U | T;
454
+ reduceRight<U = T>(callback: (accumulator: U, model: T, index: number, array: T[]) => U, initialValue?: U): U | T;
455
+ toArray(): T[];
456
+ /**
457
+ * Get a model from the set by id, cid, model object with id or cid
458
+ * properties, or an attributes object that is transformed through modelId.
459
+ */
460
+ get(obj?: string | number | ModelAttributes | T | null): T | undefined;
461
+ /**
462
+ * Returns `true` if the model is in the collection.
463
+ */
464
+ has(obj: string | number | ModelAttributes | T | null): boolean;
465
+ /**
466
+ * Get the model at the given index.
467
+ */
468
+ at(index: number): T | undefined;
469
+ /**
470
+ * Return models with matching attributes. Useful for simple cases of
471
+ * `filter`.
472
+ */
473
+ where(attrs: ModelAttributes | Partial<ModelAttributes>, first?: boolean): T[] | T | undefined;
474
+ /**
475
+ * Return the first model with matching attributes. Useful for simple cases
476
+ * of `find`.
477
+ */
478
+ findWhere(attrs: ModelAttributes): T | undefined;
479
+ find(predicate: ((model: T) => boolean) | Partial<ModelAttributes> | string, fromIndex?: number): T | undefined;
480
+ /**
481
+ * Force the collection to re-sort itself. You don't need to call this under
482
+ * normal circumstances, as the set will maintain sort order as each item
483
+ * is added.
484
+ */
485
+ sort(options?: Options): this;
486
+ /**
487
+ * Pluck an attribute from each model in the collection.
488
+ */
489
+ pluck(attr: string): any[];
490
+ /**
491
+ * Fetch the default set of models for this collection, resetting the
492
+ * collection when they arrive. If `reset: true` is passed, the response
493
+ * data will be passed through the `reset` method instead of `set`.
494
+ */
495
+ fetch(options?: Options): Promise<any> | any;
496
+ /**
497
+ * Create a new instance of a model in this collection. Add the model to the
498
+ * collection immediately, unless `wait: true` is passed, in which case we
499
+ * wait for the server to agree.
500
+ */
501
+ create(model: T | ModelAttributes, options?: FetchOrCreateOptions): Promise<T> | T;
502
+ /**
503
+ * Subscribe to collection changes (add, remove, reset, sort, update).
504
+ * Returns an unsubscribe function.
505
+ *
506
+ * `collection.subscribe(callback)` — fires once per operation on add/remove/reset/sort (via `update`, `reset`, `sort` events).
507
+ * `collection.subscribe(event, callback)` — subscribe to a specific event (base EventEmitter form).
508
+ *
509
+ * Compatible with React's `useSyncExternalStore` and other store-style APIs.
510
+ */
511
+ subscribe(event: string, callback: EventCallback, context?: unknown): () => void;
512
+ subscribe(callback: (collection: this) => void): () => void;
513
+ /**
514
+ * **parse** converts a response into a list of models to be added to the
515
+ * collection. The default implementation is just to pass it through.
516
+ */
517
+ parse(resp: any, _options?: Options): any;
518
+ /**
519
+ * Define how to uniquely identify models in the collection.
520
+ */
521
+ modelId(attrs: ModelAttributes): string | number | undefined;
522
+ /** Get an iterator of all models in this collection. */
523
+ values(): CollectionIterator<T>;
524
+ /**
525
+ * @public
526
+ * Enable for...of iteration over the collection.
527
+ */
528
+ [Symbol.iterator]: () => CollectionIterator<T>;
529
+ /** Get an iterator of all model IDs in this collection. */
530
+ keys(): CollectionIterator<T>;
531
+ /** Get an iterator of all [ID, model] tuples in this collection. */
532
+ entries(): CollectionIterator<T>;
533
+ /**
534
+ * Private method to reset all internal state. Called when the collection
535
+ * is first initialized or reset.
536
+ */
537
+ _reset(): void;
538
+ createModel(attrs: ModelAttributes, options?: Options): T;
539
+ /**
540
+ * Prepare a hash of attributes (or other model) to be added to this
541
+ * collection.
542
+ */
543
+ _prepareModel(attrs: ModelAttributes | T, options?: Options): T | null;
544
+ /**
545
+ * Internal method called by both remove and set.
546
+ */
547
+ _removeModels(models: (T | ObjectWithId)[], options?: Options): T[];
548
+ /**
549
+ * Method for checking whether an object should be considered a model for
550
+ * the purposes of adding to the collection.
551
+ */
552
+ _isModel(model: any): model is T;
553
+ /**
554
+ * Internal method to create a model's ties to a collection.
555
+ */
556
+ _addReference(model: T, _options?: Options): void;
557
+ /**
558
+ * Internal method to sever a model's ties to a collection.
559
+ */
560
+ _removeReference(model: T, _options?: Options): void;
561
+ /**
562
+ * Internal method called every time a model in the set fires an event.
563
+ * Sets need to update their indexes when models change ids. All other
564
+ * events simply proxy through. "add" and "remove" events that originate
565
+ * in other collections are ignored.
566
+ */
567
+ _onModelEvent(event: string, model: T, collection: Collection<T>, options?: Options): void;
568
+ }
569
+ /**
570
+ * @public
571
+ */
572
+ declare class CollectionIterator<T extends Model> {
573
+ private _collection;
574
+ private _kind;
575
+ private _index;
576
+ /**
577
+ * A CollectionIterator implements JavaScript's Iterator protocol, allowing the
578
+ * use of `for of` loops in modern browsers and interoperation between
579
+ * Collection and other JavaScript functions and third-party libraries
580
+ * which can operate on Iterables.
581
+ */
582
+ constructor(collection: Collection<T>, kind: number);
583
+ next(): IteratorResult<any>;
584
+ [Symbol.iterator](): IterableIterator<any>;
585
+ }
586
+
587
+ /**
588
+ * @public
589
+ */
590
+ type SyncOperation = 'create' | 'update' | 'patch' | 'delete' | 'read';
591
+ /**
592
+ * @public
593
+ */
594
+ type ObjectListenedTo = object & {
595
+ _listenId?: string;
596
+ };
597
+ /**
598
+ * @public
599
+ */
600
+ interface SyncOptions {
601
+ url?: string;
602
+ data?: any;
603
+ attrs?: any;
604
+ success?: (data?: any, options?: SyncOptions) => void;
605
+ error?: (error: any) => void;
606
+ xhr?: any;
607
+ wait?: boolean;
608
+ collection?: Collection;
609
+ }
610
+ /**
611
+ * @public
612
+ */
613
+ type ClassConstructor<T = any> = new (...args: any[]) => T;
614
+ /**
615
+ * @public
616
+ */
617
+ type EventContext = unknown;
618
+ /**
619
+ * @public
620
+ */
621
+ type EventCallback = (...args: any[]) => void;
622
+ /**
623
+ * @public
624
+ */
625
+ type EventCallbackMap = Record<string, EventCallback>;
626
+ /**
627
+ * @public
628
+ */
629
+ type EventListenerMap = Record<string, ListeningType>;
630
+ /**
631
+ * @public
632
+ */
633
+ interface EventHandlersMap {
634
+ all?: EventHandler[];
635
+ [name: string]: EventHandler[];
636
+ }
637
+ /**
638
+ * @public
639
+ */
640
+ type ListeningMap = Record<string, ListeningType>;
641
+ /**
642
+ * @public
643
+ */
644
+ type ObjectWithId = Record<string, any> & {
645
+ id: string | number;
646
+ };
647
+ /**
648
+ * @public
649
+ */
650
+ interface IEventEmitter {
651
+ _events?: Record<string, any>;
652
+ _listeners?: ListeningMap;
653
+ _listeningTo?: ListeningMap;
654
+ _listenId?: string;
655
+ on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
656
+ off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): this;
657
+ trigger(name: string, ...args: any[]): this;
658
+ stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): this;
659
+ once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
660
+ listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): this;
661
+ listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): this;
662
+ }
663
+ /**
664
+ * @public
665
+ */
666
+ interface EventHandler {
667
+ callback: EventCallback;
668
+ context: any;
669
+ ctx: any;
670
+ listening?: ListeningType | null;
671
+ }
672
+ /**
673
+ * @public
674
+ */
675
+ interface ListeningType {
676
+ _events?: EventCallbackMap;
677
+ cleanup(): void;
678
+ count: number;
679
+ id: string;
680
+ interop: boolean;
681
+ listener: IEventEmitter;
682
+ obj: any;
683
+ start(name: string | EventCallbackMap, callback: EventCallback, context: any, _listening: ListeningType): this;
684
+ stop(name: string | EventCallbackMap, callback: EventCallback): void;
685
+ }
686
+ /**
687
+ * @public
688
+ */
689
+ type Comparator<T extends Model = Model> = string | boolean | ((a: T, b: T) => number) | ((a?: T) => string);
690
+ /**
691
+ * @public
692
+ */
693
+ type ComputedProperty<M> = {
694
+ deps: string[];
695
+ fn: (model: M) => any;
696
+ };
697
+ /**
698
+ * @public
699
+ */
700
+ type ComputedProperties<M> = Record<string, ComputedProperty<M>>;
701
+ /**
702
+ * @public
703
+ */
704
+ type ModelAttributes = Record<string | number, any> & {
705
+ id?: string | number;
706
+ };
707
+ /**
708
+ * @public
709
+ */
710
+ type Options = Record<string, any>;
711
+ /**
712
+ * @public
713
+ */
714
+ type FetchOrCreateOptions = Options & {
715
+ promise?: boolean;
716
+ success?: (m: Model, resp: any, callbackOpts: Options) => void;
717
+ };
718
+ /**
719
+ * @public
720
+ */
721
+ type CollectionOptions<T extends Model = Model> = Options & {
722
+ model?: new (attributes?: Partial<ModelAttributes>, options?: ModelOptions) => T;
723
+ comparator?: Comparator<T>;
724
+ previousModels?: Model[];
725
+ };
726
+ /**
727
+ * @public
728
+ */
729
+ type ModelOptions = Options & {
730
+ collection?: Collection;
731
+ parse?: boolean;
732
+ unset?: boolean;
733
+ silent?: boolean;
734
+ validate?: boolean;
735
+ /** Suppress the auto-save triggered by set() on autoSync models. */
736
+ noAutoSave?: boolean;
737
+ /** Mark a set() call as originating from a storage read; suppresses auto-save. */
738
+ fromStorage?: boolean;
739
+ };
740
+
741
+ /**
742
+ * @public
743
+ */
744
+ declare function EventEmitter<T extends ClassConstructor>(Base: T): {
745
+ new (...args: any[]): {
746
+ [x: string]: any;
747
+ _events?: EventHandlersMap;
748
+ _listeners?: EventListenerMap;
749
+ _listeningTo?: EventListenerMap;
750
+ _listenId?: string;
751
+ /**
752
+ * Bind an event to a `callback` function. Passing `"all"` will bind
753
+ * the callback to all events fired.
754
+ */
755
+ on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
756
+ /**
757
+ * Inversion-of-control versions of `on`. Tell *this* object to listen to
758
+ * an event in another object... keeping track of what it's listening to
759
+ * for easier unbinding later.
760
+ */
761
+ listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
762
+ /**
763
+ * Remove one or many callbacks. If `context` is null, removes all
764
+ * callbacks with that function. If `callback` is null, removes all
765
+ * callbacks for the event. If `name` is null, removes all bound
766
+ * callbacks for all events.
767
+ */
768
+ off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): /*elided*/ any;
769
+ /**
770
+ * Tell this object to stop listening to either specific events ... or
771
+ * to every object it's currently listening to.
772
+ */
773
+ stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
774
+ /**
775
+ * Bind an event to only be triggered a single time. After the first time
776
+ * the callback is invoked, its listener will be removed. If multiple events
777
+ * are passed in using the space-separated syntax, the handler will fire
778
+ * once for each event, not once for a combination of all events.
779
+ */
780
+ once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
781
+ /**
782
+ * Inversion-of-control versions of `once`.
783
+ */
784
+ listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
785
+ /**
786
+ * Trigger one or many events, firing all bound callbacks. Callbacks are
787
+ * passed the same arguments as `trigger` is, apart from the event name
788
+ * (unless you're listening on `"all"`, which will cause your callback to
789
+ * receive the true name of the event as the first argument).
790
+ */
791
+ trigger(name: string, ...args: any[]): /*elided*/ any;
792
+ /**
793
+ * Subscribe to an event. Returns an unsubscribe function.
794
+ * Compatible with `useSyncExternalStore` and other store-style APIs.
795
+ */
796
+ subscribe(event: string, callback: EventCallback, context?: EventContext): () => void;
797
+ };
798
+ } & T;
799
+ /**
800
+ * @public
801
+ */
802
+ declare const EventEmitterObject: {
803
+ new (...args: any[]): {
804
+ [x: string]: any;
805
+ _events?: EventHandlersMap;
806
+ _listeners?: EventListenerMap;
807
+ _listeningTo?: EventListenerMap;
808
+ _listenId?: string;
809
+ /**
810
+ * Bind an event to a `callback` function. Passing `"all"` will bind
811
+ * the callback to all events fired.
812
+ */
813
+ on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
814
+ /**
815
+ * Inversion-of-control versions of `on`. Tell *this* object to listen to
816
+ * an event in another object... keeping track of what it's listening to
817
+ * for easier unbinding later.
818
+ */
819
+ listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
820
+ /**
821
+ * Remove one or many callbacks. If `context` is null, removes all
822
+ * callbacks with that function. If `callback` is null, removes all
823
+ * callbacks for the event. If `name` is null, removes all bound
824
+ * callbacks for all events.
825
+ */
826
+ off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): /*elided*/ any;
827
+ /**
828
+ * Tell this object to stop listening to either specific events ... or
829
+ * to every object it's currently listening to.
830
+ */
831
+ stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
832
+ /**
833
+ * Bind an event to only be triggered a single time. After the first time
834
+ * the callback is invoked, its listener will be removed. If multiple events
835
+ * are passed in using the space-separated syntax, the handler will fire
836
+ * once for each event, not once for a combination of all events.
837
+ */
838
+ once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): /*elided*/ any;
839
+ /**
840
+ * Inversion-of-control versions of `once`.
841
+ */
842
+ listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): /*elided*/ any;
843
+ /**
844
+ * Trigger one or many events, firing all bound callbacks. Callbacks are
845
+ * passed the same arguments as `trigger` is, apart from the event name
846
+ * (unless you're listening on `"all"`, which will cause your callback to
847
+ * receive the true name of the event as the first argument).
848
+ */
849
+ trigger(name: string, ...args: any[]): /*elided*/ any;
850
+ /**
851
+ * Subscribe to an event. Returns an unsubscribe function.
852
+ * Compatible with `useSyncExternalStore` and other store-style APIs.
853
+ */
854
+ subscribe(event: string, callback: EventCallback, context?: EventContext): () => void;
855
+ };
856
+ } & ObjectConstructor;
857
+
858
+ /**
859
+ * Return the PersistentStorage instance configured on `obj`, checking both
860
+ * the canonical `storage` accessor and the deprecated `browserStorage` alias
861
+ * so that subclasses that still override `get browserStorage()` continue to work.
862
+ * @public
863
+ */
864
+ declare function getStorage(obj: Model<any> | Collection<any> | null | undefined): PersistentStorage | undefined;
865
+ /**
866
+ * The error the default `sync` hands to `options.error`, and rejects with, for
867
+ * a response outside the 2xx range.
868
+ * @public
869
+ */
870
+ declare class HTTPError extends Error {
871
+ readonly status: number;
872
+ readonly response: Response;
873
+ constructor(response: Response, method: string, url: string);
874
+ }
875
+ /**
876
+ * The default `sync`: a JSON request over `fetch()` to the model's `url()`.
877
+ * Override it (or `Model.sync`/`Collection.sync`) to change how models are
878
+ * persisted, for instance to batch rapid-fire updates with `setTimeout`, to
879
+ * talk over WebSockets, or to write to browser storage.
880
+ *
881
+ * It honours both contracts a `sync` may use. On a 2xx response the JSON body
882
+ * (`null` when the body is empty) is passed to `options.success` and the
883
+ * returned promise resolves with it. On a non-2xx response, a network failure
884
+ * or an unparsable body, `options.error` receives the error (an `HTTPError`
885
+ * for the first) and the promise rejects with it.
886
+ *
887
+ * `options.data` is sent as query parameters on GET, which may not carry a
888
+ * body, and as a JSON body otherwise. For create, update and patch the body
889
+ * defaults to `options.attrs` or the model's `toJSON()`.
890
+ * @public
891
+ */
892
+ declare function sync(method: SyncOperation, model: Model | Collection<any>, options?: SyncOptions): Promise<any>;
893
+
894
+ /**
895
+ * @public
896
+ */
897
+ interface SkeletorType {
898
+ Collection: typeof Collection;
899
+ EventEmitter: typeof EventEmitter;
900
+ Model: typeof Model;
901
+ sync: typeof sync;
902
+ HTTPError: typeof HTTPError;
903
+ VERSION?: string;
904
+ noConflict?: () => SkeletorType;
905
+ }
906
+ /**
907
+ * @public
908
+ */
909
+ declare const skeletor: SkeletorType;
910
+ /**
911
+ * @public
912
+ */
913
+ declare function noConflict(): any;
914
+
915
+ /**
916
+ * @deprecated Use `PersistentStorage` instead.
917
+ * @public
918
+ */
919
+ declare const BrowserStorage: typeof PersistentStorage;
920
+
921
+ export { BrowserStorage, Collection, CollectionIterator, EventEmitter, EventEmitterObject, HTTPError, Model, PersistentStorage, skeletor as default, getStorage, noConflict, sync };
922
+ export type { ClassConstructor, CollectionOptions, Comparator, ComputedProperties, ComputedProperty, EventCallback, EventCallbackMap, EventContext, EventHandler, EventHandlersMap, EventListenerMap, FetchOrCreateOptions, IEventEmitter, ListeningMap, ListeningType, ModelAttributes, ModelOptions, NodeStorageConstructor, ObjectListenedTo, ObjectWithId, Options, SkeletorType, StorageDriver, StoreType, SyncOperation, SyncOptions };