@8ms/helpers 2.0.15 → 2.0.17
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/.yarn/install-state.gz +0 -0
- package/aws/s3/AwsS3Namespace.d.ts +10 -5
- package/aws/s3/AwsS3Namespace.js +60 -44
- package/date/calculation.d.ts +7 -0
- package/date/calculation.js +38 -3
- package/package.json +1 -1
- package/util/getGzipCompressed.d.ts +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
|
@@ -40,14 +40,19 @@ export declare class AwsS3Namespace extends BaseNamespace {
|
|
|
40
40
|
*/
|
|
41
41
|
listFolders: (bucket: string, folder: string) => Promise<string[]>;
|
|
42
42
|
move: (fromBucket: string, fromKey: string, toBucket: string, toKey: string) => Promise<void>;
|
|
43
|
-
readBrotli: (bucket: string, key: string,
|
|
43
|
+
readBrotli: (bucket: string, key: string, brotliOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
44
|
+
readJsonBrotli: (bucket: string, key: string, brotliOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
44
45
|
readBuffer: (bucket: string, key: string) => Promise<ReadBufferResponse>;
|
|
45
46
|
fileExists: (bucket: string, key: string) => Promise<boolean>;
|
|
46
|
-
readFile: (bucket: string, key: string,
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
readFile: (bucket: string, key: string, options?: Options) => Promise<ReadFileResponse>;
|
|
48
|
+
readJson: (bucket: string, key: string) => Promise<ReadFileResponse>;
|
|
49
|
+
readJsonGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
50
|
+
readGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
51
|
+
writeBrotli: (bucket: string, key: string, data: any, brotliOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
49
52
|
writeFile: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
50
|
-
|
|
53
|
+
writeJson: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
54
|
+
writeJsonGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
55
|
+
writeGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
51
56
|
/**
|
|
52
57
|
* Get a presigned post URL so we can upload directly to S3 via frontend.
|
|
53
58
|
*/
|
package/aws/s3/AwsS3Namespace.js
CHANGED
|
@@ -206,17 +206,23 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
206
206
|
Key: fromKey,
|
|
207
207
|
}));
|
|
208
208
|
};
|
|
209
|
-
this.readBrotli = async (bucket, key,
|
|
209
|
+
this.readBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
210
210
|
await this.ensureInit();
|
|
211
|
-
|
|
211
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
212
212
|
// Cache exists and is still within our caching timeframe
|
|
213
|
-
if (undefined !==
|
|
214
|
-
|
|
215
|
-
if (false !== isJson) {
|
|
216
|
-
response.body = JSON.parse(response.body);
|
|
217
|
-
}
|
|
213
|
+
if (undefined !== apiResponse.body) {
|
|
214
|
+
apiResponse.body = await (0, server_2.getBrotliDecompressed)(apiResponse.body, brotliOptions);
|
|
218
215
|
}
|
|
219
|
-
return
|
|
216
|
+
return apiResponse;
|
|
217
|
+
};
|
|
218
|
+
this.readJsonBrotli = async (bucket, key, brotliOptions = {}, awsS3Options = {}) => {
|
|
219
|
+
await this.ensureInit();
|
|
220
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
221
|
+
if (undefined !== apiResponse.body) {
|
|
222
|
+
apiResponse.body = await (0, server_2.getBrotliDecompressed)(apiResponse.body, brotliOptions);
|
|
223
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
224
|
+
}
|
|
225
|
+
return apiResponse;
|
|
220
226
|
};
|
|
221
227
|
this.readBuffer = async (bucket, key) => {
|
|
222
228
|
await this.ensureInit();
|
|
@@ -264,7 +270,7 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
264
270
|
}
|
|
265
271
|
return response;
|
|
266
272
|
};
|
|
267
|
-
this.readFile = async (bucket, key,
|
|
273
|
+
this.readFile = async (bucket, key, options = {}) => {
|
|
268
274
|
await this.ensureInit();
|
|
269
275
|
let response = (0, cloneDeep_1.default)(server_3.readFileDefault);
|
|
270
276
|
const today = (0, date_1.getToday)();
|
|
@@ -276,6 +282,7 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
276
282
|
const apiResponse = await this.client.send(new GetObjectCommand({
|
|
277
283
|
Bucket: bucket,
|
|
278
284
|
Key: key,
|
|
285
|
+
...options,
|
|
279
286
|
}));
|
|
280
287
|
//console.log('apiResponse', apiResponse);
|
|
281
288
|
if ((0, server_1.isResponse200)(apiResponse)) {
|
|
@@ -283,19 +290,15 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
283
290
|
// Convert the date to unix
|
|
284
291
|
response.modified.unix = modified.toUnixInteger();
|
|
285
292
|
// Compare now to unix
|
|
286
|
-
response.modified.vs_now.months = today.diff(modified,
|
|
287
|
-
response.modified.vs_now.days = today.diff(modified,
|
|
288
|
-
response.modified.vs_now.hours = today.diff(modified,
|
|
289
|
-
response.modified.vs_now.minutes = today.diff(modified,
|
|
293
|
+
response.modified.vs_now.months = today.diff(modified, "months").months;
|
|
294
|
+
response.modified.vs_now.days = today.diff(modified, "days").days;
|
|
295
|
+
response.modified.vs_now.hours = today.diff(modified, "hours").hours;
|
|
296
|
+
response.modified.vs_now.minutes = today.diff(modified, "minutes").minutes;
|
|
290
297
|
// Compare now to midnight
|
|
291
|
-
response.modified.vs_midnight.hours = today.diff(midnight,
|
|
292
|
-
response.modified.vs_midnight.minutes = today.diff(midnight,
|
|
298
|
+
response.modified.vs_midnight.hours = today.diff(midnight, "hours").hours;
|
|
299
|
+
response.modified.vs_midnight.minutes = today.diff(midnight, "minutes").hours;
|
|
293
300
|
// Convert stream into a string
|
|
294
301
|
response.body = await (0, string_1.getStringFromStream)(apiResponse.Body);
|
|
295
|
-
// If we need to return JSON, parse it. On error return undefined
|
|
296
|
-
if (false !== isJson) {
|
|
297
|
-
response.body = JSON.parse(response.body) || null;
|
|
298
|
-
}
|
|
299
302
|
}
|
|
300
303
|
}
|
|
301
304
|
catch (error) {
|
|
@@ -304,29 +307,34 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
304
307
|
}
|
|
305
308
|
return response;
|
|
306
309
|
};
|
|
307
|
-
this.
|
|
310
|
+
this.readJson = async (bucket, key) => {
|
|
308
311
|
await this.ensureInit();
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
312
|
+
const apiResponse = await this.readFile(bucket, key);
|
|
313
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
314
|
+
return apiResponse;
|
|
315
|
+
};
|
|
316
|
+
this.readJsonGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
317
|
+
await this.ensureInit();
|
|
318
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
319
|
+
if (undefined !== apiResponse.body) {
|
|
320
|
+
apiResponse.body = await (0, server_2.getGzipDecompressed)(apiResponse.body, gzipOptions);
|
|
321
|
+
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
316
322
|
}
|
|
317
|
-
return
|
|
323
|
+
return apiResponse;
|
|
318
324
|
};
|
|
319
|
-
this.
|
|
325
|
+
this.readGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
320
326
|
await this.ensureInit();
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
|
|
327
|
+
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
328
|
+
if (undefined !== apiResponse.body) {
|
|
329
|
+
apiResponse.body = await (0, server_2.getGzipDecompressed)(apiResponse.body, gzipOptions);
|
|
324
330
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
331
|
+
return apiResponse;
|
|
332
|
+
};
|
|
333
|
+
this.writeBrotli = async (bucket, key, data, brotliOptions = {}, awsS3Options = {}) => {
|
|
334
|
+
await this.ensureInit();
|
|
335
|
+
let finalData = data;
|
|
336
|
+
finalData = await (0, server_2.getBrotliCompressed)(finalData, brotliOptions);
|
|
337
|
+
const apiResponse = await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
330
338
|
return apiResponse;
|
|
331
339
|
};
|
|
332
340
|
this.writeFile = async (bucket, key, data, options = {}) => {
|
|
@@ -340,15 +348,23 @@ class AwsS3Namespace extends _class_1.BaseNamespace {
|
|
|
340
348
|
}));
|
|
341
349
|
return apiResponse;
|
|
342
350
|
};
|
|
343
|
-
this.
|
|
351
|
+
this.writeJson = async (bucket, key, data, options = {}) => {
|
|
352
|
+
await this.ensureInit();
|
|
353
|
+
const apiResponse = await this.writeFile(bucket, key, JSON.stringify(data), options);
|
|
354
|
+
return apiResponse;
|
|
355
|
+
};
|
|
356
|
+
this.writeJsonGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
357
|
+
await this.ensureInit();
|
|
358
|
+
let finalData = JSON.stringify(data);
|
|
359
|
+
finalData = await (0, server_2.getGzipCompressed)(finalData, gzipOptions);
|
|
360
|
+
const apiResponse = await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
361
|
+
return apiResponse;
|
|
362
|
+
};
|
|
363
|
+
this.writeGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
344
364
|
await this.ensureInit();
|
|
345
365
|
let finalData = data;
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
// Compress the data
|
|
350
|
-
const gzipData = await (0, server_2.getGzipCompressed)(finalData);
|
|
351
|
-
const apiResponse = await this.writeFile(bucket, key, gzipData, options);
|
|
366
|
+
finalData = await (0, server_2.getGzipCompressed)(finalData, gzipOptions);
|
|
367
|
+
const apiResponse = await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
352
368
|
return apiResponse;
|
|
353
369
|
};
|
|
354
370
|
/**
|
package/date/calculation.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ export declare const getUnix: (input?: InputDate) => number;
|
|
|
11
11
|
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
12
12
|
*/
|
|
13
13
|
export declare const getDate: (input?: InputDate, setMidnight?: boolean) => DateTime<boolean>;
|
|
14
|
+
export declare const isMonday: (input?: InputDate) => boolean;
|
|
15
|
+
export declare const isTuesday: (input?: InputDate) => boolean;
|
|
16
|
+
export declare const isWednesday: (input?: InputDate) => boolean;
|
|
17
|
+
export declare const isThursday: (input?: InputDate) => boolean;
|
|
18
|
+
export declare const isFriday: (input?: InputDate) => boolean;
|
|
19
|
+
export declare const isSaturday: (input?: InputDate) => boolean;
|
|
20
|
+
export declare const isSunday: (input?: InputDate) => boolean;
|
|
14
21
|
/**
|
|
15
22
|
* Determines if a given date falls on a weekend.
|
|
16
23
|
*
|
package/date/calculation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getDatesBetween = exports.differenceInBusinessDays = exports.differenceInMinutes = exports.isWeekend = exports.getDate = exports.getUnix = exports.getUtcDate = void 0;
|
|
3
|
+
exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getDatesBetween = exports.differenceInBusinessDays = exports.differenceInMinutes = exports.isWeekend = exports.isSunday = exports.isSaturday = exports.isFriday = exports.isThursday = exports.isWednesday = exports.isTuesday = exports.isMonday = exports.getDate = exports.getUnix = exports.getUtcDate = void 0;
|
|
4
4
|
const luxon_1 = require("luxon");
|
|
5
5
|
/**
|
|
6
6
|
* Convert an client's input (any time-zone) ready to be used by the server (UTC).
|
|
@@ -63,6 +63,41 @@ const getDate = (input, setMidnight) => {
|
|
|
63
63
|
return instance;
|
|
64
64
|
};
|
|
65
65
|
exports.getDate = getDate;
|
|
66
|
+
const isMonday = (input) => {
|
|
67
|
+
const date = (0, exports.getDate)(input);
|
|
68
|
+
return date.weekday === 1;
|
|
69
|
+
};
|
|
70
|
+
exports.isMonday = isMonday;
|
|
71
|
+
const isTuesday = (input) => {
|
|
72
|
+
const date = (0, exports.getDate)(input);
|
|
73
|
+
return date.weekday === 2;
|
|
74
|
+
};
|
|
75
|
+
exports.isTuesday = isTuesday;
|
|
76
|
+
const isWednesday = (input) => {
|
|
77
|
+
const date = (0, exports.getDate)(input);
|
|
78
|
+
return date.weekday === 3;
|
|
79
|
+
};
|
|
80
|
+
exports.isWednesday = isWednesday;
|
|
81
|
+
const isThursday = (input) => {
|
|
82
|
+
const date = (0, exports.getDate)(input);
|
|
83
|
+
return date.weekday === 4;
|
|
84
|
+
};
|
|
85
|
+
exports.isThursday = isThursday;
|
|
86
|
+
const isFriday = (input) => {
|
|
87
|
+
const date = (0, exports.getDate)(input);
|
|
88
|
+
return date.weekday === 6;
|
|
89
|
+
};
|
|
90
|
+
exports.isFriday = isFriday;
|
|
91
|
+
const isSaturday = (input) => {
|
|
92
|
+
const date = (0, exports.getDate)(input);
|
|
93
|
+
return date.weekday === 6;
|
|
94
|
+
};
|
|
95
|
+
exports.isSaturday = isSaturday;
|
|
96
|
+
const isSunday = (input) => {
|
|
97
|
+
const date = (0, exports.getDate)(input);
|
|
98
|
+
return date.weekday === 7;
|
|
99
|
+
};
|
|
100
|
+
exports.isSunday = isSunday;
|
|
66
101
|
/**
|
|
67
102
|
* Determines if a given date falls on a weekend.
|
|
68
103
|
*
|
|
@@ -71,7 +106,7 @@ exports.getDate = getDate;
|
|
|
71
106
|
*/
|
|
72
107
|
const isWeekend = (input) => {
|
|
73
108
|
const date = (0, exports.getDate)(input);
|
|
74
|
-
return date.weekday
|
|
109
|
+
return 6 === date.weekday || 7 === date.weekday;
|
|
75
110
|
};
|
|
76
111
|
exports.isWeekend = isWeekend;
|
|
77
112
|
/**
|
|
@@ -80,7 +115,7 @@ exports.isWeekend = isWeekend;
|
|
|
80
115
|
const differenceInMinutes = (start, end) => {
|
|
81
116
|
const startDate = (0, exports.getDate)(start);
|
|
82
117
|
const endDate = (0, exports.getDate)(end);
|
|
83
|
-
return endDate.diff(startDate,
|
|
118
|
+
return endDate.diff(startDate, "minutes").minutes;
|
|
84
119
|
};
|
|
85
120
|
exports.differenceInMinutes = differenceInMinutes;
|
|
86
121
|
/**
|
package/package.json
CHANGED
|
@@ -2,4 +2,4 @@ import { type ZlibOptions } from "zlib";
|
|
|
2
2
|
/**
|
|
3
3
|
* Compress a given input using Gzip.
|
|
4
4
|
*/
|
|
5
|
-
export declare const getGzipCompressed: (input: any, options?: ZlibOptions) => Promise<
|
|
5
|
+
export declare const getGzipCompressed: (input: any, options?: ZlibOptions) => Promise<string>;
|