@aligent/microservice-util-lib 0.1.1
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/README.md +36 -0
- package/dist/chunkBy/chunkBy.d.ts +11 -0
- package/dist/chunkBy/chunkBy.js +22 -0
- package/dist/chunkBy/chunkBy.js.map +1 -0
- package/dist/chunkBy/chunkBy.test.d.ts +1 -0
- package/dist/chunkBy/chunkBy.test.js +17 -0
- package/dist/chunkBy/chunkBy.test.js.map +1 -0
- package/dist/fetchSsmParams/fetchSsmParams.d.ts +12 -0
- package/dist/fetchSsmParams/fetchSsmParams.js +82 -0
- package/dist/fetchSsmParams/fetchSsmParams.js.map +1 -0
- package/dist/fetchSsmParams/fetchSsmParams.test.d.ts +1 -0
- package/dist/fetchSsmParams/fetchSsmParams.test.js +119 -0
- package/dist/fetchSsmParams/fetchSsmParams.test.js.map +1 -0
- package/dist/hasPropertiesDefined/hasPropertiesDefined.d.ts +24 -0
- package/dist/hasPropertiesDefined/hasPropertiesDefined.js +36 -0
- package/dist/hasPropertiesDefined/hasPropertiesDefined.js.map +1 -0
- package/dist/hasPropertiesDefined/hasPropertiesDefined.test.d.ts +1 -0
- package/dist/hasPropertiesDefined/hasPropertiesDefined.test.js +37 -0
- package/dist/hasPropertiesDefined/hasPropertiesDefined.test.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/remap/remap.d.ts +147 -0
- package/dist/remap/remap.js +50 -0
- package/dist/remap/remap.js.map +1 -0
- package/dist/remap/remap.test.d.ts +1 -0
- package/dist/remap/remap.test.js +65 -0
- package/dist/remap/remap.test.js.map +1 -0
- package/dist/retryWrapper/retryWrapper.d.ts +40 -0
- package/dist/retryWrapper/retryWrapper.js +121 -0
- package/dist/retryWrapper/retryWrapper.js.map +1 -0
- package/dist/retryWrapper/retryWrapper.test.d.ts +1 -0
- package/dist/retryWrapper/retryWrapper.test.js +234 -0
- package/dist/retryWrapper/retryWrapper.test.js.map +1 -0
- package/dist/s3/s3.d.ts +47 -0
- package/dist/s3/s3.js +196 -0
- package/dist/s3/s3.js.map +1 -0
- package/package.json +44 -0
package/dist/s3/s3.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
50
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
51
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
52
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
53
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
54
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
55
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
56
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
57
|
+
function fulfill(value) { resume("next", value); }
|
|
58
|
+
function reject(value) { resume("throw", value); }
|
|
59
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
var aws_sdk_1 = require("aws-sdk");
|
|
66
|
+
var object_hash_1 = __importDefault(require("object-hash"));
|
|
67
|
+
var chunkBy_1 = __importDefault(require("../chunkBy/chunkBy"));
|
|
68
|
+
/** A data access object for an S3 bucket */
|
|
69
|
+
var S3Dao = /** @class */ (function () {
|
|
70
|
+
/**
|
|
71
|
+
* @param bucket the location of the bucket that objects should be stored in
|
|
72
|
+
*/
|
|
73
|
+
function S3Dao(bucket) {
|
|
74
|
+
this.bucket = bucket;
|
|
75
|
+
this.s3 = new aws_sdk_1.S3();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Store data in an S3 bucket
|
|
79
|
+
* @param data the data to store
|
|
80
|
+
* @param name the name to call the object in S3 @default the hash of the data
|
|
81
|
+
* @returns an object which can be used to fetch the data
|
|
82
|
+
*/
|
|
83
|
+
S3Dao.prototype.storeData = function (data, name) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var getObject;
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
if (typeof data === 'undefined') {
|
|
90
|
+
throw new Error('data is undefined');
|
|
91
|
+
}
|
|
92
|
+
getObject = {
|
|
93
|
+
Bucket: this.bucket,
|
|
94
|
+
Key: name || (0, object_hash_1.default)(data)
|
|
95
|
+
};
|
|
96
|
+
return [4 /*yield*/, this.s3.putObject(__assign(__assign({}, getObject), { Body: JSON.stringify(data) })).promise()];
|
|
97
|
+
case 1:
|
|
98
|
+
_a.sent();
|
|
99
|
+
return [2 /*return*/, getObject];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Store an array of object as individual chunks in S3
|
|
106
|
+
* @param data the data to store
|
|
107
|
+
* @param chunkSize the number of entries that should be in each chunk
|
|
108
|
+
* @returns an array of objects which can be used to fetch the chunks
|
|
109
|
+
*/
|
|
110
|
+
S3Dao.prototype.storeChunked = function (data, chunkSize) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var chunks;
|
|
113
|
+
var _this = this;
|
|
114
|
+
return __generator(this, function (_a) {
|
|
115
|
+
switch (_a.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
chunks = (0, chunkBy_1.default)(data, chunkSize);
|
|
118
|
+
return [4 /*yield*/, Promise.all(chunks.map(function (chunk) { return _this.storeData(chunk); }))];
|
|
119
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Fetch an object from the S3 bucket
|
|
126
|
+
* @param objectDetails the object which describes the location of the object
|
|
127
|
+
* @returns the body of the object
|
|
128
|
+
*/
|
|
129
|
+
S3Dao.prototype.fetchData = function (objectDetails) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var data;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0: return [4 /*yield*/, this.s3.getObject(objectDetails).promise()];
|
|
135
|
+
case 1:
|
|
136
|
+
data = _a.sent();
|
|
137
|
+
return [2 /*return*/, JSON.parse(data.Body.toString())];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Generator to fetch chunked data, chunk by chunk
|
|
144
|
+
* @param chunks the list of object chunks
|
|
145
|
+
*/
|
|
146
|
+
S3Dao.prototype.fetchChunks = function (chunks) {
|
|
147
|
+
return __asyncGenerator(this, arguments, function fetchChunks_1() {
|
|
148
|
+
var i, chunk, response;
|
|
149
|
+
return __generator(this, function (_a) {
|
|
150
|
+
switch (_a.label) {
|
|
151
|
+
case 0:
|
|
152
|
+
i = 0;
|
|
153
|
+
_a.label = 1;
|
|
154
|
+
case 1:
|
|
155
|
+
if (!(i < chunks.length)) return [3 /*break*/, 8];
|
|
156
|
+
return [4 /*yield*/, __await(this.fetchData(chunks[i]))];
|
|
157
|
+
case 2:
|
|
158
|
+
chunk = _a.sent();
|
|
159
|
+
response = {
|
|
160
|
+
chunk: chunk,
|
|
161
|
+
s3Object: chunks[i]
|
|
162
|
+
};
|
|
163
|
+
if (!(i === chunks.length - 1)) return [3 /*break*/, 4];
|
|
164
|
+
return [4 /*yield*/, __await(response)];
|
|
165
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
166
|
+
case 4: return [4 /*yield*/, __await(response)];
|
|
167
|
+
case 5: return [4 /*yield*/, _a.sent()];
|
|
168
|
+
case 6:
|
|
169
|
+
_a.sent();
|
|
170
|
+
_a.label = 7;
|
|
171
|
+
case 7:
|
|
172
|
+
i++;
|
|
173
|
+
return [3 /*break*/, 1];
|
|
174
|
+
case 8: return [2 /*return*/];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Delete an object from the S3 bucket
|
|
181
|
+
* @param objectDetails the object to delete
|
|
182
|
+
*/
|
|
183
|
+
S3Dao.prototype.deleteData = function (objectDetails) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
return __generator(this, function (_a) {
|
|
186
|
+
switch (_a.label) {
|
|
187
|
+
case 0: return [4 /*yield*/, this.s3.deleteObject(objectDetails).promise()];
|
|
188
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
return S3Dao;
|
|
194
|
+
}());
|
|
195
|
+
exports.default = S3Dao;
|
|
196
|
+
//# sourceMappingURL=s3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3.js","sourceRoot":"","sources":["../../src/s3/s3.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA6B;AAC7B,4DAA+B;AAE/B,+DAAyC;AAEzC,4CAA4C;AAC5C;IAIE;;OAEG;IACH,eAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,IAAI,YAAE,EAAE,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACU,yBAAS,GAAtB,UACE,IAAO,EACP,IAAa;;;;;;wBAEb,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;4BAC/B,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;yBACtC;wBACK,SAAS,GAAwB;4BACrC,MAAM,EAAE,IAAI,CAAC,MAAM;4BACnB,GAAG,EAAE,IAAI,IAAI,IAAA,qBAAI,EAAC,IAAW,CAAC;yBAC/B,CAAC;wBAEF,qBAAM,IAAI,CAAC,EAAE,CAAC,SAAS,uBAClB,SAAS,KACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAC1B,CAAC,OAAO,EAAE,EAAA;;wBAHZ,SAGY,CAAC;wBAEb,sBAAO,SAAS,EAAC;;;;KAClB;IAED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AC,CAAC,OAAO,EAAE,EAAA;4BAA1D,sBAAO,SAAmD,EAAC;;;;KAC5D;IACH,YAAC;AAAD,CAAC,AAtFD,IAsFC;AAED,kBAAe,KAAK,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aligent/microservice-util-lib",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A set of utility functions for Aligent Microservices",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"lint": "eslint src/*.ts src/**/*.ts",
|
|
9
|
+
"lint:fix": "eslint --fix src/*.ts src/**/*.ts",
|
|
10
|
+
"test": "npm run lint && npm run test:types && npm run test:jest",
|
|
11
|
+
"test:jest": "jest src/",
|
|
12
|
+
"test:types": "tsc --noEmit",
|
|
13
|
+
"docs": "typedoc --readme none --githubPages false --plugin typedoc-plugin-markdown --entryDocument modules.md --namedAnchors true --out docs src/index.ts"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+ssh://git@bitbucket.org/aligent/microservices-utilities.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "Aligent",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/jest": "^29.2.4",
|
|
23
|
+
"@types/lodash": "^4.14.191",
|
|
24
|
+
"@types/node": "^18.11.17",
|
|
25
|
+
"@types/object-hash": "^3.0.2",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
27
|
+
"@typescript-eslint/parser": "^5.46.1",
|
|
28
|
+
"eslint": "^8.30.0",
|
|
29
|
+
"jest": "^29.3.1",
|
|
30
|
+
"ts-jest": "^29.0.3",
|
|
31
|
+
"typedoc": "^0.23.23",
|
|
32
|
+
"typedoc-plugin-markdown": "^3.14.0",
|
|
33
|
+
"typescript": "^4.9.4"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"aws-sdk": "^2.1281.0",
|
|
37
|
+
"axios": "^1.2.1",
|
|
38
|
+
"lodash": "^4.17.21",
|
|
39
|
+
"object-hash": "^3.0.0"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
]
|
|
44
|
+
}
|