@punks/backend-entity-manager 0.0.254 → 0.0.256
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/cjs/index.js +53 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/commands.d.ts +10 -0
- package/dist/cjs/types/abstractions/index.d.ts +1 -1
- package/dist/cjs/types/commands/upsertBy.d.ts +8 -0
- package/dist/cjs/types/concrete/index.d.ts +2 -1
- package/dist/cjs/types/platforms/nest/__test__/server/entities/foos/connectors/custom/connector.d.ts +12 -0
- package/dist/cjs/types/platforms/nest/__test__/server/entities/foos/connectors/custom/mapper.d.ts +6 -0
- package/dist/cjs/types/platforms/nest/__test__/server/entities/foos/connectors/custom/model.d.ts +4 -0
- package/dist/cjs/types/platforms/nest/__test__/server/entities/foos/connectors/index.d.ts +3 -0
- package/dist/cjs/types/platforms/nest/__test__/tests/connectors/entity-connectors.test.d.ts +1 -0
- package/dist/cjs/types/providers/services.d.ts +4 -1
- package/dist/cjs/types/symbols/ioc.d.ts +1 -0
- package/dist/esm/index.js +53 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/commands.d.ts +10 -0
- package/dist/esm/types/abstractions/index.d.ts +1 -1
- package/dist/esm/types/commands/upsertBy.d.ts +8 -0
- package/dist/esm/types/concrete/index.d.ts +2 -1
- package/dist/esm/types/platforms/nest/__test__/server/entities/foos/connectors/custom/connector.d.ts +12 -0
- package/dist/esm/types/platforms/nest/__test__/server/entities/foos/connectors/custom/mapper.d.ts +6 -0
- package/dist/esm/types/platforms/nest/__test__/server/entities/foos/connectors/custom/model.d.ts +4 -0
- package/dist/esm/types/platforms/nest/__test__/server/entities/foos/connectors/index.d.ts +3 -0
- package/dist/esm/types/platforms/nest/__test__/tests/connectors/entity-connectors.test.d.ts +1 -0
- package/dist/esm/types/providers/services.d.ts +4 -1
- package/dist/esm/types/symbols/ioc.d.ts +1 -0
- package/dist/index.d.ts +14 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1006,6 +1006,36 @@ class EntityUpsertCommand {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
}
|
|
1008
1008
|
|
|
1009
|
+
class EntitiesUpsertByCommand {
|
|
1010
|
+
constructor(services) {
|
|
1011
|
+
this.services = services;
|
|
1012
|
+
}
|
|
1013
|
+
async execute(params) {
|
|
1014
|
+
const { items } = await this.services.resolveSearchQuery().execute({
|
|
1015
|
+
filters: params.filter,
|
|
1016
|
+
});
|
|
1017
|
+
if (items.length === 0) {
|
|
1018
|
+
const createdItem = await this.services
|
|
1019
|
+
.resolveCreateCommand()
|
|
1020
|
+
.execute(params.data);
|
|
1021
|
+
// todo: parametrize id field
|
|
1022
|
+
const id = createdItem.id;
|
|
1023
|
+
return {
|
|
1024
|
+
id,
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
if (items.length > 1) {
|
|
1028
|
+
throw new Error("Multiple items found");
|
|
1029
|
+
}
|
|
1030
|
+
// todo: parametrize id field
|
|
1031
|
+
const id = items[0].id;
|
|
1032
|
+
await this.services.resolveUpdateCommand().execute(id, params.data);
|
|
1033
|
+
return {
|
|
1034
|
+
id,
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1009
1039
|
class EntityVersionCommand {
|
|
1010
1040
|
constructor(services) {
|
|
1011
1041
|
this.services = services;
|
|
@@ -1063,6 +1093,9 @@ class EntityManager {
|
|
|
1063
1093
|
get upsert() {
|
|
1064
1094
|
return this.services.resolveUpsertCommand();
|
|
1065
1095
|
}
|
|
1096
|
+
get upsertBy() {
|
|
1097
|
+
return this.services.resolveUpsertByCommand();
|
|
1098
|
+
}
|
|
1066
1099
|
get delete() {
|
|
1067
1100
|
return this.services.resolveDeleteCommand();
|
|
1068
1101
|
}
|
|
@@ -1214,6 +1247,7 @@ const EntityServices = {
|
|
|
1214
1247
|
IEntityCreateCommand: "IEntityCreateCommand",
|
|
1215
1248
|
IEntityUpdateCommand: "IEntityUpdateCommand",
|
|
1216
1249
|
IEntityUpsertCommand: "IEntityUpsertCommand",
|
|
1250
|
+
IEntityUpsertByCommand: "IEntityUpsertByCommand",
|
|
1217
1251
|
IEntityMergeCommand: "IEntityMergeCommand",
|
|
1218
1252
|
IEntityDeleteCommand: "IEntityDeleteCommand",
|
|
1219
1253
|
IEntityVersionCommand: "IEntityVersionCommand",
|
|
@@ -1385,6 +1419,9 @@ class EntityServiceLocator {
|
|
|
1385
1419
|
resolveUpsertCommand() {
|
|
1386
1420
|
return this.services.resolveUpsertCommand(this.entityName);
|
|
1387
1421
|
}
|
|
1422
|
+
resolveUpsertByCommand() {
|
|
1423
|
+
return this.services.resolveUpsertByCommand(this.entityName);
|
|
1424
|
+
}
|
|
1388
1425
|
resolveDeleteCommand() {
|
|
1389
1426
|
return this.services.resolveDeleteCommand(this.entityName);
|
|
1390
1427
|
}
|
|
@@ -1750,6 +1787,12 @@ class EntitiesServiceLocator {
|
|
|
1750
1787
|
registerUpsertCommand(entityName, instance) {
|
|
1751
1788
|
this.provider.registerEntityService(EntityServices.Commands.IEntityUpsertCommand, entityName, instance);
|
|
1752
1789
|
}
|
|
1790
|
+
registerUpsertByCommand(entityName, instance) {
|
|
1791
|
+
this.provider.registerEntityService(EntityServices.Commands.IEntityUpsertByCommand, entityName, instance);
|
|
1792
|
+
}
|
|
1793
|
+
resolveUpsertByCommand(entityName) {
|
|
1794
|
+
return this.provider.resolveEntityService(EntityServices.Commands.IEntityUpsertByCommand, entityName);
|
|
1795
|
+
}
|
|
1753
1796
|
resolveDeleteItemsCommand(entityName) {
|
|
1754
1797
|
return this.provider.resolveEntityService(EntityServices.Commands.IEntitiesDeleteCommand, entityName);
|
|
1755
1798
|
}
|
|
@@ -2376,8 +2419,6 @@ class EntityManagerServiceCollection {
|
|
|
2376
2419
|
constructor(entityName, locator) {
|
|
2377
2420
|
this.entityName = entityName;
|
|
2378
2421
|
this.locator = locator;
|
|
2379
|
-
this.replicas = new ReplicasConfiguration();
|
|
2380
|
-
this.connectors = new ConnectorsConfiguration();
|
|
2381
2422
|
this.resolver = new EntityServiceLocator(locator, entityName);
|
|
2382
2423
|
}
|
|
2383
2424
|
getServiceLocator() {
|
|
@@ -2436,6 +2477,7 @@ class EntityManagerServiceCollection {
|
|
|
2436
2477
|
return this;
|
|
2437
2478
|
}
|
|
2438
2479
|
mapUpdate() {
|
|
2480
|
+
this.locator.registerUpsertByCommand(this.entityName, new EntitiesUpsertByCommand(this.resolver));
|
|
2439
2481
|
this.locator.registerUpsertCommand(this.entityName, new EntityUpsertCommand(this.resolver));
|
|
2440
2482
|
this.locator.registerUpsertAction(this.entityName, new EntityUpsertAction(this.resolver));
|
|
2441
2483
|
this.locator.registerUpdateCommand(this.entityName, new EntityUpdateCommand(this.resolver));
|
|
@@ -2470,11 +2512,15 @@ class EntityManagerServiceCollection {
|
|
|
2470
2512
|
return this;
|
|
2471
2513
|
}
|
|
2472
2514
|
withReplica({ name, options, repository, }) {
|
|
2473
|
-
this.
|
|
2515
|
+
this.resolver
|
|
2516
|
+
.resolveReplicaConfiguration()
|
|
2517
|
+
.configureReplica(name, options, repository);
|
|
2474
2518
|
return this;
|
|
2475
2519
|
}
|
|
2476
2520
|
withSynchronization({ name, options, connector, mapper, }) {
|
|
2477
|
-
this.
|
|
2521
|
+
this.resolver
|
|
2522
|
+
.resolveConnectorsConfiguration()
|
|
2523
|
+
.configureConnector(name, options, connector, mapper);
|
|
2478
2524
|
return this;
|
|
2479
2525
|
}
|
|
2480
2526
|
}
|
|
@@ -4047,8 +4093,9 @@ exports.EntityManagerRegistry = class EntityManagerRegistry {
|
|
|
4047
4093
|
if (!mapper.discoveredClass.injectType) {
|
|
4048
4094
|
throw new Error(`No inject type found for entity connector mapper: ${entityName} - ${connector.meta.connectorName}`);
|
|
4049
4095
|
}
|
|
4050
|
-
const connectorInstance =
|
|
4051
|
-
|
|
4096
|
+
const connectorInstance = connector.discoveredClass
|
|
4097
|
+
.instance;
|
|
4098
|
+
const mapperInstance = mapper.discoveredClass.instance;
|
|
4052
4099
|
registration.withSynchronization({
|
|
4053
4100
|
name: connector.meta.connectorName,
|
|
4054
4101
|
mapper: mapperInstance,
|