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

fql-toolkit

v2.10.1

Published

Fql Toolkit

Downloads

962

Readme

FQL Toolkit Library

A lightweight and flexible JavaScript toolkit library for Form Query Language (FQL) that provides a fluent API for building and executing FQL queries.

📦 Installation

# Using npm
npm install fql-toolkit

# Using yarn
yarn add fql-toolkit

# Using pnpm
pnpm add fql-toolkit

🔧 Quick Start

import { FQL } from 'fql-toolkit';

// Initialize the client
const fql = new FQL({
  url: 'https://api.example.com',
  token: 'FQL USER TOKEN HERE'
});

// Create a form
await fql.createForm('users')
  .addDataDefinition({name: 'name', type: 'text'})
  .addDataDefinition({name: 'age', type: 'number'})
  .addDataDefinition({name: 'email', type: 'text'})
  .create();

// Insert data
await fql.createData('users')
  .setValue('John Doe')
  .setValue(30)
  .setValue('[email protected]')
  .create();

// Show forms
await fql.showForms()
  .setForm("users")
  .create();

// Remove forms
await fql.removeForms()
  .setForm("users")
  .create();

📖 Documentation

Initialization

const fql = new FQL({
  url: string;     // Required: API endpoint
  token: string;   // Required: FQL token
});

Creating Forms

// Basic form creation
await fql.createForm('employees')
  .addDataDefinition({name: 'name', type: 'text'})
  .addDataDefinition({name: 'salary', type: 'number'})
  .create();

// Getting the FQL without executing
const formQuery = fql.createForm('employees')
  .addDataDefinition({name: 'name', type: 'text'})
  .getFQL();
// Result: "create form employees(name text, salary number)"

Inserting Data

// Single record insertion
await fql.createData('employees')
  .setValue('John Doe')
  .setValue(50000)
  .create();

// Get FQL without executing
const dataQuery = fql.createData('employees')
  .setValue('Jane Smith')
  .setValue(60000)
  .getFQL();
// Result: "create employees('Jane Smith', 60000)"

Showing Forms

// All forms
const allForms = fql.showForms()
// Specific form
const specificForm = fql.showForms().setForm("People")
// List of forms
const formList =  fql.showForms().setForm("People").setForm("Countries")
// Equivalent to fql.showForms().setForms(["People", "Countries"]")

// Get FQL without executing
allForms.getFql() // Result: "show forms"
specificForm.getFql() // Result: "show forms People"
formList.getFql() // Result: "show forms People, Countries"

// Show all forms
await allForms.create()
// Show a specific form
await specificForm.create()
// Show list of forms
await formList.create()

Removing Forms

// All forms
const allForms = fql.removeForms()
// Specific form
const specificForm = fql.removeForms().setForm("People")
// List of forms
const formList =  fql.removeForms().setForm("People").setForm("Countries")
// Equivalent to fql.removeForms().setForms(["People", "Countries"]")

// Get FQL without executing
allForms.getFql() // Result: "show forms"
specificForm.getFql() // Result: "show forms People"
formList.getFql() // Result: "show forms People, Countries"

// Show all forms
await allForms.create()
// Show a specific form
await specificForm.create()
// Show list of forms
await formList.create()

Error Handling

try {
  const result = await fql.createData('employees')
    .setValue('John Doe')
    .setValue('invalid_salary') // Wrong type
    .create();
} catch (error) {
  if (error instanceof FQLError) {
    console.error('FQL Error:', error.message);
    console.error('Query:', error.query);
    console.error('Code:', error.code);
  }
}

🎯 Examples

Complex Form Creation

const form = await fql.createForm('products')
  .addDataDefinition({name: 'id', type: 'number'})
  .addDataDefinition({name: 'name', type: 'text'})
  .addDataDefinition({name: 'description', type: 'text'})
  .addDataDefinition({name: 'price', type: 'number'})
  .addDataDefinition({name: 'inStock', type: 'boolean'})
  .addDataDefinition({name: 'categories', type: 'array'})
  .addDataDefinition({name: 'created', type: 'date'})
  .create();

Batch Data Insertion

const products = [
  ['Product A', 29.99, true],
  ['Product B', 49.99, false],
  ['Product C', 99.99, true]
];

for (const [name, price, inStock] of products) {
  await fql.createData('products')
    .setValue(name)
    .setValue(price)
    .setValue(inStock)
    .create();
}

🔍 API Reference

FQL Class

| Method | Description | Parameters | Returns | |---------------|-----------------------------------|--------------------|-------------------------| | createForm | Creates a FQLForm builder | formName: string | FQLFormBuilder | | createNew | Creates a FQLData builder | formName: string | FQLDataBuilder | | showForms | Create a FQLShowForms builder | None | FQLShowFormsBuilder | | removeForms | Create a FQLRemoveForms builder | None | FQLRemoveFormsBuilder | | executeFQL | Executes raw FQL | query: string | Promise<any> |

FQLFormBuilder Class

| Method | Description | Parameters | Returns | |---------------------|--------------------------------|-------------------------------------------------------------------------------------------------------------|------------------| | addDataDefinition | Adds a data definition field | {name: string, type: string, notNull: boolean = false, unique: boolean: false} | FQLFormBuilder | | addDataReference | Adds a data reference field | {name: string, cardinality: list = [0, 1], path: list, totally: boolean = false, unique: boolean = false} | FQLFormBuilder | | create | Executes the query | None | Promise<any> | | getFQL | Gets the FQL string | query: string | string |

FQLDataBuilder Class

| Method | Description | Parameters | Returns | |---------------|--------------------------|--------------------|------------------| | setValue | Adds a value | value: any | FQLDataBuilder | | create | Executes the query | None | Promise<any> | | getFQL | Gets the FQL string | query: string | string |

FQLShowFormsBuilder Class

| Method | Description | Parameters | Returns | |---------------|--------------------------|--------------------|-----------------------| | setForm | Add a form | value: string | FQLShowFormsBuilder | | setForms | Add a form list | value: [string] | FQLShowFormsBuilder | | create | Executes the query | None | Promise<any> | | getFQL | Gets the FQL string | query: string | string |

FQLRemoveFormsBuilder Class

| Method | Description | Parameters | Returns | |---------------|--------------------------|--------------------|-------------------------| | setForm | Add a form | value: string | FQLRemoveFormsBuilder | | setForms | Add a form list | value: [string] | FQLRemoveFormsBuilder | | create | Executes the query | None | Promise<any> | | getFQL | Gets the FQL string | query: string | string |

🔨 Development

# Install dependencies
npm install

# Run tests
npm test

# Build
npm run build

# Lint
npm run lint

# Type check
npm run type-check

🤝 Contributing

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'Add some amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.