@sdlcworks/components 0.0.32 → 0.0.34
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 +11 -0
- package/dist/index.js +170 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,14 @@ export type BranchMetadataCloudCredentialCloudflare = {
|
|
|
44
44
|
CLOUDFLARE_API_TOKEN: string;
|
|
45
45
|
CLOUDFLARE_ACCOUNT_ID?: string;
|
|
46
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Environment variable store for app components.
|
|
49
|
+
* Maps component name to its resolved environment variables (key-value pairs).
|
|
50
|
+
*
|
|
51
|
+
* For each infra component, this contains only the env vars for app components
|
|
52
|
+
* that are actively targeting that infra component.
|
|
53
|
+
*/
|
|
54
|
+
export type EnvStore = Record<string, Record<string, string>>;
|
|
47
55
|
/**
|
|
48
56
|
* Maps each CloudProvider to its corresponding credential type.
|
|
49
57
|
* Used to provide fully-typed credentials in handler contexts.
|
|
@@ -233,6 +241,7 @@ export type ProviderPulumiCtx<I, S, P extends CloudProvider = CloudProvider> = {
|
|
|
233
241
|
state: S;
|
|
234
242
|
declareConnectionInterfaces: DeclareConnectionInterfacesFn;
|
|
235
243
|
buildArtifacts: Record<string, ArtifactInfo>;
|
|
244
|
+
envStore: EnvStore;
|
|
236
245
|
getCredentials: GetCredentialsFn<P>;
|
|
237
246
|
};
|
|
238
247
|
/**
|
|
@@ -289,6 +298,7 @@ export type ProviderAllocateCtx<S, P extends CloudProvider = CloudProvider> = {
|
|
|
289
298
|
(name: string, ...values: any[]): string;
|
|
290
299
|
(strings: TemplateStringsArray, ...values: any[]): string;
|
|
291
300
|
};
|
|
301
|
+
envStore: EnvStore;
|
|
292
302
|
getCredentials: GetCredentialsFn<P>;
|
|
293
303
|
};
|
|
294
304
|
export type ProviderDeallocateCtx<S, P extends CloudProvider = CloudProvider> = {
|
|
@@ -304,6 +314,7 @@ export type ProviderDeallocateCtx<S, P extends CloudProvider = CloudProvider> =
|
|
|
304
314
|
export type ProviderUpsertArtifactsCtx<S, P extends CloudProvider = CloudProvider> = {
|
|
305
315
|
buildArtifacts: Record<string, ArtifactInfo>;
|
|
306
316
|
state: S;
|
|
317
|
+
envStore: EnvStore;
|
|
307
318
|
getCredentials: GetCredentialsFn<P>;
|
|
308
319
|
};
|
|
309
320
|
export type ProviderPulumiFn<I, S, O, P extends CloudProvider = CloudProvider> = (ctx: ProviderPulumiCtx<I, S, P>) => Promise<O>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1,170 @@
|
|
|
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
|
+
})(DeploymentArtifactType ||= {});
|
|
19
|
+
|
|
20
|
+
// src/infra.ts
|
|
21
|
+
var TCPUrlType;
|
|
22
|
+
((TCPUrlType2) => {
|
|
23
|
+
TCPUrlType2["ipv4"] = "ipv4";
|
|
24
|
+
TCPUrlType2["ipv6"] = "ipv6";
|
|
25
|
+
TCPUrlType2["domain"] = "domain";
|
|
26
|
+
})(TCPUrlType ||= {});
|
|
27
|
+
var connectionInterfaceRegistry = new Map;
|
|
28
|
+
function toCanonicalInterfaceName(name) {
|
|
29
|
+
return name.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase().replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
30
|
+
}
|
|
31
|
+
function registerInterfaceName(name) {
|
|
32
|
+
const canonical = toCanonicalInterfaceName(name);
|
|
33
|
+
if (canonical.length === 0) {
|
|
34
|
+
throw new Error(`Connection interface name cannot be empty`);
|
|
35
|
+
}
|
|
36
|
+
const existing = connectionInterfaceRegistry.get(canonical);
|
|
37
|
+
if (existing !== undefined && existing !== name) {
|
|
38
|
+
throw new Error(`Connection interface name collision: '${name}' resolves to '${canonical}' which is already registered by '${existing}'`);
|
|
39
|
+
}
|
|
40
|
+
connectionInterfaceRegistry.set(canonical, name);
|
|
41
|
+
return canonical;
|
|
42
|
+
}
|
|
43
|
+
function defineConnectionInterface(name, schema, resultSchema) {
|
|
44
|
+
const canonicalName = registerInterfaceName(name);
|
|
45
|
+
return {
|
|
46
|
+
name: canonicalName,
|
|
47
|
+
schema,
|
|
48
|
+
resultSchema
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function extendSchema(parentDef, additionalSchema) {
|
|
52
|
+
return parentDef.schema.merge(additionalSchema);
|
|
53
|
+
}
|
|
54
|
+
var TCPCI = defineConnectionInterface("tcp", z.object({
|
|
55
|
+
url: z.object({
|
|
56
|
+
type: z.nativeEnum(TCPUrlType),
|
|
57
|
+
value: z.string()
|
|
58
|
+
}),
|
|
59
|
+
publicAccess: z.boolean()
|
|
60
|
+
}));
|
|
61
|
+
var emptyOutputSchema = z.object({});
|
|
62
|
+
function transformSchemaToAcceptOutputs(schema) {
|
|
63
|
+
if (schema instanceof z.ZodObject) {
|
|
64
|
+
const shape = schema.shape;
|
|
65
|
+
const newShape = {};
|
|
66
|
+
for (const key in shape) {
|
|
67
|
+
newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
|
|
68
|
+
}
|
|
69
|
+
return z.object(newShape);
|
|
70
|
+
}
|
|
71
|
+
if (schema instanceof z.ZodOptional) {
|
|
72
|
+
return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
|
|
73
|
+
}
|
|
74
|
+
if (schema instanceof z.ZodNullable) {
|
|
75
|
+
return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
|
|
76
|
+
}
|
|
77
|
+
if (schema instanceof z.ZodDefault) {
|
|
78
|
+
return transformSchemaToAcceptOutputs(schema._def.innerType).default(schema._def.defaultValue);
|
|
79
|
+
}
|
|
80
|
+
if (schema instanceof z.ZodArray) {
|
|
81
|
+
return z.array(transformSchemaToAcceptOutputs(schema.element));
|
|
82
|
+
}
|
|
83
|
+
if (schema instanceof z.ZodDiscriminatedUnion) {
|
|
84
|
+
const transformedOptions = schema._def.options.map((option) => transformSchemaToAcceptOutputs(option));
|
|
85
|
+
return z.discriminatedUnion(schema._def.discriminator, transformedOptions);
|
|
86
|
+
}
|
|
87
|
+
if (schema instanceof z.ZodRecord) {
|
|
88
|
+
const keyType = schema._def.keyType;
|
|
89
|
+
const valueType = schema._def.valueType;
|
|
90
|
+
const transformedKey = keyType ? transformSchemaToAcceptOutputs(keyType) : z.string();
|
|
91
|
+
const transformedValue = valueType ? transformSchemaToAcceptOutputs(valueType) : z.any();
|
|
92
|
+
return z.record(transformedKey, transformedValue);
|
|
93
|
+
}
|
|
94
|
+
return z.union([
|
|
95
|
+
schema,
|
|
96
|
+
z.custom((val) => pulumi.Output.isInstance(val))
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
var InfraComponentOptsSchema = z.object({
|
|
100
|
+
metadata: z.object({
|
|
101
|
+
stateful: z.boolean(),
|
|
102
|
+
proxiable: z.boolean()
|
|
103
|
+
}),
|
|
104
|
+
connectionTypes: z.record(z.string(), z.object({
|
|
105
|
+
description: z.string().min(5)
|
|
106
|
+
})),
|
|
107
|
+
configSchema: z.custom(),
|
|
108
|
+
deploymentInputSchema: z.custom(),
|
|
109
|
+
outputSchema: z.custom()
|
|
110
|
+
});
|
|
111
|
+
function connectionHandler(entry) {
|
|
112
|
+
return entry;
|
|
113
|
+
}
|
|
114
|
+
var emptyStateSchema = z.object({});
|
|
115
|
+
|
|
116
|
+
class InfraComponent {
|
|
117
|
+
opts;
|
|
118
|
+
providers;
|
|
119
|
+
validationSchema;
|
|
120
|
+
validationDeploymentInputSchema;
|
|
121
|
+
declaredConnectionInterfaces = new Map;
|
|
122
|
+
constructor(opts) {
|
|
123
|
+
this.opts = InfraComponentOptsSchema.parse(opts);
|
|
124
|
+
this.providers = {};
|
|
125
|
+
this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
|
|
126
|
+
this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
|
|
127
|
+
}
|
|
128
|
+
implement(provider, fns) {
|
|
129
|
+
this.providers[provider] = {
|
|
130
|
+
...fns,
|
|
131
|
+
stateSchema: fns.stateSchema ?? emptyStateSchema,
|
|
132
|
+
initialState: fns.initialState
|
|
133
|
+
};
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
getConnectionSchema(interfaceDef) {
|
|
137
|
+
return interfaceDef.schema;
|
|
138
|
+
}
|
|
139
|
+
createDeclareConnectionInterfacesFn() {
|
|
140
|
+
return (entries) => {
|
|
141
|
+
this.declaredConnectionInterfaces = new Map;
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
const schema = entry.interface.schema;
|
|
144
|
+
const transformedSchema = transformSchemaToAcceptOutputs(schema);
|
|
145
|
+
const parseResult = transformedSchema.safeParse(entry.data);
|
|
146
|
+
if (!parseResult.success) {
|
|
147
|
+
throw new Error(`Invalid data for connection interface '${entry.interface.name}': ${parseResult.error.message}`);
|
|
148
|
+
}
|
|
149
|
+
this.declaredConnectionInterfaces.set(entry.interface.name, {
|
|
150
|
+
schema: transformedSchema,
|
|
151
|
+
data: entry.data
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
getDeclaredInterfaces() {
|
|
157
|
+
return this.declaredConnectionInterfaces;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
toCanonicalInterfaceName,
|
|
162
|
+
extendSchema,
|
|
163
|
+
defineConnectionInterface,
|
|
164
|
+
connectionHandler,
|
|
165
|
+
TCPUrlType,
|
|
166
|
+
TCPCI,
|
|
167
|
+
InfraComponent,
|
|
168
|
+
DeploymentArtifactType,
|
|
169
|
+
CloudProvider
|
|
170
|
+
};
|