How to use @signalk/signalk-schema - 10 common examples

To help you get started, we’ve selected a few @signalk/signalk-schema 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 SignalK / signalk-server-node / src / interfaces / rest.js View on Github external
) {
          let meta = getMetadata(path.slice(0, path.length - 1).join('.'))
          let fromDefaults = _.get(app.deltaCache.defaults, path.join('.'))
          if (meta || fromDefaults) {
            res.json({...meta, ...fromDefaults})
            return
          }
        }
        if (
          path.length > 5 &&
          path[path.length - 1] === 'units' &&
          path[path.length - 2] === 'meta'
        ) {
          let units = _.get(app.deltaCache.defaults, path.join('.'))
          if (!units) {
            units = getUnits(path.slice(0, path.length - 2).join('.'))
          }
          if (units) {
            res.json(units)
            return
          }
        }

        if ( path[0] === 'vessels' && path[1] === 'self' ) {
          path[1] = app.selfId
        }
             
        function sendResult(last, aPath) {
          if (last) {
            // tslint:disable-next-line: forin
            for (const i in aPath) {
              const p = aPath[i]
github SignalK / signalk-server-node / test / multiple-values.js View on Github external
const chai = require('chai')
chai.Should()
chai.use(require('chai-things'))
chai.use(require('@signalk/signalk-schema').chaiModule)
const freeport = require('freeport-promise')
const startServerP = require('./servertestutilities').startServerP

const rp = require('request-promise')

const uuid = 'urn:mrn:signalk:uuid:c0d79334-4e25-4245-8892-54e8ccc8021d'

const delta = {
  context: 'vessels.' + uuid,
  updates: [
    {
      source: {
        pgn: 128275,
        label: '/dev/actisense',
        src: '115'
      },
github SignalK / signalk-server-node / test / deltacache.js View on Github external
const chai = require('chai')
chai.Should()
chai.use(require('chai-things'))
chai.use(require('@signalk/signalk-schema').chaiModule)
const _ = require('lodash')
const assert = require('assert')
const freeport = require('freeport-promise')
const WebSocket = require('ws')
const rp = require('request-promise')
const startServerP = require('./servertestutilities').startServerP

const testDelta = {
  context: 'vessels.self',
  updates: [
    {
      timestamp: '2014-05-03T09:14:11.100Z',
      values: [
        {
          path: 'navigation.trip.log',
          value: 43374
github SignalK / signalk-server-node / src / interfaces / ws.js View on Github external
msg.updates.forEach(update => {
    let source = update.$source
    if (!source && update.source) {
      source = getSourceId(update.source)
    }

    if (source) {
      update.values.forEach(valuePath => {
        if (!pathSources[valuePath.path]) {
          pathSources[valuePath.path] = {}
        }
        if (
          !pathSources[valuePath.path][source] ||
          pathSources[valuePath.path][source] !== spark
        ) {
          if (pathSources[valuePath.path][source]) {
            console.log(
              `WARNING: got a new ws client for path ${valuePath.path} source ${source}`
            )
          }
github SignalK / signalk-server-node / src / interfaces / rest.js View on Github external
if (path === 'self') {
          return res.json(`vessels.${app.selfId}`)
        }

        path =
          path.length > 0
            ? path
                .replace(/\/$/, '')
                .split('/')
            : []

        if (
          path.length > 4 &&
          path[path.length - 1] === 'meta'
        ) {
          let meta = getMetadata(path.slice(0, path.length - 1).join('.'))
          let fromDefaults = _.get(app.deltaCache.defaults, path.join('.'))
          if (meta || fromDefaults) {
            res.json({...meta, ...fromDefaults})
            return
          }
        }
        if (
          path.length > 5 &&
          path[path.length - 1] === 'units' &&
          path[path.length - 2] === 'meta'
        ) {
          let units = _.get(app.deltaCache.defaults, path.join('.'))
          if (!units) {
            units = getUnits(path.slice(0, path.length - 2).join('.'))
          }
          if (units) {
github tkurki / signalk-to-influxdb / skToInflux.js View on Github external
function addSource(update, tags) {
  if ( update['$source'] ) {
    tags.source = update['$source']
  } else if ( update['source'] ) {
    tags.source = getSourceId(update['source'])
  }
  return tags
}
github SignalK / signalk-server-node / src / deltacache.js View on Github external
function ensureHasDollarSource(normalizedDelta) {
  let dollarSource = normalizedDelta.$source
  if (!dollarSource) {
    dollarSource = getSourceId(normalizedDelta.source)
    normalizedDelta.$source = dollarSource
  }
  return dollarSource
}
github SignalK / signalk-server-node / src / tokensecurity.js View on Github external
const notAllowed = delta.updates.find(update => {
        let source = update.$source
        if (!source) {
          source = getSourceId(update.source)
        }
        return update.values.find(valuePath => {
          return (
            strategy.checkACL(
              req.skPrincipal.identifier,
              context,
              valuePath.path,
              source,
              'write'
            ) === false
          )
        })
      })
github SignalK / signalk-server-node / src / index.js View on Github external
app.use(require('cors')())
  app.use(bodyParser.json({ limit: FILEUPLOADSIZELIMIT }))

  this.app = app
  app.started = false
  _.merge(app, opts)

  require('./config/config').load(app)
  app.version = '0.0.1'

  startSecurity(app, opts ? opts.securityConfig : null)

  require('./serverroutes')(app, saveSecurityConfig, getSecurityConfig)
  require('./put').start(app)

  app.signalk = new FullSignalK(app.selfId, app.selfType, app.config.defaults)

  const deltachain = new DeltaChain(app.signalk.addDelta.bind(app.signalk))
  app.registerDeltaInputHandler = deltachain.register

  app.providerStatus = {}

  app.setProviderStatus = function(providerId, statusMessage) {
    doSetProviderStatus(providerId, statusMessage, 'status')
  }

  app.setProviderError = function(providerId, errorMessage) {
    doSetProviderStatus(providerId, errorMessage, 'error')
  }

  function doSetProviderStatus(providerId, statusMessage, type) {
    if (!statusMessage) {
github SignalK / signalk-server-node / src / deltacache.js View on Github external
DeltaCache.prototype.buildFullFromDeltas = function(
  user,
  deltas,
  includeSources
) {
  const signalk = new FullSignalK(
    this.app.selfId,
    this.app.selfType,
    JSON.parse(JSON.stringify(this.defaults))
  )

  const addDelta = signalk.addDelta.bind(signalk)

  if (includeSources) {
    _.values(this.sourceDeltas).forEach(addDelta)
  }

  if (deltas && deltas.length) {
    const secFilter = this.app.securityStrategy.shouldFilterDeltas()
      ? delta => this.app.securityStrategy.filterReadDelta(user, delta)
      : delta => true
    deltas.filter(secFilter).forEach(addDelta)

@signalk/signalk-schema

SignalK specification schema as an npm module with tests

CC-BY-SA-2.0
Latest version published 10 months ago

Package Health Score

65 / 100
Full package analysis