0.6.35 • Published 1 year ago

@x/unify v0.6.35

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

Unify

Unify for Node.js and the browser in a simple package.

For Unify documentation, visit https://unifyjs.io/docs.

Getting Started

Install Dependencies

yarn add unify unify.react sqlite3

Start Application

npx unify

This starts both the host and the react development server. The following command line options are available:

OptionTypeDefaultDescription
--help-hbooleanShow help
--versionbooleanShow version number
--configstring"unify"Path to JS or JSON config file
--port-pinteger3001TCP port number to listen on
--scope-sstringProperty name that can participate in scopes. Multiple can be specified
--sqliteFile-fstringPath to a SQLite database to use
--vocabulary-vstring"src/vocabulary"Path to a file containing vocabulary definitions
--constraints-cstring"src/constraints"Path to a file containing constraint definitions
--types-tstring"src/types"Path to a file containing type declarations
--strictApibooleanEnforce strict vocabulary API surface
--strictTypesbooleanEnforce explicit message types
--requireSslbooleanAllows disabling of SSL requirement for production
--auth0DomainbooleanEnable auth0 authentication with the provided domain
--authSecretbooleanSecret to use for signing authentication tokens
--startDevelopmentServerbooleanStart react development server
--watchbooleanWatch for changes to configuration files and reload on change

For alternate ways of starting the host, including using other database providers, see the section below.

Configure Consumer

For applications bootstrapped with create-react-app, replace the contents of src/index.js with the following:

import React from 'react'
import ReactDOM from 'react-dom'
import consumer from 'unify'
import { Provider } from 'unify.react'
import App from './App'

consumer().connect()
  .then(host => ReactDOM.render(
    <Provider host={host}><App /></Provider>,
    document.getElementById('root')
  ))

Vocabulary can also be passed in as a prop to the Provider component.

An options object can also be passed to the consumer factory. Options are as follows:

NameTypeDescription
urlstringThe websocket URL of the host to connect to
reconnectDelaynumberTime in milliseconds between reconnect attempts. Defaults to 1000ms
logobjectLogging configuration options. level property can be error, warn, debug, trace or none

Any components in your application can now use the higher order components and hooks from the unify.react library.

Host Startup / Configuration Options

The example here uses npx to invoke the Unify command line interface. A number of other options are available for starting and configuring the host.

Installing Globally

The Unify package can be installed globally by executing:

npm i -g unify
# or
yarn global add unify

This makes the CLI available globally throughout your system and can be invoked without npx.

Using a Configuration File

Configuration options can be specified in a Javascript or JSON file. By default, this file is called unify.js. The full set of options can be found here.

Starting the Host Programmatically

The host process can be started from any Node.js module.

const host = require('unify')
const vocabulary = require('./vocabulary')

host({
  port: 1234,
  scopes: ['orderId', 'productId'],
  storage: { client: 'sqlite3', connection: { filename: 'data.sqlite' } },
  vocabulary
})

Any database supported by knex can be used and should be configured accordingly here. An in-memory instance of the sqlite provider is used by default, but the sqlite3 package must be installed separately.

License

The MIT License (MIT)

Copyright © 2022 Dale Anderson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0.6.34

1 year ago

0.6.35

1 year ago

0.6.21

2 years ago

0.6.20

2 years ago

0.6.23

2 years ago

0.6.22

2 years ago

0.6.29

2 years ago

0.6.28

2 years ago

0.6.25

2 years ago

0.6.24

2 years ago

0.6.27

2 years ago

0.6.26

2 years ago

0.6.32

1 year ago

0.6.31

2 years ago

0.6.33

1 year ago

0.6.30

2 years ago

0.6.18

2 years ago

0.6.17

2 years ago

0.6.19

2 years ago

0.6.16

2 years ago

0.6.15

2 years ago

0.6.14

2 years ago

0.6.13

2 years ago

0.6.12

2 years ago

0.6.11

2 years ago

0.6.10

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.5

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.18

2 years ago