| 1 | import type * as schemas from "@distilled.cloud/aws/schemas"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Schema } from "./Schema.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Runtime binding for `schemas:ExportSchema`. |
| 8 | * |
| 9 | * Exports the bound {@link Schema} as a JSONSchema Draft 4 document — |
| 10 | * useful when a function needs a portable validation schema for an event |
| 11 | * contract that is registered as OpenAPI 3. The registry and schema names |
| 12 | * are injected from the binding. Provide the implementation with |
| 13 | * `Effect.provide(AWS.Schemas.ExportSchemaHttp)`. |
| 14 | * |
| 15 | * Note: AWS only allows exporting discovered or AWS-managed schemas |
| 16 | * (registries `discovered-schemas` / `aws.events`). Calling it on a |
| 17 | * custom-registry schema fails with a typed `ForbiddenException` |
| 18 | * (`You cannot export non discovered or non aws managed schemas.`). |
| 19 | * ### Reading Schemas |
| 20 | * **Example:** Export As JSONSchema Draft 4 |
| 21 | * ```typescript |
| 22 | * // init — bind the operation to the schema |
| 23 | * const exportSchema = yield* AWS.Schemas.ExportSchema(schema); |
| 24 | * |
| 25 | * // runtime |
| 26 | * const { Content } = yield* exportSchema({ Type: "JSONSchemaDraft4" }); |
| 27 | * const jsonSchema = JSON.parse(Content!); |
| 28 | * ``` |
| 29 | * |
| 30 | * @binding |
| 31 | */ |
| 32 | export interface ExportSchema extends Binding.Service< |
| 33 | ExportSchema, |
| 34 | "AWS.Schemas.ExportSchema", |
| 35 | (schema: Schema) => Effect.Effect< |
| 36 | (request?: { |
| 37 | /** The version of the schema to export. Defaults to the latest. */ |
| 38 | SchemaVersion?: string; |
| 39 | /** |
| 40 | * The target format. `JSONSchemaDraft4` is the only supported value. |
| 41 | * @default "JSONSchemaDraft4" |
| 42 | */ |
| 43 | Type?: string; |
| 44 | }) => Effect.Effect<schemas.ExportSchemaResponse, schemas.ExportSchemaError> |
| 45 | > |
| 46 | > {} |
| 47 | export const ExportSchema = Binding.Service<ExportSchema>( |
| 48 | "AWS.Schemas.ExportSchema", |
| 49 | ); |