@openfn/language-common 1.13.1 → 1.13.3
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 +10 -1
- package/dist/index.cjs +7 -6
- package/dist/index.js +7 -6
- package/package.json +3 -3
- package/types/Adaptor.d.ts +4 -0
package/ast.json
CHANGED
|
@@ -1319,7 +1319,7 @@
|
|
|
1319
1319
|
"options"
|
|
1320
1320
|
],
|
|
1321
1321
|
"docs": {
|
|
1322
|
-
"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.\nSee the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
|
|
1322
|
+
"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}",
|
|
1323
1323
|
"tags": [
|
|
1324
1324
|
{
|
|
1325
1325
|
"title": "public",
|
|
@@ -1377,6 +1377,15 @@
|
|
|
1377
1377
|
},
|
|
1378
1378
|
"name": "options.defaultValue"
|
|
1379
1379
|
},
|
|
1380
|
+
{
|
|
1381
|
+
"title": "param",
|
|
1382
|
+
"description": "custom formatter for the final cursor value",
|
|
1383
|
+
"type": {
|
|
1384
|
+
"type": "NameExpression",
|
|
1385
|
+
"name": "Function"
|
|
1386
|
+
},
|
|
1387
|
+
"name": "options.format"
|
|
1388
|
+
},
|
|
1380
1389
|
{
|
|
1381
1390
|
"title": "returns",
|
|
1382
1391
|
"description": null,
|
package/dist/index.cjs
CHANGED
|
@@ -105,7 +105,7 @@ var import_jsonpath_plus = require("jsonpath-plus");
|
|
|
105
105
|
var import_csv_parse = require("csv-parse");
|
|
106
106
|
var import_node_stream3 = require("stream");
|
|
107
107
|
var import_undici2 = require("undici");
|
|
108
|
-
var import_date_fns3 = require("date-fns");
|
|
108
|
+
var import_date_fns3 = __toESM(require("date-fns"), 1);
|
|
109
109
|
|
|
110
110
|
// src/util/http.js
|
|
111
111
|
var import_undici = require("undici");
|
|
@@ -645,7 +645,8 @@ var cursorStart = void 0;
|
|
|
645
645
|
var cursorKey = "cursor";
|
|
646
646
|
function cursor(value, options2 = {}) {
|
|
647
647
|
return (state) => {
|
|
648
|
-
const
|
|
648
|
+
const { format: format2, ...optionsWithoutFormat } = options2;
|
|
649
|
+
const [resolvedValue, resolvedOptions] = expandReferences(state, value, optionsWithoutFormat);
|
|
649
650
|
const {
|
|
650
651
|
defaultValue,
|
|
651
652
|
key
|
|
@@ -660,14 +661,14 @@ function cursor(value, options2 = {}) {
|
|
|
660
661
|
if (typeof cursor2 === "string") {
|
|
661
662
|
const date = parse_date_default(cursor2, cursorStart);
|
|
662
663
|
if (date instanceof Date && date.toString !== "Invalid Date") {
|
|
663
|
-
state[cursorKey] = date.toISOString();
|
|
664
|
-
const formatted =
|
|
664
|
+
state[cursorKey] = (format2 == null ? void 0 : format2(date)) ?? date.toISOString();
|
|
665
|
+
const formatted = format2 ? state[cursorKey] : import_date_fns3.default.format(date, "HH:MM d MMM yyyy (OOO)");
|
|
665
666
|
console.log(`Setting cursor "${cursor2}" to: ${formatted}`);
|
|
666
667
|
return state;
|
|
667
668
|
}
|
|
668
669
|
}
|
|
669
|
-
state[cursorKey] = cursor2;
|
|
670
|
-
console.log("Setting cursor to:",
|
|
670
|
+
state[cursorKey] = (format2 == null ? void 0 : format2(cursor2)) ?? cursor2;
|
|
671
|
+
console.log("Setting cursor to:", state[cursorKey]);
|
|
671
672
|
return state;
|
|
672
673
|
};
|
|
673
674
|
}
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,7 @@ import { JSONPath } from "jsonpath-plus";
|
|
|
47
47
|
import { parse as parse2 } from "csv-parse";
|
|
48
48
|
import { Readable as Readable2 } from "stream";
|
|
49
49
|
import { request } from "undici";
|
|
50
|
-
import
|
|
50
|
+
import dateFns from "date-fns";
|
|
51
51
|
|
|
52
52
|
// src/util/http.js
|
|
53
53
|
import { Client, MockAgent } from "undici";
|
|
@@ -586,7 +586,8 @@ var cursorStart = void 0;
|
|
|
586
586
|
var cursorKey = "cursor";
|
|
587
587
|
function cursor(value, options2 = {}) {
|
|
588
588
|
return (state) => {
|
|
589
|
-
const
|
|
589
|
+
const { format: format2, ...optionsWithoutFormat } = options2;
|
|
590
|
+
const [resolvedValue, resolvedOptions] = expandReferences(state, value, optionsWithoutFormat);
|
|
590
591
|
const {
|
|
591
592
|
defaultValue,
|
|
592
593
|
key
|
|
@@ -601,14 +602,14 @@ function cursor(value, options2 = {}) {
|
|
|
601
602
|
if (typeof cursor2 === "string") {
|
|
602
603
|
const date = parse_date_default(cursor2, cursorStart);
|
|
603
604
|
if (date instanceof Date && date.toString !== "Invalid Date") {
|
|
604
|
-
state[cursorKey] = date.toISOString();
|
|
605
|
-
const formatted = format2(date, "HH:MM d MMM yyyy (OOO)");
|
|
605
|
+
state[cursorKey] = (format2 == null ? void 0 : format2(date)) ?? date.toISOString();
|
|
606
|
+
const formatted = format2 ? state[cursorKey] : dateFns.format(date, "HH:MM d MMM yyyy (OOO)");
|
|
606
607
|
console.log(`Setting cursor "${cursor2}" to: ${formatted}`);
|
|
607
608
|
return state;
|
|
608
609
|
}
|
|
609
610
|
}
|
|
610
|
-
state[cursorKey] = cursor2;
|
|
611
|
-
console.log("Setting cursor to:",
|
|
611
|
+
state[cursorKey] = (format2 == null ? void 0 : format2(cursor2)) ?? cursor2;
|
|
612
|
+
console.log("Setting cursor to:", state[cursorKey]);
|
|
612
613
|
return state;
|
|
613
614
|
};
|
|
614
615
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-common",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.3",
|
|
4
4
|
"description": "Common Expressions for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"repository": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"date-fns": "^2.25.0",
|
|
41
41
|
"http-status-codes": "^2.3.0",
|
|
42
42
|
"jsonpath-plus": "^4.0.0",
|
|
43
|
-
"lodash": "^4.17.
|
|
44
|
-
"undici": "^5.
|
|
43
|
+
"lodash": "^4.17.21",
|
|
44
|
+
"undici": "^5.28.4"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@openfn/simple-ast": "0.4.1",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -352,6 +352,8 @@ export function validate(schema?: string | object, data?: string | object): Oper
|
|
|
352
352
|
* Supports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,
|
|
353
353
|
* which will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones
|
|
354
354
|
* are not yet supported.
|
|
355
|
+
* You can provide a formatter to customise the final cursor value, which is useful for normalising
|
|
356
|
+
* different inputs. The custom formatter runs after natural language date conversion.
|
|
355
357
|
* See the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}
|
|
356
358
|
* @public
|
|
357
359
|
* @example <caption>Use a cursor from state if present, or else use the default value</caption>
|
|
@@ -363,11 +365,13 @@ export function validate(schema?: string | object, data?: string | object): Oper
|
|
|
363
365
|
* @param {object} options - options to control the cursor.
|
|
364
366
|
* @param {string} options.key - set the cursor key. Will persist through the whole run.
|
|
365
367
|
* @param {any} options.defaultValue - the value to use if value is falsy
|
|
368
|
+
* @param {Function} options.format - custom formatter for the final cursor value
|
|
366
369
|
* @returns {Operation}
|
|
367
370
|
*/
|
|
368
371
|
export function cursor(value: any, options?: {
|
|
369
372
|
key: string;
|
|
370
373
|
defaultValue: any;
|
|
374
|
+
format: Function;
|
|
371
375
|
}): Operation;
|
|
372
376
|
export * as beta from "./beta";
|
|
373
377
|
export * as http from "./http.deprecated";
|