pg-prisma package

Prisma and Postgres building blocks for @imqueue services.

Two kinds of thing live here, and they are used at different times.

Query extensions wrap a PrismaClient and change what queries do: softDelete turns deletes into deletedAt stamps and hides stamped rows, accessScope narrows every read to the records the caller is allowed to see, authorship stamps who created, updated or deleted a row, audit writes a trail of every write to a table you nominate, and isoDates serializes Date values so they survive the RPC wire as ISO strings. Each is independent; each is driven by a per-model config the code generator emits from your Prisma schema.

Installers and tools run once at startup or by hand rather than per query: installArchiving moves aged rows into a mirror archive schema on a pg_cron schedule, installChangeTriggers makes Postgres NOTIFY on every row change, migrateDown rolls applied migrations back (Prisma has no native "down"), and prettifySql/silently/isSqlLogSuppressed are query-logging helpers.

Ordering matters when extensions are combined, because Prisma runs the first-added query hook outermost. audit has to be added first if it is to see operations that softDelete reroutes; the individual pages say so where it applies.

The Prisma generator that emits typed @imqueue/rpc models from your schema ships separately at @imqueue/pg-prisma/codegen and is invoked by Prisma, not imported — it is deliberately absent from this barrel.

Functions

Function

Description

accessScope(input)

Build the query extension that restricts queries to the records the active access levels allow.

accessWhere(where, config, resolvers)

Compose the access-scope where clause for a single model.

audit(input)

Build the query extension that records every write to an audited model.

authorship(input)

Build the query extension that stamps who created, updated or deleted a row.

installArchiving(options)

Install the row-archiving machinery: a mirror archive schema, its settings table, the sweep function, and — best effort — a pg_cron schedule to run it.

installChangeTriggers(client, input)

Install Postgres triggers that NOTIFY on every row change in the given tables.

isoDates()

Build the query extension that serializes every Date in a query result to an ISO-8601 string.

isSqlLogSuppressed()

Whether SQL logging is currently suppressed.

migrateDown(options)

Roll back the most recently applied Prisma migrations.

prettifySql(sql)

Format a one-line SQL string so it is readable in a log.

silently(fn)

Run fn with SQL logging suppressed.

softDelete(input)

Build the query extension that turns deletes into deletedAt stamps and hides stamped rows from reads.

Interfaces

Interface

Description

AccessScopeOptions

Everything accessScope() needs to build its extension.

ArchivableModel

One watched table to seed into the archive settings table.

ArchiveClient

The raw-SQL surface this installer needs (a Prisma client or its tx).

AuditColumns

Column names in the audit target table.

AuditConfig

Where the audit trail is written, and under which column names.

AuditOptions

Everything audit() needs to build its extension.

AuthorshipColumns

Which columns on one model carry authorship, and which one triggers a delete stamp.

AuthorshipOptions

Everything authorship() needs to build its extension.

ChangeTriggerConfig

Which tables notify, and under which Postgres object names.

InstallArchiveOptions

Everything installArchiving() needs.

MigrateDownOptions

Everything migrateDown() needs: no globals and no environment are read.

MigrateDownResult

What migrateDown() did.

RawClient

A RawExecutor that can also open a transaction.

RawExecutor

The raw-SQL surface used to install triggers (a Prisma client or its tx).

SoftDeleteOptions

Everything softDelete() needs to build its extension.

Variables

Variable

Description

AuditAction

The three kinds of write recorded in the audit trail.

CHANGE_NOTIFY_CHANNEL

Default Postgres NOTIFY channel the change triggers emit on.

CHANGE_NOTIFY_FUNCTION_NAME

Default name of the trigger's plpgsql notify function.

CHANGE_NOTIFY_TRIGGER_NAME

Default name of the per-table change trigger.

Type Aliases

Type Alias

Description

AccessScopeModels

Per-model access-scope config: model → level → columns. A record is in scope for a level when ANY of the level's columns matches (OR); a model is in scope when EVERY active level matches (AND). See the generated ACCESS_SCOPE_MODELS.

AccessScopeResolver

Resolves the current request's value for one access level: - undefined — the level does not constrain this request (skip it), - null — active but there is no value → deny (match nothing), - a string — match rows where a scope column equals it, - an array — match rows where a scope column is IN it (empty → deny).

AuthorshipModels

Which models carry authorship, keyed by Prisma model name.

SoftDeleteModels

Which models are soft-deleted, and which column carries the stamp.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.