Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@ddd-ts-kit/drizzle

Latest version: v0.115.0

Overview

Last scanned
26 Nov 2026
Published
26 Nov 2026
npm package Publisher: gbourgeat
25 Stars
1 Forks
69 Versions
6.1K Downloads
TypeScript Repo language

Scan summary

@ddd-ts-kit/drizzle was last scanned on 26 Nov 2026 at version 0.115.0. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 69 versions; the latest was published on 26 Nov 2026.
  • Findings: No rules fired in version 0.115.0.
  • Downloads: 6,132 downloads.

Versions

69 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.115.0 LATEST 26 Nov 2026 No rules fired
0.114.1 19 Nov 2026 No rules fired
0.113.2 17 Nov 2026 No rules fired
0.113.1 16 Nov 2026 Not shown
0.113.0 16 Nov 2026 Not shown

No rules fired in 0.115.0

Findings

Findings for v0.115.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.115.0; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

English · Français

@ddd-ts-kit/drizzle

Drizzle adapters of the kernel and events ports on PostgreSQL: a unit of work that repositories never see, the transactional outbox store, the processed-event store, and one database schema per bounded context. Drizzle is the default persistence of the kit, not a requirement: everything here implements ports, and another ORM is another adapter passing the same contract suites.

npm i @ddd-ts-kit/drizzle drizzle-orm

Works with every drizzle PostgreSQL driver (node-postgres, postgres-js, PGlite, Neon): the functions are generic over the database type, so executor() is typed exactly like your db.

Where it sits in an application

Nothing here is imported from domain/ or application/. A handler depends on the repository port of its domain; the adapter of that port, in infrastructure/, runs its statements on the Database of the project; the platform builds the unit of work once and binds it.

A bounded context holds a handler, the repository port of the domain and the drizzle repository that implements it; createDrizzleUnitOfWork gives one object that is both the UnitOfWork the command bus runs each command in and the Database whose executor() the repository and the stores query through; it opens db.transaction() on a drizzle database of any PostgreSQL driver, whose tables drizzle-kit migrations create

The one idea to keep: every statement goes through executor(). Inside a unit of work it is the transaction of that unit of work, so the row of the aggregate, the outbox record of the event it published and the processed-event mark of a consumer commit or roll back together. Outside one (a query, a script) it is the database itself.

Schema

The tables are plain drizzle definitions: export them from the schema files drizzle-kit reads and they are created by your own migrations.

// platform/database/schema.ts
import { integer, text } from 'drizzle-orm/pg-core';
import { contextSchema, outboxTable, processedEventsTable } from '@ddd-ts-kit/drizzle/postgres';

export const outbox = outboxTable('messaging'); // messaging.outbox; no argument: public.outbox
export const processedEvents = processedEventsTable('messaging');

// contexts/order-management/infrastructure/persistence/order-management.schema.ts
export const orderManagement = contextSchema('order-management'); // schema order_management
export const orders = orderManagement.table('orders', {
  id: text('id').primaryKey(),
  status: text('status').notNull(),
  version: integer('version').notNull(),
});

outbox is indexed for the relay (pending records by next attempt, partial index); processed_events has (consumer, event_id) as its primary key.

Composition root

DrizzleContext is the handle repositories and stores run their queries on. It is generic over the drizzle database, so the project names its own database with a class, which is then the injection token:

// platform/database/database.ts
import type { PgQueryResultHKT } from 'drizzle-orm/pg-core';
import { DrizzleContext } from '@ddd-ts-kit/drizzle/postgres';

export abstract class Database extends DrizzleContext<PgQueryResultHKT> {}

This is the class the CLI writes: typed on the driver-neutral base, so the same repositories run on node-postgres in production and on PGlite in the tests, the connection being typed PgDatabase<PgQueryResultHKT>. A project bound to one driver may name its kind instead (DrizzleContext<NodePgQueryResultHKT>), which types the raw result of execute exactly.

createDrizzleUnitOfWork(db) gives one object that is both the kernel UnitOfWork and that Database. Bind it to both:

// platform/database/persistence.module.ts
import { drizzle } from 'drizzle-orm/node-postgres';
import type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
import { defineContextModule } from '@ddd-ts-kit/di';
import { IntegrationEventPublisher, ProcessedEventStore, UnitOfWork } from '@ddd-ts-kit/kernel';
import { OutboxPublisher, OutboxStore } from '@ddd-ts-kit/events';
import {
  createDrizzleUnitOfWork,
  DrizzleOutboxStore,
  DrizzleProcessedEventStore,
} from '@ddd-ts-kit/drizzle/postgres';
import { Database } from '@/platform/database/database';
import { outbox, processedEvents } from '@/platform/database/schema';

const db: PgDatabase<PgQueryResultHKT> = drizzle(process.env.DATABASE_URL);
const unitOfWork = createDrizzleUnitOfWork(db);

export const persistenceModule = defineContextModule({
  name: 'persistence',
  register(builder) {
    builder.rebind(UnitOfWork).toValue(unitOfWork);
    builder.bind(Database).toValue(unitOfWork);
    builder
      .bind(OutboxStore)
      .toFactory((resolve) => new DrizzleOutboxStore(resolve(Database), { table: outbox }));
    builder
      .rebind(ProcessedEventStore)
      .toFactory((resolve) => new DrizzleProcessedEventStore(resolve(Database), { table: processedEvents }));
    builder.rebind(IntegrationEventPublisher).toClass(OutboxPublisher, [OutboxStore]);
  },
});
// main.ts
const app = createApplication({ modules: [kernelModule(), persistenceModule, contextModule('order-management', orderManagementDeclarations)] });

List the module after kernelModule(): rebind replaces its in-memory defaults. The command bus of the kernel module runs every command in the bound UnitOfWork; handlers do not know it. contextModule of @ddd-ts-kit/di turns the declared classes of a context into its module.

A project written by the CLI holds the same wiring in two files: platform/database/persistence-over.ts builds the unit of work and the two stores once, and platform/composition/platform.module.ts binds them, the outbox publisher being given to kernelModule({ eventPublisher }).

The factories pass the tables of the messaging schema. With the tables in public, the stores need no option and the class is bound directly: builder.bind(OutboxStore).toClass(DrizzleOutboxStore, [Database]), builder.rebind(ProcessedEventStore).toClass(DrizzleProcessedEventStore, [Database]).

The relay reads the same store and hands the records to the broker:

const relay = new OutboxRelay({ store: app.resolve(OutboxStore), publisher: broker, clock: app.resolve(Clock) });
relay.start({ intervalMs: 500 });

unitOfWork.run(work) opens db.transaction and keeps the transaction in an AsyncLocalStorage; a nested run joins the outer transaction. Because append uses the current transaction, an event published by a handler that then fails is rolled back with the business write: that is the whole point of the outbox.

run is built on unitOfWorkOver of the kernel. The domain events of the aggregates saved inside it wait until work has returned, then are dispatched inside the transaction, before the commit: their handlers see every save, and what they write commits or rolls back with it. If work, a handler or the commit fails, nothing is left: no row, no outbox record, no handler run after the commit. Handlers declared after-commit run once the transaction has committed. A nested run joins the unit of work in progress: one dispatch, at the end of the outermost. Called inside the unit of work of another database, run opens its own: its events are dispatched before its own commit. The unit of work commits or rolls back as a whole: once a nested run has failed it no longer commits, and when the work caught that failure and went on the outermost run rejects with a UnitOfWorkAbortedError whose cause it is. A run called directly (a consumer, a script) has the same timing as a command. unitOfWorkContract of @ddd-ts-kit/testing/contracts proves it on PGlite, with a deferred constraint for the commit that fails. The README of @ddd-ts-kit/kernel draws this timeline (Domain events and the unit of work).

Repository

The port lives in the domain, the adapter in infrastructure. A repository receives the database, never a transaction: executor() is the transaction of the unit of work when there is one and db otherwise.

// Instead of: a transaction handed down by the caller, which every port and every handler would then carry
save(order: Order, transaction: PgTransaction<PgQueryResultHKT>): Promise<void>;

// Write: the database, whose executor() is the transaction of the unit of work in progress
constructor(private readonly database: Database) {}

The domain side, an aggregate that knows nothing of rows, and its port:

import { AggregateRoot, DomainRefusal, Repository } from '@ddd-ts-kit/kernel';

// contexts/order-management/order-management.codes.ts
export const OrderManagementCodes = {
  OrderAlreadyPlaced: 'ORDER_ALREADY_PLACED',
} as const;

// contexts/order-management/domain/errors/order-already-placed.error.ts
export class OrderAlreadyPlaced extends DomainRefusal {
  readonly code = OrderManagementCodes.OrderAlreadyPlaced;

  static forOrder(orderId: string) {
    return OrderAlreadyPlaced.refusal(`Order ${orderId} is already placed.`, { orderId });
  }
}

// contexts/order-management/domain/order.aggregate.ts
export type OrderStatus = 'open' | 'placed';

export class Order extends AggregateRoot {
  private constructor(
    id: string,
    private status: OrderStatus,
  ) {
    super(id);
  }

  static open(id: string): Order {
    return new Order(id, 'open');
  }

  /** Rebuilds a stored order: used by the mapper only. */
  static rehydrate(id: string, status: OrderStatus): Order {
    return new Order(id, status);
  }

  get currentStatus(): OrderStatus {
    return this.status;
  }

  place(): void {
    if (this.status === 'placed') {
      throw OrderAlreadyPlaced.forOrder(this.id);
    }

    this.status = 'placed';
  }
}

// contexts/order-management/domain/repositories/order.repository.ts: findById and save come from Repository
export abstract class OrderRepository extends Repository<Order> {}

The infrastructure side, the table, the mapper and the adapter:

// contexts/order-management/infrastructure/persistence/drizzle-order.repository.ts
import { and, eq } from 'drizzle-orm';
import { integer, text, type PgQueryResultHKT } from 'drizzle-orm/pg-core';
import { AggregateRoot } from '@ddd-ts-kit/kernel';
import { Repository } from '@ddd-ts-kit/kernel/declarations';
import { aggregateMapper, contextSchema, DrizzleContext, insertIgnoringConflict, optimisticUpdate } from '@ddd-ts-kit/drizzle/postgres';

// The aggregate and its port of the previous sample, reduced to their shape.
type OrderStatus = 'open' | 'placed';
declare class Order extends AggregateRoot {
  static rehydrate(id: string, status: OrderStatus): Order;
  get currentStatus(): OrderStatus;
}
abstract class OrderRepository {
  abstract findById(id: string): Promise<Order | undefined>;
  abstract save(order: Order): Promise<void>;
}

// platform/database/database.ts: the injection token of the database
abstract class Database extends DrizzleContext<PgQueryResultHKT> {}

// order-management.schema.ts: the table of the schema sample, with a typed status
const orders = contextSchema('order-management').table('orders', {
  id: text('id').primaryKey(),
  status: text('status').$type<OrderStatus>().notNull(),
  version: integer('version').notNull(),
});

type OrderRow = typeof orders.$inferSelect;

// order.mapper.ts: the row never leaves infrastructure
const OrderMapper = aggregateMapper({
  toDomain(row: OrderRow): Order {
    return Order.rehydrate(row.id, row.status);
  },

  toRow(order: Order): Omit<OrderRow, 'version'> {
    return { id: order.id, status: order.currentStatus };
  },
});

@Repository(OrderRepository)
export class DrizzleOrderRepository implements OrderRepository {
  constructor(private readonly database: Database) {}

  async findById(id: string): Promise<Order | undefined> {
    // executor(): the transaction of the unit of work in progress, or the database outside one
    const [row] = await this.database.executor().select().from(orders).where(eq(orders.id, id));

    return row === undefined ? undefined : OrderMapper.toDomain(row);
  }

  async save(order: Order): Promise<void> {
    const db = this.database.executor();

    await optimisticUpdate(order, async ({ expected, next }) => {
      const row = { ...OrderMapper.toRow(order), version: next };

      if (expected === 0) {
        return (await insertIgnoringConflict(() => db.insert(orders).values(row), orders)) ? 1 : 0;
      }

      const written = await db
        .update(orders)
        .set(row)
        .where(and(eq(orders.id, order.id), eq(orders.version, expected)))
        .returning({ id: orders.id });

      return written.length; // 0 rows: optimisticUpdate throws ConcurrencyError
    });
  }
}

In the explicit style, without the decorator, the same binding is one line of <context>.module.ts: builder.bind(OrderRepository).toClass(DrizzleOrderRepository, [Database]).

The save above is written out to show each statement. saveAggregate does the same in one call: it takes a table that keeps the key under id and the version under version, and one save, the aggregate, the columns its mapper gave, the scope and the clock that stamp the audit columns. saveTenantAggregate is the same for a table every tenant shares: it writes the row in the tenant of the work in progress and confines its update to that tenant. A generated repository saves this way and holds nothing else of the plumbing.

async save(invoice: Invoice): Promise<void> {
  await saveAggregate(this.database, invoices, {
    aggregate: invoice,
    row: InvoiceMapper.toRow(invoice),
    scope: this.scope,
    clock: this.clock,
  });
}

optimisticUpdate gives the version to expect and the version to write, raises a ConcurrencyError (a DomainError with code CONCURRENCY_CONFLICT) when the guarded statement wrote no row, and moves order.version on otherwise. If your database was created with a relational schema (drizzle(url, { schema })), declare Database as DrizzleContext<PgQueryResultHKT, typeof schema> to keep executor().query.

expected Statement No row written means
0: never saved insertIgnoringConflict: INSERT ... ON CONFLICT DO NOTHING, then ON CONFLICT (id) DO NOTHING when it wrote nothing the id is taken
n UPDATE ... SET version = n + 1 WHERE id = ... AND version = n another transaction saved it since it was read

insertIgnoringConflict(() => db.insert(orders).values(row), orders) inserts unless the primary key exists, as the table declares it (primaryKeyOf(orders), the id, or every column of a key that holds the tenant), and says whether it did. It takes two statements at most, which is why the insert is given as a function. Neither conflict clause is enough alone. Without a target, PostgreSQL also skips a row that takes a value another row holds under a unique constraint (an email), and the save reads as a lost update. With the key as its target, two first saves of one aggregate made at once (a request delivered twice) meet on the other unique index first, and the one that lost is refused for a value no other row holds, where it lost an update. So the first statement names no target, and only when it wrote nothing the second names the key: a key that is held writes no row, which optimisticUpdate raises as a ConcurrencyError, and a value another row holds is refused by the database, which it raises as a UniqueViolationError (code CONFLICT, 409), as for an update that takes such a value.

A lock on a business key

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @ddd-ts-kit/drizzle

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Critical Apache HTTP Server Flaw Exposes Web Servers to RCE (1)
CVE

CVE-2026-119618: Critical Apache HTTP Server Flaw Exposes Web Servers to Remote Code Execution

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

Frame 2085668439 (1)
Group 1261154229