@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,11 +155,12 @@ 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/collection.ts
159
- var Collection = class Collection extends collect_js.Collection {
163
+ var Collection = class extends _h3ravel_collect_js.Collection {
160
164
  newConstructor(...args) {
161
165
  return new (this.getConstructor())(...args);
162
166
  }
@@ -165,17 +169,18 @@ var Collection = class Collection extends collect_js.Collection {
165
169
  }
166
170
  async load(...relations) {
167
171
  if (this.isNotEmpty()) {
168
- const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.items);
172
+ const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.all());
169
173
  return this.newConstructor(items);
170
174
  }
171
175
  return this;
172
176
  }
173
177
  async loadAggregate(relations, column, action = null) {
174
178
  if (this.isEmpty()) return this;
175
- 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());
176
- const attributes = (0, radashi.diff)(Object.keys(models.first().getAttributes()), [models.first().getKeyName()]);
179
+ const first = this.first();
180
+ const models = (await first.newModelQuery().whereIn(first.getKeyName(), this.modelKeys()).select(first.getKeyName()).withAggregate(relations, column, action).get()).keyBy(first.getKeyName());
181
+ const attributes = (0, _h3ravel_collect_js.collect)(Object.keys(models.first().getAttributes())).diff([models.first().getKeyName()]).all();
177
182
  this.each((model) => {
178
- const extraAttributes = (0, radashi.pick)(models.get(model.getKey()).getAttributes(), attributes);
183
+ const extraAttributes = _h3ravel_support.Arr.select(models.get(model.getKey()).getAttributes(), attributes);
179
184
  model.fill(extraAttributes).syncOriginalAttributes(...attributes);
180
185
  });
181
186
  return this;
@@ -213,20 +218,21 @@ var Collection = class Collection extends collect_js.Collection {
213
218
  diff(items) {
214
219
  const diff = new this.constructor();
215
220
  const dictionary = this.getDictionary(items);
216
- this.items.map((item) => {
221
+ this.all().map((item) => {
217
222
  if (dictionary[item.getKey()] === void 0) diff.add(item);
218
223
  });
219
224
  return diff;
220
225
  }
221
- except(keys) {
222
- const dictionary = (0, radashi.omit)(this.getDictionary(), keys);
226
+ except(...keys) {
227
+ const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
228
+ const dictionary = _h3ravel_support.Arr.except(this.getDictionary(), values);
223
229
  return new this.constructor(Object.values(dictionary));
224
230
  }
225
231
  intersect(items) {
226
232
  const intersect = new this.constructor();
227
- if ((0, radashi.isEmpty)(items)) return intersect;
233
+ if (_h3ravel_support.Arr.isEmpty(items)) return intersect;
228
234
  const dictionary = this.getDictionary(items);
229
- for (const item of this.items) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
235
+ for (const item of this.all()) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
230
236
  return intersect;
231
237
  }
232
238
  unique(key, _strict = false) {
@@ -235,20 +241,21 @@ var Collection = class Collection extends collect_js.Collection {
235
241
  }
236
242
  find(key, defaultValue = null) {
237
243
  if (key instanceof Model) key = key.getKey();
238
- if ((0, radashi.isArray)(key)) {
244
+ if (Array.isArray(key)) {
239
245
  if (this.isEmpty()) return new this.constructor();
240
246
  return this.whereIn(this.first().getKeyName(), key);
241
247
  }
242
- (0, collect_js.collect)(this.items).first((model) => {
248
+ (0, _h3ravel_collect_js.collect)(this.all()).first((model) => {
243
249
  return model.getKey() == key;
244
250
  });
245
- return this.items.filter((model) => {
251
+ return this.all().filter((model) => {
246
252
  return model.getKey() == key;
247
253
  })[0] || defaultValue;
248
254
  }
249
255
  async fresh(...args) {
250
256
  if (this.isEmpty()) return new this.constructor();
251
257
  const model = this.first();
258
+ if (!model) return new this.constructor();
252
259
  const freshModels = (await model.newQuery().with(...args).whereIn(model.getKeyName(), this.modelKeys()).get()).getDictionary();
253
260
  return this.filter((model) => {
254
261
  return model.exists && freshModels[model.getKey()] !== void 0;
@@ -271,15 +278,15 @@ var Collection = class Collection extends collect_js.Collection {
271
278
  item.append(attributes);
272
279
  });
273
280
  }
274
- only(keys) {
275
- if (keys === null) return new Collection(this.items);
276
- const dictionary = (0, radashi.pick)(this.getDictionary(), keys);
281
+ only(...keys) {
282
+ const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
283
+ const dictionary = _h3ravel_support.Arr.select(this.getDictionary(), values);
277
284
  return new this.constructor(Object.values(dictionary));
278
285
  }
279
286
  getDictionary(items) {
280
- items = !items ? this.items : items;
287
+ const values = !items ? this.all() : items instanceof _h3ravel_collect_js.Collection ? items.all() : items;
281
288
  const dictionary = {};
282
- items.map((value) => {
289
+ values.map((value) => {
283
290
  dictionary[value.getKey()] = value;
284
291
  });
285
292
  return dictionary;
@@ -303,8 +310,8 @@ var Collection = class Collection extends collect_js.Collection {
303
310
  return JSON.stringify(this.toData(), ...args);
304
311
  }
305
312
  [Symbol.iterator] = () => {
306
- const items = this.items;
307
- const length = this.items.length;
313
+ const items = this.all();
314
+ const length = items.length;
308
315
  let n = 0;
309
316
  return { next() {
310
317
  return n < length ? {
@@ -351,24 +358,24 @@ const InteractsWithPivotTable$1 = (Relation) => {
351
358
  let records;
352
359
  const results = await this.getCurrentlyAttachedPivots();
353
360
  const current = results.length === 0 ? [] : results.map((result) => result.toData()).pluck(this.relatedPivotKey).all().map((i) => String(i));
354
- const detach = (0, radashi.diff)(current, Object.keys(records = this.formatRecordsList(this.parseIds(ids))));
361
+ const detach = (0, _h3ravel_collect_js.collect)(current).diff(Object.keys(records = this.formatRecordsList(this.parseIds(ids)))).all();
355
362
  if (detaching && detach.length > 0) {
356
363
  await this.detach(detach);
357
364
  changes.detached = this.castKeys(detach);
358
365
  }
359
- changes = (0, radashi.assign)(changes, await this.attachNew(records, current, false));
366
+ changes = _h3ravel_support.Obj.deepMerge(changes, await this.attachNew(records, current, false));
360
367
  return changes;
361
368
  }
362
369
  syncWithoutDetaching(ids) {
363
370
  return this.sync(ids, false);
364
371
  }
365
372
  syncWithPivotValues(ids, values, detaching = true) {
366
- return this.sync((0, collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
367
- return [id, values];
373
+ return this.sync((0, _h3ravel_collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
374
+ return [String(id), values];
368
375
  }), detaching);
369
376
  }
370
377
  withPivot(columns) {
371
- this.pivotColumns = this.pivotColumns.concat((0, radashi.isArray)(columns) ? columns : Array.prototype.slice.call(columns));
378
+ this.pivotColumns = this.pivotColumns.concat(Array.isArray(columns) ? columns : Array.prototype.slice.call(columns));
372
379
  return this;
373
380
  }
374
381
  async attachNew(records, current, touch = true) {
@@ -404,9 +411,9 @@ const InteractsWithPivotTable$1 = (Relation) => {
404
411
  return parseInt(updated);
405
412
  }
406
413
  formatRecordsList(records) {
407
- return (0, collect_js.collect)(records).mapWithKeys((attributes, id) => {
408
- if (!(0, radashi.isArray)(attributes)) [id, attributes] = [attributes, {}];
409
- return [id, attributes];
414
+ return (0, _h3ravel_collect_js.collect)(records).mapWithKeys((attributes, id) => {
415
+ if (!Array.isArray(attributes)) [id, attributes] = [attributes, {}];
416
+ return [String(id), attributes];
410
417
  }).all();
411
418
  }
412
419
  async getCurrentlyAttachedPivots() {
@@ -476,7 +483,7 @@ const InteractsWithPivotTable$1 = (Relation) => {
476
483
  }
477
484
  formatAttachRecord(key, value, attributes, hasTimestamps) {
478
485
  const [id, newAttributes] = this.extractAttachIdAndAttributes(key, value, attributes);
479
- return (0, radashi.assign)(this.baseAttachRecord(id, hasTimestamps), newAttributes);
486
+ return _h3ravel_support.Obj.deepMerge(this.baseAttachRecord(id, hasTimestamps), newAttributes);
480
487
  }
481
488
  baseAttachRecord(id, timed) {
482
489
  let record = {};
@@ -489,7 +496,7 @@ const InteractsWithPivotTable$1 = (Relation) => {
489
496
  return record;
490
497
  }
491
498
  extractAttachIdAndAttributes(key, value, newAttributes) {
492
- return (0, radashi.isArray)(value) ? [key, {
499
+ return Array.isArray(value) ? [key, {
493
500
  ...value,
494
501
  ...newAttributes
495
502
  }] : [value, newAttributes];
@@ -500,7 +507,7 @@ const InteractsWithPivotTable$1 = (Relation) => {
500
507
  parseIds(value) {
501
508
  if (value instanceof Model) return [value[this.relatedKey]];
502
509
  if (value instanceof Collection) return value.pluck(this.relatedKey).all();
503
- return (0, radashi.isArray)(value) ? value : [value];
510
+ return Array.isArray(value) ? value : [value];
504
511
  }
505
512
  };
506
513
  };
@@ -522,7 +529,7 @@ var ModelNotFoundError = class extends BaseError {
522
529
  }
523
530
  setModel(model, ids = []) {
524
531
  this.model = model;
525
- this.ids = (0, radashi.isArray)(ids) ? ids : [ids];
532
+ this.ids = Array.isArray(ids) ? ids : [ids];
526
533
  this.message = `No query results for model [${model}]`;
527
534
  if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
528
535
  else this.message += ".";
@@ -623,8 +630,7 @@ var Relation$1 = class {
623
630
  return this.parent.getQualifiedKeyName();
624
631
  }
625
632
  getExistenceCompareKey() {
626
- var _this$getQualifiedFor;
627
- return (_this$getQualifiedFor = this.getQualifiedForeignKeyName) === null || _this$getQualifiedFor === void 0 ? void 0 : _this$getQualifiedFor.call(this);
633
+ return this.getQualifiedForeignKeyName?.();
628
634
  }
629
635
  };
630
636
  //#endregion
@@ -683,9 +689,8 @@ var BelongsToMany$1 = class extends compose(Relation$1, InteractsWithPivotTable$
683
689
  return this;
684
690
  }
685
691
  async get(columns) {
686
- var _builder$query;
687
692
  const builder = this.query.applyScopes();
688
- 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;
693
+ columns = builder.query?._statements?.find((item) => item.grouping == "columns") ? [] : columns;
689
694
  let models = await builder.select(this.shouldSelect(columns)).getModels();
690
695
  this.hydratePivotRelation(models);
691
696
  if (models.length > 0) models = await builder.eagerLoadRelations(models);
@@ -734,7 +739,7 @@ var BelongsToMany$1 = class extends compose(Relation$1, InteractsWithPivotTable$
734
739
  const value = model.attributes[key];
735
740
  if (key.startsWith("pivot_")) {
736
741
  values[key.substring(6)] = value;
737
- model.attributes = (0, radashi.omit)(model.attributes, [key]);
742
+ model.attributes = _h3ravel_support.Arr.except(model.attributes, [key]);
738
743
  }
739
744
  }
740
745
  return values;
@@ -745,11 +750,11 @@ var BelongsToMany$1 = class extends compose(Relation$1, InteractsWithPivotTable$
745
750
  return this.withPivot(this.createdAt(), this.updatedAt());
746
751
  }
747
752
  shouldSelect(columns = ["*"]) {
748
- if ((0, radashi.isEqual)(columns, ["*"])) columns = [this.related.getTable() + ".*"];
753
+ if (columns.length === 1 && columns[0] === "*") columns = [this.related.getTable() + ".*"];
749
754
  return columns.concat(this.aliasedPivotColumns());
750
755
  }
751
756
  aliasedPivotColumns() {
752
- return (0, collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
757
+ return (0, _h3ravel_collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
753
758
  return this.qualifyPivotColumn(column) + " as pivot_" + column;
754
759
  }).unique().all();
755
760
  }
@@ -967,9 +972,8 @@ var Builder = class Builder extends Inference$1 {
967
972
  }
968
973
  asProxy() {
969
974
  return new Proxy(this, { get(target, prop) {
970
- var _target$query$connect;
971
975
  if (typeof target[prop] !== "undefined") return target[prop];
972
- 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";
976
+ const skipReturning = !!target.query.connector?.client.config?.client?.includes("mysql") && prop === "returning";
973
977
  if ([
974
978
  "select",
975
979
  "from",
@@ -1063,7 +1067,7 @@ var Builder = class Builder extends Inference$1 {
1063
1067
  };
1064
1068
  }
1065
1069
  if (prop.startsWith("where")) {
1066
- const column = (0, radashi.snake)(prop.substring(5));
1070
+ const column = _h3ravel_support.Str.snake(prop.substring(5));
1067
1071
  return (...args) => {
1068
1072
  target.query.where(column, ...args);
1069
1073
  return target.asProxy();
@@ -1138,7 +1142,8 @@ var Builder = class Builder extends Inference$1 {
1138
1142
  }
1139
1143
  addUpdatedAtColumn(values) {
1140
1144
  if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
1141
- values = (0, radashi.assign)({ [this.model.getUpdatedAtColumn()]: this.model.freshTimestampString() }, values);
1145
+ const column = this.model.getUpdatedAtColumn();
1146
+ values = _h3ravel_support.Obj.deepMerge({ [column]: this.model.freshTimestampString() }, values);
1142
1147
  return values;
1143
1148
  }
1144
1149
  delete() {
@@ -1166,9 +1171,8 @@ var Builder = class Builder extends Inference$1 {
1166
1171
  return this.model;
1167
1172
  }
1168
1173
  setModel(model) {
1169
- var _this$query;
1170
1174
  this.model = model;
1171
- 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());
1175
+ if (typeof this.query?.client?.table == "function") this.query = this.query.client.table(this.model.getTable());
1172
1176
  else this.query = this.query.table(this.model.getTable());
1173
1177
  return this;
1174
1178
  }
@@ -1211,7 +1215,7 @@ var Builder = class Builder extends Inference$1 {
1211
1215
  }
1212
1216
  withoutGlobalScope(scope) {
1213
1217
  if (typeof scope !== "string") scope = scope.constructor.name;
1214
- this.globalScopes = (0, radashi.omit)(this.globalScopes, [scope]);
1218
+ this.globalScopes = _h3ravel_support.Arr.except(this.globalScopes, [scope]);
1215
1219
  return this;
1216
1220
  }
1217
1221
  macro(name, callback) {
@@ -1228,7 +1232,7 @@ var Builder = class Builder extends Inference$1 {
1228
1232
  let eagerLoads = {};
1229
1233
  if (typeof args[1] === "function") {
1230
1234
  const eagerLoad = this.parseWithRelations({ [args[0]]: args[1] });
1231
- this.eagerLoad = (0, radashi.assign)(this.eagerLoad, eagerLoad);
1235
+ this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, eagerLoad);
1232
1236
  return this;
1233
1237
  }
1234
1238
  const relations = flattenDeep(args);
@@ -1237,13 +1241,13 @@ var Builder = class Builder extends Inference$1 {
1237
1241
  let eagerLoad;
1238
1242
  if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
1239
1243
  else if (typeof relation === "object") eagerLoad = relation;
1240
- eagerLoads = (0, radashi.assign)(eagerLoads, eagerLoad);
1244
+ eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
1241
1245
  }
1242
- this.eagerLoad = (0, radashi.assign)(this.eagerLoad, this.parseWithRelations(eagerLoads));
1246
+ this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, this.parseWithRelations(eagerLoads));
1243
1247
  return this;
1244
1248
  }
1245
1249
  has(relation, operator = ">=", count = 1, boolean = "and", callback = null) {
1246
- if ((0, radashi.isString)(relation)) {
1250
+ if (typeof relation === "string") {
1247
1251
  if (relation.includes(".")) return this.hasNested(relation, operator, count, boolean, callback);
1248
1252
  relation = this.getRelationWithoutConstraints(getRelationMethod(relation));
1249
1253
  }
@@ -1320,7 +1324,7 @@ var Builder = class Builder extends Inference$1 {
1320
1324
  let eagerLoad;
1321
1325
  if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
1322
1326
  else if (typeof relation === "object") eagerLoad = relation;
1323
- eagerLoads = (0, radashi.assign)(eagerLoads, eagerLoad);
1327
+ eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
1324
1328
  }
1325
1329
  relations = eagerLoads;
1326
1330
  const db = this.model.getConnection();
@@ -1339,7 +1343,7 @@ var Builder = class Builder extends Inference$1 {
1339
1343
  } else expression = column;
1340
1344
  const query = relation.getRelationExistenceQuery(relation.getRelated().newModelQuery(), this, db.raw(expression));
1341
1345
  constraints(query);
1342
- alias = alias || (0, radashi.snake)(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
1346
+ alias = alias || _h3ravel_support.Str.snake(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
1343
1347
  if (action === "exists") this.select(db.raw(`exists(${query.toSql().sql}) as ${alias}`));
1344
1348
  else this.selectSub(action ? query : query.limit(1), alias);
1345
1349
  }
@@ -1363,7 +1367,7 @@ var Builder = class Builder extends Inference$1 {
1363
1367
  }
1364
1368
  parseSub(query) {
1365
1369
  if (query instanceof Builder || query instanceof Relation$1) return [query.toSql().sql, query.toSql().bindings];
1366
- else if ((0, radashi.isString)(query)) return [query, []];
1370
+ else if (typeof query === "string") return [query, []];
1367
1371
  else throw new Error("A subquery must be a query builder instance, a Closure, or a string.");
1368
1372
  }
1369
1373
  prependDatabaseNameIfCrossDatabaseQuery(query) {
@@ -1420,15 +1424,15 @@ var Builder = class Builder extends Inference$1 {
1420
1424
  if (prefix !== "") prefix += ".";
1421
1425
  for (const key in relations) {
1422
1426
  const value = relations[key];
1423
- if ((0, radashi.isString)(value) || Number.isFinite(parseInt(value))) continue;
1427
+ if (typeof value === "string" || Number.isFinite(parseInt(value))) continue;
1424
1428
  const [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(key, value);
1425
1429
  preparedRelationships = Object.assign({}, preparedRelationships, { [`${prefix}${attribute}`]: attributeSelectConstraint }, this.prepareNestedWithRelationships(value, `${prefix}${attribute}`));
1426
- relations = (0, radashi.omit)(relations, [key]);
1430
+ relations = _h3ravel_support.Arr.except(relations, [key]);
1427
1431
  }
1428
1432
  for (const key in relations) {
1429
1433
  const value = relations[key];
1430
1434
  let attribute = key, attributeSelectConstraint = value;
1431
- if ((0, radashi.isString)(value)) [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
1435
+ if (typeof value === "string") [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
1432
1436
  preparedRelationships[`${prefix}${attribute}`] = this.combineConstraints([attributeSelectConstraint, preparedRelationships[`${prefix}${attribute}`] || (() => {})]);
1433
1437
  }
1434
1438
  return preparedRelationships;
@@ -1476,8 +1480,8 @@ var Builder = class Builder extends Inference$1 {
1476
1480
  }
1477
1481
  async findOrFail(...args) {
1478
1482
  const data = await this.find(...args);
1479
- if ((0, radashi.isArray)(args[0])) {
1480
- if (data.count() !== args[0].length) throw new ModelNotFoundError().setModel(this.model.constructor.name, (0, radashi.diff)(args[0], data.modelKeys()));
1483
+ if (Array.isArray(args[0])) {
1484
+ 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());
1481
1485
  return data;
1482
1486
  }
1483
1487
  if (data === null) throw new ModelNotFoundError().setModel(this.model.constructor.name, args[0]);
@@ -1491,12 +1495,12 @@ var Builder = class Builder extends Inference$1 {
1491
1495
  async firstOrNew(attributes = {}, values = {}) {
1492
1496
  const instance = await this.where(attributes).first();
1493
1497
  if (instance !== null) return instance;
1494
- return this.newModelInstance((0, radashi.assign)(attributes, values));
1498
+ return this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values));
1495
1499
  }
1496
1500
  async firstOrCreate(attributes = {}, values = {}) {
1497
1501
  const instance = await this.where(attributes).first();
1498
1502
  if (instance !== null) return instance;
1499
- return tap(this.newModelInstance((0, radashi.assign)(attributes, values)), async (instance) => {
1503
+ return tap(this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values)), async (instance) => {
1500
1504
  await instance.save({ client: this.query });
1501
1505
  });
1502
1506
  }
@@ -1516,22 +1520,21 @@ var Builder = class Builder extends Inference$1 {
1516
1520
  return this;
1517
1521
  }
1518
1522
  async find(id, columns) {
1519
- if ((0, radashi.isArray)(id) || id instanceof Collection) return await this.findMany(id, columns);
1523
+ if (Array.isArray(id) || id instanceof Collection) return await this.findMany(id, columns);
1520
1524
  return await this.where(this.model.getKeyName(), id).first(columns);
1521
1525
  }
1522
1526
  async findMany(ids, columns = ["*"]) {
1523
- if (ids instanceof Collection) ids = ids.modelKeys();
1524
- ids = (0, radashi.isArray)(ids) ? ids : [ids];
1525
- if (ids.length === 0) return new Collection([]);
1526
- return await this.whereIn(this.model.getKeyName(), ids).get(columns);
1527
+ const values = ids instanceof Collection ? ids.modelKeys() : Array.isArray(ids) ? ids : [ids];
1528
+ if (values.length === 0) return new Collection([]);
1529
+ return await this.whereIn(this.model.getKeyName(), values).get(columns);
1527
1530
  }
1528
1531
  async pluck(column) {
1529
1532
  return new Collection(await this.query.pluck(column));
1530
1533
  }
1531
1534
  async destroy(ids) {
1532
1535
  if (ids instanceof Collection) ids = ids.modelKeys();
1533
- if (ids instanceof collect_js.Collection) ids = ids.all();
1534
- ids = (0, radashi.isArray)(ids) ? ids : Array.prototype.slice.call(ids);
1536
+ if (ids instanceof _h3ravel_collect_js.Collection) ids = ids.all();
1537
+ ids = Array.isArray(ids) ? ids : Array.prototype.slice.call(ids);
1535
1538
  if (ids.length === 0) return 0;
1536
1539
  const key = this.model.newInstance().getKeyName();
1537
1540
  let count = 0;
@@ -1549,12 +1552,11 @@ var Builder = class Builder extends Inference$1 {
1549
1552
  return await this.model.newModelQuery().get(columns);
1550
1553
  }
1551
1554
  async paginate(page = 1, perPage = 10) {
1552
- var _this;
1553
1555
  page = page || 1;
1554
- perPage = perPage || ((_this = this) === null || _this === void 0 || (_this = _this.model) === null || _this === void 0 ? void 0 : _this.perPage) || 15;
1556
+ perPage = perPage || this?.model?.perPage || 15;
1555
1557
  this.applyScopes();
1556
1558
  const total = await this.query.clone().clearOrder().clearSelect().count(this.primaryKey);
1557
- let results = [];
1559
+ let results;
1558
1560
  if (total > 0) {
1559
1561
  const skip = (page - 1) * (perPage ?? 10);
1560
1562
  this.take(perPage).skip(skip);
@@ -1564,7 +1566,7 @@ var Builder = class Builder extends Inference$1 {
1564
1566
  return new Paginator(results, parseInt(total), perPage, page);
1565
1567
  }
1566
1568
  async getModels(...columns) {
1567
- columns = (0, radashi.flat)(columns);
1569
+ columns = flatten(columns);
1568
1570
  if (columns.length > 0) {
1569
1571
  if (this.query._statements.filter((item) => item.grouping == "columns").length == 0 && columns[0] !== "*") this.query.select(...columns);
1570
1572
  }
@@ -1641,8 +1643,7 @@ const HasAttributes = (Model) => {
1641
1643
  return this;
1642
1644
  }
1643
1645
  normalizeCastClassResponse(key, value) {
1644
- var _value$constructor;
1645
- return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
1646
+ return value?.constructor?.name === "Object" ? value : { [key]: value };
1646
1647
  }
1647
1648
  syncOriginal() {
1648
1649
  this.original = this.getAttributes();
@@ -1752,9 +1753,9 @@ const HasAttributes = (Model) => {
1752
1753
  return null;
1753
1754
  }
1754
1755
  case "collection": try {
1755
- return (0, collect_js.default)(JSON.parse(value));
1756
+ return (0, _h3ravel_collect_js.collect)(JSON.parse(value));
1756
1757
  } catch {
1757
- return (0, collect_js.default)([]);
1758
+ return (0, _h3ravel_collect_js.collect)([]);
1758
1759
  }
1759
1760
  case "date": return this.asDate(value);
1760
1761
  case "datetime":
@@ -1767,8 +1768,8 @@ const HasAttributes = (Model) => {
1767
1768
  attributesToData() {
1768
1769
  let attributes = { ...this.attributes };
1769
1770
  for (const key in attributes) {
1770
- if (this.hidden.includes(key)) attributes = (0, radashi.omit)(attributes, [key]);
1771
- if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = (0, radashi.omit)(attributes, [key]);
1771
+ if (this.hidden.includes(key)) attributes = _h3ravel_support.Arr.except(attributes, [key]);
1772
+ if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = _h3ravel_support.Arr.except(attributes, [key]);
1772
1773
  }
1773
1774
  for (const key of this.getDates()) {
1774
1775
  if (attributes[key] === void 0) continue;
@@ -1780,7 +1781,7 @@ const HasAttributes = (Model) => {
1780
1781
  if (key in attributes === false) continue;
1781
1782
  attributes[key] = this.castAttribute(key, attributes[key]);
1782
1783
  if (key in attributes && ["date", "datetime"].includes(String(value))) attributes[key] = this.serializeDate(attributes[key]);
1783
- if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = (0, dayjs.default)(attributes[key]).format(String(value).split(":")[1]);
1784
+ if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = dayjs$1(attributes[key]).format(String(value).split(":")[1]);
1784
1785
  }
1785
1786
  for (const key of this.appends) attributes[key] = this.mutateAttribute(key, null);
1786
1787
  return attributes;
@@ -1796,7 +1797,7 @@ const HasAttributes = (Model) => {
1796
1797
  return this.getDates().includes(key) || this.isDateCastable(key);
1797
1798
  }
1798
1799
  serializeDate(date) {
1799
- return date ? (0, dayjs.default)(date).toISOString() : null;
1800
+ return date ? dayjs$1(date).toISOString() : null;
1800
1801
  }
1801
1802
  getDates() {
1802
1803
  return this.usesTimestamps() ? [this.getCreatedAtColumn(), this.getUpdatedAtColumn()] : [];
@@ -1823,13 +1824,13 @@ const HasAttributes = (Model) => {
1823
1824
  }
1824
1825
  hasCast(key, types = []) {
1825
1826
  if (key in this.casts) {
1826
- types = (0, radashi.flat)(types);
1827
+ types = flatten(types);
1827
1828
  return types.length > 0 ? types.includes(this.getCastType(key)) : true;
1828
1829
  }
1829
1830
  return false;
1830
1831
  }
1831
1832
  withDayjs(date) {
1832
- return (0, dayjs.default)(date);
1833
+ return dayjs$1(date);
1833
1834
  }
1834
1835
  isCustomCast(cast) {
1835
1836
  return typeof cast === "function" && new cast() instanceof CastsAttributes;
@@ -1846,7 +1847,7 @@ const HasAttributes = (Model) => {
1846
1847
  return this.hasCast(key, ["date", "datetime"]);
1847
1848
  }
1848
1849
  fromDateTime(value) {
1849
- return (0, dayjs.default)(this.asDateTime(value)).format(this.getDateFormat());
1850
+ return dayjs$1(this.asDateTime(value)).format(this.getDateFormat());
1850
1851
  }
1851
1852
  getDateFormat() {
1852
1853
  return this.dateFormat || "YYYY-MM-DD HH:mm:ss";
@@ -1861,7 +1862,7 @@ const HasAttributes = (Model) => {
1861
1862
  return new Date(value);
1862
1863
  }
1863
1864
  asDate(value) {
1864
- return (0, dayjs.default)(this.asDateTime(value)).startOf("day").toDate();
1865
+ return dayjs$1(this.asDateTime(value)).startOf("day").toDate();
1865
1866
  }
1866
1867
  };
1867
1868
  };
@@ -1872,10 +1873,14 @@ const HasGlobalScopes = (Model) => {
1872
1873
  static globalScopes;
1873
1874
  static addGlobalScope(scope, implementation = null) {
1874
1875
  if (typeof scope === "string" && implementation instanceof Scope) {
1875
- this.globalScopes = (0, radashi.set)(this.globalScopes ?? {}, this.name + "." + scope, implementation);
1876
+ const scopes = this.globalScopes ?? {};
1877
+ (0, _h3ravel_support.data_set)(scopes, this.name + "." + scope, implementation);
1878
+ this.globalScopes = scopes;
1876
1879
  return implementation;
1877
1880
  } else if (scope instanceof Scope) {
1878
- this.globalScopes = (0, radashi.set)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name, scope);
1881
+ const scopes = this.globalScopes ?? {};
1882
+ (0, _h3ravel_support.data_set)(scopes, this.name + "." + scope.constructor.name, scope);
1883
+ this.globalScopes = scopes;
1879
1884
  return scope;
1880
1885
  }
1881
1886
  throw new InvalidArgumentError("Global scope must be an instance of Scope.");
@@ -1884,8 +1889,8 @@ const HasGlobalScopes = (Model) => {
1884
1889
  return this.getGlobalScope(scope) !== null;
1885
1890
  }
1886
1891
  static getGlobalScope(scope) {
1887
- if (typeof scope === "string") return (0, radashi.get)(this.globalScopes, this.name + "." + scope);
1888
- return (0, radashi.get)(this.globalScopes, this.name + "." + scope.constructor.name);
1892
+ if (typeof scope === "string") return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope);
1893
+ return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name);
1889
1894
  }
1890
1895
  static getAllGlobalScopes() {
1891
1896
  return this.globalScopes;
@@ -1894,7 +1899,7 @@ const HasGlobalScopes = (Model) => {
1894
1899
  this.globalScopes = scopes;
1895
1900
  }
1896
1901
  getGlobalScopes() {
1897
- return (0, radashi.get)(this.constructor.globalScopes, this.constructor.name, {});
1902
+ return (0, _h3ravel_support.data_get)(this.constructor.globalScopes ?? {}, this.constructor.name, {});
1898
1903
  }
1899
1904
  };
1900
1905
  };
@@ -1994,7 +1999,7 @@ const HasOneOrMany$1 = (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$1 = class extends compose(Relation$1, HasOneOrMany$1) {
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$1 = class extends compose(Relation$1, HasOneOrMany$1, SupportsDefault
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);
@@ -2231,10 +2232,10 @@ var HasManyThrough$1 = class extends Relation$1 {
2231
2232
  }
2232
2233
  const model = await this.first(columns);
2233
2234
  if (model) return model;
2234
- return callback === null || callback === void 0 ? void 0 : callback();
2235
+ return callback?.();
2235
2236
  }
2236
2237
  async find(id, columns = ["*"]) {
2237
- if ((0, radashi.isArray)(id)) return await this.findMany(id, columns);
2238
+ if (Array.isArray(id)) return await this.findMany(id, columns);
2238
2239
  return await this.where(this.getRelated().getQualifiedKeyName(), "=", id).first(columns);
2239
2240
  }
2240
2241
  async findMany(ids, columns = ["*"]) {
@@ -2262,7 +2263,7 @@ var HasManyThrough$1 = class extends Relation$1 {
2262
2263
  return await this.query.paginate(perPage ?? 15, columns, pageName, page);
2263
2264
  }
2264
2265
  shouldSelect(columns = ["*"]) {
2265
- if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
2266
+ if (columns?.at(0) == "*") columns = [this.related.getTable() + ".*"];
2266
2267
  return [...columns, this.getQualifiedFirstKeyName() + " as laravel_through_key"];
2267
2268
  }
2268
2269
  async chunk(count, callback) {
@@ -2356,7 +2357,7 @@ const HasRelations = (Model) => {
2356
2357
  return this;
2357
2358
  }
2358
2359
  unsetRelation(relation) {
2359
- this.relations = (0, radashi.omit)(this.relations, [relation]);
2360
+ this.relations = _h3ravel_support.Arr.except(this.relations, [relation]);
2360
2361
  return this;
2361
2362
  }
2362
2363
  relationLoaded(relation) {
@@ -2379,8 +2380,7 @@ const HasRelations = (Model) => {
2379
2380
  return data;
2380
2381
  }
2381
2382
  guessBelongsToRelation() {
2382
- var _e$stack;
2383
- const functionName = (((_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2]) ?? "").split(" ")[5];
2383
+ const functionName = ((/* @__PURE__ */ new Error()).stack?.split("\n")[2] ?? "").split(" ")[5];
2384
2384
  return getRelationName(functionName);
2385
2385
  }
2386
2386
  joiningTable(related, instance = null) {
@@ -2490,7 +2490,7 @@ const HidesAttributes = (Model) => {
2490
2490
  makeVisible(...keys) {
2491
2491
  const visible = flattenDeep(keys);
2492
2492
  if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
2493
- this.hidden = (0, radashi.diff)(this.hidden, visible);
2493
+ this.hidden = (0, _h3ravel_collect_js.collect)(this.hidden).diff(visible).all();
2494
2494
  return this;
2495
2495
  }
2496
2496
  makeHidden(key, ...keys) {
@@ -2578,10 +2578,9 @@ var QueryBuilder = class QueryBuilder extends Inference {
2578
2578
  asProxy() {
2579
2579
  return new Proxy(this, {
2580
2580
  get: function(target, prop) {
2581
- var _target$connector$cli;
2582
2581
  if (typeof target[prop] !== "undefined") return target[prop];
2583
2582
  if (["destroy", "schema"].includes(prop)) return target.connector.schema;
2584
- 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";
2583
+ const skipReturning = !!target.connector.client.config?.client?.includes("mysql") && prop === "returning";
2585
2584
  if ([
2586
2585
  "select",
2587
2586
  "from",
@@ -2784,6 +2783,9 @@ var arquebus = class arquebus {
2784
2783
  if (this.instance === null) this.instance = new arquebus();
2785
2784
  return this.instance;
2786
2785
  }
2786
+ static withSchema() {
2787
+ return this;
2788
+ }
2787
2789
  /**
2788
2790
  * Initialize a new database connection
2789
2791
  *
@@ -2873,12 +2875,12 @@ var arquebus = class arquebus {
2873
2875
  const tsPath = path.default.resolve("arquebus.config.ts");
2874
2876
  const instance = this.getInstance();
2875
2877
  if ((0, fs.existsSync)(jsPath)) {
2876
- config = (await import(jsPath)).default;
2878
+ config = (await (0, _h3ravel_shared.importFile)(jsPath)).default;
2877
2879
  if (addConnection) instance.addConnection(config, config.client);
2878
2880
  return config;
2879
2881
  }
2880
2882
  if ((0, fs.existsSync)(tsPath)) if (process.env.NODE_ENV !== "production") {
2881
- config = (await import(tsPath)).default;
2883
+ config = (await (0, _h3ravel_shared.importFile)(tsPath)).default;
2882
2884
  if (addConnection) instance.addConnection(config, config.client);
2883
2885
  return config;
2884
2886
  } else throw new Error("arquebus.config.ts found in production without build step");
@@ -2894,7 +2896,7 @@ var arquebus = class arquebus {
2894
2896
  "cjs"
2895
2897
  ], dir);
2896
2898
  if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
2897
- config = (await import(found)).default;
2899
+ config = (await (0, _h3ravel_shared.importFile)(found)).default;
2898
2900
  if (addConnection) instance.addConnection(config, config.client);
2899
2901
  return config;
2900
2902
  } else throw new Error("arquebus.config.ts found in production without build step");
@@ -2915,7 +2917,7 @@ var arquebus = class arquebus {
2915
2917
  }
2916
2918
  async destroyAll() {
2917
2919
  await Promise.all(Object.values(this.manager).map((connection) => {
2918
- return connection === null || connection === void 0 ? void 0 : connection.destroy();
2920
+ return connection?.destroy();
2919
2921
  }));
2920
2922
  }
2921
2923
  createModel(name, options = {}) {
@@ -2924,29 +2926,25 @@ var arquebus = class arquebus {
2924
2926
  this.models = {
2925
2927
  ...this.models,
2926
2928
  [name]: class extends BaseModel {
2927
- table = (options === null || options === void 0 ? void 0 : options.table) ?? null;
2928
- connection = (options === null || options === void 0 ? void 0 : options.connection) ?? null;
2929
- timestamps = (options === null || options === void 0 ? void 0 : options.timestamps) ?? true;
2930
- primaryKey = (options === null || options === void 0 ? void 0 : options.primaryKey) ?? "id";
2931
- keyType = (options === null || options === void 0 ? void 0 : options.keyType) ?? "int";
2932
- incrementing = (options === null || options === void 0 ? void 0 : options.incrementing) ?? true;
2933
- with = (options === null || options === void 0 ? void 0 : options.with) ?? [];
2934
- casts = (options === null || options === void 0 ? void 0 : options.casts) ?? {};
2935
- static CREATED_AT = (options === null || options === void 0 ? void 0 : options.CREATED_AT) ?? "created_at";
2936
- static UPDATED_AT = (options === null || options === void 0 ? void 0 : options.UPDATED_AT) ?? "updated_at";
2937
- static DELETED_AT = (options === null || options === void 0 ? void 0 : options.DELETED_AT) ?? "deleted_at";
2929
+ table = options?.table ?? null;
2930
+ connection = options?.connection ?? null;
2931
+ timestamps = options?.timestamps ?? true;
2932
+ primaryKey = options?.primaryKey ?? "id";
2933
+ keyType = options?.keyType ?? "int";
2934
+ incrementing = options?.incrementing ?? true;
2935
+ with = options?.with ?? [];
2936
+ casts = options?.casts ?? {};
2937
+ static CREATED_AT = options?.CREATED_AT ?? "created_at";
2938
+ static UPDATED_AT = options?.UPDATED_AT ?? "updated_at";
2939
+ static DELETED_AT = options?.DELETED_AT ?? "deleted_at";
2938
2940
  }
2939
2941
  };
2940
2942
  if ("attributes" in options) for (const attribute in options.attributes) {
2941
2943
  if (options.attributes[attribute] instanceof Attribute === false) throw new Error("Attribute must be an instance of \"Attribute\"");
2942
- this.models[name].prototype[getAttrMethod(attribute)] = () => {
2943
- var _options$attributes;
2944
- return (_options$attributes = options.attributes) === null || _options$attributes === void 0 ? void 0 : _options$attributes[attribute];
2945
- };
2944
+ this.models[name].prototype[getAttrMethod(attribute)] = () => options.attributes?.[attribute];
2946
2945
  }
2947
2946
  if ("relations" in options) for (const relation in options.relations) this.models[name].prototype[getRelationMethod(relation)] = function() {
2948
- var _options$relations;
2949
- return (_options$relations = options.relations) === null || _options$relations === void 0 ? void 0 : _options$relations[relation](this);
2947
+ return options.relations?.[relation](this);
2950
2948
  };
2951
2949
  if ("scopes" in options) for (const scope in options.scopes) this.models[name].prototype[getScopeMethod(scope)] = options.scopes[scope];
2952
2950
  this.models[name].setConnectionResolver(this);
@@ -2984,6 +2982,9 @@ var Model = class Model extends BaseModel {
2984
2982
  this.buildRelationships(attributes);
2985
2983
  return this.asProxy();
2986
2984
  }
2985
+ static define() {
2986
+ return this;
2987
+ }
2987
2988
  static query(trx = null) {
2988
2989
  return new this().newQuery(trx);
2989
2990
  }
@@ -3167,7 +3168,7 @@ var Model = class Model extends BaseModel {
3167
3168
  });
3168
3169
  }
3169
3170
  toData() {
3170
- return (0, radashi.assign)(this.attributesToData(), this.relationsToData());
3171
+ return _h3ravel_support.Obj.deepMerge(this.attributesToData(), this.relationsToData());
3171
3172
  }
3172
3173
  toJSON() {
3173
3174
  return this.toData();
@@ -3178,6 +3179,15 @@ var Model = class Model extends BaseModel {
3178
3179
  toString() {
3179
3180
  return this.toJson();
3180
3181
  }
3182
+ getAttributes() {
3183
+ return super.getAttributes();
3184
+ }
3185
+ getAttribute(key) {
3186
+ return super.getAttribute(key);
3187
+ }
3188
+ setAttribute(key, value) {
3189
+ return super.setAttribute(key, value);
3190
+ }
3181
3191
  fill(attributes) {
3182
3192
  for (const key in attributes) this.setAttribute(key, attributes[key]);
3183
3193
  return this;
@@ -3218,10 +3228,9 @@ var Model = class Model extends BaseModel {
3218
3228
  if (this.usesTimestamps()) this.updateTimestamps();
3219
3229
  const attributes = this.getAttributes();
3220
3230
  if (this.getIncrementing()) {
3221
- var _data$;
3222
3231
  const keyName = this.getKeyName();
3223
3232
  const data = await query.insert([attributes], [keyName]);
3224
- this.setAttribute(keyName, ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$[keyName]) || data[0]);
3233
+ this.setAttribute(keyName, data[0]?.[keyName] || data[0]);
3225
3234
  } else if (Object.keys(attributes).length > 0) await query.insert(attributes);
3226
3235
  this.exists = true;
3227
3236
  await this.execHooks("created", options);
@@ -3263,7 +3272,7 @@ var Model = class Model extends BaseModel {
3263
3272
  if (!this.exists) return Promise.resolve(void 0);
3264
3273
  const model = await this.constructor.query().where(this.getKeyName(), this.getKey()).first();
3265
3274
  this.attributes = { ...model.attributes };
3266
- await this.load((0, collect_js.default)(this.relations).reject((relation) => {
3275
+ await this.load((0, _h3ravel_collect_js.collect)(this.relations).reject((relation) => {
3267
3276
  return relation instanceof Pivot;
3268
3277
  }).keys().all());
3269
3278
  this.syncOriginal();