metal-orm 1.0.105 → 1.0.107

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.cjs CHANGED
@@ -5261,8 +5261,18 @@ var hideInternal = (obj, keys) => {
5261
5261
  Object.defineProperty(obj, key, {
5262
5262
  value: obj[key],
5263
5263
  writable: false,
5264
+ configurable: false,
5265
+ enumerable: false
5266
+ });
5267
+ }
5268
+ };
5269
+ var hideWritable = (obj, keys) => {
5270
+ for (const key of keys) {
5271
+ const value = obj[key];
5272
+ Object.defineProperty(obj, key, {
5273
+ value,
5274
+ writable: true,
5264
5275
  configurable: true,
5265
- // Must be configurable for Proxy get trap to work properly
5266
5276
  enumerable: false
5267
5277
  });
5268
5278
  }
@@ -5291,43 +5301,44 @@ var DefaultHasManyCollection = class {
5291
5301
  this.createEntity = createEntity;
5292
5302
  this.localKey = localKey;
5293
5303
  hideInternal(this, ["ctx", "meta", "root", "relationName", "relation", "rootTable", "loader", "createEntity", "localKey"]);
5304
+ hideWritable(this, ["loaded", "items", "added", "removed"]);
5294
5305
  this.hydrateFromCache();
5295
5306
  }
5296
- #loaded = false;
5297
- #items = [];
5298
- #added = /* @__PURE__ */ new Set();
5299
- #removed = /* @__PURE__ */ new Set();
5307
+ loaded = false;
5308
+ items = [];
5309
+ added = /* @__PURE__ */ new Set();
5310
+ removed = /* @__PURE__ */ new Set();
5300
5311
  /**
5301
5312
  * Loads the related entities if not already loaded.
5302
5313
  * @returns Promise resolving to the array of child entities
5303
5314
  */
5304
5315
  async load() {
5305
- if (this.#loaded) return this.#items;
5316
+ if (this.loaded) return this.items;
5306
5317
  const map = await this.loader();
5307
5318
  const key = toKey3(this.root[this.localKey]);
5308
5319
  const rows = map.get(key) ?? [];
5309
- this.#items = rows.map((row) => this.createEntity(row));
5310
- this.#loaded = true;
5311
- return this.#items;
5320
+ this.items = rows.map((row) => this.createEntity(row));
5321
+ this.loaded = true;
5322
+ return this.items;
5312
5323
  }
5313
5324
  /**
5314
5325
  * Gets the current items in the collection.
5315
5326
  * @returns Array of child entities
5316
5327
  */
5317
5328
  getItems() {
5318
- return this.#items;
5329
+ return this.items;
5319
5330
  }
5320
5331
  /**
5321
5332
  * Array-compatible length for testing frameworks.
5322
5333
  */
5323
5334
  get length() {
5324
- return this.#items.length;
5335
+ return this.items.length;
5325
5336
  }
5326
5337
  /**
5327
5338
  * Enables iteration over the collection like an array.
5328
5339
  */
5329
5340
  [Symbol.iterator]() {
5330
- return this.#items[Symbol.iterator]();
5341
+ return this.items[Symbol.iterator]();
5331
5342
  }
5332
5343
  /**
5333
5344
  * Adds a new child entity to the collection.
@@ -5341,8 +5352,8 @@ var DefaultHasManyCollection = class {
5341
5352
  [this.relation.foreignKey]: keyValue
5342
5353
  };
5343
5354
  const entity = this.createEntity(childRow);
5344
- this.#added.add(entity);
5345
- this.#items.push(entity);
5355
+ this.added.add(entity);
5356
+ this.items.push(entity);
5346
5357
  this.ctx.registerRelationChange(
5347
5358
  this.root,
5348
5359
  this.relationKey,
@@ -5361,7 +5372,7 @@ var DefaultHasManyCollection = class {
5361
5372
  const keyValue = this.root[this.localKey];
5362
5373
  entity[this.relation.foreignKey] = keyValue;
5363
5374
  this.ctx.markDirty(entity);
5364
- this.#items.push(entity);
5375
+ this.items.push(entity);
5365
5376
  this.ctx.registerRelationChange(
5366
5377
  this.root,
5367
5378
  this.relationKey,
@@ -5376,8 +5387,8 @@ var DefaultHasManyCollection = class {
5376
5387
  * @param entity - The entity to remove
5377
5388
  */
5378
5389
  remove(entity) {
5379
- this.#items = this.#items.filter((item) => item !== entity);
5380
- this.#removed.add(entity);
5390
+ this.items = this.items.filter((item) => item !== entity);
5391
+ this.removed.add(entity);
5381
5392
  this.ctx.registerRelationChange(
5382
5393
  this.root,
5383
5394
  this.relationKey,
@@ -5391,13 +5402,10 @@ var DefaultHasManyCollection = class {
5391
5402
  * Clears all entities from the collection.
5392
5403
  */
5393
5404
  clear() {
5394
- for (const entity of [...this.#items]) {
5405
+ for (const entity of [...this.items]) {
5395
5406
  this.remove(entity);
5396
5407
  }
5397
5408
  }
5398
- isLoaded() {
5399
- return this.#loaded;
5400
- }
5401
5409
  get relationKey() {
5402
5410
  return `${this.rootTable.name}.${this.relationName}`;
5403
5411
  }
@@ -5406,15 +5414,15 @@ var DefaultHasManyCollection = class {
5406
5414
  if (keyValue === void 0 || keyValue === null) return;
5407
5415
  const rows = getHydrationRows(this.meta, this.relationName, keyValue);
5408
5416
  if (!rows?.length) return;
5409
- this.#items = rows.map((row) => this.createEntity(row));
5410
- this.#loaded = true;
5417
+ this.items = rows.map((row) => this.createEntity(row));
5418
+ this.loaded = true;
5411
5419
  }
5412
5420
  /**
5413
5421
  * Returns the items for JSON serialization.
5414
5422
  * @returns Array of child entities
5415
5423
  */
5416
5424
  toJSON() {
5417
- return this.#items;
5425
+ return this.items;
5418
5426
  }
5419
5427
  };
5420
5428
 
@@ -5425,8 +5433,18 @@ var hideInternal2 = (obj, keys) => {
5425
5433
  Object.defineProperty(obj, key, {
5426
5434
  value: obj[key],
5427
5435
  writable: false,
5436
+ configurable: false,
5437
+ enumerable: false
5438
+ });
5439
+ }
5440
+ };
5441
+ var hideWritable2 = (obj, keys) => {
5442
+ for (const key of keys) {
5443
+ const value = obj[key];
5444
+ Object.defineProperty(obj, key, {
5445
+ value,
5446
+ writable: true,
5428
5447
  configurable: true,
5429
- // Must be configurable for Proxy get trap to work properly
5430
5448
  enumerable: false
5431
5449
  });
5432
5450
  }
@@ -5464,44 +5482,45 @@ var DefaultHasOneReference = class {
5464
5482
  "createEntity",
5465
5483
  "localKey"
5466
5484
  ]);
5485
+ hideWritable2(this, ["loaded", "current"]);
5467
5486
  this.populateFromHydrationCache();
5468
5487
  }
5469
- #loaded = false;
5470
- #current = null;
5488
+ loaded = false;
5489
+ current = null;
5471
5490
  async load() {
5472
- if (this.#loaded) return this.#current;
5491
+ if (this.loaded) return this.current;
5473
5492
  const map = await this.loader();
5474
5493
  const keyValue = this.root[this.localKey];
5475
5494
  if (keyValue === void 0 || keyValue === null) {
5476
- this.#loaded = true;
5477
- return this.#current;
5495
+ this.loaded = true;
5496
+ return this.current;
5478
5497
  }
5479
5498
  const row = map.get(toKey4(keyValue));
5480
- this.#current = row ? this.createEntity(row) : null;
5481
- this.#loaded = true;
5482
- return this.#current;
5499
+ this.current = row ? this.createEntity(row) : null;
5500
+ this.loaded = true;
5501
+ return this.current;
5483
5502
  }
5484
5503
  get() {
5485
- return this.#current;
5504
+ return this.current;
5486
5505
  }
5487
5506
  set(data) {
5488
5507
  if (data === null) {
5489
5508
  return this.detachCurrent();
5490
5509
  }
5491
5510
  const entity = hasEntityMeta(data) ? data : this.createEntity(data);
5492
- if (this.#current && this.#current !== entity) {
5511
+ if (this.current && this.current !== entity) {
5493
5512
  this.ctx.registerRelationChange(
5494
5513
  this.root,
5495
5514
  this.relationKey,
5496
5515
  this.rootTable,
5497
5516
  this.relationName,
5498
5517
  this.relation,
5499
- { kind: "remove", entity: this.#current }
5518
+ { kind: "remove", entity: this.current }
5500
5519
  );
5501
5520
  }
5502
5521
  this.assignForeignKey(entity);
5503
- this.#current = entity;
5504
- this.#loaded = true;
5522
+ this.current = entity;
5523
+ this.loaded = true;
5505
5524
  this.ctx.registerRelationChange(
5506
5525
  this.root,
5507
5526
  this.relationKey,
@@ -5512,17 +5531,14 @@ var DefaultHasOneReference = class {
5512
5531
  );
5513
5532
  return entity;
5514
5533
  }
5515
- isLoaded() {
5516
- return this.#loaded;
5517
- }
5518
5534
  toJSON() {
5519
- return this.#current;
5535
+ return this.current;
5520
5536
  }
5521
5537
  detachCurrent() {
5522
- const previous = this.#current;
5538
+ const previous = this.current;
5523
5539
  if (!previous) return null;
5524
- this.#current = null;
5525
- this.#loaded = true;
5540
+ this.current = null;
5541
+ this.loaded = true;
5526
5542
  this.ctx.registerRelationChange(
5527
5543
  this.root,
5528
5544
  this.relationKey,
@@ -5545,8 +5561,8 @@ var DefaultHasOneReference = class {
5545
5561
  if (keyValue === void 0 || keyValue === null) return;
5546
5562
  const row = getHydrationRecord(this.meta, this.relationName, keyValue);
5547
5563
  if (!row) return;
5548
- this.#current = this.createEntity(row);
5549
- this.#loaded = true;
5564
+ this.current = this.createEntity(row);
5565
+ this.loaded = true;
5550
5566
  }
5551
5567
  };
5552
5568
 
@@ -5557,8 +5573,18 @@ var hideInternal3 = (obj, keys) => {
5557
5573
  Object.defineProperty(obj, key, {
5558
5574
  value: obj[key],
5559
5575
  writable: false,
5576
+ configurable: false,
5577
+ enumerable: false
5578
+ });
5579
+ }
5580
+ };
5581
+ var hideWritable3 = (obj, keys) => {
5582
+ for (const key of keys) {
5583
+ const value = obj[key];
5584
+ Object.defineProperty(obj, key, {
5585
+ value,
5586
+ writable: true,
5560
5587
  configurable: true,
5561
- // Must be configurable for Proxy get trap to work properly
5562
5588
  enumerable: false
5563
5589
  });
5564
5590
  }
@@ -5586,31 +5612,32 @@ var DefaultBelongsToReference = class {
5586
5612
  this.createEntity = createEntity;
5587
5613
  this.targetKey = targetKey;
5588
5614
  hideInternal3(this, ["ctx", "meta", "root", "relationName", "relation", "rootTable", "loader", "createEntity", "targetKey"]);
5615
+ hideWritable3(this, ["loaded", "current"]);
5589
5616
  this.populateFromHydrationCache();
5590
5617
  }
5591
- #loaded = false;
5592
- #current = null;
5618
+ loaded = false;
5619
+ current = null;
5593
5620
  async load() {
5594
- if (this.#loaded) return this.#current;
5621
+ if (this.loaded) return this.current;
5595
5622
  const map = await this.loader();
5596
5623
  const fkValue = this.root[this.relation.foreignKey];
5597
5624
  if (fkValue === null || fkValue === void 0) {
5598
- this.#current = null;
5625
+ this.current = null;
5599
5626
  } else {
5600
5627
  const row = map.get(toKey5(fkValue));
5601
- this.#current = row ? this.createEntity(row) : null;
5628
+ this.current = row ? this.createEntity(row) : null;
5602
5629
  }
5603
- this.#loaded = true;
5604
- return this.#current;
5630
+ this.loaded = true;
5631
+ return this.current;
5605
5632
  }
5606
5633
  get() {
5607
- return this.#current;
5634
+ return this.current;
5608
5635
  }
5609
5636
  set(data) {
5610
5637
  if (data === null) {
5611
- const previous = this.#current;
5638
+ const previous = this.current;
5612
5639
  this.root[this.relation.foreignKey] = null;
5613
- this.#current = null;
5640
+ this.current = null;
5614
5641
  this.ctx.registerRelationChange(
5615
5642
  this.root,
5616
5643
  this.relationKey,
@@ -5626,7 +5653,7 @@ var DefaultBelongsToReference = class {
5626
5653
  if (pkValue !== void 0) {
5627
5654
  this.root[this.relation.foreignKey] = pkValue;
5628
5655
  }
5629
- this.#current = entity;
5656
+ this.current = entity;
5630
5657
  this.ctx.registerRelationChange(
5631
5658
  this.root,
5632
5659
  this.relationKey,
@@ -5637,9 +5664,6 @@ var DefaultBelongsToReference = class {
5637
5664
  );
5638
5665
  return entity;
5639
5666
  }
5640
- isLoaded() {
5641
- return this.#loaded;
5642
- }
5643
5667
  get relationKey() {
5644
5668
  return `${this.rootTable.name}.${this.relationName}`;
5645
5669
  }
@@ -5648,11 +5672,11 @@ var DefaultBelongsToReference = class {
5648
5672
  if (fkValue === void 0 || fkValue === null) return;
5649
5673
  const row = getHydrationRecord(this.meta, this.relationName, fkValue);
5650
5674
  if (!row) return;
5651
- this.#current = this.createEntity(row);
5652
- this.#loaded = true;
5675
+ this.current = this.createEntity(row);
5676
+ this.loaded = true;
5653
5677
  }
5654
5678
  toJSON() {
5655
- return this.#current;
5679
+ return this.current;
5656
5680
  }
5657
5681
  };
5658
5682
 
@@ -5663,8 +5687,18 @@ var hideInternal4 = (obj, keys) => {
5663
5687
  Object.defineProperty(obj, key, {
5664
5688
  value: obj[key],
5665
5689
  writable: false,
5690
+ configurable: false,
5691
+ enumerable: false
5692
+ });
5693
+ }
5694
+ };
5695
+ var hideWritable4 = (obj, keys) => {
5696
+ for (const key of keys) {
5697
+ const value = obj[key];
5698
+ Object.defineProperty(obj, key, {
5699
+ value,
5700
+ writable: true,
5666
5701
  configurable: true,
5667
- // Must be configurable for Proxy get trap to work properly
5668
5702
  enumerable: false
5669
5703
  });
5670
5704
  }
@@ -5692,47 +5726,48 @@ var DefaultManyToManyCollection = class {
5692
5726
  this.createEntity = createEntity;
5693
5727
  this.localKey = localKey;
5694
5728
  hideInternal4(this, ["ctx", "meta", "root", "relationName", "relation", "rootTable", "loader", "createEntity", "localKey"]);
5729
+ hideWritable4(this, ["loaded", "items"]);
5695
5730
  this.hydrateFromCache();
5696
5731
  }
5697
- #loaded = false;
5698
- #items = [];
5732
+ loaded = false;
5733
+ items = [];
5699
5734
  /**
5700
5735
  * Loads the collection items if not already loaded.
5701
5736
  * @returns A promise that resolves to the array of target entities.
5702
5737
  */
5703
5738
  async load() {
5704
- if (this.#loaded) return this.#items;
5739
+ if (this.loaded) return this.items;
5705
5740
  const map = await this.loader();
5706
5741
  const key = toKey6(this.root[this.localKey]);
5707
5742
  const rows = map.get(key) ?? [];
5708
- this.#items = rows.map((row) => {
5743
+ this.items = rows.map((row) => {
5709
5744
  const entity = this.createEntity(row);
5710
5745
  if (row._pivot) {
5711
5746
  entity._pivot = row._pivot;
5712
5747
  }
5713
5748
  return entity;
5714
5749
  });
5715
- this.#loaded = true;
5716
- return this.#items;
5750
+ this.loaded = true;
5751
+ return this.items;
5717
5752
  }
5718
5753
  /**
5719
5754
  * Returns the currently loaded items.
5720
5755
  * @returns Array of target entities.
5721
5756
  */
5722
5757
  getItems() {
5723
- return this.#items;
5758
+ return this.items;
5724
5759
  }
5725
5760
  /**
5726
5761
  * Array-compatible length for testing frameworks.
5727
5762
  */
5728
5763
  get length() {
5729
- return this.#items.length;
5764
+ return this.items.length;
5730
5765
  }
5731
5766
  /**
5732
5767
  * Enables iteration over the collection like an array.
5733
5768
  */
5734
5769
  [Symbol.iterator]() {
5735
- return this.#items[Symbol.iterator]();
5770
+ return this.items[Symbol.iterator]();
5736
5771
  }
5737
5772
  /**
5738
5773
  * Attaches an entity to the collection.
@@ -5742,13 +5777,13 @@ var DefaultManyToManyCollection = class {
5742
5777
  attach(target) {
5743
5778
  const entity = this.ensureEntity(target);
5744
5779
  const id = this.extractId(entity);
5745
- if (id != null && this.#items.some((item) => this.extractId(item) === id)) {
5780
+ if (id != null && this.items.some((item) => this.extractId(item) === id)) {
5746
5781
  return;
5747
5782
  }
5748
- if (id == null && this.#items.includes(entity)) {
5783
+ if (id == null && this.items.includes(entity)) {
5749
5784
  return;
5750
5785
  }
5751
- this.#items.push(entity);
5786
+ this.items.push(entity);
5752
5787
  this.ctx.registerRelationChange(
5753
5788
  this.root,
5754
5789
  this.relationKey,
@@ -5766,9 +5801,9 @@ var DefaultManyToManyCollection = class {
5766
5801
  detach(target) {
5767
5802
  const id = typeof target === "number" || typeof target === "string" ? target : this.extractId(target);
5768
5803
  if (id == null) return;
5769
- const existing = this.#items.find((item) => this.extractId(item) === id);
5804
+ const existing = this.items.find((item) => this.extractId(item) === id);
5770
5805
  if (!existing) return;
5771
- this.#items = this.#items.filter((item) => this.extractId(item) !== id);
5806
+ this.items = this.items.filter((item) => this.extractId(item) !== id);
5772
5807
  this.ctx.registerRelationChange(
5773
5808
  this.root,
5774
5809
  this.relationKey,
@@ -5786,22 +5821,19 @@ var DefaultManyToManyCollection = class {
5786
5821
  async syncByIds(ids) {
5787
5822
  await this.load();
5788
5823
  const normalized = new Set(ids.map((id) => toKey6(id)));
5789
- const currentIds = new Set(this.#items.map((item) => toKey6(this.extractId(item))));
5824
+ const currentIds = new Set(this.items.map((item) => toKey6(this.extractId(item))));
5790
5825
  for (const id of normalized) {
5791
5826
  if (!currentIds.has(id)) {
5792
5827
  this.attach(id);
5793
5828
  }
5794
5829
  }
5795
- for (const item of [...this.#items]) {
5830
+ for (const item of [...this.items]) {
5796
5831
  const itemId = toKey6(this.extractId(item));
5797
5832
  if (!normalized.has(itemId)) {
5798
5833
  this.detach(item);
5799
5834
  }
5800
5835
  }
5801
5836
  }
5802
- isLoaded() {
5803
- return this.#loaded;
5804
- }
5805
5837
  ensureEntity(target) {
5806
5838
  if (typeof target === "number" || typeof target === "string") {
5807
5839
  const stub = {
@@ -5829,17 +5861,17 @@ var DefaultManyToManyCollection = class {
5829
5861
  if (keyValue === void 0 || keyValue === null) return;
5830
5862
  const rows = getHydrationRows(this.meta, this.relationName, keyValue);
5831
5863
  if (!rows?.length) return;
5832
- this.#items = rows.map((row) => {
5864
+ this.items = rows.map((row) => {
5833
5865
  const entity = this.createEntity(row);
5834
5866
  if (row._pivot) {
5835
5867
  entity._pivot = row._pivot;
5836
5868
  }
5837
5869
  return entity;
5838
5870
  });
5839
- this.#loaded = true;
5871
+ this.loaded = true;
5840
5872
  }
5841
5873
  toJSON() {
5842
- return this.#items;
5874
+ return this.items;
5843
5875
  }
5844
5876
  };
5845
5877
 
@@ -6181,31 +6213,12 @@ var relationLoaderCache = (meta, relationName, factory) => {
6181
6213
  // src/orm/entity-relations.ts
6182
6214
  var proxifyRelationWrapper = (wrapper) => {
6183
6215
  return new Proxy(wrapper, {
6184
- get(target, prop, _receiver) {
6185
- if (prop === "toJSON") {
6186
- return () => {
6187
- const wrapperToJSON = target.toJSON;
6188
- if (typeof wrapperToJSON === "function") {
6189
- return wrapperToJSON.call(target);
6190
- }
6191
- const getRef2 = target.get;
6192
- if (typeof getRef2 === "function") {
6193
- return getRef2.call(target);
6194
- }
6195
- const getItems2 = target.getItems;
6196
- if (typeof getItems2 === "function") {
6197
- return getItems2.call(target);
6198
- }
6199
- return target;
6200
- };
6201
- }
6216
+ get(target, prop, receiver) {
6202
6217
  if (typeof prop === "symbol") {
6203
- const value = Reflect.get(target, prop, target);
6204
- return typeof value === "function" ? value.bind(target) : value;
6218
+ return Reflect.get(target, prop, receiver);
6205
6219
  }
6206
6220
  if (prop in target) {
6207
- const value = Reflect.get(target, prop, target);
6208
- return typeof value === "function" ? value.bind(target) : value;
6221
+ return Reflect.get(target, prop, receiver);
6209
6222
  }
6210
6223
  const getItems = target.getItems;
6211
6224
  if (typeof getItems === "function") {
@@ -6227,12 +6240,12 @@ var proxifyRelationWrapper = (wrapper) => {
6227
6240
  }
6228
6241
  return void 0;
6229
6242
  },
6230
- set(target, prop, value, _receiver) {
6243
+ set(target, prop, value, receiver) {
6231
6244
  if (typeof prop === "symbol") {
6232
- return Reflect.set(target, prop, value, target);
6245
+ return Reflect.set(target, prop, value, receiver);
6233
6246
  }
6234
6247
  if (prop in target) {
6235
- return Reflect.set(target, prop, value, target);
6248
+ return Reflect.set(target, prop, value, receiver);
6236
6249
  }
6237
6250
  const getRef = target.get;
6238
6251
  if (typeof getRef === "function") {
@@ -6246,7 +6259,7 @@ var proxifyRelationWrapper = (wrapper) => {
6246
6259
  const items = getItems.call(target);
6247
6260
  return Reflect.set(items, prop, value);
6248
6261
  }
6249
- return Reflect.set(target, prop, value, target);
6262
+ return Reflect.set(target, prop, value, receiver);
6250
6263
  }
6251
6264
  });
6252
6265
  };
@@ -6348,15 +6361,7 @@ var instantiateWrapper = (meta, relationName, relation, owner, createEntity) =>
6348
6361
  // src/orm/entity.ts
6349
6362
  var isRelationWrapperLoaded = (value) => {
6350
6363
  if (!value || typeof value !== "object") return false;
6351
- const wrapper = value;
6352
- if (typeof wrapper.isLoaded === "function") return wrapper.isLoaded();
6353
- return false;
6354
- };
6355
- var unwrapRelationForJson = (value) => {
6356
- if (value && typeof value === "object" && typeof value.toJSON === "function") {
6357
- return value.toJSON();
6358
- }
6359
- return value;
6364
+ return Boolean(value.loaded);
6360
6365
  };
6361
6366
  var createEntityProxy = (ctx, table, row, lazyRelations = [], lazyRelationOptions = /* @__PURE__ */ new Map()) => {
6362
6367
  const target = { ...row };
@@ -6373,13 +6378,14 @@ var createEntityProxy = (ctx, table, row, lazyRelations = [], lazyRelationOption
6373
6378
  const buildJson = (self) => {
6374
6379
  const json = {};
6375
6380
  for (const key of Object.keys(target)) {
6376
- const value = self[key];
6377
- json[key] = unwrapRelationForJson(value);
6378
- }
6379
- for (const [relationName, wrapper] of meta.relationWrappers) {
6380
- if (Object.prototype.hasOwnProperty.call(json, relationName)) continue;
6381
- if (isRelationWrapperLoaded(wrapper)) {
6382
- json[relationName] = unwrapRelationForJson(wrapper);
6381
+ if (table.relations[key]) continue;
6382
+ json[key] = self[key];
6383
+ }
6384
+ for (const relationName of Object.keys(table.relations)) {
6385
+ const wrapper = self[relationName];
6386
+ if (wrapper && isRelationWrapperLoaded(wrapper)) {
6387
+ const wrapperWithToJSON = wrapper;
6388
+ json[relationName] = typeof wrapperWithToJSON.toJSON === "function" ? wrapperWithToJSON.toJSON() : wrapper;
6383
6389
  }
6384
6390
  }
6385
6391
  return json;