@h3ravel/arquebus 0.4.1 → 0.6.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/README.md +20 -1
- package/bin/index.cjs +225 -171
- package/bin/index.js +208 -122
- package/bin/seeders-8GJzfIIN.js +3 -0
- package/bin/seeders-ByeSoCAQ.cjs +131 -0
- package/bin/seeders-CltigymO.js +79 -0
- package/bin/seeders-_xJ6VGVS.cjs +3 -0
- package/dist/browser/index.cjs +9 -9
- package/dist/browser/index.d.cts +3655 -183
- package/dist/browser/index.d.ts +3655 -183
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +270 -135
- package/dist/index.d.cts +3797 -294
- package/dist/index.d.ts +3797 -294
- package/dist/index.js +263 -133
- package/dist/inspector/index.cjs +122 -46
- package/dist/inspector/index.js +119 -46
- package/dist/migrations/index.cjs +171 -151
- package/dist/migrations/index.d.cts +3510 -27
- package/dist/migrations/index.d.ts +3510 -27
- package/dist/migrations/index.js +177 -150
- package/dist/migrations/stubs/migration-js.stub +1 -1
- package/dist/migrations/stubs/migration-ts.stub +1 -1
- package/dist/migrations/stubs/migration.create-js.stub +5 -5
- package/dist/migrations/stubs/migration.create-ts.stub +5 -5
- package/dist/migrations/stubs/migration.update-js.stub +2 -2
- package/dist/migrations/stubs/migration.update-ts.stub +3 -3
- package/dist/seeders/index.cjs +141 -0
- package/dist/seeders/index.d.cts +4766 -0
- package/dist/seeders/index.d.ts +4766 -0
- package/dist/seeders/index.js +118 -0
- package/dist/seeders/index.ts +3 -0
- package/dist/seeders/runner.ts +102 -0
- package/dist/seeders/seeder-creator.ts +42 -0
- package/dist/seeders/seeder.ts +10 -0
- package/dist/stubs/seeder-js.stub +13 -0
- package/dist/stubs/seeder-ts.stub +9 -0
- package/package.json +15 -4
- package/types/builder.ts +158 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -36
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +223 -186
- package/types/query-methods.ts +160 -104
- package/types/utils.ts +64 -55
package/dist/index.js
CHANGED
|
@@ -6,12 +6,14 @@ import collect$1, { Collection, collect } from "collect.js";
|
|
|
6
6
|
import Knex$1 from "knex";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { existsSync } from "fs";
|
|
9
|
-
import pluralize from "pluralize";
|
|
10
|
-
import { Logger, TaskManager } from "@h3ravel/shared";
|
|
11
|
-
import fs from "node:fs/promises";
|
|
12
9
|
import { access } from "fs/promises";
|
|
13
10
|
import escalade from "escalade/sync";
|
|
14
11
|
import resolveFrom from "resolve-from";
|
|
12
|
+
import pluralize from "pluralize";
|
|
13
|
+
import { Logger, TaskManager } from "@h3ravel/shared";
|
|
14
|
+
import fs, { access as access$1, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
15
|
+
import { dirname } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
15
17
|
|
|
16
18
|
//#region rolldown:runtime
|
|
17
19
|
var __defProp = Object.defineProperty;
|
|
@@ -97,7 +99,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
97
99
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
98
100
|
/**
|
|
99
101
|
* Compose function that merges multiple classes and mixins
|
|
100
|
-
*
|
|
102
|
+
*
|
|
101
103
|
* @example
|
|
102
104
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
103
105
|
* return class extends Base {
|
|
@@ -134,10 +136,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
134
136
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
135
137
|
* console.log(user.pluginMethod()) // "plugin"
|
|
136
138
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
137
|
-
*
|
|
138
|
-
* @param Base
|
|
139
|
-
* @param mixins
|
|
140
|
-
* @returns
|
|
139
|
+
*
|
|
140
|
+
* @param Base
|
|
141
|
+
* @param mixins
|
|
142
|
+
* @returns
|
|
141
143
|
*/
|
|
142
144
|
function compose$1(Base, ...mixins) {
|
|
143
145
|
/**
|
|
@@ -198,10 +200,10 @@ const getAttrName = (attrMethod) => {
|
|
|
198
200
|
};
|
|
199
201
|
/**
|
|
200
202
|
* Tap into a model a collection instance
|
|
201
|
-
*
|
|
202
|
-
* @param instance
|
|
203
|
-
* @param callback
|
|
204
|
-
* @returns
|
|
203
|
+
*
|
|
204
|
+
* @param instance
|
|
205
|
+
* @param callback
|
|
206
|
+
* @returns
|
|
205
207
|
*/
|
|
206
208
|
const tap = (instance, callback) => {
|
|
207
209
|
const result = callback(instance);
|
|
@@ -1041,8 +1043,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
1041
1043
|
const results = await this.take(1).get(columns);
|
|
1042
1044
|
return results.count() > 0 ? results.first() : null;
|
|
1043
1045
|
}
|
|
1044
|
-
async firstOrFail(columns
|
|
1045
|
-
const model = await this.first(columns);
|
|
1046
|
+
async firstOrFail(...columns) {
|
|
1047
|
+
const model = await this.first(...columns);
|
|
1046
1048
|
if (model) return model;
|
|
1047
1049
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
1048
1050
|
}
|
|
@@ -1081,7 +1083,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
1081
1083
|
}
|
|
1082
1084
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
1083
1085
|
this.query.addSelect(this.shouldSelect(columns));
|
|
1084
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
1086
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
1085
1087
|
}
|
|
1086
1088
|
shouldSelect(columns = ["*"]) {
|
|
1087
1089
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -1359,9 +1361,6 @@ const UniqueIds = (Model$1) => {
|
|
|
1359
1361
|
uniqueIds() {
|
|
1360
1362
|
return [];
|
|
1361
1363
|
}
|
|
1362
|
-
newUniqueId() {
|
|
1363
|
-
return null;
|
|
1364
|
-
}
|
|
1365
1364
|
setUniqueIds() {
|
|
1366
1365
|
const uniqueIds = this.uniqueIds();
|
|
1367
1366
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -1383,6 +1382,7 @@ var Paginator = class {
|
|
|
1383
1382
|
options = {};
|
|
1384
1383
|
static setFormatter(formatter) {
|
|
1385
1384
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
1385
|
+
if (!formatter) return;
|
|
1386
1386
|
this.formatter = formatter;
|
|
1387
1387
|
}
|
|
1388
1388
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -1471,8 +1471,10 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1471
1471
|
asProxy() {
|
|
1472
1472
|
return new Proxy(this, {
|
|
1473
1473
|
get: function(target, prop) {
|
|
1474
|
+
var _target$connector$cli;
|
|
1474
1475
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
1475
1476
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
1477
|
+
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";
|
|
1476
1478
|
if ([
|
|
1477
1479
|
"select",
|
|
1478
1480
|
"from",
|
|
@@ -1535,7 +1537,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1535
1537
|
"clearWhere",
|
|
1536
1538
|
"clearHaving",
|
|
1537
1539
|
"clearGroup"
|
|
1538
|
-
].includes(prop)) return (...args) => {
|
|
1540
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
1539
1541
|
target.connector[prop](...args);
|
|
1540
1542
|
return target.asProxy();
|
|
1541
1543
|
};
|
|
@@ -1592,7 +1594,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1592
1594
|
} while (countResults === count);
|
|
1593
1595
|
return true;
|
|
1594
1596
|
}
|
|
1595
|
-
async paginate(page = 1, perPage = 15) {
|
|
1597
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
1596
1598
|
const total = await this.clone().clearOrder().count("*");
|
|
1597
1599
|
let results;
|
|
1598
1600
|
if (total > 0) {
|
|
@@ -1656,6 +1658,59 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1656
1658
|
};
|
|
1657
1659
|
var query_builder_default = QueryBuilder;
|
|
1658
1660
|
|
|
1661
|
+
//#endregion
|
|
1662
|
+
//#region src/cli/utils.ts
|
|
1663
|
+
const join = path.join;
|
|
1664
|
+
var Utils = class {
|
|
1665
|
+
/**
|
|
1666
|
+
* Wraps text with chalk
|
|
1667
|
+
*
|
|
1668
|
+
* @param txt
|
|
1669
|
+
* @param color
|
|
1670
|
+
* @returns
|
|
1671
|
+
*/
|
|
1672
|
+
static textFormat(txt, color) {
|
|
1673
|
+
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
1674
|
+
}
|
|
1675
|
+
static findModulePkg(moduleId, cwd) {
|
|
1676
|
+
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
1677
|
+
let packageName = "";
|
|
1678
|
+
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
1679
|
+
packageName += parts.shift();
|
|
1680
|
+
const packageJson = path.join(packageName, "package.json");
|
|
1681
|
+
const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
|
|
1682
|
+
if (!resolved) return;
|
|
1683
|
+
return path.join(path.dirname(resolved), parts.join("/"));
|
|
1684
|
+
}
|
|
1685
|
+
static async getMigrationPaths(cwd, migrator, defaultPath, path$1) {
|
|
1686
|
+
if (path$1) return [join(cwd, path$1)];
|
|
1687
|
+
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Check if file exists
|
|
1691
|
+
*
|
|
1692
|
+
* @param path
|
|
1693
|
+
* @returns
|
|
1694
|
+
*/
|
|
1695
|
+
static async fileExists(path$1) {
|
|
1696
|
+
try {
|
|
1697
|
+
await access(path$1);
|
|
1698
|
+
return true;
|
|
1699
|
+
} catch {
|
|
1700
|
+
return false;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
static findUpConfig(cwd, name, extensions) {
|
|
1704
|
+
return escalade(cwd, (_dir, names) => {
|
|
1705
|
+
for (const ext of extensions) {
|
|
1706
|
+
const filename = `${name}.${ext}`;
|
|
1707
|
+
if (names.includes(filename)) return filename;
|
|
1708
|
+
}
|
|
1709
|
+
return false;
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
|
|
1659
1714
|
//#endregion
|
|
1660
1715
|
//#region src/arquebus.ts
|
|
1661
1716
|
var arquebus = class arquebus {
|
|
@@ -1677,22 +1732,22 @@ var arquebus = class arquebus {
|
|
|
1677
1732
|
return this.instance;
|
|
1678
1733
|
}
|
|
1679
1734
|
/**
|
|
1680
|
-
* Initialize a new database connection
|
|
1681
|
-
*
|
|
1682
|
-
* @returns
|
|
1735
|
+
* Initialize a new database connection
|
|
1736
|
+
*
|
|
1737
|
+
* @returns
|
|
1683
1738
|
*/
|
|
1684
1739
|
static fire(connection = null) {
|
|
1685
1740
|
return this.getInstance().getConnection(connection);
|
|
1686
1741
|
}
|
|
1687
1742
|
/**
|
|
1688
|
-
* Initialize a new database connection
|
|
1689
|
-
*
|
|
1743
|
+
* Initialize a new database connection
|
|
1744
|
+
*
|
|
1690
1745
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
1691
|
-
*
|
|
1746
|
+
*
|
|
1692
1747
|
* @deprecated since version 0.3.0
|
|
1693
1748
|
* @alias fire
|
|
1694
|
-
*
|
|
1695
|
-
* @returns
|
|
1749
|
+
*
|
|
1750
|
+
* @returns
|
|
1696
1751
|
*/
|
|
1697
1752
|
static connection(connection = null) {
|
|
1698
1753
|
return this.fire(connection);
|
|
@@ -1729,11 +1784,12 @@ var arquebus = class arquebus {
|
|
|
1729
1784
|
}
|
|
1730
1785
|
getConnection(name = null) {
|
|
1731
1786
|
name = name || "default";
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
this.
|
|
1787
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
1788
|
+
if (this.manager[resolvedName] === void 0) {
|
|
1789
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
1790
|
+
this.manager[resolvedName] = queryBuilder;
|
|
1735
1791
|
}
|
|
1736
|
-
return this.manager[
|
|
1792
|
+
return this.manager[resolvedName];
|
|
1737
1793
|
}
|
|
1738
1794
|
addConnection(config, name = "default") {
|
|
1739
1795
|
this.connections[name] = {
|
|
@@ -1750,13 +1806,13 @@ var arquebus = class arquebus {
|
|
|
1750
1806
|
}
|
|
1751
1807
|
/**
|
|
1752
1808
|
* Autoload the config file
|
|
1753
|
-
*
|
|
1754
|
-
* @param addConnection
|
|
1809
|
+
*
|
|
1810
|
+
* @param addConnection
|
|
1755
1811
|
* @default true
|
|
1756
|
-
* If set to `false` we will no attempt add the connection, we
|
|
1812
|
+
* If set to `false` we will no attempt add the connection, we
|
|
1757
1813
|
* will just go ahead and return the config
|
|
1758
|
-
*
|
|
1759
|
-
* @returns
|
|
1814
|
+
*
|
|
1815
|
+
* @returns
|
|
1760
1816
|
*/
|
|
1761
1817
|
static async autoLoad(addConnection = true) {
|
|
1762
1818
|
let config;
|
|
@@ -1773,6 +1829,23 @@ var arquebus = class arquebus {
|
|
|
1773
1829
|
if (addConnection) instance.addConnection(config, config.client);
|
|
1774
1830
|
return config;
|
|
1775
1831
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
1832
|
+
const candidateDirs = [
|
|
1833
|
+
process.cwd(),
|
|
1834
|
+
path.join(process.cwd(), "test", "cli"),
|
|
1835
|
+
path.join(process.cwd(), "test")
|
|
1836
|
+
];
|
|
1837
|
+
for (const dir of candidateDirs) {
|
|
1838
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
1839
|
+
"js",
|
|
1840
|
+
"ts",
|
|
1841
|
+
"cjs"
|
|
1842
|
+
]);
|
|
1843
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
1844
|
+
config = (await import(found)).default;
|
|
1845
|
+
if (addConnection) instance.addConnection(config, config.client);
|
|
1846
|
+
return config;
|
|
1847
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
1848
|
+
}
|
|
1776
1849
|
return {};
|
|
1777
1850
|
}
|
|
1778
1851
|
beginTransaction(connection = null) {
|
|
@@ -1831,14 +1904,15 @@ var arquebus_default = arquebus;
|
|
|
1831
1904
|
|
|
1832
1905
|
//#endregion
|
|
1833
1906
|
//#region src/model.ts
|
|
1834
|
-
const
|
|
1907
|
+
const ModelClass = class {};
|
|
1908
|
+
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);
|
|
1835
1909
|
var Model = class Model extends BaseModel {
|
|
1836
|
-
primaryKey = "id";
|
|
1837
1910
|
builder = null;
|
|
1838
1911
|
table = null;
|
|
1839
1912
|
keyType = "int";
|
|
1840
1913
|
incrementing = true;
|
|
1841
1914
|
withCount = [];
|
|
1915
|
+
primaryKey = "id";
|
|
1842
1916
|
perPage = 15;
|
|
1843
1917
|
static globalScopes = {};
|
|
1844
1918
|
static pluginInitializers = {};
|
|
@@ -1848,6 +1922,7 @@ var Model = class Model extends BaseModel {
|
|
|
1848
1922
|
eagerLoad = {};
|
|
1849
1923
|
exists = false;
|
|
1850
1924
|
with = [];
|
|
1925
|
+
name;
|
|
1851
1926
|
trx = null;
|
|
1852
1927
|
constructor(attributes = {}) {
|
|
1853
1928
|
super();
|
|
@@ -2619,8 +2694,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
2619
2694
|
const results = await this.take(1).get(columns);
|
|
2620
2695
|
return results.count() > 0 ? results.first() : null;
|
|
2621
2696
|
}
|
|
2622
|
-
async firstOrFail(columns
|
|
2623
|
-
const model = await this.first(columns);
|
|
2697
|
+
async firstOrFail(...columns) {
|
|
2698
|
+
const model = await this.first(...columns);
|
|
2624
2699
|
if (model !== null) return model;
|
|
2625
2700
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2626
2701
|
}
|
|
@@ -2796,7 +2871,9 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2796
2871
|
}
|
|
2797
2872
|
asProxy() {
|
|
2798
2873
|
return new Proxy(this, { get(target, prop) {
|
|
2874
|
+
var _target$query$connect;
|
|
2799
2875
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2876
|
+
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";
|
|
2800
2877
|
if ([
|
|
2801
2878
|
"select",
|
|
2802
2879
|
"from",
|
|
@@ -2859,7 +2936,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2859
2936
|
"clearWhere",
|
|
2860
2937
|
"clearHaving",
|
|
2861
2938
|
"clearGroup"
|
|
2862
|
-
].includes(prop)) return (...args) => {
|
|
2939
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2863
2940
|
target.query[prop](...args);
|
|
2864
2941
|
return target.asProxy();
|
|
2865
2942
|
};
|
|
@@ -4953,7 +5030,7 @@ var SchemaInspector = class {
|
|
|
4953
5030
|
|
|
4954
5031
|
//#endregion
|
|
4955
5032
|
//#region src/migrations/migrator.ts
|
|
4956
|
-
async function glob(folderPath) {
|
|
5033
|
+
async function glob$1(folderPath) {
|
|
4957
5034
|
const files = await fs.readdir(folderPath);
|
|
4958
5035
|
const allFiles = [];
|
|
4959
5036
|
for (const file of files) {
|
|
@@ -4961,7 +5038,7 @@ async function glob(folderPath) {
|
|
|
4961
5038
|
const stats = await fs.stat(filePath);
|
|
4962
5039
|
if (stats.isFile()) allFiles.push(filePath);
|
|
4963
5040
|
else if (stats.isDirectory()) {
|
|
4964
|
-
const subFiles = await glob(filePath);
|
|
5041
|
+
const subFiles = await glob$1(filePath);
|
|
4965
5042
|
allFiles.push(...subFiles);
|
|
4966
5043
|
}
|
|
4967
5044
|
}
|
|
@@ -5055,9 +5132,9 @@ var Migrator = class {
|
|
|
5055
5132
|
}
|
|
5056
5133
|
/**
|
|
5057
5134
|
* Drop all tables and re-run all migrations
|
|
5058
|
-
*
|
|
5059
|
-
* @param paths
|
|
5060
|
-
* @param options
|
|
5135
|
+
*
|
|
5136
|
+
* @param paths
|
|
5137
|
+
* @param options
|
|
5061
5138
|
*/
|
|
5062
5139
|
async fresh(paths, options) {
|
|
5063
5140
|
/** Initialise connections */
|
|
@@ -5104,7 +5181,7 @@ var Migrator = class {
|
|
|
5104
5181
|
files.push(p);
|
|
5105
5182
|
continue;
|
|
5106
5183
|
}
|
|
5107
|
-
files.push(...await glob(p));
|
|
5184
|
+
files.push(...await glob$1(p));
|
|
5108
5185
|
}
|
|
5109
5186
|
return files.filter(Boolean).reduce((result, file) => {
|
|
5110
5187
|
result[this.getMigrationName(file)] = file;
|
|
@@ -5149,59 +5226,6 @@ var Migrator = class {
|
|
|
5149
5226
|
};
|
|
5150
5227
|
var migrator_default = Migrator;
|
|
5151
5228
|
|
|
5152
|
-
//#endregion
|
|
5153
|
-
//#region src/cli/utils.ts
|
|
5154
|
-
const join = path.join;
|
|
5155
|
-
var Utils = class {
|
|
5156
|
-
/**
|
|
5157
|
-
* Wraps text with chalk
|
|
5158
|
-
*
|
|
5159
|
-
* @param txt
|
|
5160
|
-
* @param color
|
|
5161
|
-
* @returns
|
|
5162
|
-
*/
|
|
5163
|
-
static textFormat(txt, color) {
|
|
5164
|
-
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
5165
|
-
}
|
|
5166
|
-
static findModulePkg(moduleId, cwd) {
|
|
5167
|
-
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
5168
|
-
let packageName = "";
|
|
5169
|
-
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
5170
|
-
packageName += parts.shift();
|
|
5171
|
-
const packageJson = path.join(packageName, "package.json");
|
|
5172
|
-
const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
|
|
5173
|
-
if (!resolved) return;
|
|
5174
|
-
return path.join(path.dirname(resolved), parts.join("/"));
|
|
5175
|
-
}
|
|
5176
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path$1) {
|
|
5177
|
-
if (path$1) return [join(cwd, path$1)];
|
|
5178
|
-
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
5179
|
-
}
|
|
5180
|
-
/**
|
|
5181
|
-
* Check if file exists
|
|
5182
|
-
*
|
|
5183
|
-
* @param path
|
|
5184
|
-
* @returns
|
|
5185
|
-
*/
|
|
5186
|
-
static async fileExists(path$1) {
|
|
5187
|
-
try {
|
|
5188
|
-
await access(path$1);
|
|
5189
|
-
return true;
|
|
5190
|
-
} catch {
|
|
5191
|
-
return false;
|
|
5192
|
-
}
|
|
5193
|
-
}
|
|
5194
|
-
static findUpConfig(cwd, name, extensions) {
|
|
5195
|
-
return escalade(cwd, (_dir, names) => {
|
|
5196
|
-
for (const ext of extensions) {
|
|
5197
|
-
const filename = `${name}.${ext}`;
|
|
5198
|
-
if (names.includes(filename)) return filename;
|
|
5199
|
-
}
|
|
5200
|
-
return false;
|
|
5201
|
-
});
|
|
5202
|
-
}
|
|
5203
|
-
};
|
|
5204
|
-
|
|
5205
5229
|
//#endregion
|
|
5206
5230
|
//#region src/migrate.ts
|
|
5207
5231
|
var Migrate = class {
|
|
@@ -5213,10 +5237,10 @@ var Migrate = class {
|
|
|
5213
5237
|
}
|
|
5214
5238
|
/**
|
|
5215
5239
|
* Runs all pending migrations
|
|
5216
|
-
*
|
|
5217
|
-
* @param config
|
|
5218
|
-
* @param options
|
|
5219
|
-
* @param destroyAll
|
|
5240
|
+
*
|
|
5241
|
+
* @param config
|
|
5242
|
+
* @param options
|
|
5243
|
+
* @param destroyAll
|
|
5220
5244
|
*/
|
|
5221
5245
|
async run(config, options = {}, destroyAll = false) {
|
|
5222
5246
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5230,10 +5254,10 @@ var Migrate = class {
|
|
|
5230
5254
|
}
|
|
5231
5255
|
/**
|
|
5232
5256
|
* Rollback the last migration
|
|
5233
|
-
*
|
|
5234
|
-
* @param config
|
|
5235
|
-
* @param options
|
|
5236
|
-
* @param destroyAll
|
|
5257
|
+
*
|
|
5258
|
+
* @param config
|
|
5259
|
+
* @param options
|
|
5260
|
+
* @param destroyAll
|
|
5237
5261
|
*/
|
|
5238
5262
|
async rollback(config, options = {}, destroyAll = false) {
|
|
5239
5263
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5247,10 +5271,10 @@ var Migrate = class {
|
|
|
5247
5271
|
}
|
|
5248
5272
|
/**
|
|
5249
5273
|
* Rollback all database migrations
|
|
5250
|
-
*
|
|
5251
|
-
* @param config
|
|
5252
|
-
* @param options
|
|
5253
|
-
* @param destroyAll
|
|
5274
|
+
*
|
|
5275
|
+
* @param config
|
|
5276
|
+
* @param options
|
|
5277
|
+
* @param destroyAll
|
|
5254
5278
|
*/
|
|
5255
5279
|
async reset(config, options = {}, destroyAll = false) {
|
|
5256
5280
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5265,10 +5289,10 @@ var Migrate = class {
|
|
|
5265
5289
|
}
|
|
5266
5290
|
/**
|
|
5267
5291
|
* Reset and re-run all migrations
|
|
5268
|
-
*
|
|
5269
|
-
* @param config
|
|
5270
|
-
* @param options
|
|
5271
|
-
* @param destroyAll
|
|
5292
|
+
*
|
|
5293
|
+
* @param config
|
|
5294
|
+
* @param options
|
|
5295
|
+
* @param destroyAll
|
|
5272
5296
|
*/
|
|
5273
5297
|
async refresh(config, options = {}, destroyAll = false) {
|
|
5274
5298
|
await this.reset(config, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5277,10 +5301,10 @@ var Migrate = class {
|
|
|
5277
5301
|
}
|
|
5278
5302
|
/**
|
|
5279
5303
|
* Drop all tables and re-run all migrations
|
|
5280
|
-
*
|
|
5281
|
-
* @param config
|
|
5282
|
-
* @param options
|
|
5283
|
-
* @param destroyAll
|
|
5304
|
+
*
|
|
5305
|
+
* @param config
|
|
5306
|
+
* @param options
|
|
5307
|
+
* @param destroyAll
|
|
5284
5308
|
*/
|
|
5285
5309
|
async fresh(config, options = {}, destroyAll = false) {
|
|
5286
5310
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5290,8 +5314,8 @@ var Migrate = class {
|
|
|
5290
5314
|
}
|
|
5291
5315
|
/**
|
|
5292
5316
|
* Prepares the database for migration
|
|
5293
|
-
*
|
|
5294
|
-
* @param migrator
|
|
5317
|
+
*
|
|
5318
|
+
* @param migrator
|
|
5295
5319
|
*/
|
|
5296
5320
|
async prepareDatabase(migrator) {
|
|
5297
5321
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5303,11 +5327,11 @@ var Migrate = class {
|
|
|
5303
5327
|
}
|
|
5304
5328
|
/**
|
|
5305
5329
|
* Check the status of available migrations
|
|
5306
|
-
*
|
|
5307
|
-
* @param config
|
|
5308
|
-
* @param options
|
|
5309
|
-
* @param destroyAll
|
|
5310
|
-
* @returns
|
|
5330
|
+
*
|
|
5331
|
+
* @param config
|
|
5332
|
+
* @param options
|
|
5333
|
+
* @param destroyAll
|
|
5334
|
+
* @returns
|
|
5311
5335
|
*/
|
|
5312
5336
|
async status(config, options = {}, destroyAll = false) {
|
|
5313
5337
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5334,9 +5358,9 @@ var Migrate = class {
|
|
|
5334
5358
|
}
|
|
5335
5359
|
/**
|
|
5336
5360
|
* Setup the database connection
|
|
5337
|
-
*
|
|
5338
|
-
* @param config
|
|
5339
|
-
* @returns
|
|
5361
|
+
*
|
|
5362
|
+
* @param config
|
|
5363
|
+
* @returns
|
|
5340
5364
|
*/
|
|
5341
5365
|
async setupConnection(config) {
|
|
5342
5366
|
var _config$migrations;
|
|
@@ -5368,6 +5392,112 @@ var Migration = class extends Inference {
|
|
|
5368
5392
|
};
|
|
5369
5393
|
var migration_default = Migration;
|
|
5370
5394
|
|
|
5395
|
+
//#endregion
|
|
5396
|
+
//#region src/seeders/seeder.ts
|
|
5397
|
+
var Seeder = class {};
|
|
5398
|
+
var seeder_default = Seeder;
|
|
5399
|
+
|
|
5400
|
+
//#endregion
|
|
5401
|
+
//#region src/seeders/runner.ts
|
|
5402
|
+
async function glob(folderPath) {
|
|
5403
|
+
const { default: escalade$1 } = await import("escalade");
|
|
5404
|
+
const entries = [];
|
|
5405
|
+
await escalade$1(folderPath, async (dir, names) => {
|
|
5406
|
+
await Promise.all(names.map(async (name) => {
|
|
5407
|
+
const p = path.join(dir, name);
|
|
5408
|
+
try {
|
|
5409
|
+
await access$1(p);
|
|
5410
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
5411
|
+
} catch {}
|
|
5412
|
+
}));
|
|
5413
|
+
return "";
|
|
5414
|
+
});
|
|
5415
|
+
return entries;
|
|
5416
|
+
}
|
|
5417
|
+
var SeederRunner = class {
|
|
5418
|
+
resolver;
|
|
5419
|
+
connection;
|
|
5420
|
+
paths = [];
|
|
5421
|
+
constructor(resolver) {
|
|
5422
|
+
this.resolver = resolver;
|
|
5423
|
+
}
|
|
5424
|
+
path(p) {
|
|
5425
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
5426
|
+
}
|
|
5427
|
+
getPaths() {
|
|
5428
|
+
return this.paths;
|
|
5429
|
+
}
|
|
5430
|
+
resolveConnection(connection) {
|
|
5431
|
+
var _getInstance, _ref, _instance$connections;
|
|
5432
|
+
const name = connection || this.connection || "default";
|
|
5433
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
5434
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
5435
|
+
/** noop */
|
|
5436
|
+
});
|
|
5437
|
+
return this.resolver.fire(name);
|
|
5438
|
+
}
|
|
5439
|
+
setConnection(connection) {
|
|
5440
|
+
this.connection = connection;
|
|
5441
|
+
return this;
|
|
5442
|
+
}
|
|
5443
|
+
async getSeederFiles(paths) {
|
|
5444
|
+
const files = [];
|
|
5445
|
+
for (const p of paths) {
|
|
5446
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
5447
|
+
files.push(p);
|
|
5448
|
+
continue;
|
|
5449
|
+
}
|
|
5450
|
+
files.push(...await glob(p));
|
|
5451
|
+
}
|
|
5452
|
+
return files;
|
|
5453
|
+
}
|
|
5454
|
+
async resolvePath(filePath) {
|
|
5455
|
+
try {
|
|
5456
|
+
const mod = await import(filePath);
|
|
5457
|
+
return new (mod.default ?? mod.Seeder)();
|
|
5458
|
+
} catch {
|
|
5459
|
+
return null;
|
|
5460
|
+
}
|
|
5461
|
+
}
|
|
5462
|
+
async run(paths, connection) {
|
|
5463
|
+
const files = await this.getSeederFiles(paths);
|
|
5464
|
+
const conn = this.resolveConnection(connection);
|
|
5465
|
+
for (const file of files) {
|
|
5466
|
+
const seeder = await this.resolvePath(file);
|
|
5467
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
5468
|
+
}
|
|
5469
|
+
}
|
|
5470
|
+
};
|
|
5471
|
+
var runner_default = SeederRunner;
|
|
5472
|
+
|
|
5473
|
+
//#endregion
|
|
5474
|
+
//#region src/seeders/seeder-creator.ts
|
|
5475
|
+
var SeederCreator = class {
|
|
5476
|
+
constructor(customStubPath) {
|
|
5477
|
+
this.customStubPath = customStubPath;
|
|
5478
|
+
}
|
|
5479
|
+
async create(dir, name, type = "js") {
|
|
5480
|
+
await mkdir(dir, { recursive: true });
|
|
5481
|
+
const stubPath = this.getStubPath(type);
|
|
5482
|
+
let stub = await readFile(stubPath, "utf-8");
|
|
5483
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
5484
|
+
const filePath = path.join(dir, `${name}.${type}`);
|
|
5485
|
+
await writeFile(filePath, stub);
|
|
5486
|
+
return filePath;
|
|
5487
|
+
}
|
|
5488
|
+
getStubPath(type) {
|
|
5489
|
+
if (this.customStubPath) return path.join(this.customStubPath, `seeder-${type}.stub`);
|
|
5490
|
+
const __dirname$1 = this.getDirname(import.meta);
|
|
5491
|
+
return path.join(__dirname$1, "stubs", `seeder-${type}.stub`);
|
|
5492
|
+
}
|
|
5493
|
+
getDirname(meta) {
|
|
5494
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
5495
|
+
if (meta && meta.url) return dirname(fileURLToPath(meta.url));
|
|
5496
|
+
throw new Error("Unable to determine dirname");
|
|
5497
|
+
}
|
|
5498
|
+
};
|
|
5499
|
+
var seeder_creator_default = SeederCreator;
|
|
5500
|
+
|
|
5371
5501
|
//#endregion
|
|
5372
5502
|
//#region src/pivot.ts
|
|
5373
5503
|
var pivot_default = Pivot;
|
|
@@ -5543,7 +5673,7 @@ const make = (model, data, options = {}) => {
|
|
|
5543
5673
|
return model.make(data);
|
|
5544
5674
|
};
|
|
5545
5675
|
const makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
5546
|
-
const makePaginator = (model, data) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5676
|
+
const makePaginator = (model, data, _) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5547
5677
|
|
|
5548
5678
|
//#endregion
|
|
5549
|
-
export { attribute_default as Attribute, builder_default as Builder, casts_attributes_default as CastsAttributes, collection_default as Collection, has_unique_ids_default as HasUniqueIds, InvalidArgumentError, Migrate, migration_default as Migration, model_default as Model, ModelNotFoundError, paginator_default as Paginator, pivot_default as Pivot, query_builder_default as QueryBuilder, RelationNotFoundError, scope_default as Scope, soft_deletes_default as SoftDeletes, arquebus_default as arquebus, compose, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };
|
|
5679
|
+
export { attribute_default as Attribute, builder_default as Builder, casts_attributes_default as CastsAttributes, collection_default as Collection, has_unique_ids_default as HasUniqueIds, InvalidArgumentError, Migrate, migration_default as Migration, model_default as Model, ModelNotFoundError, paginator_default as Paginator, pivot_default as Pivot, query_builder_default as QueryBuilder, RelationNotFoundError, scope_default as Scope, seeder_default as Seeder, seeder_creator_default as SeederCreator, runner_default as SeederRunner, soft_deletes_default as SoftDeletes, arquebus_default as arquebus, compose, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };
|