Skip to content

Commit

Permalink
Revert "Made assigning an id to documents more resilient (#1525)"
Browse files Browse the repository at this point in the history
This reverts commit 4a9d5de.
  • Loading branch information
alonp99 committed Nov 2, 2023
1 parent 1024d21 commit 00a08ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ export type TDocuments = DefaultContextSchema['documents'];

export const assignIdToDocuments = (documents: TDocuments): TDocuments =>
documents?.map(document => {
const documentWithId = {
return {
...document,
id: document.id || randomUUID(),
id: document.id ?? randomUUID(),
};

if (!documentWithId?.id) {
console.error('Failed to assign an ID to a document\n', documentWithId);
}

return documentWithId;
});
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('#Workflow Runtime Repository Integration Tests', () => {
id: '1',
name: 'TestEntity',
},
documents: [{ id: 'file1' }, { id: 'file2' }],
documents: ['file1', 'file2'],
},
},
},
Expand All @@ -140,7 +140,7 @@ describe('#Workflow Runtime Repository Integration Tests', () => {
id: '2',
name: 'UpdatedEntity',
},
documents: [{ id: 'file3' }],
documents: ['file3'],
};

const res = await workflowRuntimeRepository.updateById(
Expand All @@ -159,7 +159,7 @@ describe('#Workflow Runtime Repository Integration Tests', () => {
id: '2',
name: 'UpdatedEntity',
},
documents: [{ id: 'file3' }],
documents: ['file3'],
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ export class WorkflowRuntimeDataRepository {
{
where: { id },
...args,
data: {
...args.data,
context: {
...((args.data?.context ?? {}) as any),
documents: assignIdToDocuments((args.data?.context as any)?.documents),
},
} as any,
},
projectId,
),
Expand All @@ -101,10 +94,7 @@ export class WorkflowRuntimeDataRepository {
arrayMergeOption: ArrayMergeOption = 'by_id',
projectIds: TProjectIds,
): Promise<WorkflowRuntimeData> {
const stringifiedContext = JSON.stringify({
...newContext,
documents: assignIdToDocuments(newContext?.documents),
});
const stringifiedContext = JSON.stringify(newContext);
const affectedRows = await this.prisma
.$executeRaw`UPDATE "WorkflowRuntimeData" SET "context" = jsonb_deep_merge_with_options("context", ${stringifiedContext}::jsonb, ${arrayMergeOption}) WHERE "id" = ${id} AND "projectId" in (${projectIds?.join(
',',
Expand Down

0 comments on commit 00a08ba

Please sign in to comment.