@cumulus/ingest 13.0.1 → 13.1.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/package.json +14 -14
- package/src/url-path-template.js +19 -5
- package/tsconfig.tsbuildinfo +1 -1
- package/url-path-template.d.ts.map +1 -1
- package/url-path-template.js +17 -5
- package/url-path-template.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/ingest",
|
|
3
|
-
"version": "13.0
|
|
3
|
+
"version": "13.1.0",
|
|
4
4
|
"description": "Ingest utilities",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=14.19.1"
|
|
@@ -38,19 +38,19 @@
|
|
|
38
38
|
"author": "Cumulus Authors",
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@cumulus/aws-client": "13.0
|
|
42
|
-
"@cumulus/common": "13.0
|
|
43
|
-
"@cumulus/db": "13.0
|
|
44
|
-
"@cumulus/errors": "13.0
|
|
45
|
-
"@cumulus/logger": "13.0
|
|
46
|
-
"@cumulus/message": "13.0
|
|
47
|
-
"@cumulus/sftp-client": "13.0
|
|
41
|
+
"@cumulus/aws-client": "13.1.0",
|
|
42
|
+
"@cumulus/common": "13.1.0",
|
|
43
|
+
"@cumulus/db": "13.1.0",
|
|
44
|
+
"@cumulus/errors": "13.1.0",
|
|
45
|
+
"@cumulus/logger": "13.1.0",
|
|
46
|
+
"@cumulus/message": "13.1.0",
|
|
47
|
+
"@cumulus/sftp-client": "13.1.0",
|
|
48
48
|
"aws-sdk": "^2.585.0",
|
|
49
49
|
"cksum": "^1.3.0",
|
|
50
50
|
"delay": "^4.3.0",
|
|
51
51
|
"encodeurl": "^1.0.2",
|
|
52
52
|
"fs-extra": "^5.0.0",
|
|
53
|
-
"got": "^11.
|
|
53
|
+
"got": "^11.8.5",
|
|
54
54
|
"is-ip": "^2.0.0",
|
|
55
55
|
"is-valid-hostname": "^0.1.1",
|
|
56
56
|
"jsftp": "https://github.com/jkovarik/jsftp.git#add_288",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"tough-cookie": "^4.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@cumulus/checksum": "13.0
|
|
65
|
-
"@cumulus/cmrjs": "13.0
|
|
66
|
-
"@cumulus/test-data": "13.0
|
|
67
|
-
"@cumulus/types": "13.0
|
|
64
|
+
"@cumulus/checksum": "13.1.0",
|
|
65
|
+
"@cumulus/cmrjs": "13.1.0",
|
|
66
|
+
"@cumulus/test-data": "13.1.0",
|
|
67
|
+
"@cumulus/types": "13.1.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "1966c485551680a65e665ecb30c05a8fadad0d08"
|
|
70
70
|
}
|
package/src/url-path-template.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const get = require('lodash/get');
|
|
2
2
|
const moment = require('moment');
|
|
3
|
+
const path = require('path');
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* evaluate the operation specified in template
|
|
@@ -29,6 +30,9 @@ function evaluateOperation(name, args) {
|
|
|
29
30
|
case 'substring': {
|
|
30
31
|
return String.prototype.substring.apply(String(valueStr), args.slice(1));
|
|
31
32
|
}
|
|
33
|
+
case 'extractPath': {
|
|
34
|
+
return path.dirname(valueStr);
|
|
35
|
+
}
|
|
32
36
|
default:
|
|
33
37
|
throw new Error(`Could not support operation ${name}`);
|
|
34
38
|
}
|
|
@@ -46,17 +50,21 @@ function templateReplacer(context, submatch) {
|
|
|
46
50
|
const expressionRegex = /([^(]+)\(([^)]+)\)/;
|
|
47
51
|
const matches = submatch.match(expressionRegex);
|
|
48
52
|
|
|
49
|
-
// submatch contains operation
|
|
53
|
+
// submatch contains operation and args
|
|
50
54
|
if (submatch.match(expressionRegex)) {
|
|
51
55
|
const name = matches[1];
|
|
52
56
|
const args = matches[2].split(/\s*,\s*/);
|
|
53
|
-
|
|
57
|
+
// args[0] is either an object path or a constant
|
|
58
|
+
// e.g. extractPath(file.path) or extractPath('/a/b/c')
|
|
59
|
+
// assume args[0] is an object path if it starts with a key of context
|
|
60
|
+
const isObjectPath = Object.keys(context).includes(args[0].split('.')[0]);
|
|
61
|
+
const jsonPathValue = get(context, args[0], isObjectPath ? undefined : args[0]);
|
|
54
62
|
if (!jsonPathValue) throw new Error(`Could not resolve path ${args[0]}`);
|
|
55
63
|
args[0] = jsonPathValue;
|
|
56
64
|
return evaluateOperation(name, args);
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
const jsonPathValue = get(context, submatch
|
|
67
|
+
const jsonPathValue = get(context, submatch);
|
|
60
68
|
if (!jsonPathValue) throw new Error(`Could not resolve path ${submatch}`);
|
|
61
69
|
return jsonPathValue;
|
|
62
70
|
}
|
|
@@ -70,11 +78,17 @@ function templateReplacer(context, submatch) {
|
|
|
70
78
|
* @returns {string} - the url path for the file
|
|
71
79
|
**/
|
|
72
80
|
function urlPathTemplate(pathTemplate, context) {
|
|
73
|
-
const templateRegex = /{([^}]+)}/g;
|
|
81
|
+
const templateRegex = /{([^{}]+)}/g;
|
|
82
|
+
|
|
74
83
|
try {
|
|
75
84
|
// match: The matched substring, submatch: The parenthesized submatch string
|
|
76
|
-
|
|
85
|
+
const replacedPath = pathTemplate.replace(templateRegex, (match, submatch) =>
|
|
77
86
|
templateReplacer(context, submatch));
|
|
87
|
+
|
|
88
|
+
if (replacedPath.match(templateRegex)) {
|
|
89
|
+
return urlPathTemplate(replacedPath, context);
|
|
90
|
+
}
|
|
91
|
+
return replacedPath;
|
|
78
92
|
} catch (error) {
|
|
79
93
|
throw new Error(
|
|
80
94
|
`Could not resolve path template "${pathTemplate}" with error "${error.toString()}"`
|