@openfn/language-common 1.7.2 → 1.7.3

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 (3) hide show
  1. package/ast.json +45 -0
  2. package/lib/Adaptor.js +21 -0
  3. package/package.json +1 -1
package/ast.json CHANGED
@@ -78,6 +78,51 @@
78
78
  },
79
79
  "valid": true
80
80
  },
81
+ {
82
+ "name": "jsonValue",
83
+ "params": [
84
+ "obj",
85
+ "path"
86
+ ],
87
+ "docs": {
88
+ "description": "Picks out a single value from a JSON object.\nIf a JSONPath returns more than one value for the reference, the first\nitem will be returned.",
89
+ "tags": [
90
+ {
91
+ "title": "public",
92
+ "description": null,
93
+ "type": null
94
+ },
95
+ {
96
+ "title": "example",
97
+ "description": "jsonValue({ a:1 }, 'a')"
98
+ },
99
+ {
100
+ "title": "function",
101
+ "description": null,
102
+ "name": null
103
+ },
104
+ {
105
+ "title": "param",
106
+ "description": "A valid JSON object.",
107
+ "type": {
108
+ "type": "NameExpression",
109
+ "name": "object"
110
+ },
111
+ "name": "obj"
112
+ },
113
+ {
114
+ "title": "param",
115
+ "description": "JSONPath referencing a point in given JSON object.",
116
+ "type": {
117
+ "type": "NameExpression",
118
+ "name": "String"
119
+ },
120
+ "name": "path"
121
+ }
122
+ ]
123
+ },
124
+ "valid": true
125
+ },
81
126
  {
82
127
  "name": "sourceValue",
83
128
  "params": [
package/lib/Adaptor.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.execute = execute;
7
7
  exports.alterState = alterState;
8
8
  exports.fn = fn;
9
+ exports.jsonValue = jsonValue;
9
10
  exports.sourceValue = sourceValue;
10
11
  exports.source = source;
11
12
  exports.dataPath = dataPath;
@@ -101,6 +102,26 @@ function fn(func) {
101
102
  return func(state);
102
103
  };
103
104
  }
105
+ /**
106
+ * Picks out a single value from a JSON object.
107
+ * If a JSONPath returns more than one value for the reference, the first
108
+ * item will be returned.
109
+ * @public
110
+ * @example
111
+ * jsonValue({ a:1 }, 'a')
112
+ * @function
113
+ * @param {object} obj - A valid JSON object.
114
+ * @param {String} path - JSONPath referencing a point in given JSON object.
115
+ * @returns {<Operation>}
116
+ */
117
+
118
+
119
+ function jsonValue(obj, path) {
120
+ return (0, _jsonpathPlus.JSONPath)({
121
+ path,
122
+ json: obj
123
+ })[0];
124
+ }
104
125
  /**
105
126
  * Picks out a single value from source data.
106
127
  * If a JSONPath returns more than one value for the reference, the first
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/language-common",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Common Expressions for OpenFn",
5
5
  "main": "lib/Adaptor.js",
6
6
  "scripts": {