Skip to content

Commit 11b3aef

Browse files
committed
Removing dynamic imports
1 parent b567a88 commit 11b3aef

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

deno.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "@acr/dbx",
3-
"version": "0.9.1",
43
"license": "MIT",
54
"exports": "./mod.ts",
65
"fmt": {

src/ddl.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { existsSync } from "@std/fs";
21
import { eTag } from "@std/http/etag";
32
import type { Column, Constraint, Index, Relation, Schema } from "./types.ts";
43
import DB from "./db.ts";
@@ -58,17 +57,19 @@ export class DDL {
5857
*/
5958
static generator: (classFiles: Record<string, string>, base?: string, extensions?: string[]) => Promise<Record<string, Schema>>;
6059

61-
static async ensureSchemas(schemasFile: string, classFiles: Record<string, string>, base?: string, enhance = false): Promise<Record<string, Schema>> {
62-
const sfn = base + schemasFile;
63-
64-
// Try reading schemas from file
65-
let schemas = existsSync(schemasFile) ? (await import(sfn)).default : undefined;
66-
const outdated = !schemas ? true : await DDL.#outdatedSchemas(schemas, base);
60+
static async ensureSchemas(
61+
schemas: Record<string, Schema>,
62+
classFiles: Record<string, string>,
63+
base?: string,
64+
enhance = false,
65+
schemasFile?: string,
66+
): Promise<Record<string, Schema>> {
67+
const outdated = !schemas ? true : await DDL.outdatedSchemas(schemas, base);
6768
if (!outdated) return schemas;
6869

6970
// Generate and save
7071
schemas = await DDL.generateSchemas(classFiles, base, enhance);
71-
await Deno.writeTextFile(sfn, JSON.stringify(schemas, null, 2));
72+
if (schemasFile) await Deno.writeTextFile(schemasFile, JSON.stringify(schemas, null, 2));
7273
return schemas;
7374
}
7475

@@ -116,9 +117,9 @@ export class DDL {
116117
return schema;
117118
}
118119

119-
static async #outdatedSchemas(schemas: Record<string, Schema> | Schema[], base = "") {
120+
static async outdatedSchemas(schemas: Record<string, Schema> | Schema[], base = ""): Promise<boolean> {
120121
for (const schema of Array.isArray(schemas) ? schemas : Object.values(schemas)) {
121-
const outdated = await DDL.#outdatedSchema(schema, base);
122+
const outdated = await DDL.outdatedSchema(schema, base);
122123
if (outdated) return true;
123124
}
124125
return false;
@@ -130,7 +131,7 @@ export class DDL {
130131
* @param schema - the schema to check
131132
* @param base - the directory where the schema file is located
132133
*/
133-
static async #outdatedSchema(schema: Schema, base = "") {
134+
static async outdatedSchema(schema: Schema, base = ""): Promise<boolean> {
134135
if (!schema.$id) throw new Error("Schema must have an '$id' property to test if it is outdated");
135136

136137
// Get file and schema create date from $id

0 commit comments

Comments
 (0)