every-plugin 0.3.2 → 0.4.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 +5 -9
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +6 -2
- package/dist/runtime/index.d.ts +8 -29
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +63 -52
- package/dist/runtime/services/module-federation.service.d.ts.map +1 -1
- package/dist/runtime/services/module-federation.service.js +24 -3
- package/dist/runtime/services/plugin-loader.service.d.ts +4 -4
- package/dist/runtime/services/plugin-loader.service.d.ts.map +1 -1
- package/dist/runtime/services/plugin-loader.service.js +2 -10
- package/dist/runtime/services/plugin.service.d.ts +3 -3
- package/dist/testing/index.d.ts +15 -9
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/types.d.ts +85 -64
- package/dist/types.d.ts.map +1 -1
- package/package.json +103 -103
- package/dist/client/index.d.ts +0 -17
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -33
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,
|
|
5
|
+
export type { AnyPlugin, EveryPlugin, InitializedPlugin, LoadedPlugin, PluginClientType, PluginConfigInput, PluginContext, PluginContract, PluginInstance, PluginMetadata, PluginRegistry, PluginRouterType, PluginRuntimeConfig, PluginSecrets, PluginVariables, RegisteredPlugins, 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,
|
|
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,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAClF,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EACtE,aAAa,EACb,MAAM,SAAS,CAAC"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -16,15 +16,12 @@ export interface LoadedPluginWithBinding<TContract extends AnyContractRouter, TV
|
|
|
16
16
|
new (): Plugin<TContract, TVariables, TSecrets, TContext>;
|
|
17
17
|
binding: {
|
|
18
18
|
contract: TContract;
|
|
19
|
+
variables: TVariables;
|
|
20
|
+
secrets: TSecrets;
|
|
19
21
|
config: PluginConfigFor<TVariables, TSecrets>;
|
|
22
|
+
context: TContext;
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Utility type to extract binding from plugin constructor
|
|
24
|
-
*/
|
|
25
|
-
export type PluginBinding<T> = T extends {
|
|
26
|
-
binding: infer B;
|
|
27
|
-
} ? B : never;
|
|
28
25
|
/**
|
|
29
26
|
* Common error schemas that all plugins can use
|
|
30
27
|
* These provide consistent error handling across the plugin ecosystem
|
|
@@ -99,15 +96,14 @@ export interface Plugin<TContract extends AnyContractRouter, TVariables extends
|
|
|
99
96
|
* Creates the strongly-typed oRPC router for this plugin.
|
|
100
97
|
* The router's procedure types are inferred directly from the contract.
|
|
101
98
|
* @param context The initialized plugin context
|
|
102
|
-
* @returns A router with procedures matching the plugin's contract
|
|
99
|
+
* @returns A router with procedures matching the plugin's contract
|
|
103
100
|
*/
|
|
104
|
-
createRouter
|
|
101
|
+
createRouter(context: TContext): Router<TContract, TContext>;
|
|
105
102
|
}
|
|
106
103
|
/**
|
|
107
104
|
* Factory function to create plugins
|
|
108
105
|
*/
|
|
109
106
|
export declare function createPlugin<V extends AnySchema, S extends AnySchema, TContract extends AnyContractRouter, TContext extends Context = Record<never, never>>(config: {
|
|
110
|
-
id: string;
|
|
111
107
|
variables: V;
|
|
112
108
|
secrets: S;
|
|
113
109
|
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,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,IAAI;IACvE,SAAS,EAAE,CAAC,CAAC;IACb,OAAO,EAAE,CAAC,CAAC;CACX,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,uBAAuB,CACvC,SAAS,SAAS,iBAAiB,EACnC,UAAU,SAAS,SAAS,EAC5B,QAAQ,SAAS,SAAS,EAC1B,QAAQ,SAAS,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;IAE/C,QAAO,MAAM,CAAC,SAAS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EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACjD,YAAY,EAAE,CACb,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,KAC7F,MAAM,CAAC,SAAS,EAAE,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CAChE,GA+D4B,uBAAuB,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAC9E"}
|
package/dist/plugin.js
CHANGED
|
@@ -60,7 +60,8 @@ export function createPlugin(config) {
|
|
|
60
60
|
secrets: config.secrets
|
|
61
61
|
};
|
|
62
62
|
class CreatedPlugin {
|
|
63
|
-
|
|
63
|
+
/** set during instantiation - registry key */
|
|
64
|
+
id;
|
|
64
65
|
contract = config.contract;
|
|
65
66
|
configSchema = configSchema;
|
|
66
67
|
_context = null;
|
|
@@ -85,7 +86,10 @@ export function createPlugin(config) {
|
|
|
85
86
|
const PluginConstructor = CreatedPlugin;
|
|
86
87
|
PluginConstructor.binding = {
|
|
87
88
|
contract: config.contract,
|
|
88
|
-
|
|
89
|
+
variables: config.variables,
|
|
90
|
+
secrets: config.secrets,
|
|
91
|
+
config: configSchema,
|
|
92
|
+
context: {}
|
|
89
93
|
};
|
|
90
94
|
return PluginConstructor;
|
|
91
95
|
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { InferSchemaInput } from "@orpc/contract";
|
|
2
1
|
import { ManagedRuntime } from "effect";
|
|
3
|
-
import type {
|
|
2
|
+
import type { AnyPlugin, InitializedPlugin, LoadedPlugin, PluginConfigInput, PluginInstance, PluginRegistry, PluginRuntimeConfig, RegisteredPlugin, RegisteredPlugins, UsePluginResult } from "../types";
|
|
4
3
|
import { PluginService } from "./services/plugin.service";
|
|
5
|
-
export declare class PluginRuntime<R extends
|
|
4
|
+
export declare class PluginRuntime<R extends RegisteredPlugins = RegisteredPlugins> {
|
|
6
5
|
private runtime;
|
|
7
6
|
private registry;
|
|
8
7
|
private pluginCache;
|
|
@@ -10,32 +9,12 @@ export declare class PluginRuntime<R extends RegistryBindings = RegistryBindings
|
|
|
10
9
|
private generateCacheKey;
|
|
11
10
|
private validatePluginId;
|
|
12
11
|
private runPromise;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
secrets: InferSchemaInput<PluginOf<R[K]>["configSchema"]["secrets"]>;
|
|
18
|
-
}): Promise<InitializedPlugin<PluginOf<R[K]>> & {
|
|
19
|
-
config: ConfigOf<R[K]>;
|
|
20
|
-
}>;
|
|
21
|
-
usePlugin<K extends keyof R>(pluginId: K, config: {
|
|
22
|
-
variables: InferSchemaInput<PluginOf<R[K]>["configSchema"]["variables"]>;
|
|
23
|
-
secrets: InferSchemaInput<PluginOf<R[K]>["configSchema"]["secrets"]>;
|
|
24
|
-
}): Promise<EveryPlugin<PluginOf<R[K]>> & {
|
|
25
|
-
initialized: InitializedPlugin<PluginOf<R[K]>> & {
|
|
26
|
-
config: ConfigOf<R[K]>;
|
|
27
|
-
};
|
|
28
|
-
}>;
|
|
12
|
+
usePlugin<K extends keyof RegisteredPlugins & string>(pluginId: K, config: PluginConfigInput<R[K]>): Promise<UsePluginResult<K>>;
|
|
13
|
+
loadPlugin<K extends keyof RegisteredPlugins & string>(pluginId: K): Promise<LoadedPlugin<RegisteredPlugin<K>>>;
|
|
14
|
+
instantiatePlugin<K extends keyof RegisteredPlugins & string>(pluginId: K, loadedPlugin: LoadedPlugin<RegisteredPlugin<K>>): Promise<PluginInstance<RegisteredPlugin<K>>>;
|
|
15
|
+
initializePlugin<T extends AnyPlugin>(instance: PluginInstance<T>, config: any): Promise<InitializedPlugin<T>>;
|
|
29
16
|
shutdown(): Promise<void>;
|
|
30
|
-
evictPlugin<K extends keyof
|
|
31
|
-
variables: InferSchemaInput<PluginOf<R[K]>["configSchema"]["variables"]>;
|
|
32
|
-
secrets: InferSchemaInput<PluginOf<R[K]>["configSchema"]["secrets"]>;
|
|
33
|
-
}): Promise<void>;
|
|
17
|
+
evictPlugin<K extends keyof RegisteredPlugins & string>(pluginId: K, config: PluginConfigInput<RegisteredPlugins[K]>): Promise<void>;
|
|
34
18
|
}
|
|
35
|
-
export declare function createPluginRuntime
|
|
36
|
-
registry: PluginRegistry;
|
|
37
|
-
secrets?: SecretsConfig;
|
|
38
|
-
options?: RuntimeOptions;
|
|
39
|
-
}): PluginRuntime<R>;
|
|
40
|
-
export type { ConfigOf, EveryPlugin, InitializedPlugin, PluginOf, RegistryBindings } from "../types";
|
|
19
|
+
export declare function createPluginRuntime(config: PluginRuntimeConfig): PluginRuntime;
|
|
41
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,cAAc,EAAU,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,EACX,SAAS,EACT,iBAAiB,EACjB,YAAY,EAEZ,iBAAiB,EACjB,cAAc,EACd,cAAc,EAEd,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,qBAAa,aAAa,CAAC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB;IAIxE,OAAO,CAAC,OAAO;IACf,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AkBf"}
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { createRouterClient } from "@orpc/server";
|
|
1
2
|
import { Cause, Effect, Exit, Hash, ManagedRuntime, Option } from "effect";
|
|
2
|
-
import { createPluginClient, getPluginRouter } from "../client/index";
|
|
3
3
|
import { PluginRuntimeError } from "./errors";
|
|
4
4
|
import { PluginService } from "./services/plugin.service";
|
|
5
5
|
export class PluginRuntime {
|
|
@@ -15,16 +15,15 @@ export class PluginRuntime {
|
|
|
15
15
|
return `${pluginId}:${configHash}`;
|
|
16
16
|
}
|
|
17
17
|
validatePluginId(pluginId) {
|
|
18
|
-
|
|
19
|
-
if (!(pluginIdStr in this.registry)) {
|
|
18
|
+
if (!(pluginId in this.registry)) {
|
|
20
19
|
return Effect.fail(new PluginRuntimeError({
|
|
21
|
-
pluginId:
|
|
20
|
+
pluginId: String(pluginId),
|
|
22
21
|
operation: "validate-plugin-id",
|
|
23
|
-
cause: new Error(`Plugin ID '${
|
|
22
|
+
cause: new Error(`Plugin ID '${String(pluginId)}' not found in registry.`),
|
|
24
23
|
retryable: false,
|
|
25
24
|
}));
|
|
26
25
|
}
|
|
27
|
-
return Effect.succeed(
|
|
26
|
+
return Effect.succeed(String(pluginId));
|
|
28
27
|
}
|
|
29
28
|
async runPromise(effect) {
|
|
30
29
|
const exit = await this.runtime.runPromiseExit(effect);
|
|
@@ -37,34 +36,8 @@ export class PluginRuntime {
|
|
|
37
36
|
}
|
|
38
37
|
return exit.value;
|
|
39
38
|
}
|
|
40
|
-
loadPlugin(pluginId) {
|
|
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);
|
|
45
|
-
return result;
|
|
46
|
-
});
|
|
47
|
-
return this.runPromise(effect);
|
|
48
|
-
}
|
|
49
|
-
instantiatePlugin(pluginId, loadedPlugin) {
|
|
50
|
-
const effect = Effect.gen(this, function* () {
|
|
51
|
-
const pluginService = yield* PluginService;
|
|
52
|
-
const pluginIdStr = pluginId;
|
|
53
|
-
const result = yield* pluginService.instantiatePlugin(pluginIdStr, loadedPlugin);
|
|
54
|
-
return result;
|
|
55
|
-
});
|
|
56
|
-
return this.runPromise(effect);
|
|
57
|
-
}
|
|
58
|
-
initializePlugin(instance, config) {
|
|
59
|
-
const effect = Effect.gen(this, function* () {
|
|
60
|
-
const pluginService = yield* PluginService;
|
|
61
|
-
const result = yield* pluginService.initializePlugin(instance, config);
|
|
62
|
-
return result;
|
|
63
|
-
});
|
|
64
|
-
return this.runPromise(effect);
|
|
65
|
-
}
|
|
66
39
|
async usePlugin(pluginId, config) {
|
|
67
|
-
const cacheKey = this.generateCacheKey(
|
|
40
|
+
const cacheKey = this.generateCacheKey(pluginId, config);
|
|
68
41
|
let cachedPlugin = this.pluginCache.get(cacheKey);
|
|
69
42
|
if (!cachedPlugin) {
|
|
70
43
|
const operation = Effect.gen(this, function* () {
|
|
@@ -72,49 +45,87 @@ export class PluginRuntime {
|
|
|
72
45
|
const validatedId = yield* this.validatePluginId(pluginId);
|
|
73
46
|
// Load → Instantiate → Initialize
|
|
74
47
|
const ctor = yield* pluginService.loadPlugin(validatedId);
|
|
75
|
-
const instance = yield* pluginService.instantiatePlugin(
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const client = createPluginClient(initialized);
|
|
79
|
-
const router = getPluginRouter(initialized);
|
|
80
|
-
return {
|
|
81
|
-
client,
|
|
82
|
-
router,
|
|
83
|
-
metadata: initialized.metadata,
|
|
84
|
-
initialized
|
|
85
|
-
};
|
|
48
|
+
const instance = yield* pluginService.instantiatePlugin(pluginId, ctor);
|
|
49
|
+
const initialized = yield* pluginService.initializePlugin(instance, config);
|
|
50
|
+
return initialized;
|
|
86
51
|
}).pipe(Effect.provide(this.runtime));
|
|
87
52
|
cachedPlugin = Effect.cached(operation).pipe(Effect.flatten);
|
|
88
53
|
this.pluginCache.set(cacheKey, cachedPlugin);
|
|
89
54
|
}
|
|
90
|
-
|
|
55
|
+
const initialized = await this.runPromise(cachedPlugin);
|
|
56
|
+
const router = initialized.plugin.createRouter(initialized.context);
|
|
57
|
+
const client = createRouterClient(router);
|
|
58
|
+
return {
|
|
59
|
+
router: router,
|
|
60
|
+
client: client,
|
|
61
|
+
metadata: initialized.metadata,
|
|
62
|
+
initialized: initialized
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async loadPlugin(pluginId) {
|
|
66
|
+
const effect = Effect.gen(function* () {
|
|
67
|
+
const pluginService = yield* PluginService;
|
|
68
|
+
return yield* pluginService.loadPlugin(pluginId);
|
|
69
|
+
});
|
|
70
|
+
return this.runPromise(effect);
|
|
71
|
+
}
|
|
72
|
+
async instantiatePlugin(pluginId, loadedPlugin) {
|
|
73
|
+
const effect = Effect.gen(function* () {
|
|
74
|
+
const pluginService = yield* PluginService;
|
|
75
|
+
return yield* pluginService.instantiatePlugin(pluginId, loadedPlugin);
|
|
76
|
+
});
|
|
77
|
+
return this.runPromise(effect);
|
|
78
|
+
}
|
|
79
|
+
async initializePlugin(instance, config) {
|
|
80
|
+
const effect = Effect.gen(function* () {
|
|
81
|
+
const pluginService = yield* PluginService;
|
|
82
|
+
return yield* pluginService.initializePlugin(instance, config);
|
|
83
|
+
});
|
|
84
|
+
return this.runPromise(effect);
|
|
91
85
|
}
|
|
92
|
-
shutdown() {
|
|
86
|
+
async shutdown() {
|
|
93
87
|
const effect = Effect.gen(function* () {
|
|
94
88
|
const pluginService = yield* PluginService;
|
|
95
89
|
yield* pluginService.cleanup();
|
|
96
90
|
});
|
|
97
91
|
return this.runPromise(effect);
|
|
98
92
|
}
|
|
99
|
-
evictPlugin(pluginId, config) {
|
|
100
|
-
const cacheKey = this.generateCacheKey(
|
|
93
|
+
async evictPlugin(pluginId, config) {
|
|
94
|
+
const cacheKey = this.generateCacheKey(pluginId, config);
|
|
101
95
|
const effect = Effect.gen(this, function* () {
|
|
102
96
|
const pluginService = yield* PluginService;
|
|
103
97
|
const cachedPlugin = this.pluginCache.get(cacheKey);
|
|
104
98
|
if (cachedPlugin) {
|
|
105
99
|
this.pluginCache.delete(cacheKey);
|
|
106
100
|
const pluginResult = yield* cachedPlugin.pipe(Effect.catchAll(() => Effect.succeed(null)));
|
|
107
|
-
if (pluginResult
|
|
108
|
-
yield* pluginService.shutdownPlugin(pluginResult
|
|
101
|
+
if (pluginResult) {
|
|
102
|
+
yield* pluginService.shutdownPlugin(pluginResult).pipe(Effect.catchAll(() => Effect.void));
|
|
109
103
|
}
|
|
110
104
|
}
|
|
111
105
|
}).pipe(Effect.catchAll(() => Effect.void));
|
|
112
106
|
return this.runPromise(effect);
|
|
113
107
|
}
|
|
114
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Normalizes a remote URL to ensure it points to remoteEntry.js
|
|
111
|
+
* If the URL doesn't end with a file extension, appends /remoteEntry.js
|
|
112
|
+
*/
|
|
113
|
+
function normalizeRemoteUrl(url) {
|
|
114
|
+
if (url.endsWith('.js'))
|
|
115
|
+
return url; // Already a file
|
|
116
|
+
return `${url.endsWith('/') ? url.slice(0, -1) : url}/remoteEntry.js`;
|
|
117
|
+
}
|
|
115
118
|
export function createPluginRuntime(config) {
|
|
116
119
|
const secrets = config.secrets || {};
|
|
117
|
-
|
|
120
|
+
// Normalize all remote URLs in the registry
|
|
121
|
+
const normalizedRegistry = Object.fromEntries(Object.entries(config.registry).map(([pluginId, entry]) => [
|
|
122
|
+
pluginId,
|
|
123
|
+
{
|
|
124
|
+
...entry,
|
|
125
|
+
remoteUrl: normalizeRemoteUrl(entry.remoteUrl)
|
|
126
|
+
}
|
|
127
|
+
]));
|
|
128
|
+
const layer = PluginService.Live(normalizedRegistry, secrets);
|
|
118
129
|
const runtime = ManagedRuntime.make(layer);
|
|
119
|
-
return new PluginRuntime(runtime,
|
|
130
|
+
return new PluginRuntime(runtime, normalizedRegistry);
|
|
120
131
|
}
|
|
@@ -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,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,6BAxH/B,SAAS;;;AAwElC,qBAAa,uBAAwB,SAAQ,
|
|
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,6BAxH/B,SAAS;;;AAwElC,qBAAa,uBAAwB,SAAQ,4BAkH3C;CAAG"}
|
|
@@ -112,11 +112,32 @@ export class ModuleFederationService extends Effect.Service()("ModuleFederationS
|
|
|
112
112
|
if (!container) {
|
|
113
113
|
throw new Error(`No container returned for ${modulePath}`);
|
|
114
114
|
}
|
|
115
|
+
// Support multiple export patterns: direct function, default export, named exports
|
|
115
116
|
const Constructor = typeof container === "function"
|
|
116
|
-
? container
|
|
117
|
-
: container.default
|
|
117
|
+
? container // Direct function export
|
|
118
|
+
: container.default
|
|
119
|
+
? container.default // Default export
|
|
120
|
+
: Object.values(container).find(// Named export fallback
|
|
121
|
+
(exp) => typeof exp === "function" && exp.prototype?.constructor === exp);
|
|
118
122
|
if (!Constructor || typeof Constructor !== "function") {
|
|
119
|
-
|
|
123
|
+
const containerInfo = typeof container === "object"
|
|
124
|
+
? `Available exports: ${Object.keys(container).join(', ')}`
|
|
125
|
+
: `Container type: ${typeof container}`;
|
|
126
|
+
throw new Error(`No valid plugin constructor found for '${pluginId}'.\n` +
|
|
127
|
+
`Supported patterns:\n` +
|
|
128
|
+
` - export const YourPlugin = createPlugin({...})\n` +
|
|
129
|
+
` - export default createPlugin({...})\n` +
|
|
130
|
+
`${containerInfo}`);
|
|
131
|
+
}
|
|
132
|
+
// Validate it looks like a plugin constructor (has binding property)
|
|
133
|
+
if (!Constructor.binding) {
|
|
134
|
+
const containerInfo = typeof container === "object"
|
|
135
|
+
? `Found exports: ${Object.keys(container).join(', ')}`
|
|
136
|
+
: `Container type: ${typeof container}`;
|
|
137
|
+
throw new Error(`Invalid plugin constructor for '${pluginId}'. ` +
|
|
138
|
+
`The exported value must be created with createPlugin(). ` +
|
|
139
|
+
`Found a function but it's missing the required 'binding' property.\n` +
|
|
140
|
+
`${containerInfo}`);
|
|
120
141
|
}
|
|
121
142
|
console.log(`[MF] ✅ Loaded constructor for ${pluginId}`);
|
|
122
143
|
return Constructor;
|
|
@@ -9,7 +9,7 @@ export declare class PluginRegistryTag extends PluginRegistryTag_base {
|
|
|
9
9
|
}
|
|
10
10
|
declare const RegistryService_base: Effect.Service.Class<RegistryService, "RegistryService", {
|
|
11
11
|
readonly effect: Effect.Effect<{
|
|
12
|
-
get: (pluginId: string) => Effect.Effect<import("
|
|
12
|
+
get: (pluginId: string) => Effect.Effect<import("../..").PluginMetadata, PluginRuntimeError, never>;
|
|
13
13
|
}, never, PluginRegistryTag>;
|
|
14
14
|
}>;
|
|
15
15
|
export declare class RegistryService extends RegistryService_base {
|
|
@@ -18,18 +18,18 @@ declare const PluginLoaderService_base: Effect.Service.Class<PluginLoaderService
|
|
|
18
18
|
readonly effect: Effect.Effect<{
|
|
19
19
|
loadPlugin: (pluginId: string) => Effect.Effect<{
|
|
20
20
|
ctor: new () => AnyPlugin;
|
|
21
|
-
metadata: import("
|
|
21
|
+
metadata: import("../..").PluginMetadata;
|
|
22
22
|
}, PluginRuntimeError, never>;
|
|
23
23
|
instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: LoadedPlugin<T>) => Effect.Effect<{
|
|
24
24
|
plugin: T;
|
|
25
|
-
metadata: import("
|
|
25
|
+
metadata: import("../..").PluginMetadata;
|
|
26
26
|
}, PluginRuntimeError, never>;
|
|
27
27
|
initializePlugin: <T extends AnyPlugin>(pluginInstance: PluginInstance<T>, config: {
|
|
28
28
|
variables: InferSchemaInput<T["configSchema"]["variables"]>;
|
|
29
29
|
secrets: InferSchemaInput<T["configSchema"]["secrets"]>;
|
|
30
30
|
}) => Effect.Effect<{
|
|
31
31
|
plugin: T;
|
|
32
|
-
metadata: import("
|
|
32
|
+
metadata: import("../..").PluginMetadata;
|
|
33
33
|
config: {
|
|
34
34
|
variables: InferSchemaOutput<T["configSchema"]["variables"]>;
|
|
35
35
|
secrets: InferSchemaOutput<T["configSchema"]["secrets"]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-loader.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin-loader.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,KAAK,EACX,SAAS,EAET,YAAY,EACZ,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;;;;4BAyBT,CAAC,SAAS,SAAS,YAC5B,MAAM,gBACF,YAAY,CAAC,CAAC,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"plugin-loader.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin-loader.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,KAAK,EACX,SAAS,EAET,YAAY,EACZ,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;;;;4BAyBT,CAAC,SAAS,SAAS,YAC5B,MAAM,gBACF,YAAY,CAAC,CAAC,CAAC;;;;2BAuBX,CAAC,SAAS,SAAS,kBACrB,cAAc,CAAC,CAAC,CAAC,UACzB;YAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;YAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;SAAE;;;;;;;;;;;;AAlEpI,qBAAa,mBAAoB,SAAQ,wBAoJvC;CACD"}
|
|
@@ -11,7 +11,7 @@ export class RegistryService extends Effect.Service()("RegistryService", {
|
|
|
11
11
|
return {
|
|
12
12
|
get: (pluginId) => Effect.fromNullable(registry[pluginId]).pipe(Effect.mapError(() => new PluginRuntimeError({
|
|
13
13
|
pluginId,
|
|
14
|
-
operation: "
|
|
14
|
+
operation: "validate-plugin-id",
|
|
15
15
|
cause: new Error(`Plugin ${pluginId} not found in registry`),
|
|
16
16
|
retryable: false,
|
|
17
17
|
}))),
|
|
@@ -42,15 +42,7 @@ export class PluginLoaderService extends Effect.Service()("PluginLoaderService",
|
|
|
42
42
|
}),
|
|
43
43
|
instantiatePlugin: (pluginId, loadedPlugin) => Effect.gen(function* () {
|
|
44
44
|
const instance = yield* Effect.try(() => new loadedPlugin.ctor()).pipe(Effect.mapError((error) => toPluginRuntimeError(error, pluginId, undefined, "instantiate-plugin", false)));
|
|
45
|
-
|
|
46
|
-
if (instance.id !== pluginId) {
|
|
47
|
-
return yield* Effect.fail(new PluginRuntimeError({
|
|
48
|
-
pluginId,
|
|
49
|
-
operation: "validate-plugin-id",
|
|
50
|
-
cause: new Error(`Plugin ID mismatch: expected ${pluginId}, got ${instance.id}`),
|
|
51
|
-
retryable: false,
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
45
|
+
instance.id = pluginId;
|
|
54
46
|
return {
|
|
55
47
|
plugin: instance,
|
|
56
48
|
metadata: loadedPlugin.metadata,
|
|
@@ -6,18 +6,18 @@ declare const PluginService_base: Effect.Service.Class<PluginService, "PluginSer
|
|
|
6
6
|
readonly scoped: Effect.Effect<{
|
|
7
7
|
loadPlugin: (pluginId: string) => Effect.Effect<{
|
|
8
8
|
ctor: new () => AnyPlugin;
|
|
9
|
-
metadata: import("
|
|
9
|
+
metadata: import("../..").PluginMetadata;
|
|
10
10
|
}, import("../errors").PluginRuntimeError, never>;
|
|
11
11
|
instantiatePlugin: <T extends AnyPlugin>(pluginId: string, loadedPlugin: import("../..").LoadedPlugin<T>) => Effect.Effect<{
|
|
12
12
|
plugin: T;
|
|
13
|
-
metadata: import("
|
|
13
|
+
metadata: import("../..").PluginMetadata;
|
|
14
14
|
}, import("../errors").PluginRuntimeError, never>;
|
|
15
15
|
initializePlugin: <T extends AnyPlugin>(pluginInstance: import("../..").PluginInstance<T>, config: {
|
|
16
16
|
variables: import("@orpc/contract").InferSchemaInput<T["configSchema"]["variables"]>;
|
|
17
17
|
secrets: import("@orpc/contract").InferSchemaInput<T["configSchema"]["secrets"]>;
|
|
18
18
|
}) => Effect.Effect<{
|
|
19
19
|
plugin: T;
|
|
20
|
-
metadata: import("
|
|
20
|
+
metadata: import("../..").PluginMetadata;
|
|
21
21
|
config: {
|
|
22
22
|
variables: import("@orpc/contract").InferSchemaOutput<T["configSchema"]["variables"]>;
|
|
23
23
|
secrets: import("@orpc/contract").InferSchemaOutput<T["configSchema"]["secrets"]>;
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
|
-
import type { PluginBinding } from "../plugin";
|
|
3
2
|
import { PluginRuntime } from "../runtime";
|
|
4
3
|
import { PluginService } from "../runtime/services";
|
|
5
|
-
import type { PluginRuntimeConfig,
|
|
4
|
+
import type { PluginRuntimeConfig, RegisteredPlugins } from "../types";
|
|
6
5
|
import { type PluginMap } from "./mocks/module-federation.service";
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Validates that all plugin map keys exist in RegisteredPlugins.
|
|
8
|
+
* This ensures proper type inference for client methods.
|
|
9
|
+
*/
|
|
10
|
+
type ValidatePluginMap<T extends PluginMap> = {
|
|
11
|
+
[K in keyof T]: K extends keyof RegisteredPlugins ? T[K] : `❌ Plugin key "${K & string}" not registered in RegisteredPlugins. Add it to your types.d.ts file.`;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Simplified type inference for local plugin maps.
|
|
15
|
+
* Just use the constructor types directly.
|
|
10
16
|
*
|
|
11
17
|
* @example
|
|
12
18
|
* ```ts
|
|
@@ -15,13 +21,13 @@ import { type PluginMap } from "./mocks/module-federation.service";
|
|
|
15
21
|
* ```
|
|
16
22
|
*/
|
|
17
23
|
export type InferBindingsFromMap<T extends PluginMap> = {
|
|
18
|
-
[K in keyof T]:
|
|
19
|
-
} &
|
|
24
|
+
[K in keyof T]: T[K];
|
|
25
|
+
} & RegisteredPlugins;
|
|
20
26
|
/**
|
|
21
27
|
* Creates a test layer with mock ModuleFederationService for unit testing.
|
|
22
28
|
* This mirrors PluginService.Live() but uses mock ModuleFederationService.
|
|
23
29
|
*/
|
|
24
|
-
export declare const createTestLayer: <R extends
|
|
30
|
+
export declare const createTestLayer: <R extends RegisteredPlugins = RegisteredPlugins>(config: PluginRuntimeConfig<R>, pluginMap: PluginMap) => Layer.Layer<PluginService, never, never>;
|
|
25
31
|
/**
|
|
26
32
|
* Creates a plugin runtime for locally available plugins (non-remote).
|
|
27
33
|
* Automatically infers type bindings from the plugin map, eliminating
|
|
@@ -43,11 +49,11 @@ export declare const createTestLayer: <R extends RegistryBindings = RegistryBind
|
|
|
43
49
|
* const plugin = await runtime.usePlugin("my-plugin", config);
|
|
44
50
|
* ```
|
|
45
51
|
*/
|
|
46
|
-
export declare function createLocalPluginRuntime<
|
|
52
|
+
export declare function createLocalPluginRuntime<TMap extends PluginMap & ValidatePluginMap<TMap>>(config: PluginRuntimeConfig, pluginMap: TMap): PluginRuntime<InferBindingsFromMap<TMap>>;
|
|
47
53
|
/**
|
|
48
54
|
* @deprecated Use `createLocalPluginRuntime` instead. This alias is kept for backward compatibility.
|
|
49
55
|
*/
|
|
50
56
|
export declare const createTestPluginRuntime: typeof createLocalPluginRuntime;
|
|
51
|
-
export type { PluginRegistry,
|
|
57
|
+
export type { EveryPlugin, PluginRegistry, RegisteredPlugins } from "../types";
|
|
52
58
|
export type { PluginMap, PluginRuntimeConfig };
|
|
53
59
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,QAAQ,CAAC;AAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.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SAAS,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,55 +1,76 @@
|
|
|
1
|
-
import type { AnyContractRouter, AnySchema, InferSchemaOutput } from "@orpc/contract";
|
|
1
|
+
import type { AnyContractRouter, AnySchema, InferSchemaInput, InferSchemaOutput } from "@orpc/contract";
|
|
2
2
|
import type { Context, Router, RouterClient } from "@orpc/server";
|
|
3
3
|
import type { Scope } from "effect";
|
|
4
4
|
import type { Plugin } from "./plugin";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Registry bindings interface - populated via module augmentation
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* declare module "every-plugin" {
|
|
10
|
+
* interface RegisteredPlugins {
|
|
11
|
+
* "my-plugin": typeof MyPlugin;
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface RegisteredPlugins {
|
|
17
|
+
}
|
|
6
18
|
/**
|
|
7
19
|
* Base type for any plugin instance.
|
|
8
|
-
* This is the foundation that enables type inference across the entire plugin system.
|
|
9
|
-
* Uses 'any' for context to allow plugins with custom context types.
|
|
10
20
|
*/
|
|
11
21
|
export type AnyPlugin = Plugin<AnyContractRouter, AnySchema, AnySchema, any>;
|
|
12
22
|
/**
|
|
13
|
-
*
|
|
14
|
-
* This is a type-only construct that enables full IDE autocomplete and type safety
|
|
15
|
-
* without requiring runtime plugin imports.
|
|
23
|
+
* Extract plugin type from registered plugins by key
|
|
16
24
|
*/
|
|
17
|
-
export type
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
export type RegisteredPlugin<K extends keyof RegisteredPlugins> = RegisteredPlugins[K] extends {
|
|
26
|
+
binding: infer B;
|
|
27
|
+
} ? B extends {
|
|
28
|
+
contract: infer C extends AnyContractRouter;
|
|
29
|
+
variables: infer V extends AnySchema;
|
|
30
|
+
secrets: infer S extends AnySchema;
|
|
31
|
+
context: infer TContext extends Context;
|
|
32
|
+
} ? Plugin<C, V, S, TContext> : never : never;
|
|
24
33
|
/**
|
|
25
|
-
*
|
|
26
|
-
* This enables type inference: Binding → Plugin → Router → Client
|
|
34
|
+
* Extract router type from plugin binding
|
|
27
35
|
*/
|
|
28
|
-
export type
|
|
29
|
-
contract: infer C;
|
|
30
|
-
config: infer Conf;
|
|
31
|
-
} ? Conf extends {
|
|
32
|
-
variables: infer V;
|
|
33
|
-
secrets: infer S;
|
|
34
|
-
} ? V extends AnySchema ? S extends AnySchema ? C extends AnyContractRouter ? Plugin<C, V, S, Context> : never : never : never : never : never;
|
|
36
|
+
export type PluginRouterType<T> = Router<PluginContract<T>, PluginContext<T>>;
|
|
35
37
|
/**
|
|
36
|
-
*
|
|
37
|
-
* This provides strongly-typed configuration based on the plugin's schema.
|
|
38
|
+
* Extract client type from plugin binding
|
|
38
39
|
*/
|
|
39
|
-
export type
|
|
40
|
+
export type PluginClientType<T> = RouterClient<Router<PluginContract<T>, PluginContext<T>>>;
|
|
41
|
+
export type PluginContract<T> = T extends {
|
|
42
|
+
binding: {
|
|
43
|
+
contract: infer C extends AnyContractRouter;
|
|
44
|
+
};
|
|
45
|
+
} ? C : never;
|
|
46
|
+
export type PluginVariables<T> = T extends {
|
|
47
|
+
binding: {
|
|
48
|
+
variables: infer V extends AnySchema;
|
|
49
|
+
};
|
|
50
|
+
} ? V : never;
|
|
51
|
+
export type PluginSecrets<T> = T extends {
|
|
52
|
+
binding: {
|
|
53
|
+
secrets: infer S extends AnySchema;
|
|
54
|
+
};
|
|
55
|
+
} ? S : never;
|
|
56
|
+
export type PluginContext<T> = T extends {
|
|
57
|
+
binding: {
|
|
58
|
+
context: infer C extends Context;
|
|
59
|
+
};
|
|
60
|
+
} ? C : never;
|
|
40
61
|
/**
|
|
41
|
-
*
|
|
42
|
-
* Supports host context composition via THostContext type parameter
|
|
62
|
+
* Extract config input type from plugin binding
|
|
43
63
|
*/
|
|
44
|
-
export type
|
|
64
|
+
export type PluginConfigInput<T> = {
|
|
65
|
+
variables: InferSchemaInput<PluginVariables<T>>;
|
|
66
|
+
secrets: InferSchemaInput<PluginSecrets<T>>;
|
|
67
|
+
};
|
|
45
68
|
/**
|
|
46
|
-
*
|
|
47
|
-
* This is used for typing the router client context parameter.
|
|
69
|
+
* Extract context type from plugin instance
|
|
48
70
|
*/
|
|
49
71
|
export type ContextOf<T extends AnyPlugin> = T extends Plugin<AnyContractRouter, AnySchema, AnySchema, infer TContext> ? TContext : never;
|
|
50
72
|
/**
|
|
51
73
|
* Runtime registry configuration.
|
|
52
|
-
* Maps plugin IDs to their remote URLs and metadata.
|
|
53
74
|
*/
|
|
54
75
|
export type PluginRegistry = Record<string, PluginMetadata>;
|
|
55
76
|
/**
|
|
@@ -60,8 +81,7 @@ export interface SecretsConfig {
|
|
|
60
81
|
[key: string]: string;
|
|
61
82
|
}
|
|
62
83
|
/**
|
|
63
|
-
*
|
|
64
|
-
* Contains information about the plugin that persists across different stages.
|
|
84
|
+
* Plugin metadata
|
|
65
85
|
*/
|
|
66
86
|
export type PluginMetadata = {
|
|
67
87
|
readonly remoteUrl: string;
|
|
@@ -69,22 +89,21 @@ export type PluginMetadata = {
|
|
|
69
89
|
readonly description?: string;
|
|
70
90
|
};
|
|
71
91
|
/**
|
|
72
|
-
* Loaded plugin
|
|
92
|
+
* Loaded plugin
|
|
73
93
|
*/
|
|
74
94
|
export interface LoadedPlugin<T extends AnyPlugin = AnyPlugin> {
|
|
75
95
|
readonly ctor: new () => T;
|
|
76
96
|
readonly metadata: PluginMetadata;
|
|
77
97
|
}
|
|
78
98
|
/**
|
|
79
|
-
* Instantiated plugin
|
|
99
|
+
* Instantiated plugin
|
|
80
100
|
*/
|
|
81
101
|
export interface PluginInstance<T extends AnyPlugin = AnyPlugin> {
|
|
82
102
|
readonly plugin: T;
|
|
83
103
|
readonly metadata: PluginMetadata;
|
|
84
104
|
}
|
|
85
105
|
/**
|
|
86
|
-
* Fully initialized plugin ready for use
|
|
87
|
-
* Contains the plugin instance, validated config, execution context, and scope.
|
|
106
|
+
* Fully initialized plugin ready for use
|
|
88
107
|
*/
|
|
89
108
|
export interface InitializedPlugin<T extends AnyPlugin = AnyPlugin> {
|
|
90
109
|
readonly plugin: T;
|
|
@@ -97,57 +116,59 @@ export interface InitializedPlugin<T extends AnyPlugin = AnyPlugin> {
|
|
|
97
116
|
readonly scope: Scope.CloseableScope;
|
|
98
117
|
}
|
|
99
118
|
/**
|
|
100
|
-
*
|
|
119
|
+
* Helper type to detect type errors when looking up RegisteredPlugins
|
|
120
|
+
*/
|
|
121
|
+
type VerifyPluginBinding<K extends keyof RegisteredPlugins> = RegisteredPlugins[K] extends {
|
|
122
|
+
binding: infer B;
|
|
123
|
+
} ? B extends {
|
|
124
|
+
contract: AnyContractRouter;
|
|
125
|
+
variables: AnySchema;
|
|
126
|
+
secrets: AnySchema;
|
|
127
|
+
context: Context;
|
|
128
|
+
} ? true : `❌ Plugin "${K & string}" is not properly registered. Ensure it extends plugin binding layout { contract, variables, secrets, context }.` : `❌ Plugin "${K & string}" is not properly registered. Missing binding property.`;
|
|
129
|
+
/**
|
|
130
|
+
* Result of runtime.usePlugin() call
|
|
131
|
+
*/
|
|
132
|
+
export type UsePluginResult<K extends keyof RegisteredPlugins> = VerifyPluginBinding<K> extends true ? {
|
|
133
|
+
readonly client: PluginClientType<RegisteredPlugins[K]>;
|
|
134
|
+
readonly router: PluginRouterType<RegisteredPlugins[K]>;
|
|
135
|
+
readonly metadata: PluginMetadata;
|
|
136
|
+
readonly initialized: InitializedPlugin<RegisteredPlugin<K>>;
|
|
137
|
+
} : VerifyPluginBinding<K>;
|
|
138
|
+
/**
|
|
139
|
+
* Runtime options
|
|
101
140
|
*/
|
|
102
141
|
export interface RuntimeOptions {
|
|
103
|
-
/** Resource isolation level for plugins */
|
|
104
142
|
isolation?: "strict" | "shared" | "none";
|
|
105
|
-
/** Memory limit per plugin instance */
|
|
106
143
|
memoryLimit?: string;
|
|
107
|
-
/** Maximum concurrent plugin operations */
|
|
108
144
|
concurrency?: number;
|
|
109
|
-
/** Resource timeout for plugin operations */
|
|
110
145
|
resourceTimeout?: string;
|
|
111
|
-
/** Enable debug logging */
|
|
112
146
|
debug?: boolean;
|
|
113
|
-
/** Enable metrics collection */
|
|
114
147
|
metrics?: boolean;
|
|
115
148
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Enhanced plugin result containing client, router, and metadata.
|
|
118
|
-
* Router is typed as ContractRouter for encapsulation, but runtime compatible with oRPC routers.
|
|
119
|
-
* Supports host context composition through THostContext type parameter.
|
|
120
|
-
*/
|
|
121
|
-
export interface EveryPlugin<T extends AnyPlugin = AnyPlugin, THostContext extends Context = Record<never, never>> {
|
|
122
|
-
readonly client: RouterClient<PluginRouter<T, THostContext>, THostContext>;
|
|
123
|
-
readonly router: PluginRouter<T, THostContext>;
|
|
124
|
-
readonly metadata: PluginMetadata;
|
|
125
|
-
readonly initialized: InitializedPlugin<T>;
|
|
126
|
-
}
|
|
127
149
|
/**
|
|
128
150
|
* Namespace containing type utilities for working with plugin results.
|
|
129
151
|
*/
|
|
130
152
|
export declare namespace EveryPlugin {
|
|
131
153
|
/**
|
|
132
|
-
* Extract
|
|
154
|
+
* Extract plugin runtime instance type from registered plugins.
|
|
133
155
|
* Provides full type safety for plugin clients, routers, and metadata.
|
|
134
156
|
*
|
|
135
157
|
* @example
|
|
136
158
|
* ```ts
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* plugin = await runtime.usePlugin("my-plugin", config);
|
|
159
|
+
* type Plugin = EveryPlugin.Infer<"my-plugin">;
|
|
160
|
+
* const plugin: Plugin = await runtime.usePlugin("my-plugin", config);
|
|
140
161
|
* ```
|
|
141
162
|
*/
|
|
142
|
-
type Infer<
|
|
163
|
+
type Infer<K extends keyof RegisteredPlugins> = UsePluginResult<K>;
|
|
143
164
|
}
|
|
144
165
|
/**
|
|
145
|
-
*
|
|
146
|
-
* The generic R parameter enables compile-time type safety when provided.
|
|
166
|
+
* Plugin runtime configuration
|
|
147
167
|
*/
|
|
148
|
-
export interface PluginRuntimeConfig<R extends
|
|
168
|
+
export interface PluginRuntimeConfig<R extends RegisteredPlugins = RegisteredPlugins> {
|
|
149
169
|
registry: PluginRegistry;
|
|
150
170
|
secrets?: SecretsConfig;
|
|
151
171
|
options?: RuntimeOptions;
|
|
152
172
|
}
|
|
173
|
+
export {};
|
|
153
174
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,iBAAiB;CAAI;AAEtC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,iBAAiB,IAC5D,iBAAiB,CAAC,CAAC,CAAC,SAAS;IAAE,OAAO,EAAE,MAAM,CAAC,CAAA;CAAE,GAC/C,CAAC,SAAS;IACV,Q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-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
2
|
+
"name": "every-plugin",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"default": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./runtime": {
|
|
12
|
+
"types": "./dist/runtime/index.d.ts",
|
|
13
|
+
"default": "./dist/runtime/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client/index.d.ts",
|
|
17
|
+
"default": "./dist/client/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./testing": {
|
|
20
|
+
"types": "./dist/testing/index.d.ts",
|
|
21
|
+
"default": "./dist/testing/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./normalize": {
|
|
24
|
+
"types": "./dist/runtime/services/normalize.d.ts",
|
|
25
|
+
"require": "./dist/runtime/services/normalize.js",
|
|
26
|
+
"default": "./dist/runtime/services/normalize.js"
|
|
27
|
+
},
|
|
28
|
+
"./effect": {
|
|
29
|
+
"types": "./dist/effect.d.ts",
|
|
30
|
+
"default": "./dist/effect.js"
|
|
31
|
+
},
|
|
32
|
+
"./zod": {
|
|
33
|
+
"types": "./dist/zod.d.ts",
|
|
34
|
+
"default": "./dist/zod.js"
|
|
35
|
+
},
|
|
36
|
+
"./orpc": {
|
|
37
|
+
"types": "./dist/orpc.d.ts",
|
|
38
|
+
"default": "./dist/orpc.js"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -b tsconfig.build.json",
|
|
47
|
+
"build:test": "cd tests/fixtures/test-plugin && bun run build",
|
|
48
|
+
"test": "vitest run --config vitest.config.ts",
|
|
49
|
+
"test:unit": "vitest run --config vitest.config.ts",
|
|
50
|
+
"test:integration": "bun run build:test && vitest run --config vitest.integration.config.ts",
|
|
51
|
+
"test:all": "bun run test:unit && bun run test:integration",
|
|
52
|
+
"test:watch": "vitest --config vitest.config.ts --watch",
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"typescript": "^5.6.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@effect/language-service": "^0.38.4",
|
|
60
|
+
"@effect/vitest": "^0.25.1",
|
|
61
|
+
"@orpc/client": "^1.10.0",
|
|
62
|
+
"@orpc/openapi": "^1.10.0",
|
|
63
|
+
"@orpc/zod": "^1.10.0",
|
|
64
|
+
"@rspack/cli": "^1.5.8",
|
|
65
|
+
"@rspack/core": "^1.5.8",
|
|
66
|
+
"@types/bun": "^1.3.0",
|
|
67
|
+
"@types/node": "^24.9.0",
|
|
68
|
+
"@vitest/ui": "3.2.4",
|
|
69
|
+
"bun-types": "^1.3.0",
|
|
70
|
+
"sirv": "^3.0.2",
|
|
71
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
72
|
+
"vitest": "^3.2.4"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@better-fetch/fetch": "^1.1.18",
|
|
76
|
+
"@module-federation/enhanced": "^0.19.1",
|
|
77
|
+
"@module-federation/node": "^2.7.15",
|
|
78
|
+
"@module-federation/runtime-core": "^0.19.1",
|
|
79
|
+
"@orpc/contract": "^1.10.0",
|
|
80
|
+
"@orpc/experimental-publisher": "^1.10.0",
|
|
81
|
+
"@orpc/server": "^1.10.0",
|
|
82
|
+
"effect": "3.18.1",
|
|
83
|
+
"zod": "4.1.5"
|
|
84
|
+
},
|
|
85
|
+
"keywords": [
|
|
86
|
+
"plugin",
|
|
87
|
+
"module-federation",
|
|
88
|
+
"orpc",
|
|
89
|
+
"zod",
|
|
90
|
+
"typescript"
|
|
91
|
+
],
|
|
92
|
+
"author": "plugin.every.near",
|
|
93
|
+
"license": "MIT",
|
|
94
|
+
"repository": {
|
|
95
|
+
"type": "git",
|
|
96
|
+
"url": "https://github.com/near-everything/every-plugin.git"
|
|
97
|
+
},
|
|
98
|
+
"bugs": {
|
|
99
|
+
"url": "https://github.com/near-everything/every-plugin/issues"
|
|
100
|
+
},
|
|
101
|
+
"homepage": "https://plugin.everything.dev",
|
|
102
|
+
"workspaces": [
|
|
103
|
+
"tests/fixtures/*"
|
|
104
|
+
]
|
|
105
105
|
}
|
package/dist/client/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type ClientContext, type CreateProcedureClientOptions, type ErrorMap, type InferRouterInitialContext, type Meta, type RouterClient, type Schema } from "@orpc/server";
|
|
2
|
-
import type { AnyPlugin, InitializedPlugin, PluginRouter } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* Extracts the oRPC router from an initialized plugin.
|
|
5
|
-
* The router type is precisely inferred from the plugin's contract.
|
|
6
|
-
* Useful for mounting into HTTP frameworks or direct router usage.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getPluginRouter<T extends AnyPlugin>(initialized: InitializedPlugin<T>): PluginRouter<T>;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a fully type-safe client for calling plugin procedures as methods.
|
|
11
|
-
* The client type is precisely inferred from the plugin's contract, providing
|
|
12
|
-
* complete autocomplete and type safety for all procedures, inputs, and outputs.
|
|
13
|
-
*
|
|
14
|
-
* Type safety flows: Plugin Contract → Router → RouterClient with full procedure autocomplete
|
|
15
|
-
*/
|
|
16
|
-
export declare function createPluginClient<T extends AnyPlugin, TClientContext extends ClientContext = Record<never, never>>(initialized: InitializedPlugin<T>, options?: CreateProcedureClientOptions<InferRouterInitialContext<PluginRouter<T>>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>): RouterClient<PluginRouter<T>, TClientContext>;
|
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,4BAA4B,EAEjC,KAAK,QAAQ,EACb,KAAK,yBAAyB,EAC9B,KAAK,IAAI,EAET,KAAK,YAAY,EACjB,KAAK,MAAM,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAa,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEtF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,SAAS,EACjD,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAChC,YAAY,CAAC,CAAC,CAAC,CAmBjB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,SAAS,EACnB,cAAc,SAAS,aAAa,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE3D,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,EACjC,OAAO,CAAC,EAAE,4BAA4B,CACpC,yBAAyB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAC1C,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,EACxB,QAAQ,EACR,IAAI,EACJ,cAAc,CACf,GACA,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAS/C"}
|
package/dist/client/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createRouterClient } from "@orpc/server";
|
|
2
|
-
/**
|
|
3
|
-
* Extracts the oRPC router from an initialized plugin.
|
|
4
|
-
* The router type is precisely inferred from the plugin's contract.
|
|
5
|
-
* Useful for mounting into HTTP frameworks or direct router usage.
|
|
6
|
-
*/
|
|
7
|
-
export function getPluginRouter(initialized) {
|
|
8
|
-
if (!initialized) {
|
|
9
|
-
throw new Error("InitializedPlugin is undefined - plugin initialization failed");
|
|
10
|
-
}
|
|
11
|
-
if (!initialized.plugin) {
|
|
12
|
-
throw new Error("Plugin instance is undefined - check service layer dependencies (ModuleFederationService, SecretsService)");
|
|
13
|
-
}
|
|
14
|
-
if (typeof initialized.plugin.createRouter !== "function") {
|
|
15
|
-
throw new Error(`Plugin ${initialized.plugin.id || 'unknown'} does not have a createRouter method`);
|
|
16
|
-
}
|
|
17
|
-
if (!initialized.context) {
|
|
18
|
-
throw new Error("Plugin context is undefined - plugin initialization incomplete");
|
|
19
|
-
}
|
|
20
|
-
const router = initialized.plugin.createRouter(initialized.context);
|
|
21
|
-
return router;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Creates a fully type-safe client for calling plugin procedures as methods.
|
|
25
|
-
* The client type is precisely inferred from the plugin's contract, providing
|
|
26
|
-
* complete autocomplete and type safety for all procedures, inputs, and outputs.
|
|
27
|
-
*
|
|
28
|
-
* Type safety flows: Plugin Contract → Router → RouterClient with full procedure autocomplete
|
|
29
|
-
*/
|
|
30
|
-
export function createPluginClient(initialized, options) {
|
|
31
|
-
const router = getPluginRouter(initialized);
|
|
32
|
-
return createRouterClient(router, options);
|
|
33
|
-
}
|