@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.
Files changed (2) hide show
  1. package/README.md +43 -33
  2. 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
- - **RXC** (Content) - Stream-based content
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
- ### RXC - Resource Content
77
+ ### RXA - Resource Archive
77
78
 
78
- Archive-based content (internally tar.gz), supports single or multi-file resources:
79
+ Archive container (tar.gz) for storage/transfer. Extract to RXP for file access:
79
80
 
80
81
  ```typescript
81
- import { createRXC } from "@resourcexjs/core";
82
+ import { createRXA } from "@resourcexjs/core";
82
83
 
83
84
  // Single file
84
- const content = await createRXC({ content: "Hello, World!" });
85
+ const content = await createRXA({ content: "Hello, World!" });
85
86
 
86
87
  // Multiple files
87
- const content = await createRXC({
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 createRXC({
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 archive (for deserialization)
99
- const content = await createRXC({ archive: tarGzBuffer });
99
+ // From existing tar.gz buffer (for deserialization)
100
+ const content = await createRXA({ buffer: tarGzBuffer });
100
101
 
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>
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
- content: RXC;
125
+ archive: RXA;
120
126
  }
121
127
 
122
128
  // Create from literals
123
- const rxr: RXR = { locator, manifest, content };
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 content.text();
151
- await content.text(); // Second consumption
156
+ const pkg = await archive.extract();
157
+ await pkg.file("nonexistent");
152
158
  } catch (error) {
153
159
  if (error instanceof ContentError) {
154
- console.error("Content already consumed");
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, createRXC } from "@resourcexjs/core";
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 content (single file)
188
- const content = await createRXC({ content: "You are a helpful assistant." });
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
- content,
200
+ archive,
195
201
  };
196
202
  ```
197
203
 
198
204
  ### Multi-file Resource
199
205
 
200
206
  ```typescript
201
- import { createRXC } from "@resourcexjs/core";
207
+ import { createRXA } from "@resourcexjs/core";
202
208
 
203
- // Create multi-file content
204
- const content = await createRXC({
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 content.file("prompt.md");
211
- const configBuffer = await content.file("config.json");
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 content.files();
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, RXC, RXR } from "@resourcexjs/core";
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 content: RXC = createRXC("...");
265
- const resource: RXR = { locator, manifest, content };
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resourcexjs/core",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "description": "ResourceX Core - Resource management layer",
5
5
  "keywords": [
6
6
  "resourcex",