@sdlcworks/components 0.0.8 → 0.0.12

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
@@ -3,14 +3,7 @@
3
3
  import { Input as PulumiInput, Output as PulumiOutput } from '@pulumi/pulumi';
4
4
  import { z } from 'zod';
5
5
 
6
- declare const InfraComponentOutputSchema = z.object({
7
- service_name: z.string().nullable().optional(),
8
- public_url: z.string().nullable().optional(),
9
- env_outputs: z.array(z.string()).default([]),
10
- resource_urns: z.array(z.string()),
11
- });
12
- export type InfraComponentOutput = z.infer<typeof InfraComponentOutputSchema>;
13
- export declare enum CloudProvider {
6
+ declare enum CloudProvider {
14
7
  aws = "aws",
15
8
  gcloud = "gcloud",
16
9
  azure = "azure",
@@ -18,25 +11,65 @@ export declare enum CloudProvider {
18
11
  hetzner = "hetzner",
19
12
  cloudflare = "cloudflare"
20
13
  }
14
+ declare const InfraComponentOutputSchema = z.object({
15
+ service_name: z.string().nullable().optional(),
16
+ public_url: z.string().nullable().optional(),
17
+ env_outputs: z.array(z.string()).default([]),
18
+ resource_urns: z.array(z.string()),
19
+ });
20
+ export type InfraComponentOutput = z.infer<typeof InfraComponentOutputSchema>;
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 declareConnectionInterfaces parameter.
62
+ * Declares an interface that this component exposes with typed data.
63
+ */
64
+ export type DeclaredConnectionInterfaceEntry<C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
65
+ interface: C;
66
+ data: InferConnectionDataWithInputs<C>;
67
+ };
68
+ /**
69
+ * Function type for declareConnectionInterfaces.
70
+ * Called within pulumi function to declare exposed connection interfaces.
71
+ */
72
+ export type DeclareConnectionInterfacesFn = <C extends ConnectionInterfaceClass>(entries: DeclaredConnectionInterfaceEntry<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,120 @@ 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
+ declareConnectionInterfaces: DeclareConnectionInterfacesFn;
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, ConnectorData, ConnectionType extends string = string> = {
87
136
  state: S;
137
+ connectionData: ConnectorData;
138
+ connectionType: ConnectionType;
88
139
  };
89
- export type ProviderDeployCtx<S> = CommonDeployFnInputs & {
90
- state: S;
140
+ /**
141
+ * Result returned by connection handlers.
142
+ * Handlers can optionally return a URI for the connection.
143
+ */
144
+ export type ConnectionHandlerResult = {
145
+ uri?: PulumiOutput<string>;
91
146
  };
147
+ /**
148
+ * A connection handler entry mapping a ConnectionInterface to its handler function.
149
+ */
150
+ export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends ConnectionInterfaceClass> = {
151
+ interface: C;
152
+ handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<ConnectionHandlerResult>;
153
+ };
154
+ export type ProviderDeployCtx<D, S> = {
155
+ state: S;
156
+ } & Record<string, {
157
+ provisionOutput: InfraComponentOutput;
158
+ deploymentConfig: D;
159
+ deploymentArtifact: {
160
+ uri: string;
161
+ type: DeploymentArtifactType;
162
+ };
163
+ }>;
92
164
  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>;
165
+ export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
95
166
  declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
96
167
  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>;
168
+ export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
169
+ stateSchema?: z.ZodObject<SShape>;
105
170
  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>>>;
171
+ connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, any>[];
172
+ deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
173
+ };
174
+ /**
175
+ * Stored version of ConnectionHandlerEntry that preserves ConnectionInterfaceClass type.
176
+ * This ensures `interface` is always typed as ConnectionInterfaceClass (not any)
177
+ * when accessing from the registry, allowing runtime schema access.
178
+ */
179
+ export type StoredConnectionHandlerEntry = {
180
+ interface: ConnectionInterfaceClass;
181
+ handler: (ctx: ConnectionHandlerCtx<any, any, any>) => Promise<ConnectionHandlerResult>;
108
182
  };
109
- export type ProviderFnsDef<I, O, SShape extends z.ZodRawShape = EmptyStateShape> = ProviderFnsDefStateless<I, O> | ProviderFnsDefStateful<I, O, SShape>;
110
183
  export type StoredProviderFns = {
111
184
  stateSchema: z.ZodObject<any>;
112
185
  pulumi: ProviderPulumiFn<any, any, any>;
113
- onConnect?: ProviderConnectFn<any>;
114
- onDeploy?: ProviderDeployFn<any>;
186
+ connect?: readonly StoredConnectionHandlerEntry[];
187
+ deploy?: ProviderDeployFn<any, any>;
115
188
  };
116
189
  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>;
190
+ export type DeclaredConnectionInterfaces = Map<ConnectionInterfaceClass, any>;
191
+ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape = EmptyOutputShape, ConnTypes extends Record<string, {
192
+ description: string;
193
+ }> = Record<string, {
194
+ description: string;
195
+ }>> {
196
+ opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>;
119
197
  providers: ProviderRegistry;
120
198
  validationSchema: z.ZodTypeAny;
121
199
  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;
200
+ private declaredConnectionInterfaces;
201
+ constructor(opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>);
202
+ implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, InferZodType<DShape>, InferOutputType<OShape>, SShape, keyof ConnTypes & string>): this;
203
+ /**
204
+ * Get the schema for a specific connection interface.
205
+ * Used by the orchestrator at runtime.
206
+ */
207
+ getConnectionSchema(interfaceClass: ConnectionInterfaceClass): z.ZodObject<z.ZodRawShape> | undefined;
208
+ /**
209
+ * Create the declareConnectionInterfaces function for use in pulumi context.
210
+ * The orchestrator calls this before invoking the pulumi function.
211
+ *
212
+ * @returns Function that validates and stores declared connection interfaces
213
+ */
214
+ createDeclareConnectionInterfacesFn(): DeclareConnectionInterfacesFn;
215
+ /**
216
+ * Get the declared connection interfaces that were declared via declareConnectionInterfaces.
217
+ * The orchestrator calls this after the pulumi function completes.
218
+ */
219
+ getDeclaredInterfaces(): DeclaredConnectionInterfaces;
124
220
  }
125
221
 
126
222
  export {};
package/dist/index.js CHANGED
@@ -1,21 +1,18 @@
1
1
  // src/infra.ts
2
2
  import { z } from "zod";
3
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
4
  var DeploymentArtifactType;
15
5
  ((DeploymentArtifactType2) => {
16
6
  DeploymentArtifactType2["container_image"] = "container_image";
17
- DeploymentArtifactType2["local_file"] = "local_file";
18
7
  })(DeploymentArtifactType ||= {});
8
+
9
+ class ConnectionInterface {
10
+ }
11
+ function createConnectionInterface(schema) {
12
+ return class extends ConnectionInterface {
13
+ schema = schema;
14
+ };
15
+ }
19
16
  var emptyOutputSchema = z.object({});
20
17
  function transformSchemaToAcceptOutputs(schema) {
21
18
  if (schema instanceof z.ZodObject) {
@@ -59,6 +56,7 @@ class InfraComponent {
59
56
  providers;
60
57
  validationSchema;
61
58
  validationDeploymentInputSchema;
59
+ declaredConnectionInterfaces = new Map;
62
60
  constructor(opts) {
63
61
  this.opts = InfraComponentOptsSchema.parse(opts);
64
62
  this.providers = {};
@@ -72,9 +70,30 @@ class InfraComponent {
72
70
  };
73
71
  return this;
74
72
  }
73
+ getConnectionSchema(interfaceClass) {
74
+ const instance = new interfaceClass;
75
+ return instance.schema;
76
+ }
77
+ createDeclareConnectionInterfacesFn() {
78
+ return (entries) => {
79
+ for (const entry of entries) {
80
+ const instance = new entry.interface;
81
+ const schema = instance.schema;
82
+ const parseResult = schema.safeParse(entry.data);
83
+ if (!parseResult.success) {
84
+ throw new Error(`Invalid data for connection interface ${entry.interface.name}: ${parseResult.error.message}`);
85
+ }
86
+ this.declaredConnectionInterfaces.set(entry.interface, entry.data);
87
+ }
88
+ };
89
+ }
90
+ getDeclaredInterfaces() {
91
+ return this.declaredConnectionInterfaces;
92
+ }
75
93
  }
76
94
  export {
95
+ createConnectionInterface,
77
96
  InfraComponent,
78
97
  DeploymentArtifactType,
79
- CloudProvider
98
+ ConnectionInterface
80
99
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.8",
3
+ "version": "0.0.12",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"