@proteinjs/db 1.34.3 → 1.35.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 (43) hide show
  1. package/CHANGELOG.md +22 -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/Db.d.ts +10 -0
  8. package/dist/src/Db.d.ts.map +1 -1
  9. package/dist/src/Db.js +42 -2
  10. package/dist/src/Db.js.map +1 -1
  11. package/dist/src/MigrationRunner.d.ts +26 -0
  12. package/dist/src/MigrationRunner.d.ts.map +1 -1
  13. package/dist/src/MigrationRunner.js +82 -0
  14. package/dist/src/MigrationRunner.js.map +1 -1
  15. package/dist/src/source/SourceRecord.d.ts +35 -2
  16. package/dist/src/source/SourceRecord.d.ts.map +1 -1
  17. package/dist/src/source/SourceRecord.js +8 -1
  18. package/dist/src/source/SourceRecord.js.map +1 -1
  19. package/dist/src/source/SourceRecordLoader.d.ts +105 -7
  20. package/dist/src/source/SourceRecordLoader.d.ts.map +1 -1
  21. package/dist/src/source/SourceRecordLoader.js +358 -94
  22. package/dist/src/source/SourceRecordLoader.js.map +1 -1
  23. package/dist/src/tables/MigrationTable.d.ts +26 -0
  24. package/dist/src/tables/MigrationTable.d.ts.map +1 -1
  25. package/dist/src/tables/MigrationTable.js +1 -0
  26. package/dist/src/tables/MigrationTable.js.map +1 -1
  27. package/dist/test/reusable/SourceRecordSyncTests.d.ts.map +1 -1
  28. package/dist/test/reusable/SourceRecordSyncTests.js +803 -27
  29. package/dist/test/reusable/SourceRecordSyncTests.js.map +1 -1
  30. package/dist/test/util/tables/sourceRecordSyncTestTables.d.ts +16 -0
  31. package/dist/test/util/tables/sourceRecordSyncTestTables.d.ts.map +1 -1
  32. package/dist/test/util/tables/sourceRecordSyncTestTables.js +23 -1
  33. package/dist/test/util/tables/sourceRecordSyncTestTables.js.map +1 -1
  34. package/generated/index.ts +1 -1
  35. package/generated/test/index.ts +3 -1
  36. package/package.json +4 -4
  37. package/src/Db.ts +19 -0
  38. package/src/MigrationRunner.ts +62 -0
  39. package/src/source/SourceRecord.ts +42 -4
  40. package/src/source/SourceRecordLoader.ts +342 -48
  41. package/src/tables/MigrationTable.ts +24 -0
  42. package/test/reusable/SourceRecordSyncTests.ts +462 -11
  43. package/test/util/tables/sourceRecordSyncTestTables.ts +20 -0
@@ -57,42 +57,103 @@ var Record_1 = require("../Record");
57
57
  var SourceRecordLoader = /** @class */ (function () {
58
58
  function SourceRecordLoader() {
59
59
  this.logger = new logger_1.Logger({ name: this.constructor.name });
60
+ /** Memo of resolved package versions — one resolution (and at most one warning) per source. */
61
+ this.sourceVersions = new Map();
60
62
  }
61
- SourceRecordLoader.prototype.load = function () {
63
+ /**
64
+ * One boot of the source-record sync, per source-record table in this build. Returns what it
65
+ * did to each table (also logged).
66
+ *
67
+ * Ownership model — every row has one owner, the package that declares it, ordered by that
68
+ * package's version:
69
+ * - A boot speaks only for the packages it carries. Rows owned by a package this build does
70
+ * not carry are never touched: several servers running different builds against one shared
71
+ * database coexist without pruning each other's rows.
72
+ * - Within a package, a boot speaks only for its own version or older. A row stamped by a
73
+ * NEWER version of the same package is left exactly as it is — neither pruned nor rewritten —
74
+ * so ordinary version skew (an older build restarting against rows a newer build added or
75
+ * redefined) cannot delete or churn data. The newest version stays authoritative for
76
+ * genuine removals and redefinitions.
77
+ * - A package in the build is authoritative for all of its rows on every table, including
78
+ * tables it no longer declares anything for: dropping the last declaration is a removal.
79
+ * - Rows with no owner stamp (written before `source_package` existed) are claimed by the
80
+ * declaration that still matches them; the rest are reported as unowned and left alone.
81
+ *
82
+ * Accepted residuals: a package removed from every build leaves its rows behind (no surviving
83
+ * boot carries its authority — clean up explicitly); two builds of one package at the SAME
84
+ * version with differing sets (uncommitted local skew) are last-writer-wins, since versions
85
+ * cannot order them.
86
+ *
87
+ * With no argument, every source-record table is synced (the `Db.init` full pass). Passing
88
+ * `onlyTable` scopes the sync to that one table — the pre-schema-sync migration phase uses
89
+ * this to land the migration ledger's rows before the full schema sync has run (see
90
+ * {@link MigrationRunner.runPreSchemaSyncMigrations}); the later full pass re-reconciles the
91
+ * same rows idempotently under the same ownership model.
92
+ */
93
+ SourceRecordLoader.prototype.load = function (onlyTable) {
62
94
  return __awaiter(this, void 0, void 0, function () {
63
- var sourceRecordsMap, db, _loop_1, this_1, _a, _b, _c, _i, tableName;
64
- return __generator(this, function (_d) {
65
- switch (_d.label) {
66
- case 0: return [4 /*yield*/, this.getSourceRecordsMap()];
95
+ var _a, tables, buildSources, db, summary, _loop_1, this_1, _b, _c, _d, _i, tableName;
96
+ return __generator(this, function (_e) {
97
+ switch (_e.label) {
98
+ case 0: return [4 /*yield*/, this.getDeclarations()];
67
99
  case 1:
68
- sourceRecordsMap = _d.sent();
100
+ _a = _e.sent(), tables = _a.tables, buildSources = _a.buildSources;
69
101
  db = (0, Db_1.getDbAsSystem)();
102
+ summary = {};
70
103
  _loop_1 = function (tableName) {
71
- var _e, table, records, keyProperty, declaredKeys, _f, deleteCount, removedUpdateCount, insertCount, updateCount, unchangedCount, adoptedCount, _g, records_1, sourceRecord, existingRecord, dbSourceRecord;
72
- var _h, _j;
73
- return __generator(this, function (_k) {
74
- switch (_k.label) {
104
+ var _f, table, records, keyProperty, allDeclaredKeys, removed, insertCount, updateCount, unchangedCount, adoptedCount, skippedNewer, _g, records_1, _h, source, record, sourceRecord, sourceVersion, existingRecord, dbSourceRecord, unowned;
105
+ var _j, _k;
106
+ return __generator(this, function (_l) {
107
+ switch (_l.label) {
75
108
  case 0:
76
- _e = sourceRecordsMap[tableName], table = _e.table, records = _e.records;
77
- keyProperty = this_1.validateSyncKey(table, records);
78
- declaredKeys = records.map(function (record) { return record[keyProperty]; });
79
- return [4 /*yield*/, this_1.reconcileRemoved(db, table, keyProperty, declaredKeys)];
109
+ if (onlyTable && tableName !== onlyTable.name) {
110
+ return [2 /*return*/, "continue"];
111
+ }
112
+ _f = tables[tableName], table = _f.table, records = _f.records;
113
+ keyProperty = this_1.validateSyncKey(table, records.map(function (_a) {
114
+ var record = _a.record;
115
+ return record;
116
+ }));
117
+ allDeclaredKeys = records.map(function (_a) {
118
+ var record = _a.record;
119
+ return record[keyProperty];
120
+ });
121
+ return [4 /*yield*/, this_1.reconcileRemoved(db, table, keyProperty, buildSources, allDeclaredKeys)];
80
122
  case 1:
81
- _f = _k.sent(), deleteCount = _f.deleteCount, removedUpdateCount = _f.removedUpdateCount;
123
+ removed = _l.sent();
82
124
  insertCount = 0;
83
125
  updateCount = 0;
84
126
  unchangedCount = 0;
85
127
  adoptedCount = 0;
128
+ skippedNewer = removed.skippedNewer;
86
129
  _g = 0, records_1 = records;
87
- _k.label = 2;
130
+ _l.label = 2;
88
131
  case 2:
89
132
  if (!(_g < records_1.length)) return [3 /*break*/, 12];
90
- sourceRecord = records_1[_g];
133
+ _h = records_1[_g], source = _h.source, record = _h.record;
134
+ sourceRecord = record;
91
135
  sourceRecord.isLoadedFromSource = true;
92
- return [4 /*yield*/, db.get(table, (_h = {}, _h[keyProperty] = sourceRecord[keyProperty], _h))];
136
+ // Ownership stamp: the declaring package (and its version) claims the row. Stamped
137
+ // before the drift comparison so pre-existing rows (including pre-source_package legacy
138
+ // rows and rows whose declaration moved packages) converge to the current owner on
139
+ // their next boot.
140
+ sourceRecord.sourcePackage = source;
141
+ sourceVersion = this_1.sourceVersion(source);
142
+ if (sourceVersion !== undefined) {
143
+ sourceRecord.sourcePackageVersion = sourceVersion;
144
+ }
145
+ return [4 /*yield*/, db.get(table, (_j = {}, _j[keyProperty] = sourceRecord[keyProperty], _j))];
93
146
  case 3:
94
- existingRecord = _k.sent();
147
+ existingRecord = _l.sent();
95
148
  if (!existingRecord) return [3 /*break*/, 8];
149
+ if (existingRecord.sourcePackage === source &&
150
+ this_1.isNewerStamp(existingRecord.sourcePackageVersion, sourceVersion)) {
151
+ // A newer version of this very package already defined the row: this build's older
152
+ // definition does not land, and the row's stamp is not downgraded.
153
+ skippedNewer += 1;
154
+ new SourceRecordRepo_1.SourceRecordRepo().loadSourceRecord(table.name, existingRecord);
155
+ return [3 /*break*/, 11];
156
+ }
96
157
  if (existingRecord.id !== sourceRecord.id) {
97
158
  // Adopt in place: the existing row keeps its id — other tables may reference it.
98
159
  // The declared id is only ever used for fresh inserts.
@@ -104,127 +165,192 @@ var SourceRecordLoader = /** @class */ (function () {
104
165
  adoptedCount += 1;
105
166
  this_1.logger.info({
106
167
  message: "(".concat(table.name, ") Adopting existing record into source ownership"),
107
- obj: (_j = {}, _j[keyProperty] = sourceRecord[keyProperty], _j.id = existingRecord.id, _j),
168
+ obj: (_k = {}, _k[keyProperty] = sourceRecord[keyProperty], _k.id = existingRecord.id, _k),
108
169
  });
109
170
  }
110
171
  return [4 /*yield*/, this_1.hasChanges(table, sourceRecord, existingRecord)];
111
172
  case 4:
112
- if (!_k.sent()) return [3 /*break*/, 6];
173
+ if (!_l.sent()) return [3 /*break*/, 6];
113
174
  return [4 /*yield*/, db.update(table, sourceRecord)];
114
175
  case 5:
115
- _k.sent();
176
+ _l.sent();
116
177
  updateCount += 1;
117
178
  return [3 /*break*/, 7];
118
179
  case 6:
119
180
  unchangedCount += 1;
120
- _k.label = 7;
181
+ _l.label = 7;
121
182
  case 7: return [3 /*break*/, 10];
122
183
  case 8: return [4 /*yield*/, db.insert(table, sourceRecord)];
123
184
  case 9:
124
- dbSourceRecord = _k.sent();
185
+ dbSourceRecord = _l.sent();
125
186
  sourceRecord = __assign(__assign({}, sourceRecord), dbSourceRecord);
126
187
  insertCount += 1;
127
- _k.label = 10;
188
+ _l.label = 10;
128
189
  case 10:
129
190
  // Registered under the DB id (= the adopted id when an existing row matched by natural key).
130
191
  new SourceRecordRepo_1.SourceRecordRepo().loadSourceRecord(table.name, sourceRecord);
131
- _k.label = 11;
192
+ _l.label = 11;
132
193
  case 11:
133
194
  _g++;
134
195
  return [3 /*break*/, 2];
135
- case 12:
196
+ case 12: return [4 /*yield*/, this_1.countUnowned(db, table, keyProperty)];
197
+ case 13:
198
+ unowned = _l.sent();
199
+ summary[table.name] = {
200
+ inserts: insertCount,
201
+ updates: updateCount,
202
+ unchanged: unchangedCount,
203
+ adopted: adoptedCount,
204
+ deletes: removed.deleteCount,
205
+ removedUpdates: removed.removedUpdateCount,
206
+ skippedNewer: skippedNewer,
207
+ unowned: unowned,
208
+ };
136
209
  this_1.logger.info({
137
210
  message: "(".concat(table.name, ") Loaded ").concat(records.length, " ").concat(records.length == 1 ? 'record' : 'records', " from source"),
138
- obj: {
139
- inserts: insertCount,
140
- updates: updateCount,
141
- unchanged: unchangedCount,
142
- adopted: adoptedCount,
143
- deletes: deleteCount,
144
- removedUpdates: removedUpdateCount,
145
- },
211
+ obj: summary[table.name],
146
212
  });
147
213
  return [2 /*return*/];
148
214
  }
149
215
  });
150
216
  };
151
217
  this_1 = this;
152
- _a = sourceRecordsMap;
153
- _b = [];
154
- for (_c in _a)
155
- _b.push(_c);
218
+ _b = tables;
219
+ _c = [];
220
+ for (_d in _b)
221
+ _c.push(_d);
156
222
  _i = 0;
157
- _d.label = 2;
223
+ _e.label = 2;
158
224
  case 2:
159
- if (!(_i < _b.length)) return [3 /*break*/, 5];
160
- _c = _b[_i];
161
- if (!(_c in _a)) return [3 /*break*/, 4];
162
- tableName = _c;
225
+ if (!(_i < _c.length)) return [3 /*break*/, 5];
226
+ _d = _c[_i];
227
+ if (!(_d in _b)) return [3 /*break*/, 4];
228
+ tableName = _d;
163
229
  return [5 /*yield**/, _loop_1(tableName)];
164
230
  case 3:
165
- _d.sent();
166
- _d.label = 4;
231
+ _e.sent();
232
+ _e.label = 4;
167
233
  case 4:
168
234
  _i++;
169
235
  return [3 /*break*/, 2];
170
- case 5: return [2 /*return*/];
236
+ case 5: return [2 /*return*/, summary];
171
237
  }
172
238
  });
173
239
  });
174
240
  };
175
241
  /**
176
- * The removed-reconcile leg: rows previously loaded from source whose declaration no longer
177
- * exists (`is_loaded_from_source = true AND <key> NOT IN declared`), handled per the table's
178
- * `onSourceRemoved` policy delete (default), keep, or update with a patch. The update leg
179
- * applies the patch only to rows whose fields actually differ (idempotent boots), through
180
- * `Db.update` so table watchers observe each write.
242
+ * The removed-reconcile leg: rows owned by a package this build carries, at that package's
243
+ * version or older, that NO package in this build still declares
244
+ * (`is_loaded_from_source = true AND source_package IN <build's packages> AND <key> NOT IN
245
+ * <build's declared keys for the table>`, minus rows stamped by a newer version of their
246
+ * package) are handled per the table's `onSourceRemoved` policy delete (default), keep, or
247
+ * update with a patch. The update leg applies the patch only to rows whose fields actually
248
+ * differ (idempotent boots), through `Db.update` so table watchers observe each write.
249
+ * See {@link load} for the ownership model.
181
250
  */
182
- SourceRecordLoader.prototype.reconcileRemoved = function (db, table, keyProperty, declaredKeys) {
251
+ SourceRecordLoader.prototype.reconcileRemoved = function (db, table, keyProperty, buildSources, allDeclaredKeys) {
183
252
  var _a;
184
253
  return __awaiter(this, void 0, void 0, function () {
185
- var policy, qb, removedUpdateCount, removedRecords, _i, removedRecords_1, removedRecord;
186
- var _b, _c;
187
- return __generator(this, function (_d) {
188
- switch (_d.label) {
254
+ var policy, qb, candidates, stampedNewer, removedRecords, skippedNewer, deleteQb, removedUpdateCount, _i, removedRecords_1, removedRecord;
255
+ var _b, _c, _d;
256
+ var _this = this;
257
+ return __generator(this, function (_e) {
258
+ switch (_e.label) {
189
259
  case 0:
190
260
  policy = (_a = table.sourceRecordOptions.onSourceRemoved) !== null && _a !== void 0 ? _a : 'delete';
191
- if (policy === 'keep') {
192
- return [2 /*return*/, { deleteCount: 0, removedUpdateCount: 0 }];
261
+ if (policy === 'keep' || buildSources.size == 0) {
262
+ return [2 /*return*/, { deleteCount: 0, removedUpdateCount: 0, skippedNewer: 0 }];
193
263
  }
194
264
  qb = db_query_1.QueryBuilder.fromObject({ isLoadedFromSource: true }, table.name);
195
- if (declaredKeys.length > 0) {
196
- qb.condition({ field: keyProperty, operator: 'NOT IN', value: declaredKeys });
265
+ qb.condition({ field: 'sourcePackage', operator: 'IN', value: Array.from(buildSources) });
266
+ if (allDeclaredKeys.length > 0) {
267
+ qb.condition({ field: keyProperty, operator: 'NOT IN', value: allDeclaredKeys });
197
268
  }
198
- if (!(policy === 'delete')) return [3 /*break*/, 2];
199
- _b = {};
200
- return [4 /*yield*/, db.delete(table, qb)];
201
- case 1: return [2 /*return*/, (_b.deleteCount = _d.sent(), _b.removedUpdateCount = 0, _b)];
202
- case 2:
203
- removedUpdateCount = 0;
204
269
  return [4 /*yield*/, db.query(table, qb)];
270
+ case 1:
271
+ candidates = _e.sent();
272
+ stampedNewer = function (candidate) {
273
+ return _this.isNewerStamp(candidate.sourcePackageVersion, _this.sourceVersion(candidate.sourcePackage));
274
+ };
275
+ removedRecords = candidates.filter(function (candidate) { return !stampedNewer(candidate); });
276
+ skippedNewer = candidates.length - removedRecords.length;
277
+ if (skippedNewer > 0) {
278
+ this.logger.info({
279
+ message: "(".concat(table.name, ") Left ").concat(skippedNewer, " record").concat(skippedNewer == 1 ? '' : 's', " stamped by a newer version of ").concat(skippedNewer == 1 ? 'its' : 'their', " package \u2014 not treated as removed"),
280
+ obj: (_b = {}, _b[keyProperty] = candidates.filter(stampedNewer).map(function (candidate) { return candidate[keyProperty]; }), _b),
281
+ });
282
+ }
283
+ if (removedRecords.length == 0) {
284
+ return [2 /*return*/, { deleteCount: 0, removedUpdateCount: 0, skippedNewer: skippedNewer }];
285
+ }
286
+ if (!(policy === 'delete')) return [3 /*break*/, 3];
287
+ deleteQb = db_query_1.QueryBuilder.fromObject({ isLoadedFromSource: true }, table.name);
288
+ deleteQb.condition({ field: 'id', operator: 'IN', value: removedRecords.map(function (record) { return record.id; }) });
289
+ _c = {};
290
+ return [4 /*yield*/, db.delete(table, deleteQb)];
291
+ case 2: return [2 /*return*/, (_c.deleteCount = _e.sent(), _c.removedUpdateCount = 0, _c.skippedNewer = skippedNewer, _c)];
205
292
  case 3:
206
- removedRecords = _d.sent();
293
+ removedUpdateCount = 0;
207
294
  _i = 0, removedRecords_1 = removedRecords;
208
- _d.label = 4;
295
+ _e.label = 4;
209
296
  case 4:
210
297
  if (!(_i < removedRecords_1.length)) return [3 /*break*/, 8];
211
298
  removedRecord = removedRecords_1[_i];
212
299
  return [4 /*yield*/, this.hasChanges(table, policy.update, removedRecord)];
213
300
  case 5:
214
- if (!_d.sent()) return [3 /*break*/, 7];
301
+ if (!_e.sent()) return [3 /*break*/, 7];
215
302
  return [4 /*yield*/, db.update(table, __assign({ id: removedRecord.id }, policy.update))];
216
303
  case 6:
217
- _d.sent();
304
+ _e.sent();
218
305
  removedUpdateCount += 1;
219
306
  this.logger.info({
220
307
  message: "(".concat(table.name, ") Applied onSourceRemoved update to record removed from source"),
221
- obj: (_c = { id: removedRecord.id }, _c[keyProperty] = removedRecord[keyProperty], _c),
308
+ obj: (_d = {
309
+ id: removedRecord.id
310
+ },
311
+ _d[keyProperty] = removedRecord[keyProperty],
312
+ _d.source = removedRecord.sourcePackage,
313
+ _d),
222
314
  });
223
- _d.label = 7;
315
+ _e.label = 7;
224
316
  case 7:
225
317
  _i++;
226
318
  return [3 /*break*/, 4];
227
- case 8: return [2 /*return*/, { deleteCount: 0, removedUpdateCount: removedUpdateCount }];
319
+ case 8: return [2 /*return*/, { deleteCount: 0, removedUpdateCount: removedUpdateCount, skippedNewer: skippedNewer }];
320
+ }
321
+ });
322
+ });
323
+ };
324
+ /**
325
+ * Source-loaded rows with no owner stamp that no declaration in this build claimed on this
326
+ * boot (the stamp leg has already run). They predate `source_package`, or their declaring
327
+ * package is not in this build; nobody prunes them. Reported so they are visible, never acted
328
+ * on. Tables that keep removed rows (`onSourceRemoved: 'keep'`) opted out of removal
329
+ * semantics altogether, so there is nothing to explain there.
330
+ */
331
+ SourceRecordLoader.prototype.countUnowned = function (db, table, keyProperty) {
332
+ var _a;
333
+ return __awaiter(this, void 0, void 0, function () {
334
+ var qb, unowned;
335
+ var _b;
336
+ return __generator(this, function (_c) {
337
+ switch (_c.label) {
338
+ case 0:
339
+ if (((_a = table.sourceRecordOptions.onSourceRemoved) !== null && _a !== void 0 ? _a : 'delete') === 'keep') {
340
+ return [2 /*return*/, 0];
341
+ }
342
+ qb = db_query_1.QueryBuilder.fromObject({ isLoadedFromSource: true }, table.name);
343
+ qb.condition({ field: 'sourcePackage', operator: 'IS NULL' });
344
+ return [4 /*yield*/, db.query(table, qb)];
345
+ case 1:
346
+ unowned = _c.sent();
347
+ if (unowned.length > 0) {
348
+ this.logger.warn({
349
+ message: "(".concat(table.name, ") ").concat(unowned.length, " source-loaded ").concat(unowned.length == 1 ? 'record has' : 'records have', " no owning package and no declaration in this build \u2014 left untouched"),
350
+ obj: (_b = {}, _b[keyProperty] = unowned.map(function (record) { return record[keyProperty]; }), _b),
351
+ });
352
+ }
353
+ return [2 /*return*/, unowned.length];
228
354
  }
229
355
  });
230
356
  });
@@ -307,30 +433,29 @@ var SourceRecordLoader = /** @class */ (function () {
307
433
  });
308
434
  });
309
435
  };
310
- SourceRecordLoader.prototype.getSourceRecordsMap = function () {
436
+ /**
437
+ * Every source-record table in this build with the records declared for it, plus the set of
438
+ * packages that declare ANY source record in this build — the packages this boot speaks for.
439
+ */
440
+ SourceRecordLoader.prototype.getDeclarations = function () {
311
441
  return __awaiter(this, void 0, void 0, function () {
312
- var sourceRecordsMap, sourceRecordTables, _i, sourceRecordTables_1, sourceRecordTable, sourceRecordLoaders, _a, sourceRecordLoaders_1, sourceRecordLoader;
313
- return __generator(this, function (_b) {
314
- sourceRecordsMap = {};
315
- sourceRecordTables = (0, SourceRecord_1.getSourceRecordTables)();
316
- for (_i = 0, sourceRecordTables_1 = sourceRecordTables; _i < sourceRecordTables_1.length; _i++) {
317
- sourceRecordTable = sourceRecordTables_1[_i];
318
- if (!sourceRecordsMap[sourceRecordTable.name]) {
319
- sourceRecordsMap[sourceRecordTable.name] = { table: sourceRecordTable, records: [] };
320
- }
442
+ var tables, _i, _a, table, buildSources, _b, _c, _d, source, loader;
443
+ return __generator(this, function (_e) {
444
+ tables = {};
445
+ for (_i = 0, _a = (0, SourceRecord_1.getSourceRecordTables)(); _i < _a.length; _i++) {
446
+ table = _a[_i];
447
+ tables[table.name] = { table: table, records: [] };
321
448
  }
322
- sourceRecordLoaders = (0, SourceRecord_1.getSourceRecordLoaders)();
323
- for (_a = 0, sourceRecordLoaders_1 = sourceRecordLoaders; _a < sourceRecordLoaders_1.length; _a++) {
324
- sourceRecordLoader = sourceRecordLoaders_1[_a];
325
- if (!sourceRecordsMap[sourceRecordLoader.table.name]) {
326
- sourceRecordsMap[sourceRecordLoader.table.name] = {
327
- table: sourceRecordLoader.table,
328
- records: [],
329
- };
449
+ buildSources = new Set();
450
+ for (_b = 0, _c = (0, SourceRecord_1.getSourceRecordLoaders)(); _b < _c.length; _b++) {
451
+ _d = _c[_b], source = _d.source, loader = _d.loader;
452
+ buildSources.add(source);
453
+ if (!tables[loader.table.name]) {
454
+ tables[loader.table.name] = { table: loader.table, records: [] };
330
455
  }
331
- sourceRecordsMap[sourceRecordLoader.table.name].records.push(sourceRecordLoader.record);
456
+ tables[loader.table.name].records.push({ source: source, record: loader.record });
332
457
  }
333
- return [2 /*return*/, sourceRecordsMap];
458
+ return [2 /*return*/, { tables: tables, buildSources: buildSources }];
334
459
  });
335
460
  });
336
461
  };
@@ -421,6 +546,145 @@ var SourceRecordLoader = /** @class */ (function () {
421
546
  .sort();
422
547
  return '{' + keys.map(function (k) { return JSON.stringify(k) + ':' + _this.canonicalStringify(obj[k]); }).join(',') + '}';
423
548
  };
549
+ /** Memoized {@link resolveSourceVersion} — one resolution (and at most one warning) per source. */
550
+ SourceRecordLoader.prototype.sourceVersion = function (source) {
551
+ if (!this.sourceVersions.has(source)) {
552
+ this.sourceVersions.set(source, this.resolveSourceVersion(source));
553
+ }
554
+ return this.sourceVersions.get(source);
555
+ };
556
+ /**
557
+ * The declaring package's version, read from its own package.json at runtime. Resolution runs
558
+ * from the process cwd — the booting server's package, the one dependency tree every declaring
559
+ * package is reachable from (`@proteinjs/db` itself does not depend on the packages that
560
+ * declare records, so module-relative resolution could never find them). The package's entry
561
+ * is resolved (honoring exports maps, where `<pkg>/package.json` is usually not requireable),
562
+ * then the nearest package.json whose `name` matches is read walking up from it.
563
+ *
564
+ * Returns undefined where resolution is impossible — no Node `require` (browser bundles), or a
565
+ * package not resolvable from cwd. The sync then has no place in the version order for that
566
+ * package: it never touches its version-stamped rows, and what it writes is unversioned
567
+ * (see {@link isNewerStamp}). Logged once per boot so a misconfigured cwd is visible.
568
+ */
569
+ SourceRecordLoader.prototype.resolveSourceVersion = function (source) {
570
+ // The ambient CJS `require` — the only require carrying `.resolve` (module.require does
571
+ // not). Every use below goes through the variable, so bundlers never see a statically
572
+ // analyzable `require(...)` call; in a browser bundle the runtime attempts throw into
573
+ // their catches and the method degrades to undefined.
574
+ var nodeRequire = typeof require === 'function' && typeof require.resolve === 'function' ? require : undefined;
575
+ var cwd = typeof process !== 'undefined' && typeof process.cwd === 'function' ? process.cwd() : undefined;
576
+ if (nodeRequire && cwd) {
577
+ try {
578
+ var entryPath = nodeRequire.resolve(source, { paths: [cwd] });
579
+ var path = nodeRequire('path');
580
+ var fs = nodeRequire('fs');
581
+ // Walk up from the entry file to the package's own package.json (the name check skips
582
+ // nested stubs like a dist/package.json); stop at the filesystem root.
583
+ for (var directory = path.dirname(entryPath);; directory = path.dirname(directory)) {
584
+ var candidate = path.join(directory, 'package.json');
585
+ if (fs.existsSync(candidate)) {
586
+ var packageJson = JSON.parse(fs.readFileSync(candidate, 'utf8'));
587
+ if ((packageJson === null || packageJson === void 0 ? void 0 : packageJson.name) === source && typeof packageJson.version === 'string') {
588
+ return packageJson.version;
589
+ }
590
+ }
591
+ if (path.dirname(directory) === directory) {
592
+ break;
593
+ }
594
+ }
595
+ }
596
+ catch (error) {
597
+ // Unresolvable from cwd — reported below.
598
+ }
599
+ }
600
+ this.logger.warn({
601
+ message: "Could not resolve a version for source package '".concat(source, "' from '").concat(cwd, "' \u2014 its records sync without version ordering (this build never touches its version-stamped rows)"),
602
+ });
603
+ return undefined;
604
+ };
605
+ /**
606
+ * Whether a row's version stamp is strictly newer than the reconciling build's version of the
607
+ * same package — the guard that makes version skew of one package safe on a shared database:
608
+ * an older build never prunes (or flags) rows a newer build of the same package declared.
609
+ *
610
+ * Unversioned stamps (NULL — legacy rows, or builds whose version could not be resolved)
611
+ * carry no ordering and stay reconcilable (last-writer-wins, the pre-version behavior). A
612
+ * build whose OWN version is unresolvable cannot place itself in the order, so it never
613
+ * touches a version-stamped row — conservative: prefer leaving a removed row behind over
614
+ * deleting one that might be newer.
615
+ */
616
+ SourceRecordLoader.prototype.isNewerStamp = function (stampedVersion, reconcilingVersion) {
617
+ if (stampedVersion == null) {
618
+ return false;
619
+ }
620
+ if (reconcilingVersion == null) {
621
+ return true;
622
+ }
623
+ var comparison = this.compareVersions(stampedVersion, reconcilingVersion);
624
+ return comparison === undefined ? true : comparison > 0;
625
+ };
626
+ /**
627
+ * Semver comparison (major.minor.patch, prerelease-aware): negative when a < b, 0 when equal,
628
+ * positive when a > b, and undefined when either side does not parse as semver (unorderable —
629
+ * the caller treats that conservatively).
630
+ */
631
+ SourceRecordLoader.prototype.compareVersions = function (a, b) {
632
+ var parse = function (version) {
633
+ var _a;
634
+ var match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?/.exec(version.trim());
635
+ if (!match) {
636
+ return undefined;
637
+ }
638
+ return { main: [Number(match[1]), Number(match[2]), Number(match[3])], prerelease: (_a = match[4]) === null || _a === void 0 ? void 0 : _a.split('.') };
639
+ };
640
+ var parsedA = parse(a);
641
+ var parsedB = parse(b);
642
+ if (!parsedA || !parsedB) {
643
+ return undefined;
644
+ }
645
+ for (var i = 0; i < 3; i++) {
646
+ if (parsedA.main[i] !== parsedB.main[i]) {
647
+ return parsedA.main[i] - parsedB.main[i];
648
+ }
649
+ }
650
+ if (!parsedA.prerelease && !parsedB.prerelease) {
651
+ return 0;
652
+ }
653
+ if (!parsedA.prerelease) {
654
+ return 1; // a release outranks any prerelease of the same triple
655
+ }
656
+ if (!parsedB.prerelease) {
657
+ return -1;
658
+ }
659
+ var length = Math.max(parsedA.prerelease.length, parsedB.prerelease.length);
660
+ for (var i = 0; i < length; i++) {
661
+ var identifierA = parsedA.prerelease[i];
662
+ var identifierB = parsedB.prerelease[i];
663
+ if (identifierA === undefined) {
664
+ return -1; // fewer identifiers sorts first when all shared ones are equal
665
+ }
666
+ if (identifierB === undefined) {
667
+ return 1;
668
+ }
669
+ var numericA = /^\d+$/.test(identifierA) ? Number(identifierA) : undefined;
670
+ var numericB = /^\d+$/.test(identifierB) ? Number(identifierB) : undefined;
671
+ if (numericA !== undefined && numericB !== undefined) {
672
+ if (numericA !== numericB) {
673
+ return numericA - numericB;
674
+ }
675
+ }
676
+ else if (numericA !== undefined) {
677
+ return -1; // numeric identifiers sort before alphanumeric ones
678
+ }
679
+ else if (numericB !== undefined) {
680
+ return 1;
681
+ }
682
+ else if (identifierA !== identifierB) {
683
+ return identifierA < identifierB ? -1 : 1;
684
+ }
685
+ }
686
+ return 0;
687
+ };
424
688
  return SourceRecordLoader;
425
689
  }());
426
690
  exports.SourceRecordLoader = SourceRecordLoader;
@@ -1 +1 @@
1
- {"version":3,"file":"SourceRecordLoader.js","sourceRoot":"","sources":["../../../src/source/SourceRecordLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAC3C,gDAAmD;AACnD,+CAA6F;AAE7F,4BAA0C;AAC1C,uDAAsD;AACtD,oCAA6C;AAM7C;IAAA;QACU,WAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAwT/D,CAAC;IAtTO,iCAAI,GAAV;;;;;4BAC2B,qBAAM,IA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