@sdlcworks/components 0.0.9 → 0.0.13
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 +44 -35
- package/dist/index.js +101 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,14 +3,7 @@
|
|
|
3
3
|
import { Input as PulumiInput, Output as PulumiOutput } from '@pulumi/pulumi';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
service_name: z.string().nullable().optional(),
|
|
8
|
-
public_url: z.string().nullable().optional(),
|
|
9
|
-
env_outputs: z.array(z.string()).default([]),
|
|
10
|
-
resource_urns: z.array(z.string()),
|
|
11
|
-
});
|
|
12
|
-
export type InfraComponentOutput = z.infer<typeof InfraComponentOutputSchema>;
|
|
13
|
-
export declare enum CloudProvider {
|
|
6
|
+
export enum CloudProvider {
|
|
14
7
|
aws = "aws",
|
|
15
8
|
gcloud = "gcloud",
|
|
16
9
|
azure = "azure",
|
|
@@ -58,18 +51,18 @@ export type InferConnectionDataWithInputs<C extends ConnectionInterfaceClass> =
|
|
|
58
51
|
[K in keyof InferConnectionData<C>]: PulumiInput<InferConnectionData<C>[K]>;
|
|
59
52
|
};
|
|
60
53
|
/**
|
|
61
|
-
* Entry type for
|
|
54
|
+
* Entry type for declareConnectionInterfaces parameter.
|
|
62
55
|
* Declares an interface that this component exposes with typed data.
|
|
63
56
|
*/
|
|
64
|
-
export type
|
|
57
|
+
export type DeclaredConnectionInterfaceEntry<C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
|
|
65
58
|
interface: C;
|
|
66
59
|
data: InferConnectionDataWithInputs<C>;
|
|
67
60
|
};
|
|
68
61
|
/**
|
|
69
|
-
* Function type for
|
|
62
|
+
* Function type for declareConnectionInterfaces.
|
|
70
63
|
* Called within pulumi function to declare exposed connection interfaces.
|
|
71
64
|
*/
|
|
72
|
-
export type
|
|
65
|
+
export type DeclareConnectionInterfacesFn = <C extends ConnectionInterfaceClass>(entries: DeclaredConnectionInterfaceEntry<C>[]) => void;
|
|
73
66
|
export type InferZodType<S extends z.ZodRawShape> = {
|
|
74
67
|
[K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
|
|
75
68
|
};
|
|
@@ -117,6 +110,13 @@ export type InfraComponentInputs<C, D> = {
|
|
|
117
110
|
config: C;
|
|
118
111
|
deploymentInput: D;
|
|
119
112
|
};
|
|
113
|
+
export type DeploymentInfo = {
|
|
114
|
+
config: Record<string, any>;
|
|
115
|
+
artifact: {
|
|
116
|
+
uri: string;
|
|
117
|
+
type: DeploymentArtifactType;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
120
|
export type ProviderPulumiCtx<I, S> = {
|
|
121
121
|
componentName: string;
|
|
122
122
|
$: {
|
|
@@ -125,35 +125,36 @@ export type ProviderPulumiCtx<I, S> = {
|
|
|
125
125
|
};
|
|
126
126
|
inputs: I;
|
|
127
127
|
state: S;
|
|
128
|
-
|
|
128
|
+
declareConnectionInterfaces: DeclareConnectionInterfacesFn;
|
|
129
|
+
buildArtifacts: Record<string, DeploymentInfo>;
|
|
129
130
|
};
|
|
130
131
|
/**
|
|
131
132
|
* Context passed to connection handlers.
|
|
132
133
|
* Contains the provider state, typed data from the connecting component,
|
|
133
134
|
* and the connection type chosen by the orchestrator.
|
|
134
135
|
*/
|
|
135
|
-
export type ConnectionHandlerCtx<S,
|
|
136
|
+
export type ConnectionHandlerCtx<S, ConnectorData, ConnectionType extends string = string> = {
|
|
136
137
|
state: S;
|
|
137
|
-
|
|
138
|
+
connectionData: ConnectorData;
|
|
138
139
|
connectionType: ConnectionType;
|
|
139
140
|
};
|
|
141
|
+
/**
|
|
142
|
+
* Result returned by connection handlers.
|
|
143
|
+
* Handlers can optionally return a URI for the connection.
|
|
144
|
+
*/
|
|
145
|
+
export type ConnectionHandlerResult = {
|
|
146
|
+
uri?: PulumiOutput<string>;
|
|
147
|
+
};
|
|
140
148
|
/**
|
|
141
149
|
* A connection handler entry mapping a ConnectionInterface to its handler function.
|
|
142
150
|
*/
|
|
143
|
-
export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends ConnectionInterfaceClass
|
|
151
|
+
export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends ConnectionInterfaceClass> = {
|
|
144
152
|
interface: C;
|
|
145
|
-
handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<
|
|
153
|
+
handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<ConnectionHandlerResult>;
|
|
146
154
|
};
|
|
147
155
|
export type ProviderDeployCtx<D, S> = {
|
|
148
156
|
state: S;
|
|
149
|
-
} & Record<string,
|
|
150
|
-
provisionOutput: InfraComponentOutput;
|
|
151
|
-
deploymentConfig: D;
|
|
152
|
-
deploymentArtifact: {
|
|
153
|
-
uri: string;
|
|
154
|
-
type: DeploymentArtifactType;
|
|
155
|
-
};
|
|
156
|
-
}>;
|
|
157
|
+
} & Record<string, DeploymentInfo>;
|
|
157
158
|
export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
|
|
158
159
|
export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
|
|
159
160
|
declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
|
|
@@ -161,16 +162,26 @@ export type EmptyStateShape = typeof emptyStateSchema.shape;
|
|
|
161
162
|
export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
|
|
162
163
|
stateSchema?: z.ZodObject<SShape>;
|
|
163
164
|
pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
|
|
164
|
-
connect?: ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType>[];
|
|
165
|
+
connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, any>[];
|
|
165
166
|
deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
|
|
166
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Stored version of ConnectionHandlerEntry that preserves ConnectionInterfaceClass type.
|
|
170
|
+
* This ensures `interface` is always typed as ConnectionInterfaceClass (not any)
|
|
171
|
+
* when accessing from the registry, allowing runtime schema access.
|
|
172
|
+
*/
|
|
173
|
+
export type StoredConnectionHandlerEntry = {
|
|
174
|
+
interface: ConnectionInterfaceClass;
|
|
175
|
+
handler: (ctx: ConnectionHandlerCtx<any, any, any>) => Promise<ConnectionHandlerResult>;
|
|
176
|
+
};
|
|
167
177
|
export type StoredProviderFns = {
|
|
168
178
|
stateSchema: z.ZodObject<any>;
|
|
169
179
|
pulumi: ProviderPulumiFn<any, any, any>;
|
|
170
|
-
connect?:
|
|
180
|
+
connect?: readonly StoredConnectionHandlerEntry[];
|
|
171
181
|
deploy?: ProviderDeployFn<any, any>;
|
|
172
182
|
};
|
|
173
183
|
export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
|
|
184
|
+
export type DeclaredConnectionInterfaces = Map<ConnectionInterfaceClass, any>;
|
|
174
185
|
export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape = EmptyOutputShape, ConnTypes extends Record<string, {
|
|
175
186
|
description: string;
|
|
176
187
|
}> = Record<string, {
|
|
@@ -180,7 +191,7 @@ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends
|
|
|
180
191
|
providers: ProviderRegistry;
|
|
181
192
|
validationSchema: z.ZodTypeAny;
|
|
182
193
|
validationDeploymentInputSchema: z.ZodTypeAny;
|
|
183
|
-
private
|
|
194
|
+
private declaredConnectionInterfaces;
|
|
184
195
|
constructor(opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>);
|
|
185
196
|
implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, InferZodType<DShape>, InferOutputType<OShape>, SShape, keyof ConnTypes & string>): this;
|
|
186
197
|
/**
|
|
@@ -189,19 +200,17 @@ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends
|
|
|
189
200
|
*/
|
|
190
201
|
getConnectionSchema(interfaceClass: ConnectionInterfaceClass): z.ZodObject<z.ZodRawShape> | undefined;
|
|
191
202
|
/**
|
|
192
|
-
* Create the
|
|
203
|
+
* Create the declareConnectionInterfaces function for use in pulumi context.
|
|
193
204
|
* The orchestrator calls this before invoking the pulumi function.
|
|
194
205
|
*
|
|
195
|
-
* @returns Function that validates and stores
|
|
206
|
+
* @returns Function that validates and stores declared connection interfaces
|
|
196
207
|
*/
|
|
197
|
-
|
|
208
|
+
createDeclareConnectionInterfacesFn(): DeclareConnectionInterfacesFn;
|
|
198
209
|
/**
|
|
199
|
-
* Get the
|
|
210
|
+
* Get the declared connection interfaces that were declared via declareConnectionInterfaces.
|
|
200
211
|
* The orchestrator calls this after the pulumi function completes.
|
|
201
|
-
*
|
|
202
|
-
* @returns Map of interface classes to their data, or null if not set
|
|
203
212
|
*/
|
|
204
|
-
|
|
213
|
+
getDeclaredInterfaces(): DeclaredConnectionInterfaces;
|
|
205
214
|
}
|
|
206
215
|
|
|
207
216
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1 +1,101 @@
|
|
|
1
|
-
|
|
1
|
+
// src/infra.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import * as pulumi from "@pulumi/pulumi";
|
|
4
|
+
import { CloudProvider } from "@sdlc/types";
|
|
5
|
+
var DeploymentArtifactType;
|
|
6
|
+
((DeploymentArtifactType2) => {
|
|
7
|
+
DeploymentArtifactType2["container_image"] = "container_image";
|
|
8
|
+
})(DeploymentArtifactType ||= {});
|
|
9
|
+
|
|
10
|
+
class ConnectionInterface {
|
|
11
|
+
}
|
|
12
|
+
function createConnectionInterface(schema) {
|
|
13
|
+
return class extends ConnectionInterface {
|
|
14
|
+
schema = schema;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
var emptyOutputSchema = z.object({});
|
|
18
|
+
function transformSchemaToAcceptOutputs(schema) {
|
|
19
|
+
if (schema instanceof z.ZodObject) {
|
|
20
|
+
const shape = schema.shape;
|
|
21
|
+
const newShape = {};
|
|
22
|
+
for (const key in shape) {
|
|
23
|
+
newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
|
|
24
|
+
}
|
|
25
|
+
return z.object(newShape);
|
|
26
|
+
}
|
|
27
|
+
if (schema instanceof z.ZodOptional) {
|
|
28
|
+
return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
|
|
29
|
+
}
|
|
30
|
+
if (schema instanceof z.ZodNullable) {
|
|
31
|
+
return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
|
|
32
|
+
}
|
|
33
|
+
if (schema instanceof z.ZodArray) {
|
|
34
|
+
return z.array(transformSchemaToAcceptOutputs(schema.element));
|
|
35
|
+
}
|
|
36
|
+
return z.union([
|
|
37
|
+
schema,
|
|
38
|
+
z.custom((val) => pulumi.Output.isInstance(val))
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
var InfraComponentOptsSchema = z.object({
|
|
42
|
+
metadata: z.object({
|
|
43
|
+
stateful: z.boolean(),
|
|
44
|
+
proxiable: z.boolean()
|
|
45
|
+
}),
|
|
46
|
+
connectionTypes: z.record(z.string(), z.object({
|
|
47
|
+
description: z.string().min(5)
|
|
48
|
+
})),
|
|
49
|
+
configSchema: z.custom(),
|
|
50
|
+
deploymentInputSchema: z.custom(),
|
|
51
|
+
outputSchema: z.custom()
|
|
52
|
+
});
|
|
53
|
+
var emptyStateSchema = z.object({});
|
|
54
|
+
|
|
55
|
+
class InfraComponent {
|
|
56
|
+
opts;
|
|
57
|
+
providers;
|
|
58
|
+
validationSchema;
|
|
59
|
+
validationDeploymentInputSchema;
|
|
60
|
+
declaredConnectionInterfaces = new Map;
|
|
61
|
+
constructor(opts) {
|
|
62
|
+
this.opts = InfraComponentOptsSchema.parse(opts);
|
|
63
|
+
this.providers = {};
|
|
64
|
+
this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
|
|
65
|
+
this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
|
|
66
|
+
}
|
|
67
|
+
implement(provider, fns) {
|
|
68
|
+
this.providers[provider] = {
|
|
69
|
+
...fns,
|
|
70
|
+
stateSchema: fns.stateSchema ?? emptyStateSchema
|
|
71
|
+
};
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
getConnectionSchema(interfaceClass) {
|
|
75
|
+
const instance = new interfaceClass;
|
|
76
|
+
return instance.schema;
|
|
77
|
+
}
|
|
78
|
+
createDeclareConnectionInterfacesFn() {
|
|
79
|
+
return (entries) => {
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const instance = new entry.interface;
|
|
82
|
+
const schema = instance.schema;
|
|
83
|
+
const parseResult = schema.safeParse(entry.data);
|
|
84
|
+
if (!parseResult.success) {
|
|
85
|
+
throw new Error(`Invalid data for connection interface ${entry.interface.name}: ${parseResult.error.message}`);
|
|
86
|
+
}
|
|
87
|
+
this.declaredConnectionInterfaces.set(entry.interface, entry.data);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
getDeclaredInterfaces() {
|
|
92
|
+
return this.declaredConnectionInterfaces;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
createConnectionInterface,
|
|
97
|
+
InfraComponent,
|
|
98
|
+
DeploymentArtifactType,
|
|
99
|
+
ConnectionInterface,
|
|
100
|
+
CloudProvider
|
|
101
|
+
};
|