@orieljs/database 0.1.0-alpha.5 → 0.1.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -363,7 +363,10 @@ var AbstractPaginator = class _AbstractPaginator {
363
363
  this.collection = items;
364
364
  return this;
365
365
  }
366
- /** Transforms each item in place, typically for serialization: paginator.through(post => ({ id: post.id })). */
366
+ /**
367
+ * Transforms each item in place, typically for serialization, and returns this paginator typed with the new items:
368
+ * `posts.through((post) => ({ id: post.id }))`. Each paginator narrows the return type to its own class.
369
+ */
367
370
  through(callback) {
368
371
  this.collection = this.collection.map(callback);
369
372
  return this;
@@ -466,6 +469,9 @@ var CursorPaginator = class extends AbstractPaginator {
466
469
  getCursorName() {
467
470
  return this.cursorName;
468
471
  }
472
+ through(callback) {
473
+ return super.through(callback);
474
+ }
469
475
  hasMorePages() {
470
476
  return this.cursorValue === void 0 && this.hasMore || this.cursorValue !== void 0 && this.cursorValue.pointsToNextItems() && this.hasMore || this.cursorValue !== void 0 && this.cursorValue.pointsToPreviousItems();
471
477
  }
@@ -524,6 +530,9 @@ var LengthAwarePaginator = class extends AbstractPaginator {
524
530
  total() {
525
531
  return this.totalValue;
526
532
  }
533
+ through(callback) {
534
+ return super.through(callback);
535
+ }
527
536
  lastPage() {
528
537
  return this.lastPageValue;
529
538
  }
@@ -614,6 +623,9 @@ var Paginator = class extends AbstractPaginator {
614
623
  hasMorePages() {
615
624
  return this.hasMore;
616
625
  }
626
+ through(callback) {
627
+ return super.through(callback);
628
+ }
617
629
  hasPages() {
618
630
  return this.currentPageValue !== 1 || this.hasMore;
619
631
  }
@@ -2788,7 +2800,7 @@ import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
2788
2800
  import { DatabaseManager as DatabaseManager2 } from "@orieljs/contracts";
2789
2801
  import { Collection as Collection11 } from "@orieljs/collections";
2790
2802
  import { currentContainer as currentContainer3, inject } from "@orieljs/container";
2791
- import { Str as Str5 } from "@orieljs/support";
2803
+ import { Str as Str6 } from "@orieljs/support";
2792
2804
 
2793
2805
  // Eloquent/Builder.ts
2794
2806
  import { Collection as Collection4 } from "@orieljs/collections";
@@ -3126,12 +3138,19 @@ var Builder2 = class extends Builder {
3126
3138
  const key = column.includes(".") ? column.slice(column.lastIndexOf(".") + 1) : column;
3127
3139
  return new Collection4(rows.map((row) => this.model.newInstance().setRawAttributes({ [key]: row[key] }).getAttribute(key)));
3128
3140
  }
3141
+ /** Whether `id` can't be one of the model's unique ids (not a UUID for HasUuids): it matches no row. */
3142
+ isMalformedKey(id) {
3143
+ return this.model.uniqueIds().includes(this.model.getKeyName()) && !this.model.isValidUniqueId(id);
3144
+ }
3145
+ /** A malformed unique id (HasUuids, HasUlids) finds nothing without a query, as route model binding does. */
3129
3146
  async find(id) {
3147
+ if (this.isMalformedKey(id)) return void 0;
3130
3148
  return this.clone().whereKey(id).first();
3131
3149
  }
3132
3150
  async findMany(ids) {
3133
- if (!ids.length) return new Collection4();
3134
- return this.clone().whereKey([...ids]).get();
3151
+ const keys = ids.filter((id) => !this.isMalformedKey(id));
3152
+ if (!keys.length) return new Collection4();
3153
+ return this.clone().whereKey(keys).get();
3135
3154
  }
3136
3155
  async findOrFail(id) {
3137
3156
  if (Array.isArray(id)) {
@@ -3387,7 +3406,7 @@ import { existsSync, readdirSync } from "fs";
3387
3406
  import { join as join3 } from "path";
3388
3407
  import { pathToFileURL } from "url";
3389
3408
  import { Collection as Collection8 } from "@orieljs/collections";
3390
- import { Str as Str4 } from "@orieljs/support";
3409
+ import { Str as Str5 } from "@orieljs/support";
3391
3410
 
3392
3411
  // Eloquent/Relations/BelongsTo.ts
3393
3412
  import { Str as Str3 } from "@orieljs/support";
@@ -3779,6 +3798,7 @@ var BelongsToMany = class extends Relation {
3779
3798
  };
3780
3799
 
3781
3800
  // Eloquent/Relations/HasOneOrMany.ts
3801
+ import { Str as Str4 } from "@orieljs/support";
3782
3802
  var HasOneOrMany = class extends Relation {
3783
3803
  /**
3784
3804
  * @param foreignKey the qualified foreign key on the related table ('comments.post_id')
@@ -3795,6 +3815,8 @@ var HasOneOrMany = class extends Relation {
3795
3815
  foreignKey;
3796
3816
  localKey;
3797
3817
  morph;
3818
+ /** The relation on each related model that chaperone() points back at the parent. */
3819
+ inverseRelationship;
3798
3820
  /** 'post_id' */
3799
3821
  getForeignKeyName() {
3800
3822
  return this.foreignKey.slice(this.foreignKey.lastIndexOf(".") + 1);
@@ -3816,6 +3838,61 @@ var HasOneOrMany = class extends Relation {
3816
3838
  getMorphClass() {
3817
3839
  return this.morph?.value;
3818
3840
  }
3841
+ /**
3842
+ * Laravel's chaperone(): every related model this relation loads, eagerly or lazily, or makes, gets the parent as
3843
+ * its `relation` (guessed when not given: post_id → post, the parent's class, owner), so reading it needs no query:
3844
+ * `comments() { return this.hasMany(Comment).chaperone() }`.
3845
+ */
3846
+ chaperone(relation) {
3847
+ const name = relation ?? this.guessInverseRelation();
3848
+ if (name === void 0 || !this.model.isRelation(name)) throw new RelationNotFoundError(this.model.constructor.name, name ?? "null");
3849
+ this.inverseRelationship = name;
3850
+ return this;
3851
+ }
3852
+ /** Laravel's inverse(): chaperone() under its other name. */
3853
+ inverse(relation) {
3854
+ return this.chaperone(relation);
3855
+ }
3856
+ withoutChaperone() {
3857
+ this.inverseRelationship = void 0;
3858
+ return this;
3859
+ }
3860
+ withoutInverse() {
3861
+ return this.withoutChaperone();
3862
+ }
3863
+ getInverseRelationship() {
3864
+ return this.inverseRelationship;
3865
+ }
3866
+ /** The first of the possible names that is a relation of the related model. */
3867
+ guessInverseRelation() {
3868
+ return this.getPossibleInverseRelations().find((name) => this.model.isRelation(name));
3869
+ }
3870
+ /** Laravel's candidates: the morph name, the foreign key without the parent's key, the parent's class, owner, parent. */
3871
+ getPossibleInverseRelations() {
3872
+ const key = this.parent.getKeyName();
3873
+ const names = [
3874
+ this.morph ? Str4.beforeLast(this.getMorphType(), "_type") : "",
3875
+ Str4.camel(Str4.beforeLast(this.getForeignKeyName(), key)),
3876
+ Str4.camel(Str4.beforeLast(this.parent.getForeignKey(), key)),
3877
+ Str4.camel(this.parent.constructor.name),
3878
+ "owner",
3879
+ this.parent.constructor === this.model.constructor ? "parent" : ""
3880
+ ];
3881
+ return [...new Set(names.filter((name) => name !== ""))];
3882
+ }
3883
+ /** Sets the parent on a related model, when chaperone() named the relation. */
3884
+ applyInverseRelationToModel(model, parent = this.parent) {
3885
+ if (model && this.inverseRelationship !== void 0) model.setRelation(this.inverseRelationship, parent);
3886
+ return model;
3887
+ }
3888
+ applyInverseRelationToMany(models, parent = this.parent) {
3889
+ for (const model of models) this.applyInverseRelationToModel(model, parent);
3890
+ return models;
3891
+ }
3892
+ /** The relation query's rows (get(), first(), paginate(), …), pointing back at the parent with chaperone(). */
3893
+ async runSelect() {
3894
+ return this.applyInverseRelationToMany(await super.runSelect());
3895
+ }
3819
3896
  addConstraints() {
3820
3897
  this.where(this.foreignKey, "=", this.getParentKey());
3821
3898
  this.whereNotNull(this.foreignKey);
@@ -3849,7 +3926,7 @@ var HasOneOrMany = class extends Relation {
3849
3926
  setForeignAttributes(model) {
3850
3927
  model.setAttribute(this.getForeignKeyName(), this.getParentKey());
3851
3928
  if (this.morph) model.setAttribute(this.getMorphType(), this.morph.value);
3852
- return model;
3929
+ return this.applyInverseRelationToModel(model);
3853
3930
  }
3854
3931
  async saveMany(models) {
3855
3932
  const saved = [];
@@ -4004,13 +4081,13 @@ var Factory = class _Factory {
4004
4081
  }
4005
4082
  /** Creates related models for each created model: has(Post.factory().count(3)) (relationship default: 'posts'). */
4006
4083
  has(factory, relationship, pivot = {}) {
4007
- const name = relationship ?? Str4.camel(Str4.plural(new factory.model().constructor.name));
4084
+ const name = relationship ?? Str5.camel(Str5.plural(new factory.model().constructor.name));
4008
4085
  return this.newInstance({ hasRelations: [...this.hasRelations, { factory, relationship: name, pivot }] });
4009
4086
  }
4010
4087
  /** Sets a belongsTo parent: for(User.factory()) or for(user) (relationship default: 'user'). Created once. */
4011
4088
  for(parent, relationship) {
4012
4089
  const cls = parent instanceof Model ? parent.constructor : new parent.model().constructor;
4013
- return this.newInstance({ forRelations: [...this.forRelations, { parent, relationship: relationship ?? Str4.camel(cls.name) }] });
4090
+ return this.newInstance({ forRelations: [...this.forRelations, { parent, relationship: relationship ?? Str5.camel(cls.name) }] });
4014
4091
  }
4015
4092
  afterMaking(callback) {
4016
4093
  return this.newInstance({ afterMakingCallbacks: [...this.afterMakingCallbacks, callback] });
@@ -4181,7 +4258,8 @@ var HasMany = class extends HasOneOrMany {
4181
4258
  match(models, results, relation) {
4182
4259
  const dictionary = this.buildDictionary(results);
4183
4260
  for (const model of models) {
4184
- model.setRelation(relation, new Collection9(dictionary.get(String(model.getAttribute(this.localKey))) ?? []));
4261
+ const children = this.applyInverseRelationToMany(dictionary.get(String(model.getAttribute(this.localKey))) ?? [], model);
4262
+ model.setRelation(relation, new Collection9(children));
4185
4263
  }
4186
4264
  return models;
4187
4265
  }
@@ -4295,7 +4373,7 @@ var HasOne = class extends HasOneOrMany {
4295
4373
  match(models, results, relation) {
4296
4374
  const dictionary = this.buildDictionary(results);
4297
4375
  for (const model of models) {
4298
- model.setRelation(relation, dictionary.get(String(model.getAttribute(this.localKey)))?.[0] ?? null);
4376
+ model.setRelation(relation, this.applyInverseRelationToModel(dictionary.get(String(model.getAttribute(this.localKey)))?.[0] ?? null, model));
4299
4377
  }
4300
4378
  return models;
4301
4379
  }
@@ -4344,7 +4422,7 @@ function installScopeProxies(cls) {
4344
4422
  for (const key of Object.getOwnPropertyNames(current)) {
4345
4423
  if (!key.startsWith("scope") || key.length <= 5) continue;
4346
4424
  if (typeof Reflect.get(current, key) !== "function") continue;
4347
- const name = Str5.lcfirst(key.slice(5));
4425
+ const name = Str6.lcfirst(key.slice(5));
4348
4426
  if (name in cls) continue;
4349
4427
  Object.defineProperty(cls, name, {
4350
4428
  configurable: true,
@@ -4361,6 +4439,7 @@ function methodOf(model, name) {
4361
4439
  const value = Reflect.get(Object.getPrototypeOf(model), name);
4362
4440
  return typeof value === "function" ? value : void 0;
4363
4441
  }
4442
+ var serializing = /* @__PURE__ */ new WeakSet();
4364
4443
  function serializeDate(date) {
4365
4444
  return date.toISOString().replace(/\.(\d{3})Z$/, ".$1000Z");
4366
4445
  }
@@ -4816,7 +4895,7 @@ var Model = class _Model {
4816
4895
  /** Every cast, including the implied ones: the incrementing key (int) and the timestamp columns (datetime). */
4817
4896
  getCasts() {
4818
4897
  const implied = {};
4819
- if (this.incrementing) implied[this.getKeyName()] = this.keyType === "int" ? "int" : "string";
4898
+ if (this.getIncrementing()) implied[this.getKeyName()] = this.getKeyType() === "int" ? "int" : "string";
4820
4899
  if (this.usesTimestamps()) {
4821
4900
  const created = this.getCreatedAtColumn();
4822
4901
  const updated = this.getUpdatedAtColumn();
@@ -4927,7 +5006,7 @@ var Model = class _Model {
4927
5006
  }
4928
5007
  }
4929
5008
  mutatorFor(kind, key) {
4930
- return methodOf(this, `${kind}${Str5.studly(key)}Attribute`);
5009
+ return methodOf(this, `${kind}${Str6.studly(key)}Attribute`);
4931
5010
  }
4932
5011
  // ---------------------------------------------------------------- keys, table and naming
4933
5012
  getKeyName() {
@@ -4939,11 +5018,34 @@ var Model = class _Model {
4939
5018
  getIncrementing() {
4940
5019
  return this.incrementing;
4941
5020
  }
5021
+ /** Whether new rows get unique string ids before `creating` (HasUuids, HasUlids). */
5022
+ usesUniqueIds() {
5023
+ return false;
5024
+ }
5025
+ /** The columns that get a unique id (HasUuids and HasUlids: the primary key). */
5026
+ uniqueIds() {
5027
+ return [];
5028
+ }
5029
+ /** A new unique id (HasUuids: a version 7 UUID; HasUlids: a lower-case ULID). */
5030
+ newUniqueId() {
5031
+ return void 0;
5032
+ }
5033
+ /** Whether a value has the shape of this model's unique ids (HasUuids: a UUID). Any value passes by default. */
5034
+ isValidUniqueId(_value) {
5035
+ return true;
5036
+ }
5037
+ /** Fills each empty unique id column with newUniqueId() (Laravel's setUniqueIds()). */
5038
+ setUniqueIds() {
5039
+ for (const column of this.uniqueIds()) {
5040
+ const value = this.getAttribute(column);
5041
+ if (value === void 0 || value === null || value === "") this.setAttribute(column, this.newUniqueId());
5042
+ }
5043
+ }
4942
5044
  getKey() {
4943
5045
  return this.getAttribute(this.getKeyName());
4944
5046
  }
4945
5047
  getTable() {
4946
- return this.table ?? Str5.snake(Str5.plural(this.constructor.name));
5048
+ return this.table ?? Str6.snake(Str6.plural(this.constructor.name));
4947
5049
  }
4948
5050
  getConnectionName() {
4949
5051
  return this.connection;
@@ -4960,7 +5062,7 @@ var Model = class _Model {
4960
5062
  }
4961
5063
  /** The conventional foreign key pointing at this model: user_id for User. */
4962
5064
  getForeignKey() {
4963
- return `${Str5.snake(this.constructor.name)}_${this.getKeyName()}`;
5065
+ return `${Str6.snake(this.constructor.name)}_${this.getKeyName()}`;
4964
5066
  }
4965
5067
  getRouteKeyName() {
4966
5068
  return this.getKeyName();
@@ -4970,11 +5072,13 @@ var Model = class _Model {
4970
5072
  }
4971
5073
  /**
4972
5074
  * The model a route parameter value points at: where <field or route key> = value (global scopes apply, so a
4973
- * soft-deleted row isn't found). A non-numeric value for an integer primary key finds nothing without a query.
5075
+ * soft-deleted row isn't found). A non-numeric value for an integer primary key, or a value that isn't a UUID
5076
+ * (ULID) for a unique id column, finds nothing without a query.
4974
5077
  */
4975
5078
  async resolveRouteBinding(value, field) {
4976
5079
  const column = field ?? this.getRouteKeyName();
4977
- if (column === this.getKeyName() && this.keyType === "int" && !/^-?\d+$/.test(value)) return void 0;
5080
+ if (column === this.getKeyName() && this.getKeyType() === "int" && !/^-?\d+$/.test(value)) return void 0;
5081
+ if (this.uniqueIds().includes(column) && !this.isValidUniqueId(value)) return void 0;
4978
5082
  return this.resolveRouteBindingQuery(this.newQuery(), value, column).first();
4979
5083
  }
4980
5084
  /** Override to customize the binding query (Laravel's resolveRouteBindingQuery()). */
@@ -5192,6 +5296,7 @@ var Model = class _Model {
5192
5296
  if (!this.exists && created && !this.isDirty(created)) this.setAttribute(created, time);
5193
5297
  }
5194
5298
  async performInsert(query) {
5299
+ if (this.usesUniqueIds()) this.setUniqueIds();
5195
5300
  if (await this.fireModelEvent("creating") === false) return false;
5196
5301
  if (this.usesTimestamps()) this.updateTimestamps();
5197
5302
  const attributes = this.getAttributes();
@@ -5307,7 +5412,7 @@ var Model = class _Model {
5307
5412
  */
5308
5413
  belongsToMany(related, table, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
5309
5414
  const instance = this.newRelatedInstance(related);
5310
- const joining = table ?? [Str5.snake(this.constructor.name), Str5.snake(related.name)].sort().join("_").toLowerCase();
5415
+ const joining = table ?? [Str6.snake(this.constructor.name), Str6.snake(related.name)].sort().join("_").toLowerCase();
5311
5416
  const relation = new BelongsToMany(
5312
5417
  instance,
5313
5418
  this,
@@ -5375,6 +5480,10 @@ var Model = class _Model {
5375
5480
  if (!instance.getConnectionName()) instance.setConnection(this.getConnectionName());
5376
5481
  return instance;
5377
5482
  }
5483
+ /** Whether the model has a relation method called `name` (Laravel's isRelation()). */
5484
+ isRelation(name) {
5485
+ return !(name in _Model.prototype) && methodOf(this, name) !== void 0;
5486
+ }
5378
5487
  /** Calls the relation method `name` (post.comments()) and checks that it returns a relation. */
5379
5488
  getRelationInstance(name) {
5380
5489
  if (name in _Model.prototype) throw new RelationNotFoundError(this.constructor.name, name);
@@ -5469,9 +5578,18 @@ var Model = class _Model {
5469
5578
  this.appends = [.../* @__PURE__ */ new Set([...this.appends, ...attributes.flat()])];
5470
5579
  return this;
5471
5580
  }
5472
- /** Attributes (through accessors and casts, dates as ISO strings), appends and loaded relations, minus hidden ones. */
5581
+ /**
5582
+ * Attributes (through accessors and casts, dates as ISO strings), appends and loaded relations, minus hidden ones.
5583
+ * A model met again while its own toArray() runs (a child chaperone() pointed back at it) gives its attributes only.
5584
+ */
5473
5585
  toArray() {
5474
- return { ...this.attributesToArray(), ...this.relationsToArray() };
5586
+ if (serializing.has(this)) return this.attributesToArray();
5587
+ serializing.add(this);
5588
+ try {
5589
+ return { ...this.attributesToArray(), ...this.relationsToArray() };
5590
+ } finally {
5591
+ serializing.delete(this);
5592
+ }
5475
5593
  }
5476
5594
  toJSON() {
5477
5595
  return this.toArray();
@@ -5494,7 +5612,7 @@ var Model = class _Model {
5494
5612
  relationsToArray() {
5495
5613
  const result = {};
5496
5614
  for (const [name, value] of Object.entries(this.relations)) {
5497
- const key = Str5.snake(name);
5615
+ const key = Str6.snake(name);
5498
5616
  if (!this.isArrayableKey(key)) continue;
5499
5617
  if (value === null || value === void 0) result[key] = null;
5500
5618
  else if (value instanceof Collection11) result[key] = value.toArray();
@@ -5545,7 +5663,40 @@ var Pivot = class extends Model {
5545
5663
 
5546
5664
  // Eloquent/DatabaseNotification.ts
5547
5665
  import { Collection as Collection12 } from "@orieljs/collections";
5548
- var DatabaseNotification = class extends Model {
5666
+
5667
+ // Eloquent/HasUniqueStringIds.ts
5668
+ import { Str as Str7 } from "@orieljs/support";
5669
+ function uniqueStringIds(Base, generate, valid) {
5670
+ return class WithUniqueStringIds extends Base {
5671
+ usesUniqueIds() {
5672
+ return true;
5673
+ }
5674
+ uniqueIds() {
5675
+ return [this.getKeyName()];
5676
+ }
5677
+ newUniqueId() {
5678
+ return generate();
5679
+ }
5680
+ isValidUniqueId(value) {
5681
+ return valid(value);
5682
+ }
5683
+ getKeyType() {
5684
+ return this.uniqueIds().includes(this.getKeyName()) ? "string" : super.getKeyType();
5685
+ }
5686
+ getIncrementing() {
5687
+ return this.uniqueIds().includes(this.getKeyName()) ? false : super.getIncrementing();
5688
+ }
5689
+ };
5690
+ }
5691
+ function HasUuids(Base) {
5692
+ return uniqueStringIds(Base, () => Str7.uuid7(), Str7.isUuid);
5693
+ }
5694
+ function HasUlids(Base) {
5695
+ return uniqueStringIds(Base, () => Str7.ulid().toLowerCase(), Str7.isUlid);
5696
+ }
5697
+
5698
+ // Eloquent/DatabaseNotification.ts
5699
+ var DatabaseNotification = class extends HasUuids(Model) {
5549
5700
  table = "notifications";
5550
5701
  keyType = "string";
5551
5702
  incrementing = false;
@@ -5643,7 +5794,7 @@ var Migration = class {
5643
5794
  // Migrations/MigrationCreator.ts
5644
5795
  import { existsSync as existsSync2, mkdirSync, writeFileSync } from "fs";
5645
5796
  import { join as join4 } from "path";
5646
- import { Str as Str6 } from "@orieljs/support";
5797
+ import { Str as Str8 } from "@orieljs/support";
5647
5798
  var MIGRATION_CREATE_STUB = `import { Migration, Schema } from '{{ importSource }}'
5648
5799
 
5649
5800
  export default class extends Migration {
@@ -5701,7 +5852,7 @@ function migrationDatePrefix(date = /* @__PURE__ */ new Date()) {
5701
5852
  var MigrationCreator = class {
5702
5853
  /** Returns the path of the new file. */
5703
5854
  create(name, path, options = {}) {
5704
- const snake = Str6.snake(name.trim());
5855
+ const snake = Str8.snake(name.trim());
5705
5856
  let table = options.table ?? options.create;
5706
5857
  let create = options.create !== void 0;
5707
5858
  if (table === void 0) {
@@ -5950,7 +6101,7 @@ import { pathToFileURL as pathToFileURL3 } from "url";
5950
6101
  // Types/TypeGenerator.ts
5951
6102
  import { mkdir, writeFile } from "fs/promises";
5952
6103
  import { dirname, relative, sep } from "path";
5953
- import { Str as Str7 } from "@orieljs/support";
6104
+ import { Str as Str9 } from "@orieljs/support";
5954
6105
  var INTEGER = /* @__PURE__ */ new Set(["int", "integer", "int2", "int4", "int8", "bigint", "smallint", "mediumint", "tinyint", "serial", "bigserial", "smallserial", "year"]);
5955
6106
  var FLOAT = /* @__PURE__ */ new Set(["float", "float4", "float8", "double", "double precision", "real"]);
5956
6107
  var BOOLEAN = /* @__PURE__ */ new Set(["bool", "boolean"]);
@@ -5985,7 +6136,7 @@ function accessors(model) {
5985
6136
  for (let proto = model.prototype; proto && proto !== Model.prototype; proto = Object.getPrototypeOf(proto)) {
5986
6137
  for (const key of Object.getOwnPropertyNames(proto)) {
5987
6138
  const match = /^get(.+)Attribute$/.exec(key);
5988
- if (match && typeof Reflect.get(proto, key) === "function" && !found.has(Str7.snake(match[1]))) found.set(Str7.snake(match[1]), key);
6139
+ if (match && typeof Reflect.get(proto, key) === "function" && !found.has(Str9.snake(match[1]))) found.set(Str9.snake(match[1]), key);
5989
6140
  }
5990
6141
  }
5991
6142
  return [...found];
@@ -5995,7 +6146,7 @@ function scopes(model) {
5995
6146
  for (let current = model; current && current !== Model; current = Object.getPrototypeOf(current)) {
5996
6147
  for (const key of Object.getOwnPropertyNames(current)) {
5997
6148
  if (key.startsWith("scope") && key.length > 5 && typeof Reflect.get(current, key) === "function") {
5998
- const name = Str7.lcfirst(key.slice(5));
6149
+ const name = Str9.lcfirst(key.slice(5));
5999
6150
  if (!found.has(name)) found.set(name, key);
6000
6151
  }
6001
6152
  }
@@ -6108,6 +6259,11 @@ async function generateModelTypes(context) {
6108
6259
  await new TypeGenerator({ outputFile, importSource: context.typesImportSource }).write((await context.models()).all());
6109
6260
  return relative2(context.app.basePath(), outputFile);
6110
6261
  }
6262
+ async function writeModelTypes(context, command) {
6263
+ if (context.app.isProduction() || !existsSync4(context.app.basePath("types"))) return;
6264
+ const written = await generateModelTypes(context);
6265
+ if (written) command.line(`Model types written to ${written}.`);
6266
+ }
6111
6267
  async function seedIfRequested(context, command) {
6112
6268
  const seeder = text(command.option("seeder"));
6113
6269
  if (command.option("seed") !== true && seeder === void 0) return;
@@ -6119,10 +6275,7 @@ function registerMigrationCommands(kernel, context) {
6119
6275
  if (!confirmToProceed(context, command)) return 1;
6120
6276
  await migrator(context, command).run(migrationPaths(context, command), { step: command.option("step") === true });
6121
6277
  await seedIfRequested(context, command);
6122
- if (!context.app.isProduction() && existsSync4(context.app.basePath("types"))) {
6123
- const written = await generateModelTypes(context);
6124
- if (written) command.line(`Model types written to ${written}.`);
6125
- }
6278
+ await writeModelTypes(context, command);
6126
6279
  return 0;
6127
6280
  });
6128
6281
  define(kernel, "migrate:install {--database=}", "Create the migration repository", async (command) => {
@@ -6153,12 +6306,14 @@ function registerMigrationCommands(kernel, context) {
6153
6306
  else await instance.reset(paths);
6154
6307
  await instance.run(paths);
6155
6308
  await seedIfRequested(context, command);
6309
+ await writeModelTypes(context, command);
6156
6310
  return 0;
6157
6311
  });
6158
6312
  define(kernel, "migrate:fresh {--database=} {--force} {--path=*} {--seed} {--seeder=}", "Drop all tables and re-run all migrations", async (command) => {
6159
6313
  if (!confirmToProceed(context, command)) return 1;
6160
6314
  await migrator(context, command).fresh(migrationPaths(context, command));
6161
6315
  await seedIfRequested(context, command);
6316
+ await writeModelTypes(context, command);
6162
6317
  return 0;
6163
6318
  });
6164
6319
  define(kernel, "migrate:status {--database=} {--path=*}", "Show the status of each migration", async (command) => {
@@ -6213,7 +6368,7 @@ function registerModelTypesCommand(kernel, context) {
6213
6368
  import { existsSync as existsSync5, readdirSync as readdirSync3, statSync } from "fs";
6214
6369
  import { join as join7 } from "path";
6215
6370
  import { pathToFileURL as pathToFileURL4 } from "url";
6216
- import { Str as Str8 } from "@orieljs/support";
6371
+ import { Str as Str10 } from "@orieljs/support";
6217
6372
  var MODEL_FILE = /^(?!.*\.d\.[mc]?ts$).+\.(ts|js|mts|mjs)$/;
6218
6373
  var ModelRegistry = class {
6219
6374
  models = /* @__PURE__ */ new Map();
@@ -6239,7 +6394,7 @@ var ModelRegistry = class {
6239
6394
  }
6240
6395
  /** A model by class name or route parameter name: 'Post', 'post', 'blog_post' and 'blogPost' find BlogPost. */
6241
6396
  get(name) {
6242
- return this.models.get(name) ?? this.models.get(Str8.studly(name));
6397
+ return this.models.get(name) ?? this.models.get(Str10.studly(name));
6243
6398
  }
6244
6399
  resolve(name) {
6245
6400
  return this.get(name)?.model;
@@ -6777,6 +6932,8 @@ export {
6777
6932
  HasManyThrough,
6778
6933
  HasOne,
6779
6934
  HasOneOrMany,
6935
+ HasUlids,
6936
+ HasUuids,
6780
6937
  InvalidCastError,
6781
6938
  JoinClause,
6782
6939
  LengthAwarePaginator,