metal-orm 1.0.106 → 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 +54 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/orm/entity.ts +155 -151
- package/src/orm/relations/belongs-to.ts +139 -126
- package/src/orm/relations/has-many.ts +199 -186
- package/src/orm/relations/has-one.ts +171 -158
- package/src/orm/relations/many-to-many.ts +237 -224
package/dist/index.cjs
CHANGED
|
@@ -5266,6 +5266,17 @@ var hideInternal = (obj, keys) => {
|
|
|
5266
5266
|
});
|
|
5267
5267
|
}
|
|
5268
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,
|
|
5275
|
+
configurable: true,
|
|
5276
|
+
enumerable: false
|
|
5277
|
+
});
|
|
5278
|
+
}
|
|
5279
|
+
};
|
|
5269
5280
|
var DefaultHasManyCollection = class {
|
|
5270
5281
|
/**
|
|
5271
5282
|
* Creates a new DefaultHasManyCollection instance.
|
|
@@ -5290,6 +5301,7 @@ var DefaultHasManyCollection = class {
|
|
|
5290
5301
|
this.createEntity = createEntity;
|
|
5291
5302
|
this.localKey = localKey;
|
|
5292
5303
|
hideInternal(this, ["ctx", "meta", "root", "relationName", "relation", "rootTable", "loader", "createEntity", "localKey"]);
|
|
5304
|
+
hideWritable(this, ["loaded", "items", "added", "removed"]);
|
|
5293
5305
|
this.hydrateFromCache();
|
|
5294
5306
|
}
|
|
5295
5307
|
loaded = false;
|
|
@@ -5426,6 +5438,17 @@ var hideInternal2 = (obj, keys) => {
|
|
|
5426
5438
|
});
|
|
5427
5439
|
}
|
|
5428
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,
|
|
5447
|
+
configurable: true,
|
|
5448
|
+
enumerable: false
|
|
5449
|
+
});
|
|
5450
|
+
}
|
|
5451
|
+
};
|
|
5429
5452
|
var DefaultHasOneReference = class {
|
|
5430
5453
|
/**
|
|
5431
5454
|
* @param ctx The entity context for tracking changes.
|
|
@@ -5459,6 +5482,7 @@ var DefaultHasOneReference = class {
|
|
|
5459
5482
|
"createEntity",
|
|
5460
5483
|
"localKey"
|
|
5461
5484
|
]);
|
|
5485
|
+
hideWritable2(this, ["loaded", "current"]);
|
|
5462
5486
|
this.populateFromHydrationCache();
|
|
5463
5487
|
}
|
|
5464
5488
|
loaded = false;
|
|
@@ -5554,6 +5578,17 @@ var hideInternal3 = (obj, keys) => {
|
|
|
5554
5578
|
});
|
|
5555
5579
|
}
|
|
5556
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,
|
|
5587
|
+
configurable: true,
|
|
5588
|
+
enumerable: false
|
|
5589
|
+
});
|
|
5590
|
+
}
|
|
5591
|
+
};
|
|
5557
5592
|
var DefaultBelongsToReference = class {
|
|
5558
5593
|
/**
|
|
5559
5594
|
* @param ctx The entity context for tracking changes.
|
|
@@ -5577,6 +5612,7 @@ var DefaultBelongsToReference = class {
|
|
|
5577
5612
|
this.createEntity = createEntity;
|
|
5578
5613
|
this.targetKey = targetKey;
|
|
5579
5614
|
hideInternal3(this, ["ctx", "meta", "root", "relationName", "relation", "rootTable", "loader", "createEntity", "targetKey"]);
|
|
5615
|
+
hideWritable3(this, ["loaded", "current"]);
|
|
5580
5616
|
this.populateFromHydrationCache();
|
|
5581
5617
|
}
|
|
5582
5618
|
loaded = false;
|
|
@@ -5656,6 +5692,17 @@ var hideInternal4 = (obj, keys) => {
|
|
|
5656
5692
|
});
|
|
5657
5693
|
}
|
|
5658
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,
|
|
5701
|
+
configurable: true,
|
|
5702
|
+
enumerable: false
|
|
5703
|
+
});
|
|
5704
|
+
}
|
|
5705
|
+
};
|
|
5659
5706
|
var DefaultManyToManyCollection = class {
|
|
5660
5707
|
/**
|
|
5661
5708
|
* @param ctx The entity context for tracking changes.
|
|
@@ -5679,6 +5726,7 @@ var DefaultManyToManyCollection = class {
|
|
|
5679
5726
|
this.createEntity = createEntity;
|
|
5680
5727
|
this.localKey = localKey;
|
|
5681
5728
|
hideInternal4(this, ["ctx", "meta", "root", "relationName", "relation", "rootTable", "loader", "createEntity", "localKey"]);
|
|
5729
|
+
hideWritable4(this, ["loaded", "items"]);
|
|
5682
5730
|
this.hydrateFromCache();
|
|
5683
5731
|
}
|
|
5684
5732
|
loaded = false;
|
|
@@ -6330,12 +6378,14 @@ var createEntityProxy = (ctx, table, row, lazyRelations = [], lazyRelationOption
|
|
|
6330
6378
|
const buildJson = (self) => {
|
|
6331
6379
|
const json = {};
|
|
6332
6380
|
for (const key of Object.keys(target)) {
|
|
6381
|
+
if (table.relations[key]) continue;
|
|
6333
6382
|
json[key] = self[key];
|
|
6334
6383
|
}
|
|
6335
|
-
for (const
|
|
6336
|
-
|
|
6337
|
-
if (isRelationWrapperLoaded(wrapper)) {
|
|
6338
|
-
|
|
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;
|
|
6339
6389
|
}
|
|
6340
6390
|
}
|
|
6341
6391
|
return json;
|