@xylabs/object 4.13.4 → 4.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,187 +1,158 @@
1
- import { AnyNonPromise } from '@xylabs/promise';
2
- import type { AnyObject } from '@xylabs/object-model';
3
- import { AsTypeFunction } from '@xylabs/object-model';
4
- import type { FieldType } from '@xylabs/typeof';
5
- import { ObjectTypeShape } from '@xylabs/typeof';
6
- import type { Promisable } from '@xylabs/promise';
7
- import type { TypeCheck } from '@xylabs/object-model';
8
- import type { TypeCheckConfig } from '@xylabs/object-model';
9
- import { TypedObject } from '@xylabs/typeof';
10
-
11
- export declare const asAnyObject: AsTypeFunction<AnyObject>;
12
-
13
- export declare const AsObjectFactory: {
14
- create: <T extends TypedObject>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
15
- createOptional: <T extends TypedObject>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
16
- };
17
-
18
- export declare const AsTypeFactory: {
19
- create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
20
- createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
21
- };
22
-
23
- /**
24
- * Creates a deep merge function with the specified options.
25
- * @param options Options for merging.
26
- * @returns A deep merge function configured for the specified options.
27
- */
28
- export declare function createDeepMerge(options: MergeOptions): <T extends AnyObject[]>(...objects: T) => MergeAll<T>;
29
-
30
- /**
31
- * Deeply merges two types into a new type.
32
- */
33
- declare type DeepMerge<A, B> = {
34
- [K in keyof A | keyof B]: K extends keyof B ? K extends keyof A ? A[K] extends object ? B[K] extends object ? DeepMerge<A[K], B[K]> : B[K] : B[K] : B[K] : K extends keyof A ? A[K] : never;
35
- };
36
-
37
- /**
38
- * Deeply merges multiple objects into a new object.
39
- * @param objects Multiple objects to merge deeply.
40
- * The function merges properties from all objects into a new object.
41
- * If a property exists in multiple objects, the last object's value will be used.
42
- * If a property is an object, it will be merged recursively.
43
- * If a property is an array, it will be overwritten by the last object's value.
44
- * If a property is a primitive value, it will be overwritten by the last object's value.
45
- * If a property is undefined in the source, it will be skipped.
46
- * If a property is a symbol, it will be merged as well.
47
- * @returns A new object with the merged properties.
48
- */
49
- export declare const deepMerge: <T extends AnyObject[]>(...objects: T) => MergeAll<T>;
50
-
51
- export declare type DeepOmitStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? {
52
- [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix>;
53
- } : T;
54
-
55
- export declare type DeepPickStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepPickStartsWith<U, Prefix>[] : T extends object ? {
56
- [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? K : never : K]: DeepPickStartsWith<T[K], Prefix>;
57
- } : T;
58
-
59
- export declare type DeepRestrictToStringKeys<T> = {
60
- [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K];
61
- };
62
-
63
- /**
64
- * An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
65
- * extended from, which then adds only those additional fields
66
- */
67
- export declare type EmptyObject<T extends object = object> = {
68
- [K in keyof T]?: never;
69
- };
70
-
71
- export declare type EmptyObjectOf<T extends object> = EmptyObject<T> extends T ? EmptyObject<T> : never;
72
-
73
- export declare const isJsonArray: (value: unknown) => value is JsonArray;
74
-
75
- export declare const isJsonObject: (value: unknown) => value is JsonObject;
76
-
77
- export declare const isJsonValue: (value: unknown) => value is JsonValue;
78
-
79
- export declare const isObject: <T>(value: T) => value is T & object;
80
-
81
- export declare class IsObjectFactory<T extends TypedObject> {
82
- create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T>;
83
- }
84
-
85
- export declare const isType: (value: unknown, expectedType: FieldType) => boolean;
86
-
87
- export declare const isValidJsonFieldPair: ([key, value]: [key: unknown, value: unknown]) => boolean;
88
-
89
- export declare type JsonArray = JsonValue[];
90
-
91
- export declare type JsonObject = {
92
- [key: string]: JsonValue;
93
- };
94
-
95
- export declare type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
96
-
97
- /**
98
- * Merges multiple types into a new type.
99
- */
100
- declare type MergeAll<T extends object[], R = {}> = T extends [infer First extends object, ...infer Rest extends object[]] ? MergeAll<Rest, DeepMerge<R, First>> : R;
101
-
102
- /**
103
- * Options for merging objects in the deep merge function.
104
- */
105
- declare type MergeOptions = {
106
- /**
107
- * Strategy for merging arrays.
108
- * - 'overwrite': Overwrites the array with the last object's value.
109
- * - 'concat': Concatenates arrays from all objects.
110
- * @default 'overwrite'
111
- */
112
- arrayStrategy?: 'overwrite' | 'concat';
113
- /**
114
- * Mutate the first object in the list instead of creating a new one.
115
- * @default false
116
- */
117
- mutate?: boolean;
118
- };
119
-
120
- export declare interface ObjectTypeConfig extends TypeCheckConfig {
121
- }
122
-
123
- export declare abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {
124
- readonly obj: T;
125
- constructor(obj: T);
126
- protected get stringKeyObj(): StringKeyObject;
127
- }
128
-
129
- export declare const omitBy: <T extends EmptyObject>(obj: T, predicate: OmitByPredicate, maxDepth?: number) => Partial<T>;
130
-
131
- export declare type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean;
132
-
133
- export declare const omitByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepOmitStartsWith<T, P>;
134
-
135
- export declare type OmitStartsWith<T, Prefix extends string> = {
136
- [K in keyof T as K extends `${Prefix}${string}` ? never : K]: T[K];
137
- };
138
-
139
- export declare type Optional<T extends object, F extends keyof T> = Omit<T, F> & Partial<Pick<T, F>>;
140
-
141
- export declare type Override<T1, T2> = Omit<T1, keyof T2> & T2;
142
-
143
- /** @deprecated use Partial<Record<>> instead */
144
- export declare type PartialRecord<K extends keyof any, T> = {
145
- [P in K]?: T;
146
- };
147
-
148
- export declare const pickBy: <T extends EmptyObject>(obj: T, predicate: PickByPredicate, maxDepth?: number) => Partial<T>;
149
-
150
- export declare type PickByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean;
151
-
152
- export declare const pickByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepPickStartsWith<T, P>;
153
-
154
- export declare type PickStartsWith<T, Prefix extends string> = {
155
- [K in keyof T as K extends `${Prefix}${string}` ? K : never]: T[K];
156
- };
157
-
158
- export declare const removeFields: <T extends EmptyObject, K extends keyof T>(obj: T, fields: K[]) => Omit<T, K>;
159
-
160
- export declare type StringKeyObject<T = unknown> = {
161
- [key: string]: T;
162
- };
163
-
164
- export declare const toJson: (value: unknown, maxDepth?: number) => JsonValue;
165
-
166
- export declare const toJsonArray: (value: unknown[], cycleList?: unknown[], maxDepth?: number) => JsonArray;
167
-
168
- export declare const toJsonObject: (value: object, cycleList?: unknown[], maxDepth?: number) => JsonObject;
169
-
170
- export declare const toJsonString: (value: unknown, maxDepth?: number) => string;
171
-
172
- export declare const toJsonValue: (value: unknown, cycleList?: unknown[], maxDepth?: number) => JsonValue;
173
-
174
- export declare interface Validator<T extends EmptyObject = AnyObject> {
175
- validate(payload: T): Promisable<Error[]>;
176
- }
177
-
178
- export declare abstract class ValidatorBase<T extends EmptyObject = AnyObject> extends ObjectWrapper<Partial<T>> implements Validator<T> {
179
- abstract validate(payload: T): Promisable<Error[]>;
180
- }
181
-
182
- export declare type WithAdditional<T extends EmptyObject | void, TAdditional extends EmptyObject | void = void> = TAdditional extends EmptyObject ? T & TAdditional : T;
183
-
184
-
185
- export * from "@xylabs/object-model";
186
-
187
- export { }
1
+ import * as _xylabs_object_model from '@xylabs/object-model';
2
+ import { AnyObject, TypeCheck, AsTypeFunction, TypeCheckConfig } from '@xylabs/object-model';
3
+ export * from '@xylabs/object-model';
4
+ import * as _xylabs_promise from '@xylabs/promise';
5
+ import { AnyNonPromise, Promisable } from '@xylabs/promise';
6
+ import { TypedObject, ObjectTypeShape, FieldType } from '@xylabs/typeof';
7
+
8
+ declare const asAnyObject: _xylabs_object_model.AsTypeFunction<AnyObject>;
9
+
10
+ declare const AsObjectFactory: {
11
+ create: <T extends TypedObject>(typeCheck: TypeCheck<T>) => _xylabs_object_model.AsTypeFunction<T>;
12
+ createOptional: <T extends TypedObject>(typeCheck: TypeCheck<T>) => (value: _xylabs_promise.AnyNonPromise) => T | undefined;
13
+ };
14
+
15
+ declare const AsTypeFactory: {
16
+ create: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => AsTypeFunction<T>;
17
+ createOptional: <T extends AnyNonPromise>(typeCheck: TypeCheck<T>) => (value: AnyNonPromise) => T | undefined;
18
+ };
19
+
20
+ /**
21
+ * Deeply merges two types into a new type.
22
+ */
23
+ type DeepMerge<A, B> = {
24
+ [K in keyof A | keyof B]: K extends keyof B ? K extends keyof A ? A[K] extends object ? B[K] extends object ? DeepMerge<A[K], B[K]> : B[K] : B[K] : B[K] : K extends keyof A ? A[K] : never;
25
+ };
26
+ /**
27
+ * Merges multiple types into a new type.
28
+ */
29
+ type MergeAll<T extends object[], R = {}> = T extends [infer First extends object, ...infer Rest extends object[]] ? MergeAll<Rest, DeepMerge<R, First>> : R;
30
+ /**
31
+ * Options for merging objects in the deep merge function.
32
+ */
33
+ type MergeOptions = {
34
+ /**
35
+ * Strategy for merging arrays.
36
+ * - 'overwrite': Overwrites the array with the last object's value.
37
+ * - 'concat': Concatenates arrays from all objects.
38
+ * @default 'overwrite'
39
+ */
40
+ arrayStrategy?: 'overwrite' | 'concat';
41
+ /**
42
+ * Mutate the first object in the list instead of creating a new one.
43
+ * @default false
44
+ */
45
+ mutate?: boolean;
46
+ };
47
+ /**
48
+ * Creates a deep merge function with the specified options.
49
+ * @param options Options for merging.
50
+ * @returns A deep merge function configured for the specified options.
51
+ */
52
+ declare function createDeepMerge(options: MergeOptions): <T extends AnyObject[]>(...objects: T) => MergeAll<T>;
53
+ /**
54
+ * Deeply merges multiple objects into a new object.
55
+ * @param objects Multiple objects to merge deeply.
56
+ * The function merges properties from all objects into a new object.
57
+ * If a property exists in multiple objects, the last object's value will be used.
58
+ * If a property is an object, it will be merged recursively.
59
+ * If a property is an array, it will be overwritten by the last object's value.
60
+ * If a property is a primitive value, it will be overwritten by the last object's value.
61
+ * If a property is undefined in the source, it will be skipped.
62
+ * If a property is a symbol, it will be merged as well.
63
+ * @returns A new object with the merged properties.
64
+ */
65
+ declare const deepMerge: <T extends AnyObject[]>(...objects: T) => MergeAll<T>;
66
+
67
+ /**
68
+ * An empty object, which means that it does enforce the set of field names, defaulting to an empty set until
69
+ * extended from, which then adds only those additional fields
70
+ */
71
+ type EmptyObject<T extends object = object> = {
72
+ [K in keyof T]?: never;
73
+ };
74
+ type EmptyObjectOf<T extends object> = EmptyObject<T> extends T ? EmptyObject<T> : never;
75
+
76
+ declare const isObject: <T>(value: T) => value is T & object;
77
+
78
+ interface ObjectTypeConfig extends TypeCheckConfig {
79
+ }
80
+ declare class IsObjectFactory<T extends TypedObject> {
81
+ create(shape?: ObjectTypeShape, additionalChecks?: TypeCheck<TypedObject>[]): TypeCheck<T>;
82
+ }
83
+
84
+ declare const isType: (value: unknown, expectedType: FieldType) => boolean;
85
+
86
+ type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
87
+ type JsonObject = {
88
+ [key: string]: JsonValue;
89
+ };
90
+ type JsonArray = JsonValue[];
91
+ declare const isJsonValue: (value: unknown) => value is JsonValue;
92
+ declare const isJsonArray: (value: unknown) => value is JsonArray;
93
+ declare const isValidJsonFieldPair: ([key, value]: [key: unknown, value: unknown]) => boolean;
94
+ declare const isJsonObject: (value: unknown) => value is JsonObject;
95
+
96
+ type StringKeyObject<T = unknown> = {
97
+ [key: string]: T;
98
+ };
99
+
100
+ declare abstract class ObjectWrapper<T extends EmptyObject = EmptyObject> {
101
+ readonly obj: T;
102
+ constructor(obj: T);
103
+ protected get stringKeyObj(): StringKeyObject;
104
+ }
105
+
106
+ type OmitStartsWith<T, Prefix extends string> = {
107
+ [K in keyof T as K extends `${Prefix}${string}` ? never : K]: T[K];
108
+ };
109
+ type DeepOmitStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepOmitStartsWith<U, Prefix>[] : T extends object ? {
110
+ [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? never : K : K]: DeepOmitStartsWith<T[K], Prefix>;
111
+ } : T;
112
+ type DeepRestrictToStringKeys<T> = {
113
+ [K in keyof T as K extends string ? K : never]: T[K] extends (infer U)[] ? DeepRestrictToStringKeys<U>[] : T[K] extends object ? DeepRestrictToStringKeys<T[K]> : T[K];
114
+ };
115
+
116
+ type OmitByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean;
117
+ declare const omitBy: <T extends EmptyObject>(obj: T, predicate: OmitByPredicate, maxDepth?: number) => Partial<T>;
118
+ declare const omitByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepOmitStartsWith<T, P>;
119
+
120
+ type Optional<T extends object, F extends keyof T> = Omit<T, F> & Partial<Pick<T, F>>;
121
+
122
+ type Override<T1, T2> = Omit<T1, keyof T2> & T2;
123
+
124
+ /** @deprecated use Partial<Record<>> instead */
125
+ type PartialRecord<K extends keyof any, T> = {
126
+ [P in K]?: T;
127
+ };
128
+
129
+ type PickStartsWith<T, Prefix extends string> = {
130
+ [K in keyof T as K extends `${Prefix}${string}` ? K : never]: T[K];
131
+ };
132
+ type DeepPickStartsWith<T, Prefix extends string> = T extends (infer U)[] ? DeepPickStartsWith<U, Prefix>[] : T extends object ? {
133
+ [K in keyof T as K extends string ? K extends `${Prefix}${string}` ? K : never : K]: DeepPickStartsWith<T[K], Prefix>;
134
+ } : T;
135
+
136
+ type PickByPredicate<T extends EmptyObject = Record<string, unknown>> = (value: T[keyof T], key: keyof T) => boolean;
137
+ declare const pickBy: <T extends EmptyObject>(obj: T, predicate: PickByPredicate, maxDepth?: number) => Partial<T>;
138
+ declare const pickByPrefix: <T extends EmptyObject, P extends string>(payload: T, prefix: P, maxDepth?: number) => DeepPickStartsWith<T, P>;
139
+
140
+ declare const removeFields: <T extends EmptyObject, K extends keyof T>(obj: T, fields: K[]) => Omit<T, K>;
141
+
142
+ declare const toJsonArray: (value: unknown[], cycleList?: unknown[], maxDepth?: number) => JsonArray;
143
+ declare const toJsonObject: (value: object, cycleList?: unknown[], maxDepth?: number) => JsonObject;
144
+ declare const toJsonValue: (value: unknown, cycleList?: unknown[], maxDepth?: number) => JsonValue;
145
+ declare const toJsonString: (value: unknown, maxDepth?: number) => string;
146
+ declare const toJson: (value: unknown, maxDepth?: number) => JsonValue;
147
+
148
+ interface Validator<T extends EmptyObject = AnyObject> {
149
+ validate(payload: T): Promisable<Error[]>;
150
+ }
151
+ declare abstract class ValidatorBase<T extends EmptyObject = AnyObject> extends ObjectWrapper<Partial<T>> implements Validator<T> {
152
+ abstract validate(payload: T): Promisable<Error[]>;
153
+ }
154
+
155
+ type WithAdditional<T extends EmptyObject | void, TAdditional extends EmptyObject | void = void> = TAdditional extends EmptyObject ? T & TAdditional : T;
156
+
157
+ export { AsObjectFactory, AsTypeFactory, IsObjectFactory, ObjectWrapper, ValidatorBase, asAnyObject, createDeepMerge, deepMerge, isJsonArray, isJsonObject, isJsonValue, isObject, isType, isValidJsonFieldPair, omitBy, omitByPrefix, pickBy, pickByPrefix, removeFields, toJson, toJsonArray, toJsonObject, toJsonString, toJsonValue };
158
+ export type { DeepOmitStartsWith, DeepPickStartsWith, DeepRestrictToStringKeys, EmptyObject, EmptyObjectOf, JsonArray, JsonObject, JsonValue, ObjectTypeConfig, OmitByPredicate, OmitStartsWith, Optional, Override, PartialRecord, PickByPredicate, PickStartsWith, StringKeyObject, Validator, WithAdditional };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/object",
3
- "version": "4.13.4",
3
+ "version": "4.13.6",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -29,14 +29,14 @@
29
29
  "module": "dist/neutral/index.mjs",
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "dependencies": {
32
- "@xylabs/assert": "^4.13.4",
33
- "@xylabs/object-model": "^4.13.4",
34
- "@xylabs/promise": "^4.13.4",
35
- "@xylabs/typeof": "^4.13.4"
32
+ "@xylabs/assert": "^4.13.6",
33
+ "@xylabs/object-model": "^4.13.6",
34
+ "@xylabs/promise": "^4.13.6",
35
+ "@xylabs/typeof": "^4.13.6"
36
36
  },
37
37
  "devDependencies": {
38
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.7",
39
- "@xylabs/tsconfig": "^7.0.0-rc.7",
38
+ "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.8",
39
+ "@xylabs/tsconfig": "^7.0.0-rc.8",
40
40
  "typescript": "^5.8.3",
41
41
  "vitest": "^3.2.4"
42
42
  },