@webiny/utils 6.0.0-beta.0 → 6.0.0-rc.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.
Files changed (72) hide show
  1. package/GenericRecord.d.ts +1 -0
  2. package/GenericRecord.js +3 -0
  3. package/GenericRecord.js.map +1 -0
  4. package/README.md +6 -20
  5. package/cacheKey.d.ts +2 -9
  6. package/cacheKey.js +5 -11
  7. package/cacheKey.js.map +1 -1
  8. package/compose.js +2 -9
  9. package/compose.js.map +1 -1
  10. package/compression/CompressionPlugin.d.ts +12 -0
  11. package/compression/CompressionPlugin.js +6 -0
  12. package/compression/CompressionPlugin.js.map +1 -0
  13. package/compression/Compressor.d.ts +29 -0
  14. package/compression/Compressor.js +63 -0
  15. package/compression/Compressor.js.map +1 -0
  16. package/compression/gzip.d.ts +0 -1
  17. package/compression/gzip.js +5 -14
  18. package/compression/gzip.js.map +1 -1
  19. package/compression/index.d.ts +4 -0
  20. package/compression/index.js +6 -0
  21. package/compression/index.js.map +1 -0
  22. package/compression/jsonpack.d.ts +2 -0
  23. package/compression/jsonpack.js +11 -0
  24. package/compression/jsonpack.js.map +1 -0
  25. package/compression/plugins/GzipCompression.d.ts +10 -0
  26. package/compression/plugins/GzipCompression.js +58 -0
  27. package/compression/plugins/GzipCompression.js.map +1 -0
  28. package/compression/plugins/JsonpackCompression.d.ts +9 -0
  29. package/compression/plugins/JsonpackCompression.js +52 -0
  30. package/compression/plugins/JsonpackCompression.js.map +1 -0
  31. package/createIdentifier.js +5 -11
  32. package/createIdentifier.js.map +1 -1
  33. package/createZodError.d.ts +1 -1
  34. package/createZodError.js +7 -13
  35. package/createZodError.js.map +1 -1
  36. package/cursor.d.ts +2 -2
  37. package/cursor.js +2 -10
  38. package/cursor.js.map +1 -1
  39. package/exception.d.ts +6 -0
  40. package/exception.js +16 -0
  41. package/exception.js.map +1 -0
  42. package/executeWithRetry.d.ts +2 -1
  43. package/executeWithRetry.js +3 -11
  44. package/executeWithRetry.js.map +1 -1
  45. package/generateId.d.ts +5 -5
  46. package/generateId.js +9 -21
  47. package/generateId.js.map +1 -1
  48. package/getObjectProperties.js +1 -8
  49. package/getObjectProperties.js.map +1 -1
  50. package/headers.js +2 -9
  51. package/headers.js.map +1 -1
  52. package/index.d.ts +19 -16
  53. package/index.js +18 -195
  54. package/index.js.map +1 -1
  55. package/mdbid.js +4 -12
  56. package/mdbid.js.map +1 -1
  57. package/middleware.d.ts +1 -1
  58. package/middleware.js +1 -8
  59. package/middleware.js.map +1 -1
  60. package/package.json +16 -24
  61. package/parseIdentifier.d.ts +1 -1
  62. package/parseIdentifier.js +5 -14
  63. package/parseIdentifier.js.map +1 -1
  64. package/removeNullValues.d.ts +1 -1
  65. package/removeNullValues.js +1 -8
  66. package/removeNullValues.js.map +1 -1
  67. package/removeUndefinedValues.js +1 -8
  68. package/removeUndefinedValues.js.map +1 -1
  69. package/utcTimezones.js +1 -7
  70. package/utcTimezones.js.map +1 -1
  71. package/zeroPad.js +1 -8
  72. package/zeroPad.js.map +1 -1
@@ -0,0 +1 @@
1
+ export type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=GenericRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["GenericRecord.ts"],"sourcesContent":["export type GenericRecord<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;\n"],"mappings":"","ignoreList":[]}
package/README.md CHANGED
@@ -1,25 +1,11 @@
1
1
  # @webiny/utils
2
2
 
3
- [![](https://img.shields.io/npm/dw/@webiny/utils.svg)](https://www.npmjs.com/package/@webiny/utils)
4
- [![](https://img.shields.io/npm/v/@webiny/utils.svg)](https://www.npmjs.com/package/@webiny/utils)
5
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
6
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
7
6
 
8
- ## About
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
9
8
 
10
- Small package containing the methods that are used throughout our other packages.
11
- * for example, zeroPad adds zeros to the start of the version number.
9
+ ---
12
10
 
13
- ## Install
14
-
15
- ```
16
- yarn add @webiny/utils
17
- ```
18
-
19
-
20
- ## Testing
21
-
22
- ### Command
23
- ````
24
- yarn test packages/utils
25
- ````
11
+ _This README file is automatically generated during the publish process._
package/cacheKey.d.ts CHANGED
@@ -1,9 +1,2 @@
1
- /// <reference types="node" />
2
- import { BinaryToTextEncoding } from "crypto";
3
- export declare type ICacheKeyKeys = Record<string, any> | string | number;
4
- export interface ICacheKeyOptions {
5
- algorithm?: CacheKeyAlgorithmType;
6
- encoding?: BinaryToTextEncoding;
7
- }
8
- export declare type CacheKeyAlgorithmType = "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512";
9
- export declare const createCacheKey: (input: ICacheKeyKeys, options?: ICacheKeyOptions) => string;
1
+ export type ICacheKeyKeys = Record<string, any> | string | number;
2
+ export declare const createCacheKey: (input: ICacheKeyKeys) => string;
package/cacheKey.js CHANGED
@@ -1,11 +1,5 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createCacheKey = void 0;
8
- var _crypto = _interopRequireDefault(require("crypto"));
1
+ import { sha256 } from "@noble/hashes/sha2.js";
2
+ import { utf8ToBytes, bytesToHex } from "@noble/hashes/utils.js";
9
3
  const getCacheKey = input => {
10
4
  if (typeof input === "string") {
11
5
  return input;
@@ -14,10 +8,10 @@ const getCacheKey = input => {
14
8
  }
15
9
  return JSON.stringify(input);
16
10
  };
17
- const createCacheKey = (input, options) => {
11
+ export const createCacheKey = input => {
18
12
  const key = getCacheKey(input);
19
- return _crypto.default.createHash(options?.algorithm || "sha1").update(key).digest(options?.encoding || "hex");
13
+ const hash = sha256(utf8ToBytes(key));
14
+ return bytesToHex(hash);
20
15
  };
21
- exports.createCacheKey = createCacheKey;
22
16
 
23
17
  //# sourceMappingURL=cacheKey.js.map
package/cacheKey.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_crypto","_interopRequireDefault","require","getCacheKey","input","JSON","stringify","createCacheKey","options","key","crypto","createHash","algorithm","update","digest","encoding","exports"],"sources":["cacheKey.ts"],"sourcesContent":["import crypto, { BinaryToTextEncoding } from \"crypto\";\n\nexport type ICacheKeyKeys = Record<string, any> | string | number;\n\nexport interface ICacheKeyOptions {\n algorithm?: CacheKeyAlgorithmType;\n encoding?: BinaryToTextEncoding;\n}\n\nexport type CacheKeyAlgorithmType = \"md5\" | \"sha1\" | \"sha224\" | \"sha256\" | \"sha384\" | \"sha512\";\n\nconst getCacheKey = (input: ICacheKeyKeys): string => {\n if (typeof input === \"string\") {\n return input;\n } else if (typeof input === \"number\") {\n return `${input}`;\n }\n return JSON.stringify(input);\n};\n\nexport const createCacheKey = (input: ICacheKeyKeys, options?: ICacheKeyOptions): string => {\n const key = getCacheKey(input);\n return crypto\n .createHash(options?.algorithm || \"sha1\")\n .update(key)\n .digest(options?.encoding || \"hex\");\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAWA,MAAMC,WAAW,GAAIC,KAAoB,IAAa;EAClD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOA,KAAK;EAChB,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAClC,OAAQ,GAAEA,KAAM,EAAC;EACrB;EACA,OAAOC,IAAI,CAACC,SAAS,CAACF,KAAK,CAAC;AAChC,CAAC;AAEM,MAAMG,cAAc,GAAGA,CAACH,KAAoB,EAAEI,OAA0B,KAAa;EACxF,MAAMC,GAAG,GAAGN,WAAW,CAACC,KAAK,CAAC;EAC9B,OAAOM,eAAM,CACRC,UAAU,CAACH,OAAO,EAAEI,SAAS,IAAI,MAAM,CAAC,CACxCC,MAAM,CAACJ,GAAG,CAAC,CACXK,MAAM,CAACN,OAAO,EAAEO,QAAQ,IAAI,KAAK,CAAC;AAC3C,CAAC;AAACC,OAAA,CAAAT,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"names":["sha256","utf8ToBytes","bytesToHex","getCacheKey","input","JSON","stringify","createCacheKey","key","hash"],"sources":["cacheKey.ts"],"sourcesContent":["import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { utf8ToBytes, bytesToHex } from \"@noble/hashes/utils.js\";\n\nexport type ICacheKeyKeys = Record<string, any> | string | number;\n\nconst getCacheKey = (input: ICacheKeyKeys): string => {\n if (typeof input === \"string\") {\n return input;\n } else if (typeof input === \"number\") {\n return `${input}`;\n }\n return JSON.stringify(input);\n};\n\nexport const createCacheKey = (input: ICacheKeyKeys): string => {\n const key = getCacheKey(input);\n\n const hash = sha256(utf8ToBytes(key));\n\n return bytesToHex(hash);\n};\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,WAAW,EAAEC,UAAU,QAAQ,wBAAwB;AAIhE,MAAMC,WAAW,GAAIC,KAAoB,IAAa;EAClD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOA,KAAK;EAChB,CAAC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAClC,OAAO,GAAGA,KAAK,EAAE;EACrB;EACA,OAAOC,IAAI,CAACC,SAAS,CAACF,KAAK,CAAC;AAChC,CAAC;AAED,OAAO,MAAMG,cAAc,GAAIH,KAAoB,IAAa;EAC5D,MAAMI,GAAG,GAAGL,WAAW,CAACC,KAAK,CAAC;EAE9B,MAAMK,IAAI,GAAGT,MAAM,CAACC,WAAW,CAACO,GAAG,CAAC,CAAC;EAErC,OAAON,UAAU,CAACO,IAAI,CAAC;AAC3B,CAAC","ignoreList":[]}
package/compose.js CHANGED
@@ -1,11 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.composeAsync = composeAsync;
7
- exports.composeSync = composeSync;
8
- function composeAsync(functions = []) {
1
+ export function composeAsync(functions = []) {
9
2
  return input => {
10
3
  if (!functions.length) {
11
4
  return Promise.resolve(input);
@@ -22,7 +15,7 @@ function composeAsync(functions = []) {
22
15
  return next(input);
23
16
  };
24
17
  }
25
- function composeSync(functions = []) {
18
+ export function composeSync(functions = []) {
26
19
  return input => {
27
20
  if (!functions.length) {
28
21
  return input;
package/compose.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["composeAsync","functions","input","length","Promise","resolve","index","next","fn","composeSync"],"sources":["compose.ts"],"sourcesContent":["export interface NextAsyncProcessor<TInput, TOutput> {\n (input: TInput): Promise<TOutput>;\n}\n\nexport interface AsyncProcessor<TInput, TOutput = TInput> {\n (next: NextAsyncProcessor<TInput, TOutput>): NextAsyncProcessor<TInput, TOutput>;\n}\n\nexport interface NextSyncProcessor<TInput, TOutput = TInput> {\n (input: TInput): TOutput;\n}\n\nexport interface SyncProcessor<TInput, TOutput = TInput> {\n (next: NextSyncProcessor<TInput, TOutput>): NextSyncProcessor<TInput, TOutput>;\n}\n\nexport function composeAsync<TInput = unknown, TOutput = TInput>(\n functions: Array<AsyncProcessor<TInput, TOutput>> = []\n): NextAsyncProcessor<TInput, TOutput> {\n return (input: TInput): Promise<TOutput> => {\n if (!functions.length) {\n return Promise.resolve(input as unknown as TOutput);\n }\n\n let index = -1;\n\n const next: NextAsyncProcessor<TInput, TOutput> = async input => {\n index++;\n\n const fn = functions[index];\n if (!fn) {\n return input as unknown as TOutput;\n }\n\n return fn(next)(input);\n };\n\n return next(input);\n };\n}\n\nexport function composeSync<TInput = unknown, TOutput = TInput>(\n functions: Array<SyncProcessor<TInput, TOutput>> = []\n): NextSyncProcessor<TInput, TOutput> {\n return (input: TInput): TOutput => {\n if (!functions.length) {\n return input as unknown as TOutput;\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n let index = -1;\n\n const next: NextSyncProcessor<TInput, TOutput> = input => {\n index++;\n\n const fn = functions[index];\n if (!fn) {\n return input as unknown as TOutput;\n }\n\n return fn(next)(input);\n };\n\n return next(input);\n };\n}\n"],"mappings":";;;;;;;AAgBO,SAASA,YAAYA,CACxBC,SAAiD,GAAG,EAAE,EACnB;EACnC,OAAQC,KAAa,IAAuB;IACxC,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE;MACnB,OAAOC,OAAO,CAACC,OAAO,CAACH,KAA2B,CAAC;IACvD;IAEA,IAAII,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMC,IAAyC,GAAG,MAAML,KAAK,IAAI;MAC7DI,KAAK,EAAE;MAEP,MAAME,EAAE,GAAGP,SAAS,CAACK,KAAK,CAAC;MAC3B,IAAI,CAACE,EAAE,EAAE;QACL,OAAON,KAAK;MAChB;MAEA,OAAOM,EAAE,CAACD,IAAI,CAAC,CAACL,KAAK,CAAC;IAC1B,CAAC;IAED,OAAOK,IAAI,CAACL,KAAK,CAAC;EACtB,CAAC;AACL;AAEO,SAASO,WAAWA,CACvBR,SAAgD,GAAG,EAAE,EACnB;EAClC,OAAQC,KAAa,IAAc;IAC/B,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE;MACnB,OAAOD,KAAK;IAChB;;IAEA;IACA,IAAII,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMC,IAAwC,GAAGL,KAAK,IAAI;MACtDI,KAAK,EAAE;MAEP,MAAME,EAAE,GAAGP,SAAS,CAACK,KAAK,CAAC;MAC3B,IAAI,CAACE,EAAE,EAAE;QACL,OAAON,KAAK;MAChB;MAEA,OAAOM,EAAE,CAACD,IAAI,CAAC,CAACL,KAAK,CAAC;IAC1B,CAAC;IAED,OAAOK,IAAI,CAACL,KAAK,CAAC;EACtB,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"names":["composeAsync","functions","input","length","Promise","resolve","index","next","fn","composeSync"],"sources":["compose.ts"],"sourcesContent":["export interface NextAsyncProcessor<TInput, TOutput> {\n (input: TInput): Promise<TOutput>;\n}\n\nexport interface AsyncProcessor<TInput, TOutput = TInput> {\n (next: NextAsyncProcessor<TInput, TOutput>): NextAsyncProcessor<TInput, TOutput>;\n}\n\nexport interface NextSyncProcessor<TInput, TOutput = TInput> {\n (input: TInput): TOutput;\n}\n\nexport interface SyncProcessor<TInput, TOutput = TInput> {\n (next: NextSyncProcessor<TInput, TOutput>): NextSyncProcessor<TInput, TOutput>;\n}\n\nexport function composeAsync<TInput = unknown, TOutput = TInput>(\n functions: Array<AsyncProcessor<TInput, TOutput>> = []\n): NextAsyncProcessor<TInput, TOutput> {\n return (input: TInput): Promise<TOutput> => {\n if (!functions.length) {\n return Promise.resolve(input as unknown as TOutput);\n }\n\n let index = -1;\n\n const next: NextAsyncProcessor<TInput, TOutput> = async input => {\n index++;\n\n const fn = functions[index];\n if (!fn) {\n return input as unknown as TOutput;\n }\n\n return fn(next)(input);\n };\n\n return next(input);\n };\n}\n\nexport function composeSync<TInput = unknown, TOutput = TInput>(\n functions: Array<SyncProcessor<TInput, TOutput>> = []\n): NextSyncProcessor<TInput, TOutput> {\n return (input: TInput): TOutput => {\n if (!functions.length) {\n return input as unknown as TOutput;\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n let index = -1;\n\n const next: NextSyncProcessor<TInput, TOutput> = input => {\n index++;\n\n const fn = functions[index];\n if (!fn) {\n return input as unknown as TOutput;\n }\n\n return fn(next)(input);\n };\n\n return next(input);\n };\n}\n"],"mappings":"AAgBA,OAAO,SAASA,YAAYA,CACxBC,SAAiD,GAAG,EAAE,EACnB;EACnC,OAAQC,KAAa,IAAuB;IACxC,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE;MACnB,OAAOC,OAAO,CAACC,OAAO,CAACH,KAA2B,CAAC;IACvD;IAEA,IAAII,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMC,IAAyC,GAAG,MAAML,KAAK,IAAI;MAC7DI,KAAK,EAAE;MAEP,MAAME,EAAE,GAAGP,SAAS,CAACK,KAAK,CAAC;MAC3B,IAAI,CAACE,EAAE,EAAE;QACL,OAAON,KAAK;MAChB;MAEA,OAAOM,EAAE,CAACD,IAAI,CAAC,CAACL,KAAK,CAAC;IAC1B,CAAC;IAED,OAAOK,IAAI,CAACL,KAAK,CAAC;EACtB,CAAC;AACL;AAEA,OAAO,SAASO,WAAWA,CACvBR,SAAgD,GAAG,EAAE,EACnB;EAClC,OAAQC,KAAa,IAAc;IAC/B,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE;MACnB,OAAOD,KAAK;IAChB;;IAEA;IACA,IAAII,KAAK,GAAG,CAAC,CAAC;IAEd,MAAMC,IAAwC,GAAGL,KAAK,IAAI;MACtDI,KAAK,EAAE;MAEP,MAAME,EAAE,GAAGP,SAAS,CAACK,KAAK,CAAC;MAC3B,IAAI,CAACE,EAAE,EAAE;QACL,OAAON,KAAK;MAChB;MAEA,OAAOM,EAAE,CAACD,IAAI,CAAC,CAACL,KAAK,CAAC;IAC1B,CAAC;IAED,OAAOK,IAAI,CAACL,KAAK,CAAC;EACtB,CAAC;AACL","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ export interface ICompressedValue {
3
+ compression: string;
4
+ value: string;
5
+ }
6
+ export declare abstract class CompressionPlugin extends Plugin {
7
+ static type: string;
8
+ abstract canCompress(data: any): boolean;
9
+ abstract compress(data: any): Promise<ICompressedValue>;
10
+ abstract canDecompress(data: ICompressedValue | unknown): boolean;
11
+ abstract decompress(data: ICompressedValue | unknown): Promise<any>;
12
+ }
@@ -0,0 +1,6 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ export class CompressionPlugin extends Plugin {
3
+ static type = "utils.compression";
4
+ }
5
+
6
+ //# sourceMappingURL=CompressionPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Plugin","CompressionPlugin","type"],"sources":["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"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iBAAiB;AAOxC,OAAO,MAAeC,iBAAiB,SAASD,MAAM,CAAC;EACnD,OAAuBE,IAAI,GAAW,mBAAmB;AAK7D","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ import type { PluginsContainer } from "@webiny/plugins";
2
+ import { type ICompressedValue } from "./CompressionPlugin.js";
3
+ export interface ICompressorParams {
4
+ plugins: PluginsContainer;
5
+ }
6
+ export interface ICompressor {
7
+ disable(name: string): void;
8
+ enable(name: string): void;
9
+ /**
10
+ * Compresses the given data using the first plugin that can compress it.
11
+ */
12
+ compress<T = unknown>(data: T): Promise<T | ICompressedValue>;
13
+ /**
14
+ * Decompresses the given data using the first plugin that can decompress it.
15
+ */
16
+ decompress<T = unknown>(data: ICompressedValue | unknown): Promise<T>;
17
+ }
18
+ declare class Compressor implements ICompressor {
19
+ private readonly _plugins;
20
+ private readonly disabled;
21
+ private get plugins();
22
+ constructor(params: ICompressorParams);
23
+ disable(name: string): void;
24
+ enable(name: string): void;
25
+ compress<T = unknown>(data: T): Promise<T | ICompressedValue>;
26
+ decompress<T = unknown>(data: ICompressedValue | unknown): Promise<T>;
27
+ }
28
+ export declare const createDefaultCompressor: (params: ICompressorParams) => Compressor;
29
+ export {};
@@ -0,0 +1,63 @@
1
+ import { CompressionPlugin } from "./CompressionPlugin.js";
2
+ import { createGzipCompression } from "./plugins/GzipCompression.js";
3
+ import { createJsonpackCompression } from "./plugins/JsonpackCompression.js";
4
+ class Compressor {
5
+ disabled = new Set();
6
+ get plugins() {
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
+ }
35
+ }
36
+ return data;
37
+ }
38
+ async decompress(data) {
39
+ for (const plugin of this.plugins) {
40
+ if (plugin.canDecompress(data) === false) {
41
+ continue;
42
+ }
43
+ try {
44
+ return await plugin.decompress(data);
45
+ } catch (ex) {
46
+ console.error(`Could not decompress given data. More info in next line. Trying next plugin.`);
47
+ console.log(ex);
48
+ }
49
+ }
50
+ return data;
51
+ }
52
+ }
53
+ export const createDefaultCompressor = params => {
54
+ const {
55
+ plugins
56
+ } = params;
57
+ plugins.register([createJsonpackCompression(), createGzipCompression()]);
58
+ return new Compressor({
59
+ plugins
60
+ });
61
+ };
62
+
63
+ //# sourceMappingURL=Compressor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CompressionPlugin","createGzipCompression","createJsonpackCompression","Compressor","disabled","Set","plugins","_plugins","byType","type","reverse","constructor","params","disable","name","add","enable","delete","compress","data","plugin","has","canCompress","ex","console","error","log","decompress","canDecompress","createDefaultCompressor","register"],"sources":["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"],"mappings":"AACA,SAASA,iBAAiB;AAC1B,SAASC,qBAAqB;AAC9B,SAASC,yBAAyB;AAmBlC,MAAMC,UAAU,CAAwB;EAGnBC,QAAQ,GAAgB,IAAIC,GAAG,CAAC,CAAC;EAElD,IAAYC,OAAOA,CAAA,EAAwB;IACvC,OAAO,IAAI,CAACC,QAAQ,CAACC,MAAM,CAAoBR,iBAAiB,CAACS,IAAI,CAAC,CAACC,OAAO,CAAC,CAAC;EACpF;EAEOC,WAAWA,CAACC,MAAyB,EAAE;IAC1C,IAAI,CAACL,QAAQ,GAAGK,MAAM,CAACN,OAAO;EAClC;EAEOO,OAAOA,CAACC,IAAY,EAAQ;IAC/B,IAAI,CAACV,QAAQ,CAACW,GAAG,CAACD,IAAI,CAAC;EAC3B;EAEOE,MAAMA,CAACF,IAAY,EAAQ;IAC9B,IAAI,CAACV,QAAQ,CAACa,MAAM,CAACH,IAAI,CAAC;EAC9B;EAEA,MAAaI,QAAQA,CAAcC,IAAO,EAAiC;IACvE,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACd,OAAO,EAAE;MAC/B;AACZ;AACA;MACY,IAAIc,MAAM,CAACN,IAAI,IAAI,IAAI,CAACV,QAAQ,CAACiB,GAAG,CAACD,MAAM,CAACN,IAAI,CAAC,EAAE;QAC/C;MACJ;MACA,IAAIM,MAAM,CAACE,WAAW,CAACH,IAAI,CAAC,KAAK,KAAK,EAAE;QACpC;MACJ;MACA,IAAI;QACA,OAAO,MAAMC,MAAM,CAACF,QAAQ,CAACC,IAAI,CAAC;MACtC,CAAC,CAAC,OAAOI,EAAE,EAAE;QACTC,OAAO,CAACC,KAAK,CACT,4EACJ,CAAC;QACDD,OAAO,CAACE,GAAG,CAACH,EAAE,CAAC;MACnB;IACJ;IACA,OAAOJ,IAAI;EACf;EAEA,MAAaQ,UAAUA,CAAcR,IAAgC,EAAc;IAC/E,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACd,OAAO,EAAE;MAC/B,IAAIc,MAAM,CAACQ,aAAa,CAACT,IAAI,CAAC,KAAK,KAAK,EAAE;QACtC;MACJ;MACA,IAAI;QACA,OAAO,MAAMC,MAAM,CAACO,UAAU,CAACR,IAAI,CAAC;MACxC,CAAC,CAAC,OAAOI,EAAE,EAAE;QACTC,OAAO,CAACC,KAAK,CACT,8EACJ,CAAC;QACDD,OAAO,CAACE,GAAG,CAACH,EAAE,CAAC;MACnB;IACJ;IACA,OAAOJ,IAAI;EACf;AACJ;AAEA,OAAO,MAAMU,uBAAuB,GAAIjB,MAAyB,IAAK;EAClE,MAAM;IAAEN;EAAQ,CAAC,GAAGM,MAAM;EAC1BN,OAAO,CAACwB,QAAQ,CAAC,CAAC5B,yBAAyB,CAAC,CAAC,EAAED,qBAAqB,CAAC,CAAC,CAAC,CAAC;EACxE,OAAO,IAAIE,UAAU,CAAC;IAClBG;EACJ,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import zlib from "zlib";
3
2
  export declare const compress: (input: zlib.InputType, options?: zlib.ZlibOptions) => Promise<Buffer>;
4
3
  export declare const decompress: (input: zlib.InputType, options?: zlib.ZlibOptions) => Promise<Buffer>;
@@ -1,14 +1,7 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.decompress = exports.compress = void 0;
8
- var _zlib = _interopRequireDefault(require("zlib"));
9
- const compress = (input, options) => {
1
+ import zlib from "zlib";
2
+ export const compress = (input, options) => {
10
3
  return new Promise(function (resolve, reject) {
11
- _zlib.default.gzip(input, options || {}, function (error, result) {
4
+ zlib.gzip(input, options || {}, function (error, result) {
12
5
  if (!error) {
13
6
  resolve(result);
14
7
  } else {
@@ -17,10 +10,9 @@ const compress = (input, options) => {
17
10
  });
18
11
  });
19
12
  };
20
- exports.compress = compress;
21
- const decompress = (input, options) => {
13
+ export const decompress = (input, options) => {
22
14
  return new Promise(function (resolve, reject) {
23
- _zlib.default.gunzip(input, options || {}, function (error, result) {
15
+ zlib.gunzip(input, options || {}, function (error, result) {
24
16
  if (!error) {
25
17
  resolve(result);
26
18
  } else {
@@ -29,6 +21,5 @@ const decompress = (input, options) => {
29
21
  });
30
22
  });
31
23
  };
32
- exports.decompress = decompress;
33
24
 
34
25
  //# sourceMappingURL=gzip.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_zlib","_interopRequireDefault","require","compress","input","options","Promise","resolve","reject","zlib","gzip","error","result","exports","decompress","gunzip"],"sources":["gzip.ts"],"sourcesContent":["import zlib from \"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"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,MAAMC,QAAQ,GAAGA,CAACC,KAAqB,EAAEC,OAA0B,KAAsB;EAC5F,OAAO,IAAIC,OAAO,CAAC,UAAUC,OAAO,EAAEC,MAAM,EAAE;IAC1CC,aAAI,CAACC,IAAI,CAACN,KAAK,EAAEC,OAAO,IAAI,CAAC,CAAC,EAAE,UAAUM,KAAK,EAAEC,MAAM,EAAE;MACrD,IAAI,CAACD,KAAK,EAAE;QACRJ,OAAO,CAACK,MAAM,CAAC;MACnB,CAAC,MAAM;QACHJ,MAAM,CAACG,KAAK,CAAC;MACjB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAV,QAAA,GAAAA,QAAA;AACK,MAAMW,UAAU,GAAGA,CAACV,KAAqB,EAAEC,OAA0B,KAAsB;EAC9F,OAAO,IAAIC,OAAO,CAAC,UAAUC,OAAO,EAAEC,MAAM,EAAE;IAC1CC,aAAI,CAACM,MAAM,CAACX,KAAK,EAAEC,OAAO,IAAI,CAAC,CAAC,EAAE,UAAUM,KAAK,EAAEC,MAAM,EAAE;MACvD,IAAI,CAACD,KAAK,EAAE;QACRJ,OAAO,CAACK,MAAM,CAAC;MACnB,CAAC,MAAM;QACHJ,MAAM,CAACG,KAAK,CAAC;MACjB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAC,UAAA,GAAAA,UAAA","ignoreList":[]}
1
+ {"version":3,"names":["zlib","compress","input","options","Promise","resolve","reject","gzip","error","result","decompress","gunzip"],"sources":["gzip.ts"],"sourcesContent":["import zlib from \"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"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,OAAO,MAAMC,QAAQ,GAAGA,CAACC,KAAqB,EAAEC,OAA0B,KAAsB;EAC5F,OAAO,IAAIC,OAAO,CAAC,UAAUC,OAAO,EAAEC,MAAM,EAAE;IAC1CN,IAAI,CAACO,IAAI,CAACL,KAAK,EAAEC,OAAO,IAAI,CAAC,CAAC,EAAE,UAAUK,KAAK,EAAEC,MAAM,EAAE;MACrD,IAAI,CAACD,KAAK,EAAE;QACRH,OAAO,CAACI,MAAM,CAAC;MACnB,CAAC,MAAM;QACHH,MAAM,CAACE,KAAK,CAAC;MACjB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AACD,OAAO,MAAME,UAAU,GAAGA,CAACR,KAAqB,EAAEC,OAA0B,KAAsB;EAC9F,OAAO,IAAIC,OAAO,CAAC,UAAUC,OAAO,EAAEC,MAAM,EAAE;IAC1CN,IAAI,CAACW,MAAM,CAACT,KAAK,EAAEC,OAAO,IAAI,CAAC,CAAC,EAAE,UAAUK,KAAK,EAAEC,MAAM,EAAE;MACvD,IAAI,CAACD,KAAK,EAAE;QACRH,OAAO,CAACI,MAAM,CAAC;MACnB,CAAC,MAAM;QACHH,MAAM,CAACE,KAAK,CAAC;MACjB;IACJ,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export * from "./Compressor.js";
2
+ export * from "./CompressionPlugin.js";
3
+ export * from "./plugins/GzipCompression.js";
4
+ export * from "./plugins/JsonpackCompression.js";
@@ -0,0 +1,6 @@
1
+ export * from "./Compressor.js";
2
+ export * from "./CompressionPlugin.js";
3
+ export * from "./plugins/GzipCompression.js";
4
+ export * from "./plugins/JsonpackCompression.js";
5
+
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Compressor.js\";\nexport * from \"./CompressionPlugin.js\";\nexport * from \"./plugins/GzipCompression.js\";\nexport * from \"./plugins/JsonpackCompression.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export declare const compress: (value: any) => Promise<string>;
2
+ export declare const decompress: (value: string) => Promise<{}>;
@@ -0,0 +1,11 @@
1
+ import jsonpack from "jsonpack";
2
+ export const compress = async value => {
3
+ return jsonpack.pack(value, {
4
+ verbose: false
5
+ });
6
+ };
7
+ export const decompress = async value => {
8
+ return jsonpack.unpack(value);
9
+ };
10
+
11
+ //# sourceMappingURL=jsonpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["jsonpack","compress","value","pack","verbose","decompress","unpack"],"sources":["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"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,UAAU;AAE/B,OAAO,MAAMC,QAAQ,GAAG,MAAOC,KAAU,IAAK;EAC1C,OAAOF,QAAQ,CAACG,IAAI,CAACD,KAAK,EAAE;IACxBE,OAAO,EAAE;EACb,CAAC,CAAC;AACN,CAAC;AAED,OAAO,MAAMC,UAAU,GAAG,MAAOH,KAAa,IAAK;EAC/C,OAAOF,QAAQ,CAACM,MAAM,CAACJ,KAAK,CAAC;AACjC,CAAC","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ import { CompressionPlugin, type ICompressedValue } from "../CompressionPlugin.js";
2
+ export declare const convertToBuffer: (value: string | Buffer) => Buffer<ArrayBufferLike>;
3
+ export declare class GzipCompression extends CompressionPlugin {
4
+ name: string;
5
+ canCompress(data: any): boolean;
6
+ compress(data: any): Promise<ICompressedValue>;
7
+ canDecompress(data: Partial<ICompressedValue>): boolean;
8
+ decompress(data: ICompressedValue): Promise<any>;
9
+ }
10
+ export declare const createGzipCompression: () => GzipCompression;
@@ -0,0 +1,58 @@
1
+ import { CompressionPlugin } from "../CompressionPlugin.js";
2
+ import { compress as gzip, decompress as ungzip } from "../gzip.js";
3
+ const GZIP = "gzip";
4
+ const TO_STORAGE_ENCODING = "base64";
5
+ const FROM_STORAGE_ENCODING = "utf8";
6
+ export const convertToBuffer = value => {
7
+ if (typeof value === "string") {
8
+ return Buffer.from(value, TO_STORAGE_ENCODING);
9
+ }
10
+ return value;
11
+ };
12
+ export class GzipCompression extends CompressionPlugin {
13
+ name = "utils.compression.gzip";
14
+ canCompress(data) {
15
+ if (!!data?.compression) {
16
+ return false;
17
+ }
18
+ return true;
19
+ }
20
+ async compress(data) {
21
+ if (data === null || data === undefined) {
22
+ return data;
23
+ }
24
+ // This stringifies both regular strings and JSON objects.
25
+ const value = await gzip(JSON.stringify(data));
26
+ return {
27
+ compression: GZIP,
28
+ value: value.toString(TO_STORAGE_ENCODING)
29
+ };
30
+ }
31
+ canDecompress(data) {
32
+ if (!data?.compression) {
33
+ return false;
34
+ }
35
+ const compression = data.compression;
36
+ return compression.toLowerCase() === GZIP;
37
+ }
38
+ async decompress(data) {
39
+ if (!data) {
40
+ return data;
41
+ } else if (!data.value) {
42
+ return null;
43
+ }
44
+ try {
45
+ const buf = await ungzip(convertToBuffer(data.value));
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;
51
+ }
52
+ }
53
+ }
54
+ export const createGzipCompression = () => {
55
+ return new GzipCompression();
56
+ };
57
+
58
+ //# sourceMappingURL=GzipCompression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CompressionPlugin","compress","gzip","decompress","ungzip","GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","GzipCompression","name","canCompress","data","compression","undefined","JSON","stringify","toString","canDecompress","toLowerCase","buf","parse","ex","console","log","message","createGzipCompression"],"sources":["GzipCompression.ts"],"sourcesContent":["import { CompressionPlugin, type ICompressedValue } from \"../CompressionPlugin.js\";\nimport { compress as gzip, decompress as ungzip } from \"~/compression/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 try {\n const buf = await ungzip(convertToBuffer(data.value));\n const value = buf.toString(FROM_STORAGE_ENCODING);\n return JSON.parse(value);\n } catch (ex) {\n console.log(`Could not decompress given data.`, ex.message);\n return null;\n }\n }\n}\n\nexport const createGzipCompression = () => {\n return new GzipCompression();\n};\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,QAAQ,IAAIC,IAAI,EAAEC,UAAU,IAAIC,MAAM;AAE/C,MAAMC,IAAI,GAAG,MAAM;AACnB,MAAMC,mBAAmB,GAAG,QAAQ;AACpC,MAAMC,qBAAqB,GAAG,MAAM;AAEpC,OAAO,MAAMC,eAAe,GAAIC,KAAsB,IAAK;EACvD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOC,MAAM,CAACC,IAAI,CAACF,KAAK,EAAEH,mBAAmB,CAAC;EAClD;EACA,OAAOG,KAAK;AAChB,CAAC;AAED,OAAO,MAAMG,eAAe,SAASZ,iBAAiB,CAAC;EACnCa,IAAI,GAAG,wBAAwB;EAE/BC,WAAWA,CAACC,IAAS,EAAW;IAC5C,IAAI,CAAC,CAACA,IAAI,EAAEC,WAAW,EAAE;MACrB,OAAO,KAAK;IAChB;IACA,OAAO,IAAI;EACf;EAEA,MAAsBf,QAAQA,CAACc,IAAS,EAA6B;IACjE,IAAIA,IAAI,KAAK,IAAI,IAAIA,IAAI,KAAKE,SAAS,EAAE;MACrC,OAAOF,IAAI;IACf;IACA;IACA,MAAMN,KAAK,GAAG,MAAMP,IAAI,CAACgB,IAAI,CAACC,SAAS,CAACJ,IAAI,CAAC,CAAC;IAE9C,OAAO;MACHC,WAAW,EAAEX,IAAI;MACjBI,KAAK,EAAEA,KAAK,CAACW,QAAQ,CAACd,mBAAmB;IAC7C,CAAC;EACL;EAEgBe,aAAaA,CAACN,IAA+B,EAAW;IACpE,IAAI,CAACA,IAAI,EAAEC,WAAW,EAAE;MACpB,OAAO,KAAK;IAChB;IAEA,MAAMA,WAAW,GAAGD,IAAI,CAACC,WAAqB;IAE9C,OAAOA,WAAW,CAACM,WAAW,CAAC,CAAC,KAAKjB,IAAI;EAC7C;EAEA,MAAsBF,UAAUA,CAACY,IAAsB,EAAgB;IACnE,IAAI,CAACA,IAAI,EAAE;MACP,OAAOA,IAAI;IACf,CAAC,MAAM,IAAI,CAACA,IAAI,CAACN,KAAK,EAAE;MACpB,OAAO,IAAI;IACf;IACA,IAAI;MACA,MAAMc,GAAG,GAAG,MAAMnB,MAAM,CAACI,eAAe,CAACO,IAAI,CAACN,KAAK,CAAC,CAAC;MACrD,MAAMA,KAAK,GAAGc,GAAG,CAACH,QAAQ,CAACb,qBAAqB,CAAC;MACjD,OAAOW,IAAI,CAACM,KAAK,CAACf,KAAK,CAAC;IAC5B,CAAC,CAAC,OAAOgB,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAAC,kCAAkC,EAAEF,EAAE,CAACG,OAAO,CAAC;MAC3D,OAAO,IAAI;IACf;EACJ;AACJ;AAEA,OAAO,MAAMC,qBAAqB,GAAGA,CAAA,KAAM;EACvC,OAAO,IAAIjB,eAAe,CAAC,CAAC;AAChC,CAAC","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import { CompressionPlugin, type ICompressedValue } from "../CompressionPlugin.js";
2
+ export declare class JsonpackCompression extends CompressionPlugin {
3
+ name: string;
4
+ canCompress(data: any): boolean;
5
+ compress(data: any): Promise<ICompressedValue>;
6
+ canDecompress(data: Partial<ICompressedValue>): boolean;
7
+ decompress(data: ICompressedValue): Promise<any>;
8
+ }
9
+ export declare const createJsonpackCompression: () => JsonpackCompression;
@@ -0,0 +1,52 @@
1
+ import { CompressionPlugin } from "../CompressionPlugin.js";
2
+ import { compress, decompress } from "../jsonpack.js";
3
+ const JSONPACK = "jsonpack";
4
+ export class JsonpackCompression extends CompressionPlugin {
5
+ name = "utils.compression.jsonpack";
6
+ canCompress(data) {
7
+ if (typeof data !== "object") {
8
+ return false;
9
+ } else if (!!data.compression) {
10
+ return false;
11
+ }
12
+ // TODO Do we want to compress anything with jsonpack anymore? Maybe not...
13
+ return false;
14
+ }
15
+ async compress(data) {
16
+ if (data === null || data === undefined) {
17
+ return data;
18
+ }
19
+ const value = await compress(data);
20
+ return {
21
+ compression: JSONPACK,
22
+ value
23
+ };
24
+ }
25
+ canDecompress(data) {
26
+ if (typeof data !== "object") {
27
+ return false;
28
+ } else if (!data?.compression) {
29
+ return false;
30
+ }
31
+ const compression = data.compression;
32
+ return compression.toLowerCase() === JSONPACK;
33
+ }
34
+ async decompress(data) {
35
+ if (!data) {
36
+ return data;
37
+ } else if (!data.value) {
38
+ return null;
39
+ }
40
+ try {
41
+ return await decompress(data.value);
42
+ } catch (ex) {
43
+ console.log(`Could not decompress given data.`, ex.message);
44
+ return null;
45
+ }
46
+ }
47
+ }
48
+ export const createJsonpackCompression = () => {
49
+ return new JsonpackCompression();
50
+ };
51
+
52
+ //# sourceMappingURL=JsonpackCompression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CompressionPlugin","compress","decompress","JSONPACK","JsonpackCompression","name","canCompress","data","compression","undefined","value","canDecompress","toLowerCase","ex","console","log","message","createJsonpackCompression"],"sources":["JsonpackCompression.ts"],"sourcesContent":["import { CompressionPlugin, type ICompressedValue } from \"../CompressionPlugin.js\";\nimport { compress, decompress } from \"~/compression/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 return null;\n }\n }\n}\n\nexport const createJsonpackCompression = () => {\n return new JsonpackCompression();\n};\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,QAAQ,EAAEC,UAAU;AAE7B,MAAMC,QAAQ,GAAG,UAAU;AAE3B,OAAO,MAAMC,mBAAmB,SAASJ,iBAAiB,CAAC;EACvCK,IAAI,GAAG,4BAA4B;EAEnCC,WAAWA,CAACC,IAAS,EAAW;IAC5C,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC1B,OAAO,KAAK;IAChB,CAAC,MAAM,IAAI,CAAC,CAACA,IAAI,CAACC,WAAW,EAAE;MAC3B,OAAO,KAAK;IAChB;IACA;IACA,OAAO,KAAK;EAChB;EAEA,MAAsBP,QAAQA,CAACM,IAAS,EAA6B;IACjE,IAAIA,IAAI,KAAK,IAAI,IAAIA,IAAI,KAAKE,SAAS,EAAE;MACrC,OAAOF,IAAI;IACf;IACA,MAAMG,KAAK,GAAG,MAAMT,QAAQ,CAACM,IAAI,CAAC;IAElC,OAAO;MACHC,WAAW,EAAEL,QAAQ;MACrBO;IACJ,CAAC;EACL;EAEgBC,aAAaA,CAACJ,IAA+B,EAAW;IACpE,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC1B,OAAO,KAAK;IAChB,CAAC,MAAM,IAAI,CAACA,IAAI,EAAEC,WAAW,EAAE;MAC3B,OAAO,KAAK;IAChB;IAEA,MAAMA,WAAW,GAAGD,IAAI,CAACC,WAAqB;IAC9C,OAAOA,WAAW,CAACI,WAAW,CAAC,CAAC,KAAKT,QAAQ;EACjD;EAEA,MAAsBD,UAAUA,CAACK,IAAsB,EAAgB;IACnE,IAAI,CAACA,IAAI,EAAE;MACP,OAAOA,IAAI;IACf,CAAC,MAAM,IAAI,CAACA,IAAI,CAACG,KAAK,EAAE;MACpB,OAAO,IAAI;IACf;IACA,IAAI;MACA,OAAO,MAAMR,UAAU,CAACK,IAAI,CAACG,KAAK,CAAC;IACvC,CAAC,CAAC,OAAOG,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAAC,kCAAkC,EAAEF,EAAE,CAACG,OAAO,CAAC;MAC3D,OAAO,IAAI;IACf;EACJ;AACJ;AAEA,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,IAAIb,mBAAmB,CAAC,CAAC;AACpC,CAAC","ignoreList":[]}
@@ -1,11 +1,6 @@
1
- "use strict";
1
+ import { zeroPad } from "./zeroPad.js";
2
+ import { parseIdentifier } from "./parseIdentifier.js";
2
3
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createIdentifier = void 0;
7
- var _zeroPad = require("./zeroPad");
8
- var _parseIdentifier = require("./parseIdentifier");
9
4
  /**
10
5
  * Used to create the identifier that is an absolute unique for the record.
11
6
  * It is created out of the generated ID and version of the record.
@@ -14,12 +9,11 @@ var _parseIdentifier = require("./parseIdentifier");
14
9
  * The input ID is being parsed as you might send a full ID instead of only the generated one.
15
10
  */
16
11
 
17
- const createIdentifier = values => {
12
+ export const createIdentifier = values => {
18
13
  const {
19
14
  id
20
- } = (0, _parseIdentifier.parseIdentifier)(values.id);
21
- return `${id}#${(0, _zeroPad.zeroPad)(values.version)}`;
15
+ } = parseIdentifier(values.id);
16
+ return `${id}#${zeroPad(values.version)}`;
22
17
  };
23
- exports.createIdentifier = createIdentifier;
24
18
 
25
19
  //# sourceMappingURL=createIdentifier.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_zeroPad","require","_parseIdentifier","createIdentifier","values","id","parseIdentifier","zeroPad","version","exports"],"sources":["createIdentifier.ts"],"sourcesContent":["import { zeroPad } from \"~/zeroPad\";\nimport { parseIdentifier } from \"~/parseIdentifier\";\n\n/**\n * Used to create the identifier that is an absolute unique for the record.\n * It is created out of the generated ID and version of the record.\n *\n *\n * The input ID is being parsed as you might send a full ID instead of only the generated one.\n */\nexport interface CreateIdentifierParams {\n id: string;\n version: number;\n}\n\nexport const createIdentifier = (values: CreateIdentifierParams): string => {\n const { id } = parseIdentifier(values.id);\n\n return `${id}#${zeroPad(values.version)}`;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMO,MAAME,gBAAgB,GAAIC,MAA8B,IAAa;EACxE,MAAM;IAAEC;EAAG,CAAC,GAAG,IAAAC,gCAAe,EAACF,MAAM,CAACC,EAAE,CAAC;EAEzC,OAAQ,GAAEA,EAAG,IAAG,IAAAE,gBAAO,EAACH,MAAM,CAACI,OAAO,CAAE,EAAC;AAC7C,CAAC;AAACC,OAAA,CAAAN,gBAAA,GAAAA,gBAAA","ignoreList":[]}
1
+ {"version":3,"names":["zeroPad","parseIdentifier","createIdentifier","values","id","version"],"sources":["createIdentifier.ts"],"sourcesContent":["import { zeroPad } from \"./zeroPad.js\";\nimport { parseIdentifier } from \"./parseIdentifier.js\";\n\n/**\n * Used to create the identifier that is an absolute unique for the record.\n * It is created out of the generated ID and version of the record.\n *\n *\n * The input ID is being parsed as you might send a full ID instead of only the generated one.\n */\nexport interface CreateIdentifierParams {\n id: string;\n version: number;\n}\n\nexport const createIdentifier = (values: CreateIdentifierParams): string => {\n const { id } = parseIdentifier(values.id);\n\n return `${id}#${zeroPad(values.version)}`;\n};\n"],"mappings":"AAAA,SAASA,OAAO;AAChB,SAASC,eAAe;;AAExB;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,OAAO,MAAMC,gBAAgB,GAAIC,MAA8B,IAAa;EACxE,MAAM;IAAEC;EAAG,CAAC,GAAGH,eAAe,CAACE,MAAM,CAACC,EAAE,CAAC;EAEzC,OAAO,GAAGA,EAAE,IAAIJ,OAAO,CAACG,MAAM,CAACE,OAAO,CAAC,EAAE;AAC7C,CAAC","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import WebinyError from "@webiny/error";
2
- import { ZodError } from "zod/lib/ZodError";
2
+ import type { ZodError } from "zod";
3
3
  interface OutputError {
4
4
  code: string;
5
5
  data: Record<string, any> | null;
package/createZodError.js CHANGED
@@ -1,19 +1,14 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createZodError = void 0;
8
- var _error = _interopRequireDefault(require("@webiny/error"));
1
+ import WebinyError from "@webiny/error";
2
+ import { generateAlphaNumericId } from "./generateId.js";
9
3
  const createValidationErrorData = error => {
10
4
  return {
11
5
  invalidFields: error.issues.reduce((collection, issue) => {
12
6
  const name = issue.path.join(".");
13
- if (!name) {
7
+ if (!name && !issue.code) {
14
8
  return collection;
15
9
  }
16
- collection[name] = {
10
+ const key = name || issue.path.join(".") || issue.message || issue.code || generateAlphaNumericId();
11
+ collection[key] = {
17
12
  code: issue.code,
18
13
  message: issue.message,
19
14
  data: {
@@ -25,13 +20,12 @@ const createValidationErrorData = error => {
25
20
  }, {})
26
21
  };
27
22
  };
28
- const createZodError = error => {
29
- return new _error.default({
23
+ export const createZodError = error => {
24
+ return new WebinyError({
30
25
  message: `Validation failed.`,
31
26
  code: "VALIDATION_FAILED_INVALID_FIELDS",
32
27
  data: createValidationErrorData(error)
33
28
  });
34
29
  };
35
- exports.createZodError = createZodError;
36
30
 
37
31
  //# sourceMappingURL=createZodError.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_error","_interopRequireDefault","require","createValidationErrorData","error","invalidFields","issues","reduce","collection","issue","name","path","join","code","message","data","fatal","createZodError","WebinyError","exports"],"sources":["createZodError.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ZodError } from \"zod/lib/ZodError\";\n\ninterface OutputError {\n code: string;\n data: Record<string, any> | null;\n message: string;\n}\n\nexport interface OutputErrors {\n [key: string]: OutputError;\n}\n\nconst createValidationErrorData = (error: ZodError) => {\n return {\n invalidFields: error.issues.reduce<OutputErrors>((collection, issue) => {\n const name = issue.path.join(\".\");\n if (!name) {\n return collection;\n }\n collection[name] = {\n code: issue.code,\n message: issue.message,\n data: {\n fatal: issue.fatal,\n path: issue.path\n }\n };\n\n return collection;\n }, {})\n };\n};\n\nexport const createZodError = (error: ZodError) => {\n return new WebinyError({\n message: `Validation failed.`,\n code: \"VALIDATION_FAILED_INVALID_FIELDS\",\n data: createValidationErrorData(error)\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAaA,MAAMC,yBAAyB,GAAIC,KAAe,IAAK;EACnD,OAAO;IACHC,aAAa,EAAED,KAAK,CAACE,MAAM,CAACC,MAAM,CAAe,CAACC,UAAU,EAAEC,KAAK,KAAK;MACpE,MAAMC,IAAI,GAAGD,KAAK,CAACE,IAAI,CAACC,IAAI,CAAC,GAAG,CAAC;MACjC,IAAI,CAACF,IAAI,EAAE;QACP,OAAOF,UAAU;MACrB;MACAA,UAAU,CAACE,IAAI,CAAC,GAAG;QACfG,IAAI,EAAEJ,KAAK,CAACI,IAAI;QAChBC,OAAO,EAAEL,KAAK,CAACK,OAAO;QACtBC,IAAI,EAAE;UACFC,KAAK,EAAEP,KAAK,CAACO,KAAK;UAClBL,IAAI,EAAEF,KAAK,CAACE;QAChB;MACJ,CAAC;MAED,OAAOH,UAAU;IACrB,CAAC,EAAE,CAAC,CAAC;EACT,CAAC;AACL,CAAC;AAEM,MAAMS,cAAc,GAAIb,KAAe,IAAK;EAC/C,OAAO,IAAIc,cAAW,CAAC;IACnBJ,OAAO,EAAG,oBAAmB;IAC7BD,IAAI,EAAE,kCAAkC;IACxCE,IAAI,EAAEZ,yBAAyB,CAACC,KAAK;EACzC,CAAC,CAAC;AACN,CAAC;AAACe,OAAA,CAAAF,cAAA,GAAAA,cAAA","ignoreList":[]}
1
+ {"version":3,"names":["WebinyError","generateAlphaNumericId","createValidationErrorData","error","invalidFields","issues","reduce","collection","issue","name","path","join","code","key","message","data","fatal","createZodError"],"sources":["createZodError.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { ZodError } from \"zod\";\nimport { generateAlphaNumericId } from \"~/generateId.js\";\n\ninterface OutputError {\n code: string;\n data: Record<string, any> | null;\n message: string;\n}\n\nexport interface OutputErrors {\n [key: string]: OutputError;\n}\n\nconst createValidationErrorData = (error: ZodError) => {\n return {\n invalidFields: error.issues.reduce<OutputErrors>((collection, issue) => {\n const name = issue.path.join(\".\");\n if (!name && !issue.code) {\n return collection;\n }\n\n const key =\n name ||\n issue.path.join(\".\") ||\n issue.message ||\n issue.code ||\n generateAlphaNumericId();\n collection[key] = {\n code: issue.code,\n message: issue.message,\n data: {\n fatal: issue.fatal,\n path: issue.path\n }\n };\n\n return collection;\n }, {})\n };\n};\n\nexport const createZodError = (error: ZodError) => {\n return new WebinyError({\n message: `Validation failed.`,\n code: \"VALIDATION_FAILED_INVALID_FIELDS\",\n data: createValidationErrorData(error)\n });\n};\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAEvC,SAASC,sBAAsB;AAY/B,MAAMC,yBAAyB,GAAIC,KAAe,IAAK;EACnD,OAAO;IACHC,aAAa,EAAED,KAAK,CAACE,MAAM,CAACC,MAAM,CAAe,CAACC,UAAU,EAAEC,KAAK,KAAK;MACpE,MAAMC,IAAI,GAAGD,KAAK,CAACE,IAAI,CAACC,IAAI,CAAC,GAAG,CAAC;MACjC,IAAI,CAACF,IAAI,IAAI,CAACD,KAAK,CAACI,IAAI,EAAE;QACtB,OAAOL,UAAU;MACrB;MAEA,MAAMM,GAAG,GACLJ,IAAI,IACJD,KAAK,CAACE,IAAI,CAACC,IAAI,CAAC,GAAG,CAAC,IACpBH,KAAK,CAACM,OAAO,IACbN,KAAK,CAACI,IAAI,IACVX,sBAAsB,CAAC,CAAC;MAC5BM,UAAU,CAACM,GAAG,CAAC,GAAG;QACdD,IAAI,EAAEJ,KAAK,CAACI,IAAI;QAChBE,OAAO,EAAEN,KAAK,CAACM,OAAO;QACtBC,IAAI,EAAE;UACFC,KAAK,EAAER,KAAK,CAACQ,KAAK;UAClBN,IAAI,EAAEF,KAAK,CAACE;QAChB;MACJ,CAAC;MAED,OAAOH,UAAU;IACrB,CAAC,EAAE,CAAC,CAAC;EACT,CAAC;AACL,CAAC;AAED,OAAO,MAAMU,cAAc,GAAId,KAAe,IAAK;EAC/C,OAAO,IAAIH,WAAW,CAAC;IACnBc,OAAO,EAAE,oBAAoB;IAC7BF,IAAI,EAAE,kCAAkC;IACxCG,IAAI,EAAEb,yBAAyB,CAACC,KAAK;EACzC,CAAC,CAAC;AACN,CAAC","ignoreList":[]}