@lowdefy/operators 5.5.0 → 5.6.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/dist/getFromObject.js +14 -8
- package/package.json +3 -3
package/dist/getFromObject.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import { applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
|
|
15
|
+
*/ import { ReservedKeyError, applyArrayIndices, get, serializer, type } from '@lowdefy/helpers';
|
|
16
16
|
function getFromObject({ params, object, arrayIndices, operator, location }) {
|
|
17
17
|
if (params === true) params = {
|
|
18
18
|
all: true
|
|
@@ -23,20 +23,26 @@ function getFromObject({ params, object, arrayIndices, operator, location }) {
|
|
|
23
23
|
if (!type.isObject(params)) {
|
|
24
24
|
throw new Error(`${operator} params must be of type string, integer, boolean or object.`);
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
const defaultValue = get(params, 'default', {
|
|
27
27
|
default: null,
|
|
28
28
|
copy: true
|
|
29
29
|
});
|
|
30
|
+
if (params.key === null) return defaultValue;
|
|
30
31
|
if (params.all === true) return serializer.copy(object);
|
|
31
32
|
if (!type.isString(params.key) && !type.isInt(params.key)) {
|
|
32
33
|
throw new Error(`${operator}.key must be of type string or integer.`);
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
default:
|
|
35
|
+
try {
|
|
36
|
+
return get(object, applyArrayIndices(arrayIndices, params.key), {
|
|
37
|
+
default: defaultValue,
|
|
37
38
|
copy: true
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// Tier 2: a runtime read of an app-developer keypath. There is no loud failure that helps here —
|
|
42
|
+
// a thrown error in the browser is worse than the default, and the reserved rule's job (refusing
|
|
43
|
+
// the read) is already done. Author-written identifiers fail loudly at build instead.
|
|
44
|
+
if (error instanceof ReservedKeyError) return defaultValue;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
48
|
export default getFromObject;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/operators",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@lowdefy/errors": "5.
|
|
38
|
-
"@lowdefy/helpers": "5.
|
|
37
|
+
"@lowdefy/errors": "5.6.0",
|
|
38
|
+
"@lowdefy/helpers": "5.6.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@jest/globals": "28.1.3",
|