-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrethinkdb.d.ts
2940 lines (2628 loc) · 113 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
import Bluebird = require('bluebird');
import { EventEmitter } from 'events';
/**
* Basic data types:
*
* - `RString`
* - `RNumber`
* - `RBoolean`
* - `RObject`
* - `RArray`
*
* RethinkDB data types:
*
* - `RDb`
* - `RTableSlice` (extends `RSelection`)
* - `RTable` (extends `RTableSlice`)
* - `RStream`
* - `RSelection`
* - `RSelectionObject`
* - `RBinary`
* - `RTime`
* - `RGeometry` (extended by `RLine`, `RPoint`, `RPolygon`, etc)
* - `RGroupedStream`
*
* Note: Sequence types are `RArray`, `RStream`, `RSelection` and `RTableSlice`.
* Note: All datum types extend `RValue`.
*/
declare namespace rethinkdb {
export interface RArray <T> extends
RBase<T[]>,
r.Run<ArrayResult<T>>,
r.Add<r.ArrayLike<T>>,
r.Append<T>,
r.ChangeAt<T>,
r.Contains<T>,
r.DeleteAt<T>,
r.Difference<T>,
r.InsertAt<T>,
r.Map.Array<T>,
r.Filter<T>,
r.Mul,
r.Prepend<T>,
r.SetDifference<T>,
r.SetInsert<T>,
r.SetIntersection<T>,
r.SetUnion<T>,
r.Skip,
r.Limit,
r.OffsetsOf<T>,
r.Merge.Array<T>,
r.Union.Array<T>,
r.SpliceAt<T>,
r.Count.Datum,
r.EqJoin.Array<T>,
r.OuterJoin.Array<T>,
r.InnerJoin.Array<T>,
r.Without.Array,
r.Pluck.Array,
r.OrderBy.Sequence<T>,
r.Bracket.Array<T>,
r.GetField.Array<T>,
r.Nth.Sequence<T>,
r.WithFields.Array {}
export interface RArrayJoin <Left, Right> extends
RArray<JoinResult<Left, Right>>,
r.Zip<RArray<Left & Right>> {}
export interface RStream <T> extends
r.Run<CursorResult<T>>,
r.Query,
r.CoerceTo<T>,
r.Changes<T>,
r.OrderBy.Sequence<T>,
r.Union.Stream<T>,
r.ConcatMap.Stream<T>,
r.Filter<T>,
r.Bracket.Stream,
r.GetField.Stream,
r.OffsetsOf<T>,
r.Skip,
r.Limit,
r.Pluck.Sequence,
r.Merge.Stream<T>,
r.Map.Sequence<T>,
r.Count.Sequence<T>,
r.EqJoin.Sequence<T>,
r.OuterJoin.Sequence<T>,
r.InnerJoin.Sequence<T>,
r.Without.Sequence,
r.HasFields<RStream<T>>,
r.Distinct.Sequence<T>,
r.Nth.Sequence<T>,
r.Sample<RArray<T>> {}
export interface RStreamJoin <Left, Right> extends
RStream<JoinResult<Left, Right>>,
r.Zip<RStream<Left & Right>> {}
export interface RSelection <T> extends
r.Run<CursorResult<T>>,
r.Operations<T>,
r.Query,
r.CoerceTo<T>,
r.Changes<T>,
r.Operators<T>,
r.Avg<T>,
r.Contains<T>,
r.Count.Sequence<T>,
r.Default<T>,
r.ForEach<T>,
r.Group<T>,
r.IsEmpty,
r.Max<T>,
r.Min<T>,
r.OffsetsOf<T>,
r.Reduce<T>,
r.Slice,
r.Sum<T>,
r.Skip,
r.Limit,
r.Pluck.Sequence,
r.Merge.Stream<T>,
r.Map.Sequence<T>,
r.OrderBy.Selection<T>,
r.Union.Stream<T>,
r.ConcatMap.Stream<T>,
r.EqJoin.Sequence<T>,
r.OuterJoin.Sequence<T>,
r.InnerJoin.Sequence<T>,
r.Without.Sequence,
r.Filter<T>,
r.Bracket.Stream,
r.GetField.Stream,
r.HasFields<RStream<T>>,
r.Sample<RArray<T>>,
r.Nth.Selection<T> {}
export interface RBase <T> extends
r.Do,
r.Query,
r.CoerceTo<T>,
r.ToJSON,
r.Default<T>,
r.Operators<T> {}
export interface RValue <T> extends
RBase<T>,
r.Run<T> {}
export interface RDatum <T> extends
RValue<T>,
r.Bracket.Datum<T>,
r.GetField.Object,
// Object.
r.Count.Datum,
r.HasFields<RBoolean<boolean>>,
r.Merge.Object<T>,
r.Pluck.Object,
r.Without.Object,
r.Default<T>,
r.Keys,
r.Values<any>,
// Number.
r.Ceil,
r.Div,
r.Floor,
r.Mod,
r.Mul,
r.Round,
r.Sub<r.NumberLike<number> | r.TimeLike>,
// String.
r.Count.Datum,
r.Downcase,
r.Match,
r.Split,
r.Upcase,
// Array.
r.Add<r.DatumLike>,
r.Contains<T>,
r.Append<T>,
r.ChangeAt<T>,
r.DeleteAt<T>,
r.Difference<T>,
r.InsertAt<T>,
r.Map.Array<T>,
r.Mul,
r.Prepend<T>,
r.SetDifference<T>,
r.SetInsert<T>,
r.SetIntersection<T>,
r.SetUnion<T>,
r.Skip,
r.Limit,
r.OffsetsOf<T>,
r.Union.Array<T>,
r.SpliceAt<T>,
r.Count.Datum,
r.WithFields.Array,
// Boolean.
r.And, r.Not, r.Or,
// Time.
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,
// Geometry.
RGeometry<T> {}
export interface RNull extends RValue<null> {}
export interface RBoolean <T extends boolean> extends
RValue<T>,
r.And, r.Not, r.Or {}
export interface RNumber <T extends number> extends
RValue<T>,
r.Add<r.NumberLike<T>>,
r.Ceil,
r.Div,
r.Floor,
r.Mod,
r.Mul,
r.Round,
r.Sub<r.NumberLike<T>> {}
export interface RString <T extends string> extends
RValue<T>,
r.Count.Datum,
r.Add<r.StringLike<T>>,
r.Downcase,
r.Match,
r.Split,
r.Upcase {}
export interface RTime extends
RValue<Date>,
r.Add<r.TimeLike>,
r.Sub<r.TimeLike>,
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 <T extends 'ARGS' | 'ORDER_BY' | 'ERROR' | 'MAXVAL' | 'MINVAL' | 'LITERAL'> extends
r.CoerceTo<T> {
type: T
}
export interface RObject <T> extends
RValue<T>,
r.Bracket.Object,
r.GetField.Object,
r.Count.Datum,
r.HasFields<RBoolean<boolean>>,
r.Merge.Object<T>,
r.Pluck.Object,
r.Without.Object,
r.Default<T>,
r.Keys,
r.Values<any> {}
export interface RSelectionObject <T> extends
RObject<T | null>,
r.Operations<T>,
r.Changes<T> {}
export interface RSelectionObjectResult <T> extends
RObject<T>,
r.Operations<T>,
r.Changes<T> {}
export type TypeOf = 'Array' | 'BOOL' | 'DB' | 'Function' | 'GROUPED_DATA' |
'GROUPED_STREAM' | 'MAXVAL' | 'MINVAL' | 'NULL' | 'NUMBER' | 'OBJECT' |
'PTYPE<BINARY>' | 'PTYPE<GEOMETRY>' | 'PTYPE<TIME>' | 'SELECTION<ARRAY>' |
'SELECTION<OBJECT>' | 'SELECTION<STREAM>' | 'STREAM' | 'STRING' |
'TABLE_SLICE' | 'TABLE';
type IndexFunction <T> = RValue<any> | Array<RValue<any>> | ((item: RObject<T>) => RValue<any> | Array<RValue<any>>);
type PrimitiveKeyType = r.StringLike<string> | r.NumberLike<number> | r.BooleanLike<boolean> | r.TimeLike | RSpecial<'MINVAL'> | RSpecial<'MAXVAL'> | RSpecial<'ARGS'> | ArrayKeyType | RArrayKeyType | ArrayReturnsKeyType;
interface ArrayKeyType extends Array<PrimitiveKeyType> {}
interface RArrayKeyType extends RArray<PrimitiveKeyType> {}
interface ArrayReturnsKeyType extends r.ReturnsType<PrimitiveKeyType> {}
type KeyType = PrimitiveKeyType;
export interface IndexOptions {
index?: string;
}
export interface IndexRequiredOptions {
index: string;
}
export type Bound = 'closed' | 'open';
export interface BoundOptions {
leftBound?: Bound;
rightBound?: Bound;
}
export type BetweenOptions = IndexOptions & BoundOptions;
export interface JoinOptions extends IndexOptions {
ordered?: boolean;
}
export interface DistanceOptions {
/**
* Unit for the distance. Possible values are `m` (meter, the default), `km` (kilometer), `mi` (international mile), `nm` (nautical mile), `ft` (international foot).
*/
unit?: 'm' | 'km' | 'mi' | 'nm' | 'ft';
/**
* The reference ellipsoid to use for geographic coordinates. Possible values are `WGS84` (the default), a common standard for Earth’s geometry, or `unit_sphere`, a perfect sphere of 1 meter radius.
*/
geoSystem?: 'WGS84' | 'unit_sphere';
}
export interface CircleOptions extends DistanceOptions {
/**
* The number of vertices in the polygon or line. Defaults to 32.
*/
numVertices?: number;
/**
* If `true` (the default) the circle is filled, creating a polygon; if `false` the circle is unfilled (creating a line).
*/
fill?: boolean;
}
export interface GetNearestOptions extends IndexRequiredOptions, DistanceOptions {
/**
* The maximum number of results to return (default 100).
*/
maxResults?: number;
/**
* The maximum distance from an object to the specified point (default 100 km).
*/
maxDist?: number;
}
export interface GetNearestResult <T> {
dist: number;
doc: T;
}
export interface IndexRenameOptions {
overwrite: boolean;
}
export interface IndexRenameResult {
renamed: boolean;
}
export interface IndexStatusResult {
index: string;
ready: boolean;
progress?: number;
function: Buffer;
multi: boolean;
geo: boolean;
outdated: boolean;
}
export interface StatusResult {
id: string;
name: string;
db: string;
status: {
all_replicas_ready: boolean;
ready_for_outdated_reads: boolean;
ready_for_reads: boolean;
ready_for_writes: boolean;
};
shards: Array<{ primary_replicas: string[], replicas: Array<{ server: string, state: 'ready' | 'transitioning' | 'backfilling' | 'disconnected' | 'waiting_for_primary' | 'waiting_for_quorum' }> }>
}
export interface IndexCreateOptions {
/**
* Geospatial indexes based on indexes of geometry objects, created when the `geo` optional argument is true.
*/
geo?: boolean;
/**
* Multi indexes based on arrays of values, created when the `multi` optional argument is `true`.
*/
multi?: boolean;
}
/**
* RethinkDB uses promises or Node.js-style callbacks.
*/
export interface Callback <T> {
(err: Error | null | undefined, res: T): void;
}
/**
* Options used when creating a new connection.
*/
export interface ConnectOptions {
/**
* The host to connect to (default: `localhost`).
*/
host?: string;
/**
* The port the connect on (default: `28015`).
*/
port?: number | string;
/**
* The default database (default: `test`).
*/
db?: string;
/**
* The user account to connect as (default: `admin`).
*/
user?: string;
/**
* The password for the user account to connect as (default: `''`, empty).
*/
password?: string;
/**
* Timeout period in seconds for the connection to be opened (default: `20`).
*/
timeout?: number;
/**
* A hash of options to support SSL connections (default: `null`). Currently, there is only one option available, and if the `ssl` option is specified, this key is required.
*/
ssl?: {
/**
* A list of Node.js `Buffer` objects containing SSL CA certificates.
*/
ca: string | Buffer | (string | Buffer)[];
};
}
/**
* Options used when closing a connection.
*/
export interface CloseOptions {
noreplayWait?: boolean
}
/**
* The connection object passed around for queries.
*/
export interface Connection extends EventEmitter {
clientPort (): number;
clientAddress (): string;
/**
* Close an open connection. If no callback is provided, a promise will be returned.
*/
close (cb: Callback<void>): void;
close (options: CloseOptions, cb: Callback<void>): void;
close (options?: CloseOptions): Bluebird<void>;
/**
* Close and reopen a connection. If no callback is provided, a promise will be returned.
*/
reconnect (cb: Callback<Connection>): void;
reconnect (options: CloseOptions, cb: Callback<Connection>): void;
reconnect (options?: CloseOptions): Bluebird<Connection>;
/**
* Change the default database on this connection.
*/
use <T extends string> (dbName: T): T;
/**
* `noreplyWait` ensures that previous queries with the `noreply` flag have been processed by the server. Note that this guarantee only applies to queries run on the given connection.
*/
noreplyWait (cb: Callback<void>): void;
noreplyWait (): Bluebird<void>;
/**
* Return information about the server being used by a connection.
*/
server (cb: Callback<ServerInfo>): void;
server (): Bluebird<ServerInfo>;
/**
* Check if the connection is open.
*/
isOpen (): boolean;
}
/**
* Object result of getting server info from connection.
*/
export interface ServerInfo {
id: string;
name: string;
proxy: boolean;
}
/**
* Options for streaming.
*/
export interface StreamOptions {
/**
* Controls how change notifications are batched.
*/
squash?: boolean | number;
/**
* The number of changes the server will buffer between client reads before it starts dropping changes and generates an error (default: 100,000).
*/
changefeedQueueSize?: number;
/**
* If `true`, the changefeed stream will begin with the current contents of the table or selection being monitored. These initial results will have `new_val` fields, but no `old_val` fields. The initial results may be intermixed with actual changes, as long as an initial result for the changed document has already been given. If an initial result for a document has been sent and a change is made to that document that would move it to the unsent part of the result set (e.g., a changefeed monitors the top 100 posters, the first 50 have been sent, and poster 48 has become poster 52), an “uninitial” notification will be sent, with an `old_val` field but no `new_val` field.
*/
includeInitial?: boolean;
/**
* If `true`, the changefeed stream will include special status documents consisting of the field `state` and a string indicating a change in the feed’s state. These documents can occur at any point in the feed between the notification documents described below. If `includeStates` is `false` (the default), the status documents will not be sent.
*/
includeStates?: boolean;
/**
* If `true`, a changefeed stream on an `orderBy.limit` changefeed will include `old_offset` and `new_offset` fields in status documents that include `old_val` and `new_val`. This allows applications to maintain ordered lists of the stream’s result set. If `old_offset` is set and not `null`, the element at `old_offset` is being deleted; if `new_offset` is set and not null, then `new_val` is being inserted at `new_offset`. Setting `includeOffsets` to `true` on a changefeed that does not support it will raise an error.
*/
includeOffsets?: boolean;
/**
* If `true`, every result on a changefeed will include a `type` field with a string that indicates the kind of change the result represents: `add`, `remove`, `change`, `initial`, `uninitial`, state. Defaults to `false`.
*/
includeTypes?: boolean;
}
export interface WriteOptions {
/**
* Possible values are `hard` and `soft`. This option will override the table or query’s durability setting (set in run). In soft durability mode RethinkDB will acknowledge the write immediately after receiving and caching it, but before the write has been committed to disk.
*/
durability?: 'hard' | 'soft';
/**
* `true`: return a changes array consisting of `old_val`/`new_val` objects describing the changes made, only including the documents actually updated.
* `false`: do not return a `changes` array (the default).
* `"always"`: behave as true, but include all documents the command tried to update whether or not the update was successful. (This was the behavior of `true` pre-2.0.)
*/
returnChanges?: 'always' | boolean;
}
export interface InsertOptions <T> extends WriteOptions {
/**
* Determine handling of inserting documents with the same primary key as existing entries. There are three built-in methods: `"error"`, `"replace"` or `"update"`; alternatively, you may provide a conflict resolution function.
*/
conflict?: 'error' | 'replace' | 'update' | ((id: string, oldDoc: RObject<T>, newDoc: RObject<T>) => RObject<T>);
}
export interface UpdateOptions extends WriteOptions {
/**
* If set to `true`, executes the update and distributes the result to replicas in a non-atomic fashion. This flag is required to perform non-deterministic updates, such as those that require reading data from another table.
*/
nonAtomic?: boolean;
}
export interface TableOptions {
/**
* One of three possible values affecting the consistency guarantee for the table read:
*
* - `single` returns values that are in memory (but not necessarily written to disk) on the primary replica. This is the default.
* - `majority` will only return values that are safely committed on disk on a majority of replicas. This requires sending a message to every replica on each read, so it is the slowest but most consistent.
* - `outdated` will return values that are in memory on an arbitrarily-selected replica. This is the fastest but least consistent.
*/
readMode?: 'single' | 'majority' | 'outdated';
/**
* Possible values are `name` and `uuid`, with a default of `name`. If set to `uuid`, then system tables will refer to servers, databases and tables by UUID rather than name. (This only has an effect when used with system tables.)
*/
identifierFormat?: 'name' | 'uuid';
}
export interface TableCreateOptions {
/**
* The name of the primary key. The default primary key is `id`.
*/
primaryKey?: string;
/**
* If set to `soft`, writes will be acknowledged by the server immediately and flushed to disk in the background. The default is `hard`: acknowledgment of writes happens after data has been written to disk.
*/
durability?: string;
/**
* The number of shards, an integer from 1-64. Defaults to `1`.
*/
shards?: number;
/**
* Either an integer or a mapping object. Defaults to 1.
*/
replicas?: number | { [tag: string]: number };
/**
* The primary server specified by its server tag. Required if `replicas` is an object; the tag must be in the object. This must _not_ be specified if `replicas` is an integer.
*/
primaryReplicaTag?: string;
}
export interface ChangeSet <Old, New> {
old_val: Old;
new_val: New;
}
export interface ChangeState {
state: 'initializing' | 'ready';
}
export interface ChangeFeed <T> extends ChangeSet<T | undefined, T | undefined> {
type?: string;
}
export interface IndexCreateResult {
created: number;
}
export interface IndexDropResult {
dropped: number;
}
export interface Config {
id: string;
name: string;
db: string;
primary_key: string;
shards: Array<{ primary_replica: string, replicas: string[], nonvoting_replicates: string[] }>;
indexes: string[];
write_acks: string;
durability: string;
}
export interface DbCreateResult {
dbs_created: number;
config_changes: ChangeSet<undefined, Config>[];
}
export interface DbDropResult {
dbs_dropped: number;
tables_dropped: number;
config_changes: ChangeSet<Config, undefined>[];
}
export interface TableCreateResult {
tables_created: number;
config_changes: ChangeSet<undefined, Config>[];
}
export interface TableDropResult {
tables_dropped: number;
config_changes: ChangeSet<Config, undefined>[];
}
export interface WriteResult <Old, New> {
/**
* The number of documents successfully inserted.
*/
inserted: number;
/**
* The number of documents updated when conflict is set to "replace" or "update".
*/
replaced: number;
/**
* The number of documents whose fields are identical to existing documents with the same primary key when `conflict` is set to "replace" or "update".
*/
unchanged: number;
/**
* The number of errors encountered while performing the insert.
*/
errors: number;
/**
* If errors were encountered, contains the text of the first error.
*/
first_error: string;
/**
* The number of documents that were deleted.
*/
deleted: number;
/**
* The number of documents that were skipped because the document didn’t exist.
*/
skipped: number;
/**
* If `returnChanges` is set to `true`, this will be an array of objects, one for each objected affected by the operation.
*/
changes?: ChangeSet<Old, New>[];
}
export interface InsertResult <T> extends WriteResult<null, T> {
/**
* A list of generated primary keys for inserted documents whose primary keys were not specified (capped to 100,000).
*/
generated_keys?: string[];
/**
* If the field generated_keys is truncated, you will get the warning “Too many generated keys (<X>), array truncated to 100000.”.
*/
warnings: string;
}
export interface UpdateResult <T> extends WriteResult<T, T> {}
export interface ReplaceResult <T> extends WriteResult<T, T> {}
export interface DeleteResult <T> extends WriteResult<T, null> {}
export interface SyncResult {
synced: number;
}
export interface UnionOptions <T> {
interleave?: boolean | string | ((row: RObject<T>) => RString<string>);
}
export interface NestedFieldsObject {
[key: string]: boolean | NestedFieldsSelector;
}
type NestedFieldsSelector = string | string[] | NestedFieldsObject | NestedFieldsObject[];
export interface RTableSlice <T> extends
r.Run<CursorResult<T>>,
r.Query,
r.Configurable,
r.Operations<T>,
r.Changes<T>,
r.Skip,
r.Limit,
r.CoerceTo<T>,
r.Avg<T>,
r.Contains<T>,
r.Count.Sequence<T>,
r.Default<T>,
r.ForEach<T>,
r.Group<T>,
r.IsEmpty,
r.Max<T>,
r.Min<T>,
r.OffsetsOf<T>,
r.Reduce<T>,
r.Slice,
r.Sum<T>,
r.Merge.Stream<T>,
r.Union.Stream<T>,
r.ConcatMap.Stream<T>,
r.Filter<T>,
r.Pluck.Sequence,
r.Bracket.Stream,
r.GetField.Stream,
r.EqJoin.Sequence<T>,
r.OuterJoin.Sequence<T>,
r.InnerJoin.Sequence<T>,
r.Without.Sequence,
r.HasFields<RStream<T>>,
r.Sample<RArray<T>>,
r.Nth.Selection<T>,
r.Map.Sequence<T>,
r.Distinct.Table<T>,
r.OrderBy.Table<T> {
/**
* 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).
*
* https://www.rethinkdb.com/api/javascript/between
*/
between <U extends T> (lowerKey: KeyType, upperKey: KeyType, options?: BetweenOptions): RTableSlice<U>;
}
export interface RTable <T> extends RTableSlice<T> {
/**
* Get a document by primary key.
*
* If no document exists with that primary key, `get` will return `null`.
*
* https://www.rethinkdb.com/api/javascript/get
*/
get <U extends T> (key: KeyType): RSelectionObject<U>;
/**
* Get all documents where the given value matches the value of the requested index.
*
* https://www.rethinkdb.com/api/javascript/get_all
*/
getAll <U extends T> (key: KeyType, options?: IndexOptions): RSelection<U>;
getAll <U extends T> (key: KeyType, ...keys: Array<KeyType>): RSelection<U>;
getAll <U extends T> (key: KeyType, ...keysAndThenOptions: Array<KeyType | IndexOptions>): RSelection<U>;
/**
* Get all documents where the given geometry object intersects the geometry object of the requested geospatial index.
*
* https://www.rethinkdb.com/api/javascript/get_intersecting
*/
getIntersecting (geometry: RGeometry<any>, options?: IndexOptions): RStream<T>;
/**
* Get all documents where the specified geospatial index is within a certain distance of the specified point (default 100 kilometers).
*
* https://www.rethinkdb.com/api/javascript/get_nearest
*/
getNearest (point: RPoint, options?: GetNearestOptions): RArray<GetNearestResult<T>>;
/**
* Create a new secondary index on a table.
*
* https://www.rethinkdb.com/api/javascript/index_create
*/
indexCreate (indexName: r.StringLike<string>, options?: IndexCreateOptions): RObject<IndexCreateResult>;
indexCreate (indexName: r.StringLike<string>, indexFunction: IndexFunction<T>, options?: IndexCreateOptions): RObject<IndexCreateResult>;
/**
* Delete a previously created secondary index of this table.
*
* https://www.rethinkdb.com/api/javascript/index_drop
*/
indexDrop (indexName: r.StringLike<string>): RObject<IndexDropResult>;
/**
* List all the secondary indexes of this table.
*
* https://www.rethinkdb.com/api/javascript/index_list
*/
indexList (): RArray<string>;
/**
* 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.
*
* https://www.rethinkdb.com/api/javascript/index_rename
*/
indexRename (oldIndexName: r.StringLike<string>, newIndexName: r.StringLike<string>, options?: IndexRenameOptions): RObject<IndexRenameResult>;
/**
* Get the status of the specified indexes on this table, or the status of all indexes on this table if no indexes are specified.
*
* https://www.rethinkdb.com/api/javascript/index_status
*/
indexStatus (...indexes: Array<string>): RArray<IndexStatusResult>;
indexStatus (): RArray<IndexStatusResult>;
/**
* 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.
*
* https://www.rethinkdb.com/api/javascript/index_wait
*/
indexWait (...indexes: Array<string>): RArray<IndexStatusResult>;
indexWait (): RArray<IndexStatusResult>;
/**
* Return the status of a table.
*
* https://www.rethinkdb.com/api/javascript/status
*/
status (): RSelectionObjectResult<StatusResult>;
/**
* `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.
*
* https://www.rethinkdb.com/api/javascript/sync
*/
sync (): RObject<SyncResult>;
}
export interface RBinary extends
RValue<Buffer>,
r.Count.Datum,
r.Slice {}
export interface RGeometry <T> extends
RValue<T>,
r.Intersects.Geometry,
r.Includes.Geometry {
/**
* Compute the distance between a point and another geometry object. At least one of the geometry objects specified must be a point.
*
* https://www.rethinkdb.com/api/javascript/distance
*/
distance (geometry: RGeometry<T>, options?: DistanceOptions): RNumber<number>;
/**
* Convert a ReQL geometry object to a [GeoJSON](http://geojson.org/) object.
*
* https://www.rethinkdb.com/api/javascript/to_geojson
*/
toGeojson (): RObject<any>;
}
export interface RPolygon extends RGeometry<Array<[number, number]>> {
/**
* Use `polygon2` to "punch out" a hole in `polygon1`. `polygon2` must be completely contained within `polygon1` and must have no holes itself (it must not be the output of `polygonSub` itself).
*
* https://www.rethinkdb.com/api/javascript/polygon_sub
*/
polygonSub (polygon2: RPolygon): RPolygon;
}
export interface RLine extends RGeometry<Array<number>> {
/**
* Convert a Line object into a Polygon object. If the last point does not specify the same coordinates as the first point, `polygon` will close the polygon by connecting them.
*
* https://www.rethinkdb.com/api/javascript/fill
*/
fill (): RPolygon;
}
export interface RPoint extends RGeometry<[number, number]> {}
export interface RGroupedStream <Group, Reduction> extends RStream<GroupResult<Group, Reduction>> {
/**
* Takes a grouped stream or grouped data and turns it into an array of objects representing the groups. Any commands chained after `ungroup` will operate on this array, rather than operating on each group individually. This is useful if you want to e.g. order the groups by the value of their reduction.
*
* https://www.rethinkdb.com/api/javascript/ungroup
*/
ungroup (): RArray<GroupResult<Group, Reduction>>;
}
export interface WaitOptions {
/**
* A string indicating a table status to wait on before returning, one of `ready_for_outdated_reads`, `ready_for_reads`, `ready_for_writes`, or `all_replicas_ready`. The default is `all_replicas_ready`.
*/
waitFor?: 'ready_for_outdated_reads' | 'ready_for_reads' | 'ready_for_writes' | 'all_replicas_ready';
/**
* A number indicating maximum time, in seconds, to wait for the table to be ready. If this value is exceeded, a `ReqlRuntimeError` will be thrown. A value of `0` means no timeout. The default is `0` (no timeout).
*/
timeout?: number;
}
export interface WaitResult {
ready: number;
}
export interface ReconfigureOptions {
/**
* The number of shards, an integer from 1-64. Required.
*/
shards: number;
/**
* Either an integer or a mapping object. Required.
*
* - If `replicas` is an integer, it specifies the number of replicas per shard. Specifying more replicas than there are servers will return an error.
* - If `replicas` is an object, it specifies key-value pairs of server tags and the number of replicas to assign to those servers: `{tag1: 2, tag2: 4, tag3: 2, ...}`.
*/
replicas: number | { [tag: string]: number };
/**
* The primary server specified by its server tag. Required if `replicas` is an object; the tag must be in the object. This must not be specified if `replicas` is an integer.
*/
primaryReplicaTag?: string;
/**
* If `true` the generated configuration will not be applied to the table, only returned.
*/
dryRun?: boolean;
/**
* Replicas with these server tags will be added to the nonvoting_replicas list of the resulting configuration. (See failover for details about non-voting replicas.)
*/
nonvotingReplicaTags?: string[];
/**
* Used for the Emergency Repair mode.
*/
emergencyRepair?: 'unsafe_rollback' | 'unsafe_rollback_or_erase';
}
export interface ReconfigureResult {
/**
* The number of tables reconfigured. This will be `0` if `dryRun` is `true`.
*/
reconfigured: number;
/**
* A list of new and old table configuration values.
*/
config_changes: ChangeSet<Config, Config>[];
/**
* A list of new and old table status values.
*/
status_changes: ChangeSet<StatusResult, StatusResult>[];
}
export interface RebalanceResult {
rebalanced: number;
status_changes: ChangeSet<StatusResult, StatusResult>[];
}
export interface RDb extends r.Configurable, r.Query {
/**
* Select all documents in a table. This command can be chained with other commands to do further processing on the data.
*
* https://www.rethinkdb.com/api/javascript/table
*/
table <T> (name: r.StringLike<string>, options?: TableOptions): RTable<T>;
/**
* Create a table. A RethinkDB table is a collection of JSON documents.
*
* https://www.rethinkdb.com/api/javascript/table_create
*/
tableCreate (tableName: r.StringLike<string>, options?: TableCreateOptions): RObject<TableCreateResult>;
/**
* Drop a table. The table and all its data will be deleted.
*
* https://www.rethinkdb.com/api/javascript/table_drop
*/
tableDrop (tableName: r.StringLike<string>): RObject<TableDropResult>;
/**
* List all table names in a database. The result is a list of strings.
*
* https://www.rethinkdb.com/api/javascript/table_list
*/
tableList (): RArray<string>;
}
export interface JoinFunction <U> {
(left: RObject<any>, right: RObject<any>): U;
}