@hestia-earth/schema-convert
Advanced tools
Comparing version 14.4.0 to 15.0.0
@@ -75,10 +75,9 @@ "use strict"; | ||
var processFile = function (filepath, pivot) { return __awaiter(void 0, void 0, void 0, function () { | ||
var content, _a, _b, nodes, res, _c, destPath; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
_b = (_a = JSON).parse; | ||
return [4 /*yield*/, readFile(filepath, encoding)]; | ||
var data, content, nodes, res, _a, destPath; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [4 /*yield*/, readFile(filepath, encoding)]; | ||
case 1: | ||
content = _b.apply(_a, [_d.sent()]); | ||
data = _b.sent(); | ||
content = JSON.parse(data.trim()); | ||
nodes = Array.isArray(content) ? content : ('nodes' in content ? content.nodes : [content]); | ||
@@ -88,13 +87,13 @@ if (!pivot) return [3 /*break*/, 3]; | ||
case 2: | ||
_c = _d.sent(); | ||
_a = _b.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
_c = csv_1.toCsv(nodes); | ||
_d.label = 4; | ||
_a = csv_1.toCsv(nodes); | ||
_b.label = 4; | ||
case 4: | ||
res = _c; | ||
res = _a; | ||
destPath = filepath.replace('.jsonld', '.csv').replace('.json', '.csv'); | ||
return [4 /*yield*/, writeFile(destPath, res, encoding)]; | ||
case 5: | ||
_d.sent(); | ||
_b.sent(); | ||
return [2 /*return*/, destPath]; | ||
@@ -101,0 +100,0 @@ } |
36
json.js
@@ -116,2 +116,13 @@ "use strict"; | ||
var nonEmptyCell = function (value) { return !isEmptyCell(value); }; | ||
var isEmptyNode = function (node, schemas) { | ||
var schema = node.type ? schemas[node.type] : null; | ||
var properties = Object.keys(node).filter(function (key) { return !types_1.excludedDefaultProperties.includes(key); }); | ||
var defaultProperties = schema ? getDefaultProperties(schema).map(function (_a) { | ||
var property = _a.property; | ||
return property; | ||
}) : []; | ||
// get the list of properties that do not have a default value | ||
var nonDefaultProperties = properties.filter(function (p) { return !defaultProperties.includes(p); }); | ||
return nonDefaultProperties.length === 0; | ||
}; | ||
var isEmptyValueType = (_a = { | ||
@@ -122,5 +133,3 @@ undefined: function () { return true; }, | ||
_a[schema_1.SchemaType.Term] = function (value) { return !(value['@id'] || value.id || value.name); }, | ||
_a.BlankNode = function (value, schemas) { | ||
return Object.values(value).filter(function (value) { return !utils_1.isEmpty(value); }).length <= schemaMinKeys(schemas, value); | ||
}, | ||
_a.blankNode = isEmptyNode, | ||
_a.array = function (value) { return value.filter(function (v) { return !utils_1.isEmpty(v); }).length === 0; }, | ||
@@ -135,3 +144,3 @@ _a.object = function (value, schemas) { | ||
: schema_1.isBlankNode(value) | ||
? isEmptyValueType.BlankNode(value, schemas) | ||
? isEmptyValueType.blankNode(value, schemas) | ||
: Object.keys(value).length === 0; | ||
@@ -148,7 +157,2 @@ }, | ||
}; | ||
var schemaMinKeys = function (schemas, _a) { | ||
var schemaVersion = _a.schemaVersion, node = __rest(_a, ["schemaVersion"]); | ||
var schema = node.type ? schemas[node.type] : null; | ||
return schema ? getDefaultProperties(schema).length + 1 : 1; | ||
}; | ||
var propertyRequiredValue = function (value, required) { | ||
@@ -171,5 +175,3 @@ var _a; | ||
var internal = internalProperties({ properties: properties }); | ||
var allKeys = Object.keys(properties).filter(function (k) { return !__spread([ | ||
'@type', 'type' | ||
], internal).includes(k); }); | ||
var allKeys = Object.keys(properties).filter(function (k) { return !__spread(types_1.excludedDefaultProperties, internal).includes(k); }); | ||
return allKeys.filter(function (v) { return levenshtein.get(v, key) <= 3; }); | ||
@@ -379,6 +381,6 @@ }; | ||
: safeParseJSON(value); | ||
var includeDefaults = [schema_1.SchemaType.Actor].includes(schemaType); // only nested node allowed | ||
var includeDefaults = schema_1.isBlankNode(data) || schemaType === schema_1.SchemaType.Actor; // only blank nodes or actors allowed | ||
return utils_1.isEmpty(data) | ||
? {} | ||
: schema | ||
: !!schema | ||
? extendDataFromSchema(data, schema, schemaType, _i, includeDefaults) | ||
@@ -436,5 +438,5 @@ : data; | ||
getDefaultProperties(schema, data, ignoreInternal).reduce(function (prev, _a) { | ||
var _b; | ||
var property = _a.property, defaultValue = _a.defaultValue; | ||
return (__assign(__assign({}, prev), (_b = {}, _b[property] = defaultValue, _b))); | ||
prev[property] = defaultValue; | ||
return prev; | ||
}, {}) : | ||
@@ -467,3 +469,3 @@ {})), nodeType(id, type, '@id' in data)), true); | ||
// make sure defaultProperties are not counted | ||
return !!schema && !utils_1.isEmpty(node, schemaMinKeys(schemas, node)); | ||
return !!schema && !isEmptyNode(node, schemas); | ||
}; | ||
@@ -470,0 +472,0 @@ var convetToNode = function (schemas) { return function (data) { |
{ | ||
"name": "@hestia-earth/schema-convert", | ||
"version": "14.4.0", | ||
"version": "15.0.0", | ||
"description": "Hestia Schema Converters", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
61783
1292