@http-client-toolkit/store-dynamodb 0.0.1 → 0.4.0
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/lib/index.cjs +518 -392
- package/lib/index.d.cts +195 -139
- package/lib/index.d.ts +195 -139
- package/lib/index.js +542 -395
- package/package.json +4 -4
package/lib/index.d.cts
CHANGED
|
@@ -1,165 +1,221 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DynamoDBClient,
|
|
3
|
+
KeySchemaElement,
|
|
4
|
+
AttributeDefinition,
|
|
5
|
+
GlobalSecondaryIndex,
|
|
6
|
+
} from '@aws-sdk/client-dynamodb';
|
|
2
7
|
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
|
|
3
|
-
import {
|
|
4
|
-
|
|
8
|
+
import {
|
|
9
|
+
CacheStore,
|
|
10
|
+
DedupeStore,
|
|
11
|
+
RateLimitStore,
|
|
12
|
+
RateLimitConfig,
|
|
13
|
+
AdaptiveRateLimitStore,
|
|
14
|
+
AdaptiveConfigSchema,
|
|
15
|
+
RequestPriority,
|
|
16
|
+
} from '@http-client-toolkit/core';
|
|
17
|
+
export {
|
|
18
|
+
AdaptiveConfig,
|
|
19
|
+
AdaptiveRateLimitStore,
|
|
20
|
+
CacheStore,
|
|
21
|
+
DedupeStore,
|
|
22
|
+
RateLimitConfig,
|
|
23
|
+
RateLimitStore,
|
|
24
|
+
RequestPriority,
|
|
25
|
+
} from '@http-client-toolkit/core';
|
|
5
26
|
import { z } from 'zod';
|
|
6
27
|
|
|
7
28
|
interface DynamoDBCacheStoreOptions {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
29
|
+
client?: DynamoDBDocumentClient | DynamoDBClient;
|
|
30
|
+
region?: string;
|
|
31
|
+
tableName?: string;
|
|
32
|
+
maxEntrySizeBytes?: number;
|
|
12
33
|
}
|
|
13
34
|
declare class DynamoDBCacheStore<T = unknown> implements CacheStore<T> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
private readonly docClient;
|
|
36
|
+
private readonly rawClient;
|
|
37
|
+
private readonly isClientManaged;
|
|
38
|
+
private readonly tableName;
|
|
39
|
+
private readonly maxEntrySizeBytes;
|
|
40
|
+
private isDestroyed;
|
|
41
|
+
constructor({
|
|
42
|
+
client,
|
|
43
|
+
region,
|
|
44
|
+
tableName,
|
|
45
|
+
maxEntrySizeBytes,
|
|
46
|
+
}?: DynamoDBCacheStoreOptions);
|
|
47
|
+
get(hash: string): Promise<T | undefined>;
|
|
48
|
+
set(hash: string, value: T, ttlSeconds: number): Promise<void>;
|
|
49
|
+
delete(hash: string): Promise<void>;
|
|
50
|
+
clear(): Promise<void>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
destroy(): void;
|
|
53
|
+
private assertValidHash;
|
|
28
54
|
}
|
|
29
55
|
|
|
30
56
|
interface DynamoDBDedupeStoreOptions {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
57
|
+
client?: DynamoDBDocumentClient | DynamoDBClient;
|
|
58
|
+
region?: string;
|
|
59
|
+
tableName?: string;
|
|
60
|
+
jobTimeoutMs?: number;
|
|
61
|
+
pollIntervalMs?: number;
|
|
36
62
|
}
|
|
37
63
|
declare class DynamoDBDedupeStore<T = unknown> implements DedupeStore<T> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
private readonly docClient;
|
|
65
|
+
private readonly rawClient;
|
|
66
|
+
private readonly isClientManaged;
|
|
67
|
+
private readonly tableName;
|
|
68
|
+
private readonly jobTimeoutMs;
|
|
69
|
+
private readonly pollIntervalMs;
|
|
70
|
+
private jobPromises;
|
|
71
|
+
private jobSettlers;
|
|
72
|
+
private isDestroyed;
|
|
73
|
+
constructor({
|
|
74
|
+
client,
|
|
75
|
+
region,
|
|
76
|
+
tableName,
|
|
77
|
+
jobTimeoutMs,
|
|
78
|
+
pollIntervalMs,
|
|
79
|
+
}?: DynamoDBDedupeStoreOptions);
|
|
80
|
+
waitFor(hash: string): Promise<T | undefined>;
|
|
81
|
+
register(hash: string): Promise<string>;
|
|
82
|
+
registerOrJoin(hash: string): Promise<{
|
|
83
|
+
jobId: string;
|
|
84
|
+
isOwner: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
complete(hash: string, value: T | undefined): Promise<void>;
|
|
87
|
+
fail(hash: string, _error: Error): Promise<void>;
|
|
88
|
+
isInProgress(hash: string): Promise<boolean>;
|
|
89
|
+
clear(): Promise<void>;
|
|
90
|
+
close(): Promise<void>;
|
|
91
|
+
destroy(): void;
|
|
92
|
+
private deserializeResult;
|
|
93
|
+
private assertValidHash;
|
|
62
94
|
}
|
|
63
95
|
|
|
64
96
|
interface DynamoDBRateLimitStoreOptions {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
97
|
+
client?: DynamoDBDocumentClient | DynamoDBClient;
|
|
98
|
+
region?: string;
|
|
99
|
+
tableName?: string;
|
|
100
|
+
defaultConfig?: RateLimitConfig;
|
|
101
|
+
resourceConfigs?: Map<string, RateLimitConfig>;
|
|
70
102
|
}
|
|
71
103
|
declare class DynamoDBRateLimitStore implements RateLimitStore {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
private readonly docClient;
|
|
105
|
+
private readonly rawClient;
|
|
106
|
+
private readonly isClientManaged;
|
|
107
|
+
private readonly tableName;
|
|
108
|
+
private defaultConfig;
|
|
109
|
+
private resourceConfigs;
|
|
110
|
+
private isDestroyed;
|
|
111
|
+
constructor({
|
|
112
|
+
client,
|
|
113
|
+
region,
|
|
114
|
+
tableName,
|
|
115
|
+
defaultConfig,
|
|
116
|
+
resourceConfigs,
|
|
117
|
+
}?: DynamoDBRateLimitStoreOptions);
|
|
118
|
+
canProceed(resource: string): Promise<boolean>;
|
|
119
|
+
acquire(resource: string): Promise<boolean>;
|
|
120
|
+
record(resource: string): Promise<void>;
|
|
121
|
+
getStatus(resource: string): Promise<{
|
|
122
|
+
remaining: number;
|
|
123
|
+
resetTime: Date;
|
|
124
|
+
limit: number;
|
|
125
|
+
}>;
|
|
126
|
+
reset(resource: string): Promise<void>;
|
|
127
|
+
getWaitTime(resource: string): Promise<number>;
|
|
128
|
+
setResourceConfig(resource: string, config: RateLimitConfig): void;
|
|
129
|
+
getResourceConfig(resource: string): RateLimitConfig;
|
|
130
|
+
clear(): Promise<void>;
|
|
131
|
+
close(): Promise<void>;
|
|
132
|
+
destroy(): void;
|
|
133
|
+
private countRequestsInWindow;
|
|
134
|
+
private hasCapacityInWindow;
|
|
135
|
+
private deleteResourceItems;
|
|
136
|
+
private assertValidResource;
|
|
99
137
|
}
|
|
100
138
|
|
|
101
139
|
interface DynamoDBAdaptiveRateLimitStoreOptions {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
140
|
+
client?: DynamoDBDocumentClient | DynamoDBClient;
|
|
141
|
+
region?: string;
|
|
142
|
+
tableName?: string;
|
|
143
|
+
defaultConfig?: RateLimitConfig;
|
|
144
|
+
resourceConfigs?: Map<string, RateLimitConfig>;
|
|
145
|
+
adaptiveConfig?: Partial<z.input<typeof AdaptiveConfigSchema>>;
|
|
108
146
|
}
|
|
109
147
|
declare class DynamoDBAdaptiveRateLimitStore implements AdaptiveRateLimitStore {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
148
|
+
private readonly docClient;
|
|
149
|
+
private readonly rawClient;
|
|
150
|
+
private readonly isClientManaged;
|
|
151
|
+
private readonly tableName;
|
|
152
|
+
private defaultConfig;
|
|
153
|
+
private resourceConfigs;
|
|
154
|
+
private isDestroyed;
|
|
155
|
+
private capacityCalculator;
|
|
156
|
+
private activityMetrics;
|
|
157
|
+
private lastCapacityUpdate;
|
|
158
|
+
private cachedCapacity;
|
|
159
|
+
private readonly maxMetricSamples;
|
|
160
|
+
constructor({
|
|
161
|
+
client,
|
|
162
|
+
region,
|
|
163
|
+
tableName,
|
|
164
|
+
defaultConfig,
|
|
165
|
+
resourceConfigs,
|
|
166
|
+
adaptiveConfig,
|
|
167
|
+
}?: DynamoDBAdaptiveRateLimitStoreOptions);
|
|
168
|
+
canProceed(resource: string, priority?: RequestPriority): Promise<boolean>;
|
|
169
|
+
acquire(resource: string, priority?: RequestPriority): Promise<boolean>;
|
|
170
|
+
record(resource: string, priority?: RequestPriority): Promise<void>;
|
|
171
|
+
getStatus(resource: string): Promise<{
|
|
172
|
+
remaining: number;
|
|
173
|
+
resetTime: Date;
|
|
174
|
+
limit: number;
|
|
175
|
+
adaptive?: {
|
|
176
|
+
userReserved: number;
|
|
177
|
+
backgroundMax: number;
|
|
178
|
+
backgroundPaused: boolean;
|
|
179
|
+
recentUserActivity: number;
|
|
180
|
+
reason: string;
|
|
181
|
+
};
|
|
182
|
+
}>;
|
|
183
|
+
reset(resource: string): Promise<void>;
|
|
184
|
+
getWaitTime(resource: string, priority?: RequestPriority): Promise<number>;
|
|
185
|
+
setResourceConfig(resource: string, config: RateLimitConfig): void;
|
|
186
|
+
getResourceConfig(resource: string): RateLimitConfig;
|
|
187
|
+
clear(): Promise<void>;
|
|
188
|
+
close(): Promise<void>;
|
|
189
|
+
destroy(): void;
|
|
190
|
+
private calculateCurrentCapacity;
|
|
191
|
+
private getOrCreateActivityMetrics;
|
|
192
|
+
private ensureActivityMetrics;
|
|
193
|
+
private getCurrentUsage;
|
|
194
|
+
private hasPriorityCapacityInWindow;
|
|
195
|
+
private cleanupOldRequests;
|
|
196
|
+
private pushRecentRequest;
|
|
197
|
+
private getResourceLimit;
|
|
198
|
+
private getDefaultCapacity;
|
|
199
|
+
private deleteResourceItems;
|
|
200
|
+
private assertValidResource;
|
|
156
201
|
}
|
|
157
202
|
|
|
158
|
-
declare const DEFAULT_TABLE_NAME =
|
|
203
|
+
declare const DEFAULT_TABLE_NAME = 'http-client-toolkit';
|
|
159
204
|
declare const TABLE_SCHEMA: {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
205
|
+
KeySchema: Array<KeySchemaElement>;
|
|
206
|
+
AttributeDefinitions: Array<AttributeDefinition>;
|
|
207
|
+
GlobalSecondaryIndexes: Array<GlobalSecondaryIndex>;
|
|
163
208
|
};
|
|
164
209
|
|
|
165
|
-
export {
|
|
210
|
+
export {
|
|
211
|
+
DEFAULT_TABLE_NAME,
|
|
212
|
+
DynamoDBAdaptiveRateLimitStore,
|
|
213
|
+
type DynamoDBAdaptiveRateLimitStoreOptions,
|
|
214
|
+
DynamoDBCacheStore,
|
|
215
|
+
type DynamoDBCacheStoreOptions,
|
|
216
|
+
DynamoDBDedupeStore,
|
|
217
|
+
type DynamoDBDedupeStoreOptions,
|
|
218
|
+
DynamoDBRateLimitStore,
|
|
219
|
+
type DynamoDBRateLimitStoreOptions,
|
|
220
|
+
TABLE_SCHEMA,
|
|
221
|
+
};
|