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

feat!: remove ErrorHandlerContext and rename package #687

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ncurc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dep": "dev,prod,peer"
}
12 changes: 6 additions & 6 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**
!src
!src/**/*
!lib
!lib/**/*
!*.md
!package.json
!/src/
!/src/**/*
!/lib/
!/lib/**/*
!/*.md
!/package.json
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion __tests__/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Copyright: Technology Studio
**/

import './Config/LogConfig'
import 'Config/LogConfig'

// Mock your external modules here if needed
// jest
Expand Down
9 changes: 9 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 2 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -15,9 +15,6 @@ module.exports = {
testMatch: [
'<rootDir>/__tests__/Tests/**/?(*.)(spec|test).ts'
],
transformIgnorePatterns: [
'/node_modules/(?!@txo).+\\.js$'
],
testPathIgnorePatterns: [
'/node_modules/'
],
Expand All @@ -29,7 +26,7 @@ module.exports = {
],
transform: {
'^.+\\.tsx?$': ['ts-jest', {
tsconfig: './tsconfig.json'
tsconfig: '<rootDir>/__tests__/tsconfig.json'
}]
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths , { prefix: '<rootDir>/' } ),
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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 .",
Expand All @@ -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"
Expand Down
22 changes: 0 additions & 22 deletions src/Api/ErrorHandlerContext.ts

This file was deleted.

58 changes: 12 additions & 46 deletions src/Api/ErrorHandlerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,22 @@
**/

import { Log } from '@txo/log'
import type { ServiceErrorException } 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 = (serviceErrorException: ServiceErrorException) => void
let 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 (serviceErrorException: ServiceErrorException): void {
log.debug('EMIT', serviceErrorException)
for (const subscription of this._subscriptionList) {
subscription(serviceErrorException)
}
}

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 (serviceErrorException: ServiceErrorException): void {
log.debug('EMIT', serviceErrorException)
for (const subscription of this._middlewareSubscriptionList) {
subscription(serviceErrorException)
}
}
export const subscribeErrorListener = (errorListener: ErrorListener) => {
errorListenerList.push(errorListener)
return () => {
errorListenerList = errorListenerList.filter(listener => listener !== errorListener)
}
}

export const errorHandlerManager: ErrorHandlerManager = new ErrorHandlerManager()
25 changes: 0 additions & 25 deletions src/Model/Types.ts

This file was deleted.

8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,4 @@
* @Copyright: Technology Studio
**/

export type {
ErrorHandler,
ErrorHandlerAttributes,
ContextServiceErrorExceptionMap,
} from './Model/Types'
export { ErrorHandlerContext } from './Api/ErrorHandlerContext'
export { errorHandlerManager } from './Api/ErrorHandlerManager'
export * from './Api/ErrorHandlerManager'
20 changes: 0 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -1390,13 +1382,6 @@
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==
dependencies:
"@txo/functional" "^4.6.19"

"@txo/tsconfig@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@txo/tsconfig/-/tsconfig-1.1.1.tgz#0e746a34c5a5092459235e15588fb33e94cbf067"
Expand Down Expand Up @@ -8132,11 +8117,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"
Expand Down
Loading