@openfn/language-motherduck 1.0.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.
package/ast.json ADDED
@@ -0,0 +1,1111 @@
1
+ {
2
+ "operations": [
3
+ {
4
+ "name": "execute",
5
+ "params": [
6
+ "operations"
7
+ ],
8
+ "docs": {
9
+ "description": "Execute a sequence of operations against MotherDuck cloud database.\nWraps `@openfn/language-common/execute`, and prepends initial state for MotherDuck.",
10
+ "tags": [
11
+ {
12
+ "title": "example",
13
+ "description": "execute(\n query('SELECT * FROM my_table'),\n insert('users', { name: 'John', age: 30 })\n)(state)"
14
+ },
15
+ {
16
+ "title": "public",
17
+ "description": null,
18
+ "type": null
19
+ },
20
+ {
21
+ "title": "function",
22
+ "description": null,
23
+ "name": null
24
+ },
25
+ {
26
+ "title": "param",
27
+ "description": "Operations to be performed.",
28
+ "type": {
29
+ "type": "RestType",
30
+ "expression": {
31
+ "type": "NameExpression",
32
+ "name": "Operation"
33
+ }
34
+ },
35
+ "name": "operations"
36
+ },
37
+ {
38
+ "title": "returns",
39
+ "description": null,
40
+ "type": {
41
+ "type": "NameExpression",
42
+ "name": "Operation"
43
+ }
44
+ },
45
+ {
46
+ "title": "state",
47
+ "description": "{Array} references - Array of previous operation results"
48
+ },
49
+ {
50
+ "title": "state",
51
+ "description": "{*} data - Data from the last operation"
52
+ }
53
+ ]
54
+ },
55
+ "valid": true
56
+ },
57
+ {
58
+ "name": "query",
59
+ "params": [
60
+ "sqlQuery",
61
+ "options"
62
+ ],
63
+ "docs": {
64
+ "description": "Execute a SQL query against the MotherDuck database.",
65
+ "tags": [
66
+ {
67
+ "title": "public",
68
+ "description": null,
69
+ "type": null
70
+ },
71
+ {
72
+ "title": "example",
73
+ "description": "query('SELECT * FROM users WHERE age > 18')",
74
+ "caption": "Simple query"
75
+ },
76
+ {
77
+ "title": "example",
78
+ "description": "query('SELECT * FROM orders', { writeSql: true })",
79
+ "caption": "Query with SQL logging"
80
+ },
81
+ {
82
+ "title": "function",
83
+ "description": null,
84
+ "name": null
85
+ },
86
+ {
87
+ "title": "param",
88
+ "description": "SQL query string",
89
+ "type": {
90
+ "type": "NameExpression",
91
+ "name": "string"
92
+ },
93
+ "name": "sqlQuery"
94
+ },
95
+ {
96
+ "title": "param",
97
+ "description": "Query execution options",
98
+ "type": {
99
+ "type": "OptionalType",
100
+ "expression": {
101
+ "type": "NameExpression",
102
+ "name": "object"
103
+ }
104
+ },
105
+ "name": "options"
106
+ },
107
+ {
108
+ "title": "param",
109
+ "description": "Include full SQL in response.query (default: false, hides query for security)",
110
+ "type": {
111
+ "type": "OptionalType",
112
+ "expression": {
113
+ "type": "NameExpression",
114
+ "name": "boolean"
115
+ }
116
+ },
117
+ "name": "options.writeSql",
118
+ "default": "false"
119
+ },
120
+ {
121
+ "title": "returns",
122
+ "description": null,
123
+ "type": {
124
+ "type": "NameExpression",
125
+ "name": "Operation"
126
+ }
127
+ },
128
+ {
129
+ "title": "state",
130
+ "description": "{Array} data - Query results as array of row objects"
131
+ },
132
+ {
133
+ "title": "state",
134
+ "description": "{object} response - Metadata including rowCount, command, and query"
135
+ }
136
+ ]
137
+ },
138
+ "valid": false
139
+ },
140
+ {
141
+ "name": "insert",
142
+ "params": [
143
+ "table",
144
+ "records",
145
+ "options"
146
+ ],
147
+ "docs": {
148
+ "description": "Insert one or more records into a MotherDuck table with automatic batching.\nLarge datasets are automatically split into batches for optimal performance.",
149
+ "tags": [
150
+ {
151
+ "title": "public",
152
+ "description": null,
153
+ "type": null
154
+ },
155
+ {
156
+ "title": "example",
157
+ "description": "insert('users', { name: 'John', age: 30, email: 'john@example.com' })",
158
+ "caption": "Insert a single record"
159
+ },
160
+ {
161
+ "title": "example",
162
+ "description": "insert('users', [\n { name: 'John', age: 30 },\n { name: 'Jane', age: 25 }\n])",
163
+ "caption": "Insert multiple records"
164
+ },
165
+ {
166
+ "title": "example",
167
+ "description": "insert('users', records, { batchSize: 500 })",
168
+ "caption": "Insert with custom batch size"
169
+ },
170
+ {
171
+ "title": "function",
172
+ "description": null,
173
+ "name": null
174
+ },
175
+ {
176
+ "title": "param",
177
+ "description": "Target table name",
178
+ "type": {
179
+ "type": "NameExpression",
180
+ "name": "string"
181
+ },
182
+ "name": "table"
183
+ },
184
+ {
185
+ "title": "param",
186
+ "description": "A single record object or array of records",
187
+ "type": {
188
+ "type": "UnionType",
189
+ "elements": [
190
+ {
191
+ "type": "NameExpression",
192
+ "name": "object"
193
+ },
194
+ {
195
+ "type": "NameExpression",
196
+ "name": "Array"
197
+ }
198
+ ]
199
+ },
200
+ "name": "records"
201
+ },
202
+ {
203
+ "title": "param",
204
+ "description": "Insert options",
205
+ "type": {
206
+ "type": "OptionalType",
207
+ "expression": {
208
+ "type": "NameExpression",
209
+ "name": "object"
210
+ }
211
+ },
212
+ "name": "options"
213
+ },
214
+ {
215
+ "title": "param",
216
+ "description": "Number of records per batch",
217
+ "type": {
218
+ "type": "OptionalType",
219
+ "expression": {
220
+ "type": "NameExpression",
221
+ "name": "number"
222
+ }
223
+ },
224
+ "name": "options.batchSize",
225
+ "default": "1000"
226
+ },
227
+ {
228
+ "title": "returns",
229
+ "description": null,
230
+ "type": {
231
+ "type": "NameExpression",
232
+ "name": "Operation"
233
+ }
234
+ },
235
+ {
236
+ "title": "state",
237
+ "description": "{object} data - Metadata including recordsInserted and batches"
238
+ }
239
+ ]
240
+ },
241
+ "valid": false
242
+ }
243
+ ],
244
+ "exports": [],
245
+ "common": [
246
+ {
247
+ "name": "fn",
248
+ "params": [
249
+ "func"
250
+ ],
251
+ "docs": {
252
+ "description": "Creates a custom step (or operation) for more flexible job writing.",
253
+ "tags": [
254
+ {
255
+ "title": "public",
256
+ "description": null,
257
+ "type": null
258
+ },
259
+ {
260
+ "title": "function",
261
+ "description": null,
262
+ "name": null
263
+ },
264
+ {
265
+ "title": "example",
266
+ "description": "fn(state => {\n // do some things to state\n return state;\n});"
267
+ },
268
+ {
269
+ "title": "param",
270
+ "description": "is the function",
271
+ "type": {
272
+ "type": "NameExpression",
273
+ "name": "Function"
274
+ },
275
+ "name": "func"
276
+ },
277
+ {
278
+ "title": "returns",
279
+ "description": null,
280
+ "type": {
281
+ "type": "NameExpression",
282
+ "name": "Operation"
283
+ }
284
+ }
285
+ ]
286
+ },
287
+ "valid": true
288
+ },
289
+ {
290
+ "name": "fnIf",
291
+ "params": [
292
+ "condition",
293
+ "operation"
294
+ ],
295
+ "docs": {
296
+ "description": "Execute a function only when the condition returns true",
297
+ "tags": [
298
+ {
299
+ "title": "public",
300
+ "description": null,
301
+ "type": null
302
+ },
303
+ {
304
+ "title": "function",
305
+ "description": null,
306
+ "name": null
307
+ },
308
+ {
309
+ "title": "example",
310
+ "description": "fnIf((state) => state?.data?.name, get(\"https://example.com\"));"
311
+ },
312
+ {
313
+ "title": "param",
314
+ "description": "The condition that returns true",
315
+ "type": {
316
+ "type": "NameExpression",
317
+ "name": "Boolean"
318
+ },
319
+ "name": "condition"
320
+ },
321
+ {
322
+ "title": "param",
323
+ "description": "The operation needed to be executed.",
324
+ "type": {
325
+ "type": "NameExpression",
326
+ "name": "Operation"
327
+ },
328
+ "name": "operation"
329
+ },
330
+ {
331
+ "title": "returns",
332
+ "description": null,
333
+ "type": {
334
+ "type": "NameExpression",
335
+ "name": "Operation"
336
+ }
337
+ }
338
+ ]
339
+ },
340
+ "valid": true
341
+ },
342
+ {
343
+ "name": "sourceValue",
344
+ "params": [
345
+ "path"
346
+ ],
347
+ "docs": {
348
+ "description": "Picks out a single value from source data.\nIf a JSONPath returns more than one value for the reference, the first\nitem will be returned.",
349
+ "tags": [
350
+ {
351
+ "title": "public",
352
+ "description": null,
353
+ "type": null
354
+ },
355
+ {
356
+ "title": "function",
357
+ "description": null,
358
+ "name": null
359
+ },
360
+ {
361
+ "title": "example",
362
+ "description": "sourceValue('$.key')"
363
+ },
364
+ {
365
+ "title": "param",
366
+ "description": "JSONPath referencing a point in `state`.",
367
+ "type": {
368
+ "type": "NameExpression",
369
+ "name": "String"
370
+ },
371
+ "name": "path"
372
+ },
373
+ {
374
+ "title": "returns",
375
+ "description": null,
376
+ "type": {
377
+ "type": "NameExpression",
378
+ "name": "Operation"
379
+ }
380
+ }
381
+ ]
382
+ },
383
+ "valid": true
384
+ },
385
+ {
386
+ "name": "dataPath",
387
+ "params": [
388
+ "path"
389
+ ],
390
+ "docs": {
391
+ "description": "Ensures a path points at the data.",
392
+ "tags": [
393
+ {
394
+ "title": "public",
395
+ "description": null,
396
+ "type": null
397
+ },
398
+ {
399
+ "title": "function",
400
+ "description": null,
401
+ "name": null
402
+ },
403
+ {
404
+ "title": "example",
405
+ "description": "dataPath('key')"
406
+ },
407
+ {
408
+ "title": "param",
409
+ "description": "JSONPath referencing a point in `data`.",
410
+ "type": {
411
+ "type": "NameExpression",
412
+ "name": "string"
413
+ },
414
+ "name": "path"
415
+ },
416
+ {
417
+ "title": "returns",
418
+ "description": null,
419
+ "type": {
420
+ "type": "NameExpression",
421
+ "name": "string"
422
+ }
423
+ }
424
+ ]
425
+ },
426
+ "valid": true
427
+ },
428
+ {
429
+ "name": "dataValue",
430
+ "params": [
431
+ "path"
432
+ ],
433
+ "docs": {
434
+ "description": "Picks out a single value from the source data object—usually `state.data`.\nIf a JSONPath returns more than one value for the reference, the first\nitem will be returned.",
435
+ "tags": [
436
+ {
437
+ "title": "public",
438
+ "description": null,
439
+ "type": null
440
+ },
441
+ {
442
+ "title": "function",
443
+ "description": null,
444
+ "name": null
445
+ },
446
+ {
447
+ "title": "example",
448
+ "description": "dataValue('key')"
449
+ },
450
+ {
451
+ "title": "param",
452
+ "description": "JSONPath referencing a point in `data`.",
453
+ "type": {
454
+ "type": "NameExpression",
455
+ "name": "String"
456
+ },
457
+ "name": "path"
458
+ },
459
+ {
460
+ "title": "returns",
461
+ "description": null,
462
+ "type": {
463
+ "type": "NameExpression",
464
+ "name": "Operation"
465
+ }
466
+ }
467
+ ]
468
+ },
469
+ "valid": true
470
+ },
471
+ {
472
+ "name": "lastReferenceValue",
473
+ "params": [
474
+ "path"
475
+ ],
476
+ "docs": {
477
+ "description": "Picks out the last reference value from source data.",
478
+ "tags": [
479
+ {
480
+ "title": "public",
481
+ "description": null,
482
+ "type": null
483
+ },
484
+ {
485
+ "title": "function",
486
+ "description": null,
487
+ "name": null
488
+ },
489
+ {
490
+ "title": "example",
491
+ "description": "lastReferenceValue('key')"
492
+ },
493
+ {
494
+ "title": "param",
495
+ "description": "JSONPath referencing a point in `references`.",
496
+ "type": {
497
+ "type": "NameExpression",
498
+ "name": "String"
499
+ },
500
+ "name": "path"
501
+ },
502
+ {
503
+ "title": "returns",
504
+ "description": null,
505
+ "type": {
506
+ "type": "NameExpression",
507
+ "name": "Operation"
508
+ }
509
+ }
510
+ ]
511
+ },
512
+ "valid": true
513
+ },
514
+ {
515
+ "name": "each",
516
+ "params": [
517
+ "dataSource",
518
+ "operation"
519
+ ],
520
+ "docs": {
521
+ "description": "Iterates over an array of items and invokes an operation upon each one, where the state\nobject is _scoped_ so that state.data is the item under iteration.\nThe rest of the state object is untouched and can be referenced as usual.\nYou can pass an array directly, or use lazy state or a JSONPath string to\nreference a slice of state.",
522
+ "tags": [
523
+ {
524
+ "title": "public",
525
+ "description": null,
526
+ "type": null
527
+ },
528
+ {
529
+ "title": "function",
530
+ "description": null,
531
+ "name": null
532
+ },
533
+ {
534
+ "title": "example",
535
+ "description": "each(\n $.data,\n // Inside the callback operation, `$.data` is scoped to the item under iteration\n insert(\"patient\", {\n patient_name: $.data.properties.case_name,\n patient_id: $.data.case_id,\n })\n);",
536
+ "caption": "Using lazy state ($) to iterate over items in state.data and pass each into an \"insert\" operation"
537
+ },
538
+ {
539
+ "title": "example",
540
+ "description": "each(\n $.data,\n insert(\"patient\", (state) => ({\n patient_id: state.data.case_id,\n ...state.data\n }))\n);",
541
+ "caption": "Iterate over items in state.data and pass each one into an \"insert\" operation"
542
+ },
543
+ {
544
+ "title": "example",
545
+ "description": "each(\n \"$.data[*]\",\n insert(\"patient\", (state) => ({\n patient_name: state.data.properties.case_name,\n patient_id: state.data.case_id,\n }))\n);",
546
+ "caption": "Using JSON path to iterate over items in state.data and pass each one into an \"insert\" operation"
547
+ },
548
+ {
549
+ "title": "param",
550
+ "description": "JSONPath referencing a point in `state`.",
551
+ "type": {
552
+ "type": "NameExpression",
553
+ "name": "DataSource"
554
+ },
555
+ "name": "dataSource"
556
+ },
557
+ {
558
+ "title": "param",
559
+ "description": "The operation needed to be repeated.",
560
+ "type": {
561
+ "type": "NameExpression",
562
+ "name": "Operation"
563
+ },
564
+ "name": "operation"
565
+ },
566
+ {
567
+ "title": "returns",
568
+ "description": null,
569
+ "type": {
570
+ "type": "NameExpression",
571
+ "name": "Operation"
572
+ }
573
+ }
574
+ ]
575
+ },
576
+ "valid": true
577
+ },
578
+ {
579
+ "name": "combine",
580
+ "params": [
581
+ "operations"
582
+ ],
583
+ "docs": {
584
+ "description": "Combines two operations into one",
585
+ "tags": [
586
+ {
587
+ "title": "public",
588
+ "description": null,
589
+ "type": null
590
+ },
591
+ {
592
+ "title": "function",
593
+ "description": null,
594
+ "name": null
595
+ },
596
+ {
597
+ "title": "example",
598
+ "description": "combine(\n create('foo'),\n delete('bar')\n)"
599
+ },
600
+ {
601
+ "title": "param",
602
+ "description": "Operations to be performed.",
603
+ "type": {
604
+ "type": "NameExpression",
605
+ "name": "Operations"
606
+ },
607
+ "name": "operations"
608
+ },
609
+ {
610
+ "title": "returns",
611
+ "description": null,
612
+ "type": {
613
+ "type": "NameExpression",
614
+ "name": "Operation"
615
+ }
616
+ }
617
+ ]
618
+ },
619
+ "valid": true
620
+ },
621
+ {
622
+ "name": "field",
623
+ "params": [
624
+ "key",
625
+ "value"
626
+ ],
627
+ "docs": {
628
+ "description": "Returns a key, value pair in an array.",
629
+ "tags": [
630
+ {
631
+ "title": "public",
632
+ "description": null,
633
+ "type": null
634
+ },
635
+ {
636
+ "title": "function",
637
+ "description": null,
638
+ "name": null
639
+ },
640
+ {
641
+ "title": "example",
642
+ "description": "field('destination_field_name__c', 'value')"
643
+ },
644
+ {
645
+ "title": "param",
646
+ "description": "Name of the field",
647
+ "type": {
648
+ "type": "NameExpression",
649
+ "name": "string"
650
+ },
651
+ "name": "key"
652
+ },
653
+ {
654
+ "title": "param",
655
+ "description": "The value itself or a sourceable operation.",
656
+ "type": {
657
+ "type": "NameExpression",
658
+ "name": "Value"
659
+ },
660
+ "name": "value"
661
+ },
662
+ {
663
+ "title": "returns",
664
+ "description": null,
665
+ "type": {
666
+ "type": "NameExpression",
667
+ "name": "Field"
668
+ }
669
+ }
670
+ ]
671
+ },
672
+ "valid": true
673
+ },
674
+ {
675
+ "name": "fields",
676
+ "params": [
677
+ "fields"
678
+ ],
679
+ "docs": {
680
+ "description": "Zips key value pairs into an object.",
681
+ "tags": [
682
+ {
683
+ "title": "public",
684
+ "description": null,
685
+ "type": null
686
+ },
687
+ {
688
+ "title": "function",
689
+ "description": null,
690
+ "name": null
691
+ },
692
+ {
693
+ "title": "example",
694
+ "description": "fields(list_of_fields)"
695
+ },
696
+ {
697
+ "title": "param",
698
+ "description": "a list of fields",
699
+ "type": {
700
+ "type": "NameExpression",
701
+ "name": "Fields"
702
+ },
703
+ "name": "fields"
704
+ },
705
+ {
706
+ "title": "returns",
707
+ "description": null,
708
+ "type": {
709
+ "type": "NameExpression",
710
+ "name": "Object"
711
+ }
712
+ }
713
+ ]
714
+ },
715
+ "valid": true
716
+ },
717
+ {
718
+ "name": "merge",
719
+ "params": [
720
+ "dataSource",
721
+ "fields"
722
+ ],
723
+ "docs": {
724
+ "description": "Merges fields into each item in an array.",
725
+ "tags": [
726
+ {
727
+ "title": "public",
728
+ "description": null,
729
+ "type": null
730
+ },
731
+ {
732
+ "title": "example",
733
+ "description": "merge(\n \"$.books[*]\",\n fields(\n field( \"publisher\", sourceValue(\"$.publisher\") )\n )\n)"
734
+ },
735
+ {
736
+ "title": "function",
737
+ "description": null,
738
+ "name": null
739
+ },
740
+ {
741
+ "title": "public",
742
+ "description": null,
743
+ "type": null
744
+ },
745
+ {
746
+ "title": "param",
747
+ "description": null,
748
+ "type": {
749
+ "type": "NameExpression",
750
+ "name": "DataSource"
751
+ },
752
+ "name": "dataSource"
753
+ },
754
+ {
755
+ "title": "param",
756
+ "description": "Group of fields to merge in.",
757
+ "type": {
758
+ "type": "NameExpression",
759
+ "name": "Object"
760
+ },
761
+ "name": "fields"
762
+ },
763
+ {
764
+ "title": "returns",
765
+ "description": null,
766
+ "type": {
767
+ "type": "NameExpression",
768
+ "name": "DataSource"
769
+ }
770
+ }
771
+ ]
772
+ },
773
+ "valid": true
774
+ },
775
+ {
776
+ "name": "group",
777
+ "params": [
778
+ "arrayOfObjects",
779
+ "keyPath",
780
+ "callback"
781
+ ],
782
+ "docs": {
783
+ "description": "Groups an array of objects by a specified key path.",
784
+ "tags": [
785
+ {
786
+ "title": "public",
787
+ "description": null,
788
+ "type": null
789
+ },
790
+ {
791
+ "title": "example",
792
+ "description": "const users = [\n { name: 'Alice', age: 25, city: 'New York' },\n { name: 'Bob', age: 30, city: 'San Francisco' },\n { name: 'Charlie', age: 25, city: 'New York' },\n { name: 'David', age: 30, city: 'San Francisco' }\n];\ngroup(users, 'city');\n// state is { data: { 'New York': [/Alice, Charlie/], 'San Francisco': [ /Bob, David / ] }"
793
+ },
794
+ {
795
+ "title": "function",
796
+ "description": null,
797
+ "name": null
798
+ },
799
+ {
800
+ "title": "public",
801
+ "description": null,
802
+ "type": null
803
+ },
804
+ {
805
+ "title": "param",
806
+ "description": "The array of objects to be grouped.",
807
+ "type": {
808
+ "type": "TypeApplication",
809
+ "expression": {
810
+ "type": "NameExpression",
811
+ "name": "Array"
812
+ },
813
+ "applications": [
814
+ {
815
+ "type": "NameExpression",
816
+ "name": "Object"
817
+ }
818
+ ]
819
+ },
820
+ "name": "arrayOfObjects"
821
+ },
822
+ {
823
+ "title": "param",
824
+ "description": "The key path to group by.",
825
+ "type": {
826
+ "type": "NameExpression",
827
+ "name": "string"
828
+ },
829
+ "name": "keyPath"
830
+ },
831
+ {
832
+ "title": "param",
833
+ "description": "(Optional) Callback function",
834
+ "type": {
835
+ "type": "NameExpression",
836
+ "name": "function"
837
+ },
838
+ "name": "callback"
839
+ },
840
+ {
841
+ "title": "returns",
842
+ "description": null,
843
+ "type": {
844
+ "type": "NameExpression",
845
+ "name": "Operation"
846
+ }
847
+ }
848
+ ]
849
+ },
850
+ "valid": true
851
+ },
852
+ {
853
+ "name": "arrayToString",
854
+ "params": [
855
+ "arr",
856
+ "separator"
857
+ ],
858
+ "docs": {
859
+ "description": "Turns an array into a string, separated by X.",
860
+ "tags": [
861
+ {
862
+ "title": "public",
863
+ "description": null,
864
+ "type": null
865
+ },
866
+ {
867
+ "title": "function",
868
+ "description": null,
869
+ "name": null
870
+ },
871
+ {
872
+ "title": "example",
873
+ "description": "field(\"destination_string__c\", function(state) {\n return arrayToString(dataValue(\"path_of_array\")(state), ', ')\n})"
874
+ },
875
+ {
876
+ "title": "param",
877
+ "description": "Array of toString'able primatives.",
878
+ "type": {
879
+ "type": "NameExpression",
880
+ "name": "array"
881
+ },
882
+ "name": "arr"
883
+ },
884
+ {
885
+ "title": "param",
886
+ "description": "Separator string.",
887
+ "type": {
888
+ "type": "NameExpression",
889
+ "name": "string"
890
+ },
891
+ "name": "separator"
892
+ },
893
+ {
894
+ "title": "returns",
895
+ "description": null,
896
+ "type": {
897
+ "type": "NameExpression",
898
+ "name": "string"
899
+ }
900
+ }
901
+ ]
902
+ },
903
+ "valid": true
904
+ },
905
+ {
906
+ "name": "cursor",
907
+ "params": [
908
+ "value",
909
+ "options"
910
+ ],
911
+ "docs": {
912
+ "description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones\nare not yet supported.\nYou can provide a formatter to customise the final cursor value, which is useful for normalising\ndifferent inputs. The custom formatter runs after natural language date conversion.\nSee the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
913
+ "tags": [
914
+ {
915
+ "title": "public",
916
+ "description": null,
917
+ "type": null
918
+ },
919
+ {
920
+ "title": "function",
921
+ "description": null,
922
+ "name": null
923
+ },
924
+ {
925
+ "title": "example",
926
+ "description": "cursor($.cursor, { defaultValue: 'today' })",
927
+ "caption": "Use a cursor from state if present, or else use the default value"
928
+ },
929
+ {
930
+ "title": "example",
931
+ "description": "cursor(22)",
932
+ "caption": "Use a pagination cursor"
933
+ },
934
+ {
935
+ "title": "param",
936
+ "description": "the cursor value. Usually an ISO date, natural language date, or page number",
937
+ "type": {
938
+ "type": "NameExpression",
939
+ "name": "any"
940
+ },
941
+ "name": "value"
942
+ },
943
+ {
944
+ "title": "param",
945
+ "description": "options to control the cursor.",
946
+ "type": {
947
+ "type": "NameExpression",
948
+ "name": "object"
949
+ },
950
+ "name": "options"
951
+ },
952
+ {
953
+ "title": "param",
954
+ "description": "set the cursor key. Will persist through the whole run.",
955
+ "type": {
956
+ "type": "NameExpression",
957
+ "name": "string"
958
+ },
959
+ "name": "options.key"
960
+ },
961
+ {
962
+ "title": "param",
963
+ "description": "the value to use if value is falsy",
964
+ "type": {
965
+ "type": "NameExpression",
966
+ "name": "any"
967
+ },
968
+ "name": "options.defaultValue"
969
+ },
970
+ {
971
+ "title": "param",
972
+ "description": "custom formatter for the final cursor value",
973
+ "type": {
974
+ "type": "NameExpression",
975
+ "name": "Function"
976
+ },
977
+ "name": "options.format"
978
+ },
979
+ {
980
+ "title": "returns",
981
+ "description": null,
982
+ "type": {
983
+ "type": "NameExpression",
984
+ "name": "Operation"
985
+ }
986
+ }
987
+ ]
988
+ },
989
+ "valid": false
990
+ },
991
+ {
992
+ "name": "as",
993
+ "params": [
994
+ "key",
995
+ "operation"
996
+ ],
997
+ "docs": {
998
+ "description": "Run an operation and save the result to a custom key in state instead of overwriting state.data.",
999
+ "tags": [
1000
+ {
1001
+ "title": "public",
1002
+ "description": null,
1003
+ "type": null
1004
+ },
1005
+ {
1006
+ "title": "function",
1007
+ "description": null,
1008
+ "name": null
1009
+ },
1010
+ {
1011
+ "title": "example",
1012
+ "description": "as('cceData', collections.get('cce-data-dhis2', { key: `*:*:${$.syncedAt}*` }));",
1013
+ "caption": "Fetch cce-data from collections and store them under state.cceData"
1014
+ },
1015
+ {
1016
+ "title": "param",
1017
+ "description": "The state key to assign the result of the operation to.",
1018
+ "type": {
1019
+ "type": "NameExpression",
1020
+ "name": "string"
1021
+ },
1022
+ "name": "key"
1023
+ },
1024
+ {
1025
+ "title": "param",
1026
+ "description": " An operation that returns a new state object with a `data` property",
1027
+ "type": {
1028
+ "type": "NameExpression",
1029
+ "name": "function"
1030
+ },
1031
+ "name": "operation"
1032
+ },
1033
+ {
1034
+ "title": "returns",
1035
+ "description": null,
1036
+ "type": {
1037
+ "type": "NameExpression",
1038
+ "name": "Operation"
1039
+ }
1040
+ }
1041
+ ]
1042
+ },
1043
+ "valid": true
1044
+ },
1045
+ {
1046
+ "name": "map",
1047
+ "params": {},
1048
+ "docs": {
1049
+ "description": "Iterates over a collection of items and returns a new array of mapped values,\nlike Javascript's `Array.map()` function.\n\nEach item in the source array will be passed into the callback function. The returned value\nwill be added to the new array. The callback is passed the original item, the current index\nin the source array (ie, the nth item number), and the state object.\n\nWrites a new array to `state.data` with transformed values.c array.",
1050
+ "tags": [
1051
+ {
1052
+ "title": "public",
1053
+ "description": null,
1054
+ "type": null
1055
+ },
1056
+ {
1057
+ "title": "function",
1058
+ "description": null,
1059
+ "name": null
1060
+ },
1061
+ {
1062
+ "title": "example",
1063
+ "description": "map($.items', (data, index, state) => {\n return {\n id: index + 1,\n name: data.name,\n createdAt: state.cursor,\n };\n});",
1064
+ "caption": "Transform an array of items in state"
1065
+ },
1066
+ {
1067
+ "title": "example",
1068
+ "description": "map($.items, async (data, index, state) => {\n const userInfo = await fetchUserInfo(data.userId);\n return {\n id: index + 1,\n name: data.name,\n extra: userInfo,\n };\n});",
1069
+ "caption": "Map items asynchronously (e.g. fetch extra info)"
1070
+ },
1071
+ {
1072
+ "title": "param",
1073
+ "description": "An array of items or a a JSONPath string which points to an array of items.",
1074
+ "type": {
1075
+ "type": "UnionType",
1076
+ "elements": [
1077
+ {
1078
+ "type": "NameExpression",
1079
+ "name": "string"
1080
+ },
1081
+ {
1082
+ "type": "NameExpression",
1083
+ "name": "Array"
1084
+ }
1085
+ ]
1086
+ },
1087
+ "name": "path"
1088
+ },
1089
+ {
1090
+ "title": "param",
1091
+ "description": "The mapping function, invoked with `(data, index, state)` for each item in the array.",
1092
+ "type": {
1093
+ "type": "NameExpression",
1094
+ "name": "function"
1095
+ },
1096
+ "name": "callback"
1097
+ },
1098
+ {
1099
+ "title": "returns",
1100
+ "description": null,
1101
+ "type": {
1102
+ "type": "NameExpression",
1103
+ "name": "State"
1104
+ }
1105
+ }
1106
+ ]
1107
+ },
1108
+ "valid": false
1109
+ }
1110
+ ]
1111
+ }