@ghom/orm 1.2.2 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/app/orm.js +4 -1
- package/dist/esm/app/orm.js +4 -1
- package/package.json +1 -1
- package/src/app/orm.ts +5 -1
package/dist/cjs/app/orm.js
CHANGED
|
@@ -23,10 +23,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.ORM = void 0;
|
|
26
|
+
const fs_1 = __importDefault(require("fs"));
|
|
26
27
|
const url_1 = __importDefault(require("url"));
|
|
27
28
|
const handler_1 = require("@ghom/handler");
|
|
28
29
|
const knex_1 = __importDefault(require("knex"));
|
|
29
30
|
const table_js_1 = require("./table.js");
|
|
31
|
+
const pack = JSON.parse(fs_1.default.readFileSync("./package.json", "utf8"));
|
|
32
|
+
const isCJS = pack.type === "commonjs" || pack.type == void 0;
|
|
30
33
|
class ORM extends handler_1.Handler {
|
|
31
34
|
/**
|
|
32
35
|
* @param ormConfig configuration for table handler or just tablePath (path to directory that contains js files of tables)
|
|
@@ -47,7 +50,7 @@ class ORM extends handler_1.Handler {
|
|
|
47
50
|
async init() {
|
|
48
51
|
this.once("finish", async (pathList) => {
|
|
49
52
|
const tables = await Promise.all(pathList.map(async (filepath) => {
|
|
50
|
-
return Promise.resolve().then(() => __importStar(require(
|
|
53
|
+
return Promise.resolve().then(() => __importStar(require(isCJS ? filepath : url_1.default.pathToFileURL(filepath).href))).then((file) => file.default);
|
|
51
54
|
}));
|
|
52
55
|
const migration = new table_js_1.Table({
|
|
53
56
|
name: "migration",
|
package/dist/esm/app/orm.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import fs from "fs";
|
|
1
2
|
import url from "url";
|
|
2
3
|
import { Handler } from "@ghom/handler";
|
|
3
4
|
import { default as knex } from "knex";
|
|
4
5
|
import { Table } from "./table.js";
|
|
6
|
+
const pack = JSON.parse(fs.readFileSync("./package.json", "utf8"));
|
|
7
|
+
const isCJS = pack.type === "commonjs" || pack.type == void 0;
|
|
5
8
|
export class ORM extends Handler {
|
|
6
9
|
db;
|
|
7
10
|
ormConfig;
|
|
@@ -24,7 +27,7 @@ export class ORM extends Handler {
|
|
|
24
27
|
async init() {
|
|
25
28
|
this.once("finish", async (pathList) => {
|
|
26
29
|
const tables = await Promise.all(pathList.map(async (filepath) => {
|
|
27
|
-
return import(
|
|
30
|
+
return import(isCJS ? filepath : url.pathToFileURL(filepath).href).then((file) => file.default);
|
|
28
31
|
}));
|
|
29
32
|
const migration = new Table({
|
|
30
33
|
name: "migration",
|
package/package.json
CHANGED
package/src/app/orm.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import fs from "fs"
|
|
1
2
|
import url from "url"
|
|
2
3
|
import { Handler } from "@ghom/handler"
|
|
3
4
|
import { Knex, default as knex } from "knex"
|
|
4
5
|
import { MigrationData, Table } from "./table.js"
|
|
5
6
|
|
|
7
|
+
const pack = JSON.parse(fs.readFileSync("./package.json", "utf8"))
|
|
8
|
+
const isCJS = pack.type === "commonjs" || pack.type == void 0
|
|
9
|
+
|
|
6
10
|
export interface ORMLogger {
|
|
7
11
|
log: (message: string, section?: string) => void
|
|
8
12
|
error: (text: string | Error, _path: string, full?: boolean) => void
|
|
@@ -46,7 +50,7 @@ export class ORM extends Handler {
|
|
|
46
50
|
const tables: Table<any>[] = await Promise.all(
|
|
47
51
|
pathList.map(async (filepath) => {
|
|
48
52
|
return import(
|
|
49
|
-
|
|
53
|
+
isCJS ? filepath : url.pathToFileURL(filepath).href
|
|
50
54
|
).then((file) => file.default)
|
|
51
55
|
})
|
|
52
56
|
)
|