@cyberskill/shared 3.11.0 → 3.13.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.
@@ -1,5 +1,5 @@
1
1
  import { deepMerge as e } from "../../util/object/object.util.js";
2
- import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.1_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_5f6c16f4d4385f16c87b17afc93c851f/node_modules/vitest/dist/config.js";
2
+ import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.2_@types_node@25.5.0_jsdom@29.0.1_@noble_hashes@1.8.0__vite@8.0.3_@types_nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js";
3
3
  import n from "@vitejs/plugin-react";
4
4
  //#region src/config/vitest/vitest.e2e.ts
5
5
  function r(r) {
@@ -1,5 +1,5 @@
1
1
  import { deepMerge as e } from "../../util/object/object.util.js";
2
- import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.1_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_5f6c16f4d4385f16c87b17afc93c851f/node_modules/vitest/dist/config.js";
2
+ import { defineConfig as t } from "../../node_modules/.pnpm/vitest@4.1.2_@types_node@25.5.0_jsdom@29.0.1_@noble_hashes@1.8.0__vite@8.0.3_@types_nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js";
3
3
  import n from "@vitejs/plugin-react";
4
4
  //#region src/config/vitest/vitest.unit.ts
5
5
  function r(r) {
@@ -0,0 +1,8 @@
1
+ //#region node_modules/.pnpm/vitest@4.1.2_@types+node@25.5.0_jsdom@29.0.1_@noble+hashes@1.8.0__vite@8.0.3_@types+nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js
2
+ function e(e) {
3
+ return e;
4
+ }
5
+ //#endregion
6
+ export { e as defineConfig };
7
+
8
+ //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":[],"sources":["../../../../../../../node_modules/.pnpm/vitest@4.1.0_@types+node@25.5.0_jsdom@29.0.1_@noble+hashes@1.8.0__vite@8.0.1_@types+nod_5f6c16f4d4385f16c87b17afc93c851f/node_modules/vitest/dist/config.js"],"sourcesContent":["export { c as configDefaults, a as coverageConfigDefaults, d as defaultExclude, b as defaultInclude } from './chunks/defaults.CdU2lD-q.js';\nexport { mergeConfig } from 'vite';\nexport { d as defaultBrowserPort } from './chunks/constants.CPYnjOGj.js';\nimport 'node:os';\nimport './chunks/env.D4Lgay0q.js';\nimport 'std-env';\n\nfunction defineConfig(config) {\n\treturn config;\n}\nfunction defineProject(config) {\n\treturn config;\n}\n\nexport { defineConfig, defineProject };\n"],"x_google_ignoreList":[0],"mappings":";AAOA,SAAS,EAAa,GAAQ;AAC7B,QAAO"}
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../../../../../../node_modules/.pnpm/vitest@4.1.2_@types+node@25.5.0_jsdom@29.0.1_@noble+hashes@1.8.0__vite@8.0.3_@types+nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js"],"sourcesContent":["export { c as configDefaults, a as coverageConfigDefaults, d as defaultExclude, b as defaultInclude } from './chunks/defaults.9aQKnqFk.js';\nexport { mergeConfig } from 'vite';\nexport { d as defaultBrowserPort } from './chunks/constants.CPYnjOGj.js';\nimport 'node:os';\nimport './chunks/env.D4Lgay0q.js';\nimport 'std-env';\n\nfunction defineConfig(config) {\n\treturn config;\n}\nfunction defineProject(config) {\n\treturn config;\n}\n\nexport { defineConfig, defineProject };\n"],"x_google_ignoreList":[0],"mappings":";AAOA,SAAS,EAAa,GAAQ;AAC7B,QAAO"}
@@ -27,7 +27,10 @@ function c() {
27
27
  };
28
28
  if (!c) return null;
29
29
  let p = "locations" in c || "path" in c || "extensions" in c, m = "message" in c ? c.message : "Unknown error occurred";
30
- return /* @__PURE__ */ r.createElement("div", { className: n["modal-backdrop"] }, /* @__PURE__ */ r.createElement("div", {
30
+ return /* @__PURE__ */ r.createElement("div", {
31
+ className: n["modal-backdrop"],
32
+ onClick: l
33
+ }, /* @__PURE__ */ r.createElement("div", {
31
34
  ref: u,
32
35
  className: n["modal-content"],
33
36
  role: "dialog",
@@ -35,7 +38,8 @@ function c() {
35
38
  "aria-labelledby": "apollo-error-title",
36
39
  "aria-describedby": "apollo-error-details",
37
40
  tabIndex: -1,
38
- onKeyDown: f
41
+ onKeyDown: f,
42
+ onClick: (e) => e.stopPropagation()
39
43
  }, /* @__PURE__ */ r.createElement("button", {
40
44
  type: "button",
41
45
  className: n["btn-close"],
@@ -1 +1 @@
1
- {"version":3,"file":"apollo-error.component.js","names":[],"sources":["../../../src/react/apollo-error/apollo-error.component.tsx"],"sourcesContent":["import * as React from 'react';\nimport { use, useEffect, useRef } from 'react';\n\nimport { validate } from '#util/validate/validate.util.js';\n\nimport { ApolloErrorContext } from './apollo-error.context.js';\nimport style from './apollo-error.module.scss';\n\nconst FOCUSABLE_SELECTORS = 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Apollo Error Component that displays detailed error information in a modal.\n * This component provides a comprehensive error display interface that shows\n * GraphQL errors and other error types with detailed information for debugging purposes.\n *\n * Features:\n * - Modal overlay with backdrop for focus\n * - Detailed error categorization and display\n * - Reload functionality for error recovery\n * - Close button to dismiss the error modal\n * - Structured display of different error types\n * - Extra information display for debugging\n *\n * @returns A modal component displaying Apollo error details, or null if no error is present.\n */\nexport function ApolloErrorComponent() {\n const context = use(ApolloErrorContext);\n const { error, hideError } = context ?? {};\n const dialogRef = useRef<HTMLDivElement>(null);\n const previousFocusRef = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!error || !hideError)\n return;\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n hideError();\n }\n };\n\n window.addEventListener('keydown', handleKeyDown);\n\n return () => {\n window.removeEventListener('keydown', handleKeyDown);\n };\n }, [error, hideError]);\n\n useEffect(() => {\n if (error && dialogRef.current) {\n previousFocusRef.current = document.activeElement as HTMLElement;\n dialogRef.current.focus();\n }\n else if (!error && previousFocusRef.current) {\n previousFocusRef.current.focus();\n previousFocusRef.current = null;\n }\n }, [error]);\n\n const handleFocusTrap = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== 'Tab' || !dialogRef.current)\n return;\n\n const focusableElements = [...dialogRef.current.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTORS)].filter(el => !el.hasAttribute('disabled'));\n\n if (focusableElements.length === 0)\n return;\n\n const firstElement = focusableElements[0];\n const lastElement = focusableElements.at(-1);\n\n if (!firstElement || !lastElement)\n return;\n\n if (event.shiftKey) {\n if (document.activeElement === firstElement) {\n event.preventDefault();\n lastElement.focus();\n }\n }\n else if (document.activeElement === lastElement) {\n event.preventDefault();\n firstElement.focus();\n }\n };\n\n if (!error) {\n return null;\n }\n\n const isGraphQLError = 'locations' in error || 'path' in error || 'extensions' in error;\n const errorMessage = 'message' in error ? error.message : 'Unknown error occurred';\n\n return (\n <div className={style['modal-backdrop']}>\n <div\n ref={dialogRef}\n className={style['modal-content']}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby=\"apollo-error-title\"\n aria-describedby=\"apollo-error-details\"\n tabIndex={-1}\n onKeyDown={handleFocusTrap}\n >\n <button\n type=\"button\"\n className={style['btn-close']}\n onClick={hideError}\n aria-label=\"Close error details (Esc)\"\n aria-keyshortcuts=\"Escape\"\n title=\"Close error details (Esc)\"\n >\n ✕\n </button>\n <div className={style['error-title']}>\n <button\n type=\"button\"\n className={style['btn-retry']}\n onClick={() => window.location.reload()}\n aria-label=\"Reload page\"\n >\n Reload\n </button>\n {' '}\n <span id=\"apollo-error-title\">\n {errorMessage || 'Error details'}\n </span>\n </div>\n <div id=\"apollo-error-details\" className={style['error-details']}>\n {isGraphQLError && 'locations' in error && error.locations && (\n <pre className=\"locations\">\n <strong>Locations:</strong>\n {' '}\n {JSON.stringify(error.locations, null, 4)}\n </pre>\n )}\n {isGraphQLError && 'path' in error && error.path && (\n <pre className=\"path\">\n <strong>Path:</strong>\n {' '}\n {JSON.stringify(error.path, null, 4)}\n </pre>\n )}\n {isGraphQLError && 'extensions' in error && error.extensions && (\n <pre className=\"extensions\">\n <strong>Extensions:</strong>\n {' '}\n {JSON.stringify(error.extensions, null, 4)}\n </pre>\n )}\n {!isGraphQLError && (\n <pre className=\"error-details\">\n <strong>Error Details:</strong>\n {' '}\n {validate.isEmpty(error) ? errorMessage : JSON.stringify(error, null, 4)}\n </pre>\n )}\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;AAQA,IAAM,IAAsB;AAiB5B,SAAgB,IAAuB;CAEnC,IAAM,EAAE,UAAO,iBADC,EAAI,EAAmB,IACC,EAAE,EACpC,IAAY,EAAuB,KAAK,EACxC,IAAmB,EAA2B,KAAK;AAmBzD,CAjBA,QAAgB;AACZ,MAAI,CAAC,KAAS,CAAC,EACX;EAEJ,IAAM,KAAiB,MAAyB;AAC5C,GAAI,EAAM,QAAQ,YACd,GAAW;;AAMnB,SAFA,OAAO,iBAAiB,WAAW,EAAc,QAEpC;AACT,UAAO,oBAAoB,WAAW,EAAc;;IAEzD,CAAC,GAAO,EAAU,CAAC,EAEtB,QAAgB;AACZ,EAAI,KAAS,EAAU,WACnB,EAAiB,UAAU,SAAS,eACpC,EAAU,QAAQ,OAAO,IAEpB,CAAC,KAAS,EAAiB,YAChC,EAAiB,QAAQ,OAAO,EAChC,EAAiB,UAAU;IAEhC,CAAC,EAAM,CAAC;CAEX,IAAM,KAAmB,MAA+C;AACpE,MAAI,EAAM,QAAQ,SAAS,CAAC,EAAU,QAClC;EAEJ,IAAM,IAAoB,CAAC,GAAG,EAAU,QAAQ,iBAA8B,EAAoB,CAAC,CAAC,QAAO,MAAM,CAAC,EAAG,aAAa,WAAW,CAAC;AAE9I,MAAI,EAAkB,WAAW,EAC7B;EAEJ,IAAM,IAAe,EAAkB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AM,MAAM,MAAM,EAAE,CAClC,EAET,KAAkB,gBAAgB,KAAS,EAAM,cAC9C,kBAAA,cAAC,OAAD,EAAK,WAAU,cAIT,EAHF,kBAAA,cAAC,UAAA,MAAO,cAAoB,EAC3B,KACA,KAAK,UAAU,EAAM,YAAY,MAAM,EAAE,CACxC,EAET,CAAC,KACE,kBAAA,cAAC,OAAD,EAAK,WAAU,iBAIT,EAHF,kBAAA,cAAC,UAAA,MAAO,iBAAuB,EAC9B,KACA,EAAS,QAAQ,EAAM,GAAG,IAAe,KAAK,UAAU,GAAO,MAAM,EAAE,CACtE,CAER,CACJ,CACJ"}
1
+ {"version":3,"file":"apollo-error.component.js","names":[],"sources":["../../../src/react/apollo-error/apollo-error.component.tsx"],"sourcesContent":["import * as React from 'react';\nimport { use, useEffect, useRef } from 'react';\n\nimport { validate } from '#util/validate/validate.util.js';\n\nimport { ApolloErrorContext } from './apollo-error.context.js';\nimport style from './apollo-error.module.scss';\n\nconst FOCUSABLE_SELECTORS = 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Apollo Error Component that displays detailed error information in a modal.\n * This component provides a comprehensive error display interface that shows\n * GraphQL errors and other error types with detailed information for debugging purposes.\n *\n * Features:\n * - Modal overlay with backdrop for focus\n * - Detailed error categorization and display\n * - Reload functionality for error recovery\n * - Close button to dismiss the error modal\n * - Structured display of different error types\n * - Extra information display for debugging\n *\n * @returns A modal component displaying Apollo error details, or null if no error is present.\n */\nexport function ApolloErrorComponent() {\n const context = use(ApolloErrorContext);\n const { error, hideError } = context ?? {};\n const dialogRef = useRef<HTMLDivElement>(null);\n const previousFocusRef = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n if (!error || !hideError)\n return;\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n hideError();\n }\n };\n\n window.addEventListener('keydown', handleKeyDown);\n\n return () => {\n window.removeEventListener('keydown', handleKeyDown);\n };\n }, [error, hideError]);\n\n useEffect(() => {\n if (error && dialogRef.current) {\n previousFocusRef.current = document.activeElement as HTMLElement;\n dialogRef.current.focus();\n }\n else if (!error && previousFocusRef.current) {\n previousFocusRef.current.focus();\n previousFocusRef.current = null;\n }\n }, [error]);\n\n const handleFocusTrap = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.key !== 'Tab' || !dialogRef.current)\n return;\n\n const focusableElements = [...dialogRef.current.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTORS)].filter(el => !el.hasAttribute('disabled'));\n\n if (focusableElements.length === 0)\n return;\n\n const firstElement = focusableElements[0];\n const lastElement = focusableElements.at(-1);\n\n if (!firstElement || !lastElement)\n return;\n\n if (event.shiftKey) {\n if (document.activeElement === firstElement) {\n event.preventDefault();\n lastElement.focus();\n }\n }\n else if (document.activeElement === lastElement) {\n event.preventDefault();\n firstElement.focus();\n }\n };\n\n if (!error) {\n return null;\n }\n\n const isGraphQLError = 'locations' in error || 'path' in error || 'extensions' in error;\n const errorMessage = 'message' in error ? error.message : 'Unknown error occurred';\n\n return (\n <div className={style['modal-backdrop']} onClick={hideError}>\n <div\n ref={dialogRef}\n className={style['modal-content']}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-labelledby=\"apollo-error-title\"\n aria-describedby=\"apollo-error-details\"\n tabIndex={-1}\n onKeyDown={handleFocusTrap}\n onClick={e => e.stopPropagation()}\n >\n <button\n type=\"button\"\n className={style['btn-close']}\n onClick={hideError}\n aria-label=\"Close error details (Esc)\"\n aria-keyshortcuts=\"Escape\"\n title=\"Close error details (Esc)\"\n >\n ✕\n </button>\n <div className={style['error-title']}>\n <button\n type=\"button\"\n className={style['btn-retry']}\n onClick={() => window.location.reload()}\n aria-label=\"Reload page\"\n >\n Reload\n </button>\n {' '}\n <span id=\"apollo-error-title\">\n {errorMessage || 'Error details'}\n </span>\n </div>\n <div id=\"apollo-error-details\" className={style['error-details']}>\n {isGraphQLError && 'locations' in error && error.locations && (\n <pre className=\"locations\">\n <strong>Locations:</strong>\n {' '}\n {JSON.stringify(error.locations, null, 4)}\n </pre>\n )}\n {isGraphQLError && 'path' in error && error.path && (\n <pre className=\"path\">\n <strong>Path:</strong>\n {' '}\n {JSON.stringify(error.path, null, 4)}\n </pre>\n )}\n {isGraphQLError && 'extensions' in error && error.extensions && (\n <pre className=\"extensions\">\n <strong>Extensions:</strong>\n {' '}\n {JSON.stringify(error.extensions, null, 4)}\n </pre>\n )}\n {!isGraphQLError && (\n <pre className=\"error-details\">\n <strong>Error Details:</strong>\n {' '}\n {validate.isEmpty(error) ? errorMessage : JSON.stringify(error, null, 4)}\n </pre>\n )}\n </div>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;AAQA,IAAM,IAAsB;AAiB5B,SAAgB,IAAuB;CAEnC,IAAM,EAAE,UAAO,iBADC,EAAI,EAAmB,IACC,EAAE,EACpC,IAAY,EAAuB,KAAK,EACxC,IAAmB,EAA2B,KAAK;AAmBzD,CAjBA,QAAgB;AACZ,MAAI,CAAC,KAAS,CAAC,EACX;EAEJ,IAAM,KAAiB,MAAyB;AAC5C,GAAI,EAAM,QAAQ,YACd,GAAW;;AAMnB,SAFA,OAAO,iBAAiB,WAAW,EAAc,QAEpC;AACT,UAAO,oBAAoB,WAAW,EAAc;;IAEzD,CAAC,GAAO,EAAU,CAAC,EAEtB,QAAgB;AACZ,EAAI,KAAS,EAAU,WACnB,EAAiB,UAAU,SAAS,eACpC,EAAU,QAAQ,OAAO,IAEpB,CAAC,KAAS,EAAiB,YAChC,EAAiB,QAAQ,OAAO,EAChC,EAAiB,UAAU;IAEhC,CAAC,EAAM,CAAC;CAEX,IAAM,KAAmB,MAA+C;AACpE,MAAI,EAAM,QAAQ,SAAS,CAAC,EAAU,QAClC;EAEJ,IAAM,IAAoB,CAAC,GAAG,EAAU,QAAQ,iBAA8B,EAAoB,CAAC,CAAC,QAAO,MAAM,CAAC,EAAG,aAAa,WAAW,CAAC;AAE9I,MAAI,EAAkB,WAAW,EAC7B;EAEJ,IAAM,IAA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AA,cAAC,UAAA,MAAO,QAAc,EACrB,KACA,KAAK,UAAU,EAAM,MAAM,MAAM,EAAE,CAClC,EAET,KAAkB,gBAAgB,KAAS,EAAM,cAC9C,kBAAA,cAAC,OAAD,EAAK,WAAU,cAIT,EAHF,kBAAA,cAAC,UAAA,MAAO,cAAoB,EAC3B,KACA,KAAK,UAAU,EAAM,YAAY,MAAM,EAAE,CACxC,EAET,CAAC,KACE,kBAAA,cAAC,OAAD,EAAK,WAAU,iBAIT,EAHF,kBAAA,cAAC,UAAA,MAAO,iBAAuB,EAC9B,KACA,EAAS,QAAQ,EAAM,GAAG,IAAe,KAAK,UAAU,GAAO,MAAM,EAAE,CACtE,CAER,CACJ,CACJ"}
@@ -33,21 +33,23 @@ function r(e, t, r) {
33
33
  return t.length === 0 ? e : n(e, t, r, 0);
34
34
  }
35
35
  function i(e) {
36
- return a(e, /* @__PURE__ */ new WeakSet());
36
+ return a(e, /* @__PURE__ */ new WeakMap());
37
37
  }
38
38
  function a(e, t) {
39
39
  if (typeof e != "object" || !e) return e;
40
- if (t.has(e)) throw Error("deepClone: Circular reference detected.");
41
- if (t.add(e), e instanceof Date) return new Date(e.getTime());
40
+ if (t.has(e)) return t.get(e);
41
+ if (e instanceof Date) return new Date(e.getTime());
42
42
  if (e instanceof RegExp) return new RegExp(e.source, e.flags);
43
43
  if (Array.isArray(e)) {
44
44
  let n = e.length, r = Array(n);
45
+ t.set(e, r);
45
46
  for (let i = 0; i < n; i++) r[i] = a(e[i], t);
46
47
  return r;
47
48
  }
48
49
  let n = Object.getPrototypeOf(e);
49
50
  if (n !== Object.prototype && n !== null) return e;
50
51
  let r = {};
52
+ t.set(e, r);
51
53
  for (let n in e) Object.hasOwn(e, n) && (r[n] = a(e[n], t));
52
54
  return r;
53
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"object.util.js","names":[],"sources":["../../../src/util/object/object.util.ts"],"sourcesContent":["/**\n * Check if a string is a valid JSON string.\n * This function attempts to parse the string as JSON and returns true if successful,\n * false if the string is not valid JSON.\n *\n * @param str - The string to check for valid JSON format.\n * @returns True if the string is a valid JSON string, false otherwise.\n */\nexport function isJSON(str: string): boolean {\n try {\n JSON.parse(str);\n return true;\n }\n catch {\n return false;\n }\n}\n\n/**\n * Gets a nested value from an object using a path array.\n * This function traverses the object following the provided path and returns\n * the value at the specified location, or undefined if the path doesn't exist.\n *\n * @param obj - The object to get the value from.\n * @param path - An array of keys representing the path to the desired value.\n * @returns The value at the specified path, or undefined if the path doesn't exist.\n */\nexport function getNestedValue<T>(obj: T, path: (string | number)[]): unknown {\n // Optimization: Loop is faster than reduce and allows early exit\n let current: unknown = obj;\n const len = path.length;\n\n for (let i = 0; i < len; i++) {\n // Optimization: Early return if current value is null/undefined or not an object\n // This avoids unnecessary key lookups and type checks\n if (current == null || typeof current !== 'object') {\n return undefined;\n }\n\n const key = path[i];\n\n if (key !== undefined && key in (current as Record<string | number, unknown>)) {\n current = (current as Record<string | number, unknown>)[key];\n }\n else {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n * Recursively sets a value at a nested path within an object, creating intermediate objects as needed.\n *\n * @param obj - The source object.\n * @param path - Array of keys forming the path.\n * @param value - The value to set.\n * @param index - Current recursion depth.\n * @returns A new object with the value set at the specified path.\n */\nfunction setNestedValueHelper<T>(obj: T, path: (string | number)[], value: unknown, index: number): T {\n if (index >= path.length)\n return obj;\n\n const head = path[index];\n\n if (index === path.length - 1) {\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number]: value,\n } as T;\n }\n\n const current = (obj as Record<string | number, unknown>)[head as string | number];\n\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number | symbol]: setNestedValueHelper(\n typeof current === 'object' && current !== null\n ? (current as object)\n : {},\n path,\n value,\n index + 1,\n ),\n } as T;\n}\n\n/**\n * Sets a nested value in an object using a path array.\n * This function creates the path if it doesn't exist and sets the value at the specified location.\n * The function returns a new object with the updated value, maintaining immutability.\n *\n * @param obj - The object to set the value in.\n * @param path - An array of keys representing the path to the desired location.\n * @param value - The value to set at the specified path.\n * @returns A new object with the updated value at the specified path.\n */\nexport function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T {\n if (path.length === 0)\n return obj;\n\n return setNestedValueHelper(obj, path, value, 0);\n}\n\n/**\n * Deep clones an object or array.\n * This function creates a deep copy of the input, recursively cloning objects and arrays.\n * Primitive values, dates, and other non-plain objects are returned as is (or cloned if supported).\n *\n * @remarks\n * **Non-POJO objects are NOT cloned.** Objects with custom prototypes (e.g., Mongoose ObjectId,\n * class instances, Map, Set, Buffer) are returned **by reference** to preserve driver\n * compatibility. Mutations to these nested references will affect the original.\n * If you need full deep cloning of complex types, use `structuredClone()` or a dedicated library.\n *\n * @param obj - The object to clone.\n * @returns A deep copy of the object (with non-POJO objects returned by reference).\n */\nexport function deepClone<T>(obj: T): T {\n return deepCloneInternal(obj, new WeakSet<object>());\n}\n\n/**\n * Internal recursive implementation of deepClone with circular reference detection.\n *\n * @param obj - The value to clone.\n * @param seen - A WeakSet tracking already-visited objects to prevent infinite recursion.\n * @returns A deep copy of the value.\n */\nfunction deepCloneInternal<T>(obj: T, seen: WeakSet<object>): T {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (seen.has(obj as object)) {\n throw new Error('deepClone: Circular reference detected.');\n }\n seen.add(obj as object);\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as unknown as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as unknown as T;\n }\n\n if (Array.isArray(obj)) {\n // Optimization: `new Array(len)` + `for` loop is ~10-15% faster than `Array.map` or `Array.from`\n // for large arrays since it avoids callback overhead and pre-allocates memory.\n const len = obj.length;\n // eslint-disable-next-line unicorn/no-new-array -- Pre-allocating array size for performance\n const arr = new Array(len);\n for (let i = 0; i < len; i++) {\n arr[i] = deepCloneInternal(obj[i], seen);\n }\n return arr as unknown as T;\n }\n\n // Handle Mongoose ObjectId and other custom classes by returning reference.\n // structuredClone is not used here because it silently corrupts nested non-POJO\n // types (e.g., ObjectId → plain object) and Date instances in jsdom environments.\n const proto = Object.getPrototypeOf(obj);\n if (proto !== Object.prototype && proto !== null) {\n return obj;\n }\n\n const result = {} as Record<string, unknown>;\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n result[key] = deepCloneInternal((obj as Record<string, unknown>)[key], seen);\n }\n }\n\n return result as T;\n}\n\n/**\n * Deep merges multiple objects into a single object.\n * @param args - The objects to merge. Can be empty, in which case returns an empty object.\n * @returns The merged object.\n */\nexport function deepMerge<T = Record<string, unknown>>(\n ...args: (object | null | undefined)[]\n): T;\n\n/**\n * Deep merges multiple arrays into a single array.\n * @param args - The arrays to merge. Can be empty, in which case returns an empty array.\n * @returns The merged array.\n */\nexport function deepMerge<T = unknown[]>(\n ...args: (unknown[] | null | undefined)[]\n): T;\n\n/**\n * Implementation of deepMerge function.\n * @param args - The objects or arrays to merge.\n * @returns The merged result.\n */\nexport function deepMerge<T = Record<string, unknown> | unknown[]>(\n ...args: (object | unknown[] | null | undefined)[]\n): T {\n const MAX_DEPTH = 20;\n\n /** Recursively merges an array of objects with depth and circular-reference tracking. */\n function mergeRecursive(\n validArgs: object[],\n depth: number,\n seen: WeakSet<object>,\n ): unknown {\n // Depth guard\n if (depth > MAX_DEPTH) {\n throw new Error(`deepMerge: Maximum depth of ${MAX_DEPTH} exceeded. Possible circular reference or excessively nested objects.`);\n }\n\n // Handle empty arguments\n if (validArgs.length === 0) {\n return {};\n }\n\n // If only one argument, return it directly\n if (validArgs.length === 1) {\n return validArgs[0];\n }\n\n // Check if all arguments are arrays\n if (validArgs.every(Array.isArray)) {\n return (validArgs as unknown[][]).flat();\n }\n\n // Check if all arguments are objects (but not arrays)\n if (validArgs.every(arg => typeof arg === 'object' && arg !== null && !Array.isArray(arg))) {\n const result = {} as Record<string, unknown>;\n\n for (const arg of validArgs) {\n // Circular reference protection (per-arg scope prevents false\n // positives when the same object appears in multiple branches)\n if (seen.has(arg)) {\n throw new Error('deepMerge: Circular reference detected.');\n }\n\n const obj = arg as Record<string, unknown>;\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key];\n if (Object.hasOwn(result, key)) {\n const existingValue = result[key];\n if (\n typeof value === 'object' && value !== null\n && typeof existingValue === 'object' && existingValue !== null\n ) {\n if (Array.isArray(value) && Array.isArray(existingValue)) {\n result[key] = [...existingValue, ...value];\n }\n else if (!Array.isArray(value) && !Array.isArray(existingValue)) {\n result[key] = mergeRecursive(\n [existingValue as Record<string, unknown>, value as Record<string, unknown>],\n depth + 1,\n new WeakSet<object>(),\n );\n }\n else {\n // One is array, other is object — overwrite\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n }\n }\n return result;\n }\n\n // Check if all arguments are primitive values\n if (validArgs.every(arg => typeof arg !== 'object' || arg === null)) {\n throw new Error(\n 'deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.',\n );\n }\n\n // Mixed types error\n const hasArrays = validArgs.some(Array.isArray);\n const hasObjects = validArgs.some(arg =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg),\n );\n\n if (hasArrays && hasObjects) {\n throw new Error(\n 'deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects.',\n );\n }\n\n // Fallback for unexpected cases\n throw new Error(\n 'deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.',\n );\n }\n\n // Filter out null/undefined\n const validArgs = args.filter((arg): arg is object => arg !== null && arg !== undefined);\n\n return mergeRecursive(validArgs, 0, new WeakSet<object>()) as T;\n}\n\n/**\n * Normalizes MongoDB filters to support both dot notation strings and nested objects.\n * This function converts nested object filters to dot notation format while preserving\n * MongoDB operators to ensure consistent behavior across different filter input formats.\n *\n * @param filter - The filter object to normalize.\n * @returns A normalized filter object with nested objects converted to dot notation,\n * while preserving MongoDB operators as nested objects.\n *\n * @example\n * ```typescript\n * // Both of these will work the same way:\n * normalizeMongoFilter({ \"location.countryId\": \"240\" })\n * normalizeMongoFilter({ location: { countryId: \"240\" } })\n * // Both return: { \"location.countryId\": \"240\" }\n *\n * // MongoDB operators are preserved:\n * normalizeMongoFilter({ id: { $in: [\"240\", \"59\"] } })\n * // Returns: { id: { $in: [\"240\", \"59\"] } }\n * ```\n */\nexport function normalizeMongoFilter<T extends Record<string, unknown>>(filter: T): T {\n if (!filter || typeof filter !== 'object') {\n return filter;\n }\n\n const normalized: Record<string, unknown> = {};\n\n /**\n * Recursively flattens nested objects into dot-notation keys, preserving MongoDB operators.\n */\n function flatten(current: Record<string, unknown>, prefix: string) {\n for (const key in current) {\n if (!Object.hasOwn(current, key))\n continue;\n\n const value = current[key];\n const newKey = prefix ? `${prefix}.${key}` : key;\n\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n // Fast-path POJO check: `.constructor` is safe even on null-prototype objects\n // (returns undefined, so the === Object check simply fails and falls through\n // to the getPrototypeOf check which correctly identifies it as a POJO).\n const isPojo = (value as object).constructor === Object\n || Object.getPrototypeOf(value) === null;\n\n if (!isPojo) {\n normalized[newKey] = value;\n continue;\n }\n\n // Check for Mongo operator\n let hasMongoOperator = false;\n for (const subKey in value as Record<string, unknown>) {\n if (Object.hasOwn(value, subKey) && subKey.startsWith('$')) {\n hasMongoOperator = true;\n break;\n }\n }\n\n if (hasMongoOperator) {\n normalized[newKey] = value;\n }\n else {\n flatten(value as Record<string, unknown>, newKey);\n }\n }\n else {\n normalized[newKey] = value;\n }\n }\n }\n\n flatten(filter, '');\n\n return normalized as T;\n}\n"],"mappings":";AAQA,SAAgB,EAAO,GAAsB;AACzC,KAAI;AAEA,SADA,KAAK,MAAM,EAAI,EACR;SAEL;AACF,SAAO;;;AAaf,SAAgB,EAAkB,GAAQ,GAAoC;CAE1E,IAAI,IAAmB,GACjB,IAAM,EAAK;AAEjB,MAAK,IAAI,IAAI,GAAG,IAAI,GAAK,KAAK;AAG1B,MAAuB,OAAO,KAAY,aAAtC,EACA;EAGJ,IAAM,IAAM,EAAK;AAEjB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AAQ,cAAY,KAAgB,CAAC,MAAM,QAAQ,EAAI,CACjE;AASD,QANc,MADV,KAAa,IAET,8FAMJ,mGALC;;AAYT,QAAO,EAFW,EAAK,QAAQ,MAAuB,KAAQ,KAA0B,EAEvD,mBAAG,IAAI,SAAiB,CAAC;;AAwB9D,SAAgB,EAAwD,GAAc;AAClF,KAAI,CAAC,KAAU,OAAO,KAAW,SAC7B,QAAO;CAGX,IAAM,IAAsC,EAAE;CAK9C,SAAS,EAAQ,GAAkC,GAAgB;AAC/D,OAAK,IAAM,KAAO,GAAS;AACvB,OAAI,CAAC,OAAO,OAAO,GAAS,EAAI,CAC5B;GAEJ,IAAM,IAAQ,EAAQ,IAChB,IAAS,IAAS,GAAG,EAAO,GAAG,MAAQ;AAE7C,OAAI,KAAS,OAAO,KAAU,YAAY,CAAC,MAAM,QAAQ,EAAM,EAAE;AAO7D,QAAI,EAHY,EAAiB,gBAAgB,UAC1C,OAAO,eAAe,EAAM,KAAK,OAE3B;AACT,OAAW,KAAU;AACrB;;IAIJ,IAAI,IAAmB;AACvB,SAAK,IAAM,KAAU,EACjB,KAAI,OAAO,OAAO,GAAO,EAAO,IAAI,EAAO,WAAW,IAAI,EAAE;AACxD,SAAmB;AACnB;;AAIR,IAAI,IACA,EAAW,KAAU,IAGrB,EAAQ,GAAkC,EAAO;SAIrD,GAAW,KAAU;;;AAOjC,QAFA,EAAQ,GAAQ,GAAG,EAEZ"}
1
+ {"version":3,"file":"object.util.js","names":[],"sources":["../../../src/util/object/object.util.ts"],"sourcesContent":["/**\n * Check if a string is a valid JSON string.\n * This function attempts to parse the string as JSON and returns true if successful,\n * false if the string is not valid JSON.\n *\n * @param str - The string to check for valid JSON format.\n * @returns True if the string is a valid JSON string, false otherwise.\n */\nexport function isJSON(str: string): boolean {\n try {\n JSON.parse(str);\n return true;\n }\n catch {\n return false;\n }\n}\n\n/**\n * Gets a nested value from an object using a path array.\n * This function traverses the object following the provided path and returns\n * the value at the specified location, or undefined if the path doesn't exist.\n *\n * @param obj - The object to get the value from.\n * @param path - An array of keys representing the path to the desired value.\n * @returns The value at the specified path, or undefined if the path doesn't exist.\n */\nexport function getNestedValue<T>(obj: T, path: (string | number)[]): unknown {\n // Optimization: Loop is faster than reduce and allows early exit\n let current: unknown = obj;\n const len = path.length;\n\n for (let i = 0; i < len; i++) {\n // Optimization: Early return if current value is null/undefined or not an object\n // This avoids unnecessary key lookups and type checks\n if (current == null || typeof current !== 'object') {\n return undefined;\n }\n\n const key = path[i];\n\n if (key !== undefined && key in (current as Record<string | number, unknown>)) {\n current = (current as Record<string | number, unknown>)[key];\n }\n else {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n * Recursively sets a value at a nested path within an object, creating intermediate objects as needed.\n *\n * @param obj - The source object.\n * @param path - Array of keys forming the path.\n * @param value - The value to set.\n * @param index - Current recursion depth.\n * @returns A new object with the value set at the specified path.\n */\nfunction setNestedValueHelper<T>(obj: T, path: (string | number)[], value: unknown, index: number): T {\n if (index >= path.length)\n return obj;\n\n const head = path[index];\n\n if (index === path.length - 1) {\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number]: value,\n } as T;\n }\n\n const current = (obj as Record<string | number, unknown>)[head as string | number];\n\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number | symbol]: setNestedValueHelper(\n typeof current === 'object' && current !== null\n ? (current as object)\n : {},\n path,\n value,\n index + 1,\n ),\n } as T;\n}\n\n/**\n * Sets a nested value in an object using a path array.\n * This function creates the path if it doesn't exist and sets the value at the specified location.\n * The function returns a new object with the updated value, maintaining immutability.\n *\n * @param obj - The object to set the value in.\n * @param path - An array of keys representing the path to the desired location.\n * @param value - The value to set at the specified path.\n * @returns A new object with the updated value at the specified path.\n */\nexport function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T {\n if (path.length === 0)\n return obj;\n\n return setNestedValueHelper(obj, path, value, 0);\n}\n\n/**\n * Deep clones an object or array.\n * This function creates a deep copy of the input, recursively cloning objects and arrays.\n * Primitive values, dates, and other non-plain objects are returned as is (or cloned if supported).\n *\n * @remarks\n * **Non-POJO objects are NOT cloned.** Objects with custom prototypes (e.g., Mongoose ObjectId,\n * class instances, Map, Set, Buffer) are returned **by reference** to preserve driver\n * compatibility. Mutations to these nested references will affect the original.\n * If you need full deep cloning of complex types, use `structuredClone()` or a dedicated library.\n *\n * @param obj - The object to clone.\n * @returns A deep copy of the object (with non-POJO objects returned by reference).\n */\nexport function deepClone<T>(obj: T): T {\n return deepCloneInternal(obj, new WeakMap<object, unknown>());\n}\n\n/**\n * Internal recursive implementation of deepClone with shared-reference and circular-reference handling.\n *\n * Uses a WeakMap to track already-cloned objects. This correctly handles:\n * - **Shared references**: The same object appearing in multiple places returns\n * the same clone (preserving the shared-reference topology).\n * - **Circular references**: Detected because the object is added to the map\n * before* its children are recursed into; a back-edge will find itself in\n * the map and return the (partially constructed) clone rather than recursing\n * infinitely.\n *\n * @param obj - The value to clone.\n * @param seen - A WeakMap mapping original objects to their clones.\n * @returns A deep copy of the value.\n */\nfunction deepCloneInternal<T>(obj: T, seen: WeakMap<object, unknown>): T {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n // Return the already-cloned copy for shared (or circular) references\n if (seen.has(obj as object)) {\n return seen.get(obj as object) as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as unknown as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as unknown as T;\n }\n\n if (Array.isArray(obj)) {\n // Optimization: `new Array(len)` + `for` loop is ~10-15% faster than `Array.map` or `Array.from`\n // for large arrays since it avoids callback overhead and pre-allocates memory.\n const len = obj.length;\n // eslint-disable-next-line unicorn/no-new-array -- Pre-allocating array size for performance\n const arr = new Array(len);\n // Register before recursing to handle circular references within arrays\n seen.set(obj as object, arr);\n\n for (let i = 0; i < len; i++) {\n arr[i] = deepCloneInternal(obj[i], seen);\n }\n\n return arr as unknown as T;\n }\n\n // Handle Mongoose ObjectId and other custom classes by returning reference.\n // structuredClone is not used here because it silently corrupts nested non-POJO\n // types (e.g., ObjectId → plain object) and Date instances in jsdom environments.\n const proto = Object.getPrototypeOf(obj);\n\n if (proto !== Object.prototype && proto !== null) {\n return obj;\n }\n\n const result = {} as Record<string, unknown>;\n // Register before recursing to handle circular references within objects\n seen.set(obj as object, result);\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n result[key] = deepCloneInternal((obj as Record<string, unknown>)[key], seen);\n }\n }\n\n return result as T;\n}\n\n/**\n * Deep merges multiple objects into a single object.\n * @param args - The objects to merge. Can be empty, in which case returns an empty object.\n * @returns The merged object.\n */\nexport function deepMerge<T = Record<string, unknown>>(\n ...args: (object | null | undefined)[]\n): T;\n\n/**\n * Deep merges multiple arrays into a single array.\n * @param args - The arrays to merge. Can be empty, in which case returns an empty array.\n * @returns The merged array.\n */\nexport function deepMerge<T = unknown[]>(\n ...args: (unknown[] | null | undefined)[]\n): T;\n\n/**\n * Implementation of deepMerge function.\n * @param args - The objects or arrays to merge.\n * @returns The merged result.\n */\nexport function deepMerge<T = Record<string, unknown> | unknown[]>(\n ...args: (object | unknown[] | null | undefined)[]\n): T {\n const MAX_DEPTH = 20;\n\n /** Recursively merges an array of objects with depth and circular-reference tracking. */\n function mergeRecursive(\n validArgs: object[],\n depth: number,\n seen: WeakSet<object>,\n ): unknown {\n // Depth guard\n if (depth > MAX_DEPTH) {\n throw new Error(`deepMerge: Maximum depth of ${MAX_DEPTH} exceeded. Possible circular reference or excessively nested objects.`);\n }\n\n // Handle empty arguments\n if (validArgs.length === 0) {\n return {};\n }\n\n // If only one argument, return it directly\n if (validArgs.length === 1) {\n return validArgs[0];\n }\n\n // Check if all arguments are arrays\n if (validArgs.every(Array.isArray)) {\n return (validArgs as unknown[][]).flat();\n }\n\n // Check if all arguments are objects (but not arrays)\n if (validArgs.every(arg => typeof arg === 'object' && arg !== null && !Array.isArray(arg))) {\n const result = {} as Record<string, unknown>;\n\n for (const arg of validArgs) {\n // Circular reference protection (per-arg scope prevents false\n // positives when the same object appears in multiple branches)\n if (seen.has(arg)) {\n throw new Error('deepMerge: Circular reference detected.');\n }\n\n const obj = arg as Record<string, unknown>;\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key];\n if (Object.hasOwn(result, key)) {\n const existingValue = result[key];\n if (\n typeof value === 'object' && value !== null\n && typeof existingValue === 'object' && existingValue !== null\n ) {\n if (Array.isArray(value) && Array.isArray(existingValue)) {\n result[key] = [...existingValue, ...value];\n }\n else if (!Array.isArray(value) && !Array.isArray(existingValue)) {\n result[key] = mergeRecursive(\n [existingValue as Record<string, unknown>, value as Record<string, unknown>],\n depth + 1,\n new WeakSet<object>(),\n );\n }\n else {\n // One is array, other is object — overwrite\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n }\n }\n return result;\n }\n\n // Check if all arguments are primitive values\n if (validArgs.every(arg => typeof arg !== 'object' || arg === null)) {\n throw new Error(\n 'deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.',\n );\n }\n\n // Mixed types error\n const hasArrays = validArgs.some(Array.isArray);\n const hasObjects = validArgs.some(arg =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg),\n );\n\n if (hasArrays && hasObjects) {\n throw new Error(\n 'deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects.',\n );\n }\n\n // Fallback for unexpected cases\n throw new Error(\n 'deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.',\n );\n }\n\n // Filter out null/undefined\n const validArgs = args.filter((arg): arg is object => arg !== null && arg !== undefined);\n\n return mergeRecursive(validArgs, 0, new WeakSet<object>()) as T;\n}\n\n/**\n * Normalizes MongoDB filters to support both dot notation strings and nested objects.\n * This function converts nested object filters to dot notation format while preserving\n * MongoDB operators to ensure consistent behavior across different filter input formats.\n *\n * @param filter - The filter object to normalize.\n * @returns A normalized filter object with nested objects converted to dot notation,\n * while preserving MongoDB operators as nested objects.\n *\n * @example\n * ```typescript\n * // Both of these will work the same way:\n * normalizeMongoFilter({ \"location.countryId\": \"240\" })\n * normalizeMongoFilter({ location: { countryId: \"240\" } })\n * // Both return: { \"location.countryId\": \"240\" }\n *\n * // MongoDB operators are preserved:\n * normalizeMongoFilter({ id: { $in: [\"240\", \"59\"] } })\n * // Returns: { id: { $in: [\"240\", \"59\"] } }\n * ```\n */\nexport function normalizeMongoFilter<T extends Record<string, unknown>>(filter: T): T {\n if (!filter || typeof filter !== 'object') {\n return filter;\n }\n\n const normalized: Record<string, unknown> = {};\n\n /**\n * Recursively flattens nested objects into dot-notation keys, preserving MongoDB operators.\n */\n function flatten(current: Record<string, unknown>, prefix: string) {\n for (const key in current) {\n if (!Object.hasOwn(current, key))\n continue;\n\n const value = current[key];\n const newKey = prefix ? `${prefix}.${key}` : key;\n\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n // Fast-path POJO check: `.constructor` is safe even on null-prototype objects\n // (returns undefined, so the === Object check simply fails and falls through\n // to the getPrototypeOf check which correctly identifies it as a POJO).\n const isPojo = (value as object).constructor === Object\n || Object.getPrototypeOf(value) === null;\n\n if (!isPojo) {\n normalized[newKey] = value;\n continue;\n }\n\n // Check for Mongo operator\n let hasMongoOperator = false;\n for (const subKey in value as Record<string, unknown>) {\n if (Object.hasOwn(value, subKey) && subKey.startsWith('$')) {\n hasMongoOperator = true;\n break;\n }\n }\n\n if (hasMongoOperator) {\n normalized[newKey] = value;\n }\n else {\n flatten(value as Record<string, unknown>, newKey);\n }\n }\n else {\n normalized[newKey] = value;\n }\n }\n }\n\n flatten(filter, '');\n\n return normalized as T;\n}\n"],"mappings":";AAQA,SAAgB,EAAO,GAAsB;AACzC,KAAI;AAEA,SADA,KAAK,MAAM,EAAI,EACR;SAEL;AACF,SAAO;;;AAaf,SAAgB,EAAkB,GAAQ,GAAoC;CAE1E,IAAI,IAAmB,GACjB,IAAM,EAAK;AAEjB,MAAK,IAAI,IAAI,GAAG,IAAI,GAAK,KAAK;AAG1B,MAAuB,O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AU,MACN,qFACH;EAIL,IAAM,IAAY,EAAU,KAAK,MAAM,QAAQ,EACzC,IAAa,EAAU,MAAK,MAC9B,OAAO,KAAQ,cAAY,KAAgB,CAAC,MAAM,QAAQ,EAAI,CACjE;AASD,QANc,MADV,KAAa,IAET,8FAMJ,mGALC;;AAYT,QAAO,EAFW,EAAK,QAAQ,MAAuB,KAAQ,KAA0B,EAEvD,mBAAG,IAAI,SAAiB,CAAC;;AAwB9D,SAAgB,EAAwD,GAAc;AAClF,KAAI,CAAC,KAAU,OAAO,KAAW,SAC7B,QAAO;CAGX,IAAM,IAAsC,EAAE;CAK9C,SAAS,EAAQ,GAAkC,GAAgB;AAC/D,OAAK,IAAM,KAAO,GAAS;AACvB,OAAI,CAAC,OAAO,OAAO,GAAS,EAAI,CAC5B;GAEJ,IAAM,IAAQ,EAAQ,IAChB,IAAS,IAAS,GAAG,EAAO,GAAG,MAAQ;AAE7C,OAAI,KAAS,OAAO,KAAU,YAAY,CAAC,MAAM,QAAQ,EAAM,EAAE;AAO7D,QAAI,EAHY,EAAiB,gBAAgB,UAC1C,OAAO,eAAe,EAAM,KAAK,OAE3B;AACT,OAAW,KAAU;AACrB;;IAIJ,IAAI,IAAmB;AACvB,SAAK,IAAM,KAAU,EACjB,KAAI,OAAO,OAAO,GAAO,EAAO,IAAI,EAAO,WAAW,IAAI,EAAE;AACxD,SAAmB;AACnB;;AAIR,IAAI,IACA,EAAW,KAAU,IAGrB,EAAQ,GAAkC,EAAO;SAIrD,GAAW,KAAU;;;AAOjC,QAFA,EAAQ,GAAQ,GAAG,EAEZ"}
@@ -46,16 +46,16 @@ var e = {
46
46
  }),
47
47
  deserialize: (e) => BigInt(e)
48
48
  }
49
- }, t = {
50
- serialize(t) {
51
- return JSON.stringify(t, function(t, n) {
52
- let r = this[t];
53
- if (r instanceof Date) return e.Date.serialize(r);
54
- for (let t of Object.keys(e)) {
55
- let r = e[t];
56
- if (r.is(n)) return r.serialize(n);
49
+ }, t = Object.entries(e).filter(([e]) => e !== "Date").map(([, e]) => e), n = {
50
+ serialize(n) {
51
+ return JSON.stringify(n, function(n, r) {
52
+ let i = this[n];
53
+ if (i instanceof Date) return e.Date.serialize(i);
54
+ for (let e = 0; e < t.length; e++) {
55
+ let n = t[e];
56
+ if (n.is(r)) return n.serialize(r);
57
57
  }
58
- return n;
58
+ return r;
59
59
  });
60
60
  },
61
61
  deserialize(t) {
@@ -69,6 +69,6 @@ var e = {
69
69
  }
70
70
  };
71
71
  //#endregion
72
- export { t as serializer };
72
+ export { n as serializer };
73
73
 
74
74
  //# sourceMappingURL=serializer.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.util.js","names":[],"sources":["../../../src/util/serializer/serializer.util.ts"],"sourcesContent":["import type {\n I_Serializer,\n I_SerializerTypeWrapper,\n I_SerializerValueMap,\n T_SerializerKnownTypes,\n} from './serializer.type.js';\n\n/**\n * Interface for handling serialization and deserialization of specific types.\n * Each handler provides methods to check if a value is of the specific type,\n * serialize it to a format that can be JSON stringified, and deserialize it back.\n */\ninterface I_Handler<T extends T_SerializerKnownTypes> {\n /** Checks if a value is of the specific type */\n is: (value: unknown) => value is I_SerializerValueMap[T];\n /** Serializes a value of the specific type to a format that can be JSON stringified */\n serialize: (value: I_SerializerValueMap[T]) => I_SerializerTypeWrapper<T>;\n /** Deserializes a value back to the specific type */\n deserialize: (value: unknown) => I_SerializerValueMap[T];\n}\n\n/**\n * Type handlers for different JavaScript types that cannot be directly serialized to JSON.\n * Each handler provides methods to serialize and deserialize specific types like Date, Map, Set, etc.\n */\nconst typeHandlers: {\n [K in T_SerializerKnownTypes]: I_Handler<K>;\n} = {\n Date: {\n is: (v): v is Date => v instanceof Date,\n serialize: v => ({ __type: 'Date', value: v.toISOString() }),\n deserialize: v => new Date(v as string),\n },\n Map: {\n is: (v): v is Map<unknown, unknown> => v instanceof Map,\n serialize: v => ({ __type: 'Map', value: [...v.entries()] }),\n deserialize: v => new Map(v as [unknown, unknown][]),\n },\n Set: {\n is: (v): v is Set<unknown> => v instanceof Set,\n serialize: v => ({ __type: 'Set', value: [...v] }),\n deserialize: v => new Set(v as unknown[]),\n },\n RegExp: {\n is: (v): v is RegExp => v instanceof RegExp,\n serialize: v => ({\n __type: 'RegExp',\n value: { source: v.source, flags: v.flags },\n }),\n deserialize: (v) => {\n const { source, flags } = v as { source: string; flags: string };\n return new RegExp(source, flags);\n },\n },\n BigInt: {\n is: (v): v is bigint => typeof v === 'bigint',\n serialize: v => ({ __type: 'BigInt', value: v.toString() }),\n deserialize: v => BigInt(v as string),\n },\n};\n\n/**\n * A serializer that can handle complex JavaScript types that cannot be directly JSON stringified.\n * This serializer extends JSON.stringify and JSON.parse to handle types like Date, Map, Set, RegExp, and BigInt.\n *\n * The serializer works by:\n * 1. During serialization: Wrapping special types with type information before JSON stringification\n * 2. During deserialization: Detecting wrapped types and reconstructing them to their original form\n *\n * @remarks\n * **Wire format protocol:** Non-JSON-native types are serialized as wrapper objects with the shape\n * `{ __type: string, value: unknown }`. For example:\n * - Date → `{ __type: 'Date', value: '2024-01-01T00:00:00.000Z' }`\n * - Map → `{ __type: 'Map', value: [['key', 'val']] }`\n * - Set → `{ __type: 'Set', value: [1, 2, 3] }`\n * - RegExp → `{ __type: 'RegExp', value: { source: '...', flags: '...' } }`\n * - BigInt → `{ __type: 'BigInt', value: '12345' }`\n *\n * **Cross-service compatibility:** Any service that deserializes data produced by this serializer\n * must use the same `__type` protocol. Plain `JSON.parse` will return the wrapper objects as-is\n * without reconstructing the original types.\n */\nexport const serializer: I_Serializer<unknown> = {\n /**\n * Serializes a value to a JSON string.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be serialized using the corresponding handler.\n * Otherwise, it will be serialized as is.\n *\n * @param value - The value to serialize to a JSON string.\n * @returns The serialized JSON string that can be safely stored or transmitted.\n */\n serialize(value) {\n return JSON.stringify(value, function (_key, val) {\n // eslint-disable-next-line ts/no-this-alias\n const context = this;\n const originalValue = context[_key];\n\n if (originalValue instanceof Date) {\n return typeHandlers.Date.serialize(originalValue);\n }\n\n for (const type of Object.keys(typeHandlers) as T_SerializerKnownTypes[]) {\n const handler = typeHandlers[type];\n\n if (handler.is(val)) {\n return (handler as I_Handler<typeof type>).serialize(val);\n }\n }\n\n return val;\n });\n },\n /**\n * Deserializes a JSON string to its original value.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be deserialized using the corresponding handler.\n * Otherwise, it will be deserialized as is.\n *\n * @param json - The JSON string to deserialize back to its original form.\n * @returns The deserialized value with all special types reconstructed.\n */\n deserialize(json) {\n return JSON.parse(json, (_key, val) => {\n if (\n val\n && typeof val === 'object'\n && '__type' in val\n && typeof val.__type === 'string'\n ) {\n const type = val.__type as T_SerializerKnownTypes;\n const handler = typeHandlers[type];\n\n if (handler) {\n return handler.deserialize(val.value);\n }\n }\n return val;\n });\n },\n};\n"],"mappings":";AAyBA,IAAM,IAEF;CACA,MAAM;EACF,KAAK,MAAiB,aAAa;EACnC,YAAW,OAAM;GAAE,QAAQ;GAAQ,OAAO,EAAE,aAAa;GAAE;EAC3D,cAAa,MAAK,IAAI,KAAK,EAAY;EAC1C;CACD,KAAK;EACD,KAAK,MAAkC,aAAa;EACpD,YAAW,OAAM;GAAE,QAAQ;GAAO,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC;GAAE;EAC3D,cAAa,MAAK,IAAI,IAAI,EAA0B;EACvD;CACD,KAAK;EACD,KAAK,MAAyB,aAAa;EAC3C,YAAW,OAAM;GAAE,QAAQ;GAAO,OAAO,CAAC,GAAG,EAAE;GAAE;EACjD,cAAa,MAAK,IAAI,IAAI,EAAe;EAC5C;CACD,QAAQ;EACJ,KAAK,MAAmB,aAAa;EACrC,YAAW,OAAM;GACb,QAAQ;GACR,OAAO;IAAE,QAAQ,EAAE;IAAQ,OAAO,EAAE;IAAO;GAC9C;EACD,cAAc,MAAM;GAChB,IAAM,EAAE,WAAQ,aAAU;AAC1B,UAAO,IAAI,OAAO,GAAQ,EAAM;;EAEvC;CACD,QAAQ;EACJ,KAAK,MAAmB,OAAO,KAAM;EACrC,YAAW,OAAM;GAAE,QAAQ;GAAU,OAAO,EAAE,UAAU;GAAE;EAC1D,cAAa,MAAK,OAAO,EAAY;EACxC;CACJ,EAuBY,IAAoC;CAU7C,UAAU,GAAO;AACb,SAAO,KAAK,UAAU,GAAO,SAAU,GAAM,GAAK;GAG9C,IAAM,IADU,KACc;AAE9B,OAAI,aAAyB,KACzB,QAAO,EAAa,KAAK,UAAU,EAAc;AAGrD,QAAK,IAAM,KAAQ,OAAO,KAAK,EAAa,EAA8B;IACtE,IAAM,IAAU,EAAa;AAE7B,QAAI,EAAQ,GAAG,EAAI,CACf,QAAQ,EAAmC,UAAU,EAAI;;AAIjE,UAAO;IACT;;CAWN,YAAY,GAAM;AACd,SAAO,KAAK,MAAM,IAAO,GAAM,MAAQ;AACnC,OACI,KACG,OAAO,KAAQ,YACf,YAAY,KACZ,OAAO,EAAI,UAAW,UAC3B;IAEE,IAAM,IAAU,EADH,EAAI;AAGjB,QAAI,EACA,QAAO,EAAQ,YAAY,EAAI,MAAM;;AAG7C,UAAO;IACT;;CAET"}
1
+ {"version":3,"file":"serializer.util.js","names":[],"sources":["../../../src/util/serializer/serializer.util.ts"],"sourcesContent":["import type {\n I_Serializer,\n I_SerializerTypeWrapper,\n I_SerializerValueMap,\n T_SerializerKnownTypes,\n} from './serializer.type.js';\n\n/**\n * Interface for handling serialization and deserialization of specific types.\n * Each handler provides methods to check if a value is of the specific type,\n * serialize it to a format that can be JSON stringified, and deserialize it back.\n */\ninterface I_Handler<T extends T_SerializerKnownTypes> {\n /** Checks if a value is of the specific type */\n is: (value: unknown) => value is I_SerializerValueMap[T];\n /** Serializes a value of the specific type to a format that can be JSON stringified */\n serialize: (value: I_SerializerValueMap[T]) => I_SerializerTypeWrapper<T>;\n /** Deserializes a value back to the specific type */\n deserialize: (value: unknown) => I_SerializerValueMap[T];\n}\n\n/**\n * Type handlers for different JavaScript types that cannot be directly serialized to JSON.\n * Each handler provides methods to serialize and deserialize specific types like Date, Map, Set, etc.\n */\nconst typeHandlers: {\n [K in T_SerializerKnownTypes]: I_Handler<K>;\n} = {\n Date: {\n is: (v): v is Date => v instanceof Date,\n serialize: v => ({ __type: 'Date', value: v.toISOString() }),\n deserialize: v => new Date(v as string),\n },\n Map: {\n is: (v): v is Map<unknown, unknown> => v instanceof Map,\n serialize: v => ({ __type: 'Map', value: [...v.entries()] }),\n deserialize: v => new Map(v as [unknown, unknown][]),\n },\n Set: {\n is: (v): v is Set<unknown> => v instanceof Set,\n serialize: v => ({ __type: 'Set', value: [...v] }),\n deserialize: v => new Set(v as unknown[]),\n },\n RegExp: {\n is: (v): v is RegExp => v instanceof RegExp,\n serialize: v => ({\n __type: 'RegExp',\n value: { source: v.source, flags: v.flags },\n }),\n deserialize: (v) => {\n const { source, flags } = v as { source: string; flags: string };\n return new RegExp(source, flags);\n },\n },\n BigInt: {\n is: (v): v is bigint => typeof v === 'bigint',\n serialize: v => ({ __type: 'BigInt', value: v.toString() }),\n deserialize: v => BigInt(v as string),\n },\n};\n\nconst typeHandlersValues = (Object.entries(typeHandlers) as [\n T_SerializerKnownTypes,\n I_Handler<T_SerializerKnownTypes>,\n][])\n .filter(([key]) => key !== 'Date')\n .map(([, handler]) => handler);\n\n/**\n * A serializer that can handle complex JavaScript types that cannot be directly JSON stringified.\n * This serializer extends JSON.stringify and JSON.parse to handle types like Date, Map, Set, RegExp, and BigInt.\n *\n * The serializer works by:\n * 1. During serialization: Wrapping special types with type information before JSON stringification\n * 2. During deserialization: Detecting wrapped types and reconstructing them to their original form\n *\n * @remarks\n * **Wire format protocol:** Non-JSON-native types are serialized as wrapper objects with the shape\n * `{ __type: string, value: unknown }`. For example:\n * - Date → `{ __type: 'Date', value: '2024-01-01T00:00:00.000Z' }`\n * - Map → `{ __type: 'Map', value: [['key', 'val']] }`\n * - Set → `{ __type: 'Set', value: [1, 2, 3] }`\n * - RegExp → `{ __type: 'RegExp', value: { source: '...', flags: '...' } }`\n * - BigInt → `{ __type: 'BigInt', value: '12345' }`\n *\n * **Cross-service compatibility:** Any service that deserializes data produced by this serializer\n * must use the same `__type` protocol. Plain `JSON.parse` will return the wrapper objects as-is\n * without reconstructing the original types.\n */\nexport const serializer: I_Serializer<unknown> = {\n /**\n * Serializes a value to a JSON string.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be serialized using the corresponding handler.\n * Otherwise, it will be serialized as is.\n *\n * @param value - The value to serialize to a JSON string.\n * @returns The serialized JSON string that can be safely stored or transmitted.\n */\n serialize(value) {\n return JSON.stringify(value, function (_key, val) {\n // eslint-disable-next-line ts/no-this-alias\n const context = this;\n const originalValue = context[_key];\n\n if (originalValue instanceof Date) {\n return typeHandlers.Date.serialize(originalValue);\n }\n\n for (let i = 0; i < typeHandlersValues.length; i++) {\n const handler = typeHandlersValues[i]!;\n\n if (handler.is(val)) {\n return handler.serialize(val as I_SerializerValueMap[T_SerializerKnownTypes]);\n }\n }\n\n return val;\n });\n },\n /**\n * Deserializes a JSON string to its original value.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be deserialized using the corresponding handler.\n * Otherwise, it will be deserialized as is.\n *\n * @param json - The JSON string to deserialize back to its original form.\n * @returns The deserialized value with all special types reconstructed.\n */\n deserialize(json) {\n return JSON.parse(json, (_key, val) => {\n if (\n val\n && typeof val === 'object'\n && '__type' in val\n && typeof val.__type === 'string'\n ) {\n const type = val.__type as T_SerializerKnownTypes;\n const handler = typeHandlers[type];\n\n if (handler) {\n return handler.deserialize(val.value);\n }\n }\n return val;\n });\n },\n};\n"],"mappings":";AAyBA,IAAM,IAEF;CACA,MAAM;EACF,KAAK,MAAiB,aAAa;EACnC,YAAW,OAAM;GAAE,QAAQ;GAAQ,OAAO,EAAE,aAAa;GAAE;EAC3D,cAAa,MAAK,IAAI,KAAK,EAAY;EAC1C;CACD,KAAK;EACD,KAAK,MAAkC,aAAa;EACpD,YAAW,OAAM;G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,QAAO,EAAQ,YAAY,EAAI,MAAM;;AAG7C,UAAO;IACT;;CAET"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cyberskill/shared",
3
3
  "type": "module",
4
- "version": "3.11.0",
4
+ "version": "3.13.0",
5
5
  "description": "CyberSkill Shared",
6
6
  "author": "Stephen Cheng",
7
7
  "license": "MIT",
@@ -232,9 +232,9 @@
232
232
  "@antfu/eslint-config": "7.7.3",
233
233
  "@apollo/client": "4.1.6",
234
234
  "@apollo/client-integration-nextjs": "0.14.4",
235
- "@apollo/server": "5.4.0",
235
+ "@apollo/server": "5.5.0",
236
236
  "@as-integrations/express5": "1.1.2",
237
- "@dotenvx/dotenvx": "1.57.0",
237
+ "@dotenvx/dotenvx": "1.58.0",
238
238
  "@eddeee888/gcg-typescript-resolver-files": "0.15.0",
239
239
  "@eslint-react/eslint-plugin": "2.13.0",
240
240
  "@graphql-codegen/cli": "6.2.1",
@@ -252,7 +252,7 @@
252
252
  "cors": "2.8.6",
253
253
  "date-fns": "4.1.0",
254
254
  "envalid": "8.1.1",
255
- "eslint-config-next": "16.2.0",
255
+ "eslint-config-next": "16.2.1",
256
256
  "eslint-plugin-format": "2.0.1",
257
257
  "eslint-plugin-react-hooks": "7.0.1",
258
258
  "eslint-plugin-react-refresh": "0.5.2",
@@ -263,36 +263,36 @@
263
263
  "extract-files": "13.0.0",
264
264
  "fs-extra": "11.3.4",
265
265
  "globals": "17.4.0",
266
- "graphql": "16.13.1",
266
+ "graphql": "16.13.2",
267
267
  "graphql-upload": "17.0.0",
268
- "graphql-ws": "6.0.7",
268
+ "graphql-ws": "6.0.8",
269
269
  "helmet": "8.1.0",
270
- "i18next": "25.8.20",
270
+ "i18next": "25.10.10",
271
271
  "migrate-mongo": "14.0.7",
272
- "mongodb": "7.1.0",
273
- "mongoose": "9.3.1",
272
+ "mongodb": "7.1.1",
273
+ "mongoose": "9.3.3",
274
274
  "mongoose-aggregate-paginate-v2": "1.1.4",
275
- "mongoose-paginate-v2": "1.9.3",
275
+ "mongoose-paginate-v2": "1.9.4",
276
276
  "next-intl": "4.8.3",
277
277
  "qs": "6.15.0",
278
278
  "react": "19.2.4",
279
279
  "react-dom": "19.2.4",
280
280
  "react-hot-toast": "2.6.0",
281
- "react-i18next": "16.5.8",
281
+ "react-i18next": "16.6.6",
282
282
  "rxjs": "7.8.2",
283
- "ws": "8.19.0",
283
+ "ws": "8.20.0",
284
284
  "yargs": "18.0.0"
285
285
  },
286
286
  "devDependencies": {
287
287
  "@commitlint/cli": "20.5.0",
288
288
  "@commitlint/config-conventional": "20.5.0",
289
289
  "@eslint/config-inspector": "1.5.0",
290
- "@next/eslint-plugin-next": "16.2.0",
290
+ "@next/eslint-plugin-next": "16.2.1",
291
291
  "@semantic-release/changelog": "6.0.3",
292
292
  "@semantic-release/git": "10.0.1",
293
293
  "@semantic-release/github": "12.0.6",
294
- "@storybook/react": "10.3.1",
295
- "@storybook/react-vite": "10.3.1",
294
+ "@storybook/react": "10.3.3",
295
+ "@storybook/react-vite": "10.3.3",
296
296
  "@testing-library/dom": "10.4.1",
297
297
  "@testing-library/jest-dom": "6.9.1",
298
298
  "@testing-library/react": "16.3.2",
@@ -312,8 +312,8 @@
312
312
  "@types/react-dom": "19.2.3",
313
313
  "@types/ws": "8.18.1",
314
314
  "@types/yargs": "17.0.35",
315
- "@vitest/browser": "4.1.0",
316
- "@vitest/coverage-istanbul": "4.1.0",
315
+ "@vitest/browser": "4.1.2",
316
+ "@vitest/coverage-istanbul": "4.1.2",
317
317
  "conventional-changelog-conventionalcommits": "9.3.0",
318
318
  "eslint": "10.1.0",
319
319
  "glob": "13.0.6",
@@ -325,10 +325,10 @@
325
325
  "semantic-release": "25.0.3",
326
326
  "simple-git-hooks": "2.13.1",
327
327
  "tsx": "4.21.0",
328
- "typescript": "5.9.3",
329
- "vite": "8.0.1",
328
+ "typescript": "6.0.2",
329
+ "vite": "8.0.3",
330
330
  "vite-plugin-dts": "4.5.4",
331
- "vitest": "4.1.0"
331
+ "vitest": "4.1.2"
332
332
  },
333
333
  "publishConfig": {
334
334
  "access": "public",
@@ -337,7 +337,7 @@
337
337
  },
338
338
  "pnpm": {
339
339
  "overrides": {
340
- "minimatch": ">=10.2.3"
340
+ "minimatch": ">=10.2.4"
341
341
  }
342
342
  }
343
343
  }
@@ -1,8 +0,0 @@
1
- //#region node_modules/.pnpm/vitest@4.1.0_@types+node@25.5.0_jsdom@29.0.1_@noble+hashes@1.8.0__vite@8.0.1_@types+nod_5f6c16f4d4385f16c87b17afc93c851f/node_modules/vitest/dist/config.js
2
- function e(e) {
3
- return e;
4
- }
5
- //#endregion
6
- export { e as defineConfig };
7
-
8
- //# sourceMappingURL=config.js.map