@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/migrations/index.js
CHANGED
|
@@ -7,11 +7,11 @@ import collect, { Collection, collect as collect$1 } from "collect.js";
|
|
|
7
7
|
import Knex$1 from "knex";
|
|
8
8
|
import path from "path";
|
|
9
9
|
import { existsSync } from "fs";
|
|
10
|
-
import pluralize from "pluralize";
|
|
11
|
-
import fs, { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
12
10
|
import { access } from "fs/promises";
|
|
13
11
|
import escalade from "escalade/sync";
|
|
14
12
|
import resolveFrom from "resolve-from";
|
|
13
|
+
import pluralize from "pluralize";
|
|
14
|
+
import fs, { copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
15
15
|
import path$1, { dirname } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
|
|
@@ -1404,7 +1404,7 @@ var InvalidArgumentError = class extends BaseError {};
|
|
|
1404
1404
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
1405
1405
|
/**
|
|
1406
1406
|
* Compose function that merges multiple classes and mixins
|
|
1407
|
-
*
|
|
1407
|
+
*
|
|
1408
1408
|
* @example
|
|
1409
1409
|
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
1410
1410
|
* return class extends Base {
|
|
@@ -1441,10 +1441,10 @@ var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
|
1441
1441
|
* console.log(user.pluginMethod('w')) // "plugin"
|
|
1442
1442
|
* console.log(user.pluginMethod()) // "plugin"
|
|
1443
1443
|
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
1444
|
-
*
|
|
1445
|
-
* @param Base
|
|
1446
|
-
* @param mixins
|
|
1447
|
-
* @returns
|
|
1444
|
+
*
|
|
1445
|
+
* @param Base
|
|
1446
|
+
* @param mixins
|
|
1447
|
+
* @returns
|
|
1448
1448
|
*/
|
|
1449
1449
|
function compose$1(Base, ...mixins) {
|
|
1450
1450
|
/**
|
|
@@ -1498,10 +1498,10 @@ const getSetterMethod = (attr) => {
|
|
|
1498
1498
|
};
|
|
1499
1499
|
/**
|
|
1500
1500
|
* Tap into a model a collection instance
|
|
1501
|
-
*
|
|
1502
|
-
* @param instance
|
|
1503
|
-
* @param callback
|
|
1504
|
-
* @returns
|
|
1501
|
+
*
|
|
1502
|
+
* @param instance
|
|
1503
|
+
* @param callback
|
|
1504
|
+
* @returns
|
|
1505
1505
|
*/
|
|
1506
1506
|
const tap = (instance, callback) => {
|
|
1507
1507
|
const result = callback(instance);
|
|
@@ -2952,6 +2952,59 @@ var QueryBuilder = class QueryBuilder extends Inference$2 {
|
|
|
2952
2952
|
};
|
|
2953
2953
|
var query_builder_default = QueryBuilder;
|
|
2954
2954
|
|
|
2955
|
+
//#endregion
|
|
2956
|
+
//#region src/cli/utils.ts
|
|
2957
|
+
const join = path.join;
|
|
2958
|
+
var Utils = class {
|
|
2959
|
+
/**
|
|
2960
|
+
* Wraps text with chalk
|
|
2961
|
+
*
|
|
2962
|
+
* @param txt
|
|
2963
|
+
* @param color
|
|
2964
|
+
* @returns
|
|
2965
|
+
*/
|
|
2966
|
+
static textFormat(txt, color) {
|
|
2967
|
+
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
2968
|
+
}
|
|
2969
|
+
static findModulePkg(moduleId, cwd) {
|
|
2970
|
+
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
2971
|
+
let packageName = "";
|
|
2972
|
+
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
2973
|
+
packageName += parts.shift();
|
|
2974
|
+
const packageJson = path.join(packageName, "package.json");
|
|
2975
|
+
const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
|
|
2976
|
+
if (!resolved) return;
|
|
2977
|
+
return path.join(path.dirname(resolved), parts.join("/"));
|
|
2978
|
+
}
|
|
2979
|
+
static async getMigrationPaths(cwd, migrator, defaultPath, path$2) {
|
|
2980
|
+
if (path$2) return [join(cwd, path$2)];
|
|
2981
|
+
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
2982
|
+
}
|
|
2983
|
+
/**
|
|
2984
|
+
* Check if file exists
|
|
2985
|
+
*
|
|
2986
|
+
* @param path
|
|
2987
|
+
* @returns
|
|
2988
|
+
*/
|
|
2989
|
+
static async fileExists(path$2) {
|
|
2990
|
+
try {
|
|
2991
|
+
await access(path$2);
|
|
2992
|
+
return true;
|
|
2993
|
+
} catch {
|
|
2994
|
+
return false;
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
static findUpConfig(cwd, name, extensions) {
|
|
2998
|
+
return escalade(cwd, (_dir, names) => {
|
|
2999
|
+
for (const ext of extensions) {
|
|
3000
|
+
const filename = `${name}.${ext}`;
|
|
3001
|
+
if (names.includes(filename)) return filename;
|
|
3002
|
+
}
|
|
3003
|
+
return false;
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
};
|
|
3007
|
+
|
|
2955
3008
|
//#endregion
|
|
2956
3009
|
//#region src/arquebus.ts
|
|
2957
3010
|
var arquebus = class arquebus {
|
|
@@ -2973,22 +3026,22 @@ var arquebus = class arquebus {
|
|
|
2973
3026
|
return this.instance;
|
|
2974
3027
|
}
|
|
2975
3028
|
/**
|
|
2976
|
-
* Initialize a new database connection
|
|
2977
|
-
*
|
|
2978
|
-
* @returns
|
|
3029
|
+
* Initialize a new database connection
|
|
3030
|
+
*
|
|
3031
|
+
* @returns
|
|
2979
3032
|
*/
|
|
2980
3033
|
static fire(connection = null) {
|
|
2981
3034
|
return this.getInstance().getConnection(connection);
|
|
2982
3035
|
}
|
|
2983
3036
|
/**
|
|
2984
|
-
* Initialize a new database connection
|
|
2985
|
-
*
|
|
3037
|
+
* Initialize a new database connection
|
|
3038
|
+
*
|
|
2986
3039
|
* This is an alias of `arquebus.fire()` and will be removed in the future
|
|
2987
|
-
*
|
|
3040
|
+
*
|
|
2988
3041
|
* @deprecated since version 0.3.0
|
|
2989
3042
|
* @alias fire
|
|
2990
|
-
*
|
|
2991
|
-
* @returns
|
|
3043
|
+
*
|
|
3044
|
+
* @returns
|
|
2992
3045
|
*/
|
|
2993
3046
|
static connection(connection = null) {
|
|
2994
3047
|
return this.fire(connection);
|
|
@@ -3025,11 +3078,12 @@ var arquebus = class arquebus {
|
|
|
3025
3078
|
}
|
|
3026
3079
|
getConnection(name = null) {
|
|
3027
3080
|
name = name || "default";
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
this.
|
|
3081
|
+
const resolvedName = this.connections[name] ? name : "default";
|
|
3082
|
+
if (this.manager[resolvedName] === void 0) {
|
|
3083
|
+
const queryBuilder = new query_builder_default(this.connections[resolvedName], arquebus.getConnectorFactory());
|
|
3084
|
+
this.manager[resolvedName] = queryBuilder;
|
|
3031
3085
|
}
|
|
3032
|
-
return this.manager[
|
|
3086
|
+
return this.manager[resolvedName];
|
|
3033
3087
|
}
|
|
3034
3088
|
addConnection(config, name = "default") {
|
|
3035
3089
|
this.connections[name] = {
|
|
@@ -3046,13 +3100,13 @@ var arquebus = class arquebus {
|
|
|
3046
3100
|
}
|
|
3047
3101
|
/**
|
|
3048
3102
|
* Autoload the config file
|
|
3049
|
-
*
|
|
3050
|
-
* @param addConnection
|
|
3103
|
+
*
|
|
3104
|
+
* @param addConnection
|
|
3051
3105
|
* @default true
|
|
3052
|
-
* If set to `false` we will no attempt add the connection, we
|
|
3106
|
+
* If set to `false` we will no attempt add the connection, we
|
|
3053
3107
|
* will just go ahead and return the config
|
|
3054
|
-
*
|
|
3055
|
-
* @returns
|
|
3108
|
+
*
|
|
3109
|
+
* @returns
|
|
3056
3110
|
*/
|
|
3057
3111
|
static async autoLoad(addConnection = true) {
|
|
3058
3112
|
let config;
|
|
@@ -3069,6 +3123,23 @@ var arquebus = class arquebus {
|
|
|
3069
3123
|
if (addConnection) instance.addConnection(config, config.client);
|
|
3070
3124
|
return config;
|
|
3071
3125
|
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3126
|
+
const candidateDirs = [
|
|
3127
|
+
process.cwd(),
|
|
3128
|
+
path.join(process.cwd(), "test", "cli"),
|
|
3129
|
+
path.join(process.cwd(), "test")
|
|
3130
|
+
];
|
|
3131
|
+
for (const dir of candidateDirs) {
|
|
3132
|
+
const found = Utils.findUpConfig(dir, "arquebus.config", [
|
|
3133
|
+
"js",
|
|
3134
|
+
"ts",
|
|
3135
|
+
"cjs"
|
|
3136
|
+
]);
|
|
3137
|
+
if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
|
|
3138
|
+
config = (await import(found)).default;
|
|
3139
|
+
if (addConnection) instance.addConnection(config, config.client);
|
|
3140
|
+
return config;
|
|
3141
|
+
} else throw new Error("arquebus.config.ts found in production without build step");
|
|
3142
|
+
}
|
|
3072
3143
|
return {};
|
|
3073
3144
|
}
|
|
3074
3145
|
beginTransaction(connection = null) {
|
|
@@ -4761,6 +4832,12 @@ var Migration = class extends Inference {
|
|
|
4761
4832
|
};
|
|
4762
4833
|
var migration_default = Migration;
|
|
4763
4834
|
|
|
4835
|
+
//#endregion
|
|
4836
|
+
//#region node_modules/.pnpm/tsdown@0.15.6_typescript@5.9.3/node_modules/tsdown/esm-shims.js
|
|
4837
|
+
const getFilename = () => fileURLToPath(import.meta.url);
|
|
4838
|
+
const getDirname = () => path$1.dirname(getFilename());
|
|
4839
|
+
const __dirname = /* @__PURE__ */ getDirname();
|
|
4840
|
+
|
|
4764
4841
|
//#endregion
|
|
4765
4842
|
//#region src/inspector/dialects/sqlite.ts
|
|
4766
4843
|
function parseDefaultValue(value) {
|
|
@@ -5038,9 +5115,9 @@ var Migrator = class {
|
|
|
5038
5115
|
}
|
|
5039
5116
|
/**
|
|
5040
5117
|
* Drop all tables and re-run all migrations
|
|
5041
|
-
*
|
|
5042
|
-
* @param paths
|
|
5043
|
-
* @param options
|
|
5118
|
+
*
|
|
5119
|
+
* @param paths
|
|
5120
|
+
* @param options
|
|
5044
5121
|
*/
|
|
5045
5122
|
async fresh(paths, options) {
|
|
5046
5123
|
/** Initialise connections */
|
|
@@ -5132,59 +5209,6 @@ var Migrator = class {
|
|
|
5132
5209
|
};
|
|
5133
5210
|
var migrator_default = Migrator;
|
|
5134
5211
|
|
|
5135
|
-
//#endregion
|
|
5136
|
-
//#region src/cli/utils.ts
|
|
5137
|
-
const join = path.join;
|
|
5138
|
-
var Utils = class {
|
|
5139
|
-
/**
|
|
5140
|
-
* Wraps text with chalk
|
|
5141
|
-
*
|
|
5142
|
-
* @param txt
|
|
5143
|
-
* @param color
|
|
5144
|
-
* @returns
|
|
5145
|
-
*/
|
|
5146
|
-
static textFormat(txt, color) {
|
|
5147
|
-
return String(txt).split(":").map((e, i, a) => i == 0 && a.length > 1 ? color(" " + e + ": ") : e).join("");
|
|
5148
|
-
}
|
|
5149
|
-
static findModulePkg(moduleId, cwd) {
|
|
5150
|
-
const parts = moduleId.replace(/\\/g, "/").split("/");
|
|
5151
|
-
let packageName = "";
|
|
5152
|
-
if (parts.length > 0 && parts[0][0] === "@") packageName += parts.shift() + "/";
|
|
5153
|
-
packageName += parts.shift();
|
|
5154
|
-
const packageJson = path.join(packageName, "package.json");
|
|
5155
|
-
const resolved = resolveFrom.silent(cwd ?? process.cwd(), packageJson);
|
|
5156
|
-
if (!resolved) return;
|
|
5157
|
-
return path.join(path.dirname(resolved), parts.join("/"));
|
|
5158
|
-
}
|
|
5159
|
-
static async getMigrationPaths(cwd, migrator, defaultPath, path$2) {
|
|
5160
|
-
if (path$2) return [join(cwd, path$2)];
|
|
5161
|
-
return [...migrator.getPaths(), join(cwd, defaultPath)];
|
|
5162
|
-
}
|
|
5163
|
-
/**
|
|
5164
|
-
* Check if file exists
|
|
5165
|
-
*
|
|
5166
|
-
* @param path
|
|
5167
|
-
* @returns
|
|
5168
|
-
*/
|
|
5169
|
-
static async fileExists(path$2) {
|
|
5170
|
-
try {
|
|
5171
|
-
await access(path$2);
|
|
5172
|
-
return true;
|
|
5173
|
-
} catch {
|
|
5174
|
-
return false;
|
|
5175
|
-
}
|
|
5176
|
-
}
|
|
5177
|
-
static findUpConfig(cwd, name, extensions) {
|
|
5178
|
-
return escalade(cwd, (_dir, names) => {
|
|
5179
|
-
for (const ext of extensions) {
|
|
5180
|
-
const filename = `${name}.${ext}`;
|
|
5181
|
-
if (names.includes(filename)) return filename;
|
|
5182
|
-
}
|
|
5183
|
-
return false;
|
|
5184
|
-
});
|
|
5185
|
-
}
|
|
5186
|
-
};
|
|
5187
|
-
|
|
5188
5212
|
//#endregion
|
|
5189
5213
|
//#region src/migrate.ts
|
|
5190
5214
|
var Migrate = class {
|
|
@@ -5196,10 +5220,10 @@ var Migrate = class {
|
|
|
5196
5220
|
}
|
|
5197
5221
|
/**
|
|
5198
5222
|
* Runs all pending migrations
|
|
5199
|
-
*
|
|
5200
|
-
* @param config
|
|
5201
|
-
* @param options
|
|
5202
|
-
* @param destroyAll
|
|
5223
|
+
*
|
|
5224
|
+
* @param config
|
|
5225
|
+
* @param options
|
|
5226
|
+
* @param destroyAll
|
|
5203
5227
|
*/
|
|
5204
5228
|
async run(config, options = {}, destroyAll = false) {
|
|
5205
5229
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5213,10 +5237,10 @@ var Migrate = class {
|
|
|
5213
5237
|
}
|
|
5214
5238
|
/**
|
|
5215
5239
|
* Rollback the last migration
|
|
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 rollback(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 all database migrations
|
|
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 reset(config, options = {}, destroyAll = false) {
|
|
5239
5263
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5248,10 +5272,10 @@ var Migrate = class {
|
|
|
5248
5272
|
}
|
|
5249
5273
|
/**
|
|
5250
5274
|
* Reset and re-run all migrations
|
|
5251
|
-
*
|
|
5252
|
-
* @param config
|
|
5253
|
-
* @param options
|
|
5254
|
-
* @param destroyAll
|
|
5275
|
+
*
|
|
5276
|
+
* @param config
|
|
5277
|
+
* @param options
|
|
5278
|
+
* @param destroyAll
|
|
5255
5279
|
*/
|
|
5256
5280
|
async refresh(config, options = {}, destroyAll = false) {
|
|
5257
5281
|
await this.reset(config, Object.assign({}, options, { quiet: true }), false);
|
|
@@ -5260,10 +5284,10 @@ var Migrate = class {
|
|
|
5260
5284
|
}
|
|
5261
5285
|
/**
|
|
5262
5286
|
* Drop all tables and re-run all migrations
|
|
5263
|
-
*
|
|
5264
|
-
* @param config
|
|
5265
|
-
* @param options
|
|
5266
|
-
* @param destroyAll
|
|
5287
|
+
*
|
|
5288
|
+
* @param config
|
|
5289
|
+
* @param options
|
|
5290
|
+
* @param destroyAll
|
|
5267
5291
|
*/
|
|
5268
5292
|
async fresh(config, options = {}, destroyAll = false) {
|
|
5269
5293
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5273,8 +5297,8 @@ var Migrate = class {
|
|
|
5273
5297
|
}
|
|
5274
5298
|
/**
|
|
5275
5299
|
* Prepares the database for migration
|
|
5276
|
-
*
|
|
5277
|
-
* @param migrator
|
|
5300
|
+
*
|
|
5301
|
+
* @param migrator
|
|
5278
5302
|
*/
|
|
5279
5303
|
async prepareDatabase(migrator) {
|
|
5280
5304
|
if (!await migrator.repositoryExists()) {
|
|
@@ -5286,11 +5310,11 @@ var Migrate = class {
|
|
|
5286
5310
|
}
|
|
5287
5311
|
/**
|
|
5288
5312
|
* Check the status of available migrations
|
|
5289
|
-
*
|
|
5290
|
-
* @param config
|
|
5291
|
-
* @param options
|
|
5292
|
-
* @param destroyAll
|
|
5293
|
-
* @returns
|
|
5313
|
+
*
|
|
5314
|
+
* @param config
|
|
5315
|
+
* @param options
|
|
5316
|
+
* @param destroyAll
|
|
5317
|
+
* @returns
|
|
5294
5318
|
*/
|
|
5295
5319
|
async status(config, options = {}, destroyAll = false) {
|
|
5296
5320
|
const { arquebus: arquebus$1, migrator } = await this.setupConnection(config);
|
|
@@ -5317,9 +5341,9 @@ var Migrate = class {
|
|
|
5317
5341
|
}
|
|
5318
5342
|
/**
|
|
5319
5343
|
* Setup the database connection
|
|
5320
|
-
*
|
|
5321
|
-
* @param config
|
|
5322
|
-
* @returns
|
|
5344
|
+
*
|
|
5345
|
+
* @param config
|
|
5346
|
+
* @returns
|
|
5323
5347
|
*/
|
|
5324
5348
|
async setupConnection(config) {
|
|
5325
5349
|
var _config$migrations;
|
|
@@ -5339,12 +5363,6 @@ var Migrate = class {
|
|
|
5339
5363
|
}
|
|
5340
5364
|
};
|
|
5341
5365
|
|
|
5342
|
-
//#endregion
|
|
5343
|
-
//#region node_modules/.pnpm/tsdown@0.15.4_typescript@5.9.2/node_modules/tsdown/esm-shims.js
|
|
5344
|
-
const getFilename = () => fileURLToPath(import.meta.url);
|
|
5345
|
-
const getDirname = () => path$1.dirname(getFilename());
|
|
5346
|
-
const __dirname = /* @__PURE__ */ getDirname();
|
|
5347
|
-
|
|
5348
5366
|
//#endregion
|
|
5349
5367
|
//#region src/migrations/migration-creator.ts
|
|
5350
5368
|
var MigrationCreator = class {
|
|
@@ -5355,12 +5373,12 @@ var MigrationCreator = class {
|
|
|
5355
5373
|
}
|
|
5356
5374
|
/**
|
|
5357
5375
|
* Create a new migration file
|
|
5358
|
-
*
|
|
5359
|
-
* @param name
|
|
5360
|
-
* @param dir
|
|
5361
|
-
* @param table
|
|
5362
|
-
* @param create
|
|
5363
|
-
* @returns
|
|
5376
|
+
*
|
|
5377
|
+
* @param name
|
|
5378
|
+
* @param dir
|
|
5379
|
+
* @param table
|
|
5380
|
+
* @param create
|
|
5381
|
+
* @returns
|
|
5364
5382
|
*/
|
|
5365
5383
|
async create(name, dir, table, create = false) {
|
|
5366
5384
|
const stub = await this.getStub(table, create);
|
|
@@ -5372,9 +5390,9 @@ var MigrationCreator = class {
|
|
|
5372
5390
|
}
|
|
5373
5391
|
/**
|
|
5374
5392
|
* Publish migrations from third party vendors
|
|
5375
|
-
*
|
|
5376
|
-
* @param dir
|
|
5377
|
-
* @param callback
|
|
5393
|
+
*
|
|
5394
|
+
* @param dir
|
|
5395
|
+
* @param callback
|
|
5378
5396
|
*/
|
|
5379
5397
|
async publish(dir, callback) {
|
|
5380
5398
|
const migrationFiles = await readdir(this.customStubPath ?? "");
|
|
@@ -5402,7 +5420,7 @@ var MigrationCreator = class {
|
|
|
5402
5420
|
return await readFile(stub, "utf-8");
|
|
5403
5421
|
}
|
|
5404
5422
|
populateStub(stub, table) {
|
|
5405
|
-
if (table
|
|
5423
|
+
if (table) stub = stub.replace(/DummyTable|{{\s*table\s*}}/g, table);
|
|
5406
5424
|
return stub;
|
|
5407
5425
|
}
|
|
5408
5426
|
getClassName(name) {
|
|
@@ -8,9 +8,9 @@ export default class extends Migration {
|
|
|
8
8
|
*/
|
|
9
9
|
async up(schema) {
|
|
10
10
|
await schema.createTable('{{ table }}', (table) => {
|
|
11
|
-
table.increments('id')
|
|
12
|
-
table.timestamps()
|
|
13
|
-
})
|
|
11
|
+
table.increments('id')
|
|
12
|
+
table.timestamps()
|
|
13
|
+
})
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -19,6 +19,6 @@ export default class extends Migration {
|
|
|
19
19
|
* @param {(import('@h3ravel/arquebus/types/query-builder').SchemaBuilder)} schema
|
|
20
20
|
*/
|
|
21
21
|
async down(schema) {
|
|
22
|
-
await schema.dropTableIfExists('{{ table }}')
|
|
22
|
+
await schema.dropTableIfExists('{{ table }}')
|
|
23
23
|
}
|
|
24
|
-
}
|
|
24
|
+
}
|
|
@@ -7,15 +7,15 @@ export default class extends Migration {
|
|
|
7
7
|
*/
|
|
8
8
|
async up(schema: SchemaBuilder) {
|
|
9
9
|
await schema.createTable('{{ table }}', (table) => {
|
|
10
|
-
table.increments('id')
|
|
11
|
-
table.timestamps()
|
|
12
|
-
})
|
|
10
|
+
table.increments('id')
|
|
11
|
+
table.timestamps()
|
|
12
|
+
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Reverse the migrations.
|
|
17
17
|
*/
|
|
18
18
|
async down(schema: SchemaBuilder) {
|
|
19
|
-
await schema.dropTableIfExists('{{ table }}')
|
|
19
|
+
await schema.dropTableIfExists('{{ table }}')
|
|
20
20
|
}
|
|
21
|
-
}
|
|
21
|
+
}
|
|
@@ -9,7 +9,7 @@ export default class extends Migration {
|
|
|
9
9
|
async up(schema) {
|
|
10
10
|
await schema.table('{{ table }}', (table) => {
|
|
11
11
|
//
|
|
12
|
-
})
|
|
12
|
+
})
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -20,6 +20,6 @@ export default class extends Migration {
|
|
|
20
20
|
async down(schema) {
|
|
21
21
|
await schema.table('{{ table }}', (table) => {
|
|
22
22
|
//
|
|
23
|
-
})
|
|
23
|
+
})
|
|
24
24
|
}
|
|
25
25
|
};
|
|
@@ -8,7 +8,7 @@ export default class extends Migration {
|
|
|
8
8
|
async up(schema: SchemaBuilder) {
|
|
9
9
|
await schema.table('{{ table }}', (table) => {
|
|
10
10
|
//
|
|
11
|
-
})
|
|
11
|
+
})
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -17,6 +17,6 @@ export default class extends Migration {
|
|
|
17
17
|
async down(schema: SchemaBuilder) {
|
|
18
18
|
await schema.table('{{ table }}', (table) => {
|
|
19
19
|
//
|
|
20
|
-
})
|
|
20
|
+
})
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
let path = require("path");
|
|
25
|
+
path = __toESM(path);
|
|
26
|
+
let node_fs_promises = require("node:fs/promises");
|
|
27
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
node_path = __toESM(node_path);
|
|
30
|
+
let node_url = require("node:url");
|
|
31
|
+
node_url = __toESM(node_url);
|
|
32
|
+
|
|
33
|
+
//#region src/seeders/seeder.ts
|
|
34
|
+
var Seeder = class {};
|
|
35
|
+
var seeder_default = Seeder;
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/seeders/runner.ts
|
|
39
|
+
async function glob(folderPath) {
|
|
40
|
+
const { default: escalade } = await import("escalade");
|
|
41
|
+
const entries = [];
|
|
42
|
+
await escalade(folderPath, async (dir, names) => {
|
|
43
|
+
await Promise.all(names.map(async (name) => {
|
|
44
|
+
const p = path.default.join(dir, name);
|
|
45
|
+
try {
|
|
46
|
+
await (0, node_fs_promises.access)(p);
|
|
47
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
48
|
+
} catch {}
|
|
49
|
+
}));
|
|
50
|
+
return "";
|
|
51
|
+
});
|
|
52
|
+
return entries;
|
|
53
|
+
}
|
|
54
|
+
var SeederRunner = class {
|
|
55
|
+
resolver;
|
|
56
|
+
connection;
|
|
57
|
+
paths = [];
|
|
58
|
+
constructor(resolver) {
|
|
59
|
+
this.resolver = resolver;
|
|
60
|
+
}
|
|
61
|
+
path(p) {
|
|
62
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
63
|
+
}
|
|
64
|
+
getPaths() {
|
|
65
|
+
return this.paths;
|
|
66
|
+
}
|
|
67
|
+
resolveConnection(connection) {
|
|
68
|
+
var _getInstance, _ref, _instance$connections;
|
|
69
|
+
const name = connection || this.connection || "default";
|
|
70
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
71
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
72
|
+
/** noop */
|
|
73
|
+
});
|
|
74
|
+
return this.resolver.fire(name);
|
|
75
|
+
}
|
|
76
|
+
setConnection(connection) {
|
|
77
|
+
this.connection = connection;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
async getSeederFiles(paths) {
|
|
81
|
+
const files = [];
|
|
82
|
+
for (const p of paths) {
|
|
83
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
84
|
+
files.push(p);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
files.push(...await glob(p));
|
|
88
|
+
}
|
|
89
|
+
return files;
|
|
90
|
+
}
|
|
91
|
+
async resolvePath(filePath) {
|
|
92
|
+
try {
|
|
93
|
+
const mod = await import(filePath);
|
|
94
|
+
return new (mod.default ?? mod.Seeder)();
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async run(paths, connection) {
|
|
100
|
+
const files = await this.getSeederFiles(paths);
|
|
101
|
+
const conn = this.resolveConnection(connection);
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
const seeder = await this.resolvePath(file);
|
|
104
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var runner_default = SeederRunner;
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/seeders/seeder-creator.ts
|
|
112
|
+
var SeederCreator = class {
|
|
113
|
+
constructor(customStubPath) {
|
|
114
|
+
this.customStubPath = customStubPath;
|
|
115
|
+
}
|
|
116
|
+
async create(dir, name, type = "js") {
|
|
117
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
118
|
+
const stubPath = this.getStubPath(type);
|
|
119
|
+
let stub = await (0, node_fs_promises.readFile)(stubPath, "utf-8");
|
|
120
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
121
|
+
const filePath = path.default.join(dir, `${name}.${type}`);
|
|
122
|
+
await (0, node_fs_promises.writeFile)(filePath, stub);
|
|
123
|
+
return filePath;
|
|
124
|
+
}
|
|
125
|
+
getStubPath(type) {
|
|
126
|
+
if (this.customStubPath) return path.default.join(this.customStubPath, `seeder-${type}.stub`);
|
|
127
|
+
const __dirname$1 = this.getDirname({});
|
|
128
|
+
return path.default.join(__dirname$1, "stubs", `seeder-${type}.stub`);
|
|
129
|
+
}
|
|
130
|
+
getDirname(meta) {
|
|
131
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
132
|
+
if (meta && meta.url) return (0, node_path.dirname)((0, node_url.fileURLToPath)(meta.url));
|
|
133
|
+
throw new Error("Unable to determine dirname");
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var seeder_creator_default = SeederCreator;
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
exports.Seeder = seeder_default;
|
|
140
|
+
exports.SeederCreator = seeder_creator_default;
|
|
141
|
+
exports.SeederRunner = runner_default;
|