@camstack/sdk 0.1.36 → 0.1.37
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/__tests__/race-endpoints.spec.d.ts +1 -0
- package/dist/index.cjs +1076 -2130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1022 -1994
- package/dist/index.js.map +1 -1
- package/dist/system.d.ts +68 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,1781 +1,785 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __commonJS = /* @__PURE__ */ __name((cb, mod) => function() {
|
|
12
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
-
}, "__commonJS");
|
|
14
|
-
var __copyProps = /* @__PURE__ */ __name((to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
-
key = keys[i];
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp2(to, key, {
|
|
18
|
-
get: ((k) => from[k]).bind(null, key),
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
1
|
+
import { createWSClient, createTRPCClient, wsLink, httpLink } from "@trpc/client";
|
|
2
|
+
import { createSystemProxy, SystemMirror } from "@camstack/types";
|
|
3
|
+
class DoubleIndexedKV {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.keyToValue = /* @__PURE__ */ new Map();
|
|
6
|
+
this.valueToKey = /* @__PURE__ */ new Map();
|
|
21
7
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
36
|
-
}
|
|
37
|
-
__name(_typeof$2, "_typeof$2");
|
|
38
|
-
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
39
|
-
} });
|
|
40
|
-
var require_toPrimitive = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
41
|
-
var _typeof$1 = require_typeof()["default"];
|
|
42
|
-
function toPrimitive$1(t, r) {
|
|
43
|
-
if ("object" != _typeof$1(t) || !t) return t;
|
|
44
|
-
var e = t[Symbol.toPrimitive];
|
|
45
|
-
if (void 0 !== e) {
|
|
46
|
-
var i = e.call(t, r || "default");
|
|
47
|
-
if ("object" != _typeof$1(i)) return i;
|
|
48
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
49
|
-
}
|
|
50
|
-
return ("string" === r ? String : Number)(t);
|
|
51
|
-
}
|
|
52
|
-
__name(toPrimitive$1, "toPrimitive$1");
|
|
53
|
-
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
54
|
-
} });
|
|
55
|
-
var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
56
|
-
var _typeof = require_typeof()["default"];
|
|
57
|
-
var toPrimitive = require_toPrimitive();
|
|
58
|
-
function toPropertyKey$1(t) {
|
|
59
|
-
var i = toPrimitive(t, "string");
|
|
60
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
61
|
-
}
|
|
62
|
-
__name(toPropertyKey$1, "toPropertyKey$1");
|
|
63
|
-
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
64
|
-
} });
|
|
65
|
-
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
66
|
-
var toPropertyKey = require_toPropertyKey();
|
|
67
|
-
function _defineProperty(e, r, t) {
|
|
68
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
69
|
-
value: t,
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
writable: true
|
|
73
|
-
}) : e[r] = t, e;
|
|
74
|
-
}
|
|
75
|
-
__name(_defineProperty, "_defineProperty");
|
|
76
|
-
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
77
|
-
} });
|
|
78
|
-
var require_objectSpread2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
79
|
-
var defineProperty = require_defineProperty();
|
|
80
|
-
function ownKeys(e, r) {
|
|
81
|
-
var t = Object.keys(e);
|
|
82
|
-
if (Object.getOwnPropertySymbols) {
|
|
83
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
84
|
-
r && (o = o.filter(function(r$1) {
|
|
85
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
86
|
-
})), t.push.apply(t, o);
|
|
87
|
-
}
|
|
88
|
-
return t;
|
|
89
|
-
}
|
|
90
|
-
__name(ownKeys, "ownKeys");
|
|
91
|
-
function _objectSpread2(e) {
|
|
92
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
93
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
94
|
-
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
95
|
-
defineProperty(e, r$1, t[r$1]);
|
|
96
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
97
|
-
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return e;
|
|
8
|
+
set(key, value) {
|
|
9
|
+
this.keyToValue.set(key, value);
|
|
10
|
+
this.valueToKey.set(value, key);
|
|
11
|
+
}
|
|
12
|
+
getByKey(key) {
|
|
13
|
+
return this.keyToValue.get(key);
|
|
14
|
+
}
|
|
15
|
+
getByValue(value) {
|
|
16
|
+
return this.valueToKey.get(value);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this.keyToValue.clear();
|
|
20
|
+
this.valueToKey.clear();
|
|
101
21
|
}
|
|
102
|
-
__name(_objectSpread2, "_objectSpread2");
|
|
103
|
-
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
104
|
-
} });
|
|
105
|
-
|
|
106
|
-
// ../../node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
|
|
107
|
-
function observable(subscribe) {
|
|
108
|
-
const self = {
|
|
109
|
-
subscribe(observer) {
|
|
110
|
-
let teardownRef = null;
|
|
111
|
-
let isDone = false;
|
|
112
|
-
let unsubscribed = false;
|
|
113
|
-
let teardownImmediately = false;
|
|
114
|
-
function unsubscribe() {
|
|
115
|
-
if (teardownRef === null) {
|
|
116
|
-
teardownImmediately = true;
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (unsubscribed) return;
|
|
120
|
-
unsubscribed = true;
|
|
121
|
-
if (typeof teardownRef === "function") teardownRef();
|
|
122
|
-
else if (teardownRef) teardownRef.unsubscribe();
|
|
123
|
-
}
|
|
124
|
-
__name(unsubscribe, "unsubscribe");
|
|
125
|
-
teardownRef = subscribe({
|
|
126
|
-
next(value) {
|
|
127
|
-
var _observer$next;
|
|
128
|
-
if (isDone) return;
|
|
129
|
-
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
130
|
-
},
|
|
131
|
-
error(err) {
|
|
132
|
-
var _observer$error;
|
|
133
|
-
if (isDone) return;
|
|
134
|
-
isDone = true;
|
|
135
|
-
(_observer$error = observer.error) === null || _observer$error === void 0 || _observer$error.call(observer, err);
|
|
136
|
-
unsubscribe();
|
|
137
|
-
},
|
|
138
|
-
complete() {
|
|
139
|
-
var _observer$complete;
|
|
140
|
-
if (isDone) return;
|
|
141
|
-
isDone = true;
|
|
142
|
-
(_observer$complete = observer.complete) === null || _observer$complete === void 0 || _observer$complete.call(observer);
|
|
143
|
-
unsubscribe();
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
if (teardownImmediately) unsubscribe();
|
|
147
|
-
return { unsubscribe };
|
|
148
|
-
},
|
|
149
|
-
pipe(...operations) {
|
|
150
|
-
return operations.reduce(pipeReducer, self);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
return self;
|
|
154
|
-
}
|
|
155
|
-
__name(observable, "observable");
|
|
156
|
-
function pipeReducer(prev, fn) {
|
|
157
|
-
return fn(prev);
|
|
158
22
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
obs$.unsubscribe();
|
|
23
|
+
class Registry {
|
|
24
|
+
constructor(generateIdentifier) {
|
|
25
|
+
this.generateIdentifier = generateIdentifier;
|
|
26
|
+
this.kv = new DoubleIndexedKV();
|
|
27
|
+
}
|
|
28
|
+
register(value, identifier) {
|
|
29
|
+
if (this.kv.getByValue(value)) {
|
|
30
|
+
return;
|
|
168
31
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
reject(ac.signal.reason);
|
|
172
|
-
});
|
|
173
|
-
const obs$ = observable$1.subscribe({
|
|
174
|
-
next(data) {
|
|
175
|
-
isDone = true;
|
|
176
|
-
resolve(data);
|
|
177
|
-
onDone();
|
|
178
|
-
},
|
|
179
|
-
error(data) {
|
|
180
|
-
reject(data);
|
|
181
|
-
},
|
|
182
|
-
complete() {
|
|
183
|
-
ac.abort();
|
|
184
|
-
onDone();
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
return promise;
|
|
189
|
-
}
|
|
190
|
-
__name(observableToPromise, "observableToPromise");
|
|
191
|
-
|
|
192
|
-
// ../../node_modules/@trpc/server/dist/observable-CUiPknO-.mjs
|
|
193
|
-
function share(_opts) {
|
|
194
|
-
return (source) => {
|
|
195
|
-
let refCount = 0;
|
|
196
|
-
let subscription = null;
|
|
197
|
-
const observers = [];
|
|
198
|
-
function startIfNeeded() {
|
|
199
|
-
if (subscription) return;
|
|
200
|
-
subscription = source.subscribe({
|
|
201
|
-
next(value) {
|
|
202
|
-
for (const observer of observers) {
|
|
203
|
-
var _observer$next;
|
|
204
|
-
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
error(error) {
|
|
208
|
-
for (const observer of observers) {
|
|
209
|
-
var _observer$error;
|
|
210
|
-
(_observer$error = observer.error) === null || _observer$error === void 0 || _observer$error.call(observer, error);
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
complete() {
|
|
214
|
-
for (const observer of observers) {
|
|
215
|
-
var _observer$complete;
|
|
216
|
-
(_observer$complete = observer.complete) === null || _observer$complete === void 0 || _observer$complete.call(observer);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
});
|
|
32
|
+
if (!identifier) {
|
|
33
|
+
identifier = this.generateIdentifier(value);
|
|
220
34
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
35
|
+
this.kv.set(identifier, value);
|
|
36
|
+
}
|
|
37
|
+
clear() {
|
|
38
|
+
this.kv.clear();
|
|
39
|
+
}
|
|
40
|
+
getIdentifier(value) {
|
|
41
|
+
return this.kv.getByValue(value);
|
|
42
|
+
}
|
|
43
|
+
getValue(identifier) {
|
|
44
|
+
return this.kv.getByKey(identifier);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class ClassRegistry extends Registry {
|
|
48
|
+
constructor() {
|
|
49
|
+
super((c) => c.name);
|
|
50
|
+
this.classToAllowedProps = /* @__PURE__ */ new Map();
|
|
51
|
+
}
|
|
52
|
+
register(value, options) {
|
|
53
|
+
if (typeof options === "object") {
|
|
54
|
+
if (options.allowProps) {
|
|
55
|
+
this.classToAllowedProps.set(value, options.allowProps);
|
|
227
56
|
}
|
|
57
|
+
super.register(value, options.identifier);
|
|
58
|
+
} else {
|
|
59
|
+
super.register(value, options);
|
|
228
60
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
startIfNeeded();
|
|
234
|
-
return { unsubscribe() {
|
|
235
|
-
refCount--;
|
|
236
|
-
resetIfNeeded();
|
|
237
|
-
const index = observers.findIndex((v) => v === subscriber);
|
|
238
|
-
if (index > -1) observers.splice(index, 1);
|
|
239
|
-
} };
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
__name(share, "share");
|
|
244
|
-
function behaviorSubject(initialValue) {
|
|
245
|
-
let value = initialValue;
|
|
246
|
-
const observerList = [];
|
|
247
|
-
const addObserver = /* @__PURE__ */ __name((observer) => {
|
|
248
|
-
if (value !== void 0) observer.next(value);
|
|
249
|
-
observerList.push(observer);
|
|
250
|
-
}, "addObserver");
|
|
251
|
-
const removeObserver = /* @__PURE__ */ __name((observer) => {
|
|
252
|
-
observerList.splice(observerList.indexOf(observer), 1);
|
|
253
|
-
}, "removeObserver");
|
|
254
|
-
const obs = observable((observer) => {
|
|
255
|
-
addObserver(observer);
|
|
256
|
-
return () => {
|
|
257
|
-
removeObserver(observer);
|
|
258
|
-
};
|
|
259
|
-
});
|
|
260
|
-
obs.next = (nextValue) => {
|
|
261
|
-
if (value === nextValue) return;
|
|
262
|
-
value = nextValue;
|
|
263
|
-
for (const observer of observerList) observer.next(nextValue);
|
|
264
|
-
};
|
|
265
|
-
obs.get = () => value;
|
|
266
|
-
return obs;
|
|
61
|
+
}
|
|
62
|
+
getAllowedProps(value) {
|
|
63
|
+
return this.classToAllowedProps.get(value);
|
|
64
|
+
}
|
|
267
65
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const subscription = next({
|
|
277
|
-
op,
|
|
278
|
-
next(nextOp) {
|
|
279
|
-
const nextObserver = execute(index + 1, nextOp);
|
|
280
|
-
return nextObserver;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
return subscription;
|
|
66
|
+
function valuesOfObj(record) {
|
|
67
|
+
if ("values" in Object) {
|
|
68
|
+
return Object.values(record);
|
|
69
|
+
}
|
|
70
|
+
const values = [];
|
|
71
|
+
for (const key in record) {
|
|
72
|
+
if (record.hasOwnProperty(key)) {
|
|
73
|
+
values.push(record[key]);
|
|
284
74
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return obs$.subscribe(observer);
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
__name(createChain, "createChain");
|
|
291
|
-
|
|
292
|
-
// ../../node_modules/@trpc/server/dist/codes-DagpWZLc.mjs
|
|
293
|
-
function isObject(value) {
|
|
294
|
-
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
75
|
+
}
|
|
76
|
+
return values;
|
|
295
77
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
78
|
+
function find(record, predicate) {
|
|
79
|
+
const values = valuesOfObj(record);
|
|
80
|
+
if ("find" in values) {
|
|
81
|
+
return values.find(predicate);
|
|
82
|
+
}
|
|
83
|
+
const valuesNotNever = values;
|
|
84
|
+
for (let i = 0; i < valuesNotNever.length; i++) {
|
|
85
|
+
const value = valuesNotNever[i];
|
|
86
|
+
if (predicate(value)) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return void 0;
|
|
299
91
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
function sleep(ms = 0) {
|
|
303
|
-
return new Promise((res) => setTimeout(res, ms));
|
|
92
|
+
function forEach(record, run) {
|
|
93
|
+
Object.entries(record).forEach(([key, value]) => run(value, key));
|
|
304
94
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
PARSE_ERROR: -32700,
|
|
308
|
-
BAD_REQUEST: -32600,
|
|
309
|
-
INTERNAL_SERVER_ERROR: -32603,
|
|
310
|
-
NOT_IMPLEMENTED: -32603,
|
|
311
|
-
BAD_GATEWAY: -32603,
|
|
312
|
-
SERVICE_UNAVAILABLE: -32603,
|
|
313
|
-
GATEWAY_TIMEOUT: -32603,
|
|
314
|
-
UNAUTHORIZED: -32001,
|
|
315
|
-
PAYMENT_REQUIRED: -32002,
|
|
316
|
-
FORBIDDEN: -32003,
|
|
317
|
-
NOT_FOUND: -32004,
|
|
318
|
-
METHOD_NOT_SUPPORTED: -32005,
|
|
319
|
-
TIMEOUT: -32008,
|
|
320
|
-
CONFLICT: -32009,
|
|
321
|
-
PRECONDITION_FAILED: -32012,
|
|
322
|
-
PAYLOAD_TOO_LARGE: -32013,
|
|
323
|
-
UNSUPPORTED_MEDIA_TYPE: -32015,
|
|
324
|
-
UNPROCESSABLE_CONTENT: -32022,
|
|
325
|
-
PRECONDITION_REQUIRED: -32028,
|
|
326
|
-
TOO_MANY_REQUESTS: -32029,
|
|
327
|
-
CLIENT_CLOSED_REQUEST: -32099
|
|
328
|
-
};
|
|
329
|
-
var retryableRpcCodes = [
|
|
330
|
-
TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
|
|
331
|
-
TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
|
|
332
|
-
TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
|
|
333
|
-
TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
|
|
334
|
-
];
|
|
335
|
-
|
|
336
|
-
// ../../node_modules/@trpc/server/dist/getErrorShape-BPSzUA7W.mjs
|
|
337
|
-
var __create2 = Object.create;
|
|
338
|
-
var __defProp3 = Object.defineProperty;
|
|
339
|
-
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
340
|
-
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
341
|
-
var __getProtoOf2 = Object.getPrototypeOf;
|
|
342
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
343
|
-
var __commonJS2 = /* @__PURE__ */ __name((cb, mod) => function() {
|
|
344
|
-
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
345
|
-
}, "__commonJS");
|
|
346
|
-
var __copyProps2 = /* @__PURE__ */ __name((to, from, except, desc) => {
|
|
347
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames2(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
348
|
-
key = keys[i];
|
|
349
|
-
if (!__hasOwnProp2.call(to, key) && key !== except) __defProp3(to, key, {
|
|
350
|
-
get: ((k) => from[k]).bind(null, key),
|
|
351
|
-
enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
return to;
|
|
355
|
-
}, "__copyProps");
|
|
356
|
-
var __toESM2 = /* @__PURE__ */ __name((mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(isNodeMode || !mod || !mod.__esModule ? __defProp3(target, "default", {
|
|
357
|
-
value: mod,
|
|
358
|
-
enumerable: true
|
|
359
|
-
}) : target, mod)), "__toESM");
|
|
360
|
-
var noop = /* @__PURE__ */ __name(() => {
|
|
361
|
-
}, "noop");
|
|
362
|
-
var freezeIfAvailable = /* @__PURE__ */ __name((obj) => {
|
|
363
|
-
if (Object.freeze) Object.freeze(obj);
|
|
364
|
-
}, "freezeIfAvailable");
|
|
365
|
-
function createInnerProxy(callback, path, memo) {
|
|
366
|
-
var _memo$cacheKey;
|
|
367
|
-
const cacheKey = path.join(".");
|
|
368
|
-
(_memo$cacheKey = memo[cacheKey]) !== null && _memo$cacheKey !== void 0 || (memo[cacheKey] = new Proxy(noop, {
|
|
369
|
-
get(_obj, key) {
|
|
370
|
-
if (typeof key !== "string" || key === "then") return void 0;
|
|
371
|
-
return createInnerProxy(callback, [...path, key], memo);
|
|
372
|
-
},
|
|
373
|
-
apply(_1, _2, args) {
|
|
374
|
-
const lastOfPath = path[path.length - 1];
|
|
375
|
-
if (lastOfPath === "valueOf" || lastOfPath === "toString" || lastOfPath === "toJSON") {
|
|
376
|
-
const debugPath = path.slice(0, -1).join(".");
|
|
377
|
-
return `tRPC.proxy(${debugPath})`;
|
|
378
|
-
}
|
|
379
|
-
let opts = {
|
|
380
|
-
args,
|
|
381
|
-
path
|
|
382
|
-
};
|
|
383
|
-
if (lastOfPath === "call") opts = {
|
|
384
|
-
args: args.length >= 2 ? [args[1]] : [],
|
|
385
|
-
path: path.slice(0, -1)
|
|
386
|
-
};
|
|
387
|
-
else if (lastOfPath === "apply") opts = {
|
|
388
|
-
args: args.length >= 2 ? args[1] : [],
|
|
389
|
-
path: path.slice(0, -1)
|
|
390
|
-
};
|
|
391
|
-
freezeIfAvailable(opts.args);
|
|
392
|
-
freezeIfAvailable(opts.path);
|
|
393
|
-
return callback(opts);
|
|
394
|
-
}
|
|
395
|
-
}));
|
|
396
|
-
return memo[cacheKey];
|
|
95
|
+
function includes(arr, value) {
|
|
96
|
+
return arr.indexOf(value) !== -1;
|
|
397
97
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return callback(name);
|
|
404
|
-
} });
|
|
405
|
-
}, "createFlatProxy");
|
|
406
|
-
var require_typeof2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
407
|
-
function _typeof$2(o) {
|
|
408
|
-
"@babel/helpers - typeof";
|
|
409
|
-
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
410
|
-
return typeof o$1;
|
|
411
|
-
} : function(o$1) {
|
|
412
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
413
|
-
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
414
|
-
}
|
|
415
|
-
__name(_typeof$2, "_typeof$2");
|
|
416
|
-
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
417
|
-
} });
|
|
418
|
-
var require_toPrimitive2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
419
|
-
var _typeof$1 = require_typeof2()["default"];
|
|
420
|
-
function toPrimitive$1(t, r) {
|
|
421
|
-
if ("object" != _typeof$1(t) || !t) return t;
|
|
422
|
-
var e = t[Symbol.toPrimitive];
|
|
423
|
-
if (void 0 !== e) {
|
|
424
|
-
var i = e.call(t, r || "default");
|
|
425
|
-
if ("object" != _typeof$1(i)) return i;
|
|
426
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
98
|
+
function findArr(record, predicate) {
|
|
99
|
+
for (let i = 0; i < record.length; i++) {
|
|
100
|
+
const value = record[i];
|
|
101
|
+
if (predicate(value)) {
|
|
102
|
+
return value;
|
|
427
103
|
}
|
|
428
|
-
return ("string" === r ? String : Number)(t);
|
|
429
|
-
}
|
|
430
|
-
__name(toPrimitive$1, "toPrimitive$1");
|
|
431
|
-
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
432
|
-
} });
|
|
433
|
-
var require_toPropertyKey2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
434
|
-
var _typeof = require_typeof2()["default"];
|
|
435
|
-
var toPrimitive = require_toPrimitive2();
|
|
436
|
-
function toPropertyKey$1(t) {
|
|
437
|
-
var i = toPrimitive(t, "string");
|
|
438
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
439
|
-
}
|
|
440
|
-
__name(toPropertyKey$1, "toPropertyKey$1");
|
|
441
|
-
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
442
|
-
} });
|
|
443
|
-
var require_defineProperty2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
444
|
-
var toPropertyKey = require_toPropertyKey2();
|
|
445
|
-
function _defineProperty(e, r, t) {
|
|
446
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
447
|
-
value: t,
|
|
448
|
-
enumerable: true,
|
|
449
|
-
configurable: true,
|
|
450
|
-
writable: true
|
|
451
|
-
}) : e[r] = t, e;
|
|
452
|
-
}
|
|
453
|
-
__name(_defineProperty, "_defineProperty");
|
|
454
|
-
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
455
|
-
} });
|
|
456
|
-
var require_objectSpread22 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
457
|
-
var defineProperty = require_defineProperty2();
|
|
458
|
-
function ownKeys(e, r) {
|
|
459
|
-
var t = Object.keys(e);
|
|
460
|
-
if (Object.getOwnPropertySymbols) {
|
|
461
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
462
|
-
r && (o = o.filter(function(r$1) {
|
|
463
|
-
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
464
|
-
})), t.push.apply(t, o);
|
|
465
|
-
}
|
|
466
|
-
return t;
|
|
467
|
-
}
|
|
468
|
-
__name(ownKeys, "ownKeys");
|
|
469
|
-
function _objectSpread2(e) {
|
|
470
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
471
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
472
|
-
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
473
|
-
defineProperty(e, r$1, t[r$1]);
|
|
474
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
475
|
-
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
return e;
|
|
479
|
-
}
|
|
480
|
-
__name(_objectSpread2, "_objectSpread2");
|
|
481
|
-
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
482
|
-
} });
|
|
483
|
-
var import_objectSpread2 = __toESM2(require_objectSpread22(), 1);
|
|
484
|
-
|
|
485
|
-
// ../../node_modules/@trpc/server/dist/tracked-DWInO6EQ.mjs
|
|
486
|
-
var import_defineProperty = __toESM2(require_defineProperty2(), 1);
|
|
487
|
-
var import_objectSpread2$1 = __toESM2(require_objectSpread22(), 1);
|
|
488
|
-
function transformResultInner(response, transformer) {
|
|
489
|
-
if ("error" in response) {
|
|
490
|
-
const error = transformer.deserialize(response.error);
|
|
491
|
-
return {
|
|
492
|
-
ok: false,
|
|
493
|
-
error: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, response), {}, { error })
|
|
494
|
-
};
|
|
495
104
|
}
|
|
496
|
-
|
|
497
|
-
type: "data",
|
|
498
|
-
data: transformer.deserialize(response.result.data)
|
|
499
|
-
});
|
|
500
|
-
return {
|
|
501
|
-
ok: true,
|
|
502
|
-
result
|
|
503
|
-
};
|
|
105
|
+
return void 0;
|
|
504
106
|
}
|
|
505
|
-
|
|
506
|
-
var TransformResultError = class extends Error {
|
|
507
|
-
static {
|
|
508
|
-
__name(this, "TransformResultError");
|
|
509
|
-
}
|
|
107
|
+
class CustomTransformerRegistry {
|
|
510
108
|
constructor() {
|
|
511
|
-
|
|
109
|
+
this.transfomers = {};
|
|
512
110
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
}
|
|
519
|
-
|
|
111
|
+
register(transformer) {
|
|
112
|
+
this.transfomers[transformer.name] = transformer;
|
|
113
|
+
}
|
|
114
|
+
findApplicable(v) {
|
|
115
|
+
return find(this.transfomers, (transformer) => transformer.isApplicable(v));
|
|
116
|
+
}
|
|
117
|
+
findByName(name) {
|
|
118
|
+
return this.transfomers[name];
|
|
520
119
|
}
|
|
521
|
-
if (!result.ok && (!isObject(result.error.error) || typeof result.error.error["code"] !== "number")) throw new TransformResultError();
|
|
522
|
-
if (result.ok && !isObject(result.result)) throw new TransformResultError();
|
|
523
|
-
return result;
|
|
524
|
-
}
|
|
525
|
-
__name(transformResult, "transformResult");
|
|
526
|
-
var import_objectSpread22 = __toESM2(require_objectSpread22(), 1);
|
|
527
|
-
|
|
528
|
-
// ../../node_modules/@trpc/client/dist/TRPCClientError-apv8gw59.mjs
|
|
529
|
-
var import_defineProperty2 = __toESM(require_defineProperty(), 1);
|
|
530
|
-
var import_objectSpread23 = __toESM(require_objectSpread2(), 1);
|
|
531
|
-
function isTRPCClientError(cause) {
|
|
532
|
-
return cause instanceof TRPCClientError;
|
|
533
|
-
}
|
|
534
|
-
__name(isTRPCClientError, "isTRPCClientError");
|
|
535
|
-
function isTRPCErrorResponse(obj) {
|
|
536
|
-
return isObject(obj) && isObject(obj["error"]) && typeof obj["error"]["code"] === "number" && typeof obj["error"]["message"] === "string";
|
|
537
|
-
}
|
|
538
|
-
__name(isTRPCErrorResponse, "isTRPCErrorResponse");
|
|
539
|
-
function getMessageFromUnknownError(err, fallback) {
|
|
540
|
-
if (typeof err === "string") return err;
|
|
541
|
-
if (isObject(err) && typeof err["message"] === "string") return err["message"];
|
|
542
|
-
return fallback;
|
|
543
120
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
121
|
+
const getType$1 = (payload) => Object.prototype.toString.call(payload).slice(8, -1);
|
|
122
|
+
const isUndefined = (payload) => typeof payload === "undefined";
|
|
123
|
+
const isNull = (payload) => payload === null;
|
|
124
|
+
const isPlainObject$1 = (payload) => {
|
|
125
|
+
if (typeof payload !== "object" || payload === null)
|
|
126
|
+
return false;
|
|
127
|
+
if (payload === Object.prototype)
|
|
128
|
+
return false;
|
|
129
|
+
if (Object.getPrototypeOf(payload) === null)
|
|
130
|
+
return true;
|
|
131
|
+
return Object.getPrototypeOf(payload) === Object.prototype;
|
|
132
|
+
};
|
|
133
|
+
const isEmptyObject = (payload) => isPlainObject$1(payload) && Object.keys(payload).length === 0;
|
|
134
|
+
const isArray$1 = (payload) => Array.isArray(payload);
|
|
135
|
+
const isString = (payload) => typeof payload === "string";
|
|
136
|
+
const isNumber = (payload) => typeof payload === "number" && !isNaN(payload);
|
|
137
|
+
const isBoolean = (payload) => typeof payload === "boolean";
|
|
138
|
+
const isRegExp = (payload) => payload instanceof RegExp;
|
|
139
|
+
const isMap = (payload) => payload instanceof Map;
|
|
140
|
+
const isSet = (payload) => payload instanceof Set;
|
|
141
|
+
const isSymbol = (payload) => getType$1(payload) === "Symbol";
|
|
142
|
+
const isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
|
|
143
|
+
const isError = (payload) => payload instanceof Error;
|
|
144
|
+
const isNaNValue = (payload) => typeof payload === "number" && isNaN(payload);
|
|
145
|
+
const isPrimitive = (payload) => isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
|
146
|
+
const isBigint = (payload) => typeof payload === "bigint";
|
|
147
|
+
const isInfinite = (payload) => payload === Infinity || payload === -Infinity;
|
|
148
|
+
const isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
|
|
149
|
+
const isURL = (payload) => payload instanceof URL;
|
|
150
|
+
const escapeKey = (key) => key.replace(/\\/g, "\\\\").replace(/\./g, "\\.");
|
|
151
|
+
const stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
|
|
152
|
+
const parsePath = (string, legacyPaths) => {
|
|
153
|
+
const result = [];
|
|
154
|
+
let segment = "";
|
|
155
|
+
for (let i = 0; i < string.length; i++) {
|
|
156
|
+
let char = string.charAt(i);
|
|
157
|
+
if (!legacyPaths && char === "\\") {
|
|
158
|
+
const escaped = string.charAt(i + 1);
|
|
159
|
+
if (escaped === "\\") {
|
|
160
|
+
segment += "\\";
|
|
161
|
+
i++;
|
|
162
|
+
continue;
|
|
163
|
+
} else if (escaped !== ".") {
|
|
164
|
+
throw Error("invalid path");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const isEscapedDot = char === "\\" && string.charAt(i + 1) === ".";
|
|
168
|
+
if (isEscapedDot) {
|
|
169
|
+
segment += ".";
|
|
170
|
+
i++;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
const isEndOfSegment = char === ".";
|
|
174
|
+
if (isEndOfSegment) {
|
|
175
|
+
result.push(segment);
|
|
176
|
+
segment = "";
|
|
177
|
+
continue;
|
|
569
178
|
}
|
|
570
|
-
|
|
571
|
-
result: cause,
|
|
572
|
-
cause: opts.cause
|
|
573
|
-
}));
|
|
574
|
-
return new TRPCClientError2(getMessageFromUnknownError(cause, "Unknown error"), (0, import_objectSpread23.default)((0, import_objectSpread23.default)({}, opts), {}, { cause }));
|
|
179
|
+
segment += char;
|
|
575
180
|
}
|
|
181
|
+
const lastSegment = segment;
|
|
182
|
+
result.push(lastSegment);
|
|
183
|
+
return result;
|
|
576
184
|
};
|
|
577
|
-
|
|
578
|
-
// ../../node_modules/@trpc/client/dist/unstable-internals-Bg7n9BBj.mjs
|
|
579
|
-
function getTransformer(transformer) {
|
|
580
|
-
const _transformer = transformer;
|
|
581
|
-
if (!_transformer) return {
|
|
582
|
-
input: {
|
|
583
|
-
serialize: /* @__PURE__ */ __name((data) => data, "serialize"),
|
|
584
|
-
deserialize: /* @__PURE__ */ __name((data) => data, "deserialize")
|
|
585
|
-
},
|
|
586
|
-
output: {
|
|
587
|
-
serialize: /* @__PURE__ */ __name((data) => data, "serialize"),
|
|
588
|
-
deserialize: /* @__PURE__ */ __name((data) => data, "deserialize")
|
|
589
|
-
}
|
|
590
|
-
};
|
|
591
|
-
if ("input" in _transformer) return _transformer;
|
|
185
|
+
function simpleTransformation(isApplicable, annotation, transform, untransform) {
|
|
592
186
|
return {
|
|
593
|
-
|
|
594
|
-
|
|
187
|
+
isApplicable,
|
|
188
|
+
annotation,
|
|
189
|
+
transform,
|
|
190
|
+
untransform
|
|
595
191
|
};
|
|
596
192
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
193
|
+
const simpleRules = [
|
|
194
|
+
simpleTransformation(isUndefined, "undefined", () => null, () => void 0),
|
|
195
|
+
simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => {
|
|
196
|
+
if (typeof BigInt !== "undefined") {
|
|
197
|
+
return BigInt(v);
|
|
198
|
+
}
|
|
199
|
+
console.error("Please add a BigInt polyfill.");
|
|
200
|
+
return v;
|
|
201
|
+
}),
|
|
202
|
+
simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
|
|
203
|
+
simpleTransformation(isError, "Error", (v, superJson) => {
|
|
204
|
+
const baseError = {
|
|
205
|
+
name: v.name,
|
|
206
|
+
message: v.message
|
|
207
|
+
};
|
|
208
|
+
if ("cause" in v) {
|
|
209
|
+
baseError.cause = v.cause;
|
|
210
|
+
}
|
|
211
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
212
|
+
baseError[prop] = v[prop];
|
|
213
|
+
});
|
|
214
|
+
return baseError;
|
|
215
|
+
}, (v, superJson) => {
|
|
216
|
+
const e = new Error(v.message, { cause: v.cause });
|
|
217
|
+
e.name = v.name;
|
|
218
|
+
e.stack = v.stack;
|
|
219
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
220
|
+
e[prop] = v[prop];
|
|
221
|
+
});
|
|
222
|
+
return e;
|
|
223
|
+
}),
|
|
224
|
+
simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => {
|
|
225
|
+
const body = regex.slice(1, regex.lastIndexOf("/"));
|
|
226
|
+
const flags = regex.slice(regex.lastIndexOf("/") + 1);
|
|
227
|
+
return new RegExp(body, flags);
|
|
228
|
+
}),
|
|
229
|
+
simpleTransformation(
|
|
230
|
+
isSet,
|
|
231
|
+
"set",
|
|
232
|
+
// (sets only exist in es6+)
|
|
233
|
+
// eslint-disable-next-line es5/no-es6-methods
|
|
234
|
+
(v) => [...v.values()],
|
|
235
|
+
(v) => new Set(v)
|
|
236
|
+
),
|
|
237
|
+
simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
|
|
238
|
+
simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => {
|
|
239
|
+
if (isNaNValue(v)) {
|
|
240
|
+
return "NaN";
|
|
241
|
+
}
|
|
242
|
+
if (v > 0) {
|
|
243
|
+
return "Infinity";
|
|
244
|
+
} else {
|
|
245
|
+
return "-Infinity";
|
|
246
|
+
}
|
|
247
|
+
}, Number),
|
|
248
|
+
simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
|
|
249
|
+
return "-0";
|
|
250
|
+
}, Number),
|
|
251
|
+
simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v))
|
|
252
|
+
];
|
|
253
|
+
function compositeTransformation(isApplicable, annotation, transform, untransform) {
|
|
610
254
|
return {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
255
|
+
isApplicable,
|
|
256
|
+
annotation,
|
|
257
|
+
transform,
|
|
258
|
+
untransform
|
|
615
259
|
};
|
|
616
260
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
261
|
+
const symbolRule = compositeTransformation((s, superJson) => {
|
|
262
|
+
if (isSymbol(s)) {
|
|
263
|
+
const isRegistered = !!superJson.symbolRegistry.getIdentifier(s);
|
|
264
|
+
return isRegistered;
|
|
265
|
+
}
|
|
266
|
+
return false;
|
|
267
|
+
}, (s, superJson) => {
|
|
268
|
+
const identifier = superJson.symbolRegistry.getIdentifier(s);
|
|
269
|
+
return ["symbol", identifier];
|
|
270
|
+
}, (v) => v.description, (_, a, superJson) => {
|
|
271
|
+
const value = superJson.symbolRegistry.getValue(a[1]);
|
|
272
|
+
if (!value) {
|
|
273
|
+
throw new Error("Trying to deserialize unknown symbol");
|
|
274
|
+
}
|
|
275
|
+
return value;
|
|
276
|
+
});
|
|
277
|
+
const constructorToName = [
|
|
278
|
+
Int8Array,
|
|
279
|
+
Uint8Array,
|
|
280
|
+
Int16Array,
|
|
281
|
+
Uint16Array,
|
|
282
|
+
Int32Array,
|
|
283
|
+
Uint32Array,
|
|
284
|
+
Float32Array,
|
|
285
|
+
Float64Array,
|
|
286
|
+
Uint8ClampedArray
|
|
287
|
+
].reduce((obj, ctor) => {
|
|
288
|
+
obj[ctor.name] = ctor;
|
|
289
|
+
return obj;
|
|
290
|
+
}, {});
|
|
291
|
+
const typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a) => {
|
|
292
|
+
const ctor = constructorToName[a[1]];
|
|
293
|
+
if (!ctor) {
|
|
294
|
+
throw new Error("Trying to deserialize unknown typed array");
|
|
295
|
+
}
|
|
296
|
+
return new ctor(v);
|
|
297
|
+
});
|
|
298
|
+
function isInstanceOfRegisteredClass(potentialClass, superJson) {
|
|
299
|
+
if (potentialClass?.constructor) {
|
|
300
|
+
const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
|
|
301
|
+
return isRegistered;
|
|
302
|
+
}
|
|
303
|
+
return false;
|
|
634
304
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
return
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
return
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
305
|
+
const classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
|
|
306
|
+
const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
|
|
307
|
+
return ["class", identifier];
|
|
308
|
+
}, (clazz, superJson) => {
|
|
309
|
+
const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
|
|
310
|
+
if (!allowedProps) {
|
|
311
|
+
return { ...clazz };
|
|
312
|
+
}
|
|
313
|
+
const result = {};
|
|
314
|
+
allowedProps.forEach((prop) => {
|
|
315
|
+
result[prop] = clazz[prop];
|
|
316
|
+
});
|
|
317
|
+
return result;
|
|
318
|
+
}, (v, a, superJson) => {
|
|
319
|
+
const clazz = superJson.classRegistry.getValue(a[1]);
|
|
320
|
+
if (!clazz) {
|
|
321
|
+
throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
|
|
322
|
+
}
|
|
323
|
+
return Object.assign(Object.create(clazz.prototype), v);
|
|
324
|
+
});
|
|
325
|
+
const customRule = compositeTransformation((value, superJson) => {
|
|
326
|
+
return !!superJson.customTransformerRegistry.findApplicable(value);
|
|
327
|
+
}, (value, superJson) => {
|
|
328
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
329
|
+
return ["custom", transformer.name];
|
|
330
|
+
}, (value, superJson) => {
|
|
331
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
332
|
+
return transformer.serialize(value);
|
|
333
|
+
}, (v, a, superJson) => {
|
|
334
|
+
const transformer = superJson.customTransformerRegistry.findByName(a[1]);
|
|
335
|
+
if (!transformer) {
|
|
336
|
+
throw new Error("Trying to deserialize unknown custom value");
|
|
337
|
+
}
|
|
338
|
+
return transformer.deserialize(v);
|
|
339
|
+
});
|
|
340
|
+
const compositeRules = [classRule, symbolRule, customRule, typedArrayRule];
|
|
341
|
+
const transformValue = (value, superJson) => {
|
|
342
|
+
const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
|
|
343
|
+
if (applicableCompositeRule) {
|
|
344
|
+
return {
|
|
345
|
+
value: applicableCompositeRule.transform(value, superJson),
|
|
346
|
+
type: applicableCompositeRule.annotation(value, superJson)
|
|
347
|
+
};
|
|
665
348
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
349
|
+
const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
|
|
350
|
+
if (applicableSimpleRule) {
|
|
351
|
+
return {
|
|
352
|
+
value: applicableSimpleRule.transform(value, superJson),
|
|
353
|
+
type: applicableSimpleRule.annotation
|
|
354
|
+
};
|
|
671
355
|
}
|
|
356
|
+
return void 0;
|
|
672
357
|
};
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
})();
|
|
691
|
-
const headers = (0, import_objectSpread24.default)((0, import_objectSpread24.default)((0, import_objectSpread24.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);
|
|
692
|
-
return getFetch(opts.fetch)(url, {
|
|
693
|
-
method,
|
|
694
|
-
signal: opts.signal,
|
|
695
|
-
body,
|
|
696
|
-
headers
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
__name(fetchHTTPResponse, "fetchHTTPResponse");
|
|
700
|
-
async function httpRequest(opts) {
|
|
701
|
-
const meta = {};
|
|
702
|
-
const res = await fetchHTTPResponse(opts);
|
|
703
|
-
meta.response = res;
|
|
704
|
-
const json = await res.json();
|
|
705
|
-
meta.responseJSON = json;
|
|
706
|
-
return {
|
|
707
|
-
json,
|
|
708
|
-
meta
|
|
709
|
-
};
|
|
710
|
-
}
|
|
711
|
-
__name(httpRequest, "httpRequest");
|
|
712
|
-
|
|
713
|
-
// ../../node_modules/@trpc/client/dist/httpLink-lG_6juPY.mjs
|
|
714
|
-
function isOctetType(input) {
|
|
715
|
-
return input instanceof Uint8Array || input instanceof Blob;
|
|
716
|
-
}
|
|
717
|
-
__name(isOctetType, "isOctetType");
|
|
718
|
-
function isFormData(input) {
|
|
719
|
-
return input instanceof FormData;
|
|
720
|
-
}
|
|
721
|
-
__name(isFormData, "isFormData");
|
|
722
|
-
var import_objectSpread25 = __toESM(require_objectSpread2(), 1);
|
|
723
|
-
var universalRequester = /* @__PURE__ */ __name((opts) => {
|
|
724
|
-
if ("input" in opts) {
|
|
725
|
-
const { input } = opts;
|
|
726
|
-
if (isFormData(input)) {
|
|
727
|
-
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations");
|
|
728
|
-
return httpRequest((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, opts), {}, {
|
|
729
|
-
contentTypeHeader: void 0,
|
|
730
|
-
getUrl,
|
|
731
|
-
getBody: /* @__PURE__ */ __name(() => input, "getBody")
|
|
732
|
-
}));
|
|
358
|
+
const simpleRulesByAnnotation = {};
|
|
359
|
+
simpleRules.forEach((rule) => {
|
|
360
|
+
simpleRulesByAnnotation[rule.annotation] = rule;
|
|
361
|
+
});
|
|
362
|
+
const untransformValue = (json, type, superJson) => {
|
|
363
|
+
if (isArray$1(type)) {
|
|
364
|
+
switch (type[0]) {
|
|
365
|
+
case "symbol":
|
|
366
|
+
return symbolRule.untransform(json, type, superJson);
|
|
367
|
+
case "class":
|
|
368
|
+
return classRule.untransform(json, type, superJson);
|
|
369
|
+
case "custom":
|
|
370
|
+
return customRule.untransform(json, type, superJson);
|
|
371
|
+
case "typed-array":
|
|
372
|
+
return typedArrayRule.untransform(json, type, superJson);
|
|
373
|
+
default:
|
|
374
|
+
throw new Error("Unknown transformation: " + type);
|
|
733
375
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
getUrl,
|
|
739
|
-
getBody: /* @__PURE__ */ __name(() => input, "getBody")
|
|
740
|
-
}));
|
|
376
|
+
} else {
|
|
377
|
+
const transformation = simpleRulesByAnnotation[type];
|
|
378
|
+
if (!transformation) {
|
|
379
|
+
throw new Error("Unknown transformation: " + type);
|
|
741
380
|
}
|
|
381
|
+
return transformation.untransform(json, superJson);
|
|
742
382
|
}
|
|
743
|
-
return jsonHttpRequester(opts);
|
|
744
|
-
}, "universalRequester");
|
|
745
|
-
function httpLink(opts) {
|
|
746
|
-
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
747
|
-
return () => {
|
|
748
|
-
return (operationOpts) => {
|
|
749
|
-
const { op } = operationOpts;
|
|
750
|
-
return observable((observer) => {
|
|
751
|
-
const { path, input, type } = op;
|
|
752
|
-
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
753
|
-
const request = universalRequester((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, resolvedOpts), {}, {
|
|
754
|
-
type,
|
|
755
|
-
path,
|
|
756
|
-
input,
|
|
757
|
-
signal: op.signal,
|
|
758
|
-
headers() {
|
|
759
|
-
if (!opts.headers) return {};
|
|
760
|
-
if (typeof opts.headers === "function") return opts.headers({ op });
|
|
761
|
-
return opts.headers;
|
|
762
|
-
}
|
|
763
|
-
}));
|
|
764
|
-
let meta = void 0;
|
|
765
|
-
request.then((res) => {
|
|
766
|
-
meta = res.meta;
|
|
767
|
-
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
768
|
-
if (!transformed.ok) {
|
|
769
|
-
observer.error(TRPCClientError.from(transformed.error, { meta }));
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
observer.next({
|
|
773
|
-
context: res.meta,
|
|
774
|
-
result: transformed.result
|
|
775
|
-
});
|
|
776
|
-
observer.complete();
|
|
777
|
-
}).catch((cause) => {
|
|
778
|
-
observer.error(TRPCClientError.from(cause, { meta }));
|
|
779
|
-
});
|
|
780
|
-
return () => {
|
|
781
|
-
};
|
|
782
|
-
});
|
|
783
|
-
};
|
|
784
|
-
};
|
|
785
|
-
}
|
|
786
|
-
__name(httpLink, "httpLink");
|
|
787
|
-
|
|
788
|
-
// ../../node_modules/@trpc/client/dist/httpBatchLink-LhidKAPw.mjs
|
|
789
|
-
var import_objectSpread26 = __toESM(require_objectSpread2(), 1);
|
|
790
|
-
|
|
791
|
-
// ../../node_modules/@trpc/client/dist/loggerLink-ineCN1PO.mjs
|
|
792
|
-
var import_objectSpread27 = __toESM(require_objectSpread2(), 1);
|
|
793
|
-
|
|
794
|
-
// ../../node_modules/@trpc/client/dist/wsLink-DSf4KOdW.mjs
|
|
795
|
-
var jsonEncoder = {
|
|
796
|
-
encode: /* @__PURE__ */ __name((data) => JSON.stringify(data), "encode"),
|
|
797
|
-
decode: /* @__PURE__ */ __name((data) => {
|
|
798
|
-
if (typeof data !== "string") throw new Error("jsonEncoder received binary data. JSON uses text frames. Use a binary encoder for binary data.");
|
|
799
|
-
return JSON.parse(data);
|
|
800
|
-
}, "decode")
|
|
801
|
-
};
|
|
802
|
-
var lazyDefaults = {
|
|
803
|
-
enabled: false,
|
|
804
|
-
closeMs: 0
|
|
805
|
-
};
|
|
806
|
-
var keepAliveDefaults = {
|
|
807
|
-
enabled: false,
|
|
808
|
-
pongTimeoutMs: 1e3,
|
|
809
|
-
intervalMs: 5e3
|
|
810
383
|
};
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
__name(this, "TRPCWebSocketClosedError");
|
|
821
|
-
}
|
|
822
|
-
constructor(opts) {
|
|
823
|
-
super(opts.message, { cause: opts.cause });
|
|
824
|
-
this.name = "TRPCWebSocketClosedError";
|
|
825
|
-
Object.setPrototypeOf(this, TRPCWebSocketClosedError2.prototype);
|
|
826
|
-
}
|
|
384
|
+
const getNthKey = (value, n) => {
|
|
385
|
+
if (n > value.size)
|
|
386
|
+
throw new Error("index out of bounds");
|
|
387
|
+
const keys = value.keys();
|
|
388
|
+
while (n > 0) {
|
|
389
|
+
keys.next();
|
|
390
|
+
n--;
|
|
391
|
+
}
|
|
392
|
+
return keys.next().value;
|
|
827
393
|
};
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
394
|
+
function validatePath(path) {
|
|
395
|
+
if (includes(path, "__proto__")) {
|
|
396
|
+
throw new Error("__proto__ is not allowed as a property");
|
|
831
397
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
this.timeoutMs = timeoutMs;
|
|
835
|
-
(0, import_defineProperty$3.default)(this, "timeout", void 0);
|
|
398
|
+
if (includes(path, "prototype")) {
|
|
399
|
+
throw new Error("prototype is not allowed as a property");
|
|
836
400
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
* Does nothing if no timeout is active.
|
|
840
|
-
*/
|
|
841
|
-
reset() {
|
|
842
|
-
if (!this.timeout) return;
|
|
843
|
-
clearTimeout(this.timeout);
|
|
844
|
-
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
845
|
-
}
|
|
846
|
-
start() {
|
|
847
|
-
clearTimeout(this.timeout);
|
|
848
|
-
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
849
|
-
}
|
|
850
|
-
stop() {
|
|
851
|
-
clearTimeout(this.timeout);
|
|
852
|
-
this.timeout = void 0;
|
|
401
|
+
if (includes(path, "constructor")) {
|
|
402
|
+
throw new Error("constructor is not allowed as a property");
|
|
853
403
|
}
|
|
854
|
-
};
|
|
855
|
-
function withResolvers() {
|
|
856
|
-
let resolve;
|
|
857
|
-
let reject;
|
|
858
|
-
const promise = new Promise((res, rej) => {
|
|
859
|
-
resolve = res;
|
|
860
|
-
reject = rej;
|
|
861
|
-
});
|
|
862
|
-
return {
|
|
863
|
-
promise,
|
|
864
|
-
resolve,
|
|
865
|
-
reject
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
__name(withResolvers, "withResolvers");
|
|
869
|
-
async function prepareUrl(urlOptions) {
|
|
870
|
-
const url = await resultOf(urlOptions.url);
|
|
871
|
-
if (!urlOptions.connectionParams) return url;
|
|
872
|
-
const prefix = url.includes("?") ? "&" : "?";
|
|
873
|
-
const connectionParams = `${prefix}connectionParams=1`;
|
|
874
|
-
return url + connectionParams;
|
|
875
|
-
}
|
|
876
|
-
__name(prepareUrl, "prepareUrl");
|
|
877
|
-
async function buildConnectionMessage(connectionParams, encoder) {
|
|
878
|
-
const message = {
|
|
879
|
-
method: "connectionParams",
|
|
880
|
-
data: await resultOf(connectionParams)
|
|
881
|
-
};
|
|
882
|
-
return encoder.encode(message);
|
|
883
404
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
*/
|
|
902
|
-
register(message, callbacks) {
|
|
903
|
-
const { promise: end, resolve } = withResolvers();
|
|
904
|
-
this.outgoingRequests.push({
|
|
905
|
-
id: String(message.id),
|
|
906
|
-
message,
|
|
907
|
-
end,
|
|
908
|
-
callbacks: {
|
|
909
|
-
next: callbacks.next,
|
|
910
|
-
complete: /* @__PURE__ */ __name(() => {
|
|
911
|
-
callbacks.complete();
|
|
912
|
-
resolve();
|
|
913
|
-
}, "complete"),
|
|
914
|
-
error: /* @__PURE__ */ __name((e) => {
|
|
915
|
-
callbacks.error(e);
|
|
916
|
-
resolve();
|
|
917
|
-
}, "error")
|
|
405
|
+
const getDeep = (object, path) => {
|
|
406
|
+
validatePath(path);
|
|
407
|
+
for (let i = 0; i < path.length; i++) {
|
|
408
|
+
const key = path[i];
|
|
409
|
+
if (isSet(object)) {
|
|
410
|
+
object = getNthKey(object, +key);
|
|
411
|
+
} else if (isMap(object)) {
|
|
412
|
+
const row = +key;
|
|
413
|
+
const type = +path[++i] === 0 ? "key" : "value";
|
|
414
|
+
const keyOfRow = getNthKey(object, row);
|
|
415
|
+
switch (type) {
|
|
416
|
+
case "key":
|
|
417
|
+
object = keyOfRow;
|
|
418
|
+
break;
|
|
419
|
+
case "value":
|
|
420
|
+
object = object.get(keyOfRow);
|
|
421
|
+
break;
|
|
918
422
|
}
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
callbacks.complete();
|
|
923
|
-
resolve();
|
|
924
|
-
};
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Deletes a request from both the outgoing and pending collections, if it exists.
|
|
928
|
-
*/
|
|
929
|
-
delete(messageId) {
|
|
930
|
-
if (messageId === null) return;
|
|
931
|
-
this.outgoingRequests = this.outgoingRequests.filter(({ id }) => id !== String(messageId));
|
|
932
|
-
delete this.pendingRequests[String(messageId)];
|
|
933
|
-
}
|
|
934
|
-
/**
|
|
935
|
-
* Moves all outgoing requests to the pending state and clears the outgoing queue.
|
|
936
|
-
*
|
|
937
|
-
* The caller is expected to handle the actual sending of the requests
|
|
938
|
-
* (e.g., sending them over the network) after this method is called.
|
|
939
|
-
*
|
|
940
|
-
* @returns The list of requests that were transitioned to the pending state.
|
|
941
|
-
*/
|
|
942
|
-
flush() {
|
|
943
|
-
const requests = this.outgoingRequests;
|
|
944
|
-
this.outgoingRequests = [];
|
|
945
|
-
for (const request of requests) this.pendingRequests[request.id] = request;
|
|
946
|
-
return requests;
|
|
423
|
+
} else {
|
|
424
|
+
object = object[key];
|
|
425
|
+
}
|
|
947
426
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
return
|
|
427
|
+
return object;
|
|
428
|
+
};
|
|
429
|
+
const setDeep = (object, path, mapper) => {
|
|
430
|
+
validatePath(path);
|
|
431
|
+
if (path.length === 0) {
|
|
432
|
+
return mapper(object);
|
|
433
|
+
}
|
|
434
|
+
let parent = object;
|
|
435
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
436
|
+
const key = path[i];
|
|
437
|
+
if (isArray$1(parent)) {
|
|
438
|
+
const index = +key;
|
|
439
|
+
parent = parent[index];
|
|
440
|
+
} else if (isPlainObject$1(parent)) {
|
|
441
|
+
parent = parent[key];
|
|
442
|
+
} else if (isSet(parent)) {
|
|
443
|
+
const row = +key;
|
|
444
|
+
parent = getNthKey(parent, row);
|
|
445
|
+
} else if (isMap(parent)) {
|
|
446
|
+
const isEnd = i === path.length - 2;
|
|
447
|
+
if (isEnd) {
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
const row = +key;
|
|
451
|
+
const type = +path[++i] === 0 ? "key" : "value";
|
|
452
|
+
const keyOfRow = getNthKey(parent, row);
|
|
453
|
+
switch (type) {
|
|
454
|
+
case "key":
|
|
455
|
+
parent = keyOfRow;
|
|
456
|
+
break;
|
|
457
|
+
case "value":
|
|
458
|
+
parent = parent.get(keyOfRow);
|
|
459
|
+
break;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
954
462
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
463
|
+
const lastKey = path[path.length - 1];
|
|
464
|
+
if (isArray$1(parent)) {
|
|
465
|
+
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
466
|
+
} else if (isPlainObject$1(parent)) {
|
|
467
|
+
parent[lastKey] = mapper(parent[lastKey]);
|
|
468
|
+
}
|
|
469
|
+
if (isSet(parent)) {
|
|
470
|
+
const oldValue = getNthKey(parent, +lastKey);
|
|
471
|
+
const newValue = mapper(oldValue);
|
|
472
|
+
if (oldValue !== newValue) {
|
|
473
|
+
parent.delete(oldValue);
|
|
474
|
+
parent.add(newValue);
|
|
475
|
+
}
|
|
961
476
|
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
477
|
+
if (isMap(parent)) {
|
|
478
|
+
const row = +path[path.length - 2];
|
|
479
|
+
const keyToRow = getNthKey(parent, row);
|
|
480
|
+
const type = +lastKey === 0 ? "key" : "value";
|
|
481
|
+
switch (type) {
|
|
482
|
+
case "key": {
|
|
483
|
+
const newKey = mapper(keyToRow);
|
|
484
|
+
parent.set(newKey, parent.get(keyToRow));
|
|
485
|
+
if (newKey !== keyToRow) {
|
|
486
|
+
parent.delete(keyToRow);
|
|
487
|
+
}
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
case "value": {
|
|
491
|
+
parent.set(keyToRow, mapper(parent.get(keyToRow)));
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
967
495
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
496
|
+
return object;
|
|
497
|
+
};
|
|
498
|
+
const enableLegacyPaths = (version) => version < 1;
|
|
499
|
+
function traverse(tree, walker2, version, origin = []) {
|
|
500
|
+
if (!tree) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
const legacyPaths = enableLegacyPaths(version);
|
|
504
|
+
if (!isArray$1(tree)) {
|
|
505
|
+
forEach(tree, (subtree, key) => traverse(subtree, walker2, version, [
|
|
506
|
+
...origin,
|
|
507
|
+
...parsePath(key, legacyPaths)
|
|
508
|
+
]));
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const [nodeValue, children] = tree;
|
|
512
|
+
if (children) {
|
|
513
|
+
forEach(children, (child, key) => {
|
|
514
|
+
traverse(child, walker2, version, [
|
|
515
|
+
...origin,
|
|
516
|
+
...parsePath(key, legacyPaths)
|
|
517
|
+
]);
|
|
518
|
+
});
|
|
985
519
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
520
|
+
walker2(nodeValue, origin);
|
|
521
|
+
}
|
|
522
|
+
function applyValueAnnotations(plain, annotations, version, superJson) {
|
|
523
|
+
traverse(annotations, (type, path) => {
|
|
524
|
+
plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
|
|
525
|
+
}, version);
|
|
526
|
+
return plain;
|
|
527
|
+
}
|
|
528
|
+
function applyReferentialEqualityAnnotations(plain, annotations, version) {
|
|
529
|
+
const legacyPaths = enableLegacyPaths(version);
|
|
530
|
+
function apply(identicalPaths, path) {
|
|
531
|
+
const object = getDeep(plain, parsePath(path, legacyPaths));
|
|
532
|
+
identicalPaths.map((path2) => parsePath(path2, legacyPaths)).forEach((identicalObjectPath) => {
|
|
533
|
+
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
534
|
+
});
|
|
991
535
|
}
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
536
|
+
if (isArray$1(annotations)) {
|
|
537
|
+
const [root, other] = annotations;
|
|
538
|
+
root.forEach((identicalPath) => {
|
|
539
|
+
plain = setDeep(plain, parsePath(identicalPath, legacyPaths), () => plain);
|
|
540
|
+
});
|
|
541
|
+
if (other) {
|
|
542
|
+
forEach(other, apply);
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
forEach(annotations, apply);
|
|
997
546
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
547
|
+
return plain;
|
|
548
|
+
}
|
|
549
|
+
const isDeep = (object, superJson) => isPlainObject$1(object) || isArray$1(object) || isMap(object) || isSet(object) || isError(object) || isInstanceOfRegisteredClass(object, superJson);
|
|
550
|
+
function addIdentity(object, path, identities) {
|
|
551
|
+
const existingSet = identities.get(object);
|
|
552
|
+
if (existingSet) {
|
|
553
|
+
existingSet.push(path);
|
|
554
|
+
} else {
|
|
555
|
+
identities.set(object, [path]);
|
|
1003
556
|
}
|
|
1004
|
-
};
|
|
1005
|
-
var import_defineProperty$1 = __toESM(require_defineProperty(), 1);
|
|
1006
|
-
function asyncWsOpen(ws) {
|
|
1007
|
-
const { promise, resolve, reject } = withResolvers();
|
|
1008
|
-
ws.addEventListener("open", () => {
|
|
1009
|
-
ws.removeEventListener("error", reject);
|
|
1010
|
-
resolve();
|
|
1011
|
-
});
|
|
1012
|
-
ws.addEventListener("error", reject);
|
|
1013
|
-
return promise;
|
|
1014
557
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
let
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}
|
|
1032
|
-
__name(reset, "reset");
|
|
1033
|
-
function pong() {
|
|
1034
|
-
clearTimeout(pongTimeout);
|
|
1035
|
-
reset();
|
|
1036
|
-
}
|
|
1037
|
-
__name(pong, "pong");
|
|
1038
|
-
ws.addEventListener("open", start);
|
|
1039
|
-
ws.addEventListener("message", ({ data }) => {
|
|
1040
|
-
clearTimeout(pingTimeout);
|
|
1041
|
-
start();
|
|
1042
|
-
if (data === "PONG") pong();
|
|
1043
|
-
});
|
|
1044
|
-
ws.addEventListener("close", () => {
|
|
1045
|
-
clearTimeout(pingTimeout);
|
|
1046
|
-
clearTimeout(pongTimeout);
|
|
558
|
+
function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
559
|
+
const result = {};
|
|
560
|
+
let rootEqualityPaths = void 0;
|
|
561
|
+
identitites.forEach((paths) => {
|
|
562
|
+
if (paths.length <= 1) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (!dedupe) {
|
|
566
|
+
paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length);
|
|
567
|
+
}
|
|
568
|
+
const [representativePath, ...identicalPaths] = paths;
|
|
569
|
+
if (representativePath.length === 0) {
|
|
570
|
+
rootEqualityPaths = identicalPaths.map(stringifyPath);
|
|
571
|
+
} else {
|
|
572
|
+
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
|
|
573
|
+
}
|
|
1047
574
|
});
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
(0, import_defineProperty$1.default)(this, "id", ++WsConnection2.connectCount);
|
|
1057
|
-
(0, import_defineProperty$1.default)(this, "WebSocketPonyfill", void 0);
|
|
1058
|
-
(0, import_defineProperty$1.default)(this, "urlOptions", void 0);
|
|
1059
|
-
(0, import_defineProperty$1.default)(this, "keepAliveOpts", void 0);
|
|
1060
|
-
(0, import_defineProperty$1.default)(this, "encoder", void 0);
|
|
1061
|
-
(0, import_defineProperty$1.default)(this, "wsObservable", behaviorSubject(null));
|
|
1062
|
-
(0, import_defineProperty$1.default)(this, "openPromise", null);
|
|
1063
|
-
this.WebSocketPonyfill = (_opts$WebSocketPonyfi = opts.WebSocketPonyfill) !== null && _opts$WebSocketPonyfi !== void 0 ? _opts$WebSocketPonyfi : WebSocket;
|
|
1064
|
-
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");
|
|
1065
|
-
this.urlOptions = opts.urlOptions;
|
|
1066
|
-
this.keepAliveOpts = opts.keepAlive;
|
|
1067
|
-
this.encoder = opts.encoder;
|
|
1068
|
-
}
|
|
1069
|
-
get ws() {
|
|
1070
|
-
return this.wsObservable.get();
|
|
1071
|
-
}
|
|
1072
|
-
set ws(ws) {
|
|
1073
|
-
this.wsObservable.next(ws);
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Checks if the WebSocket connection is open and ready to communicate.
|
|
1077
|
-
*/
|
|
1078
|
-
isOpen() {
|
|
1079
|
-
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise;
|
|
575
|
+
if (rootEqualityPaths) {
|
|
576
|
+
if (isEmptyObject(result)) {
|
|
577
|
+
return [rootEqualityPaths];
|
|
578
|
+
} else {
|
|
579
|
+
return [rootEqualityPaths, result];
|
|
580
|
+
}
|
|
581
|
+
} else {
|
|
582
|
+
return isEmptyObject(result) ? void 0 : result;
|
|
1080
583
|
}
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
const wsPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url));
|
|
1092
|
-
_this.openPromise = wsPromise.then(async (ws) => {
|
|
1093
|
-
_this.ws = ws;
|
|
1094
|
-
ws.binaryType = "arraybuffer";
|
|
1095
|
-
ws.addEventListener("message", function({ data }) {
|
|
1096
|
-
if (data === "PING") this.send("PONG");
|
|
1097
|
-
});
|
|
1098
|
-
if (_this.keepAliveOpts.enabled) setupPingInterval(ws, _this.keepAliveOpts);
|
|
1099
|
-
ws.addEventListener("close", () => {
|
|
1100
|
-
if (_this.ws === ws) _this.ws = null;
|
|
1101
|
-
});
|
|
1102
|
-
await asyncWsOpen(ws);
|
|
1103
|
-
if (_this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(_this.urlOptions.connectionParams, _this.encoder));
|
|
1104
|
-
});
|
|
1105
|
-
try {
|
|
1106
|
-
await _this.openPromise;
|
|
1107
|
-
} finally {
|
|
1108
|
-
_this.openPromise = null;
|
|
584
|
+
}
|
|
585
|
+
const walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
586
|
+
const primitive = isPrimitive(object);
|
|
587
|
+
if (!primitive) {
|
|
588
|
+
addIdentity(object, path, identities);
|
|
589
|
+
const seen = seenObjects.get(object);
|
|
590
|
+
if (seen) {
|
|
591
|
+
return dedupe ? {
|
|
592
|
+
transformedValue: null
|
|
593
|
+
} : seen;
|
|
1109
594
|
}
|
|
1110
595
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
(_this$ws = _this2.ws) === null || _this$ws === void 0 || _this$ws.close();
|
|
596
|
+
if (!isDeep(object, superJson)) {
|
|
597
|
+
const transformed2 = transformValue(object, superJson);
|
|
598
|
+
const result2 = transformed2 ? {
|
|
599
|
+
transformedValue: transformed2.value,
|
|
600
|
+
annotations: [transformed2.type]
|
|
601
|
+
} : {
|
|
602
|
+
transformedValue: object
|
|
603
|
+
};
|
|
604
|
+
if (!primitive) {
|
|
605
|
+
seenObjects.set(object, result2);
|
|
1122
606
|
}
|
|
607
|
+
return result2;
|
|
1123
608
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
if (connection.isOpen()) return {
|
|
1128
|
-
id: connection.id,
|
|
1129
|
-
state: "open",
|
|
1130
|
-
ws: connection.ws
|
|
1131
|
-
};
|
|
1132
|
-
if (connection.isClosed()) return {
|
|
1133
|
-
id: connection.id,
|
|
1134
|
-
state: "closed",
|
|
1135
|
-
ws: connection.ws
|
|
1136
|
-
};
|
|
1137
|
-
if (!connection.ws) return null;
|
|
1138
|
-
return {
|
|
1139
|
-
id: connection.id,
|
|
1140
|
-
state: "connecting",
|
|
1141
|
-
ws: connection.ws
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
__name(backwardCompatibility, "backwardCompatibility");
|
|
1145
|
-
var import_defineProperty3 = __toESM(require_defineProperty(), 1);
|
|
1146
|
-
var import_objectSpread28 = __toESM(require_objectSpread2(), 1);
|
|
1147
|
-
var WsClient = class {
|
|
1148
|
-
static {
|
|
1149
|
-
__name(this, "WsClient");
|
|
1150
|
-
}
|
|
1151
|
-
constructor(opts) {
|
|
1152
|
-
var _opts$experimental_en, _opts$retryDelayMs;
|
|
1153
|
-
(0, import_defineProperty3.default)(this, "connectionState", void 0);
|
|
1154
|
-
(0, import_defineProperty3.default)(this, "allowReconnect", false);
|
|
1155
|
-
(0, import_defineProperty3.default)(this, "requestManager", new RequestManager());
|
|
1156
|
-
(0, import_defineProperty3.default)(this, "activeConnection", void 0);
|
|
1157
|
-
(0, import_defineProperty3.default)(this, "reconnectRetryDelay", void 0);
|
|
1158
|
-
(0, import_defineProperty3.default)(this, "inactivityTimeout", void 0);
|
|
1159
|
-
(0, import_defineProperty3.default)(this, "callbacks", void 0);
|
|
1160
|
-
(0, import_defineProperty3.default)(this, "lazyMode", void 0);
|
|
1161
|
-
(0, import_defineProperty3.default)(this, "encoder", void 0);
|
|
1162
|
-
(0, import_defineProperty3.default)(this, "reconnecting", null);
|
|
1163
|
-
this.encoder = (_opts$experimental_en = opts.experimental_encoder) !== null && _opts$experimental_en !== void 0 ? _opts$experimental_en : jsonEncoder;
|
|
1164
|
-
this.callbacks = {
|
|
1165
|
-
onOpen: opts.onOpen,
|
|
1166
|
-
onClose: opts.onClose,
|
|
1167
|
-
onError: opts.onError
|
|
609
|
+
if (includes(objectsInThisPath, object)) {
|
|
610
|
+
return {
|
|
611
|
+
transformedValue: null
|
|
1168
612
|
};
|
|
1169
|
-
const lazyOptions = (0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, lazyDefaults), opts.lazy);
|
|
1170
|
-
this.inactivityTimeout = new ResettableTimeout(() => {
|
|
1171
|
-
if (this.requestManager.hasOutgoingRequests() || this.requestManager.hasPendingRequests()) {
|
|
1172
|
-
this.inactivityTimeout.reset();
|
|
1173
|
-
return;
|
|
1174
|
-
}
|
|
1175
|
-
this.close().catch(() => null);
|
|
1176
|
-
}, lazyOptions.closeMs);
|
|
1177
|
-
this.activeConnection = new WsConnection({
|
|
1178
|
-
WebSocketPonyfill: opts.WebSocket,
|
|
1179
|
-
urlOptions: opts,
|
|
1180
|
-
keepAlive: (0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, keepAliveDefaults), opts.keepAlive),
|
|
1181
|
-
encoder: this.encoder
|
|
1182
|
-
});
|
|
1183
|
-
this.activeConnection.wsObservable.subscribe({ next: /* @__PURE__ */ __name((ws) => {
|
|
1184
|
-
if (!ws) return;
|
|
1185
|
-
this.setupWebSocketListeners(ws);
|
|
1186
|
-
}, "next") });
|
|
1187
|
-
this.reconnectRetryDelay = (_opts$retryDelayMs = opts.retryDelayMs) !== null && _opts$retryDelayMs !== void 0 ? _opts$retryDelayMs : exponentialBackoff;
|
|
1188
|
-
this.lazyMode = lazyOptions.enabled;
|
|
1189
|
-
this.connectionState = behaviorSubject({
|
|
1190
|
-
type: "state",
|
|
1191
|
-
state: lazyOptions.enabled ? "idle" : "connecting",
|
|
1192
|
-
error: null
|
|
1193
|
-
});
|
|
1194
|
-
if (!this.lazyMode) this.open().catch(() => null);
|
|
1195
613
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
if (_this.connectionState.get().state === "idle") _this.connectionState.next({
|
|
1204
|
-
type: "state",
|
|
1205
|
-
state: "connecting",
|
|
1206
|
-
error: null
|
|
1207
|
-
});
|
|
1208
|
-
try {
|
|
1209
|
-
await _this.activeConnection.open();
|
|
1210
|
-
} catch (error) {
|
|
1211
|
-
_this.reconnect(new TRPCWebSocketClosedError({
|
|
1212
|
-
message: "Initialization error",
|
|
1213
|
-
cause: error
|
|
1214
|
-
}));
|
|
1215
|
-
return _this.reconnecting;
|
|
614
|
+
const transformationResult = transformValue(object, superJson);
|
|
615
|
+
const transformed = transformationResult?.value ?? object;
|
|
616
|
+
const transformedValue = isArray$1(transformed) ? [] : {};
|
|
617
|
+
const innerAnnotations = {};
|
|
618
|
+
forEach(transformed, (value, index) => {
|
|
619
|
+
if (index === "__proto__" || index === "constructor" || index === "prototype") {
|
|
620
|
+
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
1216
621
|
}
|
|
622
|
+
const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
|
|
623
|
+
transformedValue[index] = recursiveResult.transformedValue;
|
|
624
|
+
if (isArray$1(recursiveResult.annotations)) {
|
|
625
|
+
innerAnnotations[escapeKey(index)] = recursiveResult.annotations;
|
|
626
|
+
} else if (isPlainObject$1(recursiveResult.annotations)) {
|
|
627
|
+
forEach(recursiveResult.annotations, (tree, key) => {
|
|
628
|
+
innerAnnotations[escapeKey(index) + "." + key] = tree;
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
const result = isEmptyObject(innerAnnotations) ? {
|
|
633
|
+
transformedValue,
|
|
634
|
+
annotations: !!transformationResult ? [transformationResult.type] : void 0
|
|
635
|
+
} : {
|
|
636
|
+
transformedValue,
|
|
637
|
+
annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
|
|
638
|
+
};
|
|
639
|
+
if (!primitive) {
|
|
640
|
+
seenObjects.set(object, result);
|
|
1217
641
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
642
|
+
return result;
|
|
643
|
+
};
|
|
644
|
+
function getType(payload) {
|
|
645
|
+
return Object.prototype.toString.call(payload).slice(8, -1);
|
|
646
|
+
}
|
|
647
|
+
function isArray(payload) {
|
|
648
|
+
return getType(payload) === "Array";
|
|
649
|
+
}
|
|
650
|
+
function isPlainObject(payload) {
|
|
651
|
+
if (getType(payload) !== "Object")
|
|
652
|
+
return false;
|
|
653
|
+
const prototype = Object.getPrototypeOf(payload);
|
|
654
|
+
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
|
655
|
+
}
|
|
656
|
+
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
|
657
|
+
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
|
|
658
|
+
if (propType === "enumerable")
|
|
659
|
+
carry[key] = newVal;
|
|
660
|
+
if (includeNonenumerable && propType === "nonenumerable") {
|
|
661
|
+
Object.defineProperty(carry, key, {
|
|
662
|
+
value: newVal,
|
|
663
|
+
enumerable: false,
|
|
664
|
+
writable: true,
|
|
665
|
+
configurable: true
|
|
1236
666
|
});
|
|
1237
667
|
}
|
|
668
|
+
}
|
|
669
|
+
function copy(target, options = {}) {
|
|
670
|
+
if (isArray(target)) {
|
|
671
|
+
return target.map((item) => copy(item, options));
|
|
672
|
+
}
|
|
673
|
+
if (!isPlainObject(target)) {
|
|
674
|
+
return target;
|
|
675
|
+
}
|
|
676
|
+
const props = Object.getOwnPropertyNames(target);
|
|
677
|
+
const symbols = Object.getOwnPropertySymbols(target);
|
|
678
|
+
return [...props, ...symbols].reduce((carry, key) => {
|
|
679
|
+
if (key === "__proto__")
|
|
680
|
+
return carry;
|
|
681
|
+
if (isArray(options.props) && !options.props.includes(key)) {
|
|
682
|
+
return carry;
|
|
683
|
+
}
|
|
684
|
+
const val = target[key];
|
|
685
|
+
const newVal = copy(val, options);
|
|
686
|
+
assignProp(carry, key, newVal, target, options.nonenumerable);
|
|
687
|
+
return carry;
|
|
688
|
+
}, {});
|
|
689
|
+
}
|
|
690
|
+
class SuperJSON {
|
|
1238
691
|
/**
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
}, (0, import_objectSpread28.default)((0, import_objectSpread28.default)({}, observer), {}, { next(event) {
|
|
1259
|
-
const transformed = transformResult(event, transformer.output);
|
|
1260
|
-
if (!transformed.ok) {
|
|
1261
|
-
observer.error(TRPCClientError.from(transformed.error));
|
|
1262
|
-
return;
|
|
1263
|
-
}
|
|
1264
|
-
observer.next({ result: transformed.result });
|
|
1265
|
-
} }));
|
|
1266
|
-
return () => {
|
|
1267
|
-
abort();
|
|
1268
|
-
if (type === "subscription" && this.activeConnection.isOpen()) this.send({
|
|
1269
|
-
id,
|
|
1270
|
-
method: "subscription.stop"
|
|
1271
|
-
});
|
|
1272
|
-
signal === null || signal === void 0 || signal.removeEventListener("abort", abort);
|
|
692
|
+
* @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
|
|
693
|
+
*/
|
|
694
|
+
constructor({ dedupe = false } = {}) {
|
|
695
|
+
this.classRegistry = new ClassRegistry();
|
|
696
|
+
this.symbolRegistry = new Registry((s) => s.description ?? "");
|
|
697
|
+
this.customTransformerRegistry = new CustomTransformerRegistry();
|
|
698
|
+
this.allowedErrorProps = [];
|
|
699
|
+
this.dedupe = dedupe;
|
|
700
|
+
}
|
|
701
|
+
serialize(object) {
|
|
702
|
+
const identities = /* @__PURE__ */ new Map();
|
|
703
|
+
const output = walker(object, identities, this, this.dedupe);
|
|
704
|
+
const res = {
|
|
705
|
+
json: output.transformedValue
|
|
706
|
+
};
|
|
707
|
+
if (output.annotations) {
|
|
708
|
+
res.meta = {
|
|
709
|
+
...res.meta,
|
|
710
|
+
values: output.annotations
|
|
1273
711
|
};
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
get connection() {
|
|
1277
|
-
return backwardCompatibility(this.activeConnection);
|
|
1278
|
-
}
|
|
1279
|
-
reconnect(closedError) {
|
|
1280
|
-
var _this3 = this;
|
|
1281
|
-
this.connectionState.next({
|
|
1282
|
-
type: "state",
|
|
1283
|
-
state: "connecting",
|
|
1284
|
-
error: TRPCClientError.from(closedError)
|
|
1285
|
-
});
|
|
1286
|
-
if (this.reconnecting) return;
|
|
1287
|
-
const tryReconnect = /* @__PURE__ */ __name(async (attemptIndex) => {
|
|
1288
|
-
try {
|
|
1289
|
-
await sleep(_this3.reconnectRetryDelay(attemptIndex));
|
|
1290
|
-
if (_this3.allowReconnect) {
|
|
1291
|
-
await _this3.activeConnection.close();
|
|
1292
|
-
await _this3.activeConnection.open();
|
|
1293
|
-
if (_this3.requestManager.hasPendingRequests()) _this3.send(_this3.requestManager.getPendingRequests().map(({ message }) => message));
|
|
1294
|
-
}
|
|
1295
|
-
_this3.reconnecting = null;
|
|
1296
|
-
} catch (_unused) {
|
|
1297
|
-
await tryReconnect(attemptIndex + 1);
|
|
1298
|
-
}
|
|
1299
|
-
}, "tryReconnect");
|
|
1300
|
-
this.reconnecting = tryReconnect(0);
|
|
1301
|
-
}
|
|
1302
|
-
setupWebSocketListeners(ws) {
|
|
1303
|
-
var _this4 = this;
|
|
1304
|
-
const handleCloseOrError = /* @__PURE__ */ __name((cause) => {
|
|
1305
|
-
const reqs = this.requestManager.getPendingRequests();
|
|
1306
|
-
for (const { message, callbacks } of reqs) {
|
|
1307
|
-
if (message.method === "subscription") continue;
|
|
1308
|
-
callbacks.error(TRPCClientError.from(cause !== null && cause !== void 0 ? cause : new TRPCWebSocketClosedError({
|
|
1309
|
-
message: "WebSocket closed",
|
|
1310
|
-
cause
|
|
1311
|
-
})));
|
|
1312
|
-
this.requestManager.delete(message.id);
|
|
1313
|
-
}
|
|
1314
|
-
}, "handleCloseOrError");
|
|
1315
|
-
ws.addEventListener("open", () => {
|
|
1316
|
-
run(async () => {
|
|
1317
|
-
var _this$callbacks$onOpe, _this$callbacks;
|
|
1318
|
-
if (_this4.lazyMode) _this4.inactivityTimeout.start();
|
|
1319
|
-
(_this$callbacks$onOpe = (_this$callbacks = _this4.callbacks).onOpen) === null || _this$callbacks$onOpe === void 0 || _this$callbacks$onOpe.call(_this$callbacks);
|
|
1320
|
-
_this4.connectionState.next({
|
|
1321
|
-
type: "state",
|
|
1322
|
-
state: "pending",
|
|
1323
|
-
error: null
|
|
1324
|
-
});
|
|
1325
|
-
}).catch((error) => {
|
|
1326
|
-
ws.close(3e3);
|
|
1327
|
-
handleCloseOrError(error);
|
|
1328
|
-
});
|
|
1329
|
-
});
|
|
1330
|
-
ws.addEventListener("message", ({ data }) => {
|
|
1331
|
-
this.inactivityTimeout.reset();
|
|
1332
|
-
if (["PING", "PONG"].includes(data)) return;
|
|
1333
|
-
const incomingMessage = this.encoder.decode(data);
|
|
1334
|
-
if ("method" in incomingMessage) {
|
|
1335
|
-
this.handleIncomingRequest(incomingMessage);
|
|
1336
|
-
return;
|
|
1337
|
-
}
|
|
1338
|
-
this.handleResponseMessage(incomingMessage);
|
|
1339
|
-
});
|
|
1340
|
-
ws.addEventListener("close", (event) => {
|
|
1341
|
-
var _this$callbacks$onClo, _this$callbacks2;
|
|
1342
|
-
handleCloseOrError(event);
|
|
1343
|
-
(_this$callbacks$onClo = (_this$callbacks2 = this.callbacks).onClose) === null || _this$callbacks$onClo === void 0 || _this$callbacks$onClo.call(_this$callbacks2, event);
|
|
1344
|
-
if (!this.lazyMode || this.requestManager.hasPendingSubscriptions()) this.reconnect(new TRPCWebSocketClosedError({
|
|
1345
|
-
message: "WebSocket closed",
|
|
1346
|
-
cause: event
|
|
1347
|
-
}));
|
|
1348
|
-
});
|
|
1349
|
-
ws.addEventListener("error", (event) => {
|
|
1350
|
-
var _this$callbacks$onErr, _this$callbacks3;
|
|
1351
|
-
handleCloseOrError(event);
|
|
1352
|
-
(_this$callbacks$onErr = (_this$callbacks3 = this.callbacks).onError) === null || _this$callbacks$onErr === void 0 || _this$callbacks$onErr.call(_this$callbacks3, event);
|
|
1353
|
-
this.reconnect(new TRPCWebSocketClosedError({
|
|
1354
|
-
message: "WebSocket closed",
|
|
1355
|
-
cause: event
|
|
1356
|
-
}));
|
|
1357
|
-
});
|
|
1358
|
-
}
|
|
1359
|
-
handleResponseMessage(message) {
|
|
1360
|
-
const request = this.requestManager.getPendingRequest(message.id);
|
|
1361
|
-
if (!request) return;
|
|
1362
|
-
request.callbacks.next(message);
|
|
1363
|
-
let completed = true;
|
|
1364
|
-
if ("result" in message && request.message.method === "subscription") {
|
|
1365
|
-
if (message.result.type === "data") request.message.params.lastEventId = message.result.id;
|
|
1366
|
-
if (message.result.type !== "stopped") completed = false;
|
|
1367
712
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
713
|
+
const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
|
|
714
|
+
if (equalityAnnotations) {
|
|
715
|
+
res.meta = {
|
|
716
|
+
...res.meta,
|
|
717
|
+
referentialEqualities: equalityAnnotations
|
|
718
|
+
};
|
|
1371
719
|
}
|
|
720
|
+
if (res.meta)
|
|
721
|
+
res.meta.v = 1;
|
|
722
|
+
return res;
|
|
723
|
+
}
|
|
724
|
+
deserialize(payload, options) {
|
|
725
|
+
const { json, meta } = payload;
|
|
726
|
+
let result = options?.inPlace ? json : copy(json);
|
|
727
|
+
if (meta?.values) {
|
|
728
|
+
result = applyValueAnnotations(result, meta.values, meta.v ?? 0, this);
|
|
729
|
+
}
|
|
730
|
+
if (meta?.referentialEqualities) {
|
|
731
|
+
result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities, meta.v ?? 0);
|
|
732
|
+
}
|
|
733
|
+
return result;
|
|
1372
734
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Sends a message or batch of messages directly to the server.
|
|
1378
|
-
*/
|
|
1379
|
-
send(messageOrMessages) {
|
|
1380
|
-
if (!this.activeConnection.isOpen()) throw new Error("Active connection is not open");
|
|
1381
|
-
const messages = messageOrMessages instanceof Array ? messageOrMessages : [messageOrMessages];
|
|
1382
|
-
this.activeConnection.ws.send(this.encoder.encode(messages.length === 1 ? messages[0] : messages));
|
|
735
|
+
stringify(object) {
|
|
736
|
+
return JSON.stringify(this.serialize(object));
|
|
1383
737
|
}
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
*
|
|
1387
|
-
* @returns A function to abort the batched request.
|
|
1388
|
-
*/
|
|
1389
|
-
batchSend(message, callbacks) {
|
|
1390
|
-
var _this5 = this;
|
|
1391
|
-
this.inactivityTimeout.reset();
|
|
1392
|
-
run(async () => {
|
|
1393
|
-
if (!_this5.activeConnection.isOpen()) await _this5.open();
|
|
1394
|
-
await sleep(0);
|
|
1395
|
-
if (!_this5.requestManager.hasOutgoingRequests()) return;
|
|
1396
|
-
_this5.send(_this5.requestManager.flush().map(({ message: message$1 }) => message$1));
|
|
1397
|
-
}).catch((err) => {
|
|
1398
|
-
this.requestManager.delete(message.id);
|
|
1399
|
-
callbacks.error(TRPCClientError.from(err));
|
|
1400
|
-
});
|
|
1401
|
-
return this.requestManager.register(message, callbacks);
|
|
738
|
+
parse(string) {
|
|
739
|
+
return this.deserialize(JSON.parse(string), { inPlace: true });
|
|
1402
740
|
}
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
return new WsClient(opts);
|
|
1406
|
-
}
|
|
1407
|
-
__name(createWSClient, "createWSClient");
|
|
1408
|
-
function wsLink(opts) {
|
|
1409
|
-
const { client } = opts;
|
|
1410
|
-
const transformer = getTransformer(opts.transformer);
|
|
1411
|
-
return () => {
|
|
1412
|
-
return ({ op }) => {
|
|
1413
|
-
return observable((observer) => {
|
|
1414
|
-
const connStateSubscription = op.type === "subscription" ? client.connectionState.subscribe({ next(result) {
|
|
1415
|
-
observer.next({
|
|
1416
|
-
result,
|
|
1417
|
-
context: op.context
|
|
1418
|
-
});
|
|
1419
|
-
} }) : null;
|
|
1420
|
-
const requestSubscription = client.request({
|
|
1421
|
-
op,
|
|
1422
|
-
transformer
|
|
1423
|
-
}).subscribe(observer);
|
|
1424
|
-
return () => {
|
|
1425
|
-
requestSubscription.unsubscribe();
|
|
1426
|
-
connStateSubscription === null || connStateSubscription === void 0 || connStateSubscription.unsubscribe();
|
|
1427
|
-
};
|
|
1428
|
-
});
|
|
1429
|
-
};
|
|
1430
|
-
};
|
|
1431
|
-
}
|
|
1432
|
-
__name(wsLink, "wsLink");
|
|
1433
|
-
|
|
1434
|
-
// ../../node_modules/@trpc/client/dist/index.mjs
|
|
1435
|
-
var import_defineProperty4 = __toESM(require_defineProperty(), 1);
|
|
1436
|
-
var import_objectSpread2$4 = __toESM(require_objectSpread2(), 1);
|
|
1437
|
-
var TRPCUntypedClient = class {
|
|
1438
|
-
static {
|
|
1439
|
-
__name(this, "TRPCUntypedClient");
|
|
1440
|
-
}
|
|
1441
|
-
constructor(opts) {
|
|
1442
|
-
(0, import_defineProperty4.default)(this, "links", void 0);
|
|
1443
|
-
(0, import_defineProperty4.default)(this, "runtime", void 0);
|
|
1444
|
-
(0, import_defineProperty4.default)(this, "requestId", void 0);
|
|
1445
|
-
this.requestId = 0;
|
|
1446
|
-
this.runtime = {};
|
|
1447
|
-
this.links = opts.links.map((link) => link(this.runtime));
|
|
1448
|
-
}
|
|
1449
|
-
$request(opts) {
|
|
1450
|
-
var _opts$context;
|
|
1451
|
-
const chain$ = createChain({
|
|
1452
|
-
links: this.links,
|
|
1453
|
-
op: (0, import_objectSpread2$4.default)((0, import_objectSpread2$4.default)({}, opts), {}, {
|
|
1454
|
-
context: (_opts$context = opts.context) !== null && _opts$context !== void 0 ? _opts$context : {},
|
|
1455
|
-
id: ++this.requestId
|
|
1456
|
-
})
|
|
1457
|
-
});
|
|
1458
|
-
return chain$.pipe(share());
|
|
1459
|
-
}
|
|
1460
|
-
async requestAsPromise(opts) {
|
|
1461
|
-
var _this = this;
|
|
1462
|
-
try {
|
|
1463
|
-
const req$ = _this.$request(opts);
|
|
1464
|
-
const envelope = await observableToPromise(req$);
|
|
1465
|
-
const data = envelope.result.data;
|
|
1466
|
-
return data;
|
|
1467
|
-
} catch (err) {
|
|
1468
|
-
throw TRPCClientError.from(err);
|
|
1469
|
-
}
|
|
741
|
+
registerClass(v, options) {
|
|
742
|
+
this.classRegistry.register(v, options);
|
|
1470
743
|
}
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
type: "query",
|
|
1474
|
-
path,
|
|
1475
|
-
input,
|
|
1476
|
-
context: opts === null || opts === void 0 ? void 0 : opts.context,
|
|
1477
|
-
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
1478
|
-
});
|
|
744
|
+
registerSymbol(v, identifier) {
|
|
745
|
+
this.symbolRegistry.register(v, identifier);
|
|
1479
746
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
input,
|
|
1485
|
-
context: opts === null || opts === void 0 ? void 0 : opts.context,
|
|
1486
|
-
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
747
|
+
registerCustom(transformer, name) {
|
|
748
|
+
this.customTransformerRegistry.register({
|
|
749
|
+
name,
|
|
750
|
+
...transformer
|
|
1487
751
|
});
|
|
1488
752
|
}
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
type: "subscription",
|
|
1492
|
-
path,
|
|
1493
|
-
input,
|
|
1494
|
-
context: opts.context,
|
|
1495
|
-
signal: opts.signal
|
|
1496
|
-
});
|
|
1497
|
-
return observable$.subscribe({
|
|
1498
|
-
next(envelope) {
|
|
1499
|
-
switch (envelope.result.type) {
|
|
1500
|
-
case "state": {
|
|
1501
|
-
var _opts$onConnectionSta;
|
|
1502
|
-
(_opts$onConnectionSta = opts.onConnectionStateChange) === null || _opts$onConnectionSta === void 0 || _opts$onConnectionSta.call(opts, envelope.result);
|
|
1503
|
-
break;
|
|
1504
|
-
}
|
|
1505
|
-
case "started": {
|
|
1506
|
-
var _opts$onStarted;
|
|
1507
|
-
(_opts$onStarted = opts.onStarted) === null || _opts$onStarted === void 0 || _opts$onStarted.call(opts, { context: envelope.context });
|
|
1508
|
-
break;
|
|
1509
|
-
}
|
|
1510
|
-
case "stopped": {
|
|
1511
|
-
var _opts$onStopped;
|
|
1512
|
-
(_opts$onStopped = opts.onStopped) === null || _opts$onStopped === void 0 || _opts$onStopped.call(opts);
|
|
1513
|
-
break;
|
|
1514
|
-
}
|
|
1515
|
-
case "data":
|
|
1516
|
-
case void 0: {
|
|
1517
|
-
var _opts$onData;
|
|
1518
|
-
(_opts$onData = opts.onData) === null || _opts$onData === void 0 || _opts$onData.call(opts, envelope.result.data);
|
|
1519
|
-
break;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
},
|
|
1523
|
-
error(err) {
|
|
1524
|
-
var _opts$onError;
|
|
1525
|
-
(_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, err);
|
|
1526
|
-
},
|
|
1527
|
-
complete() {
|
|
1528
|
-
var _opts$onComplete;
|
|
1529
|
-
(_opts$onComplete = opts.onComplete) === null || _opts$onComplete === void 0 || _opts$onComplete.call(opts);
|
|
1530
|
-
}
|
|
1531
|
-
});
|
|
753
|
+
allowErrorProps(...props) {
|
|
754
|
+
this.allowedErrorProps.push(...props);
|
|
1532
755
|
}
|
|
1533
|
-
};
|
|
1534
|
-
var untypedClientSymbol = /* @__PURE__ */ Symbol.for("trpc_untypedClient");
|
|
1535
|
-
var clientCallTypeMap = {
|
|
1536
|
-
query: "query",
|
|
1537
|
-
mutate: "mutation",
|
|
1538
|
-
subscribe: "subscription"
|
|
1539
|
-
};
|
|
1540
|
-
var clientCallTypeToProcedureType = /* @__PURE__ */ __name((clientCallType) => {
|
|
1541
|
-
return clientCallTypeMap[clientCallType];
|
|
1542
|
-
}, "clientCallTypeToProcedureType");
|
|
1543
|
-
function createTRPCClientProxy(client) {
|
|
1544
|
-
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
1545
|
-
const pathCopy = [...path];
|
|
1546
|
-
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
1547
|
-
const fullPath = pathCopy.join(".");
|
|
1548
|
-
return client[procedureType](fullPath, ...args);
|
|
1549
|
-
});
|
|
1550
|
-
return createFlatProxy((key) => {
|
|
1551
|
-
if (key === untypedClientSymbol) return client;
|
|
1552
|
-
return proxy[key];
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
__name(createTRPCClientProxy, "createTRPCClientProxy");
|
|
1556
|
-
function createTRPCClient(opts) {
|
|
1557
|
-
const client = new TRPCUntypedClient(opts);
|
|
1558
|
-
const proxy = createTRPCClientProxy(client);
|
|
1559
|
-
return proxy;
|
|
1560
756
|
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
return AsyncFromSyncIterator = /* @__PURE__ */ __name(function AsyncFromSyncIterator$1(r$1) {
|
|
1588
|
-
this.s = r$1, this.n = r$1.next;
|
|
1589
|
-
}, "AsyncFromSyncIterator$1"), AsyncFromSyncIterator.prototype = {
|
|
1590
|
-
s: null,
|
|
1591
|
-
n: null,
|
|
1592
|
-
next: /* @__PURE__ */ __name(function next() {
|
|
1593
|
-
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
1594
|
-
}, "next"),
|
|
1595
|
-
"return": /* @__PURE__ */ __name(function _return(r$1) {
|
|
1596
|
-
var n = this.s["return"];
|
|
1597
|
-
return void 0 === n ? Promise.resolve({
|
|
1598
|
-
value: r$1,
|
|
1599
|
-
done: true
|
|
1600
|
-
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
1601
|
-
}, "_return"),
|
|
1602
|
-
"throw": /* @__PURE__ */ __name(function _throw(r$1) {
|
|
1603
|
-
var n = this.s["return"];
|
|
1604
|
-
return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
1605
|
-
}, "_throw")
|
|
1606
|
-
}, new AsyncFromSyncIterator(r);
|
|
1607
|
-
}
|
|
1608
|
-
__name(AsyncFromSyncIterator, "AsyncFromSyncIterator");
|
|
1609
|
-
module.exports = _asyncIterator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1610
|
-
} });
|
|
1611
|
-
var import_asyncIterator = __toESM(require_asyncIterator(), 1);
|
|
1612
|
-
var import_objectSpread2$12 = __toESM(require_objectSpread2(), 1);
|
|
1613
|
-
var require_usingCtx = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
|
|
1614
|
-
function _usingCtx() {
|
|
1615
|
-
var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
|
|
1616
|
-
var n$1 = Error();
|
|
1617
|
-
return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
|
|
1618
|
-
}, e = {}, n = [];
|
|
1619
|
-
function using(r$1, e$1) {
|
|
1620
|
-
if (null != e$1) {
|
|
1621
|
-
if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
1622
|
-
if (r$1) var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
1623
|
-
if (void 0 === o && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1)) var t = o;
|
|
1624
|
-
if ("function" != typeof o) throw new TypeError("Object is not disposable.");
|
|
1625
|
-
t && (o = /* @__PURE__ */ __name(function o$1() {
|
|
1626
|
-
try {
|
|
1627
|
-
t.call(e$1);
|
|
1628
|
-
} catch (r$2) {
|
|
1629
|
-
return Promise.reject(r$2);
|
|
1630
|
-
}
|
|
1631
|
-
}, "o$1")), n.push({
|
|
1632
|
-
v: e$1,
|
|
1633
|
-
d: o,
|
|
1634
|
-
a: r$1
|
|
1635
|
-
});
|
|
1636
|
-
} else r$1 && n.push({
|
|
1637
|
-
d: e$1,
|
|
1638
|
-
a: r$1
|
|
1639
|
-
});
|
|
1640
|
-
return e$1;
|
|
1641
|
-
}
|
|
1642
|
-
__name(using, "using");
|
|
1643
|
-
return {
|
|
1644
|
-
e,
|
|
1645
|
-
u: using.bind(null, false),
|
|
1646
|
-
a: using.bind(null, true),
|
|
1647
|
-
d: /* @__PURE__ */ __name(function d() {
|
|
1648
|
-
var o, t = this.e, s = 0;
|
|
1649
|
-
function next() {
|
|
1650
|
-
for (; o = n.pop(); ) try {
|
|
1651
|
-
if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
|
|
1652
|
-
if (o.d) {
|
|
1653
|
-
var r$1 = o.d.call(o.v);
|
|
1654
|
-
if (o.a) return s |= 2, Promise.resolve(r$1).then(next, err);
|
|
1655
|
-
} else s |= 1;
|
|
1656
|
-
} catch (r$2) {
|
|
1657
|
-
return err(r$2);
|
|
1658
|
-
}
|
|
1659
|
-
if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
1660
|
-
if (t !== e) throw t;
|
|
1661
|
-
}
|
|
1662
|
-
__name(next, "next");
|
|
1663
|
-
function err(n$1) {
|
|
1664
|
-
return t = t !== e ? new r(n$1, t) : n$1, next();
|
|
1665
|
-
}
|
|
1666
|
-
__name(err, "err");
|
|
1667
|
-
return next();
|
|
1668
|
-
}, "d")
|
|
1669
|
-
};
|
|
1670
|
-
}
|
|
1671
|
-
__name(_usingCtx, "_usingCtx");
|
|
1672
|
-
module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1673
|
-
} });
|
|
1674
|
-
var require_OverloadYield = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js"(exports, module) {
|
|
1675
|
-
function _OverloadYield(e, d) {
|
|
1676
|
-
this.v = e, this.k = d;
|
|
1677
|
-
}
|
|
1678
|
-
__name(_OverloadYield, "_OverloadYield");
|
|
1679
|
-
module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1680
|
-
} });
|
|
1681
|
-
var require_awaitAsyncGenerator = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js"(exports, module) {
|
|
1682
|
-
var OverloadYield$1 = require_OverloadYield();
|
|
1683
|
-
function _awaitAsyncGenerator$1(e) {
|
|
1684
|
-
return new OverloadYield$1(e, 0);
|
|
1685
|
-
}
|
|
1686
|
-
__name(_awaitAsyncGenerator$1, "_awaitAsyncGenerator$1");
|
|
1687
|
-
module.exports = _awaitAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1688
|
-
} });
|
|
1689
|
-
var require_wrapAsyncGenerator = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js"(exports, module) {
|
|
1690
|
-
var OverloadYield = require_OverloadYield();
|
|
1691
|
-
function _wrapAsyncGenerator$1(e) {
|
|
1692
|
-
return function() {
|
|
1693
|
-
return new AsyncGenerator(e.apply(this, arguments));
|
|
1694
|
-
};
|
|
1695
|
-
}
|
|
1696
|
-
__name(_wrapAsyncGenerator$1, "_wrapAsyncGenerator$1");
|
|
1697
|
-
function AsyncGenerator(e) {
|
|
1698
|
-
var r, t;
|
|
1699
|
-
function resume(r$1, t$1) {
|
|
1700
|
-
try {
|
|
1701
|
-
var n = e[r$1](t$1), o = n.value, u = o instanceof OverloadYield;
|
|
1702
|
-
Promise.resolve(u ? o.v : o).then(function(t$2) {
|
|
1703
|
-
if (u) {
|
|
1704
|
-
var i = "return" === r$1 ? "return" : "next";
|
|
1705
|
-
if (!o.k || t$2.done) return resume(i, t$2);
|
|
1706
|
-
t$2 = e[i](t$2).value;
|
|
1707
|
-
}
|
|
1708
|
-
settle(n.done ? "return" : "normal", t$2);
|
|
1709
|
-
}, function(e$1) {
|
|
1710
|
-
resume("throw", e$1);
|
|
1711
|
-
});
|
|
1712
|
-
} catch (e$1) {
|
|
1713
|
-
settle("throw", e$1);
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
__name(resume, "resume");
|
|
1717
|
-
function settle(e$1, n) {
|
|
1718
|
-
switch (e$1) {
|
|
1719
|
-
case "return":
|
|
1720
|
-
r.resolve({
|
|
1721
|
-
value: n,
|
|
1722
|
-
done: true
|
|
1723
|
-
});
|
|
1724
|
-
break;
|
|
1725
|
-
case "throw":
|
|
1726
|
-
r.reject(n);
|
|
1727
|
-
break;
|
|
1728
|
-
default:
|
|
1729
|
-
r.resolve({
|
|
1730
|
-
value: n,
|
|
1731
|
-
done: false
|
|
1732
|
-
});
|
|
1733
|
-
}
|
|
1734
|
-
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
1735
|
-
}
|
|
1736
|
-
__name(settle, "settle");
|
|
1737
|
-
this._invoke = function(e$1, n) {
|
|
1738
|
-
return new Promise(function(o, u) {
|
|
1739
|
-
var i = {
|
|
1740
|
-
key: e$1,
|
|
1741
|
-
arg: n,
|
|
1742
|
-
resolve: o,
|
|
1743
|
-
reject: u,
|
|
1744
|
-
next: null
|
|
1745
|
-
};
|
|
1746
|
-
t ? t = t.next = i : (r = t = i, resume(e$1, n));
|
|
1747
|
-
});
|
|
1748
|
-
}, "function" != typeof e["return"] && (this["return"] = void 0);
|
|
1749
|
-
}
|
|
1750
|
-
__name(AsyncGenerator, "AsyncGenerator");
|
|
1751
|
-
AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
1752
|
-
return this;
|
|
1753
|
-
}, AsyncGenerator.prototype.next = function(e) {
|
|
1754
|
-
return this._invoke("next", e);
|
|
1755
|
-
}, AsyncGenerator.prototype["throw"] = function(e) {
|
|
1756
|
-
return this._invoke("throw", e);
|
|
1757
|
-
}, AsyncGenerator.prototype["return"] = function(e) {
|
|
1758
|
-
return this._invoke("return", e);
|
|
1759
|
-
};
|
|
1760
|
-
module.exports = _wrapAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1761
|
-
} });
|
|
1762
|
-
var import_usingCtx = __toESM(require_usingCtx(), 1);
|
|
1763
|
-
var import_awaitAsyncGenerator = __toESM(require_awaitAsyncGenerator(), 1);
|
|
1764
|
-
var import_wrapAsyncGenerator = __toESM(require_wrapAsyncGenerator(), 1);
|
|
1765
|
-
var import_objectSpread29 = __toESM(require_objectSpread2(), 1);
|
|
1766
|
-
|
|
1767
|
-
// src/system.ts
|
|
1768
|
-
import superjson from "superjson";
|
|
1769
|
-
import { SystemMirror, createSystemProxy } from "@camstack/types";
|
|
1770
|
-
var WS_KEEP_ALIVE_INTERVAL_MS = 1e4;
|
|
1771
|
-
var WS_KEEP_ALIVE_PONG_TIMEOUT_MS = 3e3;
|
|
1772
|
-
var WS_RECONNECT_RETRY_DELAY_MS = 2e3;
|
|
1773
|
-
var WS_RECONNECT_MAX_RETRY_DELAY_MS = 3e4;
|
|
1774
|
-
var System = class {
|
|
1775
|
-
static {
|
|
1776
|
-
__name(this, "System");
|
|
1777
|
-
}
|
|
1778
|
-
serverUrl;
|
|
757
|
+
SuperJSON.defaultInstance = new SuperJSON();
|
|
758
|
+
SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
|
|
759
|
+
SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
|
|
760
|
+
SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
|
|
761
|
+
SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
|
|
762
|
+
SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
|
|
763
|
+
SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
|
|
764
|
+
SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
|
|
765
|
+
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
|
766
|
+
SuperJSON.serialize;
|
|
767
|
+
SuperJSON.deserialize;
|
|
768
|
+
SuperJSON.stringify;
|
|
769
|
+
SuperJSON.parse;
|
|
770
|
+
SuperJSON.registerClass;
|
|
771
|
+
SuperJSON.registerCustom;
|
|
772
|
+
SuperJSON.registerSymbol;
|
|
773
|
+
SuperJSON.allowErrorProps;
|
|
774
|
+
const WS_KEEP_ALIVE_INTERVAL_MS = 1e4;
|
|
775
|
+
const WS_KEEP_ALIVE_PONG_TIMEOUT_MS = 3e3;
|
|
776
|
+
const WS_RECONNECT_RETRY_DELAY_MS = 2e3;
|
|
777
|
+
const WS_RECONNECT_MAX_RETRY_DELAY_MS = 3e4;
|
|
778
|
+
class System {
|
|
779
|
+
/** Active server base URL. Mutable via `switchServerUrl()` so the
|
|
780
|
+
* endpoint-race helper can pivot the transport onto a LAN candidate
|
|
781
|
+
* after the initial public-URL bootstrap. */
|
|
782
|
+
_serverUrl;
|
|
1779
783
|
useWs;
|
|
1780
784
|
baseRetryMs;
|
|
1781
785
|
maxRetryMs;
|
|
@@ -1803,7 +807,7 @@ var System = class {
|
|
|
1803
807
|
_connectionVersion = 0;
|
|
1804
808
|
connectionListeners = /* @__PURE__ */ new Set();
|
|
1805
809
|
constructor(config) {
|
|
1806
|
-
this.
|
|
810
|
+
this._serverUrl = config.serverUrl.replace(/\/+$/, "");
|
|
1807
811
|
this.token = config.token;
|
|
1808
812
|
const isBrowser = typeof window !== "undefined";
|
|
1809
813
|
this.useWs = config.useWebSocket ?? isBrowser;
|
|
@@ -1814,15 +818,19 @@ var System = class {
|
|
|
1814
818
|
this._systemProxy = createSystemProxy(this._trpcClient);
|
|
1815
819
|
}
|
|
1816
820
|
// ── Connection state ─────────────────────────────────────────────
|
|
821
|
+
/** Active server base URL (no trailing slash). */
|
|
822
|
+
get serverUrl() {
|
|
823
|
+
return this._serverUrl;
|
|
824
|
+
}
|
|
1817
825
|
get connectionVersion() {
|
|
1818
826
|
return this._connectionVersion;
|
|
1819
827
|
}
|
|
1820
828
|
/**
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
829
|
+
* Subscribe to connection-state transitions. Called with `('connected'
|
|
830
|
+
* | 'disconnected' | 'connecting', version)` whenever the SDK opens,
|
|
831
|
+
* closes, or starts a manual reconnect. Listener errors are swallowed
|
|
832
|
+
* so a misbehaving consumer cannot break the SDK's event loop.
|
|
833
|
+
*/
|
|
1826
834
|
subscribeConnectionEvents(cb) {
|
|
1827
835
|
this.connectionListeners.add(cb);
|
|
1828
836
|
return () => {
|
|
@@ -1843,30 +851,30 @@ var System = class {
|
|
|
1843
851
|
}
|
|
1844
852
|
// ── Lifecycle ────────────────────────────────────────────────────
|
|
1845
853
|
/**
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
854
|
+
* Wait until the underlying tRPC transport is connected AND the
|
|
855
|
+
* server has responded to a cheap auth round-trip (`auth.me`). This
|
|
856
|
+
* is the canonical "ready to issue queries" gate.
|
|
857
|
+
*
|
|
858
|
+
* Why a probe, not just `ws.readyState === OPEN`?
|
|
859
|
+
* The WS handshake completes asynchronously: tRPC's `wsLink`
|
|
860
|
+
* queues outgoing messages and only flushes them after `open()`
|
|
861
|
+
* resolves (post `connectionParams` send). On the server, the
|
|
862
|
+
* tRPC context is created lazily once the connectionParams
|
|
863
|
+
* message is received. A query fired between WS-open and
|
|
864
|
+
* connection-params-processed is technically queued by tRPC, but
|
|
865
|
+
* the auth context for that query is only resolved once the
|
|
866
|
+
* handshake message is decoded server-side. A probe round-trip is
|
|
867
|
+
* the safest way to confirm both sides have agreed on the auth
|
|
868
|
+
* identity before the React tree starts firing parallel queries
|
|
869
|
+
* (which can otherwise land before any addon-side service
|
|
870
|
+
* discovery has settled, returning empty results that get cached).
|
|
871
|
+
*
|
|
872
|
+
* Idempotent — concurrent callers await the same in-flight Promise.
|
|
873
|
+
* Bounded by `timeoutMs` (default 15s) — beyond which a
|
|
874
|
+
* `Error('System.awaitConnected: probe timed out after Xms')` is
|
|
875
|
+
* thrown so the host can render a clear error state instead of
|
|
876
|
+
* hanging on a bricked socket.
|
|
877
|
+
*/
|
|
1870
878
|
async awaitConnected(timeoutMs) {
|
|
1871
879
|
if (this.connected) return;
|
|
1872
880
|
if (this.connectedPromise) return this.connectedPromise;
|
|
@@ -1877,14 +885,20 @@ var System = class {
|
|
|
1877
885
|
await probe;
|
|
1878
886
|
} else {
|
|
1879
887
|
await new Promise((resolve, reject) => {
|
|
1880
|
-
const timer = setTimeout(
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
888
|
+
const timer = setTimeout(
|
|
889
|
+
() => reject(new Error(`System.awaitConnected: probe timed out after ${effectiveTimeoutMs}ms`)),
|
|
890
|
+
effectiveTimeoutMs
|
|
891
|
+
);
|
|
892
|
+
probe.then(
|
|
893
|
+
() => {
|
|
894
|
+
clearTimeout(timer);
|
|
895
|
+
resolve();
|
|
896
|
+
},
|
|
897
|
+
(err) => {
|
|
898
|
+
clearTimeout(timer);
|
|
899
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
900
|
+
}
|
|
901
|
+
);
|
|
1888
902
|
});
|
|
1889
903
|
}
|
|
1890
904
|
this.connected = true;
|
|
@@ -1896,15 +910,15 @@ var System = class {
|
|
|
1896
910
|
}
|
|
1897
911
|
}
|
|
1898
912
|
/**
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
913
|
+
* Warm-boot the device mirror. Awaits the transport probe first
|
|
914
|
+
* (`awaitConnected`) so the three mirror round-trips
|
|
915
|
+
* (`getAllBindings` + `getAllSnapshots` + `listAll`) cannot race
|
|
916
|
+
* against the WS auth handshake. Subsequent `getDevice(id)` calls
|
|
917
|
+
* are sync; live `device.*` event subscriptions keep the caches
|
|
918
|
+
* fresh.
|
|
919
|
+
*
|
|
920
|
+
* Idempotent — concurrent callers await the same in-flight Promise.
|
|
921
|
+
*/
|
|
1908
922
|
async init(timeoutMs) {
|
|
1909
923
|
if (this.mirror?.isReady()) return;
|
|
1910
924
|
if (this.mirrorInit) return this.mirrorInit;
|
|
@@ -1933,11 +947,11 @@ var System = class {
|
|
|
1933
947
|
return this.connected;
|
|
1934
948
|
}
|
|
1935
949
|
/**
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
950
|
+
* Force a fresh WebSocket handshake. Tears down the wsClient + tRPC
|
|
951
|
+
* client + mirror (the mirror captures the tRPC reference at
|
|
952
|
+
* construction time and would otherwise dispatch through a closed
|
|
953
|
+
* client) and rebuilds them. No-op for HTTP transport.
|
|
954
|
+
*/
|
|
1941
955
|
reconnect() {
|
|
1942
956
|
if (!this.useWs) return;
|
|
1943
957
|
this.emitConnectionEvent("connecting");
|
|
@@ -1948,6 +962,76 @@ var System = class {
|
|
|
1948
962
|
this._trpcClient = this.buildTrpcClient();
|
|
1949
963
|
this._systemProxy = createSystemProxy(this._trpcClient);
|
|
1950
964
|
}
|
|
965
|
+
/**
|
|
966
|
+
* Pivot the underlying tRPC transport onto a different base URL.
|
|
967
|
+
* Used by the endpoint-race flow: the SDK opens against the public
|
|
968
|
+
* URL the operator provided, calls `localNetwork.getConnectionEndpoints`
|
|
969
|
+
* to discover LAN candidates, races them, and (when a faster one wins)
|
|
970
|
+
* calls `switchServerUrl(winner)` to migrate every subsequent query
|
|
971
|
+
* onto the LAN path without losing auth state.
|
|
972
|
+
*
|
|
973
|
+
* Keeps the auth token. Tears down the WS + mirror and rebuilds them
|
|
974
|
+
* against the new URL — same machinery as `reconnect()` but with a
|
|
975
|
+
* different target.
|
|
976
|
+
*/
|
|
977
|
+
switchServerUrl(nextUrl) {
|
|
978
|
+
const normalized = nextUrl.replace(/\/+$/, "");
|
|
979
|
+
if (normalized === this._serverUrl) return;
|
|
980
|
+
this._serverUrl = normalized;
|
|
981
|
+
this.reconnect();
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Race the candidate base URLs reported by the hub's `local-network`
|
|
985
|
+
* cap, pick the fastest one that responds, and (if it's different
|
|
986
|
+
* from the current URL) pivot the transport onto it.
|
|
987
|
+
*
|
|
988
|
+
* Flow:
|
|
989
|
+
* 1. Query `localNetwork.getConnectionEndpoints({ port })` over the
|
|
990
|
+
* already-authenticated tRPC channel — the cap is auth-gated,
|
|
991
|
+
* so the LAN IPs never leak to anonymous callers.
|
|
992
|
+
* 2. For each candidate, fire a HEAD on `{baseUrl}/trpc/health`
|
|
993
|
+
* with a short timeout (default 1500ms). The first 2xx wins.
|
|
994
|
+
* 3. If the winner differs from `this.serverUrl`, call
|
|
995
|
+
* `switchServerUrl(winner)` and return it. Otherwise return
|
|
996
|
+
* the current URL unchanged.
|
|
997
|
+
*
|
|
998
|
+
* Bounded — if every candidate times out we keep the current URL.
|
|
999
|
+
* Idempotent — safe to call on every connect / reconnect / network
|
|
1000
|
+
* change event.
|
|
1001
|
+
*/
|
|
1002
|
+
async raceConnectionEndpoints(options) {
|
|
1003
|
+
const timeoutMs = options?.perCandidateTimeoutMs ?? 1500;
|
|
1004
|
+
const url = (() => {
|
|
1005
|
+
try {
|
|
1006
|
+
return new URL(this._serverUrl);
|
|
1007
|
+
} catch {
|
|
1008
|
+
return null;
|
|
1009
|
+
}
|
|
1010
|
+
})();
|
|
1011
|
+
const port = url?.port ? Number(url.port) : url?.protocol === "https:" ? 443 : 80;
|
|
1012
|
+
const scheme = url?.protocol === "https:" ? "https" : "http";
|
|
1013
|
+
const proxy = this._trpcClient;
|
|
1014
|
+
const cap = proxy.localNetwork?.getConnectionEndpoints;
|
|
1015
|
+
if (!cap) {
|
|
1016
|
+
return { winner: this._serverUrl, switched: false };
|
|
1017
|
+
}
|
|
1018
|
+
let endpoints = [];
|
|
1019
|
+
try {
|
|
1020
|
+
const res = await cap.query({ port, ipv4Only: options?.ipv4Only, scheme });
|
|
1021
|
+
endpoints = res.endpoints;
|
|
1022
|
+
} catch {
|
|
1023
|
+
return { winner: this._serverUrl, switched: false };
|
|
1024
|
+
}
|
|
1025
|
+
if (endpoints.length === 0) {
|
|
1026
|
+
return { winner: this._serverUrl, switched: false };
|
|
1027
|
+
}
|
|
1028
|
+
const winner = await raceFastestEndpoint(endpoints.map((e) => e.baseUrl), timeoutMs);
|
|
1029
|
+
if (!winner || winner === this._serverUrl) {
|
|
1030
|
+
return { winner: winner ?? this._serverUrl, switched: false };
|
|
1031
|
+
}
|
|
1032
|
+
this.switchServerUrl(winner);
|
|
1033
|
+
return { winner, switched: true };
|
|
1034
|
+
}
|
|
1951
1035
|
/** Tear down WS connection + mirror. The instance is unusable afterwards. */
|
|
1952
1036
|
close() {
|
|
1953
1037
|
this.disposeMirror();
|
|
@@ -1962,10 +1046,7 @@ var System = class {
|
|
|
1962
1046
|
}
|
|
1963
1047
|
// ── Auth ──────────────────────────────────────────────────────────
|
|
1964
1048
|
async login(username, password) {
|
|
1965
|
-
const result = await this._trpcClient.auth.login.mutate({
|
|
1966
|
-
username,
|
|
1967
|
-
password
|
|
1968
|
-
});
|
|
1049
|
+
const result = await this._trpcClient.auth.login.mutate({ username, password });
|
|
1969
1050
|
if (typeof result === "object" && result !== null && "token" in result) {
|
|
1970
1051
|
const token = result.token;
|
|
1971
1052
|
if (typeof token === "string") this.setToken(token);
|
|
@@ -1985,24 +1066,24 @@ var System = class {
|
|
|
1985
1066
|
}
|
|
1986
1067
|
// ── Devices ──────────────────────────────────────────────────────
|
|
1987
1068
|
/**
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1069
|
+
* Synchronous snapshot of every device matching the optional filters.
|
|
1070
|
+
* Backed by the `SystemMirror` warm-boot cache — call `init()` first
|
|
1071
|
+
* (or `awaitReady()`) before invoking. Returns an empty array if the
|
|
1072
|
+
* mirror has not yet been booted.
|
|
1073
|
+
*
|
|
1074
|
+
* Each returned proxy has `binding` populated from the mirror's
|
|
1075
|
+
* binding cache (Phase 5 dedup), so consumers no longer need to
|
|
1076
|
+
* make a separate `deviceManager.getBindings` round-trip.
|
|
1077
|
+
*/
|
|
1997
1078
|
listDevices(filters) {
|
|
1998
1079
|
if (!this.mirror) return [];
|
|
1999
1080
|
const proxies = filters ? this.mirror.query(filters) : this.mirror.getAllDevices();
|
|
2000
1081
|
return proxies.map((p) => this.attachBinding(p));
|
|
2001
1082
|
}
|
|
2002
1083
|
/**
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
1084
|
+
* Sync lookup by numeric id. `null` if the mirror has not been booted
|
|
1085
|
+
* or the device is unknown.
|
|
1086
|
+
*/
|
|
2006
1087
|
getDevice(deviceId) {
|
|
2007
1088
|
const proxy = this.mirror?.getDeviceById(deviceId) ?? null;
|
|
2008
1089
|
return proxy ? this.attachBinding(proxy) : null;
|
|
@@ -2018,10 +1099,10 @@ var System = class {
|
|
|
2018
1099
|
return proxy ? this.attachBinding(proxy) : null;
|
|
2019
1100
|
}
|
|
2020
1101
|
/**
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
1102
|
+
* Resolve when a device with `deviceId` becomes available. Resolves
|
|
1103
|
+
* immediately if already known; rejects with a timeout error
|
|
1104
|
+
* otherwise (default 30s).
|
|
1105
|
+
*/
|
|
2025
1106
|
async waitForDevice(deviceId, timeoutMs) {
|
|
2026
1107
|
if (!this.mirror) await this.init();
|
|
2027
1108
|
const proxy = await this.mirror.waitForDevice(deviceId, timeoutMs ?? 3e4);
|
|
@@ -2042,12 +1123,12 @@ var System = class {
|
|
|
2042
1123
|
return this.mirror.onDeviceRemoved(cb);
|
|
2043
1124
|
}
|
|
2044
1125
|
/**
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
1126
|
+
* Patch the proxy's `binding` field from the mirror's cache. The
|
|
1127
|
+
* generated `createDeviceProxy()` already sets `binding` to the
|
|
1128
|
+
* binding it was constructed with — this is a defensive overwrite
|
|
1129
|
+
* that uses the latest cached entry in case a `binding-changed`
|
|
1130
|
+
* event landed between proxy creation and access.
|
|
1131
|
+
*/
|
|
2051
1132
|
attachBinding(proxy) {
|
|
2052
1133
|
const binding = this.lookupBinding(proxy.deviceId);
|
|
2053
1134
|
if (binding === proxy.binding) return proxy;
|
|
@@ -2135,26 +1216,27 @@ var System = class {
|
|
|
2135
1216
|
}
|
|
2136
1217
|
// ── Live events ──────────────────────────────────────────────────
|
|
2137
1218
|
/**
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
1219
|
+
* Subscribe to a single event category. Returns an unsubscribe
|
|
1220
|
+
* handle. Errors thrown by the listener are swallowed so a single
|
|
1221
|
+
* misbehaving consumer cannot tear down the WS subscription.
|
|
1222
|
+
*
|
|
1223
|
+
* Categories should be values from the `EventCategory` enum
|
|
1224
|
+
* (`@camstack/types`) — passing a raw string works for forward-compat
|
|
1225
|
+
* but loses type safety. The SDK forwards the value verbatim to the
|
|
1226
|
+
* server's `live.onEvent` subscription.
|
|
1227
|
+
*/
|
|
2147
1228
|
subscribeEvent(category, cb) {
|
|
2148
|
-
const sub = this._trpcClient.live.onEvent.subscribe(
|
|
2149
|
-
category
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
1229
|
+
const sub = this._trpcClient.live.onEvent.subscribe(
|
|
1230
|
+
{ category },
|
|
1231
|
+
{
|
|
1232
|
+
onData: (event) => {
|
|
1233
|
+
try {
|
|
1234
|
+
cb(event);
|
|
1235
|
+
} catch {
|
|
1236
|
+
}
|
|
2155
1237
|
}
|
|
2156
|
-
}
|
|
2157
|
-
|
|
1238
|
+
}
|
|
1239
|
+
);
|
|
2158
1240
|
return () => {
|
|
2159
1241
|
try {
|
|
2160
1242
|
sub.unsubscribe();
|
|
@@ -2172,71 +1254,94 @@ var System = class {
|
|
|
2172
1254
|
return this._trpcClient;
|
|
2173
1255
|
}
|
|
2174
1256
|
/**
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
1257
|
+
* Underlying WSClient (or `null` for HTTP transport). Used by
|
|
1258
|
+
* advanced consumers that need direct access to the WebSocket
|
|
1259
|
+
* (e.g. for keep-alive metrics). Rebuilt on `reconnect()`.
|
|
1260
|
+
*/
|
|
2179
1261
|
get wsClient() {
|
|
2180
1262
|
return this._wsClient;
|
|
2181
1263
|
}
|
|
2182
1264
|
// ── Internals ────────────────────────────────────────────────────
|
|
2183
1265
|
buildTrpcClient() {
|
|
2184
|
-
const headers =
|
|
1266
|
+
const headers = () => {
|
|
2185
1267
|
const h = {};
|
|
2186
1268
|
if (this.token) h["Authorization"] = `Bearer ${this.token}`;
|
|
2187
1269
|
return h;
|
|
2188
|
-
}
|
|
1270
|
+
};
|
|
2189
1271
|
if (this.useWs) {
|
|
2190
|
-
const wsUrl = this.
|
|
1272
|
+
const wsUrl = this._serverUrl.replace(/^http/, "ws") + "/trpc";
|
|
2191
1273
|
const baseRetryMs = this.baseRetryMs;
|
|
2192
1274
|
const maxRetryMs = this.maxRetryMs;
|
|
2193
1275
|
this._wsClient = createWSClient({
|
|
2194
1276
|
url: wsUrl,
|
|
2195
|
-
connectionParams:
|
|
2196
|
-
|
|
2197
|
-
}), "connectionParams"),
|
|
2198
|
-
retryDelayMs: /* @__PURE__ */ __name((attemptIndex) => Math.min(baseRetryMs * Math.pow(2, attemptIndex), maxRetryMs), "retryDelayMs"),
|
|
1277
|
+
connectionParams: () => ({ token: this.token }),
|
|
1278
|
+
retryDelayMs: (attemptIndex) => Math.min(baseRetryMs * Math.pow(2, attemptIndex), maxRetryMs),
|
|
2199
1279
|
keepAlive: {
|
|
2200
1280
|
enabled: true,
|
|
2201
1281
|
intervalMs: WS_KEEP_ALIVE_INTERVAL_MS,
|
|
2202
1282
|
pongTimeoutMs: WS_KEEP_ALIVE_PONG_TIMEOUT_MS
|
|
2203
1283
|
},
|
|
2204
|
-
onOpen:
|
|
1284
|
+
onOpen: () => {
|
|
2205
1285
|
this._connectionVersion += 1;
|
|
2206
1286
|
this.emitConnectionEvent("connected");
|
|
2207
|
-
},
|
|
2208
|
-
onClose:
|
|
1287
|
+
},
|
|
1288
|
+
onClose: () => {
|
|
2209
1289
|
this.emitConnectionEvent("disconnected");
|
|
2210
|
-
}
|
|
1290
|
+
}
|
|
2211
1291
|
});
|
|
2212
1292
|
return createTRPCClient({
|
|
2213
|
-
links: [
|
|
2214
|
-
wsLink({
|
|
2215
|
-
client: this._wsClient,
|
|
2216
|
-
transformer: superjson
|
|
2217
|
-
})
|
|
2218
|
-
]
|
|
1293
|
+
links: [wsLink({ client: this._wsClient, transformer: SuperJSON })]
|
|
2219
1294
|
});
|
|
2220
1295
|
}
|
|
2221
1296
|
this._wsClient = null;
|
|
2222
1297
|
return createTRPCClient({
|
|
2223
|
-
links: [
|
|
2224
|
-
httpLink({
|
|
2225
|
-
url: `${this.serverUrl}/trpc`,
|
|
2226
|
-
headers,
|
|
2227
|
-
transformer: superjson
|
|
2228
|
-
})
|
|
2229
|
-
]
|
|
1298
|
+
links: [httpLink({ url: `${this._serverUrl}/trpc`, headers, transformer: SuperJSON })]
|
|
2230
1299
|
});
|
|
2231
1300
|
}
|
|
2232
|
-
}
|
|
1301
|
+
}
|
|
2233
1302
|
function createSystem(config) {
|
|
2234
1303
|
return new System(config);
|
|
2235
1304
|
}
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
1305
|
+
async function raceFastestEndpoint(candidates, timeoutMs) {
|
|
1306
|
+
if (candidates.length === 0) return null;
|
|
1307
|
+
if (typeof fetch !== "function") return candidates[0] ?? null;
|
|
1308
|
+
const pageIsHttps = typeof window !== "undefined" && typeof window.location !== "undefined" && window.location.protocol === "https:";
|
|
1309
|
+
const reachable = pageIsHttps ? candidates.filter((u) => u.toLowerCase().startsWith("https://")) : candidates;
|
|
1310
|
+
if (reachable.length === 0) return null;
|
|
1311
|
+
const controllers = reachable.map(() => new AbortController());
|
|
1312
|
+
const probes = reachable.map(async (baseUrl, i) => {
|
|
1313
|
+
const ctrl = controllers[i];
|
|
1314
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
1315
|
+
try {
|
|
1316
|
+
const res = await fetch(`${baseUrl.replace(/\/+$/, "")}/trpc/health`, {
|
|
1317
|
+
method: "GET",
|
|
1318
|
+
signal: ctrl.signal,
|
|
1319
|
+
// Cross-origin probes from a browser sandbox are fine — the
|
|
1320
|
+
// /trpc/health response is open-CORS by the Fastify default.
|
|
1321
|
+
// No credentials needed (this is a transport-quality probe,
|
|
1322
|
+
// not an auth round-trip).
|
|
1323
|
+
credentials: "omit"
|
|
1324
|
+
});
|
|
1325
|
+
if (!res.ok) throw new Error(`${res.status}`);
|
|
1326
|
+
return baseUrl;
|
|
1327
|
+
} finally {
|
|
1328
|
+
clearTimeout(timer);
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
try {
|
|
1332
|
+
const winner = await Promise.any(probes);
|
|
1333
|
+
for (const c of controllers) {
|
|
1334
|
+
try {
|
|
1335
|
+
c.abort();
|
|
1336
|
+
} catch {
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
return winner;
|
|
1340
|
+
} catch {
|
|
1341
|
+
return null;
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
var DetectionClass = /* @__PURE__ */ ((DetectionClass2) => {
|
|
2240
1345
|
DetectionClass2["Motion"] = "motion";
|
|
2241
1346
|
DetectionClass2["Person"] = "person";
|
|
2242
1347
|
DetectionClass2["Vehicle"] = "vehicle";
|
|
@@ -2248,8 +1353,8 @@ var DetectionClass = /* @__PURE__ */ (function(DetectionClass2) {
|
|
|
2248
1353
|
DetectionClass2["Doorbell"] = "doorbell";
|
|
2249
1354
|
DetectionClass2["Sensor"] = "sensor";
|
|
2250
1355
|
return DetectionClass2;
|
|
2251
|
-
})({});
|
|
2252
|
-
|
|
1356
|
+
})(DetectionClass || {});
|
|
1357
|
+
const animalClasses = [
|
|
2253
1358
|
"animal",
|
|
2254
1359
|
"dog_cat",
|
|
2255
1360
|
"dog",
|
|
@@ -2277,7 +1382,7 @@ var animalClasses = [
|
|
|
2277
1382
|
"turtle",
|
|
2278
1383
|
"lizard"
|
|
2279
1384
|
];
|
|
2280
|
-
|
|
1385
|
+
const personClasses = [
|
|
2281
1386
|
"person",
|
|
2282
1387
|
"people",
|
|
2283
1388
|
"pedestrian",
|
|
@@ -2291,7 +1396,7 @@ var personClasses = [
|
|
|
2291
1396
|
"head",
|
|
2292
1397
|
"body"
|
|
2293
1398
|
];
|
|
2294
|
-
|
|
1399
|
+
const vehicleClasses = [
|
|
2295
1400
|
"vehicle",
|
|
2296
1401
|
"car",
|
|
2297
1402
|
"truck",
|
|
@@ -2310,7 +1415,7 @@ var vehicleClasses = [
|
|
|
2310
1415
|
"ship",
|
|
2311
1416
|
"helicopter"
|
|
2312
1417
|
];
|
|
2313
|
-
|
|
1418
|
+
const faceClasses = [
|
|
2314
1419
|
"face",
|
|
2315
1420
|
"eyes",
|
|
2316
1421
|
"nose",
|
|
@@ -2338,7 +1443,7 @@ var faceClasses = [
|
|
|
2338
1443
|
"facial_landmark",
|
|
2339
1444
|
"facial_keypoint"
|
|
2340
1445
|
];
|
|
2341
|
-
|
|
1446
|
+
const licensePlateClasses = [
|
|
2342
1447
|
"plate",
|
|
2343
1448
|
"license_plate",
|
|
2344
1449
|
"front_plate",
|
|
@@ -2362,19 +1467,13 @@ var licensePlateClasses = [
|
|
|
2362
1467
|
"obscured_plate",
|
|
2363
1468
|
"dirty_plate"
|
|
2364
1469
|
];
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
"other"
|
|
2369
|
-
];
|
|
2370
|
-
var packageClasses = [
|
|
2371
|
-
"package",
|
|
2372
|
-
"packet"
|
|
2373
|
-
];
|
|
2374
|
-
var audioClasses = [
|
|
1470
|
+
const motionClasses = ["motion", "movement", "other"];
|
|
1471
|
+
const packageClasses = ["package", "packet"];
|
|
1472
|
+
const audioClasses = [
|
|
2375
1473
|
"audio"
|
|
1474
|
+
/* Audio */
|
|
2376
1475
|
];
|
|
2377
|
-
|
|
1476
|
+
const audioLabelClasses = [
|
|
2378
1477
|
"speech",
|
|
2379
1478
|
"scream",
|
|
2380
1479
|
"babbling",
|
|
@@ -2435,11 +1534,8 @@ var audioLabelClasses = [
|
|
|
2435
1534
|
"dog",
|
|
2436
1535
|
"dogs"
|
|
2437
1536
|
];
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
"ring"
|
|
2441
|
-
];
|
|
2442
|
-
var sensorLabelClasses = [
|
|
1537
|
+
const doorbellClasses = ["doorbell", "ring"];
|
|
1538
|
+
const sensorLabelClasses = [
|
|
2443
1539
|
"lock",
|
|
2444
1540
|
"binary",
|
|
2445
1541
|
"flood",
|
|
@@ -2450,92 +1546,113 @@ var sensorLabelClasses = [
|
|
|
2450
1546
|
"flooded",
|
|
2451
1547
|
"entry_open"
|
|
2452
1548
|
];
|
|
2453
|
-
|
|
1549
|
+
const detectionClassesDefaultMap = {
|
|
2454
1550
|
...animalClasses.reduce((tot, curr) => ({
|
|
2455
1551
|
...tot,
|
|
2456
1552
|
[curr]: "animal"
|
|
1553
|
+
/* Animal */
|
|
2457
1554
|
}), {}),
|
|
2458
1555
|
...personClasses.reduce((tot, curr) => ({
|
|
2459
1556
|
...tot,
|
|
2460
1557
|
[curr]: "person"
|
|
1558
|
+
/* Person */
|
|
2461
1559
|
}), {}),
|
|
2462
1560
|
...vehicleClasses.reduce((tot, curr) => ({
|
|
2463
1561
|
...tot,
|
|
2464
1562
|
[curr]: "vehicle"
|
|
1563
|
+
/* Vehicle */
|
|
2465
1564
|
}), {}),
|
|
2466
1565
|
...motionClasses.reduce((tot, curr) => ({
|
|
2467
1566
|
...tot,
|
|
2468
1567
|
[curr]: "motion"
|
|
1568
|
+
/* Motion */
|
|
2469
1569
|
}), {}),
|
|
2470
1570
|
...packageClasses.reduce((tot, curr) => ({
|
|
2471
1571
|
...tot,
|
|
2472
1572
|
[curr]: "package"
|
|
1573
|
+
/* Package */
|
|
2473
1574
|
}), {}),
|
|
2474
1575
|
...faceClasses.reduce((tot, curr) => ({
|
|
2475
1576
|
...tot,
|
|
2476
1577
|
[curr]: "face"
|
|
1578
|
+
/* Face */
|
|
2477
1579
|
}), {}),
|
|
2478
1580
|
...licensePlateClasses.reduce((tot, curr) => ({
|
|
2479
1581
|
...tot,
|
|
2480
1582
|
[curr]: "plate"
|
|
1583
|
+
/* Plate */
|
|
2481
1584
|
}), {}),
|
|
2482
1585
|
...audioClasses.reduce((tot, curr) => ({
|
|
2483
1586
|
...tot,
|
|
2484
1587
|
[curr]: "audio"
|
|
1588
|
+
/* Audio */
|
|
2485
1589
|
}), {}),
|
|
2486
1590
|
...audioLabelClasses.reduce((tot, curr) => ({
|
|
2487
1591
|
...tot,
|
|
2488
1592
|
[curr]: "audio"
|
|
1593
|
+
/* Audio */
|
|
2489
1594
|
}), {}),
|
|
2490
1595
|
...doorbellClasses.reduce((tot, curr) => ({
|
|
2491
1596
|
...tot,
|
|
2492
1597
|
[curr]: "doorbell"
|
|
1598
|
+
/* Doorbell */
|
|
2493
1599
|
}), {}),
|
|
2494
1600
|
...sensorLabelClasses.reduce((tot, curr) => ({
|
|
2495
1601
|
...tot,
|
|
2496
1602
|
[curr]: "sensor"
|
|
1603
|
+
/* Sensor */
|
|
2497
1604
|
}), {})
|
|
2498
1605
|
};
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
1606
|
+
const isFaceClassname = (c) => faceClasses.includes(c);
|
|
1607
|
+
const isPlateClassname = (c) => licensePlateClasses.includes(c);
|
|
1608
|
+
const isAnimalClassname = (c) => animalClasses.includes(c);
|
|
1609
|
+
const isPersonClassname = (c) => personClasses.includes(c);
|
|
1610
|
+
const isVehicleClassname = (c) => vehicleClasses.includes(c);
|
|
1611
|
+
const isMotionClassname = (c) => motionClasses.includes(c);
|
|
1612
|
+
const isDoorbellClassname = (c) => doorbellClasses.includes(c);
|
|
1613
|
+
const isPackageClassname = (c) => packageClasses.includes(c);
|
|
1614
|
+
const isAudioClassname = (c) => audioClasses.includes(c) || audioLabelClasses.includes(c);
|
|
1615
|
+
const isSensorLabelClassname = (c) => sensorLabelClasses.includes(c);
|
|
1616
|
+
const isLabelDetection = (c) => isFaceClassname(c) || isPlateClassname(c);
|
|
1617
|
+
const getParentClass = (className) => detectionClassesDefaultMap[className];
|
|
1618
|
+
const getParentDetectionClass = (det) => {
|
|
2512
1619
|
const { className } = det;
|
|
2513
1620
|
const baseMap = {
|
|
2514
|
-
[
|
|
2515
|
-
|
|
1621
|
+
[
|
|
1622
|
+
"face"
|
|
1623
|
+
/* Face */
|
|
1624
|
+
]: "person",
|
|
1625
|
+
[
|
|
1626
|
+
"plate"
|
|
1627
|
+
/* Plate */
|
|
1628
|
+
]: "vehicle"
|
|
1629
|
+
/* Vehicle */
|
|
2516
1630
|
};
|
|
2517
1631
|
const parentGroup = detectionClassesDefaultMap[className];
|
|
2518
1632
|
if (parentGroup && parentGroup !== className) return parentGroup;
|
|
2519
1633
|
return baseMap[className];
|
|
2520
|
-
}
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
1634
|
+
};
|
|
1635
|
+
const defaultDetectionClasses = Object.values(DetectionClass);
|
|
1636
|
+
const DEFAULT_ENABLED_CLASSES = defaultDetectionClasses.filter(
|
|
1637
|
+
(c) => c !== "motion"
|
|
1638
|
+
/* Motion */
|
|
1639
|
+
);
|
|
1640
|
+
const TIMELINE_PRESET_CRITICAL = [
|
|
2524
1641
|
"person",
|
|
2525
1642
|
"doorbell",
|
|
2526
1643
|
"package"
|
|
1644
|
+
/* Package */
|
|
2527
1645
|
];
|
|
2528
|
-
|
|
1646
|
+
const TIMELINE_PRESET_IMPORTANT = [
|
|
2529
1647
|
...TIMELINE_PRESET_CRITICAL,
|
|
2530
1648
|
"vehicle",
|
|
2531
1649
|
"animal",
|
|
2532
1650
|
"audio",
|
|
2533
1651
|
"face",
|
|
2534
1652
|
"plate"
|
|
1653
|
+
/* Plate */
|
|
2535
1654
|
];
|
|
2536
|
-
|
|
2537
|
-
...DEFAULT_ENABLED_CLASSES
|
|
2538
|
-
];
|
|
1655
|
+
const TIMELINE_PRESET_ALL = [...DEFAULT_ENABLED_CLASSES];
|
|
2539
1656
|
function getClassesForTimelinePreset(preset, customClasses) {
|
|
2540
1657
|
switch (preset) {
|
|
2541
1658
|
case "critical":
|
|
@@ -2550,10 +1667,7 @@ function getClassesForTimelinePreset(preset, customClasses) {
|
|
|
2550
1667
|
return DEFAULT_ENABLED_CLASSES;
|
|
2551
1668
|
}
|
|
2552
1669
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
// src/devices.ts
|
|
2556
|
-
var RAW_TO_CANONICAL = {
|
|
1670
|
+
const RAW_TO_CANONICAL = {
|
|
2557
1671
|
// Scrypted PascalCase
|
|
2558
1672
|
Light: "light",
|
|
2559
1673
|
Switch: "switch",
|
|
@@ -2584,7 +1698,7 @@ var RAW_TO_CANONICAL = {
|
|
|
2584
1698
|
media_player: "media_player",
|
|
2585
1699
|
script: "script"
|
|
2586
1700
|
};
|
|
2587
|
-
|
|
1701
|
+
const HA_DOMAIN_TYPE_MAP = {
|
|
2588
1702
|
light: "light",
|
|
2589
1703
|
switch: "switch",
|
|
2590
1704
|
input_boolean: "switch",
|
|
@@ -2612,7 +1726,7 @@ var HA_DOMAIN_TYPE_MAP = {
|
|
|
2612
1726
|
weather: "weather",
|
|
2613
1727
|
water_heater: "climate"
|
|
2614
1728
|
};
|
|
2615
|
-
|
|
1729
|
+
const SCRYPTED_TYPE_TO_CANONICAL = {
|
|
2616
1730
|
Light: "light",
|
|
2617
1731
|
Switch: "switch",
|
|
2618
1732
|
WindowCovering: "cover",
|
|
@@ -2636,8 +1750,7 @@ function getCanonicalDeviceType(rawType) {
|
|
|
2636
1750
|
const lower = rawType.toLowerCase();
|
|
2637
1751
|
return RAW_TO_CANONICAL[lower] ?? null;
|
|
2638
1752
|
}
|
|
2639
|
-
|
|
2640
|
-
var ELIGIBLE_SCRYPTED_DEVICE_TYPES = [
|
|
1753
|
+
const ELIGIBLE_SCRYPTED_DEVICE_TYPES = [
|
|
2641
1754
|
"Entry",
|
|
2642
1755
|
"Light",
|
|
2643
1756
|
"Switch",
|
|
@@ -2650,8 +1763,8 @@ var ELIGIBLE_SCRYPTED_DEVICE_TYPES = [
|
|
|
2650
1763
|
"Select",
|
|
2651
1764
|
"Program"
|
|
2652
1765
|
];
|
|
2653
|
-
|
|
2654
|
-
|
|
1766
|
+
const ELIGIBLE_SCRYPTED_DEVICE_TYPES_SET = new Set(ELIGIBLE_SCRYPTED_DEVICE_TYPES);
|
|
1767
|
+
const ELIGIBLE_HA_DOMAINS = [
|
|
2655
1768
|
"light",
|
|
2656
1769
|
"switch",
|
|
2657
1770
|
"input_boolean",
|
|
@@ -2666,179 +1779,109 @@ var ELIGIBLE_HA_DOMAINS = [
|
|
|
2666
1779
|
"media_player",
|
|
2667
1780
|
"script"
|
|
2668
1781
|
];
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
// src/features.ts
|
|
2672
|
-
var FEATURE_MATRIX = [
|
|
1782
|
+
const ELIGIBLE_HA_DOMAINS_SET = new Set(ELIGIBLE_HA_DOMAINS);
|
|
1783
|
+
const FEATURE_MATRIX = [
|
|
2673
1784
|
{
|
|
2674
1785
|
id: "liveStream",
|
|
2675
1786
|
label: "Live Stream",
|
|
2676
|
-
sources: {
|
|
2677
|
-
frigate: true,
|
|
2678
|
-
scrypted: true,
|
|
2679
|
-
rtsp: true
|
|
2680
|
-
},
|
|
1787
|
+
sources: { frigate: true, scrypted: true, rtsp: true },
|
|
2681
1788
|
adapterMethod: "getLiveStream"
|
|
2682
1789
|
},
|
|
2683
1790
|
{
|
|
2684
1791
|
id: "multiResolution",
|
|
2685
1792
|
label: "Multi-Resolution",
|
|
2686
|
-
sources: {
|
|
2687
|
-
frigate: true,
|
|
2688
|
-
scrypted: true,
|
|
2689
|
-
rtsp: false
|
|
2690
|
-
},
|
|
1793
|
+
sources: { frigate: true, scrypted: true, rtsp: false },
|
|
2691
1794
|
adapterMethod: "getResolutions"
|
|
2692
1795
|
},
|
|
2693
1796
|
{
|
|
2694
1797
|
id: "motion",
|
|
2695
1798
|
label: "Motion Detection",
|
|
2696
|
-
sources: {
|
|
2697
|
-
frigate: false,
|
|
2698
|
-
scrypted: true,
|
|
2699
|
-
rtsp: false
|
|
2700
|
-
},
|
|
1799
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2701
1800
|
adapterMethod: "getMotion"
|
|
2702
1801
|
},
|
|
2703
1802
|
{
|
|
2704
1803
|
id: "objectDetection",
|
|
2705
1804
|
label: "Object Detection",
|
|
2706
|
-
sources: {
|
|
2707
|
-
frigate: false,
|
|
2708
|
-
scrypted: true,
|
|
2709
|
-
rtsp: false
|
|
2710
|
-
},
|
|
1805
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2711
1806
|
adapterMethod: "getObjectDetections"
|
|
2712
1807
|
},
|
|
2713
1808
|
{
|
|
2714
1809
|
id: "audioVolume",
|
|
2715
1810
|
label: "Audio Level",
|
|
2716
|
-
sources: {
|
|
2717
|
-
frigate: false,
|
|
2718
|
-
scrypted: true,
|
|
2719
|
-
rtsp: false
|
|
2720
|
-
},
|
|
1811
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2721
1812
|
adapterMethod: "getAudioVolume"
|
|
2722
1813
|
},
|
|
2723
1814
|
{
|
|
2724
1815
|
id: "audioVolumes",
|
|
2725
1816
|
label: "Audio Volumes (dBFS)",
|
|
2726
|
-
sources: {
|
|
2727
|
-
frigate: false,
|
|
2728
|
-
scrypted: true,
|
|
2729
|
-
rtsp: false
|
|
2730
|
-
},
|
|
1817
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2731
1818
|
adapterMethod: "getAudioVolumes"
|
|
2732
1819
|
},
|
|
2733
1820
|
{
|
|
2734
1821
|
id: "ptz",
|
|
2735
1822
|
label: "PTZ Control",
|
|
2736
|
-
sources: {
|
|
2737
|
-
frigate: false,
|
|
2738
|
-
scrypted: true,
|
|
2739
|
-
rtsp: false
|
|
2740
|
-
},
|
|
1823
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2741
1824
|
adapterMethod: "getPTZ"
|
|
2742
1825
|
},
|
|
2743
1826
|
{
|
|
2744
1827
|
id: "intercom",
|
|
2745
1828
|
label: "Intercom (Mic)",
|
|
2746
|
-
sources: {
|
|
2747
|
-
frigate: false,
|
|
2748
|
-
scrypted: true,
|
|
2749
|
-
rtsp: false
|
|
2750
|
-
},
|
|
1829
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2751
1830
|
adapterMethod: "getIntercomSupport"
|
|
2752
1831
|
},
|
|
2753
1832
|
{
|
|
2754
1833
|
id: "deviceStatus",
|
|
2755
1834
|
label: "Device Status",
|
|
2756
|
-
sources: {
|
|
2757
|
-
frigate: false,
|
|
2758
|
-
scrypted: true,
|
|
2759
|
-
rtsp: false
|
|
2760
|
-
},
|
|
1835
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2761
1836
|
adapterMethod: "getStatus"
|
|
2762
1837
|
},
|
|
2763
1838
|
{
|
|
2764
1839
|
id: "timeline",
|
|
2765
1840
|
label: "Detection Timeline",
|
|
2766
|
-
sources: {
|
|
2767
|
-
frigate: true,
|
|
2768
|
-
scrypted: true,
|
|
2769
|
-
rtsp: false
|
|
2770
|
-
},
|
|
1841
|
+
sources: { frigate: true, scrypted: true, rtsp: false },
|
|
2771
1842
|
adapterMethod: "getCameraDayData"
|
|
2772
1843
|
},
|
|
2773
1844
|
{
|
|
2774
1845
|
id: "clusteredTimeline",
|
|
2775
1846
|
label: "Clustered Timeline",
|
|
2776
|
-
sources: {
|
|
2777
|
-
frigate: true,
|
|
2778
|
-
scrypted: true,
|
|
2779
|
-
rtsp: false
|
|
2780
|
-
},
|
|
1847
|
+
sources: { frigate: true, scrypted: true, rtsp: false },
|
|
2781
1848
|
requiresBackend: true,
|
|
2782
1849
|
adapterMethod: "getClusteredDayData"
|
|
2783
1850
|
},
|
|
2784
1851
|
{
|
|
2785
1852
|
id: "detectionClasses",
|
|
2786
1853
|
label: "Detection Classes",
|
|
2787
|
-
sources: {
|
|
2788
|
-
frigate: true,
|
|
2789
|
-
scrypted: true,
|
|
2790
|
-
rtsp: false
|
|
2791
|
-
},
|
|
1854
|
+
sources: { frigate: true, scrypted: true, rtsp: false },
|
|
2792
1855
|
adapterMethod: "getDetectionClasses"
|
|
2793
1856
|
},
|
|
2794
1857
|
{
|
|
2795
1858
|
id: "videoClips",
|
|
2796
1859
|
label: "Video Clips",
|
|
2797
|
-
sources: {
|
|
2798
|
-
frigate: true,
|
|
2799
|
-
scrypted: true,
|
|
2800
|
-
rtsp: false
|
|
2801
|
-
},
|
|
1860
|
+
sources: { frigate: true, scrypted: true, rtsp: false },
|
|
2802
1861
|
adapterMethod: "getVideoClips"
|
|
2803
1862
|
},
|
|
2804
1863
|
{
|
|
2805
1864
|
id: "nvrPlayback",
|
|
2806
1865
|
label: "NVR Playback",
|
|
2807
|
-
sources: {
|
|
2808
|
-
frigate: true,
|
|
2809
|
-
scrypted: true,
|
|
2810
|
-
rtsp: false
|
|
2811
|
-
},
|
|
1866
|
+
sources: { frigate: true, scrypted: true, rtsp: false },
|
|
2812
1867
|
adapterMethod: "getNvrPlaybackSupported"
|
|
2813
1868
|
},
|
|
2814
1869
|
{
|
|
2815
1870
|
id: "nvrScrub",
|
|
2816
1871
|
label: "NVR Scrub/Seek",
|
|
2817
|
-
sources: {
|
|
2818
|
-
frigate: false,
|
|
2819
|
-
scrypted: true,
|
|
2820
|
-
rtsp: false
|
|
2821
|
-
},
|
|
1872
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2822
1873
|
adapterMethod: "seekRecordingStream"
|
|
2823
1874
|
},
|
|
2824
1875
|
{
|
|
2825
1876
|
id: "recordingThumbnail",
|
|
2826
1877
|
label: "Recording Thumbnails",
|
|
2827
|
-
sources: {
|
|
2828
|
-
frigate: true,
|
|
2829
|
-
scrypted: true,
|
|
2830
|
-
rtsp: false
|
|
2831
|
-
},
|
|
1878
|
+
sources: { frigate: true, scrypted: true, rtsp: false },
|
|
2832
1879
|
adapterMethod: "getRecordingStreamThumbnail"
|
|
2833
1880
|
},
|
|
2834
1881
|
{
|
|
2835
1882
|
id: "nvrSeekToLive",
|
|
2836
1883
|
label: "Seek to Live",
|
|
2837
|
-
sources: {
|
|
2838
|
-
frigate: false,
|
|
2839
|
-
scrypted: true,
|
|
2840
|
-
rtsp: false
|
|
2841
|
-
},
|
|
1884
|
+
sources: { frigate: false, scrypted: true, rtsp: false },
|
|
2842
1885
|
adapterMethod: "seekNvrToLive"
|
|
2843
1886
|
}
|
|
2844
1887
|
];
|
|
@@ -2849,17 +1892,12 @@ function isFeatureAvailable(featureId, source, platform) {
|
|
|
2849
1892
|
if (entry.platforms && entry.platforms[platform] === false) return false;
|
|
2850
1893
|
return true;
|
|
2851
1894
|
}
|
|
2852
|
-
__name(isFeatureAvailable, "isFeatureAvailable");
|
|
2853
1895
|
function getSourceFeatures(source) {
|
|
2854
1896
|
return FEATURE_MATRIX.filter((f) => f.sources[source]);
|
|
2855
1897
|
}
|
|
2856
|
-
__name(getSourceFeatures, "getSourceFeatures");
|
|
2857
1898
|
function getBackendRequiredFeatures() {
|
|
2858
1899
|
return FEATURE_MATRIX.filter((f) => f.requiresBackend);
|
|
2859
1900
|
}
|
|
2860
|
-
__name(getBackendRequiredFeatures, "getBackendRequiredFeatures");
|
|
2861
|
-
|
|
2862
|
-
// src/adaptive-stream.ts
|
|
2863
1901
|
function selectOptimalStream(streams, constraints, defaultTransport) {
|
|
2864
1902
|
if (streams.length === 0) return null;
|
|
2865
1903
|
const viewportPixels = constraints.viewportWidth * constraints.viewportHeight * (constraints.pixelRatio ?? 1);
|
|
@@ -2900,11 +1938,7 @@ function selectOptimalStream(streams, constraints, defaultTransport) {
|
|
|
2900
1938
|
if (bw < 5 && s.metadata.codec.includes("265")) score += 10;
|
|
2901
1939
|
if (bw >= 10 && s.metadata.codec.includes("264")) score += 5;
|
|
2902
1940
|
}
|
|
2903
|
-
return {
|
|
2904
|
-
...s,
|
|
2905
|
-
score,
|
|
2906
|
-
targetTier
|
|
2907
|
-
};
|
|
1941
|
+
return { ...s, score, targetTier };
|
|
2908
1942
|
});
|
|
2909
1943
|
scored.sort((a, b) => b.score - a.score);
|
|
2910
1944
|
const best = scored[0];
|
|
@@ -2914,17 +1948,15 @@ function selectOptimalStream(streams, constraints, defaultTransport) {
|
|
|
2914
1948
|
transport: best.transport,
|
|
2915
1949
|
label: best.label,
|
|
2916
1950
|
metadata: best.metadata,
|
|
2917
|
-
reason: `${best.targetTier} quality
|
|
1951
|
+
reason: `${best.targetTier} quality → ${best.profile}/${best.transport} (score: ${best.score})`
|
|
2918
1952
|
};
|
|
2919
1953
|
}
|
|
2920
|
-
__name(selectOptimalStream, "selectOptimalStream");
|
|
2921
1954
|
function getNextEvalInterval(constraints, wasSwitch) {
|
|
2922
1955
|
if (wasSwitch) return 10;
|
|
2923
1956
|
if (constraints.isCellular) return 15;
|
|
2924
1957
|
if ((constraints.packetLoss ?? 0) > 0.02) return 15;
|
|
2925
1958
|
return 30;
|
|
2926
1959
|
}
|
|
2927
|
-
__name(getNextEvalInterval, "getNextEvalInterval");
|
|
2928
1960
|
export {
|
|
2929
1961
|
DEFAULT_ENABLED_CLASSES,
|
|
2930
1962
|
DetectionClass,
|
|
@@ -2971,13 +2003,9 @@ export {
|
|
|
2971
2003
|
motionClasses,
|
|
2972
2004
|
packageClasses,
|
|
2973
2005
|
personClasses,
|
|
2006
|
+
raceFastestEndpoint,
|
|
2974
2007
|
selectOptimalStream,
|
|
2975
2008
|
sensorLabelClasses,
|
|
2976
2009
|
vehicleClasses
|
|
2977
2010
|
};
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
@trpc/client/dist/httpLink-lG_6juPY.mjs:
|
|
2981
|
-
(* istanbul ignore if -- @preserve *)
|
|
2982
|
-
*/
|
|
2983
|
-
//# sourceMappingURL=index.js.map
|
|
2011
|
+
//# sourceMappingURL=index.js.map
|