@sdlcworks/components 0.0.19 → 0.0.20

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 CHANGED
@@ -156,6 +156,12 @@ export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.Zo
156
156
  connectionTypes: ConnTypes;
157
157
  };
158
158
  export type InfraComponentInputs<C> = C;
159
+ export type ArtifactInfo = {
160
+ artifact: {
161
+ uri: string;
162
+ type: DeploymentArtifactType;
163
+ };
164
+ };
159
165
  export type DeploymentInfo = {
160
166
  config: Record<string, any>;
161
167
  artifact: {
@@ -172,7 +178,7 @@ export type ProviderPulumiCtx<I, S> = {
172
178
  inputs: I;
173
179
  state: S;
174
180
  declareConnectionInterfaces: DeclareConnectionInterfacesFn;
175
- buildArtifacts: Record<string, DeploymentInfo>;
181
+ buildArtifacts: Record<string, ArtifactInfo>;
176
182
  };
177
183
  /**
178
184
  * Context passed to connection handlers.
@@ -186,11 +192,9 @@ export type ConnectionHandlerCtx<S, ConnectorData, ConnectionType extends string
186
192
  };
187
193
  /**
188
194
  * Result returned by connection handlers.
189
- * Handlers can optionally return a URI for the connection.
195
+ * Maps component names to their URIs, or void if no URIs need to be returned.
190
196
  */
191
- export type ConnectionHandlerResult = {
192
- uri?: PulumiOutput<string>;
193
- };
197
+ export type ConnectionHandlerResult = Record<string, PulumiOutput<string>> | void;
194
198
  /**
195
199
  * A connection handler entry mapping a ConnectionInterface to its handler function.
196
200
  */
@@ -208,15 +212,44 @@ export declare function connectionHandler<C extends ConnectionInterfaceClass>(en
208
212
  export type ProviderDeployCtx<D, S> = {
209
213
  state: S;
210
214
  } & Record<string, DeploymentInfo>;
215
+ export type ProviderAllocateCtx<S> = {
216
+ name: string;
217
+ deploymentConfig: Record<string, any>;
218
+ state: S;
219
+ $: {
220
+ (name: string, ...values: any[]): string;
221
+ (strings: TemplateStringsArray, ...values: any[]): string;
222
+ };
223
+ };
224
+ export type ProviderDeallocateCtx<S> = {
225
+ name: string;
226
+ deploymentConfig: Record<string, any>;
227
+ state: S;
228
+ $: {
229
+ (name: string, ...values: any[]): string;
230
+ (strings: TemplateStringsArray, ...values: any[]): string;
231
+ };
232
+ };
233
+ export type ProviderUpsertArtifactsCtx<S> = {
234
+ buildArtifacts: Record<string, ArtifactInfo>;
235
+ state: S;
236
+ };
211
237
  export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
212
238
  export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
239
+ export type ProviderAllocateFn<S> = (ctx: ProviderAllocateCtx<S>) => Promise<void>;
240
+ export type ProviderDeallocateFn<S> = (ctx: ProviderDeallocateCtx<S>) => Promise<void>;
241
+ export type ProviderUpsertArtifactsFn<S> = (ctx: ProviderUpsertArtifactsCtx<S>) => Promise<void>;
213
242
  declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
214
243
  export type EmptyStateShape = typeof emptyStateSchema.shape;
215
244
  export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
216
245
  stateSchema?: z.ZodObject<SShape>;
246
+ initialState?: z.infer<z.ZodObject<SShape>>;
217
247
  pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
218
248
  connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, any>[];
219
249
  deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
250
+ allocateComponent?: ProviderAllocateFn<z.infer<z.ZodObject<SShape>>>;
251
+ deallocateComponent?: ProviderDeallocateFn<z.infer<z.ZodObject<SShape>>>;
252
+ upsertArtifacts?: ProviderUpsertArtifactsFn<z.infer<z.ZodObject<SShape>>>;
220
253
  };
221
254
  /**
222
255
  * Stored version of ConnectionHandlerEntry that preserves ConnectionInterfaceClass type.
@@ -229,9 +262,13 @@ export type StoredConnectionHandlerEntry = {
229
262
  };
230
263
  export type StoredProviderFns = {
231
264
  stateSchema: z.ZodObject<any>;
265
+ initialState?: any;
232
266
  pulumi: ProviderPulumiFn<any, any, any>;
233
267
  connect?: readonly StoredConnectionHandlerEntry[];
234
268
  deploy?: ProviderDeployFn<any, any>;
269
+ allocateComponent?: ProviderAllocateFn<any>;
270
+ deallocateComponent?: ProviderDeallocateFn<any>;
271
+ upsertArtifacts?: ProviderUpsertArtifactsFn<any>;
235
272
  };
236
273
  export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
237
274
  export type DeclaredConnectionInterfaces = Map<ConnectionInterfaceClass, any>;
package/dist/index.js CHANGED
@@ -1 +1,137 @@
1
- import{z as x}from"zod";import*as K from"@pulumi/pulumi";var M;((B)=>{B.aws="aws";B.gcloud="gcloud";B.azure="azure";B.linode="linode";B.hetzner="hetzner";B.cloudflare="cloudflare"})(M||={});var L;((q)=>{q.ipv4="ipv4";q.ipv6="ipv6";q.domain="domain"})(L||={});var N;((j)=>j.container_image="container_image")(N||={});class H{}function Q(b){return class extends H{schema=b}}function Z(b,j){let q=new b().schema.merge(j);return class extends H{schema=q}}var _=Q(x.object({url:x.object({type:x.nativeEnum(L),value:x.string()}),publicAccess:x.boolean()})),$=x.object({});function E(b){if(b instanceof x.ZodObject){let j=b.shape,F={};for(let q in j)F[q]=E(j[q]);return x.object(F)}if(b instanceof x.ZodOptional)return E(b.unwrap()).optional();if(b instanceof x.ZodNullable)return E(b.unwrap()).nullable();if(b instanceof x.ZodArray)return x.array(E(b.element));return x.union([b,x.custom((j)=>K.Output.isInstance(j))])}var V=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()});function g(b){return b}var W=x.object({});class X{opts;providers;validationSchema;validationDeploymentInputSchema;declaredConnectionInterfaces=new Map;constructor(b){this.opts=V.parse(b),this.providers={},this.validationSchema=E(b.configSchema),this.validationDeploymentInputSchema=E(b.deploymentInputSchema)}implement(b,j){return this.providers[b]={...j,stateSchema:j.stateSchema??W},this}getConnectionSchema(b){return new b().schema}createDeclareConnectionInterfacesFn(){return(b)=>{for(let j of b){let J=new j.interface().schema.safeParse(j.data);if(!J.success)throw new Error(`Invalid data for connection interface ${j.interface.name}: ${J.error.message}`);this.declaredConnectionInterfaces.set(j.interface,j.data)}}}getDeclaredInterfaces(){return this.declaredConnectionInterfaces}}export{Z as extendConnectionInterface,Q as createConnectionInterface,g as connectionHandler,L as TCPUrlType,_ as TCPCI,X as InfraComponent,N as DeploymentArtifactType,H as ConnectionInterface,M as CloudProvider};
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 TCPUrlType;
14
+ ((TCPUrlType2) => {
15
+ TCPUrlType2["ipv4"] = "ipv4";
16
+ TCPUrlType2["ipv6"] = "ipv6";
17
+ TCPUrlType2["domain"] = "domain";
18
+ })(TCPUrlType ||= {});
19
+ var DeploymentArtifactType;
20
+ ((DeploymentArtifactType2) => {
21
+ DeploymentArtifactType2["container_image"] = "container_image";
22
+ })(DeploymentArtifactType ||= {});
23
+
24
+ class ConnectionInterface {
25
+ }
26
+ function createConnectionInterface(schema) {
27
+ return class extends ConnectionInterface {
28
+ schema = schema;
29
+ };
30
+ }
31
+ function extendConnectionInterface(parentClass, additionalSchema) {
32
+ const parentInstance = new parentClass;
33
+ const mergedSchema = parentInstance.schema.merge(additionalSchema);
34
+ return class extends ConnectionInterface {
35
+ schema = mergedSchema;
36
+ };
37
+ }
38
+ var TCPCI = createConnectionInterface(z.object({
39
+ url: z.object({
40
+ type: z.nativeEnum(TCPUrlType),
41
+ value: z.string()
42
+ }),
43
+ publicAccess: z.boolean()
44
+ }));
45
+ var emptyOutputSchema = z.object({});
46
+ function transformSchemaToAcceptOutputs(schema) {
47
+ if (schema instanceof z.ZodObject) {
48
+ const shape = schema.shape;
49
+ const newShape = {};
50
+ for (const key in shape) {
51
+ newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
52
+ }
53
+ return z.object(newShape);
54
+ }
55
+ if (schema instanceof z.ZodOptional) {
56
+ return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
57
+ }
58
+ if (schema instanceof z.ZodNullable) {
59
+ return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
60
+ }
61
+ if (schema instanceof z.ZodArray) {
62
+ return z.array(transformSchemaToAcceptOutputs(schema.element));
63
+ }
64
+ return z.union([
65
+ schema,
66
+ z.custom((val) => pulumi.Output.isInstance(val))
67
+ ]);
68
+ }
69
+ var InfraComponentOptsSchema = z.object({
70
+ metadata: z.object({
71
+ stateful: z.boolean(),
72
+ proxiable: z.boolean()
73
+ }),
74
+ connectionTypes: z.record(z.string(), z.object({
75
+ description: z.string().min(5)
76
+ })),
77
+ configSchema: z.custom(),
78
+ deploymentInputSchema: z.custom(),
79
+ outputSchema: z.custom()
80
+ });
81
+ function connectionHandler(entry) {
82
+ return entry;
83
+ }
84
+ var emptyStateSchema = z.object({});
85
+
86
+ class InfraComponent {
87
+ opts;
88
+ providers;
89
+ validationSchema;
90
+ validationDeploymentInputSchema;
91
+ declaredConnectionInterfaces = new Map;
92
+ constructor(opts) {
93
+ this.opts = InfraComponentOptsSchema.parse(opts);
94
+ this.providers = {};
95
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
96
+ this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
97
+ }
98
+ implement(provider, fns) {
99
+ this.providers[provider] = {
100
+ ...fns,
101
+ stateSchema: fns.stateSchema ?? emptyStateSchema,
102
+ initialState: fns.initialState
103
+ };
104
+ return this;
105
+ }
106
+ getConnectionSchema(interfaceClass) {
107
+ const instance = new interfaceClass;
108
+ return instance.schema;
109
+ }
110
+ createDeclareConnectionInterfacesFn() {
111
+ return (entries) => {
112
+ for (const entry of entries) {
113
+ const instance = new entry.interface;
114
+ const schema = instance.schema;
115
+ const parseResult = schema.safeParse(entry.data);
116
+ if (!parseResult.success) {
117
+ throw new Error(`Invalid data for connection interface ${entry.interface.name}: ${parseResult.error.message}`);
118
+ }
119
+ this.declaredConnectionInterfaces.set(entry.interface, entry.data);
120
+ }
121
+ };
122
+ }
123
+ getDeclaredInterfaces() {
124
+ return this.declaredConnectionInterfaces;
125
+ }
126
+ }
127
+ export {
128
+ extendConnectionInterface,
129
+ createConnectionInterface,
130
+ connectionHandler,
131
+ TCPUrlType,
132
+ TCPCI,
133
+ InfraComponent,
134
+ DeploymentArtifactType,
135
+ ConnectionInterface,
136
+ CloudProvider
137
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"