@workflow/utils 4.0.1-beta.7 → 4.0.1-beta.8

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,25 @@
1
+ /**
2
+ * Known paths where workflow data might be stored, relative to the project root.
3
+ */
4
+ export declare const possibleWorkflowDataPaths: readonly [".next/workflow-data", ".workflow-data", "workflow-data"];
5
+ export interface WorkflowDataDirInfo {
6
+ /** Absolute path to the project root (parent of the workflow data folder) */
7
+ projectDir: string;
8
+ /** Absolute path to the workflow data directory */
9
+ dataDir: string;
10
+ /** Short name for display: up to last two folder names of projectDir */
11
+ shortName: string;
12
+ }
13
+ /**
14
+ * Finds the workflow data directory starting from the given path.
15
+ *
16
+ * This function handles several cases:
17
+ * 1. The path itself is a workflow data directory
18
+ * 2. The path contains one of the known workflow data directories
19
+ * 3. The path is somewhere inside a project with workflow data
20
+ *
21
+ * @param cwd - The directory to start searching from (can be relative, absolute, or use ~)
22
+ * @returns Information about the found workflow data directory, or null if not found
23
+ */
24
+ export declare function findWorkflowDataDir(cwd: string): Promise<WorkflowDataDirInfo | null>;
25
+ //# sourceMappingURL=check-data-dir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-data-dir.d.ts","sourceRoot":"","sources":["../src/check-data-dir.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,yBAAyB,qEAI5B,CAAC;AAEX,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,SAAS,EAAE,MAAM,CAAC;CACnB;AA+ED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAkDrC"}
@@ -0,0 +1,139 @@
1
+ import { access } from 'node:fs/promises';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
4
+ /**
5
+ * Known paths where workflow data might be stored, relative to the project root.
6
+ */
7
+ export const possibleWorkflowDataPaths = [
8
+ '.next/workflow-data',
9
+ '.workflow-data',
10
+ 'workflow-data',
11
+ ];
12
+ /**
13
+ * Expands a path that starts with ~ to use the user's home directory.
14
+ */
15
+ function expandTilde(path) {
16
+ if (path.startsWith('~')) {
17
+ return join(homedir(), path.slice(1));
18
+ }
19
+ return path;
20
+ }
21
+ /**
22
+ * Normalizes a path to an absolute path.
23
+ */
24
+ function toAbsolutePath(path, basePath) {
25
+ const expanded = expandTilde(path);
26
+ if (isAbsolute(expanded)) {
27
+ return resolve(expanded);
28
+ }
29
+ return resolve(basePath || process.cwd(), expanded);
30
+ }
31
+ /**
32
+ * Extracts up to the last two folder names from a path for a short display name.
33
+ *
34
+ * Examples:
35
+ * - `/Users/peter/code/myproject` → `code/myproject`
36
+ * - `/myproject` → `myproject`
37
+ * - `/` → ``
38
+ */
39
+ function getShortName(projectDir) {
40
+ const parts = projectDir.split(sep).filter(Boolean);
41
+ if (parts.length === 0) {
42
+ return '';
43
+ }
44
+ if (parts.length === 1) {
45
+ return parts[0];
46
+ }
47
+ return parts.slice(-2).join('/');
48
+ }
49
+ /**
50
+ * Checks if a directory exists.
51
+ */
52
+ async function directoryExists(path) {
53
+ try {
54
+ await access(path);
55
+ return true;
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
61
+ /**
62
+ * Checks if the given path is itself a workflow data directory
63
+ * (ends with one of the possibleWorkflowDataPaths).
64
+ *
65
+ * Returns the matching suffix and the projectDir if found.
66
+ */
67
+ function checkIfPathIsWorkflowDataDir(absolutePath) {
68
+ for (const suffix of possibleWorkflowDataPaths) {
69
+ // Handle both forward slashes and the platform's separator
70
+ const normalizedSuffix = suffix.split('/').join(sep);
71
+ if (absolutePath.endsWith(normalizedSuffix)) {
72
+ // Calculate how many directories up we need to go
73
+ const suffixParts = suffix.split('/').length;
74
+ let projectDir = absolutePath;
75
+ for (let i = 0; i < suffixParts; i++) {
76
+ projectDir = dirname(projectDir);
77
+ }
78
+ return { suffix, projectDir };
79
+ }
80
+ }
81
+ return null;
82
+ }
83
+ /**
84
+ * Finds the workflow data directory starting from the given path.
85
+ *
86
+ * This function handles several cases:
87
+ * 1. The path itself is a workflow data directory
88
+ * 2. The path contains one of the known workflow data directories
89
+ * 3. The path is somewhere inside a project with workflow data
90
+ *
91
+ * @param cwd - The directory to start searching from (can be relative, absolute, or use ~)
92
+ * @returns Information about the found workflow data directory, or null if not found
93
+ */
94
+ export async function findWorkflowDataDir(cwd) {
95
+ const absoluteCwd = toAbsolutePath(cwd);
96
+ // Case 1: Check if the path itself is already a workflow data directory
97
+ const isDataDir = checkIfPathIsWorkflowDataDir(absoluteCwd);
98
+ if (isDataDir && (await directoryExists(absoluteCwd))) {
99
+ return {
100
+ projectDir: isDataDir.projectDir,
101
+ dataDir: absoluteCwd,
102
+ shortName: getShortName(isDataDir.projectDir),
103
+ };
104
+ }
105
+ // Case 2: Check if cwd contains one of the workflow data directories
106
+ for (const path of possibleWorkflowDataPaths) {
107
+ const fullPath = join(absoluteCwd, path);
108
+ if (await directoryExists(fullPath)) {
109
+ return {
110
+ projectDir: absoluteCwd,
111
+ dataDir: resolve(fullPath),
112
+ shortName: getShortName(absoluteCwd),
113
+ };
114
+ }
115
+ }
116
+ // Case 3: Walk up the directory tree to find the project root
117
+ let currentDir = absoluteCwd;
118
+ const root = resolve('/');
119
+ while (currentDir !== root) {
120
+ // Check if any workflow data path exists here
121
+ for (const path of possibleWorkflowDataPaths) {
122
+ const fullPath = join(currentDir, path);
123
+ if (await directoryExists(fullPath)) {
124
+ return {
125
+ projectDir: currentDir,
126
+ dataDir: resolve(fullPath),
127
+ shortName: getShortName(currentDir),
128
+ };
129
+ }
130
+ }
131
+ const parentDir = dirname(currentDir);
132
+ if (parentDir === currentDir) {
133
+ break; // Reached the filesystem root
134
+ }
135
+ currentDir = parentDir;
136
+ }
137
+ return null;
138
+ }
139
+ //# sourceMappingURL=check-data-dir.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-data-dir.js","sourceRoot":"","sources":["../src/check-data-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,qBAAqB;IACrB,gBAAgB;IAChB,eAAe;CACP,CAAC;AAWX;;GAEG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,QAAiB;IACrD,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,UAAkB;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;I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7B,MAAM,CAAC,8BAA8B;QACvC,CAAC;QACD,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,39 +1,3 @@
1
- import type { StringValue } from 'ms';
2
- export interface PromiseWithResolvers<T> {
3
- promise: Promise<T>;
4
- resolve: (value: T) => void;
5
- reject: (reason?: any) => void;
6
- }
7
- /**
8
- * Polyfill for `Promise.withResolvers()`.
9
- *
10
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
11
- */
12
- export declare function withResolvers<T>(): PromiseWithResolvers<T>;
13
- /**
14
- * Creates a lazily-evaluated, memoized version of the provided function.
15
- *
16
- * The returned object exposes a `value` getter that calls `fn` only once,
17
- * caches its result, and returns the cached value on subsequent accesses.
18
- *
19
- * @typeParam T - The return type of the provided function.
20
- * @param fn - The function to be called once and whose result will be cached.
21
- * @returns An object with a `value` property that returns the memoized result of `fn`.
22
- */
23
- export declare function once<T>(fn: () => T): {
24
- readonly value: T;
25
- };
26
- /**
27
- * Parses a duration parameter (string, number, or Date) and returns a Date object
28
- * representing when the duration should elapse.
29
- *
30
- * - For strings: Parses duration strings like "1s", "5m", "1h", etc. using the `ms` library
31
- * - For numbers: Treats as milliseconds from now
32
- * - For Date objects: Returns the date directly (handles both Date instances and date-like objects from deserialization)
33
- *
34
- * @param param - The duration parameter (StringValue, Date, or number of milliseconds)
35
- * @returns A Date object representing when the duration should elapse
36
- * @throws {Error} If the parameter is invalid or cannot be parsed
37
- */
38
- export declare function parseDurationToDate(param: StringValue | Date | number): Date;
1
+ export { once, type PromiseWithResolvers, withResolvers } from './promise.js';
2
+ export { parseDurationToDate } from './time.js';
39
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAGtC,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAChC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,CAQ1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC;;EASlC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CA6B5E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,73 +1,3 @@
1
- import ms from 'ms';
2
- /**
3
- * Polyfill for `Promise.withResolvers()`.
4
- *
5
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
6
- */
7
- export function withResolvers() {
8
- let resolve;
9
- let reject;
10
- const promise = new Promise((_resolve, _reject) => {
11
- resolve = _resolve;
12
- reject = _reject;
13
- });
14
- return { promise, resolve, reject };
15
- }
16
- /**
17
- * Creates a lazily-evaluated, memoized version of the provided function.
18
- *
19
- * The returned object exposes a `value` getter that calls `fn` only once,
20
- * caches its result, and returns the cached value on subsequent accesses.
21
- *
22
- * @typeParam T - The return type of the provided function.
23
- * @param fn - The function to be called once and whose result will be cached.
24
- * @returns An object with a `value` property that returns the memoized result of `fn`.
25
- */
26
- export function once(fn) {
27
- const result = {
28
- get value() {
29
- const value = fn();
30
- Object.defineProperty(result, 'value', { value });
31
- return value;
32
- },
33
- };
34
- return result;
35
- }
36
- /**
37
- * Parses a duration parameter (string, number, or Date) and returns a Date object
38
- * representing when the duration should elapse.
39
- *
40
- * - For strings: Parses duration strings like "1s", "5m", "1h", etc. using the `ms` library
41
- * - For numbers: Treats as milliseconds from now
42
- * - For Date objects: Returns the date directly (handles both Date instances and date-like objects from deserialization)
43
- *
44
- * @param param - The duration parameter (StringValue, Date, or number of milliseconds)
45
- * @returns A Date object representing when the duration should elapse
46
- * @throws {Error} If the parameter is invalid or cannot be parsed
47
- */
48
- export function parseDurationToDate(param) {
49
- if (typeof param === 'string') {
50
- const durationMs = ms(param);
51
- if (typeof durationMs !== 'number' || durationMs < 0) {
52
- throw new Error(`Invalid duration: "${param}". Expected a valid duration string like "1s", "1m", "1h", etc.`);
53
- }
54
- return new Date(Date.now() + durationMs);
55
- }
56
- else if (typeof param === 'number') {
57
- if (param < 0 || !Number.isFinite(param)) {
58
- throw new Error(`Invalid duration: ${param}. Expected a non-negative finite number of milliseconds.`);
59
- }
60
- return new Date(Date.now() + param);
61
- }
62
- else if (param instanceof Date ||
63
- (param &&
64
- typeof param === 'object' &&
65
- typeof param.getTime === 'function')) {
66
- // Handle both Date instances and date-like objects (from deserialization)
67
- return param instanceof Date ? param : new Date(param.getTime());
68
- }
69
- else {
70
- throw new Error(`Invalid duration parameter. Expected a duration string, number (milliseconds), or Date object.`);
71
- }
72
- }
1
+ export { once, withResolvers } from './promise.js';
2
+ export { parseDurationToDate } from './time.js';
73
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AAQpB;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,IAAI,OAA4B,CAAC;IACjC,IAAI,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,KAAK,CAAC,CAAC;IACtC,CAAC;SAAM,IACL,KAAK,YAAY,IAAI;QACrB,CAAC,KAAK;YACJ,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAQ,KAAa,CAAC,OAAO,KAAK,UAAU,CAAC,EAC/C,CAAC;QACD,0EAA0E;QAC1E,OAAO,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAE,KAAa,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;IACJ,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA6B,aAAa,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,25 @@
1
+ export interface PromiseWithResolvers<T> {
2
+ promise: Promise<T>;
3
+ resolve: (value: T) => void;
4
+ reject: (reason?: any) => void;
5
+ }
6
+ /**
7
+ * Polyfill for `Promise.withResolvers()`.
8
+ *
9
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
10
+ */
11
+ export declare function withResolvers<T>(): PromiseWithResolvers<T>;
12
+ /**
13
+ * Creates a lazily-evaluated, memoized version of the provided function.
14
+ *
15
+ * The returned object exposes a `value` getter that calls `fn` only once,
16
+ * caches its result, and returns the cached value on subsequent accesses.
17
+ *
18
+ * @typeParam T - The return type of the provided function.
19
+ * @param fn - The function to be called once and whose result will be cached.
20
+ * @returns An object with a `value` property that returns the memoized result of `fn`.
21
+ */
22
+ export declare function once<T>(fn: () => T): {
23
+ readonly value: T;
24
+ };
25
+ //# sourceMappingURL=promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAChC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,CAQ1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC;;EASlC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Polyfill for `Promise.withResolvers()`.
3
+ *
4
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
5
+ */
6
+ export function withResolvers() {
7
+ let resolve;
8
+ let reject;
9
+ const promise = new Promise((_resolve, _reject) => {
10
+ resolve = _resolve;
11
+ reject = _reject;
12
+ });
13
+ return { promise, resolve, reject };
14
+ }
15
+ /**
16
+ * Creates a lazily-evaluated, memoized version of the provided function.
17
+ *
18
+ * The returned object exposes a `value` getter that calls `fn` only once,
19
+ * caches its result, and returns the cached value on subsequent accesses.
20
+ *
21
+ * @typeParam T - The return type of the provided function.
22
+ * @param fn - The function to be called once and whose result will be cached.
23
+ * @returns An object with a `value` property that returns the memoized result of `fn`.
24
+ */
25
+ export function once(fn) {
26
+ const result = {
27
+ get value() {
28
+ const value = fn();
29
+ Object.defineProperty(result, 'value', { value });
30
+ return value;
31
+ },
32
+ };
33
+ return result;
34
+ }
35
+ //# sourceMappingURL=promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../src/promise.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC3B,IAAI,OAA4B,CAAC;IACjC,IAAI,MAA+B,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE;QACnD,OAAO,GAAG,QAAQ,CAAC;QACnB,MAAM,GAAG,OAAO,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACtC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,IAAI,CAAI,EAAW;IACjC,MAAM,MAAM,GAAG;QACb,IAAI,KAAK;YACP,MAAM,KAAK,GAAG,EAAE,EAAE,CAAC;YACnB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAClD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/dist/time.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { StringValue } from 'ms';
2
+ /**
3
+ * Parses a duration parameter (string, number, or Date) and returns a Date object
4
+ * representing when the duration should elapse.
5
+ *
6
+ * - For strings: Parses duration strings like "1s", "5m", "1h", etc. using the `ms` library
7
+ * - For numbers: Treats as milliseconds from now
8
+ * - For Date objects: Returns the date directly (handles both Date instances and date-like objects from deserialization)
9
+ *
10
+ * @param param - The duration parameter (StringValue, Date, or number of milliseconds)
11
+ * @returns A Date object representing when the duration should elapse
12
+ * @throws {Error} If the parameter is invalid or cannot be parsed
13
+ */
14
+ export declare function parseDurationToDate(param: StringValue | Date | number): Date;
15
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAGtC;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CA6B5E"}
package/dist/time.js ADDED
@@ -0,0 +1,39 @@
1
+ import ms from 'ms';
2
+ /**
3
+ * Parses a duration parameter (string, number, or Date) and returns a Date object
4
+ * representing when the duration should elapse.
5
+ *
6
+ * - For strings: Parses duration strings like "1s", "5m", "1h", etc. using the `ms` library
7
+ * - For numbers: Treats as milliseconds from now
8
+ * - For Date objects: Returns the date directly (handles both Date instances and date-like objects from deserialization)
9
+ *
10
+ * @param param - The duration parameter (StringValue, Date, or number of milliseconds)
11
+ * @returns A Date object representing when the duration should elapse
12
+ * @throws {Error} If the parameter is invalid or cannot be parsed
13
+ */
14
+ export function parseDurationToDate(param) {
15
+ if (typeof param === 'string') {
16
+ const durationMs = ms(param);
17
+ if (typeof durationMs !== 'number' || durationMs < 0) {
18
+ throw new Error(`Invalid duration: "${param}". Expected a valid duration string like "1s", "1m", "1h", etc.`);
19
+ }
20
+ return new Date(Date.now() + durationMs);
21
+ }
22
+ else if (typeof param === 'number') {
23
+ if (param < 0 || !Number.isFinite(param)) {
24
+ throw new Error(`Invalid duration: ${param}. Expected a non-negative finite number of milliseconds.`);
25
+ }
26
+ return new Date(Date.now() + param);
27
+ }
28
+ else if (param instanceof Date ||
29
+ (param &&
30
+ typeof param === 'object' &&
31
+ typeof param.getTime === 'function')) {
32
+ // Handle both Date instances and date-like objects (from deserialization)
33
+ return param instanceof Date ? param : new Date(param.getTime());
34
+ }
35
+ else {
36
+ throw new Error(`Invalid duration parameter. Expected a duration string, number (milliseconds), or Date object.`);
37
+ }
38
+ }
39
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAkC;IACpE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,KAAK,CACb,sBAAsB,KAAK,iEAAiE,CAC7F,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,CAAC;IAC3C,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACb,qBAAqB,KAAK,0DAA0D,CACrF,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;IACtC,CAAC;SAAM,IACL,KAAK,YAAY,IAAI;QACrB,CAAC,KAAK;YACJ,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAQ,KAAa,CAAC,OAAO,KAAK,UAAU,CAAC,EAC/C,CAAC;QACD,0EAA0E;QAC1E,OAAO,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAE,KAAa,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;IACJ,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workflow/utils",
3
3
  "description": "Utility functions for Workflow DevKit",
4
- "version": "4.0.1-beta.7",
4
+ "version": "4.0.1-beta.8",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "files": [
@@ -24,6 +24,10 @@
24
24
  "./get-port": {
25
25
  "types": "./dist/get-port.d.ts",
26
26
  "default": "./dist/get-port.js"
27
+ },
28
+ "./check-data-dir": {
29
+ "types": "./dist/check-data-dir.d.ts",
30
+ "default": "./dist/check-data-dir.js"
27
31
  }
28
32
  },
29
33
  "devDependencies": {