@seamapi/blueprint
Version:
Build tools for the Seam API using this blueprint.
48 lines • 1.68 kB
JavaScript
export const formatCodeRecords = async (code, context) => {
const entries = Object.entries(code);
const formattedEntries = await Promise.all(entries.map(async (entry) => {
if (entry == null)
throw new Error('Unexpected null code entry');
return await formatCodeEntry(entry, context);
}));
return Object.fromEntries(formattedEntries);
};
const formatCodeEntry = async ([key, code], { formatCode }) => {
if (code == null)
throw new Error(`Unexpected null in code object for ${key}`);
const [request, response] = await Promise.all([
await formatCode(code.request, code.request_syntax),
await formatCode(code.response, code.response_syntax),
]);
return [
key,
{
...code,
request,
response,
},
];
};
export const formatResourceRecords = async (resource, context) => {
const entries = Object.entries(resource);
const formattedEntries = await Promise.all(entries.map(async (entry) => {
if (entry == null)
throw new Error('Unexpected null resource entry');
return await formatResourceEntry(entry, context);
}));
return Object.fromEntries(formattedEntries);
};
const formatResourceEntry = async ([key, resource], { formatCode }) => {
if (resource == null) {
throw new Error(`Unexpected null in resource object for ${key}`);
}
const resourceData = await formatCode(resource.resource_data, resource.resource_data_syntax);
return [
key,
{
...resource,
resource_data: resourceData,
},
];
};
//# sourceMappingURL=format.js.map