@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 +8 -18
- package/dist/index.js +113 -1
- package/package.json +1 -1
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
+
};
|