Socket
Book a DemoInstallSign in
Socket

cagibi

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cagibi

Tiny asynchronous state management based on static data stitching

latest
Source
npmnpm
Version
0.1.21
Version published
Maintainers
1
Created
Source

Cagibi Illustration


Addition-only asynchronous state based on static data stitching
import { make } from 'cagibi';

// Create a stitchable copy of your object
const profile = make({ name: 'Joe', posts: [] });

// Use your object as a reference to stitch a sub-object
const post = make({ title: 'A new post' }, profile.posts);

// Stitch them all to get the final object
const stitched = stitch(profile, post);

// => { name: 'Joe', posts: [{ title: 'A new post' }] }

npm i cagibi / yarn add cagibi

Version Downloads

Cagibi's name comes from the french word used to call a small storeroom. Pronounced /kä'jēbē/.

What is cagibi?

  • Two main methods to use it: make and stitch.
  • Two more methods to use it with persisted state or through remote channels: write and read.
  • Some utilities like protect(target, ...keys) to forbid changes on keys.
  • And a Patches array-based class to help handling all patches to be stitched back into one object.
  • No store.
  • No complex API.
  • Fully extendable.
  • Intends to work with all native objects.

When would cagibi come in handy?

Merging nested data structure through async channels (API, parallel threads or job queues) without willing to maintain a key-value store with primary keys linking records.

Create a stitchable copy of your object

import { make } from 'cagibi';

const profile = make({ name: 'Joe', posts: [] });
// => { name: 'Joe', posts: [] }

Use your object as a reference to stitch a sub-object

const post = make({ title: 'A new post' }, profile.posts);

Stitch them all to get the final object

import { stitch } from 'cagibi';

const stitched = stitch(profile, post);

Returns stitched state:

{
    "name": "Joe",
    "posts": [{ "title": "A new post" }]
}

Need to re-use it asynchronously or later?

import { make, stitch, write, read } from 'cagibi';

const stack = [];

const profile = make({ name: 'Joe', posts: [] });
const post = make({ title: 'A new post' }, profile.posts);

stack.push(write(profile));
stack.push(write(post));

// ...
// And only later on or in another environment
const profile = read(profileWritten);
const post = read(postWritten);
const stitched = stitch(profile, post);

Returns stitched state:

{
    "name": "Joe",
    "posts": [{ "title": "A new post" }]
}

Need help managing all patches?

import { make, stitch, write, read, Patches } from 'cagibi';

const patches = new Patches();

const profile = make({ name: 'Joe', posts: [] });
const post = make({ title: 'A new post' }, profile.posts);

patches.push(profile, post);

const savedPatches = patches.write();

// ...
// And only later on or in another environment

const importedPatches = new Patches();
importedPatches.read(savedPatches);

const stitched = importedPatches.stitch();

Returns stitched state:

{
    "name": "Joe",
    "posts": [{ "title": "A new post" }]
}

Keywords

state

FAQs

Package last updated on 06 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.