every-plugin 2.9.2 → 2.9.4
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/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +2 -2
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +2 -2
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/runtime/mf-config.cjs +1 -1
- package/dist/runtime/mf-config.mjs +1 -1
- package/dist/runtime/services/plugin-loader.service.cjs +4 -4
- package/dist/runtime/services/plugin-loader.service.cjs.map +1 -1
- package/dist/runtime/services/plugin-loader.service.mjs +4 -4
- package/dist/runtime/services/plugin-loader.service.mjs.map +1 -1
- package/package.json +1 -1
- package/src/plugin.ts +3 -3
- package/src/runtime/services/plugin-loader.service.ts +8 -8
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","names":["Effect","extractFromFiberFailure","ORPCError","formatORPCError"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport { ORPCError } from \"@orpc/contract\";\nimport type { Implementer, Router } from \"@orpc/server\";\nimport { implement, onError } from \"@orpc/server\";\nimport { Effect, type Context as EffectContext, type Layer, type Scope } from \"effect\";\nimport { extractFromFiberFailure, formatORPCError } from \"./runtime/errors\";\n\ntype ContextOutput<T> = T extends AnySchema ? InferSchemaOutput<T> : Record<string, never>;\n\nexport type PluginConfigFor<\n V extends AnySchema,\n S extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n> = {\n variables: V;\n secrets: S;\n context: TRequestContext;\n};\n\ntype PluginInitializeInput<V extends AnySchema, S extends AnySchema> = {\n variables: InferSchemaOutput<V>;\n secrets: InferSchemaOutput<S>;\n};\n\n/**\n * Tools provided to plugin initialize/services for building long-lived scoped resources.\n */\ntype ServiceOf<T> = T extends EffectContext.Tag<any, infer S> ? S : never;\n\nexport type PluginServicesTools = {\n buildService: <T>(tag: T, layer: Layer.Layer<any, any, any>) => Effect.Effect<ServiceOf<T>>;\n};\n\ntype PluginDefinition<\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any>,\n P extends Record<string, unknown>,\n> = {\n variables: V;\n secrets: S;\n contract: TContract;\n context?: TRequestContext;\n /**\n * Initialize the plugin and build dependencies.\n * A third argument `tools` is provided for building long-lived scoped resources\n * (e.g. database pools) via `tools.buildService(tag, layer)`.\n */\n initialize?: (\n config: PluginInitializeInput<V, S>,\n plugins: P,\n tools
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":["Effect","extractFromFiberFailure","ORPCError","formatORPCError"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport { ORPCError } from \"@orpc/contract\";\nimport type { Implementer, Router } from \"@orpc/server\";\nimport { implement, onError } from \"@orpc/server\";\nimport { Effect, type Context as EffectContext, type Layer, type Scope } from \"effect\";\nimport { extractFromFiberFailure, formatORPCError } from \"./runtime/errors\";\n\ntype ContextOutput<T> = T extends AnySchema ? InferSchemaOutput<T> : Record<string, never>;\n\nexport type PluginConfigFor<\n V extends AnySchema,\n S extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n> = {\n variables: V;\n secrets: S;\n context: TRequestContext;\n};\n\ntype PluginInitializeInput<V extends AnySchema, S extends AnySchema> = {\n variables: InferSchemaOutput<V>;\n secrets: InferSchemaOutput<S>;\n};\n\n/**\n * Tools provided to plugin initialize/services for building long-lived scoped resources.\n */\ntype ServiceOf<T> = T extends EffectContext.Tag<any, infer S> ? S : never;\n\nexport type PluginServicesTools = {\n buildService: <T>(tag: T, layer: Layer.Layer<any, any, any>) => Effect.Effect<ServiceOf<T>>;\n};\n\ntype PluginDefinition<\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any>,\n P extends Record<string, unknown>,\n> = {\n variables: V;\n secrets: S;\n contract: TContract;\n context?: TRequestContext;\n /**\n * Initialize the plugin and build dependencies.\n * A third argument `tools` is provided for building long-lived scoped resources\n * (e.g. database pools) via `tools.buildService(tag, layer)`.\n */\n initialize?: (\n config: PluginInitializeInput<V, S>,\n plugins: P,\n tools: PluginServicesTools,\n ) => Effect.Effect<TDeps, Error, Scope.Scope>;\n createRouter: (\n deps: TDeps,\n builder: Implementer<TContract, ContextOutput<TRequestContext>, ContextOutput<TRequestContext>>,\n ) => Router<TContract, any>;\n shutdown?: (deps: TDeps) => Effect.Effect<void, Error, never>;\n};\n\n/**\n * Loaded plugin with static binding property\n */\nexport interface LoadedPluginWithBinding<\n TContract extends AnyContractRouter,\n TVariables extends AnySchema,\n TSecrets extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n> {\n new (): Plugin<TContract, TVariables, TSecrets, TRequestContext, TDeps>;\n binding: {\n contract: TContract;\n variables: TVariables;\n secrets: TSecrets;\n context: TRequestContext;\n };\n}\n\n/**\n * Plugin interface\n */\nexport interface Plugin<\n TContract extends AnyContractRouter,\n TVariables extends AnySchema,\n TSecrets extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n> {\n readonly id: string;\n readonly contract: TContract;\n readonly configSchema: PluginConfigFor<TVariables, TSecrets, TRequestContext>;\n\n initialize(\n config: PluginInitializeInput<TVariables, TSecrets>,\n plugins: Record<string, unknown>,\n tools: PluginServicesTools,\n ): Effect.Effect<TDeps, unknown, Scope.Scope>;\n\n shutdown(): Effect.Effect<void, never>;\n\n /**\n * Creates the strongly-typed oRPC router for this plugin.\n * The router's procedure types are inferred directly from the contract.\n * @param deps The initialized plugin dependencies\n * @returns A router with procedures matching the plugin's contract\n */\n createRouter(deps: TDeps): Router<TContract, any>;\n}\n\nexport interface CreatePluginFn {\n <\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n P extends Record<string, unknown> = Record<string, never>,\n >(\n config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>,\n ): LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n\n withPlugins: <P extends Record<string, unknown>>() => CreatePluginWithPlugins<P>;\n}\n\nexport const createPlugin: CreatePluginFn = function createPlugin<\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n P extends Record<string, unknown> = Record<string, never>,\n>(config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>) {\n const configSchema: PluginConfigFor<V, S, TRequestContext> = {\n variables: config.variables,\n secrets: config.secrets,\n context: config.context as TRequestContext,\n };\n\n class CreatedPlugin implements Plugin<TContract, V, S, TRequestContext, TDeps> {\n /** set during instantiation - registry key */\n id!: string;\n readonly contract = config.contract;\n readonly configSchema = configSchema;\n\n private _deps: TDeps | null = null;\n\n initialize(\n pluginConfig: PluginInitializeInput<V, S>,\n plugins: Record<string, unknown> = {},\n tools: PluginServicesTools,\n ): Effect.Effect<TDeps, unknown, Scope.Scope> {\n const init = config.initialize ?? (() => Effect.succeed({} as TDeps));\n\n return init(pluginConfig, plugins as P, tools).pipe(\n Effect.tap((deps) =>\n Effect.sync(() => {\n this._deps = deps;\n }),\n ),\n Effect.map(() => this._deps as TDeps),\n Effect.mapError((error) => error as unknown),\n );\n }\n\n shutdown(): Effect.Effect<void, never> {\n const self = this;\n return Effect.gen(function* () {\n if (config.shutdown && self._deps) {\n yield* config\n .shutdown(self._deps)\n .pipe(\n Effect.catchAll((error) =>\n Effect.logWarning(`Plugin shutdown hook failed for ${self.id}`, error),\n ),\n );\n }\n self._deps = null;\n });\n }\n\n createRouter(deps: TDeps): Router<TContract, any> {\n const base = implement(config.contract).$context<ContextOutput<TRequestContext>>();\n const errorMiddleware = onError((error: unknown) => {\n const unwrapped = extractFromFiberFailure(error);\n\n if (unwrapped !== error && unwrapped instanceof ORPCError) {\n throw unwrapped;\n }\n\n const formatted = formatORPCError(error);\n if (formatted) console.error(formatted);\n throw error;\n }) as any;\n\n const builder = (base as any).use(errorMiddleware);\n const router = config.createRouter(deps, builder as any);\n return router as Router<TContract, any>;\n }\n }\n\n const PluginConstructor = CreatedPlugin as unknown as {\n new (): Plugin<TContract, V, S, TRequestContext, TDeps>;\n binding: {\n contract: TContract;\n variables: V;\n secrets: S;\n context: TRequestContext;\n };\n };\n\n PluginConstructor.binding = {\n contract: config.contract,\n variables: config.variables,\n secrets: config.secrets,\n context: config.context as TRequestContext,\n };\n\n return PluginConstructor as LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n};\n\nexport type CreatePluginWithPlugins<P extends Record<string, unknown>> = <\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n>(\n config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>,\n) => LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n\nexport function withPlugins<P extends Record<string, unknown>>(): CreatePluginWithPlugins<P> {\n return <\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n >(\n config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>,\n ) => createPlugin<V, S, TContract, TRequestContext, TDeps, P>(config as any);\n}\n\ncreatePlugin.withPlugins = withPlugins;\n"],"mappings":";;;;;;;AA+HA,MAAa,eAA+B,SAAS,aAOnD,QAAsE;CACtE,MAAM,eAAuD;EAC3D,WAAW,OAAO;EAClB,SAAS,OAAO;EAChB,SAAS,OAAO;EACjB;CAED,MAAM,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* A third argument `tools` is provided for building long-lived scoped resources
|
|
31
31
|
* (e.g. database pools) via `tools.buildService(tag, layer)`.
|
|
32
32
|
*/
|
|
33
|
-
initialize?: (config: PluginInitializeInput<V, S>, plugins: P, tools
|
|
33
|
+
initialize?: (config: PluginInitializeInput<V, S>, plugins: P, tools: PluginServicesTools) => Effect.Effect<TDeps, Error, Scope.Scope>;
|
|
34
34
|
createRouter: (deps: TDeps, builder: Implementer<TContract, ContextOutput<TRequestContext>, ContextOutput<TRequestContext>>) => Router<TContract, any>;
|
|
35
35
|
shutdown?: (deps: TDeps) => Effect.Effect<void, Error, never>;
|
|
36
36
|
};
|
|
@@ -53,7 +53,7 @@ interface Plugin<TContract extends AnyContractRouter, TVariables extends AnySche
|
|
|
53
53
|
readonly id: string;
|
|
54
54
|
readonly contract: TContract;
|
|
55
55
|
readonly configSchema: PluginConfigFor<TVariables, TSecrets, TRequestContext>;
|
|
56
|
-
initialize(config: PluginInitializeInput<TVariables, TSecrets>, plugins: Record<string, unknown>, tools
|
|
56
|
+
initialize(config: PluginInitializeInput<TVariables, TSecrets>, plugins: Record<string, unknown>, tools: PluginServicesTools): Effect.Effect<TDeps, unknown, Scope.Scope>;
|
|
57
57
|
shutdown(): Effect.Effect<void, never>;
|
|
58
58
|
/**
|
|
59
59
|
* Creates the strongly-typed oRPC router for this plugin.
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;KAOK,aAAA,MAAmB,CAAA,SAAU,SAAA,GAAY,iBAAA,CAAkB,CAAA,IAAK,MAAA;AAAA,KAEzD,eAAA,WACA,SAAA,YACA,SAAA,0BACc,SAAA;EAExB,SAAA,EAAW,CAAA;EACX,OAAA,EAAS,CAAA;EACT,OAAA,EAAS,eAAA;AAAA;AAAA,KAGN,qBAAA,WAAgC,SAAA,YAAqB,SAAA;EACxD,SAAA,EAAW,iBAAA,CAAkB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AAM,KAAA;EAEvC,QAAA,IAAY,MAAA,CAAO,MAAA;EAhFQ;;;;;;EAwF3B,YAAA,CAAa,IAAA,EAAM,KAAA,GAAQ,MAAA,CAAO,SAAA;AAAA;AAAA,UAGnB,cAAA;EAAA,WAEH,SAAA,YACA,SAAA,oBACQ,iBAAA,0BACM,SAAA,wCACV,MAAA,gBAAsB,MAAA,0BAC1B,MAAA,oBAA0B,MAAA,iBAEpC,MAAA,EAAQ,gBAAA,CAAiB,CAAA,EAAG,CAAA,EAAG,SAAA,EAAW,eAAA,EAAiB,KAAA,EAAO,CAAA,IACjE,uBAAA,CAAwB,SAAA,EAAW,CAAA,EAAG,CAAA,EAAG,eAAA,EAAiB,KAAA;EAE7D,WAAA,aAAwB,MAAA,wBAA8B,uBAAA,CAAwB,CAAA;AAAA;AAAA,cAGnE,YAAA,EAAc,cAAA;AAAA,KAgGf,uBAAA,WAAkC,MAAA,gCAClC,SAAA,YACA,SAAA,oBACQ,iBAAA,0BACM,SAAA,wCACV,MAAA,gBAAsB,MAAA,gBAEpC,MAAA,EAAQ,gBAAA,CAAiB,CAAA,EAAG,CAAA,EAAG,SAAA,EAAW,eAAA,EAAiB,KAAA,EAAO,CAAA,MAC/D,uBAAA,CAAwB,SAAA,EAAW,CAAA,EAAG,CAAA,EAAG,eAAA,EAAiB,KAAA;AAAA,iBAE/C,WAAA,WAAsB,MAAA,kBAAA,CAAA,GAA4B,uBAAA,CAAwB,CAAA"}
|
package/dist/plugin.d.mts
CHANGED
|
@@ -30,7 +30,7 @@ type PluginDefinition<V extends AnySchema, S extends AnySchema, TContract extend
|
|
|
30
30
|
* A third argument `tools` is provided for building long-lived scoped resources
|
|
31
31
|
* (e.g. database pools) via `tools.buildService(tag, layer)`.
|
|
32
32
|
*/
|
|
33
|
-
initialize?: (config: PluginInitializeInput<V, S>, plugins: P, tools
|
|
33
|
+
initialize?: (config: PluginInitializeInput<V, S>, plugins: P, tools: PluginServicesTools) => Effect.Effect<TDeps, Error, Scope.Scope>;
|
|
34
34
|
createRouter: (deps: TDeps, builder: Implementer<TContract, ContextOutput<TRequestContext>, ContextOutput<TRequestContext>>) => Router<TContract, any>;
|
|
35
35
|
shutdown?: (deps: TDeps) => Effect.Effect<void, Error, never>;
|
|
36
36
|
};
|
|
@@ -53,7 +53,7 @@ interface Plugin<TContract extends AnyContractRouter, TVariables extends AnySche
|
|
|
53
53
|
readonly id: string;
|
|
54
54
|
readonly contract: TContract;
|
|
55
55
|
readonly configSchema: PluginConfigFor<TVariables, TSecrets, TRequestContext>;
|
|
56
|
-
initialize(config: PluginInitializeInput<TVariables, TSecrets>, plugins: Record<string, unknown>, tools
|
|
56
|
+
initialize(config: PluginInitializeInput<TVariables, TSecrets>, plugins: Record<string, unknown>, tools: PluginServicesTools): Effect.Effect<TDeps, unknown, Scope.Scope>;
|
|
57
57
|
shutdown(): Effect.Effect<void, never>;
|
|
58
58
|
/**
|
|
59
59
|
* Creates the strongly-typed oRPC router for this plugin.
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;KAOK,aAAA,MAAmB,CAAA,SAAU,SAAA,GAAY,iBAAA,CAAkB,CAAA,IAAK,MAAA;AAAA,KAEzD,eAAA,WACA,SAAA,YACA,SAAA,0BACc,SAAA;EAExB,SAAA,EAAW,CAAA;EACX,OAAA,EAAS,CAAA;EACT,OAAA,EAAS,eAAA;AAAA;AAAA,KAGN,qBAAA,WAAgC,SAAA,YAAqB,SAAA;EACxD,SAAA,EAAW,iBAAA,CAAkB,CAAA;EAC7B,OAAA,EAAS,iBAAA,CAAkB,CAAA;AAAA;;;;KAMxB,SAAA,MAAe,CAAA,SAAU,OAAA,CAAc,GAAA,iBAAoB,CAAA;AAAA,KAEpD,mBAAA;EACV,YAAA,MAAkB,GAAA,EAAK,CAAA,EAAG,KAAA,EAAO,KAAA,CAAM,KAAA,oBAAyB,MAAA,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MAAA,0BAC1B,MAAA,oBAA0B,MAAA,iBAEpC,MAAA,EAAQ,gBAAA,CAAiB,CAAA,EAAG,CAAA,EAAG,SAAA,EAAW,eAAA,EAAiB,KAAA,EAAO,CAAA,IACjE,uBAAA,CAAwB,SAAA,EAAW,CAAA,EAAG,CAAA,EAAG,eAAA,EAAiB,KAAA;EAE7D,WAAA,aAAwB,MAAA,wBAA8B,uBAAA,CAAwB,CAAA;AAAA;AAAA,cAGnE,YAAA,EAAc,cAAA;AAAA,KAgGf,uBAAA,WAAkC,MAAA,gCAClC,SAAA,YACA,SAAA,oBACQ,iBAAA,0BACM,SAAA,wCACV,MAAA,gBAAsB,MAAA,gBAEpC,MAAA,EAAQ,gBAAA,CAAiB,CAAA,EAAG,CAAA,EAAG,SAAA,EAAW,eAAA,EAAiB,KAAA,EAAO,CAAA,MAC/D,uBAAA,CAAwB,SAAA,EAAW,CAAA,EAAG,CAAA,EAAG,eAAA,EAAiB,KAAA;AAAA,iBAE/C,WAAA,WAAsB,MAAA,kBAAA,CAAA,GAA4B,uBAAA,CAAwB,CAAA"}
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport { ORPCError } from \"@orpc/contract\";\nimport type { Implementer, Router } from \"@orpc/server\";\nimport { implement, onError } from \"@orpc/server\";\nimport { Effect, type Context as EffectContext, type Layer, type Scope } from \"effect\";\nimport { extractFromFiberFailure, formatORPCError } from \"./runtime/errors\";\n\ntype ContextOutput<T> = T extends AnySchema ? InferSchemaOutput<T> : Record<string, never>;\n\nexport type PluginConfigFor<\n V extends AnySchema,\n S extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n> = {\n variables: V;\n secrets: S;\n context: TRequestContext;\n};\n\ntype PluginInitializeInput<V extends AnySchema, S extends AnySchema> = {\n variables: InferSchemaOutput<V>;\n secrets: InferSchemaOutput<S>;\n};\n\n/**\n * Tools provided to plugin initialize/services for building long-lived scoped resources.\n */\ntype ServiceOf<T> = T extends EffectContext.Tag<any, infer S> ? S : never;\n\nexport type PluginServicesTools = {\n buildService: <T>(tag: T, layer: Layer.Layer<any, any, any>) => Effect.Effect<ServiceOf<T>>;\n};\n\ntype PluginDefinition<\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any>,\n P extends Record<string, unknown>,\n> = {\n variables: V;\n secrets: S;\n contract: TContract;\n context?: TRequestContext;\n /**\n * Initialize the plugin and build dependencies.\n * A third argument `tools` is provided for building long-lived scoped resources\n * (e.g. database pools) via `tools.buildService(tag, layer)`.\n */\n initialize?: (\n config: PluginInitializeInput<V, S>,\n plugins: P,\n tools
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { AnyContractRouter, AnySchema, InferSchemaOutput } from \"@orpc/contract\";\nimport { ORPCError } from \"@orpc/contract\";\nimport type { Implementer, Router } from \"@orpc/server\";\nimport { implement, onError } from \"@orpc/server\";\nimport { Effect, type Context as EffectContext, type Layer, type Scope } from \"effect\";\nimport { extractFromFiberFailure, formatORPCError } from \"./runtime/errors\";\n\ntype ContextOutput<T> = T extends AnySchema ? InferSchemaOutput<T> : Record<string, never>;\n\nexport type PluginConfigFor<\n V extends AnySchema,\n S extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n> = {\n variables: V;\n secrets: S;\n context: TRequestContext;\n};\n\ntype PluginInitializeInput<V extends AnySchema, S extends AnySchema> = {\n variables: InferSchemaOutput<V>;\n secrets: InferSchemaOutput<S>;\n};\n\n/**\n * Tools provided to plugin initialize/services for building long-lived scoped resources.\n */\ntype ServiceOf<T> = T extends EffectContext.Tag<any, infer S> ? S : never;\n\nexport type PluginServicesTools = {\n buildService: <T>(tag: T, layer: Layer.Layer<any, any, any>) => Effect.Effect<ServiceOf<T>>;\n};\n\ntype PluginDefinition<\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any>,\n P extends Record<string, unknown>,\n> = {\n variables: V;\n secrets: S;\n contract: TContract;\n context?: TRequestContext;\n /**\n * Initialize the plugin and build dependencies.\n * A third argument `tools` is provided for building long-lived scoped resources\n * (e.g. database pools) via `tools.buildService(tag, layer)`.\n */\n initialize?: (\n config: PluginInitializeInput<V, S>,\n plugins: P,\n tools: PluginServicesTools,\n ) => Effect.Effect<TDeps, Error, Scope.Scope>;\n createRouter: (\n deps: TDeps,\n builder: Implementer<TContract, ContextOutput<TRequestContext>, ContextOutput<TRequestContext>>,\n ) => Router<TContract, any>;\n shutdown?: (deps: TDeps) => Effect.Effect<void, Error, never>;\n};\n\n/**\n * Loaded plugin with static binding property\n */\nexport interface LoadedPluginWithBinding<\n TContract extends AnyContractRouter,\n TVariables extends AnySchema,\n TSecrets extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n> {\n new (): Plugin<TContract, TVariables, TSecrets, TRequestContext, TDeps>;\n binding: {\n contract: TContract;\n variables: TVariables;\n secrets: TSecrets;\n context: TRequestContext;\n };\n}\n\n/**\n * Plugin interface\n */\nexport interface Plugin<\n TContract extends AnyContractRouter,\n TVariables extends AnySchema,\n TSecrets extends AnySchema,\n TRequestContext extends AnySchema | undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n> {\n readonly id: string;\n readonly contract: TContract;\n readonly configSchema: PluginConfigFor<TVariables, TSecrets, TRequestContext>;\n\n initialize(\n config: PluginInitializeInput<TVariables, TSecrets>,\n plugins: Record<string, unknown>,\n tools: PluginServicesTools,\n ): Effect.Effect<TDeps, unknown, Scope.Scope>;\n\n shutdown(): Effect.Effect<void, never>;\n\n /**\n * Creates the strongly-typed oRPC router for this plugin.\n * The router's procedure types are inferred directly from the contract.\n * @param deps The initialized plugin dependencies\n * @returns A router with procedures matching the plugin's contract\n */\n createRouter(deps: TDeps): Router<TContract, any>;\n}\n\nexport interface CreatePluginFn {\n <\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n P extends Record<string, unknown> = Record<string, never>,\n >(\n config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>,\n ): LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n\n withPlugins: <P extends Record<string, unknown>>() => CreatePluginWithPlugins<P>;\n}\n\nexport const createPlugin: CreatePluginFn = function createPlugin<\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n P extends Record<string, unknown> = Record<string, never>,\n>(config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>) {\n const configSchema: PluginConfigFor<V, S, TRequestContext> = {\n variables: config.variables,\n secrets: config.secrets,\n context: config.context as TRequestContext,\n };\n\n class CreatedPlugin implements Plugin<TContract, V, S, TRequestContext, TDeps> {\n /** set during instantiation - registry key */\n id!: string;\n readonly contract = config.contract;\n readonly configSchema = configSchema;\n\n private _deps: TDeps | null = null;\n\n initialize(\n pluginConfig: PluginInitializeInput<V, S>,\n plugins: Record<string, unknown> = {},\n tools: PluginServicesTools,\n ): Effect.Effect<TDeps, unknown, Scope.Scope> {\n const init = config.initialize ?? (() => Effect.succeed({} as TDeps));\n\n return init(pluginConfig, plugins as P, tools).pipe(\n Effect.tap((deps) =>\n Effect.sync(() => {\n this._deps = deps;\n }),\n ),\n Effect.map(() => this._deps as TDeps),\n Effect.mapError((error) => error as unknown),\n );\n }\n\n shutdown(): Effect.Effect<void, never> {\n const self = this;\n return Effect.gen(function* () {\n if (config.shutdown && self._deps) {\n yield* config\n .shutdown(self._deps)\n .pipe(\n Effect.catchAll((error) =>\n Effect.logWarning(`Plugin shutdown hook failed for ${self.id}`, error),\n ),\n );\n }\n self._deps = null;\n });\n }\n\n createRouter(deps: TDeps): Router<TContract, any> {\n const base = implement(config.contract).$context<ContextOutput<TRequestContext>>();\n const errorMiddleware = onError((error: unknown) => {\n const unwrapped = extractFromFiberFailure(error);\n\n if (unwrapped !== error && unwrapped instanceof ORPCError) {\n throw unwrapped;\n }\n\n const formatted = formatORPCError(error);\n if (formatted) console.error(formatted);\n throw error;\n }) as any;\n\n const builder = (base as any).use(errorMiddleware);\n const router = config.createRouter(deps, builder as any);\n return router as Router<TContract, any>;\n }\n }\n\n const PluginConstructor = CreatedPlugin as unknown as {\n new (): Plugin<TContract, V, S, TRequestContext, TDeps>;\n binding: {\n contract: TContract;\n variables: V;\n secrets: S;\n context: TRequestContext;\n };\n };\n\n PluginConstructor.binding = {\n contract: config.contract,\n variables: config.variables,\n secrets: config.secrets,\n context: config.context as TRequestContext,\n };\n\n return PluginConstructor as LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n};\n\nexport type CreatePluginWithPlugins<P extends Record<string, unknown>> = <\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n>(\n config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>,\n) => LoadedPluginWithBinding<TContract, V, S, TRequestContext, TDeps>;\n\nexport function withPlugins<P extends Record<string, unknown>>(): CreatePluginWithPlugins<P> {\n return <\n V extends AnySchema,\n S extends AnySchema,\n TContract extends AnyContractRouter,\n TRequestContext extends AnySchema | undefined = undefined,\n TDeps extends Record<string, any> = Record<never, never>,\n >(\n config: PluginDefinition<V, S, TContract, TRequestContext, TDeps, P>,\n ) => createPlugin<V, S, TContract, TRequestContext, TDeps, P>(config as any);\n}\n\ncreatePlugin.withPlugins = withPlugins;\n"],"mappings":";;;;;;AA+HA,MAAa,eAA+B,SAAS,aAOnD,QAAsE;CACtE,MAAM,eAAu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ackageVersion(packageName, fallbackRange) {
|
|
|
21
21
|
return match ? match[0] : fallbackRange.replace(/^[\^~>=<\s]+/, "");
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
const PLUGIN_VERSION = "2.9.
|
|
24
|
+
const PLUGIN_VERSION = "2.9.4";
|
|
25
25
|
const SHARE_CONFIG = {
|
|
26
26
|
singleton: true,
|
|
27
27
|
requiredVersion: false,
|
|
@@ -19,7 +19,7 @@ function getInstalledPackageVersion(packageName, fallbackRange) {
|
|
|
19
19
|
return match ? match[0] : fallbackRange.replace(/^[\^~>=<\s]+/, "");
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
const PLUGIN_VERSION = "2.9.
|
|
22
|
+
const PLUGIN_VERSION = "2.9.4";
|
|
23
23
|
const SHARE_CONFIG = {
|
|
24
24
|
singleton: true,
|
|
25
25
|
requiredVersion: false,
|
|
@@ -63,18 +63,18 @@ var PluginLoaderService = class extends effect.Effect.Service()("PluginLoaderSer
|
|
|
63
63
|
retryable: false
|
|
64
64
|
}));
|
|
65
65
|
const resolvedUrl = resolveUrl(url);
|
|
66
|
-
yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(effect.Effect.tapError((
|
|
66
|
+
yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(effect.Effect.tapError((error) => effect.Effect.logError(`Plugin ${pluginId} failed during register-remote: ${error}`)), effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, pluginId, void 0, "register-remote", true)));
|
|
67
67
|
yield* effect.Effect.logDebug("Loading plugin from remote", {
|
|
68
68
|
pluginId,
|
|
69
69
|
url: resolvedUrl
|
|
70
70
|
});
|
|
71
71
|
return {
|
|
72
|
-
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(effect.Effect.tapError((
|
|
72
|
+
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(effect.Effect.tapError((error) => effect.Effect.logError(`Plugin ${pluginId} failed during load-remote: ${error}`)), effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, pluginId, void 0, "load-remote", false))),
|
|
73
73
|
metadata: entry.metadata
|
|
74
74
|
};
|
|
75
75
|
}),
|
|
76
76
|
instantiatePlugin: (pluginId, loadedPlugin) => effect.Effect.gen(function* () {
|
|
77
|
-
const instance = yield* effect.Effect.try(() => new loadedPlugin.ctor()).pipe(effect.Effect.tapError((
|
|
77
|
+
const instance = yield* effect.Effect.try(() => new loadedPlugin.ctor()).pipe(effect.Effect.tapError((error) => effect.Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin: ${error}`)), effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, pluginId, void 0, "instantiate-plugin", false)));
|
|
78
78
|
instance.id = pluginId;
|
|
79
79
|
return {
|
|
80
80
|
plugin: instance,
|
|
@@ -110,7 +110,7 @@ var PluginLoaderService = class extends effect.Effect.Service()("PluginLoaderSer
|
|
|
110
110
|
const context = yield* plugin.initialize({
|
|
111
111
|
variables: _variables,
|
|
112
112
|
secrets: hydratedConfig.secrets
|
|
113
|
-
}, plugins ?? {}, { buildService: (tag, layer) => effect.Layer.buildWithMemoMap(layer, memoMap, scope).pipe(effect.Effect.map((ctx) => effect.Context.get(ctx, tag))) }).pipe(effect.Effect.provideService(effect.Scope.Scope, scope), effect.Effect.tapError((
|
|
113
|
+
}, plugins ?? {}, { buildService: (tag, layer) => effect.Layer.buildWithMemoMap(layer, memoMap, scope).pipe(effect.Effect.map((ctx) => effect.Context.get(ctx, tag))) }).pipe(effect.Effect.provideService(effect.Scope.Scope, scope), effect.Effect.tapError((error) => effect.Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin: ${error}`)), effect.Effect.mapError((error) => require_errors.toPluginRuntimeError(error, plugin.id, void 0, "initialize-plugin", false)));
|
|
114
114
|
return {
|
|
115
115
|
plugin,
|
|
116
116
|
metadata: pluginInstance.metadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.cjs","names":["Context","Effect","PluginRuntimeError","ModuleFederationService","SecretsService","toPluginRuntimeError","validate","Scope","Layer","EffectContext"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Context as EffectContext, Layer, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type { PluginServicesTools } from \"../../plugin\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InitializedPlugin,\n LoadedPlugin,\n PluginInstance,\n PluginMetadata,\n PluginRegistry,\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 PluginRegistryTag,\n PluginRegistry\n>() {}\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n PluginMapTag,\n Record<string, AnyPluginConstructor>\n>() {}\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n effect: Effect.gen(function* () {\n const registry = yield* PluginRegistryTag;\n const pluginMap = yield* PluginMapTag;\n\n return {\n get: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = registry[pluginId];\n\n if (!entry) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ${pluginId} not found in registry`),\n retryable: false,\n }),\n );\n }\n\n if (\"module\" in entry) {\n return {\n constructor: entry.module,\n metadata: {\n remoteUrl: entry.remote || \"\",\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }\n\n return {\n constructor: null,\n metadata: {\n remoteUrl: entry.remote,\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }),\n\n getModule: (pluginId: string) => Effect.succeed(pluginMap[pluginId] || null),\n };\n }),\n}) {}\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\n \"PluginLoaderService\",\n {\n effect: Effect.gen(function* () {\n const moduleFederationService = yield* ModuleFederationService;\n const secretsService = yield* SecretsService;\n const registryService = yield* RegistryService;\n\n const resolveUrl = (baseUrl: string, version?: string): string =>\n version && version !== \"latest\" ? baseUrl.replace(\"@latest\", `@${version}`) : baseUrl;\n\n return {\n loadPlugin: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = yield* registryService.get(pluginId);\n\n if (entry.constructor) {\n yield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\n return {\n ctor: entry.constructor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }\n\n const url = entry.metadata.remoteUrl;\n if (!url) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"load-plugin\",\n cause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n retryable: false,\n }),\n );\n }\n\n const resolvedUrl = resolveUrl(url);\n\n yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${pluginId} failed during register-remote`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n ),\n );\n\n yield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n const ctor = yield* moduleFederationService\n .loadRemoteConstructor(pluginId, resolvedUrl)\n .pipe(\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${pluginId} failed during load-remote`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n ),\n );\n\n return {\n ctor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }),\n\n instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: LoadedPlugin<T>) =>\n Effect.gen(function* () {\n const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"instantiate-plugin\", false),\n ),\n );\n\n (instance.id as string) = pluginId;\n\n return {\n plugin: instance,\n metadata: loadedPlugin.metadata,\n } satisfies PluginInstance<T>;\n }),\n\n initializePlugin: <T extends AnyPlugin>(\n pluginInstance: PluginInstance<T>,\n config: {\n variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>;\n secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]>;\n },\n plugins?: Record<string, unknown>,\n ) =>\n Effect.gen(function* () {\n const { plugin } = pluginInstance;\n\n // Validate and hydrate config\n const validatedVariables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n config.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Validate secrets\n const validatedSecrets = yield* validate(\n plugin.configSchema.secrets as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>\n >,\n config.secrets,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-secrets\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Hydrate secrets in variables\n const hydratedConfig = yield* secretsService.hydrateSecrets({\n variables: validatedVariables,\n secrets: validatedSecrets,\n });\n\n const _variables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n hydratedConfig.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-hydrated-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Create a long-lived scope for this plugin instance\n const scope = yield* Scope.make();\n\n // Create a per-plugin MemoMap so tool-built layers are memoized\n const memoMap = yield* Layer.makeMemoMap;\n\n const tools: PluginServicesTools = {\n buildService: (tag: any, layer: any) =>\n (Layer.buildWithMemoMap(layer, memoMap, scope) as any).pipe(\n Effect.map((ctx: any) => EffectContext.get(ctx, tag)) as any,\n ),\n };\n\n // Initialize plugin within the scope\n // The plugin's initialize method handles:\n // 1. Building services (DB pools, caches) via tools.buildService\n // 2. Shaping final deps via initialize\n // Any Layer.scoped resources built through tools.buildService are\n // bound to the plugin scope and persist until the plugin is shutdown.\n const context = yield* plugin\n .initialize(\n { variables: _variables, secrets: hydratedConfig.secrets },\n plugins ?? {},\n tools,\n )\n .pipe(\n Effect.provideService(Scope.Scope, scope),\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n ),\n );\n\n return {\n plugin,\n metadata: pluginInstance.metadata,\n config: { variables: _variables, secrets: hydratedConfig.secrets },\n context,\n scope,\n } satisfies InitializedPlugin<T>;\n }),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;;;;AAkBA,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,EACxF,QAAQA,cAAO,IAAI,aAAa;CAC9B,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,OAAO;AAEzB,QAAO;EACL,MAAM,aACJA,cAAO,IAAI,aAAa;GACtB,MAAM,QAAQ,SAAS;AAEvB,OAAI,CAAC,MACH,QAAO,OAAOA,cAAO,KACnB,IAAIC,kCAAmB;IACrB;IACA,WAAW;IACX,uBAAO,IAAI,MAAM,UAAU,SAAS,wBAAwB;IAC5D,WAAW;IACZ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AAO,IACP,SACD,CAAC,KACAL,cAAO,UACJ,oBACC,IAAIC,kCAAmB;IACrB,UAAU,OAAO;IACjB,WAAW;IACX,OAAO,gBAAgB;IACvB,WAAW;IACZ,CAAC,CACL,CACF;GAGD,MAAM,QAAQ,OAAOK,aAAM,MAAM;GAGjC,MAAM,UAAU,OAAOC,aAAM;GAe7B,MAAM,UAAU,OAAO,OACpB,WACC;IAAE,WAAW;IAAY,SAAS,eAAe;IAAS,EAC1D,WAAW,EAAE,EACb,EAhBF,eAAe,KAAU,UACtBA,aAAM,iBAAiB,OAAO,SAAS,MAAM,CAAS,KACrDP,cAAO,KAAK,QAAaQ,eAAc,IAAI,KAAK,IAAI,CAAC,CACtD,EAaI,CACN,CACA,KACCR,cAAO,eAAeM,aAAM,OAAO,MAAM,EACzCN,cAAO,UAAU,WACfA,cAAO,SAAS,UAAU,OAAO,GAAG,kCAAkC,CACvE,EACDA,cAAO,UAAU,UACfI,oCAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC9E,CACF;AAEH,UAAO;IACL;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACD;IACD;EACL;EACD,EACH,CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.cjs","names":["Context","Effect","PluginRuntimeError","ModuleFederationService","SecretsService","toPluginRuntimeError","validate","Scope","Layer","EffectContext"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Context as EffectContext, Layer, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type { PluginServicesTools } from \"../../plugin\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InitializedPlugin,\n LoadedPlugin,\n PluginInstance,\n PluginMetadata,\n PluginRegistry,\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 PluginRegistryTag,\n PluginRegistry\n>() {}\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n PluginMapTag,\n Record<string, AnyPluginConstructor>\n>() {}\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n effect: Effect.gen(function* () {\n const registry = yield* PluginRegistryTag;\n const pluginMap = yield* PluginMapTag;\n\n return {\n get: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = registry[pluginId];\n\n if (!entry) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ${pluginId} not found in registry`),\n retryable: false,\n }),\n );\n }\n\n if (\"module\" in entry) {\n return {\n constructor: entry.module,\n metadata: {\n remoteUrl: entry.remote || \"\",\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }\n\n return {\n constructor: null,\n metadata: {\n remoteUrl: entry.remote,\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }),\n\n getModule: (pluginId: string) => Effect.succeed(pluginMap[pluginId] || null),\n };\n }),\n}) {}\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\n \"PluginLoaderService\",\n {\n effect: Effect.gen(function* () {\n const moduleFederationService = yield* ModuleFederationService;\n const secretsService = yield* SecretsService;\n const registryService = yield* RegistryService;\n\n const resolveUrl = (baseUrl: string, version?: string): string =>\n version && version !== \"latest\" ? baseUrl.replace(\"@latest\", `@${version}`) : baseUrl;\n\n return {\n loadPlugin: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = yield* registryService.get(pluginId);\n\n if (entry.constructor) {\n yield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\n return {\n ctor: entry.constructor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }\n\n const url = entry.metadata.remoteUrl;\n if (!url) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"load-plugin\",\n cause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n retryable: false,\n }),\n );\n }\n\n const resolvedUrl = resolveUrl(url);\n\n yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${pluginId} failed during register-remote: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n ),\n );\n\n yield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n const ctor = yield* moduleFederationService\n .loadRemoteConstructor(pluginId, resolvedUrl)\n .pipe(\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${pluginId} failed during load-remote: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n ),\n );\n\n return {\n ctor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }),\n\n instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: LoadedPlugin<T>) =>\n Effect.gen(function* () {\n const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"instantiate-plugin\", false),\n ),\n );\n\n (instance.id as string) = pluginId;\n\n return {\n plugin: instance,\n metadata: loadedPlugin.metadata,\n } satisfies PluginInstance<T>;\n }),\n\n initializePlugin: <T extends AnyPlugin>(\n pluginInstance: PluginInstance<T>,\n config: {\n variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>;\n secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]>;\n },\n plugins?: Record<string, unknown>,\n ) =>\n Effect.gen(function* () {\n const { plugin } = pluginInstance;\n\n // Validate and hydrate config\n const validatedVariables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n config.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Validate secrets\n const validatedSecrets = yield* validate(\n plugin.configSchema.secrets as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>\n >,\n config.secrets,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-secrets\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Hydrate secrets in variables\n const hydratedConfig = yield* secretsService.hydrateSecrets({\n variables: validatedVariables,\n secrets: validatedSecrets,\n });\n\n const _variables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n hydratedConfig.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-hydrated-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Create a long-lived scope for this plugin instance\n const scope = yield* Scope.make();\n\n // Create a per-plugin MemoMap so tool-built layers are memoized\n const memoMap = yield* Layer.makeMemoMap;\n\n const tools: PluginServicesTools = {\n buildService: (tag: any, layer: any) =>\n (Layer.buildWithMemoMap(layer, memoMap, scope) as any).pipe(\n Effect.map((ctx: any) => EffectContext.get(ctx, tag)) as any,\n ),\n };\n\n // Initialize plugin within the scope\n // The plugin's initialize method handles:\n // 1. Building services (DB pools, caches) via tools.buildService\n // 2. Shaping final deps via initialize\n // Any Layer.scoped resources built through tools.buildService are\n // bound to the plugin scope and persist until the plugin is shutdown.\n const context = yield* plugin\n .initialize(\n { variables: _variables, secrets: hydratedConfig.secrets },\n plugins ?? {},\n tools,\n )\n .pipe(\n Effect.provideService(Scope.Scope, scope),\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n ),\n );\n\n return {\n plugin,\n metadata: pluginInstance.metadata,\n config: { variables: _variables, secrets: hydratedConfig.secrets },\n context,\n scope,\n } satisfies InitializedPlugin<T>;\n }),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;;;;AAkBA,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,EACxF,QAAQA,cAAO,IAAI,aAAa;CAC9B,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,OAAO;AAEzB,QAAO;EACL,MAAM,aACJA,cAAO,IAAI,aAAa;GACtB,MAAM,QAAQ,SAAS;AAEvB,OAAI,CAAC,MACH,QAAO,OAAOA,cAAO,KACnB,IAAIC,kCAAmB;IACrB;IACA,WAAW;IACX,uBAAO,IAAI,MAAM,UAAU,SAAS,wBAAwB;IAC5D,WAAW;IACZ,CAAC,CACH;AAGH,OAAI,YAAY,MACd,QAAO;IACL,aAAa,MAAM;IACnB,UAAU;KACR,WAAW,MAAM,UAAU;KAC3B,SAAS,MAAM;KACf,aAAa,MAAM;KACpB;IACF;AAGH,UAAO;IACL,aAAa;IACb,UAAU;KACR,WAAW,MAAM;KACjB,SAAS,MAAM;KACf,aAAa,MAAM;KACpB;IACF;IACD;EAEJ,YAAY,aAAqBD,cAAO,QAAQ,UAAU,aAAa,KAAK;EAC7E;EACD,EACH,CAAC,CAAC;AAEH,IAAa,sBAAb,cAAyCA,cAAO,SAA8B,CAC5E,uBACA,EACE,QAAQA,cAAO,IAAI,aA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P,cAAO,KAAK,QAAaQ,eAAc,IAAI,KAAK,IAAI,CAAC,CACtD,EAaI,CACN,CACA,KACCR,cAAO,eAAeM,aAAM,OAAO,MAAM,EACzCN,cAAO,UAAU,UACfA,cAAO,SAAS,UAAU,OAAO,GAAG,oCAAoC,QAAQ,CACjF,EACDA,cAAO,UAAU,UACfI,oCAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC9E,CACF;AAEH,UAAO;IACL;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACD;IACD;EACL;EACD,EACH,CACF,CAAC"}
|
|
@@ -62,18 +62,18 @@ var PluginLoaderService = class extends Effect.Service()("PluginLoaderService",
|
|
|
62
62
|
retryable: false
|
|
63
63
|
}));
|
|
64
64
|
const resolvedUrl = resolveUrl(url);
|
|
65
|
-
yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(Effect.tapError((
|
|
65
|
+
yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(Effect.tapError((error) => Effect.logError(`Plugin ${pluginId} failed during register-remote: ${error}`)), Effect.mapError((error) => toPluginRuntimeError(error, pluginId, void 0, "register-remote", true)));
|
|
66
66
|
yield* Effect.logDebug("Loading plugin from remote", {
|
|
67
67
|
pluginId,
|
|
68
68
|
url: resolvedUrl
|
|
69
69
|
});
|
|
70
70
|
return {
|
|
71
|
-
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(Effect.tapError((
|
|
71
|
+
ctor: yield* moduleFederationService.loadRemoteConstructor(pluginId, resolvedUrl).pipe(Effect.tapError((error) => Effect.logError(`Plugin ${pluginId} failed during load-remote: ${error}`)), Effect.mapError((error) => toPluginRuntimeError(error, pluginId, void 0, "load-remote", false))),
|
|
72
72
|
metadata: entry.metadata
|
|
73
73
|
};
|
|
74
74
|
}),
|
|
75
75
|
instantiatePlugin: (pluginId, loadedPlugin) => Effect.gen(function* () {
|
|
76
|
-
const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(Effect.tapError((
|
|
76
|
+
const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(Effect.tapError((error) => Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin: ${error}`)), Effect.mapError((error) => toPluginRuntimeError(error, pluginId, void 0, "instantiate-plugin", false)));
|
|
77
77
|
instance.id = pluginId;
|
|
78
78
|
return {
|
|
79
79
|
plugin: instance,
|
|
@@ -109,7 +109,7 @@ var PluginLoaderService = class extends Effect.Service()("PluginLoaderService",
|
|
|
109
109
|
const context = yield* plugin.initialize({
|
|
110
110
|
variables: _variables,
|
|
111
111
|
secrets: hydratedConfig.secrets
|
|
112
|
-
}, plugins ?? {}, { buildService: (tag, layer) => Layer.buildWithMemoMap(layer, memoMap, scope).pipe(Effect.map((ctx) => Context.get(ctx, tag))) }).pipe(Effect.provideService(Scope.Scope, scope), Effect.tapError((
|
|
112
|
+
}, plugins ?? {}, { buildService: (tag, layer) => Layer.buildWithMemoMap(layer, memoMap, scope).pipe(Effect.map((ctx) => Context.get(ctx, tag))) }).pipe(Effect.provideService(Scope.Scope, scope), Effect.tapError((error) => Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin: ${error}`)), Effect.mapError((error) => toPluginRuntimeError(error, plugin.id, void 0, "initialize-plugin", false)));
|
|
113
113
|
return {
|
|
114
114
|
plugin,
|
|
115
115
|
metadata: pluginInstance.metadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.mjs","names":["EffectContext"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Context as EffectContext, Layer, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type { PluginServicesTools } from \"../../plugin\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InitializedPlugin,\n LoadedPlugin,\n PluginInstance,\n PluginMetadata,\n PluginRegistry,\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 PluginRegistryTag,\n PluginRegistry\n>() {}\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n PluginMapTag,\n Record<string, AnyPluginConstructor>\n>() {}\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n effect: Effect.gen(function* () {\n const registry = yield* PluginRegistryTag;\n const pluginMap = yield* PluginMapTag;\n\n return {\n get: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = registry[pluginId];\n\n if (!entry) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ${pluginId} not found in registry`),\n retryable: false,\n }),\n );\n }\n\n if (\"module\" in entry) {\n return {\n constructor: entry.module,\n metadata: {\n remoteUrl: entry.remote || \"\",\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }\n\n return {\n constructor: null,\n metadata: {\n remoteUrl: entry.remote,\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }),\n\n getModule: (pluginId: string) => Effect.succeed(pluginMap[pluginId] || null),\n };\n }),\n}) {}\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\n \"PluginLoaderService\",\n {\n effect: Effect.gen(function* () {\n const moduleFederationService = yield* ModuleFederationService;\n const secretsService = yield* SecretsService;\n const registryService = yield* RegistryService;\n\n const resolveUrl = (baseUrl: string, version?: string): string =>\n version && version !== \"latest\" ? baseUrl.replace(\"@latest\", `@${version}`) : baseUrl;\n\n return {\n loadPlugin: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = yield* registryService.get(pluginId);\n\n if (entry.constructor) {\n yield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\n return {\n ctor: entry.constructor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }\n\n const url = entry.metadata.remoteUrl;\n if (!url) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"load-plugin\",\n cause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n retryable: false,\n }),\n );\n }\n\n const resolvedUrl = resolveUrl(url);\n\n yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${pluginId} failed during register-remote`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n ),\n );\n\n yield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n const ctor = yield* moduleFederationService\n .loadRemoteConstructor(pluginId, resolvedUrl)\n .pipe(\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${pluginId} failed during load-remote`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n ),\n );\n\n return {\n ctor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }),\n\n instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: LoadedPlugin<T>) =>\n Effect.gen(function* () {\n const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"instantiate-plugin\", false),\n ),\n );\n\n (instance.id as string) = pluginId;\n\n return {\n plugin: instance,\n metadata: loadedPlugin.metadata,\n } satisfies PluginInstance<T>;\n }),\n\n initializePlugin: <T extends AnyPlugin>(\n pluginInstance: PluginInstance<T>,\n config: {\n variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>;\n secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]>;\n },\n plugins?: Record<string, unknown>,\n ) =>\n Effect.gen(function* () {\n const { plugin } = pluginInstance;\n\n // Validate and hydrate config\n const validatedVariables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n config.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Validate secrets\n const validatedSecrets = yield* validate(\n plugin.configSchema.secrets as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>\n >,\n config.secrets,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-secrets\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Hydrate secrets in variables\n const hydratedConfig = yield* secretsService.hydrateSecrets({\n variables: validatedVariables,\n secrets: validatedSecrets,\n });\n\n const _variables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n hydratedConfig.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-hydrated-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Create a long-lived scope for this plugin instance\n const scope = yield* Scope.make();\n\n // Create a per-plugin MemoMap so tool-built layers are memoized\n const memoMap = yield* Layer.makeMemoMap;\n\n const tools: PluginServicesTools = {\n buildService: (tag: any, layer: any) =>\n (Layer.buildWithMemoMap(layer, memoMap, scope) as any).pipe(\n Effect.map((ctx: any) => EffectContext.get(ctx, tag)) as any,\n ),\n };\n\n // Initialize plugin within the scope\n // The plugin's initialize method handles:\n // 1. Building services (DB pools, caches) via tools.buildService\n // 2. Shaping final deps via initialize\n // Any Layer.scoped resources built through tools.buildService are\n // bound to the plugin scope and persist until the plugin is shutdown.\n const context = yield* plugin\n .initialize(\n { variables: _variables, secrets: hydratedConfig.secrets },\n plugins ?? {},\n tools,\n )\n .pipe(\n Effect.provideService(Scope.Scope, scope),\n Effect.tapError((_error) =>\n Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n ),\n );\n\n return {\n plugin,\n metadata: pluginInstance.metadata,\n config: { variables: _variables, secrets: hydratedConfig.secrets },\n context,\n scope,\n } satisfies InitializedPlugin<T>;\n }),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;;;AAkBA,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,EACxF,QAAQ,OAAO,IAAI,aAAa;CAC9B,MAAM,WAAW,OAAO;CACxB,MAAM,YAAY,OAAO;AAEzB,QAAO;EACL,MAAM,aACJ,OAAO,IAAI,aAAa;GACtB,MAAM,QAAQ,SAAS;AAEvB,OAAI,CAAC,MACH,QAAO,OAAO,OAAO,KACnB,IAAI,mBAAmB;IACrB;IACA,WAAW;IACX,uBAAO,IAAI,MAAM,UAAU,SAAS,wBAAwB;IAC5D,WAAW;IACZ,CAAC,CACH;AAGH,OAAI,YAAY,MACd,QAAO;IACL,aAAa,MAAM;IACnB,UAAU;KACR,WAAW,MAAM,UAAU;KAC3B,SAAS,MAAM;KACf,aAAa,MAAM;KACpB;IACF;AAGH,UAAO;IACL,aAAa;IACb,UAAU;KACR,WAAW,MAAM;KACjB,SAAS,MAAM;KACf,aAAa,MAAM;KACpB;IACF;IACD;EAEJ,YAAY,aAAqB,OAAO,QAAQ,UAAU,aAAa,KAAK;EAC7E;EACD,EACH,CAAC,CAAC;AAEH,IAAa,sBAAb,cAAyC,OAAO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Ac,IAAI,KAAK,IAAI,CAAC,CACtD,EAaI,CACN,CACA,KACC,OAAO,eAAe,MAAM,OAAO,MAAM,EACzC,OAAO,UAAU,WACf,OAAO,SAAS,UAAU,OAAO,GAAG,kCAAkC,CACvE,EACD,OAAO,UAAU,UACf,qBAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC9E,CACF;AAEH,UAAO;IACL;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACD;IACD;EACL;EACD,EACH,CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.mjs","names":["EffectContext"],"sources":["../../../src/runtime/services/plugin-loader.service.ts"],"sourcesContent":["import type { InferSchemaInput, InferSchemaOutput } from \"@orpc/contract\";\nimport { Context, Effect, Context as EffectContext, Layer, Scope } from \"effect\";\nimport type { z } from \"zod\";\nimport type { PluginServicesTools } from \"../../plugin\";\nimport type {\n AnyPlugin,\n AnyPluginConstructor,\n InitializedPlugin,\n LoadedPlugin,\n PluginInstance,\n PluginMetadata,\n PluginRegistry,\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 PluginRegistryTag,\n PluginRegistry\n>() {}\n\nexport class PluginMapTag extends Context.Tag(\"PluginMap\")<\n PluginMapTag,\n Record<string, AnyPluginConstructor>\n>() {}\n\nexport class RegistryService extends Effect.Service<RegistryService>()(\"RegistryService\", {\n effect: Effect.gen(function* () {\n const registry = yield* PluginRegistryTag;\n const pluginMap = yield* PluginMapTag;\n\n return {\n get: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = registry[pluginId];\n\n if (!entry) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"validate-plugin-id\",\n cause: new Error(`Plugin ${pluginId} not found in registry`),\n retryable: false,\n }),\n );\n }\n\n if (\"module\" in entry) {\n return {\n constructor: entry.module,\n metadata: {\n remoteUrl: entry.remote || \"\",\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }\n\n return {\n constructor: null,\n metadata: {\n remoteUrl: entry.remote,\n version: entry.version,\n description: entry.description,\n } as PluginMetadata,\n };\n }),\n\n getModule: (pluginId: string) => Effect.succeed(pluginMap[pluginId] || null),\n };\n }),\n}) {}\n\nexport class PluginLoaderService extends Effect.Service<PluginLoaderService>()(\n \"PluginLoaderService\",\n {\n effect: Effect.gen(function* () {\n const moduleFederationService = yield* ModuleFederationService;\n const secretsService = yield* SecretsService;\n const registryService = yield* RegistryService;\n\n const resolveUrl = (baseUrl: string, version?: string): string =>\n version && version !== \"latest\" ? baseUrl.replace(\"@latest\", `@${version}`) : baseUrl;\n\n return {\n loadPlugin: (pluginId: string) =>\n Effect.gen(function* () {\n const entry = yield* registryService.get(pluginId);\n\n if (entry.constructor) {\n yield* Effect.logDebug(\"Loading plugin from direct module\", { pluginId });\n\n return {\n ctor: entry.constructor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }\n\n const url = entry.metadata.remoteUrl;\n if (!url) {\n return yield* Effect.fail(\n new PluginRuntimeError({\n pluginId,\n operation: \"load-plugin\",\n cause: new Error(`Plugin ${pluginId} has no module or remote URL configured`),\n retryable: false,\n }),\n );\n }\n\n const resolvedUrl = resolveUrl(url);\n\n yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${pluginId} failed during register-remote: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"register-remote\", true),\n ),\n );\n\n yield* Effect.logDebug(\"Loading plugin from remote\", { pluginId, url: resolvedUrl });\n\n const ctor = yield* moduleFederationService\n .loadRemoteConstructor(pluginId, resolvedUrl)\n .pipe(\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${pluginId} failed during load-remote: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"load-remote\", false),\n ),\n );\n\n return {\n ctor,\n metadata: entry.metadata,\n } satisfies LoadedPlugin;\n }),\n\n instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: LoadedPlugin<T>) =>\n Effect.gen(function* () {\n const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, pluginId, undefined, \"instantiate-plugin\", false),\n ),\n );\n\n (instance.id as string) = pluginId;\n\n return {\n plugin: instance,\n metadata: loadedPlugin.metadata,\n } satisfies PluginInstance<T>;\n }),\n\n initializePlugin: <T extends AnyPlugin>(\n pluginInstance: PluginInstance<T>,\n config: {\n variables: InferSchemaInput<T[\"configSchema\"][\"variables\"]>;\n secrets: InferSchemaInput<T[\"configSchema\"][\"secrets\"]>;\n },\n plugins?: Record<string, unknown>,\n ) =>\n Effect.gen(function* () {\n const { plugin } = pluginInstance;\n\n // Validate and hydrate config\n const validatedVariables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n config.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Validate secrets\n const validatedSecrets = yield* validate(\n plugin.configSchema.secrets as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"secrets\"]>\n >,\n config.secrets,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-secrets\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Hydrate secrets in variables\n const hydratedConfig = yield* secretsService.hydrateSecrets({\n variables: validatedVariables,\n secrets: validatedSecrets,\n });\n\n const _variables = yield* validate(\n plugin.configSchema.variables as z.ZodSchema<\n InferSchemaOutput<T[\"configSchema\"][\"variables\"]>\n >,\n hydratedConfig.variables,\n plugin.id,\n \"config\",\n ).pipe(\n Effect.mapError(\n (validationError) =>\n new PluginRuntimeError({\n pluginId: plugin.id,\n operation: \"validate-hydrated-config\",\n cause: validationError.zodError,\n retryable: false,\n }),\n ),\n );\n\n // Create a long-lived scope for this plugin instance\n const scope = yield* Scope.make();\n\n // Create a per-plugin MemoMap so tool-built layers are memoized\n const memoMap = yield* Layer.makeMemoMap;\n\n const tools: PluginServicesTools = {\n buildService: (tag: any, layer: any) =>\n (Layer.buildWithMemoMap(layer, memoMap, scope) as any).pipe(\n Effect.map((ctx: any) => EffectContext.get(ctx, tag)) as any,\n ),\n };\n\n // Initialize plugin within the scope\n // The plugin's initialize method handles:\n // 1. Building services (DB pools, caches) via tools.buildService\n // 2. Shaping final deps via initialize\n // Any Layer.scoped resources built through tools.buildService are\n // bound to the plugin scope and persist until the plugin is shutdown.\n const context = yield* plugin\n .initialize(\n { variables: _variables, secrets: hydratedConfig.secrets },\n plugins ?? {},\n tools,\n )\n .pipe(\n Effect.provideService(Scope.Scope, scope),\n Effect.tapError((error) =>\n Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin: ${error}`),\n ),\n Effect.mapError((error) =>\n toPluginRuntimeError(error, plugin.id, undefined, \"initialize-plugin\", false),\n ),\n );\n\n return {\n plugin,\n metadata: pluginInstance.metadata,\n config: { variables: _variables, secrets: hydratedConfig.secrets },\n context,\n scope,\n } satisfies InitializedPlugin<T>;\n }),\n };\n }),\n },\n) {}\n"],"mappings":";;;;;;;AAkBA,IAAa,oBAAb,cAAuC,QAAQ,IAAI,iBAAiB,EAGjE,CAAC;AAEJ,IAAa,eAAb,cAAkC,QAAQ,IAAI,YAAY,EAGvD,CAAC;AAEJ,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mB,OAAO,SAC9B,OAAO,aAAa,SAGpB,OAAO,SACP,OAAO,IACP,SACD,CAAC,KACA,OAAO,UACJ,oBACC,IAAI,mBAAmB;IACrB,UAAU,OAAO;IACjB,WAAW;IACX,OAAO,gBAAgB;IACvB,WAAW;IACZ,CAAC,CACL,CACF;GAGD,MAAM,iBAAiB,OAAO,eAAe,eAAe;IAC1D,WAAW;IACX,SAAS;IACV,CAAC;GAEF,MAAM,aAAa,OAAO,SACxB,OAAO,aAAa,WAGpB,eAAe,WACf,OAAO,IACP,SACD,CAAC,KACA,OAAO,UACJ,oBACC,IAAI,mBAAmB;IACrB,UAAU,OAAO;IACjB,WAAW;IACX,OAAO,gBAAgB;IACvB,WAAW;IACZ,CAAC,CACL,CACF;GAGD,MAAM,QAAQ,OAAO,MAAM,MAAM;GAGjC,MAAM,UAAU,OAAO,MAAM;GAe7B,MAAM,UAAU,OAAO,OACpB,WACC;IAAE,WAAW;IAAY,SAAS,eAAe;IAAS,EAC1D,WAAW,EAAE,EACb,EAhBF,eAAe,KAAU,UACtB,MAAM,iBAAiB,OAAO,SAAS,MAAM,CAAS,KACrD,OAAO,KAAK,QAAaA,QAAc,IAAI,KAAK,IAAI,CAAC,CACtD,EAaI,CACN,CACA,KACC,OAAO,eAAe,MAAM,OAAO,MAAM,EACzC,OAAO,UAAU,UACf,OAAO,SAAS,UAAU,OAAO,GAAG,oCAAoC,QAAQ,CACjF,EACD,OAAO,UAAU,UACf,qBAAqB,OAAO,OAAO,IAAI,QAAW,qBAAqB,MAAM,CAC9E,CACF;AAEH,UAAO;IACL;IACA,UAAU,eAAe;IACzB,QAAQ;KAAE,WAAW;KAAY,SAAS,eAAe;KAAS;IAClE;IACA;IACD;IACD;EACL;EACD,EACH,CACF,CAAC"}
|
package/package.json
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -51,7 +51,7 @@ type PluginDefinition<
|
|
|
51
51
|
initialize?: (
|
|
52
52
|
config: PluginInitializeInput<V, S>,
|
|
53
53
|
plugins: P,
|
|
54
|
-
tools
|
|
54
|
+
tools: PluginServicesTools,
|
|
55
55
|
) => Effect.Effect<TDeps, Error, Scope.Scope>;
|
|
56
56
|
createRouter: (
|
|
57
57
|
deps: TDeps,
|
|
@@ -96,7 +96,7 @@ export interface Plugin<
|
|
|
96
96
|
initialize(
|
|
97
97
|
config: PluginInitializeInput<TVariables, TSecrets>,
|
|
98
98
|
plugins: Record<string, unknown>,
|
|
99
|
-
tools
|
|
99
|
+
tools: PluginServicesTools,
|
|
100
100
|
): Effect.Effect<TDeps, unknown, Scope.Scope>;
|
|
101
101
|
|
|
102
102
|
shutdown(): Effect.Effect<void, never>;
|
|
@@ -150,7 +150,7 @@ export const createPlugin: CreatePluginFn = function createPlugin<
|
|
|
150
150
|
initialize(
|
|
151
151
|
pluginConfig: PluginInitializeInput<V, S>,
|
|
152
152
|
plugins: Record<string, unknown> = {},
|
|
153
|
-
tools
|
|
153
|
+
tools: PluginServicesTools,
|
|
154
154
|
): Effect.Effect<TDeps, unknown, Scope.Scope> {
|
|
155
155
|
const init = config.initialize ?? (() => Effect.succeed({} as TDeps));
|
|
156
156
|
|
|
@@ -113,8 +113,8 @@ export class PluginLoaderService extends Effect.Service<PluginLoaderService>()(
|
|
|
113
113
|
const resolvedUrl = resolveUrl(url);
|
|
114
114
|
|
|
115
115
|
yield* moduleFederationService.registerRemote(pluginId, resolvedUrl).pipe(
|
|
116
|
-
Effect.tapError((
|
|
117
|
-
Effect.logError(`Plugin ${pluginId} failed during register-remote`),
|
|
116
|
+
Effect.tapError((error) =>
|
|
117
|
+
Effect.logError(`Plugin ${pluginId} failed during register-remote: ${error}`),
|
|
118
118
|
),
|
|
119
119
|
Effect.mapError((error) =>
|
|
120
120
|
toPluginRuntimeError(error, pluginId, undefined, "register-remote", true),
|
|
@@ -126,8 +126,8 @@ export class PluginLoaderService extends Effect.Service<PluginLoaderService>()(
|
|
|
126
126
|
const ctor = yield* moduleFederationService
|
|
127
127
|
.loadRemoteConstructor(pluginId, resolvedUrl)
|
|
128
128
|
.pipe(
|
|
129
|
-
Effect.tapError((
|
|
130
|
-
Effect.logError(`Plugin ${pluginId} failed during load-remote`),
|
|
129
|
+
Effect.tapError((error) =>
|
|
130
|
+
Effect.logError(`Plugin ${pluginId} failed during load-remote: ${error}`),
|
|
131
131
|
),
|
|
132
132
|
Effect.mapError((error) =>
|
|
133
133
|
toPluginRuntimeError(error, pluginId, undefined, "load-remote", false),
|
|
@@ -143,8 +143,8 @@ export class PluginLoaderService extends Effect.Service<PluginLoaderService>()(
|
|
|
143
143
|
instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: LoadedPlugin<T>) =>
|
|
144
144
|
Effect.gen(function* () {
|
|
145
145
|
const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(
|
|
146
|
-
Effect.tapError((
|
|
147
|
-
Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin`),
|
|
146
|
+
Effect.tapError((error) =>
|
|
147
|
+
Effect.logError(`Plugin ${pluginId} failed during instantiate-plugin: ${error}`),
|
|
148
148
|
),
|
|
149
149
|
Effect.mapError((error) =>
|
|
150
150
|
toPluginRuntimeError(error, pluginId, undefined, "instantiate-plugin", false),
|
|
@@ -262,8 +262,8 @@ export class PluginLoaderService extends Effect.Service<PluginLoaderService>()(
|
|
|
262
262
|
)
|
|
263
263
|
.pipe(
|
|
264
264
|
Effect.provideService(Scope.Scope, scope),
|
|
265
|
-
Effect.tapError((
|
|
266
|
-
Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin`),
|
|
265
|
+
Effect.tapError((error) =>
|
|
266
|
+
Effect.logError(`Plugin ${plugin.id} failed during initialize-plugin: ${error}`),
|
|
267
267
|
),
|
|
268
268
|
Effect.mapError((error) =>
|
|
269
269
|
toPluginRuntimeError(error, plugin.id, undefined, "initialize-plugin", false),
|