@rayfold/conformance 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1456 @@
1
+ {
2
+ "name": "Commands: idempotency, replay, simulate (spec 03 s4)",
3
+ "schema": "\nentity Author { id: ID name: String bio: String? @lazy }\nentity Book @cache(maxAge: 60s, scope: public) {\n id: ID\n title: String\n stock: Int\n author: Author\n secret: String? @allow(read: viewer.role == \"admin\")\n reviews(page: PageArgs = { first: 10 }): Page<Review>\n version: Int @version\n}\ninput BookPatch { title: String? stock: Int? @range(min: 0) secret: String? }\nentity Review { id: ID rating: Int bookId: ID }\nentity Order @allow(read: viewer.id == customerId) { id: ID customerId: ID bookId: ID qty: Int }\nobject Tick { n: Int }\nview Book.default = { id title stock }\nquery book(id: ID): Book?\nquery books(page: PageArgs = { first: 20 }): Page<Book> @cost(base: 5, perItem: 1)\nquery author(id: ID): Author?\nquery order(id: ID): Order? @allow(read: viewer != null)\ncommand buy(bookId: ID, qty: Int = 1 @range(min: 1, max: 10)): Order throws OutOfStock { bookId: ID, available: Int } emits Bought @allow(write: viewer != null) @simulate\ncommand restock(bookId: ID, qty: Int): Book\ncommand patchBook(id: ID, patch: BookPatch): Book\nevent Bought { orderId: ID }\nstream ticks(n: Int): Tick\n",
4
+ "ir": {
5
+ "rayfold": "0.1",
6
+ "types": {
7
+ "ID": {
8
+ "kind": "scalar",
9
+ "name": "ID",
10
+ "annotations": [],
11
+ "builtin": true
12
+ },
13
+ "String": {
14
+ "kind": "scalar",
15
+ "name": "String",
16
+ "annotations": [],
17
+ "builtin": true
18
+ },
19
+ "Int": {
20
+ "kind": "scalar",
21
+ "name": "Int",
22
+ "annotations": [],
23
+ "builtin": true
24
+ },
25
+ "Long": {
26
+ "kind": "scalar",
27
+ "name": "Long",
28
+ "annotations": [],
29
+ "builtin": true
30
+ },
31
+ "Float": {
32
+ "kind": "scalar",
33
+ "name": "Float",
34
+ "annotations": [],
35
+ "builtin": true
36
+ },
37
+ "Boolean": {
38
+ "kind": "scalar",
39
+ "name": "Boolean",
40
+ "annotations": [],
41
+ "builtin": true
42
+ },
43
+ "Decimal": {
44
+ "kind": "scalar",
45
+ "name": "Decimal",
46
+ "annotations": [],
47
+ "builtin": true
48
+ },
49
+ "Instant": {
50
+ "kind": "scalar",
51
+ "name": "Instant",
52
+ "annotations": [],
53
+ "builtin": true
54
+ },
55
+ "Date": {
56
+ "kind": "scalar",
57
+ "name": "Date",
58
+ "annotations": [],
59
+ "builtin": true
60
+ },
61
+ "Duration": {
62
+ "kind": "scalar",
63
+ "name": "Duration",
64
+ "annotations": [],
65
+ "builtin": true
66
+ },
67
+ "Bytes": {
68
+ "kind": "scalar",
69
+ "name": "Bytes",
70
+ "annotations": [],
71
+ "builtin": true
72
+ },
73
+ "JSON": {
74
+ "kind": "scalar",
75
+ "name": "JSON",
76
+ "annotations": [],
77
+ "builtin": true
78
+ },
79
+ "Page": {
80
+ "kind": "object",
81
+ "name": "Page",
82
+ "builtin": true,
83
+ "typeParams": [
84
+ "T"
85
+ ],
86
+ "annotations": [],
87
+ "fields": [
88
+ {
89
+ "name": "items",
90
+ "type": {
91
+ "kind": "list",
92
+ "of": {
93
+ "kind": "named",
94
+ "name": "T",
95
+ "nullable": false
96
+ },
97
+ "nullable": false
98
+ },
99
+ "args": [],
100
+ "annotations": [],
101
+ "ordinal": 1
102
+ },
103
+ {
104
+ "name": "cursor",
105
+ "type": {
106
+ "kind": "named",
107
+ "name": "String",
108
+ "nullable": true
109
+ },
110
+ "args": [],
111
+ "annotations": [],
112
+ "ordinal": 2
113
+ },
114
+ {
115
+ "name": "hasMore",
116
+ "type": {
117
+ "kind": "named",
118
+ "name": "Boolean",
119
+ "nullable": false
120
+ },
121
+ "args": [],
122
+ "annotations": [],
123
+ "ordinal": 3
124
+ },
125
+ {
126
+ "name": "total",
127
+ "type": {
128
+ "kind": "named",
129
+ "name": "Int",
130
+ "nullable": true
131
+ },
132
+ "args": [],
133
+ "annotations": [],
134
+ "ordinal": 4
135
+ }
136
+ ]
137
+ },
138
+ "PageArgs": {
139
+ "kind": "input",
140
+ "name": "PageArgs",
141
+ "builtin": true,
142
+ "annotations": [],
143
+ "fields": [
144
+ {
145
+ "name": "first",
146
+ "type": {
147
+ "kind": "named",
148
+ "name": "Int",
149
+ "nullable": false
150
+ },
151
+ "args": [],
152
+ "default": 20,
153
+ "annotations": [],
154
+ "ordinal": 1
155
+ },
156
+ {
157
+ "name": "after",
158
+ "type": {
159
+ "kind": "named",
160
+ "name": "String",
161
+ "nullable": true
162
+ },
163
+ "args": [],
164
+ "annotations": [],
165
+ "ordinal": 2
166
+ },
167
+ {
168
+ "name": "offset",
169
+ "type": {
170
+ "kind": "named",
171
+ "name": "Int",
172
+ "nullable": true
173
+ },
174
+ "args": [],
175
+ "annotations": [],
176
+ "ordinal": 3
177
+ }
178
+ ]
179
+ },
180
+ "Author": {
181
+ "kind": "entity",
182
+ "name": "Author",
183
+ "annotations": [],
184
+ "fields": [
185
+ {
186
+ "name": "id",
187
+ "type": {
188
+ "kind": "named",
189
+ "name": "ID",
190
+ "nullable": false
191
+ },
192
+ "args": [],
193
+ "annotations": [],
194
+ "ordinal": 1
195
+ },
196
+ {
197
+ "name": "name",
198
+ "type": {
199
+ "kind": "named",
200
+ "name": "String",
201
+ "nullable": false
202
+ },
203
+ "args": [],
204
+ "annotations": [],
205
+ "ordinal": 2
206
+ },
207
+ {
208
+ "name": "bio",
209
+ "type": {
210
+ "kind": "named",
211
+ "name": "String",
212
+ "nullable": true
213
+ },
214
+ "args": [],
215
+ "annotations": [
216
+ {
217
+ "name": "lazy",
218
+ "args": {}
219
+ }
220
+ ],
221
+ "ordinal": 3
222
+ }
223
+ ],
224
+ "implements": []
225
+ },
226
+ "Book": {
227
+ "kind": "entity",
228
+ "name": "Book",
229
+ "annotations": [
230
+ {
231
+ "name": "cache",
232
+ "args": {
233
+ "maxAge": {
234
+ "$duration": 60000
235
+ },
236
+ "scope": {
237
+ "$ident": "public"
238
+ }
239
+ }
240
+ }
241
+ ],
242
+ "fields": [
243
+ {
244
+ "name": "id",
245
+ "type": {
246
+ "kind": "named",
247
+ "name": "ID",
248
+ "nullable": false
249
+ },
250
+ "args": [],
251
+ "annotations": [],
252
+ "ordinal": 1
253
+ },
254
+ {
255
+ "name": "title",
256
+ "type": {
257
+ "kind": "named",
258
+ "name": "String",
259
+ "nullable": false
260
+ },
261
+ "args": [],
262
+ "annotations": [],
263
+ "ordinal": 2
264
+ },
265
+ {
266
+ "name": "stock",
267
+ "type": {
268
+ "kind": "named",
269
+ "name": "Int",
270
+ "nullable": false
271
+ },
272
+ "args": [],
273
+ "annotations": [],
274
+ "ordinal": 3
275
+ },
276
+ {
277
+ "name": "author",
278
+ "type": {
279
+ "kind": "named",
280
+ "name": "Author",
281
+ "nullable": false
282
+ },
283
+ "args": [],
284
+ "annotations": [],
285
+ "ordinal": 4
286
+ },
287
+ {
288
+ "name": "secret",
289
+ "type": {
290
+ "kind": "named",
291
+ "name": "String",
292
+ "nullable": true
293
+ },
294
+ "args": [],
295
+ "annotations": [
296
+ {
297
+ "name": "allow",
298
+ "args": {
299
+ "read": {
300
+ "$expr": {
301
+ "k": "bin",
302
+ "op": "==",
303
+ "l": {
304
+ "k": "path",
305
+ "root": "viewer",
306
+ "path": [
307
+ "role"
308
+ ]
309
+ },
310
+ "r": {
311
+ "k": "lit",
312
+ "v": "admin"
313
+ }
314
+ }
315
+ }
316
+ }
317
+ }
318
+ ],
319
+ "ordinal": 5
320
+ },
321
+ {
322
+ "name": "reviews",
323
+ "type": {
324
+ "kind": "named",
325
+ "name": "Page",
326
+ "nullable": false,
327
+ "args": [
328
+ {
329
+ "kind": "named",
330
+ "name": "Review",
331
+ "nullable": false
332
+ }
333
+ ]
334
+ },
335
+ "args": [
336
+ {
337
+ "name": "page",
338
+ "type": {
339
+ "kind": "named",
340
+ "name": "PageArgs",
341
+ "nullable": false
342
+ },
343
+ "annotations": [],
344
+ "default": {
345
+ "first": 10
346
+ }
347
+ }
348
+ ],
349
+ "annotations": [],
350
+ "ordinal": 6
351
+ },
352
+ {
353
+ "name": "version",
354
+ "type": {
355
+ "kind": "named",
356
+ "name": "Int",
357
+ "nullable": false
358
+ },
359
+ "args": [],
360
+ "annotations": [
361
+ {
362
+ "name": "version",
363
+ "args": {}
364
+ }
365
+ ],
366
+ "ordinal": 7
367
+ }
368
+ ],
369
+ "implements": []
370
+ },
371
+ "BookPatch": {
372
+ "kind": "input",
373
+ "name": "BookPatch",
374
+ "annotations": [],
375
+ "fields": [
376
+ {
377
+ "name": "title",
378
+ "type": {
379
+ "kind": "named",
380
+ "name": "String",
381
+ "nullable": true
382
+ },
383
+ "args": [],
384
+ "annotations": [],
385
+ "ordinal": 1
386
+ },
387
+ {
388
+ "name": "stock",
389
+ "type": {
390
+ "kind": "named",
391
+ "name": "Int",
392
+ "nullable": true
393
+ },
394
+ "args": [],
395
+ "annotations": [
396
+ {
397
+ "name": "range",
398
+ "args": {
399
+ "min": 0
400
+ }
401
+ }
402
+ ],
403
+ "ordinal": 2
404
+ },
405
+ {
406
+ "name": "secret",
407
+ "type": {
408
+ "kind": "named",
409
+ "name": "String",
410
+ "nullable": true
411
+ },
412
+ "args": [],
413
+ "annotations": [],
414
+ "ordinal": 3
415
+ }
416
+ ]
417
+ },
418
+ "Review": {
419
+ "kind": "entity",
420
+ "name": "Review",
421
+ "annotations": [],
422
+ "fields": [
423
+ {
424
+ "name": "id",
425
+ "type": {
426
+ "kind": "named",
427
+ "name": "ID",
428
+ "nullable": false
429
+ },
430
+ "args": [],
431
+ "annotations": [],
432
+ "ordinal": 1
433
+ },
434
+ {
435
+ "name": "rating",
436
+ "type": {
437
+ "kind": "named",
438
+ "name": "Int",
439
+ "nullable": false
440
+ },
441
+ "args": [],
442
+ "annotations": [],
443
+ "ordinal": 2
444
+ },
445
+ {
446
+ "name": "bookId",
447
+ "type": {
448
+ "kind": "named",
449
+ "name": "ID",
450
+ "nullable": false
451
+ },
452
+ "args": [],
453
+ "annotations": [],
454
+ "ordinal": 3
455
+ }
456
+ ],
457
+ "implements": []
458
+ },
459
+ "Order": {
460
+ "kind": "entity",
461
+ "name": "Order",
462
+ "annotations": [
463
+ {
464
+ "name": "allow",
465
+ "args": {
466
+ "read": {
467
+ "$expr": {
468
+ "k": "bin",
469
+ "op": "==",
470
+ "l": {
471
+ "k": "path",
472
+ "root": "viewer",
473
+ "path": [
474
+ "id"
475
+ ]
476
+ },
477
+ "r": {
478
+ "k": "path",
479
+ "root": "this",
480
+ "path": [
481
+ "customerId"
482
+ ]
483
+ }
484
+ }
485
+ }
486
+ }
487
+ }
488
+ ],
489
+ "fields": [
490
+ {
491
+ "name": "id",
492
+ "type": {
493
+ "kind": "named",
494
+ "name": "ID",
495
+ "nullable": false
496
+ },
497
+ "args": [],
498
+ "annotations": [],
499
+ "ordinal": 1
500
+ },
501
+ {
502
+ "name": "customerId",
503
+ "type": {
504
+ "kind": "named",
505
+ "name": "ID",
506
+ "nullable": false
507
+ },
508
+ "args": [],
509
+ "annotations": [],
510
+ "ordinal": 2
511
+ },
512
+ {
513
+ "name": "bookId",
514
+ "type": {
515
+ "kind": "named",
516
+ "name": "ID",
517
+ "nullable": false
518
+ },
519
+ "args": [],
520
+ "annotations": [],
521
+ "ordinal": 3
522
+ },
523
+ {
524
+ "name": "qty",
525
+ "type": {
526
+ "kind": "named",
527
+ "name": "Int",
528
+ "nullable": false
529
+ },
530
+ "args": [],
531
+ "annotations": [],
532
+ "ordinal": 4
533
+ }
534
+ ],
535
+ "implements": []
536
+ },
537
+ "Tick": {
538
+ "kind": "object",
539
+ "name": "Tick",
540
+ "annotations": [],
541
+ "fields": [
542
+ {
543
+ "name": "n",
544
+ "type": {
545
+ "kind": "named",
546
+ "name": "Int",
547
+ "nullable": false
548
+ },
549
+ "args": [],
550
+ "annotations": [],
551
+ "ordinal": 1
552
+ }
553
+ ]
554
+ },
555
+ "OutOfStock": {
556
+ "kind": "error",
557
+ "name": "OutOfStock",
558
+ "annotations": [],
559
+ "fields": [
560
+ {
561
+ "name": "bookId",
562
+ "type": {
563
+ "kind": "named",
564
+ "name": "ID",
565
+ "nullable": false
566
+ },
567
+ "args": [],
568
+ "annotations": [],
569
+ "ordinal": 1
570
+ },
571
+ {
572
+ "name": "available",
573
+ "type": {
574
+ "kind": "named",
575
+ "name": "Int",
576
+ "nullable": false
577
+ },
578
+ "args": [],
579
+ "annotations": [],
580
+ "ordinal": 2
581
+ }
582
+ ]
583
+ },
584
+ "Bought": {
585
+ "kind": "event",
586
+ "name": "Bought",
587
+ "annotations": [],
588
+ "fields": [
589
+ {
590
+ "name": "orderId",
591
+ "type": {
592
+ "kind": "named",
593
+ "name": "ID",
594
+ "nullable": false
595
+ },
596
+ "args": [],
597
+ "annotations": [],
598
+ "ordinal": 1
599
+ }
600
+ ]
601
+ }
602
+ },
603
+ "ops": {
604
+ "book": {
605
+ "kind": "query",
606
+ "name": "book",
607
+ "args": [
608
+ {
609
+ "name": "id",
610
+ "type": {
611
+ "kind": "named",
612
+ "name": "ID",
613
+ "nullable": false
614
+ },
615
+ "annotations": []
616
+ }
617
+ ],
618
+ "returns": {
619
+ "kind": "named",
620
+ "name": "Book",
621
+ "nullable": true
622
+ },
623
+ "throws": [],
624
+ "emits": [],
625
+ "annotations": []
626
+ },
627
+ "books": {
628
+ "kind": "query",
629
+ "name": "books",
630
+ "args": [
631
+ {
632
+ "name": "page",
633
+ "type": {
634
+ "kind": "named",
635
+ "name": "PageArgs",
636
+ "nullable": false
637
+ },
638
+ "annotations": [],
639
+ "default": {
640
+ "first": 20
641
+ }
642
+ }
643
+ ],
644
+ "returns": {
645
+ "kind": "named",
646
+ "name": "Page",
647
+ "nullable": false,
648
+ "args": [
649
+ {
650
+ "kind": "named",
651
+ "name": "Book",
652
+ "nullable": false
653
+ }
654
+ ]
655
+ },
656
+ "throws": [],
657
+ "emits": [],
658
+ "annotations": [
659
+ {
660
+ "name": "cost",
661
+ "args": {
662
+ "base": 5,
663
+ "perItem": 1
664
+ }
665
+ }
666
+ ]
667
+ },
668
+ "author": {
669
+ "kind": "query",
670
+ "name": "author",
671
+ "args": [
672
+ {
673
+ "name": "id",
674
+ "type": {
675
+ "kind": "named",
676
+ "name": "ID",
677
+ "nullable": false
678
+ },
679
+ "annotations": []
680
+ }
681
+ ],
682
+ "returns": {
683
+ "kind": "named",
684
+ "name": "Author",
685
+ "nullable": true
686
+ },
687
+ "throws": [],
688
+ "emits": [],
689
+ "annotations": []
690
+ },
691
+ "order": {
692
+ "kind": "query",
693
+ "name": "order",
694
+ "args": [
695
+ {
696
+ "name": "id",
697
+ "type": {
698
+ "kind": "named",
699
+ "name": "ID",
700
+ "nullable": false
701
+ },
702
+ "annotations": []
703
+ }
704
+ ],
705
+ "returns": {
706
+ "kind": "named",
707
+ "name": "Order",
708
+ "nullable": true
709
+ },
710
+ "throws": [],
711
+ "emits": [],
712
+ "annotations": [
713
+ {
714
+ "name": "allow",
715
+ "args": {
716
+ "read": {
717
+ "$expr": {
718
+ "k": "bin",
719
+ "op": "!=",
720
+ "l": {
721
+ "k": "path",
722
+ "root": "viewer",
723
+ "path": []
724
+ },
725
+ "r": {
726
+ "k": "lit",
727
+ "v": null
728
+ }
729
+ }
730
+ }
731
+ }
732
+ }
733
+ ]
734
+ },
735
+ "buy": {
736
+ "kind": "command",
737
+ "name": "buy",
738
+ "args": [
739
+ {
740
+ "name": "bookId",
741
+ "type": {
742
+ "kind": "named",
743
+ "name": "ID",
744
+ "nullable": false
745
+ },
746
+ "annotations": []
747
+ },
748
+ {
749
+ "name": "qty",
750
+ "type": {
751
+ "kind": "named",
752
+ "name": "Int",
753
+ "nullable": false
754
+ },
755
+ "annotations": [
756
+ {
757
+ "name": "range",
758
+ "args": {
759
+ "min": 1,
760
+ "max": 10
761
+ }
762
+ }
763
+ ],
764
+ "default": 1
765
+ }
766
+ ],
767
+ "returns": {
768
+ "kind": "named",
769
+ "name": "Order",
770
+ "nullable": false
771
+ },
772
+ "throws": [
773
+ "OutOfStock"
774
+ ],
775
+ "emits": [
776
+ "Bought"
777
+ ],
778
+ "annotations": [
779
+ {
780
+ "name": "allow",
781
+ "args": {
782
+ "write": {
783
+ "$expr": {
784
+ "k": "bin",
785
+ "op": "!=",
786
+ "l": {
787
+ "k": "path",
788
+ "root": "viewer",
789
+ "path": []
790
+ },
791
+ "r": {
792
+ "k": "lit",
793
+ "v": null
794
+ }
795
+ }
796
+ }
797
+ }
798
+ },
799
+ {
800
+ "name": "simulate",
801
+ "args": {}
802
+ }
803
+ ]
804
+ },
805
+ "restock": {
806
+ "kind": "command",
807
+ "name": "restock",
808
+ "args": [
809
+ {
810
+ "name": "bookId",
811
+ "type": {
812
+ "kind": "named",
813
+ "name": "ID",
814
+ "nullable": false
815
+ },
816
+ "annotations": []
817
+ },
818
+ {
819
+ "name": "qty",
820
+ "type": {
821
+ "kind": "named",
822
+ "name": "Int",
823
+ "nullable": false
824
+ },
825
+ "annotations": []
826
+ }
827
+ ],
828
+ "returns": {
829
+ "kind": "named",
830
+ "name": "Book",
831
+ "nullable": false
832
+ },
833
+ "throws": [],
834
+ "emits": [],
835
+ "annotations": []
836
+ },
837
+ "patchBook": {
838
+ "kind": "command",
839
+ "name": "patchBook",
840
+ "args": [
841
+ {
842
+ "name": "id",
843
+ "type": {
844
+ "kind": "named",
845
+ "name": "ID",
846
+ "nullable": false
847
+ },
848
+ "annotations": []
849
+ },
850
+ {
851
+ "name": "patch",
852
+ "type": {
853
+ "kind": "named",
854
+ "name": "BookPatch",
855
+ "nullable": false
856
+ },
857
+ "annotations": []
858
+ }
859
+ ],
860
+ "returns": {
861
+ "kind": "named",
862
+ "name": "Book",
863
+ "nullable": false
864
+ },
865
+ "throws": [],
866
+ "emits": [],
867
+ "annotations": []
868
+ },
869
+ "ticks": {
870
+ "kind": "stream",
871
+ "name": "ticks",
872
+ "args": [
873
+ {
874
+ "name": "n",
875
+ "type": {
876
+ "kind": "named",
877
+ "name": "Int",
878
+ "nullable": false
879
+ },
880
+ "annotations": []
881
+ }
882
+ ],
883
+ "returns": {
884
+ "kind": "named",
885
+ "name": "Tick",
886
+ "nullable": false
887
+ },
888
+ "throws": [],
889
+ "emits": [],
890
+ "annotations": []
891
+ }
892
+ },
893
+ "views": {
894
+ "Book.default": {
895
+ "type": "Book",
896
+ "name": "default",
897
+ "shape": {
898
+ "items": [
899
+ {
900
+ "kind": "field",
901
+ "name": "id"
902
+ },
903
+ {
904
+ "kind": "field",
905
+ "name": "title"
906
+ },
907
+ {
908
+ "kind": "field",
909
+ "name": "stock"
910
+ }
911
+ ]
912
+ }
913
+ }
914
+ }
915
+ },
916
+ "data": {
917
+ "Author": [
918
+ {
919
+ "id": "a1",
920
+ "name": "Ann",
921
+ "bio": "Writes."
922
+ },
923
+ {
924
+ "id": "a2",
925
+ "name": "Bob",
926
+ "bio": null
927
+ }
928
+ ],
929
+ "Book": [
930
+ {
931
+ "id": "b1",
932
+ "title": "T1",
933
+ "stock": 2,
934
+ "authorId": "a1",
935
+ "secret": "s1",
936
+ "version": 1
937
+ },
938
+ {
939
+ "id": "b2",
940
+ "title": "T2",
941
+ "stock": 0,
942
+ "authorId": "a2",
943
+ "secret": "s2",
944
+ "version": 1
945
+ }
946
+ ],
947
+ "Review": [
948
+ {
949
+ "id": "r1",
950
+ "rating": 5,
951
+ "bookId": "b1"
952
+ },
953
+ {
954
+ "id": "r2",
955
+ "rating": 3,
956
+ "bookId": "b1"
957
+ },
958
+ {
959
+ "id": "r3",
960
+ "rating": 4,
961
+ "bookId": "b2"
962
+ }
963
+ ],
964
+ "Order": [
965
+ {
966
+ "id": "o0",
967
+ "customerId": "u1",
968
+ "bookId": "b1",
969
+ "qty": 1
970
+ }
971
+ ]
972
+ },
973
+ "resolvers": {
974
+ "Query": {
975
+ "book": {
976
+ "from": "Book",
977
+ "where": {
978
+ "id": "$args.id"
979
+ },
980
+ "mode": "one"
981
+ },
982
+ "books": {
983
+ "from": "Book",
984
+ "mode": "page"
985
+ },
986
+ "author": {
987
+ "from": "Author",
988
+ "where": {
989
+ "id": "$args.id"
990
+ },
991
+ "mode": "one"
992
+ },
993
+ "order": {
994
+ "from": "Order",
995
+ "where": {
996
+ "id": "$args.id"
997
+ },
998
+ "mode": "one"
999
+ }
1000
+ },
1001
+ "fields": {
1002
+ "Book": {
1003
+ "author": {
1004
+ "from": "Author",
1005
+ "key": "authorId",
1006
+ "match": "id",
1007
+ "mode": "one"
1008
+ },
1009
+ "reviews": {
1010
+ "from": "Review",
1011
+ "key": "id",
1012
+ "match": "bookId",
1013
+ "mode": "page"
1014
+ }
1015
+ }
1016
+ },
1017
+ "Command": {
1018
+ "buy": {
1019
+ "fail": [
1020
+ {
1021
+ "when": {
1022
+ "from": "Book",
1023
+ "where": {
1024
+ "id": "$args.bookId"
1025
+ },
1026
+ "field": "stock",
1027
+ "op": "lt",
1028
+ "value": "$args.qty"
1029
+ },
1030
+ "type": "OutOfStock",
1031
+ "data": {
1032
+ "bookId": "$args.bookId",
1033
+ "available": "$row.stock"
1034
+ },
1035
+ "message": "Out of stock"
1036
+ }
1037
+ ],
1038
+ "update": {
1039
+ "table": "Book",
1040
+ "where": {
1041
+ "id": "$args.bookId"
1042
+ },
1043
+ "set": {
1044
+ "stock": {
1045
+ "$sub": "$args.qty"
1046
+ }
1047
+ }
1048
+ },
1049
+ "insert": {
1050
+ "into": "Order",
1051
+ "row": {
1052
+ "customerId": "$viewer.id",
1053
+ "bookId": "$args.bookId",
1054
+ "qty": "$args.qty"
1055
+ },
1056
+ "idPrefix": "o"
1057
+ },
1058
+ "returns": "inserted",
1059
+ "patch": [
1060
+ {
1061
+ "invOp": [
1062
+ "books"
1063
+ ]
1064
+ }
1065
+ ],
1066
+ "emit": [
1067
+ {
1068
+ "event": "Bought",
1069
+ "payload": {
1070
+ "orderId": "$row.id"
1071
+ }
1072
+ }
1073
+ ]
1074
+ },
1075
+ "restock": {
1076
+ "update": {
1077
+ "table": "Book",
1078
+ "where": {
1079
+ "id": "$args.bookId"
1080
+ },
1081
+ "set": {
1082
+ "stock": {
1083
+ "$add": "$args.qty"
1084
+ }
1085
+ }
1086
+ },
1087
+ "returns": "updated"
1088
+ },
1089
+ "patchBook": {
1090
+ "update": {
1091
+ "table": "Book",
1092
+ "where": {
1093
+ "id": "$args.id"
1094
+ },
1095
+ "merge": "$args.patch",
1096
+ "version": "version"
1097
+ },
1098
+ "returns": "updated"
1099
+ }
1100
+ },
1101
+ "Stream": {
1102
+ "ticks": {
1103
+ "items": [
1104
+ {
1105
+ "n": 1
1106
+ },
1107
+ {
1108
+ "n": 2
1109
+ }
1110
+ ]
1111
+ }
1112
+ }
1113
+ },
1114
+ "cases": [
1115
+ {
1116
+ "name": "a command without an idempotency key is rejected",
1117
+ "request": {
1118
+ "ops": [
1119
+ {
1120
+ "id": 1,
1121
+ "op": "restock",
1122
+ "args": {
1123
+ "bookId": "b1",
1124
+ "qty": 1
1125
+ }
1126
+ }
1127
+ ]
1128
+ },
1129
+ "frames": [
1130
+ {
1131
+ "id": 1,
1132
+ "error": {
1133
+ "code": "invalid_argument",
1134
+ "message": "restock(): commands require an idempotency key of 16-128 characters"
1135
+ },
1136
+ "fin": true
1137
+ }
1138
+ ],
1139
+ "calls": {}
1140
+ },
1141
+ {
1142
+ "name": "a repeated key replays the stored frame without re-executing",
1143
+ "request": {
1144
+ "ops": [
1145
+ {
1146
+ "id": 1,
1147
+ "op": "restock",
1148
+ "args": {
1149
+ "bookId": "b1",
1150
+ "qty": 1
1151
+ },
1152
+ "key": "kkkkkkkkkkkkkkkk"
1153
+ }
1154
+ ]
1155
+ },
1156
+ "frames": [
1157
+ {
1158
+ "id": 1,
1159
+ "ok": {
1160
+ "$type": "Book",
1161
+ "id": "b1",
1162
+ "title": "T1",
1163
+ "stock": 3
1164
+ },
1165
+ "patch": [
1166
+ {
1167
+ "set": "Book:b1",
1168
+ "value": {
1169
+ "$type": "Book",
1170
+ "id": "b1",
1171
+ "title": "T1",
1172
+ "stock": 3
1173
+ }
1174
+ }
1175
+ ],
1176
+ "meta": {
1177
+ "cost": 1,
1178
+ "replay": true
1179
+ },
1180
+ "fin": true
1181
+ }
1182
+ ],
1183
+ "viewer": {
1184
+ "id": "u1",
1185
+ "role": "customer"
1186
+ },
1187
+ "calls": {
1188
+ "Command.restock": 1
1189
+ },
1190
+ "repeat": 2
1191
+ },
1192
+ {
1193
+ "name": "the same key with different args is already_exists",
1194
+ "request": {
1195
+ "ops": [
1196
+ {
1197
+ "id": 1,
1198
+ "op": "restock",
1199
+ "args": {
1200
+ "bookId": "b1",
1201
+ "qty": 1
1202
+ },
1203
+ "key": "kkkkkkkkkkkkkkkk"
1204
+ },
1205
+ {
1206
+ "id": 2,
1207
+ "op": "restock",
1208
+ "args": {
1209
+ "bookId": "b1",
1210
+ "qty": 2
1211
+ },
1212
+ "key": "kkkkkkkkkkkkkkkk"
1213
+ }
1214
+ ]
1215
+ },
1216
+ "frames": [
1217
+ {
1218
+ "id": 1,
1219
+ "ok": {
1220
+ "$type": "Book",
1221
+ "id": "b1",
1222
+ "title": "T1",
1223
+ "stock": 3
1224
+ },
1225
+ "patch": [
1226
+ {
1227
+ "set": "Book:b1",
1228
+ "value": {
1229
+ "$type": "Book",
1230
+ "id": "b1",
1231
+ "title": "T1",
1232
+ "stock": 3
1233
+ }
1234
+ }
1235
+ ],
1236
+ "meta": {
1237
+ "cost": 1
1238
+ },
1239
+ "fin": true
1240
+ },
1241
+ {
1242
+ "id": 2,
1243
+ "error": {
1244
+ "code": "already_exists",
1245
+ "message": "Idempotency key kkkkkkkkkkkkkkkk was used for another operation or other arguments"
1246
+ },
1247
+ "fin": true
1248
+ }
1249
+ ],
1250
+ "viewer": {
1251
+ "id": "u1",
1252
+ "role": "customer"
1253
+ },
1254
+ "calls": {
1255
+ "Command.restock": 1
1256
+ }
1257
+ },
1258
+ {
1259
+ "name": "a key can never replay another operation's result",
1260
+ "request": {
1261
+ "ops": [
1262
+ {
1263
+ "id": 1,
1264
+ "op": "restock",
1265
+ "args": {
1266
+ "bookId": "b1",
1267
+ "qty": 1
1268
+ },
1269
+ "key": "kkkkkkkkkkkkkkkk"
1270
+ },
1271
+ {
1272
+ "id": 2,
1273
+ "op": "patchBook",
1274
+ "args": {
1275
+ "id": "b1",
1276
+ "patch": {
1277
+ "stock": 9
1278
+ }
1279
+ },
1280
+ "key": "kkkkkkkkkkkkkkkk"
1281
+ }
1282
+ ]
1283
+ },
1284
+ "frames": [
1285
+ {
1286
+ "id": 1,
1287
+ "ok": {
1288
+ "$type": "Book",
1289
+ "id": "b1",
1290
+ "title": "T1",
1291
+ "stock": 3
1292
+ },
1293
+ "patch": [
1294
+ {
1295
+ "set": "Book:b1",
1296
+ "value": {
1297
+ "$type": "Book",
1298
+ "id": "b1",
1299
+ "title": "T1",
1300
+ "stock": 3
1301
+ }
1302
+ }
1303
+ ],
1304
+ "meta": {
1305
+ "cost": 1
1306
+ },
1307
+ "fin": true
1308
+ },
1309
+ {
1310
+ "id": 2,
1311
+ "error": {
1312
+ "code": "already_exists",
1313
+ "message": "Idempotency key kkkkkkkkkkkkkkkk was used for another operation or other arguments"
1314
+ },
1315
+ "fin": true
1316
+ }
1317
+ ],
1318
+ "viewer": {
1319
+ "id": "u1",
1320
+ "role": "customer"
1321
+ },
1322
+ "calls": {
1323
+ "Command.restock": 1
1324
+ }
1325
+ },
1326
+ {
1327
+ "name": "an anonymous caller cannot use an idempotency key (anonymous callers would share one replay scope)",
1328
+ "request": {
1329
+ "ops": [
1330
+ {
1331
+ "id": 1,
1332
+ "op": "restock",
1333
+ "args": {
1334
+ "bookId": "b1",
1335
+ "qty": 1
1336
+ },
1337
+ "key": "kkkkkkkkkkkkkkkk"
1338
+ }
1339
+ ]
1340
+ },
1341
+ "frames": [
1342
+ {
1343
+ "id": 1,
1344
+ "error": {
1345
+ "code": "unauthenticated",
1346
+ "message": "restock(): idempotency keys need an identified caller"
1347
+ },
1348
+ "fin": true
1349
+ }
1350
+ ],
1351
+ "calls": {}
1352
+ },
1353
+ {
1354
+ "name": "simulate is refused for a command that does not declare @simulate",
1355
+ "request": {
1356
+ "ops": [
1357
+ {
1358
+ "id": 1,
1359
+ "op": "restock",
1360
+ "args": {
1361
+ "bookId": "b1",
1362
+ "qty": 1
1363
+ },
1364
+ "key": "kkkkkkkkkkkkkkkk",
1365
+ "simulate": true
1366
+ }
1367
+ ]
1368
+ },
1369
+ "frames": [
1370
+ {
1371
+ "id": 1,
1372
+ "error": {
1373
+ "code": "failed_precondition",
1374
+ "message": "restock() does not support dry runs"
1375
+ },
1376
+ "fin": true
1377
+ }
1378
+ ],
1379
+ "viewer": {
1380
+ "id": "u1",
1381
+ "role": "customer"
1382
+ },
1383
+ "calls": {}
1384
+ },
1385
+ {
1386
+ "name": "simulate returns the would-be result and patches without committing",
1387
+ "request": {
1388
+ "ops": [
1389
+ {
1390
+ "id": 1,
1391
+ "op": "buy",
1392
+ "args": {
1393
+ "bookId": "b1"
1394
+ },
1395
+ "key": "kkkkkkkkkkkkkkkk",
1396
+ "simulate": true
1397
+ },
1398
+ {
1399
+ "id": 2,
1400
+ "op": "order",
1401
+ "args": {
1402
+ "id": {
1403
+ "$ref": "1.id"
1404
+ }
1405
+ }
1406
+ }
1407
+ ]
1408
+ },
1409
+ "frames": [
1410
+ {
1411
+ "id": 1,
1412
+ "ok": {
1413
+ "$type": "Order",
1414
+ "id": "o1",
1415
+ "customerId": "u1",
1416
+ "bookId": "b1",
1417
+ "qty": 1
1418
+ },
1419
+ "patch": [
1420
+ {
1421
+ "set": "Order:o1",
1422
+ "value": {
1423
+ "$type": "Order",
1424
+ "id": "o1",
1425
+ "customerId": "u1",
1426
+ "bookId": "b1",
1427
+ "qty": 1
1428
+ }
1429
+ },
1430
+ {
1431
+ "invOp": [
1432
+ "books"
1433
+ ]
1434
+ }
1435
+ ],
1436
+ "meta": {
1437
+ "cost": 1
1438
+ },
1439
+ "fin": true
1440
+ },
1441
+ {
1442
+ "id": 2,
1443
+ "data": null,
1444
+ "meta": {
1445
+ "cost": 1
1446
+ },
1447
+ "fin": true
1448
+ }
1449
+ ],
1450
+ "viewer": {
1451
+ "id": "u1",
1452
+ "role": "customer"
1453
+ }
1454
+ }
1455
+ ]
1456
+ }