@sdlcworks/components 0.0.17 → 0.0.18

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
@@ -149,23 +149,13 @@ export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends C
149
149
  interface: C;
150
150
  handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<ConnectionHandlerResult>;
151
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>;
152
+ export declare function connectionHandler<C extends ConnectionInterfaceClass>(entry: {
153
+ interface: C;
154
+ handler: (ctx: ConnectionHandlerCtx<any, InferConnectionData<C>, any>) => Promise<ConnectionHandlerResult>;
155
+ }): {
156
+ interface: C;
157
+ handler: (ctx: ConnectionHandlerCtx<any, InferConnectionData<C>, any>) => Promise<ConnectionHandlerResult>;
158
+ };
169
159
  export type ProviderDeployCtx<D, S> = {
170
160
  state: S;
171
161
  } & Record<string, DeploymentInfo>;
@@ -176,7 +166,7 @@ export type EmptyStateShape = typeof emptyStateSchema.shape;
176
166
  export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
177
167
  stateSchema?: z.ZodObject<SShape>;
178
168
  pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
179
- connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, ConnectionInterfaceClass>[];
169
+ connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, any>[];
180
170
  deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
181
171
  };
182
172
  /**
package/dist/index.js CHANGED
@@ -1 +1,113 @@
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};
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
+ function connectionHandler(entry) {
62
+ return entry;
63
+ }
64
+ var emptyStateSchema = z.object({});
65
+
66
+ class InfraComponent {
67
+ opts;
68
+ providers;
69
+ validationSchema;
70
+ validationDeploymentInputSchema;
71
+ declaredConnectionInterfaces = new Map;
72
+ constructor(opts) {
73
+ this.opts = InfraComponentOptsSchema.parse(opts);
74
+ this.providers = {};
75
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
76
+ this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
77
+ }
78
+ implement(provider, fns) {
79
+ this.providers[provider] = {
80
+ ...fns,
81
+ stateSchema: fns.stateSchema ?? emptyStateSchema
82
+ };
83
+ return this;
84
+ }
85
+ getConnectionSchema(interfaceClass) {
86
+ const instance = new interfaceClass;
87
+ return instance.schema;
88
+ }
89
+ createDeclareConnectionInterfacesFn() {
90
+ return (entries) => {
91
+ for (const entry of entries) {
92
+ const instance = new entry.interface;
93
+ const schema = instance.schema;
94
+ const parseResult = schema.safeParse(entry.data);
95
+ if (!parseResult.success) {
96
+ throw new Error(`Invalid data for connection interface ${entry.interface.name}: ${parseResult.error.message}`);
97
+ }
98
+ this.declaredConnectionInterfaces.set(entry.interface, entry.data);
99
+ }
100
+ };
101
+ }
102
+ getDeclaredInterfaces() {
103
+ return this.declaredConnectionInterfaces;
104
+ }
105
+ }
106
+ export {
107
+ createConnectionInterface,
108
+ connectionHandler,
109
+ InfraComponent,
110
+ DeploymentArtifactType,
111
+ ConnectionInterface,
112
+ CloudProvider
113
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"