@radiantearth/stac-migrate 1.3.0 → 1.5.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/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.3.0**
5
+ Version of this library: **1.5.0**
6
6
 
7
7
  ## Usage
8
8
 
@@ -12,12 +12,14 @@ Add to your project with `npm install @radiantearth/stac-migrate --save`
12
12
 
13
13
  Import the library: `const Migrate = require('@radiantearth/stac-migrate');`
14
14
 
15
- * Migrate (auto-detection): `Migrate.stac(stac: object) => object`<br />
15
+ * Migrate (auto-detection): `Migrate.stac(stac: object, updateVersionNumber: boolean = true) => object`<br />
16
16
  *This method does not migrate the Commons extension - use `Migrate.item` if you have used the Commons extension.*
17
- * Migrate a STAC Collection: `Migrate.collection(collection: object) => object`
18
- * Migrate a STAC Catalog: `Migrate.catalog(catalog: object) => object`
19
- * Migrate a STAC Item: `Migrate.item(item: object, collection: object = null) => object`<br />
17
+ * Migrate a STAC Collection: `Migrate.collection(collection: object, updateVersionNumber: boolean = true) => object`
18
+ * Migrate a STAC Catalog: `Migrate.catalog(catalog: object, updateVersionNumber: boolean = true) => object`
19
+ * Migrate a STAC Item: `Migrate.item(item: object, collection: object = null, updateVersionNumber: boolean = true) => object`<br />
20
20
  *The `collection` parameter is only required to migrate the Commons extension. Otherwise, you don't need to pass this paramater.*
21
+ * Migrate a STAC CollectionCollection: `Migrate.collectionCollection(apiCollections: object, updateVersionNumber: boolean = true) => object`
22
+ * Migrate a STAC ItemCollection: `Migrate.itemCollection(apiItems: object, updateVersionNumber: boolean = true) => object`
21
23
 
22
24
  **Note:** All changes will be applied in-place! If you don't want the input object to change, make a deep clone before. If you don't have a library which supports this (e.g. [lodash](https://lodash.com/docs/4.17.15#cloneDeep)) you can simply use `var clone = JSON.parse(JSON.stringify(object));`.
23
25
 
@@ -31,6 +33,8 @@ The commands follow the different methods above and has the same "restrictions"
31
33
  * Migrate a STAC Collection: `npx stac-migrate <source_path> <dest_path> --collection`
32
34
  * Migrate a STAC Catalog: `npx stac-migrate <source_path> <dest_path> --catalog`
33
35
  * Migrate a STAC Item: `npx stac-migrate <source_path> <dest_path> --item --collection_path <collection_path>`
36
+ * Migrate a STAC Item Collection: `npx stac-migrate <source_path> <dest_path> --item_collection`
37
+ * Migrate a STAC Collection Collection: `npx stac-migrate <source_path> <dest_path> --collecions`
34
38
 
35
39
  ## Supported Extensions
36
40
 
package/bin/cli.js CHANGED
@@ -18,23 +18,33 @@ const args = yargs(hideBin(process.argv))
18
18
  .option('collection', {
19
19
  type: 'boolean',
20
20
  description: 'Enforce the collection migration',
21
- conflicts: ['catalog', 'item'],
21
+ conflicts: ['catalog', 'collections', 'item', 'item_collection'],
22
22
 
23
23
  })
24
24
  .option('catalog', {
25
25
  type: 'boolean',
26
26
  description: 'Enforce the catalog migration',
27
- conflicts: ['collection', 'item',]
27
+ conflicts: ['collection', 'collections', 'item', 'item_collection']
28
28
  })
29
29
  .option('item', {
30
30
  type: 'boolean',
31
31
  description: 'Enforce the item migration',
32
- conflicts: ['catalog', 'collection']
32
+ conflicts: ['catalog', 'collection', 'collections', 'item_collection']
33
+ })
34
+ .option('item_collection', {
35
+ type: 'boolean',
36
+ description: 'Enforce the item collection migration',
37
+ conflicts: ['catalog', 'collection', 'collections', 'item']
38
+ })
39
+ .option('collections', {
40
+ type: 'boolean',
41
+ description: 'Enforce the collection collection migration',
42
+ conflicts: ['catalog', 'collection', 'item', 'item_collection']
33
43
  })
34
44
  .option('collection_path', {
35
45
  type: 'string',
36
46
  description: 'Pass the path to a collection to the item, only possible if --item has been specified.',
37
- conflicts: ['catalog', 'collection']
47
+ conflicts: ['catalog', 'collection', 'collections', 'item_collection']
38
48
  })
39
49
  .option('indent', {
40
50
  type: 'number',
@@ -48,9 +58,16 @@ run(args);
48
58
 
49
59
  function run(args) {
50
60
  console.log("STAC Migrate v" + package.version);
51
- let fn = ['collection', 'catalog', 'item'].find(type => Boolean(args[type])) || 'stac';
61
+ let fn = ['collection', 'collections', 'catalog', 'item', 'item_collection'].find(type => Boolean(args[type])) || 'stac';
62
+ let fns = {
63
+ item_collection: 'itemCollection',
64
+ collections: 'collectionCollection'
65
+ };
66
+ if (fns[fn]) {
67
+ fn = fns[fn];
68
+ }
52
69
  if (args._.length !== 1) {
53
- throw new Error("Please provide exatctly one source file.");
70
+ throw new Error("Please provide exactly one source file.");
54
71
  }
55
72
  let src = args._[0];
56
73
  let dest = args.dest || src;
package/migrate.js CHANGED
@@ -402,6 +402,8 @@ var Catalog = {
402
402
  _.runAll(Catalog, catalog, catalog);
403
403
 
404
404
  V.before('0.8.0') && _.populateExtensions(catalog, 'catalog') && DONE;
405
+
406
+ return catalog;
405
407
  },
406
408
 
407
409
  openeo(obj) {
@@ -442,6 +444,8 @@ var Collection = {
442
444
 
443
445
  V.before('0.8.0') && _.populateExtensions(collection, 'collection') && DONE;
444
446
  V.before('1.0.0-beta.1') && _.mapValues(collection, 'stac_extensions', ['assets'], ['item-assets']) && DONE;
447
+
448
+ return collection;
445
449
  },
446
450
 
447
451
  extent(collection) {
@@ -652,10 +656,43 @@ var Item = {
652
656
 
653
657
  // Also populate extensions if commons has been implemented
654
658
  (V.before('0.8.0') || commons) && _.populateExtensions(item, 'item') && DONE;
659
+
660
+ return item;
655
661
  }
656
662
 
657
663
  };
658
664
 
665
+ var CollectionCollection = {
666
+
667
+ migrate(object, updateVersionNumber = true) {
668
+ _.ensure(object, 'collections', []) && DONE;
669
+ _.ensure(object, 'links', []) && DONE;
670
+
671
+ _.runAll(CollectionCollection, object, object);
672
+
673
+ object.collections = object.collections.map(collection => Collection.migrate(collection, updateVersionNumber));
674
+
675
+ return object;
676
+ },
677
+
678
+ };
679
+
680
+ var ItemCollection = {
681
+
682
+ migrate(itemCollection, updateVersionNumber = true) {
683
+ _.ensure(itemCollection, 'type', 'FeatureCollection') && DONE;
684
+ _.ensure(itemCollection, 'features', []) && DONE;
685
+ _.ensure(itemCollection, 'links', []) && DONE;
686
+
687
+ _.runAll(ItemCollection, itemCollection, itemCollection);
688
+
689
+ itemCollection.features = itemCollection.features.map(feature => Item.migrate(feature, null, updateVersionNumber));
690
+
691
+ return itemCollection;
692
+ },
693
+
694
+ };
695
+
659
696
  var Asset = {
660
697
 
661
698
  migrateAll(context, field = 'assets') {
@@ -666,7 +703,10 @@ var Asset = {
666
703
 
667
704
  migrate(asset, context) {
668
705
  _.runAll(Asset, asset, context);
706
+
669
707
  Fields.migrate(asset, context);
708
+
709
+ return asset;
670
710
  },
671
711
 
672
712
  mediaTypes(asset) {
@@ -699,6 +739,8 @@ var Fields = {
699
739
 
700
740
  migrate(obj, context, summaries = false) {
701
741
  _.runAll(Fields, obj, context, summaries);
742
+
743
+ return obj;
702
744
  },
703
745
 
704
746
  _commonMetadata(obj) {
@@ -892,27 +934,38 @@ var Fields = {
892
934
  var Migrate = {
893
935
 
894
936
  item(item, collection = null, updateVersionNumber = true) {
895
- Item.migrate(item, collection, updateVersionNumber);
896
- return item;
937
+ return Item.migrate(item, collection, updateVersionNumber);
897
938
  },
898
939
 
899
940
  catalog(catalog, updateVersionNumber = true) {
900
- Catalog.migrate(catalog, updateVersionNumber);
901
- return catalog;
941
+ return Catalog.migrate(catalog, updateVersionNumber);
902
942
  },
903
943
 
904
944
  collection(collection, updateVersionNumber = true) {
905
- Collection.migrate(collection, updateVersionNumber);
906
- return collection;
945
+ return Collection.migrate(collection, updateVersionNumber);
946
+ },
947
+
948
+ collectionCollection(collections, updateVersionNumber = true) {
949
+ return CollectionCollection.migrate(collections, updateVersionNumber);
950
+ },
951
+
952
+ itemCollection(itemCollection, updateVersionNumber = true) {
953
+ return ItemCollection.migrate(itemCollection, updateVersionNumber);
907
954
  },
908
955
 
909
956
  stac(object, updateVersionNumber = true) {
910
957
  if (object.type === 'Feature') {
911
958
  return Migrate.item(object, null, updateVersionNumber);
912
959
  }
913
- else if (object.type === 'Collection' || _.isDefined(object.extent) || _.isDefined(object.license)) {
960
+ else if (object.type === 'FeatureCollection') {
961
+ return Migrate.itemCollection(object, updateVersionNumber);
962
+ }
963
+ else if (object.type === 'Collection' || (!object.type && _.isDefined(object.extent) && _.isDefined(object.license))) {
914
964
  return Migrate.collection(object, updateVersionNumber);
915
965
  }
966
+ else if (!object.type && Array.isArray(object.collections)) {
967
+ return Migrate.collectionCollection(object, updateVersionNumber);
968
+ }
916
969
  else {
917
970
  return Migrate.catalog(object, updateVersionNumber);
918
971
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantearth/stac-migrate",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "A library to update STAC files to the latest version.",
5
5
  "main": "migrate.js",
6
6
  "bin": {