opik 0.0.7 → 0.1.0

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.
@@ -1,208 +0,0 @@
1
- import "./chunk-MLKGABMK.js";
2
-
3
- // src/opik/rest_api/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts
4
- var UndiciStreamWrapper = class _UndiciStreamWrapper {
5
- readableStream;
6
- reader;
7
- events;
8
- paused;
9
- resumeCallback;
10
- encoding;
11
- constructor(readableStream) {
12
- this.readableStream = readableStream;
13
- this.reader = this.readableStream.getReader();
14
- this.events = {
15
- data: [],
16
- end: [],
17
- error: [],
18
- readable: [],
19
- close: [],
20
- pause: [],
21
- resume: []
22
- };
23
- this.paused = false;
24
- this.resumeCallback = null;
25
- this.encoding = null;
26
- }
27
- on(event, callback) {
28
- this.events[event]?.push(callback);
29
- }
30
- off(event, callback) {
31
- this.events[event] = this.events[event]?.filter((cb) => cb !== callback);
32
- }
33
- pipe(dest) {
34
- this.on("data", (chunk) => {
35
- if (dest instanceof _UndiciStreamWrapper) {
36
- dest._write(chunk);
37
- } else {
38
- const writer = dest.getWriter();
39
- writer.write(chunk).then(() => writer.releaseLock());
40
- }
41
- });
42
- this.on("end", () => {
43
- if (dest instanceof _UndiciStreamWrapper) {
44
- dest._end();
45
- } else {
46
- const writer = dest.getWriter();
47
- writer.close();
48
- }
49
- });
50
- this.on("error", (error) => {
51
- if (dest instanceof _UndiciStreamWrapper) {
52
- dest._error(error);
53
- } else {
54
- const writer = dest.getWriter();
55
- writer.abort(error);
56
- }
57
- });
58
- this._startReading();
59
- return dest;
60
- }
61
- pipeTo(dest) {
62
- return this.pipe(dest);
63
- }
64
- unpipe(dest) {
65
- this.off("data", (chunk) => {
66
- if (dest instanceof _UndiciStreamWrapper) {
67
- dest._write(chunk);
68
- } else {
69
- const writer = dest.getWriter();
70
- writer.write(chunk).then(() => writer.releaseLock());
71
- }
72
- });
73
- this.off("end", () => {
74
- if (dest instanceof _UndiciStreamWrapper) {
75
- dest._end();
76
- } else {
77
- const writer = dest.getWriter();
78
- writer.close();
79
- }
80
- });
81
- this.off("error", (error) => {
82
- if (dest instanceof _UndiciStreamWrapper) {
83
- dest._error(error);
84
- } else {
85
- const writer = dest.getWriter();
86
- writer.abort(error);
87
- }
88
- });
89
- }
90
- destroy(error) {
91
- this.reader.cancel(error).then(() => {
92
- this._emit("close");
93
- }).catch((err) => {
94
- this._emit("error", err);
95
- });
96
- }
97
- pause() {
98
- this.paused = true;
99
- this._emit("pause");
100
- }
101
- resume() {
102
- if (this.paused) {
103
- this.paused = false;
104
- this._emit("resume");
105
- if (this.resumeCallback) {
106
- this.resumeCallback();
107
- this.resumeCallback = null;
108
- }
109
- }
110
- }
111
- get isPaused() {
112
- return this.paused;
113
- }
114
- async read() {
115
- if (this.paused) {
116
- await new Promise((resolve) => {
117
- this.resumeCallback = resolve;
118
- });
119
- }
120
- const { done, value } = await this.reader.read();
121
- if (done) {
122
- return void 0;
123
- }
124
- return value;
125
- }
126
- setEncoding(encoding) {
127
- this.encoding = encoding;
128
- }
129
- async text() {
130
- const chunks = [];
131
- while (true) {
132
- const { done, value } = await this.reader.read();
133
- if (done) {
134
- break;
135
- }
136
- if (value) {
137
- chunks.push(value);
138
- }
139
- }
140
- const decoder = new TextDecoder(this.encoding || "utf-8");
141
- return decoder.decode(await new Blob(chunks).arrayBuffer());
142
- }
143
- async json() {
144
- const text = await this.text();
145
- return JSON.parse(text);
146
- }
147
- _write(chunk) {
148
- this._emit("data", chunk);
149
- }
150
- _end() {
151
- this._emit("end");
152
- }
153
- _error(error) {
154
- this._emit("error", error);
155
- }
156
- _emit(event, data) {
157
- if (this.events[event]) {
158
- for (const callback of this.events[event] || []) {
159
- callback(data);
160
- }
161
- }
162
- }
163
- async _startReading() {
164
- try {
165
- this._emit("readable");
166
- while (true) {
167
- if (this.paused) {
168
- await new Promise((resolve) => {
169
- this.resumeCallback = resolve;
170
- });
171
- }
172
- const { done, value } = await this.reader.read();
173
- if (done) {
174
- this._emit("end");
175
- this._emit("close");
176
- break;
177
- }
178
- if (value) {
179
- this._emit("data", value);
180
- }
181
- }
182
- } catch (error) {
183
- this._emit("error", error);
184
- }
185
- }
186
- [Symbol.asyncIterator]() {
187
- return {
188
- next: async () => {
189
- if (this.paused) {
190
- await new Promise((resolve) => {
191
- this.resumeCallback = resolve;
192
- });
193
- }
194
- const { done, value } = await this.reader.read();
195
- if (done) {
196
- return { done: true, value: void 0 };
197
- }
198
- return { done: false, value };
199
- },
200
- [Symbol.asyncIterator]() {
201
- return this;
202
- }
203
- };
204
- }
205
- };
206
- export {
207
- UndiciStreamWrapper
208
- };