@gobing-ai/ts-runtime 0.3.0 → 0.3.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/README.md +234 -176
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -0
- package/dist/context.d.ts +28 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +45 -2
- package/dist/file-system-cf.d.ts +25 -0
- package/dist/file-system-cf.d.ts.map +1 -0
- package/dist/file-system-cf.js +59 -0
- package/dist/file-system-node.d.ts +29 -0
- package/dist/file-system-node.d.ts.map +1 -0
- package/dist/file-system-node.js +94 -0
- package/dist/file-system.d.ts +47 -0
- package/dist/file-system.d.ts.map +1 -0
- package/dist/file-system.js +0 -0
- package/dist/fs.d.ts +31 -1
- package/dist/fs.d.ts.map +1 -1
- package/dist/fs.js +32 -19
- package/dist/index.d.ts +21 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -2
- package/dist/path.d.ts +12 -0
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +65 -4
- package/dist/platform.d.ts +12 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +41 -0
- package/dist/plugin/capability-registry.d.ts +35 -0
- package/dist/plugin/capability-registry.d.ts.map +1 -0
- package/dist/plugin/capability-registry.js +43 -0
- package/dist/plugin/extension-loader.d.ts +66 -0
- package/dist/plugin/extension-loader.d.ts.map +1 -0
- package/dist/plugin/extension-loader.js +47 -0
- package/dist/plugin/extension-path.d.ts +15 -0
- package/dist/plugin/extension-path.d.ts.map +1 -0
- package/dist/plugin/extension-path.js +20 -0
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +3 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +1 -0
- package/dist/process-executor.d.ts +77 -19
- package/dist/process-executor.d.ts.map +1 -1
- package/dist/process-executor.js +209 -37
- package/dist/runtime-cf.d.ts +6 -0
- package/dist/runtime-cf.d.ts.map +1 -0
- package/dist/runtime-cf.js +33 -0
- package/dist/runtime-factory.d.ts +24 -0
- package/dist/runtime-factory.d.ts.map +1 -0
- package/dist/runtime-factory.js +0 -0
- package/dist/runtime-node-bun.d.ts +8 -0
- package/dist/runtime-node-bun.d.ts.map +1 -0
- package/dist/runtime-node-bun.js +67 -0
- package/dist/schema-validation.d.ts +16 -0
- package/dist/schema-validation.d.ts.map +1 -1
- package/dist/schema-validation.js +9 -4
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -2
- package/src/config.ts +16 -4
- package/src/context.ts +58 -4
- package/src/file-system-cf.ts +74 -0
- package/src/file-system-node.ts +122 -0
- package/src/file-system.ts +55 -0
- package/src/fs.ts +35 -18
- package/src/index.ts +57 -2
- package/src/path.ts +68 -4
- package/src/platform.ts +47 -0
- package/src/plugin/capability-registry.ts +58 -0
- package/src/plugin/extension-loader.ts +105 -0
- package/src/plugin/extension-path.ts +20 -0
- package/src/plugin/index.ts +3 -0
- package/src/plugin.ts +1 -0
- package/src/process-executor.ts +296 -58
- package/src/runtime-cf.ts +44 -0
- package/src/runtime-factory.ts +28 -0
- package/src/runtime-node-bun.ts +83 -0
- package/src/schema-validation.ts +20 -4
- package/src/types.ts +4 -0
package/src/schema-validation.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parse as parseYaml } from 'yaml';
|
|
2
|
+
import type { FileSystem } from './file-system';
|
|
2
3
|
import { getFs } from './fs';
|
|
3
|
-
import { dirnamePath, isAbsolutePath, joinPath } from './path';
|
|
4
|
+
import { dirnamePath, getProcessCwd, isAbsolutePath, joinPath } from './path';
|
|
4
5
|
|
|
5
6
|
/** Default time budget for a single remote schema fetch. */
|
|
6
7
|
const REMOTE_SCHEMA_FETCH_TIMEOUT_MS = 5_000;
|
|
@@ -8,11 +9,13 @@ const REMOTE_SCHEMA_FETCH_TIMEOUT_MS = 5_000;
|
|
|
8
9
|
/** Upper bound on a remote schema body. A timeout alone lets a slow multi-GB drip exhaust memory. */
|
|
9
10
|
const REMOTE_SCHEMA_MAX_BYTES = 5 * 1024 * 1024;
|
|
10
11
|
|
|
12
|
+
/** A single JSON Schema validation failure — records the JSON pointer path and a human-readable message. */
|
|
11
13
|
export interface JsonSchemaViolation {
|
|
12
14
|
path: string;
|
|
13
15
|
message: string;
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
/** Subset of JSON Schema 2020-12 keywords used for runtime configuration validation. */
|
|
16
19
|
export interface JsonSchema {
|
|
17
20
|
type?: string | string[];
|
|
18
21
|
required?: string[];
|
|
@@ -27,6 +30,7 @@ export interface JsonSchema {
|
|
|
27
30
|
$defs?: Record<string, JsonSchema>;
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
/** Options for loading and validating structured configuration files (YAML/JSON with `$schema`). */
|
|
30
34
|
export interface StructuredConfigLoadOptions {
|
|
31
35
|
validateSchema?: boolean;
|
|
32
36
|
/**
|
|
@@ -42,8 +46,16 @@ export interface StructuredConfigLoadOptions {
|
|
|
42
46
|
* Injectable for testing.
|
|
43
47
|
*/
|
|
44
48
|
resolve?: (specifier: string, from: string) => string;
|
|
49
|
+
/**
|
|
50
|
+
* File system used to read the config and local schema files. Defaults to the
|
|
51
|
+
* deprecated `getFs()` global; supply a {@link FileSystem} from the runtime factory
|
|
52
|
+
* (`createNodeFileSystem()`) to route reads through the factory path or to inject a
|
|
53
|
+
* virtual file system in tests.
|
|
54
|
+
*/
|
|
55
|
+
fileSystem?: Pick<FileSystem, 'readFile'>;
|
|
45
56
|
}
|
|
46
57
|
|
|
58
|
+
/** Error thrown when structured config validation fails, carrying the list of {@link JsonSchemaViolation}s. */
|
|
47
59
|
export class StructuredConfigSchemaError extends Error {
|
|
48
60
|
constructor(
|
|
49
61
|
message: string,
|
|
@@ -54,11 +66,13 @@ export class StructuredConfigSchemaError extends Error {
|
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
68
|
|
|
69
|
+
/** Reads a config file from disk, parses it (YAML or JSON), and validates against its declared `$schema`. */
|
|
57
70
|
export async function loadStructuredConfig(path: string, options: StructuredConfigLoadOptions = {}): Promise<unknown> {
|
|
58
|
-
const content = await getFs().readFile(path);
|
|
71
|
+
const content = await (options.fileSystem ?? getFs()).readFile(path);
|
|
59
72
|
return await parseStructuredConfig(content, path, options);
|
|
60
73
|
}
|
|
61
74
|
|
|
75
|
+
/** Parses a config string (YAML or JSON) and validates against its declared `$schema` if present. */
|
|
62
76
|
export async function parseStructuredConfig(
|
|
63
77
|
content: string,
|
|
64
78
|
source: string,
|
|
@@ -71,6 +85,7 @@ export async function parseStructuredConfig(
|
|
|
71
85
|
return parsed;
|
|
72
86
|
}
|
|
73
87
|
|
|
88
|
+
/** Extracts the `$schema` reference from a parsed config object, resolves and fetches the schema, then validates. */
|
|
74
89
|
export async function validateDeclaredJsonSchema(
|
|
75
90
|
value: unknown,
|
|
76
91
|
source: string,
|
|
@@ -108,6 +123,7 @@ export async function validateDeclaredJsonSchema(
|
|
|
108
123
|
}
|
|
109
124
|
}
|
|
110
125
|
|
|
126
|
+
/** Validates a value against a {@link JsonSchema}, returning a list of {@link JsonSchemaViolation}s. Does not throw. */
|
|
111
127
|
export function validateJsonSchema(
|
|
112
128
|
value: unknown,
|
|
113
129
|
schema: JsonSchema,
|
|
@@ -309,7 +325,7 @@ function resolvePackageSchema(
|
|
|
309
325
|
`Package schema ref "${specifier}" referenced by "${source}" must include a path within the package`,
|
|
310
326
|
);
|
|
311
327
|
}
|
|
312
|
-
const from = isRemoteRef(source) ?
|
|
328
|
+
const from = isRemoteRef(source) ? getProcessCwd() : dirnamePath(source);
|
|
313
329
|
try {
|
|
314
330
|
// Resolve the package root via its always-present package.json, then join the subpath.
|
|
315
331
|
// This sidesteps `exports` gating on arbitrary JSON subpaths.
|
|
@@ -344,7 +360,7 @@ async function readSchema(schemaLocation: string, options: StructuredConfigLoadO
|
|
|
344
360
|
}
|
|
345
361
|
return await readBoundedBody(response, schemaLocation);
|
|
346
362
|
}
|
|
347
|
-
return await getFs().readFile(schemaLocation);
|
|
363
|
+
return await (options.fileSystem ?? getFs()).readFile(schemaLocation);
|
|
348
364
|
}
|
|
349
365
|
|
|
350
366
|
/**
|
package/src/types.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import type { Config } from './config';
|
|
2
2
|
|
|
3
|
+
/** Identifier for the target runtime platform. */
|
|
3
4
|
export type RuntimeName = 'node-bun' | 'cloudflare-workers' | 'test';
|
|
4
5
|
|
|
6
|
+
/** Feature flags describing what a runtime platform supports (filesystem, process execution, persistent storage). */
|
|
5
7
|
export interface RuntimeCapabilities {
|
|
6
8
|
readonly hasFilesystem: boolean;
|
|
7
9
|
readonly hasProcessExecution: boolean;
|
|
8
10
|
readonly hasPersistentStorage: boolean;
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
/** Options passed to config loading functions, including overrides and environment variable bindings. */
|
|
11
14
|
export interface LoadConfigOptions {
|
|
12
15
|
overrides?: Partial<Config>;
|
|
13
16
|
envBindings?: Record<string, unknown>;
|
|
14
17
|
}
|
|
15
18
|
|
|
19
|
+
/** Minimal distributed tracing context for W3C trace/span propagation. */
|
|
16
20
|
export interface SpanContext {
|
|
17
21
|
traceId: string;
|
|
18
22
|
spanId: string;
|