@sdlcworks/components 0.0.7 → 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,94 +19,189 @@ 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
  };
43
- export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape> = {
44
- metadata: {
45
- stateful: boolean;
46
- proxiable: boolean;
47
- require_connector_same_provider: boolean;
48
- };
49
- connectionTypes: Record<string, {
50
- description: string;
51
- }>;
76
+ export type InferOutputType<OShape extends z.ZodRawShape> = {
77
+ [K in keyof z.infer<z.ZodObject<OShape>>]: PulumiOutput<z.infer<z.ZodObject<OShape>>[K]>;
78
+ };
79
+ declare const emptyOutputSchema: z.ZodObject<{}, z.core.$strip>;
80
+ export type EmptyOutputShape = typeof emptyOutputSchema.shape;
81
+ declare const InfraComponentOptsSchema: z.ZodObject<{
82
+ metadata: z.ZodObject<{
83
+ stateful: z.ZodBoolean;
84
+ proxiable: z.ZodBoolean;
85
+ }, z.core.$strip>;
86
+ connectionTypes: z.ZodRecord<z.ZodString, z.ZodObject<{
87
+ description: z.ZodString;
88
+ }, z.core.$strip>>;
89
+ configSchema: z.ZodCustom<z.ZodObject<Readonly<{
90
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
91
+ }>, z.core.$strip>, z.ZodObject<Readonly<{
92
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
93
+ }>, z.core.$strip>>;
94
+ deploymentInputSchema: z.ZodCustom<z.ZodObject<Readonly<{
95
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
96
+ }>, z.core.$strip>, z.ZodObject<Readonly<{
97
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
98
+ }>, z.core.$strip>>;
99
+ outputSchema: z.ZodCustom<z.ZodObject<Readonly<{
100
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
101
+ }>, z.core.$strip>, z.ZodObject<Readonly<{
102
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
103
+ }>, z.core.$strip>>;
104
+ }, z.core.$strip>;
105
+ export type InfraComponentOptsBase = z.infer<typeof InfraComponentOptsSchema>;
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"> & {
52
111
  configSchema: z.ZodObject<CShape>;
53
112
  deploymentInputSchema: z.ZodObject<DShape>;
113
+ outputSchema: z.ZodObject<OShape>;
114
+ connectionTypes: ConnTypes;
54
115
  };
55
116
  export type InfraComponentInputs<C, D> = {
56
117
  config: C;
57
118
  deploymentInput: D;
58
119
  };
59
- export type InfraComponentOutputs = {
60
- [key: string]: PulumiOutput<any>;
61
- };
62
- 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
+ };
63
126
  inputs: I;
64
127
  state: S;
128
+ allowConnectionInterfaces: AllowConnectionInterfacesFn;
65
129
  };
66
- 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> = {
67
136
  state: S;
137
+ data: Data;
138
+ connectionType: ConnectionType;
68
139
  };
69
- export type ProviderDeployCtx<S> = CommonDeployFnInputs & {
70
- 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>;
71
146
  };
72
- export type ProviderPulumiFn<I, S> = (ctx: ProviderPulumiCtx<I, S>) => Promise<InfraComponentOutputs>;
73
- export type ProviderConnectFn<S> = (ctx: ProviderConnectCtx<S>) => Promise<void>;
74
- export type ProviderDeployFn<S> = (ctx: ProviderDeployCtx<S>) => Promise<void>;
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
+ }>;
157
+ export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
158
+ export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
75
159
  declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
76
160
  export type EmptyStateShape = typeof emptyStateSchema.shape;
77
- export type ProviderFnsDefStateless<I> = {
78
- stateSchema?: never;
79
- pulumi: ProviderPulumiFn<I, Record<string, never>>;
80
- onConnect?: ProviderConnectFn<Record<string, never>>;
81
- onDeploy?: ProviderDeployFn<Record<string, never>>;
82
- };
83
- export type ProviderFnsDefStateful<I, SShape extends z.ZodRawShape> = {
84
- stateSchema: z.ZodObject<SShape>;
85
- pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>>;
86
- onConnect?: ProviderConnectFn<z.infer<z.ZodObject<SShape>>>;
87
- onDeploy?: ProviderDeployFn<z.infer<z.ZodObject<SShape>>>;
161
+ export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
162
+ stateSchema?: z.ZodObject<SShape>;
163
+ pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
164
+ connect?: ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType>[];
165
+ deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
88
166
  };
89
- export type ProviderFnsDef<I, SShape extends z.ZodRawShape = EmptyStateShape> = ProviderFnsDefStateless<I> | ProviderFnsDefStateful<I, SShape>;
90
167
  export type StoredProviderFns = {
91
168
  stateSchema: z.ZodObject<any>;
92
- pulumi: ProviderPulumiFn<any, any>;
93
- onConnect?: ProviderConnectFn<any>;
94
- onDeploy?: ProviderDeployFn<any>;
169
+ pulumi: ProviderPulumiFn<any, any, any>;
170
+ connect?: ConnectionHandlerEntry<any, any>[];
171
+ deploy?: ProviderDeployFn<any, any>;
95
172
  };
96
173
  export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
97
- export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape> {
98
- opts: InfraComponentOpts<CShape, DShape>;
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>;
99
180
  providers: ProviderRegistry;
100
181
  validationSchema: z.ZodTypeAny;
101
182
  validationDeploymentInputSchema: z.ZodTypeAny;
102
- constructor(opts: InfraComponentOpts<CShape, DShape>);
103
- private register;
104
- aws<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
105
- gcloud<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
106
- azure<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
107
- linode<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
108
- hetzner<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
109
- cloudflare<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
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;
110
205
  }
111
206
 
112
207
  export {};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{z as q}from"zod";import*as H from"@pulumi/pulumi";var J;((B)=>{B.aws="aws";B.gcloud="gcloud";B.azure="azure";B.linode="linode";B.hetzner="hetzner";B.cloudflare="cloudflare"})(J||={});var K;((F)=>{F.container_image="container_image";F.local_file="local_file"})(K||={});function E(j){if(j instanceof q.ZodObject){let x=j.shape,F={};for(let G in x)F[G]=E(x[G]);return q.object(F)}if(j instanceof q.ZodOptional)return E(j.unwrap()).optional();if(j instanceof q.ZodNullable)return E(j.unwrap()).nullable();if(j instanceof q.ZodArray)return q.array(E(j.element));return q.union([j,q.custom((x)=>H.Output.isInstance(x))])}var L=q.object({metadata:q.object({stateful:q.boolean(),proxiable:q.boolean(),require_connector_same_provider:q.boolean()}),connectionTypes:q.record(q.string(),q.object({description:q.string().min(5)})),configSchema:q.any(),deploymentInputSchema:q.any()}),M=q.object({});class N{opts;providers;validationSchema;validationDeploymentInputSchema;constructor(j){this.opts=L.parse(j),this.providers={},this.validationSchema=E(j.configSchema),this.validationDeploymentInputSchema=E(j.deploymentInputSchema)}register(j,x){this.providers[j]={...x,stateSchema:x.stateSchema??M}}aws(j){this.register("aws",j)}gcloud(j){this.register("gcloud",j)}azure(j){this.register("azure",j)}linode(j){this.register("linode",j)}hetzner(j){this.register("hetzner",j)}cloudflare(j){this.register("cloudflare",j)}}export{N as InfraComponent,K as DeploymentArtifactType,J as CloudProvider};
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.7",
3
+ "version": "0.0.9",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"