This repository was archived by the owner on Feb 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrethinkdb.d.ts
3476 lines (3329 loc) · 141 KB
/
rethinkdb.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
// Type definitions for RethinkDB v2.2.0
// Project: http://rethinkdb.com/
// Definitions by: Bazyli Brzóska <https://invent.life/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Reference: http://www.rethinkdb.com/api/#js
// Previous definitions by: Sean Hess <https://seanhess.github.io/>
declare namespace rethinkdb {
export interface RSequence<RemoteT> extends
RAny,
RCoercable,
RToJSON,
r.avg<RemoteT>,
r.contains<RemoteT>,
r.count.sequence<RemoteT>,
r.default_<RemoteT>,
r.forEach<RemoteT>,
r.group<RemoteT>,
r.isEmpty,
r.limit,
r.max<RemoteT>,
r.min<RemoteT>,
r.nth.sequence,
r.offsetsOf<RemoteT>,
r.reduce<RemoteT>,
r.slice,
r.sum<RemoteT>,
r.union
{}
export interface RSequenceArray<RemoteT> extends
RSequence<RemoteT>,
RRunable<Array<RemoteT>>,
r.bracketsGetByIndex<RValue<RemoteT>>, // TODO: sure?
r.bracketsPluckSequence,
r.concatMap.array<RemoteT>,
r.eqJoin.array<RemoteT>,
r.filter<RemoteT>,
r.distinct<RArray<RemoteT>>,
r.hasFields<RArray<RemoteT>>,
r.innerJoin.array<RemoteT>,
r.merge.array<RemoteT>,
r.orderBy<RemoteT, RArray<RemoteT>>,
r.outerJoin.array<RemoteT>,
r.pluck.array,
r.without.array,
r.sample<RArray<RemoteT>>,
r.skip<RArray<RemoteT>>,
r.withFields<RArray<RemoteT>>
{}
export interface RArray<RemoteT> extends
RSequenceArray<RemoteT>,
r.add<r.arrayLike<RemoteT>, RArray<RemoteT>>,
r.append<RemoteT>,
r.changeAt<RemoteT>,
r.deleteAt<RemoteT>,
r.difference<RemoteT>,
r.insertAt<RemoteT>,
r.map.array<RemoteT>,
r.mul<RArray<RemoteT>>,
r.prepend<RemoteT>,
r.setDifference<RemoteT>,
r.setInsert<RemoteT>,
r.setIntersection<RemoteT>,
r.setUnion<RemoteT>,
r.spliceAt<RemoteT>
{}
export interface RArrayJoin<TLeft, TRight> extends
RArray<{ left:TLeft, right:TRight }>,
r.zip<RArray<TLeft & TRight>>
{}
export interface RSequenceStream<RemoteT> extends
RSequence<RemoteT>,
RRunable<RCursor<RemoteT>>,
r.bracketsGetByIndex<RStream<RemoteT>>,
r.concatMap.stream<RemoteT>,
r.eqJoin.stream<RemoteT>,
r.filter<RemoteT>,
r.getField.stream,
r.hasFields<RStream<RemoteT>>,
r.includes.stream,
r.innerJoin.stream<RemoteT>,
r.intersects.stream,
r.map.stream<RemoteT>,
r.merge.stream<RemoteT>,
r.outerJoin.sequence<RemoteT>,
r.without.sequence,
r.pluck.sequence,
r.sample<RSelection<RemoteT>>,
r.skip<RStream<RemoteT>>,
r.withFields<RStream<RemoteT>>
{}
export interface RStream<RemoteT> extends
RObservable<RemoteT>,
RSequenceStream<RemoteT>,
r.distinct.sequence<RemoteT>,
r.orderBy<RemoteT, RSequence<RemoteT>>
// note: distinct and orderBy is defined in RStream,
// because table is a type of a stream that has a different signature for those two
// TODO: check if `sample` return type is correct
{}
export interface RStreamJoin<TLeft, TRight> extends
RStream<JoinResult<TLeft, TRight>>,
r.zip<RStream<TLeft & TRight>>
{}
export interface RSelection<RemoteT> extends
RStream<RemoteT>,
ROperations<RemoteT>
{}
export interface RValue<RemoteT> extends
RAny,
RCoercable,
RRunable<RemoteT>,
RToJSON,
r.default_<RemoteT>,
r.operators<RemoteT>
{}
export interface RBool extends
RValue<boolean>,
r.and, r.not, r.or
{}
export interface RNumber extends
RValue<number>,
r.add<r.numberLike, RNumber>,
r.ceil,
r.div,
r.floor,
r.mod,
r.mul<RNumber>,
r.round,
r.sub<r.numberLike, RNumber>
{}
export interface RString extends
RValue<string>,
r.add<r.stringLike, RString>,
r.downcase,
r.match,
r.split,
r.upcase
{}
export interface RTime extends
RValue<Date>,
r.add<r.dateLike, RTime>,
r.sub<r.dateLike, RTime>,
r.date, r.dayOfWeek, r.dayOfYear,
r.during, r.inTimezone,
r.seconds, r.minutes, r.hours, r.month, r.year, r.day,
r.timeOfDay, r.timezone, r.toEpochTime, r.toISO8601
{}
export interface RSpecial extends
RAny
{}
export interface RObject<RemoteT> extends
RAny,
RRunable<RemoteT>,
RGetField,
RToJSON,
RCoercable,
r.hasFields<RBool>,
r.merge.object<RemoteT>,
r.pluck.object,
r.without.object,
r.default_<RemoteT>
{
/**
* Return an array containing all of an object's keys. Note that the keys will be sorted as described in [ReQL data types](/docs/data-types/#sorting-order) (for strings, lexicographically).
*
* singleSelection.keys() → array
* object.keys() → array
* **Example:** Get all the keys from a table row.
*
* // row: { id: 1, mail: "[email protected]", name: "fred" }
*
* r.table('users').get(1).keys().run(conn, callback);
* // Result passed to callback
* [ "id", "mail", "name" ]
*
* http://rethinkdb.com/api/javascript/keys
*/
keys(): RArray<string>;
/**
* # Command syntax
*
* Return an array containing all of an object's values. `values()` guarantees the values will come out in the same order as [keys](/api/javascript/keys).
*
* singleSelection.values() → array
* object.values() → array
* **Example:** Get all of the values from a table row.
*
* // row: { id: 1, mail: "[email protected]", name: "fred" }
*
* r.table('users').get(1).values().run(conn, callback);
* // Result passed to callback
* [ 1, "[email protected]", "fred" ]
*
* http://rethinkdb.com/api/javascript/values
*/
values(): RArray<RemoteT>;
}
export interface RSingleSelection<RemoteT> extends
RObject<RemoteT>,
RValue<RemoteT>,
ROperations<RemoteT>,
RObservable<RemoteT>
//RSelection<RemoteT> // HACK: UNABLE TO EXTEND, SO DUPLICATED FROM SELECTION INTERFACE
{}
export interface RAny {
/**
* Call an anonymous function using return values from other ReQL commands or queries as arguments.
*
* **Example:** Compute a golfer's net score for a game.
*
* `js r.table('players').get('f19b5f16-ef14-468f-bd48-e194761df255').do( function (player) { return player('gross_score').sub(player('course_handicap')); } ).run(conn, callback);`
*
* any.do(function) → anyr.do([args]*, function) → anyany.do(expr) → anyr.do([args]*, expr) → any
*
*
* http://rethinkdb.com/api/javascript/do
*/
// do<R extends RAny>(...args_and_then_a_function):R;
do<R extends RAny>(expr:(thisObject:RAny) => R): R;
do<R extends RAny, Arg1 extends RAny>(arg1:Arg1, expr:(arg1:Arg1) => R): R;
do<R extends RAny, Arg1 extends RAny, Arg2 extends RAny>(arg1:Arg1, arg2:Arg2, expr:(arg1:Arg1, arg2:Arg2) => R): R;
do<R extends RAny, Arg1 extends RAny, Arg2 extends RAny, Arg3 extends RAny>(arg1:Arg1, arg2:Arg2, arg3:Arg3, expr:(arg1:Arg1, arg2:Arg2, arg3:Arg3) => R): R;
/**
* Get information about a ReQL value.
*
* any.info() → object
* r.info(any) → object
* **Example:** Get information about a table such as primary key, or cache size.
*
* r.table('marvel').info().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/info
*/
info(): RObject<any>;
// TODO: write proper object output
/**
* Gets the type of a value.
*
* any.typeOf() → string
* **Example:** Get the type of a string.
*
* r.expr("foo").typeOf().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/type_of
*/
typeOf(): RString;
}
type IndexFunction<T> = RValue<any>|Array<RValue<any>>|((item:RValue<T> | RObject<T>)=>RValue<any>);
type KeyType = r.stringLike|r.numberLike|r.arrayLike<string|number>|r.dateLike;
interface IndexOptions {
index?: string;
leftBound?: 'closed' | 'open';
rightBound?: 'closed' | 'open';
}
export interface RTable<RemoteT> extends
RSequenceStream<RemoteT>, RObservable<RemoteT>, // instead of RSelection<RemoteT>,
ROperations<RemoteT>,
RConfigurable,
r.distinct.table<RemoteT>,
r.orderBy<RemoteT, RTableSlice<RemoteT>>
{
/**
* Get all documents between two keys. Accepts three optional arguments: `index`, `left_bound`, and `right_bound`. If `index` is set to the name of a secondary index, `between` will return all documents where that index's value is in the specified range (it uses the primary key by default). `left_bound` or `right_bound` may be set to `open` or `closed` to indicate whether or not to include that endpoint of the range (by default, `left_bound` is closed and `right_bound` is open).
*
* table.between(lowerKey, upperKey[, options]) → table_slice
* table_slice.between(lowerKey, upperKey[, options]) → table_slice
* **Example:** Find all users with primary key >= 10 and < 20 (a normal half-open interval).
*
* r.table('marvel').between(10, 20).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/between
*/
between(lowerKey:KeyType, upperKey:KeyType, options?:IndexOptions): RTableSlice<RemoteT>;
/**
* Get a document by primary key.
*
* If no document exists with that primary key, `get` will return `null`.
*
* table.get(key) → singleRowSelection
* **Example:** Find a document by UUID.
*
* r.table('posts').get('a9849eef-7176-4411-935b-79a6e3c56a74').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/get
*/
get(key:KeyType): RSingleSelection<RemoteT>;
/**
* Get all documents where the given value matches the value of the requested index.
*
* table.getAll(key[, key2...], [, {index:'id'}]) → selection
* **Example:** Secondary index keys are not guaranteed to be unique so we cannot query via [get](/api/javascript/get/) when using a secondary index.
*
* r.table('marvel').getAll('man_of_steel', {index:'code_name'}).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/get_all
*/
getAll(key:KeyType, ...keys_and_then_options:Array<KeyType | { index?:string }>): RSelection<RemoteT>;
getAll(key:KeyType, options?:{ index:string }): RSelection<RemoteT>;
getAll(key:KeyType, ...keys:Array<KeyType>): RSelection<RemoteT>;
getAll(range:Array<KeyType>, options?:{ index:string }): RSelection<RemoteT>;
getAll(args:RSpecial, options?:{ index:string }): RSelection<RemoteT>; // TODO: add this everywhere! || 1 month LATER: add what?
/**
* Get all documents where the given geometry object intersects the geometry object of the requested geospatial index.
*
* table.getIntersecting(geometry, {index: 'indexname'}) → selection<stream>
* **Example:** Which of the locations in a list of parks intersect `circle1`?
*
* var circle1 = r.circle([-117.220406,32.719464], 10, {unit: 'mi'});
* r.table('parks').getIntersecting(circle1, {index: 'area'}).run(conn, callback);
*
* http://rethinkdb.com/api/javascript/get_intersecting
*/
getIntersecting(geometry:RGeometry<any>, options?:{ index:string }): RStream<RemoteT>;
/**
* Get all documents where the specified geospatial index is within a certain distance of the specified point (default 100 kilometers).
*
* table.getNearest(point, {index: 'indexname'[, maxResults: 100, maxDist: 100000, unit: 'm', geoSystem: 'WGS84']}) → selection<array>
* **Example:** Return a list of enemy hideouts within 5000 meters of the secret base.
*
* var secretBase = r.point(-122.422876,37.777128);
* r.table('hideouts').getNearest(secretBase,
* {index: 'location', maxDist: 5000}
* ).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/get_nearest
*/
getNearest(point:RPoint, options?:{ index: string, maxResults?: number, maxDist?: number, unit?: string, geoSystem?: string }): RSelection<Array<RemoteT>>;
/**
* Create a new secondary index on a table.
*
* table.indexCreate(indexName[, indexFunction][, {multi: false, geo: false}]) → object
* **Example:** Create a simple index based on the field `postId`.
*
* r.table('comments').indexCreate('postId').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/index_create
*/
indexCreate(indexName:r.stringLike, indexFunction:IndexFunction<RemoteT>, options?:{ multi?:boolean, geo? }): RObject<any>;
indexCreate(indexName:r.stringLike, options?:{ multi?:boolean, geo? }): RObject<any>;
// TODO: indexCreate result object
/**
* Delete a previously created secondary index of this table.
*
* table.indexDrop(indexName) → object
* **Example:** Drop a secondary index named 'code_name'.
*
* r.table('dc').indexDrop('code_name').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/index_drop
*/
indexDrop(indexName:r.stringLike): RObject<any>;
// TODO: index result object
/**
* List all the secondary indexes of this table.
*
* table.indexList() → array
* **Example:** List the available secondary indexes for this table.
*
* r.table('marvel').indexList().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/index_list
*/
indexList(): RArray<any>;
// TODO: index result object
/**
* Rename an existing secondary index on a table. If the optional argument `overwrite` is specified as `true`, a previously existing index with the new name will be deleted and the index will be renamed. If `overwrite` is `false` (the default) an error will be raised if the new index name already exists.
*
* table.indexRename(oldIndexName, newIndexName[, {overwrite: false}]) → object
* **Example:** Rename an index on the comments table.
*
* r.table('comments').indexRename('postId', 'messageId').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/index_rename
*/
indexRename(oldIndexName:r.stringLike, newIndexName:r.stringLike, options?:{ overwrite?:boolean }): RObject<any>;
// TODO: index result object
/**
* Get the status of the specified indexes on this table, or the status of all indexes on this table if no indexes are specified.
*
* table.indexStatus([, index...]) → array
* **Example:** Get the status of all the indexes on `test`:
*
* r.table('test').indexStatus().run(conn, callback)
*
* **Example:** Get the status of the `timestamp` index:
*
* r.table('test').indexStatus('timestamp').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/index_status
*/
indexStatus(...indexes:Array<string>): RArray<any>;
indexStatus(): RArray<any>;
// TODO: index result object
/**
* Wait for the specified indexes on this table to be ready, or for all indexes on this table to be ready if no indexes are specified.
*
* table.indexWait([, index...]) → array
* **Example:** Wait for all indexes on the table `test` to be ready:
*
* r.table('test').indexWait().run(conn, callback)
*
* **Example:** Wait for the index `timestamp` to be ready:
*
* r.table('test').indexWait('timestamp').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/index_wait
*/
indexWait(...indexes:Array<string>): RArray<any>;
indexWait(): RArray<any>;
// TODO: index result object
/**
* Return the status of a table.
*
* table.status() → selection<object>
* **Example:** Get a table's status.
*
* > r.table('superheroes').status().run(conn, callback);
*
* http://rethinkdb.com/api/javascript/status
*/
status(): RSingleSelection<any>;
// TODO: status result object
/**
* `sync` ensures that writes on a given table are written to permanent storage. Queries that specify soft durability (`{durability: 'soft'}`) do not give such guarantees, so `sync` can be used to ensure the state of these queries. A call to `sync` does not return until all previous writes to the table are persisted.
*
* table.sync()→ object
* **Example:** After having updated multiple heroes with soft durability, we now want to wait until these changes are persisted.
*
* r.table('marvel').sync().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/sync
*/
sync(): RObject<any>;
// TODO: status result object
}
export interface RBinary extends
RCoercable,
RAny,
r.count.binary,
r.slice
{}
export interface RToJSON extends RAny {
/**
* Convert a ReQL value or object to a JSON string. You may use either `toJsonString` or `toJSON`.
*
* value.toJsonString() → stringvalue.toJSON() → string
* **Example:** Get a ReQL document as a JSON string.
*
* > r.table('hero').get(1).toJSON()
* // result returned to callback
* '{"id": 1, "name": "Batman", "city": "Gotham", "powers": ["martial arts", "cinematic entrances"]}'
*
* http://rethinkdb.com/api/javascript/to_json_string
*/
toJsonString(): RString;
/**
* Convert a ReQL value or object to a JSON string. You may use either `toJsonString` or `toJSON`.
*
* value.toJsonString() → stringvalue.toJSON() → string
* **Example:** Get a ReQL document as a JSON string.
*
* > r.table('hero').get(1).toJSON()
* // result returned to callback
* '{"id": 1, "name": "Batman", "city": "Gotham", "powers": ["martial arts", "cinematic entrances"]}'
*
* http://rethinkdb.com/api/javascript/to_json_string
*/
toJSON(): RString;
}
export interface RTableSlice<RemoteT> extends RTable<RemoteT> {}
export interface RExpression {
<T extends RNumber>(expression:r.numberLike): T;
<T extends RBool>(expression:r.boolLike): T;
<T extends RString>(expression:r.stringLike): T;
<T extends RArray<any>>(expression:r.arrayLike<any>): T;
<T extends RObject<any>>(expression:r.objectLike<any>): T;
<T extends RTime>(expression:r.dateLike): T;
<T extends RGeometry<any>>(expression:T): T;
<T extends number>(expression:r.numberLike): RNumber;
<T extends boolean>(expression:r.boolLike): RBool;
<T extends string>(expression:r.stringLike): RString;
<T extends Array<any>>(expression:r.arrayLike<any>): RArray<any>;
<T extends Date>(expression:r.dateLike): RTime;
<T extends {}>(expression:r.objectLike<any>): RObject<T>;
}
export interface RGetFieldBase {
/**
* Get a single field from an object or a single element from a sequence.
*
* sequence(attr) → sequence
* singleSelection(attr) → value
* object(attr) → value
* array(index) → value
* **Example:** What was Iron Man's first appearance in a comic?
*
* r.table('marvel').get('IronMan')('firstAppearance').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/bracket
*/
(attr:r.stringLike|r.numberLike): RValue<any>;
<T extends RNumber>(attr:r.stringLike|r.numberLike): RNumber;
<T extends RString>(attr:r.stringLike|r.numberLike): RString;
<T extends RArray<any>>(attr:r.stringLike|r.numberLike): T;
<T extends RObject<any>>(attr:r.stringLike|r.numberLike): T;
<T extends RTime>(attr:r.stringLike|r.numberLike): RTime;
<T extends RGeometry<any>>(attr:r.stringLike|r.numberLike): T;
<T extends number>(attr:r.stringLike|r.numberLike): RNumber;
<T extends string>(attr:r.stringLike|r.numberLike): RString;
<T extends Array<any>>(attr:r.stringLike|r.numberLike): RArray<any>;
<T extends Date>(attr:r.stringLike|r.numberLike): RTime;
<T extends {}>(attr:r.stringLike|r.numberLike): RObject<T>;
}
export interface RGetField extends RGetFieldBase {
/**
* Get a single field from an object. If called on a sequence, gets that field from every object in the sequence, skipping objects that lack it.
*
* sequence.getField(attr) → sequence
* singleSelection.getField(attr) → value
* object.getField(attr) → value
* **Example:** What was Iron Man's first appearance in a comic?
*
* r.table('marvel').get('IronMan').getField('firstAppearance').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/get_field
*/
getField:RGetFieldBase;
// TODO: implement getFields the same as bracket
}
namespace r {
// TODO: functions should be RFunctions
type numberLike = (()=>number | RNumber) | number | RNumber;
type stringLike = (()=>string | RString) | string | RString;
type objectLike<T extends Object> = (()=>T | RValue<T>) | T | RValue<T>;
type arrayLike<T> = (()=>Array<T> | RArray<T>) | Array<T> | RArray<T>;
type dateLike = (()=>Date | RTime) | Date | RTime | numberLike; // TODO: verify date can take a number
type boolLike = boolean | RBool;
type rLike<T> = T|r.objectLike<T>|r.numberLike|r.stringLike|r.arrayLike<T>|r.dateLike|r.boolLike;
type rQuery<T> = RSelection<T>|RTable<T>|RTableSlice<T>|RSingleSelection<T>; //|RSequence<T>;
interface add<TIn, TOut> {
/**
* Sum two or more numbers, or concatenate two or more strings or arrays.
*
* value.add(value[, value, ...]) → valuetime.add(number[, number, ...]) → time
* **Example:** It's as easy as 2 + 2 = 4.
*
* r.expr(2).add(2).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/add
*/
add(value:TIn, ...values:Array<TIn>): TOut;
add(value:TIn): TOut;
}
interface sub<TIn, TOut> {
/**
* Subtract two numbers.
*
* number.sub(number[, number, ...]) → numbertime.sub(number[, number, ...]) → timetime.sub(time) → number
* **Example:** It's as easy as 2 - 2 = 0.
*
* r.expr(2).sub(2).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/sub
*/
sub(number:TIn, ...numbers:Array<TIn>): TOut;
sub(number:TIn): TOut;
}
interface ceil {
/**
* Rounds the given value up, returning the smallest integer value greater than or equal to the given value (the value's ceiling).
*
* r.ceil(number) → numbernumber.ceil() → number
* **Example:** Return the ceiling of 12.345.
*
* > r.ceil(12.345).run(conn, callback);
*
* 13.0
*
* http://rethinkdb.com/api/javascript/ceil
*/
ceil(): RNumber;
}
interface div {
/**
* Divide two numbers.
*
* number.div(number[, number ...]) → number
* **Example:** It's as easy as 2 / 2 = 1.
*
* r.expr(2).div(2).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/div
*/
div(number:r.numberLike, ...numbers:Array<r.numberLike>): RNumber;
div(number:r.numberLike): RNumber;
}
interface floor {
/**
* Rounds the given value down, returning the largest integer value less than or equal to the given value (the value's floor).
*
* r.floor(number) → numbernumber.floor() → number
* **Example:** Return the floor of 12.345.
*
* > r.floor(12.345).run(conn, callback);
*
* 12.0
*
* http://rethinkdb.com/api/javascript/floor
*/
floor(): RNumber;
}
interface mod {
/**
* Find the remainder when dividing two numbers.
*
* number.mod(number) → number
* **Example:** It's as easy as 2 % 2 = 0.
*
* r.expr(2).mod(2).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/mod
*/
mod(number:r.numberLike): RNumber;
}
interface mul<TOut> {
/**
* Multiply two numbers, or make a periodic array.
*
* number.mul(number[, number, ...]) → numberarray.mul(number[, number, ...]) → array
* **Example:** It's as easy as 2 * 2 = 4.
*
* r.expr(2).mul(2).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/mul
*/
mul(number:r.numberLike, ...numbers:Array<r.numberLike>): TOut;
mul(number:r.numberLike): TOut;
}
interface round {
/**
* Rounds the given value to the nearest whole integer.
*
* r.round(number) → numbernumber.round() → number
* **Example:** Round 12.345 to the nearest integer.
*
* > r.round(12.345).run(conn, callback);
*
* 12.0
*
* http://rethinkdb.com/api/javascript/round
*/
round(): RNumber;
}
// string
interface downcase {
/**
* Lowercases a string.
*
* string.downcase() → string
* **Example:**
*
* r.expr("Sentence about LaTeX.").downcase().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/downcase
*/
downcase(): RString;
}
interface match {
/**
* Matches against a regular expression. If there is a match, returns an object with the fields:
*
* * `str`: The matched string
* * `start`: The matched string's start
* * `end`: The matched string's end
* * `groups`: The capture groups defined with parentheses
*
* If no match is found, returns `null`.
*
* string.match(regexp) → null/object
* **Example:** Get all users whose name starts with "A".
*
* r.table('users').filter(function(doc){
* return doc('name').match("^A")
* }).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/match
*/
match(regexp): RObject<{str:string, start:number, end:number, groups:Array<string>}> & RBool;
}
interface split {
/**
* Splits a string into substrings. Splits on whitespace when called with no arguments. When called with a separator, splits on that separator. When called with a separator and a maximum number of splits, splits on that separator at most `max_splits` times. (Can be called with `null` as the separator if you want to split on whitespace while still specifying `max_splits`.)
*
* Mimics the behavior of Python's `string.split` in edge cases, except for splitting on the empty string, which instead produces an array of single-character strings.
*
* string.split([separator, [max_splits]]) → array
* **Example:** Split on whitespace.
*
* r.expr("foo bar bax").split().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/split
*/
split(separator?:string, max_splits?:number): RArray<string>;
}
interface upcase {
/**
* Uppercases a string.
*
* string.upcase() → string
* **Example:**
*
* r.expr("Sentence about LaTeX.").upcase().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/upcase
*/
upcase(): RString;
}
// array
interface append<T> {
/**
* Append a value to an array.
*
* array.append(value) → array
* **Example:** Retrieve Iron Man's equipment list with the addition of some new boots.
*
* r.table('marvel').get('IronMan')('equipment').append('newBoots').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/append
*/
append(value:T): RArray<T>;
}
interface changeAt<T> {
/**
* Change a value in an array at a given index. Returns the modified array.
*
* array.changeAt(index, value) → array
* **Example:** Bruce Banner hulks out.
*
* r.expr(["Iron Man", "Bruce", "Spider-Man"]).changeAt(1, "Hulk").run(conn, callback)
*
* http://rethinkdb.com/api/javascript/change_at
*/
changeAt(index:r.numberLike, value:T): RArray<T>;
}
interface deleteAt<T> {
/**
* Remove one or more elements from an array at a given index. Returns the modified array.
*
* array.deleteAt(index [,endIndex]) → array
* **Example:** Delete the second element of an array.
*
* > r(['a','b','c','d','e','f']).deleteAt(1).run(conn, callback)
* // result passed to callback
* ['a', 'c', 'd', 'e', 'f']
*
* http://rethinkdb.com/api/javascript/delete_at
*/
deleteAt(index:r.numberLike, endIndex?:r.numberLike): RArray<T>;
}
interface difference<T> {
/**
* Remove the elements of one array from another array.
*
* array.difference(array) → array
* **Example:** Retrieve Iron Man's equipment list without boots.
*
* r.table('marvel').get('IronMan')('equipment').difference(['Boots']).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/difference
*/
difference(array:r.arrayLike<T>): RArray<T>;
}
interface insertAt<T> {
/**
* Insert a value in to an array at a given index. Returns the modified array.
*
* array.insertAt(index, value) → array
* **Example:** Hulk decides to join the avengers.
*
* r.expr(["Iron Man", "Spider-Man"]).insertAt(1, "Hulk").run(conn, callback)
*
* http://rethinkdb.com/api/javascript/insert_at
*/
insertAt(index:r.numberLike, value:T): RArray<T>;
}
namespace map {
interface array<T> {
/**
* Transform each element of one or more sequences by applying a mapping function to them. If `map` is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence.
*
* sequence1.map([sequence2, ...], function) → stream
* array1.map([array2, ...], function) → array
* r.map(sequence1[, sequence2, ...], function) → stream
* r.map(array1[, array2, ...], function) → array
* **Example:** Return the first five squares.
*
* r.expr([1, 2, 3, 4, 5]).map(function (val) {
* return val.mul(val);
* }).run(conn, callback);
* // Result passed to callback
* [1, 4, 9, 16, 25]
*
* http://rethinkdb.com/api/javascript/map
*/
// note: RValue<TOut> is needed when doing r.branch
map<TOut>(mappingExpression:RValue<TOut>|((item:RValue<T> | RObject<T>)=>TOut)):RArray<TOut>
}
interface stream<T> {
/**
* Transform each element of one or more sequences by applying a mapping function to them. If `map` is run with two or more sequences, it will iterate for as many items as there are in the shortest sequence.
*
* sequence1.map([sequence2, ...], function) → stream
* array1.map([array2, ...], function) → array
* r.map(sequence1[, sequence2, ...], function) → stream
* r.map(array1[, array2, ...], function) → array
* **Example:** Return the first five squares.
*
* r.expr([1, 2, 3, 4, 5]).map(function (val) {
* return val.mul(val);
* }).run(conn, callback);
* // Result passed to callback
* [1, 4, 9, 16, 25]
*
* http://rethinkdb.com/api/javascript/map
*/
// NOTE: RValue<TOut> is needed when doing r.branch
// NOTE: RValue<T> & RObject makes it more permissive (not exact type check here)
map<TOut>(mappingExpression:RValue<TOut>|((item:RValue<T> & RObject<T>)=>TOut)):RStream<TOut>
}
interface r {
// there are only for r.map:
// TODO: fixme
//map(...arrays_and_then_a_function:Array<RArray | Array<any> | ExpressionFunction<RValue<any>, RAny | Object>>): RArray;
//map(...sequences_and_then_a_function:Array<RSequence | Array<any> | ExpressionFunction<RValue<any>, RAny | Object>>): RArray;
//map(a_function:ExpressionFunction<RValue<any>, RAny | Object>): RArray;
//map(array1:RArray | Array<any>, ...arrays_and_then_a_function:Array<RArray | Array<any> | ExpressionFunction<RValue<any>, RAny | Object>>): RArray;
//map(array1:RArray | Array<any>, a_function:ExpressionFunction<RValue<any>, RAny | Object>): RArray;
}
}
interface prepend<T> {
/**
* Prepend a value to an array.
*
* array.prepend(value) → array
* **Example:** Retrieve Iron Man's equipment list with the addition of some new boots.
*
* r.table('marvel').get('IronMan')('equipment').prepend('newBoots').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/prepend
*/
prepend(value:T): RArray<T>;
}
interface setDifference<T> {
/**
* Remove the elements of one array from another and return them as a set (an array with distinct values).
*
* array.setDifference(array) → array
* **Example:** Check which pieces of equipment Iron Man has, excluding a fixed list.
*
* r.table('marvel').get('IronMan')('equipment').setDifference(['newBoots', 'arc_reactor']).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/set_difference
*/
setDifference(array:r.arrayLike<T>): RArray<T>;
}
interface setInsert<T> {
/**
* Add a value to an array and return it as a set (an array with distinct values).
*
* array.setInsert(value) → array
* **Example:** Retrieve Iron Man's equipment list with the addition of some new boots.
*
* r.table('marvel').get('IronMan')('equipment').setInsert('newBoots').run(conn, callback)
*
* http://rethinkdb.com/api/javascript/set_insert
*/
setInsert(value:T): RArray<T>;
}
interface setIntersection<T> {
/**
* Intersect two arrays returning values that occur in both of them as a set (an array with distinct values).
*
* array.setIntersection(array) → array
* **Example:** Check which pieces of equipment Iron Man has from a fixed list.
*
* r.table('marvel').get('IronMan')('equipment').setIntersection(['newBoots', 'arc_reactor']).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/set_intersection
*/
setIntersection(array:r.arrayLike<T>): RArray<T>;
}
interface setUnion<T> {
/**
* Add a several values to an array and return it as a set (an array with distinct values).
*
* array.setUnion(array) → array
* **Example:** Retrieve Iron Man's equipment list with the addition of some new boots and an arc reactor.
*
* r.table('marvel').get('IronMan')('equipment').setUnion(['newBoots', 'arc_reactor']).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/set_union
*/
setUnion(array:r.arrayLike<T>): RArray<T>;
}
interface spliceAt<T> {
/**
* Insert several values in to an array at a given index. Returns the modified array.
*
* array.spliceAt(index, array) → array
* **Example:** Hulk and Thor decide to join the avengers.
*
* r.expr(["Iron Man", "Spider-Man"]).spliceAt(1, ["Hulk", "Thor"]).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/splice_at
*/
spliceAt(index:r.numberLike, array:r.arrayLike<T>): RArray<T>;
}
// join
interface zip<TOutJoin> {
/**
* Used to 'zip' up the result of a join by merging the 'right' fields into 'left' fields of each member of the sequence.
*
* stream.zip() → stream
* array.zip() → array
* **Example:** 'zips up' the sequence by merging the left and right fields produced by a join.
*
* r.table('marvel').eqJoin('main_dc_collaborator', r.table('dc'))
* .zip().run(conn, callback)
*
* http://rethinkdb.com/api/javascript/zip
*/
zip(): TOutJoin; //RArray<TLeft & TRight>;
}
// time
interface date {
/**
* Return a new time object only based on the day, month and year (ie. the same day at 00:00).
*
* time.date() → time
* **Example:** Retrieve all the users whose birthday is today
*
* r.table("users").filter(function(user) {
* return user("birthdate").date().eq(r.now().date())
* }).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/date
*/
date(): RTime;
}
interface day {
/**
* Return the day of a time object as a number between 1 and 31.
*
* time.day() → number
* **Example:** Return the users born on the 24th of any month.
*
* r.table("users").filter(
* r.row("birthdate").day().eq(24)
* ).run(conn, callback)
*
* http://rethinkdb.com/api/javascript/day
*/
day(): RNumber;
}
interface dayOfWeek {
/**
* Return the day of week of a time object as a number between 1 and 7 (following ISO 8601 standard). For your convenience, the terms r.monday, r.tuesday etc. are defined and map to the appropriate integer.
*
* time.dayOfWeek() → number
* **Example:** Return today's day of week.