@sdlcworks/components 0.0.7 → 0.0.8

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
@@ -40,25 +40,45 @@ export type CommonDeployFnInputs<T = undefined> = Record<string, {
40
40
  export type InferZodType<S extends z.ZodRawShape> = {
41
41
  [K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
42
42
  };
43
- export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape> = {
44
- metadata: {
45
- stateful: boolean;
46
- proxiable: boolean;
47
- require_connector_same_provider: boolean;
48
- };
49
- connectionTypes: Record<string, {
50
- description: string;
51
- }>;
43
+ export type InferOutputType<OShape extends z.ZodRawShape> = {
44
+ [K in keyof z.infer<z.ZodObject<OShape>>]: PulumiOutput<z.infer<z.ZodObject<OShape>>[K]>;
45
+ };
46
+ declare const emptyOutputSchema: z.ZodObject<{}, z.core.$strip>;
47
+ export type EmptyOutputShape = typeof emptyOutputSchema.shape;
48
+ declare const InfraComponentOptsSchema: z.ZodObject<{
49
+ metadata: z.ZodObject<{
50
+ stateful: z.ZodBoolean;
51
+ proxiable: z.ZodBoolean;
52
+ }, z.core.$strip>;
53
+ connectionTypes: z.ZodRecord<z.ZodString, z.ZodObject<{
54
+ description: z.ZodString;
55
+ }, z.core.$strip>>;
56
+ configSchema: z.ZodCustom<z.ZodObject<Readonly<{
57
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
58
+ }>, z.core.$strip>, z.ZodObject<Readonly<{
59
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
60
+ }>, z.core.$strip>>;
61
+ deploymentInputSchema: z.ZodCustom<z.ZodObject<Readonly<{
62
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
63
+ }>, z.core.$strip>, z.ZodObject<Readonly<{
64
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
65
+ }>, z.core.$strip>>;
66
+ outputSchema: z.ZodCustom<z.ZodObject<Readonly<{
67
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
68
+ }>, z.core.$strip>, z.ZodObject<Readonly<{
69
+ [k: string]: z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
70
+ }>, z.core.$strip>>;
71
+ }, z.core.$strip>;
72
+ export type InfraComponentOptsBase = z.infer<typeof InfraComponentOptsSchema>;
73
+ export type InfraComponentOpts<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape> = Omit<InfraComponentOptsBase, "configSchema" | "deploymentInputSchema" | "outputSchema"> & {
52
74
  configSchema: z.ZodObject<CShape>;
53
75
  deploymentInputSchema: z.ZodObject<DShape>;
76
+ outputSchema: z.ZodObject<OShape>;
54
77
  };
55
78
  export type InfraComponentInputs<C, D> = {
56
79
  config: C;
57
80
  deploymentInput: D;
58
81
  };
59
- export type InfraComponentOutputs = {
60
- [key: string]: PulumiOutput<any>;
61
- };
62
82
  export type ProviderPulumiCtx<I, S> = CommonPulumiFnInputs & {
63
83
  inputs: I;
64
84
  state: S;
@@ -69,44 +89,38 @@ export type ProviderConnectCtx<S> = {
69
89
  export type ProviderDeployCtx<S> = CommonDeployFnInputs & {
70
90
  state: S;
71
91
  };
72
- export type ProviderPulumiFn<I, S> = (ctx: ProviderPulumiCtx<I, S>) => Promise<InfraComponentOutputs>;
92
+ export type ProviderPulumiFn<I, S, O> = (ctx: ProviderPulumiCtx<I, S>) => Promise<O>;
73
93
  export type ProviderConnectFn<S> = (ctx: ProviderConnectCtx<S>) => Promise<void>;
74
94
  export type ProviderDeployFn<S> = (ctx: ProviderDeployCtx<S>) => Promise<void>;
75
95
  declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
76
96
  export type EmptyStateShape = typeof emptyStateSchema.shape;
77
- export type ProviderFnsDefStateless<I> = {
97
+ export type ProviderFnsDefStateless<I, O> = {
78
98
  stateSchema?: never;
79
- pulumi: ProviderPulumiFn<I, Record<string, never>>;
99
+ pulumi: ProviderPulumiFn<I, Record<string, never>, O>;
80
100
  onConnect?: ProviderConnectFn<Record<string, never>>;
81
101
  onDeploy?: ProviderDeployFn<Record<string, never>>;
82
102
  };
83
- export type ProviderFnsDefStateful<I, SShape extends z.ZodRawShape> = {
103
+ export type ProviderFnsDefStateful<I, O, SShape extends z.ZodRawShape> = {
84
104
  stateSchema: z.ZodObject<SShape>;
85
- pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>>;
105
+ pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>, O>;
86
106
  onConnect?: ProviderConnectFn<z.infer<z.ZodObject<SShape>>>;
87
107
  onDeploy?: ProviderDeployFn<z.infer<z.ZodObject<SShape>>>;
88
108
  };
89
- export type ProviderFnsDef<I, SShape extends z.ZodRawShape = EmptyStateShape> = ProviderFnsDefStateless<I> | ProviderFnsDefStateful<I, SShape>;
109
+ export type ProviderFnsDef<I, O, SShape extends z.ZodRawShape = EmptyStateShape> = ProviderFnsDefStateless<I, O> | ProviderFnsDefStateful<I, O, SShape>;
90
110
  export type StoredProviderFns = {
91
111
  stateSchema: z.ZodObject<any>;
92
- pulumi: ProviderPulumiFn<any, any>;
112
+ pulumi: ProviderPulumiFn<any, any, any>;
93
113
  onConnect?: ProviderConnectFn<any>;
94
114
  onDeploy?: ProviderDeployFn<any>;
95
115
  };
96
116
  export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
97
- export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape> {
98
- opts: InfraComponentOpts<CShape, DShape>;
117
+ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape, OShape extends z.ZodRawShape = EmptyOutputShape> {
118
+ opts: InfraComponentOpts<CShape, DShape, OShape>;
99
119
  providers: ProviderRegistry;
100
120
  validationSchema: z.ZodTypeAny;
101
121
  validationDeploymentInputSchema: z.ZodTypeAny;
102
- constructor(opts: InfraComponentOpts<CShape, DShape>);
103
- private register;
104
- aws<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
105
- gcloud<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
106
- azure<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
107
- linode<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
108
- hetzner<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
109
- cloudflare<SShape extends z.ZodRawShape = EmptyStateShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
122
+ constructor(opts: InfraComponentOpts<CShape, DShape, OShape>);
123
+ implement<SShape extends z.ZodRawShape = EmptyStateShape>(provider: CloudProvider, fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, InferOutputType<OShape>, SShape>): this;
110
124
  }
111
125
 
112
126
  export {};
package/dist/index.js CHANGED
@@ -1 +1,80 @@
1
- import{z as q}from"zod";import*as H from"@pulumi/pulumi";var J;((B)=>{B.aws="aws";B.gcloud="gcloud";B.azure="azure";B.linode="linode";B.hetzner="hetzner";B.cloudflare="cloudflare"})(J||={});var K;((F)=>{F.container_image="container_image";F.local_file="local_file"})(K||={});function E(j){if(j instanceof q.ZodObject){let x=j.shape,F={};for(let G in x)F[G]=E(x[G]);return q.object(F)}if(j instanceof q.ZodOptional)return E(j.unwrap()).optional();if(j instanceof q.ZodNullable)return E(j.unwrap()).nullable();if(j instanceof q.ZodArray)return q.array(E(j.element));return q.union([j,q.custom((x)=>H.Output.isInstance(x))])}var L=q.object({metadata:q.object({stateful:q.boolean(),proxiable:q.boolean(),require_connector_same_provider:q.boolean()}),connectionTypes:q.record(q.string(),q.object({description:q.string().min(5)})),configSchema:q.any(),deploymentInputSchema:q.any()}),M=q.object({});class N{opts;providers;validationSchema;validationDeploymentInputSchema;constructor(j){this.opts=L.parse(j),this.providers={},this.validationSchema=E(j.configSchema),this.validationDeploymentInputSchema=E(j.deploymentInputSchema)}register(j,x){this.providers[j]={...x,stateSchema:x.stateSchema??M}}aws(j){this.register("aws",j)}gcloud(j){this.register("gcloud",j)}azure(j){this.register("azure",j)}linode(j){this.register("linode",j)}hetzner(j){this.register("hetzner",j)}cloudflare(j){this.register("cloudflare",j)}}export{N as InfraComponent,K as DeploymentArtifactType,J 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 CloudProviderSchema = z.enum(CloudProvider);
14
+ var DeploymentArtifactType;
15
+ ((DeploymentArtifactType2) => {
16
+ DeploymentArtifactType2["container_image"] = "container_image";
17
+ DeploymentArtifactType2["local_file"] = "local_file";
18
+ })(DeploymentArtifactType ||= {});
19
+ var emptyOutputSchema = z.object({});
20
+ function transformSchemaToAcceptOutputs(schema) {
21
+ if (schema instanceof z.ZodObject) {
22
+ const shape = schema.shape;
23
+ const newShape = {};
24
+ for (const key in shape) {
25
+ newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
26
+ }
27
+ return z.object(newShape);
28
+ }
29
+ if (schema instanceof z.ZodOptional) {
30
+ return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
31
+ }
32
+ if (schema instanceof z.ZodNullable) {
33
+ return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
34
+ }
35
+ if (schema instanceof z.ZodArray) {
36
+ return z.array(transformSchemaToAcceptOutputs(schema.element));
37
+ }
38
+ return z.union([
39
+ schema,
40
+ z.custom((val) => pulumi.Output.isInstance(val))
41
+ ]);
42
+ }
43
+ var InfraComponentOptsSchema = z.object({
44
+ metadata: z.object({
45
+ stateful: z.boolean(),
46
+ proxiable: z.boolean()
47
+ }),
48
+ connectionTypes: z.record(z.string(), z.object({
49
+ description: z.string().min(5)
50
+ })),
51
+ configSchema: z.custom(),
52
+ deploymentInputSchema: z.custom(),
53
+ outputSchema: z.custom()
54
+ });
55
+ var emptyStateSchema = z.object({});
56
+
57
+ class InfraComponent {
58
+ opts;
59
+ providers;
60
+ validationSchema;
61
+ validationDeploymentInputSchema;
62
+ constructor(opts) {
63
+ this.opts = InfraComponentOptsSchema.parse(opts);
64
+ this.providers = {};
65
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
66
+ this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
67
+ }
68
+ implement(provider, fns) {
69
+ this.providers[provider] = {
70
+ ...fns,
71
+ stateSchema: fns.stateSchema ?? emptyStateSchema
72
+ };
73
+ return this;
74
+ }
75
+ }
76
+ export {
77
+ InfraComponent,
78
+ DeploymentArtifactType,
79
+ CloudProvider
80
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"