@sdlcworks/components 0.0.19 → 0.0.21

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,12 @@ 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
+ * Can return:
196
+ * - A record mapping component names to their URIs
197
+ * - A single URI string
198
+ * - void if no URIs need to be returned
190
199
  */
191
- export type ConnectionHandlerResult = {
192
- uri?: PulumiOutput<string>;
193
- };
200
+ export type ConnectionHandlerResult = Record<string, PulumiOutput<string>> | PulumiOutput<string> | void;
194
201
  /**
195
202
  * A connection handler entry mapping a ConnectionInterface to its handler function.
196
203
  */
@@ -208,15 +215,44 @@ export declare function connectionHandler<C extends ConnectionInterfaceClass>(en
208
215
  export type ProviderDeployCtx<D, S> = {
209
216
  state: S;
210
217
  } & Record<string, DeploymentInfo>;
218
+ export type ProviderAllocateCtx<S> = {
219
+ name: string;
220
+ deploymentConfig: Record<string, any>;
221
+ state: S;
222
+ $: {
223
+ (name: string, ...values: any[]): string;
224
+ (strings: TemplateStringsArray, ...values: any[]): string;
225
+ };
226
+ };
227
+ export type ProviderDeallocateCtx<S> = {
228
+ name: string;
229
+ deploymentConfig: Record<string, any>;
230
+ state: S;
231
+ $: {
232
+ (name: string, ...values: any[]): string;
233
+ (strings: TemplateStringsArray, ...values: any[]): string;
234
+ };
235
+ };
236
+ export type ProviderUpsertArtifactsCtx<S> = {
237
+ buildArtifacts: Record<string, ArtifactInfo>;
238
+ state: S;
239
+ };
211
240
  export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
212
241
  export type ProviderDeployFn<D, S> = (ctx: ProviderDeployCtx<D, S>) => Promise<void>;
242
+ export type ProviderAllocateFn<S> = (ctx: ProviderAllocateCtx<S>) => Promise<void>;
243
+ export type ProviderDeallocateFn<S> = (ctx: ProviderDeallocateCtx<S>) => Promise<void>;
244
+ export type ProviderUpsertArtifactsFn<S> = (ctx: ProviderUpsertArtifactsCtx<S>) => Promise<void>;
213
245
  declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
214
246
  export type EmptyStateShape = typeof emptyStateSchema.shape;
215
247
  export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateShape, ConnectionType extends string = string> = {
216
248
  stateSchema?: z.ZodObject<SShape>;
249
+ initialState?: z.infer<z.ZodObject<SShape>>;
217
250
  pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
218
251
  connect?: readonly ConnectionHandlerEntry<z.infer<z.ZodObject<SShape>>, ConnectionType, any>[];
219
252
  deploy?: ProviderDeployFn<D, z.infer<z.ZodObject<SShape>>>;
253
+ allocateComponent?: ProviderAllocateFn<z.infer<z.ZodObject<SShape>>>;
254
+ deallocateComponent?: ProviderDeallocateFn<z.infer<z.ZodObject<SShape>>>;
255
+ upsertArtifacts?: ProviderUpsertArtifactsFn<z.infer<z.ZodObject<SShape>>>;
220
256
  };
221
257
  /**
222
258
  * Stored version of ConnectionHandlerEntry that preserves ConnectionInterfaceClass type.
@@ -229,9 +265,13 @@ export type StoredConnectionHandlerEntry = {
229
265
  };
230
266
  export type StoredProviderFns = {
231
267
  stateSchema: z.ZodObject<any>;
268
+ initialState?: any;
232
269
  pulumi: ProviderPulumiFn<any, any, any>;
233
270
  connect?: readonly StoredConnectionHandlerEntry[];
234
271
  deploy?: ProviderDeployFn<any, any>;
272
+ allocateComponent?: ProviderAllocateFn<any>;
273
+ deallocateComponent?: ProviderDeallocateFn<any>;
274
+ upsertArtifacts?: ProviderUpsertArtifactsFn<any>;
235
275
  };
236
276
  export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
237
277
  export type DeclaredConnectionInterfaces = Map<ConnectionInterfaceClass, any>;
package/dist/index.js CHANGED
@@ -1 +1,138 @@
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 transformedSchema = transformSchemaToAcceptOutputs(schema);
116
+ const parseResult = transformedSchema.safeParse(entry.data);
117
+ if (!parseResult.success) {
118
+ throw new Error(`Invalid data for connection interface ${entry.interface.name}: ${parseResult.error.message}`);
119
+ }
120
+ this.declaredConnectionInterfaces.set(entry.interface, entry.data);
121
+ }
122
+ };
123
+ }
124
+ getDeclaredInterfaces() {
125
+ return this.declaredConnectionInterfaces;
126
+ }
127
+ }
128
+ export {
129
+ extendConnectionInterface,
130
+ createConnectionInterface,
131
+ connectionHandler,
132
+ TCPUrlType,
133
+ TCPCI,
134
+ InfraComponent,
135
+ DeploymentArtifactType,
136
+ ConnectionInterface,
137
+ CloudProvider
138
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"