@ny4n/durable 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +711 -2
- package/dist/documents.d.ts +66 -0
- package/dist/documents.d.ts.map +1 -0
- package/dist/documents.js +98 -0
- package/dist/documents.js.map +1 -0
- package/dist/entries.d.ts +31 -0
- package/dist/entries.d.ts.map +1 -0
- package/dist/entries.js +31 -0
- package/dist/entries.js.map +1 -0
- package/dist/env/decode.d.ts +16 -0
- package/dist/env/decode.d.ts.map +1 -0
- package/dist/env/decode.js +28 -0
- package/dist/env/decode.js.map +1 -0
- package/dist/env/index.d.ts +263 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/env/index.js +49 -0
- package/dist/env/index.js.map +1 -0
- package/dist/env/line-scan.d.ts +13 -0
- package/dist/env/line-scan.d.ts.map +1 -0
- package/dist/env/line-scan.js +147 -0
- package/dist/env/line-scan.js.map +1 -0
- package/dist/env/node-watch.d.ts +29 -0
- package/dist/env/node-watch.d.ts.map +1 -0
- package/dist/env/node-watch.js +485 -0
- package/dist/env/node-watch.js.map +1 -0
- package/dist/env/node.d.ts +56 -0
- package/dist/env/node.d.ts.map +1 -0
- package/dist/env/node.js +1166 -0
- package/dist/env/node.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +53 -0
- package/dist/errors.js.map +1 -0
- package/dist/harness/agent.d.ts +33 -0
- package/dist/harness/agent.d.ts.map +1 -0
- package/dist/harness/agent.js +235 -0
- package/dist/harness/agent.js.map +1 -0
- package/dist/harness/assistant.d.ts +15 -0
- package/dist/harness/assistant.d.ts.map +1 -0
- package/dist/harness/assistant.js +23 -0
- package/dist/harness/assistant.js.map +1 -0
- package/dist/harness/compaction.d.ts +56 -0
- package/dist/harness/compaction.d.ts.map +1 -0
- package/dist/harness/compaction.js +384 -0
- package/dist/harness/compaction.js.map +1 -0
- package/dist/harness/context.d.ts +63 -0
- package/dist/harness/context.d.ts.map +1 -0
- package/dist/harness/context.js +221 -0
- package/dist/harness/context.js.map +1 -0
- package/dist/harness/define.d.ts +18 -0
- package/dist/harness/define.d.ts.map +1 -0
- package/dist/harness/define.js +25 -0
- package/dist/harness/define.js.map +1 -0
- package/dist/harness/events.d.ts +180 -0
- package/dist/harness/events.d.ts.map +1 -0
- package/dist/harness/events.js +370 -0
- package/dist/harness/events.js.map +1 -0
- package/dist/harness/generation.d.ts +54 -0
- package/dist/harness/generation.d.ts.map +1 -0
- package/dist/harness/generation.js +514 -0
- package/dist/harness/generation.js.map +1 -0
- package/dist/harness/harness.d.ts +17 -0
- package/dist/harness/harness.d.ts.map +1 -0
- package/dist/harness/harness.js +332 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/inbox.d.ts +59 -0
- package/dist/harness/inbox.d.ts.map +1 -0
- package/dist/harness/inbox.js +97 -0
- package/dist/harness/inbox.js.map +1 -0
- package/dist/harness/json.d.ts +10 -0
- package/dist/harness/json.d.ts.map +1 -0
- package/dist/harness/json.js +33 -0
- package/dist/harness/json.js.map +1 -0
- package/dist/harness/live.d.ts +142 -0
- package/dist/harness/live.d.ts.map +1 -0
- package/dist/harness/live.js +149 -0
- package/dist/harness/live.js.map +1 -0
- package/dist/harness/output.d.ts +69 -0
- package/dist/harness/output.d.ts.map +1 -0
- package/dist/harness/output.js +318 -0
- package/dist/harness/output.js.map +1 -0
- package/dist/harness/prompt.d.ts +27 -0
- package/dist/harness/prompt.d.ts.map +1 -0
- package/dist/harness/prompt.js +131 -0
- package/dist/harness/prompt.js.map +1 -0
- package/dist/harness/provider.d.ts +14 -0
- package/dist/harness/provider.d.ts.map +1 -0
- package/dist/harness/provider.js +30 -0
- package/dist/harness/provider.js.map +1 -0
- package/dist/harness/registry.d.ts +6 -0
- package/dist/harness/registry.d.ts.map +1 -0
- package/dist/harness/registry.js +101 -0
- package/dist/harness/registry.js.map +1 -0
- package/dist/harness/run.d.ts +17 -0
- package/dist/harness/run.d.ts.map +1 -0
- package/dist/harness/run.js +26 -0
- package/dist/harness/run.js.map +1 -0
- package/dist/harness/scheduler.d.ts +106 -0
- package/dist/harness/scheduler.d.ts.map +1 -0
- package/dist/harness/scheduler.js +1743 -0
- package/dist/harness/scheduler.js.map +1 -0
- package/dist/harness/submissions.d.ts +29 -0
- package/dist/harness/submissions.d.ts.map +1 -0
- package/dist/harness/submissions.js +175 -0
- package/dist/harness/submissions.js.map +1 -0
- package/dist/harness/task-graph.d.ts +49 -0
- package/dist/harness/task-graph.d.ts.map +1 -0
- package/dist/harness/task-graph.js +168 -0
- package/dist/harness/task-graph.js.map +1 -0
- package/dist/harness/tool.d.ts +76 -0
- package/dist/harness/tool.d.ts.map +1 -0
- package/dist/harness/tool.js +736 -0
- package/dist/harness/tool.js.map +1 -0
- package/dist/harness/types.d.ts +713 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +2 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/harness/usage.d.ts +18 -0
- package/dist/harness/usage.d.ts.map +1 -0
- package/dist/harness/usage.js +57 -0
- package/dist/harness/usage.js.map +1 -0
- package/dist/harness/util.d.ts +19 -0
- package/dist/harness/util.d.ts.map +1 -0
- package/dist/harness/util.js +58 -0
- package/dist/harness/util.js.map +1 -0
- package/dist/harness/view.d.ts +47 -0
- package/dist/harness/view.d.ts.map +1 -0
- package/dist/harness/view.js +206 -0
- package/dist/harness/view.js.map +1 -0
- package/dist/ids.d.ts +6 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +9 -0
- package/dist/ids.js.map +1 -0
- package/dist/images/cloudflare.d.ts +4 -0
- package/dist/images/cloudflare.d.ts.map +1 -0
- package/dist/images/cloudflare.js +9 -0
- package/dist/images/cloudflare.js.map +1 -0
- package/dist/images/exif.d.ts +3 -0
- package/dist/images/exif.d.ts.map +1 -0
- package/dist/images/exif.js +71 -0
- package/dist/images/exif.js.map +1 -0
- package/dist/images/index.d.ts +18 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +125 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/node-worker.d.ts +17 -0
- package/dist/images/node-worker.d.ts.map +1 -0
- package/dist/images/node-worker.js +16 -0
- package/dist/images/node-worker.js.map +1 -0
- package/dist/images/node.d.ts +21 -0
- package/dist/images/node.d.ts.map +1 -0
- package/dist/images/node.js +121 -0
- package/dist/images/node.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/session/forks.d.ts +10 -0
- package/dist/session/forks.d.ts.map +1 -0
- package/dist/session/forks.js +42 -0
- package/dist/session/forks.js.map +1 -0
- package/dist/session/observation.d.ts +42 -0
- package/dist/session/observation.d.ts.map +1 -0
- package/dist/session/observation.js +281 -0
- package/dist/session/observation.js.map +1 -0
- package/dist/session/session.d.ts +133 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +811 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/transaction.d.ts +119 -0
- package/dist/session/transaction.d.ts.map +1 -0
- package/dist/session/transaction.js +795 -0
- package/dist/session/transaction.js.map +1 -0
- package/dist/storage/jsonl/index.d.ts +2 -0
- package/dist/storage/jsonl/index.d.ts.map +1 -0
- package/dist/storage/jsonl/index.js +2 -0
- package/dist/storage/jsonl/index.js.map +1 -0
- package/dist/storage/jsonl/node.d.ts +6 -0
- package/dist/storage/jsonl/node.d.ts.map +1 -0
- package/dist/storage/jsonl/node.js +8 -0
- package/dist/storage/jsonl/node.js.map +1 -0
- package/dist/storage/jsonl/storage.d.ts +143 -0
- package/dist/storage/jsonl/storage.d.ts.map +1 -0
- package/dist/storage/jsonl/storage.js +682 -0
- package/dist/storage/jsonl/storage.js.map +1 -0
- package/dist/storage/memory.d.ts +62 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +733 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/scan.d.ts +18 -0
- package/dist/storage/scan.d.ts.map +1 -0
- package/dist/storage/scan.js +29 -0
- package/dist/storage/scan.js.map +1 -0
- package/dist/storage/sqlite/cloudflare.d.ts +46 -0
- package/dist/storage/sqlite/cloudflare.d.ts.map +1 -0
- package/dist/storage/sqlite/cloudflare.js +106 -0
- package/dist/storage/sqlite/cloudflare.js.map +1 -0
- package/dist/storage/sqlite/database.d.ts +37 -0
- package/dist/storage/sqlite/database.d.ts.map +1 -0
- package/dist/storage/sqlite/database.js +2 -0
- package/dist/storage/sqlite/database.js.map +1 -0
- package/dist/storage/sqlite/index.d.ts +4 -0
- package/dist/storage/sqlite/index.d.ts.map +1 -0
- package/dist/storage/sqlite/index.js +3 -0
- package/dist/storage/sqlite/index.js.map +1 -0
- package/dist/storage/sqlite/migrations.d.ts +11 -0
- package/dist/storage/sqlite/migrations.d.ts.map +1 -0
- package/dist/storage/sqlite/migrations.js +111 -0
- package/dist/storage/sqlite/migrations.js.map +1 -0
- package/dist/storage/sqlite/node.d.ts +41 -0
- package/dist/storage/sqlite/node.d.ts.map +1 -0
- package/dist/storage/sqlite/node.js +179 -0
- package/dist/storage/sqlite/node.js.map +1 -0
- package/dist/storage/sqlite/storage.d.ts +65 -0
- package/dist/storage/sqlite/storage.d.ts.map +1 -0
- package/dist/storage/sqlite/storage.js +670 -0
- package/dist/storage/sqlite/storage.js.map +1 -0
- package/dist/tasks.d.ts +6 -0
- package/dist/tasks.d.ts.map +1 -0
- package/dist/tasks.js +5 -0
- package/dist/tasks.js.map +1 -0
- package/dist/testing/assertions.d.ts +5 -0
- package/dist/testing/assertions.d.ts.map +1 -0
- package/dist/testing/assertions.js +25 -0
- package/dist/testing/assertions.js.map +1 -0
- package/dist/testing/env-conformance.d.ts +7 -0
- package/dist/testing/env-conformance.d.ts.map +1 -0
- package/dist/testing/env-conformance.js +431 -0
- package/dist/testing/env-conformance.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +6 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/runner.d.ts +12 -0
- package/dist/testing/runner.d.ts.map +1 -0
- package/dist/testing/runner.js +23 -0
- package/dist/testing/runner.js.map +1 -0
- package/dist/testing/storage-benchmark.d.ts +41 -0
- package/dist/testing/storage-benchmark.d.ts.map +1 -0
- package/dist/testing/storage-benchmark.js +350 -0
- package/dist/testing/storage-benchmark.js.map +1 -0
- package/dist/testing/storage-conformance.d.ts +4 -0
- package/dist/testing/storage-conformance.d.ts.map +1 -0
- package/dist/testing/storage-conformance.js +1213 -0
- package/dist/testing/storage-conformance.js.map +1 -0
- package/dist/testing/types.d.ts +37 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +2 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/tools/bash.d.ts +55 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +138 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +89 -0
- package/dist/tools/edit-diff.d.ts.map +1 -0
- package/dist/tools/edit-diff.js +386 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit.d.ts +18 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +117 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/env.d.ts +5 -0
- package/dist/tools/env.d.ts.map +1 -0
- package/dist/tools/env.js +7 -0
- package/dist/tools/env.js.map +1 -0
- package/dist/tools/file-mutation-queue.d.ts +9 -0
- package/dist/tools/file-mutation-queue.d.ts.map +1 -0
- package/dist/tools/file-mutation-queue.js +52 -0
- package/dist/tools/file-mutation-queue.js.map +1 -0
- package/dist/tools/image-processor.d.ts +47 -0
- package/dist/tools/image-processor.d.ts.map +1 -0
- package/dist/tools/image-processor.js +30 -0
- package/dist/tools/image-processor.js.map +1 -0
- package/dist/tools/image.d.ts +20 -0
- package/dist/tools/image.d.ts.map +1 -0
- package/dist/tools/image.js +178 -0
- package/dist/tools/image.js.map +1 -0
- package/dist/tools/index.d.ts +46 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +23 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/path-utils.d.ts +5 -0
- package/dist/tools/path-utils.d.ts.map +1 -0
- package/dist/tools/path-utils.js +26 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/read.d.ts +25 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +235 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/write.d.ts +10 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +31 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/truncate.d.ts +64 -0
- package/dist/truncate.d.ts.map +1 -0
- package/dist/truncate.js +154 -0
- package/dist/truncate.js.map +1 -0
- package/dist/types.d.ts +932 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +140 -5
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function ok(value) {
|
|
2
|
+
return { ok: true, value };
|
|
3
|
+
}
|
|
4
|
+
export function err(error) {
|
|
5
|
+
return { ok: false, error };
|
|
6
|
+
}
|
|
7
|
+
export function getOrThrow(result) {
|
|
8
|
+
if (!result.ok)
|
|
9
|
+
throw result.error;
|
|
10
|
+
return result.value;
|
|
11
|
+
}
|
|
12
|
+
export function getOrUndefined(result) {
|
|
13
|
+
return result.ok ? result.value : undefined;
|
|
14
|
+
}
|
|
15
|
+
export function toError(error) {
|
|
16
|
+
if (error instanceof Error)
|
|
17
|
+
return error;
|
|
18
|
+
if (typeof error === "string")
|
|
19
|
+
return new Error(error);
|
|
20
|
+
try {
|
|
21
|
+
return new Error(JSON.stringify(error));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return new Error(String(error));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class FileError extends Error {
|
|
28
|
+
code;
|
|
29
|
+
path;
|
|
30
|
+
constructor(code, message, path, cause) {
|
|
31
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
32
|
+
this.name = "FileError";
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.path = path;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class ExecutionError extends Error {
|
|
38
|
+
code;
|
|
39
|
+
/** Spill file of a command that timed out or was aborted after its output crossed the spill thresholds. */
|
|
40
|
+
spillPath;
|
|
41
|
+
constructor(code, message, cause) {
|
|
42
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
43
|
+
this.name = "ExecutionError";
|
|
44
|
+
this.code = code;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export { rangeDecoder, StreamDecoder, startsWithBom } from "./decode.js";
|
|
48
|
+
export { LineScanner } from "./line-scan.js";
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,EAAE,CAAiB,KAAa;IAC/C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,GAAG,CAAiB,KAAa;IAChD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,UAAU,CAAiB,MAA8B;IACxE,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,MAAM,CAAC,KAAK,CAAC;IACnC,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,cAAc,CAAgC,MAA8B;IAC3F,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7C,CAAC;AAED,M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AAW,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["import type { Context } from \"@ny4n/chord\";\n\n/** Result of a fallible operation. Expected failures are returned instead of thrown. */\nexport type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport function ok<TValue, TError>(value: TValue): Result<TValue, TError> {\n\treturn { ok: true, value };\n}\n\nexport function err<TValue, TError>(error: TError): Result<TValue, TError> {\n\treturn { ok: false, error };\n}\n\nexport function getOrThrow<TValue, TError>(result: Result<TValue, TError>): TValue {\n\tif (!result.ok) throw result.error;\n\treturn result.value;\n}\n\nexport function getOrUndefined<TValue extends object, TError>(result: Result<TValue, TError>): TValue | undefined {\n\treturn result.ok ? result.value : undefined;\n}\n\nexport function toError(error: unknown): Error {\n\tif (error instanceof Error) return error;\n\tif (typeof error === \"string\") return new Error(error);\n\ttry {\n\t\treturn new Error(JSON.stringify(error));\n\t} catch {\n\t\treturn new Error(String(error));\n\t}\n}\n\nexport type FileKind = \"file\" | \"directory\" | \"symlink\";\n\nexport type FileErrorCode =\n\t| \"aborted\"\n\t| \"not_found\"\n\t| \"permission_denied\"\n\t| \"not_directory\"\n\t| \"is_directory\"\n\t| \"invalid\"\n\t| \"not_supported\"\n\t| \"unknown\";\n\nexport class FileError extends Error {\n\tpublic code: FileErrorCode;\n\tpublic path?: string;\n\n\tconstructor(code: FileErrorCode, message: string, path?: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"FileError\";\n\t\tthis.code = code;\n\t\tthis.path = path;\n\t}\n}\n\nexport type ExecutionErrorCode =\n\t| \"aborted\"\n\t| \"timeout\"\n\t| \"shell_unavailable\"\n\t| \"spawn_error\"\n\t| \"callback_error\"\n\t| \"unknown\";\n\nexport class ExecutionError extends Error {\n\tpublic code: ExecutionErrorCode;\n\t/** Spill file of a command that timed out or was aborted after its output crossed the spill thresholds. */\n\tpublic spillPath?: string;\n\n\tconstructor(code: ExecutionErrorCode, message: string, cause?: Error) {\n\t\tsuper(message, cause === undefined ? undefined : { cause });\n\t\tthis.name = \"ExecutionError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport interface FileInfo {\n\tname: string;\n\tpath: string;\n\tkind: FileKind;\n\tsize: number;\n\tmtimeMs: number;\n}\n\nexport interface TextLine {\n\ttext: string;\n\tterminated: boolean;\n}\n\nexport interface TextLineReader {\n\treadLine(context: Context): Promise<Result<TextLine | undefined, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** Positional reads from one opened regular file; all calls see the same file even if its path is renamed. */\nexport interface BinaryReader {\n\t/** Metadata of the opened file, not of whatever its path names now. */\n\tinfo(context: Context): Promise<Result<FileInfo, FileError>>;\n\t/** Up to `length` bytes at `offset`; fewer only at end of file. */\n\tread(offset: number, length: number, context: Context): Promise<Result<Uint8Array, FileError>>;\n\t/**\n\t * One pass over the file that locates lines `[startLine, endLine)` (`endLine` absent: to the end), 0-based, where line\n\t * `k` starts after the `k`-th newline byte. Decoded sizes are those of the text `new TextDecoder().decode(file)` would\n\t * produce for that range, so a byte-order mark at the start of the file is not counted.\n\t */\n\tscanLines(options: { startLine: number; endLine?: number }, context: Context): Promise<Result<LineScan, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** A file or directory to watch. It may be missing; creating it is a change. */\nexport interface WatchTarget {\n\tpath: string;\n\t/** Watch everything below a directory, not only its entries. Symbolic links below it are not followed. */\n\trecursive?: boolean;\n\t/** Entries below `path` that are neither watched nor reported: names starting with `.`, or these names. */\n\texclude?: { hidden?: boolean; names?: readonly string[] };\n}\n\n/**\n * What changed:\n * - `paths`: something at or below each path may have changed (a directory path covers its whole subtree). Calls may be\n * spurious; a change is never missed while the watcher is healthy.\n * - `overflow`: coverage was uncertain for a while (lost events, reconnect); rescan everything that is watched.\n * - `error`: the watcher stopped, for example because the watched tree grew past the environment's limit; no calls\n * follow.\n */\nexport type WatchChange = { paths: string[] } | { overflow: true } | { error: FileError };\n\nexport interface FileWatcher {\n\t/**\n\t * `native`: changes are reported within about two seconds. `polling`: the environment compares snapshots, because\n\t * the file system does not report changes reliably (network and FUSE file systems); a change undone between two\n\t * snapshots can be missed.\n\t */\n\treadonly mode: \"native\" | \"polling\";\n\t/** Stop watching; no `onChange` call starts after this resolves. Idempotent. */\n\tclose(context: Context): Promise<void>;\n}\n\n/** Where lines of a file are, as `BinaryReader.scanLines` found them. */\nexport interface LineScan {\n\t/** Newline bytes in the whole file; it has `newlines + 1` lines. */\n\tnewlines: number;\n\t/**\n\t * Byte range of the selected lines: from the start of the first to the end of the last, without the newline that\n\t * ends it. A selection past the last line is empty at the end of the file.\n\t */\n\tstart: number;\n\tend: number;\n\t/** Where the first selected line ends: its newline, or the end of the file. */\n\tfirstLineEnd: number;\n\t/** Where the last selected line starts. */\n\tlastLineStart: number;\n\t/** UTF-8 byte length of the decoded selection and of its first line. */\n\tselectedBytes: number;\n\tfirstLineBytes: number;\n}\n\n/** Pages of one directory's entries. */\nexport interface DirReader {\n\t/**\n\t * Up to `maxEntries` entries in the order the file system returns them, continuing where the previous call stopped.\n\t * `done` marks the end; it may come with the last entries or with an empty page. An entry that disappears before its\n\t * metadata is read is skipped, as are entries of unsupported kinds. After a failed or aborted call, close the reader.\n\t */\n\tnext(maxEntries: number, context: Context): Promise<Result<{ entries: FileInfo[]; done: boolean }, FileError>>;\n\tclose(context: Context): Promise<void>;\n}\n\n/** Portable filesystem capability. Operations return failures rather than throwing. */\nexport interface FileSystem {\n\t/**\n\t * The file namespace: equal ids see the same files at the same paths, whatever their `cwd`. Every local Node\n\t * environment shares one id; each container or remote host has its own.\n\t */\n\treadonly id: string;\n\tcwd: string;\n\tabsolutePath(path: string, context: Context): Promise<Result<string, FileError>>;\n\tjoinPath(parts: string[], context: Context): Promise<Result<string, FileError>>;\n\treadTextFile(path: string, context: Context): Promise<Result<string, FileError>>;\n\topenTextLineReader(path: string, context: Context): Promise<Result<TextLineReader, FileError>>;\n\treadTextLines(\n\t\tpath: string,\n\t\toptions: { maxLines?: number } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string[], FileError>>;\n\treadBinaryFile(path: string, context: Context): Promise<Result<Uint8Array, FileError>>;\n\t/**\n\t * Open a regular file for bounded positional reads. A directory fails with `is_directory`, other non-regular files\n\t * with `invalid`. With `noFollow`, a symbolic link as the final path component fails with `invalid` instead of being\n\t * followed; earlier components are still resolved.\n\t */\n\topenBinaryReader(\n\t\tpath: string,\n\t\toptions: { noFollow?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<BinaryReader, FileError>>;\n\twriteFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\tappendFile(path: string, content: string | Uint8Array, context: Context): Promise<Result<void, FileError>>;\n\t/** Truncate or extend a file to exactly `size` bytes. */\n\ttruncateFile(path: string, size: number, context: Context): Promise<Result<void, FileError>>;\n\t/** Flush file contents and metadata needed to retrieve them from an open file handle. */\n\tflushFile(path: string, context: Context): Promise<Result<void, FileError>>;\n\trenameFile(sourcePath: string, destinationPath: string, context: Context): Promise<Result<void, FileError>>;\n\tfileInfo(path: string, context: Context): Promise<Result<FileInfo, FileError>>;\n\tlistDir(path: string, context: Context): Promise<Result<FileInfo[], FileError>>;\n\topenDirReader(path: string, context: Context): Promise<Result<DirReader, FileError>>;\n\t/**\n\t * Report changes to files and directories, for hosts that load resources from the environment. When the returned\n\t * watcher exists, coverage is established: a host that watches before it loads cannot miss a change made during the\n\t * load. See `WatchChange` for what is reported and `FileWatcher.mode` for how reliably.\n\t */\n\twatch(\n\t\ttargets: readonly WatchTarget[],\n\t\tonChange: (change: WatchChange) => void,\n\t\tcontext: Context,\n\t): Promise<Result<FileWatcher, FileError>>;\n\tcanonicalPath(path: string, context: Context): Promise<Result<string, FileError>>;\n\texists(path: string, context: Context): Promise<Result<boolean, FileError>>;\n\tcreateDir(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tremove(\n\t\tpath: string,\n\t\toptions: { recursive?: boolean; force?: boolean } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<void, FileError>>;\n\tcreateTempDir(prefix: string | undefined, context: Context): Promise<Result<string, FileError>>;\n\tcreateTempFile(\n\t\toptions: { prefix?: string; suffix?: string } | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<string, FileError>>;\n\tcleanup(context: Context): Promise<void>;\n}\n\n/** Spill the complete output to a temporary file once it exceeds either threshold. */\nexport interface ShellSpillOptions {\n\tafterBytes: number;\n\t/** Complete or partial lines. */\n\tafterLines: number;\n}\n\nexport interface ShellExecResult {\n\texitCode: number;\n\t/** Temporary file holding the complete raw output, when the spill thresholds were exceeded. */\n\tspillPath?: string;\n}\n\nexport interface ShellExecOptions {\n\tcwd?: string;\n\tenv?: Record<string, string>;\n\tinheritEnv?: boolean;\n\ttimeout?: number;\n\t/**\n\t * Every decoded chunk of stdout and stderr as it arrives, in arrival order, with the stream it came from: raw,\n\t * unbounded, and unthrottled. Each stream is decoded separately, so a character split across chunks survives.\n\t */\n\tonOutput?: (text: string, context: Context, info: ShellOutputInfo) => void;\n\tspill?: ShellSpillOptions;\n\t/**\n\t * The caller keeps only this tail of the output, so the environment may omit output outside it and report the omission\n\t * as `info.skipped`. Without it, every chunk is delivered.\n\t */\n\twindow?: ShellOutputWindow;\n}\n\n/**\n * The tail of the combined output a caller keeps, and how often it samples it. An environment that transfers output\n * over a slow link uses it to omit what the caller would drop anyway and to send no faster than the caller commits.\n */\nexport interface ShellOutputWindow {\n\t/** UTF-8 bytes of decoded text kept at the end of the output. */\n\tmaxBytes: number;\n\t/** Lines kept at the end of the output. */\n\tmaxLines: number;\n\t/** Minimum pause between the caller's samples of the output. */\n\tminIntervalMs: number;\n\t/** Each sample also pauses the caller in proportion to its size at this rate. */\n\tbytesPerSecond: number;\n}\n\n/**\n * Output an environment omitted, measured on the decoded text `onOutput` would have received: every U+FFFD counts as\n * three bytes, and no sanitizing is applied.\n */\nexport interface ShellOutputSkip {\n\t/** UTF-8 byte length of the omitted text. */\n\tbytes: number;\n\t/** Newlines (U+000A) in the omitted text. */\n\tnewlines: number;\n\t/** Whether the omitted text ends with a newline. */\n\tendsWithNewline: boolean;\n}\n\nexport interface ShellOutputInfo {\n\tstream: \"stdout\" | \"stderr\";\n\t/**\n\t * Output omitted immediately before this chunk, only with `window`. The chunk then holds all output after the\n\t * omission up to its end, and that is more than the window by at least one byte or one line: more than\n\t * `window.maxBytes` bytes or more than `window.maxLines` newlines. So the omitted text can never be in the kept tail.\n\t * The omission and such a chunk may span both streams in arrival order; `stream` then names the chunk's last stream.\n\t * Callers that need the streams apart do not pass `window`.\n\t */\n\tskipped?: ShellOutputSkip;\n}\n\nexport interface Shell {\n\t/**\n\t * Run a command. A string runs through the environment's shell. An array runs `command[0]` directly with the rest\n\t * as its arguments, without a shell, so they reach the program unparsed. Aborting the context or a timeout kills\n\t * only this command's processes.\n\t */\n\texec(\n\t\tcommand: string | readonly string[],\n\t\toptions: ShellExecOptions | undefined,\n\t\tcontext: Context,\n\t): Promise<Result<ShellExecResult, ExecutionError>>;\n\t/** Kill every command this environment still runs; for its owner's shutdown, never for one request. */\n\tcleanup(context: Context): Promise<void>;\n}\n\nexport interface ExecutionEnv extends FileSystem, Shell {}\n\nexport { rangeDecoder, StreamDecoder, startsWithBom } from \"./decode.ts\";\nexport { LineScanner } from \"./line-scan.ts\";\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LineScan } from "./index.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Computes a `LineScan` from a file's bytes fed in order, so an environment can scan any size in bounded memory. Decoded
|
|
4
|
+
* sizes use the same streaming WHATWG decoder as decoding the whole file at once.
|
|
5
|
+
*/
|
|
6
|
+
export declare class LineScanner {
|
|
7
|
+
#private;
|
|
8
|
+
/** `startLine` and `endLine` must be non-negative integers with `endLine > startLine`; `endLine` absent: to the end. */
|
|
9
|
+
constructor(startLine: number, endLine?: number);
|
|
10
|
+
push(chunk: Uint8Array): void;
|
|
11
|
+
finish(): LineScan;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=line-scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-scan.d.ts","sourceRoot":"","sources":["../../src/env/line-scan.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAU3C;;;GAGG;AACH,qBAAa,WAAW;;IAkBvB,wHAAwH;IACxH,YAAY,SAAS,EAAE,MAAM,EAAE,OAAO,SAA2B,EAShE;IAED,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAS5B;IA8BD,MAAM,IAAI,QAAQ,CA0BjB;CAkCD"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { rangeDecoder, startsWithBom } from "./decode.js";
|
|
2
|
+
const NEWLINE = 0x0a;
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
/** UTF-8 byte length of decoded text. */
|
|
5
|
+
function decodedBytes(text) {
|
|
6
|
+
return text === "" ? 0 : encoder.encode(text).length;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Computes a `LineScan` from a file's bytes fed in order, so an environment can scan any size in bounded memory. Decoded
|
|
10
|
+
* sizes use the same streaming WHATWG decoder as decoding the whole file at once.
|
|
11
|
+
*/
|
|
12
|
+
export class LineScanner {
|
|
13
|
+
#startLine;
|
|
14
|
+
#endLine;
|
|
15
|
+
#position = 0;
|
|
16
|
+
#newlines = 0;
|
|
17
|
+
#lineStart = 0;
|
|
18
|
+
#start;
|
|
19
|
+
#end;
|
|
20
|
+
#firstLineEnd;
|
|
21
|
+
#lastLineStart;
|
|
22
|
+
#selectedBytes = 0;
|
|
23
|
+
#firstLineBytes = 0;
|
|
24
|
+
#selection;
|
|
25
|
+
#firstLine;
|
|
26
|
+
/** The first bytes, held until it is known whether they are a byte-order mark. */
|
|
27
|
+
#head = [];
|
|
28
|
+
#bom = false;
|
|
29
|
+
/** `startLine` and `endLine` must be non-negative integers with `endLine > startLine`; `endLine` absent: to the end. */
|
|
30
|
+
constructor(startLine, endLine = Number.POSITIVE_INFINITY) {
|
|
31
|
+
if (!Number.isSafeInteger(startLine) || startLine < 0 || !(endLine > startLine)) {
|
|
32
|
+
throw new RangeError("Invalid line range");
|
|
33
|
+
}
|
|
34
|
+
if (endLine !== Number.POSITIVE_INFINITY && !Number.isSafeInteger(endLine))
|
|
35
|
+
throw new RangeError("Invalid line range");
|
|
36
|
+
this.#startLine = startLine;
|
|
37
|
+
this.#endLine = endLine;
|
|
38
|
+
if (startLine === 0)
|
|
39
|
+
this.#begin(0);
|
|
40
|
+
}
|
|
41
|
+
push(chunk) {
|
|
42
|
+
if (this.#head !== undefined) {
|
|
43
|
+
const take = Math.min(3 - this.#head.length, chunk.length);
|
|
44
|
+
this.#head.push(...chunk.subarray(0, take));
|
|
45
|
+
if (this.#head.length < 3)
|
|
46
|
+
return;
|
|
47
|
+
this.#releaseHead();
|
|
48
|
+
chunk = chunk.subarray(take);
|
|
49
|
+
}
|
|
50
|
+
this.#process(chunk);
|
|
51
|
+
}
|
|
52
|
+
#releaseHead() {
|
|
53
|
+
const head = Uint8Array.from(this.#head ?? []);
|
|
54
|
+
this.#head = undefined;
|
|
55
|
+
this.#bom = startsWithBom(head);
|
|
56
|
+
this.#process(head);
|
|
57
|
+
}
|
|
58
|
+
#process(chunk) {
|
|
59
|
+
const base = this.#position;
|
|
60
|
+
let from = 0;
|
|
61
|
+
for (let index = chunk.indexOf(NEWLINE); index !== -1; index = chunk.indexOf(NEWLINE, index + 1)) {
|
|
62
|
+
// The newline ends line `this.#newlines`. It belongs to the selection between selected lines only.
|
|
63
|
+
this.#feed(chunk, base, from, index);
|
|
64
|
+
const line = this.#newlines;
|
|
65
|
+
const position = base + index;
|
|
66
|
+
if (line === this.#startLine)
|
|
67
|
+
this.#endFirstLine(position);
|
|
68
|
+
if (line === this.#endLine - 1)
|
|
69
|
+
this.#endSelection(position);
|
|
70
|
+
this.#feed(chunk, base, index, index + 1);
|
|
71
|
+
from = index + 1;
|
|
72
|
+
this.#newlines++;
|
|
73
|
+
this.#lineStart = position + 1;
|
|
74
|
+
if (this.#newlines === this.#startLine)
|
|
75
|
+
this.#begin(this.#lineStart);
|
|
76
|
+
if (this.#newlines === this.#endLine - 1)
|
|
77
|
+
this.#lastLineStart = this.#lineStart;
|
|
78
|
+
}
|
|
79
|
+
this.#feed(chunk, base, from, chunk.length);
|
|
80
|
+
this.#position += chunk.length;
|
|
81
|
+
}
|
|
82
|
+
finish() {
|
|
83
|
+
if (this.#head !== undefined)
|
|
84
|
+
this.#releaseHead();
|
|
85
|
+
const size = this.#position;
|
|
86
|
+
if (this.#start === undefined) {
|
|
87
|
+
return {
|
|
88
|
+
newlines: this.#newlines,
|
|
89
|
+
start: size,
|
|
90
|
+
end: size,
|
|
91
|
+
firstLineEnd: size,
|
|
92
|
+
lastLineStart: size,
|
|
93
|
+
selectedBytes: 0,
|
|
94
|
+
firstLineBytes: 0,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (this.#firstLineEnd === undefined)
|
|
98
|
+
this.#endFirstLine(size);
|
|
99
|
+
if (this.#end === undefined)
|
|
100
|
+
this.#endSelection(size);
|
|
101
|
+
return {
|
|
102
|
+
newlines: this.#newlines,
|
|
103
|
+
start: this.#start,
|
|
104
|
+
end: this.#end ?? size,
|
|
105
|
+
firstLineEnd: this.#firstLineEnd ?? size,
|
|
106
|
+
// A selection that reaches past the last line ends with the last line.
|
|
107
|
+
lastLineStart: this.#lastLineStart ?? this.#lineStart,
|
|
108
|
+
selectedBytes: this.#selectedBytes,
|
|
109
|
+
firstLineBytes: this.#firstLineBytes,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
#begin(start) {
|
|
113
|
+
this.#start = start;
|
|
114
|
+
if (this.#startLine === this.#endLine - 1)
|
|
115
|
+
this.#lastLineStart = start;
|
|
116
|
+
this.#selection = rangeDecoder();
|
|
117
|
+
this.#firstLine = rangeDecoder();
|
|
118
|
+
}
|
|
119
|
+
#endFirstLine(position) {
|
|
120
|
+
this.#firstLineEnd = position;
|
|
121
|
+
if (this.#firstLine !== undefined)
|
|
122
|
+
this.#firstLineBytes += decodedBytes(this.#firstLine.decode());
|
|
123
|
+
this.#firstLine = undefined;
|
|
124
|
+
}
|
|
125
|
+
#endSelection(position) {
|
|
126
|
+
this.#end = position;
|
|
127
|
+
if (this.#selection !== undefined)
|
|
128
|
+
this.#selectedBytes += decodedBytes(this.#selection.decode());
|
|
129
|
+
this.#selection = undefined;
|
|
130
|
+
}
|
|
131
|
+
/** Feed `chunk[from, to)`, which starts at file offset `base`, to the decoders of the ranges still open. */
|
|
132
|
+
#feed(chunk, base, from, to) {
|
|
133
|
+
// Decoding the whole file drops a leading byte-order mark.
|
|
134
|
+
if (this.#bom && base + from < 3)
|
|
135
|
+
from = Math.min(to, 3 - base);
|
|
136
|
+
if (to <= from)
|
|
137
|
+
return;
|
|
138
|
+
const bytes = chunk.subarray(from, to);
|
|
139
|
+
if (this.#selection !== undefined) {
|
|
140
|
+
this.#selectedBytes += decodedBytes(this.#selection.decode(bytes, { stream: true }));
|
|
141
|
+
}
|
|
142
|
+
if (this.#firstLine !== undefined) {
|
|
143
|
+
this.#firstLineBytes += decodedBytes(this.#firstLine.decode(bytes, { stream: true }));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=line-scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-scan.js","sourceRoot":"","sources":["../../src/env/line-scan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG1D,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,yCAAyC;AACzC,SAAS,YAAY,CAAC,IAAY;IACjC,OAAO,IAAI,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AC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;QACjG,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,4GAA4G;IAC5G,KAAK,CAAC,KAAiB,EAAE,IAAY,EAAE,IAAY,EAAE,EAAU;QAC9D,2DAA2D;QAC3D,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,GAAG,IAAI,GAAG,CAAC;YAAE,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QAChE,IAAI,EAAE,IAAI,IAAI;YAAE,OAAO;QACvB,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,cAAc,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACtF,CAAC;QACD,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,eAAe,IAAI,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACvF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { rangeDecoder, startsWithBom } from \"./decode.ts\";\nimport type { LineScan } from \"./index.ts\";\n\nconst NEWLINE = 0x0a;\nconst encoder = new TextEncoder();\n\n/** UTF-8 byte length of decoded text. */\nfunction decodedBytes(text: string): number {\n\treturn text === \"\" ? 0 : encoder.encode(text).length;\n}\n\n/**\n * Computes a `LineScan` from a file's bytes fed in order, so an environment can scan any size in bounded memory. Decoded\n * sizes use the same streaming WHATWG decoder as decoding the whole file at once.\n */\nexport class LineScanner {\n\treadonly #startLine: number;\n\treadonly #endLine: number;\n\t#position = 0;\n\t#newlines = 0;\n\t#lineStart = 0;\n\t#start: number | undefined;\n\t#end: number | undefined;\n\t#firstLineEnd: number | undefined;\n\t#lastLineStart: number | undefined;\n\t#selectedBytes = 0;\n\t#firstLineBytes = 0;\n\t#selection: InstanceType<typeof TextDecoder> | undefined;\n\t#firstLine: InstanceType<typeof TextDecoder> | undefined;\n\t/** The first bytes, held until it is known whether they are a byte-order mark. */\n\t#head: number[] | undefined = [];\n\t#bom = false;\n\n\t/** `startLine` and `endLine` must be non-negative integers with `endLine > startLine`; `endLine` absent: to the end. */\n\tconstructor(startLine: number, endLine = Number.POSITIVE_INFINITY) {\n\t\tif (!Number.isSafeInteger(startLine) || startLine < 0 || !(endLine > startLine)) {\n\t\t\tthrow new RangeError(\"Invalid line range\");\n\t\t}\n\t\tif (endLine !== Number.POSITIVE_INFINITY && !Number.isSafeInteger(endLine))\n\t\t\tthrow new RangeError(\"Invalid line range\");\n\t\tthis.#startLine = startLine;\n\t\tthis.#endLine = endLine;\n\t\tif (startLine === 0) this.#begin(0);\n\t}\n\n\tpush(chunk: Uint8Array): void {\n\t\tif (this.#head !== undefined) {\n\t\t\tconst take = Math.min(3 - this.#head.length, chunk.length);\n\t\t\tthis.#head.push(...chunk.subarray(0, take));\n\t\t\tif (this.#head.length < 3) return;\n\t\t\tthis.#releaseHead();\n\t\t\tchunk = chunk.subarray(take);\n\t\t}\n\t\tthis.#process(chunk);\n\t}\n\n\t#releaseHead(): void {\n\t\tconst head = Uint8Array.from(this.#head ?? []);\n\t\tthis.#head = undefined;\n\t\tthis.#bom = startsWithBom(head);\n\t\tthis.#process(head);\n\t}\n\n\t#process(chunk: Uint8Array): void {\n\t\tconst base = this.#position;\n\t\tlet from = 0;\n\t\tfor (let index = chunk.indexOf(NEWLINE); index !== -1; index = chunk.indexOf(NEWLINE, index + 1)) {\n\t\t\t// The newline ends line `this.#newlines`. It belongs to the selection between selected lines only.\n\t\t\tthis.#feed(chunk, base, from, index);\n\t\t\tconst line = this.#newlines;\n\t\t\tconst position = base + index;\n\t\t\tif (line === this.#startLine) this.#endFirstLine(position);\n\t\t\tif (line === this.#endLine - 1) this.#endSelection(position);\n\t\t\tthis.#feed(chunk, base, index, index + 1);\n\t\t\tfrom = index + 1;\n\t\t\tthis.#newlines++;\n\t\t\tthis.#lineStart = position + 1;\n\t\t\tif (this.#newlines === this.#startLine) this.#begin(this.#lineStart);\n\t\t\tif (this.#newlines === this.#endLine - 1) this.#lastLineStart = this.#lineStart;\n\t\t}\n\t\tthis.#feed(chunk, base, from, chunk.length);\n\t\tthis.#position += chunk.length;\n\t}\n\n\tfinish(): LineScan {\n\t\tif (this.#head !== undefined) this.#releaseHead();\n\t\tconst size = this.#position;\n\t\tif (this.#start === undefined) {\n\t\t\treturn {\n\t\t\t\tnewlines: this.#newlines,\n\t\t\t\tstart: size,\n\t\t\t\tend: size,\n\t\t\t\tfirstLineEnd: size,\n\t\t\t\tlastLineStart: size,\n\t\t\t\tselectedBytes: 0,\n\t\t\t\tfirstLineBytes: 0,\n\t\t\t};\n\t\t}\n\t\tif (this.#firstLineEnd === undefined) this.#endFirstLine(size);\n\t\tif (this.#end === undefined) this.#endSelection(size);\n\t\treturn {\n\t\t\tnewlines: this.#newlines,\n\t\t\tstart: this.#start,\n\t\t\tend: this.#end ?? size,\n\t\t\tfirstLineEnd: this.#firstLineEnd ?? size,\n\t\t\t// A selection that reaches past the last line ends with the last line.\n\t\t\tlastLineStart: this.#lastLineStart ?? this.#lineStart,\n\t\t\tselectedBytes: this.#selectedBytes,\n\t\t\tfirstLineBytes: this.#firstLineBytes,\n\t\t};\n\t}\n\n\t#begin(start: number): void {\n\t\tthis.#start = start;\n\t\tif (this.#startLine === this.#endLine - 1) this.#lastLineStart = start;\n\t\tthis.#selection = rangeDecoder();\n\t\tthis.#firstLine = rangeDecoder();\n\t}\n\n\t#endFirstLine(position: number): void {\n\t\tthis.#firstLineEnd = position;\n\t\tif (this.#firstLine !== undefined) this.#firstLineBytes += decodedBytes(this.#firstLine.decode());\n\t\tthis.#firstLine = undefined;\n\t}\n\n\t#endSelection(position: number): void {\n\t\tthis.#end = position;\n\t\tif (this.#selection !== undefined) this.#selectedBytes += decodedBytes(this.#selection.decode());\n\t\tthis.#selection = undefined;\n\t}\n\n\t/** Feed `chunk[from, to)`, which starts at file offset `base`, to the decoders of the ranges still open. */\n\t#feed(chunk: Uint8Array, base: number, from: number, to: number): void {\n\t\t// Decoding the whole file drops a leading byte-order mark.\n\t\tif (this.#bom && base + from < 3) from = Math.min(to, 3 - base);\n\t\tif (to <= from) return;\n\t\tconst bytes = chunk.subarray(from, to);\n\t\tif (this.#selection !== undefined) {\n\t\t\tthis.#selectedBytes += decodedBytes(this.#selection.decode(bytes, { stream: true }));\n\t\t}\n\t\tif (this.#firstLine !== undefined) {\n\t\t\tthis.#firstLineBytes += decodedBytes(this.#firstLine.decode(bytes, { stream: true }));\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Context } from "@ny4n/chord";
|
|
2
|
+
import { type FileWatcher, type WatchChange, type WatchTarget } from "./index.ts";
|
|
3
|
+
/** How `NodeExecutionEnv` watches. */
|
|
4
|
+
export interface NodeWatchOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Force a mode. By default `polling` is chosen on Windows, where native watchers keep directories open and so block
|
|
7
|
+
* renaming their parents, and for file systems that do not report remote changes.
|
|
8
|
+
*/
|
|
9
|
+
mode?: "native" | "polling";
|
|
10
|
+
/** Interval between snapshots in `polling` mode; default 2000 ms. */
|
|
11
|
+
pollIntervalMs?: number;
|
|
12
|
+
/** Most directories one watcher covers; default 10,000. */
|
|
13
|
+
maxDirectories?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Watches by snapshots: native events only trigger a debounced rescan, and changes are the difference between
|
|
17
|
+
* snapshots plus the event paths. A replaced file, a renamed or recreated ancestor, or a directory created with its
|
|
18
|
+
* contents therefore never depends on which events an operating system sends. New directories get their watchers
|
|
19
|
+
* before they are scanned again, so nothing written into them before the watcher existed is missed.
|
|
20
|
+
*/
|
|
21
|
+
export declare class NodeFileWatcher implements FileWatcher {
|
|
22
|
+
#private;
|
|
23
|
+
private constructor();
|
|
24
|
+
/** Establish coverage: watchers first, then the snapshot later changes are compared with. */
|
|
25
|
+
static open(targets: readonly WatchTarget[], resolvePath: (path: string) => string, onChange: (change: WatchChange) => void, options: NodeWatchOptions): Promise<NodeFileWatcher>;
|
|
26
|
+
get mode(): "native" | "polling";
|
|
27
|
+
close(_context: Context): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=node-watch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-watch.d.ts","sourceRoot":"","sources":["../../src/env/node-watch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7F,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC5B,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAkHD;;;;;GAKG;AACH,qBAAa,eAAgB,YAAW,WAAW;;IAelD,OAAO,eAWN;IAED,6FAA6F;IAC7F,OAAa,IAAI,CAChB,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EACrC,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,EACvC,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,eAAe,CAAC,CAwB1B;IAED,IAAI,IAAI,IAAI,QAAQ,GAAG,SAAS,CAE/B;IAEK,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAI5C;CA6SD"}
|