@punks/backend-entity-manager 0.0.334 → 0.0.336

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.
Files changed (34) hide show
  1. package/dist/cjs/index.js +348 -51
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/types/integrations/cache/dynamo/converter.d.ts +4 -0
  4. package/dist/cjs/types/integrations/cache/dynamo/index.d.ts +2 -0
  5. package/dist/cjs/types/integrations/cache/dynamo/instance.d.ts +27 -0
  6. package/dist/cjs/types/integrations/cache/dynamo/types.d.ts +8 -0
  7. package/dist/cjs/types/integrations/cache/index.d.ts +1 -0
  8. package/dist/cjs/types/platforms/nest/__test__/server/app/appAuth/appAuth.actions.d.ts +1 -1
  9. package/dist/cjs/types/platforms/nest/extensions/authentication/handlers/index.d.ts +1 -1
  10. package/dist/cjs/types/platforms/nest/plugins/collections/aws-dynamodb/collection.d.ts +33 -0
  11. package/dist/cjs/types/platforms/nest/plugins/collections/aws-dynamodb/index.d.ts +2 -0
  12. package/dist/cjs/types/platforms/nest/plugins/collections/aws-dynamodb/module.d.ts +5 -0
  13. package/dist/cjs/types/platforms/nest/plugins/collections/aws-dynamodb/settings.d.ts +7 -0
  14. package/dist/cjs/types/platforms/nest/plugins/collections/aws-dynamodb/types.d.ts +66 -0
  15. package/dist/cjs/types/platforms/nest/plugins/collections/index.d.ts +1 -0
  16. package/dist/cjs/types/platforms/nest/plugins/index.d.ts +1 -0
  17. package/dist/esm/index.js +347 -52
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/types/integrations/cache/dynamo/converter.d.ts +4 -0
  20. package/dist/esm/types/integrations/cache/dynamo/index.d.ts +2 -0
  21. package/dist/esm/types/integrations/cache/dynamo/instance.d.ts +27 -0
  22. package/dist/esm/types/integrations/cache/dynamo/types.d.ts +8 -0
  23. package/dist/esm/types/integrations/cache/index.d.ts +1 -0
  24. package/dist/esm/types/platforms/nest/__test__/server/app/appAuth/appAuth.actions.d.ts +1 -1
  25. package/dist/esm/types/platforms/nest/extensions/authentication/handlers/index.d.ts +1 -1
  26. package/dist/esm/types/platforms/nest/plugins/collections/aws-dynamodb/collection.d.ts +33 -0
  27. package/dist/esm/types/platforms/nest/plugins/collections/aws-dynamodb/index.d.ts +2 -0
  28. package/dist/esm/types/platforms/nest/plugins/collections/aws-dynamodb/module.d.ts +5 -0
  29. package/dist/esm/types/platforms/nest/plugins/collections/aws-dynamodb/settings.d.ts +7 -0
  30. package/dist/esm/types/platforms/nest/plugins/collections/aws-dynamodb/types.d.ts +66 -0
  31. package/dist/esm/types/platforms/nest/plugins/collections/index.d.ts +1 -0
  32. package/dist/esm/types/platforms/nest/plugins/index.d.ts +1 -0
  33. package/dist/index.d.ts +184 -38
  34. package/package.json +5 -1
@@ -0,0 +1,4 @@
1
+ import { CacheEntryDetail, CacheEntryInfo } from "../../../abstractions/cache";
2
+ import { DynamoDbCacheItem } from "./types";
3
+ export declare const toCacheEntryInfo: (item: DynamoDbCacheItem) => CacheEntryInfo;
4
+ export declare const toCacheEntryDetail: (item: DynamoDbCacheItem) => CacheEntryDetail;
@@ -0,0 +1,2 @@
1
+ export { DynamoDbCacheInstance } from "./instance";
2
+ export { DynamoDbCacheItem } from "./types";
@@ -0,0 +1,27 @@
1
+ import { CacheEntryDetail, CacheEntryInfo, CacheTtl, ICacheInstance } from "../../../abstractions/cache";
2
+ export type DynamoDbCacheInstanceOptions = {
3
+ tableName: string;
4
+ partitionKey?: string;
5
+ sortKey?: string;
6
+ };
7
+ export declare abstract class DynamoDbCacheInstance implements ICacheInstance {
8
+ protected readonly instanceName: string;
9
+ private readonly logger;
10
+ private readonly collection;
11
+ constructor(instanceName: string, dynamoDbOptions: DynamoDbCacheInstanceOptions);
12
+ getEntries(): Promise<CacheEntryInfo[]>;
13
+ getEntry(key: string): Promise<CacheEntryDetail | undefined>;
14
+ get<T>(key: string): Promise<T | undefined>;
15
+ set<T>(key: string, input: {
16
+ value: T;
17
+ ttl: CacheTtl;
18
+ }): Promise<void>;
19
+ retrieve<T>(key: string, input: {
20
+ ttl: CacheTtl;
21
+ valueFactory: () => Promise<T>;
22
+ }): Promise<T>;
23
+ delete(key: string): Promise<void>;
24
+ clear(): Promise<void>;
25
+ getInstanceName(): string;
26
+ private isExpired;
27
+ }
@@ -0,0 +1,8 @@
1
+ export type DynamoDbCacheItem = {
2
+ instance: string;
3
+ key: string;
4
+ expiration: number;
5
+ createdOn: number;
6
+ updatedOn: number;
7
+ data: any;
8
+ };
@@ -1 +1,2 @@
1
+ export * from "./dynamo";
1
2
  export * from "./typeorm";
@@ -7,6 +7,6 @@ export declare class AppAuthActions {
7
7
  register(data: UserRegisterRequest): Promise<import("../../../../extensions").UserRegistrationResult>;
8
8
  passwordReset(data: UserPasswordResetRequest): Promise<import("../../../../extensions").UserPasswordResetRequestResult>;
9
9
  passwordResetComplete(data: UserPasswordResetCompleteRequest): Promise<void>;
10
- userVerifyRequest(data: UserEmailVerifyRequest): Promise<import("../../../../extensions").UserVerifyResetRequestResult>;
10
+ userVerifyRequest(data: UserEmailVerifyRequest): Promise<import("../../../../extensions").UserVerifyRequestResult>;
11
11
  userVerifyComplete(data: UserEmailVerifyCompleteRequest): Promise<void>;
12
12
  }
@@ -9,4 +9,4 @@ export { UserPasswordResetRequestInput, UserPasswordResetRequestResult, UserPass
9
9
  export { UserRegisterCallbackTemplate, UserRegistrationInput, UserRegistrationResult, } from "./user-register/types";
10
10
  export { UserTokenVerifyInput, UserTokenVerifyResult, } from "./user-token-verify/types";
11
11
  export { UserVerifyCompleteInput } from "./user-verify-complete/types";
12
- export { UserVerifyRequestInput, UserVerifyRequestCallbackTemplate, UserVerifyRequestResult as UserVerifyResetRequestResult, } from "./user-verify-request/types";
12
+ export { UserVerifyRequestInput, UserVerifyRequestCallbackTemplate, UserVerifyRequestResult, } from "./user-verify-request/types";
@@ -0,0 +1,33 @@
1
+ import { DynamoItem, QueryDynamoTableInput, QueryDynamoTableItemsInput, QueryDynamoTablePageInput, QueryDynamoTablePageInputRaw, QueryDynamoTablePageRawResult, QueryDynamoTablePageResult, RawQueryDynamoTableInput, RawScanDynamoTableInput, ScanDynamoTableInput, ScanDynamoTableItemsInput } from "./types";
2
+ export type DynamoDbPrimaryKey = {
3
+ partitionKey: string;
4
+ sortKey?: string;
5
+ };
6
+ export type DynamoDbCollectionOptions = {
7
+ tableName: string;
8
+ primaryKey: DynamoDbPrimaryKey;
9
+ };
10
+ export declare class DynamoDbCollection {
11
+ private readonly settings;
12
+ private client;
13
+ constructor(settings: DynamoDbCollectionOptions);
14
+ queryTableItems<T>(input: QueryDynamoTableItemsInput): Promise<T[]>;
15
+ queryTable<T>(input: QueryDynamoTableInput<T>): Promise<void>;
16
+ protected rawQueryTable(input: RawQueryDynamoTableInput): Promise<void>;
17
+ queryTablePage<T>(input: QueryDynamoTablePageInput): Promise<QueryDynamoTablePageResult<T>>;
18
+ protected queryTablePageRaw(input: QueryDynamoTablePageInputRaw): Promise<QueryDynamoTablePageRawResult>;
19
+ scanTableItems<T>(input: ScanDynamoTableItemsInput): Promise<T[]>;
20
+ scanTable<T>(input: ScanDynamoTableInput<T>): Promise<void>;
21
+ protected rawScanTable(input: RawScanDynamoTableInput): Promise<void>;
22
+ itemExists(key: DynamoItem): Promise<boolean>;
23
+ getItem<T>(key: DynamoItem): Promise<T | undefined>;
24
+ protected getItemRaw(key: DynamoItem): Promise<DynamoItem | undefined>;
25
+ putItem<T>(item: T): Promise<void>;
26
+ protected putItemRaw(item: DynamoItem): Promise<void>;
27
+ deleteItem(key: DynamoItem): Promise<void>;
28
+ private deserializeItem;
29
+ private serializeItem;
30
+ private serializeCursor;
31
+ private deserializeCursor;
32
+ private getClient;
33
+ }
@@ -0,0 +1,2 @@
1
+ export { DynamoDbCollection } from "./collection";
2
+ export { AwsDynamoDbModule } from "./module";
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ import { AwsDynamoDbSettings } from "./settings";
3
+ export declare class AwsDynamoDbModule {
4
+ static forRoot(input: AwsDynamoDbSettings): DynamicModule;
5
+ }
@@ -0,0 +1,7 @@
1
+ import { AppInMemorySettings } from "../../../../../settings";
2
+ export type AwsDynamoDbSettings = {
3
+ awsAccessKeyId?: string;
4
+ awsSecretAccessKey?: string;
5
+ region?: string;
6
+ };
7
+ export declare const awsDynamoDbSettings: AppInMemorySettings<AwsDynamoDbSettings>;
@@ -0,0 +1,66 @@
1
+ import { AttributeValue } from "@aws-sdk/client-dynamodb";
2
+ export type DynamoItem = {
3
+ [key: string]: AttributeValue;
4
+ };
5
+ export type RawScanDynamoTableInput = {
6
+ index?: string;
7
+ pageSize: number;
8
+ filter?: string;
9
+ callback: (data: DynamoItem[]) => void;
10
+ };
11
+ export type ScanDynamoTableInput<T> = {
12
+ index?: string;
13
+ pageSize: number;
14
+ filter?: string;
15
+ callback: (data: T[]) => void;
16
+ };
17
+ export type ScanDynamoTableItemsInput = {
18
+ index?: string;
19
+ pageSize: number;
20
+ filter?: string;
21
+ };
22
+ export type SortDirection = "asc" | "desc";
23
+ export type QueryDynamoTablePageInputBase = {
24
+ index?: string;
25
+ pageSize: number;
26
+ cursor?: string;
27
+ direction?: SortDirection;
28
+ keyFilter?: string;
29
+ dataFilter?: string;
30
+ };
31
+ export type QueryDynamoTablePageInputRaw = QueryDynamoTablePageInputBase & {
32
+ filterAttributes?: DynamoItem;
33
+ };
34
+ export type QueryDynamoTablePageInput = QueryDynamoTablePageInputBase & {
35
+ filterAttributes?: any;
36
+ };
37
+ export type QueryDynamoTablePageRawResult = {
38
+ items: DynamoItem[];
39
+ cursor?: string;
40
+ };
41
+ export type QueryDynamoTablePageResult<T> = {
42
+ items: T[];
43
+ cursor?: string;
44
+ };
45
+ export type RawQueryDynamoTableInput = {
46
+ index?: string;
47
+ pageSize: number;
48
+ keyFilter?: string;
49
+ attributesFilter?: string;
50
+ filterAttributes?: DynamoItem;
51
+ callback: (data: DynamoItem[]) => void;
52
+ };
53
+ export type QueryDynamoTableInput<T> = {
54
+ index?: string;
55
+ pageSize: number;
56
+ keyFilter?: string;
57
+ callback: (data: T[]) => void;
58
+ };
59
+ export type QueryDynamoTableItemsInput = {
60
+ index?: string;
61
+ pageSize: number;
62
+ keyFilter?: string;
63
+ attributesFilter?: string;
64
+ filterAttributes?: DynamoItem;
65
+ direction?: SortDirection;
66
+ };
@@ -0,0 +1 @@
1
+ export * from "./aws-dynamodb";
@@ -1,4 +1,5 @@
1
1
  export * from "./buckets";
2
+ export * from "./collections";
2
3
  export * from "./email";
3
4
  export * from "./jobs";
4
5
  export * from "./media";
package/dist/esm/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { Log, csvParse, excelParse, excelBuild, csvBuild, isNullOrUndefined, addTime, newUuid as newUuid$1, buildObject, toDict, sleep, sort, byField, toArrayDict, toItemsDict, ensureTailingSlash, ensureStartSlash, removeUndefinedProps } from '@punks/backend-core';
2
+ import { QueryCommand, ScanCommand, GetItemCommand, PutItemCommand, DeleteItemCommand, DynamoDBClient } from '@aws-sdk/client-dynamodb';
3
+ import { unmarshall, marshall } from '@aws-sdk/util-dynamodb';
4
+ import { Module, applyDecorators, Injectable, SetMetadata, createParamDecorator, Global, Scope, Inject, Logger, StreamableFile, HttpException, HttpStatus } from '@nestjs/common';
2
5
  import { MoreThanOrEqual, Equal, Not, IsNull, And, MoreThan, LessThanOrEqual, LessThan, ILike, In, Or, Repository } from 'typeorm';
3
- import { applyDecorators, Injectable, SetMetadata, createParamDecorator, Global, Module, Scope, Inject, Logger, StreamableFile, HttpException, HttpStatus } from '@nestjs/common';
4
6
  import { Reflector } from '@nestjs/core';
5
7
  import { AsyncLocalStorage } from 'async_hooks';
6
8
  import { hash } from 'bcrypt';
@@ -2563,6 +2565,349 @@ const PlatformEvents = {
2563
2565
  },
2564
2566
  };
2565
2567
 
2568
+ class AppInMemorySettings {
2569
+ constructor(name) {
2570
+ this.name = name;
2571
+ }
2572
+ initialize(value) {
2573
+ this._instance = value;
2574
+ }
2575
+ get value() {
2576
+ if (!this._instance) {
2577
+ throw new Error(`AppSettings ${this.name} not initialized`);
2578
+ }
2579
+ return this._instance;
2580
+ }
2581
+ }
2582
+
2583
+ const awsDynamoDbSettings = new AppInMemorySettings("awsDynamoDbSettings");
2584
+
2585
+ class DynamoDbCollection {
2586
+ constructor(settings) {
2587
+ this.settings = settings;
2588
+ // *** Utility methods ***
2589
+ this.deserializeItem = (item) => unmarshall(item);
2590
+ this.serializeItem = (item) => marshall(item, {
2591
+ removeUndefinedValues: true,
2592
+ });
2593
+ this.serializeCursor = (cursor) => cursor ? JSON.stringify(cursor) : undefined;
2594
+ this.deserializeCursor = (cursor) => cursor ? JSON.parse(cursor) : undefined;
2595
+ this.client = this.getClient();
2596
+ }
2597
+ async queryTableItems(input) {
2598
+ const results = [];
2599
+ await this.queryTable({
2600
+ ...input,
2601
+ callback: (items) => {
2602
+ results.push(...items);
2603
+ },
2604
+ });
2605
+ return results;
2606
+ }
2607
+ async queryTable(input) {
2608
+ const { callback, ...data } = input;
2609
+ return await this.rawQueryTable({
2610
+ ...data,
2611
+ callback: (items) => callback(items.map((x) => this.deserializeItem(x))),
2612
+ });
2613
+ }
2614
+ async rawQueryTable(input) {
2615
+ const { callback } = input;
2616
+ let cursor = undefined;
2617
+ while (true) {
2618
+ const buildCommand = new QueryCommand({
2619
+ TableName: this.settings.tableName,
2620
+ IndexName: input.index,
2621
+ Limit: input.pageSize,
2622
+ ExclusiveStartKey: cursor,
2623
+ KeyConditionExpression: input.keyFilter,
2624
+ FilterExpression: input.attributesFilter,
2625
+ ExpressionAttributeValues: input.filterAttributes,
2626
+ });
2627
+ const result = await this.client.send(buildCommand);
2628
+ callback(result.Items);
2629
+ cursor = result.LastEvaluatedKey;
2630
+ if (!result.LastEvaluatedKey) {
2631
+ return;
2632
+ }
2633
+ }
2634
+ }
2635
+ async queryTablePage(input) {
2636
+ const result = await this.queryTablePageRaw({
2637
+ ...input,
2638
+ filterAttributes: input.filterAttributes
2639
+ ? marshall(input.filterAttributes, {
2640
+ removeUndefinedValues: true,
2641
+ })
2642
+ : undefined,
2643
+ });
2644
+ return {
2645
+ items: result.items.map((x) => this.deserializeItem(x)),
2646
+ cursor: result.cursor,
2647
+ };
2648
+ }
2649
+ async queryTablePageRaw(input) {
2650
+ const result = await this.client.send(new QueryCommand({
2651
+ TableName: this.settings.tableName,
2652
+ IndexName: input.index,
2653
+ Limit: input.pageSize,
2654
+ ExclusiveStartKey: input.cursor
2655
+ ? this.deserializeCursor(input.cursor)
2656
+ : undefined,
2657
+ KeyConditionExpression: input.keyFilter,
2658
+ FilterExpression: input.dataFilter,
2659
+ ExpressionAttributeValues: input.filterAttributes,
2660
+ ScanIndexForward: input.direction !== "desc",
2661
+ }));
2662
+ return {
2663
+ items: result.Items ?? [],
2664
+ cursor: result.LastEvaluatedKey
2665
+ ? this.serializeCursor(result.LastEvaluatedKey)
2666
+ : undefined,
2667
+ };
2668
+ }
2669
+ async scanTableItems(input) {
2670
+ const items = [];
2671
+ await this.scanTable({
2672
+ ...input,
2673
+ callback: (x) => items.push(...x),
2674
+ });
2675
+ return items;
2676
+ }
2677
+ async scanTable(input) {
2678
+ const { callback, ...data } = input;
2679
+ return await this.rawScanTable({
2680
+ ...data,
2681
+ callback: (items) => callback(items.map((x) => this.deserializeItem(x))),
2682
+ });
2683
+ }
2684
+ async rawScanTable(input) {
2685
+ const { callback } = input;
2686
+ let cursor = undefined;
2687
+ while (true) {
2688
+ const result = await this.client.send(new ScanCommand({
2689
+ TableName: this.settings.tableName,
2690
+ IndexName: input.index,
2691
+ Limit: input.pageSize,
2692
+ FilterExpression: input.filter,
2693
+ ExclusiveStartKey: cursor,
2694
+ }));
2695
+ if (result.Items) {
2696
+ callback(result.Items);
2697
+ }
2698
+ cursor = result.LastEvaluatedKey;
2699
+ if (!result.LastEvaluatedKey) {
2700
+ return;
2701
+ }
2702
+ }
2703
+ }
2704
+ async itemExists(key) {
2705
+ return !!(await this.getItemRaw(key));
2706
+ }
2707
+ async getItem(key) {
2708
+ const item = await this.getItemRaw(key);
2709
+ const el = item ? this.deserializeItem(item) : undefined;
2710
+ return el;
2711
+ }
2712
+ async getItemRaw(key) {
2713
+ const result = await this.client.send(new GetItemCommand({
2714
+ TableName: this.settings.tableName,
2715
+ Key: key,
2716
+ }));
2717
+ return result.Item;
2718
+ }
2719
+ async putItem(item) {
2720
+ await this.putItemRaw(this.serializeItem(item));
2721
+ }
2722
+ async putItemRaw(item) {
2723
+ await this.getClient().send(new PutItemCommand({
2724
+ TableName: this.settings.tableName,
2725
+ Item: item,
2726
+ }));
2727
+ }
2728
+ async deleteItem(key) {
2729
+ await this.getClient().send(new DeleteItemCommand({
2730
+ TableName: this.settings.tableName,
2731
+ Key: key,
2732
+ }));
2733
+ }
2734
+ getClient() {
2735
+ return new DynamoDBClient({
2736
+ credentials: awsDynamoDbSettings.value.awsAccessKeyId &&
2737
+ awsDynamoDbSettings.value.awsSecretAccessKey
2738
+ ? {
2739
+ accessKeyId: awsDynamoDbSettings.value.awsAccessKeyId,
2740
+ secretAccessKey: awsDynamoDbSettings.value.awsSecretAccessKey,
2741
+ }
2742
+ : undefined,
2743
+ region: awsDynamoDbSettings.value.region,
2744
+ });
2745
+ }
2746
+ }
2747
+
2748
+ /******************************************************************************
2749
+ Copyright (c) Microsoft Corporation.
2750
+
2751
+ Permission to use, copy, modify, and/or distribute this software for any
2752
+ purpose with or without fee is hereby granted.
2753
+
2754
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2755
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2756
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2757
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2758
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2759
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2760
+ PERFORMANCE OF THIS SOFTWARE.
2761
+ ***************************************************************************** */
2762
+
2763
+ function __decorate(decorators, target, key, desc) {
2764
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2765
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2766
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2767
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2768
+ }
2769
+
2770
+ function __param(paramIndex, decorator) {
2771
+ return function (target, key) { decorator(target, key, paramIndex); }
2772
+ }
2773
+
2774
+ function __metadata(metadataKey, metadataValue) {
2775
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
2776
+ }
2777
+
2778
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2779
+ var e = new Error(message);
2780
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2781
+ };
2782
+
2783
+ var AwsDynamoDbModule_1;
2784
+ const ModuleData$a = {
2785
+ providers: [],
2786
+ exports: [],
2787
+ };
2788
+ let AwsDynamoDbModule = AwsDynamoDbModule_1 = class AwsDynamoDbModule {
2789
+ static forRoot(input) {
2790
+ awsDynamoDbSettings.initialize(input);
2791
+ return {
2792
+ module: AwsDynamoDbModule_1,
2793
+ ...ModuleData$a,
2794
+ };
2795
+ }
2796
+ };
2797
+ AwsDynamoDbModule = AwsDynamoDbModule_1 = __decorate([
2798
+ Module({
2799
+ ...ModuleData$a,
2800
+ })
2801
+ ], AwsDynamoDbModule);
2802
+
2803
+ const toCacheEntryInfo = (item) => ({
2804
+ instanceName: item.instance,
2805
+ key: item.key,
2806
+ expiration: new Date(item.expiration),
2807
+ createdOn: new Date(item.createdOn),
2808
+ updatedOn: new Date(item.updatedOn),
2809
+ });
2810
+ const toCacheEntryDetail = (item) => ({
2811
+ instanceName: item.instance,
2812
+ key: item.key,
2813
+ expiration: new Date(item.expiration),
2814
+ createdOn: new Date(item.createdOn),
2815
+ updatedOn: new Date(item.updatedOn),
2816
+ data: item.data,
2817
+ });
2818
+
2819
+ class DynamoDbCacheInstance {
2820
+ constructor(instanceName, dynamoDbOptions) {
2821
+ this.instanceName = instanceName;
2822
+ this.logger = Log.getLogger(`DynamoDb Cache Instance ${instanceName}`);
2823
+ this.collection = new DynamoDbCollection({
2824
+ tableName: dynamoDbOptions.tableName,
2825
+ primaryKey: {
2826
+ partitionKey: dynamoDbOptions.partitionKey ?? "instance",
2827
+ sortKey: dynamoDbOptions.sortKey ?? "key",
2828
+ },
2829
+ });
2830
+ }
2831
+ async getEntries() {
2832
+ const items = await this.collection.queryTableItems({
2833
+ pageSize: 100,
2834
+ });
2835
+ return items.map(toCacheEntryInfo);
2836
+ }
2837
+ async getEntry(key) {
2838
+ const entry = await this.collection.getItem({
2839
+ instance: {
2840
+ S: this.instanceName,
2841
+ },
2842
+ key: {
2843
+ S: key,
2844
+ },
2845
+ });
2846
+ return entry && !this.isExpired(entry, new Date())
2847
+ ? toCacheEntryDetail(entry)
2848
+ : undefined;
2849
+ }
2850
+ async get(key) {
2851
+ const item = await this.getEntry(key);
2852
+ return item?.data;
2853
+ }
2854
+ async set(key, input) {
2855
+ const now = Date.now();
2856
+ await this.collection.putItem({
2857
+ key,
2858
+ data: input.value,
2859
+ createdOn: now,
2860
+ updatedOn: now,
2861
+ expiration: addTime(new Date(), input.ttl).getTime(),
2862
+ instance: this.instanceName,
2863
+ });
2864
+ }
2865
+ async retrieve(key, input) {
2866
+ const item = await this.get(key);
2867
+ if (item) {
2868
+ return item;
2869
+ }
2870
+ const value = await input.valueFactory();
2871
+ await this.set(key, { value, ttl: input.ttl });
2872
+ return value;
2873
+ }
2874
+ async delete(key) {
2875
+ await this.collection.deleteItem({
2876
+ instance: {
2877
+ S: this.instanceName,
2878
+ },
2879
+ key: {
2880
+ S: key,
2881
+ },
2882
+ });
2883
+ }
2884
+ async clear() {
2885
+ await this.collection.scanTable({
2886
+ pageSize: 100,
2887
+ callback: (items) => {
2888
+ items.forEach((item) => {
2889
+ if (item.instance === this.instanceName) {
2890
+ this.collection.deleteItem({
2891
+ instance: {
2892
+ S: this.instanceName,
2893
+ },
2894
+ key: {
2895
+ S: item.key,
2896
+ },
2897
+ });
2898
+ }
2899
+ });
2900
+ },
2901
+ });
2902
+ }
2903
+ getInstanceName() {
2904
+ return this.instanceName;
2905
+ }
2906
+ isExpired(item, when) {
2907
+ return item.expiration < when.getTime();
2908
+ }
2909
+ }
2910
+
2566
2911
  class TypeormCacheInstance {
2567
2912
  constructor(instanceName) {
2568
2913
  this.instanceName = instanceName;
@@ -3834,41 +4179,6 @@ const AuthenticationEvents = {
3834
4179
  UserPasswordResetCompleted: `${AUTHENTICATION_EVENTS_NAMESPACE}:user.passwordResetCompleted`,
3835
4180
  };
3836
4181
 
3837
- /******************************************************************************
3838
- Copyright (c) Microsoft Corporation.
3839
-
3840
- Permission to use, copy, modify, and/or distribute this software for any
3841
- purpose with or without fee is hereby granted.
3842
-
3843
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3844
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3845
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3846
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3847
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3848
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3849
- PERFORMANCE OF THIS SOFTWARE.
3850
- ***************************************************************************** */
3851
-
3852
- function __decorate(decorators, target, key, desc) {
3853
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3854
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3855
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3856
- return c > 3 && r && Object.defineProperty(target, key, r), r;
3857
- }
3858
-
3859
- function __param(paramIndex, decorator) {
3860
- return function (target, key) { decorator(target, key, paramIndex); }
3861
- }
3862
-
3863
- function __metadata(metadataKey, metadataValue) {
3864
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
3865
- }
3866
-
3867
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3868
- var e = new Error(message);
3869
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3870
- };
3871
-
3872
4182
  var AuthGuard_1;
3873
4183
  let AuthGuard = AuthGuard_1 = class AuthGuard {
3874
4184
  constructor(reflector) {
@@ -22360,21 +22670,6 @@ AuthenticationServicesResolver = __decorate([
22360
22670
  Injectable()
22361
22671
  ], AuthenticationServicesResolver);
22362
22672
 
22363
- class AppInMemorySettings {
22364
- constructor(name) {
22365
- this.name = name;
22366
- }
22367
- initialize(value) {
22368
- this._instance = value;
22369
- }
22370
- get value() {
22371
- if (!this._instance) {
22372
- throw new Error(`AppSettings ${this.name} not initialized`);
22373
- }
22374
- return this._instance;
22375
- }
22376
- }
22377
-
22378
22673
  const authSettings = new AppInMemorySettings("authSettings");
22379
22674
 
22380
22675
  let JwtProvider = class JwtProvider {
@@ -43808,5 +44103,5 @@ InMemorySecretsProvider = __decorate([
43808
44103
  WpSecretsProvider("inMemorySecretsManager")
43809
44104
  ], InMemorySecretsProvider);
43810
44105
 
43811
- export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
44106
+ export { AUTHENTICATION_EVENTS_NAMESPACE, ApiKeyAccess, AppExceptionsFilterBase, AppHashingService, AppInMemorySettings, AppSession, AppSessionMiddleware, AppSessionService, AuthGuard, Authenticated, AuthenticationEmailTemplates, AuthenticationError, AuthenticationEvents, AuthenticationExtensionSymbols, AuthenticationModule, AuthenticationService, AwsBucketModule, AwsDynamoDbModule, AwsEmailModule, AwsJobsModule, AwsS3BucketError, AwsS3BucketProvider, AwsS3MediaError, AwsS3MediaModule, AwsS3MediaProvider, AwsSecretsModule, AwsSecretsProvider, AwsSesEmailTemplate, BucketItemType, CacheService, ConnectorMode, CurrentUser, CustomDiscoveryModule, CustomDiscoveryService, DynamoDbCacheInstance, DynamoDbCollection, EmailService, EntityManagerConfigurationError, EntityManagerException, EntityManagerInitializer, EntityManagerModule, EntityManagerRegistry, EntityManagerService, EntityManagerSymbols, EntityManagerUnauthorizedException, EntityNotFoundException, EntityOperationType, EntityOperationUnauthorizedException, EntitySeeder, EntitySerializationFormat, EntitySerializer, EntitySnapshotService, EntityVersionOperation, EventsService, ExclusiveOperationResult, FilesManager, IEntityVersionsCursor, InMemoryBucketProvider, InMemoryEmailProvider, InMemoryMediaProvider, InMemorySecretsProvider, InvalidCredentialsError, JobConcurrency, JobInstance, JobProviderState, JobRunType, JobSchedule, JobStatus, JobsModule, JobsService, LockNotFoundError, MediaLibraryService, MemberOf, MissingEntityIdError, ModulesContainerProvider, MultiTenancyModule, MultipleEntitiesFoundException, NestEntityActions, NestEntityAuthorizationMiddleware, NestEntityManager, NestEntitySerializer, NestEntitySnapshotService, NestPipelineTemplate, NestTypeOrmEntitySeeder, NestTypeOrmQueryBuilder, NestTypeOrmRepository, OperationLockService, OperationTokenMismatchError, PLATFORM_EVENT_NAMESPACE, Permissions, PipelineController, PipelineErrorType, PipelineInvocationError, PipelineStatus, PipelineStepErrorType, PipelinesBuilder, PipelinesRunner, PlatformEvents, Public, QueryBuilderBase, QueryBuilderOperation, ReplicationMode, Roles, SanityMediaError, SanityMediaModule, SanityMediaProvider, SecretsService, SendgridEmailModule, SendgridEmailTemplate, SortDirection, TrackingService, TypeOrmQueryBuilder, TypeOrmRepository, TypeormCacheInstance, TypeormOperationLockRepository, UserCreationError, UserRegistrationError, WpApiKeysService, WpAppInitializer, WpAwsSesEmailTemplate, WpBucketProvider, WpCacheInstance, WpEmailLogger, WpEmailProvider, WpEmailTemplate, WpEntity, WpEntityActions, WpEntityAdapter, WpEntityAuthMiddleware, WpEntityConnector, WpEntityConnectorMapper, WpEntityConverter, WpEntityManager, WpEntityQueryBuilder, WpEntityRepository, WpEntitySeeder, WpEntitySerializer, WpEntitySnapshotService, WpEntityVersioningProvider, WpEventsTracker, WpFileProvider, WpFileReferenceRepository, WpGlobalAuthenticationMiddleware, WpMediaFolderRepository, WpMediaProvider, WpMediaReferenceRepository, WpPermissionsService, WpPipeline, WpRolesService, WpSendgridEmailTemplate, WpUserRolesService, WpUserService, awsBatchSettings, buildPermissionsGuard, buildProviderToken, buildRolesGuard, createContainer, createExpressFileResponse, getEntityManagerProviderToken, getLocalizedText, newUuid, renderHandlebarsTemplate, sessionStorage, toEntitiesImportInput };
43812
44107
  //# sourceMappingURL=index.js.map