@lingxia/rong 0.0.1

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 (82) hide show
  1. package/README.md +59 -0
  2. package/dist/abort.d.ts +36 -0
  3. package/dist/abort.d.ts.map +1 -0
  4. package/dist/abort.js +6 -0
  5. package/dist/assert.d.ts +44 -0
  6. package/dist/assert.d.ts.map +1 -0
  7. package/dist/assert.js +6 -0
  8. package/dist/buffer.d.ts +45 -0
  9. package/dist/buffer.d.ts.map +1 -0
  10. package/dist/buffer.js +6 -0
  11. package/dist/child_process.d.ts +99 -0
  12. package/dist/child_process.d.ts.map +1 -0
  13. package/dist/child_process.js +6 -0
  14. package/dist/console.d.ts +40 -0
  15. package/dist/console.d.ts.map +1 -0
  16. package/dist/console.js +9 -0
  17. package/dist/encoding.d.ts +10 -0
  18. package/dist/encoding.d.ts.map +1 -0
  19. package/dist/encoding.js +10 -0
  20. package/dist/error.d.ts +104 -0
  21. package/dist/error.d.ts.map +1 -0
  22. package/dist/error.js +90 -0
  23. package/dist/event.d.ts +96 -0
  24. package/dist/event.d.ts.map +1 -0
  25. package/dist/event.js +6 -0
  26. package/dist/exception.d.ts +19 -0
  27. package/dist/exception.d.ts.map +1 -0
  28. package/dist/exception.js +6 -0
  29. package/dist/fs.d.ts +450 -0
  30. package/dist/fs.d.ts.map +1 -0
  31. package/dist/fs.js +23 -0
  32. package/dist/global.d.ts +76 -0
  33. package/dist/global.d.ts.map +1 -0
  34. package/dist/global.js +8 -0
  35. package/dist/http.d.ts +117 -0
  36. package/dist/http.d.ts.map +1 -0
  37. package/dist/http.js +9 -0
  38. package/dist/index.d.ts +56 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +77 -0
  41. package/dist/navigator.d.ts +16 -0
  42. package/dist/navigator.d.ts.map +1 -0
  43. package/dist/navigator.js +6 -0
  44. package/dist/path.d.ts +70 -0
  45. package/dist/path.d.ts.map +1 -0
  46. package/dist/path.js +6 -0
  47. package/dist/process.d.ts +53 -0
  48. package/dist/process.d.ts.map +1 -0
  49. package/dist/process.js +6 -0
  50. package/dist/storage.d.ts +53 -0
  51. package/dist/storage.d.ts.map +1 -0
  52. package/dist/storage.js +8 -0
  53. package/dist/stream.d.ts +90 -0
  54. package/dist/stream.d.ts.map +1 -0
  55. package/dist/stream.js +90 -0
  56. package/dist/timer.d.ts +52 -0
  57. package/dist/timer.d.ts.map +1 -0
  58. package/dist/timer.js +6 -0
  59. package/dist/url.d.ts +75 -0
  60. package/dist/url.d.ts.map +1 -0
  61. package/dist/url.js +6 -0
  62. package/package.json +27 -0
  63. package/src/abort.ts +50 -0
  64. package/src/assert.ts +51 -0
  65. package/src/buffer.ts +60 -0
  66. package/src/child_process.ts +116 -0
  67. package/src/console.ts +53 -0
  68. package/src/encoding.ts +10 -0
  69. package/src/error.ts +149 -0
  70. package/src/event.ts +128 -0
  71. package/src/exception.ts +77 -0
  72. package/src/fs.ts +514 -0
  73. package/src/global.ts +98 -0
  74. package/src/http.ts +151 -0
  75. package/src/index.ts +67 -0
  76. package/src/navigator.ts +20 -0
  77. package/src/path.ts +83 -0
  78. package/src/process.ts +74 -0
  79. package/src/storage.ts +64 -0
  80. package/src/stream.ts +98 -0
  81. package/src/timer.ts +61 -0
  82. package/src/url.ts +106 -0
package/src/console.ts ADDED
@@ -0,0 +1,53 @@
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 {};
@@ -0,0 +1,10 @@
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 ADDED
@@ -0,0 +1,149 @@
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 ADDED
@@ -0,0 +1,128 @@
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 {};
@@ -0,0 +1,77 @@
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 {};