From e090fdedc6895c3778f94149896a687eeeb2898e Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Wed, 20 Dec 2023 23:26:30 -0100 Subject: [PATCH] chore: Remove offending script and slowly start removing sdks --- apps/web/pages/api/v0/[...trpc].ts | 18 ++++++++-------- kits/sdk/bin/jsonToJs.ts | 34 ------------------------------ kits/sdk/package.json | 4 +--- 3 files changed, 10 insertions(+), 46 deletions(-) delete mode 100644 kits/sdk/bin/jsonToJs.ts diff --git a/apps/web/pages/api/v0/[...trpc].ts b/apps/web/pages/api/v0/[...trpc].ts index 578183a4..800b4f5c 100644 --- a/apps/web/pages/api/v0/[...trpc].ts +++ b/apps/web/pages/api/v0/[...trpc].ts @@ -1,12 +1,8 @@ import '@usevenice/app-config/register.node' - import type {NextApiHandler} from 'next' - import {createOpenApiNextHandler} from '@usevenice/trpc-openapi' - import {respondToCORS} from '@/lib-server' import {appRouter} from '@/lib-server/appRouter' - import {createContext, onError} from '../trpc/[...trpc]' const handler = createOpenApiNextHandler({ @@ -16,13 +12,17 @@ const handler = createOpenApiNextHandler({ onError, }) -export default (function trpcHandler(req, res) { +export default (function trpcOpenAPIHandler(req, res) { if (respondToCORS(req, res)) { return } - // allow the root document to work. - if (!req.query['trpc']) { - req.query['trpc'] = '' - } + console.log( + '[trpcOpenAPIHandler]', + req.url, + req.method, + req.headers, + req.body, + ) + return handler(req, res) } satisfies NextApiHandler) diff --git a/kits/sdk/bin/jsonToJs.ts b/kits/sdk/bin/jsonToJs.ts deleted file mode 100644 index 5c6d8403..00000000 --- a/kits/sdk/bin/jsonToJs.ts +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env node -import fs from 'node:fs' - -/** - * This is used to workaround the fact that many applications such as - * webpack does not natively know how to import / bundle JSON files - * And we also don't want to use something ugly heavy handed like a roll up - * So simpliest solution is to rewrite the JSON file as a JS file - */ -const jsonFileName = process.argv[2] - -if (!jsonFileName) { - console.error('Please provide a JSON file name as a command line argument.') - process.exit(1) -} - -try { - const jsonData = fs.readFileSync(jsonFileName, 'utf8') - const jsFileName = `${jsonFileName}.js` - const jsContent = `module.exports = \n${jsonData}` - - fs.writeFileSync(jsFileName, jsContent, 'utf8') - fs.rmSync(jsonFileName) - - console.log(`Successfully generated ${jsFileName} with JSON content.`) -} catch (err) { - console.error('An error occurred while generating the JavaScript file:', err) - process.exit(1) -} - - -// TODO: There is additional problem where tsc does not copy .d.ts files to build, and therefore we -// need to do it manully -// https://stackoverflow.com/questions/56018167/typescript-does-not-copy-d-ts-files-to-build diff --git a/kits/sdk/package.json b/kits/sdk/package.json index e1b614d2..088c88b5 100644 --- a/kits/sdk/package.json +++ b/kits/sdk/package.json @@ -6,9 +6,7 @@ "main": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": { - "build": "tsc -p ./tsconfig.json && run-s build:json build:dts", - "build:dts": "cp ./venice.oas.d.ts ./dist/venice.oas.d.ts", - "build:json": "node --loader tsx ./bin/jsonToJs.ts ./dist/venice.oas.json", + "build": "tsc -p ./tsconfig.json", "clean": "rm -rf ./dist", "generate": "pnpm generate:schema && pnpm generate:types", "generate:schema": "NEXT_PUBLIC_SERVER_URL=https://app.venice.is node --loader tsx ../../apps/web/lib-server/appRouter.ts > ./venice.oas.json",