meadow-integration 1.0.10 → 1.0.12

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.10",
3
+ "version": "1.0.12",
4
4
  "description": "Meadow Data Integration",
5
5
  "bin": {
6
6
  "mdwint": "source/cli/Meadow-Integration-CLI-Run.js"
@@ -45,6 +45,8 @@ class MeadowSyncEntityInitial extends libFableServiceProviderBase
45
45
  this.Meadow = false;
46
46
 
47
47
  this.operation = new libMeadowOperation(this.fable);
48
+
49
+ this.skipSync = false;
48
50
  }
49
51
 
50
52
  initialize(fCallback)
@@ -72,6 +74,7 @@ class MeadowSyncEntityInitial extends libFableServiceProviderBase
72
74
 
73
75
  return tmpProvider.createTable(this.EntitySchema, (pCreateError) =>
74
76
  {
77
+
75
78
  if (pCreateError)
76
79
  {
77
80
  this.log.warn(`${this.EntitySchema.TableName}: createTable returned error: ${pCreateError}`);
@@ -115,7 +118,7 @@ class MeadowSyncEntityInitial extends libFableServiceProviderBase
115
118
  {
116
119
  this.log.warn(`${this.EntitySchema.TableName}: Index creation error: ${pIndexError}`);
117
120
  }
118
- return fCallback(pIndexError || pCreateError);
121
+ return fValidateAndCallback(pIndexError || pCreateError);
119
122
  });
120
123
  });
121
124
  }
@@ -300,6 +303,35 @@ class MeadowSyncEntityInitial extends libFableServiceProviderBase
300
303
  }
301
304
 
302
305
  sync(fCallback)
306
+ {
307
+ if (this.skipSync)
308
+ {
309
+ this.log.warn(`Skipping sync for ${this.EntitySchema.TableName} -- local table schema does not match expected schema.`);
310
+ return fCallback();
311
+ }
312
+
313
+ // Validate local table schema with a lightweight read before syncing
314
+ const tmpValidationQuery = this.Meadow.query;
315
+ tmpValidationQuery.setSort({ Column: this.DefaultIdentifier, Direction: 'Descending' });
316
+ tmpValidationQuery.setCap(1);
317
+ tmpValidationQuery.setDisableDeleteTracking(true);
318
+ this.Meadow.doRead(tmpValidationQuery,
319
+ (pReadError) =>
320
+ {
321
+ if (pReadError)
322
+ {
323
+ let tmpErrorStr = (typeof(pReadError) === 'string') ? pReadError : JSON.stringify(pReadError);
324
+ if (tmpErrorStr.indexOf('Invalid column') > -1 || tmpErrorStr.indexOf('Invalid object') > -1 || tmpErrorStr.indexOf('no such column') > -1 || tmpErrorStr.indexOf('no such table') > -1)
325
+ {
326
+ this.log.warn(`${this.EntitySchema.TableName}: local table schema mismatch (${pReadError}); skipping sync.`);
327
+ return fCallback();
328
+ }
329
+ }
330
+ return this._syncInternal(fCallback);
331
+ });
332
+ }
333
+
334
+ _syncInternal(fCallback)
303
335
  {
304
336
  this.operation.createTimeStamp('EntityInitialSync');
305
337
 
@@ -377,7 +409,8 @@ class MeadowSyncEntityInitial extends libFableServiceProviderBase
377
409
  {
378
410
  if (pError)
379
411
  {
380
- return fStageComplete(`Error getting server max entity ID ${this.EntitySchema.TableName}: ${pError}`);
412
+ this.fable.log.warn(`Could not get server max entity ID for ${this.EntitySchema.TableName} (${pError}); continuing sync.`);
413
+ return fStageComplete();
381
414
  }
382
415
  if (pBody && pBody.hasOwnProperty(this.DefaultIdentifier))
383
416
  {
@@ -394,7 +427,9 @@ class MeadowSyncEntityInitial extends libFableServiceProviderBase
394
427
  {
395
428
  if (pError)
396
429
  {
397
- return fStageComplete(`Error getting server count for ${this.EntitySchema.TableName}: ${pError}`);
430
+ this.fable.log.warn(`Could not get server count for ${this.EntitySchema.TableName} (${pError}); estimating from max ID.`);
431
+ tmpSyncState.Server.RecordCount = tmpSyncState.Server.MaxIDEntity > 0 ? tmpSyncState.Server.MaxIDEntity : 0;
432
+ return fStageComplete();
398
433
  }
399
434
  if (pBody && pBody.hasOwnProperty('Count'))
400
435
  {
@@ -451,7 +486,7 @@ class MeadowSyncEntityInitial extends libFableServiceProviderBase
451
486
  this.fable.log.error(`${this.EntitySchema.TableName}: page ${tmpPageIndex} download error: ${pDownloadError}`);
452
487
  return fDownloadComplete();
453
488
  }
454
- if (pBody && pBody.length > 0)
489
+ if (pBody && Array.isArray(pBody) && pBody.length > 0)
455
490
  {
456
491
  this.fable.Utility.eachLimit(pBody, 5,
457
492
  (pEntityRecord, fEntitySyncComplete) =>
@@ -45,6 +45,8 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
45
45
  this.Meadow = false;
46
46
 
47
47
  this.operation = new libMeadowOperation(this.fable);
48
+
49
+ this.skipSync = false;
48
50
  }
49
51
 
50
52
  initialize(fCallback)
@@ -60,6 +62,7 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
60
62
  {
61
63
  return this.Meadow.provider.getProvider().createTable(this.EntitySchema, (pCreateError) =>
62
64
  {
65
+
63
66
  const tmpGUIDColumn = this.EntitySchema.Columns.find((c) => c.DataType == 'GUID');
64
67
  const tmpDeletedColumn = this.EntitySchema.Columns.find((c) => c.Column == 'Deleted');
65
68
 
@@ -92,7 +95,7 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
92
95
  return this.fable.MeadowConnectionManager.createIndex(this.EntitySchema, tmpDeletedColumn, false, fNext);
93
96
  });
94
97
  }
95
- tmpAnticipate.wait(fCallback);
98
+ tmpAnticipate.wait((pIndexError) => { return fCallback(pCreateError); });
96
99
  });
97
100
  }
98
101
  return fCallback();
@@ -288,7 +291,7 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
288
291
  this.fable.log.error(`Error getting URL Partial [${tmpURLPartial}]: ${pDownloadError}`, { Error: pDownloadError });
289
292
  return fNext();
290
293
  }
291
- if (pBody && pBody.length > 0)
294
+ if (pBody && Array.isArray(pBody) && pBody.length > 0)
292
295
  {
293
296
  for (let i = 0; i < pBody.length; i++)
294
297
  {
@@ -419,6 +422,35 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
419
422
  }
420
423
 
421
424
  sync(fCallback)
425
+ {
426
+ if (this.skipSync)
427
+ {
428
+ this.log.warn(`Skipping sync for ${this.EntitySchema.TableName} -- local table schema does not match expected schema.`);
429
+ return fCallback();
430
+ }
431
+
432
+ // Validate local table schema with a lightweight read before syncing
433
+ const tmpValidationQuery = this.Meadow.query;
434
+ tmpValidationQuery.setSort({ Column: this.DefaultIdentifier, Direction: 'Descending' });
435
+ tmpValidationQuery.setCap(1);
436
+ tmpValidationQuery.setDisableDeleteTracking(true);
437
+ this.Meadow.doRead(tmpValidationQuery,
438
+ (pReadError) =>
439
+ {
440
+ if (pReadError)
441
+ {
442
+ let tmpErrorStr = (typeof(pReadError) === 'string') ? pReadError : JSON.stringify(pReadError);
443
+ if (tmpErrorStr.indexOf('Invalid column') > -1 || tmpErrorStr.indexOf('Invalid object') > -1 || tmpErrorStr.indexOf('no such column') > -1 || tmpErrorStr.indexOf('no such table') > -1)
444
+ {
445
+ this.log.warn(`${this.EntitySchema.TableName}: local table schema mismatch (${pReadError}); skipping sync.`);
446
+ return fCallback();
447
+ }
448
+ }
449
+ return this._syncInternal(fCallback);
450
+ });
451
+ }
452
+
453
+ _syncInternal(fCallback)
422
454
  {
423
455
  this.operation.createTimeStamp('EntityOngoingSync');
424
456
 
@@ -551,8 +583,8 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
551
583
  {
552
584
  if (pError)
553
585
  {
554
- this.fable.log.error(`Error getting server max entity ID ${this.EntitySchema.TableName}: ${pError}`, { Error: pError });
555
- return fStageComplete(`Error getting server max entity ID ${this.EntitySchema.TableName}: ${pError}`);
586
+ this.fable.log.warn(`Could not get server max entity ID for ${this.EntitySchema.TableName} (${pError}); continuing sync.`);
587
+ return fStageComplete();
556
588
  }
557
589
  if (pBody && pBody.hasOwnProperty(this.DefaultIdentifier))
558
590
  {
@@ -574,8 +606,8 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
574
606
  {
575
607
  if (pError)
576
608
  {
577
- this.fable.log.error(`Error getting server max UpdateDate ${this.EntitySchema.TableName}: ${pError}`, { Error: pError });
578
- return fStageComplete(`Error getting server max UpdateDate ${this.EntitySchema.TableName}: ${pError}`);
609
+ this.fable.log.warn(`Could not get server max UpdateDate for ${this.EntitySchema.TableName} (${pError}); will sync by ID only.`);
610
+ return fStageComplete();
579
611
  }
580
612
  if (pBody && pBody.hasOwnProperty(this.DefaultIdentifier))
581
613
  {
@@ -597,8 +629,9 @@ class MeadowSyncEntityOngoing extends libFableServiceProviderBase
597
629
  {
598
630
  if (pError)
599
631
  {
600
- this.fable.log.error(`Error getting server count for ${this.EntitySchema.TableName}: ${pError}`, { Error: pError });
601
- return fStageComplete(`Error getting server count for ${this.EntitySchema.TableName}: ${pError}`);
632
+ this.fable.log.warn(`Could not get server count for ${this.EntitySchema.TableName} (${pError}); estimating from max ID.`);
633
+ tmpSyncState.Server.RecordCount = tmpSyncState.Server.MaxIDEntity > 0 ? tmpSyncState.Server.MaxIDEntity : 0;
634
+ return fStageComplete();
602
635
  }
603
636
  if (pBody && pBody.hasOwnProperty('Count'))
604
637
  {
@@ -87,7 +87,7 @@ class MeadowSync extends libFableServiceProviderBase
87
87
  let tmpErrorCount = 0;
88
88
  let tmpSuccessCount = 0;
89
89
 
90
- this.fable.Utility.eachLimit(this.MeadowSchemaTableList, 1,
90
+ this.fable.Utility.eachLimit(this.MeadowSchemaTableList, 5,
91
91
  (pEntitySchemaName, fSyncInitializationComplete) =>
92
92
  {
93
93
  tmpEntityIndex++;