@radiantearth/stac-migrate 1.0.2 → 1.1.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 (3) hide show
  1. package/README.md +2 -2
  2. package/migrate.js +28 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A library to update STAC files to the latest version (**1.0.0** at the moment of writing). Supports updating **STAC versions 0.6.0 and later**.
4
4
 
5
- Version of this library: **1.0.2**
5
+ Version of this library: **1.1.0**
6
6
 
7
7
  ## Usage
8
8
 
@@ -21,7 +21,7 @@ Import the library: `const Migrate = require('@radiantearth/stac-migrate');`
21
21
 
22
22
  ## Supported Extensions
23
23
 
24
- * Checksum
24
+ * Checksum (use `Migrate.enableMultihash(require('multihashes'))` to enable conversion from pre-0.9 checksums - disabled by default to keep the bundle size low)
25
25
  * Collection Assets 1.0.0
26
26
  * Commons
27
27
  * Data Cube 1.0.0
package/migrate.js CHANGED
@@ -250,6 +250,7 @@ var _ = {
250
250
  },
251
251
 
252
252
  moveTo(obj, key, context, fromSummary = false, mergedSummary = false) {
253
+ let condition;
253
254
  if (fromSummary) {
254
255
  if (mergedSummary) {
255
256
  condition = val => Array.isArray(val);
@@ -299,6 +300,8 @@ var _ = {
299
300
 
300
301
  var Checksum = {
301
302
 
303
+ multihash: null,
304
+
302
305
  hexToUint8(hexString) {
303
306
  if(hexString.length === 0 || hexString.length % 2 !== 0){
304
307
  throw new Error(`The string "${hexString}" is not valid hex.`)
@@ -311,12 +314,11 @@ var Checksum = {
311
314
  },
312
315
 
313
316
  toMultihash(obj, key, algo) {
314
- if (!_.is(obj[key], 'string')) {
317
+ if (!Checksum.multihash || !_.is(obj[key], 'string')) {
315
318
  return false;
316
319
  }
317
320
  try {
318
- const multihash = require('multihashes');
319
- const encoded = multihash.encode(Checksum.hexToUint8(obj[key]), algo);
321
+ const encoded = Checksum.multihash.encode(Checksum.hexToUint8(obj[key]), algo);
320
322
  obj[key] = Checksum.uint8ToHex(encoded);
321
323
  return true;
322
324
  } catch (error) {
@@ -345,7 +347,15 @@ var Catalog = {
345
347
 
346
348
  _.ensure(catalog, 'stac_extensions', []) && DONE;
347
349
  V.before('0.8.0') && _.populateExtensions(catalog, 'catalog') && DONE;
348
- }
350
+ },
351
+
352
+ openeo(obj) {
353
+ _.rename(obj, 'api_version', 'openeo:api_version') && DONE;
354
+ _.rename(obj, 'backend_version', 'openeo:backend_version') && DONE;
355
+ _.rename(obj, 'production', 'openeo:production') && DONE;
356
+ _.rename(obj, 'endpoints', 'openeo:endpoints') && DONE;
357
+ _.rename(obj, 'billing', 'openeo:billing') && DONE;
358
+ },
349
359
 
350
360
  };
351
361
 
@@ -379,6 +389,8 @@ var Collection = {
379
389
  },
380
390
 
381
391
  extent(collection) {
392
+ _.ensure(collection, "extent", {});
393
+
382
394
  if (V.before('0.8.0')) {
383
395
  // Restructure spatial extent
384
396
  if (Array.isArray(collection.extent.spatial)) {
@@ -398,9 +410,14 @@ var Collection = {
398
410
  }
399
411
  }
400
412
 
413
+ _.ensure(collection.extent, "spatial", {});
414
+ _.ensure(collection.extent.spatial, "bbox", []);
415
+ _.ensure(collection.extent, "temporal", {});
416
+ _.ensure(collection.extent.temporal, "interval", []);
417
+
401
418
  if (V.before('1.0.0-rc.3')) {
402
419
  // The first extent in a Collection is always the overall extent, followed by more specific extents.
403
- if (Array.isArray(collection.extent.temporal.interval) && collection.extent.temporal.interval.length > 1) {
420
+ if (collection.extent.temporal.interval.length > 1) {
404
421
  let min, max;
405
422
  for(let interval of collection.extent.temporal.interval) {
406
423
  if (interval[0] === null) {
@@ -432,7 +449,7 @@ var Collection = {
432
449
  max ? _.toISOString(max) : null
433
450
  ]);
434
451
  }
435
- if (Array.isArray(collection.extent.spatial.bbox) && collection.extent.spatial.bbox.length > 1) {
452
+ if (collection.extent.spatial.bbox.length > 1) {
436
453
  let count = collection.extent.spatial.bbox.reduce((val, bbox) => Array.isArray(bbox) ? Math.max(bbox.length, val) : val, 4);
437
454
  if (count >= 4) {
438
455
  let union = new Array(count).fill(null);
@@ -649,7 +666,7 @@ var Fields = {
649
666
  },
650
667
 
651
668
  checksum(obj, context) {
652
- if (V.before('0.9.0')) {
669
+ if (V.before('0.9.0') && Checksum.multihash) {
653
670
  _.rename(obj, 'checksum:md5', 'checksum:multihash') && Checksum.toMultihash(obj, 'checksum:multihash', 'md5') && DONE;
654
671
  _.rename(obj, 'checksum:sha1', 'checksum:multihash') && Checksum.toMultihash(obj, 'checksum:multihash', 'sha1') && DONE;
655
672
  // We assume sha2/3-256 although that may fail in some cases and other lengths are chosen
@@ -789,6 +806,10 @@ var Migrate = {
789
806
  else {
790
807
  return Migrate.catalog(object, updateVersionNumber);
791
808
  }
809
+ },
810
+
811
+ enableMultihash(multihash) {
812
+ Checksum.multihash = multihash;
792
813
  }
793
814
 
794
815
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantearth/stac-migrate",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "A library to update STAC files to the latest version.",
5
5
  "main": "migrate.js",
6
6
  "bugs": {