@webiny/utils 6.3.0 → 6.4.0-beta.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/GenericRecord.js +0 -3
- package/cacheKey.js +10 -12
- package/cacheKey.js.map +1 -1
- package/compose.js +23 -32
- package/compose.js.map +1 -1
- package/createIdentifier.js +4 -14
- package/createIdentifier.js.map +1 -1
- package/createZodError.js +22 -27
- package/createZodError.js.map +1 -1
- package/cursor.js +20 -25
- package/cursor.js.map +1 -1
- package/exception.js +8 -13
- package/exception.js.map +1 -1
- package/executeWithRetry.js +11 -10
- package/executeWithRetry.js.map +1 -1
- package/exports/api.js +0 -2
- package/features/compression/CompressionHandler.js +21 -27
- package/features/compression/CompressionHandler.js.map +1 -1
- package/features/compression/GzipCompression.js +21 -20
- package/features/compression/GzipCompression.js.map +1 -1
- package/features/compression/JsonpackCompression.js +21 -23
- package/features/compression/JsonpackCompression.js.map +1 -1
- package/features/compression/abstractions/Compression.js +2 -1
- package/features/compression/abstractions/Compression.js.map +1 -1
- package/features/compression/abstractions/CompressionHandler.js +2 -1
- package/features/compression/abstractions/CompressionHandler.js.map +1 -1
- package/features/compression/feature.js +8 -7
- package/features/compression/feature.js.map +1 -1
- package/features/compression/legacy/CompressionPlugin.js +5 -2
- package/features/compression/legacy/CompressionPlugin.js.map +1 -1
- package/features/compression/legacy/Compressor.js +41 -53
- package/features/compression/legacy/Compressor.js.map +1 -1
- package/features/compression/legacy/gzip.js +12 -21
- package/features/compression/legacy/gzip.js.map +1 -1
- package/features/compression/legacy/index.js +0 -2
- package/features/compression/legacy/jsonpack.js +5 -8
- package/features/compression/legacy/jsonpack.js.map +1 -1
- package/features/compression/legacy/plugins/GzipCompression.js +52 -45
- package/features/compression/legacy/plugins/GzipCompression.js.map +1 -1
- package/features/compression/legacy/plugins/JsonpackCompression.js +32 -41
- package/features/compression/legacy/plugins/JsonpackCompression.js.map +1 -1
- package/generateId.js +7 -8
- package/generateId.js.map +1 -1
- package/getObjectProperties.js +7 -12
- package/getObjectProperties.js.map +1 -1
- package/headers.js +9 -13
- package/headers.js.map +1 -1
- package/index.js +1 -4
- package/mdbid.js +3 -4
- package/mdbid.js.map +1 -1
- package/middleware.js +25 -37
- package/middleware.js.map +1 -1
- package/package.json +8 -8
- package/parseIdentifier.js +16 -26
- package/parseIdentifier.js.map +1 -1
- package/removeNullValues.js +5 -9
- package/removeNullValues.js.map +1 -1
- package/removeUndefinedValues.js +5 -9
- package/removeUndefinedValues.js.map +1 -1
- package/utcTimezones.js +159 -118
- package/utcTimezones.js.map +1 -1
- package/zeroPad.js +2 -7
- package/zeroPad.js.map +1 -1
- package/GenericRecord.js.map +0 -1
- package/exports/api.js.map +0 -1
- package/features/compression/legacy/index.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/abstractions/CompressionHandler.js","sources":["../../../../src/features/compression/abstractions/CompressionHandler.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface ICompressedValue {\n compression: string;\n value: string;\n}\n\nexport interface ICompressionHandler {\n /**\n * Compresses the given data using the first plugin that can compress it.\n */\n compress<T = unknown>(data: T): Promise<ICompressedValue>;\n /**\n * Decompresses the given data using the first plugin that can decompress it.\n */\n decompress<T = unknown>(data: ICompressedValue | unknown): Promise<T>;\n}\n\nexport const CompressionHandler = createAbstraction<ICompressionHandler>(\"Api/Compression/Handler\");\n\nexport namespace CompressionHandler {\n export type Interface = ICompressionHandler;\n export type CompressParams<T = unknown> = T;\n export type CompressResponse = Promise<ICompressedValue>;\n export type DecompressParams = ICompressedValue | unknown;\n export type DecompressResponse<T = unknown> = Promise<T>;\n}\n"],"names":["CompressionHandler","createAbstraction"],"mappings":";AAkBO,MAAMA,qBAAqBC,kBAAuC"}
|
|
@@ -2,13 +2,14 @@ import { createFeature } from "@webiny/feature/api";
|
|
|
2
2
|
import { CompressionHandler } from "./CompressionHandler.js";
|
|
3
3
|
import { GzipCompression } from "./GzipCompression.js";
|
|
4
4
|
import { JsonpackCompression } from "./JsonpackCompression.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const CompressionFeature = createFeature({
|
|
6
|
+
name: "Api/CompressionFeature",
|
|
7
|
+
register: (container)=>{
|
|
8
|
+
container.register(GzipCompression);
|
|
9
|
+
container.register(JsonpackCompression);
|
|
10
|
+
container.register(CompressionHandler);
|
|
11
|
+
}
|
|
12
12
|
});
|
|
13
|
+
export { CompressionFeature };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/feature.js","sources":["../../../src/features/compression/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CompressionHandler } from \"./CompressionHandler.js\";\nimport { GzipCompression } from \"./GzipCompression.js\";\nimport { JsonpackCompression } from \"./JsonpackCompression.js\";\n\nexport const CompressionFeature = createFeature({\n name: \"Api/CompressionFeature\",\n register: container => {\n container.register(GzipCompression);\n container.register(JsonpackCompression);\n container.register(CompressionHandler);\n }\n});\n"],"names":["CompressionFeature","createFeature","container","GzipCompression","JsonpackCompression","CompressionHandler"],"mappings":";;;;AAKO,MAAMA,qBAAqBC,cAAc;IAC5C,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
class CompressionPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "utils.compression";
|
|
5
|
+
}
|
|
4
6
|
}
|
|
7
|
+
export { CompressionPlugin };
|
|
5
8
|
|
|
6
9
|
//# sourceMappingURL=CompressionPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/legacy/CompressionPlugin.js","sources":["../../../../src/features/compression/legacy/CompressionPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\n\nexport interface ICompressedValue {\n compression: string;\n value: string;\n}\n\nexport abstract class CompressionPlugin extends Plugin {\n public static override type: string = \"utils.compression\";\n public abstract canCompress(data: any): boolean;\n public abstract compress(data: any): Promise<ICompressedValue>;\n public abstract canDecompress(data: ICompressedValue | unknown): boolean;\n public abstract decompress(data: ICompressedValue | unknown): Promise<any>;\n}\n"],"names":["CompressionPlugin","Plugin"],"mappings":";AAOO,MAAeA,0BAA0BC;;aACrB,IAAI,GAAW;;AAK1C"}
|
|
@@ -2,62 +2,50 @@ import { CompressionPlugin } from "./CompressionPlugin.js";
|
|
|
2
2
|
import { createGzipCompression } from "./plugins/GzipCompression.js";
|
|
3
3
|
import { createJsonpackCompression } from "./plugins/JsonpackCompression.js";
|
|
4
4
|
class Compressor {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return this._plugins.byType(CompressionPlugin.type).reverse();
|
|
8
|
-
}
|
|
9
|
-
constructor(params) {
|
|
10
|
-
this._plugins = params.plugins;
|
|
11
|
-
}
|
|
12
|
-
disable(name) {
|
|
13
|
-
this.disabled.add(name);
|
|
14
|
-
}
|
|
15
|
-
enable(name) {
|
|
16
|
-
this.disabled.delete(name);
|
|
17
|
-
}
|
|
18
|
-
async compress(data) {
|
|
19
|
-
for (const plugin of this.plugins) {
|
|
20
|
-
/**
|
|
21
|
-
* We skip disabled plugins.
|
|
22
|
-
*/
|
|
23
|
-
if (plugin.name && this.disabled.has(plugin.name)) {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (plugin.canCompress(data) === false) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
return await plugin.compress(data);
|
|
31
|
-
} catch (ex) {
|
|
32
|
-
console.error(`Could not compress given data. More info in next line. Trying next plugin.`);
|
|
33
|
-
console.log(ex);
|
|
34
|
-
}
|
|
5
|
+
get plugins() {
|
|
6
|
+
return this._plugins.byType(CompressionPlugin.type).reverse();
|
|
35
7
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
8
|
+
constructor(params){
|
|
9
|
+
this.disabled = new Set();
|
|
10
|
+
this._plugins = params.plugins;
|
|
11
|
+
}
|
|
12
|
+
disable(name) {
|
|
13
|
+
this.disabled.add(name);
|
|
14
|
+
}
|
|
15
|
+
enable(name) {
|
|
16
|
+
this.disabled.delete(name);
|
|
17
|
+
}
|
|
18
|
+
async compress(data) {
|
|
19
|
+
for (const plugin of this.plugins)if (!(plugin.name && this.disabled.has(plugin.name))) {
|
|
20
|
+
if (false !== plugin.canCompress(data)) try {
|
|
21
|
+
return await plugin.compress(data);
|
|
22
|
+
} catch (ex) {
|
|
23
|
+
console.error("Could not compress given data. More info in next line. Trying next plugin.");
|
|
24
|
+
console.log(ex);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
async decompress(data) {
|
|
30
|
+
for (const plugin of this.plugins)if (false !== plugin.canDecompress(data)) try {
|
|
31
|
+
return await plugin.decompress(data);
|
|
32
|
+
} catch (ex) {
|
|
33
|
+
console.error("Could not decompress given data. More info in next line. Trying next plugin.");
|
|
34
|
+
console.log(ex);
|
|
35
|
+
}
|
|
36
|
+
return data;
|
|
49
37
|
}
|
|
50
|
-
return data;
|
|
51
|
-
}
|
|
52
38
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
plugins
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
const createDefaultCompressor = (params)=>{
|
|
40
|
+
const { plugins } = params;
|
|
41
|
+
plugins.register([
|
|
42
|
+
createJsonpackCompression(),
|
|
43
|
+
createGzipCompression()
|
|
44
|
+
]);
|
|
45
|
+
return new Compressor({
|
|
46
|
+
plugins
|
|
47
|
+
});
|
|
61
48
|
};
|
|
49
|
+
export { createDefaultCompressor };
|
|
62
50
|
|
|
63
51
|
//# sourceMappingURL=Compressor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/legacy/Compressor.js","sources":["../../../../src/features/compression/legacy/Compressor.ts"],"sourcesContent":["import type { PluginsContainer } from \"@webiny/plugins\";\nimport { CompressionPlugin, type ICompressedValue } from \"./CompressionPlugin.js\";\nimport { createGzipCompression } from \"./plugins/GzipCompression.js\";\nimport { createJsonpackCompression } from \"./plugins/JsonpackCompression.js\";\n\nexport interface ICompressorParams {\n plugins: PluginsContainer;\n}\n\nexport interface ICompressor {\n disable(name: string): void;\n enable(name: string): void;\n /**\n * Compresses the given data using the first plugin that can compress it.\n */\n compress<T = unknown>(data: T): Promise<T | ICompressedValue>;\n /**\n * Decompresses the given data using the first plugin that can decompress it.\n */\n decompress<T = unknown>(data: ICompressedValue | unknown): Promise<T>;\n}\n\nclass Compressor implements ICompressor {\n private readonly _plugins: PluginsContainer;\n\n private readonly disabled: Set<string> = new Set();\n\n private get plugins(): CompressionPlugin[] {\n return this._plugins.byType<CompressionPlugin>(CompressionPlugin.type).reverse();\n }\n\n public constructor(params: ICompressorParams) {\n this._plugins = params.plugins;\n }\n\n public disable(name: string): void {\n this.disabled.add(name);\n }\n\n public enable(name: string): void {\n this.disabled.delete(name);\n }\n\n public async compress<T = unknown>(data: T): Promise<T | ICompressedValue> {\n for (const plugin of this.plugins) {\n /**\n * We skip disabled plugins.\n */\n if (plugin.name && this.disabled.has(plugin.name)) {\n continue;\n }\n if (plugin.canCompress(data) === false) {\n continue;\n }\n try {\n return await plugin.compress(data);\n } catch (ex) {\n console.error(\n `Could not compress given data. More info in next line. Trying next plugin.`\n );\n console.log(ex);\n }\n }\n return data;\n }\n\n public async decompress<T = unknown>(data: ICompressedValue | unknown): Promise<T> {\n for (const plugin of this.plugins) {\n if (plugin.canDecompress(data) === false) {\n continue;\n }\n try {\n return await plugin.decompress(data);\n } catch (ex) {\n console.error(\n `Could not decompress given data. More info in next line. Trying next plugin.`\n );\n console.log(ex);\n }\n }\n return data as T;\n }\n}\n\nexport const createDefaultCompressor = (params: ICompressorParams) => {\n const { plugins } = params;\n plugins.register([createJsonpackCompression(), createGzipCompression()]);\n return new Compressor({\n plugins\n });\n};\n"],"names":["Compressor","CompressionPlugin","params","Set","name","data","plugin","ex","console","createDefaultCompressor","plugins","createJsonpackCompression","createGzipCompression"],"mappings":";;;AAsBA,MAAMA;IAKF,IAAY,UAA+B;QACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAoBC,kBAAkB,IAAI,EAAE,OAAO;IAClF;IAEA,YAAmBC,MAAyB,CAAE;aAN7B,QAAQ,GAAgB,IAAIC;QAOzC,IAAI,CAAC,QAAQ,GAAGD,OAAO,OAAO;IAClC;IAEO,QAAQE,IAAY,EAAQ;QAC/B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA;IACtB;IAEO,OAAOA,IAAY,EAAQ;QAC9B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACA;IACzB;IAEA,MAAa,SAAsBC,IAAO,EAAiC;QACvE,KAAK,MAAMC,UAAU,IAAI,CAAC,OAAO,CAI7B,KAAIA,CAAAA,OAAO,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAACA,OAAO,IAAI,IAGhD;YAAA,IAAIA,AAA6B,UAA7BA,OAAO,WAAW,CAACD,OAGvB,IAAI;gBACA,OAAO,MAAMC,OAAO,QAAQ,CAACD;YACjC,EAAE,OAAOE,IAAI;gBACTC,QAAQ,KAAK,CACT;gBAEJA,QAAQ,GAAG,CAACD;YAChB;QARA;QAUJ,OAAOF;IACX;IAEA,MAAa,WAAwBA,IAAgC,EAAc;QAC/E,KAAK,MAAMC,UAAU,IAAI,CAAC,OAAO,CAC7B,IAAIA,AAA+B,UAA/BA,OAAO,aAAa,CAACD,OAGzB,IAAI;YACA,OAAO,MAAMC,OAAO,UAAU,CAACD;QACnC,EAAE,OAAOE,IAAI;YACTC,QAAQ,KAAK,CACT;YAEJA,QAAQ,GAAG,CAACD;QAChB;QAEJ,OAAOF;IACX;AACJ;AAEO,MAAMI,0BAA0B,CAACP;IACpC,MAAM,EAAEQ,OAAO,EAAE,GAAGR;IACpBQ,QAAQ,QAAQ,CAAC;QAACC;QAA6BC;KAAwB;IACvE,OAAO,IAAIZ,WAAW;QAClBU;IACJ;AACJ"}
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} else {
|
|
8
|
-
reject(error);
|
|
9
|
-
}
|
|
1
|
+
import node_zlib from "node:zlib";
|
|
2
|
+
const compress = (input, options)=>new Promise(function(resolve, reject) {
|
|
3
|
+
node_zlib.gzip(input, options || {}, function(error, result) {
|
|
4
|
+
if (error) reject(error);
|
|
5
|
+
else resolve(result);
|
|
6
|
+
});
|
|
10
7
|
});
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!error) {
|
|
17
|
-
resolve(result);
|
|
18
|
-
} else {
|
|
19
|
-
reject(error);
|
|
20
|
-
}
|
|
8
|
+
const decompress = (input, options)=>new Promise(function(resolve, reject) {
|
|
9
|
+
node_zlib.gunzip(input, options || {}, function(error, result) {
|
|
10
|
+
if (error) reject(error);
|
|
11
|
+
else resolve(result);
|
|
12
|
+
});
|
|
21
13
|
});
|
|
22
|
-
|
|
23
|
-
};
|
|
14
|
+
export { compress, decompress };
|
|
24
15
|
|
|
25
16
|
//# sourceMappingURL=gzip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/legacy/gzip.js","sources":["../../../../src/features/compression/legacy/gzip.ts"],"sourcesContent":["import zlib from \"node:zlib\";\n\nexport const compress = (input: zlib.InputType, options?: zlib.ZlibOptions): Promise<Buffer> => {\n return new Promise(function (resolve, reject) {\n zlib.gzip(input, options || {}, function (error, result) {\n if (!error) {\n resolve(result);\n } else {\n reject(error);\n }\n });\n });\n};\nexport const decompress = (input: zlib.InputType, options?: zlib.ZlibOptions): Promise<Buffer> => {\n return new Promise(function (resolve, reject) {\n zlib.gunzip(input, options || {}, function (error, result) {\n if (!error) {\n resolve(result);\n } else {\n reject(error);\n }\n });\n });\n};\n"],"names":["compress","input","options","Promise","resolve","reject","zlib","error","result","decompress"],"mappings":";AAEO,MAAMA,WAAW,CAACC,OAAuBC,UACrC,IAAIC,QAAQ,SAAUC,OAAO,EAAEC,MAAM;QACxCC,UAAAA,IAAS,CAACL,OAAOC,WAAW,CAAC,GAAG,SAAUK,KAAK,EAAEC,MAAM;YACnD,IAAKD,OAGDF,OAAOE;iBAFPH,QAAQI;QAIhB;IACJ;AAEG,MAAMC,aAAa,CAACR,OAAuBC,UACvC,IAAIC,QAAQ,SAAUC,OAAO,EAAEC,MAAM;QACxCC,UAAAA,MAAW,CAACL,OAAOC,WAAW,CAAC,GAAG,SAAUK,KAAK,EAAEC,MAAM;YACrD,IAAKD,OAGDF,OAAOE;iBAFPH,QAAQI;QAIhB;IACJ"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import jsonpack from "jsonpack";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
export const decompress = async value => {
|
|
8
|
-
return jsonpack.unpack(value);
|
|
9
|
-
};
|
|
2
|
+
const compress = async (value)=>jsonpack.pack(value, {
|
|
3
|
+
verbose: false
|
|
4
|
+
});
|
|
5
|
+
const decompress = async (value)=>jsonpack.unpack(value);
|
|
6
|
+
export { compress, decompress };
|
|
10
7
|
|
|
11
8
|
//# sourceMappingURL=jsonpack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/legacy/jsonpack.js","sources":["../../../../src/features/compression/legacy/jsonpack.ts"],"sourcesContent":["import jsonpack from \"jsonpack\";\n\nexport const compress = async (value: any) => {\n return jsonpack.pack(value, {\n verbose: false\n });\n};\n\nexport const decompress = async (value: string) => {\n return jsonpack.unpack(value);\n};\n"],"names":["compress","value","jsonpack","decompress"],"mappings":";AAEO,MAAMA,WAAW,OAAOC,QACpBC,SAAS,IAAI,CAACD,OAAO;QACxB,SAAS;IACb;AAGG,MAAME,aAAa,OAAOF,QACtBC,SAAS,MAAM,CAACD"}
|
|
@@ -1,58 +1,65 @@
|
|
|
1
1
|
import { CompressionPlugin } from "../CompressionPlugin.js";
|
|
2
|
-
import { compress
|
|
2
|
+
import { compress, decompress } from "../gzip.js";
|
|
3
3
|
const GZIP = "gzip";
|
|
4
4
|
const TO_STORAGE_ENCODING = "base64";
|
|
5
5
|
const FROM_STORAGE_ENCODING = "utf8";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
return value;
|
|
6
|
+
const convertToBuffer = (value)=>{
|
|
7
|
+
if ("string" == typeof value) return Buffer.from(value, TO_STORAGE_ENCODING);
|
|
8
|
+
return value;
|
|
11
9
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return false;
|
|
10
|
+
class GzipCompression extends CompressionPlugin {
|
|
11
|
+
canCompress(data) {
|
|
12
|
+
if (!!data?.compression) return false;
|
|
13
|
+
return true;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
async compress(data) {
|
|
16
|
+
if (null == data) return data;
|
|
17
|
+
const value = await compress(JSON.stringify(data));
|
|
18
|
+
return {
|
|
19
|
+
compression: GZIP,
|
|
20
|
+
value: value.toString(TO_STORAGE_ENCODING)
|
|
21
|
+
};
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
value: value.toString(TO_STORAGE_ENCODING)
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
canDecompress(data) {
|
|
32
|
-
if (!data?.compression) {
|
|
33
|
-
return false;
|
|
23
|
+
canDecompress(data) {
|
|
24
|
+
if (!data?.compression) return false;
|
|
25
|
+
const compression = data.compression;
|
|
26
|
+
return compression.toLowerCase() === GZIP;
|
|
34
27
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
async decompress(data) {
|
|
29
|
+
if (!data) return data;
|
|
30
|
+
if (!data.value) return null;
|
|
31
|
+
let buf;
|
|
32
|
+
try {
|
|
33
|
+
buf = convertToBuffer(data.value);
|
|
34
|
+
} catch (ex) {
|
|
35
|
+
console.log("Could not convert given data to buffer.", ex.message);
|
|
36
|
+
console.log({
|
|
37
|
+
data
|
|
38
|
+
});
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
let value;
|
|
42
|
+
try {
|
|
43
|
+
const decompressed = await decompress(buf);
|
|
44
|
+
value = decompressed.toString(FROM_STORAGE_ENCODING);
|
|
45
|
+
} catch (ex) {
|
|
46
|
+
console.log("Could not decompress given data.", ex.message);
|
|
47
|
+
console.log({
|
|
48
|
+
data
|
|
49
|
+
});
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(value);
|
|
54
|
+
} catch {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
43
57
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const value = buf.toString(FROM_STORAGE_ENCODING);
|
|
47
|
-
return JSON.parse(value);
|
|
48
|
-
} catch (ex) {
|
|
49
|
-
console.log(`Could not decompress given data.`, ex.message);
|
|
50
|
-
return null;
|
|
58
|
+
constructor(...args){
|
|
59
|
+
super(...args), this.name = "utils.compression.gzip";
|
|
51
60
|
}
|
|
52
|
-
}
|
|
53
61
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
62
|
+
const createGzipCompression = ()=>new GzipCompression();
|
|
63
|
+
export { GzipCompression, convertToBuffer, createGzipCompression };
|
|
57
64
|
|
|
58
65
|
//# sourceMappingURL=GzipCompression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/legacy/plugins/GzipCompression.js","sources":["../../../../../src/features/compression/legacy/plugins/GzipCompression.ts"],"sourcesContent":["import { CompressionPlugin, type ICompressedValue } from \"../CompressionPlugin.js\";\nimport { compress as gzip, decompress as ungzip } from \"../gzip.js\";\n\nconst GZIP = \"gzip\";\nconst TO_STORAGE_ENCODING = \"base64\";\nconst FROM_STORAGE_ENCODING = \"utf8\";\n\nexport const convertToBuffer = (value: string | Buffer) => {\n if (typeof value === \"string\") {\n return Buffer.from(value, TO_STORAGE_ENCODING);\n }\n return value;\n};\n\nexport class GzipCompression extends CompressionPlugin {\n public override name = \"utils.compression.gzip\";\n\n public override canCompress(data: any): boolean {\n if (!!data?.compression) {\n return false;\n }\n return true;\n }\n\n public override async compress(data: any): Promise<ICompressedValue> {\n if (data === null || data === undefined) {\n return data;\n }\n // This stringifies both regular strings and JSON objects.\n const value = await gzip(JSON.stringify(data));\n\n return {\n compression: GZIP,\n value: value.toString(TO_STORAGE_ENCODING)\n };\n }\n\n public override canDecompress(data: Partial<ICompressedValue>): boolean {\n if (!data?.compression) {\n return false;\n }\n\n const compression = data.compression as string;\n\n return compression.toLowerCase() === GZIP;\n }\n\n public override async decompress(data: ICompressedValue): Promise<any> {\n if (!data) {\n return data;\n } else if (!data.value) {\n return null;\n }\n /**\n * First we need to convert the value to a buffer, if it fails, then we know the data is corrupted and we should return null.\n */\n let buf: Buffer;\n try {\n buf = convertToBuffer(data.value);\n } catch (ex) {\n console.log(`Could not convert given data to buffer.`, ex.message);\n console.log({\n data\n });\n return null;\n }\n /**\n * First let's attempt to ungzip the value, if it fails, then we know the data is corrupted and we should return null.\n * If it succeeds, then we can attempt to parse the value as JSON, but if that fails, we can just return the string value.\n */\n let value: string;\n try {\n const decompressed = await ungzip(buf);\n value = decompressed.toString(FROM_STORAGE_ENCODING);\n } catch (ex) {\n console.log(`Could not decompress given data.`, ex.message);\n console.log({\n data\n });\n return null;\n }\n /**\n * Legacy systems may have stored regular strings without stringify, so we should attempt to parse the value, but if it fails, just return the string.\n */\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n }\n}\n\nexport const createGzipCompression = () => {\n return new GzipCompression();\n};\n"],"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","GzipCompression","CompressionPlugin","data","gzip","JSON","compression","buf","ex","console","decompressed","ungzip","createGzipCompression"],"mappings":";;AAGA,MAAMA,OAAO;AACb,MAAMC,sBAAsB;AAC5B,MAAMC,wBAAwB;AAEvB,MAAMC,kBAAkB,CAACC;IAC5B,IAAI,AAAiB,YAAjB,OAAOA,OACP,OAAOC,OAAO,IAAI,CAACD,OAAOH;IAE9B,OAAOG;AACX;AAEO,MAAME,wBAAwBC;IAGjB,YAAYC,IAAS,EAAW;QAC5C,IAAI,CAAC,CAACA,MAAM,aACR,OAAO;QAEX,OAAO;IACX;IAEA,MAAsB,SAASA,IAAS,EAA6B;QACjE,IAAIA,QAAAA,MACA,OAAOA;QAGX,MAAMJ,QAAQ,MAAMK,SAAKC,KAAK,SAAS,CAACF;QAExC,OAAO;YACH,aAAaR;YACb,OAAOI,MAAM,QAAQ,CAACH;QAC1B;IACJ;IAEgB,cAAcO,IAA+B,EAAW;QACpE,IAAI,CAACA,MAAM,aACP,OAAO;QAGX,MAAMG,cAAcH,KAAK,WAAW;QAEpC,OAAOG,YAAY,WAAW,OAAOX;IACzC;IAEA,MAAsB,WAAWQ,IAAsB,EAAgB;QACnE,IAAI,CAACA,MACD,OAAOA;QACJ,IAAI,CAACA,KAAK,KAAK,EAClB,OAAO;QAKX,IAAII;QACJ,IAAI;YACAA,MAAMT,gBAAgBK,KAAK,KAAK;QACpC,EAAE,OAAOK,IAAI;YACTC,QAAQ,GAAG,CAAC,2CAA2CD,GAAG,OAAO;YACjEC,QAAQ,GAAG,CAAC;gBACRN;YACJ;YACA,OAAO;QACX;QAKA,IAAIJ;QACJ,IAAI;YACA,MAAMW,eAAe,MAAMC,WAAOJ;YAClCR,QAAQW,aAAa,QAAQ,CAACb;QAClC,EAAE,OAAOW,IAAI;YACTC,QAAQ,GAAG,CAAC,oCAAoCD,GAAG,OAAO;YAC1DC,QAAQ,GAAG,CAAC;gBACRN;YACJ;YACA,OAAO;QACX;QAIA,IAAI;YACA,OAAOE,KAAK,KAAK,CAACN;QACtB,EAAE,OAAM;YACJ,OAAOA;QACX;IACJ;;QA3EG,qBACa,IAAI,GAAG;;AA2E3B;AAEO,MAAMa,wBAAwB,IAC1B,IAAIX"}
|
|
@@ -1,52 +1,43 @@
|
|
|
1
1
|
import { CompressionPlugin } from "../CompressionPlugin.js";
|
|
2
2
|
import { compress, decompress } from "../jsonpack.js";
|
|
3
3
|
const JSONPACK = "jsonpack";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return false;
|
|
9
|
-
} else if (!!data.compression) {
|
|
10
|
-
return false;
|
|
4
|
+
class JsonpackCompression extends CompressionPlugin {
|
|
5
|
+
canCompress(data) {
|
|
6
|
+
"object" == typeof data && data.compression;
|
|
7
|
+
return false;
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
async compress(data) {
|
|
10
|
+
if (null == data) return data;
|
|
11
|
+
const value = await compress(data);
|
|
12
|
+
return {
|
|
13
|
+
compression: JSONPACK,
|
|
14
|
+
value
|
|
15
|
+
};
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
canDecompress(data) {
|
|
26
|
-
if (typeof data !== "object") {
|
|
27
|
-
return false;
|
|
28
|
-
} else if (!data?.compression) {
|
|
29
|
-
return false;
|
|
17
|
+
canDecompress(data) {
|
|
18
|
+
if ("object" != typeof data) return false;
|
|
19
|
+
if (!data?.compression) return false;
|
|
20
|
+
const compression = data.compression;
|
|
21
|
+
return compression.toLowerCase() === JSONPACK;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
async decompress(data) {
|
|
24
|
+
if (!data) return data;
|
|
25
|
+
if (!data.value) return null;
|
|
26
|
+
try {
|
|
27
|
+
return await decompress(data.value);
|
|
28
|
+
} catch (ex) {
|
|
29
|
+
console.log("Could not decompress given data.", ex.message);
|
|
30
|
+
console.log({
|
|
31
|
+
data
|
|
32
|
+
});
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} catch (ex) {
|
|
43
|
-
console.log(`Could not decompress given data.`, ex.message);
|
|
44
|
-
return null;
|
|
36
|
+
constructor(...args){
|
|
37
|
+
super(...args), this.name = "utils.compression.jsonpack";
|
|
45
38
|
}
|
|
46
|
-
}
|
|
47
39
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
40
|
+
const createJsonpackCompression = ()=>new JsonpackCompression();
|
|
41
|
+
export { JsonpackCompression, createJsonpackCompression };
|
|
51
42
|
|
|
52
43
|
//# sourceMappingURL=JsonpackCompression.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"features/compression/legacy/plugins/JsonpackCompression.js","sources":["../../../../../src/features/compression/legacy/plugins/JsonpackCompression.ts"],"sourcesContent":["import { CompressionPlugin, type ICompressedValue } from \"../CompressionPlugin.js\";\nimport { compress, decompress } from \"../jsonpack.js\";\n\nconst JSONPACK = \"jsonpack\";\n\nexport class JsonpackCompression extends CompressionPlugin {\n public override name = \"utils.compression.jsonpack\";\n\n public override canCompress(data: any): boolean {\n if (typeof data !== \"object\") {\n return false;\n } else if (!!data.compression) {\n return false;\n }\n // TODO Do we want to compress anything with jsonpack anymore? Maybe not...\n return false;\n }\n\n public override async compress(data: any): Promise<ICompressedValue> {\n if (data === null || data === undefined) {\n return data;\n }\n const value = await compress(data);\n\n return {\n compression: JSONPACK,\n value\n };\n }\n\n public override canDecompress(data: Partial<ICompressedValue>): boolean {\n if (typeof data !== \"object\") {\n return false;\n } else if (!data?.compression) {\n return false;\n }\n\n const compression = data.compression as string;\n return compression.toLowerCase() === JSONPACK;\n }\n\n public override async decompress(data: ICompressedValue): Promise<any> {\n if (!data) {\n return data;\n } else if (!data.value) {\n return null;\n }\n try {\n return await decompress(data.value);\n } catch (ex) {\n console.log(`Could not decompress given data.`, ex.message);\n console.log({\n data\n });\n return null;\n }\n }\n}\n\nexport const createJsonpackCompression = () => {\n return new JsonpackCompression();\n};\n"],"names":["JSONPACK","JsonpackCompression","CompressionPlugin","data","value","compress","compression","decompress","ex","console","createJsonpackCompression"],"mappings":";;AAGA,MAAMA,WAAW;AAEV,MAAMC,4BAA4BC;IAGrB,YAAYC,IAAS,EAAW;QACxB,YAAhB,OAAOA,QAEEA,KAAK,WAAW;QAI7B,OAAO;IACX;IAEA,MAAsB,SAASA,IAAS,EAA6B;QACjE,IAAIA,QAAAA,MACA,OAAOA;QAEX,MAAMC,QAAQ,MAAMC,SAASF;QAE7B,OAAO;YACH,aAAaH;YACbI;QACJ;IACJ;IAEgB,cAAcD,IAA+B,EAAW;QACpE,IAAI,AAAgB,YAAhB,OAAOA,MACP,OAAO;QACJ,IAAI,CAACA,MAAM,aACd,OAAO;QAGX,MAAMG,cAAcH,KAAK,WAAW;QACpC,OAAOG,YAAY,WAAW,OAAON;IACzC;IAEA,MAAsB,WAAWG,IAAsB,EAAgB;QACnE,IAAI,CAACA,MACD,OAAOA;QACJ,IAAI,CAACA,KAAK,KAAK,EAClB,OAAO;QAEX,IAAI;YACA,OAAO,MAAMI,WAAWJ,KAAK,KAAK;QACtC,EAAE,OAAOK,IAAI;YACTC,QAAQ,GAAG,CAAC,oCAAoCD,GAAG,OAAO;YAC1DC,QAAQ,GAAG,CAAC;gBACRN;YACJ;YACA,OAAO;QACX;IACJ;;QAnDG,qBACa,IAAI,GAAG;;AAmD3B;AAEO,MAAMO,4BAA4B,IAC9B,IAAIT"}
|
package/generateId.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { customAlphabet, nanoid } from "nanoid";
|
|
2
2
|
import { alphanumeric, lowercase, numbers, uppercase } from "nanoid-dictionary";
|
|
3
3
|
const DEFAULT_SIZE = 21;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
4
|
+
const generateAlphaNumericId = customAlphabet(alphanumeric, DEFAULT_SIZE);
|
|
5
|
+
const generateAlphaNumericLowerCaseId = customAlphabet(`${lowercase}${numbers}`, DEFAULT_SIZE);
|
|
6
|
+
const generateAlphaId = customAlphabet(`${lowercase}${uppercase}`, DEFAULT_SIZE);
|
|
7
|
+
const generateAlphaLowerCaseId = customAlphabet(lowercase, DEFAULT_SIZE);
|
|
8
|
+
const generateAlphaUpperCaseId = customAlphabet(uppercase, DEFAULT_SIZE);
|
|
9
|
+
const generateId = (size = DEFAULT_SIZE)=>nanoid(size);
|
|
10
|
+
export { generateAlphaId, generateAlphaLowerCaseId, generateAlphaNumericId, generateAlphaNumericLowerCaseId, generateAlphaUpperCaseId, generateId };
|
|
12
11
|
|
|
13
12
|
//# sourceMappingURL=generateId.js.map
|
package/generateId.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"generateId.js","sources":["../src/generateId.ts"],"sourcesContent":["import { customAlphabet, nanoid } from \"nanoid\";\nimport { alphanumeric, lowercase, numbers, uppercase } from \"nanoid-dictionary\";\n\nconst DEFAULT_SIZE = 21;\n\nexport const generateAlphaNumericId = customAlphabet(alphanumeric, DEFAULT_SIZE);\n\nexport const generateAlphaNumericLowerCaseId = customAlphabet(\n `${lowercase}${numbers}`,\n DEFAULT_SIZE\n);\n\nexport const generateAlphaId = customAlphabet(`${lowercase}${uppercase}`, DEFAULT_SIZE);\n\nexport const generateAlphaLowerCaseId = customAlphabet(lowercase, DEFAULT_SIZE);\n\nexport const generateAlphaUpperCaseId = customAlphabet(uppercase, DEFAULT_SIZE);\n\nexport const generateId = (size = DEFAULT_SIZE): string => {\n return nanoid(size);\n};\n"],"names":["DEFAULT_SIZE","generateAlphaNumericId","customAlphabet","alphanumeric","generateAlphaNumericLowerCaseId","lowercase","numbers","generateAlphaId","uppercase","generateAlphaLowerCaseId","generateAlphaUpperCaseId","generateId","size","nanoid"],"mappings":";;AAGA,MAAMA,eAAe;AAEd,MAAMC,yBAAyBC,eAAeC,cAAcH;AAE5D,MAAMI,kCAAkCF,eAC3C,GAAGG,YAAYC,SAAS,EACxBN;AAGG,MAAMO,kBAAkBL,eAAe,GAAGG,YAAYG,WAAW,EAAER;AAEnE,MAAMS,2BAA2BP,eAAeG,WAAWL;AAE3D,MAAMU,2BAA2BR,eAAeM,WAAWR;AAE3D,MAAMW,aAAa,CAACC,OAAOZ,YAAY,GACnCa,OAAOD"}
|
package/getObjectProperties.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return {};
|
|
8
|
-
}
|
|
9
|
-
return Object.getOwnPropertyNames(input).reduce((acc, key) => {
|
|
10
|
-
acc[key] = input[key];
|
|
11
|
-
return acc;
|
|
12
|
-
}, {});
|
|
1
|
+
const getObjectProperties = (input)=>{
|
|
2
|
+
if (!input || "object" != typeof input) return {};
|
|
3
|
+
return Object.getOwnPropertyNames(input).reduce((acc, key)=>{
|
|
4
|
+
acc[key] = input[key];
|
|
5
|
+
return acc;
|
|
6
|
+
}, {});
|
|
13
7
|
};
|
|
8
|
+
export { getObjectProperties };
|
|
14
9
|
|
|
15
10
|
//# sourceMappingURL=getObjectProperties.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"getObjectProperties.js","sources":["../src/getObjectProperties.ts"],"sourcesContent":["/**\n * Unfortunately we need some casting as we do not know which properties are available on the object.\n */\ninterface GenericRecord {\n [key: string]: any;\n}\n\nexport const getObjectProperties = <T = GenericRecord>(input: unknown): T => {\n if (!input || typeof input !== \"object\") {\n return {} as unknown as T;\n }\n return Object.getOwnPropertyNames(input).reduce<T>((acc, key) => {\n acc[key as keyof T] = (input as unknown as T)[key as keyof T];\n return acc;\n }, {} as T) as unknown as T;\n};\n"],"names":["getObjectProperties","input","Object","acc","key"],"mappings":"AAOO,MAAMA,sBAAsB,CAAoBC;IACnD,IAAI,CAACA,SAAS,AAAiB,YAAjB,OAAOA,OACjB,OAAO,CAAC;IAEZ,OAAOC,OAAO,mBAAmB,CAACD,OAAO,MAAM,CAAI,CAACE,KAAKC;QACrDD,GAAG,CAACC,IAAe,GAAIH,KAAsB,CAACG,IAAe;QAC7D,OAAOD;IACX,GAAG,CAAC;AACR"}
|