@hestia-earth/schema-convert 32.0.2 → 32.1.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 +5 -7
  2. package/json.js +5 -4
  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
  */
@@ -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
- existingNode?: boolean;
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?: IExtendedConversionParams) => any;
53
+ export declare const formatNode: (schemas: definitions, type: SchemaType, data: ICSVContent, params?: IJSONConversionParams) => any;
56
54
  export declare const filterEmptyNode: (schemas: definitions, node: any) => boolean;
57
55
  /**
58
56
  * Convert CSV to HESTIA JSON-LD format.
@@ -62,5 +60,5 @@ export declare const filterEmptyNode: (schemas: definitions, node: any) => boole
62
60
  * @param params Conversion parameters.
63
61
  * @returns A list of JSON-LD content.
64
62
  */
65
- 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[]>;
66
64
  export {};
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, existingNode = _c.existingNode;
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 || existingNode)), true);
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
- return (0, utils_1.reduceUndefinedValues)(__assign({ id: isEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, params)), true);
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), { existingNode: typeof data[type] === 'object' ? '@id' in data[type] : false }));
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
  }; };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "32.0.2",
3
+ "version": "32.1.1",
4
4
  "description": "HESTIA Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",