@converse/skeletor 3.1.4 → 3.1.6

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.
@@ -0,0 +1,956 @@
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)): 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)): 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
+ * @public
492
+ */
493
+ export declare interface IEventEmitter {
494
+ _events?: Record<string, any>;
495
+ _listeners?: ListeningMap;
496
+ _listeningTo?: ListeningMap;
497
+ _listenId?: string;
498
+ on(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
499
+ off(name?: string | EventCallbackMap | null, callback?: EventCallback | EventContext | null, context?: EventContext): this;
500
+ trigger(name: string, ...args: any[]): this;
501
+ stopListening(obj?: any, name?: string | EventCallbackMap, callback?: EventCallback): this;
502
+ once(name: string | EventCallbackMap, callback?: EventCallback | EventContext, context?: EventContext): this;
503
+ listenTo(obj: ObjectListenedTo, name: string | EventCallbackMap, callback?: EventCallback): this;
504
+ listenToOnce(obj: any, name: string | EventCallbackMap, callback?: EventCallback): this;
505
+ }
506
+
507
+ /**
508
+ * @public
509
+ */
510
+ export declare type ListeningMap = Record<string, ListeningType>;
511
+
512
+ /**
513
+ * @public
514
+ */
515
+ export declare interface ListeningType {
516
+ _events?: EventCallbackMap;
517
+ cleanup(): void;
518
+ count: number;
519
+ id: string;
520
+ interop: boolean;
521
+ listener: IEventEmitter;
522
+ obj: any;
523
+ start(name: string | EventCallbackMap, callback: EventCallback, context: any, _listening: ListeningType): this;
524
+ stop(name: string | EventCallbackMap, callback: EventCallback): void;
525
+ }
526
+
527
+ /**
528
+ * @public
529
+ * **Models** are the basic data object in the framework --
530
+ * frequently representing a row in a table in a database on your server.
531
+ * A discrete chunk of data and a bunch of useful, related methods for
532
+ * performing computations and transformations on that data.
533
+ */
534
+ export declare class Model<T extends ModelAttributes = ModelAttributes> extends EventEmitterObject {
535
+ #private;
536
+ _storage?: PersistentStorage;
537
+ _changing: boolean;
538
+ _pending: boolean | ModelOptions;
539
+ _previousAttributes?: T;
540
+ _url: string;
541
+ _urlRoot: string;
542
+ attrs: T;
543
+ attributes: T;
544
+ changed: Partial<T>;
545
+ cid: string;
546
+ collection?: Collection;
547
+ id: string | number;
548
+ hydrated?: Promise<void>;
549
+ validationError: string | number | null;
550
+ /**
551
+ * Create a new model with the specified attributes. A client id (`cid`)
552
+ * is automatically generated and assigned for you.
553
+ */
554
+ constructor(attributes?: Partial<T>, options?: ModelOptions);
555
+ /**
556
+ * The canonical storage accessor. Set to a `PersistentStorage` instance
557
+ * to enable local persistence for this model.
558
+ */
559
+ get storage(): PersistentStorage | undefined;
560
+ set storage(s: PersistentStorage);
561
+ /**
562
+ * @deprecated Use `storage` instead.
563
+ */
564
+ get browserStorage(): PersistentStorage | undefined;
565
+ set browserStorage(s: PersistentStorage);
566
+ /**
567
+ * Override to enable automatic persistence. When true, any `set()` call
568
+ * that changes attributes will schedule a debounced save to `storage`, and
569
+ * the model will auto-hydrate from storage on construction.
570
+ */
571
+ get autoSync(): boolean;
572
+ /**
573
+ * Debounce delay (ms) for auto-save writes. Override to tune.
574
+ */
575
+ get autoSyncDelay(): number;
576
+ /**
577
+ * The default name for the JSON `id` attribute is `"id"`. MongoDB and
578
+ * CouchDB users may want to set this to `"_id"` (by overriding this getter
579
+ * in a subclass).
580
+ */
581
+ get idAttribute(): string;
582
+ /**
583
+ * The prefix is used to create the client id which is used to identify models locally.
584
+ * You may want to override this if you're experiencing name clashes with model ids.
585
+ */
586
+ get cidPrefix(): string;
587
+ /**
588
+ * preinitialize is an empty function by default. You can override it with a function
589
+ * or object. preinitialize will run before any instantiation logic is run in the Model.
590
+ */
591
+ preinitialize(...args: any[]): void;
592
+ /**
593
+ * Initialize is an empty function by default. Override it with your own
594
+ * initialization logic.
595
+ */
596
+ initialize(attrs?: Partial<T>, options?: ModelOptions): void;
597
+ validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): string | number | null | void;
598
+ /**
599
+ * Return a hash of defaults for the model's attributes.
600
+ */
601
+ defaults(): Partial<T>;
602
+ /**
603
+ * Declare computed properties. Override in subclasses to define properties
604
+ * that derive their value from other attributes. Each entry specifies the
605
+ * attribute keys it depends on (`deps`) and a function (`fn`) that receives
606
+ * the model and returns the computed value. The value is cached and
607
+ * recalculated automatically when any dep changes, firing a `change:key`
608
+ * event.
609
+ */
610
+ get computed(): ComputedProperties<this>;
611
+ /**
612
+ * Return a copy of the model's `attributes` object.
613
+ */
614
+ toJSON(): T;
615
+ /**
616
+ * Override this if you need custom syncing semantics for *this* particular model.
617
+ */
618
+ sync(method: SyncOperation, model: Model<any>, options: Options): any;
619
+ /**
620
+ * Get the value of an attribute, or a computed property.
621
+ */
622
+ get<K extends keyof T>(attr: K): T[K];
623
+ keys(): string[];
624
+ values(): T[keyof T][];
625
+ pairs(): [keyof T, T[keyof T]][];
626
+ entries(): [keyof T, T[keyof T]][];
627
+ invert(): Record<string, keyof T>;
628
+ pick<K extends keyof T>(...args: K[]): Pick<T, K>;
629
+ omit<K extends keyof T>(...args: K[]): Omit<T, K>;
630
+ isEmpty(): boolean;
631
+ /**
632
+ * Returns `true` if the attribute contains a value that is not null
633
+ * or undefined.
634
+ */
635
+ has(attr: keyof T): boolean;
636
+ /**
637
+ * Special-cased proxy to lodash's `matches` method.
638
+ */
639
+ matches(attrs: Partial<T>): boolean;
640
+ /**
641
+ * Set a hash of model attributes on the object, firing `"change"`. This is
642
+ * the core primitive operation of a model, updating the data and notifying
643
+ * anyone who needs to know about the change in state. The heart of the beast.
644
+ */
645
+ set(key: string | Partial<T> | ObjectWithId, val?: any, options?: ModelOptions): this;
646
+ /**
647
+ * Remove an attribute from the model, firing `"change"`. `unset` is a noop
648
+ * if the attribute doesn't exist.
649
+ */
650
+ unset(attr: keyof T, options?: ModelOptions): this;
651
+ /**
652
+ * Clear all attributes on the model, firing `"change"`.
653
+ */
654
+ clear(options?: ModelOptions): this;
655
+ /**
656
+ * Determine if the model has changed since the last `"change"` event.
657
+ * If you specify an attribute name, determine if that attribute has changed.
658
+ */
659
+ hasChanged(attr?: keyof T): boolean;
660
+ /**
661
+ * Return an object containing all the attributes that have changed, or
662
+ * false if there are no changed attributes. Useful for determining what
663
+ * parts of a view need to be updated and/or what attributes need to be
664
+ * persisted to the server. Unset attributes will be set to undefined.
665
+ * You can also pass an attributes object to diff against the model,
666
+ * determining if there *would be* a change.
667
+ */
668
+ changedAttributes(diff?: Partial<T>): Partial<T> | false;
669
+ /**
670
+ * Get the previous value of an attribute, recorded at the time the last
671
+ * `"change"` event was fired.
672
+ */
673
+ previous<K extends keyof T>(attr: K): T[K] | null;
674
+ /**
675
+ * Get all of the attributes of the model at the time of the previous
676
+ * `"change"` event.
677
+ */
678
+ previousAttributes(): T | undefined;
679
+ /**
680
+ * Fetch the model from the server, merging the response with the model's
681
+ * local attributes. Any changed attributes will trigger a "change" event.
682
+ */
683
+ fetch(options?: Options): any;
684
+ /**
685
+ * Set a hash of model attributes, and sync the model to the server.
686
+ * If the server returns an attributes hash that differs, the model's
687
+ * state will be `set` again.
688
+ */
689
+ save(key?: string | null | Partial<T>, val?: any, options?: ModelOptions): any;
690
+ /**
691
+ * Destroy this model on the server if it was already persisted.
692
+ * Optimistically removes the model from its collection, if it has one.
693
+ * If `wait: true` is passed, waits for the server to respond before removal.
694
+ */
695
+ destroy(options?: ModelOptions): any;
696
+ get urlRoot(): string;
697
+ set urlRoot(root: string);
698
+ /**
699
+ * Default URL for the model's representation on the server -- if you're
700
+ * using Backbone's restful methods, override this to change the endpoint
701
+ * that will be called.
702
+ */
703
+ get url(): string;
704
+ set url(url: string);
705
+ /**
706
+ * **parse** converts a response into the hash of attributes to be `set` on
707
+ * the model. The default implementation is just to pass the response along.
708
+ */
709
+ parse(resp: any, options?: ModelOptions): Partial<T> | null | void;
710
+ /**
711
+ * A model is new if it has never been saved to the server, and lacks an id.
712
+ */
713
+ isNew(): boolean;
714
+ /**
715
+ * Check if the model is currently in a valid state.
716
+ */
717
+ isValid(options?: ModelOptions): boolean;
718
+ /**
719
+ * Subscribe to model changes. Returns an unsubscribe function.
720
+ *
721
+ * `model.subscribe(callback)` — fires on any attribute change, receives `(model, changed)`.
722
+ * `model.subscribe(event, callback)` — subscribe to a specific event (base EventEmitter form).
723
+ *
724
+ * Compatible with React's `useSyncExternalStore` and other store-style APIs.
725
+ */
726
+ subscribe(event: string, callback: EventCallback, context?: unknown): () => void;
727
+ subscribe(callback: (model: this, changed: Partial<T>) => void): () => void;
728
+ /**
729
+ * Run validation against the next complete set of model attributes,
730
+ * returning `true` if all is well. Otherwise, fire an `"invalid"` event.
731
+ */
732
+ _validate(attrs: Partial<T> | ObjectWithId, options?: ModelOptions): boolean;
733
+ }
734
+
735
+ /**
736
+ * @public
737
+ */
738
+ export declare type ModelAttributes = Record<string | number, any> & {
739
+ id?: string | number;
740
+ };
741
+
742
+ /**
743
+ * @public
744
+ */
745
+ export declare type ModelOptions = Options & {
746
+ collection?: Collection;
747
+ parse?: boolean;
748
+ unset?: boolean;
749
+ silent?: boolean;
750
+ validate?: boolean;
751
+ /** Suppress the auto-save triggered by set() on autoSync models. */
752
+ noAutoSave?: boolean;
753
+ /** Mark a set() call as originating from a storage read; suppresses auto-save. */
754
+ fromStorage?: boolean;
755
+ };
756
+
757
+ /**
758
+ * @public
759
+ */
760
+ export declare function noConflict(): any;
761
+
762
+ /**
763
+ * SQLite-backed implementation of StorageDriver.
764
+ * Uses a single table with key/value columns, storing values as JSON strings.
765
+ * @public
766
+ */
767
+ export declare class NodeSQLiteStorage implements StorageDriver {
768
+ private db;
769
+ private stmt;
770
+ ready(): Promise<void>;
771
+ constructor(name: string, storageDir?: string, inMemory?: boolean);
772
+ setItem(key: string, value: any): Promise<any>;
773
+ getItem<T>(key: string): Promise<T | null>;
774
+ removeItem(key: string): Promise<void>;
775
+ clear(): Promise<void>;
776
+ length(): Promise<number>;
777
+ key(n: number): Promise<string | null>;
778
+ keys(): Promise<string[]>;
779
+ setItems(items: Record<string, any>): Promise<Record<string, any>>;
780
+ getItems(keys: string[]): Promise<Record<string, any>>;
781
+ /**
782
+ * Close the database connection. Useful for cleanup in tests.
783
+ */
784
+ close(): void;
785
+ }
786
+
787
+ /**
788
+ * Constructor for a Node.js-only storage driver. Registered by the
789
+ * `@converse/skeletor/node` entry point via {@link PersistentStorage.nodeStorage}.
790
+ * @public
791
+ */
792
+ export declare type NodeStorageConstructor = new (name: string, storageDir?: string, inMemory?: boolean) => StorageDriver;
793
+
794
+ /**
795
+ * @public
796
+ */
797
+ export declare type ObjectListenedTo = object & {
798
+ _listenId?: string;
799
+ };
800
+
801
+ /**
802
+ * @public
803
+ */
804
+ export declare type ObjectWithId = Record<string, any> & {
805
+ id: string | number;
806
+ };
807
+
808
+ /**
809
+ * @public
810
+ */
811
+ export declare type Options = Record<string, any>;
812
+
813
+ /**
814
+ * @public
815
+ */
816
+ export declare class PersistentStorage {
817
+ storeInitialized: Promise<void>;
818
+ storeReady: boolean;
819
+ store: StorageDriver;
820
+ name: string;
821
+ static sessionStorageInitialized: Promise<void>;
822
+ static localForage: typeof localForage;
823
+ static nodeStorage: NodeStorageConstructor | null;
824
+ /**
825
+ * Directory the `'node'` store type writes its database files to. The driver's
826
+ * own default is relative, so it resolves against `process.cwd()` and a process
827
+ * started from two directories ends up with two separate sets of state. Set an
828
+ * absolute path (`$XDG_STATE_HOME/<app>`, say) to pin it. Left `null`, the
829
+ * driver's default applies.
830
+ *
831
+ * Only the `'node'` string store type reads this; passing a driver instance to
832
+ * the constructor means you've already chosen a directory yourself.
833
+ * @public
834
+ */
835
+ static nodeStorageDir: string | null;
836
+ /** Register a storage instance with a weak reference. @public */
837
+ static register(instance: PersistentStorage): void;
838
+ /**
839
+ * Flush the debounced write buffer of every registered PersistentStorage
840
+ * instance. Called automatically on pagehide/visibilitychange when autoSync
841
+ * is in use; can also be called manually.
842
+ * @public
843
+ */
844
+ static flushAll(): void;
845
+ constructor(id: string, type: StoreType | StorageDriver, batchedWrites?: boolean);
846
+ /**
847
+ * @param type - The storage type: 'local', 'session', 'indexed', 'node', or 'in_memory'
848
+ * @param batchedWrites - Whether to enable batched writes
849
+ */
850
+ initStore(type: StoreType, batchedWrites: boolean): Promise<void>;
851
+ flush(): void;
852
+ clear(): Promise<void>;
853
+ sync(): {
854
+ (method: SyncOperation, model: Model, options: SyncOptions): Promise<void>;
855
+ __name__: string;
856
+ };
857
+ removeCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
858
+ addCollectionReference(model: Model, collection: Collection | undefined): Promise<any> | undefined;
859
+ getCollectionReferenceData(model: Model): Record<string, string[]>;
860
+ save(model: Model): Promise<any>;
861
+ create(model: Model, options: SyncOptions): Promise<any>;
862
+ update(model: Model): Promise<any>;
863
+ find(model: Model): Promise<any>;
864
+ findAll(): Promise<any[]>;
865
+ destroy(model: Model, collection: Collection | undefined): Promise<Model>;
866
+ getStorageSize(): Promise<number>;
867
+ getItemName(id: string | number): string;
868
+ }
869
+
870
+ /**
871
+ * @public
872
+ */
873
+ declare const skeletor: SkeletorType;
874
+ export default skeletor;
875
+
876
+ /**
877
+ * @public
878
+ */
879
+ export declare interface SkeletorType {
880
+ Collection: typeof Collection;
881
+ EventEmitter: typeof EventEmitter;
882
+ Model: typeof Model;
883
+ sync: typeof sync;
884
+ VERSION?: string;
885
+ noConflict?: () => SkeletorType;
886
+ }
887
+
888
+ /**
889
+ * Storage driver interface for key-value persistence.
890
+ * @public
891
+ */
892
+ export declare interface StorageDriver {
893
+ ready(): Promise<void>;
894
+ setItem(key: string, value: any): Promise<any>;
895
+ getItem(key: string): Promise<any>;
896
+ removeItem(key: string): Promise<void>;
897
+ clear(): Promise<void>;
898
+ length(): Promise<number>;
899
+ key(keyIndex: number): Promise<string | null>;
900
+ keys(): Promise<string[]>;
901
+ /**
902
+ * Write several items in one go. A successful write is signalled by the
903
+ * promise settling, not by what it resolves with: drivers may resolve with
904
+ * the written items (localForage does) or with nothing, and callers must
905
+ * treat both as success.
906
+ */
907
+ setItems?(items: Record<string, any>): Promise<Record<string, any> | void>;
908
+ getItems?(keys: string[]): Promise<Record<string, any>>;
909
+ debouncedSetItems?: {
910
+ (items: Record<string, any>): Promise<Record<string, any> | void>;
911
+ flush?: () => void;
912
+ };
913
+ }
914
+
915
+ /**
916
+ * @public
917
+ */
918
+ export declare type StoreType = 'local' | 'session' | 'indexed' | 'in_memory' | 'node';
919
+
920
+ /**
921
+ * Override this function to change the manner in which Backbone persists
922
+ * models to the server. You will be passed the type of request, and the
923
+ * model in question. By default makes a `fetch()` API call
924
+ * to the model's `url()`.
925
+ *
926
+ * Some possible customizations could be:
927
+ *
928
+ * - Use `setTimeout` to batch rapid-fire updates into a single request.
929
+ * - Persist models via WebSockets instead of Ajax.
930
+ * - Persist models to browser storage
931
+ */
932
+ /**
933
+ * @public
934
+ */
935
+ export declare function sync(method: SyncOperation, model: Model | Collection<any>, options?: SyncOptions): Promise<any>;
936
+
937
+ /**
938
+ * @public
939
+ */
940
+ export declare type SyncOperation = 'create' | 'update' | 'patch' | 'delete' | 'read';
941
+
942
+ /**
943
+ * @public
944
+ */
945
+ export declare interface SyncOptions {
946
+ url?: string;
947
+ data?: any;
948
+ attrs?: any;
949
+ success?: (data?: any, options?: SyncOptions) => void;
950
+ error?: (error: any) => void;
951
+ xhr?: any;
952
+ wait?: boolean;
953
+ collection?: Collection;
954
+ }
955
+
956
+ export { }