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

@hestia-earth/schema-convert

Package Overview
Dependencies
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hestia-earth/schema-convert - npm Package Compare versions

Comparing version 15.0.0 to 15.1.0

2

bin/bin-convert-to-csv-pivot.js

@@ -5,3 +5,3 @@ #!/usr/bin/env node

var convert_csv_1 = require("../convert-csv");
convert_csv_1.run(true)
(0, convert_csv_1.run)(true)
.then(function (paths) {

@@ -8,0 +8,0 @@ console.log('Done converting', paths.length, 'files.');

@@ -5,3 +5,3 @@ #!/usr/bin/env node

var convert_csv_1 = require("../convert-csv");
convert_csv_1.run()
(0, convert_csv_1.run)()
.then(function (paths) {

@@ -8,0 +8,0 @@ console.log('Done converting', paths.length, 'files.');

@@ -5,3 +5,3 @@ #!/usr/bin/env node

var convert_json_1 = require("../convert-json");
convert_json_1.run()
(0, convert_json_1.run)()
.then(function (paths) {

@@ -8,0 +8,0 @@ console.log('Done converting', paths.length, 'files.');

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -85,3 +85,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

if (!pivot) return [3 /*break*/, 3];
return [4 /*yield*/, csv_pivot_1.toCsvPivot(nodes)];
return [4 /*yield*/, (0, csv_pivot_1.toCsvPivot)(nodes)];
case 2:

@@ -91,3 +91,3 @@ _a = _b.sent();

case 3:
_a = csv_1.toCsv(nodes);
_a = (0, csv_1.toCsv)(nodes);
_b.label = 4;

@@ -104,3 +104,3 @@ case 4:

}); };
exports.run = function (pivot) {
var run = function (pivot) {
if (pivot === void 0) { pivot = false; }

@@ -118,3 +118,3 @@ return __awaiter(void 0, void 0, void 0, function () {

case 2:
_c = (_d.sent()).map(function (file) { return processFile(path_1.join(path, file), pivot); });
_c = (_d.sent()).map(function (file) { return processFile((0, path_1.join)(path, file), pivot); });
return [3 /*break*/, 4];

@@ -129,1 +129,2 @@ case 3:

};
exports.run = run;

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -82,3 +82,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

content = _a.sent();
return [4 /*yield*/, json_1.toJson(schemas, content)];
return [4 /*yield*/, (0, json_1.toJson)(schemas, content)];
case 2:

@@ -94,3 +94,3 @@ nodes = _a.sent();

}); };
exports.run = function () { return __awaiter(void 0, void 0, void 0, function () {
var run = function () { return __awaiter(void 0, void 0, void 0, function () {
var stat, schemas, _a, _b, _c;

@@ -102,3 +102,3 @@ return __generator(this, function (_d) {

stat = _d.sent();
schemas = json_schema_1.loadSchemas();
schemas = (0, json_schema_1.loadSchemas)();
_b = (_a = Promise).all;

@@ -108,3 +108,3 @@ if (!stat.isDirectory()) return [3 /*break*/, 3];

case 2:
_c = (_d.sent()).map(function (file) { return processFile(schemas, path_1.join(path, file)); });
_c = (_d.sent()).map(function (file) { return processFile(schemas, (0, path_1.join)(path, file)); });
return [3 /*break*/, 4];

@@ -118,1 +118,2 @@ case 3:

}); };
exports.run = run;

@@ -29,5 +29,10 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -38,7 +43,7 @@ Object.defineProperty(exports, "__esModule", { value: true });

var utils_1 = require("./utils");
var omitKeys = __spread([
var omitKeys = __spreadArray([
'@context', 'schemaVersion', 'dataPrivate'
], [
], __read([
'bibliography', 'site', 'cycle', 'impactAssessment', 'defaultSource', 'source'
].flatMap(function (k) { return [k + ".id", k + ".type", k + ".@type"]; }));
].flatMap(function (k) { return ["".concat(k, ".id"), "".concat(k, ".type"), "".concat(k, ".@type")]; })), false);
var convertValue = function (value) {

@@ -51,5 +56,5 @@ return Array.isArray(value) ? value.map(String).join(';') : (typeof value === 'object' ? JSON.stringify(value) : value);

};
exports.toCsv = function (nodes, keys, excludeKeys) {
var toCsv = function (nodes, keys, excludeKeys) {
if (excludeKeys === void 0) { excludeKeys = omitKeys; }
return json_2_csv_1.json2csvAsync(nodes, {
return (0, json_2_csv_1.json2csvAsync)(nodes, {
keys: keys,

@@ -63,2 +68,3 @@ excludeKeys: excludeKeys,

};
exports.toCsv = toCsv;
var arrayKeys = function (node) { return Object.keys(node)

@@ -77,8 +83,8 @@ .filter(function (key) {

var key = termId(term);
var data = utils_1.reduceUndefinedValues(__assign(__assign({}, convertTerm(methodModel)), { value: convertValue(value) }));
var data = (0, utils_1.reduceUndefinedValues)(__assign(__assign({}, convertTerm(methodModel)), { value: convertValue(value) }));
return __assign(__assign({}, prev), (key && Object.keys(data).length ? (_b = {}, _b[key] = (prev[key] || []).concat([data]), _b) : {}));
}, {}); };
exports.pivotNode = function (node) {
var pivotNode = function (node) {
var keys = arrayKeys(node);
return utils_1.reduceUndefinedValues(__assign(__assign({}, utils_1.omit(node, __spread(omitKeys, keys))), (keys.reduce(function (prev, key) {
return (0, utils_1.reduceUndefinedValues)(__assign(__assign({}, (0, utils_1.omit)(node, __spreadArray(__spreadArray([], __read(omitKeys), false), __read(keys), false))), (keys.reduce(function (prev, key) {
var _a;

@@ -89,2 +95,3 @@ var value = pivotList(node[key]);

};
exports.pivotNode = pivotNode;
/**

@@ -96,2 +103,3 @@ * CSV format for data processing.

*/
exports.toCsvPivot = function (nodes) { return exports.toCsv(nodes.map(exports.pivotNode)); };
var toCsvPivot = function (nodes) { return (0, exports.toCsv)(nodes.map(exports.pivotNode)); };
exports.toCsvPivot = toCsvPivot;

@@ -29,5 +29,10 @@ "use strict";

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -51,5 +56,6 @@ Object.defineProperty(exports, "__esModule", { value: true });

*/
exports.headersFromCsv = function (csv) { return csv.split('\n')[0].split(exports.csvColSep); };
var headersFromCsv = function (csv) { return csv.split('\n')[0].split(exports.csvColSep); };
exports.headersFromCsv = headersFromCsv;
var convertValue = {
default: function (value) { return "" + value; },
default: function (value) { return "".concat(value); },
object: function (value) { return value === null

@@ -63,4 +69,4 @@ ? noValue

var convertType = (typeof value) in convertValue ? typeof value : 'default';
var val = ("" + convertValue[convertType](value)).replace(/"/g, '""').replace(/\r/g, '').replace('\n', '');
return val.includes(exports.csvColSep) ? "\"" + val + "\"" : val;
var val = "".concat(convertValue[convertType](value)).replace(/"/g, '""').replace(/\r/g, '').replace('\n', '');
return val.includes(exports.csvColSep) ? "\"".concat(val, "\"") : val;
};

@@ -70,3 +76,3 @@ var skipColumns = ['type', '@type', '@context'];

if (type === void 0) { type = ''; }
return "" + type.substring(0, 1).toLowerCase() + type.substring(1);
return "".concat(type.substring(0, 1).toLowerCase()).concat(type.substring(1));
};

@@ -78,5 +84,5 @@ var getChildrenHeaders = function (key, value, useBrackets) {

var _a = __read(header.split('.')), index = _a[0], rest = _a.slice(1);
return "" + key + (useBrackets ? "[" + index + "]" : "." + index) + "." + rest.join('.');
return "".concat(key).concat(useBrackets ? "[".concat(index, "]") : ".".concat(index), ".").concat(rest.join('.'));
}) :
headers.map(function (header) { return key + "." + header; });
headers.map(function (header) { return "".concat(key, ".").concat(header); });
};

@@ -87,3 +93,3 @@ var getHeaders = function (node, useBrackets) {

var value = node[key];
return utils_1.isExpandable(value) && !isIgnored(value) ? getChildrenHeaders(key, value, useBrackets) : key;
return (0, utils_1.isExpandable)(value) && !isIgnored(value) ? getChildrenHeaders(key, value, useBrackets) : key;
})

@@ -105,3 +111,3 @@ .filter(function (key) { return !skipColumns.includes(key); });

*/
exports.toCsv = function (nodes, includeExising, useBrackets, selectedHeaders) {
var toCsv = function (nodes, includeExising, useBrackets, selectedHeaders) {
if (includeExising === void 0) { includeExising = true; }

@@ -115,3 +121,3 @@ if (useBrackets === void 0) { useBrackets = false; }

var headers = getHeaders(node, useBrackets);
prev[type] = Array.from(new Set(__spread(prev[type], (!includeExising && isIndexedNode(headers) ? [] : headers))));
prev[type] = Array.from(new Set(__spreadArray(__spreadArray([], __read(prev[type]), false), __read((!includeExising && isIndexedNode(headers) ? [] : headers)), false)));
return prev;

@@ -121,3 +127,3 @@ }, {});

selectedHeaders :
Object.keys(headersByType).flatMap(function (type) { return headersByType[type].map(function (key) { return typeToColumnName(type) + "." + key; }); });
Object.keys(headersByType).flatMap(function (type) { return headersByType[type].map(function (key) { return "".concat(typeToColumnName(type), ".").concat(key); }); });
return [

@@ -138,1 +144,2 @@ allHeaders.join(exports.csvColSep),

};
exports.toCsv = toCsv;

@@ -11,3 +11,3 @@ import { SchemaType, JSON as HestiaJson, Cycle, Product, Site, Organisation, Term, ImpactAssessment } from '@hestia-earth/schema';

functionalUnitQuantity?: number;
allocationMethod?: import("../../../dist/@hestia-earth/schema").ImpactAssessmentAllocationMethod;
allocationMethod?: import("@hestia-earth/schema").ImpactAssessmentAllocationMethod;
endDate?: string;

@@ -19,6 +19,6 @@ startDate?: string;

organisation?: Organisation;
source?: import("../../../dist/@hestia-earth/schema").Source;
emissionsResourceUse?: import("../../../dist/@hestia-earth/schema").Indicator[];
impacts?: import("../../../dist/@hestia-earth/schema").Indicator[];
endpoints?: import("../../../dist/@hestia-earth/schema").Indicator[];
source?: import("@hestia-earth/schema").Source;
emissionsResourceUse?: import("@hestia-earth/schema").Indicator[];
impacts?: import("@hestia-earth/schema").Indicator[];
endpoints?: import("@hestia-earth/schema").Indicator[];
dataPrivate?: boolean;

@@ -39,3 +39,3 @@ organic?: boolean;

aggregatedImpactAssessments?: ImpactAssessment[];
aggregatedSources?: import("../../../dist/@hestia-earth/schema").Source[];
aggregatedSources?: import("@hestia-earth/schema").Source[];
type: SchemaType.ImpactAssessment;

@@ -45,2 +45,2 @@ id?: string;

export declare const extendSite: (nodes: HestiaJson<SchemaType>[], site: Site) => Site;
export declare const setDefaultValues: (nodes: HestiaJson<any>[]) => (HestiaJson<SchemaType> | Partial<Partial<HestiaJson<SchemaType.Cycle>>> | Partial<Partial<HestiaJson<SchemaType.ImpactAssessment>>> | Partial<Partial<HestiaJson<SchemaType.Site>>> | Partial<Partial<HestiaJson<SchemaType.Actor>>> | Partial<Partial<HestiaJson<SchemaType.Bibliography>>> | Partial<Partial<HestiaJson<SchemaType.Completeness>>> | Partial<Partial<HestiaJson<SchemaType.Emission>>> | Partial<Partial<HestiaJson<SchemaType.Indicator>>> | Partial<Partial<HestiaJson<SchemaType.Infrastructure>>> | Partial<Partial<HestiaJson<SchemaType.Input>>> | Partial<Partial<HestiaJson<SchemaType.Measurement>>> | Partial<Partial<HestiaJson<SchemaType.Organisation>>> | Partial<Partial<HestiaJson<SchemaType.Practice>>> | Partial<Partial<HestiaJson<SchemaType.Product>>> | Partial<Partial<HestiaJson<SchemaType.Property>>> | Partial<Partial<HestiaJson<SchemaType.Source>>> | Partial<Partial<HestiaJson<SchemaType.Term>>> | Partial<Partial<HestiaJson<SchemaType.Transformation>>> | Partial<Partial<HestiaJson<SchemaType.Transport>>>)[];
export declare const setDefaultValues: (nodes: HestiaJson<any>[]) => (HestiaJson<SchemaType> | Partial<Partial<HestiaJson<SchemaType.Cycle>> | Partial<HestiaJson<SchemaType.ImpactAssessment>> | Partial<HestiaJson<SchemaType.Site>> | Partial<HestiaJson<SchemaType.Actor>> | Partial<HestiaJson<SchemaType.Bibliography>> | Partial<HestiaJson<SchemaType.Completeness>> | Partial<HestiaJson<SchemaType.Emission>> | Partial<HestiaJson<SchemaType.Indicator>> | Partial<HestiaJson<SchemaType.Infrastructure>> | Partial<HestiaJson<SchemaType.Input>> | Partial<HestiaJson<SchemaType.Measurement>> | Partial<HestiaJson<SchemaType.Organisation>> | Partial<HestiaJson<SchemaType.Practice>> | Partial<HestiaJson<SchemaType.Product>> | Partial<HestiaJson<SchemaType.Property>> | Partial<HestiaJson<SchemaType.Source>> | Partial<HestiaJson<SchemaType.Term>> | Partial<HestiaJson<SchemaType.Transformation>> | Partial<HestiaJson<SchemaType.Transport>>>)[];

@@ -28,6 +28,7 @@ "use strict";

].filter(Boolean).join(', '); };
exports.primaryProduct = function (products, defaultValue) {
var primaryProduct = function (products, defaultValue) {
if (defaultValue === void 0) { defaultValue = {}; }
return (products && products.length ? (products.find(function (product) { return product.primary || product.economicValueShare > 50; }) || products[0]) : null) || defaultValue;
};
exports.primaryProduct = primaryProduct;
var defaultName = function (product, country, region, endDate, treatment, description) {

@@ -39,3 +40,3 @@ return [

treatment,
utils_1.ellipsis(description, 30)
(0, utils_1.ellipsis)(description, 30)
].filter(Boolean).join(' - ');

@@ -55,9 +56,10 @@ };

var startDate = _a.startDate, endDate = _a.endDate;
return utils_1.diffInDays(startDate, endDate);
return (0, utils_1.diffInDays)(startDate, endDate);
};
exports.extendCycle = function (nodes, cycle) {
var product = exports.primaryProduct(cycle.products);
var extendCycle = function (nodes, cycle) {
var product = (0, exports.primaryProduct)(cycle.products);
var site = findLinkedNode(nodes, schema_1.SchemaType.Site, cycle.site);
return __assign(__assign(__assign({}, cycle), { name: cycleDefaultName(cycle, site, product) }), (calculateCycleDuration(cycle) ? { cycleDuration: cycleDefaultDuration(cycle) } : {}));
};
exports.extendCycle = extendCycle;
var impactAssessmentDefaultName = function (_a) {

@@ -67,16 +69,18 @@ var product = _a.product, country = _a.country, region = _a.region, endDate = _a.endDate;

};
exports.extendImpactAssessment = function (_n, impactAssessment) { return (__assign(__assign({}, impactAssessment), { name: impactAssessment.name || impactAssessmentDefaultName(impactAssessment) })); };
var extendImpactAssessment = function (_n, impactAssessment) { return (__assign(__assign({}, impactAssessment), { name: impactAssessment.name || impactAssessmentDefaultName(impactAssessment) })); };
exports.extendImpactAssessment = extendImpactAssessment;
var siteDefaultName = function (_a, organisation) {
var siteType = _a.siteType, region = _a.region, country = _a.country, description = _a.description;
return [
siteType ? utils_1.keyToLabel(siteType) : null,
siteType ? (0, utils_1.keyToLabel)(siteType) : null,
organisation === null || organisation === void 0 ? void 0 : organisation.name,
siteLocationName(region, country),
utils_1.ellipsis(description, 30)
(0, utils_1.ellipsis)(description, 30)
].filter(Boolean).join(' - ');
};
exports.extendSite = function (nodes, site) {
var extendSite = function (nodes, site) {
var org = findLinkedNode(nodes, schema_1.SchemaType.Organisation, site.organisation);
return __assign(__assign({}, site), { name: siteDefaultName(site, org) });
};
exports.extendSite = extendSite;
var extendNodeType = (_a = {},

@@ -89,5 +93,6 @@ _a[schema_1.SchemaType.Cycle] = exports.extendCycle,

return node.type in extendNodeType ?
utils_1.reduceUndefinedValues(extendNodeType[node.type](nodes, node), true) :
(0, utils_1.reduceUndefinedValues)(extendNodeType[node.type](nodes, node), true) :
node;
}; };
exports.setDefaultValues = function (nodes) { return nodes.map(extendNode(nodes)); };
var setDefaultValues = function (nodes) { return nodes.map(extendNode(nodes)); };
exports.setDefaultValues = setDefaultValues;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -10,5 +14,6 @@ if (k2 === undefined) k2 = k;

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toCsvPivot = void 0;
var csv_pivot_1 = require("./csv-pivot");

@@ -15,0 +20,0 @@ Object.defineProperty(exports, "toCsvPivot", { enumerable: true, get: function () { return csv_pivot_1.toCsvPivot; } });

@@ -28,3 +28,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -77,5 +77,10 @@ if (y = 0, t) op = [op[0] & 2, t.value];

};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -135,3 +140,3 @@ var _a;

_a.blankNode = isEmptyNode,
_a.array = function (value) { return value.filter(function (v) { return !utils_1.isEmpty(v); }).length === 0; },
_a.array = function (value) { return value.filter(function (v) { return !(0, utils_1.isEmpty)(v); }).length === 0; },
_a.object = function (value, schemas) {

@@ -144,3 +149,3 @@ return value === null

? isEmptyValueType[schema_1.SchemaType.Term](value)
: schema_1.isBlankNode(value)
: (0, schema_1.isBlankNode)(value)
? isEmptyValueType.blankNode(value, schemas)

@@ -167,4 +172,5 @@ : Object.keys(value).length === 0;

};
exports.throwCSVError = function (error) { return throwError(JSON.stringify(error)); };
var schemaNotFoundError = function (schema) { return exports.throwCSVError({
var throwCSVError = function (error) { return throwError(JSON.stringify(error)); };
exports.throwCSVError = throwCSVError;
var schemaNotFoundError = function (schema) { return (0, exports.throwCSVError)({
message: 'schema-not-found',

@@ -176,6 +182,6 @@ schema: schema

var internal = internalProperties({ properties: properties });
var allKeys = Object.keys(properties).filter(function (k) { return !__spread(types_1.excludedDefaultProperties, internal).includes(k); });
var allKeys = Object.keys(properties).filter(function (k) { return !__spreadArray(__spreadArray([], __read(types_1.excludedDefaultProperties), false), __read(internal), false).includes(k); });
return allKeys.filter(function (v) { return levenshtein.get(v, key) <= 3; });
};
var propertyNotFoundError = function (schema, key, value) { return exports.throwCSVError({
var propertyNotFoundError = function (schema, key, value) { return (0, exports.throwCSVError)({
schema: schema.title,

@@ -195,3 +201,3 @@ message: 'property-not-found',

// throw already handled error or throw a generic invalid-format error
return exports.throwCSVError(data ? __assign(__assign({}, data), { key: compileFullKey(key, data.key) }) : {
return (0, exports.throwCSVError)(data ? __assign(__assign({}, data), { key: compileFullKey(key, data.key) }) : {
schema: schema.title,

@@ -214,3 +220,3 @@ message: 'property-invalid-format',

return data ?
exports.throwCSVError(__assign(__assign({}, data), { key: compileFullKey("" + index, data.key) })) :
(0, exports.throwCSVError)(__assign(__assign({}, data), { key: compileFullKey("".concat(index), data.key) })) :
(function () {

@@ -245,3 +251,3 @@ throw err;

return (!allowedGeoJSONTypes.includes(value.type)
? throwError("Invalid GeoJSON \"type\". Allowed values are: " + allowedGeoJSONTypes.join(', '))
? throwError("Invalid GeoJSON \"type\". Allowed values are: ".concat(allowedGeoJSONTypes.join(', ')))
: 'geometries' in value

@@ -265,3 +271,3 @@ ? (value.geometries || []).every(validateGeoJSONGeometryType)

properties: {},
geometry: wkt_1.wktToGeoJSON(value)
geometry: (0, wkt_1.wktToGeoJSON)(value)
}]

@@ -308,7 +314,8 @@ };

? { name: value }
: schema_1.isBlankNode({ type: type })
: (0, schema_1.isBlankNode)({ type: type })
? { term: { name: value } }
: { id: value };
};
exports.cleanStringValue = function (value) { return (value.match(/^[\d]+\.[\d]+\.[\d]+$/) === null ? value.replace(/\.0$/, '') : value).trim(); };
var cleanStringValue = function (value) { return (value.match(/^[\d]+\.[\d]+\.[\d]+$/) === null ? value.replace(/\.0$/, '') : value).trim(); };
exports.cleanStringValue = cleanStringValue;
var propertyTypeToValue = {

@@ -320,5 +327,5 @@ null: function (value) {

}
return isEmptyCell(value) ? null : propertyTypeToValue.auto.apply(propertyTypeToValue, __spread([value], args));
return isEmptyCell(value) ? null : propertyTypeToValue.auto.apply(propertyTypeToValue, __spreadArray([value], __read(args), false));
},
string: function (value) { return exports.cleanStringValue(value || ''); },
string: function (value) { return (0, exports.cleanStringValue)(value || ''); },
number: function (value) {

@@ -337,5 +344,5 @@ return isEmptyCell(value)

? undefined
: utils_1.isBoolean(value)
: (0, utils_1.isBoolean)(value)
? value.toLowerCase() === 'true'
: utils_1.isNumber(value)
: (0, utils_1.isNumber)(value)
? +value === 1 // handle setting 1 or 1.0 as true

@@ -365,7 +372,7 @@ : (function () {

// iris are mapped as {@id: val}
return utils_1.isIri(value)
return (0, utils_1.isIri)(value)
? propertyTypeToValue.required(value, schemas, { required: ['@id'] }, _i)
: utils_1.isBoolean(value)
: (0, utils_1.isBoolean)(value)
? propertyTypeToValue.boolean(value)
: utils_1.isNumber(value)
: (0, utils_1.isNumber)(value)
? propertyTypeToValue.number(value)

@@ -379,7 +386,7 @@ : value === 'null'

var data = propertyRequiredValue(value, required);
return utils_1.isEmpty(data) ? {} : data;
return (0, utils_1.isEmpty)(data) ? {} : data;
},
$ref: function (value, schemas, _a, _i) {
var $ref = _a.$ref;
var schemaType = schema_1.refToSchemaType($ref);
var schemaType = (0, schema_1.refToSchemaType)($ref);
var schema = schemaType ? schemas[schemaType] : undefined;

@@ -391,4 +398,4 @@ var data = schema

: safeParseJSON(value);
var includeDefaults = schema_1.isBlankNode(data) || schemaType === schema_1.SchemaType.Actor; // only blank nodes or actors allowed
return utils_1.isEmpty(data)
var includeDefaults = (0, schema_1.isBlankNode)(data) || schemaType === schema_1.SchemaType.Actor; // only blank nodes or actors allowed
return (0, utils_1.isEmpty)(data)
? {}

@@ -423,3 +430,3 @@ : !!schema

if (ignoreInternal === void 0) { ignoreInternal = false; }
return types_1.defaultProperties(schema)
return (0, types_1.defaultProperties)(schema)
.map(function (property) {

@@ -441,9 +448,9 @@ var def = schema.properties[property];

if (existingNode === void 0) { existingNode = false; }
return type ? (schema_1.isTypeNode(type) ? (existingNode ? { '@type': type } : { id: id, type: type }) : { type: type }) : {};
return type ? ((0, schema_1.isTypeNode)(type) ? (existingNode ? { '@type': type } : { id: id, type: type }) : { type: type }) : {};
};
var extendDataFromSchema = function (_a, schema, type, ignoreInternal, addDefaults) {
var id = _a.id, _t = _a.type, data = __rest(_a, ["id", "type"]);
if (ignoreInternal === void 0) { ignoreInternal = false; }
if (addDefaults === void 0) { addDefaults = false; }
var id = _a.id, _t = _a.type, data = __rest(_a, ["id", "type"]);
return utils_1.reduceUndefinedValues(__assign(__assign(__assign({}, filterProperties(data, ignoreInternal ? [] : internalProperties(schema))), (addDefaults && !('@id' in data) && schema ?
return (0, utils_1.reduceUndefinedValues)(__assign(__assign(__assign({}, filterProperties(data, ignoreInternal ? [] : internalProperties(schema))), (addDefaults && !('@id' in data) && schema ?
getDefaultProperties(schema, data, ignoreInternal).reduce(function (prev, _a) {

@@ -471,9 +478,10 @@ var property = _a.property, defaultValue = _a.defaultValue;

}; };
exports.formatNode = function (schemas, type, data, ignoreInternal, top) {
var formatNode = function (schemas, type, data, ignoreInternal, top) {
if (top === void 0) { top = false; }
var schema = type in schemas ? schemas[type] : schemaNotFoundError(type);
var content = mapContent(schemas, schema, ignoreInternal)(data);
return utils_1.reduceUndefinedValues(__assign({ id: isEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, ignoreInternal, top)), true);
return (0, utils_1.reduceUndefinedValues)(__assign({ id: isEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, ignoreInternal, top)), true);
};
exports.filterEmptyNode = function (schemas, node) {
exports.formatNode = formatNode;
var filterEmptyNode = function (schemas, node) {
var schema = node.type ? schemas[node.type] : null;

@@ -483,7 +491,8 @@ // make sure defaultProperties are not counted

};
exports.filterEmptyNode = filterEmptyNode;
var convetToNode = function (schemas) { return function (data) {
return Object.keys(data)
.filter(utils_1.nonEmptyValue)
.map(function (type) { return exports.formatNode(schemas, schema_1.typeToSchemaType(type), data[type], true, true); })
.filter(function (node) { return exports.filterEmptyNode(schemas, node); });
.map(function (type) { return (0, exports.formatNode)(schemas, (0, schema_1.typeToSchemaType)(type), data[type], true, true); })
.filter(function (node) { return (0, exports.filterEmptyNode)(schemas, node); });
}; };

@@ -497,3 +506,3 @@ /**

*/
exports.toJson = function (schemas, content) { return __awaiter(void 0, void 0, void 0, function () {
var toJson = function (schemas, content) { return __awaiter(void 0, void 0, void 0, function () {
var nodes;

@@ -508,5 +517,6 @@ return __generator(this, function (_a) {

nodes = (_a.sent()).flatMap(convetToNode(schemas));
return [2 /*return*/, default_values_1.setDefaultValues(nodes)];
return [2 /*return*/, (0, default_values_1.setDefaultValues)(nodes)];
}
});
}); };
exports.toJson = toJson;
{
"name": "@hestia-earth/schema-convert",
"version": "15.0.0",
"version": "15.1.0",
"description": "Hestia Schema Converters",

@@ -22,4 +22,4 @@ "main": "index.js",

],
"author": "Guillaume Royer <guillaumeroyer@gmail.com>",
"license": "GPL-3.0-or-later",
"author": "Guillaume Royer <guillaume@hestia.earth>",
"license": "MIT",
"bugs": {

@@ -26,0 +26,0 @@ "url": "https://gitlab.com/hestia-earth/hestia-schema/issues"

export declare const omit: (data: any, keys: string[]) => any;
export declare const isExpandable: (val: any) => number | boolean;
export declare const isExpandable: (val: any) => any;
export declare const isIri: (value?: string) => boolean;

@@ -4,0 +4,0 @@ export declare const isBoolean: (value: string) => boolean;

@@ -16,3 +16,3 @@ "use strict";

var unset = require('lodash.unset');
exports.omit = function (data, keys) {
var omit = function (data, keys) {
var obj = __assign({}, data);

@@ -22,8 +22,13 @@ keys.forEach(function (key) { return unset(obj, key); });

};
exports.isExpandable = function (val) { return !!val && typeof val === 'object' && (Array.isArray(val) ? val.every(exports.isExpandable) : Object.keys(val).length); };
exports.isIri = function (value) { return (value || '').startsWith('http'); };
exports.isBoolean = function (value) { return value.toLowerCase() === 'true' || value.toLowerCase() === 'false'; };
exports.isNumber = function (n) { return !isNaN(parseFloat("" + n)) && isFinite(parseFloat("" + n)); };
exports.omit = omit;
var isExpandable = function (val) { return !!val && typeof val === 'object' && (Array.isArray(val) ? val.every(exports.isExpandable) : Object.keys(val).length); };
exports.isExpandable = isExpandable;
var isIri = function (value) { return (value || '').startsWith('http'); };
exports.isIri = isIri;
var isBoolean = function (value) { return value.toLowerCase() === 'true' || value.toLowerCase() === 'false'; };
exports.isBoolean = isBoolean;
var isNumber = function (n) { return !isNaN(parseFloat("".concat(n))) && isFinite(parseFloat("".concat(n))); };
exports.isNumber = isNumber;
var ignoreKey = function (key) { return !['@type', 'type'].includes(key); };
exports.isEmpty = function (value, minKeys) {
var isEmpty = function (value, minKeys) {
if (minKeys === void 0) { minKeys = 1; }

@@ -38,10 +43,13 @@ return value === null ||

};
exports.nonEmptyValue = function (value) { return !exports.isEmpty(value) && value !== '-'; };
exports.nonEmptyNode = function (node) {
exports.isEmpty = isEmpty;
var nonEmptyValue = function (value) { return !(0, exports.isEmpty)(value) && value !== '-'; };
exports.nonEmptyValue = nonEmptyValue;
var nonEmptyNode = function (node) {
return typeof node === 'object' ?
Object.keys(node)
.filter(function (key) { return ignoreKey(key) && !exports.isEmpty(node[key]); })
.filter(function (key) { return ignoreKey(key) && !(0, exports.isEmpty)(node[key]); })
.length > 0 :
exports.nonEmptyValue(node);
(0, exports.nonEmptyValue)(node);
};
exports.nonEmptyNode = nonEmptyNode;
var isUndefined = function (value, allowNull) {

@@ -51,3 +59,3 @@ return (value === null && !allowNull) ||

};
exports.reduceUndefinedValues = function (obj, allowNull) {
var reduceUndefinedValues = function (obj, allowNull) {
if (allowNull === void 0) { allowNull = false; }

@@ -60,12 +68,16 @@ return Object.keys(obj).reduce(function (prev, key) {

};
exports.ellipsis = function (text, maxlength) {
exports.reduceUndefinedValues = reduceUndefinedValues;
var ellipsis = function (text, maxlength) {
if (text === void 0) { text = ''; }
if (maxlength === void 0) { maxlength = 20; }
return text.length > maxlength ? text.substring(0, maxlength) + "..." : text;
return text.length > maxlength ? "".concat(text.substring(0, maxlength), "...") : text;
};
exports.keyToLabel = function (key) {
return "" + key[0].toUpperCase() + key.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/([_])([a-zA-Z])/g, function (g) { return " " + g[1].toUpperCase(); }).substring(1);
exports.ellipsis = ellipsis;
var keyToLabel = function (key) {
return "".concat(key[0].toUpperCase()).concat(key.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/([_])([a-zA-Z])/g, function (g) { return " ".concat(g[1].toUpperCase()); }).substring(1));
};
exports.diffInDays = function (date1, date2) {
exports.keyToLabel = keyToLabel;
var diffInDays = function (date1, date2) {
return Math.abs(Math.round((new Date(date2).getTime() - new Date(date1).getTime()) / (24 * 60 * 60 * 1000)));
};
exports.diffInDays = diffInDays;
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