-
Notifications
You must be signed in to change notification settings - Fork 72
/
types.d.ts
4595 lines (4074 loc) · 145 KB
/
types.d.ts
1
2
3
4
5
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
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
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
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Creates an always-sorted multi-key bucket that allows ForerunnerDB to
* know the index that a document will occupy in an array with minimal
* processing, speeding up things like sorted views.
* @param {Object} orderBy An order object.
* @class
*/
declare class ActiveBucket {
/**
* Creates an always-sorted multi-key bucket that allows ForerunnerDB to
* know the index that a document will occupy in an array with minimal
* processing, speeding up things like sorted views.
* @param {Object} orderBy An order object.
* @class
*/
constructor(orderBy: Object);
/**
* Quicksorts a single document into the passed array and
* returns the index that the document should occupy.
* @param {Object} obj The document to calculate index for.
* @param {Array} arr The array the document index will be
* calculated for.
* @param {String} item The string key representation of the
* document whose index is being calculated.
* @param {Function} fn The comparison function that is used
* to determine if a document is sorted below or above the
* document we are calculating the index for.
* @returns {Number} The index the document should occupy.
*/
qs(obj: Object, arr: Array, item: String, fn: (() => any)): Number;
/**
* Calculates the sort position of an item against another item.
* @param {Object} sorter An object or instance that contains
* sortAsc and sortDesc methods.
* @param {Object} obj The document to compare.
* @param {String} a The first key to compare.
* @param {String} b The second key to compare.
* @returns {Number} Either 1 for sort a after b or -1 to sort
* a before b.
* @private
*/
private _sortFunc(sorter: Object, obj: Object, a: String, b: String): Number;
/**
* Inserts a document into the active bucket.
* @param {Object} obj The document to insert.
* @returns {Number} The index the document now occupies.
*/
insert(obj: Object): Number;
/**
* Removes a document from the active bucket.
* @param {Object} obj The document to remove.
* @returns {boolean} True if the document was removed
* successfully or false if it wasn't found in the active
* bucket.
*/
remove(obj: Object): boolean;
/**
* Get the index that the passed document currently occupies
* or the index it will occupy if added to the active bucket.
* @param {Object} obj The document to get the index for.
* @returns {Number} The index.
*/
index(obj: Object): Number;
/**
* The key that represents the passed document.
* @param {Object} obj The document to get the key for.
* @returns {String} The document key.
*/
documentKey(obj: Object): String;
/**
* Get the number of documents currently indexed in the active
* bucket instance.
* @returns {Number} The number of documents.
*/
count(): Number;
}
/**
* Provides angular scope updating functionality to ForerunnerDB. Allows
* collections and views to provide data to angular and to automatically
* update angular when data in ForerunnerDB changes.
* @class Angular
*/
declare class Angular {
/**
* Provides angular scope updating functionality to ForerunnerDB. Allows
* collections and views to provide data to angular and to automatically
* update angular when data in ForerunnerDB changes.
* @class Angular
*/
constructor();
/**
* Extends the Collection class with new binding capabilities.
* @extends Collection
* @param {Collection} Module The Collection class module.
* @private
*/
private static extendCollection(Module: Collection): void;
/**
* Extends the View class with new binding capabilities.
* @extends View
* @param {View} Module The View class module.
* @private
*/
private static extendView(Module: View): void;
/**
* Extends the Overview class with new binding capabilities.
* @extends Overview
* @param {Overview} Module The Overview class module.
* @private
*/
private static extendOverview(Module: Overview): void;
}
/**
* Provides data-binding functionality to ForerunnerDB. Allows collections
* and views to link to selectors and automatically generate DOM elements
* from jsViews (jsRender) templates.
* @class AutoBind
*/
declare class AutoBind {
/**
* Provides data-binding functionality to ForerunnerDB. Allows collections
* and views to link to selectors and automatically generate DOM elements
* from jsViews (jsRender) templates.
* @class AutoBind
*/
constructor();
/**
* Extends the Collection class with new binding capabilities.
* @extends Collection
* @param {Collection} Module The Collection class module.
* @private
*/
private static extendCollection(Module: Collection): void;
/**
* Extends the View class with new binding capabilities.
* @extends View
* @param {View} Module The View class module.
* @private
*/
private static extendView(Module: View): void;
/**
* Extends the Overview class with new binding capabilities.
* @extends Overview
* @param {Overview} Module The Overview class module.
* @private
*/
private static extendOverview(Module: Overview): void;
/**
* Extends the Document class with new binding capabilities.
* @extends Document
* @param {Document} Module The Document class module.
* @private
*/
private static extendDocument(Module: Document): void;
}
/**
* Creates a new collection. Collections store multiple documents and
* handle CRUD against those documents.
* @constructor
* @class
*/
declare class Collection {
/**
* Creates a new collection. Collections store multiple documents and
* handle CRUD against those documents.
* @constructor
* @class
*/
constructor();
/**
* Creates a link to the DOM between the collection data and the elements
* in the passed output selector. When new elements are needed or changes
* occur the passed templateSelector is used to get the template that is
* output to the DOM.
* @func link
* @memberof Collection
* @param scope
* @param varName
* @param {Object=} options Optional extra options.
* @see unlink
*/
static link(scope: any, varName: any, options?: Object): void;
/**
* Checks if the instance is data-bound to any DOM elements.
* @func isLinked
* @memberof Collection
* @returns {Boolean} True if linked, false if not.
*/
static isLinked(): Boolean;
/**
* Removes a link to the DOM between the collection data and the elements
* in the passed output selector that was created using the link() method.
* @func unlink
* @memberof Collection
* @param outputTargetSelector
* @param templateSelector
*/
static unlink(outputTargetSelector: any, templateSelector: any): void;
/**
* Creates a new collection. Collections store multiple documents and
* handle CRUD against those documents.
*/
init(): void;
/**
* Adds a job id to the async queue to signal to other parts
* of the application that some async work is currently being
* done.
* @param {String} key The id of the async job.
* @private
*/
private _asyncPending(key: String): void;
/**
* Removes a job id from the async queue to signal to other
* parts of the application that some async work has been
* completed. If no further async jobs exist on the queue then
* the "ready" event is emitted from this collection instance.
* @param {String} key The id of the async job.
* @private
*/
private _asyncComplete(key: String): void;
/**
* Get the data array that represents the collection's data.
* This data is returned by reference and should not be altered outside
* of the provided CRUD functionality of the collection as doing so
* may cause unstable index behaviour within the collection.
* @returns {Array}
*/
data(): Array;
/**
* Drops a collection and all it's stored data from the database.
* @param {Function=} callback A callback method to call once the
* operation has completed.
* @returns {boolean} True on success, false on failure.
*/
drop(callback?: (() => any)): boolean;
/**
* Gets / sets the primary key for this collection.
* @param {String=} keyName The name of the primary key.
* @returns {*}
*/
primaryKey(keyName?: String): any;
/**
* Handles insert events and routes changes to binds and views as required.
* @param {Array} inserted An array of inserted documents.
* @param {Array} failed An array of documents that failed to insert.
* @private
*/
private _onInsert(inserted: Array, failed: Array): void;
/**
* Handles update events and routes changes to binds and views as required.
* @param {Array} items An array of updated documents.
* @private
*/
private _onUpdate(items: Array): void;
/**
* Handles remove events and routes changes to binds and views as required.
* @param {Array} items An array of removed documents.
* @private
*/
private _onRemove(items: Array): void;
/**
* Handles any change to the collection by updating the
* lastChange timestamp on the collection's metaData. This
* only happens if the changeTimestamp option is enabled
* on the collection (it is disabled by default).
* @private
*/
private _onChange(): void;
/**
* Sets the collection's data to the array / documents passed. If any
* data already exists in the collection it will be removed before the
* new data is set via the remove() method, and the remove event will
* fire as well.
* @name setData
* @method Collection.setData
* @param {Array|Object} data The array of documents or a single document
* that will be set as the collections data.
*/
static setData(data: (Array|Object)): void;
/**
* Drops and rebuilds the primary key index for all documents
* in the collection.
* @param {Object=} options An optional options object.
* @private
*/
private rebuildPrimaryKeyIndex(options?: Object): void;
/**
* Checks for a primary key on the document and assigns one if none
* currently exists.
* @param {Object} obj The object to check a primary key against.
* @private
*/
private ensurePrimaryKey(obj: Object): void;
/**
* Clears all data from the collection.
* @returns {Collection}
*/
truncate(): Collection;
/**
* Inserts a new document or updates an existing document in a
* collection depending on if a matching primary key exists in
* the collection already or not.
*
* If the document contains a primary key field (based on the
* collections's primary key) then the database will search for
* an existing document with a matching id. If a matching
* document is found, the document will be updated. Any keys that
* match keys on the existing document will be overwritten with
* new data. Any keys that do not currently exist on the document
* will be added to the document.
*
* If the document does not contain an id or the id passed does
* not match an existing document, an insert is performed instead.
* If no id is present a new primary key id is provided for the
* document and the document is inserted.
*
* @param {Object} obj The document object to upsert or an array
* containing documents to upsert.
* @param {Function=} callback Optional callback method.
* @returns {Object} An object containing two keys, "op" contains
* either "insert" or "update" depending on the type of operation
* that was performed and "result" contains the return data from
* the operation used.
*/
upsert(obj: Object, callback?: (() => any)): Object;
/**
* Executes a method against each document that matches query and returns an
* array of documents that may have been modified by the method.
* @param {Object} query The query object.
* @param {Function} func The method that each document is passed to. If this method
* returns false for a particular document it is excluded from the results.
* @param {Object=} options Optional options object.
* @returns {Array}
*/
filter(query: Object, func: (() => any), options?: Object): Array;
/**
* Executes a method against each document that matches query and then executes
* an update based on the return data of the method.
* @param {Object} query The query object.
* @param {Function} func The method that each document is passed to. If this method
* returns false for a particular document it is excluded from the update.
* @param {Object=} options Optional options object passed to the initial find call.
* @returns {Array}
*/
filterUpdate(query: Object, func: (() => any), options?: Object): Array;
/**
* Modifies an existing document or documents in a collection.
* This will update all matches for 'query' with the data held
* in 'update'. It will not overwrite the matched documents
* with the update document.
*
* @param {Object} query The query that must be matched for a
* document to be operated on.
* @param {Object} update The object containing updated
* key/values. Any keys that match keys on the existing document
* will be overwritten with this data. Any keys that do not
* currently exist on the document will be added to the document.
* @param {Object=} options An options object.
* @param {Function=} callback The callback method to call when
* the update is complete.
* @returns {Array} The items that were updated.
*/
update(query: Object, update: Object, options?: Object, callback?: (() => any)): Array;
/**
* Handles the update operation that was initiated by a call to update().
* @param {Object} query The query that must be matched for a
* document to be operated on.
* @param {Object} update The object containing updated
* key/values. Any keys that match keys on the existing document
* will be overwritten with this data. Any keys that do not
* currently exist on the document will be added to the document.
* @param {Object=} options An options object.
* @param {Function=} callback The callback method to call when
* the update is complete.
* @returns {Array} The items that were updated.
* @private
*/
private _handleUpdate(query: Object, update: Object, options?: Object, callback?: (() => any)): Array;
/**
* Replaces an existing object with data from the new object without
* breaking data references. It does this by removing existing keys
* from the base object and then adding the passed object's keys to
* the existing base object, thereby maintaining any references to
* the existing base object but effectively replacing the object with
* the new one.
* @param {Object} currentObj The base object to alter.
* @param {Object} newObj The new object to overwrite the existing one
* with.
* @returns {*} Chain.
* @private
*/
private _replaceObj(currentObj: Object, newObj: Object): any;
/**
* Helper method to update a document via it's id.
* @param {String} id The id of the document.
* @param {Object} update The object containing the key/values to
* update to.
* @param {Object=} options An options object.
* @param {Function=} callback The callback method to call when
* the update is complete.
* @returns {Object} The document that was updated or undefined
* if no document was updated.
*/
updateById(id: String, update: Object, options?: Object, callback?: (() => any)): Object;
/**
* Internal method for document updating.
* @param {Object} doc The document to update.
* @param {Object} update The object with key/value pairs to update
* the document with.
* @param {Object} query The query object that we need to match to
* perform an update.
* @param {Object} options An options object.
* @param {String} path The current recursive path.
* @param {String} opType The type of update operation to perform,
* if none is specified default is to set new data against matching
* fields.
* @returns {Boolean} True if the document was updated with new /
* changed data or false if it was not updated because the data was
* the same.
* @private
*/
private updateObject(doc: Object, update: Object, query: Object, options: Object, path: String, opType: String): Boolean;
/**
* Determines if the passed key has an array positional mark
* (a dollar at the end of its name).
* @param {String} key The key to check.
* @returns {Boolean} True if it is a positional or false if not.
* @private
*/
private _isPositionalKey(key: String): Boolean;
/**
* Removes any documents from the collection that match the search
* query key/values.
* @param {Object=} query The query identifying the documents to remove. If no
* query object is passed, all documents will be removed from the collection.
* @param {Object=} options An options object.
* @param {Function=} callback A callback method.
* @returns {Array} An array of the documents that were removed.
*/
remove(query?: Object, options?: Object, callback?: (() => any)): Array;
/**
* Helper method that removes a document that matches the given id.
* @param {String} id The id of the document to remove.
* @returns {Object} The document that was removed or undefined if
* nothing was removed.
*/
removeById(id: String): Object;
/**
* Processes a deferred action queue.
* @param {String} type The queue name to process.
* @param {Function} callback A method to call when the queue has processed.
* @param {Object=} resultObj A temp object to hold results in.
*/
processQueue(type: String, callback: (() => any), resultObj?: Object): void;
/**
* Checks if any CRUD operations have been deferred and are still waiting to
* be processed.
* @returns {Boolean} True if there are still deferred CRUD operations to process
* or false if all queues are clear.
*/
isProcessingQueue(): Boolean;
/**
* Inserts a document or array of documents into the collection.
* @param {Object|Array} data Either a document object or array of document
* @param {Number=} index Optional index to insert the record at.
* @param {Collection.insertCallback=} callback Optional callback called
* once the insert is complete.
*/
insert(data: (Object|Array), index?: Number, callback?: Collection.insertCallback): void;
/**
* The insert operation's callback.
* @name Collection.insertCallback
* @callback Collection.insertCallback
* @param {Object} result The result object will contain two arrays (inserted
* and failed) which represent the documents that did get inserted and those
* that didn't for some reason (usually index violation). Failed items also
* contain a reason. Inspect the failed array for further information.
*
* A third field called "deferred" is a boolean value to indicate if the
* insert operation was deferred across more than one CPU cycle (to avoid
* blocking the main thread).
*/
type insertCallback = (result: Object) => void;
/**
* Inserts a document or array of documents into the collection.
* @param {Object|Array} data Either a document object or array of document
* @param {Number=} index Optional index to insert the record at.
* @param {Collection.insertCallback=} callback Optional callback called
* once the insert is complete.
*/
_insertHandle(data: (Object|Array), index?: Number, callback?: Collection.insertCallback): void;
/**
* Internal method to insert a document into the collection. Will
* check for index violations before allowing the document to be inserted.
* @param {Object} doc The document to insert after passing index violation
* tests.
* @param {Number=} index Optional index to insert the document at.
* @returns {Boolean|Object} True on success, false if no document passed,
* or an object containing details about an index violation if one occurred.
* @private
*/
private _insert(doc: Object, index?: Number): (Boolean|Object);
/**
* Inserts a document into the internal collection data array at
* Inserts a document into the internal collection data array at
* the specified index.
* @param {Number} index The index to insert at.
* @param {Object} doc The document to insert.
* @private
*/
private _dataInsertAtIndex(index: Number, doc: Object): void;
/**
* Removes a document from the internal collection data array at
* the specified index.
* @param {Number} index The index to remove from.
* @private
*/
private _dataRemoveAtIndex(index: Number): void;
/**
* Replaces all data in the collection's internal data array with
* the passed array of data.
* @param {Array} data The array of data to replace existing data with.
* @private
*/
private _dataReplace(data: Array): void;
/**
* Inserts a document into the collection indexes.
* @param {Object} doc The document to insert.
* @private
*/
private _insertIntoIndexes(doc: Object): void;
/**
* Removes a document from the collection indexes.
* @param {Object} doc The document to remove.
* @private
*/
private _removeFromIndexes(doc: Object): void;
/**
* Updates collection index data for the passed document.
* @param {Object} oldDoc The old document as it was before the update (must be
* actual reference to original document).
* @param {Object} newDoc The document as it now is after the update.
* @private
*/
private _updateIndexes(oldDoc: Object, newDoc: Object): void;
/**
* Rebuild collection indexes.
* @private
*/
private _rebuildIndexes(): void;
/**
* Uses the passed query to generate a new collection with results
* matching the query parameters.
*
* @param {Object} query The query object to generate the subset with.
* @param {Object=} options An options object.
* @returns {*}
*/
subset(query: Object, options?: Object): any;
/**
* Checks if the collection is a subset of the passed collection.
* @param {Collection} collection The collection to test against.
* @returns {Boolean} True if the passed collection is the parent of
* the current collection.
*/
isSubsetOf(collection: Collection): Boolean;
/**
* Find the distinct values for a specified field across a single collection and
* returns the results in an array.
* @param {String} key The field path to return distinct values for e.g. "person.name".
* @param {Object=} query The query to use to filter the documents used to return values from.
* @param {Object=} options The query options to use when running the query.
* @returns {Array}
*/
distinct(key: String, query?: Object, options?: Object): Array;
/**
* Helper method to find a document by it's id.
* @param {String} id The id of the document.
* @param {Object=} options The options object, allowed keys are sort and limit.
* @returns {Array} The items that were updated.
*/
findById(id: String, options?: Object): Array;
/**
* Finds all documents that contain the passed string or search object
* regardless of where the string might occur within the document. This
* will match strings from the start, middle or end of the document's
* string (partial match).
* @param {String} search The string to search for. Case sensitive.
* @param {Object=} options A standard find() options object.
* @returns {Array} An array of documents that matched the search string.
*/
peek(search: String, options?: Object): Array;
/**
* Provides a query plan / operations log for a query.
* @param {Object} query The query to execute.
* @param {Object=} options Optional options object.
* @returns {Object} The query plan.
*/
explain(query: Object, options?: Object): Object;
/**
* Generates an options object with default values or adds default
* values to a passed object if those values are not currently set
* to anything.
* @param {Object=} obj Optional options object to modify.
* @returns {Object} The options object.
*/
options(obj?: Object): Object;
/**
* Queries the collection based on the query object passed.
* @param {Object} query The query key/values that a document must match in
* order for it to be returned in the result array.
* @param {Object=} options An optional options object.
* @param {Function=} callback !! DO NOT USE, THIS IS NON-OPERATIONAL !!
* Optional callback. If specified the find process
* will not return a value and will assume that you wish to operate under an
* async mode. This will break up large find requests into smaller chunks and
* process them in a non-blocking fashion allowing large datasets to be queried
* without causing the browser UI to pause. Results from this type of operation
* will be passed back to the callback once completed.
*
* @returns {Array} The results array from the find operation, containing all
* documents that matched the query.
*/
find(query: Object, options?: Object, callback?: (() => any)): Array;
/**
* Returns one document that satisfies the specified query criteria. If multiple
* documents satisfy the query, this method returns the first document to match
* the query.
* @returns {*}
*/
findOne(): any;
/**
* Gets the index in the collection data array of the first item matched by
* the passed query object.
* @param {Object} query The query to run to find the item to return the index of.
* @param {Object=} options An options object.
* @returns {Number}
*/
indexOf(query: Object, options?: Object): Number;
/**
* Returns the index of the document identified by the passed item's primary key.
* @param {*} itemLookup The document whose primary key should be used to lookup
* or the id to lookup.
* @param {Object=} options An options object.
* @returns {Number} The index the item with the matching primary key is occupying.
*/
indexOfDocById(itemLookup: any, options?: Object): Number;
/**
* Removes a document from the collection by it's index in the collection's
* data array.
* @param {Number} index The index of the document to remove.
* @returns {Object} The document that has been removed or false if none was
* removed.
*/
removeByIndex(index: Number): Object;
/**
* Gets / sets the collection transform options.
* @param {Object} obj A collection transform options object.
* @returns {*}
*/
transform(obj: Object): any;
/**
* Transforms data using the set transformIn method.
* @param {Object} data The data to transform.
* @returns {*}
*/
transformIn(data: Object): any;
/**
* Transforms data using the set transformOut method.
* @param {Object} data The data to transform.
* @returns {*}
*/
transformOut(data: Object): any;
/**
* Sorts an array of documents by the given sort path.
* @param {*} sortObj The keys and orders the array objects should be sorted by.
* @param {Array} arr The array of documents to sort.
* @returns {Array}
*/
sort(sortObj: any, arr: Array): Array;
/**
* Groups an array of documents into multiple array fields, named by the value
* of the given group path.
* @param {*} groupObj The key path the array objects should be grouped by.
* @param {Array} arr The array of documents to group.
* @returns {Object}
*/
group(groupObj: any, arr: Array): Object;
/**
* Sorts array by individual sort path.
* @param {String} key The path to sort by.
* @param {Array} arr The array of objects to sort.
* @returns {Array|*}
* @private
*/
private _sort(key: String, arr: Array): (Array|any);
/**
* Internal method that takes a search query and options and
* returns an object containing details about the query which
* can be used to optimise the search.
*
* @param {Object} query The search query to analyse.
* @param {Object} options The query options object.
* @param {Operation} op The instance of the Operation class that
* this operation is using to track things like performance and steps
* taken etc.
* @returns {Object}
* @private
*/
private _analyseQuery(query: Object, options: Object, op: Operation): Object;
/**
* Checks if the passed query references a source object (such
* as a collection) by name.
* @param {Object} query The query object to scan.
* @param {String} sourceName The source name to scan for in the query.
* @param {String=} path The path to scan from.
* @returns {*}
* @private
*/
private _queryReferencesSource(query: Object, sourceName: String, path?: String): any;
/**
* Returns the number of documents currently in the collection.
* @returns {Number}
*/
count(): Number;
/**
* Finds sub-documents from the collection's documents.
* @param {Object} match The query object to use when matching
* parent documents from which the sub-documents are queried.
* @param {String} path The path string used to identify the
* key in which sub-documents are stored in parent documents.
* @param {Object=} subDocQuery The query to use when matching
* which sub-documents to return.
* @param {Object=} subDocOptions The options object to use
* when querying for sub-documents.
* @returns {*}
*/
findSub(match: Object, path: String, subDocQuery?: Object, subDocOptions?: Object): any;
/**
* Finds the first sub-document from the collection's documents
* that matches the subDocQuery parameter.
* @param {Object} match The query object to use when matching
* parent documents from which the sub-documents are queried.
* @param {String} path The path string used to identify the
* key in which sub-documents are stored in parent documents.
* @param {Object=} subDocQuery The query to use when matching
* which sub-documents to return.
* @param {Object=} subDocOptions The options object to use
* when querying for sub-documents.
* @returns {Object}
*/
findSubOne(match: Object, path: String, subDocQuery?: Object, subDocOptions?: Object): Object;
/**
* Checks that the passed document will not violate any index rules if
* inserted into the collection.
* @param {Object} doc The document to check indexes against.
* @returns {Boolean} Either false (no violation occurred) or true if
* a violation was detected.
*/
insertIndexViolation(doc: Object): Boolean;
/**
* Creates an index on the specified keys.
* @param {Object} keys The object containing keys to index.
* @param {Object} options An options object.
* @returns {*}
*/
ensureIndex(keys: Object, options: Object): any;
/**
* Gets an index by it's name.
* @param {String} name The name of the index to retreive.
* @returns {*}
*/
index(name: String): any;
/**
* Gets the last reporting operation's details such as run time.
* @returns {Object}
*/
lastOp(): Object;
/**
* Generates a difference object that contains insert, update and remove arrays
* representing the operations to execute to make this collection have the same
* data as the one passed.
* @param {Collection} collection The collection to diff against.
* @returns {{}}
*/
diff(collection: Collection): Object;
/**
* Adds a data source to collate data from and specifies the
* key name to collate data to.
* @func collateAdd
* @memberof Collection
* @param {Collection} collection The collection to collate data from.
* @param {String=} keyName Optional name of the key to collate data to.
* If none is provided the record CRUD is operated on the root collection
* data.
*/
static collateAdd(collection: Collection, keyName?: String): void;
/**
* Creates a condition handler that will react to changes in data on the
* collection.
* @example Create a condition handler that reacts when data changes.
* var coll = db.collection('test'),
* condition = coll.when({_id: 'test1', val: 1})
* .then(function () {
* console.log('Condition met!');
* })
* .else(function () {
* console.log('Condition un-met');
* });
*
* coll.insert({_id: 'test1', val: 1});
*
* @see Condition
* @param {Object} query The query that will trigger the condition's then()
* callback.
* @returns {Condition}
*/
when(query: Object): Condition;
/**
* Creates a grid and assigns the collection as its data source.
* @func grid
* @memberof Collection
* @param {String} selector jQuery selector of grid output target.
* @param {String} template The table template to use when rendering the grid.
* @param {Object=} options The options object to apply to the grid.
* @returns {*}
*/
static grid(selector: String, template: String, options?: Object): any;
/**
* Removes a grid safely from the DOM. Must be called when grid is
* no longer required / is being removed from DOM otherwise references
* will stick around and cause memory leaks.
* @func unGrid
* @memberof Collection
* @param {String} selector jQuery selector of grid output target.
* @param {String} template The table template to use when rendering the grid.
* @param {Object=} options The options object to apply to the grid.
* @returns {*}
*/
static unGrid(selector: String, template: String, options?: Object): any;
/**
* Adds a grid to the internal grid lookup.
* @func _addGrid
* @memberof Collection
* @param {Grid} grid The grid to add.
* @returns {Collection}
* @private
*/
private static _addGrid(grid: Grid): Collection;
/**
* Removes a grid from the internal grid lookup.
* @func _removeGrid
* @memberof Collection
* @param {Grid} grid The grid to remove.
* @returns {Collection}
* @private
*/
private static _removeGrid(grid: Grid): Collection;
/**
* Creates a pie chart from the collection.
* @type {Overload}
*/
pieChart: Overload;
/**
* Creates a line chart from the collection.
* @type {Overload}
*/
lineChart: Overload;
/**
* Creates an area chart from the collection.
* @type {Overload}
*/
areaChart: Overload;
/**
* Creates a column chart from the collection.
* @type {Overload}
*/
columnChart: Overload;
/**
* Creates a bar chart from the collection.
* @type {Overload}
*/
barChart: Overload;
/**
* Creates a stacked bar chart from the collection.
* @type {Overload}
*/
stackedBarChart: Overload;
/**
* Removes a chart from the page by it's selector.
* @memberof Collection
* @param {String} selector The chart selector.
*/
dropChart(selector: String): void;
/**
* Sync with this collection on the server-side.
* @name sync