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

Generates @nestjs/mongoose schema classes from schemas with the entity role.

IRGenerated
facets.storage.name (or the schema name in snake case)@Schema({ collection })
facets.storage.primary_key_id; a system uuid key gets default: () => randomUUID()
facets.storage.indexes<Model>Schema.index({ … }, { name, unique })
schema invariants (form)a pre("validate") hook that invalidates the document; opaque rules get a comment instead
string limits and patternminlength, maxlength, match (the first pattern)
number range, integersmin, max, an integer validator
enumsenum: Object.values(<Enum>)
instants, dates, timesDate
relations (relation)the id as a string with ref: "<TargetModel>"; the reverse side isn't stored
records, nested schemas, durationsSchema.Types.Mixed

Each model file exports the class, <Model>Document (HydratedDocument<…>) and <Model>Schema.

Test: bun scripts/test-pack.ts inject/persistence/mongoose renders the fixture IR, typechecks against the real @nestjs/mongoose and mongoose, then builds the schemas and validates valid and invalid documents (no database needed).

Use it

The executable Usage fixture shows the current source collection, destination and pack activation for this pack.

Slots

  • provides schema.persistence
  • provides property.enum.types