Scheduling infrastructure for absolutely everyone.
add @lib and @api paths for cleaner imports
Agusti Fernandez Pardof4d889e87b41
diff --git a/jest.config.ts b/jest.config.tsindex 6045b4fa450..48bf90223af 100644--- a/jest.config.ts+++ b/jest.config.ts@@ -82,7 +82,9 @@ export default {// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module// moduleNameMapper: {},-+ moduleNameMapper: {+ "^@lib/(.*)$": "<rootDir>/lib/$1",+ },// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader// modulePathIgnorePatterns: [],diff --git a/lib/validation/eventType.ts b/lib/validation/eventType.tsnew file mode 100644index 00000000000..581c9fd3c22--- /dev/null+++ b/lib/validation/eventType.ts@@ -0,0 +1,12 @@+import { z } from "zod";++const schema = z+ .object({+ title: z.string().min(3),+ slug: z.string().min(3),+ length: z.number().min(1).max(1440), // max is a full day.+ description: z.string().min(3).optional(),+ })+ .strict(); // Adding strict so that we can disallow passing in extra fields++export default schema;diff --git a/lib/validations/queryIdTransformParseInt.ts b/lib/validation/queryIdTransformParseInt.tssimilarity index 100%rename from lib/validations/queryIdTransformParseInt.tsrename to lib/validation/queryIdTransformParseInt.tsdiff --git a/package.json b/package.jsonindex 135808bdf28..496c86a04f6 100644--- a/package.json+++ b/package.json@@ -24,8 +24,7 @@"babel-jest": "^27.5.1","jest": "^27.5.1","node-mocks-http": "^1.11.0",- "typescript": "^4.5.3",- "zod": "^3.14.2"+ "typescript": "^4.5.3"},"dependencies": {"next": "^12.1.0",diff --git a/pages/api/event-types/[id]/delete.ts b/pages/api/event-types/[id]/delete.tsindex 038a23d7341..0158a4c02ec 100644--- a/pages/api/event-types/[id]/delete.ts+++ b/pages/api/event-types/[id]/delete.ts@@ -1,8 +1,9 @@import { PrismaClient, EventType } from "@prisma/client";-import schema from "lib/validations/queryIdTransformParseInt";import type { NextApiRequest, NextApiResponse } from "next";import { withValidation } from "next-validations";+import schema from "@lib/validation/queryIdTransformParseInt";+const prisma = new PrismaClient();type ResponseData = {diff --git a/pages/api/event-types/[id]/edit.ts b/pages/api/event-types/[id]/edit.tsindex 34c55b296b2..20e0dad0668 100644--- a/pages/api/event-types/[id]/edit.ts+++ b/pages/api/event-types/[id]/edit.ts@@ -1,19 +1,11 @@import { PrismaClient, EventType } from "@prisma/client";-import schemaQuery from "lib/validations/queryIdTransformParseInt";import type { NextApiRequest, NextApiResponse } from "next";import { withValidation } from "next-validations";-import { z } from "zod";-const prisma = new PrismaClient();+import schema from "@lib/validation/eventType";+import schemaQuery from "@lib/validation/queryIdTransformParseInt";-const schema = z- .object({- title: z.string().min(3),- slug: z.string().min(3),- length: z.number().min(1).max(1440), // max is a full day.- description: z.string().min(3).optional(),- })- .strict(); // Adding strict so that we can disallow passing in extra fields+const prisma = new PrismaClient();type ResponseData = {data?: EventType;diff --git a/pages/api/event-types/[id]/index.ts b/pages/api/event-types/[id]/index.tsindex 5fb6a6a5195..b17b0bb57b9 100644--- a/pages/api/event-types/[id]/index.ts+++ b/pages/api/event-types/[id]/index.ts@@ -1,8 +1,9 @@import { PrismaClient, EventType } from "@prisma/client";-import schema from "lib/validations/queryIdTransformParseInt";import type { NextApiRequest, NextApiResponse } from "next";import { withValidation } from "next-validations";+import schema from "@lib/validation/queryIdTransformParseInt";+const prisma = new PrismaClient();type ResponseData = {diff --git a/pages/api/event-types/new.ts b/pages/api/event-types/new.tsindex baf590a4d85..accfb24eabd 100644--- a/pages/api/event-types/new.ts+++ b/pages/api/event-types/new.ts@@ -1,48 +1,30 @@import { PrismaClient, EventType } from "@prisma/client";import type { NextApiRequest, NextApiResponse } from "next";import { withValidation } from "next-validations";-import { z } from "zod";-const prisma = new PrismaClient();+import schema from "@lib/validation/eventType";-const schema = z- .object({- title: z.string().min(3),- slug: z.string().min(3),- length: z.number().min(1).max(1440), // max is a full day.- description: z.string().min(3).optional(),- })- .strict(); // Adding strict so that we can disallow passing in extra fields+const prisma = new PrismaClient();-// type schema = z.infer<typeof schema>;const validate = withValidation({schema,type: "Zod",mode: "body",});-// interface Body {-// title: string;-// slug: string;-// length: number;-// }type Data = {data?: EventType;error?: string;};-type NextApiRequestWithBody = NextApiRequest & {- // body: Body;-};--async function createEventType(req: NextApiRequestWithBody, res: NextApiResponse<Data>) {+async function createEventType(req: NextApiRequest, res: NextApiResponse<Data>) {const { body, method } = req;if (method === "POST") {const safe = schema.safeParse(body);if (safe.success && safe.data) {await prisma.eventType.create({- data: { title: safe.data.title, slug: safe.data.slug, length: safe.data.length },+ data: safe.data,}).then((event) => res.status(201).json({ data: event })).catch((error) => {diff --git a/tsconfig.json b/tsconfig.jsonindex 67dc71427ae..b9b2164ce04 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -6,6 +6,7 @@"compilerOptions": {"strictNullChecks": true,"baseUrl": ".",+"target": "es5","lib": ["dom",@@ -18,6 +19,10 @@"module": "esnext","resolveJsonModule": true,"jsx": "preserve",+ "paths": {+ "@api/*": ["pages/api/*"],+ "@lib/*": ["lib/*"]+},},"include": ["./**/*.ts"diff --git a/yarn-error.log b/yarn-error.lognew file mode 100644index 00000000000..aed4e9d8633--- /dev/null+++ b/yarn-error.log@@ -0,0 +1,200 @@+Arguments:+ /Users/ag/Library/Application Support/fnm/node-versions/v14.17.6/installation/bin/node /Users/ag/Library/Caches/fnm_multishells/3034_1648146693474/bin/yarn test++PATH:+ /Users/ag/Library/pnpm:/Users/ag/Library/Caches/fnm_multishells/3034_1648146693474/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ag/.local/bin:/Users/ag/.fig/bin:/Users/ag/.local/bin:/Users/ag/.local/bin:/Users/ag/.yarn/bin++Yarn version:+ 1.22.17++Node version:+ 14.17.6++Platform:+ darwin x64++Trace:+ SyntaxError: /Users/ag/src/cal.com/apps/api/package.json: Unexpected token } in JSON at position 793+ at JSON.parse (<anonymous>)+ at /Users/ag/Library/Application Support/fnm/node-versions/v14.17.6/installation/lib/node_modules/yarn/lib/cli.js:1625:59+ at Generator.next (<anonymous>)+ at step (/Users/ag/Library/Application Support/fnm/node-versions/v14.17.6/installation/lib/node_modules/yarn/lib/cli.js:310:30)+ at /Users/ag/Library/Application Support/fnm/node-versions/v14.17.6/installation/lib/node_modules/yarn/lib/cli.js:321:13++npm manifest:+ {+ "name": "@calcom/api",+ "version": "1.0.0",+ "description": "Public API for Cal.com",+ "main": "index.ts",+ "repository": "[email protected]:calcom/api.git",+ "author": "Cal.com Inc.",+ "private": true,+ "scripts": {+ "dev": "PORT=3002 next",+ "start": "next start",+ "build": "next build",+ "lint": "next lint",+ "test": "jest --detectOpenHandles",+ "type-check": "tsc --pretty --noEmit",+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"+ },+ "devDependencies": {+ "@babel/core": "^7.17.8",+ "@babel/preset-env": "^7.16.11",+ "@babel/preset-typescript": "^7.16.7",+ "@calcom/prisma": "*",+ "@calcom/tsconfig": "*",+ "babel-jest": "^27.5.1",+ "jest": "^27.5.1",+ "node-mocks-http": "^1.11.0",+ "typescript": "^4.5.3",+ },+ "dependencies": {+ "next": "^12.1.0",+ "next-validations": "^0.1.11",+ "zod": "^3.14.2"+ }+ }++yarn manifest:+ No manifest++Lockfile:+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.+ # yarn lockfile v1+++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/env/-/env-12.1.0.tgz#73713399399b34aa5a01771fb73272b55b22c314"+ integrity sha512-nrIgY6t17FQ9xxwH3jj0a6EOiQ/WDHUos35Hghtr+SWN/ntHIQ7UpuvSi0vaLzZVHQWaDupKI+liO5vANcDeTQ==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-android-arm64/-/swc-android-arm64-12.1.0.tgz#865ba3a9afc204ff2bdeea49dd64d58705007a39"+ integrity sha512-/280MLdZe0W03stA69iL+v6I+J1ascrQ6FrXBlXGCsGzrfMaGr7fskMa0T5AhQIVQD4nA/46QQWxG//DYuFBcA==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-12.1.0.tgz#08e8b411b8accd095009ed12efbc2f1d4d547135"+ integrity sha512-R8vcXE2/iONJ1Unf5Ptqjk6LRW3bggH+8drNkkzH4FLEQkHtELhvcmJwkXcuipyQCsIakldAXhRbZmm3YN1vXg==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-12.1.0.tgz#fcd684497a76e8feaca88db3c394480ff0b007cd"+ integrity sha512-ieAz0/J0PhmbZBB8+EA/JGdhRHBogF8BWaeqR7hwveb6SYEIJaDNQy0I+ZN8gF8hLj63bEDxJAs/cEhdnTq+ug==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-12.1.0.tgz#9ec6380a27938a5799aaa6035c205b3c478468a7"+ integrity sha512-njUd9hpl6o6A5d08dC0cKAgXKCzm5fFtgGe6i0eko8IAdtAPbtHxtpre3VeSxdZvuGFh+hb0REySQP9T1ttkog==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-12.1.0.tgz#7f4196dff1049cea479607c75b81033ae2dbd093"+ integrity sha512-OqangJLkRxVxMhDtcb7Qn1xjzFA3s50EIxY7mljbSCLybU+sByPaWAHY4px97ieOlr2y4S0xdPKkQ3BCAwyo6Q==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-12.1.0.tgz#b445f767569cdc2dddee785ca495e1a88c025566"+ integrity sha512-hB8cLSt4GdmOpcwRe2UzI5UWn6HHO/vLkr5OTuNvCJ5xGDwpPXelVkYW/0+C3g5axbDW2Tym4S+MQCkkH9QfWA==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-12.1.0.tgz#67610e9be4fbc987de7535f1bcb17e45fe12f90e"+ integrity sha512-OKO4R/digvrVuweSw/uBM4nSdyzsBV5EwkUeeG4KVpkIZEe64ZwRpnFB65bC6hGwxIBnTv5NMSnJ+0K/WmG78A==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.1.0.tgz#ea19a23db08a9f2e34ac30401f774cf7d1669d31"+ integrity sha512-JohhgAHZvOD3rQY7tlp7NlmvtvYHBYgY0x5ZCecUT6eCCcl9lv6iV3nfu82ErkxNk1H893fqH0FUpznZ/H3pSw==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-12.1.0.tgz#eadf054fc412085659b98e145435bbba200b5283"+ integrity sha512-T/3gIE6QEfKIJ4dmJk75v9hhNiYZhQYAoYm4iVo1TgcsuaKLFa+zMPh4056AHiG6n9tn2UQ1CFE8EoybEsqsSw==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-12.1.0.tgz#68faeae10c89f698bf9d28759172b74c9c21bda1"+ integrity sha512-iwnKgHJdqhIW19H9PRPM9j55V6RdcOo6rX+5imx832BCWzkDbyomWnlzBfr6ByUYfhohb8QuH4hSGEikpPqI0Q==++ "@next/[email protected]":+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.1.0.tgz#d27e7e76c87a460a4da99c5bfdb1618dcd6cd064"+ integrity sha512-aBvcbMwuanDH4EMrL2TthNJy+4nP59Bimn8egqv6GHMVj0a44cU6Au4PjOhLNqEh9l+IpRGBqMTzec94UdC5xg==++ "@types/node@^17.0.21":+ version "17.0.21"+ resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.21.tgz#864b987c0c68d07b4345845c3e63b75edd143644"+ integrity sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==++ caniuse-lite@^1.0.30001283:+ version "1.0.30001317"+ resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001317.tgz#0548fb28fd5bc259a70b8c1ffdbe598037666a1b"+ integrity sha512-xIZLh8gBm4dqNX0gkzrBeyI86J2eCjWzYAs40q88smG844YIrN4tVQl/RhquHvKEKImWWFIVh1Lxe5n1G/N+GQ==++ nanoid@^3.1.30:+ version "3.3.1"+ resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.1.tgz#6347a18cac88af88f58af0b3594b723d5e99bb35"+ integrity sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw==++ next@^12.1.0:+ version "12.1.0"+ resolved "https://registry.yarnpkg.com/next/-/next-12.1.0.tgz#c33d753b644be92fc58e06e5a214f143da61dd5d"+ integrity sha512-s885kWvnIlxsUFHq9UGyIyLiuD0G3BUC/xrH0CEnH5lHEWkwQcHOORgbDF0hbrW9vr/7am4ETfX4A7M6DjrE7Q==+ dependencies:+ "@next/env" "12.1.0"+ caniuse-lite "^1.0.30001283"+ postcss "8.4.5"+ styled-jsx "5.0.0"+ use-subscription "1.5.1"+ optionalDependencies:+ "@next/swc-android-arm64" "12.1.0"+ "@next/swc-darwin-arm64" "12.1.0"+ "@next/swc-darwin-x64" "12.1.0"+ "@next/swc-linux-arm-gnueabihf" "12.1.0"+ "@next/swc-linux-arm64-gnu" "12.1.0"+ "@next/swc-linux-arm64-musl" "12.1.0"+ "@next/swc-linux-x64-gnu" "12.1.0"+ "@next/swc-linux-x64-musl" "12.1.0"+ "@next/swc-win32-arm64-msvc" "12.1.0"+ "@next/swc-win32-ia32-msvc" "12.1.0"+ "@next/swc-win32-x64-msvc" "12.1.0"++ object-assign@^4.1.1:+ version "4.1.1"+ resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"+ integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=++ picocolors@^1.0.0:+ version "1.0.0"+ resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"+ integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==++ version "8.4.5"+ resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.5.tgz#bae665764dfd4c6fcc24dc0fdf7e7aa00cc77f95"+ integrity sha512-jBDboWM8qpaqwkMwItqTQTiFikhs/67OYVvblFFTM7MrZjt6yMKd6r2kgXizEbTTljacm4NldIlZnhbjr84QYg==+ dependencies:+ nanoid "^3.1.30"+ picocolors "^1.0.0"+ source-map-js "^1.0.1"++ source-map-js@^1.0.1:+ version "1.0.2"+ resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"+ integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==++ version "5.0.0"+ resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-5.0.0.tgz#816b4b92e07b1786c6b7111821750e0ba4d26e77"+ integrity sha512-qUqsWoBquEdERe10EW8vLp3jT25s/ssG1/qX5gZ4wu15OZpmSMFI2v+fWlRhLfykA5rFtlJ1ME8A8pm/peV4WA==++ version "1.5.1"+ resolved "https://registry.yarnpkg.com/use-subscription/-/use-subscription-1.5.1.tgz#73501107f02fad84c6dd57965beb0b75c68c42d1"+ integrity sha512-Xv2a1P/yReAjAbhylMfFplFKj9GssgTwN7RlcTxBujFQcloStWNDQdc4g4NRWH9xS4i/FDk04vQBptAXoF3VcA==+ dependencies:+ object-assign "^4.1.1"