Comparing version 1.0.0 to 1.1.0
@@ -0,3 +1,7 @@ | ||
# 1.1.0 - 2016-02-01 | ||
- Expose a `dereference` function. Both the example and schema generators now use this internally to simplify their specific code. | ||
# 1.0.0 - 2016-01-29 | ||
- Initial release. |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var Eidolon, generateExample, generateSchema, inherit; | ||
var Eidolon, dereference, generateExample, generateSchema, inherit; | ||
dereference = require('./dereference'); | ||
generateExample = require('./example'); | ||
@@ -16,2 +18,6 @@ | ||
Eidolon.prototype.dereference = function(element) { | ||
return dereference(element, this.structures); | ||
}; | ||
Eidolon.prototype.example = function(element) { | ||
@@ -31,2 +37,3 @@ return generateExample(element, this.structures); | ||
Eidolon: Eidolon, | ||
dereference: dereference, | ||
example: generateExample, | ||
@@ -33,0 +40,0 @@ inherit: inherit, |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var defaultValue, generateExample, inherit; | ||
var defaultValue, dereference, generateExample; | ||
inherit = require('./inherit'); | ||
dereference = require('./dereference'); | ||
@@ -18,4 +18,4 @@ defaultValue = function(type) { | ||
module.exports = generateExample = function(root, dataStructures) { | ||
var i, item, j, key, len, member, obj, properties, ref, ref1, ref2, results; | ||
generateExample = function(root) { | ||
var i, item, j, key, len, len1, member, obj, ref, ref1, ref2, results; | ||
switch (root.element) { | ||
@@ -28,3 +28,3 @@ case 'boolean': | ||
} else { | ||
if (((ref1 = root.attributes) != null ? ref1["default"] : void 0) !== void 0) { | ||
if (((ref = root.attributes) != null ? ref["default"] : void 0) !== void 0) { | ||
return root.attributes["default"]; | ||
@@ -37,9 +37,9 @@ } else { | ||
case 'enum': | ||
return generateExample(root.content[0], dataStructures); | ||
return generateExample(root.content[0]); | ||
case 'array': | ||
ref2 = root.content || []; | ||
ref1 = root.content || []; | ||
results = []; | ||
for (j = 0, len = ref2.length; j < len; j++) { | ||
item = ref2[j]; | ||
results.push(generateExample(item, dataStructures)); | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
item = ref1[i]; | ||
results.push(generateExample(item)); | ||
} | ||
@@ -50,27 +50,19 @@ return results; | ||
obj = {}; | ||
properties = root.content.slice(0); | ||
i = 0; | ||
while (i < properties.length) { | ||
member = properties[i]; | ||
i++; | ||
if (member.element === 'ref') { | ||
ref = dataStructures[member.content.href]; | ||
i--; | ||
properties.splice.apply(properties, [i, 1].concat(ref.content)); | ||
continue; | ||
} else if (member.element === 'select') { | ||
ref2 = root.content; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
member = ref2[j]; | ||
if (member.element === 'select') { | ||
member = member.content[0].content[0]; | ||
} | ||
key = member.content.key.content; | ||
obj[key] = member.content.value ? generateExample(member.content.value, dataStructures) : defaultValue('string'); | ||
obj[key] = member.content.value ? generateExample(member.content.value) : defaultValue('string'); | ||
} | ||
return obj; | ||
default: | ||
ref = dataStructures[root.element]; | ||
if (ref) { | ||
return generateExample(inherit(ref, root), dataStructures); | ||
} | ||
} | ||
}; | ||
module.exports = function(root, dataStructures) { | ||
return generateExample(dereference(root, dataStructures)); | ||
}; | ||
}).call(this); |
@@ -63,3 +63,5 @@ // Generated by CoffeeScript 1.10.0 | ||
} else { | ||
combined.content = element.content; | ||
if (element.content != null) { | ||
combined.content = element.content; | ||
} | ||
} | ||
@@ -66,0 +68,0 @@ } |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var deepEqual, generateSchema, inherit; | ||
var deepEqual, dereference, generateSchema; | ||
deepEqual = require('assert').deepEqual; | ||
inherit = require('./inherit'); | ||
dereference = require('./dereference'); | ||
module.exports = generateSchema = function(root, dataStructures, top) { | ||
var error, exclusive, i, item, items, j, k, key, len, len1, len2, m, member, option, optionSchema, prop, properties, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, required, schema, typeAttr; | ||
generateSchema = function(root, top) { | ||
var error, exclusive, i, item, items, j, k, key, len, len1, len2, len3, m, member, option, optionSchema, prop, properties, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, required, schema, typeAttr; | ||
if (top == null) { | ||
@@ -23,3 +23,3 @@ top = true; | ||
schema.type = root.element; | ||
if (((ref1 = root.attributes) != null ? ref1["default"] : void 0) != null) { | ||
if (((ref = root.attributes) != null ? ref["default"] : void 0) != null) { | ||
schema["default"] = root.attributes["default"]; | ||
@@ -30,5 +30,5 @@ } | ||
schema["enum"] = []; | ||
ref2 = root.content || []; | ||
for (j = 0, len = ref2.length; j < len; j++) { | ||
item = ref2[j]; | ||
ref1 = root.content || []; | ||
for (i = 0, len = ref1.length; i < len; i++) { | ||
item = ref1[i]; | ||
schema["enum"].push(item.content); | ||
@@ -40,6 +40,6 @@ } | ||
items = []; | ||
ref3 = root.content || []; | ||
for (k = 0, len1 = ref3.length; k < len1; k++) { | ||
item = ref3[k]; | ||
items.push(generateSchema(item, dataStructures, false)); | ||
ref2 = root.content || []; | ||
for (j = 0, len1 = ref2.length; j < len1; j++) { | ||
item = ref2[j]; | ||
items.push(generateSchema(item, false)); | ||
} | ||
@@ -66,17 +66,11 @@ if (items.length === 1) { | ||
properties = root.content.slice(0); | ||
i = 0; | ||
while (i < properties.length) { | ||
member = properties[i]; | ||
i++; | ||
if (member.element === 'ref') { | ||
ref = dataStructures[member.content.href]; | ||
i--; | ||
properties.splice.apply(properties, [i, 1].concat(ref.content)); | ||
continue; | ||
} else if (member.element === 'select') { | ||
ref3 = root.content; | ||
for (k = 0, len2 = ref3.length; k < len2; k++) { | ||
member = ref3[k]; | ||
if (member.element === 'select') { | ||
exclusive = []; | ||
ref4 = member.content; | ||
for (m = 0, len2 = ref4.length; m < len2; m++) { | ||
for (m = 0, len3 = ref4.length; m < len3; m++) { | ||
option = ref4[m]; | ||
optionSchema = generateSchema(option, dataStructures, false); | ||
optionSchema = generateSchema(option, false); | ||
ref5 = optionSchema.properties; | ||
@@ -100,3 +94,3 @@ for (key in ref5) { | ||
key = member.content.key.content; | ||
schema.properties[key] = member.content.value ? generateSchema(member.content.value, dataStructures, false) : { | ||
schema.properties[key] = member.content.value ? generateSchema(member.content.value, false) : { | ||
type: 'string' | ||
@@ -122,8 +116,2 @@ }; | ||
} | ||
break; | ||
default: | ||
ref = dataStructures[root.element]; | ||
if (ref) { | ||
schema = generateSchema(inherit(ref, root), dataStructures, top); | ||
} | ||
} | ||
@@ -142,2 +130,6 @@ if (((ref8 = root.meta) != null ? ref8.description : void 0) != null) { | ||
module.exports = function(root, dataStructures) { | ||
return generateSchema(dereference(root, dataStructures)); | ||
}; | ||
}).call(this); |
{ | ||
"name": "eidolon", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Generate JSON or JSON Schema from Refract & MSON data structures", | ||
@@ -5,0 +5,0 @@ "main": "lib/eidolon.js", |
@@ -136,2 +136,3 @@ # Eidolon | ||
let schema = instance.schema(input); | ||
let dereferenced = instance.dereference(input); | ||
``` | ||
@@ -161,2 +162,28 @@ | ||
### `eidolon.dereference(input, [dataStructures])` | ||
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. | ||
```js | ||
import eidolon from 'eidolon'; | ||
const input = { | ||
element: 'MyString' | ||
}; | ||
const dataStructures = { | ||
MyElement: { | ||
element: 'string', | ||
meta: { | ||
id: 'MyString' | ||
}, | ||
content: 'Hello, world!' | ||
} | ||
}; | ||
let dereferenced = eidolon.dereference(input, dataStructures); | ||
console.log(dereferenced.element); // => 'string' | ||
console.log(dereferenced.content); // => 'Hello, world!' | ||
``` | ||
### `eidolon.inherit(base, element)` | ||
@@ -163,0 +190,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18002
10
331
231