0.1.3 • Published 9 months ago

object-rules-engine v0.1.3

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

Example

import { NestedObjectWithSubscriptions } from 'object-subscriptions';
import SubscriptionObjectRulesEngineAutomation
    from "./src/targets/subscription-object/SubscriptionObjectRulesEngineAutomation.js";

// getters need a subscribe()
const objectOptions = {
    separator: "/",
    parent: "..",
    current: ".",
};

const object = new NestedObjectWithSubscriptions({
    value: {
        key1: {
            key2: {
                key3: {
                    key4: "value-key4"
                }
            }
        }
    },
    schema: {
        key1: {
            _children: {
                key2: {
                    _children: {
                        key3: {
                            _value: "schema-key3",
                            _children: {
                                key4: {
                                    _value: "schema-key4"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}, objectOptions);

const automationConfig = {
    "condition":{
        "and": {
            "$[value]": {
                "eq": "value-key4"
            },
            "$[schema]../../../_value":"truthy"
        }
    },
    "actions":[
        {
            "action":"set",
            "args":[
                "$[value]../key4b",
                "xxx"
            ]
        }
    ]
}

const automation = new SubscriptionObjectRulesEngineAutomation(
    automationConfig,
    object,
    {
        pathPrefix: "$",
        basePaths: {
            value: ["value", "key1", "key2", "key3", "key4"],
            schema: ["schema", "key1", "_children", "key2", "_children", "key3", "_children", "key4", "_value"]
        }
    }
)
0.1.0

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.3

9 months ago

0.0.1

1 year ago