@h3ravel/arquebus 0.4.0 → 0.5.0
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/bin/index.cjs +47 -56
- package/bin/index.js +49 -57
- package/dist/browser/index.d.cts +3648 -176
- package/dist/browser/index.d.ts +3648 -176
- package/dist/index.cjs +21 -28
- package/dist/index.d.cts +3757 -287
- package/dist/index.d.ts +3757 -287
- package/dist/index.js +22 -29
- package/dist/inspector/index.cjs +17 -13
- package/dist/inspector/index.js +17 -13
- package/dist/migrations/index.cjs +30 -39
- package/dist/migrations/index.d.cts +3500 -18
- package/dist/migrations/index.d.ts +3500 -18
- package/dist/migrations/index.js +43 -45
- package/package.json +17 -17
- package/types/builder.ts +21 -16
- package/types/generics.ts +1 -0
- package/types/modeling.ts +7 -7
- package/types/query-builder.ts +9 -2
- package/types/query-methods.ts +20 -0
- package/types/utils.ts +1 -0
package/bin/index.cjs
CHANGED
|
@@ -58,8 +58,6 @@ let fs = require("fs");
|
|
|
58
58
|
fs = __toESM(fs);
|
|
59
59
|
let pluralize = require("pluralize");
|
|
60
60
|
pluralize = __toESM(pluralize);
|
|
61
|
-
let node_fs = require("node:fs");
|
|
62
|
-
node_fs = __toESM(node_fs);
|
|
63
61
|
let node_path = require("node:path");
|
|
64
62
|
node_path = __toESM(node_path);
|
|
65
63
|
let node_url = require("node:url");
|
|
@@ -2459,8 +2457,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
2459
2457
|
const results = await this.take(1).get(columns);
|
|
2460
2458
|
return results.count() > 0 ? results.first() : null;
|
|
2461
2459
|
}
|
|
2462
|
-
async firstOrFail(columns
|
|
2463
|
-
const model = await this.first(columns);
|
|
2460
|
+
async firstOrFail(...columns) {
|
|
2461
|
+
const model = await this.first(...columns);
|
|
2464
2462
|
if (model) return model;
|
|
2465
2463
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2466
2464
|
}
|
|
@@ -2499,7 +2497,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
2499
2497
|
}
|
|
2500
2498
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
2501
2499
|
this.query.addSelect(this.shouldSelect(columns));
|
|
2502
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
2500
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2503
2501
|
}
|
|
2504
2502
|
shouldSelect(columns = ["*"]) {
|
|
2505
2503
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -2777,9 +2775,6 @@ const UniqueIds = (Model$1) => {
|
|
|
2777
2775
|
uniqueIds() {
|
|
2778
2776
|
return [];
|
|
2779
2777
|
}
|
|
2780
|
-
newUniqueId() {
|
|
2781
|
-
return null;
|
|
2782
|
-
}
|
|
2783
2778
|
setUniqueIds() {
|
|
2784
2779
|
const uniqueIds = this.uniqueIds();
|
|
2785
2780
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -2801,6 +2796,7 @@ var Paginator = class {
|
|
|
2801
2796
|
options = {};
|
|
2802
2797
|
static setFormatter(formatter) {
|
|
2803
2798
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
2799
|
+
if (!formatter) return;
|
|
2804
2800
|
this.formatter = formatter;
|
|
2805
2801
|
}
|
|
2806
2802
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -2889,8 +2885,10 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2889
2885
|
asProxy() {
|
|
2890
2886
|
return new Proxy(this, {
|
|
2891
2887
|
get: function(target, prop) {
|
|
2888
|
+
var _target$connector$cli;
|
|
2892
2889
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2893
2890
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2891
|
+
const skipReturning = !!((_target$connector$cli = target.connector.client.config) === null || _target$connector$cli === void 0 || (_target$connector$cli = _target$connector$cli.client) === null || _target$connector$cli === void 0 ? void 0 : _target$connector$cli.includes("mysql")) && prop === "returning";
|
|
2894
2892
|
if ([
|
|
2895
2893
|
"select",
|
|
2896
2894
|
"from",
|
|
@@ -2953,7 +2951,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2953
2951
|
"clearWhere",
|
|
2954
2952
|
"clearHaving",
|
|
2955
2953
|
"clearGroup"
|
|
2956
|
-
].includes(prop)) return (...args) => {
|
|
2954
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2957
2955
|
target.connector[prop](...args);
|
|
2958
2956
|
return target.asProxy();
|
|
2959
2957
|
};
|
|
@@ -3010,7 +3008,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
3010
3008
|
} while (countResults === count);
|
|
3011
3009
|
return true;
|
|
3012
3010
|
}
|
|
3013
|
-
async paginate(page = 1, perPage = 15) {
|
|
3011
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
3014
3012
|
const total = await this.clone().clearOrder().count("*");
|
|
3015
3013
|
let results;
|
|
3016
3014
|
if (total > 0) {
|
|
@@ -3249,14 +3247,15 @@ var arquebus_default = arquebus;
|
|
|
3249
3247
|
|
|
3250
3248
|
//#endregion
|
|
3251
3249
|
//#region src/model.ts
|
|
3252
|
-
const
|
|
3250
|
+
const ModelClass = class {};
|
|
3251
|
+
const BaseModel = compose(ModelClass, has_attributes_default, hides_attributes_default, has_relations_default, has_timestamps_default, has_hooks_default, has_global_scopes_default, unique_ids_default);
|
|
3253
3252
|
var Model = class Model extends BaseModel {
|
|
3254
|
-
primaryKey = "id";
|
|
3255
3253
|
builder = null;
|
|
3256
3254
|
table = null;
|
|
3257
3255
|
keyType = "int";
|
|
3258
3256
|
incrementing = true;
|
|
3259
3257
|
withCount = [];
|
|
3258
|
+
primaryKey = "id";
|
|
3260
3259
|
perPage = 15;
|
|
3261
3260
|
static globalScopes = {};
|
|
3262
3261
|
static pluginInitializers = {};
|
|
@@ -3266,6 +3265,7 @@ var Model = class Model extends BaseModel {
|
|
|
3266
3265
|
eagerLoad = {};
|
|
3267
3266
|
exists = false;
|
|
3268
3267
|
with = [];
|
|
3268
|
+
name;
|
|
3269
3269
|
trx = null;
|
|
3270
3270
|
constructor(attributes = {}) {
|
|
3271
3271
|
super();
|
|
@@ -4037,8 +4037,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
4037
4037
|
const results = await this.take(1).get(columns);
|
|
4038
4038
|
return results.count() > 0 ? results.first() : null;
|
|
4039
4039
|
}
|
|
4040
|
-
async firstOrFail(columns
|
|
4041
|
-
const model = await this.first(columns);
|
|
4040
|
+
async firstOrFail(...columns) {
|
|
4041
|
+
const model = await this.first(...columns);
|
|
4042
4042
|
if (model !== null) return model;
|
|
4043
4043
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
4044
4044
|
}
|
|
@@ -4214,7 +4214,9 @@ var Builder = class Builder extends Inference {
|
|
|
4214
4214
|
}
|
|
4215
4215
|
asProxy() {
|
|
4216
4216
|
return new Proxy(this, { get(target, prop) {
|
|
4217
|
+
var _target$query$connect;
|
|
4217
4218
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4219
|
+
const skipReturning = !!((_target$query$connect = target.query.connector) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client.config) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client) === null || _target$query$connect === void 0 ? void 0 : _target$query$connect.includes("mysql")) && prop === "returning";
|
|
4218
4220
|
if ([
|
|
4219
4221
|
"select",
|
|
4220
4222
|
"from",
|
|
@@ -4277,7 +4279,7 @@ var Builder = class Builder extends Inference {
|
|
|
4277
4279
|
"clearWhere",
|
|
4278
4280
|
"clearHaving",
|
|
4279
4281
|
"clearGroup"
|
|
4280
|
-
].includes(prop)) return (...args) => {
|
|
4282
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
4281
4283
|
target.query[prop](...args);
|
|
4282
4284
|
return target.asProxy();
|
|
4283
4285
|
};
|
|
@@ -5089,13 +5091,13 @@ var Migrator = class {
|
|
|
5089
5091
|
async runUp(file, batch, _pretend) {
|
|
5090
5092
|
const migration = await this.resolvePath(file);
|
|
5091
5093
|
const name$1 = this.getMigrationName(file);
|
|
5092
|
-
await
|
|
5094
|
+
await __h3ravel_shared.TaskManager.taskRunner(name$1, () => this.runMigration(migration, "up"));
|
|
5093
5095
|
await this.repository.log(name$1, batch);
|
|
5094
5096
|
}
|
|
5095
5097
|
async runDown(file, migration, _pretend) {
|
|
5096
5098
|
const instance = await this.resolvePath(file);
|
|
5097
5099
|
const name$1 = this.getMigrationName(file);
|
|
5098
|
-
await
|
|
5100
|
+
await __h3ravel_shared.TaskManager.taskRunner(name$1, () => this.runMigration(instance, "down"));
|
|
5099
5101
|
await this.repository.delete(migration);
|
|
5100
5102
|
}
|
|
5101
5103
|
async rollback(paths = [], options = {}) {
|
|
@@ -5146,7 +5148,7 @@ var Migrator = class {
|
|
|
5146
5148
|
const inspector = SchemaInspector.inspect(connection);
|
|
5147
5149
|
await connection.raw("SET foreign_key_checks = 0");
|
|
5148
5150
|
/** Drop all existing tables */
|
|
5149
|
-
for (const table of await inspector.tables())
|
|
5151
|
+
for (const table of await inspector.tables()) await __h3ravel_shared.TaskManager.taskRunner(`Dropping ${__h3ravel_shared.Logger.parse([[table, "grey"]], "", false)} table`, () => connection.schema.dropTableIfExists(table));
|
|
5150
5152
|
await connection.raw("SET foreign_key_checks = 1");
|
|
5151
5153
|
/** Create the migration repository */
|
|
5152
5154
|
await this.repository.createRepository();
|
|
@@ -5227,17 +5229,6 @@ var Migrator = class {
|
|
|
5227
5229
|
write(...args) {
|
|
5228
5230
|
if (this.output) console.log(...args);
|
|
5229
5231
|
}
|
|
5230
|
-
async taskRunner(description$1, task) {
|
|
5231
|
-
const startTime = process.hrtime();
|
|
5232
|
-
let result = false;
|
|
5233
|
-
try {
|
|
5234
|
-
result = await Promise.all([(task || (() => true))()].flat());
|
|
5235
|
-
} finally {
|
|
5236
|
-
const endTime = process.hrtime(startTime);
|
|
5237
|
-
const duration = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
5238
|
-
__h3ravel_shared.Logger.twoColumnLog(__h3ravel_shared.Logger.parse([[description$1, "green"]], "", false), [__h3ravel_shared.Logger.parse([[`${Math.floor(duration)}ms`, "gray"]], "", false), __h3ravel_shared.Logger.parse([[result !== false ? "✔" : "✘", result !== false ? "green" : "red"]], "", false)].join(" "));
|
|
5239
|
-
}
|
|
5240
|
-
}
|
|
5241
5232
|
};
|
|
5242
5233
|
var migrator_default = Migrator;
|
|
5243
5234
|
|
|
@@ -5413,10 +5404,10 @@ var MigrationCreator = class {
|
|
|
5413
5404
|
* @returns
|
|
5414
5405
|
*/
|
|
5415
5406
|
async create(name$1, dir, table, create = false) {
|
|
5416
|
-
const stub = this.getStub(table, create);
|
|
5407
|
+
const stub = await this.getStub(table, create);
|
|
5417
5408
|
const filePath = this.getPath(name$1, dir);
|
|
5418
5409
|
await this.ensureDirectoryExists(path.default.dirname(filePath));
|
|
5419
|
-
await node_fs_promises.
|
|
5410
|
+
await (0, node_fs_promises.writeFile)(filePath, this.populateStub(stub, table));
|
|
5420
5411
|
await this.firePostCreateHooks(table, filePath);
|
|
5421
5412
|
return filePath;
|
|
5422
5413
|
}
|
|
@@ -5427,29 +5418,29 @@ var MigrationCreator = class {
|
|
|
5427
5418
|
* @param callback
|
|
5428
5419
|
*/
|
|
5429
5420
|
async publish(dir, callback) {
|
|
5430
|
-
const migrationFiles = await node_fs_promises.
|
|
5421
|
+
const migrationFiles = await (0, node_fs_promises.readdir)(this.customStubPath ?? "");
|
|
5431
5422
|
await this.ensureDirectoryExists(dir);
|
|
5432
5423
|
for (const migrationFile of migrationFiles) {
|
|
5433
5424
|
const sourceFilePath = path.default.join(this.customStubPath ?? "", migrationFile);
|
|
5434
5425
|
const destinationFilePath = path.default.join(dir, migrationFile);
|
|
5435
|
-
await node_fs_promises.
|
|
5426
|
+
await (0, node_fs_promises.copyFile)(sourceFilePath, destinationFilePath);
|
|
5436
5427
|
if (callback) callback(migrationFile, sourceFilePath, destinationFilePath);
|
|
5437
5428
|
}
|
|
5438
5429
|
}
|
|
5439
|
-
getStub(table, create = false) {
|
|
5430
|
+
async getStub(table, create = false) {
|
|
5440
5431
|
let stub;
|
|
5441
5432
|
if (!table) {
|
|
5442
5433
|
const customPath = path.default.join(this.customStubPath ?? "", `migration-${this.type}.stub`);
|
|
5443
5434
|
console.log("\n", customPath, "---");
|
|
5444
|
-
stub =
|
|
5435
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
|
|
5445
5436
|
} else if (create) {
|
|
5446
5437
|
const customPath = path.default.join(this.customStubPath ?? "", `migration.create-${this.type}.stub`);
|
|
5447
|
-
stub =
|
|
5438
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.create-${this.type}.stub`);
|
|
5448
5439
|
} else {
|
|
5449
5440
|
const customPath = path.default.join(this.customStubPath ?? "", `migration.update-${this.type}.stub`);
|
|
5450
|
-
stub =
|
|
5441
|
+
stub = await __h3ravel_shared.FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.update-${this.type}.stub`);
|
|
5451
5442
|
}
|
|
5452
|
-
return (0,
|
|
5443
|
+
return await (0, node_fs_promises.readFile)(stub, "utf-8");
|
|
5453
5444
|
}
|
|
5454
5445
|
populateStub(stub, table) {
|
|
5455
5446
|
if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
@@ -5469,7 +5460,7 @@ var MigrationCreator = class {
|
|
|
5469
5460
|
this.postCreate.push(callback);
|
|
5470
5461
|
}
|
|
5471
5462
|
async ensureDirectoryExists(dir) {
|
|
5472
|
-
await node_fs_promises.
|
|
5463
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
5473
5464
|
}
|
|
5474
5465
|
stubPath(stub = "") {
|
|
5475
5466
|
const __dirname$1 = this.getDirname({});
|
|
@@ -5485,7 +5476,7 @@ var MigrationCreator = class {
|
|
|
5485
5476
|
//#endregion
|
|
5486
5477
|
//#region package.json
|
|
5487
5478
|
var name = "@h3ravel/arquebus";
|
|
5488
|
-
var version = "0.
|
|
5479
|
+
var version = "0.5.0";
|
|
5489
5480
|
var packageManager = "pnpm@10.14.0";
|
|
5490
5481
|
var description = "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.";
|
|
5491
5482
|
var homepage = "https://h3ravel.toneflix.net/arquebus";
|
|
@@ -5603,23 +5594,23 @@ var scripts = {
|
|
|
5603
5594
|
"test:postgres": "cross-env DB=postgres vitest --project node",
|
|
5604
5595
|
"test:sqlite": "cross-env DB=sqlite vitest --project node",
|
|
5605
5596
|
"test:browser": "vitest --project browser",
|
|
5606
|
-
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version
|
|
5597
|
+
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version\" && pnpm version patch && pnpm publish --tag latest"
|
|
5607
5598
|
};
|
|
5608
5599
|
var husky = { "hooks": { "pre-commit": "lint-staged" } };
|
|
5609
5600
|
var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
|
|
5610
5601
|
var dependencies = {
|
|
5611
|
-
"@h3ravel/shared": "^0.
|
|
5612
|
-
"chalk": "^5.6.
|
|
5602
|
+
"@h3ravel/shared": "^0.20.1",
|
|
5603
|
+
"chalk": "^5.6.2",
|
|
5613
5604
|
"collect.js": "^4.36.1",
|
|
5614
|
-
"commander": "^14.0.
|
|
5605
|
+
"commander": "^14.0.1",
|
|
5615
5606
|
"cross-env": "^10.0.0",
|
|
5616
|
-
"dayjs": "^1.11.
|
|
5617
|
-
"dotenv": "^17.2.
|
|
5607
|
+
"dayjs": "^1.11.18",
|
|
5608
|
+
"dotenv": "^17.2.2",
|
|
5618
5609
|
"escalade": "^3.2.0",
|
|
5619
5610
|
"husky": "^9.1.7",
|
|
5620
5611
|
"knex": "^3.1.0",
|
|
5621
|
-
"lint-staged": "^16.
|
|
5622
|
-
"mysql2": "^3.
|
|
5612
|
+
"lint-staged": "^16.2.0",
|
|
5613
|
+
"mysql2": "^3.15.0",
|
|
5623
5614
|
"pg": "^8.16.3",
|
|
5624
5615
|
"pluralize": "^8.0.0",
|
|
5625
5616
|
"prettier": "^3.6.2",
|
|
@@ -5628,21 +5619,21 @@ var dependencies = {
|
|
|
5628
5619
|
"tedious": "^19.0.0"
|
|
5629
5620
|
};
|
|
5630
5621
|
var devDependencies = {
|
|
5631
|
-
"@eslint/js": "^9.
|
|
5632
|
-
"@types/node": "^24.
|
|
5622
|
+
"@eslint/js": "^9.36.0",
|
|
5623
|
+
"@types/node": "^24.5.2",
|
|
5633
5624
|
"@types/pluralize": "^0.0.33",
|
|
5634
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
5635
|
-
"@typescript-eslint/parser": "^8.
|
|
5625
|
+
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
5626
|
+
"@typescript-eslint/parser": "^8.44.0",
|
|
5636
5627
|
"@vitest/coverage-v8": "^3.2.4",
|
|
5637
|
-
"eslint": "^9.
|
|
5628
|
+
"eslint": "^9.36.0",
|
|
5638
5629
|
"jsdom": "^26.1.0",
|
|
5639
5630
|
"sqlite3": "5.1.7",
|
|
5640
|
-
"terser": "^5.
|
|
5631
|
+
"terser": "^5.44.0",
|
|
5641
5632
|
"ts-node": "^10.9.2",
|
|
5642
5633
|
"tsdown": "^0.15.4",
|
|
5643
|
-
"tsx": "^4.20.
|
|
5634
|
+
"tsx": "^4.20.5",
|
|
5644
5635
|
"typescript": "^5.9.2",
|
|
5645
|
-
"typescript-eslint": "^8.
|
|
5636
|
+
"typescript-eslint": "^8.44.0",
|
|
5646
5637
|
"vite-tsconfig-paths": "^5.1.4",
|
|
5647
5638
|
"vitest": "^3.2.4"
|
|
5648
5639
|
};
|
package/bin/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import { access } from "fs/promises";
|
|
|
5
5
|
import escalade from "escalade/sync";
|
|
6
6
|
import path from "path";
|
|
7
7
|
import resolveFrom from "resolve-from";
|
|
8
|
-
import fs, { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
9
|
-
import { Logger } from "@h3ravel/shared";
|
|
8
|
+
import fs, { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
9
|
+
import { FileSystem, Logger, TaskManager } from "@h3ravel/shared";
|
|
10
10
|
import { assign, camel, diff, flat, get, isArray, isEmpty, isEqual, isString, omit, pick, set, snake, trim } from "radashi";
|
|
11
11
|
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
12
12
|
import dayjs from "dayjs";
|
|
@@ -14,7 +14,6 @@ import collect, { Collection, collect as collect$1 } from "collect.js";
|
|
|
14
14
|
import Knex from "knex";
|
|
15
15
|
import { existsSync } from "fs";
|
|
16
16
|
import pluralize from "pluralize";
|
|
17
|
-
import { existsSync as existsSync$1, readFileSync } from "node:fs";
|
|
18
17
|
import { dirname } from "node:path";
|
|
19
18
|
import { fileURLToPath } from "node:url";
|
|
20
19
|
import chalk from "chalk";
|
|
@@ -2422,8 +2421,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
2422
2421
|
const results = await this.take(1).get(columns);
|
|
2423
2422
|
return results.count() > 0 ? results.first() : null;
|
|
2424
2423
|
}
|
|
2425
|
-
async firstOrFail(columns
|
|
2426
|
-
const model = await this.first(columns);
|
|
2424
|
+
async firstOrFail(...columns) {
|
|
2425
|
+
const model = await this.first(...columns);
|
|
2427
2426
|
if (model) return model;
|
|
2428
2427
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2429
2428
|
}
|
|
@@ -2462,7 +2461,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
2462
2461
|
}
|
|
2463
2462
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
2464
2463
|
this.query.addSelect(this.shouldSelect(columns));
|
|
2465
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
2464
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
2466
2465
|
}
|
|
2467
2466
|
shouldSelect(columns = ["*"]) {
|
|
2468
2467
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -2740,9 +2739,6 @@ const UniqueIds = (Model$1) => {
|
|
|
2740
2739
|
uniqueIds() {
|
|
2741
2740
|
return [];
|
|
2742
2741
|
}
|
|
2743
|
-
newUniqueId() {
|
|
2744
|
-
return null;
|
|
2745
|
-
}
|
|
2746
2742
|
setUniqueIds() {
|
|
2747
2743
|
const uniqueIds = this.uniqueIds();
|
|
2748
2744
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -2764,6 +2760,7 @@ var Paginator = class {
|
|
|
2764
2760
|
options = {};
|
|
2765
2761
|
static setFormatter(formatter) {
|
|
2766
2762
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
2763
|
+
if (!formatter) return;
|
|
2767
2764
|
this.formatter = formatter;
|
|
2768
2765
|
}
|
|
2769
2766
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -2852,8 +2849,10 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2852
2849
|
asProxy() {
|
|
2853
2850
|
return new Proxy(this, {
|
|
2854
2851
|
get: function(target, prop) {
|
|
2852
|
+
var _target$connector$cli;
|
|
2855
2853
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2856
2854
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
2855
|
+
const skipReturning = !!((_target$connector$cli = target.connector.client.config) === null || _target$connector$cli === void 0 || (_target$connector$cli = _target$connector$cli.client) === null || _target$connector$cli === void 0 ? void 0 : _target$connector$cli.includes("mysql")) && prop === "returning";
|
|
2857
2856
|
if ([
|
|
2858
2857
|
"select",
|
|
2859
2858
|
"from",
|
|
@@ -2916,7 +2915,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2916
2915
|
"clearWhere",
|
|
2917
2916
|
"clearHaving",
|
|
2918
2917
|
"clearGroup"
|
|
2919
|
-
].includes(prop)) return (...args) => {
|
|
2918
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2920
2919
|
target.connector[prop](...args);
|
|
2921
2920
|
return target.asProxy();
|
|
2922
2921
|
};
|
|
@@ -2973,7 +2972,7 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
|
|
|
2973
2972
|
} while (countResults === count);
|
|
2974
2973
|
return true;
|
|
2975
2974
|
}
|
|
2976
|
-
async paginate(page = 1, perPage = 15) {
|
|
2975
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
2977
2976
|
const total = await this.clone().clearOrder().count("*");
|
|
2978
2977
|
let results;
|
|
2979
2978
|
if (total > 0) {
|
|
@@ -3212,14 +3211,15 @@ var arquebus_default = arquebus;
|
|
|
3212
3211
|
|
|
3213
3212
|
//#endregion
|
|
3214
3213
|
//#region src/model.ts
|
|
3215
|
-
const
|
|
3214
|
+
const ModelClass = class {};
|
|
3215
|
+
const BaseModel = compose(ModelClass, has_attributes_default, hides_attributes_default, has_relations_default, has_timestamps_default, has_hooks_default, has_global_scopes_default, unique_ids_default);
|
|
3216
3216
|
var Model = class Model extends BaseModel {
|
|
3217
|
-
primaryKey = "id";
|
|
3218
3217
|
builder = null;
|
|
3219
3218
|
table = null;
|
|
3220
3219
|
keyType = "int";
|
|
3221
3220
|
incrementing = true;
|
|
3222
3221
|
withCount = [];
|
|
3222
|
+
primaryKey = "id";
|
|
3223
3223
|
perPage = 15;
|
|
3224
3224
|
static globalScopes = {};
|
|
3225
3225
|
static pluginInitializers = {};
|
|
@@ -3229,6 +3229,7 @@ var Model = class Model extends BaseModel {
|
|
|
3229
3229
|
eagerLoad = {};
|
|
3230
3230
|
exists = false;
|
|
3231
3231
|
with = [];
|
|
3232
|
+
name;
|
|
3232
3233
|
trx = null;
|
|
3233
3234
|
constructor(attributes = {}) {
|
|
3234
3235
|
super();
|
|
@@ -4000,8 +4001,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
4000
4001
|
const results = await this.take(1).get(columns);
|
|
4001
4002
|
return results.count() > 0 ? results.first() : null;
|
|
4002
4003
|
}
|
|
4003
|
-
async firstOrFail(columns
|
|
4004
|
-
const model = await this.first(columns);
|
|
4004
|
+
async firstOrFail(...columns) {
|
|
4005
|
+
const model = await this.first(...columns);
|
|
4005
4006
|
if (model !== null) return model;
|
|
4006
4007
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
4007
4008
|
}
|
|
@@ -4177,7 +4178,9 @@ var Builder = class Builder extends Inference {
|
|
|
4177
4178
|
}
|
|
4178
4179
|
asProxy() {
|
|
4179
4180
|
return new Proxy(this, { get(target, prop) {
|
|
4181
|
+
var _target$query$connect;
|
|
4180
4182
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
4183
|
+
const skipReturning = !!((_target$query$connect = target.query.connector) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client.config) === null || _target$query$connect === void 0 || (_target$query$connect = _target$query$connect.client) === null || _target$query$connect === void 0 ? void 0 : _target$query$connect.includes("mysql")) && prop === "returning";
|
|
4181
4184
|
if ([
|
|
4182
4185
|
"select",
|
|
4183
4186
|
"from",
|
|
@@ -4240,7 +4243,7 @@ var Builder = class Builder extends Inference {
|
|
|
4240
4243
|
"clearWhere",
|
|
4241
4244
|
"clearHaving",
|
|
4242
4245
|
"clearGroup"
|
|
4243
|
-
].includes(prop)) return (...args) => {
|
|
4246
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
4244
4247
|
target.query[prop](...args);
|
|
4245
4248
|
return target.asProxy();
|
|
4246
4249
|
};
|
|
@@ -5052,13 +5055,13 @@ var Migrator = class {
|
|
|
5052
5055
|
async runUp(file, batch, _pretend) {
|
|
5053
5056
|
const migration = await this.resolvePath(file);
|
|
5054
5057
|
const name$1 = this.getMigrationName(file);
|
|
5055
|
-
await
|
|
5058
|
+
await TaskManager.taskRunner(name$1, () => this.runMigration(migration, "up"));
|
|
5056
5059
|
await this.repository.log(name$1, batch);
|
|
5057
5060
|
}
|
|
5058
5061
|
async runDown(file, migration, _pretend) {
|
|
5059
5062
|
const instance = await this.resolvePath(file);
|
|
5060
5063
|
const name$1 = this.getMigrationName(file);
|
|
5061
|
-
await
|
|
5064
|
+
await TaskManager.taskRunner(name$1, () => this.runMigration(instance, "down"));
|
|
5062
5065
|
await this.repository.delete(migration);
|
|
5063
5066
|
}
|
|
5064
5067
|
async rollback(paths = [], options = {}) {
|
|
@@ -5109,7 +5112,7 @@ var Migrator = class {
|
|
|
5109
5112
|
const inspector = SchemaInspector.inspect(connection);
|
|
5110
5113
|
await connection.raw("SET foreign_key_checks = 0");
|
|
5111
5114
|
/** Drop all existing tables */
|
|
5112
|
-
for (const table of await inspector.tables())
|
|
5115
|
+
for (const table of await inspector.tables()) await TaskManager.taskRunner(`Dropping ${Logger.parse([[table, "grey"]], "", false)} table`, () => connection.schema.dropTableIfExists(table));
|
|
5113
5116
|
await connection.raw("SET foreign_key_checks = 1");
|
|
5114
5117
|
/** Create the migration repository */
|
|
5115
5118
|
await this.repository.createRepository();
|
|
@@ -5190,17 +5193,6 @@ var Migrator = class {
|
|
|
5190
5193
|
write(...args) {
|
|
5191
5194
|
if (this.output) console.log(...args);
|
|
5192
5195
|
}
|
|
5193
|
-
async taskRunner(description$1, task) {
|
|
5194
|
-
const startTime = process.hrtime();
|
|
5195
|
-
let result = false;
|
|
5196
|
-
try {
|
|
5197
|
-
result = await Promise.all([(task || (() => true))()].flat());
|
|
5198
|
-
} finally {
|
|
5199
|
-
const endTime = process.hrtime(startTime);
|
|
5200
|
-
const duration = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
5201
|
-
Logger.twoColumnLog(Logger.parse([[description$1, "green"]], "", false), [Logger.parse([[`${Math.floor(duration)}ms`, "gray"]], "", false), Logger.parse([[result !== false ? "✔" : "✘", result !== false ? "green" : "red"]], "", false)].join(" "));
|
|
5202
|
-
}
|
|
5203
|
-
}
|
|
5204
5196
|
};
|
|
5205
5197
|
var migrator_default = Migrator;
|
|
5206
5198
|
|
|
@@ -5376,10 +5368,10 @@ var MigrationCreator = class {
|
|
|
5376
5368
|
* @returns
|
|
5377
5369
|
*/
|
|
5378
5370
|
async create(name$1, dir, table, create = false) {
|
|
5379
|
-
const stub = this.getStub(table, create);
|
|
5371
|
+
const stub = await this.getStub(table, create);
|
|
5380
5372
|
const filePath = this.getPath(name$1, dir);
|
|
5381
5373
|
await this.ensureDirectoryExists(path.dirname(filePath));
|
|
5382
|
-
await
|
|
5374
|
+
await writeFile(filePath, this.populateStub(stub, table));
|
|
5383
5375
|
await this.firePostCreateHooks(table, filePath);
|
|
5384
5376
|
return filePath;
|
|
5385
5377
|
}
|
|
@@ -5390,29 +5382,29 @@ var MigrationCreator = class {
|
|
|
5390
5382
|
* @param callback
|
|
5391
5383
|
*/
|
|
5392
5384
|
async publish(dir, callback) {
|
|
5393
|
-
const migrationFiles = await
|
|
5385
|
+
const migrationFiles = await readdir(this.customStubPath ?? "");
|
|
5394
5386
|
await this.ensureDirectoryExists(dir);
|
|
5395
5387
|
for (const migrationFile of migrationFiles) {
|
|
5396
5388
|
const sourceFilePath = path.join(this.customStubPath ?? "", migrationFile);
|
|
5397
5389
|
const destinationFilePath = path.join(dir, migrationFile);
|
|
5398
|
-
await
|
|
5390
|
+
await copyFile(sourceFilePath, destinationFilePath);
|
|
5399
5391
|
if (callback) callback(migrationFile, sourceFilePath, destinationFilePath);
|
|
5400
5392
|
}
|
|
5401
5393
|
}
|
|
5402
|
-
getStub(table, create = false) {
|
|
5394
|
+
async getStub(table, create = false) {
|
|
5403
5395
|
let stub;
|
|
5404
5396
|
if (!table) {
|
|
5405
5397
|
const customPath = path.join(this.customStubPath ?? "", `migration-${this.type}.stub`);
|
|
5406
5398
|
console.log("\n", customPath, "---");
|
|
5407
|
-
stub =
|
|
5399
|
+
stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration-${this.type}.stub`);
|
|
5408
5400
|
} else if (create) {
|
|
5409
5401
|
const customPath = path.join(this.customStubPath ?? "", `migration.create-${this.type}.stub`);
|
|
5410
|
-
stub =
|
|
5402
|
+
stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.create-${this.type}.stub`);
|
|
5411
5403
|
} else {
|
|
5412
5404
|
const customPath = path.join(this.customStubPath ?? "", `migration.update-${this.type}.stub`);
|
|
5413
|
-
stub =
|
|
5405
|
+
stub = await FileSystem.fileExists(customPath) ? customPath : this.stubPath(`/migration.update-${this.type}.stub`);
|
|
5414
5406
|
}
|
|
5415
|
-
return
|
|
5407
|
+
return await readFile(stub, "utf-8");
|
|
5416
5408
|
}
|
|
5417
5409
|
populateStub(stub, table) {
|
|
5418
5410
|
if (table !== null) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
@@ -5432,7 +5424,7 @@ var MigrationCreator = class {
|
|
|
5432
5424
|
this.postCreate.push(callback);
|
|
5433
5425
|
}
|
|
5434
5426
|
async ensureDirectoryExists(dir) {
|
|
5435
|
-
await
|
|
5427
|
+
await mkdir(dir, { recursive: true });
|
|
5436
5428
|
}
|
|
5437
5429
|
stubPath(stub = "") {
|
|
5438
5430
|
const __dirname$1 = this.getDirname(import.meta);
|
|
@@ -5448,7 +5440,7 @@ var MigrationCreator = class {
|
|
|
5448
5440
|
//#endregion
|
|
5449
5441
|
//#region package.json
|
|
5450
5442
|
var name = "@h3ravel/arquebus";
|
|
5451
|
-
var version = "0.
|
|
5443
|
+
var version = "0.5.0";
|
|
5452
5444
|
var packageManager = "pnpm@10.14.0";
|
|
5453
5445
|
var description = "Arquebus ORM is a Beautiful, expressive ORM inspired by Laravel's Eloquent, designed for TypeScript applications and for the H3ravel Framework.";
|
|
5454
5446
|
var homepage = "https://h3ravel.toneflix.net/arquebus";
|
|
@@ -5566,23 +5558,23 @@ var scripts = {
|
|
|
5566
5558
|
"test:postgres": "cross-env DB=postgres vitest --project node",
|
|
5567
5559
|
"test:sqlite": "cross-env DB=sqlite vitest --project node",
|
|
5568
5560
|
"test:browser": "vitest --project browser",
|
|
5569
|
-
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version
|
|
5561
|
+
"release:patch": "pnpm build && git add . && git commit -m \"version: bump version\" && pnpm version patch && pnpm publish --tag latest"
|
|
5570
5562
|
};
|
|
5571
5563
|
var husky = { "hooks": { "pre-commit": "lint-staged" } };
|
|
5572
5564
|
var lint_staged = { "*.{js,json}": ["prettier --write", "git add"] };
|
|
5573
5565
|
var dependencies = {
|
|
5574
|
-
"@h3ravel/shared": "^0.
|
|
5575
|
-
"chalk": "^5.6.
|
|
5566
|
+
"@h3ravel/shared": "^0.20.1",
|
|
5567
|
+
"chalk": "^5.6.2",
|
|
5576
5568
|
"collect.js": "^4.36.1",
|
|
5577
|
-
"commander": "^14.0.
|
|
5569
|
+
"commander": "^14.0.1",
|
|
5578
5570
|
"cross-env": "^10.0.0",
|
|
5579
|
-
"dayjs": "^1.11.
|
|
5580
|
-
"dotenv": "^17.2.
|
|
5571
|
+
"dayjs": "^1.11.18",
|
|
5572
|
+
"dotenv": "^17.2.2",
|
|
5581
5573
|
"escalade": "^3.2.0",
|
|
5582
5574
|
"husky": "^9.1.7",
|
|
5583
5575
|
"knex": "^3.1.0",
|
|
5584
|
-
"lint-staged": "^16.
|
|
5585
|
-
"mysql2": "^3.
|
|
5576
|
+
"lint-staged": "^16.2.0",
|
|
5577
|
+
"mysql2": "^3.15.0",
|
|
5586
5578
|
"pg": "^8.16.3",
|
|
5587
5579
|
"pluralize": "^8.0.0",
|
|
5588
5580
|
"prettier": "^3.6.2",
|
|
@@ -5591,21 +5583,21 @@ var dependencies = {
|
|
|
5591
5583
|
"tedious": "^19.0.0"
|
|
5592
5584
|
};
|
|
5593
5585
|
var devDependencies = {
|
|
5594
|
-
"@eslint/js": "^9.
|
|
5595
|
-
"@types/node": "^24.
|
|
5586
|
+
"@eslint/js": "^9.36.0",
|
|
5587
|
+
"@types/node": "^24.5.2",
|
|
5596
5588
|
"@types/pluralize": "^0.0.33",
|
|
5597
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
5598
|
-
"@typescript-eslint/parser": "^8.
|
|
5589
|
+
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
5590
|
+
"@typescript-eslint/parser": "^8.44.0",
|
|
5599
5591
|
"@vitest/coverage-v8": "^3.2.4",
|
|
5600
|
-
"eslint": "^9.
|
|
5592
|
+
"eslint": "^9.36.0",
|
|
5601
5593
|
"jsdom": "^26.1.0",
|
|
5602
5594
|
"sqlite3": "5.1.7",
|
|
5603
|
-
"terser": "^5.
|
|
5595
|
+
"terser": "^5.44.0",
|
|
5604
5596
|
"ts-node": "^10.9.2",
|
|
5605
5597
|
"tsdown": "^0.15.4",
|
|
5606
|
-
"tsx": "^4.20.
|
|
5598
|
+
"tsx": "^4.20.5",
|
|
5607
5599
|
"typescript": "^5.9.2",
|
|
5608
|
-
"typescript-eslint": "^8.
|
|
5600
|
+
"typescript-eslint": "^8.44.0",
|
|
5609
5601
|
"vite-tsconfig-paths": "^5.1.4",
|
|
5610
5602
|
"vitest": "^3.2.4"
|
|
5611
5603
|
};
|