dryvPacks

@dryv/typeormv0.6.0

TypeORM entities with typed columns, relations, checks and indexes.

TypeORM EntitiesPersistenceInjectPublished 7 days ago2 downloads

dryv pack add @dryv/typeorm
2.9 KBRaw ↗
yaml
version: dryv.pack/v1alpha1
key: inject.persistence.typeorm
source: templates

info:
  title: TypeORM Entities
  version: 0.6.0
  description: Generates TypeORM entities with typed columns, indexes, checks and relations from entity-role schemas.
  purpose: persistence
  summary: TypeORM entities with typed columns, relations, checks and indexes.
  languages: [typescript]
  frameworks: [typeorm]
  tags: [entities, database, orm]

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

# One store per activation: the engine hands the pack only that store's entities.
capabilities: { persistence: true, stores: true }

inputs:
  naming_strategy:
    type: string
    default: snake
    description: Column naming, `snake` (cart_id) or `camel` (cartId).

# Enums and named property types come from the bound types pack (inject/types/typescript).
needs:
  property.enum.types: { required: true }
  property.types: { required: true }

selections:
  # Persisted schemas: the entity role.
  entities:
    subject: schema
    filter:
      all: { role: entity }
    scope: each
  all-entities:
    subject: schema
    filter:
      all: { role: entity }
    scope: all

templates:
  entity:
    $ref: '#/selections/entities'
    output:
      name: $(subject.name.kebab)
      path:
        - $(group.name.kebab)
      symbol: $(subject.name.scoped)Entity
    imports:
      - $ref: '#/needs/property.enum.types'
      - $ref: '#/needs/property.types'
      - $ref: '#/templates/entity'

  # common/schema/entities/testing/entities.integrity.spec.ts (Vitest + pg-mem): every entity
  # synchronizes into Postgres and maps exactly its contract's tables, keys and constraints.
  integrity:
    $ref: '#/selections/all-entities'
    output:
      destination: test
    imports:
      - $ref: '#/templates/entity'
        members: true

provides:
  schema.persistence:
    $ref: '#/templates/entity'

# 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:
    reflect-metadata: ^0.2
    typeorm: ^0.3
  dev:
    prettier: "*"
    pg: ^8
    pg-mem: ^3
    vitest: ^3

# 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