Add js client lib

This commit is contained in:
David Corbitt
2023-08-06 13:50:43 -07:00
parent 7f8b574c9f
commit 109a9ddb1e
18 changed files with 596 additions and 3 deletions

View File

@@ -85,7 +85,7 @@ export const externalApiRouter = createTRPCRouter({
data: {
organizationId: key.organizationId,
startTime: new Date(input.startTime),
cacheHit: false,
cacheHit: true,
modelResponseId: existingResponse.id,
}
})

View File

@@ -2,9 +2,14 @@ import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { type GetServerSidePropsContext } from "next";
import { getServerSession, type NextAuthOptions, type DefaultSession } from "next-auth";
import { prisma } from "~/server/db";
import GitHubProvider from "next-auth/providers/github";
import GitHubModule from "next-auth/providers/github";
import { env } from "~/env.mjs";
// The client codegen script doesn't properly read the default export
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const untypedGitHubModule = GitHubModule as unknown as any
const GitHubProvider: typeof GitHubModule = untypedGitHubModule.default ? untypedGitHubModule.default : untypedGitHubModule
/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.

View File

@@ -0,0 +1,36 @@
import "dotenv/config";
import { openApiDocument } from "~/pages/api/openapi.json";
import fs from "fs";
import path from "path";
import { execSync } from "child_process";
console.log("Exporting public OpenAPI schema to client-libs/schema.json");
const scriptPath = import.meta.url.replace("file://", "");
const clientLibsPath = path.join(path.dirname(scriptPath), "../../../../client-libs");
const schemaPath = path.join(
clientLibsPath,
"schema.json"
);
console.log("Exporting schema");
fs.writeFileSync(schemaPath, JSON.stringify(openApiDocument, null, 2), "utf-8");
console.log("Generating Typescript client");
const tsClientPath = path.join(
clientLibsPath,
"js/codegen"
);
fs.rmSync(tsClientPath, { recursive: true, force: true });
execSync(
`pnpm dlx @openapitools/openapi-generator-cli generate -i "${schemaPath}" -g typescript-axios -o "${tsClientPath}"`,
{
stdio: "inherit",
}
);
console.log("Done!");