@sdlcworks/components 0.0.2 → 0.0.4

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
@@ -1,6 +1,6 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- import { Output as PulumiOutput } from '@pulumi/pulumi';
3
+ import { Input as PulumiInput, Output as PulumiOutput } from '@pulumi/pulumi';
4
4
  import { z } from 'zod';
5
5
 
6
6
  declare const InfraComponentOutputSchema = z.object({
@@ -36,6 +36,9 @@ export declare class InfraComponent {
36
36
  connect?: ConnectorFn;
37
37
  deploy?: DeployFn;
38
38
  pulumiFns: InfraComponentProviderPulumiFns;
39
+ validationConfigSchema: z.ZodTypeAny;
40
+ validationNetworkInputSchema: z.ZodTypeAny;
41
+ validationDeploymentInputSchema: z.ZodTypeAny;
39
42
  constructor(opts: InfraComponentOpts);
40
43
  onConnect(connectFn: ConnectorFn): void;
41
44
  onDeploy(deployFn: DeployFn): void;
@@ -57,12 +60,15 @@ export type SubnetComponentOutputs = {
57
60
  export type SubnetComponentPulumiFn<I> = PulumiFn<SubnetComponentCtx<I>, SubnetComponentOutputs>;
58
61
  export declare class SubnetComponent<IShape extends z.ZodRawShape> {
59
62
  inputSchema: z.ZodObject<IShape>;
63
+ validationSchema: z.ZodTypeAny;
60
64
  pulumiFns: Partial<Record<CloudProvider, SubnetComponentPulumiFn<InferZodType<IShape>>>>;
61
65
  constructor(opts: SubnetComponentOpts<IShape>);
62
66
  pulumi(provider: CloudProvider, pulumiFn: SubnetComponentPulumiFn<InferZodType<IShape>>): void;
63
67
  }
64
68
  export type SomeComponent = InfraComponent | NetworkComponent<any> | SubnetComponent<any>;
65
- export type InferZodType<S extends z.ZodRawShape> = z.infer<z.ZodObject<S>>;
69
+ export type InferZodType<S extends z.ZodRawShape> = {
70
+ [K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
71
+ };
66
72
  export type DefaultPulumiFnOutputs = Record<string, PulumiOutput<any>>;
67
73
  export declare enum CloudProvider {
68
74
  aws = "aws",
@@ -110,9 +116,10 @@ export type NetworkComponentOutputs = {
110
116
  export type NetworkComponentPulumiFn<I> = PulumiFn<NetworkCtx<I>, NetworkComponentOutputs>;
111
117
  export type NetworkComponentProviderPulumiFns<I> = Partial<Record<CloudProvider, NetworkComponentPulumiFn<I>>>;
112
118
  export declare class NetworkComponent<IShape extends z.ZodRawShape> {
113
- inputSchema: z.ZodObject<IShape>;
119
+ private validationSchema;
114
120
  pulumiFns: NetworkComponentProviderPulumiFns<InferZodType<IShape>>;
115
121
  constructor(opts: NetworkComponentOpts<IShape>);
122
+ validateParseInputs(inputs: any): unknown;
116
123
  pulumi(provider: CloudProvider, pulumiFn: NetworkComponentPulumiFn<InferZodType<IShape>>): void;
117
124
  }
118
125
  export declare function sanitizeForAlphaNum(_name: string, validSpaceRepl: string): string;
package/dist/index.js CHANGED
@@ -1,28 +1,58 @@
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
+
1
28
  // src/network.ts
2
29
  class NetworkComponent {
3
- inputSchema;
30
+ validationSchema;
4
31
  pulumiFns;
5
32
  constructor(opts) {
6
- this.inputSchema = opts.inputSchema;
33
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.inputSchema);
7
34
  this.pulumiFns = {};
8
35
  }
36
+ validateParseInputs(inputs) {
37
+ return this.validationSchema.parse(inputs);
38
+ }
9
39
  pulumi(provider, pulumiFn) {
10
40
  this.pulumiFns[provider] = pulumiFn;
11
41
  }
12
42
  }
13
43
  // src/infra.ts
14
- import { z } from "zod";
15
- var InfraComponentOptsSchema = z.object({
16
- metadata: z.object({
17
- stateful: z.boolean(),
18
- proxiable: z.boolean()
44
+ import { z as z2 } from "zod";
45
+ var InfraComponentOptsSchema = z2.object({
46
+ metadata: z2.object({
47
+ stateful: z2.boolean(),
48
+ proxiable: z2.boolean()
19
49
  }),
20
- connectionTypes: z.record(z.string(), z.object({
21
- description: z.string().min(5)
50
+ connectionTypes: z2.record(z2.string(), z2.object({
51
+ description: z2.string().min(5)
22
52
  })),
23
- configSchema: z.any(),
24
- networkInputSchema: z.any(),
25
- deploymentInputSchema: z.any()
53
+ configSchema: z2.any(),
54
+ networkInputSchema: z2.any(),
55
+ deploymentInputSchema: z2.any()
26
56
  });
27
57
 
28
58
  class InfraComponent {
@@ -30,9 +60,15 @@ class InfraComponent {
30
60
  connect;
31
61
  deploy;
32
62
  pulumiFns;
63
+ validationConfigSchema;
64
+ validationNetworkInputSchema;
65
+ validationDeploymentInputSchema;
33
66
  constructor(opts) {
34
67
  this.opts = InfraComponentOptsSchema.parse(opts);
35
68
  this.pulumiFns = {};
69
+ this.validationConfigSchema = transformSchemaToAcceptOutputs(opts.configSchema);
70
+ this.validationNetworkInputSchema = transformSchemaToAcceptOutputs(opts.networkInputSchema);
71
+ this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
36
72
  }
37
73
  onConnect(connectFn) {
38
74
  this.connect = connectFn;
@@ -62,9 +98,11 @@ var DeploymentArtifactType;
62
98
  // src/subnet.ts
63
99
  class SubnetComponent {
64
100
  inputSchema;
101
+ validationSchema;
65
102
  pulumiFns;
66
103
  constructor(opts) {
67
104
  this.inputSchema = opts.inputSchema;
105
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.inputSchema);
68
106
  this.pulumiFns = {};
69
107
  }
70
108
  pulumi(provider, pulumiFn) {
@@ -95,7 +133,7 @@ function sanitizeForAlphaNum(_name, validSpaceRepl) {
95
133
  }
96
134
  function getComponentInfraID(componentName) {
97
135
  const componentNameRand = sanitizeForAlphaNum(crypto.createHash("sha256").update(`${Date.now()}${Math.random()}`).digest("base64"), "-").slice(0, COMPONENT_NAME_RANDCHARS);
98
- return `${sanitizeForAlphaNum(componentName, "-").slice(COMPONENT_NAME_MAXLEN)}${componentNameRand}`;
136
+ return `${sanitizeForAlphaNum(componentName, "-").slice(0, COMPONENT_NAME_MAXLEN)}${componentNameRand}`;
99
137
  }
100
138
  function generateFullResourceName(componentInfraID, name) {
101
139
  let resourceName = sanitizeForAlphaNum(name, "-").slice(RESOURCE_NAME_MAXLEN);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"