@proteinjs/db 1.34.3 → 1.34.4

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 (30) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/generated/index.js +1 -1
  3. package/dist/generated/index.js.map +1 -1
  4. package/dist/generated/test/index.d.ts.map +1 -1
  5. package/dist/generated/test/index.js +3 -1
  6. package/dist/generated/test/index.js.map +1 -1
  7. package/dist/src/source/SourceRecord.d.ts +35 -2
  8. package/dist/src/source/SourceRecord.d.ts.map +1 -1
  9. package/dist/src/source/SourceRecord.js +8 -1
  10. package/dist/src/source/SourceRecord.js.map +1 -1
  11. package/dist/src/source/SourceRecordLoader.d.ts +98 -7
  12. package/dist/src/source/SourceRecordLoader.d.ts.map +1 -1
  13. package/dist/src/source/SourceRecordLoader.js +348 -93
  14. package/dist/src/source/SourceRecordLoader.js.map +1 -1
  15. package/dist/src/tables/MigrationTable.d.ts +2 -0
  16. package/dist/src/tables/MigrationTable.d.ts.map +1 -1
  17. package/dist/test/reusable/SourceRecordSyncTests.d.ts.map +1 -1
  18. package/dist/test/reusable/SourceRecordSyncTests.js +803 -27
  19. package/dist/test/reusable/SourceRecordSyncTests.js.map +1 -1
  20. package/dist/test/util/tables/sourceRecordSyncTestTables.d.ts +16 -0
  21. package/dist/test/util/tables/sourceRecordSyncTestTables.d.ts.map +1 -1
  22. package/dist/test/util/tables/sourceRecordSyncTestTables.js +23 -1
  23. package/dist/test/util/tables/sourceRecordSyncTestTables.js.map +1 -1
  24. package/generated/index.ts +1 -1
  25. package/generated/test/index.ts +3 -1
  26. package/package.json +4 -4
  27. package/src/source/SourceRecord.ts +42 -4
  28. package/src/source/SourceRecordLoader.ts +333 -48
  29. package/test/reusable/SourceRecordSyncTests.ts +462 -11
  30. package/test/util/tables/sourceRecordSyncTestTables.ts +20 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../generated/test/index.ts"],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B,EAAE,uCAAY;IAC1C,yBAAyB,EAAE,iCAAS;IACpC,iCAAiC,EAAE,kCAAiB;IACpD,qCAAqC,EAAE,sCAAqB;IAC5D,sCAAsC,EAAE,yDAAsB;IAC9D,6BAA6B,EAAE,gDAAa;IAC5C,6BAA6B,EAAE,gDAAa;IAC5C,mCAAmC,EAAE,sDAAmB;IACxD,uCAAuC,EAAE,kDAAuB;IAChE,uCAAuC,EAAE,oDAAuB;IAChE,sCAAsC,EAAE,mDAAsB;IAC9D,kCAAkC,EAAE,+CAAkB;IACtD,6CAA6C,EAAE,0DAA6B;IAC5E,mCAAmC,EAAE,gDAAmB;IACxD,6BAA6B,EAAE,sCAAa;IAC5C,oCAAoC,EAAE,6CAAoB;IAC1D,gCAAgC,EAAE,yCAAgB;IAClD,4CAA4C,EAAE,oDAA4B;IAC1E,gDAAgD,EAAE,wDAAgC;IAClF,kBAAkB,EAAE,OAAE;IACtB,iCAAiC,EAAE,qCAAiB;IACpD,+BAA+B,EAAE,iCAAe;IAChD,yBAAyB,EAAE,qBAAS;IACpC,8BAA8B,EAAE,+BAAc;IAC9C,wCAAwC,EAAE,mDAAwB;IAClE,mCAAmC,EAAE,yCAAmB;IACxD,+BAA+B,EAAE,iCAAe;IAChD,kCAAkC,EAAE,uCAAkB;IACtD,8BAA8B,EAAE,+BAAc;IAC9C,iCAAiC,EAAE,qCAAiB;CACpD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,mDAAiC"}
@@ -1,11 +1,40 @@
1
1
  import { Loadable } from '@proteinjs/reflection';
2
2
  import { Columns, Table } from '../Table';
3
3
  import { Record as DbRecord } from '../Record';
4
- export declare const getSourceRecordLoaders: <T extends SourceRecord = SourceRecord>() => SourceRecordLoader<T>[];
4
+ /**
5
+ * A source record declaration paired with its owning source: the package that compiled the
6
+ * declaration into this build (from the declaration's reflection qualified name). The source is
7
+ * the ownership grain of the sync — {@link SourceRecordLoader} stamps it on every row it writes
8
+ * and prunes only within it, so servers running different builds against one shared database
9
+ * never delete each other's rows.
10
+ */
11
+ export type SourceRecordLoaderDeclaration<T extends SourceRecord = SourceRecord> = {
12
+ source: string;
13
+ loader: SourceRecordLoader<T>;
14
+ };
15
+ export declare const getSourceRecordLoaders: <T extends SourceRecord = SourceRecord>() => SourceRecordLoaderDeclaration<T>[];
5
16
  export declare function getSourceRecordTables(): Table<any>[];
6
17
  export declare function isSourceRecordTable(table: Table<any>): boolean;
7
18
  export interface SourceRecord extends DbRecord {
8
19
  isLoadedFromSource?: boolean;
20
+ /**
21
+ * The package whose declaration owns this row (the declaring loader's package, from its
22
+ * reflection qualified name). Stamped by {@link SourceRecordLoader} on every row it writes;
23
+ * the removed-reconcile prunes only rows whose `sourcePackage` matches a package the running
24
+ * build actually declares from — so a build never deletes rows owned by a package it does not
25
+ * carry (e.g. another server's types on a shared database). Rows written before this column
26
+ * existed carry NULL until their owning package's next boot adopts and stamps them.
27
+ */
28
+ sourcePackage?: string;
29
+ /**
30
+ * The declaring package's version at the time this row was last stamped (from the package's
31
+ * own package.json, resolved at runtime). This is the ordering WITHIN a package that makes
32
+ * version skew safe on a shared database: a boot never prunes, flags, or rewrites a row stamped
33
+ * by a strictly NEWER version of the same package, so an older build cannot delete the types a
34
+ * newer build added or churn the ones it redefined. NULL (legacy rows, or builds whose package
35
+ * version could not be resolved) carries no ordering and keeps the last-writer-wins semantics.
36
+ */
37
+ sourcePackageVersion?: string;
9
38
  }
10
39
  /**
11
40
  * Wrapper function to add default Record and SourceRecord columns to your table's columns.
@@ -30,7 +59,11 @@ type OptionalProperties<T> = Pick<T, {
30
59
  *
31
60
  * On Db.init, the record will be inserted if it doesn't exist, and updated if it does exist to mirror what is in source.
32
61
  *
33
- * If the SourceRecordLoader is deleted from source, the record will be deleted from the db on server startup. This will also be the behavior if id is changed - the record with the old id will be deleted.
62
+ * If the SourceRecordLoader is deleted from source, the record will be deleted from the db on server startup (per the
63
+ * table's `onSourceRemoved` policy) — by the next boot of a build that still carries the declaring package at its
64
+ * version or newer. Ownership is per package: a boot only reconciles rows owned by packages it carries, and never
65
+ * rows a newer version of the same package stamped; a package removed from every build leaves its rows behind.
66
+ * This will also be the behavior if id is changed - the record with the old id will be deleted.
34
67
  */
35
68
  export interface SourceRecordLoader<T extends SourceRecord> extends Loadable {
36
69
  table: Table<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"SourceRecord.d.ts","sourceRoot":"","sources":["../../../src/source/SourceRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAa,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAqB,MAAM,WAAW,CAAC;AAGlE,eAAO,MAAM,sBAAsB,sEACwD,CAAC;AAE5F,wBAAgB,qBAAqB,iBAUpC;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,WASpD;AAED,MAAM,WAAW,YAAa,SAAQ,QAAQ;IAC5C,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAQD;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,YAAY,EAC5D,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,EAC7C,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,CAK9D;AAED,KAAK,oBAAoB,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACpE,KAAK,4BAA4B,CAAC,CAAC,IAAI,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,SAA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C,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CACtD,CAAC,MAAM,CAAC,CAAC,CACX,CAAC;AACF,KAAK,kBAAkB,CAAC,CAAC,IAAI,IAAI,CAC/B,CAAC,EACD;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;CACtD,CAAC,MAAM,CAAC,CAAC,CACX,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,YAAY,CAAE,SAAQ,QAAQ;IAC1E,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAChB,MAAM,EAAE;SACL,CAAC,IAAI,MAAM,kBAAkB,CAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,kBAAkB,CACzF,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACvC,CAAC,CAAC,CAAC;KACL,GAAG;SACD,CAAC,IAAI,MAAM,kBAAkB,CAAC,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAC1F,4BAA4B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACvC,CAAC,CAAC,CAAC;KACL,CAAC;CACH"}
@@ -6,7 +6,12 @@ var Table_1 = require("../Table");
6
6
  var Record_1 = require("../Record");
7
7
  var Columns_1 = require("../Columns");
8
8
  var getSourceRecordLoaders = function () {
9
- return reflection_1.SourceRepository.get().objects('@proteinjs/db/SourceRecordLoader');
9
+ return reflection_1.SourceRepository.get()
10
+ .objectsWithNames('@proteinjs/db/SourceRecordLoader')
11
+ .map(function (_a) {
12
+ var packageName = _a.packageName, object = _a.object;
13
+ return ({ source: packageName, loader: object });
14
+ });
10
15
  };
11
16
  exports.getSourceRecordLoaders = getSourceRecordLoaders;
12
17
  function getSourceRecordTables() {
@@ -35,6 +40,8 @@ var getSourceRecordColumns = function (hideFromUi) {
35
40
  if (hideFromUi === void 0) { hideFromUi = true; }
36
41
  return {
37
42
  isLoadedFromSource: new Columns_1.BooleanColumn('is_loaded_from_source', { ui: { hidden: hideFromUi } }),
43
+ sourcePackage: new Columns_1.StringColumn('source_package', { ui: { hidden: hideFromUi } }),
44
+ sourcePackageVersion: new Columns_1.StringColumn('source_package_version', { ui: { hidden: hideFromUi } }),
38
45
  };
39
46
  };
40
47
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"SourceRecord.js","sourceRoot":"","sources":["../../../src/source/SourceRecord.ts"],"names":[],"mappings":";;;AAAA,oDAAmE;AACnE,kCAAqD;AACrD,oCAAkE;AAClE,sCAA2C;AAEpC,IAAM,sBAAsB,GAAG;IACpC,OAAA,6BAAgB,CAAC,GAAG,EAAE,CAAC,OAAO,CAAwB,kCAAkC,CAAC;AAAzF,CAAyF,CAAC;AAD/E,QAAA,sBAAsB,0BACyD;AAE5F,SAAgB,qBAAqB;IACnC,IAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,IAAM,kBAAkB,GAAiB,EAAE,CAAC;IAC5C,KAAoB,UAAM,EAAN,iBAAM,EAAN,oBAAM,EAAN,IAAM,EAAE;QAAvB,IAAM,KAAK,eAAA;QACd,IAAI,mBAAmB,CAAC,KAAK,CAAC,EAAE;YAC9B,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SAChC;KACF;IAED,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAVD,sDAUC;AAED,SAAgB,mBAAmB,CAAC,KAAiB;IACnD,KAAK,IAAM,kBAAkB,IAAI,KAAK,CAAC,OAAO,EAAE;QAC9C,IAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACjD,IAAI,MAAM,CAAC,IAAI,IAAI,sBAAsB,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE;YACnE,OAAO,IA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= {
3
+ inserts: number;
4
+ updates: number;
5
+ unchanged: number;
6
+ adopted: number;
7
+ deletes: number;
8
+ removedUpdates: number;
9
+ /** Rows stamped by a newer version of their declaring package — left exactly as they are. */
10
+ skippedNewer: number;
11
+ /** Source-loaded rows with no owner stamp that no declaration in this build claims. */
12
+ unowned: number;
13
+ };
14
+ export type SourceRecordLoadSummary = {
15
+ [tableName: string]: SourceRecordTableLoadSummary;
16
+ };
1
17
  export declare class SourceRecordLoader {
2
18
  private logger;
3
- load(): Promise<void>;
19
+ /** Memo of resolved package versions — one resolution (and at most one warning) per source. */
20
+ private sourceVersions;
4
21
  /**
5
- * The removed-reconcile leg: rows previously loaded from source whose declaration no longer
6
- * exists (`is_loaded_from_source = true AND <key> NOT IN declared`), handled per the table's
7
- * `onSourceRemoved` policy — delete (default), keep, or update with a patch. The update leg
8
- * applies the patch only to rows whose fields actually differ (idempotent boots), through
9
- * `Db.update` so table watchers observe each write.
22
+ * One boot of the source-record sync, per source-record table in this build. Returns what it
23
+ * did to each table (also logged).
24
+ *
25
+ * Ownership model every row has one owner, the package that declares it, ordered by that
26
+ * package's version:
27
+ * - A boot speaks only for the packages it carries. Rows owned by a package this build does
28
+ * not carry are never touched: several servers running different builds against one shared
29
+ * database coexist without pruning each other's rows.
30
+ * - Within a package, a boot speaks only for its own version or older. A row stamped by a
31
+ * NEWER version of the same package is left exactly as it is — neither pruned nor rewritten —
32
+ * so ordinary version skew (an older build restarting against rows a newer build added or
33
+ * redefined) cannot delete or churn data. The newest version stays authoritative for
34
+ * genuine removals and redefinitions.
35
+ * - A package in the build is authoritative for all of its rows on every table, including
36
+ * tables it no longer declares anything for: dropping the last declaration is a removal.
37
+ * - Rows with no owner stamp (written before `source_package` existed) are claimed by the
38
+ * declaration that still matches them; the rest are reported as unowned and left alone.
39
+ *
40
+ * Accepted residuals: a package removed from every build leaves its rows behind (no surviving
41
+ * boot carries its authority — clean up explicitly); two builds of one package at the SAME
42
+ * version with differing sets (uncommitted local skew) are last-writer-wins, since versions
43
+ * cannot order them.
44
+ */
45
+ load(): Promise<SourceRecordLoadSummary>;
46
+ /**
47
+ * The removed-reconcile leg: rows owned by a package this build carries, at that package's
48
+ * version or older, that NO package in this build still declares
49
+ * (`is_loaded_from_source = true AND source_package IN <build's packages> AND <key> NOT IN
50
+ * <build's declared keys for the table>`, minus rows stamped by a newer version of their
51
+ * package) are handled per the table's `onSourceRemoved` policy — delete (default), keep, or
52
+ * update with a patch. The update leg applies the patch only to rows whose fields actually
53
+ * differ (idempotent boots), through `Db.update` so table watchers observe each write.
54
+ * See {@link load} for the ownership model.
10
55
  */
11
56
  private reconcileRemoved;
57
+ /**
58
+ * Source-loaded rows with no owner stamp that no declaration in this build claimed on this
59
+ * boot (the stamp leg has already run). They predate `source_package`, or their declaring
60
+ * package is not in this build; nobody prunes them. Reported so they are visible, never acted
61
+ * on. Tables that keep removed rows (`onSourceRemoved: 'keep'`) opted out of removal
62
+ * semantics altogether, so there is nothing to explain there.
63
+ */
64
+ private countUnowned;
12
65
  /**
13
66
  * Resolve and validate the property the sync keys on: `id` unless the table declares
14
67
  * `sourceRecordOptions.naturalKey`. A natural key must be schema-unique (a `ColumnOptions.unique`
@@ -29,7 +82,11 @@ export declare class SourceRecordLoader {
29
82
  * triggers a rewrite. Primitive columns retain their existing semantics.
30
83
  */
31
84
  private hasChanges;
32
- private getSourceRecordsMap;
85
+ /**
86
+ * Every source-record table in this build with the records declared for it, plus the set of
87
+ * packages that declare ANY source record in this build — the packages this boot speaks for.
88
+ */
89
+ private getDeclarations;
33
90
  /**
34
91
  * Find the first point of divergence between source and existing values.
35
92
  * Returns a description of the mismatch path, or null if they match.
@@ -58,5 +115,39 @@ export declare class SourceRecordLoader {
58
115
  * are sorted.
59
116
  */
60
117
  private canonicalStringify;
118
+ /** Memoized {@link resolveSourceVersion} — one resolution (and at most one warning) per source. */
119
+ private sourceVersion;
120
+ /**
121
+ * The declaring package's version, read from its own package.json at runtime. Resolution runs
122
+ * from the process cwd — the booting server's package, the one dependency tree every declaring
123
+ * package is reachable from (`@proteinjs/db` itself does not depend on the packages that
124
+ * declare records, so module-relative resolution could never find them). The package's entry
125
+ * is resolved (honoring exports maps, where `<pkg>/package.json` is usually not requireable),
126
+ * then the nearest package.json whose `name` matches is read walking up from it.
127
+ *
128
+ * Returns undefined where resolution is impossible — no Node `require` (browser bundles), or a
129
+ * package not resolvable from cwd. The sync then has no place in the version order for that
130
+ * package: it never touches its version-stamped rows, and what it writes is unversioned
131
+ * (see {@link isNewerStamp}). Logged once per boot so a misconfigured cwd is visible.
132
+ */
133
+ private resolveSourceVersion;
134
+ /**
135
+ * Whether a row's version stamp is strictly newer than the reconciling build's version of the
136
+ * same package — the guard that makes version skew of one package safe on a shared database:
137
+ * an older build never prunes (or flags) rows a newer build of the same package declared.
138
+ *
139
+ * Unversioned stamps (NULL — legacy rows, or builds whose version could not be resolved)
140
+ * carry no ordering and stay reconcilable (last-writer-wins, the pre-version behavior). A
141
+ * build whose OWN version is unresolvable cannot place itself in the order, so it never
142
+ * touches a version-stamped row — conservative: prefer leaving a removed row behind over
143
+ * deleting one that might be newer.
144
+ */
145
+ private isNewerStamp;
146
+ /**
147
+ * Semver comparison (major.minor.patch, prerelease-aware): negative when a < b, 0 when equal,
148
+ * positive when a > b, and undefined when either side does not parse as semver (unorderable —
149
+ * the caller treats that conservatively).
150
+ */
151
+ private compareVersions;
61
152
  }
62
153
  //# sourceMappingURL=SourceRecordLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SourceRecordLoader.d.ts","sourceRoot":"","sources":["../../../src/source/SourceRecordLoader.ts"],"names":[],"mappings":"AAYA,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAA+C;IAEvD,IAAI;IAiEV;;;;;;OAMG;YACW,gBAAgB;IAoC9B;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IA+CvB;;;;;;;;;;;OAWG;YACW,UAAU;YAmBV,mBAAmB;IAwBjC;;;;;;;;;;;;OA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