@h3ravel/arquebus 0.6.6 → 0.6.8

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.
Files changed (33) hide show
  1. package/README.md +5 -4
  2. package/bin/index.cjs +270 -425
  3. package/bin/{index.js → index.mjs} +230 -409
  4. package/bin/seeders-C0schOjT.mjs +3 -0
  5. package/bin/seeders-D-v59HCz.cjs +3 -0
  6. package/dist/browser/index.cjs +4 -12
  7. package/dist/browser/index.d.cts +203 -203
  8. package/dist/browser/{index.d.ts → index.d.mts} +203 -203
  9. package/dist/browser/{index.js → index.mjs} +4 -11
  10. package/dist/index.cjs +21 -59
  11. package/dist/index.d.cts +133 -133
  12. package/dist/{index.d.ts → index.d.mts} +133 -133
  13. package/dist/{index.js → index.mjs} +21 -54
  14. package/dist/inspector/index.cjs +15 -46
  15. package/dist/inspector/{index.js → index.mjs} +15 -43
  16. package/dist/migrations/{chunk-PECeCxCb.js → chunk-BD38OWEx.mjs} +1 -1
  17. package/dist/migrations/index.cjs +20 -57
  18. package/dist/migrations/index.d.cts +186 -186
  19. package/dist/migrations/{index.d.ts → index.d.mts} +186 -186
  20. package/dist/migrations/{index.js → index.mjs} +22 -54
  21. package/dist/seeders/index.cjs +1 -5
  22. package/dist/seeders/index.d.cts +184 -184
  23. package/dist/seeders/{index.d.ts → index.d.mts} +184 -184
  24. package/dist/seeders/{index.js → index.mjs} +2 -3
  25. package/dist/stubs/seeder-js.stub +4 -4
  26. package/dist/stubs/seeder-ts.stub +5 -0
  27. package/package.json +5 -4
  28. package/bin/seeders-8GJzfIIN.js +0 -3
  29. package/bin/seeders-ByeSoCAQ.cjs +0 -131
  30. package/bin/seeders-CltigymO.js +0 -79
  31. package/bin/seeders-_xJ6VGVS.cjs +0 -3
  32. /package/bin/{index.d.ts → index.d.mts} +0 -0
  33. /package/dist/inspector/{index.d.ts → index.d.mts} +0 -0
@@ -317,9 +317,7 @@ const HasAttributes = (Model$1) => {
317
317
  }
318
318
  originalIsEquivalent(key) {
319
319
  if (this.original[key] === void 0) return false;
320
- const attribute = this.attributes[key];
321
- const original = this.original[key];
322
- if (attribute === original) return true;
320
+ if (this.attributes[key] === this.original[key]) return true;
323
321
  else return false;
324
322
  }
325
323
  setAttributes(attributes) {
@@ -501,8 +499,7 @@ const HasAttributes = (Model$1) => {
501
499
  return new Date(value);
502
500
  }
503
501
  asDate(value) {
504
- const date = this.asDateTime(value);
505
- return dayjs(date).startOf("day").toDate();
502
+ return dayjs(this.asDateTime(value)).startOf("day").toDate();
506
503
  }
507
504
  };
508
505
  };
@@ -617,10 +614,7 @@ const HasRelations = (Instance) => {
617
614
  return this.relations[relation] !== void 0;
618
615
  }
619
616
  related(relation) {
620
- if (typeof this[getRelationMethod(relation)] !== "function") {
621
- const message = `Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`;
622
- throw new RelationNotFoundError(message);
623
- }
617
+ if (typeof this[getRelationMethod(relation)] !== "function") throw new RelationNotFoundError(`Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`);
624
618
  return this[getRelationMethod(relation)]();
625
619
  }
626
620
  async getRelated(relation) {
@@ -638,8 +632,7 @@ const HasRelations = (Instance) => {
638
632
  guessBelongsToRelation() {
639
633
  var _e$stack;
640
634
  const frame = (_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2];
641
- const functionName = frame === null || frame === void 0 ? void 0 : frame.split(" ")[5];
642
- return getRelationName(functionName);
635
+ return getRelationName(frame === null || frame === void 0 ? void 0 : frame.split(" ")[5]);
643
636
  }
644
637
  joiningTable(related, instance = null) {
645
638
  return [instance ? instance.joiningTableSegment() : snakeCase(related.name), this.joiningTableSegment()].sort().join("_").toLocaleLowerCase();
package/dist/index.cjs CHANGED
@@ -30,7 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
 
31
31
  //#endregion
32
32
  let radashi = require("radashi");
33
- radashi = __toESM(radashi);
34
33
  let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
35
34
  dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js);
36
35
  let dayjs = require("dayjs");
@@ -42,9 +41,7 @@ knex = __toESM(knex);
42
41
  let path = require("path");
43
42
  path = __toESM(path);
44
43
  let fs = require("fs");
45
- fs = __toESM(fs);
46
44
  let __h3ravel_shared = require("@h3ravel/shared");
47
- __h3ravel_shared = __toESM(__h3ravel_shared);
48
45
  let pluralize = require("pluralize");
49
46
  pluralize = __toESM(pluralize);
50
47
  let node_fs_promises = require("node:fs/promises");
@@ -52,9 +49,7 @@ node_fs_promises = __toESM(node_fs_promises);
52
49
  let resolve_from = require("resolve-from");
53
50
  resolve_from = __toESM(resolve_from);
54
51
  let node_path = require("node:path");
55
- node_path = __toESM(node_path);
56
52
  let node_url = require("node:url");
57
- node_url = __toESM(node_url);
58
53
 
59
54
  //#region src/casts/attribute.ts
60
55
  var Attribute = class Attribute {
@@ -521,9 +516,7 @@ const HasAttributes = (Model$1) => {
521
516
  }
522
517
  originalIsEquivalent(key) {
523
518
  if (this.original[key] === void 0) return false;
524
- const attribute = this.attributes[key];
525
- const original = this.original[key];
526
- if (attribute === original) return true;
519
+ if (this.attributes[key] === this.original[key]) return true;
527
520
  else return false;
528
521
  }
529
522
  setAttributes(attributes) {
@@ -705,8 +698,7 @@ const HasAttributes = (Model$1) => {
705
698
  return new Date(value);
706
699
  }
707
700
  asDate(value) {
708
- const date = this.asDateTime(value);
709
- return (0, dayjs.default)(date).startOf("day").toDate();
701
+ return (0, dayjs.default)(this.asDateTime(value)).startOf("day").toDate();
710
702
  }
711
703
  };
712
704
  };
@@ -1220,10 +1212,7 @@ const HasRelations = (Model$1) => {
1220
1212
  return this.relations[relation] !== void 0;
1221
1213
  }
1222
1214
  related(relation) {
1223
- if (typeof this[getRelationMethod(relation)] !== "function") {
1224
- const message = `Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`;
1225
- throw new RelationNotFoundError(message);
1226
- }
1215
+ if (typeof this[getRelationMethod(relation)] !== "function") throw new RelationNotFoundError(`Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`);
1227
1216
  return this[getRelationMethod(relation)]();
1228
1217
  }
1229
1218
  async getRelated(relation) {
@@ -2724,8 +2713,7 @@ var BelongsToMany = class extends compose(relation_default, interacts_with_pivot
2724
2713
  return columns.concat(this.aliasedPivotColumns());
2725
2714
  }
2726
2715
  aliasedPivotColumns() {
2727
- const defaults = [this.foreignPivotKey, this.relatedPivotKey];
2728
- return (0, collect_js.collect)(defaults.concat(this.pivotColumns)).map((column) => {
2716
+ return (0, collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
2729
2717
  return this.qualifyPivotColumn(column) + " as pivot_" + column;
2730
2718
  }).unique().all();
2731
2719
  }
@@ -3018,8 +3006,7 @@ var Builder = class Builder extends Inference$1 {
3018
3006
  }
3019
3007
  addUpdatedAtColumn(values) {
3020
3008
  if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
3021
- const column = this.model.getUpdatedAtColumn();
3022
- values = (0, radashi.assign)({ [column]: this.model.freshTimestampString() }, values);
3009
+ values = (0, radashi.assign)({ [this.model.getUpdatedAtColumn()]: this.model.freshTimestampString() }, values);
3023
3010
  return values;
3024
3011
  }
3025
3012
  delete() {
@@ -3334,10 +3321,7 @@ var Builder = class Builder extends Inference$1 {
3334
3321
  }];
3335
3322
  }
3336
3323
  related(relation) {
3337
- if (typeof this.model[getRelationMethod(relation)] !== "function") {
3338
- const message = `Model [${this.model.constructor.name}]'s relation [${relation}] doesn't exist.`;
3339
- throw new RelationNotFoundError(message);
3340
- }
3324
+ if (typeof this.model[getRelationMethod(relation)] !== "function") throw new RelationNotFoundError(`Model [${this.model.constructor.name}]'s relation [${relation}] doesn't exist.`);
3341
3325
  return this.model[getRelationMethod(relation)]();
3342
3326
  }
3343
3327
  take(...args) {
@@ -3410,8 +3394,7 @@ var Builder = class Builder extends Inference$1 {
3410
3394
  return await this.whereIn(this.model.getKeyName(), ids).get(columns);
3411
3395
  }
3412
3396
  async pluck(column) {
3413
- const data = await this.query.pluck(column);
3414
- return new collection_default(data);
3397
+ return new collection_default(await this.query.pluck(column));
3415
3398
  }
3416
3399
  async destroy(ids) {
3417
3400
  if (ids instanceof collection_default) ids = ids.modelKeys();
@@ -3456,10 +3439,7 @@ var Builder = class Builder extends Inference$1 {
3456
3439
  return this.hydrate(await this.query.get()).all();
3457
3440
  }
3458
3441
  getRelation(name) {
3459
- if (typeof this.model[getRelationMethod(name)] !== "function") {
3460
- const message = `Model [${this.model.constructor.name}]'s relation [${name}] doesn't exist.`;
3461
- throw new RelationNotFoundError(message);
3462
- }
3442
+ if (typeof this.model[getRelationMethod(name)] !== "function") throw new RelationNotFoundError(`Model [${this.model.constructor.name}]'s relation [${name}] doesn't exist.`);
3463
3443
  const relation = relation_default.noConstraints(() => this.model.newInstance(this.model.attributes)[getRelationMethod(name)]());
3464
3444
  const nested = this.relationsNestedUnder(name);
3465
3445
  if (Object.keys(nested).length > 0) relation.query.with(nested);
@@ -4057,10 +4037,7 @@ var MSSQL = class {
4057
4037
  AND ISNULL([i].[index_column_count], 1) = 1
4058
4038
  AND ISNULL([i].[index_priority], 1) = 1`).where({ "s.name": this.schema });
4059
4039
  if (table) query.andWhere({ "o.name": table });
4060
- if (column) {
4061
- const rawColumn = await query.andWhere({ "c.name": column }).first();
4062
- return rawColumnToColumn$2(rawColumn);
4063
- }
4040
+ if (column) return rawColumnToColumn$2(await query.andWhere({ "c.name": column }).first());
4064
4041
  return (await query).map(rawColumnToColumn$2);
4065
4042
  }
4066
4043
  /**
@@ -4211,10 +4188,7 @@ var MySQL = class {
4211
4188
  this.on("rc.TABLE_NAME", "=", "fk.TABLE_NAME").andOn("rc.CONSTRAINT_NAME", "=", "fk.CONSTRAINT_NAME").andOn("rc.CONSTRAINT_SCHEMA", "=", "fk.CONSTRAINT_SCHEMA");
4212
4189
  }).where({ "c.TABLE_SCHEMA": this.knex.client.database() });
4213
4190
  if (table) query.andWhere({ "c.TABLE_NAME": table });
4214
- if (column) {
4215
- const rawColumn = await query.andWhere({ "c.column_name": column }).first();
4216
- return rawColumnToColumn$1(rawColumn);
4217
- }
4191
+ if (column) return rawColumnToColumn$1(await query.andWhere({ "c.column_name": column }).first());
4218
4192
  return (await query).map(rawColumnToColumn$1).sort((column$1) => +!column$1.foreign_key_column).filter((column$1, index, records) => {
4219
4193
  return records.findIndex((_column) => {
4220
4194
  return column$1.name === _column.name && column$1.table === _column.table;
@@ -4400,10 +4374,7 @@ var oracleDB = class {
4400
4374
  ON "ct"."R_CONSTRAINT_NAME" = "fk"."CONSTRAINT_NAME"
4401
4375
  `)).where({ "c.HIDDEN_COLUMN": "NO" });
4402
4376
  if (table) query.andWhere({ "c.TABLE_NAME": table });
4403
- if (column) {
4404
- const rawColumn = await query.andWhere({ "c.COLUMN_NAME": column }).first();
4405
- return rawColumnToColumn(rawColumn);
4406
- }
4377
+ if (column) return rawColumnToColumn(await query.andWhere({ "c.COLUMN_NAME": column }).first());
4407
4378
  return (await query).map(rawColumnToColumn);
4408
4379
  }
4409
4380
  /**
@@ -4881,8 +4852,7 @@ var SQLite = class {
4881
4852
  column: column.name
4882
4853
  }));
4883
4854
  const tables = await this.tables();
4884
- const columnsPerTable = await Promise.all(tables.map(async (table$1) => await this.columns(table$1)));
4885
- return flatten(columnsPerTable);
4855
+ return flatten(await Promise.all(tables.map(async (table$1) => await this.columns(table$1))));
4886
4856
  }
4887
4857
  async columnInfo(table, column) {
4888
4858
  const getColumnsForTable = async (table$1) => {
@@ -4917,8 +4887,7 @@ var SQLite = class {
4917
4887
  };
4918
4888
  if (!table) {
4919
4889
  const tables = await this.tables();
4920
- const columnsPerTable = await Promise.all(tables.map(async (table$1) => await getColumnsForTable(table$1)));
4921
- return flatten(columnsPerTable);
4890
+ return flatten(await Promise.all(tables.map(async (table$1) => await getColumnsForTable(table$1))));
4922
4891
  }
4923
4892
  if (table && !column) return await getColumnsForTable(table);
4924
4893
  return (await getColumnsForTable(table)).find((columnInfo) => columnInfo.name === column);
@@ -4949,8 +4918,7 @@ var SQLite = class {
4949
4918
  constraint_name: null
4950
4919
  }));
4951
4920
  const tables = await this.tables();
4952
- const keysPerTable = await Promise.all(tables.map(async (table$1) => await this.foreignKeys(table$1)));
4953
- return flatten(keysPerTable);
4921
+ return flatten(await Promise.all(tables.map(async (table$1) => await this.foreignKeys(table$1))));
4954
4922
  }
4955
4923
  async uniqueConstraints(table) {
4956
4924
  if (table) {
@@ -4966,8 +4934,7 @@ var SQLite = class {
4966
4934
  });
4967
4935
  }
4968
4936
  const tables = await this.tables();
4969
- const constraintsPerTable = await Promise.all(tables.map(async (table$1) => await this.uniqueConstraints(table$1)));
4970
- return flatten(constraintsPerTable);
4937
+ return flatten(await Promise.all(tables.map(async (table$1) => await this.uniqueConstraints(table$1))));
4971
4938
  }
4972
4939
  };
4973
4940
 
@@ -5334,21 +5301,19 @@ var Migrate = class {
5334
5301
  const getAllMigrationFiles = async () => {
5335
5302
  return await migrator.getMigrationFiles(await Utils.getMigrationPaths(this.basePath ?? process.cwd(), migrator, config.migrations.path, options.path));
5336
5303
  };
5337
- async function getStatusFor(ran$1, batches$1) {
5304
+ async function getStatusFor(ran, batches) {
5338
5305
  const files = await getAllMigrationFiles();
5339
5306
  return Object.values(files).map((migration) => {
5340
5307
  const migrationName = migrator.getMigrationName(migration);
5341
5308
  return {
5342
5309
  name: migrationName,
5343
- ran: ran$1.includes(migrationName),
5344
- batch: ran$1.includes(migrationName) ? batches$1[migrationName] : null
5310
+ ran: ran.includes(migrationName),
5311
+ batch: ran.includes(migrationName) ? batches[migrationName] : null
5345
5312
  };
5346
5313
  });
5347
5314
  }
5348
5315
  if (!await migrator.repositoryExists()) this.callback("ERROR: Migration table does not exist.", "error");
5349
- const ran = await migrator.repository.getRan();
5350
- const batches = await migrator.getRepository().getMigrationBatches();
5351
- const migrations = await getStatusFor(ran, batches);
5316
+ const migrations = await getStatusFor(await migrator.repository.getRan(), await migrator.getRepository().getMigrationBatches());
5352
5317
  if (destroyAll) await arquebus$1.destroyAll();
5353
5318
  return migrations;
5354
5319
  }
@@ -5367,11 +5332,9 @@ var Migrate = class {
5367
5332
  arquebus_default.addConnection(connection, name);
5368
5333
  });
5369
5334
  }
5370
- const repository = new MigrationRepository(arquebus_default, table);
5371
- const migrator = new migrator_default(repository, arquebus_default);
5372
5335
  return {
5373
5336
  arquebus: arquebus_default,
5374
- migrator
5337
+ migrator: new migrator_default(new MigrationRepository(arquebus_default, table), arquebus_default)
5375
5338
  };
5376
5339
  }
5377
5340
  };
@@ -5474,8 +5437,7 @@ var SeederCreator = class {
5474
5437
  }
5475
5438
  async create(dir, name, type = "js") {
5476
5439
  await (0, node_fs_promises.mkdir)(dir, { recursive: true });
5477
- const stubPath = this.getStubPath(type);
5478
- let stub = await (0, node_fs_promises.readFile)(stubPath, "utf-8");
5440
+ let stub = await (0, node_fs_promises.readFile)(this.getStubPath(type), "utf-8");
5479
5441
  stub = stub.replace(/{{ name }}/g, name);
5480
5442
  const filePath = path.default.join(dir, `${name}.${type}`);
5481
5443
  await (0, node_fs_promises.writeFile)(filePath, stub);