From 5c7e2cd59a6500aec332fde16c761fc62c32eb53 Mon Sep 17 00:00:00 2001 From: acaldas Date: Wed, 15 May 2024 13:12:49 +0100 Subject: [PATCH] feat: added support for building with esbuild --- api/.prettierrc | 4 + api/esbuild.config.js | 28 ++ api/logger.config.ts | 2 +- api/package.json | 11 +- api/pnpm-lock.yaml | 384 +++++++++++++++--- api/src/database.ts | 7 +- api/src/generated/nexus.ts | 20 +- api/src/graphql/generated/drive/nexus.ts | 18 +- api/src/graphql/generated/index/nexus.ts | 18 +- api/src/graphql/server/drive/schema.ts | 14 +- api/src/graphql/server/index.ts | 2 + api/src/graphql/server/index/schema.ts | 14 +- api/src/index.ts | 7 +- api/src/logger.ts | 6 +- api/src/modules/document/listenerManager.ts | 116 +++--- api/src/modules/index.ts | 5 +- api/src/modules/real-world-assets/index.ts | 10 + api/src/modules/real-world-assets/listener.ts | 9 +- api/src/modules/system/challenge/model.ts | 2 +- api/src/modules/system/core-unit/resolvers.ts | 4 +- api/src/modules/system/session/helpers.ts | 10 +- api/src/modules/system/session/resolvers.ts | 4 +- api/src/modules/system/user/resolvers.ts | 2 +- api/src/modules/types.ts | 21 + api/tsconfig.json | 15 +- 25 files changed, 539 insertions(+), 194 deletions(-) create mode 100644 api/.prettierrc create mode 100644 api/esbuild.config.js create mode 100644 api/src/modules/types.ts diff --git a/api/.prettierrc b/api/.prettierrc new file mode 100644 index 00000000..496867ee --- /dev/null +++ b/api/.prettierrc @@ -0,0 +1,4 @@ +{ + "tabWidth": 2, + "singleQuote": true +} diff --git a/api/esbuild.config.js b/api/esbuild.config.js new file mode 100644 index 00000000..16650499 --- /dev/null +++ b/api/esbuild.config.js @@ -0,0 +1,28 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import esbuild from 'esbuild'; +import { builtinModules } from 'module'; +import pkg from './package.json' with { type: 'json' }; + +// Configuration options +const config = { + entryPoints: ['src/index.ts'], + bundle: true, + platform: 'node', + format: 'esm', + outdir: 'dist', + sourcemap: true, + target: 'node20', + loader: { + '.node': 'copy', + }, + external: [ + ...builtinModules, // Exclude Node.js built-in modules + // Exclude all node_modules except specific-module + ...Object.keys(pkg.dependencies).filter((dep) => dep !== 'document-drive'), + ...Object.keys(pkg.devDependencies), + ], + logLevel: 'info', +}; + +// Build process +esbuild.build(config).catch(() => process.exit(1)); diff --git a/api/logger.config.ts b/api/logger.config.ts index 2f3d9c4f..23803f76 100644 --- a/api/logger.config.ts +++ b/api/logger.config.ts @@ -1,4 +1,4 @@ -import { LoggerConfig } from './src/types'; +import type { LoggerConfig } from './src/types'; export const defaultLoggerConfig: LoggerConfig = { // Filter by module name diff --git a/api/package.json b/api/package.json index 436fac94..69fe31d6 100644 --- a/api/package.json +++ b/api/package.json @@ -6,13 +6,14 @@ "type": "module", "license": "AGPL-3", "scripts": { + "start": "node dist/index.js", "dev": "vite-node -w src/index.ts", - "start": "NODE_ENV=production vite-node src/index.ts", "debug": "DEBUG=1 npm run dev", "lint": "eslint \"./**/*.{ts,tsx}\" --max-warnings=0", "typecheck": "tsc --noEmit", "test": "vitest run && vitest run --config ./vitest.modules.config.ts", - "watch": "vitest watch" + "watch": "vitest watch", + "build": "node --no-warnings=ExperimentalWarning ./esbuild.config.js" }, "dependencies": { "@apollo/server": "^4.10.3", @@ -52,14 +53,16 @@ }, "devDependencies": { "@types/bcrypt": "^5.0.2", + "@types/body-parser": "^1.19.5", "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/jsonwebtoken": "^9.0.6", "@types/ms": "^0.7.34", - "@types/node": "^18.19.31", + "@types/node": "^20.12.12", "@typescript-eslint/eslint-plugin": "^5.62.0", "@typescript-eslint/parser": "^5.62.0", "@vitest/coverage-istanbul": "^0.29.8", + "esbuild": "^0.21.2", "eslint": "^8.57.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-typescript": "^17.1.0", @@ -67,7 +70,7 @@ "graphql-request": "^5.2.0", "node-fetch": "^3.3.2", "prisma": "5.11.0", - "typescript": "^4.9.5", + "typescript": "^5.4.5", "vitest-mock-extended": "^1.3.1" } } diff --git a/api/pnpm-lock.yaml b/api/pnpm-lock.yaml index 9739964a..4db31aab 100644 --- a/api/pnpm-lock.yaml +++ b/api/pnpm-lock.yaml @@ -97,7 +97,7 @@ dependencies: version: 2.3.2(ethers@5.7.2) vite-node: specifier: ^0.29.8 - version: 0.29.8(@types/node@18.19.31) + version: 0.29.8(@types/node@20.12.12) vitest: specifier: ^0.32.4 version: 0.32.4 @@ -112,6 +112,9 @@ devDependencies: '@types/bcrypt': specifier: ^5.0.2 version: 5.0.2 + '@types/body-parser': + specifier: ^1.19.5 + version: 1.19.5 '@types/cors': specifier: ^2.8.17 version: 2.8.17 @@ -125,17 +128,20 @@ devDependencies: specifier: ^0.7.34 version: 0.7.34 '@types/node': - specifier: ^18.19.31 - version: 18.19.31 + specifier: ^20.12.12 + version: 20.12.12 '@typescript-eslint/eslint-plugin': specifier: ^5.62.0 - version: 5.62.0(@typescript-eslint/parser@5.62.0)(eslint@8.57.0)(typescript@4.9.5) + version: 5.62.0(@typescript-eslint/parser@5.62.0)(eslint@8.57.0)(typescript@5.4.5) '@typescript-eslint/parser': specifier: ^5.62.0 - version: 5.62.0(eslint@8.57.0)(typescript@4.9.5) + version: 5.62.0(eslint@8.57.0)(typescript@5.4.5) '@vitest/coverage-istanbul': specifier: ^0.29.8 version: 0.29.8(vitest@0.32.4) + esbuild: + specifier: ^0.21.2 + version: 0.21.2 eslint: specifier: ^8.57.0 version: 8.57.0 @@ -158,11 +164,11 @@ devDependencies: specifier: 5.11.0 version: 5.11.0 typescript: - specifier: ^4.9.5 - version: 4.9.5 + specifier: ^5.4.5 + version: 5.4.5 vitest-mock-extended: specifier: ^1.3.1 - version: 1.3.1(typescript@4.9.5)(vitest@0.32.4) + version: 1.3.1(typescript@5.4.5)(vitest@0.32.4) packages: @@ -933,6 +939,15 @@ packages: '@babel/helper-validator-identifier': 7.22.20 to-fast-properties: 2.0.0 + /@esbuild/aix-ppc64@0.21.2: + resolution: {integrity: sha512-/c7hocx0pm14bHQlqUVKmxwdT/e5/KkyoY1W8F9lk/8CkE037STDDz8PXUP/LE6faj2HqchvDs9GcShxFhI78Q==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [aix] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-arm64@0.18.20: resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==} engines: {node: '>=12'} @@ -941,6 +956,15 @@ packages: requiresBuild: true optional: true + /@esbuild/android-arm64@0.21.2: + resolution: {integrity: sha512-SGZKngoTWVUriO5bDjI4WDGsNx2VKZoXcds+ita/kVYB+8IkSCKDRDaK+5yu0b5S0eq6B3S7fpiEvpsa2ammlQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-arm@0.18.20: resolution: {integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==} engines: {node: '>=12'} @@ -949,6 +973,15 @@ packages: requiresBuild: true optional: true + /@esbuild/android-arm@0.21.2: + resolution: {integrity: sha512-G1ve3b4FeyJeyCjB4MX1CiWyTaIJwT9wAYE+8+IRA53YoN/reC/Bf2GDRXAzDTnh69Fpl+1uIKg76DiB3U6vwQ==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-x64@0.18.20: resolution: {integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==} engines: {node: '>=12'} @@ -957,6 +990,15 @@ packages: requiresBuild: true optional: true + /@esbuild/android-x64@0.21.2: + resolution: {integrity: sha512-1wzzNoj2QtNkAYwIcWJ66UTRA80+RTQ/kuPMtEuP0X6dp5Ar23Dn566q3aV61h4EYrrgGlOgl/HdcqN/2S/2vg==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/darwin-arm64@0.18.20: resolution: {integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==} engines: {node: '>=12'} @@ -965,6 +1007,15 @@ packages: requiresBuild: true optional: true + /@esbuild/darwin-arm64@0.21.2: + resolution: {integrity: sha512-ZyMkPWc5eTROcLOA10lEqdDSTc6ds6nuh3DeHgKip/XJrYjZDfnkCVSty8svWdy+SC1f77ULtVeIqymTzaB6/Q==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /@esbuild/darwin-x64@0.18.20: resolution: {integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==} engines: {node: '>=12'} @@ -973,6 +1024,15 @@ packages: requiresBuild: true optional: true + /@esbuild/darwin-x64@0.21.2: + resolution: {integrity: sha512-K4ZdVq1zP9v51h/cKVna7im7G0zGTKKB6bP2yJiSmHjjOykbd8DdhrSi8V978sF69rkwrn8zCyL2t6I3ei6j9A==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /@esbuild/freebsd-arm64@0.18.20: resolution: {integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==} engines: {node: '>=12'} @@ -981,6 +1041,15 @@ packages: requiresBuild: true optional: true + /@esbuild/freebsd-arm64@0.21.2: + resolution: {integrity: sha512-4kbOGdpA61CXqadD+Gb/Pw3YXamQGiz9mal/h93rFVSjr5cgMnmJd/gbfPRm+3BMifvnaOfS1gNWaIDxkE2A3A==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/freebsd-x64@0.18.20: resolution: {integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==} engines: {node: '>=12'} @@ -989,6 +1058,15 @@ packages: requiresBuild: true optional: true + /@esbuild/freebsd-x64@0.21.2: + resolution: {integrity: sha512-ShS+R09nuHzDBfPeMUliKZX27Wrmr8UFp93aFf/S8p+++x5BZ+D344CLKXxmY6qzgTL3mILSImPCNJOzD6+RRg==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-arm64@0.18.20: resolution: {integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==} engines: {node: '>=12'} @@ -997,6 +1075,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-arm64@0.21.2: + resolution: {integrity: sha512-Hdu8BL+AmO+eCDvvT6kz/fPQhvuHL8YK4ExKZfANWsNe1kFGOHw7VJvS/FKSLFqheXmB3rTF3xFQIgUWPYsGnA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-arm@0.18.20: resolution: {integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==} engines: {node: '>=12'} @@ -1005,6 +1092,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-arm@0.21.2: + resolution: {integrity: sha512-nnGXjOAv+7cM3LYRx4tJsYdgy8dGDGkAzF06oIDGppWbUkUKN9SmgQA8H0KukpU0Pjrj9XmgbWqMVSX/U7eeTA==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-ia32@0.18.20: resolution: {integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==} engines: {node: '>=12'} @@ -1013,6 +1109,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-ia32@0.21.2: + resolution: {integrity: sha512-m73BOCW2V9lcj7RtEMi+gBfHC6n3+VHpwQXP5offtQMPLDkpVolYn1YGXxOZ9hp4h3UPRKuezL7WkBsw+3EB3Q==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-loong64@0.18.20: resolution: {integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==} engines: {node: '>=12'} @@ -1021,6 +1126,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-loong64@0.21.2: + resolution: {integrity: sha512-84eYHwwWHq3myIY/6ikALMcnwkf6Qo7NIq++xH0x+cJuUNpdwh8mlpUtRY+JiGUc60yu7ElWBbVHGWTABTclGw==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-mips64el@0.18.20: resolution: {integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==} engines: {node: '>=12'} @@ -1029,6 +1143,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-mips64el@0.21.2: + resolution: {integrity: sha512-9siSZngT0/ZKG+AH+/agwKF29LdCxw4ODi/PiE0F52B2rtLozlDP92umf8G2GPoVV611LN4pZ+nSTckebOscUA==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-ppc64@0.18.20: resolution: {integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==} engines: {node: '>=12'} @@ -1037,6 +1160,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-ppc64@0.21.2: + resolution: {integrity: sha512-y0T4aV2CA+ic04ULya1A/8M2RDpDSK2ckgTj6jzHKFJvCq0jQg8afQQIn4EM0G8u2neyOiNHgSF9YKPfuqKOVw==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-riscv64@0.18.20: resolution: {integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==} engines: {node: '>=12'} @@ -1045,6 +1177,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-riscv64@0.21.2: + resolution: {integrity: sha512-x5ssCdXmZC86L2Li1qQPF/VaC4VP20u/Zm8jlAu9IiVOVi79YsSz6cpPDYZl1rfKSHYCJW9XBfFCo66S5gVPSA==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-s390x@0.18.20: resolution: {integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==} engines: {node: '>=12'} @@ -1053,6 +1194,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-s390x@0.21.2: + resolution: {integrity: sha512-NP7fTpGSFWdXyvp8iAFU04uFh9ARoplFVM/m+8lTRpaYG+2ytHPZWyscSsMM6cvObSIK2KoPHXiZD4l99WaxbQ==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-x64@0.18.20: resolution: {integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==} engines: {node: '>=12'} @@ -1061,6 +1211,15 @@ packages: requiresBuild: true optional: true + /@esbuild/linux-x64@0.21.2: + resolution: {integrity: sha512-giZ/uOxWDKda44ZuyfKbykeXznfuVNkTgXOUOPJIjbayJV6FRpQ4zxUy9JMBPLaK9IJcdWtaoeQrYBMh3Rr4vQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/netbsd-x64@0.18.20: resolution: {integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==} engines: {node: '>=12'} @@ -1069,6 +1228,15 @@ packages: requiresBuild: true optional: true + /@esbuild/netbsd-x64@0.21.2: + resolution: {integrity: sha512-IeFMfGFSQfIj1d4XU+6lkbFzMR+mFELUUVYrZ+jvWzG4NGvs6o53ReEHLHpYkjRbdEjJy2W3lTekTxrFHW7YJg==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/openbsd-x64@0.18.20: resolution: {integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==} engines: {node: '>=12'} @@ -1077,6 +1245,15 @@ packages: requiresBuild: true optional: true + /@esbuild/openbsd-x64@0.21.2: + resolution: {integrity: sha512-48QhWD6WxcebNNaE4FCwgvQVUnAycuTd+BdvA/oZu+/MmbpU8pY2dMEYlYzj5uNHWIG5jvdDmFXu0naQeOWUoA==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/sunos-x64@0.18.20: resolution: {integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==} engines: {node: '>=12'} @@ -1085,6 +1262,15 @@ packages: requiresBuild: true optional: true + /@esbuild/sunos-x64@0.21.2: + resolution: {integrity: sha512-90r3nTBLgdIgD4FCVV9+cR6Hq2Dzs319icVsln+NTmTVwffWcCqXGml8rAoocHuJ85kZK36DCteii96ba/PX8g==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-arm64@0.18.20: resolution: {integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==} engines: {node: '>=12'} @@ -1093,6 +1279,15 @@ packages: requiresBuild: true optional: true + /@esbuild/win32-arm64@0.21.2: + resolution: {integrity: sha512-sNndlsBT8OeE/MZDSGpRDJlWuhjuUz/dn80nH0EP4ZzDUYvMDVa7G87DVpweBrn4xdJYyXS/y4CQNrf7R2ODXg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-ia32@0.18.20: resolution: {integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==} engines: {node: '>=12'} @@ -1101,6 +1296,15 @@ packages: requiresBuild: true optional: true + /@esbuild/win32-ia32@0.21.2: + resolution: {integrity: sha512-Ti2QChGNFzWhUNNVuU4w21YkYTErsNh3h+CzvlEhzgRbwsJ7TrWQqRzW3bllLKKvTppuF3DJ3XP1GEg11AfrEQ==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-x64@0.18.20: resolution: {integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==} engines: {node: '>=12'} @@ -1109,6 +1313,15 @@ packages: requiresBuild: true optional: true + /@esbuild/win32-x64@0.21.2: + resolution: {integrity: sha512-VEfTCZicoZnZ6sGkjFPGRFFJuL2fZn2bLhsekZl1CJslflp2cJS/VoKs1jMk+3pDfsGW6CfQVUckP707HwbXeQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@eslint-community/eslint-utils@4.4.0(eslint@8.57.0): resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1615,7 +1828,7 @@ packages: '@graphql-tools/utils': 8.9.0(graphql@16.8.1) dataloader: 2.1.0 graphql: 16.8.1 - tslib: 2.4.1 + tslib: 2.6.2 value-or-promise: 1.0.11 dev: false @@ -1745,7 +1958,7 @@ packages: graphql: ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 dependencies: graphql: 16.8.1 - tslib: 2.4.1 + tslib: 2.6.2 dev: false /@graphql-tools/utils@9.2.1(graphql@16.8.1): @@ -3545,7 +3758,7 @@ packages: resolution: {integrity: sha512-fB3Zu92ucau0iQ0JMCFQE7b/dv8Ot07NI3KaZIkIUNXq82k4eBAqUaneXfleGY9JWskeS9y+u0nXMyspcuQrCg==} dependencies: '@types/connect': 3.4.38 - '@types/node': 18.19.31 + '@types/node': 20.12.12 /@types/chai-subset@1.3.5: resolution: {integrity: sha512-c2mPnw+xHtXDoHmdtcCXGwyLMiauiAyxWMzhGpqHC4nqI/Y5G2XhTampslK2rb59kpcuHon03UH8W6iYUzw88A==} @@ -3558,7 +3771,7 @@ packages: /@types/connect@3.4.38: resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} dependencies: - '@types/node': 18.19.31 + '@types/node': 20.12.12 /@types/cookie-parser@1.4.7: resolution: {integrity: sha512-Fvuyi354Z+uayxzIGCwYTayFKocfV7TuDYZClCdIP9ckhvAu/ixDtCB6qx2TT0FKjPLf1f3P/J1rgf6lPs64mw==} @@ -3639,6 +3852,11 @@ packages: dependencies: undici-types: 5.26.5 + /@types/node@20.12.12: + resolution: {integrity: sha512-eWLDGF/FOSPtAvEqeRAQ4C8LSA7M1I7i0ky1I8U7kD1J5ITyW3AsRhQrKVoWf5pFKZ2kILsEGJhsI9r93PYnOw==} + dependencies: + undici-types: 5.26.5 + /@types/qs@6.9.15: resolution: {integrity: sha512-uXHQKES6DQKKCLh441Xv/dwxOq1TVS3JPUMlEqoEglvlhR6Mxnlew/Xq/LRVHpLyk7iK3zODe1qYHIMltO7XGg==} @@ -3668,7 +3886,7 @@ packages: dev: false optional: true - /@typescript-eslint/eslint-plugin@5.62.0(@typescript-eslint/parser@5.62.0)(eslint@8.57.0)(typescript@4.9.5): + /@typescript-eslint/eslint-plugin@5.62.0(@typescript-eslint/parser@5.62.0)(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3680,23 +3898,23 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.10.0 - '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@4.9.5) + '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@5.4.5) '@typescript-eslint/scope-manager': 5.62.0 - '@typescript-eslint/type-utils': 5.62.0(eslint@8.57.0)(typescript@4.9.5) - '@typescript-eslint/utils': 5.62.0(eslint@8.57.0)(typescript@4.9.5) + '@typescript-eslint/type-utils': 5.62.0(eslint@8.57.0)(typescript@5.4.5) + '@typescript-eslint/utils': 5.62.0(eslint@8.57.0)(typescript@5.4.5) debug: 4.3.4 eslint: 8.57.0 graphemer: 1.4.0 ignore: 5.3.1 natural-compare-lite: 1.4.0 semver: 7.6.0 - tsutils: 3.21.0(typescript@4.9.5) - typescript: 4.9.5 + tsutils: 3.21.0(typescript@5.4.5) + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser@5.62.0(eslint@8.57.0)(typescript@4.9.5): + /@typescript-eslint/parser@5.62.0(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3708,10 +3926,10 @@ packages: dependencies: '@typescript-eslint/scope-manager': 5.62.0 '@typescript-eslint/types': 5.62.0 - '@typescript-eslint/typescript-estree': 5.62.0(typescript@4.9.5) + '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.4.5) debug: 4.3.4 eslint: 8.57.0 - typescript: 4.9.5 + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true @@ -3724,7 +3942,7 @@ packages: '@typescript-eslint/visitor-keys': 5.62.0 dev: true - /@typescript-eslint/type-utils@5.62.0(eslint@8.57.0)(typescript@4.9.5): + /@typescript-eslint/type-utils@5.62.0(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-xsSQreu+VnfbqQpW5vnCJdq1Z3Q0U31qiWmRhr98ONQmcp/yhiPJFPq8MXiJVLiksmOKSjIldZzkebzHuCGzew==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3734,12 +3952,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 5.62.0(typescript@4.9.5) - '@typescript-eslint/utils': 5.62.0(eslint@8.57.0)(typescript@4.9.5) + '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.4.5) + '@typescript-eslint/utils': 5.62.0(eslint@8.57.0)(typescript@5.4.5) debug: 4.3.4 eslint: 8.57.0 - tsutils: 3.21.0(typescript@4.9.5) - typescript: 4.9.5 + tsutils: 3.21.0(typescript@5.4.5) + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true @@ -3749,7 +3967,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree@5.62.0(typescript@4.9.5): + /@typescript-eslint/typescript-estree@5.62.0(typescript@5.4.5): resolution: {integrity: sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3764,13 +3982,13 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.6.0 - tsutils: 3.21.0(typescript@4.9.5) - typescript: 4.9.5 + tsutils: 3.21.0(typescript@5.4.5) + typescript: 5.4.5 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils@5.62.0(eslint@8.57.0)(typescript@4.9.5): + /@typescript-eslint/utils@5.62.0(eslint@8.57.0)(typescript@5.4.5): resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -3781,7 +3999,7 @@ packages: '@types/semver': 7.5.8 '@typescript-eslint/scope-manager': 5.62.0 '@typescript-eslint/types': 5.62.0 - '@typescript-eslint/typescript-estree': 5.62.0(typescript@4.9.5) + '@typescript-eslint/typescript-estree': 5.62.0(typescript@5.4.5) eslint: 8.57.0 eslint-scope: 5.1.1 semver: 7.6.0 @@ -5144,6 +5362,37 @@ packages: '@esbuild/win32-ia32': 0.18.20 '@esbuild/win32-x64': 0.18.20 + /esbuild@0.21.2: + resolution: {integrity: sha512-LmHPAa5h4tSxz+g/D8IHY6wCjtIiFx8I7/Q0Aq+NmvtoYvyMnJU0KQJcqB6QH30X9x/W4CemgUtPgQDZFca5SA==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/aix-ppc64': 0.21.2 + '@esbuild/android-arm': 0.21.2 + '@esbuild/android-arm64': 0.21.2 + '@esbuild/android-x64': 0.21.2 + '@esbuild/darwin-arm64': 0.21.2 + '@esbuild/darwin-x64': 0.21.2 + '@esbuild/freebsd-arm64': 0.21.2 + '@esbuild/freebsd-x64': 0.21.2 + '@esbuild/linux-arm': 0.21.2 + '@esbuild/linux-arm64': 0.21.2 + '@esbuild/linux-ia32': 0.21.2 + '@esbuild/linux-loong64': 0.21.2 + '@esbuild/linux-mips64el': 0.21.2 + '@esbuild/linux-ppc64': 0.21.2 + '@esbuild/linux-riscv64': 0.21.2 + '@esbuild/linux-s390x': 0.21.2 + '@esbuild/linux-x64': 0.21.2 + '@esbuild/netbsd-x64': 0.21.2 + '@esbuild/openbsd-x64': 0.21.2 + '@esbuild/sunos-x64': 0.21.2 + '@esbuild/win32-arm64': 0.21.2 + '@esbuild/win32-ia32': 0.21.2 + '@esbuild/win32-x64': 0.21.2 + dev: true + /escalade@3.1.2: resolution: {integrity: sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==} engines: {node: '>=6'} @@ -5184,8 +5433,8 @@ packages: eslint: ^7.32.0 || ^8.2.0 eslint-plugin-import: ^2.25.3 dependencies: - '@typescript-eslint/eslint-plugin': 5.62.0(@typescript-eslint/parser@5.62.0)(eslint@8.57.0)(typescript@4.9.5) - '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@4.9.5) + '@typescript-eslint/eslint-plugin': 5.62.0(@typescript-eslint/parser@5.62.0)(eslint@8.57.0)(typescript@5.4.5) + '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@5.4.5) eslint: 8.57.0 eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.29.1)(eslint@8.57.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@5.62.0)(eslint@8.57.0) @@ -5222,7 +5471,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@4.9.5) + '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@5.4.5) debug: 3.2.7 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 @@ -5240,7 +5489,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@4.9.5) + '@typescript-eslint/parser': 5.62.0(eslint@8.57.0)(typescript@5.4.5) array-includes: 3.1.8 array.prototype.findlastindex: 1.2.5 array.prototype.flat: 1.3.2 @@ -8236,9 +8485,6 @@ packages: /sqlite3@5.1.7: resolution: {integrity: sha512-GGIyOiFaG+TUra3JIfkI/zGP8yZYLPQ0pl1bH+ODjiX57sPhrLU5sQJn1y9bDKZUFYkX1crlrPfSYt0BKKdkog==} requiresBuild: true - peerDependenciesMeta: - node-gyp: - optional: true dependencies: bindings: 1.5.0 node-addon-api: 7.1.0 @@ -8510,7 +8756,7 @@ packages: engines: {node: '>=6.10'} dev: false - /ts-essentials@9.4.2(typescript@4.9.5): + /ts-essentials@9.4.2(typescript@5.4.5): resolution: {integrity: sha512-mB/cDhOvD7pg3YCLk2rOtejHjjdSi9in/IBYE13S+8WA5FBSraYf4V/ws55uvs0IvQ/l0wBOlXy5yBNZ9Bl8ZQ==} peerDependencies: typescript: '>=4.1.0' @@ -8518,7 +8764,7 @@ packages: typescript: optional: true dependencies: - typescript: 4.9.5 + typescript: 5.4.5 dev: true /tsconfig-paths@3.15.0: @@ -8546,14 +8792,14 @@ packages: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} dev: false - /tsutils@3.21.0(typescript@4.9.5): + /tsutils@3.21.0(typescript@5.4.5): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' dependencies: tslib: 1.14.1 - typescript: 4.9.5 + typescript: 5.4.5 dev: true /tunnel-agent@0.6.0: @@ -8637,9 +8883,9 @@ packages: possible-typed-array-names: 1.0.0 dev: true - /typescript@4.9.5: - resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} - engines: {node: '>=4.2.0'} + /typescript@5.4.5: + resolution: {integrity: sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==} + engines: {node: '>=14.17'} hasBin: true dev: true @@ -8789,7 +9035,7 @@ packages: engines: {node: '>= 0.8'} dev: false - /vite-node@0.29.8(@types/node@18.19.31): + /vite-node@0.29.8(@types/node@20.12.12): resolution: {integrity: sha512-b6OtCXfk65L6SElVM20q5G546yu10/kNrhg08afEoWlFRJXFq9/6glsvSVY+aI6YeC1tu2TtAqI2jHEQmOmsFw==} engines: {node: '>=v14.16.0'} hasBin: true @@ -8799,7 +9045,7 @@ packages: mlly: 1.6.1 pathe: 1.1.2 picocolors: 1.0.0 - vite: 4.5.3(@types/node@18.19.31) + vite: 4.5.3(@types/node@20.12.12) transitivePeerDependencies: - '@types/node' - less @@ -8867,14 +9113,50 @@ packages: optionalDependencies: fsevents: 2.3.3 - /vitest-mock-extended@1.3.1(typescript@4.9.5)(vitest@0.32.4): + /vite@4.5.3(@types/node@20.12.12): + resolution: {integrity: sha512-kQL23kMeX92v3ph7IauVkXkikdDRsYMGTVl5KY2E9OY4ONLvkHf04MDTbnfo6NKxZiDLWzVpP5oTa8hQD8U3dg==} + engines: {node: ^14.18.0 || >=16.0.0} + hasBin: true + peerDependencies: + '@types/node': '>= 14' + less: '*' + lightningcss: ^1.21.0 + sass: '*' + stylus: '*' + sugarss: '*' + terser: ^5.4.0 + peerDependenciesMeta: + '@types/node': + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + dependencies: + '@types/node': 20.12.12 + esbuild: 0.18.20 + postcss: 8.4.38 + rollup: 3.29.4 + optionalDependencies: + fsevents: 2.3.3 + dev: false + + /vitest-mock-extended@1.3.1(typescript@5.4.5)(vitest@0.32.4): resolution: {integrity: sha512-OpghYjh4BDuQ/Mzs3lFMQ1QRk9D8/2O9T47MLUA5eLn7K4RWIy+MfIivYOWEyxjTENjsBnzgMihDjyNalN/K0Q==} peerDependencies: typescript: 3.x || 4.x || 5.x vitest: '>=0.31.1' dependencies: - ts-essentials: 9.4.2(typescript@4.9.5) - typescript: 4.9.5 + ts-essentials: 9.4.2(typescript@5.4.5) + typescript: 5.4.5 vitest: 0.32.4 dev: true @@ -9025,7 +9307,7 @@ packages: resolution: {integrity: sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==} requiresBuild: true dependencies: - '@types/node': 18.19.31 + '@types/node': 20.12.12 dev: false optional: true diff --git a/api/src/database.ts b/api/src/database.ts index 07fffedd..83672751 100644 --- a/api/src/database.ts +++ b/api/src/database.ts @@ -1,8 +1,11 @@ import { PrismaClient, Prisma } from '@prisma/client'; import { Level as PinoLevel } from 'pino'; import { getChildLogger } from './logger'; -import { getUserCrud, getSessionCrud, getChallengeCrud, getRWACRUD } from './modules'; -import { getDocumentDriveCRUD } from './modules/document'; +import { getUserCrud } from './modules/system/user/model'; +import { getSessionCrud } from './modules/system/session/model'; +import { getChallengeCrud } from './modules/system/challenge/model'; +import { getRWACRUD } from './modules/real-world-assets/model'; +import { getDocumentDriveCRUD } from './modules/document/model'; const dbLogger = getChildLogger({ msgPrefix: 'DATABASE' }); diff --git a/api/src/generated/nexus.ts b/api/src/generated/nexus.ts index c3d065b0..b264c3ff 100644 --- a/api/src/generated/nexus.ts +++ b/api/src/generated/nexus.ts @@ -4,10 +4,10 @@ */ -import type { Context } from "./../graphql/context" -import type { FieldAuthorizeResolver } from "nexus/dist/plugins/fieldAuthorizePlugin" +import type { Context } from "../graphql/server/index"; +import type { FieldAuthorizeResolver } from "nexus/dist/plugins/fieldAuthorizePlugin.js" import type { core, connectionPluginCore } from "nexus" -import type { ArgsValidationConfig, HasTypeField } from "nexus-validation-plugin/utils" +import type { ArgsValidationConfig, HasTypeField } from "nexus-validation-plugin/utils.js" declare global { interface NexusGenCustomInputMethods { /** @@ -36,7 +36,7 @@ declare global { declare global { - interface NexusGen extends NexusGenTypes {} + interface NexusGen extends NexusGenTypes { } } export interface NexusGenInputs { @@ -576,15 +576,15 @@ declare global { * resolver from executing. */ authorize?: FieldAuthorizeResolver - + /** * Async validation function. Reject when validation fails. Resolve otherwise. */ - validate?: - NexusGenArgTypes extends HasTypeField - ? ArgsValidationConfig - : never - + validate?: + NexusGenArgTypes extends HasTypeField + ? ArgsValidationConfig + : never + } interface NexusGenPluginInputFieldConfig { } diff --git a/api/src/graphql/generated/drive/nexus.ts b/api/src/graphql/generated/drive/nexus.ts index ec0528c0..77477fdf 100644 --- a/api/src/graphql/generated/drive/nexus.ts +++ b/api/src/graphql/generated/drive/nexus.ts @@ -5,9 +5,9 @@ import type { Context } from "./../../server/drive/context" -import type { FieldAuthorizeResolver } from "nexus/dist/plugins/fieldAuthorizePlugin" +import type { FieldAuthorizeResolver } from "nexus/dist/plugins/fieldAuthorizePlugin.js" import type { core, connectionPluginCore } from "nexus" -import type { ArgsValidationConfig, HasTypeField } from "nexus-validation-plugin/utils" +import type { ArgsValidationConfig, HasTypeField } from "nexus-validation-plugin/utils.js" declare global { interface NexusGenCustomInputMethods { /** @@ -44,7 +44,7 @@ declare global { declare global { - interface NexusGen extends NexusGenTypes {} + interface NexusGen extends NexusGenTypes { } } export interface NexusGenInputs { @@ -1786,15 +1786,15 @@ declare global { * resolver from executing. */ authorize?: FieldAuthorizeResolver - + /** * Async validation function. Reject when validation fails. Resolve otherwise. */ - validate?: - NexusGenArgTypes extends HasTypeField - ? ArgsValidationConfig - : never - + validate?: + NexusGenArgTypes extends HasTypeField + ? ArgsValidationConfig + : never + } interface NexusGenPluginInputFieldConfig { } diff --git a/api/src/graphql/generated/index/nexus.ts b/api/src/graphql/generated/index/nexus.ts index bf81eeed..146f2ca1 100644 --- a/api/src/graphql/generated/index/nexus.ts +++ b/api/src/graphql/generated/index/nexus.ts @@ -5,9 +5,9 @@ import type { Context } from "./../../server/index/context" -import type { FieldAuthorizeResolver } from "nexus/dist/plugins/fieldAuthorizePlugin" +import type { FieldAuthorizeResolver } from "nexus/dist/plugins/fieldAuthorizePlugin.js" import type { core, connectionPluginCore } from "nexus" -import type { ArgsValidationConfig, HasTypeField } from "nexus-validation-plugin/utils" +import type { ArgsValidationConfig, HasTypeField } from "nexus-validation-plugin/utils.js" declare global { interface NexusGenCustomInputMethods { /** @@ -44,7 +44,7 @@ declare global { declare global { - interface NexusGen extends NexusGenTypes {} + interface NexusGen extends NexusGenTypes { } } export interface NexusGenInputs { @@ -422,15 +422,15 @@ declare global { * resolver from executing. */ authorize?: FieldAuthorizeResolver - + /** * Async validation function. Reject when validation fails. Resolve otherwise. */ - validate?: - NexusGenArgTypes extends HasTypeField - ? ArgsValidationConfig - : never - + validate?: + NexusGenArgTypes extends HasTypeField + ? ArgsValidationConfig + : never + } interface NexusGenPluginInputFieldConfig { } diff --git a/api/src/graphql/server/drive/schema.ts b/api/src/graphql/server/drive/schema.ts index 71038f89..96ffb6a1 100644 --- a/api/src/graphql/server/drive/schema.ts +++ b/api/src/graphql/server/drive/schema.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { connectionPlugin, fieldAuthorizePlugin, makeSchema } from 'nexus/dist'; +import nexus from 'nexus'; import { validationPlugin } from 'nexus-validation-plugin'; import { applyMiddleware } from 'graphql-middleware'; import * as driveResolver from '../../../modules/document-drive/drive-resolver'; @@ -12,7 +12,7 @@ import * as scopeFramework from '../../../modules/scope-framework'; import { getExtraResolvers } from '../../../importedModules'; /* istanbul ignore next @preserve */ -export const schema = makeSchema({ +export const schema = nexus.makeSchema({ types: { ...systemResolver, ...driveResolver, @@ -24,10 +24,10 @@ export const schema = makeSchema({ ...getExtraResolvers(), }, plugins: [ - fieldAuthorizePlugin({ + nexus.fieldAuthorizePlugin({ formatError: (authConfig) => authConfig.error, }), - connectionPlugin({ + nexus.connectionPlugin({ cursorFromNode(node: any) { return node.id; }, @@ -35,11 +35,11 @@ export const schema = makeSchema({ validationPlugin(), ], outputs: { - schema: path.join(__dirname, '../../generated/drive/schema.graphql'), - typegen: path.join(__dirname, '../../generated/drive/nexus.ts'), + schema: path.join(import.meta.dirname, '../../generated/drive/schema.graphql'), + typegen: path.join(import.meta.dirname, '../../generated/drive/nexus.ts'), }, contextType: { - module: path.join(__dirname, './context.ts'), + module: path.resolve(import.meta.dirname, '../src/graphql/server/drive/context.ts'), export: 'Context', }, }); diff --git a/api/src/graphql/server/index.ts b/api/src/graphql/server/index.ts index 51cbe4d7..62350841 100644 --- a/api/src/graphql/server/index.ts +++ b/api/src/graphql/server/index.ts @@ -65,3 +65,5 @@ export const addGraphqlRoutes = async ( }), ); }; + +export { Context }; diff --git a/api/src/graphql/server/index/schema.ts b/api/src/graphql/server/index/schema.ts index 3a07f2c1..25859ae2 100644 --- a/api/src/graphql/server/index/schema.ts +++ b/api/src/graphql/server/index/schema.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { connectionPlugin, fieldAuthorizePlugin, makeSchema } from 'nexus/dist'; +import nexus from 'nexus'; import { validationPlugin } from 'nexus-validation-plugin'; import { applyMiddleware } from 'graphql-middleware'; import * as systemResolver from '../../../modules/system'; @@ -7,15 +7,15 @@ import * as drivesResolver from '../../../modules/document-drive/drives-resolver import { getExtraResolvers } from '../../../importedModules'; /* istanbul ignore next @preserve */ -export const schema = makeSchema({ +export const schema = nexus.makeSchema({ types: { ...systemResolver, ...drivesResolver, ...getExtraResolvers(), }, plugins: [ - fieldAuthorizePlugin({ + nexus.fieldAuthorizePlugin({ formatError: (authConfig) => authConfig.error, }), - connectionPlugin({ + nexus.connectionPlugin({ cursorFromNode(node: any) { return node.id; }, @@ -23,11 +23,11 @@ export const schema = makeSchema({ validationPlugin(), ], outputs: { - schema: path.join(__dirname, '../../generated/index/schema.graphql'), - typegen: path.join(__dirname, '../../generated/index/nexus.ts'), + schema: path.join(import.meta.dirname, '../../generated/index/schema.graphql'), + typegen: path.join(import.meta.dirname, '../../generated/index/nexus.ts'), }, contextType: { - module: path.join(__dirname, './context.ts'), + module: path.resolve(import.meta.dirname, '../src/graphql/server/drive/context.ts'), export: 'Context', }, }); diff --git a/api/src/index.ts b/api/src/index.ts index 52967ef0..23160437 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -4,7 +4,7 @@ import { createApp } from './app'; import { addGraphqlRoutes } from './graphql/server'; import { getChildLogger } from './logger'; import { closeRedis } from './redis'; -import { Server, createServer as createHttpServer } from 'http'; +import { type Server, createServer as createHttpServer } from 'http'; import { PORT } from './env'; import { errorHandler } from './middleware/errors'; import { initRedis } from './redis'; @@ -46,8 +46,9 @@ async function startServer( startServer(app, router) .then((e) => { // Hot Module Replacement - if (import.meta.hot) { - import.meta.hot.on("vite:beforeFullReload", () => { + const { hot } = (import.meta as any); + if (hot) { + hot.on('vite:beforeFullReload', () => { e.close(); }); } diff --git a/api/src/logger.ts b/api/src/logger.ts index c0c87a6b..096402fb 100644 --- a/api/src/logger.ts +++ b/api/src/logger.ts @@ -2,13 +2,13 @@ import path from 'path'; import pino from 'pino'; import pinoHttp from 'pino-http'; import { loggerConfig } from '../logger.config'; -import { createWriteStream, Sentry } from "pino-sentry"; + const { moduleFilter, prefixFilter, logLevel, httpLogLevel, } = loggerConfig; const formatPrefix = (prefix: string): string => `[${prefix.toUpperCase()}] `; -const PROJECT_ROOT = path.resolve(__dirname, '..'); +const PROJECT_ROOT = path.resolve(import.meta.dirname, '..'); const filterPrefix = (config: { options: pino.ChildLoggerOptions; @@ -81,7 +81,7 @@ export const getChildLogger = ( bindings?: pino.Bindings, ) => { // get caller module of this function - const caller = Error().stack?.split('at ')[2].trim().split(':')[0] || ''; + const caller = Error().stack?.split('at ').at(2)?.trim().split(':')[0] || ''; const localOptions = { ...options }; const appliedBindings: pino.Bindings = { module: path.relative(PROJECT_ROOT, caller), diff --git a/api/src/modules/document/listenerManager.ts b/api/src/modules/document/listenerManager.ts index 24a065ed..dc412782 100644 --- a/api/src/modules/document/listenerManager.ts +++ b/api/src/modules/document/listenerManager.ts @@ -1,81 +1,77 @@ -import path from 'path'; -import fs from 'fs'; -import { DocumentDriveServer, IReceiver, InternalTransmitter, InternalTransmitterUpdate } from 'document-drive'; +import { + DocumentDriveServer, IReceiver, InternalTransmitter, InternalTransmitterUpdate, +} from 'document-drive'; import { Listener, DocumentDriveDocument } from 'document-model-libs/document-drive'; -import { Document, OperationScope } from "document-model/document" +import { Document, OperationScope } from 'document-model/document'; import { Prisma } from '@prisma/client'; import { getChildLogger } from '../../logger'; +// eslint-disable-next-line import/no-cycle +import * as modules from '..'; +import type { SwitchboardModule, SwitchboardTransmitter } from '../types'; const logger = getChildLogger({ msgPrefix: 'Listener Manager' }, { module: 'Listener Manager' }); -const listeners: Promise[] = []; -function loadModules(startPath: string, filter: string): Promise[] { - if (!fs.existsSync(startPath)) { - logger.error(`Directory not found: ${startPath}`); - return []; +const transmitters: SwitchboardTransmitter[] = []; +function loadModules(): SwitchboardTransmitter[] { + // eslint-disable-next-line no-restricted-syntax + for (const moduleName of Object.keys(modules)) { + const module = modules[moduleName] as SwitchboardModule; + if (module.transmitter) { + logger.info(`Loading listener from ${moduleName}`); + transmitters.push(module.transmitter); } - - var files = fs.readdirSync(startPath); - for (var i = 0; i < files.length; i++) { - var filename = path.join(startPath, files[i]); - var stat = fs.lstatSync(filename); - if (stat.isDirectory()) { - loadModules(filename, filter); //recursive - } else if (filename.endsWith(filter)) { - logger.info(`Loading listener from ${filename}`); - listeners.push(import(filename)); - }; - }; - return listeners; -}; + } + return transmitters; +} function isListenerRegistered(drive: DocumentDriveDocument, listener: Listener) { - const listeners = drive.state.local.listeners; - return listeners.filter((l) => l.listenerId === listener.listenerId).length > 0; + const { listeners } = drive.state.local; + return listeners.filter((l) => l.listenerId === listener.listenerId).length > 0; } async function registerListener(driveServer: DocumentDriveServer, driveId: string, listener: Listener) { - const receiver: IReceiver = { - transmit: async () => { } - } - await driveServer.addInternalListener(driveId, receiver, { - listenerId: listener.listenerId, - filter: listener.filter, - block: false, - label: listener.label!, - }) + const receiver: IReceiver = { + transmit: async () => { }, + }; + await driveServer.addInternalListener(driveId, receiver, { + listenerId: listener.listenerId, + filter: listener.filter, + block: false, + label: listener.label!, + }); - logger.info(`Listener ${listener.label}(${listener.listenerId}) registered for drive ${driveId}`); + logger.info(`Listener ${listener.label}(${listener.listenerId}) registered for drive ${driveId}`); } export async function init(driveServer: DocumentDriveServer, prisma: Prisma.TransactionClient) { - loadModules('./src/modules', 'listener.ts'); - const modules = await Promise.all(listeners); - const drives = await driveServer.getDrives(); - for (const { listener, transmit } of modules) { - if (!listener || !transmit) { - continue; - } + const listeners = loadModules(); + const drives = await driveServer.getDrives(); + // eslint-disable-next-line no-restricted-syntax + for (const { options, transmit } of listeners) { + if (!options || !transmit) { + continue; + } - for (const driveId of drives) { - try { - const drive = await driveServer.getDrive(driveId); - if (!isListenerRegistered(drive, listener)) { - await registerListener(driveServer, driveId, listener); - } + // eslint-disable-next-line no-restricted-syntax + for (const driveId of drives) { + try { + const drive = await driveServer.getDrive(driveId); + if (!isListenerRegistered(drive, options)) { + await registerListener(driveServer, driveId, options); + } - const transmitter = (await driveServer.getTransmitter(driveId, listener.listenerId)); - if (transmitter instanceof InternalTransmitter) { - logger.info(`Setting receiver for ${listener.listenerId}`); - transmitter.setReceiver({ - transmit: async (strands: InternalTransmitterUpdate[]) => { - transmit(strands, prisma) - } - }) - } - } catch (e) { - logger.error(`Error while initializing listener ${listener.listenerId} for drive ${driveId}`, e); - } + const transmitter = (await driveServer.getTransmitter(driveId, options.listenerId)); + if (transmitter instanceof InternalTransmitter) { + logger.info(`Setting receiver for ${options.listenerId}`); + transmitter.setReceiver({ + transmit: async (strands: InternalTransmitterUpdate[]) => { + transmit(strands, prisma); + }, + }); } + } catch (e) { + logger.error(`Error while initializing listener ${options.listenerId} for drive ${driveId}`, e); + } } + } } diff --git a/api/src/modules/index.ts b/api/src/modules/index.ts index bf3b88d4..687da38f 100644 --- a/api/src/modules/index.ts +++ b/api/src/modules/index.ts @@ -1,4 +1 @@ -export * from './system'; -export * from './system/core-unit'; -export * from './document-drive'; -export * from './real-world-assets'; +export { module as RealWorldAssets } from './real-world-assets'; diff --git a/api/src/modules/real-world-assets/index.ts b/api/src/modules/real-world-assets/index.ts index b45adb6e..82c9885f 100644 --- a/api/src/modules/real-world-assets/index.ts +++ b/api/src/modules/real-world-assets/index.ts @@ -1,2 +1,12 @@ +import { SwitchboardModule } from '../types'; +import { options, transmit } from './listener'; + export * from './resolvers'; export * from './model'; + +export const module: SwitchboardModule = { + transmitter: { + transmit, + options, + }, +}; diff --git a/api/src/modules/real-world-assets/listener.ts b/api/src/modules/real-world-assets/listener.ts index 67cca572..8f67d780 100644 --- a/api/src/modules/real-world-assets/listener.ts +++ b/api/src/modules/real-world-assets/listener.ts @@ -6,14 +6,7 @@ import { getChildLogger } from "../../logger"; const logger = getChildLogger({ msgPrefix: 'RWA Internal Listener' }, { moduleName: "RWA Internal Listener" }); -export interface IReceiverOptions { - listenerId: string; - label: string; - block: boolean; - filter: ListenerFilter; -} - -export const listener: IReceiverOptions = { +export const options: IReceiverOptions = { listenerId: "real-world-assets", filter: { branch: ["main"], diff --git a/api/src/modules/system/challenge/model.ts b/api/src/modules/system/challenge/model.ts index bef43c8b..8a09b0e3 100644 --- a/api/src/modules/system/challenge/model.ts +++ b/api/src/modules/system/challenge/model.ts @@ -4,9 +4,9 @@ import { GraphQLError } from 'graphql'; import url from 'url'; import { randomUUID } from 'crypto'; import { getUserCrud } from '../user'; -import { getSessionCrud } from '../session'; import { getChildLogger } from '../../../logger'; import { API_ORIGIN } from '../../../env'; +import { getSessionCrud } from '../session/model'; const logger = getChildLogger({ msgPrefix: 'Challenge' }); diff --git a/api/src/modules/system/core-unit/resolvers.ts b/api/src/modules/system/core-unit/resolvers.ts index 4427ba04..f3a1436d 100644 --- a/api/src/modules/system/core-unit/resolvers.ts +++ b/api/src/modules/system/core-unit/resolvers.ts @@ -1,7 +1,7 @@ import { stringArg, list, queryField, objectType, -} from 'nexus/dist'; -import { Context } from '../../../graphql/server/index/context'; +} from 'nexus'; +import { Context } from '../../../graphql/server/drive/context'; export const CoreUnit = objectType({ name: 'CoreUnit', diff --git a/api/src/modules/system/session/helpers.ts b/api/src/modules/system/session/helpers.ts index 41af8759..73f717d3 100644 --- a/api/src/modules/system/session/helpers.ts +++ b/api/src/modules/system/session/helpers.ts @@ -4,7 +4,7 @@ import type { Prisma } from '@prisma/client'; import { randomUUID } from 'crypto'; import { GraphQLError } from 'graphql'; import wildcard from 'wildcard-match'; -import { sign, verify as jwtVerify } from 'jsonwebtoken'; +import jwt from 'jsonwebtoken'; import { JWT_SECRET, JWT_EXPIRATION_PERIOD } from '../../../env'; const jwtSchema = z.object({ @@ -23,16 +23,16 @@ const generateToken = ( expiryDurationSeconds?: number | null, ) => { if (expiryDurationSeconds === null) { - return sign({ sessionId }, JWT_SECRET); + return jwt.sign({ sessionId }, JWT_SECRET); } const expiresIn = typeof expiryDurationSeconds !== 'undefined' ? ms(expiryDurationSeconds * 1000) : JWT_EXPIRATION_PERIOD; - return sign({ sessionId }, JWT_SECRET, { expiresIn }); + return jwt.sign({ sessionId }, JWT_SECRET, { expiresIn }); }; const getExpiryDateFromToken = (token: string) => { - const { exp } = jwtSchema.parse(jwtVerify(token, JWT_SECRET)); + const { exp } = jwtSchema.parse(jwt.verify(token, JWT_SECRET)); if (!exp) { return null; } @@ -40,7 +40,7 @@ const getExpiryDateFromToken = (token: string) => { }; export const verifyToken = (token: string) => { - const verified = jwtVerify(token, JWT_SECRET, (err, decoded) => { + const verified = jwt.verify(token, JWT_SECRET, (err, decoded) => { if (err) { throw new GraphQLError( err.name === 'TokenExpiredError' diff --git a/api/src/modules/system/session/resolvers.ts b/api/src/modules/system/session/resolvers.ts index 6a953068..c797920a 100644 --- a/api/src/modules/system/session/resolvers.ts +++ b/api/src/modules/system/session/resolvers.ts @@ -2,11 +2,9 @@ import { mutationField, nonNull, stringArg, - queryField, - list, inputObjectType, objectType, -} from 'nexus/dist'; +} from 'nexus'; import { Context } from '../../../graphql/server/index/context'; export const Session = objectType({ diff --git a/api/src/modules/system/user/resolvers.ts b/api/src/modules/system/user/resolvers.ts index 7a4cdf25..122f65e4 100644 --- a/api/src/modules/system/user/resolvers.ts +++ b/api/src/modules/system/user/resolvers.ts @@ -1,4 +1,4 @@ -import { objectType } from 'nexus/dist'; +import { objectType } from 'nexus'; export const User = objectType({ name: 'User', diff --git a/api/src/modules/types.ts b/api/src/modules/types.ts new file mode 100644 index 00000000..e9d1d243 --- /dev/null +++ b/api/src/modules/types.ts @@ -0,0 +1,21 @@ +import type { Prisma } from '@prisma/client'; +import type { InternalTransmitterUpdate } from 'document-drive'; +import type { ListenerFilter } from 'document-model-libs/document-drive'; + +export interface IReceiverOptions { + listenerId: string; + label: string; + block: boolean; + filter: ListenerFilter; +} + +export type InternalTransmit = ( + strands: InternalTransmitterUpdate[], + prisma?: Prisma.TransactionClient) +=> Promise; + +export type SwitchboardTransmitter = { transmit: InternalTransmit, options: IReceiverOptions }; + +export type SwitchboardModule = { + transmitter?: SwitchboardTransmitter +}; diff --git a/api/tsconfig.json b/api/tsconfig.json index 29586e18..cde33785 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -1,10 +1,17 @@ { "compilerOptions": { - "strict": true, "esModuleInterop": true, + "skipLibCheck": true, + "target": "es2022", + "verbatimModuleSyntax": false, + "allowJs": true, + "resolveJsonModule": true, + "moduleDetection": "force", + "strict": true, + "noUncheckedIndexedAccess": true, "moduleResolution": "Bundler", - "module": "ES2022", - "rootDirs": ["./src"], - "target": "ES2022" + "module": "ESNext", + "noEmit": true, + "lib": ["es2022"] } }