@resourcexjs/registry 2.4.1 → 2.5.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/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { RXR as RXR3, RXL as RXL3 } from "@resourcexjs/core";
2
- import { BundledType, ResolvedResource, IsolatorType } from "@resourcexjs/type";
3
- import { RXR, RXL } from "@resourcexjs/core";
1
+ import { RXL, RXR } from "@resourcexjs/core";
4
2
  /**
5
3
  * Search options for querying resources.
6
4
  */
@@ -19,304 +17,155 @@ interface SearchOptions {
19
17
  offset?: number;
20
18
  }
21
19
  /**
22
- * Storage interface - pure storage abstraction.
23
- * Handles CRUD operations for resources.
20
+ * Registry interface - business layer for RXR operations.
24
21
  *
25
- * Different implementations:
26
- * - LocalStorage: filesystem, read-write
27
- * - GitStorage: git clone, read-only
28
- * - HttpStorage: HTTP API, typically read-only
22
+ * This interface defines CRUD operations on RXR objects.
23
+ * Different implementations (HostedRegistry, MirrorRegistry, LinkedRegistry)
24
+ * provide different semantics on top of the same Storage layer.
29
25
  */
30
- interface Storage {
31
- /**
32
- * Storage type identifier.
33
- */
34
- readonly type: string;
26
+ interface Registry {
35
27
  /**
36
28
  * Get resource by locator.
37
29
  * @throws RegistryError if not found
38
30
  */
39
- get(locator: string): Promise<RXR>;
31
+ get(rxl: RXL): Promise<RXR>;
40
32
  /**
41
- * Store a resource.
42
- * @throws RegistryError if storage is read-only
33
+ * Store resource.
43
34
  */
44
35
  put(rxr: RXR): Promise<void>;
45
36
  /**
46
37
  * Check if resource exists.
47
38
  */
48
- exists(locator: string): Promise<boolean>;
39
+ has(rxl: RXL): Promise<boolean>;
49
40
  /**
50
- * Delete a resource.
51
- * @throws RegistryError if storage is read-only
41
+ * Delete resource.
52
42
  */
53
- delete(locator: string): Promise<void>;
54
- /**
55
- * Search for resources.
56
- */
57
- search(options?: SearchOptions): Promise<RXL[]>;
58
- }
59
- import { RXR as RXR2, RXL as RXL2 } from "@resourcexjs/core";
60
- /**
61
- * LocalStorage configuration.
62
- */
63
- interface LocalStorageConfig {
43
+ remove(rxl: RXL): Promise<void>;
64
44
  /**
65
- * Base path for storage. Defaults to ~/.resourcex
45
+ * List resources matching options.
66
46
  */
67
- path?: string;
47
+ list(options?: SearchOptions): Promise<RXL[]>;
68
48
  }
49
+ import { RXL as RXL2, RXR as RXR2 } from "@resourcexjs/core";
50
+ import { Storage } from "@resourcexjs/storage";
69
51
  /**
70
- * Local filesystem storage implementation.
71
- * Uses ARP file transport for I/O operations.
52
+ * HostedRegistry - Registry for resources you own (authoritative data).
72
53
  *
54
+ * Uses Storage layer for persistence.
73
55
  * Storage structure:
74
- * - {basePath}/{domain}/{path}/{name}.{type}/{version}/
75
- * - manifest.json
76
- * - archive.tar.gz
77
- *
78
- * For localhost/no-domain resources:
79
- * - {basePath}/localhost/{name}.{type}/{version}/
56
+ * {domain}/{path}/{name}.{type}/{version}/
57
+ * - manifest.json
58
+ * - archive.tar.gz
80
59
  */
81
- declare class LocalStorage implements Storage {
82
- readonly type = "local";
83
- private readonly basePath;
84
- private readonly arp;
85
- constructor(config?: LocalStorageConfig);
86
- /**
87
- * Create ARP URL for a file path.
88
- */
89
- private toArpUrl;
90
- /**
91
- * Build filesystem path for a resource.
92
- * Path: {basePath}/{domain}/{path}/{name}.{type}/{version}
93
- */
94
- private buildPath;
95
- /**
96
- * Check if a resource exists at a specific path.
97
- * Handles both regular storage (manifest.json) and symlinked dev directories (resource.json).
98
- */
99
- private existsAt;
100
- /**
101
- * Check if a path is a symlink.
102
- */
103
- private isSymlink;
60
+ declare class HostedRegistry implements Registry {
61
+ private readonly storage;
62
+ constructor(storage: Storage);
104
63
  /**
105
- * Load resource from a specific path.
106
- * If path is a symlink, loads from the linked directory.
64
+ * Build storage key prefix for a resource.
107
65
  */
108
- private loadFrom;
109
- get(locator: string): Promise<RXR2>;
66
+ private buildKeyPrefix;
67
+ get(rxl: RXL2): Promise<RXR2>;
110
68
  put(rxr: RXR2): Promise<void>;
111
- exists(locator: string): Promise<boolean>;
112
- delete(locator: string): Promise<void>;
113
- search(options?: SearchOptions): Promise<RXL2[]>;
114
- /**
115
- * Link a development directory.
116
- * Creates a symlink so changes are reflected immediately.
117
- */
118
- link(path: string): Promise<void>;
119
- /**
120
- * Parse entry path to RXL.
121
- * Entry format: {domain}/{path}/{name}.{type}/{version}/manifest.json
122
- */
123
- private parseEntryToRXL;
124
- }
125
- /**
126
- * Registry configuration.
127
- */
128
- interface RegistryConfig {
129
- /**
130
- * Storage backend. Defaults to LocalStorage.
131
- */
132
- storage?: Storage;
133
- /**
134
- * Mirror URL for remote fetch (client mode).
135
- * If configured, tries mirror before well-known discovery.
136
- */
137
- mirror?: string;
138
- /**
139
- * Additional custom resource types to support.
140
- * Built-in types (text, json, binary) are always included by default.
141
- */
142
- types?: BundledType[];
143
- /**
144
- * Isolator type for resolver execution (SandboX).
145
- * - "none": No isolation, fastest (~10ms), for development
146
- * - "srt": OS-level isolation (~50ms), secure local dev
147
- * - "cloudflare": Container isolation (~100ms), local Docker or edge
148
- * - "e2b": MicroVM isolation (~150ms), production (planned)
149
- */
150
- isolator?: IsolatorType;
151
- }
152
- /**
153
- * Registry interface for resource management.
154
- */
155
- interface Registry {
156
- /**
157
- * Add support for a custom resource type.
158
- */
159
- supportType(type: BundledType): void;
160
- /**
161
- * Link a development directory.
162
- * Creates a symlink so changes are reflected immediately.
163
- * Only supported by LocalStorage.
164
- */
165
- link(path: string): Promise<void>;
166
- /**
167
- * Add resource to storage.
168
- * @param source - Resource directory path or RXR object
169
- */
170
- add(source: string | RXR3): Promise<void>;
171
- /**
172
- * Get raw resource by locator.
173
- *
174
- * Flow:
175
- * - localhost: Only queries local storage
176
- * - Other domains: Local cache -> [Mirror] -> Source (well-known)
177
- */
178
- get(locator: string): Promise<RXR3>;
179
- /**
180
- * Resolve resource by locator.
181
- * Returns ResolvedResource with execute function.
182
- */
183
- resolve<
184
- TArgs = void,
185
- TResult = unknown
186
- >(locator: string): Promise<ResolvedResource<TArgs, TResult>>;
69
+ has(rxl: RXL2): Promise<boolean>;
70
+ remove(rxl: RXL2): Promise<void>;
71
+ list(options?: SearchOptions): Promise<RXL2[]>;
187
72
  /**
188
- * Check if resource exists.
73
+ * Parse storage key to RXL.
74
+ * Key format: {domain}/{path}/{name}.{type}/{version}/manifest.json
189
75
  */
190
- exists(locator: string): Promise<boolean>;
191
- /**
192
- * Delete resource from storage.
193
- */
194
- delete(locator: string): Promise<void>;
195
- /**
196
- * Search for resources.
197
- */
198
- search(options?: SearchOptions): Promise<RXL3[]>;
76
+ private parseKeyToRXL;
199
77
  }
78
+ import { RXL as RXL3, RXR as RXR3 } from "@resourcexjs/core";
79
+ import { Storage as Storage2 } from "@resourcexjs/storage";
200
80
  /**
201
- * Default Registry implementation.
81
+ * MirrorRegistry - Registry for cached/mirrored remote resources.
202
82
  *
203
- * Combines Storage (for CRUD) with TypeHandlerChain (for type resolution).
204
- * Supports remote fetch for non-localhost domains.
83
+ * Similar to HostedRegistry but adds cache management methods.
84
+ * Resources can be cleared (evicted from cache).
85
+ *
86
+ * Storage structure:
87
+ * {domain}/{path}/{name}.{type}/{version}/
88
+ * - manifest.json
89
+ * - archive.tar.gz
205
90
  */
206
- declare class DefaultRegistry implements Registry {
91
+ declare class MirrorRegistry implements Registry {
207
92
  private readonly storage;
208
- private readonly mirror?;
209
- private readonly typeHandler;
210
- private readonly executor;
211
- private readonly discoveryCache;
212
- constructor(config?: RegistryConfig);
213
- supportType(type: BundledType): void;
214
- link(path: string): Promise<void>;
215
- add(source: string | RXR3): Promise<void>;
216
- get(locator: string): Promise<RXR3>;
217
- resolve<
218
- TArgs = void,
219
- TResult = unknown
220
- >(locator: string): Promise<ResolvedResource<TArgs, TResult>>;
221
- exists(locator: string): Promise<boolean>;
222
- delete(locator: string): Promise<void>;
223
- search(options?: SearchOptions): Promise<RXL3[]>;
93
+ constructor(storage: Storage2);
224
94
  /**
225
- * Fetch resource from remote.
226
- * Flow: Mirror (if configured) -> Source (well-known)
95
+ * Build storage key prefix for a resource.
227
96
  */
228
- private fetchRemote;
97
+ private buildKeyPrefix;
98
+ get(rxl: RXL3): Promise<RXR3>;
99
+ put(rxr: RXR3): Promise<void>;
100
+ has(rxl: RXL3): Promise<boolean>;
101
+ remove(rxl: RXL3): Promise<void>;
102
+ list(options?: SearchOptions): Promise<RXL3[]>;
229
103
  /**
230
- * Discover registry endpoint for a domain via well-known.
104
+ * Clear cached resources.
105
+ * @param domain - If provided, only clear resources from this domain
231
106
  */
232
- private discoverEndpoint;
107
+ clear(domain?: string): Promise<void>;
233
108
  /**
234
- * Fetch resource from a specific endpoint via HTTP API.
109
+ * Parse storage key to RXL.
110
+ * Key format: {domain}/{path}/{name}.{type}/{version}/manifest.json
235
111
  */
236
- private fetchFromEndpoint;
112
+ private parseKeyToRXL;
237
113
  }
238
- import { BundledType as BundledType2, IsolatorType as IsolatorType2 } from "@resourcexjs/type";
114
+ import { RXL as RXL4, RXR as RXR4 } from "@resourcexjs/core";
239
115
  /**
240
- * Client registry configuration.
241
- * Uses LocalStorage as cache, optionally fetches from remote via mirror or well-known.
116
+ * LinkedRegistry - Registry for development symlinks.
117
+ *
118
+ * Creates symlinks to development directories so changes are reflected immediately.
119
+ * Unlike HostedRegistry/MirrorRegistry, it doesn't use Storage layer directly.
120
+ * Instead, it manages symlinks in a base directory.
121
+ *
122
+ * Storage structure:
123
+ * {basePath}/{domain}/{path}/{name}.{type}/{version} → /path/to/dev/folder
242
124
  */
243
- interface ClientRegistryConfig {
125
+ declare class LinkedRegistry implements Registry {
126
+ private readonly basePath;
127
+ constructor(basePath: string);
244
128
  /**
245
- * Local cache path. Defaults to ~/.resourcex
129
+ * Build symlink path for a resource.
246
130
  */
247
- path?: string;
131
+ private buildLinkPath;
248
132
  /**
249
- * Mirror URL for remote fetch.
250
- * If configured, tries mirror before well-known discovery.
133
+ * Check if a path is a symlink.
251
134
  */
252
- mirror?: string;
135
+ private isSymlink;
136
+ get(rxl: RXL4): Promise<RXR4>;
253
137
  /**
254
- * Additional custom resource types.
255
- * Built-in types (text, json, binary) are always included.
138
+ * Put is not typically used for LinkedRegistry.
139
+ * Use link() instead to create symlinks.
256
140
  */
257
- types?: BundledType2[];
141
+ put(_rxr: RXR4): Promise<void>;
142
+ has(rxl: RXL4): Promise<boolean>;
143
+ remove(rxl: RXL4): Promise<void>;
144
+ list(options?: SearchOptions): Promise<RXL4[]>;
258
145
  /**
259
- * Isolator type for resolver execution.
260
- * Defaults to "none".
146
+ * Link a development directory.
147
+ * Creates a symlink so changes are reflected immediately.
148
+ *
149
+ * @param devPath - Path to development directory (must contain resource.json)
150
+ * @returns The RXL of the linked resource
261
151
  */
262
- isolator?: IsolatorType2;
263
- }
264
- /**
265
- * Server registry configuration.
266
- * Uses custom Storage implementation.
267
- */
268
- interface ServerRegistryConfig {
152
+ link(devPath: string): Promise<RXL4>;
269
153
  /**
270
- * Custom storage implementation.
271
- * Example: new LocalStorage({ path: "..." })
154
+ * Unlink a development directory.
155
+ * Alias for remove().
272
156
  */
273
- storage: Storage;
157
+ unlink(rxl: RXL4): Promise<void>;
274
158
  /**
275
- * Additional custom resource types.
276
- * Built-in types (text, json, binary) are always included.
159
+ * Recursively scan for symlinks.
277
160
  */
278
- types?: BundledType2[];
161
+ private scanSymlinks;
279
162
  /**
280
- * Isolator type for resolver execution.
281
- * Defaults to "none".
163
+ * Parse relative path to RXL.
164
+ * Path format: {domain}/{path}/{name}.{type}/{version}
282
165
  */
283
- isolator?: IsolatorType2;
166
+ private parsePathToRXL;
284
167
  }
285
168
  /**
286
- * All supported registry configurations.
287
- */
288
- type CreateRegistryConfig = ClientRegistryConfig | ServerRegistryConfig;
289
- /**
290
- * Create a registry instance.
291
- *
292
- * Built-in types (text, json, binary) are always included by default.
293
- *
294
- * Two modes:
295
- * 1. Client mode (default): Uses LocalStorage as cache, fetches from remote when cache miss
296
- * 2. Server mode: Uses custom Storage implementation
297
- *
298
- * @example
299
- * // Simple usage - builtin types included
300
- * const registry = createRegistry();
301
- *
302
- * @example
303
- * // With custom types
304
- * const registry = createRegistry({ types: [myPromptType] });
305
- *
306
- * @example
307
- * // With isolator (SandboX)
308
- * const registry = createRegistry({
309
- * isolator: "srt", // or "none", "cloudflare", "e2b"
310
- * });
311
- *
312
- * @example
313
- * // Server mode - custom storage
314
- * const registry = createRegistry({
315
- * storage: new LocalStorage({ path: "./data" }),
316
- * });
317
- */
318
- declare function createRegistry(config?: CreateRegistryConfig): Registry;
319
- /**
320
169
  * Well-known discovery response format.
321
170
  */
322
171
  interface WellKnownResponse {
@@ -343,8 +192,7 @@ import { ResourceXError } from "@resourcexjs/core";
343
192
  declare class RegistryError extends ResourceXError {
344
193
  constructor(message: string, options?: ErrorOptions);
345
194
  }
346
- import { RXR as RXR4, RXL as RXL4 } from "@resourcexjs/core";
347
- import { BundledType as BundledType3, ResolvedResource as ResolvedResource2 } from "@resourcexjs/type";
195
+ import { RXR as RXR5, RXL as RXL5 } from "@resourcexjs/core";
348
196
  /**
349
197
  * Base class for Registry middleware.
350
198
  * Delegates all operations to the inner registry.
@@ -353,20 +201,13 @@ import { BundledType as BundledType3, ResolvedResource as ResolvedResource2 } fr
353
201
  declare abstract class RegistryMiddleware implements Registry {
354
202
  protected readonly inner: Registry;
355
203
  constructor(inner: Registry);
356
- supportType(type: BundledType3): void;
357
- link(path: string): Promise<void>;
358
- add(source: string | RXR4): Promise<void>;
359
- get(locator: string): Promise<RXR4>;
360
- resolve<
361
- TArgs = void,
362
- TResult = unknown
363
- >(locator: string): Promise<ResolvedResource2<TArgs, TResult>>;
364
- exists(locator: string): Promise<boolean>;
365
- delete(locator: string): Promise<void>;
366
- search(options?: SearchOptions): Promise<RXL4[]>;
204
+ get(rxl: RXL5): Promise<RXR5>;
205
+ put(rxr: RXR5): Promise<void>;
206
+ has(rxl: RXL5): Promise<boolean>;
207
+ remove(rxl: RXL5): Promise<void>;
208
+ list(options?: SearchOptions): Promise<RXL5[]>;
367
209
  }
368
- import { RXR as RXR5 } from "@resourcexjs/core";
369
- import { ResolvedResource as ResolvedResource3 } from "@resourcexjs/type";
210
+ import { RXR as RXR6, RXL as RXL6 } from "@resourcexjs/core";
370
211
  /**
371
212
  * Domain validation middleware.
372
213
  * Ensures all resources from this registry match the trusted domain.
@@ -381,20 +222,13 @@ declare class DomainValidation extends RegistryMiddleware {
381
222
  /**
382
223
  * Get resource and validate domain.
383
224
  */
384
- get(locator: string): Promise<RXR5>;
385
- /**
386
- * Resolve resource and validate domain.
387
- */
388
- resolve<
389
- TArgs = void,
390
- TResult = unknown
391
- >(locator: string): Promise<ResolvedResource3<TArgs, TResult>>;
225
+ get(rxl: RXL6): Promise<RXR6>;
392
226
  }
393
227
  /**
394
228
  * Factory function to create domain validation middleware.
395
229
  *
396
230
  * @example
397
- * const registry = withDomainValidation(gitRegistry, "deepractice.ai");
231
+ * const registry = withDomainValidation(hostedRegistry, "deepractice.ai");
398
232
  */
399
233
  declare function withDomainValidation(registry: Registry, trustedDomain: string): Registry;
400
- export { withDomainValidation, discoverRegistry, createRegistry, WellKnownResponse, Storage, ServerRegistryConfig, SearchOptions, RegistryMiddleware, RegistryError, RegistryConfig, Registry, LocalStorageConfig, LocalStorage, DomainValidation, DiscoveryResult, DefaultRegistry, CreateRegistryConfig, ClientRegistryConfig };
234
+ export { withDomainValidation, discoverRegistry, WellKnownResponse, SearchOptions, RegistryMiddleware, RegistryError, Registry, MirrorRegistry, LinkedRegistry, HostedRegistry, DomainValidation, DiscoveryResult };