Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability for nested arrays. #422

Merged
merged 12 commits into from
Jun 30, 2022
Merged

Added the ability for nested arrays. #422

merged 12 commits into from
Jun 30, 2022

Conversation

sidblommerswork
Copy link
Contributor

Please feel free to add any comments to the code changes or better ways to refactor / test the changes. I'm just getting into NodeJS / Frontend development, so I can use all the feedback you provide!

Auto formatting of some of the files in VSCode leaves much to be desired for PRs.

@sidblommerswork
Copy link
Contributor Author

I have continued writing test cases for the addition of arrays and have found a couple of issues with count. I'm going to continue writing tests to confirm changes.

@Belphemur Belphemur changed the base branch from nested-array to develop June 26, 2022 02:43
@Belphemur Belphemur self-assigned this Jun 26, 2022
@Belphemur Belphemur self-requested a review June 26, 2022 02:44
@Belphemur Belphemur linked an issue Jun 26, 2022 that may be closed by this pull request
@Belphemur Belphemur closed this Jun 26, 2022
@Belphemur Belphemur reopened this Jun 26, 2022
@codecov
Copy link

codecov bot commented Jun 26, 2022

Codecov Report

Merging #422 (ce7a6c1) into develop (dc936ba) will increase coverage by 3.44%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##           develop      #422      +/-   ##
============================================
+ Coverage    96.55%   100.00%   +3.44%     
============================================
  Files            6         6              
  Lines          696       833     +137     
  Branches       154       186      +32     
============================================
+ Hits           672       833     +161     
+ Misses          24         0      -24     
Impacted Files Coverage Δ
src/JsonDB.ts 100.00% <100.00%> (+4.35%) ⬆️
src/lib/ArrayInfo.ts 100.00% <100.00%> (+3.30%) ⬆️
src/lib/DBParentData.ts 100.00% <0.00%> (+3.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc936ba...ce7a6c1. Read the comment docs.

src/lib/ArrayInfo.ts Fixed Show fixed Hide fixed
src/lib/ArrayInfo.ts Fixed Show fixed Hide fixed
data = data[property]
} else if (create) {
if (isArray) {
data[property] = []

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](2). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](3). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](4). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](5). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](6). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](7). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](8). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](9). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](10).
if (isArray) {
data[property] = []
} else {
data[property] = {}

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](2). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](3). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](4). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](5). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](6). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](7). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](8). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](9). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](10).
Fixed logic errors when using nested arrays.
Added existing feature using -1 in arrays to use the last entry of the array.
if (index === -1) {
dataForProperty.push(value)
} else {
dataForProperty[index] = value

Check warning

Code scanning / CodeQL

Prototype-polluting assignment

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](1). This assignment may alter Object.prototype if a malicious '__proto__' string is injected from [library input](2).
@sidblommerswork
Copy link
Contributor Author

@Belphemur I will look into the code coverages fix tomorrow. This has been a fun experience, and this is the first time I've encountered code coverage with tests. 👍

@sidblommerswork
Copy link
Contributor Author

@Belphemur I have added tests to get the code coverage up to 100%.

@sidblommerswork
Copy link
Contributor Author

@Belphemur PR now looks mostly good to go. There is one change that I had added a comment to and commented out the code instead of actually removing the code. This has to deal with the JsonDB.push and JsonDB.delete methods. They call getParentData process and from what I can tell, getParentData can never return a null or undefined object. I attempted to try to fake / mock it with a test, but it also stated that it could not be null or undefined.

One outlying issue right now is the regex used for array identification. I can't seem to figure out a better way to write it.
export const arrayIndiciesRegex = /\[(.*?)\]/g

Copy link
Owner

@Belphemur Belphemur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good in general, a couple of things relating to the regex that I would like to have changed.

src/lib/ArrayInfo.ts Outdated Show resolved Hide resolved
src/lib/ArrayInfo.ts Outdated Show resolved Hide resolved
src/lib/ArrayInfo.ts Outdated Show resolved Hide resolved
src/lib/ArrayInfo.ts Outdated Show resolved Hide resolved
@sidblommerswork
Copy link
Contributor Author

Sounds great! Let me know. :)

@Belphemur
Copy link
Owner

@sidblommerswork I've put all my comments in the review :)

Created method for parsing array indicies
Added tests to support new function
Added logic to prevent append syntax in nested array.
Added logic to force append syntax to be last entry in nested array.
Added tests to enforce new rules.
@Belphemur
Copy link
Owner

@all-contributors please add @sidblommerswork for code and test

@allcontributors
Copy link
Contributor

@Belphemur

I've put up a pull request to add @sidblommerswork! 🎉

@Belphemur
Copy link
Owner

Looks great to me, I'm merging this and triggering the release process :)

@Belphemur Belphemur merged commit 854422f into Belphemur:develop Jun 30, 2022
github-actions bot pushed a commit that referenced this pull request Jun 30, 2022
# [1.6.0](v1.5.0...v1.6.0) (2022-06-30)

### Features

* **Array:** Add support for nested array ([854422f](854422f)), closes [#422](#422) [#417](#417)
@github-actions
Copy link
Contributor

🎉 This PR is included in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Belphemur added a commit that referenced this pull request Sep 9, 2022
Merge pull request #422 from sidblommerswork/nested-array-implementation
Fixes #417
Belphemur pushed a commit that referenced this pull request Sep 9, 2022
# [1.6.0](v1.5.0...v1.6.0) (2022-06-30)

### Features

* **Array:** Add support for nested array ([854422f](854422f)), closes [#422](#422) [#417](#417)
github-actions bot pushed a commit that referenced this pull request Sep 9, 2022
# [3.0.0](v2.1.1...v3.0.0) (2022-09-09)

### Bug Fixes

* **Array:** Add support for dash in array name ([b001403](b001403)), closes [#98](#98)
* **Array:** Fix array not properly async ([7bfd98d](7bfd98d))
* **ArrayInfo:** Returns type of isValid ([d206098](d206098))
* **Array:** Support dot and number in name ([eb89a42](eb89a42)), closes [#95](#95)
* **Concurrency:** Fix issue with concurrent push from different sources ([daae2bb](daae2bb)), closes [#484](#484)
* **Config:** put proper default for ConfigWithAdapter ([dbb3b7b](dbb3b7b))
* **Convention:** Fixed quotes ([7126cad](7126cad))
* **Docs:** Be sure the doc contains Config ([c453c5d](c453c5d))
* **getIndex:** Improve documentation ([17ba435](17ba435))
* **HumanReadable:** Fix missing humanreadable ([4a2d198](4a2d198))
* **JsonAdapter:** Don't override the data property ([43898d5](43898d5))
* **Packaging:** Add type to package. ([983ea99](983ea99)), closes [#58](#58) [#57](#57)
* **README:** Update documentation ([d66d712](d66d712))
* **README:** Update documentation ([ba42a83](ba42a83)), closes [#90](#90) [#85](#85)
* **Separator:** Fix still using the slash as separator. ([c4c18b8](c4c18b8))

### Features

* **Adapter:** Add concept of adapter to read and write data ([9a31abc](9a31abc))
* **Adapter:** Let the user decide what adapter to use if they want to tweak the inner working ([975a653](975a653)), closes [#448](#448)
* add some array utils ([c85618e](c85618e))
* **Array:** Add support for nested array ([57c049f](57c049f)), closes [#422](#422) [#417](#417)
* **Async:** All the method are now async/await ([a6a4a8d](a6a4a8d)), closes [#171](#171)
* **Async:** Make the whole library async ([b99d784](b99d784)), closes [#444](#444)
* **AtomicFileAdapter:** Add support for fsync ([e4760cb](e4760cb))
* **Config:** Add Config file to setup the Database ([3915aee](3915aee))
* **Configuration:** Force giving a config object to the constructor ([8e415e6](8e415e6))
* **Date:** Add support for serializing and deserializing date type ([e62e792](e62e792)), closes [#362](#362)
* **Exists:** Add exits method ([35152a2](35152a2)), closes [#19](#19)
* **filename:** Support non json file extensions ([6be9a1d](6be9a1d))
* **Filter:** Add filtering feature ([0f7d276](0f7d276))
* **find:** Add find feature ([bd7ab4c](bd7ab4c)), closes [#17](#17)
* **FSYNC:** Optional fsync when saving the database ([8ae82ab](8ae82ab)), closes [#372](#372)
* **getIndex:** Support Numerical id ([d2e88ea](d2e88ea))
* **GetIndexValue:** Get index of a value in an array ([35d1807](35d1807)), closes [#191](#191)
* **Packaging:** Use es6 module packaging ([4487c4b](4487c4b))
* **typing:** Add basic typing to the lib for TS ([db8ab77](db8ab77))

### Performance Improvements

* **Concurrency:** Be sure that only one read or one write can be done at the same time ([1cf0038](1cf0038))
* **Config:** Easier way to import the configuration of JsonDB ([e371b71](e371b71))
* **Errors:** Export errors for easier error management in other projects ([60c90f8](60c90f8)), closes [#479](#479)

### BREAKING CHANGES

* **Async:** Every method of the library is now async and returns a promise.
* **Configuration:** We now need to receive the JsonDBConfig object in the constructor
* **Packaging:** The default export has been removed. You need to do a deconstruction import to load the library now.

import JsonDB from 'node-json-db'
becomes
import {JsonDB} from 'node-json-db'
github-actions bot pushed a commit that referenced this pull request Sep 9, 2022
# [1.0.0](v0.7.3...v1.0.0) (2022-09-09)

### Bug Fixes

* **Array:** Add support for dash in array name ([b001403](b001403)), closes [#98](#98)
* **Array:** Fix array not properly async ([7bfd98d](7bfd98d))
* **ArrayInfo:** Returns type of isValid ([d206098](d206098))
* **Array:** Support dot and number in name ([eb89a42](eb89a42)), closes [#95](#95)
* **Concurrency:** Fix issue with concurrent push from different sources ([daae2bb](daae2bb)), closes [#484](#484)
* **Config:** put proper default for ConfigWithAdapter ([dbb3b7b](dbb3b7b))
* **Convention:** Fixed quotes ([7126cad](7126cad))
* **Docs:** Be sure the doc contains Config ([c453c5d](c453c5d))
* **getIndex:** Improve documentation ([17ba435](17ba435))
* **HumanReadable:** Fix missing humanreadable ([4a2d198](4a2d198))
* **JsonAdapter:** Don't override the data property ([43898d5](43898d5))
* **Packaging:** Add type to package. ([983ea99](983ea99)), closes [#58](#58) [#57](#57)
* **README:** Update documentation ([d66d712](d66d712))
* **README:** Update documentation ([ba42a83](ba42a83)), closes [#90](#90) [#85](#85)
* **Separator:** Fix still using the slash as separator. ([c4c18b8](c4c18b8))

### Features

* **Adapter:** Add concept of adapter to read and write data ([9a31abc](9a31abc))
* **Adapter:** Let the user decide what adapter to use if they want to tweak the inner working ([975a653](975a653)), closes [#448](#448)
* add some array utils ([c85618e](c85618e))
* **Array:** Add support for nested array ([57c049f](57c049f)), closes [#422](#422) [#417](#417)
* **Async:** All the method are now async/await ([a6a4a8d](a6a4a8d)), closes [#171](#171)
* **Async:** Make the whole library async ([b99d784](b99d784)), closes [#444](#444)
* **AtomicFileAdapter:** Add support for fsync ([e4760cb](e4760cb))
* **Config:** Add Config file to setup the Database ([3915aee](3915aee))
* **Configuration:** Force giving a config object to the constructor ([8e415e6](8e415e6))
* **Date:** Add support for serializing and deserializing date type ([e62e792](e62e792)), closes [#362](#362)
* **Exists:** Add exits method ([35152a2](35152a2)), closes [#19](#19)
* **filename:** Support non json file extensions ([6be9a1d](6be9a1d))
* **Filter:** Add filtering feature ([0f7d276](0f7d276))
* **find:** Add find feature ([bd7ab4c](bd7ab4c)), closes [#17](#17)
* **FSYNC:** Optional fsync when saving the database ([8ae82ab](8ae82ab)), closes [#372](#372)
* **getIndex:** Support Numerical id ([d2e88ea](d2e88ea))
* **GetIndexValue:** Get index of a value in an array ([35d1807](35d1807)), closes [#191](#191)
* **Packaging:** Use es6 module packaging ([4487c4b](4487c4b))
* **typing:** Add basic typing to the lib for TS ([db8ab77](db8ab77))

### Performance Improvements

* **Concurrency:** Be sure that only one read or one write can be done at the same time ([1cf0038](1cf0038))
* **Config:** Easier way to import the configuration of JsonDB ([e371b71](e371b71))
* **Errors:** Export errors for easier error management in other projects ([60c90f8](60c90f8)), closes [#479](#479)

### BREAKING CHANGES

* **Async:** Every method of the library is now async and returns a promise.
* **Configuration:** We now need to receive the JsonDBConfig object in the constructor
* **Packaging:** The default export has been removed. You need to do a deconstruction import to load the library now.

import JsonDB from 'node-json-db'
becomes
import {JsonDB} from 'node-json-db'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to access indexes of nested arrays.
2 participants