@cyberskill/shared 2.4.0 → 2.6.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/node/mongo/mongo.util.cjs +4 -4
- package/dist/node/mongo/mongo.util.d.ts +21 -5
- package/dist/node/mongo/mongo.util.js +299 -263
- package/dist/util/index.cjs +1 -1
- package/dist/util/index.js +16 -15
- package/dist/util/object/index.cjs +1 -1
- package/dist/util/object/index.js +6 -5
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.d.ts +53 -5
- package/dist/util/object/object.util.js +76 -40
- package/package.json +11 -11
package/dist/util/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./common/common.util.cjs"),e=require("./object/object.util.cjs"),a=require("./serializer/serializer.util.cjs"),r=require("./string/string.util.cjs"),i=require("./validate/validate.util.cjs");exports.mapEnvironment=t.mapEnvironment;exports.regexSearchMapper=t.regexSearchMapper;exports.removeAccent=t.removeAccent;exports.uniqueArray=t.uniqueArray;exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;exports.serializer=a.serializer;exports.generateRandomPassword=r.generateRandomPassword;exports.generateShortId=r.generateShortId;exports.generateSlug=r.generateSlug;exports.getFileName=r.getFileName;exports.substringBetween=r.substringBetween;exports.validate=i.validate;
|
package/dist/util/index.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import { mapEnvironment as t, regexSearchMapper as
|
|
2
|
-
import { deepMerge as g, getNestedValue as
|
|
3
|
-
import { serializer as
|
|
4
|
-
import { generateRandomPassword as
|
|
1
|
+
import { mapEnvironment as t, regexSearchMapper as o, removeAccent as a, uniqueArray as n } from "./common/common.util.js";
|
|
2
|
+
import { deepMerge as g, getNestedValue as i, isJSON as p, normalizeMongoFilter as s, setNestedValue as l } from "./object/object.util.js";
|
|
3
|
+
import { serializer as u } from "./serializer/serializer.util.js";
|
|
4
|
+
import { generateRandomPassword as f, generateShortId as N, generateSlug as S, getFileName as c, substringBetween as v } from "./string/string.util.js";
|
|
5
5
|
import { validate as h } from "./validate/validate.util.js";
|
|
6
6
|
export {
|
|
7
7
|
g as deepMerge,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
f as generateRandomPassword,
|
|
9
|
+
N as generateShortId,
|
|
10
|
+
S as generateSlug,
|
|
11
|
+
c as getFileName,
|
|
12
|
+
i as getNestedValue,
|
|
13
|
+
p as isJSON,
|
|
14
14
|
t as mapEnvironment,
|
|
15
|
-
|
|
16
|
-
o as
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
s as normalizeMongoFilter,
|
|
16
|
+
o as regexSearchMapper,
|
|
17
|
+
a as removeAccent,
|
|
18
|
+
u as serializer,
|
|
19
|
+
l as setNestedValue,
|
|
20
|
+
v as substringBetween,
|
|
20
21
|
n as uniqueArray,
|
|
21
22
|
h as validate
|
|
22
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.setNestedValue=e.setNestedValue;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { deepMerge as
|
|
1
|
+
import { deepMerge as o, getNestedValue as r, isJSON as l, normalizeMongoFilter as s, setNestedValue as a } from "./object.util.js";
|
|
2
2
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
o as deepMerge,
|
|
4
|
+
r as getNestedValue,
|
|
5
|
+
l as isJSON,
|
|
6
|
+
s as normalizeMongoFilter,
|
|
7
|
+
a as setNestedValue
|
|
7
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("lodash-es");var m=Object.defineProperty,v=Object.defineProperties,b=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,g=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,u=(r,e,n)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n,l=(r,e)=>{for(var n in e||(e={}))g.call(e,n)&&u(r,n,e[n]);if(a)for(var n of a(e))O.call(e,n)&&u(r,n,e[n]);return r},c=(r,e)=>v(r,b(e));function _(r){try{return JSON.parse(r),!0}catch(e){return!1}}function h(r,e){return e.reduce((n,o)=>{if(n&&typeof n=="object"&&o in n)return n[o]},r)}function f(r,e,n){if(e.length===0)return r;const[o,...t]=e;if(t.length===0)return c(l({},r),{[o]:n});const s=r[o];return c(l({},r),{[o]:f(typeof s=="object"&&s!==null?s:{},t,n)})}function j(...r){if(r.length===0)return{};const e=r.filter(t=>t!=null).map(t=>typeof t!="object"?{}:t);if(e.length===0)return{};if(e.length===1)return e[0];if(e.every(i.isArray))return[].concat(...e);if(e.every(t=>typeof t=="object"&&t!==null&&!i.isArray(t)))return i.mergeWith({},...e,(t,s)=>{if(i.isArray(t)&&i.isArray(s))return t.concat(s)});if(e.every(t=>typeof t!="object"||t===null))throw new Error("deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.");const n=e.some(i.isArray),o=e.some(t=>typeof t=="object"&&t!==null&&!i.isArray(t));throw n&&o?new Error("deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."):new Error("deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.")}function p(r){if(!r||typeof r!="object")return r;const e={};for(const[n,o]of Object.entries(r))if(o&&typeof o=="object"&&!Array.isArray(o)){const t=p(o);for(const[s,y]of Object.entries(t)){const d=`${n}.${s}`;e[d]=y}}else e[n]=o;return e}exports.deepMerge=j;exports.getNestedValue=h;exports.isJSON=_;exports.normalizeMongoFilter=p;exports.setNestedValue=f;
|
|
@@ -30,13 +30,61 @@ export declare function getNestedValue<T>(obj: T, path: (string | number)[]): un
|
|
|
30
30
|
export declare function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T;
|
|
31
31
|
/**
|
|
32
32
|
* Deep merges multiple objects or arrays into a single object or array.
|
|
33
|
-
* This function handles different types of merging:
|
|
33
|
+
* This function handles different types of merging with improved type safety and error handling:
|
|
34
34
|
* - If all arguments are arrays, it concatenates them
|
|
35
35
|
* - If all arguments are objects, it deeply merges them (concatenating arrays within objects)
|
|
36
|
-
* -
|
|
36
|
+
* - Handles null/undefined values gracefully by treating them as empty objects
|
|
37
|
+
* - Provides better type inference and safety
|
|
38
|
+
* - Throws descriptive errors for invalid input
|
|
37
39
|
*
|
|
38
|
-
* @param args - The objects or arrays to merge.
|
|
40
|
+
* @param args - The objects or arrays to merge. Can be empty, in which case returns an empty object.
|
|
39
41
|
* @returns The merged result - either a concatenated array or a deeply merged object.
|
|
40
|
-
* @throws {Error} When arguments are mixed types (some arrays, some objects).
|
|
42
|
+
* @throws {Error} When arguments are mixed types (some arrays, some objects) or when all arguments are primitive values.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Merge objects
|
|
47
|
+
* deepMerge({ a: 1 }, { b: 2 }, { a: 3 }) // { a: 3, b: 2 }
|
|
48
|
+
*
|
|
49
|
+
* // Merge arrays
|
|
50
|
+
* deepMerge([1, 2], [3, 4]) // [1, 2, 3, 4]
|
|
51
|
+
*
|
|
52
|
+
* // Handle null/undefined
|
|
53
|
+
* deepMerge({ a: 1 }, null, undefined, { b: 2 }) // { a: 1, b: 2 }
|
|
54
|
+
*
|
|
55
|
+
* // Nested objects with arrays
|
|
56
|
+
* deepMerge(
|
|
57
|
+
* { items: [1, 2], config: { theme: 'dark' } },
|
|
58
|
+
* { items: [3, 4], config: { size: 'large' } }
|
|
59
|
+
* ) // { items: [1, 2, 3, 4], config: { theme: 'dark', size: 'large' } }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Deep merges multiple objects into a single object.
|
|
64
|
+
* @param args - The objects to merge. Can be empty, in which case returns an empty object.
|
|
65
|
+
* @returns The merged object.
|
|
66
|
+
*/
|
|
67
|
+
export declare function deepMerge<T extends Record<string, unknown>>(...args: (T | null | undefined)[]): T;
|
|
68
|
+
/**
|
|
69
|
+
* Deep merges multiple arrays into a single array.
|
|
70
|
+
* @param args - The arrays to merge. Can be empty, in which case returns an empty array.
|
|
71
|
+
* @returns The merged array.
|
|
72
|
+
*/
|
|
73
|
+
export declare function deepMerge<T extends unknown[]>(...args: (T | null | undefined)[]): T;
|
|
74
|
+
/**
|
|
75
|
+
* Normalizes MongoDB filters to support both dot notation strings and nested objects.
|
|
76
|
+
* This function converts nested object filters to dot notation format to ensure
|
|
77
|
+
* consistent behavior across different filter input formats.
|
|
78
|
+
*
|
|
79
|
+
* @param filter - The filter object to normalize.
|
|
80
|
+
* @returns A normalized filter object with nested objects converted to dot notation.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Both of these will work the same way:
|
|
85
|
+
* normalizeMongoFilter({ "location.countryId": "240" })
|
|
86
|
+
* normalizeMongoFilter({ location: { countryId: "240" } })
|
|
87
|
+
* // Both return: { "location.countryId": "240" }
|
|
88
|
+
* ```
|
|
41
89
|
*/
|
|
42
|
-
export declare function
|
|
90
|
+
export declare function normalizeMongoFilter<T extends Record<string, unknown>>(filter: T): T;
|
|
@@ -1,55 +1,91 @@
|
|
|
1
|
-
import { isArray as i,
|
|
2
|
-
var
|
|
3
|
-
for (var
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
return
|
|
9
|
-
},
|
|
10
|
-
function
|
|
1
|
+
import { isArray as i, mergeWith as y } from "lodash-es";
|
|
2
|
+
var d = Object.defineProperty, m = Object.defineProperties, v = Object.getOwnPropertyDescriptors, u = Object.getOwnPropertySymbols, b = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, a = (r, e, n) => e in r ? d(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n, f = (r, e) => {
|
|
3
|
+
for (var n in e || (e = {}))
|
|
4
|
+
b.call(e, n) && a(r, n, e[n]);
|
|
5
|
+
if (u)
|
|
6
|
+
for (var n of u(e))
|
|
7
|
+
_.call(e, n) && a(r, n, e[n]);
|
|
8
|
+
return r;
|
|
9
|
+
}, c = (r, e) => m(r, v(e));
|
|
10
|
+
function j(r) {
|
|
11
11
|
try {
|
|
12
|
-
return JSON.parse(
|
|
13
|
-
} catch (
|
|
12
|
+
return JSON.parse(r), !0;
|
|
13
|
+
} catch (e) {
|
|
14
14
|
return !1;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
21
|
-
},
|
|
17
|
+
function w(r, e) {
|
|
18
|
+
return e.reduce((n, o) => {
|
|
19
|
+
if (n && typeof n == "object" && o in n)
|
|
20
|
+
return n[o];
|
|
21
|
+
}, r);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
26
|
-
const [
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
29
|
-
[
|
|
23
|
+
function O(r, e, n) {
|
|
24
|
+
if (e.length === 0)
|
|
25
|
+
return r;
|
|
26
|
+
const [o, ...t] = e;
|
|
27
|
+
if (t.length === 0)
|
|
28
|
+
return c(f({}, r), {
|
|
29
|
+
[o]: n
|
|
30
30
|
});
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
[
|
|
34
|
-
typeof
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
const s = r[o];
|
|
32
|
+
return c(f({}, r), {
|
|
33
|
+
[o]: O(
|
|
34
|
+
typeof s == "object" && s !== null ? s : {},
|
|
35
|
+
t,
|
|
36
|
+
n
|
|
37
37
|
)
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
-
function
|
|
40
|
+
function P(...r) {
|
|
41
|
+
if (r.length === 0)
|
|
42
|
+
return {};
|
|
43
|
+
const e = r.filter((t) => t != null).map((t) => typeof t != "object" ? {} : t);
|
|
44
|
+
if (e.length === 0)
|
|
45
|
+
return {};
|
|
46
|
+
if (e.length === 1)
|
|
47
|
+
return e[0];
|
|
41
48
|
if (e.every(i))
|
|
42
49
|
return [].concat(...e);
|
|
43
|
-
if (e.every(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
if (e.every(
|
|
51
|
+
(t) => typeof t == "object" && t !== null && !i(t)
|
|
52
|
+
))
|
|
53
|
+
return y({}, ...e, (t, s) => {
|
|
54
|
+
if (i(t) && i(s))
|
|
55
|
+
return t.concat(s);
|
|
47
56
|
});
|
|
48
|
-
|
|
57
|
+
if (e.every((t) => typeof t != "object" || t === null))
|
|
58
|
+
throw new Error(
|
|
59
|
+
"deepMerge: Cannot merge primitive values. All arguments must be objects or arrays."
|
|
60
|
+
);
|
|
61
|
+
const n = e.some(i), o = e.some(
|
|
62
|
+
(t) => typeof t == "object" && t !== null && !i(t)
|
|
63
|
+
);
|
|
64
|
+
throw n && o ? new Error(
|
|
65
|
+
"deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."
|
|
66
|
+
) : new Error(
|
|
67
|
+
"deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type."
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function h(r) {
|
|
71
|
+
if (!r || typeof r != "object")
|
|
72
|
+
return r;
|
|
73
|
+
const e = {};
|
|
74
|
+
for (const [n, o] of Object.entries(r))
|
|
75
|
+
if (o && typeof o == "object" && !Array.isArray(o)) {
|
|
76
|
+
const t = h(o);
|
|
77
|
+
for (const [s, l] of Object.entries(t)) {
|
|
78
|
+
const p = `${n}.${s}`;
|
|
79
|
+
e[p] = l;
|
|
80
|
+
}
|
|
81
|
+
} else
|
|
82
|
+
e[n] = o;
|
|
83
|
+
return e;
|
|
49
84
|
}
|
|
50
85
|
export {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
86
|
+
P as deepMerge,
|
|
87
|
+
w as getNestedValue,
|
|
88
|
+
j as isJSON,
|
|
89
|
+
h as normalizeMongoFilter,
|
|
90
|
+
O as setNestedValue
|
|
55
91
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyberskill/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.6.0",
|
|
5
5
|
"description": "CyberSkill Shared",
|
|
6
6
|
"author": "Stephen Cheng",
|
|
7
7
|
"license": "MIT",
|
|
@@ -208,11 +208,11 @@
|
|
|
208
208
|
},
|
|
209
209
|
"dependencies": {
|
|
210
210
|
"@antfu/eslint-config": "5.0.0",
|
|
211
|
-
"@apollo/client": "3.13.
|
|
212
|
-
"@apollo/client-integration-nextjs": "0.12.
|
|
211
|
+
"@apollo/client": "3.13.9",
|
|
212
|
+
"@apollo/client-integration-nextjs": "0.12.3",
|
|
213
213
|
"@apollo/server": "5.0.0",
|
|
214
214
|
"@as-integrations/express5": "1.1.2",
|
|
215
|
-
"@dotenvx/dotenvx": "1.48.
|
|
215
|
+
"@dotenvx/dotenvx": "1.48.4",
|
|
216
216
|
"@eddeee888/gcg-typescript-resolver-files": "0.12.1",
|
|
217
217
|
"@eslint-react/eslint-plugin": "1.52.3",
|
|
218
218
|
"@graphql-codegen/cli": "5.0.7",
|
|
@@ -249,15 +249,15 @@
|
|
|
249
249
|
"lodash-es": "4.17.21",
|
|
250
250
|
"migrate-mongo": "12.1.3",
|
|
251
251
|
"mongodb": "6.18.0",
|
|
252
|
-
"mongoose": "8.
|
|
252
|
+
"mongoose": "8.17.0",
|
|
253
253
|
"mongoose-aggregate-paginate-v2": "1.1.4",
|
|
254
254
|
"mongoose-paginate-v2": "1.9.1",
|
|
255
255
|
"next-intl": "4.3.4",
|
|
256
256
|
"node-fetch": "3.3.2",
|
|
257
257
|
"node-persist": "4.0.4",
|
|
258
258
|
"qs": "6.14.0",
|
|
259
|
-
"react": "19.1.
|
|
260
|
-
"react-dom": "19.1.
|
|
259
|
+
"react": "19.1.1",
|
|
260
|
+
"react-dom": "19.1.1",
|
|
261
261
|
"react-hot-toast": "2.5.2",
|
|
262
262
|
"react-i18next": "15.6.1",
|
|
263
263
|
"slugify": "1.6.6",
|
|
@@ -271,7 +271,7 @@
|
|
|
271
271
|
"@commitlint/cli": "19.8.1",
|
|
272
272
|
"@commitlint/config-conventional": "19.8.1",
|
|
273
273
|
"@eslint/config-inspector": "1.1.0",
|
|
274
|
-
"@next/eslint-plugin-next": "15.4.
|
|
274
|
+
"@next/eslint-plugin-next": "15.4.5",
|
|
275
275
|
"@testing-library/jest-dom": "6.6.4",
|
|
276
276
|
"@testing-library/react": "16.3.0",
|
|
277
277
|
"@types/apollo-upload-client": "18.0.0",
|
|
@@ -289,15 +289,15 @@
|
|
|
289
289
|
"@types/migrate-mongo": "10.0.5",
|
|
290
290
|
"@types/node": "24.1.0",
|
|
291
291
|
"@types/node-persist": "3.1.8",
|
|
292
|
-
"@types/react": "19.1.
|
|
293
|
-
"@types/react-dom": "19.1.
|
|
292
|
+
"@types/react": "19.1.9",
|
|
293
|
+
"@types/react-dom": "19.1.7",
|
|
294
294
|
"@types/unorm": "1.3.31",
|
|
295
295
|
"@types/uuid": "10.0.0",
|
|
296
296
|
"@types/ws": "8.18.1",
|
|
297
297
|
"@types/yargs": "17.0.33",
|
|
298
298
|
"@vitest/browser": "3.2.4",
|
|
299
299
|
"eslint": "9.32.0",
|
|
300
|
-
"eslint-config-next": "15.4.
|
|
300
|
+
"eslint-config-next": "15.4.5",
|
|
301
301
|
"glob": "11.0.3",
|
|
302
302
|
"lint-staged": "16.1.2",
|
|
303
303
|
"node-modules-inspector": "1.0.0",
|