From 668c891d51eb72ccd73302ade9677b7961f00e37 Mon Sep 17 00:00:00 2001 From: Gab Mule Date: Wed, 25 Aug 2021 10:49:26 -0300 Subject: [PATCH 01/15] feat: Including github workflows --- .github/workflows/deploy.yml | 65 ++++++++++++++++++++++++++++++++++ .github/workflows/run_test.yml | 21 +++++++++++ .gitlab-ci.yml | 36 ------------------- 3 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/run_test.yml delete mode 100644 .gitlab-ci.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..d296ed5 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,65 @@ +name: deploy + +on: + release: + types: [ created ] + +jobs: + deploy: + if: ${{ contains(github.ref, 'refs/tags/release-') }} + runs-on: ubuntu-latest + steps: + # GET TAG VERSION & RELEASE_VERSION IN $GITHUB_ENV + - name: Get TAG_VERSION & RELEASE_VERSION + run: | + echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + echo "RELEASE_VERSION=${GITHUB_REF#refs/*/release-}" >> $GITHUB_ENV + # CHECKOUT REPOSITORY + - name: Checkout Repository + uses: actions/checkout@v2 + with: + ref: master + # SETUP NODE ENV W/ NPM PUBLIC REGISTRY + - name: Setup Node Env + uses: actions/setup-node@v2 + with: + registry-url: 'https://registry.npmjs.org' + # CONFIGURE GIT + - name: Configure Git + run: | + git config user.name github-ci + git config user.email gabriel.mule@cyberlabs.ai + # RUN SCRIPTS + - name: Update package version + run: node -e "let pkg=require('./package.json'); pkg.version='${{ env.RELEASE_VERSION }}'; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2));" + - name: Build Package + run: | + npm install + npm run build + # PUBLISH VUE PACKAGE + - name: Publish VueJS Package + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + # ADD & COMMIT CHANGES + - name: Add & Commit Changes + run: | + git add . + git commit -am "[github-ci] Published Version" + git push origin main:npm --force + # TAG VERSION + - name: Tag Version + run: | + git tag -a ${{ env.TAG_VERSION }} -m ${{ env.TAG_VERSION }} --force + git push --tags --force + # SUCCESS MESSAGE TO DISCORD + - name: Success Message to Discord + uses: sarisia/actions-status-discord@v1 + with: + webhook: ${{ secrets.WEBHOOK_URL }} + title: "Published @yoonit/rxjs-yoonit-store v${{ env.RELEASE_VERSION }}" + description: | + A new release has been published: + [Click here to go to the release page](https://github.com/Yoonit-Labs/rxjs-yoonit-store/releases/tag/${{ env.TAG_VERSION }}) + color: 0x00ff00 + username: GitHub Actions diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml new file mode 100644 index 0000000..a03c2ed --- /dev/null +++ b/.github/workflows/run_test.yml @@ -0,0 +1,21 @@ +name: run_test:unit + +on: [push, workflow_dispatch] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [10.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci + - run: npm run test:unit diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index f1f8de0..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,36 +0,0 @@ -stages: - - package-release - -package-release: - image: node:12.17.0 - stage: package-release - before_script: - - git remote set-url origin https://gitlab-ci-token:$CI_PUSH_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git - - git config --global user.email 'gabriel.mule@cyberlabs.ai' - - git config --global user.name 'gitlab-ci' - - | - { - echo "registry=https://registry.npmjs.org/" - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" - } | tee --append .npmrc - script: - - node "./ci.js" $CI_COMMIT_TAG - - npm ci - - npm run build - - npm publish --access public - after_script: - - git checkout -B master - - git add package.json - - git commit -m '[gitlab-ci] Published Version' - - git push "https://gitlab-ci-token:$CI_PUSH_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" - - git tag -d $CI_COMMIT_TAG - - git tag $CI_COMMIT_TAG - - git push "https://gitlab-ci-token:$CI_PUSH_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git" --tags --force - rules: - - if: '$CI_COMMIT_TITLE == "[gitlab-ci] Published Version"' - when: never - - if: '$CI_COMMIT_TAG =~ /^release-/' - when: always - - when: never - tags: - - gitlab-org From 9ce55bd86259019a92112041e26e8cdd3e1cc4ca Mon Sep 17 00:00:00 2001 From: Gab Mule Date: Wed, 25 Aug 2021 10:53:14 -0300 Subject: [PATCH 02/15] fix: fixing pipeline command --- .github/workflows/run_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index a03c2ed..b008d6c 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -17,5 +17,5 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - run: npm ci + - run: npm install - run: npm run test:unit From a1f71881cae6b8c348f66a3d1f60ba65618338e2 Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 12:20:26 -0300 Subject: [PATCH 03/15] Adding catch on create to prevent conflict issues --- src/persist/db/index.js | 2 +- src/persist/exceptions/index.js | 12 +++++++++++- src/persist/persist/index.js | 19 ++++++++++++++++--- src/test/helpers.js | 2 +- src/utils/index.js | 1 - 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/persist/db/index.js b/src/persist/db/index.js index cda9806..2745977 100644 --- a/src/persist/db/index.js +++ b/src/persist/db/index.js @@ -1,5 +1,5 @@ import PouchDB from 'pouchdb' -import { catchError } from "../exceptions"; +import { catchError, ConflictException } from "../exceptions"; function localDatabase () { const db = new PouchDB('state') diff --git a/src/persist/exceptions/index.js b/src/persist/exceptions/index.js index 9441f56..2eb4945 100644 --- a/src/persist/exceptions/index.js +++ b/src/persist/exceptions/index.js @@ -3,6 +3,11 @@ function NotFoundException () { this.message = 'Registry was not found' } +function ConflictException () { + this.code = 409 + this.message = 'Document update conflict' +} + function UnexpectedErrorException (message) { this.message = message } @@ -11,18 +16,23 @@ function UnexpectedErrorException (message) { * @function catchError * @description Handle error and throw custom error exception. * @param {Error} error - * @returns {UnexpectedErrorException|NotFoundException} + * @returns {UnexpectedErrorException|NotFoundException|ConflictException} */ function catchError (error) { if (error.status === 404) { return new NotFoundException() } + if (error.status === 409) { + return new ConflictException() + } + return new UnexpectedErrorException(error.message) } export { NotFoundException, UnexpectedErrorException, + ConflictException, catchError } diff --git a/src/persist/persist/index.js b/src/persist/persist/index.js index 77269f4..90cc1d1 100644 --- a/src/persist/persist/index.js +++ b/src/persist/persist/index.js @@ -1,9 +1,23 @@ import { localDatabase } from "../db"; -import { NotFoundException } from "../exceptions"; +import {ConflictException, NotFoundException} from "../exceptions"; function CreatePersistence () { const db = localDatabase() + async function create (payload) { + try { + await db.create(payload) + return Promise.resolve(true) + } catch (e) { + if (e instanceof ConflictException) { + console.log(`Aqui ow`) + await db.update(payload) + + return Promise.resolve(true) + } + } + + } return { /** * @method get @@ -27,8 +41,7 @@ function CreatePersistence () { return Promise.resolve(true) } catch (e) { if (e instanceof NotFoundException) { - await db.create(payload) - return Promise.resolve(true) + return create(payload) } return Promise.reject(e) diff --git a/src/test/helpers.js b/src/test/helpers.js index 8345e9e..f62601a 100644 --- a/src/test/helpers.js +++ b/src/test/helpers.js @@ -24,7 +24,7 @@ const areArraysEquals = (firstArray, secondArray) => { } /** - * @description Delay function with 1 second timeout + * @description Delay function with 3 second timeout * @returns {Promise} */ const delay = () => { diff --git a/src/utils/index.js b/src/utils/index.js index aab833d..69ed654 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -79,7 +79,6 @@ const loadPersistedData = async (modules) => { return false } catch (e) { - console.log(e) return false } } From 76f68b28f7b507d99474d4a815b091e388e4c738 Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 12:36:57 -0300 Subject: [PATCH 04/15] Removing console.log from exception handle --- src/persist/persist/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/persist/persist/index.js b/src/persist/persist/index.js index 90cc1d1..41f7dd4 100644 --- a/src/persist/persist/index.js +++ b/src/persist/persist/index.js @@ -10,7 +10,6 @@ function CreatePersistence () { return Promise.resolve(true) } catch (e) { if (e instanceof ConflictException) { - console.log(`Aqui ow`) await db.update(payload) return Promise.resolve(true) From fbe2ef7e6cea0f63778ec840752ce47e71580c7b Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 12:59:02 -0300 Subject: [PATCH 05/15] Adding delay to test github pipeline --- src/persist/main.test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/persist/main.test.js b/src/persist/main.test.js index bda7caa..284933c 100644 --- a/src/persist/main.test.js +++ b/src/persist/main.test.js @@ -1,4 +1,5 @@ import { Persist } from './main.js' +import { delay } from "../test/helpers"; import { NotFoundException } from "./exceptions"; describe('Testing Persist setter', () => { @@ -13,6 +14,8 @@ describe('Testing Persist setter', () => { }) expect(cacheResult).toBeTruthy() + + await delay() }) it('Should update data on store', async () => { @@ -39,6 +42,8 @@ describe('Testing Persist setter', () => { const cachedValue = await Persist.get() expect(cachedValue).toStrictEqual(expectedValue) + + await delay() }) }) @@ -58,6 +63,8 @@ describe('Testing Persist getter', () => { const cachedData = await Persist.get() expect(cachedData).toStrictEqual(expectedValue) + + await delay() }) it('Should return error when there is no cached value', async () => { @@ -69,6 +76,8 @@ describe('Testing Persist getter', () => { await Persist.clear() await Persist.get() + + await delay() } catch (e) { expect(e instanceof NotFoundException).toBeTruthy() } @@ -82,6 +91,8 @@ describe('Testing clear persist', () => { const clearPersistResult = await Persist.clear() expect(clearPersistResult).toBeTruthy() + + await delay() }) it('Should return false if persist is empty', async () => { @@ -92,5 +103,7 @@ describe('Testing clear persist', () => { const cacheClearResult = await Persist.clear() expect(cacheClearResult).toBeFalsy() + + await delay() }) }) From 3d254cb3c74335f2e957688994db5910bfedff6c Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 14:36:12 -0300 Subject: [PATCH 06/15] Fixing test and improving remove code --- src/main.test.js | 88 ++++++++++++++++++++++++++++++- src/persist/db/index.js | 4 +- src/persist/main.test.js | 109 --------------------------------------- 3 files changed, 88 insertions(+), 113 deletions(-) delete mode 100644 src/persist/main.test.js diff --git a/src/main.test.js b/src/main.test.js index 149ad64..66b383b 100644 --- a/src/main.test.js +++ b/src/main.test.js @@ -1,7 +1,8 @@ import * as Yoox from './main' -import {mixedStore, officeStore, rootAccessors, storeWithModule} from "./test/mockedStore" +import { mixedStore, officeStore, rootAccessors, storeWithModule } from "./test/mockedStore" import Persist from './persist/main' import { delay } from "./test/helpers" +import { NotFoundException } from "./persist/exceptions" describe('Testing Yoox modularized', () => { it('Should create yoox from object', async() => { @@ -119,3 +120,88 @@ describe('Testing store with more then one module', () => { }) }) }) + + +describe('Testing Persist setter', () => { + it('Should set data on store when persist is empty', async () => { + const cacheResult = await Persist.set({ + state: { + user: { + name: 'Gabriel Rizzo', + age: 25 + } + } + }) + + expect(cacheResult).toBeTruthy() + }) + + it('Should update data on store', async () => { + const expectedValue = { + state: { + group: { + id: 1, + name: 'Happy Group' + } + } + } + + await Persist.set({ + state: { + user: { + name: 'Gabriel Rizzo', + age: 25 + } + } + }) + + await Persist.set(expectedValue) + + const cachedValue = await Persist.get() + + expect(cachedValue).toStrictEqual(expectedValue) + }) +}) + +describe('Testing Persist getter', () => { + it('Should get cached value', async () => { + const expectedValue = { + state: { + group: { + id: 1, + name: 'Happy Group' + } + } + } + + await Persist.set(expectedValue) + + const cachedData = await Persist.get() + + expect(cachedData).toStrictEqual(expectedValue) + }) + + it('Should return error when there is no cached value', async () => { + try { + // setting value to guarantee that store is not empty + await Persist.set({ value: true }) + + // Cleaning persist + await Persist.clear() + + await Persist.get() + } catch (e) { + expect(e instanceof NotFoundException).toBeTruthy() + } + }) +}) + +describe('Testing clear persist', () => { + it('Should clear stored value', async () => { + await Persist.set({ value: true }) + + const clearPersistResult = await Persist.clear() + + expect(clearPersistResult).toBeTruthy() + }) +}) diff --git a/src/persist/db/index.js b/src/persist/db/index.js index 2745977..4e71c11 100644 --- a/src/persist/db/index.js +++ b/src/persist/db/index.js @@ -68,9 +68,7 @@ function localDatabase () { try { const cachedData = await db.get(id) - const dbResponse = await db.remove(cachedData) - - return Promise.resolve(dbResponse) + return db.remove(cachedData) } catch (e) { throw catchError(e) } diff --git a/src/persist/main.test.js b/src/persist/main.test.js deleted file mode 100644 index 284933c..0000000 --- a/src/persist/main.test.js +++ /dev/null @@ -1,109 +0,0 @@ -import { Persist } from './main.js' -import { delay } from "../test/helpers"; -import { NotFoundException } from "./exceptions"; - -describe('Testing Persist setter', () => { - it('Should set data on store when persist is empty', async () => { - const cacheResult = await Persist.set({ - state: { - user: { - name: 'Gabriel Rizzo', - age: 25 - } - } - }) - - expect(cacheResult).toBeTruthy() - - await delay() - }) - - it('Should update data on store', async () => { - const expectedValue = { - state: { - group: { - id: 1, - name: 'Happy Group' - } - } - } - - await Persist.set({ - state: { - user: { - name: 'Gabriel Rizzo', - age: 25 - } - } - }) - - await Persist.set(expectedValue) - - const cachedValue = await Persist.get() - - expect(cachedValue).toStrictEqual(expectedValue) - - await delay() - }) -}) - -describe('Testing Persist getter', () => { - it('Should get cached value', async () => { - const expectedValue = { - state: { - group: { - id: 1, - name: 'Happy Group' - } - } - } - - await Persist.set(expectedValue) - - const cachedData = await Persist.get() - - expect(cachedData).toStrictEqual(expectedValue) - - await delay() - }) - - it('Should return error when there is no cached value', async () => { - try { - // setting value to guarantee that store is not empty - await Persist.set({ value: true }) - - // Cleaning persist - await Persist.clear() - - await Persist.get() - - await delay() - } catch (e) { - expect(e instanceof NotFoundException).toBeTruthy() - } - }) -}) - -describe('Testing clear persist', () => { - it('Should clear stored value', async () => { - await Persist.set({ value: true }) - - const clearPersistResult = await Persist.clear() - - expect(clearPersistResult).toBeTruthy() - - await delay() - }) - - it('Should return false if persist is empty', async () => { - await Persist.set({ value: true }) - - await Persist.clear() - - const cacheClearResult = await Persist.clear() - - expect(cacheClearResult).toBeFalsy() - - await delay() - }) -}) From 583a9e9096c069825b5eccc33360f635362b6a10 Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 15:08:33 -0300 Subject: [PATCH 07/15] Refactoring reducer to mixerHandler to be more meaningfull --- src/yoox/index.js | 2 +- src/yoox/observerHandlers.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/yoox/index.js b/src/yoox/index.js index 08ec3d7..c0a0ddf 100644 --- a/src/yoox/index.js +++ b/src/yoox/index.js @@ -25,7 +25,7 @@ const store = (modules, { persist = false, onLoad = () => ({}) }) => { */ const store = storeObservable.pipe( startWith({type: '__INIT__'}), - scan(observerHandlers.reducer, storeAccessors.initialState), + scan(observerHandlers.mixerHandler, storeAccessors.initialState), shareReplay(1), scan(persistStoreState, {}) ) diff --git a/src/yoox/observerHandlers.js b/src/yoox/observerHandlers.js index 3784774..a7f6139 100644 --- a/src/yoox/observerHandlers.js +++ b/src/yoox/observerHandlers.js @@ -5,12 +5,12 @@ function createObserverHandlers (storeAccessors) { return { /** - * Create a reducer according to module action by type + * Create a handler to execute mixer * @param {Observable} state * @param {string} action * @returns {*} */ - reducer: function (state, action) { + mixerHandler: function (state, action) { const DEFAULT_STATE = state => state const handler = _storeAccessors.setterList[action.type] || DEFAULT_STATE return handler(state, action) From a2f5b9dc43cfd14fa0d629612136b047a7a6e4dd Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 16:13:20 -0300 Subject: [PATCH 08/15] Changing remove method to remove all docs --- src/main.test.js | 2 +- src/persist/db/index.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.test.js b/src/main.test.js index 66b383b..f08975d 100644 --- a/src/main.test.js +++ b/src/main.test.js @@ -198,7 +198,7 @@ describe('Testing Persist getter', () => { describe('Testing clear persist', () => { it('Should clear stored value', async () => { - await Persist.set({ value: true }) + await Persist.set({ foo: true }) const clearPersistResult = await Persist.clear() diff --git a/src/persist/db/index.js b/src/persist/db/index.js index 4e71c11..d18ac8e 100644 --- a/src/persist/db/index.js +++ b/src/persist/db/index.js @@ -2,7 +2,7 @@ import PouchDB from 'pouchdb' import { catchError, ConflictException } from "../exceptions"; function localDatabase () { - const db = new PouchDB('state') + const db = new PouchDB('state', { revs_limit: 1 }) const id = 'global_state' return { @@ -66,9 +66,14 @@ function localDatabase () { */ remove: async function () { try { - const cachedData = await db.get(id) + const cachedData = await db.allDocs() + + await Promise.all(cachedData.rows.map((doc) => { + console.log(doc) + return db.remove(doc.id, doc.value.rev) + })) - return db.remove(cachedData) + return Promise.resolve(true) } catch (e) { throw catchError(e) } From 1c19fbbe013f34faf1be22d38eb90d28485bafa3 Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 16:24:55 -0300 Subject: [PATCH 09/15] Changing persist remove function to delete all doc's revision --- src/main.test.js | 12 ++++++++++++ src/persist/db/index.js | 14 +++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main.test.js b/src/main.test.js index f08975d..9f16667 100644 --- a/src/main.test.js +++ b/src/main.test.js @@ -204,4 +204,16 @@ describe('Testing clear persist', () => { expect(clearPersistResult).toBeTruthy() }) + + it('Should throw NotFoundError when trying to retrieve data after deletion', async () => { + try { + await Persist.set({ foo: true }) + + await Persist.clear() + + await Persist.get() + } catch (e) { + expect(e instanceof NotFoundException).toBeTruthy() + } + }) }) diff --git a/src/persist/db/index.js b/src/persist/db/index.js index d18ac8e..b58eb26 100644 --- a/src/persist/db/index.js +++ b/src/persist/db/index.js @@ -61,16 +61,20 @@ function localDatabase () { }, /** * @method remove - * @description Proxy PouchDB remove to abstract lib implementation details. Remove stored data. + * @description Proxy PouchDB remove to abstract lib implementation details. Remove stored data with all its revisions. * @returns {Promise<*>} */ remove: async function () { try { - const cachedData = await db.allDocs() + const cachedData = await db.get(id, { + revs: true, + open_revs: 'all' + }) + + await Promise.all(cachedData.map((doc) => { + if (!doc.ok) return - await Promise.all(cachedData.rows.map((doc) => { - console.log(doc) - return db.remove(doc.id, doc.value.rev) + return db.remove(doc.ok._id, doc.ok._rev) })) return Promise.resolve(true) From 40bc785fc68dab6fde4a7cf3538356780a08fabe Mon Sep 17 00:00:00 2001 From: Gabriel Rizzo Date: Wed, 25 Aug 2021 17:27:48 -0300 Subject: [PATCH 10/15] Update README.md Updating readme with onLoad callback --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8eabba0..ad47f47 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ After installing the project: ``` import yourStore from './yourstore' -Yoox.store(yourStore, { persist: true }) +Yoox.store(yourStore, { persist: true, onLoad: hideLoad }) ``` ## store Object @@ -168,3 +168,5 @@ It's only necessary to pass { persist: true } to the second parameter on store, - When there is a change on store modules, persisted data is reseted, to not cause trouble with wrong store structure. +- It's highly recommended to use onLoad method to guarantee that persisted data have been loaded to Yoox state. Ie: Show load until onLoad callback is called. + From 85fef5c1e48f349f991c5574ccbd2ecb54f2acef Mon Sep 17 00:00:00 2001 From: Gabriel Rizzo Date: Wed, 25 Aug 2021 17:28:13 -0300 Subject: [PATCH 11/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad47f47..0d51454 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ After installing the project: ``` import yourStore from './yourstore' -Yoox.store(yourStore, { persist: true, onLoad: hideLoad }) +const myStore = Yoox.store(yourStore, { persist: true, onLoad: hideLoad }) ``` ## store Object From 9fa7081b0a351a8de0f0732666aab63f986a6dd6 Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 19:46:45 -0300 Subject: [PATCH 12/15] Adding state return to mixerHandler --- src/test/mockedStore.js | 10 ---------- src/yoox/observerHandlers.js | 3 ++- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/test/mockedStore.js b/src/test/mockedStore.js index 4719b31..fed8f10 100644 --- a/src/test/mockedStore.js +++ b/src/test/mockedStore.js @@ -24,8 +24,6 @@ export const storeWithModule = { 'personalData': function (state, { payload }) { state.user.name = payload.name state.user.age = payload.age - - return state } } } @@ -51,8 +49,6 @@ export const rootAccessors = { mix: { 'userPersonalData': function (state, { payload }) { state.user = payload - - return state } } } @@ -75,8 +71,6 @@ export const officeStore = { mix: { 'officeData': function (state, { payload }) { state.user.name = payload.name - - return state } } } @@ -100,8 +94,6 @@ export const mixedStore = { mix: { 'officeData': function (state, { payload }) { state.office.name = payload.name - - return state } } }, @@ -130,8 +122,6 @@ export const mixedStore = { 'personalData': function (state, { payload }) { state.user.name = payload.name state.user.age = payload.age - - return state } } } diff --git a/src/yoox/observerHandlers.js b/src/yoox/observerHandlers.js index a7f6139..0e6beff 100644 --- a/src/yoox/observerHandlers.js +++ b/src/yoox/observerHandlers.js @@ -13,7 +13,8 @@ function createObserverHandlers (storeAccessors) { mixerHandler: function (state, action) { const DEFAULT_STATE = state => state const handler = _storeAccessors.setterList[action.type] || DEFAULT_STATE - return handler(state, action) + handler(state, action) + return state }, /** From df1e97ad0d73c52d3997b5a155315364ca50c70d Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 19:57:06 -0300 Subject: [PATCH 13/15] Refactoring setter list to mixer --- src/test/helpers.js | 4 ++-- src/utils/index.js | 12 ++++++------ src/utils/utils.test.js | 4 ++-- src/yoox/observerHandlers.js | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/helpers.js b/src/test/helpers.js index f62601a..7b0fe4f 100644 --- a/src/test/helpers.js +++ b/src/test/helpers.js @@ -7,10 +7,10 @@ const areAccessorsKeysEquals = (expectedAccessors, generatedAccessors) => { const actionListMatched = areArraysEquals(expectedAccessors.actionList, Object.keys(generatedAccessors.actionList)) const getterListMatched = areArraysEquals(expectedAccessors.getterList, Object.keys(generatedAccessors.getterList)) - const setterListMatched = areArraysEquals(expectedAccessors.setterList, Object.keys(generatedAccessors.setterList)) + const mixerListMatched = areArraysEquals(expectedAccessors.mixerList, Object.keys(generatedAccessors.mixerList)) const initialStateMatched = areArraysEquals(expectedAccessors.initialState, Object.keys(generatedAccessors.initialState)) - return actionListMatched && getterListMatched && setterListMatched && initialStateMatched + return actionListMatched && getterListMatched && mixerListMatched && initialStateMatched } /** diff --git a/src/utils/index.js b/src/utils/index.js index 69ed654..4ed5d54 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -18,7 +18,7 @@ function modularizeFunctionNames (accessors, moduleName) { /** * @description Create store accessors * @param {Object} modules - * @returns {{setterList: *, getterList, initialState, actionList}|{setterList, getterList, initialState, actionList: {}, modules}} + * @returns {{mixerList: *, getterList, initialState, actionList}|{mixerList, getterList, initialState, actionList: {}, modules}} */ function createStoreAccessors (modules) { const moduleKeys = Object.keys(modules) @@ -27,23 +27,23 @@ function createStoreAccessors (modules) { moduleKeys.includes('mix') && moduleKeys.includes('state') - let initialState, getterList, setterList, actionList = {} + let initialState, getterList, mixerList, actionList = {} if (isAccessorsOnRoot) { return { getterList: modules.get, actionList: modules.set, initialState: modules.state, - setterList: modules.mix + mixerList: modules.mix } } const modulesKeys = [] - // Populate setterList and initialState object according to modules + // Populate mixerList and initialState object according to modules moduleKeys.forEach((moduleKey) => { initialState = { ...initialState, [moduleKey]: { ...modules[moduleKey].state } } getterList = { ...getterList, ...modularizeFunctionNames(modules[moduleKey].get, moduleKey) } - setterList = { ...setterList, ...modularizeFunctionNames(modules[moduleKey].mix, moduleKey) } + mixerList = { ...mixerList, ...modularizeFunctionNames(modules[moduleKey].mix, moduleKey) } actionList = { ...actionList, ...modularizeFunctionNames(modules[moduleKey].set, moduleKey) } modulesKeys.push(moduleKey) }) @@ -51,7 +51,7 @@ function createStoreAccessors (modules) { return { initialState, getterList, - setterList, + mixerList, actionList, modules: modulesKeys } diff --git a/src/utils/utils.test.js b/src/utils/utils.test.js index d9f036e..447f024 100644 --- a/src/utils/utils.test.js +++ b/src/utils/utils.test.js @@ -31,7 +31,7 @@ describe('Testing function createStoreAccessors', () => { getterList: [ 'user/personalData' ], - setterList: [ + mixerList: [ 'user/personalData' ], initialState: [ @@ -52,7 +52,7 @@ describe('Testing function createStoreAccessors', () => { getterList: [ 'userPersonalData' ], - setterList: [ + mixerList: [ 'userPersonalData' ], initialState: [ diff --git a/src/yoox/observerHandlers.js b/src/yoox/observerHandlers.js index 0e6beff..df08bd1 100644 --- a/src/yoox/observerHandlers.js +++ b/src/yoox/observerHandlers.js @@ -12,7 +12,7 @@ function createObserverHandlers (storeAccessors) { */ mixerHandler: function (state, action) { const DEFAULT_STATE = state => state - const handler = _storeAccessors.setterList[action.type] || DEFAULT_STATE + const handler = _storeAccessors.mixerList[action.type] || DEFAULT_STATE handler(state, action) return state }, From 22bf883b137c5a0ef067c81fce51353b7f67beb9 Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Wed, 25 Aug 2021 20:01:21 -0300 Subject: [PATCH 14/15] Audit fix --- package-lock.json | 78 +++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 50 deletions(-) diff --git a/package-lock.json b/package-lock.json index 681c01b..7a9ab6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,13 @@ { - "name": "@cyberlabsai/perse-store", - "version": "0.0.1-alpha.4", + "name": "@cyberlabsai/yoox", + "version": "0.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "@cyberlabsai/perse-store", - "version": "0.0.1-alpha.4", + "name": "@cyberlabsai/yoox", + "version": "0.0.1", "dependencies": { - "lodash.isempty": "^4.4.0", - "lodash.isequal": "^4.5.0", "pouchdb": "^7.2.2", "rxjs": "^6.6.6" }, @@ -8905,16 +8903,6 @@ "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=", "dev": true }, - "node_modules/lodash.isempty": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.isempty/-/lodash.isempty-4.4.0.tgz", - "integrity": "sha1-b4bL7di+TsmHvpqvM8loTbGzHn4=" - }, - "node_modules/lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, "node_modules/loglevel": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.7.1.tgz", @@ -9928,9 +9916,9 @@ } }, "node_modules/path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, "node_modules/path-to-regexp": { @@ -12611,9 +12599,9 @@ } }, "node_modules/url-parse": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.1.tgz", - "integrity": "sha512-HOfCOUJt7iSYzEx/UqgtwKRMC6EU91NFhsCHMv9oM03VJcVo2Qrp8T8kI9D7amFf1cu+/3CEhgb3rF9zL7k85Q==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.3.tgz", + "integrity": "sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==", "dev": true, "dependencies": { "querystringify": "^2.1.1", @@ -13952,9 +13940,9 @@ } }, "node_modules/webpack-dev-server/node_modules/ws": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", - "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", + "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", "dev": true, "dependencies": { "async-limiter": "~1.0.0" @@ -14344,9 +14332,9 @@ "integrity": "sha1-8y124/uGM0SlSNeZIwBxc2ZbO40=" }, "node_modules/ws": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz", - "integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", + "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", "dev": true, "engines": { "node": ">=8.3.0" @@ -21548,16 +21536,6 @@ "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=", "dev": true }, - "lodash.isempty": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.isempty/-/lodash.isempty-4.4.0.tgz", - "integrity": "sha1-b4bL7di+TsmHvpqvM8loTbGzHn4=" - }, - "lodash.isequal": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", - "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=" - }, "loglevel": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.7.1.tgz", @@ -22368,9 +22346,9 @@ "dev": true }, "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, "path-to-regexp": { @@ -24602,9 +24580,9 @@ } }, "url-parse": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.1.tgz", - "integrity": "sha512-HOfCOUJt7iSYzEx/UqgtwKRMC6EU91NFhsCHMv9oM03VJcVo2Qrp8T8kI9D7amFf1cu+/3CEhgb3rF9zL7k85Q==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.3.tgz", + "integrity": "sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==", "dev": true, "requires": { "querystringify": "^2.1.1", @@ -25802,9 +25780,9 @@ } }, "ws": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", - "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", + "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", "dev": true, "requires": { "async-limiter": "~1.0.0" @@ -26020,9 +25998,9 @@ } }, "ws": { - "version": "7.4.5", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz", - "integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.3.tgz", + "integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg==", "dev": true, "requires": {} }, From 57010fc9b2947b5507b4c4874f0856d2208550cb Mon Sep 17 00:00:00 2001 From: Gabriel Santiago Cardoso Rizzo Date: Thu, 26 Aug 2021 16:28:49 -0300 Subject: [PATCH 15/15] Adding new package name to lib --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 37c9bc6..29cd5c9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@yoonit/yoox", + "name": "@yoonit/yoox-store-js", "version": "0.0.1", - "description": "The official Cyberlabs store library.", + "description": "The official Cyberlabs Javascript global store library.", "main": "dist/bundle.js", "files": [ "dist/"