Skip to content

Commit

Permalink
feat(client): create minimal client prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
LilaRest committed May 15, 2023
1 parent 8a09e7b commit 2295036
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
30 changes: 15 additions & 15 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"files.exclude": {
"renovate.json": false,
"tsconfig.json": false,
"pnpm-lock.yaml": false,
"CHANGELOG.md": false,
".releaserc.json": false,
".github": false,
"node_modules": false,
"package.json": false,
".gitignore": false,
"README.md": false,
"LICENSE": false,
"vitest.config.ts": false,
"coverage": false,
"dist": false,
"scripts": false
"renovate.json": true,
"tsconfig.json": true,
"pnpm-lock.yaml": true,
"CHANGELOG.md": true,
".releaserc.json": true,
".github": true,
"node_modules": true,
"package.json": true,
".gitignore": true,
"README.md": true,
"LICENSE": true,
"vitest.config.ts": true,
"coverage": true,
"dist": true,
"scripts": true
}
}
31 changes: 31 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PrismaClient } from "@prisma/client";
import { modelsSpecs } from "./.generated";
import { methodClauses, MethodClause } from "./clauses";
import { getConfig } from "./config";
import { ValidatedQuery } from "./validator";

const config = getConfig();
const prisma = config?.prismaClientInstance as PrismaClient & {
[key: string]: any;
};
if (!prisma) throw "Prisma Client instance not found";

class PrismaryModel {
[key: MethodClause]: any;
constructor (model: string) {
for (const methodName of methodClauses) {
this[methodName] = (body: object) => {
new ValidatedQuery(model, methodName, body).send();
};
}
}
}

export class PrismaryClient {
[key: keyof typeof modelsSpecs]: PrismaryModel;
constructor () {
for (const model of Object.keys(modelsSpecs)) {
this[model] = new PrismaryModel(model);
}
}
}
2 changes: 1 addition & 1 deletion src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type ReadQueryBody = Partial<{



class ValidatedQuery {
export class ValidatedQuery {
model: string;
method: MethodClause;
body: QueryBody;
Expand Down
4 changes: 4 additions & 0 deletions tests/main.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { describe, expect, it } from 'vitest';

describe.skip("", () => {
};

0 comments on commit 2295036

Please sign in to comment.