Skip to content
/ loque Public

Object Data Locator, Extractor, Updater [Work in Thinking]

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE.deon
Notifications You must be signed in to change notification settings

plurid/loque

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



License: DEL

loque

Object Data Locator, Extractor, Updater


loque provides utility for locating, extracting, and updating data from object-like structures (arbitrarily nested maps and lists) based on a querying syntax.

Contents

About

Given a collection of data, loque selects, retrieves, and modifies values.

Example:

import loque from '@plurid/loque';



const data = {
    records: [
        {
            ownedBy: 'A',
            id: '1',
            value: 'one',
        },
        {
            ownedBy: 'B',
            id: '2',
            value: 'two',
        },
        {
            ownedBy: 'A',
            id: '3',
            value: 'three',
        },
        {
            ownedBy: 'A',
            id: '4',
            value: 'four',
        },
    ],
};


const main = () => {
    // LocatorStatements
    const locatorRecordOne = loque.locate(
        'records.id:1',
    );

    // Extracted data obtained with locator statements.
    // {
    //     ownedBy: 'A',
    //     id: '1',
    //     value: 'one',
    // };
    const recordOne = loque.extract(
        locatorRecordOne,
        data,
    ).data;

    // Extracted data obtained with locator string.
    // [
    //     {
    //         ownedBy: 'A',
    //         id: '1',
    //         value: 'one',
    //     },
    //     {
    //         ownedBy: 'B',
    //         id: '2',
    //         value: 'two',
    //     },
    // ];
    const recordsOneTwo = loque.extract(
        'records . id:1 & id:2',
        data,
    ).data;

    // Updated data with locator string.
    // {
    //     records: [
    //         ...
    //         {
    //             ownedBy: 'A',
    //             id: '3',
    //             value: 'three-modified',
    //         },
    //         ...
    //     ],
    // };
    const newData = loque.update(
        'records.id:3',
        data,
        {
            value: 'three-modified',
        },
    );


    // Extraction with cursor.
    const lastTwo = loque.extract(
        'records.ownedBy:A |last 2|',
        newData,
    ).data;


    const firstTwo = loque.extract(
        'records.ownedBy:A |first 2|',
        newData,
    );

    // Cursor index value of the last document.
    const firstTwoCursor = firstTwo.cursor;

    const nextTwo = loque.extract(
        `records.ownedBy:A |first 2 above ${firstTwoCursor}|`,
        newData,
    ).data;
}

main();

Data

A collection of data is an arbitrary structure composed of collections of documents and values.

const data = {
    // collections
    aCollection: [
    ],

    // or values
    aValue: 'value',
};

A collection is a specialized list.

const data = {
    // a normal list
    list: [
        'one',
        'two,
    ],
    collection: [
        // the first item is always a marker for the collection type
        {
            type: 'collection',
        },

        // the other elements are any type the collection holds
        // and is available to the public interface
        {
            one: 'two',
        },
    ],
}

A value can be a number, a string, a boolean, a map.

A document can contain arbitrary values and collections.

Packages

Version

@plurid/loque-javascript • the JavaScript/TypeScript implementation

About

Object Data Locator, Extractor, Updater [Work in Thinking]

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE.deon

Stars

Watchers

Forks