Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datatype-expansion

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datatype-expansion - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

2

package.json
{
"name": "datatype-expansion",
"version": "0.2.2",
"version": "0.2.3",
"description": "Utility tool to expand a given RAML type and create a canonical form",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -7,3 +7,3 @@ 'use strict'

const consistencyCheck = require('./util').consistencyCheck
const types = require('./util').types
const isOpaqueType = require('./util').isOpaqueType

@@ -41,3 +41,3 @@ /**

if (types.indexOf(type) !== -1) {
if (isOpaqueType(type)) {
// 2. if `type` is in the set `any boolean datetime datetime-only number integer string null file xml json`

@@ -101,5 +101,8 @@ // 2.1. we return the output of applying the `consistency-check` to the `form`

elem = _.cloneDeep(elem)
// 4.4.3.2.1.2. we add the pair `property-name` `elem-of` to the key `properties` of the cloned`elem`
elem.properties[propName] = elemOf
// 4.4.3.2.1.3. we add the cloned `elem` to the sequence `new-new-accum`
// 4.4.3.2.1.2. we clone `tmp` as `new-value`, except for `of`, and assign the properties of `elem-of` to it
const newValue = Object.assign({}, tmp, elemOf)
delete newValue.anyOf
// 4.4.3.2.1.3. we add the pair `property-name` `new-value` to the key `properties` of the cloned `elem`
elem.properties[propName] = newValue
// 4.4.3.2.1.4. we add the cloned `elem` to the sequence `new-accum`
newAccum.push(elem)

@@ -106,0 +109,0 @@ }

@@ -5,3 +5,3 @@ 'use strict'

const types = require('./util').types
const isOpaqueType = require('./util').isOpaqueType

@@ -70,3 +70,3 @@ /**

// 1.1. if `form` is a RAML built-in data type, we return `(Record "type" form)`
if (types.indexOf(form) !== -1 || form === 'object' || form === 'array') {
if (isOpaqueType(form) || form === 'object' || form === 'array') {
return {type: form}

@@ -76,3 +76,3 @@ }

if (form.endsWith('?')) {
if (types.indexOf(form.replace('?', '')) !== -1) {
if (isOpaqueType(form.replace('?', ''))) {
return expandUnion({

@@ -79,0 +79,0 @@ type: 'union',

'use strict'
const _ = require('lodash')
const types = require('./util').types
const isOpaqueType = require('./util').isOpaqueType
const consistencyCheck = require('./util').consistencyCheck

@@ -134,5 +132,5 @@

// 2. if `super-type` and `sub-type` have the same value and the value is in the set `any boolean datetime datetime-only number integer string null file xml json"`
if (superType === subType && types.indexOf(superType) !== -1) {
if (superType === subType && isOpaqueType(superType)) {
// 2.1. we initialize the variable `computed` to the record with property `type` having the common `super-type` and `sub-type` value
const computed = _.cloneDeep(sup)
const computed = Object.assign({}, sup, sub)
for (let restriction in restrictions) {

@@ -155,10 +153,11 @@ if (sup[restriction] !== undefined && sub[restriction] !== undefined) {

const other = superType === 'any' ? sub : sup
const computed = Object.assign({}, sup, sub)
computed.type = other.type
for (let restriction in restrictions) {
if (anytype[restriction] !== undefined && other[restriction] !== undefined) {
// 3.1. for each restriction in the `any` type and in the other type, we compute the narrower restriction and we re-assign it to the other type
other[restriction] = restrictions[restriction](anytype[restriction], other[restriction])
computed[restriction] = restrictions[restriction](anytype[restriction], other[restriction])
} else if (anytype[restriction] !== undefined) {
// 3.2. for each restriction only in `any` we assign it directly to the other type
other[restriction] = anytype[restriction]
computed[restriction] = anytype[restriction]
}

@@ -168,3 +167,3 @@ }

// 3.3. we return the output of computing the algorithm `consistency-check` on the other type
return consistencyCheck(other)
return consistencyCheck(computed)
}

@@ -174,13 +173,14 @@

if (superType === 'number' && subType === 'integer') {
const computed = Object.assign({}, sup, sub)
for (let restriction in restrictions) {
if (sup[restriction] !== undefined && sub[restriction] !== undefined) {
// 4.1. for each restriction in the `number` type and in the `integer` type, we compute the narrower restriction and we re-assign it to the `integer` type
sub[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
computed[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
} else if (sup[restriction] !== undefined) {
// 4.2. for each restriction only in `number` we assign it directly to the `integer` type
sub[restriction] = sup[restriction]
computed[restriction] = sup[restriction]
}
}
// 4.3. we return the output of computing the algorithm `consistency-check` on the `integer` type
return consistencyCheck(sub)
return consistencyCheck(computed)
}

@@ -190,5 +190,6 @@

if (superType === 'array' && subType === 'array') {
const computed = Object.assign({}, sup, sub)
// 5.1. we initialize the variable `min-items` with the output of applying this algorithm to the values for the key `items` in `super` and `sub`
// 5.2. we re-assign the value of the property `items` in `sub` with the value of `min-items`
sub.items = minType(sup.items, sub.items)
computed.items = minType(sup.items, sub.items)

@@ -198,10 +199,10 @@ for (let restriction in restrictions) {

// 4.3. for each restriction in `super` and `sub` we compute the narrower restriction and we assign it in `sub`
sub[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
computed[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
} else if (sup[restriction] !== undefined) {
// 4.4. for each restriction only in `super` we assign it directly to `sub`
sub[restriction] = sup[restriction]
computed[restriction] = sup[restriction]
}
}
// 4.5. we return the output of computing the algorithm `consistency-check` on `sub`
return consistencyCheck(sub)
return consistencyCheck(computed)
}

@@ -211,8 +212,11 @@

if (superType === 'object' && subType === 'object') {
const computed = Object.assign({}, sup, sub)
// 6.1. for initialize the variable `common-props` to the empty record
const commonProps = {}
let superProps = Object.keys(sup.properties || {})
let subProps = Object.keys(sub.properties || {})
const superProps = sup.properties || {}
const subProps = sub.properties || {}
const superPropKeys = Object.keys(superProps)
const subPropKeys = Object.keys(subProps)
// 6.2. for each key in the `properties` value `sub` that is also present in the `properties` value of `super`
superProps.filter(p => subProps.indexOf(p) !== -1).forEach((p) => {
superPropKeys.filter(p => p in subProps).forEach((p) => {
// 6.2.1. we initialize the variable `tmp` with the output of applying the algorithm to the value for the common property in `super` and in `sub`

@@ -224,6 +228,6 @@ // 6.2.2. we assign the computed value using the name of the common property as the key in the `common-props` record

// 6.3. for each pair `property-name` `property-value` only in either `super` or `sub` we add it to the record `common-props`
superProps.filter(p => !(p in sub)).forEach((p) => {
superPropKeys.filter(p => !(p in subProps)).forEach((p) => {
commonProps[p] = sup.properties[p]
})
subProps.filter(p => !(p in sub)).forEach((p) => {
subPropKeys.filter(p => !(p in superProps)).forEach((p) => {
commonProps[p] = sub.properties[p]

@@ -235,6 +239,6 @@ })

// 6.4. for each restriction in `super` and `sub` we compute the narrower restriction and we assign it in `sub`
sub[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
computed[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
} else if (sup[restriction] !== undefined) {
// 6.5. for each restriction only in `super` we assign it directly to `sub`
sub[restriction] = sup[restriction]
computed[restriction] = sup[restriction]
}

@@ -244,5 +248,5 @@ }

// 6.6. we assign the value of the key `properties` in `sub` to be `common-props`
sub.properties = commonProps
computed.properties = commonProps
// 6.7. we return the output of computing the algorithm `consistency-check` on `sub`
return consistencyCheck(sub)
return consistencyCheck(computed)
}

@@ -252,2 +256,3 @@

if (superType === 'union' && subType === 'union') {
const computed = Object.assign({}, sup, sub)
// 7.1. we initialize the variable `accum` to the empty sequence

@@ -273,6 +278,6 @@ const accum = []

// 7.3. for each restriction in `super` and `sub` we compute the narrower restriction and we assign it in `sub`
sub[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
computed[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
} else if (sup[restriction] !== undefined) {
// 7.4. for each restriction only in `super` we assign it directly to `sub`
sub[restriction] = sup[restriction]
computed[restriction] = sup[restriction]
}

@@ -282,5 +287,5 @@ }

// 7.5. we assign the value of the key `of` in `sub` to be `accum`
sub.anyOf = accum
computed.anyOf = accum
// 7.6. we return the output of computing the algorithm `consistency-check` on `sub`
return consistencyCheck(sub)
return consistencyCheck(computed)
}

@@ -290,5 +295,7 @@

if (superType === 'union' && subType !== 'union') {
const computed = Object.assign({}, sup, sub)
computed.type = superType
// 8.1. for each value `i` `elem-super` in the property `of` of `super`
// 8.1.1. we replace `i` in `of` with the output of applying this algorithm to `elem-super` and `sub`
sup.anyOf = sup.anyOf.map(elem => minType(elem, sub))
computed.anyOf = sup.anyOf.map(elem => minType(elem, sub))

@@ -298,6 +305,6 @@ for (let restriction in restrictions) {

// 8.2. for each restriction in `super` and `sub` we compute the narrower restriction and we assign it in `sub`
sup[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
computed[restriction] = restrictions[restriction](sup[restriction], sub[restriction])
} else if (sub[restriction] !== undefined) {
// 8.3. for each restriction only in `super` we assign it directly to `sub`
sup[restriction] = sub[restriction]
computed[restriction] = sub[restriction]
}

@@ -307,3 +314,3 @@ }

// 8.4. we return the output of computing the algorithm `consistency-check` on `super`
return consistencyCheck(sup)
return consistencyCheck(computed)
}

@@ -310,0 +317,0 @@

'use strict'
// is this correct?
module.exports.types = [
const _ = require('lodash')
// scalar types + [any, xml, json], excludes [array, object, union]
const opaqueTypes = _.keyBy([
'any',

@@ -18,4 +20,8 @@ 'boolean',

'json'
]
])
module.exports.isOpaqueType = function isOpaqueType (type) {
return type in opaqueTypes
}
/**

@@ -22,0 +28,0 @@ * Iterates through all the possible restriction constraints defined in the RAML specification and checks that the constraints hold for the provided type using custom logic.

@@ -916,3 +916,189 @@ 'use strict'

additionalProperties: true
},
Named: {
type: 'object',
properties: {
name: {
type: 'string',
required: true
}
},
additionalProperties: true
},
InheritNamedWithNameAttribute: {
name: 'InheritNamedWithNameAttribute',
type: 'object',
properties: {
name: {
type: 'string',
required: true
},
other: {
type: 'string',
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsWithTypeArray: {
type: 'object',
properties: {
name: {
type: 'string',
required: true,
displayName: 'name'
}
},
additionalProperties: true
},
ExtraPropAttrsInTypeArray: {
type: 'object',
properties: {
name: {
type: 'string',
required: true,
displayName: 'name'
}
},
additionalProperties: true
},
ExtraPropAttrsAnyOther: {
type: 'object',
properties: {
prop: {
type: 'number',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsNumberInteger: {
type: 'object',
properties: {
prop: {
type: 'integer',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsArrays: {
type: 'object',
properties: {
prop: {
type: 'array',
items: {
type: 'any'
},
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsObjects: {
type: 'object',
properties: {
prop: {
type: 'object',
properties: {},
additionalProperties: true,
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsUnions: {
type: 'union',
anyOf: [{
type: 'object',
properties: {
prop: {
type: 'any',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
}, {
type: 'object',
properties: {
prop: {
type: 'integer',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
}, {
type: 'object',
properties: {
prop: {
type: 'number',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
}, {
type: 'object',
properties: {
prop: {
type: 'integer',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
}],
additionalProperties: true
},
ExtraPropAttrsSuperUnion: {
type: 'union',
anyOf: [{
type: 'object',
properties: {
prop: {
type: 'integer',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
}, {
type: 'object',
properties: {
prop: {
type: 'integer',
extra1: 'a',
extra2: 'b',
common: 'c',
required: true
}
},
additionalProperties: true
}],
additionalProperties: true
}
}

@@ -1057,3 +1057,178 @@ 'use strict'

additionalProperties: true
},
Named: {
type: 'object',
properties: {
name: {
type: 'string',
required: true
}
},
additionalProperties: true
},
InheritNamedWithNameAttribute: {
name: 'InheritNamedWithNameAttribute',
type: {
type: 'object',
properties: {
name: {
type: 'string',
required: true
}
},
additionalProperties: true
},
properties: {
other: {
type: 'string',
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsWithTypeArray: {
type: 'object',
properties: {
name: {
type: [{
type: 'string'
}],
required: true,
displayName: 'name'
}
},
additionalProperties: true
},
ExtraPropAttrsInTypeArray: {
type: 'object',
properties: {
name: {
type: [{
type: 'string',
displayName: 'name'
}],
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsAnyOther: {
type: 'object',
properties: {
prop: {
type: [{
type: 'any',
extra1: 'a',
common: 'c'
}, {
type: 'number',
extra2: 'b',
common: 'd'
}],
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsNumberInteger: {
type: 'object',
properties: {
prop: {
type: [{
type: 'integer',
extra1: 'a',
common: 'c'
}, {
type: 'number',
extra2: 'b',
common: 'd'
}],
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsArrays: {
type: 'object',
properties: {
prop: {
type: [{
type: 'array',
items: {
type: 'any'
},
extra1: 'a',
common: 'c'
}, {
type: 'array',
items: {
type: 'any'
},
extra2: 'b',
common: 'd'
}],
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsObjects: {
type: 'object',
properties: {
prop: {
type: [{
type: 'object',
additionalProperties: true,
extra1: 'a',
common: 'c'
}, {
type: 'object',
additionalProperties: true,
extra2: 'b',
common: 'd'
}],
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsUnions: {
type: 'object',
properties: {
prop: {
type: [{
type: 'union',
anyOf: [{ type: 'any' }, { type: 'integer' }],
extra1: 'a',
common: 'c'
}, {
type: 'union',
anyOf: [{ type: 'any' }, { type: 'number' }],
extra2: 'b',
common: 'd'
}],
required: true
}
},
additionalProperties: true
},
ExtraPropAttrsSuperUnion: {
type: 'object',
properties: {
prop: {
type: [{
type: 'integer',
extra1: 'a',
common: 'c'
}, {
type: 'union',
anyOf: [{ type: 'any' }, { type: 'number' }],
extra2: 'b',
common: 'd'
}],
required: true
}
},
additionalProperties: true
}
}

@@ -451,3 +451,123 @@ 'use strict'

maxItems: 3
},
Named: {
properties: {
name: 'string'
}
},
InheritNamedWithNameAttribute: {
name: 'InheritNamedWithNameAttribute',
type: 'Named',
properties: {
other: 'string'
}
},
ExtraPropAttrsWithTypeArray: {
properties: {
name: {
type: ['string'],
displayName: 'name'
}
}
},
ExtraPropAttrsInTypeArray: {
properties: {
name: {
type: [{
type: 'string',
displayName: 'name'
}]
}
}
},
ExtraPropAttrsAnyOther: {
properties: {
prop: {
type: [{
type: 'any',
extra1: 'a',
common: 'c'
}, {
type: 'number',
extra2: 'b',
common: 'd'
}]
}
}
},
ExtraPropAttrsNumberInteger: {
properties: {
prop: {
type: [{
type: 'integer',
extra1: 'a',
common: 'c'
}, {
type: 'number',
extra2: 'b',
common: 'd'
}]
}
}
},
ExtraPropAttrsArrays: {
properties: {
prop: {
type: [{
type: 'array',
extra1: 'a',
common: 'c'
}, {
type: 'array',
extra2: 'b',
common: 'd'
}]
}
}
},
ExtraPropAttrsObjects: {
properties: {
prop: {
type: [{
type: 'object',
extra1: 'a',
common: 'c'
}, {
type: 'object',
extra2: 'b',
common: 'd'
}]
}
}
},
ExtraPropAttrsUnions: {
properties: {
prop: {
type: [{
type: 'any | integer',
extra1: 'a',
common: 'c'
}, {
type: 'any | number',
extra2: 'b',
common: 'd'
}]
}
}
},
ExtraPropAttrsSuperUnion: {
properties: {
prop: {
type: [{
type: 'integer',
extra1: 'a',
common: 'c'
}, {
type: 'any | number',
extra2: 'b',
common: 'd'
}]
}
}
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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