How to use @logux/core - 8 common examples

To help you get started, we’ve selected a few @logux/core 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 logux / server / test / stress / client.js View on Github external
async function tick () {
  if (stop) return

  let nodeId = `1:${ ++index }`
  let connection = new WsConnection('ws://localhost:31337', WebSocket)
  let log = new Log({ nodeId, store: new MemoryStore() })
  let node = new ClientNode(nodeId, log, connection, {
    credentials: 'secret',
    subprotocol: '1.0.0',
    outMap: map
  })

  node.on('clientError', e => {
    stop = true
    throw e
  })
  node.catch(e => {
    stop = true
    throw e
  })

  node.connection.connect()
github logux / server / test / stress / client.js View on Github external
async function tick () {
  if (stop) return

  let nodeId = `1:${ ++index }`
  let connection = new WsConnection('ws://localhost:31337', WebSocket)
  let log = new Log({ nodeId, store: new MemoryStore() })
  let node = new ClientNode(nodeId, log, connection, {
    credentials: 'secret',
    subprotocol: '1.0.0',
    outMap: map
  })

  node.on('clientError', e => {
    stop = true
    throw e
  })
  node.catch(e => {
    stop = true
    throw e
  })

  node.connection.connect()
  await node.waitFor('synchronized')
github logux / server / test / stress / client.js View on Github external
async function tick () {
  if (stop) return

  let nodeId = `1:${ ++index }`
  let connection = new WsConnection('ws://localhost:31337', WebSocket)
  let log = new Log({ nodeId, store: new MemoryStore() })
  let node = new ClientNode(nodeId, log, connection, {
    credentials: 'secret',
    subprotocol: '1.0.0',
    outMap: map
  })

  node.on('clientError', e => {
    stop = true
    throw e
  })
  node.catch(e => {
    stop = true
    throw e
  })
github logux / server / base-server.js View on Github external
* @type {string}
     *
     * @example
     * console.log('Error was raised on ' + server.nodeId)
     */
    this.nodeId = `server:${ this.options.id || nanoid(8) }`

    this.options.root = this.options.root || process.cwd()

    let store = this.options.store || new MemoryStore()

    let log
    if (this.options.time) {
      log = this.options.time.nextLog({ store, nodeId: this.nodeId })
    } else {
      log = new Log({ store, nodeId: this.nodeId })
    }
    /**
     * Server actions log.
     * @type {Log}
     *
     * @example
     * server.log.each(finder)
     */
    this.log = log

    this.on('preadd', (action, meta) => {
      let isLogux = action.type.slice(0, 6) === 'logux/'
      if (!meta.server) {
        meta.server = this.nodeId
      }
      if (!meta.status && !isLogux) {
github logux / server / base-server.js View on Github external
}
    if (!this.options.controlPort) this.options.controlPort = 31338
    if (!this.options.controlHost) this.options.controlHost = '127.0.0.1'

    /**
     * Server unique ID.
     * @type {string}
     *
     * @example
     * console.log('Error was raised on ' + server.nodeId)
     */
    this.nodeId = `server:${ this.options.id || nanoid(8) }`

    this.options.root = this.options.root || process.cwd()

    let store = this.options.store || new MemoryStore()

    let log
    if (this.options.time) {
      log = this.options.time.nextLog({ store, nodeId: this.nodeId })
    } else {
      log = new Log({ store, nodeId: this.nodeId })
    }
    /**
     * Server actions log.
     * @type {Log}
     *
     * @example
     * server.log.each(finder)
     */
    this.log = log
github logux / server / server-client.js View on Github external
this.node.on('connect', () => {
      if (!this.isSubprotocol(this.app.options.supports)) {
        throw new LoguxError('wrong-subprotocol', {
          supported: this.app.options.supports,
          used: this.node.remoteSubprotocol
        })
      }
    })
    this.node.on('state', () => {
github logux / server / server-client.js View on Github external
async auth (credentials, nodeId) {
    this.nodeId = nodeId
    let data = parseNodeId(nodeId)
    this.clientId = data.clientId
    this.userId = data.userId

    if (nodeId === 'server' || data.userId === 'server') {
      this.app.reporter('unauthenticated', reportDetails(this))
      return false
    }

    let start = Date.now()
    let result = await this.app.authenticator(this.userId, credentials, this)

    if (this.app.isBruteforce(this.remoteAddress)) {
      throw new LoguxError('bruteforce')
    }

    if (result) {
      let zombie = this.app.clientIds[this.clientId]
      if (zombie) {
        zombie.zombie = true
        this.app.reporter('zombie', { nodeId: zombie.nodeId })
        zombie.destroy()
      }
      this.app.clientIds[this.clientId] = this
      this.app.nodeIds[this.nodeId] = this
      if (this.userId) {
        if (!this.app.userIds[this.userId]) {
          this.app.userIds[this.userId] = []
        }
        this.app.userIds[this.userId].push(this)
github logux / server / base-server.js View on Github external
this.ws.on('connection', ws => {
      this.addClient(new ServerConnection(ws))
    })
    this.reporter('listen', {