Skip to content

Commit

Permalink
Merge pull request #15 from narthur/codegen
Browse files Browse the repository at this point in the history
don't require database token to instantiate factory
  • Loading branch information
narthur committed Apr 11, 2024
2 parents fab0116 + f928d6e commit 80de5b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
14 changes: 2 additions & 12 deletions src/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import rc from "rc";
import { BaserowSdk } from "./index.js";
import z from "zod";
import fs from "fs";
import makeType from "./codegen/makeType.js";
import makeClassMethods from "./codegen/makeClassMethods.js";
import path from "path";
import { getConfig } from "./getConfig.js";

const __dirname = path.dirname(new URL(import.meta.url).pathname);

export default async function main(): Promise<void> {
const raw = rc("baserow");
const config = z
.object({
url: z.string(),
tables: z.record(z.string(), z.number()),
databaseToken: z.string(),
outDir: z.string(),
config: z.string(),
})
.parse(raw);
const config = getConfig();

console.dir(config);

Expand Down
6 changes: 4 additions & 2 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { getConfig } from "./getConfig.js";
import { BaserowSdk } from "./index.js";

export abstract class Factory {
protected sdk: BaserowSdk;
constructor({ sdk }: { sdk: BaserowSdk }) {
this.sdk = sdk;
constructor() {
const config = getConfig();
this.sdk = new BaserowSdk(config.databaseToken);
}
}
16 changes: 16 additions & 0 deletions src/getConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import rc from "rc";
import z from "zod";

const schema = z.object({
url: z.string(),
tables: z.record(z.string(), z.number()),
databaseToken: z.string(),
outDir: z.string(),
config: z.string(),
});

type BaserowConfig = z.infer<typeof schema>;

export function getConfig(): BaserowConfig {
return schema.parse(rc("baserow"));
}

0 comments on commit 80de5b4

Please sign in to comment.