@radiantearth/stac-migrate 1.0.4 → 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 +9 -4
  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.4**
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
@@ -300,6 +300,8 @@ var _ = {
300
300
 
301
301
  var Checksum = {
302
302
 
303
+ multihash: null,
304
+
303
305
  hexToUint8(hexString) {
304
306
  if(hexString.length === 0 || hexString.length % 2 !== 0){
305
307
  throw new Error(`The string "${hexString}" is not valid hex.`)
@@ -312,12 +314,11 @@ var Checksum = {
312
314
  },
313
315
 
314
316
  toMultihash(obj, key, algo) {
315
- if (!_.is(obj[key], 'string')) {
317
+ if (!Checksum.multihash || !_.is(obj[key], 'string')) {
316
318
  return false;
317
319
  }
318
320
  try {
319
- const multihash = require('multihashes');
320
- const encoded = multihash.encode(Checksum.hexToUint8(obj[key]), algo);
321
+ const encoded = Checksum.multihash.encode(Checksum.hexToUint8(obj[key]), algo);
321
322
  obj[key] = Checksum.uint8ToHex(encoded);
322
323
  return true;
323
324
  } catch (error) {
@@ -665,7 +666,7 @@ var Fields = {
665
666
  },
666
667
 
667
668
  checksum(obj, context) {
668
- if (V.before('0.9.0')) {
669
+ if (V.before('0.9.0') && Checksum.multihash) {
669
670
  _.rename(obj, 'checksum:md5', 'checksum:multihash') && Checksum.toMultihash(obj, 'checksum:multihash', 'md5') && DONE;
670
671
  _.rename(obj, 'checksum:sha1', 'checksum:multihash') && Checksum.toMultihash(obj, 'checksum:multihash', 'sha1') && DONE;
671
672
  // We assume sha2/3-256 although that may fail in some cases and other lengths are chosen
@@ -805,6 +806,10 @@ var Migrate = {
805
806
  else {
806
807
  return Migrate.catalog(object, updateVersionNumber);
807
808
  }
809
+ },
810
+
811
+ enableMultihash(multihash) {
812
+ Checksum.multihash = multihash;
808
813
  }
809
814
 
810
815
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantearth/stac-migrate",
3
- "version": "1.0.4",
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": {