@radiantearth/stac-migrate 1.3.0 → 1.4.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 +7 -5
- package/bin/cli.js +14 -6
- package/migrate.js +37 -6
- 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.
|
|
5
|
+
Version of this library: **1.4.0**
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
@@ -12,12 +12,13 @@ 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 ItemCollection: `Migrate.itemCollection(catalog: object, updateVersionNumber: boolean = true) => object`
|
|
21
22
|
|
|
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));`.
|
|
23
24
|
|
|
@@ -31,6 +32,7 @@ The commands follow the different methods above and has the same "restrictions"
|
|
|
31
32
|
* Migrate a STAC Collection: `npx stac-migrate <source_path> <dest_path> --collection`
|
|
32
33
|
* Migrate a STAC Catalog: `npx stac-migrate <source_path> <dest_path> --catalog`
|
|
33
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`
|
|
34
36
|
|
|
35
37
|
## Supported Extensions
|
|
36
38
|
|
package/bin/cli.js
CHANGED
|
@@ -18,23 +18,28 @@ 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', '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', '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', 'item_collection']
|
|
33
|
+
})
|
|
34
|
+
.option('item_collection', {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
description: 'Enforce the item collection migration',
|
|
37
|
+
conflicts: ['catalog', 'collection', 'item']
|
|
33
38
|
})
|
|
34
39
|
.option('collection_path', {
|
|
35
40
|
type: 'string',
|
|
36
41
|
description: 'Pass the path to a collection to the item, only possible if --item has been specified.',
|
|
37
|
-
conflicts: ['catalog', 'collection']
|
|
42
|
+
conflicts: ['catalog', 'collection', 'item_collection']
|
|
38
43
|
})
|
|
39
44
|
.option('indent', {
|
|
40
45
|
type: 'number',
|
|
@@ -48,9 +53,12 @@ run(args);
|
|
|
48
53
|
|
|
49
54
|
function run(args) {
|
|
50
55
|
console.log("STAC Migrate v" + package.version);
|
|
51
|
-
let fn = ['collection', 'catalog', 'item'].find(type => Boolean(args[type])) || 'stac';
|
|
56
|
+
let fn = ['collection', 'catalog', 'item', 'item_collection'].find(type => Boolean(args[type])) || 'stac';
|
|
57
|
+
if (fn === 'item_collection') {
|
|
58
|
+
fn = 'itemCollection';
|
|
59
|
+
}
|
|
52
60
|
if (args._.length !== 1) {
|
|
53
|
-
throw new Error("Please provide
|
|
61
|
+
throw new Error("Please provide exactly one source file.");
|
|
54
62
|
}
|
|
55
63
|
let src = args._[0];
|
|
56
64
|
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,28 @@ 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 ItemCollection = {
|
|
666
|
+
|
|
667
|
+
migrate(itemCollection, updateVersionNumber = true) {
|
|
668
|
+
_.ensure(itemCollection, 'type', 'FeatureCollection') && DONE;
|
|
669
|
+
_.ensure(itemCollection, 'features', []) && DONE;
|
|
670
|
+
_.ensure(itemCollection, 'links', []) && DONE;
|
|
671
|
+
|
|
672
|
+
_.runAll(ItemCollection, itemCollection, itemCollection);
|
|
673
|
+
|
|
674
|
+
itemCollection.features = itemCollection.features.map(feature => Item.migrate(feature, null, updateVersionNumber));
|
|
675
|
+
|
|
676
|
+
return itemCollection;
|
|
677
|
+
},
|
|
678
|
+
|
|
679
|
+
};
|
|
680
|
+
|
|
659
681
|
var Asset = {
|
|
660
682
|
|
|
661
683
|
migrateAll(context, field = 'assets') {
|
|
@@ -666,7 +688,10 @@ var Asset = {
|
|
|
666
688
|
|
|
667
689
|
migrate(asset, context) {
|
|
668
690
|
_.runAll(Asset, asset, context);
|
|
691
|
+
|
|
669
692
|
Fields.migrate(asset, context);
|
|
693
|
+
|
|
694
|
+
return asset;
|
|
670
695
|
},
|
|
671
696
|
|
|
672
697
|
mediaTypes(asset) {
|
|
@@ -699,6 +724,8 @@ var Fields = {
|
|
|
699
724
|
|
|
700
725
|
migrate(obj, context, summaries = false) {
|
|
701
726
|
_.runAll(Fields, obj, context, summaries);
|
|
727
|
+
|
|
728
|
+
return obj;
|
|
702
729
|
},
|
|
703
730
|
|
|
704
731
|
_commonMetadata(obj) {
|
|
@@ -892,24 +919,28 @@ var Fields = {
|
|
|
892
919
|
var Migrate = {
|
|
893
920
|
|
|
894
921
|
item(item, collection = null, updateVersionNumber = true) {
|
|
895
|
-
Item.migrate(item, collection, updateVersionNumber);
|
|
896
|
-
return item;
|
|
922
|
+
return Item.migrate(item, collection, updateVersionNumber);
|
|
897
923
|
},
|
|
898
924
|
|
|
899
925
|
catalog(catalog, updateVersionNumber = true) {
|
|
900
|
-
Catalog.migrate(catalog, updateVersionNumber);
|
|
901
|
-
return catalog;
|
|
926
|
+
return Catalog.migrate(catalog, updateVersionNumber);
|
|
902
927
|
},
|
|
903
928
|
|
|
904
929
|
collection(collection, updateVersionNumber = true) {
|
|
905
|
-
Collection.migrate(collection, updateVersionNumber);
|
|
906
|
-
|
|
930
|
+
return Collection.migrate(collection, updateVersionNumber);
|
|
931
|
+
},
|
|
932
|
+
|
|
933
|
+
itemCollection(itemCollection, updateVersionNumber = true) {
|
|
934
|
+
return ItemCollection.migrate(itemCollection, updateVersionNumber);
|
|
907
935
|
},
|
|
908
936
|
|
|
909
937
|
stac(object, updateVersionNumber = true) {
|
|
910
938
|
if (object.type === 'Feature') {
|
|
911
939
|
return Migrate.item(object, null, updateVersionNumber);
|
|
912
940
|
}
|
|
941
|
+
else if (object.type === 'FeatureCollection') {
|
|
942
|
+
return Migrate.itemCollection(object, updateVersionNumber);
|
|
943
|
+
}
|
|
913
944
|
else if (object.type === 'Collection' || _.isDefined(object.extent) || _.isDefined(object.license)) {
|
|
914
945
|
return Migrate.collection(object, updateVersionNumber);
|
|
915
946
|
}
|