@punks/backend-entity-manager 0.0.131 → 0.0.133
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 +72 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/__test__/entity/foo.d.ts +5 -1
- package/dist/cjs/types/abstractions/errors.d.ts +2 -1
- package/dist/cjs/types/abstractions/queries.d.ts +10 -0
- package/dist/cjs/types/concrete/index.d.ts +2 -1
- package/dist/cjs/types/integrations/repository/typeorm/queryBuilder.d.ts +4 -0
- package/dist/cjs/types/providers/services.d.ts +4 -1
- package/dist/cjs/types/queries/find.d.ts +12 -0
- package/dist/cjs/types/symbols/ioc.d.ts +1 -0
- package/dist/cjs/types/templates/queryBuilder/index.d.ts +4 -0
- package/dist/esm/index.js +72 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/__test__/entity/foo.d.ts +5 -1
- package/dist/esm/types/abstractions/errors.d.ts +2 -1
- package/dist/esm/types/abstractions/queries.d.ts +10 -0
- package/dist/esm/types/concrete/index.d.ts +2 -1
- package/dist/esm/types/integrations/repository/typeorm/queryBuilder.d.ts +4 -0
- package/dist/esm/types/providers/services.d.ts +4 -1
- package/dist/esm/types/queries/find.d.ts +12 -0
- package/dist/esm/types/symbols/ioc.d.ts +1 -0
- package/dist/esm/types/templates/queryBuilder/index.d.ts +4 -0
- package/dist/index.d.ts +23 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.EntityOperationType = void 0;
|
|
|
43
43
|
EntityOperationType[EntityOperationType["Delete"] = 2] = "Delete";
|
|
44
44
|
EntityOperationType[EntityOperationType["Read"] = 3] = "Read";
|
|
45
45
|
EntityOperationType[EntityOperationType["Search"] = 4] = "Search";
|
|
46
|
+
EntityOperationType[EntityOperationType["Find"] = 5] = "Find";
|
|
46
47
|
})(exports.EntityOperationType || (exports.EntityOperationType = {}));
|
|
47
48
|
class EntityManagerUnauthorizedException extends EntityManagerException {
|
|
48
49
|
constructor(message) {
|
|
@@ -919,6 +920,9 @@ class EntityManager {
|
|
|
919
920
|
get search() {
|
|
920
921
|
return this.services.resolveSearchQuery();
|
|
921
922
|
}
|
|
923
|
+
get find() {
|
|
924
|
+
return this.services.resolveFindQuery();
|
|
925
|
+
}
|
|
922
926
|
get create() {
|
|
923
927
|
return this.services.resolveCreateCommand();
|
|
924
928
|
}
|
|
@@ -1103,6 +1107,7 @@ const EntityServices = {
|
|
|
1103
1107
|
IEntityCountQuery: "IEntityCountQuery",
|
|
1104
1108
|
IEntityExistsQuery: "IEntityExistsQuery",
|
|
1105
1109
|
IEntityGetQuery: "IEntityGetQuery",
|
|
1110
|
+
IEntitiesFindQuery: "IEntitiesFindQuery",
|
|
1106
1111
|
IEntitiesSearchQuery: "IEntitiesSearchQuery",
|
|
1107
1112
|
IEntitiesQueryBuilder: "IEntitiesQueryBuilder",
|
|
1108
1113
|
IEntityVersionsSearchQuery: "IEntityVersionsSearchQuery",
|
|
@@ -1225,6 +1230,9 @@ class EntityServiceLocator {
|
|
|
1225
1230
|
resolveSearchQuery() {
|
|
1226
1231
|
return this.services.resolveSearchQuery(this.entityName);
|
|
1227
1232
|
}
|
|
1233
|
+
resolveFindQuery() {
|
|
1234
|
+
return this.services.resolveFindQuery(this.entityName);
|
|
1235
|
+
}
|
|
1228
1236
|
resolveCreateCommand() {
|
|
1229
1237
|
return this.services.resolveCreateCommand(this.entityName);
|
|
1230
1238
|
}
|
|
@@ -1491,6 +1499,12 @@ class EntitiesServiceLocator {
|
|
|
1491
1499
|
registerSearchQuery(entityName, instance) {
|
|
1492
1500
|
this.provider.registerEntityService(EntityServices.Queries.IEntitiesSearchQuery, entityName, instance);
|
|
1493
1501
|
}
|
|
1502
|
+
resolveFindQuery(entityName) {
|
|
1503
|
+
return this.provider.resolveEntityService(EntityServices.Queries.IEntitiesSearchQuery, entityName);
|
|
1504
|
+
}
|
|
1505
|
+
registerFindQuery(entityName, instance) {
|
|
1506
|
+
this.provider.registerEntityService(EntityServices.Queries.IEntitiesFindQuery, entityName, instance);
|
|
1507
|
+
}
|
|
1494
1508
|
resolveExistsQuery(entityName) {
|
|
1495
1509
|
return this.provider.resolveEntityService(EntityServices.Queries.IEntityExistsQuery, entityName);
|
|
1496
1510
|
}
|
|
@@ -1705,6 +1719,53 @@ class EntityExistsQuery {
|
|
|
1705
1719
|
}
|
|
1706
1720
|
}
|
|
1707
1721
|
|
|
1722
|
+
class EntitiesFindQuery {
|
|
1723
|
+
constructor(services) {
|
|
1724
|
+
this.services = services;
|
|
1725
|
+
}
|
|
1726
|
+
async execute(request) {
|
|
1727
|
+
const context = await this.getContext();
|
|
1728
|
+
await this.authorizeSearch(context);
|
|
1729
|
+
const result = await this.services
|
|
1730
|
+
.resolveQueryBuilder()
|
|
1731
|
+
.find(request, context);
|
|
1732
|
+
const filteredEntities = await this.filterAllowedEntities([result], context);
|
|
1733
|
+
return filteredEntities[0];
|
|
1734
|
+
}
|
|
1735
|
+
async getContext() {
|
|
1736
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
1737
|
+
if (!authorization) {
|
|
1738
|
+
return undefined;
|
|
1739
|
+
}
|
|
1740
|
+
const contextService = this.services.resolveAuthenticationContextProvider();
|
|
1741
|
+
return await contextService?.getContext();
|
|
1742
|
+
}
|
|
1743
|
+
async filterAllowedEntities(entities, context) {
|
|
1744
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
1745
|
+
if (!authorization) {
|
|
1746
|
+
return entities;
|
|
1747
|
+
}
|
|
1748
|
+
const filteredEntities = await Promise.all(entities.map(async (entity) => {
|
|
1749
|
+
const authorizationResult = await authorization.canRead(entity, context);
|
|
1750
|
+
if (!authorizationResult.isAuthorized) {
|
|
1751
|
+
return null;
|
|
1752
|
+
}
|
|
1753
|
+
return entity;
|
|
1754
|
+
}));
|
|
1755
|
+
return filteredEntities.filter((entity) => entity !== null);
|
|
1756
|
+
}
|
|
1757
|
+
async authorizeSearch(context) {
|
|
1758
|
+
const authorization = this.services.resolveAuthorizationMiddleware();
|
|
1759
|
+
if (!authorization) {
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
const { isAuthorized } = await authorization.canSearch(context);
|
|
1763
|
+
if (!isAuthorized) {
|
|
1764
|
+
throw new EntityOperationUnauthorizedException(exports.EntityOperationType.Find, this.services.getEntityName());
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1708
1769
|
class EntityGetQuery {
|
|
1709
1770
|
constructor(services) {
|
|
1710
1771
|
this.services = services;
|
|
@@ -2104,6 +2165,7 @@ class EntityManagerServiceCollection {
|
|
|
2104
2165
|
return this;
|
|
2105
2166
|
}
|
|
2106
2167
|
mapSearch({ queryBuilder, }) {
|
|
2168
|
+
this.locator.registerFindQuery(this.entityName, new EntitiesFindQuery(this.resolver));
|
|
2107
2169
|
this.locator.registerSearchQuery(this.entityName, new EntitiesSearchQuery(this.resolver));
|
|
2108
2170
|
this.locator.registerSearchAction(this.entityName, new EntitiesSearchAction(this.resolver));
|
|
2109
2171
|
this.locator.registerQueryBuilder(this.entityName, queryBuilder);
|
|
@@ -22063,6 +22125,16 @@ class TypeOrmQueryBuilder extends QueryBuilderBase {
|
|
|
22063
22125
|
...this.buildWhereClause(request),
|
|
22064
22126
|
});
|
|
22065
22127
|
}
|
|
22128
|
+
async find(request, context) {
|
|
22129
|
+
const results = await this.findPagedQueryResults({
|
|
22130
|
+
filters: request.filters,
|
|
22131
|
+
sorting: request.sorting,
|
|
22132
|
+
paging: {
|
|
22133
|
+
pageSize: 1,
|
|
22134
|
+
},
|
|
22135
|
+
}, context);
|
|
22136
|
+
return results[0];
|
|
22137
|
+
}
|
|
22066
22138
|
async search(request, context) {
|
|
22067
22139
|
// todo: execute inside read transaction in order to perform the three queries on the same dataset
|
|
22068
22140
|
const queryResults = await this.countQueryResults(request, context);
|