@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
@@ -32,13 +32,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
  //#endregion
33
33
  let path = require("path");
34
34
  path = __toESM(path, 1);
35
- let radashi = require("radashi");
36
- let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
37
- dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
35
+ let _h3ravel_support = require("@h3ravel/support");
38
36
  let dayjs = require("dayjs");
39
37
  dayjs = __toESM(dayjs, 1);
40
- let collect_js = require("collect.js");
41
- collect_js = __toESM(collect_js, 1);
38
+ let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
39
+ dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js, 1);
40
+ let _h3ravel_collect_js = require("@h3ravel/collect.js");
42
41
  let knex = require("knex");
43
42
  knex = __toESM(knex, 1);
44
43
  let fs = require("fs");
@@ -123,8 +122,7 @@ var CockroachDB = class {
123
122
  */
124
123
  async hasTable(table) {
125
124
  const subquery = this.knex.select().from("information_schema.tables").whereIn("table_schema", this.explodedSchema).andWhere({ table_name: table });
126
- const record = await this.knex.select(this.knex.raw("exists (?)", [subquery])).first();
127
- return (record === null || record === void 0 ? void 0 : record.exists) || false;
125
+ return (await this.knex.select(this.knex.raw("exists (?)", [subquery])).first())?.exists || false;
128
126
  }
129
127
  /**
130
128
  * Get all the available columns in the current schema/database. Can be filtered to a specific table
@@ -224,18 +222,17 @@ var CockroachDB = class {
224
222
  ${column ? "AND att.attname = ?" : ""}
225
223
  `, bindings)]);
226
224
  const parsedColumms = columns.rows.map((col) => {
227
- var _col$default_value;
228
225
  const constraintsForColumn = constraints.rows.filter((constraint) => constraint.table === col.table && constraint.column === col.name);
229
226
  const foreignKeyConstraint = constraintsForColumn.find((constraint) => constraint.type === "f");
230
227
  return {
231
228
  ...col,
232
229
  is_unique: constraintsForColumn.some((constraint) => ["u", "p"].includes(constraint.type)),
233
230
  is_primary_key: constraintsForColumn.some((constraint) => constraint.type === "p"),
234
- has_auto_increment: ["integer", "bigint"].includes(col.data_type) && (((_col$default_value = col.default_value) === null || _col$default_value === void 0 ? void 0 : _col$default_value.startsWith("nextval(")) ?? false),
231
+ has_auto_increment: ["integer", "bigint"].includes(col.data_type) && (col.default_value?.startsWith("nextval(") ?? false),
235
232
  default_value: parseDefaultValue$5(col.default_value),
236
- foreign_key_schema: (foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_schema) ?? null,
237
- foreign_key_table: (foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_table) ?? null,
238
- foreign_key_column: (foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_column) ?? null
233
+ foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null,
234
+ foreign_key_table: foreignKeyConstraint?.foreign_key_table ?? null,
235
+ foreign_key_column: foreignKeyConstraint?.foreign_key_column ?? null
239
236
  };
240
237
  });
241
238
  if (table && column) return parsedColumms[0];
@@ -249,8 +246,7 @@ var CockroachDB = class {
249
246
  table_name: table,
250
247
  column_name: column
251
248
  });
252
- const record = await this.knex.select(this.knex.raw("exists (?)", [subquery])).first();
253
- return (record === null || record === void 0 ? void 0 : record.exists) || false;
249
+ return (await this.knex.select(this.knex.raw("exists (?)", [subquery])).first())?.exists || false;
254
250
  }
255
251
  /**
256
252
  * Get the primary key column for the given table
@@ -562,14 +558,13 @@ var MSSQL = class {
562
558
  WHERE
563
559
  OBJECT_SCHEMA_NAME (f.parent_object_id) = ?;
564
560
  `, [this.schema]);
565
- if (table) return result === null || result === void 0 ? void 0 : result.filter((row) => row.table === table);
561
+ if (table) return result?.filter((row) => row.table === table);
566
562
  return result;
567
563
  }
568
564
  };
569
565
  //#endregion
570
566
  //#region src/inspector/dialects/mysql.ts
571
567
  function rawColumnToColumn$1(rawColumn) {
572
- var _rawColumn$EXTRA;
573
568
  let dataType = rawColumn.COLUMN_TYPE.replace(/\(.*?\)/, "");
574
569
  if (rawColumn.COLUMN_TYPE.startsWith("tinyint(1)")) dataType = "boolean";
575
570
  return {
@@ -582,7 +577,7 @@ function rawColumnToColumn$1(rawColumn) {
582
577
  max_length: rawColumn.CHARACTER_MAXIMUM_LENGTH,
583
578
  numeric_precision: rawColumn.NUMERIC_PRECISION,
584
579
  numeric_scale: rawColumn.NUMERIC_SCALE,
585
- is_generated: !!((_rawColumn$EXTRA = rawColumn.EXTRA) === null || _rawColumn$EXTRA === void 0 ? void 0 : _rawColumn$EXTRA.endsWith("GENERATED")),
580
+ is_generated: !!rawColumn.EXTRA?.endsWith("GENERATED"),
586
581
  is_nullable: rawColumn.IS_NULLABLE === "YES",
587
582
  is_unique: rawColumn.COLUMN_KEY === "UNI",
588
583
  is_primary_key: rawColumn.CONSTRAINT_NAME === "PRIMARY" || rawColumn.COLUMN_KEY === "PRI",
@@ -775,11 +770,10 @@ var oracleDB = class {
775
770
  * Check if a table exists in the current schema/database
776
771
  */
777
772
  async hasTable(table) {
778
- const result = await this.knex.select(this.knex.raw(`
773
+ return !!(await this.knex.select(this.knex.raw(`
779
774
  /*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') */
780
775
  COUNT(*) "count"
781
- `)).from("USER_TABLES").where({ TABLE_NAME: table }).first();
782
- return !!(result === null || result === void 0 ? void 0 : result.count);
776
+ `)).from("USER_TABLES").where({ TABLE_NAME: table }).first())?.count;
783
777
  }
784
778
  /**
785
779
  * Get all the available columns in the current schema/database. Can be filtered to a specific table
@@ -855,15 +849,14 @@ var oracleDB = class {
855
849
  * Check if a table exists in the current schema/database
856
850
  */
857
851
  async hasColumn(table, column) {
858
- const result = await this.knex.select(this.knex.raw(`
852
+ return !!(await this.knex.select(this.knex.raw(`
859
853
  /*+ OPTIMIZER_FEATURES_ENABLE('${OPTIMIZER_FEATURES}') NO_QUERY_TRANSFORMATION */
860
854
  COUNT(*) "count"
861
855
  `)).from("USER_TAB_COLS").where({
862
856
  TABLE_NAME: table,
863
857
  COLUMN_NAME: column,
864
858
  HIDDEN_COLUMN: "NO"
865
- }).first();
866
- return !!(result === null || result === void 0 ? void 0 : result.count);
859
+ }).first())?.count;
867
860
  }
868
861
  /**
869
862
  * Get the primary key column for the given table
@@ -1029,13 +1022,12 @@ var Postgres = class {
1029
1022
  `, bindings)).rows;
1030
1023
  }
1031
1024
  async columnInfo(table, column) {
1032
- var _versionResponse$rows;
1033
1025
  const { knex } = this;
1034
1026
  const bindings = [];
1035
1027
  if (table) bindings.push(table);
1036
1028
  if (column) bindings.push(column);
1037
1029
  const schemaIn = this.explodedSchema.map((schemaName) => `${this.knex.raw("?", [schemaName])}::regnamespace`);
1038
- const majorVersion = ((_versionResponse$rows = (await this.knex.raw("SHOW server_version")).rows) === null || _versionResponse$rows === void 0 || (_versionResponse$rows = _versionResponse$rows[0]) === null || _versionResponse$rows === void 0 || (_versionResponse$rows = _versionResponse$rows.server_version) === null || _versionResponse$rows === void 0 || (_versionResponse$rows = _versionResponse$rows.split(".")) === null || _versionResponse$rows === void 0 ? void 0 : _versionResponse$rows[0]) ?? 10;
1030
+ const majorVersion = (await this.knex.raw("SHOW server_version")).rows?.[0]?.server_version?.split(".")?.[0] ?? 10;
1039
1031
  let generationSelect = `
1040
1032
  NULL AS generation_expression,
1041
1033
  pg_get_expr(ad.adbin, ad.adrelid) AS default_value,
@@ -1127,9 +1119,9 @@ var Postgres = class {
1127
1119
  is_primary_key: constraintsForColumn.some((constraint) => constraint.type === "p"),
1128
1120
  has_auto_increment: constraintsForColumn.some((constraint) => constraint.has_auto_increment),
1129
1121
  default_value: parseDefaultValue$1(col.default_value),
1130
- foreign_key_schema: (foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_schema) ?? null,
1131
- foreign_key_table: (foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_table) ?? null,
1132
- foreign_key_column: (foreignKeyConstraint === null || foreignKeyConstraint === void 0 ? void 0 : foreignKeyConstraint.foreign_key_column) ?? null
1122
+ foreign_key_schema: foreignKeyConstraint?.foreign_key_schema ?? null,
1123
+ foreign_key_table: foreignKeyConstraint?.foreign_key_table ?? null,
1124
+ foreign_key_column: foreignKeyConstraint?.foreign_key_column ?? null
1133
1125
  };
1134
1126
  });
1135
1127
  if (table && column) return parsedColumms[0];
@@ -1326,7 +1318,7 @@ var ModelNotFoundError = class extends BaseError {
1326
1318
  }
1327
1319
  setModel(model, ids = []) {
1328
1320
  this.model = model;
1329
- this.ids = (0, radashi.isArray)(ids) ? ids : [ids];
1321
+ this.ids = Array.isArray(ids) ? ids : [ids];
1330
1322
  this.message = `No query results for model [${model}]`;
1331
1323
  if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
1332
1324
  else this.message += ".";
@@ -1417,25 +1409,29 @@ function compose$1(Base, ...mixins) {
1417
1409
  }, Base);
1418
1410
  }
1419
1411
  //#endregion
1412
+ //#region src/dayjs.ts
1413
+ const dayjs$1 = dayjs.default ?? dayjs;
1414
+ const advancedFormat = dayjs_plugin_advancedFormat_js.default ?? dayjs_plugin_advancedFormat_js;
1415
+ dayjs$1.extend(advancedFormat);
1416
+ //#endregion
1420
1417
  //#region src/utils.ts
1421
- dayjs.default.extend(dayjs_plugin_advancedFormat_js.default);
1422
1418
  const getRelationName = (relationMethod) => {
1423
- return (0, radashi.snake)(relationMethod.substring(8));
1419
+ return _h3ravel_support.Str.snake(relationMethod.substring(8));
1424
1420
  };
1425
1421
  const getRelationMethod = (relation) => {
1426
- return (0, radashi.camel)(`relation_${relation}`);
1422
+ return _h3ravel_support.Str.camel(`relation_${relation}`);
1427
1423
  };
1428
1424
  const getScopeMethod = (scope) => {
1429
- return (0, radashi.camel)(`scope_${scope}`);
1425
+ return _h3ravel_support.Str.camel(`scope_${scope}`);
1430
1426
  };
1431
1427
  const getAttrMethod = (attr) => {
1432
- return (0, radashi.camel)(`attribute_${attr}`);
1428
+ return _h3ravel_support.Str.camel(`attribute_${attr}`);
1433
1429
  };
1434
1430
  const getGetterMethod = (attr) => {
1435
- return (0, radashi.camel)(`get_${attr}_attribute`);
1431
+ return _h3ravel_support.Str.camel(`get_${attr}_attribute`);
1436
1432
  };
1437
1433
  const getSetterMethod = (attr) => {
1438
- return (0, radashi.camel)(`set_${attr}_attribute`);
1434
+ return _h3ravel_support.Str.camel(`set_${attr}_attribute`);
1439
1435
  };
1440
1436
  /**
1441
1437
  * Tap into a model a collection instance
@@ -1449,9 +1445,9 @@ const tap = (instance, callback) => {
1449
1445
  return result instanceof Promise ? result.then(() => instance) : instance;
1450
1446
  };
1451
1447
  const { compose } = mixin_exports;
1452
- const flatten$2 = (arr) => arr.flat();
1448
+ const flatten = (arr) => arr.flat();
1453
1449
  const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
1454
- const snakeCase = (str) => (0, radashi.trim)((0, radashi.snake)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
1450
+ const snakeCase = (str) => _h3ravel_support.Str.trim(_h3ravel_support.Str.snake(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-").replace(/_+/g, "_");
1455
1451
  //#endregion
1456
1452
  //#region src/relations/relation.ts
1457
1453
  var Relation = class {
@@ -1538,8 +1534,7 @@ var Relation = class {
1538
1534
  return this.parent.getQualifiedKeyName();
1539
1535
  }
1540
1536
  getExistenceCompareKey() {
1541
- var _this$getQualifiedFor;
1542
- return (_this$getQualifiedFor = this.getQualifiedForeignKeyName) === null || _this$getQualifiedFor === void 0 ? void 0 : _this$getQualifiedFor.call(this);
1537
+ return this.getQualifiedForeignKeyName?.();
1543
1538
  }
1544
1539
  };
1545
1540
  //#endregion
@@ -1680,8 +1675,7 @@ const HasAttributes = (Model) => {
1680
1675
  return this;
1681
1676
  }
1682
1677
  normalizeCastClassResponse(key, value) {
1683
- var _value$constructor;
1684
- return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
1678
+ return value?.constructor?.name === "Object" ? value : { [key]: value };
1685
1679
  }
1686
1680
  syncOriginal() {
1687
1681
  this.original = this.getAttributes();
@@ -1791,9 +1785,9 @@ const HasAttributes = (Model) => {
1791
1785
  return null;
1792
1786
  }
1793
1787
  case "collection": try {
1794
- return (0, collect_js.default)(JSON.parse(value));
1788
+ return (0, _h3ravel_collect_js.collect)(JSON.parse(value));
1795
1789
  } catch {
1796
- return (0, collect_js.default)([]);
1790
+ return (0, _h3ravel_collect_js.collect)([]);
1797
1791
  }
1798
1792
  case "date": return this.asDate(value);
1799
1793
  case "datetime":
@@ -1806,8 +1800,8 @@ const HasAttributes = (Model) => {
1806
1800
  attributesToData() {
1807
1801
  let attributes = { ...this.attributes };
1808
1802
  for (const key in attributes) {
1809
- if (this.hidden.includes(key)) attributes = (0, radashi.omit)(attributes, [key]);
1810
- if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = (0, radashi.omit)(attributes, [key]);
1803
+ if (this.hidden.includes(key)) attributes = _h3ravel_support.Arr.except(attributes, [key]);
1804
+ if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = _h3ravel_support.Arr.except(attributes, [key]);
1811
1805
  }
1812
1806
  for (const key of this.getDates()) {
1813
1807
  if (attributes[key] === void 0) continue;
@@ -1819,7 +1813,7 @@ const HasAttributes = (Model) => {
1819
1813
  if (key in attributes === false) continue;
1820
1814
  attributes[key] = this.castAttribute(key, attributes[key]);
1821
1815
  if (key in attributes && ["date", "datetime"].includes(String(value))) attributes[key] = this.serializeDate(attributes[key]);
1822
- if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = (0, dayjs.default)(attributes[key]).format(String(value).split(":")[1]);
1816
+ if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = dayjs$1(attributes[key]).format(String(value).split(":")[1]);
1823
1817
  }
1824
1818
  for (const key of this.appends) attributes[key] = this.mutateAttribute(key, null);
1825
1819
  return attributes;
@@ -1835,7 +1829,7 @@ const HasAttributes = (Model) => {
1835
1829
  return this.getDates().includes(key) || this.isDateCastable(key);
1836
1830
  }
1837
1831
  serializeDate(date) {
1838
- return date ? (0, dayjs.default)(date).toISOString() : null;
1832
+ return date ? dayjs$1(date).toISOString() : null;
1839
1833
  }
1840
1834
  getDates() {
1841
1835
  return this.usesTimestamps() ? [this.getCreatedAtColumn(), this.getUpdatedAtColumn()] : [];
@@ -1862,13 +1856,13 @@ const HasAttributes = (Model) => {
1862
1856
  }
1863
1857
  hasCast(key, types = []) {
1864
1858
  if (key in this.casts) {
1865
- types = (0, radashi.flat)(types);
1859
+ types = flatten(types);
1866
1860
  return types.length > 0 ? types.includes(this.getCastType(key)) : true;
1867
1861
  }
1868
1862
  return false;
1869
1863
  }
1870
1864
  withDayjs(date) {
1871
- return (0, dayjs.default)(date);
1865
+ return dayjs$1(date);
1872
1866
  }
1873
1867
  isCustomCast(cast) {
1874
1868
  return typeof cast === "function" && new cast() instanceof CastsAttributes;
@@ -1885,7 +1879,7 @@ const HasAttributes = (Model) => {
1885
1879
  return this.hasCast(key, ["date", "datetime"]);
1886
1880
  }
1887
1881
  fromDateTime(value) {
1888
- return (0, dayjs.default)(this.asDateTime(value)).format(this.getDateFormat());
1882
+ return dayjs$1(this.asDateTime(value)).format(this.getDateFormat());
1889
1883
  }
1890
1884
  getDateFormat() {
1891
1885
  return this.dateFormat || "YYYY-MM-DD HH:mm:ss";
@@ -1900,7 +1894,7 @@ const HasAttributes = (Model) => {
1900
1894
  return new Date(value);
1901
1895
  }
1902
1896
  asDate(value) {
1903
- return (0, dayjs.default)(this.asDateTime(value)).startOf("day").toDate();
1897
+ return dayjs$1(this.asDateTime(value)).startOf("day").toDate();
1904
1898
  }
1905
1899
  };
1906
1900
  };
@@ -1921,10 +1915,14 @@ const HasGlobalScopes = (Model) => {
1921
1915
  static globalScopes;
1922
1916
  static addGlobalScope(scope, implementation = null) {
1923
1917
  if (typeof scope === "string" && implementation instanceof Scope) {
1924
- this.globalScopes = (0, radashi.set)(this.globalScopes ?? {}, this.name + "." + scope, implementation);
1918
+ const scopes = this.globalScopes ?? {};
1919
+ (0, _h3ravel_support.data_set)(scopes, this.name + "." + scope, implementation);
1920
+ this.globalScopes = scopes;
1925
1921
  return implementation;
1926
1922
  } else if (scope instanceof Scope) {
1927
- this.globalScopes = (0, radashi.set)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name, scope);
1923
+ const scopes = this.globalScopes ?? {};
1924
+ (0, _h3ravel_support.data_set)(scopes, this.name + "." + scope.constructor.name, scope);
1925
+ this.globalScopes = scopes;
1928
1926
  return scope;
1929
1927
  }
1930
1928
  throw new InvalidArgumentError("Global scope must be an instance of Scope.");
@@ -1933,8 +1931,8 @@ const HasGlobalScopes = (Model) => {
1933
1931
  return this.getGlobalScope(scope) !== null;
1934
1932
  }
1935
1933
  static getGlobalScope(scope) {
1936
- if (typeof scope === "string") return (0, radashi.get)(this.globalScopes, this.name + "." + scope);
1937
- return (0, radashi.get)(this.globalScopes, this.name + "." + scope.constructor.name);
1934
+ if (typeof scope === "string") return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope);
1935
+ return (0, _h3ravel_support.data_get)(this.globalScopes ?? {}, this.name + "." + scope.constructor.name);
1938
1936
  }
1939
1937
  static getAllGlobalScopes() {
1940
1938
  return this.globalScopes;
@@ -1943,7 +1941,7 @@ const HasGlobalScopes = (Model) => {
1943
1941
  this.globalScopes = scopes;
1944
1942
  }
1945
1943
  getGlobalScopes() {
1946
- return (0, radashi.get)(this.constructor.globalScopes, this.constructor.name, {});
1944
+ return (0, _h3ravel_support.data_get)(this.constructor.globalScopes ?? {}, this.constructor.name, {});
1947
1945
  }
1948
1946
  };
1949
1947
  };
@@ -2043,7 +2041,7 @@ const HasOneOrMany = (Relation) => {
2043
2041
  }
2044
2042
  buildDictionary(results) {
2045
2043
  const foreign = this.getForeignKeyName();
2046
- return (0, collect_js.default)(results).mapToDictionary((result) => [result[foreign], result]).all();
2044
+ return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
2047
2045
  }
2048
2046
  async save(model) {
2049
2047
  this.setForeignAttributesForCreate(model);
@@ -2114,13 +2112,11 @@ var HasMany = class extends compose(Relation, HasOneOrMany) {
2114
2112
  return this.getParentKey() !== null ? await this.query.get() : new Collection([]);
2115
2113
  }
2116
2114
  getForeignKeyName() {
2117
- var _this$foreignKey;
2118
- const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
2119
- return segments === null || segments === void 0 ? void 0 : segments.pop();
2115
+ return (this.foreignKey?.split("."))?.pop();
2120
2116
  }
2121
2117
  buildDictionary(results) {
2122
2118
  const foreign = this.getForeignKeyName();
2123
- return (0, collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
2119
+ return (0, _h3ravel_collect_js.collect)(results).mapToDictionary((result) => [result[foreign], result]).all();
2124
2120
  }
2125
2121
  match(models, results, relation) {
2126
2122
  return this.matchOneOrMany(models, results, relation, "many");
@@ -2151,9 +2147,7 @@ var HasOne = class extends compose(Relation, HasOneOrMany, SupportsDefaultModels
2151
2147
  return this.matchOneOrMany(models, results, relation, "one");
2152
2148
  }
2153
2149
  getForeignKeyName() {
2154
- var _this$foreignKey;
2155
- const segments = (_this$foreignKey = this.foreignKey) === null || _this$foreignKey === void 0 ? void 0 : _this$foreignKey.split(".");
2156
- return segments === null || segments === void 0 ? void 0 : segments.pop();
2150
+ return (this.foreignKey?.split("."))?.pop();
2157
2151
  }
2158
2152
  async getResults() {
2159
2153
  if (this.getParentKey() === null) return this.getDefaultFor(this.parent);
@@ -2262,10 +2256,10 @@ var HasManyThrough = class extends Relation {
2262
2256
  }
2263
2257
  const model = await this.first(columns);
2264
2258
  if (model) return model;
2265
- return callback === null || callback === void 0 ? void 0 : callback();
2259
+ return callback?.();
2266
2260
  }
2267
2261
  async find(id, columns = ["*"]) {
2268
- if ((0, radashi.isArray)(id)) return await this.findMany(id, columns);
2262
+ if (Array.isArray(id)) return await this.findMany(id, columns);
2269
2263
  return await this.where(this.getRelated().getQualifiedKeyName(), "=", id).first(columns);
2270
2264
  }
2271
2265
  async findMany(ids, columns = ["*"]) {
@@ -2293,7 +2287,7 @@ var HasManyThrough = class extends Relation {
2293
2287
  return await this.query.paginate(perPage ?? 15, columns, pageName, page);
2294
2288
  }
2295
2289
  shouldSelect(columns = ["*"]) {
2296
- if ((columns === null || columns === void 0 ? void 0 : columns.at(0)) == "*") columns = [this.related.getTable() + ".*"];
2290
+ if (columns?.at(0) == "*") columns = [this.related.getTable() + ".*"];
2297
2291
  return [...columns, this.getQualifiedFirstKeyName() + " as laravel_through_key"];
2298
2292
  }
2299
2293
  async chunk(count, callback) {
@@ -2387,7 +2381,7 @@ const HasRelations = (Model) => {
2387
2381
  return this;
2388
2382
  }
2389
2383
  unsetRelation(relation) {
2390
- this.relations = (0, radashi.omit)(this.relations, [relation]);
2384
+ this.relations = _h3ravel_support.Arr.except(this.relations, [relation]);
2391
2385
  return this;
2392
2386
  }
2393
2387
  relationLoaded(relation) {
@@ -2410,8 +2404,7 @@ const HasRelations = (Model) => {
2410
2404
  return data;
2411
2405
  }
2412
2406
  guessBelongsToRelation() {
2413
- var _e$stack;
2414
- const functionName = (((_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2]) ?? "").split(" ")[5];
2407
+ const functionName = ((/* @__PURE__ */ new Error()).stack?.split("\n")[2] ?? "").split(" ")[5];
2415
2408
  return getRelationName(functionName);
2416
2409
  }
2417
2410
  joiningTable(related, instance = null) {
@@ -2521,7 +2514,7 @@ const HidesAttributes = (Model) => {
2521
2514
  makeVisible(...keys) {
2522
2515
  const visible = flattenDeep(keys);
2523
2516
  if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
2524
- this.hidden = (0, radashi.diff)(this.hidden, visible);
2517
+ this.hidden = (0, _h3ravel_collect_js.collect)(this.hidden).diff(visible).all();
2525
2518
  return this;
2526
2519
  }
2527
2520
  makeHidden(key, ...keys) {
@@ -2665,10 +2658,9 @@ var QueryBuilder = class QueryBuilder extends Inference$1 {
2665
2658
  asProxy() {
2666
2659
  return new Proxy(this, {
2667
2660
  get: function(target, prop) {
2668
- var _target$connector$cli;
2669
2661
  if (typeof target[prop] !== "undefined") return target[prop];
2670
2662
  if (["destroy", "schema"].includes(prop)) return target.connector.schema;
2671
- 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";
2663
+ const skipReturning = !!target.connector.client.config?.client?.includes("mysql") && prop === "returning";
2672
2664
  if ([
2673
2665
  "select",
2674
2666
  "from",
@@ -2871,6 +2863,9 @@ var arquebus = class arquebus {
2871
2863
  if (this.instance === null) this.instance = new arquebus();
2872
2864
  return this.instance;
2873
2865
  }
2866
+ static withSchema() {
2867
+ return this;
2868
+ }
2874
2869
  /**
2875
2870
  * Initialize a new database connection
2876
2871
  *
@@ -2960,12 +2955,12 @@ var arquebus = class arquebus {
2960
2955
  const tsPath = path.default.resolve("arquebus.config.ts");
2961
2956
  const instance = this.getInstance();
2962
2957
  if ((0, fs.existsSync)(jsPath)) {
2963
- config = (await import(jsPath)).default;
2958
+ config = (await (0, _h3ravel_shared.importFile)(jsPath)).default;
2964
2959
  if (addConnection) instance.addConnection(config, config.client);
2965
2960
  return config;
2966
2961
  }
2967
2962
  if ((0, fs.existsSync)(tsPath)) if (process.env.NODE_ENV !== "production") {
2968
- config = (await import(tsPath)).default;
2963
+ config = (await (0, _h3ravel_shared.importFile)(tsPath)).default;
2969
2964
  if (addConnection) instance.addConnection(config, config.client);
2970
2965
  return config;
2971
2966
  } else throw new Error("arquebus.config.ts found in production without build step");
@@ -2981,7 +2976,7 @@ var arquebus = class arquebus {
2981
2976
  "cjs"
2982
2977
  ], dir);
2983
2978
  if (found) if (!found.endsWith(".ts") || process.env.NODE_ENV !== "production") {
2984
- config = (await import(found)).default;
2979
+ config = (await (0, _h3ravel_shared.importFile)(found)).default;
2985
2980
  if (addConnection) instance.addConnection(config, config.client);
2986
2981
  return config;
2987
2982
  } else throw new Error("arquebus.config.ts found in production without build step");
@@ -3002,7 +2997,7 @@ var arquebus = class arquebus {
3002
2997
  }
3003
2998
  async destroyAll() {
3004
2999
  await Promise.all(Object.values(this.manager).map((connection) => {
3005
- return connection === null || connection === void 0 ? void 0 : connection.destroy();
3000
+ return connection?.destroy();
3006
3001
  }));
3007
3002
  }
3008
3003
  createModel(name, options = {}) {
@@ -3011,29 +3006,25 @@ var arquebus = class arquebus {
3011
3006
  this.models = {
3012
3007
  ...this.models,
3013
3008
  [name]: class extends BaseModel {
3014
- table = (options === null || options === void 0 ? void 0 : options.table) ?? null;
3015
- connection = (options === null || options === void 0 ? void 0 : options.connection) ?? null;
3016
- timestamps = (options === null || options === void 0 ? void 0 : options.timestamps) ?? true;
3017
- primaryKey = (options === null || options === void 0 ? void 0 : options.primaryKey) ?? "id";
3018
- keyType = (options === null || options === void 0 ? void 0 : options.keyType) ?? "int";
3019
- incrementing = (options === null || options === void 0 ? void 0 : options.incrementing) ?? true;
3020
- with = (options === null || options === void 0 ? void 0 : options.with) ?? [];
3021
- casts = (options === null || options === void 0 ? void 0 : options.casts) ?? {};
3022
- static CREATED_AT = (options === null || options === void 0 ? void 0 : options.CREATED_AT) ?? "created_at";
3023
- static UPDATED_AT = (options === null || options === void 0 ? void 0 : options.UPDATED_AT) ?? "updated_at";
3024
- static DELETED_AT = (options === null || options === void 0 ? void 0 : options.DELETED_AT) ?? "deleted_at";
3009
+ table = options?.table ?? null;
3010
+ connection = options?.connection ?? null;
3011
+ timestamps = options?.timestamps ?? true;
3012
+ primaryKey = options?.primaryKey ?? "id";
3013
+ keyType = options?.keyType ?? "int";
3014
+ incrementing = options?.incrementing ?? true;
3015
+ with = options?.with ?? [];
3016
+ casts = options?.casts ?? {};
3017
+ static CREATED_AT = options?.CREATED_AT ?? "created_at";
3018
+ static UPDATED_AT = options?.UPDATED_AT ?? "updated_at";
3019
+ static DELETED_AT = options?.DELETED_AT ?? "deleted_at";
3025
3020
  }
3026
3021
  };
3027
3022
  if ("attributes" in options) for (const attribute in options.attributes) {
3028
3023
  if (options.attributes[attribute] instanceof Attribute === false) throw new Error("Attribute must be an instance of \"Attribute\"");
3029
- this.models[name].prototype[getAttrMethod(attribute)] = () => {
3030
- var _options$attributes;
3031
- return (_options$attributes = options.attributes) === null || _options$attributes === void 0 ? void 0 : _options$attributes[attribute];
3032
- };
3024
+ this.models[name].prototype[getAttrMethod(attribute)] = () => options.attributes?.[attribute];
3033
3025
  }
3034
3026
  if ("relations" in options) for (const relation in options.relations) this.models[name].prototype[getRelationMethod(relation)] = function() {
3035
- var _options$relations;
3036
- return (_options$relations = options.relations) === null || _options$relations === void 0 ? void 0 : _options$relations[relation](this);
3027
+ return options.relations?.[relation](this);
3037
3028
  };
3038
3029
  if ("scopes" in options) for (const scope in options.scopes) this.models[name].prototype[getScopeMethod(scope)] = options.scopes[scope];
3039
3030
  this.models[name].setConnectionResolver(this);
@@ -3071,6 +3062,9 @@ var Model = class Model extends BaseModel {
3071
3062
  this.buildRelationships(attributes);
3072
3063
  return this.asProxy();
3073
3064
  }
3065
+ static define() {
3066
+ return this;
3067
+ }
3074
3068
  static query(trx = null) {
3075
3069
  return new this().newQuery(trx);
3076
3070
  }
@@ -3254,7 +3248,7 @@ var Model = class Model extends BaseModel {
3254
3248
  });
3255
3249
  }
3256
3250
  toData() {
3257
- return (0, radashi.assign)(this.attributesToData(), this.relationsToData());
3251
+ return _h3ravel_support.Obj.deepMerge(this.attributesToData(), this.relationsToData());
3258
3252
  }
3259
3253
  toJSON() {
3260
3254
  return this.toData();
@@ -3265,6 +3259,15 @@ var Model = class Model extends BaseModel {
3265
3259
  toString() {
3266
3260
  return this.toJson();
3267
3261
  }
3262
+ getAttributes() {
3263
+ return super.getAttributes();
3264
+ }
3265
+ getAttribute(key) {
3266
+ return super.getAttribute(key);
3267
+ }
3268
+ setAttribute(key, value) {
3269
+ return super.setAttribute(key, value);
3270
+ }
3268
3271
  fill(attributes) {
3269
3272
  for (const key in attributes) this.setAttribute(key, attributes[key]);
3270
3273
  return this;
@@ -3305,10 +3308,9 @@ var Model = class Model extends BaseModel {
3305
3308
  if (this.usesTimestamps()) this.updateTimestamps();
3306
3309
  const attributes = this.getAttributes();
3307
3310
  if (this.getIncrementing()) {
3308
- var _data$;
3309
3311
  const keyName = this.getKeyName();
3310
3312
  const data = await query.insert([attributes], [keyName]);
3311
- this.setAttribute(keyName, ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$[keyName]) || data[0]);
3313
+ this.setAttribute(keyName, data[0]?.[keyName] || data[0]);
3312
3314
  } else if (Object.keys(attributes).length > 0) await query.insert(attributes);
3313
3315
  this.exists = true;
3314
3316
  await this.execHooks("created", options);
@@ -3350,7 +3352,7 @@ var Model = class Model extends BaseModel {
3350
3352
  if (!this.exists) return Promise.resolve(void 0);
3351
3353
  const model = await this.constructor.query().where(this.getKeyName(), this.getKey()).first();
3352
3354
  this.attributes = { ...model.attributes };
3353
- await this.load((0, collect_js.default)(this.relations).reject((relation) => {
3355
+ await this.load((0, _h3ravel_collect_js.collect)(this.relations).reject((relation) => {
3354
3356
  return relation instanceof Pivot;
3355
3357
  }).keys().all());
3356
3358
  this.syncOriginal();
@@ -3414,7 +3416,7 @@ var Pivot = class extends Model {
3414
3416
  };
3415
3417
  //#endregion
3416
3418
  //#region src/collection.ts
3417
- var Collection = class Collection extends collect_js.Collection {
3419
+ var Collection = class extends _h3ravel_collect_js.Collection {
3418
3420
  newConstructor(...args) {
3419
3421
  return new (this.getConstructor())(...args);
3420
3422
  }
@@ -3423,17 +3425,18 @@ var Collection = class Collection extends collect_js.Collection {
3423
3425
  }
3424
3426
  async load(...relations) {
3425
3427
  if (this.isNotEmpty()) {
3426
- const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.items);
3428
+ const items = await this.first().constructor.query().with(...relations).eagerLoadRelations(this.all());
3427
3429
  return this.newConstructor(items);
3428
3430
  }
3429
3431
  return this;
3430
3432
  }
3431
3433
  async loadAggregate(relations, column, action = null) {
3432
3434
  if (this.isEmpty()) return this;
3433
- 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());
3434
- const attributes = (0, radashi.diff)(Object.keys(models.first().getAttributes()), [models.first().getKeyName()]);
3435
+ const first = this.first();
3436
+ const models = (await first.newModelQuery().whereIn(first.getKeyName(), this.modelKeys()).select(first.getKeyName()).withAggregate(relations, column, action).get()).keyBy(first.getKeyName());
3437
+ const attributes = (0, _h3ravel_collect_js.collect)(Object.keys(models.first().getAttributes())).diff([models.first().getKeyName()]).all();
3435
3438
  this.each((model) => {
3436
- const extraAttributes = (0, radashi.pick)(models.get(model.getKey()).getAttributes(), attributes);
3439
+ const extraAttributes = _h3ravel_support.Arr.select(models.get(model.getKey()).getAttributes(), attributes);
3437
3440
  model.fill(extraAttributes).syncOriginalAttributes(...attributes);
3438
3441
  });
3439
3442
  return this;
@@ -3471,20 +3474,21 @@ var Collection = class Collection extends collect_js.Collection {
3471
3474
  diff(items) {
3472
3475
  const diff = new this.constructor();
3473
3476
  const dictionary = this.getDictionary(items);
3474
- this.items.map((item) => {
3477
+ this.all().map((item) => {
3475
3478
  if (dictionary[item.getKey()] === void 0) diff.add(item);
3476
3479
  });
3477
3480
  return diff;
3478
3481
  }
3479
- except(keys) {
3480
- const dictionary = (0, radashi.omit)(this.getDictionary(), keys);
3482
+ except(...keys) {
3483
+ const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
3484
+ const dictionary = _h3ravel_support.Arr.except(this.getDictionary(), values);
3481
3485
  return new this.constructor(Object.values(dictionary));
3482
3486
  }
3483
3487
  intersect(items) {
3484
3488
  const intersect = new this.constructor();
3485
- if ((0, radashi.isEmpty)(items)) return intersect;
3489
+ if (_h3ravel_support.Arr.isEmpty(items)) return intersect;
3486
3490
  const dictionary = this.getDictionary(items);
3487
- for (const item of this.items) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
3491
+ for (const item of this.all()) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
3488
3492
  return intersect;
3489
3493
  }
3490
3494
  unique(key, _strict = false) {
@@ -3493,20 +3497,21 @@ var Collection = class Collection extends collect_js.Collection {
3493
3497
  }
3494
3498
  find(key, defaultValue = null) {
3495
3499
  if (key instanceof Model) key = key.getKey();
3496
- if ((0, radashi.isArray)(key)) {
3500
+ if (Array.isArray(key)) {
3497
3501
  if (this.isEmpty()) return new this.constructor();
3498
3502
  return this.whereIn(this.first().getKeyName(), key);
3499
3503
  }
3500
- (0, collect_js.collect)(this.items).first((model) => {
3504
+ (0, _h3ravel_collect_js.collect)(this.all()).first((model) => {
3501
3505
  return model.getKey() == key;
3502
3506
  });
3503
- return this.items.filter((model) => {
3507
+ return this.all().filter((model) => {
3504
3508
  return model.getKey() == key;
3505
3509
  })[0] || defaultValue;
3506
3510
  }
3507
3511
  async fresh(...args) {
3508
3512
  if (this.isEmpty()) return new this.constructor();
3509
3513
  const model = this.first();
3514
+ if (!model) return new this.constructor();
3510
3515
  const freshModels = (await model.newQuery().with(...args).whereIn(model.getKeyName(), this.modelKeys()).get()).getDictionary();
3511
3516
  return this.filter((model) => {
3512
3517
  return model.exists && freshModels[model.getKey()] !== void 0;
@@ -3529,15 +3534,15 @@ var Collection = class Collection extends collect_js.Collection {
3529
3534
  item.append(attributes);
3530
3535
  });
3531
3536
  }
3532
- only(keys) {
3533
- if (keys === null) return new Collection(this.items);
3534
- const dictionary = (0, radashi.pick)(this.getDictionary(), keys);
3537
+ only(...keys) {
3538
+ const values = keys.length === 1 && Array.isArray(keys[0]) ? keys[0].map(String) : keys.map(String);
3539
+ const dictionary = _h3ravel_support.Arr.select(this.getDictionary(), values);
3535
3540
  return new this.constructor(Object.values(dictionary));
3536
3541
  }
3537
3542
  getDictionary(items) {
3538
- items = !items ? this.items : items;
3543
+ const values = !items ? this.all() : items instanceof _h3ravel_collect_js.Collection ? items.all() : items;
3539
3544
  const dictionary = {};
3540
- items.map((value) => {
3545
+ values.map((value) => {
3541
3546
  dictionary[value.getKey()] = value;
3542
3547
  });
3543
3548
  return dictionary;
@@ -3561,8 +3566,8 @@ var Collection = class Collection extends collect_js.Collection {
3561
3566
  return JSON.stringify(this.toData(), ...args);
3562
3567
  }
3563
3568
  [Symbol.iterator] = () => {
3564
- const items = this.items;
3565
- const length = this.items.length;
3569
+ const items = this.all();
3570
+ const length = items.length;
3566
3571
  let n = 0;
3567
3572
  return { next() {
3568
3573
  return n < length ? {
@@ -3609,24 +3614,24 @@ const InteractsWithPivotTable = (Relation) => {
3609
3614
  let records;
3610
3615
  const results = await this.getCurrentlyAttachedPivots();
3611
3616
  const current = results.length === 0 ? [] : results.map((result) => result.toData()).pluck(this.relatedPivotKey).all().map((i) => String(i));
3612
- const detach = (0, radashi.diff)(current, Object.keys(records = this.formatRecordsList(this.parseIds(ids))));
3617
+ const detach = (0, _h3ravel_collect_js.collect)(current).diff(Object.keys(records = this.formatRecordsList(this.parseIds(ids)))).all();
3613
3618
  if (detaching && detach.length > 0) {
3614
3619
  await this.detach(detach);
3615
3620
  changes.detached = this.castKeys(detach);
3616
3621
  }
3617
- changes = (0, radashi.assign)(changes, await this.attachNew(records, current, false));
3622
+ changes = _h3ravel_support.Obj.deepMerge(changes, await this.attachNew(records, current, false));
3618
3623
  return changes;
3619
3624
  }
3620
3625
  syncWithoutDetaching(ids) {
3621
3626
  return this.sync(ids, false);
3622
3627
  }
3623
3628
  syncWithPivotValues(ids, values, detaching = true) {
3624
- return this.sync((0, collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
3625
- return [id, values];
3629
+ return this.sync((0, _h3ravel_collect_js.collect)(this.parseIds(ids)).mapWithKeys((id) => {
3630
+ return [String(id), values];
3626
3631
  }), detaching);
3627
3632
  }
3628
3633
  withPivot(columns) {
3629
- this.pivotColumns = this.pivotColumns.concat((0, radashi.isArray)(columns) ? columns : Array.prototype.slice.call(columns));
3634
+ this.pivotColumns = this.pivotColumns.concat(Array.isArray(columns) ? columns : Array.prototype.slice.call(columns));
3630
3635
  return this;
3631
3636
  }
3632
3637
  async attachNew(records, current, touch = true) {
@@ -3662,9 +3667,9 @@ const InteractsWithPivotTable = (Relation) => {
3662
3667
  return parseInt(updated);
3663
3668
  }
3664
3669
  formatRecordsList(records) {
3665
- return (0, collect_js.collect)(records).mapWithKeys((attributes, id) => {
3666
- if (!(0, radashi.isArray)(attributes)) [id, attributes] = [attributes, {}];
3667
- return [id, attributes];
3670
+ return (0, _h3ravel_collect_js.collect)(records).mapWithKeys((attributes, id) => {
3671
+ if (!Array.isArray(attributes)) [id, attributes] = [attributes, {}];
3672
+ return [String(id), attributes];
3668
3673
  }).all();
3669
3674
  }
3670
3675
  async getCurrentlyAttachedPivots() {
@@ -3734,7 +3739,7 @@ const InteractsWithPivotTable = (Relation) => {
3734
3739
  }
3735
3740
  formatAttachRecord(key, value, attributes, hasTimestamps) {
3736
3741
  const [id, newAttributes] = this.extractAttachIdAndAttributes(key, value, attributes);
3737
- return (0, radashi.assign)(this.baseAttachRecord(id, hasTimestamps), newAttributes);
3742
+ return _h3ravel_support.Obj.deepMerge(this.baseAttachRecord(id, hasTimestamps), newAttributes);
3738
3743
  }
3739
3744
  baseAttachRecord(id, timed) {
3740
3745
  let record = {};
@@ -3747,7 +3752,7 @@ const InteractsWithPivotTable = (Relation) => {
3747
3752
  return record;
3748
3753
  }
3749
3754
  extractAttachIdAndAttributes(key, value, newAttributes) {
3750
- return (0, radashi.isArray)(value) ? [key, {
3755
+ return Array.isArray(value) ? [key, {
3751
3756
  ...value,
3752
3757
  ...newAttributes
3753
3758
  }] : [value, newAttributes];
@@ -3758,7 +3763,7 @@ const InteractsWithPivotTable = (Relation) => {
3758
3763
  parseIds(value) {
3759
3764
  if (value instanceof Model) return [value[this.relatedKey]];
3760
3765
  if (value instanceof Collection) return value.pluck(this.relatedKey).all();
3761
- return (0, radashi.isArray)(value) ? value : [value];
3766
+ return Array.isArray(value) ? value : [value];
3762
3767
  }
3763
3768
  };
3764
3769
  };
@@ -3818,9 +3823,8 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
3818
3823
  return this;
3819
3824
  }
3820
3825
  async get(columns) {
3821
- var _builder$query;
3822
3826
  const builder = this.query.applyScopes();
3823
- 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;
3827
+ columns = builder.query?._statements?.find((item) => item.grouping == "columns") ? [] : columns;
3824
3828
  let models = await builder.select(this.shouldSelect(columns)).getModels();
3825
3829
  this.hydratePivotRelation(models);
3826
3830
  if (models.length > 0) models = await builder.eagerLoadRelations(models);
@@ -3869,7 +3873,7 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
3869
3873
  const value = model.attributes[key];
3870
3874
  if (key.startsWith("pivot_")) {
3871
3875
  values[key.substring(6)] = value;
3872
- model.attributes = (0, radashi.omit)(model.attributes, [key]);
3876
+ model.attributes = _h3ravel_support.Arr.except(model.attributes, [key]);
3873
3877
  }
3874
3878
  }
3875
3879
  return values;
@@ -3880,11 +3884,11 @@ var BelongsToMany = class extends compose(Relation, InteractsWithPivotTable) {
3880
3884
  return this.withPivot(this.createdAt(), this.updatedAt());
3881
3885
  }
3882
3886
  shouldSelect(columns = ["*"]) {
3883
- if ((0, radashi.isEqual)(columns, ["*"])) columns = [this.related.getTable() + ".*"];
3887
+ if (columns.length === 1 && columns[0] === "*") columns = [this.related.getTable() + ".*"];
3884
3888
  return columns.concat(this.aliasedPivotColumns());
3885
3889
  }
3886
3890
  aliasedPivotColumns() {
3887
- return (0, collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
3891
+ return (0, _h3ravel_collect_js.collect)([this.foreignPivotKey, this.relatedPivotKey].concat(this.pivotColumns)).map((column) => {
3888
3892
  return this.qualifyPivotColumn(column) + " as pivot_" + column;
3889
3893
  }).unique().all();
3890
3894
  }
@@ -4004,9 +4008,8 @@ var Builder = class Builder extends Inference {
4004
4008
  }
4005
4009
  asProxy() {
4006
4010
  return new Proxy(this, { get(target, prop) {
4007
- var _target$query$connect;
4008
4011
  if (typeof target[prop] !== "undefined") return target[prop];
4009
- 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";
4012
+ const skipReturning = !!target.query.connector?.client.config?.client?.includes("mysql") && prop === "returning";
4010
4013
  if ([
4011
4014
  "select",
4012
4015
  "from",
@@ -4100,7 +4103,7 @@ var Builder = class Builder extends Inference {
4100
4103
  };
4101
4104
  }
4102
4105
  if (prop.startsWith("where")) {
4103
- const column = (0, radashi.snake)(prop.substring(5));
4106
+ const column = _h3ravel_support.Str.snake(prop.substring(5));
4104
4107
  return (...args) => {
4105
4108
  target.query.where(column, ...args);
4106
4109
  return target.asProxy();
@@ -4175,7 +4178,8 @@ var Builder = class Builder extends Inference {
4175
4178
  }
4176
4179
  addUpdatedAtColumn(values) {
4177
4180
  if (!this.model.usesTimestamps() || this.model.getUpdatedAtColumn() === null) return values;
4178
- values = (0, radashi.assign)({ [this.model.getUpdatedAtColumn()]: this.model.freshTimestampString() }, values);
4181
+ const column = this.model.getUpdatedAtColumn();
4182
+ values = _h3ravel_support.Obj.deepMerge({ [column]: this.model.freshTimestampString() }, values);
4179
4183
  return values;
4180
4184
  }
4181
4185
  delete() {
@@ -4203,9 +4207,8 @@ var Builder = class Builder extends Inference {
4203
4207
  return this.model;
4204
4208
  }
4205
4209
  setModel(model) {
4206
- var _this$query;
4207
4210
  this.model = model;
4208
- 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());
4211
+ if (typeof this.query?.client?.table == "function") this.query = this.query.client.table(this.model.getTable());
4209
4212
  else this.query = this.query.table(this.model.getTable());
4210
4213
  return this;
4211
4214
  }
@@ -4248,7 +4251,7 @@ var Builder = class Builder extends Inference {
4248
4251
  }
4249
4252
  withoutGlobalScope(scope) {
4250
4253
  if (typeof scope !== "string") scope = scope.constructor.name;
4251
- this.globalScopes = (0, radashi.omit)(this.globalScopes, [scope]);
4254
+ this.globalScopes = _h3ravel_support.Arr.except(this.globalScopes, [scope]);
4252
4255
  return this;
4253
4256
  }
4254
4257
  macro(name, callback) {
@@ -4265,7 +4268,7 @@ var Builder = class Builder extends Inference {
4265
4268
  let eagerLoads = {};
4266
4269
  if (typeof args[1] === "function") {
4267
4270
  const eagerLoad = this.parseWithRelations({ [args[0]]: args[1] });
4268
- this.eagerLoad = (0, radashi.assign)(this.eagerLoad, eagerLoad);
4271
+ this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, eagerLoad);
4269
4272
  return this;
4270
4273
  }
4271
4274
  const relations = flattenDeep(args);
@@ -4274,13 +4277,13 @@ var Builder = class Builder extends Inference {
4274
4277
  let eagerLoad;
4275
4278
  if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
4276
4279
  else if (typeof relation === "object") eagerLoad = relation;
4277
- eagerLoads = (0, radashi.assign)(eagerLoads, eagerLoad);
4280
+ eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
4278
4281
  }
4279
- this.eagerLoad = (0, radashi.assign)(this.eagerLoad, this.parseWithRelations(eagerLoads));
4282
+ this.eagerLoad = _h3ravel_support.Obj.deepMerge(this.eagerLoad, this.parseWithRelations(eagerLoads));
4280
4283
  return this;
4281
4284
  }
4282
4285
  has(relation, operator = ">=", count = 1, boolean = "and", callback = null) {
4283
- if ((0, radashi.isString)(relation)) {
4286
+ if (typeof relation === "string") {
4284
4287
  if (relation.includes(".")) return this.hasNested(relation, operator, count, boolean, callback);
4285
4288
  relation = this.getRelationWithoutConstraints(getRelationMethod(relation));
4286
4289
  }
@@ -4357,7 +4360,7 @@ var Builder = class Builder extends Inference {
4357
4360
  let eagerLoad;
4358
4361
  if (typeof relation === "string") eagerLoad = { [relation]: (q) => q };
4359
4362
  else if (typeof relation === "object") eagerLoad = relation;
4360
- eagerLoads = (0, radashi.assign)(eagerLoads, eagerLoad);
4363
+ eagerLoads = _h3ravel_support.Obj.deepMerge(eagerLoads, eagerLoad);
4361
4364
  }
4362
4365
  relations = eagerLoads;
4363
4366
  const db = this.model.getConnection();
@@ -4376,7 +4379,7 @@ var Builder = class Builder extends Inference {
4376
4379
  } else expression = column;
4377
4380
  const query = relation.getRelationExistenceQuery(relation.getRelated().newModelQuery(), this, db.raw(expression));
4378
4381
  constraints(query);
4379
- alias = alias || (0, radashi.snake)(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
4382
+ alias = alias || _h3ravel_support.Str.snake(`${name} ${action} ${column}`.replace("/[^[:alnum:][:space:]_]/u", ""));
4380
4383
  if (action === "exists") this.select(db.raw(`exists(${query.toSql().sql}) as ${alias}`));
4381
4384
  else this.selectSub(action ? query : query.limit(1), alias);
4382
4385
  }
@@ -4400,7 +4403,7 @@ var Builder = class Builder extends Inference {
4400
4403
  }
4401
4404
  parseSub(query) {
4402
4405
  if (query instanceof Builder || query instanceof Relation) return [query.toSql().sql, query.toSql().bindings];
4403
- else if ((0, radashi.isString)(query)) return [query, []];
4406
+ else if (typeof query === "string") return [query, []];
4404
4407
  else throw new Error("A subquery must be a query builder instance, a Closure, or a string.");
4405
4408
  }
4406
4409
  prependDatabaseNameIfCrossDatabaseQuery(query) {
@@ -4457,15 +4460,15 @@ var Builder = class Builder extends Inference {
4457
4460
  if (prefix !== "") prefix += ".";
4458
4461
  for (const key in relations) {
4459
4462
  const value = relations[key];
4460
- if ((0, radashi.isString)(value) || Number.isFinite(parseInt(value))) continue;
4463
+ if (typeof value === "string" || Number.isFinite(parseInt(value))) continue;
4461
4464
  const [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(key, value);
4462
4465
  preparedRelationships = Object.assign({}, preparedRelationships, { [`${prefix}${attribute}`]: attributeSelectConstraint }, this.prepareNestedWithRelationships(value, `${prefix}${attribute}`));
4463
- relations = (0, radashi.omit)(relations, [key]);
4466
+ relations = _h3ravel_support.Arr.except(relations, [key]);
4464
4467
  }
4465
4468
  for (const key in relations) {
4466
4469
  const value = relations[key];
4467
4470
  let attribute = key, attributeSelectConstraint = value;
4468
- if ((0, radashi.isString)(value)) [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
4471
+ if (typeof value === "string") [attribute, attributeSelectConstraint] = this.parseNameAndAttributeSelectionConstraint(value);
4469
4472
  preparedRelationships[`${prefix}${attribute}`] = this.combineConstraints([attributeSelectConstraint, preparedRelationships[`${prefix}${attribute}`] || (() => {})]);
4470
4473
  }
4471
4474
  return preparedRelationships;
@@ -4513,8 +4516,8 @@ var Builder = class Builder extends Inference {
4513
4516
  }
4514
4517
  async findOrFail(...args) {
4515
4518
  const data = await this.find(...args);
4516
- if ((0, radashi.isArray)(args[0])) {
4517
- if (data.count() !== args[0].length) throw new ModelNotFoundError().setModel(this.model.constructor.name, (0, radashi.diff)(args[0], data.modelKeys()));
4519
+ if (Array.isArray(args[0])) {
4520
+ 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());
4518
4521
  return data;
4519
4522
  }
4520
4523
  if (data === null) throw new ModelNotFoundError().setModel(this.model.constructor.name, args[0]);
@@ -4528,12 +4531,12 @@ var Builder = class Builder extends Inference {
4528
4531
  async firstOrNew(attributes = {}, values = {}) {
4529
4532
  const instance = await this.where(attributes).first();
4530
4533
  if (instance !== null) return instance;
4531
- return this.newModelInstance((0, radashi.assign)(attributes, values));
4534
+ return this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values));
4532
4535
  }
4533
4536
  async firstOrCreate(attributes = {}, values = {}) {
4534
4537
  const instance = await this.where(attributes).first();
4535
4538
  if (instance !== null) return instance;
4536
- return tap(this.newModelInstance((0, radashi.assign)(attributes, values)), async (instance) => {
4539
+ return tap(this.newModelInstance(_h3ravel_support.Obj.deepMerge(attributes, values)), async (instance) => {
4537
4540
  await instance.save({ client: this.query });
4538
4541
  });
4539
4542
  }
@@ -4553,22 +4556,21 @@ var Builder = class Builder extends Inference {
4553
4556
  return this;
4554
4557
  }
4555
4558
  async find(id, columns) {
4556
- if ((0, radashi.isArray)(id) || id instanceof Collection) return await this.findMany(id, columns);
4559
+ if (Array.isArray(id) || id instanceof Collection) return await this.findMany(id, columns);
4557
4560
  return await this.where(this.model.getKeyName(), id).first(columns);
4558
4561
  }
4559
4562
  async findMany(ids, columns = ["*"]) {
4560
- if (ids instanceof Collection) ids = ids.modelKeys();
4561
- ids = (0, radashi.isArray)(ids) ? ids : [ids];
4562
- if (ids.length === 0) return new Collection([]);
4563
- return await this.whereIn(this.model.getKeyName(), ids).get(columns);
4563
+ const values = ids instanceof Collection ? ids.modelKeys() : Array.isArray(ids) ? ids : [ids];
4564
+ if (values.length === 0) return new Collection([]);
4565
+ return await this.whereIn(this.model.getKeyName(), values).get(columns);
4564
4566
  }
4565
4567
  async pluck(column) {
4566
4568
  return new Collection(await this.query.pluck(column));
4567
4569
  }
4568
4570
  async destroy(ids) {
4569
4571
  if (ids instanceof Collection) ids = ids.modelKeys();
4570
- if (ids instanceof collect_js.Collection) ids = ids.all();
4571
- ids = (0, radashi.isArray)(ids) ? ids : Array.prototype.slice.call(ids);
4572
+ if (ids instanceof _h3ravel_collect_js.Collection) ids = ids.all();
4573
+ ids = Array.isArray(ids) ? ids : Array.prototype.slice.call(ids);
4572
4574
  if (ids.length === 0) return 0;
4573
4575
  const key = this.model.newInstance().getKeyName();
4574
4576
  let count = 0;
@@ -4586,12 +4588,11 @@ var Builder = class Builder extends Inference {
4586
4588
  return await this.model.newModelQuery().get(columns);
4587
4589
  }
4588
4590
  async paginate(page = 1, perPage = 10) {
4589
- var _this;
4590
4591
  page = page || 1;
4591
- perPage = perPage || ((_this = this) === null || _this === void 0 || (_this = _this.model) === null || _this === void 0 ? void 0 : _this.perPage) || 15;
4592
+ perPage = perPage || this?.model?.perPage || 15;
4592
4593
  this.applyScopes();
4593
4594
  const total = await this.query.clone().clearOrder().clearSelect().count(this.primaryKey);
4594
- let results = [];
4595
+ let results;
4595
4596
  if (total > 0) {
4596
4597
  const skip = (page - 1) * (perPage ?? 10);
4597
4598
  this.take(perPage).skip(skip);
@@ -4601,7 +4602,7 @@ var Builder = class Builder extends Inference {
4601
4602
  return new Paginator(results, parseInt(total), perPage, page);
4602
4603
  }
4603
4604
  async getModels(...columns) {
4604
- columns = (0, radashi.flat)(columns);
4605
+ columns = flatten(columns);
4605
4606
  if (columns.length > 0) {
4606
4607
  if (this.query._statements.filter((item) => item.grouping == "columns").length == 0 && columns[0] !== "*") this.query.select(...columns);
4607
4608
  }
@@ -4692,7 +4693,7 @@ var SQLite = class {
4692
4693
  column: column.name
4693
4694
  }));
4694
4695
  const tables = await this.tables();
4695
- return flatten$2(await Promise.all(tables.map(async (table) => await this.columns(table))));
4696
+ return flatten(await Promise.all(tables.map(async (table) => await this.columns(table))));
4696
4697
  }
4697
4698
  async columnInfo(table, column) {
4698
4699
  const getColumnsForTable = async (table) => {
@@ -4718,17 +4719,17 @@ var SQLite = class {
4718
4719
  is_generated: raw.hidden !== 0,
4719
4720
  generation_expression: null,
4720
4721
  is_nullable: raw.notnull === 0,
4721
- is_unique: !!(index === null || index === void 0 ? void 0 : index.unique) && (indexInfo === null || indexInfo === void 0 ? void 0 : indexInfo.length) === 1,
4722
+ is_unique: !!index?.unique && indexInfo?.length === 1,
4722
4723
  is_primary_key: raw.pk === 1,
4723
4724
  has_auto_increment: raw.pk === 1 && tablesWithAutoIncrementPrimaryKeys.includes(table),
4724
- foreign_key_column: (foreignKey === null || foreignKey === void 0 ? void 0 : foreignKey.to) || null,
4725
- foreign_key_table: (foreignKey === null || foreignKey === void 0 ? void 0 : foreignKey.table) || null
4725
+ foreign_key_column: foreignKey?.to || null,
4726
+ foreign_key_table: foreignKey?.table || null
4726
4727
  };
4727
4728
  });
4728
4729
  };
4729
4730
  if (!table) {
4730
4731
  const tables = await this.tables();
4731
- return flatten$2(await Promise.all(tables.map(async (table) => await getColumnsForTable(table))));
4732
+ return flatten(await Promise.all(tables.map(async (table) => await getColumnsForTable(table))));
4732
4733
  }
4733
4734
  if (table && !column) return await getColumnsForTable(table);
4734
4735
  return (await getColumnsForTable(table)).find((columnInfo) => columnInfo.name === column);
@@ -4759,7 +4760,7 @@ var SQLite = class {
4759
4760
  constraint_name: null
4760
4761
  }));
4761
4762
  const tables = await this.tables();
4762
- return flatten$2(await Promise.all(tables.map(async (table) => await this.foreignKeys(table))));
4763
+ return flatten(await Promise.all(tables.map(async (table) => await this.foreignKeys(table))));
4763
4764
  }
4764
4765
  async uniqueConstraints(table) {
4765
4766
  if (table) {
@@ -4775,7 +4776,7 @@ var SQLite = class {
4775
4776
  });
4776
4777
  }
4777
4778
  const tables = await this.tables();
4778
- return flatten$2(await Promise.all(tables.map(async (table) => await this.uniqueConstraints(table))));
4779
+ return flatten(await Promise.all(tables.map(async (table) => await this.uniqueConstraints(table))));
4779
4780
  }
4780
4781
  };
4781
4782
  //#endregion