opik 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Client-DilyWTdT.d.cts → Client-W52L9RIs.d.cts} +2 -0
- package/dist/{Client-DilyWTdT.d.ts → Client-W52L9RIs.d.ts} +2 -0
- package/dist/Node18UniversalStreamWrapper-GZXI7BSF.js +1 -0
- package/dist/NodePre18StreamWrapper-TZYQXHQT.js +1 -0
- package/dist/UndiciStreamWrapper-4QYH36IP.js +1 -0
- package/dist/chunk-POLPT3OJ.js +4 -0
- package/dist/chunk-WOT6VMZA.js +1 -0
- package/dist/index.cjs +4 -13021
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1 -4
- package/dist/vercel/index.cjs +4 -13037
- package/dist/vercel/index.d.cts +1 -1
- package/dist/vercel/index.d.ts +1 -1
- package/dist/vercel/index.js +1 -207
- package/package.json +7 -2
- package/dist/Node18UniversalStreamWrapper-CE7OKAXD.js +0 -217
- package/dist/Node18UniversalStreamWrapper-CE7OKAXD.js.map +0 -1
- package/dist/NodePre18StreamWrapper-TYJO3GAZ.js +0 -89
- package/dist/NodePre18StreamWrapper-TYJO3GAZ.js.map +0 -1
- package/dist/UndiciStreamWrapper-UCC32KBP.js +0 -205
- package/dist/UndiciStreamWrapper-UCC32KBP.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/chunk-ZB4ZJRLY.js +0 -12479
- package/dist/chunk-ZB4ZJRLY.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/vercel/index.cjs.map +0 -1
- package/dist/vercel/index.js.map +0 -1
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import './chunk-PZ5AY32C.js';
|
|
2
|
-
|
|
3
|
-
// src/opik/rest_api/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts
|
|
4
|
-
var UndiciStreamWrapper = class _UndiciStreamWrapper {
|
|
5
|
-
constructor(readableStream) {
|
|
6
|
-
this.readableStream = readableStream;
|
|
7
|
-
this.reader = this.readableStream.getReader();
|
|
8
|
-
this.events = {
|
|
9
|
-
data: [],
|
|
10
|
-
end: [],
|
|
11
|
-
error: [],
|
|
12
|
-
readable: [],
|
|
13
|
-
close: [],
|
|
14
|
-
pause: [],
|
|
15
|
-
resume: []
|
|
16
|
-
};
|
|
17
|
-
this.paused = false;
|
|
18
|
-
this.resumeCallback = null;
|
|
19
|
-
this.encoding = null;
|
|
20
|
-
}
|
|
21
|
-
on(event, callback) {
|
|
22
|
-
var _a;
|
|
23
|
-
(_a = this.events[event]) == null ? void 0 : _a.push(callback);
|
|
24
|
-
}
|
|
25
|
-
off(event, callback) {
|
|
26
|
-
var _a;
|
|
27
|
-
this.events[event] = (_a = this.events[event]) == null ? void 0 : _a.filter((cb) => cb !== callback);
|
|
28
|
-
}
|
|
29
|
-
pipe(dest) {
|
|
30
|
-
this.on("data", (chunk) => {
|
|
31
|
-
if (dest instanceof _UndiciStreamWrapper) {
|
|
32
|
-
dest._write(chunk);
|
|
33
|
-
} else {
|
|
34
|
-
const writer = dest.getWriter();
|
|
35
|
-
writer.write(chunk).then(() => writer.releaseLock());
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
this.on("end", () => {
|
|
39
|
-
if (dest instanceof _UndiciStreamWrapper) {
|
|
40
|
-
dest._end();
|
|
41
|
-
} else {
|
|
42
|
-
const writer = dest.getWriter();
|
|
43
|
-
writer.close();
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
this.on("error", (error) => {
|
|
47
|
-
if (dest instanceof _UndiciStreamWrapper) {
|
|
48
|
-
dest._error(error);
|
|
49
|
-
} else {
|
|
50
|
-
const writer = dest.getWriter();
|
|
51
|
-
writer.abort(error);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
this._startReading();
|
|
55
|
-
return dest;
|
|
56
|
-
}
|
|
57
|
-
pipeTo(dest) {
|
|
58
|
-
return this.pipe(dest);
|
|
59
|
-
}
|
|
60
|
-
unpipe(dest) {
|
|
61
|
-
this.off("data", (chunk) => {
|
|
62
|
-
if (dest instanceof _UndiciStreamWrapper) {
|
|
63
|
-
dest._write(chunk);
|
|
64
|
-
} else {
|
|
65
|
-
const writer = dest.getWriter();
|
|
66
|
-
writer.write(chunk).then(() => writer.releaseLock());
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
this.off("end", () => {
|
|
70
|
-
if (dest instanceof _UndiciStreamWrapper) {
|
|
71
|
-
dest._end();
|
|
72
|
-
} else {
|
|
73
|
-
const writer = dest.getWriter();
|
|
74
|
-
writer.close();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
this.off("error", (error) => {
|
|
78
|
-
if (dest instanceof _UndiciStreamWrapper) {
|
|
79
|
-
dest._error(error);
|
|
80
|
-
} else {
|
|
81
|
-
const writer = dest.getWriter();
|
|
82
|
-
writer.abort(error);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
destroy(error) {
|
|
87
|
-
this.reader.cancel(error).then(() => {
|
|
88
|
-
this._emit("close");
|
|
89
|
-
}).catch((err) => {
|
|
90
|
-
this._emit("error", err);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
pause() {
|
|
94
|
-
this.paused = true;
|
|
95
|
-
this._emit("pause");
|
|
96
|
-
}
|
|
97
|
-
resume() {
|
|
98
|
-
if (this.paused) {
|
|
99
|
-
this.paused = false;
|
|
100
|
-
this._emit("resume");
|
|
101
|
-
if (this.resumeCallback) {
|
|
102
|
-
this.resumeCallback();
|
|
103
|
-
this.resumeCallback = null;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
get isPaused() {
|
|
108
|
-
return this.paused;
|
|
109
|
-
}
|
|
110
|
-
async read() {
|
|
111
|
-
if (this.paused) {
|
|
112
|
-
await new Promise((resolve) => {
|
|
113
|
-
this.resumeCallback = resolve;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const { done, value } = await this.reader.read();
|
|
117
|
-
if (done) {
|
|
118
|
-
return void 0;
|
|
119
|
-
}
|
|
120
|
-
return value;
|
|
121
|
-
}
|
|
122
|
-
setEncoding(encoding) {
|
|
123
|
-
this.encoding = encoding;
|
|
124
|
-
}
|
|
125
|
-
async text() {
|
|
126
|
-
const chunks = [];
|
|
127
|
-
while (true) {
|
|
128
|
-
const { done, value } = await this.reader.read();
|
|
129
|
-
if (done) {
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
if (value) {
|
|
133
|
-
chunks.push(value);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const decoder = new TextDecoder(this.encoding || "utf-8");
|
|
137
|
-
return decoder.decode(await new Blob(chunks).arrayBuffer());
|
|
138
|
-
}
|
|
139
|
-
async json() {
|
|
140
|
-
const text = await this.text();
|
|
141
|
-
return JSON.parse(text);
|
|
142
|
-
}
|
|
143
|
-
_write(chunk) {
|
|
144
|
-
this._emit("data", chunk);
|
|
145
|
-
}
|
|
146
|
-
_end() {
|
|
147
|
-
this._emit("end");
|
|
148
|
-
}
|
|
149
|
-
_error(error) {
|
|
150
|
-
this._emit("error", error);
|
|
151
|
-
}
|
|
152
|
-
_emit(event, data) {
|
|
153
|
-
if (this.events[event]) {
|
|
154
|
-
for (const callback of this.events[event] || []) {
|
|
155
|
-
callback(data);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
async _startReading() {
|
|
160
|
-
try {
|
|
161
|
-
this._emit("readable");
|
|
162
|
-
while (true) {
|
|
163
|
-
if (this.paused) {
|
|
164
|
-
await new Promise((resolve) => {
|
|
165
|
-
this.resumeCallback = resolve;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
const { done, value } = await this.reader.read();
|
|
169
|
-
if (done) {
|
|
170
|
-
this._emit("end");
|
|
171
|
-
this._emit("close");
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
if (value) {
|
|
175
|
-
this._emit("data", value);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
} catch (error) {
|
|
179
|
-
this._emit("error", error);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
[Symbol.asyncIterator]() {
|
|
183
|
-
return {
|
|
184
|
-
next: async () => {
|
|
185
|
-
if (this.paused) {
|
|
186
|
-
await new Promise((resolve) => {
|
|
187
|
-
this.resumeCallback = resolve;
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
const { done, value } = await this.reader.read();
|
|
191
|
-
if (done) {
|
|
192
|
-
return { done: true, value: void 0 };
|
|
193
|
-
}
|
|
194
|
-
return { done: false, value };
|
|
195
|
-
},
|
|
196
|
-
[Symbol.asyncIterator]() {
|
|
197
|
-
return this;
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
export { UndiciStreamWrapper };
|
|
204
|
-
//# sourceMappingURL=UndiciStreamWrapper-UCC32KBP.js.map
|
|
205
|
-
//# sourceMappingURL=UndiciStreamWrapper-UCC32KBP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/opik/rest_api/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts"],"names":[],"mappings":";;;AAIa,IAAA,mBAAA,GAAN,MAAM,oBAEb,CAAA;AAAA,EAQI,YAAY,cAA4C,EAAA;AACpD,IAAA,IAAA,CAAK,cAAiB,GAAA,cAAA;AACtB,IAAK,IAAA,CAAA,MAAA,GAAS,IAAK,CAAA,cAAA,CAAe,SAAU,EAAA;AAC5C,IAAA,IAAA,CAAK,MAAS,GAAA;AAAA,MACV,MAAM,EAAC;AAAA,MACP,KAAK,EAAC;AAAA,MACN,OAAO,EAAC;AAAA,MACR,UAAU,EAAC;AAAA,MACX,OAAO,EAAC;AAAA,MACR,OAAO,EAAC;AA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Aa,CAAI,GAAA;AACrB,QAAO,OAAA,IAAA;AAAA;AACX,KACJ;AAAA;AAER","file":"UndiciStreamWrapper-UCC32KBP.js","sourcesContent":["import { StreamWrapper } from \"./chooseStreamWrapper\";\n\ntype EventCallback = (data?: any) => void;\n\nexport class UndiciStreamWrapper<ReadFormat extends Uint8Array | Uint16Array | Uint32Array>\n implements StreamWrapper<UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>, ReadFormat>\n{\n private readableStream: ReadableStream<ReadFormat>;\n private reader: ReadableStreamDefaultReader<ReadFormat>;\n private events: Record<string, EventCallback[] | undefined>;\n private paused: boolean;\n private resumeCallback: ((value?: unknown) => void) | null;\n private encoding: string | null;\n\n constructor(readableStream: ReadableStream<ReadFormat>) {\n this.readableStream = readableStream;\n this.reader = this.readableStream.getReader();\n this.events = {\n data: [],\n end: [],\n error: [],\n readable: [],\n close: [],\n pause: [],\n resume: [],\n };\n this.paused = false;\n this.resumeCallback = null;\n this.encoding = null;\n }\n\n public on(event: string, callback: EventCallback): void {\n this.events[event]?.push(callback);\n }\n\n public off(event: string, callback: EventCallback): void {\n this.events[event] = this.events[event]?.filter((cb) => cb !== callback);\n }\n\n public pipe(\n dest: UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>,\n ): UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat> {\n this.on(\"data\", (chunk) => {\n if (dest instanceof UndiciStreamWrapper) {\n dest._write(chunk);\n } else {\n const writer = dest.getWriter();\n writer.write(chunk).then(() => writer.releaseLock());\n }\n });\n\n this.on(\"end\", () => {\n if (dest instanceof UndiciStreamWrapper) {\n dest._end();\n } else {\n const writer = dest.getWriter();\n writer.close();\n }\n });\n\n this.on(\"error\", (error) => {\n if (dest instanceof UndiciStreamWrapper) {\n dest._error(error);\n } else {\n const writer = dest.getWriter();\n writer.abort(error);\n }\n });\n\n this._startReading();\n\n return dest;\n }\n\n public pipeTo(\n dest: UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat>,\n ): UndiciStreamWrapper<ReadFormat> | WritableStream<ReadFormat> {\n return this.pipe(dest);\n }\n\n public unpipe(dest: UndiciStreamWrapper<ReadFormat> | WritableStream): void {\n this.off(\"data\", (chunk) => {\n if (dest instanceof UndiciStreamWrapper) {\n dest._write(chunk);\n } else {\n const writer = dest.getWriter();\n writer.write(chunk).then(() => writer.releaseLock());\n }\n });\n\n this.off(\"end\", () => {\n if (dest instanceof UndiciStreamWrapper) {\n dest._end();\n } else {\n const writer = dest.getWriter();\n writer.close();\n }\n });\n\n this.off(\"error\", (error) => {\n if (dest instanceof UndiciStreamWrapper) {\n dest._error(error);\n } else {\n const writer = dest.getWriter();\n writer.abort(error);\n }\n });\n }\n\n public destroy(error?: Error): void {\n this.reader\n .cancel(error)\n .then(() => {\n this._emit(\"close\");\n })\n .catch((err) => {\n this._emit(\"error\", err);\n });\n }\n\n public pause(): void {\n this.paused = true;\n this._emit(\"pause\");\n }\n\n public resume(): void {\n if (this.paused) {\n this.paused = false;\n this._emit(\"resume\");\n if (this.resumeCallback) {\n this.resumeCallback();\n this.resumeCallback = null;\n }\n }\n }\n\n public get isPaused(): boolean {\n return this.paused;\n }\n\n public async read(): Promise<ReadFormat | undefined> {\n if (this.paused) {\n await new Promise((resolve) => {\n this.resumeCallback = resolve;\n });\n }\n const { done, value } = await this.reader.read();\n if (done) {\n return undefined;\n }\n return value;\n }\n\n public setEncoding(encoding: string): void {\n this.encoding = encoding;\n }\n\n public async text(): Promise<string> {\n const chunks: BlobPart[] = [];\n\n while (true) {\n const { done, value } = await this.reader.read();\n if (done) {\n break;\n }\n if (value) {\n chunks.push(value);\n }\n }\n\n const decoder = new TextDecoder(this.encoding || \"utf-8\");\n return decoder.decode(await new Blob(chunks).arrayBuffer());\n }\n\n public async json<T>(): Promise<T> {\n const text = await this.text();\n return JSON.parse(text);\n }\n\n private _write(chunk: ReadFormat): void {\n this._emit(\"data\", chunk);\n }\n\n private _end(): void {\n this._emit(\"end\");\n }\n\n private _error(error: any): void {\n this._emit(\"error\", error);\n }\n\n private _emit(event: string, data?: any): void {\n if (this.events[event]) {\n for (const callback of this.events[event] || []) {\n callback(data);\n }\n }\n }\n\n private async _startReading(): Promise<void> {\n try {\n this._emit(\"readable\");\n while (true) {\n if (this.paused) {\n await new Promise((resolve) => {\n this.resumeCallback = resolve;\n });\n }\n const { done, value } = await this.reader.read();\n if (done) {\n this._emit(\"end\");\n this._emit(\"close\");\n break;\n }\n if (value) {\n this._emit(\"data\", value);\n }\n }\n } catch (error) {\n this._emit(\"error\", error);\n }\n }\n\n [Symbol.asyncIterator](): AsyncIterableIterator<ReadFormat> {\n return {\n next: async () => {\n if (this.paused) {\n await new Promise((resolve) => {\n this.resumeCallback = resolve;\n });\n }\n const { done, value } = await this.reader.read();\n if (done) {\n return { done: true, value: undefined };\n }\n return { done: false, value };\n },\n [Symbol.asyncIterator]() {\n return this;\n },\n };\n }\n}\n"]}
|
package/dist/chunk-PZ5AY32C.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export { __export };
|
|
8
|
-
//# sourceMappingURL=chunk-PZ5AY32C.js.map
|
|
9
|
-
//# sourceMappingURL=chunk-PZ5AY32C.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-PZ5AY32C.js"}
|