@sdlcworks/components 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -19,24 +19,57 @@ export declare enum CloudProvider {
19
19
  cloudflare = "cloudflare"
20
20
  }
21
21
  export declare enum DeploymentArtifactType {
22
- container_image = "container_image",
23
- local_file = "local_file"
22
+ container_image = "container_image"
24
23
  }
25
- export type CommonPulumiFnInputs = {
26
- componentName: string;
27
- $: {
28
- (name: string, ...values: any[]): string;
29
- (strings: TemplateStringsArray, ...values: any[]): string;
24
+ /**
25
+ * Abstract base class for defining connection interfaces.
26
+ * Users extend this class to define the schema for data that
27
+ * connecting components must provide.
28
+ */
29
+ export declare abstract class ConnectionInterface<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> {
30
+ abstract readonly schema: TSchema;
31
+ }
32
+ /**
33
+ * Factory function to create a ConnectionInterface class from a schema.
34
+ * Avoids boilerplate of defining a class manually.
35
+ *
36
+ * @example
37
+ * const TriggerConnection = createConnectionInterface(
38
+ * z.object({ eventSource: z.string() })
39
+ * );
40
+ */
41
+ export declare function createConnectionInterface<TSchema extends z.ZodObject<z.ZodRawShape>>(schema: TSchema): {
42
+ new (): {
43
+ readonly schema: TSchema;
30
44
  };
31
45
  };
32
- export type CommonDeployFnInputs<T = undefined> = Record<string, {
33
- provisionOutput: InfraComponentOutput;
34
- deploymentConfig: T;
35
- deploymentArtifact: {
36
- uri: string;
37
- type: DeploymentArtifactType;
38
- };
39
- }>;
46
+ /**
47
+ * Type alias for ConnectionInterface class constructors.
48
+ */
49
+ export type ConnectionInterfaceClass<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> = new () => ConnectionInterface<TSchema>;
50
+ /**
51
+ * Extract the inferred data type from a ConnectionInterface class.
52
+ */
53
+ export type InferConnectionData<C extends ConnectionInterfaceClass> = z.infer<InstanceType<C>["schema"]>;
54
+ /**
55
+ * Wrap connection data with PulumiInput to support Pulumi Output types.
56
+ */
57
+ export type InferConnectionDataWithInputs<C extends ConnectionInterfaceClass> = {
58
+ [K in keyof InferConnectionData<C>]: PulumiInput<InferConnectionData<C>[K]>;
59
+ };
60
+ /**
61
+ * Entry type for allowConnectionInterfaces parameter.
62
+ * Declares an interface that this component exposes with typed data.
63
+ */
64
+ export type AllowedConnectionInterfaceEntry<C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
65
+ interface: C;
66
+ data: InferConnectionDataWithInputs<C>;
67
+ };
68
+ /**
69
+ * Function type for allowConnectionInterfaces.
70
+ * Called within pulumi function to declare exposed connection interfaces.
71
+ */
72
+ export type AllowConnectionInterfacesFn = <C extends ConnectionInterfaceClass>(entries: AllowedConnectionInterfaceEntry<C>[]) => void;
40
73
  export type InferZodType<S extends z.ZodRawShape> = {
41
74
  [K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
42
75
  };
@@ -70,57 +103,105 @@ declare const InfraComponentOptsSchema: z.ZodObject<{
70
103
  }>, z.core.$strip>>;
71
104
  }, z.core.$strip>;
72
105
  export type InfraComponentOptsBase = z.infer<typeof InfraComponentOptsSchema>;
73
- export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape> = Omit<InfraComponentOptsBase, "configSchema" | "deploymentInputSchema" | "outputSchema"> & {
106
+ export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape, ConnTypes extends Record<string, {
107
+ description: string;
108
+ }> = Record<string, {
109
+ description: string;
110
+ }>> = Omit<InfraComponentOptsBase, "configSchema" | "deploymentInputSchema" | "outputSchema" | "connectionTypes"> & {
74
111
  configSchema: z.ZodObject<CShape>;
75
112
  deploymentInputSchema: z.ZodObject<DShape>;
76
113
  outputSchema: z.ZodObject<OShape>;
114
+ connectionTypes: ConnTypes;
77
115
  };
78
116
  export type InfraComponentInputs<C, D> = {
79
117
  config: C;
80
118
  deploymentInput: D;
81
119
  };
82
- export type ProviderPulumiCtx<I, S> = CommonPulumiFnInputs & {
120
+ export type ProviderPulumiCtx<I, S> = {
121
+ componentName: string;
122
+ $: {
123
+ (name: string, ...values: any[]): string;
124
+ (strings: TemplateStringsArray, ...values: any[]): string;
125
+ };
83
126
  inputs: I;
84
127
  state: S;
128
+ allowConnectionInterfaces: AllowConnectionInterfacesFn;
85
129
  };
86
- export type ProviderConnectCtx<S> = {
130
+ /**
131
+ * Context passed to connection handlers.
132
+ * Contains the provider state, typed data from the connecting component,
133
+ * and the connection type chosen by the orchestrator.
134
+ */
135
+ export type ConnectionHandlerCtx<S, Data, ConnectionType extends string = string> = {
87
136
  state: S;
137
+ data: Data;
138
+ connectionType: ConnectionType;
88
139
  };
89
- export type ProviderDeployCtx<S> = CommonDeployFnInputs & {
90
- state: S;
140
+ /**
141
+ * A connection handler entry mapping a ConnectionInterface to its handler function.
142
+ */
143
+ export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
144
+ interface: C;
145
+ handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<void>;
91
146
  };
147
+ export type ProviderDeployCtx<D, S> = {
148
+ state: S;
149
+ } & Record<string, {
150
+ provisionOutput: InfraComponentOutput;
151
+ deploymentConfig: D;
152
+ deploymentArtifact: {
153
+ uri: string;
154
+ type: DeploymentArtifactType;
155
+ };
156
+ }>;
92
157
  export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
93
- export type ProviderConnectFn<S> = (ctx: ProviderConnectCtx<S>) => Promise<void>;
94
- export type ProviderDeployFn<S> = (ctx: ProviderDeployCtx<S>) => Promise<void>;
158
+ export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
95
159
  declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
96
160
  export type EmptyStateShape = typeof emptyStateSchema.shape;
97
- export type ProviderFnsDefStateless<I, O> = {
98
- stateSchema?: never;
99
- pulumi: ProviderPulumiFn<I, Record<string, never>, O>;
100
- onConnect?: ProviderConnectFn<Record<string, never>>;
101
- onDeploy?: ProviderDeployFn<Record<string, never>>;
102
- };
103
- export type ProviderFnsDefStateful<I, O, SShape extends z.ZodRawShape> = {
104
- stateSchema: z.ZodObject<SShape>;
161
+ export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
162
+ stateSchema?: z.ZodObject<SShape>;
105
163
  pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
106
- onConnect?: ProviderConnectFn<z.infer<z.ZodObject<SShape>>>;
107
- onDeploy?: ProviderDeployFn<z.infer<z.ZodObject<SShape>>>;
164
+ connect?: ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType>[];
165
+ deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
108
166
  };
109
- export type ProviderFnsDef<I, O, SShape extends z.ZodRawShape = EmptyStateShape> = ProviderFnsDefStateless<I, O> | ProviderFnsDefStateful<I, O, SShape>;
110
167
  export type StoredProviderFns = {
111
168
  stateSchema: z.ZodObject<any>;
112
169
  pulumi: ProviderPulumiFn<any, any, any>;
113
- onConnect?: ProviderConnectFn<any>;
114
- onDeploy?: ProviderDeployFn<any>;
170
+ connect?: ConnectionHandlerEntry<any, any>[];
171
+ deploy?: ProviderDeployFn<any, any>;
115
172
  };
116
173
  export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
117
- export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape = EmptyOutputShape> {
118
- opts: InfraComponentOpts<CShape, DShape, OShape>;
174
+ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape = EmptyOutputShape, ConnTypes extends Record<string, {
175
+ description: string;
176
+ }> = Record<string, {
177
+ description: string;
178
+ }>> {
179
+ opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>;
119
180
  providers: ProviderRegistry;
120
181
  validationSchema: z.ZodTypeAny;
121
182
  validationDeploymentInputSchema: z.ZodTypeAny;
122
- constructor(opts: InfraComponentOpts<CShape, DShape, OShape>);
123
- implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, InferOutputType<OShape>, SShape>): this;
183
+ private allowedInterfaces;
184
+ constructor(opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>);
185
+ implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, InferZodType<DShape>, InferOutputType<OShape>, SShape, keyof ConnTypes & string>): this;
186
+ /**
187
+ * Get the schema for a specific connection interface.
188
+ * Used by the orchestrator at runtime.
189
+ */
190
+ getConnectionSchema(interfaceClass: ConnectionInterfaceClass): z.ZodObject<z.ZodRawShape> | undefined;
191
+ /**
192
+ * Create the allowConnectionInterfaces function for use in pulumi context.
193
+ * The orchestrator calls this before invoking the pulumi function.
194
+ *
195
+ * @returns Function that validates and stores allowed connection interfaces
196
+ */
197
+ createAllowConnectionInterfacesFn(): AllowConnectionInterfacesFn;
198
+ /**
199
+ * Get the allowed connection interfaces that were declared via allowConnectionInterfaces.
200
+ * The orchestrator calls this after the pulumi function completes.
201
+ *
202
+ * @returns Map of interface classes to their data, or null if not set
203
+ */
204
+ getAllowedInterfaces(): Map<ConnectionInterfaceClass, any> | null;
124
205
  }
125
206
 
126
207
  export {};
package/dist/index.js CHANGED
@@ -1,80 +1 @@
1
- // src/infra.ts
2
- import { z } from "zod";
3
- import * as pulumi from "@pulumi/pulumi";
4
- var CloudProvider;
5
- ((CloudProvider2) => {
6
- CloudProvider2["aws"] = "aws";
7
- CloudProvider2["gcloud"] = "gcloud";
8
- CloudProvider2["azure"] = "azure";
9
- CloudProvider2["linode"] = "linode";
10
- CloudProvider2["hetzner"] = "hetzner";
11
- CloudProvider2["cloudflare"] = "cloudflare";
12
- })(CloudProvider ||= {});
13
- var CloudProviderSchema = z.enum(CloudProvider);
14
- var DeploymentArtifactType;
15
- ((DeploymentArtifactType2) => {
16
- DeploymentArtifactType2["container_image"] = "container_image";
17
- DeploymentArtifactType2["local_file"] = "local_file";
18
- })(DeploymentArtifactType ||= {});
19
- var emptyOutputSchema = z.object({});
20
- function transformSchemaToAcceptOutputs(schema) {
21
- if (schema instanceof z.ZodObject) {
22
- const shape = schema.shape;
23
- const newShape = {};
24
- for (const key in shape) {
25
- newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
26
- }
27
- return z.object(newShape);
28
- }
29
- if (schema instanceof z.ZodOptional) {
30
- return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
31
- }
32
- if (schema instanceof z.ZodNullable) {
33
- return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
34
- }
35
- if (schema instanceof z.ZodArray) {
36
- return z.array(transformSchemaToAcceptOutputs(schema.element));
37
- }
38
- return z.union([
39
- schema,
40
- z.custom((val) => pulumi.Output.isInstance(val))
41
- ]);
42
- }
43
- var InfraComponentOptsSchema = z.object({
44
- metadata: z.object({
45
- stateful: z.boolean(),
46
- proxiable: z.boolean()
47
- }),
48
- connectionTypes: z.record(z.string(), z.object({
49
- description: z.string().min(5)
50
- })),
51
- configSchema: z.custom(),
52
- deploymentInputSchema: z.custom(),
53
- outputSchema: z.custom()
54
- });
55
- var emptyStateSchema = z.object({});
56
-
57
- class InfraComponent {
58
- opts;
59
- providers;
60
- validationSchema;
61
- validationDeploymentInputSchema;
62
- constructor(opts) {
63
- this.opts = InfraComponentOptsSchema.parse(opts);
64
- this.providers = {};
65
- this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
66
- this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
67
- }
68
- implement(provider, fns) {
69
- this.providers[provider] = {
70
- ...fns,
71
- stateSchema: fns.stateSchema ?? emptyStateSchema
72
- };
73
- return this;
74
- }
75
- }
76
- export {
77
- InfraComponent,
78
- DeploymentArtifactType,
79
- CloudProvider
80
- };
1
+ import{z as x}from"zod";import*as H from"@pulumi/pulumi";var J;((j)=>{j.aws="aws";j.gcloud="gcloud";j.azure="azure";j.linode="linode";j.hetzner="hetzner";j.cloudflare="cloudflare"})(J||={});var W=x.enum(J),L;((g)=>g.container_image="container_image")(L||={});class K{}function X(b){return class extends K{schema=b}}var Y=x.object({});function q(b){if(b instanceof x.ZodObject){let g=b.shape,B={};for(let E in g)B[E]=q(g[E]);return x.object(B)}if(b instanceof x.ZodOptional)return q(b.unwrap()).optional();if(b instanceof x.ZodNullable)return q(b.unwrap()).nullable();if(b instanceof x.ZodArray)return x.array(q(b.element));return x.union([b,x.custom((g)=>H.Output.isInstance(g))])}var N=x.object({metadata:x.object({stateful:x.boolean(),proxiable:x.boolean()}),connectionTypes:x.record(x.string(),x.object({description:x.string().min(5)})),configSchema:x.custom(),deploymentInputSchema:x.custom(),outputSchema:x.custom()}),Q=x.object({});class U{opts;providers;validationSchema;validationDeploymentInputSchema;allowedInterfaces=null;constructor(b){this.opts=N.parse(b),this.providers={},this.validationSchema=q(b.configSchema),this.validationDeploymentInputSchema=q(b.deploymentInputSchema)}implement(b,g){return this.providers[b]={...g,stateSchema:g.stateSchema??Q},this}getConnectionSchema(b){return new b().schema}createAllowConnectionInterfacesFn(){return(b)=>{if(!this.allowedInterfaces)this.allowedInterfaces=new Map;for(let g of b){let F=new g.interface().schema.safeParse(g.data);if(!F.success)throw new Error(`Invalid data for connection interface ${g.interface.name}: ${F.error.message}`);this.allowedInterfaces.set(g.interface,g.data)}}}getAllowedInterfaces(){return this.allowedInterfaces}}export{X as createConnectionInterface,U as InfraComponent,L as DeploymentArtifactType,K as ConnectionInterface,J as CloudProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"