@radiantearth/stac-migrate 1.4.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.4.0**
5
+ Version of this library: **1.5.0**
6
6
 
7
7
  ## Usage
8
8
 
@@ -18,7 +18,8 @@ Import the library: `const Migrate = require('@radiantearth/stac-migrate');`
18
18
  * Migrate a STAC Catalog: `Migrate.catalog(catalog: object, updateVersionNumber: boolean = true) => object`
19
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 ItemCollection: `Migrate.itemCollection(catalog: object, updateVersionNumber: boolean = true) => object`
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`
22
23
 
23
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));`.
24
25
 
@@ -33,6 +34,7 @@ The commands follow the different methods above and has the same "restrictions"
33
34
  * Migrate a STAC Catalog: `npx stac-migrate <source_path> <dest_path> --catalog`
34
35
  * Migrate a STAC Item: `npx stac-migrate <source_path> <dest_path> --item --collection_path <collection_path>`
35
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`
36
38
 
37
39
  ## Supported Extensions
38
40
 
package/bin/cli.js CHANGED
@@ -18,28 +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', 'item_collection'],
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', 'item_collection']
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', 'item_collection']
32
+ conflicts: ['catalog', 'collection', 'collections', 'item_collection']
33
33
  })
34
34
  .option('item_collection', {
35
35
  type: 'boolean',
36
36
  description: 'Enforce the item collection migration',
37
- conflicts: ['catalog', 'collection', 'item']
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']
38
43
  })
39
44
  .option('collection_path', {
40
45
  type: 'string',
41
46
  description: 'Pass the path to a collection to the item, only possible if --item has been specified.',
42
- conflicts: ['catalog', 'collection', 'item_collection']
47
+ conflicts: ['catalog', 'collection', 'collections', 'item_collection']
43
48
  })
44
49
  .option('indent', {
45
50
  type: 'number',
@@ -53,9 +58,13 @@ run(args);
53
58
 
54
59
  function run(args) {
55
60
  console.log("STAC Migrate v" + package.version);
56
- let fn = ['collection', 'catalog', 'item', 'item_collection'].find(type => Boolean(args[type])) || 'stac';
57
- if (fn === 'item_collection') {
58
- fn = 'itemCollection';
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];
59
68
  }
60
69
  if (args._.length !== 1) {
61
70
  throw new Error("Please provide exactly one source file.");
package/migrate.js CHANGED
@@ -662,6 +662,21 @@ var Item = {
662
662
 
663
663
  };
664
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
+
665
680
  var ItemCollection = {
666
681
 
667
682
  migrate(itemCollection, updateVersionNumber = true) {
@@ -930,6 +945,10 @@ var Migrate = {
930
945
  return Collection.migrate(collection, updateVersionNumber);
931
946
  },
932
947
 
948
+ collectionCollection(collections, updateVersionNumber = true) {
949
+ return CollectionCollection.migrate(collections, updateVersionNumber);
950
+ },
951
+
933
952
  itemCollection(itemCollection, updateVersionNumber = true) {
934
953
  return ItemCollection.migrate(itemCollection, updateVersionNumber);
935
954
  },
@@ -941,9 +960,12 @@ var Migrate = {
941
960
  else if (object.type === 'FeatureCollection') {
942
961
  return Migrate.itemCollection(object, updateVersionNumber);
943
962
  }
944
- else if (object.type === 'Collection' || _.isDefined(object.extent) || _.isDefined(object.license)) {
963
+ else if (object.type === 'Collection' || (!object.type && _.isDefined(object.extent) && _.isDefined(object.license))) {
945
964
  return Migrate.collection(object, updateVersionNumber);
946
965
  }
966
+ else if (!object.type && Array.isArray(object.collections)) {
967
+ return Migrate.collectionCollection(object, updateVersionNumber);
968
+ }
947
969
  else {
948
970
  return Migrate.catalog(object, updateVersionNumber);
949
971
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radiantearth/stac-migrate",
3
- "version": "1.4.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": {