every-plugin 0.0.6 → 0.1.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.
Files changed (50) hide show
  1. package/README.md +77 -13
  2. package/dist/errors.js +10 -10
  3. package/dist/plugin.d.ts +98 -44
  4. package/dist/plugin.js +17 -15
  5. package/dist/runtime/errors.d.ts +22 -1
  6. package/dist/runtime/errors.d.ts.map +1 -1
  7. package/dist/runtime/errors.js +8 -6
  8. package/dist/runtime/index.d.ts +68 -16
  9. package/dist/runtime/index.d.ts.map +1 -1
  10. package/dist/runtime/index.js +126 -27
  11. package/dist/runtime/mf.test.d.ts +2 -0
  12. package/dist/runtime/mf.test.d.ts.map +1 -0
  13. package/dist/runtime/mf.test.js +135 -0
  14. package/dist/runtime/runtime.test.d.ts +1 -1
  15. package/dist/runtime/runtime.test.js +366 -296
  16. package/dist/runtime/services/module-federation.service.d.ts +36 -9
  17. package/dist/runtime/services/module-federation.service.d.ts.map +1 -1
  18. package/dist/runtime/services/module-federation.service.js +122 -99
  19. package/dist/runtime/services/plugin.service.d.ts +66 -13
  20. package/dist/runtime/services/plugin.service.d.ts.map +1 -1
  21. package/dist/runtime/services/plugin.service.js +330 -122
  22. package/dist/runtime/services/secrets.service.d.ts +29 -9
  23. package/dist/runtime/services/secrets.service.d.ts.map +1 -1
  24. package/dist/runtime/services/secrets.service.js +30 -26
  25. package/dist/runtime/services.d.ts +1 -2
  26. package/dist/runtime/services.d.ts.map +1 -1
  27. package/dist/runtime/services.js +0 -1
  28. package/dist/runtime/streaming.d.ts +29 -0
  29. package/dist/runtime/streaming.d.ts.map +1 -0
  30. package/dist/runtime/streaming.js +59 -0
  31. package/dist/runtime/streaming.test.d.ts +2 -0
  32. package/dist/runtime/streaming.test.d.ts.map +1 -0
  33. package/dist/runtime/streaming.test.js +271 -0
  34. package/dist/runtime/test-utils.d.ts +3 -0
  35. package/dist/runtime/test-utils.d.ts.map +1 -0
  36. package/dist/runtime/test-utils.js +13 -0
  37. package/dist/runtime/types.d.ts +27 -27
  38. package/dist/runtime/validation.d.ts +1 -1
  39. package/dist/runtime/validation.d.ts.map +1 -1
  40. package/dist/runtime/validation.js +14 -11
  41. package/dist/source.d.ts +62 -190
  42. package/dist/source.d.ts.map +1 -1
  43. package/dist/source.js +32 -85
  44. package/package.json +7 -3
  45. package/dist/runtime/runtime.d.ts +0 -58
  46. package/dist/runtime/runtime.d.ts.map +0 -1
  47. package/dist/runtime/runtime.js +0 -75
  48. package/dist/runtime/services/plugin-cache.service.d.ts +0 -18
  49. package/dist/runtime/services/plugin-cache.service.d.ts.map +0 -1
  50. package/dist/runtime/services/plugin-cache.service.js +0 -55
package/dist/source.d.ts CHANGED
@@ -1,198 +1,70 @@
1
+ import type { Effect } from "effect";
1
2
  import { z } from "zod";
2
- import type { Config, Input, Output, Plugin } from "./plugin";
3
+ import type { ConfigurationError, PluginExecutionError } from "./errors";
4
+ import type { PluginLoggerTag } from "./plugin";
3
5
  /**
4
- * Zod schema for the Author interface
6
+ * Source-specific schema creators for contract-based plugins
5
7
  */
6
- export declare const authorSchema: z.ZodObject<{
7
- id: z.ZodOptional<z.ZodString>;
8
- username: z.ZodOptional<z.ZodString>;
9
- displayName: z.ZodOptional<z.ZodString>;
10
- url: z.ZodOptional<z.ZodString>;
11
- }, z.core.$strip>;
8
+ export declare function createSourceInputSchema<
9
+ TContract,
10
+ TStateSchema extends z.ZodTypeAny,
11
+ >(
12
+ contract: TContract,
13
+ stateSchema: TStateSchema,
14
+ ): z.ZodDiscriminatedUnion<
15
+ [z.ZodObject<any, z.core.$strip>, ...z.ZodObject<any, z.core.$strip>[]],
16
+ "procedure"
17
+ >;
12
18
  /**
13
- * Zod schema for PluginSourceItem - defines the structure that plugins must return
19
+ * Contract-based output schema creator that infers from oRPC contract
14
20
  */
15
- export declare const pluginSourceItemSchema: z.ZodObject<{
16
- externalId: z.ZodString;
17
- content: z.ZodString;
18
- contentType: z.ZodOptional<z.ZodString>;
19
- createdAt: z.ZodOptional<z.ZodString>;
20
- url: z.ZodOptional<z.ZodString>;
21
- authors: z.ZodOptional<z.ZodArray<z.ZodObject<{
22
- id: z.ZodOptional<z.ZodString>;
23
- username: z.ZodOptional<z.ZodString>;
24
- displayName: z.ZodOptional<z.ZodString>;
25
- url: z.ZodOptional<z.ZodString>;
26
- }, z.core.$strip>>>;
27
- raw: z.ZodUnknown;
28
- }, z.core.$strip>;
21
+ export declare function createSourceOutputSchema<
22
+ TContract,
23
+ TStateSchema extends z.ZodTypeAny,
24
+ >(
25
+ contract: TContract,
26
+ stateSchema: TStateSchema,
27
+ ): z.ZodUnion<
28
+ [
29
+ z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>,
30
+ ...z.ZodType<
31
+ unknown,
32
+ unknown,
33
+ z.core.$ZodTypeInternals<unknown, unknown>
34
+ >[],
35
+ ]
36
+ >;
29
37
  /**
30
- * Standard content types supported by the system.
31
- * Plugins can extend this with custom types.
38
+ * Contract-first source plugin interface following the Plugin pattern
32
39
  */
33
- export declare const ContentType: {
34
- readonly POST: "post";
35
- readonly ARTICLE: "article";
36
- readonly VIDEO: "video";
37
- readonly PODCAST: "podcast";
38
- readonly WEBSITE: "website";
39
- readonly FEED: "feed";
40
- readonly DATABASE_ENTRY: "database-entry";
41
- readonly UNKNOWN: "unknown";
42
- };
43
- export type ContentType = (typeof ContentType)[keyof typeof ContentType];
44
- /**
45
- * Represents a single author - derived from the authorSchema
46
- */
47
- export type Author = z.infer<typeof authorSchema>;
48
- /**
49
- * Base PluginSourceItem type derived from schema (with unknown raw type)
50
- */
51
- export type BasePluginSourceItem = z.infer<typeof pluginSourceItemSchema>;
52
- /**
53
- * This is the data structure a plugin is responsible for creating.
54
- * It's generic over the raw data type.
55
- */
56
- export interface PluginSourceItem<TRaw = Record<string, any>> extends Omit<BasePluginSourceItem, "raw"> {
57
- raw: TRaw;
58
- }
59
- /**
60
- * This is the final, canonical data structure used within the system.
61
- * It extends PluginSourceItem with system-generated fields.
62
- */
63
- export interface SourceItem<TRaw = Record<string, any>> extends PluginSourceItem<TRaw> {
64
- id: string;
65
- createdAt: string;
66
- metadata: {
67
- sourcePlugin: string;
68
- workflowId: string;
69
- runId: string;
70
- [key: string]: any;
71
- };
72
- }
73
- /**
74
- * Defines the progress of a job submitted to an external asynchronous service (e.g., Masa).
75
- */
76
- export interface AsyncJobProgress {
77
- workflowId: string;
78
- status: "submitted" | "pending" | "processing" | "done" | "error" | "timeout";
79
- submittedAt: string;
80
- lastCheckedAt?: string;
81
- errorMessage?: string;
82
- }
83
- export declare const AsyncJobProgressSchema: z.ZodObject<{
84
- workflowId: z.ZodString;
85
- status: z.ZodEnum<{
86
- error: "error";
87
- timeout: "timeout";
88
- submitted: "submitted";
89
- pending: "pending";
90
- processing: "processing";
91
- done: "done";
92
- }>;
93
- submittedAt: z.ZodString;
94
- lastCheckedAt: z.ZodOptional<z.ZodString>;
95
- errorMessage: z.ZodOptional<z.ZodString>;
96
- }, z.core.$strip>;
97
- /**
98
- * Generic platform-specific state for managing resumable searches and long-running jobs.
99
- */
100
- export interface PlatformState {
101
- latestProcessedId?: string | number | Record<string, any>;
102
- currentAsyncJob?: AsyncJobProgress | null;
103
- [key: string]: any;
104
- }
105
- export declare const PlatformStateSchema: z.ZodObject<{
106
- latestProcessedId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
107
- currentAsyncJob: z.ZodOptional<z.ZodNullable<z.ZodObject<{
108
- workflowId: z.ZodString;
109
- status: z.ZodEnum<{
110
- error: "error";
111
- timeout: "timeout";
112
- submitted: "submitted";
113
- pending: "pending";
114
- processing: "processing";
115
- done: "done";
116
- }>;
117
- submittedAt: z.ZodString;
118
- lastCheckedAt: z.ZodOptional<z.ZodString>;
119
- errorMessage: z.ZodOptional<z.ZodString>;
120
- }, z.core.$strip>>>;
121
- }, z.core.$catchall<z.ZodAny>>;
122
- /**
123
- * State passed between search calls to enable resumption.
124
- * TData is expected to be an object conforming to PlatformState or a derivative.
125
- */
126
- export interface LastProcessedState<TData extends PlatformState = PlatformState> {
127
- data: TData;
128
- }
129
- export type SourceConfig<V extends z.ZodTypeAny = z.ZodRecord<z.ZodString, z.ZodUnknown>, S extends z.ZodTypeAny = z.ZodRecord<z.ZodString, z.ZodUnknown>> = Config<V, S>;
130
- export interface SourceInput<TSearchOptions extends z.ZodTypeAny = z.ZodTypeAny> extends Input<z.ZodAny> {
131
- searchOptions: TSearchOptions;
132
- lastProcessedState?: LastProcessedState<PlatformState> | null;
133
- }
134
- export interface PluginSourceInput<TSearchOptions = Record<string, unknown>> extends Input<z.ZodAny> {
135
- searchOptions: TSearchOptions;
136
- lastProcessedState?: LastProcessedState<PlatformState> | null;
137
- }
138
- export interface PluginSourceOutputData<TItem extends PluginSourceItem = PluginSourceItem> {
139
- items: TItem[];
140
- nextLastProcessedState?: PlatformState | null;
141
- }
142
- export interface PluginSourceOutput<TItem extends PluginSourceItem = PluginSourceItem> extends Output<z.ZodAny> {
143
- success: boolean;
144
- data?: PluginSourceOutputData<TItem>;
145
- errors?: Array<{
146
- message: string;
147
- details?: Record<string, unknown>;
148
- stack?: string;
149
- }>;
150
- }
151
- export interface SourceOutputData {
152
- items: SourceItem[];
153
- nextLastProcessedState?: PlatformState | null;
154
- }
155
- export interface SourceOutput extends Output<z.ZodAny> {
156
- success: boolean;
157
- data?: SourceOutputData;
158
- errors?: Array<{
159
- message: string;
160
- details?: Record<string, unknown>;
161
- stack?: string;
162
- }>;
163
- }
164
- export interface SourcePlugin<TInputSchema extends z.ZodTypeAny = z.ZodTypeAny, TOutputSchema extends z.ZodTypeAny = z.ZodTypeAny, TConfigSchema extends z.ZodTypeAny = z.ZodTypeAny> extends Plugin<TInputSchema, TOutputSchema, TConfigSchema> {
165
- readonly type: "source";
40
+ export interface SourcePlugin<
41
+ TContract = Record<string, any>,
42
+ TConfigSchema extends z.ZodTypeAny = z.ZodTypeAny,
43
+ TStateSchema extends z.ZodTypeAny = z.ZodTypeAny,
44
+ > {
45
+ readonly id: string;
46
+ readonly type: "source";
47
+ readonly contract: TContract;
48
+ readonly configSchema: TConfigSchema;
49
+ readonly stateSchema: TStateSchema;
50
+ readonly inputSchema: ReturnType<
51
+ typeof createSourceInputSchema<TContract, TStateSchema>
52
+ >;
53
+ readonly outputSchema: ReturnType<
54
+ typeof createSourceOutputSchema<TContract, TStateSchema>
55
+ >;
56
+ initialize(
57
+ config?: z.infer<TConfigSchema>,
58
+ ): Effect.Effect<void, ConfigurationError, PluginLoggerTag>;
59
+ execute(
60
+ input: z.infer<this["inputSchema"]>,
61
+ ): Effect.Effect<
62
+ z.infer<this["outputSchema"]>,
63
+ PluginExecutionError,
64
+ PluginLoggerTag
65
+ >;
66
+ shutdown(): Effect.Effect<void, never, PluginLoggerTag>;
67
+ createRouter(): any;
68
+ isStreamable(procedureName: string): boolean;
166
69
  }
167
- export declare const createSourceInputSchema: <TSearchOptions extends z.ZodTypeAny, TState extends z.ZodTypeAny>(searchOptionsSchema: TSearchOptions, stateSchema: TState) => z.ZodObject<{
168
- searchOptions: TSearchOptions;
169
- lastProcessedState: z.ZodNullable<z.ZodOptional<z.ZodObject<{
170
- data: z.ZodNullable<z.ZodOptional<TState>>;
171
- }, z.core.$strip>>>;
172
- }, z.core.$strip>;
173
- export declare const createSourceOutputSchema: <TItem extends z.ZodTypeAny, TState extends z.ZodTypeAny>(itemData: TItem, stateSchema: TState) => z.ZodObject<{
174
- success: z.ZodBoolean;
175
- data: z.ZodOptional<z.ZodObject<{
176
- items: z.ZodArray<z.ZodObject<{
177
- externalId: z.ZodString;
178
- content: z.ZodString;
179
- contentType: z.ZodOptional<z.ZodString>;
180
- createdAt: z.ZodOptional<z.ZodString>;
181
- url: z.ZodOptional<z.ZodString>;
182
- authors: z.ZodOptional<z.ZodArray<z.ZodObject<{
183
- id: z.ZodOptional<z.ZodString>;
184
- username: z.ZodOptional<z.ZodString>;
185
- displayName: z.ZodOptional<z.ZodString>;
186
- url: z.ZodOptional<z.ZodString>;
187
- }, z.core.$strip>>>;
188
- raw: TItem;
189
- }, z.core.$strip>>;
190
- nextLastProcessedState: z.ZodNullable<z.ZodOptional<TState>>;
191
- }, z.core.$strip>>;
192
- errors: z.ZodOptional<z.ZodArray<z.ZodObject<{
193
- message: z.ZodString;
194
- details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
195
- stack: z.ZodOptional<z.ZodString>;
196
- }, z.core.$strip>>>;
197
- }, z.core.$strip>;
198
- //# sourceMappingURL=source.d.ts.map
70
+ //# sourceMappingURL=source.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAG9D;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;iBAKvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;iBAQjC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;;;;CASd,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAC3D,SAAQ,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC;IAEzC,GAAG,EAAE,IAA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KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GACjC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,oBAAoB,EAAE,eAAe,CAAC,CAAC;IAEvF,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;IAExD,YAAY,IAAI,GAAG,CAAC;IAEpB,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7C"}
package/dist/source.js CHANGED
@@ -1,90 +1,37 @@
1
1
  import { z } from "zod";
2
- import { ErrorDetailsSchema } from "./plugin";
3
2
  /**
4
- * Zod schema for the Author interface
3
+ * Source-specific schema creators for contract-based plugins
5
4
  */
6
- export const authorSchema = z.object({
7
- id: z.string().optional(),
8
- username: z.string().optional(),
9
- displayName: z.string().optional(),
10
- url: z.string().optional(),
11
- });
5
+ export function createSourceInputSchema(contract, stateSchema) {
6
+ const contractEntries = Object.entries(contract);
7
+ const procedureSchemas = contractEntries.map(
8
+ ([procedureName, procedureSpec]) => {
9
+ // Extract input and output schemas from oRPC contract procedure
10
+ const inputSchema = procedureSpec["~orpc"]?.inputSchema || z.object({});
11
+ const outputSchema = procedureSpec["~orpc"]?.outputSchema || z.object({});
12
+ // Check if this procedure is streamable (has nextState in output)
13
+ const isStreamable = outputSchema._def?.shape?.nextState !== undefined;
14
+ const baseSchema = z.object({
15
+ procedure: z.literal(procedureName),
16
+ input: inputSchema,
17
+ });
18
+ // Only add state field for streamable procedures
19
+ return isStreamable
20
+ ? baseSchema.extend({ state: stateSchema })
21
+ : baseSchema;
22
+ },
23
+ );
24
+ return z.discriminatedUnion("procedure", procedureSchemas);
25
+ }
12
26
  /**
13
- * Zod schema for PluginSourceItem - defines the structure that plugins must return
27
+ * Contract-based output schema creator that infers from oRPC contract
14
28
  */
15
- export const pluginSourceItemSchema = z.object({
16
- externalId: z.string(),
17
- content: z.string(),
18
- contentType: z.string().optional(),
19
- createdAt: z.string().optional(),
20
- url: z.string().optional(),
21
- authors: z.array(authorSchema).optional(),
22
- raw: z.unknown(),
23
- });
24
- /**
25
- * Standard content types supported by the system.
26
- * Plugins can extend this with custom types.
27
- */
28
- export const ContentType = {
29
- POST: "post",
30
- ARTICLE: "article",
31
- VIDEO: "video",
32
- PODCAST: "podcast",
33
- WEBSITE: "website",
34
- FEED: "feed",
35
- DATABASE_ENTRY: "database-entry",
36
- UNKNOWN: "unknown",
37
- };
38
- export const AsyncJobProgressSchema = z.object({
39
- workflowId: z.string(),
40
- status: z.enum([
41
- "submitted",
42
- "pending",
43
- "processing",
44
- "done",
45
- "error",
46
- "timeout",
47
- ]),
48
- submittedAt: z.string(), // ISO timestamp
49
- lastCheckedAt: z.string().optional(), // ISO timestamp
50
- errorMessage: z.string().optional(),
51
- });
52
- export const PlatformStateSchema = z
53
- .object({
54
- latestProcessedId: z
55
- .union([z.string(), z.number(), z.record(z.string(), z.any())])
56
- .optional(),
57
- currentAsyncJob: AsyncJobProgressSchema.nullable().optional(),
58
- })
59
- .catchall(z.any());
60
- // Source-specific schema creators
61
- export const createSourceInputSchema = (searchOptionsSchema, stateSchema) => z.object({
62
- searchOptions: searchOptionsSchema,
63
- lastProcessedState: z
64
- .object({
65
- data: stateSchema.optional().nullable(),
66
- })
67
- .optional()
68
- .nullable(),
69
- });
70
- export const createSourceOutputSchema = (itemData, stateSchema) => {
71
- const pluginSourceItemSchema = z.object({
72
- externalId: z.string(),
73
- content: z.string(),
74
- contentType: z.string().optional(),
75
- createdAt: z.string().optional(),
76
- url: z.string().optional(),
77
- authors: z.array(authorSchema).optional(),
78
- raw: itemData,
79
- });
80
- return z.object({
81
- success: z.boolean(),
82
- data: z
83
- .object({
84
- items: z.array(pluginSourceItemSchema),
85
- nextLastProcessedState: stateSchema.optional().nullable(),
86
- })
87
- .optional(),
88
- errors: z.array(ErrorDetailsSchema).optional(),
89
- });
90
- };
29
+ export function createSourceOutputSchema(contract, stateSchema) {
30
+ const contractEntries = Object.entries(contract);
31
+ const procedureOutputSchemas = contractEntries.map(([_, procedureSpec]) => {
32
+ // Extract output schema from oRPC contract procedure
33
+ return procedureSpec["~orpc"]?.outputSchema || z.object({});
34
+ });
35
+ // Return union of all procedure output schemas
36
+ return z.union(procedureOutputSchemas);
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "every-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -24,12 +24,16 @@
24
24
  "effect": ">=3.17.0 <4.0.0",
25
25
  "zod": ">=4.0.0",
26
26
  "@module-federation/enhanced": ">=0.18.0",
27
- "@module-federation/runtime-core": ">=0.18.0"
27
+ "@module-federation/runtime-core": ">=0.18.0",
28
+ "@orpc/server": ">=0.0.1"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@effect/vitest": "^0.25.1",
31
32
  "@module-federation/enhanced": "^0.18.3",
32
33
  "@module-federation/runtime-core": "^0.18.3",
34
+ "@types/bun": "^1.2.21",
35
+ "@vitest/ui": "3.2.4",
36
+ "bun-types": "^1.2.21",
33
37
  "effect": "^3.17.7",
34
38
  "typescript": "^5.0.0",
35
39
  "vitest": "^3.2.4",
@@ -37,6 +41,6 @@
37
41
  },
38
42
  "dependencies": {
39
43
  "@better-fetch/fetch": "^1.1.18",
40
- "ajv": "^8.17.1"
44
+ "@orpc/contract": "^1.8.6"
41
45
  }
42
46
  }
@@ -1,58 +0,0 @@
1
- import { Effect, Layer, ManagedRuntime } from "effect";
2
- import { z } from "zod";
3
- import { PluginRuntimeError } from "./errors";
4
- import type {
5
- AnyPlugin,
6
- InitializedPlugin,
7
- PluginConstructor,
8
- PluginInstance,
9
- PluginRuntimeConfig,
10
- } from "./types";
11
- export interface IPluginRuntime {
12
- readonly loadPlugin: (
13
- pluginId: string,
14
- ) => Effect.Effect<PluginConstructor, PluginRuntimeError>;
15
- readonly instantiatePlugin: <T extends AnyPlugin>(
16
- ctor: PluginConstructor,
17
- ) => Effect.Effect<PluginInstance<T>, PluginRuntimeError>;
18
- readonly initializePlugin: <T extends AnyPlugin>(
19
- instance: PluginInstance<T>,
20
- config: z.infer<T["configSchema"]>,
21
- ) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
22
- readonly executePlugin: <T extends AnyPlugin>(
23
- initializedPlugin: InitializedPlugin<T>,
24
- input: z.infer<T["inputSchema"]>,
25
- ) => Effect.Effect<z.infer<T["outputSchema"]>, PluginRuntimeError>;
26
- readonly createPlugin: <T extends AnyPlugin>(
27
- pluginId: string,
28
- config: z.infer<T["configSchema"]>,
29
- ) => Effect.Effect<InitializedPlugin<T>, PluginRuntimeError>;
30
- readonly shutdown: () => Effect.Effect<void, never>;
31
- }
32
- declare const PluginRuntime_base: import("effect/Context").TagClass<
33
- PluginRuntime,
34
- "PluginRuntime",
35
- IPluginRuntime
36
- > &
37
- Effect.Tag.Proxy<PluginRuntime, IPluginRuntime> & {
38
- use: <X>(
39
- body: (_: IPluginRuntime) => X,
40
- ) => [X] extends [Effect.Effect<infer A, infer E, infer R>]
41
- ? Effect.Effect<A, E, R | PluginRuntime>
42
- : [X] extends [PromiseLike<infer A_1>]
43
- ? Effect.Effect<
44
- A_1,
45
- import("effect/Cause").UnknownException,
46
- PluginRuntime
47
- >
48
- : Effect.Effect<X, never, PluginRuntime>;
49
- };
50
- export declare class PluginRuntime extends PluginRuntime_base {
51
- static Live: (
52
- config: PluginRuntimeConfig,
53
- ) => Layer.Layer<PluginRuntime, never, never>;
54
- }
55
- export declare const createManagedPluginRuntime: (
56
- config: PluginRuntimeConfig,
57
- ) => ManagedRuntime.ManagedRuntime<PluginRuntime, never>;
58
- //# sourceMappingURL=runtime.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.ts"],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AE,MAAM,EAChB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,KAC9B,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAC7D,QAAQ,CAAC,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;CACpD;;;;AAGD,qBAAa,aAAc,SAAQ,kBAGhC;IACF,MAAM,CAAC,IAAI,GAAI,QAAQ,mBAAmB,8CA4CxC;CACF;AAGD,eAAO,MAAM,0BAA0B,GAAI,QAAQ,mBAAmB,wDACtB,CAAC"}
@@ -1,75 +0,0 @@
1
- import { Effect, Layer, ManagedRuntime } from "effect";
2
- import { PluginLoggerTag } from "../plugin";
3
- import {
4
- ModuleFederationService,
5
- PluginCacheService,
6
- PluginService,
7
- SecretsService,
8
- } from "./services";
9
-
10
- // Default logger implementation
11
- const createDefaultLogger = () => ({
12
- logInfo: (message, context) =>
13
- Effect.logInfo(message).pipe(
14
- Effect.annotateLogs({ source: "plugin", context }),
15
- ),
16
- logWarning: (message, context) =>
17
- Effect.logWarning(message).pipe(
18
- Effect.annotateLogs({ source: "plugin", context }),
19
- ),
20
- logError: (message, error, context) =>
21
- Effect.logError(message, error).pipe(
22
- Effect.annotateLogs({ source: "plugin", error, context }),
23
- ),
24
- logDebug: (message, context) =>
25
- Effect.logDebug(message).pipe(
26
- Effect.annotateLogs({ source: "plugin", context }),
27
- ),
28
- });
29
- // Main PluginRuntime service using Effect.Tag pattern
30
- export class PluginRuntime extends Effect.Tag("PluginRuntime")() {
31
- static Live = (config) => {
32
- const secrets = config.secrets || {};
33
- const logger = config.logger || createDefaultLogger();
34
- return Layer.effect(
35
- PluginRuntime,
36
- Effect.gen(function* () {
37
- const pluginService = yield* PluginService;
38
- return {
39
- loadPlugin: pluginService.loadPlugin,
40
- instantiatePlugin: pluginService.instantiatePlugin,
41
- initializePlugin: pluginService.initializePlugin,
42
- executePlugin: pluginService.executePlugin,
43
- createPlugin: (pluginId, config) =>
44
- Effect.gen(function* () {
45
- const ctor = yield* pluginService.loadPlugin(pluginId);
46
- const instance = yield* pluginService.instantiatePlugin(ctor);
47
- return yield* pluginService.initializePlugin(instance, config);
48
- }),
49
- shutdown: () =>
50
- Effect.sync(() => {
51
- // Cleanup handled by Layer disposal
52
- }),
53
- };
54
- }),
55
- ).pipe(
56
- Layer.provide(
57
- PluginService.Live(config.registry, secrets).pipe(
58
- Layer.provide(
59
- Layer.mergeAll(
60
- ModuleFederationService.Live,
61
- PluginCacheService.Live.pipe(
62
- Layer.provide(ModuleFederationService.Live),
63
- ),
64
- SecretsService.Live(secrets),
65
- Layer.succeed(PluginLoggerTag, logger),
66
- ),
67
- ),
68
- ),
69
- ),
70
- );
71
- };
72
- }
73
- // ManagedRuntime factory function
74
- export const createManagedPluginRuntime = (config) =>
75
- ManagedRuntime.make(PluginRuntime.Live(config));
@@ -1,18 +0,0 @@
1
- import { Effect, Layer } from "effect";
2
- import { PluginRuntimeError } from "../errors";
3
- import type { PluginConstructor } from "../types";
4
- import { ModuleFederationService } from "./module-federation.service";
5
- export interface IPluginCacheService {
6
- readonly getCachedConstructor: (cacheKey: string) => Effect.Effect<PluginConstructor, PluginRuntimeError>;
7
- readonly invalidate: (cacheKey: string) => Effect.Effect<void>;
8
- }
9
- declare const PluginCacheService_base: import("effect/Context").TagClass<PluginCacheService, "PluginCacheService", IPluginCacheService> & Effect.Tag.Proxy<PluginCacheService, IPluginCacheService> & {
10
- use: <X>(body: (_: IPluginCacheService) => X) => [X] extends [Effect.Effect<infer A, infer E, infer R>] ? Effect.Effect<A, E, R | PluginCacheService> : [X] extends [PromiseLike<infer A_1>] ? Effect.Effect<A_1, import("effect/Cause").UnknownException, PluginCacheService> : Effect.Effect<X, never, PluginCacheService>;
11
- };
12
- export declare class PluginCacheService extends PluginCacheService_base {
13
- static Live: Layer.Layer<PluginCacheService, never, ModuleFederationService>;
14
- }
15
- export declare const PluginCacheServiceTag: typeof PluginCacheService;
16
- export declare const PluginCacheServiceLive: Layer.Layer<PluginCacheService, never, ModuleFederationService>;
17
- export {};
18
- //# sourceMappingURL=plugin-cache.service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin-cache.service.d.ts","sourceRoot":"","sources":["../../../src/runtime/services/plugin-cache.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,oBAAoB,EAAE,CAC7B,QAAQ,EAAE,MAAM,KACb,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;IAC1D,QAAQ,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;CAChE;;;;AAED,qBAAa,kBAAmB,SAAQ,uBAGrC;IACD,MAAM,CAAC,IAAI,kEAoET;CACH;AAED,eAAO,MAAM,qBAAqB,2BAAqB,CAAC;AACxD,eAAO,MAAM,sBAAsB,iEAA0B,CAAC"}
@@ -1,55 +0,0 @@
1
- import { Cache, Duration, Effect, Layer } from "effect";
2
- import { PluginRuntimeError } from "../errors";
3
- import { ModuleFederationService } from "./module-federation.service";
4
- export class PluginCacheService extends Effect.Tag("PluginCacheService")() {
5
- static Live = Layer.effect(PluginCacheService, Effect.gen(function* () {
6
- const mfService = yield* ModuleFederationService;
7
- const cache = yield* Cache.make({
8
- capacity: 50,
9
- timeToLive: Duration.minutes(30),
10
- lookup: (cacheKey) => {
11
- // Parse cache key: "pluginId:url"
12
- const colonIndex = cacheKey.indexOf(":");
13
- if (colonIndex === -1) {
14
- return Effect.fail(new PluginRuntimeError({
15
- pluginId: cacheKey,
16
- operation: "cache-lookup",
17
- cause: new Error(`Invalid cache key format: ${cacheKey}`),
18
- retryable: false,
19
- }));
20
- }
21
- const pluginId = cacheKey.substring(0, colonIndex);
22
- const url = cacheKey.substring(colonIndex + 1);
23
- return Effect.gen(function* () {
24
- yield* mfService.registerRemote(pluginId, url).pipe(Effect.mapError((mfError) => new PluginRuntimeError({
25
- pluginId,
26
- operation: "register-remote",
27
- cause: mfError.cause,
28
- retryable: true,
29
- })));
30
- const ctor = yield* mfService.loadRemoteConstructor(pluginId, url).pipe(Effect.mapError((mfError) => new PluginRuntimeError({
31
- pluginId,
32
- operation: "load-remote",
33
- cause: mfError.cause,
34
- retryable: true,
35
- })));
36
- return {
37
- ctor,
38
- metadata: {
39
- pluginId,
40
- version: "unknown", // Will be resolved from registry
41
- description: "Loaded from remote",
42
- type: "unknown",
43
- },
44
- };
45
- });
46
- },
47
- });
48
- return {
49
- getCachedConstructor: (cacheKey) => cache.get(cacheKey),
50
- invalidate: (cacheKey) => cache.invalidate(cacheKey),
51
- };
52
- }));
53
- }
54
- export const PluginCacheServiceTag = PluginCacheService;
55
- export const PluginCacheServiceLive = PluginCacheService.Live;