dryvPacks

@dryv/mongoosev0.1.0

@nestjs/mongoose schema classes with typed props, references, indexes and invariants.

Mongoose ModelsPersistenceInjectPublished 7 days ago2 downloads

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

info:
  title: Mongoose Models
  version: 0.1.0
  description: Generates @nestjs/mongoose schema classes with typed props, validation, references, indexes and invariants from entity-role schemas.
  purpose: persistence
  summary: "@nestjs/mongoose schema classes with typed props, references, indexes and invariants."
  languages: [typescript]
  frameworks: [mongoose, nestjs]
  tags: [models, database, odm, mongodb]

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

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

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

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

  model:
    $ref: '#/selections/models'
    output:
      name: $(subject.name.kebab)
      path:
        - $(group.name.kebab)
      symbol: $(subject.name.pascal)Model
    imports:
      - $ref: '#/templates/enum'
      - $ref: '#/templates/model'

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

provides:
  schema.persistence:
    $ref: '#/templates/model'
  property.enum.types:
    $ref: '#/templates/enum'

# 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:
    '@nestjs/common': ^11
    '@nestjs/mongoose': ^11
    mongoose: ^8
    reflect-metadata: ^0.2
    rxjs: ^7
  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