@sdlcworks/components 0.0.34 → 0.0.36
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 +187 -34
- package/dist/index.js +1 -170
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,8 @@ export declare enum CloudProvider {
|
|
|
20
20
|
cloudflare = "cloudflare"
|
|
21
21
|
}
|
|
22
22
|
export declare enum DeploymentArtifactType {
|
|
23
|
-
oci_spec_image = "oci_spec_image"
|
|
23
|
+
oci_spec_image = "oci_spec_image",
|
|
24
|
+
file = "file"
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* GCP credential fields required for authentication.
|
|
@@ -69,11 +70,6 @@ export type ProviderCredentialsMap = {
|
|
|
69
70
|
* Returns the typed credentials for the specified provider.
|
|
70
71
|
*/
|
|
71
72
|
export type GetCredentialsFn<P extends CloudProvider> = () => ProviderCredentialsMap[P];
|
|
72
|
-
export declare enum TCPUrlType {
|
|
73
|
-
ipv4 = "ipv4",
|
|
74
|
-
ipv6 = "ipv6",
|
|
75
|
-
domain = "domain"
|
|
76
|
-
}
|
|
77
73
|
/**
|
|
78
74
|
* Transforms any interface name to canonical hyphen-separated lowercase form.
|
|
79
75
|
*
|
|
@@ -136,16 +132,19 @@ export declare function extendSchema<TParentSchema extends z.ZodObject<z.ZodRawS
|
|
|
136
132
|
[k in keyof T]: T[k];
|
|
137
133
|
} : never, TChildSchema["_zod"]["config"]>;
|
|
138
134
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
135
|
+
* Public HTTP Connection Interface - defines a public HTTP endpoint.
|
|
136
|
+
* No metadata, only URI is provided.
|
|
141
137
|
*/
|
|
142
|
-
export declare const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
export declare const PublicHTTPCI: ConnectionInterfaceDef<"public-http", z.ZodObject<{}, z.core.$strip>, undefined>;
|
|
139
|
+
/**
|
|
140
|
+
* Connection type used by the orchestrator when performing anonymous URI discovery
|
|
141
|
+
* for URL register component collection. Infra component connect handlers that expose
|
|
142
|
+
* interfaces consumed by URL registers must accept this connection type.
|
|
143
|
+
*
|
|
144
|
+
* If your infra component's connect handler does not handle this type, the orchestrator
|
|
145
|
+
* will raise an error instructing you to add support for it.
|
|
146
|
+
*/
|
|
147
|
+
export declare const ANONYMOUS_CONNECTION_TYPE: "@anonymous";
|
|
149
148
|
/**
|
|
150
149
|
* Extract the inferred data type from a ConnectionInterfaceDef.
|
|
151
150
|
*/
|
|
@@ -245,15 +244,31 @@ export type ProviderPulumiCtx<I, S, P extends CloudProvider = CloudProvider> = {
|
|
|
245
244
|
getCredentials: GetCredentialsFn<P>;
|
|
246
245
|
};
|
|
247
246
|
/**
|
|
248
|
-
* Context passed to
|
|
249
|
-
*
|
|
250
|
-
*
|
|
247
|
+
* Context passed to the connect function.
|
|
248
|
+
* Called once per app component requesting a connection.
|
|
249
|
+
* The connect function returns handler entries that can capture this context via closure.
|
|
251
250
|
*/
|
|
252
|
-
export type
|
|
251
|
+
export type ConnectFnCtx<S, P extends CloudProvider = CloudProvider> = {
|
|
253
252
|
state: S;
|
|
253
|
+
getCredentials: GetCredentialsFn<P>;
|
|
254
|
+
componentName: string;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Reduced context passed to individual connection handlers.
|
|
258
|
+
* Only contains the per-invocation essentials (connectionData, connectionType, and $).
|
|
259
|
+
* Handlers access state, getCredentials, and componentName via closure from the connect function.
|
|
260
|
+
*
|
|
261
|
+
* $ - Naming function for Pulumi resources created by this handler. Always use $ for resource
|
|
262
|
+
* names so the orchestrator can track which resources are created by connection logic and
|
|
263
|
+
* apply the correct delete-protection policy (connection resources are ephemeral and un-protected).
|
|
264
|
+
*/
|
|
265
|
+
export type ConnectHandlerCtx<ConnectorData, ConnectionType extends string = string> = {
|
|
254
266
|
connectionData: ConnectorData;
|
|
255
267
|
connectionType: ConnectionType;
|
|
256
|
-
|
|
268
|
+
$: {
|
|
269
|
+
(name: string, ...values: any[]): string;
|
|
270
|
+
(strings: TemplateStringsArray, ...values: any[]): string;
|
|
271
|
+
};
|
|
257
272
|
};
|
|
258
273
|
/**
|
|
259
274
|
* Result returned by connection handlers.
|
|
@@ -271,11 +286,13 @@ export type ConnectionHandlerResult<TMetadata = undefined> = {
|
|
|
271
286
|
};
|
|
272
287
|
/**
|
|
273
288
|
* A connection handler entry mapping a ConnectionInterfaceDef to its handler function.
|
|
289
|
+
* The handler receives a reduced context (connectionData and connectionType only).
|
|
290
|
+
* State, getCredentials, and componentName are accessed via closure from the connect function.
|
|
274
291
|
* The handler returns typed metadata based on the interface's resultSchema.
|
|
275
292
|
*/
|
|
276
|
-
export type ConnectionHandlerEntry<
|
|
293
|
+
export type ConnectionHandlerEntry<ConnectionType extends string, D extends ConnectionInterfaceDef> = {
|
|
277
294
|
interface: D;
|
|
278
|
-
handler: (ctx:
|
|
295
|
+
handler: (ctx: ConnectHandlerCtx<InferConnectionData<D>, ConnectionType>) => Promise<ConnectionHandlerResult<InferConnectionResultMetadata<D>>>;
|
|
279
296
|
};
|
|
280
297
|
/**
|
|
281
298
|
* Type definition for a connection handler entry.
|
|
@@ -283,9 +300,56 @@ export type ConnectionHandlerEntry<S, ConnectionType extends string, D extends C
|
|
|
283
300
|
*/
|
|
284
301
|
export type ConnectionHandlerDef<D extends ConnectionInterfaceDef> = {
|
|
285
302
|
interface: D;
|
|
286
|
-
handler: (ctx:
|
|
303
|
+
handler: (ctx: ConnectHandlerCtx<InferConnectionData<D>, any>) => Promise<ConnectionHandlerResult<InferConnectionResultMetadata<D>>>;
|
|
287
304
|
};
|
|
288
305
|
export declare function connectionHandler<D extends ConnectionInterfaceDef>(entry: ConnectionHandlerDef<D>): ConnectionHandlerDef<D>;
|
|
306
|
+
/**
|
|
307
|
+
* Type for the connect function.
|
|
308
|
+
* Called once per app component requesting a connection.
|
|
309
|
+
* Returns an array of handler entries that can use the context via closure.
|
|
310
|
+
*/
|
|
311
|
+
export type ConnectFn<S, ConnectionType extends string, P extends CloudProvider = CloudProvider> = (ctx: ConnectFnCtx<S, P>) => readonly ConnectionHandlerEntry<ConnectionType, any>[];
|
|
312
|
+
/**
|
|
313
|
+
* Component entry in the URLRegister provision context.
|
|
314
|
+
* Reference metadata for components, keyed by their original URI.
|
|
315
|
+
*
|
|
316
|
+
* The provision function may or may not use this reference data.
|
|
317
|
+
* Metadata is fully typed based on the ConnectionInterface's resultSchema.
|
|
318
|
+
*/
|
|
319
|
+
export type URLRegisterComponentEntry<TInterface extends ConnectionInterfaceDef> = {
|
|
320
|
+
component: string;
|
|
321
|
+
metadata: InferConnectionResultMetadata<TInterface> extends undefined ? Record<string, never> : {
|
|
322
|
+
[K in keyof InferConnectionResultMetadata<TInterface>]: PulumiInput<InferConnectionResultMetadata<TInterface>[K]>;
|
|
323
|
+
};
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
326
|
+
* Context passed to the URLRegister provision function.
|
|
327
|
+
*
|
|
328
|
+
* @property config - Global configuration + URL map definition (user-defined routes/URLs to provision)
|
|
329
|
+
* @property state - Mutable state for this URLRegister instance
|
|
330
|
+
* @property components - Reference metadata keyed by original URI (may or may not be used by provision function)
|
|
331
|
+
* @property $ - Naming helper for Pulumi resource names
|
|
332
|
+
*
|
|
333
|
+
* Fully typed based on configSchema, stateSchema, and the declared ConnectionInterface.
|
|
334
|
+
*/
|
|
335
|
+
export type URLRegisterProvisionCtx<TConfig, TInterface extends ConnectionInterfaceDef, S> = {
|
|
336
|
+
config: TConfig;
|
|
337
|
+
state: S;
|
|
338
|
+
components: Record<string, URLRegisterComponentEntry<TInterface>>;
|
|
339
|
+
$: {
|
|
340
|
+
(name: string, ...values: any[]): string;
|
|
341
|
+
(strings: TemplateStringsArray, ...values: any[]): string;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Result returned by the URLRegister provision function.
|
|
346
|
+
* Maps component names to their provisioned URIs.
|
|
347
|
+
*/
|
|
348
|
+
export type URLRegisterProvisionResult = Record<string, PulumiOutput<string>>;
|
|
349
|
+
/**
|
|
350
|
+
* Type-erased storage for URLRegister provision function.
|
|
351
|
+
*/
|
|
352
|
+
export type StoredProvisionFn = (ctx: URLRegisterProvisionCtx<any, any, any>) => Promise<URLRegisterProvisionResult>;
|
|
289
353
|
export type ProviderDeployCtx<D, S, P extends CloudProvider = CloudProvider> = {
|
|
290
354
|
state: S;
|
|
291
355
|
getCredentials: GetCredentialsFn<P>;
|
|
@@ -301,6 +365,19 @@ export type ProviderAllocateCtx<S, P extends CloudProvider = CloudProvider> = {
|
|
|
301
365
|
envStore: EnvStore;
|
|
302
366
|
getCredentials: GetCredentialsFn<P>;
|
|
303
367
|
};
|
|
368
|
+
export type ProviderAllocateWithPulumiCtxCtx<S, P extends CloudProvider = CloudProvider> = {
|
|
369
|
+
name: string;
|
|
370
|
+
deploymentConfig: Record<string, any>;
|
|
371
|
+
state: S;
|
|
372
|
+
$: {
|
|
373
|
+
(name: string, ...values: any[]): string;
|
|
374
|
+
(strings: TemplateStringsArray, ...values: any[]): string;
|
|
375
|
+
};
|
|
376
|
+
envStore: EnvStore;
|
|
377
|
+
getCredentials: GetCredentialsFn<P>;
|
|
378
|
+
/** Build artifact for this app component, if available. */
|
|
379
|
+
buildArtifact?: ArtifactInfo;
|
|
380
|
+
};
|
|
304
381
|
export type ProviderDeallocateCtx<S, P extends CloudProvider = CloudProvider> = {
|
|
305
382
|
name: string;
|
|
306
383
|
deploymentConfig: Record<string, any>;
|
|
@@ -320,6 +397,7 @@ export type ProviderUpsertArtifactsCtx<S, P extends CloudProvider = CloudProvide
|
|
|
320
397
|
export type ProviderPulumiFn<I, S, O, P extends CloudProvider = CloudProvider> = (ctx: ProviderPulumiCtx<I, S, P>) => Promise<O>;
|
|
321
398
|
export type ProviderDeployFn<D, S, P extends CloudProvider = CloudProvider> = (ctx: ProviderDeployCtx<D, S, P>) => Promise<void>;
|
|
322
399
|
export type ProviderAllocateFn<S, P extends CloudProvider = CloudProvider> = (ctx: ProviderAllocateCtx<S, P>) => Promise<void>;
|
|
400
|
+
export type ProviderAllocateWithPulumiCtxFn<S, P extends CloudProvider = CloudProvider> = (ctx: ProviderAllocateWithPulumiCtxCtx<S, P>) => Promise<void>;
|
|
323
401
|
export type ProviderDeallocateFn<S, P extends CloudProvider = CloudProvider> = (ctx: ProviderDeallocateCtx<S, P>) => Promise<void>;
|
|
324
402
|
export type ProviderUpsertArtifactsFn<S, P extends CloudProvider = CloudProvider> = (ctx: ProviderUpsertArtifactsCtx<S, P>) => Promise<void>;
|
|
325
403
|
declare const emptyStateSchema: z.ZodObject<{}, z.core.$strip>;
|
|
@@ -340,29 +418,28 @@ export type ProviderFnsDef<I, D, O, SShape extends z.ZodRawShape = EmptyStateSha
|
|
|
340
418
|
stateSchema?: z.ZodObject<SShape>;
|
|
341
419
|
initialState?: Partial<S>;
|
|
342
420
|
pulumi: ProviderPulumiFn<I, S, O, P>;
|
|
343
|
-
connect?:
|
|
421
|
+
connect?: ConnectFn<S, ConnectionType, P>;
|
|
344
422
|
deploy?: ProviderDeployFn<D, S, P>;
|
|
345
423
|
allocateComponent?: ProviderAllocateFn<S, P>;
|
|
346
424
|
deallocateComponent?: ProviderDeallocateFn<S, P>;
|
|
425
|
+
/**
|
|
426
|
+
* Pulumi-context allocation: creates declarative Pulumi resources per app component.
|
|
427
|
+
* Mutually exclusive with `allocateComponent` — defining both will throw an error.
|
|
428
|
+
* Unlike `allocateComponent` (imperative side-effects), resources created here are
|
|
429
|
+
* tracked by Pulumi and automatically destroyed when the app component is removed.
|
|
430
|
+
*/
|
|
431
|
+
allocateWithPulumiCtx?: ProviderAllocateWithPulumiCtxFn<S, P>;
|
|
347
432
|
upsertArtifacts?: ProviderUpsertArtifactsFn<S, P>;
|
|
348
433
|
};
|
|
349
|
-
/**
|
|
350
|
-
* Stored version of ConnectionHandlerEntry that preserves ConnectionInterfaceDef type.
|
|
351
|
-
* This ensures `interface` is always typed as ConnectionInterfaceDef (not any)
|
|
352
|
-
* when accessing from the registry, allowing runtime schema access.
|
|
353
|
-
*/
|
|
354
|
-
export type StoredConnectionHandlerEntry = {
|
|
355
|
-
interface: ConnectionInterfaceDef<string, any, any>;
|
|
356
|
-
handler: (ctx: ConnectionHandlerCtx<any, any, any, any>) => Promise<ConnectionHandlerResult<any>>;
|
|
357
|
-
};
|
|
358
434
|
export type StoredProviderFns = {
|
|
359
435
|
stateSchema: z.ZodObject<any>;
|
|
360
436
|
initialState?: any;
|
|
361
437
|
pulumi: ProviderPulumiFn<any, any, any, any>;
|
|
362
|
-
connect?:
|
|
438
|
+
connect?: ConnectFn<any, any, any>;
|
|
363
439
|
deploy?: ProviderDeployFn<any, any, any>;
|
|
364
440
|
allocateComponent?: ProviderAllocateFn<any, any>;
|
|
365
441
|
deallocateComponent?: ProviderDeallocateFn<any, any>;
|
|
442
|
+
allocateWithPulumiCtx?: ProviderAllocateWithPulumiCtxFn<any, any>;
|
|
366
443
|
upsertArtifacts?: ProviderUpsertArtifactsFn<any, any>;
|
|
367
444
|
};
|
|
368
445
|
export type ProviderRegistry = Partial<Record<CloudProvider, StoredProviderFns>>;
|
|
@@ -405,5 +482,81 @@ export declare class InfraComponent<CShape extends z.ZodRawShape, DShape extends
|
|
|
405
482
|
*/
|
|
406
483
|
getDeclaredInterfaces(): DeclaredConnectionInterfaces;
|
|
407
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* URLRegister component for managing URL routing/registration (e.g., DNS, LB paths).
|
|
487
|
+
*
|
|
488
|
+
* Provider-agnostic: runs at app-layer, not tied to specific cloud providers.
|
|
489
|
+
*
|
|
490
|
+
* ## Conceptual Model
|
|
491
|
+
*
|
|
492
|
+
* - **`interface` field**: Required metadata for SDLC orchestrator (determines which components get passed)
|
|
493
|
+
* - **`configSchema`**: Defines global settings + URL map (routes/paths the user wants to provision)
|
|
494
|
+
* - **`ctx.components`**: Reference metadata keyed by URI (provision function may or may not use this)
|
|
495
|
+
* - **Return type**: Component name → rewritten URI (can be empty `{}` if no rewriting needed)
|
|
496
|
+
*
|
|
497
|
+
* @param TName - Unique name for this URLRegister
|
|
498
|
+
* @param TInterface - The ConnectionInterfaceDef this register handles (orchestrator metadata)
|
|
499
|
+
* @param CShape - Zod shape for the config schema (global settings + URL map definition)
|
|
500
|
+
* @param SShape - Zod shape for the state schema (default: empty)
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* const BackendServiceCI = defineConnectionInterface(
|
|
504
|
+
* "backend-service",
|
|
505
|
+
* z.object({ backendServiceId: z.string() }),
|
|
506
|
+
* z.object({ region: z.string(), port: z.number() })
|
|
507
|
+
* );
|
|
508
|
+
*
|
|
509
|
+
* const lbPathRegister = new URLRegister({
|
|
510
|
+
* name: "lb-path-manager",
|
|
511
|
+
* interface: BackendServiceCI, // Orchestrator uses this to route components
|
|
512
|
+
* configSchema: z.object({
|
|
513
|
+
* domain: z.string(),
|
|
514
|
+
* urlMapId: z.string(),
|
|
515
|
+
* routes: z.array(z.object({
|
|
516
|
+
* path: z.string(),
|
|
517
|
+
* targetComponent: z.string(),
|
|
518
|
+
* })),
|
|
519
|
+
* }),
|
|
520
|
+
* provision: async (ctx) => {
|
|
521
|
+
* // ctx.config: { domain, urlMapId, routes: [...] }
|
|
522
|
+
* // ctx.components: { [uri: string]: { component: string, metadata: {...typed...} } }
|
|
523
|
+
*
|
|
524
|
+
* const results: Record<string, pulumi.Output<string>> = {};
|
|
525
|
+
* for (const route of ctx.config.routes) {
|
|
526
|
+
* // Find component's original URI if needed
|
|
527
|
+
* const componentEntry = Object.entries(ctx.components)
|
|
528
|
+
* .find(([_, entry]) => entry.component === route.targetComponent);
|
|
529
|
+
*
|
|
530
|
+
* if (componentEntry) {
|
|
531
|
+
* const [originalUri, entry] = componentEntry;
|
|
532
|
+
* // Use originalUri and entry.metadata as needed
|
|
533
|
+
* results[entry.component] = pulumi.interpolate`https://${ctx.config.domain}${route.path}`;
|
|
534
|
+
* }
|
|
535
|
+
* }
|
|
536
|
+
* return results; // Can be {} if no rewriting needed
|
|
537
|
+
* },
|
|
538
|
+
* });
|
|
539
|
+
*/
|
|
540
|
+
export declare class URLRegister<TName extends string, TInterface extends ConnectionInterfaceDef, CShape extends z.ZodRawShape, SShape extends z.ZodRawShape = EmptyStateShape> {
|
|
541
|
+
readonly name: TName;
|
|
542
|
+
readonly interface: TInterface;
|
|
543
|
+
readonly configSchema: z.ZodObject<CShape>;
|
|
544
|
+
readonly stateSchema: z.ZodObject<SShape>;
|
|
545
|
+
readonly validationSchema: z.ZodTypeAny;
|
|
546
|
+
private readonly provisionFn;
|
|
547
|
+
readonly initialState?: Partial<RuntimeState<SShape>>;
|
|
548
|
+
constructor(opts: {
|
|
549
|
+
name: TName;
|
|
550
|
+
interface: TInterface;
|
|
551
|
+
configSchema: z.ZodObject<CShape>;
|
|
552
|
+
stateSchema?: z.ZodObject<SShape>;
|
|
553
|
+
initialState?: Partial<RuntimeState<SShape>>;
|
|
554
|
+
provision: (ctx: URLRegisterProvisionCtx<InferZodType<CShape>, TInterface, RuntimeState<SShape>>) => Promise<URLRegisterProvisionResult>;
|
|
555
|
+
});
|
|
556
|
+
/**
|
|
557
|
+
* Get the provision function (for orchestrator use).
|
|
558
|
+
*/
|
|
559
|
+
getProvision(): StoredProvisionFn;
|
|
560
|
+
}
|
|
408
561
|
|
|
409
562
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,170 +1 @@
|
|
|
1
|
-
|
|
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
|
-
this.declaredConnectionInterfaces = new Map;
|
|
142
|
-
for (const entry of entries) {
|
|
143
|
-
const schema = entry.interface.schema;
|
|
144
|
-
const transformedSchema = transformSchemaToAcceptOutputs(schema);
|
|
145
|
-
const parseResult = transformedSchema.safeParse(entry.data);
|
|
146
|
-
if (!parseResult.success) {
|
|
147
|
-
throw new Error(`Invalid data for connection interface '${entry.interface.name}': ${parseResult.error.message}`);
|
|
148
|
-
}
|
|
149
|
-
this.declaredConnectionInterfaces.set(entry.interface.name, {
|
|
150
|
-
schema: transformedSchema,
|
|
151
|
-
data: entry.data
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
getDeclaredInterfaces() {
|
|
157
|
-
return this.declaredConnectionInterfaces;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
export {
|
|
161
|
-
toCanonicalInterfaceName,
|
|
162
|
-
extendSchema,
|
|
163
|
-
defineConnectionInterface,
|
|
164
|
-
connectionHandler,
|
|
165
|
-
TCPUrlType,
|
|
166
|
-
TCPCI,
|
|
167
|
-
InfraComponent,
|
|
168
|
-
DeploymentArtifactType,
|
|
169
|
-
CloudProvider
|
|
170
|
-
};
|
|
1
|
+
import{z as j}from"zod";import*as Z from"@pulumi/pulumi";var W;((M)=>{M.aws="aws";M.gcloud="gcloud";M.azure="azure";M.linode="linode";M.hetzner="hetzner";M.cloudflare="cloudflare"})(W||={});var X;((F)=>{F.oci_spec_image="oci_spec_image";F.file="file"})(X||={});var Y=new Map;function $(b){return b.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[_\s]+/g,"-").toLowerCase().replace(/-+/g,"-").replace(/^-|-$/g,"")}function q(b){let B=$(b);if(B.length===0)throw new Error("Connection interface name cannot be empty");let F=Y.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 Y.set(B,b),B}function E(b,B,F){return{name:q(b),schema:B,resultSchema:F}}function k(b,B){return b.schema.merge(B)}var x=E("public-http",j.object({})),I="@anonymous",R=j.object({});function H(b){if(b instanceof j.ZodObject){let B=b.shape,F={};for(let J in B)F[J]=H(B[J]);return j.object(F)}if(b instanceof j.ZodOptional)return H(b.unwrap()).optional();if(b instanceof j.ZodNullable)return H(b.unwrap()).nullable();if(b instanceof j.ZodDefault)return H(b._def.innerType).default(b._def.defaultValue);if(b instanceof j.ZodArray)return j.array(H(b.element));if(b instanceof j.ZodDiscriminatedUnion){let B=b._def.options.map((F)=>H(F));return j.discriminatedUnion(b._def.discriminator,B)}if(b instanceof j.ZodRecord){let B=b._def.keyType,F=b._def.valueType,J=B?H(B):j.string(),Q=F?H(F):j.any();return j.record(J,Q)}return j.union([b,j.custom((B)=>Z.Output.isInstance(B))])}var G=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 g(b){return b}var _=j.object({});class K{opts;providers;validationSchema;validationDeploymentInputSchema;declaredConnectionInterfaces=new Map;constructor(b){this.opts=G.parse(b),this.providers={},this.validationSchema=H(b.configSchema),this.validationDeploymentInputSchema=H(b.deploymentInputSchema)}implement(b,B){if(B.allocateComponent&&B.allocateWithPulumiCtx)throw new Error(`Provider '${b}' cannot define both 'allocateComponent' and 'allocateWithPulumiCtx'. These are mutually exclusive allocation strategies.`);return this.providers[b]={...B,stateSchema:B.stateSchema??_,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,J=H(F),Q=J.safeParse(B.data);if(!Q.success)throw new Error(`Invalid data for connection interface '${B.interface.name}': ${Q.error.message}`);this.declaredConnectionInterfaces.set(B.interface.name,{schema:J,data:B.data})}}}getDeclaredInterfaces(){return this.declaredConnectionInterfaces}}var L=j.object({name:j.string().min(1),interface:j.custom(),configSchema:j.custom(),stateSchema:j.custom().optional(),provision:j.function()});class U{name;interface;configSchema;stateSchema;validationSchema;provisionFn;initialState;constructor(b){L.parse(b),this.name=b.name,this.interface=b.interface,this.configSchema=b.configSchema,this.stateSchema=b.stateSchema??_,this.validationSchema=H(b.configSchema),this.provisionFn=b.provision,this.initialState=b.initialState}getProvision(){return this.provisionFn}}export{$ as toCanonicalInterfaceName,k as extendSchema,E as defineConnectionInterface,g as connectionHandler,U as URLRegister,x as PublicHTTPCI,K as InfraComponent,X as DeploymentArtifactType,W as CloudProvider,I as ANONYMOUS_CONNECTION_TYPE};
|