@voltagent/internal 0.0.6 → 0.0.7

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.
@@ -31,28 +31,6 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
31
31
  */
32
32
  declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
33
33
 
34
- /**
35
- * A plain object is an object that has no special properties or methods,
36
- * and just has properties that are strings, numbers, or symbols.
37
- */
38
- type PlainObject = Record<string | number | symbol, unknown>;
39
- /**
40
- * A nil value is a value that is not defined or is undefined.
41
- */
42
- type Nil = null | undefined;
43
- /**
44
- * A type that represents any async function.
45
- */
46
- type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
47
- /**
48
- * A type that represents any synchronous function.
49
- */
50
- type AnySyncFunction = (...args: unknown[]) => unknown;
51
- /**
52
- * A type that represents any function.
53
- */
54
- type AnyFunction = AnyAsyncFunction | AnySyncFunction;
55
-
56
34
  /**
57
35
  * Shared logger types for VoltAgent
58
36
  * These types define the minimal logger interface that both core and logger packages use
@@ -64,9 +42,7 @@ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silen
64
42
  /**
65
43
  * Log function signatures
66
44
  */
67
- interface LogFn {
68
- (msg: string, context?: object): void;
69
- }
45
+ type LogFn = (msg: string, context?: object) => void;
70
46
  /**
71
47
  * Minimal logger interface for VoltAgent
72
48
  * This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
@@ -157,6 +133,28 @@ interface LogBuffer {
157
133
  size(): number;
158
134
  }
159
135
 
136
+ /**
137
+ * A plain object is an object that has no special properties or methods,
138
+ * and just has properties that are strings, numbers, or symbols.
139
+ */
140
+ type PlainObject = Record<string | number | symbol, unknown>;
141
+ /**
142
+ * A nil value is a value that is not defined or is undefined.
143
+ */
144
+ type Nil = null | undefined;
145
+ /**
146
+ * A type that represents any async function.
147
+ */
148
+ type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
149
+ /**
150
+ * A type that represents any synchronous function.
151
+ */
152
+ type AnySyncFunction = (...args: unknown[]) => unknown;
153
+ /**
154
+ * A type that represents any function.
155
+ */
156
+ type AnyFunction = AnyAsyncFunction | AnySyncFunction;
157
+
160
158
  /**
161
159
  * Deep clone an object using JSON serialization with fallback to shallow clone
162
160
  *
@@ -31,28 +31,6 @@ declare function convertArrayToReadableStream<T>(values: T[]): ReadableStream<T>
31
31
  */
32
32
  declare function convertResponseStreamToArray(response: Response): Promise<string[]>;
33
33
 
34
- /**
35
- * A plain object is an object that has no special properties or methods,
36
- * and just has properties that are strings, numbers, or symbols.
37
- */
38
- type PlainObject = Record<string | number | symbol, unknown>;
39
- /**
40
- * A nil value is a value that is not defined or is undefined.
41
- */
42
- type Nil = null | undefined;
43
- /**
44
- * A type that represents any async function.
45
- */
46
- type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
47
- /**
48
- * A type that represents any synchronous function.
49
- */
50
- type AnySyncFunction = (...args: unknown[]) => unknown;
51
- /**
52
- * A type that represents any function.
53
- */
54
- type AnyFunction = AnyAsyncFunction | AnySyncFunction;
55
-
56
34
  /**
57
35
  * Shared logger types for VoltAgent
58
36
  * These types define the minimal logger interface that both core and logger packages use
@@ -64,9 +42,7 @@ type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "silen
64
42
  /**
65
43
  * Log function signatures
66
44
  */
67
- interface LogFn {
68
- (msg: string, context?: object): void;
69
- }
45
+ type LogFn = (msg: string, context?: object) => void;
70
46
  /**
71
47
  * Minimal logger interface for VoltAgent
72
48
  * This interface is implemented by @voltagent/logger and can be implemented by other logging solutions
@@ -157,6 +133,28 @@ interface LogBuffer {
157
133
  size(): number;
158
134
  }
159
135
 
136
+ /**
137
+ * A plain object is an object that has no special properties or methods,
138
+ * and just has properties that are strings, numbers, or symbols.
139
+ */
140
+ type PlainObject = Record<string | number | symbol, unknown>;
141
+ /**
142
+ * A nil value is a value that is not defined or is undefined.
143
+ */
144
+ type Nil = null | undefined;
145
+ /**
146
+ * A type that represents any async function.
147
+ */
148
+ type AnyAsyncFunction = (...args: unknown[]) => Promise<unknown>;
149
+ /**
150
+ * A type that represents any synchronous function.
151
+ */
152
+ type AnySyncFunction = (...args: unknown[]) => unknown;
153
+ /**
154
+ * A type that represents any function.
155
+ */
156
+ type AnyFunction = AnyAsyncFunction | AnySyncFunction;
157
+
160
158
  /**
161
159
  * Deep clone an object using JSON serialization with fallback to shallow clone
162
160
  *
@@ -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 = {};
@@ -89,51 +38,33 @@ __export(index_exports, {
89
38
  module.exports = __toCommonJS(index_exports);
90
39
 
91
40
  // src/test/conversions.ts
92
- function convertReadableStreamToArray(stream) {
93
- return __async(this, null, function* () {
94
- const reader = stream.getReader();
95
- const result = [];
96
- while (true) {
97
- const { done, value } = yield reader.read();
98
- if (done) break;
99
- result.push(value);
100
- }
101
- return result;
102
- });
41
+ async function convertReadableStreamToArray(stream) {
42
+ const reader = stream.getReader();
43
+ const result = [];
44
+ while (true) {
45
+ const { done, value } = await reader.read();
46
+ if (done) break;
47
+ result.push(value);
48
+ }
49
+ return result;
103
50
  }
104
51
  __name(convertReadableStreamToArray, "convertReadableStreamToArray");
105
52
  function convertArrayToAsyncIterable(values) {
106
53
  return {
107
- [Symbol.asyncIterator]() {
108
- return __asyncGenerator(this, null, function* () {
109
- for (const value of values) {
110
- yield value;
111
- }
112
- });
54
+ async *[Symbol.asyncIterator]() {
55
+ for (const value of values) {
56
+ yield value;
57
+ }
113
58
  }
114
59
  };
115
60
  }
116
61
  __name(convertArrayToAsyncIterable, "convertArrayToAsyncIterable");
117
- function convertAsyncIterableToArray(iterable) {
118
- return __async(this, null, function* () {
119
- const result = [];
120
- try {
121
- for (var iter = __forAwait(iterable), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
122
- const item = temp.value;
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
- });
62
+ async function convertAsyncIterableToArray(iterable) {
63
+ const result = [];
64
+ for await (const item of iterable) {
65
+ result.push(item);
66
+ }
67
+ return result;
137
68
  }
138
69
  __name(convertAsyncIterableToArray, "convertAsyncIterableToArray");
139
70
  function convertArrayToReadableStream(values) {
@@ -150,10 +81,8 @@ function convertArrayToReadableStream(values) {
150
81
  });
151
82
  }
152
83
  __name(convertArrayToReadableStream, "convertArrayToReadableStream");
153
- function convertResponseStreamToArray(response) {
154
- return __async(this, null, function* () {
155
- return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
156
- });
84
+ async function convertResponseStreamToArray(response) {
85
+ return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
157
86
  }
158
87
  __name(convertResponseStreamToArray, "convertResponseStreamToArray");
159
88
 
@@ -200,7 +129,7 @@ function deepClone(obj, logger) {
200
129
  if (obj === null || typeof obj !== "object") {
201
130
  return obj;
202
131
  }
203
- return __spreadValues({}, obj);
132
+ return { ...obj };
204
133
  }
205
134
  }
206
135
  __name(deepClone, "deepClone");
@@ -215,11 +144,9 @@ function createAsyncIterableStream(source) {
215
144
  stream[Symbol.asyncIterator] = () => {
216
145
  const reader = stream.getReader();
217
146
  return {
218
- next() {
219
- return __async(this, null, function* () {
220
- const { done, value } = yield reader.read();
221
- return done ? { done: true, value: void 0 } : { done: false, value };
222
- });
147
+ async next() {
148
+ const { done, value } = await reader.read();
149
+ return done ? { done: true, value: void 0 } : { done: false, value };
223
150
  }
224
151
  };
225
152
  };
@@ -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 { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\nimport type { Logger } from \"../logger/types\";\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC1C,iBAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAU,IAAI,EAAE,MAAM,OAAO,MAAM;AAAA,QACxE;AAAA;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"],"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,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ACT;AAGA,MAAI,OAAO,oBAAoB,GAAG,EAAE,SAAS,KAAK,OAAO,sBAAsB,GAAG,EAAE,SAAS,GAAG;AAC9F,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAXgB;;;AC1CT,SAAS,UAAa,KAAQ,QAAoB;AACvD,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AAAA,EACvC,SAAS,OAAO;AACd,QAAI,QAAQ;AACV,aAAO,KAAK,oDAAoD,EAAE,MAAM,CAAC;AAAA,IAC3E;AAEA,QAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C,aAAO;AAAA,IACT;AACA,WAAO,EAAE,GAAG,IAAI;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,104 +1,34 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __spreadValues = (a, b) => {
8
- for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
11
- if (__getOwnPropSymbols)
12
- for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- }
16
- return a;
17
- };
18
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
19
- var __async = (__this, __arguments, generator) => {
20
- return new Promise((resolve, reject) => {
21
- var fulfilled = (value) => {
22
- try {
23
- step(generator.next(value));
24
- } catch (e) {
25
- reject(e);
26
- }
27
- };
28
- var rejected = (value) => {
29
- try {
30
- step(generator.throw(value));
31
- } catch (e) {
32
- reject(e);
33
- }
34
- };
35
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
- step((generator = generator.apply(__this, __arguments)).next());
37
- });
38
- };
39
- var __await = function(promise, isYieldStar) {
40
- this[0] = promise;
41
- this[1] = isYieldStar;
42
- };
43
- var __asyncGenerator = (__this, __arguments, generator) => {
44
- var resume = (k, v, yes, no) => {
45
- try {
46
- var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
47
- 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));
48
- } catch (e) {
49
- no(e);
50
- }
51
- }, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
52
- return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
53
- };
54
- 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);
55
3
 
56
4
  // src/test/conversions.ts
57
- function convertReadableStreamToArray(stream) {
58
- return __async(this, null, function* () {
59
- const reader = stream.getReader();
60
- const result = [];
61
- while (true) {
62
- const { done, value } = yield reader.read();
63
- if (done) break;
64
- result.push(value);
65
- }
66
- return result;
67
- });
5
+ async function convertReadableStreamToArray(stream) {
6
+ const reader = stream.getReader();
7
+ const result = [];
8
+ while (true) {
9
+ const { done, value } = await reader.read();
10
+ if (done) break;
11
+ result.push(value);
12
+ }
13
+ return result;
68
14
  }
69
15
  __name(convertReadableStreamToArray, "convertReadableStreamToArray");
70
16
  function convertArrayToAsyncIterable(values) {
71
17
  return {
72
- [Symbol.asyncIterator]() {
73
- return __asyncGenerator(this, null, function* () {
74
- for (const value of values) {
75
- yield value;
76
- }
77
- });
18
+ async *[Symbol.asyncIterator]() {
19
+ for (const value of values) {
20
+ yield value;
21
+ }
78
22
  }
79
23
  };
80
24
  }
81
25
  __name(convertArrayToAsyncIterable, "convertArrayToAsyncIterable");
82
- function convertAsyncIterableToArray(iterable) {
83
- return __async(this, null, function* () {
84
- const result = [];
85
- try {
86
- for (var iter = __forAwait(iterable), more, temp, error; more = !(temp = yield iter.next()).done; more = false) {
87
- const item = temp.value;
88
- result.push(item);
89
- }
90
- } catch (temp) {
91
- error = [temp];
92
- } finally {
93
- try {
94
- more && (temp = iter.return) && (yield temp.call(iter));
95
- } finally {
96
- if (error)
97
- throw error[0];
98
- }
99
- }
100
- return result;
101
- });
26
+ async function convertAsyncIterableToArray(iterable) {
27
+ const result = [];
28
+ for await (const item of iterable) {
29
+ result.push(item);
30
+ }
31
+ return result;
102
32
  }
103
33
  __name(convertAsyncIterableToArray, "convertAsyncIterableToArray");
104
34
  function convertArrayToReadableStream(values) {
@@ -115,10 +45,8 @@ function convertArrayToReadableStream(values) {
115
45
  });
116
46
  }
117
47
  __name(convertArrayToReadableStream, "convertArrayToReadableStream");
118
- function convertResponseStreamToArray(response) {
119
- return __async(this, null, function* () {
120
- return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
121
- });
48
+ async function convertResponseStreamToArray(response) {
49
+ return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
122
50
  }
123
51
  __name(convertResponseStreamToArray, "convertResponseStreamToArray");
124
52
 
@@ -165,7 +93,7 @@ function deepClone(obj, logger) {
165
93
  if (obj === null || typeof obj !== "object") {
166
94
  return obj;
167
95
  }
168
- return __spreadValues({}, obj);
96
+ return { ...obj };
169
97
  }
170
98
  }
171
99
  __name(deepClone, "deepClone");
@@ -180,11 +108,9 @@ function createAsyncIterableStream(source) {
180
108
  stream[Symbol.asyncIterator] = () => {
181
109
  const reader = stream.getReader();
182
110
  return {
183
- next() {
184
- return __async(this, null, function* () {
185
- const { done, value } = yield reader.read();
186
- return done ? { done: true, value: void 0 } : { done: false, value };
187
- });
111
+ async next() {
112
+ const { done, value } = await reader.read();
113
+ return done ? { done: true, value: void 0 } : { done: false, value };
188
114
  }
189
115
  };
190
116
  };
@@ -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 { PlainObject } from \"../types\";\nimport { isObject } from \"./lang\";\nimport type { Logger } from \"../logger/types\";\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,SAAsB,6BAAgC,QAAyC;AAAA;AAC7F,UAAM,SAAS,OAAO,UAAU;AAChC,UAAM,SAAc,CAAC;AAErB,WAAO,MAAM;AACX,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,UAAI,KAAM;AACV,aAAO,KAAK,KAAK;AAAA,IACnB;AAEA,WAAO;AAAA,EACT;AAAA;AAXsB;AAkBf,SAAS,4BAA+B,QAA+B;AAC5E,SAAO;AAAA,IACL,CAAQ,OAAO,aAAa,IAAI;AAAA;AAC9B,mBAAW,SAAS,QAAQ;AAC1B,gBAAM;AAAA,QACR;AAAA,MACF;AAAA;AAAA,EACF;AACF;AARgB;AAehB,SAAsB,4BAA+B,UAA0C;AAAA;AAC7F,UAAM,SAAc,CAAC;AACrB;AAAA,iCAAyB,WAAzB,0EAAmC;AAAxB,cAAM,OAAjB;AACE,eAAO,KAAK,IAAI;AAAA,MAClB;AAAA,aAFA,MAxCF;AAwCE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,WAAO;AAAA,EACT;AAAA;AANsB;AAaf,SAAS,6BAAgC,QAAgC;AAC9E,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,YAAY;AAChB,UAAI;AACF,mBAAW,SAAS,QAAQ;AAC1B,qBAAW,QAAQ,KAAK;AAAA,QAC1B;AAAA,MACF,UAAE;AACA,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAZgB;AAmBhB,SAAsB,6BAA6B,UAAuC;AAAA;AAExF,WAAO,6BAA6B,SAAS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AAM,SAAS,OAAO,UAAU;AAChC,WAAO;AAAA,MACC,OAAmC;AAAA;AACvC,gBAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,iBAAO,OAAO,EAAE,MAAM,MAAM,OAAO,OAAU,IAAI,EAAE,MAAM,OAAO,MAAM;AAAA,QACxE;AAAA;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"],"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;AAXs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