@swarmion/serverless-contracts
Version:
Generate and use type-safe contracts between your Serverless services.
73 lines • 2.4 kB
TypeScript
import { JSONSchema } from 'json-schema-to-ts';
import type { EventPattern, NativePattern } from './types/patterns';
/**
* EventBridgeContract:
*
* a contract used to define a type-safe interaction between AWS Services through EventBridge.
*
* Main features:
* - input and output dynamic validation with JSONSchemas on both end of the contract;
* - type inference for both input and output;
* - generation of a contract document that can be checked for breaking changes;
*/
export declare class EventBridgeContract<Sources extends readonly string[] = readonly string[], EventType extends string = string, PayloadSchema extends JSONSchema = JSONSchema> {
id: string;
contractType: "eventBridge";
sources: Sources;
eventType: EventType;
payloadSchema: PayloadSchema;
/**
* a native event pattern:
* ```ts
* {
* source: string[];
* 'detail-type': string[];
* }
* ```
*/
nativePattern: NativePattern;
/**
* an event pattern accepted by the CDK:
* ```ts
* {
* source: string[];
* detailType: string[];
* }
* ```
*/
pattern: EventPattern;
/**
* Builds a new EventBridgeContract contract
*/
constructor({ id, sources, eventType, payloadSchema, }: {
/**
* A unique id to identify the contract among stacks. Beware uniqueness!
*/
id: string;
/**
* The sources of the event.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*
* @type string[]
*/
sources: Sources;
/**
* The event type.
*
* @type string
*/
eventType: EventType;
/**
* A JSONSchema used to validate the payload and infer its type.
*
* Please note that the `as const` directive is necessary to properly infer the type from the schema.
* See https://github.com/ThomasAribart/json-schema-to-ts#fromschema.
*
* Also please note that for Typescript reasons, you need to explicitly pass `undefined` if you don't want to use the schema.
*/
payloadSchema: PayloadSchema;
});
}
//# sourceMappingURL=eventBridgeContract.d.ts.map