@ddd-ts-kit/drizzle 0.88.0 → 0.89.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 +63 -1
- package/README.md +60 -0
- package/dist/postgres/personal-data/about-subject.d.ts +6 -0
- package/dist/postgres/personal-data/about-subject.d.ts.map +1 -0
- package/dist/postgres/personal-data/about-subject.js +17 -0
- package/dist/postgres/personal-data/about-subject.js.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure-options.d.ts +18 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure-options.d.ts.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure-options.js +2 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure-options.js.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure.d.ts +33 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure.d.ts.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure.js +118 -0
- package/dist/postgres/personal-data/drizzle-personal-data-erasure.js.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export-options.d.ts +4 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export-options.d.ts.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export-options.js +2 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export-options.js.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export.d.ts +25 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export.d.ts.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export.js +59 -0
- package/dist/postgres/personal-data/drizzle-personal-data-export.js.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-fields.d.ts +15 -0
- package/dist/postgres/personal-data/drizzle-personal-fields.d.ts.map +1 -0
- package/dist/postgres/personal-data/drizzle-personal-fields.js +2 -0
- package/dist/postgres/personal-data/drizzle-personal-fields.js.map +1 -0
- package/dist/postgres/personal-data/expired-rows.d.ts +14 -0
- package/dist/postgres/personal-data/expired-rows.d.ts.map +1 -0
- package/dist/postgres/personal-data/expired-rows.js +26 -0
- package/dist/postgres/personal-data/expired-rows.js.map +1 -0
- package/dist/postgres/personal-data/named.d.ts +5 -0
- package/dist/postgres/personal-data/named.d.ts.map +1 -0
- package/dist/postgres/personal-data/named.js +6 -0
- package/dist/postgres/personal-data/named.js.map +1 -0
- package/dist/postgres/personal-data/table-sql-of.d.ts +5 -0
- package/dist/postgres/personal-data/table-sql-of.d.ts.map +1 -0
- package/dist/postgres/personal-data/table-sql-of.js +8 -0
- package/dist/postgres/personal-data/table-sql-of.js.map +1 -0
- package/dist/postgres/personal-data/tenant-column-of.d.ts +5 -0
- package/dist/postgres/personal-data/tenant-column-of.d.ts.map +1 -0
- package/dist/postgres/personal-data/tenant-column-of.js +10 -0
- package/dist/postgres/personal-data/tenant-column-of.js.map +1 -0
- package/dist/postgres.d.ts +5 -0
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +5 -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:62a037da816460ff -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/drizzle
|
|
5
5
|
|
|
@@ -830,6 +830,68 @@ par renommage en une transaction) et ses garanties et limites sont dans le READM
|
|
|
830
830
|
Le store passe `criteriaContract` et `readModelStoreContract` de
|
|
831
831
|
`@ddd-ts-kit/testing/contracts`, sur PGlite et sur PostgreSQL 18.
|
|
832
832
|
|
|
833
|
+
## Effacement des données personnelles
|
|
834
|
+
|
|
835
|
+
L'effacement d'une personne concernée des tables d'un contexte, à partir des déclarations
|
|
836
|
+
`personalFields` écrites à côté de ses *mappers* (`@ddd-ts-kit/kernel`, « Données personnelles ») :
|
|
837
|
+
`DrizzlePersonalDataErasure` implémente le port `PersonalDataErasure` sur l'exécuteur de l'unité de travail. Le port du contexte étend celui du
|
|
838
|
+
kernel, et son adaptateur étend cette classe.
|
|
839
|
+
|
|
840
|
+
```ts
|
|
841
|
+
// infrastructure/persistence/person.personal-fields.ts : la table elle-même, les colonnes par les clés de sa définition
|
|
842
|
+
export const personPersonalFields = personalFields<typeof persons.$inferSelect, PgTable>(persons, {
|
|
843
|
+
subject: 'id',
|
|
844
|
+
fields: ['displayName', 'email'],
|
|
845
|
+
erasure: 'row',
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
// infrastructure/persistence/drizzle-identity-erasure.repository.ts
|
|
849
|
+
@Repository(IdentityErasure)
|
|
850
|
+
export class DrizzleIdentityErasure extends DrizzlePersonalDataErasure<NodePgQueryResultHKT> implements IdentityErasure {
|
|
851
|
+
constructor(database: Database, scope: ExecutionScope, files: FileStorage) {
|
|
852
|
+
super(database, { name: 'identity.persons', declarations: [personPersonalFields], tenant: { scope }, files });
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
```
|
|
856
|
+
|
|
857
|
+
`erase(subject)` supprime d'abord du stockage les fichiers que les lignes nomment, puis supprime les
|
|
858
|
+
lignes de la personne (`row`) ou les pseudonymise (`pseudonymise` : une colonne texte lit `[erased]`,
|
|
859
|
+
une colonne de tout autre type ne lit rien, une colonne de fichier rien), et répond combien de lignes
|
|
860
|
+
il a atteintes, aucune la seconde fois. Avec `tenant`, chaque instruction est confinée au *tenant* du
|
|
861
|
+
travail et jamais élargie par une élévation (la colonne nommée `tenant_id`, ou `tenant.column`) ; sans lui, la table tient les lignes de tous
|
|
862
|
+
les *tenants*. Un sujet qui n'est pas un identifiant opaque est refusé avant toute instruction, et une
|
|
863
|
+
déclaration qui nomme des colonnes de fichier sans stockage de fichiers est refusée à la construction
|
|
864
|
+
de l'adaptateur. Les types des colonnes viennent de la définition de la table, pour qu'un texte et un nombre soient pseudonymisés chacun à sa façon. Une colonne personnelle qui n'est pas un texte doit accepter null, sinon
|
|
865
|
+
les lignes s'effacent avec `row` : une déclaration qui en pseudonymiserait une qui ne l'accepte pas
|
|
866
|
+
est refusée avant qu'un fichier ou une ligne ne soit touché (`NotNullablePersonalColumnError`). L'adaptateur passe `personalDataErasureContract` de
|
|
867
|
+
`@ddd-ts-kit/testing`, comme celui en mémoire, sur PGlite et PostgreSQL. Ce qu'un effacement
|
|
868
|
+
n'atteint pas, et la chaîne entière (`eraseDataSubject` : la clé, chaque copie dans chaque *tenant*,
|
|
869
|
+
les reconstructions), sont dans le README du kernel (« Données personnelles »).
|
|
870
|
+
|
|
871
|
+
`DrizzlePersonalDataExport` répond au droit d'accès et à la portabilité à partir des mêmes déclarations :
|
|
872
|
+
`exportOf(subject)` remet un `PersonalDataRecord` par ligne sur la personne dans chaque table déclarée,
|
|
873
|
+
sous `<name>.<table>`, avec chaque colonne personnelle et chaque colonne de fichier (par sa clé) en
|
|
874
|
+
données simples, par les clés de la définition de la table, aucune autre colonne et rien de personne d'autre ; une ligne déjà
|
|
875
|
+
pseudonymisée répond ce qu'elle lit. La même option `tenant` confine chaque instruction au *tenant* du
|
|
876
|
+
travail, un sujet qui n'est pas un identifiant opaque est refusé avant toute instruction, et
|
|
877
|
+
l'adaptateur passe `personalDataExportContract`. Le port du contexte étend `PersonalDataExport` du
|
|
878
|
+
kernel et son adaptateur étend cette classe avec `name`, `declarations` et `tenant`
|
|
879
|
+
(`DrizzlePersonalDataExportOptions`) ; `generate repository --personal` écrit les deux adaptateurs, et
|
|
880
|
+
`exportDataSubject` du kernel rassemble chaque export en un document daté. Enveloppez l'adaptateur
|
|
881
|
+
avec `auditedPersonalDataExport` de `@ddd-ts-kit/audit` là où il est lié, pour que chaque remise
|
|
882
|
+
laisse une entrée.
|
|
883
|
+
|
|
884
|
+
Les mêmes déclarations donnent la limitation de la conservation (RGPD, article 5(1)(e)) : une
|
|
885
|
+
déclaration avec `retention: { after: 'endedAt', months: 36 }` dit combien de temps ses lignes gardent
|
|
886
|
+
la personne, compté depuis une colonne de date de la ligne, et `purgeExpired(now)` de l'adaptateur
|
|
887
|
+
d'effacement efface, comme la déclaration le dit, les lignes dont la date est plus ancienne que la
|
|
888
|
+
période ; une ligne dont la date est vide n'expire jamais, et un second passage n'atteint rien. Il
|
|
889
|
+
se confine au *tenant* du travail quand le travail en nomme un, et atteint chaque *tenant* quand il
|
|
890
|
+
n'en nomme aucun, comme le fait le *job* de nuit de la plateforme : un *tenant* oublié dans une liste
|
|
891
|
+
garderait ce qu'il ne doit pas. L'adaptateur implémente `PersonalDataRetention` du kernel et passe
|
|
892
|
+
`personalDataRetentionContract` ; `purgeExpiredPersonalData` du kernel lance chaque copie, et
|
|
893
|
+
`auditedPersonalDataRetention` de `@ddd-ts-kit/audit` enregistre chaque purge.
|
|
894
|
+
|
|
833
895
|
## Outbox et idempotence
|
|
834
896
|
|
|
835
897
|
- `DrizzleOutboxStore.claimBatch` sélectionne les lignes dues `FOR UPDATE SKIP LOCKED` et les
|
package/README.md
CHANGED
|
@@ -809,6 +809,66 @@ and limits are in the README of `@ddd-ts-kit/kernel` ([Rebuild](../kernel/README
|
|
|
809
809
|
The store passes `criteriaContract` and `readModelStoreContract` of
|
|
810
810
|
`@ddd-ts-kit/testing/contracts`, on PGlite and on PostgreSQL 18.
|
|
811
811
|
|
|
812
|
+
## Personal data erasure
|
|
813
|
+
|
|
814
|
+
The erasure of a data subject from the tables of a context, from the `personalFields` declarations
|
|
815
|
+
written next to its mappers (`@ddd-ts-kit/kernel`, "Personal data"): `DrizzlePersonalDataErasure` implements
|
|
816
|
+
the `PersonalDataErasure` port over the executor of the unit of work. The port of the context extends the one of the kernel, and
|
|
817
|
+
its adapter extends this class.
|
|
818
|
+
|
|
819
|
+
```ts
|
|
820
|
+
// infrastructure/persistence/person.personal-fields.ts: the table itself, the columns by the keys of its definition
|
|
821
|
+
export const personPersonalFields = personalFields<typeof persons.$inferSelect, PgTable>(persons, {
|
|
822
|
+
subject: 'id',
|
|
823
|
+
fields: ['displayName', 'email'],
|
|
824
|
+
erasure: 'row',
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
// infrastructure/persistence/drizzle-identity-erasure.repository.ts
|
|
828
|
+
@Repository(IdentityErasure)
|
|
829
|
+
export class DrizzleIdentityErasure extends DrizzlePersonalDataErasure<NodePgQueryResultHKT> implements IdentityErasure {
|
|
830
|
+
constructor(database: Database, scope: ExecutionScope, files: FileStorage) {
|
|
831
|
+
super(database, { name: 'identity.persons', declarations: [personPersonalFields], tenant: { scope }, files });
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
`erase(subject)` deletes the files the rows name from the storage first, then deletes the rows of
|
|
837
|
+
the subject (`row`) or pseudonymises them (`pseudonymise`: a text column reads `[erased]`, a column
|
|
838
|
+
of any other type reads nothing, a file column nothing), and answers how many rows it reached, none
|
|
839
|
+
the second time. With `tenant`, every statement is confined to the tenant of the work and never
|
|
840
|
+
widened by an elevation (the column named `tenant_id`, or `tenant.column`); without it, the table holds the rows of every tenant. A subject
|
|
841
|
+
that is not an opaque identifier is refused before any statement, and a declaration that names file
|
|
842
|
+
columns without a file storage is refused when the adapter is built. The types of the columns come from the table definition, so that a text and a number are pseudonymised each its own way. A personal column
|
|
843
|
+
that is not a text has to accept null, or the rows are erased with `row`: a declaration that would
|
|
844
|
+
pseudonymise one that does not is refused before any file or row is touched
|
|
845
|
+
(`NotNullablePersonalColumnError`). The adapter passes
|
|
846
|
+
`personalDataErasureContract` of `@ddd-ts-kit/testing`, as the in-memory one does, on PGlite and
|
|
847
|
+
PostgreSQL. What an erasure does not reach, and the whole chain (`eraseDataSubject`: the key, every
|
|
848
|
+
copy in every tenant, the rebuilds), is in the README of the kernel ("Personal data").
|
|
849
|
+
|
|
850
|
+
`DrizzlePersonalDataExport` answers the right of access and to portability from the same declarations:
|
|
851
|
+
`exportOf(subject)` hands over one `PersonalDataRecord` per row about the subject in every declared
|
|
852
|
+
table, under `<name>.<table>`, with each personal column and each file column (by its key) as plain
|
|
853
|
+
data, by the keys of the table definition, no other column and nothing of anyone else; a row pseudonymised already
|
|
854
|
+
answers what it reads. The same `tenant` option confines every statement to the tenant of the work, a
|
|
855
|
+
subject that is not an opaque identifier is refused before any statement, and the adapter passes
|
|
856
|
+
`personalDataExportContract`. The port of the context extends `PersonalDataExport` of the kernel and
|
|
857
|
+
its adapter extends this class with `name`, `declarations` and `tenant` (`DrizzlePersonalDataExportOptions`);
|
|
858
|
+
`generate repository --personal` writes both adapters, and `exportDataSubject` of the kernel gathers
|
|
859
|
+
every export into one dated document. Wrap the adapter with `auditedPersonalDataExport` of
|
|
860
|
+
`@ddd-ts-kit/audit` where it is bound, so that each handover leaves an entry.
|
|
861
|
+
|
|
862
|
+
The same declarations give the storage limitation (GDPR article 5(1)(e)): a declaration with
|
|
863
|
+
`retention: { after: 'endedAt', months: 36 }` says how long its rows keep the person, counted from a
|
|
864
|
+
date column of the row, and `purgeExpired(now)` of the erasure adapter erases, as the declaration
|
|
865
|
+
says, the rows whose date is older than the period; a row whose date is empty never expires, and a
|
|
866
|
+
second run reaches nothing. It confines itself to the tenant of the work when the work names one,
|
|
867
|
+
and reaches every tenant when it names none, as the nightly job of the platform does: a tenant left
|
|
868
|
+
out of a list would keep what it should not. The adapter implements `PersonalDataRetention` of the
|
|
869
|
+
kernel and passes `personalDataRetentionContract`; `purgeExpiredPersonalData` of the kernel runs
|
|
870
|
+
every copy, and `auditedPersonalDataRetention` of `@ddd-ts-kit/audit` records each purge.
|
|
871
|
+
|
|
812
872
|
## Outbox and idempotency
|
|
813
873
|
|
|
814
874
|
- `DrizzleOutboxStore.claimBatch` selects the due rows `FOR UPDATE SKIP LOCKED` and leases
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type SQL } from 'drizzle-orm';
|
|
2
|
+
import type { DrizzleErasureTenant } from './drizzle-personal-data-erasure-options.js';
|
|
3
|
+
import type { DrizzlePersonalFields } from './drizzle-personal-fields.js';
|
|
4
|
+
/** The rows about the subject, in the tenant of the work when the table holds tenant data. */
|
|
5
|
+
export declare function aboutSubject(declaration: DrizzlePersonalFields, subject: string, tenant: DrizzleErasureTenant | undefined): SQL;
|
|
6
|
+
//# sourceMappingURL=about-subject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"about-subject.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/about-subject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAMvE,8FAA8F;AAC9F,wBAAgB,YAAY,CAC1B,WAAW,EAAE,qBAAqB,EAClC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,oBAAoB,GAAG,SAAS,GACvC,GAAG,CAWL"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getTableColumns, sql } from 'drizzle-orm';
|
|
2
|
+
import { tenantScopeOf } from '@ddd-ts-kit/kernel';
|
|
3
|
+
import { columnOf } from '../read-model/column-of.js';
|
|
4
|
+
import { named } from './named.js';
|
|
5
|
+
import { tenantColumnOf } from './tenant-column-of.js';
|
|
6
|
+
const TENANT_COLUMN = 'tenant_id';
|
|
7
|
+
/** The rows about the subject, in the tenant of the work when the table holds tenant data. */
|
|
8
|
+
export function aboutSubject(declaration, subject, tenant) {
|
|
9
|
+
const columns = getTableColumns(declaration.table);
|
|
10
|
+
const subjectColumn = named(columnOf(columns, declaration.subject));
|
|
11
|
+
if (tenant === undefined) {
|
|
12
|
+
return sql `${subjectColumn} = ${subject}`;
|
|
13
|
+
}
|
|
14
|
+
const tenantColumn = tenantColumnOf(columns, tenant.column ?? TENANT_COLUMN, declaration);
|
|
15
|
+
return sql `${subjectColumn} = ${subject} and ${named(tenantColumn)} = ${tenantScopeOf(tenant.scope).tenantId}`;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=about-subject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"about-subject.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/about-subject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAY,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,aAAa,GAAG,WAAW,CAAC;AAElC,8FAA8F;AAC9F,MAAM,UAAU,YAAY,CAC1B,WAAkC,EAClC,OAAe,EACf,MAAwC;IAExC,MAAM,OAAO,GAAG,eAAe,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,aAAa,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAEpE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,GAAG,CAAA,GAAG,aAAa,MAAM,OAAO,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,IAAI,aAAa,EAAE,WAAW,CAAC,CAAC;IAE1F,OAAO,GAAG,CAAA,GAAG,aAAa,MAAM,OAAO,QAAQ,KAAK,CAAC,YAAY,CAAC,MAAM,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC;AACjH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ExecutionScope, FileStorage } from '@ddd-ts-kit/kernel';
|
|
2
|
+
import type { DrizzlePersonalFields } from './drizzle-personal-fields.js';
|
|
3
|
+
export interface DrizzleErasureTenant {
|
|
4
|
+
readonly scope: ExecutionScope;
|
|
5
|
+
/** The SQL name of the tenant column every declared table has. Default `tenant_id`. */
|
|
6
|
+
readonly column?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface DrizzlePersonalDataErasureOptions {
|
|
9
|
+
/** The copy this erasure reaches, as the report of `eraseDataSubject` names it: `identity.persons`. */
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** The tables of the context that hold personal data, each with its `personalFields` declaration. */
|
|
12
|
+
readonly declarations: readonly DrizzlePersonalFields[];
|
|
13
|
+
/** For tables of tenant data: every statement is confined to the tenant of the work in progress, and never widened by an elevation. Absent: the tables hold the rows of every tenant, or the project has none. */
|
|
14
|
+
readonly tenant?: DrizzleErasureTenant;
|
|
15
|
+
/** Where the files the declarations name live: deleted before their columns are emptied. Required as soon as a declaration names a file column. */
|
|
16
|
+
readonly files?: FileStorage;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=drizzle-personal-data-erasure-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-erasure-options.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-erasure-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,uFAAuF;IACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iCAAiC;IAChD,uGAAuG;IACvG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qGAAqG;IACrG,QAAQ,CAAC,YAAY,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACxD,kNAAkN;IAClN,QAAQ,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IACvC,mJAAmJ;IACnJ,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-erasure-options.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-erasure-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type TablesRelationalConfig } from 'drizzle-orm';
|
|
2
|
+
import { type PgQueryResultHKT } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { type PersonalDataErasure, type PersonalDataRetention } from '@ddd-ts-kit/kernel';
|
|
4
|
+
import type { DrizzleContext } from '../unit-of-work/drizzle-context.js';
|
|
5
|
+
import type { DrizzlePersonalDataErasureOptions } from './drizzle-personal-data-erasure-options.js';
|
|
6
|
+
/**
|
|
7
|
+
* The erasure of a data subject from the tables a context declared with `personalFields`, on
|
|
8
|
+
* Drizzle: the files the rows name are deleted from the storage first, then the rows of the subject
|
|
9
|
+
* are deleted (`row`) or their personal columns pseudonymised (`pseudonymise`: a text reads
|
|
10
|
+
* `ERASED_PERSONAL_DATA`, any other type nothing, a file column nothing). Every statement runs on
|
|
11
|
+
* the executor of the unit of work and, for tenant data, in the tenant of the work alone. The port
|
|
12
|
+
* of the context extends `PersonalDataErasure` and its adapter extends this class:
|
|
13
|
+
* `class DrizzlePatientErasure extends DrizzlePersonalDataErasure<NodePgQueryResultHKT> implements PatientErasure`.
|
|
14
|
+
* The same declarations give the storage limitation: `purgeExpired(now)` erases, as each declaration
|
|
15
|
+
* says, the rows whose `retention` ended.
|
|
16
|
+
*/
|
|
17
|
+
export declare class DrizzlePersonalDataErasure<Q extends PgQueryResultHKT, F extends Record<string, unknown> = Record<string, never>, S extends TablesRelationalConfig = TablesRelationalConfig> implements PersonalDataErasure, PersonalDataRetention {
|
|
18
|
+
private readonly context;
|
|
19
|
+
private readonly options;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
constructor(context: DrizzleContext<Q, F, S>, options: DrizzlePersonalDataErasureOptions);
|
|
22
|
+
/** The rows reached in every declared table, none the second time. A subject that is not an opaque id is refused before any statement. */
|
|
23
|
+
erase(subject: string): Promise<number>;
|
|
24
|
+
/** The rows whose retention ended before `now`, in every declared table that gives one, none the second time. */
|
|
25
|
+
purgeExpired(now: Date): Promise<number>;
|
|
26
|
+
/** What a pseudonymisation would write is settled, and refused, before any file or row is touched. */
|
|
27
|
+
private eraseIn;
|
|
28
|
+
/** The content first, then the reference: a row that still names a deleted file is run again, a file nothing names is lost. */
|
|
29
|
+
private deleteFilesOf;
|
|
30
|
+
private deleteRows;
|
|
31
|
+
private pseudonymise;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=drizzle-personal-data-erasure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-erasure.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-erasure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAiC,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAML,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC3B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAYjG;;;;;;;;;;GAUG;AACH,qBAAa,0BAA0B,CACrC,CAAC,SAAS,gBAAgB,EAC1B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACzD,CAAC,SAAS,sBAAsB,GAAG,sBAAsB,CACzD,YAAW,mBAAmB,EAAE,qBAAqB;IAKnD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YACmB,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAChC,OAAO,EAAE,iCAAiC,EAI5D;IAED,0IAA0I;IACpI,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAY5C;IAED,iHAAiH;IAC3G,YAAY,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ7C;IAED,sGAAsG;YACxF,OAAO;IAUrB,+HAA+H;YACjH,aAAa;YA6Bb,UAAU;YAQV,YAAY;CAkB3B"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { getTableColumns, sql } from 'drizzle-orm';
|
|
2
|
+
import { getTableConfig } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { ERASED_PERSONAL_DATA, NotADataSubjectIdError, NotNullablePersonalColumnError, isDataSubjectId, pseudonymisedValueOf, } from '@ddd-ts-kit/kernel';
|
|
4
|
+
import { columnOf } from '../read-model/column-of.js';
|
|
5
|
+
import { rowsOf } from '../read-model/rows-of.js';
|
|
6
|
+
import { aboutSubject } from './about-subject.js';
|
|
7
|
+
import { expiredRows } from './expired-rows.js';
|
|
8
|
+
import { named } from './named.js';
|
|
9
|
+
import { tableSqlOf } from './table-sql-of.js';
|
|
10
|
+
/**
|
|
11
|
+
* The erasure of a data subject from the tables a context declared with `personalFields`, on
|
|
12
|
+
* Drizzle: the files the rows name are deleted from the storage first, then the rows of the subject
|
|
13
|
+
* are deleted (`row`) or their personal columns pseudonymised (`pseudonymise`: a text reads
|
|
14
|
+
* `ERASED_PERSONAL_DATA`, any other type nothing, a file column nothing). Every statement runs on
|
|
15
|
+
* the executor of the unit of work and, for tenant data, in the tenant of the work alone. The port
|
|
16
|
+
* of the context extends `PersonalDataErasure` and its adapter extends this class:
|
|
17
|
+
* `class DrizzlePatientErasure extends DrizzlePersonalDataErasure<NodePgQueryResultHKT> implements PatientErasure`.
|
|
18
|
+
* The same declarations give the storage limitation: `purgeExpired(now)` erases, as each declaration
|
|
19
|
+
* says, the rows whose `retention` ended.
|
|
20
|
+
*/
|
|
21
|
+
export class DrizzlePersonalDataErasure {
|
|
22
|
+
context;
|
|
23
|
+
options;
|
|
24
|
+
name;
|
|
25
|
+
constructor(context, options) {
|
|
26
|
+
this.context = context;
|
|
27
|
+
this.options = options;
|
|
28
|
+
this.name = options.name;
|
|
29
|
+
assertFilesReachable(options);
|
|
30
|
+
}
|
|
31
|
+
/** The rows reached in every declared table, none the second time. A subject that is not an opaque id is refused before any statement. */
|
|
32
|
+
async erase(subject) {
|
|
33
|
+
if (!isDataSubjectId(subject)) {
|
|
34
|
+
throw new NotADataSubjectIdError();
|
|
35
|
+
}
|
|
36
|
+
let reached = 0;
|
|
37
|
+
for (const declaration of this.options.declarations) {
|
|
38
|
+
reached += await this.eraseIn(declaration, aboutSubject(declaration, subject, this.options.tenant));
|
|
39
|
+
}
|
|
40
|
+
return reached;
|
|
41
|
+
}
|
|
42
|
+
/** The rows whose retention ended before `now`, in every declared table that gives one, none the second time. */
|
|
43
|
+
async purgeExpired(now) {
|
|
44
|
+
let reached = 0;
|
|
45
|
+
for (const declaration of this.options.declarations.filter((declared) => declared.retention !== undefined)) {
|
|
46
|
+
reached += await this.eraseIn(declaration, expiredRows(declaration, { now, tenant: this.options.tenant }));
|
|
47
|
+
}
|
|
48
|
+
return reached;
|
|
49
|
+
}
|
|
50
|
+
/** What a pseudonymisation would write is settled, and refused, before any file or row is touched. */
|
|
51
|
+
async eraseIn(declaration, rows) {
|
|
52
|
+
const pseudonymised = declaration.erasure === 'row' ? undefined : pseudonymisedOf(declaration);
|
|
53
|
+
await this.deleteFilesOf(declaration, rows);
|
|
54
|
+
return pseudonymised === undefined
|
|
55
|
+
? this.deleteRows(declaration, rows)
|
|
56
|
+
: this.pseudonymise(declaration, rows, pseudonymised);
|
|
57
|
+
}
|
|
58
|
+
/** The content first, then the reference: a row that still names a deleted file is run again, a file nothing names is lost. */
|
|
59
|
+
async deleteFilesOf(declaration, rows) {
|
|
60
|
+
const storage = this.options.files;
|
|
61
|
+
if (declaration.files.length === 0 || storage === undefined) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const files = declaration.files.map((file) => columnOf(getTableColumns(declaration.table), file));
|
|
65
|
+
const anyFile = sql.join(files.map((file) => sql `${named(file)} is not null`), sql ` or `);
|
|
66
|
+
const withFiles = rowsOf(await this.context
|
|
67
|
+
.executor()
|
|
68
|
+
.execute(sql `select ${sql.join(files.map(named), sql `, `)} from ${tableSqlOf(declaration)} where ${rows} and (${anyFile})`));
|
|
69
|
+
for (const key of withFiles.flatMap((row) => files.map((file) => row[file.name]))) {
|
|
70
|
+
if (typeof key === 'string') {
|
|
71
|
+
await storage.delete(key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async deleteRows(declaration, rows) {
|
|
76
|
+
const deleted = await this.context
|
|
77
|
+
.executor()
|
|
78
|
+
.execute(sql `delete from ${tableSqlOf(declaration)} where ${rows} returning 1`);
|
|
79
|
+
return rowsOf(deleted).length;
|
|
80
|
+
}
|
|
81
|
+
async pseudonymise(declaration, rows, pseudonymised) {
|
|
82
|
+
const changes = sql.join(pseudonymised.map(({ column, erased }) => sql `${named(column)} = ${erased}`), sql `, `);
|
|
83
|
+
const updated = await this.context
|
|
84
|
+
.executor()
|
|
85
|
+
.execute(sql `update ${tableSqlOf(declaration)} set ${changes} where ${rows} and (${notYetErased(pseudonymised)}) returning 1`);
|
|
86
|
+
return rowsOf(updated).length;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Each personal column and what it reads once pseudonymised: the marker for a text, nothing for anything else or for a file, which the column has to accept. */
|
|
90
|
+
function pseudonymisedOf(declaration) {
|
|
91
|
+
const columns = getTableColumns(declaration.table);
|
|
92
|
+
const pseudonymised = [
|
|
93
|
+
...declaration.fields.map((field) => {
|
|
94
|
+
const column = columnOf(columns, field);
|
|
95
|
+
return { column, erased: pseudonymisedValueOf(column.getSQLType()) };
|
|
96
|
+
}),
|
|
97
|
+
...declaration.files.map((file) => ({ column: columnOf(columns, file), erased: null })),
|
|
98
|
+
];
|
|
99
|
+
for (const { column, erased } of pseudonymised) {
|
|
100
|
+
if (erased === null && column.notNull) {
|
|
101
|
+
throw new NotNullablePersonalColumnError(getTableConfig(declaration.table).name, column.name);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return pseudonymised;
|
|
105
|
+
}
|
|
106
|
+
/** A row is reached while one personal column still holds something: a text other than the marker, any other value, a file. */
|
|
107
|
+
function notYetErased(pseudonymised) {
|
|
108
|
+
return sql.join(pseudonymised.map(({ column, erased }) => erased === null
|
|
109
|
+
? sql `${named(column)} is not null`
|
|
110
|
+
: sql `(${named(column)} is not null and ${named(column)} <> ${ERASED_PERSONAL_DATA})`), sql ` or `);
|
|
111
|
+
}
|
|
112
|
+
function assertFilesReachable({ declarations, files }) {
|
|
113
|
+
const naming = declarations.find((declaration) => declaration.files.length > 0);
|
|
114
|
+
if (naming !== undefined && files === undefined) {
|
|
115
|
+
throw new Error(`The declaration of ${getTableConfig(naming.table).name} names file columns (${naming.files.join(', ')}) and no file storage was given: the files of an erased person would stay in the storage`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=drizzle-personal-data-erasure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-erasure.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-erasure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAyC,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAwC,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EACL,oBAAoB,EACpB,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AC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,+HAA+H;AAC/H,SAAS,YAAY,CAAC,aAAuC;IAC3D,OAAO,GAAG,CAAC,IAAI,CACb,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,CACvC,MAAM,KAAK,IAAI;QACb,CAAC,CAAC,GAAG,CAAA,GAAG,KAAK,CAAC,MAAM,CAAC,cAAc;QACnC,CAAC,CAAC,GAAG,CAAA,IAAI,KAAK,CAAC,MAAM,CAAC,oBAAoB,KAAK,CAAC,MAAM,CAAC,OAAO,oBAAoB,GAAG,CACxF,EACD,GAAG,CAAA,MAAM,CACV,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,EAAE,YAAY,EAAE,KAAK,EAAqC;IACtF,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEhF,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,sBAAsB,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,wBAAwB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,0FAA0F,CACjM,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DrizzlePersonalDataErasureOptions } from './drizzle-personal-data-erasure-options.js';
|
|
2
|
+
/** What an export reads: the copy it names, the tables of the context that hold personal data, the tenant that confines them. A file is handed over by its key, as a value. */
|
|
3
|
+
export type DrizzlePersonalDataExportOptions = Pick<DrizzlePersonalDataErasureOptions, 'name' | 'declarations' | 'tenant'>;
|
|
4
|
+
//# sourceMappingURL=drizzle-personal-data-export-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-export-options.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-export-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAC;AAEjG,+KAA+K;AAC/K,MAAM,MAAM,gCAAgC,GAAG,IAAI,CACjD,iCAAiC,EACjC,MAAM,GAAG,cAAc,GAAG,QAAQ,CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-export-options.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-export-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type TablesRelationalConfig } from 'drizzle-orm';
|
|
2
|
+
import { type PgQueryResultHKT } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { type PersonalDataExport, type PersonalDataRecord } from '@ddd-ts-kit/kernel';
|
|
4
|
+
import type { DrizzleContext } from '../unit-of-work/drizzle-context.js';
|
|
5
|
+
import type { DrizzlePersonalDataExportOptions } from './drizzle-personal-data-export-options.js';
|
|
6
|
+
/**
|
|
7
|
+
* The export of what a context keeps of a data subject, on Drizzle: for every table declared with
|
|
8
|
+
* `personalFields`, one record per row about the subject, under `<name>.<table>`, holding each
|
|
9
|
+
* personal column and each file column (by its key) as plain data, by the keys of the definition,
|
|
10
|
+
* nothing of anyone else and no other column. A row erased already answers what it reads,
|
|
11
|
+
* `[erased]` or nothing. Every statement runs on the executor of the unit of work and, for tenant
|
|
12
|
+
* data, in the tenant of the work alone. The port of the context extends `PersonalDataExport` and its
|
|
13
|
+
* adapter extends this class:
|
|
14
|
+
* `class DrizzlePatientExport extends DrizzlePersonalDataExport<NodePgQueryResultHKT> implements PatientExport`.
|
|
15
|
+
*/
|
|
16
|
+
export declare class DrizzlePersonalDataExport<Q extends PgQueryResultHKT, F extends Record<string, unknown> = Record<string, never>, S extends TablesRelationalConfig = TablesRelationalConfig> implements PersonalDataExport {
|
|
17
|
+
private readonly context;
|
|
18
|
+
private readonly options;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
constructor(context: DrizzleContext<Q, F, S>, options: DrizzlePersonalDataExportOptions);
|
|
21
|
+
/** The records about the subject in every declared table, in the order the store answers them. A subject that is not an opaque id is refused before any statement. */
|
|
22
|
+
exportOf(subject: string): Promise<readonly PersonalDataRecord[]>;
|
|
23
|
+
private recordsIn;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=drizzle-personal-data-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-export.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAiC,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAC;AAO/F;;;;;;;;;GASG;AACH,qBAAa,yBAAyB,CACpC,CAAC,SAAS,gBAAgB,EAC1B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACzD,CAAC,SAAS,sBAAsB,GAAG,sBAAsB,CACzD,YAAW,kBAAkB;IAK3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YACmB,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAChC,OAAO,EAAE,gCAAgC,EAG3D;IAED,sKAAsK;IAChK,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,kBAAkB,EAAE,CAAC,CAYtE;YAEa,SAAS;CAcxB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getTableColumns, sql } from 'drizzle-orm';
|
|
2
|
+
import { getTableConfig } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { NotADataSubjectIdError, isDataSubjectId, personalDataValueOf, } from '@ddd-ts-kit/kernel';
|
|
4
|
+
import { columnOf } from '../read-model/column-of.js';
|
|
5
|
+
import { rowsOf } from '../read-model/rows-of.js';
|
|
6
|
+
import { aboutSubject } from './about-subject.js';
|
|
7
|
+
import { named } from './named.js';
|
|
8
|
+
import { tableSqlOf } from './table-sql-of.js';
|
|
9
|
+
const COMMA = sql `, `;
|
|
10
|
+
/**
|
|
11
|
+
* The export of what a context keeps of a data subject, on Drizzle: for every table declared with
|
|
12
|
+
* `personalFields`, one record per row about the subject, under `<name>.<table>`, holding each
|
|
13
|
+
* personal column and each file column (by its key) as plain data, by the keys of the definition,
|
|
14
|
+
* nothing of anyone else and no other column. A row erased already answers what it reads,
|
|
15
|
+
* `[erased]` or nothing. Every statement runs on the executor of the unit of work and, for tenant
|
|
16
|
+
* data, in the tenant of the work alone. The port of the context extends `PersonalDataExport` and its
|
|
17
|
+
* adapter extends this class:
|
|
18
|
+
* `class DrizzlePatientExport extends DrizzlePersonalDataExport<NodePgQueryResultHKT> implements PatientExport`.
|
|
19
|
+
*/
|
|
20
|
+
export class DrizzlePersonalDataExport {
|
|
21
|
+
context;
|
|
22
|
+
options;
|
|
23
|
+
name;
|
|
24
|
+
constructor(context, options) {
|
|
25
|
+
this.context = context;
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.name = options.name;
|
|
28
|
+
}
|
|
29
|
+
/** The records about the subject in every declared table, in the order the store answers them. A subject that is not an opaque id is refused before any statement. */
|
|
30
|
+
async exportOf(subject) {
|
|
31
|
+
if (!isDataSubjectId(subject)) {
|
|
32
|
+
throw new NotADataSubjectIdError();
|
|
33
|
+
}
|
|
34
|
+
const records = [];
|
|
35
|
+
for (const declaration of this.options.declarations) {
|
|
36
|
+
records.push(...(await this.recordsIn(declaration, subject)));
|
|
37
|
+
}
|
|
38
|
+
return records;
|
|
39
|
+
}
|
|
40
|
+
async recordsIn(declaration, subject) {
|
|
41
|
+
const exported = exportedColumnsOf(declaration);
|
|
42
|
+
const names = exported.map(({ column }) => named(column));
|
|
43
|
+
const selected = sql.join(names, COMMA);
|
|
44
|
+
const about = aboutSubject(declaration, subject, this.options.tenant);
|
|
45
|
+
const statement = sql `select ${selected} from ${tableSqlOf(declaration)} where ${about}`;
|
|
46
|
+
const answered = await this.context.executor().execute(statement);
|
|
47
|
+
const source = `${this.name}.${getTableConfig(declaration.table).name}`;
|
|
48
|
+
return rowsOf(answered).map((row) => ({
|
|
49
|
+
source,
|
|
50
|
+
values: Object.fromEntries(exported.map(({ field, column }) => [field, personalDataValueOf(row[column.name])])),
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The declared columns of a table, each under the key of the definition the record names it by. */
|
|
55
|
+
function exportedColumnsOf(declaration) {
|
|
56
|
+
const columns = getTableColumns(declaration.table);
|
|
57
|
+
return [...declaration.fields, ...declaration.files].map((field) => ({ field, column: columnOf(columns, field) }));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=drizzle-personal-data-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-data-export.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-data-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAA+B,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,cAAc,EAAwC,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,mBAAmB,GAGpB,MAAM,oBA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le-orm/pg-core';
|
|
2
|
+
import type { ErasureMode, RetentionPeriod } from '@ddd-ts-kit/kernel';
|
|
3
|
+
/** A `personalFields` declaration on a Drizzle table, whatever its row type: the table itself, the columns by the keys of its definition. */
|
|
4
|
+
export interface DrizzlePersonalFields {
|
|
5
|
+
readonly table: PgTable;
|
|
6
|
+
readonly subject: string;
|
|
7
|
+
readonly fields: readonly string[];
|
|
8
|
+
readonly erasure: ErasureMode;
|
|
9
|
+
readonly files: readonly string[];
|
|
10
|
+
/** How long the rows keep it, from a date column: what `purgeExpired` reads. */
|
|
11
|
+
readonly retention?: RetentionPeriod & {
|
|
12
|
+
readonly after: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=drizzle-personal-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-fields.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEvE,6IAA6I;AAC7I,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,gFAAgF;IAChF,QAAQ,CAAC,SAAS,CAAC,EAAE,eAAe,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle-personal-fields.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/drizzle-personal-fields.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type SQL } from 'drizzle-orm';
|
|
2
|
+
import type { DrizzleErasureTenant } from './drizzle-personal-data-erasure-options.js';
|
|
3
|
+
import type { DrizzlePersonalFields } from './drizzle-personal-fields.js';
|
|
4
|
+
/**
|
|
5
|
+
* The rows of a declared table whose retention ended before `now`: their date column is earlier
|
|
6
|
+
* than the end of the period, a row whose date is empty never expires. In the tenant of the work
|
|
7
|
+
* when it names one, in every tenant when it names none: a purge is a policy of the table, run by
|
|
8
|
+
* the platform, and a tenant left out of a list would keep what it should not.
|
|
9
|
+
*/
|
|
10
|
+
export declare function expiredRows(declaration: DrizzlePersonalFields, { now, tenant }: {
|
|
11
|
+
readonly now: Date;
|
|
12
|
+
readonly tenant: DrizzleErasureTenant | undefined;
|
|
13
|
+
}): SQL;
|
|
14
|
+
//# sourceMappingURL=expired-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expired-rows.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/expired-rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAI7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIvE;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,WAAW,EAAE,qBAAqB,EAClC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAAA;CAAE,GACzF,GAAG,CAgBL"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getTableColumns, sql } from 'drizzle-orm';
|
|
2
|
+
import { getTableConfig } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { expiredBefore } from '@ddd-ts-kit/kernel';
|
|
4
|
+
import { columnOf } from '../read-model/column-of.js';
|
|
5
|
+
import { named } from './named.js';
|
|
6
|
+
import { tenantColumnOf } from './tenant-column-of.js';
|
|
7
|
+
/**
|
|
8
|
+
* The rows of a declared table whose retention ended before `now`: their date column is earlier
|
|
9
|
+
* than the end of the period, a row whose date is empty never expires. In the tenant of the work
|
|
10
|
+
* when it names one, in every tenant when it names none: a purge is a policy of the table, run by
|
|
11
|
+
* the platform, and a tenant left out of a list would keep what it should not.
|
|
12
|
+
*/
|
|
13
|
+
export function expiredRows(declaration, { now, tenant }) {
|
|
14
|
+
const { retention } = declaration;
|
|
15
|
+
if (retention === undefined) {
|
|
16
|
+
throw new Error(`The declaration of ${getTableConfig(declaration.table).name} gives no retention to purge by`);
|
|
17
|
+
}
|
|
18
|
+
const columns = getTableColumns(declaration.table);
|
|
19
|
+
const expired = sql `${named(columnOf(columns, retention.after))} < ${expiredBefore(retention, now)}`;
|
|
20
|
+
const tenantId = tenant?.scope.current()?.tenantId;
|
|
21
|
+
if (tenant === undefined || tenantId === undefined) {
|
|
22
|
+
return expired;
|
|
23
|
+
}
|
|
24
|
+
return sql `${expired} and ${named(tenantColumnOf(columns, tenant.column ?? 'tenant_id', declaration))} = ${tenantId}`;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=expired-rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expired-rows.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/expired-rows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAY,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGnD,OAAO,EAAE,KA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MAAM,EAAE,QAAQ,GAAG,GAAG,CAE3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/named.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAY,MAAM,aAAa,CAAC;AAG5C,oDAAoD;AACpD,MAAM,UAAU,KAAK,CAAC,MAAgB;IACpC,OAAO,GAAG,CAAA,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SQL } from 'drizzle-orm';
|
|
2
|
+
import type { DrizzlePersonalFields } from './drizzle-personal-fields.js';
|
|
3
|
+
/** The table of a declaration, in its schema, quoted. */
|
|
4
|
+
export declare function tableSqlOf({ table }: DrizzlePersonalFields): SQL;
|
|
5
|
+
//# sourceMappingURL=table-sql-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-sql-of.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/table-sql-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,GAAG,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,qBAAqB,GAAG,GAAG,CAIhE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { getTableConfig } from 'drizzle-orm/pg-core';
|
|
3
|
+
/** The table of a declaration, in its schema, quoted. */
|
|
4
|
+
export function tableSqlOf({ table }) {
|
|
5
|
+
const { schema, name } = getTableConfig(table);
|
|
6
|
+
return schema === undefined ? sql `${sql.identifier(name)}` : sql `${sql.identifier(schema)}.${sql.identifier(name)}`;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=table-sql-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-sql-of.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/table-sql-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAY,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,yDAAyD;AACzD,MAAM,UAAU,UAAU,CAAC,EAAE,KAAK,EAAyB;IACzD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAE/C,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;AACtH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PgColumn } from 'drizzle-orm/pg-core';
|
|
2
|
+
import type { DrizzlePersonalFields } from './drizzle-personal-fields.js';
|
|
3
|
+
/** The column of a table that names its tenant, by its SQL name. */
|
|
4
|
+
export declare function tenantColumnOf(columns: Readonly<Record<string, PgColumn>>, name: string, declaration: DrizzlePersonalFields): PgColumn;
|
|
5
|
+
//# sourceMappingURL=tenant-column-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-column-of.d.ts","sourceRoot":"","sources":["../../../src/postgres/personal-data/tenant-column-of.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,oEAAoE;AACpE,wBAAgB,cAAc,CAC5B,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAC3C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,qBAAqB,GACjC,QAAQ,CAUV"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getTableConfig } from 'drizzle-orm/pg-core';
|
|
2
|
+
/** The column of a table that names its tenant, by its SQL name. */
|
|
3
|
+
export function tenantColumnOf(columns, name, declaration) {
|
|
4
|
+
const column = Object.values(columns).find((candidate) => candidate.name === name);
|
|
5
|
+
if (column === undefined) {
|
|
6
|
+
throw new Error(`The table ${getTableConfig(declaration.table).name} has no column "${name}": a table of tenant data names its tenant in it, or the erasure is given the column`);
|
|
7
|
+
}
|
|
8
|
+
return column;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=tenant-column-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant-column-of.js","sourceRoot":"","sources":["../../../src/postgres/personal-data/tenant-column-of.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,oEAAoE;AACpE,MAAM,UAAU,cAAc,CAC5B,OAA2C,EAC3C,IAAY,EACZ,WAAkC;IAElC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAEnF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,aAAa,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,mBAAmB,IAAI,sFAAsF,CACjK,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/postgres.d.ts
CHANGED
|
@@ -28,4 +28,9 @@ export * from './postgres/jobs/jobs-table.js';
|
|
|
28
28
|
export * from './postgres/jobs/drizzle-job-store.js';
|
|
29
29
|
export * from './postgres/processes/processes-table.js';
|
|
30
30
|
export * from './postgres/processes/drizzle-process-store.js';
|
|
31
|
+
export * from './postgres/personal-data/drizzle-personal-data-erasure.js';
|
|
32
|
+
export * from './postgres/personal-data/drizzle-personal-data-erasure-options.js';
|
|
33
|
+
export * from './postgres/personal-data/drizzle-personal-data-export.js';
|
|
34
|
+
export * from './postgres/personal-data/drizzle-personal-data-export-options.js';
|
|
35
|
+
export * from './postgres/personal-data/drizzle-personal-fields.js';
|
|
31
36
|
//# sourceMappingURL=postgres.d.ts.map
|
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,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,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DAAkD,CAAC"}
|
package/dist/postgres.js
CHANGED
|
@@ -28,4 +28,9 @@ export * from './postgres/jobs/jobs-table.js';
|
|
|
28
28
|
export * from './postgres/jobs/drizzle-job-store.js';
|
|
29
29
|
export * from './postgres/processes/processes-table.js';
|
|
30
30
|
export * from './postgres/processes/drizzle-process-store.js';
|
|
31
|
+
export * from './postgres/personal-data/drizzle-personal-data-erasure.js';
|
|
32
|
+
export * from './postgres/personal-data/drizzle-personal-data-erasure-options.js';
|
|
33
|
+
export * from './postgres/personal-data/drizzle-personal-data-export.js';
|
|
34
|
+
export * from './postgres/personal-data/drizzle-personal-data-export-options.js';
|
|
35
|
+
export * from './postgres/personal-data/drizzle-personal-fields.js';
|
|
31
36
|
//# sourceMappingURL=postgres.js.map
|
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,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,cA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;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.89.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",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@ddd-ts-kit/kernel": "0.
|
|
43
|
-
"@ddd-ts-kit/events": "0.
|
|
44
|
-
"@ddd-ts-kit/scheduling": "0.
|
|
42
|
+
"@ddd-ts-kit/kernel": "0.89.0",
|
|
43
|
+
"@ddd-ts-kit/events": "0.89.0",
|
|
44
|
+
"@ddd-ts-kit/scheduling": "0.89.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"drizzle-orm": ">=0.40.0"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"drizzle-orm": "latest",
|
|
51
51
|
"@electric-sql/pglite": "0.5.10",
|
|
52
|
-
"@ddd-ts-kit/testing": "0.
|
|
52
|
+
"@ddd-ts-kit/testing": "0.89.0",
|
|
53
53
|
"pg": "^8.23.1",
|
|
54
54
|
"@types/pg": "^8.23.1"
|
|
55
55
|
}
|