Skip to content

Commit

Permalink
[nan-621] output # of records (NangoHQ#1895)
Browse files Browse the repository at this point in the history
## Describe your changes
Ouput a summary of records that would be added, updated, or deleted by
the integration script

## Issue ticket number and link
NAN-621

## Checklist before requesting a review (skip if just adding/editing
APIs & templates)
- [ ] I added tests, otherwise the reason is: 
- [ ] I added observability, otherwise the reason is:
- [ ] I added analytics, otherwise the reason is:
  • Loading branch information
khaliqgant authored Mar 22, 2024
1 parent a2389d0 commit 8f78686
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
14 changes: 9 additions & 5 deletions packages/cli/lib/services/dryrun.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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)`
);
Expand Down
6 changes: 5 additions & 1 deletion packages/runner/lib/client.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down
28 changes: 20 additions & 8 deletions packages/shared/lib/sdk/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 5 additions & 2 deletions packages/shared/lib/services/sync/run.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
21 changes: 1 addition & 20 deletions packages/webapp/src/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<string>';
case 'integer':
return '<number>';
case 'boolean':
return '<boolean>';
case 'number':
return '<number>';
case 'object':
return '<object>';
case 'array':
return '<array>';
case 'date':
return '<date>';
default:
return '';
}
return `<${type}>`;
}

export function generateExampleValueForProperty(model: NangoSyncModel): Record<string, boolean | string | number> {
Expand Down

0 comments on commit 8f78686

Please sign in to comment.