@lingxia/rong 0.2.0 → 0.3.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.
Files changed (66) hide show
  1. package/README.md +9 -7
  2. package/dist/command.d.ts +93 -0
  3. package/dist/command.d.ts.map +1 -0
  4. package/dist/command.js +6 -0
  5. package/dist/compression.d.ts +12 -0
  6. package/dist/compression.d.ts.map +1 -0
  7. package/dist/compression.js +6 -0
  8. package/dist/console.d.ts +20 -7
  9. package/dist/console.d.ts.map +1 -1
  10. package/dist/error.d.ts +40 -13
  11. package/dist/error.d.ts.map +1 -1
  12. package/dist/error.js +63 -28
  13. package/dist/fs.d.ts +111 -310
  14. package/dist/fs.d.ts.map +1 -1
  15. package/dist/fs.js +7 -4
  16. package/dist/global.d.ts +44 -37
  17. package/dist/global.d.ts.map +1 -1
  18. package/dist/http.d.ts +4 -0
  19. package/dist/http.d.ts.map +1 -1
  20. package/dist/index.d.ts +15 -12
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +15 -12
  23. package/dist/redis.d.ts +109 -0
  24. package/dist/redis.d.ts.map +1 -0
  25. package/dist/redis.js +13 -0
  26. package/dist/s3.d.ts +174 -0
  27. package/dist/s3.d.ts.map +1 -0
  28. package/dist/s3.js +10 -0
  29. package/dist/sqlite.d.ts +98 -0
  30. package/dist/sqlite.d.ts.map +1 -0
  31. package/dist/sqlite.js +8 -0
  32. package/dist/sse.d.ts +26 -0
  33. package/dist/sse.d.ts.map +1 -0
  34. package/dist/sse.js +2 -0
  35. package/dist/storage.d.ts +5 -16
  36. package/dist/storage.d.ts.map +1 -1
  37. package/dist/storage.js +4 -1
  38. package/dist/stream.d.ts +5 -8
  39. package/dist/stream.d.ts.map +1 -1
  40. package/dist/stream.js +5 -8
  41. package/dist/timer.d.ts +1 -18
  42. package/dist/timer.d.ts.map +1 -1
  43. package/dist/worker.d.ts +31 -0
  44. package/dist/worker.d.ts.map +1 -0
  45. package/dist/worker.js +14 -0
  46. package/package.json +12 -4
  47. package/src/abort.ts +0 -50
  48. package/src/assert.ts +0 -51
  49. package/src/buffer.ts +0 -60
  50. package/src/child_process.ts +0 -116
  51. package/src/console.ts +0 -53
  52. package/src/encoding.ts +0 -10
  53. package/src/error.ts +0 -149
  54. package/src/event.ts +0 -128
  55. package/src/exception.ts +0 -77
  56. package/src/fs.ts +0 -514
  57. package/src/global.ts +0 -98
  58. package/src/http.ts +0 -157
  59. package/src/index.ts +0 -67
  60. package/src/navigator.ts +0 -20
  61. package/src/path.ts +0 -83
  62. package/src/process.ts +0 -74
  63. package/src/storage.ts +0 -64
  64. package/src/stream.ts +0 -98
  65. package/src/timer.ts +0 -61
  66. package/src/url.ts +0 -106
package/README.md CHANGED
@@ -9,12 +9,11 @@ TypeScript type definitions for the Rong JavaScript runtime (globals injected by
9
9
 
10
10
  ## Runtime Export Map (high level)
11
11
 
12
- Rong injects a small set of globals:
12
+ - `Rong` namespace: file system, storage, runtime metadata, command APIs, timer helpers, compression helpers, and host constructors such as `RedisClient`, `S3Client`, `SQLite`, and `SSE`
13
+ - Globals added by Rong modules include `fetch`, `assert`, `atob`, `btoa`, `Worker`, `setTimeout`, `clearTimeout`, `setInterval`, and `clearInterval`
14
+ - Additional Web-standard globals such as `Request`, `Response`, `Headers`, `FormData`, `URL`, `ReadableStream`, `WritableStream`, `Blob`, `File`, `AbortController`, and `DOMException` are also provided when the corresponding runtime modules are enabled
13
15
 
14
- - `Rong` namespace: file system + storage
15
- - Globals: `process`, `child_process`, `path`, `fetch`, `timers`, `assert`, `atob`, `btoa`
16
-
17
- Rong also implements/extends a subset of Web APIs; the type package relies on TypeScript’s DOM libs for base types like `URL`, `ReadableStream`, `AbortController`, etc.
16
+ The type package relies on TypeScript’s DOM libs for shared Web API base types.
18
17
 
19
18
  ## Installation
20
19
 
@@ -36,12 +35,15 @@ Add to your `tsconfig.json`:
36
35
 
37
36
  Notes:
38
37
 
39
- - This enables global typings; you should not `import` runtime modules like `'child_process'` or `'http'` (those are Rong globals, not Node modules).
38
+ - This enables global typings; you should not `import` runtime modules like `'http'` (those are Rong globals, not Node modules).
40
39
  - Ensure your `tsconfig.json` `lib` includes `"DOM"` if you want DOM globals (e.g. `URL`, `ReadableStream`) to be typed.
40
+ - `Worker` uses the DOM global type name. The package exports `RongWorker`/`RongWorkerMessageEvent`/`RongWorkerErrorEvent` for the precise Rong subset when you want stricter annotations.
41
+ - Rong’s runtime `Storage` constructor intentionally is not redeclared globally in the type package, because the DOM lib already owns the global `Storage` name. Use the exported `Storage`/`StorageConstructor` types as local annotations when needed.
42
+ - The package only supports the root export `@lingxia/rong`; `src/*` and `dist/*` are not public import paths.
41
43
 
42
44
  ## Accuracy notes (common gotchas)
43
45
 
44
- - Storage is not `localStorage`-compatible. Use `await Rong.storage.open(path)` or `new Rong.Storage(path)`, then `set/get/delete/clear/list/info`.
46
+ - Storage is not `localStorage`-compatible. The standard runtime exposes `new Storage(path, options?)`; embedders may also inject a preconfigured `storage` instance, but that is not part of the default runtime surface.
45
47
  - Directory listing is `Rong.readDir(...)` (async iterator), not `Rong.readdir(...)`.
46
48
  - HTTP is the global `fetch(...)` API. There is no `http` namespace and no `download` JS API.
47
49
 
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Command execution APIs mounted on the Rong namespace.
3
+ * Corresponds to: modules/rong_command
4
+ */
5
+ export type RongSpawnStdio = 'pipe' | 'ignore' | 'inherit';
6
+ export type RongEnvMap = Record<string, string | undefined>;
7
+ export interface RongSpawnOptions {
8
+ cwd?: string;
9
+ env?: Record<string, string | undefined>;
10
+ shell?: boolean;
11
+ stdin?: 'pipe' | string | ArrayBuffer | ArrayBufferView | null;
12
+ stdout?: RongSpawnStdio;
13
+ stderr?: RongSpawnStdio;
14
+ timeout?: number;
15
+ killSignal?: string | number;
16
+ signal?: AbortSignal;
17
+ onExit?(subprocess: RongSubprocess, exitCode: number | null, signalCode: number | null, error?: unknown): void | Promise<void>;
18
+ }
19
+ export interface RongSpawnOptionsWithCmd extends RongSpawnOptions {
20
+ cmd: string[];
21
+ }
22
+ export interface RongSyncSubprocess {
23
+ readonly exitCode: number | null;
24
+ readonly success: boolean;
25
+ readonly signalCode: number | null;
26
+ readonly stdout: Uint8Array;
27
+ readonly stderr: Uint8Array;
28
+ }
29
+ export interface RongReadableProcessStream extends ReadableStream<Uint8Array> {
30
+ bytes(): Promise<Uint8Array>;
31
+ text(): Promise<string>;
32
+ json(): Promise<unknown>;
33
+ blob(): Promise<Blob>;
34
+ lines(): AsyncIterableIterator<string>;
35
+ }
36
+ export interface RongOutputHandle {
37
+ write(chunk: string | ArrayBuffer | ArrayBufferView): void;
38
+ flush(): void;
39
+ }
40
+ export interface RongWritableProcessStream extends WritableStream<Uint8Array> {
41
+ write(chunk: string | ArrayBuffer | ArrayBufferView): Promise<this>;
42
+ flush(): Promise<void>;
43
+ end(): Promise<void>;
44
+ }
45
+ export interface RongSubprocess {
46
+ readonly pid: number | null;
47
+ readonly exitCode: number | null;
48
+ readonly signalCode: number | null;
49
+ readonly killed: boolean;
50
+ readonly success: boolean;
51
+ readonly exited: Promise<number | null>;
52
+ stdin: RongWritableProcessStream | null;
53
+ stdout: RongReadableProcessStream | null;
54
+ stderr: RongReadableProcessStream | null;
55
+ kill(signal?: string | number): boolean;
56
+ wait(): Promise<number | null>;
57
+ unref(): void;
58
+ }
59
+ export interface RongShellResult {
60
+ stdout: Uint8Array;
61
+ stderr: Uint8Array;
62
+ exitCode: number | null;
63
+ success: boolean;
64
+ }
65
+ export interface RongShellCommand extends PromiseLike<RongShellResult> {
66
+ cwd(path: string): RongShellCommand;
67
+ env(values: Record<string, string | undefined>): RongShellCommand;
68
+ quiet(): RongShellCommand;
69
+ nothrow(): RongShellCommand;
70
+ throws(value?: boolean): RongShellCommand;
71
+ run(): Promise<RongShellResult>;
72
+ text(): Promise<string>;
73
+ json(): Promise<unknown>;
74
+ blob(): Promise<Blob>;
75
+ lines(): AsyncIterableIterator<string>;
76
+ }
77
+ export interface RongShellTag {
78
+ (strings: TemplateStringsArray, ...values: unknown[]): RongShellCommand;
79
+ (command: string): RongShellCommand;
80
+ cwd(path?: string): string | RongShellTag | undefined;
81
+ env(values?: Record<string, string | undefined>): Record<string, string | undefined> | RongShellTag | undefined;
82
+ throws(value?: boolean): RongShellTag;
83
+ nothrow(): RongShellTag;
84
+ quiet(): RongShellTag;
85
+ escape(value: unknown): string;
86
+ }
87
+ export interface RongShellError extends Error {
88
+ command: string;
89
+ exitCode: number | null;
90
+ stdout: Uint8Array;
91
+ stderr: Uint8Array;
92
+ }
93
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,CAAC;IAC/D,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,CACL,UAAU,EAAE,cAAc,EAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,KAAK,CAAC,EAAE,OAAO,GACd,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AC;IACtB,KAAK,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;IACxE,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACpC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,CAAC;IACtD,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,YAAY,GAAG,SAAS,CAAC;IAChH,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IACtC,OAAO,IAAI,YAAY,CAAC;IACxB,KAAK,IAAI,YAAY,CAAC;IACtB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,cAAe,SAAQ,KAAK;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC;CACpB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Command execution APIs mounted on the Rong namespace.
4
+ * Corresponds to: modules/rong_command
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Compression APIs mounted on the Rong namespace.
3
+ * Corresponds to: modules/rong_compression
4
+ */
5
+ export type RongCompressionInput = ArrayBuffer | ArrayBufferView;
6
+ export interface RongZstdCompressOptions {
7
+ level?: number;
8
+ }
9
+ export interface RongGzipCompressOptions {
10
+ level?: number;
11
+ }
12
+ //# sourceMappingURL=compression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../src/compression.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG,eAAe,CAAC;AAEjE,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Compression APIs mounted on the Rong namespace.
4
+ * Corresponds to: modules/rong_compression
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/console.d.ts CHANGED
@@ -16,13 +16,29 @@ export interface Console {
16
16
  info(...args: any[]): void;
17
17
  /** Log debug messages to stdout */
18
18
  debug(...args: any[]): void;
19
+ /** Log assertion failures to stderr */
20
+ assert(condition?: any, ...args: any[]): void;
21
+ /** Inspect a value with optional depth and length limits */
22
+ dir(value?: any, options?: {
23
+ depth?: number;
24
+ maxArrayLength?: number;
25
+ maxObjectKeys?: number;
26
+ }): void;
27
+ /** Log a stack trace */
28
+ trace(...args: any[]): void;
29
+ /** Start a named timer */
30
+ time(label?: string): void;
31
+ /** Log the elapsed time for a timer without stopping it */
32
+ timeLog(label?: string, ...args: any[]): void;
33
+ /** Log the elapsed time for a timer and stop it */
34
+ timeEnd(label?: string): void;
35
+ /** Increment and log a named counter */
36
+ count(label?: string): void;
37
+ /** Reset a named counter */
38
+ countReset(label?: string): void;
19
39
  /** Clear the console */
20
40
  clear(): void;
21
41
  }
22
- export interface ConsoleConstructor {
23
- new (): Console;
24
- prototype: Console;
25
- }
26
42
  /**
27
43
  * Rong console supports format strings in console.log():
28
44
  * - %s - String substitution
@@ -33,8 +49,5 @@ export interface ConsoleConstructor {
33
49
  * Example:
34
50
  * console.log("Name: %s, Age: %d", "Alice", 30);
35
51
  */
36
- declare global {
37
- const Console: ConsoleConstructor;
38
- }
39
52
  export {};
40
53
  //# sourceMappingURL=console.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,OAAO;IACtB,6BAA6B;IAC7B,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE1B,mCAAmC;IACnC,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE5B,qCAAqC;IACrC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE3B,2CAA2C;IAC3C,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE3B,mCAAmC;IACnC,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE5B,wBAAwB;IACxB,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAO,OAAO,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;CACpB;AAMD;;;;;;;;;GASG;AAEH,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,OAAO,EAAE,kBAAkB,CAAC;CACnC;AAED,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,OAAO;IACtB,6BAA6B;IAC7B,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE1B,mCAAmC;IACnC,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE5B,qCAAqC;IACrC,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE3B,2CAA2C;IAC3C,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE3B,mCAAmC;IACnC,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE5B,uCAAuC;IACvC,MAAM,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE9C,4DAA4D;IAC5D,GAAG,CACD,KAAK,CAAC,EAAE,GAAG,EACX,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GACA,IAAI,CAAC;IAER,wBAAwB;IACxB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE5B,0BAA0B;IAC1B,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B,2DAA2D;IAC3D,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE9C,mDAAmD;IACnD,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B,wCAAwC;IACxC,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE5B,4BAA4B;IAC5B,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEjC,wBAAwB;IACxB,KAAK,IAAI,IAAI,CAAC;CACf;AAMD;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC"}
package/dist/error.d.ts CHANGED
@@ -1,22 +1,37 @@
1
1
  /**
2
2
  * Error type definitions for Rong runtime
3
3
  *
4
- * Rong can throw:
4
+ * Rong can throw or reject with any JavaScript value.
5
+ *
6
+ * Common host-generated cases are:
5
7
  * - standard JS `Error` objects (including `TypeError`, `RangeError`, etc.)
6
- * - `DOMException` instances for Abort-related errors (e.g. `AbortError`)
8
+ * - `DOMException`-like objects for web-style failures (e.g. `AbortError`)
9
+ * - preserved JavaScript payloads from `throw <value>` / Promise rejection / abort reasons
7
10
  *
8
- * This module provides type guards and utilities for error handling.
11
+ * This module provides type guards and utilities for the error-object subset.
12
+ */
13
+ /**
14
+ * Known error names commonly produced by Rong host APIs.
9
15
  */
16
+ export type KnownRongErrorName = 'Error' | 'TypeError' | 'RangeError' | 'ReferenceError' | 'AbortError' | 'NetworkError' | 'SyntaxError' | 'InvalidStateError' | 'NotSupportedError' | 'TimeoutError' | 'SecurityError' | 'QuotaExceededError' | 'NotFoundError' | 'DataCloneError' | 'InvalidAccessError' | 'TypeMismatchError' | 'URLMismatchError';
10
17
  /**
11
- * Common error names used throughout the Rong runtime (as `error.name`).
18
+ * Backwards-compatible alias for the known error-name set.
12
19
  */
13
- export type RongErrorName = 'Error' | 'TypeError' | 'RangeError' | 'ReferenceError' | 'AbortError' | 'NetworkError';
20
+ export type RongErrorName = KnownRongErrorName;
14
21
  /**
15
- * Base error interface for Rong runtime errors.
22
+ * Catch/reject payload from Rong.
23
+ *
24
+ * This is intentionally `unknown`: runtime code may preserve arbitrary JavaScript values.
25
+ */
26
+ export type RongThrowable = unknown;
27
+ /**
28
+ * Error-object shape commonly produced by Rong host APIs.
29
+ *
30
+ * Note that not every caught Rong throwable matches this interface.
16
31
  */
17
32
  export interface RongError extends Error {
18
33
  /** Error name identifying the error type */
19
- readonly name: RongErrorName;
34
+ readonly name: string;
20
35
  /** Human-readable error message */
21
36
  readonly message: string;
22
37
  /** Stable Rong error code (e.g. "E_IO", "E_TIMEOUT", ...) when available */
@@ -35,7 +50,7 @@ export interface RongError extends Error {
35
50
  * setTimeout(() => controller.abort(), 1000);
36
51
  *
37
52
  * try {
38
- * await Rong.readTextFile('/large-file.txt', {
53
+ * await fetch('https://api.example.com/slow', {
39
54
  * signal: controller.signal
40
55
  * });
41
56
  * } catch (error) {
@@ -52,15 +67,15 @@ export interface NetworkError extends RongError {
52
67
  readonly name: 'NetworkError';
53
68
  }
54
69
  /**
55
- * Type guard to check if an error is a Rong runtime error.
70
+ * Type guard to check if a caught value is an Error-like object from Rong.
56
71
  *
57
72
  * @param error - The error to check
58
- * @returns true if the error is a RongError
73
+ * @returns true if the value behaves like a RongError object
59
74
  *
60
75
  * @example
61
76
  * ```typescript
62
77
  * try {
63
- * await Rong.readTextFile('/file.txt');
78
+ * await Rong.file('/file.txt').text();
64
79
  * } catch (error) {
65
80
  * if (isRongError(error)) {
66
81
  * console.error(`Rong error [${error.name}]: ${error.message}`);
@@ -77,6 +92,18 @@ export declare function isAbortError(error: unknown): error is AbortError;
77
92
  * Type guard to check if an error is a NetworkError.
78
93
  */
79
94
  export declare function isNetworkError(error: unknown): error is NetworkError;
95
+ /**
96
+ * Returns the `.name` of an Error-like throwable when present.
97
+ */
98
+ export declare function getErrorName(error: unknown): string | undefined;
99
+ /**
100
+ * Returns the stable Rong `.code` when present on an Error-like throwable.
101
+ */
102
+ export declare function getErrorCode(error: unknown): string | undefined;
103
+ /**
104
+ * Get a human-readable message from any throwable value.
105
+ */
106
+ export declare function getErrorMessage(error: unknown): string;
80
107
  /**
81
108
  * Get a human-readable error message from any error.
82
109
  *
@@ -94,10 +121,10 @@ export declare function isNetworkError(error: unknown): error is NetworkError;
94
121
  */
95
122
  export declare function formatError(error: unknown): string;
96
123
  /**
97
- * Assert that a value is a RongError, throwing if not.
124
+ * Assert that a value is a RongError-like object, throwing if not.
98
125
  *
99
126
  * @param error - The value to check
100
- * @throws {TypeError} If the value is not a RongError
127
+ * @throws {TypeError} If the value is not a RongError-like object
101
128
  */
102
129
  export declare function assertRongError(error: unknown): asserts error is RongError;
103
130
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,WAAW,GACX,YAA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B,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG/D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAWtD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAWlD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,SAAS,CAI1E;AAED,OAAO,EAAE,CAAC"}
package/dist/error.js CHANGED
@@ -2,25 +2,40 @@
2
2
  /**
3
3
  * Error type definitions for Rong runtime
4
4
  *
5
- * Rong can throw:
5
+ * Rong can throw or reject with any JavaScript value.
6
+ *
7
+ * Common host-generated cases are:
6
8
  * - standard JS `Error` objects (including `TypeError`, `RangeError`, etc.)
7
- * - `DOMException` instances for Abort-related errors (e.g. `AbortError`)
9
+ * - `DOMException`-like objects for web-style failures (e.g. `AbortError`)
10
+ * - preserved JavaScript payloads from `throw <value>` / Promise rejection / abort reasons
8
11
  *
9
- * This module provides type guards and utilities for error handling.
12
+ * This module provides type guards and utilities for the error-object subset.
10
13
  */
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.assertRongError = exports.formatError = exports.isNetworkError = exports.isAbortError = exports.isRongError = void 0;
13
- // ==================== Type Guards ====================
15
+ exports.isRongError = isRongError;
16
+ exports.isAbortError = isAbortError;
17
+ exports.isNetworkError = isNetworkError;
18
+ exports.getErrorName = getErrorName;
19
+ exports.getErrorCode = getErrorCode;
20
+ exports.getErrorMessage = getErrorMessage;
21
+ exports.formatError = formatError;
22
+ exports.assertRongError = assertRongError;
23
+ function getField(error, key) {
24
+ if ((typeof error === 'object' && error !== null) || typeof error === 'function') {
25
+ return error[key];
26
+ }
27
+ return undefined;
28
+ }
14
29
  /**
15
- * Type guard to check if an error is a Rong runtime error.
30
+ * Type guard to check if a caught value is an Error-like object from Rong.
16
31
  *
17
32
  * @param error - The error to check
18
- * @returns true if the error is a RongError
33
+ * @returns true if the value behaves like a RongError object
19
34
  *
20
35
  * @example
21
36
  * ```typescript
22
37
  * try {
23
- * await Rong.readTextFile('/file.txt');
38
+ * await Rong.file('/file.txt').text();
24
39
  * } catch (error) {
25
40
  * if (isRongError(error)) {
26
41
  * console.error(`Rong error [${error.name}]: ${error.message}`);
@@ -30,26 +45,48 @@ exports.assertRongError = exports.formatError = exports.isNetworkError = exports
30
45
  */
31
46
  function isRongError(error) {
32
47
  return (error instanceof Error || error instanceof DOMException) &&
33
- typeof error.name === 'string';
48
+ typeof getField(error, 'name') === 'string' &&
49
+ typeof getField(error, 'message') === 'string';
34
50
  }
35
- exports.isRongError = isRongError;
36
51
  /**
37
52
  * Type guard to check if an error is an AbortError.
38
53
  */
39
54
  function isAbortError(error) {
40
- return (error instanceof Error || error instanceof DOMException) &&
41
- error.name === 'AbortError';
55
+ return isRongError(error) && error.name === 'AbortError';
42
56
  }
43
- exports.isAbortError = isAbortError;
44
57
  /**
45
58
  * Type guard to check if an error is a NetworkError.
46
59
  */
47
60
  function isNetworkError(error) {
48
- return (error instanceof Error || error instanceof DOMException) &&
49
- error.name === 'NetworkError';
61
+ return isRongError(error) && error.name === 'NetworkError';
62
+ }
63
+ /**
64
+ * Returns the `.name` of an Error-like throwable when present.
65
+ */
66
+ function getErrorName(error) {
67
+ const name = getField(error, 'name');
68
+ return typeof name === 'string' ? name : undefined;
69
+ }
70
+ /**
71
+ * Returns the stable Rong `.code` when present on an Error-like throwable.
72
+ */
73
+ function getErrorCode(error) {
74
+ const code = getField(error, 'code');
75
+ return typeof code === 'string' ? code : undefined;
76
+ }
77
+ /**
78
+ * Get a human-readable message from any throwable value.
79
+ */
80
+ function getErrorMessage(error) {
81
+ if (typeof error === 'string') {
82
+ return error;
83
+ }
84
+ const message = getField(error, 'message');
85
+ if (typeof message === 'string') {
86
+ return message;
87
+ }
88
+ return String(error);
50
89
  }
51
- exports.isNetworkError = isNetworkError;
52
- // ==================== Utility Functions ====================
53
90
  /**
54
91
  * Get a human-readable error message from any error.
55
92
  *
@@ -66,25 +103,23 @@ exports.isNetworkError = isNetworkError;
66
103
  * ```
67
104
  */
68
105
  function formatError(error) {
69
- if (isRongError(error)) {
70
- const code = error.code ? ` ${error.code}` : '';
71
- return `[${error.name}${code}] ${error.message}`;
72
- }
73
- if (error instanceof Error) {
74
- return error.message;
106
+ const name = getErrorName(error);
107
+ const code = getErrorCode(error);
108
+ const message = getErrorMessage(error);
109
+ if (name) {
110
+ const formattedCode = code ? ` ${code}` : '';
111
+ return `[${name}${formattedCode}] ${message}`;
75
112
  }
76
- return String(error);
113
+ return message;
77
114
  }
78
- exports.formatError = formatError;
79
115
  /**
80
- * Assert that a value is a RongError, throwing if not.
116
+ * Assert that a value is a RongError-like object, throwing if not.
81
117
  *
82
118
  * @param error - The value to check
83
- * @throws {TypeError} If the value is not a RongError
119
+ * @throws {TypeError} If the value is not a RongError-like object
84
120
  */
85
121
  function assertRongError(error) {
86
122
  if (!isRongError(error)) {
87
123
  throw new TypeError('Expected RongError');
88
124
  }
89
125
  }
90
- exports.assertRongError = assertRongError;