@ghom/orm 1.8.6 → 1.8.8

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.
@@ -102,7 +102,6 @@ export async function enableForeignKeys(orm, trx) {
102
102
  sqlite3: () => ctx.raw("PRAGMA foreign_keys = 1;"),
103
103
  pg: () => ctx.raw("SET session_replication_role = DEFAULT;"),
104
104
  });
105
- console.log("Foreign key constraints enabled.");
106
105
  }
107
106
  export async function disableForeignKeys(orm, run) {
108
107
  const trx = orm.clientBasedOperation({
@@ -132,7 +131,6 @@ export async function disableForeignKeys(orm, run) {
132
131
  return check;
133
132
  },
134
133
  });
135
- console.log(`Foreign key constraints ${ran ? "" : "already "}disabled.`);
136
134
  try {
137
135
  await run(trx);
138
136
  await enableForeignKeys(orm, trx);
package/dist/app/orm.d.ts CHANGED
@@ -46,9 +46,9 @@ export interface ORMConfig {
46
46
  export declare class ORM {
47
47
  config: ORMConfig;
48
48
  private _ready;
49
- database: Knex;
49
+ database: Knex<any, unknown[]>;
50
50
  handler: Handler<Table<any>>;
51
- _rawCache: ResponseCache<[sql: string], Knex.Raw>;
51
+ _rawCache: ResponseCache<[raw: string], Knex.Raw<any>>;
52
52
  constructor(config: ORMConfig);
53
53
  get cachedTables(): Table<any>[];
54
54
  get cachedTableNames(): string[];
package/dist/app/orm.js CHANGED
@@ -21,8 +21,13 @@ export class ORM {
21
21
  },
22
22
  });
23
23
  this.handler = new Handler(config.tableLocation, {
24
- loader: (filepath) => import(isCJS ? filepath : url.pathToFileURL(filepath).href).then((file) => file.default),
25
- pattern: /\.js$/,
24
+ pattern: /\.[jt]s$/,
25
+ loader: async (filepath) => {
26
+ const file = await import(isCJS ? filepath : url.pathToFileURL(filepath).href);
27
+ if (file.default instanceof Table)
28
+ return file.default;
29
+ throw new Error(`${filepath}: default export must be a Table instance`);
30
+ },
26
31
  });
27
32
  this._rawCache = new ResponseCache((raw) => this.raw(raw), config.caching ?? Infinity);
28
33
  }
@@ -57,8 +62,7 @@ export class ORM {
57
62
  }));
58
63
  const sortedTables = this.cachedTables.toSorted((a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0));
59
64
  for (const table of sortedTables) {
60
- table.orm = this;
61
- await table.make();
65
+ await table.make(this);
62
66
  }
63
67
  this._ready = true;
64
68
  }
@@ -28,7 +28,7 @@ export declare class Table<Type extends object = object> {
28
28
  ], unknown>;
29
29
  _countCache?: ResponseCache<[where: string | null], Promise<number>>;
30
30
  constructor(options: TableOptions<Type>);
31
- get db(): Knex<any, any[]>;
31
+ get db(): Knex<any, unknown[]>;
32
32
  get query(): Knex.QueryBuilder<Type, {
33
33
  _base: Type;
34
34
  _hasSelection: false;
@@ -50,6 +50,6 @@ export declare class Table<Type extends object = object> {
50
50
  getColumns(): Promise<Record<keyof Type & string, Knex.ColumnInfo>>;
51
51
  getColumnNames(): Promise<Array<keyof Type & string>>;
52
52
  isEmpty(): Promise<boolean>;
53
- make(): Promise<this>;
53
+ make(orm: ORM): Promise<this>;
54
54
  private migrate;
55
55
  }
package/dist/app/table.js CHANGED
@@ -62,9 +62,8 @@ export class Table {
62
62
  async isEmpty() {
63
63
  return this.count().then((count) => count === 0);
64
64
  }
65
- async make() {
66
- if (!this.orm)
67
- throw new Error("missing ORM");
65
+ async make(orm) {
66
+ this.orm = orm;
68
67
  this._whereCache = new ResponseCache((cb) => cb(this.query), this.options.caching ?? this.orm?.config.caching ?? Infinity);
69
68
  this._countCache = new ResponseCache((where) => this.count(where ?? undefined), this.options.caching ?? this.orm?.config.caching ?? Infinity);
70
69
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghom/orm",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "sqlite3": "^5.1.6"
32
32
  },
33
33
  "dependencies": {
34
- "@ghom/handler": "^2.0.0",
34
+ "@ghom/handler": "^3.1.0",
35
35
  "csv-parser": "^3.0.0",
36
36
  "json-2-csv": "^5.5.6",
37
37
  "knex": "^3.0.1"