@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/http.ts ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * HTTP module type definitions
3
+ * Corresponds to: modules/rong_http
4
+ *
5
+ * The HTTP module provides the standard `fetch` API for making HTTP requests.
6
+ * It does NOT provide an `http` object or `download` function.
7
+ */
8
+
9
+ export interface FetchOptions {
10
+ method?: string;
11
+ headers?: HeadersInit | Headers;
12
+ body?: BodyInit | null;
13
+ signal?: AbortSignal | null;
14
+ redirect?: 'follow' | 'error' | 'manual';
15
+ }
16
+
17
+ export interface FetchResponse {
18
+ /** HTTP status code */
19
+ readonly status: number;
20
+
21
+ /** HTTP status text */
22
+ readonly statusText: string;
23
+
24
+ /** Whether the response was successful (status in 200-299) */
25
+ readonly ok: boolean;
26
+
27
+ /** Response headers */
28
+ readonly headers: Headers;
29
+
30
+ /** Whether the response body has been read */
31
+ readonly bodyUsed: boolean;
32
+
33
+ /** Response type */
34
+ readonly type: string;
35
+
36
+ /** Whether the response was redirected */
37
+ readonly redirected: boolean;
38
+
39
+ /** Response URL */
40
+ readonly url: string;
41
+
42
+ /** Parse response body as text */
43
+ text(): Promise<string>;
44
+
45
+ /** Parse response body as JSON */
46
+ json<T = any>(): Promise<T>;
47
+
48
+ /** Get response body as ArrayBuffer */
49
+ arrayBuffer(): Promise<ArrayBuffer>;
50
+
51
+ /** Get response body as Blob */
52
+ blob(): Promise<Blob>;
53
+
54
+ /** Get response body as FormData */
55
+ formData(): Promise<FormData>;
56
+
57
+ /** Get response body as ReadableStream */
58
+ readonly body: ReadableStream<Uint8Array> | null;
59
+ }
60
+
61
+ declare global {
62
+ /**
63
+ * Fetch API - Make HTTP requests
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const response = await fetch('https://api.example.com/data', {
68
+ * method: 'POST',
69
+ * headers: { 'Content-Type': 'application/json' },
70
+ * body: JSON.stringify({ key: 'value' })
71
+ * });
72
+ * const data = await response.json();
73
+ * ```
74
+ */
75
+ function fetch(url: RequestInfo | URL, options?: RequestInit): Promise<Response>;
76
+
77
+ }
78
+
79
+ export {};
80
+
81
+ export type BodyInit =
82
+ | string
83
+ | Blob
84
+ | ArrayBuffer
85
+ | ArrayBufferView
86
+ | FormData
87
+ | URLSearchParams
88
+ | ReadableStream<Uint8Array>;
89
+
90
+ export interface Body {
91
+ /** Consumes the body and returns a promise that resolves with a Blob */
92
+ blob(): Promise<Blob>;
93
+ /** Consumes the body and returns a promise that resolves with a FormData */
94
+ formData(): Promise<FormData>;
95
+ /** Consumes the body and returns a promise that resolves with the result of parsing the body text as JSON */
96
+ json<T = any>(): Promise<T>;
97
+ /** Consumes the body and returns a promise that resolves with the result of parsing the body text as a String */
98
+ text(): Promise<string>;
99
+ /** Consumes the body and returns a promise that resolves with an ArrayBuffer */
100
+ arrayBuffer(): Promise<ArrayBuffer>;
101
+ /** Returns a boolean indicating whether body has been consumed */
102
+ readonly bodyUsed: boolean;
103
+ /** The body content */
104
+ readonly body: ReadableStream<Uint8Array> | null;
105
+ }
106
+
107
+ export interface RequestInit {
108
+ method?: string;
109
+ headers?: HeadersInit | Headers;
110
+ body?: BodyInit | null;
111
+ redirect?: 'follow' | 'error' | 'manual';
112
+ signal?: AbortSignal | null;
113
+ }
114
+
115
+ export interface Request extends Body {
116
+ readonly method: string;
117
+ readonly headers: Headers;
118
+ readonly redirect: string;
119
+ readonly signal: AbortSignal | null;
120
+ readonly url: string;
121
+ clone(): Request;
122
+ }
123
+
124
+ export interface RequestConstructor {
125
+ new(input: RequestInfo | string, init?: RequestInit): Request;
126
+ prototype: Request;
127
+ }
128
+
129
+ export type RequestInfo = string | Request | URL;
130
+
131
+ export type HeadersInit = Record<string, string> | Array<[string, string]> | Headers;
132
+
133
+ export interface Headers {
134
+ append(name: string, value: string): void;
135
+ delete(name: string): void;
136
+ get(name: string): string | null;
137
+ has(name: string): boolean;
138
+ set(name: string, value: string): void;
139
+ forEach(callback: (value: string, name: string, self: Headers) => void, thisArg?: any): void;
140
+ entries(): IterableIterator<[string, string]>;
141
+ keys(): IterableIterator<string>;
142
+ values(): IterableIterator<string>;
143
+
144
+ /** Returns all Set-Cookie values (Rong extension) */
145
+ getSetCookie(): string[];
146
+ }
147
+
148
+ export interface HeadersConstructor {
149
+ new(init?: HeadersInit): Headers;
150
+ prototype: Headers;
151
+ }
package/src/index.ts ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Rong JavaScript Runtime Type Definitions
3
+ *
4
+ * This package provides TypeScript type definitions for all Rust-driven
5
+ * JavaScript APIs in the Rong runtime.
6
+ *
7
+ * ## Quick Start
8
+ *
9
+ * Add to your tsconfig.json:
10
+ * ```json
11
+ * {
12
+ * "compilerOptions": {
13
+ * "types": ["@lingxia/rong"]
14
+ * }
15
+ * }
16
+ * ```
17
+ *
18
+ * Then use the global APIs:
19
+ * ```typescript
20
+ * // File system
21
+ * const text = await Rong.readTextFile('/path/to/file.txt');
22
+ * await Rong.writeTextFile('/output.txt', 'Hello World');
23
+ *
24
+ * // Process
25
+ * console.log(process.pid);
26
+ * console.log(process.env.PATH);
27
+ *
28
+ * // HTTP
29
+ * const response = await fetch('https://api.example.com');
30
+ *
31
+ * // Child process
32
+ * const child = child_process.spawn('ls', ['-la']);
33
+ * ```
34
+ *
35
+ * For detailed API documentation, see individual module exports below.
36
+ */
37
+
38
+ // Global API declarations - Import this for full IDE autocomplete
39
+ import './global';
40
+
41
+ // Core runtime modules
42
+ export * from './process';
43
+ export * from './child_process';
44
+ export * from './stream';
45
+ export * from './encoding';
46
+ export * from './storage';
47
+ export * from './http';
48
+
49
+ // File system
50
+ export * from './fs';
51
+
52
+ // Web APIs
53
+ export * from './url';
54
+ export * from './buffer';
55
+ export * from './event';
56
+ export * from './abort';
57
+ export * from './exception';
58
+
59
+ // Utility modules
60
+ export * from './navigator';
61
+ export * from './timer';
62
+ export * from './path';
63
+ export * from './assert';
64
+ export * from './console';
65
+
66
+ // Error types
67
+ export * from './error';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Navigator module type definitions
3
+ * Corresponds to: modules/rong_navigator
4
+ */
5
+
6
+ // Extend the global Navigator interface with Rong-specific properties
7
+ declare global {
8
+ interface Navigator {
9
+ /** User agent string */
10
+ readonly userAgent: string;
11
+
12
+ /** Platform identifier (e.g., "macos", "linux", "windows") */
13
+ readonly platform: string;
14
+
15
+ /** CPU architecture (e.g., "x86_64", "aarch64") */
16
+ readonly arch: string;
17
+ }
18
+ }
19
+
20
+ export {};
package/src/path.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Path module type definitions
3
+ * Corresponds to: modules/rong_path
4
+ */
5
+
6
+ export interface ParsedPath {
7
+ /** Root directory (e.g., "/" on Unix, "C:\\" on Windows) */
8
+ root: string;
9
+ /** Directory path */
10
+ dir: string;
11
+ /** File name with extension */
12
+ base: string;
13
+ /** File extension (including the dot) */
14
+ ext: string;
15
+ /** File name without extension */
16
+ name: string;
17
+ }
18
+
19
+ export interface PathModule {
20
+ /**
21
+ * Returns the last portion of a path
22
+ * @param path - The path to process
23
+ * @param suffix - Optional suffix to remove from the result
24
+ */
25
+ basename(path: string, suffix?: string): string;
26
+
27
+ /**
28
+ * Returns the directory name of a path
29
+ * @param path - The path to process
30
+ */
31
+ dirname(path: string): string;
32
+
33
+ /**
34
+ * Returns the extension of a path (including the dot)
35
+ * @param path - The path to process
36
+ */
37
+ extname(path: string): string;
38
+
39
+ /**
40
+ * Determines whether a path is absolute
41
+ * @param path - The path to check
42
+ */
43
+ isAbsolute(path: string): boolean;
44
+
45
+ /**
46
+ * Joins path segments together
47
+ * @param paths - Path segments to join
48
+ */
49
+ join(...paths: string[]): string;
50
+
51
+ /**
52
+ * Normalizes a path by resolving '..' and '.' segments
53
+ * @param path - The path to normalize
54
+ */
55
+ normalize(path: string): string;
56
+
57
+ /**
58
+ * Resolves a sequence of paths to an absolute path
59
+ * @param paths - Paths to resolve
60
+ */
61
+ resolve(...paths: string[]): string;
62
+
63
+ /**
64
+ * Parses a path into an object
65
+ * @param path - The path to parse
66
+ */
67
+ parse(path: string): ParsedPath;
68
+
69
+ /**
70
+ * Formats a path object into a path string
71
+ * @param pathObject - Path object to format
72
+ */
73
+ format(pathObject: Partial<ParsedPath>): string;
74
+
75
+ /** Platform-specific path segment separator ("/" on Unix, "\\" on Windows) */
76
+ readonly sep: string;
77
+
78
+ /** Platform-specific PATH delimiter (":" on Unix, ";" on Windows) */
79
+ readonly delimiter: string;
80
+ }
81
+
82
+ // Note: path is declared as a global in global.d.ts
83
+ export {};
package/src/process.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Process module type definitions
3
+ * Corresponds to: modules/rong_process
4
+ */
5
+
6
+ import type { EventEmitter } from './event';
7
+
8
+ export interface ProcessEnv {
9
+ [key: string]: string | undefined;
10
+ }
11
+
12
+ export interface ProcessStdin extends ReadableStream<Uint8Array> {
13
+ readonly isTTY: boolean;
14
+ }
15
+
16
+ export interface ProcessStdout {
17
+ write(data: string): boolean;
18
+ readonly isTTY: boolean;
19
+ }
20
+
21
+ export interface ProcessStderr {
22
+ write(data: string): boolean;
23
+ readonly isTTY: boolean;
24
+ }
25
+
26
+ export interface Process extends EventEmitter {
27
+ /** Process ID */
28
+ readonly pid: number;
29
+
30
+ /** Current working directory */
31
+ cwd(): string;
32
+
33
+ /** Change working directory */
34
+ chdir(directory: string): void;
35
+
36
+ /** Environment variables */
37
+ readonly env: ProcessEnv;
38
+
39
+ /** Platform (e.g., 'darwin', 'linux', 'win32') */
40
+ readonly platform: string;
41
+
42
+ /** CPU architecture (e.g., 'x64', 'arm64') */
43
+ readonly arch: string;
44
+
45
+ /** Process version */
46
+ readonly version: string;
47
+
48
+ /** Command line arguments */
49
+ readonly argv: string[];
50
+
51
+ /** Exit the process */
52
+ exit(code?: number): never;
53
+
54
+ /** Process uptime in seconds */
55
+ uptime(): number;
56
+
57
+ /** High-resolution real time - returns [seconds, nanoseconds] since arbitrary point */
58
+ hrtime(prev?: [number, number]): [number, number];
59
+
60
+ /** Schedule callback for next tick (microtask) */
61
+ nextTick(callback: (...args: any[]) => void, ...args: any[]): void;
62
+
63
+ /** Standard input stream */
64
+ readonly stdin: ProcessStdin;
65
+
66
+ /** Standard output stream */
67
+ readonly stdout: ProcessStdout;
68
+
69
+ /** Standard error stream */
70
+ readonly stderr: ProcessStderr;
71
+ }
72
+
73
+ // Note: process is declared as a global in global.d.ts
74
+ export {};
package/src/storage.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Storage module type definitions
3
+ * Corresponds to: modules/rong_storage
4
+ *
5
+ * IMPORTANT: Storage is accessed via `Rong.storage.open(path)` or `new Rong.Storage(path)`
6
+ */
7
+
8
+ export interface StorageInfo {
9
+ /** Current storage size in bytes */
10
+ currentSize: number;
11
+ /** Size limit in bytes */
12
+ limitSize: number;
13
+ /** Number of keys */
14
+ keyCount: number;
15
+ }
16
+
17
+ export interface Storage {
18
+ /** Set a key-value pair */
19
+ set(key: string, value: any): Promise<void>;
20
+
21
+ /** Get value by key */
22
+ get(key: string): Promise<any>;
23
+
24
+ /** Delete a key */
25
+ delete(key: string): Promise<void>;
26
+
27
+ /** Clear all items */
28
+ clear(): Promise<void>;
29
+
30
+ /** Get all keys (returns async iterator) */
31
+ list(prefix?: string): Promise<IterableIterator<string>>;
32
+
33
+ /** Get storage info */
34
+ info(): Promise<StorageInfo>;
35
+ }
36
+
37
+ export interface StorageConstructor {
38
+ /** Create a new Storage instance for the given database path */
39
+ new(path: string, options?: StorageOptionsInput): Storage;
40
+ }
41
+
42
+ export interface StorageOptionsInput {
43
+ maxKeySize?: number;
44
+ maxValueSize?: number;
45
+ maxDataSize?: number;
46
+ }
47
+
48
+ export interface StorageModule {
49
+ /**
50
+ * Open a storage database at the given path
51
+ * @param path - Path to the database file
52
+ * @returns Storage instance
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const storage = Rong.storage.open('/path/to/db.sqlite');
57
+ * await storage.set('key', 'value');
58
+ * ```
59
+ */
60
+ open(path: string, options?: StorageOptionsInput): Promise<Storage>;
61
+ }
62
+
63
+ // Note: Storage is accessed via Rong.storage.open() or new Rong.Storage()
64
+ export {};
package/src/stream.ts ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Stream module type definitions
3
+ * Corresponds to: modules/rong_stream
4
+ *
5
+ * Rong runtime provides the Web Streams API, which is a standard for handling
6
+ * streaming data in JavaScript. These APIs are globally available.
7
+ *
8
+ * ## Available Stream Types
9
+ *
10
+ * ### ReadableStream<T>
11
+ * Represents a readable stream of data.
12
+ *
13
+ * Usage:
14
+ * ```typescript
15
+ * // From file
16
+ * const file = await Rong.open('/path/to/file.txt', { read: true });
17
+ * const readable = file.readable;
18
+ *
19
+ * // Read from stream
20
+ * const reader = readable.getReader();
21
+ * while (true) {
22
+ * const { done, value } = await reader.read();
23
+ * if (done) break;
24
+ * console.log('Received:', value);
25
+ * }
26
+ * ```
27
+ *
28
+ * ### WritableStream<T>
29
+ * Represents a writable stream of data.
30
+ *
31
+ * Usage:
32
+ * ```typescript
33
+ * // To file
34
+ * const file = await Rong.open('/path/to/output.txt', { write: true, create: true });
35
+ * const writable = file.writable;
36
+ *
37
+ * // Write to stream
38
+ * const writer = writable.getWriter();
39
+ * await writer.write(new TextEncoder().encode('Hello World'));
40
+ * await writer.close();
41
+ * ```
42
+ *
43
+ * ### TransformStream<I, O>
44
+ * Represents a transform stream for processing data.
45
+ *
46
+ * Usage:
47
+ * ```typescript
48
+ * // Pipe with transformation
49
+ * await readable
50
+ * .pipeThrough(new TransformStream({
51
+ * transform(chunk, controller) {
52
+ * // Process chunk
53
+ * controller.enqueue(processedChunk);
54
+ * }
55
+ * }))
56
+ * .pipeTo(writable);
57
+ * ```
58
+ *
59
+ * ## Common Use Cases
60
+ *
61
+ * ### Pipe streams
62
+ * ```typescript
63
+ * // Pipe stdin to stdout
64
+ * await process.stdin.pipeTo(process.stdout);
65
+ *
66
+ * // Pipe file to file
67
+ * const source = await Rong.open('/source.txt', { read: true });
68
+ * const dest = await Rong.open('/dest.txt', { write: true, create: true });
69
+ * await source.readable.pipeTo(dest.writable);
70
+ * ```
71
+ *
72
+ * ### Process data in chunks
73
+ * ```typescript
74
+ * const file = await Rong.open('/large-file.txt', { read: true });
75
+ * const reader = file.readable.getReader();
76
+ *
77
+ * let totalBytes = 0;
78
+ * while (true) {
79
+ * const { done, value } = await reader.read();
80
+ * if (done) break;
81
+ * totalBytes += value.byteLength;
82
+ * // Process chunk...
83
+ * }
84
+ * console.log(`Processed ${totalBytes} bytes`);
85
+ * ```
86
+ *
87
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
88
+ */
89
+
90
+ // Stream types are provided globally by the DOM library
91
+ // When you include "DOM" in tsconfig.json lib array, these types are available:
92
+ // - ReadableStream<T>
93
+ // - WritableStream<T>
94
+ // - TransformStream<I, O>
95
+ // - ReadableStreamDefaultReader<T>
96
+ // - WritableStreamDefaultWriter<T>
97
+
98
+ export {};
package/src/timer.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Timer module type definitions
3
+ * Corresponds to: modules/rong_timer
4
+ */
5
+
6
+ export type TimerCallback = () => void;
7
+ export type TimerId = number;
8
+
9
+ export interface TimersNamespace {
10
+ /**
11
+ * Promise-based timeout that resolves with a timestamp (ms since epoch).
12
+ */
13
+ setTimeout(delay?: number): Promise<number>;
14
+
15
+ /**
16
+ * Promise-based immediate that resolves with a timestamp (ms since epoch).
17
+ */
18
+ setImmediate(): Promise<number>;
19
+
20
+ /**
21
+ * Async iterator that yields timestamps (ms since epoch) on each interval tick.
22
+ */
23
+ setInterval(delay?: number): AsyncIterableIterator<number>;
24
+ }
25
+
26
+ declare global {
27
+ /**
28
+ * Set a timer that executes a callback once after a delay
29
+ * @param callback - Function to execute
30
+ * @param delay - Delay in milliseconds (default: 0)
31
+ * @returns Timer ID that can be used with clearTimeout
32
+ */
33
+ function setTimeout(callback: TimerCallback, delay?: number): TimerId;
34
+
35
+ /**
36
+ * Clear a timer set with setTimeout
37
+ * @param id - Timer ID returned by setTimeout
38
+ */
39
+ function clearTimeout(id: TimerId): void;
40
+
41
+ /**
42
+ * Set a timer that executes a callback repeatedly with a delay between executions
43
+ * @param callback - Function to execute
44
+ * @param delay - Delay in milliseconds between executions (default: 0)
45
+ * @returns Timer ID that can be used with clearInterval
46
+ */
47
+ function setInterval(callback: TimerCallback, delay?: number): TimerId;
48
+
49
+ /**
50
+ * Clear a timer set with setInterval
51
+ * @param id - Timer ID returned by setInterval
52
+ */
53
+ function clearInterval(id: TimerId): void;
54
+
55
+ /**
56
+ * Promise-based timer namespace
57
+ */
58
+ const timers: TimersNamespace;
59
+ }
60
+
61
+ export {};