@vobs/http 1.2.1 → 1.3.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.
- package/dist/debug.cjs +33 -8
- package/dist/debug.cjs.map +1 -1
- package/dist/debug.js +6 -3
- package/dist/debug.js.map +1 -1
- package/dist/index.cjs +86 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -150
- package/dist/index.js.map +1 -1
- package/dist/stream.cjs +31 -6
- package/dist/stream.cjs.map +1 -1
- package/dist/stream.js +6 -3
- package/dist/stream.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,145 +1,9 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
3
|
|
|
6
|
-
// packages/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return activeDebugHooks !== null;
|
|
10
|
-
}
|
|
11
|
-
__name(hasDebugHooks, "hasDebugHooks");
|
|
12
|
-
function invokeDebug(name, ...args) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
__name(invokeDebug, "invokeDebug");
|
|
16
|
-
|
|
17
|
-
// packages/reactivity/src/scheduler.ts
|
|
18
|
-
var _Scheduler = class _Scheduler {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.dirtyEffects = /* @__PURE__ */ new Set();
|
|
21
|
-
this.lowPriorityEffects = /* @__PURE__ */ new Set();
|
|
22
|
-
// flush 不可重入(flushing 标志保证),缓冲数组可在轮次间安全复用,避免每轮分配。
|
|
23
|
-
this.normalBuffer = [];
|
|
24
|
-
this.lowBuffer = [];
|
|
25
|
-
this.flushing = false;
|
|
26
|
-
this.scheduled = false;
|
|
27
|
-
this.batchDepth = 0;
|
|
28
|
-
}
|
|
29
|
-
schedule(effect2) {
|
|
30
|
-
if (effect2.disposed) return;
|
|
31
|
-
this.dirtyEffects.add(effect2);
|
|
32
|
-
this.lowPriorityEffects.delete(effect2);
|
|
33
|
-
this.ensureScheduled();
|
|
34
|
-
}
|
|
35
|
-
/** Queue an effect behind normal updates while preserving deterministic order. */
|
|
36
|
-
scheduleLow(effect2) {
|
|
37
|
-
if (effect2.disposed) return;
|
|
38
|
-
if (!this.dirtyEffects.has(effect2)) this.lowPriorityEffects.add(effect2);
|
|
39
|
-
this.ensureScheduled();
|
|
40
|
-
}
|
|
41
|
-
ensureScheduled() {
|
|
42
|
-
if (this.batchDepth === 0 && !this.flushing && !this.scheduled) {
|
|
43
|
-
this.scheduled = true;
|
|
44
|
-
queueMicrotask(() => {
|
|
45
|
-
this.scheduled = false;
|
|
46
|
-
this.flush();
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
remove(effect2) {
|
|
51
|
-
this.dirtyEffects.delete(effect2);
|
|
52
|
-
this.lowPriorityEffects.delete(effect2);
|
|
53
|
-
}
|
|
54
|
-
batch(fn) {
|
|
55
|
-
this.batchDepth++;
|
|
56
|
-
try {
|
|
57
|
-
return fn();
|
|
58
|
-
} finally {
|
|
59
|
-
this.batchDepth--;
|
|
60
|
-
if (this.batchDepth === 0) this.flush();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
flush() {
|
|
64
|
-
if (this.flushing || this.batchDepth > 0) return;
|
|
65
|
-
this.flushing = true;
|
|
66
|
-
let rounds = 0;
|
|
67
|
-
let firstError;
|
|
68
|
-
let hasError = false;
|
|
69
|
-
try {
|
|
70
|
-
while (this.dirtyEffects.size > 0 || this.lowPriorityEffects.size > 0) {
|
|
71
|
-
if (++rounds > 100) {
|
|
72
|
-
this.dirtyEffects.clear();
|
|
73
|
-
this.lowPriorityEffects.clear();
|
|
74
|
-
throw new Error("Vobs: \u54CD\u5E94\u5F0F\u66F4\u65B0\u8D85\u8FC7 100 \u8F6E\uFF0C\u53EF\u80FD\u5B58\u5728\u5FAA\u73AF\u4F9D\u8D56");
|
|
75
|
-
}
|
|
76
|
-
this.collectRunnable(this.dirtyEffects, this.normalBuffer);
|
|
77
|
-
this.collectRunnable(this.lowPriorityEffects, this.lowBuffer);
|
|
78
|
-
sortEffects(this.normalBuffer);
|
|
79
|
-
sortEffects(this.lowBuffer);
|
|
80
|
-
for (const effect2 of this.normalBuffer) {
|
|
81
|
-
try {
|
|
82
|
-
effect2.run();
|
|
83
|
-
} catch (error) {
|
|
84
|
-
if (!hasError) {
|
|
85
|
-
firstError = error;
|
|
86
|
-
hasError = true;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
for (const effect2 of this.lowBuffer) {
|
|
91
|
-
try {
|
|
92
|
-
effect2.run();
|
|
93
|
-
} catch (error) {
|
|
94
|
-
if (!hasError) {
|
|
95
|
-
firstError = error;
|
|
96
|
-
hasError = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
this.normalBuffer.length = 0;
|
|
101
|
-
this.lowBuffer.length = 0;
|
|
102
|
-
}
|
|
103
|
-
} finally {
|
|
104
|
-
this.normalBuffer.length = 0;
|
|
105
|
-
this.lowBuffer.length = 0;
|
|
106
|
-
this.flushing = false;
|
|
107
|
-
}
|
|
108
|
-
if (hasError) throw firstError;
|
|
109
|
-
}
|
|
110
|
-
/** 收集未 disposed 的 effect 并清空源集合;run() 期间新调度的 effect 留给下一轮。 */
|
|
111
|
-
collectRunnable(source, target) {
|
|
112
|
-
for (const effect2 of source) {
|
|
113
|
-
if (!effect2.disposed) target.push(effect2);
|
|
114
|
-
}
|
|
115
|
-
source.clear();
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
__name(_Scheduler, "Scheduler");
|
|
119
|
-
function sortEffects(effects) {
|
|
120
|
-
if (effects.length > 1) {
|
|
121
|
-
effects.sort((a, b) => b.depth - a.depth || a.order - b.order);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
__name(sortEffects, "sortEffects");
|
|
125
|
-
|
|
126
|
-
// packages/runtime/src/debug.ts
|
|
127
|
-
var activeRuntimeDebugContext = null;
|
|
128
|
-
function getRuntimeDebugContext() {
|
|
129
|
-
return activeRuntimeDebugContext;
|
|
130
|
-
}
|
|
131
|
-
__name(getRuntimeDebugContext, "getRuntimeDebugContext");
|
|
132
|
-
|
|
133
|
-
// packages/runtime/src/hmr.ts
|
|
134
|
-
var globalTarget = globalThis;
|
|
135
|
-
var hmrGlobal = globalTarget.__VOBS_HMR__ ?? { modules: /* @__PURE__ */ new Map() };
|
|
136
|
-
globalTarget.__VOBS_HMR__ = hmrGlobal;
|
|
137
|
-
|
|
138
|
-
// packages/vobs/src/app.ts
|
|
139
|
-
function createInjectionKey(description) {
|
|
140
|
-
return Symbol(description);
|
|
141
|
-
}
|
|
142
|
-
__name(createInjectionKey, "createInjectionKey");
|
|
4
|
+
// packages/http/src/index.ts
|
|
5
|
+
import { createInjectionKey } from "@vobs/vobs";
|
|
6
|
+
import axios from "axios";
|
|
143
7
|
|
|
144
8
|
// packages/http/src/stream.ts
|
|
145
9
|
function createSSE(url, options = {}) {
|
|
@@ -164,7 +28,7 @@ function createWebSocket(url, options = {}) {
|
|
|
164
28
|
}
|
|
165
29
|
const listeners = /* @__PURE__ */ new Map();
|
|
166
30
|
let socket = null;
|
|
167
|
-
let
|
|
31
|
+
let state = "idle";
|
|
168
32
|
let manuallyClosed = false;
|
|
169
33
|
let reconnectTimer;
|
|
170
34
|
const client = {
|
|
@@ -172,18 +36,18 @@ function createWebSocket(url, options = {}) {
|
|
|
172
36
|
return socket;
|
|
173
37
|
},
|
|
174
38
|
get state() {
|
|
175
|
-
return
|
|
39
|
+
return state;
|
|
176
40
|
},
|
|
177
41
|
connect,
|
|
178
42
|
send(data) {
|
|
179
|
-
if (!socket ||
|
|
43
|
+
if (!socket || state !== "open") throw new Error("HTTP: WebSocket \u5C1A\u672A\u8FDE\u63A5");
|
|
180
44
|
socket.send(data);
|
|
181
45
|
},
|
|
182
46
|
close(code, reason) {
|
|
183
47
|
manuallyClosed = true;
|
|
184
48
|
if (reconnectTimer !== void 0) clearTimeout(reconnectTimer);
|
|
185
49
|
socket?.close(code, reason);
|
|
186
|
-
if (!socket)
|
|
50
|
+
if (!socket) state = "closed";
|
|
187
51
|
},
|
|
188
52
|
on(event, listener) {
|
|
189
53
|
let eventListeners = listeners.get(event);
|
|
@@ -198,19 +62,19 @@ function createWebSocket(url, options = {}) {
|
|
|
198
62
|
connect();
|
|
199
63
|
return client;
|
|
200
64
|
function connect() {
|
|
201
|
-
if (
|
|
65
|
+
if (state === "connecting" || state === "open") return;
|
|
202
66
|
manuallyClosed = false;
|
|
203
|
-
|
|
67
|
+
state = "connecting";
|
|
204
68
|
const protocols = options.protocols === void 0 ? void 0 : typeof options.protocols === "string" ? options.protocols : [...options.protocols];
|
|
205
69
|
socket = new WebSocketImpl(url, protocols);
|
|
206
70
|
socket.addEventListener("open", (event) => {
|
|
207
|
-
|
|
71
|
+
state = "open";
|
|
208
72
|
notify("open", event);
|
|
209
73
|
});
|
|
210
74
|
socket.addEventListener("message", (event) => notify("message", event));
|
|
211
75
|
socket.addEventListener("error", (event) => notify("error", event));
|
|
212
76
|
socket.addEventListener("close", (event) => {
|
|
213
|
-
|
|
77
|
+
state = "closed";
|
|
214
78
|
socket = null;
|
|
215
79
|
notify("close", event);
|
|
216
80
|
if (options.autoReconnect && !manuallyClosed) {
|
|
@@ -221,9 +85,11 @@ function createWebSocket(url, options = {}) {
|
|
|
221
85
|
}
|
|
222
86
|
});
|
|
223
87
|
}
|
|
88
|
+
__name(connect, "connect");
|
|
224
89
|
function notify(event, value) {
|
|
225
90
|
for (const listener of [...listeners.get(event) ?? []]) listener(value);
|
|
226
91
|
}
|
|
92
|
+
__name(notify, "notify");
|
|
227
93
|
}
|
|
228
94
|
__name(createWebSocket, "createWebSocket");
|
|
229
95
|
|
|
@@ -260,6 +126,7 @@ function emitHTTPDebug(event) {
|
|
|
260
126
|
__name(emitHTTPDebug, "emitHTTPDebug");
|
|
261
127
|
|
|
262
128
|
// packages/http/src/index.ts
|
|
129
|
+
import { getRuntimeDebugContext } from "@vobs/runtime";
|
|
263
130
|
var PROGRESS_HANDLED = Symbol("vobs.http.progress-handled");
|
|
264
131
|
var nextHTTPDebugId = 1;
|
|
265
132
|
function toResourceFetcher(request) {
|
|
@@ -561,6 +428,7 @@ function createHTTPClient(options = {}) {
|
|
|
561
428
|
inputSignal?.removeEventListener("abort", abortFromInput);
|
|
562
429
|
}
|
|
563
430
|
}
|
|
431
|
+
__name(executeWithRetry, "executeWithRetry");
|
|
564
432
|
}
|
|
565
433
|
__name(createHTTPClient, "createHTTPClient");
|
|
566
434
|
function debugHeaders(headers) {
|
|
@@ -916,7 +784,23 @@ function toProgress(loaded, total) {
|
|
|
916
784
|
};
|
|
917
785
|
}
|
|
918
786
|
__name(toProgress, "toProgress");
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
787
|
+
export {
|
|
788
|
+
HTTPError,
|
|
789
|
+
HTTP_KEY,
|
|
790
|
+
TimeoutError,
|
|
791
|
+
createAxiosAdapter,
|
|
792
|
+
createConcurrencyLimiter,
|
|
793
|
+
createFetchAdapter,
|
|
794
|
+
createHTTPClient,
|
|
795
|
+
createMockAdapter,
|
|
796
|
+
createSSE,
|
|
797
|
+
createWebSocket,
|
|
798
|
+
createXHRAdapter,
|
|
799
|
+
emitHTTPDebug,
|
|
800
|
+
getHTTPDebugHooks,
|
|
801
|
+
httpPlugin,
|
|
802
|
+
setHTTPDebugHooks,
|
|
803
|
+
subscribeHTTPDebug,
|
|
804
|
+
toResourceFetcher
|
|
805
|
+
};
|
|
922
806
|
//# sourceMappingURL=index.js.map
|