@hestia-earth/schema-convert 15.2.0 → 16.0.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.
- package/json.js +85 -81
- package/package.json +1 -1
package/json.js
CHANGED
|
@@ -82,7 +82,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
82
82
|
}
|
|
83
83
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
84
84
|
};
|
|
85
|
-
var _a;
|
|
85
|
+
var _a, _b;
|
|
86
86
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
87
|
exports.toJson = exports.filterEmptyNode = exports.formatNode = exports.cleanStringValue = exports.throwCSVError = void 0;
|
|
88
88
|
var csvtojson = require("csvtojson");
|
|
@@ -307,88 +307,92 @@ var schemaRefValue = function (value, type) {
|
|
|
307
307
|
};
|
|
308
308
|
var cleanStringValue = function (value) { return (value.match(/^[\d]+\.[\d]+\.[\d]+$/) === null ? value.replace(/\.0$/, '') : value).trim(); };
|
|
309
309
|
exports.cleanStringValue = cleanStringValue;
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
310
|
+
var geojsonRef = 'http://json.schemastore.org/geojson';
|
|
311
|
+
var propertyTypeToValue = (_b = {
|
|
312
|
+
null: function (value) {
|
|
313
|
+
var args = [];
|
|
314
|
+
for (var _a = 1; _a < arguments.length; _a++) {
|
|
315
|
+
args[_a - 1] = arguments[_a];
|
|
316
|
+
}
|
|
317
|
+
return isEmptyCell(value) ? null : propertyTypeToValue.auto.apply(propertyTypeToValue, __spreadArray([value], __read(args), false));
|
|
318
|
+
},
|
|
319
|
+
string: function (value) { return (0, exports.cleanStringValue)(value || ''); },
|
|
320
|
+
number: function (value) {
|
|
321
|
+
return isEmptyCell(value)
|
|
322
|
+
? undefined
|
|
323
|
+
: isNaN(+value)
|
|
324
|
+
? (function () {
|
|
325
|
+
throw new Error('failed to parse number');
|
|
326
|
+
})()
|
|
327
|
+
: +value;
|
|
328
|
+
},
|
|
329
|
+
integer: function (value) { return isEmptyCell(value) ? undefined : +value; },
|
|
330
|
+
boolean: function (value) {
|
|
331
|
+
return isEmptyCell(value)
|
|
332
|
+
? undefined
|
|
333
|
+
: (0, utils_1.isBoolean)(value)
|
|
334
|
+
? value.toLowerCase() === 'true'
|
|
335
|
+
: (0, utils_1.isNumber)(value)
|
|
336
|
+
? +value === 1 // handle setting 1 or 1.0 as true
|
|
337
|
+
: (function () {
|
|
338
|
+
throw new Error('failed to parse boolean, expected true or false');
|
|
339
|
+
})();
|
|
340
|
+
},
|
|
341
|
+
object: function (value, schemas, _a, _i) {
|
|
342
|
+
var $ref = _a.$ref, required = _a.required;
|
|
343
|
+
return $ref === geojsonRef
|
|
344
|
+
? propertyTypeToValue[geojsonRef](value)
|
|
345
|
+
: $ref
|
|
346
|
+
? propertyTypeToValue.$ref(value, schemas, { $ref: $ref }, _i)
|
|
347
|
+
: propertyTypeToValue.required(value, schemas, { required: required }, _i);
|
|
348
|
+
},
|
|
349
|
+
array: function (value, schemas, _a, _i) {
|
|
350
|
+
var items = _a.items;
|
|
351
|
+
return (Array.isArray(value) ? value : value.split(arrayDelimiter()))
|
|
352
|
+
.map(handleArrayError(function (val) { return items ? ('$ref' in items ?
|
|
353
|
+
propertyTypeToValue.object(val, schemas, items, _i) :
|
|
354
|
+
Array.isArray(items.type) ?
|
|
355
|
+
propertyTypeToValue.auto(val, schemas, items, _i) :
|
|
356
|
+
propertyTypeToValue[items.type](val, schemas, items, _i)) : val; }))
|
|
357
|
+
.filter(function (val) { return !isEmptyValue(val, schemas); });
|
|
358
|
+
},
|
|
359
|
+
// try to determine the type automatically
|
|
360
|
+
auto: function (value, schemas, _d, _i) {
|
|
361
|
+
// iris are mapped as {@id: val}
|
|
362
|
+
return (0, utils_1.isIri)(value)
|
|
363
|
+
? propertyTypeToValue.required(value, schemas, { required: ['@id'] }, _i)
|
|
364
|
+
: (0, utils_1.isBoolean)(value)
|
|
365
|
+
? propertyTypeToValue.boolean(value)
|
|
366
|
+
: (0, utils_1.isNumber)(value)
|
|
367
|
+
? propertyTypeToValue.number(value)
|
|
368
|
+
: value === 'null'
|
|
369
|
+
? null
|
|
370
|
+
: propertyTypeToValue.string(value);
|
|
371
|
+
},
|
|
372
|
+
required: function (value, _schemas, _a) {
|
|
373
|
+
var required = _a.required;
|
|
374
|
+
var data = propertyRequiredValue(value, required);
|
|
375
|
+
return (0, utils_1.isEmpty)(data) ? {} : data;
|
|
376
|
+
},
|
|
377
|
+
$ref: function (value, schemas, _a, _i) {
|
|
378
|
+
var $ref = _a.$ref;
|
|
379
|
+
var schemaType = (0, schema_1.refToSchemaType)($ref);
|
|
380
|
+
var schema = schemaType ? schemas[schemaType] : undefined;
|
|
381
|
+
var data = schema
|
|
382
|
+
? mapContent(schemas, schema, _i)(schemaRefValue(value, schemaType))
|
|
383
|
+
: $ref in propertyTypeToValue
|
|
384
|
+
? propertyTypeToValue[$ref](value)
|
|
385
|
+
: safeParseJSON(value);
|
|
386
|
+
var includeDefaults = (0, schema_1.isBlankNode)(data) || schemaType === schema_1.SchemaType.Actor; // only blank nodes or actors allowed
|
|
387
|
+
return (0, utils_1.isEmpty)(data)
|
|
388
|
+
? {}
|
|
389
|
+
: !!schema
|
|
390
|
+
? extendDataFromSchema(data, schema, schemaType, _i, includeDefaults)
|
|
391
|
+
: data;
|
|
315
392
|
}
|
|
316
|
-
return isEmptyCell(value) ? null : propertyTypeToValue.auto.apply(propertyTypeToValue, __spreadArray([value], __read(args), false));
|
|
317
|
-
},
|
|
318
|
-
string: function (value) { return (0, exports.cleanStringValue)(value || ''); },
|
|
319
|
-
number: function (value) {
|
|
320
|
-
return isEmptyCell(value)
|
|
321
|
-
? undefined
|
|
322
|
-
: isNaN(+value)
|
|
323
|
-
? (function () {
|
|
324
|
-
throw new Error('failed to parse number');
|
|
325
|
-
})()
|
|
326
|
-
: +value;
|
|
327
|
-
},
|
|
328
|
-
integer: function (value) { return isEmptyCell(value) ? undefined : +value; },
|
|
329
|
-
boolean: function (value) {
|
|
330
|
-
return isEmptyCell(value)
|
|
331
|
-
? undefined
|
|
332
|
-
: (0, utils_1.isBoolean)(value)
|
|
333
|
-
? value.toLowerCase() === 'true'
|
|
334
|
-
: (0, utils_1.isNumber)(value)
|
|
335
|
-
? +value === 1 // handle setting 1 or 1.0 as true
|
|
336
|
-
: (function () {
|
|
337
|
-
throw new Error('failed to parse boolean, expected true or false');
|
|
338
|
-
})();
|
|
339
|
-
},
|
|
340
|
-
object: function (value, schemas, _a, _i) {
|
|
341
|
-
var $ref = _a.$ref, required = _a.required;
|
|
342
|
-
return $ref ?
|
|
343
|
-
propertyTypeToValue.$ref(value, schemas, { $ref: $ref }, _i) :
|
|
344
|
-
propertyTypeToValue.required(value, schemas, { required: required }, _i);
|
|
345
393
|
},
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return (Array.isArray(value) ? value : value.split(arrayDelimiter()))
|
|
349
|
-
.map(handleArrayError(function (val) { return items ? ('$ref' in items ?
|
|
350
|
-
propertyTypeToValue.object(val, schemas, items, _i) :
|
|
351
|
-
Array.isArray(items.type) ?
|
|
352
|
-
propertyTypeToValue.auto(val, schemas, items, _i) :
|
|
353
|
-
propertyTypeToValue[items.type](val, schemas, items, _i)) : val; }))
|
|
354
|
-
.filter(function (val) { return !isEmptyValue(val, schemas); });
|
|
355
|
-
},
|
|
356
|
-
// try to determine the type automatically
|
|
357
|
-
auto: function (value, schemas, _d, _i) {
|
|
358
|
-
// iris are mapped as {@id: val}
|
|
359
|
-
return (0, utils_1.isIri)(value)
|
|
360
|
-
? propertyTypeToValue.required(value, schemas, { required: ['@id'] }, _i)
|
|
361
|
-
: (0, utils_1.isBoolean)(value)
|
|
362
|
-
? propertyTypeToValue.boolean(value)
|
|
363
|
-
: (0, utils_1.isNumber)(value)
|
|
364
|
-
? propertyTypeToValue.number(value)
|
|
365
|
-
: value === 'null'
|
|
366
|
-
? null
|
|
367
|
-
: propertyTypeToValue.string(value);
|
|
368
|
-
},
|
|
369
|
-
required: function (value, _schemas, _a) {
|
|
370
|
-
var required = _a.required;
|
|
371
|
-
var data = propertyRequiredValue(value, required);
|
|
372
|
-
return (0, utils_1.isEmpty)(data) ? {} : data;
|
|
373
|
-
},
|
|
374
|
-
$ref: function (value, schemas, _a, _i) {
|
|
375
|
-
var $ref = _a.$ref;
|
|
376
|
-
var schemaType = (0, schema_1.refToSchemaType)($ref);
|
|
377
|
-
var schema = schemaType ? schemas[schemaType] : undefined;
|
|
378
|
-
var data = schema
|
|
379
|
-
? mapContent(schemas, schema, _i)(schemaRefValue(value, schemaType))
|
|
380
|
-
: $ref in propertyTypeToValue
|
|
381
|
-
? propertyTypeToValue[$ref](value)
|
|
382
|
-
: safeParseJSON(value);
|
|
383
|
-
var includeDefaults = (0, schema_1.isBlankNode)(data) || schemaType === schema_1.SchemaType.Actor; // only blank nodes or actors allowed
|
|
384
|
-
return (0, utils_1.isEmpty)(data)
|
|
385
|
-
? {}
|
|
386
|
-
: !!schema
|
|
387
|
-
? extendDataFromSchema(data, schema, schemaType, _i, includeDefaults)
|
|
388
|
-
: data;
|
|
389
|
-
},
|
|
390
|
-
'http://json.schemastore.org/geojson': function (value) { return isEmptyCell(value) ? undefined : parseGeoJSONValue(value); }
|
|
391
|
-
};
|
|
394
|
+
_b[geojsonRef] = function (value) { return isEmptyCell(value) ? undefined : parseGeoJSONValue(value); },
|
|
395
|
+
_b);
|
|
392
396
|
var getPropertyDefinition = function (schema, key, ignoreErrors, value) {
|
|
393
397
|
if (ignoreErrors === void 0) { ignoreErrors = false; }
|
|
394
398
|
return key in schema.properties ? schema.properties[key] : !ignoreErrors && propertyNotFoundError(schema, key, value);
|