@hestia-earth/schema-convert 32.1.0 → 32.1.2

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 +3 -3
  2. package/json.js +13 -5
  3. package/package.json +1 -1
package/json.d.ts CHANGED
@@ -34,7 +34,7 @@ export declare enum ErrorKeys {
34
34
  DuplicatedIdFields = "duplicated-id-fields",
35
35
  ObjectArrayInvalid = "object-array-invalid"
36
36
  }
37
- interface IConversionParams {
37
+ export interface IJSONConversionParams {
38
38
  /**
39
39
  * Ignore all internal fields (see `internal: true` in the schema). Defaults to `true`.
40
40
  */
@@ -50,7 +50,7 @@ interface IConversionParams {
50
50
  }
51
51
  export declare const throwCSVErrors: <T extends ICSVError>(errors: T[]) => never;
52
52
  export declare const cleanStringValue: (value: string) => string;
53
- export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, params?: IConversionParams) => any;
53
+ export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, params?: IJSONConversionParams) => any;
54
54
  export declare const filterEmptyNode: (schemas: definitions, node: any) => boolean;
55
55
  /**
56
56
  * Convert CSV to HESTIA JSON-LD format.
@@ -60,5 +60,5 @@ export declare const filterEmptyNode: (schemas: definitions, node: any) => boole
60
60
  * @param params Conversion parameters.
61
61
  * @returns A list of JSON-LD content.
62
62
  */
63
- export declare const toJson: (schemas: definitions, content: string, params?: IConversionParams) => Promise<any[]>;
63
+ export declare const toJson: (schemas: definitions, content: string, params?: IJSONConversionParams) => Promise<any[]>;
64
64
  export {};
package/json.js CHANGED
@@ -493,18 +493,26 @@ var filterProperties = function (data, excludedProps) {
493
493
  };
494
494
  var nodeType = function (id, type, existingNode) {
495
495
  if (existingNode === void 0) { existingNode = false; }
496
- return type ? (existingNode ? { '@type': type } : { id: id, type: type }) : {};
496
+ return type
497
+ ? existingNode
498
+ ? (0, schema_1.isTypeNode)(type)
499
+ ? { '@type': type, '@id': id }
500
+ : { '@type': type }
501
+ : (0, schema_1.isTypeNode)(type)
502
+ ? { type: type, id: id }
503
+ : { type: type }
504
+ : {};
497
505
  };
498
506
  var extendDataFromSchema = function (_a, schema, type, _b) {
499
- var id = _a.id, _t = _a.type, data = __rest(_a, ["id", "type"]);
507
+ var id = _a.id, _id = _a["@id"], _t = _a.type, data = __rest(_a, ["id", '@id', "type"]);
500
508
  var _c = _b === void 0 ? {} : _b, ignoreInternal = _c.ignoreInternal, addDefaults = _c.addDefaults, convertToExistingNodes = _c.convertToExistingNodes;
501
- return (0, utils_1.reduceUndefinedValues)(__assign(__assign(__assign({}, filterProperties(data, ignoreInternal ? [] : internalProperties(schema))), (addDefaults && !('@id' in data) && schema
509
+ return (0, utils_1.reduceUndefinedValues)(__assign(__assign(__assign({}, filterProperties(data, ignoreInternal ? [] : internalProperties(schema))), (addDefaults && !_id && schema
502
510
  ? getDefaultProperties(schema, data, ignoreInternal).reduce(function (prev, _a) {
503
511
  var property = _a.property, defaultValue = _a.defaultValue;
504
512
  prev[property] = defaultValue;
505
513
  return prev;
506
514
  }, {})
507
- : {})), nodeType(id, type, '@id' in data || convertToExistingNodes)), true);
515
+ : {})), nodeType(id || _id, type, !!_id || convertToExistingNodes)), true);
508
516
  };
509
517
  var validateArrayType = function (schema, def, key, value) {
510
518
  return typeof value !== 'object' ||
@@ -566,7 +574,7 @@ var formatNode = function (schemas, type, data, params) {
566
574
  var schema = type in schemas && exports.acceptedNodeTypes.includes(type) ? schemas[type] : schemaNotFoundError(type);
567
575
  var content = mapContent(schemas, schema, params)(data);
568
576
  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);
577
+ return (0, utils_1.reduceUndefinedValues)(extendDataFromSchema(content, schema, type, params), true);
570
578
  };
571
579
  exports.formatNode = formatNode;
572
580
  var filterEmptyNode = function (schemas, node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "32.1.0",
3
+ "version": "32.1.2",
4
4
  "description": "HESTIA Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",