@pawells/typescript-common 2.1.5 → 2.1.6
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/README.md +22 -1
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.d.ts.map +1 -1
- package/dist/array/index.js +1 -0
- package/dist/array/iterators.d.ts +40 -0
- package/dist/array/iterators.d.ts.map +1 -0
- package/dist/array/iterators.js +54 -0
- package/dist/asserts/generic.d.ts +1 -1
- package/dist/asserts/generic.d.ts.map +1 -1
- package/dist/asserts/generic.js +8 -2
- package/dist/asserts/utils.d.ts.map +1 -1
- package/dist/asserts/utils.js +2 -3
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.d.ts.map +1 -1
- package/dist/enum/index.js +1 -1
- package/dist/function/memoize.d.ts +13 -0
- package/dist/function/memoize.d.ts.map +1 -1
- package/dist/function/memoize.js +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/json.sanitization.d.ts +14 -0
- package/dist/json.sanitization.d.ts.map +1 -0
- package/dist/json.sanitization.js +37 -0
- package/dist/object/clone.d.ts +6 -0
- package/dist/object/clone.d.ts.map +1 -1
- package/dist/object/clone.js +7 -1
- package/dist/object/filter-cached.d.ts +0 -18
- package/dist/object/filter-cached.d.ts.map +1 -1
- package/dist/object/filter-cached.js +0 -18
- package/dist/object/filter.d.ts.map +1 -1
- package/dist/object/filter.js +10 -1
- package/dist/object/hash.js +2 -2
- package/dist/object/index.d.ts +1 -1
- package/dist/object/index.d.ts.map +1 -1
- package/dist/object/object-flatten.js +4 -0
- package/dist/object/property-paths.d.ts +2 -0
- package/dist/object/property-paths.d.ts.map +1 -1
- package/dist/object/property-paths.js +2 -0
- package/dist/object/security-utils.d.ts.map +1 -1
- package/dist/object/security-utils.js +8 -1
- package/dist/object/sort-keys.d.ts +14 -0
- package/dist/object/sort-keys.d.ts.map +1 -1
- package/dist/object/sort-keys.js +14 -0
- package/dist/object/types.d.ts +0 -102
- package/dist/object/types.d.ts.map +1 -1
- package/dist/string/assert.d.ts +19 -0
- package/dist/string/assert.d.ts.map +1 -1
- package/dist/string/assert.js +19 -0
- package/dist/time/elapsed-time/elapsed-time.d.ts +7 -7
- package/dist/time/elapsed-time/elapsed-time.js +25 -25
- package/dist/time/index.d.ts +1 -3
- package/dist/time/index.d.ts.map +1 -1
- package/dist/time/index.js +0 -3
- package/dist/time/stopwatch/stopwatch.d.ts +18 -0
- package/dist/time/stopwatch/stopwatch.d.ts.map +1 -1
- package/dist/time/stopwatch/stopwatch.js +23 -0
- package/dist/zod-util.d.ts +145 -0
- package/dist/zod-util.d.ts.map +1 -0
- package/dist/zod-util.js +126 -0
- package/package.json +65 -58
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @pawells/typescript-common
|
|
2
2
|
|
|
3
|
-
[](https://github.com/PhillipAWells/common/actions/workflows/ci.yml)
|
|
4
4
|
[](https://nodejs.org)
|
|
5
5
|
[](https://www.npmjs.com/package/@pawells/typescript-common)
|
|
6
6
|
[](./LICENSE)
|
|
@@ -409,6 +409,27 @@ console.log(stopwatch.elapsed().toString()); // Duration of work
|
|
|
409
409
|
| `Stopwatch` | Utility for recording timestamped events and intervals |
|
|
410
410
|
| `StopwatchEntry` | Represents single stopwatch event (start, stop, lap, etc.) |
|
|
411
411
|
|
|
412
|
+
### Iterators
|
|
413
|
+
|
|
414
|
+
| Symbol | Description |
|
|
415
|
+
|--------|-------------|
|
|
416
|
+
| `FilteredIterator` | Async generator that filters array elements based on a predicate and optional filter criteria |
|
|
417
|
+
|
|
418
|
+
### Zod Utilities
|
|
419
|
+
|
|
420
|
+
Pre-built Zod schemas and types for common runtime validation scenarios.
|
|
421
|
+
|
|
422
|
+
| Symbol | Description |
|
|
423
|
+
|--------|-------------|
|
|
424
|
+
| `OBJECT_ID_SCHEMA` | Zod schema for MongoDB ObjectId validation (24-char hex string) |
|
|
425
|
+
| `TObjectId` | Type inferred from OBJECT_ID_SCHEMA; represents valid ObjectId string |
|
|
426
|
+
| `SEMVER_SCHEMA` | Zod schema for semantic version validation; transforms to SemVer instance |
|
|
427
|
+
| `TZodObjectSchema` | Type for Zod object schema instances; result of z.object() |
|
|
428
|
+
| `JSON_SERIALIZABLE_SCHEMA` | Zod schema for generic JSON-serializable values (primitives, arrays, objects) |
|
|
429
|
+
| `TJSONSerializable` | Recursive type for JSON-serializable values (excludes undefined and functions) |
|
|
430
|
+
| `JSON_OBJECT_SCHEMA` | Zod schema for JSON objects with string keys and serializable values |
|
|
431
|
+
| `JSON_DATE_SCHEMA` | Zod schema for date strings; transforms to Date instances |
|
|
432
|
+
|
|
412
433
|
## License
|
|
413
434
|
|
|
414
435
|
MIT — See [LICENSE](../../LICENSE) for details.
|
package/dist/array/index.d.ts
CHANGED
|
@@ -25,4 +25,5 @@ export * from './array-sample.js';
|
|
|
25
25
|
export type * from './array-element.js';
|
|
26
26
|
export type { TPredicate, TTransform, TComparator, TEqualityComparator } from './types.js';
|
|
27
27
|
export * from './assert.js';
|
|
28
|
+
export * from './iterators.js';
|
|
28
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,mBAAmB,oBAAoB,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3F,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/array/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,mBAAmB,oBAAoB,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3F,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
|
package/dist/array/index.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async generator function that filters array elements based on a predicate and optional filter criteria.
|
|
3
|
+
*
|
|
4
|
+
* Yields only elements that pass both the optional validator function and the filter criteria object.
|
|
5
|
+
* This is useful for streaming large datasets through memory-efficient async iteration.
|
|
6
|
+
*
|
|
7
|
+
* @template TObject The type of elements in the iterator
|
|
8
|
+
* @template TArgs The type of filter criteria object (extends Record<string, unknown>)
|
|
9
|
+
*
|
|
10
|
+
* @param iterator The async iterable to filter
|
|
11
|
+
* @param args Optional filter criteria object; if provided, only elements matching all criteria are yielded
|
|
12
|
+
* @param validator Optional predicate function returning true for elements to keep; called before filter criteria
|
|
13
|
+
*
|
|
14
|
+
* @returns {AsyncGenerator<TObject, void, unknown>} Async generator that yields filtered elements
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Elements are evaluated one at a time without batching. The validator is applied first; if it rejects
|
|
18
|
+
* an element, the filter criteria are not evaluated. If no args are provided, all elements (passing the
|
|
19
|
+
* validator if present) are passed through unchanged.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* async function* items() {
|
|
23
|
+
* yield { id: 1, status: 'active' };
|
|
24
|
+
* yield { id: 2, status: 'inactive' };
|
|
25
|
+
* yield { id: 3, status: 'active' };
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* for await (const item of FilteredIterator(items(), { status: 'active' })) {
|
|
29
|
+
* console.log(item); // Only logs items with status: 'active'
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* for await (const item of FilteredIterator(items(), undefined, (obj) => obj.id > 1)) {
|
|
34
|
+
* console.log(item); // Only logs items with id > 1
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* @throws {TypeError} if iterator is null or undefined
|
|
38
|
+
*/
|
|
39
|
+
export declare function FilteredIterator<TObject, TArgs extends Record<string, unknown>>(iterator: AsyncIterable<TObject>, args?: TArgs, validator?: (obj: TObject) => boolean): AsyncGenerator<TObject, void, unknown>;
|
|
40
|
+
//# sourceMappingURL=iterators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterators.d.ts","sourceRoot":"","sources":["../../src/array/iterators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAuB,gBAAgB,CAAC,OAAO,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAcrN"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ObjectFilter } from '../object/filter.js';
|
|
2
|
+
/**
|
|
3
|
+
* Async generator function that filters array elements based on a predicate and optional filter criteria.
|
|
4
|
+
*
|
|
5
|
+
* Yields only elements that pass both the optional validator function and the filter criteria object.
|
|
6
|
+
* This is useful for streaming large datasets through memory-efficient async iteration.
|
|
7
|
+
*
|
|
8
|
+
* @template TObject The type of elements in the iterator
|
|
9
|
+
* @template TArgs The type of filter criteria object (extends Record<string, unknown>)
|
|
10
|
+
*
|
|
11
|
+
* @param iterator The async iterable to filter
|
|
12
|
+
* @param args Optional filter criteria object; if provided, only elements matching all criteria are yielded
|
|
13
|
+
* @param validator Optional predicate function returning true for elements to keep; called before filter criteria
|
|
14
|
+
*
|
|
15
|
+
* @returns {AsyncGenerator<TObject, void, unknown>} Async generator that yields filtered elements
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Elements are evaluated one at a time without batching. The validator is applied first; if it rejects
|
|
19
|
+
* an element, the filter criteria are not evaluated. If no args are provided, all elements (passing the
|
|
20
|
+
* validator if present) are passed through unchanged.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* async function* items() {
|
|
24
|
+
* yield { id: 1, status: 'active' };
|
|
25
|
+
* yield { id: 2, status: 'inactive' };
|
|
26
|
+
* yield { id: 3, status: 'active' };
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* for await (const item of FilteredIterator(items(), { status: 'active' })) {
|
|
30
|
+
* console.log(item); // Only logs items with status: 'active'
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* for await (const item of FilteredIterator(items(), undefined, (obj) => obj.id > 1)) {
|
|
35
|
+
* console.log(item); // Only logs items with id > 1
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* @throws {TypeError} if iterator is null or undefined
|
|
39
|
+
*/
|
|
40
|
+
export async function* FilteredIterator(iterator, args, validator) {
|
|
41
|
+
for await (const obj of iterator) {
|
|
42
|
+
// Validate entity before filtering/yielding
|
|
43
|
+
if (validator && !validator(obj))
|
|
44
|
+
continue;
|
|
45
|
+
// If no filter args provided, pass through all events
|
|
46
|
+
if (!args || typeof args !== 'object' || Object.keys(args).length === 0) {
|
|
47
|
+
yield obj;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// Apply filter criteria
|
|
51
|
+
if (ObjectFilter(obj, args))
|
|
52
|
+
yield obj;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -9,7 +9,7 @@ import { SimpleError } from './errors.js';
|
|
|
9
9
|
* - Handling non-serializable values gracefully
|
|
10
10
|
*
|
|
11
11
|
* @param value - The value to serialize for display
|
|
12
|
-
* @param maxLength - Maximum characters to display for primitives (default:
|
|
12
|
+
* @param maxLength - Maximum characters to display for primitives (default: 100, capped at 10,000)
|
|
13
13
|
* @returns A safe string representation (at most maxLength chars plus "[truncated]" suffix)
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/asserts/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/asserts/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE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,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAU9I;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAOjI;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAOtG;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,aAAa,CAAC,OAAO,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,IAAI,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAqBvK"}
|
package/dist/asserts/generic.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { ObjectEquals } from './internal-utils.js';
|
|
2
2
|
import { SetExceptionClass, SetExceptionMessage, ThrowException } from './utils.js';
|
|
3
3
|
import { AssertionError, SimpleError } from './errors.js';
|
|
4
|
+
/**
|
|
5
|
+
* Maximum length for safe value display in assertion error messages.
|
|
6
|
+
* Prevents verbose output and potential information disclosure.
|
|
7
|
+
*/
|
|
8
|
+
const MAX_SAFE_DISPLAY_LENGTH = 100;
|
|
4
9
|
/**
|
|
5
10
|
* Serializes a value to a human-readable string, safe for any value type.
|
|
6
11
|
*
|
|
@@ -10,7 +15,7 @@ import { AssertionError, SimpleError } from './errors.js';
|
|
|
10
15
|
* - Handling non-serializable values gracefully
|
|
11
16
|
*
|
|
12
17
|
* @param value - The value to serialize for display
|
|
13
|
-
* @param maxLength - Maximum characters to display for primitives (default:
|
|
18
|
+
* @param maxLength - Maximum characters to display for primitives (default: 100, capped at 10,000)
|
|
14
19
|
* @returns A safe string representation (at most maxLength chars plus "[truncated]" suffix)
|
|
15
20
|
*
|
|
16
21
|
* @example
|
|
@@ -20,7 +25,7 @@ import { AssertionError, SimpleError } from './errors.js';
|
|
|
20
25
|
*
|
|
21
26
|
* @internal Used internally by assertion functions to safely display values in error messages
|
|
22
27
|
*/
|
|
23
|
-
export function safeDisplay(value, maxLength =
|
|
28
|
+
export function safeDisplay(value, maxLength = MAX_SAFE_DISPLAY_LENGTH) {
|
|
24
29
|
// Cap maxLength to prevent memory exhaustion from extremely large values
|
|
25
30
|
const effectiveMaxLength = Math.min(maxLength, 10_000);
|
|
26
31
|
// For objects, use type name instead of full serialization to avoid leaking structure
|
|
@@ -203,6 +208,7 @@ export class ExtendsError extends SimpleError {
|
|
|
203
208
|
* }); // ✗ Throws with custom message
|
|
204
209
|
* ```
|
|
205
210
|
*/
|
|
211
|
+
// @internal — Do not import from this module directly. Use asserts/index.ts instead.
|
|
206
212
|
export function AssertEquals(value, expected, exception = {}) {
|
|
207
213
|
SetExceptionClass(exception, AssertionError);
|
|
208
214
|
if (!ObjectEquals(value, expected)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/asserts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAInD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/asserts/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAInD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAIhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,UAAQ,GAAG,IAAI,CAGpH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,IAAI,CAGrG;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC9B,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,EAClE,SAAS,EAAE,gBAAgB,GACzB,OAAO,CAAC,KAAK,CAuCf"}
|
package/dist/asserts/utils.js
CHANGED
|
@@ -29,9 +29,8 @@ import { safeDisplay, GetValueType } from './generic.js';
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
export function ThrowException(exception) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
32
|
+
// exception.class is always set by SetExceptionClass before this is called
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
34
|
throw new exception.class(exception.message ?? 'An assertion error occurred');
|
|
36
35
|
}
|
|
37
36
|
/**
|
package/dist/enum/index.d.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module enum
|
|
9
9
|
*/
|
|
10
|
-
export * from './types.js';
|
|
11
10
|
export * from './enum-keys.js';
|
|
12
11
|
export * from './enum-values.js';
|
|
13
12
|
export * from './enum-entries.js';
|
|
14
13
|
export * from './validate-enum-value.js';
|
|
15
14
|
export * from './enum-key-by-value.js';
|
|
16
15
|
export * from './enum-safe-value.js';
|
|
16
|
+
export * from './types.js';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/enum/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enum/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enum/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC"}
|
package/dist/enum/index.js
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module enum
|
|
9
9
|
*/
|
|
10
|
-
export * from './types.js';
|
|
11
10
|
export * from './enum-keys.js';
|
|
12
11
|
export * from './enum-values.js';
|
|
13
12
|
export * from './enum-entries.js';
|
|
14
13
|
export * from './validate-enum-value.js';
|
|
15
14
|
export * from './enum-key-by-value.js';
|
|
16
15
|
export * from './enum-safe-value.js';
|
|
16
|
+
export * from './types.js';
|
|
@@ -39,5 +39,18 @@
|
|
|
39
39
|
* console.log(cachedAdd(1, 2)); // Returns cached result: 3
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
+
/**
|
|
43
|
+
* Memoizes a function using an LRU cache.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* - Default key function uses JSON.stringify(args)
|
|
47
|
+
* - Non-serializable arguments (functions, symbols, circular refs) will produce incorrect cache behavior
|
|
48
|
+
* - Supply a custom `keyFn` for non-serializable arguments or for content-addressed keys
|
|
49
|
+
*
|
|
50
|
+
* @param fn - The function to memoize
|
|
51
|
+
* @param keyFn - Optional custom cache key function; defaults to JSON.stringify(args)
|
|
52
|
+
* @param maxCacheSize - Maximum number of entries in the cache; defaults to 1000
|
|
53
|
+
* @returns Memoized version of the function
|
|
54
|
+
*/
|
|
42
55
|
export declare function Memoize<T extends (...args: any[]) => any>(fn: T, keyFn?: (...args: Parameters<T>) => string, maxCacheSize?: number): T;
|
|
43
56
|
//# sourceMappingURL=memoize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/function/memoize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,wBAAgB,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,EAC1C,YAAY,SAAO,GACjB,CAAC,CAkBH"}
|
|
1
|
+
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/function/memoize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH;;;;;;;;;;;;GAYG;AAEH,wBAAgB,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,MAAM,EAC1C,YAAY,SAAO,GACjB,CAAC,CAkBH"}
|
package/dist/function/memoize.js
CHANGED
|
@@ -40,6 +40,19 @@ import { LRUCache } from '../lru-cache.js';
|
|
|
40
40
|
* console.log(cachedAdd(1, 2)); // Returns cached result: 3
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
+
/**
|
|
44
|
+
* Memoizes a function using an LRU cache.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* - Default key function uses JSON.stringify(args)
|
|
48
|
+
* - Non-serializable arguments (functions, symbols, circular refs) will produce incorrect cache behavior
|
|
49
|
+
* - Supply a custom `keyFn` for non-serializable arguments or for content-addressed keys
|
|
50
|
+
*
|
|
51
|
+
* @param fn - The function to memoize
|
|
52
|
+
* @param keyFn - Optional custom cache key function; defaults to JSON.stringify(args)
|
|
53
|
+
* @param maxCacheSize - Maximum number of entries in the cache; defaults to 1000
|
|
54
|
+
* @returns Memoized version of the function
|
|
55
|
+
*/
|
|
43
56
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
57
|
export function Memoize(fn, keyFn, maxCacheSize = 1000) {
|
|
45
58
|
const cache = new LRUCache(maxCacheSize);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,7 @@ export * from './number/index.js';
|
|
|
8
8
|
export * from './object/index.js';
|
|
9
9
|
export * from './string/index.js';
|
|
10
10
|
export * from './time/index.js';
|
|
11
|
+
export * from './array/iterators.js';
|
|
12
|
+
export * from './json.sanitization.js';
|
|
13
|
+
export * from './zod-util.js';
|
|
11
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes a JSON Schema object by recursively removing all keys that start with "$".
|
|
3
|
+
* This prevents Mongoose Map field errors when storing JSON Schema definitions with
|
|
4
|
+
* metadata properties like $schema, $id, $defs, etc.
|
|
5
|
+
*
|
|
6
|
+
* @param schema - The JSON Schema object to sanitize
|
|
7
|
+
* @returns The sanitized schema object with all "$"-prefixed keys removed
|
|
8
|
+
* @example
|
|
9
|
+
* const schema = { type: 'object', $schema: 'http://...', properties: { ... } };
|
|
10
|
+
* const clean = SanitizeJsonSchema(schema);
|
|
11
|
+
* // Result: { type: 'object', properties: { ... } }
|
|
12
|
+
*/
|
|
13
|
+
export declare function SanitizeJsonSchema(schema: unknown): Record<string, unknown>;
|
|
14
|
+
//# sourceMappingURL=json.sanitization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.sanitization.d.ts","sourceRoot":"","sources":["../src/json.sanitization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM3E"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes a JSON Schema object by recursively removing all keys that start with "$".
|
|
3
|
+
* This prevents Mongoose Map field errors when storing JSON Schema definitions with
|
|
4
|
+
* metadata properties like $schema, $id, $defs, etc.
|
|
5
|
+
*
|
|
6
|
+
* @param schema - The JSON Schema object to sanitize
|
|
7
|
+
* @returns The sanitized schema object with all "$"-prefixed keys removed
|
|
8
|
+
* @example
|
|
9
|
+
* const schema = { type: 'object', $schema: 'http://...', properties: { ... } };
|
|
10
|
+
* const clean = SanitizeJsonSchema(schema);
|
|
11
|
+
* // Result: { type: 'object', properties: { ... } }
|
|
12
|
+
*/
|
|
13
|
+
export function SanitizeJsonSchema(schema) {
|
|
14
|
+
const result = sanitizeJsonSchemaInternal(schema);
|
|
15
|
+
if (typeof result === 'object' && result !== null && !Array.isArray(result)) {
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
function sanitizeJsonSchemaInternal(schema) {
|
|
21
|
+
if (schema === null || schema === undefined) {
|
|
22
|
+
return schema;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(schema)) {
|
|
25
|
+
return schema.map((item) => sanitizeJsonSchemaInternal(item));
|
|
26
|
+
}
|
|
27
|
+
if (typeof schema !== 'object') {
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
const cleanSchema = {};
|
|
31
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
32
|
+
if (!key.startsWith('$')) {
|
|
33
|
+
cleanSchema[key] = sanitizeJsonSchemaInternal(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return cleanSchema;
|
|
37
|
+
}
|
package/dist/object/clone.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ import type { TObjectTransformer } from './types.js';
|
|
|
21
21
|
* clone.b.c = 99;
|
|
22
22
|
* console.log(original.b.c); // 2 (original is not affected)
|
|
23
23
|
* ```
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const nullProtoObj = Object.create(null);
|
|
27
|
+
* nullProtoObj.x = 1;
|
|
28
|
+
* const cloned = ObjectClone(nullProtoObj); // Works correctly even for null-prototype objects
|
|
29
|
+
* ```
|
|
24
30
|
*/
|
|
25
31
|
export declare function ObjectClone<T>(obj: T, visitedInput?: WeakSet<object>): T;
|
|
26
32
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/object/clone.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD
|
|
1
|
+
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/object/clone.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAkExE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,eAAe,CAAC,MAAM,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,EAC5E,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9C,OAAO,CAMT"}
|
package/dist/object/clone.js
CHANGED
|
@@ -21,6 +21,12 @@ import { FilterDangerousKeys } from './security-utils.js';
|
|
|
21
21
|
* clone.b.c = 99;
|
|
22
22
|
* console.log(original.b.c); // 2 (original is not affected)
|
|
23
23
|
* ```
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const nullProtoObj = Object.create(null);
|
|
27
|
+
* nullProtoObj.x = 1;
|
|
28
|
+
* const cloned = ObjectClone(nullProtoObj); // Works correctly even for null-prototype objects
|
|
29
|
+
* ```
|
|
24
30
|
*/
|
|
25
31
|
export function ObjectClone(obj, visitedInput) {
|
|
26
32
|
if (obj === null || obj === undefined) {
|
|
@@ -56,7 +62,7 @@ export function ObjectClone(obj, visitedInput) {
|
|
|
56
62
|
return result;
|
|
57
63
|
}
|
|
58
64
|
// Handle plain objects only
|
|
59
|
-
if (obj
|
|
65
|
+
if (Object.getPrototypeOf(obj) === null || obj.constructor === Object) {
|
|
60
66
|
// Security: Filter out dangerous keys
|
|
61
67
|
const safeObj = FilterDangerousKeys(obj);
|
|
62
68
|
const copy = {};
|
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
import type { ICachedObjectFilterOptions, TCachedObjectFilterFunction } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a cached version of {@link ObjectFilter} for improved performance
|
|
4
|
-
* when filtering the same objects repeatedly.
|
|
5
|
-
*
|
|
6
|
-
* Results are cached by hashing the filter and object together. When the cache
|
|
7
|
-
* exceeds `maxCacheSize`, approximately 20% of the entries in the largest
|
|
8
|
-
* per-filter bucket are evicted.
|
|
9
|
-
*
|
|
10
|
-
* @template T - The object type being filtered
|
|
11
|
-
* @param options - Configuration for both the cache and the underlying filter
|
|
12
|
-
* @returns A cached filter function `(cursor, filter) => Promise<boolean>`
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const cachedFilter = ObjectFilterCached<User>({ maxCacheSize: 500 });
|
|
17
|
-
* const isAdmin = await cachedFilter(user, { role: 'admin' });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
2
|
/**
|
|
21
3
|
* Creates a cached version of {@link ObjectFilter} for improved performance
|
|
22
4
|
* when filtering the same objects repeatedly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter-cached.d.ts","sourceRoot":"","sources":["../../src/object/filter-cached.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,2BAA2B,EAAwB,MAAM,YAAY,CAAC;AAMhH
|
|
1
|
+
{"version":3,"file":"filter-cached.d.ts","sourceRoot":"","sources":["../../src/object/filter-cached.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,2BAA2B,EAAwB,MAAM,YAAY,CAAC;AAMhH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,2BAA2B,CAAC,CAAC,CAAC,CAmI7H"}
|
|
@@ -3,24 +3,6 @@ import { ObjectHash } from './hash.js';
|
|
|
3
3
|
// Cache configuration constants
|
|
4
4
|
const DEFAULT_MAX_CACHE_SIZE = 1000;
|
|
5
5
|
const CACHE_EVICTION_PERCENTAGE = 0.2; // 20%
|
|
6
|
-
/**
|
|
7
|
-
* Creates a cached version of {@link ObjectFilter} for improved performance
|
|
8
|
-
* when filtering the same objects repeatedly.
|
|
9
|
-
*
|
|
10
|
-
* Results are cached by hashing the filter and object together. When the cache
|
|
11
|
-
* exceeds `maxCacheSize`, approximately 20% of the entries in the largest
|
|
12
|
-
* per-filter bucket are evicted.
|
|
13
|
-
*
|
|
14
|
-
* @template T - The object type being filtered
|
|
15
|
-
* @param options - Configuration for both the cache and the underlying filter
|
|
16
|
-
* @returns A cached filter function `(cursor, filter) => Promise<boolean>`
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const cachedFilter = ObjectFilterCached<User>({ maxCacheSize: 500 });
|
|
21
|
-
* const isAdmin = await cachedFilter(user, { role: 'admin' });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
6
|
/**
|
|
25
7
|
* Creates a cached version of {@link ObjectFilter} for improved performance
|
|
26
8
|
* when filtering the same objects repeatedly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/object/filter.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/object/filter.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmGxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAyCvH;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAiBhG"}
|
package/dist/object/filter.js
CHANGED
|
@@ -2,6 +2,15 @@ import { ObjectEquals } from './equals.js';
|
|
|
2
2
|
import { IsPropertyPathSafe } from './security-utils.js';
|
|
3
3
|
import { ObjectGetPropertyByPath } from './property-paths.js';
|
|
4
4
|
import { StringEquals } from '../string/comparison.js';
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to safely identify a filter predicate function.
|
|
7
|
+
*
|
|
8
|
+
* @param v - The value to check
|
|
9
|
+
* @returns True if the value is a function that can be used as a filter predicate
|
|
10
|
+
*/
|
|
11
|
+
function isFilterPredicate(v) {
|
|
12
|
+
return typeof v === 'function';
|
|
13
|
+
}
|
|
5
14
|
/**
|
|
6
15
|
* Compares two values for ObjectFilter with support for predicates, case-insensitive strings,
|
|
7
16
|
* and deep equality via ObjectEquals.
|
|
@@ -14,7 +23,7 @@ import { StringEquals } from '../string/comparison.js';
|
|
|
14
23
|
*/
|
|
15
24
|
function compareValuesForFilter(objValue, filterValue, caseInsensitiveStrings = false, useDeepEqual = false) {
|
|
16
25
|
// Handle function as predicate
|
|
17
|
-
if (
|
|
26
|
+
if (isFilterPredicate(filterValue)) {
|
|
18
27
|
return filterValue(objValue);
|
|
19
28
|
}
|
|
20
29
|
// Handle case-insensitive string comparison (filter-specific feature)
|
package/dist/object/hash.js
CHANGED
|
@@ -69,9 +69,9 @@ export function ObjectHash(obj, hashFunction) {
|
|
|
69
69
|
}
|
|
70
70
|
catch (e) {
|
|
71
71
|
if (e instanceof TypeError && e.message.includes('circular')) {
|
|
72
|
-
throw new Error('Cannot hash object with circular references');
|
|
72
|
+
throw new Error('Cannot hash object with circular references', { cause: e });
|
|
73
73
|
}
|
|
74
|
-
throw new Error('Cannot hash object: JSON.stringify failed');
|
|
74
|
+
throw new Error('Cannot hash object: JSON.stringify failed', { cause: e });
|
|
75
75
|
}
|
|
76
76
|
// Handle cases where JSON.stringify returns undefined
|
|
77
77
|
if (jsonString === undefined) {
|
package/dist/object/index.d.ts
CHANGED
|
@@ -29,6 +29,6 @@ export { ObjectFlatten } from './object-flatten.js';
|
|
|
29
29
|
export { ObjectDiff } from './object-diff.js';
|
|
30
30
|
export { AssertObject, ObjectError, ObjectPropertyError, AssertObjectHasProperty, AssertObjectHasOwnProperty, AssertObjectPropertyNotNull } from './assert.js';
|
|
31
31
|
export type { IObjectDiffResult } from './object-diff.js';
|
|
32
|
-
export type {
|
|
32
|
+
export type { TCachedObjectFilterFunction, TCachedObjectMapperFunction, TObjectPredicate, TObjectTransformer, TObjectComparator, TObjectEqualityComparator, TPropertyMapper, TPropertyFilter } from './types.js';
|
|
33
33
|
export type { IObjectFilterOptions, ICachedObjectFilterOptions, ICachedObjectMapOptions } from './types.js';
|
|
34
34
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/object/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,0BAA0B,EAAE,M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CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC/J,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,YAAY,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGjN,YAAY,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
export function ObjectFlatten(obj, separator = '.') {
|
|
22
22
|
return flattenRecursive(obj, separator, '');
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @internal Recursion helper; not part of the public API.
|
|
26
|
+
* @param prefix - Accumulated key prefix from parent recursion level
|
|
27
|
+
*/
|
|
24
28
|
function flattenRecursive(obj, separator, prefix) {
|
|
25
29
|
const result = {};
|
|
26
30
|
for (const key of Object.keys(obj)) {
|
|
@@ -68,6 +68,8 @@ export declare function ObjectGetPropertyByPath<T = unknown>(obj: unknown, path:
|
|
|
68
68
|
* @param obj - Target object to modify
|
|
69
69
|
* @param path - Path to the property using dot notation (e.g., 'user.address.street')
|
|
70
70
|
* @param value - Value to set at the specified path
|
|
71
|
+
* @throws Throws if `path` contains dangerous keys (`__proto__`, `constructor`, `prototype`)
|
|
72
|
+
* @throws Throws if `path` is invalid or contains non-string segments
|
|
71
73
|
*
|
|
72
74
|
* @example
|
|
73
75
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property-paths.d.ts","sourceRoot":"","sources":["../../src/object/property-paths.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAiChH;AAED
|
|
1
|
+
{"version":3,"file":"property-paths.d.ts","sourceRoot":"","sources":["../../src/object/property-paths.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAiChH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAyC/F"}
|
|
@@ -95,6 +95,8 @@ export function ObjectGetPropertyByPath(obj, path, defaultValue) {
|
|
|
95
95
|
* @param obj - Target object to modify
|
|
96
96
|
* @param path - Path to the property using dot notation (e.g., 'user.address.street')
|
|
97
97
|
* @param value - Value to set at the specified path
|
|
98
|
+
* @throws Throws if `path` contains dangerous keys (`__proto__`, `constructor`, `prototype`)
|
|
99
|
+
* @throws Throws if `path` is invalid or contains non-string segments
|
|
98
100
|
*
|
|
99
101
|
* @example
|
|
100
102
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security-utils.d.ts","sourceRoot":"","sources":["../../src/object/security-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"security-utils.d.ts","sourceRoot":"","sources":["../../src/object/security-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAsDH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAkBtD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAkBxD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO9D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAUzF;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,+BAA+B,IAAI,0BAA0B,CA6B5E;AAKD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,MAAiC,GAAG,OAAO,CAqBjG"}
|