@sdlcworks/components 0.0.9 → 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,6 +11,13 @@ 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
22
  container_image = "container_image"
23
23
  }
@@ -58,18 +58,18 @@ export type InferConnectionDataWithInputs<C extends ConnectionInterfaceClass> =
58
58
  [K in keyof InferConnectionData<C>]: PulumiInput<InferConnectionData<C>[K]>;
59
59
  };
60
60
  /**
61
- * Entry type for allowConnectionInterfaces parameter.
61
+ * Entry type for declareConnectionInterfaces parameter.
62
62
  * Declares an interface that this component exposes with typed data.
63
63
  */
64
- export type AllowedConnectionInterfaceEntry<C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
64
+ export type DeclaredConnectionInterfaceEntry<C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
65
65
  interface: C;
66
66
  data: InferConnectionDataWithInputs<C>;
67
67
  };
68
68
  /**
69
- * Function type for allowConnectionInterfaces.
69
+ * Function type for declareConnectionInterfaces.
70
70
  * Called within pulumi function to declare exposed connection interfaces.
71
71
  */
72
- export type AllowConnectionInterfacesFn = <C extends ConnectionInterfaceClass>(entries: AllowedConnectionInterfaceEntry<C>[]) => void;
72
+ export type DeclareConnectionInterfacesFn = <C extends ConnectionInterfaceClass>(entries: DeclaredConnectionInterfaceEntry<C>[]) => void;
73
73
  export type InferZodType<S extends z.ZodRawShape> = {
74
74
  [K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
75
75
  };
@@ -125,24 +125,31 @@ export type ProviderPulumiCtx<I, S> = {
125
125
  };
126
126
  inputs: I;
127
127
  state: S;
128
- allowConnectionInterfaces: AllowConnectionInterfacesFn;
128
+ declareConnectionInterfaces: DeclareConnectionInterfacesFn;
129
129
  };
130
130
  /**
131
131
  * Context passed to connection handlers.
132
132
  * Contains the provider state, typed data from the connecting component,
133
133
  * and the connection type chosen by the orchestrator.
134
134
  */
135
- export type ConnectionHandlerCtx<S, Data, ConnectionType extends string = string> = {
135
+ export type ConnectionHandlerCtx<S, ConnectorData, ConnectionType extends string = string> = {
136
136
  state: S;
137
- data: Data;
137
+ connectionData: ConnectorData;
138
138
  connectionType: ConnectionType;
139
139
  };
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>;
146
+ };
140
147
  /**
141
148
  * A connection handler entry mapping a ConnectionInterface to its handler function.
142
149
  */
143
- export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
150
+ export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends ConnectionInterfaceClass> = {
144
151
  interface: C;
145
- handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<void>;
152
+ handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<ConnectionHandlerResult>;
146
153
  };
147
154
  export type ProviderDeployCtx<D, S> = {
148
155
  state: S;
@@ -161,16 +168,26 @@ export type EmptyStateShape = typeof emptyStateSchema.shape;
161
168
  export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
162
169
  stateSchema?: z.ZodObject<SShape>;
163
170
  pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
164
- connect?: ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType>[];
171
+ connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, any>[];
165
172
  deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
166
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>;
182
+ };
167
183
  export type StoredProviderFns = {
168
184
  stateSchema: z.ZodObject<any>;
169
185
  pulumi: ProviderPulumiFn<any, any, any>;
170
- connect?: ConnectionHandlerEntry<any, any>[];
186
+ connect?: readonly StoredConnectionHandlerEntry[];
171
187
  deploy?: ProviderDeployFn<any, any>;
172
188
  };
173
189
  export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
190
+ export type DeclaredConnectionInterfaces = Map<ConnectionInterfaceClass, any>;
174
191
  export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape = EmptyOutputShape, ConnTypes extends Record<string, {
175
192
  description: string;
176
193
  }> = Record<string, {
@@ -180,7 +197,7 @@ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends
180
197
  providers: ProviderRegistry;
181
198
  validationSchema: z.ZodTypeAny;
182
199
  validationDeploymentInputSchema: z.ZodTypeAny;
183
- private allowedInterfaces;
200
+ private declaredConnectionInterfaces;
184
201
  constructor(opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>);
185
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;
186
203
  /**
@@ -189,19 +206,17 @@ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends
189
206
  */
190
207
  getConnectionSchema(interfaceClass: ConnectionInterfaceClass): z.ZodObject<z.ZodRawShape> | undefined;
191
208
  /**
192
- * Create the allowConnectionInterfaces function for use in pulumi context.
209
+ * Create the declareConnectionInterfaces function for use in pulumi context.
193
210
  * The orchestrator calls this before invoking the pulumi function.
194
211
  *
195
- * @returns Function that validates and stores allowed connection interfaces
212
+ * @returns Function that validates and stores declared connection interfaces
196
213
  */
197
- createAllowConnectionInterfacesFn(): AllowConnectionInterfacesFn;
214
+ createDeclareConnectionInterfacesFn(): DeclareConnectionInterfacesFn;
198
215
  /**
199
- * Get the allowed connection interfaces that were declared via allowConnectionInterfaces.
216
+ * Get the declared connection interfaces that were declared via declareConnectionInterfaces.
200
217
  * 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
218
  */
204
- getAllowedInterfaces(): Map<ConnectionInterfaceClass, any> | null;
219
+ getDeclaredInterfaces(): DeclaredConnectionInterfaces;
205
220
  }
206
221
 
207
222
  export {};
package/dist/index.js CHANGED
@@ -1 +1,99 @@
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};
1
+ // src/infra.ts
2
+ import { z } from "zod";
3
+ import * as pulumi from "@pulumi/pulumi";
4
+ var DeploymentArtifactType;
5
+ ((DeploymentArtifactType2) => {
6
+ DeploymentArtifactType2["container_image"] = "container_image";
7
+ })(DeploymentArtifactType ||= {});
8
+
9
+ class ConnectionInterface {
10
+ }
11
+ function createConnectionInterface(schema) {
12
+ return class extends ConnectionInterface {
13
+ schema = schema;
14
+ };
15
+ }
16
+ var emptyOutputSchema = z.object({});
17
+ function transformSchemaToAcceptOutputs(schema) {
18
+ if (schema instanceof z.ZodObject) {
19
+ const shape = schema.shape;
20
+ const newShape = {};
21
+ for (const key in shape) {
22
+ newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
23
+ }
24
+ return z.object(newShape);
25
+ }
26
+ if (schema instanceof z.ZodOptional) {
27
+ return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
28
+ }
29
+ if (schema instanceof z.ZodNullable) {
30
+ return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
31
+ }
32
+ if (schema instanceof z.ZodArray) {
33
+ return z.array(transformSchemaToAcceptOutputs(schema.element));
34
+ }
35
+ return z.union([
36
+ schema,
37
+ z.custom((val) => pulumi.Output.isInstance(val))
38
+ ]);
39
+ }
40
+ var InfraComponentOptsSchema = z.object({
41
+ metadata: z.object({
42
+ stateful: z.boolean(),
43
+ proxiable: z.boolean()
44
+ }),
45
+ connectionTypes: z.record(z.string(), z.object({
46
+ description: z.string().min(5)
47
+ })),
48
+ configSchema: z.custom(),
49
+ deploymentInputSchema: z.custom(),
50
+ outputSchema: z.custom()
51
+ });
52
+ var emptyStateSchema = z.object({});
53
+
54
+ class InfraComponent {
55
+ opts;
56
+ providers;
57
+ validationSchema;
58
+ validationDeploymentInputSchema;
59
+ declaredConnectionInterfaces = new Map;
60
+ constructor(opts) {
61
+ this.opts = InfraComponentOptsSchema.parse(opts);
62
+ this.providers = {};
63
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
64
+ this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
65
+ }
66
+ implement(provider, fns) {
67
+ this.providers[provider] = {
68
+ ...fns,
69
+ stateSchema: fns.stateSchema ?? emptyStateSchema
70
+ };
71
+ return this;
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
+ }
93
+ }
94
+ export {
95
+ createConnectionInterface,
96
+ InfraComponent,
97
+ DeploymentArtifactType,
98
+ ConnectionInterface
99
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.9",
3
+ "version": "0.0.12",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"