@altopelago/sansa 0.9.0 → 0.10.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,1280 @@
1
+ export const defaultPolicy = {
2
+ default: 'deny',
3
+ rules: [
4
+ {
5
+ allow: true,
6
+ operations: ['replace'],
7
+ target: '$.inventory.items.*.sku',
8
+ datatype: 'string',
9
+ },
10
+ {
11
+ allow: true,
12
+ operations: ['replace'],
13
+ target: '$.inventory.items.*.qty',
14
+ datatypes: ['number', 'int32'],
15
+ },
16
+ {
17
+ allow: true,
18
+ operations: ['create'],
19
+ parent: '$.inventory.items.*',
20
+ names: ['status'],
21
+ datatype: 'string',
22
+ values: ['pending', 'active'],
23
+ },
24
+ {
25
+ allow: true,
26
+ operations: ['remove'],
27
+ target: '$.inventory.items.*.metric',
28
+ },
29
+ {
30
+ allow: true,
31
+ operations: ['insert'],
32
+ container: '$.inventory.items.*.roles',
33
+ datatype: 'string',
34
+ values: ['admin', 'user'],
35
+ },
36
+ {
37
+ allow: true,
38
+ operations: ['move'],
39
+ source: '$.inventory.items.*.roles.*',
40
+ container: '$.inventory.items.*.roles',
41
+ },
42
+ ],
43
+ };
44
+
45
+ const allowQtyPolicySource = JSON.stringify({
46
+ default: 'deny',
47
+ rules: [
48
+ {
49
+ allow: true,
50
+ operations: ['replace'],
51
+ target: '$.inventory.items.*.qty',
52
+ datatypes: ['number', 'int32'],
53
+ },
54
+ ],
55
+ }, null, 2);
56
+
57
+ const denySkuPolicySource = JSON.stringify({
58
+ default: 'allow',
59
+ rules: [
60
+ {
61
+ allow: false,
62
+ operations: ['replace'],
63
+ target: '$.inventory.items.*.sku',
64
+ },
65
+ ],
66
+ }, null, 2);
67
+
68
+ export const mutateExamples = [
69
+ {
70
+ id: 'replace-sku',
71
+ label: 'Replace SKU',
72
+ group: 'Core Mutations',
73
+ variants: {
74
+ structured: {
75
+ request: {
76
+ operations: [
77
+ { op: 'replace', target: '$.inventory.items[0].sku', value: 'A-101' },
78
+ ],
79
+ preconditions: [
80
+ { expression: '$.inventory.items[0].sku == "A-100"' },
81
+ ],
82
+ provenance: { source: 'mutate-workbench' },
83
+ },
84
+ },
85
+ instruction: {
86
+ request: [
87
+ 'because "manual correction"',
88
+ 'by "Bob"',
89
+ 'from $.inventory.items[0]',
90
+ 'where .sku == "A-100"',
91
+ 'replace .sku with "A-101"',
92
+ ].join('\n'),
93
+ },
94
+ },
95
+ },
96
+ {
97
+ id: 'replace-qty',
98
+ label: 'Replace Qty',
99
+ group: 'Core Mutations',
100
+ variants: {
101
+ instruction: {
102
+ request: [
103
+ 'from $.inventory.items.*',
104
+ 'where .sku == "B-200"',
105
+ 'replace .qty with :int32, 10',
106
+ ].join('\n'),
107
+ },
108
+ },
109
+ },
110
+ {
111
+ id: 'guarded-replace-qty',
112
+ label: 'Require Qty Before Replace',
113
+ group: 'Preconditions',
114
+ variants: {
115
+ structured: {
116
+ request: {
117
+ operations: [
118
+ { op: 'replace', target: '$.inventory.items[0].qty', datatype: 'int32', value: 10 },
119
+ ],
120
+ preconditions: [
121
+ { expression: '.qty == 7', target: '$.inventory.items[0]' },
122
+ ],
123
+ },
124
+ },
125
+ instruction: {
126
+ request: [
127
+ 'from $.inventory.items.*',
128
+ 'where .sku == "A-100"',
129
+ 'require .qty == 1',
130
+ 'replace .qty with :int32, 10',
131
+ ].join('\n'),
132
+ },
133
+ },
134
+ },
135
+ {
136
+ id: 'create-status',
137
+ label: 'Create Status',
138
+ group: 'Core Mutations',
139
+ variants: {
140
+ structured: {
141
+ request: {
142
+ op: 'create',
143
+ parent: '$.inventory.items[2]',
144
+ name: 'status',
145
+ value: 'pending',
146
+ },
147
+ },
148
+ instruction: {
149
+ request: [
150
+ 'from $.inventory.items.*',
151
+ 'where .sku == "C-300"',
152
+ 'create status with "pending"',
153
+ ].join('\n'),
154
+ },
155
+ },
156
+ },
157
+ {
158
+ id: 'create-attribute',
159
+ label: 'Create Attribute',
160
+ group: 'Attributes and Kinds',
161
+ variants: {
162
+ structured: {
163
+ request: {
164
+ op: 'create',
165
+ parent: '$.types.color.@',
166
+ name: 'selector',
167
+ datatype: 'sansa',
168
+ value: '$.inventory.items.*',
169
+ },
170
+ },
171
+ instruction: {
172
+ request: 'create $.types.color.@.selector with :sansa, $.inventory.items.*',
173
+ },
174
+ },
175
+ },
176
+ {
177
+ id: 'create-kind',
178
+ label: 'Create Kind',
179
+ group: 'Attributes and Kinds',
180
+ variants: {
181
+ structured: {
182
+ request: {
183
+ op: 'create',
184
+ parent: '$.types',
185
+ name: 'brand',
186
+ datatype: 'brandColor',
187
+ kind: 'hex',
188
+ value: 'ff00aa',
189
+ },
190
+ },
191
+ instruction: {
192
+ request: 'create $.types.brand with :brandColor, #ff00aa',
193
+ },
194
+ },
195
+ },
196
+ {
197
+ id: 'remove-metric',
198
+ label: 'Remove Metric',
199
+ group: 'Core Mutations',
200
+ variants: {
201
+ structured: {
202
+ request: {
203
+ op: 'remove',
204
+ target: '$.inventory.items[2].metric',
205
+ },
206
+ },
207
+ instruction: {
208
+ request: 'remove $.inventory.items[2].metric',
209
+ },
210
+ },
211
+ },
212
+ {
213
+ id: 'insert-role',
214
+ label: 'Append Role',
215
+ group: 'Ordered Containers',
216
+ variants: {
217
+ structured: {
218
+ request: {
219
+ op: 'insert',
220
+ container: '$.inventory.items[1].roles',
221
+ placement: 'last',
222
+ value: 'admin',
223
+ },
224
+ },
225
+ instruction: {
226
+ request: 'append $.inventory.items[1].roles with "admin"',
227
+ },
228
+ },
229
+ },
230
+ {
231
+ id: 'move-role',
232
+ label: 'Move Role',
233
+ group: 'Ordered Containers',
234
+ variants: {
235
+ structured: {
236
+ request: {
237
+ op: 'move',
238
+ source: '$.inventory.items[0].roles[0]',
239
+ container: '$.inventory.items[0].roles',
240
+ placement: { kind: 'after', anchor: '$.inventory.items[0].roles[1]' },
241
+ },
242
+ },
243
+ instruction: {
244
+ request: 'move $.inventory.items[0].roles[0] after $.inventory.items[0].roles[1] in $.inventory.items[0].roles',
245
+ },
246
+ },
247
+ },
248
+ {
249
+ id: 'create-sansa-value',
250
+ label: 'Create SANSA Value',
251
+ group: 'Typed Values',
252
+ variants: {
253
+ structured: {
254
+ request: {
255
+ op: 'create',
256
+ parent: '$.types',
257
+ name: 'selectorWorkbench',
258
+ datatype: 'sansa',
259
+ value: '$.inventory.items.*',
260
+ },
261
+ },
262
+ instruction: {
263
+ request: 'create $.types.selectorWorkbench with :sansa, $.inventory.items.*',
264
+ },
265
+ },
266
+ },
267
+ {
268
+ id: 'create-sep-value',
269
+ label: 'Create Sep Value',
270
+ group: 'Typed Values',
271
+ variants: {
272
+ structured: {
273
+ request: {
274
+ op: 'create',
275
+ parent: '$.types',
276
+ name: 'versionWorkbench',
277
+ datatype: 'version',
278
+ kind: 'sep',
279
+ value: '0.11.0',
280
+ },
281
+ },
282
+ instruction: {
283
+ request: 'create $.types.versionWorkbench with :version, ^0.11.0',
284
+ },
285
+ },
286
+ },
287
+ {
288
+ id: 'create-null-value',
289
+ label: 'Create Null Value',
290
+ group: 'Typed Values',
291
+ variants: {
292
+ structured: {
293
+ request: {
294
+ op: 'create',
295
+ parent: '$.types',
296
+ name: 'absentWorkbench',
297
+ datatype: 'null<string>',
298
+ kind: 'null',
299
+ value: 'notApplicable',
300
+ },
301
+ },
302
+ instruction: {
303
+ request: 'create $.types.absentWorkbench with :null<string>, !notApplicable',
304
+ },
305
+ },
306
+ },
307
+ {
308
+ id: 'create-reference-value',
309
+ label: 'Create Reference Value',
310
+ group: 'Typed Values',
311
+ variants: {
312
+ structured: {
313
+ request: {
314
+ op: 'create',
315
+ parent: '$',
316
+ name: 'cloneWorkbench',
317
+ datatype: 'number',
318
+ kind: 'cloneReference',
319
+ value: 'target',
320
+ },
321
+ },
322
+ instruction: {
323
+ request: 'create $.cloneWorkbench with :number, ~target',
324
+ },
325
+ },
326
+ },
327
+ {
328
+ id: 'create-object-value',
329
+ label: 'Create Object Value',
330
+ group: 'Typed Values',
331
+ variants: {
332
+ structured: {
333
+ request: {
334
+ op: 'create',
335
+ parent: '$.types',
336
+ name: 'settingsWorkbench',
337
+ datatype: 'object',
338
+ value: { enabled: true },
339
+ },
340
+ },
341
+ instruction: {
342
+ request: 'create $.types.settingsWorkbench with :object, { enabled = true }',
343
+ },
344
+ },
345
+ },
346
+ {
347
+ id: 'create-object-quoted-field',
348
+ label: 'Create Quoted Field',
349
+ group: 'Typed Values',
350
+ variants: {
351
+ structured: {
352
+ request: {
353
+ op: 'create',
354
+ parent: '$.types',
355
+ name: 'quotedSettingsWorkbench',
356
+ datatype: 'object',
357
+ value: { 'display name': 'Adapter', 'quote"key': 'ok', enabled: true },
358
+ },
359
+ },
360
+ instruction: {
361
+ request: `create $.types.quotedSettingsWorkbench with :object, { "display name" = "Adapter", "quote\\"key" = "ok", enabled = true }`,
362
+ },
363
+ },
364
+ },
365
+ {
366
+ id: 'create-list-value',
367
+ label: 'Create List Value',
368
+ group: 'Typed Values',
369
+ variants: {
370
+ structured: {
371
+ request: {
372
+ op: 'create',
373
+ parent: '$.types',
374
+ name: 'aliasesWorkbench',
375
+ datatype: 'list<string>',
376
+ value: ['adapter', 'driver'],
377
+ },
378
+ },
379
+ instruction: {
380
+ request: 'create $.types.aliasesWorkbench with :list<string>, ["adapter", "driver"]',
381
+ },
382
+ },
383
+ },
384
+ {
385
+ id: 'create-generic-object-value',
386
+ label: 'Create object<node>',
387
+ group: 'Typed Values',
388
+ variants: {
389
+ structured: {
390
+ request: {
391
+ op: 'create',
392
+ parent: '$.types',
393
+ name: 'settingsGenericWorkbench',
394
+ datatype: 'object<node>',
395
+ value: { enabled: true },
396
+ },
397
+ },
398
+ instruction: {
399
+ request: 'create $.types.settingsGenericWorkbench with :object<node>, { enabled = true }',
400
+ },
401
+ },
402
+ },
403
+ {
404
+ id: 'create-tuple-value',
405
+ label: 'Create Tuple Value',
406
+ group: 'Typed Values',
407
+ variants: {
408
+ structured: {
409
+ request: {
410
+ op: 'create',
411
+ parent: '$.types',
412
+ name: 'pairingWorkbench',
413
+ datatype: 'tuple',
414
+ value: ['sku', 7],
415
+ },
416
+ },
417
+ instruction: {
418
+ request: 'create $.types.pairingWorkbench with :tuple, ("sku", 7)',
419
+ },
420
+ },
421
+ },
422
+ {
423
+ id: 'create-node-value',
424
+ label: 'Create Node Value',
425
+ group: 'Typed Values',
426
+ variants: {
427
+ structured: {
428
+ request: {
429
+ op: 'create',
430
+ parent: '$.types',
431
+ name: 'badgeWorkbench',
432
+ datatype: 'node',
433
+ value: { tag: 'badge', children: ['new', 3] },
434
+ },
435
+ },
436
+ instruction: {
437
+ request: 'create $.types.badgeWorkbench with :node, <badge("new", 3)>',
438
+ },
439
+ },
440
+ },
441
+ {
442
+ id: 'append-typed-role',
443
+ label: 'Append Typed Role',
444
+ group: 'Ordered Containers',
445
+ variants: {
446
+ structured: {
447
+ request: {
448
+ op: 'insert',
449
+ container: '$.inventory.items[1].roles',
450
+ placement: 'last',
451
+ datatype: 'string',
452
+ kind: 'string',
453
+ value: 'admin,editor',
454
+ },
455
+ },
456
+ instruction: {
457
+ request: 'append in $.inventory.items[1].roles with :string, "admin,editor"',
458
+ },
459
+ },
460
+ },
461
+ {
462
+ id: 'target-aeon-generic-fail',
463
+ label: 'AEON Rejects string<null>',
464
+ group: 'Target Surfaces',
465
+ variants: {
466
+ instruction: {
467
+ options: { targetFormat: 'aeon' },
468
+ request: 'create $.types.textProbe with :string<null>, ""',
469
+ },
470
+ },
471
+ },
472
+ {
473
+ id: 'target-aeon-container-generic-ok',
474
+ label: 'AEON Allows object<node>',
475
+ group: 'Target Surfaces',
476
+ variants: {
477
+ instruction: {
478
+ options: { targetFormat: 'aeon' },
479
+ request: 'create $.types.settingsAeonProbe with :object<node>, { enabled = true }',
480
+ },
481
+ },
482
+ },
483
+ {
484
+ id: 'target-aeon-known-kind-mismatch-fail',
485
+ label: 'AEON Rejects number+string',
486
+ group: 'Target Surfaces',
487
+ variants: {
488
+ structured: {
489
+ options: { targetFormat: 'aeon' },
490
+ request: {
491
+ op: 'create',
492
+ parent: '$.types',
493
+ name: 'badNumberString',
494
+ datatype: 'number',
495
+ kind: 'string',
496
+ value: '42',
497
+ },
498
+ },
499
+ },
500
+ },
501
+ {
502
+ id: 'target-json-scalar-ok',
503
+ label: 'JSON Allows Scalar',
504
+ group: 'Target Surfaces',
505
+ variants: {
506
+ structured: {
507
+ options: { targetFormat: 'json' },
508
+ request: {
509
+ op: 'replace',
510
+ target: '$.inventory.items[0].sku',
511
+ value: 'A-101',
512
+ },
513
+ },
514
+ instruction: {
515
+ options: { targetFormat: 'json' },
516
+ request: [
517
+ 'from $.inventory.items[0]',
518
+ 'where .sku == "A-100"',
519
+ 'replace .sku with "A-101"',
520
+ ].join('\n'),
521
+ },
522
+ },
523
+ },
524
+ {
525
+ id: 'target-json-container-ok',
526
+ label: 'JSON Allows Container',
527
+ group: 'Target Surfaces',
528
+ variants: {
529
+ instruction: {
530
+ options: { targetFormat: 'json' },
531
+ request: 'create $.types.settingsJsonProbe with :object, { enabled = true }',
532
+ },
533
+ },
534
+ },
535
+ {
536
+ id: 'target-json-attribute-fail',
537
+ label: 'JSON Rejects Attribute',
538
+ group: 'Target Surfaces',
539
+ variants: {
540
+ structured: {
541
+ options: { targetFormat: 'json' },
542
+ request: {
543
+ op: 'create',
544
+ parent: '$.types.color.@',
545
+ name: 'selector',
546
+ datatype: 'sansa',
547
+ value: '$.inventory.items.*',
548
+ },
549
+ },
550
+ instruction: {
551
+ options: { targetFormat: 'json' },
552
+ request: 'create $.types.color.@.selector with :sansa, $.inventory.items.*',
553
+ },
554
+ },
555
+ },
556
+ {
557
+ id: 'target-json-typed-sansa-fail',
558
+ label: 'JSON Rejects SANSA Type',
559
+ group: 'Target Surfaces',
560
+ variants: {
561
+ structured: {
562
+ options: { targetFormat: 'json' },
563
+ request: {
564
+ op: 'create',
565
+ parent: '$.types',
566
+ name: 'selectorJsonProbe',
567
+ datatype: 'sansa',
568
+ value: '$.inventory.items.*',
569
+ },
570
+ },
571
+ instruction: {
572
+ options: { targetFormat: 'json' },
573
+ request: 'create $.types.selectorJsonProbe with :sansa, $.inventory.items.*',
574
+ },
575
+ },
576
+ },
577
+ {
578
+ id: 'target-json-parameterized-list-fail',
579
+ label: 'JSON Rejects list<string>',
580
+ group: 'Target Surfaces',
581
+ variants: {
582
+ instruction: {
583
+ options: { targetFormat: 'json' },
584
+ request: 'create $.types.aliasesJsonProbe with :list<string>, ["adapter", "driver"]',
585
+ },
586
+ },
587
+ },
588
+ {
589
+ id: 'target-json-parameterized-object-fail',
590
+ label: 'JSON Rejects object<node>',
591
+ group: 'Target Surfaces',
592
+ variants: {
593
+ instruction: {
594
+ options: { targetFormat: 'json' },
595
+ request: 'create $.types.settingsJsonGenericProbe with :object<node>, { enabled = true }',
596
+ },
597
+ },
598
+ },
599
+ {
600
+ id: 'target-json-tuple-fail',
601
+ label: 'JSON Rejects Tuple',
602
+ group: 'Target Surfaces',
603
+ variants: {
604
+ instruction: {
605
+ options: { targetFormat: 'json' },
606
+ request: 'create $.types.pairingJsonProbe with :tuple, ("sku", 7)',
607
+ },
608
+ },
609
+ },
610
+ {
611
+ id: 'target-json-node-fail',
612
+ label: 'JSON Rejects Node',
613
+ group: 'Target Surfaces',
614
+ variants: {
615
+ instruction: {
616
+ options: { targetFormat: 'json' },
617
+ request: 'create $.types.badgeJsonProbe with :node, <badge("new", 3)>',
618
+ },
619
+ },
620
+ },
621
+ {
622
+ id: 'target-json-quoted-field-node-fail',
623
+ label: 'JSON Rejects Quoted Field Node',
624
+ group: 'Target Surfaces',
625
+ variants: {
626
+ instruction: {
627
+ options: { targetFormat: 'json' },
628
+ request: 'create $.types.payloadJsonProbe with :object, { "bad.key" = :node, <badge("new")> }',
629
+ },
630
+ },
631
+ },
632
+ {
633
+ id: 'target-json-reference-fail',
634
+ label: 'JSON Rejects Reference',
635
+ group: 'Target Surfaces',
636
+ variants: {
637
+ instruction: {
638
+ options: { targetFormat: 'json' },
639
+ request: 'create $.cloneJsonProbe with :number, ~target',
640
+ },
641
+ },
642
+ },
643
+ {
644
+ id: 'policy-allow-qty',
645
+ label: 'Policy Allows Qty',
646
+ group: 'Policy Boundaries',
647
+ variants: {
648
+ instruction: {
649
+ options: { policySource: allowQtyPolicySource },
650
+ request: [
651
+ 'from $.inventory.items.*',
652
+ 'where .sku == "B-200"',
653
+ 'replace .qty with :int32, 10',
654
+ ].join('\n'),
655
+ },
656
+ },
657
+ },
658
+ {
659
+ id: 'policy-deny-status-create',
660
+ label: 'Policy Denies Create',
661
+ group: 'Policy Boundaries',
662
+ variants: {
663
+ structured: {
664
+ options: { policySource: allowQtyPolicySource },
665
+ request: {
666
+ op: 'create',
667
+ parent: '$.types',
668
+ name: 'policyDeniedStatus',
669
+ value: 'active',
670
+ },
671
+ },
672
+ instruction: {
673
+ options: { policySource: allowQtyPolicySource },
674
+ request: 'create $.types.policyDeniedStatus with "active"',
675
+ },
676
+ },
677
+ },
678
+ {
679
+ id: 'policy-explicit-deny-sku',
680
+ label: 'Policy Explicit Deny',
681
+ group: 'Policy Boundaries',
682
+ variants: {
683
+ instruction: {
684
+ options: { policySource: denySkuPolicySource },
685
+ request: [
686
+ 'from $.inventory.items[0]',
687
+ 'where .sku == "A-100"',
688
+ 'replace .sku with "A-101"',
689
+ ].join('\n'),
690
+ },
691
+ },
692
+ },
693
+ {
694
+ id: 'instruction-duplicate-object-field-fail',
695
+ label: 'Duplicate Object Field',
696
+ group: 'Instruction Diagnostics',
697
+ variants: {
698
+ instruction: {
699
+ request: 'create $.types.settingsWorkbench with :object, { enabled = true enabled = false }',
700
+ },
701
+ },
702
+ },
703
+ {
704
+ id: 'instruction-literal-only-fail',
705
+ label: 'Literal-Only Value',
706
+ group: 'Instruction Diagnostics',
707
+ variants: {
708
+ instruction: {
709
+ request: 'replace $.inventory.items[0].sku with lower("A")',
710
+ },
711
+ },
712
+ },
713
+ {
714
+ id: 'instruction-invalid-create-name-fail',
715
+ label: 'Invalid Create Name',
716
+ group: 'Instruction Diagnostics',
717
+ variants: {
718
+ instruction: {
719
+ request: 'create "" with "x"',
720
+ },
721
+ },
722
+ },
723
+ {
724
+ id: 'instruction-lower-target-miss',
725
+ label: 'Lower Target Miss',
726
+ group: 'Instruction Diagnostics',
727
+ variants: {
728
+ instruction: {
729
+ request: [
730
+ 'from $.inventory.items.*',
731
+ 'replace .missing with "x"',
732
+ ].join('\n'),
733
+ },
734
+ },
735
+ },
736
+ {
737
+ id: 'instruction-lower-anchor-miss',
738
+ label: 'Lower Anchor Miss',
739
+ group: 'Instruction Diagnostics',
740
+ variants: {
741
+ instruction: {
742
+ request: [
743
+ 'from $.inventory.items.*',
744
+ 'insert after .roles[99] in .roles with "review"',
745
+ ].join('\n'),
746
+ },
747
+ },
748
+ },
749
+ {
750
+ id: 'create-scalars',
751
+ label: 'Create Scalars',
752
+ group: 'Batch Requests',
753
+ variants: {
754
+ structured: {
755
+ request: {
756
+ operations: [
757
+ {
758
+ op: 'create',
759
+ parent: '$.types',
760
+ name: 'selectorCopy',
761
+ datatype: 'sansa',
762
+ value: '$.inventory.items.*',
763
+ },
764
+ {
765
+ op: 'create',
766
+ parent: '$.types',
767
+ name: 'versionCopy',
768
+ datatype: 'version',
769
+ kind: 'sep',
770
+ value: '0.11.0',
771
+ },
772
+ {
773
+ op: 'create',
774
+ parent: '$.types',
775
+ name: 'absentCopy',
776
+ datatype: 'null<string>',
777
+ kind: 'null',
778
+ value: 'notApplicable',
779
+ },
780
+ {
781
+ op: 'create',
782
+ parent: '$',
783
+ name: 'cloneCopy',
784
+ datatype: 'number',
785
+ kind: 'cloneReference',
786
+ value: 'target',
787
+ },
788
+ ],
789
+ },
790
+ },
791
+ },
792
+ },
793
+ {
794
+ id: 'create-containers',
795
+ label: 'Create Containers',
796
+ group: 'Batch Requests',
797
+ variants: {
798
+ structured: {
799
+ request: {
800
+ operations: [
801
+ {
802
+ op: 'create',
803
+ parent: '$.types',
804
+ name: 'settings',
805
+ datatype: 'object',
806
+ value: { enabled: true },
807
+ },
808
+ {
809
+ op: 'create',
810
+ parent: '$.types',
811
+ name: 'aliases',
812
+ datatype: 'list<string>',
813
+ value: ['adapter', 'driver'],
814
+ },
815
+ {
816
+ op: 'create',
817
+ parent: '$.types',
818
+ name: 'pairing',
819
+ datatype: 'tuple',
820
+ value: ['sku', 7],
821
+ },
822
+ {
823
+ op: 'create',
824
+ parent: '$.types',
825
+ name: 'badge',
826
+ datatype: 'node',
827
+ value: { tag: 'badge', children: ['new', 3] },
828
+ },
829
+ ],
830
+ },
831
+ },
832
+ },
833
+ },
834
+ {
835
+ id: 'insert-item',
836
+ label: 'Insert Item',
837
+ group: 'Ordered Containers',
838
+ variants: {
839
+ structured: {
840
+ request: {
841
+ op: 'insert',
842
+ container: '$.inventory.items',
843
+ placement: { kind: 'before', anchor: '$.inventory.items[1]' },
844
+ value: {
845
+ sku: 'B-150',
846
+ name: 'Brace',
847
+ qty: 4,
848
+ category: 'hardware',
849
+ },
850
+ },
851
+ },
852
+ instruction: {
853
+ request: 'insert before $.inventory.items[1] in $.inventory.items with :object, { sku = "B-150" name = "Brace" qty = 4 category = "hardware" }',
854
+ },
855
+ },
856
+ },
857
+ {
858
+ id: 'move-item',
859
+ label: 'Move Item',
860
+ group: 'Ordered Containers',
861
+ variants: {
862
+ structured: {
863
+ request: {
864
+ op: 'move',
865
+ source: '$.inventory.items[0]',
866
+ container: '$.inventory.items',
867
+ placement: 'last',
868
+ },
869
+ },
870
+ instruction: {
871
+ request: 'move $.inventory.items[0] last in $.inventory.items',
872
+ },
873
+ },
874
+ },
875
+ {
876
+ id: 'budget-fail',
877
+ label: 'Budget Failure',
878
+ group: 'Failure Cases',
879
+ variants: {
880
+ structured: {
881
+ options: { maxOperations: 1 },
882
+ request: [
883
+ { op: 'replace', target: '$.inventory.items[0].qty', value: 9 },
884
+ { op: 'replace', target: '$.inventory.items[1].qty', value: 2 },
885
+ ],
886
+ },
887
+ instruction: {
888
+ options: { maxOperations: 1 },
889
+ request: [
890
+ 'from $.inventory.items[0..1]',
891
+ 'replace .qty with 9',
892
+ ].join('\n'),
893
+ },
894
+ },
895
+ },
896
+ {
897
+ id: 'value-budget-fail',
898
+ label: 'Value Budget',
899
+ group: 'Failure Cases',
900
+ variants: {
901
+ structured: {
902
+ options: { maxStringLength: 4 },
903
+ request: {
904
+ op: 'replace',
905
+ target: '$.inventory.items[0].sku',
906
+ value: 'ABCDEFGHIJ',
907
+ },
908
+ },
909
+ instruction: {
910
+ options: { maxStringLength: 4 },
911
+ request: 'replace $.inventory.items[0].sku with "ABCDEFGHIJ"',
912
+ },
913
+ },
914
+ },
915
+ {
916
+ id: 'capability-fail',
917
+ label: 'Precondition Failure',
918
+ group: 'Failure Cases',
919
+ variants: {
920
+ structured: {
921
+ request: {
922
+ operations: [
923
+ { op: 'replace', target: '$.inventory.items[0].sku', value: 'A-101' },
924
+ ],
925
+ preconditions: [
926
+ { expression: '$.inventory.items[0].sku == "Z-999"' },
927
+ ],
928
+ },
929
+ },
930
+ instruction: {
931
+ request: [
932
+ 'require $.inventory.items[0].sku == "Z-999"',
933
+ 'replace $.inventory.items[0].sku with "A-101"',
934
+ ].join('\n'),
935
+ },
936
+ },
937
+ },
938
+ ];
939
+
940
+ const mutateExampleExpectationOverrides = {
941
+ 'replace-sku:structured': {
942
+ ok: true,
943
+ operationCount: 1,
944
+ textIncludes: ['0: replace $.inventory.items[0].sku', 'preconditions: 1'],
945
+ },
946
+ 'replace-sku:instruction': {
947
+ ok: true,
948
+ operationCount: 1,
949
+ textIncludes: ['0: replace $.inventory.items[0].sku', 'because "manual correction"', 'by "Bob"'],
950
+ },
951
+ 'replace-qty:instruction': {
952
+ ok: true,
953
+ operationCount: 1,
954
+ textIncludes: ['0: replace $.inventory.items[1].qty'],
955
+ },
956
+ 'guarded-replace-qty:structured': {
957
+ ok: false,
958
+ phase: 'plan',
959
+ code: 'SANSA_MUTATE_PRECONDITION_FAILED',
960
+ },
961
+ 'create-status:instruction': {
962
+ ok: true,
963
+ operationCount: 1,
964
+ textIncludes: ['0: create $.inventory.items[2]'],
965
+ },
966
+ 'create-attribute:instruction': {
967
+ ok: true,
968
+ operationCount: 1,
969
+ textIncludes: ['0: create $.types.color.@'],
970
+ },
971
+ 'append-typed-role:instruction': {
972
+ ok: true,
973
+ operationCount: 1,
974
+ textIncludes: ['0: insert $.inventory.items[1].roles'],
975
+ },
976
+ 'target-aeon-generic-fail:instruction': {
977
+ ok: false,
978
+ phase: 'target',
979
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
980
+ targetFormat: 'aeon',
981
+ datatype: 'string<null>',
982
+ },
983
+ 'target-json-attribute-fail:structured': {
984
+ ok: false,
985
+ phase: 'target',
986
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_FEATURE',
987
+ targetFormat: 'json',
988
+ },
989
+ 'target-json-attribute-fail:instruction': {
990
+ ok: false,
991
+ phase: 'target',
992
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_FEATURE',
993
+ targetFormat: 'json',
994
+ },
995
+ 'target-json-typed-sansa-fail:structured': {
996
+ ok: false,
997
+ phase: 'target',
998
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
999
+ targetFormat: 'json',
1000
+ datatype: 'sansa',
1001
+ },
1002
+ 'target-json-typed-sansa-fail:instruction': {
1003
+ ok: false,
1004
+ phase: 'target',
1005
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
1006
+ targetFormat: 'json',
1007
+ datatype: 'sansa',
1008
+ },
1009
+ 'target-json-parameterized-list-fail:instruction': {
1010
+ ok: false,
1011
+ phase: 'target',
1012
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
1013
+ targetFormat: 'json',
1014
+ datatype: 'list<string>',
1015
+ },
1016
+ 'target-json-parameterized-object-fail:instruction': {
1017
+ ok: false,
1018
+ phase: 'target',
1019
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
1020
+ targetFormat: 'json',
1021
+ datatype: 'object<node>',
1022
+ },
1023
+ 'target-json-tuple-fail:instruction': {
1024
+ ok: false,
1025
+ phase: 'target',
1026
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
1027
+ targetFormat: 'json',
1028
+ datatype: 'tuple',
1029
+ },
1030
+ 'target-json-node-fail:instruction': {
1031
+ ok: false,
1032
+ phase: 'target',
1033
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
1034
+ targetFormat: 'json',
1035
+ datatype: 'node',
1036
+ },
1037
+ 'target-json-quoted-field-node-fail:instruction': {
1038
+ ok: false,
1039
+ phase: 'target',
1040
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_VALUE',
1041
+ targetFormat: 'json',
1042
+ textIncludes: ['value value["bad.key"]'],
1043
+ },
1044
+ 'target-json-reference-fail:instruction': {
1045
+ ok: false,
1046
+ phase: 'target',
1047
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
1048
+ targetFormat: 'json',
1049
+ datatype: 'cloneReference',
1050
+ },
1051
+ 'policy-allow-qty:instruction': {
1052
+ ok: true,
1053
+ operationCount: 1,
1054
+ textIncludes: ['0: replace $.inventory.items[1].qty'],
1055
+ },
1056
+ 'policy-deny-status-create:structured': {
1057
+ ok: false,
1058
+ phase: 'policy',
1059
+ code: 'SANSA_MUTATE_POLICY_DENIED',
1060
+ operationIndex: 0,
1061
+ textIncludes: ['SANSA_MUTATE_POLICY_DENIED [policy] operation 0'],
1062
+ },
1063
+ 'policy-deny-status-create:instruction': {
1064
+ ok: false,
1065
+ phase: 'policy',
1066
+ code: 'SANSA_MUTATE_POLICY_DENIED',
1067
+ operationIndex: 0,
1068
+ textIncludes: ['SANSA_MUTATE_POLICY_DENIED [policy] operation 0'],
1069
+ },
1070
+ 'policy-explicit-deny-sku:instruction': {
1071
+ ok: false,
1072
+ phase: 'policy',
1073
+ code: 'SANSA_MUTATE_POLICY_DENIED',
1074
+ operationIndex: 0,
1075
+ ruleIndex: 0,
1076
+ textIncludes: ['SANSA_MUTATE_POLICY_DENIED [policy] operation 0 rule 0'],
1077
+ },
1078
+ 'instruction-duplicate-object-field-fail:instruction': {
1079
+ ok: false,
1080
+ phase: 'parse',
1081
+ code: 'SANSA_INSTRUCTION_PARSE_FAILED',
1082
+ },
1083
+ 'instruction-literal-only-fail:instruction': {
1084
+ ok: false,
1085
+ phase: 'parse',
1086
+ code: 'SANSA_INSTRUCTION_PARSE_FAILED',
1087
+ },
1088
+ 'instruction-invalid-create-name-fail:instruction': {
1089
+ ok: false,
1090
+ phase: 'parse',
1091
+ code: 'SANSA_INSTRUCTION_PARSE_FAILED',
1092
+ },
1093
+ 'instruction-lower-target-miss:instruction': {
1094
+ ok: false,
1095
+ phase: 'lower',
1096
+ code: 'SANSA_INSTRUCTION_TARGET_MISS',
1097
+ textIncludes: ['SANSA_INSTRUCTION_TARGET_MISS [lower]'],
1098
+ },
1099
+ 'instruction-lower-anchor-miss:instruction': {
1100
+ ok: false,
1101
+ phase: 'lower',
1102
+ code: 'SANSA_INSTRUCTION_TARGET_MISS',
1103
+ textIncludes: ['SANSA_INSTRUCTION_TARGET_MISS [lower]'],
1104
+ },
1105
+ 'budget-fail:structured': {
1106
+ ok: false,
1107
+ phase: 'plan',
1108
+ code: 'SANSA_MUTATE_BUDGET_EXCEEDED',
1109
+ budget: 'maxOperations',
1110
+ },
1111
+ 'budget-fail:instruction': {
1112
+ ok: false,
1113
+ phase: 'plan',
1114
+ code: 'SANSA_MUTATE_BUDGET_EXCEEDED',
1115
+ budget: 'maxOperations',
1116
+ },
1117
+ 'value-budget-fail:structured': {
1118
+ ok: false,
1119
+ phase: 'plan',
1120
+ code: 'SANSA_MUTATE_BUDGET_EXCEEDED',
1121
+ budget: 'maxStringLength',
1122
+ },
1123
+ 'value-budget-fail:instruction': {
1124
+ ok: false,
1125
+ phase: 'plan',
1126
+ code: 'SANSA_MUTATE_BUDGET_EXCEEDED',
1127
+ budget: 'maxStringLength',
1128
+ },
1129
+ 'capability-fail:structured': {
1130
+ ok: false,
1131
+ phase: 'plan',
1132
+ code: 'SANSA_MUTATE_PRECONDITION_FAILED',
1133
+ },
1134
+ 'capability-fail:instruction': {
1135
+ ok: false,
1136
+ phase: 'plan',
1137
+ code: 'SANSA_MUTATE_PRECONDITION_FAILED',
1138
+ },
1139
+ 'target-aeon-container-generic-ok:instruction': {
1140
+ ok: true,
1141
+ operationCount: 1,
1142
+ textIncludes: ['0: create $.types'],
1143
+ },
1144
+ 'target-aeon-known-kind-mismatch-fail:structured': {
1145
+ ok: false,
1146
+ phase: 'target',
1147
+ code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_VALUE',
1148
+ targetFormat: 'aeon',
1149
+ datatype: 'number',
1150
+ textIncludes: ['target aeon, datatype number', "Datatype 'number' is not compatible with string literal representation"],
1151
+ },
1152
+ 'target-json-container-ok:instruction': {
1153
+ ok: true,
1154
+ operationCount: 1,
1155
+ textIncludes: ['0: create $.types'],
1156
+ },
1157
+ 'insert-item:instruction': {
1158
+ ok: true,
1159
+ operationCount: 1,
1160
+ textIncludes: ['0: insert $.inventory.items'],
1161
+ },
1162
+ 'move-item:instruction': {
1163
+ ok: true,
1164
+ operationCount: 1,
1165
+ textIncludes: ['0: move $.inventory.items[0]'],
1166
+ },
1167
+ 'create-scalars:structured': {
1168
+ ok: true,
1169
+ operationCount: 4,
1170
+ textIncludes: ['operations: 4', '3: create $'],
1171
+ },
1172
+ 'create-containers:structured': {
1173
+ ok: true,
1174
+ operationCount: 4,
1175
+ textIncludes: ['operations: 4'],
1176
+ },
1177
+ };
1178
+
1179
+ const mutateExampleApplyExpectationOverrides = {
1180
+ 'replace-sku:structured': {
1181
+ ok: true,
1182
+ operationStatuses: ['applied'],
1183
+ sourceIncludes: ['sku@{origin:string = "catalog"}:string = "A-101"'],
1184
+ textIncludes: ['applied: 1', '0: applied $.inventory.items[0].sku -> $.inventory.items[0].sku'],
1185
+ },
1186
+ 'replace-sku:instruction': {
1187
+ ok: true,
1188
+ operationStatuses: ['applied'],
1189
+ sourceIncludes: ['sku@{origin:string = "catalog"}:string = "A-101"'],
1190
+ textIncludes: ['applied: 1', '0: applied $.inventory.items[0].sku -> $.inventory.items[0].sku'],
1191
+ },
1192
+ 'replace-qty:instruction': {
1193
+ ok: true,
1194
+ operationStatuses: ['applied'],
1195
+ sourceIncludes: ['qty:int32 = 10'],
1196
+ textIncludes: ['applied: 1', '0: applied $.inventory.items[1].qty -> $.inventory.items[1].qty'],
1197
+ },
1198
+ 'create-status:instruction': {
1199
+ ok: true,
1200
+ operationStatuses: ['applied'],
1201
+ sourceIncludes: ['status:string = "pending"'],
1202
+ textIncludes: ['applied: 1', '0: applied $.inventory.items[2] -> $.inventory.items[2].status'],
1203
+ },
1204
+ 'create-object-quoted-field:structured': {
1205
+ ok: true,
1206
+ operationStatuses: ['applied'],
1207
+ sourceIncludes: ['quotedSettingsWorkbench:object = {', '"display name":string = "Adapter"', '"quote\\"key":string = "ok"', 'enabled:boolean = true'],
1208
+ textIncludes: ['applied: 1', '0: applied $.types -> $.types.quotedSettingsWorkbench'],
1209
+ },
1210
+ 'create-object-quoted-field:instruction': {
1211
+ ok: true,
1212
+ operationStatuses: ['applied'],
1213
+ sourceIncludes: ['quotedSettingsWorkbench:object = {', '"display name":string = "Adapter"', '"quote\\"key":string = "ok"', 'enabled:boolean = true'],
1214
+ textIncludes: ['applied: 1', '0: applied $.types -> $.types.quotedSettingsWorkbench'],
1215
+ },
1216
+ 'create-attribute:instruction': {
1217
+ ok: true,
1218
+ operationStatuses: ['applied'],
1219
+ sourceIncludes: ['color@{selector:sansa = $.inventory.items.*}:hex = #ff00aa'],
1220
+ textIncludes: ['applied: 1', '0: applied $.types.color.@ -> $.types.color.@.selector'],
1221
+ },
1222
+ 'create-kind:structured': {
1223
+ ok: true,
1224
+ operationStatuses: ['applied'],
1225
+ sourceIncludes: ['brand:brandColor = #ff00aa'],
1226
+ textIncludes: ['applied: 1', '0: applied $.types -> $.types.brand'],
1227
+ },
1228
+ 'create-kind:instruction': {
1229
+ ok: true,
1230
+ operationStatuses: ['applied'],
1231
+ sourceIncludes: ['brand:brandColor = #ff00aa'],
1232
+ textIncludes: ['applied: 1', '0: applied $.types -> $.types.brand'],
1233
+ },
1234
+ 'remove-metric:instruction': {
1235
+ ok: true,
1236
+ operationStatuses: ['applied'],
1237
+ sourceExcludes: ['metric:nan<number> = NaN'],
1238
+ textIncludes: ['applied: 1', '0: applied $.inventory.items[2].metric -> $.inventory.items[2].metric'],
1239
+ },
1240
+ 'append-typed-role:instruction': {
1241
+ ok: true,
1242
+ operationStatuses: ['applied'],
1243
+ sourceIncludes: ['roles:list<string> = [\n "user"\n "admin,editor"\n ]'],
1244
+ textIncludes: ['applied: 1', '0: applied $.inventory.items[1].roles -> $.inventory.items[1].roles[1]'],
1245
+ },
1246
+ 'insert-item:instruction': {
1247
+ ok: true,
1248
+ operationStatuses: ['applied'],
1249
+ sourceIncludes: ['sku:string = "B-150"'],
1250
+ textIncludes: ['applied: 1', '0: applied $.inventory.items -> $.inventory.items[1]'],
1251
+ },
1252
+ 'policy-allow-qty:instruction': {
1253
+ ok: true,
1254
+ operationStatuses: ['applied'],
1255
+ sourceIncludes: ['qty:int32 = 10'],
1256
+ textIncludes: ['applied: 1', '0: applied $.inventory.items[1].qty -> $.inventory.items[1].qty'],
1257
+ },
1258
+ };
1259
+
1260
+ for (const example of mutateExamples) {
1261
+ for (const [kind, variant] of Object.entries(example.variants)) {
1262
+ const key = `${example.id}:${kind}`;
1263
+ variant.expected = mutateExampleExpectationOverrides[key] ?? { ok: true };
1264
+ if (mutateExampleApplyExpectationOverrides[key] !== undefined) {
1265
+ variant.applyExpected = mutateExampleApplyExpectationOverrides[key];
1266
+ }
1267
+ }
1268
+ }
1269
+
1270
+ export const mutateExampleGroups = Array.from(mutateExamples.reduce((groups, example) => {
1271
+ const group = example.group ?? 'Examples';
1272
+ const entries = groups.get(group) ?? [];
1273
+ entries.push(example);
1274
+ groups.set(group, entries);
1275
+ return groups;
1276
+ }, new Map()), ([label, examples]) => ({ label, examples }));
1277
+
1278
+ export function firstMutateExampleId() {
1279
+ return mutateExamples[0]?.id ?? '';
1280
+ }