bun-query-builder 0.1.5 → 0.1.6
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/actions/benchmark.d.ts +9 -5
- package/dist/actions/cache.d.ts +2 -14
- package/dist/actions/console.d.ts +0 -6
- package/dist/actions/data.d.ts +3 -13
- package/dist/actions/db-info.d.ts +4 -9
- package/dist/actions/db-optimize.d.ts +4 -5
- package/dist/actions/db-wipe.d.ts +4 -5
- package/dist/actions/file.d.ts +2 -1
- package/dist/actions/index.d.ts +25 -25
- package/dist/actions/inspect.d.ts +3 -9
- package/dist/actions/introspect.d.ts +2 -1
- package/dist/actions/make-model.d.ts +3 -5
- package/dist/actions/migrate-generate.d.ts +4 -5
- package/dist/actions/migrate-rollback.d.ts +4 -11
- package/dist/actions/migrate-status.d.ts +5 -9
- package/dist/actions/migrate.d.ts +13 -21
- package/dist/actions/model-show.d.ts +3 -5
- package/dist/actions/query-explain-all.d.ts +3 -5
- package/dist/actions/relation-diagram.d.ts +5 -5
- package/dist/actions/seed.d.ts +7 -17
- package/dist/actions/sql.d.ts +2 -1
- package/dist/actions/unsafe.d.ts +2 -1
- package/dist/actions/validate.d.ts +4 -9
- package/dist/actions/wait-ready.d.ts +2 -1
- package/dist/client.d.ts +199 -189
- package/dist/config.d.ts +2 -1
- package/dist/db.d.ts +8 -9
- package/dist/drivers/index.d.ts +8 -6
- package/dist/drivers/mysql.d.ts +169 -19
- package/dist/drivers/postgres.d.ts +155 -19
- package/dist/drivers/sqlite.d.ts +157 -19
- package/dist/factory.d.ts +3 -6
- package/dist/index.d.ts +11 -11
- package/dist/index.js +48 -51
- package/dist/loader.d.ts +3 -2
- package/dist/meta.d.ts +3 -2
- package/dist/migrations.d.ts +42 -47
- package/dist/schema.d.ts +30 -177
- package/dist/seeder.d.ts +12 -17
- package/dist/types.d.ts +42 -143
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
|
28
28
|
var __promiseAll = (args) => Promise.all(args);
|
|
29
29
|
var __require = import.meta.require;
|
|
30
30
|
|
|
31
|
-
// ../../node_modules/bunfig/dist/index.js
|
|
31
|
+
// ../../node_modules/.bun/bunfig@0.15.0/node_modules/bunfig/dist/index.js
|
|
32
32
|
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readdirSync as readdirSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
33
33
|
import { homedir } from "os";
|
|
34
34
|
import { dirname as dirname2, resolve as resolve3 } from "path";
|
|
@@ -6443,20 +6443,13 @@ __export(exports_migrate, {
|
|
|
6443
6443
|
});
|
|
6444
6444
|
import { copyFileSync, existsSync as existsSync7, mkdirSync as mkdirSync5, mkdtempSync, readdirSync as readdirSync3, readFileSync as readFileSync2, unlinkSync, writeFileSync as writeFileSync7 } from "fs";
|
|
6445
6445
|
import { tmpdir } from "os";
|
|
6446
|
-
import {
|
|
6446
|
+
import { join as join5 } from "path";
|
|
6447
6447
|
import process13 from "process";
|
|
6448
|
-
function
|
|
6449
|
-
let currentPath = startPath;
|
|
6450
|
-
while (currentPath !== dirname5(currentPath)) {
|
|
6451
|
-
if (existsSync7(join5(currentPath, "package.json"))) {
|
|
6452
|
-
return currentPath;
|
|
6453
|
-
}
|
|
6454
|
-
currentPath = dirname5(currentPath);
|
|
6455
|
-
}
|
|
6448
|
+
function getWorkspaceRoot() {
|
|
6456
6449
|
return process13.cwd();
|
|
6457
6450
|
}
|
|
6458
|
-
function ensureSqlDirectory() {
|
|
6459
|
-
const sqlDir = getSqlDirectory();
|
|
6451
|
+
function ensureSqlDirectory(workspaceRoot) {
|
|
6452
|
+
const sqlDir = getSqlDirectory(workspaceRoot);
|
|
6460
6453
|
if (!existsSync7(sqlDir)) {
|
|
6461
6454
|
mkdirSync5(sqlDir, { recursive: true });
|
|
6462
6455
|
console.log(`-- Created SQL directory: ${sqlDir}`);
|
|
@@ -6467,8 +6460,8 @@ async function generateMigration(dir, opts = {}) {
|
|
|
6467
6460
|
if (!dir) {
|
|
6468
6461
|
dir = join5(process13.cwd(), "app/Models");
|
|
6469
6462
|
}
|
|
6470
|
-
const dialect =
|
|
6471
|
-
const workspaceRoot =
|
|
6463
|
+
const dialect = opts.dialect || config2.dialect || "postgres";
|
|
6464
|
+
const workspaceRoot = getWorkspaceRoot();
|
|
6472
6465
|
const models = await loadModels({ modelsDir: dir });
|
|
6473
6466
|
const plan = buildMigrationPlan(models, { dialect });
|
|
6474
6467
|
const defaultStatePath = join5(dir, `.qb-migrations.${dialect}.json`);
|
|
@@ -6522,8 +6515,12 @@ async function generateMigration(dir, opts = {}) {
|
|
|
6522
6515
|
await copyModelsToGenerated(dir, workspaceRoot);
|
|
6523
6516
|
return { sql, sqlStatements, hasChanges, plan };
|
|
6524
6517
|
}
|
|
6525
|
-
async function executeMigration() {
|
|
6526
|
-
|
|
6518
|
+
async function executeMigration(dir) {
|
|
6519
|
+
if (!dir) {
|
|
6520
|
+
dir = join5(process13.cwd(), "app/Models");
|
|
6521
|
+
}
|
|
6522
|
+
const workspaceRoot = getWorkspaceRoot();
|
|
6523
|
+
const sqlDir = ensureSqlDirectory(workspaceRoot);
|
|
6527
6524
|
const dialect = config2.dialect || "postgres";
|
|
6528
6525
|
const files = readdirSync3(sqlDir);
|
|
6529
6526
|
const scriptFiles = files.filter((file2) => file2.endsWith(".sql")).sort();
|
|
@@ -6587,9 +6584,9 @@ async function resetDatabase(dir, opts = {}) {
|
|
|
6587
6584
|
if (!dir) {
|
|
6588
6585
|
dir = join5(process13.cwd(), "app/Models");
|
|
6589
6586
|
}
|
|
6590
|
-
const dialect =
|
|
6587
|
+
const dialect = opts.dialect || "postgres";
|
|
6591
6588
|
const driver = getDialectDriver(dialect);
|
|
6592
|
-
const workspaceRoot =
|
|
6589
|
+
const workspaceRoot = getWorkspaceRoot();
|
|
6593
6590
|
try {
|
|
6594
6591
|
const dropMigrationsSql = driver.dropTable("migrations");
|
|
6595
6592
|
try {
|
|
@@ -6675,7 +6672,7 @@ async function deleteMigrationFiles(dir, workspaceRoot, opts = {}) {
|
|
|
6675
6672
|
dir = join5(process13.cwd(), "app/Models");
|
|
6676
6673
|
}
|
|
6677
6674
|
if (!workspaceRoot) {
|
|
6678
|
-
workspaceRoot =
|
|
6675
|
+
workspaceRoot = getWorkspaceRoot();
|
|
6679
6676
|
}
|
|
6680
6677
|
const dialect = String(opts.dialect || "postgres");
|
|
6681
6678
|
const defaultStatePath = join5(dir, `.qb-migrations.${dialect}.json`);
|
|
@@ -6701,7 +6698,7 @@ async function copyModelsToGenerated(dir, workspaceRoot) {
|
|
|
6701
6698
|
dir = join5(process13.cwd(), "app/Models");
|
|
6702
6699
|
}
|
|
6703
6700
|
if (!workspaceRoot) {
|
|
6704
|
-
workspaceRoot =
|
|
6701
|
+
workspaceRoot = getWorkspaceRoot();
|
|
6705
6702
|
}
|
|
6706
6703
|
try {
|
|
6707
6704
|
const generatedDir = join5(workspaceRoot, "generated");
|
|
@@ -6728,9 +6725,9 @@ async function copyModelsToGenerated(dir, workspaceRoot) {
|
|
|
6728
6725
|
}
|
|
6729
6726
|
function getSqlDirectory(workspaceRoot) {
|
|
6730
6727
|
if (!workspaceRoot) {
|
|
6731
|
-
workspaceRoot =
|
|
6728
|
+
workspaceRoot = getWorkspaceRoot();
|
|
6732
6729
|
}
|
|
6733
|
-
return join5(workspaceRoot, "sql");
|
|
6730
|
+
return join5(workspaceRoot, "database", "sql");
|
|
6734
6731
|
}
|
|
6735
6732
|
async function createMigrationsTable(qb, dialect) {
|
|
6736
6733
|
const driver = getDialectDriver(dialect);
|
|
@@ -6783,21 +6780,21 @@ var init_migrate_generate = __esm(async () => {
|
|
|
6783
6780
|
|
|
6784
6781
|
// src/actions/migrate-rollback.ts
|
|
6785
6782
|
import { existsSync as existsSync8, unlinkSync as unlinkSync2 } from "fs";
|
|
6786
|
-
import { dirname as
|
|
6783
|
+
import { dirname as dirname5, join as join6 } from "path";
|
|
6787
6784
|
import process14 from "process";
|
|
6788
|
-
function
|
|
6785
|
+
function findWorkspaceRoot2(startPath) {
|
|
6789
6786
|
let currentPath = startPath;
|
|
6790
|
-
while (currentPath !==
|
|
6787
|
+
while (currentPath !== dirname5(currentPath)) {
|
|
6791
6788
|
if (existsSync8(join6(currentPath, "package.json"))) {
|
|
6792
6789
|
return currentPath;
|
|
6793
6790
|
}
|
|
6794
|
-
currentPath =
|
|
6791
|
+
currentPath = dirname5(currentPath);
|
|
6795
6792
|
}
|
|
6796
6793
|
return process14.cwd();
|
|
6797
6794
|
}
|
|
6798
6795
|
function getSqlDirectory2(workspaceRoot) {
|
|
6799
6796
|
if (!workspaceRoot) {
|
|
6800
|
-
workspaceRoot =
|
|
6797
|
+
workspaceRoot = findWorkspaceRoot2(process14.cwd());
|
|
6801
6798
|
}
|
|
6802
6799
|
return join6(workspaceRoot, "sql");
|
|
6803
6800
|
}
|
|
@@ -6865,21 +6862,21 @@ var init_migrate_rollback = __esm(async () => {
|
|
|
6865
6862
|
|
|
6866
6863
|
// src/actions/migrate-status.ts
|
|
6867
6864
|
import { existsSync as existsSync9, readdirSync as readdirSync5 } from "fs";
|
|
6868
|
-
import { dirname as
|
|
6865
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
6869
6866
|
import process15 from "process";
|
|
6870
|
-
function
|
|
6867
|
+
function findWorkspaceRoot3(startPath) {
|
|
6871
6868
|
let currentPath = startPath;
|
|
6872
|
-
while (currentPath !==
|
|
6869
|
+
while (currentPath !== dirname6(currentPath)) {
|
|
6873
6870
|
if (existsSync9(join7(currentPath, "package.json"))) {
|
|
6874
6871
|
return currentPath;
|
|
6875
6872
|
}
|
|
6876
|
-
currentPath =
|
|
6873
|
+
currentPath = dirname6(currentPath);
|
|
6877
6874
|
}
|
|
6878
6875
|
return process15.cwd();
|
|
6879
6876
|
}
|
|
6880
6877
|
function getSqlDirectory3(workspaceRoot) {
|
|
6881
6878
|
if (!workspaceRoot) {
|
|
6882
|
-
workspaceRoot =
|
|
6879
|
+
workspaceRoot = findWorkspaceRoot3(process15.cwd());
|
|
6883
6880
|
}
|
|
6884
6881
|
return join7(workspaceRoot, "sql");
|
|
6885
6882
|
}
|
|
@@ -7314,15 +7311,15 @@ var init_relation_diagram = __esm(async () => {
|
|
|
7314
7311
|
|
|
7315
7312
|
// src/actions/seed.ts
|
|
7316
7313
|
import { existsSync as existsSync10, mkdirSync as mkdirSync6, readdirSync as readdirSync8, writeFileSync as writeFileSync9 } from "fs";
|
|
7317
|
-
import { dirname as
|
|
7314
|
+
import { dirname as dirname7, join as join11 } from "path";
|
|
7318
7315
|
import process18 from "process";
|
|
7319
|
-
function
|
|
7316
|
+
function findWorkspaceRoot4(startPath) {
|
|
7320
7317
|
let currentPath = startPath;
|
|
7321
|
-
while (currentPath !==
|
|
7318
|
+
while (currentPath !== dirname7(currentPath)) {
|
|
7322
7319
|
if (existsSync10(join11(currentPath, "package.json"))) {
|
|
7323
7320
|
return currentPath;
|
|
7324
7321
|
}
|
|
7325
|
-
currentPath =
|
|
7322
|
+
currentPath = dirname7(currentPath);
|
|
7326
7323
|
}
|
|
7327
7324
|
return process18.cwd();
|
|
7328
7325
|
}
|
|
@@ -7356,7 +7353,7 @@ async function loadSeeders(seedersDir) {
|
|
|
7356
7353
|
return seeders;
|
|
7357
7354
|
}
|
|
7358
7355
|
async function runSeeders(config3 = {}) {
|
|
7359
|
-
const workspaceRoot =
|
|
7356
|
+
const workspaceRoot = findWorkspaceRoot4(process18.cwd());
|
|
7360
7357
|
const seedersDir = config3.seedersDir || join11(workspaceRoot, "database/seeders");
|
|
7361
7358
|
const verbose = config3.verbose ?? true;
|
|
7362
7359
|
if (verbose) {
|
|
@@ -7391,7 +7388,7 @@ async function runSeeders(config3 = {}) {
|
|
|
7391
7388
|
}
|
|
7392
7389
|
}
|
|
7393
7390
|
async function runSeeder(className, options = {}) {
|
|
7394
|
-
const workspaceRoot =
|
|
7391
|
+
const workspaceRoot = findWorkspaceRoot4(process18.cwd());
|
|
7395
7392
|
const seedersDir = join11(workspaceRoot, "database/seeders");
|
|
7396
7393
|
const verbose = options.verbose ?? true;
|
|
7397
7394
|
if (verbose) {
|
|
@@ -7415,7 +7412,7 @@ async function runSeeder(className, options = {}) {
|
|
|
7415
7412
|
}
|
|
7416
7413
|
}
|
|
7417
7414
|
async function makeSeeder(name) {
|
|
7418
|
-
const workspaceRoot =
|
|
7415
|
+
const workspaceRoot = findWorkspaceRoot4(process18.cwd());
|
|
7419
7416
|
const seedersDir = join11(workspaceRoot, "database/seeders");
|
|
7420
7417
|
if (!existsSync10(seedersDir)) {
|
|
7421
7418
|
mkdirSync6(seedersDir, { recursive: true });
|
|
@@ -7479,7 +7476,7 @@ export default class ${className} extends Seeder {
|
|
|
7479
7476
|
console.log(`-- \u2713 Created seeder: ${filePath}`);
|
|
7480
7477
|
}
|
|
7481
7478
|
async function freshDatabase(options = {}) {
|
|
7482
|
-
const workspaceRoot =
|
|
7479
|
+
const workspaceRoot = findWorkspaceRoot4(process18.cwd());
|
|
7483
7480
|
const modelsDir = options.modelsDir || join11(workspaceRoot, "app/Models");
|
|
7484
7481
|
const seedersDir = options.seedersDir || join11(workspaceRoot, "database/seeders");
|
|
7485
7482
|
const verbose = options.verbose ?? true;
|
|
@@ -7542,21 +7539,21 @@ var init_unsafe = __esm(async () => {
|
|
|
7542
7539
|
|
|
7543
7540
|
// src/actions/validate.ts
|
|
7544
7541
|
import { existsSync as existsSync11 } from "fs";
|
|
7545
|
-
import { dirname as
|
|
7542
|
+
import { dirname as dirname8, join as join12 } from "path";
|
|
7546
7543
|
import process19 from "process";
|
|
7547
|
-
function
|
|
7544
|
+
function findWorkspaceRoot5(startPath) {
|
|
7548
7545
|
let currentPath = startPath;
|
|
7549
|
-
while (currentPath !==
|
|
7546
|
+
while (currentPath !== dirname8(currentPath)) {
|
|
7550
7547
|
if (existsSync11(join12(currentPath, "package.json"))) {
|
|
7551
7548
|
return currentPath;
|
|
7552
7549
|
}
|
|
7553
|
-
currentPath =
|
|
7550
|
+
currentPath = dirname8(currentPath);
|
|
7554
7551
|
}
|
|
7555
7552
|
return process19.cwd();
|
|
7556
7553
|
}
|
|
7557
7554
|
async function validateSchema(dir) {
|
|
7558
7555
|
if (!dir) {
|
|
7559
|
-
dir = join12(
|
|
7556
|
+
dir = join12(findWorkspaceRoot5(process19.cwd()), "app/Models");
|
|
7560
7557
|
}
|
|
7561
7558
|
const dialect = config2.dialect || "postgres";
|
|
7562
7559
|
console.log("-- Validating Schema");
|
|
@@ -7899,21 +7896,21 @@ function buildSchemaMeta(models) {
|
|
|
7899
7896
|
|
|
7900
7897
|
// src/migrations.ts
|
|
7901
7898
|
import { existsSync as existsSync12, mkdirSync as mkdirSync7, writeFileSync as writeFileSync10 } from "fs";
|
|
7902
|
-
import { dirname as
|
|
7899
|
+
import { dirname as dirname9, join as join13 } from "path";
|
|
7903
7900
|
import process21 from "process";
|
|
7904
|
-
function
|
|
7901
|
+
function findWorkspaceRoot6(startPath) {
|
|
7905
7902
|
let currentPath = startPath;
|
|
7906
|
-
while (currentPath !==
|
|
7903
|
+
while (currentPath !== dirname9(currentPath)) {
|
|
7907
7904
|
if (existsSync12(join13(currentPath, "package.json"))) {
|
|
7908
7905
|
return currentPath;
|
|
7909
7906
|
}
|
|
7910
|
-
currentPath =
|
|
7907
|
+
currentPath = dirname9(currentPath);
|
|
7911
7908
|
}
|
|
7912
7909
|
return process21.cwd();
|
|
7913
7910
|
}
|
|
7914
7911
|
function ensureSqlDirectory2() {
|
|
7915
|
-
const workspaceRoot =
|
|
7916
|
-
const sqlDir = join13(workspaceRoot, "sql");
|
|
7912
|
+
const workspaceRoot = findWorkspaceRoot6(process21.cwd());
|
|
7913
|
+
const sqlDir = join13(workspaceRoot, "database", "sql");
|
|
7917
7914
|
if (!existsSync12(sqlDir)) {
|
|
7918
7915
|
mkdirSync7(sqlDir, { recursive: true });
|
|
7919
7916
|
console.log(`-- Created SQL directory: ${sqlDir}`);
|
package/dist/loader.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ModelRecord } from './schema';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
export declare interface LoadModelsOptions {
|
|
4
4
|
cwd?: string
|
|
5
5
|
modelsDir: string
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
|
+
export declare function loadModels(options: LoadModelsOptions): Promise<ModelRecord>;
|
package/dist/meta.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModelRecord } from './schema';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
export declare interface SchemaMeta {
|
|
4
4
|
modelToTable: Record<string, string>
|
|
5
5
|
tableToModel: Record<string, string>
|
|
@@ -18,4 +18,5 @@ export declare interface SchemaMeta {
|
|
|
18
18
|
morphedByMany?: Record<string, string>
|
|
19
19
|
}>
|
|
20
20
|
scopes?: Record<string, Record<string, (qb: any, value?: any) => any>>
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
|
+
export declare function buildSchemaMeta(models: ModelRecord): SchemaMeta;
|
package/dist/migrations.d.ts
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
import type { ModelRecord } from './schema';
|
|
2
2
|
import type { SupportedDialect } from './types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* - Drops removed indexes
|
|
25
|
-
* - Adds new foreign keys for newly added columns
|
|
26
|
-
*
|
|
27
|
-
* If there is no previous plan or the dialect changed, generates full SQL.
|
|
28
|
-
*/
|
|
29
|
-
export declare function generateDiffSql(previous: MigrationPlan | undefined, next: MigrationPlan): string[];
|
|
30
|
-
export declare interface ColumnPlan {
|
|
3
|
+
|
|
4
|
+
declare function findWorkspaceRoot(startPath: string): string;
|
|
5
|
+
declare function ensureSqlDirectory(): string;
|
|
6
|
+
declare function createMigrationFile(statement: string, fileName: string): boolean;
|
|
7
|
+
export declare type PrimitiveDefault = string | number | boolean | bigint | Date
|
|
8
|
+
|
|
9
|
+
export type NormalizedColumnType =
|
|
10
|
+
| 'string'
|
|
11
|
+
| 'text'
|
|
12
|
+
| 'boolean'
|
|
13
|
+
| 'integer'
|
|
14
|
+
| 'bigint'
|
|
15
|
+
| 'float'
|
|
16
|
+
| 'double'
|
|
17
|
+
| 'decimal'
|
|
18
|
+
| 'date'
|
|
19
|
+
| 'datetime'
|
|
20
|
+
| 'json'
|
|
21
|
+
| 'enum'
|
|
22
|
+
|
|
23
|
+
export interface ColumnPlan {
|
|
31
24
|
name: string
|
|
32
25
|
type: NormalizedColumnType
|
|
33
26
|
isPrimaryKey: boolean
|
|
@@ -38,33 +31,35 @@ export declare interface ColumnPlan {
|
|
|
38
31
|
references?: { table: string, column: string }
|
|
39
32
|
enumValues?: string[]
|
|
40
33
|
}
|
|
41
|
-
|
|
34
|
+
|
|
35
|
+
export interface IndexPlan {
|
|
42
36
|
name: string
|
|
43
37
|
columns: string[]
|
|
44
38
|
type: 'index' | 'unique'
|
|
45
39
|
}
|
|
46
|
-
|
|
40
|
+
|
|
41
|
+
export interface TablePlan {
|
|
47
42
|
table: string
|
|
48
43
|
columns: ColumnPlan[]
|
|
49
44
|
indexes: IndexPlan[]
|
|
50
45
|
}
|
|
51
|
-
|
|
46
|
+
|
|
47
|
+
export interface MigrationPlan {
|
|
52
48
|
dialect: SupportedDialect
|
|
53
49
|
tables: TablePlan[]
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
| 'enum'
|
|
51
|
+
declare function guessTypeFromName(columnName: string): NormalizedColumnType | undefined;
|
|
52
|
+
declare function normalizeDefaultValue(value: unknown): PrimitiveDefault | undefined;
|
|
53
|
+
declare function detectEnumFromValidationRule(rule: unknown): string[] | undefined;
|
|
54
|
+
declare function detectTypeFromValidationRule(rule: unknown): NormalizedColumnType | undefined;
|
|
55
|
+
export declare function buildMigrationPlan(models: ModelRecord, options: InferenceOptions): MigrationPlan;
|
|
56
|
+
export declare function generateSql(plan: MigrationPlan): string[];
|
|
57
|
+
export declare function generateSqlString(plan: MigrationPlan): string;
|
|
58
|
+
export declare function generateDiffSqlString(previous: MigrationPlan | undefined, next: MigrationPlan): string;
|
|
59
|
+
export declare function hashMigrationPlan(plan: MigrationPlan): string;
|
|
60
|
+
declare function canonicalize(value: any): any;
|
|
61
|
+
declare function mapTablesByName(tables: TablePlan[]): Record<string, TablePlan>;
|
|
62
|
+
declare function mapColumnsByName(columns: ColumnPlan[]): Record<string, ColumnPlan>;
|
|
63
|
+
declare function columnsAreDifferent(col1: ColumnPlan, col2: ColumnPlan): boolean;
|
|
64
|
+
declare function mapIndexesByKey(indexes: IndexPlan[]): Record<string, IndexPlan>;
|
|
65
|
+
export declare function generateDiffSql(previous: MigrationPlan | undefined, next: MigrationPlan): string[];
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,49 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const Post = defineModel({
|
|
10
|
-
* name: 'Post',
|
|
11
|
-
* attributes: {
|
|
12
|
-
* title: { validation: { rule: {} // isLength({ min: 1 }) } },
|
|
13
|
-
* },
|
|
14
|
-
* })
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export declare function defineModel<const T extends ModelDefinition>(model: T): T;
|
|
18
|
-
/**
|
|
19
|
-
* # `defineModels(models)`
|
|
20
|
-
*
|
|
21
|
-
* Freezes and returns a record of model definitions, preserving literal keys so
|
|
22
|
-
* downstream types (like `DatabaseSchema`) can map model names to table names.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const models = defineModels({ User, Post })
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function defineModels<const T extends ModelRecord>(models: T): T;
|
|
30
|
-
/**
|
|
31
|
-
* # `Attribute`
|
|
32
|
-
*
|
|
33
|
-
* Describes a model column and its validation/meta options.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const User = defineModel({
|
|
38
|
-
* name: 'User',
|
|
39
|
-
* attributes: {
|
|
40
|
-
* email: { validation: { rule: {} // isEmail() }, unique: true },
|
|
41
|
-
* age: { validation: { rule: {} // isInt({ min: 0 }) }, default: 0 },
|
|
42
|
-
* }
|
|
43
|
-
* })
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export declare interface Attribute {
|
|
1
|
+
export declare type ValidatorMessage = Record<string, string>
|
|
2
|
+
|
|
3
|
+
export type ValidationType = unknown
|
|
4
|
+
|
|
5
|
+
export interface Attribute {
|
|
47
6
|
default?: string | number | boolean | Date
|
|
48
7
|
unique?: boolean
|
|
49
8
|
order?: number
|
|
@@ -56,46 +15,33 @@ export declare interface Attribute {
|
|
|
56
15
|
message?: ValidatorMessage
|
|
57
16
|
}
|
|
58
17
|
}
|
|
59
|
-
export declare interface AttributesElements {
|
|
60
18
|
|
|
19
|
+
export interface AttributesElements {
|
|
20
|
+
[key: string]: Attribute
|
|
61
21
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*
|
|
65
|
-
* Describes a named multi-column index.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* { name: 'user_email_unique', columns: ['email'] }
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export declare interface CompositeIndex {
|
|
22
|
+
|
|
23
|
+
export interface CompositeIndex {
|
|
73
24
|
name: string
|
|
74
25
|
columns: string[]
|
|
75
26
|
}
|
|
76
|
-
export declare interface Base {
|
|
77
27
|
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* })
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export declare interface ModelOptions extends Base {
|
|
28
|
+
export interface Base {}
|
|
29
|
+
|
|
30
|
+
export type ModelNames = string
|
|
31
|
+
|
|
32
|
+
export type HasOne<T extends string> = Record<string, T>
|
|
33
|
+
export type HasMany<T extends string> = Record<string, T>
|
|
34
|
+
export type BelongsTo<T extends string> = Record<string, T>
|
|
35
|
+
export type BelongsToMany<T extends string> = Record<string, T>
|
|
36
|
+
export type HasOneThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
37
|
+
export type HasManyThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
38
|
+
export type MorphOne<T extends string> = Record<string, T>
|
|
39
|
+
export type MorphMany<T extends string> = Record<string, T>
|
|
40
|
+
export type MorphTo = Record<string, unknown>
|
|
41
|
+
export type MorphToMany<T extends string> = Record<string, T>
|
|
42
|
+
export type MorphedByMany<T extends string> = Record<string, T>
|
|
43
|
+
|
|
44
|
+
export interface ModelOptions extends Base {
|
|
99
45
|
name: string
|
|
100
46
|
description?: string
|
|
101
47
|
table?: string
|
|
@@ -125,102 +71,9 @@ export declare interface ModelOptions extends Base {
|
|
|
125
71
|
[key: string]: (value: any) => any
|
|
126
72
|
}
|
|
127
73
|
}
|
|
128
|
-
|
|
129
|
-
* # `ValidatorMessage`
|
|
130
|
-
*
|
|
131
|
-
* Map of field identifiers to custom error messages returned by validators.
|
|
132
|
-
*/
|
|
133
|
-
export type ValidatorMessage = Record<string, string>
|
|
134
|
-
/**
|
|
135
|
-
* # `ValidationType`
|
|
136
|
-
*
|
|
137
|
-
* External validator rule type (compatible with ts-validation). Kept broad to
|
|
138
|
-
* avoid a hard dependency while still enabling type inference via rule shape.
|
|
139
|
-
*/
|
|
140
|
-
export type ValidationType = unknown
|
|
141
|
-
export type ModelNames = string
|
|
142
|
-
/**
|
|
143
|
-
* # Relationship helpers
|
|
144
|
-
*
|
|
145
|
-
* Lightweight relationship declarations for model definitions. Each helper is a
|
|
146
|
-
* record keyed by relation name with the related model name as value.
|
|
147
|
-
*/
|
|
148
|
-
export type HasOne<T extends string> = Record<string, T>
|
|
149
|
-
export type HasMany<T extends string> = Record<string, T>
|
|
150
|
-
export type BelongsTo<T extends string> = Record<string, T>
|
|
151
|
-
export type BelongsToMany<T extends string> = Record<string, T>
|
|
152
|
-
export type HasOneThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
153
|
-
export type HasManyThrough<T extends string> = Record<string, { through: T, target: T }>
|
|
154
|
-
export type MorphOne<T extends string> = Record<string, T>
|
|
155
|
-
export type MorphMany<T extends string> = Record<string, T>
|
|
156
|
-
export type MorphTo = Record<string, unknown>
|
|
157
|
-
export type MorphToMany<T extends string> = Record<string, T>
|
|
158
|
-
export type MorphedByMany<T extends string> = Record<string, T>
|
|
74
|
+
|
|
159
75
|
export type ModelDefinition = Readonly<ModelOptions>
|
|
160
|
-
|
|
161
|
-
* # `ModelRecord`
|
|
162
|
-
*
|
|
163
|
-
* Collection of models keyed by model name. Kept flexible to preserve literal
|
|
164
|
-
* attribute keys and value types.
|
|
165
|
-
*/
|
|
76
|
+
|
|
166
77
|
export type ModelRecord = Record<string, any>
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
* Given a `ModelDefinition`, produces a record of attribute names to their
|
|
171
|
-
* inferred input type based on the validator rule shape.
|
|
172
|
-
*/
|
|
173
|
-
declare type ExtractRuleInput<R> = R extends { validate: (value: infer T) => any }
|
|
174
|
-
? T
|
|
175
|
-
: R extends { test: (value: infer T) => any }
|
|
176
|
-
? T
|
|
177
|
-
: R extends { getRules: () => Array<{ test: (value: infer T) => any }> }
|
|
178
|
-
? T
|
|
179
|
-
: unknown
|
|
180
|
-
export type InferAttributes<M extends ModelDefinition> = M extends {
|
|
181
|
-
attributes: infer A extends Record<string, { validation: { rule: any } }>
|
|
182
|
-
}
|
|
183
|
-
? { [K in keyof A & string]: ExtractRuleInput<A[K]['validation']['rule']> }
|
|
184
|
-
: Record<string, unknown>
|
|
185
|
-
/**
|
|
186
|
-
* # `InferPrimaryKey<M>`
|
|
187
|
-
*
|
|
188
|
-
* Extracts a model's primary key field name, defaulting to `'id'`.
|
|
189
|
-
*/
|
|
190
|
-
export type InferPrimaryKey<M extends ModelDefinition> = M extends {
|
|
191
|
-
primaryKey: infer K extends string
|
|
192
|
-
}
|
|
193
|
-
? K
|
|
194
|
-
: 'id'
|
|
195
|
-
/**
|
|
196
|
-
* # `InferTableName<M>`
|
|
197
|
-
*
|
|
198
|
-
* Resolves the table name from a model: uses `table` when provided, otherwise
|
|
199
|
-
* falls back to a simple pluralized form of the model name.
|
|
200
|
-
*/
|
|
201
|
-
export type InferTableName<M extends ModelDefinition> = M extends {
|
|
202
|
-
table: infer T extends string
|
|
203
|
-
}
|
|
204
|
-
? T
|
|
205
|
-
: M extends { name: infer N extends string }
|
|
206
|
-
? `${Lowercase<N>}s`
|
|
207
|
-
: string
|
|
208
|
-
/**
|
|
209
|
-
* # `DatabaseSchema<Models>`
|
|
210
|
-
*
|
|
211
|
-
* Maps model definitions to a concrete database schema shape containing the
|
|
212
|
-
* table columns and primary key. This is the primary input for the query
|
|
213
|
-
* builder's type-safety.
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* ```ts
|
|
217
|
-
* const models = defineModels({ User, Post })
|
|
218
|
-
* type Schema = DatabaseSchema<typeof models>
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
export type DatabaseSchema<MRecord extends ModelRecord> = {
|
|
222
|
-
[MName in keyof MRecord & string as InferTableName<MRecord[MName]>]: {
|
|
223
|
-
columns: InferAttributes<MRecord[MName]>
|
|
224
|
-
primaryKey: InferPrimaryKey<MRecord[MName]>
|
|
225
|
-
};
|
|
226
|
-
}
|
|
78
|
+
export declare function defineModel<const T extends ModelDefinition>(model: T): T;
|
|
79
|
+
export declare function defineModels<const T extends ModelRecord>(models: T): T;
|
package/dist/seeder.d.ts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export declare abstract class Seeder {
|
|
2
|
+
abstract run(qb: any): Promise<void>
|
|
3
|
+
|
|
4
|
+
get order(): number {
|
|
5
|
+
return 100
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get description(): string | undefined {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
11
|
+
}
|
|
8
12
|
export declare interface SeederConfig {
|
|
9
13
|
seedersDir?: string
|
|
10
14
|
seeders?: string[]
|
|
11
15
|
verbose?: boolean
|
|
12
16
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Options for running seeders
|
|
15
|
-
*/
|
|
16
17
|
export declare interface RunSeederOptions {
|
|
17
18
|
class?: string
|
|
18
19
|
verbose?: boolean
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
* Base seeder class that all seeders should extend.
|
|
22
|
-
* Provides access to query builder and faker for generating test data.
|
|
23
|
-
*/
|
|
24
|
-
export declare abstract class Seeder {
|
|
25
|
-
abstract run(qb: any): Promise<void>;
|
|
26
|
-
}
|
|
21
|
+
export declare function defineSeeder(seederClass?: new ()): new () => Seeder;
|