forked from rethinkdb/rethinkdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.coffee
1326 lines (1046 loc) · 38 KB
/
ast.coffee
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
# # AST
util = require('./util')
err = require('./errors')
net = require('./net')
protoTermType = require('./proto-def').Term.TermType
Promise = require('bluebird')
# Import some names to this namespace for convenience
ar = util.ar
varar = util.varar
aropt = util.aropt
# rethinkdb is both the main export object for the module
# and a function that shortcuts `r.expr`.
rethinkdb = (args...) -> rethinkdb.expr(args...)
# ## Utilities
funcWrap = (val) ->
if val is undefined
# Pass through the undefined value so it's caught by
# the appropriate undefined checker
return val
val = rethinkdb.expr(val)
ivarScan = (node) ->
unless node instanceof TermBase then return false
if node instanceof ImplicitVar then return true
if (node.args.map ivarScan).some((a)->a) then return true
if (v for own k,v of node.optargs).map(ivarScan).some((a)->a) then return true
return false
if ivarScan(val)
return new Func {}, (x) -> val
return val
hasImplicit = (args) ->
# args is an array of (strings and arrays)
# We recurse to look for `r.row` which is an implicit var
if Array.isArray(args)
for arg in args
if hasImplicit(arg) is true
return true
else if args is 'r.row'
return true
return false
# AST classes
class TermBase
showRunWarning: true
constructor: ->
self = (ar (field) -> self.bracket(field))
self.__proto__ = @.__proto__
return self
run: (connection, options, callback) ->
# Valid syntaxes are
# connection, callback
# connection, options # return a Promise
# connection, options, callback
# connection, null, callback
# connection, null # return a Promise
#
# Depreciated syntaxes are
# optionsWithConnection, callback
if net.isConnection(connection) is true
# Handle run(connection, callback)
if typeof options is "function"
if callback is undefined
callback = options
options = {}
else
#options is a function here
return Promise.reject(new err.RqlDriverError("Second argument to `run` cannot be a function if a third argument is provided.")).nodeify options
# else we suppose that we have run(connection[, options][, callback])
else if connection?.constructor is Object
if @showRunWarning is true
process?.stderr.write("RethinkDB warning: This syntax is deprecated. Please use `run(connection[, options], callback)`.")
@showRunWarning = false
# Handle run(connectionWithOptions, callback)
callback = options
options = connection
connection = connection.connection
delete options["connection"]
options = {} if not options?
if callback? and typeof callback isnt 'function'
return Promise.reject(new err.RqlDriverError("If provided, the callback must be a function. Please use `run(connection[, options][, callback])"))
if net.isConnection(connection) is false
return Promise.reject(new err.RqlDriverError("First argument to `run` must be an open connection.")).nodeify callback
# if `noreply` is `true`, the callback will be immediately called without error
# so we do not have to worry about bluebird complaining about errors not being
# caught
new Promise( (resolve, reject) =>
wrappedCb = (err, result) ->
if err?
reject(err)
else
resolve(result)
try
connection._start @, wrappedCb, options
catch e
# It was decided that, if we can, we prefer to invoke the callback
# with any errors rather than throw them as normal exceptions.
# Thus we catch errors here and invoke the callback instead of
# letting the error bubble up.
wrappedCb(e)
).nodeify callback
toString: -> err.printQuery(@)
class RDBVal extends TermBase
eq: (args...) -> new Eq {}, @, args...
ne: (args...) -> new Ne {}, @, args...
lt: (args...) -> new Lt {}, @, args...
le: (args...) -> new Le {}, @, args...
gt: (args...) -> new Gt {}, @, args...
ge: (args...) -> new Ge {}, @, args...
not: (args...) -> new Not {}, @, args...
add: (args...) -> new Add {}, @, args...
sub: (args...) -> new Sub {}, @, args...
mul: (args...) -> new Mul {}, @, args...
div: (args...) -> new Div {}, @, args...
mod: (args...) -> new Mod {}, @, args...
floor: (args...) -> new Floor {}, @, args...
ceil: (args...) -> new Ceil {}, @, args...
round: (args...) -> new Round {}, @, args...
append: (args...) -> new Append {}, @, args...
prepend: (args...) -> new Prepend {}, @, args...
difference: (args...) -> new Difference {}, @, args...
setInsert: (args...) -> new SetInsert {}, @, args...
setUnion: (args...) -> new SetUnion {}, @, args...
setIntersection: (args...) -> new SetIntersection {}, @, args...
setDifference: (args...) -> new SetDifference {}, @, args...
slice: varar(1, 3, (left, right_or_opts, opts) ->
if opts?
new Slice opts, @, left, right_or_opts
else if typeof right_or_opts isnt 'undefined'
# FIXME
if (Object::toString.call(right_or_opts) is '[object Object]') and not (right_or_opts instanceof TermBase)
new Slice right_or_opts, @, left
else
new Slice {}, @, left, right_or_opts
else
new Slice {}, @, left
)
skip: (args...) -> new Skip {}, @, args...
limit: (args...) -> new Limit {}, @, args...
getField: (args...) -> new GetField {}, @, args...
contains: (args...) -> new Contains {}, @, args...
insertAt: (args...) -> new InsertAt {}, @, args...
spliceAt: (args...) -> new SpliceAt {}, @, args...
deleteAt: (args...) -> new DeleteAt {}, @, args...
changeAt: (args...) -> new ChangeAt {}, @, args...
offsetsOf: (args...) -> new OffsetsOf {}, @, args.map(funcWrap)...
hasFields: (args...) -> new HasFields {}, @, args...
withFields: (args...) -> new WithFields {}, @, args...
keys: (args...) -> new Keys {}, @, args...
changes: aropt (opts) -> new Changes opts, @
# pluck and without on zero fields are allowed
pluck: (args...) -> new Pluck {}, @, args...
without: (args...) -> new Without {}, @, args...
merge: (args...) -> new Merge {}, @, args.map(funcWrap)...
between: aropt (left, right, opts) -> new Between opts, @, left, right
reduce: (args...) -> new Reduce {}, @, args.map(funcWrap)...
map: varar 1, null, (args..., funcArg) -> new Map {}, @, args..., funcWrap(funcArg)
filter: aropt (predicate, opts) -> new Filter opts, @, funcWrap(predicate)
concatMap: (args...) -> new ConcatMap {}, @, args.map(funcWrap)...
distinct: aropt (opts) -> new Distinct opts, @
count: (args...) -> new Count {}, @, args.map(funcWrap)...
union: (args...) -> new Union {}, @, args...
nth: (args...) -> new Nth {}, @, args...
bracket: (args...) -> new Bracket {}, @, args...
toJSON: (args...) -> new ToJsonString {}, @, args...
toJsonString: (args...) -> new ToJsonString {}, @, args...
match: (args...) -> new Match {}, @, args...
split: (args...) -> new Split {}, @, args.map(funcWrap)...
upcase: (args...) -> new Upcase {}, @, args...
downcase: (args...) -> new Downcase {}, @, args...
isEmpty: (args...) -> new IsEmpty {}, @, args...
innerJoin: (args...) -> new InnerJoin {}, @, args...
outerJoin: (args...) -> new OuterJoin {}, @, args...
eqJoin: aropt (left_attr, right, opts) -> new EqJoin opts, @, funcWrap(left_attr), right
zip: (args...) -> new Zip {}, @, args...
coerceTo: (args...) -> new CoerceTo {}, @, args...
ungroup: (args...) -> new Ungroup {}, @, args...
typeOf: (args...) -> new TypeOf {}, @, args...
update: aropt (func, opts) -> new Update opts, @, funcWrap(func)
delete: aropt (opts) -> new Delete opts, @
replace: aropt (func, opts) -> new Replace opts, @, funcWrap(func)
do: (args...) ->
new FunCall {}, funcWrap(args[-1..][0]), @, args[...-1]...
default: (args...) -> new Default {}, @, args...
or: (args...) -> new Or {}, @, args...
and: (args...) -> new And {}, @, args...
forEach: (args...) -> new ForEach {}, @, args.map(funcWrap)...
sum: (args...) -> new Sum {}, @, args.map(funcWrap)...
avg: (args...) -> new Avg {}, @, args.map(funcWrap)...
info: (args...) -> new Info {}, @, args...
sample: (args...) -> new Sample {}, @, args...
group: (fieldsAndOpts...) ->
# Default if no opts dict provided
opts = {}
fields = fieldsAndOpts
# Look for opts dict
if fieldsAndOpts.length > 0
perhapsOptDict = fieldsAndOpts[fieldsAndOpts.length - 1]
if perhapsOptDict and
(Object::toString.call(perhapsOptDict) is '[object Object]') and
not (perhapsOptDict instanceof TermBase)
opts = perhapsOptDict
fields = fieldsAndOpts[0...(fieldsAndOpts.length - 1)]
new Group opts, @, fields.map(funcWrap)...
orderBy: (attrsAndOpts...) ->
# Default if no opts dict provided
opts = {}
attrs = attrsAndOpts
# Look for opts dict
perhapsOptDict = attrsAndOpts[attrsAndOpts.length - 1]
if perhapsOptDict and
(Object::toString.call(perhapsOptDict) is '[object Object]') and
not (perhapsOptDict instanceof TermBase)
opts = perhapsOptDict
attrs = attrsAndOpts[0...(attrsAndOpts.length - 1)]
attrs = (for attr in attrs
if attr instanceof Asc or attr instanceof Desc
attr
else
funcWrap(attr)
)
new OrderBy opts, @, attrs...
# Geo operations
toGeojson: (args...) -> new ToGeojson {}, @, args...
distance: aropt (g, opts) -> new Distance opts, @, g
intersects: (args...) -> new Intersects {}, @, args...
includes: (args...) -> new Includes {}, @, args...
fill: (args...) -> new Fill {}, @, args...
polygonSub: (args...) -> new PolygonSub {}, @, args...
# Database operations
tableCreate: aropt (tblName, opts) -> new TableCreate opts, @, tblName
tableDrop: (args...) -> new TableDrop {}, @, args...
tableList: (args...) -> new TableList {}, @, args...
# Mixed db/table operations
config: () -> new Config {}, @
status: () -> new Status {}, @
wait: aropt (opts) -> new Wait opts, @
table: aropt (tblName, opts) -> new Table opts, @, tblName
# Table operations
get: (args...) -> new Get {}, @, args...
getAll: (keysAndOpts...) ->
# Default if no opts dict provided
opts = {}
keys = keysAndOpts
# Look for opts dict
if keysAndOpts.length > 1
perhapsOptDict = keysAndOpts[keysAndOpts.length - 1]
if perhapsOptDict and
((Object::toString.call(perhapsOptDict) is '[object Object]') and not (perhapsOptDict instanceof TermBase))
opts = perhapsOptDict
keys = keysAndOpts[0...(keysAndOpts.length - 1)]
new GetAll opts, @, keys...
min: (keysAndOpts...) ->
# Default if no opts dict provided
opts = {}
keys = keysAndOpts
# Look for opts dict
if keysAndOpts.length == 1
perhapsOptDict = keysAndOpts[0]
if perhapsOptDict and
((Object::toString.call(perhapsOptDict) is '[object Object]') and not (perhapsOptDict instanceof TermBase))
opts = perhapsOptDict
keys = []
new Min opts, @, keys.map(funcWrap)...
max: (keysAndOpts...) ->
# Default if no opts dict provided
opts = {}
keys = keysAndOpts
# Look for opts dict
if keysAndOpts.length == 1
perhapsOptDict = keysAndOpts[0]
if perhapsOptDict and
((Object::toString.call(perhapsOptDict) is '[object Object]') and not (perhapsOptDict instanceof TermBase))
opts = perhapsOptDict
keys = []
new Max opts, @, keys.map(funcWrap)...
insert: aropt (doc, opts) -> new Insert opts, @, rethinkdb.expr(doc)
indexCreate: varar(1, 3, (name, defun_or_opts, opts) ->
if opts?
new IndexCreate opts, @, name, funcWrap(defun_or_opts)
else if defun_or_opts?
# FIXME?
if (Object::toString.call(defun_or_opts) is '[object Object]') and not (defun_or_opts instanceof Function) and not (defun_or_opts instanceof TermBase)
new IndexCreate defun_or_opts, @, name
else
new IndexCreate {}, @, name, funcWrap(defun_or_opts)
else
new IndexCreate {}, @, name
)
indexDrop: (args...) -> new IndexDrop {}, @, args...
indexList: (args...) -> new IndexList {}, @, args...
indexStatus: (args...) -> new IndexStatus {}, @, args...
indexWait: (args...) -> new IndexWait {}, @, args...
indexRename: aropt (old_name, new_name, opts) -> new IndexRename opts, @, old_name, new_name
reconfigure: (opts) -> new Reconfigure opts, @
rebalance: () -> new Rebalance {}, @
sync: (args...) -> new Sync {}, @, args...
toISO8601: (args...) -> new ToISO8601 {}, @, args...
toEpochTime: (args...) -> new ToEpochTime {}, @, args...
inTimezone: (args...) -> new InTimezone {}, @, args...
during: aropt (t2, t3, opts) -> new During opts, @, t2, t3
date: (args...) -> new RQLDate {}, @, args...
timeOfDay: (args...) -> new TimeOfDay {}, @, args...
timezone: (args...) -> new Timezone {}, @, args...
year: (args...) -> new Year {}, @, args...
month: (args...) -> new Month {}, @, args...
day: (args...) -> new Day {}, @, args...
dayOfWeek: (args...) -> new DayOfWeek {}, @, args...
dayOfYear: (args...) -> new DayOfYear {}, @, args...
hours: (args...) -> new Hours {}, @, args...
minutes: (args...) -> new Minutes {}, @, args...
seconds: (args...) -> new Seconds {}, @, args...
uuid: (args...) -> new UUID {}, @, args...
getIntersecting: aropt (g, opts) -> new GetIntersecting opts, @, g
getNearest: aropt (g, opts) -> new GetNearest opts, @, g
class DatumTerm extends RDBVal
args: []
optargs: {}
constructor: (val) ->
self = super()
self.data = val
return self
compose: ->
switch typeof @data
when 'string'
'"'+@data+'"'
else
''+@data
build: ->
if typeof(@data) is 'number'
if !isFinite(@data)
throw new TypeError("Illegal non-finite number `" + @data.toString() + "`.")
@data
translateBackOptargs = (optargs) ->
result = {}
for own key,val of optargs
result[util.toCamelCase(key)] = val
return result
translateOptargs = (optargs) ->
result = {}
for own key,val of optargs
# We translate opt-args to camel case for your convience
if key is undefined or val is undefined then continue
result[util.fromCamelCase(key)] = rethinkdb.expr val
return result
class RDBOp extends RDBVal
constructor: (optargs, args...) ->
self = super()
self.args =
for arg,i in args
if arg isnt undefined
rethinkdb.expr arg
else
throw new err.RqlDriverError "Argument #{i} to #{@st || @mt} may not be `undefined`."
self.optargs = translateOptargs(optargs)
return self
build: ->
res = [@tt, []]
for arg in @args
res[1].push(arg.build())
opts = {}
add_opts = false
for own key,val of @optargs
add_opts = true
opts[key] = val.build()
if add_opts
res.push(opts)
res
# a class that extends RDBOp should have a property `st` or `mt` depending on
# how the term should be printed (see `compose` below)
compose: (args, optargs) ->
if @st
return ['r.', @st, '(', intspallargs(args, optargs), ')']
else # @mt is defined
if shouldWrap(@args[0])
args[0] = ['r(', args[0], ')']
return [args[0], '.', @mt, '(', intspallargs(args[1..], optargs), ')']
class RDBConstant extends RDBOp
compose: (args, optargs) ->
# Constants should not have any args or optargs, and should not look like a call
return ['r.', @st]
intsp = (seq) ->
unless seq[0]? then return []
res = [seq[0]]
for e in seq[1..]
res.push(', ', e)
return res
kved = (optargs) ->
['{', intsp([k, ': ', v] for own k,v of optargs), '}']
intspallargs = (args, optargs) ->
argrepr = []
if args.length > 0
argrepr.push(intsp(args))
if Object.keys(optargs).length > 0
if argrepr.length > 0
argrepr.push(', ')
argrepr.push(kved(translateBackOptargs(optargs)))
return argrepr
shouldWrap = (arg) ->
arg instanceof DatumTerm or arg instanceof MakeArray or arg instanceof MakeObject
class MakeArray extends RDBOp
tt: protoTermType.MAKE_ARRAY
st: '[...]' # This is only used by the `undefined` argument checker
compose: (args) -> ['[', intsp(args), ']']
class MakeObject extends RDBOp
tt: protoTermType.MAKE_OBJECT
st: '{...}' # This is only used by the `undefined` argument checker
constructor: (obj, nestingDepth=20) ->
self = super({})
self.optargs = {}
for own key,val of obj
if typeof val is 'undefined'
throw new err.RqlDriverError "Object field '#{key}' may not be undefined"
self.optargs[key] = rethinkdb.expr val, nestingDepth-1
return self
compose: (args, optargs) -> kved(optargs)
build: ->
res = {}
for own key,val of @optargs
res[key] = val.build()
return res
class Var extends RDBOp
tt: protoTermType.VAR
compose: (args) -> ['var_'+args]
class JavaScript extends RDBOp
tt: protoTermType.JAVASCRIPT
st: 'js'
class Http extends RDBOp
tt: protoTermType.HTTP
st: 'http'
class Json extends RDBOp
tt: protoTermType.JSON
st: 'json'
class Binary extends RDBOp
tt: protoTermType.BINARY
st: 'binary'
constructor: (data) ->
if data instanceof TermBase
self = super({}, data)
else if data instanceof Buffer
self = super()
self.base64_data = data.toString("base64")
else
throw new TypeError("Parameter to `r.binary` must be a Buffer object or RQL query.")
return self
compose: ->
if @args.length == 0
'r.binary(<data>)'
else
super
build: ->
if @args.length == 0
{ '$reql_type$': 'BINARY', 'data': @base64_data }
else
super
class Args extends RDBOp
tt: protoTermType.ARGS
st: 'args'
class UserError extends RDBOp
tt: protoTermType.ERROR
st: 'error'
class Random extends RDBOp
tt: protoTermType.RANDOM
st: 'random'
class ImplicitVar extends RDBOp
tt: protoTermType.IMPLICIT_VAR
compose: -> ['r.row']
class Db extends RDBOp
tt: protoTermType.DB
st: 'db'
class Table extends RDBOp
tt: protoTermType.TABLE
st: 'table'
compose: (args, optargs) ->
if @args[0] instanceof Db
[args[0], '.table(', intspallargs(args[1..], optargs), ')']
else
['r.table(', intspallargs(args, optargs), ')']
class Get extends RDBOp
tt: protoTermType.GET
mt: 'get'
class GetAll extends RDBOp
tt: protoTermType.GET_ALL
mt: 'getAll'
class Eq extends RDBOp
tt: protoTermType.EQ
mt: 'eq'
class Ne extends RDBOp
tt: protoTermType.NE
mt: 'ne'
class Lt extends RDBOp
tt: protoTermType.LT
mt: 'lt'
class Le extends RDBOp
tt: protoTermType.LE
mt: 'le'
class Gt extends RDBOp
tt: protoTermType.GT
mt: 'gt'
class Ge extends RDBOp
tt: protoTermType.GE
mt: 'ge'
class Not extends RDBOp
tt: protoTermType.NOT
mt: 'not'
class Add extends RDBOp
tt: protoTermType.ADD
mt: 'add'
class Sub extends RDBOp
tt: protoTermType.SUB
mt: 'sub'
class Mul extends RDBOp
tt: protoTermType.MUL
mt: 'mul'
class Div extends RDBOp
tt: protoTermType.DIV
mt: 'div'
class Mod extends RDBOp
tt: protoTermType.MOD
mt: 'mod'
class Floor extends RDBOp
tt: protoTermType.FLOOR
mt: 'floor'
class Ceil extends RDBOp
tt: protoTermType.CEIL
mt: 'ceil'
class Round extends RDBOp
tt: protoTermType.ROUND
mt: 'round'
class Append extends RDBOp
tt: protoTermType.APPEND
mt: 'append'
class Prepend extends RDBOp
tt: protoTermType.PREPEND
mt: 'prepend'
class Difference extends RDBOp
tt: protoTermType.DIFFERENCE
mt: 'difference'
class SetInsert extends RDBOp
tt: protoTermType.SET_INSERT
mt: 'setInsert'
class SetUnion extends RDBOp
tt: protoTermType.SET_UNION
mt: 'setUnion'
class SetIntersection extends RDBOp
tt: protoTermType.SET_INTERSECTION
mt: 'setIntersection'
class SetDifference extends RDBOp
tt: protoTermType.SET_DIFFERENCE
mt: 'setDifference'
class Slice extends RDBOp
tt: protoTermType.SLICE
mt: 'slice'
class Skip extends RDBOp
tt: protoTermType.SKIP
mt: 'skip'
class Limit extends RDBOp
tt: protoTermType.LIMIT
mt: 'limit'
class GetField extends RDBOp
tt: protoTermType.GET_FIELD
mt: 'getField'
class Bracket extends RDBOp
tt: protoTermType.BRACKET
st: '(...)' # This is only used by the `undefined` argument checker
compose: (args) -> [args[0], '(', args[1], ')']
class Contains extends RDBOp
tt: protoTermType.CONTAINS
mt: 'contains'
class InsertAt extends RDBOp
tt: protoTermType.INSERT_AT
mt: 'insertAt'
class SpliceAt extends RDBOp
tt: protoTermType.SPLICE_AT
mt: 'spliceAt'
class DeleteAt extends RDBOp
tt: protoTermType.DELETE_AT
mt: 'deleteAt'
class ChangeAt extends RDBOp
tt: protoTermType.CHANGE_AT
mt: 'changeAt'
class Contains extends RDBOp
tt: protoTermType.CONTAINS
mt: 'contains'
class HasFields extends RDBOp
tt: protoTermType.HAS_FIELDS
mt: 'hasFields'
class WithFields extends RDBOp
tt: protoTermType.WITH_FIELDS
mt: 'withFields'
class Keys extends RDBOp
tt: protoTermType.KEYS
mt: 'keys'
class Changes extends RDBOp
tt: protoTermType.CHANGES
mt: 'changes'
class Object_ extends RDBOp
tt: protoTermType.OBJECT
mt: 'object'
class Pluck extends RDBOp
tt: protoTermType.PLUCK
mt: 'pluck'
class OffsetsOf extends RDBOp
tt: protoTermType.OFFSETS_OF
mt: 'offsetsOf'
class Without extends RDBOp
tt: protoTermType.WITHOUT
mt: 'without'
class Merge extends RDBOp
tt: protoTermType.MERGE
mt: 'merge'
class Between extends RDBOp
tt: protoTermType.BETWEEN
mt: 'between'
class Reduce extends RDBOp
tt: protoTermType.REDUCE
mt: 'reduce'
class Map extends RDBOp
tt: protoTermType.MAP
mt: 'map'
class Filter extends RDBOp
tt: protoTermType.FILTER
mt: 'filter'
class ConcatMap extends RDBOp
tt: protoTermType.CONCAT_MAP
mt: 'concatMap'
class OrderBy extends RDBOp
tt: protoTermType.ORDER_BY
mt: 'orderBy'
class Distinct extends RDBOp
tt: protoTermType.DISTINCT
mt: 'distinct'
class Count extends RDBOp
tt: protoTermType.COUNT
mt: 'count'
class Union extends RDBOp
tt: protoTermType.UNION
mt: 'union'
class Nth extends RDBOp
tt: protoTermType.NTH
mt: 'nth'
class ToJsonString extends RDBOp
tt: protoTermType.TO_JSON_STRING
mt: 'toJsonString'
class Match extends RDBOp
tt: protoTermType.MATCH
mt: 'match'
class Split extends RDBOp
tt: protoTermType.SPLIT
mt: 'split'
class Upcase extends RDBOp
tt: protoTermType.UPCASE
mt: 'upcase'
class Downcase extends RDBOp
tt: protoTermType.DOWNCASE
mt: 'downcase'
class IsEmpty extends RDBOp
tt: protoTermType.IS_EMPTY
mt: 'isEmpty'
class Group extends RDBOp
tt: protoTermType.GROUP
mt: 'group'
class Sum extends RDBOp
tt: protoTermType.SUM
mt: 'sum'
class Avg extends RDBOp
tt: protoTermType.AVG
mt: 'avg'
class Min extends RDBOp
tt: protoTermType.MIN
mt: 'min'
class Max extends RDBOp
tt: protoTermType.MAX
mt: 'max'
class InnerJoin extends RDBOp
tt: protoTermType.INNER_JOIN
mt: 'innerJoin'
class OuterJoin extends RDBOp
tt: protoTermType.OUTER_JOIN
mt: 'outerJoin'
class EqJoin extends RDBOp
tt: protoTermType.EQ_JOIN
mt: 'eqJoin'
class Zip extends RDBOp
tt: protoTermType.ZIP
mt: 'zip'
class Range extends RDBOp
tt: protoTermType.RANGE
st: 'range'
class CoerceTo extends RDBOp
tt: protoTermType.COERCE_TO
mt: 'coerceTo'
class Ungroup extends RDBOp
tt: protoTermType.UNGROUP
mt: 'ungroup'
class TypeOf extends RDBOp
tt: protoTermType.TYPE_OF
mt: 'typeOf'
class Info extends RDBOp
tt: protoTermType.INFO
mt: 'info'
class Sample extends RDBOp
tt: protoTermType.SAMPLE
mt: 'sample'
class Update extends RDBOp
tt: protoTermType.UPDATE
mt: 'update'
class Delete extends RDBOp
tt: protoTermType.DELETE
mt: 'delete'
class Replace extends RDBOp
tt: protoTermType.REPLACE
mt: 'replace'
class Insert extends RDBOp
tt: protoTermType.INSERT
mt: 'insert'
class DbCreate extends RDBOp
tt: protoTermType.DB_CREATE
st: 'dbCreate'
class DbDrop extends RDBOp
tt: protoTermType.DB_DROP
st: 'dbDrop'
class DbList extends RDBOp
tt: protoTermType.DB_LIST
st: 'dbList'
class TableCreate extends RDBOp
tt: protoTermType.TABLE_CREATE
mt: 'tableCreate'
class TableDrop extends RDBOp
tt: protoTermType.TABLE_DROP
mt: 'tableDrop'
class TableList extends RDBOp
tt: protoTermType.TABLE_LIST
mt: 'tableList'
class IndexCreate extends RDBOp
tt: protoTermType.INDEX_CREATE
mt: 'indexCreate'
class IndexDrop extends RDBOp
tt: protoTermType.INDEX_DROP
mt: 'indexDrop'
class IndexRename extends RDBOp
tt: protoTermType.INDEX_RENAME
mt: 'indexRename'
class IndexList extends RDBOp
tt: protoTermType.INDEX_LIST
mt: 'indexList'
class IndexStatus extends RDBOp
tt: protoTermType.INDEX_STATUS
mt: 'indexStatus'
class IndexWait extends RDBOp
tt: protoTermType.INDEX_WAIT
mt: 'indexWait'
class Config extends RDBOp
tt: protoTermType.CONFIG
mt: 'config'
class Status extends RDBOp
tt: protoTermType.STATUS
mt: 'status'
class Wait extends RDBOp
tt: protoTermType.WAIT
mt: 'wait'
class Reconfigure extends RDBOp
tt: protoTermType.RECONFIGURE
mt: 'reconfigure'
class Rebalance extends RDBOp
tt: protoTermType.REBALANCE
mt: 'rebalance'
class Sync extends RDBOp
tt: protoTermType.SYNC
mt: 'sync'
class FunCall extends RDBOp
tt: protoTermType.FUNCALL
st: 'do' # This is only used by the `undefined` argument checker
compose: (args) ->
if args.length > 2
['r.do(', intsp(args[1..]), ', ', args[0], ')']
else
if shouldWrap(@args[1])
args[1] = ['r(', args[1], ')']
[args[1], '.do(', args[0], ')']
class Default extends RDBOp
tt: protoTermType.DEFAULT
mt: 'default'
class Branch extends RDBOp
tt: protoTermType.BRANCH
st: 'branch'
class Or extends RDBOp
tt: protoTermType.OR
mt: 'or'
class And extends RDBOp
tt: protoTermType.AND
mt: 'and'
class ForEach extends RDBOp
tt: protoTermType.FOR_EACH
mt: 'forEach'
class Func extends RDBOp
tt: protoTermType.FUNC
@nextVarId: 0
constructor: (optargs, func) ->
args = []