@swarmion/serverless-contracts
Version:
Generate and use type-safe contracts between your Serverless services.
18 lines • 1.69 kB
TypeScript
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { O } from 'ts-toolbelt';
import { StringDictionaryJSONSchema } from '../../../types/constrainedJSONSchema';
import { GenericApiGatewayContract } from '../apiGatewayContract';
export type PathParametersType<Contract extends GenericApiGatewayContract> = Contract['pathParametersSchema'] extends StringDictionaryJSONSchema ? FromSchema<Contract['pathParametersSchema']> : undefined;
export type QueryStringParametersType<Contract extends GenericApiGatewayContract> = Contract['queryStringParametersSchema'] extends StringDictionaryJSONSchema ? FromSchema<Contract['queryStringParametersSchema']> : undefined;
export type HeadersType<Contract extends GenericApiGatewayContract> = Contract['headersSchema'] extends StringDictionaryJSONSchema ? FromSchema<Contract['headersSchema']> : undefined;
export type CustomRequestContextType<Contract extends GenericApiGatewayContract> = Contract['requestContextSchema'] extends JSONSchema ? FromSchema<Contract['requestContextSchema']> : undefined;
export type BodyType<Contract extends GenericApiGatewayContract> = Contract['bodySchema'] extends JSONSchema ? FromSchema<Contract['bodySchema']> : undefined;
export type OutputsType<Contract extends GenericApiGatewayContract> = {
[StatusCode in keyof Contract['outputSchemas']]: {
statusCode: StatusCode;
headers?: Record<string, string>;
body: Contract['outputSchemas'][StatusCode] extends JSONSchema ? FromSchema<Contract['outputSchemas'][StatusCode]> : void;
};
};
export type OutputType<Contract extends GenericApiGatewayContract> = O.UnionOf<OutputsType<Contract>>;
//# sourceMappingURL=common.d.ts.map