@h3ravel/arquebus 2.0.0 → 3.0.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.
Files changed (45) hide show
  1. package/bin/index.cjs +580 -451
  2. package/bin/index.js +566 -437
  3. package/dist/browser/index.cjs +54 -51
  4. package/dist/browser/index.d.ts +804 -737
  5. package/dist/browser/index.js +48 -44
  6. package/dist/concerns/index.cjs +152 -143
  7. package/dist/concerns/index.d.ts +849 -776
  8. package/dist/concerns/index.js +143 -133
  9. package/dist/index.cjs +186 -185
  10. package/dist/index.d.ts +856 -782
  11. package/dist/index.js +179 -177
  12. package/dist/inspector/index.cjs +175 -174
  13. package/dist/inspector/index.d.ts +0 -1
  14. package/dist/inspector/index.js +161 -159
  15. package/dist/migrations/index.cjs +183 -182
  16. package/dist/migrations/index.d.ts +799 -727
  17. package/dist/migrations/index.js +172 -170
  18. package/dist/relations/index.cjs +152 -143
  19. package/dist/relations/index.d.ts +835 -762
  20. package/dist/relations/index.js +143 -133
  21. package/dist/seeders/index.cjs +7 -5
  22. package/dist/seeders/index.d.ts +797 -724
  23. package/dist/seeders/index.js +8 -6
  24. package/dist/{migrations/stubs/stubs → stubs}/migration-js.stub +1 -0
  25. package/dist/{migrations/stubs/stubs → stubs}/migration-ts.stub +1 -0
  26. package/dist/{migrations/stubs/stubs → stubs}/migration.create-js.stub +1 -0
  27. package/dist/{migrations/stubs/stubs → stubs}/migration.create-ts.stub +1 -0
  28. package/dist/{migrations/stubs/stubs → stubs}/migration.update-js.stub +1 -0
  29. package/dist/{migrations/stubs/stubs → stubs}/migration.update-ts.stub +1 -0
  30. package/dist/stubs/model-ts.stub +9 -0
  31. package/package.json +31 -31
  32. package/types/builder.ts +1 -1
  33. package/types/database.ts +69 -0
  34. package/types/index.ts +3 -0
  35. package/types/model-builder.ts +132 -0
  36. package/types/query-builder.ts +0 -1
  37. package/types/query-methods.ts +0 -1
  38. package/types/schema.ts +92 -0
  39. package/types/utils.ts +1 -40
  40. package/dist/stubs/stubs/model-ts.stub +0 -5
  41. /package/dist/stubs/{stubs/arquebus.config-js.stub → arquebus.config-js.stub} +0 -0
  42. /package/dist/stubs/{stubs/arquebus.config-ts.stub → arquebus.config-ts.stub} +0 -0
  43. /package/dist/stubs/{stubs/model-js.stub → model-js.stub} +0 -0
  44. /package/dist/stubs/{stubs/seeder-js.stub → seeder-js.stub} +0 -0
  45. /package/dist/stubs/{stubs/seeder-ts.stub → seeder-ts.stub} +0 -0
@@ -30,13 +30,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  enumerable: true
31
31
  }) : target, mod));
32
32
  //#endregion
33
- let radashi = require("radashi");
34
- let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
35
- dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
33
+ let _h3ravel_support = require("@h3ravel/support");
36
34
  let dayjs = require("dayjs");
37
35
  dayjs = __toESM(dayjs, 1);
38
- let collect_js = require("collect.js");
39
- collect_js = __toESM(collect_js, 1);
36
+ let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
37
+ dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
38
+ let _h3ravel_collect_js = require("@h3ravel/collect.js");
40
39
  let knex = require("knex");
41
40
  knex = __toESM(knex, 1);
42
41
  let path = require("path");
@@ -120,25 +119,29 @@ function compose$1(Base, ...mixins) {
120
119
  }, Base);
121
120
  }
122
121
  //#endregion
122
+ //#region src/dayjs.ts
123
+ const dayjs$1 = dayjs.default ?? dayjs;
124
+ const advancedFormat = dayjs_plugin_advancedFormat_js.default ?? dayjs_plugin_advancedFormat_js;
125
+ dayjs$1.extend(advancedFormat);
126
+ //#endregion
123
127
  //#region src/utils.ts
124
- dayjs.default.extend(dayjs_plugin_advancedFormat_js.default);
125
128
  const getRelationName = (relationMethod) => {
126
- return (0, radashi.snake)(relationMethod.substring(8));
129
+ return _h3ravel_support.Str.snake(relationMethod.substring(8));
127
130
  };
128
131
  const getRelationMethod = (relation) => {
129
- return (0, radashi.camel)(`relation_${relation}`);
132
+ return _h3ravel_support.Str.camel(`relation_${relation}`);
130
133
  };
131
134
  const getScopeMethod = (scope) => {
132
- return (0, radashi.camel)(`scope_${scope}`);
135
+ return _h3ravel_support.Str.camel(`scope_${scope}`);
133
136
  };
134
137
  const getAttrMethod = (attr) => {
135
- return (0, radashi.camel)(`attribute_${attr}`);
138
+ return _h3ravel_support.Str.camel(`attribute_${attr}`);
136
139
  };
137
140
  const getGetterMethod = (attr) => {
138
- return (0, radashi.camel)(`get_${attr}_attribute`);
141
+ return _h3ravel_support.Str.camel(`get_${attr}_attribute`);
139
142
  };
140
143
  const getSetterMethod = (attr) => {
141
- return (0, radashi.camel)(`set_${attr}_attribute`);
144
+ return _h3ravel_support.Str.camel(`set_${attr}_attribute`);
142
145
  };
143
146
  /**
144
147
  * Tap into a model a collection instance
@@ -152,8 +155,9 @@ const tap = (instance, callback) => {
152
155
  return result instanceof Promise ? result.then(() => instance) : instance;
153
156
  };
154
157
  const { compose } = mixin_exports;
158
+ const flatten = (arr) => arr.flat();
155
159
  const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
156
- const snakeCase = (str) => (0, radashi.trim)((0, radashi.snake)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
160
+ const snakeCase = (str) => _h3ravel_support.Str.trim(_h3ravel_support.Str.snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/_+/g, "_");
157
161
  //#endregion
158
162
  //#region src/casts-attributes.ts
159
163
  var CastsAttributes = class CastsAttributes {
@@ -187,8 +191,7 @@ const HasAttributes$1 = (Model) => {
187
191
  return this;
188
192
  }
189
193
  normalizeCastClassResponse(key, value) {
190
- var _value$constructor;
191
- return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
194
+ return value?.constructor?.name === "Object" ? value : { [key]: value };
192
195
  }
193
196
  syncOriginal() {
194
197
  this.original = this.getAttributes();
@@ -298,9 +301,9 @@ const HasAttributes$1 = (Model) => {
298
301
  return null;
299
302
  }
300
303
  case "collection": try {
301
- return (0, collect_js.default)(JSON.parse(value));
304
+ return (0, _h3ravel_collect_js.collect)(JSON.parse(value));
302
305
  } catch {
303
- return (0, collect_js.default)([]);
306
+ return (0, _h3ravel_collect_js.collect)([]);
304
307
  }
305
308
  case "date": return this.asDate(value);
306
309
  case "datetime":
@@ -313,8 +316,8 @@ const HasAttributes$1 = (Model) => {
313
316
  attributesToData() {
314
317
  let attributes = { ...this.attributes };
315
318
  for (const key in attributes) {
316
- if (this.hidden.includes(key)) attributes = (0, radashi.omit)(attributes, [key]);
317
- if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = (0, radashi.omit)(attributes, [key]);
319
+ if (this.hidden.includes(key)) attributes = _h3ravel_support.Arr.except(attributes, [key]);
320
+ if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = _h3ravel_support.Arr.except(attributes, [key]);
318
321
  }
319
322
  for (const key of this.getDates()) {
320
323
  if (attributes[key] === void 0) continue;
@@ -326,7 +329,7 @@ const HasAttributes$1 = (Model) => {
326
329
  if (key in attributes === false) continue;
327
330
  attributes[key] = this.castAttribute(key, attributes[key]);
328
331
  if (key in attributes && ["date", "datetime"].includes(String(value))) attributes[key] = this.serializeDate(attributes[key]);
329
- if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = (0, dayjs.default)(attributes[key]).format(String(value).split(":")[1]);
332
+ if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = dayjs$1(attributes[key]).format(String(value).split(":")[1]);
330
333
  }
331
334
  for (const key of this.appends) attributes[key] = this.mutateAttribute(key, null);
332
335
  return attributes;
@@ -342,7 +345,7 @@ const HasAttributes$1 = (Model) => {
342
345
  return this.getDates().includes(key) || this.isDateCastable(key);
343
346
  }
344
347
  serializeDate(date) {
345
- return date ? (0, dayjs.default)(date).toISOString() : null;
348
+ return date ? dayjs$1(date).toISOString() : null;
346
349
  }
347
350
  getDates() {
348
351
  return this.usesTimestamps() ? [this.getCreatedAtColumn(), this.getUpdatedAtColumn()] : [];
@@ -369,13 +372,13 @@ const HasAttributes$1 = (Model) => {
369
372
  }
370
373
  hasCast(key, types = []) {
371
374
  if (key in this.casts) {
372
- types = (0, radashi.flat)(types);
375
+ types = flatten(types);
373
376
  return types.length > 0 ? types.includes(this.getCastType(key)) : true;
374
377
  }
375
378
  return false;
376
379
  }
377
380
  withDayjs(date) {
378
- return (0, dayjs.default)(date);
381
+ return dayjs$1(date);
379
382
  }
380
383
  isCustomCast(cast) {
381
384
  return typeof cast === "function" && new cast() instanceof CastsAttributes;
@@ -392,7 +395,7 @@ const HasAttributes$1 = (Model) => {
392
395
  return this.hasCast(key, ["date", "datetime"]);
393
396
  }
394
397
  fromDateTime(value) {
395
- return (0, dayjs.default)(this.asDateTime(value)).format(this.getDateFormat());
398
+ return dayjs$1(this.asDateTime(value)).format(this.getDateFormat());
396
399
  }
397
400
  getDateFormat() {
398
401
  return this.dateFormat || "YYYY-MM-DD HH:mm:ss";
@@ -407,7 +410,7 @@ const HasAttributes$1 = (Model) => {
407
410
  return new Date(value);
408
411
  }
409
412
  asDate(value) {
410
- return (0, dayjs.default)(this.asDateTime(value)).startOf("day").toDate();
413
+ return dayjs$1(this.asDateTime(value)).startOf("day").toDate();
411
414
  }
412
415
  };
413
416
  };
@@ -429,7 +432,7 @@ var ModelNotFoundError = class extends BaseError {
429
432
  }
430
433
  setModel(model, ids = []) {
431
434
  this.model = model;
432
- this.ids = (0, radashi.isArray)(ids) ? ids : [ids];
435
+ this.ids = Array.isArray(ids) ? ids : [ids];
433
436
  this.message = `No query results for model [${model}]`;
434
437
  if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
435
438
  else this.message += ".";
@@ -461,10 +464,14 @@ const HasGlobalScopes$1 = (Model) => {
461
464
  static globalScopes;
462
465
  static addGlobalScope(scope, implementation = null) {
463
466
  if (typeof scope === "string" && implementation instanceof Scope) {
464
- this.globalScopes = (0, radashi.set)(this.globalScopes ?? {}, this.name + "." + scope, implementation);
467
+ const scopes = this.globalScopes ?? {};
468
+ (0, _h3ravel_support.data_set)(scopes, this.name + "." + scope, implementation);
469
+ this.globalScopes = scopes;
465
470
  return implementation;
466
471
  } else if (scope instanceof Scope) {
467
- this.globalScopes = (0, radashi.set)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name, scope);
472
+ const scopes = this.globalScopes ?? {};
473
+ (0, _h3ravel_support.data_set)(scopes, this.name + "." + scope.constructor.name, scope);
474
+ this.globalScopes = scopes;
468
475
  return scope;
469
476
  }
470
477
  throw new InvalidArgumentError("Global scope must be an instance of Scope.");
@@ -473,8 +480,8 @@ const HasGlobalScopes$1 = (Model) => {
473
480
  return this.getGlobalScope(scope) !== null;
474
481
  }
475
482
  static getGlobalScope(scope) {
476
- if (typeof scope === "string") return (0, radashi.get)(this.globalScopes, this.name + "." + scope);
477
- return (0, radashi.get)(this.globalScopes, this.name + "." + scope.constructor.name);
483
+ if (typeof scope === "string") return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope);
484
+ return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name);
478
485
  }
479
486
  static getAllGlobalScopes() {
480
487
  return this.globalScopes;
@@ -483,7 +490,7 @@ const HasGlobalScopes$1 = (Model) => {
483
490
  this.globalScopes = scopes;
484
491
  }
485
492
  getGlobalScopes() {
486
- return (0, radashi.get)(this.constructor.globalScopes, this.constructor.name, {});
493
+ return (0, _h3ravel_support.data_get)(this.constructor.globalScopes ?? {}, this.constructor.name, {});
487
494
  }
488
495
  };
489
496
  };
@@ -567,7 +574,7 @@ const HasHooks$1 = (Model) => {
567
574
  };
568
575
  //#endregion
569
576
  //#region src/collection.ts
570
- var Collection = class Collection extends collect_js.Collection {
577
+ var Collection = class extends _h3ravel_collect_js.Collection {
571
578
  newConstructor(...args) {
572
579
  return new (this.getConstructor())(...args);
573
580
  }
@@ -576,17 +583,18 @@ var Collection = class Collection extends collect_js.Collection {
576
583
  }
577
584
  async load(...relations) {
578
585
  if (this.isNotEmpty()) {
579
- const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.items);
586
+ const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.all());
580
587
  return this.newConstructor(items);
581
588
  }
582
589
  return this;
583
590
  }
584
591
  async loadAggregate(relations, column, action = null) {
585
592
  if (this.isEmpty()) return this;
586
- const models = (await this.first().newModelQuery().whereIn(this.first().getKeyName(), this.modelKeys()).select(this.first().getKeyName()).withAggregate(relations, column, action).get()).keyBy(this.first().getKeyName());
587
- const attributes = (0, radashi.diff)(Object.keys(models.first().getAttributes()), [models.first().getKeyName()]);
593
+ const first = this.first();
594
+ const models = (await first.newModelQuery().whereIn(first.getKeyName(), this.modelKeys()).select(first.getKeyName()).withAggregate(relations, column, action).get()).keyBy(first.getKeyName());
595
+ const attributes = (0, _h3ravel_collect_js.collect)(Object.keys(models.first().getAttributes())).diff([models.first().getKeyName()]).all();
588
596
  this.each((model) => {
589
- const extraAttributes = (0, radashi.pick)(models.get(model.getKey()).getAttributes(), attributes);
597
+ const extraAttributes = _h3ravel_support.Arr.select(models.get(model.getKey()).getAttributes(), attributes);
590
598
  model.fill(extraAttributes).syncOriginalAttributes(...attributes);
591
599
  });
592
600
  return this;
@@ -624,20 +632,21 @@ var Collection = class Collection extends collect_js.Collection {
624
632
  diff(items) {
625
633
  const diff = new this.constructor();
626
634
  const dictionary = this.getDictionary(items);
627
- this.items.map((item) => {
635
+ this.all().map((item) => {
628
636
  if (dictionary[item.getKey()] === void 0) diff.add(item);
629
637
  });
630
638
  return diff;
631
639
  }
632
- except(keys) {
633
- const dictionary = (0, radashi.omit)(this.getDictionary(), keys);
640
+ except(...keys) {
641
+ const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
642
+ const dictionary = _h3ravel_support.Arr.except(this.getDictionary(), values);
634
643
  return new this.constructor(Object.values(dictionary));
635
644
  }
636
645
  intersect(items) {
637
646
  const intersect = new this.constructor();
638
- if ((0, radashi.isEmpty)(items)) return intersect;
647
+ if (_h3ravel_support.Arr.isEmpty(items)) return intersect;
639
648
  const dictionary = this.getDictionary(items);
640
- for (const item of this.items) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
649
+ for (const item of this.all()) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
641
650
  return intersect;
642
651
  }
643
652
  unique(key, _strict = false) {
@@ -646,20 +655,21 @@ var Collection = class Collection extends collect_js.Collection {
646
655
  }
647
656
  find(key, defaultValue = null) {
648
657
  if (key instanceof Model) key = key.getKey();
649
- if ((0, radashi.isArray)(key)) {
658
+ if (Array.isArray(key)) {
650
659
  if (this.isEmpty()) return new this.constructor();
651
660
  return this.whereIn(this.first().getKeyName(), key);
652
661
  }
653
- (0, collect_js.collect)(this.items).first((model) => {
662
+ (0, _h3ravel_collect_js.collect)(this.all()).first((model) => {
654
663
  return model.getKey() == key;
655
664
  });
656
- return this.items.filter((model) => {
665
+ return this.all().filter((model) => {
657
666
  return model.getKey() == key;
658
667
  })[0] || defaultValue;
659
668
  }
660
669
  async fresh(...args) {
661
670
  if (this.isEmpty()) return new this.constructor();
662
671
  const model = this.first();
672
+ if (!model) return new this.constructor();
663
673
  const freshModels = (await model.newQuery().with(...args).whereIn(model.getKeyName(), this.modelKeys()).get()).getDictionary();
664
674
  return this.filter((model) => {
665
675
  return model.exists && freshModels[model.getKey()] !== void 0;
@@ -682,15 +692,15 @@ var Collection = class Collection extends collect_js.Collection {
682
692
  item.append(attributes);
683
693
  });
684
694
  }
685
- only(keys) {
686
- if (keys === null) return new Collection(this.items);
687
- const dictionary = (0, radashi.pick)(this.getDictionary(), keys);
695
+ only(...keys) {
696
+ const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
697
+ const dictionary = _h3ravel_support.Arr.select(this.getDictionary(), values);
688
698
  return new this.constructor(Object.values(dictionary));
689
699
  }
690
700
  getDictionary(items) {
691
- items = !items ? this.items : items;
701
+ const values = !items ? this.all() : items instanceof _h3ravel_collect_js.Collection ? items.all() : items;
692
702
  const dictionary = {};
693
- items.map((value) => {
703
+ values.map((value) => {
694
704
  dictionary[value.getKey()] = value;
695
705
  });
696
706
  return dictionary;
@@ -714,8 +724,8 @@ var Collection = class Collection extends collect_js.Collection {
714
724
  return JSON.stringify(this.toData(), ...args);
715
725
  }
716
726
  [Symbol.iterator] = () => {
717
- const items = this.items;
718
- const length = this.items.length;
727
+ const items = this.all();
728
+ const length = items.length;
719
729
  let n = 0;
720
730
  return { next() {
721
731
  return n < length ? {
@@ -762,24 +772,24 @@ const InteractsWithPivotTable = (Relation) => {
762
772
  let records;
763
773
  const results = await this.getCurrentlyAttachedPivots();
764
774
  const current = results.length === 0 ? [] : results.map((result) => result.toData()).pluck(this.relatedPivotKey).all().map((i) => String(i));
765
- const detach = (0, radashi.diff)(current, Object.keys(records = this.formatRecordsList(this.parseIds(ids))));
775
+ const detach = (0, _h3ravel_collect_js.collect)(current).diff(Object.keys(records = this.formatRecordsList(this.parseIds(ids)))).all();
766
776
  if (detaching && detach.length > 0) {
767
777
  await this.detach(detach);
768
778
  changes.detached = this.castKeys(detach);
769
779
  }
770
- changes = (0, radashi.assign)(changes, await this.attachNew(records, current, false));
780
+ changes = _h3ravel_support.Obj.deepMerge(changes, await this.attachNew(records, current, false));
771
781
  return changes;
772
782
  }
773
783
  syncWithoutDetaching(ids) {
774
784
  return this.sync(ids, false);
775
785
  }
776
786
  syncWithPivotValues(ids, values, detaching = true) {
777
- return this.sync((0, collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
778
- return [id, values];
787
+ return this.sync((0, _h3ravel_collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
788
+ return [String(id), values];
779
789
  }), detaching);
780
790
  }
781
791
  withPivot(columns) {
782
- this.pivotColumns = this.pivotColumns.concat((0, radashi.isArray)(columns) ? columns : Array.prototype.slice.call(columns));
792
+ this.pivotColumns = this.pivotColumns.concat(Array.isArray(columns) ? columns : Array.prototype.slice.call(columns));
783
793
  return this;
784
794
  }
785
795
  async attachNew(records, current, touch = true) {
@@ -815,9 +825,9 @@ const InteractsWithPivotTable = (Relation) => {
815
825
  return parseInt(updated);
816
826
  }
817
827
  formatRecordsList(records) {
818
- return (0, collect_js.collect)(records).mapWithKeys((attributes, id) => {
819
- if (!(0, radashi.isArray)(attributes)) [id, attributes] = [attributes, {}];
820
- return [id, attributes];
828
+ return (0, _h3ravel_collect_js.collect)(records).mapWithKeys((attributes, id) => {
829
+ if (!Array.isArray(attributes)) [id, attributes] = [attributes, {}];
830
+ return [String(id), attributes];
821
831
  }).all();
822
832
  }
823
833
  async getCurrentlyAttachedPivots() {
@@ -887,7 +897,7 @@ const InteractsWithPivotTable = (Relation) => {
887
897
  }
888
898
  formatAttachRecord(key, value, attributes, hasTimestamps) {
889
899
  const [id, newAttributes] = this.extractAttachIdAndAttributes(key, value, attributes);
890
- return (0, radashi.assign)(this.baseAttachRecord(id, hasTimestamps), newAttributes);
900
+ return _h3ravel_support.Obj.deepMerge(this.baseAttachRecord(id, hasTimestamps), newAttributes);
891
901
  }
892
902
  baseAttachRecord(id, timed) {
893
903
  let record = {};
@@ -900,7 +910,7 @@ const InteractsWithPivotTable = (Relation) => {
900
910
  return record;
901
911
  }
902
912
  extractAttachIdAndAttributes(key, value, newAttributes) {
903
- return (0, radashi.isArray)(value) ? [key, {
913
+ return Array.isArray(value) ? [key, {
904
914
  ...value,
905
915
  ...newAttributes
906
916
  }] : [value, newAttributes];
@@ -911,7 +921,7 @@ const InteractsWithPivotTable = (Relation) => {
911
921
  parseIds(value) {
912
922
  if (value instanceof Model) return [value[this.relatedKey]];
913
923
  if (value instanceof Collection) return value.pluck(this.relatedKey).all();
914
- return (0, radashi.isArray)(value) ? value : [value];
924
+ return Array.isArray(value) ? value : [value];
915
925
  }
916
926
  };
917
927
  };
@@ -1001,8 +1011,7 @@ var Relation = class {
1001
1011
  return this.parent.getQualifiedKeyName();
1002
1012
  }
1003
1013
  getExistenceCompareKey() {
1004
- var _this$getQualifiedFor;
1005
- return (_this$getQualifiedFor = this.getQualifiedForeignKeyName) === null || _this$getQualifiedFor === void 0 ? void 0 : _this$getQualifiedFor.call(this);
1014
+ return this.getQualifiedForeignKeyName?.();
1006
1015
  }
1007
1016
  };
1008
1017
  //#endregion
@@ -1061,9 +1070,8 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
1061
1070
  return this;
1062
1071
  }
1063
1072
  async get(columns) {
1064
- var _builder$query;
1065
1073
  const builder = this.query.applyScopes();
1066
- columns = ((_builder$query = builder.query) === null || _builder$query === void 0 || (_builder$query = _builder$query._statements) === null || _builder$query === void 0 ? void 0 : _builder$query.find((item) => item.grouping == "columns")) ? [] : columns;
1074
+ columns = builder.query?._statements?.find((item) => item.grouping == "columns") ? [] : columns;
1067
1075
  let models = await builder.select(this.shouldSelect(columns)).getModels();
1068
1076
  this.hydratePivotRelation(models);
1069
1077
  if (models.length > 0) models = await builder.eagerLoadRelations(models);
@@ -1112,7 +1120,7 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
1112
1120
  const value = model.attributes[key];
1113
1121
  if (key.startsWith("pivot_")) {
1114
1122
  values[key.substring(6)] = value;
1115
- model.attributes = (0, radashi.omit)(model.attributes, [key]);
1123
+ model.attributes = _h3ravel_support.Arr.except(model.attributes, [key]);
1116
1124
  }
1117
1125
  }
1118
1126
  return values;
@@ -1123,11 +1131,11 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
1123
1131
  return this.withPivot(this.createdAt(), this.updatedAt());
1124
1132
  }
1125
1133
  shouldSelect(columns = ["*"]) {
1126
- if ((0, radashi.isEqual)(columns, ["*"])) columns = [this.related.getTable() + ".*"];
1134
+ if (columns.length === 1 && columns[0] === "*") columns = [this.related.getTable() + ".*"];
1127
1135
  return columns.concat(this.aliasedPivotColumns());
1128
1136
  }
1129
1137
  aliasedPivotColumns() {
1130
- return (0, collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
1138
+ return (0, _h3ravel_collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
1131
1139
  return this.qualifyPivotColumn(column) + " as pivot_" + column;
1132
1140
  }).unique().all();
1133
1141
  }
@@ -1335,9 +1343,8 @@ var Builder = class Builder extends Inference$1 {
1335
1343
  }
1336
1344
  asProxy() {
1337
1345
  return new Proxy(this, { get(target, prop) {
1338
- var _target$query$connect;
1339
1346
  if (typeof target[prop] !== "undefined") return target[prop];
1340
- 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";
1347
+ const skipReturning = !!target.query.connector?.client.config?.client?.includes("mysql") && prop === "returning";
1341
1348
  if ([
1342
1349
  "select",
1343
1350
  "from",
@@ -1431,7 +1438,7 @@ var Builder = class Builder extends Inference$1 {
1431
1438
  };
1432
1439
  }
1433
1440
  if (prop.startsWith("where")) {
1434
- const column = (0, radashi.snake)(prop.substring(5));
1441
+ const column = _h3ravel_support.Str.snake(prop.substring(5));
1435
1442
  return (...args) => {
1436
1443
  target.query.where(column, ...args);
1437
1444
  return target.asProxy();
@@ -1506,7 +1513,8 @@ var Builder = class Builder extends Inference$1 {
1506
1513
  }
1507
1514
  addUpdatedAtColumn(values) {
1508
1515
  if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
1509
- values = (0, radashi.assign)({ [this.model.getUpdatedAtColumn()]: this.model.freshTimestampString() }, values);
1516
+ const column = this.model.getUpdatedAtColumn();
1517
+ values = _h3ravel_support.Obj.deepMerge({ [column]: this.model.freshTimestampString() }, values);
1510
1518
  return values;
1511
1519
  }
1512
1520
  delete() {
@@ -1534,9 +1542,8 @@ var Builder = class Builder extends Inference$1 {
1534
1542
  return this.model;
1535
1543
  }
1536
1544
  setModel(model) {
1537
- var _this$query;
1538
1545
  this.model = model;
1539
- if (typeof ((_this$query = this.query) === null || _this$query === void 0 || (_this$query = _this$query.client) === null || _this$query === void 0 ? void 0 : _this$query.table) == "function") this.query = this.query.client.table(this.model.getTable());
1546
+ if (typeof this.query?.client?.table == "function") this.query = this.query.client.table(this.model.getTable());
1540
1547
  else this.query = this.query.table(this.model.getTable());
1541
1548
  return this;
1542
1549
  }
@@ -1579,7 +1586,7 @@ var Builder = class Builder extends Inference$1 {
1579
1586
  }
1580
1587
  withoutGlobalScope(scope) {
1581
1588
  if (typeof scope !== "string") scope = scope.constructor.name;
1582
- this.globalScopes = (0, radashi.omit)(this.globalScopes, [scope]);
1589
+ this.globalScopes = _h3ravel_support.Arr.except(this.globalScopes, [scope]);
1583
1590
  return this;
1584
1591
  }
1585
1592
  macro(name, callback) {
@@ -1596,7 +1603,7 @@ var Builder = class Builder extends Inference$1 {
1596
1603
  let eagerLoads = {};
1597
1604
  if (typeof args[1] === "function") {
1598
1605
  const eagerLoad = this.parseWithRelations({ [args[0]]: args[1] });
1599
- this.eagerLoad = (0, radashi.assign)(this.eagerLoad, eagerLoad);
1606
+ this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, eagerLoad);
1600
1607
  return this;
1601
1608
  }
1602
1609
  const relations = flattenDeep(args);
@@ -1605,13 +1612,13 @@ var Builder = class Builder extends Inference$1 {
1605
1612
  let eagerLoad;
1606
1613
  if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
1607
1614
  else if (typeof relation === "object") eagerLoad = relation;
1608
- eagerLoads = (0, radashi.assign)(eagerLoads, eagerLoad);
1615
+ eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
1609
1616
  }
1610
- this.eagerLoad = (0, radashi.assign)(this.eagerLoad, this.parseWithRelations(eagerLoads));
1617
+ this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, this.parseWithRelations(eagerLoads));
1611
1618
  return this;
1612
1619
  }
1613
1620
  has(relation, operator = ">=", count = 1, boolean = "and", callback = null) {
1614
- if ((0, radashi.isString)(relation)) {
1621
+ if (typeof relation === "string") {
1615
1622
  if (relation.includes(".")) return this.hasNested(relation, operator, count, boolean, callback);
1616
1623
  relation = this.getRelationWithoutConstraints(getRelationMethod(relation));
1617
1624
  }
@@ -1688,7 +1695,7 @@ var Builder = class Builder extends Inference$1 {
1688
1695
  let eagerLoad;
1689
1696
  if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
1690
1697
  else if (typeof relation === "object") eagerLoad = relation;
1691
- eagerLoads = (0, radashi.assign)(eagerLoads, eagerLoad);
1698
+ eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
1692
1699
  }
1693
1700
  relations = eagerLoads;
1694
1701
  const db = this.model.getConnection();
@@ -1707,7 +1714,7 @@ var Builder = class Builder extends Inference$1 {
1707
1714
  } else expression = column;
1708
1715
  const query = relation.getRelationExistenceQuery(relation.getRelated().newModelQuery(), this, db.raw(expression));
1709
1716
  constraints(query);
1710
- alias = alias || (0, radashi.snake)(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
1717
+ alias = alias || _h3ravel_support.Str.snake(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
1711
1718
  if (action === "exists") this.select(db.raw(`exists(${query.toSql().sql}) as ${alias}`));
1712
1719
  else this.selectSub(action ? query : query.limit(1), alias);
1713
1720
  }
@@ -1731,7 +1738,7 @@ var Builder = class Builder extends Inference$1 {
1731
1738
  }
1732
1739
  parseSub(query) {
1733
1740
  if (query instanceof Builder || query instanceof Relation) return [query.toSql().sql, query.toSql().bindings];
1734
- else if ((0, radashi.isString)(query)) return [query, []];
1741
+ else if (typeof query === "string") return [query, []];
1735
1742
  else throw new Error("A subquery must be a query builder instance, a Closure, or a string.");
1736
1743
  }
1737
1744
  prependDatabaseNameIfCrossDatabaseQuery(query) {
@@ -1788,15 +1795,15 @@ var Builder = class Builder extends Inference$1 {
1788
1795
  if (prefix !== "") prefix += ".";
1789
1796
  for (const key in relations) {
1790
1797
  const value = relations[key];
1791
- if ((0, radashi.isString)(value) || Number.isFinite(parseInt(value))) continue;
1798
+ if (typeof value === "string" || Number.isFinite(parseInt(value))) continue;
1792
1799
  const [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(key, value);
1793
1800
  preparedRelationships = Object.assign({}, preparedRelationships, { [`${prefix}${attribute}`]: attributeSelectConstraint }, this.prepareNestedWithRelationships(value, `${prefix}${attribute}`));
1794
- relations = (0, radashi.omit)(relations, [key]);
1801
+ relations = _h3ravel_support.Arr.except(relations, [key]);
1795
1802
  }
1796
1803
  for (const key in relations) {
1797
1804
  const value = relations[key];
1798
1805
  let attribute = key, attributeSelectConstraint = value;
1799
- if ((0, radashi.isString)(value)) [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
1806
+ if (typeof value === "string") [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
1800
1807
  preparedRelationships[`${prefix}${attribute}`] = this.combineConstraints([attributeSelectConstraint, preparedRelationships[`${prefix}${attribute}`] || (() => {})]);
1801
1808
  }
1802
1809
  return preparedRelationships;
@@ -1844,8 +1851,8 @@ var Builder = class Builder extends Inference$1 {
1844
1851
  }
1845
1852
  async findOrFail(...args) {
1846
1853
  const data = await this.find(...args);
1847
- if ((0, radashi.isArray)(args[0])) {
1848
- if (data.count() !== args[0].length) throw new ModelNotFoundError().setModel(this.model.constructor.name, (0, radashi.diff)(args[0], data.modelKeys()));
1854
+ if (Array.isArray(args[0])) {
1855
+ if (data.count() !== args[0].length) throw new ModelNotFoundError().setModel(this.model.constructor.name, (0, _h3ravel_collect_js.collect)(args[0]).diff(data.modelKeys()).all());
1849
1856
  return data;
1850
1857
  }
1851
1858
  if (data === null) throw new ModelNotFoundError().setModel(this.model.constructor.name, args[0]);
@@ -1859,12 +1866,12 @@ var Builder = class Builder extends Inference$1 {
1859
1866
  async firstOrNew(attributes = {}, values = {}) {
1860
1867
  const instance = await this.where(attributes).first();
1861
1868
  if (instance !== null) return instance;
1862
- return this.newModelInstance((0, radashi.assign)(attributes, values));
1869
+ return this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values));
1863
1870
  }
1864
1871
  async firstOrCreate(attributes = {}, values = {}) {
1865
1872
  const instance = await this.where(attributes).first();
1866
1873
  if (instance !== null) return instance;
1867
- return tap(this.newModelInstance((0, radashi.assign)(attributes, values)), async (instance) => {
1874
+ return tap(this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values)), async (instance) => {
1868
1875
  await instance.save({ client: this.query });
1869
1876
  });
1870
1877
  }
@@ -1884,22 +1891,21 @@ var Builder = class Builder extends Inference$1 {
1884
1891
  return this;
1885
1892
  }
1886
1893
  async find(id, columns) {
1887
- if ((0, radashi.isArray)(id) || id instanceof Collection) return await this.findMany(id, columns);
1894
+ if (Array.isArray(id) || id instanceof Collection) return await this.findMany(id, columns);
1888
1895
  return await this.where(this.model.getKeyName(), id).first(columns);
1889
1896
  }
1890
1897
  async findMany(ids, columns = ["*"]) {
1891
- if (ids instanceof Collection) ids = ids.modelKeys();
1892
- ids = (0, radashi.isArray)(ids) ? ids : [ids];
1893
- if (ids.length === 0) return new Collection([]);
1894
- return await this.whereIn(this.model.getKeyName(), ids).get(columns);
1898
+ const values = ids instanceof Collection ? ids.modelKeys() : Array.isArray(ids) ? ids : [ids];
1899
+ if (values.length === 0) return new Collection([]);
1900
+ return await this.whereIn(this.model.getKeyName(), values).get(columns);
1895
1901
  }
1896
1902
  async pluck(column) {
1897
1903
  return new Collection(await this.query.pluck(column));
1898
1904
  }
1899
1905
  async destroy(ids) {
1900
1906
  if (ids instanceof Collection) ids = ids.modelKeys();
1901
- if (ids instanceof collect_js.Collection) ids = ids.all();
1902
- ids = (0, radashi.isArray)(ids) ? ids : Array.prototype.slice.call(ids);
1907
+ if (ids instanceof _h3ravel_collect_js.Collection) ids = ids.all();
1908
+ ids = Array.isArray(ids) ? ids : Array.prototype.slice.call(ids);
1903
1909
  if (ids.length === 0) return 0;
1904
1910
  const key = this.model.newInstance().getKeyName();
1905
1911
  let count = 0;
@@ -1917,12 +1923,11 @@ var Builder = class Builder extends Inference$1 {
1917
1923
  return await this.model.newModelQuery().get(columns);
1918
1924
  }
1919
1925
  async paginate(page = 1, perPage = 10) {
1920
- var _this;
1921
1926
  page = page || 1;
1922
- perPage = perPage || ((_this = this) === null || _this === void 0 || (_this = _this.model) === null || _this === void 0 ? void 0 : _this.perPage) || 15;
1927
+ perPage = perPage || this?.model?.perPage || 15;
1923
1928
  this.applyScopes();
1924
1929
  const total = await this.query.clone().clearOrder().clearSelect().count(this.primaryKey);
1925
- let results = [];
1930
+ let results;
1926
1931
  if (total > 0) {
1927
1932
  const skip = (page - 1) * (perPage ?? 10);
1928
1933
  this.take(perPage).skip(skip);
@@ -1932,7 +1937,7 @@ var Builder = class Builder extends Inference$1 {
1932
1937
  return new Paginator(results, parseInt(total), perPage, page);
1933
1938
  }
1934
1939
  async getModels(...columns) {
1935
- columns = (0, radashi.flat)(columns);
1940
+ columns = flatten(columns);
1936
1941
  if (columns.length > 0) {
1937
1942
  if (this.query._statements.filter((item) => item.grouping == "columns").length == 0 && columns[0] !== "*") this.query.select(...columns);
1938
1943
  }
@@ -1994,7 +1999,7 @@ const HasOneOrMany = (Relation) => {
1994
1999
  }
1995
2000
  buildDictionary(results) {
1996
2001
  const foreign = this.getForeignKeyName();
1997
- return (0, collect_js.default)(results).mapToDictionary((result) => [result[foreign], result]).all();
2002
+ return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
1998
2003
  }
1999
2004
  async save(model) {
2000
2005
  this.setForeignAttributesForCreate(model);
@@ -2065,13 +2070,11 @@ var HasMany = class extends compose(Relation, HasOneOrMany) {
2065
2070
  return this.getParentKey() !== null ? await this.query.get() : new Collection([]);
2066
2071
  }
2067
2072
  getForeignKeyName() {
2068
- var _this$foreignKey;
2069
- const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
2070
- return segments === null || segments === void 0 ? void 0 : segments.pop();
2073
+ return (this.foreignKey?.split("."))?.pop();
2071
2074
  }
2072
2075
  buildDictionary(results) {
2073
2076
  const foreign = this.getForeignKeyName();
2074
- return (0, collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
2077
+ return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
2075
2078
  }
2076
2079
  match(models, results, relation) {
2077
2080
  return this.matchOneOrMany(models, results, relation, "many");
@@ -2120,9 +2123,7 @@ var HasOne = class extends compose(Relation, HasOneOrMany, SupportsDefaultModels
2120
2123
  return this.matchOneOrMany(models, results, relation, "one");
2121
2124
  }
2122
2125
  getForeignKeyName() {
2123
- var _this$foreignKey;
2124
- const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
2125
- return segments === null || segments === void 0 ? void 0 : segments.pop();
2126
+ return (this.foreignKey?.split("."))?.pop();
2126
2127
  }
2127
2128
  async getResults() {
2128
2129
  if (this.getParentKey() === null) return this.getDefaultFor(this.parent);
@@ -2191,7 +2192,7 @@ const HidesAttributes$1 = (Model) => {
2191
2192
  makeVisible(...keys) {
2192
2193
  const visible = flattenDeep(keys);
2193
2194
  if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
2194
- this.hidden = (0, radashi.diff)(this.hidden, visible);
2195
+ this.hidden = (0, _h3ravel_collect_js.collect)(this.hidden).diff(visible).all();
2195
2196
  return this;
2196
2197
  }
2197
2198
  makeHidden(key, ...keys) {
@@ -2279,10 +2280,9 @@ var QueryBuilder = class QueryBuilder extends Inference {
2279
2280
  asProxy() {
2280
2281
  return new Proxy(this, {
2281
2282
  get: function(target, prop) {
2282
- var _target$connector$cli;
2283
2283
  if (typeof target[prop] !== "undefined") return target[prop];
2284
2284
  if (["destroy", "schema"].includes(prop)) return target.connector.schema;
2285
- 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";
2285
+ const skipReturning = !!target.connector.client.config?.client?.includes("mysql") && prop === "returning";
2286
2286
  if ([
2287
2287
  "select",
2288
2288
  "from",
@@ -2485,6 +2485,9 @@ var arquebus = class arquebus {
2485
2485
  if (this.instance === null) this.instance = new arquebus();
2486
2486
  return this.instance;
2487
2487
  }
2488
+ static withSchema() {
2489
+ return this;
2490
+ }
2488
2491
  /**
2489
2492
  * Initialize a new database connection
2490
2493
  *
@@ -2574,12 +2577,12 @@ var arquebus = class arquebus {
2574
2577
  const tsPath = path.default.resolve("arquebus.config.ts");
2575
2578
  const instance = this.getInstance();
2576
2579
  if ((0, fs.existsSync)(jsPath)) {
2577
- config = (await import(jsPath)).default;
2580
+ config = (await (0, _h3ravel_shared.importFile)(jsPath)).default;
2578
2581
  if (addConnection) instance.addConnection(config, config.client);
2579
2582
  return config;
2580
2583
  }
2581
2584
  if ((0, fs.existsSync)(tsPath)) if (process.env.NODE_ENV !== "production") {
2582
- config = (await import(tsPath)).default;
2585
+ config = (await (0, _h3ravel_shared.importFile)(tsPath)).default;
2583
2586
  if (addConnection) instance.addConnection(config, config.client);
2584
2587
  return config;
2585
2588
  } else throw new Error("arquebus.config.ts found in production without build step");
@@ -2595,7 +2598,7 @@ var arquebus = class arquebus {
2595
2598
  "cjs"
2596
2599
  ], dir);
2597
2600
  if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
2598
- config = (await import(found)).default;
2601
+ config = (await (0, _h3ravel_shared.importFile)(found)).default;
2599
2602
  if (addConnection) instance.addConnection(config, config.client);
2600
2603
  return config;
2601
2604
  } else throw new Error("arquebus.config.ts found in production without build step");
@@ -2616,7 +2619,7 @@ var arquebus = class arquebus {
2616
2619
  }
2617
2620
  async destroyAll() {
2618
2621
  await Promise.all(Object.values(this.manager).map((connection) => {
2619
- return connection === null || connection === void 0 ? void 0 : connection.destroy();
2622
+ return connection?.destroy();
2620
2623
  }));
2621
2624
  }
2622
2625
  createModel(name, options = {}) {
@@ -2625,29 +2628,25 @@ var arquebus = class arquebus {
2625
2628
  this.models = {
2626
2629
  ...this.models,
2627
2630
  [name]: class extends BaseModel {
2628
- table = (options === null || options === void 0 ? void 0 : options.table) ?? null;
2629
- connection = (options === null || options === void 0 ? void 0 : options.connection) ?? null;
2630
- timestamps = (options === null || options === void 0 ? void 0 : options.timestamps) ?? true;
2631
- primaryKey = (options === null || options === void 0 ? void 0 : options.primaryKey) ?? "id";
2632
- keyType = (options === null || options === void 0 ? void 0 : options.keyType) ?? "int";
2633
- incrementing = (options === null || options === void 0 ? void 0 : options.incrementing) ?? true;
2634
- with = (options === null || options === void 0 ? void 0 : options.with) ?? [];
2635
- casts = (options === null || options === void 0 ? void 0 : options.casts) ?? {};
2636
- static CREATED_AT = (options === null || options === void 0 ? void 0 : options.CREATED_AT) ?? "created_at";
2637
- static UPDATED_AT = (options === null || options === void 0 ? void 0 : options.UPDATED_AT) ?? "updated_at";
2638
- static DELETED_AT = (options === null || options === void 0 ? void 0 : options.DELETED_AT) ?? "deleted_at";
2631
+ table = options?.table ?? null;
2632
+ connection = options?.connection ?? null;
2633
+ timestamps = options?.timestamps ?? true;
2634
+ primaryKey = options?.primaryKey ?? "id";
2635
+ keyType = options?.keyType ?? "int";
2636
+ incrementing = options?.incrementing ?? true;
2637
+ with = options?.with ?? [];
2638
+ casts = options?.casts ?? {};
2639
+ static CREATED_AT = options?.CREATED_AT ?? "created_at";
2640
+ static UPDATED_AT = options?.UPDATED_AT ?? "updated_at";
2641
+ static DELETED_AT = options?.DELETED_AT ?? "deleted_at";
2639
2642
  }
2640
2643
  };
2641
2644
  if ("attributes" in options) for (const attribute in options.attributes) {
2642
2645
  if (options.attributes[attribute] instanceof Attribute === false) throw new Error("Attribute must be an instance of \"Attribute\"");
2643
- this.models[name].prototype[getAttrMethod(attribute)] = () => {
2644
- var _options$attributes;
2645
- return (_options$attributes = options.attributes) === null || _options$attributes === void 0 ? void 0 : _options$attributes[attribute];
2646
- };
2646
+ this.models[name].prototype[getAttrMethod(attribute)] = () => options.attributes?.[attribute];
2647
2647
  }
2648
2648
  if ("relations" in options) for (const relation in options.relations) this.models[name].prototype[getRelationMethod(relation)] = function() {
2649
- var _options$relations;
2650
- return (_options$relations = options.relations) === null || _options$relations === void 0 ? void 0 : _options$relations[relation](this);
2649
+ return options.relations?.[relation](this);
2651
2650
  };
2652
2651
  if ("scopes" in options) for (const scope in options.scopes) this.models[name].prototype[getScopeMethod(scope)] = options.scopes[scope];
2653
2652
  this.models[name].setConnectionResolver(this);
@@ -2685,6 +2684,9 @@ var Model = class Model extends BaseModel {
2685
2684
  this.buildRelationships(attributes);
2686
2685
  return this.asProxy();
2687
2686
  }
2687
+ static define() {
2688
+ return this;
2689
+ }
2688
2690
  static query(trx = null) {
2689
2691
  return new this().newQuery(trx);
2690
2692
  }
@@ -2868,7 +2870,7 @@ var Model = class Model extends BaseModel {
2868
2870
  });
2869
2871
  }
2870
2872
  toData() {
2871
- return (0, radashi.assign)(this.attributesToData(), this.relationsToData());
2873
+ return _h3ravel_support.Obj.deepMerge(this.attributesToData(), this.relationsToData());
2872
2874
  }
2873
2875
  toJSON() {
2874
2876
  return this.toData();
@@ -2879,6 +2881,15 @@ var Model = class Model extends BaseModel {
2879
2881
  toString() {
2880
2882
  return this.toJson();
2881
2883
  }
2884
+ getAttributes() {
2885
+ return super.getAttributes();
2886
+ }
2887
+ getAttribute(key) {
2888
+ return super.getAttribute(key);
2889
+ }
2890
+ setAttribute(key, value) {
2891
+ return super.setAttribute(key, value);
2892
+ }
2882
2893
  fill(attributes) {
2883
2894
  for (const key in attributes) this.setAttribute(key, attributes[key]);
2884
2895
  return this;
@@ -2919,10 +2930,9 @@ var Model = class Model extends BaseModel {
2919
2930
  if (this.usesTimestamps()) this.updateTimestamps();
2920
2931
  const attributes = this.getAttributes();
2921
2932
  if (this.getIncrementing()) {
2922
- var _data$;
2923
2933
  const keyName = this.getKeyName();
2924
2934
  const data = await query.insert([attributes], [keyName]);
2925
- this.setAttribute(keyName, ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$[keyName]) || data[0]);
2935
+ this.setAttribute(keyName, data[0]?.[keyName] || data[0]);
2926
2936
  } else if (Object.keys(attributes).length > 0) await query.insert(attributes);
2927
2937
  this.exists = true;
2928
2938
  await this.execHooks("created", options);
@@ -2964,7 +2974,7 @@ var Model = class Model extends BaseModel {
2964
2974
  if (!this.exists) return Promise.resolve(void 0);
2965
2975
  const model = await this.constructor.query().where(this.getKeyName(), this.getKey()).first();
2966
2976
  this.attributes = { ...model.attributes };
2967
- await this.load((0, collect_js.default)(this.relations).reject((relation) => {
2977
+ await this.load((0, _h3ravel_collect_js.collect)(this.relations).reject((relation) => {
2968
2978
  return relation instanceof Pivot;
2969
2979
  }).keys().all());
2970
2980
  this.syncOriginal();
@@ -3206,10 +3216,10 @@ var HasManyThrough = class extends Relation {
3206
3216
  }
3207
3217
  const model = await this.first(columns);
3208
3218
  if (model) return model;
3209
- return callback === null || callback === void 0 ? void 0 : callback();
3219
+ return callback?.();
3210
3220
  }
3211
3221
  async find(id, columns = ["*"]) {
3212
- if ((0, radashi.isArray)(id)) return await this.findMany(id, columns);
3222
+ if (Array.isArray(id)) return await this.findMany(id, columns);
3213
3223
  return await this.where(this.getRelated().getQualifiedKeyName(), "=", id).first(columns);
3214
3224
  }
3215
3225
  async findMany(ids, columns = ["*"]) {
@@ -3237,7 +3247,7 @@ var HasManyThrough = class extends Relation {
3237
3247
  return await this.query.paginate(perPage ?? 15, columns, pageName, page);
3238
3248
  }
3239
3249
  shouldSelect(columns = ["*"]) {
3240
- if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
3250
+ if (columns?.at(0) == "*") columns = [this.related.getTable() + ".*"];
3241
3251
  return [...columns, this.getQualifiedFirstKeyName() + " as laravel_through_key"];
3242
3252
  }
3243
3253
  async chunk(count, callback) {
@@ -3331,7 +3341,7 @@ const HasRelations$1 = (Model) => {
3331
3341
  return this;
3332
3342
  }
3333
3343
  unsetRelation(relation) {
3334
- this.relations = (0, radashi.omit)(this.relations, [relation]);
3344
+ this.relations = _h3ravel_support.Arr.except(this.relations, [relation]);
3335
3345
  return this;
3336
3346
  }
3337
3347
  relationLoaded(relation) {
@@ -3354,8 +3364,7 @@ const HasRelations$1 = (Model) => {
3354
3364
  return data;
3355
3365
  }
3356
3366
  guessBelongsToRelation() {
3357
- var _e$stack;
3358
- const functionName = (((_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2]) ?? "").split(" ")[5];
3367
+ const functionName = ((/* @__PURE__ */ new Error()).stack?.split("\n")[2] ?? "").split(" ")[5];
3359
3368
  return getRelationName(functionName);
3360
3369
  }
3361
3370
  joiningTable(related, instance = null) {