@resourcexjs/registry 1.7.0 → 2.1.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 CHANGED
@@ -10,36 +10,47 @@ bun add @resourcexjs/registry
10
10
 
11
11
  ## Overview
12
12
 
13
- The `@resourcexjs/registry` package provides a Maven-style registry for storing and resolving resources locally.
13
+ The `@resourcexjs/registry` package provides a Maven-style registry for storing and resolving resources (local or remote).
14
14
 
15
15
  ### Key Concepts
16
16
 
17
17
  - **Registry**: Interface for resource storage and retrieval
18
- - **ARPRegistry**: Implementation using ARP (Agent Resource Protocol) for I/O
19
- - **Local-first**: Resources cached locally at `~/.resourcex`
20
- - **Maven-style**: Organized by `domain/path/name.type@version`
18
+ - **LocalRegistry**: Filesystem-based implementation for local storage
19
+ - **RemoteRegistry**: HTTP API-based implementation for remote access
20
+ - **Well-known discovery**: Auto-discover registry endpoint via `/.well-known/resourcex`
21
+ - **Maven-style**: Organized by `domain/path/name.type/version`
21
22
 
22
23
  ## Usage
23
24
 
24
25
  ### Create Registry
25
26
 
26
27
  ```typescript
27
- import { createRegistry } from "@resourcexjs/registry";
28
+ import { createRegistry, discoverRegistry } from "@resourcexjs/registry";
28
29
 
29
- // Default configuration (~/.resourcex)
30
+ // Local registry (default)
30
31
  const registry = createRegistry();
31
32
 
32
- // Custom path
33
- const registry = createRegistry({
33
+ // Local registry with custom path
34
+ const registry2 = createRegistry({
34
35
  path: "./my-registry",
35
36
  });
36
37
 
37
- // With extension types
38
+ // Local registry with extension types
38
39
  import { promptType } from "@my-org/types";
39
40
 
40
- const registry = createRegistry({
41
+ const registry3 = createRegistry({
42
+ path: "~/.resourcex",
41
43
  types: [promptType],
42
44
  });
45
+
46
+ // Remote registry
47
+ const registry4 = createRegistry({
48
+ endpoint: "https://registry.deepractice.ai/v1",
49
+ });
50
+
51
+ // Remote registry with well-known discovery
52
+ const endpoint = await discoverRegistry("deepractice.ai");
53
+ const registry5 = createRegistry({ endpoint });
43
54
  ```
44
55
 
45
56
  ### Link Resource
@@ -201,30 +212,59 @@ const all = await registry.search();
201
212
 
202
213
  ## Storage Structure
203
214
 
204
- Resources are stored in Maven-style structure:
215
+ Resources are stored in two separate areas:
216
+
217
+ - **local/** - Development resources (organized by name.type/version)
218
+ - **cache/** - Remote cached resources (organized by domain/path/name.type/version)
205
219
 
206
220
  ```
207
221
  ~/.resourcex/
208
- └── {domain}/
209
- └── {path}/
210
- └── {name}.{type}@{version}/
211
- ├── manifest.json # RXM metadata
212
- └── content # Serialized content
222
+ ├── local/ # Development area
223
+ └── {name}.{type}/
224
+ └── {version}/
225
+ ├── manifest.json
226
+ └── content.tar.gz
227
+
228
+ └── cache/ # Remote cache area
229
+ └── {domain}/
230
+ └── {path}/
231
+ └── {name}.{type}/
232
+ └── {version}/
233
+ ├── manifest.json
234
+ └── content.tar.gz
213
235
  ```
214
236
 
215
237
  ### Example
216
238
 
217
- For resource `deepractice.ai/prompts/assistant.prompt@1.0.0`:
239
+ For a local development resource `my-prompt.text@1.0.0`:
240
+
241
+ ```
242
+ ~/.resourcex/
243
+ └── local/
244
+ └── my-prompt.text/
245
+ └── 1.0.0/
246
+ ├── manifest.json # domain can be "deepractice.ai" or "localhost"
247
+ └── content.tar.gz
248
+ ```
249
+
250
+ For a cached remote resource `deepractice.ai/prompts/assistant.text@1.0.0`:
218
251
 
219
252
  ```
220
253
  ~/.resourcex/
221
- └── deepractice.ai/
222
- └── prompts/
223
- └── assistant.prompt@1.0.0/
224
- ├── manifest.json
225
- └── content
254
+ └── cache/
255
+ └── deepractice.ai/
256
+ └── prompts/
257
+ └── assistant.text/
258
+ └── 1.0.0/
259
+ ├── manifest.json
260
+ └── content.tar.gz
226
261
  ```
227
262
 
263
+ ### Resolution Order
264
+
265
+ 1. **local/** is checked first (development resources)
266
+ 2. **cache/** is checked second (remote cached resources)
267
+
228
268
  **manifest.json:**
229
269
 
230
270
  ```json
@@ -237,7 +277,7 @@ For resource `deepractice.ai/prompts/assistant.prompt@1.0.0`:
237
277
  }
238
278
  ```
239
279
 
240
- **content:** (serialized by type's serializer)
280
+ **content.tar.gz:** Archive containing resource files (managed by TypeHandlerChain)
241
281
 
242
282
  ## Extension Types
243
283
 
@@ -373,31 +413,47 @@ await registry.link(agentResource);
373
413
 
374
414
  ## Resolution Strategy
375
415
 
376
- 1. **Check local registry** (`~/.resourcex` or custom path)
377
- 2. **If not found**: (TODO) Fetch from remote registry based on domain
378
- 3. **Cache locally** after fetching
379
- 4. **Return** resource
416
+ ### LocalRegistry
417
+
418
+ 1. **Check local filesystem** (`~/.resourcex` or custom path)
419
+ 2. **If not found**: Throw RegistryError
420
+ 3. **Return** RXR
421
+
422
+ ### RemoteRegistry
423
+
424
+ 1. **Fetch from HTTP API** (`GET /resource` + `GET /content`)
425
+ 2. **Return** RXR (no local caching)
426
+
427
+ ### Future: Hybrid Strategy (TODO)
380
428
 
381
- Currently only local resolution is implemented. Remote fetching is planned.
429
+ 1. Check local cache first
430
+ 2. If not found, fetch from remote based on domain
431
+ 3. Cache locally
432
+ 4. Return RXR
382
433
 
383
434
  ## Architecture
384
435
 
385
436
  ```
386
- ┌─────────────────────────────────────┐
387
- Registry Interface
388
- └──────────────┬──────────────────────┘
389
-
390
- ┌──────▼──────┐
391
- ARPRegistry
392
- │(implements) │
393
- └──────┬──────┘
394
-
395
- ┌─────────┴─────────┐
396
-
397
- ┌────▼────┐ ┌──────▼──────┐
398
- ARP TypeHandler
399
- (I/O) Chain │
400
- └─────────┘ └─────────────┘
437
+ ┌─────────────────────────────────────────┐
438
+ Registry Interface
439
+ └────────────┬────────────────────────────┘
440
+
441
+ ┌────────┴────────┐
442
+
443
+ ┌───▼──────────┐ ┌──▼──────────────┐
444
+ │LocalRegistry │ │RemoteRegistry │
445
+ (filesystem) │ │(HTTP API) │
446
+ └───┬──────────┘ └──┬──────────────┘
447
+
448
+ ┌───▼───────┐ ┌──▼──────┐
449
+ Node.js fetch
450
+ fs module │
451
+ └───────────┘ └─────────┘
452
+ │ │
453
+ ┌────▼────────────────▼─────┐
454
+ │ TypeHandlerChain │
455
+ │ (serialization logic) │
456
+ └───────────────────────────┘
401
457
  ```
402
458
 
403
459
  ## Type Safety
package/dist/index.d.ts CHANGED
@@ -27,14 +27,59 @@ interface RemoteRegistryConfig {
27
27
  endpoint: string;
28
28
  }
29
29
  /**
30
- * Registry configuration - either local or remote.
30
+ * Git registry configuration.
31
+ * Uses git clone to fetch registry content.
31
32
  */
32
- type RegistryConfig = LocalRegistryConfig | RemoteRegistryConfig;
33
+ interface GitRegistryConfig {
34
+ type: "git";
35
+ /** Git repository URL (SSH format: git@github.com:owner/repo.git) */
36
+ url: string;
37
+ /** Git ref (branch, tag, or commit). Default: "main" */
38
+ ref?: string;
39
+ /** Base path in repo for resources. Default: ".resourcex" */
40
+ basePath?: string;
41
+ /**
42
+ * Trusted domain for this registry.
43
+ * If set, only resources with this domain in manifest are allowed.
44
+ * Required for security - prevents untrusted registries from claiming any domain.
45
+ */
46
+ domain?: string;
47
+ }
48
+ /**
49
+ * Well-known discovery response format.
50
+ * Used by discoverRegistry() to find registry for a domain.
51
+ */
52
+ interface WellKnownResponse {
53
+ version: string;
54
+ /**
55
+ * List of registry URLs (git or http).
56
+ * First one is primary, rest are fallbacks (for future use).
57
+ */
58
+ registries: string[];
59
+ }
60
+ /**
61
+ * Result from discoverRegistry().
62
+ * Contains domain and its authorized registries.
63
+ */
64
+ interface DiscoveryResult {
65
+ /** The domain that was discovered */
66
+ domain: string;
67
+ /** Authorized registry URLs for this domain */
68
+ registries: string[];
69
+ }
70
+ /**
71
+ * Registry configuration - local, remote, or git.
72
+ */
73
+ type RegistryConfig = LocalRegistryConfig | RemoteRegistryConfig | GitRegistryConfig;
33
74
  /**
34
75
  * Type guard to check if config is for remote registry.
35
76
  */
36
77
  declare function isRemoteConfig(config?: RegistryConfig): config is RemoteRegistryConfig;
37
78
  /**
79
+ * Type guard to check if config is for git registry.
80
+ */
81
+ declare function isGitConfig(config?: RegistryConfig): config is GitRegistryConfig;
82
+ /**
38
83
  * Search options for querying resources.
39
84
  */
40
85
  interface SearchOptions {
@@ -52,6 +97,36 @@ interface SearchOptions {
52
97
  offset?: number;
53
98
  }
54
99
  /**
100
+ * Options for pulling resources from remote registry.
101
+ */
102
+ interface PullOptions {
103
+ /**
104
+ * Pull from a specific registry instead of auto-discovering.
105
+ */
106
+ from?: Registry;
107
+ }
108
+ /**
109
+ * Target configuration for publishing resources.
110
+ */
111
+ interface PublishTarget {
112
+ type: "http" | "git";
113
+ /** HTTP endpoint (for type: "http") */
114
+ endpoint?: string;
115
+ /** Git repository URL (for type: "git") */
116
+ url?: string;
117
+ /** Git ref - branch/tag (for type: "git"). Default: "main" */
118
+ ref?: string;
119
+ }
120
+ /**
121
+ * Options for publishing resources to remote registry.
122
+ */
123
+ interface PublishOptions {
124
+ /**
125
+ * Target registry configuration.
126
+ */
127
+ to: PublishTarget;
128
+ }
129
+ /**
55
130
  * Registry interface for resource storage and retrieval.
56
131
  */
57
132
  interface Registry {
@@ -61,9 +136,19 @@ interface Registry {
61
136
  */
62
137
  supportType(type: ResourceType): void;
63
138
  /**
64
- * Publish resource to remote registry (based on domain).
139
+ * Pull resource from remote registry to local cache.
140
+ * Discovers remote registry via well-known and caches locally.
141
+ * @param locator - Resource locator (must include domain)
142
+ * @param options - Pull options
143
+ */
144
+ pull(locator: string, options?: PullOptions): Promise<void>;
145
+ /**
146
+ * Publish resource to remote registry.
147
+ * Resource must exist in local first.
148
+ * @param resource - Resource to publish
149
+ * @param options - Publish target configuration
65
150
  */
66
- publish(resource: RXR): Promise<void>;
151
+ publish(resource: RXR, options: PublishOptions): Promise<void>;
67
152
  /**
68
153
  * Link resource to local registry (for development/caching).
69
154
  */
@@ -103,25 +188,54 @@ import { ResourceXError } from "@resourcexjs/core";
103
188
  * Registry-specific error.
104
189
  */
105
190
  declare class RegistryError extends ResourceXError {
106
- constructor(message: string);
191
+ constructor(message: string, options?: ErrorOptions);
107
192
  }
108
193
  import { RXR as RXR2, RXL as RXL2 } from "@resourcexjs/core";
109
194
  import { ResourceType as ResourceType2, ResolvedResource as ResolvedResource2 } from "@resourcexjs/type";
110
195
  /**
111
196
  * Local filesystem-based registry implementation.
112
- * Uses Node.js fs module directly for storage operations.
197
+ * Uses ARP file transport for I/O operations.
113
198
  */
114
199
  declare class LocalRegistry implements Registry {
115
200
  private readonly basePath;
116
201
  private readonly typeHandler;
202
+ private readonly arp;
117
203
  constructor(config?: LocalRegistryConfig);
118
204
  supportType(type: ResourceType2): void;
119
205
  /**
206
+ * Create ARP URL for a file path.
207
+ */
208
+ private toArpUrl;
209
+ /**
120
210
  * Build filesystem path for a resource.
121
- * Path structure: {basePath}/{domain}/{path}/{name}.{type}/{version}
211
+ *
212
+ * Storage structure:
213
+ * - local: {basePath}/local/{name}.{type}/{version}
214
+ * - cache: {basePath}/cache/{domain}/{path}/{name}.{type}/{version}
215
+ *
216
+ * @param locator - Resource locator
217
+ * @param area - Storage area ("local" or "cache")
122
218
  */
123
219
  private buildPath;
124
- publish(_resource: RXR2): Promise<void>;
220
+ /**
221
+ * Determine if a locator refers to a local-only resource (no domain or localhost).
222
+ */
223
+ private isLocalOnlyLocator;
224
+ /**
225
+ * Check if a resource exists at a specific path.
226
+ */
227
+ private existsAt;
228
+ /**
229
+ * Find which area a resource exists in.
230
+ * Returns the area ("local" or "cache") or null if not found.
231
+ */
232
+ private findArea;
233
+ /**
234
+ * Load resource from a specific path.
235
+ */
236
+ private loadFrom;
237
+ pull(_locator: string, _options?: PullOptions): Promise<void>;
238
+ publish(_resource: RXR2, _options: PublishOptions): Promise<void>;
125
239
  link(resource: RXR2): Promise<void>;
126
240
  get(locator: string): Promise<RXR2>;
127
241
  resolve<
@@ -132,14 +246,19 @@ declare class LocalRegistry implements Registry {
132
246
  delete(locator: string): Promise<void>;
133
247
  search(options?: SearchOptions): Promise<RXL2[]>;
134
248
  /**
135
- * Recursively list all files in a directory.
249
+ * Parse a local entry path to RXL.
250
+ * Entry format: {name}.{type}/{version}/manifest.json
136
251
  */
137
- private listRecursive;
252
+ private parseLocalEntry;
138
253
  /**
139
- * Parse a file entry path to RXL.
254
+ * Parse a cache entry path to RXL.
140
255
  * Entry format: {domain}/{path}/{name}.{type}/{version}/manifest.json
141
256
  */
142
- private parseEntryToRXL;
257
+ private parseCacheEntry;
258
+ /**
259
+ * Parse name and type from a combined string like "name.type" or "name".
260
+ */
261
+ private parseNameType;
143
262
  }
144
263
  import { RXR as RXR3, RXL as RXL3 } from "@resourcexjs/core";
145
264
  import { ResourceType as ResourceType3, ResolvedResource as ResolvedResource3 } from "@resourcexjs/type";
@@ -152,7 +271,8 @@ declare class RemoteRegistry implements Registry {
152
271
  private readonly typeHandler;
153
272
  constructor(config: RemoteRegistryConfig);
154
273
  supportType(type: ResourceType3): void;
155
- publish(_resource: RXR3): Promise<void>;
274
+ pull(_locator: string, _options?: PullOptions): Promise<void>;
275
+ publish(_resource: RXR3, _options: PublishOptions): Promise<void>;
156
276
  link(_resource: RXR3): Promise<void>;
157
277
  get(locator: string): Promise<RXR3>;
158
278
  resolve<
@@ -164,17 +284,75 @@ declare class RemoteRegistry implements Registry {
164
284
  search(options?: SearchOptions): Promise<RXL3[]>;
165
285
  }
166
286
  /**
167
- * Discover registry endpoint for a domain using well-known.
287
+ * Discover registry for a domain using well-known.
168
288
  * @param domain - The domain to discover (e.g., "deepractice.ai")
169
- * @returns The registry endpoint URL
289
+ * @returns Discovery result with domain and authorized registries
170
290
  */
171
- declare function discoverRegistry(domain: string): Promise<string>;
291
+ declare function discoverRegistry(domain: string): Promise<DiscoveryResult>;
292
+ import { RXR as RXR4, RXL as RXL4 } from "@resourcexjs/core";
293
+ import { ResourceType as ResourceType4, ResolvedResource as ResolvedResource4 } from "@resourcexjs/type";
294
+ /**
295
+ * Git-based registry implementation.
296
+ * Clones a git repository and reads resources from it.
297
+ */
298
+ declare class GitRegistry implements Registry {
299
+ private readonly url;
300
+ private readonly ref;
301
+ private readonly basePath;
302
+ private readonly cacheDir;
303
+ private readonly typeHandler;
304
+ private readonly arp;
305
+ constructor(config: GitRegistryConfig);
306
+ /**
307
+ * Build cache directory name from git URL.
308
+ * git@github.com:Deepractice/Registry.git → github.com-Deepractice-Registry
309
+ */
310
+ private buildCacheDir;
311
+ supportType(type: ResourceType4): void;
312
+ /**
313
+ * Create ARP URL for a file path.
314
+ */
315
+ private toArpUrl;
316
+ /**
317
+ * Ensure the repository is cloned and up to date.
318
+ */
319
+ private ensureCloned;
320
+ /**
321
+ * Get the default branch name (main or master).
322
+ */
323
+ private getDefaultBranch;
324
+ /**
325
+ * Execute git command in the cache directory.
326
+ */
327
+ private gitExec;
328
+ /**
329
+ * Build filesystem path for a resource in the cloned repo.
330
+ * Path structure: {cacheDir}/{basePath}/{domain}/{path}/{name}.{type}/{version}
331
+ */
332
+ private buildResourcePath;
333
+ get(locator: string): Promise<RXR4>;
334
+ resolve<
335
+ TArgs = void,
336
+ TResult = unknown
337
+ >(locator: string): Promise<ResolvedResource4<TArgs, TResult>>;
338
+ exists(locator: string): Promise<boolean>;
339
+ search(options?: SearchOptions): Promise<RXL4[]>;
340
+ private parseEntryToRXL;
341
+ pull(_locator: string, _options?: PullOptions): Promise<void>;
342
+ publish(_resource: RXR4, _options: PublishOptions): Promise<void>;
343
+ link(_resource: RXR4): Promise<void>;
344
+ delete(_locator: string): Promise<void>;
345
+ }
172
346
  /**
173
347
  * Create a registry instance.
174
348
  *
349
+ * When a `domain` is provided in GitRegistryConfig, the registry is automatically
350
+ * wrapped with DomainValidation middleware for security.
351
+ *
175
352
  * @param config - Registry configuration
176
353
  * - No config or LocalRegistryConfig: Creates LocalRegistry (filesystem-based)
177
354
  * - RemoteRegistryConfig: Creates RemoteRegistry (HTTP-based)
355
+ * - GitRegistryConfig: Creates GitRegistry (git clone-based)
178
356
  *
179
357
  * @example
180
358
  * // Local registry (default)
@@ -183,6 +361,68 @@ declare function discoverRegistry(domain: string): Promise<string>;
183
361
  *
184
362
  * // Remote registry
185
363
  * const registry3 = createRegistry({ endpoint: "https://registry.deepractice.ai/v1" });
364
+ *
365
+ * // Git registry (requires domain for remote URLs)
366
+ * const registry4 = createRegistry({
367
+ * type: "git",
368
+ * url: "git@github.com:Deepractice/Registry.git",
369
+ * domain: "deepractice.ai", // Auto-wrapped with DomainValidation
370
+ * });
186
371
  */
187
372
  declare function createRegistry(config?: RegistryConfig): Registry;
188
- export { isRemoteConfig, discoverRegistry, createRegistry, SearchOptions, RemoteRegistryConfig, RemoteRegistry, RegistryError, RegistryConfig, Registry, LocalRegistryConfig, LocalRegistry };
373
+ import { RXR as RXR5, RXL as RXL5 } from "@resourcexjs/core";
374
+ import { ResourceType as ResourceType5, ResolvedResource as ResolvedResource5 } from "@resourcexjs/type";
375
+ /**
376
+ * Base class for Registry middleware.
377
+ * Delegates all operations to the inner registry.
378
+ * Override specific methods to add custom behavior.
379
+ */
380
+ declare abstract class RegistryMiddleware implements Registry {
381
+ protected readonly inner: Registry;
382
+ constructor(inner: Registry);
383
+ supportType(type: ResourceType5): void;
384
+ pull(locator: string, options?: PullOptions): Promise<void>;
385
+ publish(resource: RXR5, options: PublishOptions): Promise<void>;
386
+ link(resource: RXR5): Promise<void>;
387
+ get(locator: string): Promise<RXR5>;
388
+ resolve<
389
+ TArgs = void,
390
+ TResult = unknown
391
+ >(locator: string): Promise<ResolvedResource5<TArgs, TResult>>;
392
+ exists(locator: string): Promise<boolean>;
393
+ delete(locator: string): Promise<void>;
394
+ search(options?: SearchOptions): Promise<RXL5[]>;
395
+ }
396
+ import { RXR as RXR6 } from "@resourcexjs/core";
397
+ import { ResolvedResource as ResolvedResource6 } from "@resourcexjs/type";
398
+ /**
399
+ * Domain validation middleware.
400
+ * Ensures all resources from this registry match the trusted domain.
401
+ */
402
+ declare class DomainValidation extends RegistryMiddleware {
403
+ private readonly trustedDomain;
404
+ constructor(inner: Registry, trustedDomain: string);
405
+ /**
406
+ * Validate that manifest domain matches trusted domain.
407
+ */
408
+ private validateDomain;
409
+ /**
410
+ * Get resource and validate domain.
411
+ */
412
+ get(locator: string): Promise<RXR6>;
413
+ /**
414
+ * Resolve resource and validate domain.
415
+ */
416
+ resolve<
417
+ TArgs = void,
418
+ TResult = unknown
419
+ >(locator: string): Promise<ResolvedResource6<TArgs, TResult>>;
420
+ }
421
+ /**
422
+ * Factory function to create domain validation middleware.
423
+ *
424
+ * @example
425
+ * const registry = withDomainValidation(gitRegistry, "deepractice.ai");
426
+ */
427
+ declare function withDomainValidation(registry: Registry, trustedDomain: string): Registry;
428
+ export { withDomainValidation, isRemoteConfig, isGitConfig, discoverRegistry, createRegistry, WellKnownResponse, SearchOptions, RemoteRegistryConfig, RemoteRegistry, RegistryMiddleware, RegistryError, RegistryConfig, Registry, PullOptions, PublishTarget, PublishOptions, LocalRegistryConfig, LocalRegistry, GitRegistryConfig, GitRegistry, DomainValidation, DiscoveryResult };