ml-cache 1.0.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/LICENSE +21 -0
- package/README.md +599 -0
- package/dist/client.d.ts +175 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +411 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +184 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +236 -0
- package/dist/constants.js.map +1 -0
- package/dist/esm/client.d.ts +175 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +407 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/constants.d.ts +184 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +233 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.d.ts +58 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/queue.d.ts +106 -0
- package/dist/esm/queue.d.ts.map +1 -0
- package/dist/esm/queue.js +207 -0
- package/dist/esm/queue.js.map +1 -0
- package/dist/esm/storage/glacier-storage.d.ts +77 -0
- package/dist/esm/storage/glacier-storage.d.ts.map +1 -0
- package/dist/esm/storage/glacier-storage.js +133 -0
- package/dist/esm/storage/glacier-storage.js.map +1 -0
- package/dist/esm/storage/index.d.ts +7 -0
- package/dist/esm/storage/index.d.ts.map +1 -0
- package/dist/esm/storage/index.js +7 -0
- package/dist/esm/storage/index.js.map +1 -0
- package/dist/esm/storage/s3-storage.d.ts +89 -0
- package/dist/esm/storage/s3-storage.d.ts.map +1 -0
- package/dist/esm/storage/s3-storage.js +161 -0
- package/dist/esm/storage/s3-storage.js.map +1 -0
- package/dist/esm/types/index.d.ts +337 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +6 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/helpers.d.ts +132 -0
- package/dist/esm/utils/helpers.d.ts.map +1 -0
- package/dist/esm/utils/helpers.js +198 -0
- package/dist/esm/utils/helpers.js.map +1 -0
- package/dist/esm/utils/index.d.ts +8 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +110 -0
- package/dist/esm/utils/logger.d.ts.map +1 -0
- package/dist/esm/utils/logger.js +177 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/validator.d.ts +77 -0
- package/dist/esm/utils/validator.d.ts.map +1 -0
- package/dist/esm/utils/validator.js +208 -0
- package/dist/esm/utils/validator.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +72 -0
- package/dist/queue.d.ts +106 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +211 -0
- package/dist/queue.js.map +1 -0
- package/dist/storage/glacier-storage.d.ts +77 -0
- package/dist/storage/glacier-storage.d.ts.map +1 -0
- package/dist/storage/glacier-storage.js +137 -0
- package/dist/storage/glacier-storage.js.map +1 -0
- package/dist/storage/index.d.ts +7 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +12 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/s3-storage.d.ts +89 -0
- package/dist/storage/s3-storage.d.ts.map +1 -0
- package/dist/storage/s3-storage.js +165 -0
- package/dist/storage/s3-storage.js.map +1 -0
- package/dist/types/index.d.ts +337 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/helpers.d.ts +132 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +215 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +35 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +110 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +181 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validator.d.ts +77 -0
- package/dist/utils/validator.d.ts.map +1 -0
- package/dist/utils/validator.js +221 -0
- package/dist/utils/validator.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main ML Cache SDK client
|
|
3
|
+
* @module ml-cache/client
|
|
4
|
+
*/
|
|
5
|
+
import { DEFAULT_BATCH_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_LOG_CONFIG, SDK_VERSION, SHUTDOWN_GRACE_PERIOD_MS, } from './constants';
|
|
6
|
+
import { Logger, validateConfig, validateEvent, enrichEvent, calculateRetryDelay, sleep, } from './utils';
|
|
7
|
+
import { S3Storage } from './storage/s3-storage';
|
|
8
|
+
import { GlacierStorage } from './storage/glacier-storage';
|
|
9
|
+
import { EventQueue } from './queue';
|
|
10
|
+
/**
|
|
11
|
+
* ML Cache SDK client for collecting and storing events for future ML training
|
|
12
|
+
* @class MLCacheClient
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const client = new MLCacheClient({
|
|
16
|
+
* credentials: {
|
|
17
|
+
* accessKeyId: 'YOUR_ACCESS_KEY',
|
|
18
|
+
* secretAccessKey: 'YOUR_SECRET_KEY',
|
|
19
|
+
* },
|
|
20
|
+
* s3: {
|
|
21
|
+
* bucket: 'my-ml-data-bucket',
|
|
22
|
+
* region: 'us-east-1',
|
|
23
|
+
* },
|
|
24
|
+
* storageMode: 'S3',
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* await client.track({
|
|
28
|
+
* eventType: 'purchase',
|
|
29
|
+
* properties: {
|
|
30
|
+
* productId: '12345',
|
|
31
|
+
* amount: 99.99,
|
|
32
|
+
* },
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export class MLCacheClient {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new MLCacheClient instance
|
|
39
|
+
* @param {MLCacheConfig} config - SDK configuration
|
|
40
|
+
* @throws {ValidationError} If configuration is invalid
|
|
41
|
+
*/
|
|
42
|
+
constructor(config) {
|
|
43
|
+
/** @private */
|
|
44
|
+
this.s3Storage = null;
|
|
45
|
+
/** @private */
|
|
46
|
+
this.glacierStorage = null;
|
|
47
|
+
/** @private */
|
|
48
|
+
this.isInitialized = false;
|
|
49
|
+
/** @private */
|
|
50
|
+
this.isShuttingDown = false;
|
|
51
|
+
/** @private */
|
|
52
|
+
this.lastFlush = null;
|
|
53
|
+
/** @private */
|
|
54
|
+
this.lastError = null;
|
|
55
|
+
/** @private */
|
|
56
|
+
this.eventCallbacks = [];
|
|
57
|
+
/** @private */
|
|
58
|
+
this.errorCallbacks = [];
|
|
59
|
+
/** @private */
|
|
60
|
+
this.flushCallbacks = [];
|
|
61
|
+
validateConfig(config);
|
|
62
|
+
this.config = config;
|
|
63
|
+
this.batchConfig = { ...DEFAULT_BATCH_CONFIG, ...config.batch };
|
|
64
|
+
this.retryConfig = { ...DEFAULT_RETRY_CONFIG, ...config.retry };
|
|
65
|
+
const logConfig = {
|
|
66
|
+
...DEFAULT_LOG_CONFIG,
|
|
67
|
+
...config.log,
|
|
68
|
+
level: config.debug ? 'debug' : config.log?.level || 'info',
|
|
69
|
+
};
|
|
70
|
+
this.logger = new Logger(logConfig);
|
|
71
|
+
this.queue = new EventQueue(this.batchConfig, this.logger);
|
|
72
|
+
this.queue.setOnBatchReady(this.handleBatchReady.bind(this));
|
|
73
|
+
this.initializeStorage();
|
|
74
|
+
this.isInitialized = true;
|
|
75
|
+
this.logger.info('MLCacheClient initialized', {
|
|
76
|
+
storageMode: config.storageMode,
|
|
77
|
+
batchEnabled: this.batchConfig.enabled,
|
|
78
|
+
version: SDK_VERSION,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Initializes storage providers based on configuration
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
initializeStorage() {
|
|
86
|
+
if (this.config.storageMode === 'S3' ||
|
|
87
|
+
this.config.storageMode === 'S3_TO_GLACIER') {
|
|
88
|
+
if (this.config.s3) {
|
|
89
|
+
this.s3Storage = new S3Storage(this.config.s3, this.config.credentials, this.logger.child('s3'));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (this.config.storageMode === 'GLACIER') {
|
|
93
|
+
if (this.config.glacier) {
|
|
94
|
+
this.glacierStorage = new GlacierStorage(this.config.glacier, this.config.credentials, this.logger.child('glacier'));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Handles a batch of events ready for storage
|
|
100
|
+
* @private
|
|
101
|
+
* @param {MLCacheEvent[]} events - Events to store
|
|
102
|
+
* @param {string} batchId - Batch identifier
|
|
103
|
+
*/
|
|
104
|
+
async handleBatchReady(events, batchId) {
|
|
105
|
+
const result = await this.storeEventsWithRetry(events, batchId);
|
|
106
|
+
this.flushCallbacks.forEach((callback) => callback(result));
|
|
107
|
+
if (result.success) {
|
|
108
|
+
this.lastFlush = new Date();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Stores events with retry logic
|
|
113
|
+
* @private
|
|
114
|
+
* @param {MLCacheEvent[]} events - Events to store
|
|
115
|
+
* @param {string} batchId - Batch identifier
|
|
116
|
+
* @returns {Promise<FlushResult>} Flush result
|
|
117
|
+
*/
|
|
118
|
+
async storeEventsWithRetry(events, batchId) {
|
|
119
|
+
const result = {
|
|
120
|
+
success: false,
|
|
121
|
+
eventCount: events.length,
|
|
122
|
+
storageLocations: [],
|
|
123
|
+
failedEventIds: [],
|
|
124
|
+
errors: [],
|
|
125
|
+
};
|
|
126
|
+
for (let attempt = 0; attempt <= this.retryConfig.maxRetries; attempt++) {
|
|
127
|
+
try {
|
|
128
|
+
if (this.s3Storage) {
|
|
129
|
+
const s3Result = await this.s3Storage.storeBatch(events, batchId);
|
|
130
|
+
if (s3Result.success) {
|
|
131
|
+
result.success = true;
|
|
132
|
+
result.storageLocations.push(`s3://${s3Result.bucket}/${s3Result.key}`);
|
|
133
|
+
this.logger.info('Batch stored successfully', {
|
|
134
|
+
batchId,
|
|
135
|
+
eventCount: events.length,
|
|
136
|
+
location: result.storageLocations[0],
|
|
137
|
+
});
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
throw new Error(s3Result.error || 'S3 storage failed');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else if (this.glacierStorage) {
|
|
145
|
+
const glacierResult = await this.glacierStorage.archiveEvents(events, batchId);
|
|
146
|
+
if (glacierResult.success) {
|
|
147
|
+
result.success = true;
|
|
148
|
+
result.storageLocations.push(`glacier://${glacierResult.vaultName}/${glacierResult.archiveId}`);
|
|
149
|
+
this.logger.info('Batch archived successfully', {
|
|
150
|
+
batchId,
|
|
151
|
+
eventCount: events.length,
|
|
152
|
+
archiveId: glacierResult.archiveId,
|
|
153
|
+
});
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
throw new Error(glacierResult.error || 'Glacier storage failed');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
throw new Error('No storage provider configured');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
166
|
+
result.errors.push(errorMessage);
|
|
167
|
+
this.lastError = errorMessage;
|
|
168
|
+
if (attempt < this.retryConfig.maxRetries) {
|
|
169
|
+
const delay = calculateRetryDelay(attempt, this.retryConfig.initialDelayMs, this.retryConfig.maxDelayMs, this.retryConfig.exponentialBackoff);
|
|
170
|
+
this.logger.warn('Storage failed, retrying', {
|
|
171
|
+
batchId,
|
|
172
|
+
attempt: attempt + 1,
|
|
173
|
+
maxRetries: this.retryConfig.maxRetries,
|
|
174
|
+
delayMs: delay,
|
|
175
|
+
error: errorMessage,
|
|
176
|
+
});
|
|
177
|
+
await sleep(delay);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this.logger.error('Storage failed after all retries', {
|
|
181
|
+
batchId,
|
|
182
|
+
eventCount: events.length,
|
|
183
|
+
errors: result.errors,
|
|
184
|
+
});
|
|
185
|
+
result.failedEventIds = events
|
|
186
|
+
.map((e) => e.eventId)
|
|
187
|
+
.filter((id) => id !== undefined);
|
|
188
|
+
events.forEach((event) => {
|
|
189
|
+
this.errorCallbacks.forEach((callback) => callback(new Error(errorMessage), event));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Tracks an event
|
|
198
|
+
* @param {MLCacheEvent} event - Event to track
|
|
199
|
+
* @returns {Promise<TrackResult>} Track result
|
|
200
|
+
* @example
|
|
201
|
+
* ```typescript
|
|
202
|
+
* const result = await client.track({
|
|
203
|
+
* eventType: 'page_view',
|
|
204
|
+
* properties: {
|
|
205
|
+
* page: '/home',
|
|
206
|
+
* referrer: 'google.com',
|
|
207
|
+
* },
|
|
208
|
+
* context: {
|
|
209
|
+
* user: { userId: 'user123' },
|
|
210
|
+
* },
|
|
211
|
+
* });
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
async track(event) {
|
|
215
|
+
const result = {
|
|
216
|
+
success: false,
|
|
217
|
+
eventId: '',
|
|
218
|
+
queued: false,
|
|
219
|
+
};
|
|
220
|
+
if (this.isShuttingDown) {
|
|
221
|
+
result.error = 'Client is shutting down';
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
try {
|
|
225
|
+
validateEvent(event);
|
|
226
|
+
const enrichedEvent = enrichEvent(event, {
|
|
227
|
+
sourceApp: this.config.sourceApp,
|
|
228
|
+
environment: this.config.environment,
|
|
229
|
+
});
|
|
230
|
+
result.eventId = enrichedEvent.eventId || '';
|
|
231
|
+
this.eventCallbacks.forEach((callback) => callback(enrichedEvent));
|
|
232
|
+
if (this.batchConfig.enabled) {
|
|
233
|
+
const enqueued = this.queue.enqueue(enrichedEvent);
|
|
234
|
+
result.success = enqueued;
|
|
235
|
+
result.queued = enqueued;
|
|
236
|
+
if (!enqueued) {
|
|
237
|
+
result.error = 'Queue is full';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
const flushResult = await this.storeEventsWithRetry([enrichedEvent], enrichedEvent.eventId || '');
|
|
242
|
+
result.success = flushResult.success;
|
|
243
|
+
result.storageLocation = flushResult.storageLocations[0];
|
|
244
|
+
if (!result.success) {
|
|
245
|
+
result.error = flushResult.errors.join('; ');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
result.error = error instanceof Error ? error.message : String(error);
|
|
252
|
+
this.logger.error('Track failed', {
|
|
253
|
+
eventType: event.eventType,
|
|
254
|
+
error: result.error,
|
|
255
|
+
});
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Identifies a user with traits
|
|
261
|
+
* @param {string} userId - User identifier
|
|
262
|
+
* @param {Record<string, unknown>} [traits] - User traits
|
|
263
|
+
* @returns {Promise<TrackResult>} Track result
|
|
264
|
+
* @example
|
|
265
|
+
* ```typescript
|
|
266
|
+
* await client.identify('user123', {
|
|
267
|
+
* email: 'user@example.com',
|
|
268
|
+
* plan: 'premium',
|
|
269
|
+
* });
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
async identify(userId, traits) {
|
|
273
|
+
return this.track({
|
|
274
|
+
eventType: 'identify',
|
|
275
|
+
context: {
|
|
276
|
+
user: {
|
|
277
|
+
userId,
|
|
278
|
+
traits,
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
properties: traits,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Tracks a page view
|
|
286
|
+
* @param {string} name - Page name
|
|
287
|
+
* @param {Record<string, unknown>} [properties] - Page properties
|
|
288
|
+
* @returns {Promise<TrackResult>} Track result
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* await client.page('Home', {
|
|
292
|
+
* url: 'https://example.com',
|
|
293
|
+
* title: 'Welcome Home',
|
|
294
|
+
* });
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
async page(name, properties) {
|
|
298
|
+
return this.track({
|
|
299
|
+
eventType: 'page',
|
|
300
|
+
properties: {
|
|
301
|
+
name,
|
|
302
|
+
...properties,
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Flushes all queued events
|
|
308
|
+
* @returns {Promise<FlushResult>} Flush result
|
|
309
|
+
*/
|
|
310
|
+
async flush() {
|
|
311
|
+
this.logger.debug('Manual flush triggered');
|
|
312
|
+
const events = await this.queue.flush();
|
|
313
|
+
if (events.length === 0) {
|
|
314
|
+
return {
|
|
315
|
+
success: true,
|
|
316
|
+
eventCount: 0,
|
|
317
|
+
storageLocations: [],
|
|
318
|
+
failedEventIds: [],
|
|
319
|
+
errors: [],
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
success: true,
|
|
324
|
+
eventCount: events.length,
|
|
325
|
+
storageLocations: [],
|
|
326
|
+
failedEventIds: [],
|
|
327
|
+
errors: [],
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Gets the health status of the client
|
|
332
|
+
* @returns {Promise<HealthStatus>} Health status
|
|
333
|
+
*/
|
|
334
|
+
async getHealth() {
|
|
335
|
+
const status = {
|
|
336
|
+
healthy: this.isInitialized && !this.isShuttingDown,
|
|
337
|
+
s3Connected: false,
|
|
338
|
+
glacierConnected: false,
|
|
339
|
+
queueSize: this.queue.size(),
|
|
340
|
+
lastFlush: this.lastFlush?.toISOString(),
|
|
341
|
+
lastError: this.lastError || undefined,
|
|
342
|
+
};
|
|
343
|
+
if (this.s3Storage) {
|
|
344
|
+
status.s3Connected = await this.s3Storage.testConnection();
|
|
345
|
+
}
|
|
346
|
+
if (this.glacierStorage) {
|
|
347
|
+
status.glacierConnected = await this.glacierStorage.testConnection();
|
|
348
|
+
}
|
|
349
|
+
status.healthy =
|
|
350
|
+
status.healthy && (status.s3Connected || status.glacierConnected);
|
|
351
|
+
return status;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Registers an event callback
|
|
355
|
+
* @param {EventCallback} callback - Callback function
|
|
356
|
+
*/
|
|
357
|
+
onEvent(callback) {
|
|
358
|
+
this.eventCallbacks.push(callback);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Registers an error callback
|
|
362
|
+
* @param {ErrorCallback} callback - Callback function
|
|
363
|
+
*/
|
|
364
|
+
onError(callback) {
|
|
365
|
+
this.errorCallbacks.push(callback);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Registers a flush callback
|
|
369
|
+
* @param {FlushCallback} callback - Callback function
|
|
370
|
+
*/
|
|
371
|
+
onFlush(callback) {
|
|
372
|
+
this.flushCallbacks.push(callback);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Gets the current queue size
|
|
376
|
+
* @returns {number} Queue size
|
|
377
|
+
*/
|
|
378
|
+
getQueueSize() {
|
|
379
|
+
return this.queue.size();
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Gets the SDK version
|
|
383
|
+
* @returns {string} SDK version
|
|
384
|
+
*/
|
|
385
|
+
getVersion() {
|
|
386
|
+
return SDK_VERSION;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Shuts down the client gracefully
|
|
390
|
+
* @returns {Promise<void>}
|
|
391
|
+
*/
|
|
392
|
+
async shutdown() {
|
|
393
|
+
if (this.isShuttingDown) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
this.logger.info('Shutting down MLCacheClient');
|
|
397
|
+
this.isShuttingDown = true;
|
|
398
|
+
const shutdownPromise = this.flush();
|
|
399
|
+
const timeoutPromise = sleep(SHUTDOWN_GRACE_PERIOD_MS);
|
|
400
|
+
await Promise.race([shutdownPromise, timeoutPromise]);
|
|
401
|
+
this.queue.destroy();
|
|
402
|
+
this.s3Storage?.destroy();
|
|
403
|
+
this.glacierStorage?.destroy();
|
|
404
|
+
this.logger.info('MLCacheClient shut down complete');
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,MAAM,EACN,cAAc,EACd,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,KAAK,GACN,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,aAAa;IA2CxB;;;;OAIG;IACH,YAAY,MAAqB;QAnCjC,eAAe;QACP,cAAS,GAAqB,IAAI,CAAC;QAE3C,eAAe;QACP,mBAAc,GAA0B,IAAI,CAAC;QAKrD,eAAe;QACP,kBAAa,GAAG,KAAK,CAAC;QAE9B,eAAe;QACP,mBAAc,GAAG,KAAK,CAAC;QAE/B,eAAe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IAAI,CAAC,6BAA6B,CAAC,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAE3B,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAEvD,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC,CAAC;QAEtD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;QAC1B,IAAI,CAAC,cAAc,EAAE,OAAO,EAAE,CAAC;QAE/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Constants and default values for ml-cache SDK
|
|
3
|
+
* @module ml-cache/constants
|
|
4
|
+
*/
|
|
5
|
+
import type { BatchConfig, RetryConfig, LogConfig, S3StorageClass } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Current SDK version
|
|
8
|
+
* @constant
|
|
9
|
+
*/
|
|
10
|
+
export declare const SDK_VERSION = "1.0.0";
|
|
11
|
+
/**
|
|
12
|
+
* SDK name identifier
|
|
13
|
+
* @constant
|
|
14
|
+
*/
|
|
15
|
+
export declare const SDK_NAME = "ml-cache";
|
|
16
|
+
/**
|
|
17
|
+
* Default batch configuration
|
|
18
|
+
* @constant
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_BATCH_CONFIG: BatchConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Default retry configuration
|
|
23
|
+
* @constant
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Default logging configuration
|
|
28
|
+
* @constant
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_LOG_CONFIG: LogConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Default S3 storage class for long-term ML data storage
|
|
33
|
+
* @constant
|
|
34
|
+
*/
|
|
35
|
+
export declare const DEFAULT_S3_STORAGE_CLASS: S3StorageClass;
|
|
36
|
+
/**
|
|
37
|
+
* Default Glacier account ID (uses current account)
|
|
38
|
+
* @constant
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_GLACIER_ACCOUNT_ID = "-";
|
|
41
|
+
/**
|
|
42
|
+
* Maximum size of a single event payload in bytes (256 KB)
|
|
43
|
+
* @constant
|
|
44
|
+
*/
|
|
45
|
+
export declare const MAX_EVENT_SIZE_BYTES: number;
|
|
46
|
+
/**
|
|
47
|
+
* Maximum size of a batch payload in bytes (5 MB for S3 PutObject)
|
|
48
|
+
* @constant
|
|
49
|
+
*/
|
|
50
|
+
export declare const MAX_BATCH_SIZE_BYTES: number;
|
|
51
|
+
/**
|
|
52
|
+
* Minimum size for S3 multipart upload (5 MB)
|
|
53
|
+
* @constant
|
|
54
|
+
*/
|
|
55
|
+
export declare const S3_MULTIPART_THRESHOLD_BYTES: number;
|
|
56
|
+
/**
|
|
57
|
+
* Glacier archive description prefix
|
|
58
|
+
* @constant
|
|
59
|
+
*/
|
|
60
|
+
export declare const GLACIER_ARCHIVE_PREFIX = "ml-cache-events";
|
|
61
|
+
/**
|
|
62
|
+
* S3 object key date format
|
|
63
|
+
* @constant
|
|
64
|
+
*/
|
|
65
|
+
export declare const S3_KEY_DATE_FORMAT = "YYYY/MM/DD";
|
|
66
|
+
/**
|
|
67
|
+
* Default S3 object prefix
|
|
68
|
+
* @constant
|
|
69
|
+
*/
|
|
70
|
+
export declare const DEFAULT_S3_PREFIX = "ml-cache-events";
|
|
71
|
+
/**
|
|
72
|
+
* Reserved event property names that cannot be overwritten
|
|
73
|
+
* @constant
|
|
74
|
+
*/
|
|
75
|
+
export declare const RESERVED_EVENT_PROPERTIES: readonly string[];
|
|
76
|
+
/**
|
|
77
|
+
* Valid event type pattern (alphanumeric with underscores)
|
|
78
|
+
* @constant
|
|
79
|
+
*/
|
|
80
|
+
export declare const EVENT_TYPE_PATTERN: RegExp;
|
|
81
|
+
/**
|
|
82
|
+
* Maximum event type length
|
|
83
|
+
* @constant
|
|
84
|
+
*/
|
|
85
|
+
export declare const MAX_EVENT_TYPE_LENGTH = 128;
|
|
86
|
+
/**
|
|
87
|
+
* Maximum property key length
|
|
88
|
+
* @constant
|
|
89
|
+
*/
|
|
90
|
+
export declare const MAX_PROPERTY_KEY_LENGTH = 256;
|
|
91
|
+
/**
|
|
92
|
+
* Health check interval in milliseconds (5 minutes)
|
|
93
|
+
* @constant
|
|
94
|
+
*/
|
|
95
|
+
export declare const HEALTH_CHECK_INTERVAL_MS: number;
|
|
96
|
+
/**
|
|
97
|
+
* Connection timeout in milliseconds (30 seconds)
|
|
98
|
+
* @constant
|
|
99
|
+
*/
|
|
100
|
+
export declare const CONNECTION_TIMEOUT_MS = 30000;
|
|
101
|
+
/**
|
|
102
|
+
* Request timeout in milliseconds (2 minutes)
|
|
103
|
+
* @constant
|
|
104
|
+
*/
|
|
105
|
+
export declare const REQUEST_TIMEOUT_MS: number;
|
|
106
|
+
/**
|
|
107
|
+
* Shutdown grace period in milliseconds (10 seconds)
|
|
108
|
+
* @constant
|
|
109
|
+
*/
|
|
110
|
+
export declare const SHUTDOWN_GRACE_PERIOD_MS = 10000;
|
|
111
|
+
/**
|
|
112
|
+
* SDK error codes
|
|
113
|
+
* @constant
|
|
114
|
+
*/
|
|
115
|
+
export declare const ERROR_CODES: {
|
|
116
|
+
/** Configuration error */
|
|
117
|
+
readonly CONFIG_ERROR: "ML_CACHE_CONFIG_ERROR";
|
|
118
|
+
/** Validation error */
|
|
119
|
+
readonly VALIDATION_ERROR: "ML_CACHE_VALIDATION_ERROR";
|
|
120
|
+
/** S3 storage error */
|
|
121
|
+
readonly S3_ERROR: "ML_CACHE_S3_ERROR";
|
|
122
|
+
/** Glacier storage error */
|
|
123
|
+
readonly GLACIER_ERROR: "ML_CACHE_GLACIER_ERROR";
|
|
124
|
+
/** Network error */
|
|
125
|
+
readonly NETWORK_ERROR: "ML_CACHE_NETWORK_ERROR";
|
|
126
|
+
/** Timeout error */
|
|
127
|
+
readonly TIMEOUT_ERROR: "ML_CACHE_TIMEOUT_ERROR";
|
|
128
|
+
/** Queue full error */
|
|
129
|
+
readonly QUEUE_FULL_ERROR: "ML_CACHE_QUEUE_FULL_ERROR";
|
|
130
|
+
/** Event too large error */
|
|
131
|
+
readonly EVENT_TOO_LARGE_ERROR: "ML_CACHE_EVENT_TOO_LARGE_ERROR";
|
|
132
|
+
/** Batch error */
|
|
133
|
+
readonly BATCH_ERROR: "ML_CACHE_BATCH_ERROR";
|
|
134
|
+
/** Shutdown error */
|
|
135
|
+
readonly SHUTDOWN_ERROR: "ML_CACHE_SHUTDOWN_ERROR";
|
|
136
|
+
/** Unknown error */
|
|
137
|
+
readonly UNKNOWN_ERROR: "ML_CACHE_UNKNOWN_ERROR";
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Error code type
|
|
141
|
+
* @typedef ErrorCode
|
|
142
|
+
*/
|
|
143
|
+
export type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
144
|
+
/**
|
|
145
|
+
* Maximum queue size (number of events)
|
|
146
|
+
* @constant
|
|
147
|
+
*/
|
|
148
|
+
export declare const MAX_QUEUE_SIZE = 10000;
|
|
149
|
+
/**
|
|
150
|
+
* Queue warning threshold (80% of max)
|
|
151
|
+
* @constant
|
|
152
|
+
*/
|
|
153
|
+
export declare const QUEUE_WARNING_THRESHOLD = 0.8;
|
|
154
|
+
/**
|
|
155
|
+
* Content type for stored events (NDJSON)
|
|
156
|
+
* @constant
|
|
157
|
+
*/
|
|
158
|
+
export declare const CONTENT_TYPE_NDJSON = "application/x-ndjson";
|
|
159
|
+
/**
|
|
160
|
+
* Content type for compressed events
|
|
161
|
+
* @constant
|
|
162
|
+
*/
|
|
163
|
+
export declare const CONTENT_TYPE_GZIP = "application/gzip";
|
|
164
|
+
/**
|
|
165
|
+
* Environment variable names for configuration
|
|
166
|
+
* @constant
|
|
167
|
+
*/
|
|
168
|
+
export declare const ENV_VARS: {
|
|
169
|
+
/** AWS access key ID */
|
|
170
|
+
readonly AWS_ACCESS_KEY_ID: "AWS_ACCESS_KEY_ID";
|
|
171
|
+
/** AWS secret access key */
|
|
172
|
+
readonly AWS_SECRET_ACCESS_KEY: "AWS_SECRET_ACCESS_KEY";
|
|
173
|
+
/** AWS session token */
|
|
174
|
+
readonly AWS_SESSION_TOKEN: "AWS_SESSION_TOKEN";
|
|
175
|
+
/** AWS region */
|
|
176
|
+
readonly AWS_REGION: "AWS_REGION";
|
|
177
|
+
/** S3 bucket name */
|
|
178
|
+
readonly ML_CACHE_S3_BUCKET: "ML_CACHE_S3_BUCKET";
|
|
179
|
+
/** Glacier vault name */
|
|
180
|
+
readonly ML_CACHE_GLACIER_VAULT: "ML_CACHE_GLACIER_VAULT";
|
|
181
|
+
/** Debug mode */
|
|
182
|
+
readonly ML_CACHE_DEBUG: "ML_CACHE_DEBUG";
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMnF;;;GAGG;AACH,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC;;;GAGG;AACH,eAAO,MAAM,QAAQ,aAAa,CAAC;AAMnC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAOlC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,WASlC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAOhC,C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