@punks/backend-entity-manager 0.0.255 → 0.0.257
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 +44 -0
- 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/abstractions/manager.d.ts +2 -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/providers/services.d.ts +4 -1
- package/dist/cjs/types/symbols/ioc.d.ts +1 -0
- package/dist/esm/index.js +44 -0
- 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/abstractions/manager.d.ts +2 -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/providers/services.d.ts +4 -1
- package/dist/esm/types/symbols/ioc.d.ts +1 -0
- package/dist/index.d.ts +15 -1
- package/package.json +1 -1
|
@@ -43,3 +43,13 @@ export interface IEntitiesImportCommand<TEntity> {
|
|
|
43
43
|
export interface IEntitiesSampleDownloadCommand<TEntity> {
|
|
44
44
|
execute(input: EntitiesSampleDownloadOptions): Promise<EntitiesSampleDownloadResult>;
|
|
45
45
|
}
|
|
46
|
+
export interface IEntityUpsertByParameters<TEntity, TEntityFilters extends ISearchFilters> {
|
|
47
|
+
filter: TEntityFilters;
|
|
48
|
+
data: Partial<Omit<TEntity, "id">>;
|
|
49
|
+
}
|
|
50
|
+
export interface IEntityUpsertByResult {
|
|
51
|
+
id: string;
|
|
52
|
+
}
|
|
53
|
+
export interface IEntityUpsertByCommand<TEntity, TEntityFilters extends ISearchFilters> {
|
|
54
|
+
execute(params: IEntityUpsertByParameters<TEntity, TEntityFilters>): Promise<IEntityUpsertByResult>;
|
|
55
|
+
}
|
|
@@ -5,7 +5,7 @@ export * from "./authentication";
|
|
|
5
5
|
export * from "./buckets";
|
|
6
6
|
export * from "./cache";
|
|
7
7
|
export { IAuthorizationResult, IEntityAuthorizationMiddleware, } from "./authorization";
|
|
8
|
-
export { IEntityCreateCommand, IEntityUpdateCommand, IEntityUpsertCommand, IEntityDeleteCommand, IEntityVersionCommand, IEntitiesImportCommand, IEntitiesExportCommand, IEntitiesDeleteParameters, IEntitiesDeleteCommand, IEntitiesDeleteResult, IEntitiesSampleDownloadCommand, } from "./commands";
|
|
8
|
+
export { IEntityCreateCommand, IEntityUpdateCommand, IEntityUpsertCommand, IEntityDeleteCommand, IEntityVersionCommand, IEntitiesImportCommand, IEntitiesExportCommand, IEntitiesDeleteParameters, IEntitiesDeleteCommand, IEntitiesDeleteResult, IEntitiesSampleDownloadCommand, IEntityUpsertByParameters as IEntitiesUpsertByParameters, IEntityUpsertByResult as IEntitiesUpsertByResult, IEntityUpsertByCommand as IEntitiesUpsertByCommand, } from "./commands";
|
|
9
9
|
export { SortingType, ClassType, EnumType } from "./common";
|
|
10
10
|
export { IEntityManagerServiceRoot, IEntityManagerServiceCollection, } from "./configuration";
|
|
11
11
|
export { ConnectorMode, ConnectorOptions, IEntityConnector } from "./connectors";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IEntitiesDeleteCommand, IEntitiesDeleteParameters, IEntitiesExportCommand, IEntitiesImportCommand, IEntitiesSampleDownloadCommand, IEntityCreateCommand, IEntityDeleteCommand, IEntityUpdateCommand, IEntityUpsertCommand, IEntityVersionCommand } from "./commands";
|
|
1
|
+
import { IEntitiesDeleteCommand, IEntitiesDeleteParameters, IEntitiesExportCommand, IEntitiesImportCommand, IEntitiesSampleDownloadCommand, IEntityCreateCommand, IEntityDeleteCommand, IEntityUpdateCommand, IEntityUpsertByCommand, IEntityUpsertCommand, IEntityVersionCommand } from "./commands";
|
|
2
2
|
import { SortingType } from "./common";
|
|
3
3
|
import { IEntitiesCountQuery, IEntitiesFindQuery, IEntitiesSearchQuery, IEntityExistsQuery, IEntityGetQuery, IEntityVersionsSearchQuery } from "./queries";
|
|
4
4
|
import { IEntitySearchParameters } from "./searchParameters";
|
|
@@ -13,6 +13,7 @@ export interface IEntityManager<TEntity, TEntityId, TEntityCreateData, TEntityUp
|
|
|
13
13
|
get create(): IEntityCreateCommand<TEntity, TEntityId, TEntityCreateData>;
|
|
14
14
|
get update(): IEntityUpdateCommand<TEntity, TEntityId, TEntityUpdateData>;
|
|
15
15
|
get upsert(): IEntityUpsertCommand<TEntity, TEntityId, TEntityUpdateData>;
|
|
16
|
+
get upsertBy(): IEntityUpsertByCommand<TEntity, TEntitySearchParameters>;
|
|
16
17
|
get delete(): IEntityDeleteCommand<TEntity, TEntityId>;
|
|
17
18
|
get deleteItems(): IEntitiesDeleteCommand<TEntity, TEntitiesDeleteParameters, TSorting>;
|
|
18
19
|
get import(): IEntitiesImportCommand<TEntity>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ISearchFilters } from "../abstractions";
|
|
2
|
+
import { IEntityUpsertByCommand, IEntityUpsertByParameters, IEntityUpsertByResult } from "../abstractions/commands";
|
|
3
|
+
import { EntityServiceLocator } from "../providers/services";
|
|
4
|
+
export declare class EntitiesUpsertByCommand<TEntity, TEntityFilters extends ISearchFilters> implements IEntityUpsertByCommand<TEntity, TEntityFilters> {
|
|
5
|
+
private readonly services;
|
|
6
|
+
constructor(services: EntityServiceLocator<TEntity, unknown>);
|
|
7
|
+
execute(params: IEntityUpsertByParameters<TEntity, TEntityFilters>): Promise<IEntityUpsertByResult>;
|
|
8
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IEntitiesCountAction, IEntitiesDeleteAction, IEntitiesExportAction, IEntitiesImportAction, IEntitiesSampleDownloadAction, IEntitiesSearchAction, IEntityActions, IEntityCreateAction, IEntityDeleteAction, IEntityExistsAction, IEntityGetAction, IEntityUpdateAction, IEntityUpsertAction, IEntityVersionsSearchAction } from "../abstractions/actions";
|
|
2
|
-
import { IEntitiesDeleteCommand, IEntitiesDeleteParameters, IEntitiesExportCommand, IEntitiesImportCommand, IEntitiesSampleDownloadCommand, IEntityCreateCommand, IEntityDeleteCommand, IEntityUpdateCommand, IEntityUpsertCommand, IEntityVersionCommand } from "../abstractions/commands";
|
|
2
|
+
import { IEntitiesDeleteCommand, IEntitiesDeleteParameters, IEntitiesExportCommand, IEntitiesImportCommand, IEntitiesSampleDownloadCommand, IEntityUpsertByCommand, IEntityCreateCommand, IEntityDeleteCommand, IEntityUpdateCommand, IEntityUpsertCommand, IEntityVersionCommand } from "../abstractions/commands";
|
|
3
3
|
import { SortingType } from "../abstractions/common";
|
|
4
4
|
import { IEntityManager } from "../abstractions/manager";
|
|
5
5
|
import { IEntitiesCountQuery, IEntitiesFindQuery, IEntitiesSearchQuery, IEntityExistsQuery, IEntityGetQuery, IEntityVersionsSearchQuery } from "../abstractions/queries";
|
|
@@ -19,6 +19,7 @@ export declare class EntityManager<TEntity, TEntityId, TEntityCreateData, TEntit
|
|
|
19
19
|
get create(): IEntityCreateCommand<TEntity, TEntityId, TEntityCreateData>;
|
|
20
20
|
get update(): IEntityUpdateCommand<TEntity, TEntityId, TEntityUpdateData>;
|
|
21
21
|
get upsert(): IEntityUpsertCommand<TEntity, TEntityId, TEntityUpdateData>;
|
|
22
|
+
get upsertBy(): IEntityUpsertByCommand<TEntity, TEntitySearchParameters>;
|
|
22
23
|
get delete(): IEntityDeleteCommand<TEntity, TEntityId>;
|
|
23
24
|
get export(): IEntitiesExportCommand<TEntity, TEntitySearchParameters, TSorting, TCursor>;
|
|
24
25
|
get import(): IEntitiesImportCommand<TEntity>;
|
|
@@ -2,7 +2,7 @@ import { IAuthenticationContext, IAuthenticationContextProvider, IAuthentication
|
|
|
2
2
|
import { IEntitiesCountAction, IEntitiesDeleteAction, IEntitiesExportAction, IEntitiesImportAction, IEntitiesSampleDownloadAction, IEntitiesSearchAction, IEntityActions, IEntityCreateAction, IEntityDeleteAction, IEntityExistsAction, IEntityGetAction, IEntityUpdateAction, IEntityUpsertAction, IEntityVersionsSearchAction } from "../abstractions/actions";
|
|
3
3
|
import { IEntityAdapter } from "../abstractions/adapters";
|
|
4
4
|
import { IEntityAuthorizationMiddleware } from "../abstractions/authorization";
|
|
5
|
-
import { IEntitiesDeleteCommand, IEntitiesDeleteParameters, IEntitiesExportCommand, IEntitiesImportCommand, IEntitiesSampleDownloadCommand, IEntityCreateCommand, IEntityDeleteCommand, IEntityUpdateCommand, IEntityUpsertCommand, IEntityVersionCommand } from "../abstractions/commands";
|
|
5
|
+
import { IEntitiesDeleteCommand, IEntitiesDeleteParameters, IEntitiesExportCommand, IEntitiesImportCommand, IEntitiesSampleDownloadCommand, IEntityUpsertByCommand, IEntityCreateCommand, IEntityDeleteCommand, IEntityUpdateCommand, IEntityUpsertCommand, IEntityVersionCommand } from "../abstractions/commands";
|
|
6
6
|
import { SortingType } from "../abstractions/common";
|
|
7
7
|
import { IConnectorsConfiguration, IEntityConnectorDeleteManager, IEntityConnectorSyncManager } from "../abstractions/connectors";
|
|
8
8
|
import { IEntityConverter } from "../abstractions/converters";
|
|
@@ -47,6 +47,7 @@ export declare class EntityServiceLocator<TEntity, TEntityId> {
|
|
|
47
47
|
resolveCreateCommand<TEntityCreateData>(): IEntityCreateCommand<TEntity, TEntityId, TEntityCreateData>;
|
|
48
48
|
resolveUpdateCommand<TEntityUpdateData>(): IEntityUpdateCommand<TEntity, TEntityId, TEntityUpdateData>;
|
|
49
49
|
resolveUpsertCommand<TEntityUpdateData>(): IEntityUpsertCommand<TEntity, TEntityId, TEntityUpdateData>;
|
|
50
|
+
resolveUpsertByCommand<TEntitySearchParameters extends IEntitySearchParameters<TEntity, unknown, unknown>>(): IEntityUpsertByCommand<TEntity, TEntitySearchParameters>;
|
|
50
51
|
resolveDeleteCommand<TEntityId>(): IEntityDeleteCommand<TEntity, TEntityId>;
|
|
51
52
|
resolveDeleteItemsCommand<TEntitiesDeleteParameters extends IEntitiesDeleteParameters<TSorting>, TSorting>(): IEntitiesDeleteCommand<TEntity, TEntitiesDeleteParameters, TSorting>;
|
|
52
53
|
resolveVersionCommand(): IEntityVersionCommand<TEntity, TEntityId>;
|
|
@@ -163,6 +164,8 @@ export declare class EntitiesServiceLocator {
|
|
|
163
164
|
registerUpdateCommand<TEntity, TEntityId, TEntityUpdateData>(entityName: string, instance: IEntityUpdateCommand<TEntity, TEntityId, TEntityUpdateData>): void;
|
|
164
165
|
resolveUpsertCommand<TEntity, TEntityId, TEntityUpdateData>(entityName: string): IEntityUpsertCommand<TEntity, TEntityId, TEntityUpdateData>;
|
|
165
166
|
registerUpsertCommand<TEntity, TEntityId, TEntityUpdateData>(entityName: string, instance: IEntityUpsertCommand<TEntity, TEntityId, TEntityUpdateData>): void;
|
|
167
|
+
registerUpsertByCommand<TEntity, TEntitySearchParameters extends IEntitySearchParameters<TEntity, unknown, unknown>>(entityName: string, instance: IEntityUpsertByCommand<TEntity, TEntitySearchParameters>): void;
|
|
168
|
+
resolveUpsertByCommand<TEntity, TEntitySearchParameters extends IEntitySearchParameters<TEntity, unknown, unknown>>(entityName: string): IEntityUpsertByCommand<TEntity, TEntitySearchParameters>;
|
|
166
169
|
resolveDeleteItemsCommand<TEntity, TEntitiesDeleteParameters extends IEntitiesDeleteParameters<TSorting>, TSorting>(entityName: string): IEntitiesDeleteCommand<TEntity, TEntitiesDeleteParameters, TSorting>;
|
|
167
170
|
registerDeleteItemsCommand<TEntity, TEntitiesDeleteParameters extends IEntitiesDeleteParameters<TSorting>, TSorting>(entityName: string, instance: IEntitiesDeleteCommand<TEntity, TEntitiesDeleteParameters, TSorting>): void;
|
|
168
171
|
resolveDeleteCommand<TEntity, TEntityId>(entityName: string): IEntityDeleteCommand<TEntity, TEntityId>;
|
|
@@ -22,6 +22,7 @@ export declare const EntityServices: {
|
|
|
22
22
|
IEntityCreateCommand: string;
|
|
23
23
|
IEntityUpdateCommand: string;
|
|
24
24
|
IEntityUpsertCommand: string;
|
|
25
|
+
IEntityUpsertByCommand: string;
|
|
25
26
|
IEntityMergeCommand: string;
|
|
26
27
|
IEntityDeleteCommand: string;
|
|
27
28
|
IEntityVersionCommand: string;
|
package/dist/esm/index.js
CHANGED
|
@@ -992,6 +992,36 @@ class EntityUpsertCommand {
|
|
|
992
992
|
}
|
|
993
993
|
}
|
|
994
994
|
|
|
995
|
+
class EntitiesUpsertByCommand {
|
|
996
|
+
constructor(services) {
|
|
997
|
+
this.services = services;
|
|
998
|
+
}
|
|
999
|
+
async execute(params) {
|
|
1000
|
+
const { items } = await this.services.resolveSearchQuery().execute({
|
|
1001
|
+
filters: params.filter,
|
|
1002
|
+
});
|
|
1003
|
+
if (items.length === 0) {
|
|
1004
|
+
const createdItem = await this.services
|
|
1005
|
+
.resolveCreateCommand()
|
|
1006
|
+
.execute(params.data);
|
|
1007
|
+
// todo: parametrize id field
|
|
1008
|
+
const id = createdItem.id;
|
|
1009
|
+
return {
|
|
1010
|
+
id,
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
if (items.length > 1) {
|
|
1014
|
+
throw new Error("Multiple items found");
|
|
1015
|
+
}
|
|
1016
|
+
// todo: parametrize id field
|
|
1017
|
+
const id = items[0].id;
|
|
1018
|
+
await this.services.resolveUpdateCommand().execute(id, params.data);
|
|
1019
|
+
return {
|
|
1020
|
+
id,
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
995
1025
|
class EntityVersionCommand {
|
|
996
1026
|
constructor(services) {
|
|
997
1027
|
this.services = services;
|
|
@@ -1049,6 +1079,9 @@ class EntityManager {
|
|
|
1049
1079
|
get upsert() {
|
|
1050
1080
|
return this.services.resolveUpsertCommand();
|
|
1051
1081
|
}
|
|
1082
|
+
get upsertBy() {
|
|
1083
|
+
return this.services.resolveUpsertByCommand();
|
|
1084
|
+
}
|
|
1052
1085
|
get delete() {
|
|
1053
1086
|
return this.services.resolveDeleteCommand();
|
|
1054
1087
|
}
|
|
@@ -1200,6 +1233,7 @@ const EntityServices = {
|
|
|
1200
1233
|
IEntityCreateCommand: "IEntityCreateCommand",
|
|
1201
1234
|
IEntityUpdateCommand: "IEntityUpdateCommand",
|
|
1202
1235
|
IEntityUpsertCommand: "IEntityUpsertCommand",
|
|
1236
|
+
IEntityUpsertByCommand: "IEntityUpsertByCommand",
|
|
1203
1237
|
IEntityMergeCommand: "IEntityMergeCommand",
|
|
1204
1238
|
IEntityDeleteCommand: "IEntityDeleteCommand",
|
|
1205
1239
|
IEntityVersionCommand: "IEntityVersionCommand",
|
|
@@ -1371,6 +1405,9 @@ class EntityServiceLocator {
|
|
|
1371
1405
|
resolveUpsertCommand() {
|
|
1372
1406
|
return this.services.resolveUpsertCommand(this.entityName);
|
|
1373
1407
|
}
|
|
1408
|
+
resolveUpsertByCommand() {
|
|
1409
|
+
return this.services.resolveUpsertByCommand(this.entityName);
|
|
1410
|
+
}
|
|
1374
1411
|
resolveDeleteCommand() {
|
|
1375
1412
|
return this.services.resolveDeleteCommand(this.entityName);
|
|
1376
1413
|
}
|
|
@@ -1736,6 +1773,12 @@ class EntitiesServiceLocator {
|
|
|
1736
1773
|
registerUpsertCommand(entityName, instance) {
|
|
1737
1774
|
this.provider.registerEntityService(EntityServices.Commands.IEntityUpsertCommand, entityName, instance);
|
|
1738
1775
|
}
|
|
1776
|
+
registerUpsertByCommand(entityName, instance) {
|
|
1777
|
+
this.provider.registerEntityService(EntityServices.Commands.IEntityUpsertByCommand, entityName, instance);
|
|
1778
|
+
}
|
|
1779
|
+
resolveUpsertByCommand(entityName) {
|
|
1780
|
+
return this.provider.resolveEntityService(EntityServices.Commands.IEntityUpsertByCommand, entityName);
|
|
1781
|
+
}
|
|
1739
1782
|
resolveDeleteItemsCommand(entityName) {
|
|
1740
1783
|
return this.provider.resolveEntityService(EntityServices.Commands.IEntitiesDeleteCommand, entityName);
|
|
1741
1784
|
}
|
|
@@ -2420,6 +2463,7 @@ class EntityManagerServiceCollection {
|
|
|
2420
2463
|
return this;
|
|
2421
2464
|
}
|
|
2422
2465
|
mapUpdate() {
|
|
2466
|
+
this.locator.registerUpsertByCommand(this.entityName, new EntitiesUpsertByCommand(this.resolver));
|
|
2423
2467
|
this.locator.registerUpsertCommand(this.entityName, new EntityUpsertCommand(this.resolver));
|
|
2424
2468
|
this.locator.registerUpsertAction(this.entityName, new EntityUpsertAction(this.resolver));
|
|
2425
2469
|
this.locator.registerUpdateCommand(this.entityName, new EntityUpdateCommand(this.resolver));
|