| 1 | import type * as appsync from "@distilled.cloud/aws/appsync"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Runtime binding for `appsync:EvaluateMappingTemplate` — evaluate a VTL |
| 7 | * request/response mapping template against a mock context without touching |
| 8 | * a deployed resolver. The VTL twin of {@link EvaluateCode}, for resolvers |
| 9 | * defined with `requestMappingTemplate`/`responseMappingTemplate` instead of |
| 10 | * `APPSYNC_JS` code. |
| 11 | * |
| 12 | * An account-level operation: the binding takes no resource. Template |
| 13 | * *evaluation* errors do not fail the effect — they surface on the |
| 14 | * response's `error` field. Provide `AppSync.EvaluateMappingTemplateHttp` |
| 15 | * on the hosting function's Effect to implement the binding. |
| 16 | * |
| 17 | * ### Evaluating Mapping Templates |
| 18 | * **Example:** Render a VTL template against a mock context |
| 19 | * ```typescript |
| 20 | * // init — account-level binding takes no resource |
| 21 | * const evaluateTemplate = yield* AppSync.EvaluateMappingTemplate(); |
| 22 | * |
| 23 | * // runtime |
| 24 | * const result = yield* evaluateTemplate({ |
| 25 | * template: `{ "sum": $util.toJson($ctx.args.a + $ctx.args.b) }`, |
| 26 | * context: JSON.stringify({ arguments: { a: 2, b: 3 } }), |
| 27 | * }); |
| 28 | * // JSON.parse(result.evaluationResult!) → { sum: 5 } |
| 29 | * ``` |
| 30 | * |
| 31 | * @binding |
| 32 | */ |
| 33 | export interface EvaluateMappingTemplate extends Binding.Service< |
| 34 | EvaluateMappingTemplate, |
| 35 | "AWS.AppSync.EvaluateMappingTemplate", |
| 36 | () => Effect.Effect< |
| 37 | ( |
| 38 | request: appsync.EvaluateMappingTemplateRequest, |
| 39 | ) => Effect.Effect< |
| 40 | appsync.EvaluateMappingTemplateResponse, |
| 41 | appsync.EvaluateMappingTemplateError |
| 42 | > |
| 43 | > |
| 44 | > {} |
| 45 | export const EvaluateMappingTemplate = Binding.Service<EvaluateMappingTemplate>( |
| 46 | "AWS.AppSync.EvaluateMappingTemplate", |
| 47 | ); |