@sdlcworks/components 0.0.1 → 0.0.3
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 +10 -3
- package/dist/index.js +152 -1
- package/package.json +1 -1
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> =
|
|
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
|
-
|
|
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 +1,152 @@
|
|
|
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
|
+
validationConfigSchema;
|
|
64
|
+
validationNetworkInputSchema;
|
|
65
|
+
validationDeploymentInputSchema;
|
|
66
|
+
constructor(opts) {
|
|
67
|
+
this.opts = InfraComponentOptsSchema.parse(opts);
|
|
68
|
+
this.pulumiFns = {};
|
|
69
|
+
this.validationConfigSchema = 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
|
+
// src/names.ts
|
|
113
|
+
import crypto from "crypto";
|
|
114
|
+
var COMPONENT_NAME_MAXLEN = 10;
|
|
115
|
+
var COMPONENT_NAME_RANDCHARS = 2;
|
|
116
|
+
var RESOURCE_NAME_MAXLEN = 10;
|
|
117
|
+
var RESOURCE_NAME_HASHCHARS = 2;
|
|
118
|
+
function escapeRegExp(str) {
|
|
119
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
120
|
+
}
|
|
121
|
+
function sanitizeForAlphaNum(_name, validSpaceRepl) {
|
|
122
|
+
let name = _name;
|
|
123
|
+
name = name.replace(/\s+/g, " ");
|
|
124
|
+
name = name.split(" ").join(validSpaceRepl);
|
|
125
|
+
const escapedRepl = escapeRegExp(validSpaceRepl);
|
|
126
|
+
const collapseRegex = new RegExp(`${escapedRepl}+`, "g");
|
|
127
|
+
name = name.replace(collapseRegex, validSpaceRepl);
|
|
128
|
+
const trimRegex = new RegExp(`^${escapedRepl}+|${escapedRepl}+$`, "g");
|
|
129
|
+
name = name.replace(trimRegex, "");
|
|
130
|
+
name = name.toLowerCase();
|
|
131
|
+
name = name.replace(/[^a-z0-9\-]/g, "");
|
|
132
|
+
return name;
|
|
133
|
+
}
|
|
134
|
+
function getComponentInfraID(componentName) {
|
|
135
|
+
const componentNameRand = sanitizeForAlphaNum(crypto.createHash("sha256").update(`${Date.now()}${Math.random()}`).digest("base64"), "-").slice(0, COMPONENT_NAME_RANDCHARS);
|
|
136
|
+
return `${sanitizeForAlphaNum(componentName, "-").slice(COMPONENT_NAME_MAXLEN)}${componentNameRand}`;
|
|
137
|
+
}
|
|
138
|
+
function generateFullResourceName(componentInfraID, name) {
|
|
139
|
+
let resourceName = sanitizeForAlphaNum(name, "-").slice(RESOURCE_NAME_MAXLEN);
|
|
140
|
+
resourceName = sanitizeForAlphaNum(crypto.createHash("sha256").update(resourceName).digest("base64"), "-").slice(0, RESOURCE_NAME_HASHCHARS);
|
|
141
|
+
return `${componentInfraID}-${resourceName}`;
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
sanitizeForAlphaNum,
|
|
145
|
+
getComponentInfraID,
|
|
146
|
+
generateFullResourceName,
|
|
147
|
+
SubnetComponent,
|
|
148
|
+
NetworkComponent,
|
|
149
|
+
InfraComponent,
|
|
150
|
+
DeploymentArtifactType,
|
|
151
|
+
CloudProvider
|
|
152
|
+
};
|