@hestia-earth/schema-convert 7.6.2 → 7.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/json.d.ts +1 -1
- package/json.js +29 -9
- package/package.json +1 -1
package/json.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface ICSVError {
|
|
|
25
25
|
export declare const throwCSVError: <T extends ICSVError>(error: T) => never;
|
|
26
26
|
export declare const cleanStringValue: (value: string) => string;
|
|
27
27
|
export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, ignoreInternal: boolean, top?: boolean) => any;
|
|
28
|
-
export declare const filterEmptyNode: (schemas: definitions,
|
|
28
|
+
export declare const filterEmptyNode: (schemas: definitions, node: any) => boolean;
|
|
29
29
|
/**
|
|
30
30
|
* Convert CSV to Hestia JSON-LD format.
|
|
31
31
|
*
|
package/json.js
CHANGED
|
@@ -77,6 +77,7 @@ var __spread = (this && this.__spread) || function () {
|
|
|
77
77
|
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
78
78
|
return ar;
|
|
79
79
|
};
|
|
80
|
+
var _a;
|
|
80
81
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
82
|
exports.toJson = exports.filterEmptyNode = exports.formatNode = exports.cleanStringValue = exports.throwCSVError = void 0;
|
|
82
83
|
var csvtojson = require("csvtojson");
|
|
@@ -114,6 +115,11 @@ var compileFullKey = function (key1, key2) {
|
|
|
114
115
|
var joinKey = (key2 || '').startsWith('[') ? '' : '.';
|
|
115
116
|
return [key1, key2].filter(Boolean).join(joinKey);
|
|
116
117
|
};
|
|
118
|
+
var schemaMinKeys = function (schemas, _a) {
|
|
119
|
+
var schemaVersion = _a.schemaVersion, node = __rest(_a, ["schemaVersion"]);
|
|
120
|
+
var schema = node.type ? schemas[node.type] : null;
|
|
121
|
+
return schema ? getDefaultProperties(schema).length + 1 : 1;
|
|
122
|
+
};
|
|
117
123
|
var propertyRequiredValue = function (value, required) {
|
|
118
124
|
var _a;
|
|
119
125
|
var val = typeof value === 'object' && required[0] in value ? value[required[0]] : value;
|
|
@@ -188,7 +194,7 @@ var propertyTypeToValue = {
|
|
|
188
194
|
})() : +value;
|
|
189
195
|
},
|
|
190
196
|
integer: function (value) { return isEmptyCell(value) ? undefined : +value; },
|
|
191
|
-
boolean: function (value) { return value.toLowerCase() === 'true'; },
|
|
197
|
+
boolean: function (value) { return isEmptyCell(value) ? undefined : value.toLowerCase() === 'true'; },
|
|
192
198
|
object: function (value, schemas, _a, _i) {
|
|
193
199
|
var $ref = _a.$ref, required = _a.required;
|
|
194
200
|
return $ref ?
|
|
@@ -277,8 +283,24 @@ var extendDataFromSchema = function (_a, schema, type, ignoreInternal, top) {
|
|
|
277
283
|
}, {}) :
|
|
278
284
|
{})), nodeType(id, type, '@id' in data)), true);
|
|
279
285
|
};
|
|
280
|
-
var
|
|
281
|
-
|
|
286
|
+
var isEmptyValueType = (_a = {},
|
|
287
|
+
_a[schema_1.SchemaType.Term] = function (value) { return !(value['@id'] || value.id || value.name); },
|
|
288
|
+
_a.BlankNode = function (value, schemas) {
|
|
289
|
+
return Object.values(value).filter(function (value) { return !utils_1.isEmpty(value); }).length <= schemaMinKeys(schemas, value);
|
|
290
|
+
},
|
|
291
|
+
_a.array = function (value, schemas) { return value.every(function (val) { return isEmptyValue(val, schemas); }); },
|
|
292
|
+
_a.object = function (value, schemas) {
|
|
293
|
+
return Array.isArray(value) ?
|
|
294
|
+
isEmptyValueType.array(value, schemas) :
|
|
295
|
+
(value['@type'] || value.type) === schema_1.SchemaType.Term ?
|
|
296
|
+
isEmptyValueType[schema_1.SchemaType.Term](value) :
|
|
297
|
+
schema_1.isBlankNode(value) ?
|
|
298
|
+
isEmptyValueType.BlankNode(value, schemas) :
|
|
299
|
+
false;
|
|
300
|
+
},
|
|
301
|
+
_a);
|
|
302
|
+
var isEmptyValue = function (value, schemas) {
|
|
303
|
+
return (typeof value) in isEmptyValueType ? isEmptyValueType[typeof value](value, schemas) : isEmptyCell(value);
|
|
282
304
|
};
|
|
283
305
|
var mapContent = function (schemas, schema, ignoreInternal) { return function (json) {
|
|
284
306
|
return Object.keys(json)
|
|
@@ -292,7 +314,7 @@ var mapContent = function (schemas, schema, ignoreInternal) { return function (j
|
|
|
292
314
|
var newValue = key === VALUE_TYPE_KEY ? '' : propertyInvalidFormat(schema, key, value, function () {
|
|
293
315
|
return Array.isArray(type) ? value : propertyTypeToValue[type](value, schemas, propertyDefinition, ignoreInternal);
|
|
294
316
|
});
|
|
295
|
-
return __assign(__assign(__assign({}, prev), (schema.$id ? { type: schema.title } : {})), (type !== 'null' && isEmptyValue(newValue) ? {} : (_a = {}, _a[key] = newValue, _a)));
|
|
317
|
+
return __assign(__assign(__assign({}, prev), (schema.$id ? { type: schema.title } : {})), (type !== 'null' && isEmptyValue(newValue, schemas) ? {} : (_a = {}, _a[key] = newValue, _a)));
|
|
296
318
|
}, {});
|
|
297
319
|
}; };
|
|
298
320
|
exports.formatNode = function (schemas, type, data, ignoreInternal, top) {
|
|
@@ -301,12 +323,10 @@ exports.formatNode = function (schemas, type, data, ignoreInternal, top) {
|
|
|
301
323
|
var content = mapContent(schemas, schema, ignoreInternal)(data);
|
|
302
324
|
return utils_1.reduceUndefinedValues(__assign({ id: isEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, ignoreInternal, top)), true);
|
|
303
325
|
};
|
|
304
|
-
exports.filterEmptyNode = function (schemas,
|
|
305
|
-
var schemaVersion = _a.schemaVersion, node = __rest(_a, ["schemaVersion"]);
|
|
306
|
-
// make sure defaultProperties are not counted
|
|
326
|
+
exports.filterEmptyNode = function (schemas, node) {
|
|
307
327
|
var schema = node.type ? schemas[node.type] : null;
|
|
308
|
-
|
|
309
|
-
return !utils_1.isEmpty(node,
|
|
328
|
+
// make sure defaultProperties are not counted
|
|
329
|
+
return !!schema && !utils_1.isEmpty(node, schemaMinKeys(schemas, node));
|
|
310
330
|
};
|
|
311
331
|
var convetToNode = function (schemas) { return function (data) {
|
|
312
332
|
return Object.keys(data)
|