@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.cjs
CHANGED
|
@@ -43,18 +43,22 @@ let path = require("path");
|
|
|
43
43
|
path = __toESM(path);
|
|
44
44
|
let fs = require("fs");
|
|
45
45
|
fs = __toESM(fs);
|
|
46
|
-
let pluralize = require("pluralize");
|
|
47
|
-
pluralize = __toESM(pluralize);
|
|
48
|
-
let __h3ravel_shared = require("@h3ravel/shared");
|
|
49
|
-
__h3ravel_shared = __toESM(__h3ravel_shared);
|
|
50
|
-
let node_fs_promises = require("node:fs/promises");
|
|
51
|
-
node_fs_promises = __toESM(node_fs_promises);
|
|
52
46
|
let fs_promises = require("fs/promises");
|
|
53
47
|
fs_promises = __toESM(fs_promises);
|
|
54
48
|
let escalade_sync = require("escalade/sync");
|
|
55
49
|
escalade_sync = __toESM(escalade_sync);
|
|
56
50
|
let resolve_from = require("resolve-from");
|
|
57
51
|
resolve_from = __toESM(resolve_from);
|
|
52
|
+
let pluralize = require("pluralize");
|
|
53
|
+
pluralize = __toESM(pluralize);
|
|
54
|
+
let __h3ravel_shared = require("@h3ravel/shared");
|
|
55
|
+
__h3ravel_shared = __toESM(__h3ravel_shared);
|
|
56
|
+
let node_fs_promises = require("node:fs/promises");
|
|
57
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
58
|
+
let node_path = require("node:path");
|
|
59
|
+
node_path = __toESM(node_path);
|
|
60
|
+
let node_url = require("node:url");
|
|
61
|
+
node_url = __toESM(node_url);
|
|
58
62
|
|
|
59
63
|
//#region src/casts/attribute.ts
|
|
60
64
|
var Attribute = class Attribute {
|
|
@@ -128,7 +132,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
128
132
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
129
133
|
/**
|
|
130
134
|
* Compose function that merges multiple classes and mixins
|
|
131
|
-
*
|
|
135
|
+
*
|
|
132
136
|
* @example
|
|
133
137
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
134
138
|
* return class extends Base {
|
|
@@ -165,10 +169,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
165
169
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
166
170
|
* console.log(user.pluginMethod()) // "plugin"
|
|
167
171
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
168
|
-
*
|
|
169
|
-
* @param Base
|
|
170
|
-
* @param mixins
|
|
171
|
-
* @returns
|
|
172
|
+
*
|
|
173
|
+
* @param Base
|
|
174
|
+
* @param mixins
|
|
175
|
+
* @returns
|
|
172
176
|
*/
|
|
173
177
|
function compose$1(Base, ...mixins) {
|
|
174
178
|
/**
|
|
@@ -229,10 +233,10 @@ const getAttrName = (attrMethod) => {
|
|
|
229
233
|
};
|
|
230
234
|
/**
|
|
231
235
|
* Tap into a model a collection instance
|
|
232
|
-
*
|
|
233
|
-
* @param instance
|
|
234
|
-
* @param callback
|
|
235
|
-
* @returns
|
|
236
|
+
*
|
|
237
|
+
* @param instance
|
|
238
|
+
* @param callback
|
|
239
|
+
* @returns
|
|
236
240
|
*/
|
|
237
241
|
const tap = (instance, callback) => {
|
|
238
242
|
const result = callback(instance);
|
|
@@ -1072,8 +1076,8 @@ var HasManyThrough = class extends relation_default {
|
|
|
1072
1076
|
const results = await this.take(1).get(columns);
|
|
1073
1077
|
return results.count() > 0 ? results.first() : null;
|
|
1074
1078
|
}
|
|
1075
|
-
async firstOrFail(columns
|
|
1076
|
-
const model = await this.first(columns);
|
|
1079
|
+
async firstOrFail(...columns) {
|
|
1080
|
+
const model = await this.first(...columns);
|
|
1077
1081
|
if (model) return model;
|
|
1078
1082
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
1079
1083
|
}
|
|
@@ -1112,7 +1116,7 @@ var HasManyThrough = class extends relation_default {
|
|
|
1112
1116
|
}
|
|
1113
1117
|
async paginate(perPage = null, columns = ["*"], pageName = "page", page = null) {
|
|
1114
1118
|
this.query.addSelect(this.shouldSelect(columns));
|
|
1115
|
-
return await this.query.paginate(perPage, columns, pageName, page);
|
|
1119
|
+
return await this.query.paginate(perPage ?? 15, columns, pageName, page);
|
|
1116
1120
|
}
|
|
1117
1121
|
shouldSelect(columns = ["*"]) {
|
|
1118
1122
|
if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
|
|
@@ -1390,9 +1394,6 @@ const UniqueIds = (Model$1) => {
|
|
|
1390
1394
|
uniqueIds() {
|
|
1391
1395
|
return [];
|
|
1392
1396
|
}
|
|
1393
|
-
newUniqueId() {
|
|
1394
|
-
return null;
|
|
1395
|
-
}
|
|
1396
1397
|
setUniqueIds() {
|
|
1397
1398
|
const uniqueIds = this.uniqueIds();
|
|
1398
1399
|
for (const column of uniqueIds) if (this[column] === null || this[column] === void 0) this[column] = this.newUniqueId();
|
|
@@ -1414,6 +1415,7 @@ var Paginator = class {
|
|
|
1414
1415
|
options = {};
|
|
1415
1416
|
static setFormatter(formatter) {
|
|
1416
1417
|
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
1418
|
+
if (!formatter) return;
|
|
1417
1419
|
this.formatter = formatter;
|
|
1418
1420
|
}
|
|
1419
1421
|
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
@@ -1502,8 +1504,10 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1502
1504
|
asProxy() {
|
|
1503
1505
|
return new Proxy(this, {
|
|
1504
1506
|
get: function(target, prop) {
|
|
1507
|
+
var _target$connector$cli;
|
|
1505
1508
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
1506
1509
|
if (["destroy", "schema"].includes(prop)) return target.connector.schema;
|
|
1510
|
+
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";
|
|
1507
1511
|
if ([
|
|
1508
1512
|
"select",
|
|
1509
1513
|
"from",
|
|
@@ -1566,7 +1570,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1566
1570
|
"clearWhere",
|
|
1567
1571
|
"clearHaving",
|
|
1568
1572
|
"clearGroup"
|
|
1569
|
-
].includes(prop)) return (...args) => {
|
|
1573
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
1570
1574
|
target.connector[prop](...args);
|
|
1571
1575
|
return target.asProxy();
|
|
1572
1576
|
};
|
|
@@ -1623,7 +1627,7 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1623
1627
|
} while (countResults === count);
|
|
1624
1628
|
return true;
|
|
1625
1629
|
}
|
|
1626
|
-
async paginate(page = 1, perPage = 15) {
|
|
1630
|
+
async paginate(page = 1, perPage = 15, _pageName, _page) {
|
|
1627
1631
|
const total = await this.clone().clearOrder().count("*");
|
|
1628
1632
|
let results;
|
|
1629
1633
|
if (total > 0) {
|
|
@@ -1687,6 +1691,59 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
1687
1691
|
};
|
|
1688
1692
|
var query_builder_default = QueryBuilder;
|
|
1689
1693
|
|
|
1694
|
+
//#endregion
|
|
1695
|
+
//#region src/cli/utils.ts
|
|
1696
|
+
const join = path.default.join;
|
|
1697
|
+
var Utils = class {
|
|
1698
|
+
/**
|
|
1699
|
+
* Wraps text with chalk
|
|
1700
|
+
*
|
|
1701
|
+
* @param txt
|
|
1702
|
+
* @param color
|
|
1703
|
+
* @returns
|
|
1704
|
+
*/
|
|
1705
|
+
static textFormat(txt, color) {
|
|
1706
|
+
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
1707
|
+
}
|
|
1708
|
+
static findModulePkg(moduleId, cwd) {
|
|
1709
|
+
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
1710
|
+
let packageName = "";
|
|
1711
|
+
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
1712
|
+
packageName += parts.shift();
|
|
1713
|
+
const packageJson = path.default.join(packageName, "package.json");
|
|
1714
|
+
const resolved = resolve_from.default.silent(cwd ?? process.cwd(), packageJson);
|
|
1715
|
+
if (!resolved) return;
|
|
1716
|
+
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
1717
|
+
}
|
|
1718
|
+
static async getMigrationPaths(cwd, migrator, defaultPath, path$6) {
|
|
1719
|
+
if (path$6) return [join(cwd, path$6)];
|
|
1720
|
+
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Check if file exists
|
|
1724
|
+
*
|
|
1725
|
+
* @param path
|
|
1726
|
+
* @returns
|
|
1727
|
+
*/
|
|
1728
|
+
static async fileExists(path$6) {
|
|
1729
|
+
try {
|
|
1730
|
+
await (0, fs_promises.access)(path$6);
|
|
1731
|
+
return true;
|
|
1732
|
+
} catch {
|
|
1733
|
+
return false;
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
static findUpConfig(cwd, name, extensions) {
|
|
1737
|
+
return (0, escalade_sync.default)(cwd, (_dir, names) => {
|
|
1738
|
+
for (const ext of extensions) {
|
|
1739
|
+
const filename = `${name}.${ext}`;
|
|
1740
|
+
if (names.includes(filename)) return filename;
|
|
1741
|
+
}
|
|
1742
|
+
return false;
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
|
|
1690
1747
|
//#endregion
|
|
1691
1748
|
//#region src/arquebus.ts
|
|
1692
1749
|
var arquebus = class arquebus {
|
|
@@ -1708,22 +1765,22 @@ var arquebus = class arquebus {
|
|
|
1708
1765
|
return this.instance;
|
|
1709
1766
|
}
|
|
1710
1767
|
/**
|
|
1711
|
-
* Initialize a new database connection
|
|
1712
|
-
*
|
|
1713
|
-
* @returns
|
|
1768
|
+
* Initialize a new database connection
|
|
1769
|
+
*
|
|
1770
|
+
* @returns
|
|
1714
1771
|
*/
|
|
1715
1772
|
static fire(connection = null) {
|
|
1716
1773
|
return this.getInstance().getConnection(connection);
|
|
1717
1774
|
}
|
|
1718
1775
|
/**
|
|
1719
|
-
* Initialize a new database connection
|
|
1720
|
-
*
|
|
1776
|
+
* Initialize a new database connection
|
|
1777
|
+
*
|
|
1721
1778
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
1722
|
-
*
|
|
1779
|
+
*
|
|
1723
1780
|
* @deprecated since version 0.3.0
|
|
1724
1781
|
* @alias fire
|
|
1725
|
-
*
|
|
1726
|
-
* @returns
|
|
1782
|
+
*
|
|
1783
|
+
* @returns
|
|
1727
1784
|
*/
|
|
1728
1785
|
static connection(connection = null) {
|
|
1729
1786
|
return this.fire(connection);
|
|
@@ -1760,11 +1817,12 @@ var arquebus = class arquebus {
|
|
|
1760
1817
|
}
|
|
1761
1818
|
getConnection(name = null) {
|
|
1762
1819
|
name = name || "default";
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
this.
|
|
1820
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
1821
|
+
if (this.manager[resolvedName] === void 0) {
|
|
1822
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
1823
|
+
this.manager[resolvedName] = queryBuilder;
|
|
1766
1824
|
}
|
|
1767
|
-
return this.manager[
|
|
1825
|
+
return this.manager[resolvedName];
|
|
1768
1826
|
}
|
|
1769
1827
|
addConnection(config, name = "default") {
|
|
1770
1828
|
this.connections[name] = {
|
|
@@ -1781,13 +1839,13 @@ var arquebus = class arquebus {
|
|
|
1781
1839
|
}
|
|
1782
1840
|
/**
|
|
1783
1841
|
* Autoload the config file
|
|
1784
|
-
*
|
|
1785
|
-
* @param addConnection
|
|
1842
|
+
*
|
|
1843
|
+
* @param addConnection
|
|
1786
1844
|
* @default true
|
|
1787
|
-
* If set to `false` we will no attempt add the connection, we
|
|
1845
|
+
* If set to `false` we will no attempt add the connection, we
|
|
1788
1846
|
* will just go ahead and return the config
|
|
1789
|
-
*
|
|
1790
|
-
* @returns
|
|
1847
|
+
*
|
|
1848
|
+
* @returns
|
|
1791
1849
|
*/
|
|
1792
1850
|
static async autoLoad(addConnection = true) {
|
|
1793
1851
|
let config;
|
|
@@ -1804,6 +1862,23 @@ var arquebus = class arquebus {
|
|
|
1804
1862
|
if (addConnection) instance.addConnection(config, config.client);
|
|
1805
1863
|
return config;
|
|
1806
1864
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
1865
|
+
const candidateDirs = [
|
|
1866
|
+
process.cwd(),
|
|
1867
|
+
path.default.join(process.cwd(), "test", "cli"),
|
|
1868
|
+
path.default.join(process.cwd(), "test")
|
|
1869
|
+
];
|
|
1870
|
+
for (const dir of candidateDirs) {
|
|
1871
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
1872
|
+
"js",
|
|
1873
|
+
"ts",
|
|
1874
|
+
"cjs"
|
|
1875
|
+
]);
|
|
1876
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
1877
|
+
config = (await import(found)).default;
|
|
1878
|
+
if (addConnection) instance.addConnection(config, config.client);
|
|
1879
|
+
return config;
|
|
1880
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
1881
|
+
}
|
|
1807
1882
|
return {};
|
|
1808
1883
|
}
|
|
1809
1884
|
beginTransaction(connection = null) {
|
|
@@ -1862,14 +1937,15 @@ var arquebus_default = arquebus;
|
|
|
1862
1937
|
|
|
1863
1938
|
//#endregion
|
|
1864
1939
|
//#region src/model.ts
|
|
1865
|
-
const
|
|
1940
|
+
const ModelClass = class {};
|
|
1941
|
+
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);
|
|
1866
1942
|
var Model = class Model extends BaseModel {
|
|
1867
|
-
primaryKey = "id";
|
|
1868
1943
|
builder = null;
|
|
1869
1944
|
table = null;
|
|
1870
1945
|
keyType = "int";
|
|
1871
1946
|
incrementing = true;
|
|
1872
1947
|
withCount = [];
|
|
1948
|
+
primaryKey = "id";
|
|
1873
1949
|
perPage = 15;
|
|
1874
1950
|
static globalScopes = {};
|
|
1875
1951
|
static pluginInitializers = {};
|
|
@@ -1879,6 +1955,7 @@ var Model = class Model extends BaseModel {
|
|
|
1879
1955
|
eagerLoad = {};
|
|
1880
1956
|
exists = false;
|
|
1881
1957
|
with = [];
|
|
1958
|
+
name;
|
|
1882
1959
|
trx = null;
|
|
1883
1960
|
constructor(attributes = {}) {
|
|
1884
1961
|
super();
|
|
@@ -2650,8 +2727,8 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
|
|
|
2650
2727
|
const results = await this.take(1).get(columns);
|
|
2651
2728
|
return results.count() > 0 ? results.first() : null;
|
|
2652
2729
|
}
|
|
2653
|
-
async firstOrFail(columns
|
|
2654
|
-
const model = await this.first(columns);
|
|
2730
|
+
async firstOrFail(...columns) {
|
|
2731
|
+
const model = await this.first(...columns);
|
|
2655
2732
|
if (model !== null) return model;
|
|
2656
2733
|
throw new ModelNotFoundError().setModel(this.related.constructor);
|
|
2657
2734
|
}
|
|
@@ -2827,7 +2904,9 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2827
2904
|
}
|
|
2828
2905
|
asProxy() {
|
|
2829
2906
|
return new Proxy(this, { get(target, prop) {
|
|
2907
|
+
var _target$query$connect;
|
|
2830
2908
|
if (typeof target[prop] !== "undefined") return target[prop];
|
|
2909
|
+
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";
|
|
2831
2910
|
if ([
|
|
2832
2911
|
"select",
|
|
2833
2912
|
"from",
|
|
@@ -2890,7 +2969,7 @@ var Builder = class Builder extends Inference$1 {
|
|
|
2890
2969
|
"clearWhere",
|
|
2891
2970
|
"clearHaving",
|
|
2892
2971
|
"clearGroup"
|
|
2893
|
-
].includes(prop)) return (...args) => {
|
|
2972
|
+
].includes(prop) && !skipReturning) return (...args) => {
|
|
2894
2973
|
target.query[prop](...args);
|
|
2895
2974
|
return target.asProxy();
|
|
2896
2975
|
};
|
|
@@ -4984,7 +5063,7 @@ var SchemaInspector = class {
|
|
|
4984
5063
|
|
|
4985
5064
|
//#endregion
|
|
4986
5065
|
//#region src/migrations/migrator.ts
|
|
4987
|
-
async function glob(folderPath) {
|
|
5066
|
+
async function glob$1(folderPath) {
|
|
4988
5067
|
const files = await node_fs_promises.default.readdir(folderPath);
|
|
4989
5068
|
const allFiles = [];
|
|
4990
5069
|
for (const file of files) {
|
|
@@ -4992,7 +5071,7 @@ async function glob(folderPath) {
|
|
|
4992
5071
|
const stats = await node_fs_promises.default.stat(filePath);
|
|
4993
5072
|
if (stats.isFile()) allFiles.push(filePath);
|
|
4994
5073
|
else if (stats.isDirectory()) {
|
|
4995
|
-
const subFiles = await glob(filePath);
|
|
5074
|
+
const subFiles = await glob$1(filePath);
|
|
4996
5075
|
allFiles.push(...subFiles);
|
|
4997
5076
|
}
|
|
4998
5077
|
}
|
|
@@ -5086,9 +5165,9 @@ var Migrator = class {
|
|
|
5086
5165
|
}
|
|
5087
5166
|
/**
|
|
5088
5167
|
* Drop all tables and re-run all migrations
|
|
5089
|
-
*
|
|
5090
|
-
* @param paths
|
|
5091
|
-
* @param options
|
|
5168
|
+
*
|
|
5169
|
+
* @param paths
|
|
5170
|
+
* @param options
|
|
5092
5171
|
*/
|
|
5093
5172
|
async fresh(paths, options) {
|
|
5094
5173
|
/** Initialise connections */
|
|
@@ -5135,7 +5214,7 @@ var Migrator = class {
|
|
|
5135
5214
|
files.push(p);
|
|
5136
5215
|
continue;
|
|
5137
5216
|
}
|
|
5138
|
-
files.push(...await glob(p));
|
|
5217
|
+
files.push(...await glob$1(p));
|
|
5139
5218
|
}
|
|
5140
5219
|
return files.filter(Boolean).reduce((result, file) => {
|
|
5141
5220
|
result[this.getMigrationName(file)] = file;
|
|
@@ -5180,59 +5259,6 @@ var Migrator = class {
|
|
|
5180
5259
|
};
|
|
5181
5260
|
var migrator_default = Migrator;
|
|
5182
5261
|
|
|
5183
|
-
//#endregion
|
|
5184
|
-
//#region src/cli/utils.ts
|
|
5185
|
-
const join = path.default.join;
|
|
5186
|
-
var Utils = class {
|
|
5187
|
-
/**
|
|
5188
|
-
* Wraps text with chalk
|
|
5189
|
-
*
|
|
5190
|
-
* @param txt
|
|
5191
|
-
* @param color
|
|
5192
|
-
* @returns
|
|
5193
|
-
*/
|
|
5194
|
-
static textFormat(txt, color) {
|
|
5195
|
-
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
5196
|
-
}
|
|
5197
|
-
static findModulePkg(moduleId, cwd) {
|
|
5198
|
-
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
5199
|
-
let packageName = "";
|
|
5200
|
-
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
5201
|
-
packageName += parts.shift();
|
|
5202
|
-
const packageJson = path.default.join(packageName, "package.json");
|
|
5203
|
-
const resolved = resolve_from.default.silent(cwd ?? process.cwd(), packageJson);
|
|
5204
|
-
if (!resolved) return;
|
|
5205
|
-
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
5206
|
-
}
|
|
5207
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path$4) {
|
|
5208
|
-
if (path$4) return [join(cwd, path$4)];
|
|
5209
|
-
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
5210
|
-
}
|
|
5211
|
-
/**
|
|
5212
|
-
* Check if file exists
|
|
5213
|
-
*
|
|
5214
|
-
* @param path
|
|
5215
|
-
* @returns
|
|
5216
|
-
*/
|
|
5217
|
-
static async fileExists(path$4) {
|
|
5218
|
-
try {
|
|
5219
|
-
await (0, fs_promises.access)(path$4);
|
|
5220
|
-
return true;
|
|
5221
|
-
} catch {
|
|
5222
|
-
return false;
|
|
5223
|
-
}
|
|
5224
|
-
}
|
|
5225
|
-
static findUpConfig(cwd, name, extensions) {
|
|
5226
|
-
return (0, escalade_sync.default)(cwd, (_dir, names) => {
|
|
5227
|
-
for (const ext of extensions) {
|
|
5228
|
-
const filename = `${name}.${ext}`;
|
|
5229
|
-
if (names.includes(filename)) return filename;
|
|
5230
|
-
}
|
|
5231
|
-
return false;
|
|
5232
|
-
});
|
|
5233
|
-
}
|
|
5234
|
-
};
|
|
5235
|
-
|
|
5236
5262
|
//#endregion
|
|
5237
5263
|
//#region src/migrate.ts
|
|
5238
5264
|
var Migrate = class {
|
|
@@ -5244,10 +5270,10 @@ var Migrate = class {
|
|
|
5244
5270
|
}
|
|
5245
5271
|
/**
|
|
5246
5272
|
* Runs all pending migrations
|
|
5247
|
-
*
|
|
5248
|
-
* @param config
|
|
5249
|
-
* @param options
|
|
5250
|
-
* @param destroyAll
|
|
5273
|
+
*
|
|
5274
|
+
* @param config
|
|
5275
|
+
* @param options
|
|
5276
|
+
* @param destroyAll
|
|
5251
5277
|
*/
|
|
5252
5278
|
async run(config, options = {}, destroyAll = false) {
|
|
5253
5279
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5261,10 +5287,10 @@ var Migrate = class {
|
|
|
5261
5287
|
}
|
|
5262
5288
|
/**
|
|
5263
5289
|
* Rollback the last migration
|
|
5264
|
-
*
|
|
5265
|
-
* @param config
|
|
5266
|
-
* @param options
|
|
5267
|
-
* @param destroyAll
|
|
5290
|
+
*
|
|
5291
|
+
* @param config
|
|
5292
|
+
* @param options
|
|
5293
|
+
* @param destroyAll
|
|
5268
5294
|
*/
|
|
5269
5295
|
async rollback(config, options = {}, destroyAll = false) {
|
|
5270
5296
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5278,10 +5304,10 @@ var Migrate = class {
|
|
|
5278
5304
|
}
|
|
5279
5305
|
/**
|
|
5280
5306
|
* Rollback all database migrations
|
|
5281
|
-
*
|
|
5282
|
-
* @param config
|
|
5283
|
-
* @param options
|
|
5284
|
-
* @param destroyAll
|
|
5307
|
+
*
|
|
5308
|
+
* @param config
|
|
5309
|
+
* @param options
|
|
5310
|
+
* @param destroyAll
|
|
5285
5311
|
*/
|
|
5286
5312
|
async reset(config, options = {}, destroyAll = false) {
|
|
5287
5313
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5296,10 +5322,10 @@ var Migrate = class {
|
|
|
5296
5322
|
}
|
|
5297
5323
|
/**
|
|
5298
5324
|
* Reset and re-run all migrations
|
|
5299
|
-
*
|
|
5300
|
-
* @param config
|
|
5301
|
-
* @param options
|
|
5302
|
-
* @param destroyAll
|
|
5325
|
+
*
|
|
5326
|
+
* @param config
|
|
5327
|
+
* @param options
|
|
5328
|
+
* @param destroyAll
|
|
5303
5329
|
*/
|
|
5304
5330
|
async refresh(config, options = {}, destroyAll = false) {
|
|
5305
5331
|
await this.reset(config, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5308,10 +5334,10 @@ var Migrate = class {
|
|
|
5308
5334
|
}
|
|
5309
5335
|
/**
|
|
5310
5336
|
* Drop all tables and re-run all migrations
|
|
5311
|
-
*
|
|
5312
|
-
* @param config
|
|
5313
|
-
* @param options
|
|
5314
|
-
* @param destroyAll
|
|
5337
|
+
*
|
|
5338
|
+
* @param config
|
|
5339
|
+
* @param options
|
|
5340
|
+
* @param destroyAll
|
|
5315
5341
|
*/
|
|
5316
5342
|
async fresh(config, options = {}, destroyAll = false) {
|
|
5317
5343
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5321,8 +5347,8 @@ var Migrate = class {
|
|
|
5321
5347
|
}
|
|
5322
5348
|
/**
|
|
5323
5349
|
* Prepares the database for migration
|
|
5324
|
-
*
|
|
5325
|
-
* @param migrator
|
|
5350
|
+
*
|
|
5351
|
+
* @param migrator
|
|
5326
5352
|
*/
|
|
5327
5353
|
async prepareDatabase(migrator) {
|
|
5328
5354
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5334,11 +5360,11 @@ var Migrate = class {
|
|
|
5334
5360
|
}
|
|
5335
5361
|
/**
|
|
5336
5362
|
* Check the status of available migrations
|
|
5337
|
-
*
|
|
5338
|
-
* @param config
|
|
5339
|
-
* @param options
|
|
5340
|
-
* @param destroyAll
|
|
5341
|
-
* @returns
|
|
5363
|
+
*
|
|
5364
|
+
* @param config
|
|
5365
|
+
* @param options
|
|
5366
|
+
* @param destroyAll
|
|
5367
|
+
* @returns
|
|
5342
5368
|
*/
|
|
5343
5369
|
async status(config, options = {}, destroyAll = false) {
|
|
5344
5370
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5365,9 +5391,9 @@ var Migrate = class {
|
|
|
5365
5391
|
}
|
|
5366
5392
|
/**
|
|
5367
5393
|
* Setup the database connection
|
|
5368
|
-
*
|
|
5369
|
-
* @param config
|
|
5370
|
-
* @returns
|
|
5394
|
+
*
|
|
5395
|
+
* @param config
|
|
5396
|
+
* @returns
|
|
5371
5397
|
*/
|
|
5372
5398
|
async setupConnection(config) {
|
|
5373
5399
|
var _config$migrations;
|
|
@@ -5399,6 +5425,112 @@ var Migration = class extends Inference {
|
|
|
5399
5425
|
};
|
|
5400
5426
|
var migration_default = Migration;
|
|
5401
5427
|
|
|
5428
|
+
//#endregion
|
|
5429
|
+
//#region src/seeders/seeder.ts
|
|
5430
|
+
var Seeder = class {};
|
|
5431
|
+
var seeder_default = Seeder;
|
|
5432
|
+
|
|
5433
|
+
//#endregion
|
|
5434
|
+
//#region src/seeders/runner.ts
|
|
5435
|
+
async function glob(folderPath) {
|
|
5436
|
+
const { default: escalade$1 } = await import("escalade");
|
|
5437
|
+
const entries = [];
|
|
5438
|
+
await escalade$1(folderPath, async (dir, names) => {
|
|
5439
|
+
await Promise.all(names.map(async (name) => {
|
|
5440
|
+
const p = path.default.join(dir, name);
|
|
5441
|
+
try {
|
|
5442
|
+
await (0, node_fs_promises.access)(p);
|
|
5443
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
5444
|
+
} catch {}
|
|
5445
|
+
}));
|
|
5446
|
+
return "";
|
|
5447
|
+
});
|
|
5448
|
+
return entries;
|
|
5449
|
+
}
|
|
5450
|
+
var SeederRunner = class {
|
|
5451
|
+
resolver;
|
|
5452
|
+
connection;
|
|
5453
|
+
paths = [];
|
|
5454
|
+
constructor(resolver) {
|
|
5455
|
+
this.resolver = resolver;
|
|
5456
|
+
}
|
|
5457
|
+
path(p) {
|
|
5458
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
5459
|
+
}
|
|
5460
|
+
getPaths() {
|
|
5461
|
+
return this.paths;
|
|
5462
|
+
}
|
|
5463
|
+
resolveConnection(connection) {
|
|
5464
|
+
var _getInstance, _ref, _instance$connections;
|
|
5465
|
+
const name = connection || this.connection || "default";
|
|
5466
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
5467
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
5468
|
+
/** noop */
|
|
5469
|
+
});
|
|
5470
|
+
return this.resolver.fire(name);
|
|
5471
|
+
}
|
|
5472
|
+
setConnection(connection) {
|
|
5473
|
+
this.connection = connection;
|
|
5474
|
+
return this;
|
|
5475
|
+
}
|
|
5476
|
+
async getSeederFiles(paths) {
|
|
5477
|
+
const files = [];
|
|
5478
|
+
for (const p of paths) {
|
|
5479
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
5480
|
+
files.push(p);
|
|
5481
|
+
continue;
|
|
5482
|
+
}
|
|
5483
|
+
files.push(...await glob(p));
|
|
5484
|
+
}
|
|
5485
|
+
return files;
|
|
5486
|
+
}
|
|
5487
|
+
async resolvePath(filePath) {
|
|
5488
|
+
try {
|
|
5489
|
+
const mod = await import(filePath);
|
|
5490
|
+
return new (mod.default ?? mod.Seeder)();
|
|
5491
|
+
} catch {
|
|
5492
|
+
return null;
|
|
5493
|
+
}
|
|
5494
|
+
}
|
|
5495
|
+
async run(paths, connection) {
|
|
5496
|
+
const files = await this.getSeederFiles(paths);
|
|
5497
|
+
const conn = this.resolveConnection(connection);
|
|
5498
|
+
for (const file of files) {
|
|
5499
|
+
const seeder = await this.resolvePath(file);
|
|
5500
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
5501
|
+
}
|
|
5502
|
+
}
|
|
5503
|
+
};
|
|
5504
|
+
var runner_default = SeederRunner;
|
|
5505
|
+
|
|
5506
|
+
//#endregion
|
|
5507
|
+
//#region src/seeders/seeder-creator.ts
|
|
5508
|
+
var SeederCreator = class {
|
|
5509
|
+
constructor(customStubPath) {
|
|
5510
|
+
this.customStubPath = customStubPath;
|
|
5511
|
+
}
|
|
5512
|
+
async create(dir, name, type = "js") {
|
|
5513
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
5514
|
+
const stubPath = this.getStubPath(type);
|
|
5515
|
+
let stub = await (0, node_fs_promises.readFile)(stubPath, "utf-8");
|
|
5516
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
5517
|
+
const filePath = path.default.join(dir, `${name}.${type}`);
|
|
5518
|
+
await (0, node_fs_promises.writeFile)(filePath, stub);
|
|
5519
|
+
return filePath;
|
|
5520
|
+
}
|
|
5521
|
+
getStubPath(type) {
|
|
5522
|
+
if (this.customStubPath) return path.default.join(this.customStubPath, `seeder-${type}.stub`);
|
|
5523
|
+
const __dirname$1 = this.getDirname({});
|
|
5524
|
+
return path.default.join(__dirname$1, "stubs", `seeder-${type}.stub`);
|
|
5525
|
+
}
|
|
5526
|
+
getDirname(meta) {
|
|
5527
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
5528
|
+
if (meta && meta.url) return (0, node_path.dirname)((0, node_url.fileURLToPath)(meta.url));
|
|
5529
|
+
throw new Error("Unable to determine dirname");
|
|
5530
|
+
}
|
|
5531
|
+
};
|
|
5532
|
+
var seeder_creator_default = SeederCreator;
|
|
5533
|
+
|
|
5402
5534
|
//#endregion
|
|
5403
5535
|
//#region src/pivot.ts
|
|
5404
5536
|
var pivot_default = Pivot;
|
|
@@ -5574,7 +5706,7 @@ const make = (model, data, options = {}) => {
|
|
|
5574
5706
|
return model.make(data);
|
|
5575
5707
|
};
|
|
5576
5708
|
const makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
5577
|
-
const makePaginator = (model, data) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5709
|
+
const makePaginator = (model, data, _) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5578
5710
|
|
|
5579
5711
|
//#endregion
|
|
5580
5712
|
exports.Attribute = attribute_default;
|
|
@@ -5592,6 +5724,9 @@ exports.Pivot = pivot_default;
|
|
|
5592
5724
|
exports.QueryBuilder = query_builder_default;
|
|
5593
5725
|
exports.RelationNotFoundError = RelationNotFoundError;
|
|
5594
5726
|
exports.Scope = scope_default;
|
|
5727
|
+
exports.Seeder = seeder_default;
|
|
5728
|
+
exports.SeederCreator = seeder_creator_default;
|
|
5729
|
+
exports.SeederRunner = runner_default;
|
|
5595
5730
|
exports.SoftDeletes = soft_deletes_default;
|
|
5596
5731
|
exports.arquebus = arquebus_default;
|
|
5597
5732
|
exports.compose = compose;
|