@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 +16 -15
- package/dist/index.js +158 -1
- package/package.json +1 -1
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
|
-
*
|
|
132
|
-
*
|
|
135
|
+
* Public HTTP Connection Interface - defines a public HTTP endpoint.
|
|
136
|
+
* No metadata, only URI is provided.
|
|
133
137
|
*/
|
|
134
|
-
export declare const
|
|
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
|
-
|
|
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
|
+
};
|