plenna_utilities 1.1.1 → 1.2.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/src/general/index.d.ts +3 -0
- package/dist/src/general/index.js +41 -0
- package/dist/src/general/interfaces.d.ts +4 -0
- package/dist/src/general/interfaces.js +2 -0
- package/dist/src/s3/index.d.ts +1 -1
- package/dist/src/s3/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type IFlattenOptions } from './interfaces';
|
|
2
|
+
export declare const flatten: <T>(input: T, reference?: string, output?: Record<string, unknown>, opts?: IFlattenOptions) => Record<string, unknown>;
|
|
3
|
+
export declare const unflatten: (input: Record<string, unknown>, delimiter?: string) => Record<string, unknown>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unflatten = exports.flatten = void 0;
|
|
4
|
+
const flatten = (input, reference = '', output = {}, opts = { secure: true, delimiter: '|' }) => {
|
|
5
|
+
for (const key in input) {
|
|
6
|
+
const value = input[key];
|
|
7
|
+
const newKey = reference !== '' ? `${reference}${opts.delimiter}${key}` : key;
|
|
8
|
+
const isObject = typeof value === 'object';
|
|
9
|
+
const isInstanceOfObject = value instanceof Object;
|
|
10
|
+
const isInstanceOfDate = value instanceof Date;
|
|
11
|
+
const isArray = Array.isArray(value);
|
|
12
|
+
if (isObject && isInstanceOfObject && !isInstanceOfDate && (!isArray || !opts.secure)) {
|
|
13
|
+
(0, exports.flatten)(value, newKey, output, opts);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
output[newKey] = value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return output;
|
|
20
|
+
};
|
|
21
|
+
exports.flatten = flatten;
|
|
22
|
+
const unflatten = (input, delimiter = '|') => {
|
|
23
|
+
const output = {};
|
|
24
|
+
Object.keys(input).forEach((key) => {
|
|
25
|
+
const keys = key.split(delimiter);
|
|
26
|
+
let currentLevel = output;
|
|
27
|
+
keys.forEach((part, index) => {
|
|
28
|
+
if (index === keys.length - 1) {
|
|
29
|
+
currentLevel[part] = input[key];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
if (currentLevel[part] === undefined) {
|
|
33
|
+
currentLevel[part] = {};
|
|
34
|
+
}
|
|
35
|
+
currentLevel = currentLevel[part];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return output;
|
|
40
|
+
};
|
|
41
|
+
exports.unflatten = unflatten;
|
package/dist/src/s3/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare class PlennaS3Service {
|
|
|
4
4
|
private readonly acl;
|
|
5
5
|
private readonly options;
|
|
6
6
|
constructor(bucket: string, acl: ObjectCannedACL, options?: Partial<PutObjectCommandInput>);
|
|
7
|
-
getPresignedUrl(keyName: string, clientConfig
|
|
7
|
+
getPresignedUrl(keyName: string, clientConfig?: S3ClientConfig): Promise<string>;
|
|
8
8
|
upload(fileName: string, file: PutObjectCommandInput['Body'], options?: Partial<PutObjectCommandInput>): Promise<string>;
|
|
9
9
|
}
|
package/dist/src/s3/index.js
CHANGED
|
@@ -13,7 +13,7 @@ class PlennaS3Service {
|
|
|
13
13
|
this.acl = acl;
|
|
14
14
|
this.options = options;
|
|
15
15
|
}
|
|
16
|
-
async getPresignedUrl(keyName, clientConfig) {
|
|
16
|
+
async getPresignedUrl(keyName, clientConfig = {}) {
|
|
17
17
|
const s3Client = new client_s3_1.S3Client({ region: REGION, ...clientConfig });
|
|
18
18
|
const command = new client_s3_1.PutObjectCommand({
|
|
19
19
|
...this.options,
|