@sdlcworks/components 0.0.4 → 0.0.6

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,66 +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
- declare const InfraComponentOptsSchema: z.ZodObject<{
14
- metadata: z.ZodObject<{
15
- stateful: z.ZodBoolean;
16
- proxiable: z.ZodBoolean;
17
- }, z.core.$strip>;
18
- connectionTypes: z.ZodRecord<z.ZodString, z.ZodObject<{
19
- description: z.ZodString;
20
- }, z.core.$strip>>;
21
- configSchema: z.ZodAny;
22
- networkInputSchema: z.ZodAny;
23
- deploymentInputSchema: z.ZodAny;
24
- }, z.core.$strip>;
25
- export interface InfraComponentOpts extends z.infer<typeof InfraComponentOptsSchema> {
26
- configSchema: z.ZodObject<any>;
27
- networkInputSchema: z.ZodObject<any>;
28
- deploymentInputSchema: z.ZodObject<any>;
29
- }
30
- export interface ICPulumiCtx extends CommonPulumiFnInputs {
31
- }
32
- export type InfraComponentPulumiFn = PulumiFn<ICPulumiCtx>;
33
- export type InfraComponentProviderPulumiFns = Partial<Record<string, InfraComponentPulumiFn>>;
34
- export declare class InfraComponent {
35
- opts: InfraComponentOpts;
36
- connect?: ConnectorFn;
37
- deploy?: DeployFn;
38
- pulumiFns: InfraComponentProviderPulumiFns;
39
- validationConfigSchema: z.ZodTypeAny;
40
- validationNetworkInputSchema: z.ZodTypeAny;
41
- validationDeploymentInputSchema: z.ZodTypeAny;
42
- constructor(opts: InfraComponentOpts);
43
- onConnect(connectFn: ConnectorFn): void;
44
- onDeploy(deployFn: DeployFn): void;
45
- pulumi(provider: CloudProvider, pulumiFn: InfraComponentPulumiFn): void;
46
- }
47
- export type SubnetComponentOpts<IShape extends z.ZodRawShape> = {
48
- inputSchema: z.ZodObject<IShape>;
49
- };
50
- export interface SubnetComponentCtx<T = undefined> extends CommonPulumiFnInputs {
51
- inputs: T;
52
- }
53
- export type SubnetComponentOutputs = {
54
- id: PulumiOutput<string>;
55
- region: PulumiOutput<string>;
56
- cidr?: PulumiOutput<string>;
57
- zone?: PulumiOutput<string>;
58
- [key: string]: any;
59
- };
60
- export type SubnetComponentPulumiFn<I> = PulumiFn<SubnetComponentCtx<I>, SubnetComponentOutputs>;
61
- export declare class SubnetComponent<IShape extends z.ZodRawShape> {
62
- inputSchema: z.ZodObject<IShape>;
63
- validationSchema: z.ZodTypeAny;
64
- pulumiFns: Partial<Record<CloudProvider, SubnetComponentPulumiFn<InferZodType<IShape>>>>;
65
- constructor(opts: SubnetComponentOpts<IShape>);
66
- pulumi(provider: CloudProvider, pulumiFn: SubnetComponentPulumiFn<InferZodType<IShape>>): void;
67
- }
68
- export type SomeComponent = InfraComponent | NetworkComponent<any> | SubnetComponent<any>;
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
- };
72
- export type DefaultPulumiFnOutputs = Record<string, PulumiOutput<any>>;
73
13
  export declare enum CloudProvider {
74
14
  aws = "aws",
75
15
  gcloud = "gcloud",
@@ -97,33 +37,67 @@ export type CommonDeployFnInputs<T = undefined> = Record<string, {
97
37
  type: DeploymentArtifactType;
98
38
  };
99
39
  }>;
100
- export type ConnectorFn = (ctx: any) => Promise<void>;
101
- export type DeployFn<T = CommonDeployFnInputs> = (ctx: T) => Promise<void>;
102
- export type PulumiFn<T = CommonPulumiFnInputs, R = any> = (ctx: T) => Promise<R>;
103
- export type ProviderPulumiFns<Ctx = undefined, R = any> = Partial<Record<CloudProvider, PulumiFn<Ctx, R>>>;
104
- export type NetworkComponentOpts<IShape extends z.ZodRawShape> = {
105
- 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]>;
106
42
  };
107
- export interface NetworkCtx<T = undefined> extends CommonPulumiFnInputs {
108
- inputs: T;
109
- }
110
- export type NetworkComponentOutputs = {
111
- id: PulumiOutput<string>;
112
- region?: PulumiOutput<string>;
113
- cidr?: PulumiOutput<string>;
114
- [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>;
54
+ };
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;
115
65
  };
116
- export type NetworkComponentPulumiFn<I> = PulumiFn<NetworkCtx<I>, NetworkComponentOutputs>;
117
- export type NetworkComponentProviderPulumiFns<I> = Partial<Record<CloudProvider, NetworkComponentPulumiFn<I>>>;
118
- export declare class NetworkComponent<IShape extends z.ZodRawShape> {
119
- private validationSchema;
120
- pulumiFns: NetworkComponentProviderPulumiFns<InferZodType<IShape>>;
121
- constructor(opts: NetworkComponentOpts<IShape>);
122
- validateParseInputs(inputs: any): unknown;
123
- pulumi(provider: CloudProvider, pulumiFn: NetworkComponentPulumiFn<InferZodType<IShape>>): void;
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
+ export type ProviderFnsDef<I, SShape extends z.ZodRawShape> = {
76
+ stateSchema: z.ZodObject<SShape>;
77
+ pulumi: ProviderPulumiFn<I, z.infer<z.ZodObject<SShape>>>;
78
+ onConnect?: ProviderConnectFn<z.infer<z.ZodObject<SShape>>>;
79
+ onDeploy?: ProviderDeployFn<z.infer<z.ZodObject<SShape>>>;
80
+ };
81
+ export type StoredProviderFns = {
82
+ stateSchema: z.ZodObject<any>;
83
+ pulumi: ProviderPulumiFn<any, any>;
84
+ onConnect?: ProviderConnectFn<any>;
85
+ onDeploy?: ProviderDeployFn<any>;
86
+ };
87
+ export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
88
+ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends z.ZodRawShape> {
89
+ opts: InfraComponentOpts<CShape, DShape>;
90
+ providers: ProviderRegistry;
91
+ validationSchema: z.ZodTypeAny;
92
+ validationDeploymentInputSchema: z.ZodTypeAny;
93
+ constructor(opts: InfraComponentOpts<CShape, DShape>);
94
+ private register;
95
+ aws<SShape extends z.ZodRawShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
96
+ gcloud<SShape extends z.ZodRawShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
97
+ azure<SShape extends z.ZodRawShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
98
+ linode<SShape extends z.ZodRawShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
99
+ hetzner<SShape extends z.ZodRawShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
100
+ cloudflare<SShape extends z.ZodRawShape>(fns: ProviderFnsDef<InfraComponentInputs<InferZodType<CShape>, InferZodType<DShape>>, SShape>): void;
124
101
  }
125
- export declare function sanitizeForAlphaNum(_name: string, validSpaceRepl: string): string;
126
- export declare function getComponentInfraID(componentName: string): string;
127
- export declare function generateFullResourceName(componentInfraID: string, name: string): string;
128
102
 
129
103
  export {};
package/dist/index.js CHANGED
@@ -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(0, 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
- };
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()});class M{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}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{M 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.4",
3
+ "version": "0.0.6",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"