@hestia-earth/schema-convert 32.0.2 → 32.1.0
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 +3 -5
- package/json.js +5 -4
- package/package.json +1 -1
package/json.d.ts
CHANGED
|
@@ -43,16 +43,14 @@ interface IConversionParams {
|
|
|
43
43
|
* Add default values (see `default: true` in the schema). Defaults to `true`.
|
|
44
44
|
*/
|
|
45
45
|
addDefaults?: boolean;
|
|
46
|
-
}
|
|
47
|
-
interface IExtendedConversionParams extends IConversionParams {
|
|
48
46
|
/**
|
|
49
|
-
* If it's an existing Node on HESTIA, i.e. the `@id` is used instead of `id`.
|
|
47
|
+
* If it's an existing Node on HESTIA, i.e. the `@type` / `@id` is used instead of ``type / `id`.
|
|
50
48
|
*/
|
|
51
|
-
|
|
49
|
+
convertToExistingNodes?: boolean;
|
|
52
50
|
}
|
|
53
51
|
export declare const throwCSVErrors: <T extends ICSVError>(errors: T[]) => never;
|
|
54
52
|
export declare const cleanStringValue: (value: string) => string;
|
|
55
|
-
export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, params?:
|
|
53
|
+
export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, params?: IConversionParams) => any;
|
|
56
54
|
export declare const filterEmptyNode: (schemas: definitions, node: any) => boolean;
|
|
57
55
|
/**
|
|
58
56
|
* Convert CSV to HESTIA JSON-LD format.
|
package/json.js
CHANGED
|
@@ -497,14 +497,14 @@ var nodeType = function (id, type, existingNode) {
|
|
|
497
497
|
};
|
|
498
498
|
var extendDataFromSchema = function (_a, schema, type, _b) {
|
|
499
499
|
var id = _a.id, _t = _a.type, data = __rest(_a, ["id", "type"]);
|
|
500
|
-
var _c = _b === void 0 ? {} : _b, ignoreInternal = _c.ignoreInternal, addDefaults = _c.addDefaults,
|
|
500
|
+
var _c = _b === void 0 ? {} : _b, ignoreInternal = _c.ignoreInternal, addDefaults = _c.addDefaults, convertToExistingNodes = _c.convertToExistingNodes;
|
|
501
501
|
return (0, utils_1.reduceUndefinedValues)(__assign(__assign(__assign({}, filterProperties(data, ignoreInternal ? [] : internalProperties(schema))), (addDefaults && !('@id' in data) && schema
|
|
502
502
|
? getDefaultProperties(schema, data, ignoreInternal).reduce(function (prev, _a) {
|
|
503
503
|
var property = _a.property, defaultValue = _a.defaultValue;
|
|
504
504
|
prev[property] = defaultValue;
|
|
505
505
|
return prev;
|
|
506
506
|
}, {})
|
|
507
|
-
: {})), nodeType(id, type, '@id' in data ||
|
|
507
|
+
: {})), nodeType(id, type, '@id' in data || convertToExistingNodes)), true);
|
|
508
508
|
};
|
|
509
509
|
var validateArrayType = function (schema, def, key, value) {
|
|
510
510
|
return typeof value !== 'object' ||
|
|
@@ -565,7 +565,8 @@ var formatNode = function (schemas, type, data, params) {
|
|
|
565
565
|
if (params === void 0) { params = {}; }
|
|
566
566
|
var schema = type in schemas && exports.acceptedNodeTypes.includes(type) ? schemas[type] : schemaNotFoundError(type);
|
|
567
567
|
var content = mapContent(schemas, schema, params)(data);
|
|
568
|
-
|
|
568
|
+
var id = isEmptyCell(data.id) ? undefined : data.id;
|
|
569
|
+
return (0, utils_1.reduceUndefinedValues)(__assign(__assign({}, (params.convertToExistingNodes ? { '@id': id } : { id: id })), extendDataFromSchema(content, schema, type, params)), true);
|
|
569
570
|
};
|
|
570
571
|
exports.formatNode = formatNode;
|
|
571
572
|
var filterEmptyNode = function (schemas, node) {
|
|
@@ -579,7 +580,7 @@ var convetToNode = function (schemas, params) { return function (data) {
|
|
|
579
580
|
return Object.keys(data)
|
|
580
581
|
.filter(utils_1.nonEmptyValue)
|
|
581
582
|
.map(function (type) {
|
|
582
|
-
return (0, exports.formatNode)(schemas, (0, schema_1.typeToSchemaType)(type) || type, data[type], __assign(__assign({}, params), {
|
|
583
|
+
return (0, exports.formatNode)(schemas, (0, schema_1.typeToSchemaType)(type) || type, data[type], __assign(__assign({}, params), { convertToExistingNodes: params.convertToExistingNodes || (typeof data[type] === 'object' ? '@id' in data[type] : false) }));
|
|
583
584
|
})
|
|
584
585
|
.filter(function (node) { return (0, exports.filterEmptyNode)(schemas, node); });
|
|
585
586
|
}; };
|