diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 95e3b7f8..bb4a3074 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -208,7 +208,7 @@ dependencies: version: 10.2.3 poolifier: specifier: ^3.0.0 - version: 3.0.0 + version: 3.0.1 preview-email: specifier: ^3.0.19 version: 3.0.19 @@ -611,7 +611,7 @@ packages: '@smithy/invalid-dependency': 2.0.11 '@smithy/md5-js': 2.0.11 '@smithy/middleware-content-length': 2.0.13 - '@smithy/middleware-endpoint': 2.1.0 + '@smithy/middleware-endpoint': 2.1.1 '@smithy/middleware-retry': 2.0.16 '@smithy/middleware-serde': 2.0.11 '@smithy/middleware-stack': 2.0.5 @@ -659,7 +659,7 @@ packages: '@smithy/hash-node': 2.0.11 '@smithy/invalid-dependency': 2.0.11 '@smithy/middleware-content-length': 2.0.13 - '@smithy/middleware-endpoint': 2.1.0 + '@smithy/middleware-endpoint': 2.1.1 '@smithy/middleware-retry': 2.0.16 '@smithy/middleware-serde': 2.0.11 '@smithy/middleware-stack': 2.0.5 @@ -703,7 +703,7 @@ packages: '@smithy/hash-node': 2.0.11 '@smithy/invalid-dependency': 2.0.11 '@smithy/middleware-content-length': 2.0.13 - '@smithy/middleware-endpoint': 2.1.0 + '@smithy/middleware-endpoint': 2.1.1 '@smithy/middleware-retry': 2.0.16 '@smithy/middleware-serde': 2.0.11 '@smithy/middleware-stack': 2.0.5 @@ -748,7 +748,7 @@ packages: '@smithy/hash-node': 2.0.11 '@smithy/invalid-dependency': 2.0.11 '@smithy/middleware-content-length': 2.0.13 - '@smithy/middleware-endpoint': 2.1.0 + '@smithy/middleware-endpoint': 2.1.1 '@smithy/middleware-retry': 2.0.16 '@smithy/middleware-serde': 2.0.11 '@smithy/middleware-stack': 2.0.5 @@ -1025,7 +1025,7 @@ packages: '@smithy/hash-node': 2.0.11 '@smithy/invalid-dependency': 2.0.11 '@smithy/middleware-content-length': 2.0.13 - '@smithy/middleware-endpoint': 2.1.0 + '@smithy/middleware-endpoint': 2.1.1 '@smithy/middleware-retry': 2.0.16 '@smithy/middleware-serde': 2.0.11 '@smithy/middleware-stack': 2.0.5 @@ -1476,8 +1476,8 @@ packages: dev: true optional: true - /@commitlint/load@17.7.2(@swc/core@1.3.93): - resolution: {integrity: sha512-XA7WTnsjHZ4YH6ZYsrnxgLdXzriwMMq+utZUET6spbOEEIPBCDLdOQXS26P+v3TTO4hUHOEhzUquaBv3jbBixw==} + /@commitlint/load@17.8.0(@swc/core@1.3.93): + resolution: {integrity: sha512-9VnGXYJCP4tXmR4YrwP8n5oX6T5ZsHfPQq6WuUQOvAI+QsDQMaTGgTRXr7us+xsjz+b+mMBSagogqfUx2aixyw==} engines: {node: '>=v14'} requiresBuild: true dependencies: @@ -2030,7 +2030,7 @@ packages: dependencies: '@graphql-tools/utils': 9.2.1(graphql@16.8.1) graphql: 16.8.1 - tslib: 2.6.2 + tslib: 2.5.0 dev: false optional: true @@ -2043,7 +2043,7 @@ packages: '@graphql-tools/merge': 8.3.18(graphql@16.8.1) '@graphql-tools/utils': 9.2.1(graphql@16.8.1) graphql: 16.8.1 - tslib: 2.6.2 + tslib: 2.5.0 value-or-promise: 1.0.12 dev: false optional: true @@ -2056,7 +2056,7 @@ packages: dependencies: '@graphql-typed-document-node/core': 3.2.0(graphql@16.8.1) graphql: 16.8.1 - tslib: 2.6.2 + tslib: 2.5.0 dev: false optional: true @@ -3650,7 +3650,7 @@ packages: eslint-plugin-no-only-tests: 3.1.0 eslint-plugin-react: 7.33.2(eslint@8.51.0) eslint-plugin-react-hooks: 4.6.0(eslint@8.51.0) - eslint-plugin-rubiin: 1.8.21(eslint@8.51.0)(typescript@5.2.2) + eslint-plugin-rubiin: 1.8.26(eslint@8.51.0)(typescript@5.2.2) eslint-plugin-sonarjs: 0.21.0(eslint@8.51.0) eslint-plugin-unicorn: 48.0.1(eslint@8.51.0) eslint-plugin-unused-imports: 3.0.0(@typescript-eslint/eslint-plugin@6.7.5)(eslint@8.51.0) @@ -3943,12 +3943,13 @@ packages: tslib: 2.6.2 dev: false - /@smithy/middleware-endpoint@2.1.0: - resolution: {integrity: sha512-e6HZbfrp9CNTJqIPSgkydB9mNQXiq5pkHF3ZB6rOzPPR9PkJBoGFo9TcM7FaaKFUaH4Kc20AX6WwwVyIlNhXTA==} + /@smithy/middleware-endpoint@2.1.1: + resolution: {integrity: sha512-YAqGagBvHqDEew4EGz9BrQ7M+f+u7ck9EL4zzYirOhIcXeBS/+q4A5+ObHDDwEp38lD6t88YUtFy3OptqEaDQg==} engines: {node: '>=14.0.0'} dependencies: '@smithy/middleware-serde': 2.0.11 '@smithy/node-config-provider': 2.1.1 + '@smithy/shared-ini-file-loader': 2.2.0 '@smithy/types': 2.3.5 '@smithy/url-parser': 2.0.11 '@smithy/util-middleware': 2.0.4 @@ -4888,8 +4889,8 @@ packages: resolution: {integrity: sha512-d0XxK3YTObnWVp6rZuev3c49+j4Lo8g4L1ZRm9z5L0xpoZycUPshHgczK5gsUMaZOstjVYYi09p5gYvUtfChYw==} dev: true - /@types/validator@13.11.2: - resolution: {integrity: sha512-nIKVVQKT6kGKysnNt+xLobr+pFJNssJRi2s034wgWeFBUx01fI8BeHTW2TcRp7VcFu9QCYG8IlChTuovcm0oKQ==} + /@types/validator@13.11.3: + resolution: {integrity: sha512-jxjhh33aTYDHnrV1vZ3AvWQHfrGx2f5UxKjaP13l5q04fG+/hCKKm0MfodIoCqxevhbcfBb6ZjynyHuQ/jueGQ==} /@types/yargs-parser@21.0.1: resolution: {integrity: sha512-axdPBuLuEJt0c4yI5OZssC19K2Mq1uKdrfZBzuxLvaztgqUtFYZUNw7lETExPYJR9jdEoIg4mb7RQKRQzOkeGQ==} @@ -5096,7 +5097,7 @@ packages: resolution: {integrity: sha512-IG5aDD8S6zlvloDsnzHw0Ut5xczlF+kv2BOTo+iXfPr54Yhi5qbVOgGB1hZaVq4iJ4C/MZ2J0y15IlsV/ZcI0A==} dependencies: diff-sequences: 29.6.3 - loupe: 2.3.6 + loupe: 2.3.7 pretty-format: 29.7.0 dev: true @@ -5892,8 +5893,8 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001547 - electron-to-chromium: 1.4.551 + caniuse-lite: 1.0.30001549 + electron-to-chromium: 1.4.554 node-releases: 2.0.13 update-browserslist-db: 1.0.13(browserslist@4.22.1) dev: true @@ -5998,7 +5999,7 @@ packages: /call-bind@1.0.2: resolution: {integrity: sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==} dependencies: - function-bind: 1.1.1 + function-bind: 1.1.2 get-intrinsic: 1.2.1 /callsites@3.1.0: @@ -6014,8 +6015,8 @@ packages: resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} engines: {node: '>=10'} - /caniuse-lite@1.0.30001547: - resolution: {integrity: sha512-W7CrtIModMAxobGhz8iXmDfuJiiKg1WADMO/9x7/CLNin5cpSbuBjooyoIUVB5eyCc36QuTVlkVa1iB2S5+/eA==} + /caniuse-lite@1.0.30001549: + resolution: {integrity: sha512-qRp48dPYSCYaP+KurZLhDYdVE+yEyht/3NlmcJgVQ2VMGt6JL36ndQ/7rgspdZsJuxDPFIo/OzBT2+GmIJ53BA==} dev: true /canvg@3.0.10: @@ -6051,7 +6052,7 @@ packages: check-error: 1.0.3 deep-eql: 4.1.3 get-func-name: 2.0.2 - loupe: 2.3.6 + loupe: 2.3.7 pathval: 1.1.1 type-detect: 4.0.8 dev: true @@ -6168,7 +6169,7 @@ packages: /class-validator@0.14.0: resolution: {integrity: sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A==} dependencies: - '@types/validator': 13.11.2 + '@types/validator': 13.11.3 libphonenumber-js: 1.10.47 validator: 13.11.0 @@ -6641,7 +6642,7 @@ packages: longest: 2.0.1 word-wrap: 1.2.5 optionalDependencies: - '@commitlint/load': 17.7.2(@swc/core@1.3.93) + '@commitlint/load': 17.8.0(@swc/core@1.3.93) transitivePeerDependencies: - '@swc/core' - '@swc/wasm' @@ -6770,8 +6771,8 @@ packages: clone: 1.0.4 dev: true - /define-data-property@1.1.0: - resolution: {integrity: sha512-UzGwzcjyv3OtAvolTj1GoyNYzfFR+iqbGjcnBEENZVCpM4/Ng1yhGNvS3lR/xDS74Tb2wGG9WzNSNIOS9UVb2g==} + /define-data-property@1.1.1: + resolution: {integrity: sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==} engines: {node: '>= 0.4'} dependencies: get-intrinsic: 1.2.1 @@ -6783,7 +6784,7 @@ packages: resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} engines: {node: '>= 0.4'} dependencies: - define-data-property: 1.1.0 + define-data-property: 1.1.1 has-property-descriptors: 1.0.0 object-keys: 1.1.1 dev: true @@ -6957,8 +6958,8 @@ packages: /ee-first@1.1.1: resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==} - /electron-to-chromium@1.4.551: - resolution: {integrity: sha512-/Ng/W/kFv7wdEHYzxdK7Cv0BHEGSkSB3M0Ssl8Ndr1eMiYeas/+Mv4cNaDqamqWx6nd2uQZfPz6g25z25M/sdw==} + /electron-to-chromium@1.4.554: + resolution: {integrity: sha512-Q0umzPJjfBrrj8unkONTgbKQXzXRrH7sVV7D9ea2yBV3Oaogz991yhbpfvo2LMNkJItmruXTEzVpP9cp7vaIiQ==} dev: true /emittery@0.13.1: @@ -7071,7 +7072,7 @@ packages: is-string: 1.0.7 is-typed-array: 1.1.12 is-weakref: 1.0.2 - object-inspect: 1.12.3 + object-inspect: 1.13.0 object-keys: 1.1.1 object.assign: 4.1.4 regexp.prototype.flags: 1.5.1 @@ -7096,7 +7097,7 @@ packages: define-properties: 1.2.1 es-abstract: 1.22.2 es-set-tostringtag: 2.0.1 - function-bind: 1.1.1 + function-bind: 1.1.2 get-intrinsic: 1.2.1 globalthis: 1.0.3 has-property-descriptors: 1.0.0 @@ -7418,10 +7419,10 @@ packages: string.prototype.matchall: 4.0.10 dev: true - /eslint-plugin-rubiin@1.8.21(eslint@8.51.0)(typescript@5.2.2): - resolution: {integrity: sha512-88Oeajg+3J00CaHZa07e3BOByJn8ncttH+Y3BKIFYuImn6fkhrZeWFZbFaHWq/1kUPrHIy+XmWQliUM5EpYn5w==} + /eslint-plugin-rubiin@1.8.26(eslint@8.51.0)(typescript@5.2.2): + resolution: {integrity: sha512-oA71xf3WGX68RzxiN86TuiL7X88pxoJqz5+HDQ/06LRX4QJrzgvSebpdWvfZT6sjBau3iMd53CeJ5N+1QSMpvQ==} peerDependencies: - eslint: '*' + eslint: '>=8.0.0' dependencies: '@typescript-eslint/utils': 6.7.5(eslint@8.51.0)(typescript@5.2.2) eslint: 8.51.0 @@ -8227,8 +8228,8 @@ packages: requiresBuild: true optional: true - /function-bind@1.1.1: - resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} + /function-bind@1.1.2: + resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} /function.prototype.name@1.1.6: resolution: {integrity: sha512-Z5kx79swU5P27WEayXM1tBi5Ze/lbIyiNgU3qyXUOf9b2rgXYyF9Dy9Cx+IQv/Lc8WCG6L82zwUPpSS9hGehIg==} @@ -8314,7 +8315,7 @@ packages: /get-intrinsic@1.2.1: resolution: {integrity: sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==} dependencies: - function-bind: 1.1.1 + function-bind: 1.1.2 has: 1.0.4 has-proto: 1.0.1 has-symbols: 1.0.3 @@ -8554,7 +8555,7 @@ packages: graphql: ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 dependencies: graphql: 16.8.1 - tslib: 2.6.2 + tslib: 2.5.0 dev: false optional: true @@ -8986,7 +8987,6 @@ packages: /is-arrayish@0.2.1: resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} - requiresBuild: true /is-arrayish@0.3.2: resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==} @@ -9771,8 +9771,8 @@ packages: '@sideway/formula': 3.0.1 '@sideway/pinpoint': 2.0.0 - /jose@4.15.3: - resolution: {integrity: sha512-RZJdL9Qjd1sqNdyiVteRGV/bnWtik/+PJh1JP4kT6+x1QQMn+7ryueRys5BEueuayvSVY8CWGCisCDazeRLTuw==} + /jose@4.15.4: + resolution: {integrity: sha512-W+oqK4H+r5sITxfxpSU+MMdr/YSWGvgZMQDIsNoBDGGy4i7GBPTtvFKibQzW06n3U3TqHjhvBJsirShsEJ6eeQ==} dev: false /joycon@3.1.1: @@ -10039,7 +10039,7 @@ packages: '@types/express': 4.17.19 '@types/jsonwebtoken': 9.0.3 debug: 4.3.4 - jose: 4.15.3 + jose: 4.15.4 limiter: 1.1.5 lru-memoizer: 2.2.0 transitivePeerDependencies: @@ -10210,7 +10210,6 @@ packages: /lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} - requiresBuild: true dev: true /lines-and-columns@2.0.3: @@ -10399,8 +10398,8 @@ packages: js-tokens: 4.0.0 dev: true - /loupe@2.3.6: - resolution: {integrity: sha512-RaPMZKiMy8/JruncMU5Bt6na1eftNoo++R4Y+N2FrxkDVTrGvcyzFTsaGif4QTeKESheMGegbhw6iUAq+5A8zA==} + /loupe@2.3.7: + resolution: {integrity: sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==} dependencies: get-func-name: 2.0.2 dev: true @@ -11086,8 +11085,8 @@ packages: resolution: {integrity: sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==} engines: {node: '>= 6'} - /object-inspect@1.12.3: - resolution: {integrity: sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==} + /object-inspect@1.13.0: + resolution: {integrity: sha512-HQ4J+ic8hKrgIt3mqk6cVOVrW2ozL4KdvHlqpBv9vDYWx9ysAgENAdvy4FoGF+KFdhR7nQTNm5J0ctAeOwn+3g==} /object-keys@1.1.1: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} @@ -11315,7 +11314,6 @@ packages: /parent-module@1.0.1: resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} engines: {node: '>=6'} - requiresBuild: true dependencies: callsites: 3.1.0 dev: true @@ -11697,8 +11695,8 @@ packages: resolution: {integrity: sha512-3IKLNXclQgkU++2fSi93sQ6BznFuxSLB11HdvZQ6JW/spahf/P1pAHBQEahr20rs0htZW0UDkM1HmA+nZkXKsw==} engines: {node: '>=12.0.0'} - /poolifier@3.0.0: - resolution: {integrity: sha512-Jp5xkqNNhswcOuCisP03hjfi4KXIzNy73e/EcGupI4sbeQMTOKgcRiW1VCfg2Mq29ldkf6sMm79HI5WovaUV/A==} + /poolifier@3.0.1: + resolution: {integrity: sha512-O1mLQAW7fyVVam8kqQAW0dWKcqm22c2pgmFfaNBTPvzUKh9B9xaPsHnYhJP2rtqDVOcPXjYHNdt4y8A4GoE7jQ==} engines: {node: '>=18.0.0', pnpm: '>=8.6.0'} requiresBuild: true dev: false @@ -12354,7 +12352,6 @@ packages: /resolve-from@4.0.0: resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} engines: {node: '>=4'} - requiresBuild: true dev: true /resolve-from@5.0.0: @@ -12650,7 +12647,7 @@ packages: resolution: {integrity: sha512-tMNCiqYVkXIZgc2Hnoy2IvC/f8ezc5koaRFkCjrpWzGpCd3qbZXPzVy9MAZzK1ch/X0jvSkojys3oqJN0qCmdA==} engines: {node: '>= 0.4'} dependencies: - define-data-property: 1.1.0 + define-data-property: 1.1.1 functions-have-names: 1.2.3 has-property-descriptors: 1.0.0 dev: true @@ -12727,7 +12724,7 @@ packages: dependencies: call-bind: 1.0.2 get-intrinsic: 1.2.1 - object-inspect: 1.12.3 + object-inspect: 1.13.0 /siginfo@2.0.0: resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} @@ -14543,7 +14540,7 @@ packages: dependencies: eslint-visitor-keys: 3.4.3 lodash: 4.17.21 - yaml: 2.3.2 + yaml: 2.3.3 dev: true /yaml@1.10.2: @@ -14556,6 +14553,11 @@ packages: engines: {node: '>= 14'} dev: true + /yaml@2.3.3: + resolution: {integrity: sha512-zw0VAJxgeZ6+++/su5AFoqBbZbrEakwu+X0M5HmcwUiBL7AzcuPKjj5we4xfQLp78LkEMpD0cOnUhmgOVy3KdQ==} + engines: {node: '>= 14'} + dev: true + /yargs-parser@18.1.3: resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==} engines: {node: '>=6'} diff --git a/src/common/misc/pool.ts b/src/common/misc/pool.ts index 44fc768a..3256b695 100644 --- a/src/common/misc/pool.ts +++ b/src/common/misc/pool.ts @@ -2,23 +2,35 @@ import path from "node:path"; import { Logger } from "@nestjs/common"; import { DynamicThreadPool, PoolEvents, availableParallelism } from "poolifier"; +import type { WorkerData, WorkerResponse } from "./workers"; const logger = new Logger("ThreadPool"); +/* The `workerFile` constant is creating a file path to the worker file. It uses the `path.join()` +method to join the current directory (`__dirname`) with the `workers` directory and the extension of +the current file (`__filename`). This ensures that the correct worker file is referenced regardless +of the current directory or file name. */ const workerFile = path.join( __dirname, `workers${path.extname(__filename)}`, ); /* Creating a new thread pool with half of available threads and a maximum of available threads. */ -export const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), workerFile, { - enableTasksQueue: true, - tasksQueueOptions: { - concurrency: 8, +export const pool = new DynamicThreadPool< +WorkerData, +WorkerResponse +>(Math.floor(availableParallelism() / 2), + availableParallelism(), + workerFile, + { + enableTasksQueue: true, + tasksQueueOptions: { + concurrency: 8, + }, + errorHandler: error => logger.error(error), + onlineHandler: () => logger.log("⚡️ Worker is online"), }, - errorHandler: error => logger.error(error), - onlineHandler: () => logger.log("✅ Worker is online"), -}); +); pool.emitter?.on(PoolEvents.ready, () => logger.log("✅ Pool is ready")); pool.emitter?.on(PoolEvents.busy, () => logger.log("🔵 Pool is busy")); diff --git a/src/common/misc/workers.ts b/src/common/misc/workers.ts index bf88f96a..675a0f2b 100644 --- a/src/common/misc/workers.ts +++ b/src/common/misc/workers.ts @@ -1,17 +1,31 @@ -import { ThreadWorker } from "poolifier"; -import { HelperService } from "@common/helpers"; -import { ThreadFunctions } from "@common/@types"; +import { HelperService } from "@common/helpers" +import { ThreadWorker } from 'poolifier' -// all expensive process goes here to avoid blocking the main thread -function workerFunction(data: { functionName: string; input: string }) { - if (data.functionName === ThreadFunctions.HASH_STRING) - return HelperService.hashString(data.input); +export interface WorkerData { + input: T +} - throw new Error(`Invalid thread function name, available are ${Object.keys(ThreadFunctions).join(" ,")}`); +export interface WorkerResponse { + response: T } -const threadWorker = new ThreadWorker(workerFunction as any); +class FunctionHandlerWorker< + Data extends WorkerData, + Response extends WorkerResponse +> extends ThreadWorker { + + public constructor() { + super({ + hashString: async (workerData?: Data) => { + const hashedString = await HelperService.hashString(JSON.stringify(workerData)); + return { response: hashedString } as Response; + } + }); + } -export default threadWorker; +} -// TODO: fix this +export const requestHandlerWorker = new FunctionHandlerWorker< +WorkerData, +WorkerResponse +>() diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 5acba943..fdd30bb9 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -107,7 +107,7 @@ export class AuthController { user: OauthResponse, @Res() response: Response, ) { - return this.authService.oauthHandler({ response, user }); + return this.authService.OauthHandler({ response, user }); } @Get("facebook") @@ -123,7 +123,7 @@ export class AuthController { user: OauthResponse, @Res() response: Response, ) { - return this.authService.oauthHandler({ response, user }); + return this.authService.OauthHandler({ response, user }); } // this simulates a frontend url for testing oauth login @@ -165,7 +165,7 @@ export class AuthController { @Post("logout") logout( @LoggedInUser() user: User, - @Query("from_all", new DefaultValuePipe(false), ParseBoolPipe) fromAll: boolean, + @Query("fromAll", new DefaultValuePipe(false), ParseBoolPipe) fromAll?: boolean, @Body() refreshToken?: RefreshTokenDto, ): Observable { return fromAll diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index 577c33c3..823b7579 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -273,6 +273,7 @@ export class AuthService { * contains the OTP code that needs to be verified. * @returns The `verifyOtp` function returns an Observable of type `User`. */ + verifyOtp(otpDto: OtpVerifyDto): Observable { const { otpCode } = otpDto; @@ -336,6 +337,7 @@ export class AuthService { * @param user - User - The user object that is currently logged in. * @returns Observable of type User */ + changePassword(dto: ChangePasswordDto, user: User): Observable { const { password, oldPassword } = dto; @@ -377,6 +379,14 @@ export class AuthService { ); } + /** + * The function `findUser` searches for a user based on a given condition and returns the user if + * found, otherwise it throws an UnauthorizedException. + * @param condition - The `condition` parameter is a filter query that specifies the conditions to + * match when searching for a user. It is used to filter the user records in the database and find a + * specific user that meets the specified conditions. + * @returns a Promise that resolves to a User object. + */ async findUser(condition: FilterQuery): Promise { const user = await this.userRepository.findOne(condition); @@ -385,7 +395,12 @@ export class AuthService { return user; } - oauthHandler({ response, user }: { response: Response; user: OauthResponse }) { + /** + * The `OauthHandler` function handles the OAuth login process and redirects the user to the client URL + * with the access token. + * @returns a redirect response to a client URL with an access token as a query parameter. + */ + OauthHandler({ response, user }: { response: Response; user: OauthResponse }) { return this.login({ email: user.email }, false).pipe( map((data) => { // client url diff --git a/tsconfig.json b/tsconfig.json index afcf2024..5a928f28 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,7 @@ "include": [ "test/**/*", "src/**/*", - "eslint.config.mjs" + "eslint.config.js" ], "exclude": [ "node_modules",