@hestia-earth/schema-convert 7.3.1 → 7.5.1

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.
Files changed (3) hide show
  1. package/json.d.ts +1 -1
  2. package/json.js +7 -5
  3. package/package.json +1 -1
package/json.d.ts CHANGED
@@ -24,7 +24,7 @@ export interface ICSVError {
24
24
  }
25
25
  export declare const throwCSVError: <T extends ICSVError>(error: T) => never;
26
26
  export declare const cleanStringValue: (value: string) => string;
27
- export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, ignoreInternal: boolean) => any;
27
+ export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, ignoreInternal: boolean, top?: boolean) => any;
28
28
  export declare const filterEmptyNode: (schemas: definitions, { schemaVersion, ...node }: any) => boolean;
29
29
  /**
30
30
  * Convert CSV to Hestia JSON-LD format.
package/json.js CHANGED
@@ -235,10 +235,11 @@ var nodeType = function (id, type, existingNode) {
235
235
  if (existingNode === void 0) { existingNode = false; }
236
236
  return type ? (schema_1.isTypeNode(type) ? (existingNode ? { '@type': type } : { id: id, type: type }) : { type: type }) : {};
237
237
  };
238
- var extendDataFromSchema = function (_a, schema, type, ignoreInternal) {
238
+ var extendDataFromSchema = function (_a, schema, type, ignoreInternal, top) {
239
239
  if (ignoreInternal === void 0) { ignoreInternal = false; }
240
+ if (top === void 0) { top = false; }
240
241
  var id = _a.id, _t = _a.type, data = __rest(_a, ["id", "type"]);
241
- return utils_1.reduceUndefinedValues(__assign(__assign(__assign({}, filterProperties(data, ignoreInternal ? [] : internalProperties(schema))), (schema ?
242
+ return utils_1.reduceUndefinedValues(__assign(__assign(__assign({}, filterProperties(data, ignoreInternal ? [] : internalProperties(schema))), (top && schema ?
242
243
  getDefaultProperties(schema, data, ignoreInternal).reduce(function (prev, _a) {
243
244
  var _b;
244
245
  var property = _a.property, defaultValue = _a.defaultValue;
@@ -264,10 +265,11 @@ var mapContent = function (schemas, schema, ignoreInternal) { return function (j
264
265
  return __assign(__assign(__assign({}, prev), (schema.$id ? { type: schema.title } : {})), (isEmptyValue(newValue) ? {} : (_a = {}, _a[key] = newValue, _a)));
265
266
  }, {});
266
267
  }; };
267
- exports.formatNode = function (schemas, type, data, ignoreInternal) {
268
+ exports.formatNode = function (schemas, type, data, ignoreInternal, top) {
269
+ if (top === void 0) { top = false; }
268
270
  var schema = type in schemas ? schemas[type] : schemaNotFoundError();
269
271
  var content = mapContent(schemas, schema, ignoreInternal)(data);
270
- return utils_1.reduceUndefinedValues(__assign({ id: !nonEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, ignoreInternal)));
272
+ return utils_1.reduceUndefinedValues(__assign({ id: !nonEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, ignoreInternal, top)));
271
273
  };
272
274
  exports.filterEmptyNode = function (schemas, _a) {
273
275
  var schemaVersion = _a.schemaVersion, node = __rest(_a, ["schemaVersion"]);
@@ -279,7 +281,7 @@ exports.filterEmptyNode = function (schemas, _a) {
279
281
  var convetToNode = function (schemas) { return function (data) {
280
282
  return Object.keys(data)
281
283
  .filter(utils_1.nonEmptyValue)
282
- .map(function (type) { return exports.formatNode(schemas, schema_1.typeToSchemaType(type), data[type], true); })
284
+ .map(function (type) { return exports.formatNode(schemas, schema_1.typeToSchemaType(type), data[type], true, true); })
283
285
  .filter(function (node) { return exports.filterEmptyNode(schemas, node); });
284
286
  }; };
285
287
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "7.3.1",
3
+ "version": "7.5.1",
4
4
  "description": "Hestia Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",