@sdlcworks/components 0.0.5 → 0.0.7

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
@@ -10,70 +10,6 @@ declare const InfraComponentOutputSchema = z.object({
10
10
  resource_urns: z.array(z.string()),
11
11
  });
12
12
  export type InfraComponentOutput = z.infer<typeof InfraComponentOutputSchema>;
13
- export type InfraComponentOpts<CShape extends z.ZodRawShape, NShape extends z.ZodRawShape, DShape extends z.ZodRawShape> = {
14
- metadata: {
15
- stateful: boolean;
16
- proxiable: boolean;
17
- };
18
- connectionTypes: Record<string, {
19
- description: string;
20
- }>;
21
- configSchema: z.ZodObject<CShape>;
22
- networkInputSchema: z.ZodObject<NShape>;
23
- deploymentInputSchema: z.ZodObject<DShape>;
24
- };
25
- export interface InfraComponentCtx<T = undefined> extends CommonPulumiFnInputs {
26
- inputs: T;
27
- }
28
- export type InfraComponentInputs<C, N, D> = {
29
- config: C;
30
- networkInput: N;
31
- deploymentInput: D;
32
- };
33
- export type InfraComponentOutputs = {
34
- [key: string]: PulumiOutput<any>;
35
- };
36
- export type InfraComponentPulumiFn<I> = PulumiFn<InfraComponentCtx<I>, InfraComponentOutputs>;
37
- export type InfraComponentProviderPulumiFns<I> = Partial<Record<string, InfraComponentPulumiFn<I>>>;
38
- export declare class InfraComponent<CShape extends z.ZodRawShape, NShape extends z.ZodRawShape, DShape extends z.ZodRawShape> {
39
- opts: InfraComponentOpts<CShape, NShape, DShape>;
40
- connect?: ConnectorFn;
41
- deploy?: DeployFn;
42
- pulumiFns: InfraComponentProviderPulumiFns<InfraComponentInputs<InferZodType<CShape>, InferZodType<NShape>, InferZodType<DShape>>>;
43
- validationSchema: z.ZodTypeAny;
44
- validationNetworkInputSchema: z.ZodTypeAny;
45
- validationDeploymentInputSchema: z.ZodTypeAny;
46
- constructor(opts: InfraComponentOpts<CShape, NShape, DShape>);
47
- onConnect(connectFn: ConnectorFn): void;
48
- onDeploy(deployFn: DeployFn): void;
49
- pulumi(provider: CloudProvider, pulumiFn: InfraComponentPulumiFn<InfraComponentInputs<InferZodType<CShape>, InferZodType<NShape>, InferZodType<DShape>>>): void;
50
- }
51
- export type SubnetComponentOpts<IShape extends z.ZodRawShape> = {
52
- inputSchema: z.ZodObject<IShape>;
53
- };
54
- export interface SubnetComponentCtx<T = undefined> extends CommonPulumiFnInputs {
55
- inputs: T;
56
- }
57
- export type SubnetComponentOutputs = {
58
- id: PulumiOutput<string>;
59
- region: PulumiOutput<string>;
60
- cidr?: PulumiOutput<string>;
61
- zone?: PulumiOutput<string>;
62
- [key: string]: any;
63
- };
64
- export type SubnetComponentPulumiFn<I> = PulumiFn<SubnetComponentCtx<I>, SubnetComponentOutputs>;
65
- export declare class SubnetComponent<IShape extends z.ZodRawShape> {
66
- inputSchema: z.ZodObject<IShape>;
67
- validationSchema: z.ZodTypeAny;
68
- pulumiFns: Partial<Record<CloudProvider, SubnetComponentPulumiFn<InferZodType<IShape>>>>;
69
- constructor(opts: SubnetComponentOpts<IShape>);
70
- pulumi(provider: CloudProvider, pulumiFn: SubnetComponentPulumiFn<InferZodType<IShape>>): void;
71
- }
72
- export type SomeComponent = InfraComponent<any, any, any> | NetworkComponent<any> | SubnetComponent<any>;
73
- export type InferZodType<S extends z.ZodRawShape> = {
74
- [K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
75
- };
76
- export type DefaultPulumiFnOutputs = Record<string, PulumiOutput<any>>;
77
13
  export declare enum CloudProvider {
78
14
  aws = "aws",
79
15
  gcloud = "gcloud",
@@ -101,30 +37,76 @@ export type CommonDeployFnInputs<T = undefined> = Record<string, {
101
37
  type: DeploymentArtifactType;
102
38
  };
103
39
  }>;
104
- export type ConnectorFn = (ctx: any) => Promise<void>;
105
- export type DeployFn<T = CommonDeployFnInputs> = (ctx: T) => Promise<void>;
106
- export type PulumiFn<T = CommonPulumiFnInputs, R = any> = (ctx: T) => Promise<R>;
107
- export type ProviderPulumiFns<Ctx = undefined, R = any> = Partial<Record<CloudProvider, PulumiFn<Ctx, R>>>;
108
- export type NetworkComponentOpts<IShape extends z.ZodRawShape> = {
109
- inputSchema: z.ZodObject<IShape>;
40
+ export type InferZodType<S extends z.ZodRawShape> = {
41
+ [K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
110
42
  };
111
- export interface NetworkCtx<T = undefined> extends CommonPulumiFnInputs {
112
- inputs: T;
113
- }
114
- export type NetworkComponentOutputs = {
115
- id: PulumiOutput<string>;
116
- region?: PulumiOutput<string>;
117
- cidr?: PulumiOutput<string>;
118
- [key: string]: any;
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
+ }>;
52
+ configSchema: z.ZodObject<CShape>;
53
+ deploymentInputSchema: z.ZodObject<DShape>;
119
54
  };
120
- export type NetworkComponentPulumiFn<I> = PulumiFn<NetworkCtx<I>, NetworkComponentOutputs>;
121
- export type NetworkComponentProviderPulumiFns<I> = Partial<Record<CloudProvider, NetworkComponentPulumiFn<I>>>;
122
- export declare class NetworkComponent<IShape extends z.ZodRawShape> {
123
- private validationSchema;
124
- pulumiFns: NetworkComponentProviderPulumiFns<InferZodType<IShape>>;
125
- constructor(opts: NetworkComponentOpts<IShape>);
126
- validateParseInputs(inputs: any): unknown;
127
- pulumi(provider: CloudProvider, pulumiFn: NetworkComponentPulumiFn<InferZodType<IShape>>): void;
55
+ export type InfraComponentInputs<C, D> = {
56
+ config: C;
57
+ deploymentInput: D;
58
+ };
59
+ export type InfraComponentOutputs = {
60
+ [key: string]: PulumiOutput<any>;
61
+ };
62
+ export type ProviderPulumiCtx<I, S> = CommonPulumiFnInputs & {
63
+ inputs: I;
64
+ state: S;
65
+ };
66
+ export type ProviderConnectCtx<S> = {
67
+ state: S;
68
+ };
69
+ export type ProviderDeployCtx<S> = CommonDeployFnInputs & {
70
+ state: S;
71
+ };
72
+ export type ProviderPulumiFn<I, S> = (ctx: ProviderPulumiCtx<I, S>) => Promise<InfraComponentOutputs>;
73
+ export type ProviderConnectFn<S> = (ctx: ProviderConnectCtx<S>) => Promise<void>;
74
+ export type ProviderDeployFn<S> = (ctx: ProviderDeployCtx<S>) => Promise<void>;
75
+ declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
76
+ export type EmptyStateShape = typeof emptyStateSchema.shape;
77
+ export type ProviderFnsDefStateless<I> = {
78
+ stateSchema?: never;
79
+ pulumi: ProviderPulumiFn<I, Record<string, never>>;
80
+ onConnect?: ProviderConnectFn<Record<string, never>>;
81
+ onDeploy?: ProviderDeployFn<Record<string, never>>;
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>>>;
88
+ };
89
+ export type ProviderFnsDef<I, SShape extends z.ZodRawShape = EmptyStateShape> = ProviderFnsDefStateless<I> | ProviderFnsDefStateful<I, SShape>;
90
+ export type StoredProviderFns = {
91
+ stateSchema: z.ZodObject<any>;
92
+ pulumi: ProviderPulumiFn<any, any>;
93
+ onConnect?: ProviderConnectFn<any>;
94
+ onDeploy?: ProviderDeployFn<any>;
95
+ };
96
+ 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>;
99
+ providers: ProviderRegistry;
100
+ validationSchema: z.ZodTypeAny;
101
+ 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;
128
110
  }
129
111
 
130
112
  export {};
package/dist/index.js CHANGED
@@ -1,118 +1 @@
1
- // src/schema.ts
2
- import { z } from "zod";
3
- import * as pulumi from "@pulumi/pulumi";
4
- function transformSchemaToAcceptOutputs(schema) {
5
- if (schema instanceof z.ZodObject) {
6
- const shape = schema.shape;
7
- const newShape = {};
8
- for (const key in shape) {
9
- newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
10
- }
11
- return z.object(newShape);
12
- }
13
- if (schema instanceof z.ZodOptional) {
14
- return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
15
- }
16
- if (schema instanceof z.ZodNullable) {
17
- return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
18
- }
19
- if (schema instanceof z.ZodArray) {
20
- return z.array(transformSchemaToAcceptOutputs(schema.element));
21
- }
22
- return z.union([
23
- schema,
24
- z.custom((val) => pulumi.Output.isInstance(val))
25
- ]);
26
- }
27
-
28
- // src/network.ts
29
- class NetworkComponent {
30
- validationSchema;
31
- pulumiFns;
32
- constructor(opts) {
33
- this.validationSchema = transformSchemaToAcceptOutputs(opts.inputSchema);
34
- this.pulumiFns = {};
35
- }
36
- validateParseInputs(inputs) {
37
- return this.validationSchema.parse(inputs);
38
- }
39
- pulumi(provider, pulumiFn) {
40
- this.pulumiFns[provider] = pulumiFn;
41
- }
42
- }
43
- // src/infra.ts
44
- import { z as z2 } from "zod";
45
- var InfraComponentOptsSchema = z2.object({
46
- metadata: z2.object({
47
- stateful: z2.boolean(),
48
- proxiable: z2.boolean()
49
- }),
50
- connectionTypes: z2.record(z2.string(), z2.object({
51
- description: z2.string().min(5)
52
- })),
53
- configSchema: z2.any(),
54
- networkInputSchema: z2.any(),
55
- deploymentInputSchema: z2.any()
56
- });
57
-
58
- class InfraComponent {
59
- opts;
60
- connect;
61
- deploy;
62
- pulumiFns;
63
- validationSchema;
64
- validationNetworkInputSchema;
65
- validationDeploymentInputSchema;
66
- constructor(opts) {
67
- this.opts = InfraComponentOptsSchema.parse(opts);
68
- this.pulumiFns = {};
69
- this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
70
- this.validationNetworkInputSchema = transformSchemaToAcceptOutputs(opts.networkInputSchema);
71
- this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
72
- }
73
- onConnect(connectFn) {
74
- this.connect = connectFn;
75
- }
76
- onDeploy(deployFn) {
77
- this.deploy = deployFn;
78
- }
79
- pulumi(provider, pulumiFn) {
80
- this.pulumiFns[provider] = pulumiFn;
81
- }
82
- }
83
- // src/types.ts
84
- var CloudProvider;
85
- ((CloudProvider2) => {
86
- CloudProvider2["aws"] = "aws";
87
- CloudProvider2["gcloud"] = "gcloud";
88
- CloudProvider2["azure"] = "azure";
89
- CloudProvider2["linode"] = "linode";
90
- CloudProvider2["hetzner"] = "hetzner";
91
- CloudProvider2["cloudflare"] = "cloudflare";
92
- })(CloudProvider ||= {});
93
- var DeploymentArtifactType;
94
- ((DeploymentArtifactType2) => {
95
- DeploymentArtifactType2["container_image"] = "container_image";
96
- DeploymentArtifactType2["local_file"] = "local_file";
97
- })(DeploymentArtifactType ||= {});
98
- // src/subnet.ts
99
- class SubnetComponent {
100
- inputSchema;
101
- validationSchema;
102
- pulumiFns;
103
- constructor(opts) {
104
- this.inputSchema = opts.inputSchema;
105
- this.validationSchema = transformSchemaToAcceptOutputs(opts.inputSchema);
106
- this.pulumiFns = {};
107
- }
108
- pulumi(provider, pulumiFn) {
109
- this.pulumiFns[provider] = pulumiFn;
110
- }
111
- }
112
- export {
113
- SubnetComponent,
114
- NetworkComponent,
115
- InfraComponent,
116
- DeploymentArtifactType,
117
- CloudProvider
118
- };
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"