@sdlcworks/components 0.0.33 → 0.0.35

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
@@ -20,7 +20,8 @@ export declare enum CloudProvider {
20
20
  cloudflare = "cloudflare"
21
21
  }
22
22
  export declare enum DeploymentArtifactType {
23
- oci_spec_image = "oci_spec_image"
23
+ oci_spec_image = "oci_spec_image",
24
+ file = "file"
24
25
  }
25
26
  /**
26
27
  * GCP credential fields required for authentication.
@@ -44,6 +45,14 @@ export type BranchMetadataCloudCredentialCloudflare = {
44
45
  CLOUDFLARE_API_TOKEN: string;
45
46
  CLOUDFLARE_ACCOUNT_ID?: string;
46
47
  };
48
+ /**
49
+ * Environment variable store for app components.
50
+ * Maps component name to its resolved environment variables (key-value pairs).
51
+ *
52
+ * For each infra component, this contains only the env vars for app components
53
+ * that are actively targeting that infra component.
54
+ */
55
+ export type EnvStore = Record<string, Record<string, string>>;
47
56
  /**
48
57
  * Maps each CloudProvider to its corresponding credential type.
49
58
  * Used to provide fully-typed credentials in handler contexts.
@@ -61,11 +70,6 @@ export type ProviderCredentialsMap = {
61
70
  * Returns the typed credentials for the specified provider.
62
71
  */
63
72
  export type GetCredentialsFn<P extends CloudProvider> = () => ProviderCredentialsMap[P];
64
- export declare enum TCPUrlType {
65
- ipv4 = "ipv4",
66
- ipv6 = "ipv6",
67
- domain = "domain"
68
- }
69
73
  /**
70
74
  * Transforms any interface name to canonical hyphen-separated lowercase form.
71
75
  *
@@ -128,16 +132,10 @@ export declare function extendSchema<TParentSchema extends z.ZodObject<z.ZodRawS
128
132
  [k in keyof T]: T[k];
129
133
  } : never, TChildSchema["_zod"]["config"]>;
130
134
  /**
131
- * TCP Connection Interface - defines a TCP-based connection endpoint.
132
- * Use this for components that expose TCP services.
135
+ * Public HTTP Connection Interface - defines a public HTTP endpoint.
136
+ * No metadata, only URI is provided.
133
137
  */
134
- export declare const TCPCI: ConnectionInterfaceDef<"tcp", z.ZodObject<{
135
- url: z.ZodObject<{
136
- type: z.ZodEnum<typeof TCPUrlType>;
137
- value: z.ZodString;
138
- }, z.core.$strip>;
139
- publicAccess: z.ZodBoolean;
140
- }, z.core.$strip>, undefined>;
138
+ export declare const PublicHTTPCI: ConnectionInterfaceDef<"public-http", z.ZodObject<{}, z.core.$strip>, undefined>;
141
139
  /**
142
140
  * Extract the inferred data type from a ConnectionInterfaceDef.
143
141
  */
@@ -233,6 +231,7 @@ export type ProviderPulumiCtx<I, S, P extends CloudProvider = CloudProvider> = {
233
231
  state: S;
234
232
  declareConnectionInterfaces: DeclareConnectionInterfacesFn;
235
233
  buildArtifacts: Record<string, ArtifactInfo>;
234
+ envStore: EnvStore;
236
235
  getCredentials: GetCredentialsFn<P>;
237
236
  };
238
237
  /**
@@ -289,6 +288,7 @@ export type ProviderAllocateCtx<S, P extends CloudProvider = CloudProvider> = {
289
288
  (name: string, ...values: any[]): string;
290
289
  (strings: TemplateStringsArray, ...values: any[]): string;
291
290
  };
291
+ envStore: EnvStore;
292
292
  getCredentials: GetCredentialsFn<P>;
293
293
  };
294
294
  export type ProviderDeallocateCtx<S, P extends CloudProvider = CloudProvider> = {
@@ -304,6 +304,7 @@ export type ProviderDeallocateCtx<S, P extends CloudProvider = CloudProvider> =
304
304
  export type ProviderUpsertArtifactsCtx<S, P extends CloudProvider = CloudProvider> = {
305
305
  buildArtifacts: Record<string, ArtifactInfo>;
306
306
  state: S;
307
+ envStore: EnvStore;
307
308
  getCredentials: GetCredentialsFn<P>;
308
309
  };
309
310
  export type ProviderPulumiFn<I, S, O, P extends CloudProvider = CloudProvider> = (ctx: ProviderPulumiCtx<I, S, P>) => Promise<O>;
package/dist/index.js CHANGED
@@ -1 +1,158 @@
1
- import{z as j}from"zod";import*as Y from"@pulumi/pulumi";var Q;((L)=>{L.aws="aws";L.gcloud="gcloud";L.azure="azure";L.linode="linode";L.hetzner="hetzner";L.cloudflare="cloudflare"})(Q||={});var W;((B)=>B.oci_spec_image="oci_spec_image")(W||={});var Z;((H)=>{H.ipv4="ipv4";H.ipv6="ipv6";H.domain="domain"})(Z||={});var X=new Map;function _(b){return b.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase().replace(/-+/g,"-").replace(/^-|-$/g,"")}function $(b){let B=_(b);if(B.length===0)throw new Error("Connection interface name cannot be empty");let F=X.get(B);if(F!==void 0&&F!==b)throw new Error(`Connection interface name collision: '${b}' resolves to '${B}' which is already registered by '${F}'`);return X.set(B,b),B}function q(b,B,F){return{name:$(b),schema:B,resultSchema:F}}function w(b,B){return b.schema.merge(B)}var x=q("tcp",j.object({url:j.object({type:j.nativeEnum(Z),value:j.string()}),publicAccess:j.boolean()})),R=j.object({});function J(b){if(b instanceof j.ZodObject){let B=b.shape,F={};for(let H in B)F[H]=J(B[H]);return j.object(F)}if(b instanceof j.ZodOptional)return J(b.unwrap()).optional();if(b instanceof j.ZodNullable)return J(b.unwrap()).nullable();if(b instanceof j.ZodDefault)return J(b._def.innerType).default(b._def.defaultValue);if(b instanceof j.ZodArray)return j.array(J(b.element));if(b instanceof j.ZodDiscriminatedUnion){let B=b._def.options.map((F)=>J(F));return j.discriminatedUnion(b._def.discriminator,B)}if(b instanceof j.ZodRecord){let B=b._def.keyType,F=b._def.valueType,H=B?J(B):j.string(),M=F?J(F):j.any();return j.record(H,M)}return j.union([b,j.custom((B)=>Y.Output.isInstance(B))])}var E=j.object({metadata:j.object({stateful:j.boolean(),proxiable:j.boolean()}),connectionTypes:j.record(j.string(),j.object({description:j.string().min(5)})),configSchema:j.custom(),deploymentInputSchema:j.custom(),outputSchema:j.custom()});function U(b){return b}var G=j.object({});class K{opts;providers;validationSchema;validationDeploymentInputSchema;declaredConnectionInterfaces=new Map;constructor(b){this.opts=E.parse(b),this.providers={},this.validationSchema=J(b.configSchema),this.validationDeploymentInputSchema=J(b.deploymentInputSchema)}implement(b,B){return this.providers[b]={...B,stateSchema:B.stateSchema??G,initialState:B.initialState},this}getConnectionSchema(b){return b.schema}createDeclareConnectionInterfacesFn(){return(b)=>{this.declaredConnectionInterfaces=new Map;for(let B of b){let F=B.interface.schema,H=J(F),M=H.safeParse(B.data);if(!M.success)throw new Error(`Invalid data for connection interface '${B.interface.name}': ${M.error.message}`);this.declaredConnectionInterfaces.set(B.interface.name,{schema:H,data:B.data})}}}getDeclaredInterfaces(){return this.declaredConnectionInterfaces}}export{_ as toCanonicalInterfaceName,w as extendSchema,q as defineConnectionInterface,U as connectionHandler,Z as TCPUrlType,x as TCPCI,K as InfraComponent,W as DeploymentArtifactType,Q as CloudProvider};
1
+ // src/infra.ts
2
+ import { z } from "zod";
3
+ import * as pulumi from "@pulumi/pulumi";
4
+
5
+ // src/copied-types.ts
6
+ var CloudProvider;
7
+ ((CloudProvider2) => {
8
+ CloudProvider2["aws"] = "aws";
9
+ CloudProvider2["gcloud"] = "gcloud";
10
+ CloudProvider2["azure"] = "azure";
11
+ CloudProvider2["linode"] = "linode";
12
+ CloudProvider2["hetzner"] = "hetzner";
13
+ CloudProvider2["cloudflare"] = "cloudflare";
14
+ })(CloudProvider ||= {});
15
+ var DeploymentArtifactType;
16
+ ((DeploymentArtifactType2) => {
17
+ DeploymentArtifactType2["oci_spec_image"] = "oci_spec_image";
18
+ DeploymentArtifactType2["file"] = "file";
19
+ })(DeploymentArtifactType ||= {});
20
+
21
+ // src/infra.ts
22
+ var connectionInterfaceRegistry = new Map;
23
+ function toCanonicalInterfaceName(name) {
24
+ return name.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase().replace(/-+/g, "-").replace(/^-|-$/g, "");
25
+ }
26
+ function registerInterfaceName(name) {
27
+ const canonical = toCanonicalInterfaceName(name);
28
+ if (canonical.length === 0) {
29
+ throw new Error(`Connection interface name cannot be empty`);
30
+ }
31
+ const existing = connectionInterfaceRegistry.get(canonical);
32
+ if (existing !== undefined && existing !== name) {
33
+ throw new Error(`Connection interface name collision: '${name}' resolves to '${canonical}' which is already registered by '${existing}'`);
34
+ }
35
+ connectionInterfaceRegistry.set(canonical, name);
36
+ return canonical;
37
+ }
38
+ function defineConnectionInterface(name, schema, resultSchema) {
39
+ const canonicalName = registerInterfaceName(name);
40
+ return {
41
+ name: canonicalName,
42
+ schema,
43
+ resultSchema
44
+ };
45
+ }
46
+ function extendSchema(parentDef, additionalSchema) {
47
+ return parentDef.schema.merge(additionalSchema);
48
+ }
49
+ var PublicHTTPCI = defineConnectionInterface("public-http", z.object({}));
50
+ var emptyOutputSchema = z.object({});
51
+ function transformSchemaToAcceptOutputs(schema) {
52
+ if (schema instanceof z.ZodObject) {
53
+ const shape = schema.shape;
54
+ const newShape = {};
55
+ for (const key in shape) {
56
+ newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
57
+ }
58
+ return z.object(newShape);
59
+ }
60
+ if (schema instanceof z.ZodOptional) {
61
+ return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
62
+ }
63
+ if (schema instanceof z.ZodNullable) {
64
+ return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
65
+ }
66
+ if (schema instanceof z.ZodDefault) {
67
+ return transformSchemaToAcceptOutputs(schema._def.innerType).default(schema._def.defaultValue);
68
+ }
69
+ if (schema instanceof z.ZodArray) {
70
+ return z.array(transformSchemaToAcceptOutputs(schema.element));
71
+ }
72
+ if (schema instanceof z.ZodDiscriminatedUnion) {
73
+ const transformedOptions = schema._def.options.map((option) => transformSchemaToAcceptOutputs(option));
74
+ return z.discriminatedUnion(schema._def.discriminator, transformedOptions);
75
+ }
76
+ if (schema instanceof z.ZodRecord) {
77
+ const keyType = schema._def.keyType;
78
+ const valueType = schema._def.valueType;
79
+ const transformedKey = keyType ? transformSchemaToAcceptOutputs(keyType) : z.string();
80
+ const transformedValue = valueType ? transformSchemaToAcceptOutputs(valueType) : z.any();
81
+ return z.record(transformedKey, transformedValue);
82
+ }
83
+ return z.union([
84
+ schema,
85
+ z.custom((val) => pulumi.Output.isInstance(val))
86
+ ]);
87
+ }
88
+ var InfraComponentOptsSchema = z.object({
89
+ metadata: z.object({
90
+ stateful: z.boolean(),
91
+ proxiable: z.boolean()
92
+ }),
93
+ connectionTypes: z.record(z.string(), z.object({
94
+ description: z.string().min(5)
95
+ })),
96
+ configSchema: z.custom(),
97
+ deploymentInputSchema: z.custom(),
98
+ outputSchema: z.custom()
99
+ });
100
+ function connectionHandler(entry) {
101
+ return entry;
102
+ }
103
+ var emptyStateSchema = z.object({});
104
+
105
+ class InfraComponent {
106
+ opts;
107
+ providers;
108
+ validationSchema;
109
+ validationDeploymentInputSchema;
110
+ declaredConnectionInterfaces = new Map;
111
+ constructor(opts) {
112
+ this.opts = InfraComponentOptsSchema.parse(opts);
113
+ this.providers = {};
114
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
115
+ this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
116
+ }
117
+ implement(provider, fns) {
118
+ this.providers[provider] = {
119
+ ...fns,
120
+ stateSchema: fns.stateSchema ?? emptyStateSchema,
121
+ initialState: fns.initialState
122
+ };
123
+ return this;
124
+ }
125
+ getConnectionSchema(interfaceDef) {
126
+ return interfaceDef.schema;
127
+ }
128
+ createDeclareConnectionInterfacesFn() {
129
+ return (entries) => {
130
+ this.declaredConnectionInterfaces = new Map;
131
+ for (const entry of entries) {
132
+ const schema = entry.interface.schema;
133
+ const transformedSchema = transformSchemaToAcceptOutputs(schema);
134
+ const parseResult = transformedSchema.safeParse(entry.data);
135
+ if (!parseResult.success) {
136
+ throw new Error(`Invalid data for connection interface '${entry.interface.name}': ${parseResult.error.message}`);
137
+ }
138
+ this.declaredConnectionInterfaces.set(entry.interface.name, {
139
+ schema: transformedSchema,
140
+ data: entry.data
141
+ });
142
+ }
143
+ };
144
+ }
145
+ getDeclaredInterfaces() {
146
+ return this.declaredConnectionInterfaces;
147
+ }
148
+ }
149
+ export {
150
+ toCanonicalInterfaceName,
151
+ extendSchema,
152
+ defineConnectionInterface,
153
+ connectionHandler,
154
+ PublicHTTPCI,
155
+ InfraComponent,
156
+ DeploymentArtifactType,
157
+ CloudProvider
158
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"