@webpieces/core-util 0.2.16 → 0.2.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/core-util",
3
- "version": "0.2.16",
3
+ "version": "0.2.21",
4
4
  "description": "Utility functions for WebPieces - works in browser and Node.js",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Header - Interface for HTTP header definitions.
3
+ *
4
+ * This interface is defined in core-util (lowest level package) to avoid
5
+ * circular dependencies. core-context depends on this interface, while
6
+ * http-api's PlatformHeader implements it.
7
+ *
8
+ * Dependency hierarchy:
9
+ * - core-util (defines Header interface)
10
+ * - core-context (uses Header interface)
11
+ * - http-api (PlatformHeader implements Header)
12
+ *
13
+ * This allows RequestContext to work with headers without depending on
14
+ * higher-level packages like http-api.
15
+ */
16
+ export interface Header {
17
+ /**
18
+ * Get the HTTP header name (e.g., 'x-request-id', 'Authorization').
19
+ * Also used as the key in RequestContext storage.
20
+ */
21
+ getHeaderName(): string;
22
+ }
package/src/Header.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Header.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Header.js","sourceRoot":"","sources":["../../../../../packages/core/core-util/src/Header.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Header - Interface for HTTP header definitions.\n *\n * This interface is defined in core-util (lowest level package) to avoid\n * circular dependencies. core-context depends on this interface, while\n * http-api's PlatformHeader implements it.\n *\n * Dependency hierarchy:\n * - core-util (defines Header interface)\n * - core-context (uses Header interface)\n * - http-api (PlatformHeader implements Header)\n *\n * This allows RequestContext to work with headers without depending on\n * higher-level packages like http-api.\n */\nexport interface Header {\n /**\n * Get the HTTP header name (e.g., 'x-request-id', 'Authorization').\n * Also used as the key in RequestContext storage.\n */\n getHeaderName(): string;\n}\n"]}
package/src/index.d.ts CHANGED
@@ -7,3 +7,4 @@
7
7
  * @packageDocumentation
8
8
  */
9
9
  export { toError } from './lib/errorUtils';
10
+ export { Header } from './Header';
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-util/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,+CAA2C;AAAlC,qGAAA,OAAO,OAAA","sourcesContent":["/**\n * @webpieces/core-util\n *\n * Utility functions for WebPieces applications.\n * This package works in both browser and Node.js environments.\n *\n * @packageDocumentation\n */\n\nexport { toError } from './lib/errorUtils';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/core-util/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,+CAA2C;AAAlC,qGAAA,OAAO,OAAA","sourcesContent":["/**\n * @webpieces/core-util\n *\n * Utility functions for WebPieces applications.\n * This package works in both browser and Node.js environments.\n *\n * @packageDocumentation\n */\n\nexport { toError } from './lib/errorUtils';\nexport { Header } from './Header';\n"]}
@@ -87,14 +87,16 @@ function toError(err) {
87
87
  return error;
88
88
  }
89
89
  // For objects without message, try to stringify
90
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- toError utility must handle circular references without recursion
90
91
  try {
91
92
  const message = JSON.stringify(err);
92
93
  return new Error(`Non-Error object thrown: ${message}`);
93
94
  }
94
95
  catch (err) {
95
- // eslint-disable-next-line @webpieces/catch-error-pattern
96
+ //const error = toError(err);
96
97
  // NOTE: Intentionally not calling toError() here to prevent infinite recursion
97
98
  // in error recovery path. This is the ONLY acceptable exception to the pattern.
99
+ void err; // Mark as intentionally unused
98
100
  return new Error('Non-Error object thrown (unable to stringify)');
99
101
  }
100
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errorUtils.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/lib/errorU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,CAAC,0BAA0B,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Error handling utilities for standardized error processing\n * All catch blocks should use toError() to ensure consistent error handling\n *\n * This pattern is enforced by the @webpieces/eslint-plugin-webpieces rule:\n * `catch-error-pattern`\n */\n\n/**\n * Converts unknown error types to Error instances\n *\n * This function standardizes all caught errors into Error objects, ensuring:\n * - Type safety (always returns Error)\n * - Consistent error structure\n * - Proper stack traces\n * - Integration with monitoring/logging systems\n *\n * **WebPieces Pattern**: All catch blocks must follow this pattern:\n * ```typescript\n * try {\n * riskyOperation();\n * } catch (err: any) {\n * const error = toError(err);\n * // Handle error...\n * }\n * ```\n *\n * Alternative (explicitly ignored errors):\n * ```typescript\n * try {\n * riskyOperation();\n * } catch (err: any) {\n * //const error = toError(err);\n * }\n * ```\n *\n * @param err - Unknown error from catch block (typed as any)\n * @returns Standardized Error instance\n *\n * @example\n * ```typescript\n * // Standard usage\n * try {\n * await riskyOperation();\n * } catch (err: any) {\n * const error = toError(err);\n * console.error('Operation failed:', error.message);\n * throw error;\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Nested catch blocks\n * try {\n * await operation1();\n * } catch (err: any) {\n * const error = toError(err);\n * try {\n * await rollback();\n * } catch (err2: any) {\n * const error2 = toError(err2);\n * console.error('Rollback failed:', error2);\n * }\n * }\n * ```\n */\nexport function toError(err: any): Error {\n // If already an Error instance, return it directly\n if (err instanceof Error) {\n return err;\n }\n\n // If it's an object with a message property, create Error from it\n if (err && typeof err === 'object') {\n if ('message' in err) {\n const error = new Error(String(err.message));\n\n // Preserve stack trace if available\n if ('stack' in err && typeof err.stack === 'string') {\n error.stack = err.stack;\n }\n\n // Preserve error name if available\n if ('name' in err && typeof err.name === 'string') {\n error.name = err.name;\n }\n\n return error;\n }\n\n // For objects without message, try to stringify\n try {\n const message = JSON.stringify(err);\n return new Error(`Non-Error object thrown: ${message}`);\n } catch (err: any) {\n // eslint-disable-next-line @webpieces/catch-error-pattern\n // NOTE: Intentionally not calling toError() here to prevent infinite recursion\n // in error recovery path. This is the ONLY acceptable exception to the pattern.\n return new Error('Non-Error object thrown (unable to stringify)');\n }\n }\n\n // For primitives (string, number, boolean, null, undefined)\n const message = err == null ? 'Null or undefined thrown' : String(err);\n return new Error(message);\n}\n"]}
1
+ {"version":3,"file":"errorUtils.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/lib/errorUtils.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AA6DH,0BAyCC;AApGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,SAAgB,OAAO,CAAC,GAAQ;IAC5B,mDAAmD;IACnD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC;IACf,CAAC;IAED,kEAAkE;IAClE,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACjC,IAAI,SAAS,IAAI,GAAG,EAAE,CAAC;YACnB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;YAE7C,oCAAoC;YACpC,IAAI,OAAO,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAClD,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;YAC5B,CAAC;YAED,mCAAmC;YACnC,IAAI,MAAM,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAChD,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YAC1B,CAAC;YAED,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,gDAAgD;QAChD,mIAAmI;QACnI,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YACpC,OAAO,IAAI,KAAK,CAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,6BAA6B;YAC7B,+EAA+E;YAC/E,gFAAgF;YAChF,KAAK,GAAG,CAAC,CAAC,+BAA+B;YACzC,OAAO,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACtE,CAAC;IACL,CAAC;IAED,4DAA4D;IAC5D,MAAM,OAAO,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * Error handling utilities for standardized error processing\n * All catch blocks should use toError() to ensure consistent error handling\n *\n * This pattern is enforced by the @webpieces/eslint-plugin-webpieces rule:\n * `catch-error-pattern`\n */\n\n/**\n * Converts unknown error types to Error instances\n *\n * This function standardizes all caught errors into Error objects, ensuring:\n * - Type safety (always returns Error)\n * - Consistent error structure\n * - Proper stack traces\n * - Integration with monitoring/logging systems\n *\n * **WebPieces Pattern**: All catch blocks must follow this pattern:\n * ```typescript\n * try {\n * riskyOperation();\n * } catch (err: any) {\n * const error = toError(err);\n * // Handle error...\n * }\n * ```\n *\n * Alternative (explicitly ignored errors):\n * ```typescript\n * try {\n * riskyOperation();\n * } catch (err: any) {\n * //const error = toError(err);\n * }\n * ```\n *\n * @param err - Unknown error from catch block (typed as any)\n * @returns Standardized Error instance\n *\n * @example\n * ```typescript\n * // Standard usage\n * try {\n * await riskyOperation();\n * } catch (err: any) {\n * const error = toError(err);\n * console.error('Operation failed:', error.message);\n * throw error;\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Nested catch blocks\n * try {\n * await operation1();\n * } catch (err: any) {\n * const error = toError(err);\n * try {\n * await rollback();\n * } catch (err2: any) {\n * const error2 = toError(err2);\n * console.error('Rollback failed:', error2);\n * }\n * }\n * ```\n */\nexport function toError(err: any): Error {\n // If already an Error instance, return it directly\n if (err instanceof Error) {\n return err;\n }\n\n // If it's an object with a message property, create Error from it\n if (err && typeof err === 'object') {\n if ('message' in err) {\n const error = new Error(String(err.message));\n\n // Preserve stack trace if available\n if ('stack' in err && typeof err.stack === 'string') {\n error.stack = err.stack;\n }\n\n // Preserve error name if available\n if ('name' in err && typeof err.name === 'string') {\n error.name = err.name;\n }\n\n return error;\n }\n\n // For objects without message, try to stringify\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- toError utility must handle circular references without recursion\n try {\n const message = JSON.stringify(err);\n return new Error(`Non-Error object thrown: ${message}`);\n } catch (err: any) {\n //const error = toError(err);\n // NOTE: Intentionally not calling toError() here to prevent infinite recursion\n // in error recovery path. This is the ONLY acceptable exception to the pattern.\n void err; // Mark as intentionally unused\n return new Error('Non-Error object thrown (unable to stringify)');\n }\n }\n\n // For primitives (string, number, boolean, null, undefined)\n const message = err == null ? 'Null or undefined thrown' : String(err);\n return new Error(message);\n}\n"]}