@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.d.cts CHANGED
@@ -1,165 +1,221 @@
1
- import { DynamoDBClient, KeySchemaElement, AttributeDefinition, GlobalSecondaryIndex } from '@aws-sdk/client-dynamodb';
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 { CacheStore, DedupeStore, RateLimitStore, RateLimitConfig, AdaptiveRateLimitStore, AdaptiveConfigSchema, RequestPriority } from '@http-client-toolkit/core';
4
- export { AdaptiveConfig, AdaptiveRateLimitStore, CacheStore, DedupeStore, RateLimitConfig, RateLimitStore, RequestPriority } from '@http-client-toolkit/core';
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
- client?: DynamoDBDocumentClient | DynamoDBClient;
9
- region?: string;
10
- tableName?: string;
11
- maxEntrySizeBytes?: number;
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
- private readonly docClient;
15
- private readonly rawClient;
16
- private readonly isClientManaged;
17
- private readonly tableName;
18
- private readonly maxEntrySizeBytes;
19
- private isDestroyed;
20
- constructor({ client, region, tableName, maxEntrySizeBytes, }?: DynamoDBCacheStoreOptions);
21
- get(hash: string): Promise<T | undefined>;
22
- set(hash: string, value: T, ttlSeconds: number): Promise<void>;
23
- delete(hash: string): Promise<void>;
24
- clear(): Promise<void>;
25
- close(): Promise<void>;
26
- destroy(): void;
27
- private assertValidHash;
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
- client?: DynamoDBDocumentClient | DynamoDBClient;
32
- region?: string;
33
- tableName?: string;
34
- jobTimeoutMs?: number;
35
- pollIntervalMs?: number;
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
- private readonly docClient;
39
- private readonly rawClient;
40
- private readonly isClientManaged;
41
- private readonly tableName;
42
- private readonly jobTimeoutMs;
43
- private readonly pollIntervalMs;
44
- private jobPromises;
45
- private jobSettlers;
46
- private isDestroyed;
47
- constructor({ client, region, tableName, jobTimeoutMs, pollIntervalMs, }?: DynamoDBDedupeStoreOptions);
48
- waitFor(hash: string): Promise<T | undefined>;
49
- register(hash: string): Promise<string>;
50
- registerOrJoin(hash: string): Promise<{
51
- jobId: string;
52
- isOwner: boolean;
53
- }>;
54
- complete(hash: string, value: T | undefined): Promise<void>;
55
- fail(hash: string, _error: Error): Promise<void>;
56
- isInProgress(hash: string): Promise<boolean>;
57
- clear(): Promise<void>;
58
- close(): Promise<void>;
59
- destroy(): void;
60
- private deserializeResult;
61
- private assertValidHash;
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
- client?: DynamoDBDocumentClient | DynamoDBClient;
66
- region?: string;
67
- tableName?: string;
68
- defaultConfig?: RateLimitConfig;
69
- resourceConfigs?: Map<string, RateLimitConfig>;
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
- private readonly docClient;
73
- private readonly rawClient;
74
- private readonly isClientManaged;
75
- private readonly tableName;
76
- private defaultConfig;
77
- private resourceConfigs;
78
- private isDestroyed;
79
- constructor({ client, region, tableName, defaultConfig, resourceConfigs, }?: DynamoDBRateLimitStoreOptions);
80
- canProceed(resource: string): Promise<boolean>;
81
- acquire(resource: string): Promise<boolean>;
82
- record(resource: string): Promise<void>;
83
- getStatus(resource: string): Promise<{
84
- remaining: number;
85
- resetTime: Date;
86
- limit: number;
87
- }>;
88
- reset(resource: string): Promise<void>;
89
- getWaitTime(resource: string): Promise<number>;
90
- setResourceConfig(resource: string, config: RateLimitConfig): void;
91
- getResourceConfig(resource: string): RateLimitConfig;
92
- clear(): Promise<void>;
93
- close(): Promise<void>;
94
- destroy(): void;
95
- private countRequestsInWindow;
96
- private hasCapacityInWindow;
97
- private deleteResourceItems;
98
- private assertValidResource;
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
- client?: DynamoDBDocumentClient | DynamoDBClient;
103
- region?: string;
104
- tableName?: string;
105
- defaultConfig?: RateLimitConfig;
106
- resourceConfigs?: Map<string, RateLimitConfig>;
107
- adaptiveConfig?: Partial<z.input<typeof AdaptiveConfigSchema>>;
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
- private readonly docClient;
111
- private readonly rawClient;
112
- private readonly isClientManaged;
113
- private readonly tableName;
114
- private defaultConfig;
115
- private resourceConfigs;
116
- private isDestroyed;
117
- private capacityCalculator;
118
- private activityMetrics;
119
- private lastCapacityUpdate;
120
- private cachedCapacity;
121
- private readonly maxMetricSamples;
122
- constructor({ client, region, tableName, defaultConfig, resourceConfigs, adaptiveConfig, }?: DynamoDBAdaptiveRateLimitStoreOptions);
123
- canProceed(resource: string, priority?: RequestPriority): Promise<boolean>;
124
- acquire(resource: string, priority?: RequestPriority): Promise<boolean>;
125
- record(resource: string, priority?: RequestPriority): Promise<void>;
126
- getStatus(resource: string): Promise<{
127
- remaining: number;
128
- resetTime: Date;
129
- limit: number;
130
- adaptive?: {
131
- userReserved: number;
132
- backgroundMax: number;
133
- backgroundPaused: boolean;
134
- recentUserActivity: number;
135
- reason: string;
136
- };
137
- }>;
138
- reset(resource: string): Promise<void>;
139
- getWaitTime(resource: string, priority?: RequestPriority): Promise<number>;
140
- setResourceConfig(resource: string, config: RateLimitConfig): void;
141
- getResourceConfig(resource: string): RateLimitConfig;
142
- clear(): Promise<void>;
143
- close(): Promise<void>;
144
- destroy(): void;
145
- private calculateCurrentCapacity;
146
- private getOrCreateActivityMetrics;
147
- private ensureActivityMetrics;
148
- private getCurrentUsage;
149
- private hasPriorityCapacityInWindow;
150
- private cleanupOldRequests;
151
- private pushRecentRequest;
152
- private getResourceLimit;
153
- private getDefaultCapacity;
154
- private deleteResourceItems;
155
- private assertValidResource;
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 = "http-client-toolkit";
203
+ declare const DEFAULT_TABLE_NAME = 'http-client-toolkit';
159
204
  declare const TABLE_SCHEMA: {
160
- KeySchema: Array<KeySchemaElement>;
161
- AttributeDefinitions: Array<AttributeDefinition>;
162
- GlobalSecondaryIndexes: Array<GlobalSecondaryIndex>;
205
+ KeySchema: Array<KeySchemaElement>;
206
+ AttributeDefinitions: Array<AttributeDefinition>;
207
+ GlobalSecondaryIndexes: Array<GlobalSecondaryIndex>;
163
208
  };
164
209
 
165
- export { DEFAULT_TABLE_NAME, DynamoDBAdaptiveRateLimitStore, type DynamoDBAdaptiveRateLimitStoreOptions, DynamoDBCacheStore, type DynamoDBCacheStoreOptions, DynamoDBDedupeStore, type DynamoDBDedupeStoreOptions, DynamoDBRateLimitStore, type DynamoDBRateLimitStoreOptions, TABLE_SCHEMA };
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
+ };