every-plugin 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/rolldown_runtime.cjs +0 -4
- package/dist/_virtual/rolldown_runtime.mjs +1 -10
- package/dist/build/rspack/dev-server-middleware.cjs +1 -1
- package/dist/build/rspack/dev-server-middleware.cjs.map +1 -1
- package/dist/build/rspack/dev-server-middleware.mjs +1 -1
- package/dist/build/rspack/dev-server-middleware.mjs.map +1 -1
- package/dist/build/rspack/module-federation.cjs +11 -12
- package/dist/build/rspack/module-federation.cjs.map +1 -1
- package/dist/build/rspack/module-federation.mjs +11 -12
- package/dist/build/rspack/module-federation.mjs.map +1 -1
- package/dist/errors.cjs +41 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +29 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.mts +29 -1
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +41 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/package.cjs +20 -161
- package/dist/package.cjs.map +1 -1
- package/dist/package.mjs +13 -163
- package/dist/package.mjs.map +1 -1
- package/dist/runtime/errors.cjs +54 -2
- package/dist/runtime/errors.cjs.map +1 -1
- package/dist/runtime/errors.mjs +54 -2
- package/dist/runtime/errors.mjs.map +1 -1
- package/dist/runtime/services/module-federation.service.cjs +7 -8
- package/dist/runtime/services/module-federation.service.cjs.map +1 -1
- package/dist/runtime/services/module-federation.service.mjs +7 -9
- package/dist/runtime/services/module-federation.service.mjs.map +1 -1
- package/dist/runtime/services/plugin-loader.service.cjs +11 -4
- package/dist/runtime/services/plugin-loader.service.cjs.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.cts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.d.mts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.mjs +11 -4
- package/dist/runtime/services/plugin-loader.service.mjs.map +1 -1
- package/package.json +1 -1
package/dist/runtime/errors.mjs
CHANGED
|
@@ -5,6 +5,56 @@ import { ORPCError } from "@orpc/contract";
|
|
|
5
5
|
var PluginRuntimeError = class extends Data.TaggedError("PluginRuntimeError") {};
|
|
6
6
|
var ModuleFederationError = class extends Data.TaggedError("ModuleFederationError") {};
|
|
7
7
|
var ValidationError = class extends Data.TaggedError("ValidationError") {};
|
|
8
|
+
const extractErrorMessage = (error) => {
|
|
9
|
+
if (!error) return "Unknown error";
|
|
10
|
+
if (error instanceof Error) {
|
|
11
|
+
if (error.message) return error.message;
|
|
12
|
+
if (error.cause instanceof Error) return extractErrorMessage(error.cause);
|
|
13
|
+
}
|
|
14
|
+
if (error instanceof AggregateError && error.errors?.length) return error.errors.map((e) => extractErrorMessage(e)).join("; ");
|
|
15
|
+
if (typeof error === "object" && "message" in error) return String(error.message);
|
|
16
|
+
return String(error);
|
|
17
|
+
};
|
|
18
|
+
const formatPluginError = (pluginId, operation, message) => {
|
|
19
|
+
const lines = [];
|
|
20
|
+
lines.push(`\n╭─ Plugin Error ${"─".repeat(40)}`);
|
|
21
|
+
if (pluginId) lines.push(`│ Plugin: ${pluginId}`);
|
|
22
|
+
if (operation) lines.push(`│ During: ${operation}`);
|
|
23
|
+
lines.push(`│`);
|
|
24
|
+
if (message.includes("ECONNREFUSED")) {
|
|
25
|
+
lines.push(`│ ❌ Connection refused`);
|
|
26
|
+
lines.push(`│ `);
|
|
27
|
+
lines.push(`│ A required service is not running.`);
|
|
28
|
+
lines.push(`│ → Run: docker compose up -d`);
|
|
29
|
+
} else if (message.includes("ENOTFOUND")) {
|
|
30
|
+
lines.push(`│ ❌ Host not found`);
|
|
31
|
+
lines.push(`│ `);
|
|
32
|
+
lines.push(`│ Check your connection URL or network settings.`);
|
|
33
|
+
} else if (message.includes("ETIMEDOUT") || message.includes("timeout")) {
|
|
34
|
+
lines.push(`│ ❌ Connection timeout`);
|
|
35
|
+
lines.push(`│ `);
|
|
36
|
+
lines.push(`│ The service took too long to respond.`);
|
|
37
|
+
} else if (message.includes("EACCES") || message.includes("permission")) {
|
|
38
|
+
lines.push(`│ ❌ Permission denied`);
|
|
39
|
+
lines.push(`│ `);
|
|
40
|
+
lines.push(`│ Check credentials or access permissions.`);
|
|
41
|
+
} else if (message.includes("401") || message.includes("unauthorized")) {
|
|
42
|
+
lines.push(`│ ❌ Authentication failed`);
|
|
43
|
+
lines.push(`│ `);
|
|
44
|
+
lines.push(`│ Check your API key or credentials.`);
|
|
45
|
+
} else lines.push(`│ ❌ ${message}`);
|
|
46
|
+
lines.push(`╰${"─".repeat(50)}\n`);
|
|
47
|
+
console.error(lines.join("\n"));
|
|
48
|
+
};
|
|
49
|
+
const isRetryableError = (message) => {
|
|
50
|
+
return [
|
|
51
|
+
"ETIMEDOUT",
|
|
52
|
+
"ECONNRESET",
|
|
53
|
+
"timeout",
|
|
54
|
+
"503",
|
|
55
|
+
"429"
|
|
56
|
+
].some((p) => message.toLowerCase().includes(p.toLowerCase()));
|
|
57
|
+
};
|
|
8
58
|
const isRetryableORPCCode = (code) => {
|
|
9
59
|
switch (code) {
|
|
10
60
|
case "TOO_MANY_REQUESTS":
|
|
@@ -27,12 +77,14 @@ const wrapORPCError = (orpcError, pluginId, procedureName, operation) => {
|
|
|
27
77
|
const toPluginRuntimeError = (error, pluginId, procedureName, operation, defaultRetryable = false) => {
|
|
28
78
|
if (error instanceof ORPCError) return wrapORPCError(error, pluginId, procedureName, operation);
|
|
29
79
|
if (error instanceof PluginRuntimeError) return error;
|
|
80
|
+
const message = extractErrorMessage(error);
|
|
81
|
+
formatPluginError(pluginId, operation, message);
|
|
30
82
|
return new PluginRuntimeError({
|
|
31
83
|
pluginId,
|
|
32
84
|
operation,
|
|
33
85
|
procedureName,
|
|
34
|
-
retryable: defaultRetryable,
|
|
35
|
-
cause: error instanceof Error ? error : new Error(
|
|
86
|
+
retryable: defaultRetryable || isRetryableError(message),
|
|
87
|
+
cause: error instanceof Error ? error : new Error(message)
|
|
36
88
|
});
|
|
37
89
|
};
|
|
38
90
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { 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\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\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// 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
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":["lines: string[]"],"sources":["../../src/runtime/errors.ts"],"sourcesContent":["import { ORPCError } from \"@orpc/contract\";\nimport { 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 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\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// 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 message = extractErrorMessage(error);\n\n\tformatPluginError(pluginId, operation, message);\n\n\treturn new PluginRuntimeError({\n\t\tpluginId,\n\t\toperation,\n\t\tprocedureName,\n\t\tretryable: defaultRetryable || isRetryableError(message),\n\t\tcause: error instanceof Error ? error : new Error(message)\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;AAChC,MAAK,MAAc,iBAAiB,MACnC,QAAO,oBAAqB,MAAc,MAAM;;AAIlD,KAAI,iBAAiB,kBAAkB,MAAM,QAAQ,OACpD,QAAO,MAAM,OAAO,KAAI,MAAK,oBAAoB,EAAE,CAAC,CAAC,KAAK,KAAK;AAGhE,KAAI,OAAO,UAAU,YAAY,aAAa,MAC7C,QAAO,OAAQ,MAAc,QAAQ;AAGtC,QAAO,OAAO,MAAM;;AAGrB,MAAM,qBACL,UACA,WACA,YACU;CACV,MAAMA,QAAkB,EAAE;AAE1B,OAAM,KAAK,qBAAqB,IAAI,OA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xB,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,UAAU,KAAK;EAC9C,OAAO;EACP,CAAC;;AAIH,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,UAAU,oBAAoB,MAAM;AAE1C,mBAAkB,UAAU,WAAW,QAAQ;AAE/C,QAAO,IAAI,mBAAmB;EAC7B;EACA;EACA;EACA,WAAW,oBAAoB,iBAAiB,QAAQ;EACxD,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,QAAQ;EAC1D,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_errors = require('../errors.cjs');
|
|
3
3
|
const require_runtime_services_normalize = require('./normalize.cjs');
|
|
4
|
-
const require_package
|
|
4
|
+
const require_package = require('../../package.cjs');
|
|
5
5
|
let effect = require("effect");
|
|
6
6
|
let __module_federation_enhanced_runtime = require("@module-federation/enhanced/runtime");
|
|
7
7
|
let __module_federation_runtime_core = require("@module-federation/runtime-core");
|
|
8
8
|
|
|
9
9
|
//#region src/runtime/services/module-federation.service.ts
|
|
10
|
-
var import_package = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_package$1.default, 1);
|
|
11
10
|
const createModuleFederationInstance = effect.Effect.cached(effect.Effect.sync(() => {
|
|
12
11
|
try {
|
|
13
12
|
let instance = (0, __module_federation_enhanced_runtime.getInstance)();
|
|
@@ -17,16 +16,16 @@ const createModuleFederationInstance = effect.Effect.cached(effect.Effect.sync((
|
|
|
17
16
|
remotes: [],
|
|
18
17
|
shared: {
|
|
19
18
|
"every-plugin": {
|
|
20
|
-
version:
|
|
19
|
+
version: require_package.version,
|
|
21
20
|
shareConfig: {
|
|
22
21
|
singleton: true,
|
|
23
|
-
requiredVersion: `^${
|
|
22
|
+
requiredVersion: `^${require_package.version}`,
|
|
24
23
|
eager: true,
|
|
25
24
|
strictVersion: false
|
|
26
25
|
}
|
|
27
26
|
},
|
|
28
27
|
effect: {
|
|
29
|
-
version:
|
|
28
|
+
version: require_package.dependencies.effect,
|
|
30
29
|
shareConfig: {
|
|
31
30
|
singleton: true,
|
|
32
31
|
requiredVersion: "^3.18.0",
|
|
@@ -35,7 +34,7 @@ const createModuleFederationInstance = effect.Effect.cached(effect.Effect.sync((
|
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
zod: {
|
|
38
|
-
version:
|
|
37
|
+
version: require_package.dependencies.zod,
|
|
39
38
|
shareConfig: {
|
|
40
39
|
singleton: true,
|
|
41
40
|
requiredVersion: "^4.1.0",
|
|
@@ -44,7 +43,7 @@ const createModuleFederationInstance = effect.Effect.cached(effect.Effect.sync((
|
|
|
44
43
|
}
|
|
45
44
|
},
|
|
46
45
|
"@orpc/contract": {
|
|
47
|
-
version:
|
|
46
|
+
version: require_package.dependencies["@orpc/contract"],
|
|
48
47
|
shareConfig: {
|
|
49
48
|
singleton: true,
|
|
50
49
|
requiredVersion: "^1.8.0",
|
|
@@ -53,7 +52,7 @@ const createModuleFederationInstance = effect.Effect.cached(effect.Effect.sync((
|
|
|
53
52
|
}
|
|
54
53
|
},
|
|
55
54
|
"@orpc/server": {
|
|
56
|
-
version:
|
|
55
|
+
version: require_package.dependencies["@orpc/server"],
|
|
57
56
|
shareConfig: {
|
|
58
57
|
singleton: true,
|
|
59
58
|
requiredVersion: "^1.8.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.cjs","names":["Effect","pkg","entryUrl: string","getNormalizedRemoteName","ModuleFederationError"],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import {\n\tcreateInstance,\n\tgetInstance,\n} from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule = \n | (new () => AnyPlugin)\n | { default: new () => AnyPlugin };\n\nimport pkg from \"../../../package.json\";\n\nconst createModuleFederationInstance = Effect.cached(\n\tEffect.sync(() => {\n\t\ttry {\n\t\t\tlet instance = getInstance();\n\n\t\t\tif (!instance) {\n\t\t\t\tinstance = createInstance({\n\t\t\t\t\tname: \"host\",\n\t\t\t\t\tremotes: [],\n\t\t\t\t\tshared: {\n\t\t\t\t\t\t\"every-plugin\": {\n\t\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: `^${pkg.version}`,\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow bidirectional version compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\teffect: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.effect,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^3.18.0\", // Allow any 3.18.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tzod: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.zod,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^4.1.0\", // Allow any 4.1.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/contract\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/contract\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/server\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/server\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tsetGlobalFederationInstance(instance);\n\t\t\t}\n\n\t\t\treturn instance;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to initialize Module Federation: ${error}`);\n\t\t}\n\t}),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\"ModuleFederationService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst mf = yield* Effect.flatten(createModuleFederationInstance);\n\n\t\treturn {\n\t\t\tregisterRemote: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconsole.log(`[MF] Registering ${pluginId}`);\n\n\t\t\t\t\tconst manifestUrl = url.endsWith('/')\n\t\t\t\t\t\t? `${url}mf-manifest.json`\n\t\t\t\t\t\t: `${url}/mf-manifest.json`;\n\n\t\t\t\t\t// Check if manifest is available (MF 2.0 with manifests)\n\t\t\t\t\tconst manifestCheck = yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\t\t\t\t\t\t\tconst response = await fetch(manifestUrl, { method: \"HEAD\" });\n\t\t\t\t\t\t\treturn response.ok;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: () => false,\n\t\t\t\t\t});\n\n\t\t\t\t\tlet entryUrl: string;\n\t\t\t\t\tlet isManifestMode = false;\n\n\t\t\t\t\tif (manifestCheck) {\n\t\t\t\t\t\t// MF 2.0 manifest mode - use manifest URL\n\t\t\t\t\t\tentryUrl = manifestUrl;\n\t\t\t\t\t\tisManifestMode = true;\n\t\t\t\t\t\tconsole.log(`[MF] Using MF 2.0 manifest mode for ${pluginId}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Fallback to MF 1.5 direct mode - assume URL points to remoteEntry.js\n\t\t\t\t\t\tconsole.log(`[MF] ⚠️ Manifest not found, falling back to MF 1.5 mode for ${pluginId}`);\n\t\t\t\t\t\tentryUrl = url;\n\t\t\t\t\t\tisManifestMode = false;\n\t\t\t\t\t}\n\n\t\t\t\t\t// For MF 2.0, the name can be the pluginId (alias)\n\t\t\t\t\t// The manifest will contain the actual container name\n\t\t\t\t\tconst remoteName = isManifestMode ? pluginId : getNormalizedRemoteName(pluginId);\n\n\t\t\t\t\tyield* Effect.try({\n\t\t\t\t\t\ttry: () => mf.registerRemotes([{\n\t\t\t\t\t\t\tname: remoteName,\n\t\t\t\t\t\t\tentry: entryUrl,\n\t\t\t\t\t\t\t...(isManifestMode && { alias: pluginId }) // Explicit alias for clarity\n\t\t\t\t\t\t}]),\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\tconsole.log(`[MF] ✅ Registered ${pluginId} (${isManifestMode ? 'MF 2.0' : 'MF 1.5'})`);\n\t\t\t\t}),\n\n\t\t\tloadRemoteConstructor: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\t\t\t\t\tconsole.log(`[MF] Loading remote ${remoteName}`);\n\t\t\t\t\tconst modulePath = `${remoteName}/plugin`;\n\n\t\t\t\t\treturn yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\n\t\t\t\t\t\t\tconst container = await mf.loadRemote<RemoteModule>(modulePath);\n\t\t\t\t\t\t\tif (!container) {\n\t\t\t\t\t\t\t\tthrow new Error(`No container returned for ${modulePath}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Support multiple export patterns: direct function, default export, named exports\n\t\t\t\t\t\t\tconst Constructor =\n\t\t\t\t\t\t\t\ttypeof container === \"function\"\n\t\t\t\t\t\t\t\t\t? container // Direct function export\n\t\t\t\t\t\t\t\t\t: container.default\n\t\t\t\t\t\t\t\t\t? container.default // Default export\n\t\t\t\t\t\t\t\t\t: Object.values(container).find( // Named export fallback\n\t\t\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp\n\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (!Constructor || typeof Constructor !== \"function\") {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Available exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`No valid plugin constructor found for '${pluginId}'.\\n` +\n\t\t\t\t\t\t\t\t\t`Supported patterns:\\n` +\n\t\t\t\t\t\t\t\t\t` - export const YourPlugin = createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t` - export default createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Validate it looks like a plugin constructor (has binding property)\n\t\t\t\t\t\t\tif (!(Constructor as any).binding) {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Found exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Invalid plugin constructor for '${pluginId}'. ` +\n\t\t\t\t\t\t\t\t\t`The exported value must be created with createPlugin(). ` +\n\t\t\t\t\t\t\t\t\t`Found a function but it's missing the required 'binding' property.\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n\t\t\t\t\t\t\treturn Constructor;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {}\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,iCAAiCA,cAAO,OAC7CA,cAAO,WAAW;AACjB,KAAI;EACH,IAAI,kEAAwB;AAE5B,MAAI,CAAC,UAAU;AACd,uEAA0B;IACzB,MAAM;IACN,SAAS,EAAE;IACX,QAAQ;KACP,gBAAgB;MACf,SAASC,uBAAI;MACb,aAAa;OACZ,WAAW;OACX,iBAAiB,IAAIA,uBAAI;OACzB,OAAO;OACP,eAAe;OACf;MACD;KACD,QAAQ;MACP,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KACzB;KACA,WAAW;KACX,OACC,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;KAC1D,CAAC;IACH,CAAC;IACD;EACH;EACA,EACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"module-federation.service.cjs","names":["Effect","entryUrl: string","getNormalizedRemoteName","ModuleFederationError"],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import {\n\tcreateInstance,\n\tgetInstance,\n} from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule = \n | (new () => AnyPlugin)\n | { default: new () => AnyPlugin };\n\nimport pkg from \"../../../package.json\";\n\nconst createModuleFederationInstance = Effect.cached(\n\tEffect.sync(() => {\n\t\ttry {\n\t\t\tlet instance = getInstance();\n\n\t\t\tif (!instance) {\n\t\t\t\tinstance = createInstance({\n\t\t\t\t\tname: \"host\",\n\t\t\t\t\tremotes: [],\n\t\t\t\t\tshared: {\n\t\t\t\t\t\t\"every-plugin\": {\n\t\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: `^${pkg.version}`,\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow bidirectional version compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\teffect: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.effect,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^3.18.0\", // Allow any 3.18.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tzod: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.zod,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^4.1.0\", // Allow any 4.1.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/contract\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/contract\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/server\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/server\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tsetGlobalFederationInstance(instance);\n\t\t\t}\n\n\t\t\treturn instance;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to initialize Module Federation: ${error}`);\n\t\t}\n\t}),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\"ModuleFederationService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst mf = yield* Effect.flatten(createModuleFederationInstance);\n\n\t\treturn {\n\t\t\tregisterRemote: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconsole.log(`[MF] Registering ${pluginId}`);\n\n\t\t\t\t\tconst manifestUrl = url.endsWith('/')\n\t\t\t\t\t\t? `${url}mf-manifest.json`\n\t\t\t\t\t\t: `${url}/mf-manifest.json`;\n\n\t\t\t\t\t// Check if manifest is available (MF 2.0 with manifests)\n\t\t\t\t\tconst manifestCheck = yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\t\t\t\t\t\t\tconst response = await fetch(manifestUrl, { method: \"HEAD\" });\n\t\t\t\t\t\t\treturn response.ok;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: () => false,\n\t\t\t\t\t});\n\n\t\t\t\t\tlet entryUrl: string;\n\t\t\t\t\tlet isManifestMode = false;\n\n\t\t\t\t\tif (manifestCheck) {\n\t\t\t\t\t\t// MF 2.0 manifest mode - use manifest URL\n\t\t\t\t\t\tentryUrl = manifestUrl;\n\t\t\t\t\t\tisManifestMode = true;\n\t\t\t\t\t\tconsole.log(`[MF] Using MF 2.0 manifest mode for ${pluginId}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Fallback to MF 1.5 direct mode - assume URL points to remoteEntry.js\n\t\t\t\t\t\tconsole.log(`[MF] ⚠️ Manifest not found, falling back to MF 1.5 mode for ${pluginId}`);\n\t\t\t\t\t\tentryUrl = url;\n\t\t\t\t\t\tisManifestMode = false;\n\t\t\t\t\t}\n\n\t\t\t\t\t// For MF 2.0, the name can be the pluginId (alias)\n\t\t\t\t\t// The manifest will contain the actual container name\n\t\t\t\t\tconst remoteName = isManifestMode ? pluginId : getNormalizedRemoteName(pluginId);\n\n\t\t\t\t\tyield* Effect.try({\n\t\t\t\t\t\ttry: () => mf.registerRemotes([{\n\t\t\t\t\t\t\tname: remoteName,\n\t\t\t\t\t\t\tentry: entryUrl,\n\t\t\t\t\t\t\t...(isManifestMode && { alias: pluginId }) // Explicit alias for clarity\n\t\t\t\t\t\t}]),\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\tconsole.log(`[MF] ✅ Registered ${pluginId} (${isManifestMode ? 'MF 2.0' : 'MF 1.5'})`);\n\t\t\t\t}),\n\n\t\t\tloadRemoteConstructor: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\t\t\t\t\tconsole.log(`[MF] Loading remote ${remoteName}`);\n\t\t\t\t\tconst modulePath = `${remoteName}/plugin`;\n\n\t\t\t\t\treturn yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\n\t\t\t\t\t\t\tconst container = await mf.loadRemote<RemoteModule>(modulePath);\n\t\t\t\t\t\t\tif (!container) {\n\t\t\t\t\t\t\t\tthrow new Error(`No container returned for ${modulePath}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Support multiple export patterns: direct function, default export, named exports\n\t\t\t\t\t\t\tconst Constructor =\n\t\t\t\t\t\t\t\ttypeof container === \"function\"\n\t\t\t\t\t\t\t\t\t? container // Direct function export\n\t\t\t\t\t\t\t\t\t: container.default\n\t\t\t\t\t\t\t\t\t? container.default // Default export\n\t\t\t\t\t\t\t\t\t: Object.values(container).find( // Named export fallback\n\t\t\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp\n\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (!Constructor || typeof Constructor !== \"function\") {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Available exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`No valid plugin constructor found for '${pluginId}'.\\n` +\n\t\t\t\t\t\t\t\t\t`Supported patterns:\\n` +\n\t\t\t\t\t\t\t\t\t` - export const YourPlugin = createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t` - export default createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Validate it looks like a plugin constructor (has binding property)\n\t\t\t\t\t\t\tif (!(Constructor as any).binding) {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Found exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Invalid plugin constructor for '${pluginId}'. ` +\n\t\t\t\t\t\t\t\t\t`The exported value must be created with createPlugin(). ` +\n\t\t\t\t\t\t\t\t\t`Found a function but it's missing the required 'binding' property.\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n\t\t\t\t\t\t\treturn Constructor;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\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HAIhD,gBACH;;AAIF,SAAI,CAAE,YAAoB,SAAS;MAClC,MAAM,gBAAgB,OAAO,cAAc,WACxC,kBAAkB,OAAO,KAAK,UAAU,CAAC,KAAK,KAAK,KACnD,mBAAmB,OAAO;AAE7B,YAAM,IAAI,MACT,mCAAmC,SAAS,iIAGzC,gBACH;;AAGF,aAAQ,IAAI,iCAAiC,WAAW;AACxD,YAAO;;IAER,QAAQ,UACP,IAAIG,qCAAsB;KACzB;KACA,WAAW;KACX,OACC,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;KAC1D,CAAC;IACH,CAAC;IACD;EACH;EACA,EACF,CAAC,CAAC"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { __toESM } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
1
|
import { ModuleFederationError } from "../errors.mjs";
|
|
3
2
|
import { getNormalizedRemoteName } from "./normalize.mjs";
|
|
4
|
-
import {
|
|
3
|
+
import { dependencies, version } from "../../package.mjs";
|
|
5
4
|
import { Effect } from "effect";
|
|
6
5
|
import { createInstance, getInstance } from "@module-federation/enhanced/runtime";
|
|
7
6
|
import { setGlobalFederationInstance } from "@module-federation/runtime-core";
|
|
8
7
|
|
|
9
8
|
//#region src/runtime/services/module-federation.service.ts
|
|
10
|
-
var import_package = /* @__PURE__ */ __toESM(require_package(), 1);
|
|
11
9
|
const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
12
10
|
try {
|
|
13
11
|
let instance = getInstance();
|
|
@@ -17,16 +15,16 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
17
15
|
remotes: [],
|
|
18
16
|
shared: {
|
|
19
17
|
"every-plugin": {
|
|
20
|
-
version
|
|
18
|
+
version,
|
|
21
19
|
shareConfig: {
|
|
22
20
|
singleton: true,
|
|
23
|
-
requiredVersion: `^${
|
|
21
|
+
requiredVersion: `^${version}`,
|
|
24
22
|
eager: true,
|
|
25
23
|
strictVersion: false
|
|
26
24
|
}
|
|
27
25
|
},
|
|
28
26
|
effect: {
|
|
29
|
-
version:
|
|
27
|
+
version: dependencies.effect,
|
|
30
28
|
shareConfig: {
|
|
31
29
|
singleton: true,
|
|
32
30
|
requiredVersion: "^3.18.0",
|
|
@@ -35,7 +33,7 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
35
33
|
}
|
|
36
34
|
},
|
|
37
35
|
zod: {
|
|
38
|
-
version:
|
|
36
|
+
version: dependencies.zod,
|
|
39
37
|
shareConfig: {
|
|
40
38
|
singleton: true,
|
|
41
39
|
requiredVersion: "^4.1.0",
|
|
@@ -44,7 +42,7 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
44
42
|
}
|
|
45
43
|
},
|
|
46
44
|
"@orpc/contract": {
|
|
47
|
-
version:
|
|
45
|
+
version: dependencies["@orpc/contract"],
|
|
48
46
|
shareConfig: {
|
|
49
47
|
singleton: true,
|
|
50
48
|
requiredVersion: "^1.8.0",
|
|
@@ -53,7 +51,7 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
53
51
|
}
|
|
54
52
|
},
|
|
55
53
|
"@orpc/server": {
|
|
56
|
-
version:
|
|
54
|
+
version: dependencies["@orpc/server"],
|
|
57
55
|
shareConfig: {
|
|
58
56
|
singleton: true,
|
|
59
57
|
requiredVersion: "^1.8.0",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.mjs","names":["pkg","entryUrl: string"],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import {\n\tcreateInstance,\n\tgetInstance,\n} from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule = \n | (new () => AnyPlugin)\n | { default: new () => AnyPlugin };\n\nimport pkg from \"../../../package.json\";\n\nconst createModuleFederationInstance = Effect.cached(\n\tEffect.sync(() => {\n\t\ttry {\n\t\t\tlet instance = getInstance();\n\n\t\t\tif (!instance) {\n\t\t\t\tinstance = createInstance({\n\t\t\t\t\tname: \"host\",\n\t\t\t\t\tremotes: [],\n\t\t\t\t\tshared: {\n\t\t\t\t\t\t\"every-plugin\": {\n\t\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: `^${pkg.version}`,\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow bidirectional version compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\teffect: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.effect,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^3.18.0\", // Allow any 3.18.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tzod: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.zod,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^4.1.0\", // Allow any 4.1.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/contract\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/contract\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/server\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/server\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tsetGlobalFederationInstance(instance);\n\t\t\t}\n\n\t\t\treturn instance;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to initialize Module Federation: ${error}`);\n\t\t}\n\t}),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\"ModuleFederationService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst mf = yield* Effect.flatten(createModuleFederationInstance);\n\n\t\treturn {\n\t\t\tregisterRemote: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconsole.log(`[MF] Registering ${pluginId}`);\n\n\t\t\t\t\tconst manifestUrl = url.endsWith('/')\n\t\t\t\t\t\t? `${url}mf-manifest.json`\n\t\t\t\t\t\t: `${url}/mf-manifest.json`;\n\n\t\t\t\t\t// Check if manifest is available (MF 2.0 with manifests)\n\t\t\t\t\tconst manifestCheck = yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\t\t\t\t\t\t\tconst response = await fetch(manifestUrl, { method: \"HEAD\" });\n\t\t\t\t\t\t\treturn response.ok;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: () => false,\n\t\t\t\t\t});\n\n\t\t\t\t\tlet entryUrl: string;\n\t\t\t\t\tlet isManifestMode = false;\n\n\t\t\t\t\tif (manifestCheck) {\n\t\t\t\t\t\t// MF 2.0 manifest mode - use manifest URL\n\t\t\t\t\t\tentryUrl = manifestUrl;\n\t\t\t\t\t\tisManifestMode = true;\n\t\t\t\t\t\tconsole.log(`[MF] Using MF 2.0 manifest mode for ${pluginId}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Fallback to MF 1.5 direct mode - assume URL points to remoteEntry.js\n\t\t\t\t\t\tconsole.log(`[MF] ⚠️ Manifest not found, falling back to MF 1.5 mode for ${pluginId}`);\n\t\t\t\t\t\tentryUrl = url;\n\t\t\t\t\t\tisManifestMode = false;\n\t\t\t\t\t}\n\n\t\t\t\t\t// For MF 2.0, the name can be the pluginId (alias)\n\t\t\t\t\t// The manifest will contain the actual container name\n\t\t\t\t\tconst remoteName = isManifestMode ? pluginId : getNormalizedRemoteName(pluginId);\n\n\t\t\t\t\tyield* Effect.try({\n\t\t\t\t\t\ttry: () => mf.registerRemotes([{\n\t\t\t\t\t\t\tname: remoteName,\n\t\t\t\t\t\t\tentry: entryUrl,\n\t\t\t\t\t\t\t...(isManifestMode && { alias: pluginId }) // Explicit alias for clarity\n\t\t\t\t\t\t}]),\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\tconsole.log(`[MF] ✅ Registered ${pluginId} (${isManifestMode ? 'MF 2.0' : 'MF 1.5'})`);\n\t\t\t\t}),\n\n\t\t\tloadRemoteConstructor: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\t\t\t\t\tconsole.log(`[MF] Loading remote ${remoteName}`);\n\t\t\t\t\tconst modulePath = `${remoteName}/plugin`;\n\n\t\t\t\t\treturn yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\n\t\t\t\t\t\t\tconst container = await mf.loadRemote<RemoteModule>(modulePath);\n\t\t\t\t\t\t\tif (!container) {\n\t\t\t\t\t\t\t\tthrow new Error(`No container returned for ${modulePath}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Support multiple export patterns: direct function, default export, named exports\n\t\t\t\t\t\t\tconst Constructor =\n\t\t\t\t\t\t\t\ttypeof container === \"function\"\n\t\t\t\t\t\t\t\t\t? container // Direct function export\n\t\t\t\t\t\t\t\t\t: container.default\n\t\t\t\t\t\t\t\t\t? container.default // Default export\n\t\t\t\t\t\t\t\t\t: Object.values(container).find( // Named export fallback\n\t\t\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp\n\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (!Constructor || typeof Constructor !== \"function\") {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Available exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`No valid plugin constructor found for '${pluginId}'.\\n` +\n\t\t\t\t\t\t\t\t\t`Supported patterns:\\n` +\n\t\t\t\t\t\t\t\t\t` - export const YourPlugin = createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t` - export default createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Validate it looks like a plugin constructor (has binding property)\n\t\t\t\t\t\t\tif (!(Constructor as any).binding) {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Found exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Invalid plugin constructor for '${pluginId}'. ` +\n\t\t\t\t\t\t\t\t\t`The exported value must be created with createPlugin(). ` +\n\t\t\t\t\t\t\t\t\t`Found a function but it's missing the required 'binding' property.\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n\t\t\t\t\t\t\treturn Constructor;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {}\n"],"mappings":";;;;;;;;;;AAgBA,MAAM,iCAAiC,OAAO,OAC7C,OAAO,WAAW;AACjB,KAAI;EACH,IAAI,WAAW,aAAa;AAE5B,MAAI,CAAC,UAAU;AACd,cAAW,eAAe;IACzB,MAAM;IACN,SAAS,EAAE;IACX,QAAQ;KACP,gBAAgB;MACf,SAASA,uBAAI;MACb,aAAa;OACZ,WAAW;OACX,iBAAiB,IAAIA,uBAAI;OACzB,OAAO;OACP,eAAe;OACf;MACD;KACD,QAAQ;MACP,SAASA,uBAAI,aAAa;MAC1B,aAAa;OACZ,WAAW;OACX,iBAAiB;OACjB,OAAO;OACP,eAAe;OACf;MACD;KACD,KAAK;MACJ,SAASA,uBAAI,aAAa;MAC1B,aAAa;OACZ,WAAW;OACX,iBA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s","names":["pkg.version","entryUrl: string"],"sources":["../../../src/runtime/services/module-federation.service.ts"],"sourcesContent":["import {\n\tcreateInstance,\n\tgetInstance,\n} from \"@module-federation/enhanced/runtime\";\nimport { setGlobalFederationInstance } from \"@module-federation/runtime-core\";\nimport { Effect } from \"effect\";\nimport type { AnyPlugin } from \"../../types\";\nimport { ModuleFederationError } from \"../errors\";\nimport { getNormalizedRemoteName } from \"./normalize\";\n\ntype RemoteModule = \n | (new () => AnyPlugin)\n | { default: new () => AnyPlugin };\n\nimport pkg from \"../../../package.json\";\n\nconst createModuleFederationInstance = Effect.cached(\n\tEffect.sync(() => {\n\t\ttry {\n\t\t\tlet instance = getInstance();\n\n\t\t\tif (!instance) {\n\t\t\t\tinstance = createInstance({\n\t\t\t\t\tname: \"host\",\n\t\t\t\t\tremotes: [],\n\t\t\t\t\tshared: {\n\t\t\t\t\t\t\"every-plugin\": {\n\t\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: `^${pkg.version}`,\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow bidirectional version compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\teffect: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.effect,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^3.18.0\", // Allow any 3.18.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tzod: {\n\t\t\t\t\t\t\tversion: pkg.dependencies.zod,\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^4.1.0\", // Allow any 4.1.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/contract\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/contract\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"@orpc/server\": {\n\t\t\t\t\t\t\tversion: pkg.dependencies[\"@orpc/server\"],\n\t\t\t\t\t\t\tshareConfig: {\n\t\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\t\trequiredVersion: \"^1.8.0\", // Allow any 1.8.x patch version\n\t\t\t\t\t\t\t\teager: true,\n\t\t\t\t\t\t\t\tstrictVersion: false, // Allow version flexibility for compatibility\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tsetGlobalFederationInstance(instance);\n\t\t\t}\n\n\t\t\treturn instance;\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to initialize Module Federation: ${error}`);\n\t\t}\n\t}),\n);\n\nexport class ModuleFederationService extends Effect.Service<ModuleFederationService>()(\"ModuleFederationService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst mf = yield* Effect.flatten(createModuleFederationInstance);\n\n\t\treturn {\n\t\t\tregisterRemote: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconsole.log(`[MF] Registering ${pluginId}`);\n\n\t\t\t\t\tconst manifestUrl = url.endsWith('/')\n\t\t\t\t\t\t? `${url}mf-manifest.json`\n\t\t\t\t\t\t: `${url}/mf-manifest.json`;\n\n\t\t\t\t\t// Check if manifest is available (MF 2.0 with manifests)\n\t\t\t\t\tconst manifestCheck = yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\t\t\t\t\t\t\tconst response = await fetch(manifestUrl, { method: \"HEAD\" });\n\t\t\t\t\t\t\treturn response.ok;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: () => false,\n\t\t\t\t\t});\n\n\t\t\t\t\tlet entryUrl: string;\n\t\t\t\t\tlet isManifestMode = false;\n\n\t\t\t\t\tif (manifestCheck) {\n\t\t\t\t\t\t// MF 2.0 manifest mode - use manifest URL\n\t\t\t\t\t\tentryUrl = manifestUrl;\n\t\t\t\t\t\tisManifestMode = true;\n\t\t\t\t\t\tconsole.log(`[MF] Using MF 2.0 manifest mode for ${pluginId}`);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Fallback to MF 1.5 direct mode - assume URL points to remoteEntry.js\n\t\t\t\t\t\tconsole.log(`[MF] ⚠️ Manifest not found, falling back to MF 1.5 mode for ${pluginId}`);\n\t\t\t\t\t\tentryUrl = url;\n\t\t\t\t\t\tisManifestMode = false;\n\t\t\t\t\t}\n\n\t\t\t\t\t// For MF 2.0, the name can be the pluginId (alias)\n\t\t\t\t\t// The manifest will contain the actual container name\n\t\t\t\t\tconst remoteName = isManifestMode ? pluginId : getNormalizedRemoteName(pluginId);\n\n\t\t\t\t\tyield* Effect.try({\n\t\t\t\t\t\ttry: () => mf.registerRemotes([{\n\t\t\t\t\t\t\tname: remoteName,\n\t\t\t\t\t\t\tentry: entryUrl,\n\t\t\t\t\t\t\t...(isManifestMode && { alias: pluginId }) // Explicit alias for clarity\n\t\t\t\t\t\t}]),\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\tconsole.log(`[MF] ✅ Registered ${pluginId} (${isManifestMode ? 'MF 2.0' : 'MF 1.5'})`);\n\t\t\t\t}),\n\n\t\t\tloadRemoteConstructor: (pluginId: string, url: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst remoteName = getNormalizedRemoteName(pluginId);\n\t\t\t\t\tconsole.log(`[MF] Loading remote ${remoteName}`);\n\t\t\t\t\tconst modulePath = `${remoteName}/plugin`;\n\n\t\t\t\t\treturn yield* Effect.tryPromise({\n\t\t\t\t\t\ttry: async () => {\n\n\t\t\t\t\t\t\tconst container = await mf.loadRemote<RemoteModule>(modulePath);\n\t\t\t\t\t\t\tif (!container) {\n\t\t\t\t\t\t\t\tthrow new Error(`No container returned for ${modulePath}`);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Support multiple export patterns: direct function, default export, named exports\n\t\t\t\t\t\t\tconst Constructor =\n\t\t\t\t\t\t\t\ttypeof container === \"function\"\n\t\t\t\t\t\t\t\t\t? container // Direct function export\n\t\t\t\t\t\t\t\t\t: container.default\n\t\t\t\t\t\t\t\t\t? container.default // Default export\n\t\t\t\t\t\t\t\t\t: Object.values(container).find( // Named export fallback\n\t\t\t\t\t\t\t\t\t\t\t(exp) => typeof exp === \"function\" && exp.prototype?.constructor === exp\n\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (!Constructor || typeof Constructor !== \"function\") {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Available exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`No valid plugin constructor found for '${pluginId}'.\\n` +\n\t\t\t\t\t\t\t\t\t`Supported patterns:\\n` +\n\t\t\t\t\t\t\t\t\t` - export const YourPlugin = createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t` - export default createPlugin({...})\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Validate it looks like a plugin constructor (has binding property)\n\t\t\t\t\t\t\tif (!(Constructor as any).binding) {\n\t\t\t\t\t\t\t\tconst containerInfo = typeof container === \"object\"\n\t\t\t\t\t\t\t\t\t? `Found exports: ${Object.keys(container).join(', ')}`\n\t\t\t\t\t\t\t\t\t: `Container type: ${typeof container}`;\n\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Invalid plugin constructor for '${pluginId}'. ` +\n\t\t\t\t\t\t\t\t\t`The exported value must be created with createPlugin(). ` +\n\t\t\t\t\t\t\t\t\t`Found a function but it's missing the required 'binding' property.\\n` +\n\t\t\t\t\t\t\t\t\t`${containerInfo}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.log(`[MF] ✅ Loaded constructor for ${pluginId}`);\n\t\t\t\t\t\t\treturn Constructor;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcatch: (error): ModuleFederationError =>\n\t\t\t\t\t\t\tnew ModuleFederationError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tremoteUrl: url,\n\t\t\t\t\t\t\t\tcause:\n\t\t\t\t\t\t\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {}\n"],"mappings":";;;;;;;;AAgBA,MAAM,iCAAiC,OAAO,OAC7C,OAAO,WAAW;AACjB,KAAI;EACH,IAAI,WAAW,aAAa;AAE5B,MAAI,CAAC,UAAU;AACd,cAAW,eAAe;IACzB,MAAM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,gBACH;;AAGF,aAAQ,IAAI,iCAAiC,WAAW;AACxD,YAAO;;IAER,QAAQ,UACP,IAAI,sBAAsB;KACzB;KACA,WAAW;KACX,OACC,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;KAC1D,CAAC;IACH,CAAC;IACD;EACH;EACA,EACF,CAAC,CAAC"}
|
|
@@ -55,14 +55,21 @@ var PluginLoaderService = class extends effect.Effect.Service()("PluginLoaderSer
|
|
|
55
55
|
metadata: entry.metadata
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
const url =
|
|
59
|
-
|
|
58
|
+
const url = entry.metadata.remoteUrl;
|
|
59
|
+
if (!url) return yield* effect.Effect.fail(new require_errors.PluginRuntimeError({
|
|
60
|
+
pluginId,
|
|
61
|
+
operation: "load-plugin",
|
|
62
|
+
cause: /* @__PURE__ */ new Error(`Plugin ${pluginId} has no module or remote URL configured`),
|
|
63
|
+
retryable: false
|
|
64
|
+
}));
|
|
65
|
+
const resolvedUrl = resolveUrl(url);
|
|
66
|
+
yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, pluginId, void 0, "register-remote", true)));
|
|
60
67
|
yield* effect.Effect.logDebug("Loading plugin from remote", {
|
|
61
68
|
pluginId,
|
|
62
|
-
url
|
|
69
|
+
url: resolvedUrl
|
|
63
70
|
});
|
|
64
71
|
return {
|
|
65
|
-
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId,
|
|
72
|
+
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, pluginId, void 0, "load-remote", false))),
|
|
66
73
|
metadata: entry.metadata
|
|
67
74
|
};
|
|
68
75
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.cjs","names":["Context","Effect","PluginRuntimeError","ModuleFederationService","SecretsService","toPluginRuntimeError","validate","Scope"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type {\n\tAnyPlugin,\n\tAnyPluginConstructor,\n\tInitializedPlugin,\n\tLoadedPlugin,\n\tPluginInstance,\n\tPluginMetadata,\n\tPluginRegistry\n} from \"../../types\";\nimport { PluginRuntimeError, toPluginRuntimeError } from \"../errors\";\nimport { validate } from \"../validation\";\nimport { ModuleFederationService } from \"./module-federation.service\";\nimport { SecretsService } from \"./secrets.service\";\n\nexport class PluginRegistryTag extends Context.Tag(\"PluginRegistry\")<\n\tPluginRegistryTag,\n\tPluginRegistry\n>() { }\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n\tPluginMapTag,\n\tRecord<string, AnyPluginConstructor>\n>() { }\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst registry = yield* PluginRegistryTag;\n\t\tconst pluginMap = yield* PluginMapTag;\n\n\t\treturn {\n\t\t\tget: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = registry[pluginId];\n\t\t\t\t\t\n\t\t\t\t\tif (!entry) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"validate-plugin-id\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} not found in registry`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\"module\" in entry) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tconstructor: entry.module,\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\tremoteUrl: entry.remote || \"\",\n\t\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconstructor: null,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tremoteUrl: entry.remote,\n\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t};\n\t\t\t\t}),\n\n\t\t\tgetModule: (pluginId: string) =>\n\t\t\t\tEffect.succeed(pluginMap[pluginId] || null),\n\t\t};\n\t}),\n}) { }\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\"PluginLoaderService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst moduleFederationService = yield* ModuleFederationService;\n\t\tconst secretsService = yield* SecretsService;\n\t\tconst registryService = yield* RegistryService;\n\n\t\tconst resolveUrl = (baseUrl: string, version?: string): string =>\n\t\t\tversion && version !== \"latest\"\n\t\t\t\t? baseUrl.replace(\"@latest\", `@${version}`)\n\t\t\t\t: baseUrl;\n\n\t\treturn {\n\t\t\tloadPlugin: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = yield* registryService.get(pluginId);\n\n\t\t\t\t\tif (entry.constructor) {\n\t\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tctor: entry.constructor,\n\t\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = resolveUrl(entry.metadata.remoteUrl);\n\n\t\t\t\t\tyield* moduleFederationService.registerRemote(pluginId, url).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url });\n\n\t\t\t\t\tconst ctor = yield* moduleFederationService.loadRemoteConstructor(pluginId, url).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tctor,\n\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t}),\n\n\t\t\tinstantiatePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginId: string,\n\t\t\t\tloadedPlugin: LoadedPlugin<T>,\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\"instantiate-plugin\",\n\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t(instance.id as string) = pluginId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin: instance,\n\t\t\t\t\t\tmetadata: loadedPlugin.metadata,\n\t\t\t\t\t} satisfies PluginInstance<T>;\n\t\t\t\t}),\n\n\t\t\tinitializePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginInstance: PluginInstance<T>,\n\t\t\t\tconfig: { variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>; secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]> },\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { plugin } = pluginInstance;\n\n\t\t\t\t\t// Validate and hydrate config\n\t\t\t\t\tconst validatedVariables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\tconfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Validate secrets\n\t\t\t\t\tconst validatedSecrets = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.secrets as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>>,\n\t\t\t\t\t\tconfig.secrets,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-secrets\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Hydrate secrets in variables\n\t\t\t\t\tconst hydratedConfig = yield* secretsService.hydrateSecrets({\n\t\t\t\t\t\tvariables: validatedVariables,\n\t\t\t\t\t\tsecrets: validatedSecrets,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst _variables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\thydratedConfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-hydrated-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Create a long-lived scope for this plugin instance\n\t\t\t\t\tconst scope = yield* Scope.make();\n\n\t\t\t\t\t// Initialize plugin within the scope\n\t\t\t\t\tconst context = yield* plugin.initialize({ variables: _variables, secrets: hydratedConfig.secrets }).pipe(\n\t\t\t\t\t\tEffect.provideService(Scope.Scope, scope),\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin,\n\t\t\t\t\t\tmetadata: pluginInstance.metadata,\n\t\t\t\t\t\tconfig: { variables: _variables, secrets: hydratedConfig.secrets },\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t} satisfies InitializedPlugin<T>;\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {\n}\n"],"mappings":";;;;;;;;AAiBA,IAAa,oBAAb,cAAuCA,eAAQ,IAAI,iBAAiB,EAGjE,CAAC;AAEJ,IAAa,eAAb,cAAkCA,eAAQ,IAAI,YAAY,EAGvD,CAAC;AAEJ,IAAa,kBAAb,cAAqCC,cAAO,SAA0B,CAAC,mBAAmB,EACzF,QAAQA,cAAO,IAAI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ACvB,WAAW;IACX,CAAC,CACF,CACD;GAGD,MAAM,QAAQ,OAAOK,aAAM,MAAM;GAGjC,MAAM,UAAU,OAAO,OAAO,WAAW;IAAE,WAAW;IAAY,SAAS,eAAe;IAAS,CAAC,CAAC,KACpGN,cAAO,eAAeM,aAAM,OAAO,MAAM,EACzCN,cAAO,UAAU,UAChBI,oCAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC7E,CACD;AAED,UAAO;IACN;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACA;IACA;EACH;EACA,EACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.cjs","names":["Context","Effect","PluginRuntimeError","ModuleFederationService","SecretsService","toPluginRuntimeError","validate","Scope"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type {\n\tAnyPlugin,\n\tAnyPluginConstructor,\n\tInitializedPlugin,\n\tLoadedPlugin,\n\tPluginInstance,\n\tPluginMetadata,\n\tPluginRegistry\n} from \"../../types\";\nimport { PluginRuntimeError, toPluginRuntimeError } from \"../errors\";\nimport { validate } from \"../validation\";\nimport { ModuleFederationService } from \"./module-federation.service\";\nimport { SecretsService } from \"./secrets.service\";\n\nexport class PluginRegistryTag extends Context.Tag(\"PluginRegistry\")<\n\tPluginRegistryTag,\n\tPluginRegistry\n>() { }\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n\tPluginMapTag,\n\tRecord<string, AnyPluginConstructor>\n>() { }\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst registry = yield* PluginRegistryTag;\n\t\tconst pluginMap = yield* PluginMapTag;\n\n\t\treturn {\n\t\t\tget: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = registry[pluginId];\n\t\t\t\t\t\n\t\t\t\t\tif (!entry) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"validate-plugin-id\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} not found in registry`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\"module\" in entry) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tconstructor: entry.module,\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\tremoteUrl: entry.remote || \"\",\n\t\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconstructor: null,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tremoteUrl: entry.remote,\n\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t};\n\t\t\t\t}),\n\n\t\t\tgetModule: (pluginId: string) =>\n\t\t\t\tEffect.succeed(pluginMap[pluginId] || null),\n\t\t};\n\t}),\n}) { }\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\"PluginLoaderService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst moduleFederationService = yield* ModuleFederationService;\n\t\tconst secretsService = yield* SecretsService;\n\t\tconst registryService = yield* RegistryService;\n\n\t\tconst resolveUrl = (baseUrl: string, version?: string): string =>\n\t\t\tversion && version !== \"latest\"\n\t\t\t\t? baseUrl.replace(\"@latest\", `@${version}`)\n\t\t\t\t: baseUrl;\n\n\t\treturn {\n\t\t\tloadPlugin: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = yield* registryService.get(pluginId);\n\n\t\t\t\t\tif (entry.constructor) {\n\t\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tctor: entry.constructor,\n\t\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = entry.metadata.remoteUrl;\n\t\t\t\t\tif (!url) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"load-plugin\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst resolvedUrl = resolveUrl(url);\n\n\t\t\t\t\tyield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n\t\t\t\t\tconst ctor = yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tctor,\n\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t}),\n\n\t\t\tinstantiatePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginId: string,\n\t\t\t\tloadedPlugin: LoadedPlugin<T>,\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\"instantiate-plugin\",\n\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t(instance.id as string) = pluginId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin: instance,\n\t\t\t\t\t\tmetadata: loadedPlugin.metadata,\n\t\t\t\t\t} satisfies PluginInstance<T>;\n\t\t\t\t}),\n\n\t\t\tinitializePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginInstance: PluginInstance<T>,\n\t\t\t\tconfig: { variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>; secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]> },\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { plugin } = pluginInstance;\n\n\t\t\t\t\t// Validate and hydrate config\n\t\t\t\t\tconst validatedVariables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\tconfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Validate secrets\n\t\t\t\t\tconst validatedSecrets = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.secrets as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>>,\n\t\t\t\t\t\tconfig.secrets,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-secrets\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Hydrate secrets in variables\n\t\t\t\t\tconst hydratedConfig = yield* secretsService.hydrateSecrets({\n\t\t\t\t\t\tvariables: validatedVariables,\n\t\t\t\t\t\tsecrets: validatedSecrets,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst _variables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\thydratedConfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-hydrated-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Create a long-lived scope for this plugin instance\n\t\t\t\t\tconst scope = yield* Scope.make();\n\n\t\t\t\t\t// Initialize plugin within the scope\n\t\t\t\t\tconst context = yield* plugin.initialize({ variables: _variables, secrets: hydratedConfig.secrets }).pipe(\n\t\t\t\t\t\tEffect.provideService(Scope.Scope, scope),\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin,\n\t\t\t\t\t\tmetadata: pluginInstance.metadata,\n\t\t\t\t\t\tconfig: { variables: _variables, secrets: hydratedConfig.secrets },\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t} satisfies InitializedPlugin<T>;\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {\n}\n"],"mappings":";;;;;;;;AAiBA,IAAa,oBAAb,cAAuCA,eAAQ,IAAI,iBAAiB,EAGjE,CAAC;AAEJ,IAAa,eAAb,cAAkCA,eAAQ,IAAI,YAAY,EAGvD,CAAC;AAEJ,IAAa,kBAAb,cAAqCC,cAAO,SAA0B,CAAC,mBAAmB,EACzF,QAAQA,cAAO,IAAI,aAAa;CAC/B,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,OAAO;AAEzB,QAAO;EACN,MAAM,aACLA,cAAO,IAAI,aAAa;GACvB,MAAM,QAAQ,SAAS;AAEvB,OAAI,CAAC,MACJ,QAAO,OAAOA,cAAO,KACpB,IAAIC,kCAAmB;IACtB;IACA,WAAW;IACX,uBAAO,IAAI,MAAM,UAAU,SAAS,wBAAwB;IAC5D,WAAW;IACX,CAAC,CACF;AAGF,OAAI,YAAY,MACf,QAAO;IACN,aAAa,MAAM;IACnB,UAAU;KACT,WAAW,MAAM,UAAU;KAC3B,SAAS,MA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O,UAAU,UAChBI,oCAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC7E,CACD;AAED,UAAO;IACN;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACA;IACA;EACH;EACA,EACF,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.d.cts","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAemD;cAEtC,iBAAA,SAA0B,sBAAA;cAGhC;cAEM,YAAA,SAAqB,iBAAA;cAG3B;EARM,SAAA,MAAA,eAAkB,CAAA;IAGxB,GAAA,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAakB,MAAA,CAAA,MAblB,CAAA;;gBAmCK;;;gBAUD;IA3CE,CAAA,oBAAa,EAAQ,KAAA,CAAA;IAG3B,SAAA,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GA4CwB,MAAA,CAAA,MA5CxB,CA4CwB,oBA5CxB,GAAA,IAAA,EAAA,KAAA,EAAA,KAAA,CAAA;;;AA8BK,cA5BC,eAAA,SAAwB,oBAAA,CA4BzB;cAkBN;EAxCmB,SAAA,MAAA,eAAA,CAAA;IAoCM,UAAA,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAkBC,MAAA,CAAA,MAlBD,CAAA;MAAA,IAAA,EAAA,OAAA,YAAA;;;
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.d.cts","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAemD;cAEtC,iBAAA,SAA0B,sBAAA;cAGhC;cAEM,YAAA,SAAqB,iBAAA;cAG3B;EARM,SAAA,MAAA,eAAkB,CAAA;IAGxB,GAAA,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAakB,MAAA,CAAA,MAblB,CAAA;;gBAmCK;;;gBAUD;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AAA,CAAA,UAsF0B,SAtF1B,CAAA,CAAA,cAAA,EAuFc,cAvFd,CAuF6B,CAvF7B,CAAA,EAAA,MAAA,EAAA;iBAwFmB,iBAAiB;eAA0C,iBAAiB;UAA+B,MAAA,CAAA;;MA1EpG,QAAA,gBAAA;MA+CC,MAAA,EAAA;QAEF,SAAA,mBAAA,EAAA,CAAA,cAAA,CAAA,CAAA,WAAA,CAAA,CAAA;QAAb,OAAA,mBAAA,EAAA,CAAA,cAAA,CAAA,CAAA,SAAA,CAAA,CAAA;;;;IAAe,CAAA,oBAAA,EAAA,KAAA,CAAA;EAuBD,CAAA,EAAA,KAAA,yBAAA,iBAAA,kBAAA,CAAA;CACG,CAAA;AAAf,cArFP,mBAAA,SAA4B,wBAAA,CAqFrB"}
|
|
@@ -54,14 +54,21 @@ var PluginLoaderService = class extends Effect.Service()("PluginLoaderService",
|
|
|
54
54
|
metadata: entry.metadata
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
const url =
|
|
58
|
-
|
|
57
|
+
const url = entry.metadata.remoteUrl;
|
|
58
|
+
if (!url) return yield* Effect.fail(new PluginRuntimeError({
|
|
59
|
+
pluginId,
|
|
60
|
+
operation: "load-plugin",
|
|
61
|
+
cause: /* @__PURE__ */ new Error(`Plugin ${pluginId} has no module or remote URL configured`),
|
|
62
|
+
retryable: false
|
|
63
|
+
}));
|
|
64
|
+
const resolvedUrl = resolveUrl(url);
|
|
65
|
+
yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(Effect.mapError((error) => toPluginRuntimeError(error, pluginId, void 0, "register-remote", true)));
|
|
59
66
|
yield* Effect.logDebug("Loading plugin from remote", {
|
|
60
67
|
pluginId,
|
|
61
|
-
url
|
|
68
|
+
url: resolvedUrl
|
|
62
69
|
});
|
|
63
70
|
return {
|
|
64
|
-
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId,
|
|
71
|
+
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(Effect.mapError((error) => toPluginRuntimeError(error, pluginId, void 0, "load-remote", false))),
|
|
65
72
|
metadata: entry.metadata
|
|
66
73
|
};
|
|
67
74
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.mjs","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type {\n\tAnyPlugin,\n\tAnyPluginConstructor,\n\tInitializedPlugin,\n\tLoadedPlugin,\n\tPluginInstance,\n\tPluginMetadata,\n\tPluginRegistry\n} from \"../../types\";\nimport { PluginRuntimeError, toPluginRuntimeError } from \"../errors\";\nimport { validate } from \"../validation\";\nimport { ModuleFederationService } from \"./module-federation.service\";\nimport { SecretsService } from \"./secrets.service\";\n\nexport class PluginRegistryTag extends Context.Tag(\"PluginRegistry\")<\n\tPluginRegistryTag,\n\tPluginRegistry\n>() { }\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n\tPluginMapTag,\n\tRecord<string, AnyPluginConstructor>\n>() { }\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst registry = yield* PluginRegistryTag;\n\t\tconst pluginMap = yield* PluginMapTag;\n\n\t\treturn {\n\t\t\tget: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = registry[pluginId];\n\t\t\t\t\t\n\t\t\t\t\tif (!entry) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"validate-plugin-id\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} not found in registry`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\"module\" in entry) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tconstructor: entry.module,\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\tremoteUrl: entry.remote || \"\",\n\t\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconstructor: null,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tremoteUrl: entry.remote,\n\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t};\n\t\t\t\t}),\n\n\t\t\tgetModule: (pluginId: string) =>\n\t\t\t\tEffect.succeed(pluginMap[pluginId] || null),\n\t\t};\n\t}),\n}) { }\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\"PluginLoaderService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst moduleFederationService = yield* ModuleFederationService;\n\t\tconst secretsService = yield* SecretsService;\n\t\tconst registryService = yield* RegistryService;\n\n\t\tconst resolveUrl = (baseUrl: string, version?: string): string =>\n\t\t\tversion && version !== \"latest\"\n\t\t\t\t? baseUrl.replace(\"@latest\", `@${version}`)\n\t\t\t\t: baseUrl;\n\n\t\treturn {\n\t\t\tloadPlugin: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = yield* registryService.get(pluginId);\n\n\t\t\t\t\tif (entry.constructor) {\n\t\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tctor: entry.constructor,\n\t\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = resolveUrl(entry.metadata.remoteUrl);\n\n\t\t\t\t\tyield* moduleFederationService.registerRemote(pluginId, url).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url });\n\n\t\t\t\t\tconst ctor = yield* moduleFederationService.loadRemoteConstructor(pluginId, url).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tctor,\n\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t}),\n\n\t\t\tinstantiatePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginId: string,\n\t\t\t\tloadedPlugin: LoadedPlugin<T>,\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\"instantiate-plugin\",\n\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t(instance.id as string) = pluginId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin: instance,\n\t\t\t\t\t\tmetadata: loadedPlugin.metadata,\n\t\t\t\t\t} satisfies PluginInstance<T>;\n\t\t\t\t}),\n\n\t\t\tinitializePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginInstance: PluginInstance<T>,\n\t\t\t\tconfig: { variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>; secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]> },\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { plugin } = pluginInstance;\n\n\t\t\t\t\t// Validate and hydrate config\n\t\t\t\t\tconst validatedVariables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\tconfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Validate secrets\n\t\t\t\t\tconst validatedSecrets = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.secrets as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>>,\n\t\t\t\t\t\tconfig.secrets,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-secrets\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Hydrate secrets in variables\n\t\t\t\t\tconst hydratedConfig = yield* secretsService.hydrateSecrets({\n\t\t\t\t\t\tvariables: validatedVariables,\n\t\t\t\t\t\tsecrets: validatedSecrets,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst _variables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\thydratedConfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-hydrated-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Create a long-lived scope for this plugin instance\n\t\t\t\t\tconst scope = yield* Scope.make();\n\n\t\t\t\t\t// Initialize plugin within the scope\n\t\t\t\t\tconst context = yield* plugin.initialize({ variables: _variables, secrets: hydratedConfig.secrets }).pipe(\n\t\t\t\t\t\tEffect.provideService(Scope.Scope, scope),\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin,\n\t\t\t\t\t\tmetadata: pluginInstance.metadata,\n\t\t\t\t\t\tconfig: { variables: _variables, secrets: hydratedConfig.secrets },\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t} satisfies InitializedPlugin<T>;\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {\n}\n"],"mappings":";;;;;;;AAiBA,IAAa,oBAAb,cAAuC,QAAQ,IAAI,iBAA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WACf,OAAO,IACP,SACA,CAAC,KACD,OAAO,UAAU,oBAChB,IAAI,mBAAmB;IACtB,UAAU,OAAO;IACjB,WAAW;IACX,OAAO,gBAAgB;IACvB,WAAW;IACX,CAAC,CACF,CACD;GAGD,MAAM,QAAQ,OAAO,MAAM,MAAM;GAGjC,MAAM,UAAU,OAAO,OAAO,WAAW;IAAE,WAAW;IAAY,SAAS,eAAe;IAAS,CAAC,CAAC,KACpG,OAAO,eAAe,MAAM,OAAO,MAAM,EACzC,OAAO,UAAU,UAChB,qBAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC7E,CACD;AAED,UAAO;IACN;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACA;IACA;EACH;EACA,EACF,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.mjs","names":[],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type {\n\tAnyPlugin,\n\tAnyPluginConstructor,\n\tInitializedPlugin,\n\tLoadedPlugin,\n\tPluginInstance,\n\tPluginMetadata,\n\tPluginRegistry\n} from \"../../types\";\nimport { PluginRuntimeError, toPluginRuntimeError } from \"../errors\";\nimport { validate } from \"../validation\";\nimport { ModuleFederationService } from \"./module-federation.service\";\nimport { SecretsService } from \"./secrets.service\";\n\nexport class PluginRegistryTag extends Context.Tag(\"PluginRegistry\")<\n\tPluginRegistryTag,\n\tPluginRegistry\n>() { }\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n\tPluginMapTag,\n\tRecord<string, AnyPluginConstructor>\n>() { }\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst registry = yield* PluginRegistryTag;\n\t\tconst pluginMap = yield* PluginMapTag;\n\n\t\treturn {\n\t\t\tget: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = registry[pluginId];\n\t\t\t\t\t\n\t\t\t\t\tif (!entry) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"validate-plugin-id\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} not found in registry`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\"module\" in entry) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tconstructor: entry.module,\n\t\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\t\tremoteUrl: entry.remote || \"\",\n\t\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconstructor: null,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tremoteUrl: entry.remote,\n\t\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\t\tdescription: entry.description,\n\t\t\t\t\t\t} as PluginMetadata,\n\t\t\t\t\t};\n\t\t\t\t}),\n\n\t\t\tgetModule: (pluginId: string) =>\n\t\t\t\tEffect.succeed(pluginMap[pluginId] || null),\n\t\t};\n\t}),\n}) { }\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\"PluginLoaderService\", {\n\teffect: Effect.gen(function* () {\n\t\tconst moduleFederationService = yield* ModuleFederationService;\n\t\tconst secretsService = yield* SecretsService;\n\t\tconst registryService = yield* RegistryService;\n\n\t\tconst resolveUrl = (baseUrl: string, version?: string): string =>\n\t\t\tversion && version !== \"latest\"\n\t\t\t\t? baseUrl.replace(\"@latest\", `@${version}`)\n\t\t\t\t: baseUrl;\n\n\t\treturn {\n\t\t\tloadPlugin: (pluginId: string) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst entry = yield* registryService.get(pluginId);\n\n\t\t\t\t\tif (entry.constructor) {\n\t\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\t\t\t\t\t\t\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tctor: entry.constructor,\n\t\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst url = entry.metadata.remoteUrl;\n\t\t\t\t\tif (!url) {\n\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\toperation: \"load-plugin\",\n\t\t\t\t\t\t\t\tcause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst resolvedUrl = resolveUrl(url);\n\n\t\t\t\t\tyield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\tyield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n\t\t\t\t\tconst ctor = yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tctor,\n\t\t\t\t\t\tmetadata: entry.metadata,\n\t\t\t\t\t} satisfies LoadedPlugin;\n\t\t\t\t}),\n\n\t\t\tinstantiatePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginId: string,\n\t\t\t\tloadedPlugin: LoadedPlugin<T>,\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\tpluginId,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t\"instantiate-plugin\",\n\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t(instance.id as string) = pluginId;\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin: instance,\n\t\t\t\t\t\tmetadata: loadedPlugin.metadata,\n\t\t\t\t\t} satisfies PluginInstance<T>;\n\t\t\t\t}),\n\n\t\t\tinitializePlugin: <T extends AnyPlugin>(\n\t\t\t\tpluginInstance: PluginInstance<T>,\n\t\t\t\tconfig: { variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>; secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]> },\n\t\t\t) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst { plugin } = pluginInstance;\n\n\t\t\t\t\t// Validate and hydrate config\n\t\t\t\t\tconst validatedVariables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\tconfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Validate secrets\n\t\t\t\t\tconst validatedSecrets = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.secrets as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>>,\n\t\t\t\t\t\tconfig.secrets,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-secrets\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Hydrate secrets in variables\n\t\t\t\t\tconst hydratedConfig = yield* secretsService.hydrateSecrets({\n\t\t\t\t\t\tvariables: validatedVariables,\n\t\t\t\t\t\tsecrets: validatedSecrets,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst _variables = yield* validate(\n\t\t\t\t\t\tplugin.configSchema.variables as z.ZodSchema<InferSchemaOutput<T[\"configSchema\"][\"variables\"]>>,\n\t\t\t\t\t\thydratedConfig.variables,\n\t\t\t\t\t\tplugin.id,\n\t\t\t\t\t\t\"config\",\n\t\t\t\t\t).pipe(\n\t\t\t\t\t\tEffect.mapError((validationError) =>\n\t\t\t\t\t\t\tnew PluginRuntimeError({\n\t\t\t\t\t\t\t\tpluginId: plugin.id,\n\t\t\t\t\t\t\t\toperation: \"validate-hydrated-config\",\n\t\t\t\t\t\t\t\tcause: validationError.zodError,\n\t\t\t\t\t\t\t\tretryable: false,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\n\t\t\t\t\t// Create a long-lived scope for this plugin instance\n\t\t\t\t\tconst scope = yield* Scope.make();\n\n\t\t\t\t\t// Initialize plugin within the scope\n\t\t\t\t\tconst context = yield* plugin.initialize({ variables: _variables, secrets: hydratedConfig.secrets }).pipe(\n\t\t\t\t\t\tEffect.provideService(Scope.Scope, scope),\n\t\t\t\t\t\tEffect.mapError((error) =>\n\t\t\t\t\t\t\ttoPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tplugin,\n\t\t\t\t\t\tmetadata: pluginInstance.metadata,\n\t\t\t\t\t\tconfig: { variables: _variables, secrets: hydratedConfig.secrets },\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t} satisfies InitializedPlugin<T>;\n\t\t\t\t}),\n\t\t};\n\t}),\n}) {\n}\n"],"mappings":";;;;;;;AAiBA,IAAa,oBAAb,cAAuC,QAAQ,IAAI,iBAAiB,EAGjE,CAAC;AAEJ,IAAa,eAAb,cAAkC,QAAQ,IAAI,YAAY,EAGvD,CAAC;AAEJ,IAAa,kBAAb,cAAqC,OAAO,SAA0B,CAAC,mBAAmB,EACzF,QAAQ,OAAO,IAAI,aAAa;CAC/B,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,OAAO;AAEzB,QAAO;EACN,MAAM,aACL,OAAO,IAAI,aAAa;GACvB,MAAM,QAAQ,SAAS;AAEvB,OAAI,CAAC,MACJ,QAAO,OAAO,OAAO,KACpB,IAAI,mBAAmB;IACtB;IACA,WAAW;IACX,uBAAO,IAAI,MAAM,UAAU,SAAS,wBAAwB;IAC5D,WAAW;IACX,CAAC,CACF;AAGF,OAAI,YAAY,MACf,QAAO;IACN,aAAa,MAAM;IACnB,UAA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