@dual-os/sdk 0.0.0-stage → 0.8.0-next.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/LICENSE +4 -0
- package/README.md +19 -2
- package/dist/Action.d.ts +201 -0
- package/dist/Action.d.ts.map +1 -0
- package/dist/Action.js +172 -0
- package/dist/Action.js.map +1 -0
- package/dist/AgentChannel.d.ts +1717 -0
- package/dist/AgentChannel.d.ts.map +1 -0
- package/dist/AgentChannel.js +708 -0
- package/dist/AgentChannel.js.map +1 -0
- package/dist/AgentChannelConformance.d.ts +1543 -0
- package/dist/AgentChannelConformance.d.ts.map +1 -0
- package/dist/AgentChannelConformance.js +163 -0
- package/dist/AgentChannelConformance.js.map +1 -0
- package/dist/AgentChannelRuntime.d.ts +78 -0
- package/dist/AgentChannelRuntime.d.ts.map +1 -0
- package/dist/AgentChannelRuntime.js +270 -0
- package/dist/AgentChannelRuntime.js.map +1 -0
- package/dist/AiProvider.d.ts +132 -0
- package/dist/AiProvider.d.ts.map +1 -0
- package/dist/AiProvider.js +100 -0
- package/dist/AiProvider.js.map +1 -0
- package/dist/AuthMethod.d.ts +381 -0
- package/dist/AuthMethod.d.ts.map +1 -0
- package/dist/AuthMethod.js +225 -0
- package/dist/AuthMethod.js.map +1 -0
- package/dist/AuthMethodBinding.d.ts +77 -0
- package/dist/AuthMethodBinding.d.ts.map +1 -0
- package/dist/AuthMethodBinding.js +31 -0
- package/dist/AuthMethodBinding.js.map +1 -0
- package/dist/AuthMethodExecution.d.ts +223 -0
- package/dist/AuthMethodExecution.d.ts.map +1 -0
- package/dist/AuthMethodExecution.js +277 -0
- package/dist/AuthMethodExecution.js.map +1 -0
- package/dist/ConnectionResolver.d.ts +219 -0
- package/dist/ConnectionResolver.d.ts.map +1 -0
- package/dist/ConnectionResolver.js +153 -0
- package/dist/ConnectionResolver.js.map +1 -0
- package/dist/DefinitionError.d.ts +67 -0
- package/dist/DefinitionError.d.ts.map +1 -0
- package/dist/DefinitionError.js +82 -0
- package/dist/DefinitionError.js.map +1 -0
- package/dist/DualRegistry.d.ts +71 -0
- package/dist/DualRegistry.d.ts.map +1 -0
- package/dist/DualRegistry.js +96 -0
- package/dist/DualRegistry.js.map +1 -0
- package/dist/DualRuntime.d.ts +279 -0
- package/dist/DualRuntime.d.ts.map +1 -0
- package/dist/DualRuntime.js +311 -0
- package/dist/DualRuntime.js.map +1 -0
- package/dist/Files.d.ts +80 -0
- package/dist/Files.d.ts.map +1 -0
- package/dist/Files.js +66 -0
- package/dist/Files.js.map +1 -0
- package/dist/Group.d.ts +106 -0
- package/dist/Group.d.ts.map +1 -0
- package/dist/Group.js +86 -0
- package/dist/Group.js.map +1 -0
- package/dist/Http.d.ts +342 -0
- package/dist/Http.d.ts.map +1 -0
- package/dist/Http.js +677 -0
- package/dist/Http.js.map +1 -0
- package/dist/Mcp.d.ts +109 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +176 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/OAuth2TokenRefresher.d.ts +18 -0
- package/dist/OAuth2TokenRefresher.d.ts.map +1 -0
- package/dist/OAuth2TokenRefresher.js +19 -0
- package/dist/OAuth2TokenRefresher.js.map +1 -0
- package/dist/OAuthFlow.d.ts +71 -0
- package/dist/OAuthFlow.d.ts.map +1 -0
- package/dist/OAuthFlow.js +488 -0
- package/dist/OAuthFlow.js.map +1 -0
- package/dist/Plugin.d.ts +383 -0
- package/dist/Plugin.d.ts.map +1 -0
- package/dist/Plugin.js +249 -0
- package/dist/Plugin.js.map +1 -0
- package/dist/PluginRuntime.d.ts +3186 -0
- package/dist/PluginRuntime.d.ts.map +1 -0
- package/dist/PluginRuntime.js +331 -0
- package/dist/PluginRuntime.js.map +1 -0
- package/dist/Runner.d.ts +1 -0
- package/dist/Runner.js +124 -0
- package/dist/Runner.js.map +1 -0
- package/dist/ToolFile.d.ts +23 -0
- package/dist/ToolFile.d.ts.map +1 -0
- package/dist/ToolFile.js +33 -0
- package/dist/ToolFile.js.map +1 -0
- package/dist/Trigger.d.ts +358 -0
- package/dist/Trigger.d.ts.map +1 -0
- package/dist/Trigger.js +287 -0
- package/dist/Trigger.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/internal/auth-context.d.ts +23 -0
- package/dist/internal/auth-context.d.ts.map +1 -0
- package/dist/internal/auth-context.js +1 -0
- package/dist/internal/auth-execution.d.ts +27 -0
- package/dist/internal/auth-execution.d.ts.map +1 -0
- package/dist/internal/auth-execution.js +66 -0
- package/dist/internal/auth-execution.js.map +1 -0
- package/dist/internal/auth-runtime.d.ts +5 -0
- package/dist/internal/auth-runtime.d.ts.map +1 -0
- package/dist/internal/auth-runtime.js +16 -0
- package/dist/internal/auth-runtime.js.map +1 -0
- package/dist/internal/capabilities.d.ts +24 -0
- package/dist/internal/capabilities.d.ts.map +1 -0
- package/dist/internal/capabilities.js +22 -0
- package/dist/internal/capabilities.js.map +1 -0
- package/dist/internal/children.d.ts +34 -0
- package/dist/internal/children.d.ts.map +1 -0
- package/dist/internal/children.js +53 -0
- package/dist/internal/children.js.map +1 -0
- package/dist/internal/collection-utils.d.ts +4 -0
- package/dist/internal/collection-utils.d.ts.map +1 -0
- package/dist/internal/collection-utils.js +6 -0
- package/dist/internal/collection-utils.js.map +1 -0
- package/dist/internal/dual/actions.d.ts +33 -0
- package/dist/internal/dual/actions.d.ts.map +1 -0
- package/dist/internal/dual/actions.js +26 -0
- package/dist/internal/dual/actions.js.map +1 -0
- package/dist/internal/dual/invoke.d.ts +63 -0
- package/dist/internal/dual/invoke.d.ts.map +1 -0
- package/dist/internal/dual/invoke.js +75 -0
- package/dist/internal/dual/invoke.js.map +1 -0
- package/dist/internal/dual/registry.d.ts +125 -0
- package/dist/internal/dual/registry.d.ts.map +1 -0
- package/dist/internal/dual/registry.js +172 -0
- package/dist/internal/dual/registry.js.map +1 -0
- package/dist/internal/dual/triggers.d.ts +29 -0
- package/dist/internal/dual/triggers.d.ts.map +1 -0
- package/dist/internal/dual/triggers.js +26 -0
- package/dist/internal/dual/triggers.js.map +1 -0
- package/dist/internal/handler-context.d.ts +9 -0
- package/dist/internal/handler-context.d.ts.map +1 -0
- package/dist/internal/handler-context.js +31 -0
- package/dist/internal/handler-context.js.map +1 -0
- package/dist/internal/identifier.d.ts +6 -0
- package/dist/internal/identifier.d.ts.map +1 -0
- package/dist/internal/identifier.js +28 -0
- package/dist/internal/identifier.js.map +1 -0
- package/dist/internal/plugin-handlers.d.ts +38 -0
- package/dist/internal/plugin-handlers.d.ts.map +1 -0
- package/dist/internal/plugin-handlers.js +52 -0
- package/dist/internal/plugin-handlers.js.map +1 -0
- package/dist/internal/proto.d.ts +7 -0
- package/dist/internal/proto.d.ts.map +1 -0
- package/dist/internal/proto.js +10 -0
- package/dist/internal/proto.js.map +1 -0
- package/dist/internal/schema-runtime.d.ts +6 -0
- package/dist/internal/schema-runtime.d.ts.map +1 -0
- package/dist/internal/schema-runtime.js +10 -0
- package/dist/internal/schema-runtime.js.map +1 -0
- package/dist/internal/trigger-runtime-shared.d.ts +41 -0
- package/dist/internal/trigger-runtime-shared.d.ts.map +1 -0
- package/dist/internal/trigger-runtime-shared.js +132 -0
- package/dist/internal/trigger-runtime-shared.js.map +1 -0
- package/dist/internal/trigger-runtime.d.ts +12 -0
- package/dist/internal/trigger-runtime.d.ts.map +1 -0
- package/dist/internal/trigger-runtime.js +95 -0
- package/dist/internal/trigger-runtime.js.map +1 -0
- package/dist/internal/types.d.ts +7 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +1 -0
- package/dist/remote-runtime.d.ts +585 -0
- package/dist/remote-runtime.d.ts.map +1 -0
- package/dist/remote-runtime.js +367 -0
- package/dist/remote-runtime.js.map +1 -0
- package/package.json +55 -4
- package/src/Action.ts +370 -0
- package/src/AgentChannel.ts +860 -0
- package/src/AgentChannelConformance.ts +124 -0
- package/src/AgentChannelRuntime.ts +616 -0
- package/src/AiProvider.ts +255 -0
- package/src/AuthMethod.ts +954 -0
- package/src/AuthMethodBinding.ts +112 -0
- package/src/AuthMethodExecution.ts +542 -0
- package/src/ConnectionResolver.ts +265 -0
- package/src/DefinitionError.ts +115 -0
- package/src/DualRegistry.ts +152 -0
- package/src/DualRuntime.ts +1081 -0
- package/src/Files.ts +89 -0
- package/src/Group.ts +292 -0
- package/src/Http.ts +1205 -0
- package/src/Mcp.ts +299 -0
- package/src/OAuth2TokenRefresher.ts +22 -0
- package/src/OAuthFlow.ts +874 -0
- package/src/Plugin.ts +912 -0
- package/src/PluginRuntime.ts +414 -0
- package/src/Runner.ts +248 -0
- package/src/ToolFile.ts +28 -0
- package/src/Trigger.ts +722 -0
- package/src/index.ts +158 -0
- package/src/internal/auth-context.ts +27 -0
- package/src/internal/auth-execution.ts +241 -0
- package/src/internal/auth-runtime.ts +20 -0
- package/src/internal/capabilities.ts +55 -0
- package/src/internal/children.ts +126 -0
- package/src/internal/collection-utils.ts +8 -0
- package/src/internal/dual/actions.ts +116 -0
- package/src/internal/dual/invoke.ts +307 -0
- package/src/internal/dual/registry.ts +340 -0
- package/src/internal/dual/triggers.ts +128 -0
- package/src/internal/handler-context.ts +57 -0
- package/src/internal/identifier.ts +27 -0
- package/src/internal/plugin-handlers.ts +146 -0
- package/src/internal/proto.ts +8 -0
- package/src/internal/schema-runtime.ts +15 -0
- package/src/internal/trigger-runtime-shared.ts +449 -0
- package/src/internal/trigger-runtime.ts +223 -0
- package/src/internal/types.ts +12 -0
- package/src/remote-runtime.ts +469 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Array, Context, Predicate, String } from "effect";
|
|
2
|
+
//#region src/internal/handler-context.ts
|
|
3
|
+
/**
|
|
4
|
+
* A plugin's handlers live in the layer context as one group entry, keyed by
|
|
5
|
+
* plugin id, so merging layer outputs grows with the number of plugins and
|
|
6
|
+
* not with their actions. A handler keeps the services of its own build, never
|
|
7
|
+
* the groups of other plugins, and a runtime resolves groups through one
|
|
8
|
+
* index entry, so per-call context copies grow with the services in the app.
|
|
9
|
+
*/
|
|
10
|
+
const groupKeyPrefix = "@dual-os/sdk/Plugin/Handlers/";
|
|
11
|
+
const handlerGroupKey = (pluginId) => `${groupKeyPrefix}${pluginId}`;
|
|
12
|
+
const isGroupKey = String.startsWith(groupKeyPrefix);
|
|
13
|
+
var HandlerIndex = class extends Context.Service()("@dual-os/sdk/internal/handler-context/HandlerIndex") {};
|
|
14
|
+
const withoutGroups = (context) => {
|
|
15
|
+
const services = Array.filter(Array.fromIterable(context.mapUnsafe), (entry) => !isGroupKey(entry[0]));
|
|
16
|
+
return services.length === context.mapUnsafe.size ? context : Context.makeUnsafe(new Map(services));
|
|
17
|
+
};
|
|
18
|
+
const indexGroups = (context) => {
|
|
19
|
+
const entries = Array.fromIterable(context.mapUnsafe);
|
|
20
|
+
return Context.add(Context.makeUnsafe(new Map(Array.filter(entries, (entry) => !isGroupKey(entry[0])))), HandlerIndex, new Map(Array.filter(entries, (entry) => isGroupKey(entry[0]))));
|
|
21
|
+
};
|
|
22
|
+
const mergeUnder = (lower, input) => Array.reduce(Array.fromIterable(lower.mapUnsafe), input, (merged, entry) => input.mapUnsafe.has(entry[0]) ? merged : Context.addUnsafe(merged, entry[0], entry[1]));
|
|
23
|
+
const findHandler = (context, providerId, handlerKey) => {
|
|
24
|
+
const groupKey = handlerGroupKey(providerId);
|
|
25
|
+
const group = context.mapUnsafe.get(groupKey) ?? Context.getOrUndefined(context, HandlerIndex)?.get(groupKey);
|
|
26
|
+
return Predicate.isMap(group) ? group.get(handlerKey) : void 0;
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { findHandler, handlerGroupKey, indexGroups, mergeUnder, withoutGroups };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=handler-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-context.js","names":[],"sources":["../../src/internal/handler-context.ts"],"sourcesContent":["/**\n * A plugin's handlers live in the layer context as one group entry, keyed by\n * plugin id, so merging layer outputs grows with the number of plugins and\n * not with their actions. A handler keeps the services of its own build, never\n * the groups of other plugins, and a runtime resolves groups through one\n * index entry, so per-call context copies grow with the services in the app.\n */\nimport { Array, Context, Predicate, String } from \"effect\";\n\nconst groupKeyPrefix = \"@dual-os/sdk/Plugin/Handlers/\";\n\nexport const handlerGroupKey = (pluginId: string): string => `${groupKeyPrefix}${pluginId}`;\n\nconst isGroupKey = String.startsWith(groupKeyPrefix);\n\nclass HandlerIndex extends Context.Service<HandlerIndex, ReadonlyMap<string, unknown>>()(\n \"@dual-os/sdk/internal/handler-context/HandlerIndex\",\n) {}\n\nexport const withoutGroups = (context: Context.Context<never>): Context.Context<never> => {\n const services = Array.filter(\n Array.fromIterable(context.mapUnsafe),\n entry => !isGroupKey(entry[0]),\n );\n return services.length === context.mapUnsafe.size\n ? context\n : Context.makeUnsafe(new Map(services));\n};\n\nexport const indexGroups = (context: Context.Context<never>): Context.Context<never> => {\n const entries = Array.fromIterable(context.mapUnsafe);\n return Context.add(\n Context.makeUnsafe(new Map(Array.filter(entries, entry => !isGroupKey(entry[0])))),\n HandlerIndex,\n new Map(Array.filter(entries, entry => isGroupKey(entry[0]))),\n );\n};\n\nexport const mergeUnder = <Input>(\n lower: Context.Context<never>,\n input: Context.Context<Input>,\n): Context.Context<Input> =>\n Array.reduce(Array.fromIterable(lower.mapUnsafe), input, (merged, entry) =>\n input.mapUnsafe.has(entry[0]) ? merged : Context.addUnsafe(merged, entry[0], entry[1]),\n );\n\nexport const findHandler = (\n context: Context.Context<never>,\n providerId: string,\n handlerKey: string,\n): unknown => {\n const groupKey = handlerGroupKey(providerId);\n const group =\n context.mapUnsafe.get(groupKey) ?? Context.getOrUndefined(context, HandlerIndex)?.get(groupKey);\n\n return Predicate.isMap(group) ? group.get(handlerKey) : undefined;\n};\n"],"mappings":";;;;;;;;;AASA,MAAM,iBAAiB;AAEvB,MAAa,mBAAmB,aAA6B,GAAG,iBAAiB;AAEjF,MAAM,aAAa,OAAO,WAAW,cAAc;AAEnD,IAAM,eAAN,cAA2B,QAAQ,QAAoD,CAAC,CACtF,oDACF,CAAC,CAAC,CAAC;AAEH,MAAa,iBAAiB,YAA4D;CACxF,MAAM,WAAW,MAAM,OACrB,MAAM,aAAa,QAAQ,SAAS,IACpC,UAAS,CAAC,WAAW,MAAM,EAAE,CAC/B;CACA,OAAO,SAAS,WAAW,QAAQ,UAAU,OACzC,UACA,QAAQ,WAAW,IAAI,IAAI,QAAQ,CAAC;AAC1C;AAEA,MAAa,eAAe,YAA4D;CACtF,MAAM,UAAU,MAAM,aAAa,QAAQ,SAAS;CACpD,OAAO,QAAQ,IACb,QAAQ,WAAW,IAAI,IAAI,MAAM,OAAO,UAAS,UAAS,CAAC,WAAW,MAAM,EAAE,CAAC,CAAC,CAAC,GACjF,cACA,IAAI,IAAI,MAAM,OAAO,UAAS,UAAS,WAAW,MAAM,EAAE,CAAC,CAAC,CAC9D;AACF;AAEA,MAAa,cACX,OACA,UAEA,MAAM,OAAO,MAAM,aAAa,MAAM,SAAS,GAAG,QAAQ,QAAQ,UAChE,MAAM,UAAU,IAAI,MAAM,EAAE,IAAI,SAAS,QAAQ,UAAU,QAAQ,MAAM,IAAI,MAAM,EAAE,CACvF;AAEF,MAAa,eACX,SACA,YACA,eACY;CACZ,MAAM,WAAW,gBAAgB,UAAU;CAC3C,MAAM,QACJ,QAAQ,UAAU,IAAI,QAAQ,KAAK,QAAQ,eAAe,SAAS,YAAY,CAAC,EAAE,IAAI,QAAQ;CAEhG,OAAO,UAAU,MAAM,KAAK,IAAI,MAAM,IAAI,UAAU,IAAI,KAAA;AAC1D"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DefinitionIdentifierKind } from "../DefinitionError.js";
|
|
2
|
+
//#region src/internal/identifier.d.ts
|
|
3
|
+
export declare const MachineIdSeparator: "/";
|
|
4
|
+
export declare const validateIdentifier: (kind: DefinitionIdentifierKind, identifier: string) => void;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=identifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier.d.ts","names":[],"sources":["../../src/internal/identifier.ts"],"mappings":";;qBAIa;qBAKA,qBAAkB,MAAU,0BAAwB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { InvalidIdentifierError } from "../DefinitionError.js";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
//#region src/internal/identifier.ts
|
|
4
|
+
const MachineIdSeparator = "/";
|
|
5
|
+
const identifierSchema = Schema.String.check(Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/));
|
|
6
|
+
const isIdentifier = Schema.is(identifierSchema);
|
|
7
|
+
const validateIdentifier = (kind, identifier) => {
|
|
8
|
+
if (identifier.length === 0) throw new InvalidIdentifierError({
|
|
9
|
+
identifier,
|
|
10
|
+
kind,
|
|
11
|
+
reason: "empty"
|
|
12
|
+
});
|
|
13
|
+
if (identifier.includes("/")) throw new InvalidIdentifierError({
|
|
14
|
+
identifier,
|
|
15
|
+
kind,
|
|
16
|
+
reason: "contains-reserved-separator",
|
|
17
|
+
reservedCharacter: "/"
|
|
18
|
+
});
|
|
19
|
+
if (!isIdentifier(identifier)) throw new InvalidIdentifierError({
|
|
20
|
+
identifier,
|
|
21
|
+
kind,
|
|
22
|
+
reason: "invalid-format"
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { MachineIdSeparator, validateIdentifier };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=identifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifier.js","names":[],"sources":["../../src/internal/identifier.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nimport { InvalidIdentifierError, type DefinitionIdentifierKind } from \"../DefinitionError.ts\";\n\nexport const MachineIdSeparator = \"/\" as const;\n\nconst identifierSchema = Schema.String.check(Schema.isPattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/));\nconst isIdentifier = Schema.is(identifierSchema);\n\nexport const validateIdentifier = (kind: DefinitionIdentifierKind, identifier: string): void => {\n if (identifier.length === 0) {\n throw new InvalidIdentifierError({ identifier, kind, reason: \"empty\" });\n }\n\n if (identifier.includes(MachineIdSeparator)) {\n throw new InvalidIdentifierError({\n identifier,\n kind,\n reason: \"contains-reserved-separator\",\n reservedCharacter: MachineIdSeparator,\n });\n }\n\n if (!isIdentifier(identifier)) {\n throw new InvalidIdentifierError({ identifier, kind, reason: \"invalid-format\" });\n }\n};\n"],"mappings":";;;AAIA,MAAa,qBAAqB;AAElC,MAAM,mBAAmB,OAAO,OAAO,MAAM,OAAO,UAAU,4BAA4B,CAAC;AAC3F,MAAM,eAAe,OAAO,GAAG,gBAAgB;AAE/C,MAAa,sBAAsB,MAAgC,eAA6B;CAC9F,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,uBAAuB;EAAE;EAAY;EAAM,QAAQ;CAAQ,CAAC;CAGxE,IAAI,WAAW,SAAA,GAA2B,GACxC,MAAM,IAAI,uBAAuB;EAC/B;EACA;EACA,QAAQ;EACR,mBAAA;CACF,CAAC;CAGH,IAAI,CAAC,aAAa,UAAU,GAC1B,MAAM,IAAI,uBAAuB;EAAE;EAAY;EAAM,QAAQ;CAAiB,CAAC;AAEnF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Any } from "../AuthMethod.js";
|
|
2
|
+
import { Handler } from "../AgentChannel.js";
|
|
3
|
+
import { Any as Any$1, Handler as Handler$1 } from "../Trigger.js";
|
|
4
|
+
import { Any as Any$2 } from "../Group.js";
|
|
5
|
+
import { MachineIdSeparator } from "./identifier.js";
|
|
6
|
+
import { IsGenericArray, JoinPrefix } from "./types.js";
|
|
7
|
+
import { Any as Any$3 } from "../Plugin.js";
|
|
8
|
+
import { Context, Effect } from "effect";
|
|
9
|
+
//#region src/internal/plugin-handlers.d.ts
|
|
10
|
+
type LocalTriggerEntriesFromTriggers<Triggers extends readonly Any$1[], Prefix extends string, AllowedMethods extends readonly Any[]> = Triggers[number] extends (infer TriggerDef) ? TriggerDef extends Any$1 ? {
|
|
11
|
+
readonly localId: JoinPrefix<Prefix, TriggerDef["identifier"]>;
|
|
12
|
+
readonly trigger: TriggerDef;
|
|
13
|
+
readonly authMethods: AllowedMethods;
|
|
14
|
+
} : never : never;
|
|
15
|
+
type LocalTriggerEntriesFromGroups<GroupDef extends Any$2, Prefix extends string, AllowedMethods extends readonly Any[]> = GroupDef extends unknown ? LocalTriggerEntriesFromTriggers<GroupDef["triggers"], JoinPrefix<Prefix, GroupDef["identifier"]>, AllowedMethods> | (IsGenericArray<GroupDef["groups"]> extends true ? LocalTriggerEntriesFromTriggers<readonly Any$1[], string, AllowedMethods> : LocalTriggerEntriesFromGroups<GroupDef["groups"][number], JoinPrefix<Prefix, GroupDef["identifier"]>, AllowedMethods>) : never;
|
|
16
|
+
export type LocalTriggerEntries<P extends Any$3> = LocalTriggerEntriesFromTriggers<P["triggers"], "", P["authMethods"]> | LocalTriggerEntriesFromGroups<P["groups"][number], "", P["authMethods"]>;
|
|
17
|
+
export type CanonicalTriggerId<P extends Any$3, LocalId extends string> = `${P["identifier"]}${typeof MachineIdSeparator}${LocalId}`;
|
|
18
|
+
/** Keyed by the plugin's capabilities, which `Plugin.provide` keeps, so a Layer serves only them. */
|
|
19
|
+
export interface ActionHandlerService<in out PluginId extends string, in out Actions extends readonly unknown[], in out Groups extends readonly unknown[]> {
|
|
20
|
+
readonly _: unique symbol;
|
|
21
|
+
readonly pluginId: PluginId;
|
|
22
|
+
readonly actions: Actions;
|
|
23
|
+
readonly groups: Groups;
|
|
24
|
+
}
|
|
25
|
+
export type ActionHandlerServiceOf<P extends Any$3> = ActionHandlerService<P["identifier"], P["actions"], P["groups"]>;
|
|
26
|
+
export type HandlerServices<P extends Any$3> = ActionHandlerServiceOf<P> | ([P["agentChannels"][number]] extends [never] ? never : Handler<`${P["identifier"]}/${P["agentChannels"][number]["identifier"]}`>) | (LocalTriggerEntries<P> extends (infer Entry) ? Entry extends {
|
|
27
|
+
readonly localId: infer LocalId extends string;
|
|
28
|
+
} ? Handler$1<CanonicalTriggerId<P, LocalId>> : never : never);
|
|
29
|
+
interface Declarations {
|
|
30
|
+
readonly actions: unknown;
|
|
31
|
+
readonly triggers: unknown;
|
|
32
|
+
readonly agentChannels: unknown;
|
|
33
|
+
}
|
|
34
|
+
/** Register a plugin's handlers as one Context group keyed by the plugin. */
|
|
35
|
+
export declare const toHandlers: (plugin: Any$3, handlers: Declarations) => Effect.Effect<Context.Context<never>>;
|
|
36
|
+
//#endregion
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=plugin-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-handlers.d.ts","names":["Trigger.Any","AuthMethod.Any","Group.Any","Any","AgentChannel.Handler","Trigger.Handler"],"sources":["../../src/internal/plugin-handlers.ts"],"mappings":";;;;;;;;;KAeK,gCACH,0BAA0BA,SAC1B,uBACA,gCAAgCC,SAC9B,gCAA+B,cAC/B,mBAAmBD;WAEN,SAAS,WAAW,QAAQ;WAC5B,SAAS;WACT,aAAa;;KAKzB,8BACH,iBAAiBE,OACjB,uBACA,gCAAgCD,SAC9B,2BAEI,gCACE,sBACA,WAAW,QAAQ,yBACnB,mBAED,eAAe,mCACZ,yCAAyCD,iBAAuB,kBAChE,8BACE,4BACA,WAAW,QAAQ,yBACnB;YAIF,oBAAoB,UAAUG,SACtC,gCAAgC,mBAAmB,oBACnD,8BAA8B,yBAAyB;YAE/C,mBACV,UAAUA,OACV,6BACK,yBAAyB,qBAAqB;;iBAGpC,4BACR,gCACA,2CACA;WAEE;WACA,UAAU;WACV,SAAS;WACT,QAAQ;;YAGP,uBAAuB,UAAUA,SAAO,qBAClD,iBACA,cACA;YAGU,gBAAgB,UAAUA,SAClC,uBAAuB,OACrB,sDAEEC,WAAwB,mBAAmB,gDAC9C,oBAAoB,kBAAiB,SAClC;WAAyB,eAAe;IACtCC,UAAgB,mBAAmB,GAAG;UAItC;WACC;WACA;WACA;;;qBAmBE,aAAU,QACbF,OAAG,UACD,iBACT,OAAO,OAAO,QAAQ"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import "./identifier.js";
|
|
2
|
+
import { handlerKey } from "../Action.js";
|
|
3
|
+
import { handlerKey as handlerKey$1 } from "../AgentChannel.js";
|
|
4
|
+
import { handlerGroupKey, withoutGroups } from "./handler-context.js";
|
|
5
|
+
import { walkCapabilities } from "./capabilities.js";
|
|
6
|
+
import { handlerKey as handlerKey$2 } from "../Trigger.js";
|
|
7
|
+
import { Context, Effect, Predicate } from "effect";
|
|
8
|
+
//#region src/internal/plugin-handlers.ts
|
|
9
|
+
/** Plugin handler services and their registration. */
|
|
10
|
+
const missingDeclaration = (kind, localId, pluginId) => {
|
|
11
|
+
throw new Error(`missing ${kind} handler for "${localId}" in plugin "${pluginId}"`);
|
|
12
|
+
};
|
|
13
|
+
const getNestedHandler = (handlers, localId) => {
|
|
14
|
+
let current = handlers;
|
|
15
|
+
for (const segment of localId.split("/")) {
|
|
16
|
+
if (!Predicate.hasProperty(current, segment)) return void 0;
|
|
17
|
+
current = current[segment];
|
|
18
|
+
}
|
|
19
|
+
return current;
|
|
20
|
+
};
|
|
21
|
+
/** Register a plugin's handlers as one Context group keyed by the plugin. */
|
|
22
|
+
const toHandlers = (plugin, handlers) => Effect.gen(function* () {
|
|
23
|
+
const services = withoutGroups(yield* Effect.context());
|
|
24
|
+
const map = /* @__PURE__ */ new Map();
|
|
25
|
+
const find = (kind, declarations, localId) => {
|
|
26
|
+
const handler = getNestedHandler(declarations, localId);
|
|
27
|
+
return handler === void 0 ? missingDeclaration(kind, localId, plugin.identifier) : handler;
|
|
28
|
+
};
|
|
29
|
+
for (const entry of walkCapabilities(plugin, (owner) => owner.actions)) map.set(handlerKey(entry.canonicalId), {
|
|
30
|
+
actionId: entry.canonicalId,
|
|
31
|
+
context: services,
|
|
32
|
+
handler: find("action", handlers.actions, entry.localId)
|
|
33
|
+
});
|
|
34
|
+
for (const entry of walkCapabilities(plugin, (owner) => owner.triggers)) map.set(handlerKey$2(entry.canonicalId), {
|
|
35
|
+
context: services,
|
|
36
|
+
runtime: find("trigger", handlers.triggers, entry.localId),
|
|
37
|
+
triggerId: entry.canonicalId
|
|
38
|
+
});
|
|
39
|
+
for (const channel of plugin.agentChannels) {
|
|
40
|
+
const channelId = `${plugin.identifier}/${channel.identifier}`;
|
|
41
|
+
map.set(handlerKey$1(channelId), {
|
|
42
|
+
channelId,
|
|
43
|
+
context: services,
|
|
44
|
+
runtime: find("agent channel", handlers.agentChannels, channel.identifier)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return Context.makeUnsafe(/* @__PURE__ */ new Map([[handlerGroupKey(plugin.identifier), map]]));
|
|
48
|
+
});
|
|
49
|
+
//#endregion
|
|
50
|
+
export { toHandlers };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=plugin-handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-handlers.js","names":["Action.handlerKey","Trigger.handlerKey","AgentChannel.handlerKey"],"sources":["../../src/internal/plugin-handlers.ts"],"sourcesContent":["/** Plugin handler services and their registration. */\nimport { Context, Effect, Predicate } from \"effect\";\n\nimport * as Action from \"../Action.ts\";\nimport * as AgentChannel from \"../AgentChannel.ts\";\nimport type * as AuthMethod from \"../AuthMethod.ts\";\nimport type * as Group from \"../Group.ts\";\nimport type { Any } from \"../Plugin.ts\";\nimport * as Trigger from \"../Trigger.ts\";\n\nimport { walkCapabilities } from \"./capabilities.ts\";\nimport { handlerGroupKey, withoutGroups } from \"./handler-context.ts\";\nimport { MachineIdSeparator } from \"./identifier.ts\";\nimport type { IsGenericArray, JoinPrefix } from \"./types.ts\";\n\ntype LocalTriggerEntriesFromTriggers<\n Triggers extends readonly Trigger.Any[],\n Prefix extends string,\n AllowedMethods extends readonly AuthMethod.Any[],\n> = Triggers[number] extends infer TriggerDef\n ? TriggerDef extends Trigger.Any\n ? {\n readonly localId: JoinPrefix<Prefix, TriggerDef[\"identifier\"]>;\n readonly trigger: TriggerDef;\n readonly authMethods: AllowedMethods;\n }\n : never\n : never;\n\ntype LocalTriggerEntriesFromGroups<\n GroupDef extends Group.Any,\n Prefix extends string,\n AllowedMethods extends readonly AuthMethod.Any[],\n> = GroupDef extends unknown\n ?\n | LocalTriggerEntriesFromTriggers<\n GroupDef[\"triggers\"],\n JoinPrefix<Prefix, GroupDef[\"identifier\"]>,\n AllowedMethods\n >\n | (IsGenericArray<GroupDef[\"groups\"]> extends true\n ? LocalTriggerEntriesFromTriggers<readonly Trigger.Any[], string, AllowedMethods>\n : LocalTriggerEntriesFromGroups<\n GroupDef[\"groups\"][number],\n JoinPrefix<Prefix, GroupDef[\"identifier\"]>,\n AllowedMethods\n >)\n : never;\n\nexport type LocalTriggerEntries<P extends Any> =\n | LocalTriggerEntriesFromTriggers<P[\"triggers\"], \"\", P[\"authMethods\"]>\n | LocalTriggerEntriesFromGroups<P[\"groups\"][number], \"\", P[\"authMethods\"]>;\n\nexport type CanonicalTriggerId<\n P extends Any,\n LocalId extends string,\n> = `${P[\"identifier\"]}${typeof MachineIdSeparator}${LocalId}`;\n\n/** Keyed by the plugin's capabilities, which `Plugin.provide` keeps, so a Layer serves only them. */\nexport interface ActionHandlerService<\n in out PluginId extends string,\n in out Actions extends readonly unknown[],\n in out Groups extends readonly unknown[],\n> {\n readonly _: unique symbol;\n readonly pluginId: PluginId;\n readonly actions: Actions;\n readonly groups: Groups;\n}\n\nexport type ActionHandlerServiceOf<P extends Any> = ActionHandlerService<\n P[\"identifier\"],\n P[\"actions\"],\n P[\"groups\"]\n>;\n\nexport type HandlerServices<P extends Any> =\n | ActionHandlerServiceOf<P>\n | ([P[\"agentChannels\"][number]] extends [never]\n ? never\n : AgentChannel.Handler<`${P[\"identifier\"]}/${P[\"agentChannels\"][number][\"identifier\"]}`>)\n | (LocalTriggerEntries<P> extends infer Entry\n ? Entry extends { readonly localId: infer LocalId extends string }\n ? Trigger.Handler<CanonicalTriggerId<P, LocalId>>\n : never\n : never);\n\ninterface Declarations {\n readonly actions: unknown;\n readonly triggers: unknown;\n readonly agentChannels: unknown;\n}\n\n/* Missing handler declarations are builder defects, not expected failures, so\n they intentionally throw instead of entering the Effect failure channel. */\nconst missingDeclaration = (kind: string, localId: string, pluginId: string): never => {\n throw new Error(`missing ${kind} handler for \"${localId}\" in plugin \"${pluginId}\"`);\n};\n\nconst getNestedHandler = (handlers: unknown, localId: string): unknown => {\n let current = handlers;\n for (const segment of localId.split(MachineIdSeparator)) {\n if (!Predicate.hasProperty(current, segment)) return undefined;\n current = current[segment];\n }\n return current;\n};\n\n/** Register a plugin's handlers as one Context group keyed by the plugin. */\nexport const toHandlers = (\n plugin: Any,\n handlers: Declarations,\n): Effect.Effect<Context.Context<never>> =>\n Effect.gen(function* () {\n const services = withoutGroups(yield* Effect.context());\n const map = new Map<string, unknown>();\n // A declared but invalid handler, such as `null` from JavaScript, fails when it is used.\n const find = (kind: string, declarations: unknown, localId: string) => {\n const handler = getNestedHandler(declarations, localId);\n return handler === undefined ? missingDeclaration(kind, localId, plugin.identifier) : handler;\n };\n\n for (const entry of walkCapabilities(plugin, owner => owner.actions)) {\n map.set(Action.handlerKey(entry.canonicalId), {\n actionId: entry.canonicalId,\n context: services,\n handler: find(\"action\", handlers.actions, entry.localId),\n });\n }\n for (const entry of walkCapabilities(plugin, owner => owner.triggers)) {\n map.set(Trigger.handlerKey(entry.canonicalId), {\n context: services,\n runtime: find(\"trigger\", handlers.triggers, entry.localId),\n triggerId: entry.canonicalId,\n });\n }\n for (const channel of plugin.agentChannels) {\n const channelId = `${plugin.identifier}/${channel.identifier}`;\n map.set(AgentChannel.handlerKey(channelId), {\n channelId,\n context: services,\n runtime: find(\"agent channel\", handlers.agentChannels, channel.identifier),\n });\n }\n return Context.makeUnsafe(new Map([[handlerGroupKey(plugin.identifier), map]]));\n });\n"],"mappings":";;;;;;;;;AA+FA,MAAM,sBAAsB,MAAc,SAAiB,aAA4B;CACrF,MAAM,IAAI,MAAM,WAAW,KAAK,gBAAgB,QAAQ,eAAe,SAAS,EAAE;AACpF;AAEA,MAAM,oBAAoB,UAAmB,YAA6B;CACxE,IAAI,UAAU;CACd,KAAK,MAAM,WAAW,QAAQ,MAAA,GAAwB,GAAG;EACvD,IAAI,CAAC,UAAU,YAAY,SAAS,OAAO,GAAG,OAAO,KAAA;EACrD,UAAU,QAAQ;CACpB;CACA,OAAO;AACT;;AAGA,MAAa,cACX,QACA,aAEA,OAAO,IAAI,aAAa;CACtB,MAAM,WAAW,cAAc,OAAO,OAAO,QAAQ,CAAC;CACtD,MAAM,sBAAM,IAAI,IAAqB;CAErC,MAAM,QAAQ,MAAc,cAAuB,YAAoB;EACrE,MAAM,UAAU,iBAAiB,cAAc,OAAO;EACtD,OAAO,YAAY,KAAA,IAAY,mBAAmB,MAAM,SAAS,OAAO,UAAU,IAAI;CACxF;CAEA,KAAK,MAAM,SAAS,iBAAiB,SAAQ,UAAS,MAAM,OAAO,GACjE,IAAI,IAAIA,WAAkB,MAAM,WAAW,GAAG;EAC5C,UAAU,MAAM;EAChB,SAAS;EACT,SAAS,KAAK,UAAU,SAAS,SAAS,MAAM,OAAO;CACzD,CAAC;CAEH,KAAK,MAAM,SAAS,iBAAiB,SAAQ,UAAS,MAAM,QAAQ,GAClE,IAAI,IAAIC,aAAmB,MAAM,WAAW,GAAG;EAC7C,SAAS;EACT,SAAS,KAAK,WAAW,SAAS,UAAU,MAAM,OAAO;EACzD,WAAW,MAAM;CACnB,CAAC;CAEH,KAAK,MAAM,WAAW,OAAO,eAAe;EAC1C,MAAM,YAAY,GAAG,OAAO,WAAW,GAAG,QAAQ;EAClD,IAAI,IAAIC,aAAwB,SAAS,GAAG;GAC1C;GACA,SAAS;GACT,SAAS,KAAK,iBAAiB,SAAS,eAAe,QAAQ,UAAU;EAC3E,CAAC;CACH;CACA,OAAO,QAAQ,2BAAW,IAAI,IAAI,CAAC,CAAC,gBAAgB,OAAO,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC;AAChF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto.d.ts","names":[],"sources":["../../src/internal/proto.ts"],"mappings":";;qBAGa;EACX"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Pipeable } from "effect";
|
|
2
|
+
//#region src/internal/proto.ts
|
|
3
|
+
/** Shared prototype mixin for all SDK definition objects. */
|
|
4
|
+
const PipeableProto = { pipe() {
|
|
5
|
+
return Pipeable.pipeArguments(this, arguments);
|
|
6
|
+
} };
|
|
7
|
+
//#endregion
|
|
8
|
+
export { PipeableProto };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=proto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto.js","names":[],"sources":["../../src/internal/proto.ts"],"sourcesContent":["import { Pipeable } from \"effect\";\n\n/** Shared prototype mixin for all SDK definition objects. */\nexport const PipeableProto = {\n pipe() {\n return Pipeable.pipeArguments(this, arguments);\n },\n};\n"],"mappings":";;;AAGA,MAAa,gBAAgB,EAC3B,OAAO;CACL,OAAO,SAAS,cAAc,MAAM,SAAS;AAC/C,EACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
//#region src/internal/schema-runtime.d.ts
|
|
3
|
+
export declare function decodeJson<SchemaDef extends Schema.Top>(schema: SchemaDef, value: unknown): Effect.Effect<SchemaDef["Type"], Schema.SchemaError, SchemaDef["DecodingServices"]>;
|
|
4
|
+
export declare const decodeJsonMapError: <SchemaDef extends Schema.Top, Error>(schema: SchemaDef, value: unknown, mapError: (error: Schema.SchemaError) => Error) => Effect.Effect<SchemaDef["Type"], Error, SchemaDef["DecodingServices"]>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=schema-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-runtime.d.ts","names":[],"sources":["../../src/internal/schema-runtime.ts"],"mappings":";;wBAEgB,WAAW,kBAAkB,OAAO,KAClD,QAAQ,WACR,iBACC,OAAO,OAAO,mBAAmB,OAAO,aAAa;qBAI3C,qBAAsB,kBAAkB,OAAO,KAAK,OAAK,QAC5D,WAAS,gBACH,WACH,OAAO,OAAO,gBAAgB,UACxC,OAAO,OAAO,mBAAmB,OAAO"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
//#region src/internal/schema-runtime.ts
|
|
3
|
+
function decodeJson(schema, value) {
|
|
4
|
+
return Schema.decodeUnknownEffect(Schema.toCodecJson(schema))(value);
|
|
5
|
+
}
|
|
6
|
+
const decodeJsonMapError = (schema, value, mapError) => decodeJson(schema, value).pipe(Effect.mapError(mapError));
|
|
7
|
+
//#endregion
|
|
8
|
+
export { decodeJson, decodeJsonMapError };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=schema-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-runtime.js","names":[],"sources":["../../src/internal/schema-runtime.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\n\nexport function decodeJson<SchemaDef extends Schema.Top>(\n schema: SchemaDef,\n value: unknown,\n): Effect.Effect<SchemaDef[\"Type\"], Schema.SchemaError, SchemaDef[\"DecodingServices\"]> {\n return Schema.decodeUnknownEffect(Schema.toCodecJson(schema))(value);\n}\n\nexport const decodeJsonMapError = <SchemaDef extends Schema.Top, Error>(\n schema: SchemaDef,\n value: unknown,\n mapError: (error: Schema.SchemaError) => Error,\n): Effect.Effect<SchemaDef[\"Type\"], Error, SchemaDef[\"DecodingServices\"]> =>\n decodeJson(schema, value).pipe(Effect.mapError(mapError));\n"],"mappings":";;AAEA,SAAgB,WACd,QACA,OACqF;CACrF,OAAO,OAAO,oBAAoB,OAAO,YAAY,MAAM,CAAC,CAAC,CAAC,KAAK;AACrE;AAEA,MAAa,sBACX,QACA,OACA,aAEA,WAAW,QAAQ,KAAK,CAAC,CAAC,KAAK,OAAO,SAAS,QAAQ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConnectionResolutionContext, Service } from "../ConnectionResolver.js";
|
|
2
|
+
import { AuthResolutionRequirements, AuthSchemaRequirements, RuntimeConnectionErrorsFor } from "./auth-execution.js";
|
|
3
|
+
import { Any, ConfigSchema, Handler, InvalidTriggerConfigError, InvalidTriggerOutputError, InvalidTriggerStateError, KeyedEvent, OutputSchema, PollingRuntime, RuntimeContext, RuntimePhase, RuntimeTriggerEntry, StateSchema, UnsupportedTriggerRuntimeError, WebhookRuntime } from "../Trigger.js";
|
|
4
|
+
import { Context, Effect, Schema } from "effect";
|
|
5
|
+
//#region src/internal/trigger-runtime-shared.d.ts
|
|
6
|
+
type ConfigRequirements<TriggerDef extends Any> = ConfigSchema<TriggerDef>["DecodingServices"];
|
|
7
|
+
type StateDecodingRequirements<TriggerDef extends Any> = StateSchema<TriggerDef> extends Schema.Top ? Exclude<StateSchema<TriggerDef>, undefined>["DecodingServices"] : never;
|
|
8
|
+
type StateEncodingRequirements<TriggerDef extends Any> = StateSchema<TriggerDef> extends Schema.Top ? Exclude<StateSchema<TriggerDef>, undefined>["EncodingServices"] : never;
|
|
9
|
+
type OutputEncodingRequirements<TriggerDef extends Any> = OutputSchema<TriggerDef>["EncodingServices"];
|
|
10
|
+
/**
|
|
11
|
+
* Trigger hooks may fail with arbitrary app-defined errors, so phase failures
|
|
12
|
+
* deliberately widen to `unknown`. The alias keeps that decision visible in
|
|
13
|
+
* the phase signatures.
|
|
14
|
+
*/
|
|
15
|
+
export type TriggerAppError<_TriggerDef extends Any> = unknown;
|
|
16
|
+
export type TriggerEncodedState<TriggerDef extends Any> = StateSchema<TriggerDef> extends Schema.Top ? Exclude<StateSchema<TriggerDef>, undefined>["Encoded"] | undefined : undefined;
|
|
17
|
+
export type TriggerEncodedOutput<TriggerDef extends Any> = OutputSchema<TriggerDef>["Encoded"];
|
|
18
|
+
export type TriggerIdOf<Entry extends RuntimeTriggerEntry<any, any, any, any>> = Entry["triggerId"];
|
|
19
|
+
export type EntryTrigger<Entry extends RuntimeTriggerEntry<any, any, any, any>> = Entry["trigger"];
|
|
20
|
+
export type EntryAuthMethods<Entry extends RuntimeTriggerEntry<any, any, any, any>> = Entry["authMethods"];
|
|
21
|
+
type EntryHandler<Entry extends RuntimeTriggerEntry<any, any, any, any>> = Handler<TriggerIdOf<Entry>>;
|
|
22
|
+
export type TriggerRuntimeRequirements<Entry extends RuntimeTriggerEntry<any, any, any, any>, Phase extends RuntimePhase> = EntryHandler<Entry> | ConfigRequirements<EntryTrigger<Entry>> | StateDecodingRequirements<EntryTrigger<Entry>> | (Phase extends "activate" | "verify" | "parse" | "poll" ? StateEncodingRequirements<EntryTrigger<Entry>> : never) | (Phase extends "parse" | "poll" ? OutputEncodingRequirements<EntryTrigger<Entry>> : never) | ([EntryAuthMethods<Entry>[number]] extends [never] ? never : Service | AuthSchemaRequirements<EntryAuthMethods<Entry>> | AuthResolutionRequirements<EntryAuthMethods<Entry>>);
|
|
23
|
+
export declare const decodeConfig: <Config extends Schema.Top>(triggerId: string, schema: Config, value: unknown) => Effect.Effect<Config["Type"], InvalidTriggerConfigError, Config["DecodingServices"]>;
|
|
24
|
+
export declare function decodeState(triggerId: string, phase: RuntimePhase, schema: undefined, value: unknown): Effect.Effect<undefined, InvalidTriggerStateError>;
|
|
25
|
+
export declare function decodeState<State extends Schema.Top>(triggerId: string, phase: RuntimePhase, schema: State, value: unknown): Effect.Effect<State["Type"] | undefined, InvalidTriggerStateError, State["DecodingServices"]>;
|
|
26
|
+
export declare function validateStateResult(triggerId: string, phase: RuntimePhase, schema: undefined, value: undefined): Effect.Effect<undefined, InvalidTriggerStateError>;
|
|
27
|
+
export declare function validateStateResult<State extends Schema.Top>(triggerId: string, phase: RuntimePhase, schema: State, value: State["Type"] | undefined): Effect.Effect<State["Encoded"] | undefined, InvalidTriggerStateError, State["EncodingServices"]>;
|
|
28
|
+
export declare const validateOutputs: <Output extends Schema.Top>(triggerId: string, phase: "parse" | "poll", schema: Output, events: unknown) => Effect.Effect<readonly KeyedEvent<Output["Encoded"]>[], InvalidTriggerOutputError, Output["EncodingServices"]>;
|
|
29
|
+
interface RuntimeHook<Hook> {
|
|
30
|
+
readonly hook: Hook;
|
|
31
|
+
readonly context: Context.Context<never>;
|
|
32
|
+
}
|
|
33
|
+
type WebhookPhase = "activate" | "deactivate" | "verify" | "parse";
|
|
34
|
+
type WebhookHook<Phase extends WebhookPhase> = NonNullable<WebhookRuntime<Schema.Top, Schema.Top, Schema.Top | undefined, any, any, any>[Phase]>;
|
|
35
|
+
type PollHook = NonNullable<PollingRuntime<Schema.Top, Schema.Top, Schema.Top | undefined, any, any, any>["poll"]>;
|
|
36
|
+
export declare const requireWebhookHook: <Entry extends RuntimeTriggerEntry<any, any, any, any>, Phase extends WebhookPhase>(entry: Entry, phase: Phase) => Effect.Effect<RuntimeHook<WebhookHook<Phase>>, UnsupportedTriggerRuntimeError, EntryHandler<Entry>>;
|
|
37
|
+
export declare const requirePollingHook: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry) => Effect.Effect<RuntimeHook<PollHook>, UnsupportedTriggerRuntimeError, EntryHandler<Entry>>;
|
|
38
|
+
export declare const withRuntimeContext: <Entry extends RuntimeTriggerEntry<any, any, any, any>, Phase extends RuntimePhase, Result>(entry: Entry, phase: Phase, connectionId: string | undefined, context: ConnectionResolutionContext | undefined, run: (context: RuntimeContext<EntryAuthMethods<Entry>>) => Effect.Effect<Result, TriggerAppError<EntryTrigger<Entry>> | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>>, TriggerRuntimeRequirements<Entry, Phase>>) => Effect.Effect<Result, TriggerAppError<EntryTrigger<Entry>> | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>>, TriggerRuntimeRequirements<Entry, Phase>>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=trigger-runtime-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-runtime-shared.d.ts","names":["Trigger.Any","Trigger.ConfigSchema","Trigger.StateSchema","Trigger.OutputSchema","Trigger.RuntimeTriggerEntry","Trigger.Handler","Trigger.RuntimePhase","Trigger.InvalidTriggerConfigError","Trigger.InvalidTriggerStateError","Trigger.KeyedEvent","Trigger.InvalidTriggerOutputError","Trigger.WebhookRuntime","Trigger.PollingRuntime","Trigger.UnsupportedTriggerRuntimeError","Trigger.RuntimeContext"],"sources":["../../src/internal/trigger-runtime-shared.ts"],"mappings":";;;;;KAmBK,mBAAmB,mBAAmBA,OACzCC,aAAqB;KAElB,0BAA0B,mBAAmBD,OAChDE,YAAoB,oBAAoB,OAAO,MAC3C,QAAQA,YAAoB;KAG7B,0BAA0B,mBAAmBF,OAChDE,YAAoB,oBAAoB,OAAO,MAC3C,QAAQA,YAAoB;KAG7B,2BAA2B,mBAAmBF,OACjDG,aAAqB;;;;;;YAOX,gBAAgB,oBAAoBH;YAEpC,oBAAoB,mBAAmBA,OACjDE,YAAoB,oBAAoB,OAAO,MAC3C,QAAQA,YAAoB;YAGtB,qBAAqB,mBAAmBF,OAClDG,aAAqB;YAEX,YAAY,cAAcC,2CACpC;YACU,aAAa,cAAcA,2CACrC;YACU,iBAAiB,cAAcA,2CACzC;KACG,aAAa,cAAcA,2CAAmDC,QACjF,YAAY;YAGF,2BACV,cAAcD,yCACd,cAAcE,gBAEZ,aAAa,SACb,mBAAmB,aAAa,UAChC,0BAA0B,aAAa,WACtC,yDACG,0BAA0B,aAAa,oBAE1C,iCAAiC,2BAA2B,aAAa,qBACxE,iBAAiB,0CAGX,UACA,uBAAuB,iBAAiB,UACxC,2BAA2B,iBAAiB;qBAE3C,eAAgB,eAAe,OAAO,KAAG,mBACnC,QACT,QAAM,mBAEb,OAAO,OAAO,gBAAgBC,2BAAmC;wBA4BpD,YACd,mBACA,OAAOD,cACP,mBACA,iBACC,OAAO,kBAAkBE;wBACZ,YAAY,cAAc,OAAO,KAC/C,mBACA,OAAOF,cACP,QAAQ,OACR,iBACC,OAAO,OACR,2BACAE,0BACA;wBA6Dc,oBACd,mBACA,OAAOF,cACP,mBACA,mBACC,OAAO,kBAAkBE;wBACZ,oBAAoB,cAAc,OAAO,KACvD,mBACA,OAAOF,cACP,QAAQ,OACR,OAAO,4BACN,OAAO,OACR,8BACAE,0BACA;qBAgDW,kBAAmB,eAAe,OAAO,KAAG,mBACtC,yBACM,QACf,QAAM,oBAEb,OAAO,gBACCC,WAAmB,sBAC5BC,2BACA;UAcQ,YAAY;WACX,MAAM;WACN,SAAS,QAAQ;;KAGvB;KAEA,YAAY,cAAc,gBAAgB,YAC7CC,eAAuB,OAAO,KAAK,OAAO,KAAK,OAAO,gCAAgC;KAGnF,WAAW,YACdC,eAAuB,OAAO,KAAK,OAAO,KAAK,OAAO;qBA8B3C,qBACX,cAAcR,yCACd,cAAc,cAAY,OAEnB,OAAK,OACL,UACN,OAAO,OACR,YAAY,YAAY,SACxBS,gCACA,aAAa;qBA+BF,qBAAsB,cAAcT,yCAA+C,OACvF,UACN,OAAO,OACR,YAAY,WACZS,gCACA,aAAa;qBA+BF,qBACX,cAAcT,yCACd,cAAcE,cACd,QAEA,OAAO,OACP,OAAO,OACP,kCACA,SAAS,yCACT,MACE,SAASQ,eAAuB,iBAAiB,YAC9C,OAAO,OACV,QACA,gBAAgB,aAAa,UAAU,2BAA2B,iBAAiB,SACnF,2BAA2B,OAAO,YAEjC,OAAO,OACV,QACA,gBAAgB,aAAa,UAAU,2BAA2B,iBAAiB,SACnF,2BAA2B,OAAO"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { findHandler } from "./handler-context.js";
|
|
2
|
+
import { decodeJson, decodeJsonMapError } from "./schema-runtime.js";
|
|
3
|
+
import { authRuntimeContext, failConnectionIdNotAllowed, noAuthRuntimeContext, resolveRuntimeConnection, toNonEmptyArray } from "./auth-execution.js";
|
|
4
|
+
import { InvalidTriggerConfigError, InvalidTriggerOutputError, InvalidTriggerStateError, UnsupportedTriggerRuntimeError, handlerKey } from "../Trigger.js";
|
|
5
|
+
import { Effect, Schema } from "effect";
|
|
6
|
+
//#region src/internal/trigger-runtime-shared.ts
|
|
7
|
+
const decodeConfig = (triggerId, schema, value) => decodeJsonMapError(schema, value, (error) => new InvalidTriggerConfigError({
|
|
8
|
+
description: error.message,
|
|
9
|
+
triggerId
|
|
10
|
+
}));
|
|
11
|
+
const decodeStateValue = () => Effect.as(Effect.void, void 0);
|
|
12
|
+
function decodeStateSchema(schema, value) {
|
|
13
|
+
if (value === void 0) return decodeStateValue();
|
|
14
|
+
return decodeJson(schema, value);
|
|
15
|
+
}
|
|
16
|
+
function decodeState(triggerId, phase, schema, value) {
|
|
17
|
+
if (schema === void 0) return value === void 0 ? decodeStateValue() : Effect.fail(new InvalidTriggerStateError({
|
|
18
|
+
description: "state is not supported for this trigger",
|
|
19
|
+
location: "input",
|
|
20
|
+
phase,
|
|
21
|
+
triggerId
|
|
22
|
+
}));
|
|
23
|
+
return decodeStateSchema(schema, value).pipe(Effect.mapError((error) => new InvalidTriggerStateError({
|
|
24
|
+
description: error.message,
|
|
25
|
+
location: "input",
|
|
26
|
+
phase,
|
|
27
|
+
triggerId
|
|
28
|
+
})));
|
|
29
|
+
}
|
|
30
|
+
const encodeStateSchema = (triggerId, phase, schema, value) => {
|
|
31
|
+
if (value === void 0) return Effect.void;
|
|
32
|
+
return Schema.encodeEffect(schema)(value).pipe(Effect.mapError((error) => new InvalidTriggerStateError({
|
|
33
|
+
description: error.message,
|
|
34
|
+
location: "result",
|
|
35
|
+
phase,
|
|
36
|
+
triggerId
|
|
37
|
+
})));
|
|
38
|
+
};
|
|
39
|
+
function validateStateResult(triggerId, phase, schema, value) {
|
|
40
|
+
if (schema === void 0) return value === void 0 ? decodeStateValue() : Effect.fail(new InvalidTriggerStateError({
|
|
41
|
+
description: "state is not supported for this trigger",
|
|
42
|
+
location: "result",
|
|
43
|
+
phase,
|
|
44
|
+
triggerId
|
|
45
|
+
}));
|
|
46
|
+
return encodeStateSchema(triggerId, phase, schema, value);
|
|
47
|
+
}
|
|
48
|
+
const KeyedEventEnvelope = Schema.Struct({
|
|
49
|
+
key: Schema.NonEmptyString,
|
|
50
|
+
payload: Schema.Unknown
|
|
51
|
+
});
|
|
52
|
+
const eventKeysAreUnique = (events) => {
|
|
53
|
+
const seen = /* @__PURE__ */ new Set();
|
|
54
|
+
for (const event of events) {
|
|
55
|
+
if (seen.has(event.key)) return `duplicate event key "${event.key}"`;
|
|
56
|
+
seen.add(event.key);
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
60
|
+
const KeyedEventEnvelopes = Schema.Array(KeyedEventEnvelope).check(Schema.makeFilter(eventKeysAreUnique));
|
|
61
|
+
const mapOutputError = (triggerId, phase) => (error) => new InvalidTriggerOutputError({
|
|
62
|
+
description: error.message,
|
|
63
|
+
phase,
|
|
64
|
+
triggerId
|
|
65
|
+
});
|
|
66
|
+
const validateOutputs = (triggerId, phase, schema, events) => Schema.decodeUnknownEffect(KeyedEventEnvelopes)(events).pipe(Effect.flatMap((decodedEvents) => Effect.forEach(decodedEvents, (event) => Schema.encodeEffect(schema)(event.payload).pipe(Effect.flatMap((encoded) => Schema.decodeUnknownEffect(Schema.Json)(encoded)), Effect.map((payload) => ({
|
|
67
|
+
key: event.key,
|
|
68
|
+
payload
|
|
69
|
+
}))))), Effect.mapError(mapOutputError(triggerId, phase)));
|
|
70
|
+
const getTriggerHandler = (entry) => Effect.context().pipe(Effect.flatMap((context) => {
|
|
71
|
+
const handler = findHandler(context, entry.providerId, handlerKey(entry.triggerId));
|
|
72
|
+
return handler === void 0 ? Effect.fail(new UnsupportedTriggerRuntimeError({
|
|
73
|
+
kind: entry.trigger.kind,
|
|
74
|
+
phase: entry.trigger.kind === "polling" ? "poll" : "parse",
|
|
75
|
+
triggerId: entry.triggerId
|
|
76
|
+
})) : Effect.succeed(handler);
|
|
77
|
+
}));
|
|
78
|
+
const requireWebhookHook = (entry, phase) => {
|
|
79
|
+
if (entry.trigger.kind !== "webhook") return Effect.fail(new UnsupportedTriggerRuntimeError({
|
|
80
|
+
kind: entry.trigger.kind,
|
|
81
|
+
phase,
|
|
82
|
+
triggerId: entry.triggerId
|
|
83
|
+
}));
|
|
84
|
+
return getTriggerHandler(entry).pipe(Effect.flatMap((handler) => {
|
|
85
|
+
const hook = handler.runtime[phase];
|
|
86
|
+
if (hook === void 0) return Effect.fail(new UnsupportedTriggerRuntimeError({
|
|
87
|
+
kind: entry.trigger.kind,
|
|
88
|
+
phase,
|
|
89
|
+
triggerId: entry.triggerId
|
|
90
|
+
}));
|
|
91
|
+
return Effect.succeed({
|
|
92
|
+
context: handler.context,
|
|
93
|
+
hook
|
|
94
|
+
});
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
const requirePollingHook = (entry) => {
|
|
98
|
+
if (entry.trigger.kind !== "polling") return Effect.fail(new UnsupportedTriggerRuntimeError({
|
|
99
|
+
kind: entry.trigger.kind,
|
|
100
|
+
phase: "poll",
|
|
101
|
+
triggerId: entry.triggerId
|
|
102
|
+
}));
|
|
103
|
+
return getTriggerHandler(entry).pipe(Effect.flatMap((handler) => {
|
|
104
|
+
const hook = handler.runtime.poll;
|
|
105
|
+
if (hook === void 0) return Effect.fail(new UnsupportedTriggerRuntimeError({
|
|
106
|
+
kind: entry.trigger.kind,
|
|
107
|
+
phase: "poll",
|
|
108
|
+
triggerId: entry.triggerId
|
|
109
|
+
}));
|
|
110
|
+
return Effect.succeed({
|
|
111
|
+
context: handler.context,
|
|
112
|
+
hook
|
|
113
|
+
});
|
|
114
|
+
}));
|
|
115
|
+
};
|
|
116
|
+
const withRuntimeContext = (entry, phase, connectionId, context, run) => {
|
|
117
|
+
const requiredAuthMethods = toNonEmptyArray(entry.authMethods);
|
|
118
|
+
const runtimeContext = (authContext) => context === void 0 ? authContext : {
|
|
119
|
+
...context,
|
|
120
|
+
...authContext
|
|
121
|
+
};
|
|
122
|
+
if (requiredAuthMethods === void 0) {
|
|
123
|
+
if (connectionId !== void 0) return failConnectionIdNotAllowed("trigger", entry.triggerId, phase, entry.providerId, connectionId);
|
|
124
|
+
return run(runtimeContext(noAuthRuntimeContext()));
|
|
125
|
+
}
|
|
126
|
+
if (entry.trigger.requireAuth === false && connectionId === void 0) return run(runtimeContext(noAuthRuntimeContext()));
|
|
127
|
+
return resolveRuntimeConnection("trigger", entry.triggerId, phase, entry.providerId, requiredAuthMethods, connectionId, context).pipe(Effect.flatMap((binding) => run(runtimeContext(authRuntimeContext(binding)))));
|
|
128
|
+
};
|
|
129
|
+
//#endregion
|
|
130
|
+
export { decodeConfig, decodeState, requirePollingHook, requireWebhookHook, validateOutputs, validateStateResult, withRuntimeContext };
|
|
131
|
+
|
|
132
|
+
//# sourceMappingURL=trigger-runtime-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-runtime-shared.js","names":["Trigger.InvalidTriggerConfigError","Trigger.InvalidTriggerStateError","Trigger.InvalidTriggerOutputError","Trigger.handlerKey","Trigger.UnsupportedTriggerRuntimeError"],"sources":["../../src/internal/trigger-runtime-shared.ts"],"sourcesContent":["import type { Context } from \"effect\";\nimport { Effect, Schema } from \"effect\";\n\nimport type { ConnectionResolutionContext, Service } from \"../ConnectionResolver.ts\";\nimport * as Trigger from \"../Trigger.ts\";\n\nimport {\n authRuntimeContext,\n noAuthRuntimeContext,\n failConnectionIdNotAllowed,\n resolveRuntimeConnection,\n type AuthResolutionRequirements,\n type AuthSchemaRequirements,\n type RuntimeConnectionErrorsFor,\n toNonEmptyArray,\n} from \"./auth-execution.ts\";\nimport { findHandler } from \"./handler-context.ts\";\nimport { decodeJson, decodeJsonMapError } from \"./schema-runtime.ts\";\n\ntype ConfigRequirements<TriggerDef extends Trigger.Any> =\n Trigger.ConfigSchema<TriggerDef>[\"DecodingServices\"];\n\ntype StateDecodingRequirements<TriggerDef extends Trigger.Any> =\n Trigger.StateSchema<TriggerDef> extends Schema.Top\n ? Exclude<Trigger.StateSchema<TriggerDef>, undefined>[\"DecodingServices\"]\n : never;\n\ntype StateEncodingRequirements<TriggerDef extends Trigger.Any> =\n Trigger.StateSchema<TriggerDef> extends Schema.Top\n ? Exclude<Trigger.StateSchema<TriggerDef>, undefined>[\"EncodingServices\"]\n : never;\n\ntype OutputEncodingRequirements<TriggerDef extends Trigger.Any> =\n Trigger.OutputSchema<TriggerDef>[\"EncodingServices\"];\n\n/**\n * Trigger hooks may fail with arbitrary app-defined errors, so phase failures\n * deliberately widen to `unknown`. The alias keeps that decision visible in\n * the phase signatures.\n */\nexport type TriggerAppError<_TriggerDef extends Trigger.Any> = unknown;\n\nexport type TriggerEncodedState<TriggerDef extends Trigger.Any> =\n Trigger.StateSchema<TriggerDef> extends Schema.Top\n ? Exclude<Trigger.StateSchema<TriggerDef>, undefined>[\"Encoded\"] | undefined\n : undefined;\n\nexport type TriggerEncodedOutput<TriggerDef extends Trigger.Any> =\n Trigger.OutputSchema<TriggerDef>[\"Encoded\"];\n\nexport type TriggerIdOf<Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>> =\n Entry[\"triggerId\"];\nexport type EntryTrigger<Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>> =\n Entry[\"trigger\"];\nexport type EntryAuthMethods<Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>> =\n Entry[\"authMethods\"];\ntype EntryHandler<Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>> = Trigger.Handler<\n TriggerIdOf<Entry>\n>;\n\nexport type TriggerRuntimeRequirements<\n Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>,\n Phase extends Trigger.RuntimePhase,\n> =\n | EntryHandler<Entry>\n | ConfigRequirements<EntryTrigger<Entry>>\n | StateDecodingRequirements<EntryTrigger<Entry>>\n | (Phase extends \"activate\" | \"verify\" | \"parse\" | \"poll\"\n ? StateEncodingRequirements<EntryTrigger<Entry>>\n : never)\n | (Phase extends \"parse\" | \"poll\" ? OutputEncodingRequirements<EntryTrigger<Entry>> : never)\n | ([EntryAuthMethods<Entry>[number]] extends [never]\n ? never\n :\n | Service\n | AuthSchemaRequirements<EntryAuthMethods<Entry>>\n | AuthResolutionRequirements<EntryAuthMethods<Entry>>);\n\nexport const decodeConfig = <Config extends Schema.Top>(\n triggerId: string,\n schema: Config,\n value: unknown,\n): Effect.Effect<Config[\"Type\"], Trigger.InvalidTriggerConfigError, Config[\"DecodingServices\"]> =>\n decodeJsonMapError(\n schema,\n value,\n error => new Trigger.InvalidTriggerConfigError({ description: error.message, triggerId }),\n );\n\nconst decodeStateValue = (): Effect.Effect<undefined> => Effect.as(Effect.void, undefined);\n\nfunction decodeStateSchema<State extends Schema.Top>(\n schema: State,\n value: undefined,\n): Effect.Effect<State[\"Type\"] | undefined>;\nfunction decodeStateSchema<State extends Schema.Top>(\n schema: State,\n value: unknown,\n): Effect.Effect<State[\"Type\"] | undefined, Schema.SchemaError, State[\"DecodingServices\"]>;\nfunction decodeStateSchema<State extends Schema.Top>(\n schema: State,\n value: unknown,\n): Effect.Effect<State[\"Type\"] | undefined, Schema.SchemaError, State[\"DecodingServices\"]> {\n if (value === undefined) {\n return decodeStateValue();\n }\n\n return decodeJson(schema, value);\n}\n\nexport function decodeState(\n triggerId: string,\n phase: Trigger.RuntimePhase,\n schema: undefined,\n value: unknown,\n): Effect.Effect<undefined, Trigger.InvalidTriggerStateError>;\nexport function decodeState<State extends Schema.Top>(\n triggerId: string,\n phase: Trigger.RuntimePhase,\n schema: State,\n value: unknown,\n): Effect.Effect<\n State[\"Type\"] | undefined,\n Trigger.InvalidTriggerStateError,\n State[\"DecodingServices\"]\n>;\nexport function decodeState<State extends Schema.Top | undefined>(\n triggerId: string,\n phase: Trigger.RuntimePhase,\n schema: State,\n value: unknown,\n): Effect.Effect<unknown, Trigger.InvalidTriggerStateError, unknown> {\n if (schema === undefined) {\n return value === undefined\n ? decodeStateValue()\n : Effect.fail(\n new Trigger.InvalidTriggerStateError({\n description: \"state is not supported for this trigger\",\n location: \"input\",\n phase,\n triggerId,\n }),\n );\n }\n\n return decodeStateSchema(schema, value).pipe(\n Effect.mapError(\n error =>\n new Trigger.InvalidTriggerStateError({\n description: error.message,\n location: \"input\",\n phase,\n triggerId,\n }),\n ),\n );\n}\n\nconst encodeStateSchema = <State extends Schema.Top>(\n triggerId: string,\n phase: Trigger.RuntimePhase,\n schema: State,\n value: State[\"Type\"] | undefined,\n): Effect.Effect<\n State[\"Encoded\"] | undefined,\n Trigger.InvalidTriggerStateError,\n State[\"EncodingServices\"]\n> => {\n if (value === undefined) {\n return Effect.void;\n }\n\n return Schema.encodeEffect(schema)(value).pipe(\n Effect.mapError(\n error =>\n new Trigger.InvalidTriggerStateError({\n description: error.message,\n location: \"result\",\n phase,\n triggerId,\n }),\n ),\n );\n};\n\nexport function validateStateResult(\n triggerId: string,\n phase: Trigger.RuntimePhase,\n schema: undefined,\n value: undefined,\n): Effect.Effect<undefined, Trigger.InvalidTriggerStateError>;\nexport function validateStateResult<State extends Schema.Top>(\n triggerId: string,\n phase: Trigger.RuntimePhase,\n schema: State,\n value: State[\"Type\"] | undefined,\n): Effect.Effect<\n State[\"Encoded\"] | undefined,\n Trigger.InvalidTriggerStateError,\n State[\"EncodingServices\"]\n>;\nexport function validateStateResult<State extends Schema.Top | undefined>(\n triggerId: string,\n phase: Trigger.RuntimePhase,\n schema: State,\n value: Trigger.StateValue<State>,\n): Effect.Effect<unknown, Trigger.InvalidTriggerStateError, unknown> {\n if (schema === undefined) {\n return value === undefined\n ? decodeStateValue()\n : Effect.fail(\n new Trigger.InvalidTriggerStateError({\n description: \"state is not supported for this trigger\",\n location: \"result\",\n phase,\n triggerId,\n }),\n );\n }\n\n return encodeStateSchema(triggerId, phase, schema, value);\n}\n\nconst KeyedEventEnvelope = Schema.Struct({ key: Schema.NonEmptyString, payload: Schema.Unknown });\n\ntype KeyedEventEnvelope = typeof KeyedEventEnvelope.Type;\n\nconst eventKeysAreUnique = (events: readonly KeyedEventEnvelope[]) => {\n const seen = new Set<string>();\n for (const event of events) {\n if (seen.has(event.key)) {\n return `duplicate event key \"${event.key}\"`;\n }\n seen.add(event.key);\n }\n\n return true;\n};\n\nconst KeyedEventEnvelopes = Schema.Array(KeyedEventEnvelope).check(\n Schema.makeFilter(eventKeysAreUnique),\n);\n\nconst mapOutputError =\n (triggerId: string, phase: \"parse\" | \"poll\") => (error: Schema.SchemaError) =>\n new Trigger.InvalidTriggerOutputError({ description: error.message, phase, triggerId });\n\nexport const validateOutputs = <Output extends Schema.Top>(\n triggerId: string,\n phase: \"parse\" | \"poll\",\n schema: Output,\n events: unknown,\n): Effect.Effect<\n readonly Trigger.KeyedEvent<Output[\"Encoded\"]>[],\n Trigger.InvalidTriggerOutputError,\n Output[\"EncodingServices\"]\n> =>\n Schema.decodeUnknownEffect(KeyedEventEnvelopes)(events).pipe(\n Effect.flatMap(decodedEvents =>\n Effect.forEach(decodedEvents, event =>\n Schema.encodeEffect(schema)(event.payload).pipe(\n Effect.flatMap(encoded => Schema.decodeUnknownEffect(Schema.Json)(encoded)),\n Effect.map(payload => ({ key: event.key, payload: payload as Output[\"Encoded\"] })),\n ),\n ),\n ),\n Effect.mapError(mapOutputError(triggerId, phase)),\n );\n\ninterface RuntimeHook<Hook> {\n readonly hook: Hook;\n readonly context: Context.Context<never>;\n}\n\ntype WebhookPhase = \"activate\" | \"deactivate\" | \"verify\" | \"parse\";\n\ntype WebhookHook<Phase extends WebhookPhase> = NonNullable<\n Trigger.WebhookRuntime<Schema.Top, Schema.Top, Schema.Top | undefined, any, any, any>[Phase]\n>;\n\ntype PollHook = NonNullable<\n Trigger.PollingRuntime<Schema.Top, Schema.Top, Schema.Top | undefined, any, any, any>[\"poll\"]\n>;\n\nconst getTriggerHandler = <Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>>(\n entry: Entry,\n): Effect.Effect<\n EntryHandler<Entry>,\n Trigger.UnsupportedTriggerRuntimeError,\n EntryHandler<Entry>\n> =>\n Effect.context<EntryHandler<Entry>>().pipe(\n Effect.flatMap(context => {\n const handler = findHandler(\n context,\n entry.providerId,\n Trigger.handlerKey(entry.triggerId),\n ) as EntryHandler<Entry> | undefined;\n\n return handler === undefined\n ? Effect.fail(\n new Trigger.UnsupportedTriggerRuntimeError({\n kind: entry.trigger.kind,\n phase: entry.trigger.kind === \"polling\" ? \"poll\" : \"parse\",\n triggerId: entry.triggerId,\n }),\n )\n : Effect.succeed(handler);\n }),\n );\n\nexport const requireWebhookHook = <\n Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>,\n Phase extends WebhookPhase,\n>(\n entry: Entry,\n phase: Phase,\n): Effect.Effect<\n RuntimeHook<WebhookHook<Phase>>,\n Trigger.UnsupportedTriggerRuntimeError,\n EntryHandler<Entry>\n> => {\n if (entry.trigger.kind !== \"webhook\") {\n return Effect.fail(\n new Trigger.UnsupportedTriggerRuntimeError({\n kind: entry.trigger.kind,\n phase,\n triggerId: entry.triggerId,\n }),\n );\n }\n\n return getTriggerHandler(entry).pipe(\n Effect.flatMap(handler => {\n const hook = (handler.runtime as Trigger.WebhookRuntime<any, any, any, any, any, any>)[phase];\n\n if (hook === undefined) {\n return Effect.fail(\n new Trigger.UnsupportedTriggerRuntimeError({\n kind: entry.trigger.kind,\n phase,\n triggerId: entry.triggerId,\n }),\n );\n }\n\n return Effect.succeed({ context: handler.context, hook } as RuntimeHook<WebhookHook<Phase>>);\n }),\n );\n};\n\nexport const requirePollingHook = <Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>>(\n entry: Entry,\n): Effect.Effect<\n RuntimeHook<PollHook>,\n Trigger.UnsupportedTriggerRuntimeError,\n EntryHandler<Entry>\n> => {\n if (entry.trigger.kind !== \"polling\") {\n return Effect.fail(\n new Trigger.UnsupportedTriggerRuntimeError({\n kind: entry.trigger.kind,\n phase: \"poll\",\n triggerId: entry.triggerId,\n }),\n );\n }\n\n return getTriggerHandler(entry).pipe(\n Effect.flatMap(handler => {\n const hook = (handler.runtime as Trigger.PollingRuntime<any, any, any, any, any, any>).poll;\n\n if (hook === undefined) {\n return Effect.fail(\n new Trigger.UnsupportedTriggerRuntimeError({\n kind: entry.trigger.kind,\n phase: \"poll\",\n triggerId: entry.triggerId,\n }),\n );\n }\n\n return Effect.succeed({ context: handler.context, hook } as RuntimeHook<PollHook>);\n }),\n );\n};\n\nexport const withRuntimeContext: <\n Entry extends Trigger.RuntimeTriggerEntry<any, any, any, any>,\n Phase extends Trigger.RuntimePhase,\n Result,\n>(\n entry: Entry,\n phase: Phase,\n connectionId: string | undefined,\n context: ConnectionResolutionContext | undefined,\n run: (\n context: Trigger.RuntimeContext<EntryAuthMethods<Entry>>,\n ) => Effect.Effect<\n Result,\n TriggerAppError<EntryTrigger<Entry>> | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>>,\n TriggerRuntimeRequirements<Entry, Phase>\n >,\n) => Effect.Effect<\n Result,\n TriggerAppError<EntryTrigger<Entry>> | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>>,\n TriggerRuntimeRequirements<Entry, Phase>\n> = (\n entry: Trigger.RuntimeTriggerEntry,\n phase: Trigger.RuntimePhase,\n connectionId: string | undefined,\n context: ConnectionResolutionContext | undefined,\n run: (context: never) => Effect.Effect<unknown, unknown, unknown>,\n) => {\n const requiredAuthMethods = toNonEmptyArray(entry.authMethods);\n const runtimeContext = <AuthContext extends object>(authContext: AuthContext) =>\n context === undefined ? authContext : ({ ...context, ...authContext } as const);\n\n if (requiredAuthMethods === undefined) {\n if (connectionId !== undefined) {\n return failConnectionIdNotAllowed(\n \"trigger\",\n entry.triggerId,\n phase,\n entry.providerId,\n connectionId,\n );\n }\n\n return run(runtimeContext(noAuthRuntimeContext()) as never) as never;\n }\n\n // Only an explicit false skips auth for definitions built outside the SDK.\n if (entry.trigger.requireAuth === false && connectionId === undefined) {\n return run(runtimeContext(noAuthRuntimeContext()) as never) as never;\n }\n\n return resolveRuntimeConnection(\n \"trigger\",\n entry.triggerId,\n phase,\n entry.providerId,\n requiredAuthMethods,\n connectionId,\n context,\n ).pipe(\n Effect.flatMap(binding => run(runtimeContext(authRuntimeContext(binding)) as never)),\n ) as never;\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RuntimeConnectionErrorsFor } from "./auth-execution.js";
|
|
2
|
+
import { EntryAuthMethods, EntryTrigger, TriggerAppError, TriggerEncodedOutput, TriggerEncodedState, TriggerIdOf, TriggerRuntimeRequirements } from "./trigger-runtime-shared.js";
|
|
3
|
+
import { ActivateSuccess, DeactivateSuccess, EmittedEventsSuccess, InvalidTriggerConfigError, InvalidTriggerOutputError, InvalidTriggerStateError, PollExecutionRequest, RuntimeTriggerEntry, UnsupportedTriggerRuntimeError, VerifySuccess, WebhookActivationRequest, WebhookExecutionRequest } from "../Trigger.js";
|
|
4
|
+
import { Effect } from "effect";
|
|
5
|
+
//#region src/internal/trigger-runtime.d.ts
|
|
6
|
+
export declare const activate: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry, request: WebhookActivationRequest) => Effect.Effect<ActivateSuccess<TriggerIdOf<Entry>, TriggerEncodedState<EntryTrigger<Entry>>>, InvalidTriggerConfigError | InvalidTriggerStateError | UnsupportedTriggerRuntimeError | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>> | TriggerAppError<EntryTrigger<Entry>>, TriggerRuntimeRequirements<Entry, "activate">>;
|
|
7
|
+
export declare const deactivate: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry, request: WebhookActivationRequest) => Effect.Effect<DeactivateSuccess<TriggerIdOf<Entry>>, InvalidTriggerConfigError | InvalidTriggerStateError | UnsupportedTriggerRuntimeError | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>> | TriggerAppError<EntryTrigger<Entry>>, TriggerRuntimeRequirements<Entry, "deactivate">>;
|
|
8
|
+
export declare const verify: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry, request: WebhookExecutionRequest) => Effect.Effect<VerifySuccess<TriggerIdOf<Entry>, TriggerEncodedState<EntryTrigger<Entry>>>, InvalidTriggerConfigError | InvalidTriggerStateError | UnsupportedTriggerRuntimeError | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>> | TriggerAppError<EntryTrigger<Entry>>, TriggerRuntimeRequirements<Entry, "verify">>;
|
|
9
|
+
export declare const parse: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry, request: WebhookExecutionRequest) => Effect.Effect<EmittedEventsSuccess<TriggerIdOf<Entry>, "parse", TriggerEncodedOutput<EntryTrigger<Entry>>, TriggerEncodedState<EntryTrigger<Entry>>>, InvalidTriggerConfigError | InvalidTriggerStateError | InvalidTriggerOutputError | UnsupportedTriggerRuntimeError | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>> | TriggerAppError<EntryTrigger<Entry>>, TriggerRuntimeRequirements<Entry, "parse">>;
|
|
10
|
+
export declare const poll: <Entry extends RuntimeTriggerEntry<any, any, any, any>>(entry: Entry, request: PollExecutionRequest) => Effect.Effect<EmittedEventsSuccess<TriggerIdOf<Entry>, "poll", TriggerEncodedOutput<EntryTrigger<Entry>>, TriggerEncodedState<EntryTrigger<Entry>>>, InvalidTriggerConfigError | InvalidTriggerStateError | InvalidTriggerOutputError | UnsupportedTriggerRuntimeError | RuntimeConnectionErrorsFor<EntryAuthMethods<Entry>> | TriggerAppError<EntryTrigger<Entry>>, TriggerRuntimeRequirements<Entry, "poll">>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=trigger-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-runtime.d.ts","names":["Trigger.RuntimeTriggerEntry","Trigger.WebhookActivationRequest","Trigger.ActivateSuccess","Trigger.InvalidTriggerConfigError","Trigger.InvalidTriggerStateError","Trigger.UnsupportedTriggerRuntimeError","Trigger.DeactivateSuccess","Trigger.WebhookExecutionRequest","Trigger.VerifySuccess","Trigger.EmittedEventsSuccess","Trigger.InvalidTriggerOutputError","Trigger.PollExecutionRequest"],"sources":["../../src/internal/trigger-runtime.ts"],"mappings":";;;;;qBAoFa,WAAW,cAAcA,yCACpC,OAAO,OACP,SAASC,6BACN,OAAO,OACVC,gBAAwB,YAAY,QAAQ,oBAAoB,aAAa,UAC3EC,4BACAC,2BACAC,iCACA,2BAA2B,iBAAiB,UAC5C,gBAAgB,aAAa,SAC/B,2BAA2B;qBAchB,aAAa,cAAcL,yCACtC,OAAO,OACP,SAASC,6BACN,OAAO,OACVK,kBAA0B,YAAY,SACpCH,4BACAC,2BACAC,iCACA,2BAA2B,iBAAiB,UAC5C,gBAAgB,aAAa,SAC/B,2BAA2B;qBAgBhB,SAAS,cAAcL,yCAClC,OAAO,OACP,SAASO,4BACN,OAAO,OACVC,cAAsB,YAAY,QAAQ,oBAAoB,aAAa,UACzEL,4BACAC,2BACAC,iCACA,2BAA2B,iBAAiB,UAC5C,gBAAgB,aAAa,SAC/B,2BAA2B;qBAwBhB,QAAQ,cAAcL,yCACjC,OAAO,OACP,SAASO,4BACN,OAAO,OACVE,qBACE,YAAY,iBAEZ,qBAAqB,aAAa,SAClC,oBAAoB,aAAa,UAEjCN,4BACAC,2BACAM,4BACAL,iCACA,2BAA2B,iBAAiB,UAC5C,gBAAgB,aAAa,SAC/B,2BAA2B;qBAWhB,OAAO,cAAcL,yCAChC,OAAO,OACP,SAASW,yBACN,OAAO,OACVF,qBACE,YAAY,gBAEZ,qBAAqB,aAAa,SAClC,oBAAoB,aAAa,UAEjCN,4BACAC,2BACAM,4BACAL,iCACA,2BAA2B,iBAAiB,UAC5C,gBAAgB,aAAa,SAC/B,2BAA2B"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { mergeUnder } from "./handler-context.js";
|
|
2
|
+
import { decodeConfig, decodeState, requirePollingHook, requireWebhookHook, validateOutputs, validateStateResult, withRuntimeContext } from "./trigger-runtime-shared.js";
|
|
3
|
+
import { Effect, Record, String } from "effect";
|
|
4
|
+
//#region src/internal/trigger-runtime.ts
|
|
5
|
+
/**
|
|
6
|
+
* Shared execution skeleton for all trigger runtime phases: decode config and
|
|
7
|
+
* state, resolve the runtime connection, run the hook inside the registered
|
|
8
|
+
* handler context, then hand the raw hook result to the phase finisher.
|
|
9
|
+
*/
|
|
10
|
+
const runPhase = (options) => Effect.gen(function* () {
|
|
11
|
+
const { entry, phase, request } = options;
|
|
12
|
+
const runtime = yield* options.hook;
|
|
13
|
+
const config = yield* decodeConfig(entry.triggerId, entry.trigger.config, request.config);
|
|
14
|
+
const state = yield* decodeState(entry.triggerId, phase, entry.trigger.state, request.state);
|
|
15
|
+
const input = {
|
|
16
|
+
...options.input,
|
|
17
|
+
config,
|
|
18
|
+
state
|
|
19
|
+
};
|
|
20
|
+
const result = yield* withRuntimeContext(entry, phase, request.connectionId, request.context, (context) => Effect.suspend(() => runtime.hook(input, context))).pipe(Effect.updateContext((current) => mergeUnder(runtime.context, current)));
|
|
21
|
+
return yield* options.finish(result);
|
|
22
|
+
});
|
|
23
|
+
const meta = (entry, phase) => ({
|
|
24
|
+
phase,
|
|
25
|
+
triggerId: entry.triggerId
|
|
26
|
+
});
|
|
27
|
+
const finishEmit = (entry, phase) => (emitted) => validateOutputs(entry.triggerId, phase, entry.trigger.output, emitted.events).pipe(Effect.zip(validateStateResult(entry.triggerId, phase, entry.trigger.state, emitted.state)), Effect.map(([events, state]) => ({
|
|
28
|
+
events,
|
|
29
|
+
meta: meta(entry, phase),
|
|
30
|
+
state
|
|
31
|
+
})));
|
|
32
|
+
const activate = (entry, request) => runPhase({
|
|
33
|
+
entry,
|
|
34
|
+
finish: (result) => validateStateResult(entry.triggerId, "activate", entry.trigger.state, result.state).pipe(Effect.map((state) => ({
|
|
35
|
+
meta: meta(entry, "activate"),
|
|
36
|
+
state
|
|
37
|
+
}))),
|
|
38
|
+
hook: requireWebhookHook(entry, "activate"),
|
|
39
|
+
input: { webhookUrl: request.webhookUrl },
|
|
40
|
+
phase: "activate",
|
|
41
|
+
request
|
|
42
|
+
});
|
|
43
|
+
const deactivate = (entry, request) => runPhase({
|
|
44
|
+
entry,
|
|
45
|
+
finish: () => Effect.succeed({ meta: meta(entry, "deactivate") }),
|
|
46
|
+
hook: requireWebhookHook(entry, "deactivate"),
|
|
47
|
+
input: { webhookUrl: request.webhookUrl },
|
|
48
|
+
phase: "deactivate",
|
|
49
|
+
request
|
|
50
|
+
});
|
|
51
|
+
const lowercaseHeaders = (request) => request.headers === void 0 ? request : {
|
|
52
|
+
...request,
|
|
53
|
+
headers: Record.mapKeys(request.headers, String.toLowerCase)
|
|
54
|
+
};
|
|
55
|
+
const verify = (entry, request) => runPhase({
|
|
56
|
+
entry,
|
|
57
|
+
finish: Effect.fnUntraced(function* (result) {
|
|
58
|
+
const state = yield* validateStateResult(entry.triggerId, "verify", entry.trigger.state, result?.state);
|
|
59
|
+
return {
|
|
60
|
+
verified: true,
|
|
61
|
+
...result?.response === void 0 ? {} : { response: result.response },
|
|
62
|
+
...state === void 0 ? {} : { state },
|
|
63
|
+
meta: meta(entry, "verify")
|
|
64
|
+
};
|
|
65
|
+
}),
|
|
66
|
+
hook: requireWebhookHook(entry, "verify"),
|
|
67
|
+
input: {
|
|
68
|
+
request: lowercaseHeaders(request.request),
|
|
69
|
+
webhookUrl: request.webhookUrl
|
|
70
|
+
},
|
|
71
|
+
phase: "verify",
|
|
72
|
+
request
|
|
73
|
+
});
|
|
74
|
+
const parse = (entry, request) => runPhase({
|
|
75
|
+
entry,
|
|
76
|
+
finish: finishEmit(entry, "parse"),
|
|
77
|
+
hook: requireWebhookHook(entry, "parse"),
|
|
78
|
+
input: {
|
|
79
|
+
request: lowercaseHeaders(request.request),
|
|
80
|
+
webhookUrl: request.webhookUrl
|
|
81
|
+
},
|
|
82
|
+
phase: "parse",
|
|
83
|
+
request
|
|
84
|
+
});
|
|
85
|
+
const poll = (entry, request) => runPhase({
|
|
86
|
+
entry,
|
|
87
|
+
finish: finishEmit(entry, "poll"),
|
|
88
|
+
hook: requirePollingHook(entry),
|
|
89
|
+
phase: "poll",
|
|
90
|
+
request
|
|
91
|
+
});
|
|
92
|
+
//#endregion
|
|
93
|
+
export { activate, deactivate, parse, poll, verify };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=trigger-runtime.js.map
|