resourcexjs 0.0.2 → 0.0.3
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.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js.map
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../core/dist/index.js", "../src/ResourceX.ts", "../src/createResourceX.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"// src/errors.ts\nclass ResourceXError extends Error {\n constructor(message, options) {\n super(message, options);\n this.name = \"ResourceXError\";\n }\n}\n\nclass ParseError extends ResourceXError {\n url;\n constructor(message, url) {\n super(message);\n this.url = url;\n this.name = \"ParseError\";\n }\n}\n\nclass TransportError extends ResourceXError {\n transport;\n constructor(message, transport, options) {\n super(message, options);\n this.transport = transport;\n this.name = \"TransportError\";\n }\n}\n\nclass SemanticError extends ResourceXError {\n semantic;\n constructor(message, semantic, options) {\n super(message, options);\n this.semantic = semantic;\n this.name = \"SemanticError\";\n }\n}\n// src/parser.ts\nfunction parseARP(url) {\n if (!url.startsWith(\"arp:\")) {\n throw new ParseError(`Invalid ARP URL: must start with \"arp:\"`, url);\n }\n const content = url.substring(4);\n const separatorIndex = content.indexOf(\"://\");\n if (separatorIndex === -1) {\n throw new ParseError(`Invalid ARP URL: missing \"://\"`, url);\n }\n const typePart = content.substring(0, separatorIndex);\n const location = content.substring(separatorIndex + 3);\n const colonIndex = typePart.indexOf(\":\");\n if (colonIndex === -1) {\n throw new ParseError(`Invalid ARP URL: must have exactly 2 types (semantic:transport)`, url);\n }\n const semantic = typePart.substring(0, colonIndex);\n const transport = typePart.substring(colonIndex + 1);\n if (!semantic) {\n throw new ParseError(`Invalid ARP URL: semantic type cannot be empty`, url);\n }\n if (!transport) {\n throw new ParseError(`Invalid ARP URL: transport type cannot be empty`, url);\n }\n if (!location) {\n throw new ParseError(`Invalid ARP URL: location cannot be empty`, url);\n }\n return { semantic, transport, location };\n}\n// src/transport/http.ts\nclass HttpTransportHandler {\n type;\n protocol;\n constructor(protocol = \"https\") {\n this.protocol = protocol;\n this.type = protocol;\n }\n async fetch(location) {\n const url = `${this.protocol}://${location}`;\n try {\n const response = await fetch(url);\n if (!response.ok) {\n throw new TransportError(`HTTP ${response.status}: ${response.statusText} - ${url}`, this.type);\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n } catch (error) {\n if (error instanceof TransportError) {\n throw error;\n }\n throw new TransportError(`Network error: ${url}`, this.type, { cause: error });\n }\n }\n}\nvar httpsHandler = new HttpTransportHandler(\"https\");\nvar httpHandler = new HttpTransportHandler(\"http\");\n// src/transport/file.ts\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nclass FileTransportHandler {\n type = \"file\";\n async fetch(location) {\n const filePath = resolve(process.cwd(), location);\n try {\n return await readFile(filePath);\n } catch (error) {\n const err = error;\n throw new TransportError(`File read error: ${err.code} - ${filePath}`, this.type, {\n cause: err\n });\n }\n }\n}\nvar fileHandler = new FileTransportHandler;\n// src/transport/index.ts\nvar handlers = new Map([\n [\"https\", httpsHandler],\n [\"http\", httpHandler],\n [\"file\", fileHandler]\n]);\nfunction getTransportHandler(type) {\n const handler = handlers.get(type);\n if (!handler) {\n throw new TransportError(`Unsupported transport type: ${type}`, type);\n }\n return handler;\n}\nfunction registerTransportHandler(handler) {\n handlers.set(handler.type, handler);\n}\n// src/semantic/text.ts\nclass TextSemanticHandler {\n type = \"text\";\n parse(content, context) {\n const text = content.toString(\"utf-8\");\n const meta = {\n url: context.url,\n semantic: context.semantic,\n transport: context.transport,\n location: context.location,\n size: content.length,\n encoding: \"utf-8\",\n mimeType: \"text/plain\",\n fetchedAt: context.fetchedAt.toISOString()\n };\n return {\n type: \"text\",\n content: text,\n meta\n };\n }\n}\nvar textHandler = new TextSemanticHandler;\n// src/semantic/index.ts\nvar handlers2 = new Map([[\"text\", textHandler]]);\nfunction getSemanticHandler(type) {\n const handler = handlers2.get(type);\n if (!handler) {\n throw new SemanticError(`Unsupported semantic type: ${type}`, type);\n }\n return handler;\n}\nfunction registerSemanticHandler(handler) {\n handlers2.set(handler.type, handler);\n}\n// src/resolve.ts\nasync function resolve2(url) {\n const fetchedAt = new Date;\n const parsed = parseARP(url);\n const transportHandler = getTransportHandler(parsed.transport);\n const semanticHandler = getSemanticHandler(parsed.semantic);\n const content = await transportHandler.fetch(parsed.location);\n const context = {\n url,\n semantic: parsed.semantic,\n transport: parsed.transport,\n location: parsed.location,\n fetchedAt\n };\n return semanticHandler.parse(content, context);\n}\n\n// src/index.ts\nvar VERSION = \"0.0.
|
|
5
|
+
"// src/errors.ts\nclass ResourceXError extends Error {\n constructor(message, options) {\n super(message, options);\n this.name = \"ResourceXError\";\n }\n}\n\nclass ParseError extends ResourceXError {\n url;\n constructor(message, url) {\n super(message);\n this.url = url;\n this.name = \"ParseError\";\n }\n}\n\nclass TransportError extends ResourceXError {\n transport;\n constructor(message, transport, options) {\n super(message, options);\n this.transport = transport;\n this.name = \"TransportError\";\n }\n}\n\nclass SemanticError extends ResourceXError {\n semantic;\n constructor(message, semantic, options) {\n super(message, options);\n this.semantic = semantic;\n this.name = \"SemanticError\";\n }\n}\n// src/parser.ts\nfunction parseARP(url) {\n if (!url.startsWith(\"arp:\")) {\n throw new ParseError(`Invalid ARP URL: must start with \"arp:\"`, url);\n }\n const content = url.substring(4);\n const separatorIndex = content.indexOf(\"://\");\n if (separatorIndex === -1) {\n throw new ParseError(`Invalid ARP URL: missing \"://\"`, url);\n }\n const typePart = content.substring(0, separatorIndex);\n const location = content.substring(separatorIndex + 3);\n const colonIndex = typePart.indexOf(\":\");\n if (colonIndex === -1) {\n throw new ParseError(`Invalid ARP URL: must have exactly 2 types (semantic:transport)`, url);\n }\n const semantic = typePart.substring(0, colonIndex);\n const transport = typePart.substring(colonIndex + 1);\n if (!semantic) {\n throw new ParseError(`Invalid ARP URL: semantic type cannot be empty`, url);\n }\n if (!transport) {\n throw new ParseError(`Invalid ARP URL: transport type cannot be empty`, url);\n }\n if (!location) {\n throw new ParseError(`Invalid ARP URL: location cannot be empty`, url);\n }\n return { semantic, transport, location };\n}\n// src/transport/http.ts\nclass HttpTransportHandler {\n type;\n protocol;\n constructor(protocol = \"https\") {\n this.protocol = protocol;\n this.type = protocol;\n }\n async fetch(location) {\n const url = `${this.protocol}://${location}`;\n try {\n const response = await fetch(url);\n if (!response.ok) {\n throw new TransportError(`HTTP ${response.status}: ${response.statusText} - ${url}`, this.type);\n }\n const arrayBuffer = await response.arrayBuffer();\n return Buffer.from(arrayBuffer);\n } catch (error) {\n if (error instanceof TransportError) {\n throw error;\n }\n throw new TransportError(`Network error: ${url}`, this.type, { cause: error });\n }\n }\n}\nvar httpsHandler = new HttpTransportHandler(\"https\");\nvar httpHandler = new HttpTransportHandler(\"http\");\n// src/transport/file.ts\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nclass FileTransportHandler {\n type = \"file\";\n async fetch(location) {\n const filePath = resolve(process.cwd(), location);\n try {\n return await readFile(filePath);\n } catch (error) {\n const err = error;\n throw new TransportError(`File read error: ${err.code} - ${filePath}`, this.type, {\n cause: err\n });\n }\n }\n}\nvar fileHandler = new FileTransportHandler;\n// src/transport/index.ts\nvar handlers = new Map([\n [\"https\", httpsHandler],\n [\"http\", httpHandler],\n [\"file\", fileHandler]\n]);\nfunction getTransportHandler(type) {\n const handler = handlers.get(type);\n if (!handler) {\n throw new TransportError(`Unsupported transport type: ${type}`, type);\n }\n return handler;\n}\nfunction registerTransportHandler(handler) {\n handlers.set(handler.type, handler);\n}\n// src/semantic/text.ts\nclass TextSemanticHandler {\n type = \"text\";\n parse(content, context) {\n const text = content.toString(\"utf-8\");\n const meta = {\n url: context.url,\n semantic: context.semantic,\n transport: context.transport,\n location: context.location,\n size: content.length,\n encoding: \"utf-8\",\n mimeType: \"text/plain\",\n fetchedAt: context.fetchedAt.toISOString()\n };\n return {\n type: \"text\",\n content: text,\n meta\n };\n }\n}\nvar textHandler = new TextSemanticHandler;\n// src/semantic/index.ts\nvar handlers2 = new Map([[\"text\", textHandler]]);\nfunction getSemanticHandler(type) {\n const handler = handlers2.get(type);\n if (!handler) {\n throw new SemanticError(`Unsupported semantic type: ${type}`, type);\n }\n return handler;\n}\nfunction registerSemanticHandler(handler) {\n handlers2.set(handler.type, handler);\n}\n// src/resolve.ts\nasync function resolve2(url) {\n const fetchedAt = new Date;\n const parsed = parseARP(url);\n const transportHandler = getTransportHandler(parsed.transport);\n const semanticHandler = getSemanticHandler(parsed.semantic);\n const content = await transportHandler.fetch(parsed.location);\n const context = {\n url,\n semantic: parsed.semantic,\n transport: parsed.transport,\n location: parsed.location,\n fetchedAt\n };\n return semanticHandler.parse(content, context);\n}\n\n// src/index.ts\nvar VERSION = \"0.0.3\";\nexport {\n textHandler,\n resolve2 as resolve,\n registerTransportHandler,\n registerSemanticHandler,\n parseARP,\n httpsHandler,\n httpHandler,\n getTransportHandler,\n getSemanticHandler,\n fileHandler,\n VERSION,\n TransportError,\n SemanticError,\n ResourceXError,\n ParseError\n};\n\n//# debugId=31FB3920A030247564756E2164756E21\n",
|
|
6
6
|
"/**\n * ResourceX - Main API class\n */\n\nimport {\n parseARP,\n resolve as coreResolve,\n getTransportHandler,\n getSemanticHandler,\n registerTransportHandler,\n registerSemanticHandler,\n type ParsedARP,\n type Resource,\n type TransportHandler,\n type SemanticHandler,\n} from \"@resourcexjs/core\";\n\n/**\n * ResourceX configuration\n */\nexport interface ResourceXConfig {\n /**\n * Request timeout in milliseconds\n */\n timeout?: number;\n\n /**\n * Custom transport handlers to register\n */\n transports?: TransportHandler[];\n\n /**\n * Custom semantic handlers to register\n */\n semantics?: SemanticHandler[];\n}\n\n/**\n * ResourceX instance\n */\nexport class ResourceX {\n readonly timeout?: number;\n\n constructor(config: ResourceXConfig = {}) {\n this.timeout = config.timeout;\n\n // Register custom handlers from config\n if (config.transports) {\n for (const handler of config.transports) {\n registerTransportHandler(handler);\n }\n }\n\n if (config.semantics) {\n for (const handler of config.semantics) {\n registerSemanticHandler(handler);\n }\n }\n }\n\n /**\n * Parse an ARP URL without fetching\n */\n parse(url: string): ParsedARP {\n return parseARP(url);\n }\n\n /**\n * Resolve an ARP URL to a resource\n */\n async resolve(url: string): Promise<Resource> {\n // TODO: implement timeout using this.timeout\n return coreResolve(url);\n }\n\n /**\n * Register a custom transport handler\n */\n registerTransport(handler: TransportHandler): void {\n registerTransportHandler(handler);\n }\n\n /**\n * Register a custom semantic handler\n */\n registerSemantic(handler: SemanticHandler): void {\n registerSemanticHandler(handler);\n }\n\n /**\n * Get a transport handler by type\n */\n getTransport(type: string): TransportHandler {\n return getTransportHandler(type);\n }\n\n /**\n * Get a semantic handler by type\n */\n getSemantic(type: string): SemanticHandler {\n return getSemanticHandler(type);\n }\n}\n",
|
|
7
7
|
"/**\n * Factory function for creating ResourceX instances\n */\n\nimport { ResourceX, type ResourceXConfig } from \"./ResourceX.js\";\n\n/**\n * Create a new ResourceX instance\n *\n * @example\n * ```typescript\n * import { createResourceX } from \"resourcexjs\";\n *\n * const rx = createResourceX();\n * const resource = await rx.resolve(\"arp:text:https://example.com/file.txt\");\n * ```\n *\n * @example\n * ```typescript\n * // With custom config\n * const rx = createResourceX({\n * timeout: 5000,\n * transports: [myCustomTransport],\n * semantics: [myCustomSemantic],\n * });\n * ```\n */\nexport function createResourceX(config?: ResourceXConfig): ResourceX {\n return new ResourceX(config);\n}\n"
|
|
8
8
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resourcexjs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "ResourceX - Agent Resource Protocol for AI Agents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"resourcex",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"clean": "rm -rf dist"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@resourcexjs/core": "^0.0.
|
|
41
|
+
"@resourcexjs/core": "^0.0.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {},
|
|
44
44
|
"publishConfig": {
|