#!/usr/bin/env -S node --conditions=bun import { runGeneratorCli } from "@distilled.cloud/dev/codegen/cli"; /** * generate — turn the Smithy JSON model in .generated-specs into the Temporal * Effect SDK. * * Input: .generated-specs/temporal.json (written by scripts/convert.ts) * Output: src/services/temporal.ts + src/services/index.ts * * The smithy→SDK compiler and CLI pipeline live in * `@distilled.cloud/dev/codegen`; this script is Temporal's provider spec. * Temporal keeps the wire's camelCase member names on the TS surface, so no * member renaming or wire dictionaries appear here. */ import type { SdkSpec } from "@distilled.cloud/dev/codegen/generator"; const NULLABLE_TRAIT = "com.distilled.openapi#nullable"; const ERROR_MATCHERS_TRAIT = "com.distilled.openapi#errorMatchers"; const RAW_RESPONSE_TRAIT = "com.distilled.openapi#rawResponse"; const SENSITIVE_TRAIT = "smithy.api#sensitive"; /** Temporal's provider spec for the shared smithy→SDK compiler. */ const temporalSpec: SdkSpec = { nullableTrait: NULLABLE_TRAIT, errorMatchersTrait: ERROR_MATCHERS_TRAIT, extraBindings: [ { // Sole member of a synthesized wrapper for bare array/scalar response // bodies; as the response's only member, the response IS the payload. trait: RAW_RESPONSE_TRAIT, binding: "rawResponse", pipe: "T.RawResponse()", rootPipe: "T.RawResponseRoot()", }, ], // Sensitive strings (connection URIs, passwords, API keys): the schema // member carries T.SensitiveValue; the REST protocol delivers Redacted // values and accepts string | Redacted on input. memberTraitPipes: { [SENSITIVE_TRAIT]: "T.SensitiveValue", }, memberTsType: (m) => SENSITIVE_TRAIT in m.traits ? `string | Redacted.Redacted${m.nullable ? " | null" : ""}` : undefined, // Unions surface as TS type unions over an opaque schema — the REST // protocol passes union content through verbatim (wire names ARE the TS // names for Temporal), so no runtime case discrimination is needed. union: ({ name, caseTargets, tsRef }) => [ `export type ${name} = ${caseTargets.map(tsRef).join(" | ") || "unknown"};`, `export const ${name} = S.Unknown as any as S.Schema<${name}>;\n`, ], // One pagination profile: cursor mode (inputToken `nextPageToken`), // traversed by core's paginateCursor. paginationProfiles: { cursor: { strategy: "paginateCursor", itemsFallback: "items", }, }, operationDecl: { contextType: "TemporalOpContext", commonErrorType: "TemporalOpError", serviceErrors: "TemporalServiceErrors", protocol: "TemporalProtocol", retry: "Retry.Retry", }, sourceNote: ".generated-specs (specs/spec-mirror-temporal)", // Sensitive member types reference Redacted; pull the import in when used. postProcess: (code) => code.includes("Redacted.Redacted<") ? code.replace( `import * as S from "@distilled.cloud/core/schema-lite";\n`, `import * as S from "@distilled.cloud/core/schema-lite";\nimport * as Redacted from "effect/Redacted";\n`, ) : code, }; runGeneratorCli({ description: "Generate the Temporal Effect SDK from the Smithy model", convert: () => import("./convert.ts"), root: `${import.meta.dirname}/..`, // patches/ holds OpenAPI-document patches consumed by scripts/convert.ts; // there is no smithy-model patch chain. patchesDir: false, spec: () => temporalSpec, });