every-plugin 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +1 -329
  2. package/dist/errors.d.ts +4 -4
  3. package/dist/errors.js +10 -10
  4. package/dist/index.d.ts +2 -4
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -3
  7. package/dist/plugin.d.ts +89 -103
  8. package/dist/plugin.d.ts.map +1 -1
  9. package/dist/plugin.js +104 -23
  10. package/dist/runtime/errors.d.ts +36 -53
  11. package/dist/runtime/errors.js +8 -8
  12. package/dist/runtime/index.d.ts +17 -66
  13. package/dist/runtime/index.d.ts.map +1 -1
  14. package/dist/runtime/index.js +22 -126
  15. package/dist/runtime/services/module-federation.service.d.ts +10 -38
  16. package/dist/runtime/services/module-federation.service.d.ts.map +1 -1
  17. package/dist/runtime/services/module-federation.service.js +139 -124
  18. package/dist/runtime/services/plugin.service.d.ts +21 -67
  19. package/dist/runtime/services/plugin.service.d.ts.map +1 -1
  20. package/dist/runtime/services/plugin.service.js +263 -328
  21. package/dist/runtime/services/secrets.service.d.ts +9 -29
  22. package/dist/runtime/services/secrets.service.js +26 -30
  23. package/dist/runtime/services.d.ts +1 -1
  24. package/dist/runtime/streaming/index.d.ts +4 -0
  25. package/dist/runtime/streaming/index.d.ts.map +1 -0
  26. package/dist/runtime/streaming/index.js +2 -0
  27. package/dist/runtime/streaming/state-effects.d.ts +28 -0
  28. package/dist/runtime/streaming/state-effects.d.ts.map +1 -0
  29. package/dist/runtime/streaming/state-effects.js +30 -0
  30. package/dist/runtime/streaming/streaming.d.ts +8 -0
  31. package/dist/runtime/streaming/streaming.d.ts.map +1 -0
  32. package/dist/runtime/streaming/streaming.js +107 -0
  33. package/dist/runtime/streaming/types.d.ts +19 -0
  34. package/dist/runtime/streaming/types.d.ts.map +1 -0
  35. package/dist/runtime/streaming/types.js +1 -0
  36. package/dist/runtime/test-utils.d.ts +1 -1
  37. package/dist/runtime/test-utils.js +4 -10
  38. package/dist/runtime/types.d.ts +28 -28
  39. package/dist/runtime/types.d.ts.map +1 -1
  40. package/dist/runtime/validation.d.ts +2 -7
  41. package/dist/runtime/validation.js +11 -14
  42. package/dist/testing/index.d.ts +25 -0
  43. package/dist/testing/index.d.ts.map +1 -0
  44. package/dist/testing/index.js +40 -0
  45. package/dist/testing/mocks/module-federation.service.d.ts +8 -0
  46. package/dist/testing/mocks/module-federation.service.d.ts.map +1 -0
  47. package/dist/testing/mocks/module-federation.service.js +35 -0
  48. package/package.json +21 -4
  49. package/dist/runtime/mf.test.d.ts +0 -2
  50. package/dist/runtime/mf.test.d.ts.map +0 -1
  51. package/dist/runtime/mf.test.js +0 -135
  52. package/dist/runtime/runtime.test.d.ts +0 -2
  53. package/dist/runtime/runtime.test.d.ts.map +0 -1
  54. package/dist/runtime/runtime.test.js +0 -378
  55. package/dist/runtime/streaming.d.ts +0 -29
  56. package/dist/runtime/streaming.d.ts.map +0 -1
  57. package/dist/runtime/streaming.js +0 -59
  58. package/dist/runtime/streaming.test.d.ts +0 -2
  59. package/dist/runtime/streaming.test.d.ts.map +0 -1
  60. package/dist/runtime/streaming.test.js +0 -271
  61. package/dist/source.d.ts +0 -70
  62. package/dist/source.d.ts.map +0 -1
  63. package/dist/source.js +0 -37
package/dist/plugin.js CHANGED
@@ -1,27 +1,108 @@
1
- import { Context } from "effect";
1
+ import { Context, Effect } from "effect";
2
2
  import { z } from "zod";
3
- // Helpers
4
- export const createOutputSchema = (dataSchema) =>
5
- z.object({
6
- success: z.boolean(),
7
- data: dataSchema.optional(),
8
- errors: z.array(ErrorDetailsSchema).optional(),
9
- });
10
3
  export function createConfigSchema(variablesSchema, secretsSchema) {
11
- return z.object({
12
- variables: (
13
- variablesSchema ?? z.record(z.string(), z.unknown())
14
- ).optional(),
15
- secrets: (secretsSchema ?? z.record(z.string(), z.unknown())).optional(),
16
- });
4
+ return z.object({
5
+ variables: variablesSchema ? variablesSchema.optional() : z.record(z.string(), z.unknown()).optional(),
6
+ secrets: secretsSchema ? secretsSchema.optional() : z.record(z.string(), z.unknown()).optional(),
7
+ });
17
8
  }
18
- export function createInputSchema(inputSchema) {
19
- return inputSchema;
9
+ export function createStateSchema(pluginStateSchema) {
10
+ const BaseStreamingStateSchema = z.object({
11
+ nextPollMs: z.number().nullable().optional(), // null = terminate, undefined/0 = no delay, number = delay ms
12
+ });
13
+ return BaseStreamingStateSchema.and(pluginStateSchema);
14
+ }
15
+ export class PluginLoggerTag extends Context.Tag("PluginLogger")() {
16
+ }
17
+ /**
18
+ * Schema creators for contract-based plugins
19
+ */
20
+ export function createPluginInputSchema(contract, stateSchema) {
21
+ const contractEntries = Object.entries(contract);
22
+ const procedureSchemas = contractEntries.map(([procedureName, procedureSpec]) => {
23
+ // Extract input and output schemas from oRPC contract procedure
24
+ const inputSchema = procedureSpec['~orpc']?.inputSchema || z.object({});
25
+ const outputSchema = procedureSpec['~orpc']?.outputSchema || z.object({});
26
+ // Check if this procedure is streamable (has nextState in output)
27
+ const isStreamable = outputSchema._def?.shape?.nextState !== undefined;
28
+ const baseSchema = z.object({
29
+ procedure: z.literal(procedureName),
30
+ input: inputSchema,
31
+ });
32
+ // Only add state field for streamable procedures
33
+ return isStreamable
34
+ ? baseSchema.extend({ state: stateSchema })
35
+ : baseSchema;
36
+ });
37
+ return z.discriminatedUnion("procedure", procedureSchemas);
38
+ }
39
+ export function createPluginOutputSchema(contract, stateSchema) {
40
+ const contractEntries = Object.entries(contract);
41
+ const procedureOutputSchemas = contractEntries.map(([_, procedureSpec]) => {
42
+ // Extract output schema from oRPC contract procedure
43
+ return procedureSpec['~orpc']?.outputSchema || z.object({});
44
+ });
45
+ // Return union of all procedure output schemas
46
+ return z.union(procedureOutputSchemas);
47
+ }
48
+ /**
49
+ * State transition utilities for plugins
50
+ * These provide a functional approach to state updates while keeping the API simple
51
+ */
52
+ export const StateTransitions = {
53
+ /**
54
+ * Transition to a new phase with optional updates
55
+ */
56
+ to: (phase, updates = {}) => (state) => ({ ...state, phase, ...updates }),
57
+ /**
58
+ * Add polling delay to state
59
+ */
60
+ withPolling: (delayMs) => (state) => ({ ...state, nextPollMs: delayMs }),
61
+ /**
62
+ * Set error state with message and stop polling
63
+ */
64
+ withError: (errorMessage) => (state) => ({
65
+ ...state,
66
+ phase: 'error',
67
+ errorMessage,
68
+ nextPollMs: null
69
+ }),
70
+ /**
71
+ * Preserve existing state with updates
72
+ */
73
+ update: (updates) => (state) => ({ ...state, ...updates }),
74
+ };
75
+ /**
76
+ * Simple pipe utility for composing state transformations
77
+ */
78
+ export const pipe = (value, ...fns) => fns.reduce((acc, fn) => fn(acc), value);
79
+ /**
80
+ * Simple plugin base class that uses pure oRPC patterns
81
+ * Plugin just needs to define contract, config, and create oRPC router
82
+ */
83
+ export class SimplePlugin {
84
+ stateSchema = z.null();
85
+ // Auto-generated schemas
86
+ get inputSchema() {
87
+ return createPluginInputSchema(this.contract, this.stateSchema);
88
+ }
89
+ get outputSchema() {
90
+ return createPluginOutputSchema(this.contract, this.stateSchema);
91
+ }
92
+ // Default implementations - runtime handles validation
93
+ initialize(config) {
94
+ return Effect.void;
95
+ }
96
+ shutdown() {
97
+ return Effect.void;
98
+ }
99
+ // Default streamable detection
100
+ isStreamable(procedureName) {
101
+ const contractEntries = Object.entries(this.contract);
102
+ const procedure = contractEntries.find(([name]) => name === procedureName);
103
+ if (!procedure)
104
+ return false;
105
+ const outputSchema = procedure[1]['~orpc']?.outputSchema;
106
+ return outputSchema?._def?.shape?.nextState !== undefined;
107
+ }
20
108
  }
21
- // Core schemas
22
- export const ErrorDetailsSchema = z.object({
23
- message: z.string(),
24
- details: z.record(z.string(), z.unknown()).optional(),
25
- stack: z.string().optional(),
26
- });
27
- export class PluginLoggerTag extends Context.Tag("PluginLogger")() {}
@@ -1,62 +1,45 @@
1
1
  import type { z } from "zod";
2
- declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(
3
- args: import("effect/Types").Equals<A, {}> extends true
4
- ? void
5
- : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] },
6
- ) => import("effect/Cause").YieldableError & {
7
- readonly _tag: "PluginRuntimeError";
2
+ declare const PluginRuntimeError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
3
+ readonly _tag: "PluginRuntimeError";
8
4
  } & Readonly<A>;
9
5
  export declare class PluginRuntimeError extends PluginRuntimeError_base<{
10
- readonly pluginId?: string;
11
- readonly operation: string;
12
- readonly cause?: Error;
13
- readonly retryable: boolean;
14
- }> {}
15
- declare const ModuleFederationError_base: new <
16
- A extends Record<string, any> = {},
17
- >(
18
- args: import("effect/Types").Equals<A, {}> extends true
19
- ? void
20
- : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] },
21
- ) => import("effect/Cause").YieldableError & {
22
- readonly _tag: "ModuleFederationError";
6
+ readonly pluginId?: string;
7
+ readonly operation: string;
8
+ readonly cause?: Error;
9
+ readonly retryable: boolean;
10
+ }> {
11
+ }
12
+ declare const ModuleFederationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
13
+ readonly _tag: "ModuleFederationError";
23
14
  } & Readonly<A>;
24
15
  export declare class ModuleFederationError extends ModuleFederationError_base<{
25
- readonly pluginId: string;
26
- readonly remoteUrl: string;
27
- readonly cause?: Error;
28
- }> {}
29
- declare const ValidationError_base: new <A extends Record<string, any> = {}>(
30
- args: import("effect/Types").Equals<A, {}> extends true
31
- ? void
32
- : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] },
33
- ) => import("effect/Cause").YieldableError & {
34
- readonly _tag: "ValidationError";
16
+ readonly pluginId: string;
17
+ readonly remoteUrl: string;
18
+ readonly cause?: Error;
19
+ }> {
20
+ }
21
+ declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
22
+ readonly _tag: "ValidationError";
35
23
  } & Readonly<A>;
36
24
  export declare class ValidationError extends ValidationError_base<{
37
- readonly pluginId: string;
38
- readonly stage: "config" | "input" | "output" | "state";
39
- readonly zodError: z.ZodError;
40
- }> {}
41
- declare const StreamError_base: new <A extends Record<string, any> = {}>(
42
- args: import("effect/Types").Equals<A, {}> extends true
43
- ? void
44
- : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] },
45
- ) => import("effect/Cause").YieldableError & {
46
- readonly _tag: "StreamError";
25
+ readonly pluginId: string;
26
+ readonly stage: "config" | "input" | "output" | "state";
27
+ readonly zodError: z.ZodError;
28
+ }> {
29
+ }
30
+ declare const StreamError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
31
+ readonly _tag: "StreamError";
47
32
  } & Readonly<A>;
48
33
  export declare class StreamError extends StreamError_base<{
49
- readonly pluginId: string;
50
- readonly operation:
51
- | "callback"
52
- | "state-extraction"
53
- | "item-extraction"
54
- | "stream-termination";
55
- readonly cause?: Error;
56
- readonly context?: {
57
- readonly iteration?: number;
58
- readonly itemsProcessed?: number;
59
- readonly procedureName?: string;
60
- };
61
- }> {}
62
- //# sourceMappingURL=errors.d.ts.map
34
+ readonly pluginId: string;
35
+ readonly operation: "callback" | "state-extraction" | "item-extraction" | "stream-termination";
36
+ readonly cause?: Error;
37
+ readonly context?: {
38
+ readonly iteration?: number;
39
+ readonly itemsProcessed?: number;
40
+ readonly procedureName?: string;
41
+ };
42
+ }> {
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=errors.d.ts.map
@@ -1,9 +1,9 @@
1
1
  import { Data } from "effect";
2
- export class PluginRuntimeError extends Data.TaggedError(
3
- "PluginRuntimeError",
4
- ) {}
5
- export class ModuleFederationError extends Data.TaggedError(
6
- "ModuleFederationError",
7
- ) {}
8
- export class ValidationError extends Data.TaggedError("ValidationError") {}
9
- export class StreamError extends Data.TaggedError("StreamError") {}
2
+ export class PluginRuntimeError extends Data.TaggedError("PluginRuntimeError") {
3
+ }
4
+ export class ModuleFederationError extends Data.TaggedError("ModuleFederationError") {
5
+ }
6
+ export class ValidationError extends Data.TaggedError("ValidationError") {
7
+ }
8
+ export class StreamError extends Data.TaggedError("StreamError") {
9
+ }
@@ -1,73 +1,24 @@
1
1
  import { Effect, Layer, ManagedRuntime, type Stream } from "effect";
2
2
  import type { z } from "zod";
3
- import type { SourcePlugin } from "../source";
3
+ import { type Plugin } from "../plugin";
4
4
  import { PluginRuntimeError } from "./errors";
5
- import { type SourceStreamOptions } from "./streaming";
6
- import type {
7
- AnyPlugin,
8
- InitializedPlugin,
9
- PluginConstructor,
10
- PluginInstance,
11
- PluginRuntimeConfig,
12
- } from "./types";
5
+ import { type StreamingOptions } from "./streaming";
6
+ import type { AnyPlugin, InitializedPlugin, PluginConstructor, PluginInstance, PluginRuntimeConfig } from "./types";
13
7
  export interface IPluginRuntime {
14
- readonly loadPlugin: (
15
- pluginId: string,
16
- ) => Effect.Effect<PluginConstructor, PluginRuntimeError>;
17
- readonly instantiatePlugin: <T extends AnyPlugin>(
18
- ctor: PluginConstructor,
19
- ) => Effect.Effect<PluginInstance<T>, PluginRuntimeError>;
20
- readonly initializePlugin: <T extends AnyPlugin>(
21
- instance: PluginInstance<T>,
22
- config: z.infer<T["configSchema"]>,
23
- ) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
24
- readonly executePlugin: <T extends AnyPlugin>(
25
- initializedPlugin: InitializedPlugin<T>,
26
- input: z.infer<T["inputSchema"]>,
27
- ) => Effect.Effect<z.infer<T["outputSchema"]>, PluginRuntimeError>;
28
- readonly usePlugin: <T extends AnyPlugin>(
29
- pluginId: string,
30
- config: z.infer<T["configSchema"]>,
31
- ) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
32
- readonly streamPlugin: <
33
- T extends SourcePlugin,
34
- TInput extends z.infer<T["inputSchema"]> = z.infer<T["inputSchema"]>,
35
- TItem = unknown,
36
- >(
37
- pluginId: string,
38
- config: z.infer<T["configSchema"]>,
39
- input: TInput,
40
- options?: SourceStreamOptions<TItem>,
41
- ) => Effect.Effect<
42
- Stream.Stream<TItem, PluginRuntimeError>,
43
- PluginRuntimeError
44
- >;
45
- readonly shutdown: () => Effect.Effect<void, never, never>;
8
+ readonly loadPlugin: (pluginId: string) => Effect.Effect<PluginConstructor, PluginRuntimeError>;
9
+ readonly instantiatePlugin: <T extends AnyPlugin>(ctor: PluginConstructor) => Effect.Effect<PluginInstance<T>, PluginRuntimeError>;
10
+ readonly initializePlugin: <T extends AnyPlugin>(instance: PluginInstance<T>, config: z.infer<T["configSchema"]>) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
11
+ readonly executePlugin: <T extends AnyPlugin>(initializedPlugin: InitializedPlugin<T>, input: z.infer<T["inputSchema"]>) => Effect.Effect<z.infer<T["outputSchema"]>, PluginRuntimeError>;
12
+ readonly usePlugin: <T extends AnyPlugin>(pluginId: string, config: z.infer<T["configSchema"]>) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
13
+ readonly streamPlugin: <T extends Plugin, TInput extends z.infer<T["inputSchema"]> = z.infer<T["inputSchema"]>, TItem = unknown, TPluginState extends z.infer<T["stateSchema"]> = z.infer<T["stateSchema"]>>(pluginId: string, config: z.infer<T["configSchema"]>, input: TInput, options?: StreamingOptions<TItem, TPluginState>) => Effect.Effect<Stream.Stream<TItem, PluginRuntimeError>, PluginRuntimeError>;
14
+ readonly shutdown: () => Effect.Effect<void, never, never>;
46
15
  }
47
- declare const PluginRuntime_base: import("effect/Context").TagClass<
48
- PluginRuntime,
49
- "PluginRuntime",
50
- IPluginRuntime
51
- > &
52
- Effect.Tag.Proxy<PluginRuntime, IPluginRuntime> & {
53
- use: <X>(
54
- body: (_: IPluginRuntime) => X,
55
- ) => [X] extends [Effect.Effect<infer A, infer E, infer R>]
56
- ? Effect.Effect<A, E, PluginRuntime | R>
57
- : [X] extends [PromiseLike<infer A_1>]
58
- ? Effect.Effect<
59
- A_1,
60
- import("effect/Cause").UnknownException,
61
- PluginRuntime
62
- >
63
- : Effect.Effect<X, never, PluginRuntime>;
64
- };
16
+ declare const PluginRuntime_base: import("effect/Context").TagClass<PluginRuntime, "PluginRuntime", IPluginRuntime> & Effect.Tag.Proxy<PluginRuntime, IPluginRuntime> & {
17
+ use: <X>(body: (_: IPluginRuntime) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, PluginRuntime | R> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, import("effect/Cause").UnknownException, PluginRuntime> : Effect.Effect<X, never, PluginRuntime>;
18
+ };
65
19
  export declare class PluginRuntime extends PluginRuntime_base {
66
- static Live: (
67
- config: PluginRuntimeConfig,
68
- ) => Layer.Layer<PluginRuntime, never, never>;
20
+ static Live: (config: PluginRuntimeConfig) => Layer.Layer<PluginRuntime, never, never>;
69
21
  }
70
- export declare const createPluginRuntime: (
71
- config: PluginRuntimeConfig,
72
- ) => ManagedRuntime.ManagedRuntime<PluginRuntime, never>;
73
- //# sourceMappingURL=index.d.ts.map
22
+ export declare const createPluginRuntime: (config: PluginRuntimeConfig) => ManagedRuntime.ManagedRuntime<PluginRuntime, never>;
23
+ export {};
24
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAA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AAC,CAAC;IAC7D,QAAQ,CAAC,YAAY,EAAE,CACtB,CAAC,SAAS,MAAM,EAChB,MAAM,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,EACpE,KAAK,GAAG,OAAO,EACf,YAAY,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,EAE1E,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,EAClC,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC,KAC3C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;CAC3D;;;;AAED,qBAAa,aAAc,SAAQ,kBAGhC;IACF,MAAM,CAAC,IAAI,GAAI,QAAQ,mBAAmB,8CA8CzC;CACD;AAED,eAAO,MAAM,mBAAmB,GAAI,QAAQ,mBAAmB,wDACf,CAAC"}
@@ -1,133 +1,29 @@
1
1
  import { Effect, Layer, ManagedRuntime } from "effect";
2
2
  import { PluginLoggerTag } from "../plugin";
3
- import { PluginRuntimeError } from "./errors";
4
- import {
5
- ModuleFederationService,
6
- PluginService,
7
- SecretsService,
8
- } from "./services";
9
- import { createSourceStream } from "./streaming";
10
- import { validate } from "./validation";
11
-
3
+ import { ModuleFederationService, PluginService, SecretsService, } from "./services";
12
4
  // Default logger implementation
13
5
  const createDefaultLogger = () => ({
14
- logInfo: (message, context) =>
15
- Effect.logInfo(message).pipe(
16
- Effect.annotateLogs({ source: "plugin", context }),
17
- ),
18
- logWarning: (message, context) =>
19
- Effect.logWarning(message).pipe(
20
- Effect.annotateLogs({ source: "plugin", context }),
21
- ),
22
- logError: (message, error, context) =>
23
- Effect.logError(message, error).pipe(
24
- Effect.annotateLogs({ source: "plugin", error, context }),
25
- ),
26
- logDebug: (message, context) =>
27
- Effect.logDebug(message).pipe(
28
- Effect.annotateLogs({ source: "plugin", context }),
29
- ),
6
+ logInfo: (message, context) => Effect.logInfo(message).pipe(Effect.annotateLogs({ source: "plugin", context })),
7
+ logWarning: (message, context) => Effect.logWarning(message).pipe(Effect.annotateLogs({ source: "plugin", context })),
8
+ logError: (message, error, context) => Effect.logError(message, error).pipe(Effect.annotateLogs({ source: "plugin", error, context })),
9
+ logDebug: (message, context) => Effect.logDebug(message).pipe(Effect.annotateLogs({ source: "plugin", context })),
30
10
  });
31
11
  export class PluginRuntime extends Effect.Tag("PluginRuntime")() {
32
- static Live = (config) => {
33
- const secrets = config.secrets || {};
34
- const logger = config.logger || createDefaultLogger();
35
- return Layer.effect(
36
- PluginRuntime,
37
- Effect.gen(function* () {
38
- const pluginService = yield* PluginService;
39
- return {
40
- loadPlugin: pluginService.loadPlugin,
41
- instantiatePlugin: pluginService.instantiatePlugin,
42
- initializePlugin: pluginService.initializePlugin,
43
- executePlugin: pluginService.executePlugin,
44
- usePlugin: (pluginId, config) =>
45
- pluginService.usePlugin(pluginId, config),
46
- streamPlugin: (pluginId, config, input, options) =>
47
- Effect.gen(function* () {
48
- // Get initialized plugin (benefits from caching)
49
- const initializedPlugin = yield* pluginService.usePlugin(
50
- pluginId,
51
- config,
52
- );
53
- // Validate plugin type
54
- if (initializedPlugin.plugin.type !== "source") {
55
- return yield* Effect.fail(
56
- new PluginRuntimeError({
57
- pluginId,
58
- operation: "stream-plugin-validate",
59
- cause: new Error(
60
- `Plugin ${pluginId} is not a source plugin (type: ${initializedPlugin.plugin.type})`,
61
- ),
62
- retryable: false,
63
- }),
64
- );
65
- }
66
- // Check if procedure is streamable and validate state
67
- const procedureName = input.procedure;
68
- const isStreamable =
69
- initializedPlugin.plugin.isStreamable(procedureName);
70
- if (isStreamable) {
71
- // Check stateSchema exists
72
- if (
73
- !("stateSchema" in initializedPlugin.plugin) ||
74
- !initializedPlugin.plugin.stateSchema
75
- ) {
76
- return yield* Effect.fail(
77
- new PluginRuntimeError({
78
- pluginId: initializedPlugin.plugin.id,
79
- operation: "validate-state",
80
- cause: new Error(
81
- `Streamable plugin ${initializedPlugin.plugin.id} must have a stateSchema`,
82
- ),
83
- retryable: false,
84
- }),
85
- );
86
- }
87
- // Validate initial state
88
- yield* validate(
89
- initializedPlugin.plugin.stateSchema,
90
- input.state,
91
- initializedPlugin.plugin.id,
92
- "state",
93
- ).pipe(
94
- Effect.mapError(
95
- (validationError) =>
96
- new PluginRuntimeError({
97
- pluginId: initializedPlugin.plugin.id,
98
- operation: "validate-state",
99
- cause: validationError.zodError,
100
- retryable: false,
101
- }),
102
- ),
103
- );
104
- }
105
- // Create and return the stream
106
- return createSourceStream(
107
- initializedPlugin,
108
- pluginService.executePlugin,
109
- input,
110
- options,
111
- isStreamable,
112
- );
113
- }),
114
- shutdown: () => pluginService.cleanup(),
115
- };
116
- }),
117
- ).pipe(
118
- Layer.provide(
119
- PluginService.Live(config.registry, secrets).pipe(
120
- Layer.provide(
121
- Layer.mergeAll(
122
- ModuleFederationService.Live,
123
- SecretsService.Live(secrets),
124
- Layer.succeed(PluginLoggerTag, logger),
125
- ),
126
- ),
127
- ),
128
- ),
129
- );
130
- };
12
+ static Live = (config) => {
13
+ const secrets = config.secrets || {};
14
+ const logger = config.logger || createDefaultLogger();
15
+ return Layer.effect(PluginRuntime, Effect.gen(function* () {
16
+ const pluginService = yield* PluginService;
17
+ return {
18
+ loadPlugin: pluginService.loadPlugin,
19
+ instantiatePlugin: pluginService.instantiatePlugin,
20
+ initializePlugin: pluginService.initializePlugin,
21
+ executePlugin: pluginService.executePlugin,
22
+ usePlugin: (pluginId, config) => pluginService.usePlugin(pluginId, config),
23
+ streamPlugin: (pluginId, config, input, options) => pluginService.streamPlugin(pluginId, config, input, options),
24
+ shutdown: () => pluginService.cleanup(),
25
+ };
26
+ })).pipe(Layer.provide(PluginService.Live(config.registry, secrets).pipe(Layer.provide(Layer.mergeAll(ModuleFederationService.Live, SecretsService.Live(secrets), Layer.succeed(PluginLoggerTag, logger))))));
27
+ };
131
28
  }
132
- export const createPluginRuntime = (config) =>
133
- ManagedRuntime.make(PluginRuntime.Live(config));
29
+ export const createPluginRuntime = (config) => ManagedRuntime.make(PluginRuntime.Live(config));
@@ -1,44 +1,16 @@
1
- import * as EffectModule from "effect";
2
- import { Effect } from "effect";
1
+ import { Effect, Layer } from "effect";
3
2
  import { ModuleFederationError } from "../errors";
4
3
  export interface IModuleFederationService {
5
- readonly registerRemote: (
6
- pluginId: string,
7
- url: string,
8
- ) => Effect.Effect<void, ModuleFederationError>;
9
- readonly loadRemoteConstructor: (
10
- pluginId: string,
11
- url: string,
12
- ) => Effect.Effect<any, ModuleFederationError>;
4
+ readonly registerRemote: (pluginId: string, url: string) => Effect.Effect<void, ModuleFederationError>;
5
+ readonly loadRemoteConstructor: (pluginId: string, url: string) => Effect.Effect<any, ModuleFederationError>;
13
6
  }
14
- declare const ModuleFederationService_base: EffectModule.Context.TagClass<
15
- ModuleFederationService,
16
- "ModuleFederationService",
17
- IModuleFederationService
18
- > &
19
- EffectModule.Effect.Tag.Proxy<
20
- ModuleFederationService,
21
- IModuleFederationService
22
- > & {
23
- use: <X>(
24
- body: (_: IModuleFederationService) => X,
25
- ) => [X] extends [EffectModule.Effect.Effect<infer A, infer E, infer R>]
26
- ? EffectModule.Effect.Effect<A, E, R | ModuleFederationService>
27
- : [X] extends [PromiseLike<infer A_1>]
28
- ? EffectModule.Effect.Effect<
29
- A_1,
30
- EffectModule.Cause.UnknownException,
31
- ModuleFederationService
32
- >
33
- : EffectModule.Effect.Effect<X, never, ModuleFederationService>;
34
- };
7
+ declare const ModuleFederationService_base: import("effect/Context").TagClass<ModuleFederationService, "ModuleFederationService", IModuleFederationService> & Effect.Tag.Proxy<ModuleFederationService, IModuleFederationService> & {
8
+ use: <X>(body: (_: IModuleFederationService) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, R | ModuleFederationService> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, import("effect/Cause").UnknownException, ModuleFederationService> : Effect.Effect<X, never, ModuleFederationService>;
9
+ };
35
10
  export declare class ModuleFederationService extends ModuleFederationService_base {
36
- static Live: EffectModule.Layer.Layer<ModuleFederationService, never, never>;
11
+ static Live: Layer.Layer<ModuleFederationService, never, never>;
37
12
  }
38
13
  export declare const ModuleFederationServiceTag: typeof ModuleFederationService;
39
- export declare const ModuleFederationServiceLive: EffectModule.Layer.Layer<
40
- ModuleFederationService,
41
- never,
42
- never
43
- >;
44
- //# sourceMappingURL=module-federation.service.d.ts.map
14
+ export declare const ModuleFederationServiceLive: Layer.Layer<ModuleFederationService, never, never>;
15
+ export {};
16
+ //# 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,KAAK,YAAY,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,MAAM,EAAS,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAElD,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,cAAc,EAAE,CACxB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,KACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAChD,QAAQ,CAAC,qBAAqB,EAAE,CAC/B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,KACP,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;CAC/C;;;;AAyCD,qBAAa,uBAAwB,SAAQ,4BAES;IACrD,MAAM,CAAC,IAAI,kEAwFT;CACF;AAED,eAAO,MAAM,0BAA0B,gCAA0B,CAAC;AAClE,eAAO,MAAM,2BAA2B,iEAA+B,CAAC"}
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,KAAK,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AASlD,MAAM,WAAW,wBAAwB;IACxC,QAAQ,CAAC,cAAc,EAAE,CACxB,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,KACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAChD,QAAQ,CAAC,qBAAqB,EAAE,CAC/B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,KACP,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;CAC/C;;;;AAyED,qBAAa,uBAAwB,SAAQ,4BAES;IACrD,MAAM,CAAC,IAAI,qDA4FT;CACF;AAED,eAAO,MAAM,0BAA0B,gCAA0B,CAAC;AAClE,eAAO,MAAM,2BAA2B,oDAA+B,CAAC"}