@ztimson/pumpkinpie v1.8.9
PumpkinPie
A front end framework to work with Datalynk
This is a library to provide full Datalynk support to any JS framework or app, it supports both promises and RxJS.
Table of Contents
Quick Start
- Install Pumpkin Pie
npm install --save @ztimson/pumpkinpie
yarn add @ztimson/pumpkinpie
- Add generator script to package.json
{
"name": "example",
"scripts": {
"generate": "generate <spoke> [login] [password]", // <---- Login/Password optional
},
...
- Generate the models. If you didn't hard code the login/password you will be prompted. The generated files will be created under the 'models' folder in the current working directory. Feel free to move them.
npm run generate
> Login: example
> Password: ********
yarn generate
> Login: example
> Password: ********
- Create an API object
import {API} from '@ztimson/pumpkinpie'
const api = new API('http://example.auxiliumgroup.com/api');
- Import the generated models and start using them with the slice object
import {User} from './models/User.model';
import {Slices} from './models/slices';
// Passing the User model into the slice as a generic provides full intellisense
// Slices is an enumerable of Slice IDs to make life easier
api.slice<User>(Slices.User).select().exec().then(ignore => {});
Documentation
This library has auto generated documentation that can be found here.
API
The API layer provides the an object to handles making requests. It will automatically convert any data types, cache on going requests to prevent duplicates and, unless disabled, will bundle requests made at the same time (default 100ms delay to wait for requests) together to minimize network usage.
Generator
An experimental CLI tool to generate a slices enumerable that holds all the slice IDs. It also generates interfaces to represent the data of each slice. It takes into account the name, readonly, required and type. In the case of selection dropdowns, checkbox's, or radio buttons a companion enumerable is generated to proved type strict comparisions.
Slice
The slice layer is a generic object which will construct requests for you. It should be partnered with the generator and its models to provide intellisense and type safe calls.
Examples
Login
const api = new API('https://example.auxiliumgroup.com');
api.request({'$/auth/login': {login: 'user', password: '123'}}).then(user => ...)
Async/Away
const api = new API('https://example.auxiliumgroup.com');
let user = await api.request({'$/auth/login': {login: 'user', password: '123'}})
Select all from slice
const api = new API('https://example.auxiliumgroup.com');
let rows = await api.slice(12345).select().exec().rows();
// rows value: [{}, {}, ...]
Select single item from slice
const api = new API('https://example.auxiliumgroup.com');
let row = await api.slice(12345).select(12345).exec().row();
// row value: {a: 1, b: 2, ...}
Insert
const api = new API('https://example.auxiliumgroup.com');
let keys = await api.slice(12345).insert([
{first: 'Adam', last: 'Bilbo'},
{first: 'Charlie', last: 'DeMont'}
]).exec().keys();
// keys value: [1, 2]
Update user
const api = new API('https://example.auxiliumgroup.com');
let success = await api.slice(12345)
.update({id: 1, first: 'Adam', last: 'Baxter'}).exec().key();
// success value: 1
Add a flag to all users who are underage
const api = new API('https://example.auxiliumgroup.com');
let users = await api.slice(12345).select().exec().rows();
api.slice(1245).update(
users.map(user => Object.assign(user, {flag: user.age < 18}))
).exec();
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago