From e419ee4f2888e3900682f555582748f7e03b1b13 Mon Sep 17 00:00:00 2001 From: Erik Slovak Date: Fri, 25 Oct 2024 17:46:02 +0200 Subject: [PATCH 1/4] feat!: change error handler context to only report operation errors --- .ncurc.json | 3 +++ .npmignore | 12 ++++++------ __tests__/Setup.ts | 2 +- __tests__/tsconfig.json | 9 +++++++++ jest.config.js | 7 ++----- package.json | 2 +- src/Api/ErrorHandlerContext.ts | 10 +++------- src/Api/ErrorHandlerManager.ts | 16 ++++++++-------- src/Model/Types.ts | 11 ++--------- src/index.ts | 1 - 10 files changed, 35 insertions(+), 38 deletions(-) create mode 100644 .ncurc.json diff --git a/.ncurc.json b/.ncurc.json new file mode 100644 index 0000000..f3b330f --- /dev/null +++ b/.ncurc.json @@ -0,0 +1,3 @@ +{ + "dep": "dev,prod,peer" +} diff --git a/.npmignore b/.npmignore index 9c4a959..6472a46 100644 --- a/.npmignore +++ b/.npmignore @@ -1,7 +1,7 @@ ** -!src -!src/**/* -!lib -!lib/**/* -!*.md -!package.json +!/src/ +!/src/**/* +!/lib/ +!/lib/**/* +!/*.md +!/package.json diff --git a/__tests__/Setup.ts b/__tests__/Setup.ts index 9f90513..e01160f 100644 --- a/__tests__/Setup.ts +++ b/__tests__/Setup.ts @@ -4,7 +4,7 @@ * @Copyright: Technology Studio **/ -import './Config/LogConfig' +import 'Config/LogConfig' // Mock your external modules here if needed // jest diff --git a/__tests__/tsconfig.json b/__tests__/tsconfig.json index 34b4c6e..588d821 100644 --- a/__tests__/tsconfig.json +++ b/__tests__/tsconfig.json @@ -1,6 +1,15 @@ { "extends": "../tsconfig-base.json", "compilerOptions": { + "rootDir": "../", + "baseUrl": "../", + "paths": { + "Config/*": ["./__tests__/Config/*"], + "Data/*": ["./__tests__/Data/*"], + "Utils/*": ["./__tests__/Utils/*"], + "src": ["./src"], + "src/*": ["./src/*"] + } }, "include": [ "./**/*.ts" diff --git a/jest.config.js b/jest.config.js index 4b13d8b..890be09 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,7 +5,7 @@ **/ const { pathsToModuleNameMapper } = require('ts-jest') -const { compilerOptions } = require('./tsconfig.json'); +const { compilerOptions } = require('./__tests__/tsconfig.json'); const { defaults } = require('jest-config'); @@ -15,9 +15,6 @@ module.exports = { testMatch: [ '/__tests__/Tests/**/?(*.)(spec|test).ts' ], - transformIgnorePatterns: [ - '/node_modules/(?!@txo).+\\.js$' - ], testPathIgnorePatterns: [ '/node_modules/' ], @@ -29,7 +26,7 @@ module.exports = { ], transform: { '^.+\\.tsx?$': ['ts-jest', { - tsconfig: './tsconfig.json' + tsconfig: '/__tests__/tsconfig.json' }] }, moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths , { prefix: '/' } ), diff --git a/package.json b/package.json index 40e4299..497e071 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "build:lib": "yarn tsc", "build:watch": "yarn tsc --watch", "test": "jest", - "test:watch": "concurrently \"yarn build:watch\" \"jest --watch\"", + "test:watch": "concurrently \"yarn build:watch\" \"yarn test --watch\"", "coverage": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html", "compare-boilerplate-version": "./scripts/compare-boilerplate-version.sh", "lint": "eslint --max-warnings 0 .", diff --git a/src/Api/ErrorHandlerContext.ts b/src/Api/ErrorHandlerContext.ts index d8bd647..688b761 100644 --- a/src/Api/ErrorHandlerContext.ts +++ b/src/Api/ErrorHandlerContext.ts @@ -6,17 +6,13 @@ import { createContext } from 'react' import type { - ServiceErrorException, + ServiceOperationError, } from '@txo/service-prop' type Context = { - addServiceErrorException: (serviceErrorException: ServiceErrorException) => void, - removeServiceErrorException: (context: string) => void, - removeAllServiceErrors: () => void, + reportServiceOperationError: (serviceOperationError: ServiceOperationError) => void, } export const ErrorHandlerContext = createContext({ - addServiceErrorException: () => undefined, - removeServiceErrorException: () => undefined, - removeAllServiceErrors: () => undefined, + reportServiceOperationError: () => undefined, }) diff --git a/src/Api/ErrorHandlerManager.ts b/src/Api/ErrorHandlerManager.ts index 0b30b89..7a55955 100644 --- a/src/Api/ErrorHandlerManager.ts +++ b/src/Api/ErrorHandlerManager.ts @@ -5,13 +5,13 @@ **/ import { Log } from '@txo/log' -import type { ServiceErrorException } from '@txo/service-prop' +import type { ServiceOperationError } from '@txo/service-prop' import type { ErrorHandler } from '../Model/Types' const log = new Log('@txo-peer-dep.service-error-handler-react.Api.ErrorHandlerManager') -type ErrorListSubscription = (serviceErrorException: ServiceErrorException) => void +type ErrorListSubscription = (serviceOperationError: ServiceOperationError) => void class ErrorHandlerManager { _handlerSequence: ErrorHandler[] | null = null @@ -35,10 +35,10 @@ class ErrorHandlerManager { } } - emit (serviceErrorException: ServiceErrorException): void { - log.debug('EMIT', serviceErrorException) + emit (serviceOperationError: ServiceOperationError): void { + log.debug('EMIT', serviceOperationError) for (const subscription of this._subscriptionList) { - subscription(serviceErrorException) + subscription(serviceOperationError) } } @@ -49,10 +49,10 @@ class ErrorHandlerManager { } } - emitMiddleware (serviceErrorException: ServiceErrorException): void { - log.debug('EMIT', serviceErrorException) + emitMiddleware (serviceOperationError: ServiceOperationError): void { + log.debug('EMIT', serviceOperationError) for (const subscription of this._middlewareSubscriptionList) { - subscription(serviceErrorException) + subscription(serviceOperationError) } } } diff --git a/src/Model/Types.ts b/src/Model/Types.ts index 54223be..3ade66c 100644 --- a/src/Model/Types.ts +++ b/src/Model/Types.ts @@ -5,21 +5,14 @@ **/ import type { - ServiceErrorException, - ServiceError, + ServiceOperationError, } from '@txo/service-prop' import type React from 'react' -export type ContextServiceErrorExceptionMap = Record - export type ErrorHandler = (attributes: ErrorHandlerAttributes) => React.ReactNode export type ErrorHandlerAttributes = { children: React.ReactNode, next?: () => ErrorHandler, - contextServiceErrorExceptionMap: ContextServiceErrorExceptionMap, - addServiceErrorException: (serviceErrorException: ServiceErrorException) => void, - removeServiceErrorException: (context: string) => void, - removeAllServiceErrors: () => void, - serviceErrorList: ServiceError[], + reportServiceOperationError: (serviceOperationError: ServiceOperationError) => void, } diff --git a/src/index.ts b/src/index.ts index cce409b..87514dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,7 +7,6 @@ export type { ErrorHandler, ErrorHandlerAttributes, - ContextServiceErrorExceptionMap, } from './Model/Types' export { ErrorHandlerContext } from './Api/ErrorHandlerContext' export { errorHandlerManager } from './Api/ErrorHandlerManager' From c9d96fdbac003fcad5d89d55b635648fa473d082 Mon Sep 17 00:00:00 2001 From: Erik Slovak Date: Fri, 25 Oct 2024 21:00:43 +0200 Subject: [PATCH 2/4] feat!: remove `ErrorHandlerContext` and rename package --- README.md | 8 ++--- package.json | 11 +++---- src/Api/ErrorHandlerContext.ts | 18 ----------- src/Api/ErrorHandlerManager.ts | 58 +++++++--------------------------- src/Model/Types.ts | 18 ----------- src/index.ts | 7 +--- yarn.lock | 27 ++++++---------- 7 files changed, 31 insertions(+), 116 deletions(-) delete mode 100644 src/Api/ErrorHandlerContext.ts delete mode 100644 src/Model/Types.ts diff --git a/README.md b/README.md index 9f87af6..afc459d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -![npm](https://img.shields.io/npm/v/@txo-peer-dep/service-error-handler-react) -![codecov](https://img.shields.io/codecov/c/github/technology-studio/service-error-handler-react-peer) -# Service error handler react # +![npm](https://img.shields.io/npm/v/@txo-peer-dep/error-handler) +![codecov](https://img.shields.io/codecov/c/github/technology-studio/error-handler-peer) +# Error handler peer # -Service error handler react +Error handler peer diff --git a/package.json b/package.json index 497e071..273f437 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { - "name": "@txo-peer-dep/service-error-handler-react", - "version": "1.2.29", - "description": "Technology Studio - Service error handler react peer", + "name": "@txo-peer-dep/error-handler", + "version": "0.0.0", + "description": "Technology Studio - Error handler peer", "main": "lib/index.js", "typings": "lib/index.d.ts", "repository": { "type": "git", - "url": "https://github.com/technology-studio/service-error-handler-react-peer.git" + "url": "https://github.com/technology-studio/error-handler-peer.git" }, "author": { "name": "Technology Studio", @@ -36,8 +36,7 @@ "type-check": "tsc --noEmit" }, "dependencies": { - "@txo/log": "^2.0.16", - "@txo/service-prop": "^2.2.18" + "@txo/log": "^2.0.16" }, "peerDependencies": { "react": "^18.3.1" diff --git a/src/Api/ErrorHandlerContext.ts b/src/Api/ErrorHandlerContext.ts deleted file mode 100644 index 688b761..0000000 --- a/src/Api/ErrorHandlerContext.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @Author: Erik Slovak - * @Date: 2021-09-06T14:09:35+02:00 - * @Copyright: Technology Studio -**/ - -import { createContext } from 'react' -import type { - ServiceOperationError, -} from '@txo/service-prop' - -type Context = { - reportServiceOperationError: (serviceOperationError: ServiceOperationError) => void, -} - -export const ErrorHandlerContext = createContext({ - reportServiceOperationError: () => undefined, -}) diff --git a/src/Api/ErrorHandlerManager.ts b/src/Api/ErrorHandlerManager.ts index 7a55955..99a2628 100644 --- a/src/Api/ErrorHandlerManager.ts +++ b/src/Api/ErrorHandlerManager.ts @@ -5,56 +5,22 @@ **/ import { Log } from '@txo/log' -import type { ServiceOperationError } from '@txo/service-prop' -import type { ErrorHandler } from '../Model/Types' +const log = new Log('@txo-peer-dep.error-handler.Api.ErrorHandlerManager') -const log = new Log('@txo-peer-dep.service-error-handler-react.Api.ErrorHandlerManager') +type ErrorListener = (error: unknown) => void -type ErrorListSubscription = (serviceOperationError: ServiceOperationError) => void +const errorListenerList: ErrorListener[] = [] -class ErrorHandlerManager { - _handlerSequence: ErrorHandler[] | null = null - _subscriptionList: ErrorListSubscription[] = [] - _middlewareSubscriptionList: ErrorListSubscription[] = [] - - setHandlerSequence (handlerSequence: ErrorHandler[]): void { - log.debug('SET ERROR HANDLERS', handlerSequence) - this._handlerSequence = handlerSequence - } - - getHandlerSequence (): ErrorHandler[] | null { - log.debug('GET ERROR HANDLERS', this._handlerSequence) - return this._handlerSequence - } - - subscribe (subscription: ErrorListSubscription): () => void { - this._subscriptionList.push(subscription) - return () => { - this._subscriptionList.filter(s => s !== subscription) - } - } - - emit (serviceOperationError: ServiceOperationError): void { - log.debug('EMIT', serviceOperationError) - for (const subscription of this._subscriptionList) { - subscription(serviceOperationError) - } - } - - subscribeMiddleware (subscription: ErrorListSubscription): () => void { - this._middlewareSubscriptionList.push(subscription) - return () => { - this._middlewareSubscriptionList.filter(s => s !== subscription) - } +export const reportError = (error: unknown): void => { + log.debug('REPORT ERROR', error) + for (const errorListener of errorListenerList) { + errorListener(error) } - - emitMiddleware (serviceOperationError: ServiceOperationError): void { - log.debug('EMIT', serviceOperationError) - for (const subscription of this._middlewareSubscriptionList) { - subscription(serviceOperationError) - } +} +export const subscribeErrorListener = (errorListener: ErrorListener) => { + errorListenerList.push(errorListener) + return () => { + errorListenerList.filter(listener => listener !== errorListener) } } - -export const errorHandlerManager: ErrorHandlerManager = new ErrorHandlerManager() diff --git a/src/Model/Types.ts b/src/Model/Types.ts deleted file mode 100644 index 3ade66c..0000000 --- a/src/Model/Types.ts +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @Author: Erik Slovak - * @Date: 2021-09-06T13:09:68+02:00 - * @Copyright: Technology Studio -**/ - -import type { - ServiceOperationError, -} from '@txo/service-prop' -import type React from 'react' - -export type ErrorHandler = (attributes: ErrorHandlerAttributes) => React.ReactNode - -export type ErrorHandlerAttributes = { - children: React.ReactNode, - next?: () => ErrorHandler, - reportServiceOperationError: (serviceOperationError: ServiceOperationError) => void, -} diff --git a/src/index.ts b/src/index.ts index 87514dc..9f224b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,9 +4,4 @@ * @Copyright: Technology Studio **/ -export type { - ErrorHandler, - ErrorHandlerAttributes, -} from './Model/Types' -export { ErrorHandlerContext } from './Api/ErrorHandlerContext' -export { errorHandlerManager } from './Api/ErrorHandlerManager' +export * from './Api/ErrorHandlerManager' diff --git a/yarn.lock b/yarn.lock index abd0afd..e381ed7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1362,14 +1362,6 @@ resolved "https://registry.yarnpkg.com/@txo/config-manager/-/config-manager-3.2.0.tgz#d6bf817d0b8fa2eece61f79fc99eedf2516d68b1" integrity sha512-P4t09H/Q6AHoyps0jBy5tSp/HruQteyUeoxr758D2entD+rd8f0XXAdcrCCEIBeihlNAkv4MVj/n8bJulw5CLg== -"@txo/functional@^4.6.19": - version "4.6.19" - resolved "https://registry.yarnpkg.com/@txo/functional/-/functional-4.6.19.tgz#b51cb2c71307618e086c512108e60ef2b3cc6591" - integrity sha512-SDmY7+VKENWD/E6oHAWMx8eeNZc6GsTg47+sL8cHuB5+eLMzsxPPxatT1+VdEe5mFc3heNaGRBTiZQVPa6FM7w== - dependencies: - "@txo/log" "^2.0.16" - utility-types "^3.11.0" - "@txo/log-console@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@txo/log-console/-/log-console-3.0.0.tgz#56506a8c6afea9109301ff96520c43815814022d" @@ -1390,18 +1382,22 @@ semantic-release "^23.0.8" semantic-release-slack-bot "^4.0.2" -"@txo/service-prop@^2.2.18": - version "2.2.18" - resolved "https://registry.yarnpkg.com/@txo/service-prop/-/service-prop-2.2.18.tgz#2399b461581bc03cf7f225e69cd98257b6260908" - integrity sha512-uwMjp2ljKH9lvQs+yZX0NmTswkBUSiHJIRXIGzvcRBufdNnz0jn8dqOZLqBHb1H5J/JjjCKUdOUqFXkwYJwQiQ== +"@txo/service-prop@file:../com.github.technology-studio.service-prop/txo-service-prop-v3.0.0.tgz": + version "3.0.0" + resolved "file:../com.github.technology-studio.service-prop/txo-service-prop-v3.0.0.tgz#6d9fcf75b7ce444dd16084766f96ce00ea5892f7" dependencies: - "@txo/functional" "^4.6.19" + "@txo/types" "^1.7.0" "@txo/tsconfig@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@txo/tsconfig/-/tsconfig-1.1.1.tgz#0e746a34c5a5092459235e15588fb33e94cbf067" integrity sha512-YA8LdOoATb+LgwHlVFKxbR6i4xWkr1h6dGTqLh3HHGe25wYzJ7rixNNWucCXaY270Dmb33JQi5sDe6a1XtwRcg== +"@txo/types@^1.7.0": + version "1.7.0" + resolved "https://registry.yarnpkg.com/@txo/types/-/types-1.7.0.tgz#bb9db4417ceae237e51c14897f5c3f8b9f78cba2" + integrity sha512-mZfrfHMZK1hMDXKS7A8uvcBqqzYi5LLqg+wj4sDL77FZjQlZTdzXKlwwdco0HFamBPJS3iiDufW0Q/ZAyeRzSw== + "@types/babel__core@^7.1.14": version "7.1.19" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.19.tgz#7b497495b7d1b4812bdb9d02804d0576f43ee460" @@ -8133,11 +8129,6 @@ util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== -utility-types@^3.11.0: - version "3.11.0" - resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.11.0.tgz#607c40edb4f258915e901ea7995607fdf319424c" - integrity sha512-6Z7Ma2aVEWisaL6TvBCy7P8rm2LQoPv6dJ7ecIaIixHcwfbJ0x7mWdbcwlIM5IGQxPZSFYeqRCqlOOeKoJYMkw== - v8-to-istanbul@^9.0.1: version "9.0.1" resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-9.0.1.tgz#b6f994b0b5d4ef255e17a0d17dc444a9f5132fa4" From 876a36c65b2a154287f0aed4c328e7cd47199279 Mon Sep 17 00:00:00 2001 From: Erik Slovak Date: Fri, 25 Oct 2024 23:08:38 +0200 Subject: [PATCH 3/4] fix: update listener list after removing --- src/Api/ErrorHandlerManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Api/ErrorHandlerManager.ts b/src/Api/ErrorHandlerManager.ts index 99a2628..cb127cf 100644 --- a/src/Api/ErrorHandlerManager.ts +++ b/src/Api/ErrorHandlerManager.ts @@ -10,7 +10,7 @@ const log = new Log('@txo-peer-dep.error-handler.Api.ErrorHandlerManager') type ErrorListener = (error: unknown) => void -const errorListenerList: ErrorListener[] = [] +let errorListenerList: ErrorListener[] = [] export const reportError = (error: unknown): void => { log.debug('REPORT ERROR', error) @@ -21,6 +21,6 @@ export const reportError = (error: unknown): void => { export const subscribeErrorListener = (errorListener: ErrorListener) => { errorListenerList.push(errorListener) return () => { - errorListenerList.filter(listener => listener !== errorListener) + errorListenerList = errorListenerList.filter(listener => listener !== errorListener) } } From 63c4d0199f3d88a5946b7ae871fbe4be1d231d3e Mon Sep 17 00:00:00 2001 From: Erik Slovak Date: Mon, 28 Oct 2024 22:00:19 +0100 Subject: [PATCH 4/4] chore: update yarn.lock --- yarn.lock | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/yarn.lock b/yarn.lock index e381ed7..97028b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1382,22 +1382,11 @@ semantic-release "^23.0.8" semantic-release-slack-bot "^4.0.2" -"@txo/service-prop@file:../com.github.technology-studio.service-prop/txo-service-prop-v3.0.0.tgz": - version "3.0.0" - resolved "file:../com.github.technology-studio.service-prop/txo-service-prop-v3.0.0.tgz#6d9fcf75b7ce444dd16084766f96ce00ea5892f7" - dependencies: - "@txo/types" "^1.7.0" - "@txo/tsconfig@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@txo/tsconfig/-/tsconfig-1.1.1.tgz#0e746a34c5a5092459235e15588fb33e94cbf067" integrity sha512-YA8LdOoATb+LgwHlVFKxbR6i4xWkr1h6dGTqLh3HHGe25wYzJ7rixNNWucCXaY270Dmb33JQi5sDe6a1XtwRcg== -"@txo/types@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@txo/types/-/types-1.7.0.tgz#bb9db4417ceae237e51c14897f5c3f8b9f78cba2" - integrity sha512-mZfrfHMZK1hMDXKS7A8uvcBqqzYi5LLqg+wj4sDL77FZjQlZTdzXKlwwdco0HFamBPJS3iiDufW0Q/ZAyeRzSw== - "@types/babel__core@^7.1.14": version "7.1.19" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.19.tgz#7b497495b7d1b4812bdb9d02804d0576f43ee460"