every-plugin 0.8.9 → 2.2.2
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/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.cjs} +15 -1
- package/dist/_virtual/{rolldown_runtime.mjs → _rolldown/runtime.mjs} +15 -2
- package/dist/build/rspack/dev-server-middleware.cjs +15 -4
- package/dist/build/rspack/dev-server-middleware.cjs.map +1 -1
- package/dist/build/rspack/dev-server-middleware.mjs +15 -4
- package/dist/build/rspack/dev-server-middleware.mjs.map +1 -1
- package/dist/build/rspack/fix-mf-data-uri-plugin.cjs +44 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.cjs.map +1 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts +11 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.cts.map +1 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts +11 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.d.mts.map +1 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.mjs +43 -0
- package/dist/build/rspack/fix-mf-data-uri-plugin.mjs.map +1 -0
- package/dist/build/rspack/index.cjs +8 -6
- package/dist/build/rspack/index.d.cts +4 -3
- package/dist/build/rspack/index.d.mts +4 -3
- package/dist/build/rspack/index.mjs +4 -3
- package/dist/build/rspack/module-federation.cjs +3 -3
- package/dist/build/rspack/module-federation.cjs.map +1 -1
- package/dist/build/rspack/module-federation.mjs +1 -1
- package/dist/build/rspack/module-federation.mjs.map +1 -1
- package/dist/build/rspack/plugin.cjs +83 -5
- package/dist/build/rspack/plugin.cjs.map +1 -1
- package/dist/build/rspack/plugin.d.cts +12 -1
- package/dist/build/rspack/plugin.d.cts.map +1 -1
- package/dist/build/rspack/plugin.d.mts +12 -1
- package/dist/build/rspack/plugin.d.mts.map +1 -1
- package/dist/build/rspack/plugin.mjs +80 -5
- package/dist/build/rspack/plugin.mjs.map +1 -1
- package/dist/build/rspack/utils.cjs +5 -4
- package/dist/build/rspack/utils.cjs.map +1 -1
- package/dist/build/rspack/utils.mjs +3 -2
- package/dist/build/rspack/utils.mjs.map +1 -1
- package/dist/build/shared-deps.cjs +50 -65
- package/dist/build/shared-deps.cjs.map +1 -1
- package/dist/build/shared-deps.d.cts +27 -4
- package/dist/build/shared-deps.d.cts.map +1 -1
- package/dist/build/shared-deps.d.mts +27 -4
- package/dist/build/shared-deps.d.mts.map +1 -1
- package/dist/build/shared-deps.mjs +48 -64
- package/dist/build/shared-deps.mjs.map +1 -1
- package/dist/errors.cjs +1 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/orpc-client.cjs +17 -0
- package/dist/orpc-client.d.cts +2 -0
- package/dist/orpc-client.d.mts +2 -0
- package/dist/orpc-client.mjs +5 -0
- package/dist/orpc-openapi.cjs +17 -0
- package/dist/orpc-openapi.d.cts +2 -0
- package/dist/orpc-openapi.d.mts +2 -0
- package/dist/orpc-openapi.mjs +5 -0
- package/dist/orpc.cjs +8 -7
- package/dist/plugin.cjs +10 -9
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +28 -29
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +28 -29
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +10 -10
- package/dist/plugin.mjs.map +1 -1
- package/dist/runtime/errors.cjs +2 -2
- package/dist/runtime/errors.cjs.map +1 -1
- package/dist/runtime/errors.d.cts +4 -4
- package/dist/runtime/errors.d.cts.map +1 -1
- package/dist/runtime/errors.d.mts +4 -4
- package/dist/runtime/errors.d.mts.map +1 -1
- package/dist/runtime/errors.mjs +1 -1
- package/dist/runtime/errors.mjs.map +1 -1
- package/dist/runtime/index.cjs +24 -20
- package/dist/runtime/index.cjs.map +1 -1
- package/dist/runtime/index.d.cts +3 -3
- package/dist/runtime/index.d.cts.map +1 -1
- package/dist/runtime/index.d.mts +3 -3
- package/dist/runtime/index.d.mts.map +1 -1
- package/dist/runtime/index.mjs +12 -9
- package/dist/runtime/index.mjs.map +1 -1
- package/dist/runtime/mf-config.cjs +33 -0
- package/dist/runtime/mf-config.cjs.map +1 -0
- package/dist/runtime/mf-config.d.cts +41 -0
- package/dist/runtime/mf-config.d.cts.map +1 -0
- package/dist/runtime/mf-config.d.mts +41 -0
- package/dist/runtime/mf-config.d.mts.map +1 -0
- package/dist/runtime/mf-config.mjs +29 -0
- package/dist/runtime/mf-config.mjs.map +1 -0
- package/dist/runtime/services/module-federation.service.cjs +19 -56
- package/dist/runtime/services/module-federation.service.cjs.map +1 -1
- package/dist/runtime/services/module-federation.service.d.cts.map +1 -1
- package/dist/runtime/services/module-federation.service.d.mts.map +1 -1
- package/dist/runtime/services/module-federation.service.mjs +18 -55
- package/dist/runtime/services/module-federation.service.mjs.map +1 -1
- package/dist/runtime/services/normalize.cjs +3 -2
- package/dist/runtime/services/normalize.cjs.map +1 -1
- package/dist/runtime/services/normalize.d.cts.map +1 -1
- package/dist/runtime/services/normalize.d.mts.map +1 -1
- package/dist/runtime/services/normalize.mjs +2 -2
- package/dist/runtime/services/normalize.mjs.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.cjs +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.cjs.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.mjs.map +1 -1
- package/dist/runtime/services/plugin-loader.service.cjs +3 -3
- package/dist/runtime/services/plugin-loader.service.cjs.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.cts +1 -1
- package/dist/runtime/services/plugin-loader.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.mts +1 -1
- package/dist/runtime/services/plugin-loader.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.mjs +2 -2
- package/dist/runtime/services/plugin-loader.service.mjs.map +1 -1
- package/dist/runtime/services/plugin.service.cjs +1 -1
- package/dist/runtime/services/plugin.service.cjs.map +1 -1
- package/dist/runtime/services/plugin.service.d.cts +6 -7
- package/dist/runtime/services/plugin.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin.service.d.mts +6 -7
- package/dist/runtime/services/plugin.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin.service.mjs.map +1 -1
- package/dist/runtime/services/secrets.service.cjs +4 -4
- package/dist/runtime/services/secrets.service.cjs.map +1 -1
- package/dist/runtime/services/secrets.service.d.cts.map +1 -1
- package/dist/runtime/services/secrets.service.d.mts.map +1 -1
- package/dist/runtime/services/secrets.service.mjs +3 -3
- package/dist/runtime/services/secrets.service.mjs.map +1 -1
- package/dist/runtime/validation.cjs +1 -1
- package/dist/runtime/validation.cjs.map +1 -1
- package/dist/runtime/validation.mjs.map +1 -1
- package/dist/testing/index.cjs +2 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +0 -2
- package/dist/testing/index.d.cts.map +1 -1
- package/dist/testing/index.d.mts +0 -2
- package/dist/testing/index.d.mts.map +1 -1
- package/dist/testing/index.mjs +1 -1
- package/dist/testing/index.mjs.map +1 -1
- package/dist/types.d.cts +22 -22
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +22 -22
- package/dist/types.d.mts.map +1 -1
- package/dist/zod.cjs +4 -3
- package/dist/zod.mjs +2 -2
- package/package.json +204 -194
- package/src/build/rspack/dev-server-middleware.ts +233 -0
- package/src/build/rspack/fix-mf-data-uri-plugin.ts +49 -0
- package/src/build/rspack/index.ts +14 -0
- package/src/build/rspack/module-federation.ts +6 -0
- package/src/build/rspack/plugin.ts +252 -0
- package/src/build/rspack/utils.ts +60 -0
- package/src/build/shared-deps.ts +79 -0
- package/src/effect.ts +1 -0
- package/src/errors.ts +140 -0
- package/src/index.ts +26 -0
- package/src/orpc-client.ts +2 -0
- package/src/orpc-openapi.ts +2 -0
- package/src/orpc.ts +9 -0
- package/src/plugin.ts +220 -0
- package/src/runtime/errors.ts +332 -0
- package/src/runtime/index.ts +258 -0
- package/src/runtime/mf-config.ts +29 -0
- package/src/runtime/services/module-federation.service.ts +181 -0
- package/src/runtime/services/normalize.ts +18 -0
- package/src/runtime/services/plugin-lifecycle.service.ts +86 -0
- package/src/runtime/services/plugin-loader.service.ts +254 -0
- package/src/runtime/services/plugin.service.ts +66 -0
- package/src/runtime/services/secrets.service.ts +74 -0
- package/src/runtime/services.ts +5 -0
- package/src/runtime/validation.ts +23 -0
- package/src/testing/index.ts +87 -0
- package/src/testing/mocks/module-federation.service.ts +41 -0
- package/src/types.ts +309 -0
- package/src/zod-core.ts +4 -0
- package/src/zod.ts +1 -0
- package/dist/package.cjs +0 -47
- package/dist/package.cjs.map +0 -1
- package/dist/package.mjs +0 -29
- package/dist/package.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Cause, Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n\treadonly pluginId?: string;\n\treadonly operation?: string;\n\treadonly procedureName?: string;\n\treadonly cause?: Error;\n\treadonly retryable: boolean;\n}> { }\n\nexport class ModuleFederationError extends Data.TaggedError(\n\t\"ModuleFederationError\",\n)<{\n\treadonly pluginId: string;\n\treadonly remoteUrl: string;\n\treadonly cause?: Error;\n}> { }\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n\treadonly pluginId: string;\n\treadonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n\treadonly zodError: z.ZodError;\n}> { }\n\nconst extractErrorMessage = (error: unknown): string => {\n\tif (!error) return 'Unknown error';\n\n\tif (error instanceof Error) {\n\t\tif (error.message) return error.message;\n\t\tif ((error as any).cause instanceof Error) {\n\t\t\treturn extractErrorMessage((error as any).cause);\n\t\t}\n\t}\n\n\tif (error instanceof AggregateError && error.errors?.length) {\n\t\treturn error.errors.map(e => extractErrorMessage(e)).join('; ');\n\t}\n\n\tif (typeof error === 'object' && 'message' in error) {\n\t\treturn String((error as any).message);\n\t}\n\n\treturn String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n\tif (index >= maxDisplay) return '';\n\t\n\tconst path = Array.isArray(issue.path) && issue.path.length > 0\n\t\t? issue.path.join('.')\n\t\t: issue.path || 'root';\n\t\n\tconst message = issue.message || 'Validation failed';\n\t\n\treturn `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n\tif (!data) return 'undefined';\n\t\n\ttry {\n\t\tconst str = JSON.stringify(data);\n\t\tif (str.length <= maxLength) return str;\n\t\t\n\t\tif (typeof data === 'object' && data !== null) {\n\t\t\tif (Array.isArray(data)) {\n\t\t\t\treturn `Array(${data.length}) [...]`;\n\t\t\t}\n\t\t\tconst keys = Object.keys(data);\n\t\t\treturn `{ ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? ', ...' : ''} }`;\n\t\t}\n\t\t\n\t\treturn str.slice(0, maxLength) + '...';\n\t} catch {\n\t\treturn String(data).slice(0, maxLength);\n\t}\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n\tconst cause = error?.cause || error;\n\t\n\tif (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst lines: string[] = [];\n\tconst errorType = error?.message || cause?.message || 'Validation failed';\n\t\n\tlines.push(`\\n╭─ oRPC Validation Error ${'─'.repeat(30)}`);\n\tlines.push(`│ ${errorType}`);\n\tlines.push(`│`);\n\t\n\tconst maxDisplay = 10;\n\tconst totalIssues = cause.issues.length;\n\t\n\tlines.push(`│ Issues (${totalIssues}):`);\n\t\n\tconst displayedIssues = cause.issues.slice(0, maxDisplay);\n\tdisplayedIssues.forEach((issue: any, idx: number) => {\n\t\tconst formatted = formatValidationIssue(issue, idx, maxDisplay);\n\t\tif (formatted) lines.push(formatted);\n\t});\n\t\n\tif (totalIssues > maxDisplay) {\n\t\tlines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n\t}\n\t\n\tif (cause.data !== undefined) {\n\t\tlines.push(`│`);\n\t\tlines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n\t}\n\t\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\t\n\treturn lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n\tif (!(error instanceof ORPCError)) {\n\t\treturn;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t\treturn;\n\t}\n\n\tconst lines: string[] = [];\n\tconst code = error.code || 'UNKNOWN';\n\tconst status = error.status || 500;\n\tconst message = error.message || 'An error occurred';\n\n\tlines.push(`\\n╭─ oRPC Error ${'─'.repeat(40)}`);\n\tlines.push(`│ ${message}`);\n\tlines.push(`│ Code: ${code} (${status})`);\n\tlines.push(`│`);\n\n\tif (error.data) {\n\t\tconst dataType = typeof error.data;\n\t\tif (dataType === 'object' && error.data !== null) {\n\t\t\tif ('retryAfter' in error.data) {\n\t\t\t\tlines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n\t\t\t}\n\t\t\tif ('remainingRequests' in error.data) {\n\t\t\t\tlines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n\t\t\t}\n\t\t\tif ('host' in error.data) {\n\t\t\t\tlines.push(`│ Host: ${error.data.host}`);\n\t\t\t}\n\t\t\tif ('port' in error.data) {\n\t\t\t\tlines.push(`│ Port: ${error.data.port}`);\n\t\t\t}\n\t\t\tif ('suggestion' in error.data) {\n\t\t\t\tlines.push(`│ → ${error.data.suggestion}`);\n\t\t\t}\n\t\t\tif ('resource' in error.data) {\n\t\t\t\tlines.push(`│ Resource: ${error.data.resource}`);\n\t\t\t}\n\t\t\tif ('resourceId' in error.data) {\n\t\t\t\tlines.push(`│ ID: ${error.data.resourceId}`);\n\t\t\t}\n\t\t}\n\t}\n\n\tswitch (code) {\n\t\tcase 'UNAUTHORIZED':\n\t\t\tlines.push(`│ → Check your API key or credentials`);\n\t\t\tbreak;\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\t\tlines.push(`│ → Wait before retrying`);\n\t\t\tbreak;\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\t\tlines.push(`│ → The service may be temporarily unavailable`);\n\t\t\tbreak;\n\t\tcase 'TIMEOUT':\n\t\t\tlines.push(`│ → The operation took too long`);\n\t\t\tbreak;\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\tconsole.error(lines.join('\\n'));\n};\n\nconst formatPluginError = (\n\tpluginId: string | undefined,\n\toperation: string | undefined,\n\tmessage: string\n): void => {\n\tconst lines: string[] = [];\n\n\tlines.push(`\\n╭─ Plugin Error ${'─'.repeat(40)}`);\n\tif (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n\tif (operation) lines.push(`│ During: ${operation}`);\n\tlines.push(`│`);\n\n\tif (message.includes('ECONNREFUSED')) {\n\t\tlines.push(`│ ❌ Connection refused`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ A required service is not running.`);\n\t\tlines.push(`│ → Run: docker compose up -d`);\n\t} else if (message.includes('ENOTFOUND')) {\n\t\tlines.push(`│ ❌ Host not found`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your connection URL or network settings.`);\n\t} else if (message.includes('ETIMEDOUT') || message.includes('timeout')) {\n\t\tlines.push(`│ ❌ Connection timeout`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ The service took too long to respond.`);\n\t} else if (message.includes('EACCES') || message.includes('permission')) {\n\t\tlines.push(`│ ❌ Permission denied`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check credentials or access permissions.`);\n\t} else if (message.includes('401') || message.includes('unauthorized')) {\n\t\tlines.push(`│ ❌ Authentication failed`);\n\t\tlines.push(`│ `);\n\t\tlines.push(`│ Check your API key or credentials.`);\n\t} else {\n\t\tlines.push(`│ ❌ ${message}`);\n\t}\n\n\tlines.push(`╰${'─'.repeat(50)}\\n`);\n\n\tconsole.error(lines.join('\\n'));\n};\n\nconst isRetryableError = (message: string): boolean => {\n\tconst retryablePatterns = ['ETIMEDOUT', 'ECONNRESET', 'timeout', '503', '429'];\n\treturn retryablePatterns.some(p => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n\tswitch (code) {\n\t\tcase 'TOO_MANY_REQUESTS':\n\t\tcase 'SERVICE_UNAVAILABLE':\n\t\tcase 'BAD_GATEWAY':\n\t\tcase 'GATEWAY_TIMEOUT':\n\t\tcase 'TIMEOUT':\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n\torpcError: ORPCError<string, unknown>,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string\n): PluginRuntimeError => {\n\tconst validationLines = formatORPCValidationError(orpcError);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t}\n\t\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: isRetryableORPCCode(orpcError.code),\n\t\tcause: orpcError as Error\n\t});\n};\n\n/**\n * Extracts the underlying error from Effect's FiberFailure wrapper.\n * When Effect.runPromise rejects, errors are wrapped in FiberFailure.\n * This extracts the original error so oRPC can handle it properly.\n */\nexport const extractFromFiberFailure = (error: unknown): unknown => {\n\tif (!error || typeof error !== 'object') return error;\n\t\n\tif ('cause' in error) {\n\t\tconst cause = (error as { cause?: unknown }).cause;\n\t\t\n\t\tif (cause && typeof cause === 'object' && '_tag' in cause) {\n\t\t\ttry {\n\t\t\t\tconst squashed = Cause.squash(cause as Cause.Cause<unknown>);\n\t\t\t\tif (squashed instanceof ORPCError) {\n\t\t\t\t\treturn squashed;\n\t\t\t\t}\n\t\t\t\treturn squashed;\n\t\t\t} catch {\n\t\t\t\t// Not a valid Cause\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (cause instanceof ORPCError) {\n\t\t\treturn cause;\n\t\t}\n\t}\n\t\n\treturn error;\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n\terror: unknown,\n\tpluginId?: string,\n\tprocedureName?: string,\n\toperation?: string,\n\tdefaultRetryable = false\n): PluginRuntimeError => {\n\tif (error instanceof ORPCError) {\n\t\treturn wrapORPCError(error, pluginId, procedureName, operation);\n\t}\n\n\tif (error instanceof PluginRuntimeError) {\n\t\treturn error;\n\t}\n\n\tconst validationLines = formatORPCValidationError(error);\n\tif (validationLines) {\n\t\tconsole.error(validationLines.join('\\n'));\n\t} else {\n\t\tconst message = extractErrorMessage(error);\n\t\tformatPluginError(pluginId, operation, message);\n\t}\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n\t\tcause: error instanceof Error ? error : new Error(extractErrorMessage(error))\n\t});\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAb,cAAwC,KAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2C,KAAK,YAC/C,wBACA,CAIE;AAEH,IAAa,kBAAb,cAAqC,KAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB,UAA2B;AACvD,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI,iBAAiB,OAAO;AAC3B,MAAI,MAAM,QAAS,QAAO,MAAM;AACh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AAM,OAAO,MAA8B;AAC5D,OAAI,oBAAoB,UACvB,QAAO;AAER,UAAO;UACA;AAKT,MAAI,iBAAiB,UACpB,QAAO;;AAIT,QAAO;;AAIR,MAAa,wBACZ,OACA,UACA,eACA,WACA,mBAAmB,UACK;AACxB,KAAI,iBAAiB,UACpB,QAAO,cAAc,OAAO,UAAU,eAAe,UAAU;AAGhE,KAAI,iBAAiB,mBACpB,QAAO;CAGR,MAAM,kBAAkB,0BAA0B,MAAM;AACxD,KAAI,gBACH,SAAQ,MAAM,gBAAgB,KAAK,KAAK,CAAC;KAGzC,mBAAkB,UAAU,WADZ,oBAAoB,MAAM,CACK;AAGhD,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,oBAAoB,MAAM,CAAC;EAC3E,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,oBAAoB,MAAM,CAAC;EAC7E,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { Cause, Data } from \"effect\";\nimport type { z } from \"zod\";\n\nexport class PluginRuntimeError extends Data.TaggedError(\"PluginRuntimeError\")<{\n readonly pluginId?: string;\n readonly operation?: string;\n readonly procedureName?: string;\n readonly cause?: Error;\n readonly retryable: boolean;\n}> {}\n\nexport class ModuleFederationError extends Data.TaggedError(\"ModuleFederationError\")<{\n readonly pluginId: string;\n readonly remoteUrl: string;\n readonly cause?: Error;\n}> {}\n\nexport class ValidationError extends Data.TaggedError(\"ValidationError\")<{\n readonly pluginId: string;\n readonly stage: \"config\" | \"input\" | \"output\" | \"state\";\n readonly zodError: z.ZodError;\n}> {}\n\nconst extractErrorMessage = (error: unknown): string => {\n if (!error) return \"Unknown error\";\n\n if (error instanceof Error) {\n if (error.message) return error.message;\n if ((error as any).cause instanceof Error) {\n return extractErrorMessage((error as any).cause);\n }\n }\n\n if (error instanceof AggregateError && error.errors?.length) {\n return error.errors.map((e) => extractErrorMessage(e)).join(\"; \");\n }\n\n if (typeof error === \"object\" && \"message\" in error) {\n return String((error as any).message);\n }\n\n return String(error);\n};\n\nconst formatValidationIssue = (issue: any, index: number, maxDisplay: number): string => {\n if (index >= maxDisplay) return \"\";\n\n const path =\n Array.isArray(issue.path) && issue.path.length > 0\n ? issue.path.join(\".\")\n : issue.path || \"root\";\n\n const message = issue.message || \"Validation failed\";\n\n return `│ ${index + 1}. ${path}: ${message}`;\n};\n\nconst formatDataPreview = (data: unknown, maxLength = 100): string => {\n if (!data) return \"undefined\";\n\n try {\n const str = JSON.stringify(data);\n if (str.length <= maxLength) return str;\n\n if (typeof data === \"object\" && data !== null) {\n if (Array.isArray(data)) {\n return `Array(${data.length}) [...]`;\n }\n const keys = Object.keys(data);\n return `{ ${keys.slice(0, 3).join(\", \")}${keys.length > 3 ? \", ...\" : \"\"} }`;\n }\n\n return `${str.slice(0, maxLength)}...`;\n } catch {\n return String(data).slice(0, maxLength);\n }\n};\n\nconst formatORPCValidationError = (error: any): string[] | null => {\n const cause = error?.cause || error;\n\n if (!cause?.issues || !Array.isArray(cause.issues) || cause.issues.length === 0) {\n return null;\n }\n\n const lines: string[] = [];\n const errorType = error?.message || cause?.message || \"Validation failed\";\n\n lines.push(`\\n╭─ oRPC Validation Error ${\"─\".repeat(30)}`);\n lines.push(`│ ${errorType}`);\n lines.push(`│`);\n\n const maxDisplay = 10;\n const totalIssues = cause.issues.length;\n\n lines.push(`│ Issues (${totalIssues}):`);\n\n const displayedIssues = cause.issues.slice(0, maxDisplay);\n displayedIssues.forEach((issue: any, idx: number) => {\n const formatted = formatValidationIssue(issue, idx, maxDisplay);\n if (formatted) lines.push(formatted);\n });\n\n if (totalIssues > maxDisplay) {\n lines.push(`│ ... and ${totalIssues - maxDisplay} more`);\n }\n\n if (cause.data !== undefined) {\n lines.push(`│`);\n lines.push(`│ Data preview: ${formatDataPreview(cause.data, 80)}`);\n }\n\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n\n return lines;\n};\n\nexport const formatORPCError = (error: any): void => {\n if (!(error instanceof ORPCError)) {\n return;\n }\n\n const validationLines = formatORPCValidationError(error);\n if (validationLines) {\n console.error(validationLines.join(\"\\n\"));\n return;\n }\n\n const lines: string[] = [];\n const code = error.code || \"UNKNOWN\";\n const status = error.status || 500;\n const message = error.message || \"An error occurred\";\n\n lines.push(`\\n╭─ oRPC Error ${\"─\".repeat(40)}`);\n lines.push(`│ ${message}`);\n lines.push(`│ Code: ${code} (${status})`);\n lines.push(`│`);\n\n if (error.data) {\n const dataType = typeof error.data;\n if (dataType === \"object\" && error.data !== null) {\n if (\"retryAfter\" in error.data) {\n lines.push(`│ Retry after: ${error.data.retryAfter} seconds`);\n }\n if (\"remainingRequests\" in error.data) {\n lines.push(`│ Remaining: ${error.data.remainingRequests} requests`);\n }\n if (\"host\" in error.data) {\n lines.push(`│ Host: ${error.data.host}`);\n }\n if (\"port\" in error.data) {\n lines.push(`│ Port: ${error.data.port}`);\n }\n if (\"suggestion\" in error.data) {\n lines.push(`│ → ${error.data.suggestion}`);\n }\n if (\"resource\" in error.data) {\n lines.push(`│ Resource: ${error.data.resource}`);\n }\n if (\"resourceId\" in error.data) {\n lines.push(`│ ID: ${error.data.resourceId}`);\n }\n }\n }\n\n switch (code) {\n case \"UNAUTHORIZED\":\n lines.push(`│ → Check your API key or credentials`);\n break;\n case \"TOO_MANY_REQUESTS\":\n lines.push(`│ → Wait before retrying`);\n break;\n case \"SERVICE_UNAVAILABLE\":\n case \"BAD_GATEWAY\":\n case \"GATEWAY_TIMEOUT\":\n lines.push(`│ → The service may be temporarily unavailable`);\n break;\n case \"TIMEOUT\":\n lines.push(`│ → The operation took too long`);\n break;\n }\n\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n console.error(lines.join(\"\\n\"));\n};\n\nconst formatPluginError = (\n pluginId: string | undefined,\n operation: string | undefined,\n message: string,\n): void => {\n const lines: string[] = [];\n\n lines.push(`\\n╭─ Plugin Error ${\"─\".repeat(40)}`);\n if (pluginId) lines.push(`│ Plugin: ${pluginId}`);\n if (operation) lines.push(`│ During: ${operation}`);\n lines.push(`│`);\n\n if (message.includes(\"ECONNREFUSED\")) {\n lines.push(`│ ❌ Connection refused`);\n lines.push(`│ `);\n lines.push(`│ A required service is not running.`);\n lines.push(`│ → Run: docker compose up -d`);\n } else if (message.includes(\"ENOTFOUND\")) {\n lines.push(`│ ❌ Host not found`);\n lines.push(`│ `);\n lines.push(`│ Check your connection URL or network settings.`);\n } else if (message.includes(\"ETIMEDOUT\") || message.includes(\"timeout\")) {\n lines.push(`│ ❌ Connection timeout`);\n lines.push(`│ `);\n lines.push(`│ The service took too long to respond.`);\n } else if (message.includes(\"EACCES\") || message.includes(\"permission\")) {\n lines.push(`│ ❌ Permission denied`);\n lines.push(`│ `);\n lines.push(`│ Check credentials or access permissions.`);\n } else if (message.includes(\"401\") || message.includes(\"unauthorized\")) {\n lines.push(`│ ❌ Authentication failed`);\n lines.push(`│ `);\n lines.push(`│ Check your API key or credentials.`);\n } else {\n lines.push(`│ ❌ ${message}`);\n }\n\n lines.push(`╰${\"─\".repeat(50)}\\n`);\n\n console.error(lines.join(\"\\n\"));\n};\n\nconst isRetryableError = (message: string): boolean => {\n const retryablePatterns = [\"ETIMEDOUT\", \"ECONNRESET\", \"timeout\", \"503\", \"429\"];\n return retryablePatterns.some((p) => message.toLowerCase().includes(p.toLowerCase()));\n};\n\n// Helper to determine if an oRPC error code is retryable\nexport const isRetryableORPCCode = (code: string): boolean => {\n switch (code) {\n case \"TOO_MANY_REQUESTS\":\n case \"SERVICE_UNAVAILABLE\":\n case \"BAD_GATEWAY\":\n case \"GATEWAY_TIMEOUT\":\n case \"TIMEOUT\":\n return true;\n default:\n return false;\n }\n};\n\n// Convert ORPC errors from plugin procedures to PluginRuntimeError\nexport const wrapORPCError = (\n orpcError: ORPCError<string, unknown>,\n pluginId?: string,\n procedureName?: string,\n operation?: string,\n): PluginRuntimeError => {\n const validationLines = formatORPCValidationError(orpcError);\n if (validationLines) {\n console.error(validationLines.join(\"\\n\"));\n }\n\n return new PluginRuntimeError({\n pluginId,\n operation,\n procedureName,\n retryable: isRetryableORPCCode(orpcError.code),\n cause: orpcError as Error,\n });\n};\n\n/**\n * Extracts the underlying error from Effect's FiberFailure wrapper.\n * When Effect.runPromise rejects, errors are wrapped in FiberFailure.\n * This extracts the original error so oRPC can handle it properly.\n */\nexport const extractFromFiberFailure = (error: unknown): unknown => {\n if (!error || typeof error !== \"object\") return error;\n\n if (\"cause\" in error) {\n const cause = (error as { cause?: unknown }).cause;\n\n if (cause && typeof cause === \"object\" && \"_tag\" in cause) {\n try {\n const squashed = Cause.squash(cause as Cause.Cause<unknown>);\n if (squashed instanceof ORPCError) {\n return squashed;\n }\n return squashed;\n } catch {\n // Not a valid Cause\n }\n }\n\n if (cause instanceof ORPCError) {\n return cause;\n }\n }\n\n return error;\n};\n\n// Universal error converter for the runtime\nexport const toPluginRuntimeError = (\n error: unknown,\n pluginId?: string,\n procedureName?: string,\n operation?: string,\n defaultRetryable = false,\n): PluginRuntimeError => {\n if (error instanceof ORPCError) {\n return wrapORPCError(error, pluginId, procedureName, operation);\n }\n\n if (error instanceof PluginRuntimeError) {\n return error;\n }\n\n const validationLines = formatORPCValidationError(error);\n if (validationLines) {\n console.error(validationLines.join(\"\\n\"));\n } else {\n const message = extractErrorMessage(error);\n formatPluginError(pluginId, operation, message);\n }\n\n return new PluginRuntimeError({\n pluginId,\n operation,\n procedureName,\n retryable: defaultRetryable || isRetryableError(extractErrorMessage(error)),\n cause: error instanceof Error ? error : new Error(extractErrorMessage(error)),\n });\n};\n"],"mappings":";;;;AAIA,IAAa,qBAAb,cAAwC,KAAK,YAAY,qBAAqB,CAM3E;AAEH,IAAa,wBAAb,cAA2C,KAAK,YAAY,wBAAwB,CAIjF;AAEH,IAAa,kBAAb,cAAqC,KAAK,YAAY,kBAAkB,CAIrE;AAEH,MAAM,uBAAuB,UAA2B;AACtD,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pB,MAAM,QAAS,MAA8B;AAE7C,MAAI,SAAS,OAAO,UAAU,YAAY,UAAU,MAClD,KAAI;GACF,MAAM,WAAW,MAAM,OAAO,MAA8B;AAC5D,OAAI,oBAAoB,UACtB,QAAO;AAET,UAAO;UACD;AAKV,MAAI,iBAAiB,UACnB,QAAO;;AAIX,QAAO;;AAIT,MAAa,wBACX,OACA,UACA,eACA,WACA,mBAAmB,UACI;AACvB,KAAI,iBAAiB,UACnB,QAAO,cAAc,OAAO,UAAU,eAAe,UAAU;AAGjE,KAAI,iBAAiB,mBACnB,QAAO;CAGT,MAAM,kBAAkB,0BAA0B,MAAM;AACxD,KAAI,gBACF,SAAQ,MAAM,gBAAgB,KAAK,KAAK,CAAC;KAGzC,mBAAkB,UAAU,WADZ,oBAAoB,MAAM,CACK;AAGjD,QAAO,IAAI,mBAAmB;EAC5B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,oBAAoB,MAAM,CAAC;EAC3E,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,oBAAoB,MAAM,CAAC;EAC9E,CAAC"}
|
package/dist/runtime/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
3
|
const require_errors = require('./errors.cjs');
|
|
3
4
|
const require_plugin_service = require('./services/plugin.service.cjs');
|
|
4
5
|
let effect = require("effect");
|
|
@@ -6,7 +7,7 @@ let _orpc_server = require("@orpc/server");
|
|
|
6
7
|
|
|
7
8
|
//#region src/runtime/index.ts
|
|
8
9
|
var PluginRuntime = class {
|
|
9
|
-
|
|
10
|
+
__registryType;
|
|
10
11
|
pluginCache = /* @__PURE__ */ new Map();
|
|
11
12
|
constructor(runtime, registry) {
|
|
12
13
|
this.runtime = runtime;
|
|
@@ -33,8 +34,11 @@ var PluginRuntime = class {
|
|
|
33
34
|
}
|
|
34
35
|
return exit.value;
|
|
35
36
|
}
|
|
36
|
-
async usePlugin(pluginId, config) {
|
|
37
|
-
const cacheKey = this.generateCacheKey(pluginId,
|
|
37
|
+
async usePlugin(pluginId, config, plugins) {
|
|
38
|
+
const cacheKey = this.generateCacheKey(pluginId, {
|
|
39
|
+
...config,
|
|
40
|
+
__plugins: plugins ?? {}
|
|
41
|
+
});
|
|
38
42
|
let cachedPlugin = this.pluginCache.get(cacheKey);
|
|
39
43
|
if (!cachedPlugin) {
|
|
40
44
|
const operation = effect.Effect.gen(this, function* () {
|
|
@@ -42,7 +46,7 @@ var PluginRuntime = class {
|
|
|
42
46
|
const validatedId = yield* this.validatePluginId(pluginId);
|
|
43
47
|
const ctor = yield* pluginService.loadPlugin(validatedId);
|
|
44
48
|
const instance = yield* pluginService.instantiatePlugin(pluginId, ctor);
|
|
45
|
-
return yield* pluginService.initializePlugin(instance, config);
|
|
49
|
+
return yield* pluginService.initializePlugin(instance, config, plugins);
|
|
46
50
|
}).pipe(effect.Effect.provide(this.runtime));
|
|
47
51
|
cachedPlugin = effect.Effect.cached(operation).pipe(effect.Effect.flatten);
|
|
48
52
|
this.pluginCache.set(cacheKey, cachedPlugin);
|
|
@@ -59,32 +63,32 @@ var PluginRuntime = class {
|
|
|
59
63
|
};
|
|
60
64
|
}
|
|
61
65
|
async loadPlugin(pluginId) {
|
|
62
|
-
const effect$
|
|
66
|
+
const effect$2 = effect.Effect.gen(function* () {
|
|
63
67
|
return yield* (yield* require_plugin_service.PluginService).loadPlugin(pluginId);
|
|
64
68
|
});
|
|
65
|
-
return this.runPromise(effect$
|
|
69
|
+
return this.runPromise(effect$2);
|
|
66
70
|
}
|
|
67
71
|
async instantiatePlugin(pluginId, loadedPlugin) {
|
|
68
|
-
const effect$
|
|
72
|
+
const effect$3 = effect.Effect.gen(function* () {
|
|
69
73
|
return yield* (yield* require_plugin_service.PluginService).instantiatePlugin(pluginId, loadedPlugin);
|
|
70
74
|
});
|
|
71
|
-
return this.runPromise(effect$
|
|
75
|
+
return this.runPromise(effect$3);
|
|
72
76
|
}
|
|
73
|
-
async initializePlugin(instance, config) {
|
|
74
|
-
const effect$
|
|
75
|
-
return yield* (yield* require_plugin_service.PluginService).initializePlugin(instance, config);
|
|
77
|
+
async initializePlugin(instance, config, plugins) {
|
|
78
|
+
const effect$4 = effect.Effect.gen(function* () {
|
|
79
|
+
return yield* (yield* require_plugin_service.PluginService).initializePlugin(instance, config, plugins);
|
|
76
80
|
});
|
|
77
|
-
return this.runPromise(effect$
|
|
81
|
+
return this.runPromise(effect$4);
|
|
78
82
|
}
|
|
79
83
|
async shutdown() {
|
|
80
|
-
const effect$
|
|
84
|
+
const effect$5 = effect.Effect.gen(function* () {
|
|
81
85
|
yield* (yield* require_plugin_service.PluginService).cleanup();
|
|
82
86
|
});
|
|
83
|
-
return this.runPromise(effect$
|
|
87
|
+
return this.runPromise(effect$5);
|
|
84
88
|
}
|
|
85
89
|
async evictPlugin(pluginId, config) {
|
|
86
90
|
const cacheKey = this.generateCacheKey(pluginId, config);
|
|
87
|
-
const effect$
|
|
91
|
+
const effect$6 = effect.Effect.gen(this, function* () {
|
|
88
92
|
const pluginService = yield* require_plugin_service.PluginService;
|
|
89
93
|
const cachedPlugin = this.pluginCache.get(cacheKey);
|
|
90
94
|
if (cachedPlugin) {
|
|
@@ -93,7 +97,7 @@ var PluginRuntime = class {
|
|
|
93
97
|
if (pluginResult) yield* pluginService.shutdownPlugin(pluginResult).pipe(effect.Effect.catchAll(() => effect.Effect.void));
|
|
94
98
|
}
|
|
95
99
|
}).pipe(effect.Effect.catchAll(() => effect.Effect.void));
|
|
96
|
-
return this.runPromise(effect$
|
|
100
|
+
return this.runPromise(effect$6);
|
|
97
101
|
}
|
|
98
102
|
};
|
|
99
103
|
/**
|
|
@@ -102,7 +106,7 @@ var PluginRuntime = class {
|
|
|
102
106
|
*/
|
|
103
107
|
function normalizeRemoteUrl(url) {
|
|
104
108
|
if (!url) return url;
|
|
105
|
-
if (url.endsWith(".js")) return url;
|
|
109
|
+
if (url.endsWith(".js") || url.endsWith(".json")) return url;
|
|
106
110
|
return `${url.endsWith("/") ? url.slice(0, -1) : url}/remoteEntry.js`;
|
|
107
111
|
}
|
|
108
112
|
/**
|
|
@@ -130,7 +134,7 @@ function normalizeRegistry(registry) {
|
|
|
130
134
|
}
|
|
131
135
|
/**
|
|
132
136
|
* Creates a plugin runtime with support for both module and remote plugin entries.
|
|
133
|
-
*
|
|
137
|
+
*
|
|
134
138
|
* @example
|
|
135
139
|
* ```typescript
|
|
136
140
|
* // With module entries (types inferred automatically)
|
|
@@ -141,7 +145,7 @@ function normalizeRegistry(registry) {
|
|
|
141
145
|
* },
|
|
142
146
|
* secrets: { API_KEY: "..." }
|
|
143
147
|
* });
|
|
144
|
-
*
|
|
148
|
+
*
|
|
145
149
|
* // Types are automatically inferred from module entries!
|
|
146
150
|
* const { router } = await runtime.usePlugin("telegram", config);
|
|
147
151
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Hash","Effect","PluginRuntimeError","effect","Exit","Cause","Option","PluginService","ManagedRuntime"],"sources":["../../src/runtime/index.ts"],"sourcesContent":["import { createRouterClient } from \"@orpc/server\";\nimport { Cause, Effect, Exit, Hash, ManagedRuntime, Option } from \"effect\";\nimport type {\n\tAnyPlugin,\n\tAnyPluginConstructor,\n\tInferRegistryFromEntries,\n\tInitializedPlugin,\n\tLoadedPlugin,\n\tPluginClientType,\n\tPluginConfigInput,\n\tPluginInstance,\n\tPluginRegistry,\n\tPluginRegistryEntry,\n\tPluginRouterType,\n\tPluginRuntimeConfig,\n\tRegisteredPlugin,\n\tRegisteredPlugins,\n\tUsePluginResult\n} from \"../types\";\nimport { PluginRuntimeError } from \"./errors\";\nimport { PluginService } from \"./services/plugin.service\";\n\nexport class PluginRuntime<R = RegisteredPlugins> {\n\treadonly ['__registryType']?: R;\n\t\n\tprivate pluginCache = new Map<string, Effect.Effect<InitializedPlugin<AnyPlugin>, PluginRuntimeError>>();\n\n\tconstructor(\n\t\tprivate runtime: ManagedRuntime.ManagedRuntime<PluginService, never>,\n\t\tprivate registry: PluginRegistry\n\t) { }\n\n\tprivate generateCacheKey(pluginId: string, config: unknown): string {\n\t\tconst configHash = Hash.structure(config as object).toString();\n\t\treturn `${pluginId}:${configHash}`;\n\t}\n\n\tprivate validatePluginId(\n\t\tpluginId: string\n\t): Effect.Effect<string, PluginRuntimeError> {\n\t\tif (!(pluginId in this.registry)) {\n\t\t\treturn Effect.fail(new PluginRuntimeError({\n\t\t\t\tpluginId: String(pluginId),\n\t\t\t\toperation: \"validate-plugin-id\",\n\t\t\t\tcause: new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),\n\t\t\t\tretryable: false,\n\t\t\t}));\n\t\t}\n\t\treturn Effect.succeed(String(pluginId));\n\t}\n\n\tprivate async runPromise<A, E>(\n\t\teffect: Effect.Effect<A, E, PluginService>\n\t): Promise<A> {\n\t\tconst exit = await this.runtime.runPromiseExit(effect);\n\n\t\tif (Exit.isFailure(exit)) {\n\t\t\tconst error = Cause.failureOption(exit.cause);\n\t\t\tif (Option.isSome(error)) {\n\t\t\t\tthrow error.value;\n\t\t\t}\n\t\t\tthrow Cause.squash(exit.cause);\n\t\t}\n\n\t\treturn exit.value;\n\t}\n\n\tasync usePlugin<K extends keyof R & string>(\n\t\tpluginId: K,\n\t\tconfig: PluginConfigInput<R[K]>\n\t): Promise<UsePluginResult<K, R>> {\n\t\tconst cacheKey = this.generateCacheKey(pluginId, config);\n\n\t\tlet cachedPlugin = this.pluginCache.get(cacheKey);\n\t\tif (!cachedPlugin) {\n\t\t\tconst operation = Effect.gen(this, function* () {\n\t\t\t\tconst pluginService = yield* PluginService;\n\t\t\t\tconst validatedId = yield* this.validatePluginId(pluginId);\n\n\t\t\t\t// Load → Instantiate → Initialize\n\t\t\t\tconst ctor = yield* pluginService.loadPlugin(validatedId);\n\t\t\t\tconst instance = yield* pluginService.instantiatePlugin(pluginId, ctor);\n\t\t\t\tconst initialized = yield* pluginService.initializePlugin(instance, config);\n\n\t\t\t\treturn initialized;\n\t\t\t}).pipe(Effect.provide(this.runtime));\n\n\t\t\tcachedPlugin = Effect.cached(operation).pipe(Effect.flatten);\n\t\t\tthis.pluginCache.set(cacheKey, cachedPlugin);\n\t\t}\n\n\t\tconst initialized = await this.runPromise(cachedPlugin);\n\n\t\t// Create client factory that accepts request context\n\t\tconst createClient = (context?: any) => {\n\t\t\tconst router = initialized.plugin.createRouter(initialized.context);\n\t\t\treturn createRouterClient(router, { context: context ?? {} });\n\t\t};\n\n\t\treturn {\n\t\t\tcreateClient: createClient as any,\n\t\t\trouter: initialized.plugin.createRouter(initialized.context) as PluginRouterType<R[K]>,\n\t\t\tmetadata: initialized.metadata,\n\t\t\tinitialized: initialized as InitializedPlugin<RegisteredPlugin<K, R>>\n\t\t} as UsePluginResult<K, R>;\n\t}\n\n\tasync loadPlugin<K extends keyof R & string>(\n\t\tpluginId: K\n\t): Promise<LoadedPlugin<RegisteredPlugin<K, R>>> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\treturn yield* pluginService.loadPlugin(pluginId);\n\t\t});\n\t\treturn this.runPromise(effect) as Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;\n\t}\n\n\tasync instantiatePlugin<K extends keyof R & string>(\n\t\tpluginId: K,\n\t\tloadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>\n\t): Promise<PluginInstance<RegisteredPlugin<K, R>>> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\treturn yield* pluginService.instantiatePlugin(pluginId, loadedPlugin);\n\t\t});\n\t\treturn this.runPromise(effect) as Promise<PluginInstance<RegisteredPlugin<K, R>>>;\n\t}\n\n\tasync initializePlugin<T extends AnyPlugin>(\n\t\tinstance: PluginInstance<T>,\n\t\tconfig: any\n\t): Promise<InitializedPlugin<T>> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\treturn yield* pluginService.initializePlugin(instance, config);\n\t\t});\n\t\treturn this.runPromise(effect);\n\t}\n\n\tasync shutdown(): Promise<void> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\tyield* pluginService.cleanup();\n\t\t});\n\t\treturn this.runPromise(effect);\n\t}\n\n\tasync evictPlugin<K extends keyof R & string>(\n\t\tpluginId: K,\n\t\tconfig: PluginConfigInput<R[K]>\n\t): Promise<void> {\n\t\tconst cacheKey = this.generateCacheKey(pluginId, config);\n\n\t\tconst effect = Effect.gen(this, function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\tconst cachedPlugin = this.pluginCache.get(cacheKey);\n\n\t\t\tif (cachedPlugin) {\n\t\t\t\tthis.pluginCache.delete(cacheKey);\n\n\t\t\t\tconst pluginResult = yield* cachedPlugin.pipe(\n\t\t\t\t\tEffect.catchAll(() => Effect.succeed(null))\n\t\t\t\t);\n\n\t\t\t\tif (pluginResult) {\n\t\t\t\t\tyield* pluginService.shutdownPlugin(pluginResult).pipe(\n\t\t\t\t\t\tEffect.catchAll(() => Effect.void)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}).pipe(Effect.catchAll(() => Effect.void));\n\n\t\treturn this.runPromise(effect);\n\t}\n}\n\n/**\n * Normalizes a remote URL to ensure it points to remoteEntry.js\n * If the URL doesn't end with a file extension, appends /remoteEntry.js\n */\nfunction normalizeRemoteUrl(url: string): string {\n\tif (!url) return url;\n\tif (url.endsWith('.js')) return url;\n\treturn `${url.endsWith('/') ? url.slice(0, -1) : url}/remoteEntry.js`;\n}\n\n/**\n * Extract plugin map (module constructors) from registry entries\n */\nfunction extractPluginMap(registry: Record<string, PluginRegistryEntry>): Record<string, AnyPluginConstructor> {\n\tconst pluginMap: Record<string, AnyPluginConstructor> = {};\n\t\n\tfor (const [pluginId, entry] of Object.entries(registry)) {\n\t\tif (\"module\" in entry && entry.module) {\n\t\t\tpluginMap[pluginId] = entry.module;\n\t\t}\n\t}\n\t\n\treturn pluginMap;\n}\n\n/**\n * Normalize registry entries - ensure remote URLs are properly formatted\n */\nfunction normalizeRegistry(registry: Record<string, PluginRegistryEntry>): PluginRegistry {\n\tconst normalized: Record<string, PluginRegistryEntry> = {};\n\t\n\tfor (const [pluginId, entry] of Object.entries(registry)) {\n\t\tif (\"module\" in entry) {\n\t\t\tnormalized[pluginId] = {\n\t\t\t\t...entry,\n\t\t\t\tremote: entry.remote ? normalizeRemoteUrl(entry.remote) : undefined,\n\t\t\t};\n\t\t} else {\n\t\t\tnormalized[pluginId] = {\n\t\t\t\t...entry,\n\t\t\t\tremote: normalizeRemoteUrl(entry.remote),\n\t\t\t};\n\t\t}\n\t}\n\t\n\treturn normalized as PluginRegistry;\n}\n\n/**\n * Creates a plugin runtime with support for both module and remote plugin entries.\n * \n * @example\n * ```typescript\n * // With module entries (types inferred automatically)\n * const runtime = createPluginRuntime({\n * registry: {\n * telegram: { module: TelegramPlugin },\n * gopher: { remote: \"https://cdn.example.com/gopher/remoteEntry.js\" }\n * },\n * secrets: { API_KEY: \"...\" }\n * });\n * \n * // Types are automatically inferred from module entries!\n * const { router } = await runtime.usePlugin(\"telegram\", config);\n * ```\n */\nexport function createPluginRuntime<\n\tTRegistry extends Record<string, PluginRegistryEntry>\n>(\n\tconfig: PluginRuntimeConfig<TRegistry>\n): PluginRuntime<InferRegistryFromEntries<TRegistry>> {\n\tconst secrets = config.secrets || {};\n\tconst normalizedRegistry = normalizeRegistry(config.registry);\n\tconst pluginMap = extractPluginMap(config.registry);\n\n\tconst layer = PluginService.Live(normalizedRegistry, secrets, pluginMap);\n\tconst runtime = ManagedRuntime.make(layer);\n\n\treturn new PluginRuntime(runtime, normalizedRegistry) as PluginRuntime<InferRegistryFromEntries<TRegistry>>;\n}\n"],"mappings":";;;;;;;AAsBA,IAAa,gBAAb,MAAkD;CACjD,CAAU;CAEV,AAA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KACjDA,cAAO,eAAeA,cAAO,KAAK,CAClC;;IAGF,CAAC,KAAKA,cAAO,eAAeA,cAAO,KAAK,CAAC;AAE3C,SAAO,KAAK,WAAWE,SAAO;;;;;;;AAQhC,SAAS,mBAAmB,KAAqB;AAChD,KAAI,CAAC,IAAK,QAAO;AACjB,KAAI,IAAI,SAAS,MAAM,CAAE,QAAO;AAChC,QAAO,GAAG,IAAI,SAAS,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,GAAG,IAAI;;;;;AAMtD,SAAS,iBAAiB,UAAqF;CAC9G,MAAM,YAAkD,EAAE;AAE1D,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,SAAS,CACvD,KAAI,YAAY,SAAS,MAAM,OAC9B,WAAU,YAAY,MAAM;AAI9B,QAAO;;;;;AAMR,SAAS,kBAAkB,UAA+D;CACzF,MAAM,aAAkD,EAAE;AAE1D,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,SAAS,CACvD,KAAI,YAAY,MACf,YAAW,YAAY;EACtB,GAAG;EACH,QAAQ,MAAM,SAAS,mBAAmB,MAAM,OAAO,GAAG;EAC1D;KAED,YAAW,YAAY;EACtB,GAAG;EACH,QAAQ,mBAAmB,MAAM,OAAO;EACxC;AAIH,QAAO;;;;;;;;;;;;;;;;;;;;AAqBR,SAAgB,oBAGf,QACqD;CACrD,MAAM,UAAU,OAAO,WAAW,EAAE;CACpC,MAAM,qBAAqB,kBAAkB,OAAO,SAAS;CAC7D,MAAM,YAAY,iBAAiB,OAAO,SAAS;CAEnD,MAAM,QAAQI,qCAAc,KAAK,oBAAoB,SAAS,UAAU;AAGxE,QAAO,IAAI,cAFKC,sBAAe,KAAK,MAAM,EAER,mBAAmB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Hash","Effect","PluginRuntimeError","effect","Exit","Cause","Option","PluginService","ManagedRuntime"],"sources":["../../src/runtime/index.ts"],"sourcesContent":["import { createRouterClient } from \"@orpc/server\";\nimport { Cause, Effect, Exit, Hash, ManagedRuntime, Option } from \"effect\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InferRegistryFromEntries,\n InitializedPlugin,\n LoadedPlugin,\n PluginConfigInput,\n PluginInstance,\n PluginRegistry,\n PluginRegistryEntry,\n PluginRouterType,\n PluginRuntimeConfig,\n RegisteredPlugin,\n RegisteredPlugins,\n UsePluginResult,\n} from \"../types\";\nimport { PluginRuntimeError } from \"./errors\";\nimport { PluginService } from \"./services/plugin.service\";\n\nexport class PluginRuntime<R = RegisteredPlugins> {\n readonly __registryType?: R;\n\n private pluginCache = new Map<\n string,\n Effect.Effect<InitializedPlugin<AnyPlugin>, PluginRuntimeError>\n >();\n\n constructor(\n private runtime: ManagedRuntime.ManagedRuntime<PluginService, never>,\n private registry: PluginRegistry,\n ) {}\n\n private generateCacheKey(pluginId: string, config: unknown): string {\n const configHash = Hash.structure(config as object).toString();\n return `${pluginId}:${configHash}`;\n }\n\n private validatePluginId(pluginId: string): Effect.Effect<string, PluginRuntimeError> {\n if (!(pluginId in this.registry)) {\n return Effect.fail(\n new PluginRuntimeError({\n pluginId: String(pluginId),\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),\n retryable: false,\n }),\n );\n }\n return Effect.succeed(String(pluginId));\n }\n\n private async runPromise<A, E>(effect: Effect.Effect<A, E, PluginService>): Promise<A> {\n const exit = await this.runtime.runPromiseExit(effect);\n\n if (Exit.isFailure(exit)) {\n const error = Cause.failureOption(exit.cause);\n if (Option.isSome(error)) {\n throw error.value;\n }\n throw Cause.squash(exit.cause);\n }\n\n return exit.value;\n }\n\n async usePlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n plugins?: Record<string, unknown>,\n ): Promise<UsePluginResult<K, R>> {\n const cacheKey = this.generateCacheKey(pluginId, { ...config, __plugins: plugins ?? {} });\n\n let cachedPlugin = this.pluginCache.get(cacheKey);\n if (!cachedPlugin) {\n const operation = Effect.gen(this, function* () {\n const pluginService = yield* PluginService;\n const validatedId = yield* this.validatePluginId(pluginId);\n\n // Load → Instantiate → Initialize\n const ctor = yield* pluginService.loadPlugin(validatedId);\n const instance = yield* pluginService.instantiatePlugin(pluginId, ctor);\n const initialized = yield* pluginService.initializePlugin(instance, config, plugins);\n\n return initialized;\n }).pipe(Effect.provide(this.runtime));\n\n cachedPlugin = Effect.cached(operation).pipe(Effect.flatten);\n this.pluginCache.set(cacheKey, cachedPlugin);\n }\n\n const initialized = await this.runPromise(cachedPlugin);\n\n // Create client factory that accepts request context\n const createClient = (context?: any) => {\n const router = initialized.plugin.createRouter(initialized.context);\n return createRouterClient(router, { context: context ?? {} });\n };\n\n return {\n createClient: createClient as any,\n router: initialized.plugin.createRouter(initialized.context) as PluginRouterType<R[K]>,\n metadata: initialized.metadata,\n initialized: initialized as InitializedPlugin<RegisteredPlugin<K, R>>,\n } as UsePluginResult<K, R>;\n }\n\n async loadPlugin<K extends keyof R & string>(\n pluginId: K,\n ): Promise<LoadedPlugin<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.loadPlugin(pluginId);\n });\n return this.runPromise(effect) as Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;\n }\n\n async instantiatePlugin<K extends keyof R & string>(\n pluginId: K,\n loadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>,\n ): Promise<PluginInstance<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.instantiatePlugin(pluginId, loadedPlugin);\n });\n return this.runPromise(effect) as Promise<PluginInstance<RegisteredPlugin<K, R>>>;\n }\n\n async initializePlugin<T extends AnyPlugin>(\n instance: PluginInstance<T>,\n config: any,\n plugins?: Record<string, unknown>,\n ): Promise<InitializedPlugin<T>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.initializePlugin(instance, config, plugins);\n });\n return this.runPromise(effect);\n }\n\n async shutdown(): Promise<void> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n yield* pluginService.cleanup();\n });\n return this.runPromise(effect);\n }\n\n async evictPlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n ): Promise<void> {\n const cacheKey = this.generateCacheKey(pluginId, config);\n\n const effect = Effect.gen(this, function* () {\n const pluginService = yield* PluginService;\n const cachedPlugin = this.pluginCache.get(cacheKey);\n\n if (cachedPlugin) {\n this.pluginCache.delete(cacheKey);\n\n const pluginResult = yield* cachedPlugin.pipe(Effect.catchAll(() => Effect.succeed(null)));\n\n if (pluginResult) {\n yield* pluginService\n .shutdownPlugin(pluginResult)\n .pipe(Effect.catchAll(() => Effect.void));\n }\n }\n }).pipe(Effect.catchAll(() => Effect.void));\n\n return this.runPromise(effect);\n }\n}\n\n/**\n * Normalizes a remote URL to ensure it points to remoteEntry.js\n * If the URL doesn't end with a file extension, appends /remoteEntry.js\n */\nfunction normalizeRemoteUrl(url: string): string {\n if (!url) return url;\n if (url.endsWith(\".js\") || url.endsWith(\".json\")) return url;\n return `${url.endsWith(\"/\") ? url.slice(0, -1) : url}/remoteEntry.js`;\n}\n\n/**\n * Extract plugin map (module constructors) from registry entries\n */\nfunction extractPluginMap(\n registry: Record<string, PluginRegistryEntry>,\n): Record<string, AnyPluginConstructor> {\n const pluginMap: Record<string, AnyPluginConstructor> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry && entry.module) {\n pluginMap[pluginId] = entry.module;\n }\n }\n\n return pluginMap;\n}\n\n/**\n * Normalize registry entries - ensure remote URLs are properly formatted\n */\nfunction normalizeRegistry(registry: Record<string, PluginRegistryEntry>): PluginRegistry {\n const normalized: Record<string, PluginRegistryEntry> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry) {\n normalized[pluginId] = {\n ...entry,\n remote: entry.remote ? normalizeRemoteUrl(entry.remote) : undefined,\n };\n } else {\n normalized[pluginId] = {\n ...entry,\n remote: normalizeRemoteUrl(entry.remote),\n };\n }\n }\n\n return normalized as PluginRegistry;\n}\n\n/**\n * Creates a plugin runtime with support for both module and remote plugin entries.\n *\n * @example\n * ```typescript\n * // With module entries (types inferred automatically)\n * const runtime = createPluginRuntime({\n * registry: {\n * telegram: { module: TelegramPlugin },\n * gopher: { remote: \"https://cdn.example.com/gopher/remoteEntry.js\" }\n * },\n * secrets: { API_KEY: \"...\" }\n * });\n *\n * // Types are automatically inferred from module entries!\n * const { router } = await runtime.usePlugin(\"telegram\", config);\n * ```\n */\nexport function createPluginRuntime<TRegistry extends Record<string, PluginRegistryEntry>>(\n config: PluginRuntimeConfig<TRegistry>,\n): PluginRuntime<InferRegistryFromEntries<TRegistry>> {\n const secrets = config.secrets || {};\n const normalizedRegistry = normalizeRegistry(config.registry);\n const pluginMap = extractPluginMap(config.registry);\n\n const layer = PluginService.Live(normalizedRegistry, secrets, pluginMap);\n const runtime = ManagedRuntime.make(layer);\n\n return new PluginRuntime(runtime, normalizedRegistry) as PluginRuntime<\n InferRegistryFromEntries<TRegistry>\n >;\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,gBAAb,MAAkD;CAChD,AAAS;CAET,AAAQ,8BAAc,IAAI,KAGvB;CAEH,YACE,AAAQ,SACR,AAAQ,UACR;EAFQ;EACA;;CAGV,AAAQ,iBAAiB,UAAkB,QAAyB;AAElE,SAAO,GAAG,SAAS,GADAA,YAAK,UAAU,OAAiB,CAAC,UAAU;;CAIhE,AAAQ,iBAAiB,UAA6D;AACpF,MAAI,EAAE,YAAY,KAAK,UACrB,QAAOC,cAAO,KACZ,IAAIC,kCAAmB;GACrB,UAAU,OAAO,SAAS;GAC1B,WAAW;GACX,uBAAO,IAAI,MAAM,cAAc,OAAO,SAAS,CAAC,0BAA0B;GAC1E,WAAW;GACZ,CAAC,CACH;AAEH,SAAOD,cAAO,QAAQ,OAAO,SAAS,CAAC;;CAGzC,MAAc,WAAiB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AkD,EAAE;AAE1D,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,SAAS,CACtD,KAAI,YAAY,SAAS,MAAM,OAC7B,WAAU,YAAY,MAAM;AAIhC,QAAO;;;;;AAMT,SAAS,kBAAkB,UAA+D;CACxF,MAAM,aAAkD,EAAE;AAE1D,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,SAAS,CACtD,KAAI,YAAY,MACd,YAAW,YAAY;EACrB,GAAG;EACH,QAAQ,MAAM,SAAS,mBAAmB,MAAM,OAAO,GAAG;EAC3D;KAED,YAAW,YAAY;EACrB,GAAG;EACH,QAAQ,mBAAmB,MAAM,OAAO;EACzC;AAIL,QAAO;;;;;;;;;;;;;;;;;;;;AAqBT,SAAgB,oBACd,QACoD;CACpD,MAAM,UAAU,OAAO,WAAW,EAAE;CACpC,MAAM,qBAAqB,kBAAkB,OAAO,SAAS;CAC7D,MAAM,YAAY,iBAAiB,OAAO,SAAS;CAEnD,MAAM,QAAQI,qCAAc,KAAK,oBAAoB,SAAS,UAAU;AAGxE,QAAO,IAAI,cAFKC,sBAAe,KAAK,MAAM,EAER,mBAAmB"}
|
package/dist/runtime/index.d.cts
CHANGED
|
@@ -6,16 +6,16 @@ import { ManagedRuntime } from "effect";
|
|
|
6
6
|
declare class PluginRuntime<R = RegisteredPlugins> {
|
|
7
7
|
private runtime;
|
|
8
8
|
private registry;
|
|
9
|
-
readonly
|
|
9
|
+
readonly __registryType?: R;
|
|
10
10
|
private pluginCache;
|
|
11
11
|
constructor(runtime: ManagedRuntime.ManagedRuntime<PluginService, never>, registry: PluginRegistry);
|
|
12
12
|
private generateCacheKey;
|
|
13
13
|
private validatePluginId;
|
|
14
14
|
private runPromise;
|
|
15
|
-
usePlugin<K extends keyof R & string>(pluginId: K, config: PluginConfigInput<R[K]>): Promise<UsePluginResult<K, R>>;
|
|
15
|
+
usePlugin<K extends keyof R & string>(pluginId: K, config: PluginConfigInput<R[K]>, plugins?: Record<string, unknown>): Promise<UsePluginResult<K, R>>;
|
|
16
16
|
loadPlugin<K extends keyof R & string>(pluginId: K): Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;
|
|
17
17
|
instantiatePlugin<K extends keyof R & string>(pluginId: K, loadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>): Promise<PluginInstance<RegisteredPlugin<K, R>>>;
|
|
18
|
-
initializePlugin<T extends AnyPlugin>(instance: PluginInstance<T>, config: any): Promise<InitializedPlugin<T>>;
|
|
18
|
+
initializePlugin<T extends AnyPlugin>(instance: PluginInstance<T>, config: any, plugins?: Record<string, unknown>): Promise<InitializedPlugin<T>>;
|
|
19
19
|
shutdown(): Promise<void>;
|
|
20
20
|
evictPlugin<K extends keyof R & string>(pluginId: K, config: PluginConfigInput<R[K]>): Promise<void>;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/runtime/index.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/runtime/index.ts"],"mappings":";;;;;cAqBa,aAAA,KAAkB,iBAAA;EAAA,QASnB,OAAA;EAAA,QACA,QAAA;EAAA,SATD,cAAA,GAAiB,CAAA;EAAA,QAElB,WAAA;cAME,OAAA,EAAS,cAAA,CAAe,cAAA,CAAe,aAAA,UACvC,QAAA,EAAU,cAAA;EAAA,QAGZ,gBAAA;EAAA,QAKA,gBAAA;EAAA,QAcM,UAAA;EAcR,SAAA,iBAA0B,CAAA,UAAA,CAC9B,QAAA,EAAU,CAAA,EACV,MAAA,EAAQ,iBAAA,CAAkB,CAAA,CAAE,CAAA,IAC5B,OAAA,GAAU,MAAA,oBACT,OAAA,CAAQ,eAAA,CAAgB,CAAA,EAAG,CAAA;EAqCxB,UAAA,iBAA2B,CAAA,UAAA,CAC/B,QAAA,EAAU,CAAA,GACT,OAAA,CAAQ,YAAA,CAAa,gBAAA,CAAiB,CAAA,EAAG,CAAA;EAQtC,iBAAA,iBAAkC,CAAA,UAAA,CACtC,QAAA,EAAU,CAAA,EACV,YAAA,EAAc,YAAA,CAAa,gBAAA,CAAiB,CAAA,EAAG,CAAA,KAC9C,OAAA,CAAQ,cAAA,CAAe,gBAAA,CAAiB,CAAA,EAAG,CAAA;EAQxC,gBAAA,WAA2B,SAAA,CAAA,CAC/B,QAAA,EAAU,cAAA,CAAe,CAAA,GACzB,MAAA,OACA,OAAA,GAAU,MAAA,oBACT,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EAQvB,QAAA,CAAA,GAAY,OAAA;EAQZ,WAAA,iBAA4B,CAAA,UAAA,CAChC,QAAA,EAAU,CAAA,EACV,MAAA,EAAQ,iBAAA,CAAkB,CAAA,CAAE,CAAA,KAC3B,OAAA;AAAA;;;;;;;;;;;;;;;;;;;iBA4FW,mBAAA,mBAAsC,MAAA,SAAe,mBAAA,EAAA,CACnE,MAAA,EAAQ,mBAAA,CAAoB,SAAA,IAC3B,aAAA,CAAc,wBAAA,CAAyB,SAAA"}
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -6,16 +6,16 @@ import { ManagedRuntime } from "effect";
|
|
|
6
6
|
declare class PluginRuntime<R = RegisteredPlugins> {
|
|
7
7
|
private runtime;
|
|
8
8
|
private registry;
|
|
9
|
-
readonly
|
|
9
|
+
readonly __registryType?: R;
|
|
10
10
|
private pluginCache;
|
|
11
11
|
constructor(runtime: ManagedRuntime.ManagedRuntime<PluginService, never>, registry: PluginRegistry);
|
|
12
12
|
private generateCacheKey;
|
|
13
13
|
private validatePluginId;
|
|
14
14
|
private runPromise;
|
|
15
|
-
usePlugin<K extends keyof R & string>(pluginId: K, config: PluginConfigInput<R[K]>): Promise<UsePluginResult<K, R>>;
|
|
15
|
+
usePlugin<K extends keyof R & string>(pluginId: K, config: PluginConfigInput<R[K]>, plugins?: Record<string, unknown>): Promise<UsePluginResult<K, R>>;
|
|
16
16
|
loadPlugin<K extends keyof R & string>(pluginId: K): Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;
|
|
17
17
|
instantiatePlugin<K extends keyof R & string>(pluginId: K, loadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>): Promise<PluginInstance<RegisteredPlugin<K, R>>>;
|
|
18
|
-
initializePlugin<T extends AnyPlugin>(instance: PluginInstance<T>, config: any): Promise<InitializedPlugin<T>>;
|
|
18
|
+
initializePlugin<T extends AnyPlugin>(instance: PluginInstance<T>, config: any, plugins?: Record<string, unknown>): Promise<InitializedPlugin<T>>;
|
|
19
19
|
shutdown(): Promise<void>;
|
|
20
20
|
evictPlugin<K extends keyof R & string>(pluginId: K, config: PluginConfigInput<R[K]>): Promise<void>;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/runtime/index.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/runtime/index.ts"],"mappings":";;;;;cAqBa,aAAA,KAAkB,iBAAA;EAAA,QASnB,OAAA;EAAA,QACA,QAAA;EAAA,SATD,cAAA,GAAiB,CAAA;EAAA,QAElB,WAAA;cAME,OAAA,EAAS,cAAA,CAAe,cAAA,CAAe,aAAA,UACvC,QAAA,EAAU,cAAA;EAAA,QAGZ,gBAAA;EAAA,QAKA,gBAAA;EAAA,QAcM,UAAA;EAcR,SAAA,iBAA0B,CAAA,UAAA,CAC9B,QAAA,EAAU,CAAA,EACV,MAAA,EAAQ,iBAAA,CAAkB,CAAA,CAAE,CAAA,IAC5B,OAAA,GAAU,MAAA,oBACT,OAAA,CAAQ,eAAA,CAAgB,CAAA,EAAG,CAAA;EAqCxB,UAAA,iBAA2B,CAAA,UAAA,CAC/B,QAAA,EAAU,CAAA,GACT,OAAA,CAAQ,YAAA,CAAa,gBAAA,CAAiB,CAAA,EAAG,CAAA;EAQtC,iBAAA,iBAAkC,CAAA,UAAA,CACtC,QAAA,EAAU,CAAA,EACV,YAAA,EAAc,YAAA,CAAa,gBAAA,CAAiB,CAAA,EAAG,CAAA,KAC9C,OAAA,CAAQ,cAAA,CAAe,gBAAA,CAAiB,CAAA,EAAG,CAAA;EAQxC,gBAAA,WAA2B,SAAA,CAAA,CAC/B,QAAA,EAAU,cAAA,CAAe,CAAA,GACzB,MAAA,OACA,OAAA,GAAU,MAAA,oBACT,OAAA,CAAQ,iBAAA,CAAkB,CAAA;EAQvB,QAAA,CAAA,GAAY,OAAA;EAQZ,WAAA,iBAA4B,CAAA,UAAA,CAChC,QAAA,EAAU,CAAA,EACV,MAAA,EAAQ,iBAAA,CAAkB,CAAA,CAAE,CAAA,KAC3B,OAAA;AAAA;;;;;;;;;;;;;;;;;;;iBA4FW,mBAAA,mBAAsC,MAAA,SAAe,mBAAA,EAAA,CACnE,MAAA,EAAQ,mBAAA,CAAoB,SAAA,IAC3B,aAAA,CAAc,wBAAA,CAAyB,SAAA"}
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { createRouterClient } from "@orpc/server";
|
|
|
5
5
|
|
|
6
6
|
//#region src/runtime/index.ts
|
|
7
7
|
var PluginRuntime = class {
|
|
8
|
-
|
|
8
|
+
__registryType;
|
|
9
9
|
pluginCache = /* @__PURE__ */ new Map();
|
|
10
10
|
constructor(runtime, registry) {
|
|
11
11
|
this.runtime = runtime;
|
|
@@ -32,8 +32,11 @@ var PluginRuntime = class {
|
|
|
32
32
|
}
|
|
33
33
|
return exit.value;
|
|
34
34
|
}
|
|
35
|
-
async usePlugin(pluginId, config) {
|
|
36
|
-
const cacheKey = this.generateCacheKey(pluginId,
|
|
35
|
+
async usePlugin(pluginId, config, plugins) {
|
|
36
|
+
const cacheKey = this.generateCacheKey(pluginId, {
|
|
37
|
+
...config,
|
|
38
|
+
__plugins: plugins ?? {}
|
|
39
|
+
});
|
|
37
40
|
let cachedPlugin = this.pluginCache.get(cacheKey);
|
|
38
41
|
if (!cachedPlugin) {
|
|
39
42
|
const operation = Effect.gen(this, function* () {
|
|
@@ -41,7 +44,7 @@ var PluginRuntime = class {
|
|
|
41
44
|
const validatedId = yield* this.validatePluginId(pluginId);
|
|
42
45
|
const ctor = yield* pluginService.loadPlugin(validatedId);
|
|
43
46
|
const instance = yield* pluginService.instantiatePlugin(pluginId, ctor);
|
|
44
|
-
return yield* pluginService.initializePlugin(instance, config);
|
|
47
|
+
return yield* pluginService.initializePlugin(instance, config, plugins);
|
|
45
48
|
}).pipe(Effect.provide(this.runtime));
|
|
46
49
|
cachedPlugin = Effect.cached(operation).pipe(Effect.flatten);
|
|
47
50
|
this.pluginCache.set(cacheKey, cachedPlugin);
|
|
@@ -69,9 +72,9 @@ var PluginRuntime = class {
|
|
|
69
72
|
});
|
|
70
73
|
return this.runPromise(effect);
|
|
71
74
|
}
|
|
72
|
-
async initializePlugin(instance, config) {
|
|
75
|
+
async initializePlugin(instance, config, plugins) {
|
|
73
76
|
const effect = Effect.gen(function* () {
|
|
74
|
-
return yield* (yield* PluginService).initializePlugin(instance, config);
|
|
77
|
+
return yield* (yield* PluginService).initializePlugin(instance, config, plugins);
|
|
75
78
|
});
|
|
76
79
|
return this.runPromise(effect);
|
|
77
80
|
}
|
|
@@ -101,7 +104,7 @@ var PluginRuntime = class {
|
|
|
101
104
|
*/
|
|
102
105
|
function normalizeRemoteUrl(url) {
|
|
103
106
|
if (!url) return url;
|
|
104
|
-
if (url.endsWith(".js")) return url;
|
|
107
|
+
if (url.endsWith(".js") || url.endsWith(".json")) return url;
|
|
105
108
|
return `${url.endsWith("/") ? url.slice(0, -1) : url}/remoteEntry.js`;
|
|
106
109
|
}
|
|
107
110
|
/**
|
|
@@ -129,7 +132,7 @@ function normalizeRegistry(registry) {
|
|
|
129
132
|
}
|
|
130
133
|
/**
|
|
131
134
|
* Creates a plugin runtime with support for both module and remote plugin entries.
|
|
132
|
-
*
|
|
135
|
+
*
|
|
133
136
|
* @example
|
|
134
137
|
* ```typescript
|
|
135
138
|
* // With module entries (types inferred automatically)
|
|
@@ -140,7 +143,7 @@ function normalizeRegistry(registry) {
|
|
|
140
143
|
* },
|
|
141
144
|
* secrets: { API_KEY: "..." }
|
|
142
145
|
* });
|
|
143
|
-
*
|
|
146
|
+
*
|
|
144
147
|
* // Types are automatically inferred from module entries!
|
|
145
148
|
* const { router } = await runtime.usePlugin("telegram", config);
|
|
146
149
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/runtime/index.ts"],"sourcesContent":["import { createRouterClient } from \"@orpc/server\";\nimport { Cause, Effect, Exit, Hash, ManagedRuntime, Option } from \"effect\";\nimport type {\n\tAnyPlugin,\n\tAnyPluginConstructor,\n\tInferRegistryFromEntries,\n\tInitializedPlugin,\n\tLoadedPlugin,\n\tPluginClientType,\n\tPluginConfigInput,\n\tPluginInstance,\n\tPluginRegistry,\n\tPluginRegistryEntry,\n\tPluginRouterType,\n\tPluginRuntimeConfig,\n\tRegisteredPlugin,\n\tRegisteredPlugins,\n\tUsePluginResult\n} from \"../types\";\nimport { PluginRuntimeError } from \"./errors\";\nimport { PluginService } from \"./services/plugin.service\";\n\nexport class PluginRuntime<R = RegisteredPlugins> {\n\treadonly ['__registryType']?: R;\n\t\n\tprivate pluginCache = new Map<string, Effect.Effect<InitializedPlugin<AnyPlugin>, PluginRuntimeError>>();\n\n\tconstructor(\n\t\tprivate runtime: ManagedRuntime.ManagedRuntime<PluginService, never>,\n\t\tprivate registry: PluginRegistry\n\t) { }\n\n\tprivate generateCacheKey(pluginId: string, config: unknown): string {\n\t\tconst configHash = Hash.structure(config as object).toString();\n\t\treturn `${pluginId}:${configHash}`;\n\t}\n\n\tprivate validatePluginId(\n\t\tpluginId: string\n\t): Effect.Effect<string, PluginRuntimeError> {\n\t\tif (!(pluginId in this.registry)) {\n\t\t\treturn Effect.fail(new PluginRuntimeError({\n\t\t\t\tpluginId: String(pluginId),\n\t\t\t\toperation: \"validate-plugin-id\",\n\t\t\t\tcause: new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),\n\t\t\t\tretryable: false,\n\t\t\t}));\n\t\t}\n\t\treturn Effect.succeed(String(pluginId));\n\t}\n\n\tprivate async runPromise<A, E>(\n\t\teffect: Effect.Effect<A, E, PluginService>\n\t): Promise<A> {\n\t\tconst exit = await this.runtime.runPromiseExit(effect);\n\n\t\tif (Exit.isFailure(exit)) {\n\t\t\tconst error = Cause.failureOption(exit.cause);\n\t\t\tif (Option.isSome(error)) {\n\t\t\t\tthrow error.value;\n\t\t\t}\n\t\t\tthrow Cause.squash(exit.cause);\n\t\t}\n\n\t\treturn exit.value;\n\t}\n\n\tasync usePlugin<K extends keyof R & string>(\n\t\tpluginId: K,\n\t\tconfig: PluginConfigInput<R[K]>\n\t): Promise<UsePluginResult<K, R>> {\n\t\tconst cacheKey = this.generateCacheKey(pluginId, config);\n\n\t\tlet cachedPlugin = this.pluginCache.get(cacheKey);\n\t\tif (!cachedPlugin) {\n\t\t\tconst operation = Effect.gen(this, function* () {\n\t\t\t\tconst pluginService = yield* PluginService;\n\t\t\t\tconst validatedId = yield* this.validatePluginId(pluginId);\n\n\t\t\t\t// Load → Instantiate → Initialize\n\t\t\t\tconst ctor = yield* pluginService.loadPlugin(validatedId);\n\t\t\t\tconst instance = yield* pluginService.instantiatePlugin(pluginId, ctor);\n\t\t\t\tconst initialized = yield* pluginService.initializePlugin(instance, config);\n\n\t\t\t\treturn initialized;\n\t\t\t}).pipe(Effect.provide(this.runtime));\n\n\t\t\tcachedPlugin = Effect.cached(operation).pipe(Effect.flatten);\n\t\t\tthis.pluginCache.set(cacheKey, cachedPlugin);\n\t\t}\n\n\t\tconst initialized = await this.runPromise(cachedPlugin);\n\n\t\t// Create client factory that accepts request context\n\t\tconst createClient = (context?: any) => {\n\t\t\tconst router = initialized.plugin.createRouter(initialized.context);\n\t\t\treturn createRouterClient(router, { context: context ?? {} });\n\t\t};\n\n\t\treturn {\n\t\t\tcreateClient: createClient as any,\n\t\t\trouter: initialized.plugin.createRouter(initialized.context) as PluginRouterType<R[K]>,\n\t\t\tmetadata: initialized.metadata,\n\t\t\tinitialized: initialized as InitializedPlugin<RegisteredPlugin<K, R>>\n\t\t} as UsePluginResult<K, R>;\n\t}\n\n\tasync loadPlugin<K extends keyof R & string>(\n\t\tpluginId: K\n\t): Promise<LoadedPlugin<RegisteredPlugin<K, R>>> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\treturn yield* pluginService.loadPlugin(pluginId);\n\t\t});\n\t\treturn this.runPromise(effect) as Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;\n\t}\n\n\tasync instantiatePlugin<K extends keyof R & string>(\n\t\tpluginId: K,\n\t\tloadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>\n\t): Promise<PluginInstance<RegisteredPlugin<K, R>>> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\treturn yield* pluginService.instantiatePlugin(pluginId, loadedPlugin);\n\t\t});\n\t\treturn this.runPromise(effect) as Promise<PluginInstance<RegisteredPlugin<K, R>>>;\n\t}\n\n\tasync initializePlugin<T extends AnyPlugin>(\n\t\tinstance: PluginInstance<T>,\n\t\tconfig: any\n\t): Promise<InitializedPlugin<T>> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\treturn yield* pluginService.initializePlugin(instance, config);\n\t\t});\n\t\treturn this.runPromise(effect);\n\t}\n\n\tasync shutdown(): Promise<void> {\n\t\tconst effect = Effect.gen(function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\tyield* pluginService.cleanup();\n\t\t});\n\t\treturn this.runPromise(effect);\n\t}\n\n\tasync evictPlugin<K extends keyof R & string>(\n\t\tpluginId: K,\n\t\tconfig: PluginConfigInput<R[K]>\n\t): Promise<void> {\n\t\tconst cacheKey = this.generateCacheKey(pluginId, config);\n\n\t\tconst effect = Effect.gen(this, function* () {\n\t\t\tconst pluginService = yield* PluginService;\n\t\t\tconst cachedPlugin = this.pluginCache.get(cacheKey);\n\n\t\t\tif (cachedPlugin) {\n\t\t\t\tthis.pluginCache.delete(cacheKey);\n\n\t\t\t\tconst pluginResult = yield* cachedPlugin.pipe(\n\t\t\t\t\tEffect.catchAll(() => Effect.succeed(null))\n\t\t\t\t);\n\n\t\t\t\tif (pluginResult) {\n\t\t\t\t\tyield* pluginService.shutdownPlugin(pluginResult).pipe(\n\t\t\t\t\t\tEffect.catchAll(() => Effect.void)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}).pipe(Effect.catchAll(() => Effect.void));\n\n\t\treturn this.runPromise(effect);\n\t}\n}\n\n/**\n * Normalizes a remote URL to ensure it points to remoteEntry.js\n * If the URL doesn't end with a file extension, appends /remoteEntry.js\n */\nfunction normalizeRemoteUrl(url: string): string {\n\tif (!url) return url;\n\tif (url.endsWith('.js')) return url;\n\treturn `${url.endsWith('/') ? url.slice(0, -1) : url}/remoteEntry.js`;\n}\n\n/**\n * Extract plugin map (module constructors) from registry entries\n */\nfunction extractPluginMap(registry: Record<string, PluginRegistryEntry>): Record<string, AnyPluginConstructor> {\n\tconst pluginMap: Record<string, AnyPluginConstructor> = {};\n\t\n\tfor (const [pluginId, entry] of Object.entries(registry)) {\n\t\tif (\"module\" in entry && entry.module) {\n\t\t\tpluginMap[pluginId] = entry.module;\n\t\t}\n\t}\n\t\n\treturn pluginMap;\n}\n\n/**\n * Normalize registry entries - ensure remote URLs are properly formatted\n */\nfunction normalizeRegistry(registry: Record<string, PluginRegistryEntry>): PluginRegistry {\n\tconst normalized: Record<string, PluginRegistryEntry> = {};\n\t\n\tfor (const [pluginId, entry] of Object.entries(registry)) {\n\t\tif (\"module\" in entry) {\n\t\t\tnormalized[pluginId] = {\n\t\t\t\t...entry,\n\t\t\t\tremote: entry.remote ? normalizeRemoteUrl(entry.remote) : undefined,\n\t\t\t};\n\t\t} else {\n\t\t\tnormalized[pluginId] = {\n\t\t\t\t...entry,\n\t\t\t\tremote: normalizeRemoteUrl(entry.remote),\n\t\t\t};\n\t\t}\n\t}\n\t\n\treturn normalized as PluginRegistry;\n}\n\n/**\n * Creates a plugin runtime with support for both module and remote plugin entries.\n * \n * @example\n * ```typescript\n * // With module entries (types inferred automatically)\n * const runtime = createPluginRuntime({\n * registry: {\n * telegram: { module: TelegramPlugin },\n * gopher: { remote: \"https://cdn.example.com/gopher/remoteEntry.js\" }\n * },\n * secrets: { API_KEY: \"...\" }\n * });\n * \n * // Types are automatically inferred from module entries!\n * const { router } = await runtime.usePlugin(\"telegram\", config);\n * ```\n */\nexport function createPluginRuntime<\n\tTRegistry extends Record<string, PluginRegistryEntry>\n>(\n\tconfig: PluginRuntimeConfig<TRegistry>\n): PluginRuntime<InferRegistryFromEntries<TRegistry>> {\n\tconst secrets = config.secrets || {};\n\tconst normalizedRegistry = normalizeRegistry(config.registry);\n\tconst pluginMap = extractPluginMap(config.registry);\n\n\tconst layer = PluginService.Live(normalizedRegistry, secrets, pluginMap);\n\tconst runtime = ManagedRuntime.make(layer);\n\n\treturn new PluginRuntime(runtime, normalizedRegistry) as PluginRuntime<InferRegistryFromEntries<TRegistry>>;\n}\n"],"mappings":";;;;;;AAsBA,IAAa,gBAAb,MAAkD;CACjD,CAAU;CAEV,AAAQ,8BAAc,IAAI,KAA8E;CAExG,YACC,AAAQ,SACR,AAAQ,UACP;EAFO;EACA;;CAGT,AAAQ,iBAAiB,UAAkB,QAAyB;AAEnE,SAAO,GAAG,SAAS,GADA,KAAK,UAAU,OAAiB,CAAC,UAAU;;CAI/D,AAAQ,iBACP,UAC4C;AAC5C,MAAI,EAAE,YAAY,KAAK,UACtB,QAAO,OAAO,KAAK,IAAI,mBAAmB;GACzC,UAAU,OAAO,SAAS;GAC1B,WAAW;GACX,uBAAO,IAAI,MAAM,cAAc,OAAO,SAAS,CAAC,0BAA0B;GAC1E,WAAW;GACX,CAAC,CAAC;AAEJ,SAAO,OAAO,QAAQ,OAAO,SAAS,CAAC;;CAGxC,MAAc,WACb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;;AAMR,SAAS,kBAAkB,UAA+D;CACzF,MAAM,aAAkD,EAAE;AAE1D,MAAK,MAAM,CAAC,UAAU,UAAU,OAAO,QAAQ,SAAS,CACvD,KAAI,YAAY,MACf,YAAW,YAAY;EACtB,GAAG;EACH,QAAQ,MAAM,SAAS,mBAAmB,MAAM,OAAO,GAAG;EAC1D;KAED,YAAW,YAAY;EACtB,GAAG;EACH,QAAQ,mBAAmB,MAAM,OAAO;EACxC;AAIH,QAAO;;;;;;;;;;;;;;;;;;;;AAqBR,SAAgB,oBAGf,QACqD;CACrD,MAAM,UAAU,OAAO,WAAW,EAAE;CACpC,MAAM,qBAAqB,kBAAkB,OAAO,SAAS;CAC7D,MAAM,YAAY,iBAAiB,OAAO,SAAS;CAEnD,MAAM,QAAQ,cAAc,KAAK,oBAAoB,SAAS,UAAU;AAGxE,QAAO,IAAI,cAFK,eAAe,KAAK,MAAM,EAER,mBAAmB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/runtime/index.ts"],"sourcesContent":["import { createRouterClient } from \"@orpc/server\";\nimport { Cause, Effect, Exit, Hash, ManagedRuntime, Option } from \"effect\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InferRegistryFromEntries,\n InitializedPlugin,\n LoadedPlugin,\n PluginConfigInput,\n PluginInstance,\n PluginRegistry,\n PluginRegistryEntry,\n PluginRouterType,\n PluginRuntimeConfig,\n RegisteredPlugin,\n RegisteredPlugins,\n UsePluginResult,\n} from \"../types\";\nimport { PluginRuntimeError } from \"./errors\";\nimport { PluginService } from \"./services/plugin.service\";\n\nexport class PluginRuntime<R = RegisteredPlugins> {\n readonly __registryType?: R;\n\n private pluginCache = new Map<\n string,\n Effect.Effect<InitializedPlugin<AnyPlugin>, PluginRuntimeError>\n >();\n\n constructor(\n private runtime: ManagedRuntime.ManagedRuntime<PluginService, never>,\n private registry: PluginRegistry,\n ) {}\n\n private generateCacheKey(pluginId: string, config: unknown): string {\n const configHash = Hash.structure(config as object).toString();\n return `${pluginId}:${configHash}`;\n }\n\n private validatePluginId(pluginId: string): Effect.Effect<string, PluginRuntimeError> {\n if (!(pluginId in this.registry)) {\n return Effect.fail(\n new PluginRuntimeError({\n pluginId: String(pluginId),\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),\n retryable: false,\n }),\n );\n }\n return Effect.succeed(String(pluginId));\n }\n\n private async runPromise<A, E>(effect: Effect.Effect<A, E, PluginService>): Promise<A> {\n const exit = await this.runtime.runPromiseExit(effect);\n\n if (Exit.isFailure(exit)) {\n const error = Cause.failureOption(exit.cause);\n if (Option.isSome(error)) {\n throw error.value;\n }\n throw Cause.squash(exit.cause);\n }\n\n return exit.value;\n }\n\n async usePlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n plugins?: Record<string, unknown>,\n ): Promise<UsePluginResult<K, R>> {\n const cacheKey = this.generateCacheKey(pluginId, { ...config, __plugins: plugins ?? {} });\n\n let cachedPlugin = this.pluginCache.get(cacheKey);\n if (!cachedPlugin) {\n const operation = Effect.gen(this, function* () {\n const pluginService = yield* PluginService;\n const validatedId = yield* this.validatePluginId(pluginId);\n\n // Load → Instantiate → Initialize\n const ctor = yield* pluginService.loadPlugin(validatedId);\n const instance = yield* pluginService.instantiatePlugin(pluginId, ctor);\n const initialized = yield* pluginService.initializePlugin(instance, config, plugins);\n\n return initialized;\n }).pipe(Effect.provide(this.runtime));\n\n cachedPlugin = Effect.cached(operation).pipe(Effect.flatten);\n this.pluginCache.set(cacheKey, cachedPlugin);\n }\n\n const initialized = await this.runPromise(cachedPlugin);\n\n // Create client factory that accepts request context\n const createClient = (context?: any) => {\n const router = initialized.plugin.createRouter(initialized.context);\n return createRouterClient(router, { context: context ?? {} });\n };\n\n return {\n createClient: createClient as any,\n router: initialized.plugin.createRouter(initialized.context) as PluginRouterType<R[K]>,\n metadata: initialized.metadata,\n initialized: initialized as InitializedPlugin<RegisteredPlugin<K, R>>,\n } as UsePluginResult<K, R>;\n }\n\n async loadPlugin<K extends keyof R & string>(\n pluginId: K,\n ): Promise<LoadedPlugin<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.loadPlugin(pluginId);\n });\n return this.runPromise(effect) as Promise<LoadedPlugin<RegisteredPlugin<K, R>>>;\n }\n\n async instantiatePlugin<K extends keyof R & string>(\n pluginId: K,\n loadedPlugin: LoadedPlugin<RegisteredPlugin<K, R>>,\n ): Promise<PluginInstance<RegisteredPlugin<K, R>>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.instantiatePlugin(pluginId, loadedPlugin);\n });\n return this.runPromise(effect) as Promise<PluginInstance<RegisteredPlugin<K, R>>>;\n }\n\n async initializePlugin<T extends AnyPlugin>(\n instance: PluginInstance<T>,\n config: any,\n plugins?: Record<string, unknown>,\n ): Promise<InitializedPlugin<T>> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n return yield* pluginService.initializePlugin(instance, config, plugins);\n });\n return this.runPromise(effect);\n }\n\n async shutdown(): Promise<void> {\n const effect = Effect.gen(function* () {\n const pluginService = yield* PluginService;\n yield* pluginService.cleanup();\n });\n return this.runPromise(effect);\n }\n\n async evictPlugin<K extends keyof R & string>(\n pluginId: K,\n config: PluginConfigInput<R[K]>,\n ): Promise<void> {\n const cacheKey = this.generateCacheKey(pluginId, config);\n\n const effect = Effect.gen(this, function* () {\n const pluginService = yield* PluginService;\n const cachedPlugin = this.pluginCache.get(cacheKey);\n\n if (cachedPlugin) {\n this.pluginCache.delete(cacheKey);\n\n const pluginResult = yield* cachedPlugin.pipe(Effect.catchAll(() => Effect.succeed(null)));\n\n if (pluginResult) {\n yield* pluginService\n .shutdownPlugin(pluginResult)\n .pipe(Effect.catchAll(() => Effect.void));\n }\n }\n }).pipe(Effect.catchAll(() => Effect.void));\n\n return this.runPromise(effect);\n }\n}\n\n/**\n * Normalizes a remote URL to ensure it points to remoteEntry.js\n * If the URL doesn't end with a file extension, appends /remoteEntry.js\n */\nfunction normalizeRemoteUrl(url: string): string {\n if (!url) return url;\n if (url.endsWith(\".js\") || url.endsWith(\".json\")) return url;\n return `${url.endsWith(\"/\") ? url.slice(0, -1) : url}/remoteEntry.js`;\n}\n\n/**\n * Extract plugin map (module constructors) from registry entries\n */\nfunction extractPluginMap(\n registry: Record<string, PluginRegistryEntry>,\n): Record<string, AnyPluginConstructor> {\n const pluginMap: Record<string, AnyPluginConstructor> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry && entry.module) {\n pluginMap[pluginId] = entry.module;\n }\n }\n\n return pluginMap;\n}\n\n/**\n * Normalize registry entries - ensure remote URLs are properly formatted\n */\nfunction normalizeRegistry(registry: Record<string, PluginRegistryEntry>): PluginRegistry {\n const normalized: Record<string, PluginRegistryEntry> = {};\n\n for (const [pluginId, entry] of Object.entries(registry)) {\n if (\"module\" in entry) {\n normalized[pluginId] = {\n ...entry,\n remote: entry.remote ? normalizeRemoteUrl(entry.remote) : undefined,\n };\n } else {\n normalized[pluginId] = {\n ...entry,\n remote: normalizeRemoteUrl(entry.remote),\n };\n }\n }\n\n return normalized as PluginRegistry;\n}\n\n/**\n * Creates a plugin runtime with support for both module and remote plugin entries.\n *\n * @example\n * ```typescript\n * // With module entries (types inferred automatically)\n * const runtime = createPluginRuntime({\n * registry: {\n * telegram: { module: TelegramPlugin },\n * gopher: { remote: \"https://cdn.example.com/gopher/remoteEntry.js\" }\n * },\n * secrets: { API_KEY: \"...\" }\n * });\n *\n * // Types are automatically inferred from module entries!\n * const { router } = await runtime.usePlugin(\"telegram\", config);\n * ```\n */\nexport function createPluginRuntime<TRegistry extends Record<string, PluginRegistryEntry>>(\n config: PluginRuntimeConfig<TRegistry>,\n): PluginRuntime<InferRegistryFromEntries<TRegistry>> {\n const secrets = config.secrets || {};\n const normalizedRegistry = normalizeRegistry(config.registry);\n const pluginMap = extractPluginMap(config.registry);\n\n const layer = PluginService.Live(normalizedRegistry, secrets, pluginMap);\n const runtime = ManagedRuntime.make(layer);\n\n return new PluginRuntime(runtime, normalizedRegistry) as PluginRuntime<\n InferRegistryFromEntries<TRegistry>\n >;\n}\n"],"mappings":";;;;;;AAqBA,IAAa,gBAAb,MAAkD;CAChD,AAAS;CAET,AAAQ,8BAAc,IAAI,KAGvB;CAEH,YACE,AAAQ,SACR,AAAQ,UACR;EAFQ;EACA;;CAGV,AAAQ,iBAAiB,UAAkB,QAAyB;AAElE,SAAO,GAAG,SAAS,GADA,KAAK,UAAU,OAAiB,CAAC,UAAU;;CAIhE,AAAQ,iBAAiB,UAA6D;AACpF,MAAI,EAAE,YAAY,KAAK,UACrB,QAAO,OAAO,KACZ,IAAI,mBAAmB;GACrB,UAAU,OAAO,SAAS;GAC1B,WAAW;GACX,uBAAO,IAAI,MAAM,cAAc,OAAO,SAAS,CAAC,0BAA0B;GAC1E,WAAW;GACZ,CAAC,CACH;AAEH,SAAO,OAAO,QAAQ,OAAO,SAAS,CAAC;;CAGzC,MAAc,WAAiB,QAAwD;EACrF,MAAM,OAAO,MAAM,KAAK,QAAQ,eAAe,OAAO;AAEtD,MAAI,KAAK,UAAU,KAAK,EAAE;GACxB,MAAM,QAAQ,MAAM,cAAc,KAAK,MAAM;AAC7C,OAAI,OAAO,OAAO,MAAM,CACtB,OAAM,MAAM;AAEd,SAAM,MAAM,OAAO,KAAK,MAAM;;AAGhC,SAAO,KAAK;;CAGd,MAAM,UACJ,UACA,QACA,SACgC;EAChC,MAAM,WAAW,KAAK,iBAAiB,UAAU;GAAE,GAAG;GAAQ,WAAW,WAAW,EAAE;GAAE,CAAC;EAEzF,IAAI,eAAe,KAAK,YAAY,IAAI,SAAS;AACjD,MAAI,CAAC,cAAc;GACjB,MAAM,YAAY,OAAO,IAAI,MAAM,aAAa;IAC9C,MAAM,gBAAgB,OAAO;IAC7B,MAAM,cAAc,OAAO,KAAK,iBAAiB,SAAS;IAG1D,MAAM,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AEnD,MAAM,QAAQ,cAAc,KAAK,oBAAoB,SAAS,UAAU;AAGxE,QAAO,IAAI,cAFK,eAAe,KAAK,MAAM,EAER,mBAAmB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let node_module = require("node:module");
|
|
4
|
+
|
|
5
|
+
//#region src/runtime/mf-config.ts
|
|
6
|
+
const pkg = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("../../package.json");
|
|
7
|
+
const PLUGIN_VERSION = pkg.version;
|
|
8
|
+
const SHARE_CONFIG = {
|
|
9
|
+
singleton: true,
|
|
10
|
+
requiredVersion: false,
|
|
11
|
+
strictVersion: false,
|
|
12
|
+
eager: false
|
|
13
|
+
};
|
|
14
|
+
const MF_SHARED_DEPS = {
|
|
15
|
+
"every-plugin": {
|
|
16
|
+
version: PLUGIN_VERSION,
|
|
17
|
+
shareConfig: SHARE_CONFIG
|
|
18
|
+
},
|
|
19
|
+
effect: {
|
|
20
|
+
version: "^3.21.0",
|
|
21
|
+
shareConfig: SHARE_CONFIG
|
|
22
|
+
},
|
|
23
|
+
zod: {
|
|
24
|
+
version: "^4.3.6",
|
|
25
|
+
shareConfig: SHARE_CONFIG
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.MF_SHARED_DEPS = MF_SHARED_DEPS;
|
|
31
|
+
exports.PLUGIN_VERSION = PLUGIN_VERSION;
|
|
32
|
+
exports.SHARE_CONFIG = SHARE_CONFIG;
|
|
33
|
+
//# sourceMappingURL=mf-config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mf-config.cjs","names":[],"sources":["../../src/runtime/mf-config.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\nconst pkg = require(\"../../package.json\") as { version: string };\nexport const PLUGIN_VERSION = pkg.version;\n\nexport const SHARE_CONFIG = {\n singleton: true,\n requiredVersion: false,\n strictVersion: false,\n eager: false,\n} as const;\n\nexport const MF_SHARED_DEPS = {\n \"every-plugin\": {\n version: PLUGIN_VERSION,\n shareConfig: SHARE_CONFIG,\n },\n effect: {\n version: \"^3.21.0\",\n shareConfig: SHARE_CONFIG,\n },\n zod: {\n version: \"^4.3.6\",\n shareConfig: SHARE_CONFIG,\n },\n} as const;\n\nexport type SharedDepName = keyof typeof MF_SHARED_DEPS;\n"],"mappings":";;;;;AAGA,MAAM,mFADwC,CAC1B,qBAAqB;AACzC,MAAa,iBAAiB,IAAI;AAElC,MAAa,eAAe;CAC1B,WAAW;CACX,iBAAiB;CACjB,eAAe;CACf,OAAO;CACR;AAED,MAAa,iBAAiB;CAC5B,gBAAgB;EACd,SAAS;EACT,aAAa;EACd;CACD,QAAQ;EACN,SAAS;EACT,aAAa;EACd;CACD,KAAK;EACH,SAAS;EACT,aAAa;EACd;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/runtime/mf-config.d.ts
|
|
2
|
+
declare const PLUGIN_VERSION: string;
|
|
3
|
+
declare const SHARE_CONFIG: {
|
|
4
|
+
readonly singleton: true;
|
|
5
|
+
readonly requiredVersion: false;
|
|
6
|
+
readonly strictVersion: false;
|
|
7
|
+
readonly eager: false;
|
|
8
|
+
};
|
|
9
|
+
declare const MF_SHARED_DEPS: {
|
|
10
|
+
readonly "every-plugin": {
|
|
11
|
+
readonly version: string;
|
|
12
|
+
readonly shareConfig: {
|
|
13
|
+
readonly singleton: true;
|
|
14
|
+
readonly requiredVersion: false;
|
|
15
|
+
readonly strictVersion: false;
|
|
16
|
+
readonly eager: false;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly effect: {
|
|
20
|
+
readonly version: "^3.21.0";
|
|
21
|
+
readonly shareConfig: {
|
|
22
|
+
readonly singleton: true;
|
|
23
|
+
readonly requiredVersion: false;
|
|
24
|
+
readonly strictVersion: false;
|
|
25
|
+
readonly eager: false;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
readonly zod: {
|
|
29
|
+
readonly version: "^4.3.6";
|
|
30
|
+
readonly shareConfig: {
|
|
31
|
+
readonly singleton: true;
|
|
32
|
+
readonly requiredVersion: false;
|
|
33
|
+
readonly strictVersion: false;
|
|
34
|
+
readonly eager: false;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
type SharedDepName = keyof typeof MF_SHARED_DEPS;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { MF_SHARED_DEPS, PLUGIN_VERSION, SHARE_CONFIG, SharedDepName };
|
|
41
|
+
//# sourceMappingURL=mf-config.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mf-config.d.cts","names":[],"sources":["../../src/runtime/mf-config.ts"],"mappings":";cAIa,cAAA;AAAA,cAEA,YAAA;EAAA;;;;;cAOA,cAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAeD,aAAA,gBAA6B,cAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/runtime/mf-config.d.ts
|
|
2
|
+
declare const PLUGIN_VERSION: string;
|
|
3
|
+
declare const SHARE_CONFIG: {
|
|
4
|
+
readonly singleton: true;
|
|
5
|
+
readonly requiredVersion: false;
|
|
6
|
+
readonly strictVersion: false;
|
|
7
|
+
readonly eager: false;
|
|
8
|
+
};
|
|
9
|
+
declare const MF_SHARED_DEPS: {
|
|
10
|
+
readonly "every-plugin": {
|
|
11
|
+
readonly version: string;
|
|
12
|
+
readonly shareConfig: {
|
|
13
|
+
readonly singleton: true;
|
|
14
|
+
readonly requiredVersion: false;
|
|
15
|
+
readonly strictVersion: false;
|
|
16
|
+
readonly eager: false;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly effect: {
|
|
20
|
+
readonly version: "^3.21.0";
|
|
21
|
+
readonly shareConfig: {
|
|
22
|
+
readonly singleton: true;
|
|
23
|
+
readonly requiredVersion: false;
|
|
24
|
+
readonly strictVersion: false;
|
|
25
|
+
readonly eager: false;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
readonly zod: {
|
|
29
|
+
readonly version: "^4.3.6";
|
|
30
|
+
readonly shareConfig: {
|
|
31
|
+
readonly singleton: true;
|
|
32
|
+
readonly requiredVersion: false;
|
|
33
|
+
readonly strictVersion: false;
|
|
34
|
+
readonly eager: false;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
type SharedDepName = keyof typeof MF_SHARED_DEPS;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { MF_SHARED_DEPS, PLUGIN_VERSION, SHARE_CONFIG, SharedDepName };
|
|
41
|
+
//# sourceMappingURL=mf-config.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mf-config.d.mts","names":[],"sources":["../../src/runtime/mf-config.ts"],"mappings":";cAIa,cAAA;AAAA,cAEA,YAAA;EAAA;;;;;cAOA,cAAA;EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAeD,aAAA,gBAA6B,cAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/mf-config.ts
|
|
4
|
+
const pkg = createRequire(import.meta.url)("../../package.json");
|
|
5
|
+
const PLUGIN_VERSION = pkg.version;
|
|
6
|
+
const SHARE_CONFIG = {
|
|
7
|
+
singleton: true,
|
|
8
|
+
requiredVersion: false,
|
|
9
|
+
strictVersion: false,
|
|
10
|
+
eager: false
|
|
11
|
+
};
|
|
12
|
+
const MF_SHARED_DEPS = {
|
|
13
|
+
"every-plugin": {
|
|
14
|
+
version: PLUGIN_VERSION,
|
|
15
|
+
shareConfig: SHARE_CONFIG
|
|
16
|
+
},
|
|
17
|
+
effect: {
|
|
18
|
+
version: "^3.21.0",
|
|
19
|
+
shareConfig: SHARE_CONFIG
|
|
20
|
+
},
|
|
21
|
+
zod: {
|
|
22
|
+
version: "^4.3.6",
|
|
23
|
+
shareConfig: SHARE_CONFIG
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { MF_SHARED_DEPS, PLUGIN_VERSION, SHARE_CONFIG };
|
|
29
|
+
//# sourceMappingURL=mf-config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mf-config.mjs","names":[],"sources":["../../src/runtime/mf-config.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\nconst pkg = require(\"../../package.json\") as { version: string };\nexport const PLUGIN_VERSION = pkg.version;\n\nexport const SHARE_CONFIG = {\n singleton: true,\n requiredVersion: false,\n strictVersion: false,\n eager: false,\n} as const;\n\nexport const MF_SHARED_DEPS = {\n \"every-plugin\": {\n version: PLUGIN_VERSION,\n shareConfig: SHARE_CONFIG,\n },\n effect: {\n version: \"^3.21.0\",\n shareConfig: SHARE_CONFIG,\n },\n zod: {\n version: \"^4.3.6\",\n shareConfig: SHARE_CONFIG,\n },\n} as const;\n\nexport type SharedDepName = keyof typeof MF_SHARED_DEPS;\n"],"mappings":";;;AAGA,MAAM,MADU,cAAc,OAAO,KAAK,IAAI,CAC1B,qBAAqB;AACzC,MAAa,iBAAiB,IAAI;AAElC,MAAa,eAAe;CAC1B,WAAW;CACX,iBAAiB;CACjB,eAAe;CACf,OAAO;CACR;AAED,MAAa,iBAAiB;CAC5B,gBAAgB;EACd,SAAS;EACT,aAAa;EACd;CACD,QAAQ;EACN,SAAS;EACT,aAAa;EACd;CACD,KAAK;EACH,SAAS;EACT,aAAa;EACd;CACF"}
|