@lingxia/rong 0.0.1 → 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 +10 -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 -151
  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
@@ -1,116 +0,0 @@
1
- /**
2
- * Child Process module type definitions
3
- * Corresponds to: modules/rong_child_process
4
- */
5
-
6
- import type { EventEmitter } from './event';
7
-
8
- export interface SpawnOptions {
9
- /** Current working directory */
10
- cwd?: string;
11
- /** Environment variables */
12
- env?: Record<string, string>;
13
- /** Use shell to execute command */
14
- shell?: boolean;
15
- /** Timeout in milliseconds */
16
- timeout?: number;
17
- }
18
-
19
- export interface ExecOptions {
20
- /** Current working directory */
21
- cwd?: string;
22
- /** Environment variables */
23
- env?: Record<string, string>;
24
- /** Timeout in milliseconds */
25
- timeout?: number;
26
- }
27
-
28
- export interface ExecResult {
29
- /** Exit code (null if not yet exited) */
30
- code: number | null;
31
- /** Standard output */
32
- stdout: string;
33
- /** Standard error */
34
- stderr: string;
35
- }
36
-
37
- export interface ChildProcess extends EventEmitter {
38
- /** Process ID (null if process failed to spawn) */
39
- readonly pid: number | null;
40
-
41
- /** Exit code (available after process exits) */
42
- readonly exitCode: number | null;
43
-
44
- /** Standard input stream (if configured as 'piped') */
45
- readonly stdin: WritableStream<Uint8Array> | null;
46
-
47
- /** Standard output stream (if configured as 'piped') */
48
- readonly stdout: ReadableStream<Uint8Array> | null;
49
-
50
- /** Standard error stream (if configured as 'piped') */
51
- readonly stderr: ReadableStream<Uint8Array> | null;
52
-
53
- /**
54
- * Wait for process to exit
55
- * @returns Exit code (null if terminated by signal)
56
- */
57
- wait(): Promise<number | null>;
58
-
59
- /**
60
- * Kill the process with a signal
61
- * @param signal - Signal name (e.g., 'SIGTERM', 'SIGKILL') or number
62
- * @returns true if signal was sent successfully
63
- */
64
- kill(signal?: string): boolean;
65
-
66
- // Event emitter methods (Node.js style)
67
- on(event: 'exit', listener: (code: number | null) => void): this;
68
- once(event: 'exit', listener: (code: number | null) => void): this;
69
- off(event: 'exit', listener: (code: number | null) => void): this;
70
- }
71
-
72
- export interface ChildProcessModule {
73
- /**
74
- * Spawn a child process
75
- * @param command - Command to execute
76
- * @param args - Command arguments (optional)
77
- * @param options - Spawn options
78
- *
79
- * @example
80
- * ```typescript
81
- * const child = child_process.spawn('ls', ['-la'], { cwd: '/tmp' });
82
- * const code = await child.wait();
83
- * ```
84
- */
85
- spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess;
86
-
87
- /**
88
- * Execute a shell command and capture output
89
- * @param command - Shell command to execute
90
- * @param options - Execution options
91
- *
92
- * @example
93
- * ```typescript
94
- * const result = await child_process.exec('echo "Hello"', { timeout: 5000 });
95
- * console.log(result.stdout);
96
- * ```
97
- */
98
- exec(command: string, options?: ExecOptions): Promise<ExecResult>;
99
-
100
- /**
101
- * Execute a file directly without shell
102
- * @param file - File path to execute
103
- * @param args - Command arguments
104
- * @param options - Execution options
105
- *
106
- * @example
107
- * ```typescript
108
- * const result = await child_process.execFile('/usr/bin/node', ['--version']);
109
- * console.log(result.stdout);
110
- * ```
111
- */
112
- execFile(file: string, args?: string[], options?: ExecOptions): Promise<ExecResult>;
113
- }
114
-
115
- // Note: ChildProcess module is mounted as globalThis.child_process
116
- export {};
package/src/console.ts DELETED
@@ -1,53 +0,0 @@
1
- /**
2
- * Console module type definitions
3
- * Corresponds to: modules/rong_console
4
- *
5
- * Note: console is a global object provided by the runtime.
6
- * This module extends the standard Web Console API.
7
- */
8
-
9
- export interface Console {
10
- /** Log messages to stdout */
11
- log(...args: any[]): void;
12
-
13
- /** Log error messages to stderr */
14
- error(...args: any[]): void;
15
-
16
- /** Log warning messages to stderr */
17
- warn(...args: any[]): void;
18
-
19
- /** Log informational messages to stdout */
20
- info(...args: any[]): void;
21
-
22
- /** Log debug messages to stdout */
23
- debug(...args: any[]): void;
24
-
25
- /** Clear the console */
26
- clear(): void;
27
- }
28
-
29
- export interface ConsoleConstructor {
30
- new(): Console;
31
- prototype: Console;
32
- }
33
-
34
- // Note: console is a global object provided by the runtime
35
- // The standard Web Console API is available globally
36
- // This module documents Rong-specific console features
37
-
38
- /**
39
- * Rong console supports format strings in console.log():
40
- * - %s - String substitution
41
- * - %d, %i - Integer substitution
42
- * - %f - Float substitution
43
- * - %o - Object inspection
44
- *
45
- * Example:
46
- * console.log("Name: %s, Age: %d", "Alice", 30);
47
- */
48
-
49
- declare global {
50
- const Console: ConsoleConstructor;
51
- }
52
-
53
- export {};
package/src/encoding.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Encoding module type definitions
3
- * Corresponds to: modules/rong_encoding
4
- *
5
- * Note: TextEncoder and TextDecoder are provided by the global environment
6
- * and match the Web API specification. No custom type definitions needed.
7
- * These types are available globally when "DOM" is included in tsconfig.json lib.
8
- */
9
-
10
- export {};
package/src/error.ts DELETED
@@ -1,149 +0,0 @@
1
- /**
2
- * Error type definitions for Rong runtime
3
- *
4
- * Rong can throw:
5
- * - standard JS `Error` objects (including `TypeError`, `RangeError`, etc.)
6
- * - `DOMException` instances for Abort-related errors (e.g. `AbortError`)
7
- *
8
- * This module provides type guards and utilities for error handling.
9
- */
10
-
11
- /**
12
- * Common error names used throughout the Rong runtime (as `error.name`).
13
- */
14
- export type RongErrorName =
15
- | 'Error'
16
- | 'TypeError'
17
- | 'RangeError'
18
- | 'ReferenceError'
19
- | 'AbortError'
20
- | 'NetworkError';
21
-
22
- /**
23
- * Base error interface for Rong runtime errors.
24
- */
25
- export interface RongError extends Error {
26
- /** Error name identifying the error type */
27
- readonly name: RongErrorName;
28
-
29
- /** Human-readable error message */
30
- readonly message: string;
31
-
32
- /** Stable Rong error code (e.g. "E_IO", "E_TIMEOUT", ...) when available */
33
- readonly code?: string;
34
-
35
- /** Optional structured error data when provided by the runtime */
36
- readonly data?: unknown;
37
-
38
- /** Stack trace (if available) */
39
- readonly stack?: string;
40
- }
41
-
42
- /**
43
- * Error thrown when an operation is aborted via AbortSignal.
44
- *
45
- * @example
46
- * ```typescript
47
- * const controller = new AbortController();
48
- * setTimeout(() => controller.abort(), 1000);
49
- *
50
- * try {
51
- * await Rong.readTextFile('/large-file.txt', {
52
- * signal: controller.signal
53
- * });
54
- * } catch (error) {
55
- * if (isAbortError(error)) {
56
- * console.log('Operation cancelled');
57
- * }
58
- * }
59
- * ```
60
- */
61
- export interface AbortError extends RongError {
62
- readonly name: 'AbortError';
63
- }
64
-
65
- export interface NetworkError extends RongError {
66
- readonly name: 'NetworkError';
67
- }
68
-
69
- // ==================== Type Guards ====================
70
-
71
- /**
72
- * Type guard to check if an error is a Rong runtime error.
73
- *
74
- * @param error - The error to check
75
- * @returns true if the error is a RongError
76
- *
77
- * @example
78
- * ```typescript
79
- * try {
80
- * await Rong.readTextFile('/file.txt');
81
- * } catch (error) {
82
- * if (isRongError(error)) {
83
- * console.error(`Rong error [${error.name}]: ${error.message}`);
84
- * }
85
- * }
86
- * ```
87
- */
88
- export function isRongError(error: unknown): error is RongError {
89
- return (error instanceof Error || error instanceof DOMException) &&
90
- typeof (error as { name?: unknown }).name === 'string';
91
- }
92
-
93
- /**
94
- * Type guard to check if an error is an AbortError.
95
- */
96
- export function isAbortError(error: unknown): error is AbortError {
97
- return (error instanceof Error || error instanceof DOMException) &&
98
- (error as { name?: unknown }).name === 'AbortError';
99
- }
100
-
101
- /**
102
- * Type guard to check if an error is a NetworkError.
103
- */
104
- export function isNetworkError(error: unknown): error is NetworkError {
105
- return (error instanceof Error || error instanceof DOMException) &&
106
- (error as { name?: unknown }).name === 'NetworkError';
107
- }
108
-
109
- // ==================== Utility Functions ====================
110
-
111
- /**
112
- * Get a human-readable error message from any error.
113
- *
114
- * @param error - The error to format
115
- * @returns Formatted error message
116
- *
117
- * @example
118
- * ```typescript
119
- * try {
120
- * await someOperation();
121
- * } catch (error) {
122
- * console.error(formatError(error));
123
- * }
124
- * ```
125
- */
126
- export function formatError(error: unknown): string {
127
- if (isRongError(error)) {
128
- const code = error.code ? ` ${error.code}` : '';
129
- return `[${error.name}${code}] ${error.message}`;
130
- }
131
- if (error instanceof Error) {
132
- return error.message;
133
- }
134
- return String(error);
135
- }
136
-
137
- /**
138
- * Assert that a value is a RongError, throwing if not.
139
- *
140
- * @param error - The value to check
141
- * @throws {TypeError} If the value is not a RongError
142
- */
143
- export function assertRongError(error: unknown): asserts error is RongError {
144
- if (!isRongError(error)) {
145
- throw new TypeError('Expected RongError');
146
- }
147
- }
148
-
149
- export {};
package/src/event.ts DELETED
@@ -1,128 +0,0 @@
1
- /**
2
- * Event module type definitions
3
- * Corresponds to: modules/rong_event
4
- */
5
-
6
- export interface EventOptions {
7
- /** Whether the event bubbles */
8
- bubbles?: boolean;
9
- /** Whether the event can be cancelled */
10
- cancelable?: boolean;
11
- /** Whether the event can cross shadow DOM boundaries */
12
- composed?: boolean;
13
- }
14
-
15
- export interface Event {
16
- /** Event type name */
17
- readonly type: string;
18
-
19
- /** Whether the event bubbles */
20
- readonly bubbles: boolean;
21
-
22
- /** Whether the event can be cancelled */
23
- readonly cancelable: boolean;
24
-
25
- /** Whether the event can cross shadow DOM boundaries */
26
- readonly composed: boolean;
27
- }
28
-
29
- export interface EventConstructor {
30
- new(type: string, options?: EventOptions): Event;
31
- prototype: Event;
32
- }
33
-
34
- export interface CustomEventOptions extends EventOptions {
35
- /** Custom data associated with the event */
36
- detail?: any;
37
- }
38
-
39
- export interface CustomEvent extends Event {
40
- /** Custom data associated with the event */
41
- readonly detail: any;
42
- }
43
-
44
- export interface CustomEventConstructor {
45
- new(type: string, options?: CustomEventOptions): CustomEvent;
46
- prototype: CustomEvent;
47
- }
48
-
49
- export type EventListener = (event: Event) => void;
50
-
51
- export interface AddEventListenerOptions {
52
- /** Remove listener after first invocation */
53
- once?: boolean;
54
- /** Use capture phase */
55
- capture?: boolean;
56
- /** Listener is passive (won't call preventDefault) */
57
- passive?: boolean;
58
- }
59
-
60
- export interface EventTarget {
61
- /** Add event listener (Web standard) */
62
- addEventListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions): void;
63
-
64
- /** Remove event listener (Web standard) */
65
- removeEventListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions): void;
66
-
67
- /** Dispatch event (Web standard) */
68
- dispatchEvent(event: Event): boolean;
69
- }
70
-
71
- export interface EventTargetConstructor {
72
- new(): EventTarget;
73
- prototype: EventTarget;
74
- }
75
-
76
- export type EventName = string | symbol;
77
- export type EventEmitterListener = (...args: any[]) => void;
78
-
79
- export interface EventEmitter extends EventTarget {
80
- /** Add event listener (Node.js style) */
81
- on(eventName: EventName, listener: EventEmitterListener): this;
82
-
83
- /** Add one-time event listener */
84
- once(eventName: EventName, listener: EventEmitterListener): this;
85
-
86
- /** Remove event listener */
87
- off(eventName: EventName, listener: EventEmitterListener): this;
88
-
89
- /** Remove event listener (alias for off) */
90
- removeListener(eventName: EventName, listener: EventEmitterListener): this;
91
-
92
- /** Remove all listeners for an event */
93
- removeAllListeners(eventName?: EventName): this;
94
-
95
- /** Add listener at the beginning of the listeners array */
96
- prependListener(eventName: EventName, listener: EventEmitterListener): this;
97
-
98
- /** Add one-time listener at the beginning of the listeners array */
99
- prependOnceListener(eventName: EventName, listener: EventEmitterListener): this;
100
-
101
- /** Emit an event */
102
- emit(eventName: EventName, ...args: any[]): boolean;
103
-
104
- /** Get array of registered event names */
105
- eventNames(): EventName[];
106
-
107
- /** Set maximum number of listeners per event (default: 10) */
108
- setMaxListeners(n: number): this;
109
-
110
- /** Get maximum number of listeners per event */
111
- getMaxListeners(): number;
112
-
113
- /** Get number of listeners for an event, optionally filtered by a specific listener */
114
- listenerCount(eventName: EventName, listener?: EventEmitterListener): number;
115
- }
116
-
117
- export interface EventEmitterConstructor {
118
- new(): EventEmitter;
119
- prototype: EventEmitter;
120
- }
121
-
122
- // Note: Event, CustomEvent, and EventTarget are provided by the global environment (Web API)
123
- // EventEmitter is a Rong-specific Node.js-style event emitter
124
- declare global {
125
- const EventEmitter: EventEmitterConstructor;
126
- }
127
-
128
- export {};
package/src/exception.ts DELETED
@@ -1,77 +0,0 @@
1
- /**
2
- * Exception module type definitions
3
- * Corresponds to: modules/rong_exception
4
- */
5
-
6
- export type DOMExceptionName =
7
- | 'IndexSizeError'
8
- | 'DOMStringSizeError'
9
- | 'HierarchyRequestError'
10
- | 'InvalidCharacterError'
11
- | 'NoDataAllowedError'
12
- | 'NoModificationAllowedError'
13
- | 'NotFoundError'
14
- | 'NotSupportedError'
15
- | 'InUseAttributeError'
16
- | 'InvalidStateError'
17
- | 'SyntaxError'
18
- | 'InvalidModificationError'
19
- | 'NamespaceError'
20
- | 'InvalidAccessError'
21
- | 'ValidationError'
22
- | 'TypeMismatchError'
23
- | 'SecurityError'
24
- | 'NetworkError'
25
- | 'AbortError'
26
- | 'URLMismatchError'
27
- | 'QuotaExceededError'
28
- | 'TimeoutError'
29
- | 'InvalidNodeTypeError'
30
- | 'DataCloneError'
31
- | 'Error'
32
- // Node.js-style constant names accepted by Rong's DOMException implementation
33
- | 'INDEX_SIZE_ERR'
34
- | 'DOMSTRING_SIZE_ERR'
35
- | 'HIERARCHY_REQUEST_ERR'
36
- | 'INVALID_CHARACTER_ERR'
37
- | 'NO_DATA_ALLOWED_ERR'
38
- | 'NO_MODIFICATION_ALLOWED_ERR'
39
- | 'NOT_FOUND_ERR'
40
- | 'NOT_SUPPORTED_ERR'
41
- | 'INUSE_ATTRIBUTE_ERR'
42
- | 'INVALID_STATE_ERR'
43
- | 'SYNTAX_ERR'
44
- | 'INVALID_MODIFICATION_ERR'
45
- | 'NAMESPACE_ERR'
46
- | 'INVALID_ACCESS_ERR'
47
- | 'VALIDATION_ERR'
48
- | 'TYPE_MISMATCH_ERR'
49
- | 'SECURITY_ERR'
50
- | 'NETWORK_ERR'
51
- | 'ABORT_ERR'
52
- | 'URL_MISMATCH_ERR'
53
- | 'QUOTA_EXCEEDED_ERR'
54
- | 'TIMEOUT_ERR'
55
- | 'INVALID_NODE_TYPE_ERR'
56
- | 'DATA_CLONE_ERR'
57
- | 'ERROR';
58
-
59
- export interface DOMException extends Error {
60
- /** Error name */
61
- readonly name: string;
62
-
63
- /** Error message */
64
- readonly message: string;
65
-
66
- /** Stack trace (currently returns "NotImplemented") */
67
- readonly stack: string;
68
- }
69
-
70
- export interface DOMExceptionConstructor {
71
- new(message?: string, name?: DOMExceptionName): DOMException;
72
- prototype: DOMException;
73
- }
74
-
75
- // Note: DOMException is provided by the global environment (Web API)
76
- // These type definitions are for reference and extend the standard Web API
77
- export {};