Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
datatype-expansion
Advanced tools
Utility tool to expand a given RAML type and create a canonical form
Often, tools need the full expansion of RAML data types where there are no references. This module gives you a utility tool to expand a given type and create a canonical form.
npm install datatype-expansion
The RAML expanded form for a RAML type, resolves references and fills missing information to compute a fully expanded representation of the type. The form and the algorithm to compute is documented here.
The Node.js interface for the library offers the expandedForm
function to compute the expanded form.
It accepts an in-memory JSON representation of the type, the types mapping and an optional callback function or options object.
It returns the canonical form or an exception. The following options are supported:
callback
: Provides a callback function via the options object.topLevel
(default: any
): The default RAML type to use when base type is not explicit and cannot be inferred.
It can be any
or string
, depending on whether the type comes from the body
of a RAML service.trackOriginalType
(default: false
): Controls whether expansion should track the original type in a property called originalType
when expanding a type reference.const tools = require('datatype-expansion');
const typesContext = {
Song: {
properties: {
title: 'string',
length: 'number'
}
},
Album: {
properties: {
title: 'string',
songs: 'Songs.Song[]'
}
}
};
const expanded = tools.expandedForm(typesContext['Album'], typesContext)
console.log(JSON.stringify(expanded,null,2));
const tools = require('datatype-expansion');
const typesContext = {
Song: {
properties: {
title: 'string',
length: 'number'
}
},
Album: {
properties: {
title: 'string',
songs: 'Songs.Song[]'
}
}
};
tools.expandedForm(typesContext['Album'], typesContext, function(err, expanded) {
// expanded contains the computed expanded form
console.log(JSON.stringify(expanded,null,2));
});
{
"properties": {
"title": {
"type": "string",
"required": true
},
"songs": {
"type": "array",
"items": {
"properties": {
"title": {
"type": "string",
"required": true
},
"length": {
"type": "number",
"required": true
}
},
"additionalProperties": true,
"type": "object",
"required": true
},
"required": true
}
},
"additionalProperties": true,
"type": "object",
"required": true
}
The canonical form computes inheritance and pushes unions to the top level of the type structure of an expanded RAML type. It is described in the documentation section of this repository.
The Node.js version of the canonical form function is defined in the canonicalForm
function of the library module.
It accepts a JSON in-memory representation of an expanded RAML type and an optional callback function or options object. It returns the canonical form or an exception. The following options are supported:
callback
: Provides a callback function via the options object.hoistUnions
(default: true
): Controls whether canonicalization should hoist unions to the top level of the type form. When enabled, union
can only appear as the top-level type, and the associated type alternatives are the permutation of any nested unions in the input type. When disabled, unions remain nested.const tools = require('datatype-expansion');
const typesContext = {
SimpleUnion: {
properties: {
a: 'string',
b: 'number | string'
}
},
};
const expanded = tools.expandedForm(typesContext['SimpleUnion'], typesContext)
const canonical = tools.canonicalForm(expanded)
console.log(JSON.stringify(canonical,null,2));
const tools = require('datatype-expansion');
const typesContext = {
SimpleUnion: {
properties: {
a: 'string',
b: 'number | string'
}
},
};
tools.expandedForm(typesContext['Songs.Album'], typesContext, function(err, expanded) {
tools.canonicalForm(expanded, function(err, canonical) {
// canonical contains the computed canonical form
console.log(canonical);
});
});
{
"type": "union",
"additionalProperties": true,
"anyOf": [
{
"properties": {
"a": {
"type": "string",
"required": true
},
"b": {
"type": "number",
"required": true
}
},
"type": "object",
"additionalProperties": true
},
{
"properties": {
"a": {
"type": "string",
"required": true
},
"b": {
"type": "string",
"required": true
}
},
"type": "object",
"additionalProperties": true
}
]
}
Include it via unpkg ( if you don't use a bundler like webpack )
<script src="https://unpkg.com/datatype-expansion"></script>
It gets exported as expansion
expansion.expandedForm('string', {})
Tests for the library can be run using:
$ npm run test
FAQs
Utility tool to expand a given RAML type and create a canonical form
We found that datatype-expansion demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.