@ddd-ts-kit/knex 0.88.0 → 0.90.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.
Files changed (39) hide show
  1. package/README.fr.md +66 -1
  2. package/README.md +63 -0
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +5 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/personal-data/knex-personal-data-erasure-options.d.ts +17 -0
  8. package/dist/personal-data/knex-personal-data-erasure-options.d.ts.map +1 -0
  9. package/dist/personal-data/knex-personal-data-erasure-options.js +2 -0
  10. package/dist/personal-data/knex-personal-data-erasure-options.js.map +1 -0
  11. package/dist/personal-data/knex-personal-data-erasure.d.ts +34 -0
  12. package/dist/personal-data/knex-personal-data-erasure.d.ts.map +1 -0
  13. package/dist/personal-data/knex-personal-data-erasure.js +131 -0
  14. package/dist/personal-data/knex-personal-data-erasure.js.map +1 -0
  15. package/dist/personal-data/knex-personal-data-export-options.d.ts +4 -0
  16. package/dist/personal-data/knex-personal-data-export-options.d.ts.map +1 -0
  17. package/dist/personal-data/knex-personal-data-export-options.js +2 -0
  18. package/dist/personal-data/knex-personal-data-export-options.js.map +1 -0
  19. package/dist/personal-data/knex-personal-data-export.d.ts +22 -0
  20. package/dist/personal-data/knex-personal-data-export.d.ts.map +1 -0
  21. package/dist/personal-data/knex-personal-data-export.js +43 -0
  22. package/dist/personal-data/knex-personal-data-export.js.map +1 -0
  23. package/dist/personal-data/knex-personal-fields.d.ts +15 -0
  24. package/dist/personal-data/knex-personal-fields.d.ts.map +1 -0
  25. package/dist/personal-data/knex-personal-fields.js +2 -0
  26. package/dist/personal-data/knex-personal-fields.js.map +1 -0
  27. package/dist/personal-data/records-of.d.ts +3 -0
  28. package/dist/personal-data/records-of.d.ts.map +1 -0
  29. package/dist/personal-data/records-of.js +6 -0
  30. package/dist/personal-data/records-of.js.map +1 -0
  31. package/dist/personal-data/rows-about.d.ts +17 -0
  32. package/dist/personal-data/rows-about.d.ts.map +1 -0
  33. package/dist/personal-data/rows-about.js +16 -0
  34. package/dist/personal-data/rows-about.js.map +1 -0
  35. package/dist/personal-data/rows-expired.d.ts +16 -0
  36. package/dist/personal-data/rows-expired.d.ts.map +1 -0
  37. package/dist/personal-data/rows-expired.js +20 -0
  38. package/dist/personal-data/rows-expired.js.map +1 -0
  39. 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:af94625dc6e22b42 -->
2
+ <!-- translation-of: README.md sha256:3ccbe053ae2527ea -->
3
3
 
4
4
  # @ddd-ts-kit/knex
5
5
 
@@ -753,6 +753,71 @@ README de `@ddd-ts-kit/kernel` (« Reconstruction »). Le store passe `criteriaC
753
753
  `readModelStoreContract` de `@ddd-ts-kit/testing/contracts`, sur PGlite et sur PostgreSQL 18.
754
754
  Les critères et les modèles de lecture n'ont jamais été exécutés sur MySQL ni sur SQLite.
755
755
 
756
+ ## Effacement des données personnelles
757
+
758
+ L'effacement d'une personne concernée des tables d'un contexte, à partir des déclarations
759
+ `personalFields` écrites à côté de ses *mappers* (`@ddd-ts-kit/kernel`, « Données personnelles ») :
760
+ `KnexPersonalDataErasure` implémente le port `PersonalDataErasure` sur l'exécuteur de l'unité de travail. Le port du contexte étend celui du
761
+ kernel, et son adaptateur étend cette classe.
762
+
763
+ ```ts
764
+ // infrastructure/persistence/person.personal-fields.ts
765
+ export const personPersonalFields = personalFields<PersonRow, TenantTableTarget>(PERSONS, {
766
+ subject: 'id',
767
+ fields: ['display_name', 'email'],
768
+ erasure: 'row',
769
+ });
770
+
771
+ // application/ports/identity-erasure.port.ts
772
+ export abstract class IdentityErasure extends PersonalDataErasure {}
773
+
774
+ // infrastructure/persistence/knex-identity-erasure.repository.ts
775
+ @Repository(IdentityErasure)
776
+ export class KnexIdentityErasure extends KnexPersonalDataErasure implements IdentityErasure {
777
+ constructor(database: KnexContext, scope: ExecutionScope, files: FileStorage) {
778
+ super(database, { name: 'identity.persons', declarations: [personPersonalFields], tenant: scope, files });
779
+ }
780
+ }
781
+ ```
782
+
783
+ `erase(subject)` supprime d'abord du stockage les fichiers que les lignes nomment, puis supprime les
784
+ lignes de la personne (`row`) ou les pseudonymise (`pseudonymise` : une colonne texte lit `[erased]`,
785
+ une colonne de tout autre type ne lit rien, une colonne de fichier rien), et répond combien de lignes
786
+ il a atteintes, aucune la seconde fois. Avec `tenant`, chaque instruction est confinée au *tenant* du
787
+ travail et jamais élargie par une élévation (`tenant_id`, ou la `column` de la cible) ; sans lui, la table tient les lignes de tous
788
+ les *tenants*. Un sujet qui n'est pas un identifiant opaque est refusé avant toute instruction, et une
789
+ déclaration qui nomme des colonnes de fichier sans stockage de fichiers est refusée à la construction
790
+ de l'adaptateur. Les types des colonnes sont lus une fois dans la base (`columnInfo`), 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
791
+ les lignes s'effacent avec `row` : une déclaration qui en pseudonymiserait une qui ne l'accepte pas
792
+ est refusée avant qu'un fichier ou une ligne ne soit touché (`NotNullablePersonalColumnError`). L'adaptateur passe `personalDataErasureContract` de
793
+ `@ddd-ts-kit/testing`, comme celui en mémoire, sur PGlite et PostgreSQL. Ce qu'un effacement
794
+ n'atteint pas, et la chaîne entière (`eraseDataSubject` : la clé, chaque copie dans chaque *tenant*,
795
+ les reconstructions), sont dans le README du kernel (« Données personnelles »).
796
+
797
+ `KnexPersonalDataExport` répond au droit d'accès et à la portabilité à partir des mêmes déclarations :
798
+ `exportOf(subject)` remet un `PersonalDataRecord` par ligne sur la personne dans chaque table déclarée,
799
+ sous `<name>.<table>`, avec chaque colonne personnelle et chaque colonne de fichier (par sa clé) en
800
+ données simples, par leurs noms SQL, aucune autre colonne et rien de personne d'autre ; une ligne déjà
801
+ pseudonymisée répond ce qu'elle lit. La même option `tenant` confine chaque instruction au *tenant* du
802
+ travail, un sujet qui n'est pas un identifiant opaque est refusé avant toute instruction, et
803
+ l'adaptateur passe `personalDataExportContract`. Le port du contexte étend `PersonalDataExport` du
804
+ kernel et son adaptateur étend cette classe avec `name`, `declarations` et `tenant`
805
+ (`KnexPersonalDataExportOptions`) ; `generate repository --personal` écrit les deux adaptateurs, et
806
+ `exportDataSubject` du kernel rassemble chaque export en un document daté. Enveloppez l'adaptateur
807
+ avec `auditedPersonalDataExport` de `@ddd-ts-kit/audit` là où il est lié, pour que chaque remise
808
+ laisse une entrée.
809
+
810
+ Les mêmes déclarations donnent la limitation de la conservation (RGPD, article 5(1)(e)) : une
811
+ déclaration avec `retention: { after: 'ended_at', months: 36 }` dit combien de temps ses lignes gardent
812
+ la personne, compté depuis une colonne de date de la ligne, et `purgeExpired(now)` de l'adaptateur
813
+ d'effacement efface, comme la déclaration le dit, les lignes dont la date est plus ancienne que la
814
+ période ; une ligne dont la date est vide n'expire jamais, et un second passage n'atteint rien. Il
815
+ se confine au *tenant* du travail quand le travail en nomme un, et atteint chaque *tenant* quand il
816
+ n'en nomme aucun, comme le fait le *job* de nuit de la plateforme : un *tenant* oublié dans une liste
817
+ garderait ce qu'il ne doit pas. L'adaptateur implémente `PersonalDataRetention` du kernel et passe
818
+ `personalDataRetentionContract` ; `purgeExpiredPersonalData` du kernel lance chaque copie, et
819
+ `auditedPersonalDataRetention` de `@ddd-ts-kit/audit` enregistre chaque purge.
820
+
756
821
  ## Outbox et idempotence
757
822
 
758
823
  - `KnexOutboxStore.claimBatch` sélectionne les lignes dues `FOR UPDATE SKIP LOCKED` et les
package/README.md CHANGED
@@ -723,6 +723,69 @@ and limits are in the README of `@ddd-ts-kit/kernel` ("Rebuild"). The store pass
723
723
  and on PostgreSQL 18.
724
724
  Criteria and read models were never run on MySQL or SQLite.
725
725
 
726
+ ## Personal data erasure
727
+
728
+ The erasure of a data subject from the tables of a context, from the `personalFields` declarations
729
+ written next to its mappers (`@ddd-ts-kit/kernel`, "Personal data"): `KnexPersonalDataErasure` implements
730
+ the `PersonalDataErasure` port over the executor of the unit of work. The port of the context extends the one of the kernel, and
731
+ its adapter extends this class.
732
+
733
+ ```ts
734
+ // infrastructure/persistence/person.personal-fields.ts
735
+ export const personPersonalFields = personalFields<PersonRow, TenantTableTarget>(PERSONS, {
736
+ subject: 'id',
737
+ fields: ['display_name', 'email'],
738
+ erasure: 'row',
739
+ });
740
+
741
+ // application/ports/identity-erasure.port.ts
742
+ export abstract class IdentityErasure extends PersonalDataErasure {}
743
+
744
+ // infrastructure/persistence/knex-identity-erasure.repository.ts
745
+ @Repository(IdentityErasure)
746
+ export class KnexIdentityErasure extends KnexPersonalDataErasure implements IdentityErasure {
747
+ constructor(database: KnexContext, scope: ExecutionScope, files: FileStorage) {
748
+ super(database, { name: 'identity.persons', declarations: [personPersonalFields], tenant: scope, files });
749
+ }
750
+ }
751
+ ```
752
+
753
+ `erase(subject)` deletes the files the rows name from the storage first, then deletes the rows of
754
+ the subject (`row`) or pseudonymises them (`pseudonymise`: a text column reads `[erased]`, a column
755
+ of any other type reads nothing, a file column nothing), and answers how many rows it reached, none
756
+ the second time. With `tenant`, every statement is confined to the tenant of the work and never
757
+ widened by an elevation (`tenant_id`, or the `column` of the target); without it, the table holds the rows of every tenant. A subject
758
+ that is not an opaque identifier is refused before any statement, and a declaration that names file
759
+ columns without a file storage is refused when the adapter is built. The types of the columns are read once from the database (`columnInfo`), so that a text and a number are pseudonymised each its own way. A personal column
760
+ that is not a text has to accept null, or the rows are erased with `row`: a declaration that would
761
+ pseudonymise one that does not is refused before any file or row is touched
762
+ (`NotNullablePersonalColumnError`). The adapter passes
763
+ `personalDataErasureContract` of `@ddd-ts-kit/testing`, as the in-memory one does, on PGlite and
764
+ PostgreSQL. What an erasure does not reach, and the whole chain (`eraseDataSubject`: the key, every
765
+ copy in every tenant, the rebuilds), is in the README of the kernel ("Personal data").
766
+
767
+ `KnexPersonalDataExport` answers the right of access and to portability from the same declarations:
768
+ `exportOf(subject)` hands over one `PersonalDataRecord` per row about the subject in every declared
769
+ table, under `<name>.<table>`, with each personal column and each file column (by its key) as plain
770
+ data, by their SQL names, no other column and nothing of anyone else; a row pseudonymised already
771
+ answers what it reads. The same `tenant` option confines every statement to the tenant of the work, a
772
+ subject that is not an opaque identifier is refused before any statement, and the adapter passes
773
+ `personalDataExportContract`. The port of the context extends `PersonalDataExport` of the kernel and
774
+ its adapter extends this class with `name`, `declarations` and `tenant` (`KnexPersonalDataExportOptions`);
775
+ `generate repository --personal` writes both adapters, and `exportDataSubject` of the kernel gathers
776
+ every export into one dated document. Wrap the adapter with `auditedPersonalDataExport` of
777
+ `@ddd-ts-kit/audit` where it is bound, so that each handover leaves an entry.
778
+
779
+ The same declarations give the storage limitation (GDPR article 5(1)(e)): a declaration with
780
+ `retention: { after: 'ended_at', months: 36 }` says how long its rows keep the person, counted from a
781
+ date column of the row, and `purgeExpired(now)` of the erasure adapter erases, as the declaration
782
+ says, the rows whose date is older than the period; a row whose date is empty never expires, and a
783
+ second run reaches nothing. It confines itself to the tenant of the work when the work names one,
784
+ and reaches every tenant when it names none, as the nightly job of the platform does: a tenant left
785
+ out of a list would keep what it should not. The adapter implements `PersonalDataRetention` of the
786
+ kernel and passes `personalDataRetentionContract`; `purgeExpiredPersonalData` of the kernel runs
787
+ every copy, and `auditedPersonalDataRetention` of `@ddd-ts-kit/audit` records each purge.
788
+
726
789
  ## Outbox and idempotency
727
790
 
728
791
  - `KnexOutboxStore.claimBatch` selects the due rows `FOR UPDATE SKIP LOCKED` and leases them in
package/dist/index.d.ts CHANGED
@@ -54,4 +54,9 @@ export * from './processes/process-table-options.js';
54
54
  export * from './processes/create-process-table.js';
55
55
  export * from './processes/drop-process-table.js';
56
56
  export * from './processes/knex-process-store.js';
57
+ export * from './personal-data/knex-personal-data-erasure.js';
58
+ export * from './personal-data/knex-personal-data-erasure-options.js';
59
+ export * from './personal-data/knex-personal-data-export.js';
60
+ export * from './personal-data/knex-personal-data-export-options.js';
61
+ export * from './personal-data/knex-personal-fields.js';
57
62
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AA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AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4CAA4C,CAAC;AAC3D,cAAc,oDAAoD,CAAC;AACnE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mDAAmD,CAAC;AAClE,cAAc,sCAAsC,CAAC"}
package/dist/index.js CHANGED
@@ -54,4 +54,9 @@ export * from './processes/process-table-options.js';
54
54
  export * from './processes/create-process-table.js';
55
55
  export * from './processes/drop-process-table.js';
56
56
  export * from './processes/knex-process-store.js';
57
+ export * from './personal-data/knex-personal-data-erasure.js';
58
+ export * from './personal-data/knex-personal-data-erasure-options.js';
59
+ export * from './personal-data/knex-personal-data-export.js';
60
+ export * from './personal-data/knex-personal-data-export-options.js';
61
+ export * from './personal-data/knex-personal-fields.js';
57
62
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,GAEb,MAAM,oBAAoB,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qCAAqC,CAAC;AACpD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2CAA2C,CAAC;AAC1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'./knex-personal-fields.js';
3
+ export interface KnexPersonalDataErasureOptions {
4
+ /** The copy this erasure reaches, as the report of `eraseDataSubject` names it: `identity.persons`. */
5
+ readonly name: string;
6
+ /** The tables of the context that hold personal data, each with its `personalFields` declaration. */
7
+ readonly declarations: readonly KnexPersonalFields[];
8
+ /**
9
+ * For tables of tenant data: every statement is confined to the tenant of the work in progress
10
+ * (`tenant_id`, or the `column` of the target), and never widened by an elevation. Absent: the
11
+ * tables hold the rows of every tenant, or the project has none.
12
+ */
13
+ readonly tenant?: ExecutionScope;
14
+ /** Where the files the declarations name live: deleted before their columns are emptied. Required as soon as a declaration names a file column. */
15
+ readonly files?: FileStorage;
16
+ }
17
+ //# sourceMappingURL=knex-personal-data-erasure-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-erasure-options.d.ts","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-erasure-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,MAAM,WAAW,8BAA8B;IAC7C,uGAAuG;IACvG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qGAAqG;IACrG,QAAQ,CAAC,YAAY,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACrD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IACjC,mJAAmJ;IACnJ,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;CAC9B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=knex-personal-data-erasure-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-erasure-options.js","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-erasure-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { type PersonalDataErasure, type PersonalDataRetention } from '@ddd-ts-kit/kernel';
2
+ import type { KnexContext } from '../unit-of-work/knex-context.js';
3
+ import type { KnexPersonalDataErasureOptions } from './knex-personal-data-erasure-options.js';
4
+ /**
5
+ * The erasure of a data subject from the tables a context declared with `personalFields`, on Knex:
6
+ * the files the rows name are deleted from the storage first, then the rows of the subject are
7
+ * deleted (`row`) or their personal columns pseudonymised (`pseudonymise`: a text reads
8
+ * `ERASED_PERSONAL_DATA`, any other type nothing, a file column nothing). Every statement runs on
9
+ * the executor of the unit of work and, for tenant data, in the tenant of the work alone. The port
10
+ * of the context extends `PersonalDataErasure` and its adapter extends this class:
11
+ * `class KnexPatientErasure extends KnexPersonalDataErasure implements PatientErasure`. The same
12
+ * declarations give the storage limitation: `purgeExpired(now)` erases, as each declaration says,
13
+ * the rows whose `retention` ended.
14
+ */
15
+ export declare class KnexPersonalDataErasure implements PersonalDataErasure, PersonalDataRetention {
16
+ private readonly context;
17
+ private readonly options;
18
+ readonly name: string;
19
+ private readonly columns;
20
+ constructor(context: KnexContext, options: KnexPersonalDataErasureOptions);
21
+ /** The rows reached in every declared table, none the second time. A subject that is not an opaque id is refused before any statement. */
22
+ erase(subject: string): Promise<number>;
23
+ /** The rows whose retention ended before `now`, in every declared table that gives one, none the second time. */
24
+ purgeExpired(now: Date): Promise<number>;
25
+ /** What a pseudonymisation would write is settled, and refused, before any file or row is touched. */
26
+ private eraseIn;
27
+ /** The content first, then the reference: a row that still names a deleted file is run again, a file nothing names is lost. */
28
+ private deleteFilesOf;
29
+ /** 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. */
30
+ private changesOf;
31
+ /** What the catalogue says of each column of the table, read once: a text is pseudonymised, anything else emptied. */
32
+ private columnsOf;
33
+ }
34
+ //# sourceMappingURL=knex-personal-data-erasure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-erasure.d.ts","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-erasure.ts"],"names":[],"mappings":"AACA,OAAO,EAML,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC3B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAiB3F;;;;;;;;;;GAUG;AACH,qBAAa,uBAAwB,YAAW,mBAAmB,EAAE,qBAAqB;IAMtF,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAN1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgE;IAExF,YACmB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,8BAA8B,EAIzD;IAED,0IAA0I;IACpI,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAc5C;IAED,iHAAiH;IAC3G,YAAY,CAAC,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAU7C;IAED,sGAAsG;YACxF,OAAO;IAYrB,+HAA+H;YACjH,aAAa;IA2B3B,iKAAiK;YACnJ,SAAS;IAqBvB,sHAAsH;IACtH,OAAO,CAAC,SAAS;CAoBlB"}
@@ -0,0 +1,131 @@
1
+ import { ERASED_PERSONAL_DATA, NotADataSubjectIdError, NotNullablePersonalColumnError, isDataSubjectId, pseudonymisedValueOf, } from '@ddd-ts-kit/kernel';
2
+ import { tableIn } from '../tenancy/table-in.js';
3
+ import { recordsOf } from './records-of.js';
4
+ import { rowsAbout } from './rows-about.js';
5
+ import { rowsExpired } from './rows-expired.js';
6
+ /**
7
+ * The erasure of a data subject from the tables a context declared with `personalFields`, on Knex:
8
+ * the files the rows name are deleted from the storage first, then the rows of the subject are
9
+ * 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 KnexPatientErasure extends KnexPersonalDataErasure implements PatientErasure`. The same
14
+ * declarations give the storage limitation: `purgeExpired(now)` erases, as each declaration says,
15
+ * the rows whose `retention` ended.
16
+ */
17
+ export class KnexPersonalDataErasure {
18
+ context;
19
+ options;
20
+ name;
21
+ columns = new Map();
22
+ constructor(context, options) {
23
+ this.context = context;
24
+ this.options = options;
25
+ this.name = options.name;
26
+ assertFilesReachable(options);
27
+ }
28
+ /** The rows reached in every declared table, none the second time. A subject that is not an opaque id is refused before any statement. */
29
+ async erase(subject) {
30
+ if (!isDataSubjectId(subject)) {
31
+ throw new NotADataSubjectIdError();
32
+ }
33
+ let reached = 0;
34
+ for (const declaration of this.options.declarations) {
35
+ reached += await this.eraseIn(declaration, () => rowsAbout(this.context, { declaration, subject }, this.options.tenant));
36
+ }
37
+ return reached;
38
+ }
39
+ /** The rows whose retention ended before `now`, in every declared table that gives one, none the second time. */
40
+ async purgeExpired(now) {
41
+ let reached = 0;
42
+ for (const declaration of this.options.declarations.filter((declared) => declared.retention !== undefined)) {
43
+ reached += await this.eraseIn(declaration, () => rowsExpired(this.context, declaration, { now, tenant: this.options.tenant }));
44
+ }
45
+ return reached;
46
+ }
47
+ /** What a pseudonymisation would write is settled, and refused, before any file or row is touched. */
48
+ async eraseIn(declaration, rows) {
49
+ const changes = declaration.erasure === 'row' ? undefined : await this.changesOf(declaration);
50
+ await this.deleteFilesOf(declaration, rows);
51
+ return changes === undefined
52
+ ? rows().delete()
53
+ : rows()
54
+ .where((reached) => notYetErased(reached, changes))
55
+ .update(changes);
56
+ }
57
+ /** The content first, then the reference: a row that still names a deleted file is run again, a file nothing names is lost. */
58
+ async deleteFilesOf(declaration, rows) {
59
+ const { files } = declaration;
60
+ const storage = this.options.files;
61
+ if (files.length === 0 || storage === undefined) {
62
+ return;
63
+ }
64
+ const named = await rows()
65
+ .select(files)
66
+ .where((any) => {
67
+ for (const file of files) {
68
+ void any.orWhereNotNull(file);
69
+ }
70
+ });
71
+ for (const row of recordsOf(named)) {
72
+ for (const file of files) {
73
+ const key = row[file];
74
+ if (typeof key === 'string') {
75
+ await storage.delete(key);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ /** 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. */
81
+ async changesOf(declaration) {
82
+ const columns = await this.columnsOf(declaration);
83
+ const table = `${declaration.table.schema ?? ''}.${declaration.table.table}`;
84
+ const changes = Object.fromEntries([
85
+ ...declaration.fields.map((field) => [
86
+ field,
87
+ pseudonymisedValueOf(columns[field]?.type ?? ''),
88
+ ]),
89
+ ...declaration.files.map((file) => [file, null]),
90
+ ]);
91
+ for (const [column, erased] of Object.entries(changes)) {
92
+ if (erased === null && columns[column]?.nullable === false) {
93
+ throw new NotNullablePersonalColumnError(table, column);
94
+ }
95
+ }
96
+ return changes;
97
+ }
98
+ /** What the catalogue says of each column of the table, read once: a text is pseudonymised, anything else emptied. */
99
+ columnsOf({ table }) {
100
+ const name = `${table.schema ?? ''}.${table.table}`;
101
+ const known = this.columns.get(name);
102
+ if (known !== undefined) {
103
+ return known;
104
+ }
105
+ const read = tableIn(this.context, table)
106
+ .columnInfo()
107
+ .then((columns) => Object.fromEntries(Object.entries(columns).map(([column, info]) => [column, { type: info.type, nullable: info.nullable }])));
108
+ this.columns.set(name, read);
109
+ return read;
110
+ }
111
+ }
112
+ /** A row is reached while one personal column still holds something: a text other than the marker, any other value, a file. */
113
+ function notYetErased(reached, changes) {
114
+ for (const [column, erased] of Object.entries(changes)) {
115
+ if (erased === null) {
116
+ void reached.orWhereNotNull(column);
117
+ }
118
+ else {
119
+ void reached.orWhere((text) => {
120
+ void text.whereNotNull(column).whereNot(column, ERASED_PERSONAL_DATA);
121
+ });
122
+ }
123
+ }
124
+ }
125
+ function assertFilesReachable({ declarations, files }) {
126
+ const naming = declarations.find((declaration) => declaration.files.length > 0);
127
+ if (naming !== undefined && files === undefined) {
128
+ throw new Error(`The declaration of ${naming.table.table} names file columns (${naming.files.join(', ')}) and no file storage was given: the files of an erased person would stay in the storage`);
129
+ }
130
+ }
131
+ //# sourceMappingURL=knex-personal-data-erasure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-erasure.js","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-erasure.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,8BAA8B,EAC9B,eAAe,EACf,oBAAoB,GAGrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAa7C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAuB;IAMf,OAAO;IACP,OAAO;IANjB,IAAI,CAAS;IAEL,OAAO,GAAG,IAAI,GAAG,EAAqD,CAAC;IAExF,YACmB,OAAoB,EACpB,OAAuC;uBADvC,OAAO;uBACP,OAAO;QAExB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,0IAA0I;IAC1I,KAAK,CAAC,KAAK,CAAC,OAAe;QACzB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,sBAAsB,EAAE,CAAC;QACrC,CAAC;QAED,IAAI,OAAO,GAAG,CAAC,CAAC;QAEhB,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YACpD,OAAO,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW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CACxG,CACF,CAAC;QAEJ,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAE7B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,+HAA+H;AAC/H,SAAS,YAAY,CAAC,OAA0B,EAAE,OAAgB;IAChE,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACvD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,KAAK,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBAC5B,KAAK,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,EAAE,YAAY,EAAE,KAAK,EAAkC;IACnF,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,MAAM,CAAC,KAAK,CAAC,KAAK,wBAAwB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,0FAA0F,CAClL,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { KnexPersonalDataErasureOptions } from './knex-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 KnexPersonalDataExportOptions = Pick<KnexPersonalDataErasureOptions, 'name' | 'declarations' | 'tenant'>;
4
+ //# sourceMappingURL=knex-personal-data-export-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-export-options.d.ts","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-export-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAE3F,+KAA+K;AAC/K,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAAC,8BAA8B,EAAE,MAAM,GAAG,cAAc,GAAG,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=knex-personal-data-export-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-export-options.js","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-export-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import { type PersonalDataExport, type PersonalDataRecord } from '@ddd-ts-kit/kernel';
2
+ import type { KnexContext } from '../unit-of-work/knex-context.js';
3
+ import type { KnexPersonalDataExportOptions } from './knex-personal-data-export-options.js';
4
+ /**
5
+ * The export of what a context keeps of a data subject, on Knex: for every table declared with
6
+ * `personalFields`, one record per row about the subject, under `<name>.<table>`, holding each
7
+ * personal column and each file column (by its key) as plain data, nothing of anyone else and no
8
+ * other column. A row erased already answers what it reads, `[erased]` or nothing. Every statement
9
+ * runs on the executor of the unit of work and, for tenant data, in the tenant of the work alone.
10
+ * The port of the context extends `PersonalDataExport` and its adapter extends this class:
11
+ * `class KnexPatientExport extends KnexPersonalDataExport implements PatientExport`.
12
+ */
13
+ export declare class KnexPersonalDataExport implements PersonalDataExport {
14
+ private readonly context;
15
+ private readonly options;
16
+ readonly name: string;
17
+ constructor(context: KnexContext, options: KnexPersonalDataExportOptions);
18
+ /** 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. */
19
+ exportOf(subject: string): Promise<readonly PersonalDataRecord[]>;
20
+ private recordsIn;
21
+ }
22
+ //# sourceMappingURL=knex-personal-data-export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-export.d.ts","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAC;AAKzF;;;;;;;;GAQG;AACH,qBAAa,sBAAuB,YAAW,kBAAkB;IAI7D,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YACmB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,6BAA6B,EAGxD;IAED,sKAAsK;IAChK,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,kBAAkB,EAAE,CAAC,CAYtE;YAEa,SAAS;CAUxB"}
@@ -0,0 +1,43 @@
1
+ import { NotADataSubjectIdError, isDataSubjectId, personalDataValueOf, } from '@ddd-ts-kit/kernel';
2
+ import { recordsOf } from './records-of.js';
3
+ import { rowsAbout } from './rows-about.js';
4
+ /**
5
+ * The export of what a context keeps of a data subject, on Knex: for every table declared with
6
+ * `personalFields`, one record per row about the subject, under `<name>.<table>`, holding each
7
+ * personal column and each file column (by its key) as plain data, nothing of anyone else and no
8
+ * other column. A row erased already answers what it reads, `[erased]` or nothing. Every statement
9
+ * runs on the executor of the unit of work and, for tenant data, in the tenant of the work alone.
10
+ * The port of the context extends `PersonalDataExport` and its adapter extends this class:
11
+ * `class KnexPatientExport extends KnexPersonalDataExport implements PatientExport`.
12
+ */
13
+ export class KnexPersonalDataExport {
14
+ context;
15
+ options;
16
+ name;
17
+ constructor(context, options) {
18
+ this.context = context;
19
+ this.options = options;
20
+ this.name = options.name;
21
+ }
22
+ /** 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. */
23
+ async exportOf(subject) {
24
+ if (!isDataSubjectId(subject)) {
25
+ throw new NotADataSubjectIdError();
26
+ }
27
+ const records = [];
28
+ for (const declaration of this.options.declarations) {
29
+ records.push(...(await this.recordsIn(declaration, subject)));
30
+ }
31
+ return records;
32
+ }
33
+ async recordsIn(declaration, subject) {
34
+ const columns = [...declaration.fields, ...declaration.files];
35
+ const rows = await rowsAbout(this.context, { declaration, subject }, this.options.tenant).select(columns);
36
+ const source = `${this.name}.${declaration.table.table}`;
37
+ return recordsOf(rows).map((row) => ({
38
+ source,
39
+ values: Object.fromEntries(columns.map((column) => [column, personalDataValueOf(row[column])])),
40
+ }));
41
+ }
42
+ }
43
+ //# sourceMappingURL=knex-personal-data-export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-data-export.js","sourceRoot":"","sources":["../../src/personal-data/knex-personal-data-export.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,mBAAmB,GAGpB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,OAAO,sBAAsB;IAId,OAAO;IACP,OAAO;IAJjB,IAAI,CAAS;IAEtB,YACmB,OAAoB,EACpB,OAAsC;uBADtC,OAAO;uBACP,OAAO;QAExB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,sKAAsK;IACtK,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,sBAAsB,EAAE,CAAC;QACrC,CAAC;QAED,MAAM,OAAO,GAAyB,EAAE,CAAC;QAEzC,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;YACpD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,SAAS,CAAC,WAA+B,EAAE,OAAe;QACtE,MAAM,OAAO,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAY,MAAM,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACnH,MAAM,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAEzD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACnC,MAAM;YACN,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SAChG,CAAC,CAAC,CAAC;IACN,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ import type { ErasureMode, RetentionPeriod } from '@ddd-ts-kit/kernel';
2
+ import type { TenantTableTarget } from '../tenancy/tenant-table-target.js';
3
+ /** A `personalFields` declaration on a Knex table, whatever its row type: the table named as `tenantTable` names it, the columns by their SQL names. */
4
+ export interface KnexPersonalFields {
5
+ readonly table: TenantTableTarget;
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=knex-personal-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-fields.d.ts","sourceRoot":"","sources":["../../src/personal-data/knex-personal-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAExE,wJAAwJ;AACxJ,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAClC,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=knex-personal-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knex-personal-fields.js","sourceRoot":"","sources":["../../src/personal-data/knex-personal-fields.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ /** The rows a statement answered, as records. */
2
+ export declare function recordsOf(answered: unknown): Readonly<Record<string, unknown>>[];
3
+ //# sourceMappingURL=records-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records-of.d.ts","sourceRoot":"","sources":["../../src/personal-data/records-of.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,CAIhF"}
@@ -0,0 +1,6 @@
1
+ /** The rows a statement answered, as records. */
2
+ export function recordsOf(answered) {
3
+ const rows = Array.isArray(answered) ? answered : [];
4
+ return rows.filter((row) => typeof row === 'object' && row !== null);
5
+ }
6
+ //# sourceMappingURL=records-of.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records-of.js","sourceRoot":"","sources":["../../src/personal-data/records-of.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,MAAM,UAAU,SAAS,CAAC,QAAiB;IACzC,MAAM,IAAI,GAAuB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAEzE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAA4C,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC;AACjH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Knex } from 'knex';
2
+ import { type ExecutionScope } from '@ddd-ts-kit/kernel';
3
+ import type { KnexContext } from '../unit-of-work/knex-context.js';
4
+ import type { KnexPersonalFields } from './knex-personal-fields.js';
5
+ /** The rows sought: the ones of one subject in one declared table. */
6
+ export interface About {
7
+ readonly declaration: KnexPersonalFields;
8
+ readonly subject: string;
9
+ }
10
+ /**
11
+ * The rows about the subject, in the tenant of the work when the table holds tenant data. A
12
+ * function and not a method: a query builder is thenable, and a method that answers one is read
13
+ * as asynchronous by what wraps the adapter once it is bound (tracing, the aspects), which then
14
+ * answers a promise in its place.
15
+ */
16
+ export declare function rowsAbout(context: KnexContext, { declaration, subject }: About, tenant: ExecutionScope | undefined): Knex.QueryBuilder;
17
+ //# sourceMappingURL=rows-about.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows-about.d.ts","sourceRoot":"","sources":["../../src/personal-data/rows-about.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,sEAAsE;AACtE,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,WAAW,EACpB,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,KAAK,EAC/B,MAAM,EAAE,cAAc,GAAG,SAAS,GACjC,IAAI,CAAC,YAAY,CAMnB"}
@@ -0,0 +1,16 @@
1
+ import { tenantScopeOf } from '@ddd-ts-kit/kernel';
2
+ import { tableIn } from '../tenancy/table-in.js';
3
+ import { TENANT_COLUMN } from '../tenancy/where-tenant.js';
4
+ /**
5
+ * The rows about the subject, in the tenant of the work when the table holds tenant data. A
6
+ * function and not a method: a query builder is thenable, and a method that answers one is read
7
+ * as asynchronous by what wraps the adapter once it is bound (tracing, the aspects), which then
8
+ * answers a promise in its place.
9
+ */
10
+ export function rowsAbout(context, { declaration, subject }, tenant) {
11
+ const rows = tableIn(context, declaration.table).where(declaration.subject, subject);
12
+ return tenant === undefined
13
+ ? rows
14
+ : rows.where(declaration.table.column ?? TENANT_COLUMN, tenantScopeOf(tenant).tenantId);
15
+ }
16
+ //# sourceMappingURL=rows-about.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows-about.js","sourceRoot":"","sources":["../../src/personal-data/rows-about.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAUxD;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,OAAoB,EACpB,EAAE,WAAW,EAAE,OAAO,EAAS,EAC/B,MAAkC;IAElC,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAErF,OAAO,MAAM,KAAK,SAAS;QACzB,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,IAAI,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;AAC5F,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Knex } from 'knex';
2
+ import { type ExecutionScope } from '@ddd-ts-kit/kernel';
3
+ import type { KnexContext } from '../unit-of-work/knex-context.js';
4
+ import type { KnexPersonalFields } from './knex-personal-fields.js';
5
+ /**
6
+ * The rows of a declared table whose retention ended before `now`: their date column is earlier
7
+ * than the end of the period, a row whose date is empty never expires. In the tenant of the work
8
+ * when it names one, in every tenant when it names none: a purge is a policy of the table, run by
9
+ * the platform, and a tenant left out of a list would keep what it should not. A function and not
10
+ * a method, as `rowsAbout`: a query builder is thenable.
11
+ */
12
+ export declare function rowsExpired(context: KnexContext, declaration: KnexPersonalFields, { now, tenant }: {
13
+ readonly now: Date;
14
+ readonly tenant: ExecutionScope | undefined;
15
+ }): Knex.QueryBuilder;
16
+ //# sourceMappingURL=rows-expired.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows-expired.d.ts","sourceRoot":"","sources":["../../src/personal-data/rows-expired.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,kBAAkB,EAC/B,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,CAAA;CAAE,GACnF,IAAI,CAAC,YAAY,CAWnB"}
@@ -0,0 +1,20 @@
1
+ import { expiredBefore } from '@ddd-ts-kit/kernel';
2
+ import { tableIn } from '../tenancy/table-in.js';
3
+ import { TENANT_COLUMN } from '../tenancy/where-tenant.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. A function and not
9
+ * a method, as `rowsAbout`: a query builder is thenable.
10
+ */
11
+ export function rowsExpired(context, declaration, { now, tenant }) {
12
+ const { retention } = declaration;
13
+ if (retention === undefined) {
14
+ throw new Error(`The declaration of ${declaration.table.table} gives no retention to purge by`);
15
+ }
16
+ const rows = tableIn(context, declaration.table).where(retention.after, '<', expiredBefore(retention, now));
17
+ const tenantId = tenant?.current()?.tenantId;
18
+ return tenantId === undefined ? rows : rows.where(declaration.table.column ?? TENANT_COLUMN, tenantId);
19
+ }
20
+ //# sourceMappingURL=rows-expired.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows-expired.js","sourceRoot":"","sources":["../../src/personal-data/rows-expired.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAIxD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,OAAoB,EACpB,WAA+B,EAC/B,EAAE,GAAG,EAAE,MAAM,EAAuE;IAEpF,MAAM,EAAE,SAAS,EAAE,GAAG,WAAW,CAAC;IAElC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,sBAAsB,WAAW,CAAC,KAAK,CAAC,KAAK,iCAAiC,CAAC,CAAC;IAClG,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;IAC5G,MAAM,QAAQ,GAAG,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC;IAE7C,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,IAAI,aAAa,EAAE,QAAQ,CAAC,CAAC;AACzG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts-kit/knex",
3
- "version": "0.88.0",
3
+ "version": "0.90.0",
4
4
  "description": "Knex adapters for the kernel ports: unit of work, transactional outbox store, processed-event store, PostgreSQL event store, background job store, process store.",
5
5
  "keywords": [
6
6
  "ddd",
@@ -38,16 +38,16 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "@ddd-ts-kit/kernel": "0.88.0",
42
- "@ddd-ts-kit/events": "0.88.0",
43
- "@ddd-ts-kit/scheduling": "0.88.0"
41
+ "@ddd-ts-kit/kernel": "0.90.0",
42
+ "@ddd-ts-kit/events": "0.90.0",
43
+ "@ddd-ts-kit/scheduling": "0.90.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "knex": "^3.0.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "knex": "^3.3.0",
50
- "@ddd-ts-kit/testing": "0.88.0",
50
+ "@ddd-ts-kit/testing": "0.90.0",
51
51
  "pg": "^8.23.1",
52
52
  "@types/pg": "^8.23.1",
53
53
  "@electric-sql/pglite": "0.5.10",