@resourcexjs/core 1.0.0 → 1.1.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.
- package/README.md +43 -33
- package/dist/index.d.ts +16 -14
- package/dist/index.js +1023 -56
- package/dist/index.js.map +6 -5
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -75,33 +75,35 @@ manifest.toJSON(); // → plain object
|
|
|
75
75
|
|
|
76
76
|
### RXC - Resource Content
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
Archive-based content (internally tar.gz), supports single or multi-file resources:
|
|
79
79
|
|
|
80
80
|
```typescript
|
|
81
|
-
import { createRXC
|
|
82
|
-
|
|
83
|
-
// Create from memory
|
|
84
|
-
const content = createRXC("Hello, World!");
|
|
85
|
-
const content = createRXC(Buffer.from([1, 2, 3]));
|
|
86
|
-
const content = createRXC(readableStream);
|
|
87
|
-
|
|
88
|
-
// Load from file or URL (async)
|
|
89
|
-
const content = await loadRXC("./file.txt");
|
|
90
|
-
const content = await loadRXC("https://example.com/data.txt");
|
|
91
|
-
|
|
92
|
-
// Consume (choose one, can only use once)
|
|
93
|
-
const text = await content.text(); // → string
|
|
94
|
-
const buffer = await content.buffer(); // → Buffer
|
|
95
|
-
const json = await content.json<T>(); // → T
|
|
96
|
-
const stream = content.stream; // → ReadableStream<Uint8Array>
|
|
97
|
-
```
|
|
81
|
+
import { createRXC } from "@resourcexjs/core";
|
|
98
82
|
|
|
99
|
-
|
|
83
|
+
// Single file
|
|
84
|
+
const content = await createRXC({ content: "Hello, World!" });
|
|
100
85
|
|
|
101
|
-
|
|
102
|
-
const content = createRXC(
|
|
103
|
-
|
|
104
|
-
|
|
86
|
+
// Multiple files
|
|
87
|
+
const content = await createRXC({
|
|
88
|
+
"index.ts": "export default 1",
|
|
89
|
+
"styles.css": "body {}",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Nested directories
|
|
93
|
+
const content = await createRXC({
|
|
94
|
+
"src/index.ts": "main code",
|
|
95
|
+
"src/utils/helper.ts": "helper code",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// From existing tar.gz archive (for deserialization)
|
|
99
|
+
const content = await createRXC({ archive: tarGzBuffer });
|
|
100
|
+
|
|
101
|
+
// Read files
|
|
102
|
+
const buffer = await content.file("content"); // → Buffer
|
|
103
|
+
const buffer = await content.file("src/index.ts"); // → Buffer
|
|
104
|
+
const files = await content.files(); // → Map<string, Buffer>
|
|
105
|
+
const archiveBuffer = await content.buffer(); // → raw tar.gz Buffer
|
|
106
|
+
const stream = content.stream; // → ReadableStream (tar.gz)
|
|
105
107
|
```
|
|
106
108
|
|
|
107
109
|
### RXR - Resource
|
|
@@ -182,8 +184,8 @@ const manifest = createRXM({
|
|
|
182
184
|
// Create locator from manifest
|
|
183
185
|
const locator = parseRXL(manifest.toLocator());
|
|
184
186
|
|
|
185
|
-
// Create content
|
|
186
|
-
const content = createRXC("You are a helpful assistant.");
|
|
187
|
+
// Create content (single file)
|
|
188
|
+
const content = await createRXC({ content: "You are a helpful assistant." });
|
|
187
189
|
|
|
188
190
|
// Assemble RXR
|
|
189
191
|
const rxr: RXR = {
|
|
@@ -193,18 +195,26 @@ const rxr: RXR = {
|
|
|
193
195
|
};
|
|
194
196
|
```
|
|
195
197
|
|
|
196
|
-
###
|
|
198
|
+
### Multi-file Resource
|
|
197
199
|
|
|
198
200
|
```typescript
|
|
199
|
-
import {
|
|
201
|
+
import { createRXC } from "@resourcexjs/core";
|
|
200
202
|
|
|
201
|
-
//
|
|
202
|
-
const content = await
|
|
203
|
-
|
|
203
|
+
// Create multi-file content
|
|
204
|
+
const content = await createRXC({
|
|
205
|
+
"prompt.md": "# System Prompt\nYou are...",
|
|
206
|
+
"config.json": '{"temperature": 0.7}',
|
|
207
|
+
});
|
|
204
208
|
|
|
205
|
-
//
|
|
206
|
-
const
|
|
207
|
-
const
|
|
209
|
+
// Read individual files
|
|
210
|
+
const promptBuffer = await content.file("prompt.md");
|
|
211
|
+
const configBuffer = await content.file("config.json");
|
|
212
|
+
|
|
213
|
+
// Read all files
|
|
214
|
+
const allFiles = await content.files();
|
|
215
|
+
for (const [path, buffer] of allFiles) {
|
|
216
|
+
console.log(path, buffer.toString());
|
|
217
|
+
}
|
|
208
218
|
```
|
|
209
219
|
|
|
210
220
|
### Manifest Serialization
|
package/dist/index.d.ts
CHANGED
|
@@ -59,26 +59,28 @@ declare function createRXM(data: ManifestData): RXM;
|
|
|
59
59
|
/**
|
|
60
60
|
* RXC - ResourceX Content
|
|
61
61
|
*
|
|
62
|
-
*
|
|
62
|
+
* Archive-based content container using tar.gz format internally.
|
|
63
|
+
* Provides unified file access API for both single and multi-file resources.
|
|
63
64
|
*/
|
|
64
65
|
interface RXC {
|
|
65
|
-
/** Content as a readable stream */
|
|
66
|
+
/** Content as a readable stream (tar.gz format) */
|
|
66
67
|
readonly stream: ReadableStream<Uint8Array>;
|
|
67
|
-
/**
|
|
68
|
-
text(): Promise<string>;
|
|
69
|
-
/** Read content as Buffer */
|
|
68
|
+
/** Get raw archive buffer (tar.gz format) */
|
|
70
69
|
buffer(): Promise<Buffer>;
|
|
71
|
-
/** Read
|
|
72
|
-
|
|
70
|
+
/** Read a specific file from the archive */
|
|
71
|
+
file(path: string): Promise<Buffer>;
|
|
72
|
+
/** Read all files from the archive */
|
|
73
|
+
files(): Promise<Map<string, Buffer>>;
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
|
-
*
|
|
76
|
+
* Input type for createRXC.
|
|
77
|
+
* - Files record: { 'path/to/file': content }
|
|
78
|
+
* - Archive: { archive: tarGzBuffer }
|
|
76
79
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
declare function loadRXC(source: string): Promise<RXC>;
|
|
80
|
+
type RXCInput = Record<string, Buffer | Uint8Array | string> | {
|
|
81
|
+
archive: Buffer
|
|
82
|
+
};
|
|
83
|
+
declare function createRXC(input: RXCInput): Promise<RXC>;
|
|
82
84
|
/**
|
|
83
85
|
* RXR (ResourceX Resource) - Complete resource object.
|
|
84
86
|
* A pure data transfer object combining locator, manifest, and content.
|
|
@@ -88,4 +90,4 @@ interface RXR {
|
|
|
88
90
|
manifest: RXM;
|
|
89
91
|
content: RXC;
|
|
90
92
|
}
|
|
91
|
-
export { parseRXL,
|
|
93
|
+
export { parseRXL, createRXM, createRXC, ResourceXError, RXR, RXM, RXL, RXCInput, RXC, ManifestError, ManifestData, LocatorError, ContentError };
|