@xylabs/object 5.0.83 → 5.0.84
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 +192 -0
- package/dist/neutral/AsObjectFactory.d.ts +1 -0
- package/dist/neutral/AsObjectFactory.d.ts.map +1 -1
- package/dist/neutral/AsTypeFactory.d.ts +4 -0
- package/dist/neutral/AsTypeFactory.d.ts.map +1 -1
- package/dist/neutral/IsObjectFactory.d.ts +8 -0
- package/dist/neutral/IsObjectFactory.d.ts.map +1 -1
- package/dist/neutral/JsonObject.d.ts +13 -0
- package/dist/neutral/JsonObject.d.ts.map +1 -1
- package/dist/neutral/ObjectWrapper.d.ts +1 -0
- package/dist/neutral/ObjectWrapper.d.ts.map +1 -1
- package/dist/neutral/OmitStartsWith.d.ts +4 -0
- package/dist/neutral/OmitStartsWith.d.ts.map +1 -1
- package/dist/neutral/Optional.d.ts +1 -0
- package/dist/neutral/Optional.d.ts.map +1 -1
- package/dist/neutral/Override.d.ts +1 -0
- package/dist/neutral/Override.d.ts.map +1 -1
- package/dist/neutral/PickStartsWith.d.ts +2 -0
- package/dist/neutral/PickStartsWith.d.ts.map +1 -1
- package/dist/neutral/Simplify.d.ts +1 -0
- package/dist/neutral/Simplify.d.ts.map +1 -1
- package/dist/neutral/StringKeyObject.d.ts +1 -0
- package/dist/neutral/StringKeyObject.d.ts.map +1 -1
- package/dist/neutral/Validator.d.ts +2 -0
- package/dist/neutral/Validator.d.ts.map +1 -1
- package/dist/neutral/WithAdditional.d.ts +1 -0
- package/dist/neutral/WithAdditional.d.ts.map +1 -1
- package/dist/neutral/asObject.d.ts +1 -0
- package/dist/neutral/asObject.d.ts.map +1 -1
- package/dist/neutral/index-un-deprecated.mjs +6 -0
- package/dist/neutral/index-un-deprecated.mjs.map +1 -1
- package/dist/neutral/index.mjs +6 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/omitBy.d.ts +15 -0
- package/dist/neutral/omitBy.d.ts.map +1 -1
- package/dist/neutral/pickBy.d.ts +15 -0
- package/dist/neutral/pickBy.d.ts.map +1 -1
- package/dist/neutral/removeFields.d.ts +6 -0
- package/dist/neutral/removeFields.d.ts.map +1 -1
- package/dist/neutral/toSafeJson.d.ts +34 -0
- package/dist/neutral/toSafeJson.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TypeCheck } from '@xylabs/object-model';
|
|
2
2
|
import type { TypedObject } from '@xylabs/typeof';
|
|
3
|
+
/** Factory for creating type-narrowing functions for TypedObject types. */
|
|
3
4
|
export declare const AsObjectFactory: {
|
|
4
5
|
create: <T extends TypedObject>(typeCheck: TypeCheck<T>) => import("@xylabs/object-model").AsTypeFunction<T>;
|
|
5
6
|
createOptional: <T extends TypedObject>(typeCheck: TypeCheck<T>) => (value: import("@xylabs/promise").AnyNonPromise) => T | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/AsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAIjD,eAAO,MAAM,eAAe;aACjB,CAAC,SAAS,WAAW,aAAa,SAAS,CAAC,CAAC,CAAC;qBAGtC,CAAC,SAAS,WAAW,aAAa,SAAS,CAAC,CAAC,CAAC;CAGhE,CAAA"}
|
|
1
|
+
{"version":3,"file":"AsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/AsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAIjD,2EAA2E;AAC3E,eAAO,MAAM,eAAe;aACjB,CAAC,SAAS,WAAW,aAAa,SAAS,CAAC,CAAC,CAAC;qBAGtC,CAAC,SAAS,WAAW,aAAa,SAAS,CAAC,CAAC,CAAC;CAGhE,CAAA"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { AsTypeFunction, TypeCheck } from '@xylabs/object-model';
|
|
2
2
|
import type { AnyNonPromise } from '@xylabs/promise';
|
|
3
|
+
/**
|
|
4
|
+
* Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.
|
|
5
|
+
* Supports optional assertion messages and configuration for required/optional behavior.
|
|
6
|
+
*/
|
|
3
7
|
export declare const AsTypeFactory: {
|
|
4
8
|
create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
|
|
5
9
|
createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsTypeFactory.d.ts","sourceRoot":"","sources":["../../src/AsTypeFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACS,SAAS,EAEjC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAIpD,eAAO,MAAM,aAAa;aACf,CAAC,SAAS,aAAa,aAAa,SAAS,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,CAAC,CAAC;qBAgC5D,CAAC,SAAS,aAAa,aAAa,SAAS,CAAC,CAAC,CAAC,aAC1C,aAAa,KAAG,CAAC,GAAG,SAAS;CASrD,CAAA"}
|
|
1
|
+
{"version":3,"file":"AsTypeFactory.d.ts","sourceRoot":"","sources":["../../src/AsTypeFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACS,SAAS,EAEjC,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAIpD;;;GAGG;AACH,eAAO,MAAM,aAAa;aACf,CAAC,SAAS,aAAa,aAAa,SAAS,CAAC,CAAC,CAAC,KAAG,cAAc,CAAC,CAAC,CAAC;qBAgC5D,CAAC,SAAS,aAAa,aAAa,SAAS,CAAC,CAAC,CAAC,aAC1C,aAAa,KAAG,CAAC,GAAG,SAAS;CASrD,CAAA"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import type { TypeCheck, TypeCheckConfig } from '@xylabs/object-model';
|
|
2
2
|
import { type ObjectTypeShape, type TypedObject } from '@xylabs/typeof';
|
|
3
|
+
/** Configuration options for object type checking. */
|
|
3
4
|
export interface ObjectTypeConfig extends TypeCheckConfig {
|
|
4
5
|
}
|
|
6
|
+
/** Factory class for creating type-guard functions that validate objects against a given shape and optional additional checks. */
|
|
5
7
|
export declare class IsObjectFactory<T extends TypedObject> {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a type-guard function that validates an object matches the given shape and passes additional checks.
|
|
10
|
+
* @param shape - An optional map of property names to expected types.
|
|
11
|
+
* @param additionalChecks - Optional extra type-check functions to run after shape validation.
|
|
12
|
+
* @returns A type-guard function for type T.
|
|
13
|
+
*/
|
|
6
14
|
create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T>;
|
|
7
15
|
}
|
|
8
16
|
//# sourceMappingURL=IsObjectFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAEL,KAAK,eAAe,EAAE,KAAK,WAAW,EACvC,MAAM,gBAAgB,CAAA;AAGvB,MAAM,WAAW,gBAAiB,SAAQ,eAAe;CAAG;AAE5D,qBAAa,eAAe,CAAC,CAAC,SAAS,WAAW;IAChD,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;CAuB3F"}
|
|
1
|
+
{"version":3,"file":"IsObjectFactory.d.ts","sourceRoot":"","sources":["../../src/IsObjectFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAEL,KAAK,eAAe,EAAE,KAAK,WAAW,EACvC,MAAM,gBAAgB,CAAA;AAGvB,sDAAsD;AACtD,MAAM,WAAW,gBAAiB,SAAQ,eAAe;CAAG;AAE5D,kIAAkI;AAClI,qBAAa,eAAe,CAAC,CAAC,SAAS,WAAW;IAChD;;;;;OAKG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;CAuB3F"}
|
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
declare const JsonArrayZod: z.ZodArray<z.ZodLazy<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
3
3
|
declare const JsonValueZod: z.ZodType<unknown>;
|
|
4
|
+
/** Zod schema for a JSON object with string keys and recursive JSON values. */
|
|
4
5
|
export declare const JsonObjectZod: z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
6
|
+
/** A recursive JSON value: string, number, boolean, null, array, or object. */
|
|
5
7
|
export type JsonValue = z.infer<typeof JsonValueZod>;
|
|
8
|
+
/** A JSON object with string keys and JSON values. */
|
|
6
9
|
export type JsonObject = z.infer<typeof JsonObjectZod>;
|
|
10
|
+
/** A JSON array containing JSON values. */
|
|
7
11
|
export type JsonArray = z.infer<typeof JsonArrayZod>;
|
|
12
|
+
/** Type guard that checks if a value is a valid JSON value. */
|
|
8
13
|
export declare const isJsonValue: <T>(value: T) => value is T;
|
|
14
|
+
/** Casts a value to JsonValue or returns undefined if it does not conform. */
|
|
9
15
|
export declare const asJsonValue: {
|
|
10
16
|
<T>(value: T): T | undefined;
|
|
11
17
|
<T>(value: T, assert: import("@xylabs/zod").ZodFactoryConfig): T;
|
|
12
18
|
};
|
|
19
|
+
/** Parses a value into a JsonValue, throwing if it does not conform. */
|
|
13
20
|
export declare const toJsonValue: {
|
|
14
21
|
<T>(value: T): T | undefined;
|
|
15
22
|
<T>(value: T, assert: import("@xylabs/zod").ZodFactoryConfig): T;
|
|
16
23
|
};
|
|
24
|
+
/** Type guard that checks if a value is a valid JSON array. */
|
|
17
25
|
export declare const isJsonArray: <T>(value: T) => value is T & unknown[];
|
|
26
|
+
/** Casts a value to JsonArray or returns undefined if it does not conform. */
|
|
18
27
|
export declare const asJsonArray: {
|
|
19
28
|
<T>(value: T): (T & unknown[]) | undefined;
|
|
20
29
|
<T>(value: T, assert: import("@xylabs/zod").ZodFactoryConfig): T & unknown[];
|
|
21
30
|
};
|
|
31
|
+
/** Parses a value into a JsonArray, throwing if it does not conform. */
|
|
22
32
|
export declare const toJsonArray: {
|
|
23
33
|
<T>(value: T): (T & unknown[]) | undefined;
|
|
24
34
|
<T>(value: T, assert: import("@xylabs/zod").ZodFactoryConfig): T & unknown[];
|
|
25
35
|
};
|
|
36
|
+
/** Type guard that checks if a value is a valid JSON object. */
|
|
26
37
|
export declare const isJsonObject: <T>(value: T) => value is T & Record<string, unknown>;
|
|
38
|
+
/** Casts a value to JsonObject or returns undefined if it does not conform. */
|
|
27
39
|
export declare const asJsonObject: {
|
|
28
40
|
<T>(value: T): (T & Record<string, unknown>) | undefined;
|
|
29
41
|
<T>(value: T, assert: import("@xylabs/zod").ZodFactoryConfig): T & Record<string, unknown>;
|
|
30
42
|
};
|
|
43
|
+
/** Parses a value into a JsonObject, throwing if it does not conform. */
|
|
31
44
|
export declare const toJsonObject: {
|
|
32
45
|
<T>(value: T): (T & Record<string, unknown>) | undefined;
|
|
33
46
|
<T>(value: T, assert: import("@xylabs/zod").ZodFactoryConfig): T & Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonObject.d.ts","sourceRoot":"","sources":["../../src/JsonObject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,QAAA,MAAM,YAAY,gGAAsC,CAAA;AAGxD,QAAA,MAAM,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAQhC,CAAA;AAGL,eAAO,MAAM,aAAa,mGAAqC,CAAA;AAG/D,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AACpD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AACtD,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAEpD,eAAO,MAAM,WAAW,6BAA6B,CAAA;AACrD,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AACpE,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AAEpE,eAAO,MAAM,WAAW,yCAA6B,CAAA;AACrD,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AACpE,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AAEpE,eAAO,MAAM,YAAY,uDAA8B,CAAA;AACvD,eAAO,MAAM,YAAY;;;CAA8C,CAAA;AACvE,eAAO,MAAM,YAAY;;;CAA8C,CAAA"}
|
|
1
|
+
{"version":3,"file":"JsonObject.d.ts","sourceRoot":"","sources":["../../src/JsonObject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,QAAA,MAAM,YAAY,gGAAsC,CAAA;AAGxD,QAAA,MAAM,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAQhC,CAAA;AAGL,+EAA+E;AAC/E,eAAO,MAAM,aAAa,mGAAqC,CAAA;AAG/D,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AACpD,sDAAsD;AACtD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AACtD,2CAA2C;AAC3C,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAEpD,+DAA+D;AAC/D,eAAO,MAAM,WAAW,6BAA6B,CAAA;AACrD,8EAA8E;AAC9E,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AACpE,wEAAwE;AACxE,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AAEpE,+DAA+D;AAC/D,eAAO,MAAM,WAAW,yCAA6B,CAAA;AACrD,8EAA8E;AAC9E,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AACpE,wEAAwE;AACxE,eAAO,MAAM,WAAW;;;CAA4C,CAAA;AAEpE,gEAAgE;AAChE,eAAO,MAAM,YAAY,uDAA8B,CAAA;AACvD,+EAA+E;AAC/E,eAAO,MAAM,YAAY;;;CAA8C,CAAA;AACvE,yEAAyE;AACzE,eAAO,MAAM,YAAY;;;CAA8C,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EmptyObject } from './EmptyObject.ts';
|
|
2
2
|
import type { StringKeyObject } from './StringKeyObject.ts';
|
|
3
|
+
/** Abstract base class that wraps an object and provides typed access to it. */
|
|
3
4
|
export declare abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {
|
|
4
5
|
readonly obj: T;
|
|
5
6
|
constructor(obj: T);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectWrapper.d.ts","sourceRoot":"","sources":["../../src/ObjectWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,8BAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IACrE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAA;gBACH,GAAG,EAAE,CAAC;IAIlB,SAAS,KAAK,YAAY,IACL,eAAe,CACnC;CACF"}
|
|
1
|
+
{"version":3,"file":"ObjectWrapper.d.ts","sourceRoot":"","sources":["../../src/ObjectWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,gFAAgF;AAChF,8BAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IACrE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAA;gBACH,GAAG,EAAE,CAAC;IAIlB,SAAS,KAAK,YAAY,IACL,eAAe,CACnC;CACF"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { JsonValue } from './JsonObject.ts';
|
|
2
|
+
/** Omits the keys of T that start with the given prefix. */
|
|
2
3
|
export type OmitStartsWith<T, Prefix extends string> = {
|
|
3
4
|
[K in keyof T as K extends `${Prefix}${string}` ? never : K]: T[K];
|
|
4
5
|
};
|
|
6
|
+
/** Recursively omits keys that start with the given prefix, including in nested objects and arrays. */
|
|
5
7
|
export type DeepOmitStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? {
|
|
6
8
|
[K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix>;
|
|
7
9
|
} : T;
|
|
10
|
+
/** Recursively removes all non-string keys from an object type, including in nested objects and arrays. */
|
|
8
11
|
export type DeepRestrictToStringKeys<T> = {
|
|
9
12
|
[K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K];
|
|
10
13
|
};
|
|
14
|
+
/** Recursively restricts an object type to only JSON-compatible values, excluding non-serializable types. */
|
|
11
15
|
export type DeepRestrictToJson<T> = {
|
|
12
16
|
[K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToJson<U>[] : T[K] extends object ? DeepRestrictToJson<T[K]> : T[K] extends JsonValue ? T[K] : never;
|
|
13
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OmitStartsWith.d.ts","sourceRoot":"","sources":["../../src/OmitStartsWith.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,IAAI;KACpD,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACnE,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5E,kBAAkB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,GAC/B,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,MAAM,GAC7B,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAC5B,KAAK,GACL,CAAC,GACH,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;CACzC,GACD,CAAC,CAAA;AAEP,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI;KACvC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,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AC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"Optional.d.ts","sourceRoot":"","sources":["../../src/Optional.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Override.d.ts","sourceRoot":"","sources":["../../src/Override.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,CAAC,EAAE,EAAE,EAAE,IAAI,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,CAAA;AAE/C,YAAY,EAAE,QAAQ,EAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"Override.d.ts","sourceRoot":"","sources":["../../src/Override.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,KAAK,QAAQ,CAAC,EAAE,EAAE,EAAE,IAAI,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,CAAA;AAE/C,YAAY,EAAE,QAAQ,EAAE,CAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
/** Picks only the keys of T that start with the given prefix. */
|
|
1
2
|
export type PickStartsWith<T, Prefix extends string> = {
|
|
2
3
|
[K in keyof T as K extends `${Prefix}${string}` ? K : never]: T[K];
|
|
3
4
|
};
|
|
5
|
+
/** Recursively picks only the keys that start with the given prefix, including in nested objects and arrays. */
|
|
4
6
|
export type DeepPickStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepPickStartsWith<U, Prefix>[] : T extends object ? {
|
|
5
7
|
[K in keyof T as K extends string ? K extends `${Prefix}${string}` ? K : never : K]: DeepPickStartsWith<T[K], Prefix>;
|
|
6
8
|
} : T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PickStartsWith.d.ts","sourceRoot":"","sources":["../../src/PickStartsWith.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,IAAI;KACpD,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CACnE,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5E,kBAAkB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,GAC/B,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,MAAM,GAC7B,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAC5B,CAAC,GACD,KAAK,GACP,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;CACzC,GACD,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"PickStartsWith.d.ts","sourceRoot":"","sources":["../../src/PickStartsWith.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,MAAM,MAAM,cAAc,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,IAAI;KACpD,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;CACnE,CAAA;AAED,gHAAgH;AAChH,MAAM,MAAM,kBAAkB,CAAC,CAAC,EAAE,MAAM,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5E,kBAAkB,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,GAC/B,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,MAAM,GAC7B,CAAC,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAC5B,CAAC,GACD,KAAK,GACP,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;CACzC,GACD,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Simplify.d.ts","sourceRoot":"","sources":["../../src/Simplify.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"Simplify.d.ts","sourceRoot":"","sources":["../../src/Simplify.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringKeyObject.d.ts","sourceRoot":"","sources":["../../src/StringKeyObject.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAE,CAAA"}
|
|
1
|
+
{"version":3,"file":"StringKeyObject.d.ts","sourceRoot":"","sources":["../../src/StringKeyObject.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAE,CAAA"}
|
|
@@ -2,9 +2,11 @@ import type { AnyObject } from '@xylabs/object-model';
|
|
|
2
2
|
import type { Promisable } from '@xylabs/promise';
|
|
3
3
|
import type { EmptyObject } from './EmptyObject.ts';
|
|
4
4
|
import { ObjectWrapper } from './ObjectWrapper.ts';
|
|
5
|
+
/** Interface for validating objects and returning any errors found. */
|
|
5
6
|
export interface Validator<T extends EmptyObject = AnyObject> {
|
|
6
7
|
validate(payload: T): Promisable<Error[]>;
|
|
7
8
|
}
|
|
9
|
+
/** Abstract base class for validators that wraps a partial object and provides a validation method. */
|
|
8
10
|
export declare abstract class ValidatorBase<T extends EmptyObject = AnyObject> extends ObjectWrapper<Partial<T>> implements Validator<T> {
|
|
9
11
|
abstract validate(payload: T): Promisable<Error[]>;
|
|
10
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../src/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,SAAS;IAC1D,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;CAC1C;AAED,8BAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,SAAS,CAAE,SAAQ,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IAC9H,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;CACnD"}
|
|
1
|
+
{"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../src/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,uEAAuE;AACvE,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,SAAS;IAC1D,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;CAC1C;AAED,uGAAuG;AACvG,8BAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,SAAS,CAAE,SAAQ,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,YAAW,SAAS,CAAC,CAAC,CAAC;IAC9H,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;CACnD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { EmptyObject } from './EmptyObject.ts';
|
|
2
|
+
/** Intersects T with TAdditional if TAdditional is an object, otherwise returns T unchanged. */
|
|
2
3
|
export type WithAdditional<T extends EmptyObject | void, TAdditional extends EmptyObject | void = void> = TAdditional extends EmptyObject ? T & TAdditional : T;
|
|
3
4
|
//# sourceMappingURL=WithAdditional.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithAdditional.d.ts","sourceRoot":"","sources":["../../src/WithAdditional.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,EAAE,WAAW,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAClG,WAAW,SAAS,WAAW,GAAG,CAAC,GAAG,WAAW,GAAG,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"WithAdditional.d.ts","sourceRoot":"","sources":["../../src/WithAdditional.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD,gGAAgG;AAChG,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,IAAI,EAAE,WAAW,SAAS,WAAW,GAAG,IAAI,GAAG,IAAI,IAClG,WAAW,SAAS,WAAW,GAAG,CAAC,GAAG,WAAW,GAAG,CAAC,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { AnyObject } from '@xylabs/object-model';
|
|
2
|
+
/** Type-narrowing function that casts a value to AnyObject if it is a plain object, or returns undefined. */
|
|
2
3
|
export declare const asAnyObject: import("@xylabs/object-model").AsTypeFunction<AnyObject>;
|
|
3
4
|
//# sourceMappingURL=asObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asObject.d.ts","sourceRoot":"","sources":["../../src/asObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAKrD,eAAO,MAAM,WAAW,0DAA8G,CAAA"}
|
|
1
|
+
{"version":3,"file":"asObject.d.ts","sourceRoot":"","sources":["../../src/asObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAKrD,6GAA6G;AAC7G,eAAO,MAAM,WAAW,0DAA8G,CAAA"}
|
|
@@ -90,6 +90,12 @@ import {
|
|
|
90
90
|
} from "@xylabs/typeof";
|
|
91
91
|
import { isType } from "@xylabs/typeof";
|
|
92
92
|
var IsObjectFactory = class {
|
|
93
|
+
/**
|
|
94
|
+
* Creates a type-guard function that validates an object matches the given shape and passes additional checks.
|
|
95
|
+
* @param shape - An optional map of property names to expected types.
|
|
96
|
+
* @param additionalChecks - Optional extra type-check functions to run after shape validation.
|
|
97
|
+
* @returns A type-guard function for type T.
|
|
98
|
+
*/
|
|
93
99
|
create(shape, additionalChecks) {
|
|
94
100
|
return (obj, config) => {
|
|
95
101
|
if (!isObject2(obj)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/asObject.ts","../../src/AsTypeFactory.ts","../../src/AsObjectFactory.ts","../../src/deepMerge.ts","../../src/IsObjectFactory.ts","../../src/JsonObject.ts","../../src/ObjectWrapper.ts","../../src/omitBy.ts","../../src/pickBy.ts","../../src/removeFields.ts","../../src/toSafeJson.ts","../../src/Validator.ts","../../src/index-un-deprecated.ts"],"sourcesContent":["import type { AnyObject } from '@xylabs/object-model'\nimport { isObject } from '@xylabs/typeof'\n\nimport { AsObjectFactory } from './AsObjectFactory.ts'\n\nexport const asAnyObject = (() => AsObjectFactory.create<AnyObject>(<T extends AnyObject>(obj: unknown): obj is T => isObject(obj)))()\n","import { assertDefinedEx } from '@xylabs/assert'\nimport type {\n AsTypeFunction,\n StringOrAlertFunction, TypeCheck, TypeCheckConfig,\n TypeCheckRequiredConfig,\n} from '@xylabs/object-model'\nimport type { AnyNonPromise } from '@xylabs/promise'\nimport { isPromise } from '@xylabs/promise'\nimport { isTruthy } from '@xylabs/typeof'\n\nexport const AsTypeFactory = {\n create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>): AsTypeFunction<T> => {\n const func = (\n value: AnyNonPromise,\n assertOrConfig?: StringOrAlertFunction<T> | TypeCheckConfig,\n config?: TypeCheckConfig,\n ): T | undefined => {\n // when used as a predicate, it seems that the index is passed as the second parameter (filter,map)\n const isPredicate = typeof assertOrConfig === 'number'\n const resolvedAssert = isPredicate\n ? undefined\n : (typeof assertOrConfig === 'object' ? undefined : assertOrConfig) as (StringOrAlertFunction<T> | undefined)\n const resolvedConfig = isPredicate ? undefined : typeof assertOrConfig === 'object' ? assertOrConfig : config\n\n // only return undefined if not required\n const required = isTruthy((resolvedConfig as (TypeCheckRequiredConfig | undefined))?.required)\n if (!required && (value === undefined || value === null)) {\n return undefined\n }\n\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n\n const result = typeCheck(value, resolvedConfig) ? (value as T) : undefined\n\n if (resolvedAssert !== undefined) {\n return typeof resolvedAssert === 'function' ? assertDefinedEx<T>(result, resolvedAssert) : assertDefinedEx<T>(result, () => resolvedAssert)\n }\n return result\n }\n return func\n },\n createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => {\n const func = (value: AnyNonPromise): T | undefined => {\n if (value === undefined || value === null) return undefined\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n return typeCheck(value) ? (value as T) : undefined\n }\n return func\n },\n}\n","import type { TypeCheck } from '@xylabs/object-model'\nimport type { TypedObject } from '@xylabs/typeof'\n\nimport { AsTypeFactory } from './AsTypeFactory.ts'\n\nexport const AsObjectFactory = {\n create: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.create<T>(typeCheck)\n },\n createOptional: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.createOptional<T>(typeCheck)\n },\n}\n","import type { AnyObject } from '@xylabs/object-model'\n\n/**\n * Deeply merges two types into a new type.\n */\ntype DeepMerge<A, B> = {\n [K in keyof A | keyof B]:\n K extends keyof B\n ? K extends keyof A\n ? A[K] extends object\n ? B[K] extends object\n ? DeepMerge<A[K], B[K]>\n : B[K]\n : B[K]\n : B[K]\n : K extends keyof A\n ? A[K]\n : never;\n}\n\n/**\n * Merges multiple types into a new type.\n */\ntype MergeAll<T extends object[], R = {}>\n = T extends [infer First extends object, ...infer Rest extends object[]]\n ? MergeAll<Rest, DeepMerge<R, First>>\n : R\n\n/**\n * Options for merging objects in the deep merge function.\n */\ntype MergeOptions = {\n /**\n * Strategy for merging arrays.\n * - 'overwrite': Overwrites the array with the last object's value.\n * - 'concat': Concatenates arrays from all objects.\n * @default 'overwrite'\n */\n arrayStrategy?: 'overwrite' | 'concat'\n /**\n * Mutate the first object in the list instead of creating a new one.\n * @default false\n */\n mutate?: boolean\n}\n\nconst isUnsafeKey = (key: string | symbol): boolean =>\n key === '__proto__' || key === 'constructor' || key === 'prototype'\n\nfunction merge<T extends AnyObject>(target: AnyObject, source?: AnyObject, options?: MergeOptions): T {\n if (!source || typeof source !== 'object') return target as T\n\n for (const key of Reflect.ownKeys(source)) {\n const value = source[key]\n if (isUnsafeKey(key)) {\n continue\n } else if (Array.isArray(value)) {\n target[key]\n // If the value is an array, handle it based on the configured array strategy\n = options?.arrayStrategy === 'concat' && Array.isArray(target[key])\n ? [...target[key], ...value]\n : value\n } else if (value !== null && typeof value === 'object') {\n // Recursively merge nested objects\n if (!target[key] || typeof target[key] !== 'object') {\n target[key] = {}\n }\n merge(target[key] as AnyObject, value as AnyObject, options)\n } else {\n // Overwrite with non-object values\n target[key] = value\n }\n }\n\n return target as T\n}\n\n/**\n * Creates a deep merge function with the specified options.\n * @param options Options for merging.\n * @returns A deep merge function configured for the specified options.\n */\nexport function createDeepMerge(options: MergeOptions) {\n return function deepMerge<T extends AnyObject[]>(...objects: T): MergeAll<T> {\n const result = (options.mutate ? objects[0] ?? {} : {}) as MergeAll<T>\n for (const obj of objects) {\n merge(result, obj, options)\n }\n return result\n }\n}\n\n/**\n * Deeply merges multiple objects into a new object.\n * @param objects Multiple objects to merge deeply.\n * The function merges properties from all objects into a new object.\n * If a property exists in multiple objects, the last object's value will be used.\n * If a property is an object, it will be merged recursively.\n * If a property is an array, it will be overwritten by the last object's value.\n * If a property is a primitive value, it will be overwritten by the last object's value.\n * If a property is undefined in the source, it will be skipped.\n * If a property is a symbol, it will be merged as well.\n * @returns A new object with the merged properties.\n */\nexport const deepMerge = createDeepMerge({ arrayStrategy: 'overwrite', mutate: false })\n","import type { TypeCheck, TypeCheckConfig } from '@xylabs/object-model'\nimport {\n isObject, isTruthy,\n type ObjectTypeShape, type TypedObject,\n} from '@xylabs/typeof'\nimport { isType } from '@xylabs/typeof'\n\nexport interface ObjectTypeConfig extends TypeCheckConfig {}\n\nexport class IsObjectFactory<T extends TypedObject> {\n create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T> {\n return (obj: unknown, config?: TypeCheckConfig | number): obj is T => {\n if (!isObject(obj)) {\n return false\n }\n const log = (typeof config === 'object') ? config.log : undefined\n return (\n // do primary check\n Object.entries(shape ?? {}).filter(([key, type]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = isType((obj as any)[key], type)\n if (!result && isTruthy(log)) {\n const logger = typeof log === 'object' ? log : console\n logger.warn(`isType Failed: ${key}: ${type}`)\n }\n return !result\n }).length === 0\n // perform additional checks\n // eslint-disable-next-line unicorn/no-array-reduce\n && (additionalChecks?.reduce((prev, check) => prev && check(obj, { log }), true) ?? true)\n )\n }\n }\n}\n","import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@xylabs/zod'\nimport * as z from 'zod'\n\nconst JsonArrayZod = z.array(z.lazy(() => JsonValueZod))\n\n// Define recursive JSON value schema\nconst JsonValueZod: z.ZodType<unknown> = z.lazy(() =>\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.array(JsonValueZod),\n z.record(z.string(), JsonValueZod), // object with string keys and JSON values\n ]))\n\n// JSON object schema — top-level must be an object\nexport const JsonObjectZod = z.record(z.string(), JsonValueZod)\n\n// TypeScript type for reference\nexport type JsonValue = z.infer<typeof JsonValueZod>\nexport type JsonObject = z.infer<typeof JsonObjectZod>\nexport type JsonArray = z.infer<typeof JsonArrayZod>\n\nexport const isJsonValue = zodIsFactory(JsonValueZod)\nexport const asJsonValue = zodAsFactory(JsonValueZod, 'asJsonValue')\nexport const toJsonValue = zodToFactory(JsonValueZod, 'toJsonValue')\n\nexport const isJsonArray = zodIsFactory(JsonArrayZod)\nexport const asJsonArray = zodAsFactory(JsonArrayZod, 'asJsonArray')\nexport const toJsonArray = zodToFactory(JsonArrayZod, 'toJsonArray')\n\nexport const isJsonObject = zodIsFactory(JsonObjectZod)\nexport const asJsonObject = zodAsFactory(JsonObjectZod, 'asJsonObject')\nexport const toJsonObject = zodToFactory(JsonObjectZod, 'toJsonObject')\n","import type { EmptyObject } from './EmptyObject.ts'\nimport type { StringKeyObject } from './StringKeyObject.ts'\n\nexport abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {\n readonly obj: T\n constructor(obj: T) {\n this.obj = obj\n }\n\n protected get stringKeyObj() {\n return this.obj as StringKeyObject\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepOmitStartsWith } from './OmitStartsWith.ts'\n\nexport type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst omitByArray = <T>(\n obj: T[],\n predicate: OmitByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst omitByObject = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (!predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\nexport const omitBy = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? omitByArray(obj, predicate, maxDepth - 1) as T : omitByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst omitByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\nexport const omitByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepOmitStartsWith<T, P> => {\n return omitBy(payload, omitByPrefixPredicate(prefix), maxDepth) as unknown as DeepOmitStartsWith<T, P>\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepPickStartsWith } from './PickStartsWith.ts'\n\nexport type PickByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst pickByArray = <T>(\n obj: T[],\n predicate: PickByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst pickByObject = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\nexport const pickBy = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? pickByArray(obj, predicate, maxDepth - 1) as T : pickByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst pickByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\nexport const pickByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepPickStartsWith<T, P> => {\n return pickBy(payload, pickByPrefixPredicate(prefix), maxDepth) as unknown as DeepPickStartsWith<T, P>\n}\n","import type { EmptyObject } from './EmptyObject.ts'\n\nexport const removeFields = <T extends EmptyObject, K extends keyof T>(obj: T, fields: K[]): Omit<T, K> => {\n const clone = { ...obj }\n for (const field of fields) {\n delete clone[field]\n }\n return clone\n}\n","import type {\n JsonArray, JsonObject, JsonValue,\n} from './JsonObject.ts'\n\nexport const toSafeJsonArray = (value: unknown[], cycleList?: unknown[], maxDepth = 3): JsonArray => {\n return value.map(item => toSafeJsonValue(item, cycleList, maxDepth))\n}\n\nexport const toSafeJsonObject = (value: object, cycleList?: unknown[], maxDepth = 3): JsonObject => {\n const result: JsonObject = {}\n for (const [key, entry] of Object.entries(value)) {\n result[key] = value === undefined ? '[Undefined]' : toSafeJsonValue(entry, cycleList, maxDepth)\n }\n return result\n}\n\nexport const toSafeJsonValue = (value: unknown, cycleList?: unknown[], maxDepth = 3): JsonValue => {\n if (maxDepth <= 0 && typeof value === 'object') {\n return '[MaxDepth]'\n }\n if (cycleList?.includes(value)) {\n return '[Circular]'\n }\n switch (typeof value) {\n case 'string':\n case 'boolean':\n case 'number': {\n return value\n }\n case 'object': {\n if (value === null) {\n return null\n }\n const newCycleList = cycleList ?? []\n newCycleList.push(value)\n return Array.isArray(value) ? toSafeJsonArray(value, newCycleList, maxDepth - 1) : toSafeJsonObject(value, newCycleList, maxDepth - 1)\n }\n default: {\n return `[${typeof value}]`\n }\n }\n}\n\nexport const toSafeJsonString = (value: unknown, maxDepth = 3) => {\n return JSON.stringify(toSafeJson(value, maxDepth), null, 2)\n}\n\nexport const toSafeJson = (value: unknown, maxDepth = 3): JsonValue => {\n return toSafeJsonValue(value, undefined, maxDepth)\n}\n","import type { AnyObject } from '@xylabs/object-model'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport { ObjectWrapper } from './ObjectWrapper.ts'\n\nexport interface Validator<T extends EmptyObject = AnyObject> {\n validate(payload: T): Promisable<Error[]>\n}\n\nexport abstract class ValidatorBase<T extends EmptyObject = AnyObject> extends ObjectWrapper<Partial<T>> implements Validator<T> {\n abstract validate(payload: T): Promisable<Error[]>\n}\n","export * from './asObject.ts'\nexport * from './AsObjectFactory.ts'\nexport * from './AsTypeFactory.ts'\nexport * from './deepMerge.ts'\nexport * from './IsObjectFactory.ts'\nexport * from './JsonObject.ts'\nexport * from './ObjectWrapper.ts'\nexport * from './omitBy.ts'\nexport * from './OmitStartsWith.ts'\nexport * from './Optional.ts'\nexport * from './Override.ts'\nexport * from './PartialRecord.ts'\nexport * from './pickBy.ts'\nexport * from './PickStartsWith.ts'\nexport * from './removeFields.ts'\nexport * from './Simplify.ts'\nexport * from './StringKeyObject.ts'\nexport * from './toSafeJson.ts'\nexport * from './Validator.ts'\nexport * from './WithAdditional.ts'\nexport * from '@xylabs/object-model'\nexport { isObject } from '@xylabs/typeof'\n"],"mappings":";AACA,SAAS,gBAAgB;;;ACDzB,SAAS,uBAAuB;AAOhC,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAElB,IAAM,gBAAgB;AAAA,EAC3B,QAAQ,CAA0B,cAA+C;AAC/E,UAAM,OAAO,CACX,OACA,gBACA,WACkB;AAElB,YAAM,cAAc,OAAO,mBAAmB;AAC9C,YAAM,iBAAiB,cACnB,SACC,OAAO,mBAAmB,WAAW,SAAY;AACtD,YAAM,iBAAiB,cAAc,SAAY,OAAO,mBAAmB,WAAW,iBAAiB;AAGvG,YAAM,WAAW,SAAU,gBAA0D,QAAQ;AAC7F,UAAI,CAAC,aAAa,UAAU,UAAa,UAAU,OAAO;AACxD,eAAO;AAAA,MACT;AAEA,UAAI,UAAU,KAAK,GAAG;AACpB,cAAM,IAAI,UAAU,uDAAuD;AAAA,MAC7E;AAEA,YAAM,SAAS,UAAU,OAAO,cAAc,IAAK,QAAc;AAEjE,UAAI,mBAAmB,QAAW;AAChC,eAAO,OAAO,mBAAmB,aAAa,gBAAmB,QAAQ,cAAc,IAAI,gBAAmB,QAAQ,MAAM,cAAc;AAAA,MAC5I;AACA,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAAA,EACA,gBAAgB,CAA0B,cAA4B;AACpE,UAAM,OAAO,CAAC,UAAwC;AACpD,UAAI,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I;AAAA,IACA,SAAS;AACP,aAAO,IAAI,OAAO,KAAK;AAAA,IACzB;AAAA,EACF;AACF;AAEO,IAAM,mBAAmB,CAAC,OAAgB,WAAW,MAAM;AAChE,SAAO,KAAK,UAAU,WAAW,OAAO,QAAQ,GAAG,MAAM,CAAC;AAC5D;AAEO,IAAM,aAAa,CAAC,OAAgB,WAAW,MAAiB;AACrE,SAAO,gBAAgB,OAAO,QAAW,QAAQ;AACnD;;;ACvCO,IAAe,gBAAf,cAAwE,cAAkD;AAEjI;;;ACQA,cAAc;AACd,SAAS,YAAAC,iBAAgB;","names":["deepMerge","isObject","isTruthy","assertEx","isObject"]}
|
|
1
|
+
{"version":3,"sources":["../../src/asObject.ts","../../src/AsTypeFactory.ts","../../src/AsObjectFactory.ts","../../src/deepMerge.ts","../../src/IsObjectFactory.ts","../../src/JsonObject.ts","../../src/ObjectWrapper.ts","../../src/omitBy.ts","../../src/pickBy.ts","../../src/removeFields.ts","../../src/toSafeJson.ts","../../src/Validator.ts","../../src/index-un-deprecated.ts"],"sourcesContent":["import type { AnyObject } from '@xylabs/object-model'\nimport { isObject } from '@xylabs/typeof'\n\nimport { AsObjectFactory } from './AsObjectFactory.ts'\n\n/** Type-narrowing function that casts a value to AnyObject if it is a plain object, or returns undefined. */\nexport const asAnyObject = (() => AsObjectFactory.create<AnyObject>(<T extends AnyObject>(obj: unknown): obj is T => isObject(obj)))()\n","import { assertDefinedEx } from '@xylabs/assert'\nimport type {\n AsTypeFunction,\n StringOrAlertFunction, TypeCheck, TypeCheckConfig,\n TypeCheckRequiredConfig,\n} from '@xylabs/object-model'\nimport type { AnyNonPromise } from '@xylabs/promise'\nimport { isPromise } from '@xylabs/promise'\nimport { isTruthy } from '@xylabs/typeof'\n\n/**\n * Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.\n * Supports optional assertion messages and configuration for required/optional behavior.\n */\nexport const AsTypeFactory = {\n create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>): AsTypeFunction<T> => {\n const func = (\n value: AnyNonPromise,\n assertOrConfig?: StringOrAlertFunction<T> | TypeCheckConfig,\n config?: TypeCheckConfig,\n ): T | undefined => {\n // when used as a predicate, it seems that the index is passed as the second parameter (filter,map)\n const isPredicate = typeof assertOrConfig === 'number'\n const resolvedAssert = isPredicate\n ? undefined\n : (typeof assertOrConfig === 'object' ? undefined : assertOrConfig) as (StringOrAlertFunction<T> | undefined)\n const resolvedConfig = isPredicate ? undefined : typeof assertOrConfig === 'object' ? assertOrConfig : config\n\n // only return undefined if not required\n const required = isTruthy((resolvedConfig as (TypeCheckRequiredConfig | undefined))?.required)\n if (!required && (value === undefined || value === null)) {\n return undefined\n }\n\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n\n const result = typeCheck(value, resolvedConfig) ? (value as T) : undefined\n\n if (resolvedAssert !== undefined) {\n return typeof resolvedAssert === 'function' ? assertDefinedEx<T>(result, resolvedAssert) : assertDefinedEx<T>(result, () => resolvedAssert)\n }\n return result\n }\n return func\n },\n createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => {\n const func = (value: AnyNonPromise): T | undefined => {\n if (value === undefined || value === null) return undefined\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n return typeCheck(value) ? (value as T) : undefined\n }\n return func\n },\n}\n","import type { TypeCheck } from '@xylabs/object-model'\nimport type { TypedObject } from '@xylabs/typeof'\n\nimport { AsTypeFactory } from './AsTypeFactory.ts'\n\n/** Factory for creating type-narrowing functions for TypedObject types. */\nexport const AsObjectFactory = {\n create: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.create<T>(typeCheck)\n },\n createOptional: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.createOptional<T>(typeCheck)\n },\n}\n","import type { AnyObject } from '@xylabs/object-model'\n\n/**\n * Deeply merges two types into a new type.\n */\ntype DeepMerge<A, B> = {\n [K in keyof A | keyof B]:\n K extends keyof B\n ? K extends keyof A\n ? A[K] extends object\n ? B[K] extends object\n ? DeepMerge<A[K], B[K]>\n : B[K]\n : B[K]\n : B[K]\n : K extends keyof A\n ? A[K]\n : never;\n}\n\n/**\n * Merges multiple types into a new type.\n */\ntype MergeAll<T extends object[], R = {}>\n = T extends [infer First extends object, ...infer Rest extends object[]]\n ? MergeAll<Rest, DeepMerge<R, First>>\n : R\n\n/**\n * Options for merging objects in the deep merge function.\n */\ntype MergeOptions = {\n /**\n * Strategy for merging arrays.\n * - 'overwrite': Overwrites the array with the last object's value.\n * - 'concat': Concatenates arrays from all objects.\n * @default 'overwrite'\n */\n arrayStrategy?: 'overwrite' | 'concat'\n /**\n * Mutate the first object in the list instead of creating a new one.\n * @default false\n */\n mutate?: boolean\n}\n\nconst isUnsafeKey = (key: string | symbol): boolean =>\n key === '__proto__' || key === 'constructor' || key === 'prototype'\n\nfunction merge<T extends AnyObject>(target: AnyObject, source?: AnyObject, options?: MergeOptions): T {\n if (!source || typeof source !== 'object') return target as T\n\n for (const key of Reflect.ownKeys(source)) {\n const value = source[key]\n if (isUnsafeKey(key)) {\n continue\n } else if (Array.isArray(value)) {\n target[key]\n // If the value is an array, handle it based on the configured array strategy\n = options?.arrayStrategy === 'concat' && Array.isArray(target[key])\n ? [...target[key], ...value]\n : value\n } else if (value !== null && typeof value === 'object') {\n // Recursively merge nested objects\n if (!target[key] || typeof target[key] !== 'object') {\n target[key] = {}\n }\n merge(target[key] as AnyObject, value as AnyObject, options)\n } else {\n // Overwrite with non-object values\n target[key] = value\n }\n }\n\n return target as T\n}\n\n/**\n * Creates a deep merge function with the specified options.\n * @param options Options for merging.\n * @returns A deep merge function configured for the specified options.\n */\nexport function createDeepMerge(options: MergeOptions) {\n return function deepMerge<T extends AnyObject[]>(...objects: T): MergeAll<T> {\n const result = (options.mutate ? objects[0] ?? {} : {}) as MergeAll<T>\n for (const obj of objects) {\n merge(result, obj, options)\n }\n return result\n }\n}\n\n/**\n * Deeply merges multiple objects into a new object.\n * @param objects Multiple objects to merge deeply.\n * The function merges properties from all objects into a new object.\n * If a property exists in multiple objects, the last object's value will be used.\n * If a property is an object, it will be merged recursively.\n * If a property is an array, it will be overwritten by the last object's value.\n * If a property is a primitive value, it will be overwritten by the last object's value.\n * If a property is undefined in the source, it will be skipped.\n * If a property is a symbol, it will be merged as well.\n * @returns A new object with the merged properties.\n */\nexport const deepMerge = createDeepMerge({ arrayStrategy: 'overwrite', mutate: false })\n","import type { TypeCheck, TypeCheckConfig } from '@xylabs/object-model'\nimport {\n isObject, isTruthy,\n type ObjectTypeShape, type TypedObject,\n} from '@xylabs/typeof'\nimport { isType } from '@xylabs/typeof'\n\n/** Configuration options for object type checking. */\nexport interface ObjectTypeConfig extends TypeCheckConfig {}\n\n/** Factory class for creating type-guard functions that validate objects against a given shape and optional additional checks. */\nexport class IsObjectFactory<T extends TypedObject> {\n /**\n * Creates a type-guard function that validates an object matches the given shape and passes additional checks.\n * @param shape - An optional map of property names to expected types.\n * @param additionalChecks - Optional extra type-check functions to run after shape validation.\n * @returns A type-guard function for type T.\n */\n create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T> {\n return (obj: unknown, config?: TypeCheckConfig | number): obj is T => {\n if (!isObject(obj)) {\n return false\n }\n const log = (typeof config === 'object') ? config.log : undefined\n return (\n // do primary check\n Object.entries(shape ?? {}).filter(([key, type]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = isType((obj as any)[key], type)\n if (!result && isTruthy(log)) {\n const logger = typeof log === 'object' ? log : console\n logger.warn(`isType Failed: ${key}: ${type}`)\n }\n return !result\n }).length === 0\n // perform additional checks\n // eslint-disable-next-line unicorn/no-array-reduce\n && (additionalChecks?.reduce((prev, check) => prev && check(obj, { log }), true) ?? true)\n )\n }\n }\n}\n","import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@xylabs/zod'\nimport * as z from 'zod'\n\nconst JsonArrayZod = z.array(z.lazy(() => JsonValueZod))\n\n// Define recursive JSON value schema\nconst JsonValueZod: z.ZodType<unknown> = z.lazy(() =>\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.array(JsonValueZod),\n z.record(z.string(), JsonValueZod), // object with string keys and JSON values\n ]))\n\n// JSON object schema — top-level must be an object\n/** Zod schema for a JSON object with string keys and recursive JSON values. */\nexport const JsonObjectZod = z.record(z.string(), JsonValueZod)\n\n// TypeScript type for reference\n/** A recursive JSON value: string, number, boolean, null, array, or object. */\nexport type JsonValue = z.infer<typeof JsonValueZod>\n/** A JSON object with string keys and JSON values. */\nexport type JsonObject = z.infer<typeof JsonObjectZod>\n/** A JSON array containing JSON values. */\nexport type JsonArray = z.infer<typeof JsonArrayZod>\n\n/** Type guard that checks if a value is a valid JSON value. */\nexport const isJsonValue = zodIsFactory(JsonValueZod)\n/** Casts a value to JsonValue or returns undefined if it does not conform. */\nexport const asJsonValue = zodAsFactory(JsonValueZod, 'asJsonValue')\n/** Parses a value into a JsonValue, throwing if it does not conform. */\nexport const toJsonValue = zodToFactory(JsonValueZod, 'toJsonValue')\n\n/** Type guard that checks if a value is a valid JSON array. */\nexport const isJsonArray = zodIsFactory(JsonArrayZod)\n/** Casts a value to JsonArray or returns undefined if it does not conform. */\nexport const asJsonArray = zodAsFactory(JsonArrayZod, 'asJsonArray')\n/** Parses a value into a JsonArray, throwing if it does not conform. */\nexport const toJsonArray = zodToFactory(JsonArrayZod, 'toJsonArray')\n\n/** Type guard that checks if a value is a valid JSON object. */\nexport const isJsonObject = zodIsFactory(JsonObjectZod)\n/** Casts a value to JsonObject or returns undefined if it does not conform. */\nexport const asJsonObject = zodAsFactory(JsonObjectZod, 'asJsonObject')\n/** Parses a value into a JsonObject, throwing if it does not conform. */\nexport const toJsonObject = zodToFactory(JsonObjectZod, 'toJsonObject')\n","import type { EmptyObject } from './EmptyObject.ts'\nimport type { StringKeyObject } from './StringKeyObject.ts'\n\n/** Abstract base class that wraps an object and provides typed access to it. */\nexport abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {\n readonly obj: T\n constructor(obj: T) {\n this.obj = obj\n }\n\n protected get stringKeyObj() {\n return this.obj as StringKeyObject\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepOmitStartsWith } from './OmitStartsWith.ts'\n\n/** A predicate function used to determine which properties to omit from an object. */\nexport type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst omitByArray = <T>(\n obj: T[],\n predicate: OmitByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst omitByObject = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (!predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\n/**\n * Creates a new object excluding properties that satisfy the predicate, with optional recursive depth.\n * @param obj - The source object to omit properties from.\n * @param predicate - A function that returns true for properties to exclude.\n * @param maxDepth - Maximum recursion depth for nested objects.\n * @returns A partial copy of the object without matching properties.\n */\nexport const omitBy = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? omitByArray(obj, predicate, maxDepth - 1) as T : omitByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst omitByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\n/**\n * Omits all properties whose keys start with the given prefix, recursively through nested objects.\n * @param payload - The source object.\n * @param prefix - The string prefix to match keys against.\n * @param maxDepth - Maximum recursion depth.\n * @returns A new object without properties that have matching prefixed keys.\n */\nexport const omitByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepOmitStartsWith<T, P> => {\n return omitBy(payload, omitByPrefixPredicate(prefix), maxDepth) as unknown as DeepOmitStartsWith<T, P>\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepPickStartsWith } from './PickStartsWith.ts'\n\n/** A predicate function used to determine which properties to pick from an object. */\nexport type PickByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst pickByArray = <T>(\n obj: T[],\n predicate: PickByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst pickByObject = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\n/**\n * Creates a new object containing only the properties that satisfy the predicate, with optional recursive depth.\n * @param obj - The source object to pick properties from.\n * @param predicate - A function that returns true for properties to include.\n * @param maxDepth - Maximum recursion depth for nested objects.\n * @returns A partial copy of the object with only matching properties.\n */\nexport const pickBy = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? pickByArray(obj, predicate, maxDepth - 1) as T : pickByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst pickByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\n/**\n * Picks all properties whose keys start with the given prefix, recursively through nested objects.\n * @param payload - The source object.\n * @param prefix - The string prefix to match keys against.\n * @param maxDepth - Maximum recursion depth.\n * @returns A new object containing only properties with matching prefixed keys.\n */\nexport const pickByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepPickStartsWith<T, P> => {\n return pickBy(payload, pickByPrefixPredicate(prefix), maxDepth) as unknown as DeepPickStartsWith<T, P>\n}\n","import type { EmptyObject } from './EmptyObject.ts'\n\n/**\n * Returns a shallow copy of the object with the specified fields removed.\n * @param obj - The source object.\n * @param fields - An array of keys to remove.\n * @returns A new object without the specified fields.\n */\nexport const removeFields = <T extends EmptyObject, K extends keyof T>(obj: T, fields: K[]): Omit<T, K> => {\n const clone = { ...obj }\n for (const field of fields) {\n delete clone[field]\n }\n return clone\n}\n","import type {\n JsonArray, JsonObject, JsonValue,\n} from './JsonObject.ts'\n\n/**\n * Converts an array to a JSON-safe array, handling circular references and depth limits.\n * @param value - The array to convert.\n * @param cycleList - Tracks visited objects to detect circular references.\n * @param maxDepth - Maximum recursion depth before truncating.\n * @returns A JSON-safe array representation.\n */\nexport const toSafeJsonArray = (value: unknown[], cycleList?: unknown[], maxDepth = 3): JsonArray => {\n return value.map(item => toSafeJsonValue(item, cycleList, maxDepth))\n}\n\n/**\n * Converts an object to a JSON-safe object, handling circular references and depth limits.\n * @param value - The object to convert.\n * @param cycleList - Tracks visited objects to detect circular references.\n * @param maxDepth - Maximum recursion depth before truncating.\n * @returns A JSON-safe object representation.\n */\nexport const toSafeJsonObject = (value: object, cycleList?: unknown[], maxDepth = 3): JsonObject => {\n const result: JsonObject = {}\n for (const [key, entry] of Object.entries(value)) {\n result[key] = value === undefined ? '[Undefined]' : toSafeJsonValue(entry, cycleList, maxDepth)\n }\n return result\n}\n\n/**\n * Converts an unknown value to a JSON-safe value, replacing circular references with '[Circular]' and\n * non-JSON types with descriptive placeholder strings.\n * @param value - The value to convert.\n * @param cycleList - Tracks visited objects to detect circular references.\n * @param maxDepth - Maximum recursion depth before truncating with '[MaxDepth]'.\n * @returns A JSON-safe representation of the value.\n */\nexport const toSafeJsonValue = (value: unknown, cycleList?: unknown[], maxDepth = 3): JsonValue => {\n if (maxDepth <= 0 && typeof value === 'object') {\n return '[MaxDepth]'\n }\n if (cycleList?.includes(value)) {\n return '[Circular]'\n }\n switch (typeof value) {\n case 'string':\n case 'boolean':\n case 'number': {\n return value\n }\n case 'object': {\n if (value === null) {\n return null\n }\n const newCycleList = cycleList ?? []\n newCycleList.push(value)\n return Array.isArray(value) ? toSafeJsonArray(value, newCycleList, maxDepth - 1) : toSafeJsonObject(value, newCycleList, maxDepth - 1)\n }\n default: {\n return `[${typeof value}]`\n }\n }\n}\n\n/**\n * Converts a value to a pretty-printed JSON string, safely handling circular references and non-JSON types.\n * @param value - The value to serialize.\n * @param maxDepth - Maximum recursion depth.\n * @returns A formatted JSON string.\n */\nexport const toSafeJsonString = (value: unknown, maxDepth = 3) => {\n return JSON.stringify(toSafeJson(value, maxDepth), null, 2)\n}\n\n/**\n * Converts a value to a JSON-safe representation, handling circular references and non-serializable types.\n * @param value - The value to convert.\n * @param maxDepth - Maximum recursion depth.\n * @returns A JSON-safe value.\n */\nexport const toSafeJson = (value: unknown, maxDepth = 3): JsonValue => {\n return toSafeJsonValue(value, undefined, maxDepth)\n}\n","import type { AnyObject } from '@xylabs/object-model'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport { ObjectWrapper } from './ObjectWrapper.ts'\n\n/** Interface for validating objects and returning any errors found. */\nexport interface Validator<T extends EmptyObject = AnyObject> {\n validate(payload: T): Promisable<Error[]>\n}\n\n/** Abstract base class for validators that wraps a partial object and provides a validation method. */\nexport abstract class ValidatorBase<T extends EmptyObject = AnyObject> extends ObjectWrapper<Partial<T>> implements Validator<T> {\n abstract validate(payload: T): Promisable<Error[]>\n}\n","export * from './asObject.ts'\nexport * from './AsObjectFactory.ts'\nexport * from './AsTypeFactory.ts'\nexport * from './deepMerge.ts'\nexport * from './IsObjectFactory.ts'\nexport * from './JsonObject.ts'\nexport * from './ObjectWrapper.ts'\nexport * from './omitBy.ts'\nexport * from './OmitStartsWith.ts'\nexport * from './Optional.ts'\nexport * from './Override.ts'\nexport * from './PartialRecord.ts'\nexport * from './pickBy.ts'\nexport * from './PickStartsWith.ts'\nexport * from './removeFields.ts'\nexport * from './Simplify.ts'\nexport * from './StringKeyObject.ts'\nexport * from './toSafeJson.ts'\nexport * from './Validator.ts'\nexport * from './WithAdditional.ts'\nexport * from '@xylabs/object-model'\nexport { isObject } from '@xylabs/typeof'\n"],"mappings":";AACA,SAAS,gBAAgB;;;ACDzB,SAAS,uBAAuB;AAOhC,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAMlB,IAAM,gBAAgB;AAAA,EAC3B,QAAQ,CAA0B,cAA+C;AAC/E,UAAM,OAAO,CACX,OACA,gBACA,WACkB;AAElB,YAAM,cAAc,OAAO,mBAAmB;AAC9C,YAAM,iBAAiB,cACnB,SACC,OAAO,mBAAmB,WAAW,SAAY;AACtD,YAAM,iBAAiB,cAAc,SAAY,OAAO,mBAAmB,WAAW,iBAAiB;AAGvG,YAAM,WAAW,SAAU,gBAA0D,QAAQ;AAC7F,UAAI,CAAC,aAAa,UAAU,UAAa,UAAU,OAAO;AACxD,eAAO;AAAA,MACT;AAEA,UAAI,UAAU,KAAK,GAAG;AACpB,cAAM,IAAI,UAAU,uDAAuD;AAAA,MAC7E;AAEA,YAAM,SAAS,UAAU,OAAO,cAAc,IAAK,QAAc;AAEjE,UAAI,mBAAmB,QAAW;AAChC,eAAO,OAAO,mBAAmB,aAAa,gBAAmB,QAAQ,cAAc,IAAI,gBAAmB,QAAQ,MAAM,cAAc;AAAA,MAC5I;AACA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AC;AACnC,mBAAa,KAAK,KAAK;AACvB,aAAO,MAAM,QAAQ,KAAK,IAAI,gBAAgB,OAAO,cAAc,WAAW,CAAC,IAAI,iBAAiB,OAAO,cAAc,WAAW,CAAC;AAAA,IACvI;AAAA,IACA,SAAS;AACP,aAAO,IAAI,OAAO,KAAK;AAAA,IACzB;AAAA,EACF;AACF;AAQO,IAAM,mBAAmB,CAAC,OAAgB,WAAW,MAAM;AAChE,SAAO,KAAK,UAAU,WAAW,OAAO,QAAQ,GAAG,MAAM,CAAC;AAC5D;AAQO,IAAM,aAAa,CAAC,OAAgB,WAAW,MAAiB;AACrE,SAAO,gBAAgB,OAAO,QAAW,QAAQ;AACnD;;;ACvEO,IAAe,gBAAf,cAAwE,cAAkD;AAEjI;;;ACMA,cAAc;AACd,SAAS,YAAAC,iBAAgB;","names":["deepMerge","isObject","isTruthy","assertEx","isObject"]}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -212,6 +212,12 @@ import {
|
|
|
212
212
|
} from "@xylabs/typeof";
|
|
213
213
|
import { isType } from "@xylabs/typeof";
|
|
214
214
|
var IsObjectFactory = class {
|
|
215
|
+
/**
|
|
216
|
+
* Creates a type-guard function that validates an object matches the given shape and passes additional checks.
|
|
217
|
+
* @param shape - An optional map of property names to expected types.
|
|
218
|
+
* @param additionalChecks - Optional extra type-check functions to run after shape validation.
|
|
219
|
+
* @returns A type-guard function for type T.
|
|
220
|
+
*/
|
|
215
221
|
create(shape, additionalChecks) {
|
|
216
222
|
return (obj, config) => {
|
|
217
223
|
if (!isObject2(obj)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/index-deprecated.ts","../../src/index-un-deprecated.ts","../../src/asObject.ts","../../src/AsTypeFactory.ts","../../src/AsObjectFactory.ts","../../src/deepMerge.ts","../../src/IsObjectFactory.ts","../../src/JsonObject.ts","../../src/ObjectWrapper.ts","../../src/omitBy.ts","../../src/pickBy.ts","../../src/removeFields.ts","../../src/toSafeJson.ts","../../src/Validator.ts","../../src/isType.ts"],"sourcesContent":["export * from './index-deprecated.ts'\nexport * from './index-un-deprecated.ts'\n","export * from './index-un-deprecated.ts'\nexport * from './isType.ts'\n","export * from './asObject.ts'\nexport * from './AsObjectFactory.ts'\nexport * from './AsTypeFactory.ts'\nexport * from './deepMerge.ts'\nexport * from './IsObjectFactory.ts'\nexport * from './JsonObject.ts'\nexport * from './ObjectWrapper.ts'\nexport * from './omitBy.ts'\nexport * from './OmitStartsWith.ts'\nexport * from './Optional.ts'\nexport * from './Override.ts'\nexport * from './PartialRecord.ts'\nexport * from './pickBy.ts'\nexport * from './PickStartsWith.ts'\nexport * from './removeFields.ts'\nexport * from './Simplify.ts'\nexport * from './StringKeyObject.ts'\nexport * from './toSafeJson.ts'\nexport * from './Validator.ts'\nexport * from './WithAdditional.ts'\nexport * from '@xylabs/object-model'\nexport { isObject } from '@xylabs/typeof'\n","import type { AnyObject } from '@xylabs/object-model'\nimport { isObject } from '@xylabs/typeof'\n\nimport { AsObjectFactory } from './AsObjectFactory.ts'\n\nexport const asAnyObject = (() => AsObjectFactory.create<AnyObject>(<T extends AnyObject>(obj: unknown): obj is T => isObject(obj)))()\n","import { assertDefinedEx } from '@xylabs/assert'\nimport type {\n AsTypeFunction,\n StringOrAlertFunction, TypeCheck, TypeCheckConfig,\n TypeCheckRequiredConfig,\n} from '@xylabs/object-model'\nimport type { AnyNonPromise } from '@xylabs/promise'\nimport { isPromise } from '@xylabs/promise'\nimport { isTruthy } from '@xylabs/typeof'\n\nexport const AsTypeFactory = {\n create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>): AsTypeFunction<T> => {\n const func = (\n value: AnyNonPromise,\n assertOrConfig?: StringOrAlertFunction<T> | TypeCheckConfig,\n config?: TypeCheckConfig,\n ): T | undefined => {\n // when used as a predicate, it seems that the index is passed as the second parameter (filter,map)\n const isPredicate = typeof assertOrConfig === 'number'\n const resolvedAssert = isPredicate\n ? undefined\n : (typeof assertOrConfig === 'object' ? undefined : assertOrConfig) as (StringOrAlertFunction<T> | undefined)\n const resolvedConfig = isPredicate ? undefined : typeof assertOrConfig === 'object' ? assertOrConfig : config\n\n // only return undefined if not required\n const required = isTruthy((resolvedConfig as (TypeCheckRequiredConfig | undefined))?.required)\n if (!required && (value === undefined || value === null)) {\n return undefined\n }\n\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n\n const result = typeCheck(value, resolvedConfig) ? (value as T) : undefined\n\n if (resolvedAssert !== undefined) {\n return typeof resolvedAssert === 'function' ? assertDefinedEx<T>(result, resolvedAssert) : assertDefinedEx<T>(result, () => resolvedAssert)\n }\n return result\n }\n return func\n },\n createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => {\n const func = (value: AnyNonPromise): T | undefined => {\n if (value === undefined || value === null) return undefined\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n return typeCheck(value) ? (value as T) : undefined\n }\n return func\n },\n}\n","import type { TypeCheck } from '@xylabs/object-model'\nimport type { TypedObject } from '@xylabs/typeof'\n\nimport { AsTypeFactory } from './AsTypeFactory.ts'\n\nexport const AsObjectFactory = {\n create: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.create<T>(typeCheck)\n },\n createOptional: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.createOptional<T>(typeCheck)\n },\n}\n","import type { AnyObject } from '@xylabs/object-model'\n\n/**\n * Deeply merges two types into a new type.\n */\ntype DeepMerge<A, B> = {\n [K in keyof A | keyof B]:\n K extends keyof B\n ? K extends keyof A\n ? A[K] extends object\n ? B[K] extends object\n ? DeepMerge<A[K], B[K]>\n : B[K]\n : B[K]\n : B[K]\n : K extends keyof A\n ? A[K]\n : never;\n}\n\n/**\n * Merges multiple types into a new type.\n */\ntype MergeAll<T extends object[], R = {}>\n = T extends [infer First extends object, ...infer Rest extends object[]]\n ? MergeAll<Rest, DeepMerge<R, First>>\n : R\n\n/**\n * Options for merging objects in the deep merge function.\n */\ntype MergeOptions = {\n /**\n * Strategy for merging arrays.\n * - 'overwrite': Overwrites the array with the last object's value.\n * - 'concat': Concatenates arrays from all objects.\n * @default 'overwrite'\n */\n arrayStrategy?: 'overwrite' | 'concat'\n /**\n * Mutate the first object in the list instead of creating a new one.\n * @default false\n */\n mutate?: boolean\n}\n\nconst isUnsafeKey = (key: string | symbol): boolean =>\n key === '__proto__' || key === 'constructor' || key === 'prototype'\n\nfunction merge<T extends AnyObject>(target: AnyObject, source?: AnyObject, options?: MergeOptions): T {\n if (!source || typeof source !== 'object') return target as T\n\n for (const key of Reflect.ownKeys(source)) {\n const value = source[key]\n if (isUnsafeKey(key)) {\n continue\n } else if (Array.isArray(value)) {\n target[key]\n // If the value is an array, handle it based on the configured array strategy\n = options?.arrayStrategy === 'concat' && Array.isArray(target[key])\n ? [...target[key], ...value]\n : value\n } else if (value !== null && typeof value === 'object') {\n // Recursively merge nested objects\n if (!target[key] || typeof target[key] !== 'object') {\n target[key] = {}\n }\n merge(target[key] as AnyObject, value as AnyObject, options)\n } else {\n // Overwrite with non-object values\n target[key] = value\n }\n }\n\n return target as T\n}\n\n/**\n * Creates a deep merge function with the specified options.\n * @param options Options for merging.\n * @returns A deep merge function configured for the specified options.\n */\nexport function createDeepMerge(options: MergeOptions) {\n return function deepMerge<T extends AnyObject[]>(...objects: T): MergeAll<T> {\n const result = (options.mutate ? objects[0] ?? {} : {}) as MergeAll<T>\n for (const obj of objects) {\n merge(result, obj, options)\n }\n return result\n }\n}\n\n/**\n * Deeply merges multiple objects into a new object.\n * @param objects Multiple objects to merge deeply.\n * The function merges properties from all objects into a new object.\n * If a property exists in multiple objects, the last object's value will be used.\n * If a property is an object, it will be merged recursively.\n * If a property is an array, it will be overwritten by the last object's value.\n * If a property is a primitive value, it will be overwritten by the last object's value.\n * If a property is undefined in the source, it will be skipped.\n * If a property is a symbol, it will be merged as well.\n * @returns A new object with the merged properties.\n */\nexport const deepMerge = createDeepMerge({ arrayStrategy: 'overwrite', mutate: false })\n","import type { TypeCheck, TypeCheckConfig } from '@xylabs/object-model'\nimport {\n isObject, isTruthy,\n type ObjectTypeShape, type TypedObject,\n} from '@xylabs/typeof'\nimport { isType } from '@xylabs/typeof'\n\nexport interface ObjectTypeConfig extends TypeCheckConfig {}\n\nexport class IsObjectFactory<T extends TypedObject> {\n create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T> {\n return (obj: unknown, config?: TypeCheckConfig | number): obj is T => {\n if (!isObject(obj)) {\n return false\n }\n const log = (typeof config === 'object') ? config.log : undefined\n return (\n // do primary check\n Object.entries(shape ?? {}).filter(([key, type]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = isType((obj as any)[key], type)\n if (!result && isTruthy(log)) {\n const logger = typeof log === 'object' ? log : console\n logger.warn(`isType Failed: ${key}: ${type}`)\n }\n return !result\n }).length === 0\n // perform additional checks\n // eslint-disable-next-line unicorn/no-array-reduce\n && (additionalChecks?.reduce((prev, check) => prev && check(obj, { log }), true) ?? true)\n )\n }\n }\n}\n","import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@xylabs/zod'\nimport * as z from 'zod'\n\nconst JsonArrayZod = z.array(z.lazy(() => JsonValueZod))\n\n// Define recursive JSON value schema\nconst JsonValueZod: z.ZodType<unknown> = z.lazy(() =>\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.array(JsonValueZod),\n z.record(z.string(), JsonValueZod), // object with string keys and JSON values\n ]))\n\n// JSON object schema — top-level must be an object\nexport const JsonObjectZod = z.record(z.string(), JsonValueZod)\n\n// TypeScript type for reference\nexport type JsonValue = z.infer<typeof JsonValueZod>\nexport type JsonObject = z.infer<typeof JsonObjectZod>\nexport type JsonArray = z.infer<typeof JsonArrayZod>\n\nexport const isJsonValue = zodIsFactory(JsonValueZod)\nexport const asJsonValue = zodAsFactory(JsonValueZod, 'asJsonValue')\nexport const toJsonValue = zodToFactory(JsonValueZod, 'toJsonValue')\n\nexport const isJsonArray = zodIsFactory(JsonArrayZod)\nexport const asJsonArray = zodAsFactory(JsonArrayZod, 'asJsonArray')\nexport const toJsonArray = zodToFactory(JsonArrayZod, 'toJsonArray')\n\nexport const isJsonObject = zodIsFactory(JsonObjectZod)\nexport const asJsonObject = zodAsFactory(JsonObjectZod, 'asJsonObject')\nexport const toJsonObject = zodToFactory(JsonObjectZod, 'toJsonObject')\n","import type { EmptyObject } from './EmptyObject.ts'\nimport type { StringKeyObject } from './StringKeyObject.ts'\n\nexport abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {\n readonly obj: T\n constructor(obj: T) {\n this.obj = obj\n }\n\n protected get stringKeyObj() {\n return this.obj as StringKeyObject\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepOmitStartsWith } from './OmitStartsWith.ts'\n\nexport type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst omitByArray = <T>(\n obj: T[],\n predicate: OmitByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst omitByObject = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (!predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\nexport const omitBy = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? omitByArray(obj, predicate, maxDepth - 1) as T : omitByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst omitByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\nexport const omitByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepOmitStartsWith<T, P> => {\n return omitBy(payload, omitByPrefixPredicate(prefix), maxDepth) as unknown as DeepOmitStartsWith<T, P>\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepPickStartsWith } from './PickStartsWith.ts'\n\nexport type PickByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst pickByArray = <T>(\n obj: T[],\n predicate: PickByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst pickByObject = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\nexport const pickBy = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? pickByArray(obj, predicate, maxDepth - 1) as T : pickByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst pickByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\nexport const pickByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepPickStartsWith<T, P> => {\n return pickBy(payload, pickByPrefixPredicate(prefix), maxDepth) as unknown as DeepPickStartsWith<T, P>\n}\n","import type { EmptyObject } from './EmptyObject.ts'\n\nexport const removeFields = <T extends EmptyObject, K extends keyof T>(obj: T, fields: K[]): Omit<T, K> => {\n const clone = { ...obj }\n for (const field of fields) {\n delete clone[field]\n }\n return clone\n}\n","import type {\n JsonArray, JsonObject, JsonValue,\n} from './JsonObject.ts'\n\nexport const toSafeJsonArray = (value: unknown[], cycleList?: unknown[], maxDepth = 3): JsonArray => {\n return value.map(item => toSafeJsonValue(item, cycleList, maxDepth))\n}\n\nexport const toSafeJsonObject = (value: object, cycleList?: unknown[], maxDepth = 3): JsonObject => {\n const result: JsonObject = {}\n for (const [key, entry] of Object.entries(value)) {\n result[key] = value === undefined ? '[Undefined]' : toSafeJsonValue(entry, cycleList, maxDepth)\n }\n return result\n}\n\nexport const toSafeJsonValue = (value: unknown, cycleList?: unknown[], maxDepth = 3): JsonValue => {\n if (maxDepth <= 0 && typeof value === 'object') {\n return '[MaxDepth]'\n }\n if (cycleList?.includes(value)) {\n return '[Circular]'\n }\n switch (typeof value) {\n case 'string':\n case 'boolean':\n case 'number': {\n return value\n }\n case 'object': {\n if (value === null) {\n return null\n }\n const newCycleList = cycleList ?? []\n newCycleList.push(value)\n return Array.isArray(value) ? toSafeJsonArray(value, newCycleList, maxDepth - 1) : toSafeJsonObject(value, newCycleList, maxDepth - 1)\n }\n default: {\n return `[${typeof value}]`\n }\n }\n}\n\nexport const toSafeJsonString = (value: unknown, maxDepth = 3) => {\n return JSON.stringify(toSafeJson(value, maxDepth), null, 2)\n}\n\nexport const toSafeJson = (value: unknown, maxDepth = 3): JsonValue => {\n return toSafeJsonValue(value, undefined, maxDepth)\n}\n","import type { AnyObject } from '@xylabs/object-model'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport { ObjectWrapper } from './ObjectWrapper.ts'\n\nexport interface Validator<T extends EmptyObject = AnyObject> {\n validate(payload: T): Promisable<Error[]>\n}\n\nexport abstract class ValidatorBase<T extends EmptyObject = AnyObject> extends ObjectWrapper<Partial<T>> implements Validator<T> {\n abstract validate(payload: T): Promisable<Error[]>\n}\n","import type { FieldType } from '@xylabs/typeof'\n\n/** @deprecated use from @xylabs/typeof instead */\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array': {\n return Array.isArray(value)\n }\n case 'null': {\n return value === null\n }\n case 'undefined': {\n return value === undefined\n }\n case 'object': {\n // nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n // arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default: {\n return typeofValue === expectedType\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAAA;AAAA,EAAA,cAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAAC;AAAA,EAAA,cAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAAC;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,SA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,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK,SAAS;AACZ,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B;AAAA,IACA,KAAK,QAAQ;AACX,aAAO,UAAU;AAAA,IACnB;AAAA,IACA,KAAK,aAAa;AAChB,aAAO,UAAU;AAAA,IACnB;AAAA,IACA,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA,SAAS;AACP,aAAO,gBAAgB;AAAA,IACzB;AAAA,EACF;AACF;;;Af3BA,0BAAc;AACd,0BAAc;","names":["isObject","isType","isObject","isType","isObject","deepMerge","isObject","isTruthy","assertEx","isObject","isType"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/index-deprecated.ts","../../src/index-un-deprecated.ts","../../src/asObject.ts","../../src/AsTypeFactory.ts","../../src/AsObjectFactory.ts","../../src/deepMerge.ts","../../src/IsObjectFactory.ts","../../src/JsonObject.ts","../../src/ObjectWrapper.ts","../../src/omitBy.ts","../../src/pickBy.ts","../../src/removeFields.ts","../../src/toSafeJson.ts","../../src/Validator.ts","../../src/isType.ts"],"sourcesContent":["export * from './index-deprecated.ts'\nexport * from './index-un-deprecated.ts'\n","export * from './index-un-deprecated.ts'\nexport * from './isType.ts'\n","export * from './asObject.ts'\nexport * from './AsObjectFactory.ts'\nexport * from './AsTypeFactory.ts'\nexport * from './deepMerge.ts'\nexport * from './IsObjectFactory.ts'\nexport * from './JsonObject.ts'\nexport * from './ObjectWrapper.ts'\nexport * from './omitBy.ts'\nexport * from './OmitStartsWith.ts'\nexport * from './Optional.ts'\nexport * from './Override.ts'\nexport * from './PartialRecord.ts'\nexport * from './pickBy.ts'\nexport * from './PickStartsWith.ts'\nexport * from './removeFields.ts'\nexport * from './Simplify.ts'\nexport * from './StringKeyObject.ts'\nexport * from './toSafeJson.ts'\nexport * from './Validator.ts'\nexport * from './WithAdditional.ts'\nexport * from '@xylabs/object-model'\nexport { isObject } from '@xylabs/typeof'\n","import type { AnyObject } from '@xylabs/object-model'\nimport { isObject } from '@xylabs/typeof'\n\nimport { AsObjectFactory } from './AsObjectFactory.ts'\n\n/** Type-narrowing function that casts a value to AnyObject if it is a plain object, or returns undefined. */\nexport const asAnyObject = (() => AsObjectFactory.create<AnyObject>(<T extends AnyObject>(obj: unknown): obj is T => isObject(obj)))()\n","import { assertDefinedEx } from '@xylabs/assert'\nimport type {\n AsTypeFunction,\n StringOrAlertFunction, TypeCheck, TypeCheckConfig,\n TypeCheckRequiredConfig,\n} from '@xylabs/object-model'\nimport type { AnyNonPromise } from '@xylabs/promise'\nimport { isPromise } from '@xylabs/promise'\nimport { isTruthy } from '@xylabs/typeof'\n\n/**\n * Factory for creating type-narrowing 'as' functions that cast a value to T or return undefined.\n * Supports optional assertion messages and configuration for required/optional behavior.\n */\nexport const AsTypeFactory = {\n create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>): AsTypeFunction<T> => {\n const func = (\n value: AnyNonPromise,\n assertOrConfig?: StringOrAlertFunction<T> | TypeCheckConfig,\n config?: TypeCheckConfig,\n ): T | undefined => {\n // when used as a predicate, it seems that the index is passed as the second parameter (filter,map)\n const isPredicate = typeof assertOrConfig === 'number'\n const resolvedAssert = isPredicate\n ? undefined\n : (typeof assertOrConfig === 'object' ? undefined : assertOrConfig) as (StringOrAlertFunction<T> | undefined)\n const resolvedConfig = isPredicate ? undefined : typeof assertOrConfig === 'object' ? assertOrConfig : config\n\n // only return undefined if not required\n const required = isTruthy((resolvedConfig as (TypeCheckRequiredConfig | undefined))?.required)\n if (!required && (value === undefined || value === null)) {\n return undefined\n }\n\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n\n const result = typeCheck(value, resolvedConfig) ? (value as T) : undefined\n\n if (resolvedAssert !== undefined) {\n return typeof resolvedAssert === 'function' ? assertDefinedEx<T>(result, resolvedAssert) : assertDefinedEx<T>(result, () => resolvedAssert)\n }\n return result\n }\n return func\n },\n createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => {\n const func = (value: AnyNonPromise): T | undefined => {\n if (value === undefined || value === null) return undefined\n if (isPromise(value)) {\n throw new TypeError('un-awaited promises may not be sent to \"as\" functions')\n }\n return typeCheck(value) ? (value as T) : undefined\n }\n return func\n },\n}\n","import type { TypeCheck } from '@xylabs/object-model'\nimport type { TypedObject } from '@xylabs/typeof'\n\nimport { AsTypeFactory } from './AsTypeFactory.ts'\n\n/** Factory for creating type-narrowing functions for TypedObject types. */\nexport const AsObjectFactory = {\n create: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.create<T>(typeCheck)\n },\n createOptional: <T extends TypedObject>(typeCheck: TypeCheck<T>) => {\n return AsTypeFactory.createOptional<T>(typeCheck)\n },\n}\n","import type { AnyObject } from '@xylabs/object-model'\n\n/**\n * Deeply merges two types into a new type.\n */\ntype DeepMerge<A, B> = {\n [K in keyof A | keyof B]:\n K extends keyof B\n ? K extends keyof A\n ? A[K] extends object\n ? B[K] extends object\n ? DeepMerge<A[K], B[K]>\n : B[K]\n : B[K]\n : B[K]\n : K extends keyof A\n ? A[K]\n : never;\n}\n\n/**\n * Merges multiple types into a new type.\n */\ntype MergeAll<T extends object[], R = {}>\n = T extends [infer First extends object, ...infer Rest extends object[]]\n ? MergeAll<Rest, DeepMerge<R, First>>\n : R\n\n/**\n * Options for merging objects in the deep merge function.\n */\ntype MergeOptions = {\n /**\n * Strategy for merging arrays.\n * - 'overwrite': Overwrites the array with the last object's value.\n * - 'concat': Concatenates arrays from all objects.\n * @default 'overwrite'\n */\n arrayStrategy?: 'overwrite' | 'concat'\n /**\n * Mutate the first object in the list instead of creating a new one.\n * @default false\n */\n mutate?: boolean\n}\n\nconst isUnsafeKey = (key: string | symbol): boolean =>\n key === '__proto__' || key === 'constructor' || key === 'prototype'\n\nfunction merge<T extends AnyObject>(target: AnyObject, source?: AnyObject, options?: MergeOptions): T {\n if (!source || typeof source !== 'object') return target as T\n\n for (const key of Reflect.ownKeys(source)) {\n const value = source[key]\n if (isUnsafeKey(key)) {\n continue\n } else if (Array.isArray(value)) {\n target[key]\n // If the value is an array, handle it based on the configured array strategy\n = options?.arrayStrategy === 'concat' && Array.isArray(target[key])\n ? [...target[key], ...value]\n : value\n } else if (value !== null && typeof value === 'object') {\n // Recursively merge nested objects\n if (!target[key] || typeof target[key] !== 'object') {\n target[key] = {}\n }\n merge(target[key] as AnyObject, value as AnyObject, options)\n } else {\n // Overwrite with non-object values\n target[key] = value\n }\n }\n\n return target as T\n}\n\n/**\n * Creates a deep merge function with the specified options.\n * @param options Options for merging.\n * @returns A deep merge function configured for the specified options.\n */\nexport function createDeepMerge(options: MergeOptions) {\n return function deepMerge<T extends AnyObject[]>(...objects: T): MergeAll<T> {\n const result = (options.mutate ? objects[0] ?? {} : {}) as MergeAll<T>\n for (const obj of objects) {\n merge(result, obj, options)\n }\n return result\n }\n}\n\n/**\n * Deeply merges multiple objects into a new object.\n * @param objects Multiple objects to merge deeply.\n * The function merges properties from all objects into a new object.\n * If a property exists in multiple objects, the last object's value will be used.\n * If a property is an object, it will be merged recursively.\n * If a property is an array, it will be overwritten by the last object's value.\n * If a property is a primitive value, it will be overwritten by the last object's value.\n * If a property is undefined in the source, it will be skipped.\n * If a property is a symbol, it will be merged as well.\n * @returns A new object with the merged properties.\n */\nexport const deepMerge = createDeepMerge({ arrayStrategy: 'overwrite', mutate: false })\n","import type { TypeCheck, TypeCheckConfig } from '@xylabs/object-model'\nimport {\n isObject, isTruthy,\n type ObjectTypeShape, type TypedObject,\n} from '@xylabs/typeof'\nimport { isType } from '@xylabs/typeof'\n\n/** Configuration options for object type checking. */\nexport interface ObjectTypeConfig extends TypeCheckConfig {}\n\n/** Factory class for creating type-guard functions that validate objects against a given shape and optional additional checks. */\nexport class IsObjectFactory<T extends TypedObject> {\n /**\n * Creates a type-guard function that validates an object matches the given shape and passes additional checks.\n * @param shape - An optional map of property names to expected types.\n * @param additionalChecks - Optional extra type-check functions to run after shape validation.\n * @returns A type-guard function for type T.\n */\n create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T> {\n return (obj: unknown, config?: TypeCheckConfig | number): obj is T => {\n if (!isObject(obj)) {\n return false\n }\n const log = (typeof config === 'object') ? config.log : undefined\n return (\n // do primary check\n Object.entries(shape ?? {}).filter(([key, type]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const result = isType((obj as any)[key], type)\n if (!result && isTruthy(log)) {\n const logger = typeof log === 'object' ? log : console\n logger.warn(`isType Failed: ${key}: ${type}`)\n }\n return !result\n }).length === 0\n // perform additional checks\n // eslint-disable-next-line unicorn/no-array-reduce\n && (additionalChecks?.reduce((prev, check) => prev && check(obj, { log }), true) ?? true)\n )\n }\n }\n}\n","import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@xylabs/zod'\nimport * as z from 'zod'\n\nconst JsonArrayZod = z.array(z.lazy(() => JsonValueZod))\n\n// Define recursive JSON value schema\nconst JsonValueZod: z.ZodType<unknown> = z.lazy(() =>\n z.union([\n z.string(),\n z.number(),\n z.boolean(),\n z.null(),\n z.array(JsonValueZod),\n z.record(z.string(), JsonValueZod), // object with string keys and JSON values\n ]))\n\n// JSON object schema — top-level must be an object\n/** Zod schema for a JSON object with string keys and recursive JSON values. */\nexport const JsonObjectZod = z.record(z.string(), JsonValueZod)\n\n// TypeScript type for reference\n/** A recursive JSON value: string, number, boolean, null, array, or object. */\nexport type JsonValue = z.infer<typeof JsonValueZod>\n/** A JSON object with string keys and JSON values. */\nexport type JsonObject = z.infer<typeof JsonObjectZod>\n/** A JSON array containing JSON values. */\nexport type JsonArray = z.infer<typeof JsonArrayZod>\n\n/** Type guard that checks if a value is a valid JSON value. */\nexport const isJsonValue = zodIsFactory(JsonValueZod)\n/** Casts a value to JsonValue or returns undefined if it does not conform. */\nexport const asJsonValue = zodAsFactory(JsonValueZod, 'asJsonValue')\n/** Parses a value into a JsonValue, throwing if it does not conform. */\nexport const toJsonValue = zodToFactory(JsonValueZod, 'toJsonValue')\n\n/** Type guard that checks if a value is a valid JSON array. */\nexport const isJsonArray = zodIsFactory(JsonArrayZod)\n/** Casts a value to JsonArray or returns undefined if it does not conform. */\nexport const asJsonArray = zodAsFactory(JsonArrayZod, 'asJsonArray')\n/** Parses a value into a JsonArray, throwing if it does not conform. */\nexport const toJsonArray = zodToFactory(JsonArrayZod, 'toJsonArray')\n\n/** Type guard that checks if a value is a valid JSON object. */\nexport const isJsonObject = zodIsFactory(JsonObjectZod)\n/** Casts a value to JsonObject or returns undefined if it does not conform. */\nexport const asJsonObject = zodAsFactory(JsonObjectZod, 'asJsonObject')\n/** Parses a value into a JsonObject, throwing if it does not conform. */\nexport const toJsonObject = zodToFactory(JsonObjectZod, 'toJsonObject')\n","import type { EmptyObject } from './EmptyObject.ts'\nimport type { StringKeyObject } from './StringKeyObject.ts'\n\n/** Abstract base class that wraps an object and provides typed access to it. */\nexport abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {\n readonly obj: T\n constructor(obj: T) {\n this.obj = obj\n }\n\n protected get stringKeyObj() {\n return this.obj as StringKeyObject\n }\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepOmitStartsWith } from './OmitStartsWith.ts'\n\n/** A predicate function used to determine which properties to omit from an object. */\nexport type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst omitByArray = <T>(\n obj: T[],\n predicate: OmitByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst omitByObject = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (!predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? omitBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\n/**\n * Creates a new object excluding properties that satisfy the predicate, with optional recursive depth.\n * @param obj - The source object to omit properties from.\n * @param predicate - A function that returns true for properties to exclude.\n * @param maxDepth - Maximum recursion depth for nested objects.\n * @returns A partial copy of the object without matching properties.\n */\nexport const omitBy = <T extends EmptyObject>(\n obj: T,\n predicate: OmitByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? omitByArray(obj, predicate, maxDepth - 1) as T : omitByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst omitByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\n/**\n * Omits all properties whose keys start with the given prefix, recursively through nested objects.\n * @param payload - The source object.\n * @param prefix - The string prefix to match keys against.\n * @param maxDepth - Maximum recursion depth.\n * @returns A new object without properties that have matching prefixed keys.\n */\nexport const omitByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepOmitStartsWith<T, P> => {\n return omitBy(payload, omitByPrefixPredicate(prefix), maxDepth) as unknown as DeepOmitStartsWith<T, P>\n}\n","import { assertEx } from '@xylabs/assert'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { JsonObject } from './JsonObject.ts'\nimport type { DeepPickStartsWith } from './PickStartsWith.ts'\n\n/** A predicate function used to determine which properties to pick from an object. */\nexport type PickByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean\n\nconst pickByArray = <T>(\n obj: T[],\n predicate: PickByPredicate,\n maxDepth: number,\n): T[] => {\n return obj.map((value) => {\n return (value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth) : value\n }) as T[]\n}\n\nconst pickByObject = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth: number,\n): Partial<T> => {\n const result: JsonObject = {}\n\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key]\n if (predicate(value, key)) {\n result[key] = ((value !== null && typeof value === 'object') ? pickBy(value, predicate, maxDepth - 1) : value) as JsonObject\n }\n }\n }\n\n return result as T\n}\n\n/**\n * Creates a new object containing only the properties that satisfy the predicate, with optional recursive depth.\n * @param obj - The source object to pick properties from.\n * @param predicate - A function that returns true for properties to include.\n * @param maxDepth - Maximum recursion depth for nested objects.\n * @returns A partial copy of the object with only matching properties.\n */\nexport const pickBy = <T extends EmptyObject>(\n obj: T,\n predicate: PickByPredicate,\n maxDepth = 1,\n): Partial<T> => {\n if (maxDepth <= 0) {\n return obj\n }\n\n return Array.isArray(obj) ? pickByArray(obj, predicate, maxDepth - 1) as T : pickByObject(obj, predicate, maxDepth - 1) as T\n}\n\nconst pickByPrefixPredicate = (prefix: string) => (_: unknown, key: string) => {\n assertEx(typeof key === 'string', () => `Invalid key type [${key}, ${typeof key}]`)\n return key.startsWith(prefix)\n}\n\n/**\n * Picks all properties whose keys start with the given prefix, recursively through nested objects.\n * @param payload - The source object.\n * @param prefix - The string prefix to match keys against.\n * @param maxDepth - Maximum recursion depth.\n * @returns A new object containing only properties with matching prefixed keys.\n */\nexport const pickByPrefix = <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth = 100): DeepPickStartsWith<T, P> => {\n return pickBy(payload, pickByPrefixPredicate(prefix), maxDepth) as unknown as DeepPickStartsWith<T, P>\n}\n","import type { EmptyObject } from './EmptyObject.ts'\n\n/**\n * Returns a shallow copy of the object with the specified fields removed.\n * @param obj - The source object.\n * @param fields - An array of keys to remove.\n * @returns A new object without the specified fields.\n */\nexport const removeFields = <T extends EmptyObject, K extends keyof T>(obj: T, fields: K[]): Omit<T, K> => {\n const clone = { ...obj }\n for (const field of fields) {\n delete clone[field]\n }\n return clone\n}\n","import type {\n JsonArray, JsonObject, JsonValue,\n} from './JsonObject.ts'\n\n/**\n * Converts an array to a JSON-safe array, handling circular references and depth limits.\n * @param value - The array to convert.\n * @param cycleList - Tracks visited objects to detect circular references.\n * @param maxDepth - Maximum recursion depth before truncating.\n * @returns A JSON-safe array representation.\n */\nexport const toSafeJsonArray = (value: unknown[], cycleList?: unknown[], maxDepth = 3): JsonArray => {\n return value.map(item => toSafeJsonValue(item, cycleList, maxDepth))\n}\n\n/**\n * Converts an object to a JSON-safe object, handling circular references and depth limits.\n * @param value - The object to convert.\n * @param cycleList - Tracks visited objects to detect circular references.\n * @param maxDepth - Maximum recursion depth before truncating.\n * @returns A JSON-safe object representation.\n */\nexport const toSafeJsonObject = (value: object, cycleList?: unknown[], maxDepth = 3): JsonObject => {\n const result: JsonObject = {}\n for (const [key, entry] of Object.entries(value)) {\n result[key] = value === undefined ? '[Undefined]' : toSafeJsonValue(entry, cycleList, maxDepth)\n }\n return result\n}\n\n/**\n * Converts an unknown value to a JSON-safe value, replacing circular references with '[Circular]' and\n * non-JSON types with descriptive placeholder strings.\n * @param value - The value to convert.\n * @param cycleList - Tracks visited objects to detect circular references.\n * @param maxDepth - Maximum recursion depth before truncating with '[MaxDepth]'.\n * @returns A JSON-safe representation of the value.\n */\nexport const toSafeJsonValue = (value: unknown, cycleList?: unknown[], maxDepth = 3): JsonValue => {\n if (maxDepth <= 0 && typeof value === 'object') {\n return '[MaxDepth]'\n }\n if (cycleList?.includes(value)) {\n return '[Circular]'\n }\n switch (typeof value) {\n case 'string':\n case 'boolean':\n case 'number': {\n return value\n }\n case 'object': {\n if (value === null) {\n return null\n }\n const newCycleList = cycleList ?? []\n newCycleList.push(value)\n return Array.isArray(value) ? toSafeJsonArray(value, newCycleList, maxDepth - 1) : toSafeJsonObject(value, newCycleList, maxDepth - 1)\n }\n default: {\n return `[${typeof value}]`\n }\n }\n}\n\n/**\n * Converts a value to a pretty-printed JSON string, safely handling circular references and non-JSON types.\n * @param value - The value to serialize.\n * @param maxDepth - Maximum recursion depth.\n * @returns A formatted JSON string.\n */\nexport const toSafeJsonString = (value: unknown, maxDepth = 3) => {\n return JSON.stringify(toSafeJson(value, maxDepth), null, 2)\n}\n\n/**\n * Converts a value to a JSON-safe representation, handling circular references and non-serializable types.\n * @param value - The value to convert.\n * @param maxDepth - Maximum recursion depth.\n * @returns A JSON-safe value.\n */\nexport const toSafeJson = (value: unknown, maxDepth = 3): JsonValue => {\n return toSafeJsonValue(value, undefined, maxDepth)\n}\n","import type { AnyObject } from '@xylabs/object-model'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport { ObjectWrapper } from './ObjectWrapper.ts'\n\n/** Interface for validating objects and returning any errors found. */\nexport interface Validator<T extends EmptyObject = AnyObject> {\n validate(payload: T): Promisable<Error[]>\n}\n\n/** Abstract base class for validators that wraps a partial object and provides a validation method. */\nexport abstract class ValidatorBase<T extends EmptyObject = AnyObject> extends ObjectWrapper<Partial<T>> implements Validator<T> {\n abstract validate(payload: T): Promisable<Error[]>\n}\n","import type { FieldType } from '@xylabs/typeof'\n\n/** @deprecated use from @xylabs/typeof instead */\nexport const isType = (value: unknown, expectedType: FieldType) => {\n const typeofValue = typeof value\n switch (expectedType) {\n case 'array': {\n return Array.isArray(value)\n }\n case 'null': {\n return value === null\n }\n case 'undefined': {\n return value === undefined\n }\n case 'object': {\n // nulls resolve to objects, so exclude them\n if (value === null) {\n return false\n }\n // arrays resolve to objects, so exclude them\n return typeofValue === 'object' && !Array.isArray(value)\n }\n default: {\n return typeofValue === expectedType\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBA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MACT;AACA,YAAM,eAAe,aAAa,CAAC;AACnC,mBAAa,KAAK,KAAK;AACvB,aAAO,MAAM,QAAQ,KAAK,IAAI,gBAAgB,OAAO,cAAc,WAAW,CAAC,IAAI,iBAAiB,OAAO,cAAc,WAAW,CAAC;AAAA,IACvI;AAAA,IACA,SAAS;AACP,aAAO,IAAI,OAAO,KAAK;AAAA,IACzB;AAAA,EACF;AACF;AAQO,IAAM,mBAAmB,CAAC,OAAgB,WAAW,MAAM;AAChE,SAAO,KAAK,UAAU,WAAW,OAAO,QAAQ,GAAG,MAAM,CAAC;AAC5D;AAQO,IAAM,aAAa,CAAC,OAAgB,WAAW,MAAiB;AACrE,SAAO,gBAAgB,OAAO,QAAW,QAAQ;AACnD;;;ACvEO,IAAe,gBAAf,cAAwE,cAAkD;AAEjI;;;AZMA;AAAA,mCAAc;AACd,SAAS,YAAAC,iBAAgB;;;ADrBzB,qCAAc;;;AcGP,IAAMC,UAAS,CAAC,OAAgB,iBAA4B;AACjE,QAAM,cAAc,OAAO;AAC3B,UAAQ,cAAc;AAAA,IACpB,KAAK,SAAS;AACZ,aAAO,MAAM,QAAQ,KAAK;AAAA,IAC5B;AAAA,IACA,KAAK,QAAQ;AACX,aAAO,UAAU;AAAA,IACnB;AAAA,IACA,KAAK,aAAa;AAChB,aAAO,UAAU;AAAA,IACnB;AAAA,IACA,KAAK,UAAU;AAEb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,MACT;AAEA,aAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,KAAK;AAAA,IACzD;AAAA,IACA,SAAS;AACP,aAAO,gBAAgB;AAAA,IACzB;AAAA,EACF;AACF;;;Af3BA,0BAAc;AACd,0BAAc;","names":["isObject","isType","isObject","isType","isObject","deepMerge","isObject","isTruthy","assertEx","isObject","isType"]}
|
package/dist/neutral/omitBy.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { EmptyObject } from './EmptyObject.ts';
|
|
2
2
|
import type { DeepOmitStartsWith } from './OmitStartsWith.ts';
|
|
3
|
+
/** A predicate function used to determine which properties to omit from an object. */
|
|
3
4
|
export type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new object excluding properties that satisfy the predicate, with optional recursive depth.
|
|
7
|
+
* @param obj - The source object to omit properties from.
|
|
8
|
+
* @param predicate - A function that returns true for properties to exclude.
|
|
9
|
+
* @param maxDepth - Maximum recursion depth for nested objects.
|
|
10
|
+
* @returns A partial copy of the object without matching properties.
|
|
11
|
+
*/
|
|
4
12
|
export declare const omitBy: <T extends EmptyObject>(obj: T, predicate: OmitByPredicate, maxDepth?: number) => Partial<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Omits all properties whose keys start with the given prefix, recursively through nested objects.
|
|
15
|
+
* @param payload - The source object.
|
|
16
|
+
* @param prefix - The string prefix to match keys against.
|
|
17
|
+
* @param maxDepth - Maximum recursion depth.
|
|
18
|
+
* @returns A new object without properties that have matching prefixed keys.
|
|
19
|
+
*/
|
|
5
20
|
export declare const omitByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepOmitStartsWith<T, P>;
|
|
6
21
|
//# sourceMappingURL=omitBy.d.ts.map
|