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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ML Cache SDK - Store business events for future ML training
|
|
3
|
+
* @module ml-cache
|
|
4
|
+
* @description
|
|
5
|
+
* ML Cache is a TypeScript SDK designed to collect and store business/product events
|
|
6
|
+
* in cold storage (Amazon S3 Glacier) for future machine learning model training.
|
|
7
|
+
*
|
|
8
|
+
* The core idea is simple: ML training costs are decreasing exponentially, but data
|
|
9
|
+
* collection opportunities are fleeting. Store your data now, train your models later.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { MLCacheClient } from 'ml-cache';
|
|
14
|
+
*
|
|
15
|
+
* const client = new MLCacheClient({
|
|
16
|
+
* credentials: {
|
|
17
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
18
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
19
|
+
* },
|
|
20
|
+
* s3: {
|
|
21
|
+
* bucket: 'my-ml-data-bucket',
|
|
22
|
+
* region: 'us-east-1',
|
|
23
|
+
* storageClass: 'GLACIER',
|
|
24
|
+
* },
|
|
25
|
+
* storageMode: 'S3',
|
|
26
|
+
* sourceApp: 'my-app',
|
|
27
|
+
* environment: 'production',
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Track events
|
|
31
|
+
* await client.track({
|
|
32
|
+
* eventType: 'purchase',
|
|
33
|
+
* properties: {
|
|
34
|
+
* productId: 'SKU-123',
|
|
35
|
+
* amount: 99.99,
|
|
36
|
+
* currency: 'USD',
|
|
37
|
+
* },
|
|
38
|
+
* context: {
|
|
39
|
+
* user: { userId: 'user-456' },
|
|
40
|
+
* },
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Graceful shutdown
|
|
44
|
+
* await client.shutdown();
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @author Nicolas Mondain
|
|
48
|
+
* @license MIT
|
|
49
|
+
* @see {@link https://github.com/nicolasmondain/ml-cache}
|
|
50
|
+
*/
|
|
51
|
+
export { MLCacheClient } from './client';
|
|
52
|
+
export type { AWSCredentials, S3Config, GlacierConfig, S3StorageClass, BaseEvent, UserContext, DeviceContext, PageContext, CampaignContext, EventContext, MLCacheEvent, EventMetadata, StoredEvent, BatchConfig, RetryConfig, LogConfig, LogLevel, LoggerFunction, StorageMode, MLCacheConfig, TrackResult, FlushResult, HealthStatus, EventCallback, ErrorCallback, FlushCallback, } from './types';
|
|
53
|
+
export { SDK_VERSION, SDK_NAME, DEFAULT_BATCH_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_LOG_CONFIG, DEFAULT_S3_STORAGE_CLASS, MAX_EVENT_SIZE_BYTES, MAX_BATCH_SIZE_BYTES, MAX_QUEUE_SIZE, ERROR_CODES, ENV_VARS, } from './constants';
|
|
54
|
+
export { Logger, ValidationError, validateConfig, validateEvent, generateEventId, generateTimestamp, generateBatchId, enrichEvent, serializeEventsToNDJSON, deserializeEventsFromNDJSON, } from './utils';
|
|
55
|
+
export { S3Storage, type S3StorageResult } from './storage/s3-storage';
|
|
56
|
+
export { GlacierStorage, type GlacierStorageResult } from './storage/glacier-storage';
|
|
57
|
+
export { EventQueue, type BatchReadyCallback } from './queue';
|
|
58
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAMH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAMzC,YAAY,EAEV,cAAc,EACd,QAAQ,EACR,aAAa,EACb,cAAc,EAGd,SAAS,EACT,WAAW,EACX,aAAa,EACb,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,EAGX,WAAW,EACX,WAAW,EACX,SAAS,EACT,QAAQ,EACR,cAAc,EACd,WAAW,EACX,aAAa,EAGb,WAAW,EACX,WAAW,EACX,YAAY,EAGZ,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,QAAQ,GACT,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,MAAM,EACN,eAAe,EACf,cAAc,EACd,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,SAAS,CAAC;AAMjB,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAMtF,OAAO,EAAE,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview ML Cache SDK - Store business events for future ML training
|
|
4
|
+
* @module ml-cache
|
|
5
|
+
* @description
|
|
6
|
+
* ML Cache is a TypeScript SDK designed to collect and store business/product events
|
|
7
|
+
* in cold storage (Amazon S3 Glacier) for future machine learning model training.
|
|
8
|
+
*
|
|
9
|
+
* The core idea is simple: ML training costs are decreasing exponentially, but data
|
|
10
|
+
* collection opportunities are fleeting. Store your data now, train your models later.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { MLCacheClient } from 'ml-cache';
|
|
15
|
+
*
|
|
16
|
+
* const client = new MLCacheClient({
|
|
17
|
+
* credentials: {
|
|
18
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
19
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
20
|
+
* },
|
|
21
|
+
* s3: {
|
|
22
|
+
* bucket: 'my-ml-data-bucket',
|
|
23
|
+
* region: 'us-east-1',
|
|
24
|
+
* storageClass: 'GLACIER',
|
|
25
|
+
* },
|
|
26
|
+
* storageMode: 'S3',
|
|
27
|
+
* sourceApp: 'my-app',
|
|
28
|
+
* environment: 'production',
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Track events
|
|
32
|
+
* await client.track({
|
|
33
|
+
* eventType: 'purchase',
|
|
34
|
+
* properties: {
|
|
35
|
+
* productId: 'SKU-123',
|
|
36
|
+
* amount: 99.99,
|
|
37
|
+
* currency: 'USD',
|
|
38
|
+
* },
|
|
39
|
+
* context: {
|
|
40
|
+
* user: { userId: 'user-456' },
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Graceful shutdown
|
|
45
|
+
* await client.shutdown();
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @author Nicolas Mondain
|
|
49
|
+
* @license MIT
|
|
50
|
+
* @see {@link https://github.com/nicolasmondain/ml-cache}
|
|
51
|
+
*/
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.EventQueue = exports.GlacierStorage = exports.S3Storage = exports.deserializeEventsFromNDJSON = exports.serializeEventsToNDJSON = exports.enrichEvent = exports.generateBatchId = exports.generateTimestamp = exports.generateEventId = exports.validateEvent = exports.validateConfig = exports.ValidationError = exports.Logger = exports.ENV_VARS = exports.ERROR_CODES = exports.MAX_QUEUE_SIZE = exports.MAX_BATCH_SIZE_BYTES = exports.MAX_EVENT_SIZE_BYTES = exports.DEFAULT_S3_STORAGE_CLASS = exports.DEFAULT_LOG_CONFIG = exports.DEFAULT_RETRY_CONFIG = exports.DEFAULT_BATCH_CONFIG = exports.SDK_NAME = exports.SDK_VERSION = exports.MLCacheClient = void 0;
|
|
54
|
+
/* ============================================================================
|
|
55
|
+
* Main Client Export
|
|
56
|
+
* ============================================================================ */
|
|
57
|
+
var client_1 = require("./client");
|
|
58
|
+
Object.defineProperty(exports, "MLCacheClient", { enumerable: true, get: function () { return client_1.MLCacheClient; } });
|
|
59
|
+
/* ============================================================================
|
|
60
|
+
* Constants Export
|
|
61
|
+
* ============================================================================ */
|
|
62
|
+
var constants_1 = require("./constants");
|
|
63
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return constants_1.SDK_VERSION; } });
|
|
64
|
+
Object.defineProperty(exports, "SDK_NAME", { enumerable: true, get: function () { return constants_1.SDK_NAME; } });
|
|
65
|
+
Object.defineProperty(exports, "DEFAULT_BATCH_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_BATCH_CONFIG; } });
|
|
66
|
+
Object.defineProperty(exports, "DEFAULT_RETRY_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_RETRY_CONFIG; } });
|
|
67
|
+
Object.defineProperty(exports, "DEFAULT_LOG_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_LOG_CONFIG; } });
|
|
68
|
+
Object.defineProperty(exports, "DEFAULT_S3_STORAGE_CLASS", { enumerable: true, get: function () { return constants_1.DEFAULT_S3_STORAGE_CLASS; } });
|
|
69
|
+
Object.defineProperty(exports, "MAX_EVENT_SIZE_BYTES", { enumerable: true, get: function () { return constants_1.MAX_EVENT_SIZE_BYTES; } });
|
|
70
|
+
Object.defineProperty(exports, "MAX_BATCH_SIZE_BYTES", { enumerable: true, get: function () { return constants_1.MAX_BATCH_SIZE_BYTES; } });
|
|
71
|
+
Object.defineProperty(exports, "MAX_QUEUE_SIZE", { enumerable: true, get: function () { return constants_1.MAX_QUEUE_SIZE; } });
|
|
72
|
+
Object.defineProperty(exports, "ERROR_CODES", { enumerable: true, get: function () { return constants_1.ERROR_CODES; } });
|
|
73
|
+
Object.defineProperty(exports, "ENV_VARS", { enumerable: true, get: function () { return constants_1.ENV_VARS; } });
|
|
74
|
+
/* ============================================================================
|
|
75
|
+
* Utility Exports
|
|
76
|
+
* ============================================================================ */
|
|
77
|
+
var utils_1 = require("./utils");
|
|
78
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return utils_1.Logger; } });
|
|
79
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return utils_1.ValidationError; } });
|
|
80
|
+
Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return utils_1.validateConfig; } });
|
|
81
|
+
Object.defineProperty(exports, "validateEvent", { enumerable: true, get: function () { return utils_1.validateEvent; } });
|
|
82
|
+
Object.defineProperty(exports, "generateEventId", { enumerable: true, get: function () { return utils_1.generateEventId; } });
|
|
83
|
+
Object.defineProperty(exports, "generateTimestamp", { enumerable: true, get: function () { return utils_1.generateTimestamp; } });
|
|
84
|
+
Object.defineProperty(exports, "generateBatchId", { enumerable: true, get: function () { return utils_1.generateBatchId; } });
|
|
85
|
+
Object.defineProperty(exports, "enrichEvent", { enumerable: true, get: function () { return utils_1.enrichEvent; } });
|
|
86
|
+
Object.defineProperty(exports, "serializeEventsToNDJSON", { enumerable: true, get: function () { return utils_1.serializeEventsToNDJSON; } });
|
|
87
|
+
Object.defineProperty(exports, "deserializeEventsFromNDJSON", { enumerable: true, get: function () { return utils_1.deserializeEventsFromNDJSON; } });
|
|
88
|
+
/* ============================================================================
|
|
89
|
+
* Storage Exports
|
|
90
|
+
* ============================================================================ */
|
|
91
|
+
var s3_storage_1 = require("./storage/s3-storage");
|
|
92
|
+
Object.defineProperty(exports, "S3Storage", { enumerable: true, get: function () { return s3_storage_1.S3Storage; } });
|
|
93
|
+
var glacier_storage_1 = require("./storage/glacier-storage");
|
|
94
|
+
Object.defineProperty(exports, "GlacierStorage", { enumerable: true, get: function () { return glacier_storage_1.GlacierStorage; } });
|
|
95
|
+
/* ============================================================================
|
|
96
|
+
* Queue Export
|
|
97
|
+
* ============================================================================ */
|
|
98
|
+
var queue_1 = require("./queue");
|
|
99
|
+
Object.defineProperty(exports, "EventQueue", { enumerable: true, get: function () { return queue_1.EventQueue; } });
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;;;AAEH;;kFAEkF;AAElF,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AA4CtB;;kFAEkF;AAElF,yCAYqB;AAXnB,wGAAA,WAAW,OAAA;AACX,qGAAA,QAAQ,OAAA;AACR,iHAAA,oBAAoB,OAAA;AACpB,iHAAA,oBAAoB,OAAA;AACpB,+GAAA,kBAAkB,OAAA;AAClB,qHAAA,wBAAwB,OAAA;AACxB,iHAAA,oBAAoB,OAAA;AACpB,iHAAA,oBAAoB,OAAA;AACpB,2GAAA,cAAc,OAAA;AACd,wGAAA,WAAW,OAAA;AACX,qGAAA,QAAQ,OAAA;AAGV;;kFAEkF;AAElF,iCAWiB;AAVf,+FAAA,MAAM,OAAA;AACN,wGAAA,eAAe,OAAA;AACf,uGAAA,cAAc,OAAA;AACd,sGAAA,aAAa,OAAA;AACb,wGAAA,eAAe,OAAA;AACf,0GAAA,iBAAiB,OAAA;AACjB,wGAAA,eAAe,OAAA;AACf,oGAAA,WAAW,OAAA;AACX,gHAAA,uBAAuB,OAAA;AACvB,oHAAA,2BAA2B,OAAA;AAG7B;;kFAEkF;AAElF,mDAAuE;AAA9D,uGAAA,SAAS,OAAA;AAClB,6DAAsF;AAA7E,iHAAA,cAAc,OAAA;AAEvB;;kFAEkF;AAElF,iCAA8D;AAArD,mGAAA,UAAU,OAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ML Cache SDK - Store business events for future ML training
|
|
3
|
+
* @module ml-cache
|
|
4
|
+
* @description
|
|
5
|
+
* ML Cache is a TypeScript SDK designed to collect and store business/product events
|
|
6
|
+
* in cold storage (Amazon S3 Glacier) for future machine learning model training.
|
|
7
|
+
*
|
|
8
|
+
* The core idea is simple: ML training costs are decreasing exponentially, but data
|
|
9
|
+
* collection opportunities are fleeting. Store your data now, train your models later.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { MLCacheClient } from 'ml-cache';
|
|
14
|
+
*
|
|
15
|
+
* const client = new MLCacheClient({
|
|
16
|
+
* credentials: {
|
|
17
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
18
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
19
|
+
* },
|
|
20
|
+
* s3: {
|
|
21
|
+
* bucket: 'my-ml-data-bucket',
|
|
22
|
+
* region: 'us-east-1',
|
|
23
|
+
* storageClass: 'GLACIER',
|
|
24
|
+
* },
|
|
25
|
+
* storageMode: 'S3',
|
|
26
|
+
* sourceApp: 'my-app',
|
|
27
|
+
* environment: 'production',
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Track events
|
|
31
|
+
* await client.track({
|
|
32
|
+
* eventType: 'purchase',
|
|
33
|
+
* properties: {
|
|
34
|
+
* productId: 'SKU-123',
|
|
35
|
+
* amount: 99.99,
|
|
36
|
+
* currency: 'USD',
|
|
37
|
+
* },
|
|
38
|
+
* context: {
|
|
39
|
+
* user: { userId: 'user-456' },
|
|
40
|
+
* },
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Graceful shutdown
|
|
44
|
+
* await client.shutdown();
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @author Nicolas Mondain
|
|
48
|
+
* @license MIT
|
|
49
|
+
* @see {@link https://github.com/nicolasmondain/ml-cache}
|
|
50
|
+
*/
|
|
51
|
+
/* ============================================================================
|
|
52
|
+
* Main Client Export
|
|
53
|
+
* ============================================================================ */
|
|
54
|
+
export { MLCacheClient } from './client';
|
|
55
|
+
/* ============================================================================
|
|
56
|
+
* Constants Export
|
|
57
|
+
* ============================================================================ */
|
|
58
|
+
export { SDK_VERSION, SDK_NAME, DEFAULT_BATCH_CONFIG, DEFAULT_RETRY_CONFIG, DEFAULT_LOG_CONFIG, DEFAULT_S3_STORAGE_CLASS, MAX_EVENT_SIZE_BYTES, MAX_BATCH_SIZE_BYTES, MAX_QUEUE_SIZE, ERROR_CODES, ENV_VARS, } from './constants';
|
|
59
|
+
/* ============================================================================
|
|
60
|
+
* Utility Exports
|
|
61
|
+
* ============================================================================ */
|
|
62
|
+
export { Logger, ValidationError, validateConfig, validateEvent, generateEventId, generateTimestamp, generateBatchId, enrichEvent, serializeEventsToNDJSON, deserializeEventsFromNDJSON, } from './utils';
|
|
63
|
+
/* ============================================================================
|
|
64
|
+
* Storage Exports
|
|
65
|
+
* ============================================================================ */
|
|
66
|
+
export { S3Storage } from './storage/s3-storage';
|
|
67
|
+
export { GlacierStorage } from './storage/glacier-storage';
|
|
68
|
+
/* ============================================================================
|
|
69
|
+
* Queue Export
|
|
70
|
+
* ============================================================================ */
|
|
71
|
+
export { EventQueue } from './queue';
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Event queue for batching and buffering
|
|
3
|
+
* @module ml-cache/queue
|
|
4
|
+
*/
|
|
5
|
+
import type { MLCacheEvent, BatchConfig } from './types';
|
|
6
|
+
import { Logger } from './utils';
|
|
7
|
+
/**
|
|
8
|
+
* Batch ready callback type
|
|
9
|
+
* @typedef BatchReadyCallback
|
|
10
|
+
*/
|
|
11
|
+
export type BatchReadyCallback = (events: MLCacheEvent[], batchId: string) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Event queue for batching events before storage
|
|
14
|
+
* @class EventQueue
|
|
15
|
+
*/
|
|
16
|
+
export declare class EventQueue {
|
|
17
|
+
/** @private */
|
|
18
|
+
private queue;
|
|
19
|
+
/** @private */
|
|
20
|
+
private config;
|
|
21
|
+
/** @private */
|
|
22
|
+
private logger;
|
|
23
|
+
/** @private */
|
|
24
|
+
private flushTimer;
|
|
25
|
+
/** @private */
|
|
26
|
+
private onBatchReady;
|
|
27
|
+
/** @private */
|
|
28
|
+
private isFlushing;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new EventQueue instance
|
|
31
|
+
* @param {Partial<BatchConfig>} [config] - Batch configuration
|
|
32
|
+
* @param {Logger} [logger] - Logger instance
|
|
33
|
+
*/
|
|
34
|
+
constructor(config?: Partial<BatchConfig>, logger?: Logger);
|
|
35
|
+
/**
|
|
36
|
+
* Sets the callback for when a batch is ready
|
|
37
|
+
* @param {BatchReadyCallback} callback - Callback function
|
|
38
|
+
*/
|
|
39
|
+
setOnBatchReady(callback: BatchReadyCallback): void;
|
|
40
|
+
/**
|
|
41
|
+
* Adds an event to the queue
|
|
42
|
+
* @param {MLCacheEvent} event - Event to add
|
|
43
|
+
* @returns {boolean} Whether the event was added successfully
|
|
44
|
+
*/
|
|
45
|
+
enqueue(event: MLCacheEvent): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a flush should be triggered
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
private checkFlush;
|
|
51
|
+
/**
|
|
52
|
+
* Starts the flush timer
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
private startFlushTimer;
|
|
56
|
+
/**
|
|
57
|
+
* Stops the flush timer
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
private stopFlushTimer;
|
|
61
|
+
/**
|
|
62
|
+
* Flushes the queue
|
|
63
|
+
* @returns {Promise<MLCacheEvent[]>} Flushed events
|
|
64
|
+
*/
|
|
65
|
+
flush(): Promise<MLCacheEvent[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the current queue size
|
|
68
|
+
* @returns {number} Queue size
|
|
69
|
+
*/
|
|
70
|
+
size(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if the queue is empty
|
|
73
|
+
* @returns {boolean} Whether the queue is empty
|
|
74
|
+
*/
|
|
75
|
+
isEmpty(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if the queue is full
|
|
78
|
+
* @returns {boolean} Whether the queue is full
|
|
79
|
+
*/
|
|
80
|
+
isFull(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Gets all events without removing them
|
|
83
|
+
* @returns {MLCacheEvent[]} All events in queue
|
|
84
|
+
*/
|
|
85
|
+
peek(): MLCacheEvent[];
|
|
86
|
+
/**
|
|
87
|
+
* Clears the queue
|
|
88
|
+
* @returns {MLCacheEvent[]} Cleared events
|
|
89
|
+
*/
|
|
90
|
+
clear(): MLCacheEvent[];
|
|
91
|
+
/**
|
|
92
|
+
* Updates the batch configuration
|
|
93
|
+
* @param {Partial<BatchConfig>} config - New configuration
|
|
94
|
+
*/
|
|
95
|
+
setConfig(config: Partial<BatchConfig>): void;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the current batch configuration
|
|
98
|
+
* @returns {BatchConfig} Current configuration
|
|
99
|
+
*/
|
|
100
|
+
getConfig(): BatchConfig;
|
|
101
|
+
/**
|
|
102
|
+
* Destroys the queue
|
|
103
|
+
*/
|
|
104
|
+
destroy(): void;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","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AE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAI7C;;;OAGG;IACH,SAAS,IAAI,WAAW;IAIxB;;OAEG;IACH,OAAO,IAAI,IAAI;CAKhB"}
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Event queue for batching and buffering
|
|
4
|
+
* @module ml-cache/queue
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.EventQueue = void 0;
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
/**
|
|
11
|
+
* Event queue for batching events before storage
|
|
12
|
+
* @class EventQueue
|
|
13
|
+
*/
|
|
14
|
+
class EventQueue {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new EventQueue instance
|
|
17
|
+
* @param {Partial<BatchConfig>} [config] - Batch configuration
|
|
18
|
+
* @param {Logger} [logger] - Logger instance
|
|
19
|
+
*/
|
|
20
|
+
constructor(config, logger) {
|
|
21
|
+
/** @private */
|
|
22
|
+
this.queue = [];
|
|
23
|
+
/** @private */
|
|
24
|
+
this.flushTimer = null;
|
|
25
|
+
/** @private */
|
|
26
|
+
this.onBatchReady = null;
|
|
27
|
+
/** @private */
|
|
28
|
+
this.isFlushing = false;
|
|
29
|
+
this.config = { ...constants_1.DEFAULT_BATCH_CONFIG, ...config };
|
|
30
|
+
this.logger = logger || new utils_1.Logger();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets the callback for when a batch is ready
|
|
34
|
+
* @param {BatchReadyCallback} callback - Callback function
|
|
35
|
+
*/
|
|
36
|
+
setOnBatchReady(callback) {
|
|
37
|
+
this.onBatchReady = callback;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Adds an event to the queue
|
|
41
|
+
* @param {MLCacheEvent} event - Event to add
|
|
42
|
+
* @returns {boolean} Whether the event was added successfully
|
|
43
|
+
*/
|
|
44
|
+
enqueue(event) {
|
|
45
|
+
if (this.queue.length >= constants_1.MAX_QUEUE_SIZE) {
|
|
46
|
+
this.logger.error('Queue is full, dropping event', {
|
|
47
|
+
eventId: event.eventId,
|
|
48
|
+
queueSize: this.queue.length,
|
|
49
|
+
});
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
this.queue.push(event);
|
|
53
|
+
if (this.queue.length / constants_1.MAX_QUEUE_SIZE >= constants_1.QUEUE_WARNING_THRESHOLD) {
|
|
54
|
+
this.logger.warn('Queue is approaching capacity', {
|
|
55
|
+
queueSize: this.queue.length,
|
|
56
|
+
maxSize: constants_1.MAX_QUEUE_SIZE,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
this.logger.debug('Event enqueued', {
|
|
60
|
+
eventId: event.eventId,
|
|
61
|
+
queueSize: this.queue.length,
|
|
62
|
+
});
|
|
63
|
+
if (this.config.enabled) {
|
|
64
|
+
this.checkFlush();
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if a flush should be triggered
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
checkFlush() {
|
|
73
|
+
if (this.queue.length >= this.config.maxSize) {
|
|
74
|
+
this.logger.debug('Queue reached max size, triggering flush');
|
|
75
|
+
void this.flush();
|
|
76
|
+
}
|
|
77
|
+
else if (!this.flushTimer && this.queue.length > 0) {
|
|
78
|
+
this.startFlushTimer();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Starts the flush timer
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
startFlushTimer() {
|
|
86
|
+
if (this.flushTimer) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.flushTimer = setTimeout(() => {
|
|
90
|
+
this.flushTimer = null;
|
|
91
|
+
if (this.queue.length > 0) {
|
|
92
|
+
this.logger.debug('Flush timer triggered');
|
|
93
|
+
void this.flush();
|
|
94
|
+
}
|
|
95
|
+
}, this.config.maxWaitMs);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Stops the flush timer
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
stopFlushTimer() {
|
|
102
|
+
if (this.flushTimer) {
|
|
103
|
+
clearTimeout(this.flushTimer);
|
|
104
|
+
this.flushTimer = null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Flushes the queue
|
|
109
|
+
* @returns {Promise<MLCacheEvent[]>} Flushed events
|
|
110
|
+
*/
|
|
111
|
+
async flush() {
|
|
112
|
+
if (this.isFlushing) {
|
|
113
|
+
this.logger.debug('Flush already in progress');
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
if (this.queue.length === 0) {
|
|
117
|
+
this.logger.debug('Queue is empty, nothing to flush');
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
this.isFlushing = true;
|
|
121
|
+
this.stopFlushTimer();
|
|
122
|
+
const eventsToFlush = this.queue.splice(0, this.config.maxSize);
|
|
123
|
+
const batchId = (0, utils_1.generateBatchId)();
|
|
124
|
+
this.logger.info('Flushing queue', {
|
|
125
|
+
batchId,
|
|
126
|
+
eventCount: eventsToFlush.length,
|
|
127
|
+
remainingInQueue: this.queue.length,
|
|
128
|
+
});
|
|
129
|
+
try {
|
|
130
|
+
if (this.onBatchReady) {
|
|
131
|
+
await this.onBatchReady(eventsToFlush, batchId);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
this.logger.error('Error in batch ready callback', {
|
|
136
|
+
batchId,
|
|
137
|
+
error: error instanceof Error ? error.message : String(error),
|
|
138
|
+
});
|
|
139
|
+
this.queue.unshift(...eventsToFlush);
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
this.isFlushing = false;
|
|
143
|
+
if (this.queue.length > 0 && this.config.enabled) {
|
|
144
|
+
this.startFlushTimer();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return eventsToFlush;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Gets the current queue size
|
|
151
|
+
* @returns {number} Queue size
|
|
152
|
+
*/
|
|
153
|
+
size() {
|
|
154
|
+
return this.queue.length;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Checks if the queue is empty
|
|
158
|
+
* @returns {boolean} Whether the queue is empty
|
|
159
|
+
*/
|
|
160
|
+
isEmpty() {
|
|
161
|
+
return this.queue.length === 0;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Checks if the queue is full
|
|
165
|
+
* @returns {boolean} Whether the queue is full
|
|
166
|
+
*/
|
|
167
|
+
isFull() {
|
|
168
|
+
return this.queue.length >= constants_1.MAX_QUEUE_SIZE;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Gets all events without removing them
|
|
172
|
+
* @returns {MLCacheEvent[]} All events in queue
|
|
173
|
+
*/
|
|
174
|
+
peek() {
|
|
175
|
+
return [...this.queue];
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Clears the queue
|
|
179
|
+
* @returns {MLCacheEvent[]} Cleared events
|
|
180
|
+
*/
|
|
181
|
+
clear() {
|
|
182
|
+
this.stopFlushTimer();
|
|
183
|
+
const events = this.queue.splice(0);
|
|
184
|
+
this.logger.info('Queue cleared', { eventCount: events.length });
|
|
185
|
+
return events;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Updates the batch configuration
|
|
189
|
+
* @param {Partial<BatchConfig>} config - New configuration
|
|
190
|
+
*/
|
|
191
|
+
setConfig(config) {
|
|
192
|
+
this.config = { ...this.config, ...config };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Gets the current batch configuration
|
|
196
|
+
* @returns {BatchConfig} Current configuration
|
|
197
|
+
*/
|
|
198
|
+
getConfig() {
|
|
199
|
+
return { ...this.config };
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Destroys the queue
|
|
203
|
+
*/
|
|
204
|
+
destroy() {
|
|
205
|
+
this.stopFlushTimer();
|
|
206
|
+
this.queue = [];
|
|
207
|
+
this.onBatchReady = null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.EventQueue = EventQueue;
|
|
211
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2CAA4F;AAC5F,mCAAkD;AAWlD;;;GAGG;AACH,MAAa,UAAU;IAmBrB;;;;OAIG;IACH,YAAY,MAA6B,EAAE,MAAe;QAvB1D,eAAe;QACP,UAAK,GAAmB,EAAE,CAAC;QAQnC,eAAe;QACP,eAAU,GAA0B,IAAI,CAAC;QAEjD,eAAe;QACP,iBAAY,GAA8B,IAAI,CAAC;QAEvD,eAAe;QACP,eAAU,GAAG,KAAK,CAAC;QAQzB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,gCAAoB,EAAE,GAAG,MAAM,EAAE,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,cAAM,EAAE,CAAC;IACvC,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,QAA4B;QAC1C,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAmB;QACzB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,0BAAc,EAAE,CAAC;YACxC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE;gBACjD,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;aAC7B,CAAC,CAAC;YACH,OAAO,KAAK,CAAC;QACf,CAA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E,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,MAA4B;QACpC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;CACF;AArOD,gCAqOC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Glacier storage provider for ml-cache SDK
|
|
3
|
+
* @module ml-cache/storage/glacier-storage
|
|
4
|
+
*/
|
|
5
|
+
import type { GlacierConfig, AWSCredentials, MLCacheEvent } from '../types';
|
|
6
|
+
import { Logger } from '../utils';
|
|
7
|
+
/**
|
|
8
|
+
* Glacier storage result
|
|
9
|
+
* @interface GlacierStorageResult
|
|
10
|
+
*/
|
|
11
|
+
export interface GlacierStorageResult {
|
|
12
|
+
/** Whether the operation was successful */
|
|
13
|
+
success: boolean;
|
|
14
|
+
/** Glacier archive ID */
|
|
15
|
+
archiveId?: string;
|
|
16
|
+
/** Vault name */
|
|
17
|
+
vaultName: string;
|
|
18
|
+
/** Archive checksum */
|
|
19
|
+
checksum?: string;
|
|
20
|
+
/** Archive location */
|
|
21
|
+
location?: string;
|
|
22
|
+
/** Error message if failed */
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Glacier storage provider for long-term event archival
|
|
27
|
+
* @class GlacierStorage
|
|
28
|
+
*/
|
|
29
|
+
export declare class GlacierStorage {
|
|
30
|
+
/** @private */
|
|
31
|
+
private client;
|
|
32
|
+
/** @private */
|
|
33
|
+
private config;
|
|
34
|
+
/** @private */
|
|
35
|
+
private accountId;
|
|
36
|
+
/** @private */
|
|
37
|
+
private logger;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new GlacierStorage instance
|
|
40
|
+
* @param {GlacierConfig} config - Glacier configuration
|
|
41
|
+
* @param {AWSCredentials} credentials - AWS credentials
|
|
42
|
+
* @param {Logger} [logger] - Logger instance
|
|
43
|
+
*/
|
|
44
|
+
constructor(config: GlacierConfig, credentials: AWSCredentials, logger?: Logger);
|
|
45
|
+
/**
|
|
46
|
+
* Tests the connection to Glacier
|
|
47
|
+
* @returns {Promise<boolean>} Whether the connection is successful
|
|
48
|
+
*/
|
|
49
|
+
testConnection(): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Archives events in Glacier
|
|
52
|
+
* @param {MLCacheEvent[]} events - Events to archive
|
|
53
|
+
* @param {string} [batchId] - Optional batch ID
|
|
54
|
+
* @returns {Promise<GlacierStorageResult>} Storage result
|
|
55
|
+
*/
|
|
56
|
+
archiveEvents(events: MLCacheEvent[], batchId?: string): Promise<GlacierStorageResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the vault name
|
|
59
|
+
* @returns {string} Vault name
|
|
60
|
+
*/
|
|
61
|
+
getVaultName(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Gets the region
|
|
64
|
+
* @returns {string} Region
|
|
65
|
+
*/
|
|
66
|
+
getRegion(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the account ID
|
|
69
|
+
* @returns {string} Account ID
|
|
70
|
+
*/
|
|
71
|
+
getAccountId(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Destroys the Glacier client
|
|
74
|
+
*/
|
|
75
|
+
destroy(): void;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=glacier-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glacier-storage.d.ts","sourceRoot":"","sources":["../../src/storage/glacier-storage.ts"],"names":[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