npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fao.org/fast-fluent-formio

v0.1.12

Published

Fluent Connector for Formio submissions

Downloads

3

Readme

FAST-FLUENT-FORMIO

Form.io fluent connector for FAST-FLUENT

Installing

To install this package in your project, you can use the following command within your terminal.

npm install --save @fao.org/fast-fluent @fao.org/fast-fluent-formio

Config

Fluent offers a handy configuration method that will get you up and running in seconds.

import {Fluent} from 'fast-fluent';

Fluent.config(
		    {
          REMOTE_CONNECTORS: [{}],
          LOCAL_CONNECTORS: [{}],
          MERGE_CONNECTORS: [{}]
        }
    );

Connectors

All Fluent connectors are independent libraries, so you will need to download them separetly.

Here is an example of a REMOTE connector using fluent-formio

import formio from 'fluent-formio'
{
    name: 'formio',
    baseUrl: 'https://ydrahgggqviwquft.form.io/',
    connector: formio
}

You can use as many connectors as you like. All available connectors are listed bellow.

REMOTE

Remote connectors give you access to API's or Databases, such as MongoDB, Formio | Provider | Library | | --------------- | ----------------------------- | | Formio | @fao.org/fast-fluent-formio |

LOCAL

Local connectors give you access to in Browser/Memory DB's such as LokiJs, IndexedDB, LocalStorage

| Provider | Library | | --------------- | --------------- | | LockiJS | fluent-loki |

MERGE

Merge connectors will pull from both Local and Remote storage providers and will merge results to give you access to all your data from one call

| Provider | Library | | --------------- | -------------------- | | Loki-Formio | fluent-loki-formio |

Your first Model

To start using Fluent your will need to create a Fluent Model. Every Fluent Model is a @stampit, so you can further compose it as you like. If you only defined one connector it will be used as default, so no need to configure your models

const Mymodel = Fluent.model({
  properties: {
    name: 'Mymodel',
  }
})

In case you defined multiple connectors, your model will need to choose where to get its data from

const Mymodel = Fluent.model({
  properties: {
    name: 'Mymodel',
    config: {
      remote: {
        connector: 'formio'
      },
      local: {
        connector: 'loki'
      }
    }
  }
})

Onother way of defining a connector as default when using multiple connectors, is to set it on the Fluent.config

import {Fluent} from 'fast-fluent';
import formio from 'fluent-formio'

Fluent.config(
		    {
          REMOTE_CONNECTORS: [{
              default: true,
              name: 'formio',
              baseUrl: 'https://ydrahgggqviwquft.form.io/',
              connector: formio
          }, {...}, {...}],
        }
    );

Using a Fluent Model

Remote, Local or Merge?

Every Fluent Model can pull/push data from those 3 sources. All Fluent methods are ASYNC functions be patient and AWAIT for them ;)

const Mymodel = Fluent.model({
  properties: {
    name: 'Mymodel',
  }
})()

// Option 1
let model = await Mymodel.remote()
// Option 2
let model = await Mymodel.local()
// Option 3
let model = await Mymodel.merge()

After deciding where to pull/push the data from you will have access to quite a few helpful methods

Basic CRUD methods

Creating

const Mymodel = Fluent.model({
  properties: {
    name: 'Mymodel',
  }
})()
const myObj = { foo : "bar", pin: "pon"}
const myArrayOfObjs = [{ foo : "bar", pin: "pon"}, { foo : "bar", pin: "pon"}]
// Single insert example
let inserted = await Mymodel.remote().insert(myObj)

// Multiple insert example
let inserted = await Mymodel.remote().insert(myArrayOfObjs)

Updating

All Fluent models identify records by de _id identifier. To update a record you MUST give it the _id

const Mymodel = Fluent.model({
  properties: {
    name: 'Mymodel',
  }
})()
// Single insert example
let updated = await Mymodel.remote().update({_id : 'abcdefghjklmnopqrsuvwxyz', myNewData: 'SomeNewData' })

Deleting

To remove a records you must provide its ID

const Mymodel = Fluent.model({
  properties: {
    name: 'Mymodel',
  }
})()
// Single insert example
let updated = await Mymodel.remote().remove('abcdefghjklmnopqrsuvwxyz')

Reading - Query Builder

Here is where we start having fun with Fluent. Fluent offers a powerful QueryBuilder HEAVILY inspired in Laravel (Thanks Taylor Otwell!!)

Get all Objects (rows)

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let users = await Users.remote().get()

Unlike Laravel, Fluent get() Method returns and Array with the requested Objects, ready for you to use.

 users.forEach(user => console.log(user.name))

Get a single Object (row)

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let user = await Users.remote().first()

In this case Fluent will return a single Object

 user.name

Get a list of Column Values

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let names = await Users.remote().pluck('name')

Select

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let users = await Users.remote().select('name', 'last_name as lastName').get()

// Its also possible to pass it as an Array
let users = await Users.remote().select(['name', 'last_name as lastName']).get()

Ordering, Grouping, Limit & Offset

orderBy

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let users = await Users.remote().select('name', 'last_name as lastName').orderBy('lastName', 'asc')get()

skip / take

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let users = await Users.remote().select('name')
            .skip(10)
            .take(10)
            .get()

Is the same as

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let users = await Users.remote().select('name')
            .offset(10)
            .limit(10)
            .get()

Collections

To further operate your data, you can turn your results into Collections (Yes, Thanks again Taylor!) Just make sure to call the collect method instead of the get()

const Users = Fluent.model({
  properties: {
    name: 'Users',
  }
})()
// Single insert example
let users = await Users.remote()
            .limit(10)
            .collect()

You can also turn any array into a Fluent Collection by using the collect method

let users = [{name: 'John', age: 20}, {name: 'Michael', age: 40}]
// Single insert example
let users = Fluent.collect(users)

Now with the collection on hand, you can use the following operators

average

Alias for avg()

users.average('age')

// 30

avg

users.avg('age')

// 30

Chunk

Chunk will just get all results and then separate them in smaller Arrays.

users.chunk(1)

// [[{name: 'John', age: 20}],[{name: 'Michael', age: 40}]]

Collapse

let collection = Fluent.collect(users.chunk(1));
collection.collapse()
// [{name: 'John', age: 20}, {name: 'Michael', age: 40}]