@radiantearth/stac-migrate 2.0.0-beta.1 → 2.0.1
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 +4 -4
- package/migrate.js +27 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# stac-migrate
|
|
2
2
|
|
|
3
|
-
A library to update STAC files to the latest version (**1.1.0
|
|
3
|
+
A library to update STAC files to the latest version (**1.1.0** at the moment of writing).
|
|
4
4
|
Supports updating **STAC versions 0.6.0 and later**.
|
|
5
5
|
|
|
6
|
-
Version of this library: **2.0.
|
|
6
|
+
Version of this library: **2.0.1**
|
|
7
7
|
|
|
8
8
|
## Usage
|
|
9
9
|
|
|
@@ -46,14 +46,14 @@ The commands follow the different methods above and has the same "restrictions"
|
|
|
46
46
|
* Commons (legacy)
|
|
47
47
|
* Data Cube 2.2.0
|
|
48
48
|
* Datetime Range (legacy)
|
|
49
|
-
* Electro-Optical 2.0.0
|
|
49
|
+
* Electro-Optical 2.0.0
|
|
50
50
|
* File 2.1.0 (and 1.0.0 for `nodata`)
|
|
51
51
|
* Item Asset Definition 1.0.0 (legacy)
|
|
52
52
|
* Label 1.0.1
|
|
53
53
|
* Point Cloud 1.0.0
|
|
54
54
|
* Processing 1.2.0
|
|
55
55
|
* Projection 2.0.0
|
|
56
|
-
* Raster 2.0.0
|
|
56
|
+
* Raster 2.0.0
|
|
57
57
|
* SAR 1.0.0
|
|
58
58
|
* Satellite 1.0.0
|
|
59
59
|
* Scientific Citation 1.0.0
|
package/migrate.js
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
var compareVersions = require('compare-versions');
|
|
6
6
|
|
|
7
|
-
const LATEST_VERSION = '1.1.0
|
|
7
|
+
const LATEST_VERSION = '1.1.0';
|
|
8
8
|
const DONE = true; // This is used to verify in code coverage whether something has been used or not
|
|
9
9
|
const SCHEMAS = {
|
|
10
10
|
'classification': 'https://stac-extensions.github.io/classification/v2.0.0/schema.json',
|
|
11
11
|
'datacube': 'https://stac-extensions.github.io/datacube/v2.2.0/schema.json',
|
|
12
|
-
'eo': 'https://stac-extensions.github.io/eo/v2.0.0
|
|
12
|
+
'eo': 'https://stac-extensions.github.io/eo/v2.0.0/schema.json',
|
|
13
13
|
'file': 'https://stac-extensions.github.io/file/v2.1.0/schema.json',
|
|
14
14
|
'item-assets': 'https://stac-extensions.github.io/item-assets/v1.0.0/schema.json',
|
|
15
15
|
'label': 'https://stac-extensions.github.io/label/v1.0.1/schema.json',
|
|
16
16
|
'pointcloud': 'https://stac-extensions.github.io/pointcloud/v1.0.0/schema.json',
|
|
17
17
|
'processing': 'https://stac-extensions.github.io/processing/v1.2.0/schema.json',
|
|
18
18
|
'projection': 'https://stac-extensions.github.io/projection/v2.0.0/schema.json',
|
|
19
|
-
'raster': 'https://stac-extensions.github.io/raster/v2.0.0
|
|
19
|
+
'raster': 'https://stac-extensions.github.io/raster/v2.0.0/schema.json',
|
|
20
20
|
'sar': 'https://stac-extensions.github.io/sar/v1.0.0/schema.json',
|
|
21
21
|
'sat': 'https://stac-extensions.github.io/sat/v1.0.0/schema.json',
|
|
22
22
|
'scientific': 'https://stac-extensions.github.io/scientific/v1.0.0/schema.json',
|
|
@@ -63,7 +63,8 @@ EXTENSIONS.collection = Object.assign(EXTENSIONS.collection, EXTENSIONS.itemAndC
|
|
|
63
63
|
EXTENSIONS.item = Object.assign(EXTENSIONS.item, EXTENSIONS.itemAndCollection);
|
|
64
64
|
|
|
65
65
|
var Ext = {
|
|
66
|
-
|
|
66
|
+
parseExtension(url) {
|
|
67
|
+
// Try to match name and version from official extensions
|
|
67
68
|
let match = url.match(/^https?:\/\/stac-extensions.github.io\/([^\/]+)\/v([^\/]+)\/[^.]+.json$/i);
|
|
68
69
|
if (match) {
|
|
69
70
|
return {
|
|
@@ -71,6 +72,21 @@ var Ext = {
|
|
|
71
72
|
version: match[2]
|
|
72
73
|
};
|
|
73
74
|
}
|
|
75
|
+
// Try to match version from URIs
|
|
76
|
+
let match2 = url.match(/(\d+\.\d+(\.\d+)([a-z_.-][\w.-]+)?)/i);
|
|
77
|
+
if (match2) {
|
|
78
|
+
return {
|
|
79
|
+
id: url,
|
|
80
|
+
version: match2[1]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Handle schortnames
|
|
84
|
+
if (url in SCHEMAS) {
|
|
85
|
+
return {
|
|
86
|
+
id: url,
|
|
87
|
+
version: '0.0.0'
|
|
88
|
+
};
|
|
89
|
+
}
|
|
74
90
|
}
|
|
75
91
|
};
|
|
76
92
|
|
|
@@ -88,7 +104,7 @@ var V = {
|
|
|
88
104
|
|
|
89
105
|
if (Array.isArray(stac.stac_extensions)) {
|
|
90
106
|
for (let ext of stac.stac_extensions) {
|
|
91
|
-
let e = Ext.
|
|
107
|
+
let e = Ext.parseExtension(ext);
|
|
92
108
|
if (e) {
|
|
93
109
|
V.extensions[e.id] = e.version;
|
|
94
110
|
}
|
|
@@ -234,9 +250,9 @@ var _ = {
|
|
|
234
250
|
},
|
|
235
251
|
|
|
236
252
|
upgradeExtension(context, extension) {
|
|
237
|
-
let { id, version } = Ext.
|
|
253
|
+
let { id, version } = Ext.parseExtension(extension);
|
|
238
254
|
let index = context.stac_extensions.findIndex(url => {
|
|
239
|
-
let old = Ext.
|
|
255
|
+
let old = Ext.parseExtension(url);
|
|
240
256
|
return (old && old.id === id && compareVersions.compare(old.version, version, '<'));
|
|
241
257
|
});
|
|
242
258
|
if (index !== -1) {
|
|
@@ -249,12 +265,12 @@ var _ = {
|
|
|
249
265
|
},
|
|
250
266
|
|
|
251
267
|
addExtension(context, newExtension) {
|
|
252
|
-
let { id, version } = Ext.
|
|
268
|
+
let { id, version } = Ext.parseExtension(newExtension);
|
|
253
269
|
let index = context.stac_extensions.findIndex(url => {
|
|
254
270
|
if (url === newExtension) {
|
|
255
271
|
return true;
|
|
256
272
|
}
|
|
257
|
-
let old = Ext.
|
|
273
|
+
let old = Ext.parseExtension(url);
|
|
258
274
|
if (old && old.id === id && compareVersions.compare(old.version, version, '<')) {
|
|
259
275
|
return true;
|
|
260
276
|
}
|
|
@@ -929,8 +945,8 @@ var Fields = {
|
|
|
929
945
|
|
|
930
946
|
file(obj, context, summaries) {
|
|
931
947
|
_.rename(obj, 'file:bits_per_sample', 'raster:bits_per_sample') && _.addExtension(context, SCHEMAS.raster) && DONE;
|
|
932
|
-
_.rename(obj, 'file:data_type', 'data_type') &&
|
|
933
|
-
_.rename(obj, 'file:unit', 'unit') &&
|
|
948
|
+
_.rename(obj, 'file:data_type', 'data_type') && DONE;
|
|
949
|
+
_.rename(obj, 'file:unit', 'unit') && DONE;
|
|
934
950
|
|
|
935
951
|
if (Array.isArray(obj['file:nodata']) && obj['file:nodata'].length > 1) {
|
|
936
952
|
// In case of more than one no-data value we need to create a custom property
|