dryvPacks

@dryv/zodv0.1.0

zod schemas with field limits, formats and invariants.

Zod schemasValidationInjectPublished 7 days ago2 downloads

dryv pack add @dryv/zod
2.2 KBRaw ↗
yaml
version: dryv.pack/v1alpha1
key: inject.validation.zod
source: templates

info:
  title: Zod schemas
  version: 0.1.0
  description: Generates a zod schema and its inferred type for every schema and enum.
  purpose: validation
  summary: zod schemas with field limits, formats and invariants.
  languages: [typescript]
  frameworks: [zod]
  tags: [schemas, validation]

plugins:
  - name: jinja
    extensions: [.j2]

selections:
  enums:
    subject: property.enum
    scope: each

  schemas:
    subject: schema
    scope: each

templates:
  enum:
    $ref: '#/selections/enums'
    output:
      name: $(subject.name.kebab)
      symbol: $(subject.name.pascal)Schema

  schema:
    $ref: '#/selections/schemas'
    output:
      name: $(subject.name.kebab)
      path:
        - $(group.name.kebab)
      symbol: $(subject.name.pascal)Schema
    imports:
      - $ref: '#/templates/enum'
      - $ref: '#/templates/schema'

  index:
    exports:
      - $ref: '#/templates/schema'
      - $ref: '#/templates/enum'

# The slot symbol is the zod schema. Its type is `z.infer<typeof XSchema>`, also exported,
# but a slot carries one symbol, so this pack doesn't claim `schema.types`.
provides:
  schema.validation:
    $ref: '#/templates/schema'

# shared:js-package-manager:start
choose:
  js.package_manager: { options: [pnpm, npm, bun, yarn] }
# shared:js-package-manager:end

# Libraries the generated code imports, and the formatter its format action runs.
dependencies:
  runtime:
    zod: ^3.24
  dev:
    prettier: "*"

# shared:js-prettier-actions:start
actions:
  format:
    stage: files
    extensions: [.ts]
    commands:
      - run: [(pnpm|yarn), dlx, [email protected], --ignore-path, .prettier-none, --write, $(files)]
      - run: [npm, exec, --yes, --package, [email protected], --, prettier, --ignore-path, .prettier-none, --write, $(files)]
      - run: [bun, x, [email protected], --ignore-path, .prettier-none, --write, $(files)]
  install:
    stage: final
    dependencies:
      args:
        - dev: { (pnpm|yarn): [-D], bun: [--dev], npm: [--save-dev] }
        - { pinned: "$(name)@$(version)", any: "$(name)" }
    commands:
      - run: [(pnpm|bun|yarn), add]
      - run: [npm, install]
# shared:js-prettier-actions:end