How to use @cardstack/hub - 4 common examples

To help you get started, we’ve selected a few @cardstack/hub 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 / node-tests / support.js View on Github external
params: { repo: repoPath }
        })
    );

  factory.addResource('plugin-configs')
    .withAttributes({ module: '@cardstack/git' });

  factory.addResource('grants')
    .withAttributes({
      mayCreateResource: true,
      mayUpdateResource: true,
      mayDeleteResource: true,
      mayWriteField: true
    }).withRelated('who', factory.addResource('groups', user.id));

  let container = await wireItUp(crypto.randomBytes(32), factory.getModels(), false);

  let writers = container.lookup('hub:writers');

  for (let model of inDependencyOrder(initialModels)) {
    // TODO: this one-by-one creation is still slower than is nice for
    // tests -- each time we write a schema model it invalidates the
    // schema cache, which needs to get rebuilt before we can write
    // the next one. Which also requires us to use inDependencyOrder,
    // which is kinda lame.
    //
    // On the other hand, this is a high-quality test of our ability
    // to build up the entire state in the same way an end user would
    // via JSONAPI requests. If we optimize this away, we should also
    // add some tests like that that are similarly comprehensive.
    let response = await writers.create('master', user.data, model.type, model);
    head = response.meta.version;
github cardstack / cardstack / packages / test-support / env.js View on Github external
mayLogin: true,
      })
      .withRelated('who', [{ type: user.data.type, id: user.data.id }]);

    let models = factory.getModels();
    let [foreignInitialModels, ephemeralInitialModels] = partitionInitialModels(models);

    opts.disableAutomaticIndexing = true;
    opts.environment = 'test';
    opts.seeds = () => ephemeralInitialModels;

    opts.pgBossConfig = opts.pgBossConfig || {
      newJobCheckInterval: 100, // set to minimum to speed up tests
    };

    container = await wireItUp(projectDir, crypto.randomBytes(32), defaultDataSource.getModels(), opts);
    if (foreignInitialModels.length) {
      await loadSeeds(container, foreignInitialModels);
    } else {
      await container.lookup('hub:indexers').update({ forceRefresh: true });
    }

    let ephemeralStorage = await container.lookup(`plugin-services:${require.resolve('@cardstack/ephemeral/service')}`);
    let searchers = await container.lookup(`hub:searchers`);
    await ephemeralStorage.validateModels(models, async (type, id) => {
      let result;
      try {
        result = await searchers.get(Session.INTERNAL_PRIVILEGED, 'local-hub', type, id);
      } catch (err) {
        if (err.status !== 404) {
          throw err;
        }
github cardstack / cardstack / packages / test-support / env.js View on Github external
.withRelated('who', [{ type: user.data.type, id: user.data.id }]);

    let models = factory.getModels();
    let [foreignInitialModels, ephemeralInitialModels] = partitionInitialModels(models);

    opts.disableAutomaticIndexing = true;
    opts.environment = 'test';
    opts.seeds = () => ephemeralInitialModels;

    opts.pgBossConfig = opts.pgBossConfig || {
      newJobCheckInterval: 100, // set to minimum to speed up tests
    };

    container = await wireItUp(projectDir, crypto.randomBytes(32), defaultDataSource.getModels(), opts);
    if (foreignInitialModels.length) {
      await loadSeeds(container, foreignInitialModels);
    } else {
      await container.lookup('hub:indexers').update({ forceRefresh: true });
    }

    let ephemeralStorage = await container.lookup(`plugin-services:${require.resolve('@cardstack/ephemeral/service')}`);
    let searchers = await container.lookup(`hub:searchers`);
    await ephemeralStorage.validateModels(models, async (type, id) => {
      let result;
      try {
        result = await searchers.get(Session.INTERNAL_PRIVILEGED, 'local-hub', type, id);
      } catch (err) {
        if (err.status !== 404) {
          throw err;
        }
      }
github cardstack / cardstack / tests / stub-searcher / searcher.js View on Github external
async get(session, type, id, next) {
    if (bootstrapSchema.concat(systemModels).find(m => m.type === type && m.id === id)) {
      return await next();
    }

    if (this.params.injectFirst) {
      return { data: this.makeModel(type, id, this.params.injectFirst), meta: this.makeMeta(type, id) };
    }

    let result = await next();
    if (result) {
      return result;
    }
    if (this.params.injectSecond) {
      return { data: this.makeModel(type, id, this.params.injectSecond), meta: this.makeMeta(type, id) };
    }
  }

@cardstack/hub

Stock API server for the Cardstack tech stack.

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Similar packages