opinionated-machine
Version:
Very opinionated DI framework for fastify, built on top of awilix
177 lines (176 loc) • 7.11 kB
TypeScript
import { z } from 'zod/v4';
/**
* Duration string in the format "<number><unit>", e.g. "5s", "300ms", "1m", "2h".
* Parsed at generation time by individual gateway generators.
*/
export declare const durationSchema: z.ZodString;
export type Duration = z.infer<typeof durationSchema>;
/**
* Match rule for a single header or query value.
* Bare strings are treated as exact matches; objects are explicit.
*/
export declare const matchRuleSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
exact: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
prefix: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
regex: z.ZodString;
}, z.core.$strip>]>;
export type MatchRule = z.infer<typeof matchRuleSchema>;
/**
* Universal gateway metadata schema.
*
* Vendor-neutral. Generators map every field they support and put unmapped
* data into `warnings`. Use `extensions.<vendor>` for gateway-specific knobs
* the universal model doesn't cover.
*/
export declare const gatewayMetadataSchema: z.ZodObject<{
id: z.ZodOptional<z.ZodString>;
upstream: z.ZodOptional<z.ZodString>;
visibility: z.ZodOptional<z.ZodEnum<{
public: "public";
internal: "internal";
admin: "admin";
}>>;
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
match: z.ZodOptional<z.ZodObject<{
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
exact: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
prefix: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
regex: z.ZodString;
}, z.core.$strip>]>>>;
customHeaders: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
exact: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
prefix: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
regex: z.ZodString;
}, z.core.$strip>]>>>;
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
exact: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
prefix: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
regex: z.ZodString;
}, z.core.$strip>]>>>;
customQuery: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
exact: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
prefix: z.ZodString;
}, z.core.$strip>, z.ZodObject<{
regex: z.ZodString;
}, z.core.$strip>]>>>;
host: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
}, z.core.$strict>>;
rewrite: z.ZodOptional<z.ZodObject<{
stripPrefix: z.ZodOptional<z.ZodString>;
replacePrefix: z.ZodOptional<z.ZodObject<{
from: z.ZodString;
to: z.ZodString;
}, z.core.$strict>>;
}, z.core.$strict>>;
timeouts: z.ZodOptional<z.ZodObject<{
request: z.ZodOptional<z.ZodString>;
idle: z.ZodOptional<z.ZodString>;
connect: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>;
retry: z.ZodOptional<z.ZodObject<{
attempts: z.ZodOptional<z.ZodNumber>;
on: z.ZodOptional<z.ZodArray<z.ZodEnum<{
"5xx": "5xx";
"gateway-error": "gateway-error";
"connect-failure": "connect-failure";
reset: "reset";
"retriable-4xx": "retriable-4xx";
}>>>;
perTryTimeout: z.ZodOptional<z.ZodString>;
backoff: z.ZodOptional<z.ZodObject<{
base: z.ZodOptional<z.ZodString>;
max: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>;
}, z.core.$strict>>;
circuitBreaker: z.ZodOptional<z.ZodObject<{
maxConnections: z.ZodOptional<z.ZodNumber>;
maxPendingRequests: z.ZodOptional<z.ZodNumber>;
maxRequests: z.ZodOptional<z.ZodNumber>;
maxRetries: z.ZodOptional<z.ZodNumber>;
}, z.core.$strict>>;
rateLimit: z.ZodOptional<z.ZodObject<{
requests: z.ZodNumber;
per: z.ZodString;
key: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ip">, z.ZodObject<{
header: z.ZodString;
}, z.core.$strict>, z.ZodObject<{
customHeader: z.ZodString;
}, z.core.$strict>, z.ZodObject<{
query: z.ZodString;
}, z.core.$strict>, z.ZodObject<{
customQuery: z.ZodString;
}, z.core.$strict>]>>;
}, z.core.$strict>>;
traffic: z.ZodOptional<z.ZodObject<{
weights: z.ZodOptional<z.ZodArray<z.ZodObject<{
upstream: z.ZodString;
weight: z.ZodNumber;
}, z.core.$strict>>>;
shadow: z.ZodOptional<z.ZodObject<{
upstream: z.ZodString;
percent: z.ZodNumber;
}, z.core.$strict>>;
}, z.core.$strict>>;
cors: z.ZodOptional<z.ZodObject<{
origins: z.ZodArray<z.ZodString>;
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
GET: "GET";
POST: "POST";
PUT: "PUT";
PATCH: "PATCH";
DELETE: "DELETE";
HEAD: "HEAD";
OPTIONS: "OPTIONS";
}>>>;
headers: z.ZodOptional<z.ZodArray<z.ZodString>>;
exposeHeaders: z.ZodOptional<z.ZodArray<z.ZodString>>;
credentials: z.ZodOptional<z.ZodBoolean>;
maxAge: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>;
auth: z.ZodOptional<z.ZodObject<{
required: z.ZodOptional<z.ZodBoolean>;
jwt: z.ZodOptional<z.ZodObject<{
issuer: z.ZodString;
audiences: z.ZodOptional<z.ZodArray<z.ZodString>>;
jwksUri: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>;
mTLS: z.ZodOptional<z.ZodBoolean>;
}, z.core.$strict>>;
cache: z.ZodOptional<z.ZodObject<{
ttl: z.ZodString;
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
GET: "GET";
HEAD: "HEAD";
}>>>;
vary: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strict>>;
headers: z.ZodOptional<z.ZodObject<{
request: z.ZodOptional<z.ZodObject<{
add: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
remove: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strict>>;
response: z.ZodOptional<z.ZodObject<{
add: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
remove: z.ZodOptional<z.ZodArray<z.ZodString>>;
}, z.core.$strict>>;
}, z.core.$strict>>;
extensions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
}, z.core.$strict>;
/**
* Runtime-validated gateway metadata.
*
* For per-route declarations use the contract-generic alias `GatewayMetadata<Contract>`
* exported from `./gatewayTypes.ts` — the runtime schema is intentionally lenient
* about header/query keys (case-insensitive HTTP, dynamic keys); the type-level
* narrowing is what guides authoring.
*/
export type GatewayMetadataValue = z.infer<typeof gatewayMetadataSchema>;