@resourcexjs/core 2.3.0 → 2.4.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.
- package/README.md +43 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,8 @@ Core building blocks - pure data structures:
|
|
|
18
18
|
|
|
19
19
|
- **RXL** (Locator) - Resource locator string parser
|
|
20
20
|
- **RXM** (Manifest) - Resource metadata
|
|
21
|
-
- **
|
|
21
|
+
- **RXA** (Archive) - Archive container for storage/transfer
|
|
22
|
+
- **RXP** (Package) - Extracted files for runtime access
|
|
22
23
|
- **RXR** (Resource) - Complete resource type
|
|
23
24
|
- **Errors** - Error hierarchy
|
|
24
25
|
|
|
@@ -73,35 +74,40 @@ manifest.toJSON(); // → plain object
|
|
|
73
74
|
|
|
74
75
|
**Optional fields**: `domain` (default: "localhost"), `path`, `description`, `tags`
|
|
75
76
|
|
|
76
|
-
###
|
|
77
|
+
### RXA - Resource Archive
|
|
77
78
|
|
|
78
|
-
Archive
|
|
79
|
+
Archive container (tar.gz) for storage/transfer. Extract to RXP for file access:
|
|
79
80
|
|
|
80
81
|
```typescript
|
|
81
|
-
import {
|
|
82
|
+
import { createRXA } from "@resourcexjs/core";
|
|
82
83
|
|
|
83
84
|
// Single file
|
|
84
|
-
const content = await
|
|
85
|
+
const content = await createRXA({ content: "Hello, World!" });
|
|
85
86
|
|
|
86
87
|
// Multiple files
|
|
87
|
-
const content = await
|
|
88
|
+
const content = await createRXA({
|
|
88
89
|
"index.ts": "export default 1",
|
|
89
90
|
"styles.css": "body {}",
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
// Nested directories
|
|
93
|
-
const content = await
|
|
94
|
+
const content = await createRXA({
|
|
94
95
|
"src/index.ts": "main code",
|
|
95
96
|
"src/utils/helper.ts": "helper code",
|
|
96
97
|
});
|
|
97
98
|
|
|
98
|
-
// From existing tar.gz
|
|
99
|
-
const content = await
|
|
99
|
+
// From existing tar.gz buffer (for deserialization)
|
|
100
|
+
const content = await createRXA({ buffer: tarGzBuffer });
|
|
100
101
|
|
|
101
|
-
//
|
|
102
|
-
const
|
|
103
|
-
const buffer = await
|
|
104
|
-
const
|
|
102
|
+
// Extract to package for file access
|
|
103
|
+
const pkg = await content.extract();
|
|
104
|
+
const buffer = await pkg.file("content"); // → Buffer
|
|
105
|
+
const buffer = await pkg.file("src/index.ts"); // → Buffer
|
|
106
|
+
const files = await pkg.files(); // → Map<string, Buffer>
|
|
107
|
+
const paths = pkg.paths(); // → string[]
|
|
108
|
+
const tree = pkg.tree(); // → PathNode[]
|
|
109
|
+
|
|
110
|
+
// Archive methods
|
|
105
111
|
const archiveBuffer = await content.buffer(); // → raw tar.gz Buffer
|
|
106
112
|
const stream = content.stream; // → ReadableStream (tar.gz)
|
|
107
113
|
```
|
|
@@ -116,11 +122,11 @@ import type { RXR } from "@resourcexjs/core";
|
|
|
116
122
|
interface RXR {
|
|
117
123
|
locator: RXL;
|
|
118
124
|
manifest: RXM;
|
|
119
|
-
|
|
125
|
+
archive: RXA;
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
// Create from literals
|
|
123
|
-
const rxr: RXR = { locator, manifest,
|
|
129
|
+
const rxr: RXR = { locator, manifest, archive };
|
|
124
130
|
```
|
|
125
131
|
|
|
126
132
|
RXR is a pure DTO (Data Transfer Object) - no factory function needed.
|
|
@@ -147,11 +153,11 @@ try {
|
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
try {
|
|
150
|
-
await
|
|
151
|
-
await
|
|
156
|
+
const pkg = await archive.extract();
|
|
157
|
+
await pkg.file("nonexistent");
|
|
152
158
|
} catch (error) {
|
|
153
159
|
if (error instanceof ContentError) {
|
|
154
|
-
console.error("
|
|
160
|
+
console.error("File not found in archive");
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
```
|
|
@@ -170,7 +176,7 @@ ResourceXError (base)
|
|
|
170
176
|
### Complete Resource Creation
|
|
171
177
|
|
|
172
178
|
```typescript
|
|
173
|
-
import { parseRXL, createRXM,
|
|
179
|
+
import { parseRXL, createRXM, createRXA } from "@resourcexjs/core";
|
|
174
180
|
import type { RXR } from "@resourcexjs/core";
|
|
175
181
|
|
|
176
182
|
// Create manifest
|
|
@@ -184,34 +190,37 @@ const manifest = createRXM({
|
|
|
184
190
|
// Create locator from manifest
|
|
185
191
|
const locator = parseRXL(manifest.toLocator());
|
|
186
192
|
|
|
187
|
-
// Create
|
|
188
|
-
const
|
|
193
|
+
// Create archive (single file)
|
|
194
|
+
const archive = await createRXA({ content: "You are a helpful assistant." });
|
|
189
195
|
|
|
190
196
|
// Assemble RXR
|
|
191
197
|
const rxr: RXR = {
|
|
192
198
|
locator,
|
|
193
199
|
manifest,
|
|
194
|
-
|
|
200
|
+
archive,
|
|
195
201
|
};
|
|
196
202
|
```
|
|
197
203
|
|
|
198
204
|
### Multi-file Resource
|
|
199
205
|
|
|
200
206
|
```typescript
|
|
201
|
-
import {
|
|
207
|
+
import { createRXA } from "@resourcexjs/core";
|
|
202
208
|
|
|
203
|
-
// Create multi-file
|
|
204
|
-
const
|
|
209
|
+
// Create multi-file archive
|
|
210
|
+
const archive = await createRXA({
|
|
205
211
|
"prompt.md": "# System Prompt\nYou are...",
|
|
206
212
|
"config.json": '{"temperature": 0.7}',
|
|
207
213
|
});
|
|
208
214
|
|
|
215
|
+
// Extract to package for file access
|
|
216
|
+
const pkg = await archive.extract();
|
|
217
|
+
|
|
209
218
|
// Read individual files
|
|
210
|
-
const promptBuffer = await
|
|
211
|
-
const configBuffer = await
|
|
219
|
+
const promptBuffer = await pkg.file("prompt.md");
|
|
220
|
+
const configBuffer = await pkg.file("config.json");
|
|
212
221
|
|
|
213
222
|
// Read all files
|
|
214
|
-
const allFiles = await
|
|
223
|
+
const allFiles = await pkg.files();
|
|
215
224
|
for (const [path, buffer] of allFiles) {
|
|
216
225
|
console.log(path, buffer.toString());
|
|
217
226
|
}
|
|
@@ -257,12 +266,13 @@ This package provides only data structures. For full functionality:
|
|
|
257
266
|
All types are fully typed with TypeScript:
|
|
258
267
|
|
|
259
268
|
```typescript
|
|
260
|
-
import type { RXL, RXM,
|
|
269
|
+
import type { RXL, RXM, RXA, RXP, RXR } from "@resourcexjs/core";
|
|
270
|
+
import { parseRXL, createRXM, createRXA } from "@resourcexjs/core";
|
|
261
271
|
|
|
262
|
-
const locator: RXL = parseRXL("
|
|
263
|
-
const manifest: RXM = createRXM({
|
|
264
|
-
const
|
|
265
|
-
const resource: RXR = { locator, manifest,
|
|
272
|
+
const locator: RXL = parseRXL("localhost/test.text@1.0.0");
|
|
273
|
+
const manifest: RXM = createRXM({ name: "test", type: "text", version: "1.0.0" });
|
|
274
|
+
const archive: RXA = await createRXA({ content: "Hello" });
|
|
275
|
+
const resource: RXR = { locator, manifest, archive };
|
|
266
276
|
```
|
|
267
277
|
|
|
268
278
|
## License
|