From fc5b4ea4d4c235d983e555a58b895cde61be9c8a Mon Sep 17 00:00:00 2001 From: JG-1202 <80622886+JG-1202@users.noreply.github.com> Date: Sun, 26 Dec 2021 09:48:00 +0100 Subject: [PATCH] V1.1.1 (#20) * build: added build, buildOne, buildAll * chore: updated declaration files * chore: updated package lock * fix: resolved issue where it failed to query non existing element from an array * chore: updated package version * chore: added set from Map test to settingValues again --- CHANGELOG.md | 4 ++++ ___tests___/index/settingValues.test.js | 4 ++++ ___tests___/resolve.test.js | 8 ++++++++ ___tests___/resolveOne.test.js | 8 ++++++++ package-lock.json | 4 ++-- package.json | 2 +- src/services/querier/src/isOperationToGetEnd/index.js | 2 +- 7 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e66b539..6763fb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented here. +## [1.1.1] - 2021-12-26 +### Changed +- resolved issue where it failed to query non existing element from an array + ## [1.1.0] - 2021-12-26 ### Added - build, buildOne, buildAll handlers: sets function output on specified json path diff --git a/___tests___/index/settingValues.test.js b/___tests___/index/settingValues.test.js index 5a23a1e..c9b6dba 100644 --- a/___tests___/index/settingValues.test.js +++ b/___tests___/index/settingValues.test.js @@ -132,6 +132,10 @@ describe('Test setting value(s)', () => { JsonGo.setAll('[{$.bla.foo}].bla.foo', 123); expect(JsonGo.export()).toStrictEqual(testObject); }); + it('It does not fail when non-existing wildcard is attempted to be set', () => { + const result = JG.set([], 'test[*].test', 8); + expect(result).toStrictEqual([]); + }); }); describe('README examples', () => { diff --git a/___tests___/resolve.test.js b/___tests___/resolve.test.js index 484f753..b0a2e95 100644 --- a/___tests___/resolve.test.js +++ b/___tests___/resolve.test.js @@ -127,6 +127,14 @@ describe('Test getAll function', () => { test([], '[*][*]', []); test(null, '[*][*]', []); }); + it('Gets wildcard non existing property of an array', () => { + test([], 'test', []); + test([], 'test[*].test', []); + }); + it('Gets wildcard non existing property of an object', () => { + test({}, 'test', []); + test({}, 'test[*].test', []); + }); }); describe('Testing JSON equality', () => { diff --git a/___tests___/resolveOne.test.js b/___tests___/resolveOne.test.js index 3f064db..a8aee92 100644 --- a/___tests___/resolveOne.test.js +++ b/___tests___/resolveOne.test.js @@ -92,4 +92,12 @@ describe('Test get function', () => { it('Getting falsy value', () => { test({ test: false }, 'test', false); }); + it('Gets wildcard non existing property of an array', () => { + test([], 'test', undefined); + test([], 'test[*].test', undefined); + }); + it('Gets wildcard non existing property of an object', () => { + test({}, 'test', undefined); + test({}, 'test[*].test', undefined); + }); }); diff --git a/package-lock.json b/package-lock.json index f54f188..eb0b078 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "js-json-go", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "js-json-go", - "version": "1.1.0", + "version": "1.1.1", "license": "MIT", "devDependencies": { "@commitlint/cli": "^15.0.0", diff --git a/package.json b/package.json index 233f65b..a9ebd06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-json-go", - "version": "1.1.0", + "version": "1.1.1", "description": "Retrieves and constructs values from/into JSON objects. Js-JSON-Go is a lightweight library that offers the ability to query JSON objects to obtain data and use the same query format to build JSON objects.", "main": "index.js", "scripts": { diff --git a/src/services/querier/src/isOperationToGetEnd/index.js b/src/services/querier/src/isOperationToGetEnd/index.js index 36d07d2..3ba42f1 100644 --- a/src/services/querier/src/isOperationToGetEnd/index.js +++ b/src/services/querier/src/isOperationToGetEnd/index.js @@ -1,6 +1,6 @@ /** * check if operation is to get end of array */ -const isOperationToGetEnd = (query) => query[0] && query[0].custom === 'end'; +const isOperationToGetEnd = (query) => query && query[0] && query[0].custom === 'end'; module.exports = isOperationToGetEnd;