@baklavabg/common-ts 1.0.18 → 1.0.19

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 CHANGED
@@ -2,7 +2,6 @@ export * from "./safeExit/index.js";
2
2
  export * from "./utils/index.js";
3
3
  export type { User1, User2 } from "./types/index.js";
4
4
  export { formatUserName } from "./utils/user.utils.js";
5
- export { tryCatch } from "./utils/tryCatchDecorator.js";
6
5
  export { TryCatch } from "./utils/tryCatchSafeDecorator.js";
7
6
  export { equals, greaterThan, isEmpty, isEven, isNegative, isNotEmpty, isNull, isNullOrUndefined, isOdd, isPositive, isUndefined, isZero, lessThan, notEquals, } from "./safeExit/conditionHelpers.js";
8
7
  export { createFolder } from "./utils/file.utils.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACH,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,UAAU,EACV,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,KAAK,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,GACZ,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACH,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,UAAU,EACV,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,KAAK,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,GACZ,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from "./safeExit/index.js";
2
2
  export * from "./utils/index.js";
3
3
  export { formatUserName } from "./utils/user.utils.js";
4
- export { tryCatch } from "./utils/tryCatchDecorator.js";
5
4
  export { TryCatch } from "./utils/tryCatchSafeDecorator.js";
6
5
  export { equals, greaterThan, isEmpty, isEven, isNegative, isNotEmpty, isNull, isNullOrUndefined, isOdd, isPositive, isUndefined, isZero, lessThan, notEquals, } from "./safeExit/conditionHelpers.js";
7
6
  export { createFolder } from "./utils/file.utils.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACH,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,UAAU,EACV,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,KAAK,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,GACZ,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACH,MAAM,EACN,WAAW,EACX,OAAO,EACP,MAAM,EACN,UAAU,EACV,UAAU,EACV,MAAM,EACN,iBAAiB,EACjB,KAAK,EACL,UAAU,EACV,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,GACZ,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
@@ -51,7 +51,7 @@ export function exitIf(condition, logMessage, returnValue) {
51
51
  const shouldReturn = typeof condition === "boolean" ? condition : condition();
52
52
  if (shouldReturn) {
53
53
  if (logMessage) {
54
- print.yellow(logMessage);
54
+ print.red(logMessage);
55
55
  }
56
56
  throw new EarlyReturnError(returnValue ?? null, logMessage);
57
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"reurnIf.js","sourceRoot":"","sources":["../../src/safeExit/reurnIf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,SAAoC,EAAE,UAAmB,EAAE,WAAiB;IACjG,MAAM,YAAY,GAAG,OAAO,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAE9E,IAAI,YAAY,EAAE,CAAC;QACf,IAAI,UAAU,E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AC,CAAC;IAC1E,CAAC;IAED,OAAO,IAAI,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare function TryCatch<C = undefined>(printError?: boolean, printStack?: boolean, customReturn?: C): (_: any, __: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
1
+ export declare function TryCatch<C = undefined>(printError?: boolean, printStack?: boolean, customReturn?: C): (originalMethod: (...args: any[]) => any, _context: ClassMethodDecoratorContext) => any;
2
2
  //# sourceMappingURL=tryCatchSafeDecorator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tryCatchSafeDecorator.d.ts","sourceRoot":"","sources":["../../src/utils/tryCatchSafeDecorator.ts"],"names":[],"mappings":"AAgCA,wBAAgB,QAAQ,CAAC,CAAC,GAAG,SAAS,EAAE,UAAU,GAAE,OAAc,EAAE,UAAU,GAAE,OAAc,EAAE,YAAY,CAAC,EAAE,CAAC,IAC3F,GAAG,GAAG,EAAE,IAAI,MAAM,EAAE,YAAY,kBAAkB,wBAItE"}
1
+ {"version":3,"file":"tryCatchSafeDecorator.d.ts","sourceRoot":"","sources":["../../src/utils/tryCatchSafeDecorator.ts"],"names":[],"mappings":"AAgCA,wBAAgB,QAAQ,CAAC,CAAC,GAAG,SAAS,EAAE,UAAU,GAAE,OAAc,EAAE,UAAU,GAAE,OAAc,EAAE,YAAY,CAAC,EAAE,CAAC,IAC3F,gBAAgB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,2BAA2B,KACf,GAAG,CAEtF"}
@@ -30,9 +30,8 @@
30
30
  import { safe } from "../safeExit/safe.js";
31
31
  //@mii to move to safeExit folder
32
32
  export function TryCatch(printError = true, printStack = true, customReturn) {
33
- return function (_, __, descriptor) {
34
- descriptor.value = safe(descriptor.value, printError, printStack, customReturn);
35
- return descriptor;
33
+ return function (originalMethod, _context) {
34
+ return safe(originalMethod, printError, printStack, customReturn);
36
35
  };
37
36
  }
38
37
  //# sourceMappingURL=tryCatchSafeDecorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tryCatchSafeDecorator.js","sourceRoot":"","sources":["../../src/utils/tryCatchSafeDecorator.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,sFAAsF;AACtF,6FAA6F;AAC7F,kGAAkG;AAClG,EAAE;AACF,iBAAiB;AACjB,sDAAsD;AACtD,EAAE;AACF,kBAAkB;AAClB,wGAAwG;AACxG,4CAA4C;AAC5C,oBAAoB;AACpB,wCAAwC;AACxC,MAAM;AACN,EAAE;AACF,6FAA6F;AAC7F,2BAA2B;AAC3B,2BAA2B;AAC3B,wCAAwC;AACxC,MAAM;AACN,IAAI;AACJ,EAAE;AACF,sBAAsB;AACtB,iEAAiE;AACjE,kEAAkE;AAClE,2EAA2E;AAC3E,EAAE;AACF,8DAA8D;AAC9D,4CAA4C;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,iCAAiC;AACjC,MAAM,UAAU,QAAQ,CAAgB,aAAsB,IAAI,EAAE,aAAsB,IAAI,EAAE,YAAgB;IAC5G,OAAO,UAAU,CAAM,EAAE,EAAU,EAAE,UAA8B;QAC/D,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,YAAmB,CAAC,CAAC;QACvF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"tryCatchSafeDecorator.js","sourceRoot":"","sources":["../../src/utils/tryCatchSafeDecorator.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,sFAAsF;AACtF,6FAA6F;AAC7F,kGAAkG;AAClG,EAAE;AACF,iBAAiB;AACjB,sDAAsD;AACtD,EAAE;AACF,kBAAkB;AAClB,wGAAwG;AACxG,4CAA4C;AAC5C,oBAAoB;AACpB,wCAAwC;AACxC,MAAM;AACN,EAAE;AACF,6FAA6F;AAC7F,2BAA2B;AAC3B,2BAA2B;AAC3B,wCAAwC;AACxC,MAAM;AACN,IAAI;AACJ,EAAE;AACF,sBAAsB;AACtB,iEAAiE;AACjE,kEAAkE;AAClE,2EAA2E;AAC3E,EAAE;AACF,8DAA8D;AAC9D,4CAA4C;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,iCAAiC;AACjC,MAAM,UAAU,QAAQ,CAAgB,aAAsB,IAAI,EAAE,aAAsB,IAAI,EAAE,YAAgB;IAC5G,OAAO,UAAU,cAAuC,EAAE,QAAqC;QAC3F,OAAO,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,YAAmB,CAAQ,CAAC;IACpF,CAAC,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baklavabg/common-ts",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "type": "module",
5
5
  "description": "A comprehensive TypeScript library with common utility functions and custom types",
6
6
  "main": "./dist/index.js",
@@ -1,27 +0,0 @@
1
- /**
2
- * This try/catch decorator automatically wraps your methods in try-catch blocks so you don't have to!
3
- * Works with both sync and async functions automatically!
4
- * Works only on methods, not on class constructors, static methods or standalone functions.
5
- *
6
- * Basic Usage (just catch errors and return null):
7
- * @tryCatch()
8
- * getUserData(id: string) { ... }
9
- *
10
- * Return something else when errors happen:
11
- * @tryCatch({ returnVal: [] })
12
- *
13
- * Custom error handling:
14
- * @tryCatch({ cbk: (error) => ({ success: false, error: error.message }) })
15
- *
16
- * Async function with async custom handler
17
- @tryCatch({
18
- cbk: async (_) => {
19
- await new Promise((resolve) => setTimeout(resolve, 50))
20
- return []
21
- },
22
- })
23
- async getAllUsersAsync() { }
24
- */
25
- import type { TryCatchOptions } from "../types/index.js";
26
- export declare function tryCatch(options?: TryCatchOptions): (target: any, propertyName: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
27
- //# sourceMappingURL=tryCatchDecorator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tryCatchDecorator.d.ts","sourceRoot":"","sources":["../../src/utils/tryCatchDecorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIzD,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,IACjC,QAAQ,GAAG,EAAE,cAAc,MAAM,EAAE,YAAY,kBAAkB,wBAwCrF"}
@@ -1,64 +0,0 @@
1
- /**
2
- * This try/catch decorator automatically wraps your methods in try-catch blocks so you don't have to!
3
- * Works with both sync and async functions automatically!
4
- * Works only on methods, not on class constructors, static methods or standalone functions.
5
- *
6
- * Basic Usage (just catch errors and return null):
7
- * @tryCatch()
8
- * getUserData(id: string) { ... }
9
- *
10
- * Return something else when errors happen:
11
- * @tryCatch({ returnVal: [] })
12
- *
13
- * Custom error handling:
14
- * @tryCatch({ cbk: (error) => ({ success: false, error: error.message }) })
15
- *
16
- * Async function with async custom handler
17
- @tryCatch({
18
- cbk: async (_) => {
19
- await new Promise((resolve) => setTimeout(resolve, 50))
20
- return []
21
- },
22
- })
23
- async getAllUsersAsync() { }
24
- */
25
- // @mii use TryCatch instead!
26
- // The main decorator factory
27
- export function tryCatch(options = {}) {
28
- return function (target, propertyName, descriptor) {
29
- const originalMethod = descriptor.value;
30
- descriptor.value = async function (...args) {
31
- try {
32
- const result = originalMethod.apply(this, args);
33
- // Handle both synchronous and asynchronous functions
34
- if (result instanceof Promise) {
35
- return await result;
36
- }
37
- return result;
38
- }
39
- catch (error) {
40
- // Log the error unless explicitly disabled
41
- if (options.logError !== false) {
42
- console.error(`❌ Error in ${target.constructor.name}.${propertyName}:`, error.message);
43
- if (options.logStack === true && error.stack) {
44
- console.error(error.stack);
45
- }
46
- }
47
- // Use custom handler if provided
48
- if (options.cbk) {
49
- const handlerResult = options.cbk(error);
50
- // Handle async custom handlers too
51
- return handlerResult instanceof Promise ? await handlerResult : handlerResult;
52
- }
53
- // Rethrow after logging (useful for debugging while still propagating errors)
54
- if (options.rethrow) {
55
- throw error;
56
- }
57
- // Return fallback value or null
58
- return options.returnVal ?? null;
59
- }
60
- };
61
- return descriptor;
62
- };
63
- }
64
- //# sourceMappingURL=tryCatchDecorator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tryCatchDecorator.js","sourceRoot":"","sources":["../../src/utils/tryCatchDecorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAKH,6BAA6B;AAC7B,6BAA6B;AAC7B,MAAM,UAAU,QAAQ,CAAC,UAA2B,EAAE;IAClD,OAAO,UAAU,MAAW,EAAE,YAAoB,EAAE,UAA8B;QAC9E,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAC7C,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAEhD,qDAAqD;gBACrD,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;oBAC5B,OAAO,MAAM,MAAM,CAAC;gBACxB,CAAC;gBACD,OAAO,MAAM,CAAC;YAClB,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBAClB,2CAA2C;gBAC3C,IAAI,OAAO,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;oBAC7B,OAAO,CAAC,KAAK,CAAC,cAAc,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,YAAY,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;oBACvF,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;wBAC3C,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAC/B,CAAC;gBACL,CAAC;gBAED,iCAAiC;gBACjC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;oBACd,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBACzC,mCAAmC;oBACnC,OAAO,aAAa,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC;gBAClF,CAAC;gBAED,8EAA8E;gBAC9E,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;oBAClB,MAAM,KAAK,CAAC;gBAChB,CAAC;gBAED,gCAAgC;gBAChC,OAAO,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;YACrC,CAAC;QACL,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC;AACN,CAAC"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Wraps a function to catch errors and return undefined instead of throwing.
3
- * Optionally logs the error message and stack trace.
4
- *
5
- * function risky() { throw new Error("fail"); }
6
-
7
- * const safeRisky = safe(risky); // prints error and stack
8
- * const silentRisky = safe(risky, false); // no error printed
9
- * const noStackRisky = safe(risky, true, false); // prints error, no stack
10
- */
11
- export declare function safe_del<T extends (...args: any[]) => any, C = null>(fn: T, printError?: boolean, printStack?: boolean, customReturn?: C): (...args: Parameters<T>) => ReturnType<T> | C;
12
- //# sourceMappingURL=tryCatchSafe.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tryCatchSafe.d.ts","sourceRoot":"","sources":["../../src/utils/tryCatchSafe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,GAAG,IAAI,EAChE,EAAE,EAAE,CAAC,EACL,UAAU,GAAE,OAAc,EAC1B,UAAU,GAAE,OAAc,EAC1B,YAAY,GAAE,CAAa,GAC5B,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAoC/C"}
@@ -1,49 +0,0 @@
1
- /**
2
- * Wraps a function to catch errors and return undefined instead of throwing.
3
- * Optionally logs the error message and stack trace.
4
- *
5
- * function risky() { throw new Error("fail"); }
6
-
7
- * const safeRisky = safe(risky); // prints error and stack
8
- * const silentRisky = safe(risky, false); // no error printed
9
- * const noStackRisky = safe(risky, true, false); // prints error, no stack
10
- */
11
- import { print } from "./log.utils.js";
12
- export function safe_del(fn, printError = true, printStack = true, customReturn = null) {
13
- const getFileInfoFromStack = (stackTrace, functionName) => {
14
- const lines = stackTrace.split("\n").map(line => line.trim());
15
- const fnLine = lines.find(line => line.startsWith(`at ${functionName}`)) ||
16
- lines.find(line => /at .*:\d+:\d+/.test(line)) ||
17
- lines[1] ||
18
- "";
19
- const regex = /at (?:\S+ \()?(.+):(\d+):(\d+)\)?$/; // captures the path:line:column after "at "
20
- const match = fnLine.match(regex);
21
- if (match) {
22
- const [, path, line, col] = match;
23
- return `${path}:${line}:${col}`;
24
- }
25
- return "";
26
- };
27
- return (...args) => {
28
- try {
29
- return fn(...args);
30
- }
31
- catch (e) {
32
- if (printError) {
33
- let fileInfo = "";
34
- if (e instanceof Error && e.stack) {
35
- fileInfo = getFileInfoFromStack(e.stack, fn.name);
36
- }
37
- const header = `Exception in ${fn.name}()${fileInfo ? ` at ${fileInfo}` : ""}:`;
38
- if (printStack && e instanceof Error) {
39
- print.red(`${header}\n${e.stack}`);
40
- }
41
- else {
42
- print.red(`${header} ${e}`);
43
- }
44
- }
45
- return customReturn;
46
- }
47
- };
48
- }
49
- //# sourceMappingURL=tryCatchSafe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tryCatchSafe.js","sourceRoot":"","sources":["../../src/utils/tryCatchSafe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,MAAM,UAAU,QAAQ,CACpB,EAAK,EACL,aA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