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

eidolon

Package Overview
Dependencies
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eidolon - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

lib/util.js

4

Changelog.md

@@ -0,1 +1,5 @@

# 1.5.0 - 2016-03-25
- Handle circular references when dereferencing, by stopping processing and adding in a circular reference origin link relation.
# 1.4.0 - 2016-03-02

@@ -2,0 +6,0 @@

53

lib/dereference.js
// Generated by CoffeeScript 1.10.0
(function() {
var dereference, inherit, ref1, uniqueMembers;
var createLink, dereference, inherit, ref1, uniqueMembers;
ref1 = require('./inherit'), uniqueMembers = ref1.uniqueMembers, inherit = ref1.inherit;
module.exports = dereference = function(root, dataStructures) {
var base, i, item, j, len, member, properties, property, ref, ref2;
createLink = require('./util').createLink;
module.exports = dereference = function(root, dataStructures, known) {
var i, item, j, len, member, newKnown, properties, property, ref, ref2, ref3, ref4;
if (known == null) {
known = [];
}
newKnown = known;
if (known.indexOf(root.element) !== -1 || known.indexOf((ref2 = root.meta) != null ? ref2.id : void 0) !== -1) {
createLink(root, {
relation: 'origin',
href: 'http://refract.link/circular-reference/'
});
return root;
} else if (((ref3 = root.meta) != null ? ref3.id : void 0) != null) {
newKnown = known.concat(root.meta.id);
}
switch (root.element) {

@@ -13,8 +28,8 @@ case 'enum':

root.content = (function() {
var j, len, ref2, results;
ref2 = root.content || [];
var j, len, ref4, results;
ref4 = root.content || [];
results = [];
for (j = 0, len = ref2.length; j < len; j++) {
item = ref2[j];
results.push(dereference(item, dataStructures));
for (j = 0, len = ref4.length; j < len; j++) {
item = ref4[j];
results.push(dereference(item, dataStructures, newKnown));
}

@@ -34,16 +49,10 @@ return results;

ref.content = JSON.parse(JSON.stringify(ref.content));
ref2 = ref.content;
for (j = 0, len = ref2.length; j < len; j++) {
property = ref2[j];
if (property.meta == null) {
property.meta = {};
}
property.meta.ref = member.content.href;
if ((base = property.meta).links == null) {
base.links = [];
}
property.meta.links.push({
ref4 = ref.content;
for (j = 0, len = ref4.length; j < len; j++) {
property = ref4[j];
createLink(property, {
relation: 'origin',
href: 'http://refract.link/included-member/'
});
property.meta.ref = member.content.href;
}

@@ -54,6 +63,6 @@ properties.splice.apply(properties, [i, 1].concat(ref.content));

if (member.content.key) {
member.content.key = dereference(member.content.key, dataStructures);
member.content.key = dereference(member.content.key, dataStructures, newKnown);
}
if (member.content.value) {
member.content.value = dereference(member.content.value, dataStructures);
member.content.value = dereference(member.content.value, dataStructures, newKnown);
}

@@ -66,3 +75,3 @@ }

if (ref) {
return dereference(inherit(ref, root), dataStructures);
return dereference(inherit(ref, root), dataStructures, known.concat(root.element));
} else {

@@ -69,0 +78,0 @@ return root;

@@ -67,2 +67,4 @@ // Generated by CoffeeScript 1.10.0

return obj;
default:
return null;
}

@@ -69,0 +71,0 @@ };

// Generated by CoffeeScript 1.10.0
(function() {
var inherit, uniqueMembers,
var createLink, inherit, uniqueMembers,
hasProp = {}.hasOwnProperty;
createLink = require('./util').createLink;
uniqueMembers = function(content) {

@@ -27,3 +29,3 @@ var i, key, known;

inherit = function(base, element) {
var base1, base2, combined, item, j, k, key, len, len1, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, value;
var combined, item, j, k, key, len, len1, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, value;
combined = JSON.parse(JSON.stringify(base));

@@ -33,6 +35,3 @@ if (((ref = base.meta) != null ? ref.id : void 0) != null) {

combined.meta.ref = base.meta.id;
if ((base1 = combined.meta).links == null) {
base1.links = [];
}
combined.meta.links.push({
createLink(combined, {
relation: 'origin',

@@ -47,13 +46,7 @@ href: 'http://refract.link/inherited/'

if (!(item.meta && item.meta.ref)) {
if (item.meta == null) {
item.meta = {};
}
item.meta.ref = base.meta.id;
if ((base2 = item.meta).links == null) {
base2.links = [];
}
item.meta.links.push({
createLink(item, {
relation: 'origin',
href: 'http://refract.link/inherited-member/'
});
item.meta.ref = base.meta.id;
}

@@ -60,0 +53,0 @@ }

{
"name": "eidolon",
"version": "1.4.0",
"version": "1.5.0",
"description": "Generate JSON or JSON Schema from Refract & MSON data structures",

@@ -5,0 +5,0 @@ "main": "lib/eidolon.js",

@@ -99,2 +99,3 @@ # Eidolon

* One Of properties (the first is always selected)
* Circular references generated as `null`

@@ -110,2 +111,3 @@ ### JSON Schema Generator

* One Of (mutually exclusive) properties
* Circular references generated as an empty schema

@@ -116,3 +118,3 @@ ### Notable Missing Features

* Circular references
* Better support for circular references
* Variable values

@@ -125,2 +127,45 @@ * Variable property names

## Link Relations
Elements may be given [link relations](https://github.com/refractproject/refract-spec/blob/master/refract-spec.md#link-element-element) when dereferencing or processing inheritance that help to describe the origin of a particular element, such as wheterh it was included vs. inherited or whether the element constitutes a circular reference to a previous element in the hierarchy.
### Inheritance
Inheritance link relations come in two forms. The first, called `inherited` is for the element which inherits from another element. The second, called `inherited-member` is for elements of type `member` within an `object` that have been inherited from a parent `object`. MSON example:
```mson
# MyObject (MyBase):
+ id (number)
```
### Inclusion
Inclusion link relations are for elements of type `member` within an `object` that have been included from a parent `object`. MSON example:
```mson
# MyObject
+ Include MyBase
```
### Circular References
Circular reference link relations are for elements whose ancestral chain contains itself, causing a loop. Processing will stop and this link relation will be added so you can detect this case. MSON example:
```mson
# Person
+ address (Address)
# Address
+ owner (Person)
```
### Origins and Link Definitions
Description | Relation | Href
------------------ | -------- | ----
Inherited | `origin` | http://refract.link/inherited/
Inherited member | `origin` | http://refract.link/inherited-member/
Included member | `origin` | http://refract.link/included-member/
Circular reference | `origin` | http://refract.link/circular-reference/
## Reference

@@ -174,5 +219,5 @@

### `eidolon.dereference(input, [dataStructures])`
### `eidolon.dereference(input, [dataStructures], [known])`
Dereference an input element or structure of elements with the given data structures. This will return the same element or structure with resolved references so you do not have to handle inheritance or object includes. Each resolved reference will include the name of the referenced type or mixin in the [`meta.ref` property](https://github.com/refractproject/refract-spec/blob/master/refract-spec.md#properties).
Dereference an input element or structure of elements with the given data structures. This will return the same element or structure with resolved references so you do not have to handle inheritance or object includes. Each resolved reference will include the name of the referenced type or mixin in the [`meta.ref` property](https://github.com/refractproject/refract-spec/blob/master/refract-spec.md#properties). If given, `known` is an array of element names from ancestors of this element, used to detect circular references.

@@ -179,0 +224,0 @@ ```js

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