every-plugin 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/plugin.d.ts +0 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +0 -1
- package/dist/runtime/index.d.ts +15 -35
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +55 -68
- package/dist/runtime/services/module-federation.service.d.ts +7 -11
- package/dist/runtime/services/module-federation.service.d.ts.map +1 -1
- package/dist/runtime/services/module-federation.service.js +7 -9
- package/dist/runtime/services/plugin-lifecycle.service.d.ts +9 -12
- package/dist/runtime/services/plugin-lifecycle.service.d.ts.map +1 -1
- package/dist/runtime/services/plugin-lifecycle.service.js +5 -6
- package/dist/runtime/services/plugin-loader.service.d.ts +50 -13
- package/dist/runtime/services/plugin-loader.service.d.ts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.js +25 -15
- package/dist/runtime/services/plugin.service.d.ts +41 -17
- package/dist/runtime/services/plugin.service.d.ts.map +1 -1
- package/dist/runtime/services/plugin.service.js +13 -7
- package/dist/runtime/services/secrets.service.d.ts +8 -9
- package/dist/runtime/services/secrets.service.d.ts.map +1 -1
- package/dist/runtime/services/secrets.service.js +28 -27
- package/dist/runtime/services.d.ts +3 -1
- package/dist/runtime/services.d.ts.map +1 -1
- package/dist/runtime/services.js +3 -1
- package/dist/testing/index.d.ts +45 -12
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +34 -27
- package/dist/testing/mocks/module-federation.service.d.ts +3 -5
- package/dist/testing/mocks/module-federation.service.d.ts.map +1 -1
- package/dist/testing/mocks/module-federation.service.js +18 -24
- package/dist/types.d.ts +21 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ export * from "./errors";
|
|
|
2
2
|
export * from "./plugin";
|
|
3
3
|
export * from "./runtime";
|
|
4
4
|
export { getNormalizedRemoteName } from "./runtime/services/normalize";
|
|
5
|
-
export type { AnyPlugin, ConfigOf, InitializedPlugin, PluginConstructor, PluginInstance, PluginOf, PluginRegistry, PluginRegistryFor, PluginRuntimeConfig, RegistryBindings, RouterOf, SecretsConfig } from "./types";
|
|
5
|
+
export type { AnyPlugin, ConfigOf, InitializedPlugin, EveryPlugin, PluginConstructor, PluginInstance, PluginOf, PluginRegistry, PluginRegistryFor, PluginRuntimeConfig, RegistryBindings, RouterOf, SecretsConfig } from "./types";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAG1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,YAAY,EACX,SAAS,EACT,QAAQ,EACR,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAG1B,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,YAAY,EACX,SAAS,EACT,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,MAAM,SAAS,CAAC"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -92,7 +92,6 @@ export declare const CommonPluginErrors: {
|
|
|
92
92
|
*/
|
|
93
93
|
export interface Plugin<TContract extends AnyContractRouter, TVariables extends z.ZodTypeAny, TSecrets extends z.ZodTypeAny, TContext extends Context = Record<never, never>> {
|
|
94
94
|
readonly id: string;
|
|
95
|
-
readonly type: string;
|
|
96
95
|
readonly contract: TContract;
|
|
97
96
|
readonly configSchema: PluginConfigFor<TVariables, TSecrets>;
|
|
98
97
|
initialize(config: {
|
|
@@ -113,7 +112,6 @@ export interface Plugin<TContract extends AnyContractRouter, TVariables extends
|
|
|
113
112
|
*/
|
|
114
113
|
export declare function createPlugin<V extends z.ZodTypeAny, S extends z.ZodTypeAny, TContract extends AnyContractRouter, TContext extends Context = Record<never, never>>(config: {
|
|
115
114
|
id: string;
|
|
116
|
-
type?: string;
|
|
117
115
|
variables: V;
|
|
118
116
|
secrets: S;
|
|
119
117
|
contract: TContract;
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,KAAK,kBAAkB,CAAC,CAAC,SAAS,iBAAiB,EAAE,QAAQ,SAAS,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AAE5H;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC,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,CAAC,CAAC;QAAC,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KAAE,KAClD,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACjD,YAAY,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,kBAAkB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACzE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CAChE,GAsD4B,4BAA4B,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CACnF"}
|
package/dist/plugin.js
CHANGED
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,46 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ManagedRuntime } from "effect";
|
|
2
2
|
import type { z } from "zod";
|
|
3
|
-
import type { InitializedPlugin, PluginConstructor, PluginInstance, PluginOf, PluginRegistry,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readonly loadPlugin: <K extends keyof R>(pluginId: K) => Effect.Effect<PluginConstructor<PluginOf<R[K]>>, PluginRuntimeError>;
|
|
8
|
-
readonly instantiatePlugin: <K extends keyof R>(ctor: PluginConstructor<PluginOf<R[K]>>) => Effect.Effect<PluginInstance<PluginOf<R[K]>>, PluginRuntimeError>;
|
|
9
|
-
readonly initializePlugin: <K extends keyof R>(instance: PluginInstance<PluginOf<R[K]>>, config: z.infer<PluginOf<R[K]>["configSchema"]>) => Effect.Effect<InitializedPlugin<PluginOf<R[K]>>, PluginRuntimeError>;
|
|
10
|
-
readonly usePlugin: <K extends keyof R>(pluginId: K, config: z.infer<PluginOf<R[K]>["configSchema"]>) => Effect.Effect<PluginResult<PluginOf<R[K]>>, PluginRuntimeError>;
|
|
11
|
-
readonly shutdown: () => Effect.Effect<void, never, never>;
|
|
12
|
-
}
|
|
13
|
-
export declare class PluginRuntimeImpl<R extends RegistryBindings = RegistryBindings> implements IPluginRuntime<R> {
|
|
14
|
-
private pluginService;
|
|
3
|
+
import type { EveryPlugin, InitializedPlugin, PluginConstructor, PluginInstance, PluginOf, PluginRegistry, RegistryBindings, RuntimeOptions, SecretsConfig } from "../types";
|
|
4
|
+
import { PluginService } from "./services/plugin.service";
|
|
5
|
+
export declare class PluginRuntime<R extends RegistryBindings = RegistryBindings> {
|
|
6
|
+
private runtime;
|
|
15
7
|
private registry;
|
|
16
8
|
private pluginCache;
|
|
17
|
-
constructor(
|
|
9
|
+
constructor(runtime: ManagedRuntime.ManagedRuntime<PluginService, never>, registry: PluginRegistry);
|
|
18
10
|
private generateCacheKey;
|
|
19
11
|
private validatePluginId;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
evictPlugin<K extends keyof R>(pluginId: K, config: z.infer<PluginOf<R[K]>["configSchema"]>): Effect.Effect<void, never>;
|
|
29
|
-
}
|
|
30
|
-
declare const PluginRuntimeService_base: Context.TagClass<PluginRuntimeService, "PluginRuntimeService", IPluginService>;
|
|
31
|
-
export declare class PluginRuntimeService extends PluginRuntimeService_base {
|
|
32
|
-
static Live: <R extends RegistryBindings = RegistryBindings>(config: PluginRuntimeConfig<R>) => Layer.Layer<PluginRuntimeService, never, never>;
|
|
12
|
+
private runPromise;
|
|
13
|
+
loadPlugin<K extends keyof R>(pluginId: K): Promise<PluginConstructor<PluginOf<R[K]>>>;
|
|
14
|
+
instantiatePlugin<K extends keyof R>(ctor: PluginConstructor<PluginOf<R[K]>>): Promise<PluginInstance<PluginOf<R[K]>>>;
|
|
15
|
+
initializePlugin<K extends keyof R>(instance: PluginInstance<PluginOf<R[K]>>, config: z.infer<PluginOf<R[K]>["configSchema"]>): Promise<InitializedPlugin<PluginOf<R[K]>>>;
|
|
16
|
+
usePlugin<K extends keyof R>(pluginId: K, config: z.infer<PluginOf<R[K]>["configSchema"]>): Promise<EveryPlugin<PluginOf<R[K]>>>;
|
|
17
|
+
shutdown(): Promise<void>;
|
|
18
|
+
evictPlugin<K extends keyof R>(pluginId: K, config: z.infer<PluginOf<R[K]>["configSchema"]>): Promise<void>;
|
|
33
19
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Creates a typed plugin runtime with compile-time registry key validation.
|
|
36
|
-
*/
|
|
37
20
|
export declare function createPluginRuntime<R extends RegistryBindings = RegistryBindings>(config: {
|
|
38
21
|
registry: PluginRegistry;
|
|
39
22
|
secrets?: SecretsConfig;
|
|
40
23
|
options?: RuntimeOptions;
|
|
41
|
-
}):
|
|
42
|
-
|
|
43
|
-
PluginRuntime: Effect.Effect<PluginRuntimeImpl<R>, never, never>;
|
|
44
|
-
};
|
|
45
|
-
export type { ConfigOf, InitializedPlugin, PluginOf, PluginResult, RegistryBindings } from "../types";
|
|
24
|
+
}): PluginRuntime<R>;
|
|
25
|
+
export type { ConfigOf, EveryPlugin, InitializedPlugin, PluginOf, RegistryBindings } from "../types";
|
|
46
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,cAAc,EAAU,MAAM,QAAQ,CAAC;AAClF,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAEX,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,aAAa,EAAE,MAAM,2B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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAoCvC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAQzB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,EAC5B,QAAQ,EAAE,CAAC,EACX,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC;CAwBhB;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,gBAAgB,GAAG,gBAAgB,EAChF,MAAM,EAAE;IAAE,QAAQ,EAAE,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,GACrF,aAAa,CAAC,CAAC,CAAC,CAQlB;AAED,YAAY,EACX,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,gBAAgB,EAChB,MAAM,UAAU,CAAC"}
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cause, Effect, Exit, Hash, ManagedRuntime, Option } from "effect";
|
|
2
2
|
import { createPluginClient, getPluginRouter } from "../client/index";
|
|
3
3
|
import { PluginRuntimeError } from "./errors";
|
|
4
|
-
import { SecretsService } from "./services";
|
|
5
|
-
import { ModuleFederationService } from "./services/module-federation.service";
|
|
6
4
|
import { PluginService } from "./services/plugin.service";
|
|
7
|
-
export class
|
|
8
|
-
|
|
5
|
+
export class PluginRuntime {
|
|
6
|
+
runtime;
|
|
9
7
|
registry;
|
|
10
8
|
pluginCache = new Map();
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
9
|
+
constructor(runtime, registry) {
|
|
10
|
+
this.runtime = runtime;
|
|
13
11
|
this.registry = registry;
|
|
14
12
|
}
|
|
15
13
|
generateCacheKey(pluginId, config) {
|
|
@@ -18,7 +16,6 @@ export class PluginRuntimeImpl {
|
|
|
18
16
|
}
|
|
19
17
|
validatePluginId(pluginId) {
|
|
20
18
|
const pluginIdStr = pluginId;
|
|
21
|
-
// Runtime validation against registry
|
|
22
19
|
if (!(pluginIdStr in this.registry)) {
|
|
23
20
|
return Effect.fail(new PluginRuntimeError({
|
|
24
21
|
pluginId: pluginIdStr,
|
|
@@ -29,39 +26,54 @@ export class PluginRuntimeImpl {
|
|
|
29
26
|
}
|
|
30
27
|
return Effect.succeed(pluginIdStr);
|
|
31
28
|
}
|
|
29
|
+
async runPromise(effect) {
|
|
30
|
+
const exit = await this.runtime.runPromiseExit(effect);
|
|
31
|
+
if (Exit.isFailure(exit)) {
|
|
32
|
+
const error = Cause.failureOption(exit.cause);
|
|
33
|
+
if (Option.isSome(error)) {
|
|
34
|
+
throw error.value;
|
|
35
|
+
}
|
|
36
|
+
throw Cause.squash(exit.cause);
|
|
37
|
+
}
|
|
38
|
+
return exit.value;
|
|
39
|
+
}
|
|
32
40
|
loadPlugin(pluginId) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const validatedId = yield*
|
|
36
|
-
const result = yield*
|
|
41
|
+
const effect = Effect.gen(this, function* () {
|
|
42
|
+
const pluginService = yield* PluginService;
|
|
43
|
+
const validatedId = yield* this.validatePluginId(pluginId);
|
|
44
|
+
const result = yield* pluginService.loadPlugin(validatedId);
|
|
37
45
|
return result;
|
|
38
46
|
});
|
|
47
|
+
return this.runPromise(effect);
|
|
39
48
|
}
|
|
40
49
|
instantiatePlugin(ctor) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const result = yield*
|
|
50
|
+
const effect = Effect.gen(this, function* () {
|
|
51
|
+
const pluginService = yield* PluginService;
|
|
52
|
+
const result = yield* pluginService.instantiatePlugin(ctor);
|
|
44
53
|
return result;
|
|
45
54
|
});
|
|
55
|
+
return this.runPromise(effect);
|
|
46
56
|
}
|
|
47
57
|
initializePlugin(instance, config) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const result = yield*
|
|
58
|
+
const effect = Effect.gen(this, function* () {
|
|
59
|
+
const pluginService = yield* PluginService;
|
|
60
|
+
const result = yield* pluginService.initializePlugin(instance, config);
|
|
51
61
|
return result;
|
|
52
62
|
});
|
|
63
|
+
return this.runPromise(effect);
|
|
53
64
|
}
|
|
54
|
-
usePlugin(pluginId, config) {
|
|
65
|
+
async usePlugin(pluginId, config) {
|
|
55
66
|
const cacheKey = this.generateCacheKey(String(pluginId), config);
|
|
56
67
|
let cachedPlugin = this.pluginCache.get(cacheKey);
|
|
57
68
|
if (!cachedPlugin) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const validatedId = yield*
|
|
69
|
+
const operation = Effect.gen(this, function* () {
|
|
70
|
+
const pluginService = yield* PluginService;
|
|
71
|
+
const validatedId = yield* this.validatePluginId(pluginId);
|
|
61
72
|
// Load → Instantiate → Initialize
|
|
62
|
-
const ctor = yield*
|
|
63
|
-
const instance = yield*
|
|
64
|
-
const
|
|
73
|
+
const ctor = yield* pluginService.loadPlugin(validatedId);
|
|
74
|
+
const instance = yield* pluginService.instantiatePlugin(ctor);
|
|
75
|
+
const _initialized = yield* pluginService.initializePlugin(instance, config);
|
|
76
|
+
const initialized = _initialized;
|
|
65
77
|
const client = createPluginClient(initialized);
|
|
66
78
|
const router = getPluginRouter(initialized);
|
|
67
79
|
return {
|
|
@@ -70,63 +82,38 @@ export class PluginRuntimeImpl {
|
|
|
70
82
|
metadata: initialized.metadata,
|
|
71
83
|
initialized
|
|
72
84
|
};
|
|
73
|
-
});
|
|
85
|
+
}).pipe(Effect.provide(this.runtime));
|
|
74
86
|
cachedPlugin = Effect.cached(operation).pipe(Effect.flatten);
|
|
75
87
|
this.pluginCache.set(cacheKey, cachedPlugin);
|
|
76
88
|
}
|
|
77
|
-
return cachedPlugin;
|
|
89
|
+
return this.runPromise(cachedPlugin);
|
|
78
90
|
}
|
|
79
91
|
shutdown() {
|
|
80
|
-
|
|
92
|
+
const effect = Effect.gen(function* () {
|
|
93
|
+
const pluginService = yield* PluginService;
|
|
94
|
+
yield* pluginService.cleanup();
|
|
95
|
+
});
|
|
96
|
+
return this.runPromise(effect);
|
|
81
97
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Evict a plugin from cache and shutdown its instance
|
|
84
|
-
*/
|
|
85
98
|
evictPlugin(pluginId, config) {
|
|
86
99
|
const cacheKey = this.generateCacheKey(String(pluginId), config);
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const cachedPlugin = self.pluginCache.get(cacheKey);
|
|
100
|
+
const effect = Effect.gen(this, function* () {
|
|
101
|
+
const pluginService = yield* PluginService;
|
|
102
|
+
const cachedPlugin = this.pluginCache.get(cacheKey);
|
|
91
103
|
if (cachedPlugin) {
|
|
92
|
-
|
|
93
|
-
self.pluginCache.delete(cacheKey);
|
|
94
|
-
// Try to shutdown the plugin gracefully
|
|
104
|
+
this.pluginCache.delete(cacheKey);
|
|
95
105
|
const pluginResult = yield* cachedPlugin.pipe(Effect.catchAll(() => Effect.succeed(null)));
|
|
96
106
|
if (pluginResult?.initialized) {
|
|
97
|
-
yield*
|
|
98
|
-
);
|
|
107
|
+
yield* pluginService.shutdownPlugin(pluginResult.initialized).pipe(Effect.catchAll(() => Effect.void));
|
|
99
108
|
}
|
|
100
109
|
}
|
|
101
|
-
}).pipe(Effect.catchAll(() => Effect.void)
|
|
102
|
-
);
|
|
110
|
+
}).pipe(Effect.catchAll(() => Effect.void));
|
|
111
|
+
return this.runPromise(effect);
|
|
103
112
|
}
|
|
104
113
|
}
|
|
105
|
-
export class PluginRuntimeService extends Context.Tag("PluginRuntimeService")() {
|
|
106
|
-
static Live = (config) => {
|
|
107
|
-
const secrets = config.secrets || {};
|
|
108
|
-
return Layer.scoped(PluginRuntimeService, Effect.gen(function* () {
|
|
109
|
-
const pluginService = yield* PluginService;
|
|
110
|
-
// Register cleanup finalizer for automatic resource management
|
|
111
|
-
yield* Effect.addFinalizer(() => pluginService.cleanup().pipe(Effect.catchAll(() => Effect.void) // Ensure cleanup never fails
|
|
112
|
-
));
|
|
113
|
-
return pluginService;
|
|
114
|
-
})).pipe(Layer.provide(PluginService.Live(config.registry, secrets).pipe(Layer.provide(Layer.mergeAll(ModuleFederationService.Live, SecretsService.Live(secrets))))));
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Creates a typed plugin runtime with compile-time registry key validation.
|
|
119
|
-
*/
|
|
120
114
|
export function createPluginRuntime(config) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
};
|
|
126
|
-
const runtime = ManagedRuntime.make(PluginRuntimeService.Live(runtimeConfig));
|
|
127
|
-
const createTypedRuntime = Effect.gen(function* () {
|
|
128
|
-
const pluginService = yield* PluginRuntimeService;
|
|
129
|
-
return new PluginRuntimeImpl(pluginService, runtimeConfig.registry);
|
|
130
|
-
}).pipe(Effect.provide(runtime));
|
|
131
|
-
return { runtime, PluginRuntime: createTypedRuntime };
|
|
115
|
+
const secrets = config.secrets || {};
|
|
116
|
+
const layer = PluginService.Live(config.registry, secrets);
|
|
117
|
+
const runtime = ManagedRuntime.make(layer);
|
|
118
|
+
return new PluginRuntime(runtime, config.registry);
|
|
132
119
|
}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { Effect
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import type { AnyPlugin } from "../../types";
|
|
3
3
|
import { ModuleFederationError } from "../errors";
|
|
4
|
-
|
|
5
|
-
readonly
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
4
|
+
declare const ModuleFederationService_base: Effect.Service.Class<ModuleFederationService, "ModuleFederationService", {
|
|
5
|
+
readonly effect: Effect.Effect<{
|
|
6
|
+
registerRemote: (pluginId: string, url: string) => Effect.Effect<undefined, ModuleFederationError, never>;
|
|
7
|
+
loadRemoteConstructor: (pluginId: string, url: string) => Effect.Effect<new () => AnyPlugin, ModuleFederationError, never>;
|
|
8
|
+
}, never, never>;
|
|
9
|
+
}>;
|
|
11
10
|
export declare class ModuleFederationService extends ModuleFederationService_base {
|
|
12
|
-
static Live: Layer.Layer<ModuleFederationService, never, never>;
|
|
13
11
|
}
|
|
14
|
-
export declare const ModuleFederationServiceTag: typeof ModuleFederationService;
|
|
15
|
-
export declare const ModuleFederationServiceLive: Layer.Layer<ModuleFederationService, never, never>;
|
|
16
12
|
export {};
|
|
17
13
|
//# sourceMappingURL=module-federation.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-federation.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/module-federation.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"module-federation.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/module-federation.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;;;mCAkFpB,MAAM,OAAO,MAAM;0CA2CZ,MAAM,OAAO,MAAM,6BAzHzC,SAAS;;;AAyExB,qBAAa,uBAAwB,SAAQ,4BAuF3C;CAAG"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { betterFetch } from "@better-fetch/fetch";
|
|
2
2
|
import { createInstance, getInstance, } from "@module-federation/enhanced/runtime";
|
|
3
3
|
import { setGlobalFederationInstance } from "@module-federation/runtime-core";
|
|
4
|
-
import { Effect
|
|
4
|
+
import { Effect } from "effect";
|
|
5
5
|
import { ModuleFederationError } from "../errors";
|
|
6
6
|
import { getNormalizedRemoteName } from "./normalize";
|
|
7
|
-
|
|
7
|
+
import pkg from "../../../package.json";
|
|
8
8
|
const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
9
9
|
try {
|
|
10
10
|
let instance = getInstance();
|
|
@@ -26,7 +26,7 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
26
26
|
version: pkg.dependencies.effect,
|
|
27
27
|
shareConfig: {
|
|
28
28
|
singleton: true,
|
|
29
|
-
requiredVersion: "^3.
|
|
29
|
+
requiredVersion: "^3.18.0", // Allow any 3.18.x patch version
|
|
30
30
|
eager: true,
|
|
31
31
|
strictVersion: true, // Enforce major/minor compatibility
|
|
32
32
|
},
|
|
@@ -68,8 +68,8 @@ const createModuleFederationInstance = Effect.cached(Effect.sync(() => {
|
|
|
68
68
|
throw new Error(`Failed to initialize Module Federation: ${error}`);
|
|
69
69
|
}
|
|
70
70
|
}));
|
|
71
|
-
export class ModuleFederationService extends Effect.
|
|
72
|
-
|
|
71
|
+
export class ModuleFederationService extends Effect.Service()("ModuleFederationService", {
|
|
72
|
+
effect: Effect.gen(function* () {
|
|
73
73
|
const mf = yield* Effect.flatten(createModuleFederationInstance);
|
|
74
74
|
return {
|
|
75
75
|
registerRemote: (pluginId, url) => Effect.gen(function* () {
|
|
@@ -91,7 +91,6 @@ export class ModuleFederationService extends Effect.Tag("ModuleFederationService
|
|
|
91
91
|
cause: new Error(`Remote not available (${url}): ${JSON.stringify(error)}`),
|
|
92
92
|
}));
|
|
93
93
|
}
|
|
94
|
-
// Register remote using normalized name
|
|
95
94
|
const remoteName = getNormalizedRemoteName(pluginId);
|
|
96
95
|
yield* Effect.try({
|
|
97
96
|
try: () => mf.registerRemotes([{ name: remoteName, entry: url }]),
|
|
@@ -130,7 +129,6 @@ export class ModuleFederationService extends Effect.Tag("ModuleFederationService
|
|
|
130
129
|
});
|
|
131
130
|
}),
|
|
132
131
|
};
|
|
133
|
-
})
|
|
132
|
+
}),
|
|
133
|
+
}) {
|
|
134
134
|
}
|
|
135
|
-
export const ModuleFederationServiceTag = ModuleFederationService;
|
|
136
|
-
export const ModuleFederationServiceLive = ModuleFederationService.Live;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect } from "effect";
|
|
2
2
|
import type { AnyPlugin, InitializedPlugin } from "../../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
3
|
+
declare const PluginLifecycleService_base: Effect.Service.Class<PluginLifecycleService, "PluginLifecycleService", {
|
|
4
|
+
readonly effect: Effect.Effect<{
|
|
5
|
+
register: <T extends AnyPlugin>(plugin: InitializedPlugin<T>) => Effect.Effect<void, never, never>;
|
|
6
|
+
unregister: (plugin: InitializedPlugin<AnyPlugin>) => Effect.Effect<void, never, never>;
|
|
7
|
+
shutdown: (plugin: InitializedPlugin<AnyPlugin>) => Effect.Effect<void, import("../errors").PluginRuntimeError, never>;
|
|
8
|
+
cleanup: () => Effect.Effect<void, never, never>;
|
|
9
|
+
}, never, never>;
|
|
10
|
+
}>;
|
|
11
11
|
export declare class PluginLifecycleService extends PluginLifecycleService_base {
|
|
12
|
-
static Live: Layer.Layer<PluginLifecycleService, never, never>;
|
|
13
12
|
}
|
|
14
|
-
export declare const PluginLifecycleServiceTag: typeof PluginLifecycleService;
|
|
15
|
-
export declare const PluginLifecycleServiceLive: Layer.Layer<PluginLifecycleService, never, never>;
|
|
16
13
|
export {};
|
|
17
14
|
//# sourceMappingURL=plugin-lifecycle.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-lifecycle.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"plugin-lifecycle.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin-lifecycle.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAO,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;;;mBAQ/C,CAAC,SAAS,SAAS,UAAU,iBAAiB,CAAC,CAAC,CAAC;6BAKvC,iBAAiB,CAAC,SAAS,CAAC;2BAO9B,iBAAiB,CAAC,SAAS,CAAC;;;;AAjBrD,qBAAa,sBAAuB,SAAQ,2BAgE1C;CAAI"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Ref } from "effect";
|
|
2
2
|
import { toPluginRuntimeError } from "../errors";
|
|
3
|
-
export class PluginLifecycleService extends
|
|
4
|
-
|
|
3
|
+
export class PluginLifecycleService extends Effect.Service()("PluginLifecycleService", {
|
|
4
|
+
effect: Effect.gen(function* () {
|
|
5
5
|
const activePlugins = yield* Ref.make(new Set());
|
|
6
6
|
return {
|
|
7
7
|
register: (plugin) => Ref.update(activePlugins, plugins => new Set(plugins).add(plugin)),
|
|
@@ -29,7 +29,6 @@ export class PluginLifecycleService extends Context.Tag("PluginLifecycleService"
|
|
|
29
29
|
}).pipe(Effect.catchAll(() => Effect.void) // Convert errors to void for cleanup
|
|
30
30
|
),
|
|
31
31
|
};
|
|
32
|
-
})
|
|
32
|
+
}),
|
|
33
|
+
}) {
|
|
33
34
|
}
|
|
34
|
-
export const PluginLifecycleServiceTag = PluginLifecycleService;
|
|
35
|
-
export const PluginLifecycleServiceLive = PluginLifecycleService.Live;
|
|
@@ -1,21 +1,58 @@
|
|
|
1
|
-
import { Context, Effect,
|
|
2
|
-
import type {
|
|
1
|
+
import { Context, Effect, Scope } from "effect";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { AnyPlugin, PluginConstructor, PluginInstance, PluginRegistry } from "../../types";
|
|
3
4
|
import { PluginRuntimeError } from "../errors";
|
|
4
5
|
import { ModuleFederationService } from "./module-federation.service";
|
|
5
6
|
import { SecretsService } from "./secrets.service";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly instantiatePlugin: <T extends AnyPlugin>(pluginConstructor: PluginConstructor<T>) => Effect.Effect<PluginInstance<T>, PluginRuntimeError>;
|
|
9
|
-
readonly initializePlugin: <T extends AnyPlugin>(pluginInstance: PluginInstance<T>, config: {
|
|
10
|
-
variables: unknown;
|
|
11
|
-
secrets: unknown;
|
|
12
|
-
}) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
|
|
7
|
+
declare const PluginRegistryTag_base: Context.TagClass<PluginRegistryTag, "PluginRegistry", PluginRegistry>;
|
|
8
|
+
export declare class PluginRegistryTag extends PluginRegistryTag_base {
|
|
13
9
|
}
|
|
14
|
-
declare const
|
|
10
|
+
declare const RegistryService_base: Effect.Service.Class<RegistryService, "RegistryService", {
|
|
11
|
+
readonly effect: Effect.Effect<{
|
|
12
|
+
get: (pluginId: string) => Effect.Effect<{
|
|
13
|
+
remoteUrl: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
}, PluginRuntimeError, never>;
|
|
17
|
+
}, never, PluginRegistryTag>;
|
|
18
|
+
}>;
|
|
19
|
+
export declare class RegistryService extends RegistryService_base {
|
|
20
|
+
}
|
|
21
|
+
declare const PluginLoaderService_base: Effect.Service.Class<PluginLoaderService, "PluginLoaderService", {
|
|
22
|
+
readonly effect: Effect.Effect<{
|
|
23
|
+
loadPlugin: (pluginId: string) => Effect.Effect<{
|
|
24
|
+
ctor: new () => AnyPlugin;
|
|
25
|
+
metadata: {
|
|
26
|
+
pluginId: string;
|
|
27
|
+
version: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
}, PluginRuntimeError, never>;
|
|
30
|
+
instantiatePlugin: <T extends AnyPlugin>(pluginConstructor: PluginConstructor<T>) => Effect.Effect<{
|
|
31
|
+
plugin: T;
|
|
32
|
+
metadata: {
|
|
33
|
+
readonly pluginId: string;
|
|
34
|
+
readonly version?: string;
|
|
35
|
+
readonly description?: string;
|
|
36
|
+
readonly type?: string;
|
|
37
|
+
};
|
|
38
|
+
}, PluginRuntimeError, never>;
|
|
39
|
+
initializePlugin: <T extends AnyPlugin>(pluginInstance: PluginInstance<T>, config: {
|
|
40
|
+
variables: unknown;
|
|
41
|
+
secrets: unknown;
|
|
42
|
+
}) => Effect.Effect<{
|
|
43
|
+
plugin: T;
|
|
44
|
+
metadata: {
|
|
45
|
+
readonly pluginId: string;
|
|
46
|
+
readonly version?: string;
|
|
47
|
+
readonly description?: string;
|
|
48
|
+
};
|
|
49
|
+
config: z.infer<T["configSchema"]>;
|
|
50
|
+
context: any;
|
|
51
|
+
scope: Scope.CloseableScope;
|
|
52
|
+
}, PluginRuntimeError, never>;
|
|
53
|
+
}, never, RegistryService | ModuleFederationService | SecretsService>;
|
|
54
|
+
}>;
|
|
15
55
|
export declare class PluginLoaderService extends PluginLoaderService_base {
|
|
16
|
-
static Live: (registry: PluginRegistry, secrets: SecretsConfig) => Layer.Layer<PluginLoaderService, never, ModuleFederationService | SecretsService>;
|
|
17
56
|
}
|
|
18
|
-
export declare const PluginLoaderServiceTag: typeof PluginLoaderService;
|
|
19
|
-
export declare const PluginLoaderServiceLive: (registry: PluginRegistry, secrets: SecretsConfig) => Layer.Layer<PluginLoaderService, never, ModuleFederationService | SecretsService>;
|
|
20
57
|
export {};
|
|
21
58
|
//# sourceMappingURL=plugin-loader.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin-loader.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin-loader.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EACX,SAAS,EAET,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAwB,MAAM,WAAW,CAAC;AAErE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;;AAEnD,qBAAa,iBAAkB,SAAQ,sBAGpC;CAAI;;;wBAOY,MAAM;;;;;;;AALzB,qBAAa,eAAgB,SAAQ,oBAkBnC;CAAI;;;+BAgBoB,MAAM;;;;;;;4BA4BT,CAAC,SAAS,SAAS,qBACnB,iBAAiB,CAAC,CAAC,CAAC;;;;;;;;;2BAmCrB,CAAC,SAAS,SAAS,kBACrB,cAAc,CAAC,CAAC,CAAC,UACzB;YAAE,SAAS,EAAE,OAAO,CAAC;YAAC,OAAO,EAAE,OAAO,CAAA;SAAE;;;;;;;oBAwDvB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;;;;;;AAxIvD,qBAAa,mBAAoB,SAAQ,wBA+IvC;CACD"}
|
|
@@ -1,21 +1,33 @@
|
|
|
1
|
-
import { Context, Effect,
|
|
1
|
+
import { Context, Effect, Scope } from "effect";
|
|
2
2
|
import { PluginRuntimeError, toPluginRuntimeError } from "../errors";
|
|
3
3
|
import { validate } from "../validation";
|
|
4
4
|
import { ModuleFederationService } from "./module-federation.service";
|
|
5
5
|
import { SecretsService } from "./secrets.service";
|
|
6
|
-
export class
|
|
7
|
-
|
|
6
|
+
export class PluginRegistryTag extends Context.Tag("PluginRegistry")() {
|
|
7
|
+
}
|
|
8
|
+
export class RegistryService extends Effect.Service()("RegistryService", {
|
|
9
|
+
effect: Effect.gen(function* () {
|
|
10
|
+
const registry = yield* PluginRegistryTag;
|
|
11
|
+
return {
|
|
12
|
+
get: (pluginId) => Effect.fromNullable(registry[pluginId]).pipe(Effect.mapError(() => new PluginRuntimeError({
|
|
13
|
+
pluginId,
|
|
14
|
+
operation: "load-plugin",
|
|
15
|
+
cause: new Error(`Plugin ${pluginId} not found in registry`),
|
|
16
|
+
retryable: false,
|
|
17
|
+
}))),
|
|
18
|
+
};
|
|
19
|
+
}),
|
|
20
|
+
}) {
|
|
21
|
+
}
|
|
22
|
+
export class PluginLoaderService extends Effect.Service()("PluginLoaderService", {
|
|
23
|
+
effect: Effect.gen(function* () {
|
|
8
24
|
const moduleFederationService = yield* ModuleFederationService;
|
|
9
25
|
const secretsService = yield* SecretsService;
|
|
26
|
+
const registryService = yield* RegistryService;
|
|
10
27
|
const resolveUrl = (baseUrl, version) => version && version !== "latest"
|
|
11
28
|
? baseUrl.replace("@latest", `@${version}`)
|
|
12
29
|
: baseUrl;
|
|
13
|
-
const getMetadata = (pluginId) =>
|
|
14
|
-
pluginId,
|
|
15
|
-
operation: "load-plugin",
|
|
16
|
-
cause: new Error(`Plugin ${pluginId} not found in registry`),
|
|
17
|
-
retryable: false,
|
|
18
|
-
})));
|
|
30
|
+
const getMetadata = (pluginId) => registryService.get(pluginId);
|
|
19
31
|
return {
|
|
20
32
|
loadPlugin: (pluginId) => Effect.gen(function* () {
|
|
21
33
|
const metadata = yield* getMetadata(pluginId);
|
|
@@ -27,8 +39,7 @@ export class PluginLoaderService extends Context.Tag("PluginLoaderService")() {
|
|
|
27
39
|
ctor,
|
|
28
40
|
metadata: {
|
|
29
41
|
pluginId,
|
|
30
|
-
version: metadata.version
|
|
31
|
-
type: metadata.type,
|
|
42
|
+
version: metadata.version
|
|
32
43
|
},
|
|
33
44
|
};
|
|
34
45
|
}),
|
|
@@ -57,7 +68,7 @@ export class PluginLoaderService extends Context.Tag("PluginLoaderService")() {
|
|
|
57
68
|
cause: validationError.zodError,
|
|
58
69
|
retryable: false,
|
|
59
70
|
})));
|
|
60
|
-
const hydratedConfig = yield* secretsService.hydrateSecrets(validatedConfig
|
|
71
|
+
const hydratedConfig = yield* secretsService.hydrateSecrets(validatedConfig);
|
|
61
72
|
const finalConfig = yield* validate(plugin.configSchema, hydratedConfig, plugin.id, "config").pipe(Effect.mapError((validationError) => new PluginRuntimeError({
|
|
62
73
|
pluginId: plugin.id,
|
|
63
74
|
operation: "validate-hydrated-config",
|
|
@@ -77,7 +88,6 @@ export class PluginLoaderService extends Context.Tag("PluginLoaderService")() {
|
|
|
77
88
|
};
|
|
78
89
|
}),
|
|
79
90
|
};
|
|
80
|
-
})
|
|
91
|
+
}),
|
|
92
|
+
}) {
|
|
81
93
|
}
|
|
82
|
-
export const PluginLoaderServiceTag = PluginLoaderService;
|
|
83
|
-
export const PluginLoaderServiceLive = PluginLoaderService.Live;
|