diff --git a/packages/cli/lib/services/dryrun.service.ts b/packages/cli/lib/services/dryrun.service.ts index 8d126453df..efa86f03e7 100644 --- a/packages/cli/lib/services/dryrun.service.ts +++ b/packages/cli/lib/services/dryrun.service.ts @@ -143,7 +143,10 @@ class DryRunService { stubbedMetadata = rawStubbedMetadata; } - const logMessages: string[] = []; + const logMessages = { + counts: { updated: 0, added: 0, deleted: 0 }, + messages: [] + }; const syncRun = new syncRunService({ integrationService, @@ -171,8 +174,8 @@ class DryRunService { console.log(JSON.stringify(results, null, 2)); } - if (syncRun.logMessages && syncRun.logMessages.length > 0) { - const logMessages = syncRun.logMessages; + if (syncRun.logMessages && syncRun.logMessages.messages.length > 0) { + const logMessages = syncRun.logMessages.messages; let index = 0; const batchCount = 10; @@ -183,12 +186,13 @@ class DryRunService { } }; + console.log(chalk.yellow(`The dry run would produce the following results: ${JSON.stringify(syncRun.logMessages.counts, null, 2)}`)); console.log(chalk.yellow('The following log messages were generated:')); displayBatch(); - while (index < syncRun.logMessages.length) { - const remaining = syncRun.logMessages.length - index; + while (index < syncRun.logMessages.messages.length) { + const remaining = syncRun.logMessages.messages.length - index; const confirmation = await promptly.confirm( `There are ${remaining} logs messages remaining. Would you like to see the next 10 log messages? (y/n)` ); diff --git a/packages/runner/lib/client.unit.test.ts b/packages/runner/lib/client.unit.test.ts index 6155b33b79..b052d48ad3 100644 --- a/packages/runner/lib/client.unit.test.ts +++ b/packages/runner/lib/client.unit.test.ts @@ -32,7 +32,11 @@ describe('Runner client', () => { dryRun: true, attributes: {}, track_deletes: false, - logMessages: [], + logMessages: { + counts: { updated: 0, added: 0, deleted: 0 }, + messages: [] + }, + stubbedMetadata: {} }; const jsCode = ` diff --git a/packages/shared/lib/sdk/sync.ts b/packages/shared/lib/sdk/sync.ts index 2750dfde48..4ee341787f 100644 --- a/packages/shared/lib/sdk/sync.ts +++ b/packages/shared/lib/sdk/sync.ts @@ -233,7 +233,7 @@ export interface NangoProps { dryRun?: boolean; track_deletes?: boolean; attributes?: object | undefined; - logMessages?: unknown[] | undefined; + logMessages?: { counts: { updated: number; added: number; deleted: number }; messages: unknown[] } | undefined; stubbedMetadata?: Metadata | undefined; abortSignal?: AbortSignal; } @@ -627,7 +627,10 @@ export class NangoAction { export class NangoSync extends NangoAction { lastSyncDate?: Date; track_deletes = false; - logMessages?: unknown[] | undefined = []; + logMessages?: { counts: { updated: number; added: number; deleted: number }; messages: unknown[] } | undefined = { + counts: { updated: 0, added: 0, deleted: 0 }, + messages: [] + }; stubbedMetadata?: Metadata | undefined = undefined; private batchSize = 1000; @@ -682,8 +685,11 @@ export class NangoSync extends NangoAction { } if (this.dryRun) { - this.logMessages?.push(`A batch save call would save the following data to the ${model} model:`); - this.logMessages?.push(...results); + this.logMessages?.messages.push(`A batch save call would save the following data to the ${model} model:`); + this.logMessages?.messages.push(...results); + if (this.logMessages && this.logMessages.counts) { + this.logMessages.counts.added = Number(this.logMessages?.counts.added) + results.length; + } return null; } @@ -727,8 +733,11 @@ export class NangoSync extends NangoAction { } if (this.dryRun) { - this.logMessages?.push(`A batch delete call would delete the following data:`); - this.logMessages?.push(...results); + this.logMessages?.messages.push(`A batch delete call would delete the following data:`); + this.logMessages?.messages.push(...results); + if (this.logMessages && this.logMessages.counts) { + this.logMessages.counts.deleted = Number(this.logMessages?.counts.deleted) + results.length; + } return null; } @@ -772,8 +781,11 @@ export class NangoSync extends NangoAction { } if (this.dryRun) { - this.logMessages?.push(`A batch update call would update the following data to the ${model} model:`); - this.logMessages?.push(...results); + this.logMessages?.messages.push(`A batch update call would update the following data to the ${model} model:`); + this.logMessages?.messages.push(...results); + if (this.logMessages && this.logMessages.counts) { + this.logMessages.counts.updated = Number(this.logMessages?.counts.updated) + results.length; + } return null; } diff --git a/packages/shared/lib/services/sync/run.service.ts b/packages/shared/lib/services/sync/run.service.ts index 6c15f173ae..8f9930ce21 100644 --- a/packages/shared/lib/services/sync/run.service.ts +++ b/packages/shared/lib/services/sync/run.service.ts @@ -42,7 +42,7 @@ interface SyncRunConfig { debug?: boolean; input?: object; - logMessages?: unknown[] | undefined; + logMessages?: { counts: { updated: number; added: number; deleted: number }; messages: unknown[] } | undefined; stubbedMetadata?: Metadata | undefined; temporalContext?: Context; @@ -65,7 +65,10 @@ export default class SyncRun { debug?: boolean; input?: object; - logMessages?: unknown[] | undefined = []; + logMessages?: { counts: { updated: number; added: number; deleted: number }; messages: unknown[] } | undefined = { + counts: { updated: 0, added: 0, deleted: 0 }, + messages: [] + }; stubbedMetadata?: Metadata | undefined = undefined; temporalContext?: Context; diff --git a/packages/webapp/src/utils/utils.tsx b/packages/webapp/src/utils/utils.tsx index d7afdc9aa7..00b363da5e 100644 --- a/packages/webapp/src/utils/utils.tsx +++ b/packages/webapp/src/utils/utils.tsx @@ -275,26 +275,7 @@ export function createExampleForType(type: string): any { return {}; } - const rawType = type.replace('|', '').replace('null', '').replace('undefined', '').trim(); - - switch (rawType) { - case 'string': - return ''; - case 'integer': - return ''; - case 'boolean': - return ''; - case 'number': - return ''; - case 'object': - return ''; - case 'array': - return ''; - case 'date': - return ''; - default: - return ''; - } + return `<${type}>`; } export function generateExampleValueForProperty(model: NangoSyncModel): Record {