@voltagent/internal 0.0.7 → 0.0.9
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/main/index.d.mts +124 -105
- package/dist/main/index.d.ts +124 -105
- package/dist/main/index.js +42 -7
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +40 -6
- package/dist/main/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +22 -43
- package/dist/utils/index.d.ts +22 -43
- package/dist/utils/index.js +42 -7
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +40 -6
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/main/index.d.mts
CHANGED
|
@@ -32,107 +32,11 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
32
32
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Valid log levels
|
|
40
|
-
*/
|
|
41
|
-
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
|
42
|
-
/**
|
|
43
|
-
* Log function signatures
|
|
44
|
-
*/
|
|
45
|
-
type LogFn = (msg: string, context?: object) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Minimal logger interface for VoltAgent
|
|
48
|
-
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
49
|
-
*/
|
|
50
|
-
interface Logger {
|
|
51
|
-
/**
|
|
52
|
-
* Log at trace level - most detailed level
|
|
53
|
-
*/
|
|
54
|
-
trace: LogFn;
|
|
55
|
-
/**
|
|
56
|
-
* Log at debug level - detailed information for debugging
|
|
57
|
-
*/
|
|
58
|
-
debug: LogFn;
|
|
59
|
-
/**
|
|
60
|
-
* Log at info level - general informational messages
|
|
61
|
-
*/
|
|
62
|
-
info: LogFn;
|
|
63
|
-
/**
|
|
64
|
-
* Log at warn level - warning messages
|
|
65
|
-
*/
|
|
66
|
-
warn: LogFn;
|
|
67
|
-
/**
|
|
68
|
-
* Log at error level - error messages
|
|
69
|
-
*/
|
|
70
|
-
error: LogFn;
|
|
71
|
-
/**
|
|
72
|
-
* Log at fatal level - fatal error messages
|
|
73
|
-
*/
|
|
74
|
-
fatal: LogFn;
|
|
75
|
-
/**
|
|
76
|
-
* Create a child logger with additional context
|
|
77
|
-
* @param bindings - Additional context to bind to the child logger
|
|
78
|
-
*/
|
|
79
|
-
child(bindings: Record<string, any>): Logger;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Logger options for configuration
|
|
83
|
-
*/
|
|
84
|
-
interface LoggerOptions {
|
|
85
|
-
/**
|
|
86
|
-
* Log level
|
|
87
|
-
*/
|
|
88
|
-
level?: string;
|
|
89
|
-
/**
|
|
90
|
-
* Logger name
|
|
91
|
-
*/
|
|
92
|
-
name?: string;
|
|
93
|
-
/**
|
|
94
|
-
* Additional options specific to the logger implementation
|
|
95
|
-
*/
|
|
96
|
-
[key: string]: any;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Log entry structure
|
|
100
|
-
*/
|
|
101
|
-
interface LogEntry {
|
|
102
|
-
timestamp: string;
|
|
103
|
-
level: LogLevel;
|
|
104
|
-
msg: string;
|
|
105
|
-
component?: string;
|
|
106
|
-
agentId?: string;
|
|
107
|
-
conversationId?: string;
|
|
108
|
-
workflowId?: string;
|
|
109
|
-
executionId?: string;
|
|
110
|
-
userId?: string;
|
|
111
|
-
[key: string]: any;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Log filter for querying logs
|
|
115
|
-
*/
|
|
116
|
-
interface LogFilter {
|
|
117
|
-
level?: LogLevel;
|
|
118
|
-
agentId?: string;
|
|
119
|
-
conversationId?: string;
|
|
120
|
-
workflowId?: string;
|
|
121
|
-
executionId?: string;
|
|
122
|
-
since?: Date;
|
|
123
|
-
until?: Date;
|
|
124
|
-
limit?: number;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Log buffer interface for storing logs in memory
|
|
35
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
36
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
37
|
+
* behavior and is a dangerous practice.
|
|
128
38
|
*/
|
|
129
|
-
|
|
130
|
-
add(entry: LogEntry): void;
|
|
131
|
-
query(filter?: LogFilter): LogEntry[];
|
|
132
|
-
clear(): void;
|
|
133
|
-
size(): number;
|
|
134
|
-
}
|
|
135
|
-
|
|
39
|
+
type DangerouslyAllowAny = any;
|
|
136
40
|
/**
|
|
137
41
|
* A plain object is an object that has no special properties or methods,
|
|
138
42
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -156,13 +60,12 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
156
60
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
157
61
|
|
|
158
62
|
/**
|
|
159
|
-
* Deep clone an object
|
|
63
|
+
* Deep clone an object
|
|
160
64
|
*
|
|
161
65
|
* @param obj - The object to clone
|
|
162
|
-
* @
|
|
163
|
-
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
66
|
+
* @returns A deep copy of the object (fallback to shallow clone for failures)
|
|
164
67
|
*/
|
|
165
|
-
declare function deepClone<T>(obj: T
|
|
68
|
+
declare function deepClone<T>(obj: T): T;
|
|
166
69
|
/**
|
|
167
70
|
* Check if an object has a key
|
|
168
71
|
*
|
|
@@ -238,4 +141,120 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
|
238
141
|
*/
|
|
239
142
|
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
240
143
|
|
|
241
|
-
|
|
144
|
+
type SafeStringifyOptions = {
|
|
145
|
+
/**
|
|
146
|
+
* The indentation to use for the output.
|
|
147
|
+
*/
|
|
148
|
+
indentation?: string | number;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.
|
|
152
|
+
* @param input - The object to stringify.
|
|
153
|
+
* @param options.indentation - The indentation to use for the output.
|
|
154
|
+
* @returns The stringified object.
|
|
155
|
+
*/
|
|
156
|
+
declare function safeStringify(input: DangerouslyAllowAny, { indentation }?: SafeStringifyOptions): string;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Shared logger types for VoltAgent
|
|
160
|
+
* These types define the minimal logger interface that both core and logger packages use
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* Valid log levels
|
|
164
|
+
*/
|
|
165
|
+
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
|
166
|
+
/**
|
|
167
|
+
* Log function signatures
|
|
168
|
+
*/
|
|
169
|
+
type LogFn = (msg: string, context?: object) => void;
|
|
170
|
+
/**
|
|
171
|
+
* Minimal logger interface for VoltAgent
|
|
172
|
+
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
173
|
+
*/
|
|
174
|
+
interface Logger {
|
|
175
|
+
/**
|
|
176
|
+
* Log at trace level - most detailed level
|
|
177
|
+
*/
|
|
178
|
+
trace: LogFn;
|
|
179
|
+
/**
|
|
180
|
+
* Log at debug level - detailed information for debugging
|
|
181
|
+
*/
|
|
182
|
+
debug: LogFn;
|
|
183
|
+
/**
|
|
184
|
+
* Log at info level - general informational messages
|
|
185
|
+
*/
|
|
186
|
+
info: LogFn;
|
|
187
|
+
/**
|
|
188
|
+
* Log at warn level - warning messages
|
|
189
|
+
*/
|
|
190
|
+
warn: LogFn;
|
|
191
|
+
/**
|
|
192
|
+
* Log at error level - error messages
|
|
193
|
+
*/
|
|
194
|
+
error: LogFn;
|
|
195
|
+
/**
|
|
196
|
+
* Log at fatal level - fatal error messages
|
|
197
|
+
*/
|
|
198
|
+
fatal: LogFn;
|
|
199
|
+
/**
|
|
200
|
+
* Create a child logger with additional context
|
|
201
|
+
* @param bindings - Additional context to bind to the child logger
|
|
202
|
+
*/
|
|
203
|
+
child(bindings: Record<string, any>): Logger;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Logger options for configuration
|
|
207
|
+
*/
|
|
208
|
+
interface LoggerOptions {
|
|
209
|
+
/**
|
|
210
|
+
* Log level
|
|
211
|
+
*/
|
|
212
|
+
level?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Logger name
|
|
215
|
+
*/
|
|
216
|
+
name?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Additional options specific to the logger implementation
|
|
219
|
+
*/
|
|
220
|
+
[key: string]: any;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Log entry structure
|
|
224
|
+
*/
|
|
225
|
+
interface LogEntry {
|
|
226
|
+
timestamp: string;
|
|
227
|
+
level: LogLevel;
|
|
228
|
+
msg: string;
|
|
229
|
+
component?: string;
|
|
230
|
+
agentId?: string;
|
|
231
|
+
conversationId?: string;
|
|
232
|
+
workflowId?: string;
|
|
233
|
+
executionId?: string;
|
|
234
|
+
userId?: string;
|
|
235
|
+
[key: string]: any;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Log filter for querying logs
|
|
239
|
+
*/
|
|
240
|
+
interface LogFilter {
|
|
241
|
+
level?: LogLevel;
|
|
242
|
+
agentId?: string;
|
|
243
|
+
conversationId?: string;
|
|
244
|
+
workflowId?: string;
|
|
245
|
+
executionId?: string;
|
|
246
|
+
since?: Date;
|
|
247
|
+
until?: Date;
|
|
248
|
+
limit?: number;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Log buffer interface for storing logs in memory
|
|
252
|
+
*/
|
|
253
|
+
interface LogBuffer {
|
|
254
|
+
add(entry: LogEntry): void;
|
|
255
|
+
query(filter?: LogFilter): LogEntry[];
|
|
256
|
+
clear(): void;
|
|
257
|
+
size(): number;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { type AsyncIterableStream, type LogBuffer, type LogEntry, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerOptions, type SafeStringifyOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject, safeStringify };
|
package/dist/main/index.d.ts
CHANGED
|
@@ -32,107 +32,11 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
32
32
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Valid log levels
|
|
40
|
-
*/
|
|
41
|
-
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
|
42
|
-
/**
|
|
43
|
-
* Log function signatures
|
|
44
|
-
*/
|
|
45
|
-
type LogFn = (msg: string, context?: object) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Minimal logger interface for VoltAgent
|
|
48
|
-
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
49
|
-
*/
|
|
50
|
-
interface Logger {
|
|
51
|
-
/**
|
|
52
|
-
* Log at trace level - most detailed level
|
|
53
|
-
*/
|
|
54
|
-
trace: LogFn;
|
|
55
|
-
/**
|
|
56
|
-
* Log at debug level - detailed information for debugging
|
|
57
|
-
*/
|
|
58
|
-
debug: LogFn;
|
|
59
|
-
/**
|
|
60
|
-
* Log at info level - general informational messages
|
|
61
|
-
*/
|
|
62
|
-
info: LogFn;
|
|
63
|
-
/**
|
|
64
|
-
* Log at warn level - warning messages
|
|
65
|
-
*/
|
|
66
|
-
warn: LogFn;
|
|
67
|
-
/**
|
|
68
|
-
* Log at error level - error messages
|
|
69
|
-
*/
|
|
70
|
-
error: LogFn;
|
|
71
|
-
/**
|
|
72
|
-
* Log at fatal level - fatal error messages
|
|
73
|
-
*/
|
|
74
|
-
fatal: LogFn;
|
|
75
|
-
/**
|
|
76
|
-
* Create a child logger with additional context
|
|
77
|
-
* @param bindings - Additional context to bind to the child logger
|
|
78
|
-
*/
|
|
79
|
-
child(bindings: Record<string, any>): Logger;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Logger options for configuration
|
|
83
|
-
*/
|
|
84
|
-
interface LoggerOptions {
|
|
85
|
-
/**
|
|
86
|
-
* Log level
|
|
87
|
-
*/
|
|
88
|
-
level?: string;
|
|
89
|
-
/**
|
|
90
|
-
* Logger name
|
|
91
|
-
*/
|
|
92
|
-
name?: string;
|
|
93
|
-
/**
|
|
94
|
-
* Additional options specific to the logger implementation
|
|
95
|
-
*/
|
|
96
|
-
[key: string]: any;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Log entry structure
|
|
100
|
-
*/
|
|
101
|
-
interface LogEntry {
|
|
102
|
-
timestamp: string;
|
|
103
|
-
level: LogLevel;
|
|
104
|
-
msg: string;
|
|
105
|
-
component?: string;
|
|
106
|
-
agentId?: string;
|
|
107
|
-
conversationId?: string;
|
|
108
|
-
workflowId?: string;
|
|
109
|
-
executionId?: string;
|
|
110
|
-
userId?: string;
|
|
111
|
-
[key: string]: any;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Log filter for querying logs
|
|
115
|
-
*/
|
|
116
|
-
interface LogFilter {
|
|
117
|
-
level?: LogLevel;
|
|
118
|
-
agentId?: string;
|
|
119
|
-
conversationId?: string;
|
|
120
|
-
workflowId?: string;
|
|
121
|
-
executionId?: string;
|
|
122
|
-
since?: Date;
|
|
123
|
-
until?: Date;
|
|
124
|
-
limit?: number;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Log buffer interface for storing logs in memory
|
|
35
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
36
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
37
|
+
* behavior and is a dangerous practice.
|
|
128
38
|
*/
|
|
129
|
-
|
|
130
|
-
add(entry: LogEntry): void;
|
|
131
|
-
query(filter?: LogFilter): LogEntry[];
|
|
132
|
-
clear(): void;
|
|
133
|
-
size(): number;
|
|
134
|
-
}
|
|
135
|
-
|
|
39
|
+
type DangerouslyAllowAny = any;
|
|
136
40
|
/**
|
|
137
41
|
* A plain object is an object that has no special properties or methods,
|
|
138
42
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -156,13 +60,12 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
156
60
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
157
61
|
|
|
158
62
|
/**
|
|
159
|
-
* Deep clone an object
|
|
63
|
+
* Deep clone an object
|
|
160
64
|
*
|
|
161
65
|
* @param obj - The object to clone
|
|
162
|
-
* @
|
|
163
|
-
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
66
|
+
* @returns A deep copy of the object (fallback to shallow clone for failures)
|
|
164
67
|
*/
|
|
165
|
-
declare function deepClone<T>(obj: T
|
|
68
|
+
declare function deepClone<T>(obj: T): T;
|
|
166
69
|
/**
|
|
167
70
|
* Check if an object has a key
|
|
168
71
|
*
|
|
@@ -238,4 +141,120 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
|
238
141
|
*/
|
|
239
142
|
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
240
143
|
|
|
241
|
-
|
|
144
|
+
type SafeStringifyOptions = {
|
|
145
|
+
/**
|
|
146
|
+
* The indentation to use for the output.
|
|
147
|
+
*/
|
|
148
|
+
indentation?: string | number;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.
|
|
152
|
+
* @param input - The object to stringify.
|
|
153
|
+
* @param options.indentation - The indentation to use for the output.
|
|
154
|
+
* @returns The stringified object.
|
|
155
|
+
*/
|
|
156
|
+
declare function safeStringify(input: DangerouslyAllowAny, { indentation }?: SafeStringifyOptions): string;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Shared logger types for VoltAgent
|
|
160
|
+
* These types define the minimal logger interface that both core and logger packages use
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* Valid log levels
|
|
164
|
+
*/
|
|
165
|
+
type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silent";
|
|
166
|
+
/**
|
|
167
|
+
* Log function signatures
|
|
168
|
+
*/
|
|
169
|
+
type LogFn = (msg: string, context?: object) => void;
|
|
170
|
+
/**
|
|
171
|
+
* Minimal logger interface for VoltAgent
|
|
172
|
+
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
173
|
+
*/
|
|
174
|
+
interface Logger {
|
|
175
|
+
/**
|
|
176
|
+
* Log at trace level - most detailed level
|
|
177
|
+
*/
|
|
178
|
+
trace: LogFn;
|
|
179
|
+
/**
|
|
180
|
+
* Log at debug level - detailed information for debugging
|
|
181
|
+
*/
|
|
182
|
+
debug: LogFn;
|
|
183
|
+
/**
|
|
184
|
+
* Log at info level - general informational messages
|
|
185
|
+
*/
|
|
186
|
+
info: LogFn;
|
|
187
|
+
/**
|
|
188
|
+
* Log at warn level - warning messages
|
|
189
|
+
*/
|
|
190
|
+
warn: LogFn;
|
|
191
|
+
/**
|
|
192
|
+
* Log at error level - error messages
|
|
193
|
+
*/
|
|
194
|
+
error: LogFn;
|
|
195
|
+
/**
|
|
196
|
+
* Log at fatal level - fatal error messages
|
|
197
|
+
*/
|
|
198
|
+
fatal: LogFn;
|
|
199
|
+
/**
|
|
200
|
+
* Create a child logger with additional context
|
|
201
|
+
* @param bindings - Additional context to bind to the child logger
|
|
202
|
+
*/
|
|
203
|
+
child(bindings: Record<string, any>): Logger;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Logger options for configuration
|
|
207
|
+
*/
|
|
208
|
+
interface LoggerOptions {
|
|
209
|
+
/**
|
|
210
|
+
* Log level
|
|
211
|
+
*/
|
|
212
|
+
level?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Logger name
|
|
215
|
+
*/
|
|
216
|
+
name?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Additional options specific to the logger implementation
|
|
219
|
+
*/
|
|
220
|
+
[key: string]: any;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Log entry structure
|
|
224
|
+
*/
|
|
225
|
+
interface LogEntry {
|
|
226
|
+
timestamp: string;
|
|
227
|
+
level: LogLevel;
|
|
228
|
+
msg: string;
|
|
229
|
+
component?: string;
|
|
230
|
+
agentId?: string;
|
|
231
|
+
conversationId?: string;
|
|
232
|
+
workflowId?: string;
|
|
233
|
+
executionId?: string;
|
|
234
|
+
userId?: string;
|
|
235
|
+
[key: string]: any;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Log filter for querying logs
|
|
239
|
+
*/
|
|
240
|
+
interface LogFilter {
|
|
241
|
+
level?: LogLevel;
|
|
242
|
+
agentId?: string;
|
|
243
|
+
conversationId?: string;
|
|
244
|
+
workflowId?: string;
|
|
245
|
+
executionId?: string;
|
|
246
|
+
since?: Date;
|
|
247
|
+
until?: Date;
|
|
248
|
+
limit?: number;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Log buffer interface for storing logs in memory
|
|
252
|
+
*/
|
|
253
|
+
interface LogBuffer {
|
|
254
|
+
add(entry: LogEntry): void;
|
|
255
|
+
query(filter?: LogFilter): LogEntry[];
|
|
256
|
+
clear(): void;
|
|
257
|
+
size(): number;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { type AsyncIterableStream, type LogBuffer, type LogEntry, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerOptions, type SafeStringifyOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject, safeStringify };
|
package/dist/main/index.js
CHANGED
|
@@ -33,7 +33,8 @@ __export(index_exports, {
|
|
|
33
33
|
isFunction: () => isFunction,
|
|
34
34
|
isNil: () => isNil,
|
|
35
35
|
isObject: () => isObject,
|
|
36
|
-
isPlainObject: () => isPlainObject
|
|
36
|
+
isPlainObject: () => isPlainObject,
|
|
37
|
+
safeStringify: () => safeStringify
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(index_exports);
|
|
39
40
|
|
|
@@ -119,13 +120,13 @@ function isEmptyObject(obj) {
|
|
|
119
120
|
__name(isEmptyObject, "isEmptyObject");
|
|
120
121
|
|
|
121
122
|
// src/utils/objects.ts
|
|
122
|
-
function deepClone(obj
|
|
123
|
+
function deepClone(obj) {
|
|
123
124
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (logger) {
|
|
127
|
-
logger.warn("Failed to deep clone object, using shallow clone", { error });
|
|
125
|
+
if (typeof structuredClone === "function") {
|
|
126
|
+
return structuredClone(obj);
|
|
128
127
|
}
|
|
128
|
+
throw new Error("structuredClone is not available");
|
|
129
|
+
} catch (_error) {
|
|
129
130
|
if (obj === null || typeof obj !== "object") {
|
|
130
131
|
return obj;
|
|
131
132
|
}
|
|
@@ -153,6 +154,39 @@ function createAsyncIterableStream(source) {
|
|
|
153
154
|
return stream;
|
|
154
155
|
}
|
|
155
156
|
__name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
157
|
+
|
|
158
|
+
// src/utils/safe-stringify.ts
|
|
159
|
+
function safeStringify(input, { indentation } = {}) {
|
|
160
|
+
try {
|
|
161
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
162
|
+
return JSON.stringify(input, safeStringifyReplacer(seen), indentation);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
__name(safeStringify, "safeStringify");
|
|
168
|
+
function safeStringifyReplacer(seen) {
|
|
169
|
+
const replacer = /* @__PURE__ */ __name((_key, value) => {
|
|
170
|
+
if (typeof value?.toJSON === "function") {
|
|
171
|
+
value = value.toJSON();
|
|
172
|
+
}
|
|
173
|
+
if (!(value !== null && typeof value === "object")) {
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
if (seen.has(value)) {
|
|
177
|
+
return "[Circular]";
|
|
178
|
+
}
|
|
179
|
+
seen.add(value);
|
|
180
|
+
const newValue = Array.isArray(value) ? [] : {};
|
|
181
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
182
|
+
newValue[key2] = replacer(key2, value2);
|
|
183
|
+
}
|
|
184
|
+
seen.delete(value);
|
|
185
|
+
return newValue;
|
|
186
|
+
}, "replacer");
|
|
187
|
+
return replacer;
|
|
188
|
+
}
|
|
189
|
+
__name(safeStringifyReplacer, "safeStringifyReplacer");
|
|
156
190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
157
191
|
0 && (module.exports = {
|
|
158
192
|
convertArrayToAsyncIterable,
|
|
@@ -167,6 +201,7 @@ __name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
|
167
201
|
isFunction,
|
|
168
202
|
isNil,
|
|
169
203
|
isObject,
|
|
170
|
-
isPlainObject
|
|
204
|
+
isPlainObject,
|
|
205
|
+
safeStringify
|
|
171
206
|
});
|
|
172
207
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts"],"sourcesContent":["export * from \"./test\";\nexport * from \"./utils\";\nexport * from \"./logger/types\";\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { Logger } from \"../logger/types\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @param logger - Optional logger for warnings\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T, logger?: Logger): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n if (logger) {\n logger.warn(\"Failed to deep clone object, using shallow clone\", { error });\n }\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,eAAsB,6BAAgC,QAAyC;AAC7F,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,SAAc,CAAC;AAErB,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI,KAAM;AACV,WAAO,KAAK,KAAK;AAAA,EACnB;AAEA,SAAO;AACT;AAXsB;AAkBf,SAAS,4BAA+B,QAA+B;AAC5E,SAAO;AAAA,IACL,QAAQ,OAAO,aAAa,IAAI;AAC9B,iBAAW,SAAS,QAAQ;AAC1B,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AARgB;AAehB,eAAsB,4BAA+B,UAA0C;AAC7F,QAAM,SAAc,CAAC;AACrB,mBAAiB,QAAQ,UAAU;AACjC,WAAO,KAAK,IAAI;AAAA,EAClB;AACA,SAAO;AACT;AANsB;AAaf,SAAS,6BAAgC,QAAgC;AAC9E,SAAO,IAAI,eAAe;AAAA,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;AAAA,EAClB;AACF;AAbgB;AAsBT,SAAS,OACd,KACA,KAC8B;AAC9B,SAAO,SAAS,GAAG,KAAK,OAAO;AACjC;AALgB;;;ACHT,SAAS,0BAA6B,QAAmD;AAC9F,QAAM,SAAS,OAAO,YAAY,IAAI,gBAAsB,CAAC;AAE7D,EAAC,OAAkC,OAAO,aAAa,IAAI,MAAM;AAC/D,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACL,MAAM,OAAmC;AACvC,cAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,eAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAU,IAAI,EAAE,MAAM,OAAO,MAAM;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAdgB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts","../../src/utils/safe-stringify.ts"],"sourcesContent":["export * from \"./test\";\nexport * from \"./utils\";\nexport type * from \"./logger/types\";\n","/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object (fallback to shallow clone for failures)\n */\nexport function deepClone<T>(obj: T): T {\n try {\n // Use structuredClone if available (Node.js 17+, modern browsers)\n if (typeof structuredClone === \"function\") {\n return structuredClone(obj);\n }\n\n throw new Error(\"structuredClone is not available\");\n } catch (_error) {\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n","import type { DangerouslyAllowAny } from \"../types\";\n\nexport type SafeStringifyOptions = {\n /**\n * The indentation to use for the output.\n */\n indentation?: string | number;\n};\n\n/**\n * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.\n * @param input - The object to stringify.\n * @param options.indentation - The indentation to use for the output.\n * @returns The stringified object.\n */\nexport function safeStringify(\n input: DangerouslyAllowAny,\n { indentation }: SafeStringifyOptions = {},\n) {\n try {\n const seen = new WeakSet();\n return JSON.stringify(input, safeStringifyReplacer(seen), indentation);\n } catch (error) {\n return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n }\n}\n\nfunction safeStringifyReplacer(seen: WeakSet<DangerouslyAllowAny>) {\n const replacer = (_key: string, value: DangerouslyAllowAny) => {\n // Handle objects with a custom `.toJSON()` method.\n if (typeof value?.toJSON === \"function\") {\n // biome-ignore lint/style/noParameterAssign: needed to handle circular references\n value = value.toJSON();\n }\n\n if (!(value !== null && typeof value === \"object\")) {\n return value;\n }\n\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n\n seen.add(value);\n\n const newValue = Array.isArray(value) ? [] : {};\n\n for (const [key2, value2] of Object.entries(value)) {\n // @ts-expect-error - ignore as this is needed to handle circular references\n newValue[key2] = replacer(key2, value2);\n }\n\n seen.delete(value);\n\n return newValue;\n };\n\n return replacer;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,eAAsB,6BAAgC,QAAyC;AAC7F,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,SAAc,CAAC;AAErB,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI,KAAM;AACV,WAAO,KAAK,KAAK;AAAA,EACnB;AAEA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AAAA,IACvB;AAEA,QAAI,EAAE,UAAU,QAAQ,OAAO,UAAU,WAAW;AAClD,aAAO;AAAA,IACT;AAEA,QAAI,KAAK,IAAI,KAAK,GAAG;AACnB,aAAO;AAAA,IACT;AAEA,SAAK,IAAI,KAAK;AAEd,UAAM,WAAW,MAAM,QAAQ,KAAK,IAAI,CAAC,IAAI,CAAC;AAE9C,eAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AAElD,eAAS,IAAI,IAAI,SAAS,MAAM,MAAM;AAAA,IACxC;AAEA,SAAK,OAAO,KAAK;AAEjB,WAAO;AAAA,EACT,GA3BiB;AA6BjB,SAAO;AACT;AA/BS;","names":[]}
|
package/dist/main/index.mjs
CHANGED
|
@@ -83,13 +83,13 @@ function isEmptyObject(obj) {
|
|
|
83
83
|
__name(isEmptyObject, "isEmptyObject");
|
|
84
84
|
|
|
85
85
|
// src/utils/objects.ts
|
|
86
|
-
function deepClone(obj
|
|
86
|
+
function deepClone(obj) {
|
|
87
87
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (logger) {
|
|
91
|
-
logger.warn("Failed to deep clone object, using shallow clone", { error });
|
|
88
|
+
if (typeof structuredClone === "function") {
|
|
89
|
+
return structuredClone(obj);
|
|
92
90
|
}
|
|
91
|
+
throw new Error("structuredClone is not available");
|
|
92
|
+
} catch (_error) {
|
|
93
93
|
if (obj === null || typeof obj !== "object") {
|
|
94
94
|
return obj;
|
|
95
95
|
}
|
|
@@ -117,6 +117,39 @@ function createAsyncIterableStream(source) {
|
|
|
117
117
|
return stream;
|
|
118
118
|
}
|
|
119
119
|
__name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
120
|
+
|
|
121
|
+
// src/utils/safe-stringify.ts
|
|
122
|
+
function safeStringify(input, { indentation } = {}) {
|
|
123
|
+
try {
|
|
124
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
125
|
+
return JSON.stringify(input, safeStringifyReplacer(seen), indentation);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
__name(safeStringify, "safeStringify");
|
|
131
|
+
function safeStringifyReplacer(seen) {
|
|
132
|
+
const replacer = /* @__PURE__ */ __name((_key, value) => {
|
|
133
|
+
if (typeof value?.toJSON === "function") {
|
|
134
|
+
value = value.toJSON();
|
|
135
|
+
}
|
|
136
|
+
if (!(value !== null && typeof value === "object")) {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
if (seen.has(value)) {
|
|
140
|
+
return "[Circular]";
|
|
141
|
+
}
|
|
142
|
+
seen.add(value);
|
|
143
|
+
const newValue = Array.isArray(value) ? [] : {};
|
|
144
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
145
|
+
newValue[key2] = replacer(key2, value2);
|
|
146
|
+
}
|
|
147
|
+
seen.delete(value);
|
|
148
|
+
return newValue;
|
|
149
|
+
}, "replacer");
|
|
150
|
+
return replacer;
|
|
151
|
+
}
|
|
152
|
+
__name(safeStringifyReplacer, "safeStringifyReplacer");
|
|
120
153
|
export {
|
|
121
154
|
convertArrayToAsyncIterable,
|
|
122
155
|
convertArrayToReadableStream,
|
|
@@ -130,6 +163,7 @@ export {
|
|
|
130
163
|
isFunction,
|
|
131
164
|
isNil,
|
|
132
165
|
isObject,
|
|
133
|
-
isPlainObject
|
|
166
|
+
isPlainObject,
|
|
167
|
+
safeStringify
|
|
134
168
|
};
|
|
135
169
|
//# sourceMappingURL=index.mjs.map
|
package/dist/main/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts"],"sourcesContent":["/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { Logger } from \"../logger/types\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object using JSON serialization with fallback to shallow clone\n *\n * @param obj - The object to clone\n * @param logger - Optional logger for warnings\n * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T, logger?: Logger): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n if (logger) {\n logger.warn(\"Failed to deep clone object, using shallow clone\", { error });\n }\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n"],"mappings":";;;;AAKA,eAAsB,6BAAgC,QAAyC;AAC7F,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,SAAc,CAAC;AAErB,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI,KAAM;AACV,WAAO,KAAK,KAAK;AAAA,EACnB;AAEA,SAAO;AACT;AAXsB;AAkBf,SAAS,4BAA+B,QAA+B;AAC5E,SAAO;AAAA,IACL,QAAQ,OAAO,aAAa,IAAI;AAC9B,iBAAW,SAAS,QAAQ;AAC1B,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AARgB;AAehB,eAAsB,4BAA+B,UAA0C;AAC7F,QAAM,SAAc,CAAC;AACrB,mBAAiB,QAAQ,UAAU;AACjC,WAAO,KAAK,IAAI;AAAA,EAClB;AACA,SAAO;AACT;AANsB;AAaf,SAAS,6BAAgC,QAAgC;AAC9E,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,YAAY;AAChB,UAAI;AACF,mBAAW,SAAS,QAAQ;AAC1B,qBAAW,QAAQ,KAAK;A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K,OAAO;AACjC;AALgB;;;ACHT,SAAS,0BAA6B,QAAmD;AAC9F,QAAM,SAAS,OAAO,YAAY,IAAI,gBAAsB,CAAC;AAE7D,EAAC,OAAkC,OAAO,aAAa,IAAI,MAAM;AAC/D,UAAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACL,MAAM,OAAmC;AACvC,cAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,eAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAU,IAAI,EAAE,MAAM,OAAO,MAAM;AAAA,MACxE;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAdgB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/test/conversions.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts","../../src/utils/safe-stringify.ts"],"sourcesContent":["/**\n * Convert a readable stream to an array\n * @param stream - The readable stream to convert\n * @returns The array of values\n */\nexport async function convertReadableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> {\n const reader = stream.getReader();\n const result: T[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n result.push(value);\n }\n\n return result;\n}\n\n/**\n * Convert an array to an async iterable\n * @param values - The array to convert\n * @returns The async iterable\n */\nexport function convertArrayToAsyncIterable<T>(values: T[]): AsyncIterable<T> {\n return {\n async *[Symbol.asyncIterator]() {\n for (const value of values) {\n yield value;\n }\n },\n };\n}\n\n/**\n * Convert an async iterable to an array\n * @param iterable - The async iterable to convert\n * @returns The array of values\n */\nexport async function convertAsyncIterableToArray<T>(iterable: AsyncIterable<T>): Promise<T[]> {\n const result: T[] = [];\n for await (const item of iterable) {\n result.push(item);\n }\n return result;\n}\n\n/**\n * Convert an array to a readable stream\n * @param values - The array to convert\n * @returns The readable stream\n */\nexport function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T> {\n return new ReadableStream({\n start(controller) {\n try {\n for (const value of values) {\n controller.enqueue(value);\n }\n } finally {\n controller.close();\n }\n },\n });\n}\n\n/**\n * Convert a response stream to an array\n * @param response - The response to convert\n * @returns The array of values\n */\nexport async function convertResponseStreamToArray(response: Response): Promise<string[]> {\n // biome-ignore lint/style/noNonNullAssertion: ignore this\n return convertReadableStreamToArray(response.body!.pipeThrough(new TextDecoderStream()));\n}\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object (fallback to shallow clone for failures)\n */\nexport function deepClone<T>(obj: T): T {\n try {\n // Use structuredClone if available (Node.js 17+, modern browsers)\n if (typeof structuredClone === \"function\") {\n return structuredClone(obj);\n }\n\n throw new Error(\"structuredClone is not available\");\n } catch (_error) {\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n","import type { DangerouslyAllowAny } from \"../types\";\n\nexport type SafeStringifyOptions = {\n /**\n * The indentation to use for the output.\n */\n indentation?: string | number;\n};\n\n/**\n * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.\n * @param input - The object to stringify.\n * @param options.indentation - The indentation to use for the output.\n * @returns The stringified object.\n */\nexport function safeStringify(\n input: DangerouslyAllowAny,\n { indentation }: SafeStringifyOptions = {},\n) {\n try {\n const seen = new WeakSet();\n return JSON.stringify(input, safeStringifyReplacer(seen), indentation);\n } catch (error) {\n return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n }\n}\n\nfunction safeStringifyReplacer(seen: WeakSet<DangerouslyAllowAny>) {\n const replacer = (_key: string, value: DangerouslyAllowAny) => {\n // Handle objects with a custom `.toJSON()` method.\n if (typeof value?.toJSON === \"function\") {\n // biome-ignore lint/style/noParameterAssign: needed to handle circular references\n value = value.toJSON();\n }\n\n if (!(value !== null && typeof value === \"object\")) {\n return value;\n }\n\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n\n seen.add(value);\n\n const newValue = Array.isArray(value) ? [] : {};\n\n for (const [key2, value2] of Object.entries(value)) {\n // @ts-expect-error - ignore as this is needed to handle circular references\n newValue[key2] = replacer(key2, value2);\n }\n\n seen.delete(value);\n\n return newValue;\n };\n\n return replacer;\n}\n"],"mappings":";;;;AAKA,eAAsB,6BAAgC,QAAyC;AAC7F,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,SAAc,CAAC;AAErB,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI,KAAM;AACV,WAAO,KAAK,KAAK;AAAA,EACnB;AAEA,SAAO;AACT;AAXsB;AAkBf,SAAS,4BAA+B,QAA+B;AAC5E,SAAO;AAAA,IACL,QAAQ,OAAO,aAAa,IAAI;AAC9B,iBAAW,SAAS,QAAQ;AAC1B,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AARgB;AAehB,eAAsB,4BAA+B,UAA0C;AAC7F,QAAM,SAAc,CAAC;AACrB,mBAAiB,QAAQ,UAAU;AACjC,WAAO,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Q,KAAK,GAAG;AAElD,eAAS,IAAI,IAAI,SAAS,MAAM,MAAM;AAAA,IACxC;AAEA,SAAK,OAAO,KAAK;AAEjB,WAAO;AAAA,EACT,GA3BiB;AA6BjB,SAAO;AACT;AA/BS;","names":[]}
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,45 +1,11 @@
|
|
|
1
1
|
import { SetRequired, EmptyObject, Merge } from 'type-fest';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
5
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
6
|
+
* behavior and is a dangerous practice.
|
|
5
7
|
*/
|
|
6
|
-
type
|
|
7
|
-
/**
|
|
8
|
-
* Minimal logger interface for VoltAgent
|
|
9
|
-
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
10
|
-
*/
|
|
11
|
-
interface Logger {
|
|
12
|
-
/**
|
|
13
|
-
* Log at trace level - most detailed level
|
|
14
|
-
*/
|
|
15
|
-
trace: LogFn;
|
|
16
|
-
/**
|
|
17
|
-
* Log at debug level - detailed information for debugging
|
|
18
|
-
*/
|
|
19
|
-
debug: LogFn;
|
|
20
|
-
/**
|
|
21
|
-
* Log at info level - general informational messages
|
|
22
|
-
*/
|
|
23
|
-
info: LogFn;
|
|
24
|
-
/**
|
|
25
|
-
* Log at warn level - warning messages
|
|
26
|
-
*/
|
|
27
|
-
warn: LogFn;
|
|
28
|
-
/**
|
|
29
|
-
* Log at error level - error messages
|
|
30
|
-
*/
|
|
31
|
-
error: LogFn;
|
|
32
|
-
/**
|
|
33
|
-
* Log at fatal level - fatal error messages
|
|
34
|
-
*/
|
|
35
|
-
fatal: LogFn;
|
|
36
|
-
/**
|
|
37
|
-
* Create a child logger with additional context
|
|
38
|
-
* @param bindings - Additional context to bind to the child logger
|
|
39
|
-
*/
|
|
40
|
-
child(bindings: Record<string, any>): Logger;
|
|
41
|
-
}
|
|
42
|
-
|
|
8
|
+
type DangerouslyAllowAny = any;
|
|
43
9
|
/**
|
|
44
10
|
* A plain object is an object that has no special properties or methods,
|
|
45
11
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -63,13 +29,12 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
63
29
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
64
30
|
|
|
65
31
|
/**
|
|
66
|
-
* Deep clone an object
|
|
32
|
+
* Deep clone an object
|
|
67
33
|
*
|
|
68
34
|
* @param obj - The object to clone
|
|
69
|
-
* @
|
|
70
|
-
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
35
|
+
* @returns A deep copy of the object (fallback to shallow clone for failures)
|
|
71
36
|
*/
|
|
72
|
-
declare function deepClone<T>(obj: T
|
|
37
|
+
declare function deepClone<T>(obj: T): T;
|
|
73
38
|
/**
|
|
74
39
|
* Check if an object has a key
|
|
75
40
|
*
|
|
@@ -145,4 +110,18 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
|
145
110
|
*/
|
|
146
111
|
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
147
112
|
|
|
148
|
-
|
|
113
|
+
type SafeStringifyOptions = {
|
|
114
|
+
/**
|
|
115
|
+
* The indentation to use for the output.
|
|
116
|
+
*/
|
|
117
|
+
indentation?: string | number;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.
|
|
121
|
+
* @param input - The object to stringify.
|
|
122
|
+
* @param options.indentation - The indentation to use for the output.
|
|
123
|
+
* @returns The stringified object.
|
|
124
|
+
*/
|
|
125
|
+
declare function safeStringify(input: DangerouslyAllowAny, { indentation }?: SafeStringifyOptions): string;
|
|
126
|
+
|
|
127
|
+
export { type AsyncIterableStream, type SafeStringifyOptions, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject, safeStringify };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,45 +1,11 @@
|
|
|
1
1
|
import { SetRequired, EmptyObject, Merge } from 'type-fest';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* This type is used to allow any type and bypass restrictions used in
|
|
5
|
+
* typechecking and linting. Provides a CLEAR warning this is NOT the desired
|
|
6
|
+
* behavior and is a dangerous practice.
|
|
5
7
|
*/
|
|
6
|
-
type
|
|
7
|
-
/**
|
|
8
|
-
* Minimal logger interface for VoltAgent
|
|
9
|
-
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
10
|
-
*/
|
|
11
|
-
interface Logger {
|
|
12
|
-
/**
|
|
13
|
-
* Log at trace level - most detailed level
|
|
14
|
-
*/
|
|
15
|
-
trace: LogFn;
|
|
16
|
-
/**
|
|
17
|
-
* Log at debug level - detailed information for debugging
|
|
18
|
-
*/
|
|
19
|
-
debug: LogFn;
|
|
20
|
-
/**
|
|
21
|
-
* Log at info level - general informational messages
|
|
22
|
-
*/
|
|
23
|
-
info: LogFn;
|
|
24
|
-
/**
|
|
25
|
-
* Log at warn level - warning messages
|
|
26
|
-
*/
|
|
27
|
-
warn: LogFn;
|
|
28
|
-
/**
|
|
29
|
-
* Log at error level - error messages
|
|
30
|
-
*/
|
|
31
|
-
error: LogFn;
|
|
32
|
-
/**
|
|
33
|
-
* Log at fatal level - fatal error messages
|
|
34
|
-
*/
|
|
35
|
-
fatal: LogFn;
|
|
36
|
-
/**
|
|
37
|
-
* Create a child logger with additional context
|
|
38
|
-
* @param bindings - Additional context to bind to the child logger
|
|
39
|
-
*/
|
|
40
|
-
child(bindings: Record<string, any>): Logger;
|
|
41
|
-
}
|
|
42
|
-
|
|
8
|
+
type DangerouslyAllowAny = any;
|
|
43
9
|
/**
|
|
44
10
|
* A plain object is an object that has no special properties or methods,
|
|
45
11
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -63,13 +29,12 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
63
29
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
64
30
|
|
|
65
31
|
/**
|
|
66
|
-
* Deep clone an object
|
|
32
|
+
* Deep clone an object
|
|
67
33
|
*
|
|
68
34
|
* @param obj - The object to clone
|
|
69
|
-
* @
|
|
70
|
-
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
35
|
+
* @returns A deep copy of the object (fallback to shallow clone for failures)
|
|
71
36
|
*/
|
|
72
|
-
declare function deepClone<T>(obj: T
|
|
37
|
+
declare function deepClone<T>(obj: T): T;
|
|
73
38
|
/**
|
|
74
39
|
* Check if an object has a key
|
|
75
40
|
*
|
|
@@ -145,4 +110,18 @@ type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
|
145
110
|
*/
|
|
146
111
|
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
147
112
|
|
|
148
|
-
|
|
113
|
+
type SafeStringifyOptions = {
|
|
114
|
+
/**
|
|
115
|
+
* The indentation to use for the output.
|
|
116
|
+
*/
|
|
117
|
+
indentation?: string | number;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.
|
|
121
|
+
* @param input - The object to stringify.
|
|
122
|
+
* @param options.indentation - The indentation to use for the output.
|
|
123
|
+
* @returns The stringified object.
|
|
124
|
+
*/
|
|
125
|
+
declare function safeStringify(input: DangerouslyAllowAny, { indentation }?: SafeStringifyOptions): string;
|
|
126
|
+
|
|
127
|
+
export { type AsyncIterableStream, type SafeStringifyOptions, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject, safeStringify };
|
package/dist/utils/index.js
CHANGED
|
@@ -28,7 +28,8 @@ __export(index_exports, {
|
|
|
28
28
|
isFunction: () => isFunction,
|
|
29
29
|
isNil: () => isNil,
|
|
30
30
|
isObject: () => isObject,
|
|
31
|
-
isPlainObject: () => isPlainObject
|
|
31
|
+
isPlainObject: () => isPlainObject,
|
|
32
|
+
safeStringify: () => safeStringify
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(index_exports);
|
|
34
35
|
|
|
@@ -65,13 +66,13 @@ function isEmptyObject(obj) {
|
|
|
65
66
|
__name(isEmptyObject, "isEmptyObject");
|
|
66
67
|
|
|
67
68
|
// src/utils/objects.ts
|
|
68
|
-
function deepClone(obj
|
|
69
|
+
function deepClone(obj) {
|
|
69
70
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (logger) {
|
|
73
|
-
logger.warn("Failed to deep clone object, using shallow clone", { error });
|
|
71
|
+
if (typeof structuredClone === "function") {
|
|
72
|
+
return structuredClone(obj);
|
|
74
73
|
}
|
|
74
|
+
throw new Error("structuredClone is not available");
|
|
75
|
+
} catch (_error) {
|
|
75
76
|
if (obj === null || typeof obj !== "object") {
|
|
76
77
|
return obj;
|
|
77
78
|
}
|
|
@@ -99,6 +100,39 @@ function createAsyncIterableStream(source) {
|
|
|
99
100
|
return stream;
|
|
100
101
|
}
|
|
101
102
|
__name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
103
|
+
|
|
104
|
+
// src/utils/safe-stringify.ts
|
|
105
|
+
function safeStringify(input, { indentation } = {}) {
|
|
106
|
+
try {
|
|
107
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
108
|
+
return JSON.stringify(input, safeStringifyReplacer(seen), indentation);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
__name(safeStringify, "safeStringify");
|
|
114
|
+
function safeStringifyReplacer(seen) {
|
|
115
|
+
const replacer = /* @__PURE__ */ __name((_key, value) => {
|
|
116
|
+
if (typeof value?.toJSON === "function") {
|
|
117
|
+
value = value.toJSON();
|
|
118
|
+
}
|
|
119
|
+
if (!(value !== null && typeof value === "object")) {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
if (seen.has(value)) {
|
|
123
|
+
return "[Circular]";
|
|
124
|
+
}
|
|
125
|
+
seen.add(value);
|
|
126
|
+
const newValue = Array.isArray(value) ? [] : {};
|
|
127
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
128
|
+
newValue[key2] = replacer(key2, value2);
|
|
129
|
+
}
|
|
130
|
+
seen.delete(value);
|
|
131
|
+
return newValue;
|
|
132
|
+
}, "replacer");
|
|
133
|
+
return replacer;
|
|
134
|
+
}
|
|
135
|
+
__name(safeStringifyReplacer, "safeStringifyReplacer");
|
|
102
136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
137
|
0 && (module.exports = {
|
|
104
138
|
createAsyncIterableStream,
|
|
@@ -108,6 +142,7 @@ __name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
|
108
142
|
isFunction,
|
|
109
143
|
isNil,
|
|
110
144
|
isObject,
|
|
111
|
-
isPlainObject
|
|
145
|
+
isPlainObject,
|
|
146
|
+
safeStringify
|
|
112
147
|
});
|
|
113
148
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts"],"sourcesContent":["export { deepClone, hasKey } from \"./objects\";\nexport { isNil, isObject, isEmptyObject, isFunction, isPlainObject } from \"./lang\";\nexport type { AsyncIterableStream } from \"./async-iterable-stream\";\nexport { createAsyncIterableStream } from \"./async-iterable-stream\";\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts","../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts","../../src/utils/safe-stringify.ts"],"sourcesContent":["export { deepClone, hasKey } from \"./objects\";\nexport { isNil, isObject, isEmptyObject, isFunction, isPlainObject } from \"./lang\";\nexport type { AsyncIterableStream } from \"./async-iterable-stream\";\nexport { createAsyncIterableStream } from \"./async-iterable-stream\";\nexport { safeStringify, type SafeStringifyOptions } from \"./safe-stringify\";\n","import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object (fallback to shallow clone for failures)\n */\nexport function deepClone<T>(obj: T): T {\n try {\n // Use structuredClone if available (Node.js 17+, modern browsers)\n if (typeof structuredClone === \"function\") {\n return structuredClone(obj);\n }\n\n throw new Error(\"structuredClone is not available\");\n } catch (_error) {\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n","import type { DangerouslyAllowAny } from \"../types\";\n\nexport type SafeStringifyOptions = {\n /**\n * The indentation to use for the output.\n */\n indentation?: string | number;\n};\n\n/**\n * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.\n * @param input - The object to stringify.\n * @param options.indentation - The indentation to use for the output.\n * @returns The stringified object.\n */\nexport function safeStringify(\n input: DangerouslyAllowAny,\n { indentation }: SafeStringifyOptions = {},\n) {\n try {\n const seen = new WeakSet();\n return JSON.stringify(input, safeStringifyReplacer(seen), indentation);\n } catch (error) {\n return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n }\n}\n\nfunction safeStringifyReplacer(seen: WeakSet<DangerouslyAllowAny>) {\n const replacer = (_key: string, value: DangerouslyAllowAny) => {\n // Handle objects with a custom `.toJSON()` method.\n if (typeof value?.toJSON === \"function\") {\n // biome-ignore lint/style/noParameterAssign: needed to handle circular references\n value = value.toJSON();\n }\n\n if (!(value !== null && typeof value === \"object\")) {\n return value;\n }\n\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n\n seen.add(value);\n\n const newValue = Array.isArray(value) ? [] : {};\n\n for (const [key2, value2] of Object.entries(value)) {\n // @ts-expect-error - ignore as this is needed to handle circular references\n newValue[key2] = replacer(key2, value2);\n }\n\n seen.delete(value);\n\n return newValue;\n };\n\n return replacer;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,MAAM,KAA0B;AAC9C,SAAO,QAAQ,QAAQ,QAAQ;AACjC;AAFgB;AAUT,SAAS,SAA2B,KAAwB;AACjE,UAAQ,OAAO,QAAQ,YAAY,OAAO,QAAQ,eAAe,CAAC,MAAM,GAAG;AAC7E;AAFgB;AAUT,SAAS,WAAkC,KAAwB;AACxE,SAAO,OAAO,QAAQ;AACxB;AAFgB;AAUT,SAAS,cAAqC,KAAwB;AAC3E,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,GAAG;AAC3C,SAAO,cAAc,OAAO,aAAa,cAAc;AACzD;AAPgB;AAeT,SAAS,cAAc,KAAkC;AAC9D,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,oBAAoB,GAAG,EAAE,SAAS,KAAK,OAAO,sBAAsB,GAAG,EAAE,SAAS,GAAG;AAC9F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAXgB;;;AC5CT,SAAS,UAAa,KAAW;AACtC,MAAI;AAEF,QAAI,OAAO,oBAAoB,YAAY;AACzC,aAAO,gBAAgB,GAAG;AAAA,IAC5B;AAEA,U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I,CAAC,IAAI,CAAC;AAE9C,eAAW,CAAC,MAAM,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AAElD,eAAS,IAAI,IAAI,SAAS,MAAM,MAAM;AAAA,IACxC;AAEA,SAAK,OAAO,KAAK;AAEjB,WAAO;AAAA,EACT,GA3BiB;AA6BjB,SAAO;AACT;AA/BS;","names":[]}
|
package/dist/utils/index.mjs
CHANGED
|
@@ -34,13 +34,13 @@ function isEmptyObject(obj) {
|
|
|
34
34
|
__name(isEmptyObject, "isEmptyObject");
|
|
35
35
|
|
|
36
36
|
// src/utils/objects.ts
|
|
37
|
-
function deepClone(obj
|
|
37
|
+
function deepClone(obj) {
|
|
38
38
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (logger) {
|
|
42
|
-
logger.warn("Failed to deep clone object, using shallow clone", { error });
|
|
39
|
+
if (typeof structuredClone === "function") {
|
|
40
|
+
return structuredClone(obj);
|
|
43
41
|
}
|
|
42
|
+
throw new Error("structuredClone is not available");
|
|
43
|
+
} catch (_error) {
|
|
44
44
|
if (obj === null || typeof obj !== "object") {
|
|
45
45
|
return obj;
|
|
46
46
|
}
|
|
@@ -68,6 +68,39 @@ function createAsyncIterableStream(source) {
|
|
|
68
68
|
return stream;
|
|
69
69
|
}
|
|
70
70
|
__name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
71
|
+
|
|
72
|
+
// src/utils/safe-stringify.ts
|
|
73
|
+
function safeStringify(input, { indentation } = {}) {
|
|
74
|
+
try {
|
|
75
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
76
|
+
return JSON.stringify(input, safeStringifyReplacer(seen), indentation);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
__name(safeStringify, "safeStringify");
|
|
82
|
+
function safeStringifyReplacer(seen) {
|
|
83
|
+
const replacer = /* @__PURE__ */ __name((_key, value) => {
|
|
84
|
+
if (typeof value?.toJSON === "function") {
|
|
85
|
+
value = value.toJSON();
|
|
86
|
+
}
|
|
87
|
+
if (!(value !== null && typeof value === "object")) {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
if (seen.has(value)) {
|
|
91
|
+
return "[Circular]";
|
|
92
|
+
}
|
|
93
|
+
seen.add(value);
|
|
94
|
+
const newValue = Array.isArray(value) ? [] : {};
|
|
95
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
96
|
+
newValue[key2] = replacer(key2, value2);
|
|
97
|
+
}
|
|
98
|
+
seen.delete(value);
|
|
99
|
+
return newValue;
|
|
100
|
+
}, "replacer");
|
|
101
|
+
return replacer;
|
|
102
|
+
}
|
|
103
|
+
__name(safeStringifyReplacer, "safeStringifyReplacer");
|
|
71
104
|
export {
|
|
72
105
|
createAsyncIterableStream,
|
|
73
106
|
deepClone,
|
|
@@ -76,6 +109,7 @@ export {
|
|
|
76
109
|
isFunction,
|
|
77
110
|
isNil,
|
|
78
111
|
isObject,
|
|
79
|
-
isPlainObject
|
|
112
|
+
isPlainObject,
|
|
113
|
+
safeStringify
|
|
80
114
|
};
|
|
81
115
|
//# sourceMappingURL=index.mjs.map
|
package/dist/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts"],"sourcesContent":["import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/lang.ts","../../src/utils/objects.ts","../../src/utils/async-iterable-stream.ts","../../src/utils/safe-stringify.ts"],"sourcesContent":["import type { EmptyObject } from \"type-fest\";\nimport type { AnyFunction, Nil, PlainObject } from \"../types\";\n\n/**\n * Check if a value is nil\n *\n * @param obj - The value to check\n * @returns True if the value is nil, false otherwise\n */\nexport function isNil(obj: unknown): obj is Nil {\n return obj === null || obj === undefined;\n}\n\n/**\n * Check if an object is a JS object\n *\n * @param obj - The object to check\n * @returns True if the object is a JS object}\n */\nexport function isObject<T extends object>(obj: unknown): obj is T {\n return (typeof obj === \"object\" || typeof obj === \"function\") && !isNil(obj);\n}\n\n/**\n * Check if a value is a function\n *\n * @param obj - The value to check\n * @returns True if the value is a function, false otherwise\n */\nexport function isFunction<T extends AnyFunction>(obj: unknown): obj is T {\n return typeof obj === \"function\";\n}\n\n/**\n * Check if an object is a plain object (i.e. a JS object but not including arrays or functions)\n *\n * @param obj - The object to check\n * @returns True if the object is a plain object, false otherwise.\n */\nexport function isPlainObject<T extends PlainObject>(obj: unknown): obj is T {\n if (!isObject(obj)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(obj);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Check if an object is an empty object\n *\n * @param obj - The object to check\n * @returns True if the object is an empty object, false otherwise\n */\nexport function isEmptyObject(obj: unknown): obj is EmptyObject {\n if (!isObject(obj)) {\n return false;\n }\n\n // Check for own string and symbol properties (enumerable or not)\n if (Object.getOwnPropertyNames(obj).length > 0 || Object.getOwnPropertySymbols(obj).length > 0) {\n return false;\n }\n\n return true;\n}\n","import type { SetRequired } from \"type-fest\";\nimport type { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\n\n/**\n * Deep clone an object\n *\n * @param obj - The object to clone\n * @returns A deep copy of the object (fallback to shallow clone for failures)\n */\nexport function deepClone<T>(obj: T): T {\n try {\n // Use structuredClone if available (Node.js 17+, modern browsers)\n if (typeof structuredClone === \"function\") {\n return structuredClone(obj);\n }\n\n throw new Error(\"structuredClone is not available\");\n } catch (_error) {\n // Fallback to shallow clone for primitive types and simple objects\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n return { ...obj } as T;\n }\n}\n\n/**\n * Check if an object has a key\n *\n * @param obj - The object to check\n * @param key - The key to check\n * @returns True if the object has the key, false otherwise\n */\nexport function hasKey<T extends PlainObject, K extends string>(\n obj: T,\n key: K,\n): obj is T & SetRequired<T, K> {\n return isObject(obj) && key in obj;\n}\n","import type { Merge } from \"type-fest\";\n\n/**\n * An async iterable stream that can be read from.\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = getStream();\n * for await (const chunk of stream) {\n * console.log(chunk);\n * }\n * ```\n */\nexport type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;\n\n/**\n * Create an async iterable stream from a readable stream.\n *\n * This is useful for creating an async iterable stream from a readable stream.\n *\n * @example\n * ```typescript\n * const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({\n * start(controller) {\n * controller.enqueue(\"Hello\");\n * controller.close();\n * },\n * }));\n * ```\n * @param source The readable stream to create an async iterable stream from.\n * @returns The async iterable stream.\n */\nexport function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T> {\n const stream = source.pipeThrough(new TransformStream<T, T>());\n\n (stream as AsyncIterableStream<T>)[Symbol.asyncIterator] = () => {\n const reader = stream.getReader();\n return {\n async next(): Promise<IteratorResult<T>> {\n const { done, value } = await reader.read();\n return done ? { done: true, value: undefined } : { done: false, value };\n },\n };\n };\n\n return stream as AsyncIterableStream<T>;\n}\n","import type { DangerouslyAllowAny } from \"../types\";\n\nexport type SafeStringifyOptions = {\n /**\n * The indentation to use for the output.\n */\n indentation?: string | number;\n};\n\n/**\n * Stringifies an object, handling circular references and ensuring the output is safe to use in a JSON string.\n * @param input - The object to stringify.\n * @param options.indentation - The indentation to use for the output.\n * @returns The stringified object.\n */\nexport function safeStringify(\n input: DangerouslyAllowAny,\n { indentation }: SafeStringifyOptions = {},\n) {\n try {\n const seen = new WeakSet();\n return JSON.stringify(input, safeStringifyReplacer(seen), indentation);\n } catch (error) {\n return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : \"Unknown error\"}`;\n }\n}\n\nfunction safeStringifyReplacer(seen: WeakSet<DangerouslyAllowAny>) {\n const replacer = (_key: string, value: DangerouslyAllowAny) => {\n // Handle objects with a custom `.toJSON()` method.\n if (typeof value?.toJSON === \"function\") {\n // biome-ignore lint/style/noParameterAssign: needed to handle circular references\n value = value.toJSON();\n }\n\n if (!(value !== null && typeof value === \"object\")) {\n return value;\n }\n\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n\n seen.add(value);\n\n const newValue = Array.isArray(value) ? [] : {};\n\n for (const [key2, value2] of Object.entries(value)) {\n // @ts-expect-error - ignore as this is needed to handle circular references\n newValue[key2] = replacer(key2, value2);\n }\n\n seen.delete(value);\n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