@h3ravel/arquebus 0.5.0 → 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 +196 -144
- package/bin/index.js +177 -94
- 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 +7 -7
- package/dist/browser/index.d.ts +7 -7
- package/dist/browser/index.js +9 -9
- package/dist/index.cjs +252 -121
- package/dist/index.d.cts +40 -8
- package/dist/index.d.ts +40 -8
- package/dist/index.js +245 -119
- package/dist/inspector/index.cjs +105 -33
- package/dist/inspector/index.js +102 -33
- package/dist/migrations/index.cjs +144 -126
- package/dist/migrations/index.d.cts +10 -10
- package/dist/migrations/index.d.ts +10 -10
- package/dist/migrations/index.js +148 -130
- 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 +14 -3
- package/types/builder.ts +153 -80
- package/types/container.ts +79 -66
- package/types/generics.ts +75 -37
- package/types/modeling.ts +213 -158
- package/types/query-builder.ts +221 -191
- package/types/query-methods.ts +145 -109
- package/types/utils.ts +64 -56
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);
|
|
@@ -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) {
|
|
@@ -4988,7 +5063,7 @@ var SchemaInspector = class {
|
|
|
4988
5063
|
|
|
4989
5064
|
//#endregion
|
|
4990
5065
|
//#region src/migrations/migrator.ts
|
|
4991
|
-
async function glob(folderPath) {
|
|
5066
|
+
async function glob$1(folderPath) {
|
|
4992
5067
|
const files = await node_fs_promises.default.readdir(folderPath);
|
|
4993
5068
|
const allFiles = [];
|
|
4994
5069
|
for (const file of files) {
|
|
@@ -4996,7 +5071,7 @@ async function glob(folderPath) {
|
|
|
4996
5071
|
const stats = await node_fs_promises.default.stat(filePath);
|
|
4997
5072
|
if (stats.isFile()) allFiles.push(filePath);
|
|
4998
5073
|
else if (stats.isDirectory()) {
|
|
4999
|
-
const subFiles = await glob(filePath);
|
|
5074
|
+
const subFiles = await glob$1(filePath);
|
|
5000
5075
|
allFiles.push(...subFiles);
|
|
5001
5076
|
}
|
|
5002
5077
|
}
|
|
@@ -5090,9 +5165,9 @@ var Migrator = class {
|
|
|
5090
5165
|
}
|
|
5091
5166
|
/**
|
|
5092
5167
|
* Drop all tables and re-run all migrations
|
|
5093
|
-
*
|
|
5094
|
-
* @param paths
|
|
5095
|
-
* @param options
|
|
5168
|
+
*
|
|
5169
|
+
* @param paths
|
|
5170
|
+
* @param options
|
|
5096
5171
|
*/
|
|
5097
5172
|
async fresh(paths, options) {
|
|
5098
5173
|
/** Initialise connections */
|
|
@@ -5139,7 +5214,7 @@ var Migrator = class {
|
|
|
5139
5214
|
files.push(p);
|
|
5140
5215
|
continue;
|
|
5141
5216
|
}
|
|
5142
|
-
files.push(...await glob(p));
|
|
5217
|
+
files.push(...await glob$1(p));
|
|
5143
5218
|
}
|
|
5144
5219
|
return files.filter(Boolean).reduce((result, file) => {
|
|
5145
5220
|
result[this.getMigrationName(file)] = file;
|
|
@@ -5184,59 +5259,6 @@ var Migrator = class {
|
|
|
5184
5259
|
};
|
|
5185
5260
|
var migrator_default = Migrator;
|
|
5186
5261
|
|
|
5187
|
-
//#endregion
|
|
5188
|
-
//#region src/cli/utils.ts
|
|
5189
|
-
const join = path.default.join;
|
|
5190
|
-
var Utils = class {
|
|
5191
|
-
/**
|
|
5192
|
-
* Wraps text with chalk
|
|
5193
|
-
*
|
|
5194
|
-
* @param txt
|
|
5195
|
-
* @param color
|
|
5196
|
-
* @returns
|
|
5197
|
-
*/
|
|
5198
|
-
static textFormat(txt, color) {
|
|
5199
|
-
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
5200
|
-
}
|
|
5201
|
-
static findModulePkg(moduleId, cwd) {
|
|
5202
|
-
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
5203
|
-
let packageName = "";
|
|
5204
|
-
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
5205
|
-
packageName += parts.shift();
|
|
5206
|
-
const packageJson = path.default.join(packageName, "package.json");
|
|
5207
|
-
const resolved = resolve_from.default.silent(cwd ?? process.cwd(), packageJson);
|
|
5208
|
-
if (!resolved) return;
|
|
5209
|
-
return path.default.join(path.default.dirname(resolved), parts.join("/"));
|
|
5210
|
-
}
|
|
5211
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path$4) {
|
|
5212
|
-
if (path$4) return [join(cwd, path$4)];
|
|
5213
|
-
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
5214
|
-
}
|
|
5215
|
-
/**
|
|
5216
|
-
* Check if file exists
|
|
5217
|
-
*
|
|
5218
|
-
* @param path
|
|
5219
|
-
* @returns
|
|
5220
|
-
*/
|
|
5221
|
-
static async fileExists(path$4) {
|
|
5222
|
-
try {
|
|
5223
|
-
await (0, fs_promises.access)(path$4);
|
|
5224
|
-
return true;
|
|
5225
|
-
} catch {
|
|
5226
|
-
return false;
|
|
5227
|
-
}
|
|
5228
|
-
}
|
|
5229
|
-
static findUpConfig(cwd, name, extensions) {
|
|
5230
|
-
return (0, escalade_sync.default)(cwd, (_dir, names) => {
|
|
5231
|
-
for (const ext of extensions) {
|
|
5232
|
-
const filename = `${name}.${ext}`;
|
|
5233
|
-
if (names.includes(filename)) return filename;
|
|
5234
|
-
}
|
|
5235
|
-
return false;
|
|
5236
|
-
});
|
|
5237
|
-
}
|
|
5238
|
-
};
|
|
5239
|
-
|
|
5240
5262
|
//#endregion
|
|
5241
5263
|
//#region src/migrate.ts
|
|
5242
5264
|
var Migrate = class {
|
|
@@ -5248,10 +5270,10 @@ var Migrate = class {
|
|
|
5248
5270
|
}
|
|
5249
5271
|
/**
|
|
5250
5272
|
* Runs all pending migrations
|
|
5251
|
-
*
|
|
5252
|
-
* @param config
|
|
5253
|
-
* @param options
|
|
5254
|
-
* @param destroyAll
|
|
5273
|
+
*
|
|
5274
|
+
* @param config
|
|
5275
|
+
* @param options
|
|
5276
|
+
* @param destroyAll
|
|
5255
5277
|
*/
|
|
5256
5278
|
async run(config, options = {}, destroyAll = false) {
|
|
5257
5279
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5265,10 +5287,10 @@ var Migrate = class {
|
|
|
5265
5287
|
}
|
|
5266
5288
|
/**
|
|
5267
5289
|
* Rollback the last migration
|
|
5268
|
-
*
|
|
5269
|
-
* @param config
|
|
5270
|
-
* @param options
|
|
5271
|
-
* @param destroyAll
|
|
5290
|
+
*
|
|
5291
|
+
* @param config
|
|
5292
|
+
* @param options
|
|
5293
|
+
* @param destroyAll
|
|
5272
5294
|
*/
|
|
5273
5295
|
async rollback(config, options = {}, destroyAll = false) {
|
|
5274
5296
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5282,10 +5304,10 @@ var Migrate = class {
|
|
|
5282
5304
|
}
|
|
5283
5305
|
/**
|
|
5284
5306
|
* Rollback all database migrations
|
|
5285
|
-
*
|
|
5286
|
-
* @param config
|
|
5287
|
-
* @param options
|
|
5288
|
-
* @param destroyAll
|
|
5307
|
+
*
|
|
5308
|
+
* @param config
|
|
5309
|
+
* @param options
|
|
5310
|
+
* @param destroyAll
|
|
5289
5311
|
*/
|
|
5290
5312
|
async reset(config, options = {}, destroyAll = false) {
|
|
5291
5313
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5300,10 +5322,10 @@ var Migrate = class {
|
|
|
5300
5322
|
}
|
|
5301
5323
|
/**
|
|
5302
5324
|
* Reset and re-run all migrations
|
|
5303
|
-
*
|
|
5304
|
-
* @param config
|
|
5305
|
-
* @param options
|
|
5306
|
-
* @param destroyAll
|
|
5325
|
+
*
|
|
5326
|
+
* @param config
|
|
5327
|
+
* @param options
|
|
5328
|
+
* @param destroyAll
|
|
5307
5329
|
*/
|
|
5308
5330
|
async refresh(config, options = {}, destroyAll = false) {
|
|
5309
5331
|
await this.reset(config, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5312,10 +5334,10 @@ var Migrate = class {
|
|
|
5312
5334
|
}
|
|
5313
5335
|
/**
|
|
5314
5336
|
* Drop all tables and re-run all migrations
|
|
5315
|
-
*
|
|
5316
|
-
* @param config
|
|
5317
|
-
* @param options
|
|
5318
|
-
* @param destroyAll
|
|
5337
|
+
*
|
|
5338
|
+
* @param config
|
|
5339
|
+
* @param options
|
|
5340
|
+
* @param destroyAll
|
|
5319
5341
|
*/
|
|
5320
5342
|
async fresh(config, options = {}, destroyAll = false) {
|
|
5321
5343
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5325,8 +5347,8 @@ var Migrate = class {
|
|
|
5325
5347
|
}
|
|
5326
5348
|
/**
|
|
5327
5349
|
* Prepares the database for migration
|
|
5328
|
-
*
|
|
5329
|
-
* @param migrator
|
|
5350
|
+
*
|
|
5351
|
+
* @param migrator
|
|
5330
5352
|
*/
|
|
5331
5353
|
async prepareDatabase(migrator) {
|
|
5332
5354
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5338,11 +5360,11 @@ var Migrate = class {
|
|
|
5338
5360
|
}
|
|
5339
5361
|
/**
|
|
5340
5362
|
* Check the status of available migrations
|
|
5341
|
-
*
|
|
5342
|
-
* @param config
|
|
5343
|
-
* @param options
|
|
5344
|
-
* @param destroyAll
|
|
5345
|
-
* @returns
|
|
5363
|
+
*
|
|
5364
|
+
* @param config
|
|
5365
|
+
* @param options
|
|
5366
|
+
* @param destroyAll
|
|
5367
|
+
* @returns
|
|
5346
5368
|
*/
|
|
5347
5369
|
async status(config, options = {}, destroyAll = false) {
|
|
5348
5370
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5369,9 +5391,9 @@ var Migrate = class {
|
|
|
5369
5391
|
}
|
|
5370
5392
|
/**
|
|
5371
5393
|
* Setup the database connection
|
|
5372
|
-
*
|
|
5373
|
-
* @param config
|
|
5374
|
-
* @returns
|
|
5394
|
+
*
|
|
5395
|
+
* @param config
|
|
5396
|
+
* @returns
|
|
5375
5397
|
*/
|
|
5376
5398
|
async setupConnection(config) {
|
|
5377
5399
|
var _config$migrations;
|
|
@@ -5403,6 +5425,112 @@ var Migration = class extends Inference {
|
|
|
5403
5425
|
};
|
|
5404
5426
|
var migration_default = Migration;
|
|
5405
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
|
+
|
|
5406
5534
|
//#endregion
|
|
5407
5535
|
//#region src/pivot.ts
|
|
5408
5536
|
var pivot_default = Pivot;
|
|
@@ -5596,6 +5724,9 @@ exports.Pivot = pivot_default;
|
|
|
5596
5724
|
exports.QueryBuilder = query_builder_default;
|
|
5597
5725
|
exports.RelationNotFoundError = RelationNotFoundError;
|
|
5598
5726
|
exports.Scope = scope_default;
|
|
5727
|
+
exports.Seeder = seeder_default;
|
|
5728
|
+
exports.SeederCreator = seeder_creator_default;
|
|
5729
|
+
exports.SeederRunner = runner_default;
|
|
5599
5730
|
exports.SoftDeletes = soft_deletes_default;
|
|
5600
5731
|
exports.arquebus = arquebus_default;
|
|
5601
5732
|
exports.compose = compose;
|
package/dist/index.d.cts
CHANGED
|
@@ -98,7 +98,7 @@ declare class Builder<M extends Model$1 = Model$1, R = IModel | ICollection<M>>
|
|
|
98
98
|
enforceOrderBy(this: any): void;
|
|
99
99
|
clone(this: any): any;
|
|
100
100
|
forPage(this: any, page: number, perPage?: number): any;
|
|
101
|
-
insert(...args: Parameters<typeof
|
|
101
|
+
insert(...args: Parameters<typeof this.query.insert>): Promise<any>;
|
|
102
102
|
update<T extends TGeneric>(values: T): Promise<any>;
|
|
103
103
|
increment(column: string, amount?: number, extra?: {}): Promise<any>;
|
|
104
104
|
decrement(column: string, amount?: number, extra?: {}): Promise<any>;
|
|
@@ -437,7 +437,7 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
|
|
|
437
437
|
chunk(count: number, callback: TFunction): Promise<boolean>;
|
|
438
438
|
paginate<F extends IPaginatorParams>(this: any, page: number | undefined, perPage: number | undefined, _pageName: string, _page: number): Promise<IPaginator<M, F>>;
|
|
439
439
|
forPage(this: any, page?: number, perPage?: number): any;
|
|
440
|
-
toSQL(...args: Parameters<typeof
|
|
440
|
+
toSQL(...args: Parameters<typeof this.connector.toSQL>): Knex.Sql;
|
|
441
441
|
count(column: string): Promise<number>;
|
|
442
442
|
min(column: string): Promise<number>;
|
|
443
443
|
max(column: string): Promise<number>;
|
|
@@ -445,9 +445,9 @@ declare class QueryBuilder<M extends Model$1 = Model$1, R = M[] | M> extends Inf
|
|
|
445
445
|
avg(column: string): Promise<number>;
|
|
446
446
|
clone(): IQueryBuilder<M, R>;
|
|
447
447
|
delete(): Promise<number | boolean>;
|
|
448
|
-
insert(...args: Parameters<typeof
|
|
449
|
-
update(...args: Parameters<typeof
|
|
450
|
-
destroy(...args: Parameters<typeof
|
|
448
|
+
insert(...args: Parameters<typeof this.connector.insert>): Promise<unknown>;
|
|
449
|
+
update(...args: Parameters<typeof this.connector.update>): Promise<number>;
|
|
450
|
+
destroy(...args: Parameters<typeof this.connector.destroy>): Promise<number>;
|
|
451
451
|
get _statements(): IStatement[] & any[];
|
|
452
452
|
get _single(): any;
|
|
453
453
|
get from(): Knex.Table<any, any> & Knex.Table<any, any[]>;
|
|
@@ -473,7 +473,7 @@ declare class Relation$1 {
|
|
|
473
473
|
getEager(): any;
|
|
474
474
|
get(columns?: string | string[]): Promise<any>;
|
|
475
475
|
first(columns?: string[]): Promise<any>;
|
|
476
|
-
paginate(...args:
|
|
476
|
+
paginate(...args: unknown[]): Promise<any>;
|
|
477
477
|
count(...args: any[]): Promise<any>;
|
|
478
478
|
toSql(): string;
|
|
479
479
|
addConstraints(): void;
|
|
@@ -4629,7 +4629,7 @@ type ReturnTypeOfMethod<T, K extends keyof T> = T[K] extends ((...args: any[]) =
|
|
|
4629
4629
|
type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ? `${T}${Capitalize<SnakeToCamelCase<U>>}` : S;
|
|
4630
4630
|
type CamelToSnakeCase<S extends string> = S extends `${infer T}${infer U}` ? U extends Uncapitalize<U> ? `${Uncapitalize<T>}${CamelToSnakeCase<U>}` : `${Uncapitalize<T>}_${CamelToSnakeCase<U>}` : S;
|
|
4631
4631
|
type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends ((...args: any[]) => any) ? K : never }[keyof T];
|
|
4632
|
-
type RelationNames<T> = FunctionPropertyNames<T> extends infer R ? R extends `relation${infer P}` ? P extends
|
|
4632
|
+
type RelationNames<T> = FunctionPropertyNames<T> extends infer R ? R extends `relation${infer P}` ? P extends 'sToData' | 'loaded' ? never : CamelToSnakeCase<P> : never : never;
|
|
4633
4633
|
type MixinConstructor<T = TGeneric> = new (...args: any[]) => T;
|
|
4634
4634
|
//#endregion
|
|
4635
4635
|
//#region src/browser/collection.d.ts
|
|
@@ -4961,6 +4961,38 @@ declare class Migrate {
|
|
|
4961
4961
|
}>;
|
|
4962
4962
|
}
|
|
4963
4963
|
//#endregion
|
|
4964
|
+
//#region src/seeders/seeder.d.ts
|
|
4965
|
+
declare abstract class Seeder {
|
|
4966
|
+
/**
|
|
4967
|
+
* Run the database seeds
|
|
4968
|
+
*/
|
|
4969
|
+
abstract run(connection: QueryBuilder): Promise<void>;
|
|
4970
|
+
}
|
|
4971
|
+
//#endregion
|
|
4972
|
+
//#region src/seeders/runner.d.ts
|
|
4973
|
+
declare class SeederRunner {
|
|
4974
|
+
resolver: typeof arquebus;
|
|
4975
|
+
connection: TBaseConfig['client'];
|
|
4976
|
+
paths: string[];
|
|
4977
|
+
constructor(resolver: typeof arquebus);
|
|
4978
|
+
path(p: string): void;
|
|
4979
|
+
getPaths(): string[];
|
|
4980
|
+
resolveConnection(connection?: TBaseConfig['client']): QueryBuilder;
|
|
4981
|
+
setConnection(connection: TBaseConfig['client']): this;
|
|
4982
|
+
getSeederFiles(paths: string[]): Promise<string[]>;
|
|
4983
|
+
resolvePath(filePath: string): Promise<Seeder | null>;
|
|
4984
|
+
run(paths: string[], connection?: TBaseConfig['client']): Promise<void>;
|
|
4985
|
+
}
|
|
4986
|
+
//#endregion
|
|
4987
|
+
//#region src/seeders/seeder-creator.d.ts
|
|
4988
|
+
declare class SeederCreator {
|
|
4989
|
+
private customStubPath?;
|
|
4990
|
+
constructor(customStubPath?: string | undefined);
|
|
4991
|
+
create(dir: string, name: string, type?: 'js' | 'ts'): Promise<string>;
|
|
4992
|
+
getStubPath(type: 'js' | 'ts'): string;
|
|
4993
|
+
getDirname(meta: ImportMeta | null): string;
|
|
4994
|
+
}
|
|
4995
|
+
//#endregion
|
|
4964
4996
|
//#region src/soft-deletes.d.ts
|
|
4965
4997
|
declare const softDeletes: <TBase extends MixinConstructor>(Model: TBase) => {
|
|
4966
4998
|
new (...args: any[]): {
|
|
@@ -5094,4 +5126,4 @@ declare const make: <M extends Model$1 | typeof Model$1>(model: M, data: TGeneri
|
|
|
5094
5126
|
declare const makeCollection: <M extends Model$1 | typeof Model$1>(model: M, data: TGeneric) => Collection<Model$1 | Model$2>;
|
|
5095
5127
|
declare const makePaginator: <M extends Model$1 | typeof Model$1>(model: M, data: TGeneric, _: any) => Paginator<Model$1, IPaginatorParams>;
|
|
5096
5128
|
//#endregion
|
|
5097
|
-
export { Attribute, Builder, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Migrate, Migration, Model$1 as Model, ModelNotFoundError, Paginator, Pivot, QueryBuilder, RelationNotFoundError, Scope, softDeletes as SoftDeletes, arquebus, compose, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };
|
|
5129
|
+
export { Attribute, Builder, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Migrate, Migration, Model$1 as Model, ModelNotFoundError, Paginator, Pivot, QueryBuilder, RelationNotFoundError, Scope, Seeder, SeederCreator, SeederRunner, softDeletes as SoftDeletes, arquebus, compose, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };
|