@ddd-ts-kit/drizzle 0.110.0 → 0.111.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.fr.md +65 -10
- package/README.md +61 -10
- package/dist/postgres/locks/advisory-lock.d.ts +16 -0
- package/dist/postgres/locks/advisory-lock.d.ts.map +1 -0
- package/dist/postgres/locks/advisory-lock.js +19 -0
- package/dist/postgres/locks/advisory-lock.js.map +1 -0
- package/dist/postgres/locks/drizzle-locking-context.d.ts +7 -0
- package/dist/postgres/locks/drizzle-locking-context.d.ts.map +1 -0
- package/dist/postgres/locks/drizzle-locking-context.js +2 -0
- package/dist/postgres/locks/drizzle-locking-context.js.map +1 -0
- package/dist/postgres/locks/try-advisory-lock.d.ts +10 -0
- package/dist/postgres/locks/try-advisory-lock.d.ts.map +1 -0
- package/dist/postgres/locks/try-advisory-lock.js +15 -0
- package/dist/postgres/locks/try-advisory-lock.js.map +1 -0
- package/dist/postgres/read-model/drizzle-read-model-table.d.ts.map +1 -1
- package/dist/postgres/read-model/drizzle-read-model-table.js +19 -1
- package/dist/postgres/read-model/drizzle-read-model-table.js.map +1 -1
- package/dist/postgres/read-model/drizzle-stamped-rows.d.ts +4 -1
- package/dist/postgres/read-model/drizzle-stamped-rows.d.ts.map +1 -1
- package/dist/postgres/read-model/drizzle-stamped-rows.js +14 -13
- package/dist/postgres/read-model/drizzle-stamped-rows.js.map +1 -1
- package/dist/postgres/read-model/like-pattern.d.ts +2 -2
- package/dist/postgres/read-model/like-pattern.d.ts.map +1 -1
- package/dist/postgres/read-model/like-pattern.js +1 -1
- package/dist/postgres/read-model/like-pattern.js.map +1 -1
- package/dist/postgres/read-model/predicate-to-drizzle.d.ts +1 -1
- package/dist/postgres/read-model/predicate-to-drizzle.d.ts.map +1 -1
- package/dist/postgres/read-model/predicate-to-drizzle.js +11 -3
- package/dist/postgres/read-model/predicate-to-drizzle.js.map +1 -1
- package/dist/postgres/read-model/row.mapper.d.ts +2 -0
- package/dist/postgres/read-model/row.mapper.d.ts.map +1 -1
- package/dist/postgres/read-model/row.mapper.js +4 -0
- package/dist/postgres/read-model/row.mapper.js.map +1 -1
- package/dist/postgres.d.ts +3 -0
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +3 -0
- package/dist/postgres.js.map +1 -1
- package/package.json +5 -5
package/README.fr.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[English](README.md) · **Français**
|
|
2
|
-
<!-- translation-of: README.md sha256:
|
|
2
|
+
<!-- translation-of: README.md sha256:a91c2a406c27407d -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/drizzle
|
|
5
5
|
|
|
@@ -335,6 +335,49 @@ contrainte d'unicité (un e-mail), et l'enregistrement se lit comme une mise à
|
|
|
335
335
|
Nommée, cette ligne est refusée par la base, et `optimisticUpdate` lève `UniqueViolationError`
|
|
336
336
|
(code `CONFLICT`, 409), comme pour une mise à jour qui prend une telle valeur.
|
|
337
337
|
|
|
338
|
+
### Un verrou sur une clé métier
|
|
339
|
+
|
|
340
|
+
La concurrence optimiste protège une ligne qui existe. Une décision prise sur des lignes qui
|
|
341
|
+
n'existent pas encore (compter les réservations d'un créneau puis en insérer une, donner le
|
|
342
|
+
numéro suivant d'une séquence par *tenant*) n'a pas de version à comparer : deux unités de travail
|
|
343
|
+
lisent le même compte et écrivent toutes les deux. `advisoryLock(context, key, { tenant })` les
|
|
344
|
+
met en file : il attend qu'aucune autre transaction ne tienne le verrou sur `key`, puis le tient
|
|
345
|
+
jusqu'à ce que l'unité de travail valide ou annule (`pg_advisory_xact_lock`). Rien ne le relâche
|
|
346
|
+
à la main.
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
// infrastructure/persistence/drizzle-invoice-numbers.repository.ts
|
|
350
|
+
import { advisoryLock } from '@ddd-ts-kit/drizzle/postgres';
|
|
351
|
+
|
|
352
|
+
async next(): Promise<number> {
|
|
353
|
+
// First in the unit of work, before the read it protects.
|
|
354
|
+
await advisoryLock(this.database, 'invoice-number', { tenant: this.scope });
|
|
355
|
+
|
|
356
|
+
return (await this.lastNumber()) + 1;
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
- **La clé est un texte**, que PostgreSQL hache vers le nombre de 64 bits qu'il verrouille
|
|
361
|
+
(`hashtextextended(text, 0)`). Avec `tenant`, un `ExecutionScope`, le texte est
|
|
362
|
+
`tenant:<id>:<key>` (`tenantKey` du kernel) : deux *tenants* ne s'attendent jamais, et un
|
|
363
|
+
travail qui ne nomme aucun *tenant* est refusé. Deux textes de même hachage, environ une paire
|
|
364
|
+
sur 2^64, s'attendent comme le ferait une seule clé : une attente, jamais une réponse fausse.
|
|
365
|
+
- **Dans une unité de travail seulement.** Hors d'une unité de travail, le verrou serait relâché
|
|
366
|
+
à la fin de son instruction : `AdvisoryLockOutsideUnitOfWorkError`. Garder l'isolation par
|
|
367
|
+
défaut, `read committed` : la lecture qui suit le verrou voit alors ce que le détenteur
|
|
368
|
+
précédent a validé, là où `repeatable read` et `serializable` lisent à l'instant où le verrou
|
|
369
|
+
a été demandé.
|
|
370
|
+
- **`tryAdvisoryLock(context, key, { tenant })`** n'attend pas : `true` quand il a pris le
|
|
371
|
+
verrou, `false` quand une autre transaction le tient (`pg_try_advisory_xact_lock`).
|
|
372
|
+
- **Un cas d'usage n'importe aucun *package* d'ORM.** Le verrou se place dans la méthode du
|
|
373
|
+
*repository* qui en a besoin, ou derrière un port du contexte (`InvoiceNumbering.reserve()`)
|
|
374
|
+
dont l'adaptateur est ce seul appel et dont le *fake* ne fait rien.
|
|
375
|
+
- PostgreSQL seulement. Dans un projet multitenant, `tenancy/scoped-statement` accepte le
|
|
376
|
+
*helper* et signale un `pg_advisory_xact_lock` écrit à la main, comme tout SQL brut.
|
|
377
|
+
- Tenu au contrat `advisoryLockContract` de `@ddd-ts-kit/testing/contracts`. L'attente d'une
|
|
378
|
+
seconde unité de travail est prouvée sur un vrai serveur : PGlite est une seule session, où
|
|
379
|
+
la seconde attend la connexion elle-même.
|
|
380
|
+
|
|
338
381
|
## Colonnes d'audit, restriction au tenant et pages
|
|
339
382
|
|
|
340
383
|
Les formes de persistance standard du noyau, sur drizzle. `auditColumns()` et `tenantColumn()`
|
|
@@ -702,7 +745,7 @@ requête : `where` (les filtres, le périmètre de l'acteur et le *keyset* d'une
|
|
|
702
745
|
par le champ qui départage), `limit` et `offset`. `predicateToDrizzle(predicate, columns)` donne
|
|
703
746
|
une condition. `columns` associe chaque champ du modèle de lecture à sa colonne, et c'est la
|
|
704
747
|
seule source d'identifiants : chaque valeur est un paramètre encodé par sa colonne, une
|
|
705
|
-
recherche textuelle est `like $1 escape $2`, avec `%`, `_` et `\` échappés.
|
|
748
|
+
recherche textuelle est `like $1 escape $2`, avec `%`, `_` et `\` échappés. `containsIgnoringCase` et `startsWithIgnoringCase` sont la même recherche en `ILIKE`, que PostgreSQL replie avec la locale de la base (la règle et ses limites sont dans le README du kernel, « Ce que signifient des critères ») ; aucun index b-tree ne la sert, un index GIN de `pg_trgm` sur la colonne le fait.
|
|
706
749
|
|
|
707
750
|
Un port de lecture déclare ce qu'un appelant peut demander avec `defineCriteria` ; une requête
|
|
708
751
|
à vous sur la table d'un modèle de lecture planifie les critères, puis remet le plan au
|
|
@@ -737,8 +780,8 @@ abstract class Database extends DrizzleContext<PgQueryResultHKT> {}
|
|
|
737
780
|
// infrastructure/persistence/appointment-list.schema.ts
|
|
738
781
|
export const appointmentList = contextSchema('scheduling').table('appointment_list', {
|
|
739
782
|
id: text('id').primaryKey(),
|
|
740
|
-
status: text('status')
|
|
741
|
-
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' })
|
|
783
|
+
status: text('status'), // NULL dans une ligne supprimée, comme chaque colonne de la ligne
|
|
784
|
+
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' }),
|
|
742
785
|
...readModelColumns(), // last_event_id, last_event_at, last_event_version, deleted
|
|
743
786
|
});
|
|
744
787
|
|
|
@@ -759,7 +802,7 @@ export async function searchAppointments(
|
|
|
759
802
|
const { where, counted, orderBy, limit, offset } = criteriaToDrizzle(plan, COLUMNS);
|
|
760
803
|
const live = eq(appointmentList.deleted, false); // une ligne supprimée reste dans la table, marquée
|
|
761
804
|
const db = database.executor();
|
|
762
|
-
const
|
|
805
|
+
const selected = await db
|
|
763
806
|
.select(COLUMNS)
|
|
764
807
|
.from(appointmentList)
|
|
765
808
|
.where(and(where, live))
|
|
@@ -767,6 +810,11 @@ export async function searchAppointments(
|
|
|
767
810
|
.limit(limit)
|
|
768
811
|
.offset(offset);
|
|
769
812
|
|
|
813
|
+
// la contrainte de vérification tient ces colonnes pour une ligne vivante, ce que leurs types ne peuvent pas dire
|
|
814
|
+
const rows = selected.flatMap(({ id, status, startsAt }) =>
|
|
815
|
+
status === null || startsAt === null ? [] : [{ id, status, startsAt }],
|
|
816
|
+
);
|
|
817
|
+
|
|
770
818
|
// Une page par offset compte son total ; une page par curseur sait ce qui suit grâce à la ligne en trop.
|
|
771
819
|
const total = plan.kind === 'offset' ? await db.$count(appointmentList, and(counted, live)) : undefined;
|
|
772
820
|
|
|
@@ -790,7 +838,7 @@ entier est `integer` : un `bigint` revient du pilote sous forme de chaîne.
|
|
|
790
838
|
## Modèles de lecture
|
|
791
839
|
|
|
792
840
|
L'adaptateur d'un port de modèle de lecture étend `DrizzleReadModelStore` et n'ajoute rien : il
|
|
793
|
-
en reçoit `get`, `upsertIfNewer`, `delete` et `search`.
|
|
841
|
+
en reçoit `get`, `upsertIfNewer`, `updateIfNewer`, `delete` et `search`.
|
|
794
842
|
|
|
795
843
|
<!-- checked sample -->
|
|
796
844
|
```ts
|
|
@@ -812,8 +860,8 @@ abstract class Database extends DrizzleContext<PgQueryResultHKT> {}
|
|
|
812
860
|
// infrastructure/persistence/appointment-list.schema.ts
|
|
813
861
|
export const appointmentList = contextSchema('scheduling').table('appointment_list', {
|
|
814
862
|
id: text('id').primaryKey(),
|
|
815
|
-
status: text('status')
|
|
816
|
-
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' })
|
|
863
|
+
status: text('status'), // NULL dans une ligne supprimée, comme chaque colonne de la ligne
|
|
864
|
+
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' }),
|
|
817
865
|
...readModelColumns(), // last_event_id, last_event_at, last_event_version, deleted
|
|
818
866
|
});
|
|
819
867
|
|
|
@@ -834,8 +882,15 @@ export class DrizzleAppointmentList extends DrizzleReadModelStore<AppointmentRow
|
|
|
834
882
|
Chaque écriture passe par `TableReadModelStore` du noyau : une ligne n'est écrite que si son
|
|
835
883
|
événement est plus récent que celui qu'elle porte, sur l'exécuteur de l'unité de travail, si
|
|
836
884
|
bien que la ligne et la marque d'événement traité sont validées ensemble. Une ligne supprimée
|
|
837
|
-
reste dans la table avec `deleted`
|
|
838
|
-
|
|
885
|
+
reste dans la table comme une trace, avec `deleted` positionné : sa clé et son tampon, et NULL
|
|
886
|
+
dans toutes les autres colonnes, ce pour quoi chaque colonne de la ligne accepte NULL. La
|
|
887
|
+
suppression d'une clé que la table ne tient pas encore laisse la même trace. Une contrainte de
|
|
888
|
+
vérification garde entières les lignes vivantes (`check (deleted or (status is not null and
|
|
889
|
+
starts_at is not null))`), une requête à vous sur la table écarte les lignes supprimées
|
|
890
|
+
(`deleted = false`), et une table dont des colonnes refusent NULL est refusée par
|
|
891
|
+
`ReadModelTableNotReadyError`, à la construction du registre d'après sa définition et, avant
|
|
892
|
+
l'écriture de la première trace, par une lecture des colonnes que tient la base
|
|
893
|
+
([Ce que laisse une ligne supprimée](../../docs/concepts/cqrs.fr.md#la-table-dun-modèle-de-lecture-et-ce-que-laisse-une-ligne-supprimée)). `store.table` est ce que prend
|
|
839
894
|
`ProjectionRebuild` ; la reconstruction est réservée à PostgreSQL (une copie `<table>__rebuild`
|
|
840
895
|
faite `LIKE ... INCLUDING ALL`, les clés écrites entre-temps dans `<table>__touched`, l'échange
|
|
841
896
|
par renommage en une transaction) et ses garanties et limites sont dans le README de
|
package/README.md
CHANGED
|
@@ -327,6 +327,47 @@ it, PostgreSQL also skips a row that takes a value another row holds under a uni
|
|
|
327
327
|
and `optimisticUpdate` raises `UniqueViolationError` (code `CONFLICT`, 409), as for an update
|
|
328
328
|
that takes such a value.
|
|
329
329
|
|
|
330
|
+
### A lock on a business key
|
|
331
|
+
|
|
332
|
+
Optimistic concurrency protects a row that exists. A decision taken on rows that do not exist
|
|
333
|
+
yet (count the bookings of a slot then insert one, give the next number of a sequence per
|
|
334
|
+
tenant) has no version to compare: two units of work read the same count and both write.
|
|
335
|
+
`advisoryLock(context, key, { tenant })` serialises them: it waits until no other transaction
|
|
336
|
+
holds the lock on `key`, then holds it until the unit of work commits or rolls back
|
|
337
|
+
(`pg_advisory_xact_lock`). Nothing releases it by hand.
|
|
338
|
+
|
|
339
|
+
```ts
|
|
340
|
+
// infrastructure/persistence/drizzle-invoice-numbers.repository.ts
|
|
341
|
+
import { advisoryLock } from '@ddd-ts-kit/drizzle/postgres';
|
|
342
|
+
|
|
343
|
+
async next(): Promise<number> {
|
|
344
|
+
// First in the unit of work, before the read it protects.
|
|
345
|
+
await advisoryLock(this.database, 'invoice-number', { tenant: this.scope });
|
|
346
|
+
|
|
347
|
+
return (await this.lastNumber()) + 1;
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
- **The key is a text**, hashed by PostgreSQL into the 64-bit number it locks on
|
|
352
|
+
(`hashtextextended(text, 0)`). With `tenant`, an `ExecutionScope`, the text is
|
|
353
|
+
`tenant:<id>:<key>` (`tenantKey` of the kernel): two tenants never wait for each other, and
|
|
354
|
+
work that names no tenant is refused. Two texts of the same hash, about one pair in 2^64,
|
|
355
|
+
wait for each other as one key would: a wait, never a wrong answer.
|
|
356
|
+
- **Inside a unit of work only.** Outside of one the lock would be released as its statement
|
|
357
|
+
ends: `AdvisoryLockOutsideUnitOfWorkError`. Keep the default isolation, `read committed`:
|
|
358
|
+
the read that follows the lock then sees what the previous holder committed, where
|
|
359
|
+
`repeatable read` and `serializable` read as of the moment the lock was asked.
|
|
360
|
+
- **`tryAdvisoryLock(context, key, { tenant })`** does not wait: `true` when it took the lock,
|
|
361
|
+
`false` when another transaction holds it (`pg_try_advisory_xact_lock`).
|
|
362
|
+
- **A use case imports no ORM package.** The lock sits in the method of the repository that
|
|
363
|
+
needs it, or behind a port of the context (`InvoiceNumbering.reserve()`) whose adapter is
|
|
364
|
+
this one call and whose fake does nothing.
|
|
365
|
+
- PostgreSQL only. In a tenant-scoped project, `tenancy/scoped-statement` accepts the helper
|
|
366
|
+
and reports a raw `pg_advisory_xact_lock`, as any raw SQL.
|
|
367
|
+
- Held to `advisoryLockContract` of `@ddd-ts-kit/testing/contracts`. The wait of a second unit
|
|
368
|
+
of work is proven on a real server: PGlite is one session, where the second one waits for
|
|
369
|
+
the connection itself.
|
|
370
|
+
|
|
330
371
|
## Audit columns, tenant scoping and pages
|
|
331
372
|
|
|
332
373
|
The standard persistence shapes of the kernel, on drizzle. `auditColumns()` and `tenantColumn()`
|
|
@@ -685,7 +726,7 @@ query: `where` (the filters, the scope of the actor and the keyset of a cursor p
|
|
|
685
726
|
the tie-breaker), `limit` and `offset`. `predicateToDrizzle(predicate, columns)` gives one
|
|
686
727
|
condition. `columns` maps each field of the read model to its column, and is the only source
|
|
687
728
|
of identifiers: every value is a parameter encoded by its column, a text search is
|
|
688
|
-
`like $1 escape $2` with `%`, `_` and `\` escaped.
|
|
729
|
+
`like $1 escape $2` with `%`, `_` and `\` escaped. `containsIgnoringCase` and `startsWithIgnoringCase` are the same search as an `ILIKE`, which PostgreSQL folds with the locale of the database (the rule and its limits are in the README of the kernel, "What a criteria means"); no b-tree index serves it, a GIN index of `pg_trgm` on the column does.
|
|
689
730
|
|
|
690
731
|
A read port declares what a caller may ask with `defineCriteria`; a query of your own on the
|
|
691
732
|
table of a read model plans the criteria, then hands the plan to the translator:
|
|
@@ -719,8 +760,8 @@ abstract class Database extends DrizzleContext<PgQueryResultHKT> {}
|
|
|
719
760
|
// infrastructure/persistence/appointment-list.schema.ts
|
|
720
761
|
export const appointmentList = contextSchema('scheduling').table('appointment_list', {
|
|
721
762
|
id: text('id').primaryKey(),
|
|
722
|
-
status: text('status')
|
|
723
|
-
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' })
|
|
763
|
+
status: text('status'), // NULL in a deleted row, as every column of the row
|
|
764
|
+
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' }),
|
|
724
765
|
...readModelColumns(), // last_event_id, last_event_at, last_event_version, deleted
|
|
725
766
|
});
|
|
726
767
|
|
|
@@ -741,7 +782,7 @@ export async function searchAppointments(
|
|
|
741
782
|
const { where, counted, orderBy, limit, offset } = criteriaToDrizzle(plan, COLUMNS);
|
|
742
783
|
const live = eq(appointmentList.deleted, false); // a removed row stays in the table, flagged
|
|
743
784
|
const db = database.executor();
|
|
744
|
-
const
|
|
785
|
+
const selected = await db
|
|
745
786
|
.select(COLUMNS)
|
|
746
787
|
.from(appointmentList)
|
|
747
788
|
.where(and(where, live))
|
|
@@ -749,6 +790,11 @@ export async function searchAppointments(
|
|
|
749
790
|
.limit(limit)
|
|
750
791
|
.offset(offset);
|
|
751
792
|
|
|
793
|
+
// the check constraint holds these columns for a live row, which their types cannot say
|
|
794
|
+
const rows = selected.flatMap(({ id, status, startsAt }) =>
|
|
795
|
+
status === null || startsAt === null ? [] : [{ id, status, startsAt }],
|
|
796
|
+
);
|
|
797
|
+
|
|
752
798
|
// An offset page counts its total; a cursor page knows what follows from the extra row.
|
|
753
799
|
const total = plan.kind === 'offset' ? await db.$count(appointmentList, and(counted, live)) : undefined;
|
|
754
800
|
|
|
@@ -771,7 +817,7 @@ An integer is `integer`: a `bigint` comes back as a string from the driver.
|
|
|
771
817
|
## Read models
|
|
772
818
|
|
|
773
819
|
The adapter of a read model port extends `DrizzleReadModelStore` and adds nothing: it gets
|
|
774
|
-
`get`, `upsertIfNewer`, `delete` and `search` from it.
|
|
820
|
+
`get`, `upsertIfNewer`, `updateIfNewer`, `delete` and `search` from it.
|
|
775
821
|
|
|
776
822
|
<!-- checked sample -->
|
|
777
823
|
```ts
|
|
@@ -793,8 +839,8 @@ abstract class Database extends DrizzleContext<PgQueryResultHKT> {}
|
|
|
793
839
|
// infrastructure/persistence/appointment-list.schema.ts
|
|
794
840
|
export const appointmentList = contextSchema('scheduling').table('appointment_list', {
|
|
795
841
|
id: text('id').primaryKey(),
|
|
796
|
-
status: text('status')
|
|
797
|
-
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' })
|
|
842
|
+
status: text('status'), // NULL in a deleted row, as every column of the row
|
|
843
|
+
startsAt: timestamp('starts_at', { withTimezone: true, mode: 'date' }),
|
|
798
844
|
...readModelColumns(), // last_event_id, last_event_at, last_event_version, deleted
|
|
799
845
|
});
|
|
800
846
|
|
|
@@ -814,9 +860,14 @@ export class DrizzleAppointmentList extends DrizzleReadModelStore<AppointmentRow
|
|
|
814
860
|
|
|
815
861
|
Every write goes through `TableReadModelStore` of the kernel: a row is written only if its
|
|
816
862
|
event is newer than the one it holds, on the executor of the unit of work, so the row and the
|
|
817
|
-
processed-event mark commit together. A removed row stays in the table with `deleted`
|
|
818
|
-
|
|
819
|
-
|
|
863
|
+
processed-event mark commit together. A removed row stays in the table as a trace, with `deleted`
|
|
864
|
+
set: its key and its stamp, and NULL in every other column, which is why every column of the row
|
|
865
|
+
is nullable. A deletion of a key the table does not hold yet leaves the same trace. A check
|
|
866
|
+
constraint keeps the live rows whole (`check (deleted or (status is not null and starts_at is
|
|
867
|
+
not null))`), a query of your own on the table leaves the deleted rows out (`deleted = false`),
|
|
868
|
+
and a table whose columns refuse NULL is refused with `ReadModelTableNotReadyError`, when the store is built from its definition and, before the first
|
|
869
|
+
trace is written, from one read of the columns the database holds
|
|
870
|
+
([What a deleted row leaves](../../docs/concepts/cqrs.md#the-table-of-a-read-model-and-what-a-deleted-row-leaves)). `store.table` is what `ProjectionRebuild` takes; the rebuild is
|
|
820
871
|
PostgreSQL only (a copy `<table>__rebuild` made `LIKE ... INCLUDING ALL`, the keys written
|
|
821
872
|
meanwhile in `<table>__touched`, the swap by rename in one transaction) and its guarantees
|
|
822
873
|
and limits are in the README of `@ddd-ts-kit/kernel` ([Rebuild](../kernel/README.md#rebuild)).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type AdvisoryLockOptions } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { DrizzleLockingContext } from './drizzle-locking-context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Serialises the units of work that take the same key: waits until no other transaction holds
|
|
5
|
+
* the lock on `key`, then holds it until the unit of work commits or rolls back
|
|
6
|
+
* (`pg_advisory_xact_lock`). For a decision no row can carry a version for: count then insert, the
|
|
7
|
+
* next number of a sequence per tenant. Taken first in the unit of work, before what it protects
|
|
8
|
+
* is read; the same key taken twice in one unit of work is held once.
|
|
9
|
+
*
|
|
10
|
+
* The key is hashed by PostgreSQL (`advisoryLockKey` of the kernel says how, and what a collision
|
|
11
|
+
* costs); with `tenant`, two tenants never wait for each other. Refused outside a unit of work
|
|
12
|
+
* (`AdvisoryLockOutsideUnitOfWorkError`). PostgreSQL only. It is the one way an adapter of a
|
|
13
|
+
* tenant-scoped project takes such a lock (`tenancy/scoped-statement`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function advisoryLock(context: DrizzleLockingContext, key: string, options?: AdvisoryLockOptions): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=advisory-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advisory-lock.d.ts","sourceRoot":"","sources":["../../../src/postgres/locks/advisory-lock.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAIf"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { advisoryLockKey } from '@ddd-ts-kit/kernel';
|
|
3
|
+
/**
|
|
4
|
+
* Serialises the units of work that take the same key: waits until no other transaction holds
|
|
5
|
+
* the lock on `key`, then holds it until the unit of work commits or rolls back
|
|
6
|
+
* (`pg_advisory_xact_lock`). For a decision no row can carry a version for: count then insert, the
|
|
7
|
+
* next number of a sequence per tenant. Taken first in the unit of work, before what it protects
|
|
8
|
+
* is read; the same key taken twice in one unit of work is held once.
|
|
9
|
+
*
|
|
10
|
+
* The key is hashed by PostgreSQL (`advisoryLockKey` of the kernel says how, and what a collision
|
|
11
|
+
* costs); with `tenant`, two tenants never wait for each other. Refused outside a unit of work
|
|
12
|
+
* (`AdvisoryLockOutsideUnitOfWorkError`). PostgreSQL only. It is the one way an adapter of a
|
|
13
|
+
* tenant-scoped project takes such a lock (`tenancy/scoped-statement`).
|
|
14
|
+
*/
|
|
15
|
+
export async function advisoryLock(context, key, options = {}) {
|
|
16
|
+
const text = advisoryLockKey(context, key, options);
|
|
17
|
+
await context.executor().execute(sql `select pg_advisory_xact_lock(hashtextextended(${text}, 0))`);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=advisory-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advisory-lock.js","sourceRoot":"","sources":["../../../src/postgres/locks/advisory-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,eAAe,EAA4B,MAAM,oBAAoB,CAAC;AAG/E;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAA8B,EAC9B,GAAW,EACX,OAAO,GAAwB,EAAE;IAEjC,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,iDAAiD,IAAI,OAAO,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SqlExecutor } from '../tenancy/sql-executor.js';
|
|
2
|
+
/** What an advisory lock needs of a `DrizzleContext`, whatever its driver and its schema. */
|
|
3
|
+
export interface DrizzleLockingContext {
|
|
4
|
+
executor(): SqlExecutor;
|
|
5
|
+
inTransaction(): boolean;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=drizzle-locking-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-locking-context.d.ts","sourceRoot":"","sources":["../../../src/postgres/locks/drizzle-locking-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,6FAA6F;AAC7F,MAAM,WAAW,qBAAqB;IACpC,QAAQ,IAAI,WAAW,CAAC;IACxB,aAAa,IAAI,OAAO,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-locking-context.js","sourceRoot":"","sources":["../../../src/postgres/locks/drizzle-locking-context.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type AdvisoryLockOptions } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { DrizzleLockingContext } from './drizzle-locking-context.js';
|
|
3
|
+
/**
|
|
4
|
+
* `advisoryLock` without the wait: takes the lock on `key` for the unit of work if no other
|
|
5
|
+
* transaction holds it and answers `true`, answers `false` at once otherwise
|
|
6
|
+
* (`pg_try_advisory_xact_lock`). For work that is skipped, not queued, when somebody else is
|
|
7
|
+
* already at it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function tryAdvisoryLock(context: DrizzleLockingContext, key: string, options?: AdvisoryLockOptions): Promise<boolean>;
|
|
10
|
+
//# sourceMappingURL=try-advisory-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"try-advisory-lock.d.ts","sourceRoot":"","sources":["../../../src/postgres/locks/try-advisory-lock.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,qBAAqB,EAC9B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,OAAO,CAAC,CAQlB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { advisoryLockKey } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { rowsOf } from '../read-model/rows-of.js';
|
|
4
|
+
/**
|
|
5
|
+
* `advisoryLock` without the wait: takes the lock on `key` for the unit of work if no other
|
|
6
|
+
* transaction holds it and answers `true`, answers `false` at once otherwise
|
|
7
|
+
* (`pg_try_advisory_xact_lock`). For work that is skipped, not queued, when somebody else is
|
|
8
|
+
* already at it.
|
|
9
|
+
*/
|
|
10
|
+
export async function tryAdvisoryLock(context, key, options = {}) {
|
|
11
|
+
const text = advisoryLockKey(context, key, options);
|
|
12
|
+
const [answered] = rowsOf(await context.executor().execute(sql `select pg_try_advisory_xact_lock(hashtextextended(${text}, 0)) as acquired`));
|
|
13
|
+
return answered?.['acquired'] === true;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=try-advisory-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"try-advisory-lock.js","sourceRoot":"","sources":["../../../src/postgres/locks/try-advisory-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,eAAe,EAA4B,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAA8B,EAC9B,GAAW,EACX,OAAO,GAAwB,EAAE;IAEjC,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAEpD,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CACvB,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,qDAAqD,IAAI,mBAAmB,CAAC,CAClH,CAAC;IAEF,OAAO,QAAQ,EAAE,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;AACzC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-read-model-table.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-read-model-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,
|
|
1
|
+
{"version":3,"file":"drizzle-read-model-table.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-read-model-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,0BAA0B,EAAE,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAiC,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,UAAU,EAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAGtE,O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IAED,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAE5B;IAED,MAAM,IAAI,aAAa,CAAC,GAAG,CAAC,CAE3B;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC,CAErD;IAED,MAAM,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjD;IAED,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAEvB;IAED,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAE9B;IAED,gHAAgH;YAClG,GAAG;CAelB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { and, eq, sql } from 'drizzle-orm';
|
|
2
2
|
import { getTableConfig } from 'drizzle-orm/pg-core';
|
|
3
|
-
import { PostgresReadModelRebuild, } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { PostgresReadModelRebuild, PostgresTraceColumns, ReadModelTableNotReadyError, } from '@ddd-ts-kit/kernel';
|
|
4
4
|
import { tenantCondition } from '../tenancy/tenant-condition.js';
|
|
5
5
|
import { criteriaToDrizzle } from './criteria-to-drizzle.js';
|
|
6
6
|
import { DrizzleStampedRows } from './drizzle-stamped-rows.js';
|
|
@@ -23,12 +23,15 @@ export class DrizzleReadModelTable {
|
|
|
23
23
|
this.context = context;
|
|
24
24
|
this.options = options;
|
|
25
25
|
const { name, schema } = getTableConfig(options.table);
|
|
26
|
+
const data = holdsTraces(options, schema === undefined ? name : `${schema}.${name}`);
|
|
27
|
+
const traces = new PostgresTraceColumns((statement, parameters) => this.run(statement, parameters), () => ({ table: name, data, ...(schema === undefined ? {} : { schema }) }));
|
|
26
28
|
this.target = {
|
|
27
29
|
schema,
|
|
28
30
|
name,
|
|
29
31
|
key: options.key,
|
|
30
32
|
columns: options.columns,
|
|
31
33
|
stamps: stampColumns(options.table),
|
|
34
|
+
traces,
|
|
32
35
|
...(options.tenant === undefined ? {} : { tenant: options.tenant }),
|
|
33
36
|
};
|
|
34
37
|
this.rows = new DrizzleStampedRows(context, this.target);
|
|
@@ -98,4 +101,19 @@ export class DrizzleReadModelTable {
|
|
|
98
101
|
return rowsOf(await this.context.executor().execute(query));
|
|
99
102
|
}
|
|
100
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Refuses, when the store is built, a table whose definition could not hold the trace of a
|
|
106
|
+
* deleted row: every column of the row accepts NULL, the key and the tenant apart. An early
|
|
107
|
+
* signal: the database is asked before the first trace. Answers the columns of the row.
|
|
108
|
+
*/
|
|
109
|
+
function holdsTraces({ columns, key, tenant }, table) {
|
|
110
|
+
const mapped = Object.values(columns);
|
|
111
|
+
const kept = new Set([key.name, tenant?.column.name]);
|
|
112
|
+
const data = mapped.filter((column) => !kept.has(column.name));
|
|
113
|
+
const refusing = data.filter((column) => column.notNull);
|
|
114
|
+
if (refusing.length > 0) {
|
|
115
|
+
throw new ReadModelTableNotReadyError(table, refusing.map((column) => column.name));
|
|
116
|
+
}
|
|
117
|
+
return data.map((column) => column.name);
|
|
118
|
+
}
|
|
101
119
|
//# sourceMappingURL=drizzle-read-model-table.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-read-model-table.js","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-read-model-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAgE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"drizzle-read-model-table.js","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-read-model-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAgE,MAAM,aAAa,CAAC;AACzG,OAAO,EAAE,cAAc,EAAwC,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EACL,wBAAwB,EACxB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AO,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAM,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAgC,EAAE,KAAa;IAC7F,MAAM,MAAM,GAAwB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3D,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEzD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,2BAA2B,CACnC,KAAK,EACL,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CACtC,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TablesRelationalConfig } from 'drizzle-orm';
|
|
2
2
|
import type { PgColumn, PgQueryResultHKT } from 'drizzle-orm/pg-core';
|
|
3
|
-
import { type EventStamp, type ReadModelRows, type StampedRow } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { type EventStamp, type PostgresTraceColumns, type ReadModelRows, type StampedRow } from '@ddd-ts-kit/kernel';
|
|
4
4
|
import type { ReadModelTenant } from './read-model-tenant.js';
|
|
5
5
|
import type { DrizzleContext } from '../unit-of-work/drizzle-context.js';
|
|
6
6
|
import type { StampColumns } from './stamp-columns.js';
|
|
@@ -11,6 +11,8 @@ export interface StampedTable {
|
|
|
11
11
|
readonly columns: Readonly<Record<string, PgColumn>>;
|
|
12
12
|
readonly stamps: StampColumns;
|
|
13
13
|
readonly tenant?: ReadModelTenant;
|
|
14
|
+
/** Of the table itself, which the copy of a rebuild is made like. */
|
|
15
|
+
readonly traces: PostgresTraceColumns;
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* The stamped rows of one table, the copy of a rebuild as well as the table itself: the
|
|
@@ -28,6 +30,7 @@ export declare class DrizzleStampedRows<Row extends object, Q extends PgQueryRes
|
|
|
28
30
|
/** What a read may reach: every row, or those of the tenants of the work for a read model of tenant data. */
|
|
29
31
|
private reach;
|
|
30
32
|
private own;
|
|
33
|
+
/** The trace of a deleted row is written once the table is known, in the database, to accept it. */
|
|
31
34
|
private valuesOf;
|
|
32
35
|
/** The tenant of a written row, for a read model of tenant data. */
|
|
33
36
|
private tenantValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-stamped-rows.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-stamped-rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,
|
|
1
|
+
{"version":3,"file":"drizzle-stamped-rows.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-stamped-rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAEL,KAAK,UAAU,EACf,KAA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E,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAsBrD;IAEK,OAAO,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAmBxE;IAED,6GAA6G;IAC7G,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,GAAG;IAMX,oGAAoG;YACtF,QAAQ;IAqBtB,oEAAoE;IACpE,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,KAAK;CAKd"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sql } from 'drizzle-orm';
|
|
2
|
-
import { tenantScopeOf } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import { tenantScopeOf, } from '@ddd-ts-kit/kernel';
|
|
3
3
|
import { reachCondition } from '../tenancy/reach-condition.js';
|
|
4
4
|
import { RowMapper } from './row.mapper.js';
|
|
5
5
|
import { rowsOf } from './rows-of.js';
|
|
@@ -37,10 +37,7 @@ export class DrizzleStampedRows {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
async insert(entry) {
|
|
40
|
-
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
const values = this.valuesOf(entry);
|
|
40
|
+
const values = await this.valuesOf(entry);
|
|
44
41
|
const columns = sql.join(values.map(([column]) => named(column)), sql `, `);
|
|
45
42
|
const written = sql.join(values.map(([, value]) => sql `${value}`), sql `, `);
|
|
46
43
|
const key = named(this.target.key);
|
|
@@ -51,11 +48,12 @@ export class DrizzleStampedRows {
|
|
|
51
48
|
}
|
|
52
49
|
async replace(entry, held) {
|
|
53
50
|
const { stamps } = this.target;
|
|
54
|
-
const
|
|
51
|
+
const values = await this.valuesOf(entry);
|
|
52
|
+
const changes = sql.join(values.map(([column, value]) => sql `${named(column)} = ${value}`), sql `, `);
|
|
55
53
|
const key = named(this.target.key);
|
|
56
54
|
const replaced = await this.context
|
|
57
55
|
.executor()
|
|
58
|
-
.execute(sql `update ${this.table()} set ${changes} where ${key} = ${entry.key} and ${named(stamps.lastEventId)} = ${held.eventId} and ${named(stamps.lastEventAt)} = ${held.occurredAt.toISOString()} and ${this.own()} returning ${key}`);
|
|
56
|
+
.execute(sql `update ${this.table()} set ${changes} where ${key} = ${entry.key} and ${named(stamps.lastEventId)} = ${held.eventId} and ${named(stamps.lastEventAt)} = ${held.occurredAt.toISOString()} and ${named(stamps.lastEventVersion)} is not distinct from ${held.version ?? null}::bigint and ${this.own()} returning ${key}`);
|
|
59
57
|
return rowsOf(replaced).length === 1;
|
|
60
58
|
}
|
|
61
59
|
/** What a read may reach: every row, or those of the tenants of the work for a read model of tenant data. */
|
|
@@ -67,13 +65,16 @@ export class DrizzleStampedRows {
|
|
|
67
65
|
const { tenant } = this.target;
|
|
68
66
|
return tenant === undefined ? sql `true` : sql `${named(tenant.column)} = ${tenantScopeOf(tenant.scope).tenantId}`;
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
/** The trace of a deleted row is written once the table is known, in the database, to accept it. */
|
|
69
|
+
async valuesOf({ key, row, stamp }) {
|
|
70
|
+
const { stamps, tenant, traces } = this.target;
|
|
71
|
+
if (row === undefined) {
|
|
72
|
+
await traces.require();
|
|
73
|
+
}
|
|
74
|
+
// A deleted row keeps no data: every column of the row is written NULL, not left to its default.
|
|
75
|
+
const data = row === undefined ? this.mapper.toNulls() : this.mapper.toValues(row);
|
|
75
76
|
return [
|
|
76
|
-
...
|
|
77
|
+
...data.filter(([column]) => column !== this.target.key && column !== tenant?.column),
|
|
77
78
|
[this.target.key, key],
|
|
78
79
|
[stamps.lastEventId, stamp.eventId],
|
|
79
80
|
[stamps.lastEventAt, stamp.occurredAt.toISOString()],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle-stamped-rows.js","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-stamped-rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAyC,MAAM,aAAa,CAAC;AAEzE,OAAO,
|
|
1
|
+
{"version":3,"file":"drizzle-stamped-rows.js","sourceRoot":"","sources":["../../../src/postgres/read-model/drizzle-stamped-rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAyC,MAAM,aAAa,CAAC;AAEzE,OAAO,EACL,aAAa,GAKd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAcnC;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAUV,OAAO;IACP,MAAM;IAJR,MAAM,CAAiB;IAExC,YACmB,OAAgC,EAChC,MAAoB;uBADpB,OAAO;sBACP,MAAM;QAEvB,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAM,MAAM,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,GAAW;QACpB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAE/B,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CACrB,MAAM,IAAI,CAAC,OAAO;aACf,QAAQ,EAAE;aACV,OAAO,CACN,GAAG,CAAA,iBAAiB,IAAI,CAAC,KAAK,EAAE,UAAU,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,QAAQ,IAAI,CAAC,KAAK,EAAE,UAAU,CACxG,CACJ,CAAC;QAEF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAErD,OAAO;YACL,GAAG;YACH,GAAG,EAAE,MA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M,CAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC;YACnC,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;YACpD,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC;YAChD,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,KAAK,SAAS,CAAC;YACnC,GAAG,IAAI,CAAC,WAAW,EAAE;SACtB,CAAC;IACJ,CAAC;IAED,oEAAoE;IAC5D,WAAW;QACjB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAE/B,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7F,CAAC;IAEO,KAAK;QACX,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAErC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAA,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;IACtH,CAAC;CACF;AAED,SAAS,KAAK,CAAC,MAAgB;IAC7B,OAAO,GAAG,CAAA,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TextSearch } from '@ddd-ts-kit/kernel';
|
|
2
2
|
/** The `LIKE` pattern of a text search, the text itself taken literally: `%`, `_` and `\` are escaped by `\`. */
|
|
3
|
-
export declare function likePattern(operator:
|
|
3
|
+
export declare function likePattern(operator: TextSearch, text: string): string;
|
|
4
4
|
//# sourceMappingURL=like-pattern.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"like-pattern.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/like-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"like-pattern.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/like-pattern.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,iHAAiH;AACjH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAItE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The `LIKE` pattern of a text search, the text itself taken literally: `%`, `_` and `\` are escaped by `\`. */
|
|
2
2
|
export function likePattern(operator, text) {
|
|
3
3
|
const literal = text.replace(/[\\%_]/g, (special) => `\\${special}`);
|
|
4
|
-
return operator === 'startsWith' ? `${literal}%` : `%${literal}%`;
|
|
4
|
+
return operator === 'startsWith' || operator === 'startsWithIgnoringCase' ? `${literal}%` : `%${literal}%`;
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=like-pattern.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"like-pattern.js","sourceRoot":"","sources":["../../../src/postgres/read-model/like-pattern.ts"],"names":[],"mappings":"AAEA,iHAAiH;AACjH,MAAM,UAAU,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"like-pattern.js","sourceRoot":"","sources":["../../../src/postgres/read-model/like-pattern.ts"],"names":[],"mappings":"AAEA,iHAAiH;AACjH,MAAM,UAAU,WAAW,CAAC,QAAoB,EAAE,IAAY;IAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,OAAO,EAAE,CAAC,CAAC;IAErE,OAAO,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,wBAAwB,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAC;AAC7G,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SQL } from 'drizzle-orm';
|
|
2
2
|
import type { PgColumn } from 'drizzle-orm/pg-core';
|
|
3
|
-
import type
|
|
3
|
+
import { type Predicate } from '@ddd-ts-kit/kernel';
|
|
4
4
|
type Columns = Readonly<Record<string, PgColumn>>;
|
|
5
5
|
/**
|
|
6
6
|
* A predicate of a criteria plan as a drizzle condition. Every value is a parameter, encoded
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicate-to-drizzle.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/predicate-to-drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EAeL,KAAK,GAAG,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"predicate-to-drizzle.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/predicate-to-drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EAeL,KAAK,GAAG,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAKL,KAAK,SAAS,EAEf,MAAM,oBAAoB,CAAC;AAI5B,KAAK,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAelD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAYtG"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { and, between, eq, gt, gte, inArray, isNotNull, isNull, lt, lte, ne, not, or, sql, } from 'drizzle-orm';
|
|
2
|
+
import { isTextSearch, } from '@ddd-ts-kit/kernel';
|
|
2
3
|
import { columnOf } from './column-of.js';
|
|
3
4
|
import { likePattern } from './like-pattern.js';
|
|
5
|
+
/** A search that ignores case is an `ilike`: PostgreSQL folds it with the locale of the database, see `foldCase` of the kernel. */
|
|
6
|
+
const LIKE = {
|
|
7
|
+
contains: sql `like`,
|
|
8
|
+
startsWith: sql `like`,
|
|
9
|
+
containsIgnoringCase: sql `ilike`,
|
|
10
|
+
startsWithIgnoringCase: sql `ilike`,
|
|
11
|
+
};
|
|
4
12
|
const COMPARISONS = { eq, ne, gt, gte, lt, lte };
|
|
5
13
|
/**
|
|
6
14
|
* A predicate of a criteria plan as a drizzle condition. Every value is a parameter, encoded
|
|
@@ -27,14 +35,14 @@ function tested(test, column) {
|
|
|
27
35
|
function compared(operator, value, column) {
|
|
28
36
|
const values = typeof value === 'object' && !(value instanceof Date) ? [...value] : [value];
|
|
29
37
|
const [first = null, second = null] = values;
|
|
38
|
+
if (isTextSearch(operator)) {
|
|
39
|
+
return sql `${column} ${LIKE[operator]} ${likePattern(operator, String(first))} escape ${'\\'}`;
|
|
40
|
+
}
|
|
30
41
|
switch (operator) {
|
|
31
42
|
case 'in':
|
|
32
43
|
return inArray(column, values);
|
|
33
44
|
case 'between':
|
|
34
45
|
return between(column, first, second);
|
|
35
|
-
case 'contains':
|
|
36
|
-
case 'startsWith':
|
|
37
|
-
return sql `${column} like ${likePattern(operator, String(first))} escape ${'\\'}`;
|
|
38
46
|
default:
|
|
39
47
|
return COMPARISONS[operator](column, first);
|
|
40
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"predicate-to-drizzle.js","sourceRoot":"","sources":["../../../src/postgres/read-model/predicate-to-drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,OAAO,EACP,EAAE,EACF,EAAE,EACF,GAAG,EACH,OAAO,EACP,SAAS,EACT,MAAM,EACN,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,GAEJ,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"predicate-to-drizzle.js","sourceRoot":"","sources":["../../../src/postgres/read-model/predicate-to-drizzle.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,OAAO,EACP,EAAE,EACF,EAAE,EACF,GAAG,EACH,OAAO,EACP,SAAS,EACT,MAAM,EACN,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,GAEJ,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,YAAY,GAMb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,mIAAmI;AACnI,MAAM,IAAI,GAAG;IACX,QAAQ,EAAE,GAAG,CAAA,MAAM;IACnB,UAAU,EAAE,GAAG,CAAA,MAAM;IACrB,oBAAoB,EAAE,GAAG,CAAA,OAAO;IAChC,sBAAsB,EAAE,GAAG,CAAA,OAAO;CAC1B,CAAC;AAEX,MAAM,WAAW,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAW,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAgC,EAAE,OAAgB;IACnF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,CAAC;IA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AAM,CAAC,KAAK,CAAC,CAAC,WAAW,IAAI,EAAE,CAAC;IACjG,CAAC;IAED,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,IAAI;YACP,OAAO,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACxC;YACE,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;AACH,CAAC"}
|
|
@@ -8,6 +8,8 @@ export declare class RowMapper<Row extends object> {
|
|
|
8
8
|
toRow(record: Readonly<Record<string, unknown>>): Row;
|
|
9
9
|
/** From a record keyed by field, already decoded: what `select(columns)` of the query builder answers. */
|
|
10
10
|
fromSelected(selected: Readonly<Record<string, unknown>>): Row;
|
|
11
|
+
/** NULL in every column of the row: what a deleted row holds. */
|
|
12
|
+
toNulls(): [PgColumn, unknown][];
|
|
11
13
|
/** The values of the row by column, encoded as the driver expects them. */
|
|
12
14
|
toValues(row: Row): [PgColumn, unknown][];
|
|
13
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row.mapper.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/row.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,KAAK,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAElD,6FAA6F;AAC7F,qBAAa,SAAS,CAAC,GAAG,SAAS,MAAM;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAApC,YAA6B,OAAO,EAAE,OAAO,EAAI;IAEjD,oFAAoF;IACpF,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,CAIpD;IAED,0GAA0G;IAC1G,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,CAE7D;IAED,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAExC;CACF"}
|
|
1
|
+
{"version":3,"file":"row.mapper.d.ts","sourceRoot":"","sources":["../../../src/postgres/read-model/row.mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,KAAK,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAElD,6FAA6F;AAC7F,qBAAa,SAAS,CAAC,GAAG,SAAS,MAAM;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAApC,YAA6B,OAAO,EAAE,OAAO,EAAI;IAEjD,oFAAoF;IACpF,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,CAIpD;IAED,0GAA0G;IAC1G,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,CAE7D;IAED,iEAAiE;IACjE,OAAO,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAE/B;IAED,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAExC;CACF"}
|
|
@@ -12,6 +12,10 @@ export class RowMapper {
|
|
|
12
12
|
fromSelected(selected) {
|
|
13
13
|
return Object.fromEntries(Object.keys(this.columns).map((field) => [field, selected[field] ?? null]));
|
|
14
14
|
}
|
|
15
|
+
/** NULL in every column of the row: what a deleted row holds. */
|
|
16
|
+
toNulls() {
|
|
17
|
+
return Object.values(this.columns).map((column) => [column, null]);
|
|
18
|
+
}
|
|
15
19
|
/** The values of the row by column, encoded as the driver expects them. */
|
|
16
20
|
toValues(row) {
|
|
17
21
|
return Object.entries(this.columns).map(([field, column]) => [column, encoded(column, Reflect.get(row, field))]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"row.mapper.js","sourceRoot":"","sources":["../../../src/postgres/read-model/row.mapper.ts"],"names":[],"mappings":"AAIA,6FAA6F;AAC7F,MAAM,OAAO,SAAS;IACS,OAAO;IAApC,YAA6B,OAAgB;uBAAhB,OAAO;IAAY,CAAC;IAEjD,oFAAoF;IACpF,KAAK,CAAC,MAAyC;QAC7C,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAC9F,CAAC;IACX,CAAC;IAED,0GAA0G;IAC1G,YAAY,CAAC,QAA2C;QACtD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAQ,CAAC;IAC/G,CAAC;IAED,2EAA2E;IAC3E,QAAQ,CAAC,GAAQ;QACf,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAA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L,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,2EAA2E;IAC3E,QAAQ,CAAC,GAAQ;QACf,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnH,CAAC;CACF;AAED,SAAS,OAAO,CAAC,MAAgB,EAAE,KAAc;IAC/C,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACzF,CAAC;AAED,SAAS,OAAO,CAAC,MAAgB,EAAE,KAAc;IAC/C,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACvF,CAAC"}
|
package/dist/postgres.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export * from './postgres/outbox/processed-events-table.js';
|
|
|
10
10
|
export * from './postgres/outbox/drizzle-outbox-store.js';
|
|
11
11
|
export * from './postgres/outbox/drizzle-processed-event-store.js';
|
|
12
12
|
export * from './postgres/sql/primary-key-of.js';
|
|
13
|
+
export * from './postgres/locks/drizzle-locking-context.js';
|
|
14
|
+
export * from './postgres/locks/advisory-lock.js';
|
|
15
|
+
export * from './postgres/locks/try-advisory-lock.js';
|
|
13
16
|
export * from './postgres/columns/audit-columns.js';
|
|
14
17
|
export * from './postgres/columns/tenant-column.js';
|
|
15
18
|
export * from './postgres/read-model/read-model-columns.js';
|
package/dist/postgres.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAC5B,cAAc,yCAAyC,CAAC;AACxD,cAAc,qDAAqD,CAAC;AACpE,cAAc,kCAAkC,CAAC;AACjD,cAAc,yDAAyD,CAAC;AACxE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC;AACtD,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,yCAAyC,CAAC;AACxD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAyC,CAAC;AACxD,cAAc,oCAAoC,CAAC;AACnD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wDAAwD,CAAC;AACvE,cAAc,gEAAgE,CAAC;AAC/E,cAAc,uDAAuD,CAAC;AACtE,cAAc,+DAA+D,CAAC;AAC9E,cAAc,kDAAkD,CAAC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CHANGED
|
@@ -10,6 +10,9 @@ export * from './postgres/outbox/processed-events-table.js';
|
|
|
10
10
|
export * from './postgres/outbox/drizzle-outbox-store.js';
|
|
11
11
|
export * from './postgres/outbox/drizzle-processed-event-store.js';
|
|
12
12
|
export * from './postgres/sql/primary-key-of.js';
|
|
13
|
+
export * from './postgres/locks/drizzle-locking-context.js';
|
|
14
|
+
export * from './postgres/locks/advisory-lock.js';
|
|
15
|
+
export * from './postgres/locks/try-advisory-lock.js';
|
|
13
16
|
export * from './postgres/columns/audit-columns.js';
|
|
14
17
|
export * from './postgres/columns/tenant-column.js';
|
|
15
18
|
export * from './postgres/read-model/read-model-columns.js';
|
package/dist/postgres.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,GAEb,MAAM,oBAAoB,CAAC;AAC5B,cAAc,yCAAyC,CAAC;AACxD,cAAc,qDAAqD,CAAC;AACpE,cAAc,kCAAkC,CAAC;AACjD,cAAc,yDAAyD,CAAC;AACxE,cAAc,8CAA8C,CAAC;AAC7D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC;AACtD,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,iDAAiD,CAAC;AAChE,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,kDAAkD,CAAC;AACjE,cAAc,yCAAyC,CAAC;AACxD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAy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cAAc,6CAA6C,CAAC;AAC5D,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wDAAwD,CAAC;AACvE,cAAc,gEAAgE,CAAC;AAC/E,cAAc,uDAAuD,CAAC;AACtE,cAAc,+DAA+D,CAAC;AAC9E,cAAc,kDAAkD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/drizzle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.111.0",
|
|
4
4
|
"description": "Drizzle adapters for the kernel ports on PostgreSQL: unit of work, transactional outbox store, processed-event store, event store, background job store, process store, one schema per context.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ddd",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ddd-ts-kit/kernel": "0.
|
|
46
|
-
"@ddd-ts-kit/events": "0.
|
|
47
|
-
"@ddd-ts-kit/scheduling": "0.
|
|
45
|
+
"@ddd-ts-kit/kernel": "0.111.0",
|
|
46
|
+
"@ddd-ts-kit/events": "0.111.0",
|
|
47
|
+
"@ddd-ts-kit/scheduling": "0.111.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"drizzle-orm": ">=0.40.0"
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"drizzle-orm": "latest",
|
|
54
54
|
"@electric-sql/pglite": "0.5.15",
|
|
55
|
-
"@ddd-ts-kit/testing": "0.
|
|
55
|
+
"@ddd-ts-kit/testing": "0.111.0",
|
|
56
56
|
"pg": "^8.23.1",
|
|
57
57
|
"@types/pg": "^8.23.1"
|
|
58
58
|
}
|