@resourcexjs/core 2.4.1 → 2.5.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.
package/dist/index.d.ts CHANGED
@@ -14,130 +14,167 @@ declare class ManifestError extends ResourceXError {
14
14
  declare class ContentError extends ResourceXError {
15
15
  constructor(message: string);
16
16
  }
17
+ declare class DefinitionError extends ResourceXError {
18
+ constructor(message: string);
19
+ }
17
20
  /**
18
- * RXL - ResourceX Locator
21
+ * RXD - ResourceX Definition
19
22
  *
20
- * Format: [domain/path/]name[.type][@version]
23
+ * The content of resource.json file.
24
+ * Contains all metadata for a resource in development.
21
25
  */
22
- interface RXL {
23
- readonly domain?: string;
24
- readonly path?: string;
26
+ interface RXD {
25
27
  readonly name: string;
26
- readonly type?: string;
27
- readonly version?: string;
28
- toString(): string;
28
+ readonly type: string;
29
+ readonly tag?: string;
30
+ readonly registry?: string;
31
+ readonly path?: string;
32
+ readonly description?: string;
33
+ readonly author?: string;
34
+ readonly license?: string;
35
+ readonly keywords?: string[];
36
+ readonly repository?: string;
37
+ readonly [key: string]: unknown;
29
38
  }
30
39
  /**
31
- * Parse a resource locator string into RXL object.
40
+ * RXL - ResourceX Locator
41
+ *
42
+ * Unique identifier for a resource (pure data object).
43
+ * Docker-style format with optional tag.
44
+ *
45
+ * Format: [registry/][path/]name[:tag]
32
46
  *
33
- * Format: [domain/path/]name[.type][@version]
47
+ * Examples:
48
+ * - hello → name=hello, tag=latest (default)
49
+ * - hello:1.0.0 → name=hello, tag=1.0.0
50
+ * - prompts/hello:stable → path=prompts, name=hello, tag=stable
51
+ * - localhost:3098/hello:1.0.0 → registry=localhost:3098, name=hello, tag=1.0.0
52
+ * - registry.example.com/org/hello:latest → registry=registry.example.com, path=org, name=hello, tag=latest
34
53
  */
35
- declare function parseRXL(locator: string): RXL;
54
+ interface RXL {
55
+ /** Registry host:port (e.g., "localhost:3098", "registry.example.com") */
56
+ readonly registry?: string;
57
+ /** Path within registry (e.g., "org", "prompts") */
58
+ readonly path?: string;
59
+ /** Resource name */
60
+ readonly name: string;
61
+ /** Tag (version or label). Defaults to "latest" if not specified. */
62
+ readonly tag: string;
63
+ }
36
64
  /**
37
65
  * RXM - ResourceX Manifest
66
+ *
67
+ * Resource metadata stored within the resource (pure data object).
38
68
  */
39
69
  interface RXM {
40
- readonly domain: string;
70
+ readonly registry?: string;
41
71
  readonly path?: string;
42
72
  readonly name: string;
43
73
  readonly type: string;
44
- readonly version: string;
45
- toLocator(): string;
46
- toJSON(): ManifestData;
47
- }
48
- interface ManifestData {
49
- domain?: string;
50
- path?: string;
51
- name?: string;
52
- type?: string;
53
- version?: string;
54
- }
55
- /**
56
- * Create a manifest from data object.
57
- */
58
- declare function createRXM(data: ManifestData): RXM;
59
- /**
60
- * PathNode - Tree structure node for package file hierarchy.
61
- */
62
- interface PathNode {
63
- /** File or directory name */
64
- name: string;
65
- /** Node type */
66
- type: "file" | "directory";
67
- /** Children nodes (only for directories) */
68
- children?: PathNode[];
74
+ readonly tag: string;
75
+ readonly files?: string[];
69
76
  }
70
77
  /**
71
78
  * RXA - ResourceX Archive
72
79
  *
73
80
  * Archive container (tar.gz format) for storage and transfer.
74
- * Use extract() to get RXP for file access.
75
81
  */
76
82
  interface RXA {
77
83
  /** Content as a readable stream (tar.gz format) */
78
84
  readonly stream: ReadableStream<Uint8Array>;
79
85
  /** Get raw archive buffer (tar.gz format) */
80
86
  buffer(): Promise<Buffer>;
81
- /** Extract archive to package for file access */
82
- extract(): Promise<RXP>;
83
87
  }
84
88
  /**
85
- * RXP - ResourceX Package
89
+ * RXR - ResourceX Resource
86
90
  *
87
- * Extracted package for runtime file access.
88
- * Created from RXA.extract(), can pack back with pack().
91
+ * Complete resource object combining locator, manifest, and archive.
89
92
  */
90
- interface RXP {
91
- /** Get flat list of all file paths */
92
- paths(): string[];
93
- /** Get tree structure of files and directories */
94
- tree(): PathNode[];
95
- /** Read a specific file from the package */
96
- file(path: string): Promise<Buffer>;
97
- /** Read all files from the package */
98
- files(): Promise<Map<string, Buffer>>;
99
- /** Pack back to archive */
100
- pack(): Promise<RXA>;
93
+ interface RXR {
94
+ readonly locator: RXL;
95
+ readonly manifest: RXM;
96
+ readonly archive: RXA;
101
97
  }
102
98
  /**
103
- * Input type for createRXA.
104
- * - Files record: { 'path/to/file': content }
105
- * - Buffer: { buffer: tarGzBuffer }
99
+ * Parse and validate a resource definition (resource.json content).
100
+ *
101
+ * @param input - The raw JSON object to parse
102
+ * @returns A validated RXD object
103
+ * @throws DefinitionError if validation fails
106
104
  */
107
- type RXAInput = Record<string, Buffer | Uint8Array | string> | {
108
- buffer: Buffer
109
- };
105
+ declare function define(input: unknown): RXD;
110
106
  /**
111
- * Create RXA from files or existing buffer.
112
- *
113
- * @example
114
- * ```typescript
115
- * // Single file
116
- * const archive = await createRXA({ 'content': Buffer.from('Hello') });
117
- *
118
- * // Multiple files
119
- * const archive = await createRXA({
120
- * 'index.ts': Buffer.from('1'),
121
- * 'styles.css': Buffer.from('body {}'),
122
- * });
123
- *
124
- * // From existing tar.gz buffer
125
- * const archive = await createRXA({ buffer: existingTarGzBuffer });
126
- *
127
- * // Extract to package
128
- * const pkg = await archive.extract();
129
- * const paths = pkg.paths();
130
- * const content = await pkg.file('index.ts');
131
- * ```
107
+ * Create RXM from RXD.
108
+ * Extracts only the core metadata fields (pure data object).
109
+ *
110
+ * @param rxd - Resource definition
111
+ * @returns RXM manifest object
132
112
  */
133
- declare function createRXA(input: RXAInput): Promise<RXA>;
113
+ declare function manifest(rxd: RXD): RXM;
134
114
  /**
135
- * RXR (ResourceX Resource) - Complete resource object.
136
- * A pure data transfer object combining locator, manifest, and archive.
115
+ * Create RXA from files.
116
+ *
117
+ * @param files - Record of file paths to Buffer contents
118
+ * @returns RXA archive object
137
119
  */
138
- interface RXR {
139
- locator: RXL;
140
- manifest: RXM;
141
- archive: RXA;
142
- }
143
- export { parseRXL, createRXM, createRXA, ResourceXError, RXR, RXP, RXM, RXL, RXAInput, RXA, PathNode, ManifestError, ManifestData, LocatorError, ContentError };
120
+ declare function archive(files: Record<string, Buffer>): Promise<RXA>;
121
+ /**
122
+ * Create RXL from RXM.
123
+ *
124
+ * @param rxm - Resource manifest
125
+ * @returns RXL locator object (pure data)
126
+ */
127
+ declare function locate(rxm: RXM): RXL;
128
+ /**
129
+ * Create RXR from RXM and RXA.
130
+ *
131
+ * @param rxm - Resource manifest
132
+ * @param rxa - Resource archive
133
+ * @returns RXR resource object
134
+ */
135
+ declare function resource(rxm: RXM, rxa: RXA): RXR;
136
+ /**
137
+ * Extract files from RXA.
138
+ *
139
+ * @param rxa - Resource archive
140
+ * @returns Record of file paths to Buffer contents
141
+ */
142
+ declare function extract(rxa: RXA): Promise<Record<string, Buffer>>;
143
+ /**
144
+ * Format RXL to locator string.
145
+ *
146
+ * Docker-style format: [registry/][path/]name[:tag]
147
+ *
148
+ * Examples:
149
+ * - { name: "hello", tag: "latest" } → "hello" (omit :latest)
150
+ * - { name: "hello", tag: "1.0.0" } → "hello:1.0.0"
151
+ * - { registry: "localhost:3098", name: "hello", tag: "1.0.0" } → "localhost:3098/hello:1.0.0"
152
+ *
153
+ * @param rxl - Resource locator
154
+ * @returns Locator string
155
+ */
156
+ declare function format(rxl: RXL): string;
157
+ /**
158
+ * Parse locator string to RXL.
159
+ *
160
+ * Docker-style format: [registry/][path/]name[:tag]
161
+ *
162
+ * Examples:
163
+ * - hello → name=hello, tag=latest
164
+ * - hello:1.0.0 → name=hello, tag=1.0.0
165
+ * - prompts/hello:stable → path=prompts, name=hello, tag=stable
166
+ * - localhost:3098/hello:1.0.0 → registry=localhost:3098, name=hello, tag=1.0.0
167
+ *
168
+ * @param locator - Locator string
169
+ * @returns RXL object
170
+ * @throws LocatorError if parsing fails
171
+ */
172
+ declare function parse(locator: string): RXL;
173
+ /**
174
+ * Wrap existing tar.gz buffer as RXA.
175
+ *
176
+ * @param buffer - Existing tar.gz buffer
177
+ * @returns RXA archive object
178
+ */
179
+ declare function wrap(buffer: Buffer): RXA;
180
+ export { wrap, resource, parse, manifest, locate, format, extract, define, archive, ResourceXError, RXR, RXM, RXL, RXD, RXA, ManifestError, LocatorError, DefinitionError, ContentError };