@sdlcworks/components 0.0.31 → 0.0.33

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -169
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,169 +1 @@
1
- // src/infra.ts
2
- import { z } from "zod";
3
- import * as pulumi from "@pulumi/pulumi";
4
-
5
- // src/copied-types.ts
6
- var CloudProvider;
7
- ((CloudProvider2) => {
8
- CloudProvider2["aws"] = "aws";
9
- CloudProvider2["gcloud"] = "gcloud";
10
- CloudProvider2["azure"] = "azure";
11
- CloudProvider2["linode"] = "linode";
12
- CloudProvider2["hetzner"] = "hetzner";
13
- CloudProvider2["cloudflare"] = "cloudflare";
14
- })(CloudProvider ||= {});
15
- var DeploymentArtifactType;
16
- ((DeploymentArtifactType2) => {
17
- DeploymentArtifactType2["oci_spec_image"] = "oci_spec_image";
18
- })(DeploymentArtifactType ||= {});
19
-
20
- // src/infra.ts
21
- var TCPUrlType;
22
- ((TCPUrlType2) => {
23
- TCPUrlType2["ipv4"] = "ipv4";
24
- TCPUrlType2["ipv6"] = "ipv6";
25
- TCPUrlType2["domain"] = "domain";
26
- })(TCPUrlType ||= {});
27
- var connectionInterfaceRegistry = new Map;
28
- function toCanonicalInterfaceName(name) {
29
- return name.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase().replace(/-+/g, "-").replace(/^-|-$/g, "");
30
- }
31
- function registerInterfaceName(name) {
32
- const canonical = toCanonicalInterfaceName(name);
33
- if (canonical.length === 0) {
34
- throw new Error(`Connection interface name cannot be empty`);
35
- }
36
- const existing = connectionInterfaceRegistry.get(canonical);
37
- if (existing !== undefined && existing !== name) {
38
- throw new Error(`Connection interface name collision: '${name}' resolves to '${canonical}' which is already registered by '${existing}'`);
39
- }
40
- connectionInterfaceRegistry.set(canonical, name);
41
- return canonical;
42
- }
43
- function defineConnectionInterface(name, schema, resultSchema) {
44
- const canonicalName = registerInterfaceName(name);
45
- return {
46
- name: canonicalName,
47
- schema,
48
- resultSchema
49
- };
50
- }
51
- function extendSchema(parentDef, additionalSchema) {
52
- return parentDef.schema.merge(additionalSchema);
53
- }
54
- var TCPCI = defineConnectionInterface("tcp", z.object({
55
- url: z.object({
56
- type: z.nativeEnum(TCPUrlType),
57
- value: z.string()
58
- }),
59
- publicAccess: z.boolean()
60
- }));
61
- var emptyOutputSchema = z.object({});
62
- function transformSchemaToAcceptOutputs(schema) {
63
- if (schema instanceof z.ZodObject) {
64
- const shape = schema.shape;
65
- const newShape = {};
66
- for (const key in shape) {
67
- newShape[key] = transformSchemaToAcceptOutputs(shape[key]);
68
- }
69
- return z.object(newShape);
70
- }
71
- if (schema instanceof z.ZodOptional) {
72
- return transformSchemaToAcceptOutputs(schema.unwrap()).optional();
73
- }
74
- if (schema instanceof z.ZodNullable) {
75
- return transformSchemaToAcceptOutputs(schema.unwrap()).nullable();
76
- }
77
- if (schema instanceof z.ZodDefault) {
78
- return transformSchemaToAcceptOutputs(schema._def.innerType).default(schema._def.defaultValue);
79
- }
80
- if (schema instanceof z.ZodArray) {
81
- return z.array(transformSchemaToAcceptOutputs(schema.element));
82
- }
83
- if (schema instanceof z.ZodDiscriminatedUnion) {
84
- const transformedOptions = schema._def.options.map((option) => transformSchemaToAcceptOutputs(option));
85
- return z.discriminatedUnion(schema._def.discriminator, transformedOptions);
86
- }
87
- if (schema instanceof z.ZodRecord) {
88
- const keyType = schema._def.keyType;
89
- const valueType = schema._def.valueType;
90
- const transformedKey = keyType ? transformSchemaToAcceptOutputs(keyType) : z.string();
91
- const transformedValue = valueType ? transformSchemaToAcceptOutputs(valueType) : z.any();
92
- return z.record(transformedKey, transformedValue);
93
- }
94
- return z.union([
95
- schema,
96
- z.custom((val) => pulumi.Output.isInstance(val))
97
- ]);
98
- }
99
- var InfraComponentOptsSchema = z.object({
100
- metadata: z.object({
101
- stateful: z.boolean(),
102
- proxiable: z.boolean()
103
- }),
104
- connectionTypes: z.record(z.string(), z.object({
105
- description: z.string().min(5)
106
- })),
107
- configSchema: z.custom(),
108
- deploymentInputSchema: z.custom(),
109
- outputSchema: z.custom()
110
- });
111
- function connectionHandler(entry) {
112
- return entry;
113
- }
114
- var emptyStateSchema = z.object({});
115
-
116
- class InfraComponent {
117
- opts;
118
- providers;
119
- validationSchema;
120
- validationDeploymentInputSchema;
121
- declaredConnectionInterfaces = new Map;
122
- constructor(opts) {
123
- this.opts = InfraComponentOptsSchema.parse(opts);
124
- this.providers = {};
125
- this.validationSchema = transformSchemaToAcceptOutputs(opts.configSchema);
126
- this.validationDeploymentInputSchema = transformSchemaToAcceptOutputs(opts.deploymentInputSchema);
127
- }
128
- implement(provider, fns) {
129
- this.providers[provider] = {
130
- ...fns,
131
- stateSchema: fns.stateSchema ?? emptyStateSchema,
132
- initialState: fns.initialState
133
- };
134
- return this;
135
- }
136
- getConnectionSchema(interfaceDef) {
137
- return interfaceDef.schema;
138
- }
139
- createDeclareConnectionInterfacesFn() {
140
- return (entries) => {
141
- for (const entry of entries) {
142
- const schema = entry.interface.schema;
143
- const transformedSchema = transformSchemaToAcceptOutputs(schema);
144
- const parseResult = transformedSchema.safeParse(entry.data);
145
- if (!parseResult.success) {
146
- throw new Error(`Invalid data for connection interface '${entry.interface.name}': ${parseResult.error.message}`);
147
- }
148
- this.declaredConnectionInterfaces.set(entry.interface.name, {
149
- schema: transformedSchema,
150
- data: entry.data
151
- });
152
- }
153
- };
154
- }
155
- getDeclaredInterfaces() {
156
- return this.declaredConnectionInterfaces;
157
- }
158
- }
159
- export {
160
- toCanonicalInterfaceName,
161
- extendSchema,
162
- defineConnectionInterface,
163
- connectionHandler,
164
- TCPUrlType,
165
- TCPCI,
166
- InfraComponent,
167
- DeploymentArtifactType,
168
- CloudProvider
169
- };
1
+ import{z as j}from"zod";import*as Y from"@pulumi/pulumi";var Q;((L)=>{L.aws="aws";L.gcloud="gcloud";L.azure="azure";L.linode="linode";L.hetzner="hetzner";L.cloudflare="cloudflare"})(Q||={});var W;((B)=>B.oci_spec_image="oci_spec_image")(W||={});var Z;((H)=>{H.ipv4="ipv4";H.ipv6="ipv6";H.domain="domain"})(Z||={});var X=new Map;function _(b){return b.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase().replace(/-+/g,"-").replace(/^-|-$/g,"")}function $(b){let B=_(b);if(B.length===0)throw new Error("Connection interface name cannot be empty");let F=X.get(B);if(F!==void 0&&F!==b)throw new Error(`Connection interface name collision: '${b}' resolves to '${B}' which is already registered by '${F}'`);return X.set(B,b),B}function q(b,B,F){return{name:$(b),schema:B,resultSchema:F}}function w(b,B){return b.schema.merge(B)}var x=q("tcp",j.object({url:j.object({type:j.nativeEnum(Z),value:j.string()}),publicAccess:j.boolean()})),R=j.object({});function J(b){if(b instanceof j.ZodObject){let B=b.shape,F={};for(let H in B)F[H]=J(B[H]);return j.object(F)}if(b instanceof j.ZodOptional)return J(b.unwrap()).optional();if(b instanceof j.ZodNullable)return J(b.unwrap()).nullable();if(b instanceof j.ZodDefault)return J(b._def.innerType).default(b._def.defaultValue);if(b instanceof j.ZodArray)return j.array(J(b.element));if(b instanceof j.ZodDiscriminatedUnion){let B=b._def.options.map((F)=>J(F));return j.discriminatedUnion(b._def.discriminator,B)}if(b instanceof j.ZodRecord){let B=b._def.keyType,F=b._def.valueType,H=B?J(B):j.string(),M=F?J(F):j.any();return j.record(H,M)}return j.union([b,j.custom((B)=>Y.Output.isInstance(B))])}var E=j.object({metadata:j.object({stateful:j.boolean(),proxiable:j.boolean()}),connectionTypes:j.record(j.string(),j.object({description:j.string().min(5)})),configSchema:j.custom(),deploymentInputSchema:j.custom(),outputSchema:j.custom()});function U(b){return b}var G=j.object({});class K{opts;providers;validationSchema;validationDeploymentInputSchema;declaredConnectionInterfaces=new Map;constructor(b){this.opts=E.parse(b),this.providers={},this.validationSchema=J(b.configSchema),this.validationDeploymentInputSchema=J(b.deploymentInputSchema)}implement(b,B){return this.providers[b]={...B,stateSchema:B.stateSchema??G,initialState:B.initialState},this}getConnectionSchema(b){return b.schema}createDeclareConnectionInterfacesFn(){return(b)=>{this.declaredConnectionInterfaces=new Map;for(let B of b){let F=B.interface.schema,H=J(F),M=H.safeParse(B.data);if(!M.success)throw new Error(`Invalid data for connection interface '${B.interface.name}': ${M.error.message}`);this.declaredConnectionInterfaces.set(B.interface.name,{schema:H,data:B.data})}}}getDeclaredInterfaces(){return this.declaredConnectionInterfaces}}export{_ as toCanonicalInterfaceName,w as extendSchema,q as defineConnectionInterface,U as connectionHandler,Z as TCPUrlType,x as TCPCI,K as InfraComponent,W as DeploymentArtifactType,Q as CloudProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdlcworks/components",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "module": "dist/index.js",
5
5
  "files": [
6
6
  "dist"