From de42e7fc8aeaaf03752beb1f7554903adafad8fa Mon Sep 17 00:00:00 2001 From: Inaiat Moraes Date: Fri, 7 Jun 2024 15:09:27 -0300 Subject: [PATCH] fix: namespace declaration model --- BUILD_SHA | 2 +- README.md | 2 +- package.json | 10 +-- pnpm-lock.yaml | 168 ++++++++++++++++++------------------- src/types.ts | 7 +- tests/helpers/model.ts | 35 ++++++++ tests/index.test.ts | 27 ++---- tests/multiple.col.test.ts | 49 ++--------- tests/multiple.db.test.ts | 30 ++----- tests/register.test.ts | 7 +- tests/simple.test.ts | 21 +---- tests/validation.test.ts | 23 ++--- 12 files changed, 161 insertions(+), 220 deletions(-) create mode 100644 tests/helpers/model.ts diff --git a/BUILD_SHA b/BUILD_SHA index 64b2410..6b13cbe 100644 --- a/BUILD_SHA +++ b/BUILD_SHA @@ -1 +1 @@ -739aa6efb9c96e31554306b4761349550825fb2e +f242a65ad6e681b7e51a175bc88c067bdcab744b diff --git a/README.md b/README.md index b4c402b..2e4acf6 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ const userSchema = schema({ const userIndexes = [{ key: { name: 1 } }] -declare module 'fastify' { +declare module '@inaiat/fastify-papr' { interface FastifyPapr { user: Model> } diff --git a/package.json b/package.json index cbf0032..8c733db 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "@inaiat/fastify-papr", - "version": "7.0.1", + "version": "7.0.2", "description": "Fastify Papr Plugin Integration", "type": "module", "engines": { "node": ">=20" }, - "packageManager": "pnpm@9.1.4", + "packageManager": "pnpm@9.2.0", "exports": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": { @@ -61,14 +61,14 @@ }, "devDependencies": { "@eslint/js": "^9.4.0", - "@types/node": "^20.14.1", + "@types/node": "^20.14.2", "@types/semver": "^7.5.8", "c8": "^9.1.0", "dprint": "^0.46.1", "eslint": "^9.4.0", "eslint-plugin-functional": "^6.5.1", "eslint-plugin-import": "^2.29.1", - "eslint-plugin-n": "^17.7.0", + "eslint-plugin-n": "^17.8.1", "eslint-plugin-unicorn": "^53.0.0", "husky": "^9.0.11", "istanbul-badges-readme": "^1.9.0", @@ -77,7 +77,7 @@ "semver": "^7.6.2", "ts-node": "^10.9.2", "tsup": "^8.1.0", - "tsx": "^4.11.2", + "tsx": "^4.13.2", "typescript": "^5.4.5", "typescript-eslint": "^7.12.0" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c9ffa3f..c2cb02d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,8 +25,8 @@ importers: specifier: ^9.4.0 version: 9.4.0 '@types/node': - specifier: ^20.14.1 - version: 20.14.1 + specifier: ^20.14.2 + version: 20.14.2 '@types/semver': specifier: ^7.5.8 version: 7.5.8 @@ -46,8 +46,8 @@ importers: specifier: ^2.29.1 version: 2.29.1(@typescript-eslint/parser@7.12.0(eslint@9.4.0)(typescript@5.4.5))(eslint@9.4.0) eslint-plugin-n: - specifier: ^17.7.0 - version: 17.7.0(eslint@9.4.0) + specifier: ^17.8.1 + version: 17.8.1(eslint@9.4.0) eslint-plugin-unicorn: specifier: ^53.0.0 version: 53.0.0(eslint@9.4.0) @@ -68,13 +68,13 @@ importers: version: 7.6.2 ts-node: specifier: ^10.9.2 - version: 10.9.2(@types/node@20.14.1)(typescript@5.4.5) + version: 10.9.2(@types/node@20.14.2)(typescript@5.4.5) tsup: specifier: ^8.1.0 - version: 8.1.0(ts-node@10.9.2(@types/node@20.14.1)(typescript@5.4.5))(typescript@5.4.5) + version: 8.1.0(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.4.5))(typescript@5.4.5) tsx: - specifier: ^4.11.2 - version: 4.11.2 + specifier: ^4.13.2 + version: 4.13.2 typescript: specifier: ^5.4.5 version: 5.4.5 @@ -84,16 +84,16 @@ importers: packages: - '@babel/code-frame@7.24.6': - resolution: {integrity: sha512-ZJhac6FkEd1yhG2AHOmfcXG4ceoLltoCVJjN5XsWN9BifBQr+cHJbWi0h68HZuSORq+3WtJ2z0hwF2NG1b5kcA==} + '@babel/code-frame@7.24.7': + resolution: {integrity: sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==} engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.24.6': - resolution: {integrity: sha512-4yA7s865JHaqUdRbnaxarZREuPTHrjpDT+pXoAZ1yhyo6uFnIEpS8VMu16siFOHDpZNKYv5BObhsB//ycbICyw==} + '@babel/helper-validator-identifier@7.24.7': + resolution: {integrity: sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==} engines: {node: '>=6.9.0'} - '@babel/highlight@7.24.6': - resolution: {integrity: sha512-2YnuOp4HAk2BsBrJJvYCbItHx0zWscI1C3zgWkz+wDyD9I7GIVrfnLyrR4Y1VR+7p+chAEcrgRQYZAGIKMV7vQ==} + '@babel/highlight@7.24.7': + resolution: {integrity: sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==} engines: {node: '>=6.9.0'} '@bcoe/v8-coverage@0.2.3': @@ -609,8 +609,8 @@ packages: '@types/json5@0.0.29': resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==} - '@types/node@20.14.1': - resolution: {integrity: sha512-T2MzSGEu+ysB/FkWfqmhV3PLyQlowdptmmgD20C6QxsS8Fmv5SjpZ1ayXaEC0S21/h5UJ9iA6W/5vSNU5l00OA==} + '@types/node@20.14.2': + resolution: {integrity: sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==} '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} @@ -729,8 +729,8 @@ packages: ajv@6.12.6: resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==} - ajv@8.15.0: - resolution: {integrity: sha512-15BTtQUOsSrmHCy+B4VnAiJAJxJ8IFgu6fcjFQF3jQYZ78nLSQthlFg4ehp+NLIyfvFgOlxNsjKIEhydtFPVHQ==} + ajv@8.16.0: + resolution: {integrity: sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==} ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} @@ -883,8 +883,8 @@ packages: resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} engines: {node: '>=10'} - caniuse-lite@1.0.30001627: - resolution: {integrity: sha512-4zgNiB8nTyV/tHhwZrFs88ryjls/lHiqFhrxCW4qSTeuRByBVnPYpDInchOIySWknznucaf31Z4KYqjfbrecVw==} + caniuse-lite@1.0.30001629: + resolution: {integrity: sha512-c3dl911slnQhmxUIT4HhYzT7wnBK/XYpGnYLOj4nJBaRiw52Ibe7YxlDaAeRECvA786zCuExhxIUJ2K7nHMrBw==} chalk@2.4.2: resolution: {integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==} @@ -1013,8 +1013,8 @@ packages: eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} - electron-to-chromium@1.4.788: - resolution: {integrity: sha512-ubp5+Ev/VV8KuRoWnfP2QF2Bg+O2ZFdb49DiiNbz2VmgkIqrnyYaqIOqj8A6K/3p1xV0QcU5hBQ1+BmB6ot1OA==} + electron-to-chromium@1.4.794: + resolution: {integrity: sha512-6FApLtsYhDCY0Vglq3AptsdxQ+PJLc6AxlAM0HjEihUAiOPPbkASEsq9gtxUeZY9o0sJIEa3WnF0vVH4VT4iug==} emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -1022,8 +1022,8 @@ packages: emoji-regex@9.2.2: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} - enhanced-resolve@5.16.1: - resolution: {integrity: sha512-4U5pNsuDl0EhuZpq46M5xPslstkviJuhrdobaRDBk2Jy2KO37FDAJl4lb2KlNabxT0m4MTK2UHNrsAcphE8nyw==} + enhanced-resolve@5.17.0: + resolution: {integrity: sha512-dwDPwZL0dmye8Txp2gzFmA6sxALaSvdRDjPH0viLcKrtlOL3tw62nWWweVD1SdILDTJrbrL6tdWVN58Wo6U3eA==} engines: {node: '>=10.13.0'} error-ex@1.3.2: @@ -1108,8 +1108,8 @@ packages: eslint-import-resolver-webpack: optional: true - eslint-plugin-es-x@7.6.0: - resolution: {integrity: sha512-I0AmeNgevgaTR7y2lrVCJmGYF0rjoznpDvqV/kIkZSZbZ8Rw3eu4cGlvBBULScfkSOCzqKbff5LR4CNrV7mZHA==} + eslint-plugin-es-x@7.7.0: + resolution: {integrity: sha512-aP3qj8BwiEDPttxQkZdI221DLKq9sI/qHolE2YSQL1/9+xk7dTV+tB1Fz8/IaCA+lnLA1bDEnvaS2LKs0k2Uig==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: eslint: '>=8' @@ -1134,8 +1134,8 @@ packages: '@typescript-eslint/parser': optional: true - eslint-plugin-n@17.7.0: - resolution: {integrity: sha512-4Jg4ZKVE4VjHig2caBqPHYNW5na84RVufUuipFLJbgM/G57O6FdpUKJbHakCDJb/yjQuyqVzYWRtU3HNYaZUwg==} + eslint-plugin-n@17.8.1: + resolution: {integrity: sha512-KdG0h0voZms8UhndNu8DeWx1eM4sY+A4iXtsNo6kOfJLYHNeTGPacGalJ9GcvrbmOL3r/7QOMwVZDSw+1SqsrA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: eslint: '>=8.23.0' @@ -1227,8 +1227,8 @@ packages: resolution: {integrity: sha512-dwsoQlS7h9hMeYUq1W++23NDcBLV4KqONnITDV9DjfS3q1SgDGVrBdvvTLUotWtPSD7asWDV9/CmsZPy8Hf70A==} engines: {node: '>=6'} - fast-uri@2.3.0: - resolution: {integrity: sha512-eel5UKGn369gGEWOqBShmFJWfq/xSJvsgDzgLYC845GneayWvXBf0lJCBn5qTABfewy1ZDPoaR5OZCP+kssfuw==} + fast-uri@2.3.1: + resolution: {integrity: sha512-iC7SLdMJx2KGdBkhJ6UulbNfpeIGTMS3/OIJpPa1JkZu9DKVQmPtBBme9Esoa4XP2eLGaHBv4vzRqlolXKo9cg==} fastify-plugin@4.5.1: resolution: {integrity: sha512-stRHYGeuqpEZTL1Ef0Ovr2ltazUT9g844X5z/zEBFLG8RYlpDiOCIG+ATvYEp+/zmc7sN29mcIMp8gvYplYPIQ==} @@ -1348,8 +1348,8 @@ packages: resolution: {integrity: sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==} engines: {node: '>=18'} - globals@15.3.0: - resolution: {integrity: sha512-cCdyVjIUVTtX8ZsPkq1oCsOsLmGIswqnjZYMJJTGaNApj1yHtLSymKhwH51ttirREn75z3p4k051clwg7rvNKA==} + globals@15.4.0: + resolution: {integrity: sha512-unnwvMZpv0eDUyjNyh9DH/yxUaRYrEjW/qK4QcdrHg3oO11igUQrCSgODHEqxlKg8v2CD2Sd7UkqqEBoz5U7TQ==} engines: {node: '>=18'} globalthis@1.0.4: @@ -1576,8 +1576,8 @@ packages: resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==} engines: {node: '>=8'} - jackspeak@3.2.3: - resolution: {integrity: sha512-htOzIMPbpLid/Gq9/zaz9SfExABxqRe1sSCdxntlO/aMD6u0issZQiY25n2GKQUtJ02j7z5sfptlAOMpWWOmvw==} + jackspeak@3.4.0: + resolution: {integrity: sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==} engines: {node: '>=14'} joycon@3.1.1: @@ -2309,8 +2309,8 @@ packages: tsconfig-paths@3.15.0: resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==} - tslib@2.6.2: - resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + tslib@2.6.3: + resolution: {integrity: sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==} tsup@8.1.0: resolution: {integrity: sha512-UFdfCAXukax+U6KzeTNO2kAARHcWxmKsnvSPXUcfA1D+kU05XDccCrkffCQpFaWDsZfV0jMyTsxU39VfCp6EOg==} @@ -2331,8 +2331,8 @@ packages: typescript: optional: true - tsx@4.11.2: - resolution: {integrity: sha512-V5DL5v1BuItjsQ2FN9+4OjR7n5cr8hSgN+VGmm/fd2/0cgQdBIWHcQ3bFYm/5ZTmyxkTDBUIaRuW2divgfPe0A==} + tsx@4.13.2: + resolution: {integrity: sha512-s+WGqChkA77uU8xij1IdO9jQnwJAiWJto0bF5yJLbAZpLtNs82Qa5CwMBxWjJ7QOYU9MzBf4MCNt6lZduwkQ+g==} engines: {node: '>=18.0.0'} hasBin: true @@ -2480,16 +2480,16 @@ packages: snapshots: - '@babel/code-frame@7.24.6': + '@babel/code-frame@7.24.7': dependencies: - '@babel/highlight': 7.24.6 + '@babel/highlight': 7.24.7 picocolors: 1.0.1 - '@babel/helper-validator-identifier@7.24.6': {} + '@babel/helper-validator-identifier@7.24.7': {} - '@babel/highlight@7.24.6': + '@babel/highlight@7.24.7': dependencies: - '@babel/helper-validator-identifier': 7.24.6 + '@babel/helper-validator-identifier': 7.24.7 chalk: 2.4.2 js-tokens: 4.0.0 picocolors: 1.0.1 @@ -2694,9 +2694,9 @@ snapshots: '@fastify/ajv-compiler@3.5.0': dependencies: - ajv: 8.15.0 - ajv-formats: 2.1.1(ajv@8.15.0) - fast-uri: 2.3.0 + ajv: 8.16.0 + ajv-formats: 2.1.1(ajv@8.16.0) + fast-uri: 2.3.1 '@fastify/error@3.4.1': {} @@ -2826,7 +2826,7 @@ snapshots: '@types/json5@0.0.29': {} - '@types/node@20.14.1': + '@types/node@20.14.2': dependencies: undici-types: 5.26.5 @@ -2842,7 +2842,7 @@ snapshots: '@types/whatwg-url@8.2.2': dependencies: - '@types/node': 20.14.1 + '@types/node': 20.14.2 '@types/webidl-conversions': 7.0.3 '@typescript-eslint/eslint-plugin@7.12.0(@typescript-eslint/parser@7.12.0(eslint@9.4.0)(typescript@5.4.5))(eslint@9.4.0)(typescript@5.4.5)': @@ -2946,13 +2946,13 @@ snapshots: transitivePeerDependencies: - supports-color - ajv-formats@2.1.1(ajv@8.15.0): + ajv-formats@2.1.1(ajv@8.16.0): optionalDependencies: - ajv: 8.15.0 + ajv: 8.16.0 - ajv-formats@3.0.1(ajv@8.15.0): + ajv-formats@3.0.1(ajv@8.16.0): optionalDependencies: - ajv: 8.15.0 + ajv: 8.16.0 ajv@6.12.6: dependencies: @@ -2961,12 +2961,12 @@ snapshots: json-schema-traverse: 0.4.1 uri-js: 4.4.1 - ajv@8.15.0: + ajv@8.16.0: dependencies: fast-deep-equal: 3.1.3 - fast-uri: 2.3.0 json-schema-traverse: 1.0.0 require-from-string: 2.0.2 + uri-js: 4.4.1 ansi-regex@5.0.1: {} @@ -3045,7 +3045,7 @@ snapshots: async-mutex@0.4.1: dependencies: - tslib: 2.6.2 + tslib: 2.6.3 atomic-sleep@1.0.0: {} @@ -3084,8 +3084,8 @@ snapshots: browserslist@4.23.0: dependencies: - caniuse-lite: 1.0.30001627 - electron-to-chromium: 1.4.788 + caniuse-lite: 1.0.30001629 + electron-to-chromium: 1.4.794 node-releases: 2.0.14 update-browserslist-db: 1.0.16(browserslist@4.23.0) @@ -3135,7 +3135,7 @@ snapshots: camelcase@6.3.0: {} - caniuse-lite@1.0.30001627: {} + caniuse-lite@1.0.30001629: {} chalk@2.4.2: dependencies: @@ -3270,13 +3270,13 @@ snapshots: eastasianwidth@0.2.0: {} - electron-to-chromium@1.4.788: {} + electron-to-chromium@1.4.794: {} emoji-regex@8.0.0: {} emoji-regex@9.2.2: {} - enhanced-resolve@5.16.1: + enhanced-resolve@5.17.0: dependencies: graceful-fs: 4.2.11 tapable: 2.2.1 @@ -3441,7 +3441,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-plugin-es-x@7.6.0(eslint@9.4.0): + eslint-plugin-es-x@7.7.0(eslint@9.4.0): dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@9.4.0) '@eslint-community/regexpp': 4.10.1 @@ -3489,21 +3489,21 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-plugin-n@17.7.0(eslint@9.4.0): + eslint-plugin-n@17.8.1(eslint@9.4.0): dependencies: '@eslint-community/eslint-utils': 4.4.0(eslint@9.4.0) - enhanced-resolve: 5.16.1 + enhanced-resolve: 5.17.0 eslint: 9.4.0 - eslint-plugin-es-x: 7.6.0(eslint@9.4.0) + eslint-plugin-es-x: 7.7.0(eslint@9.4.0) get-tsconfig: 4.7.5 - globals: 15.3.0 + globals: 15.4.0 ignore: 5.3.1 minimatch: 9.0.4 semver: 7.6.2 eslint-plugin-unicorn@53.0.0(eslint@9.4.0): dependencies: - '@babel/helper-validator-identifier': 7.24.6 + '@babel/helper-validator-identifier': 7.24.7 '@eslint-community/eslint-utils': 4.4.0(eslint@9.4.0) '@eslint/eslintrc': 3.1.0 ci-info: 4.0.0 @@ -3626,10 +3626,10 @@ snapshots: fast-json-stringify@5.16.0: dependencies: '@fastify/merge-json-schemas': 0.1.1 - ajv: 8.15.0 - ajv-formats: 3.0.1(ajv@8.15.0) + ajv: 8.16.0 + ajv-formats: 3.0.1(ajv@8.16.0) fast-deep-equal: 3.1.3 - fast-uri: 2.3.0 + fast-uri: 2.3.1 json-schema-ref-resolver: 1.0.1 rfdc: 1.3.1 @@ -3641,7 +3641,7 @@ snapshots: fast-redact@3.5.0: {} - fast-uri@2.3.0: {} + fast-uri@2.3.1: {} fastify-plugin@4.5.1: {} @@ -3769,7 +3769,7 @@ snapshots: glob@10.4.1: dependencies: foreground-child: 3.1.1 - jackspeak: 3.2.3 + jackspeak: 3.4.0 minimatch: 9.0.4 minipass: 7.1.2 path-scurry: 1.11.1 @@ -3785,7 +3785,7 @@ snapshots: globals@14.0.0: {} - globals@15.3.0: {} + globals@15.4.0: {} globalthis@1.0.4: dependencies: @@ -3991,7 +3991,7 @@ snapshots: html-escaper: 2.0.2 istanbul-lib-report: 3.0.1 - jackspeak@3.2.3: + jackspeak@3.4.0: dependencies: '@isaacs/cliui': 8.0.2 optionalDependencies: @@ -4123,7 +4123,7 @@ snapshots: new-find-package-json: 2.0.0 semver: 7.6.2 tar-stream: 3.1.7 - tslib: 2.6.2 + tslib: 2.6.3 yauzl: 3.1.3 transitivePeerDependencies: - '@aws-sdk/credential-providers' @@ -4136,7 +4136,7 @@ snapshots: mongodb-memory-server@9.3.0: dependencies: mongodb-memory-server-core: 9.3.0 - tslib: 2.6.2 + tslib: 2.6.3 transitivePeerDependencies: - '@aws-sdk/credential-providers' - '@mongodb-js/zstd' @@ -4273,7 +4273,7 @@ snapshots: parse-json@5.2.0: dependencies: - '@babel/code-frame': 7.24.6 + '@babel/code-frame': 7.24.7 error-ex: 1.3.2 json-parse-even-better-errors: 2.3.1 lines-and-columns: 1.2.4 @@ -4330,12 +4330,12 @@ snapshots: possible-typed-array-names@1.0.0: {} - postcss-load-config@4.0.2(ts-node@10.9.2(@types/node@20.14.1)(typescript@5.4.5)): + postcss-load-config@4.0.2(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.4.5)): dependencies: lilconfig: 3.1.1 yaml: 2.4.3 optionalDependencies: - ts-node: 10.9.2(@types/node@20.14.1)(typescript@5.4.5) + ts-node: 10.9.2(@types/node@20.14.2)(typescript@5.4.5) prelude-ls@1.2.1: {} @@ -4695,14 +4695,14 @@ snapshots: ts-interface-checker@0.1.13: {} - ts-node@10.9.2(@types/node@20.14.1)(typescript@5.4.5): + ts-node@10.9.2(@types/node@20.14.2)(typescript@5.4.5): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.11 '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 20.14.1 + '@types/node': 20.14.2 acorn: 8.11.3 acorn-walk: 8.3.2 arg: 4.1.3 @@ -4720,9 +4720,9 @@ snapshots: minimist: 1.2.8 strip-bom: 3.0.0 - tslib@2.6.2: {} + tslib@2.6.3: {} - tsup@8.1.0(ts-node@10.9.2(@types/node@20.14.1)(typescript@5.4.5))(typescript@5.4.5): + tsup@8.1.0(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.4.5))(typescript@5.4.5): dependencies: bundle-require: 4.2.1(esbuild@0.21.4) cac: 6.7.14 @@ -4732,7 +4732,7 @@ snapshots: execa: 5.1.1 globby: 11.1.0 joycon: 3.1.1 - postcss-load-config: 4.0.2(ts-node@10.9.2(@types/node@20.14.1)(typescript@5.4.5)) + postcss-load-config: 4.0.2(ts-node@10.9.2(@types/node@20.14.2)(typescript@5.4.5)) resolve-from: 5.0.0 rollup: 4.18.0 source-map: 0.8.0-beta.0 @@ -4744,7 +4744,7 @@ snapshots: - supports-color - ts-node - tsx@4.11.2: + tsx@4.13.2: dependencies: esbuild: 0.20.2 get-tsconfig: 4.7.5 diff --git a/src/types.ts b/src/types.ts index 1ea0235..c9b5552 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,10 +2,9 @@ import type { Db, IndexDescription } from 'mongodb' import type { BaseSchema, Model, SchemaOptions } from 'papr' // eslint-disable-next-line @typescript-eslint/no-explicit-any -export type FastifyPapr> = any> = Record< - string, - Model | Record> -> +export interface FastifyPapr> = any> { + [key: string]: Model | Record> | undefined +} export type ModelRegistration = { name: string diff --git a/tests/helpers/model.ts b/tests/helpers/model.ts new file mode 100644 index 0000000..89f0bef --- /dev/null +++ b/tests/helpers/model.ts @@ -0,0 +1,35 @@ +import type { Model } from 'papr' +import { schema, types } from 'papr' + +export const userSchema = schema({ + name: types.string({ required: true, maxLength: 20 }), + phone: types.string({ required: true, minimum: 14 }), + age: types.number({ required: true, minimum: 18, maximum: 200 }), +}) + +export const orderSchema = schema({ + orderNumber: types.number({ required: true }), + description: types.string({ minLength: 5, required: true }), + date: types.date({ required: true }), +}) + +export const orderSchemaWithDefaults = schema({ + orderNumber: types.number({ required: true }), + description: types.string({ minLength: 5, required: true }), + date: types.date({ required: true }), +}, { + defaults: { + orderNumber: 1, + }, +}) + +// We use partial values here just for the tests. Dont use ? on Production +declare module '../../src/index.js' { + interface FastifyPapr { + user?: Model + order?: Model + orderDefaults?: Model + db1?: { user: Model } + db2?: { order: Model } + } +} diff --git a/tests/index.test.ts b/tests/index.test.ts index 5c9319f..1790122 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,23 +1,10 @@ import { equal, rejects } from 'node:assert' import { afterEach, beforeEach, describe, it } from 'node:test' -import type { Model } from 'papr' -import { schema, types } from 'papr' import fastifyPaprPlugin, { asCollection } from '../src/index.js' +import { userSchema } from './helpers/model.js' import type { MongoContext } from './helpers/server.js' import { getConfiguredTestServer, setupMongoContext, tearDownMongoContext } from './helpers/server.js' -export const userSchema = schema({ - name: types.string({ required: true, maxLength: 20 }), - phone: types.string({ required: true, minimum: 14 }), - age: types.number({ required: true, minimum: 18, maximum: 200 }), -}) - -declare module 'fastify' { - interface FastifyPapr { - user: Model - } -} - await describe('Index', async () => { let mut_mongoContext: MongoContext @@ -42,7 +29,7 @@ await describe('Index', async () => { }, }) - const { user } = fastify.papr + const user = fastify.papr.user! await user.insertOne({ name: 'Elizeu Drummond', age: 35, phone: '552124561234' }) await user.insertOne({ name: 'Luiz Pareto', age: 70, phone: '552124561234' }) @@ -53,7 +40,7 @@ await describe('Index', async () => { const e = await r.explain() equal(e.ok, 1) - equal((await fastify.papr.user.find({})).length, 3) + equal((await user.find({})).length, 3) }) await it('Missing index should fail', async () => { @@ -68,9 +55,11 @@ await describe('Index', async () => { }, }) - await fastify.papr.user.insertOne({ name: 'Elizeu Drummond', age: 35, phone: '552124561234' }) - await fastify.papr.user.insertOne({ name: 'Luiz Pareto', age: 70, phone: '552124561234' }) - await fastify.papr.user.insertOne({ name: 'José Augusto', age: 25, phone: '552124561234' }) + const user = fastify.papr.user! + + await user.insertOne({ name: 'Elizeu Drummond', age: 35, phone: '552124561234' }) + await user.insertOne({ name: 'Luiz Pareto', age: 70, phone: '552124561234' }) + await user.insertOne({ name: 'José Augusto', age: 25, phone: '552124561234' }) const r = db.collection('user').find().hint({ name: -1 }) diff --git a/tests/multiple.col.test.ts b/tests/multiple.col.test.ts index 2e2f69c..fe35e50 100644 --- a/tests/multiple.col.test.ts +++ b/tests/multiple.col.test.ts @@ -1,42 +1,11 @@ import { MongoServerError } from 'mongodb' import { deepEqual, rejects } from 'node:assert' import { afterEach, beforeEach, describe, it } from 'node:test' -import type { Model } from 'papr' -import { schema, types } from 'papr' import fastifyPaprPlugin, { asCollection } from '../src/index.js' +import { orderSchema, orderSchemaWithDefaults, userSchema } from './helpers/model.js' import type { MongoContext } from './helpers/server.js' import { getConfiguredTestServer, setupMongoContext, tearDownMongoContext } from './helpers/server.js' -const userSchema = schema({ - name: types.string({ required: true, maxLength: 20 }), - phone: types.string({ required: true, minimum: 14 }), - age: types.number({ required: true, minimum: 18, maximum: 200 }), -}) - -const orderSchema = schema({ - orderNumber: types.number({ required: true }), - description: types.string({ minLength: 5, required: true }), - date: types.date({ required: true }), -}) - -const orderSchemaWithDefaults = schema({ - orderNumber: types.number({ required: true }), - description: types.string({ minLength: 5, required: true }), - date: types.date({ required: true }), -}, { - defaults: { - orderNumber: 1, - }, -}) - -declare module 'fastify' { - interface FastifyPapr { - user: Model - order: Model - orderDefaults: Model - } -} - await describe('multiple collections', async () => { let mut_mongoContext: MongoContext @@ -60,14 +29,14 @@ await describe('multiple collections', async () => { }) const user = { name: 'Elizeu Drummond', age: 30, phone: '552124561234' } - const result = await fastify.papr.user.insertOne(user) + const result = await fastify.papr.user!.insertOne(user) - deepEqual(await fastify.papr.user.findById(result._id), { _id: result._id, ...user }) + deepEqual(await fastify.papr.user!.findById(result._id), { _id: result._id, ...user }) const order = { orderNumber: 1234, description: 'notebook', date: new Date() } - const orderResult = await fastify.papr.order.insertOne(order) + const orderResult = await fastify.papr.order!.insertOne(order) - deepEqual(await fastify.papr.order.findById(orderResult._id), { _id: orderResult._id, ...order }) + deepEqual(await fastify.papr.order!.findById(orderResult._id), { _id: orderResult._id, ...order }) }) await it('validation failed with two col', async () => { @@ -83,10 +52,10 @@ await describe('multiple collections', async () => { const user = { name: 'Elizeu Drummond', age: 400, phone: '552124561234' } - await rejects(async () => await fastify.papr.user.insertOne(user), MongoServerError) + await rejects(async () => await fastify.papr.user!.insertOne(user), MongoServerError) const order = { orderNumber: 1234, description: 'n', date: new Date() } - await rejects(async () => await fastify.papr.order.insertOne(order), MongoServerError) + await rejects(async () => await fastify.papr.order!.insertOne(order), MongoServerError) }) await it('one collection with default values, insert and retrieve', async () => { @@ -100,9 +69,9 @@ await describe('multiple collections', async () => { }) const order = { description: 'notebook', date: new Date() } - const orderResult = await fastify.papr.orderDefaults.insertOne(order) + const orderResult = await fastify.papr.orderDefaults!.insertOne(order) - deepEqual(await fastify.papr.orderDefaults.findById(orderResult._id), { + deepEqual(await fastify.papr.orderDefaults!.findById(orderResult._id), { _id: orderResult._id, ...order, orderNumber: 1, diff --git a/tests/multiple.db.test.ts b/tests/multiple.db.test.ts index 85f69b1..206d7cf 100644 --- a/tests/multiple.db.test.ts +++ b/tests/multiple.db.test.ts @@ -1,30 +1,10 @@ import { deepEqual } from 'node:assert' import { afterEach, beforeEach, describe, it } from 'node:test' -import type { Model } from 'papr' -import { schema, types } from 'papr' import fastifyPaprPlugin, { asCollection } from '../src/index.js' +import { orderSchema, userSchema } from './helpers/model.js' import type { MongoContext } from './helpers/server.js' import { getConfiguredTestServer, setupMongoContext, tearDownMongoContext } from './helpers/server.js' -const userSchema = schema({ - name: types.string({ required: true, maxLength: 20 }), - phone: types.string({ required: true, minimum: 14 }), - age: types.number({ required: true, minimum: 18, maximum: 200 }), -}) - -const orderSchema = schema({ - orderNumber: types.number({ required: true }), - description: types.string({ required: true }), - date: types.date({ required: true }), -}) - -declare module 'fastify' { - interface FastifyPapr { - db1: { user: Model } - db2: { order: Model } - } -} - await describe('multiple databases', async () => { let mut_mongoContext1: MongoContext let mut_mongoContext2: MongoContext @@ -59,13 +39,13 @@ await describe('multiple databases', async () => { }) const user = { name: 'Elizeu Drummond', age: 40, phone: '552124561234' } - const result = await fastify.papr.db1.user.insertOne(user) + const result = await fastify.papr.db1!.user.insertOne(user) - deepEqual(await fastify.papr.db1.user.findById(result._id), { _id: result._id, ...user }) + deepEqual(await fastify.papr.db1!.user.findById(result._id), { _id: result._id, ...user }) const order = { orderNumber: 1234, description: 'notebook', date: new Date() } - const orderResult = await fastify.papr.db2.order.insertOne(order) + const orderResult = await fastify.papr.db2!.order.insertOne(order) - deepEqual(await fastify.papr.db2.order.findById(orderResult._id), { _id: orderResult._id, ...order }) + deepEqual(await fastify.papr.db2!.order.findById(orderResult._id), { _id: orderResult._id, ...order }) }) }) diff --git a/tests/register.test.ts b/tests/register.test.ts index 3d33c22..e477d89 100644 --- a/tests/register.test.ts +++ b/tests/register.test.ts @@ -1,16 +1,11 @@ import { rejects } from 'node:assert' import { afterEach, beforeEach, describe, it } from 'node:test' -import { schema, types } from 'papr' import type { FastifyPaprOptions } from '../src/index.js' import fastifyPaprPlugin, { asCollection } from '../src/index.js' +import { userSchema } from './helpers/model.js' import type { MongoContext } from './helpers/server.js' import { getConfiguredTestServer, setupMongoContext, tearDownMongoContext } from './helpers/server.js' -export const userSchema = schema({ - name: types.string({ required: true, maxLength: 20 }), - email: types.string({ required: true, minimum: 200 }), -}) - await describe('simple tests', async () => { let mut_mongoContext: MongoContext diff --git a/tests/simple.test.ts b/tests/simple.test.ts index a52a495..94f17d1 100644 --- a/tests/simple.test.ts +++ b/tests/simple.test.ts @@ -1,23 +1,10 @@ import { deepEqual, rejects } from 'node:assert' import { afterEach, beforeEach, describe, it } from 'node:test' -import type { Model } from 'papr' -import { schema, types } from 'papr' import fastifyPaprPlugin, { asCollection } from '../src/index.js' +import { userSchema } from './helpers/model.js' import type { MongoContext } from './helpers/server.js' import { getConfiguredTestServer, setupMongoContext, tearDownMongoContext } from './helpers/server.js' -export const userSchema = schema({ - name: types.string({ required: true, maxLength: 20 }), - phone: types.string({ required: true, minimum: 14 }), - age: types.number({ required: true, minimum: 18, maximum: 200 }), -}) - -declare module 'fastify' { - interface FastifyPapr { - user: Model - } -} - await describe('simple tests', async () => { let mut_mongoContext: MongoContext @@ -40,8 +27,8 @@ await describe('simple tests', async () => { }) const user = { name: 'Elizeu Drummond', age: 40, phone: '552124561234' } - const result = await fastify.papr.user.insertOne(user) - const findResult = await fastify.papr.user.findById(result._id) + const result = await fastify.papr.user!.insertOne(user) + const findResult = await fastify.papr.user!.findById(result._id) deepEqual(findResult, { _id: result._id, ...user }) }) @@ -57,7 +44,7 @@ await describe('simple tests', async () => { const sample = { name: 'Elizeu Drummond Giant Name', age: 40, phone: '552124561234' } - await rejects(async () => await fastify.papr.user.insertOne(sample), { + await rejects(async () => await fastify.papr.user!.insertOne(sample), { name: 'MongoServerError', message: 'Document failed validation', }) diff --git a/tests/validation.test.ts b/tests/validation.test.ts index 324be85..1733c88 100644 --- a/tests/validation.test.ts +++ b/tests/validation.test.ts @@ -1,25 +1,12 @@ import { MongoServerError } from 'mongodb' import { deepEqual, equal, ok, rejects } from 'node:assert' import { afterEach, beforeEach, describe, it } from 'node:test' -import type { Model } from 'papr' -import { schema, types } from 'papr' import fastifyPaprPlugin, { asCollection } from '../src/index.js' import { SimpleDocFailedValidationError } from '../src/simple-doc-failed-validation.js' +import { userSchema } from './helpers/model.js' import type { MongoContext } from './helpers/server.js' import { getConfiguredTestServer, setupMongoContext, tearDownMongoContext } from './helpers/server.js' -export const userSchema = schema({ - name: types.string({ uniqueItems: true, required: true, maxLength: 20 }), - phone: types.string({ required: true, minimum: 14 }), - age: types.number({ required: true, minimum: 18, maximum: 200 }), -}) - -declare module 'fastify' { - interface FastifyPapr { - user: Model - } -} - await describe('Validation', async () => { let mut_mongoContext: MongoContext @@ -42,7 +29,7 @@ await describe('Validation', async () => { }) const user = { name: 'Elizeu Drummond Giant Name', age: 1050, phone: '552124561234' } - await rejects(async () => await fastify.papr.user.insertOne(user), (error) => { + await rejects(async () => await fastify.papr.user!.insertOne(user), (error) => { ok(error instanceof MongoServerError) const simpleError = new SimpleDocFailedValidationError(error) equal( @@ -68,10 +55,10 @@ await describe('Validation', async () => { }) const user = { name: 'Elizeu Drummond', age: 40, phone: '552124561234' } - const result = await fastify.papr.user.insertOne(user) + const result = await fastify.papr.user!.insertOne(user) await rejects( - async () => await fastify.papr.user.insertOne({ _id: result._id, ...user }), + async () => await fastify.papr.user!.insertOne({ _id: result._id, ...user }), (error) => { ok(error instanceof MongoServerError) const simpleError = new SimpleDocFailedValidationError(error) @@ -80,7 +67,7 @@ await describe('Validation', async () => { }, ) - deepEqual(await fastify.papr.user.findById(result._id), { _id: result._id, ...user }) + deepEqual(await fastify.papr.user!.findById(result._id), { _id: result._id, ...user }) }) const sample1 = {