@sdlcworks/components 0.0.7 → 0.0.9
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 +154 -59
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,94 +19,189 @@ export declare enum CloudProvider {
|
|
|
19
19
|
cloudflare = "cloudflare"
|
|
20
20
|
}
|
|
21
21
|
export declare enum DeploymentArtifactType {
|
|
22
|
-
container_image = "container_image"
|
|
23
|
-
local_file = "local_file"
|
|
22
|
+
container_image = "container_image"
|
|
24
23
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Abstract base class for defining connection interfaces.
|
|
26
|
+
* Users extend this class to define the schema for data that
|
|
27
|
+
* connecting components must provide.
|
|
28
|
+
*/
|
|
29
|
+
export declare abstract class ConnectionInterface<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> {
|
|
30
|
+
abstract readonly schema: TSchema;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Factory function to create a ConnectionInterface class from a schema.
|
|
34
|
+
* Avoids boilerplate of defining a class manually.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const TriggerConnection = createConnectionInterface(
|
|
38
|
+
* z.object({ eventSource: z.string() })
|
|
39
|
+
* );
|
|
40
|
+
*/
|
|
41
|
+
export declare function createConnectionInterface<TSchema extends z.ZodObject<z.ZodRawShape>>(schema: TSchema): {
|
|
42
|
+
new (): {
|
|
43
|
+
readonly schema: TSchema;
|
|
30
44
|
};
|
|
31
45
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Type alias for ConnectionInterface class constructors.
|
|
48
|
+
*/
|
|
49
|
+
export type ConnectionInterfaceClass<TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>> = new () => ConnectionInterface<TSchema>;
|
|
50
|
+
/**
|
|
51
|
+
* Extract the inferred data type from a ConnectionInterface class.
|
|
52
|
+
*/
|
|
53
|
+
export type InferConnectionData<C extends ConnectionInterfaceClass> = z.infer<InstanceType<C>["schema"]>;
|
|
54
|
+
/**
|
|
55
|
+
* Wrap connection data with PulumiInput to support Pulumi Output types.
|
|
56
|
+
*/
|
|
57
|
+
export type InferConnectionDataWithInputs<C extends ConnectionInterfaceClass> = {
|
|
58
|
+
[K in keyof InferConnectionData<C>]: PulumiInput<InferConnectionData<C>[K]>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Entry type for allowConnectionInterfaces parameter.
|
|
62
|
+
* Declares an interface that this component exposes with typed data.
|
|
63
|
+
*/
|
|
64
|
+
export type AllowedConnectionInterfaceEntry<C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
|
|
65
|
+
interface: C;
|
|
66
|
+
data: InferConnectionDataWithInputs<C>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Function type for allowConnectionInterfaces.
|
|
70
|
+
* Called within pulumi function to declare exposed connection interfaces.
|
|
71
|
+
*/
|
|
72
|
+
export type AllowConnectionInterfacesFn = <C extends ConnectionInterfaceClass>(entries: AllowedConnectionInterfaceEntry<C>[]) => void;
|
|
40
73
|
export type InferZodType<S extends z.ZodRawShape> = {
|
|
41
74
|
[K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
|
|
42
75
|
};
|
|
43
|
-
export type
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
76
|
+
export type InferOutputType<OShape extends z.ZodRawShape> = {
|
|
77
|
+
[K in keyof z.infer<z.ZodObject<OShape>>]: PulumiOutput<z.infer<z.ZodObject<OShape>>[K]>;
|
|
78
|
+
};
|
|
79
|
+
declare const emptyOutputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
80
|
+
export type EmptyOutputShape = typeof emptyOutputSchema.shape;
|
|
81
|
+
declare const InfraComponentOptsSchema: z.ZodObject<{
|
|
82
|
+
metadata: z.ZodObject<{
|
|
83
|
+
stateful: z.ZodBoolean;
|
|
84
|
+
proxiable: z.ZodBoolean;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
connectionTypes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
87
|
+
description: z.ZodString;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
configSchema: z.ZodCustom<z.ZodObject<Readonly<{
|
|
90
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
91
|
+
}>, z.core.$strip>, z.ZodObject<Readonly<{
|
|
92
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
93
|
+
}>, z.core.$strip>>;
|
|
94
|
+
deploymentInputSchema: z.ZodCustom<z.ZodObject<Readonly<{
|
|
95
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
96
|
+
}>, z.core.$strip>, z.ZodObject<Readonly<{
|
|
97
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
98
|
+
}>, z.core.$strip>>;
|
|
99
|
+
outputSchema: z.ZodCustom<z.ZodObject<Readonly<{
|
|
100
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
101
|
+
}>, z.core.$strip>, z.ZodObject<Readonly<{
|
|
102
|
+
[k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
103
|
+
}>, z.core.$strip>>;
|
|
104
|
+
}, z.core.$strip>;
|
|
105
|
+
export type InfraComponentOptsBase = z.infer<typeof InfraComponentOptsSchema>;
|
|
106
|
+
export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape, ConnTypes extends Record<string, {
|
|
107
|
+
description: string;
|
|
108
|
+
}> = Record<string, {
|
|
109
|
+
description: string;
|
|
110
|
+
}>> = Omit<InfraComponentOptsBase, "configSchema" | "deploymentInputSchema" | "outputSchema" | "connectionTypes"> & {
|
|
52
111
|
configSchema: z.ZodObject<CShape>;
|
|
53
112
|
deploymentInputSchema: z.ZodObject<DShape>;
|
|
113
|
+
outputSchema: z.ZodObject<OShape>;
|
|
114
|
+
connectionTypes: ConnTypes;
|
|
54
115
|
};
|
|
55
116
|
export type InfraComponentInputs<C, D> = {
|
|
56
117
|
config: C;
|
|
57
118
|
deploymentInput: D;
|
|
58
119
|
};
|
|
59
|
-
export type
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
120
|
+
export type ProviderPulumiCtx<I, S> = {
|
|
121
|
+
componentName: string;
|
|
122
|
+
$: {
|
|
123
|
+
(name: string, ...values: any[]): string;
|
|
124
|
+
(strings: TemplateStringsArray, ...values: any[]): string;
|
|
125
|
+
};
|
|
63
126
|
inputs: I;
|
|
64
127
|
state: S;
|
|
128
|
+
allowConnectionInterfaces: AllowConnectionInterfacesFn;
|
|
65
129
|
};
|
|
66
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Context passed to connection handlers.
|
|
132
|
+
* Contains the provider state, typed data from the connecting component,
|
|
133
|
+
* and the connection type chosen by the orchestrator.
|
|
134
|
+
*/
|
|
135
|
+
export type ConnectionHandlerCtx<S, Data, ConnectionType extends string = string> = {
|
|
67
136
|
state: S;
|
|
137
|
+
data: Data;
|
|
138
|
+
connectionType: ConnectionType;
|
|
68
139
|
};
|
|
69
|
-
|
|
70
|
-
|
|
140
|
+
/**
|
|
141
|
+
* A connection handler entry mapping a ConnectionInterface to its handler function.
|
|
142
|
+
*/
|
|
143
|
+
export type ConnectionHandlerEntry<S, ConnectionType extends string, C extends ConnectionInterfaceClass = ConnectionInterfaceClass> = {
|
|
144
|
+
interface: C;
|
|
145
|
+
handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<C>, ConnectionType>) => Promise<void>;
|
|
71
146
|
};
|
|
72
|
-
export type
|
|
73
|
-
|
|
74
|
-
|
|
147
|
+
export type ProviderDeployCtx<D, S> = {
|
|
148
|
+
state: S;
|
|
149
|
+
} & Record<string, {
|
|
150
|
+
provisionOutput: InfraComponentOutput;
|
|
151
|
+
deploymentConfig: D;
|
|
152
|
+
deploymentArtifact: {
|
|
153
|
+
uri: string;
|
|
154
|
+
type: DeploymentArtifactType;
|
|
155
|
+
};
|
|
156
|
+
}>;
|
|
157
|
+
export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
|
|
158
|
+
export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
|
|
75
159
|
declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
|
|
76
160
|
export type EmptyStateShape = typeof emptyStateSchema.shape;
|
|
77
|
-
export type
|
|
78
|
-
stateSchema?:
|
|
79
|
-
pulumi: ProviderPulumiFn<I,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
export type ProviderFnsDefStateful<I, SShape extends z.ZodRawShape> = {
|
|
84
|
-
stateSchema: z.ZodObject<SShape>;
|
|
85
|
-
pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>>;
|
|
86
|
-
onConnect?: ProviderConnectFn<z.infer<z.ZodObject<SShape>>>;
|
|
87
|
-
onDeploy?: ProviderDeployFn<z.infer<z.ZodObject<SShape>>>;
|
|
161
|
+
export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
|
|
162
|
+
stateSchema?: z.ZodObject<SShape>;
|
|
163
|
+
pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
|
|
164
|
+
connect?: ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType>[];
|
|
165
|
+
deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
|
|
88
166
|
};
|
|
89
|
-
export type ProviderFnsDef<I, SShape extends z.ZodRawShape = EmptyStateShape> = ProviderFnsDefStateless<I> | ProviderFnsDefStateful<I, SShape>;
|
|
90
167
|
export type StoredProviderFns = {
|
|
91
168
|
stateSchema: z.ZodObject<any>;
|
|
92
|
-
pulumi: ProviderPulumiFn<any, any>;
|
|
93
|
-
|
|
94
|
-
|
|
169
|
+
pulumi: ProviderPulumiFn<any, any, any>;
|
|
170
|
+
connect?: ConnectionHandlerEntry<any, any>[];
|
|
171
|
+
deploy?: ProviderDeployFn<any, any>;
|
|
95
172
|
};
|
|
96
173
|
export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
|
|
97
|
-
export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape
|
|
98
|
-
|
|
174
|
+
export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape = EmptyOutputShape, ConnTypes extends Record<string, {
|
|
175
|
+
description: string;
|
|
176
|
+
}> = Record<string, {
|
|
177
|
+
description: string;
|
|
178
|
+
}>> {
|
|
179
|
+
opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>;
|
|
99
180
|
providers: ProviderRegistry;
|
|
100
181
|
validationSchema: z.ZodTypeAny;
|
|
101
182
|
validationDeploymentInputSchema: z.ZodTypeAny;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
183
|
+
private allowedInterfaces;
|
|
184
|
+
constructor(opts: InfraComponentOpts<CShape, DShape, OShape, ConnTypes>);
|
|
185
|
+
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
|
+
/**
|
|
187
|
+
* Get the schema for a specific connection interface.
|
|
188
|
+
* Used by the orchestrator at runtime.
|
|
189
|
+
*/
|
|
190
|
+
getConnectionSchema(interfaceClass: ConnectionInterfaceClass): z.ZodObject<z.ZodRawShape> | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Create the allowConnectionInterfaces function for use in pulumi context.
|
|
193
|
+
* The orchestrator calls this before invoking the pulumi function.
|
|
194
|
+
*
|
|
195
|
+
* @returns Function that validates and stores allowed connection interfaces
|
|
196
|
+
*/
|
|
197
|
+
createAllowConnectionInterfacesFn(): AllowConnectionInterfacesFn;
|
|
198
|
+
/**
|
|
199
|
+
* Get the allowed connection interfaces that were declared via allowConnectionInterfaces.
|
|
200
|
+
* 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
|
+
*/
|
|
204
|
+
getAllowedInterfaces(): Map<ConnectionInterfaceClass, any> | null;
|
|
110
205
|
}
|
|
111
206
|
|
|
112
207
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as
|
|
1
|
+
import{z as x}from"zod";import*as H from"@pulumi/pulumi";var J;((j)=>{j.aws="aws";j.gcloud="gcloud";j.azure="azure";j.linode="linode";j.hetzner="hetzner";j.cloudflare="cloudflare"})(J||={});var W=x.enum(J),L;((g)=>g.container_image="container_image")(L||={});class K{}function X(b){return class extends K{schema=b}}var Y=x.object({});function q(b){if(b instanceof x.ZodObject){let g=b.shape,B={};for(let E in g)B[E]=q(g[E]);return x.object(B)}if(b instanceof x.ZodOptional)return q(b.unwrap()).optional();if(b instanceof x.ZodNullable)return q(b.unwrap()).nullable();if(b instanceof x.ZodArray)return x.array(q(b.element));return x.union([b,x.custom((g)=>H.Output.isInstance(g))])}var N=x.object({metadata:x.object({stateful:x.boolean(),proxiable:x.boolean()}),connectionTypes:x.record(x.string(),x.object({description:x.string().min(5)})),configSchema:x.custom(),deploymentInputSchema:x.custom(),outputSchema:x.custom()}),Q=x.object({});class U{opts;providers;validationSchema;validationDeploymentInputSchema;allowedInterfaces=null;constructor(b){this.opts=N.parse(b),this.providers={},this.validationSchema=q(b.configSchema),this.validationDeploymentInputSchema=q(b.deploymentInputSchema)}implement(b,g){return this.providers[b]={...g,stateSchema:g.stateSchema??Q},this}getConnectionSchema(b){return new b().schema}createAllowConnectionInterfacesFn(){return(b)=>{if(!this.allowedInterfaces)this.allowedInterfaces=new Map;for(let g of b){let F=new g.interface().schema.safeParse(g.data);if(!F.success)throw new Error(`Invalid data for connection interface ${g.interface.name}: ${F.error.message}`);this.allowedInterfaces.set(g.interface,g.data)}}}getAllowedInterfaces(){return this.allowedInterfaces}}export{X as createConnectionInterface,U as InfraComponent,L as DeploymentArtifactType,K as ConnectionInterface,J as CloudProvider};
|