@sdlcworks/components 0.0.4 → 0.0.5

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,39 +10,43 @@ 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 {
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;
31
27
  }
32
- export type InfraComponentPulumiFn = PulumiFn<ICPulumiCtx>;
33
- export type InfraComponentProviderPulumiFns = Partial<Record<string, InfraComponentPulumiFn>>;
34
- export declare class InfraComponent {
35
- opts: InfraComponentOpts;
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>;
36
40
  connect?: ConnectorFn;
37
41
  deploy?: DeployFn;
38
- pulumiFns: InfraComponentProviderPulumiFns;
39
- validationConfigSchema: z.ZodTypeAny;
42
+ pulumiFns: InfraComponentProviderPulumiFns<InfraComponentInputs<InferZodType<CShape>, InferZodType<NShape>, InferZodType<DShape>>>;
43
+ validationSchema: z.ZodTypeAny;
40
44
  validationNetworkInputSchema: z.ZodTypeAny;
41
45
  validationDeploymentInputSchema: z.ZodTypeAny;
42
- constructor(opts: InfraComponentOpts);
46
+ constructor(opts: InfraComponentOpts<CShape, NShape, DShape>);
43
47
  onConnect(connectFn: ConnectorFn): void;
44
48
  onDeploy(deployFn: DeployFn): void;
45
- pulumi(provider: CloudProvider, pulumiFn: InfraComponentPulumiFn): void;
49
+ pulumi(provider: CloudProvider, pulumiFn: InfraComponentPulumiFn<InfraComponentInputs<InferZodType<CShape>, InferZodType<NShape>, InferZodType<DShape>>>): void;
46
50
  }
47
51
  export type SubnetComponentOpts<IShape extends z.ZodRawShape> = {
48
52
  inputSchema: z.ZodObject<IShape>;
@@ -65,7 +69,7 @@ export declare class SubnetComponent<IShape extends z.ZodRawShape> {
65
69
  constructor(opts: SubnetComponentOpts<IShape>);
66
70
  pulumi(provider: CloudProvider, pulumiFn: SubnetComponentPulumiFn<InferZodType<IShape>>): void;
67
71
  }
68
- export type SomeComponent = InfraComponent | NetworkComponent<any> | SubnetComponent<any>;
72
+ export type SomeComponent = InfraComponent<any, any, any> | NetworkComponent<any> | SubnetComponent<any>;
69
73
  export type InferZodType<S extends z.ZodRawShape> = {
70
74
  [K in keyof z.infer<z.ZodObject<S>>]: PulumiInput<z.infer<z.ZodObject<S>>[K]>;
71
75
  };
@@ -122,8 +126,5 @@ export declare class NetworkComponent<IShape extends z.ZodRawShape> {
122
126
  validateParseInputs(inputs: any): unknown;
123
127
  pulumi(provider: CloudProvider, pulumiFn: NetworkComponentPulumiFn<InferZodType<IShape>>): void;
124
128
  }
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
129
 
129
130
  export {};
package/dist/index.js CHANGED
@@ -60,13 +60,13 @@ class InfraComponent {
60
60
  connect;
61
61
  deploy;
62
62
  pulumiFns;
63
- validationConfigSchema;
63
+ validationSchema;
64
64
  validationNetworkInputSchema;
65
65
  validationDeploymentInputSchema;
66
66
  constructor(opts) {
67
67
  this.opts = InfraComponentOptsSchema.parse(opts);
68
68
  this.pulumiFns = {};
69
- this.validationConfigSchema = transformSchemaToAcceptOutputs(opts.configSchema);
69
+ this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
70
70
  this.validationNetworkInputSchema = transformSchemaToAcceptOutputs(opts.networkInputSchema);
71
71
  this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
72
72
  }
@@ -109,41 +109,7 @@ class SubnetComponent {
109
109
  this.pulumiFns[provider] = pulumiFn;
110
110
  }
111
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
112
  export {
144
- sanitizeForAlphaNum,
145
- getComponentInfraID,
146
- generateFullResourceName,
147
113
  SubnetComponent,
148
114
  NetworkComponent,
149
115
  InfraComponent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"