Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function setupBaseCard(pgsearchClient: todo, searchers: todo, writers: todo, currentSchema: todo) {
await pgsearchClient.ensureDatabaseSetup();
let currentInternalBaseCard: SingleResourceDoc | undefined;
try {
currentInternalBaseCard = await searchers.get(
Session.INTERNAL_PRIVILEGED,
'local-hub',
baseCard.data.id,
baseCard.data.id
);
} catch (err) {
if (err.status !== 404) {
throw err;
}
}
if (!currentInternalBaseCard) {
log.info(`Base card doesn't exist yet, creating @cardstack/base-card...`);
await writers.create(Session.INTERNAL_PRIVILEGED, 'cards', baseCard);
} else {
let version = get(currentInternalBaseCard, 'data.meta.version');
let source = get(currentInternalBaseCard, 'data.meta.source');
let schema = await currentSchema.getSchema();
let dataSource = schema.getDataSource(source);
unset(currentBaseCard, 'data.attributes.metadata-summary');
for (let resource of (currentBaseCard.included || []).concat(currentBaseCard.data)) {
delete resource.meta;
if (isEmpty(resource.attributes || {})) {
delete resource.attributes;
}
if (isEmpty(resource.relationships || {})) {
delete resource.relationships;
}
}
if (!isEqual(currentBaseCard, baseCard)) {
log.debug('the current base card:', JSON.stringify(currentBaseCard, null, 2));
log.debug('new base card:', JSON.stringify(baseCard, null, 2));
log.info(`Base card is out of date, updating @cardstack/base-card...`);
set(baseCard, 'data.meta.version', version);
await writers.update(Session.INTERNAL_PRIVILEGED, 'cards', baseCard.data.id, baseCard);
} else {
log.info(`Base card is up to date.`);
}
}
}
}