@voltagent/internal 0.0.5 → 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.
- package/README.md +6 -4
- package/dist/main/index.d.mts +105 -104
- package/dist/main/index.d.ts +105 -104
- package/dist/main/index.js +29 -186
- package/dist/main/index.js.map +1 -1
- package/dist/main/index.mjs +29 -185
- 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 +42 -1
- package/dist/utils/index.d.ts +42 -1
- package/dist/utils/index.js +8 -124
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +8 -125
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +54 -26
- package/dist/dev/index.d.mts +0 -103
- package/dist/dev/index.d.ts +0 -103
- package/dist/dev/index.js +0 -115
- package/dist/dev/index.js.map +0 -1
- package/dist/dev/index.mjs +0 -89
- package/dist/dev/index.mjs.map +0 -1
package/dist/test/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
7
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
@@ -18,42 +17,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
17
|
return to;
|
|
19
18
|
};
|
|
20
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
var __async = (__this, __arguments, generator) => {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
var fulfilled = (value) => {
|
|
24
|
-
try {
|
|
25
|
-
step(generator.next(value));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var rejected = (value) => {
|
|
31
|
-
try {
|
|
32
|
-
step(generator.throw(value));
|
|
33
|
-
} catch (e) {
|
|
34
|
-
reject(e);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
var __await = function(promise, isYieldStar) {
|
|
42
|
-
this[0] = promise;
|
|
43
|
-
this[1] = isYieldStar;
|
|
44
|
-
};
|
|
45
|
-
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
46
|
-
var resume = (k, v, yes, no) => {
|
|
47
|
-
try {
|
|
48
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
49
|
-
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));
|
|
50
|
-
} catch (e) {
|
|
51
|
-
no(e);
|
|
52
|
-
}
|
|
53
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
54
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
55
|
-
};
|
|
56
|
-
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);
|
|
57
20
|
|
|
58
21
|
// src/test/index.ts
|
|
59
22
|
var index_exports = {};
|
|
@@ -67,51 +30,33 @@ __export(index_exports, {
|
|
|
67
30
|
module.exports = __toCommonJS(index_exports);
|
|
68
31
|
|
|
69
32
|
// src/test/conversions.ts
|
|
70
|
-
function convertReadableStreamToArray(stream) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return result;
|
|
80
|
-
});
|
|
33
|
+
async function convertReadableStreamToArray(stream) {
|
|
34
|
+
const reader = stream.getReader();
|
|
35
|
+
const result = [];
|
|
36
|
+
while (true) {
|
|
37
|
+
const { done, value } = await reader.read();
|
|
38
|
+
if (done) break;
|
|
39
|
+
result.push(value);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
81
42
|
}
|
|
82
43
|
__name(convertReadableStreamToArray, "convertReadableStreamToArray");
|
|
83
44
|
function convertArrayToAsyncIterable(values) {
|
|
84
45
|
return {
|
|
85
|
-
[Symbol.asyncIterator]() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
});
|
|
46
|
+
async *[Symbol.asyncIterator]() {
|
|
47
|
+
for (const value of values) {
|
|
48
|
+
yield value;
|
|
49
|
+
}
|
|
91
50
|
}
|
|
92
51
|
};
|
|
93
52
|
}
|
|
94
53
|
__name(convertArrayToAsyncIterable, "convertArrayToAsyncIterable");
|
|
95
|
-
function convertAsyncIterableToArray(iterable) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
result.push(item);
|
|
102
|
-
}
|
|
103
|
-
} catch (temp) {
|
|
104
|
-
error = [temp];
|
|
105
|
-
} finally {
|
|
106
|
-
try {
|
|
107
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
108
|
-
} finally {
|
|
109
|
-
if (error)
|
|
110
|
-
throw error[0];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return result;
|
|
114
|
-
});
|
|
54
|
+
async function convertAsyncIterableToArray(iterable) {
|
|
55
|
+
const result = [];
|
|
56
|
+
for await (const item of iterable) {
|
|
57
|
+
result.push(item);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
115
60
|
}
|
|
116
61
|
__name(convertAsyncIterableToArray, "convertAsyncIterableToArray");
|
|
117
62
|
function convertArrayToReadableStream(values) {
|
|
@@ -128,10 +73,8 @@ function convertArrayToReadableStream(values) {
|
|
|
128
73
|
});
|
|
129
74
|
}
|
|
130
75
|
__name(convertArrayToReadableStream, "convertArrayToReadableStream");
|
|
131
|
-
function convertResponseStreamToArray(response) {
|
|
132
|
-
return
|
|
133
|
-
return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
|
|
134
|
-
});
|
|
76
|
+
async function convertResponseStreamToArray(response) {
|
|
77
|
+
return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
|
|
135
78
|
}
|
|
136
79
|
__name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
137
80
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/test/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/index.ts","../../src/test/conversions.ts"],"sourcesContent":["export {\n convertArrayToAsyncIterable,\n convertArrayToReadableStream,\n convertAsyncIterableToArray,\n convertReadableStreamToArray,\n convertResponseStreamToArray,\n} from \"./conversions\";\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"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/test/index.ts","../../src/test/conversions.ts"],"sourcesContent":["export {\n convertArrayToAsyncIterable,\n convertArrayToReadableStream,\n convertAsyncIterableToArray,\n convertReadableStreamToArray,\n convertResponseStreamToArray,\n} from \"./conversions\";\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;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,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,eAAsB,6BAA6B,UAAuC;AAExF,SAAO,6BAA6B,SAAS,KAAM,YAAY,IAAI,kBAAkB,CAAC,CAAC;AACzF;AAHsB;","names":[]}
|
package/dist/test/index.mjs
CHANGED
|
@@ -1,89 +1,34 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
3
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
-
var __async = (__this, __arguments, generator) => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
var fulfilled = (value) => {
|
|
7
|
-
try {
|
|
8
|
-
step(generator.next(value));
|
|
9
|
-
} catch (e) {
|
|
10
|
-
reject(e);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
var rejected = (value) => {
|
|
14
|
-
try {
|
|
15
|
-
step(generator.throw(value));
|
|
16
|
-
} catch (e) {
|
|
17
|
-
reject(e);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
21
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
var __await = function(promise, isYieldStar) {
|
|
25
|
-
this[0] = promise;
|
|
26
|
-
this[1] = isYieldStar;
|
|
27
|
-
};
|
|
28
|
-
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
29
|
-
var resume = (k, v, yes, no) => {
|
|
30
|
-
try {
|
|
31
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
32
|
-
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));
|
|
33
|
-
} catch (e) {
|
|
34
|
-
no(e);
|
|
35
|
-
}
|
|
36
|
-
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
37
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
38
|
-
};
|
|
39
|
-
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);
|
|
40
3
|
|
|
41
4
|
// src/test/conversions.ts
|
|
42
|
-
function convertReadableStreamToArray(stream) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return result;
|
|
52
|
-
});
|
|
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;
|
|
53
14
|
}
|
|
54
15
|
__name(convertReadableStreamToArray, "convertReadableStreamToArray");
|
|
55
16
|
function convertArrayToAsyncIterable(values) {
|
|
56
17
|
return {
|
|
57
|
-
[Symbol.asyncIterator]() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
});
|
|
18
|
+
async *[Symbol.asyncIterator]() {
|
|
19
|
+
for (const value of values) {
|
|
20
|
+
yield value;
|
|
21
|
+
}
|
|
63
22
|
}
|
|
64
23
|
};
|
|
65
24
|
}
|
|
66
25
|
__name(convertArrayToAsyncIterable, "convertArrayToAsyncIterable");
|
|
67
|
-
function convertAsyncIterableToArray(iterable) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
result.push(item);
|
|
74
|
-
}
|
|
75
|
-
} catch (temp) {
|
|
76
|
-
error = [temp];
|
|
77
|
-
} finally {
|
|
78
|
-
try {
|
|
79
|
-
more && (temp = iter.return) && (yield temp.call(iter));
|
|
80
|
-
} finally {
|
|
81
|
-
if (error)
|
|
82
|
-
throw error[0];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
});
|
|
26
|
+
async function convertAsyncIterableToArray(iterable) {
|
|
27
|
+
const result = [];
|
|
28
|
+
for await (const item of iterable) {
|
|
29
|
+
result.push(item);
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
87
32
|
}
|
|
88
33
|
__name(convertAsyncIterableToArray, "convertAsyncIterableToArray");
|
|
89
34
|
function convertArrayToReadableStream(values) {
|
|
@@ -100,10 +45,8 @@ function convertArrayToReadableStream(values) {
|
|
|
100
45
|
});
|
|
101
46
|
}
|
|
102
47
|
__name(convertArrayToReadableStream, "convertArrayToReadableStream");
|
|
103
|
-
function convertResponseStreamToArray(response) {
|
|
104
|
-
return
|
|
105
|
-
return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
|
|
106
|
-
});
|
|
48
|
+
async function convertResponseStreamToArray(response) {
|
|
49
|
+
return convertReadableStreamToArray(response.body.pipeThrough(new TextDecoderStream()));
|
|
107
50
|
}
|
|
108
51
|
__name(convertResponseStreamToArray, "convertResponseStreamToArray");
|
|
109
52
|
export {
|
package/dist/test/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/conversions.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"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/test/conversions.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"],"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;AAAA,QAC1B;AAAA,MACF,UAAE;AACA,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAZgB;AAmBhB,eAAsB,6BAA6B,UAAuC;AAExF,SAAO,6BAA6B,SAAS,KAAM,YAAY,IAAI,kBAAkB,CAAC,CAAC;AACzF;AAHsB;","names":[]}
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
import { SetRequired, EmptyObject, Merge } from 'type-fest';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Log function signatures
|
|
5
|
+
*/
|
|
6
|
+
type LogFn = (msg: string, context?: object) => void;
|
|
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
|
+
|
|
3
43
|
/**
|
|
4
44
|
* A plain object is an object that has no special properties or methods,
|
|
5
45
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -26,9 +66,10 @@ type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
|
26
66
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
27
67
|
*
|
|
28
68
|
* @param obj - The object to clone
|
|
69
|
+
* @param logger - Optional logger for warnings
|
|
29
70
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
30
71
|
*/
|
|
31
|
-
declare function deepClone<T>(obj: T): T;
|
|
72
|
+
declare function deepClone<T>(obj: T, logger?: Logger): T;
|
|
32
73
|
/**
|
|
33
74
|
* Check if an object has a key
|
|
34
75
|
*
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
import { SetRequired, EmptyObject, Merge } from 'type-fest';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Log function signatures
|
|
5
|
+
*/
|
|
6
|
+
type LogFn = (msg: string, context?: object) => void;
|
|
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
|
+
|
|
3
43
|
/**
|
|
4
44
|
* A plain object is an object that has no special properties or methods,
|
|
5
45
|
* and just has properties that are strings, numbers, or symbols.
|
|
@@ -26,9 +66,10 @@ type AnyFunction = AnyAsyncFunction | AnySyncFunction;
|
|
|
26
66
|
* Deep clone an object using JSON serialization with fallback to shallow clone
|
|
27
67
|
*
|
|
28
68
|
* @param obj - The object to clone
|
|
69
|
+
* @param logger - Optional logger for warnings
|
|
29
70
|
* @returns A deep copy of the object, or shallow copy if JSON serialization fails
|
|
30
71
|
*/
|
|
31
|
-
declare function deepClone<T>(obj: T): T;
|
|
72
|
+
declare function deepClone<T>(obj: T, logger?: Logger): T;
|
|
32
73
|
/**
|
|
33
74
|
* Check if an object has a key
|
|
34
75
|
*
|
package/dist/utils/index.js
CHANGED
|
@@ -2,21 +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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
21
7
|
var __export = (target, all) => {
|
|
22
8
|
for (var name in all)
|
|
@@ -31,26 +17,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
31
17
|
return to;
|
|
32
18
|
};
|
|
33
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
-
var __async = (__this, __arguments, generator) => {
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
var fulfilled = (value) => {
|
|
37
|
-
try {
|
|
38
|
-
step(generator.next(value));
|
|
39
|
-
} catch (e) {
|
|
40
|
-
reject(e);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var rejected = (value) => {
|
|
44
|
-
try {
|
|
45
|
-
step(generator.throw(value));
|
|
46
|
-
} catch (e) {
|
|
47
|
-
reject(e);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
51
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
20
|
|
|
55
21
|
// src/utils/index.ts
|
|
56
22
|
var index_exports = {};
|
|
@@ -66,88 +32,6 @@ __export(index_exports, {
|
|
|
66
32
|
});
|
|
67
33
|
module.exports = __toCommonJS(index_exports);
|
|
68
34
|
|
|
69
|
-
// src/dev/logger.ts
|
|
70
|
-
function createDevLogger(options) {
|
|
71
|
-
const isDev = typeof (options == null ? void 0 : options.dev) === "function" ? options.dev : () => {
|
|
72
|
-
var _a;
|
|
73
|
-
return (_a = options == null ? void 0 : options.dev) != null ? _a : isDevNodeEnv();
|
|
74
|
-
};
|
|
75
|
-
return {
|
|
76
|
-
/**
|
|
77
|
-
* Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* devLogger.info("Hello, world!");
|
|
82
|
-
*
|
|
83
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
|
-
* @param message - The message to log.
|
|
87
|
-
* @param args - The arguments to log.
|
|
88
|
-
*/
|
|
89
|
-
info: /* @__PURE__ */ __name((message, ...args) => {
|
|
90
|
-
if (isDev()) {
|
|
91
|
-
console.info(formatLogPrefix("INFO"), message, ...args);
|
|
92
|
-
}
|
|
93
|
-
}, "info"),
|
|
94
|
-
/**
|
|
95
|
-
* Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not "development".
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```typescript
|
|
99
|
-
* devLogger.warn("Hello, world!");
|
|
100
|
-
*
|
|
101
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* @param message - The message to log.
|
|
105
|
-
* @param args - The arguments to log.
|
|
106
|
-
*/
|
|
107
|
-
warn: /* @__PURE__ */ __name((message, ...args) => {
|
|
108
|
-
if (isDev()) {
|
|
109
|
-
console.warn(formatLogPrefix("WARN"), message, ...args);
|
|
110
|
-
}
|
|
111
|
-
}, "warn"),
|
|
112
|
-
/**
|
|
113
|
-
* Log a warning message to the console if the environment is development.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```typescript
|
|
117
|
-
* devLogger.error("Hello, world!");
|
|
118
|
-
*
|
|
119
|
-
* // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* @param message - The message to log.
|
|
123
|
-
* @param args - The arguments to log.
|
|
124
|
-
*/
|
|
125
|
-
error: /* @__PURE__ */ __name((message, ...args) => {
|
|
126
|
-
if (isDev()) {
|
|
127
|
-
console.error(formatLogPrefix("ERROR"), message, ...args);
|
|
128
|
-
}
|
|
129
|
-
}, "error"),
|
|
130
|
-
debug: /* @__PURE__ */ __name((_message, ..._args) => {
|
|
131
|
-
return;
|
|
132
|
-
}, "debug")
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
__name(createDevLogger, "createDevLogger");
|
|
136
|
-
var logger_default = createDevLogger();
|
|
137
|
-
function isDevNodeEnv() {
|
|
138
|
-
const nodeEnv = process.env.NODE_ENV;
|
|
139
|
-
return nodeEnv !== "production" && nodeEnv !== "test" && nodeEnv !== "ci";
|
|
140
|
-
}
|
|
141
|
-
__name(isDevNodeEnv, "isDevNodeEnv");
|
|
142
|
-
function formatLogPrefix(level) {
|
|
143
|
-
return `[VoltAgent] [${timestamp()}] ${level}: `;
|
|
144
|
-
}
|
|
145
|
-
__name(formatLogPrefix, "formatLogPrefix");
|
|
146
|
-
function timestamp() {
|
|
147
|
-
return (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, -1);
|
|
148
|
-
}
|
|
149
|
-
__name(timestamp, "timestamp");
|
|
150
|
-
|
|
151
35
|
// src/utils/lang.ts
|
|
152
36
|
function isNil(obj) {
|
|
153
37
|
return obj === null || obj === void 0;
|
|
@@ -181,15 +65,17 @@ function isEmptyObject(obj) {
|
|
|
181
65
|
__name(isEmptyObject, "isEmptyObject");
|
|
182
66
|
|
|
183
67
|
// src/utils/objects.ts
|
|
184
|
-
function deepClone(obj) {
|
|
68
|
+
function deepClone(obj, logger) {
|
|
185
69
|
try {
|
|
186
70
|
return JSON.parse(JSON.stringify(obj));
|
|
187
71
|
} catch (error) {
|
|
188
|
-
|
|
72
|
+
if (logger) {
|
|
73
|
+
logger.warn("Failed to deep clone object, using shallow clone", { error });
|
|
74
|
+
}
|
|
189
75
|
if (obj === null || typeof obj !== "object") {
|
|
190
76
|
return obj;
|
|
191
77
|
}
|
|
192
|
-
return
|
|
78
|
+
return { ...obj };
|
|
193
79
|
}
|
|
194
80
|
}
|
|
195
81
|
__name(deepClone, "deepClone");
|
|
@@ -204,11 +90,9 @@ function createAsyncIterableStream(source) {
|
|
|
204
90
|
stream[Symbol.asyncIterator] = () => {
|
|
205
91
|
const reader = stream.getReader();
|
|
206
92
|
return {
|
|
207
|
-
next() {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return done ? { done: true, value: void 0 } : { done: false, value };
|
|
211
|
-
});
|
|
93
|
+
async next() {
|
|
94
|
+
const { done, value } = await reader.read();
|
|
95
|
+
return done ? { done: true, value: void 0 } : { done: false, value };
|
|
212
96
|
}
|
|
213
97
|
};
|
|
214
98
|
};
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts","../../src/dev/logger.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","export interface DevLoggerOptions {\n dev: boolean | (() => boolean);\n}\n\n/**\n * A logger for development purposes, that will not pollute the production logs (aka if process.env.NODE_ENV is not \"development\").\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n * ```\n */\nexport function createDevLogger(options?: DevLoggerOptions) {\n const isDev =\n typeof options?.dev === \"function\" ? options.dev : () => options?.dev ?? isDevNodeEnv();\n\n return {\n /**\n * Log a message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.info(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] INFO: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n info: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.info(formatLogPrefix(\"INFO\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development. This will NOT be logged if process.env.NODE_ENV is not \"development\".\n *\n * @example\n * ```typescript\n * devLogger.warn(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] WARN: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n warn: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.warn(formatLogPrefix(\"WARN\"), message, ...args);\n }\n },\n /**\n * Log a warning message to the console if the environment is development.\n *\n * @example\n * ```typescript\n * devLogger.error(\"Hello, world!\");\n *\n * // output: [VoltAgent] [2021-01-01T00:00:00.000Z] ERROR: Hello, world!\n * ```\n *\n * @param message - The message to log.\n * @param args - The arguments to log.\n */\n error: (message?: any, ...args: any[]) => {\n if (isDev()) {\n console.error(formatLogPrefix(\"ERROR\"), message, ...args);\n }\n },\n\n debug: (_message?: any, ..._args: any[]) => {\n // todo: implement debug logging with pino\n return;\n },\n };\n}\n\nexport default createDevLogger();\n\nfunction isDevNodeEnv() {\n const nodeEnv = process.env.NODE_ENV;\n return nodeEnv !== \"production\" && nodeEnv !== \"test\" && nodeEnv !== \"ci\";\n}\n\nfunction formatLogPrefix(level: \"INFO\" | \"WARN\" | \"ERROR\" | \"DEBUG\"): string {\n return `[VoltAgent] [${timestamp()}] ${level}: `;\n}\n\nfunction timestamp(): string {\n return new Date().toISOString().replace(\"T\", \" \").slice(0, -1);\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 { devLogger } from \"../dev\";\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 * @returns A deep copy of the object, or shallow copy if JSON serialization fails\n */\nexport function deepClone<T>(obj: T): T {\n try {\n return JSON.parse(JSON.stringify(obj));\n } catch (error) {\n devLogger.warn(\"Failed to deep clone object, using shallow clone:\", 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"],"mappings":"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","names":[]}
|
|
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 { 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;;;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;;;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":[]}
|