@hestia-earth/schema-convert 7.6.6 → 7.8.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.
Files changed (2) hide show
  1. package/json.js +27 -21
  2. package/package.json +1 -1
package/json.js CHANGED
@@ -110,6 +110,28 @@ var internalProperties = function (_a) {
110
110
  };
111
111
  var isEmptyCell = function (value) { return value === IGNORE_FIELD_KEY || value === ''; };
112
112
  var nonEmptyCell = function (value) { return !isEmptyCell(value); };
113
+ var isEmptyValueType = (_a = {
114
+ undefined: function () { return true; },
115
+ number: function (value) { return isNaN(value); }
116
+ },
117
+ _a[schema_1.SchemaType.Term] = function (value) { return !(value['@id'] || value.id || value.name); },
118
+ _a.BlankNode = function (value, schemas) {
119
+ return Object.values(value).filter(function (value) { return !utils_1.isEmpty(value); }).length <= schemaMinKeys(schemas, value);
120
+ },
121
+ _a.array = function (value) { return value.filter(function (v) { return !utils_1.isEmpty(v); }).length === 0; },
122
+ _a.object = function (value, schemas) {
123
+ return Array.isArray(value) ?
124
+ isEmptyValueType.array(value) :
125
+ (value['@type'] || value.type) === schema_1.SchemaType.Term ?
126
+ isEmptyValueType[schema_1.SchemaType.Term](value) :
127
+ schema_1.isBlankNode(value) ?
128
+ isEmptyValueType.BlankNode(value, schemas) :
129
+ Object.keys(value).length === 0;
130
+ },
131
+ _a);
132
+ var isEmptyValue = function (value, schemas) {
133
+ return (typeof value) in isEmptyValueType ? isEmptyValueType[typeof value](value, schemas) : isEmptyCell(value);
134
+ };
113
135
  var compileFullKey = function (key1, key2) {
114
136
  // handle arrays
115
137
  var joinKey = (key2 || '').startsWith('[') ? '' : '.';
@@ -172,10 +194,13 @@ var handleArrayError = function (func) { return function (value, index) {
172
194
  }; };
173
195
  /**
174
196
  * If the user provided a non-object where an object was expected, assume it was meant to be the `name` property.
197
+ * For non-Terms, we assume it is the `id`.
175
198
  *
176
199
  * @param value The value mapped as a Ref
177
200
  */
178
- var schemaRefValue = function (value) { return typeof value === 'object' ? value : ({ name: value }); };
201
+ var schemaRefValue = function (value, schemaType) {
202
+ return typeof value === 'object' ? value : schemaType === schema_1.SchemaType.Term ? { name: value } : { id: value };
203
+ };
179
204
  exports.cleanStringValue = function (value) { return (value.match(/^[\d]+\.[\d]+\.[\d]+$/) === null ? value.replace(/\.0$/, '') : value).trim(); };
180
205
  var propertyTypeToValue = {
181
206
  null: function (value) {
@@ -226,7 +251,7 @@ var propertyTypeToValue = {
226
251
  var $ref = _a.$ref;
227
252
  var schemaType = schema_1.refToSchemaType($ref);
228
253
  var schema = schemaType ? schemas[schemaType] : undefined;
229
- var data = schema ? mapContent(schemas, schema, _i)(schemaRefValue(value)) : safeParseJSON(value);
254
+ var data = schema ? mapContent(schemas, schema, _i)(schemaRefValue(value, schemaType)) : safeParseJSON(value);
230
255
  return utils_1.isEmpty(data) ? {} : (schema ? extendDataFromSchema(data, schema, schemaType, _i) : data);
231
256
  }
232
257
  };
@@ -283,25 +308,6 @@ var extendDataFromSchema = function (_a, schema, type, ignoreInternal, top) {
283
308
  }, {}) :
284
309
  {})), nodeType(id, type, '@id' in data)), true);
285
310
  };
286
- var isEmptyValueType = (_a = {},
287
- _a[schema_1.SchemaType.Term] = function (value) { return !(value['@id'] || value.id || value.name); },
288
- _a.BlankNode = function (value, schemas) {
289
- return Object.values(value).filter(function (value) { return !utils_1.isEmpty(value); }).length <= schemaMinKeys(schemas, value);
290
- },
291
- _a.array = function (value) { return value.filter(function (v) { return !utils_1.isEmpty(v); }).length === 0; },
292
- _a.object = function (value, schemas) {
293
- return Array.isArray(value) ?
294
- isEmptyValueType.array(value) :
295
- (value['@type'] || value.type) === schema_1.SchemaType.Term ?
296
- isEmptyValueType[schema_1.SchemaType.Term](value) :
297
- schema_1.isBlankNode(value) ?
298
- isEmptyValueType.BlankNode(value, schemas) :
299
- Object.keys(value).length === 0;
300
- },
301
- _a);
302
- var isEmptyValue = function (value, schemas) {
303
- return (typeof value) in isEmptyValueType ? isEmptyValueType[typeof value](value, schemas) : isEmptyCell(value);
304
- };
305
311
  var mapContent = function (schemas, schema, ignoreInternal) { return function (json) {
306
312
  return Object.keys(json)
307
313
  .filter(nonEmptyCell)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "7.6.6",
3
+ "version": "7.8.0",
4
4
  "description": "Hestia Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",