/
functions_ref.go
654 lines (579 loc) · 17.4 KB
/
functions_ref.go
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
package faunadb
// Ref
// Ref creates a new RefV value with the provided ID.
//
// Parameters:
// idOrRef Ref - A class reference or string repr to reference type.
// id string - The document ID.
//
// Returns:
// Ref - A new reference type.
//
// See: https://app.fauna.com/documentation/reference/queryapi#special-type
func Ref(idOrRef interface{}, id ...interface{}) Expr {
switch len(id) {
case 0:
return legacyRefFn{Ref: wrap(idOrRef)}
case 1:
return RefCollection(idOrRef, id[0])
default:
panic("Ref() accepts between 1 and 2 arguments.")
}
}
type legacyRefFn struct {
fnApply
Ref Expr `json:"@ref"`
}
// RefClass creates a new Ref based on the provided class and ID.
//
// Parameters:
// classRef Ref - A class reference.
// id string|int64 - The document ID.
//
// Deprecated: Use RefCollection instead, RefClass is kept for backwards compatibility
//
// Returns:
// Ref - A new reference type.
//
// See: https://app.fauna.com/documentation/reference/queryapi#special-type
func RefClass(classRef, id interface{}) Expr { return refFn{Ref: wrap(classRef), ID: wrap(id)} }
type refFn struct {
fnApply
Ref Expr `json:"ref"`
ID Expr `json:"id,omitempty"`
}
// RefCollection creates a new Ref based on the provided collection and ID.
//
// Parameters:
// collectionRef Ref - A collection reference.
// id string|int64 - The document ID.
//
// Returns:
// Ref - A new reference type.
//
// See: https://app.fauna.com/documentation/reference/queryapi#special-type
func RefCollection(collectionRef, id interface{}) Expr {
return refFn{Ref: wrap(collectionRef), ID: wrap(id)}
}
// Null creates a NullV value.
//
// Returns:
// Value - A null value.
//
// See: https://app.fauna.com/documentation/reference/queryapi#simple-type
func Null() Expr { return NullV{} }
// Database creates a new database ref.
//
// Parameters:
// name string - The name of the database.
//
// Returns:
// Ref - The database reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Database(name interface{}) Expr { return databaseFn{Database: wrap(name), Scope: nil} }
type databaseFn struct {
fnApply
Database Expr `json:"database"`
Scope Expr `json:"scope,omitempty" faunarepr:"scopedfn"`
}
// ScopedDatabase creates a new database ref inside a database.
//
// Parameters:
// name string - The name of the database.
// scope Ref - The reference of the database's scope.
//
// Returns:
// Ref - The database reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedDatabase(name interface{}, scope interface{}) Expr {
return databaseFn{
Database: wrap(name),
Scope: wrap(scope),
}
}
// Index creates a new index ref.
//
// Parameters:
// name string - The name of the index.
//
// Returns:
// Ref - The index reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Index(name interface{}) Expr { return indexFn{Index: wrap(name)} }
type indexFn struct {
fnApply
Index Expr `json:"index"`
Scope Expr `json:"scope,omitempty" faunarepr:"scopedfn"`
}
// ScopedIndex creates a new index ref inside a database.
//
// Parameters:
// name string - The name of the index.
// scope Ref - The reference of the index's scope.
//
// Returns:
// Ref - The index reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedIndex(name interface{}, scope interface{}) Expr {
return indexFn{
Index: wrap(name),
Scope: wrap(scope),
}
}
// Class creates a new class ref.
//
// Parameters:
// name string - The name of the class.
//
// Deprecated: Use Collection instead, Class is kept for backwards compatibility
//
// Returns:
// Ref - The class reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Class(name interface{}) Expr { return classFn{Class: wrap(name)} }
type classFn struct {
fnApply
Class Expr `json:"class"`
Scope Expr `json:"scope,omitempty" faunarepr:"scopedfn"`
}
// Collection creates a new collection ref.
//
// Parameters:
// name string - The name of the collection.
//
// Returns:
// Ref - The collection reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Collection(name interface{}) Expr { return collectionFn{Collection: wrap(name)} }
type collectionFn struct {
fnApply
Collection Expr `json:"collection"`
Scope Expr `json:"scope,omitempty" faunarepr:"scopedfn"`
}
//Documents returns a set of all documents in the given collection.
// A set must be paginated in order to retrieve its values.
//
// Parameters:
// collection ref - a reference to the collection
//
// Returns:
// Expr - A new Expr instance
//
// See: https://docs.fauna.com/fauna/current/api/fql/functions/Documents
func Documents(collection interface{}) Expr {
return documentsFn{Documents: wrap(collection)}
}
type documentsFn struct {
fnApply
Documents Expr `json:"documents"`
}
// ScopedClass creates a new class ref inside a database.
//
// Parameters:
// name string - The name of the class.
// scope Ref - The reference of the class's scope.
//
// Deprecated: Use ScopedCollection instead, ScopedClass is kept for backwards compatibility
//
// Returns:
// Ref - The collection reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedClass(name interface{}, scope interface{}) Expr {
return classFn{Class: wrap(name), Scope: wrap(scope)}
}
// ScopedCollection creates a new collection ref inside a database.
//
// Parameters:
// name string - The name of the collection.
// scope Ref - The reference of the collection's scope.
//
// Returns:
// Ref - The collection reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedCollection(name interface{}, scope interface{}) Expr {
return collectionFn{Collection: wrap(name), Scope: wrap(scope)}
}
// Function create a new function ref.
//
// Parameters:
// name string - The name of the functions.
//
// Returns:
// Ref - The function reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Function(name interface{}) Expr { return functionFn{Function: wrap(name)} }
type functionFn struct {
fnApply
Function Expr `json:"function"`
Scope Expr `json:"scope,omitempty" faunarepr:"scopedfn"`
}
// ScopedFunction creates a new function ref inside a database.
//
// Parameters:
// name string - The name of the function.
// scope Ref - The reference of the function's scope.
//
// Returns:
// Ref - The function reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedFunction(name interface{}, scope interface{}) Expr {
return functionFn{Function: wrap(name), Scope: wrap(scope)}
}
// Role create a new role ref.
//
// Parameters:
// name string - The name of the role.
//
// Returns:
// Ref - The role reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Role(name interface{}) Expr { return roleFn{Role: wrap(name)} }
type roleFn struct {
fnApply
Role Expr `json:"role"`
Scope Expr `json:"scope,omitempty" faunarepr:"scopedfn"`
}
// ScopedRole create a new role ref.
//
// Parameters:
// name string - The name of the role.
// scope Ref - The reference of the role's scope.
//
// Returns:
// Ref - The role reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedRole(name, scope interface{}) Expr { return roleFn{Role: wrap(name), Scope: wrap(scope)} }
// Classes creates a native ref for classes.
//
// Deprecated: Use Collections instead, Classes is kept for backwards compatibility
//
// Returns:
// Ref - The reference of the class set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Classes() Expr { return classesFn{Classes: NullV{}} }
type classesFn struct {
fnApply
Classes Expr `json:"classes" faunarepr:"scopedfn"`
}
// Collections creates a native ref for collections.
//
// Returns:
// Ref - The reference of the collections set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Collections() Expr { return collectionsFn{Collections: NullV{}} }
type collectionsFn struct {
fnApply
Collections Expr `json:"collections" faunarepr:"scopedfn"`
}
// ScopedClasses creates a native ref for classes inside a database.
//
// Parameters:
// scope Ref - The reference of the class set's scope.
//
// Deprecated: Use ScopedCollections instead, ScopedClasses is kept for backwards compatibility
//
// Returns:
// Ref - The reference of the class set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedClasses(scope interface{}) Expr { return classesFn{Classes: wrap(scope)} }
// ScopedCollections creates a native ref for collections inside a database.
//
// Parameters:
// scope Ref - The reference of the collections set's scope.
//
// Returns:
// Ref - The reference of the collections set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedCollections(scope interface{}) Expr {
return collectionsFn{Collections: wrap(scope)}
}
// Indexes creates a native ref for indexes.
//
// Returns:
// Ref - The reference of the index set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Indexes() Expr { return indexesFn{Indexes: NullV{}} }
type indexesFn struct {
fnApply
Indexes Expr `json:"indexes" faunarepr:"scopedfn"`
}
// ScopedIndexes creates a native ref for indexes inside a database.
//
// Parameters:
// scope Ref - The reference of the index set's scope.
//
// Returns:
// Ref - The reference of the index set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedIndexes(scope interface{}) Expr { return indexesFn{Indexes: wrap(scope)} }
// Databases creates a native ref for databases.
//
// Returns:
// Ref - The reference of the datbase set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Databases() Expr { return databasesFn{Databases: NullV{}} }
type databasesFn struct {
fnApply
Databases Expr `json:"databases" faunarepr:"scopedfn"`
}
// ScopedDatabases creates a native ref for databases inside a database.
//
// Parameters:
// scope Ref - The reference of the database set's scope.
//
// Returns:
// Ref - The reference of the database set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedDatabases(scope interface{}) Expr { return databasesFn{Databases: wrap(scope)} }
// Functions creates a native ref for functions.
//
// Returns:
// Ref - The reference of the function set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Functions() Expr { return functionsFn{Functions: NullV{}} }
type functionsFn struct {
fnApply
Functions Expr `json:"functions" faunarepr:"scopedfn"`
}
// ScopedFunctions creates a native ref for functions inside a database.
//
// Parameters:
// scope Ref - The reference of the function set's scope.
//
// Returns:
// Ref - The reference of the function set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedFunctions(scope interface{}) Expr { return functionsFn{Functions: wrap(scope)} }
// Roles creates a native ref for roles.
//
// Returns:
// Ref - The reference of the roles set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Roles() Expr { return rolesFn{Roles: NullV{}} }
type rolesFn struct {
fnApply
Roles Expr `json:"roles" faunarepr:"scopedfn"`
}
// ScopedRoles creates a native ref for roles inside a database.
//
// Parameters:
// scope Ref - The reference of the role set's scope.
//
// Returns:
// Ref - The reference of the role set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedRoles(scope interface{}) Expr { return rolesFn{Roles: wrap(scope)} }
// Keys creates a native ref for keys.
//
// Returns:
// Ref - The reference of the key set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Keys() Expr { return keysFn{Keys: NullV{}} }
type keysFn struct {
fnApply
Keys Expr `json:"keys" faunarepr:"scopedfn"`
}
// ScopedKeys creates a native ref for keys inside a database.
//
// Parameters:
// scope Ref - The reference of the key set's scope.
//
// Returns:
// Ref - The reference of the key set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedKeys(scope interface{}) Expr { return keysFn{Keys: wrap(scope)} }
// Tokens creates a native ref for tokens.
//
// Returns:
// Ref - The reference of the token set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Tokens() Expr { return tokensFn{Tokens: NullV{}} }
type tokensFn struct {
fnApply
Tokens Expr `json:"tokens" faunarepr:"scopedfn"`
}
// ScopedTokens creates a native ref for tokens inside a database.
//
// Parameters:
// scope Ref - The reference of the token set's scope.
//
// Returns:
// Ref - The reference of the token set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedTokens(scope interface{}) Expr { return tokensFn{Tokens: wrap(scope)} }
// Credentials creates a native ref for credentials.
//
// Returns:
// Ref - The reference of the credential set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func Credentials() Expr { return credentialsFn{Credentials: NullV{}} }
// ScopedCredentials creates a native ref for credentials inside a database.
//
// Parameters:
// scope Ref - The reference of the credential set's scope.
//
// Returns:
// Ref - The reference of the credential set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedCredentials(scope interface{}) Expr {
return credentialsFn{Credentials: wrap(scope)}
}
type credentialsFn struct {
fnApply
Credentials Expr `json:"credentials" faunarepr:"scopedfn"`
}
// Miscellaneous
// NextID produces a new identifier suitable for use when constructing refs.
//
// Deprecated: Use NewId instead
//
// Returns:
// string - The new ID.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func NextID() Expr { return nextIDFn{NextID: NullV{}} }
type nextIDFn struct {
fnApply
NextID Expr `json:"next_id" faunarepr:"noargs"`
}
// NewId produces a new identifier suitable for use when constructing refs.
//
// Returns:
// string - The new ID.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func NewId() Expr { return newIDFn{NewId: NullV{}} }
type newIDFn struct {
fnApply
NewId Expr `json:"new_id" faunarepr:"noargs"`
}
// AccessProvider create a new access provider ref.
//
// Parameters:
// name string - The name of the access provider.
//
// Returns:
// Ref - The access provider reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func AccessProvider(name interface{}) Expr {
return accessProviderFn{
AccessProvider: wrap(name),
}
}
// ScopedAccessProvider create a new access provider ref.
//
// Parameters:
// name string - The name of the access provider.
// scope Ref - The reference of the scope.
//
// Returns:
// Ref - The access provider reference.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedAccessProvider(name interface{}, scope interface{}) Expr {
return accessProviderFn{
AccessProvider: wrap(name),
Scope: wrap(scope),
}
}
type accessProviderFn struct {
fnApply
AccessProvider Expr `json:"access_provider"`
Scope Expr `json:"scope,omitempty" faunarepr:"scopedfn"`
}
// AccessProviders creates a native ref for access providers.
//
// Returns:
// Ref - The reference of the access providers set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func AccessProviders() Expr {
return accessProvidersFn{
AccessProviders: NullV{},
}
}
// ScopedAccessProviders creates a native ref for access providers inside a database.
//
// Parameters:
// scope Ref - The reference of the access provider's set scope.
//
// Returns:
// Ref - The reference of the access providers set.
//
// See: https://app.fauna.com/documentation/reference/queryapi#miscellaneous-functions
func ScopedAccessProviders(scope interface{}) Expr {
return accessProvidersFn{
AccessProviders: wrap(scope),
}
}
type accessProvidersFn struct {
fnApply
AccessProviders Expr `json:"access_providers" faunarepr:"scopedfn"`
}
func CurrentIdentity() Expr {
return currentIdentityFn {
CurrentIdentity: NullV{},
}
}
type currentIdentityFn struct {
fnApply
CurrentIdentity Expr `json:"current_identity"`
}
func CurrentToken() Expr {
return currentTokenFn {
CurrentToken: NullV{},
}
}
type currentTokenFn struct {
fnApply
CurrentToken Expr `json:"current_token"`
}
func HasCurrentIdentity() Expr {
return hasCurrentIdentityFn {
HasCurrentIdentity: NullV{},
}
}
type hasCurrentIdentityFn struct {
fnApply
HasCurrentIdentity Expr `json:"has_current_identity"`
}
func HasCurrentToken() Expr {
return hasCurrentTokenFn {
HasCurrentToken: NullV{},
}
}
type hasCurrentTokenFn struct {
fnApply
HasCurrentToken Expr `json:"has_current_token"`
}