@resourcexjs/type 2.2.0 → 2.4.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,16 +1,64 @@
1
- import { RXR, RXM } from "@resourcexjs/core";
2
1
  /**
3
- * ResourceSerializer - Handles RXR serialization/deserialization for storage.
2
+ * Isolator type for resolver execution.
3
+ * Matches SandboX isolator types directly.
4
+ * Configured at Registry level, not per-type.
5
+ *
6
+ * - "none": No isolation, fastest (~10ms), for development
7
+ * - "srt": OS-level isolation (~50ms), secure local dev
8
+ * - "cloudflare": Container isolation (~100ms), local Docker or edge
9
+ * - "e2b": MicroVM isolation (~150ms), production (planned)
4
10
  */
5
- interface ResourceSerializer {
11
+ type IsolatorType = "none" | "srt" | "cloudflare" | "e2b";
12
+ /**
13
+ * ResolveContext - Pure data context passed to resolver in sandbox.
14
+ *
15
+ * This is a serializable data structure that replaces RXR for sandbox execution.
16
+ * The executor pre-processes RXR (extracts files) before passing to resolver.
17
+ */
18
+ interface ResolveContext {
6
19
  /**
7
- * Serialize RXR to storage format.
20
+ * Resource manifest metadata.
8
21
  */
9
- serialize(rxr: RXR): Promise<Buffer>;
22
+ manifest: {
23
+ domain: string
24
+ path?: string
25
+ name: string
26
+ type: string
27
+ version: string
28
+ };
10
29
  /**
11
- * Deserialize storage data to RXR.
30
+ * Extracted files from archive.
31
+ * Key is file path, value is file content as Uint8Array.
12
32
  */
13
- deserialize(data: Buffer, manifest: RXM): Promise<RXR>;
33
+ files: Record<string, Uint8Array>;
34
+ }
35
+ /**
36
+ * BundledType - Pre-bundled resource type ready for execution.
37
+ * Contains bundled code string instead of closure.
38
+ *
39
+ * Note: Sandbox isolation is configured at Registry level via createRegistry({ sandbox: ... })
40
+ */
41
+ interface BundledType {
42
+ /**
43
+ * Type name (e.g., "text", "json", "prompt").
44
+ */
45
+ name: string;
46
+ /**
47
+ * Alternative names for this type.
48
+ */
49
+ aliases?: string[];
50
+ /**
51
+ * Human-readable description.
52
+ */
53
+ description: string;
54
+ /**
55
+ * JSON Schema for resolver arguments.
56
+ */
57
+ schema?: JSONSchema;
58
+ /**
59
+ * Bundled resolver code (executable in sandbox).
60
+ */
61
+ code: string;
14
62
  }
15
63
  /**
16
64
  * JSON Schema property definition.
@@ -41,9 +89,9 @@ interface ResolvedResource<
41
89
  TResult = unknown
42
90
  > {
43
91
  /**
44
- * Original RXR object (locator, manifest, content).
92
+ * Original resource object (RXR from @resourcexjs/core).
45
93
  */
46
- resource: RXR;
94
+ resource: unknown;
47
95
  /**
48
96
  * Execute function to get the resource content.
49
97
  * - For static resources (text/json/binary): call with no arguments
@@ -57,7 +105,7 @@ interface ResolvedResource<
57
105
  schema: TArgs extends void ? undefined : JSONSchema;
58
106
  }
59
107
  /**
60
- * ResourceResolver - Transforms RXR into a structured result object.
108
+ * ResourceResolver - Transforms resource into a structured result object.
61
109
  * The execute function is lazy-loaded: content is only read when called.
62
110
  */
63
111
  interface ResourceResolver<
@@ -70,9 +118,10 @@ interface ResourceResolver<
70
118
  */
71
119
  schema: TArgs extends void ? undefined : JSONSchema;
72
120
  /**
73
- * Resolve RXR into a structured result object.
121
+ * Resolve resource into a structured result object.
122
+ * @param rxr - RXR object from @resourcexjs/core
74
123
  */
75
- resolve(rxr: RXR): Promise<ResolvedResource<TArgs, TResult>>;
124
+ resolve(rxr: unknown): Promise<ResolvedResource<TArgs, TResult>>;
76
125
  }
77
126
  /**
78
127
  * ResourceType - Defines how a resource type is handled.
@@ -94,14 +143,23 @@ interface ResourceType<
94
143
  */
95
144
  description: string;
96
145
  /**
97
- * Serializer for storage operations.
98
- */
99
- serializer: ResourceSerializer;
100
- /**
101
146
  * Resolver to transform RXR into structured result object.
102
147
  */
103
148
  resolver: ResourceResolver<TArgs, TResult>;
104
149
  }
150
+ /**
151
+ * Bundle a resource type from a source file.
152
+ *
153
+ * @param sourcePath - Path to the .type.ts file
154
+ * @param basePath - Base path for resolving relative paths (defaults to cwd)
155
+ * @returns BundledType ready for registry
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const promptType = await bundleResourceType("./prompt.type.ts");
160
+ * ```
161
+ */
162
+ declare function bundleResourceType(sourcePath: string, basePath?: string): Promise<BundledType>;
105
163
  import { ResourceXError } from "@resourcexjs/core";
106
164
  /**
107
165
  * Resource type related error.
@@ -110,78 +168,69 @@ declare class ResourceTypeError extends ResourceXError {
110
168
  constructor(message: string);
111
169
  }
112
170
  /**
113
- * Text resource type
114
- */
115
- declare const textType: ResourceType<void, string>;
116
- /**
117
- * JSON resource type
118
- */
119
- declare const jsonType: ResourceType<void, unknown>;
120
- /**
121
- * Binary resource type
122
- */
123
- declare const binaryType: ResourceType<void, Buffer>;
124
- /**
125
- * All built-in types
126
- */
127
- declare const builtinTypes: ResourceType<void, unknown>[];
128
- import { RXR as RXR2, RXM as RXM2 } from "@resourcexjs/core";
129
- /**
130
- * TypeHandlerChain - Manages type registration and delegates serialization/deserialization.
131
- * Use TypeHandlerChain.create() to create a new instance.
171
+ * TypeHandlerChain - Manages resource type registration.
172
+ *
173
+ * Responsibilities:
174
+ * - Register types (name + aliases)
175
+ * - Look up types by name
176
+ *
177
+ * Execution is delegated to ResolverExecutor (in registry package).
178
+ *
179
+ * Built-in types (text, json, binary) are registered by default.
132
180
  */
133
181
  declare class TypeHandlerChain {
134
182
  private handlers;
135
183
  private constructor();
136
184
  /**
137
185
  * Create a new TypeHandlerChain instance.
138
- * Each instance includes all builtin types (text, json, binary).
186
+ * Built-in types (text, json, binary) are included by default.
139
187
  */
140
188
  static create(): TypeHandlerChain;
141
189
  /**
142
- * Register a builtin type (private, called during initialization).
190
+ * Internal registration (no duplicate check).
143
191
  */
144
- private registerBuiltin;
192
+ private registerInternal;
145
193
  /**
146
- * Register an extension type (public, for user-defined types).
194
+ * Register a type.
147
195
  * @throws ResourceTypeError if type is already registered
148
196
  */
149
- register(type: ResourceType): void;
197
+ register(type: BundledType): void;
150
198
  /**
151
199
  * Check if a type is supported.
152
200
  */
153
201
  canHandle(typeName: string): boolean;
154
202
  /**
155
203
  * Get handler for a type.
156
- */
157
- getHandler(typeName: string): ResourceType | undefined;
158
- /**
159
- * Get all supported type names (including aliases).
160
- */
161
- getSupportedTypes(): string[];
162
- /**
163
- * Serialize RXR content using the appropriate type handler.
164
204
  * @throws ResourceTypeError if type is not supported
165
205
  */
166
- serialize(rxr: RXR2): Promise<Buffer>;
206
+ getHandler(typeName: string): BundledType;
167
207
  /**
168
- * Deserialize content into RXR using the appropriate type handler.
169
- * @throws ResourceTypeError if type is not supported
208
+ * Get handler for a type, or undefined if not found.
170
209
  */
171
- deserialize(data: Buffer, manifest: RXM2): Promise<RXR2>;
210
+ getHandlerOrUndefined(typeName: string): BundledType | undefined;
172
211
  /**
173
- * Resolve RXR content into structured result object using the appropriate type handler.
174
- * Returns an object with execute function and optional schema.
175
- * @throws ResourceTypeError if type is not supported
212
+ * Get all supported type names (including aliases).
176
213
  */
177
- resolve<
178
- TArgs = void,
179
- TResult = unknown
180
- >(rxr: RXR2): Promise<ResolvedResource<TArgs, TResult>>;
214
+ getSupportedTypes(): string[];
181
215
  /**
182
- * Clear all extension types (for testing).
183
- * Keeps builtin types intact.
216
+ * Clear all registered types (for testing).
184
217
  */
185
- clearExtensions(): void;
218
+ clear(): void;
186
219
  }
187
- export { textType, jsonType, builtinTypes, binaryType, TypeHandlerChain, ResourceTypeError, ResourceType, ResourceSerializer, ResourceResolver, ResolvedResource, JSONSchemaProperty, JSONSchema };
220
+ /**
221
+ * Plain text content
222
+ */
223
+ declare const textType: BundledType;
224
+ /**
225
+ * JSON content
226
+ */
227
+ declare const jsonType: BundledType;
228
+ /**
229
+ * Binary content
230
+ */
231
+ declare const binaryType: BundledType;
232
+ /**
233
+ * All built-in types as an array.
234
+ */
235
+ declare const builtinTypes: BundledType[];
236
+ export { textType, jsonType, bundleResourceType, builtinTypes, binaryType, TypeHandlerChain, ResourceTypeError, ResourceType, ResourceResolver, ResolvedResource, ResolveContext, JSONSchemaProperty, JSONSchema, IsolatorType, BundledType };