@resourcexjs/core 0.4.0 → 0.7.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 +194 -120
- package/dist/index.d.ts +139 -275
- package/dist/index.js +347 -462
- package/dist/index.js.map +11 -15
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,349 +1,213 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ResourceX Error
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Base error class for all ResourceX errors
|
|
2
|
+
* ResourceX Error hierarchy
|
|
6
3
|
*/
|
|
7
4
|
declare class ResourceXError extends Error {
|
|
8
5
|
constructor(message: string, options?: ErrorOptions);
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
declare class ParseError extends ResourceXError {
|
|
14
|
-
readonly url?: string;
|
|
15
|
-
constructor(message: string, url?: string);
|
|
7
|
+
declare class LocatorError extends ResourceXError {
|
|
8
|
+
readonly locator?: string;
|
|
9
|
+
constructor(message: string, locator?: string);
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
declare class TransportError extends ResourceXError {
|
|
21
|
-
readonly transport?: string;
|
|
22
|
-
constructor(message: string, transport?: string, options?: ErrorOptions);
|
|
11
|
+
declare class ManifestError extends ResourceXError {
|
|
12
|
+
constructor(message: string);
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
declare class SemanticError extends ResourceXError {
|
|
28
|
-
readonly semantic?: string;
|
|
29
|
-
constructor(message: string, semantic?: string, options?: ErrorOptions);
|
|
14
|
+
declare class ContentError extends ResourceXError {
|
|
15
|
+
constructor(message: string);
|
|
30
16
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
transport: string;
|
|
34
|
-
location: string;
|
|
17
|
+
declare class ResourceTypeError extends ResourceXError {
|
|
18
|
+
constructor(message: string);
|
|
35
19
|
}
|
|
36
20
|
/**
|
|
37
|
-
*
|
|
21
|
+
* RXL - ResourceX Locator
|
|
38
22
|
*
|
|
39
|
-
* @
|
|
40
|
-
* parseARP("arp:text:https://example.com/file.txt")
|
|
41
|
-
* // { semantic: "text", transport: "https", location: "example.com/file.txt" }
|
|
42
|
-
*/
|
|
43
|
-
declare function parseARP(url: string): ParsedARP;
|
|
44
|
-
/**
|
|
45
|
-
* Transport Handler Interface
|
|
46
|
-
* Responsible for I/O primitives - read, write, list, exists, delete
|
|
47
|
-
* Transport only handles WHERE and HOW to access bytes, not WHAT they mean
|
|
48
|
-
*/
|
|
49
|
-
/**
|
|
50
|
-
* Transport capabilities declaration
|
|
23
|
+
* Format: [domain/path/]name[.type][@version]
|
|
51
24
|
*/
|
|
52
|
-
interface
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
55
|
-
readonly
|
|
56
|
-
readonly
|
|
57
|
-
readonly
|
|
25
|
+
interface RXL {
|
|
26
|
+
readonly domain?: string;
|
|
27
|
+
readonly path?: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly type?: string;
|
|
30
|
+
readonly version?: string;
|
|
31
|
+
toString(): string;
|
|
58
32
|
}
|
|
59
33
|
/**
|
|
60
|
-
*
|
|
34
|
+
* Parse a resource locator string into RXL object.
|
|
35
|
+
*
|
|
36
|
+
* Format: [domain/path/]name[.type][@version]
|
|
61
37
|
*/
|
|
62
|
-
|
|
63
|
-
size: number;
|
|
64
|
-
modifiedAt?: Date;
|
|
65
|
-
isDirectory?: boolean;
|
|
66
|
-
}
|
|
38
|
+
declare function parseRXL(locator: string): RXL;
|
|
67
39
|
/**
|
|
68
|
-
*
|
|
40
|
+
* RXM - ResourceX Manifest
|
|
69
41
|
*/
|
|
70
|
-
interface
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
readonly name: string;
|
|
75
|
-
/**
|
|
76
|
-
* Transport capabilities
|
|
77
|
-
*/
|
|
78
|
-
readonly capabilities: TransportCapabilities;
|
|
79
|
-
/**
|
|
80
|
-
* Read content from location
|
|
81
|
-
* @param location - The location string after ://
|
|
82
|
-
* @returns Raw content as Buffer
|
|
83
|
-
*/
|
|
84
|
-
read(location: string): Promise<Buffer>;
|
|
85
|
-
/**
|
|
86
|
-
* Write content to location
|
|
87
|
-
* @param location - The location string after ://
|
|
88
|
-
* @param content - Content to write
|
|
89
|
-
*/
|
|
90
|
-
write?(location: string, content: Buffer): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* List entries at location (for directory-like transports)
|
|
93
|
-
* @param location - The location string after ://
|
|
94
|
-
* @returns Array of entry names
|
|
95
|
-
*/
|
|
96
|
-
list?(location: string): Promise<string[]>;
|
|
97
|
-
/**
|
|
98
|
-
* Create directory at location
|
|
99
|
-
* @param location - The location string after ://
|
|
100
|
-
*/
|
|
101
|
-
mkdir?(location: string): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Check if resource exists at location
|
|
104
|
-
* @param location - The location string after ://
|
|
105
|
-
*/
|
|
106
|
-
exists?(location: string): Promise<boolean>;
|
|
107
|
-
/**
|
|
108
|
-
* Get resource stat information
|
|
109
|
-
* @param location - The location string after ://
|
|
110
|
-
*/
|
|
111
|
-
stat?(location: string): Promise<ResourceStat>;
|
|
112
|
-
/**
|
|
113
|
-
* Delete resource at location
|
|
114
|
-
* @param location - The location string after ://
|
|
115
|
-
*/
|
|
116
|
-
delete?(location: string): Promise<void>;
|
|
117
|
-
}
|
|
118
|
-
declare class HttpTransportHandler implements TransportHandler {
|
|
42
|
+
interface RXM {
|
|
43
|
+
readonly domain: string;
|
|
44
|
+
readonly path?: string;
|
|
119
45
|
readonly name: string;
|
|
120
|
-
|
|
121
|
-
readonly
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
declare const httpsHandler: HttpTransportHandler;
|
|
126
|
-
declare const httpHandler: HttpTransportHandler;
|
|
127
|
-
declare class FileTransportHandler implements TransportHandler {
|
|
128
|
-
readonly name = "file";
|
|
129
|
-
readonly capabilities: TransportCapabilities;
|
|
130
|
-
private resolvePath;
|
|
131
|
-
read(location: string): Promise<Buffer>;
|
|
132
|
-
write(location: string, content: Buffer): Promise<void>;
|
|
133
|
-
list(location: string): Promise<string[]>;
|
|
134
|
-
mkdir(location: string): Promise<void>;
|
|
135
|
-
exists(location: string): Promise<boolean>;
|
|
136
|
-
stat(location: string): Promise<ResourceStat>;
|
|
137
|
-
delete(location: string): Promise<void>;
|
|
46
|
+
readonly type: string;
|
|
47
|
+
readonly version: string;
|
|
48
|
+
toLocator(): string;
|
|
49
|
+
toJSON(): ManifestData;
|
|
138
50
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
parentDir?: string;
|
|
51
|
+
interface ManifestData {
|
|
52
|
+
domain?: string;
|
|
53
|
+
path?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
type?: string;
|
|
56
|
+
version?: string;
|
|
146
57
|
}
|
|
147
58
|
/**
|
|
148
|
-
* Create
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
*
|
|
153
|
-
* const handler = deepracticeHandler();
|
|
154
|
-
* // → ~/.deepractice/
|
|
59
|
+
* Create a manifest from data object.
|
|
60
|
+
*/
|
|
61
|
+
declare function createRXM(data: ManifestData): RXM;
|
|
62
|
+
/**
|
|
63
|
+
* RXC - ResourceX Content
|
|
155
64
|
*
|
|
156
|
-
*
|
|
157
|
-
* // → /var/data/.deepractice/
|
|
158
|
-
* ```
|
|
65
|
+
* Represents resource content as a stream.
|
|
159
66
|
*/
|
|
160
|
-
|
|
67
|
+
interface RXC {
|
|
68
|
+
/** Content as a readable stream */
|
|
69
|
+
readonly stream: ReadableStream<Uint8Array>;
|
|
70
|
+
/** Read content as text */
|
|
71
|
+
text(): Promise<string>;
|
|
72
|
+
/** Read content as Buffer */
|
|
73
|
+
buffer(): Promise<Buffer>;
|
|
74
|
+
/** Read content as JSON */
|
|
75
|
+
json<T>(): Promise<T>;
|
|
76
|
+
}
|
|
161
77
|
/**
|
|
162
|
-
*
|
|
78
|
+
* Create RXC from string, Buffer, or ReadableStream.
|
|
163
79
|
*/
|
|
164
|
-
declare function
|
|
80
|
+
declare function createRXC(data: string | Buffer | ReadableStream<Uint8Array>): RXC;
|
|
165
81
|
/**
|
|
166
|
-
*
|
|
82
|
+
* Load RXC from file path or URL.
|
|
167
83
|
*/
|
|
168
|
-
declare function
|
|
84
|
+
declare function loadRXC(source: string): Promise<RXC>;
|
|
169
85
|
/**
|
|
170
|
-
* Resource
|
|
86
|
+
* RXR (ResourceX Resource) - Complete resource object.
|
|
87
|
+
* A pure data transfer object combining locator, manifest, and content.
|
|
171
88
|
*/
|
|
172
|
-
interface
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
location: string;
|
|
177
|
-
size: number;
|
|
178
|
-
encoding?: string;
|
|
179
|
-
mimeType?: string;
|
|
180
|
-
resolvedAt: string;
|
|
89
|
+
interface RXR {
|
|
90
|
+
locator: RXL;
|
|
91
|
+
manifest: RXM;
|
|
92
|
+
content: RXC;
|
|
181
93
|
}
|
|
182
94
|
/**
|
|
183
|
-
*
|
|
95
|
+
* ResourceSerializer - Handles RXR serialization/deserialization for storage.
|
|
184
96
|
*/
|
|
185
|
-
interface
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
97
|
+
interface ResourceSerializer {
|
|
98
|
+
/**
|
|
99
|
+
* Serialize RXR to storage format.
|
|
100
|
+
*/
|
|
101
|
+
serialize(rxr: RXR): Promise<Buffer>;
|
|
102
|
+
/**
|
|
103
|
+
* Deserialize storage data to RXR.
|
|
104
|
+
*/
|
|
105
|
+
deserialize(data: Buffer, manifest: RXM): Promise<RXR>;
|
|
191
106
|
}
|
|
192
107
|
/**
|
|
193
|
-
*
|
|
108
|
+
* ResourceResolver - Transforms RXR into usable object.
|
|
194
109
|
*/
|
|
195
|
-
interface
|
|
196
|
-
|
|
197
|
-
content
|
|
198
|
-
|
|
110
|
+
interface ResourceResolver<T = unknown> {
|
|
111
|
+
/**
|
|
112
|
+
* Resolve RXR content into a usable object.
|
|
113
|
+
*/
|
|
114
|
+
resolve(rxr: RXR): Promise<T>;
|
|
199
115
|
}
|
|
200
116
|
/**
|
|
201
|
-
*
|
|
202
|
-
* Semantic orchestrates Transport primitives to resolve/deposit resources
|
|
117
|
+
* ResourceType - Defines how a resource type is handled.
|
|
203
118
|
*/
|
|
204
|
-
interface
|
|
119
|
+
interface ResourceType<T = unknown> {
|
|
205
120
|
/**
|
|
206
|
-
*
|
|
121
|
+
* Type name (e.g., "text", "json", "binary").
|
|
207
122
|
*/
|
|
208
|
-
|
|
123
|
+
name: string;
|
|
209
124
|
/**
|
|
210
|
-
*
|
|
211
|
-
* Semantic controls how to use transport primitives to fetch and parse resource
|
|
212
|
-
*
|
|
213
|
-
* @param transport - Transport handler for I/O operations
|
|
214
|
-
* @param location - Resource location
|
|
215
|
-
* @param context - Semantic context
|
|
125
|
+
* Alternative names for this type (e.g., ["txt", "plaintext"]).
|
|
216
126
|
*/
|
|
217
|
-
|
|
127
|
+
aliases?: string[];
|
|
218
128
|
/**
|
|
219
|
-
*
|
|
220
|
-
* Semantic controls how to serialize data and use transport primitives to store
|
|
221
|
-
*
|
|
222
|
-
* @param transport - Transport handler for I/O operations
|
|
223
|
-
* @param location - Resource location
|
|
224
|
-
* @param data - Data to deposit
|
|
225
|
-
* @param context - Semantic context
|
|
129
|
+
* Human-readable description.
|
|
226
130
|
*/
|
|
227
|
-
|
|
131
|
+
description: string;
|
|
228
132
|
/**
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* @param transport - Transport handler for I/O operations
|
|
232
|
-
* @param location - Resource location
|
|
233
|
-
* @param context - Semantic context
|
|
133
|
+
* Serializer for storage operations.
|
|
234
134
|
*/
|
|
235
|
-
|
|
135
|
+
serializer: ResourceSerializer;
|
|
236
136
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* @param transport - Transport handler for I/O operations
|
|
240
|
-
* @param location - Resource location
|
|
241
|
-
* @param context - Semantic context
|
|
137
|
+
* Resolver to transform RXR into usable object.
|
|
242
138
|
*/
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
interface TextResource extends Resource<string> {
|
|
246
|
-
type: "text";
|
|
247
|
-
content: string;
|
|
248
|
-
}
|
|
249
|
-
declare class TextSemanticHandler implements SemanticHandler<string> {
|
|
250
|
-
readonly name = "text";
|
|
251
|
-
resolve(transport: TransportHandler, location: string, context: SemanticContext): Promise<TextResource>;
|
|
252
|
-
deposit(transport: TransportHandler, location: string, data: string, _context: SemanticContext): Promise<void>;
|
|
253
|
-
exists(transport: TransportHandler, location: string, _context: SemanticContext): Promise<boolean>;
|
|
254
|
-
delete(transport: TransportHandler, location: string, _context: SemanticContext): Promise<void>;
|
|
255
|
-
}
|
|
256
|
-
declare const textHandler: TextSemanticHandler;
|
|
257
|
-
interface BinaryResource extends Resource<Buffer> {
|
|
258
|
-
type: "binary";
|
|
259
|
-
content: Buffer;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Supported binary input types for deposit
|
|
263
|
-
*/
|
|
264
|
-
type BinaryInput = Buffer | Uint8Array | ArrayBuffer | number[];
|
|
265
|
-
declare class BinarySemanticHandler implements SemanticHandler<Buffer> {
|
|
266
|
-
readonly name = "binary";
|
|
267
|
-
resolve(transport: TransportHandler, location: string, context: SemanticContext): Promise<BinaryResource>;
|
|
268
|
-
deposit(transport: TransportHandler, location: string, data: BinaryInput, _context: SemanticContext): Promise<void>;
|
|
269
|
-
exists(transport: TransportHandler, location: string, _context: SemanticContext): Promise<boolean>;
|
|
270
|
-
delete(transport: TransportHandler, location: string, _context: SemanticContext): Promise<void>;
|
|
139
|
+
resolver: ResourceResolver<T>;
|
|
271
140
|
}
|
|
272
|
-
declare const binaryHandler: BinarySemanticHandler;
|
|
273
|
-
/**
|
|
274
|
-
* Get semantic handler by name
|
|
275
|
-
*/
|
|
276
|
-
declare function getSemanticHandler(name: string): SemanticHandler;
|
|
277
141
|
/**
|
|
278
|
-
*
|
|
142
|
+
* Define and register a resource type.
|
|
143
|
+
*
|
|
144
|
+
* @throws ResourceTypeError if type is already registered
|
|
279
145
|
*/
|
|
280
|
-
declare function
|
|
146
|
+
declare function defineResourceType<T>(config: ResourceType<T>): ResourceType<T>;
|
|
281
147
|
/**
|
|
282
|
-
*
|
|
148
|
+
* Get a registered resource type by name.
|
|
283
149
|
*
|
|
284
|
-
* @
|
|
285
|
-
* const resource = await resolve("arp:text:https://example.com/file.txt");
|
|
286
|
-
* // { type: "text", content: "...", meta: { ... } }
|
|
150
|
+
* @returns ResourceType or undefined if not found
|
|
287
151
|
*/
|
|
288
|
-
declare function
|
|
152
|
+
declare function getResourceType<T = unknown>(name: string): ResourceType<T> | undefined;
|
|
289
153
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
* await deposit("arp:text:file://./data/config.txt", "hello world");
|
|
154
|
+
* Clear all registered resource types (for testing).
|
|
294
155
|
*/
|
|
295
|
-
declare function
|
|
156
|
+
declare function clearResourceTypes(): void;
|
|
296
157
|
/**
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* const exists = await resourceExists("arp:text:file://./data/config.txt");
|
|
158
|
+
* Text resource type
|
|
301
159
|
*/
|
|
302
|
-
declare
|
|
160
|
+
declare const textType: ResourceType<string>;
|
|
303
161
|
/**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* await resourceDelete("arp:text:file://./data/config.txt");
|
|
162
|
+
* JSON resource type
|
|
308
163
|
*/
|
|
309
|
-
declare
|
|
164
|
+
declare const jsonType: ResourceType<unknown>;
|
|
310
165
|
/**
|
|
311
|
-
*
|
|
166
|
+
* Binary resource type
|
|
312
167
|
*/
|
|
168
|
+
declare const binaryType: ResourceType<Buffer>;
|
|
313
169
|
/**
|
|
314
|
-
*
|
|
170
|
+
* All built-in types
|
|
315
171
|
*/
|
|
316
|
-
|
|
317
|
-
/** Unique name for the resource (used in URL: name://location) */
|
|
318
|
-
readonly name: string;
|
|
319
|
-
/** Semantic type (e.g., "text", "json", "binary") */
|
|
320
|
-
readonly semantic: string;
|
|
321
|
-
/** Transport type (e.g., "file", "https") */
|
|
322
|
-
readonly transport: string;
|
|
323
|
-
/** Base path prepended to location (optional) */
|
|
324
|
-
readonly basePath?: string;
|
|
325
|
-
}
|
|
172
|
+
declare const builtinTypes: ResourceType[];
|
|
326
173
|
/**
|
|
327
|
-
*
|
|
174
|
+
* TypeHandlerChain - Responsibility chain for resource type handling.
|
|
175
|
+
* Manages type registration and delegates serialization/deserialization.
|
|
328
176
|
*/
|
|
329
|
-
declare
|
|
177
|
+
declare class TypeHandlerChain {
|
|
178
|
+
private handlers;
|
|
330
179
|
/**
|
|
331
|
-
* Register a resource
|
|
180
|
+
* Register a resource type handler.
|
|
181
|
+
* Registers both the type name and its aliases.
|
|
332
182
|
*/
|
|
333
|
-
register(
|
|
183
|
+
register(type: ResourceType): void;
|
|
334
184
|
/**
|
|
335
|
-
*
|
|
185
|
+
* Register multiple type handlers.
|
|
336
186
|
*/
|
|
337
|
-
|
|
187
|
+
registerAll(types: ResourceType[]): void;
|
|
338
188
|
/**
|
|
339
|
-
* Check if a
|
|
189
|
+
* Check if a type is supported.
|
|
340
190
|
*/
|
|
341
|
-
|
|
191
|
+
canHandle(typeName: string): boolean;
|
|
342
192
|
/**
|
|
343
|
-
*
|
|
193
|
+
* Get handler for a type.
|
|
344
194
|
*/
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
195
|
+
getHandler(typeName: string): ResourceType | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Serialize RXR content using the appropriate type handler.
|
|
198
|
+
*/
|
|
199
|
+
serialize(rxr: RXR): Promise<Buffer>;
|
|
200
|
+
/**
|
|
201
|
+
* Deserialize content into RXR using the appropriate type handler.
|
|
202
|
+
*/
|
|
203
|
+
deserialize(data: Buffer, manifest: RXM): Promise<RXR>;
|
|
204
|
+
/**
|
|
205
|
+
* Resolve RXR content into usable object using the appropriate type handler.
|
|
206
|
+
*/
|
|
207
|
+
resolve<T = unknown>(rxr: RXR): Promise<T>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create a new TypeHandlerChain with optional initial types.
|
|
211
|
+
*/
|
|
212
|
+
declare function createTypeHandlerChain(types?: ResourceType[]): TypeHandlerChain;
|
|
213
|
+
export { textType, parseRXL, loadRXC, jsonType, getResourceType, defineResourceType, createTypeHandlerChain, createRXM, createRXC, clearResourceTypes, builtinTypes, binaryType, TypeHandlerChain, ResourceXError, ResourceTypeError, ResourceType, ResourceSerializer, ResourceResolver, RXR, RXM, RXL, RXC, ManifestError, ManifestData, LocatorError, ContentError };
|