-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The custom processors will allow customers to append extra information to the listing or transform listing information to better match their expected result
- Loading branch information
1 parent
50b3fde
commit 22ef590
Showing
6 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import fs from 'fs'; | ||
const path = '.'; | ||
|
||
const registeredProcessors = await Promise.all( | ||
fs | ||
.readdirSync('./lib/processors') | ||
.filter((file) => file.endsWith('.js') && file !== 'process.js') | ||
.map(async (integPath) => await import(`${path}/${integPath}`)) | ||
); | ||
|
||
const findProcessor = (processor) => { | ||
return registeredProcessors.find((a) => a.config.id === processor.id); | ||
}; | ||
export function processListings(listings, listingProcessors) { | ||
const processors = listingProcessors.map(findProcessor); | ||
const processedListingsPromises = listings.map(async (listing) => { | ||
return processors.reduce( | ||
async (listingAcc, processor) => await processor.processListing({ listing: await listingAcc }), | ||
listing | ||
); | ||
}); | ||
return Promise.resolve(Promise.all(processedListingsPromises)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export async function processListing({ listing }) { | ||
return { ...listing, processed: true }; | ||
} | ||
export const config = { | ||
id: 'static', | ||
name: 'Static', | ||
description: 'This processor adds an extra `processed: true` property to the listing', | ||
config: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters