@resourcexjs/core 2.5.4 → 2.5.6
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 +87 -8
- package/dist/index.d.ts +727 -1
- package/dist/index.js +680 -12
- package/dist/index.js.map +27 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -177,4 +177,730 @@ declare function parse(locator: string): RXL;
|
|
|
177
177
|
* @returns RXA archive object
|
|
178
178
|
*/
|
|
179
179
|
declare function wrap(buffer: Buffer): RXA;
|
|
180
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Isolator type for resolver execution.
|
|
182
|
+
* Matches SandboX isolator types directly.
|
|
183
|
+
* Configured at Registry level, not per-type.
|
|
184
|
+
*
|
|
185
|
+
* - "none": No isolation, fastest (~10ms), for development
|
|
186
|
+
* - "srt": OS-level isolation (~50ms), secure local dev
|
|
187
|
+
* - "cloudflare": Container isolation (~100ms), local Docker or edge
|
|
188
|
+
* - "e2b": MicroVM isolation (~150ms), production (planned)
|
|
189
|
+
*/
|
|
190
|
+
type IsolatorType = "none" | "srt" | "cloudflare" | "e2b";
|
|
191
|
+
/**
|
|
192
|
+
* ResolveContext - Pure data context passed to resolver in sandbox.
|
|
193
|
+
*
|
|
194
|
+
* This is a serializable data structure that replaces RXR for sandbox execution.
|
|
195
|
+
* The executor pre-processes RXR (extracts files) before passing to resolver.
|
|
196
|
+
*/
|
|
197
|
+
interface ResolveContext {
|
|
198
|
+
/**
|
|
199
|
+
* Resource manifest metadata.
|
|
200
|
+
*/
|
|
201
|
+
manifest: {
|
|
202
|
+
domain: string
|
|
203
|
+
path?: string
|
|
204
|
+
name: string
|
|
205
|
+
type: string
|
|
206
|
+
version: string
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Extracted files from archive.
|
|
210
|
+
* Key is file path, value is file content as Uint8Array.
|
|
211
|
+
*/
|
|
212
|
+
files: Record<string, Uint8Array>;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* BundledType - Pre-bundled resource type ready for execution.
|
|
216
|
+
* Contains bundled code string instead of closure.
|
|
217
|
+
*
|
|
218
|
+
* Note: Sandbox isolation is configured at Registry level via createRegistry({ sandbox: ... })
|
|
219
|
+
*/
|
|
220
|
+
interface BundledType {
|
|
221
|
+
/**
|
|
222
|
+
* Type name (e.g., "text", "json", "prompt").
|
|
223
|
+
*/
|
|
224
|
+
name: string;
|
|
225
|
+
/**
|
|
226
|
+
* Alternative names for this type.
|
|
227
|
+
*/
|
|
228
|
+
aliases?: string[];
|
|
229
|
+
/**
|
|
230
|
+
* Human-readable description.
|
|
231
|
+
*/
|
|
232
|
+
description: string;
|
|
233
|
+
/**
|
|
234
|
+
* JSON Schema for resolver arguments.
|
|
235
|
+
*/
|
|
236
|
+
schema?: JSONSchema;
|
|
237
|
+
/**
|
|
238
|
+
* Bundled resolver code (executable in sandbox).
|
|
239
|
+
*/
|
|
240
|
+
code: string;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* JSON Schema property definition.
|
|
244
|
+
*/
|
|
245
|
+
interface JSONSchemaProperty {
|
|
246
|
+
type: "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
247
|
+
description?: string;
|
|
248
|
+
default?: unknown;
|
|
249
|
+
enum?: unknown[];
|
|
250
|
+
items?: JSONSchemaProperty;
|
|
251
|
+
properties?: Record<string, JSONSchemaProperty>;
|
|
252
|
+
required?: string[];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* JSON Schema definition for resolver arguments.
|
|
256
|
+
* Used by UI to render parameter forms.
|
|
257
|
+
*/
|
|
258
|
+
interface JSONSchema extends JSONSchemaProperty {
|
|
259
|
+
$schema?: string;
|
|
260
|
+
title?: string;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* ResolvedResource - Structured result object returned by resolver.
|
|
264
|
+
* Contains execute function, original resource, and optional schema for UI rendering.
|
|
265
|
+
*/
|
|
266
|
+
interface ResolvedResource<
|
|
267
|
+
TArgs = void,
|
|
268
|
+
TResult = unknown
|
|
269
|
+
> {
|
|
270
|
+
/**
|
|
271
|
+
* Original resource object (RXR from @resourcexjs/core).
|
|
272
|
+
*/
|
|
273
|
+
resource: unknown;
|
|
274
|
+
/**
|
|
275
|
+
* Execute function to get the resource content.
|
|
276
|
+
* - For static resources (text/json/binary): call with no arguments
|
|
277
|
+
* - For dynamic resources (tool): call with arguments
|
|
278
|
+
*/
|
|
279
|
+
execute: (args?: TArgs) => TResult | Promise<TResult>;
|
|
280
|
+
/**
|
|
281
|
+
* JSON Schema for the arguments (undefined if no arguments needed).
|
|
282
|
+
* UI uses this to render parameter forms.
|
|
283
|
+
*/
|
|
284
|
+
schema: TArgs extends void ? undefined : JSONSchema;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* ResourceResolver - Transforms resource into a structured result object.
|
|
288
|
+
* The execute function is lazy-loaded: content is only read when called.
|
|
289
|
+
*/
|
|
290
|
+
interface ResourceResolver<
|
|
291
|
+
TArgs = void,
|
|
292
|
+
TResult = unknown
|
|
293
|
+
> {
|
|
294
|
+
/**
|
|
295
|
+
* JSON Schema for arguments (required if TArgs is not void).
|
|
296
|
+
* This constraint ensures type safety at definition time.
|
|
297
|
+
*/
|
|
298
|
+
schema: TArgs extends void ? undefined : JSONSchema;
|
|
299
|
+
/**
|
|
300
|
+
* Resolve resource into a structured result object.
|
|
301
|
+
* @param rxr - RXR object from @resourcexjs/core
|
|
302
|
+
*/
|
|
303
|
+
resolve(rxr: unknown): Promise<ResolvedResource<TArgs, TResult>>;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* ResourceType - Defines how a resource type is handled.
|
|
307
|
+
*/
|
|
308
|
+
interface ResourceType<
|
|
309
|
+
TArgs = void,
|
|
310
|
+
TResult = unknown
|
|
311
|
+
> {
|
|
312
|
+
/**
|
|
313
|
+
* Type name (e.g., "text", "json", "binary").
|
|
314
|
+
*/
|
|
315
|
+
name: string;
|
|
316
|
+
/**
|
|
317
|
+
* Alternative names for this type (e.g., ["txt", "plaintext"]).
|
|
318
|
+
*/
|
|
319
|
+
aliases?: string[];
|
|
320
|
+
/**
|
|
321
|
+
* Human-readable description.
|
|
322
|
+
*/
|
|
323
|
+
description: string;
|
|
324
|
+
/**
|
|
325
|
+
* Resolver to transform RXR into structured result object.
|
|
326
|
+
*/
|
|
327
|
+
resolver: ResourceResolver<TArgs, TResult>;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Bundle a resource type from a source file.
|
|
331
|
+
*
|
|
332
|
+
* @param sourcePath - Path to the .type.ts file
|
|
333
|
+
* @param basePath - Base path for resolving relative paths (defaults to cwd)
|
|
334
|
+
* @returns BundledType ready for registry
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const promptType = await bundleResourceType("./prompt.type.ts");
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
declare function bundleResourceType(sourcePath: string, basePath?: string): Promise<BundledType>;
|
|
342
|
+
/**
|
|
343
|
+
* Resource type related error.
|
|
344
|
+
*/
|
|
345
|
+
declare class ResourceTypeError extends ResourceXError {
|
|
346
|
+
constructor(message: string);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* TypeHandlerChain - Manages resource type registration.
|
|
350
|
+
*
|
|
351
|
+
* Responsibilities:
|
|
352
|
+
* - Register types (name + aliases)
|
|
353
|
+
* - Look up types by name
|
|
354
|
+
*
|
|
355
|
+
* Execution is delegated to ResolverExecutor (in registry package).
|
|
356
|
+
*
|
|
357
|
+
* Built-in types (text, json, binary) are registered by default.
|
|
358
|
+
*/
|
|
359
|
+
declare class TypeHandlerChain {
|
|
360
|
+
private handlers;
|
|
361
|
+
private constructor();
|
|
362
|
+
/**
|
|
363
|
+
* Create a new TypeHandlerChain instance.
|
|
364
|
+
* Built-in types (text, json, binary) are included by default.
|
|
365
|
+
*/
|
|
366
|
+
static create(): TypeHandlerChain;
|
|
367
|
+
/**
|
|
368
|
+
* Internal registration (no duplicate check).
|
|
369
|
+
*/
|
|
370
|
+
private registerInternal;
|
|
371
|
+
/**
|
|
372
|
+
* Register a type.
|
|
373
|
+
* @throws ResourceTypeError if type is already registered
|
|
374
|
+
*/
|
|
375
|
+
register(type: BundledType): void;
|
|
376
|
+
/**
|
|
377
|
+
* Check if a type is supported.
|
|
378
|
+
*/
|
|
379
|
+
canHandle(typeName: string): boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Get handler for a type.
|
|
382
|
+
* @throws ResourceTypeError if type is not supported
|
|
383
|
+
*/
|
|
384
|
+
getHandler(typeName: string): BundledType;
|
|
385
|
+
/**
|
|
386
|
+
* Get handler for a type, or undefined if not found.
|
|
387
|
+
*/
|
|
388
|
+
getHandlerOrUndefined(typeName: string): BundledType | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* Get all supported type names (including aliases).
|
|
391
|
+
*/
|
|
392
|
+
getSupportedTypes(): string[];
|
|
393
|
+
/**
|
|
394
|
+
* Clear all registered types (for testing).
|
|
395
|
+
*/
|
|
396
|
+
clear(): void;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Plain text content
|
|
400
|
+
*/
|
|
401
|
+
declare const textType: BundledType;
|
|
402
|
+
/**
|
|
403
|
+
* JSON content
|
|
404
|
+
*/
|
|
405
|
+
declare const jsonType: BundledType;
|
|
406
|
+
/**
|
|
407
|
+
* Binary content
|
|
408
|
+
*/
|
|
409
|
+
declare const binaryType: BundledType;
|
|
410
|
+
/**
|
|
411
|
+
* All built-in types as an array.
|
|
412
|
+
*/
|
|
413
|
+
declare const builtinTypes: BundledType[];
|
|
414
|
+
/**
|
|
415
|
+
* ResourceLoader - Strategy interface for loading resources from different sources.
|
|
416
|
+
*/
|
|
417
|
+
interface ResourceLoader {
|
|
418
|
+
/**
|
|
419
|
+
* Check if this loader can handle the given source.
|
|
420
|
+
*
|
|
421
|
+
* @param source - Source path or identifier
|
|
422
|
+
* @returns true if this loader can handle the source
|
|
423
|
+
*/
|
|
424
|
+
canLoad(source: string): boolean | Promise<boolean>;
|
|
425
|
+
/**
|
|
426
|
+
* Load a resource from the given source.
|
|
427
|
+
*
|
|
428
|
+
* @param source - Source path or identifier
|
|
429
|
+
* @returns Complete RXR object
|
|
430
|
+
* @throws ResourceXError if loading fails
|
|
431
|
+
*/
|
|
432
|
+
load(source: string): Promise<RXR>;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Default ResourceLoader implementation for loading resources from folders.
|
|
436
|
+
*
|
|
437
|
+
* Expected folder structure:
|
|
438
|
+
* ```
|
|
439
|
+
* folder/
|
|
440
|
+
* ├── resource.json # Resource metadata (required)
|
|
441
|
+
* └── ... # Any other files/directories (content)
|
|
442
|
+
* ```
|
|
443
|
+
*
|
|
444
|
+
* resource.json format:
|
|
445
|
+
* ```json
|
|
446
|
+
* {
|
|
447
|
+
* "name": "resource-name", // required
|
|
448
|
+
* "type": "text", // required
|
|
449
|
+
* "version": "1.0.0", // required
|
|
450
|
+
* "domain": "localhost", // optional, defaults to "localhost"
|
|
451
|
+
* "path": "optional/path" // optional
|
|
452
|
+
* }
|
|
453
|
+
* ```
|
|
454
|
+
*
|
|
455
|
+
* All files in the folder (except resource.json) will be packaged into the RXA.
|
|
456
|
+
*/
|
|
457
|
+
declare class FolderLoader implements ResourceLoader {
|
|
458
|
+
canLoad(source: string): Promise<boolean>;
|
|
459
|
+
load(folderPath: string): Promise<RXR>;
|
|
460
|
+
/**
|
|
461
|
+
* Recursively read all files in a folder, returning a map of relative paths to buffers.
|
|
462
|
+
*/
|
|
463
|
+
private readFolderFiles;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Configuration options for loadResource.
|
|
467
|
+
*/
|
|
468
|
+
interface LoadResourceConfig {
|
|
469
|
+
/**
|
|
470
|
+
* Custom loader to use. If not provided, defaults to FolderLoader.
|
|
471
|
+
*/
|
|
472
|
+
loader?: ResourceLoader;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Load a resource from a given source using a ResourceLoader.
|
|
476
|
+
*
|
|
477
|
+
* By default, uses FolderLoader which expects:
|
|
478
|
+
* ```
|
|
479
|
+
* folder/
|
|
480
|
+
* ├── resource.json # Resource metadata
|
|
481
|
+
* └── content # Resource content
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* You can provide a custom loader via config.loader to support other formats
|
|
485
|
+
* (e.g., zip, tar.gz, URLs).
|
|
486
|
+
*
|
|
487
|
+
* @param source - Source path or identifier
|
|
488
|
+
* @param config - Optional configuration
|
|
489
|
+
* @returns Complete RXR object ready for registry.link()
|
|
490
|
+
* @throws ResourceXError if the source cannot be loaded
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* // Load from folder (default)
|
|
495
|
+
* const rxr = await loadResource("./my-resource");
|
|
496
|
+
* await registry.link(rxr);
|
|
497
|
+
*
|
|
498
|
+
* // Load with custom loader
|
|
499
|
+
* const rxr = await loadResource("resource.zip", {
|
|
500
|
+
* loader: new ZipLoader()
|
|
501
|
+
* });
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
declare function loadResource(source: string, config?: LoadResourceConfig): Promise<RXR>;
|
|
505
|
+
/**
|
|
506
|
+
* Search options for querying resources.
|
|
507
|
+
*/
|
|
508
|
+
interface SearchOptions {
|
|
509
|
+
/**
|
|
510
|
+
* Search query string (matches against name, domain, path).
|
|
511
|
+
*/
|
|
512
|
+
query?: string;
|
|
513
|
+
/**
|
|
514
|
+
* Maximum number of results to return.
|
|
515
|
+
*/
|
|
516
|
+
limit?: number;
|
|
517
|
+
/**
|
|
518
|
+
* Number of results to skip (for pagination).
|
|
519
|
+
*/
|
|
520
|
+
offset?: number;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Registry interface - business layer for RXR operations.
|
|
524
|
+
*
|
|
525
|
+
* This interface defines CRUD operations on RXR objects.
|
|
526
|
+
* Different implementations (HostedRegistry, MirrorRegistry, LinkedRegistry)
|
|
527
|
+
* provide different semantics on top of the same Storage layer.
|
|
528
|
+
*/
|
|
529
|
+
interface Registry {
|
|
530
|
+
/**
|
|
531
|
+
* Get resource by locator.
|
|
532
|
+
* @throws RegistryError if not found
|
|
533
|
+
*/
|
|
534
|
+
get(rxl: RXL): Promise<RXR>;
|
|
535
|
+
/**
|
|
536
|
+
* Store resource.
|
|
537
|
+
*/
|
|
538
|
+
put(rxr: RXR): Promise<void>;
|
|
539
|
+
/**
|
|
540
|
+
* Check if resource exists.
|
|
541
|
+
*/
|
|
542
|
+
has(rxl: RXL): Promise<boolean>;
|
|
543
|
+
/**
|
|
544
|
+
* Delete resource.
|
|
545
|
+
*/
|
|
546
|
+
remove(rxl: RXL): Promise<void>;
|
|
547
|
+
/**
|
|
548
|
+
* List resources matching options.
|
|
549
|
+
*/
|
|
550
|
+
list(options?: SearchOptions): Promise<RXL[]>;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* RXAStore - Content-Addressable Storage for Resource Archives
|
|
554
|
+
*
|
|
555
|
+
* SPI interface for storing file content by digest (hash).
|
|
556
|
+
* Platform implementations provide concrete storage backends
|
|
557
|
+
* (FileSystem, S3, R2, Memory, etc.)
|
|
558
|
+
*/
|
|
559
|
+
interface RXAStore {
|
|
560
|
+
/**
|
|
561
|
+
* Get content by digest.
|
|
562
|
+
* @throws if not found
|
|
563
|
+
*/
|
|
564
|
+
get(digest: string): Promise<Buffer>;
|
|
565
|
+
/**
|
|
566
|
+
* Store content, returns digest.
|
|
567
|
+
* If content with same digest exists, skips write (deduplication).
|
|
568
|
+
*/
|
|
569
|
+
put(data: Buffer): Promise<string>;
|
|
570
|
+
/**
|
|
571
|
+
* Check if digest exists.
|
|
572
|
+
*/
|
|
573
|
+
has(digest: string): Promise<boolean>;
|
|
574
|
+
/**
|
|
575
|
+
* Delete content by digest (for GC).
|
|
576
|
+
*/
|
|
577
|
+
delete(digest: string): Promise<void>;
|
|
578
|
+
/**
|
|
579
|
+
* List all digests (for GC).
|
|
580
|
+
*/
|
|
581
|
+
list(): Promise<string[]>;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* RXMStore - Manifest Storage
|
|
585
|
+
*
|
|
586
|
+
* SPI interface for storing resource manifests.
|
|
587
|
+
* Platform implementations provide concrete storage backends
|
|
588
|
+
* (SQLite, PostgreSQL, FileSystem, Memory, etc.)
|
|
589
|
+
*/
|
|
590
|
+
/**
|
|
591
|
+
* Stored manifest with file digest mappings.
|
|
592
|
+
*/
|
|
593
|
+
interface StoredRXM {
|
|
594
|
+
readonly registry?: string;
|
|
595
|
+
readonly path?: string;
|
|
596
|
+
readonly name: string;
|
|
597
|
+
readonly type: string;
|
|
598
|
+
readonly tag: string;
|
|
599
|
+
readonly files: Record<string, string>;
|
|
600
|
+
readonly createdAt?: Date;
|
|
601
|
+
readonly updatedAt?: Date;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Search options for RXMStore.
|
|
605
|
+
*/
|
|
606
|
+
interface RXMSearchOptions {
|
|
607
|
+
/**
|
|
608
|
+
* Filter by registry.
|
|
609
|
+
* - undefined: all
|
|
610
|
+
* - null: local only (no registry)
|
|
611
|
+
* - string: specific registry
|
|
612
|
+
*/
|
|
613
|
+
registry?: string | null;
|
|
614
|
+
/**
|
|
615
|
+
* Search query (matches name).
|
|
616
|
+
*/
|
|
617
|
+
query?: string;
|
|
618
|
+
/**
|
|
619
|
+
* Maximum results.
|
|
620
|
+
*/
|
|
621
|
+
limit?: number;
|
|
622
|
+
/**
|
|
623
|
+
* Skip results (pagination).
|
|
624
|
+
*/
|
|
625
|
+
offset?: number;
|
|
626
|
+
}
|
|
627
|
+
interface RXMStore {
|
|
628
|
+
/**
|
|
629
|
+
* Get manifest.
|
|
630
|
+
* @returns null if not found
|
|
631
|
+
*/
|
|
632
|
+
get(name: string, tag: string, registry?: string): Promise<StoredRXM | null>;
|
|
633
|
+
/**
|
|
634
|
+
* Store manifest.
|
|
635
|
+
*/
|
|
636
|
+
put(manifest: StoredRXM): Promise<void>;
|
|
637
|
+
/**
|
|
638
|
+
* Check if manifest exists.
|
|
639
|
+
*/
|
|
640
|
+
has(name: string, tag: string, registry?: string): Promise<boolean>;
|
|
641
|
+
/**
|
|
642
|
+
* Delete manifest.
|
|
643
|
+
*/
|
|
644
|
+
delete(name: string, tag: string, registry?: string): Promise<void>;
|
|
645
|
+
/**
|
|
646
|
+
* List all tags for a resource.
|
|
647
|
+
*/
|
|
648
|
+
listTags(name: string, registry?: string): Promise<string[]>;
|
|
649
|
+
/**
|
|
650
|
+
* List all resource names.
|
|
651
|
+
*/
|
|
652
|
+
listNames(registry?: string, query?: string): Promise<string[]>;
|
|
653
|
+
/**
|
|
654
|
+
* Search manifests.
|
|
655
|
+
*/
|
|
656
|
+
search(options?: RXMSearchOptions): Promise<StoredRXM[]>;
|
|
657
|
+
/**
|
|
658
|
+
* Delete all manifests from a registry (clear cache).
|
|
659
|
+
*/
|
|
660
|
+
deleteByRegistry(registry: string): Promise<void>;
|
|
661
|
+
}
|
|
662
|
+
declare class CASRegistry implements Registry {
|
|
663
|
+
private readonly rxaStore;
|
|
664
|
+
private readonly rxmStore;
|
|
665
|
+
constructor(rxaStore: RXAStore, rxmStore: RXMStore);
|
|
666
|
+
get(rxl: RXL): Promise<RXR>;
|
|
667
|
+
put(rxr: RXR): Promise<void>;
|
|
668
|
+
has(rxl: RXL): Promise<boolean>;
|
|
669
|
+
remove(rxl: RXL): Promise<void>;
|
|
670
|
+
list(options?: SearchOptions): Promise<RXL[]>;
|
|
671
|
+
/**
|
|
672
|
+
* Clear cached resources (resources with registry).
|
|
673
|
+
* @param registry - If provided, only clear resources from this registry
|
|
674
|
+
*/
|
|
675
|
+
clearCache(registry?: string): Promise<void>;
|
|
676
|
+
/**
|
|
677
|
+
* Run garbage collection to remove orphaned blobs.
|
|
678
|
+
*/
|
|
679
|
+
gc(): Promise<number>;
|
|
680
|
+
/**
|
|
681
|
+
* Check if a digest exists in the blob store.
|
|
682
|
+
* Useful for "instant upload" - skip uploading if server already has it.
|
|
683
|
+
*/
|
|
684
|
+
hasBlob(digest: string): Promise<boolean>;
|
|
685
|
+
/**
|
|
686
|
+
* Get blob by digest.
|
|
687
|
+
*/
|
|
688
|
+
getBlob(digest: string): Promise<Buffer>;
|
|
689
|
+
/**
|
|
690
|
+
* Put blob directly (for pull optimization).
|
|
691
|
+
*/
|
|
692
|
+
putBlob(data: Buffer): Promise<string>;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* LinkedRegistry - Registry for development symlinks.
|
|
696
|
+
*
|
|
697
|
+
* Creates symlinks to development directories so changes are reflected immediately.
|
|
698
|
+
* Unlike HostedRegistry/MirrorRegistry, it doesn't use Storage layer directly.
|
|
699
|
+
* Instead, it manages symlinks in a base directory.
|
|
700
|
+
*
|
|
701
|
+
* Storage structure:
|
|
702
|
+
* {basePath}/{registry}/{path}/{name}/{tag} → /path/to/dev/folder
|
|
703
|
+
*/
|
|
704
|
+
declare class LinkedRegistry implements Registry {
|
|
705
|
+
private readonly basePath;
|
|
706
|
+
constructor(basePath: string);
|
|
707
|
+
/**
|
|
708
|
+
* Build symlink path for a resource.
|
|
709
|
+
*/
|
|
710
|
+
private buildLinkPath;
|
|
711
|
+
/**
|
|
712
|
+
* Check if a path is a symlink.
|
|
713
|
+
*/
|
|
714
|
+
private isSymlink;
|
|
715
|
+
get(rxl: RXL): Promise<RXR>;
|
|
716
|
+
/**
|
|
717
|
+
* Put is not typically used for LinkedRegistry.
|
|
718
|
+
* Use link() instead to create symlinks.
|
|
719
|
+
*/
|
|
720
|
+
put(_rxr: RXR): Promise<void>;
|
|
721
|
+
has(rxl: RXL): Promise<boolean>;
|
|
722
|
+
remove(rxl: RXL): Promise<void>;
|
|
723
|
+
list(options?: SearchOptions): Promise<RXL[]>;
|
|
724
|
+
/**
|
|
725
|
+
* Link a development directory.
|
|
726
|
+
* Creates a symlink so changes are reflected immediately.
|
|
727
|
+
*
|
|
728
|
+
* @param devPath - Path to development directory (must contain resource.json)
|
|
729
|
+
* @returns The RXL of the linked resource
|
|
730
|
+
*/
|
|
731
|
+
link(devPath: string): Promise<RXL>;
|
|
732
|
+
/**
|
|
733
|
+
* Unlink a development directory.
|
|
734
|
+
* Alias for remove().
|
|
735
|
+
*/
|
|
736
|
+
unlink(rxl: RXL): Promise<void>;
|
|
737
|
+
/**
|
|
738
|
+
* Recursively scan for symlinks.
|
|
739
|
+
*/
|
|
740
|
+
private scanSymlinks;
|
|
741
|
+
/**
|
|
742
|
+
* Parse relative path to RXL.
|
|
743
|
+
* Path format: {registry}/{path}/{name}/{tag}
|
|
744
|
+
*/
|
|
745
|
+
private parsePathToRXL;
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Compute SHA-256 digest of data.
|
|
749
|
+
* Returns string in format "sha256:{hex}"
|
|
750
|
+
*/
|
|
751
|
+
declare function computeDigest(data: Buffer): string;
|
|
752
|
+
/**
|
|
753
|
+
* Validate digest format.
|
|
754
|
+
*/
|
|
755
|
+
declare function isValidDigest(digest: string): boolean;
|
|
756
|
+
declare class MemoryRXAStore implements RXAStore {
|
|
757
|
+
private readonly blobs;
|
|
758
|
+
get(digest: string): Promise<Buffer>;
|
|
759
|
+
put(data: Buffer): Promise<string>;
|
|
760
|
+
has(digest: string): Promise<boolean>;
|
|
761
|
+
delete(digest: string): Promise<void>;
|
|
762
|
+
list(): Promise<string[]>;
|
|
763
|
+
/**
|
|
764
|
+
* Clear all blobs (for testing).
|
|
765
|
+
*/
|
|
766
|
+
clear(): void;
|
|
767
|
+
}
|
|
768
|
+
declare class MemoryRXMStore implements RXMStore {
|
|
769
|
+
private readonly manifests;
|
|
770
|
+
/**
|
|
771
|
+
* Build key for manifest lookup.
|
|
772
|
+
*/
|
|
773
|
+
private buildKey;
|
|
774
|
+
get(name: string, tag: string, registry?: string): Promise<StoredRXM | null>;
|
|
775
|
+
put(manifest: StoredRXM): Promise<void>;
|
|
776
|
+
has(name: string, tag: string, registry?: string): Promise<boolean>;
|
|
777
|
+
delete(name: string, tag: string, registry?: string): Promise<void>;
|
|
778
|
+
listTags(name: string, registry?: string): Promise<string[]>;
|
|
779
|
+
listNames(registry?: string, query?: string): Promise<string[]>;
|
|
780
|
+
search(options?: RXMSearchOptions): Promise<StoredRXM[]>;
|
|
781
|
+
deleteByRegistry(registry: string): Promise<void>;
|
|
782
|
+
/**
|
|
783
|
+
* Clear all manifests (for testing).
|
|
784
|
+
*/
|
|
785
|
+
clear(): void;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Well-known discovery response format.
|
|
789
|
+
*/
|
|
790
|
+
interface WellKnownResponse {
|
|
791
|
+
version?: string;
|
|
792
|
+
registries: string[];
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Result from discoverRegistry().
|
|
796
|
+
*/
|
|
797
|
+
interface DiscoveryResult {
|
|
798
|
+
domain: string;
|
|
799
|
+
registries: string[];
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* Discover registry for a domain using well-known.
|
|
803
|
+
* @param domain - The domain to discover (e.g., "deepractice.ai")
|
|
804
|
+
* @returns Discovery result with domain and authorized registries
|
|
805
|
+
*/
|
|
806
|
+
declare function discoverRegistry(domain: string): Promise<DiscoveryResult>;
|
|
807
|
+
/**
|
|
808
|
+
* Registry-specific error.
|
|
809
|
+
*/
|
|
810
|
+
declare class RegistryError extends ResourceXError {
|
|
811
|
+
constructor(message: string, options?: ErrorOptions);
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Base class for Registry middleware.
|
|
815
|
+
* Delegates all operations to the inner registry.
|
|
816
|
+
* Override specific methods to add custom behavior.
|
|
817
|
+
*/
|
|
818
|
+
declare abstract class RegistryMiddleware implements Registry {
|
|
819
|
+
protected readonly inner: Registry;
|
|
820
|
+
constructor(inner: Registry);
|
|
821
|
+
get(rxl: RXL): Promise<RXR>;
|
|
822
|
+
put(rxr: RXR): Promise<void>;
|
|
823
|
+
has(rxl: RXL): Promise<boolean>;
|
|
824
|
+
remove(rxl: RXL): Promise<void>;
|
|
825
|
+
list(options?: SearchOptions): Promise<RXL[]>;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Registry validation middleware.
|
|
829
|
+
* Ensures all resources from this registry match the trusted registry.
|
|
830
|
+
*/
|
|
831
|
+
declare class RegistryValidation extends RegistryMiddleware {
|
|
832
|
+
private readonly trustedRegistry;
|
|
833
|
+
constructor(inner: Registry, trustedRegistry: string);
|
|
834
|
+
/**
|
|
835
|
+
* Validate that manifest registry matches trusted registry.
|
|
836
|
+
*/
|
|
837
|
+
private validateRegistry;
|
|
838
|
+
/**
|
|
839
|
+
* Get resource and validate registry.
|
|
840
|
+
*/
|
|
841
|
+
get(rxl: RXL): Promise<RXR>;
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Factory function to create registry validation middleware.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* const registry = withRegistryValidation(hostedRegistry, "deepractice.ai");
|
|
848
|
+
*/
|
|
849
|
+
declare function withRegistryValidation(registry: Registry, trustedRegistry: string): Registry;
|
|
850
|
+
declare const DomainValidation: typeof RegistryValidation;
|
|
851
|
+
declare const withDomainValidation: typeof withRegistryValidation;
|
|
852
|
+
/**
|
|
853
|
+
* Provider configuration passed to createStores/createLoader.
|
|
854
|
+
*/
|
|
855
|
+
interface ProviderConfig {
|
|
856
|
+
/**
|
|
857
|
+
* Base path for storage (filesystem) or connection info.
|
|
858
|
+
*/
|
|
859
|
+
path?: string;
|
|
860
|
+
/**
|
|
861
|
+
* Platform-specific configuration.
|
|
862
|
+
*/
|
|
863
|
+
[key: string]: unknown;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Stores created by the provider.
|
|
867
|
+
*/
|
|
868
|
+
interface ProviderStores {
|
|
869
|
+
rxaStore: RXAStore;
|
|
870
|
+
rxmStore: RXMStore;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Resource loader interface for loading from directories/archives.
|
|
874
|
+
*/
|
|
875
|
+
interface ResourceLoader2 {
|
|
876
|
+
/**
|
|
877
|
+
* Check if this loader can handle the given source.
|
|
878
|
+
*/
|
|
879
|
+
canLoad(source: string): boolean | Promise<boolean>;
|
|
880
|
+
/**
|
|
881
|
+
* Load resource from source.
|
|
882
|
+
*/
|
|
883
|
+
load(source: string): Promise<unknown>;
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* ResourceX Provider - Platform implementation interface.
|
|
887
|
+
*
|
|
888
|
+
* Platforms implement this interface to provide storage and loading
|
|
889
|
+
* capabilities for their environment.
|
|
890
|
+
*/
|
|
891
|
+
interface ResourceXProvider {
|
|
892
|
+
/**
|
|
893
|
+
* Platform identifier.
|
|
894
|
+
*/
|
|
895
|
+
readonly platform: string;
|
|
896
|
+
/**
|
|
897
|
+
* Create storage instances for the platform.
|
|
898
|
+
*/
|
|
899
|
+
createStores(config: ProviderConfig): ProviderStores;
|
|
900
|
+
/**
|
|
901
|
+
* Create resource loader (optional).
|
|
902
|
+
* Not all platforms support loading from filesystem.
|
|
903
|
+
*/
|
|
904
|
+
createLoader?(config: ProviderConfig): ResourceLoader2;
|
|
905
|
+
}
|
|
906
|
+
export { wrap, withDomainValidation, textType, resource, parse, manifest, locate, loadResource, jsonType, isValidDigest, format, extract, discoverRegistry, define, computeDigest, bundleResourceType, builtinTypes, binaryType, archive, WellKnownResponse, TypeHandlerChain, StoredRXM, SearchOptions, ResourceXProvider, ResourceXError, ResourceTypeError, ResourceType, ResourceResolver, ResourceLoader, ResolvedResource, ResolveContext, RegistryMiddleware, RegistryError, Registry, RXR, RXMStore, RXMSearchOptions, RXM, RXL, RXD, RXAStore, RXA, ProviderStores, ProviderConfig, MemoryRXMStore, MemoryRXAStore, ManifestError, LocatorError, LoadResourceConfig, LinkedRegistry, JSONSchemaProperty, JSONSchema, IsolatorType, FolderLoader, DomainValidation, DiscoveryResult, DefinitionError, ContentError, CASRegistry, BundledType };
|