@sdlcworks/components 0.0.15 → 0.0.17

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
@@ -106,10 +106,7 @@ export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.Zo
106
106
  outputSchema: z.ZodObject<OShape>;
107
107
  connectionTypes: ConnTypes;
108
108
  };
109
- export type InfraComponentInputs<C, D> = {
110
- config: C;
111
- deploymentInput: D;
112
- };
109
+ export type InfraComponentInputs<C> = C;
113
110
  export type DeploymentInfo = {
114
111
  config: Record<string, any>;
115
112
  artifact: {
@@ -152,6 +149,23 @@ export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends C
152
149
  interface: C;
153
150
  handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<ConnectionHandlerResult>;
154
151
  };
152
+ /**
153
+ * Helper function that preserves type inference for connection handler entries.
154
+ * Use this to get proper typing for ctx.connectionData in handlers.
155
+ *
156
+ * @example
157
+ * connect: [
158
+ * connectionHandler({
159
+ * interface: ServiceAccountCI,
160
+ * handler: async (ctx) => {
161
+ * // ctx.connectionData is now properly typed from ServiceAccountCI schema
162
+ * ctx.connectionData.email // string
163
+ * return {};
164
+ * },
165
+ * }),
166
+ * ] as const,
167
+ */
168
+ export declare function connectionHandler<S, ConnectionType extends string, C extends ConnectionInterfaceClass>(entry: ConnectionHandlerEntry<S, ConnectionType, C>): ConnectionHandlerEntry<S, ConnectionType, C>;
155
169
  export type ProviderDeployCtx<D, S> = {
156
170
  state: S;
157
171
  } & Record<string, DeploymentInfo>;
@@ -162,7 +176,7 @@ export type EmptyStateShape = typeof emptyStateSchema.shape;
162
176
  export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
163
177
  stateSchema?: z.ZodObject<SShape>;
164
178
  pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
165
- connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, any>[];
179
+ connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, ConnectionInterfaceClass>[];
166
180
  deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
167
181
  };
168
182
  /**
@@ -193,7 +207,7 @@ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends
193
207
  validationDeploymentInputSchema: z.ZodTypeAny;
194
208
  private declaredConnectionInterfaces;
195
209
  constructor(opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>);
196
- implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, InferZodType<DShape>, InferOutputType<OShape>, SShape, keyof ConnTypes & string>): this;
210
+ implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>>, InferZodType<DShape>, InferOutputType<OShape>, SShape, keyof ConnTypes & string>): this;
197
211
  /**
198
212
  * Get the schema for a specific connection interface.
199
213
  * Used by the orchestrator at runtime.
package/dist/index.js CHANGED
@@ -1,109 +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 DeploymentArtifactType;
14
- ((DeploymentArtifactType2) => {
15
- DeploymentArtifactType2["container_image"] = "container_image";
16
- })(DeploymentArtifactType ||= {});
17
-
18
- class ConnectionInterface {
19
- }
20
- function createConnectionInterface(schema) {
21
- return class extends ConnectionInterface {
22
- schema = schema;
23
- };
24
- }
25
- var emptyOutputSchema = z.object({});
26
- function transformSchemaToAcceptOutputs(schema) {
27
- if (schema instanceof z.ZodObject) {
28
- const shape = schema.shape;
29
- const newShape = {};
30
- for (const key in shape) {
31
- newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
32
- }
33
- return z.object(newShape);
34
- }
35
- if (schema instanceof z.ZodOptional) {
36
- return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
37
- }
38
- if (schema instanceof z.ZodNullable) {
39
- return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
40
- }
41
- if (schema instanceof z.ZodArray) {
42
- return z.array(transformSchemaToAcceptOutputs(schema.element));
43
- }
44
- return z.union([
45
- schema,
46
- z.custom((val) => pulumi.Output.isInstance(val))
47
- ]);
48
- }
49
- var InfraComponentOptsSchema = z.object({
50
- metadata: z.object({
51
- stateful: z.boolean(),
52
- proxiable: z.boolean()
53
- }),
54
- connectionTypes: z.record(z.string(), z.object({
55
- description: z.string().min(5)
56
- })),
57
- configSchema: z.custom(),
58
- deploymentInputSchema: z.custom(),
59
- outputSchema: z.custom()
60
- });
61
- var emptyStateSchema = z.object({});
62
-
63
- class InfraComponent {
64
- opts;
65
- providers;
66
- validationSchema;
67
- validationDeploymentInputSchema;
68
- declaredConnectionInterfaces = new Map;
69
- constructor(opts) {
70
- this.opts = InfraComponentOptsSchema.parse(opts);
71
- this.providers = {};
72
- this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
73
- this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
74
- }
75
- implement(provider, fns) {
76
- this.providers[provider] = {
77
- ...fns,
78
- stateSchema: fns.stateSchema ?? emptyStateSchema
79
- };
80
- return this;
81
- }
82
- getConnectionSchema(interfaceClass) {
83
- const instance = new interfaceClass;
84
- return instance.schema;
85
- }
86
- createDeclareConnectionInterfacesFn() {
87
- return (entries) => {
88
- for (const entry of entries) {
89
- const instance = new entry.interface;
90
- const schema = instance.schema;
91
- const parseResult = schema.safeParse(entry.data);
92
- if (!parseResult.success) {
93
- throw new Error(`Invalid data for connection interface ${entry.interface.name}: ${parseResult.error.message}`);
94
- }
95
- this.declaredConnectionInterfaces.set(entry.interface, entry.data);
96
- }
97
- };
98
- }
99
- getDeclaredInterfaces() {
100
- return this.declaredConnectionInterfaces;
101
- }
102
- }
103
- export {
104
- createConnectionInterface,
105
- InfraComponent,
106
- DeploymentArtifactType,
107
- ConnectionInterface,
108
- CloudProvider
109
- };
1
+ import{z as b}from"zod";import*as H from"@pulumi/pulumi";var K;((j)=>{j.aws="aws";j.gcloud="gcloud";j.azure="azure";j.linode="linode";j.hetzner="hetzner";j.cloudflare="cloudflare"})(K||={});var L;((g)=>g.container_image="container_image")(L||={});class J{}function V(x){return class extends J{schema=x}}var W=b.object({});function q(x){if(x instanceof b.ZodObject){let g=x.shape,B={};for(let E in g)B[E]=q(g[E]);return b.object(B)}if(x instanceof b.ZodOptional)return q(x.unwrap()).optional();if(x instanceof b.ZodNullable)return q(x.unwrap()).nullable();if(x instanceof b.ZodArray)return b.array(q(x.element));return b.union([x,b.custom((g)=>H.Output.isInstance(g))])}var M=b.object({metadata:b.object({stateful:b.boolean(),proxiable:b.boolean()}),connectionTypes:b.record(b.string(),b.object({description:b.string().min(5)})),configSchema:b.custom(),deploymentInputSchema:b.custom(),outputSchema:b.custom()});function X(x){return x}var N=b.object({});class Q{opts;providers;validationSchema;validationDeploymentInputSchema;declaredConnectionInterfaces=new Map;constructor(x){this.opts=M.parse(x),this.providers={},this.validationSchema=q(x.configSchema),this.validationDeploymentInputSchema=q(x.deploymentInputSchema)}implement(x,g){return this.providers[x]={...g,stateSchema:g.stateSchema??N},this}getConnectionSchema(x){return new x().schema}createDeclareConnectionInterfacesFn(){return(x)=>{for(let g of x){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.declaredConnectionInterfaces.set(g.interface,g.data)}}}getDeclaredInterfaces(){return this.declaredConnectionInterfaces}}export{V as createConnectionInterface,X as connectionHandler,Q as InfraComponent,L as DeploymentArtifactType,J as ConnectionInterface,K as CloudProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"