This file is for AI coding agents (and humans who like density) working on
@imqueue/pg-prisma. It captures how the codebase is built, tested and
structured, plus the invariants that are easy to get wrong. Read it before
making changes. For contribution process/terms see
CONTRIBUTING.md; for end-user docs see the
README and https://imqueue.org/.
@imqueue/pg-prisma is the Prisma/Postgres persistence toolkit of the @imqueue
framework. It provides Prisma client extensions, Postgres operational helpers,
and a Prisma generator that emits typed
@imqueue/rpc model & repository classes.
The generated model classes validate their inputs with
@imqueue/validation.
- ESM only,
"type": "module". Useimport, notrequire(). Import sibling modules with the.jsextension (NodeNext resolves it to the.tssource), e.g.import { silently } from './sql-log.js'. - TypeScript,
module/moduleResolution: nodenext,target: es2024,verbatimModuleSyntax: true,isolatedModules: true,strict: true. Useimport type/import { type X }for type-only imports. - Node ≥ 22.12. Prisma 7+.
@prisma/clientis a peer dependency. The extension modules import thePrismanamespace /PrismaClienttype from@prisma/client/extension— the official entry for shareable Client extensions. It resolves without runningprisma generateand works no matter where the consumer generates their client (default@prisma/clientoutput or a custom output path), so this package needs no schema or generated client of its own to build. Runtime deps are kept minimal:pg(down-migrations) and@prisma/generator-helper(the generator). Do not add heavyweight deps.- Lint/format:
oxlint+oxfmt. Runnpm run formatbefore committing; CI checksnpm run format:check. - Build emits
.js/.d.ts/.js.mapnext to sources; these are gitignored, not committed (buildrunsclean-compiledfirst). Never commit compiled output. removeCommentsis intentionallyfalse— downstream tooling and the generated output rely on doc-blocks surviving compilation. Keep it that way.
npm install
npm run build # clean-compiled + tsc (emits alongside sources)
npm test # build + node:test over every test/**/*.spec.js
npm run lint # oxlint
npm run format # oxfmt (write) | npm run format:check (verify)
npm run test-coverage # tests + experimental coverage summary
npm run test-lcov # writes coverage/lcov.infoUnit tests (test/**/*.spec.ts, run compiled) cover the pure helpers
(prettifySql, accessWhere). The extension and installer modules that touch a
live database are exercised by the consuming service's integration suite, not
here.
| Path | Role |
|---|---|
index.ts |
Public entry: export * from './src/index.js' |
src/index.ts |
Barrel re-exporting the public API |
src/soft-delete.ts |
Prisma soft-delete query extension. |
src/audit.ts |
Prisma audit-trail query extension. |
src/authorship.ts |
Prisma authorship-stamping query extension. |
src/access-scope.ts |
accessWhere() row-level access-scope filter composer. |
src/archive.ts |
Row-archiving installer (aged rows → mirror archive schema, pg_cron). |
src/change-notify.ts |
Postgres row-change NOTIFY trigger installer. |
src/migrate-down.ts |
migrateDown() — undo applied Prisma migrations; also a CLI. |
src/pretty-sql.ts |
prettifySql() SQL pretty-printer for query logging. |
src/sql-log.ts |
Cooperative SQL-log suppression (silently, isSqlLogSuppressed). |
src/codegen.ts |
Prisma generator: emits typed @imqueue/rpc models & repositories. |
test/** |
node:test specs (*.spec.ts). |
- Extension ordering matters. In Prisma's query extensions the
first-added extension's hook is the outermost. When composing
auditwithsoftDelete, addauditfirst so soft-deletes still reach the audit trail. - The generator's emitted code assumes consumer conventions. It imports the
consumer's generated modules via
#generated/*, the client instance via#prisma, RPC decorators from@imqueue/rpc, and validation decorators from@imqueue/validation. Keep those import strings stable — they are the generator's output contract. migrateDown()is side-effect-pure at import time. The generator and the migrate-down CLI only run when their module is executed directly (import.meta.url === argv[1]); importing the package barrel must have no side effects and must not require the dev-only@prisma/generator-helper.silently()flips a shared module flag — it is for pre-request one-offs (startup DDL), not interleaved concurrent traffic.
GPL-3.0. Commercial licensing for closed-source products: https://imqueue.com/.