How to use the ssb-ref.isLink function in ssb-ref

To help you get started, we’ve selected a few ssb-ref 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 ssbc / ssb-server / lib / validators.js View on Github external
linksOpts: function (v, n) {
    var err = this.get('object')(v, n)
    if (err)
      return err

    // .source
    if (v.source && !ref.isLink(v.source) && !isFilter(v.source))
      return AttrType(n, 'source', 'id|filter')

    // .dest
    if (v.dest && !ref.isLink(v.dest) && !isFilter(v.dest))
      return AttrType(n, 'dest', 'id|filter')

    // .rel
    if (v.rel && typeof v.rel != 'string')
      return AttrType(n, 'rel', 'string')

    // .live
    if (v.live && typeof v.live != 'boolean' && typeof v.live != 'number')
      return AttrType(n, 'live', 'boolean')

    // .reverse
    if (v.reverse && typeof v.reverse != 'boolean' && typeof v.reverse != 'number')
      return AttrType(n, 'reverse', 'boolean')

    // .keys
    if (v.keys && typeof v.keys != 'boolean' && typeof v.keys != 'number')
github ssbc / ssb-server / lib / validators.js View on Github external
linksOpts: function (v, n) {
    var err = this.get('object')(v, n)
    if (err)
      return err

    // .source
    if (v.source && !ref.isLink(v.source) && !isFilter(v.source))
      return AttrType(n, 'source', 'id|filter')

    // .dest
    if (v.dest && !ref.isLink(v.dest) && !isFilter(v.dest))
      return AttrType(n, 'dest', 'id|filter')

    // .rel
    if (v.rel && typeof v.rel != 'string')
      return AttrType(n, 'rel', 'string')

    // .live
    if (v.live && typeof v.live != 'boolean' && typeof v.live != 'number')
      return AttrType(n, 'live', 'boolean')

    // .reverse
    if (v.reverse && typeof v.reverse != 'boolean' && typeof v.reverse != 'number')
github ticktackim / ticktack-workplan / message / obs / webshares.js View on Github external
'message.obs.webshares': (id) => {
      if (!ref.isLink(id)) throw new Error('an id must be specified')
      var obs = get(id)
      obs.id = id
      var result = computed(obs, getShares, {
        // allow manual append for simulated realtime
        onListen: () => activeShares.add(obs),
        onUnlisten: () => activeShares.delete(obs)
      })
      result.sync = obs.sync
      return result
    }
  })
github ssbc / ssb-db / lib / validators.js View on Github external
linksOpts: function (v, n) {
    var err = this.get('object')(v, n)
    if (err)
      return err

    // .source
    if (v.source && !ref.isLink(v.source) && !isFilter(v.source))
      return AttrType(n, 'source', 'id|filter')

    // .dest
    if (v.dest && !ref.isLink(v.dest) && !isFilter(v.dest))
      return AttrType(n, 'dest', 'id|filter')

    // .rel
    if (v.rel && typeof v.rel != 'string')
      return AttrType(n, 'rel', 'string')

    // .live
    if (v.live && typeof v.live != 'boolean' && typeof v.live != 'number')
      return AttrType(n, 'live', 'boolean')

    // .reverse
    if (v.reverse && typeof v.reverse != 'boolean' && typeof v.reverse != 'number')
      return AttrType(n, 'reverse', 'boolean')

    // .keys
    if (v.keys && typeof v.keys != 'boolean' && typeof v.keys != 'number')
github staltz / manyverse / src / ssb / opinions / about / obs.js View on Github external
function socialValue$(id, key, defaultValue) {
    if (!ref.isLink(id)) throw new Error('About requires an ssb ref!');
    return xs.createWithMemory({
      start(listener) {
        listener.next(defaultValue);
        this.sink = pull.drain(listener.next.bind(listener));
        pull(api.sbot.pull.aboutSocialValueStream({key, dest: id}), this.sink);
      },
      stop() {
        if (this.sink) this.sink.abort(true);
      },
    });
  }
};
github ssb-junkyard / ssb-msg-schemas / index.js View on Github external
function link (l) {
  if (typeof l == 'string') {
    if (ssbref.isLink(l))
      return l
  }
  if (l && typeof l == 'object') {
    if (Object.keys(l).length === 1 && l.link && ssbref.isLink(l))
      return l
    return mlib.link(l)
  }
}
github staltz / manyverse / src / backend / plugins / votes.ts View on Github external
voterStream: function voterStream(msgId: string) {
        if (!ref.isLink(msgId))
          throw new Error('A message id must be specified');
        return pull(
          ssb.backlinks.read({
            query: [{$filter: {dest: msgId}}],
            index: 'DTA',
            live: true,
          }),
          collectUniqueAuthors(),
        );
      },
    };
github ssb-junkyard / ssb-msg-schemas / util / index.js View on Github external
function link (l) {
  if (typeof l === 'string') {
    if (isLink(l)) { return l }
  }
  if (l && typeof l === 'object') {
    if (Object.keys(l).length === 1 && l.link && isLink(l)) { return l }
    return mlib.link(l)
  }
}
github ssb-junkyard / ssb-msg-schemas / index.js View on Github external
function link (l) {
  if (typeof l == 'string') {
    if (ssbref.isLink(l))
      return l
  }
  if (l && typeof l == 'object') {
    if (Object.keys(l).length === 1 && l.link && ssbref.isLink(l))
      return l
    return mlib.link(l)
  }
}