export async function announceNewRecipe()

in lib/recipes-data/src/lib/eventbus.ts [16:55]


export async function announceNewRecipe(
	updated: RecipeReference[],
	removedList: RecipeIndexEntry[],
	OutgoingEventBus: string,
) {
	const updates = updated.map((recep) => ({
		Time: new Date(), //Timestamp
		Source: 'recipe-responder', //Identity of sender
		Resources: [], //Affected AWS resources
		DetailType: 'recipe-update', //What happened
		Detail: JSON.stringify({
			blob: recep.jsonBlob,
			uid: recep.recipeUID,
			checksum: recep.checksum,
		}),
		EventBusName: OutgoingEventBus,
	}));

	const updatedUIDs = updated.map((_) => _.recipeUID);

	//OK this would be more efficient with sets or a map, but the numbers are going to be so small
	//it's not worth worrying about here.
	const actualRemovals = removedList.filter(
		(removedEntry) => !updatedUIDs.includes(removedEntry.recipeUID),
	);

	const removals = actualRemovals.map((ent) => ({
		Time: new Date(), //Timestamp
		Source: 'recipe-responder', //Identity of sender
		Resources: [], //Affected AWS resources
		DetailType: 'recipe-delete', //What happened
		Detail: JSON.stringify({
			checksum: ent.checksum,
			uid: ent.recipeUID,
		}),
		EventBusName: OutgoingEventBus,
	}));

	return putEntriesToBus(updates.concat(removals));
}