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