Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/integration-sdk-core/src/types/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Entity } from './entity';
import { GraphObjectFilter, GraphObjectIteratee } from './jobState';
import {
GraphObjectFilter,
GraphObjectIteratee,
GraphObjectIterateeOptions,
} from './jobState';
import { Relationship } from './relationship';
import { GraphObjectIndexMetadata } from '../types/step';

Expand Down Expand Up @@ -33,11 +37,13 @@ export interface GraphObjectStore {
iterateEntities<T extends Entity = Entity>(
filter: GraphObjectFilter,
iteratee: GraphObjectIteratee<T>,
options?: GraphObjectIterateeOptions,
): Promise<void>;

iterateRelationships<T extends Relationship = Relationship>(
filter: GraphObjectFilter,
iteratee: GraphObjectIteratee<T>,
options?: GraphObjectIterateeOptions,
): Promise<void>;

flush(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function createDuplicateEntityReport({
payload,
indexOfDuplicateKey,
graphObjectStore,
}: DuplicateKeyReportParams): Promise<DuplicateEntityReport> {
}: DuplicateKeyReportParams): Promise<DuplicateEntityReport | {}> {
const originalEntityFromPayload = getOriginalEntityFromPayload(
payload,
duplicateEntity._key,
Expand All @@ -83,10 +83,7 @@ export async function createDuplicateEntityReport({
} else {
const originalEntityFromGraphObjectStore =
await graphObjectStore.findEntity(duplicateEntity._key);
return compareEntities(
originalEntityFromGraphObjectStore!,
duplicateEntity,
);
return compareEntities(originalEntityFromGraphObjectStore, duplicateEntity);
}
}

Expand Down Expand Up @@ -130,8 +127,8 @@ function isDeepStrictEqual(a: any, b: any): boolean {

export type DuplicateEntityReport = {
_key: string;
rawDataMatch: boolean;
entityPropertiesMatch: boolean;
rawDataMatch?: boolean;
entityPropertiesMatch?: boolean;
rawDataDiff?: string;
entityPropertiesDiff?: string;
diffErrors?: { rawData?: string; entityProperties?: string };
Expand Down Expand Up @@ -233,7 +230,16 @@ export function diffObjects(
* @param b
* @returns
*/
function compareEntities(a: Entity, b: Entity): DuplicateEntityReport {
function compareEntities(
a: Entity | undefined,
b: Entity,
): DuplicateEntityReport {
if (a === undefined) {
return {
_key: b._key,
};
}

const aClone = JSON.parse(JSON.stringify(a));
const bClone = JSON.parse(JSON.stringify(b));
delete aClone._rawData;
Expand Down
12 changes: 7 additions & 5 deletions packages/integration-sdk-runtime/src/execution/jobState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export function createStepJobState({
indexOfDuplicateKey: index,
graphObjectStore,
});
onDuplicateEntityKey(duplicateEntityReport);
if ('_key' in duplicateEntityReport) {
onDuplicateEntityKey(duplicateEntityReport);
}
throw err;
}

Expand Down Expand Up @@ -274,11 +276,11 @@ export function createStepJobState({
return duplicateKeyTracker.hasKey(_key);
},

iterateEntities: (filter, iteratee) =>
graphObjectStore.iterateEntities(filter, iteratee),
iterateEntities: (filter, iteratee, options) =>
graphObjectStore.iterateEntities(filter, iteratee, options),

iterateRelationships: (filter, iteratee) =>
graphObjectStore.iterateRelationships(filter, iteratee),
iterateRelationships: (filter, iteratee, options) =>
graphObjectStore.iterateRelationships(filter, iteratee, options),

flush: () =>
graphObjectStore.flush(
Expand Down