@hestia-earth/schema-convert 7.3.0 → 7.3.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 +2 -1
  2. package/json.js +15 -7
  3. package/package.json +1 -1
package/json.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SchemaType } from '@hestia-earth/schema';
2
- import { definitions } from '@hestia-earth/json-schema';
2
+ import { definitions } from '@hestia-earth/json-schema/types';
3
3
  export interface INode {
4
4
  type: SchemaType;
5
5
  id?: string;
@@ -25,6 +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) => any;
28
+ export declare const filterEmptyNode: (schemas: definitions, { schemaVersion, ...node }: any) => boolean;
28
29
  /**
29
30
  * Convert CSV to Hestia JSON-LD format.
30
31
  *
package/json.js CHANGED
@@ -58,14 +58,22 @@ var __rest = (this && this.__rest) || function (s, e) {
58
58
  return t;
59
59
  };
60
60
  Object.defineProperty(exports, "__esModule", { value: true });
61
- exports.toJson = exports.formatNode = exports.cleanStringValue = exports.throwCSVError = void 0;
61
+ exports.toJson = exports.filterEmptyNode = exports.formatNode = exports.cleanStringValue = exports.throwCSVError = void 0;
62
62
  var csvtojson = require("csvtojson");
63
63
  var schema_1 = require("@hestia-earth/schema");
64
- var json_schema_1 = require("@hestia-earth/json-schema");
64
+ var types_1 = require("@hestia-earth/json-schema/types");
65
65
  var utils_1 = require("./utils");
66
66
  var IGNORE_FIELD_KEY = '-';
67
67
  var VALUE_TYPE_KEY = 'valueType';
68
- var ARRAY_DELIMITER = process.env.CSV_ARRAY_DELIMITER || ';';
68
+ var DEFAULT_ARRAY_DELIMITER = ';';
69
+ var arrayDelimiter = function () {
70
+ try {
71
+ return process.env.CSV_ARRAY_DELIMITER || DEFAULT_ARRAY_DELIMITER;
72
+ }
73
+ catch (err) {
74
+ return DEFAULT_ARRAY_DELIMITER;
75
+ }
76
+ };
69
77
  var safeParseJSON = function (obj) {
70
78
  // throw already handled error or throw a generic invalid-format error
71
79
  var data;
@@ -159,7 +167,7 @@ var propertyTypeToValue = {
159
167
  },
160
168
  array: function (value, schemas, _a, _i) {
161
169
  var items = _a.items;
162
- return (Array.isArray(value) ? value : value.split(ARRAY_DELIMITER))
170
+ return (Array.isArray(value) ? value : value.split(arrayDelimiter()))
163
171
  .map(handleArrayError(function (val) { return items ? ('$ref' in items ?
164
172
  propertyTypeToValue.object(val, schemas, items, _i) :
165
173
  Array.isArray(items.type) ?
@@ -208,7 +216,7 @@ var setDefaultProperty = function (prop, def, node, ignoreInternal) {
208
216
  };
209
217
  var getDefaultProperties = function (schema, node, ignoreInternal) {
210
218
  if (ignoreInternal === void 0) { ignoreInternal = false; }
211
- return json_schema_1.defaultProperties(schema)
219
+ return types_1.defaultProperties(schema)
212
220
  .map(function (property) {
213
221
  var def = schema.properties[property];
214
222
  return setDefaultProperty(property, def, node, ignoreInternal) ? { property: property, defaultValue: def.default } : null;
@@ -261,7 +269,7 @@ exports.formatNode = function (schemas, type, data, ignoreInternal) {
261
269
  var content = mapContent(schemas, schema, ignoreInternal)(data);
262
270
  return utils_1.reduceUndefinedValues(__assign({ id: !nonEmptyCell(data.id) ? undefined : data.id }, extendDataFromSchema(content, schema, type, ignoreInternal)));
263
271
  };
264
- var filterEmptyNode = function (schemas, _a) {
272
+ exports.filterEmptyNode = function (schemas, _a) {
265
273
  var schemaVersion = _a.schemaVersion, node = __rest(_a, ["schemaVersion"]);
266
274
  // make sure defaultProperties are not counted
267
275
  var schema = node.type ? schemas[node.type] : null;
@@ -272,7 +280,7 @@ var convetToNode = function (schemas) { return function (data) {
272
280
  return Object.keys(data)
273
281
  .filter(utils_1.nonEmptyValue)
274
282
  .map(function (type) { return exports.formatNode(schemas, schema_1.typeToSchemaType(type), data[type], true); })
275
- .filter(function (node) { return filterEmptyNode(schemas, node); });
283
+ .filter(function (node) { return exports.filterEmptyNode(schemas, node); });
276
284
  }; };
277
285
  /**
278
286
  * Convert CSV to Hestia JSON-LD format.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "7.3.0",
3
+ "version": "7.3.1",
4
4
  "description": "Hestia Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",