@cumulus/ingest 20.3.0 → 21.0.0-echo10
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/granule.d.ts +15 -3
- package/granule.d.ts.map +1 -1
- package/granule.js +31 -4
- package/granule.js.map +1 -1
- package/package.json +13 -13
- package/providerClientUtils.d.ts +3 -2
- package/providerClientUtils.d.ts.map +1 -1
- package/providerClientUtils.js +2 -1
- package/providerClientUtils.js.map +1 -1
- package/src/granule.ts +36 -6
- package/src/providerClientUtils.js +2 -1
- package/src/url-path-template.js +34 -26
- package/tsconfig.tsbuildinfo +1 -1
- package/url-path-template.d.ts.map +1 -1
- package/url-path-template.js +29 -25
- package/url-path-template.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-path-template.d.ts","sourceRoot":"","sources":["src/url-path-template.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"url-path-template.d.ts","sourceRoot":"","sources":["src/url-path-template.js"],"names":[],"mappings":"AAiFA;;;;;;;GAOG;AACH,8CALU,MAAM,WAEN,MAAM,GACJ,MAAM,CAiBjB"}
|
package/url-path-template.js
CHANGED
|
@@ -3,35 +3,47 @@ const get = require('lodash/get');
|
|
|
3
3
|
const moment = require('moment');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
/**
|
|
6
|
-
* evaluate the operation specified in template
|
|
7
|
-
*
|
|
8
|
-
* @param {string} name - the name of the operation
|
|
9
|
-
* @param {
|
|
10
|
-
* @
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
* evaluate the operation specified in template
|
|
7
|
+
*
|
|
8
|
+
* @param {string} name - the name of the operation
|
|
9
|
+
* @param {object} args - the args (in array) of the operation
|
|
10
|
+
* @param {object} context - the metadata used in the template
|
|
11
|
+
* @returns {string} - the return value of the operation
|
|
12
|
+
*/
|
|
13
|
+
function evaluateOperation(name, args, context) {
|
|
14
|
+
// args[0] is either an object path or a constant
|
|
15
|
+
// e.g. extractPath(file.path) or extractPath('/a/b/c')
|
|
16
|
+
// assume args[0] is an object path if it starts with a key of context
|
|
17
|
+
const isObjectPath = Object.keys(context).includes(args[0].split('.')[0]);
|
|
18
|
+
const jsonPathValue = get(context, args[0], isObjectPath ? undefined : args[0]);
|
|
19
|
+
if (name !== 'defaultTo' && !jsonPathValue)
|
|
20
|
+
throw new Error(`Could not resolve path ${args[0]}`);
|
|
14
21
|
switch (name) {
|
|
15
22
|
case 'extractYear': {
|
|
16
|
-
return new Date(
|
|
23
|
+
return new Date(jsonPathValue).getUTCFullYear();
|
|
17
24
|
}
|
|
18
25
|
case 'extractMonth': {
|
|
19
|
-
return (new Date(
|
|
26
|
+
return (new Date(jsonPathValue).getUTCMonth() + 1).toString();
|
|
20
27
|
}
|
|
21
28
|
case 'extractDate': {
|
|
22
|
-
return new Date(
|
|
29
|
+
return new Date(jsonPathValue).getUTCDate().toString();
|
|
23
30
|
}
|
|
24
31
|
case 'extractHour': {
|
|
25
|
-
return new Date(
|
|
32
|
+
return new Date(jsonPathValue).getUTCHours().toString();
|
|
26
33
|
}
|
|
27
34
|
case 'dateFormat': {
|
|
28
|
-
return moment.utc(
|
|
35
|
+
return moment.utc(jsonPathValue).format(args[1]);
|
|
29
36
|
}
|
|
30
37
|
case 'substring': {
|
|
31
|
-
return String.prototype.substring.apply(String(
|
|
38
|
+
return String.prototype.substring.apply(String(jsonPathValue), args.slice(1));
|
|
32
39
|
}
|
|
33
40
|
case 'extractPath': {
|
|
34
|
-
return path.dirname(
|
|
41
|
+
return path.dirname(jsonPathValue);
|
|
42
|
+
}
|
|
43
|
+
case 'defaultTo': {
|
|
44
|
+
const isObjectPathSecondArg = Object.keys(context).includes(args[1].split('.')[0]);
|
|
45
|
+
const jsonPathValueSecondArg = get(context, args[1], isObjectPathSecondArg ? undefined : args[1]);
|
|
46
|
+
return jsonPathValue || jsonPathValueSecondArg;
|
|
35
47
|
}
|
|
36
48
|
default:
|
|
37
49
|
throw new Error(`Could not support operation ${name}`);
|
|
@@ -40,7 +52,7 @@ function evaluateOperation(name, args) {
|
|
|
40
52
|
/**
|
|
41
53
|
* retrieve the actual value of the matched string and return it
|
|
42
54
|
*
|
|
43
|
-
* @param {
|
|
55
|
+
* @param {object} context - the metadata used in the template
|
|
44
56
|
* @param {string} submatch - the parenthesized submatch string
|
|
45
57
|
* @returns {string} - the value of the matched string
|
|
46
58
|
*/
|
|
@@ -52,15 +64,7 @@ function templateReplacer(context, submatch) {
|
|
|
52
64
|
if (submatch.match(expressionRegex)) {
|
|
53
65
|
const name = matches[1];
|
|
54
66
|
const args = matches[2].split(/\s*,\s*/);
|
|
55
|
-
|
|
56
|
-
// e.g. extractPath(file.path) or extractPath('/a/b/c')
|
|
57
|
-
// assume args[0] is an object path if it starts with a key of context
|
|
58
|
-
const isObjectPath = Object.keys(context).includes(args[0].split('.')[0]);
|
|
59
|
-
const jsonPathValue = get(context, args[0], isObjectPath ? undefined : args[0]);
|
|
60
|
-
if (!jsonPathValue)
|
|
61
|
-
throw new Error(`Could not resolve path ${args[0]}`);
|
|
62
|
-
args[0] = jsonPathValue;
|
|
63
|
-
return evaluateOperation(name, args);
|
|
67
|
+
return evaluateOperation(name, args, context);
|
|
64
68
|
}
|
|
65
69
|
const jsonPathValue = get(context, submatch);
|
|
66
70
|
if (!jsonPathValue)
|
package/url-path-template.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-path-template.js","sourceRoot":"","sources":["src/url-path-template.js"],"names":[],"mappings":";AAAA,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAClC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B
|
|
1
|
+
{"version":3,"file":"url-path-template.js","sourceRoot":"","sources":["src/url-path-template.js"],"names":[],"mappings":";AAAA,MAAM,GAAG,GAAG,OAAO,CAA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