@sdlcworks/components 0.0.29 → 0.0.30
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 +36 -11
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -79,23 +79,33 @@ export declare function toCanonicalInterfaceName(name: string): string;
|
|
|
79
79
|
/**
|
|
80
80
|
* Connection interface definition with a unique name and typed schema.
|
|
81
81
|
* The name is used for matching interfaces across separately bundled components.
|
|
82
|
+
*
|
|
83
|
+
* @param TName - Unique interface name
|
|
84
|
+
* @param TSchema - Input schema (data from connecting component)
|
|
85
|
+
* @param TResultSchema - Optional result metadata schema for typed handler results
|
|
82
86
|
*/
|
|
83
|
-
export type ConnectionInterfaceDef<TName extends string = string, TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape
|
|
87
|
+
export type ConnectionInterfaceDef<TName extends string = string, TSchema extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>, TResultSchema extends z.ZodObject<z.ZodRawShape> | undefined = undefined> = {
|
|
84
88
|
readonly name: TName;
|
|
85
89
|
readonly schema: TSchema;
|
|
90
|
+
readonly resultSchema?: TResultSchema;
|
|
86
91
|
};
|
|
87
92
|
/**
|
|
88
|
-
* Creates a connection interface definition with a unique name and
|
|
93
|
+
* Creates a connection interface definition with a unique name and schemas.
|
|
89
94
|
* The name is canonicalized to hyphen-separated lowercase and registered
|
|
90
95
|
* globally to detect collisions.
|
|
91
96
|
*
|
|
97
|
+
* @param name - Unique interface name
|
|
98
|
+
* @param schema - Input schema for data passed to handler via ctx.connectionData
|
|
99
|
+
* @param resultSchema - Optional schema for typed metadata returned by handler
|
|
100
|
+
*
|
|
92
101
|
* @example
|
|
93
102
|
* const ServiceAccountCI = defineConnectionInterface(
|
|
94
103
|
* "service-account",
|
|
95
|
-
* z.object({ email: z.string() })
|
|
104
|
+
* z.object({ email: z.string() }),
|
|
105
|
+
* z.object({ role: z.string() }) // Optional result metadata
|
|
96
106
|
* );
|
|
97
107
|
*/
|
|
98
|
-
export declare function defineConnectionInterface<TName extends string, TSchema extends z.ZodObject<z.ZodRawShape
|
|
108
|
+
export declare function defineConnectionInterface<TName extends string, TSchema extends z.ZodObject<z.ZodRawShape>, TResultSchema extends z.ZodObject<z.ZodRawShape> | undefined = undefined>(name: TName, schema: TSchema, resultSchema?: TResultSchema): ConnectionInterfaceDef<TName, TSchema, TResultSchema>;
|
|
99
109
|
/**
|
|
100
110
|
* Merges a parent interface's schema with additional fields.
|
|
101
111
|
* Use with defineConnectionInterface to create extended interfaces.
|
|
@@ -127,7 +137,7 @@ export declare const TCPCI: ConnectionInterfaceDef<"tcp", z.ZodObject<{
|
|
|
127
137
|
value: z.ZodString;
|
|
128
138
|
}, z.core.$strip>;
|
|
129
139
|
publicAccess: z.ZodBoolean;
|
|
130
|
-
}, z.core.$strip
|
|
140
|
+
}, z.core.$strip>, undefined>;
|
|
131
141
|
/**
|
|
132
142
|
* Extract the inferred data type from a ConnectionInterfaceDef.
|
|
133
143
|
*/
|
|
@@ -138,6 +148,11 @@ export type InferConnectionData<D extends ConnectionInterfaceDef> = z.infer<D["s
|
|
|
138
148
|
export type InferConnectionDataWithInputs<D extends ConnectionInterfaceDef> = InferConnectionData<D> extends infer Data ? {
|
|
139
149
|
[K in keyof Data]: PulumiInput<Data[K]>;
|
|
140
150
|
} : never;
|
|
151
|
+
/**
|
|
152
|
+
* Extract the inferred result metadata type from a ConnectionInterfaceDef.
|
|
153
|
+
* Returns undefined if no resultSchema is defined.
|
|
154
|
+
*/
|
|
155
|
+
export type InferConnectionResultMetadata<D extends ConnectionInterfaceDef> = D extends ConnectionInterfaceDef<any, any, infer R> ? R extends z.ZodObject<z.ZodRawShape> ? z.infer<R> : undefined : undefined;
|
|
141
156
|
/**
|
|
142
157
|
* Entry type for declareConnectionInterfaces parameter.
|
|
143
158
|
* Declares an interface that this component exposes with typed data.
|
|
@@ -233,15 +248,25 @@ export type ConnectionHandlerCtx<S, ConnectorData, ConnectionType extends string
|
|
|
233
248
|
};
|
|
234
249
|
/**
|
|
235
250
|
* Result returned by connection handlers.
|
|
236
|
-
*
|
|
251
|
+
* - uri: Required, the connection URI as a Pulumi Output
|
|
252
|
+
* - metadata: Optional, typed based on interface's resultSchema
|
|
253
|
+
*
|
|
254
|
+
* If no resultSchema is defined on the interface, metadata can be any record.
|
|
255
|
+
* If resultSchema is defined, metadata is typed and validated against it.
|
|
237
256
|
*/
|
|
238
|
-
export type ConnectionHandlerResult =
|
|
257
|
+
export type ConnectionHandlerResult<TMetadata = undefined> = {
|
|
258
|
+
uri: PulumiOutput<string>;
|
|
259
|
+
metadata?: TMetadata extends undefined ? Record<string, PulumiInput<string | number | boolean>> : {
|
|
260
|
+
[K in keyof TMetadata]: PulumiInput<TMetadata[K]>;
|
|
261
|
+
};
|
|
262
|
+
};
|
|
239
263
|
/**
|
|
240
264
|
* A connection handler entry mapping a ConnectionInterfaceDef to its handler function.
|
|
265
|
+
* The handler returns typed metadata based on the interface's resultSchema.
|
|
241
266
|
*/
|
|
242
267
|
export type ConnectionHandlerEntry<S, ConnectionType extends string, D extends ConnectionInterfaceDef, P extends CloudProvider = CloudProvider> = {
|
|
243
268
|
interface: D;
|
|
244
|
-
handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<D>, ConnectionType, P>) => Promise<ConnectionHandlerResult
|
|
269
|
+
handler: (ctx: ConnectionHandlerCtx<S, InferConnectionData<D>, ConnectionType, P>) => Promise<ConnectionHandlerResult<InferConnectionResultMetadata<D>>>;
|
|
245
270
|
};
|
|
246
271
|
/**
|
|
247
272
|
* Type definition for a connection handler entry.
|
|
@@ -249,7 +274,7 @@ export type ConnectionHandlerEntry<S, ConnectionType extends string, D extends C
|
|
|
249
274
|
*/
|
|
250
275
|
export type ConnectionHandlerDef<D extends ConnectionInterfaceDef> = {
|
|
251
276
|
interface: D;
|
|
252
|
-
handler: (ctx: ConnectionHandlerCtx<any, InferConnectionData<D>, any>) => Promise<ConnectionHandlerResult
|
|
277
|
+
handler: (ctx: ConnectionHandlerCtx<any, InferConnectionData<D>, any>) => Promise<ConnectionHandlerResult<InferConnectionResultMetadata<D>>>;
|
|
253
278
|
};
|
|
254
279
|
export declare function connectionHandler<D extends ConnectionInterfaceDef>(entry: ConnectionHandlerDef<D>): ConnectionHandlerDef<D>;
|
|
255
280
|
export type ProviderDeployCtx<D, S, P extends CloudProvider = CloudProvider> = {
|
|
@@ -316,8 +341,8 @@ export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateSha
|
|
|
316
341
|
* when accessing from the registry, allowing runtime schema access.
|
|
317
342
|
*/
|
|
318
343
|
export type StoredConnectionHandlerEntry = {
|
|
319
|
-
interface: ConnectionInterfaceDef
|
|
320
|
-
handler: (ctx: ConnectionHandlerCtx<any, any, any, any>) => Promise<ConnectionHandlerResult
|
|
344
|
+
interface: ConnectionInterfaceDef<string, any, any>;
|
|
345
|
+
handler: (ctx: ConnectionHandlerCtx<any, any, any, any>) => Promise<ConnectionHandlerResult<any>>;
|
|
321
346
|
};
|
|
322
347
|
export type StoredProviderFns = {
|
|
323
348
|
stateSchema: z.ZodObject<any>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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.container_image="container_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){return{name:$(b),schema:B}}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)=>{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};
|
|
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.container_image="container_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)=>{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};
|