@radiantearth/stac-migrate 1.4.0 → 1.6.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 (4) hide show
  1. package/README.md +66 -64
  2. package/bin/cli.js +17 -8
  3. package/migrate.js +25 -11
  4. package/package.json +39 -39
package/README.md CHANGED
@@ -1,64 +1,66 @@
1
- # stac-migrate
2
-
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
-
5
- Version of this library: **1.4.0**
6
-
7
- ## Usage
8
-
9
- ### JavaScript / Node
10
-
11
- Add to your project with `npm install @radiantearth/stac-migrate --save`
12
-
13
- Import the library: `const Migrate = require('@radiantearth/stac-migrate');`
14
-
15
- * Migrate (auto-detection): `Migrate.stac(stac: object, updateVersionNumber: boolean = true) => object`<br />
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, 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
- *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`
22
-
23
- **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
- ### CLI
26
-
27
- You can also use the CLI to migrate a single file.
28
- The commands follow the different methods above and has the same "restrictions" as above.
29
-
30
- * Migrate (auto-detection, override): `npx stac-migrate <source_path>`
31
- * Migrate (auto-detection, save to a different file with 4 spaces indentation): `npx stac-migrate <source_path> --dest <dest_path> --indent 4`
32
- * Migrate a STAC Collection: `npx stac-migrate <source_path> <dest_path> --collection`
33
- * Migrate a STAC Catalog: `npx stac-migrate <source_path> <dest_path> --catalog`
34
- * Migrate a STAC Item: `npx stac-migrate <source_path> <dest_path> --item --collection_path <collection_path>`
35
- * Migrate a STAC Item Collection: `npx stac-migrate <source_path> <dest_path> --item_collection`
36
-
37
- ## Supported Extensions
38
-
39
- * Checksum (legacy, use `Migrate.enableMultihash(require('multihashes'))` to enable conversion from pre-0.9 checksums - disabled by default to keep the bundle size low)
40
- * Classification 1.1.0
41
- * Collection Assets (legacy)
42
- * Commons (legacy)
43
- * Data Cube 2.1.0
44
- * Datetime Range (legacy)
45
- * Electro-Optical 1.0.0
46
- * File 1.0.0
47
- * (Item) Asset Definition 1.0.0
48
- * Label 1.0.1
49
- * Point Cloud 1.0.0
50
- * Procesing 1.1.0
51
- * Projection 1.0.0
52
- * Raster 1.1.0
53
- * SAR 1.0.0
54
- * Satellite 1.0.0
55
- * Scientific Citation 1.0.0
56
- * Single Item
57
- * Table 1.2.0
58
- * Timestamps 1.0.0
59
- * Versioning Indicators 1.0.0
60
- * View Geometry 1.0.0
61
-
62
- ## Development
63
-
64
- Run the tests: `npm test`
1
+ # stac-migrate
2
+
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
+
5
+ Version of this library: **1.6.0**
6
+
7
+ ## Usage
8
+
9
+ ### JavaScript / Node
10
+
11
+ Add to your project with `npm install @radiantearth/stac-migrate --save`
12
+
13
+ Import the library: `const Migrate = require('@radiantearth/stac-migrate');`
14
+
15
+ * Migrate (auto-detection): `Migrate.stac(stac: object, updateVersionNumber: boolean = true) => object`<br />
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, 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
+ *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`
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));`.
25
+
26
+ ### CLI
27
+
28
+ You can also use the CLI to migrate a single file.
29
+ The commands follow the different methods above and has the same "restrictions" as above.
30
+
31
+ * Migrate (auto-detection, override): `npx stac-migrate <source_path>`
32
+ * Migrate (auto-detection, save to a different file with 4 spaces indentation): `npx stac-migrate <source_path> --dest <dest_path> --indent 4`
33
+ * Migrate a STAC Collection: `npx stac-migrate <source_path> <dest_path> --collection`
34
+ * Migrate a STAC Catalog: `npx stac-migrate <source_path> <dest_path> --catalog`
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`
38
+
39
+ ## Supported Extensions
40
+
41
+ * Checksum (legacy, use `Migrate.enableMultihash(require('multihashes'))` to enable conversion from pre-0.9 checksums - disabled by default to keep the bundle size low)
42
+ * Classification 1.1.0
43
+ * Collection Assets (legacy)
44
+ * Commons (legacy)
45
+ * Data Cube 2.1.0
46
+ * Datetime Range (legacy)
47
+ * Electro-Optical 1.0.0
48
+ * File 1.0.0
49
+ * (Item) Asset Definition 1.0.0
50
+ * Label 1.0.1
51
+ * Point Cloud 1.0.0
52
+ * Procesing 1.1.0
53
+ * Projection 1.0.0
54
+ * Raster 1.1.0
55
+ * SAR 1.0.0
56
+ * Satellite 1.0.0
57
+ * Scientific Citation 1.0.0
58
+ * Single Item
59
+ * Table 1.2.0
60
+ * Timestamps 1.0.0
61
+ * Versioning Indicators 1.0.0
62
+ * View Geometry 1.0.0
63
+
64
+ ## Development
65
+
66
+ Run the tests: `npm test`
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
@@ -406,14 +406,6 @@ var Catalog = {
406
406
  return catalog;
407
407
  },
408
408
 
409
- openeo(obj) {
410
- _.rename(obj, 'api_version', 'openeo:api_version') && DONE;
411
- _.rename(obj, 'backend_version', 'openeo:backend_version') && DONE;
412
- _.rename(obj, 'production', 'openeo:production') && DONE;
413
- _.rename(obj, 'endpoints', 'openeo:endpoints') && DONE;
414
- _.rename(obj, 'billing', 'openeo:billing') && DONE;
415
- },
416
-
417
409
  };
418
410
 
419
411
  var Collection = {
@@ -556,7 +548,7 @@ var Collection = {
556
548
  _.ensure(collection, 'summaries', {});
557
549
 
558
550
  // other_properties: An early version of the Collection summaries with a similar structure
559
- // Was mostly used in standalone collctions from openEO and GEE. Move other_properties to summaries.
551
+ // Was mostly used in standalone collections from openEO and GEE. Move other_properties to summaries.
560
552
  if (V.before('0.8.0') && _.isObject(collection.other_properties)) {
561
553
  for(let key in collection.other_properties) {
562
554
  let prop = collection.other_properties[key];
@@ -662,6 +654,21 @@ var Item = {
662
654
 
663
655
  };
664
656
 
657
+ var CollectionCollection = {
658
+
659
+ migrate(object, updateVersionNumber = true) {
660
+ _.ensure(object, 'collections', []) && DONE;
661
+ _.ensure(object, 'links', []) && DONE;
662
+
663
+ _.runAll(CollectionCollection, object, object);
664
+
665
+ object.collections = object.collections.map(collection => Collection.migrate(collection, updateVersionNumber));
666
+
667
+ return object;
668
+ },
669
+
670
+ };
671
+
665
672
  var ItemCollection = {
666
673
 
667
674
  migrate(itemCollection, updateVersionNumber = true) {
@@ -930,6 +937,10 @@ var Migrate = {
930
937
  return Collection.migrate(collection, updateVersionNumber);
931
938
  },
932
939
 
940
+ collectionCollection(collections, updateVersionNumber = true) {
941
+ return CollectionCollection.migrate(collections, updateVersionNumber);
942
+ },
943
+
933
944
  itemCollection(itemCollection, updateVersionNumber = true) {
934
945
  return ItemCollection.migrate(itemCollection, updateVersionNumber);
935
946
  },
@@ -941,9 +952,12 @@ var Migrate = {
941
952
  else if (object.type === 'FeatureCollection') {
942
953
  return Migrate.itemCollection(object, updateVersionNumber);
943
954
  }
944
- else if (object.type === 'Collection' || _.isDefined(object.extent) || _.isDefined(object.license)) {
955
+ else if (object.type === 'Collection' || (!object.type && _.isDefined(object.extent) && _.isDefined(object.license))) {
945
956
  return Migrate.collection(object, updateVersionNumber);
946
957
  }
958
+ else if (!object.type && Array.isArray(object.collections)) {
959
+ return Migrate.collectionCollection(object, updateVersionNumber);
960
+ }
947
961
  else {
948
962
  return Migrate.catalog(object, updateVersionNumber);
949
963
  }
@@ -955,4 +969,4 @@ var Migrate = {
955
969
 
956
970
  };
957
971
 
958
- module.exports = Migrate;
972
+ module.exports = Migrate;
package/package.json CHANGED
@@ -1,39 +1,39 @@
1
- {
2
- "name": "@radiantearth/stac-migrate",
3
- "version": "1.4.0",
4
- "description": "A library to update STAC files to the latest version.",
5
- "main": "migrate.js",
6
- "bin": {
7
- "stac-migrate": "./bin/cli.js"
8
- },
9
- "bugs": {
10
- "url": "https://github.com/stac-utils/stac-migrate/issues"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/stac-utils/stac-migrate.git"
15
- },
16
- "author": "Radiant Earth Foundation <hello@radiant.earth>",
17
- "contributors": [
18
- {
19
- "name": "Matthias Mohr"
20
- }
21
- ],
22
- "license": "Apache-2.0",
23
- "dependencies": {
24
- "compare-versions": "^3.6.0",
25
- "multihashes": "^3.1.2",
26
- "yargs": "^17.6.2"
27
- },
28
- "devDependencies": {
29
- "jest": "^29.0.0",
30
- "jest-html-reporter": "^3.3.0"
31
- },
32
- "files": [
33
- "bin/cli.js",
34
- "migrate.js"
35
- ],
36
- "scripts": {
37
- "test": " jest"
38
- }
39
- }
1
+ {
2
+ "name": "@radiantearth/stac-migrate",
3
+ "version": "1.6.0",
4
+ "description": "A library to update STAC files to the latest version.",
5
+ "main": "migrate.js",
6
+ "bin": {
7
+ "stac-migrate": "./bin/cli.js"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/stac-utils/stac-migrate/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/stac-utils/stac-migrate.git"
15
+ },
16
+ "author": "Radiant Earth Foundation <hello@radiant.earth>",
17
+ "contributors": [
18
+ {
19
+ "name": "Matthias Mohr"
20
+ }
21
+ ],
22
+ "license": "Apache-2.0",
23
+ "dependencies": {
24
+ "compare-versions": "^3.6.0",
25
+ "multihashes": "^3.1.2",
26
+ "yargs": "^17.6.2"
27
+ },
28
+ "devDependencies": {
29
+ "jest": "^29.0.0",
30
+ "jest-html-reporter": "^3.3.0"
31
+ },
32
+ "files": [
33
+ "bin/cli.js",
34
+ "migrate.js"
35
+ ],
36
+ "scripts": {
37
+ "test": " jest"
38
+ }
39
+ }