@declaro/data 2.0.0-beta.120 → 2.0.0-beta.125
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/browser/index.js +14 -14
- package/dist/browser/index.js.map +11 -11
- package/dist/node/index.cjs +163 -45
- package/dist/node/index.cjs.map +11 -11
- package/dist/node/index.js +163 -45
- package/dist/node/index.js.map +11 -11
- package/dist/ts/application/model-controller.d.ts +22 -1
- package/dist/ts/application/model-controller.d.ts.map +1 -1
- package/dist/ts/domain/events/domain-event.d.ts +1 -1
- package/dist/ts/domain/events/domain-event.d.ts.map +1 -1
- package/dist/ts/domain/events/event-types.d.ts +10 -1
- package/dist/ts/domain/events/event-types.d.ts.map +1 -1
- package/dist/ts/domain/events/mutation-event.d.ts +5 -2
- package/dist/ts/domain/events/mutation-event.d.ts.map +1 -1
- package/dist/ts/domain/events/query-event.d.ts +4 -2
- package/dist/ts/domain/events/query-event.d.ts.map +1 -1
- package/dist/ts/domain/events/request-event.d.ts +17 -2
- package/dist/ts/domain/events/request-event.d.ts.map +1 -1
- package/dist/ts/domain/interfaces/repository.d.ts +26 -0
- package/dist/ts/domain/interfaces/repository.d.ts.map +1 -1
- package/dist/ts/domain/services/model-service.d.ts +19 -1
- package/dist/ts/domain/services/model-service.d.ts.map +1 -1
- package/dist/ts/domain/services/read-only-model-service.d.ts +19 -0
- package/dist/ts/domain/services/read-only-model-service.d.ts.map +1 -1
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts +21 -3
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts.map +1 -1
- package/dist/ts/test/mock/repositories/mock-memory-repository.trash.test.d.ts +2 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.trash.test.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/application/model-controller.test.ts +191 -0
- package/src/application/model-controller.ts +44 -1
- package/src/domain/events/domain-event.ts +1 -1
- package/src/domain/events/event-types.ts +9 -0
- package/src/domain/events/mutation-event.test.ts +369 -17
- package/src/domain/events/mutation-event.ts +10 -2
- package/src/domain/events/query-event.test.ts +218 -18
- package/src/domain/events/query-event.ts +8 -2
- package/src/domain/events/request-event.test.ts +1 -1
- package/src/domain/events/request-event.ts +22 -7
- package/src/domain/interfaces/repository.ts +29 -0
- package/src/domain/services/model-service.normalization.test.ts +6 -6
- package/src/domain/services/model-service.test.ts +311 -7
- package/src/domain/services/model-service.ts +88 -1
- package/src/domain/services/read-only-model-service.test.ts +396 -0
- package/src/domain/services/read-only-model-service.ts +23 -3
- package/src/test/mock/repositories/mock-memory-repository.trash.test.ts +736 -0
- package/src/test/mock/repositories/mock-memory-repository.ts +146 -46
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AuthValidator } from '@declaro/auth';
|
|
2
2
|
import { type AnyModelSchema } from '@declaro/core';
|
|
3
3
|
import type { ModelService, ICreateOptions, IUpdateOptions } from '../domain/services/model-service';
|
|
4
|
-
import type { InferDetail, InferInput, InferLookup, InferSummary } from '../shared/utils/schema-inference';
|
|
4
|
+
import type { InferDetail, InferFilters, InferInput, InferLookup, InferSummary } from '../shared/utils/schema-inference';
|
|
5
5
|
import { ReadOnlyModelController } from './read-only-model-controller';
|
|
6
6
|
export declare class ModelController<TSchema extends AnyModelSchema> extends ReadOnlyModelController<TSchema> {
|
|
7
7
|
protected readonly service: ModelService<TSchema>;
|
|
@@ -25,5 +25,26 @@ export declare class ModelController<TSchema extends AnyModelSchema> extends Rea
|
|
|
25
25
|
* @returns Array of upserted records.
|
|
26
26
|
*/
|
|
27
27
|
bulkUpsert(inputs: InferInput<TSchema>[], options?: ICreateOptions | IUpdateOptions): Promise<InferDetail<TSchema>[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Permanently deletes a specific entity from the trash.
|
|
30
|
+
* Requires 'permanently-delete-from-trash', 'permanently-delete', or 'empty-trash' permission.
|
|
31
|
+
* @param lookup The lookup object containing entity identifiers
|
|
32
|
+
* @returns The permanently deleted entity summary
|
|
33
|
+
*/
|
|
34
|
+
permanentlyDeleteFromTrash(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
35
|
+
/**
|
|
36
|
+
* Permanently deletes an entity without moving it to trash first.
|
|
37
|
+
* Requires 'permanently-delete' permission.
|
|
38
|
+
* @param lookup The lookup object containing entity identifiers
|
|
39
|
+
* @returns The permanently deleted entity summary
|
|
40
|
+
*/
|
|
41
|
+
permanentlyDelete(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
42
|
+
/**
|
|
43
|
+
* Empties the trash by permanently deleting entities that have been marked as removed.
|
|
44
|
+
* Requires 'empty-trash' permission.
|
|
45
|
+
* @param filters Optional filters to apply when selecting entities to delete
|
|
46
|
+
* @returns The count of entities permanently deleted
|
|
47
|
+
*/
|
|
48
|
+
emptyTrash(filters?: InferFilters<TSchema>): Promise<number>;
|
|
28
49
|
}
|
|
29
50
|
//# sourceMappingURL=model-controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-controller.d.ts","sourceRoot":"","sources":["../../../src/application/model-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AACpG,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"model-controller.d.ts","sourceRoot":"","sources":["../../../src/application/model-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAA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AAO,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;CAC3B;AAED,qBAAa,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,CAAE,YAAW,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,CAAC,CAAA;IACR,SAAS,EAAE,IAAI,CAAA;IACf,IAAI,EAAE,MAAM,CAAkB;IAC9B,UAAU,EAAE,gBAAgB,CAAA;IAC5B,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,IAAI,EAAE,CAAC,CAAA;gBAEF,OAAO,GAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAM;IAiBnD,MAAM,IAAI,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC;CAUnC"}
|
|
@@ -20,6 +20,15 @@ export declare enum ModelMutationAction {
|
|
|
20
20
|
AfterRemove = "afterRemove",
|
|
21
21
|
Restore = "restore",
|
|
22
22
|
BeforeRestore = "beforeRestore",
|
|
23
|
-
AfterRestore = "afterRestore"
|
|
23
|
+
AfterRestore = "afterRestore",
|
|
24
|
+
EmptyTrash = "emptyTrash",
|
|
25
|
+
BeforeEmptyTrash = "beforeEmptyTrash",
|
|
26
|
+
AfterEmptyTrash = "afterEmptyTrash",
|
|
27
|
+
PermanentlyDeleteFromTrash = "permanentlyDeleteFromTrash",
|
|
28
|
+
BeforePermanentlyDeleteFromTrash = "beforePermanentlyDeleteFromTrash",
|
|
29
|
+
AfterPermanentlyDeleteFromTrash = "afterPermanentlyDeleteFromTrash",
|
|
30
|
+
PermanentlyDelete = "permanentlyDelete",
|
|
31
|
+
BeforePermanentlyDelete = "beforePermanentlyDelete",
|
|
32
|
+
AfterPermanentlyDelete = "afterPermanentlyDelete"
|
|
24
33
|
}
|
|
25
34
|
//# sourceMappingURL=event-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-types.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/event-types.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACvB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,cAAc,mBAAmB;IACjC,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,UAAU,eAAe;CAC5B;AAED,oBAAY,mBAAmB;IAC3B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;
|
|
1
|
+
{"version":3,"file":"event-types.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/event-types.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACvB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,cAAc,mBAAmB;IACjC,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;IAC3B,UAAU,eAAe;CAC5B;AAED,oBAAY,mBAAmB;IAC3B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,aAAa,kBAAkB;IAC/B,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,gBAAgB,qBAAqB;IACrC,eAAe,oBAAoB;IACnC,0BAA0B,+BAA+B;IACzD,gCAAgC,qCAAqC;IACrE,+BAA+B,oCAAoC;IACnE,iBAAiB,sBAAsB;IACvC,uBAAuB,4BAA4B;IACnD,sBAAsB,2BAA2B;CACpD"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { IActionDescriptorInput } from '@declaro/core';
|
|
2
|
-
import { RequestEvent } from './request-event';
|
|
3
|
-
export
|
|
2
|
+
import { RequestEvent, type IRequestEventMeta } from './request-event';
|
|
3
|
+
export interface IMutationEventMeta<TResult> extends IRequestEventMeta {
|
|
4
|
+
existing?: TResult;
|
|
5
|
+
}
|
|
6
|
+
export declare class MutationEvent<TResult, TInput, TMeta extends IMutationEventMeta<TResult> = IMutationEventMeta<TResult>> extends RequestEvent<TResult, TInput, TMeta> {
|
|
4
7
|
constructor(descriptor: IActionDescriptorInput, input: TInput, meta?: TMeta);
|
|
5
8
|
}
|
|
6
9
|
//# sourceMappingURL=mutation-event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-event.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/mutation-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"mutation-event.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/mutation-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEtE,MAAM,WAAW,kBAAkB,CAAC,OAAO,CAAE,SAAQ,iBAAiB;IAClE,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,qBAAa,aAAa,CACtB,OAAO,EACP,MAAM,EACN,KAAK,SAAS,kBAAkB,CAAC,OAAO,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC,CACzE,SAAQ,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC;gBAC9B,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,KAAmB;CAG3F"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IActionDescriptorInput } from '@declaro/core';
|
|
2
|
-
import { RequestEvent } from './request-event';
|
|
3
|
-
export
|
|
2
|
+
import { RequestEvent, type IRequestEventMeta } from './request-event';
|
|
3
|
+
export interface IQueryEventMeta<TResult> extends IRequestEventMeta {
|
|
4
|
+
}
|
|
5
|
+
export declare class QueryEvent<TResult, TParams, TMeta extends IQueryEventMeta<TResult> = IQueryEventMeta<TResult>> extends RequestEvent<TResult, TParams, TMeta> {
|
|
4
6
|
constructor(descriptor: IActionDescriptorInput, params: TParams, meta?: TMeta);
|
|
5
7
|
}
|
|
6
8
|
//# sourceMappingURL=query-event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-event.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/query-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"query-event.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/query-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAEtE,MAAM,WAAW,eAAe,CAAC,OAAO,CAAE,SAAQ,iBAAiB;CAAG;AAEtE,qBAAa,UAAU,CACnB,OAAO,EACP,OAAO,EACP,KAAK,SAAS,eAAe,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CACnE,SAAQ,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC;gBAC/B,UAAU,EAAE,sBAAsB,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,GAAE,KAAmB;CAG7F"}
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import type { IActionDescriptorInput, Simplify } from '@declaro/core';
|
|
2
2
|
import { DomainEvent } from './domain-event';
|
|
3
|
-
export interface
|
|
3
|
+
export interface IRequestEventMeta {
|
|
4
|
+
}
|
|
5
|
+
export interface IRequestEventJSON<TInput, TMeta = IRequestEventMeta> extends Simplify<DomainEvent<TInput, TMeta>> {
|
|
4
6
|
input: TInput;
|
|
5
7
|
}
|
|
6
|
-
export declare class RequestEvent<TResult, TInput, TMeta =
|
|
8
|
+
export declare class RequestEvent<TResult, TInput, TMeta extends IRequestEventMeta = IRequestEventMeta> extends DomainEvent<TResult, TMeta> {
|
|
9
|
+
input: TInput;
|
|
7
10
|
constructor(descriptor: IActionDescriptorInput, input: TInput, meta?: TMeta);
|
|
11
|
+
setInput(input: TInput): this;
|
|
8
12
|
setMeta(meta: Partial<TMeta>): this;
|
|
9
13
|
setResult(result: TResult): this;
|
|
14
|
+
toJSON(): {
|
|
15
|
+
input: TInput;
|
|
16
|
+
eventId: string;
|
|
17
|
+
data?: TResult | undefined;
|
|
18
|
+
meta: TMeta;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
type: string;
|
|
21
|
+
session?: {
|
|
22
|
+
id: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
10
25
|
}
|
|
11
26
|
//# sourceMappingURL=request-event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-event.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/request-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"request-event.d.ts","sourceRoot":"","sources":["../../../../src/domain/events/request-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,WAAW,iBAAiB;CAAG;AAErC,MAAM,WAAW,iBAAiB,CAAC,MAAM,EAAE,KAAK,GAAG,iBAAiB,CAAE,SAAQ,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9G,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,qBAAa,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,iBAAiB,GAAG,iBAAiB,CAAE,SAAQ,WAAW,CAC/G,OAAO,EACP,KAAK,CACR;IACG,KAAK,EAAE,MAAM,CAAA;gBAED,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,KAAmB;IASxF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI;IAKnC,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAMhC,MAAM;;;;;;;;;;;CAMT"}
|
|
@@ -80,5 +80,31 @@ export interface IRepository<TSchema extends AnyModelSchema> {
|
|
|
80
80
|
* @returns A promise resolving to the count of matching elements.
|
|
81
81
|
*/
|
|
82
82
|
count(search: InferFilters<TSchema>, options?: ISearchOptions<TSchema>): Promise<number>;
|
|
83
|
+
/**
|
|
84
|
+
* Permanently deletes all items from trash, optionally filtered by the provided criteria.
|
|
85
|
+
* Items deleted via this method cannot be restored.
|
|
86
|
+
*
|
|
87
|
+
* @param filters - Optional filters to apply when selecting items to delete from trash.
|
|
88
|
+
* @returns A promise resolving to the count of permanently deleted items.
|
|
89
|
+
*/
|
|
90
|
+
emptyTrash(filters?: InferFilters<TSchema>): Promise<number>;
|
|
91
|
+
/**
|
|
92
|
+
* Permanently deletes a specific item from trash based on the provided lookup.
|
|
93
|
+
* The item must exist in trash (previously removed). Items deleted via this method cannot be restored.
|
|
94
|
+
*
|
|
95
|
+
* @param lookup - The lookup criteria for the item to permanently delete from trash.
|
|
96
|
+
* @returns A promise resolving to the permanently deleted item summary.
|
|
97
|
+
* @throws Error if the item is not found in trash.
|
|
98
|
+
*/
|
|
99
|
+
permanentlyDeleteFromTrash(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
100
|
+
/**
|
|
101
|
+
* Permanently deletes an item based on the provided lookup, regardless of whether it is active or in trash.
|
|
102
|
+
* Items deleted via this method cannot be restored.
|
|
103
|
+
*
|
|
104
|
+
* @param lookup - The lookup criteria for the item to permanently delete.
|
|
105
|
+
* @returns A promise resolving to the permanently deleted item summary.
|
|
106
|
+
* @throws Error if the item is not found in either active data or trash.
|
|
107
|
+
*/
|
|
108
|
+
permanentlyDelete(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
83
109
|
}
|
|
84
110
|
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/domain/interfaces/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,YAAY,EACf,MAAM,qCAAqC,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAEvF,MAAM,WAAW,WAAW,CAAC,OAAO,SAAS,cAAc;IACvD;;;;;OAKG;IACH,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,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IAExF;;;;;;OAMG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAE5D;;;;;;;OAOG;IACH,0BAA0B,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAExF;;;;;;;OAOG;IACH,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;CAClF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ActionDescriptor, AnyModelSchema } from '@declaro/core';
|
|
2
|
-
import type { InferDetail, InferInput, InferLookup, InferSummary } from '../../shared/utils/schema-inference';
|
|
2
|
+
import type { InferDetail, InferFilters, InferInput, InferLookup, InferSummary } from '../../shared/utils/schema-inference';
|
|
3
3
|
import type { IModelServiceArgs } from './model-service-args';
|
|
4
4
|
import { ReadOnlyModelService, type ILoadOptions } from './read-only-model-service';
|
|
5
5
|
import type { IActionOptions } from './base-model-service';
|
|
@@ -50,5 +50,23 @@ export declare class ModelService<TSchema extends AnyModelSchema> extends ReadOn
|
|
|
50
50
|
* @returns Array of upserted records.
|
|
51
51
|
*/
|
|
52
52
|
bulkUpsert(inputs: InferInput<TSchema>[], options?: ICreateOptions | IUpdateOptions): Promise<InferDetail<TSchema>[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Permanently deletes all items from trash, optionally filtered by the provided criteria.
|
|
55
|
+
* @param filters Optional filters to apply when selecting items to delete from trash.
|
|
56
|
+
* @returns The count of permanently deleted items.
|
|
57
|
+
*/
|
|
58
|
+
emptyTrash(filters?: InferFilters<TSchema>): Promise<number>;
|
|
59
|
+
/**
|
|
60
|
+
* Permanently deletes a specific item from trash based on the provided lookup.
|
|
61
|
+
* @param lookup The lookup criteria for the item to permanently delete from trash.
|
|
62
|
+
* @returns The permanently deleted item summary.
|
|
63
|
+
*/
|
|
64
|
+
permanentlyDeleteFromTrash(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
65
|
+
/**
|
|
66
|
+
* Permanently deletes an item based on the provided lookup, regardless of whether it is active or in trash.
|
|
67
|
+
* @param lookup The lookup criteria for the item to permanently delete.
|
|
68
|
+
* @returns The permanently deleted item summary.
|
|
69
|
+
*/
|
|
70
|
+
permanentlyDelete(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
53
71
|
}
|
|
54
72
|
//# sourceMappingURL=model-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-service.d.ts","sourceRoot":"","sources":["../../../../src/domain/services/model-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAA;AACxF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"model-service.d.ts","sourceRoot":"","sources":["../../../../src/domain/services/model-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAA;AACxF,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,YAAY,EACf,MAAM,qCAAqC,CAAA;AAG5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,KAAK,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACnF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,MAAM,WAAW,cAAe,SAAQ,cAAc;CAAG;AACzD,MAAM,WAAW,cAAe,SAAQ,cAAc;CAAG;AAEzD,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,cAAc;IAC/D,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IAC/B,UAAU,EAAE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,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IA0HlC;;;;OAIG;IACG,UAAU,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBlE;;;;OAIG;IACG,0BAA0B,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAsB9F;;;;OAIG;IACG,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;CAqBxF"}
|
|
@@ -2,11 +2,30 @@ import type { AnyModelSchema } from '@declaro/core';
|
|
|
2
2
|
import type { InferDetail, InferFilters, InferLookup, InferSearchResults, InferSort } from '../../shared/utils/schema-inference';
|
|
3
3
|
import { BaseModelService, type IActionOptions } from './base-model-service';
|
|
4
4
|
import type { IPaginationInput } from '../models/pagination';
|
|
5
|
+
/**
|
|
6
|
+
* Options for loading records.
|
|
7
|
+
*/
|
|
5
8
|
export interface ILoadOptions extends IActionOptions {
|
|
9
|
+
/**
|
|
10
|
+
* If true, only removed (soft-deleted) records will be returned.
|
|
11
|
+
*/
|
|
12
|
+
removedOnly?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* If true, both removed and non-removed records will be returned.
|
|
15
|
+
*/
|
|
16
|
+
includeRemoved?: boolean;
|
|
6
17
|
}
|
|
7
18
|
export interface ISearchOptions<TSchema extends AnyModelSchema> extends IActionOptions {
|
|
8
19
|
pagination?: IPaginationInput;
|
|
9
20
|
sort?: InferSort<TSchema>;
|
|
21
|
+
/**
|
|
22
|
+
* If true, only removed (soft-deleted) records will be returned.
|
|
23
|
+
*/
|
|
24
|
+
removedOnly?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* If true, both removed and non-removed records will be returned.
|
|
27
|
+
*/
|
|
28
|
+
includeRemoved?: boolean;
|
|
10
29
|
}
|
|
11
30
|
export declare class ReadOnlyModelService<TSchema extends AnyModelSchema> extends BaseModelService<TSchema> {
|
|
12
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-only-model-service.d.ts","sourceRoot":"","sources":["../../../../src/domain/services/read-only-model-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,SAAS,EACZ,MAAM,qCAAqC,CAAA;AAG5C,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,MAAM,WAAW,YAAa,SAAQ,cAAc;
|
|
1
|
+
{"version":3,"file":"read-only-model-service.d.ts","sourceRoot":"","sources":["../../../../src/domain/services/read-only-model-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,SAAS,EACZ,MAAM,qCAAqC,CAAA;AAG5C,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,cAAc;IAChD;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CAC3B;AACD,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,cAAc,CAAE,SAAQ,cAAc;IAClF,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,IAAI,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,qBAAa,oBAAoB,CAAC,OAAO,SAAS,cAAc,CAAE,SAAQ,gBAAgB,CAAC,OAAO,CAAC;IAC/F;;;;;;OAMG;IACG,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAIlF;;;;;;;OAOG;IACG,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAIpF;;;;;OAKG;IACG,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAqB/F;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IAqBxG;;;;;OAKG;IACG,MAAM,CACR,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAClC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAyBvC;;;;OAIG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAqBlG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AnyModelSchema, IModelEntityMetadata } from '@declaro/core';
|
|
2
2
|
import type { IRepository } from '../../../domain/interfaces/repository';
|
|
3
3
|
import type { InferDetail, InferFilters, InferInput, InferLookup, InferSearchResults, InferSummary } from '../../../shared/utils/schema-inference';
|
|
4
|
-
import type { ISearchOptions } from '../../../domain/services/read-only-model-service';
|
|
4
|
+
import type { ILoadOptions, ISearchOptions } from '../../../domain/services/read-only-model-service';
|
|
5
5
|
import type { ICreateOptions, IUpdateOptions } from '../../../domain/services/model-service';
|
|
6
6
|
export interface IMockMemoryRepositoryArgs<TSchema extends AnyModelSchema> {
|
|
7
7
|
schema: TSchema;
|
|
@@ -16,7 +16,21 @@ export declare class MockMemoryRepository<TSchema extends AnyModelSchema> implem
|
|
|
16
16
|
protected entityMetadata: IModelEntityMetadata;
|
|
17
17
|
protected nextId: number;
|
|
18
18
|
constructor(args: IMockMemoryRepositoryArgs<TSchema>);
|
|
19
|
-
|
|
19
|
+
private findOne;
|
|
20
|
+
/**
|
|
21
|
+
* Find an item and return both the item and its key
|
|
22
|
+
* @param lookup - The lookup criteria
|
|
23
|
+
* @param map - The map to search in
|
|
24
|
+
* @returns Object containing the item and its key, or undefined if not found
|
|
25
|
+
*/
|
|
26
|
+
private findOneWithKey;
|
|
27
|
+
/**
|
|
28
|
+
* Loads a single item by lookup criteria.
|
|
29
|
+
* @param input - The lookup criteria.
|
|
30
|
+
* @param options - Optional load options including removedOnly and includeRemoved.
|
|
31
|
+
* @returns The found item or null if not found.
|
|
32
|
+
*/
|
|
33
|
+
load(input: InferLookup<TSchema>, options?: ILoadOptions): Promise<InferDetail<TSchema> | null>;
|
|
20
34
|
loadMany(inputs: InferLookup<TSchema>[]): Promise<InferDetail<TSchema>[]>;
|
|
21
35
|
search(input: InferFilters<TSchema>, options?: ISearchOptions<TSchema>): Promise<InferSearchResults<TSchema>>;
|
|
22
36
|
remove(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
@@ -26,12 +40,16 @@ export declare class MockMemoryRepository<TSchema extends AnyModelSchema> implem
|
|
|
26
40
|
count(search: InferFilters<TSchema>, options?: ISearchOptions<TSchema> | undefined): Promise<number>;
|
|
27
41
|
upsert(input: InferInput<TSchema>, options?: ICreateOptions | IUpdateOptions): Promise<InferDetail<TSchema>>;
|
|
28
42
|
bulkUpsert(inputs: InferInput<TSchema>[], options?: ICreateOptions | IUpdateOptions): Promise<InferDetail<TSchema>[]>;
|
|
43
|
+
permanentlyDelete(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
44
|
+
permanentlyDeleteFromTrash(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
45
|
+
emptyTrash(filters?: InferFilters<TSchema>): Promise<number>;
|
|
29
46
|
/**
|
|
30
47
|
* Apply filtering logic to all items based on the provided search criteria
|
|
31
48
|
* @param input - The search/filter criteria
|
|
49
|
+
* @param options - Optional search options including removedOnly and includeRemoved
|
|
32
50
|
* @returns Filtered array of items
|
|
33
51
|
*/
|
|
34
|
-
protected applyFilters(input: InferFilters<TSchema>): InferDetail<TSchema>[];
|
|
52
|
+
protected applyFilters(input: InferFilters<TSchema>, options?: ISearchOptions<TSchema>): InferDetail<TSchema>[];
|
|
35
53
|
/**
|
|
36
54
|
* Assign input data to existing data using the provided assign function or default Object.assign
|
|
37
55
|
* @param existingData - The existing data to merge with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-memory-repository.d.ts","sourceRoot":"","sources":["../../../../../src/test/mock/repositories/mock-memory-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAqB,MAAM,eAAe,CAAA;AAC5F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAA;AAExE,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,YAAY,EACf,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kDAAkD,CAAA;
|
|
1
|
+
{"version":3,"file":"mock-memory-repository.d.ts","sourceRoot":"","sources":["../../../../../src/test/mock/repositories/mock-memory-repository.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C;IAkB5G,UAAU,CACZ,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,EAC7B,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,GAC1C,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IAI5B,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAqB/E,0BAA0B,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAcxF,UAAU,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BlE;;;;;OAKG;IACH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,EAAE;IAwB/G;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC;cAS3F,kBAAkB;CAcrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-memory-repository.trash.test.d.ts","sourceRoot":"","sources":["../../../../../src/test/mock/repositories/mock-memory-repository.trash.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@declaro/data",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.125",
|
|
4
4
|
"description": "A data-mapper framework for managing application data across integrated systems.",
|
|
5
5
|
"main": "dist/node/index.cjs",
|
|
6
6
|
"module": "dist/node/index.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"@declaro/zod": "^2.0.0-beta.51"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@declaro/auth": "^2.0.0-beta.
|
|
26
|
-
"@declaro/core": "^2.0.0-beta.
|
|
27
|
-
"@declaro/zod": "^2.0.0-beta.
|
|
25
|
+
"@declaro/auth": "^2.0.0-beta.125",
|
|
26
|
+
"@declaro/core": "^2.0.0-beta.125",
|
|
27
|
+
"@declaro/zod": "^2.0.0-beta.125",
|
|
28
28
|
"crypto-browserify": "^3.12.1",
|
|
29
29
|
"typescript": "^5.8.3",
|
|
30
30
|
"uuid": "^11.1.0",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"require": "./dist/node/index.cjs",
|
|
44
44
|
"browser": "./dist/browser/index.js"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "8ec79475e256b7b34b8f35b264638c02d76adf40"
|
|
47
47
|
}
|
|
@@ -500,4 +500,195 @@ describe('ModelController', () => {
|
|
|
500
500
|
await expect(controller.bulkUpsert([input])).rejects.toThrow(PermissionError)
|
|
501
501
|
})
|
|
502
502
|
})
|
|
503
|
+
|
|
504
|
+
describe('Trash Functionality', () => {
|
|
505
|
+
let permanentlyDeleteValidator: AuthValidator
|
|
506
|
+
let permanentlyDeleteFromTrashValidator: AuthValidator
|
|
507
|
+
let emptyTrashValidator: AuthValidator
|
|
508
|
+
|
|
509
|
+
beforeEach(() => {
|
|
510
|
+
permanentlyDeleteValidator = new AuthValidator(
|
|
511
|
+
getMockAuthSession({
|
|
512
|
+
claims: ['books::book.permanently-delete:all'],
|
|
513
|
+
}),
|
|
514
|
+
null,
|
|
515
|
+
authService,
|
|
516
|
+
)
|
|
517
|
+
permanentlyDeleteFromTrashValidator = new AuthValidator(
|
|
518
|
+
getMockAuthSession({
|
|
519
|
+
claims: ['books::book.permanently-delete-from-trash:all'],
|
|
520
|
+
}),
|
|
521
|
+
null,
|
|
522
|
+
authService,
|
|
523
|
+
)
|
|
524
|
+
emptyTrashValidator = new AuthValidator(
|
|
525
|
+
getMockAuthSession({
|
|
526
|
+
claims: ['books::book.empty-trash:all'],
|
|
527
|
+
}),
|
|
528
|
+
null,
|
|
529
|
+
authService,
|
|
530
|
+
)
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
describe('permanentlyDelete', () => {
|
|
534
|
+
it('should permanently delete a record if permissions are valid', async () => {
|
|
535
|
+
const controller = new ModelController(service, permanentlyDeleteValidator)
|
|
536
|
+
|
|
537
|
+
const input = { id: 42, title: 'Test Book', author: 'Author Name', publishedDate: new Date() }
|
|
538
|
+
await repository.create(input)
|
|
539
|
+
|
|
540
|
+
const deletedRecord = await controller.permanentlyDelete({ id: 42 })
|
|
541
|
+
|
|
542
|
+
expect(deletedRecord).toEqual(input)
|
|
543
|
+
})
|
|
544
|
+
|
|
545
|
+
it('should throw PermissionError if permissions are invalid', async () => {
|
|
546
|
+
const controller = new ModelController(service, invalidAuthValidator)
|
|
547
|
+
|
|
548
|
+
await expect(controller.permanentlyDelete({ id: 42 })).rejects.toThrow(PermissionError)
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
it('should allow permanentlyDelete with specific permanently-delete permission', async () => {
|
|
552
|
+
const controller = new ModelController(service, permanentlyDeleteValidator)
|
|
553
|
+
|
|
554
|
+
const input = { id: 42, title: 'Test Book', author: 'Author Name', publishedDate: new Date() }
|
|
555
|
+
await repository.create(input)
|
|
556
|
+
|
|
557
|
+
const deletedRecord = await controller.permanentlyDelete({ id: 42 })
|
|
558
|
+
|
|
559
|
+
expect(deletedRecord).toEqual(input)
|
|
560
|
+
})
|
|
561
|
+
})
|
|
562
|
+
|
|
563
|
+
describe('permanentlyDeleteFromTrash', () => {
|
|
564
|
+
it('should permanently delete from trash if permissions are valid', async () => {
|
|
565
|
+
const controller = new ModelController(service, permanentlyDeleteFromTrashValidator)
|
|
566
|
+
|
|
567
|
+
const input = { id: 42, title: 'Test Book', author: 'Author Name', publishedDate: new Date() }
|
|
568
|
+
await repository.create(input)
|
|
569
|
+
await repository.remove({ id: 42 })
|
|
570
|
+
|
|
571
|
+
const deletedRecord = await controller.permanentlyDeleteFromTrash({ id: 42 })
|
|
572
|
+
|
|
573
|
+
expect(deletedRecord).toEqual(input)
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
it('should throw PermissionError if permissions are invalid', async () => {
|
|
577
|
+
const controller = new ModelController(service, invalidAuthValidator)
|
|
578
|
+
|
|
579
|
+
await expect(controller.permanentlyDeleteFromTrash({ id: 42 })).rejects.toThrow(PermissionError)
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
it('should allow with permanently-delete-from-trash permission', async () => {
|
|
583
|
+
const controller = new ModelController(service, permanentlyDeleteFromTrashValidator)
|
|
584
|
+
|
|
585
|
+
const input = { id: 42, title: 'Test Book', author: 'Author Name', publishedDate: new Date() }
|
|
586
|
+
await repository.create(input)
|
|
587
|
+
await repository.remove({ id: 42 })
|
|
588
|
+
|
|
589
|
+
const deletedRecord = await controller.permanentlyDeleteFromTrash({ id: 42 })
|
|
590
|
+
|
|
591
|
+
expect(deletedRecord).toEqual(input)
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
it('should allow with permanently-delete permission', async () => {
|
|
595
|
+
const controller = new ModelController(service, permanentlyDeleteValidator)
|
|
596
|
+
|
|
597
|
+
const input = { id: 42, title: 'Test Book', author: 'Author Name', publishedDate: new Date() }
|
|
598
|
+
await repository.create(input)
|
|
599
|
+
await repository.remove({ id: 42 })
|
|
600
|
+
|
|
601
|
+
const deletedRecord = await controller.permanentlyDeleteFromTrash({ id: 42 })
|
|
602
|
+
|
|
603
|
+
expect(deletedRecord).toEqual(input)
|
|
604
|
+
})
|
|
605
|
+
|
|
606
|
+
it('should allow with empty-trash permission', async () => {
|
|
607
|
+
const controller = new ModelController(service, emptyTrashValidator)
|
|
608
|
+
|
|
609
|
+
const input = { id: 42, title: 'Test Book', author: 'Author Name', publishedDate: new Date() }
|
|
610
|
+
await repository.create(input)
|
|
611
|
+
await repository.remove({ id: 42 })
|
|
612
|
+
|
|
613
|
+
const deletedRecord = await controller.permanentlyDeleteFromTrash({ id: 42 })
|
|
614
|
+
|
|
615
|
+
expect(deletedRecord).toEqual(input)
|
|
616
|
+
})
|
|
617
|
+
})
|
|
618
|
+
|
|
619
|
+
describe('emptyTrash', () => {
|
|
620
|
+
it('should empty trash if permissions are valid', async () => {
|
|
621
|
+
const controller = new ModelController(service, emptyTrashValidator)
|
|
622
|
+
|
|
623
|
+
const input1 = { id: 1, title: 'Test Book 1', author: 'Author Name', publishedDate: new Date() }
|
|
624
|
+
const input2 = { id: 2, title: 'Test Book 2', author: 'Author Name', publishedDate: new Date() }
|
|
625
|
+
await repository.create(input1)
|
|
626
|
+
await repository.create(input2)
|
|
627
|
+
await repository.remove({ id: 1 })
|
|
628
|
+
await repository.remove({ id: 2 })
|
|
629
|
+
|
|
630
|
+
const count = await controller.emptyTrash()
|
|
631
|
+
|
|
632
|
+
expect(count).toBe(2)
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
it('should throw PermissionError if permissions are invalid', async () => {
|
|
636
|
+
const controller = new ModelController(service, invalidAuthValidator)
|
|
637
|
+
|
|
638
|
+
await expect(controller.emptyTrash()).rejects.toThrow(PermissionError)
|
|
639
|
+
})
|
|
640
|
+
|
|
641
|
+
it('should empty trash with filters if permissions are valid', async () => {
|
|
642
|
+
const repositoryWithFilter = new MockMemoryRepository({
|
|
643
|
+
schema: mockSchema,
|
|
644
|
+
filter: (data, filters) => {
|
|
645
|
+
if (filters.text) {
|
|
646
|
+
return data.title.toLowerCase().includes(filters.text.toLowerCase())
|
|
647
|
+
}
|
|
648
|
+
return true
|
|
649
|
+
},
|
|
650
|
+
})
|
|
651
|
+
|
|
652
|
+
const serviceWithFilter = new ModelService({
|
|
653
|
+
repository: repositoryWithFilter,
|
|
654
|
+
emitter: new EventManager(),
|
|
655
|
+
namespace,
|
|
656
|
+
schema: mockSchema,
|
|
657
|
+
})
|
|
658
|
+
|
|
659
|
+
const controller = new ModelController(serviceWithFilter, emptyTrashValidator)
|
|
660
|
+
|
|
661
|
+
await repositoryWithFilter.create({
|
|
662
|
+
id: 1,
|
|
663
|
+
title: 'Test Book 1',
|
|
664
|
+
author: 'Author Name',
|
|
665
|
+
publishedDate: new Date(),
|
|
666
|
+
})
|
|
667
|
+
await repositoryWithFilter.create({
|
|
668
|
+
id: 2,
|
|
669
|
+
title: 'Other Book 2',
|
|
670
|
+
author: 'Author Name',
|
|
671
|
+
publishedDate: new Date(),
|
|
672
|
+
})
|
|
673
|
+
await repositoryWithFilter.remove({ id: 1 })
|
|
674
|
+
await repositoryWithFilter.remove({ id: 2 })
|
|
675
|
+
|
|
676
|
+
const count = await controller.emptyTrash({ text: 'Test' })
|
|
677
|
+
|
|
678
|
+
expect(count).toBe(1)
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
it('should allow emptyTrash with specific empty-trash permission', async () => {
|
|
682
|
+
const controller = new ModelController(service, emptyTrashValidator)
|
|
683
|
+
|
|
684
|
+
const input = { id: 1, title: 'Test Book', author: 'Author Name', publishedDate: new Date() }
|
|
685
|
+
await repository.create(input)
|
|
686
|
+
await repository.remove({ id: 1 })
|
|
687
|
+
|
|
688
|
+
const count = await controller.emptyTrash()
|
|
689
|
+
|
|
690
|
+
expect(count).toBe(1)
|
|
691
|
+
})
|
|
692
|
+
})
|
|
693
|
+
})
|
|
503
694
|
})
|