How to use the @cardstack/base-card.data function in @cardstack/base-card

To help you get started, we’ve selected a few @cardstack/base-card examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cardstack / cardstack / packages / hub / card-services.ts View on Github external
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);
github cardstack / cardstack / packages / hub / card-services.ts View on Github external
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.`);
      }
    }
  }
}

@cardstack/base-card

Base Card for Cardstack platform

MIT
Latest version published 5 years ago

Package Health Score

54 / 100
Full package analysis

Popular @cardstack/base-card functions