ag-common 0.0.358 → 0.0.359
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/dist/api/helpers/dynamo.d.ts +2 -1
- package/dist/api/helpers/dynamo.js +5 -3
- package/dist/api/helpers/enforceDynamoProvisionCap.d.ts +2 -1
- package/dist/api/helpers/enforceDynamoProvisionCap.js +1 -0
- package/dist/api/helpers/s3.d.ts +12 -1
- package/dist/api/helpers/s3.js +26 -2
- package/package.json +1 -1
|
@@ -46,7 +46,8 @@ export declare const queryDynamo: <T>({ tableName, pkName, pkValue, pkOperator,
|
|
|
46
46
|
Items: T[];
|
|
47
47
|
startKey?: Key | undefined;
|
|
48
48
|
}>;
|
|
49
|
-
export declare const
|
|
49
|
+
export declare const getDynamoTtlDays: (days: number) => number;
|
|
50
|
+
export declare const getDynamoTtlMinutes: (mins: number) => number;
|
|
50
51
|
export declare const wipeTable: (tableName: string) => Promise<{
|
|
51
52
|
errors?: string[] | undefined;
|
|
52
53
|
}>;
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getDynamoUpdates = exports.wipeTable = exports.
|
|
15
|
+
exports.getDynamoUpdates = exports.wipeTable = exports.getDynamoTtlMinutes = exports.getDynamoTtlDays = exports.queryDynamo = exports.getItemsDynamo = exports.getItemDynamo = exports.scan = exports.batchDelete = exports.batchWrite = exports.putDynamo = exports.setDynamo = exports.dynamoDb = void 0;
|
|
16
16
|
const log_1 = require("../../common/helpers/log");
|
|
17
17
|
const array_1 = require("../../common/helpers/array");
|
|
18
18
|
const sleep_1 = require("../../common/helpers/sleep");
|
|
@@ -317,8 +317,10 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
|
|
|
317
317
|
return { Items, startKey: undefined };
|
|
318
318
|
});
|
|
319
319
|
exports.queryDynamo = queryDynamo;
|
|
320
|
-
const
|
|
321
|
-
exports.
|
|
320
|
+
const getDynamoTtlDays = (days) => Math.ceil(new Date().getTime() / 1000) + days * 86400;
|
|
321
|
+
exports.getDynamoTtlDays = getDynamoTtlDays;
|
|
322
|
+
const getDynamoTtlMinutes = (mins) => Math.ceil(new Date().getTime() / 1000) + mins * 60;
|
|
323
|
+
exports.getDynamoTtlMinutes = getDynamoTtlMinutes;
|
|
322
324
|
const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
323
325
|
var _h;
|
|
324
326
|
const dbRaw = new dynamodb_1.default({ apiVersion: '2012-10-08' });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** ensure that dynamo tables in stack dont exceed passed in provisioned limits */
|
|
1
2
|
export declare const enforceDynamoProvisionCap: ({ tables, readsMax, writesMax, mustEqual, }: {
|
|
2
3
|
tables: any[];
|
|
3
4
|
/**
|
|
@@ -9,7 +10,7 @@ export declare const enforceDynamoProvisionCap: ({ tables, readsMax, writesMax,
|
|
|
9
10
|
*/
|
|
10
11
|
writesMax?: number | undefined;
|
|
11
12
|
/**
|
|
12
|
-
* default false. if true, will throw if cap isnt met
|
|
13
|
+
* default false. if true, will throw if cap isnt met. will still throw if exceeds.
|
|
13
14
|
*/
|
|
14
15
|
mustEqual?: boolean | undefined;
|
|
15
16
|
}) => void;
|
|
@@ -9,6 +9,7 @@ const extractSum = ({ str, regex }) => {
|
|
|
9
9
|
return (0, math_1.sumArray)(((_a = str
|
|
10
10
|
.match(regex)) === null || _a === void 0 ? void 0 : _a.map((s2) => (0, string_1.trim)(s2.substring(s2.indexOf(':') + 1), ':', ',', ' ')).filter((r) => r && Number(r)).map((r) => Number(r))) || []);
|
|
11
11
|
};
|
|
12
|
+
/** ensure that dynamo tables in stack dont exceed passed in provisioned limits */
|
|
12
13
|
const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
|
|
13
14
|
if (!tables || tables.length === 0) {
|
|
14
15
|
(0, log_1.warn)('error in dynamo FT enforce');
|
package/dist/api/helpers/s3.d.ts
CHANGED
|
@@ -46,7 +46,18 @@ export declare const deleteFiles: ({ Bucket, Keys, }: {
|
|
|
46
46
|
}) => Promise<{
|
|
47
47
|
error?: string;
|
|
48
48
|
}>;
|
|
49
|
-
export declare
|
|
49
|
+
export declare const copyFile: ({ Bucket, fromKey, toKey, deleteSource, }: {
|
|
50
|
+
Bucket: string;
|
|
51
|
+
fromKey: string;
|
|
52
|
+
toKey: string;
|
|
53
|
+
/** if true, will delete original after copy. default false */
|
|
54
|
+
deleteSource?: boolean | undefined;
|
|
55
|
+
}) => Promise<{
|
|
56
|
+
error?: string;
|
|
57
|
+
}>;
|
|
58
|
+
export declare function listFiles(bucketName: string, opt?: {
|
|
59
|
+
prefix?: string;
|
|
60
|
+
}): Promise<string[]>;
|
|
50
61
|
/**
|
|
51
62
|
* allow uploading of file directly to s3
|
|
52
63
|
* @param param0
|
package/dist/api/helpers/s3.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.getPresignedPostURL = exports.listFiles = exports.deleteFiles = exports.deleteFile = exports.uploadFile = exports.putS3Object = exports.getS3Objects = exports.getS3Object = exports.setS3 = void 0;
|
|
27
|
+
exports.getPresignedPostURL = exports.listFiles = exports.copyFile = exports.deleteFiles = exports.deleteFile = exports.uploadFile = exports.putS3Object = exports.getS3Objects = exports.getS3Object = exports.setS3 = void 0;
|
|
28
28
|
const s3_1 = __importDefault(require("aws-sdk/clients/s3"));
|
|
29
29
|
const log_1 = require("../../common/helpers/log");
|
|
30
30
|
const array_1 = require("../../common/helpers/array");
|
|
@@ -110,7 +110,30 @@ const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, fun
|
|
|
110
110
|
return {};
|
|
111
111
|
});
|
|
112
112
|
exports.deleteFiles = deleteFiles;
|
|
113
|
-
function
|
|
113
|
+
const copyFile = ({ Bucket, fromKey, toKey, deleteSource = false, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
(0, log_1.debug)(`copying s3 file from ${Bucket}- ${fromKey} to ${toKey}`);
|
|
115
|
+
const res = yield s3
|
|
116
|
+
.copyObject({
|
|
117
|
+
//incl bucket
|
|
118
|
+
CopySource: Bucket + '/' + fromKey,
|
|
119
|
+
//dest
|
|
120
|
+
Bucket,
|
|
121
|
+
Key: toKey,
|
|
122
|
+
})
|
|
123
|
+
.promise();
|
|
124
|
+
if (res.$response.error) {
|
|
125
|
+
return { error: res.$response.error.message };
|
|
126
|
+
}
|
|
127
|
+
if (deleteSource) {
|
|
128
|
+
const df = yield (0, exports.deleteFile)({ Bucket, Key: fromKey });
|
|
129
|
+
if (df.error) {
|
|
130
|
+
return { error: df.error };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return {};
|
|
134
|
+
});
|
|
135
|
+
exports.copyFile = copyFile;
|
|
136
|
+
function listFiles(bucketName, opt) {
|
|
114
137
|
var _a, _b;
|
|
115
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
139
|
try {
|
|
@@ -124,6 +147,7 @@ function listFiles(bucketName) {
|
|
|
124
147
|
.listObjectsV2({
|
|
125
148
|
Bucket: bucketName,
|
|
126
149
|
ContinuationToken: response.NextContinuationToken,
|
|
150
|
+
Prefix: opt === null || opt === void 0 ? void 0 : opt.prefix,
|
|
127
151
|
})
|
|
128
152
|
.promise();
|
|
129
153
|
(_b = (_a = response.Contents) === null || _a === void 0 ? void 0 : _a.filter((r) => r.Key)) === null || _b === void 0 ? void 0 : _b.map((c) => {
|