@camstack/core 0.1.1 → 0.1.2
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/builtins/local-backup/index.d.mts +42 -0
- package/dist/builtins/local-backup/index.d.ts +42 -0
- package/dist/builtins/local-backup/index.js +188 -0
- package/dist/builtins/local-backup/index.js.map +1 -0
- package/dist/builtins/local-backup/index.mjs +11 -0
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.d.mts +2 -0
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.d.ts +2 -0
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +210 -0
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.js.map +1 -0
- package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +10 -0
- package/dist/builtins/sqlite-storage/index.d.mts +4 -0
- package/dist/builtins/sqlite-storage/index.d.ts +4 -0
- package/dist/builtins/sqlite-storage/index.js +1025 -0
- package/dist/builtins/sqlite-storage/index.js.map +1 -0
- package/dist/builtins/sqlite-storage/index.mjs +31 -0
- package/dist/builtins/sqlite-storage/index.mjs.map +1 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.d.mts +2 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.d.ts +2 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +317 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.js.map +1 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +10 -0
- package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs.map +1 -0
- package/dist/builtins/winston-logging/index.d.mts +30 -0
- package/dist/builtins/winston-logging/index.d.ts +30 -0
- package/dist/builtins/winston-logging/index.js +185 -0
- package/dist/builtins/winston-logging/index.js.map +1 -0
- package/dist/builtins/winston-logging/index.mjs +11 -0
- package/dist/builtins/winston-logging/index.mjs.map +1 -0
- package/dist/chunk-LQFPAEQF.mjs +147 -0
- package/dist/chunk-LQFPAEQF.mjs.map +1 -0
- package/dist/{chunk-LZOMFHX3.mjs → chunk-QEMJH3KY.mjs} +11 -1
- package/dist/chunk-QEMJH3KY.mjs.map +1 -0
- package/dist/chunk-R3DIIBBX.mjs +532 -0
- package/dist/chunk-R3DIIBBX.mjs.map +1 -0
- package/dist/chunk-SO4LROOT.mjs +150 -0
- package/dist/chunk-SO4LROOT.mjs.map +1 -0
- package/dist/chunk-SPA4JBKN.mjs +175 -0
- package/dist/chunk-SPA4JBKN.mjs.map +1 -0
- package/dist/chunk-YXNXYYHL.mjs +282 -0
- package/dist/chunk-YXNXYYHL.mjs.map +1 -0
- package/dist/dist-N7SR63RN.mjs +3515 -0
- package/dist/dist-N7SR63RN.mjs.map +1 -0
- package/dist/filesystem-storage.addon-C42r589X.d.mts +57 -0
- package/dist/filesystem-storage.addon-C42r589X.d.ts +57 -0
- package/dist/index.d.mts +281 -849
- package/dist/index.d.ts +281 -849
- package/dist/index.js +8351 -1942
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4086 -2164
- package/dist/index.mjs.map +1 -1
- package/dist/onnxruntime_binding-6Q6HXASN.node +0 -0
- package/dist/onnxruntime_binding-EKZT2NRK.node +0 -0
- package/dist/onnxruntime_binding-P6S7V3CI.node +0 -0
- package/dist/onnxruntime_binding-PJNNIIUO.node +0 -0
- package/dist/onnxruntime_binding-UN6SPTQK.node +0 -0
- package/dist/sql-schema-CKz78rId.d.mts +97 -0
- package/dist/sql-schema-CKz78rId.d.ts +97 -0
- package/dist/sqlite-settings.addon-DigoKwpZ.d.mts +70 -0
- package/dist/sqlite-settings.addon-DigoKwpZ.d.ts +70 -0
- package/dist/{storage-location-manager-F4YZMHGM.mjs → storage-location-manager-UQRGHTCA.mjs} +2 -2
- package/dist/storage-location-manager-UQRGHTCA.mjs.map +1 -0
- package/dist/{wrapper-NTBY5HOA.mjs → wrapper-Y55ADNM5.mjs} +2 -2
- package/package.json +64 -12
- /package/dist/{chunk-LZOMFHX3.mjs.map → builtins/local-backup/index.mjs.map} +0 -0
- /package/dist/{storage-location-manager-F4YZMHGM.mjs.map → builtins/sqlite-storage/filesystem-storage.addon.mjs.map} +0 -0
- /package/dist/{wrapper-NTBY5HOA.mjs.map → wrapper-Y55ADNM5.mjs.map} +0 -0
|
@@ -0,0 +1,3515 @@
|
|
|
1
|
+
import "./chunk-QEMJH3KY.mjs";
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/@trpc/client/dist/objectSpread2-BvkFp-_Y.mjs
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __commonJS = (cb, mod) => function() {
|
|
11
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
28
|
+
function _typeof$2(o) {
|
|
29
|
+
"@babel/helpers - typeof";
|
|
30
|
+
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
31
|
+
return typeof o$1;
|
|
32
|
+
} : function(o$1) {
|
|
33
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
34
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
35
|
+
}
|
|
36
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
37
|
+
} });
|
|
38
|
+
var require_toPrimitive = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
39
|
+
var _typeof$1 = require_typeof()["default"];
|
|
40
|
+
function toPrimitive$1(t, r) {
|
|
41
|
+
if ("object" != _typeof$1(t) || !t) return t;
|
|
42
|
+
var e = t[Symbol.toPrimitive];
|
|
43
|
+
if (void 0 !== e) {
|
|
44
|
+
var i = e.call(t, r || "default");
|
|
45
|
+
if ("object" != _typeof$1(i)) return i;
|
|
46
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
47
|
+
}
|
|
48
|
+
return ("string" === r ? String : Number)(t);
|
|
49
|
+
}
|
|
50
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
51
|
+
} });
|
|
52
|
+
var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
53
|
+
var _typeof = require_typeof()["default"];
|
|
54
|
+
var toPrimitive = require_toPrimitive();
|
|
55
|
+
function toPropertyKey$1(t) {
|
|
56
|
+
var i = toPrimitive(t, "string");
|
|
57
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
58
|
+
}
|
|
59
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
60
|
+
} });
|
|
61
|
+
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
62
|
+
var toPropertyKey = require_toPropertyKey();
|
|
63
|
+
function _defineProperty(e, r, t) {
|
|
64
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
65
|
+
value: t,
|
|
66
|
+
enumerable: true,
|
|
67
|
+
configurable: true,
|
|
68
|
+
writable: true
|
|
69
|
+
}) : e[r] = t, e;
|
|
70
|
+
}
|
|
71
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
72
|
+
} });
|
|
73
|
+
var require_objectSpread2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
74
|
+
var defineProperty = require_defineProperty();
|
|
75
|
+
function ownKeys(e, r) {
|
|
76
|
+
var t = Object.keys(e);
|
|
77
|
+
if (Object.getOwnPropertySymbols) {
|
|
78
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
79
|
+
r && (o = o.filter(function(r$1) {
|
|
80
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
81
|
+
})), t.push.apply(t, o);
|
|
82
|
+
}
|
|
83
|
+
return t;
|
|
84
|
+
}
|
|
85
|
+
function _objectSpread2(e) {
|
|
86
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
87
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
88
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
89
|
+
defineProperty(e, r$1, t[r$1]);
|
|
90
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
91
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return e;
|
|
95
|
+
}
|
|
96
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
97
|
+
} });
|
|
98
|
+
|
|
99
|
+
// ../../node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
|
|
100
|
+
function observable(subscribe) {
|
|
101
|
+
const self = {
|
|
102
|
+
subscribe(observer) {
|
|
103
|
+
let teardownRef = null;
|
|
104
|
+
let isDone = false;
|
|
105
|
+
let unsubscribed = false;
|
|
106
|
+
let teardownImmediately = false;
|
|
107
|
+
function unsubscribe() {
|
|
108
|
+
if (teardownRef === null) {
|
|
109
|
+
teardownImmediately = true;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (unsubscribed) return;
|
|
113
|
+
unsubscribed = true;
|
|
114
|
+
if (typeof teardownRef === "function") teardownRef();
|
|
115
|
+
else if (teardownRef) teardownRef.unsubscribe();
|
|
116
|
+
}
|
|
117
|
+
teardownRef = subscribe({
|
|
118
|
+
next(value) {
|
|
119
|
+
var _observer$next;
|
|
120
|
+
if (isDone) return;
|
|
121
|
+
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
122
|
+
},
|
|
123
|
+
error(err) {
|
|
124
|
+
var _observer$error;
|
|
125
|
+
if (isDone) return;
|
|
126
|
+
isDone = true;
|
|
127
|
+
(_observer$error = observer.error) === null || _observer$error === void 0 || _observer$error.call(observer, err);
|
|
128
|
+
unsubscribe();
|
|
129
|
+
},
|
|
130
|
+
complete() {
|
|
131
|
+
var _observer$complete;
|
|
132
|
+
if (isDone) return;
|
|
133
|
+
isDone = true;
|
|
134
|
+
(_observer$complete = observer.complete) === null || _observer$complete === void 0 || _observer$complete.call(observer);
|
|
135
|
+
unsubscribe();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (teardownImmediately) unsubscribe();
|
|
139
|
+
return { unsubscribe };
|
|
140
|
+
},
|
|
141
|
+
pipe(...operations) {
|
|
142
|
+
return operations.reduce(pipeReducer, self);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return self;
|
|
146
|
+
}
|
|
147
|
+
function pipeReducer(prev, fn) {
|
|
148
|
+
return fn(prev);
|
|
149
|
+
}
|
|
150
|
+
function observableToPromise(observable$1) {
|
|
151
|
+
const ac = new AbortController();
|
|
152
|
+
const promise = new Promise((resolve, reject) => {
|
|
153
|
+
let isDone = false;
|
|
154
|
+
function onDone() {
|
|
155
|
+
if (isDone) return;
|
|
156
|
+
isDone = true;
|
|
157
|
+
obs$.unsubscribe();
|
|
158
|
+
}
|
|
159
|
+
ac.signal.addEventListener("abort", () => {
|
|
160
|
+
reject(ac.signal.reason);
|
|
161
|
+
});
|
|
162
|
+
const obs$ = observable$1.subscribe({
|
|
163
|
+
next(data) {
|
|
164
|
+
isDone = true;
|
|
165
|
+
resolve(data);
|
|
166
|
+
onDone();
|
|
167
|
+
},
|
|
168
|
+
error(data) {
|
|
169
|
+
reject(data);
|
|
170
|
+
},
|
|
171
|
+
complete() {
|
|
172
|
+
ac.abort();
|
|
173
|
+
onDone();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
return promise;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ../../node_modules/@trpc/server/dist/observable-CUiPknO-.mjs
|
|
181
|
+
function share(_opts) {
|
|
182
|
+
return (source) => {
|
|
183
|
+
let refCount = 0;
|
|
184
|
+
let subscription = null;
|
|
185
|
+
const observers = [];
|
|
186
|
+
function startIfNeeded() {
|
|
187
|
+
if (subscription) return;
|
|
188
|
+
subscription = source.subscribe({
|
|
189
|
+
next(value) {
|
|
190
|
+
for (const observer of observers) {
|
|
191
|
+
var _observer$next;
|
|
192
|
+
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
error(error) {
|
|
196
|
+
for (const observer of observers) {
|
|
197
|
+
var _observer$error;
|
|
198
|
+
(_observer$error = observer.error) === null || _observer$error === void 0 || _observer$error.call(observer, error);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
complete() {
|
|
202
|
+
for (const observer of observers) {
|
|
203
|
+
var _observer$complete;
|
|
204
|
+
(_observer$complete = observer.complete) === null || _observer$complete === void 0 || _observer$complete.call(observer);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function resetIfNeeded() {
|
|
210
|
+
if (refCount === 0 && subscription) {
|
|
211
|
+
const _sub = subscription;
|
|
212
|
+
subscription = null;
|
|
213
|
+
_sub.unsubscribe();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return observable((subscriber) => {
|
|
217
|
+
refCount++;
|
|
218
|
+
observers.push(subscriber);
|
|
219
|
+
startIfNeeded();
|
|
220
|
+
return { unsubscribe() {
|
|
221
|
+
refCount--;
|
|
222
|
+
resetIfNeeded();
|
|
223
|
+
const index = observers.findIndex((v) => v === subscriber);
|
|
224
|
+
if (index > -1) observers.splice(index, 1);
|
|
225
|
+
} };
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function tap(observer) {
|
|
230
|
+
return (source) => {
|
|
231
|
+
return observable((destination) => {
|
|
232
|
+
return source.subscribe({
|
|
233
|
+
next(value) {
|
|
234
|
+
var _observer$next2;
|
|
235
|
+
(_observer$next2 = observer.next) === null || _observer$next2 === void 0 || _observer$next2.call(observer, value);
|
|
236
|
+
destination.next(value);
|
|
237
|
+
},
|
|
238
|
+
error(error) {
|
|
239
|
+
var _observer$error2;
|
|
240
|
+
(_observer$error2 = observer.error) === null || _observer$error2 === void 0 || _observer$error2.call(observer, error);
|
|
241
|
+
destination.error(error);
|
|
242
|
+
},
|
|
243
|
+
complete() {
|
|
244
|
+
var _observer$complete2;
|
|
245
|
+
(_observer$complete2 = observer.complete) === null || _observer$complete2 === void 0 || _observer$complete2.call(observer);
|
|
246
|
+
destination.complete();
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function behaviorSubject(initialValue) {
|
|
253
|
+
let value = initialValue;
|
|
254
|
+
const observerList = [];
|
|
255
|
+
const addObserver = (observer) => {
|
|
256
|
+
if (value !== void 0) observer.next(value);
|
|
257
|
+
observerList.push(observer);
|
|
258
|
+
};
|
|
259
|
+
const removeObserver = (observer) => {
|
|
260
|
+
observerList.splice(observerList.indexOf(observer), 1);
|
|
261
|
+
};
|
|
262
|
+
const obs = observable((observer) => {
|
|
263
|
+
addObserver(observer);
|
|
264
|
+
return () => {
|
|
265
|
+
removeObserver(observer);
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
obs.next = (nextValue) => {
|
|
269
|
+
if (value === nextValue) return;
|
|
270
|
+
value = nextValue;
|
|
271
|
+
for (const observer of observerList) observer.next(nextValue);
|
|
272
|
+
};
|
|
273
|
+
obs.get = () => value;
|
|
274
|
+
return obs;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ../../node_modules/@trpc/client/dist/splitLink-B7Cuf2c_.mjs
|
|
278
|
+
function createChain(opts) {
|
|
279
|
+
return observable((observer) => {
|
|
280
|
+
function execute(index = 0, op = opts.op) {
|
|
281
|
+
const next = opts.links[index];
|
|
282
|
+
if (!next) throw new Error("No more links to execute - did you forget to add an ending link?");
|
|
283
|
+
const subscription = next({
|
|
284
|
+
op,
|
|
285
|
+
next(nextOp) {
|
|
286
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
287
|
+
return nextObserver;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return subscription;
|
|
291
|
+
}
|
|
292
|
+
const obs$ = execute();
|
|
293
|
+
return obs$.subscribe(observer);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function asArray(value) {
|
|
297
|
+
return Array.isArray(value) ? value : [value];
|
|
298
|
+
}
|
|
299
|
+
function splitLink(opts) {
|
|
300
|
+
return (runtime) => {
|
|
301
|
+
const yes = asArray(opts.true).map((link) => link(runtime));
|
|
302
|
+
const no = asArray(opts.false).map((link) => link(runtime));
|
|
303
|
+
return (props) => {
|
|
304
|
+
return observable((observer) => {
|
|
305
|
+
const links = opts.condition(props.op) ? yes : no;
|
|
306
|
+
return createChain({
|
|
307
|
+
op: props.op,
|
|
308
|
+
links
|
|
309
|
+
}).subscribe(observer);
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ../../node_modules/@trpc/server/dist/codes-DagpWZLc.mjs
|
|
316
|
+
function isObject(value) {
|
|
317
|
+
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
318
|
+
}
|
|
319
|
+
function emptyObject() {
|
|
320
|
+
return /* @__PURE__ */ Object.create(null);
|
|
321
|
+
}
|
|
322
|
+
var asyncIteratorsSupported = typeof Symbol === "function" && !!Symbol.asyncIterator;
|
|
323
|
+
function isAsyncIterable(value) {
|
|
324
|
+
return asyncIteratorsSupported && isObject(value) && Symbol.asyncIterator in value;
|
|
325
|
+
}
|
|
326
|
+
var run = (fn) => fn();
|
|
327
|
+
function sleep(ms = 0) {
|
|
328
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
329
|
+
}
|
|
330
|
+
var TRPC_ERROR_CODES_BY_KEY = {
|
|
331
|
+
PARSE_ERROR: -32700,
|
|
332
|
+
BAD_REQUEST: -32600,
|
|
333
|
+
INTERNAL_SERVER_ERROR: -32603,
|
|
334
|
+
NOT_IMPLEMENTED: -32603,
|
|
335
|
+
BAD_GATEWAY: -32603,
|
|
336
|
+
SERVICE_UNAVAILABLE: -32603,
|
|
337
|
+
GATEWAY_TIMEOUT: -32603,
|
|
338
|
+
UNAUTHORIZED: -32001,
|
|
339
|
+
PAYMENT_REQUIRED: -32002,
|
|
340
|
+
FORBIDDEN: -32003,
|
|
341
|
+
NOT_FOUND: -32004,
|
|
342
|
+
METHOD_NOT_SUPPORTED: -32005,
|
|
343
|
+
TIMEOUT: -32008,
|
|
344
|
+
CONFLICT: -32009,
|
|
345
|
+
PRECONDITION_FAILED: -32012,
|
|
346
|
+
PAYLOAD_TOO_LARGE: -32013,
|
|
347
|
+
UNSUPPORTED_MEDIA_TYPE: -32015,
|
|
348
|
+
UNPROCESSABLE_CONTENT: -32022,
|
|
349
|
+
PRECONDITION_REQUIRED: -32028,
|
|
350
|
+
TOO_MANY_REQUESTS: -32029,
|
|
351
|
+
CLIENT_CLOSED_REQUEST: -32099
|
|
352
|
+
};
|
|
353
|
+
var retryableRpcCodes = [
|
|
354
|
+
TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
|
|
355
|
+
TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
|
|
356
|
+
TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
|
|
357
|
+
TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
|
|
358
|
+
];
|
|
359
|
+
|
|
360
|
+
// ../../node_modules/@trpc/server/dist/getErrorShape-vC8mUXJD.mjs
|
|
361
|
+
var __create2 = Object.create;
|
|
362
|
+
var __defProp2 = Object.defineProperty;
|
|
363
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
364
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
365
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
366
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
367
|
+
var __commonJS2 = (cb, mod) => function() {
|
|
368
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
369
|
+
};
|
|
370
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
371
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames2(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
372
|
+
key = keys[i];
|
|
373
|
+
if (!__hasOwnProp2.call(to, key) && key !== except) __defProp2(to, key, {
|
|
374
|
+
get: ((k) => from[k]).bind(null, key),
|
|
375
|
+
enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return to;
|
|
379
|
+
};
|
|
380
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", {
|
|
381
|
+
value: mod,
|
|
382
|
+
enumerable: true
|
|
383
|
+
}) : target, mod));
|
|
384
|
+
var noop = () => {
|
|
385
|
+
};
|
|
386
|
+
var freezeIfAvailable = (obj) => {
|
|
387
|
+
if (Object.freeze) Object.freeze(obj);
|
|
388
|
+
};
|
|
389
|
+
function createInnerProxy(callback, path, memo) {
|
|
390
|
+
var _memo$cacheKey;
|
|
391
|
+
const cacheKey = path.join(".");
|
|
392
|
+
(_memo$cacheKey = memo[cacheKey]) !== null && _memo$cacheKey !== void 0 || (memo[cacheKey] = new Proxy(noop, {
|
|
393
|
+
get(_obj, key) {
|
|
394
|
+
if (typeof key !== "string" || key === "then") return void 0;
|
|
395
|
+
return createInnerProxy(callback, [...path, key], memo);
|
|
396
|
+
},
|
|
397
|
+
apply(_1, _2, args) {
|
|
398
|
+
const lastOfPath = path[path.length - 1];
|
|
399
|
+
let opts = {
|
|
400
|
+
args,
|
|
401
|
+
path
|
|
402
|
+
};
|
|
403
|
+
if (lastOfPath === "call") opts = {
|
|
404
|
+
args: args.length >= 2 ? [args[1]] : [],
|
|
405
|
+
path: path.slice(0, -1)
|
|
406
|
+
};
|
|
407
|
+
else if (lastOfPath === "apply") opts = {
|
|
408
|
+
args: args.length >= 2 ? args[1] : [],
|
|
409
|
+
path: path.slice(0, -1)
|
|
410
|
+
};
|
|
411
|
+
freezeIfAvailable(opts.args);
|
|
412
|
+
freezeIfAvailable(opts.path);
|
|
413
|
+
return callback(opts);
|
|
414
|
+
}
|
|
415
|
+
}));
|
|
416
|
+
return memo[cacheKey];
|
|
417
|
+
}
|
|
418
|
+
var createRecursiveProxy = (callback) => createInnerProxy(callback, [], emptyObject());
|
|
419
|
+
var createFlatProxy = (callback) => {
|
|
420
|
+
return new Proxy(noop, { get(_obj, name) {
|
|
421
|
+
if (name === "then") return void 0;
|
|
422
|
+
return callback(name);
|
|
423
|
+
} });
|
|
424
|
+
};
|
|
425
|
+
var JSONRPC2_TO_HTTP_CODE = {
|
|
426
|
+
PARSE_ERROR: 400,
|
|
427
|
+
BAD_REQUEST: 400,
|
|
428
|
+
UNAUTHORIZED: 401,
|
|
429
|
+
PAYMENT_REQUIRED: 402,
|
|
430
|
+
FORBIDDEN: 403,
|
|
431
|
+
NOT_FOUND: 404,
|
|
432
|
+
METHOD_NOT_SUPPORTED: 405,
|
|
433
|
+
TIMEOUT: 408,
|
|
434
|
+
CONFLICT: 409,
|
|
435
|
+
PRECONDITION_FAILED: 412,
|
|
436
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
437
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
438
|
+
UNPROCESSABLE_CONTENT: 422,
|
|
439
|
+
PRECONDITION_REQUIRED: 428,
|
|
440
|
+
TOO_MANY_REQUESTS: 429,
|
|
441
|
+
CLIENT_CLOSED_REQUEST: 499,
|
|
442
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
443
|
+
NOT_IMPLEMENTED: 501,
|
|
444
|
+
BAD_GATEWAY: 502,
|
|
445
|
+
SERVICE_UNAVAILABLE: 503,
|
|
446
|
+
GATEWAY_TIMEOUT: 504
|
|
447
|
+
};
|
|
448
|
+
function getStatusCodeFromKey(code) {
|
|
449
|
+
var _JSONRPC2_TO_HTTP_COD;
|
|
450
|
+
return (_JSONRPC2_TO_HTTP_COD = JSONRPC2_TO_HTTP_CODE[code]) !== null && _JSONRPC2_TO_HTTP_COD !== void 0 ? _JSONRPC2_TO_HTTP_COD : 500;
|
|
451
|
+
}
|
|
452
|
+
function getHTTPStatusCodeFromError(error) {
|
|
453
|
+
return getStatusCodeFromKey(error.code);
|
|
454
|
+
}
|
|
455
|
+
var require_typeof2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
456
|
+
function _typeof$2(o) {
|
|
457
|
+
"@babel/helpers - typeof";
|
|
458
|
+
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
459
|
+
return typeof o$1;
|
|
460
|
+
} : function(o$1) {
|
|
461
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
462
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
463
|
+
}
|
|
464
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
465
|
+
} });
|
|
466
|
+
var require_toPrimitive2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
467
|
+
var _typeof$1 = require_typeof2()["default"];
|
|
468
|
+
function toPrimitive$1(t, r) {
|
|
469
|
+
if ("object" != _typeof$1(t) || !t) return t;
|
|
470
|
+
var e = t[Symbol.toPrimitive];
|
|
471
|
+
if (void 0 !== e) {
|
|
472
|
+
var i = e.call(t, r || "default");
|
|
473
|
+
if ("object" != _typeof$1(i)) return i;
|
|
474
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
475
|
+
}
|
|
476
|
+
return ("string" === r ? String : Number)(t);
|
|
477
|
+
}
|
|
478
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
479
|
+
} });
|
|
480
|
+
var require_toPropertyKey2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
481
|
+
var _typeof = require_typeof2()["default"];
|
|
482
|
+
var toPrimitive = require_toPrimitive2();
|
|
483
|
+
function toPropertyKey$1(t) {
|
|
484
|
+
var i = toPrimitive(t, "string");
|
|
485
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
486
|
+
}
|
|
487
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
488
|
+
} });
|
|
489
|
+
var require_defineProperty2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
490
|
+
var toPropertyKey = require_toPropertyKey2();
|
|
491
|
+
function _defineProperty(e, r, t) {
|
|
492
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
493
|
+
value: t,
|
|
494
|
+
enumerable: true,
|
|
495
|
+
configurable: true,
|
|
496
|
+
writable: true
|
|
497
|
+
}) : e[r] = t, e;
|
|
498
|
+
}
|
|
499
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
500
|
+
} });
|
|
501
|
+
var require_objectSpread22 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
502
|
+
var defineProperty = require_defineProperty2();
|
|
503
|
+
function ownKeys(e, r) {
|
|
504
|
+
var t = Object.keys(e);
|
|
505
|
+
if (Object.getOwnPropertySymbols) {
|
|
506
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
507
|
+
r && (o = o.filter(function(r$1) {
|
|
508
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
509
|
+
})), t.push.apply(t, o);
|
|
510
|
+
}
|
|
511
|
+
return t;
|
|
512
|
+
}
|
|
513
|
+
function _objectSpread2(e) {
|
|
514
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
515
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
516
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
517
|
+
defineProperty(e, r$1, t[r$1]);
|
|
518
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
519
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
return e;
|
|
523
|
+
}
|
|
524
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
525
|
+
} });
|
|
526
|
+
var import_objectSpread2 = __toESM2(require_objectSpread22(), 1);
|
|
527
|
+
function getErrorShape(opts) {
|
|
528
|
+
const { path, error, config } = opts;
|
|
529
|
+
const { code } = opts.error;
|
|
530
|
+
const shape = {
|
|
531
|
+
message: error.message,
|
|
532
|
+
code: TRPC_ERROR_CODES_BY_KEY[code],
|
|
533
|
+
data: {
|
|
534
|
+
code,
|
|
535
|
+
httpStatus: getHTTPStatusCodeFromError(error)
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
if (config.isDev && typeof opts.error.stack === "string") shape.data.stack = opts.error.stack;
|
|
539
|
+
if (typeof path === "string") shape.data.path = path;
|
|
540
|
+
return config.errorFormatter((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { shape }));
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// ../../node_modules/@trpc/server/dist/tracked-Bjtgv3wJ.mjs
|
|
544
|
+
var import_defineProperty = __toESM2(require_defineProperty2(), 1);
|
|
545
|
+
var UnknownCauseError = class extends Error {
|
|
546
|
+
};
|
|
547
|
+
function getCauseFromUnknown(cause) {
|
|
548
|
+
if (cause instanceof Error) return cause;
|
|
549
|
+
const type = typeof cause;
|
|
550
|
+
if (type === "undefined" || type === "function" || cause === null) return void 0;
|
|
551
|
+
if (type !== "object") return new Error(String(cause));
|
|
552
|
+
if (isObject(cause)) return Object.assign(new UnknownCauseError(), cause);
|
|
553
|
+
return void 0;
|
|
554
|
+
}
|
|
555
|
+
function getTRPCErrorFromUnknown(cause) {
|
|
556
|
+
if (cause instanceof TRPCError) return cause;
|
|
557
|
+
if (cause instanceof Error && cause.name === "TRPCError") return cause;
|
|
558
|
+
const trpcError = new TRPCError({
|
|
559
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
560
|
+
cause
|
|
561
|
+
});
|
|
562
|
+
if (cause instanceof Error && cause.stack) trpcError.stack = cause.stack;
|
|
563
|
+
return trpcError;
|
|
564
|
+
}
|
|
565
|
+
var TRPCError = class extends Error {
|
|
566
|
+
constructor(opts) {
|
|
567
|
+
var _ref, _opts$message, _this$cause;
|
|
568
|
+
const cause = getCauseFromUnknown(opts.cause);
|
|
569
|
+
const message = (_ref = (_opts$message = opts.message) !== null && _opts$message !== void 0 ? _opts$message : cause === null || cause === void 0 ? void 0 : cause.message) !== null && _ref !== void 0 ? _ref : opts.code;
|
|
570
|
+
super(message, { cause });
|
|
571
|
+
(0, import_defineProperty.default)(this, "cause", void 0);
|
|
572
|
+
(0, import_defineProperty.default)(this, "code", void 0);
|
|
573
|
+
this.code = opts.code;
|
|
574
|
+
this.name = "TRPCError";
|
|
575
|
+
(_this$cause = this.cause) !== null && _this$cause !== void 0 || (this.cause = cause);
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
var import_objectSpread2$1 = __toESM2(require_objectSpread22(), 1);
|
|
579
|
+
function transformResultInner(response, transformer) {
|
|
580
|
+
if ("error" in response) {
|
|
581
|
+
const error = transformer.deserialize(response.error);
|
|
582
|
+
return {
|
|
583
|
+
ok: false,
|
|
584
|
+
error: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, response), {}, { error })
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
const result = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, response.result), (!response.result.type || response.result.type === "data") && {
|
|
588
|
+
type: "data",
|
|
589
|
+
data: transformer.deserialize(response.result.data)
|
|
590
|
+
});
|
|
591
|
+
return {
|
|
592
|
+
ok: true,
|
|
593
|
+
result
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
var TransformResultError = class extends Error {
|
|
597
|
+
constructor() {
|
|
598
|
+
super("Unable to transform response from server");
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
function transformResult(response, transformer) {
|
|
602
|
+
let result;
|
|
603
|
+
try {
|
|
604
|
+
result = transformResultInner(response, transformer);
|
|
605
|
+
} catch (_unused) {
|
|
606
|
+
throw new TransformResultError();
|
|
607
|
+
}
|
|
608
|
+
if (!result.ok && (!isObject(result.error.error) || typeof result.error.error["code"] !== "number")) throw new TransformResultError();
|
|
609
|
+
if (result.ok && !isObject(result.result)) throw new TransformResultError();
|
|
610
|
+
return result;
|
|
611
|
+
}
|
|
612
|
+
var import_objectSpread22 = __toESM2(require_objectSpread22(), 1);
|
|
613
|
+
function isProcedure(procedureOrRouter) {
|
|
614
|
+
return typeof procedureOrRouter === "function";
|
|
615
|
+
}
|
|
616
|
+
async function getProcedureAtPath(router, path) {
|
|
617
|
+
const { _def } = router;
|
|
618
|
+
let procedure = _def.procedures[path];
|
|
619
|
+
while (!procedure) {
|
|
620
|
+
const key = Object.keys(_def.lazy).find((key$1) => path.startsWith(key$1));
|
|
621
|
+
if (!key) return null;
|
|
622
|
+
const lazyRouter = _def.lazy[key];
|
|
623
|
+
await lazyRouter.load();
|
|
624
|
+
procedure = _def.procedures[path];
|
|
625
|
+
}
|
|
626
|
+
return procedure;
|
|
627
|
+
}
|
|
628
|
+
async function callProcedure(opts) {
|
|
629
|
+
const { type, path } = opts;
|
|
630
|
+
const proc = await getProcedureAtPath(opts.router, path);
|
|
631
|
+
if (!proc || !isProcedure(proc) || proc._def.type !== type && !opts.allowMethodOverride) throw new TRPCError({
|
|
632
|
+
code: "NOT_FOUND",
|
|
633
|
+
message: `No "${type}"-procedure on path "${path}"`
|
|
634
|
+
});
|
|
635
|
+
if (proc._def.type !== type && opts.allowMethodOverride && proc._def.type === "subscription") throw new TRPCError({
|
|
636
|
+
code: "METHOD_NOT_SUPPORTED",
|
|
637
|
+
message: `Method override is not supported for subscriptions`
|
|
638
|
+
});
|
|
639
|
+
return proc(opts);
|
|
640
|
+
}
|
|
641
|
+
var trackedSymbol = /* @__PURE__ */ Symbol();
|
|
642
|
+
function isTrackedEnvelope(value) {
|
|
643
|
+
return Array.isArray(value) && value[2] === trackedSymbol;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// ../../node_modules/@trpc/server/dist/resolveResponse-O0k3XIo_.mjs
|
|
647
|
+
var import_objectSpread2$12 = __toESM2(require_objectSpread22(), 1);
|
|
648
|
+
function isAbortError(error) {
|
|
649
|
+
return isObject(error) && error["name"] === "AbortError";
|
|
650
|
+
}
|
|
651
|
+
var import_defineProperty2 = __toESM2(require_defineProperty2(), 1);
|
|
652
|
+
var _Symbol$toStringTag;
|
|
653
|
+
var subscribableCache = /* @__PURE__ */ new WeakMap();
|
|
654
|
+
var NOOP = () => {
|
|
655
|
+
};
|
|
656
|
+
_Symbol$toStringTag = Symbol.toStringTag;
|
|
657
|
+
var Unpromise = class Unpromise2 {
|
|
658
|
+
constructor(arg) {
|
|
659
|
+
(0, import_defineProperty2.default)(this, "promise", void 0);
|
|
660
|
+
(0, import_defineProperty2.default)(this, "subscribers", []);
|
|
661
|
+
(0, import_defineProperty2.default)(this, "settlement", null);
|
|
662
|
+
(0, import_defineProperty2.default)(this, _Symbol$toStringTag, "Unpromise");
|
|
663
|
+
if (typeof arg === "function") this.promise = new Promise(arg);
|
|
664
|
+
else this.promise = arg;
|
|
665
|
+
const thenReturn = this.promise.then((value) => {
|
|
666
|
+
const { subscribers } = this;
|
|
667
|
+
this.subscribers = null;
|
|
668
|
+
this.settlement = {
|
|
669
|
+
status: "fulfilled",
|
|
670
|
+
value
|
|
671
|
+
};
|
|
672
|
+
subscribers === null || subscribers === void 0 || subscribers.forEach(({ resolve }) => {
|
|
673
|
+
resolve(value);
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
if ("catch" in thenReturn) thenReturn.catch((reason) => {
|
|
677
|
+
const { subscribers } = this;
|
|
678
|
+
this.subscribers = null;
|
|
679
|
+
this.settlement = {
|
|
680
|
+
status: "rejected",
|
|
681
|
+
reason
|
|
682
|
+
};
|
|
683
|
+
subscribers === null || subscribers === void 0 || subscribers.forEach(({ reject }) => {
|
|
684
|
+
reject(reason);
|
|
685
|
+
});
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
/** Create a promise that mitigates uncontrolled subscription to a long-lived
|
|
689
|
+
* Promise via .then() and .catch() - otherwise a source of memory leaks.
|
|
690
|
+
*
|
|
691
|
+
* The returned promise has an `unsubscribe()` method which can be called when
|
|
692
|
+
* the Promise is no longer being tracked by application logic, and which
|
|
693
|
+
* ensures that there is no reference chain from the original promise to the
|
|
694
|
+
* new one, and therefore no memory leak.
|
|
695
|
+
*
|
|
696
|
+
* If original promise has not yet settled, this adds a new unique promise
|
|
697
|
+
* that listens to then/catch events, along with an `unsubscribe()` method to
|
|
698
|
+
* detach it.
|
|
699
|
+
*
|
|
700
|
+
* If original promise has settled, then creates a new Promise.resolve() or
|
|
701
|
+
* Promise.reject() and provided unsubscribe is a noop.
|
|
702
|
+
*
|
|
703
|
+
* If you call `unsubscribe()` before the returned Promise has settled, it
|
|
704
|
+
* will never settle.
|
|
705
|
+
*/
|
|
706
|
+
subscribe() {
|
|
707
|
+
let promise;
|
|
708
|
+
let unsubscribe;
|
|
709
|
+
const { settlement } = this;
|
|
710
|
+
if (settlement === null) {
|
|
711
|
+
if (this.subscribers === null) throw new Error("Unpromise settled but still has subscribers");
|
|
712
|
+
const subscriber = withResolvers();
|
|
713
|
+
this.subscribers = listWithMember(this.subscribers, subscriber);
|
|
714
|
+
promise = subscriber.promise;
|
|
715
|
+
unsubscribe = () => {
|
|
716
|
+
if (this.subscribers !== null) this.subscribers = listWithoutMember(this.subscribers, subscriber);
|
|
717
|
+
};
|
|
718
|
+
} else {
|
|
719
|
+
const { status } = settlement;
|
|
720
|
+
if (status === "fulfilled") promise = Promise.resolve(settlement.value);
|
|
721
|
+
else promise = Promise.reject(settlement.reason);
|
|
722
|
+
unsubscribe = NOOP;
|
|
723
|
+
}
|
|
724
|
+
return Object.assign(promise, { unsubscribe });
|
|
725
|
+
}
|
|
726
|
+
/** STANDARD PROMISE METHODS (but returning a SubscribedPromise) */
|
|
727
|
+
then(onfulfilled, onrejected) {
|
|
728
|
+
const subscribed = this.subscribe();
|
|
729
|
+
const { unsubscribe } = subscribed;
|
|
730
|
+
return Object.assign(subscribed.then(onfulfilled, onrejected), { unsubscribe });
|
|
731
|
+
}
|
|
732
|
+
catch(onrejected) {
|
|
733
|
+
const subscribed = this.subscribe();
|
|
734
|
+
const { unsubscribe } = subscribed;
|
|
735
|
+
return Object.assign(subscribed.catch(onrejected), { unsubscribe });
|
|
736
|
+
}
|
|
737
|
+
finally(onfinally) {
|
|
738
|
+
const subscribed = this.subscribe();
|
|
739
|
+
const { unsubscribe } = subscribed;
|
|
740
|
+
return Object.assign(subscribed.finally(onfinally), { unsubscribe });
|
|
741
|
+
}
|
|
742
|
+
/** Unpromise STATIC METHODS */
|
|
743
|
+
/** Create or Retrieve the proxy Unpromise (a re-used Unpromise for the VM lifetime
|
|
744
|
+
* of the provided Promise reference) */
|
|
745
|
+
static proxy(promise) {
|
|
746
|
+
const cached = Unpromise2.getSubscribablePromise(promise);
|
|
747
|
+
return typeof cached !== "undefined" ? cached : Unpromise2.createSubscribablePromise(promise);
|
|
748
|
+
}
|
|
749
|
+
/** Create and store an Unpromise keyed by an original Promise. */
|
|
750
|
+
static createSubscribablePromise(promise) {
|
|
751
|
+
const created = new Unpromise2(promise);
|
|
752
|
+
subscribableCache.set(promise, created);
|
|
753
|
+
subscribableCache.set(created, created);
|
|
754
|
+
return created;
|
|
755
|
+
}
|
|
756
|
+
/** Retrieve a previously-created Unpromise keyed by an original Promise. */
|
|
757
|
+
static getSubscribablePromise(promise) {
|
|
758
|
+
return subscribableCache.get(promise);
|
|
759
|
+
}
|
|
760
|
+
/** Promise STATIC METHODS */
|
|
761
|
+
/** Lookup the Unpromise for this promise, and derive a SubscribedPromise from
|
|
762
|
+
* it (that can be later unsubscribed to eliminate Memory leaks) */
|
|
763
|
+
static resolve(value) {
|
|
764
|
+
const promise = typeof value === "object" && value !== null && "then" in value && typeof value.then === "function" ? value : Promise.resolve(value);
|
|
765
|
+
return Unpromise2.proxy(promise).subscribe();
|
|
766
|
+
}
|
|
767
|
+
static async any(values) {
|
|
768
|
+
const valuesArray = Array.isArray(values) ? values : [...values];
|
|
769
|
+
const subscribedPromises = valuesArray.map(Unpromise2.resolve);
|
|
770
|
+
try {
|
|
771
|
+
return await Promise.any(subscribedPromises);
|
|
772
|
+
} finally {
|
|
773
|
+
subscribedPromises.forEach(({ unsubscribe }) => {
|
|
774
|
+
unsubscribe();
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
static async race(values) {
|
|
779
|
+
const valuesArray = Array.isArray(values) ? values : [...values];
|
|
780
|
+
const subscribedPromises = valuesArray.map(Unpromise2.resolve);
|
|
781
|
+
try {
|
|
782
|
+
return await Promise.race(subscribedPromises);
|
|
783
|
+
} finally {
|
|
784
|
+
subscribedPromises.forEach(({ unsubscribe }) => {
|
|
785
|
+
unsubscribe();
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
/** Create a race of SubscribedPromises that will fulfil to a single winning
|
|
790
|
+
* Promise (in a 1-Tuple). Eliminates memory leaks from long-lived promises
|
|
791
|
+
* accumulating .then() and .catch() subscribers. Allows simple logic to
|
|
792
|
+
* consume the result, like...
|
|
793
|
+
* ```ts
|
|
794
|
+
* const [ winner ] = await Unpromise.race([ promiseA, promiseB ]);
|
|
795
|
+
* if(winner === promiseB){
|
|
796
|
+
* const result = await promiseB;
|
|
797
|
+
* // do the thing
|
|
798
|
+
* }
|
|
799
|
+
* ```
|
|
800
|
+
* */
|
|
801
|
+
static async raceReferences(promises) {
|
|
802
|
+
const selfPromises = promises.map(resolveSelfTuple);
|
|
803
|
+
try {
|
|
804
|
+
return await Promise.race(selfPromises);
|
|
805
|
+
} finally {
|
|
806
|
+
for (const promise of selfPromises) promise.unsubscribe();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
function resolveSelfTuple(promise) {
|
|
811
|
+
return Unpromise.proxy(promise).then(() => [promise]);
|
|
812
|
+
}
|
|
813
|
+
function withResolvers() {
|
|
814
|
+
let resolve;
|
|
815
|
+
let reject;
|
|
816
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
817
|
+
resolve = _resolve;
|
|
818
|
+
reject = _reject;
|
|
819
|
+
});
|
|
820
|
+
return {
|
|
821
|
+
promise,
|
|
822
|
+
resolve,
|
|
823
|
+
reject
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
function listWithMember(arr, member) {
|
|
827
|
+
return [...arr, member];
|
|
828
|
+
}
|
|
829
|
+
function listWithoutIndex(arr, index) {
|
|
830
|
+
return [...arr.slice(0, index), ...arr.slice(index + 1)];
|
|
831
|
+
}
|
|
832
|
+
function listWithoutMember(arr, member) {
|
|
833
|
+
const index = arr.indexOf(member);
|
|
834
|
+
if (index !== -1) return listWithoutIndex(arr, index);
|
|
835
|
+
return arr;
|
|
836
|
+
}
|
|
837
|
+
var _Symbol;
|
|
838
|
+
var _Symbol$dispose;
|
|
839
|
+
var _Symbol2;
|
|
840
|
+
var _Symbol2$asyncDispose;
|
|
841
|
+
(_Symbol$dispose = (_Symbol = Symbol).dispose) !== null && _Symbol$dispose !== void 0 || (_Symbol.dispose = /* @__PURE__ */ Symbol());
|
|
842
|
+
(_Symbol2$asyncDispose = (_Symbol2 = Symbol).asyncDispose) !== null && _Symbol2$asyncDispose !== void 0 || (_Symbol2.asyncDispose = /* @__PURE__ */ Symbol());
|
|
843
|
+
function makeResource(thing, dispose) {
|
|
844
|
+
const it = thing;
|
|
845
|
+
const existing = it[Symbol.dispose];
|
|
846
|
+
it[Symbol.dispose] = () => {
|
|
847
|
+
dispose();
|
|
848
|
+
existing === null || existing === void 0 || existing();
|
|
849
|
+
};
|
|
850
|
+
return it;
|
|
851
|
+
}
|
|
852
|
+
function makeAsyncResource(thing, dispose) {
|
|
853
|
+
const it = thing;
|
|
854
|
+
const existing = it[Symbol.asyncDispose];
|
|
855
|
+
it[Symbol.asyncDispose] = async () => {
|
|
856
|
+
await dispose();
|
|
857
|
+
await (existing === null || existing === void 0 ? void 0 : existing());
|
|
858
|
+
};
|
|
859
|
+
return it;
|
|
860
|
+
}
|
|
861
|
+
var disposablePromiseTimerResult = /* @__PURE__ */ Symbol();
|
|
862
|
+
function timerResource(ms) {
|
|
863
|
+
let timer = null;
|
|
864
|
+
return makeResource({ start() {
|
|
865
|
+
if (timer) throw new Error("Timer already started");
|
|
866
|
+
const promise = new Promise((resolve) => {
|
|
867
|
+
timer = setTimeout(() => resolve(disposablePromiseTimerResult), ms);
|
|
868
|
+
});
|
|
869
|
+
return promise;
|
|
870
|
+
} }, () => {
|
|
871
|
+
if (timer) clearTimeout(timer);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
var require_usingCtx = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
|
|
875
|
+
function _usingCtx() {
|
|
876
|
+
var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
|
|
877
|
+
var n$1 = Error();
|
|
878
|
+
return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
|
|
879
|
+
}, e = {}, n = [];
|
|
880
|
+
function using(r$1, e$1) {
|
|
881
|
+
if (null != e$1) {
|
|
882
|
+
if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
883
|
+
if (r$1) var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
884
|
+
if (void 0 === o && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1)) var t = o;
|
|
885
|
+
if ("function" != typeof o) throw new TypeError("Object is not disposable.");
|
|
886
|
+
t && (o = function o$1() {
|
|
887
|
+
try {
|
|
888
|
+
t.call(e$1);
|
|
889
|
+
} catch (r$2) {
|
|
890
|
+
return Promise.reject(r$2);
|
|
891
|
+
}
|
|
892
|
+
}), n.push({
|
|
893
|
+
v: e$1,
|
|
894
|
+
d: o,
|
|
895
|
+
a: r$1
|
|
896
|
+
});
|
|
897
|
+
} else r$1 && n.push({
|
|
898
|
+
d: e$1,
|
|
899
|
+
a: r$1
|
|
900
|
+
});
|
|
901
|
+
return e$1;
|
|
902
|
+
}
|
|
903
|
+
return {
|
|
904
|
+
e,
|
|
905
|
+
u: using.bind(null, false),
|
|
906
|
+
a: using.bind(null, true),
|
|
907
|
+
d: function d() {
|
|
908
|
+
var o, t = this.e, s = 0;
|
|
909
|
+
function next() {
|
|
910
|
+
for (; o = n.pop(); ) try {
|
|
911
|
+
if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
|
|
912
|
+
if (o.d) {
|
|
913
|
+
var r$1 = o.d.call(o.v);
|
|
914
|
+
if (o.a) return s |= 2, Promise.resolve(r$1).then(next, err);
|
|
915
|
+
} else s |= 1;
|
|
916
|
+
} catch (r$2) {
|
|
917
|
+
return err(r$2);
|
|
918
|
+
}
|
|
919
|
+
if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
920
|
+
if (t !== e) throw t;
|
|
921
|
+
}
|
|
922
|
+
function err(n$1) {
|
|
923
|
+
return t = t !== e ? new r(n$1, t) : n$1, next();
|
|
924
|
+
}
|
|
925
|
+
return next();
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
930
|
+
} });
|
|
931
|
+
var require_OverloadYield = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js"(exports, module) {
|
|
932
|
+
function _OverloadYield(e, d) {
|
|
933
|
+
this.v = e, this.k = d;
|
|
934
|
+
}
|
|
935
|
+
module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
936
|
+
} });
|
|
937
|
+
var require_awaitAsyncGenerator = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js"(exports, module) {
|
|
938
|
+
var OverloadYield$2 = require_OverloadYield();
|
|
939
|
+
function _awaitAsyncGenerator$5(e) {
|
|
940
|
+
return new OverloadYield$2(e, 0);
|
|
941
|
+
}
|
|
942
|
+
module.exports = _awaitAsyncGenerator$5, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
943
|
+
} });
|
|
944
|
+
var require_wrapAsyncGenerator = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js"(exports, module) {
|
|
945
|
+
var OverloadYield$1 = require_OverloadYield();
|
|
946
|
+
function _wrapAsyncGenerator$6(e) {
|
|
947
|
+
return function() {
|
|
948
|
+
return new AsyncGenerator(e.apply(this, arguments));
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
function AsyncGenerator(e) {
|
|
952
|
+
var r, t;
|
|
953
|
+
function resume(r$1, t$1) {
|
|
954
|
+
try {
|
|
955
|
+
var n = e[r$1](t$1), o = n.value, u = o instanceof OverloadYield$1;
|
|
956
|
+
Promise.resolve(u ? o.v : o).then(function(t$2) {
|
|
957
|
+
if (u) {
|
|
958
|
+
var i = "return" === r$1 ? "return" : "next";
|
|
959
|
+
if (!o.k || t$2.done) return resume(i, t$2);
|
|
960
|
+
t$2 = e[i](t$2).value;
|
|
961
|
+
}
|
|
962
|
+
settle(n.done ? "return" : "normal", t$2);
|
|
963
|
+
}, function(e$1) {
|
|
964
|
+
resume("throw", e$1);
|
|
965
|
+
});
|
|
966
|
+
} catch (e$1) {
|
|
967
|
+
settle("throw", e$1);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
function settle(e$1, n) {
|
|
971
|
+
switch (e$1) {
|
|
972
|
+
case "return":
|
|
973
|
+
r.resolve({
|
|
974
|
+
value: n,
|
|
975
|
+
done: true
|
|
976
|
+
});
|
|
977
|
+
break;
|
|
978
|
+
case "throw":
|
|
979
|
+
r.reject(n);
|
|
980
|
+
break;
|
|
981
|
+
default:
|
|
982
|
+
r.resolve({
|
|
983
|
+
value: n,
|
|
984
|
+
done: false
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
988
|
+
}
|
|
989
|
+
this._invoke = function(e$1, n) {
|
|
990
|
+
return new Promise(function(o, u) {
|
|
991
|
+
var i = {
|
|
992
|
+
key: e$1,
|
|
993
|
+
arg: n,
|
|
994
|
+
resolve: o,
|
|
995
|
+
reject: u,
|
|
996
|
+
next: null
|
|
997
|
+
};
|
|
998
|
+
t ? t = t.next = i : (r = t = i, resume(e$1, n));
|
|
999
|
+
});
|
|
1000
|
+
}, "function" != typeof e["return"] && (this["return"] = void 0);
|
|
1001
|
+
}
|
|
1002
|
+
AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
1003
|
+
return this;
|
|
1004
|
+
}, AsyncGenerator.prototype.next = function(e) {
|
|
1005
|
+
return this._invoke("next", e);
|
|
1006
|
+
}, AsyncGenerator.prototype["throw"] = function(e) {
|
|
1007
|
+
return this._invoke("throw", e);
|
|
1008
|
+
}, AsyncGenerator.prototype["return"] = function(e) {
|
|
1009
|
+
return this._invoke("return", e);
|
|
1010
|
+
};
|
|
1011
|
+
module.exports = _wrapAsyncGenerator$6, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1012
|
+
} });
|
|
1013
|
+
var import_usingCtx$4 = __toESM2(require_usingCtx(), 1);
|
|
1014
|
+
var import_awaitAsyncGenerator$4 = __toESM2(require_awaitAsyncGenerator(), 1);
|
|
1015
|
+
var import_wrapAsyncGenerator$5 = __toESM2(require_wrapAsyncGenerator(), 1);
|
|
1016
|
+
function iteratorResource(iterable) {
|
|
1017
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
1018
|
+
if (iterator[Symbol.asyncDispose]) return iterator;
|
|
1019
|
+
return makeAsyncResource(iterator, async () => {
|
|
1020
|
+
var _iterator$return;
|
|
1021
|
+
await ((_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator));
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
function createDeferred() {
|
|
1025
|
+
let resolve;
|
|
1026
|
+
let reject;
|
|
1027
|
+
const promise = new Promise((res, rej) => {
|
|
1028
|
+
resolve = res;
|
|
1029
|
+
reject = rej;
|
|
1030
|
+
});
|
|
1031
|
+
return {
|
|
1032
|
+
promise,
|
|
1033
|
+
resolve,
|
|
1034
|
+
reject
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
var import_usingCtx$3 = __toESM2(require_usingCtx(), 1);
|
|
1038
|
+
var import_awaitAsyncGenerator$3 = __toESM2(require_awaitAsyncGenerator(), 1);
|
|
1039
|
+
var import_wrapAsyncGenerator$4 = __toESM2(require_wrapAsyncGenerator(), 1);
|
|
1040
|
+
var import_usingCtx$2 = __toESM2(require_usingCtx(), 1);
|
|
1041
|
+
var import_awaitAsyncGenerator$2 = __toESM2(require_awaitAsyncGenerator(), 1);
|
|
1042
|
+
var import_wrapAsyncGenerator$3 = __toESM2(require_wrapAsyncGenerator(), 1);
|
|
1043
|
+
var require_asyncIterator = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
|
|
1044
|
+
function _asyncIterator$2(r) {
|
|
1045
|
+
var n, t, o, e = 2;
|
|
1046
|
+
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--; ) {
|
|
1047
|
+
if (t && null != (n = r[t])) return n.call(r);
|
|
1048
|
+
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
|
1049
|
+
t = "@@asyncIterator", o = "@@iterator";
|
|
1050
|
+
}
|
|
1051
|
+
throw new TypeError("Object is not async iterable");
|
|
1052
|
+
}
|
|
1053
|
+
function AsyncFromSyncIterator(r) {
|
|
1054
|
+
function AsyncFromSyncIteratorContinuation(r$1) {
|
|
1055
|
+
if (Object(r$1) !== r$1) return Promise.reject(new TypeError(r$1 + " is not an object."));
|
|
1056
|
+
var n = r$1.done;
|
|
1057
|
+
return Promise.resolve(r$1.value).then(function(r$2) {
|
|
1058
|
+
return {
|
|
1059
|
+
value: r$2,
|
|
1060
|
+
done: n
|
|
1061
|
+
};
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
|
|
1065
|
+
this.s = r$1, this.n = r$1.next;
|
|
1066
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
1067
|
+
s: null,
|
|
1068
|
+
n: null,
|
|
1069
|
+
next: function next() {
|
|
1070
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
1071
|
+
},
|
|
1072
|
+
"return": function _return(r$1) {
|
|
1073
|
+
var n = this.s["return"];
|
|
1074
|
+
return void 0 === n ? Promise.resolve({
|
|
1075
|
+
value: r$1,
|
|
1076
|
+
done: true
|
|
1077
|
+
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
1078
|
+
},
|
|
1079
|
+
"throw": function _throw(r$1) {
|
|
1080
|
+
var n = this.s["return"];
|
|
1081
|
+
return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
1082
|
+
}
|
|
1083
|
+
}, new AsyncFromSyncIterator(r);
|
|
1084
|
+
}
|
|
1085
|
+
module.exports = _asyncIterator$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1086
|
+
} });
|
|
1087
|
+
var import_awaitAsyncGenerator$1 = __toESM2(require_awaitAsyncGenerator(), 1);
|
|
1088
|
+
var import_wrapAsyncGenerator$2 = __toESM2(require_wrapAsyncGenerator(), 1);
|
|
1089
|
+
var import_usingCtx$1 = __toESM2(require_usingCtx(), 1);
|
|
1090
|
+
var import_asyncIterator$1 = __toESM2(require_asyncIterator(), 1);
|
|
1091
|
+
var CHUNK_VALUE_TYPE_PROMISE = 0;
|
|
1092
|
+
var CHUNK_VALUE_TYPE_ASYNC_ITERABLE = 1;
|
|
1093
|
+
var PROMISE_STATUS_FULFILLED = 0;
|
|
1094
|
+
var PROMISE_STATUS_REJECTED = 1;
|
|
1095
|
+
var ASYNC_ITERABLE_STATUS_RETURN = 0;
|
|
1096
|
+
var ASYNC_ITERABLE_STATUS_YIELD = 1;
|
|
1097
|
+
var ASYNC_ITERABLE_STATUS_ERROR = 2;
|
|
1098
|
+
var AsyncError = class extends Error {
|
|
1099
|
+
constructor(data) {
|
|
1100
|
+
super("Received error from server");
|
|
1101
|
+
this.data = data;
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
var nodeJsStreamToReaderEsque = (source) => {
|
|
1105
|
+
return { getReader() {
|
|
1106
|
+
const stream = new ReadableStream({ start(controller) {
|
|
1107
|
+
source.on("data", (chunk) => {
|
|
1108
|
+
controller.enqueue(chunk);
|
|
1109
|
+
});
|
|
1110
|
+
source.on("end", () => {
|
|
1111
|
+
controller.close();
|
|
1112
|
+
});
|
|
1113
|
+
source.on("error", (error) => {
|
|
1114
|
+
controller.error(error);
|
|
1115
|
+
});
|
|
1116
|
+
} });
|
|
1117
|
+
return stream.getReader();
|
|
1118
|
+
} };
|
|
1119
|
+
};
|
|
1120
|
+
function createLineAccumulator(from) {
|
|
1121
|
+
const reader = "getReader" in from ? from.getReader() : nodeJsStreamToReaderEsque(from).getReader();
|
|
1122
|
+
let lineAggregate = "";
|
|
1123
|
+
return new ReadableStream({
|
|
1124
|
+
async pull(controller) {
|
|
1125
|
+
const { done, value } = await reader.read();
|
|
1126
|
+
if (done) controller.close();
|
|
1127
|
+
else controller.enqueue(value);
|
|
1128
|
+
},
|
|
1129
|
+
cancel() {
|
|
1130
|
+
return reader.cancel();
|
|
1131
|
+
}
|
|
1132
|
+
}).pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({ transform(chunk, controller) {
|
|
1133
|
+
var _parts$pop;
|
|
1134
|
+
lineAggregate += chunk;
|
|
1135
|
+
const parts = lineAggregate.split("\n");
|
|
1136
|
+
lineAggregate = (_parts$pop = parts.pop()) !== null && _parts$pop !== void 0 ? _parts$pop : "";
|
|
1137
|
+
for (const part of parts) controller.enqueue(part);
|
|
1138
|
+
} }));
|
|
1139
|
+
}
|
|
1140
|
+
function createConsumerStream(from) {
|
|
1141
|
+
const stream = createLineAccumulator(from);
|
|
1142
|
+
let sentHead = false;
|
|
1143
|
+
return stream.pipeThrough(new TransformStream({ transform(line, controller) {
|
|
1144
|
+
if (!sentHead) {
|
|
1145
|
+
const head = JSON.parse(line);
|
|
1146
|
+
controller.enqueue(head);
|
|
1147
|
+
sentHead = true;
|
|
1148
|
+
} else {
|
|
1149
|
+
const chunk = JSON.parse(line);
|
|
1150
|
+
controller.enqueue(chunk);
|
|
1151
|
+
}
|
|
1152
|
+
} }));
|
|
1153
|
+
}
|
|
1154
|
+
function createStreamsManager(abortController) {
|
|
1155
|
+
const controllerMap = /* @__PURE__ */ new Map();
|
|
1156
|
+
function isEmpty() {
|
|
1157
|
+
return Array.from(controllerMap.values()).every((c) => c.closed);
|
|
1158
|
+
}
|
|
1159
|
+
function createStreamController() {
|
|
1160
|
+
let originalController;
|
|
1161
|
+
const stream = new ReadableStream({ start(controller) {
|
|
1162
|
+
originalController = controller;
|
|
1163
|
+
} });
|
|
1164
|
+
const streamController = {
|
|
1165
|
+
enqueue: (v) => originalController.enqueue(v),
|
|
1166
|
+
close: () => {
|
|
1167
|
+
originalController.close();
|
|
1168
|
+
clear();
|
|
1169
|
+
if (isEmpty()) abortController.abort();
|
|
1170
|
+
},
|
|
1171
|
+
closed: false,
|
|
1172
|
+
getReaderResource: () => {
|
|
1173
|
+
const reader = stream.getReader();
|
|
1174
|
+
return makeResource(reader, () => {
|
|
1175
|
+
streamController.close();
|
|
1176
|
+
reader.releaseLock();
|
|
1177
|
+
});
|
|
1178
|
+
},
|
|
1179
|
+
error: (reason) => {
|
|
1180
|
+
originalController.error(reason);
|
|
1181
|
+
clear();
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
function clear() {
|
|
1185
|
+
Object.assign(streamController, {
|
|
1186
|
+
closed: true,
|
|
1187
|
+
close: () => {
|
|
1188
|
+
},
|
|
1189
|
+
enqueue: () => {
|
|
1190
|
+
},
|
|
1191
|
+
getReaderResource: null,
|
|
1192
|
+
error: () => {
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
return streamController;
|
|
1197
|
+
}
|
|
1198
|
+
function getOrCreate(chunkId) {
|
|
1199
|
+
let c = controllerMap.get(chunkId);
|
|
1200
|
+
if (!c) {
|
|
1201
|
+
c = createStreamController();
|
|
1202
|
+
controllerMap.set(chunkId, c);
|
|
1203
|
+
}
|
|
1204
|
+
return c;
|
|
1205
|
+
}
|
|
1206
|
+
function cancelAll(reason) {
|
|
1207
|
+
for (const controller of controllerMap.values()) controller.error(reason);
|
|
1208
|
+
}
|
|
1209
|
+
function closeAll() {
|
|
1210
|
+
for (const controller of controllerMap.values()) controller.close();
|
|
1211
|
+
}
|
|
1212
|
+
return {
|
|
1213
|
+
getOrCreate,
|
|
1214
|
+
cancelAll,
|
|
1215
|
+
closeAll
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
async function jsonlStreamConsumer(opts) {
|
|
1219
|
+
const { deserialize = (v) => v } = opts;
|
|
1220
|
+
let source = createConsumerStream(opts.from);
|
|
1221
|
+
if (deserialize) source = source.pipeThrough(new TransformStream({ transform(chunk, controller) {
|
|
1222
|
+
controller.enqueue(deserialize(chunk));
|
|
1223
|
+
} }));
|
|
1224
|
+
let headDeferred = createDeferred();
|
|
1225
|
+
const streamManager = createStreamsManager(opts.abortController);
|
|
1226
|
+
function decodeChunkDefinition(value) {
|
|
1227
|
+
const [_path, type, chunkId] = value;
|
|
1228
|
+
const controller = streamManager.getOrCreate(chunkId);
|
|
1229
|
+
switch (type) {
|
|
1230
|
+
case CHUNK_VALUE_TYPE_PROMISE:
|
|
1231
|
+
return run(async () => {
|
|
1232
|
+
try {
|
|
1233
|
+
var _usingCtx3 = (0, import_usingCtx$1.default)();
|
|
1234
|
+
const reader = _usingCtx3.u(controller.getReaderResource());
|
|
1235
|
+
const { value: value$1 } = await reader.read();
|
|
1236
|
+
const [_chunkId, status, data] = value$1;
|
|
1237
|
+
switch (status) {
|
|
1238
|
+
case PROMISE_STATUS_FULFILLED:
|
|
1239
|
+
return decode(data);
|
|
1240
|
+
case PROMISE_STATUS_REJECTED:
|
|
1241
|
+
var _opts$formatError3, _opts$formatError4;
|
|
1242
|
+
throw (_opts$formatError3 = (_opts$formatError4 = opts.formatError) === null || _opts$formatError4 === void 0 ? void 0 : _opts$formatError4.call(opts, { error: data })) !== null && _opts$formatError3 !== void 0 ? _opts$formatError3 : new AsyncError(data);
|
|
1243
|
+
}
|
|
1244
|
+
} catch (_) {
|
|
1245
|
+
_usingCtx3.e = _;
|
|
1246
|
+
} finally {
|
|
1247
|
+
_usingCtx3.d();
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
case CHUNK_VALUE_TYPE_ASYNC_ITERABLE:
|
|
1251
|
+
return run((0, import_wrapAsyncGenerator$2.default)(function* () {
|
|
1252
|
+
try {
|
|
1253
|
+
var _usingCtx4 = (0, import_usingCtx$1.default)();
|
|
1254
|
+
const reader = _usingCtx4.u(controller.getReaderResource());
|
|
1255
|
+
while (true) {
|
|
1256
|
+
const { value: value$1 } = yield (0, import_awaitAsyncGenerator$1.default)(reader.read());
|
|
1257
|
+
const [_chunkId, status, data] = value$1;
|
|
1258
|
+
switch (status) {
|
|
1259
|
+
case ASYNC_ITERABLE_STATUS_YIELD:
|
|
1260
|
+
yield decode(data);
|
|
1261
|
+
break;
|
|
1262
|
+
case ASYNC_ITERABLE_STATUS_RETURN:
|
|
1263
|
+
return decode(data);
|
|
1264
|
+
case ASYNC_ITERABLE_STATUS_ERROR:
|
|
1265
|
+
var _opts$formatError5, _opts$formatError6;
|
|
1266
|
+
throw (_opts$formatError5 = (_opts$formatError6 = opts.formatError) === null || _opts$formatError6 === void 0 ? void 0 : _opts$formatError6.call(opts, { error: data })) !== null && _opts$formatError5 !== void 0 ? _opts$formatError5 : new AsyncError(data);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
} catch (_) {
|
|
1270
|
+
_usingCtx4.e = _;
|
|
1271
|
+
} finally {
|
|
1272
|
+
_usingCtx4.d();
|
|
1273
|
+
}
|
|
1274
|
+
}));
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
function decode(value) {
|
|
1278
|
+
const [[data], ...asyncProps] = value;
|
|
1279
|
+
for (const value$1 of asyncProps) {
|
|
1280
|
+
const [key] = value$1;
|
|
1281
|
+
const decoded = decodeChunkDefinition(value$1);
|
|
1282
|
+
if (key === null) return decoded;
|
|
1283
|
+
data[key] = decoded;
|
|
1284
|
+
}
|
|
1285
|
+
return data;
|
|
1286
|
+
}
|
|
1287
|
+
const handleClose = () => {
|
|
1288
|
+
if (headDeferred) {
|
|
1289
|
+
headDeferred.reject(new Error("Stream closed before head was received"));
|
|
1290
|
+
headDeferred = null;
|
|
1291
|
+
}
|
|
1292
|
+
streamManager.closeAll();
|
|
1293
|
+
};
|
|
1294
|
+
const handleAbort = (reason) => {
|
|
1295
|
+
headDeferred === null || headDeferred === void 0 || headDeferred.reject(reason);
|
|
1296
|
+
headDeferred = null;
|
|
1297
|
+
streamManager.cancelAll(reason);
|
|
1298
|
+
};
|
|
1299
|
+
source.pipeTo(new WritableStream({
|
|
1300
|
+
write(chunkOrHead) {
|
|
1301
|
+
if (headDeferred) {
|
|
1302
|
+
const head = chunkOrHead;
|
|
1303
|
+
for (const [key, value] of Object.entries(chunkOrHead)) {
|
|
1304
|
+
const parsed = decode(value);
|
|
1305
|
+
head[key] = parsed;
|
|
1306
|
+
}
|
|
1307
|
+
headDeferred.resolve(head);
|
|
1308
|
+
headDeferred = null;
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
const chunk = chunkOrHead;
|
|
1312
|
+
const [idx] = chunk;
|
|
1313
|
+
const controller = streamManager.getOrCreate(idx);
|
|
1314
|
+
controller.enqueue(chunk);
|
|
1315
|
+
},
|
|
1316
|
+
close: handleClose,
|
|
1317
|
+
abort: handleAbort
|
|
1318
|
+
})).catch((error) => {
|
|
1319
|
+
var _opts$onError4;
|
|
1320
|
+
(_opts$onError4 = opts.onError) === null || _opts$onError4 === void 0 || _opts$onError4.call(opts, { error });
|
|
1321
|
+
handleAbort(error);
|
|
1322
|
+
});
|
|
1323
|
+
return [await headDeferred.promise];
|
|
1324
|
+
}
|
|
1325
|
+
var require_asyncGeneratorDelegate = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncGeneratorDelegate.js"(exports, module) {
|
|
1326
|
+
var OverloadYield = require_OverloadYield();
|
|
1327
|
+
function _asyncGeneratorDelegate$1(t) {
|
|
1328
|
+
var e = {}, n = false;
|
|
1329
|
+
function pump(e$1, r) {
|
|
1330
|
+
return n = true, r = new Promise(function(n$1) {
|
|
1331
|
+
n$1(t[e$1](r));
|
|
1332
|
+
}), {
|
|
1333
|
+
done: false,
|
|
1334
|
+
value: new OverloadYield(r, 1)
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
return e["undefined" != typeof Symbol && Symbol.iterator || "@@iterator"] = function() {
|
|
1338
|
+
return this;
|
|
1339
|
+
}, e.next = function(t$1) {
|
|
1340
|
+
return n ? (n = false, t$1) : pump("next", t$1);
|
|
1341
|
+
}, "function" == typeof t["throw"] && (e["throw"] = function(t$1) {
|
|
1342
|
+
if (n) throw n = false, t$1;
|
|
1343
|
+
return pump("throw", t$1);
|
|
1344
|
+
}), "function" == typeof t["return"] && (e["return"] = function(t$1) {
|
|
1345
|
+
return n ? (n = false, t$1) : pump("return", t$1);
|
|
1346
|
+
}), e;
|
|
1347
|
+
}
|
|
1348
|
+
module.exports = _asyncGeneratorDelegate$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1349
|
+
} });
|
|
1350
|
+
var import_asyncIterator = __toESM2(require_asyncIterator(), 1);
|
|
1351
|
+
var import_awaitAsyncGenerator = __toESM2(require_awaitAsyncGenerator(), 1);
|
|
1352
|
+
var import_wrapAsyncGenerator$1 = __toESM2(require_wrapAsyncGenerator(), 1);
|
|
1353
|
+
var import_asyncGeneratorDelegate = __toESM2(require_asyncGeneratorDelegate(), 1);
|
|
1354
|
+
var import_usingCtx = __toESM2(require_usingCtx(), 1);
|
|
1355
|
+
var PING_EVENT = "ping";
|
|
1356
|
+
var SERIALIZED_ERROR_EVENT = "serialized-error";
|
|
1357
|
+
var CONNECTED_EVENT = "connected";
|
|
1358
|
+
var RETURN_EVENT = "return";
|
|
1359
|
+
async function withTimeout(opts) {
|
|
1360
|
+
try {
|
|
1361
|
+
var _usingCtx$1 = (0, import_usingCtx.default)();
|
|
1362
|
+
const timeoutPromise = _usingCtx$1.u(timerResource(opts.timeoutMs));
|
|
1363
|
+
const res = await Unpromise.race([opts.promise, timeoutPromise.start()]);
|
|
1364
|
+
if (res === disposablePromiseTimerResult) return await opts.onTimeout();
|
|
1365
|
+
return res;
|
|
1366
|
+
} catch (_) {
|
|
1367
|
+
_usingCtx$1.e = _;
|
|
1368
|
+
} finally {
|
|
1369
|
+
_usingCtx$1.d();
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
function sseStreamConsumer(opts) {
|
|
1373
|
+
const { deserialize = (v) => v } = opts;
|
|
1374
|
+
let clientOptions = emptyObject();
|
|
1375
|
+
const signal = opts.signal;
|
|
1376
|
+
let _es = null;
|
|
1377
|
+
const createStream = () => new ReadableStream({
|
|
1378
|
+
async start(controller) {
|
|
1379
|
+
const [url, init] = await Promise.all([opts.url(), opts.init()]);
|
|
1380
|
+
const eventSource = _es = new opts.EventSource(url, init);
|
|
1381
|
+
controller.enqueue({
|
|
1382
|
+
type: "connecting",
|
|
1383
|
+
eventSource: _es,
|
|
1384
|
+
event: null
|
|
1385
|
+
});
|
|
1386
|
+
eventSource.addEventListener(CONNECTED_EVENT, (_msg) => {
|
|
1387
|
+
const msg = _msg;
|
|
1388
|
+
const options = JSON.parse(msg.data);
|
|
1389
|
+
clientOptions = options;
|
|
1390
|
+
controller.enqueue({
|
|
1391
|
+
type: "connected",
|
|
1392
|
+
options,
|
|
1393
|
+
eventSource
|
|
1394
|
+
});
|
|
1395
|
+
});
|
|
1396
|
+
eventSource.addEventListener(SERIALIZED_ERROR_EVENT, (_msg) => {
|
|
1397
|
+
const msg = _msg;
|
|
1398
|
+
controller.enqueue({
|
|
1399
|
+
type: "serialized-error",
|
|
1400
|
+
error: deserialize(JSON.parse(msg.data)),
|
|
1401
|
+
eventSource
|
|
1402
|
+
});
|
|
1403
|
+
});
|
|
1404
|
+
eventSource.addEventListener(PING_EVENT, () => {
|
|
1405
|
+
controller.enqueue({
|
|
1406
|
+
type: "ping",
|
|
1407
|
+
eventSource
|
|
1408
|
+
});
|
|
1409
|
+
});
|
|
1410
|
+
eventSource.addEventListener(RETURN_EVENT, () => {
|
|
1411
|
+
eventSource.close();
|
|
1412
|
+
controller.close();
|
|
1413
|
+
_es = null;
|
|
1414
|
+
});
|
|
1415
|
+
eventSource.addEventListener("error", (event) => {
|
|
1416
|
+
if (eventSource.readyState === eventSource.CLOSED) controller.error(event);
|
|
1417
|
+
else controller.enqueue({
|
|
1418
|
+
type: "connecting",
|
|
1419
|
+
eventSource,
|
|
1420
|
+
event
|
|
1421
|
+
});
|
|
1422
|
+
});
|
|
1423
|
+
eventSource.addEventListener("message", (_msg) => {
|
|
1424
|
+
const msg = _msg;
|
|
1425
|
+
const chunk = deserialize(JSON.parse(msg.data));
|
|
1426
|
+
const def = { data: chunk };
|
|
1427
|
+
if (msg.lastEventId) def.id = msg.lastEventId;
|
|
1428
|
+
controller.enqueue({
|
|
1429
|
+
type: "data",
|
|
1430
|
+
data: def,
|
|
1431
|
+
eventSource
|
|
1432
|
+
});
|
|
1433
|
+
});
|
|
1434
|
+
const onAbort = () => {
|
|
1435
|
+
try {
|
|
1436
|
+
eventSource.close();
|
|
1437
|
+
controller.close();
|
|
1438
|
+
} catch (_unused) {
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
if (signal.aborted) onAbort();
|
|
1442
|
+
else signal.addEventListener("abort", onAbort);
|
|
1443
|
+
},
|
|
1444
|
+
cancel() {
|
|
1445
|
+
_es === null || _es === void 0 || _es.close();
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1448
|
+
const getStreamResource = () => {
|
|
1449
|
+
let stream = createStream();
|
|
1450
|
+
let reader = stream.getReader();
|
|
1451
|
+
async function dispose() {
|
|
1452
|
+
await reader.cancel();
|
|
1453
|
+
_es = null;
|
|
1454
|
+
}
|
|
1455
|
+
return makeAsyncResource({
|
|
1456
|
+
read() {
|
|
1457
|
+
return reader.read();
|
|
1458
|
+
},
|
|
1459
|
+
async recreate() {
|
|
1460
|
+
await dispose();
|
|
1461
|
+
stream = createStream();
|
|
1462
|
+
reader = stream.getReader();
|
|
1463
|
+
}
|
|
1464
|
+
}, dispose);
|
|
1465
|
+
};
|
|
1466
|
+
return run((0, import_wrapAsyncGenerator$1.default)(function* () {
|
|
1467
|
+
try {
|
|
1468
|
+
var _usingCtx3 = (0, import_usingCtx.default)();
|
|
1469
|
+
const stream = _usingCtx3.a(getStreamResource());
|
|
1470
|
+
while (true) {
|
|
1471
|
+
let promise = stream.read();
|
|
1472
|
+
const timeoutMs = clientOptions.reconnectAfterInactivityMs;
|
|
1473
|
+
if (timeoutMs) promise = withTimeout({
|
|
1474
|
+
promise,
|
|
1475
|
+
timeoutMs,
|
|
1476
|
+
onTimeout: async () => {
|
|
1477
|
+
const res = {
|
|
1478
|
+
value: {
|
|
1479
|
+
type: "timeout",
|
|
1480
|
+
ms: timeoutMs,
|
|
1481
|
+
eventSource: _es
|
|
1482
|
+
},
|
|
1483
|
+
done: false
|
|
1484
|
+
};
|
|
1485
|
+
await stream.recreate();
|
|
1486
|
+
return res;
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
const result = yield (0, import_awaitAsyncGenerator.default)(promise);
|
|
1490
|
+
if (result.done) return result.value;
|
|
1491
|
+
yield result.value;
|
|
1492
|
+
}
|
|
1493
|
+
} catch (_) {
|
|
1494
|
+
_usingCtx3.e = _;
|
|
1495
|
+
} finally {
|
|
1496
|
+
yield (0, import_awaitAsyncGenerator.default)(_usingCtx3.d());
|
|
1497
|
+
}
|
|
1498
|
+
}));
|
|
1499
|
+
}
|
|
1500
|
+
var import_wrapAsyncGenerator = __toESM2(require_wrapAsyncGenerator(), 1);
|
|
1501
|
+
var import_objectSpread23 = __toESM2(require_objectSpread22(), 1);
|
|
1502
|
+
|
|
1503
|
+
// ../../node_modules/@trpc/client/dist/TRPCClientError-apv8gw59.mjs
|
|
1504
|
+
var import_defineProperty3 = __toESM(require_defineProperty(), 1);
|
|
1505
|
+
var import_objectSpread24 = __toESM(require_objectSpread2(), 1);
|
|
1506
|
+
function isTRPCClientError(cause) {
|
|
1507
|
+
return cause instanceof TRPCClientError;
|
|
1508
|
+
}
|
|
1509
|
+
function isTRPCErrorResponse(obj) {
|
|
1510
|
+
return isObject(obj) && isObject(obj["error"]) && typeof obj["error"]["code"] === "number" && typeof obj["error"]["message"] === "string";
|
|
1511
|
+
}
|
|
1512
|
+
function getMessageFromUnknownError(err, fallback) {
|
|
1513
|
+
if (typeof err === "string") return err;
|
|
1514
|
+
if (isObject(err) && typeof err["message"] === "string") return err["message"];
|
|
1515
|
+
return fallback;
|
|
1516
|
+
}
|
|
1517
|
+
var TRPCClientError = class TRPCClientError2 extends Error {
|
|
1518
|
+
constructor(message, opts) {
|
|
1519
|
+
var _opts$result, _opts$result2;
|
|
1520
|
+
const cause = opts === null || opts === void 0 ? void 0 : opts.cause;
|
|
1521
|
+
super(message, { cause });
|
|
1522
|
+
(0, import_defineProperty3.default)(this, "cause", void 0);
|
|
1523
|
+
(0, import_defineProperty3.default)(this, "shape", void 0);
|
|
1524
|
+
(0, import_defineProperty3.default)(this, "data", void 0);
|
|
1525
|
+
(0, import_defineProperty3.default)(this, "meta", void 0);
|
|
1526
|
+
this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
|
|
1527
|
+
this.cause = cause;
|
|
1528
|
+
this.shape = opts === null || opts === void 0 || (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
|
|
1529
|
+
this.data = opts === null || opts === void 0 || (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
|
|
1530
|
+
this.name = "TRPCClientError";
|
|
1531
|
+
Object.setPrototypeOf(this, TRPCClientError2.prototype);
|
|
1532
|
+
}
|
|
1533
|
+
static from(_cause, opts = {}) {
|
|
1534
|
+
const cause = _cause;
|
|
1535
|
+
if (isTRPCClientError(cause)) {
|
|
1536
|
+
if (opts.meta) cause.meta = (0, import_objectSpread24.default)((0, import_objectSpread24.default)({}, cause.meta), opts.meta);
|
|
1537
|
+
return cause;
|
|
1538
|
+
}
|
|
1539
|
+
if (isTRPCErrorResponse(cause)) return new TRPCClientError2(cause.error.message, (0, import_objectSpread24.default)((0, import_objectSpread24.default)({}, opts), {}, {
|
|
1540
|
+
result: cause,
|
|
1541
|
+
cause: opts.cause
|
|
1542
|
+
}));
|
|
1543
|
+
return new TRPCClientError2(getMessageFromUnknownError(cause, "Unknown error"), (0, import_objectSpread24.default)((0, import_objectSpread24.default)({}, opts), {}, { cause }));
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
|
|
1547
|
+
// ../../node_modules/@trpc/client/dist/unstable-internals-Bg7n9BBj.mjs
|
|
1548
|
+
function getTransformer(transformer) {
|
|
1549
|
+
const _transformer = transformer;
|
|
1550
|
+
if (!_transformer) return {
|
|
1551
|
+
input: {
|
|
1552
|
+
serialize: (data) => data,
|
|
1553
|
+
deserialize: (data) => data
|
|
1554
|
+
},
|
|
1555
|
+
output: {
|
|
1556
|
+
serialize: (data) => data,
|
|
1557
|
+
deserialize: (data) => data
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
if ("input" in _transformer) return _transformer;
|
|
1561
|
+
return {
|
|
1562
|
+
input: _transformer,
|
|
1563
|
+
output: _transformer
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
// ../../node_modules/@trpc/client/dist/httpUtils-pyf5RF99.mjs
|
|
1568
|
+
var isFunction2 = (fn) => typeof fn === "function";
|
|
1569
|
+
function getFetch(customFetchImpl) {
|
|
1570
|
+
if (customFetchImpl) return customFetchImpl;
|
|
1571
|
+
if (typeof window !== "undefined" && isFunction2(window.fetch)) return window.fetch;
|
|
1572
|
+
if (typeof globalThis !== "undefined" && isFunction2(globalThis.fetch)) return globalThis.fetch;
|
|
1573
|
+
throw new Error("No fetch implementation found");
|
|
1574
|
+
}
|
|
1575
|
+
var import_objectSpread25 = __toESM(require_objectSpread2(), 1);
|
|
1576
|
+
function resolveHTTPLinkOptions(opts) {
|
|
1577
|
+
return {
|
|
1578
|
+
url: opts.url.toString(),
|
|
1579
|
+
fetch: opts.fetch,
|
|
1580
|
+
transformer: getTransformer(opts.transformer),
|
|
1581
|
+
methodOverride: opts.methodOverride
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
function arrayToDict(array) {
|
|
1585
|
+
const dict = {};
|
|
1586
|
+
for (let index = 0; index < array.length; index++) {
|
|
1587
|
+
const element = array[index];
|
|
1588
|
+
dict[index] = element;
|
|
1589
|
+
}
|
|
1590
|
+
return dict;
|
|
1591
|
+
}
|
|
1592
|
+
var METHOD = {
|
|
1593
|
+
query: "GET",
|
|
1594
|
+
mutation: "POST",
|
|
1595
|
+
subscription: "PATCH"
|
|
1596
|
+
};
|
|
1597
|
+
function getInput(opts) {
|
|
1598
|
+
return "input" in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input) => opts.transformer.input.serialize(_input)));
|
|
1599
|
+
}
|
|
1600
|
+
var getUrl = (opts) => {
|
|
1601
|
+
const parts = opts.url.split("?");
|
|
1602
|
+
const base = parts[0].replace(/\/$/, "");
|
|
1603
|
+
let url = base + "/" + opts.path;
|
|
1604
|
+
const queryParts = [];
|
|
1605
|
+
if (parts[1]) queryParts.push(parts[1]);
|
|
1606
|
+
if ("inputs" in opts) queryParts.push("batch=1");
|
|
1607
|
+
if (opts.type === "query" || opts.type === "subscription") {
|
|
1608
|
+
const input = getInput(opts);
|
|
1609
|
+
if (input !== void 0 && opts.methodOverride !== "POST") queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
1610
|
+
}
|
|
1611
|
+
if (queryParts.length) url += "?" + queryParts.join("&");
|
|
1612
|
+
return url;
|
|
1613
|
+
};
|
|
1614
|
+
var getBody = (opts) => {
|
|
1615
|
+
if (opts.type === "query" && opts.methodOverride !== "POST") return void 0;
|
|
1616
|
+
const input = getInput(opts);
|
|
1617
|
+
return input !== void 0 ? JSON.stringify(input) : void 0;
|
|
1618
|
+
};
|
|
1619
|
+
var jsonHttpRequester = (opts) => {
|
|
1620
|
+
return httpRequest((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, opts), {}, {
|
|
1621
|
+
contentTypeHeader: "application/json",
|
|
1622
|
+
getUrl,
|
|
1623
|
+
getBody
|
|
1624
|
+
}));
|
|
1625
|
+
};
|
|
1626
|
+
var AbortError = class extends Error {
|
|
1627
|
+
constructor() {
|
|
1628
|
+
const name = "AbortError";
|
|
1629
|
+
super(name);
|
|
1630
|
+
this.name = name;
|
|
1631
|
+
this.message = name;
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
var throwIfAborted = (signal) => {
|
|
1635
|
+
var _signal$throwIfAborte;
|
|
1636
|
+
if (!(signal === null || signal === void 0 ? void 0 : signal.aborted)) return;
|
|
1637
|
+
(_signal$throwIfAborte = signal.throwIfAborted) === null || _signal$throwIfAborte === void 0 || _signal$throwIfAborte.call(signal);
|
|
1638
|
+
if (typeof DOMException !== "undefined") throw new DOMException("AbortError", "AbortError");
|
|
1639
|
+
throw new AbortError();
|
|
1640
|
+
};
|
|
1641
|
+
async function fetchHTTPResponse(opts) {
|
|
1642
|
+
var _opts$methodOverride, _opts$trpcAcceptHeade;
|
|
1643
|
+
throwIfAborted(opts.signal);
|
|
1644
|
+
const url = opts.getUrl(opts);
|
|
1645
|
+
const body = opts.getBody(opts);
|
|
1646
|
+
const method = (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== void 0 ? _opts$methodOverride : METHOD[opts.type];
|
|
1647
|
+
const resolvedHeaders = await (async () => {
|
|
1648
|
+
const heads = await opts.headers();
|
|
1649
|
+
if (Symbol.iterator in heads) return Object.fromEntries(heads);
|
|
1650
|
+
return heads;
|
|
1651
|
+
})();
|
|
1652
|
+
const headers = (0, import_objectSpread25.default)((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { [(_opts$trpcAcceptHeade = opts.trpcAcceptHeaderKey) !== null && _opts$trpcAcceptHeade !== void 0 ? _opts$trpcAcceptHeade : "trpc-accept"]: opts.trpcAcceptHeader } : void 0), resolvedHeaders);
|
|
1653
|
+
return getFetch(opts.fetch)(url, {
|
|
1654
|
+
method,
|
|
1655
|
+
signal: opts.signal,
|
|
1656
|
+
body,
|
|
1657
|
+
headers
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
async function httpRequest(opts) {
|
|
1661
|
+
const meta = {};
|
|
1662
|
+
const res = await fetchHTTPResponse(opts);
|
|
1663
|
+
meta.response = res;
|
|
1664
|
+
const json = await res.json();
|
|
1665
|
+
meta.responseJSON = json;
|
|
1666
|
+
return {
|
|
1667
|
+
json,
|
|
1668
|
+
meta
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
// ../../node_modules/@trpc/client/dist/httpLink-lG_6juPY.mjs
|
|
1673
|
+
function isOctetType(input) {
|
|
1674
|
+
return input instanceof Uint8Array || input instanceof Blob;
|
|
1675
|
+
}
|
|
1676
|
+
function isFormData(input) {
|
|
1677
|
+
return input instanceof FormData;
|
|
1678
|
+
}
|
|
1679
|
+
function isNonJsonSerializable(input) {
|
|
1680
|
+
return isOctetType(input) || isFormData(input);
|
|
1681
|
+
}
|
|
1682
|
+
var import_objectSpread26 = __toESM(require_objectSpread2(), 1);
|
|
1683
|
+
var universalRequester = (opts) => {
|
|
1684
|
+
if ("input" in opts) {
|
|
1685
|
+
const { input } = opts;
|
|
1686
|
+
if (isFormData(input)) {
|
|
1687
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations");
|
|
1688
|
+
return httpRequest((0, import_objectSpread26.default)((0, import_objectSpread26.default)({}, opts), {}, {
|
|
1689
|
+
contentTypeHeader: void 0,
|
|
1690
|
+
getUrl,
|
|
1691
|
+
getBody: () => input
|
|
1692
|
+
}));
|
|
1693
|
+
}
|
|
1694
|
+
if (isOctetType(input)) {
|
|
1695
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations");
|
|
1696
|
+
return httpRequest((0, import_objectSpread26.default)((0, import_objectSpread26.default)({}, opts), {}, {
|
|
1697
|
+
contentTypeHeader: "application/octet-stream",
|
|
1698
|
+
getUrl,
|
|
1699
|
+
getBody: () => input
|
|
1700
|
+
}));
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
return jsonHttpRequester(opts);
|
|
1704
|
+
};
|
|
1705
|
+
function httpLink(opts) {
|
|
1706
|
+
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
1707
|
+
return () => {
|
|
1708
|
+
return (operationOpts) => {
|
|
1709
|
+
const { op } = operationOpts;
|
|
1710
|
+
return observable((observer) => {
|
|
1711
|
+
const { path, input, type } = op;
|
|
1712
|
+
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
1713
|
+
const request = universalRequester((0, import_objectSpread26.default)((0, import_objectSpread26.default)({}, resolvedOpts), {}, {
|
|
1714
|
+
type,
|
|
1715
|
+
path,
|
|
1716
|
+
input,
|
|
1717
|
+
signal: op.signal,
|
|
1718
|
+
headers() {
|
|
1719
|
+
if (!opts.headers) return {};
|
|
1720
|
+
if (typeof opts.headers === "function") return opts.headers({ op });
|
|
1721
|
+
return opts.headers;
|
|
1722
|
+
}
|
|
1723
|
+
}));
|
|
1724
|
+
let meta = void 0;
|
|
1725
|
+
request.then((res) => {
|
|
1726
|
+
meta = res.meta;
|
|
1727
|
+
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
1728
|
+
if (!transformed.ok) {
|
|
1729
|
+
observer.error(TRPCClientError.from(transformed.error, { meta }));
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
observer.next({
|
|
1733
|
+
context: res.meta,
|
|
1734
|
+
result: transformed.result
|
|
1735
|
+
});
|
|
1736
|
+
observer.complete();
|
|
1737
|
+
}).catch((cause) => {
|
|
1738
|
+
observer.error(TRPCClientError.from(cause, { meta }));
|
|
1739
|
+
});
|
|
1740
|
+
return () => {
|
|
1741
|
+
};
|
|
1742
|
+
});
|
|
1743
|
+
};
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
// ../../node_modules/@trpc/client/dist/httpBatchLink-LhidKAPw.mjs
|
|
1748
|
+
var throwFatalError = () => {
|
|
1749
|
+
throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new");
|
|
1750
|
+
};
|
|
1751
|
+
function dataLoader(batchLoader) {
|
|
1752
|
+
let pendingItems = null;
|
|
1753
|
+
let dispatchTimer = null;
|
|
1754
|
+
const destroyTimerAndPendingItems = () => {
|
|
1755
|
+
clearTimeout(dispatchTimer);
|
|
1756
|
+
dispatchTimer = null;
|
|
1757
|
+
pendingItems = null;
|
|
1758
|
+
};
|
|
1759
|
+
function groupItems(items) {
|
|
1760
|
+
const groupedItems = [[]];
|
|
1761
|
+
let index = 0;
|
|
1762
|
+
while (true) {
|
|
1763
|
+
const item = items[index];
|
|
1764
|
+
if (!item) break;
|
|
1765
|
+
const lastGroup = groupedItems[groupedItems.length - 1];
|
|
1766
|
+
if (item.aborted) {
|
|
1767
|
+
var _item$reject;
|
|
1768
|
+
(_item$reject = item.reject) === null || _item$reject === void 0 || _item$reject.call(item, new Error("Aborted"));
|
|
1769
|
+
index++;
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
const isValid = batchLoader.validate(lastGroup.concat(item).map((it) => it.key));
|
|
1773
|
+
if (isValid) {
|
|
1774
|
+
lastGroup.push(item);
|
|
1775
|
+
index++;
|
|
1776
|
+
continue;
|
|
1777
|
+
}
|
|
1778
|
+
if (lastGroup.length === 0) {
|
|
1779
|
+
var _item$reject2;
|
|
1780
|
+
(_item$reject2 = item.reject) === null || _item$reject2 === void 0 || _item$reject2.call(item, new Error("Input is too big for a single dispatch"));
|
|
1781
|
+
index++;
|
|
1782
|
+
continue;
|
|
1783
|
+
}
|
|
1784
|
+
groupedItems.push([]);
|
|
1785
|
+
}
|
|
1786
|
+
return groupedItems;
|
|
1787
|
+
}
|
|
1788
|
+
function dispatch() {
|
|
1789
|
+
const groupedItems = groupItems(pendingItems);
|
|
1790
|
+
destroyTimerAndPendingItems();
|
|
1791
|
+
for (const items of groupedItems) {
|
|
1792
|
+
if (!items.length) continue;
|
|
1793
|
+
const batch = { items };
|
|
1794
|
+
for (const item of items) item.batch = batch;
|
|
1795
|
+
const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));
|
|
1796
|
+
promise.then(async (result) => {
|
|
1797
|
+
await Promise.all(result.map(async (valueOrPromise, index) => {
|
|
1798
|
+
const item = batch.items[index];
|
|
1799
|
+
try {
|
|
1800
|
+
var _item$resolve;
|
|
1801
|
+
const value = await Promise.resolve(valueOrPromise);
|
|
1802
|
+
(_item$resolve = item.resolve) === null || _item$resolve === void 0 || _item$resolve.call(item, value);
|
|
1803
|
+
} catch (cause) {
|
|
1804
|
+
var _item$reject3;
|
|
1805
|
+
(_item$reject3 = item.reject) === null || _item$reject3 === void 0 || _item$reject3.call(item, cause);
|
|
1806
|
+
}
|
|
1807
|
+
item.batch = null;
|
|
1808
|
+
item.reject = null;
|
|
1809
|
+
item.resolve = null;
|
|
1810
|
+
}));
|
|
1811
|
+
for (const item of batch.items) {
|
|
1812
|
+
var _item$reject4;
|
|
1813
|
+
(_item$reject4 = item.reject) === null || _item$reject4 === void 0 || _item$reject4.call(item, new Error("Missing result"));
|
|
1814
|
+
item.batch = null;
|
|
1815
|
+
}
|
|
1816
|
+
}).catch((cause) => {
|
|
1817
|
+
for (const item of batch.items) {
|
|
1818
|
+
var _item$reject5;
|
|
1819
|
+
(_item$reject5 = item.reject) === null || _item$reject5 === void 0 || _item$reject5.call(item, cause);
|
|
1820
|
+
item.batch = null;
|
|
1821
|
+
}
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
function load(key) {
|
|
1826
|
+
var _dispatchTimer;
|
|
1827
|
+
const item = {
|
|
1828
|
+
aborted: false,
|
|
1829
|
+
key,
|
|
1830
|
+
batch: null,
|
|
1831
|
+
resolve: throwFatalError,
|
|
1832
|
+
reject: throwFatalError
|
|
1833
|
+
};
|
|
1834
|
+
const promise = new Promise((resolve, reject) => {
|
|
1835
|
+
var _pendingItems;
|
|
1836
|
+
item.reject = reject;
|
|
1837
|
+
item.resolve = resolve;
|
|
1838
|
+
(_pendingItems = pendingItems) !== null && _pendingItems !== void 0 || (pendingItems = []);
|
|
1839
|
+
pendingItems.push(item);
|
|
1840
|
+
});
|
|
1841
|
+
(_dispatchTimer = dispatchTimer) !== null && _dispatchTimer !== void 0 || (dispatchTimer = setTimeout(dispatch));
|
|
1842
|
+
return promise;
|
|
1843
|
+
}
|
|
1844
|
+
return { load };
|
|
1845
|
+
}
|
|
1846
|
+
function allAbortSignals(...signals) {
|
|
1847
|
+
const ac = new AbortController();
|
|
1848
|
+
const count = signals.length;
|
|
1849
|
+
let abortedCount = 0;
|
|
1850
|
+
const onAbort = () => {
|
|
1851
|
+
if (++abortedCount === count) ac.abort();
|
|
1852
|
+
};
|
|
1853
|
+
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) onAbort();
|
|
1854
|
+
else signal === null || signal === void 0 || signal.addEventListener("abort", onAbort, { once: true });
|
|
1855
|
+
return ac.signal;
|
|
1856
|
+
}
|
|
1857
|
+
function raceAbortSignals(...signals) {
|
|
1858
|
+
const ac = new AbortController();
|
|
1859
|
+
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) ac.abort();
|
|
1860
|
+
else signal === null || signal === void 0 || signal.addEventListener("abort", () => ac.abort(), { once: true });
|
|
1861
|
+
return ac.signal;
|
|
1862
|
+
}
|
|
1863
|
+
function abortSignalToPromise(signal) {
|
|
1864
|
+
return new Promise((_, reject) => {
|
|
1865
|
+
if (signal.aborted) {
|
|
1866
|
+
reject(signal.reason);
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
signal.addEventListener("abort", () => {
|
|
1870
|
+
reject(signal.reason);
|
|
1871
|
+
}, { once: true });
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
var import_objectSpread27 = __toESM(require_objectSpread2(), 1);
|
|
1875
|
+
function httpBatchLink(opts) {
|
|
1876
|
+
var _opts$maxURLLength, _opts$maxItems;
|
|
1877
|
+
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
1878
|
+
const maxURLLength = (_opts$maxURLLength = opts.maxURLLength) !== null && _opts$maxURLLength !== void 0 ? _opts$maxURLLength : Infinity;
|
|
1879
|
+
const maxItems = (_opts$maxItems = opts.maxItems) !== null && _opts$maxItems !== void 0 ? _opts$maxItems : Infinity;
|
|
1880
|
+
return () => {
|
|
1881
|
+
const batchLoader = (type) => {
|
|
1882
|
+
return {
|
|
1883
|
+
validate(batchOps) {
|
|
1884
|
+
if (maxURLLength === Infinity && maxItems === Infinity) return true;
|
|
1885
|
+
if (batchOps.length > maxItems) return false;
|
|
1886
|
+
const path = batchOps.map((op) => op.path).join(",");
|
|
1887
|
+
const inputs = batchOps.map((op) => op.input);
|
|
1888
|
+
const url = getUrl((0, import_objectSpread27.default)((0, import_objectSpread27.default)({}, resolvedOpts), {}, {
|
|
1889
|
+
type,
|
|
1890
|
+
path,
|
|
1891
|
+
inputs,
|
|
1892
|
+
signal: null
|
|
1893
|
+
}));
|
|
1894
|
+
return url.length <= maxURLLength;
|
|
1895
|
+
},
|
|
1896
|
+
async fetch(batchOps) {
|
|
1897
|
+
const path = batchOps.map((op) => op.path).join(",");
|
|
1898
|
+
const inputs = batchOps.map((op) => op.input);
|
|
1899
|
+
const signal = allAbortSignals(...batchOps.map((op) => op.signal));
|
|
1900
|
+
const res = await jsonHttpRequester((0, import_objectSpread27.default)((0, import_objectSpread27.default)({}, resolvedOpts), {}, {
|
|
1901
|
+
path,
|
|
1902
|
+
inputs,
|
|
1903
|
+
type,
|
|
1904
|
+
headers() {
|
|
1905
|
+
if (!opts.headers) return {};
|
|
1906
|
+
if (typeof opts.headers === "function") return opts.headers({ opList: batchOps });
|
|
1907
|
+
return opts.headers;
|
|
1908
|
+
},
|
|
1909
|
+
signal
|
|
1910
|
+
}));
|
|
1911
|
+
const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(() => res.json);
|
|
1912
|
+
const result = resJSON.map((item) => ({
|
|
1913
|
+
meta: res.meta,
|
|
1914
|
+
json: item
|
|
1915
|
+
}));
|
|
1916
|
+
return result;
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1919
|
+
};
|
|
1920
|
+
const query = dataLoader(batchLoader("query"));
|
|
1921
|
+
const mutation = dataLoader(batchLoader("mutation"));
|
|
1922
|
+
const loaders = {
|
|
1923
|
+
query,
|
|
1924
|
+
mutation
|
|
1925
|
+
};
|
|
1926
|
+
return ({ op }) => {
|
|
1927
|
+
return observable((observer) => {
|
|
1928
|
+
if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
1929
|
+
const loader = loaders[op.type];
|
|
1930
|
+
const promise = loader.load(op);
|
|
1931
|
+
let _res = void 0;
|
|
1932
|
+
promise.then((res) => {
|
|
1933
|
+
_res = res;
|
|
1934
|
+
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
1935
|
+
if (!transformed.ok) {
|
|
1936
|
+
observer.error(TRPCClientError.from(transformed.error, { meta: res.meta }));
|
|
1937
|
+
return;
|
|
1938
|
+
}
|
|
1939
|
+
observer.next({
|
|
1940
|
+
context: res.meta,
|
|
1941
|
+
result: transformed.result
|
|
1942
|
+
});
|
|
1943
|
+
observer.complete();
|
|
1944
|
+
}).catch((err) => {
|
|
1945
|
+
observer.error(TRPCClientError.from(err, { meta: _res === null || _res === void 0 ? void 0 : _res.meta }));
|
|
1946
|
+
});
|
|
1947
|
+
return () => {
|
|
1948
|
+
};
|
|
1949
|
+
});
|
|
1950
|
+
};
|
|
1951
|
+
};
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
// ../../node_modules/@trpc/client/dist/loggerLink-ineCN1PO.mjs
|
|
1955
|
+
var import_objectSpread28 = __toESM(require_objectSpread2(), 1);
|
|
1956
|
+
function isFormData2(value) {
|
|
1957
|
+
if (typeof FormData === "undefined") return false;
|
|
1958
|
+
return value instanceof FormData;
|
|
1959
|
+
}
|
|
1960
|
+
var palettes = {
|
|
1961
|
+
css: {
|
|
1962
|
+
query: ["72e3ff", "3fb0d8"],
|
|
1963
|
+
mutation: ["c5a3fc", "904dfc"],
|
|
1964
|
+
subscription: ["ff49e1", "d83fbe"]
|
|
1965
|
+
},
|
|
1966
|
+
ansi: {
|
|
1967
|
+
regular: {
|
|
1968
|
+
query: ["\x1B[30;46m", "\x1B[97;46m"],
|
|
1969
|
+
mutation: ["\x1B[30;45m", "\x1B[97;45m"],
|
|
1970
|
+
subscription: ["\x1B[30;42m", "\x1B[97;42m"]
|
|
1971
|
+
},
|
|
1972
|
+
bold: {
|
|
1973
|
+
query: ["\x1B[1;30;46m", "\x1B[1;97;46m"],
|
|
1974
|
+
mutation: ["\x1B[1;30;45m", "\x1B[1;97;45m"],
|
|
1975
|
+
subscription: ["\x1B[1;30;42m", "\x1B[1;97;42m"]
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
function constructPartsAndArgs(opts) {
|
|
1980
|
+
const { direction, type, withContext, path, id, input } = opts;
|
|
1981
|
+
const parts = [];
|
|
1982
|
+
const args = [];
|
|
1983
|
+
if (opts.colorMode === "none") parts.push(direction === "up" ? ">>" : "<<", type, `#${id}`, path);
|
|
1984
|
+
else if (opts.colorMode === "ansi") {
|
|
1985
|
+
const [lightRegular, darkRegular] = palettes.ansi.regular[type];
|
|
1986
|
+
const [lightBold, darkBold] = palettes.ansi.bold[type];
|
|
1987
|
+
const reset = "\x1B[0m";
|
|
1988
|
+
parts.push(direction === "up" ? lightRegular : darkRegular, direction === "up" ? ">>" : "<<", type, direction === "up" ? lightBold : darkBold, `#${id}`, path, reset);
|
|
1989
|
+
} else {
|
|
1990
|
+
const [light, dark] = palettes.css[type];
|
|
1991
|
+
const css = `
|
|
1992
|
+
background-color: #${direction === "up" ? light : dark};
|
|
1993
|
+
color: ${direction === "up" ? "black" : "white"};
|
|
1994
|
+
padding: 2px;
|
|
1995
|
+
`;
|
|
1996
|
+
parts.push("%c", direction === "up" ? ">>" : "<<", type, `#${id}`, `%c${path}%c`, "%O");
|
|
1997
|
+
args.push(css, `${css}; font-weight: bold;`, `${css}; font-weight: normal;`);
|
|
1998
|
+
}
|
|
1999
|
+
if (direction === "up") args.push(withContext ? {
|
|
2000
|
+
input,
|
|
2001
|
+
context: opts.context
|
|
2002
|
+
} : { input });
|
|
2003
|
+
else args.push((0, import_objectSpread28.default)({
|
|
2004
|
+
input,
|
|
2005
|
+
result: opts.result,
|
|
2006
|
+
elapsedMs: opts.elapsedMs
|
|
2007
|
+
}, withContext && { context: opts.context }));
|
|
2008
|
+
return {
|
|
2009
|
+
parts,
|
|
2010
|
+
args
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
var defaultLogger = ({ c = console, colorMode = "css", withContext }) => (props) => {
|
|
2014
|
+
const rawInput = props.input;
|
|
2015
|
+
const input = isFormData2(rawInput) ? Object.fromEntries(rawInput) : rawInput;
|
|
2016
|
+
const { parts, args } = constructPartsAndArgs((0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, props), {}, {
|
|
2017
|
+
colorMode,
|
|
2018
|
+
input,
|
|
2019
|
+
withContext
|
|
2020
|
+
}));
|
|
2021
|
+
const fn = props.direction === "down" && props.result && (props.result instanceof Error || "error" in props.result.result && props.result.result.error) ? "error" : "log";
|
|
2022
|
+
c[fn].apply(null, [parts.join(" ")].concat(args));
|
|
2023
|
+
};
|
|
2024
|
+
function loggerLink(opts = {}) {
|
|
2025
|
+
var _opts$colorMode, _opts$withContext;
|
|
2026
|
+
const { enabled = () => true } = opts;
|
|
2027
|
+
const colorMode = (_opts$colorMode = opts.colorMode) !== null && _opts$colorMode !== void 0 ? _opts$colorMode : typeof window === "undefined" ? "ansi" : "css";
|
|
2028
|
+
const withContext = (_opts$withContext = opts.withContext) !== null && _opts$withContext !== void 0 ? _opts$withContext : colorMode === "css";
|
|
2029
|
+
const { logger = defaultLogger({
|
|
2030
|
+
c: opts.console,
|
|
2031
|
+
colorMode,
|
|
2032
|
+
withContext
|
|
2033
|
+
}) } = opts;
|
|
2034
|
+
return () => {
|
|
2035
|
+
return ({ op, next }) => {
|
|
2036
|
+
return observable((observer) => {
|
|
2037
|
+
if (enabled((0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, op), {}, { direction: "up" }))) logger((0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, op), {}, { direction: "up" }));
|
|
2038
|
+
const requestStartTime = Date.now();
|
|
2039
|
+
function logResult(result) {
|
|
2040
|
+
const elapsedMs = Date.now() - requestStartTime;
|
|
2041
|
+
if (enabled((0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, op), {}, {
|
|
2042
|
+
direction: "down",
|
|
2043
|
+
result
|
|
2044
|
+
}))) logger((0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, op), {}, {
|
|
2045
|
+
direction: "down",
|
|
2046
|
+
elapsedMs,
|
|
2047
|
+
result
|
|
2048
|
+
}));
|
|
2049
|
+
}
|
|
2050
|
+
return next(op).pipe(tap({
|
|
2051
|
+
next(result) {
|
|
2052
|
+
logResult(result);
|
|
2053
|
+
},
|
|
2054
|
+
error(result) {
|
|
2055
|
+
logResult(result);
|
|
2056
|
+
}
|
|
2057
|
+
})).subscribe(observer);
|
|
2058
|
+
});
|
|
2059
|
+
};
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
// ../../node_modules/@trpc/client/dist/wsLink-DSf4KOdW.mjs
|
|
2064
|
+
var jsonEncoder = {
|
|
2065
|
+
encode: (data) => JSON.stringify(data),
|
|
2066
|
+
decode: (data) => {
|
|
2067
|
+
if (typeof data !== "string") throw new Error("jsonEncoder received binary data. JSON uses text frames. Use a binary encoder for binary data.");
|
|
2068
|
+
return JSON.parse(data);
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
var lazyDefaults = {
|
|
2072
|
+
enabled: false,
|
|
2073
|
+
closeMs: 0
|
|
2074
|
+
};
|
|
2075
|
+
var keepAliveDefaults = {
|
|
2076
|
+
enabled: false,
|
|
2077
|
+
pongTimeoutMs: 1e3,
|
|
2078
|
+
intervalMs: 5e3
|
|
2079
|
+
};
|
|
2080
|
+
var exponentialBackoff = (attemptIndex) => {
|
|
2081
|
+
return attemptIndex === 0 ? 0 : Math.min(1e3 * 2 ** attemptIndex, 3e4);
|
|
2082
|
+
};
|
|
2083
|
+
var resultOf = (value, ...args) => {
|
|
2084
|
+
return typeof value === "function" ? value(...args) : value;
|
|
2085
|
+
};
|
|
2086
|
+
var import_defineProperty$3 = __toESM(require_defineProperty(), 1);
|
|
2087
|
+
var TRPCWebSocketClosedError = class TRPCWebSocketClosedError2 extends Error {
|
|
2088
|
+
constructor(opts) {
|
|
2089
|
+
super(opts.message, { cause: opts.cause });
|
|
2090
|
+
this.name = "TRPCWebSocketClosedError";
|
|
2091
|
+
Object.setPrototypeOf(this, TRPCWebSocketClosedError2.prototype);
|
|
2092
|
+
}
|
|
2093
|
+
};
|
|
2094
|
+
var ResettableTimeout = class {
|
|
2095
|
+
constructor(onTimeout, timeoutMs) {
|
|
2096
|
+
this.onTimeout = onTimeout;
|
|
2097
|
+
this.timeoutMs = timeoutMs;
|
|
2098
|
+
(0, import_defineProperty$3.default)(this, "timeout", void 0);
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Resets the current timeout, restarting it with the same duration.
|
|
2102
|
+
* Does nothing if no timeout is active.
|
|
2103
|
+
*/
|
|
2104
|
+
reset() {
|
|
2105
|
+
if (!this.timeout) return;
|
|
2106
|
+
clearTimeout(this.timeout);
|
|
2107
|
+
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
2108
|
+
}
|
|
2109
|
+
start() {
|
|
2110
|
+
clearTimeout(this.timeout);
|
|
2111
|
+
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
2112
|
+
}
|
|
2113
|
+
stop() {
|
|
2114
|
+
clearTimeout(this.timeout);
|
|
2115
|
+
this.timeout = void 0;
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
function withResolvers2() {
|
|
2119
|
+
let resolve;
|
|
2120
|
+
let reject;
|
|
2121
|
+
const promise = new Promise((res, rej) => {
|
|
2122
|
+
resolve = res;
|
|
2123
|
+
reject = rej;
|
|
2124
|
+
});
|
|
2125
|
+
return {
|
|
2126
|
+
promise,
|
|
2127
|
+
resolve,
|
|
2128
|
+
reject
|
|
2129
|
+
};
|
|
2130
|
+
}
|
|
2131
|
+
async function prepareUrl(urlOptions) {
|
|
2132
|
+
const url = await resultOf(urlOptions.url);
|
|
2133
|
+
if (!urlOptions.connectionParams) return url;
|
|
2134
|
+
const prefix = url.includes("?") ? "&" : "?";
|
|
2135
|
+
const connectionParams = `${prefix}connectionParams=1`;
|
|
2136
|
+
return url + connectionParams;
|
|
2137
|
+
}
|
|
2138
|
+
async function buildConnectionMessage(connectionParams, encoder) {
|
|
2139
|
+
const message = {
|
|
2140
|
+
method: "connectionParams",
|
|
2141
|
+
data: await resultOf(connectionParams)
|
|
2142
|
+
};
|
|
2143
|
+
return encoder.encode(message);
|
|
2144
|
+
}
|
|
2145
|
+
var import_defineProperty$2 = __toESM(require_defineProperty(), 1);
|
|
2146
|
+
var RequestManager = class {
|
|
2147
|
+
constructor() {
|
|
2148
|
+
(0, import_defineProperty$2.default)(this, "outgoingRequests", new Array());
|
|
2149
|
+
(0, import_defineProperty$2.default)(this, "pendingRequests", {});
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* Registers a new request by adding it to the outgoing queue and setting up
|
|
2153
|
+
* callbacks for lifecycle events such as completion or error.
|
|
2154
|
+
*
|
|
2155
|
+
* @param message - The outgoing message to be sent.
|
|
2156
|
+
* @param callbacks - Callback functions to observe the request's state.
|
|
2157
|
+
* @returns A cleanup function to manually remove the request.
|
|
2158
|
+
*/
|
|
2159
|
+
register(message, callbacks) {
|
|
2160
|
+
const { promise: end, resolve } = withResolvers2();
|
|
2161
|
+
this.outgoingRequests.push({
|
|
2162
|
+
id: String(message.id),
|
|
2163
|
+
message,
|
|
2164
|
+
end,
|
|
2165
|
+
callbacks: {
|
|
2166
|
+
next: callbacks.next,
|
|
2167
|
+
complete: () => {
|
|
2168
|
+
callbacks.complete();
|
|
2169
|
+
resolve();
|
|
2170
|
+
},
|
|
2171
|
+
error: (e) => {
|
|
2172
|
+
callbacks.error(e);
|
|
2173
|
+
resolve();
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
});
|
|
2177
|
+
return () => {
|
|
2178
|
+
this.delete(message.id);
|
|
2179
|
+
callbacks.complete();
|
|
2180
|
+
resolve();
|
|
2181
|
+
};
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Deletes a request from both the outgoing and pending collections, if it exists.
|
|
2185
|
+
*/
|
|
2186
|
+
delete(messageId) {
|
|
2187
|
+
if (messageId === null) return;
|
|
2188
|
+
this.outgoingRequests = this.outgoingRequests.filter(({ id }) => id !== String(messageId));
|
|
2189
|
+
delete this.pendingRequests[String(messageId)];
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* Moves all outgoing requests to the pending state and clears the outgoing queue.
|
|
2193
|
+
*
|
|
2194
|
+
* The caller is expected to handle the actual sending of the requests
|
|
2195
|
+
* (e.g., sending them over the network) after this method is called.
|
|
2196
|
+
*
|
|
2197
|
+
* @returns The list of requests that were transitioned to the pending state.
|
|
2198
|
+
*/
|
|
2199
|
+
flush() {
|
|
2200
|
+
const requests = this.outgoingRequests;
|
|
2201
|
+
this.outgoingRequests = [];
|
|
2202
|
+
for (const request of requests) this.pendingRequests[request.id] = request;
|
|
2203
|
+
return requests;
|
|
2204
|
+
}
|
|
2205
|
+
/**
|
|
2206
|
+
* Retrieves all currently pending requests, which are in flight awaiting responses
|
|
2207
|
+
* or handling ongoing subscriptions.
|
|
2208
|
+
*/
|
|
2209
|
+
getPendingRequests() {
|
|
2210
|
+
return Object.values(this.pendingRequests);
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Retrieves a specific pending request by its message ID.
|
|
2214
|
+
*/
|
|
2215
|
+
getPendingRequest(messageId) {
|
|
2216
|
+
if (messageId === null) return null;
|
|
2217
|
+
return this.pendingRequests[String(messageId)];
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Retrieves all outgoing requests, which are waiting to be sent.
|
|
2221
|
+
*/
|
|
2222
|
+
getOutgoingRequests() {
|
|
2223
|
+
return this.outgoingRequests;
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Retrieves all requests, both outgoing and pending, with their respective states.
|
|
2227
|
+
*
|
|
2228
|
+
* @returns An array of all requests with their state ("outgoing" or "pending").
|
|
2229
|
+
*/
|
|
2230
|
+
getRequests() {
|
|
2231
|
+
return [...this.getOutgoingRequests().map((request) => ({
|
|
2232
|
+
state: "outgoing",
|
|
2233
|
+
message: request.message,
|
|
2234
|
+
end: request.end,
|
|
2235
|
+
callbacks: request.callbacks
|
|
2236
|
+
})), ...this.getPendingRequests().map((request) => ({
|
|
2237
|
+
state: "pending",
|
|
2238
|
+
message: request.message,
|
|
2239
|
+
end: request.end,
|
|
2240
|
+
callbacks: request.callbacks
|
|
2241
|
+
}))];
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* Checks if there are any pending requests, including ongoing subscriptions.
|
|
2245
|
+
*/
|
|
2246
|
+
hasPendingRequests() {
|
|
2247
|
+
return this.getPendingRequests().length > 0;
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Checks if there are any pending subscriptions
|
|
2251
|
+
*/
|
|
2252
|
+
hasPendingSubscriptions() {
|
|
2253
|
+
return this.getPendingRequests().some((request) => request.message.method === "subscription");
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Checks if there are any outgoing requests waiting to be sent.
|
|
2257
|
+
*/
|
|
2258
|
+
hasOutgoingRequests() {
|
|
2259
|
+
return this.outgoingRequests.length > 0;
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
var import_defineProperty$1 = __toESM(require_defineProperty(), 1);
|
|
2263
|
+
function asyncWsOpen(ws) {
|
|
2264
|
+
const { promise, resolve, reject } = withResolvers2();
|
|
2265
|
+
ws.addEventListener("open", () => {
|
|
2266
|
+
ws.removeEventListener("error", reject);
|
|
2267
|
+
resolve();
|
|
2268
|
+
});
|
|
2269
|
+
ws.addEventListener("error", reject);
|
|
2270
|
+
return promise;
|
|
2271
|
+
}
|
|
2272
|
+
function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
|
|
2273
|
+
let pingTimeout;
|
|
2274
|
+
let pongTimeout;
|
|
2275
|
+
function start() {
|
|
2276
|
+
pingTimeout = setTimeout(() => {
|
|
2277
|
+
ws.send("PING");
|
|
2278
|
+
pongTimeout = setTimeout(() => {
|
|
2279
|
+
ws.close();
|
|
2280
|
+
}, pongTimeoutMs);
|
|
2281
|
+
}, intervalMs);
|
|
2282
|
+
}
|
|
2283
|
+
function reset() {
|
|
2284
|
+
clearTimeout(pingTimeout);
|
|
2285
|
+
start();
|
|
2286
|
+
}
|
|
2287
|
+
function pong() {
|
|
2288
|
+
clearTimeout(pongTimeout);
|
|
2289
|
+
reset();
|
|
2290
|
+
}
|
|
2291
|
+
ws.addEventListener("open", start);
|
|
2292
|
+
ws.addEventListener("message", ({ data }) => {
|
|
2293
|
+
clearTimeout(pingTimeout);
|
|
2294
|
+
start();
|
|
2295
|
+
if (data === "PONG") pong();
|
|
2296
|
+
});
|
|
2297
|
+
ws.addEventListener("close", () => {
|
|
2298
|
+
clearTimeout(pingTimeout);
|
|
2299
|
+
clearTimeout(pongTimeout);
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
var WsConnection = class WsConnection2 {
|
|
2303
|
+
constructor(opts) {
|
|
2304
|
+
var _opts$WebSocketPonyfi;
|
|
2305
|
+
(0, import_defineProperty$1.default)(this, "id", ++WsConnection2.connectCount);
|
|
2306
|
+
(0, import_defineProperty$1.default)(this, "WebSocketPonyfill", void 0);
|
|
2307
|
+
(0, import_defineProperty$1.default)(this, "urlOptions", void 0);
|
|
2308
|
+
(0, import_defineProperty$1.default)(this, "keepAliveOpts", void 0);
|
|
2309
|
+
(0, import_defineProperty$1.default)(this, "encoder", void 0);
|
|
2310
|
+
(0, import_defineProperty$1.default)(this, "wsObservable", behaviorSubject(null));
|
|
2311
|
+
(0, import_defineProperty$1.default)(this, "openPromise", null);
|
|
2312
|
+
this.WebSocketPonyfill = (_opts$WebSocketPonyfi = opts.WebSocketPonyfill) !== null && _opts$WebSocketPonyfi !== void 0 ? _opts$WebSocketPonyfi : WebSocket;
|
|
2313
|
+
if (!this.WebSocketPonyfill) throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill");
|
|
2314
|
+
this.urlOptions = opts.urlOptions;
|
|
2315
|
+
this.keepAliveOpts = opts.keepAlive;
|
|
2316
|
+
this.encoder = opts.encoder;
|
|
2317
|
+
}
|
|
2318
|
+
get ws() {
|
|
2319
|
+
return this.wsObservable.get();
|
|
2320
|
+
}
|
|
2321
|
+
set ws(ws) {
|
|
2322
|
+
this.wsObservable.next(ws);
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Checks if the WebSocket connection is open and ready to communicate.
|
|
2326
|
+
*/
|
|
2327
|
+
isOpen() {
|
|
2328
|
+
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise;
|
|
2329
|
+
}
|
|
2330
|
+
/**
|
|
2331
|
+
* Checks if the WebSocket connection is closed or in the process of closing.
|
|
2332
|
+
*/
|
|
2333
|
+
isClosed() {
|
|
2334
|
+
return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
|
|
2335
|
+
}
|
|
2336
|
+
async open() {
|
|
2337
|
+
var _this = this;
|
|
2338
|
+
if (_this.openPromise) return _this.openPromise;
|
|
2339
|
+
_this.id = ++WsConnection2.connectCount;
|
|
2340
|
+
const wsPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url));
|
|
2341
|
+
_this.openPromise = wsPromise.then(async (ws) => {
|
|
2342
|
+
_this.ws = ws;
|
|
2343
|
+
ws.binaryType = "arraybuffer";
|
|
2344
|
+
ws.addEventListener("message", function({ data }) {
|
|
2345
|
+
if (data === "PING") this.send("PONG");
|
|
2346
|
+
});
|
|
2347
|
+
if (_this.keepAliveOpts.enabled) setupPingInterval(ws, _this.keepAliveOpts);
|
|
2348
|
+
ws.addEventListener("close", () => {
|
|
2349
|
+
if (_this.ws === ws) _this.ws = null;
|
|
2350
|
+
});
|
|
2351
|
+
await asyncWsOpen(ws);
|
|
2352
|
+
if (_this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(_this.urlOptions.connectionParams, _this.encoder));
|
|
2353
|
+
});
|
|
2354
|
+
try {
|
|
2355
|
+
await _this.openPromise;
|
|
2356
|
+
} finally {
|
|
2357
|
+
_this.openPromise = null;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
/**
|
|
2361
|
+
* Closes the WebSocket connection gracefully.
|
|
2362
|
+
* Waits for any ongoing open operation to complete before closing.
|
|
2363
|
+
*/
|
|
2364
|
+
async close() {
|
|
2365
|
+
var _this2 = this;
|
|
2366
|
+
try {
|
|
2367
|
+
await _this2.openPromise;
|
|
2368
|
+
} finally {
|
|
2369
|
+
var _this$ws;
|
|
2370
|
+
(_this$ws = _this2.ws) === null || _this$ws === void 0 || _this$ws.close();
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
(0, import_defineProperty$1.default)(WsConnection, "connectCount", 0);
|
|
2375
|
+
function backwardCompatibility(connection) {
|
|
2376
|
+
if (connection.isOpen()) return {
|
|
2377
|
+
id: connection.id,
|
|
2378
|
+
state: "open",
|
|
2379
|
+
ws: connection.ws
|
|
2380
|
+
};
|
|
2381
|
+
if (connection.isClosed()) return {
|
|
2382
|
+
id: connection.id,
|
|
2383
|
+
state: "closed",
|
|
2384
|
+
ws: connection.ws
|
|
2385
|
+
};
|
|
2386
|
+
if (!connection.ws) return null;
|
|
2387
|
+
return {
|
|
2388
|
+
id: connection.id,
|
|
2389
|
+
state: "connecting",
|
|
2390
|
+
ws: connection.ws
|
|
2391
|
+
};
|
|
2392
|
+
}
|
|
2393
|
+
var import_defineProperty4 = __toESM(require_defineProperty(), 1);
|
|
2394
|
+
var import_objectSpread29 = __toESM(require_objectSpread2(), 1);
|
|
2395
|
+
var WsClient = class {
|
|
2396
|
+
constructor(opts) {
|
|
2397
|
+
var _opts$experimental_en, _opts$retryDelayMs;
|
|
2398
|
+
(0, import_defineProperty4.default)(this, "connectionState", void 0);
|
|
2399
|
+
(0, import_defineProperty4.default)(this, "allowReconnect", false);
|
|
2400
|
+
(0, import_defineProperty4.default)(this, "requestManager", new RequestManager());
|
|
2401
|
+
(0, import_defineProperty4.default)(this, "activeConnection", void 0);
|
|
2402
|
+
(0, import_defineProperty4.default)(this, "reconnectRetryDelay", void 0);
|
|
2403
|
+
(0, import_defineProperty4.default)(this, "inactivityTimeout", void 0);
|
|
2404
|
+
(0, import_defineProperty4.default)(this, "callbacks", void 0);
|
|
2405
|
+
(0, import_defineProperty4.default)(this, "lazyMode", void 0);
|
|
2406
|
+
(0, import_defineProperty4.default)(this, "encoder", void 0);
|
|
2407
|
+
(0, import_defineProperty4.default)(this, "reconnecting", null);
|
|
2408
|
+
this.encoder = (_opts$experimental_en = opts.experimental_encoder) !== null && _opts$experimental_en !== void 0 ? _opts$experimental_en : jsonEncoder;
|
|
2409
|
+
this.callbacks = {
|
|
2410
|
+
onOpen: opts.onOpen,
|
|
2411
|
+
onClose: opts.onClose,
|
|
2412
|
+
onError: opts.onError
|
|
2413
|
+
};
|
|
2414
|
+
const lazyOptions = (0, import_objectSpread29.default)((0, import_objectSpread29.default)({}, lazyDefaults), opts.lazy);
|
|
2415
|
+
this.inactivityTimeout = new ResettableTimeout(() => {
|
|
2416
|
+
if (this.requestManager.hasOutgoingRequests() || this.requestManager.hasPendingRequests()) {
|
|
2417
|
+
this.inactivityTimeout.reset();
|
|
2418
|
+
return;
|
|
2419
|
+
}
|
|
2420
|
+
this.close().catch(() => null);
|
|
2421
|
+
}, lazyOptions.closeMs);
|
|
2422
|
+
this.activeConnection = new WsConnection({
|
|
2423
|
+
WebSocketPonyfill: opts.WebSocket,
|
|
2424
|
+
urlOptions: opts,
|
|
2425
|
+
keepAlive: (0, import_objectSpread29.default)((0, import_objectSpread29.default)({}, keepAliveDefaults), opts.keepAlive),
|
|
2426
|
+
encoder: this.encoder
|
|
2427
|
+
});
|
|
2428
|
+
this.activeConnection.wsObservable.subscribe({ next: (ws) => {
|
|
2429
|
+
if (!ws) return;
|
|
2430
|
+
this.setupWebSocketListeners(ws);
|
|
2431
|
+
} });
|
|
2432
|
+
this.reconnectRetryDelay = (_opts$retryDelayMs = opts.retryDelayMs) !== null && _opts$retryDelayMs !== void 0 ? _opts$retryDelayMs : exponentialBackoff;
|
|
2433
|
+
this.lazyMode = lazyOptions.enabled;
|
|
2434
|
+
this.connectionState = behaviorSubject({
|
|
2435
|
+
type: "state",
|
|
2436
|
+
state: lazyOptions.enabled ? "idle" : "connecting",
|
|
2437
|
+
error: null
|
|
2438
|
+
});
|
|
2439
|
+
if (!this.lazyMode) this.open().catch(() => null);
|
|
2440
|
+
}
|
|
2441
|
+
/**
|
|
2442
|
+
* Opens the WebSocket connection. Handles reconnection attempts and updates
|
|
2443
|
+
* the connection state accordingly.
|
|
2444
|
+
*/
|
|
2445
|
+
async open() {
|
|
2446
|
+
var _this = this;
|
|
2447
|
+
_this.allowReconnect = true;
|
|
2448
|
+
if (_this.connectionState.get().state === "idle") _this.connectionState.next({
|
|
2449
|
+
type: "state",
|
|
2450
|
+
state: "connecting",
|
|
2451
|
+
error: null
|
|
2452
|
+
});
|
|
2453
|
+
try {
|
|
2454
|
+
await _this.activeConnection.open();
|
|
2455
|
+
} catch (error) {
|
|
2456
|
+
_this.reconnect(new TRPCWebSocketClosedError({
|
|
2457
|
+
message: "Initialization error",
|
|
2458
|
+
cause: error
|
|
2459
|
+
}));
|
|
2460
|
+
return _this.reconnecting;
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Closes the WebSocket connection and stops managing requests.
|
|
2465
|
+
* Ensures all outgoing and pending requests are properly finalized.
|
|
2466
|
+
*/
|
|
2467
|
+
async close() {
|
|
2468
|
+
var _this2 = this;
|
|
2469
|
+
_this2.allowReconnect = false;
|
|
2470
|
+
_this2.inactivityTimeout.stop();
|
|
2471
|
+
const requestsToAwait = [];
|
|
2472
|
+
for (const request of _this2.requestManager.getRequests()) if (request.message.method === "subscription") request.callbacks.complete();
|
|
2473
|
+
else if (request.state === "outgoing") request.callbacks.error(TRPCClientError.from(new TRPCWebSocketClosedError({ message: "Closed before connection was established" })));
|
|
2474
|
+
else requestsToAwait.push(request.end);
|
|
2475
|
+
await Promise.all(requestsToAwait).catch(() => null);
|
|
2476
|
+
await _this2.activeConnection.close().catch(() => null);
|
|
2477
|
+
_this2.connectionState.next({
|
|
2478
|
+
type: "state",
|
|
2479
|
+
state: "idle",
|
|
2480
|
+
error: null
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
/**
|
|
2484
|
+
* Method to request the server.
|
|
2485
|
+
* Handles data transformation, batching of requests, and subscription lifecycle.
|
|
2486
|
+
*
|
|
2487
|
+
* @param op - The operation details including id, type, path, input and signal
|
|
2488
|
+
* @param transformer - Data transformer for serializing requests and deserializing responses
|
|
2489
|
+
* @param lastEventId - Optional ID of the last received event for subscriptions
|
|
2490
|
+
*
|
|
2491
|
+
* @returns An observable that emits operation results and handles cleanup
|
|
2492
|
+
*/
|
|
2493
|
+
request({ op: { id, type, path, input, signal }, transformer, lastEventId }) {
|
|
2494
|
+
return observable((observer) => {
|
|
2495
|
+
const abort = this.batchSend({
|
|
2496
|
+
id,
|
|
2497
|
+
method: type,
|
|
2498
|
+
params: {
|
|
2499
|
+
input: transformer.input.serialize(input),
|
|
2500
|
+
path,
|
|
2501
|
+
lastEventId
|
|
2502
|
+
}
|
|
2503
|
+
}, (0, import_objectSpread29.default)((0, import_objectSpread29.default)({}, observer), {}, { next(event) {
|
|
2504
|
+
const transformed = transformResult(event, transformer.output);
|
|
2505
|
+
if (!transformed.ok) {
|
|
2506
|
+
observer.error(TRPCClientError.from(transformed.error));
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2509
|
+
observer.next({ result: transformed.result });
|
|
2510
|
+
} }));
|
|
2511
|
+
return () => {
|
|
2512
|
+
abort();
|
|
2513
|
+
if (type === "subscription" && this.activeConnection.isOpen()) this.send({
|
|
2514
|
+
id,
|
|
2515
|
+
method: "subscription.stop"
|
|
2516
|
+
});
|
|
2517
|
+
signal === null || signal === void 0 || signal.removeEventListener("abort", abort);
|
|
2518
|
+
};
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
2521
|
+
get connection() {
|
|
2522
|
+
return backwardCompatibility(this.activeConnection);
|
|
2523
|
+
}
|
|
2524
|
+
reconnect(closedError) {
|
|
2525
|
+
var _this3 = this;
|
|
2526
|
+
this.connectionState.next({
|
|
2527
|
+
type: "state",
|
|
2528
|
+
state: "connecting",
|
|
2529
|
+
error: TRPCClientError.from(closedError)
|
|
2530
|
+
});
|
|
2531
|
+
if (this.reconnecting) return;
|
|
2532
|
+
const tryReconnect = async (attemptIndex) => {
|
|
2533
|
+
try {
|
|
2534
|
+
await sleep(_this3.reconnectRetryDelay(attemptIndex));
|
|
2535
|
+
if (_this3.allowReconnect) {
|
|
2536
|
+
await _this3.activeConnection.close();
|
|
2537
|
+
await _this3.activeConnection.open();
|
|
2538
|
+
if (_this3.requestManager.hasPendingRequests()) _this3.send(_this3.requestManager.getPendingRequests().map(({ message }) => message));
|
|
2539
|
+
}
|
|
2540
|
+
_this3.reconnecting = null;
|
|
2541
|
+
} catch (_unused) {
|
|
2542
|
+
await tryReconnect(attemptIndex + 1);
|
|
2543
|
+
}
|
|
2544
|
+
};
|
|
2545
|
+
this.reconnecting = tryReconnect(0);
|
|
2546
|
+
}
|
|
2547
|
+
setupWebSocketListeners(ws) {
|
|
2548
|
+
var _this4 = this;
|
|
2549
|
+
const handleCloseOrError = (cause) => {
|
|
2550
|
+
const reqs = this.requestManager.getPendingRequests();
|
|
2551
|
+
for (const { message, callbacks } of reqs) {
|
|
2552
|
+
if (message.method === "subscription") continue;
|
|
2553
|
+
callbacks.error(TRPCClientError.from(cause !== null && cause !== void 0 ? cause : new TRPCWebSocketClosedError({
|
|
2554
|
+
message: "WebSocket closed",
|
|
2555
|
+
cause
|
|
2556
|
+
})));
|
|
2557
|
+
this.requestManager.delete(message.id);
|
|
2558
|
+
}
|
|
2559
|
+
};
|
|
2560
|
+
ws.addEventListener("open", () => {
|
|
2561
|
+
run(async () => {
|
|
2562
|
+
var _this$callbacks$onOpe, _this$callbacks;
|
|
2563
|
+
if (_this4.lazyMode) _this4.inactivityTimeout.start();
|
|
2564
|
+
(_this$callbacks$onOpe = (_this$callbacks = _this4.callbacks).onOpen) === null || _this$callbacks$onOpe === void 0 || _this$callbacks$onOpe.call(_this$callbacks);
|
|
2565
|
+
_this4.connectionState.next({
|
|
2566
|
+
type: "state",
|
|
2567
|
+
state: "pending",
|
|
2568
|
+
error: null
|
|
2569
|
+
});
|
|
2570
|
+
}).catch((error) => {
|
|
2571
|
+
ws.close(3e3);
|
|
2572
|
+
handleCloseOrError(error);
|
|
2573
|
+
});
|
|
2574
|
+
});
|
|
2575
|
+
ws.addEventListener("message", ({ data }) => {
|
|
2576
|
+
this.inactivityTimeout.reset();
|
|
2577
|
+
if (["PING", "PONG"].includes(data)) return;
|
|
2578
|
+
const incomingMessage = this.encoder.decode(data);
|
|
2579
|
+
if ("method" in incomingMessage) {
|
|
2580
|
+
this.handleIncomingRequest(incomingMessage);
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2583
|
+
this.handleResponseMessage(incomingMessage);
|
|
2584
|
+
});
|
|
2585
|
+
ws.addEventListener("close", (event) => {
|
|
2586
|
+
var _this$callbacks$onClo, _this$callbacks2;
|
|
2587
|
+
handleCloseOrError(event);
|
|
2588
|
+
(_this$callbacks$onClo = (_this$callbacks2 = this.callbacks).onClose) === null || _this$callbacks$onClo === void 0 || _this$callbacks$onClo.call(_this$callbacks2, event);
|
|
2589
|
+
if (!this.lazyMode || this.requestManager.hasPendingSubscriptions()) this.reconnect(new TRPCWebSocketClosedError({
|
|
2590
|
+
message: "WebSocket closed",
|
|
2591
|
+
cause: event
|
|
2592
|
+
}));
|
|
2593
|
+
});
|
|
2594
|
+
ws.addEventListener("error", (event) => {
|
|
2595
|
+
var _this$callbacks$onErr, _this$callbacks3;
|
|
2596
|
+
handleCloseOrError(event);
|
|
2597
|
+
(_this$callbacks$onErr = (_this$callbacks3 = this.callbacks).onError) === null || _this$callbacks$onErr === void 0 || _this$callbacks$onErr.call(_this$callbacks3, event);
|
|
2598
|
+
this.reconnect(new TRPCWebSocketClosedError({
|
|
2599
|
+
message: "WebSocket closed",
|
|
2600
|
+
cause: event
|
|
2601
|
+
}));
|
|
2602
|
+
});
|
|
2603
|
+
}
|
|
2604
|
+
handleResponseMessage(message) {
|
|
2605
|
+
const request = this.requestManager.getPendingRequest(message.id);
|
|
2606
|
+
if (!request) return;
|
|
2607
|
+
request.callbacks.next(message);
|
|
2608
|
+
let completed = true;
|
|
2609
|
+
if ("result" in message && request.message.method === "subscription") {
|
|
2610
|
+
if (message.result.type === "data") request.message.params.lastEventId = message.result.id;
|
|
2611
|
+
if (message.result.type !== "stopped") completed = false;
|
|
2612
|
+
}
|
|
2613
|
+
if (completed) {
|
|
2614
|
+
request.callbacks.complete();
|
|
2615
|
+
this.requestManager.delete(message.id);
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
handleIncomingRequest(message) {
|
|
2619
|
+
if (message.method === "reconnect") this.reconnect(new TRPCWebSocketClosedError({ message: "Server requested reconnect" }));
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Sends a message or batch of messages directly to the server.
|
|
2623
|
+
*/
|
|
2624
|
+
send(messageOrMessages) {
|
|
2625
|
+
if (!this.activeConnection.isOpen()) throw new Error("Active connection is not open");
|
|
2626
|
+
const messages = messageOrMessages instanceof Array ? messageOrMessages : [messageOrMessages];
|
|
2627
|
+
this.activeConnection.ws.send(this.encoder.encode(messages.length === 1 ? messages[0] : messages));
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* Groups requests for batch sending.
|
|
2631
|
+
*
|
|
2632
|
+
* @returns A function to abort the batched request.
|
|
2633
|
+
*/
|
|
2634
|
+
batchSend(message, callbacks) {
|
|
2635
|
+
var _this5 = this;
|
|
2636
|
+
this.inactivityTimeout.reset();
|
|
2637
|
+
run(async () => {
|
|
2638
|
+
if (!_this5.activeConnection.isOpen()) await _this5.open();
|
|
2639
|
+
await sleep(0);
|
|
2640
|
+
if (!_this5.requestManager.hasOutgoingRequests()) return;
|
|
2641
|
+
_this5.send(_this5.requestManager.flush().map(({ message: message$1 }) => message$1));
|
|
2642
|
+
}).catch((err) => {
|
|
2643
|
+
this.requestManager.delete(message.id);
|
|
2644
|
+
callbacks.error(TRPCClientError.from(err));
|
|
2645
|
+
});
|
|
2646
|
+
return this.requestManager.register(message, callbacks);
|
|
2647
|
+
}
|
|
2648
|
+
};
|
|
2649
|
+
function createWSClient(opts) {
|
|
2650
|
+
return new WsClient(opts);
|
|
2651
|
+
}
|
|
2652
|
+
function wsLink(opts) {
|
|
2653
|
+
const { client } = opts;
|
|
2654
|
+
const transformer = getTransformer(opts.transformer);
|
|
2655
|
+
return () => {
|
|
2656
|
+
return ({ op }) => {
|
|
2657
|
+
return observable((observer) => {
|
|
2658
|
+
const connStateSubscription = op.type === "subscription" ? client.connectionState.subscribe({ next(result) {
|
|
2659
|
+
observer.next({
|
|
2660
|
+
result,
|
|
2661
|
+
context: op.context
|
|
2662
|
+
});
|
|
2663
|
+
} }) : null;
|
|
2664
|
+
const requestSubscription = client.request({
|
|
2665
|
+
op,
|
|
2666
|
+
transformer
|
|
2667
|
+
}).subscribe(observer);
|
|
2668
|
+
return () => {
|
|
2669
|
+
requestSubscription.unsubscribe();
|
|
2670
|
+
connStateSubscription === null || connStateSubscription === void 0 || connStateSubscription.unsubscribe();
|
|
2671
|
+
};
|
|
2672
|
+
});
|
|
2673
|
+
};
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
// ../../node_modules/@trpc/client/dist/index.mjs
|
|
2678
|
+
var import_defineProperty5 = __toESM(require_defineProperty(), 1);
|
|
2679
|
+
var import_objectSpread2$4 = __toESM(require_objectSpread2(), 1);
|
|
2680
|
+
var TRPCUntypedClient = class {
|
|
2681
|
+
constructor(opts) {
|
|
2682
|
+
(0, import_defineProperty5.default)(this, "links", void 0);
|
|
2683
|
+
(0, import_defineProperty5.default)(this, "runtime", void 0);
|
|
2684
|
+
(0, import_defineProperty5.default)(this, "requestId", void 0);
|
|
2685
|
+
this.requestId = 0;
|
|
2686
|
+
this.runtime = {};
|
|
2687
|
+
this.links = opts.links.map((link) => link(this.runtime));
|
|
2688
|
+
}
|
|
2689
|
+
$request(opts) {
|
|
2690
|
+
var _opts$context;
|
|
2691
|
+
const chain$ = createChain({
|
|
2692
|
+
links: this.links,
|
|
2693
|
+
op: (0, import_objectSpread2$4.default)((0, import_objectSpread2$4.default)({}, opts), {}, {
|
|
2694
|
+
context: (_opts$context = opts.context) !== null && _opts$context !== void 0 ? _opts$context : {},
|
|
2695
|
+
id: ++this.requestId
|
|
2696
|
+
})
|
|
2697
|
+
});
|
|
2698
|
+
return chain$.pipe(share());
|
|
2699
|
+
}
|
|
2700
|
+
async requestAsPromise(opts) {
|
|
2701
|
+
var _this = this;
|
|
2702
|
+
try {
|
|
2703
|
+
const req$ = _this.$request(opts);
|
|
2704
|
+
const envelope = await observableToPromise(req$);
|
|
2705
|
+
const data = envelope.result.data;
|
|
2706
|
+
return data;
|
|
2707
|
+
} catch (err) {
|
|
2708
|
+
throw TRPCClientError.from(err);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
query(path, input, opts) {
|
|
2712
|
+
return this.requestAsPromise({
|
|
2713
|
+
type: "query",
|
|
2714
|
+
path,
|
|
2715
|
+
input,
|
|
2716
|
+
context: opts === null || opts === void 0 ? void 0 : opts.context,
|
|
2717
|
+
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
mutation(path, input, opts) {
|
|
2721
|
+
return this.requestAsPromise({
|
|
2722
|
+
type: "mutation",
|
|
2723
|
+
path,
|
|
2724
|
+
input,
|
|
2725
|
+
context: opts === null || opts === void 0 ? void 0 : opts.context,
|
|
2726
|
+
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
subscription(path, input, opts) {
|
|
2730
|
+
const observable$ = this.$request({
|
|
2731
|
+
type: "subscription",
|
|
2732
|
+
path,
|
|
2733
|
+
input,
|
|
2734
|
+
context: opts.context,
|
|
2735
|
+
signal: opts.signal
|
|
2736
|
+
});
|
|
2737
|
+
return observable$.subscribe({
|
|
2738
|
+
next(envelope) {
|
|
2739
|
+
switch (envelope.result.type) {
|
|
2740
|
+
case "state": {
|
|
2741
|
+
var _opts$onConnectionSta;
|
|
2742
|
+
(_opts$onConnectionSta = opts.onConnectionStateChange) === null || _opts$onConnectionSta === void 0 || _opts$onConnectionSta.call(opts, envelope.result);
|
|
2743
|
+
break;
|
|
2744
|
+
}
|
|
2745
|
+
case "started": {
|
|
2746
|
+
var _opts$onStarted;
|
|
2747
|
+
(_opts$onStarted = opts.onStarted) === null || _opts$onStarted === void 0 || _opts$onStarted.call(opts, { context: envelope.context });
|
|
2748
|
+
break;
|
|
2749
|
+
}
|
|
2750
|
+
case "stopped": {
|
|
2751
|
+
var _opts$onStopped;
|
|
2752
|
+
(_opts$onStopped = opts.onStopped) === null || _opts$onStopped === void 0 || _opts$onStopped.call(opts);
|
|
2753
|
+
break;
|
|
2754
|
+
}
|
|
2755
|
+
case "data":
|
|
2756
|
+
case void 0: {
|
|
2757
|
+
var _opts$onData;
|
|
2758
|
+
(_opts$onData = opts.onData) === null || _opts$onData === void 0 || _opts$onData.call(opts, envelope.result.data);
|
|
2759
|
+
break;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
},
|
|
2763
|
+
error(err) {
|
|
2764
|
+
var _opts$onError;
|
|
2765
|
+
(_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, err);
|
|
2766
|
+
},
|
|
2767
|
+
complete() {
|
|
2768
|
+
var _opts$onComplete;
|
|
2769
|
+
(_opts$onComplete = opts.onComplete) === null || _opts$onComplete === void 0 || _opts$onComplete.call(opts);
|
|
2770
|
+
}
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
};
|
|
2774
|
+
function createTRPCUntypedClient(opts) {
|
|
2775
|
+
return new TRPCUntypedClient(opts);
|
|
2776
|
+
}
|
|
2777
|
+
var untypedClientSymbol = /* @__PURE__ */ Symbol.for("trpc_untypedClient");
|
|
2778
|
+
var clientCallTypeMap = {
|
|
2779
|
+
query: "query",
|
|
2780
|
+
mutate: "mutation",
|
|
2781
|
+
subscribe: "subscription"
|
|
2782
|
+
};
|
|
2783
|
+
var clientCallTypeToProcedureType = (clientCallType) => {
|
|
2784
|
+
return clientCallTypeMap[clientCallType];
|
|
2785
|
+
};
|
|
2786
|
+
function createTRPCClientProxy(client) {
|
|
2787
|
+
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
2788
|
+
const pathCopy = [...path];
|
|
2789
|
+
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
2790
|
+
const fullPath = pathCopy.join(".");
|
|
2791
|
+
return client[procedureType](fullPath, ...args);
|
|
2792
|
+
});
|
|
2793
|
+
return createFlatProxy((key) => {
|
|
2794
|
+
if (key === untypedClientSymbol) return client;
|
|
2795
|
+
return proxy[key];
|
|
2796
|
+
});
|
|
2797
|
+
}
|
|
2798
|
+
function createTRPCClient(opts) {
|
|
2799
|
+
const client = new TRPCUntypedClient(opts);
|
|
2800
|
+
const proxy = createTRPCClientProxy(client);
|
|
2801
|
+
return proxy;
|
|
2802
|
+
}
|
|
2803
|
+
function getUntypedClient(client) {
|
|
2804
|
+
return client[untypedClientSymbol];
|
|
2805
|
+
}
|
|
2806
|
+
var import_objectSpread2$3 = __toESM(require_objectSpread2(), 1);
|
|
2807
|
+
function httpBatchStreamLink(opts) {
|
|
2808
|
+
var _opts$maxURLLength, _opts$maxItems;
|
|
2809
|
+
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
2810
|
+
const maxURLLength = (_opts$maxURLLength = opts.maxURLLength) !== null && _opts$maxURLLength !== void 0 ? _opts$maxURLLength : Infinity;
|
|
2811
|
+
const maxItems = (_opts$maxItems = opts.maxItems) !== null && _opts$maxItems !== void 0 ? _opts$maxItems : Infinity;
|
|
2812
|
+
return () => {
|
|
2813
|
+
const batchLoader = (type) => {
|
|
2814
|
+
return {
|
|
2815
|
+
validate(batchOps) {
|
|
2816
|
+
if (maxURLLength === Infinity && maxItems === Infinity) return true;
|
|
2817
|
+
if (batchOps.length > maxItems) return false;
|
|
2818
|
+
const path = batchOps.map((op) => op.path).join(",");
|
|
2819
|
+
const inputs = batchOps.map((op) => op.input);
|
|
2820
|
+
const url = getUrl((0, import_objectSpread2$3.default)((0, import_objectSpread2$3.default)({}, resolvedOpts), {}, {
|
|
2821
|
+
type,
|
|
2822
|
+
path,
|
|
2823
|
+
inputs,
|
|
2824
|
+
signal: null
|
|
2825
|
+
}));
|
|
2826
|
+
return url.length <= maxURLLength;
|
|
2827
|
+
},
|
|
2828
|
+
async fetch(batchOps) {
|
|
2829
|
+
var _opts$streamHeader;
|
|
2830
|
+
const path = batchOps.map((op) => op.path).join(",");
|
|
2831
|
+
const inputs = batchOps.map((op) => op.input);
|
|
2832
|
+
const batchSignals = allAbortSignals(...batchOps.map((op) => op.signal));
|
|
2833
|
+
const abortController = new AbortController();
|
|
2834
|
+
const responsePromise = fetchHTTPResponse((0, import_objectSpread2$3.default)((0, import_objectSpread2$3.default)({}, resolvedOpts), {}, {
|
|
2835
|
+
signal: raceAbortSignals(batchSignals, abortController.signal),
|
|
2836
|
+
type,
|
|
2837
|
+
contentTypeHeader: "application/json",
|
|
2838
|
+
trpcAcceptHeader: "application/jsonl",
|
|
2839
|
+
trpcAcceptHeaderKey: (_opts$streamHeader = opts.streamHeader) !== null && _opts$streamHeader !== void 0 ? _opts$streamHeader : "trpc-accept",
|
|
2840
|
+
getUrl,
|
|
2841
|
+
getBody,
|
|
2842
|
+
inputs,
|
|
2843
|
+
path,
|
|
2844
|
+
headers() {
|
|
2845
|
+
if (!opts.headers) return {};
|
|
2846
|
+
if (typeof opts.headers === "function") return opts.headers({ opList: batchOps });
|
|
2847
|
+
return opts.headers;
|
|
2848
|
+
}
|
|
2849
|
+
}));
|
|
2850
|
+
const res = await responsePromise;
|
|
2851
|
+
const [head] = await jsonlStreamConsumer({
|
|
2852
|
+
from: res.body,
|
|
2853
|
+
deserialize: (data) => resolvedOpts.transformer.output.deserialize(data),
|
|
2854
|
+
formatError(opts$1) {
|
|
2855
|
+
const error = opts$1.error;
|
|
2856
|
+
return TRPCClientError.from({ error });
|
|
2857
|
+
},
|
|
2858
|
+
abortController
|
|
2859
|
+
});
|
|
2860
|
+
const promises = Object.keys(batchOps).map(async (key) => {
|
|
2861
|
+
let json = await Promise.resolve(head[key]);
|
|
2862
|
+
if ("result" in json) {
|
|
2863
|
+
const result = await Promise.resolve(json.result);
|
|
2864
|
+
json = { result: { data: await Promise.resolve(result.data) } };
|
|
2865
|
+
}
|
|
2866
|
+
return {
|
|
2867
|
+
json,
|
|
2868
|
+
meta: { response: res }
|
|
2869
|
+
};
|
|
2870
|
+
});
|
|
2871
|
+
return promises;
|
|
2872
|
+
}
|
|
2873
|
+
};
|
|
2874
|
+
};
|
|
2875
|
+
const query = dataLoader(batchLoader("query"));
|
|
2876
|
+
const mutation = dataLoader(batchLoader("mutation"));
|
|
2877
|
+
const loaders = {
|
|
2878
|
+
query,
|
|
2879
|
+
mutation
|
|
2880
|
+
};
|
|
2881
|
+
return ({ op }) => {
|
|
2882
|
+
return observable((observer) => {
|
|
2883
|
+
if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpBatchStreamLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
2884
|
+
const loader = loaders[op.type];
|
|
2885
|
+
const promise = loader.load(op);
|
|
2886
|
+
let _res = void 0;
|
|
2887
|
+
promise.then((res) => {
|
|
2888
|
+
_res = res;
|
|
2889
|
+
if ("error" in res.json) {
|
|
2890
|
+
observer.error(TRPCClientError.from(res.json, { meta: res.meta }));
|
|
2891
|
+
return;
|
|
2892
|
+
} else if ("result" in res.json) {
|
|
2893
|
+
observer.next({
|
|
2894
|
+
context: res.meta,
|
|
2895
|
+
result: res.json.result
|
|
2896
|
+
});
|
|
2897
|
+
observer.complete();
|
|
2898
|
+
return;
|
|
2899
|
+
}
|
|
2900
|
+
observer.complete();
|
|
2901
|
+
}).catch((err) => {
|
|
2902
|
+
observer.error(TRPCClientError.from(err, { meta: _res === null || _res === void 0 ? void 0 : _res.meta }));
|
|
2903
|
+
});
|
|
2904
|
+
return () => {
|
|
2905
|
+
};
|
|
2906
|
+
});
|
|
2907
|
+
};
|
|
2908
|
+
};
|
|
2909
|
+
}
|
|
2910
|
+
var unstable_httpBatchStreamLink = httpBatchStreamLink;
|
|
2911
|
+
var import_objectSpread2$2 = __toESM(require_objectSpread2(), 1);
|
|
2912
|
+
function inputWithTrackedEventId(input, lastEventId) {
|
|
2913
|
+
if (!lastEventId) return input;
|
|
2914
|
+
if (input != null && typeof input !== "object") return input;
|
|
2915
|
+
return (0, import_objectSpread2$2.default)((0, import_objectSpread2$2.default)({}, input !== null && input !== void 0 ? input : {}), {}, { lastEventId });
|
|
2916
|
+
}
|
|
2917
|
+
var require_asyncIterator2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
|
|
2918
|
+
function _asyncIterator$1(r) {
|
|
2919
|
+
var n, t, o, e = 2;
|
|
2920
|
+
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--; ) {
|
|
2921
|
+
if (t && null != (n = r[t])) return n.call(r);
|
|
2922
|
+
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
|
2923
|
+
t = "@@asyncIterator", o = "@@iterator";
|
|
2924
|
+
}
|
|
2925
|
+
throw new TypeError("Object is not async iterable");
|
|
2926
|
+
}
|
|
2927
|
+
function AsyncFromSyncIterator(r) {
|
|
2928
|
+
function AsyncFromSyncIteratorContinuation(r$1) {
|
|
2929
|
+
if (Object(r$1) !== r$1) return Promise.reject(new TypeError(r$1 + " is not an object."));
|
|
2930
|
+
var n = r$1.done;
|
|
2931
|
+
return Promise.resolve(r$1.value).then(function(r$2) {
|
|
2932
|
+
return {
|
|
2933
|
+
value: r$2,
|
|
2934
|
+
done: n
|
|
2935
|
+
};
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
|
|
2939
|
+
this.s = r$1, this.n = r$1.next;
|
|
2940
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
2941
|
+
s: null,
|
|
2942
|
+
n: null,
|
|
2943
|
+
next: function next() {
|
|
2944
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
2945
|
+
},
|
|
2946
|
+
"return": function _return(r$1) {
|
|
2947
|
+
var n = this.s["return"];
|
|
2948
|
+
return void 0 === n ? Promise.resolve({
|
|
2949
|
+
value: r$1,
|
|
2950
|
+
done: true
|
|
2951
|
+
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
2952
|
+
},
|
|
2953
|
+
"throw": function _throw(r$1) {
|
|
2954
|
+
var n = this.s["return"];
|
|
2955
|
+
return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
2956
|
+
}
|
|
2957
|
+
}, new AsyncFromSyncIterator(r);
|
|
2958
|
+
}
|
|
2959
|
+
module.exports = _asyncIterator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
2960
|
+
} });
|
|
2961
|
+
var import_asyncIterator2 = __toESM(require_asyncIterator2(), 1);
|
|
2962
|
+
async function urlWithConnectionParams(opts) {
|
|
2963
|
+
let url = await resultOf(opts.url);
|
|
2964
|
+
if (opts.connectionParams) {
|
|
2965
|
+
const params = await resultOf(opts.connectionParams);
|
|
2966
|
+
const prefix = url.includes("?") ? "&" : "?";
|
|
2967
|
+
url += prefix + "connectionParams=" + encodeURIComponent(JSON.stringify(params));
|
|
2968
|
+
}
|
|
2969
|
+
return url;
|
|
2970
|
+
}
|
|
2971
|
+
function httpSubscriptionLink(opts) {
|
|
2972
|
+
const transformer = getTransformer(opts.transformer);
|
|
2973
|
+
return () => {
|
|
2974
|
+
return ({ op }) => {
|
|
2975
|
+
return observable((observer) => {
|
|
2976
|
+
var _opts$EventSource;
|
|
2977
|
+
const { type, path, input } = op;
|
|
2978
|
+
if (type !== "subscription") throw new Error("httpSubscriptionLink only supports subscriptions");
|
|
2979
|
+
let lastEventId = void 0;
|
|
2980
|
+
const ac = new AbortController();
|
|
2981
|
+
const signal = raceAbortSignals(op.signal, ac.signal);
|
|
2982
|
+
const eventSourceStream = sseStreamConsumer({
|
|
2983
|
+
url: async () => getUrl({
|
|
2984
|
+
transformer,
|
|
2985
|
+
url: await urlWithConnectionParams(opts),
|
|
2986
|
+
input: inputWithTrackedEventId(input, lastEventId),
|
|
2987
|
+
path,
|
|
2988
|
+
type,
|
|
2989
|
+
signal: null
|
|
2990
|
+
}),
|
|
2991
|
+
init: () => resultOf(opts.eventSourceOptions, { op }),
|
|
2992
|
+
signal,
|
|
2993
|
+
deserialize: (data) => transformer.output.deserialize(data),
|
|
2994
|
+
EventSource: (_opts$EventSource = opts.EventSource) !== null && _opts$EventSource !== void 0 ? _opts$EventSource : globalThis.EventSource
|
|
2995
|
+
});
|
|
2996
|
+
const connectionState = behaviorSubject({
|
|
2997
|
+
type: "state",
|
|
2998
|
+
state: "connecting",
|
|
2999
|
+
error: null
|
|
3000
|
+
});
|
|
3001
|
+
const connectionSub = connectionState.subscribe({ next(state) {
|
|
3002
|
+
observer.next({ result: state });
|
|
3003
|
+
} });
|
|
3004
|
+
run(async () => {
|
|
3005
|
+
var _iteratorAbruptCompletion = false;
|
|
3006
|
+
var _didIteratorError = false;
|
|
3007
|
+
var _iteratorError;
|
|
3008
|
+
try {
|
|
3009
|
+
for (var _iterator = (0, import_asyncIterator2.default)(eventSourceStream), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
|
3010
|
+
const chunk = _step.value;
|
|
3011
|
+
switch (chunk.type) {
|
|
3012
|
+
case "ping":
|
|
3013
|
+
break;
|
|
3014
|
+
case "data":
|
|
3015
|
+
const chunkData = chunk.data;
|
|
3016
|
+
let result;
|
|
3017
|
+
if (chunkData.id) {
|
|
3018
|
+
lastEventId = chunkData.id;
|
|
3019
|
+
result = {
|
|
3020
|
+
id: chunkData.id,
|
|
3021
|
+
data: chunkData
|
|
3022
|
+
};
|
|
3023
|
+
} else result = { data: chunkData.data };
|
|
3024
|
+
observer.next({
|
|
3025
|
+
result,
|
|
3026
|
+
context: { eventSource: chunk.eventSource }
|
|
3027
|
+
});
|
|
3028
|
+
break;
|
|
3029
|
+
case "connected": {
|
|
3030
|
+
observer.next({
|
|
3031
|
+
result: { type: "started" },
|
|
3032
|
+
context: { eventSource: chunk.eventSource }
|
|
3033
|
+
});
|
|
3034
|
+
connectionState.next({
|
|
3035
|
+
type: "state",
|
|
3036
|
+
state: "pending",
|
|
3037
|
+
error: null
|
|
3038
|
+
});
|
|
3039
|
+
break;
|
|
3040
|
+
}
|
|
3041
|
+
case "serialized-error": {
|
|
3042
|
+
const error = TRPCClientError.from({ error: chunk.error });
|
|
3043
|
+
if (retryableRpcCodes.includes(chunk.error.code)) {
|
|
3044
|
+
connectionState.next({
|
|
3045
|
+
type: "state",
|
|
3046
|
+
state: "connecting",
|
|
3047
|
+
error
|
|
3048
|
+
});
|
|
3049
|
+
break;
|
|
3050
|
+
}
|
|
3051
|
+
throw error;
|
|
3052
|
+
}
|
|
3053
|
+
case "connecting": {
|
|
3054
|
+
const lastState = connectionState.get();
|
|
3055
|
+
const error = chunk.event && TRPCClientError.from(chunk.event);
|
|
3056
|
+
if (!error && lastState.state === "connecting") break;
|
|
3057
|
+
connectionState.next({
|
|
3058
|
+
type: "state",
|
|
3059
|
+
state: "connecting",
|
|
3060
|
+
error
|
|
3061
|
+
});
|
|
3062
|
+
break;
|
|
3063
|
+
}
|
|
3064
|
+
case "timeout":
|
|
3065
|
+
connectionState.next({
|
|
3066
|
+
type: "state",
|
|
3067
|
+
state: "connecting",
|
|
3068
|
+
error: new TRPCClientError(`Timeout of ${chunk.ms}ms reached while waiting for a response`)
|
|
3069
|
+
});
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
} catch (err) {
|
|
3073
|
+
_didIteratorError = true;
|
|
3074
|
+
_iteratorError = err;
|
|
3075
|
+
} finally {
|
|
3076
|
+
try {
|
|
3077
|
+
if (_iteratorAbruptCompletion && _iterator.return != null) await _iterator.return();
|
|
3078
|
+
} finally {
|
|
3079
|
+
if (_didIteratorError) throw _iteratorError;
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
observer.next({ result: { type: "stopped" } });
|
|
3083
|
+
connectionState.next({
|
|
3084
|
+
type: "state",
|
|
3085
|
+
state: "idle",
|
|
3086
|
+
error: null
|
|
3087
|
+
});
|
|
3088
|
+
observer.complete();
|
|
3089
|
+
}).catch((error) => {
|
|
3090
|
+
observer.error(TRPCClientError.from(error));
|
|
3091
|
+
});
|
|
3092
|
+
return () => {
|
|
3093
|
+
observer.complete();
|
|
3094
|
+
ac.abort();
|
|
3095
|
+
connectionSub.unsubscribe();
|
|
3096
|
+
};
|
|
3097
|
+
});
|
|
3098
|
+
};
|
|
3099
|
+
};
|
|
3100
|
+
}
|
|
3101
|
+
var unstable_httpSubscriptionLink = httpSubscriptionLink;
|
|
3102
|
+
var import_objectSpread2$13 = __toESM(require_objectSpread2(), 1);
|
|
3103
|
+
function retryLink(opts) {
|
|
3104
|
+
return () => {
|
|
3105
|
+
return (callOpts) => {
|
|
3106
|
+
return observable((observer) => {
|
|
3107
|
+
let next$;
|
|
3108
|
+
let callNextTimeout = void 0;
|
|
3109
|
+
let lastEventId = void 0;
|
|
3110
|
+
attempt(1);
|
|
3111
|
+
function opWithLastEventId() {
|
|
3112
|
+
const op = callOpts.op;
|
|
3113
|
+
if (!lastEventId) return op;
|
|
3114
|
+
return (0, import_objectSpread2$13.default)((0, import_objectSpread2$13.default)({}, op), {}, { input: inputWithTrackedEventId(op.input, lastEventId) });
|
|
3115
|
+
}
|
|
3116
|
+
function attempt(attempts) {
|
|
3117
|
+
const op = opWithLastEventId();
|
|
3118
|
+
next$ = callOpts.next(op).subscribe({
|
|
3119
|
+
error(error) {
|
|
3120
|
+
var _opts$retryDelayMs, _opts$retryDelayMs2;
|
|
3121
|
+
const shouldRetry = opts.retry({
|
|
3122
|
+
op,
|
|
3123
|
+
attempts,
|
|
3124
|
+
error
|
|
3125
|
+
});
|
|
3126
|
+
if (!shouldRetry) {
|
|
3127
|
+
observer.error(error);
|
|
3128
|
+
return;
|
|
3129
|
+
}
|
|
3130
|
+
const delayMs = (_opts$retryDelayMs = (_opts$retryDelayMs2 = opts.retryDelayMs) === null || _opts$retryDelayMs2 === void 0 ? void 0 : _opts$retryDelayMs2.call(opts, attempts)) !== null && _opts$retryDelayMs !== void 0 ? _opts$retryDelayMs : 0;
|
|
3131
|
+
if (delayMs <= 0) {
|
|
3132
|
+
attempt(attempts + 1);
|
|
3133
|
+
return;
|
|
3134
|
+
}
|
|
3135
|
+
callNextTimeout = setTimeout(() => attempt(attempts + 1), delayMs);
|
|
3136
|
+
},
|
|
3137
|
+
next(envelope) {
|
|
3138
|
+
if ((!envelope.result.type || envelope.result.type === "data") && envelope.result.id) lastEventId = envelope.result.id;
|
|
3139
|
+
observer.next(envelope);
|
|
3140
|
+
},
|
|
3141
|
+
complete() {
|
|
3142
|
+
observer.complete();
|
|
3143
|
+
}
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
return () => {
|
|
3147
|
+
next$.unsubscribe();
|
|
3148
|
+
clearTimeout(callNextTimeout);
|
|
3149
|
+
};
|
|
3150
|
+
});
|
|
3151
|
+
};
|
|
3152
|
+
};
|
|
3153
|
+
}
|
|
3154
|
+
var require_usingCtx2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
|
|
3155
|
+
function _usingCtx() {
|
|
3156
|
+
var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
|
|
3157
|
+
var n$1 = Error();
|
|
3158
|
+
return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
|
|
3159
|
+
}, e = {}, n = [];
|
|
3160
|
+
function using(r$1, e$1) {
|
|
3161
|
+
if (null != e$1) {
|
|
3162
|
+
if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
3163
|
+
if (r$1) var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
3164
|
+
if (void 0 === o && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1)) var t = o;
|
|
3165
|
+
if ("function" != typeof o) throw new TypeError("Object is not disposable.");
|
|
3166
|
+
t && (o = function o$1() {
|
|
3167
|
+
try {
|
|
3168
|
+
t.call(e$1);
|
|
3169
|
+
} catch (r$2) {
|
|
3170
|
+
return Promise.reject(r$2);
|
|
3171
|
+
}
|
|
3172
|
+
}), n.push({
|
|
3173
|
+
v: e$1,
|
|
3174
|
+
d: o,
|
|
3175
|
+
a: r$1
|
|
3176
|
+
});
|
|
3177
|
+
} else r$1 && n.push({
|
|
3178
|
+
d: e$1,
|
|
3179
|
+
a: r$1
|
|
3180
|
+
});
|
|
3181
|
+
return e$1;
|
|
3182
|
+
}
|
|
3183
|
+
return {
|
|
3184
|
+
e,
|
|
3185
|
+
u: using.bind(null, false),
|
|
3186
|
+
a: using.bind(null, true),
|
|
3187
|
+
d: function d() {
|
|
3188
|
+
var o, t = this.e, s = 0;
|
|
3189
|
+
function next() {
|
|
3190
|
+
for (; o = n.pop(); ) try {
|
|
3191
|
+
if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
|
|
3192
|
+
if (o.d) {
|
|
3193
|
+
var r$1 = o.d.call(o.v);
|
|
3194
|
+
if (o.a) return s |= 2, Promise.resolve(r$1).then(next, err);
|
|
3195
|
+
} else s |= 1;
|
|
3196
|
+
} catch (r$2) {
|
|
3197
|
+
return err(r$2);
|
|
3198
|
+
}
|
|
3199
|
+
if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
3200
|
+
if (t !== e) throw t;
|
|
3201
|
+
}
|
|
3202
|
+
function err(n$1) {
|
|
3203
|
+
return t = t !== e ? new r(n$1, t) : n$1, next();
|
|
3204
|
+
}
|
|
3205
|
+
return next();
|
|
3206
|
+
}
|
|
3207
|
+
};
|
|
3208
|
+
}
|
|
3209
|
+
module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3210
|
+
} });
|
|
3211
|
+
var require_OverloadYield2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js"(exports, module) {
|
|
3212
|
+
function _OverloadYield(e, d) {
|
|
3213
|
+
this.v = e, this.k = d;
|
|
3214
|
+
}
|
|
3215
|
+
module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3216
|
+
} });
|
|
3217
|
+
var require_awaitAsyncGenerator2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js"(exports, module) {
|
|
3218
|
+
var OverloadYield$1 = require_OverloadYield2();
|
|
3219
|
+
function _awaitAsyncGenerator$1(e) {
|
|
3220
|
+
return new OverloadYield$1(e, 0);
|
|
3221
|
+
}
|
|
3222
|
+
module.exports = _awaitAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3223
|
+
} });
|
|
3224
|
+
var require_wrapAsyncGenerator2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js"(exports, module) {
|
|
3225
|
+
var OverloadYield = require_OverloadYield2();
|
|
3226
|
+
function _wrapAsyncGenerator$1(e) {
|
|
3227
|
+
return function() {
|
|
3228
|
+
return new AsyncGenerator(e.apply(this, arguments));
|
|
3229
|
+
};
|
|
3230
|
+
}
|
|
3231
|
+
function AsyncGenerator(e) {
|
|
3232
|
+
var r, t;
|
|
3233
|
+
function resume(r$1, t$1) {
|
|
3234
|
+
try {
|
|
3235
|
+
var n = e[r$1](t$1), o = n.value, u = o instanceof OverloadYield;
|
|
3236
|
+
Promise.resolve(u ? o.v : o).then(function(t$2) {
|
|
3237
|
+
if (u) {
|
|
3238
|
+
var i = "return" === r$1 ? "return" : "next";
|
|
3239
|
+
if (!o.k || t$2.done) return resume(i, t$2);
|
|
3240
|
+
t$2 = e[i](t$2).value;
|
|
3241
|
+
}
|
|
3242
|
+
settle(n.done ? "return" : "normal", t$2);
|
|
3243
|
+
}, function(e$1) {
|
|
3244
|
+
resume("throw", e$1);
|
|
3245
|
+
});
|
|
3246
|
+
} catch (e$1) {
|
|
3247
|
+
settle("throw", e$1);
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
function settle(e$1, n) {
|
|
3251
|
+
switch (e$1) {
|
|
3252
|
+
case "return":
|
|
3253
|
+
r.resolve({
|
|
3254
|
+
value: n,
|
|
3255
|
+
done: true
|
|
3256
|
+
});
|
|
3257
|
+
break;
|
|
3258
|
+
case "throw":
|
|
3259
|
+
r.reject(n);
|
|
3260
|
+
break;
|
|
3261
|
+
default:
|
|
3262
|
+
r.resolve({
|
|
3263
|
+
value: n,
|
|
3264
|
+
done: false
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
3268
|
+
}
|
|
3269
|
+
this._invoke = function(e$1, n) {
|
|
3270
|
+
return new Promise(function(o, u) {
|
|
3271
|
+
var i = {
|
|
3272
|
+
key: e$1,
|
|
3273
|
+
arg: n,
|
|
3274
|
+
resolve: o,
|
|
3275
|
+
reject: u,
|
|
3276
|
+
next: null
|
|
3277
|
+
};
|
|
3278
|
+
t ? t = t.next = i : (r = t = i, resume(e$1, n));
|
|
3279
|
+
});
|
|
3280
|
+
}, "function" != typeof e["return"] && (this["return"] = void 0);
|
|
3281
|
+
}
|
|
3282
|
+
AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
3283
|
+
return this;
|
|
3284
|
+
}, AsyncGenerator.prototype.next = function(e) {
|
|
3285
|
+
return this._invoke("next", e);
|
|
3286
|
+
}, AsyncGenerator.prototype["throw"] = function(e) {
|
|
3287
|
+
return this._invoke("throw", e);
|
|
3288
|
+
}, AsyncGenerator.prototype["return"] = function(e) {
|
|
3289
|
+
return this._invoke("return", e);
|
|
3290
|
+
};
|
|
3291
|
+
module.exports = _wrapAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3292
|
+
} });
|
|
3293
|
+
var import_usingCtx2 = __toESM(require_usingCtx2(), 1);
|
|
3294
|
+
var import_awaitAsyncGenerator2 = __toESM(require_awaitAsyncGenerator2(), 1);
|
|
3295
|
+
var import_wrapAsyncGenerator2 = __toESM(require_wrapAsyncGenerator2(), 1);
|
|
3296
|
+
var import_objectSpread210 = __toESM(require_objectSpread2(), 1);
|
|
3297
|
+
function unstable_localLink(opts) {
|
|
3298
|
+
const transformer = getTransformer(opts.transformer);
|
|
3299
|
+
const transformChunk = (chunk) => {
|
|
3300
|
+
if (opts.transformer) return chunk;
|
|
3301
|
+
if (chunk === void 0) return chunk;
|
|
3302
|
+
const serialized = JSON.stringify(transformer.input.serialize(chunk));
|
|
3303
|
+
const deserialized = JSON.parse(transformer.output.deserialize(serialized));
|
|
3304
|
+
return deserialized;
|
|
3305
|
+
};
|
|
3306
|
+
return () => ({ op }) => observable((observer) => {
|
|
3307
|
+
let ctx = void 0;
|
|
3308
|
+
const ac = new AbortController();
|
|
3309
|
+
const signal = raceAbortSignals(op.signal, ac.signal);
|
|
3310
|
+
const signalPromise = abortSignalToPromise(signal);
|
|
3311
|
+
signalPromise.catch(() => {
|
|
3312
|
+
});
|
|
3313
|
+
let input = op.input;
|
|
3314
|
+
async function runProcedure(newInput) {
|
|
3315
|
+
input = newInput;
|
|
3316
|
+
ctx = await opts.createContext();
|
|
3317
|
+
return callProcedure({
|
|
3318
|
+
router: opts.router,
|
|
3319
|
+
path: op.path,
|
|
3320
|
+
getRawInput: async () => newInput,
|
|
3321
|
+
ctx,
|
|
3322
|
+
type: op.type,
|
|
3323
|
+
signal,
|
|
3324
|
+
batchIndex: 0
|
|
3325
|
+
});
|
|
3326
|
+
}
|
|
3327
|
+
function onErrorCallback(cause) {
|
|
3328
|
+
var _opts$onError;
|
|
3329
|
+
if (isAbortError(cause)) return;
|
|
3330
|
+
(_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, {
|
|
3331
|
+
error: getTRPCErrorFromUnknown(cause),
|
|
3332
|
+
type: op.type,
|
|
3333
|
+
path: op.path,
|
|
3334
|
+
input,
|
|
3335
|
+
ctx
|
|
3336
|
+
});
|
|
3337
|
+
}
|
|
3338
|
+
function coerceToTRPCClientError(cause) {
|
|
3339
|
+
if (isTRPCClientError(cause)) return cause;
|
|
3340
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
3341
|
+
const shape = getErrorShape({
|
|
3342
|
+
config: opts.router._def._config,
|
|
3343
|
+
ctx,
|
|
3344
|
+
error,
|
|
3345
|
+
input,
|
|
3346
|
+
path: op.path,
|
|
3347
|
+
type: op.type
|
|
3348
|
+
});
|
|
3349
|
+
return TRPCClientError.from({ error: transformChunk(shape) }, { cause: cause instanceof Error ? cause : void 0 });
|
|
3350
|
+
}
|
|
3351
|
+
run(async () => {
|
|
3352
|
+
switch (op.type) {
|
|
3353
|
+
case "query":
|
|
3354
|
+
case "mutation": {
|
|
3355
|
+
const result = await runProcedure(op.input);
|
|
3356
|
+
if (!isAsyncIterable(result)) {
|
|
3357
|
+
observer.next({ result: { data: transformChunk(result) } });
|
|
3358
|
+
observer.complete();
|
|
3359
|
+
break;
|
|
3360
|
+
}
|
|
3361
|
+
observer.next({ result: { data: (0, import_wrapAsyncGenerator2.default)(function* () {
|
|
3362
|
+
try {
|
|
3363
|
+
var _usingCtx$1 = (0, import_usingCtx2.default)();
|
|
3364
|
+
const iterator = _usingCtx$1.a(iteratorResource(result));
|
|
3365
|
+
const _finally = _usingCtx$1.u(makeResource({}, () => {
|
|
3366
|
+
observer.complete();
|
|
3367
|
+
}));
|
|
3368
|
+
try {
|
|
3369
|
+
while (true) {
|
|
3370
|
+
const res = yield (0, import_awaitAsyncGenerator2.default)(Promise.race([iterator.next(), signalPromise]));
|
|
3371
|
+
if (res.done) return transformChunk(res.value);
|
|
3372
|
+
yield transformChunk(res.value);
|
|
3373
|
+
}
|
|
3374
|
+
} catch (cause) {
|
|
3375
|
+
onErrorCallback(cause);
|
|
3376
|
+
throw coerceToTRPCClientError(cause);
|
|
3377
|
+
}
|
|
3378
|
+
} catch (_) {
|
|
3379
|
+
_usingCtx$1.e = _;
|
|
3380
|
+
} finally {
|
|
3381
|
+
yield (0, import_awaitAsyncGenerator2.default)(_usingCtx$1.d());
|
|
3382
|
+
}
|
|
3383
|
+
})() } });
|
|
3384
|
+
break;
|
|
3385
|
+
}
|
|
3386
|
+
case "subscription":
|
|
3387
|
+
try {
|
|
3388
|
+
var _usingCtx3 = (0, import_usingCtx2.default)();
|
|
3389
|
+
const connectionState = behaviorSubject({
|
|
3390
|
+
type: "state",
|
|
3391
|
+
state: "connecting",
|
|
3392
|
+
error: null
|
|
3393
|
+
});
|
|
3394
|
+
const connectionSub = connectionState.subscribe({ next(state) {
|
|
3395
|
+
observer.next({ result: state });
|
|
3396
|
+
} });
|
|
3397
|
+
let lastEventId = void 0;
|
|
3398
|
+
const _finally = _usingCtx3.u(makeResource({}, async () => {
|
|
3399
|
+
observer.complete();
|
|
3400
|
+
connectionState.next({
|
|
3401
|
+
type: "state",
|
|
3402
|
+
state: "idle",
|
|
3403
|
+
error: null
|
|
3404
|
+
});
|
|
3405
|
+
connectionSub.unsubscribe();
|
|
3406
|
+
}));
|
|
3407
|
+
while (true) try {
|
|
3408
|
+
var _usingCtx4 = (0, import_usingCtx2.default)();
|
|
3409
|
+
const result = await runProcedure(inputWithTrackedEventId(op.input, lastEventId));
|
|
3410
|
+
if (!isAsyncIterable(result)) throw new Error("Expected an async iterable");
|
|
3411
|
+
const iterator = _usingCtx4.a(iteratorResource(result));
|
|
3412
|
+
observer.next({ result: { type: "started" } });
|
|
3413
|
+
connectionState.next({
|
|
3414
|
+
type: "state",
|
|
3415
|
+
state: "pending",
|
|
3416
|
+
error: null
|
|
3417
|
+
});
|
|
3418
|
+
while (true) {
|
|
3419
|
+
let res;
|
|
3420
|
+
try {
|
|
3421
|
+
res = await Promise.race([iterator.next(), signalPromise]);
|
|
3422
|
+
} catch (cause) {
|
|
3423
|
+
if (isAbortError(cause)) return;
|
|
3424
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
3425
|
+
if (!retryableRpcCodes.includes(TRPC_ERROR_CODES_BY_KEY[error.code])) throw coerceToTRPCClientError(error);
|
|
3426
|
+
onErrorCallback(error);
|
|
3427
|
+
connectionState.next({
|
|
3428
|
+
type: "state",
|
|
3429
|
+
state: "connecting",
|
|
3430
|
+
error: coerceToTRPCClientError(error)
|
|
3431
|
+
});
|
|
3432
|
+
break;
|
|
3433
|
+
}
|
|
3434
|
+
if (res.done) return;
|
|
3435
|
+
let chunk;
|
|
3436
|
+
if (isTrackedEnvelope(res.value)) {
|
|
3437
|
+
lastEventId = res.value[0];
|
|
3438
|
+
chunk = {
|
|
3439
|
+
id: res.value[0],
|
|
3440
|
+
data: {
|
|
3441
|
+
id: res.value[0],
|
|
3442
|
+
data: res.value[1]
|
|
3443
|
+
}
|
|
3444
|
+
};
|
|
3445
|
+
} else chunk = { data: res.value };
|
|
3446
|
+
observer.next({ result: (0, import_objectSpread210.default)((0, import_objectSpread210.default)({}, chunk), {}, { data: transformChunk(chunk.data) }) });
|
|
3447
|
+
}
|
|
3448
|
+
} catch (_) {
|
|
3449
|
+
_usingCtx4.e = _;
|
|
3450
|
+
} finally {
|
|
3451
|
+
await _usingCtx4.d();
|
|
3452
|
+
}
|
|
3453
|
+
break;
|
|
3454
|
+
} catch (_) {
|
|
3455
|
+
_usingCtx3.e = _;
|
|
3456
|
+
} finally {
|
|
3457
|
+
_usingCtx3.d();
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3460
|
+
}).catch((cause) => {
|
|
3461
|
+
onErrorCallback(cause);
|
|
3462
|
+
observer.error(coerceToTRPCClientError(cause));
|
|
3463
|
+
});
|
|
3464
|
+
return () => {
|
|
3465
|
+
ac.abort();
|
|
3466
|
+
};
|
|
3467
|
+
});
|
|
3468
|
+
}
|
|
3469
|
+
var experimental_localLink = unstable_localLink;
|
|
3470
|
+
export {
|
|
3471
|
+
TRPCClientError,
|
|
3472
|
+
TRPCUntypedClient,
|
|
3473
|
+
clientCallTypeToProcedureType,
|
|
3474
|
+
createTRPCClient,
|
|
3475
|
+
createTRPCClientProxy,
|
|
3476
|
+
createTRPCClient as createTRPCProxyClient,
|
|
3477
|
+
createTRPCUntypedClient,
|
|
3478
|
+
createWSClient,
|
|
3479
|
+
experimental_localLink,
|
|
3480
|
+
getFetch,
|
|
3481
|
+
getUntypedClient,
|
|
3482
|
+
httpBatchLink,
|
|
3483
|
+
httpBatchStreamLink,
|
|
3484
|
+
httpLink,
|
|
3485
|
+
httpSubscriptionLink,
|
|
3486
|
+
isFormData,
|
|
3487
|
+
isNonJsonSerializable,
|
|
3488
|
+
isOctetType,
|
|
3489
|
+
isTRPCClientError,
|
|
3490
|
+
jsonEncoder,
|
|
3491
|
+
loggerLink,
|
|
3492
|
+
retryLink,
|
|
3493
|
+
splitLink,
|
|
3494
|
+
unstable_httpBatchStreamLink,
|
|
3495
|
+
unstable_httpSubscriptionLink,
|
|
3496
|
+
unstable_localLink,
|
|
3497
|
+
wsLink
|
|
3498
|
+
};
|
|
3499
|
+
/*! Bundled license information:
|
|
3500
|
+
|
|
3501
|
+
@trpc/server/dist/tracked-Bjtgv3wJ.mjs:
|
|
3502
|
+
@trpc/client/dist/httpLink-lG_6juPY.mjs:
|
|
3503
|
+
@trpc/client/dist/httpBatchLink-LhidKAPw.mjs:
|
|
3504
|
+
@trpc/client/dist/index.mjs:
|
|
3505
|
+
(* istanbul ignore if -- @preserve *)
|
|
3506
|
+
|
|
3507
|
+
@trpc/server/dist/resolveResponse-O0k3XIo_.mjs:
|
|
3508
|
+
(*!
|
|
3509
|
+
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
3510
|
+
*
|
|
3511
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
3512
|
+
* Released under the MIT License.
|
|
3513
|
+
*)
|
|
3514
|
+
*/
|
|
3515
|
+
//# sourceMappingURL=dist-N7SR63RN.mjs.map
|