Skip to content

Commit

Permalink
Refactor route deduplication logic
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak committed Mar 2, 2024
1 parent bb3a88c commit 3728dfb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const attrDifference = (x: any[], y: any[], property: string) => {
return x.filter((j) => !y.some((k) => j[property] == k[property]));
};

const unique = (xs: any[], property: string = 'id'): any[] => {
const unique = (xs: any[], property = 'id'): any[] => {
return Object.values(xs.reduce((acc, obj) => ({ ...acc, [obj[property]]: obj })));
}

Expand Down Expand Up @@ -94,8 +94,8 @@ async function deploy(
const publishRoutes = [...routeData, ...configRoutes];
const allRoutes = unique((await listWorkerRoutes(token, accountId)).flat());
const currentRoutes = unique(allRoutes.filter((r) => r.script == name));
const addRoutes = unique(attrDifference(publishRoutes, currentRoutes, 'pattern'));
const delRoutes = unique(attrDifference(currentRoutes, publishRoutes, 'pattern'));
const addRoutes = attrDifference(publishRoutes, currentRoutes, 'pattern');
const delRoutes = attrDifference(currentRoutes, publishRoutes, 'pattern');
debug(`Account routes: ${JSON.stringify(allRoutes)}`);
debug(`Worker routes current: ${JSON.stringify(currentRoutes)}`);
debug(`Worker routes requested: ${JSON.stringify(publishRoutes)}`);
Expand Down

0 comments on commit 3728dfb

Please sign in to comment.