@workflow/world-local 5.0.0-beta.10 → 5.0.0-beta.2
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/dist/config.d.ts +17 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +18 -13
- package/dist/config.js.map +1 -1
- package/dist/fs.d.ts +58 -2
- package/dist/fs.d.ts.map +1 -1
- package/dist/fs.js +203 -24
- package/dist/fs.js.map +1 -1
- package/dist/index.d.ts +15 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -5
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +91 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +268 -0
- package/dist/init.js.map +1 -0
- package/dist/instrumentObject.d.ts +8 -0
- package/dist/instrumentObject.d.ts.map +1 -0
- package/dist/instrumentObject.js +66 -0
- package/dist/instrumentObject.js.map +1 -0
- package/dist/queue.d.ts +8 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +164 -53
- package/dist/queue.js.map +1 -1
- package/dist/storage/events-storage.d.ts +7 -0
- package/dist/storage/events-storage.d.ts.map +1 -0
- package/dist/storage/events-storage.js +744 -0
- package/dist/storage/events-storage.js.map +1 -0
- package/dist/storage/filters.d.ts +22 -0
- package/dist/storage/filters.d.ts.map +1 -0
- package/dist/storage/filters.js +33 -0
- package/dist/storage/filters.js.map +1 -0
- package/dist/storage/helpers.d.ts +18 -0
- package/dist/storage/helpers.d.ts.map +1 -0
- package/dist/storage/helpers.js +44 -0
- package/dist/storage/helpers.js.map +1 -0
- package/dist/storage/hooks-storage.d.ts +12 -0
- package/dist/storage/hooks-storage.d.ts.map +1 -0
- package/dist/storage/hooks-storage.js +92 -0
- package/dist/storage/hooks-storage.js.map +1 -0
- package/dist/storage/index.d.ts +12 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +32 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/legacy.d.ts +13 -0
- package/dist/storage/legacy.d.ts.map +1 -0
- package/dist/storage/legacy.js +73 -0
- package/dist/storage/legacy.js.map +1 -0
- package/dist/storage/runs-storage.d.ts +7 -0
- package/dist/storage/runs-storage.d.ts.map +1 -0
- package/dist/storage/runs-storage.js +58 -0
- package/dist/storage/runs-storage.js.map +1 -0
- package/dist/storage/steps-storage.d.ts +7 -0
- package/dist/storage/steps-storage.d.ts.map +1 -0
- package/dist/storage/steps-storage.js +49 -0
- package/dist/storage/steps-storage.js.map +1 -0
- package/dist/storage.d.ts +9 -2
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +8 -455
- package/dist/storage.js.map +1 -1
- package/dist/streamer.d.ts +4 -2
- package/dist/streamer.d.ts.map +1 -1
- package/dist/streamer.js +451 -104
- package/dist/streamer.js.map +1 -1
- package/dist/telemetry.d.ts +28 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +71 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/test-helpers.d.ts +54 -0
- package/dist/test-helpers.d.ts.map +1 -0
- package/dist/test-helpers.js +118 -0
- package/dist/test-helpers.js.map +1 -0
- package/dist/util.js.map +1 -1
- package/package.json +12 -11
package/dist/config.d.ts
CHANGED
|
@@ -3,17 +3,29 @@ export type Config = {
|
|
|
3
3
|
dataDir: string;
|
|
4
4
|
port?: number;
|
|
5
5
|
baseUrl?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Optional tag to scope filesystem operations.
|
|
8
|
+
* When set, files are written as `{id}.{tag}.json` and `clear()` only deletes
|
|
9
|
+
* files matching this tag. Used by vitest to isolate test data in the shared
|
|
10
|
+
* `.workflow-data` directory.
|
|
11
|
+
*/
|
|
12
|
+
tag?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Override the flush interval (in ms) for buffered stream writes.
|
|
15
|
+
* Default is 10ms. Set to 0 for immediate flushing.
|
|
16
|
+
*/
|
|
17
|
+
streamFlushIntervalMs?: number;
|
|
6
18
|
};
|
|
7
19
|
export declare const config: {
|
|
8
20
|
readonly value: Config;
|
|
9
21
|
};
|
|
10
22
|
/**
|
|
11
23
|
* Resolves the base URL for queue requests following the priority order:
|
|
12
|
-
* 1. config.baseUrl (highest priority - full override from args
|
|
13
|
-
* 2.
|
|
14
|
-
* 3.
|
|
15
|
-
* 4. PORT env var (
|
|
16
|
-
* 5.
|
|
24
|
+
* 1. config.baseUrl (highest priority - full override from args)
|
|
25
|
+
* 2. WORKFLOW_LOCAL_BASE_URL env var (checked directly to handle late env var setting)
|
|
26
|
+
* 3. config.port (explicit port override from args)
|
|
27
|
+
* 4. PORT env var (explicit configuration)
|
|
28
|
+
* 5. Auto-detected port via getPort (detect actual listening port)
|
|
17
29
|
*/
|
|
18
30
|
export declare function resolveBaseUrl(config: Partial<Config>): Promise<string>;
|
|
19
31
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,2BAA2B,QAAQ,CAAC;AAMjD,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,2BAA2B,QAAQ,CAAC;AAMjD,MAAM,MAAM,MAAM,GAAG;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,MAAM;;CAKjB,CAAC;AAEH;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAyB7E"}
|
package/dist/config.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getWorkflowPort } from '@workflow/utils/get-port';
|
|
2
2
|
import { once } from './util.js';
|
|
3
3
|
const getDataDirFromEnv = () => {
|
|
4
|
-
return process.env.
|
|
4
|
+
return process.env.WORKFLOW_LOCAL_DATA_DIR || '.workflow-data';
|
|
5
5
|
};
|
|
6
6
|
export const DEFAULT_RESOLVE_DATA_OPTION = 'all';
|
|
7
7
|
const getBaseUrlFromEnv = () => {
|
|
8
|
-
return process.env.
|
|
8
|
+
return process.env.WORKFLOW_LOCAL_BASE_URL;
|
|
9
9
|
};
|
|
10
10
|
export const config = once(() => {
|
|
11
11
|
const dataDir = getDataDirFromEnv();
|
|
@@ -14,26 +14,31 @@ export const config = once(() => {
|
|
|
14
14
|
});
|
|
15
15
|
/**
|
|
16
16
|
* Resolves the base URL for queue requests following the priority order:
|
|
17
|
-
* 1. config.baseUrl (highest priority - full override from args
|
|
18
|
-
* 2.
|
|
19
|
-
* 3.
|
|
20
|
-
* 4. PORT env var (
|
|
21
|
-
* 5.
|
|
17
|
+
* 1. config.baseUrl (highest priority - full override from args)
|
|
18
|
+
* 2. WORKFLOW_LOCAL_BASE_URL env var (checked directly to handle late env var setting)
|
|
19
|
+
* 3. config.port (explicit port override from args)
|
|
20
|
+
* 4. PORT env var (explicit configuration)
|
|
21
|
+
* 5. Auto-detected port via getPort (detect actual listening port)
|
|
22
22
|
*/
|
|
23
23
|
export async function resolveBaseUrl(config) {
|
|
24
24
|
if (config.baseUrl) {
|
|
25
25
|
return config.baseUrl;
|
|
26
26
|
}
|
|
27
|
+
// Check env var directly in case it was set after the config was cached
|
|
28
|
+
// This is important for CLI tools that set the env var after module import
|
|
29
|
+
if (process.env.WORKFLOW_LOCAL_BASE_URL) {
|
|
30
|
+
return process.env.WORKFLOW_LOCAL_BASE_URL;
|
|
31
|
+
}
|
|
27
32
|
if (typeof config.port === 'number') {
|
|
28
33
|
return `http://localhost:${config.port}`;
|
|
29
34
|
}
|
|
30
|
-
const detectedPort = await getPort();
|
|
31
|
-
if (detectedPort) {
|
|
32
|
-
return `http://localhost:${detectedPort}`;
|
|
33
|
-
}
|
|
34
35
|
if (process.env.PORT) {
|
|
35
36
|
return `http://localhost:${process.env.PORT}`;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
const detectedPort = await getWorkflowPort();
|
|
39
|
+
if (detectedPort) {
|
|
40
|
+
return `http://localhost:${detectedPort}`;
|
|
41
|
+
}
|
|
42
|
+
throw new Error('Unable to resolve base URL for workflow queue.');
|
|
38
43
|
}
|
|
39
44
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,gBAAgB,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEjD,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;AAC7C,CAAC,CAAC;AAoBF,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAS,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IAEpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9B,CAAC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAuB;IAC1D,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,wEAAwE;IACxE,2EAA2E;IAC3E,IAAI,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC;QACxC,OAAO,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IAC7C,CAAC;IAED,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,oBAAoB,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3C,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACrB,OAAO,oBAAoB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,eAAe,EAAE,CAAC;IAC7C,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,oBAAoB,YAAY,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { getWorkflowPort } from '@workflow/utils/get-port';\nimport { once } from './util.js';\n\nconst getDataDirFromEnv = () => {\n return process.env.WORKFLOW_LOCAL_DATA_DIR || '.workflow-data';\n};\n\nexport const DEFAULT_RESOLVE_DATA_OPTION = 'all';\n\nconst getBaseUrlFromEnv = () => {\n return process.env.WORKFLOW_LOCAL_BASE_URL;\n};\n\nexport type Config = {\n dataDir: string;\n port?: number;\n baseUrl?: string;\n /**\n * Optional tag to scope filesystem operations.\n * When set, files are written as `{id}.{tag}.json` and `clear()` only deletes\n * files matching this tag. Used by vitest to isolate test data in the shared\n * `.workflow-data` directory.\n */\n tag?: string;\n /**\n * Override the flush interval (in ms) for buffered stream writes.\n * Default is 10ms. Set to 0 for immediate flushing.\n */\n streamFlushIntervalMs?: number;\n};\n\nexport const config = once<Config>(() => {\n const dataDir = getDataDirFromEnv();\n const baseUrl = getBaseUrlFromEnv();\n\n return { dataDir, baseUrl };\n});\n\n/**\n * Resolves the base URL for queue requests following the priority order:\n * 1. config.baseUrl (highest priority - full override from args)\n * 2. WORKFLOW_LOCAL_BASE_URL env var (checked directly to handle late env var setting)\n * 3. config.port (explicit port override from args)\n * 4. PORT env var (explicit configuration)\n * 5. Auto-detected port via getPort (detect actual listening port)\n */\nexport async function resolveBaseUrl(config: Partial<Config>): Promise<string> {\n if (config.baseUrl) {\n return config.baseUrl;\n }\n\n // Check env var directly in case it was set after the config was cached\n // This is important for CLI tools that set the env var after module import\n if (process.env.WORKFLOW_LOCAL_BASE_URL) {\n return process.env.WORKFLOW_LOCAL_BASE_URL;\n }\n\n if (typeof config.port === 'number') {\n return `http://localhost:${config.port}`;\n }\n\n if (process.env.PORT) {\n return `http://localhost:${process.env.PORT}`;\n }\n\n const detectedPort = await getWorkflowPort();\n if (detectedPort) {\n return `http://localhost:${detectedPort}`;\n }\n\n throw new Error('Unable to resolve base URL for workflow queue.');\n}\n"]}
|
package/dist/fs.d.ts
CHANGED
|
@@ -1,16 +1,73 @@
|
|
|
1
1
|
import type { PaginatedResponse } from '@workflow/world';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Clear the created files cache. Useful for testing or when files are deleted externally.
|
|
5
|
+
*/
|
|
6
|
+
export declare function clearCreatedFilesCache(): void;
|
|
7
|
+
export { ulidToDate } from '@workflow/world';
|
|
8
|
+
/**
|
|
9
|
+
* Strip a tag suffix from a fileId.
|
|
10
|
+
* `wrun_ABC.vitest-0` → `wrun_ABC`
|
|
11
|
+
* `wrun_ABC` → `wrun_ABC` (no-op if no tag)
|
|
12
|
+
*/
|
|
13
|
+
export declare function stripTag(fileId: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Build the file path for an entity, with optional tag embedded in the filename.
|
|
16
|
+
* `taggedPath('runs', 'wrun_ABC', 'vitest-0')` → `runs/wrun_ABC.vitest-0.json`
|
|
17
|
+
* `taggedPath('runs', 'wrun_ABC')` → `runs/wrun_ABC.json`
|
|
18
|
+
*/
|
|
19
|
+
export declare function taggedPath(basedir: string, entityDir: string, fileId: string, tag?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Read a JSON entity with tagged fallback.
|
|
22
|
+
* When a tag is set, tries the tagged path first, then falls back to the
|
|
23
|
+
* untagged path (so a tagged world can read entities written without a tag).
|
|
24
|
+
*/
|
|
25
|
+
export declare function readJSONWithFallback<T>(basedir: string, entityDir: string, fileId: string, schema: z.ZodType<T>, tag?: string): Promise<T | null>;
|
|
26
|
+
/**
|
|
27
|
+
* List all filenames in a directory that have a specific tag.
|
|
28
|
+
* Returns full filenames (e.g., `wrun_ABC.vitest-0.json`).
|
|
29
|
+
*/
|
|
30
|
+
export declare function listTaggedFiles(dirPath: string, tag: string): Promise<string[]>;
|
|
31
|
+
/**
|
|
32
|
+
* List all filenames in a directory that have a specific tag and extension.
|
|
33
|
+
* Returns full filenames (e.g., `stream-chnk_ABC.vitest-0.bin`).
|
|
34
|
+
*/
|
|
35
|
+
export declare function listTaggedFilesByExtension(dirPath: string, tag: string, extension: string): Promise<string[]>;
|
|
4
36
|
export declare function ensureDir(dirPath: string): Promise<void>;
|
|
5
37
|
interface WriteOptions {
|
|
6
38
|
overwrite?: boolean;
|
|
7
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Custom JSON replacer that encodes Uint8Array as base64 strings.
|
|
42
|
+
* Format: { __type: 'Uint8Array', data: '<base64>' }
|
|
43
|
+
*/
|
|
44
|
+
export declare function jsonReplacer(_key: string, value: unknown): unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Custom JSON reviver that decodes base64 strings back to Uint8Array.
|
|
47
|
+
*/
|
|
48
|
+
export declare function jsonReviver(_key: string, value: unknown): unknown;
|
|
8
49
|
export declare function writeJSON(filePath: string, data: any, opts?: WriteOptions): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Writes data to a file using atomic write-rename pattern.
|
|
52
|
+
*
|
|
53
|
+
* Note: While this function uses temp files to avoid partial writes,
|
|
54
|
+
* it does not provide protection against concurrent writes from multiple
|
|
55
|
+
* processes. In a multi-writer scenario, the last writer wins.
|
|
56
|
+
* For production use with multiple writers, consider using a proper
|
|
57
|
+
* database or locking mechanism.
|
|
58
|
+
*/
|
|
9
59
|
export declare function write(filePath: string, data: string | Buffer, opts?: WriteOptions): Promise<void>;
|
|
10
60
|
export declare function readJSON<T>(filePath: string, decoder: z.ZodType<T>): Promise<T | null>;
|
|
11
61
|
export declare function readBuffer(filePath: string): Promise<Buffer>;
|
|
12
62
|
export declare function deleteJSON(filePath: string): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Atomically create a file using O_CREAT | O_EXCL flags.
|
|
65
|
+
* Returns true if the file was created, false if it already exists.
|
|
66
|
+
* This is atomic at the OS level, safe for concurrent access.
|
|
67
|
+
*/
|
|
68
|
+
export declare function writeExclusive(filePath: string, data: string): Promise<boolean>;
|
|
13
69
|
export declare function listJSONFiles(dirPath: string): Promise<string[]>;
|
|
70
|
+
export declare function listFilesByExtension(dirPath: string, extension: string): Promise<string[]>;
|
|
14
71
|
interface PaginatedFileSystemQueryConfig<T> {
|
|
15
72
|
directory: string;
|
|
16
73
|
schema: z.ZodType<T>;
|
|
@@ -25,5 +82,4 @@ interface PaginatedFileSystemQueryConfig<T> {
|
|
|
25
82
|
export declare function paginatedFileSystemQuery<T extends {
|
|
26
83
|
createdAt: Date;
|
|
27
84
|
}>(config: PaginatedFileSystemQueryConfig<T>): Promise<PaginatedResponse<T>>;
|
|
28
|
-
export {};
|
|
29
85
|
//# sourceMappingURL=fs.d.ts.map
|
package/dist/fs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAyCxB;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAW7C;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CAGR;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,CAAC,EAC1C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CASnB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,EAAE,CAAC,CASnB;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,EAAE,CAAC,CAS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,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,EAAE,CAAC,CAUnB;AAED,UAAU,8BAA8B,CAAC,CAAC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;IAC9B,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;CACzB;AAqBD,wBAAsB,wBAAwB,CAAC,CAAC,SAAS;IAAE,SAAS,EAAE,IAAI,CAAA;CAAE,EAC1E,MAAM,EAAE,8BAA8B,CAAC,CAAC,CAAC,GACxC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CA+I/B"}
|
package/dist/fs.js
CHANGED
|
@@ -1,16 +1,116 @@
|
|
|
1
1
|
import { promises as fs } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { EntityConflictError } from '@workflow/errors';
|
|
4
|
+
import { monotonicFactory } from 'ulid';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
const ulid = monotonicFactory(() => Math.random());
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const isWindows = process.platform === 'win32';
|
|
8
|
+
/**
|
|
9
|
+
* Execute a filesystem operation with retry logic on Windows.
|
|
10
|
+
* On Windows, file operations can fail with EPERM/EBUSY/EACCES when files
|
|
11
|
+
* are briefly locked by another process or antivirus. This wrapper adds
|
|
12
|
+
* exponential backoff retry logic. On non-Windows platforms, executes directly.
|
|
13
|
+
*/
|
|
14
|
+
async function withWindowsRetry(fn, maxRetries = 5) {
|
|
15
|
+
if (!isWindows)
|
|
16
|
+
return fn();
|
|
17
|
+
const retryableErrors = ['EPERM', 'EBUSY', 'EACCES'];
|
|
18
|
+
const baseDelayMs = 10;
|
|
19
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
20
|
+
try {
|
|
21
|
+
return await fn();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const isRetryable = attempt < maxRetries && retryableErrors.includes(error.code);
|
|
25
|
+
if (!isRetryable)
|
|
26
|
+
throw error;
|
|
27
|
+
// Exponential backoff with jitter
|
|
28
|
+
const delay = baseDelayMs * 2 ** attempt + Math.random() * baseDelayMs;
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// TypeScript: unreachable, but satisfies return type
|
|
33
|
+
throw new Error('Retry loop exited unexpectedly');
|
|
34
|
+
}
|
|
35
|
+
// In-memory cache of created files to avoid expensive fs.access() calls
|
|
36
|
+
// This is safe because we only write once per file path (no overwrites without explicit flag)
|
|
37
|
+
const createdFilesCache = new Set();
|
|
38
|
+
/**
|
|
39
|
+
* Clear the created files cache. Useful for testing or when files are deleted externally.
|
|
40
|
+
*/
|
|
41
|
+
export function clearCreatedFilesCache() {
|
|
42
|
+
createdFilesCache.clear();
|
|
43
|
+
}
|
|
44
|
+
export { ulidToDate } from '@workflow/world';
|
|
45
|
+
/**
|
|
46
|
+
* Regex matching a tag suffix on a fileId (after `.json` has been stripped).
|
|
47
|
+
* E.g., `wrun_ABC.vitest-0` → the `.vitest-0` part.
|
|
48
|
+
* Tags start with a letter and contain alphanumeric chars and hyphens.
|
|
49
|
+
* Entity IDs (ULIDs, step_N, etc.) never contain dots, so the first dot
|
|
50
|
+
* always marks the tag boundary.
|
|
51
|
+
*/
|
|
52
|
+
const TAG_PATTERN = /\.[a-zA-Z][a-zA-Z0-9-]*$/;
|
|
53
|
+
/**
|
|
54
|
+
* Strip a tag suffix from a fileId.
|
|
55
|
+
* `wrun_ABC.vitest-0` → `wrun_ABC`
|
|
56
|
+
* `wrun_ABC` → `wrun_ABC` (no-op if no tag)
|
|
57
|
+
*/
|
|
58
|
+
export function stripTag(fileId) {
|
|
59
|
+
return fileId.replace(TAG_PATTERN, '');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Build the file path for an entity, with optional tag embedded in the filename.
|
|
63
|
+
* `taggedPath('runs', 'wrun_ABC', 'vitest-0')` → `runs/wrun_ABC.vitest-0.json`
|
|
64
|
+
* `taggedPath('runs', 'wrun_ABC')` → `runs/wrun_ABC.json`
|
|
65
|
+
*/
|
|
66
|
+
export function taggedPath(basedir, entityDir, fileId, tag) {
|
|
67
|
+
const filename = tag ? `${fileId}.${tag}.json` : `${fileId}.json`;
|
|
68
|
+
return path.join(basedir, entityDir, filename);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Read a JSON entity with tagged fallback.
|
|
72
|
+
* When a tag is set, tries the tagged path first, then falls back to the
|
|
73
|
+
* untagged path (so a tagged world can read entities written without a tag).
|
|
74
|
+
*/
|
|
75
|
+
export async function readJSONWithFallback(basedir, entityDir, fileId, schema, tag) {
|
|
76
|
+
if (tag) {
|
|
77
|
+
const result = await readJSON(path.join(basedir, entityDir, `${fileId}.${tag}.json`), schema);
|
|
78
|
+
if (result !== null)
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
return readJSON(path.join(basedir, entityDir, `${fileId}.json`), schema);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* List all filenames in a directory that have a specific tag.
|
|
85
|
+
* Returns full filenames (e.g., `wrun_ABC.vitest-0.json`).
|
|
86
|
+
*/
|
|
87
|
+
export async function listTaggedFiles(dirPath, tag) {
|
|
88
|
+
const suffix = `.${tag}.json`;
|
|
89
|
+
try {
|
|
90
|
+
const files = await fs.readdir(dirPath);
|
|
91
|
+
return files.filter((f) => f.endsWith(suffix));
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error.code === 'ENOENT')
|
|
95
|
+
return [];
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* List all filenames in a directory that have a specific tag and extension.
|
|
101
|
+
* Returns full filenames (e.g., `stream-chnk_ABC.vitest-0.bin`).
|
|
102
|
+
*/
|
|
103
|
+
export async function listTaggedFilesByExtension(dirPath, tag, extension) {
|
|
104
|
+
const suffix = `.${tag}${extension}`;
|
|
105
|
+
try {
|
|
106
|
+
const files = await fs.readdir(dirPath);
|
|
107
|
+
return files.filter((f) => f.endsWith(suffix));
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error.code === 'ENOENT')
|
|
111
|
+
return [];
|
|
112
|
+
throw error;
|
|
12
113
|
}
|
|
13
|
-
return new Date(decodeTime(ulid.data));
|
|
14
114
|
}
|
|
15
115
|
export async function ensureDir(dirPath) {
|
|
16
116
|
try {
|
|
@@ -20,14 +120,56 @@ export async function ensureDir(dirPath) {
|
|
|
20
120
|
// Ignore if already exists
|
|
21
121
|
}
|
|
22
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Custom JSON replacer that encodes Uint8Array as base64 strings.
|
|
125
|
+
* Format: { __type: 'Uint8Array', data: '<base64>' }
|
|
126
|
+
*/
|
|
127
|
+
export function jsonReplacer(_key, value) {
|
|
128
|
+
if (value instanceof Uint8Array) {
|
|
129
|
+
return {
|
|
130
|
+
__type: 'Uint8Array',
|
|
131
|
+
data: Buffer.from(value).toString('base64'),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Custom JSON reviver that decodes base64 strings back to Uint8Array.
|
|
138
|
+
*/
|
|
139
|
+
export function jsonReviver(_key, value) {
|
|
140
|
+
if (value !== null &&
|
|
141
|
+
typeof value === 'object' &&
|
|
142
|
+
value.__type === 'Uint8Array' &&
|
|
143
|
+
typeof value.data === 'string') {
|
|
144
|
+
return new Uint8Array(Buffer.from(value.data, 'base64'));
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
23
148
|
export async function writeJSON(filePath, data, opts) {
|
|
24
|
-
return write(filePath, JSON.stringify(data,
|
|
149
|
+
return write(filePath, JSON.stringify(data, jsonReplacer, 2), opts);
|
|
25
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Writes data to a file using atomic write-rename pattern.
|
|
153
|
+
*
|
|
154
|
+
* Note: While this function uses temp files to avoid partial writes,
|
|
155
|
+
* it does not provide protection against concurrent writes from multiple
|
|
156
|
+
* processes. In a multi-writer scenario, the last writer wins.
|
|
157
|
+
* For production use with multiple writers, consider using a proper
|
|
158
|
+
* database or locking mechanism.
|
|
159
|
+
*/
|
|
26
160
|
export async function write(filePath, data, opts) {
|
|
27
161
|
if (!opts?.overwrite) {
|
|
162
|
+
// Fast path: check in-memory cache first to avoid expensive fs.access() calls
|
|
163
|
+
// This provides significant performance improvement when creating many files
|
|
164
|
+
if (createdFilesCache.has(filePath)) {
|
|
165
|
+
throw new EntityConflictError(`File ${filePath} already exists and 'overwrite' is false`);
|
|
166
|
+
}
|
|
167
|
+
// Slow path: check filesystem for files created before this process started
|
|
28
168
|
try {
|
|
29
169
|
await fs.access(filePath);
|
|
30
|
-
|
|
170
|
+
// File exists on disk, add to cache for future checks
|
|
171
|
+
createdFilesCache.add(filePath);
|
|
172
|
+
throw new EntityConflictError(`File ${filePath} already exists and 'overwrite' is false`);
|
|
31
173
|
}
|
|
32
174
|
catch (error) {
|
|
33
175
|
// If file doesn't exist (ENOENT), continue with write
|
|
@@ -37,20 +179,27 @@ export async function write(filePath, data, opts) {
|
|
|
37
179
|
}
|
|
38
180
|
}
|
|
39
181
|
const tempPath = `${filePath}.tmp.${ulid()}`;
|
|
182
|
+
let tempFileCreated = false;
|
|
40
183
|
try {
|
|
41
184
|
await ensureDir(path.dirname(filePath));
|
|
42
185
|
await fs.writeFile(tempPath, data);
|
|
43
|
-
|
|
186
|
+
tempFileCreated = true;
|
|
187
|
+
await withWindowsRetry(() => fs.rename(tempPath, filePath));
|
|
188
|
+
// Track this file in cache so future writes know it exists
|
|
189
|
+
createdFilesCache.add(filePath);
|
|
44
190
|
}
|
|
45
191
|
catch (error) {
|
|
46
|
-
|
|
192
|
+
// Only try to clean up temp file if it was actually created
|
|
193
|
+
if (tempFileCreated) {
|
|
194
|
+
await withWindowsRetry(() => fs.unlink(tempPath), 3).catch(() => { });
|
|
195
|
+
}
|
|
47
196
|
throw error;
|
|
48
197
|
}
|
|
49
198
|
}
|
|
50
199
|
export async function readJSON(filePath, decoder) {
|
|
51
200
|
try {
|
|
52
201
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
53
|
-
return decoder.parse(JSON.parse(content));
|
|
202
|
+
return decoder.parse(JSON.parse(content, jsonReviver));
|
|
54
203
|
}
|
|
55
204
|
catch (error) {
|
|
56
205
|
if (error.code === 'ENOENT')
|
|
@@ -71,12 +220,33 @@ export async function deleteJSON(filePath) {
|
|
|
71
220
|
throw error;
|
|
72
221
|
}
|
|
73
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Atomically create a file using O_CREAT | O_EXCL flags.
|
|
225
|
+
* Returns true if the file was created, false if it already exists.
|
|
226
|
+
* This is atomic at the OS level, safe for concurrent access.
|
|
227
|
+
*/
|
|
228
|
+
export async function writeExclusive(filePath, data) {
|
|
229
|
+
await ensureDir(path.dirname(filePath));
|
|
230
|
+
try {
|
|
231
|
+
await fs.writeFile(filePath, data, { flag: 'wx' });
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
if (error.code === 'EEXIST') {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
74
241
|
export async function listJSONFiles(dirPath) {
|
|
242
|
+
return listFilesByExtension(dirPath, '.json');
|
|
243
|
+
}
|
|
244
|
+
export async function listFilesByExtension(dirPath, extension) {
|
|
75
245
|
try {
|
|
76
246
|
const files = await fs.readdir(dirPath);
|
|
77
247
|
return files
|
|
78
|
-
.filter((f) => f.endsWith(
|
|
79
|
-
.map((f) => f.
|
|
248
|
+
.filter((f) => f.endsWith(extension))
|
|
249
|
+
.map((f) => f.slice(0, -extension.length));
|
|
80
250
|
}
|
|
81
251
|
catch (error) {
|
|
82
252
|
if (error.code === 'ENOENT')
|
|
@@ -130,21 +300,30 @@ export async function paginatedFileSystemQuery(config) {
|
|
|
130
300
|
: fileTime > cursorTime;
|
|
131
301
|
}
|
|
132
302
|
}
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
// Even without cursor, skip files where getCreatedAt returns null for consistency
|
|
139
|
-
candidateFileIds = relevantFileIds.filter((fileId) => {
|
|
140
|
-
return getCreatedAt(`${fileId}.json`) !== null;
|
|
303
|
+
// Can't extract timestamp from filename (e.g., steps use sequential IDs).
|
|
304
|
+
// Include the file and defer to JSON-based filtering below.
|
|
305
|
+
return true;
|
|
141
306
|
});
|
|
142
307
|
}
|
|
143
308
|
// 4. Load files individually and collect valid items
|
|
144
309
|
const validItems = [];
|
|
145
310
|
for (const fileId of candidateFileIds) {
|
|
146
311
|
const filePath = path.join(directory, `${fileId}.json`);
|
|
147
|
-
|
|
312
|
+
let item = null;
|
|
313
|
+
try {
|
|
314
|
+
item = await readJSON(filePath, schema);
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
// We don't expect zod errors to happen, but if the JSON does get malformed,
|
|
318
|
+
// we skip the item. Preferably, we'd have a way to mark items as malformed,
|
|
319
|
+
// so that the UI can display them as such, with richer messaging. In the meantime,
|
|
320
|
+
// we just log a warning and skip the item.
|
|
321
|
+
if (error instanceof z.ZodError) {
|
|
322
|
+
console.warn(`Skipping item ${fileId} due to malformed JSON: ${error.message}`);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
148
327
|
if (item) {
|
|
149
328
|
// Apply custom filter early if provided
|
|
150
329
|
if (filter && !filter(item))
|
package/dist/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAEnD,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;AAE/B,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACvC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAe;IAC7C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,2BA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C,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAChE,MAAM,UAAU,GACd,KAAK,CAAC,MAAM,GAAG,CAAC;QACd,CAAC,CAAC,YAAY,CACV,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,SAAS,EACjC,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CACjC;QACH,CAAC,CAAC,IAAI,CAAC;IAEX,OAAO;QACL,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,UAAU;QAClB,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import { promises as fs } from 'node:fs';\nimport path from 'node:path';\nimport { EntityConflictError } from '@workflow/errors';\nimport type { PaginatedResponse } from '@workflow/world';\nimport { monotonicFactory } from 'ulid';\nimport { z } from 'zod';\n\nconst ulid = monotonicFactory(() => Math.random());\n\nconst isWindows = process.platform === 'win32';\n\n/**\n * Execute a filesystem operation with retry logic on Windows.\n * On Windows, file operations can fail with EPERM/EBUSY/EACCES when files\n * are briefly locked by another process or antivirus. This wrapper adds\n * exponential backoff retry logic. On non-Windows platforms, executes directly.\n */\nasync function withWindowsRetry<T>(\n fn: () => Promise<T>,\n maxRetries = 5\n): Promise<T> {\n if (!isWindows) return fn();\n\n const retryableErrors = ['EPERM', 'EBUSY', 'EACCES'];\n const baseDelayMs = 10;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error: any) {\n const isRetryable =\n attempt < maxRetries && retryableErrors.includes(error.code);\n if (!isRetryable) throw error;\n // Exponential backoff with jitter\n const delay = baseDelayMs * 2 ** attempt + Math.random() * baseDelayMs;\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n // TypeScript: unreachable, but satisfies return type\n throw new Error('Retry loop exited unexpectedly');\n}\n\n// In-memory cache of created files to avoid expensive fs.access() calls\n// This is safe because we only write once per file path (no overwrites without explicit flag)\nconst createdFilesCache = new Set<string>();\n\n/**\n * Clear the created files cache. Useful for testing or when files are deleted externally.\n */\nexport function clearCreatedFilesCache(): void {\n createdFilesCache.clear();\n}\n\nexport { ulidToDate } from '@workflow/world';\n\n/**\n * Regex matching a tag suffix on a fileId (after `.json` has been stripped).\n * E.g., `wrun_ABC.vitest-0` → the `.vitest-0` part.\n * Tags start with a letter and contain alphanumeric chars and hyphens.\n * Entity IDs (ULIDs, step_N, etc.) never contain dots, so the first dot\n * always marks the tag boundary.\n */\nconst TAG_PATTERN = /\\.[a-zA-Z][a-zA-Z0-9-]*$/;\n\n/**\n * Strip a tag suffix from a fileId.\n * `wrun_ABC.vitest-0` → `wrun_ABC`\n * `wrun_ABC` → `wrun_ABC` (no-op if no tag)\n */\nexport function stripTag(fileId: string): string {\n return fileId.replace(TAG_PATTERN, '');\n}\n\n/**\n * Build the file path for an entity, with optional tag embedded in the filename.\n * `taggedPath('runs', 'wrun_ABC', 'vitest-0')` → `runs/wrun_ABC.vitest-0.json`\n * `taggedPath('runs', 'wrun_ABC')` → `runs/wrun_ABC.json`\n */\nexport function taggedPath(\n basedir: string,\n entityDir: string,\n fileId: string,\n tag?: string\n): string {\n const filename = tag ? `${fileId}.${tag}.json` : `${fileId}.json`;\n return path.join(basedir, entityDir, filename);\n}\n\n/**\n * Read a JSON entity with tagged fallback.\n * When a tag is set, tries the tagged path first, then falls back to the\n * untagged path (so a tagged world can read entities written without a tag).\n */\nexport async function readJSONWithFallback<T>(\n basedir: string,\n entityDir: string,\n fileId: string,\n schema: z.ZodType<T>,\n tag?: string\n): Promise<T | null> {\n if (tag) {\n const result = await readJSON(\n path.join(basedir, entityDir, `${fileId}.${tag}.json`),\n schema\n );\n if (result !== null) return result;\n }\n return readJSON(path.join(basedir, entityDir, `${fileId}.json`), schema);\n}\n\n/**\n * List all filenames in a directory that have a specific tag.\n * Returns full filenames (e.g., `wrun_ABC.vitest-0.json`).\n */\nexport async function listTaggedFiles(\n dirPath: string,\n tag: string\n): Promise<string[]> {\n const suffix = `.${tag}.json`;\n try {\n const files = await fs.readdir(dirPath);\n return files.filter((f) => f.endsWith(suffix));\n } catch (error) {\n if ((error as any).code === 'ENOENT') return [];\n throw error;\n }\n}\n\n/**\n * List all filenames in a directory that have a specific tag and extension.\n * Returns full filenames (e.g., `stream-chnk_ABC.vitest-0.bin`).\n */\nexport async function listTaggedFilesByExtension(\n dirPath: string,\n tag: string,\n extension: string\n): Promise<string[]> {\n const suffix = `.${tag}${extension}`;\n try {\n const files = await fs.readdir(dirPath);\n return files.filter((f) => f.endsWith(suffix));\n } catch (error) {\n if ((error as any).code === 'ENOENT') return [];\n throw error;\n }\n}\n\nexport async function ensureDir(dirPath: string): Promise<void> {\n try {\n await fs.mkdir(dirPath, { recursive: true });\n } catch (_error) {\n // Ignore if already exists\n }\n}\n\ninterface WriteOptions {\n overwrite?: boolean;\n}\n\n/**\n * Custom JSON replacer that encodes Uint8Array as base64 strings.\n * Format: { __type: 'Uint8Array', data: '<base64>' }\n */\nexport function jsonReplacer(_key: string, value: unknown): unknown {\n if (value instanceof Uint8Array) {\n return {\n __type: 'Uint8Array',\n data: Buffer.from(value).toString('base64'),\n };\n }\n return value;\n}\n\n/**\n * Custom JSON reviver that decodes base64 strings back to Uint8Array.\n */\nexport function jsonReviver(_key: string, value: unknown): unknown {\n if (\n value !== null &&\n typeof value === 'object' &&\n (value as any).__type === 'Uint8Array' &&\n typeof (value as any).data === 'string'\n ) {\n return new Uint8Array(Buffer.from((value as any).data, 'base64'));\n }\n return value;\n}\n\nexport async function writeJSON(\n filePath: string,\n data: any,\n opts?: WriteOptions\n): Promise<void> {\n return write(filePath, JSON.stringify(data, jsonReplacer, 2), opts);\n}\n\n/**\n * Writes data to a file using atomic write-rename pattern.\n *\n * Note: While this function uses temp files to avoid partial writes,\n * it does not provide protection against concurrent writes from multiple\n * processes. In a multi-writer scenario, the last writer wins.\n * For production use with multiple writers, consider using a proper\n * database or locking mechanism.\n */\nexport async function write(\n filePath: string,\n data: string | Buffer,\n opts?: WriteOptions\n): Promise<void> {\n if (!opts?.overwrite) {\n // Fast path: check in-memory cache first to avoid expensive fs.access() calls\n // This provides significant performance improvement when creating many files\n if (createdFilesCache.has(filePath)) {\n throw new EntityConflictError(\n `File ${filePath} already exists and 'overwrite' is false`\n );\n }\n\n // Slow path: check filesystem for files created before this process started\n try {\n await fs.access(filePath);\n // File exists on disk, add to cache for future checks\n createdFilesCache.add(filePath);\n throw new EntityConflictError(\n `File ${filePath} already exists and 'overwrite' is false`\n );\n } catch (error: any) {\n // If file doesn't exist (ENOENT), continue with write\n if (error.code !== 'ENOENT') {\n throw error;\n }\n }\n }\n\n const tempPath = `${filePath}.tmp.${ulid()}`;\n let tempFileCreated = false;\n try {\n await ensureDir(path.dirname(filePath));\n await fs.writeFile(tempPath, data);\n tempFileCreated = true;\n await withWindowsRetry(() => fs.rename(tempPath, filePath));\n // Track this file in cache so future writes know it exists\n createdFilesCache.add(filePath);\n } catch (error) {\n // Only try to clean up temp file if it was actually created\n if (tempFileCreated) {\n await withWindowsRetry(() => fs.unlink(tempPath), 3).catch(() => {});\n }\n throw error;\n }\n}\n\nexport async function readJSON<T>(\n filePath: string,\n decoder: z.ZodType<T>\n): Promise<T | null> {\n try {\n const content = await fs.readFile(filePath, 'utf-8');\n return decoder.parse(JSON.parse(content, jsonReviver));\n } catch (error) {\n if ((error as any).code === 'ENOENT') return null;\n throw error;\n }\n}\n\nexport async function readBuffer(filePath: string): Promise<Buffer> {\n const content = await fs.readFile(filePath);\n return content;\n}\n\nexport async function deleteJSON(filePath: string): Promise<void> {\n try {\n await fs.unlink(filePath);\n } catch (error) {\n if ((error as any).code !== 'ENOENT') throw error;\n }\n}\n\n/**\n * Atomically create a file using O_CREAT | O_EXCL flags.\n * Returns true if the file was created, false if it already exists.\n * This is atomic at the OS level, safe for concurrent access.\n */\nexport async function writeExclusive(\n filePath: string,\n data: string\n): Promise<boolean> {\n await ensureDir(path.dirname(filePath));\n try {\n await fs.writeFile(filePath, data, { flag: 'wx' });\n return true;\n } catch (error: any) {\n if (error.code === 'EEXIST') {\n return false;\n }\n throw error;\n }\n}\n\nexport async function listJSONFiles(dirPath: string): Promise<string[]> {\n return listFilesByExtension(dirPath, '.json');\n}\n\nexport async function listFilesByExtension(\n dirPath: string,\n extension: string\n): Promise<string[]> {\n try {\n const files = await fs.readdir(dirPath);\n return files\n .filter((f) => f.endsWith(extension))\n .map((f) => f.slice(0, -extension.length));\n } catch (error) {\n if ((error as any).code === 'ENOENT') return [];\n throw error;\n }\n}\n\ninterface PaginatedFileSystemQueryConfig<T> {\n directory: string;\n schema: z.ZodType<T>;\n filePrefix?: string;\n filter?: (item: T) => boolean;\n sortOrder?: 'asc' | 'desc';\n limit?: number;\n cursor?: string;\n getCreatedAt(filename: string): Date | null;\n getId?(item: T): string;\n}\n// Cursor format: \"timestamp|id\" for tie-breaking\ninterface ParsedCursor {\n timestamp: Date;\n id: string | null;\n}\n\nfunction parseCursor(cursor: string | undefined): ParsedCursor | null {\n if (!cursor) return null;\n\n const parts = cursor.split('|');\n return {\n timestamp: new Date(parts[0]),\n id: parts[1] || null,\n };\n}\n\nfunction createCursor(timestamp: Date, id: string | undefined): string {\n return id ? `${timestamp.toISOString()}|${id}` : timestamp.toISOString();\n}\n\nexport async function paginatedFileSystemQuery<T extends { createdAt: Date }>(\n config: PaginatedFileSystemQueryConfig<T>\n): Promise<PaginatedResponse<T>> {\n const {\n directory,\n schema,\n filePrefix,\n filter,\n sortOrder = 'desc',\n limit = 20,\n cursor,\n getCreatedAt,\n getId,\n } = config;\n\n // 1. Get all JSON files in directory\n const fileIds = await listJSONFiles(directory);\n\n // 2. Filter by prefix if provided\n const relevantFileIds = filePrefix\n ? fileIds.filter((fileId) => fileId.startsWith(filePrefix))\n : fileIds;\n\n // 3. ULID Optimization: Filter by cursor using filename timestamps before loading JSON\n const parsedCursor = parseCursor(cursor);\n let candidateFileIds = relevantFileIds;\n\n if (parsedCursor) {\n candidateFileIds = relevantFileIds.filter((fileId) => {\n const filenameDate = getCreatedAt(`${fileId}.json`);\n if (filenameDate) {\n // Use filename timestamp for cursor filtering\n // We need to be careful here: if parsedCursor has an ID (for tie-breaking),\n // we need to include items with the same timestamp for later ID-based filtering.\n // If no ID, we can use strict inequality for optimization.\n const cursorTime = parsedCursor.timestamp.getTime();\n const fileTime = filenameDate.getTime();\n\n if (parsedCursor.id) {\n // Tie-breaking mode: include items at or near cursor timestamp\n return sortOrder === 'desc'\n ? fileTime <= cursorTime\n : fileTime >= cursorTime;\n } else {\n // No tie-breaking: strict inequality\n return sortOrder === 'desc'\n ? fileTime < cursorTime\n : fileTime > cursorTime;\n }\n }\n // Can't extract timestamp from filename (e.g., steps use sequential IDs).\n // Include the file and defer to JSON-based filtering below.\n return true;\n });\n }\n\n // 4. Load files individually and collect valid items\n const validItems: T[] = [];\n\n for (const fileId of candidateFileIds) {\n const filePath = path.join(directory, `${fileId}.json`);\n let item: T | null = null;\n try {\n item = await readJSON(filePath, schema);\n } catch (error: unknown) {\n // We don't expect zod errors to happen, but if the JSON does get malformed,\n // we skip the item. Preferably, we'd have a way to mark items as malformed,\n // so that the UI can display them as such, with richer messaging. In the meantime,\n // we just log a warning and skip the item.\n if (error instanceof z.ZodError) {\n console.warn(\n `Skipping item ${fileId} due to malformed JSON: ${error.message}`\n );\n continue;\n }\n throw error;\n }\n\n if (item) {\n // Apply custom filter early if provided\n if (filter && !filter(item)) continue;\n\n // Double-check cursor filtering with actual createdAt from JSON\n // (in case ULID timestamp differs from stored createdAt)\n if (parsedCursor) {\n const itemTime = item.createdAt.getTime();\n const cursorTime = parsedCursor.timestamp.getTime();\n\n if (sortOrder === 'desc') {\n // For descending order, skip items >= cursor\n if (itemTime > cursorTime) continue;\n // If timestamps are equal, use ID for tie-breaking (skip if ID >= cursorId)\n if (itemTime === cursorTime && parsedCursor.id && getId) {\n const itemId = getId(item);\n if (itemId >= parsedCursor.id) continue;\n }\n } else {\n // For ascending order, skip items <= cursor\n if (itemTime < cursorTime) continue;\n // If timestamps are equal, use ID for tie-breaking (skip if ID <= cursorId)\n if (itemTime === cursorTime && parsedCursor.id && getId) {\n const itemId = getId(item);\n if (itemId <= parsedCursor.id) continue;\n }\n }\n }\n\n validItems.push(item);\n }\n }\n\n // 5. Sort by createdAt (and by ID for tie-breaking if getId is provided)\n validItems.sort((a, b) => {\n const aTime = a.createdAt.getTime();\n const bTime = b.createdAt.getTime();\n const timeComparison = sortOrder === 'asc' ? aTime - bTime : bTime - aTime;\n\n // If timestamps are equal and we have getId, use ID for stable sorting\n if (timeComparison === 0 && getId) {\n const aId = getId(a);\n const bId = getId(b);\n return sortOrder === 'asc'\n ? aId.localeCompare(bId)\n : bId.localeCompare(aId);\n }\n\n return timeComparison;\n });\n\n // 6. Apply pagination\n const hasMore = validItems.length > limit;\n const items = hasMore ? validItems.slice(0, limit) : validItems;\n const nextCursor =\n items.length > 0\n ? createCursor(\n items[items.length - 1].createdAt,\n getId?.(items[items.length - 1])\n )\n : null;\n\n return {\n data: items,\n cursor: nextCursor,\n hasMore,\n };\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import type { World } from '@workflow/world';
|
|
2
2
|
import type { Config } from './config.js';
|
|
3
|
+
import { type DirectHandler } from './queue.js';
|
|
4
|
+
export { DataDirAccessError, DataDirVersionError, ensureDataDir, initDataDir, type ParsedVersion, parseVersion, } from './init.js';
|
|
5
|
+
export type { DirectHandler } from './queue.js';
|
|
6
|
+
export type LocalWorld = World & {
|
|
7
|
+
/** Register a direct in-process handler for a queue prefix, bypassing HTTP. */
|
|
8
|
+
registerHandler(prefix: '__wkf_step_' | '__wkf_workflow_', handler: DirectHandler): void;
|
|
9
|
+
/** Clear all workflow data (runs, steps, events, hooks, streams). */
|
|
10
|
+
clear(): Promise<void>;
|
|
11
|
+
};
|
|
3
12
|
/**
|
|
4
|
-
* Creates
|
|
13
|
+
* Creates a local world instance that combines queue, storage, and streamer functionalities.
|
|
5
14
|
*
|
|
6
15
|
* @param args - Optional configuration object
|
|
7
16
|
* @param args.dataDir - Directory for storing workflow data (default: `.workflow-data/`)
|
|
8
17
|
* @param args.port - Port override for queue transport (default: auto-detected)
|
|
9
18
|
* @param args.baseUrl - Full base URL override for queue transport (default: `http://localhost:{port}`)
|
|
19
|
+
* @param args.tag - Optional tag to scope files (e.g., `vitest-0`). When set, files are written
|
|
20
|
+
* as `{id}.{tag}.json` and `clear()` only deletes files matching this tag.
|
|
21
|
+
* @throws {DataDirAccessError} If the data directory cannot be created or accessed
|
|
22
|
+
* @throws {DataDirVersionError} If the data directory version is incompatible
|
|
10
23
|
*/
|
|
11
|
-
export declare function
|
|
24
|
+
export declare function createLocalWorld(args?: Partial<Config>): LocalWorld;
|
|
12
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAW1C,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAM7D,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,KAAK,aAAa,EAClB,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG;IAC/B,+EAA+E;IAC/E,eAAe,CACb,MAAM,EAAE,aAAa,GAAG,iBAAiB,EACzC,OAAO,EAAE,aAAa,GACrB,IAAI,CAAC;IACR,qEAAqE;IACrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,UAAU,CA+FnE"}
|