@cyberskill/shared 3.10.0 → 3.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/commitlint/index.d.ts +1 -5
- package/dist/config/env/env.util.js.map +1 -1
- package/dist/config/env/index.d.ts +1 -3
- package/dist/config/eslint/index.d.ts +1 -1198
- package/dist/config/graphql-codegen/index.d.ts +1 -2
- package/dist/config/index.d.ts +1 -2
- package/dist/config/lint-staged/index.d.ts +1 -5
- package/dist/config/storybook/index.d.ts +1 -2
- package/dist/config/vitest/index.d.ts +1 -3
- package/dist/config/vitest/vitest.e2e.d.ts +1 -20
- package/dist/config/vitest/vitest.e2e.js +1 -1
- package/dist/config/vitest/vitest.unit.d.ts +1 -22
- package/dist/config/vitest/vitest.unit.js +1 -1
- package/dist/constant/index.d.ts +1 -5
- package/dist/constant/response-status.js.map +1 -1
- package/dist/node/apollo-server/index.d.ts +1 -2
- package/dist/node/cli/index.d.ts +1 -2
- package/dist/node/command/index.d.ts +1 -2
- package/dist/node/express/express.util.js.map +1 -1
- package/dist/node/express/index.d.ts +1 -2
- package/dist/node/fs/index.d.ts +1 -2
- package/dist/node/log/index.d.ts +1 -2
- package/dist/node/mongo/index.d.ts +1 -6
- package/dist/node/mongo/mongo.controller.helpers.js +20 -0
- package/dist/node/mongo/mongo.controller.helpers.js.map +1 -0
- package/dist/node/mongo/mongo.controller.native.js +65 -93
- package/dist/node/mongo/mongo.controller.native.js.map +1 -1
- package/dist/node/mongo/mongo.util.js.map +1 -1
- package/dist/node/package/index.d.ts +1 -2
- package/dist/node/path/index.d.ts +1 -2
- package/dist/node/storage/index.d.ts +1 -3
- package/dist/node/storage/index.js +3 -3
- package/dist/node/storage/storage.constant.js +2 -2
- package/dist/node/storage/storage.constant.js.map +1 -1
- package/dist/node/storage/storage.util.js +60 -68
- package/dist/node/storage/storage.util.js.map +1 -1
- package/dist/node/upload/index.d.ts +1 -3
- package/dist/node/upload/upload.type.js.map +1 -1
- package/dist/node/upload/upload.util.js +10 -2
- package/dist/node/upload/upload.util.js.map +1 -1
- package/dist/node/ws/index.d.ts +1 -2
- package/dist/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 +8 -0
- package/dist/node_modules/.pnpm/{vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_36acd00c2670b611b011192023dc5bd9 → 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.map +1 -1
- package/dist/react/apollo-client/index.d.ts +1 -9
- package/dist/react/apollo-client/links/index.d.ts +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.d.ts +1 -16
- package/dist/react/apollo-client-nextjs/index.d.ts +1 -2
- package/dist/react/apollo-error/apollo-error.component.js +6 -2
- package/dist/react/apollo-error/apollo-error.component.js.map +1 -1
- package/dist/react/apollo-error/index.d.ts +1 -6
- package/dist/react/i18next/index.d.ts +1 -2
- package/dist/react/loading/index.d.ts +1 -5
- package/dist/react/log/index.d.ts +1 -2
- package/dist/react/next-intl/index.d.ts +1 -6
- package/dist/react/storage/index.d.ts +1 -2
- package/dist/react/storage/storage.hook.js.map +1 -1
- package/dist/react/storage/storage.util.js +15 -10
- package/dist/react/storage/storage.util.js.map +1 -1
- package/dist/react/toast/index.d.ts +1 -1
- package/dist/react/userback/index.d.ts +1 -2
- package/dist/src/config/commitlint/index.d.ts +5 -0
- package/dist/{config → src/config}/config.type.d.ts +1 -1
- package/dist/{config → src/config}/config.util.d.ts +1 -1
- package/dist/src/config/env/index.d.ts +3 -0
- package/dist/src/config/eslint/index.d.ts +1198 -0
- package/dist/src/config/graphql-codegen/index.d.ts +2 -0
- package/dist/src/config/index.d.ts +2 -0
- package/dist/src/config/lint-staged/index.d.ts +5 -0
- package/dist/src/config/storybook/index.d.ts +2 -0
- package/dist/src/config/vitest/index.d.ts +3 -0
- package/dist/src/config/vitest/vitest.e2e.d.ts +20 -0
- package/dist/src/config/vitest/vitest.unit.d.ts +22 -0
- package/dist/src/constant/index.d.ts +5 -0
- package/dist/{constant → src/constant}/response-status.d.ts +4 -0
- package/dist/src/node/apollo-server/index.d.ts +2 -0
- package/dist/src/node/cli/index.d.ts +2 -0
- package/dist/src/node/command/index.d.ts +2 -0
- package/dist/{node → src/node}/express/express.util.d.ts +6 -0
- package/dist/src/node/express/index.d.ts +2 -0
- package/dist/src/node/fs/index.d.ts +2 -0
- package/dist/src/node/log/index.d.ts +2 -0
- package/dist/{node → src/node}/log/log.type.d.ts +2 -2
- package/dist/{node → src/node}/log/log.util.d.ts +1 -1
- package/dist/src/node/mongo/index.d.ts +6 -0
- package/dist/src/node/mongo/mongo.controller.helpers.d.ts +43 -0
- package/dist/{node → src/node}/mongo/mongo.controller.mongoose.d.ts +1 -1
- package/dist/{node → src/node}/mongo/mongo.controller.native.d.ts +1 -1
- package/dist/{node → src/node}/mongo/mongo.controller.type.d.ts +1 -1
- package/dist/src/node/package/index.d.ts +2 -0
- package/dist/{node → src/node}/package/package.util.d.ts +1 -1
- package/dist/src/node/path/index.d.ts +2 -0
- package/dist/src/node/storage/index.d.ts +3 -0
- package/dist/src/node/storage/storage.constant.d.ts +1 -0
- package/dist/src/node/storage/storage.type.d.ts +3 -0
- package/dist/{node → src/node}/storage/storage.util.d.ts +1 -1
- package/dist/src/node/upload/index.d.ts +3 -0
- package/dist/{node → src/node}/upload/upload.type.d.ts +2 -0
- package/dist/{node → src/node}/upload/upload.util.d.ts +1 -1
- package/dist/src/node/ws/index.d.ts +2 -0
- package/dist/{react → src/react}/apollo-client/apollo-client.type.d.ts +1 -1
- package/dist/src/react/apollo-client/index.d.ts +9 -0
- package/dist/src/react/apollo-client/links/index.d.ts +1 -0
- package/dist/src/react/apollo-client-nextjs/apollo-client-nextjs.rsc.d.ts +16 -0
- package/dist/src/react/apollo-client-nextjs/index.d.ts +2 -0
- package/dist/src/react/apollo-error/index.d.ts +6 -0
- package/dist/src/react/i18next/index.d.ts +2 -0
- package/dist/src/react/loading/index.d.ts +5 -0
- package/dist/{react → src/react}/loading/loading.provider.d.ts +1 -1
- package/dist/src/react/log/index.d.ts +2 -0
- package/dist/src/react/log/log.type.d.ts +1 -0
- package/dist/{react → src/react}/log/log.util.d.ts +1 -1
- package/dist/src/react/next-intl/index.d.ts +6 -0
- package/dist/{react → src/react}/next-intl/next-intl.hoc.d.ts +1 -1
- package/dist/{react → src/react}/next-intl/next-intl.type.d.ts +1 -1
- package/dist/src/react/storage/index.d.ts +2 -0
- package/dist/{react → src/react}/storage/storage.hook.d.ts +2 -2
- package/dist/{react → src/react}/storage/storage.util.d.ts +6 -7
- package/dist/src/react/toast/index.d.ts +1 -0
- package/dist/src/react/userback/index.d.ts +2 -0
- package/dist/src/typescript/index.d.ts +5 -0
- package/dist/{util → src/util}/common/common.util.d.ts +15 -2
- package/dist/src/util/common/index.d.ts +5 -0
- package/dist/src/util/index.d.ts +9 -0
- package/dist/src/util/log/index.d.ts +2 -0
- package/dist/{util → src/util}/log/log.util.d.ts +1 -1
- package/dist/src/util/object/index.d.ts +4 -0
- package/dist/{util → src/util}/object/object.util.d.ts +7 -3
- package/dist/src/util/serializer/index.d.ts +2 -0
- package/dist/src/util/string/index.d.ts +5 -0
- package/dist/src/util/validate/index.d.ts +4 -0
- package/dist/typescript/index.d.ts +1 -5
- package/dist/util/common/common.util.js +22 -9
- package/dist/util/common/common.util.js.map +1 -1
- package/dist/util/common/index.d.ts +1 -5
- package/dist/util/common/index.js +2 -2
- package/dist/util/index.d.ts +1 -9
- package/dist/util/index.js +7 -7
- package/dist/util/log/index.d.ts +1 -2
- package/dist/util/object/index.d.ts +1 -4
- package/dist/util/object/object.util.js +5 -3
- package/dist/util/object/object.util.js.map +1 -1
- package/dist/util/serializer/index.d.ts +1 -2
- package/dist/util/serializer/serializer.util.js +10 -10
- package/dist/util/serializer/serializer.util.js.map +1 -1
- package/dist/util/string/index.d.ts +1 -5
- package/dist/util/validate/index.d.ts +1 -4
- package/package.json +23 -24
- package/dist/node/storage/storage.constant.d.ts +0 -4
- package/dist/node/storage/storage.type.d.ts +0 -14
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.1_@types_nod_36acd00c2670b611b011192023dc5bd9/node_modules/vitest/dist/config.js +0 -8
- package/dist/react/log/log.type.d.ts +0 -1
- /package/dist/{config → src/config}/env/env.constant.d.ts +0 -0
- /package/dist/{config → src/config}/env/env.type.d.ts +0 -0
- /package/dist/{config → src/config}/env/env.util.d.ts +0 -0
- /package/dist/{config → src/config}/graphql-codegen/graphql-codegen.type.d.ts +0 -0
- /package/dist/{config → src/config}/graphql-codegen/graphql-codegen.util.d.ts +0 -0
- /package/dist/{config → src/config}/storybook/storybook.main.d.ts +0 -0
- /package/dist/{config → src/config}/storybook/storybook.preview.d.ts +0 -0
- /package/dist/{config → src/config}/vitest/vitest.unit.setup.d.ts +0 -0
- /package/dist/{constant → src/constant}/common.d.ts +0 -0
- /package/dist/{node → src/node}/apollo-server/apollo-server.type.d.ts +0 -0
- /package/dist/{node → src/node}/apollo-server/apollo-server.util.d.ts +0 -0
- /package/dist/{node → src/node}/command/command.type.d.ts +0 -0
- /package/dist/{node → src/node}/command/command.util.d.ts +0 -0
- /package/dist/{node → src/node}/express/express.type.d.ts +0 -0
- /package/dist/{node → src/node}/fs/fs.type.d.ts +0 -0
- /package/dist/{node → src/node}/fs/fs.util.d.ts +0 -0
- /package/dist/{node → src/node}/mongo/mongo.constant.d.ts +0 -0
- /package/dist/{node → src/node}/mongo/mongo.controller.d.ts +0 -0
- /package/dist/{node → src/node}/mongo/mongo.dynamic-populate.d.ts +0 -0
- /package/dist/{node → src/node}/mongo/mongo.internal-types.d.ts +0 -0
- /package/dist/{node → src/node}/mongo/mongo.populate.d.ts +0 -0
- /package/dist/{node → src/node}/mongo/mongo.type.d.ts +0 -0
- /package/dist/{node → src/node}/mongo/mongo.util.d.ts +0 -0
- /package/dist/{node → src/node}/package/package.type.d.ts +0 -0
- /package/dist/{node → src/node}/path/path.constant.d.ts +0 -0
- /package/dist/{node → src/node}/path/path.util.d.ts +0 -0
- /package/dist/{node → src/node}/upload/upload.constant.d.ts +0 -0
- /package/dist/{node → src/node}/ws/ws.type.d.ts +0 -0
- /package/dist/{node → src/node}/ws/ws.util.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client/apollo-client.component.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client/apollo-client.constant.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client/apollo-client.context.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client/apollo-client.hook.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client/apollo-client.util.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client/links/upload.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-client-nextjs/apollo-client-nextjs.util.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-error/apollo-error.component.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-error/apollo-error.context.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-error/apollo-error.hook.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-error/apollo-error.provider.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-error/apollo-error.type.d.ts +0 -0
- /package/dist/{react → src/react}/apollo-error/apollo-error.util.d.ts +0 -0
- /package/dist/{react → src/react}/i18next/i18next.hook.d.ts +0 -0
- /package/dist/{react → src/react}/i18next/i18next.util.d.ts +0 -0
- /package/dist/{react → src/react}/loading/loading.component.d.ts +0 -0
- /package/dist/{react → src/react}/loading/loading.context.d.ts +0 -0
- /package/dist/{react → src/react}/loading/loading.hook.d.ts +0 -0
- /package/dist/{react → src/react}/loading/loading.type.d.ts +0 -0
- /package/dist/{react → src/react}/next-intl/next-intl.constant.d.ts +0 -0
- /package/dist/{react → src/react}/next-intl/next-intl.context.d.ts +0 -0
- /package/dist/{react → src/react}/next-intl/next-intl.hook.d.ts +0 -0
- /package/dist/{react → src/react}/next-intl/next-intl.provider.d.ts +0 -0
- /package/dist/{react → src/react}/userback/userback.component.d.ts +0 -0
- /package/dist/{react → src/react}/userback/userback.type.d.ts +0 -0
- /package/dist/{typescript → src/typescript}/common.type.d.ts +0 -0
- /package/dist/{typescript → src/typescript}/react.type.d.ts +0 -0
- /package/dist/{util → src/util}/common/common.type.d.ts +0 -0
- /package/dist/{util → src/util}/log/log.type.d.ts +0 -0
- /package/dist/{util → src/util}/serializer/serializer.type.d.ts +0 -0
- /package/dist/{util → src/util}/serializer/serializer.util.d.ts +0 -0
- /package/dist/{util → src/util}/string/string.type.d.ts +0 -0
- /package/dist/{util → src/util}/string/string.util.d.ts +0 -0
- /package/dist/{util → src/util}/validate/validate.util.d.ts +0 -0
|
@@ -94,14 +94,22 @@ var o = [...a].join(""), s = RegExp(`[${o}]`, "g"), c = /[.*+?^${}()|[\]\\]/g;
|
|
|
94
94
|
function l(e) {
|
|
95
95
|
return e.replace(c, "\\$&");
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
return e = l(e), e.replace(s, (e) => i.get(e) || e);
|
|
99
|
-
}
|
|
100
|
-
var d = /\p{Diacritic}/gu;
|
|
97
|
+
var u = /* @__PURE__ */ new Map(), d = 128;
|
|
101
98
|
function f(e) {
|
|
102
|
-
|
|
99
|
+
let t = u.get(e);
|
|
100
|
+
if (t !== void 0) return t;
|
|
101
|
+
let n = l(e).replace(s, (e) => i.get(e) || e);
|
|
102
|
+
if (u.size >= d) {
|
|
103
|
+
let e = u.keys().next().value;
|
|
104
|
+
e !== void 0 && u.delete(e);
|
|
105
|
+
}
|
|
106
|
+
return u.set(e, n), n;
|
|
103
107
|
}
|
|
104
|
-
|
|
108
|
+
var p = /\p{Diacritic}/gu;
|
|
109
|
+
function m(e) {
|
|
110
|
+
return e.normalize("NFD").replace(p, "");
|
|
111
|
+
}
|
|
112
|
+
function h(e, t) {
|
|
105
113
|
if (!t) return [...new Set(e)];
|
|
106
114
|
let n = /* @__PURE__ */ new Set(), r = [];
|
|
107
115
|
for (let i of e) {
|
|
@@ -110,7 +118,7 @@ function p(e, t) {
|
|
|
110
118
|
}
|
|
111
119
|
return r;
|
|
112
120
|
}
|
|
113
|
-
function
|
|
121
|
+
function g(t) {
|
|
114
122
|
let { NODE_ENV: n = e.DEVELOPMENT, NODE_ENV_MODE: r = e.DEVELOPMENT } = t, i = n === e.DEVELOPMENT && r === e.DEVELOPMENT, a = n === e.PRODUCTION && r === e.STAGING, o = n === e.PRODUCTION && r === e.PRODUCTION;
|
|
115
123
|
if (n === e.PRODUCTION && r === e.DEVELOPMENT) throw Error("NODE_ENV_MODE must be set to staging or production in production environment");
|
|
116
124
|
return {
|
|
@@ -119,10 +127,15 @@ function m(t) {
|
|
|
119
127
|
IS_PROD: o
|
|
120
128
|
};
|
|
121
129
|
}
|
|
122
|
-
function
|
|
130
|
+
function _(e) {
|
|
123
131
|
return typeof e == "object" && !!e;
|
|
124
132
|
}
|
|
133
|
+
function v(e) {
|
|
134
|
+
if (typeof e != "object" || !e) return !1;
|
|
135
|
+
let t = Object.getPrototypeOf(e);
|
|
136
|
+
return t === Object.prototype || t === null;
|
|
137
|
+
}
|
|
125
138
|
//#endregion
|
|
126
|
-
export { l as escapeRegExp,
|
|
139
|
+
export { l as escapeRegExp, _ as isObject, v as isPlainObject, g as mapEnvironment, f as regexSearchMapper, m as removeAccent, h as uniqueArray };
|
|
127
140
|
|
|
128
141
|
//# sourceMappingURL=common.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.util.js","names":[],"sources":["../../../src/util/common/common.util.ts"],"sourcesContent":["import { E_Environment } from '#typescript/index.js';\n\nimport type { I_EnvFlags, I_NodeEnvInput } from './common.type.js';\n\nconst charMap: Record<string, string[]> = {\n a: ['à', 'á', 'ạ', 'ả', 'ã', 'â', 'ầ', 'ấ', 'ậ', 'ẩ', 'ẫ', 'ă', 'ằ', 'ắ', 'ặ', 'ẳ', 'ẵ'],\n e: ['è', 'é', 'ẹ', 'ẻ', 'ẽ', 'ê', 'ề', 'ế', 'ệ', 'ể', 'ễ'],\n i: ['ì', 'í', 'ị', 'ỉ', 'ĩ'],\n o: ['ò', 'ó', 'ọ', 'ỏ', 'õ', 'ô', 'ồ', 'ố', 'ộ', 'ổ', 'ỗ', 'ơ', 'ờ', 'ớ', 'ợ', 'ở', 'ỡ'],\n u: ['ù', 'ú', 'ụ', 'ủ', 'ũ', 'ư', 'ừ', 'ứ', 'ự', 'ử', 'ữ'],\n y: ['ỳ', 'ý', 'ỵ', 'ỷ', 'ỹ'],\n d: ['đ'],\n};\n\nconst upperCharMap: Record<string, string[]> = Object.entries(charMap).reduce(\n (map, [key, value]) => {\n map[key.toUpperCase()] = value.map(char => char.toUpperCase());\n return map;\n },\n {} as Record<string, string[]>,\n);\n\nconst combinedMap = { ...charMap, ...upperCharMap };\n\n// Pre-compute replacement map and search regex for better performance\n// This avoids rebuilding regexes and maps on every function call\nconst replacementMap = new Map<string, string>();\nconst charsToMatch = new Set<string>();\n\nObject.entries(combinedMap).forEach(([baseChar, variations]) => {\n // The replacement pattern is the same for the base char and all its variations\n // Example: 'a', 'à', 'á'... all map to '(a|à|á...)'\n const replacement = `(${[baseChar, ...variations].join('|')})`;\n\n [baseChar, ...variations].forEach((char) => {\n replacementMap.set(char, replacement);\n charsToMatch.add(char);\n });\n});\n\n// Construct a single regex that matches any character in our map\nconst patternString = [...charsToMatch].join('');\n// We use a character class regex: [abc...]\n// eslint-disable-next-line regexp/no-empty-character-class -- regex is built dynamically from precomputed charMap\nconst searchRegex = new RegExp(`[${patternString}]`, 'g');\n\nconst RE_ESCAPE_REGEXP = /[.*+?^${}()|[\\]\\\\]/g;\n\n/**\n * Escapes special characters in a string for use in a regular expression.\n * This function escapes characters that have special meaning in regex (e.g., ., *, +, ?, etc.)\n * so they are treated as literal characters.\n *\n * @param str - The string to escape.\n * @returns The escaped string safe for use in a RegExp.\n */\nexport function escapeRegExp(str: string): string {\n return str.replace(RE_ESCAPE_REGEXP, '\\\\$&');\n}\n\n/**\n * Convert a string to a regex pattern that matches the string and its accented variations.\n * This function normalizes the input string and creates a regex pattern that can match\n * both the original characters and their accented equivalents.\n *\n * Optimization: Uses pre-computed regex and map to perform replacement in a single pass (O(N)),\n * instead of iterating through all character groups (O(K*N)).\n * Removed unnecessary NFD normalization which improves performance and fixes\n * matching against NFC target strings.\n *\n * @param str - The string to convert to a regex pattern.\n * @returns The regex pattern as a string that matches the original string and its accented variations.\n */\nexport function regexSearchMapper(str: string) {\n str = escapeRegExp(str);\n return str.replace(searchRegex, match => replacementMap.get(match) || match);\n}\n\nconst RE_DIACRITIC = /\\p{Diacritic}/gu;\n\n/**\n * Remove accents from a string.\n * This function normalizes the string using NFD normalization and removes all diacritical marks.\n *\n * @param str - The string to remove accents from.\n * @returns The string without any accents or diacritical marks.\n */\nexport function removeAccent(str: string) {\n return str.normalize('NFD').replace(RE_DIACRITIC, '');\n}\n\n/**\n * Remove duplicates from an array based on a key function.\n * This function can remove duplicates either by comparing values directly (when no keyFn is provided)\n * or by using a custom key function to determine uniqueness.\n *\n * @param arr - The array to remove duplicates from.\n * @param keyFn - Optional function that returns a unique key for each item in the array.\n * @returns A new array with duplicates removed, maintaining the original order.\n */\nexport function uniqueArray<T>(\n arr: T[],\n keyFn?: (item: T) => string | number,\n): T[] {\n if (!keyFn) {\n return [...new Set(arr)];\n }\n\n const seen = new Set<string | number>();\n const result: T[] = [];\n\n for (const item of arr) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(item);\n }\n }\n\n return result;\n}\n\n/**\n * Map environment variables to boolean flags indicating the current environment.\n * This function takes NODE_ENV and NODE_ENV_MODE variables and returns flags\n * indicating whether the current environment is development, staging, or production.\n *\n * @param env - The environment variables object containing NODE_ENV and NODE_ENV_MODE.\n * @returns An object containing boolean flags for the environment (IS_DEV, IS_STAG, IS_PROD).\n * @throws {Error} When NODE_ENV is production but NODE_ENV_MODE is development.\n */\nexport function mapEnvironment(env: I_NodeEnvInput): I_EnvFlags {\n const { NODE_ENV = E_Environment.DEVELOPMENT, NODE_ENV_MODE = E_Environment.DEVELOPMENT } = env;\n\n const IS_DEV = NODE_ENV === E_Environment.DEVELOPMENT && NODE_ENV_MODE === E_Environment.DEVELOPMENT;\n const IS_STAG = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.STAGING;\n const IS_PROD = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.PRODUCTION;\n\n if (NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.DEVELOPMENT) {\n throw new Error('NODE_ENV_MODE must be set to staging or production in production environment');\n }\n\n return { IS_DEV, IS_STAG, IS_PROD };\n}\n\n/**\n * Checks if value is object-like (e.g., objects, arrays, etc.), not null.\n * Re-exported from util for general use across the codebase.\n *\n * @param value - The value to check.\n * @returns True if the value is an object and not null.\n */\nexport function isObject(value: unknown): value is object {\n return value != null && typeof value === 'object';\n}\n"],"mappings":";;AAIA,IAAM,IAAoC;CACtC,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CACxF,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CAC1D,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAI;CAC5B,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK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AE;AAEtB,MAAK,IAAM,KAAQ,GAAK;EACpB,IAAM,IAAM,EAAM,EAAK;AACvB,EAAK,EAAK,IAAI,EAAI,KACd,EAAK,IAAI,EAAI,EACb,EAAO,KAAK,EAAK;;AAIzB,QAAO;;AAYX,SAAgB,EAAe,GAAiC;CAC5D,IAAM,EAAE,cAAW,EAAc,aAAa,mBAAgB,EAAc,gBAAgB,GAEtF,IAAS,MAAa,EAAc,eAAe,MAAkB,EAAc,aACnF,IAAU,MAAa,EAAc,cAAc,MAAkB,EAAc,SACnF,IAAU,MAAa,EAAc,cAAc,MAAkB,EAAc;AAEzF,KAAI,MAAa,EAAc,cAAc,MAAkB,EAAc,YACzE,OAAU,MAAM,+EAA+E;AAGnG,QAAO;EAAE;EAAQ;EAAS;EAAS;;AAUvC,SAAgB,EAAS,GAAiC;AACtD,QAAwB,OAAO,KAAU,cAAlC"}
|
|
1
|
+
{"version":3,"file":"common.util.js","names":[],"sources":["../../../src/util/common/common.util.ts"],"sourcesContent":["import { E_Environment } from '#typescript/index.js';\n\nimport type { I_EnvFlags, I_NodeEnvInput } from './common.type.js';\n\nconst charMap: Record<string, string[]> = {\n a: ['à', 'á', 'ạ', 'ả', 'ã', 'â', 'ầ', 'ấ', 'ậ', 'ẩ', 'ẫ', 'ă', 'ằ', 'ắ', 'ặ', 'ẳ', 'ẵ'],\n e: ['è', 'é', 'ẹ', 'ẻ', 'ẽ', 'ê', 'ề', 'ế', 'ệ', 'ể', 'ễ'],\n i: ['ì', 'í', 'ị', 'ỉ', 'ĩ'],\n o: ['ò', 'ó', 'ọ', 'ỏ', 'õ', 'ô', 'ồ', 'ố', 'ộ', 'ổ', 'ỗ', 'ơ', 'ờ', 'ớ', 'ợ', 'ở', 'ỡ'],\n u: ['ù', 'ú', 'ụ', 'ủ', 'ũ', 'ư', 'ừ', 'ứ', 'ự', 'ử', 'ữ'],\n y: ['ỳ', 'ý', 'ỵ', 'ỷ', 'ỹ'],\n d: ['đ'],\n};\n\nconst upperCharMap: Record<string, string[]> = Object.entries(charMap).reduce(\n (map, [key, value]) => {\n map[key.toUpperCase()] = value.map(char => char.toUpperCase());\n return map;\n },\n {} as Record<string, string[]>,\n);\n\nconst combinedMap = { ...charMap, ...upperCharMap };\n\n// Pre-compute replacement map and search regex for better performance\n// This avoids rebuilding regexes and maps on every function call\nconst replacementMap = new Map<string, string>();\nconst charsToMatch = new Set<string>();\n\nObject.entries(combinedMap).forEach(([baseChar, variations]) => {\n // The replacement pattern is the same for the base char and all its variations\n // Example: 'a', 'à', 'á'... all map to '(a|à|á...)'\n const replacement = `(${[baseChar, ...variations].join('|')})`;\n\n [baseChar, ...variations].forEach((char) => {\n replacementMap.set(char, replacement);\n charsToMatch.add(char);\n });\n});\n\n// Construct a single regex that matches any character in our map\nconst patternString = [...charsToMatch].join('');\n// We use a character class regex: [abc...]\n// eslint-disable-next-line regexp/no-empty-character-class -- regex is built dynamically from precomputed charMap\nconst searchRegex = new RegExp(`[${patternString}]`, 'g');\n\nconst RE_ESCAPE_REGEXP = /[.*+?^${}()|[\\]\\\\]/g;\n\n/**\n * Escapes special characters in a string for use in a regular expression.\n * This function escapes characters that have special meaning in regex (e.g., ., *, +, ?, etc.)\n * so they are treated as literal characters.\n *\n * @param str - The string to escape.\n * @returns The escaped string safe for use in a RegExp.\n */\nexport function escapeRegExp(str: string): string {\n return str.replace(RE_ESCAPE_REGEXP, '\\\\$&');\n}\n\n/**\n * Simple LRU cache for regex search patterns.\n * Avoids redundant accent alternation and regex compilation for repeated search terms.\n */\nconst regexPatternCache = new Map<string, string>();\nconst REGEX_CACHE_MAX_SIZE = 128;\n\n/**\n * Convert a string to a regex pattern that matches the string and its accented variations.\n * This function normalizes the input string and creates a regex pattern that can match\n * both the original characters and their accented equivalents.\n *\n * Optimization: Uses pre-computed regex and map to perform replacement in a single pass (O(N)),\n * instead of iterating through all character groups (O(K*N)).\n * Results are cached in an LRU cache (max 128 entries) to avoid redundant computation\n * for repeated search terms.\n *\n * @param str - The string to convert to a regex pattern.\n * @returns The regex pattern as a string that matches the original string and its accented variations.\n */\nexport function regexSearchMapper(str: string) {\n const cached = regexPatternCache.get(str);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const escaped = escapeRegExp(str);\n const result = escaped.replace(searchRegex, match => replacementMap.get(match) || match);\n\n // Evict oldest entry if cache is full\n if (regexPatternCache.size >= REGEX_CACHE_MAX_SIZE) {\n const oldestKey = regexPatternCache.keys().next().value;\n if (oldestKey !== undefined) {\n regexPatternCache.delete(oldestKey);\n }\n }\n\n regexPatternCache.set(str, result);\n return result;\n}\n\nconst RE_DIACRITIC = /\\p{Diacritic}/gu;\n\n/**\n * Remove accents from a string.\n * This function normalizes the string using NFD normalization and removes all diacritical marks.\n *\n * @param str - The string to remove accents from.\n * @returns The string without any accents or diacritical marks.\n */\nexport function removeAccent(str: string) {\n return str.normalize('NFD').replace(RE_DIACRITIC, '');\n}\n\n/**\n * Remove duplicates from an array based on a key function.\n * This function can remove duplicates either by comparing values directly (when no keyFn is provided)\n * or by using a custom key function to determine uniqueness.\n *\n * @param arr - The array to remove duplicates from.\n * @param keyFn - Optional function that returns a unique key for each item in the array.\n * @returns A new array with duplicates removed, maintaining the original order.\n */\nexport function uniqueArray<T>(\n arr: T[],\n keyFn?: (item: T) => string | number,\n): T[] {\n if (!keyFn) {\n return [...new Set(arr)];\n }\n\n const seen = new Set<string | number>();\n const result: T[] = [];\n\n for (const item of arr) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(item);\n }\n }\n\n return result;\n}\n\n/**\n * Map environment variables to boolean flags indicating the current environment.\n * This function takes NODE_ENV and NODE_ENV_MODE variables and returns flags\n * indicating whether the current environment is development, staging, or production.\n *\n * @param env - The environment variables object containing NODE_ENV and NODE_ENV_MODE.\n * @returns An object containing boolean flags for the environment (IS_DEV, IS_STAG, IS_PROD).\n * @throws {Error} When NODE_ENV is production but NODE_ENV_MODE is development.\n */\nexport function mapEnvironment(env: I_NodeEnvInput): I_EnvFlags {\n const { NODE_ENV = E_Environment.DEVELOPMENT, NODE_ENV_MODE = E_Environment.DEVELOPMENT } = env;\n\n const IS_DEV = NODE_ENV === E_Environment.DEVELOPMENT && NODE_ENV_MODE === E_Environment.DEVELOPMENT;\n const IS_STAG = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.STAGING;\n const IS_PROD = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.PRODUCTION;\n\n if (NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.DEVELOPMENT) {\n throw new Error('NODE_ENV_MODE must be set to staging or production in production environment');\n }\n\n return { IS_DEV, IS_STAG, IS_PROD };\n}\n\n/**\n * Checks if value is object-like (e.g., objects, arrays, etc.), not null.\n * Re-exported from util for general use across the codebase.\n *\n * @remarks\n * Returns `true` for arrays, Dates, Maps, Sets, and class instances.\n * Use {@link isPlainObject} when you specifically need to check for plain objects only.\n *\n * @param value - The value to check.\n * @returns True if the value is an object and not null.\n */\nexport function isObject(value: unknown): value is object {\n return value != null && typeof value === 'object';\n}\n\n/**\n * Checks if a value is a plain object (created by `{}`, `Object.create(null)`, or `new Object()`).\n * Unlike {@link isObject}, this returns `false` for arrays, Dates, Maps, Sets, RegExps,\n * and other class instances.\n *\n * @param value - The value to check.\n * @returns True if the value is a plain object, false otherwise.\n */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value == null || typeof value !== 'object') {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n\n return proto === Object.prototype || proto === null;\n}\n"],"mappings":";;AAIA,IAAM,IAAoC;CACtC,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CACxF,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CAC1D,GAAG;EAAC;EAAK;EAAK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, isObject as t, isPlainObject as n, mapEnvironment as r, regexSearchMapper as i, removeAccent as a, uniqueArray as o } from "./common.util.js";
|
|
2
|
+
export { e as escapeRegExp, t as isObject, n as isPlainObject, r as mapEnvironment, i as regexSearchMapper, a as removeAccent, o as uniqueArray };
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Re-exports all utility modules for shared usage across the codebase.
|
|
3
|
-
*/
|
|
4
|
-
export * from './common/index.js';
|
|
5
|
-
export * from './log/index.js';
|
|
6
|
-
export * from './object/index.js';
|
|
7
|
-
export * from './serializer/index.js';
|
|
8
|
-
export * from './string/index.js';
|
|
9
|
-
export * from './validate/index.js';
|
|
1
|
+
export {}
|
package/dist/util/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { escapeRegExp as e, isObject as t,
|
|
2
|
-
import { baseCatchError as
|
|
3
|
-
import { deepClone as
|
|
4
|
-
import { serializer as
|
|
5
|
-
import { generateRandomPassword as
|
|
6
|
-
import { validate as
|
|
7
|
-
export {
|
|
1
|
+
import { escapeRegExp as e, isObject as t, isPlainObject as n, mapEnvironment as r, regexSearchMapper as i, removeAccent as a, uniqueArray as o } from "./common/common.util.js";
|
|
2
|
+
import { baseCatchError as s } from "./log/log.util.js";
|
|
3
|
+
import { deepClone as c, deepMerge as l, getNestedValue as u, isJSON as d, normalizeMongoFilter as f, setNestedValue as p } from "./object/object.util.js";
|
|
4
|
+
import { serializer as m } from "./serializer/serializer.util.js";
|
|
5
|
+
import { generateRandomPassword as h, generateRandomString as g, generateShortId as _, generateSlug as v, getFileName as y, substringBetween as b } from "./string/string.util.js";
|
|
6
|
+
import { validate as x } from "./validate/validate.util.js";
|
|
7
|
+
export { s as baseCatchError, c as deepClone, l as deepMerge, e as escapeRegExp, h as generateRandomPassword, g as generateRandomString, _ as generateShortId, v as generateSlug, y as getFileName, u as getNestedValue, d as isJSON, t as isObject, n as isPlainObject, r as mapEnvironment, f as normalizeMongoFilter, i as regexSearchMapper, a as removeAccent, m as serializer, p as setNestedValue, b as substringBetween, o as uniqueArray, x as validate };
|
package/dist/util/log/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { baseCatchError } from './log.util.js';
|
|
1
|
+
export {}
|
|
@@ -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
|
|
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))
|
|
41
|
-
if (
|
|
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 * Note: This implementation focuses on plain objects and arrays. For complex types like Map/Set/Buffer/ObjectId,\n * it returns the reference or handles them according to specific logic.\n *\n * @param obj - The object to clone.\n * @returns A deep copy of the object.\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,MAAI,MAAQ,KAAA,KAAa,KAAQ,EAC7B,KAAW,EAA6C;MAGxD;;AAIR,QAAO;;AAYX,SAAS,EAAwB,GAAQ,GAA2B,GAAgB,GAAkB;AAClG,KAAI,KAAS,EAAK,OACd,QAAO;CAEX,IAAM,IAAO,EAAK;AAElB,KAAI,MAAU,EAAK,SAAS,EACxB,QAAO;EACH,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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,OAAO,KAAY,aAAtC,EACA;EAGJ,IAAM,IAAM,EAAK;AAEjB,MAAI,MAAQ,KAAA,KAAa,KAAQ,EAC7B,KAAW,EAA6C;MAGxD;;AAIR,QAAO;;AAYX,SAAS,EAAwB,GAAQ,GAA2B,GAAgB,GAAkB;AAClG,KAAI,KAAS,EAAK,OACd,QAAO;CAEX,IAAM,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,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,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './serializer.util.js';
|
|
1
|
+
export {}
|
|
@@ -46,16 +46,16 @@ var e = {
|
|
|
46
46
|
}),
|
|
47
47
|
deserialize: (e) => BigInt(e)
|
|
48
48
|
}
|
|
49
|
-
}, t = {
|
|
50
|
-
serialize(
|
|
51
|
-
return JSON.stringify(
|
|
52
|
-
let
|
|
53
|
-
if (
|
|
54
|
-
for (let
|
|
55
|
-
let
|
|
56
|
-
if (
|
|
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
|
|
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 {
|
|
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 (
|
|
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;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,EAEK,IAAsB,OAAO,QAAQ,EAAa,CAInD,QAAQ,CAAC,OAAS,MAAQ,OAAO,CACjC,KAAK,GAAG,OAAa,EAAQ,EAuBrB,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,IAAI,IAAI,GAAG,IAAI,EAAmB,QAAQ,KAAK;IAChD,IAAM,IAAU,EAAmB;AAEnC,QAAI,EAAQ,GAAG,EAAI,CACf,QAAO,EAAQ,UAAU,EAAoD;;AAIrF,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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyberskill/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.12.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.
|
|
235
|
+
"@apollo/server": "5.5.0",
|
|
236
236
|
"@as-integrations/express5": "1.1.2",
|
|
237
|
-
"@dotenvx/dotenvx": "1.
|
|
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.
|
|
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,37 +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.
|
|
266
|
+
"graphql": "16.13.2",
|
|
267
267
|
"graphql-upload": "17.0.0",
|
|
268
|
-
"graphql-ws": "6.0.
|
|
268
|
+
"graphql-ws": "6.0.8",
|
|
269
269
|
"helmet": "8.1.0",
|
|
270
|
-
"i18next": "25.
|
|
271
|
-
"localforage": "1.10.0",
|
|
270
|
+
"i18next": "25.10.10",
|
|
272
271
|
"migrate-mongo": "14.0.7",
|
|
273
|
-
"mongodb": "7.1.
|
|
274
|
-
"mongoose": "9.3.
|
|
272
|
+
"mongodb": "7.1.1",
|
|
273
|
+
"mongoose": "9.3.3",
|
|
275
274
|
"mongoose-aggregate-paginate-v2": "1.1.4",
|
|
276
|
-
"mongoose-paginate-v2": "1.9.
|
|
275
|
+
"mongoose-paginate-v2": "1.9.4",
|
|
277
276
|
"next-intl": "4.8.3",
|
|
278
277
|
"qs": "6.15.0",
|
|
279
278
|
"react": "19.2.4",
|
|
280
279
|
"react-dom": "19.2.4",
|
|
281
280
|
"react-hot-toast": "2.6.0",
|
|
282
|
-
"react-i18next": "16.
|
|
281
|
+
"react-i18next": "16.6.6",
|
|
283
282
|
"rxjs": "7.8.2",
|
|
284
|
-
"ws": "8.
|
|
283
|
+
"ws": "8.20.0",
|
|
285
284
|
"yargs": "18.0.0"
|
|
286
285
|
},
|
|
287
286
|
"devDependencies": {
|
|
288
287
|
"@commitlint/cli": "20.5.0",
|
|
289
288
|
"@commitlint/config-conventional": "20.5.0",
|
|
290
289
|
"@eslint/config-inspector": "1.5.0",
|
|
291
|
-
"@next/eslint-plugin-next": "16.2.
|
|
290
|
+
"@next/eslint-plugin-next": "16.2.1",
|
|
292
291
|
"@semantic-release/changelog": "6.0.3",
|
|
293
292
|
"@semantic-release/git": "10.0.1",
|
|
294
293
|
"@semantic-release/github": "12.0.6",
|
|
295
|
-
"@storybook/react": "10.3.
|
|
296
|
-
"@storybook/react-vite": "10.3.
|
|
294
|
+
"@storybook/react": "10.3.3",
|
|
295
|
+
"@storybook/react-vite": "10.3.3",
|
|
297
296
|
"@testing-library/dom": "10.4.1",
|
|
298
297
|
"@testing-library/jest-dom": "6.9.1",
|
|
299
298
|
"@testing-library/react": "16.3.2",
|
|
@@ -313,12 +312,12 @@
|
|
|
313
312
|
"@types/react-dom": "19.2.3",
|
|
314
313
|
"@types/ws": "8.18.1",
|
|
315
314
|
"@types/yargs": "17.0.35",
|
|
316
|
-
"@vitest/browser": "4.1.
|
|
317
|
-
"@vitest/coverage-istanbul": "4.1.
|
|
315
|
+
"@vitest/browser": "4.1.2",
|
|
316
|
+
"@vitest/coverage-istanbul": "4.1.2",
|
|
318
317
|
"conventional-changelog-conventionalcommits": "9.3.0",
|
|
319
|
-
"eslint": "10.0
|
|
318
|
+
"eslint": "10.1.0",
|
|
320
319
|
"glob": "13.0.6",
|
|
321
|
-
"jsdom": "29.0.
|
|
320
|
+
"jsdom": "29.0.1",
|
|
322
321
|
"lint-staged": "16.4.0",
|
|
323
322
|
"node-modules-inspector": "1.4.2",
|
|
324
323
|
"npm-run-all2": "8.0.4",
|
|
@@ -326,10 +325,10 @@
|
|
|
326
325
|
"semantic-release": "25.0.3",
|
|
327
326
|
"simple-git-hooks": "2.13.1",
|
|
328
327
|
"tsx": "4.21.0",
|
|
329
|
-
"typescript": "
|
|
330
|
-
"vite": "8.0.
|
|
328
|
+
"typescript": "6.0.2",
|
|
329
|
+
"vite": "8.0.3",
|
|
331
330
|
"vite-plugin-dts": "4.5.4",
|
|
332
|
-
"vitest": "4.1.
|
|
331
|
+
"vitest": "4.1.2"
|
|
333
332
|
},
|
|
334
333
|
"publishConfig": {
|
|
335
334
|
"access": "public",
|
|
@@ -338,7 +337,7 @@
|
|
|
338
337
|
},
|
|
339
338
|
"pnpm": {
|
|
340
339
|
"overrides": {
|
|
341
|
-
"minimatch": ">=10.2.
|
|
340
|
+
"minimatch": ">=10.2.4"
|
|
342
341
|
}
|
|
343
342
|
}
|
|
344
343
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { default as localForage } from 'localforage';
|
|
2
|
-
export type LocalForageDriver = Parameters<typeof localForage.defineDriver>[0];
|
|
3
|
-
export interface NodeLocalForageOptions {
|
|
4
|
-
driver?: string | string[];
|
|
5
|
-
size?: number;
|
|
6
|
-
version?: number;
|
|
7
|
-
description?: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
storeName?: string;
|
|
10
|
-
baseDir?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface NodeFsDriverState {
|
|
13
|
-
baseDir: string;
|
|
14
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region node_modules/.pnpm/vitest@4.1.0_@types+node@25.5.0_jsdom@29.0.0_@noble+hashes@1.8.0__vite@8.0.1_@types+nod_36acd00c2670b611b011192023dc5bd9/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 +0,0 @@
|
|
|
1
|
-
export type { I_CatchErrorOptions } from '../../util/log/index.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|