@openfn/language-common 2.1.0 → 2.1.1
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 +13 -2
- package/dist/util.cjs +19 -0
- package/dist/util.js +18 -0
- package/package.json +1 -1
- package/types/Adaptor.d.ts +30 -14
- package/types/util/index.d.ts +2 -1
- package/types/util/throw-error.d.ts +5 -0
package/ast.json
CHANGED
|
@@ -541,7 +541,7 @@
|
|
|
541
541
|
"operation"
|
|
542
542
|
],
|
|
543
543
|
"docs": {
|
|
544
|
-
"description": "
|
|
544
|
+
"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.",
|
|
545
545
|
"tags": [
|
|
546
546
|
{
|
|
547
547
|
"title": "public",
|
|
@@ -555,7 +555,18 @@
|
|
|
555
555
|
},
|
|
556
556
|
{
|
|
557
557
|
"title": "example",
|
|
558
|
-
"description": "each(\
|
|
558
|
+
"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);",
|
|
559
|
+
"caption": "Using lazy state ($) to iterate over items in state.data and pass each into an \"insert\" operation"
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
"title": "example",
|
|
563
|
+
"description": "each(\n $.data,\n insert(\"patient\", (state) => ({\n patient_id: state.data.case_id,\n ...state.data\n }))\n);",
|
|
564
|
+
"caption": "Iterate over items in state.data and pass each one into an \"insert\" operation"
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
"title": "example",
|
|
568
|
+
"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);",
|
|
569
|
+
"caption": "Using JSON path to iterate over items in state.data and pass each one into an \"insert\" operation"
|
|
559
570
|
},
|
|
560
571
|
{
|
|
561
572
|
"title": "param",
|
package/dist/util.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(util_exports, {
|
|
|
42
42
|
post: () => post,
|
|
43
43
|
put: () => put,
|
|
44
44
|
request: () => request,
|
|
45
|
+
throwError: () => throw_error_default,
|
|
45
46
|
uuid: () => uuid
|
|
46
47
|
});
|
|
47
48
|
module.exports = __toCommonJS(util_exports);
|
|
@@ -311,6 +312,23 @@ var parse_date_default = (d, startDate) => {
|
|
|
311
312
|
}
|
|
312
313
|
return d;
|
|
313
314
|
};
|
|
315
|
+
|
|
316
|
+
// src/util/throw-error.js
|
|
317
|
+
var throw_error_default = (code, { description, fix, ...extras } = {}) => {
|
|
318
|
+
const message = description ? `${code}: ${description}` : code;
|
|
319
|
+
const e = new Error(message);
|
|
320
|
+
e.code = code;
|
|
321
|
+
if (description) {
|
|
322
|
+
e.description = description;
|
|
323
|
+
}
|
|
324
|
+
if (fix) {
|
|
325
|
+
e.fix = fix;
|
|
326
|
+
}
|
|
327
|
+
for (const key in extras) {
|
|
328
|
+
e[key] = extras[key];
|
|
329
|
+
}
|
|
330
|
+
throw e;
|
|
331
|
+
};
|
|
314
332
|
// Annotate the CommonJS export names for ESM import in node:
|
|
315
333
|
0 && (module.exports = {
|
|
316
334
|
ERROR_ABSOLUTE_URL,
|
|
@@ -330,5 +348,6 @@ var parse_date_default = (d, startDate) => {
|
|
|
330
348
|
post,
|
|
331
349
|
put,
|
|
332
350
|
request,
|
|
351
|
+
throwError,
|
|
333
352
|
uuid
|
|
334
353
|
});
|
package/dist/util.js
CHANGED
|
@@ -263,6 +263,23 @@ var parse_date_default = (d, startDate) => {
|
|
|
263
263
|
}
|
|
264
264
|
return d;
|
|
265
265
|
};
|
|
266
|
+
|
|
267
|
+
// src/util/throw-error.js
|
|
268
|
+
var throw_error_default = (code, { description, fix, ...extras } = {}) => {
|
|
269
|
+
const message = description ? `${code}: ${description}` : code;
|
|
270
|
+
const e = new Error(message);
|
|
271
|
+
e.code = code;
|
|
272
|
+
if (description) {
|
|
273
|
+
e.description = description;
|
|
274
|
+
}
|
|
275
|
+
if (fix) {
|
|
276
|
+
e.fix = fix;
|
|
277
|
+
}
|
|
278
|
+
for (const key in extras) {
|
|
279
|
+
e[key] = extras[key];
|
|
280
|
+
}
|
|
281
|
+
throw e;
|
|
282
|
+
};
|
|
266
283
|
export {
|
|
267
284
|
ERROR_ABSOLUTE_URL,
|
|
268
285
|
ERROR_URL_MISMATCH,
|
|
@@ -281,5 +298,6 @@ export {
|
|
|
281
298
|
post,
|
|
282
299
|
put,
|
|
283
300
|
request,
|
|
301
|
+
throw_error_default as throwError,
|
|
284
302
|
uuid
|
|
285
303
|
};
|
package/package.json
CHANGED
package/types/Adaptor.d.ts
CHANGED
|
@@ -138,22 +138,38 @@ export function lastReferenceValue(path: string): Operation;
|
|
|
138
138
|
*/
|
|
139
139
|
export function asData(data: string | object | Function, state: object): any[];
|
|
140
140
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* It also ensures the results of an operation make their way back into
|
|
148
|
-
* the state's references.
|
|
141
|
+
* Iterates over an array of items and invokes an operation upon each one, where the state
|
|
142
|
+
* object is _scoped_ so that state.data is the item under iteration.
|
|
143
|
+
* The rest of the state object is untouched and can be referenced as usual.
|
|
144
|
+
* You can pass an array directly, or use lazy state or a JSONPath string to
|
|
145
|
+
* reference a slice of state.
|
|
149
146
|
* @public
|
|
150
147
|
* @function
|
|
151
|
-
* @example
|
|
152
|
-
* each(
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
148
|
+
* @example <caption>Using lazy state ($) to iterate over items in state.data and pass each into an "insert" operation</caption>
|
|
149
|
+
* each(
|
|
150
|
+
* $.data,
|
|
151
|
+
* // Inside the callback operation, `$.data` is scoped to the item under iteration
|
|
152
|
+
* insert("patient", {
|
|
153
|
+
* patient_name: $.data.properties.case_name,
|
|
154
|
+
* patient_id: $.data.case_id,
|
|
155
|
+
* })
|
|
156
|
+
* );
|
|
157
|
+
* @example <caption>Iterate over items in state.data and pass each one into an "insert" operation</caption>
|
|
158
|
+
* each(
|
|
159
|
+
* $.data,
|
|
160
|
+
* insert("patient", (state) => ({
|
|
161
|
+
* patient_id: state.data.case_id,
|
|
162
|
+
* ...state.data
|
|
163
|
+
* }))
|
|
164
|
+
* );
|
|
165
|
+
* @example <caption>Using JSON path to iterate over items in state.data and pass each one into an "insert" operation</caption>
|
|
166
|
+
* each(
|
|
167
|
+
* "$.data[*]",
|
|
168
|
+
* insert("patient", (state) => ({
|
|
169
|
+
* patient_name: state.data.properties.case_name,
|
|
170
|
+
* patient_id: state.data.case_id,
|
|
171
|
+
* }))
|
|
172
|
+
* );
|
|
157
173
|
* @param {DataSource} dataSource - JSONPath referencing a point in `state`.
|
|
158
174
|
* @param {Operation} operation - The operation needed to be repeated.
|
|
159
175
|
* @returns {Operation}
|
package/types/util/index.d.ts
CHANGED