@voltagent/internal 0.0.6 → 0.0.8
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 +104 -87
- package/dist/main/index.d.ts +104 -87
- package/dist/main/index.js +69 -104
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +67 -104
- package/dist/main/index.mjs.map +1 -1
- package/dist/test/index.js +21 -78
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +21 -78
- package/dist/test/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +24 -47
- package/dist/utils/index.d.ts +24 -47
- package/dist/utils/index.js +48 -46
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +46 -46
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +54 -21
package/dist/main/index.d.mts
CHANGED
|
@@ -31,6 +31,12 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
31
31
|
*/
|
|
32
32
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
33
33
|
|
|
34
|
+
/**
|
|
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.
|
|
38
|
+
*/
|
|
39
|
+
type DangerouslyAllowAny = any;
|
|
34
40
|
/**
|
|
35
41
|
* A plain object is an object that has no special properties or methods,
|
|
36
42
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -53,6 +59,102 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
53
59
|
*/
|
|
54
60
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
55
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Deep clone an object
|
|
64
|
+
*
|
|
65
|
+
* @param obj - The object to clone
|
|
66
|
+
* @returns A deep copy of the object (fallback to shallow clone for failures)
|
|
67
|
+
*/
|
|
68
|
+
declare function deepClone<T>(obj: T): T;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object has a key
|
|
71
|
+
*
|
|
72
|
+
* @param obj - The object to check
|
|
73
|
+
* @param key - The key to check
|
|
74
|
+
* @returns True if the object has the key, false otherwise
|
|
75
|
+
*/
|
|
76
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if a value is nil
|
|
80
|
+
*
|
|
81
|
+
* @param obj - The value to check
|
|
82
|
+
* @returns True if the value is nil, false otherwise
|
|
83
|
+
*/
|
|
84
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
85
|
+
/**
|
|
86
|
+
* Check if an object is a JS object
|
|
87
|
+
*
|
|
88
|
+
* @param obj - The object to check
|
|
89
|
+
* @returns True if the object is a JS object}
|
|
90
|
+
*/
|
|
91
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
92
|
+
/**
|
|
93
|
+
* Check if a value is a function
|
|
94
|
+
*
|
|
95
|
+
* @param obj - The value to check
|
|
96
|
+
* @returns True if the value is a function, false otherwise
|
|
97
|
+
*/
|
|
98
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
99
|
+
/**
|
|
100
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
101
|
+
*
|
|
102
|
+
* @param obj - The object to check
|
|
103
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
104
|
+
*/
|
|
105
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
106
|
+
/**
|
|
107
|
+
* Check if an object is an empty object
|
|
108
|
+
*
|
|
109
|
+
* @param obj - The object to check
|
|
110
|
+
* @returns True if the object is an empty object, false otherwise
|
|
111
|
+
*/
|
|
112
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* An async iterable stream that can be read from.
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const stream: AsyncIterableStream<string> = getStream();
|
|
119
|
+
* for await (const chunk of stream) {
|
|
120
|
+
* console.log(chunk);
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
125
|
+
/**
|
|
126
|
+
* Create an async iterable stream from a readable stream.
|
|
127
|
+
*
|
|
128
|
+
* This is useful for creating an async iterable stream from a readable stream.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({
|
|
133
|
+
* start(controller) {
|
|
134
|
+
* controller.enqueue("Hello");
|
|
135
|
+
* controller.close();
|
|
136
|
+
* },
|
|
137
|
+
* }));
|
|
138
|
+
* ```
|
|
139
|
+
* @param source The readable stream to create an async iterable stream from.
|
|
140
|
+
* @returns The async iterable stream.
|
|
141
|
+
*/
|
|
142
|
+
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
143
|
+
|
|
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
|
+
|
|
56
158
|
/**
|
|
57
159
|
* Shared logger types for VoltAgent
|
|
58
160
|
* These types define the minimal logger interface that both core and logger packages use
|
|
@@ -64,9 +166,7 @@ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silen
|
|
|
64
166
|
/**
|
|
65
167
|
* Log function signatures
|
|
66
168
|
*/
|
|
67
|
-
|
|
68
|
-
(msg: string, context?: object): void;
|
|
69
|
-
}
|
|
169
|
+
type LogFn = (msg: string, context?: object) => void;
|
|
70
170
|
/**
|
|
71
171
|
* Minimal logger interface for VoltAgent
|
|
72
172
|
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
@@ -157,87 +257,4 @@ interface LogBuffer {
|
|
|
157
257
|
size(): number;
|
|
158
258
|
}
|
|
159
259
|
|
|
160
|
-
|
|
161
|
-
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
162
|
-
*
|
|
163
|
-
* @param obj - The object to clone
|
|
164
|
-
* @param logger - Optional logger for warnings
|
|
165
|
-
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
166
|
-
*/
|
|
167
|
-
declare function deepClone<T>(obj: T, logger?: Logger): T;
|
|
168
|
-
/**
|
|
169
|
-
* Check if an object has a key
|
|
170
|
-
*
|
|
171
|
-
* @param obj - The object to check
|
|
172
|
-
* @param key - The key to check
|
|
173
|
-
* @returns True if the object has the key, false otherwise
|
|
174
|
-
*/
|
|
175
|
-
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Check if a value is nil
|
|
179
|
-
*
|
|
180
|
-
* @param obj - The value to check
|
|
181
|
-
* @returns True if the value is nil, false otherwise
|
|
182
|
-
*/
|
|
183
|
-
declare function isNil(obj: unknown): obj is Nil;
|
|
184
|
-
/**
|
|
185
|
-
* Check if an object is a JS object
|
|
186
|
-
*
|
|
187
|
-
* @param obj - The object to check
|
|
188
|
-
* @returns True if the object is a JS object}
|
|
189
|
-
*/
|
|
190
|
-
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
191
|
-
/**
|
|
192
|
-
* Check if a value is a function
|
|
193
|
-
*
|
|
194
|
-
* @param obj - The value to check
|
|
195
|
-
* @returns True if the value is a function, false otherwise
|
|
196
|
-
*/
|
|
197
|
-
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
198
|
-
/**
|
|
199
|
-
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
200
|
-
*
|
|
201
|
-
* @param obj - The object to check
|
|
202
|
-
* @returns True if the object is a plain object, false otherwise.
|
|
203
|
-
*/
|
|
204
|
-
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
205
|
-
/**
|
|
206
|
-
* Check if an object is an empty object
|
|
207
|
-
*
|
|
208
|
-
* @param obj - The object to check
|
|
209
|
-
* @returns True if the object is an empty object, false otherwise
|
|
210
|
-
*/
|
|
211
|
-
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* An async iterable stream that can be read from.
|
|
215
|
-
* @example
|
|
216
|
-
* ```typescript
|
|
217
|
-
* const stream: AsyncIterableStream<string> = getStream();
|
|
218
|
-
* for await (const chunk of stream) {
|
|
219
|
-
* console.log(chunk);
|
|
220
|
-
* }
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
224
|
-
/**
|
|
225
|
-
* Create an async iterable stream from a readable stream.
|
|
226
|
-
*
|
|
227
|
-
* This is useful for creating an async iterable stream from a readable stream.
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({
|
|
232
|
-
* start(controller) {
|
|
233
|
-
* controller.enqueue("Hello");
|
|
234
|
-
* controller.close();
|
|
235
|
-
* },
|
|
236
|
-
* }));
|
|
237
|
-
* ```
|
|
238
|
-
* @param source The readable stream to create an async iterable stream from.
|
|
239
|
-
* @returns The async iterable stream.
|
|
240
|
-
*/
|
|
241
|
-
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
242
|
-
|
|
243
|
-
export { type AsyncIterableStream, type LogBuffer, type LogEntry, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
|
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
|
@@ -31,6 +31,12 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
|
|
|
31
31
|
*/
|
|
32
32
|
declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
|
|
33
33
|
|
|
34
|
+
/**
|
|
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.
|
|
38
|
+
*/
|
|
39
|
+
type DangerouslyAllowAny = any;
|
|
34
40
|
/**
|
|
35
41
|
* A plain object is an object that has no special properties or methods,
|
|
36
42
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -53,6 +59,102 @@ type AnySyncFunction = (...args: unknown[]) => unknown;
|
|
|
53
59
|
*/
|
|
54
60
|
type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
55
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Deep clone an object
|
|
64
|
+
*
|
|
65
|
+
* @param obj - The object to clone
|
|
66
|
+
* @returns A deep copy of the object (fallback to shallow clone for failures)
|
|
67
|
+
*/
|
|
68
|
+
declare function deepClone<T>(obj: T): T;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object has a key
|
|
71
|
+
*
|
|
72
|
+
* @param obj - The object to check
|
|
73
|
+
* @param key - The key to check
|
|
74
|
+
* @returns True if the object has the key, false otherwise
|
|
75
|
+
*/
|
|
76
|
+
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Check if a value is nil
|
|
80
|
+
*
|
|
81
|
+
* @param obj - The value to check
|
|
82
|
+
* @returns True if the value is nil, false otherwise
|
|
83
|
+
*/
|
|
84
|
+
declare function isNil(obj: unknown): obj is Nil;
|
|
85
|
+
/**
|
|
86
|
+
* Check if an object is a JS object
|
|
87
|
+
*
|
|
88
|
+
* @param obj - The object to check
|
|
89
|
+
* @returns True if the object is a JS object}
|
|
90
|
+
*/
|
|
91
|
+
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
92
|
+
/**
|
|
93
|
+
* Check if a value is a function
|
|
94
|
+
*
|
|
95
|
+
* @param obj - The value to check
|
|
96
|
+
* @returns True if the value is a function, false otherwise
|
|
97
|
+
*/
|
|
98
|
+
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
99
|
+
/**
|
|
100
|
+
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
101
|
+
*
|
|
102
|
+
* @param obj - The object to check
|
|
103
|
+
* @returns True if the object is a plain object, false otherwise.
|
|
104
|
+
*/
|
|
105
|
+
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
106
|
+
/**
|
|
107
|
+
* Check if an object is an empty object
|
|
108
|
+
*
|
|
109
|
+
* @param obj - The object to check
|
|
110
|
+
* @returns True if the object is an empty object, false otherwise
|
|
111
|
+
*/
|
|
112
|
+
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* An async iterable stream that can be read from.
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const stream: AsyncIterableStream<string> = getStream();
|
|
119
|
+
* for await (const chunk of stream) {
|
|
120
|
+
* console.log(chunk);
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
125
|
+
/**
|
|
126
|
+
* Create an async iterable stream from a readable stream.
|
|
127
|
+
*
|
|
128
|
+
* This is useful for creating an async iterable stream from a readable stream.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({
|
|
133
|
+
* start(controller) {
|
|
134
|
+
* controller.enqueue("Hello");
|
|
135
|
+
* controller.close();
|
|
136
|
+
* },
|
|
137
|
+
* }));
|
|
138
|
+
* ```
|
|
139
|
+
* @param source The readable stream to create an async iterable stream from.
|
|
140
|
+
* @returns The async iterable stream.
|
|
141
|
+
*/
|
|
142
|
+
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
143
|
+
|
|
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
|
+
|
|
56
158
|
/**
|
|
57
159
|
* Shared logger types for VoltAgent
|
|
58
160
|
* These types define the minimal logger interface that both core and logger packages use
|
|
@@ -64,9 +166,7 @@ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silen
|
|
|
64
166
|
/**
|
|
65
167
|
* Log function signatures
|
|
66
168
|
*/
|
|
67
|
-
|
|
68
|
-
(msg: string, context?: object): void;
|
|
69
|
-
}
|
|
169
|
+
type LogFn = (msg: string, context?: object) => void;
|
|
70
170
|
/**
|
|
71
171
|
* Minimal logger interface for VoltAgent
|
|
72
172
|
* This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
|
|
@@ -157,87 +257,4 @@ interface LogBuffer {
|
|
|
157
257
|
size(): number;
|
|
158
258
|
}
|
|
159
259
|
|
|
160
|
-
|
|
161
|
-
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
162
|
-
*
|
|
163
|
-
* @param obj - The object to clone
|
|
164
|
-
* @param logger - Optional logger for warnings
|
|
165
|
-
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
166
|
-
*/
|
|
167
|
-
declare function deepClone<T>(obj: T, logger?: Logger): T;
|
|
168
|
-
/**
|
|
169
|
-
* Check if an object has a key
|
|
170
|
-
*
|
|
171
|
-
* @param obj - The object to check
|
|
172
|
-
* @param key - The key to check
|
|
173
|
-
* @returns True if the object has the key, false otherwise
|
|
174
|
-
*/
|
|
175
|
-
declare function hasKey<T extends PlainObject, K extends string>(obj: T, key: K): obj is T & SetRequired<T, K>;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Check if a value is nil
|
|
179
|
-
*
|
|
180
|
-
* @param obj - The value to check
|
|
181
|
-
* @returns True if the value is nil, false otherwise
|
|
182
|
-
*/
|
|
183
|
-
declare function isNil(obj: unknown): obj is Nil;
|
|
184
|
-
/**
|
|
185
|
-
* Check if an object is a JS object
|
|
186
|
-
*
|
|
187
|
-
* @param obj - The object to check
|
|
188
|
-
* @returns True if the object is a JS object}
|
|
189
|
-
*/
|
|
190
|
-
declare function isObject<T extends object>(obj: unknown): obj is T;
|
|
191
|
-
/**
|
|
192
|
-
* Check if a value is a function
|
|
193
|
-
*
|
|
194
|
-
* @param obj - The value to check
|
|
195
|
-
* @returns True if the value is a function, false otherwise
|
|
196
|
-
*/
|
|
197
|
-
declare function isFunction<T extends AnyFunction>(obj: unknown): obj is T;
|
|
198
|
-
/**
|
|
199
|
-
* Check if an object is a plain object (i.e. a JS object but not including arrays or functions)
|
|
200
|
-
*
|
|
201
|
-
* @param obj - The object to check
|
|
202
|
-
* @returns True if the object is a plain object, false otherwise.
|
|
203
|
-
*/
|
|
204
|
-
declare function isPlainObject<T extends PlainObject>(obj: unknown): obj is T;
|
|
205
|
-
/**
|
|
206
|
-
* Check if an object is an empty object
|
|
207
|
-
*
|
|
208
|
-
* @param obj - The object to check
|
|
209
|
-
* @returns True if the object is an empty object, false otherwise
|
|
210
|
-
*/
|
|
211
|
-
declare function isEmptyObject(obj: unknown): obj is EmptyObject;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* An async iterable stream that can be read from.
|
|
215
|
-
* @example
|
|
216
|
-
* ```typescript
|
|
217
|
-
* const stream: AsyncIterableStream<string> = getStream();
|
|
218
|
-
* for await (const chunk of stream) {
|
|
219
|
-
* console.log(chunk);
|
|
220
|
-
* }
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
type AsyncIterableStream<T> = Merge<AsyncIterable<T>, ReadableStream<T>>;
|
|
224
|
-
/**
|
|
225
|
-
* Create an async iterable stream from a readable stream.
|
|
226
|
-
*
|
|
227
|
-
* This is useful for creating an async iterable stream from a readable stream.
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({
|
|
232
|
-
* start(controller) {
|
|
233
|
-
* controller.enqueue("Hello");
|
|
234
|
-
* controller.close();
|
|
235
|
-
* },
|
|
236
|
-
* }));
|
|
237
|
-
* ```
|
|
238
|
-
* @param source The readable stream to create an async iterable stream from.
|
|
239
|
-
* @returns The async iterable stream.
|
|
240
|
-
*/
|
|
241
|
-
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
242
|
-
|
|
243
|
-
export { type AsyncIterableStream, type LogBuffer, type LogEntry, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerOptions, convertArrayToAsyncIterable, convertArrayToReadableStream, convertAsyncIterableToArray, convertReadableStreamToArray, convertResponseStreamToArray, createAsyncIterableStream, deepClone, hasKey, isEmptyObject, isFunction, isNil, isObject, isPlainObject };
|
|
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
|
@@ -2,22 +2,7 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
22
7
|
var __export = (target, all) => {
|
|
23
8
|
for (var name in all)
|
|
@@ -32,42 +17,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
32
17
|
return to;
|
|
33
18
|
};
|
|
34
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
-
var __async = (__this, __arguments, generator) => {
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
var fulfilled = (value) => {
|
|
38
|
-
try {
|
|
39
|
-
step(generator.next(value));
|
|
40
|
-
} catch (e) {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var rejected = (value) => {
|
|
45
|
-
try {
|
|
46
|
-
step(generator.throw(value));
|
|
47
|
-
} catch (e) {
|
|
48
|
-
reject(e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
52
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
var __await = function(promise, isYieldStar) {
|
|
56
|
-
this[0] = promise;
|
|
57
|
-
this[1] = isYieldStar;
|
|
58
|
-
};
|
|
59
|
-
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
60
|
-
var resume = (k, v, yes, no) => {
|
|
61
|
-
try {
|
|
62
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
63
|
-
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
64
|
-
} catch (e) {
|
|
65
|
-
no(e);
|
|
66
|
-
}
|
|
67
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
68
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
69
|
-
};
|
|
70
|
-
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
71
20
|
|
|
72
21
|
// src/index.ts
|
|
73
22
|
var index_exports = {};
|
|
@@ -84,56 +33,39 @@ __export(index_exports, {
|
|
|
84
33
|
isFunction: () => isFunction,
|
|
85
34
|
isNil: () => isNil,
|
|
86
35
|
isObject: () => isObject,
|
|
87
|
-
isPlainObject: () => isPlainObject
|
|
36
|
+
isPlainObject: () => isPlainObject,
|
|
37
|
+
safeStringify: () => safeStringify
|
|
88
38
|
});
|
|
89
39
|
module.exports = __toCommonJS(index_exports);
|
|
90
40
|
|
|
91
41
|
// src/test/conversions.ts
|
|
92
|
-
function convertReadableStreamToArray(stream) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return result;
|
|
102
|
-
});
|
|
42
|
+
async function convertReadableStreamToArray(stream) {
|
|
43
|
+
const reader = stream.getReader();
|
|
44
|
+
const result = [];
|
|
45
|
+
while (true) {
|
|
46
|
+
const { done, value } = await reader.read();
|
|
47
|
+
if (done) break;
|
|
48
|
+
result.push(value);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
103
51
|
}
|
|
104
52
|
__name(convertReadableStreamToArray, "convertReadableStreamToArray");
|
|
105
53
|
function convertArrayToAsyncIterable(values) {
|
|
106
54
|
return {
|
|
107
|
-
[Symbol.asyncIterator]() {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
});
|
|
55
|
+
async *[Symbol.asyncIterator]() {
|
|
56
|
+
for (const value of values) {
|
|
57
|
+
yield value;
|
|
58
|
+
}
|
|
113
59
|
}
|
|
114
60
|
};
|
|
115
61
|
}
|
|
116
62
|
__name(convertArrayToAsyncIterable, "convertArrayToAsyncIterable");
|
|
117
|
-
function convertAsyncIterableToArray(iterable) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
result.push(item);
|
|
124
|
-
}
|
|
125
|
-
} catch (temp) {
|
|
126
|
-
error = [temp];
|
|
127
|
-
} finally {
|
|
128
|
-
try {
|
|
129
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
130
|
-
} finally {
|
|
131
|
-
if (error)
|
|
132
|
-
throw error[0];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return result;
|
|
136
|
-
});
|
|
63
|
+
async function convertAsyncIterableToArray(iterable) {
|
|
64
|
+
const result = [];
|
|
65
|
+
for await (const item of iterable) {
|
|
66
|
+
result.push(item);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
137
69
|
}
|
|
138
70
|
__name(convertAsyncIterableToArray, "convertAsyncIterableToArray");
|
|
139
71
|
function convertArrayToReadableStream(values) {
|
|
@@ -150,10 +82,8 @@ function convertArrayToReadableStream(values) {
|
|
|
150
82
|
});
|
|
151
83
|
}
|
|
152
84
|
__name(convertArrayToReadableStream, "convertArrayToReadableStream");
|
|
153
|
-
function convertResponseStreamToArray(response) {
|
|
154
|
-
return
|
|
155
|
-
return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
|
|
156
|
-
});
|
|
85
|
+
async function convertResponseStreamToArray(response) {
|
|
86
|
+
return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
|
|
157
87
|
}
|
|
158
88
|
__name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
159
89
|
|
|
@@ -190,17 +120,20 @@ function isEmptyObject(obj) {
|
|
|
190
120
|
__name(isEmptyObject, "isEmptyObject");
|
|
191
121
|
|
|
192
122
|
// src/utils/objects.ts
|
|
193
|
-
function deepClone(obj
|
|
123
|
+
function deepClone(obj) {
|
|
194
124
|
try {
|
|
195
|
-
|
|
125
|
+
if (typeof structuredClone === "function") {
|
|
126
|
+
return structuredClone(obj);
|
|
127
|
+
}
|
|
128
|
+
throw new Error("structuredClone is not available");
|
|
196
129
|
} catch (error) {
|
|
197
|
-
if (
|
|
198
|
-
|
|
130
|
+
if (process.env.NODE_ENV !== "production") {
|
|
131
|
+
console.warn("Failed to deep clone object, using shallow clone", { error });
|
|
199
132
|
}
|
|
200
133
|
if (obj === null || typeof obj !== "object") {
|
|
201
134
|
return obj;
|
|
202
135
|
}
|
|
203
|
-
return
|
|
136
|
+
return { ...obj };
|
|
204
137
|
}
|
|
205
138
|
}
|
|
206
139
|
__name(deepClone, "deepClone");
|
|
@@ -215,17 +148,48 @@ function createAsyncIterableStream(source) {
|
|
|
215
148
|
stream[Symbol.asyncIterator] = () => {
|
|
216
149
|
const reader = stream.getReader();
|
|
217
150
|
return {
|
|
218
|
-
next() {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return done ? { done: true, value: void 0 } : { done: false, value };
|
|
222
|
-
});
|
|
151
|
+
async next() {
|
|
152
|
+
const { done, value } = await reader.read();
|
|
153
|
+
return done ? { done: true, value: void 0 } : { done: false, value };
|
|
223
154
|
}
|
|
224
155
|
};
|
|
225
156
|
};
|
|
226
157
|
return stream;
|
|
227
158
|
}
|
|
228
159
|
__name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
160
|
+
|
|
161
|
+
// src/utils/safe-stringify.ts
|
|
162
|
+
function safeStringify(input, { indentation } = {}) {
|
|
163
|
+
try {
|
|
164
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
165
|
+
return JSON.stringify(input, safeStringifyReplacer(seen), indentation);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
return `SAFE_STRINGIFY_ERROR: Error stringifying object: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
__name(safeStringify, "safeStringify");
|
|
171
|
+
function safeStringifyReplacer(seen) {
|
|
172
|
+
const replacer = /* @__PURE__ */ __name((_key, value) => {
|
|
173
|
+
if (typeof value?.toJSON === "function") {
|
|
174
|
+
value = value.toJSON();
|
|
175
|
+
}
|
|
176
|
+
if (!(value !== null && typeof value === "object")) {
|
|
177
|
+
return value;
|
|
178
|
+
}
|
|
179
|
+
if (seen.has(value)) {
|
|
180
|
+
return "[Circular]";
|
|
181
|
+
}
|
|
182
|
+
seen.add(value);
|
|
183
|
+
const newValue = Array.isArray(value) ? [] : {};
|
|
184
|
+
for (const [key2, value2] of Object.entries(value)) {
|
|
185
|
+
newValue[key2] = replacer(key2, value2);
|
|
186
|
+
}
|
|
187
|
+
seen.delete(value);
|
|
188
|
+
return newValue;
|
|
189
|
+
}, "replacer");
|
|
190
|
+
return replacer;
|
|
191
|
+
}
|
|
192
|
+
__name(safeStringifyReplacer, "safeStringifyReplacer");
|
|
229
193
|
// Annotate the CommonJS export names for ESM import in node:
|
|
230
194
|
0 && (module.exports = {
|
|
231
195
|
convertArrayToAsyncIterable,
|
|
@@ -240,6 +204,7 @@ __name(createAsyncIterableStream, "createAsyncIterableStream");
|
|
|
240
204
|
isFunction,
|
|
241
205
|
isNil,
|
|
242
206
|
isObject,
|
|
243
|
-
isPlainObject
|
|
207
|
+
isPlainObject,
|
|
208
|
+
safeStringify
|
|
244
209
|
});
|
|
245
210
|
//# sourceMappingURL=index.js.map
|