meadow-integration 1.0.15 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meadow-integration",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Meadow Data Integration",
5
5
  "bin": {
6
6
  "mdwint": "source/cli/Meadow-Integration-CLI-Run.js"
@@ -372,6 +372,10 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
372
372
  {
373
373
  this.log.error(`Fallback update also failed for ${this.EntitySchema.TableName} ID ${pServerRecord[this.DefaultIdentifier]}: ${pUpdateError}`);
374
374
  }
375
+ else
376
+ {
377
+ this._recordsUpdated++;
378
+ }
375
379
  return fCallback();
376
380
  });
377
381
  return;
@@ -379,6 +383,10 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
379
383
  this.log.error(`Error creating record ${this.EntitySchema.TableName}: ${pCreateError}`, pCreateError);
380
384
  return fCallback();
381
385
  }
386
+ else
387
+ {
388
+ this._recordsCreated++;
389
+ }
382
390
  return fCallback();
383
391
  });
384
392
  }
@@ -392,6 +400,10 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
392
400
  {
393
401
  this.log.error(`Error updating record ${this.EntitySchema.TableName}: ${pUpdateError}`, pUpdateError);
394
402
  }
403
+ else
404
+ {
405
+ this._recordsUpdated++;
406
+ }
395
407
  return fCallback();
396
408
  });
397
409
  }
@@ -407,12 +419,22 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
407
419
  return fCallback(null, 0);
408
420
  }
409
421
 
422
+ // Check the global cap before starting -- if we have already synced
423
+ // MaxRecordsPerEntity records across all stages, stop immediately.
424
+ if (this.MaxRecordsPerEntity > 0 && this._totalSyncedThisSync >= this.MaxRecordsPerEntity)
425
+ {
426
+ this.fable.log.info(`${this.EntitySchema.TableName}: global record cap reached (${this._totalSyncedThisSync}/${this.MaxRecordsPerEntity}); skipping pull.`);
427
+ return fCallback(null, 0);
428
+ }
429
+
410
430
  let tmpSyncedCount = 0;
411
431
  let tmpOffset = 0;
412
432
  let tmpDone = false;
413
433
 
434
+ // Apply per-call cap based on estimated count, then further limit by
435
+ // how many records remain before hitting the global MaxRecordsPerEntity.
414
436
  let tmpRecordCap = (this.MaxRecordsPerEntity > 0)
415
- ? Math.min(pEstimatedCount, this.MaxRecordsPerEntity)
437
+ ? Math.min(pEstimatedCount, this.MaxRecordsPerEntity - this._totalSyncedThisSync)
416
438
  : pEstimatedCount;
417
439
 
418
440
  const fFetchPage = () =>
@@ -443,6 +465,7 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
443
465
  () =>
444
466
  {
445
467
  tmpSyncedCount++;
468
+ this._totalSyncedThisSync++;
446
469
  // Use setImmediate to yield the event loop and prevent
447
470
  // stack overflow when SQLite callbacks complete synchronously
448
471
  return setImmediate(fRecordDone);
@@ -485,6 +508,12 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
485
508
  // the range from the server to bring local in sync.
486
509
  _bisectRange(pMinID, pMaxID, pDepth, fCallback)
487
510
  {
511
+ // If the global record cap has been reached, stop bisecting
512
+ if (this.MaxRecordsPerEntity > 0 && this._totalSyncedThisSync >= this.MaxRecordsPerEntity)
513
+ {
514
+ return fCallback();
515
+ }
516
+
488
517
  const tmpRangeSize = pMaxID - pMinID + 1;
489
518
  const tmpIDCol = this.DefaultIdentifier;
490
519
  const tmpRangeFilter = `FBV~${tmpIDCol}~GE~${pMinID}~FBV~${tmpIDCol}~LE~${pMaxID}`;
@@ -768,7 +797,7 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
768
797
  {
769
798
  if (pReadError)
770
799
  {
771
- let tmpErrorStr = (typeof(pReadError) === 'string') ? pReadError : JSON.stringify(pReadError);
800
+ let tmpErrorStr = (typeof(pReadError) === 'string') ? pReadError : String(pReadError);
772
801
  if (tmpErrorStr.indexOf('Invalid column') > -1 || tmpErrorStr.indexOf('Invalid object') > -1 || tmpErrorStr.indexOf('no such column') > -1 || tmpErrorStr.indexOf('no such table') > -1)
773
802
  {
774
803
  this.log.warn(`${this.EntitySchema.TableName}: local table schema mismatch (${pReadError}); skipping sync.`);
@@ -783,6 +812,13 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
783
812
  {
784
813
  this.operation.createTimeStamp('EntityOngoingSync');
785
814
 
815
+ // Track total records synced across all stages to enforce MaxRecordsPerEntity globally
816
+ this._totalSyncedThisSync = 0;
817
+
818
+ // Track per-record create vs update counts for the sync report
819
+ this._recordsCreated = 0;
820
+ this._recordsUpdated = 0;
821
+
786
822
  const tmpSyncState = (
787
823
  {
788
824
  Local: { MaxIDEntity: -1, RecordCount: 0 },
@@ -941,7 +977,10 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
941
977
  // Create a progress tracker so callers (e.g. data-cloner UI) can see Total/Synced
942
978
  (fStageComplete) =>
943
979
  {
944
- this.operation.createProgressTracker(tmpSyncState.Server.RecordCount, `FullSync-${this.EntitySchema.TableName}`);
980
+ let tmpTrackerTotal = (this.MaxRecordsPerEntity > 0)
981
+ ? Math.min(tmpSyncState.Server.RecordCount, this.MaxRecordsPerEntity)
982
+ : tmpSyncState.Server.RecordCount;
983
+ this.operation.createProgressTracker(tmpTrackerTotal, `FullSync-${this.EntitySchema.TableName}`);
945
984
  return fStageComplete();
946
985
  },
947
986
 
@@ -1126,6 +1165,15 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
1126
1165
 
1127
1166
  this.fable.log.info(`${this.EntitySchema.TableName}: ongoing sync complete.`);
1128
1167
 
1168
+ // Store sync results so callers can inspect the breakdown
1169
+ this.syncResults = {
1170
+ Created: this._recordsCreated,
1171
+ Updated: this._recordsUpdated,
1172
+ Deleted: 0,
1173
+ ServerRecordCount: tmpSyncState.Server.RecordCount,
1174
+ LocalRecordCount: tmpSyncState.Local.RecordCount
1175
+ };
1176
+
1129
1177
  if (this.SyncDeletedRecords)
1130
1178
  {
1131
1179
  return this.syncDeletedRecords(() => { return fCallback(); });