New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

proto-expand

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proto-expand

The code in this module is used to preprocess a **process definition** (A.K.A. **Protocol**) and expand it to a flattened format.

  • 1.1.5
  • npm
  • Socket score

Version published
Weekly downloads
93
increased by1450%
Maintainers
1
Weekly downloads
 
Created
Source

Proto 'planilla' expander

The code in this module is used to preprocess a process definition (A.K.A. Protocol) and expand it to a flattened format.

Motivation

SWAR version 1.x doesn't support arrays so every value needs to be a scalar. The current workaround is to expand an array as a set of scalar values using a postfix number.

So instead of having an array x you will have n scalars:

x_1 x_2 ... x_n

To be able to do that you need to know n beforehand. This limit the workaround to cases where n is fixed.

This module was created to solve that problem

Payload Management

Given the data to initialize a process in a standard json format, for example:

const initialPayload = {
    "a": 10,
    "b": "xxx",
    "tires": [
        {"pressure": 36},
        {"pressure": 36},
        {"pressure": 40},
        {"pressure": 40}
    ],
    "doors": [
        {"width": 10},
        {"width": 10},
    ]
}

The data can be transformed in a flatten version of the payload for example:

flattenPayload(initialPayload)

Will return

const result = {
    "a": 10,
    "b": "xxx",
    "pressure_1": 36,
    "pressure_2": 36,
    "pressure_3": 40,
    "pressure_4": 40,
    "width_1": 10,
    "width_2": 10
};

Also check payload.ts for additional functions to operate Payloads

Process (a.k.a. Protocol) parsing and expansion

As of today a Protocol is just a set of activities each one containing a set of instructions

Appropriate Classes Activity and Instructions are created to represent this concepts. A protocol definition is just an Array<Activity>

A simple end to end example of expansion will be like this:

// Extract the `Dimensions` from the `Payload`
const dimensions: Dimensions = extractDimensions(payload)

// Parse a Protocol definition (This assume a big string as defined in a proto file today)

const activities: Array<Activity> = parseProtoString("A proto file loaded in a string")

// Expand the variables

const expandedActivities: Array<Activity> = expandAllActivities(activities, dimensions)

// Convert the array back to a big `string`

const bigString = exportToString(expandedActivities)

FAQs

Package last updated on 11 Jun 2024

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc