@xylabs/object 5.0.38 → 5.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/neutral/JsonObject.d.ts +34 -17
- package/dist/neutral/JsonObject.d.ts.map +1 -1
- package/dist/neutral/index-un-deprecated.mjs +32 -82
- package/dist/neutral/index-un-deprecated.mjs.map +1 -1
- package/dist/neutral/index.mjs +47 -94
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +7 -5
- package/src/JsonObject.ts +37 -101
|
@@ -1,19 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export type
|
|
6
|
-
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
declare const JsonArrayZod: z.ZodArray<z.ZodLazy<z.ZodType<unknown, unknown, z.z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
3
|
+
declare const JsonValueZod: z.ZodType<unknown>;
|
|
4
|
+
export declare const JsonObjectZod: z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
5
|
+
export type JsonValue = z.infer<typeof JsonValueZod>;
|
|
6
|
+
export type JsonObject = z.infer<typeof JsonObjectZod>;
|
|
7
|
+
export type JsonArray = z.infer<typeof JsonArrayZod>;
|
|
8
|
+
export declare const isJsonValue: (value: unknown) => value is unknown;
|
|
9
|
+
export declare const asJsonValue: {
|
|
10
|
+
(value: unknown): unknown;
|
|
11
|
+
(value: unknown, assert: import("@xylabs/zod").ZodFactoryConfig): unknown;
|
|
7
12
|
};
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export declare const toJsonArray:
|
|
18
|
-
|
|
13
|
+
export declare const toJsonValue: {
|
|
14
|
+
(value: unknown): unknown;
|
|
15
|
+
(value: unknown, assert: import("@xylabs/zod").ZodFactoryConfig): unknown;
|
|
16
|
+
};
|
|
17
|
+
export declare const isJsonArray: (value: unknown) => value is unknown[];
|
|
18
|
+
export declare const asJsonArray: {
|
|
19
|
+
(value: unknown): unknown[] | undefined;
|
|
20
|
+
(value: unknown, assert: import("@xylabs/zod").ZodFactoryConfig): unknown[];
|
|
21
|
+
};
|
|
22
|
+
export declare const toJsonArray: {
|
|
23
|
+
(value: unknown): unknown[] | undefined;
|
|
24
|
+
(value: unknown, assert: import("@xylabs/zod").ZodFactoryConfig): unknown[];
|
|
25
|
+
};
|
|
26
|
+
export declare const isJsonObject: (value: unknown) => value is Record<string, unknown>;
|
|
27
|
+
export declare const asJsonObject: {
|
|
28
|
+
(value: unknown): Record<string, unknown> | undefined;
|
|
29
|
+
(value: unknown, assert: import("@xylabs/zod").ZodFactoryConfig): Record<string, unknown>;
|
|
30
|
+
};
|
|
31
|
+
export declare const toJsonObject: {
|
|
32
|
+
(value: unknown): Record<string, unknown> | undefined;
|
|
33
|
+
(value: unknown, assert: import("@xylabs/zod").ZodFactoryConfig): Record<string, unknown>;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
19
36
|
//# sourceMappingURL=JsonObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonObject.d.ts","sourceRoot":"","sources":["../../src/JsonObject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JsonObject.d.ts","sourceRoot":"","sources":["../../src/JsonObject.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,QAAA,MAAM,YAAY,kGAAsC,CAAA;AAGxD,QAAA,MAAM,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAQhC,CAAA;AAGL,eAAO,MAAM,aAAa,qGAAqC,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,sCAAwC,CAAA;AAChE,eAAO,MAAM,WAAW;;;CAAuD,CAAA;AAC/E,eAAO,MAAM,WAAW;;;CAAuD,CAAA;AAE/E,eAAO,MAAM,WAAW,wCAAwC,CAAA;AAChE,eAAO,MAAM,WAAW;;;CAAuD,CAAA;AAC/E,eAAO,MAAM,WAAW;;;CAAuD,CAAA;AAE/E,eAAO,MAAM,YAAY,sDAA0C,CAAA;AACnE,eAAO,MAAM,YAAY;;;CAA0D,CAAA;AACnF,eAAO,MAAM,YAAY;;;CAA0D,CAAA"}
|
|
@@ -112,83 +112,32 @@ var IsObjectFactory = class {
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
// src/JsonObject.ts
|
|
115
|
-
import {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
const [key, val] = value;
|
|
143
|
-
return isString(key) && isJsonValue(val);
|
|
144
|
-
};
|
|
145
|
-
var isJsonObject = (value) => {
|
|
146
|
-
return isObject3(value) && !Object.entries(value).some((item) => !isValidJsonFieldPair(item));
|
|
147
|
-
};
|
|
148
|
-
var toJsonObject = (value) => {
|
|
149
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
150
|
-
throw new TypeError(`Expected an object, got ${typeof value}`);
|
|
151
|
-
}
|
|
152
|
-
if (isJsonObject(value)) {
|
|
153
|
-
return value;
|
|
154
|
-
}
|
|
155
|
-
const result = {};
|
|
156
|
-
for (const [k, v] of Object.entries(value)) {
|
|
157
|
-
if (v !== void 0) {
|
|
158
|
-
const [key, jsonValue] = toValidJsonFieldPair([k, v]);
|
|
159
|
-
result[key] = jsonValue;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return result;
|
|
163
|
-
};
|
|
164
|
-
var toJsonValue = (value) => {
|
|
165
|
-
if (isObject3(value)) {
|
|
166
|
-
return toJsonObject(value);
|
|
167
|
-
} else if (Array.isArray(value)) {
|
|
168
|
-
return toJsonArray(value);
|
|
169
|
-
} else if (isJsonValue(value)) {
|
|
170
|
-
return value;
|
|
171
|
-
}
|
|
172
|
-
throw new TypeError(`Unable to coerce ${typeof value} to a JSON value`);
|
|
173
|
-
};
|
|
174
|
-
var toJsonArray = (value) => {
|
|
175
|
-
if (Array.isArray(value)) {
|
|
176
|
-
return value.map((item) => toJsonValue(item));
|
|
177
|
-
}
|
|
178
|
-
throw new TypeError(`Unable to coerce ${typeof value} to a JSON array`);
|
|
179
|
-
};
|
|
180
|
-
var toValidJsonFieldPair = (pair) => {
|
|
181
|
-
const [key, value] = pair;
|
|
182
|
-
if (!isString(key)) {
|
|
183
|
-
throw new TypeError(`Expected a string key, got ${typeof key}`);
|
|
184
|
-
}
|
|
185
|
-
if (isJsonValue(value)) {
|
|
186
|
-
return [key, value];
|
|
187
|
-
} else if (isObject3(value)) {
|
|
188
|
-
return [key, toJsonObject(value)];
|
|
189
|
-
}
|
|
190
|
-
throw new TypeError(`Expected a valid JSON value, got ${typeof value}`);
|
|
191
|
-
};
|
|
115
|
+
import {
|
|
116
|
+
zodAsFactory,
|
|
117
|
+
zodIsFactory,
|
|
118
|
+
zodToFactory
|
|
119
|
+
} from "@xylabs/zod";
|
|
120
|
+
import z from "zod";
|
|
121
|
+
var JsonArrayZod = z.array(z.lazy(() => JsonValueZod));
|
|
122
|
+
var JsonValueZod = z.lazy(() => z.union([
|
|
123
|
+
z.string(),
|
|
124
|
+
z.number(),
|
|
125
|
+
z.boolean(),
|
|
126
|
+
z.null(),
|
|
127
|
+
z.array(JsonValueZod),
|
|
128
|
+
z.record(z.string(), JsonValueZod)
|
|
129
|
+
// object with string keys and JSON values
|
|
130
|
+
]));
|
|
131
|
+
var JsonObjectZod = z.record(z.string(), JsonValueZod);
|
|
132
|
+
var isJsonValue = zodIsFactory(JsonValueZod);
|
|
133
|
+
var asJsonValue = zodAsFactory(JsonValueZod, "asJsonValue");
|
|
134
|
+
var toJsonValue = zodToFactory(JsonValueZod, "toJsonValue");
|
|
135
|
+
var isJsonArray = zodIsFactory(JsonArrayZod);
|
|
136
|
+
var asJsonArray = zodAsFactory(JsonArrayZod, "asJsonArray");
|
|
137
|
+
var toJsonArray = zodToFactory(JsonArrayZod, "toJsonArray");
|
|
138
|
+
var isJsonObject = zodIsFactory(JsonObjectZod);
|
|
139
|
+
var asJsonObject = zodAsFactory(JsonObjectZod, "asJsonObject");
|
|
140
|
+
var toJsonObject = zodToFactory(JsonObjectZod, "toJsonObject");
|
|
192
141
|
|
|
193
142
|
// src/ObjectWrapper.ts
|
|
194
143
|
var ObjectWrapper = class {
|
|
@@ -326,22 +275,24 @@ var ValidatorBase = class extends ObjectWrapper {
|
|
|
326
275
|
|
|
327
276
|
// src/index-un-deprecated.ts
|
|
328
277
|
export * from "@xylabs/object-model";
|
|
329
|
-
import { isObject as
|
|
278
|
+
import { isObject as isObject3 } from "@xylabs/typeof";
|
|
330
279
|
export {
|
|
331
280
|
AsObjectFactory,
|
|
332
281
|
AsTypeFactory,
|
|
333
282
|
IsObjectFactory,
|
|
283
|
+
JsonObjectZod,
|
|
334
284
|
ObjectWrapper,
|
|
335
285
|
ValidatorBase,
|
|
336
286
|
asAnyObject,
|
|
337
287
|
asJsonArray,
|
|
288
|
+
asJsonObject,
|
|
289
|
+
asJsonValue,
|
|
338
290
|
createDeepMerge,
|
|
339
291
|
deepMerge,
|
|
340
292
|
isJsonArray,
|
|
341
293
|
isJsonObject,
|
|
342
294
|
isJsonValue,
|
|
343
|
-
|
|
344
|
-
isValidJsonFieldPair,
|
|
295
|
+
isObject3 as isObject,
|
|
345
296
|
omitBy,
|
|
346
297
|
omitByPrefix,
|
|
347
298
|
pickBy,
|
|
@@ -354,7 +305,6 @@ export {
|
|
|
354
305
|
toSafeJsonArray,
|
|
355
306
|
toSafeJsonObject,
|
|
356
307
|
toSafeJsonString,
|
|
357
|
-
toSafeJsonValue
|
|
358
|
-
toValidJsonFieldPair
|
|
308
|
+
toSafeJsonValue
|
|
359
309
|
};
|
|
360
310
|
//# sourceMappingURL=index-un-deprecated.mjs.map
|
|
@@ -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 { isObject, isString } from '@xylabs/typeof'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { DeepRestrictToStringKeys } from './OmitStartsWith.ts'\n\nexport type JsonFieldPair = [key: string, value: JsonValue]\nexport type JsonValue = string | number | boolean | null | JsonObject | JsonArray\nexport type JsonObject = { [key: string]: JsonValue }\nexport type JsonTypedObject<T extends EmptyObject = EmptyObject> = DeepRestrictToStringKeys<T>\nexport type JsonArray = JsonValue[]\n\nexport const isJsonValue = (value: unknown): value is JsonValue => {\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean': {\n return true\n }\n default: {\n return value === null || isJsonObject(value) || isJsonArray(value)\n }\n }\n}\n\nexport const isJsonArray = (value: unknown): value is JsonArray => {\n return Array.isArray(value) && !value.some(item => !isJsonValue(item))\n}\n\nexport const asJsonArray = (value: unknown): JsonArray => {\n if (Array.isArray(value)) {\n return value.filter(isJsonValue)\n } else {\n throw new TypeError(`Expected an array, got ${typeof value}`)\n }\n}\n\nexport const isValidJsonFieldPair = (value: unknown): value is JsonFieldPair => {\n if (!Array.isArray(value) || value.length !== 2) {\n return false\n }\n const [key, val] = value\n return isString(key) && isJsonValue(val)\n}\n\nexport const isJsonObject = (value: unknown): value is JsonObject => {\n return (\n isObject(value)\n // check if all keys are strings\n && !Object.entries(value).some(item => !isValidJsonFieldPair(item))\n )\n}\n\nexport const toJsonObject = (value: unknown): JsonObject => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(`Expected an object, got ${typeof value}`)\n }\n if (isJsonObject(value)) {\n return value\n }\n const result: JsonObject = {}\n for (const [k, v] of Object.entries(value)) {\n if (v !== undefined) {\n const [key, jsonValue] = toValidJsonFieldPair([k, v])\n result[key] = jsonValue\n }\n }\n return result\n}\n\nexport const toJsonValue = (value: unknown): JsonValue => {\n if (isObject(value)) {\n return toJsonObject(value)\n } else if (Array.isArray(value)) {\n return toJsonArray(value)\n } else if (isJsonValue(value)) {\n return value\n }\n throw new TypeError(`Unable to coerce ${typeof value} to a JSON value`)\n}\n\nexport const toJsonArray = (value: unknown): JsonArray => {\n if (Array.isArray(value)) {\n return value.map(item => toJsonValue(item))\n }\n throw new TypeError(`Unable to coerce ${typeof value} to a JSON array`)\n}\n\nexport const toValidJsonFieldPair = (pair: [key: unknown, value: unknown]): JsonFieldPair => {\n const [key, value] = pair\n if (!isString(key)) {\n throw new TypeError(`Expected a string key, got ${typeof key}`)\n }\n\n if (isJsonValue(value)) {\n return [key, value]\n } else if (isObject(value)) {\n return [key, toJsonObject(value)]\n }\n\n throw new TypeError(`Expected a valid JSON value, got ${typeof value}`)\n}\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,UAAU,UAAa,UAAU,KAAM,QAAO;AAClD,UAAI,UAAU,KA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;AACb,aAAO;AAAA,IACT;AAAA,IACA,KAAK,UAAU;AACb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,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;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","isObject","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\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 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<JsonValue>(JsonValueZod)\nexport const asJsonValue = zodAsFactory<JsonValue>(JsonValueZod, 'asJsonValue')\nexport const toJsonValue = zodToFactory<JsonValue>(JsonValueZod, 'toJsonValue')\n\nexport const isJsonArray = zodIsFactory<JsonArray>(JsonArrayZod)\nexport const asJsonArray = zodAsFactory<JsonArray>(JsonArrayZod, 'asJsonArray')\nexport const toJsonArray = zodToFactory<JsonArray>(JsonArrayZod, 'toJsonArray')\n\nexport const isJsonObject = zodIsFactory<JsonObject>(JsonObjectZod)\nexport const asJsonObject = zodAsFactory<JsonObject>(JsonObjectZod, 'asJsonObject')\nexport const toJsonObject = zodToFactory<JsonObject>(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,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C,OAAe,WAAuB,WAAW,MAAkB;AAClG,QAAM,SAAqB,CAAC;AAC5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,WAAO,GAAG,IAAI,UAAU,SAAY,gBAAgB,gBAAgB,OAAO,WAAW,QAAQ;AAAA,EAChG;AACA,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAC,OAAgB,WAAuB,WAAW,MAAiB;AACjG,MAAI,YAAY,KAAK,OAAO,UAAU,UAAU;AAC9C,WAAO;AAAA,EACT;AACA,MAAI,WAAW,SAAS,KAAK,GAAG;AAC9B,WAAO;AAAA,EACT;AACA,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,UAAU;AACb,aAAO;AAAA,IACT;AAAA,IACA,KAAK,UAAU;AACb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,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;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"]}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -22,18 +22,20 @@ __export(index_exports, {
|
|
|
22
22
|
AsObjectFactory: () => AsObjectFactory,
|
|
23
23
|
AsTypeFactory: () => AsTypeFactory,
|
|
24
24
|
IsObjectFactory: () => IsObjectFactory,
|
|
25
|
+
JsonObjectZod: () => JsonObjectZod,
|
|
25
26
|
ObjectWrapper: () => ObjectWrapper,
|
|
26
27
|
ValidatorBase: () => ValidatorBase,
|
|
27
28
|
asAnyObject: () => asAnyObject,
|
|
28
29
|
asJsonArray: () => asJsonArray,
|
|
30
|
+
asJsonObject: () => asJsonObject,
|
|
31
|
+
asJsonValue: () => asJsonValue,
|
|
29
32
|
createDeepMerge: () => createDeepMerge,
|
|
30
33
|
deepMerge: () => deepMerge,
|
|
31
34
|
isJsonArray: () => isJsonArray,
|
|
32
35
|
isJsonObject: () => isJsonObject,
|
|
33
36
|
isJsonValue: () => isJsonValue,
|
|
34
|
-
isObject: () =>
|
|
37
|
+
isObject: () => isObject3,
|
|
35
38
|
isType: () => isType2,
|
|
36
|
-
isValidJsonFieldPair: () => isValidJsonFieldPair,
|
|
37
39
|
omitBy: () => omitBy,
|
|
38
40
|
omitByPrefix: () => omitByPrefix,
|
|
39
41
|
pickBy: () => pickBy,
|
|
@@ -46,8 +48,7 @@ __export(index_exports, {
|
|
|
46
48
|
toSafeJsonArray: () => toSafeJsonArray,
|
|
47
49
|
toSafeJsonObject: () => toSafeJsonObject,
|
|
48
50
|
toSafeJsonString: () => toSafeJsonString,
|
|
49
|
-
toSafeJsonValue: () => toSafeJsonValue
|
|
50
|
-
toValidJsonFieldPair: () => toValidJsonFieldPair
|
|
51
|
+
toSafeJsonValue: () => toSafeJsonValue
|
|
51
52
|
});
|
|
52
53
|
|
|
53
54
|
// src/index-deprecated.ts
|
|
@@ -56,18 +57,20 @@ __export(index_deprecated_exports, {
|
|
|
56
57
|
AsObjectFactory: () => AsObjectFactory,
|
|
57
58
|
AsTypeFactory: () => AsTypeFactory,
|
|
58
59
|
IsObjectFactory: () => IsObjectFactory,
|
|
60
|
+
JsonObjectZod: () => JsonObjectZod,
|
|
59
61
|
ObjectWrapper: () => ObjectWrapper,
|
|
60
62
|
ValidatorBase: () => ValidatorBase,
|
|
61
63
|
asAnyObject: () => asAnyObject,
|
|
62
64
|
asJsonArray: () => asJsonArray,
|
|
65
|
+
asJsonObject: () => asJsonObject,
|
|
66
|
+
asJsonValue: () => asJsonValue,
|
|
63
67
|
createDeepMerge: () => createDeepMerge,
|
|
64
68
|
deepMerge: () => deepMerge,
|
|
65
69
|
isJsonArray: () => isJsonArray,
|
|
66
70
|
isJsonObject: () => isJsonObject,
|
|
67
71
|
isJsonValue: () => isJsonValue,
|
|
68
|
-
isObject: () =>
|
|
72
|
+
isObject: () => isObject3,
|
|
69
73
|
isType: () => isType2,
|
|
70
|
-
isValidJsonFieldPair: () => isValidJsonFieldPair,
|
|
71
74
|
omitBy: () => omitBy,
|
|
72
75
|
omitByPrefix: () => omitByPrefix,
|
|
73
76
|
pickBy: () => pickBy,
|
|
@@ -80,8 +83,7 @@ __export(index_deprecated_exports, {
|
|
|
80
83
|
toSafeJsonArray: () => toSafeJsonArray,
|
|
81
84
|
toSafeJsonObject: () => toSafeJsonObject,
|
|
82
85
|
toSafeJsonString: () => toSafeJsonString,
|
|
83
|
-
toSafeJsonValue: () => toSafeJsonValue
|
|
84
|
-
toValidJsonFieldPair: () => toValidJsonFieldPair
|
|
86
|
+
toSafeJsonValue: () => toSafeJsonValue
|
|
85
87
|
});
|
|
86
88
|
|
|
87
89
|
// src/index-un-deprecated.ts
|
|
@@ -90,17 +92,19 @@ __export(index_un_deprecated_exports, {
|
|
|
90
92
|
AsObjectFactory: () => AsObjectFactory,
|
|
91
93
|
AsTypeFactory: () => AsTypeFactory,
|
|
92
94
|
IsObjectFactory: () => IsObjectFactory,
|
|
95
|
+
JsonObjectZod: () => JsonObjectZod,
|
|
93
96
|
ObjectWrapper: () => ObjectWrapper,
|
|
94
97
|
ValidatorBase: () => ValidatorBase,
|
|
95
98
|
asAnyObject: () => asAnyObject,
|
|
96
99
|
asJsonArray: () => asJsonArray,
|
|
100
|
+
asJsonObject: () => asJsonObject,
|
|
101
|
+
asJsonValue: () => asJsonValue,
|
|
97
102
|
createDeepMerge: () => createDeepMerge,
|
|
98
103
|
deepMerge: () => deepMerge,
|
|
99
104
|
isJsonArray: () => isJsonArray,
|
|
100
105
|
isJsonObject: () => isJsonObject,
|
|
101
106
|
isJsonValue: () => isJsonValue,
|
|
102
|
-
isObject: () =>
|
|
103
|
-
isValidJsonFieldPair: () => isValidJsonFieldPair,
|
|
107
|
+
isObject: () => isObject3,
|
|
104
108
|
omitBy: () => omitBy,
|
|
105
109
|
omitByPrefix: () => omitByPrefix,
|
|
106
110
|
pickBy: () => pickBy,
|
|
@@ -113,8 +117,7 @@ __export(index_un_deprecated_exports, {
|
|
|
113
117
|
toSafeJsonArray: () => toSafeJsonArray,
|
|
114
118
|
toSafeJsonObject: () => toSafeJsonObject,
|
|
115
119
|
toSafeJsonString: () => toSafeJsonString,
|
|
116
|
-
toSafeJsonValue: () => toSafeJsonValue
|
|
117
|
-
toValidJsonFieldPair: () => toValidJsonFieldPair
|
|
120
|
+
toSafeJsonValue: () => toSafeJsonValue
|
|
118
121
|
});
|
|
119
122
|
|
|
120
123
|
// src/asObject.ts
|
|
@@ -231,83 +234,32 @@ var IsObjectFactory = class {
|
|
|
231
234
|
};
|
|
232
235
|
|
|
233
236
|
// src/JsonObject.ts
|
|
234
|
-
import {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
var
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
const [key, val] = value;
|
|
262
|
-
return isString(key) && isJsonValue(val);
|
|
263
|
-
};
|
|
264
|
-
var isJsonObject = (value) => {
|
|
265
|
-
return isObject3(value) && !Object.entries(value).some((item) => !isValidJsonFieldPair(item));
|
|
266
|
-
};
|
|
267
|
-
var toJsonObject = (value) => {
|
|
268
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
269
|
-
throw new TypeError(`Expected an object, got ${typeof value}`);
|
|
270
|
-
}
|
|
271
|
-
if (isJsonObject(value)) {
|
|
272
|
-
return value;
|
|
273
|
-
}
|
|
274
|
-
const result = {};
|
|
275
|
-
for (const [k, v] of Object.entries(value)) {
|
|
276
|
-
if (v !== void 0) {
|
|
277
|
-
const [key, jsonValue] = toValidJsonFieldPair([k, v]);
|
|
278
|
-
result[key] = jsonValue;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return result;
|
|
282
|
-
};
|
|
283
|
-
var toJsonValue = (value) => {
|
|
284
|
-
if (isObject3(value)) {
|
|
285
|
-
return toJsonObject(value);
|
|
286
|
-
} else if (Array.isArray(value)) {
|
|
287
|
-
return toJsonArray(value);
|
|
288
|
-
} else if (isJsonValue(value)) {
|
|
289
|
-
return value;
|
|
290
|
-
}
|
|
291
|
-
throw new TypeError(`Unable to coerce ${typeof value} to a JSON value`);
|
|
292
|
-
};
|
|
293
|
-
var toJsonArray = (value) => {
|
|
294
|
-
if (Array.isArray(value)) {
|
|
295
|
-
return value.map((item) => toJsonValue(item));
|
|
296
|
-
}
|
|
297
|
-
throw new TypeError(`Unable to coerce ${typeof value} to a JSON array`);
|
|
298
|
-
};
|
|
299
|
-
var toValidJsonFieldPair = (pair) => {
|
|
300
|
-
const [key, value] = pair;
|
|
301
|
-
if (!isString(key)) {
|
|
302
|
-
throw new TypeError(`Expected a string key, got ${typeof key}`);
|
|
303
|
-
}
|
|
304
|
-
if (isJsonValue(value)) {
|
|
305
|
-
return [key, value];
|
|
306
|
-
} else if (isObject3(value)) {
|
|
307
|
-
return [key, toJsonObject(value)];
|
|
308
|
-
}
|
|
309
|
-
throw new TypeError(`Expected a valid JSON value, got ${typeof value}`);
|
|
310
|
-
};
|
|
237
|
+
import {
|
|
238
|
+
zodAsFactory,
|
|
239
|
+
zodIsFactory,
|
|
240
|
+
zodToFactory
|
|
241
|
+
} from "@xylabs/zod";
|
|
242
|
+
import z from "zod";
|
|
243
|
+
var JsonArrayZod = z.array(z.lazy(() => JsonValueZod));
|
|
244
|
+
var JsonValueZod = z.lazy(() => z.union([
|
|
245
|
+
z.string(),
|
|
246
|
+
z.number(),
|
|
247
|
+
z.boolean(),
|
|
248
|
+
z.null(),
|
|
249
|
+
z.array(JsonValueZod),
|
|
250
|
+
z.record(z.string(), JsonValueZod)
|
|
251
|
+
// object with string keys and JSON values
|
|
252
|
+
]));
|
|
253
|
+
var JsonObjectZod = z.record(z.string(), JsonValueZod);
|
|
254
|
+
var isJsonValue = zodIsFactory(JsonValueZod);
|
|
255
|
+
var asJsonValue = zodAsFactory(JsonValueZod, "asJsonValue");
|
|
256
|
+
var toJsonValue = zodToFactory(JsonValueZod, "toJsonValue");
|
|
257
|
+
var isJsonArray = zodIsFactory(JsonArrayZod);
|
|
258
|
+
var asJsonArray = zodAsFactory(JsonArrayZod, "asJsonArray");
|
|
259
|
+
var toJsonArray = zodToFactory(JsonArrayZod, "toJsonArray");
|
|
260
|
+
var isJsonObject = zodIsFactory(JsonObjectZod);
|
|
261
|
+
var asJsonObject = zodAsFactory(JsonObjectZod, "asJsonObject");
|
|
262
|
+
var toJsonObject = zodToFactory(JsonObjectZod, "toJsonObject");
|
|
311
263
|
|
|
312
264
|
// src/ObjectWrapper.ts
|
|
313
265
|
var ObjectWrapper = class {
|
|
@@ -446,7 +398,7 @@ var ValidatorBase = class extends ObjectWrapper {
|
|
|
446
398
|
// src/index-un-deprecated.ts
|
|
447
399
|
__reExport(index_un_deprecated_exports, object_model_star);
|
|
448
400
|
import * as object_model_star from "@xylabs/object-model";
|
|
449
|
-
import { isObject as
|
|
401
|
+
import { isObject as isObject3 } from "@xylabs/typeof";
|
|
450
402
|
|
|
451
403
|
// src/index-deprecated.ts
|
|
452
404
|
__reExport(index_deprecated_exports, index_un_deprecated_exports);
|
|
@@ -483,18 +435,20 @@ export {
|
|
|
483
435
|
AsObjectFactory,
|
|
484
436
|
AsTypeFactory,
|
|
485
437
|
IsObjectFactory,
|
|
438
|
+
JsonObjectZod,
|
|
486
439
|
ObjectWrapper,
|
|
487
440
|
ValidatorBase,
|
|
488
441
|
asAnyObject,
|
|
489
442
|
asJsonArray,
|
|
443
|
+
asJsonObject,
|
|
444
|
+
asJsonValue,
|
|
490
445
|
createDeepMerge,
|
|
491
446
|
deepMerge,
|
|
492
447
|
isJsonArray,
|
|
493
448
|
isJsonObject,
|
|
494
449
|
isJsonValue,
|
|
495
|
-
|
|
450
|
+
isObject3 as isObject,
|
|
496
451
|
isType2 as isType,
|
|
497
|
-
isValidJsonFieldPair,
|
|
498
452
|
omitBy,
|
|
499
453
|
omitByPrefix,
|
|
500
454
|
pickBy,
|
|
@@ -507,7 +461,6 @@ export {
|
|
|
507
461
|
toSafeJsonArray,
|
|
508
462
|
toSafeJsonObject,
|
|
509
463
|
toSafeJsonString,
|
|
510
|
-
toSafeJsonValue
|
|
511
|
-
toValidJsonFieldPair
|
|
464
|
+
toSafeJsonValue
|
|
512
465
|
};
|
|
513
466
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -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 { isObject, isString } from '@xylabs/typeof'\n\nimport type { EmptyObject } from './EmptyObject.ts'\nimport type { DeepRestrictToStringKeys } from './OmitStartsWith.ts'\n\nexport type JsonFieldPair = [key: string, value: JsonValue]\nexport type JsonValue = string | number | boolean | null | JsonObject | JsonArray\nexport type JsonObject = { [key: string]: JsonValue }\nexport type JsonTypedObject<T extends EmptyObject = EmptyObject> = DeepRestrictToStringKeys<T>\nexport type JsonArray = JsonValue[]\n\nexport const isJsonValue = (value: unknown): value is JsonValue => {\n switch (typeof value) {\n case 'string':\n case 'number':\n case 'boolean': {\n return true\n }\n default: {\n return value === null || isJsonObject(value) || isJsonArray(value)\n }\n }\n}\n\nexport const isJsonArray = (value: unknown): value is JsonArray => {\n return Array.isArray(value) && !value.some(item => !isJsonValue(item))\n}\n\nexport const asJsonArray = (value: unknown): JsonArray => {\n if (Array.isArray(value)) {\n return value.filter(isJsonValue)\n } else {\n throw new TypeError(`Expected an array, got ${typeof value}`)\n }\n}\n\nexport const isValidJsonFieldPair = (value: unknown): value is JsonFieldPair => {\n if (!Array.isArray(value) || value.length !== 2) {\n return false\n }\n const [key, val] = value\n return isString(key) && isJsonValue(val)\n}\n\nexport const isJsonObject = (value: unknown): value is JsonObject => {\n return (\n isObject(value)\n // check if all keys are strings\n && !Object.entries(value).some(item => !isValidJsonFieldPair(item))\n )\n}\n\nexport const toJsonObject = (value: unknown): JsonObject => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError(`Expected an object, got ${typeof value}`)\n }\n if (isJsonObject(value)) {\n return value\n }\n const result: JsonObject = {}\n for (const [k, v] of Object.entries(value)) {\n if (v !== undefined) {\n const [key, jsonValue] = toValidJsonFieldPair([k, v])\n result[key] = jsonValue\n }\n }\n return result\n}\n\nexport const toJsonValue = (value: unknown): JsonValue => {\n if (isObject(value)) {\n return toJsonObject(value)\n } else if (Array.isArray(value)) {\n return toJsonArray(value)\n } else if (isJsonValue(value)) {\n return value\n }\n throw new TypeError(`Unable to coerce ${typeof value} to a JSON value`)\n}\n\nexport const toJsonArray = (value: unknown): JsonArray => {\n if (Array.isArray(value)) {\n return value.map(item => toJsonValue(item))\n }\n throw new TypeError(`Unable to coerce ${typeof value} to a JSON array`)\n}\n\nexport const toValidJsonFieldPair = (pair: [key: unknown, value: unknown]): JsonFieldPair => {\n const [key, value] = pair\n if (!isString(key)) {\n throw new TypeError(`Expected a string key, got ${typeof key}`)\n }\n\n if (isJsonValue(value)) {\n return [key, value]\n } else if (isObject(value)) {\n return [key, toJsonObject(value)]\n }\n\n throw new TypeError(`Expected a valid JSON value, got ${typeof value}`)\n}\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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AAM;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","isObject","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\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 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<JsonValue>(JsonValueZod)\nexport const asJsonValue = zodAsFactory<JsonValue>(JsonValueZod, 'asJsonValue')\nexport const toJsonValue = zodToFactory<JsonValue>(JsonValueZod, 'toJsonValue')\n\nexport const isJsonArray = zodIsFactory<JsonArray>(JsonArrayZod)\nexport const asJsonArray = zodAsFactory<JsonArray>(JsonArrayZod, 'asJsonArray')\nexport const toJsonArray = zodToFactory<JsonArray>(JsonArrayZod, 'toJsonArray')\n\nexport const isJsonObject = zodIsFactory<JsonObject>(JsonObjectZod)\nexport const asJsonObject = zodAsFactory<JsonObject>(JsonObjectZod, 'asJsonObject')\nexport const toJsonObject = zodToFactory<JsonObject>(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,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AAK,UAAU;AACb,UAAI,UAAU,MAAM;AAClB,eAAO;AAAA,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;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;;;AZQA;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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/object",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.40",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -43,10 +43,12 @@
|
|
|
43
43
|
"!**/*.test.*"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@xylabs/assert": "~5.0.
|
|
47
|
-
"@xylabs/object-model": "~5.0.
|
|
48
|
-
"@xylabs/promise": "~5.0.
|
|
49
|
-
"@xylabs/typeof": "~5.0.
|
|
46
|
+
"@xylabs/assert": "~5.0.40",
|
|
47
|
+
"@xylabs/object-model": "~5.0.40",
|
|
48
|
+
"@xylabs/promise": "~5.0.40",
|
|
49
|
+
"@xylabs/typeof": "~5.0.40",
|
|
50
|
+
"@xylabs/zod": "~5.0.40",
|
|
51
|
+
"zod": "~4.1.12"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
package/src/JsonObject.ts
CHANGED
|
@@ -1,101 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export const
|
|
38
|
-
if (!Array.isArray(value) || value.length !== 2) {
|
|
39
|
-
return false
|
|
40
|
-
}
|
|
41
|
-
const [key, val] = value
|
|
42
|
-
return isString(key) && isJsonValue(val)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const isJsonObject = (value: unknown): value is JsonObject => {
|
|
46
|
-
return (
|
|
47
|
-
isObject(value)
|
|
48
|
-
// check if all keys are strings
|
|
49
|
-
&& !Object.entries(value).some(item => !isValidJsonFieldPair(item))
|
|
50
|
-
)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const toJsonObject = (value: unknown): JsonObject => {
|
|
54
|
-
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
55
|
-
throw new TypeError(`Expected an object, got ${typeof value}`)
|
|
56
|
-
}
|
|
57
|
-
if (isJsonObject(value)) {
|
|
58
|
-
return value
|
|
59
|
-
}
|
|
60
|
-
const result: JsonObject = {}
|
|
61
|
-
for (const [k, v] of Object.entries(value)) {
|
|
62
|
-
if (v !== undefined) {
|
|
63
|
-
const [key, jsonValue] = toValidJsonFieldPair([k, v])
|
|
64
|
-
result[key] = jsonValue
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return result
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const toJsonValue = (value: unknown): JsonValue => {
|
|
71
|
-
if (isObject(value)) {
|
|
72
|
-
return toJsonObject(value)
|
|
73
|
-
} else if (Array.isArray(value)) {
|
|
74
|
-
return toJsonArray(value)
|
|
75
|
-
} else if (isJsonValue(value)) {
|
|
76
|
-
return value
|
|
77
|
-
}
|
|
78
|
-
throw new TypeError(`Unable to coerce ${typeof value} to a JSON value`)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const toJsonArray = (value: unknown): JsonArray => {
|
|
82
|
-
if (Array.isArray(value)) {
|
|
83
|
-
return value.map(item => toJsonValue(item))
|
|
84
|
-
}
|
|
85
|
-
throw new TypeError(`Unable to coerce ${typeof value} to a JSON array`)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export const toValidJsonFieldPair = (pair: [key: unknown, value: unknown]): JsonFieldPair => {
|
|
89
|
-
const [key, value] = pair
|
|
90
|
-
if (!isString(key)) {
|
|
91
|
-
throw new TypeError(`Expected a string key, got ${typeof key}`)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (isJsonValue(value)) {
|
|
95
|
-
return [key, value]
|
|
96
|
-
} else if (isObject(value)) {
|
|
97
|
-
return [key, toJsonObject(value)]
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
throw new TypeError(`Expected a valid JSON value, got ${typeof value}`)
|
|
101
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
zodAsFactory, zodIsFactory, zodToFactory,
|
|
3
|
+
} from '@xylabs/zod'
|
|
4
|
+
import z from 'zod'
|
|
5
|
+
|
|
6
|
+
const JsonArrayZod = z.array(z.lazy(() => JsonValueZod))
|
|
7
|
+
|
|
8
|
+
// Define recursive JSON value schema
|
|
9
|
+
const JsonValueZod: z.ZodType<unknown> = z.lazy(() =>
|
|
10
|
+
z.union([
|
|
11
|
+
z.string(),
|
|
12
|
+
z.number(),
|
|
13
|
+
z.boolean(),
|
|
14
|
+
z.null(),
|
|
15
|
+
z.array(JsonValueZod),
|
|
16
|
+
z.record(z.string(), JsonValueZod), // object with string keys and JSON values
|
|
17
|
+
]))
|
|
18
|
+
|
|
19
|
+
// JSON object schema — top-level must be an object
|
|
20
|
+
export const JsonObjectZod = z.record(z.string(), JsonValueZod)
|
|
21
|
+
|
|
22
|
+
// TypeScript type for reference
|
|
23
|
+
export type JsonValue = z.infer<typeof JsonValueZod>
|
|
24
|
+
export type JsonObject = z.infer<typeof JsonObjectZod>
|
|
25
|
+
export type JsonArray = z.infer<typeof JsonArrayZod>
|
|
26
|
+
|
|
27
|
+
export const isJsonValue = zodIsFactory<JsonValue>(JsonValueZod)
|
|
28
|
+
export const asJsonValue = zodAsFactory<JsonValue>(JsonValueZod, 'asJsonValue')
|
|
29
|
+
export const toJsonValue = zodToFactory<JsonValue>(JsonValueZod, 'toJsonValue')
|
|
30
|
+
|
|
31
|
+
export const isJsonArray = zodIsFactory<JsonArray>(JsonArrayZod)
|
|
32
|
+
export const asJsonArray = zodAsFactory<JsonArray>(JsonArrayZod, 'asJsonArray')
|
|
33
|
+
export const toJsonArray = zodToFactory<JsonArray>(JsonArrayZod, 'toJsonArray')
|
|
34
|
+
|
|
35
|
+
export const isJsonObject = zodIsFactory<JsonObject>(JsonObjectZod)
|
|
36
|
+
export const asJsonObject = zodAsFactory<JsonObject>(JsonObjectZod, 'asJsonObject')
|
|
37
|
+
export const toJsonObject = zodToFactory<JsonObject>(JsonObjectZod, 'toJsonObject')
|