@jixo/cli 0.23.7 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/bundle/google-aistudio.browser.js +231 -1
- package/assets/bundle/groq.browser.js +3714 -0
- package/assets/prompt.json +1 -4
- package/bundle/external-B5Q4zVIg.js +285 -0
- package/bundle/external-DSiJ5HUn.js +285 -0
- package/bundle/file-replacer-BBkQrlEp.js +19525 -0
- package/bundle/file-replacer-BRQH97p5.js +3 -0
- package/bundle/file-replacer-BjxkSo7g.js +3 -0
- package/bundle/file-replacer-Cn6P6P9p.js +19525 -0
- package/bundle/gen-prompt-C9t2IJs3.js +4 -0
- package/bundle/gen-prompt-CP097hvk.js +4 -0
- package/bundle/gen-prompt-CdL3aAGF.js +18145 -0
- package/bundle/gen-prompt-D01J11yn.js +18145 -0
- package/bundle/index.js +24835 -58291
- package/dist/commands/groq.d.ts +8 -0
- package/dist/commands/groq.d.ts.map +1 -0
- package/dist/commands/groq.js +70 -0
- package/dist/commands/groq.js.map +1 -0
- package/dist/prompts.json +2 -14
- package/dist/runCli.d.ts.map +1 -1
- package/dist/runCli.js +3 -1
- package/dist/runCli.js.map +1 -1
- package/package.json +3 -3
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -83
- package/dist/cli.js.map +0 -1
- package/dist/commands/daemon.d.ts +0 -5
- package/dist/commands/daemon.d.ts.map +0 -1
- package/dist/commands/daemon.js +0 -20
- package/dist/commands/daemon.js.map +0 -1
- package/dist/commands/doctor/config.d.ts +0 -3
- package/dist/commands/doctor/config.d.ts.map +0 -1
- package/dist/commands/doctor/config.js +0 -17
- package/dist/commands/doctor/config.js.map +0 -1
- package/dist/commands/doctor/doctor.d.ts +0 -3
- package/dist/commands/doctor/doctor.d.ts.map +0 -1
- package/dist/commands/doctor/doctor.js +0 -158
- package/dist/commands/doctor/doctor.js.map +0 -1
- package/dist/commands/doctor/doctor.test.d.ts +0 -2
- package/dist/commands/doctor/doctor.test.d.ts.map +0 -1
- package/dist/commands/doctor/doctor.test.js +0 -14
- package/dist/commands/doctor/doctor.test.js.map +0 -1
- package/dist/commands/doctor/index.d.ts +0 -2
- package/dist/commands/doctor/index.d.ts.map +0 -1
- package/dist/commands/doctor/index.js +0 -8
- package/dist/commands/doctor/index.js.map +0 -1
- package/dist/commands/doctor/types.d.ts +0 -45
- package/dist/commands/doctor/types.d.ts.map +0 -1
- package/dist/commands/doctor/types.js +0 -3
- package/dist/commands/doctor/types.js.map +0 -1
- package/dist/commands/init.d.ts +0 -2
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -40
- package/dist/commands/init.js.map +0 -1
- package/dist/commands/tasks/run.d.ts +0 -10
- package/dist/commands/tasks/run.d.ts.map +0 -1
- package/dist/commands/tasks/run.js +0 -44
- package/dist/commands/tasks/run.js.map +0 -1
- package/dist/config.d.ts +0 -15
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -23
- package/dist/config.js.map +0 -1
- package/dist/env.d.ts +0 -6
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -16
- package/dist/env.js.map +0 -1
- /package/bundle/{acorn-BoNAepQd.js → acorn-CU7YmuGp.js} +0 -0
- /package/bundle/{angular-pDmFHCFc.js → angular-BZFEnvyh.js} +0 -0
- /package/bundle/{babel-CxK7_76E.js → babel-BC5Ty8sN.js} +0 -0
- /package/bundle/{estree-CfdzwKX-.js → estree-DZTSfOv_.js} +0 -0
- /package/bundle/{flow-CGeR1fbg.js → flow-CNTeHoxv.js} +0 -0
- /package/bundle/{glimmer-CX3iu1jj.js → glimmer-DYkbcawC.js} +0 -0
- /package/bundle/{graphql-C32NbEjQ.js → graphql-fCaNVuM0.js} +0 -0
- /package/bundle/{html-BYSSlHHY.js → html-Bb8ztcZq.js} +0 -0
- /package/bundle/{markdown-DiTmrgL1.js → markdown-ChusAllR.js} +0 -0
- /package/bundle/{meriyah-DM8jkzWU.js → meriyah-9NeL3We4.js} +0 -0
- /package/bundle/{postcss-Au71UEeZ.js → postcss-DXCUuMfC.js} +0 -0
- /package/bundle/{typescript-Dn4uCwAY.js → typescript-C2HFEnMP.js} +0 -0
- /package/bundle/{yaml-D6G3z4bP.js → yaml-ByEZ6gmG.js} +0 -0
|
@@ -0,0 +1,3714 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
24
|
+
const obj_lazify = /* @__NO_SIDE_EFFECTS__ */ (obj, target = obj) => {
|
|
25
|
+
for (const [prop, desp] of obj_all_descriptors(obj)) _set_lazify(target, prop, desp);
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
const _set_lazify = (target, prop, desp) => {
|
|
29
|
+
if (desp.get !== void 0 && desp.set === void 0 && desp.configurable) {
|
|
30
|
+
const source_get = desp.get;
|
|
31
|
+
const cache_get = function() {
|
|
32
|
+
const cache = source_get.call(this);
|
|
33
|
+
delete desp.get;
|
|
34
|
+
delete desp.set;
|
|
35
|
+
desp.value = cache;
|
|
36
|
+
Object.defineProperty(target, prop, desp);
|
|
37
|
+
return cache;
|
|
38
|
+
};
|
|
39
|
+
desp.get = cache_get;
|
|
40
|
+
Object.defineProperty(target, prop, desp);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const obj_all_descriptors = (obj) => {
|
|
44
|
+
const desps = Object.getOwnPropertyDescriptors(obj);
|
|
45
|
+
return Reflect.ownKeys(desps).map((prop) => [prop, desps[prop]]);
|
|
46
|
+
};
|
|
47
|
+
const obj_delegate_by = (target, proto, getBy = () => proto, options) => {
|
|
48
|
+
const recursive = options?.recursive ?? false;
|
|
49
|
+
const omit = new Set(options?.omit);
|
|
50
|
+
_delegate_by(target, proto, getBy, recursive, omit);
|
|
51
|
+
return omit;
|
|
52
|
+
};
|
|
53
|
+
const _delegate_by = (target, proto, getBy, recursive, omit) => {
|
|
54
|
+
for (const [prop, desp] of obj_all_descriptors(proto)) {
|
|
55
|
+
if (omit.has(prop)) continue;
|
|
56
|
+
omit.add(prop);
|
|
57
|
+
let can_delegate = false;
|
|
58
|
+
if (desp.get != null) {
|
|
59
|
+
can_delegate = true;
|
|
60
|
+
const source_get = desp.get;
|
|
61
|
+
desp.get = function() {
|
|
62
|
+
return source_get.call(getBy(this));
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (desp.set != null) {
|
|
66
|
+
can_delegate = true;
|
|
67
|
+
const source_set = desp.set;
|
|
68
|
+
desp.set = function(value) {
|
|
69
|
+
return source_set.call(getBy(this), value);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (typeof desp.value === "function") {
|
|
73
|
+
can_delegate = true;
|
|
74
|
+
const source_func = desp.value;
|
|
75
|
+
desp.value = function(...args) {
|
|
76
|
+
return source_func.apply(getBy(this), args);
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
delete desp.value;
|
|
80
|
+
desp.set = function(value) {
|
|
81
|
+
return Reflect.set(getBy(this), prop, value, this);
|
|
82
|
+
};
|
|
83
|
+
desp.get = function() {
|
|
84
|
+
return Reflect.get(getBy(this), prop, this);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (can_delegate) Object.defineProperty(target, prop, desp);
|
|
88
|
+
}
|
|
89
|
+
if (recursive) {
|
|
90
|
+
const source_proto = Object.getPrototypeOf(proto);
|
|
91
|
+
if (source_proto !== null && source_proto !== Object.prototype) return _delegate_by(target, source_proto, getBy, recursive, omit);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const isPromiseLike = (value) => value !== null && typeof value?.then === "function";
|
|
95
|
+
const arr_set_next = (arr, item) => {
|
|
96
|
+
arr[arr.length] = item;
|
|
97
|
+
};
|
|
98
|
+
const iter_map_async_try = (values, callbackfn) => {
|
|
99
|
+
const result = [];
|
|
100
|
+
let index = 0;
|
|
101
|
+
for (const item of values) result.push(callbackfn(item, index++, values));
|
|
102
|
+
return Promise.allSettled(result);
|
|
103
|
+
};
|
|
104
|
+
const iter_map_not_null = (values, callbackfn) => {
|
|
105
|
+
const result = [];
|
|
106
|
+
let index = 0;
|
|
107
|
+
if (callbackfn) for (const value of values) {
|
|
108
|
+
const r = callbackfn(value, index++, values);
|
|
109
|
+
if (r != null) result.push(r);
|
|
110
|
+
}
|
|
111
|
+
else for (const value of values) if (value != null) result.push(value);
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
var PureEvent = class {
|
|
115
|
+
constructor() {
|
|
116
|
+
this.watch = this.watch.bind(this);
|
|
117
|
+
this.on = this.on.bind(this);
|
|
118
|
+
this.once = this.once.bind(this);
|
|
119
|
+
this.off = this.off.bind(this);
|
|
120
|
+
this.unwatch = this.unwatch.bind(this);
|
|
121
|
+
this.emit = this.emit.bind(this);
|
|
122
|
+
}
|
|
123
|
+
events = /* @__PURE__ */ new Map();
|
|
124
|
+
get size() {
|
|
125
|
+
return this.events.size;
|
|
126
|
+
}
|
|
127
|
+
has(key) {
|
|
128
|
+
return this.events.has(key);
|
|
129
|
+
}
|
|
130
|
+
on(cb, options) {
|
|
131
|
+
return this.watch(cb, options);
|
|
132
|
+
}
|
|
133
|
+
watch(cb, options) {
|
|
134
|
+
const key = options?.key ?? cb;
|
|
135
|
+
this.off(key);
|
|
136
|
+
let onDispose = options?.onDispose;
|
|
137
|
+
if (typeof onDispose !== "function") onDispose = void 0;
|
|
138
|
+
const off = () => this.off(key);
|
|
139
|
+
this.events.set(key, {
|
|
140
|
+
cb,
|
|
141
|
+
onDispose,
|
|
142
|
+
off
|
|
143
|
+
});
|
|
144
|
+
return off;
|
|
145
|
+
}
|
|
146
|
+
off(key) {
|
|
147
|
+
return this.unwatch(key);
|
|
148
|
+
}
|
|
149
|
+
unwatch(key) {
|
|
150
|
+
const event = this.events.get(key);
|
|
151
|
+
if (event == null) return false;
|
|
152
|
+
this.events.delete(key);
|
|
153
|
+
if (event.onDispose == null) return true;
|
|
154
|
+
return promise_try(event.onDispose);
|
|
155
|
+
}
|
|
156
|
+
cleanSync() {
|
|
157
|
+
const dels = iter_map_not_null(this.events, ([key, event]) => {
|
|
158
|
+
this.events.delete(key);
|
|
159
|
+
return {
|
|
160
|
+
key,
|
|
161
|
+
disposeReturn: event.onDispose ? promise_try(event.onDispose) : void 0
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
return dels;
|
|
165
|
+
}
|
|
166
|
+
async clean() {
|
|
167
|
+
const dels = this.cleanSync();
|
|
168
|
+
const results = [];
|
|
169
|
+
for (const del of dels) {
|
|
170
|
+
const disposeReturn = await del.disposeReturn;
|
|
171
|
+
results.push({
|
|
172
|
+
key: del.key,
|
|
173
|
+
disposeReturn
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return results;
|
|
177
|
+
}
|
|
178
|
+
async emit(data) {
|
|
179
|
+
if (this.size === 0) return;
|
|
180
|
+
const errors = [];
|
|
181
|
+
const results = await iter_map_async_try(this.events.values(), (cb) => cb.cb(data));
|
|
182
|
+
for (const item of results) if (item.status === "rejected") arr_set_next(errors, item.reason);
|
|
183
|
+
if (errors.length > 0) throw new AggregateError(errors, "emit error");
|
|
184
|
+
}
|
|
185
|
+
once(cb_or_options, options) {
|
|
186
|
+
let cb;
|
|
187
|
+
if (typeof cb_or_options === "function") cb = cb_or_options;
|
|
188
|
+
else if (cb_or_options != null) options = cb_or_options;
|
|
189
|
+
const filter = options?.filter ?? (() => true);
|
|
190
|
+
if (cb == null) {
|
|
191
|
+
const onDispose = options?.onDispose;
|
|
192
|
+
const off$1 = this.on((data) => {
|
|
193
|
+
if (filter(data)) {
|
|
194
|
+
promiseWithResolvers.resolve(data);
|
|
195
|
+
off$1();
|
|
196
|
+
}
|
|
197
|
+
}, {
|
|
198
|
+
...options,
|
|
199
|
+
onDispose() {
|
|
200
|
+
if (false === resolved) promiseWithResolvers.reject(/* @__PURE__ */ new Error("listener dispose"));
|
|
201
|
+
onDispose?.();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const job = Promise.withResolvers();
|
|
205
|
+
let resolved = false;
|
|
206
|
+
const promiseWithResolvers = Object.assign(job.promise, {
|
|
207
|
+
resolve(data) {
|
|
208
|
+
resolved = true;
|
|
209
|
+
job.resolve(data);
|
|
210
|
+
},
|
|
211
|
+
reject(reason) {
|
|
212
|
+
job.reject(reason);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return promiseWithResolvers;
|
|
216
|
+
}
|
|
217
|
+
const off = this.watch(async (data) => {
|
|
218
|
+
if (filter(data)) {
|
|
219
|
+
const disposeReturn = off();
|
|
220
|
+
if (disposeReturn !== false) try {
|
|
221
|
+
return cb(data);
|
|
222
|
+
} finally {
|
|
223
|
+
if (disposeReturn instanceof Promise) await disposeReturn;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, options);
|
|
227
|
+
return off;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const pureEvent = () => {
|
|
231
|
+
const pe = new PureEvent();
|
|
232
|
+
const watch = pe.watch;
|
|
233
|
+
Object.setPrototypeOf(watch, pe);
|
|
234
|
+
return watch;
|
|
235
|
+
};
|
|
236
|
+
var PureEventDelegate = class extends PureEvent {
|
|
237
|
+
byPureEvent;
|
|
238
|
+
constructor(byPureEvent = new PureEvent()) {
|
|
239
|
+
super();
|
|
240
|
+
this.byPureEvent = byPureEvent;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
obj_delegate_by(PureEventDelegate.prototype, PureEvent.prototype, (target) => target.byPureEvent);
|
|
244
|
+
const func_remember = /* @__NO_SIDE_EFFECTS__ */ (func, key) => {
|
|
245
|
+
let result;
|
|
246
|
+
const once_fn = function(...args) {
|
|
247
|
+
const newKey = key?.apply(this, args);
|
|
248
|
+
if (result === void 0 || newKey !== result.key) result = {
|
|
249
|
+
key: newKey,
|
|
250
|
+
res: func.apply(this, args)
|
|
251
|
+
};
|
|
252
|
+
return result.res;
|
|
253
|
+
};
|
|
254
|
+
const once_fn_mix = Object.assign(once_fn, {
|
|
255
|
+
get source() {
|
|
256
|
+
return func;
|
|
257
|
+
},
|
|
258
|
+
get key() {
|
|
259
|
+
return result?.key;
|
|
260
|
+
},
|
|
261
|
+
get runned() {
|
|
262
|
+
return result != null;
|
|
263
|
+
},
|
|
264
|
+
get returnValue() {
|
|
265
|
+
return result?.res;
|
|
266
|
+
},
|
|
267
|
+
reset() {
|
|
268
|
+
result = void 0;
|
|
269
|
+
},
|
|
270
|
+
rerun(...args) {
|
|
271
|
+
once_fn_mix.reset();
|
|
272
|
+
return once_fn_mix(...args);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
Object.defineProperties(once_fn_mix, {
|
|
276
|
+
source: {
|
|
277
|
+
value: func,
|
|
278
|
+
writable: false,
|
|
279
|
+
configurable: true,
|
|
280
|
+
enumerable: true
|
|
281
|
+
},
|
|
282
|
+
key: {
|
|
283
|
+
get: () => result?.key,
|
|
284
|
+
configurable: true,
|
|
285
|
+
enumerable: true
|
|
286
|
+
},
|
|
287
|
+
runned: {
|
|
288
|
+
get: () => result != null,
|
|
289
|
+
configurable: true,
|
|
290
|
+
enumerable: true
|
|
291
|
+
},
|
|
292
|
+
returnValue: {
|
|
293
|
+
get: () => result?.res,
|
|
294
|
+
configurable: true,
|
|
295
|
+
enumerable: true
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
return once_fn_mix;
|
|
299
|
+
};
|
|
300
|
+
const wrapSuccess = (result) => {
|
|
301
|
+
return Object.defineProperties([void 0, result], {
|
|
302
|
+
success: {
|
|
303
|
+
value: true,
|
|
304
|
+
writable: false,
|
|
305
|
+
enumerable: false,
|
|
306
|
+
configurable: true
|
|
307
|
+
},
|
|
308
|
+
result: {
|
|
309
|
+
value: result,
|
|
310
|
+
writable: false,
|
|
311
|
+
enumerable: false,
|
|
312
|
+
configurable: true
|
|
313
|
+
},
|
|
314
|
+
error: {
|
|
315
|
+
value: void 0,
|
|
316
|
+
writable: false,
|
|
317
|
+
enumerable: false,
|
|
318
|
+
configurable: true
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
const wrapError = (err, errorParser) => {
|
|
323
|
+
const error = errorParser ? errorParser(err) : err;
|
|
324
|
+
return Object.defineProperties([error, void 0], {
|
|
325
|
+
success: {
|
|
326
|
+
value: false,
|
|
327
|
+
writable: false,
|
|
328
|
+
enumerable: false,
|
|
329
|
+
configurable: true
|
|
330
|
+
},
|
|
331
|
+
result: {
|
|
332
|
+
value: void 0,
|
|
333
|
+
writable: false,
|
|
334
|
+
enumerable: false,
|
|
335
|
+
configurable: true
|
|
336
|
+
},
|
|
337
|
+
error: {
|
|
338
|
+
value: error,
|
|
339
|
+
writable: false,
|
|
340
|
+
enumerable: false,
|
|
341
|
+
configurable: true
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
const func_catch = /* @__PURE__ */ Object.assign((fn, errorParser) => {
|
|
346
|
+
return Object.assign(function() {
|
|
347
|
+
try {
|
|
348
|
+
const res = fn.apply(this, arguments);
|
|
349
|
+
if (isPromiseLike(res)) return res.then((value) => wrapSuccess(value), (err) => wrapError(err, errorParser));
|
|
350
|
+
return wrapSuccess(res);
|
|
351
|
+
} catch (err) {
|
|
352
|
+
return wrapError(err, errorParser);
|
|
353
|
+
}
|
|
354
|
+
}, { catchType(errorParser$1) {
|
|
355
|
+
return func_catch(fn, errorParser$1);
|
|
356
|
+
} });
|
|
357
|
+
}, {
|
|
358
|
+
wrapSuccess,
|
|
359
|
+
wrapError
|
|
360
|
+
});
|
|
361
|
+
const effect_symbol = Symbol.for("effect");
|
|
362
|
+
const promise_try = async (fn) => {
|
|
363
|
+
try {
|
|
364
|
+
const value = await fn();
|
|
365
|
+
return {
|
|
366
|
+
status: "fulfilled",
|
|
367
|
+
value
|
|
368
|
+
};
|
|
369
|
+
} catch (reason) {
|
|
370
|
+
return {
|
|
371
|
+
status: "rejected",
|
|
372
|
+
reason
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const binary_to_base64_string = (u8a) => {
|
|
377
|
+
if ("base64Slice" in u8a) return u8a.toString("base64");
|
|
378
|
+
let binaryString = "";
|
|
379
|
+
for (let i = 0; i < u8a.length; i++) binaryString += binary_base64_table[u8a[i]];
|
|
380
|
+
return btoa(binaryString);
|
|
381
|
+
};
|
|
382
|
+
const binary_base64_table = /* @__PURE__ */ Object.freeze(Array.from({ length: 256 }, (_, index) => {
|
|
383
|
+
return String.fromCharCode(index);
|
|
384
|
+
}));
|
|
385
|
+
const binary_hex_table = /* @__PURE__ */ obj_lazify({
|
|
386
|
+
get hex16() {
|
|
387
|
+
return Object.freeze(Array.from({ length: 2 ** 16 }, (_, index) => {
|
|
388
|
+
return index.toString(16).padStart(4, "0");
|
|
389
|
+
}));
|
|
390
|
+
},
|
|
391
|
+
get hex8() {
|
|
392
|
+
return Object.freeze(Array.from({ length: 256 }, (_, index) => {
|
|
393
|
+
return index.toString(16).padStart(2, "0");
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
const str_to_base64_binary = (str) => {
|
|
398
|
+
const binaryString = atob(str);
|
|
399
|
+
const uint8Array = new Uint8Array(binaryString.length);
|
|
400
|
+
for (let i = 0; i < binaryString.length; i++) uint8Array[i] = binaryString.charCodeAt(i);
|
|
401
|
+
return uint8Array;
|
|
402
|
+
};
|
|
403
|
+
const hex_binary_table = /* @__PURE__ */ obj_lazify({ get hex8() {
|
|
404
|
+
const hex8_binary_ver_table = [];
|
|
405
|
+
for (let a = 0; a < 16; a++) {
|
|
406
|
+
const bs = hex8_binary_ver_table[a.toString(16).charCodeAt(0)] = [];
|
|
407
|
+
for (let b = 0; b < 16; b++) bs[b.toString(16).charCodeAt(0)] = (a << 4) + b;
|
|
408
|
+
Object.freeze(bs);
|
|
409
|
+
}
|
|
410
|
+
return Object.freeze(hex8_binary_ver_table);
|
|
411
|
+
} });
|
|
412
|
+
let rootDirHandle;
|
|
413
|
+
const prepareDirHandle = async () => {
|
|
414
|
+
if (rootDirHandle) return rootDirHandle;
|
|
415
|
+
const ti = setTimeout(() => {
|
|
416
|
+
console.log("%c等待用户动作: 请选择一个文件夹,用来作为内容导入导出的协作目录.", styles.info);
|
|
417
|
+
}, 100);
|
|
418
|
+
try {
|
|
419
|
+
rootDirHandle = await window.showDirectoryPicker({ mode: "readwrite" });
|
|
420
|
+
console.log(`%c✅ 根文件夹已选择: %c${rootDirHandle.name}`, styles.success, styles.code);
|
|
421
|
+
return rootDirHandle;
|
|
422
|
+
} catch (e) {
|
|
423
|
+
clearTimeout(ti);
|
|
424
|
+
if (e instanceof Error) {
|
|
425
|
+
if (e.name === "SecurityError" || e.name === "NotAllowedError") {
|
|
426
|
+
console.log("%c请将鼠标聚焦到窗口视图中", styles.info);
|
|
427
|
+
await delay(1e3);
|
|
428
|
+
return prepareDirHandle();
|
|
429
|
+
}
|
|
430
|
+
if (e.name === "AbortError") throw new DOMException("用户取消了文件夹选择", "AbortError");
|
|
431
|
+
}
|
|
432
|
+
throw e;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
const getEasyFs = /* @__PURE__ */ func_remember(async () => {
|
|
436
|
+
const [error, dirHandle] = await func_catch(prepareDirHandle)();
|
|
437
|
+
if (!dirHandle) {
|
|
438
|
+
getEasyFs.reset();
|
|
439
|
+
throw error;
|
|
440
|
+
}
|
|
441
|
+
const getHandle = async (path, { create = false } = {}) => {
|
|
442
|
+
let curr = dirHandle;
|
|
443
|
+
const parts = path.split("/").filter(Boolean);
|
|
444
|
+
const last = parts.at(-1);
|
|
445
|
+
for (let i = 0; i < parts.length - 1; i++) curr = await curr.getDirectoryHandle(parts[i], { create });
|
|
446
|
+
return {
|
|
447
|
+
parent: curr,
|
|
448
|
+
name: last,
|
|
449
|
+
async getFile() {
|
|
450
|
+
if (!last) throw new Error("No file name");
|
|
451
|
+
return curr.getFileHandle(last, { create });
|
|
452
|
+
},
|
|
453
|
+
async getDir() {
|
|
454
|
+
if (!last) return curr;
|
|
455
|
+
return curr.getDirectoryHandle(last, { create });
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
const writeFile = async (filePath, data, opts) => {
|
|
460
|
+
const { getFile } = await getHandle(filePath, { create: true });
|
|
461
|
+
const handle = await getFile();
|
|
462
|
+
const w$1 = await handle.createWritable();
|
|
463
|
+
if (!opts?.append) await w$1.truncate(0);
|
|
464
|
+
await w$1.write(data);
|
|
465
|
+
await w$1.close();
|
|
466
|
+
};
|
|
467
|
+
const createWriteStream = async (filePath) => {
|
|
468
|
+
const { getFile } = await getHandle(filePath, { create: true });
|
|
469
|
+
const handle = await getFile();
|
|
470
|
+
return handle.createWritable();
|
|
471
|
+
};
|
|
472
|
+
const readFileText = async (filePath) => {
|
|
473
|
+
const { getFile } = await getHandle(filePath);
|
|
474
|
+
const file = await (await getFile()).getFile();
|
|
475
|
+
return file.text();
|
|
476
|
+
};
|
|
477
|
+
const readFileBinary = async (filePath) => {
|
|
478
|
+
const { getFile } = await getHandle(filePath);
|
|
479
|
+
const file = await (await getFile()).getFile();
|
|
480
|
+
return file.bytes();
|
|
481
|
+
};
|
|
482
|
+
const createReadStream = async (filePath) => {
|
|
483
|
+
const { getFile } = await getHandle(filePath);
|
|
484
|
+
const file = await (await getFile()).getFile();
|
|
485
|
+
return file.stream();
|
|
486
|
+
};
|
|
487
|
+
const readdir = async (dirPath) => {
|
|
488
|
+
const { getDir } = await getHandle(dirPath);
|
|
489
|
+
const dir = await getDir();
|
|
490
|
+
return Array.fromAsync(dir.keys());
|
|
491
|
+
};
|
|
492
|
+
const mkdir = async (dirPath, opts) => {
|
|
493
|
+
const parts = dirPath.split("/").filter(Boolean);
|
|
494
|
+
let curr = dirHandle;
|
|
495
|
+
for (const segment of parts) {
|
|
496
|
+
curr = await curr.getDirectoryHandle(segment, { create: true });
|
|
497
|
+
if (!opts?.recursive) break;
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
const exists = async (path) => {
|
|
501
|
+
try {
|
|
502
|
+
await getHandle(path);
|
|
503
|
+
return true;
|
|
504
|
+
} catch {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
const stat = async (path) => {
|
|
509
|
+
const { getFile, getDir } = await getHandle(path);
|
|
510
|
+
try {
|
|
511
|
+
const h$1 = await getFile();
|
|
512
|
+
const f = await h$1.getFile();
|
|
513
|
+
return {
|
|
514
|
+
isFile: true,
|
|
515
|
+
size: f.size,
|
|
516
|
+
lastModified: f.lastModified
|
|
517
|
+
};
|
|
518
|
+
} catch {
|
|
519
|
+
await getDir();
|
|
520
|
+
return { isFile: false };
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const rm = async (path, opts) => {
|
|
524
|
+
try {
|
|
525
|
+
const { parent, name } = await getHandle(path);
|
|
526
|
+
if (!name) throw new Error("Invalid path");
|
|
527
|
+
await parent.removeEntry(name, { recursive: opts?.recursive });
|
|
528
|
+
return true;
|
|
529
|
+
} catch {
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
return {
|
|
534
|
+
writeFile,
|
|
535
|
+
createWriteStream,
|
|
536
|
+
readFileText,
|
|
537
|
+
readFileBinary,
|
|
538
|
+
createReadStream,
|
|
539
|
+
readdir,
|
|
540
|
+
mkdir,
|
|
541
|
+
exists,
|
|
542
|
+
stat,
|
|
543
|
+
rm
|
|
544
|
+
};
|
|
545
|
+
});
|
|
546
|
+
const styles = {
|
|
547
|
+
header: "color: #4CAF50; font-size: 18px; font-weight: bold; border-bottom: 2px solid #4CAF50; padding-bottom: 5px;",
|
|
548
|
+
info: "color: #2196F3; font-style: italic;",
|
|
549
|
+
success: "color: #8BC34A; font-weight: bold;",
|
|
550
|
+
error: "color: #F44336; font-weight: bold;",
|
|
551
|
+
code: "background-color: #f0f0f0; color: #333; padding: 2px 4px; border-radius: 3px; font-family: monospace;",
|
|
552
|
+
warn: "color: #FFC107;"
|
|
553
|
+
};
|
|
554
|
+
const delay = (ms) => new Promise((cb) => setTimeout(cb, ms));
|
|
555
|
+
const raf = () => new Promise((cb) => requestAnimationFrame(cb));
|
|
556
|
+
const $ = document.querySelector.bind(document);
|
|
557
|
+
const $$ = document.querySelectorAll.bind(document);
|
|
558
|
+
async function extractChat(ele = document.body) {
|
|
559
|
+
const messages = [];
|
|
560
|
+
const sysCardOpenBtn = ele.querySelector(".flex.w-full.content-start.rounded-lg.hover\\:bg-secondary-subtle button");
|
|
561
|
+
if (sysCardOpenBtn) {
|
|
562
|
+
sysCardOpenBtn.click();
|
|
563
|
+
await raf();
|
|
564
|
+
}
|
|
565
|
+
const sysCard = ele.querySelector(".flex.w-full.content-start.rounded-lg.flex-col.bg-secondary-subtle");
|
|
566
|
+
if (sysCard) {
|
|
567
|
+
const ta = sysCard.querySelector("textarea");
|
|
568
|
+
const text = ta?.value.trim();
|
|
569
|
+
if (text && text !== "Enter system message (Optional)") messages.push({
|
|
570
|
+
role: "system",
|
|
571
|
+
text
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
ele.querySelectorAll("[class*=\"rounded-lg\"]").forEach((card) => {
|
|
575
|
+
const roleBtn = card.querySelector("button[class*=\"uppercase\"]");
|
|
576
|
+
if (!roleBtn) return;
|
|
577
|
+
const role = roleBtn.textContent?.trim().toLowerCase() ?? "";
|
|
578
|
+
if (!["user", "assistant"].includes(role)) return;
|
|
579
|
+
const textarea = card.querySelector("textarea");
|
|
580
|
+
if (!textarea) return;
|
|
581
|
+
const text = textarea.value.trim();
|
|
582
|
+
if (text) messages.push({
|
|
583
|
+
role,
|
|
584
|
+
text
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
return messages;
|
|
588
|
+
}
|
|
589
|
+
async function keepWeakup() {
|
|
590
|
+
const workerCode = `
|
|
591
|
+
setInterval(() => self.postMessage('tick'), 1000);
|
|
592
|
+
`;
|
|
593
|
+
const worker = new Worker(URL.createObjectURL(new Blob([workerCode], { type: "application/javascript" })));
|
|
594
|
+
worker.onmessage = () => {};
|
|
595
|
+
const ctx = new (window.AudioContext || window.webkitAudioContext)();
|
|
596
|
+
const length = ctx.sampleRate * .2;
|
|
597
|
+
const buffer = ctx.createBuffer(1, length, ctx.sampleRate);
|
|
598
|
+
const data = buffer.getChannelData(0);
|
|
599
|
+
for (let i = 0; i < length; i++) data[i] = Math.random() * .02 - .01;
|
|
600
|
+
const source = ctx.createBufferSource();
|
|
601
|
+
source.buffer = buffer;
|
|
602
|
+
source.loop = true;
|
|
603
|
+
source.connect(ctx.destination);
|
|
604
|
+
source.start();
|
|
605
|
+
return () => {
|
|
606
|
+
worker.terminate();
|
|
607
|
+
try {
|
|
608
|
+
source.stop();
|
|
609
|
+
} catch {}
|
|
610
|
+
try {
|
|
611
|
+
ctx.close();
|
|
612
|
+
} catch {}
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
const NEVER = Object.freeze({ status: "aborted" });
|
|
616
|
+
function $constructor(name, initializer$1, params) {
|
|
617
|
+
function init$1(inst, def) {
|
|
618
|
+
var _a;
|
|
619
|
+
Object.defineProperty(inst, "_zod", {
|
|
620
|
+
value: inst._zod ?? {},
|
|
621
|
+
enumerable: false
|
|
622
|
+
});
|
|
623
|
+
(_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
|
|
624
|
+
inst._zod.traits.add(name);
|
|
625
|
+
initializer$1(inst, def);
|
|
626
|
+
for (const k in _.prototype) if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
|
|
627
|
+
inst._zod.constr = _;
|
|
628
|
+
inst._zod.def = def;
|
|
629
|
+
}
|
|
630
|
+
const Parent = params?.Parent ?? Object;
|
|
631
|
+
class Definition extends Parent {}
|
|
632
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
633
|
+
function _(def) {
|
|
634
|
+
var _a;
|
|
635
|
+
const inst = params?.Parent ? new Definition() : this;
|
|
636
|
+
init$1(inst, def);
|
|
637
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
638
|
+
for (const fn of inst._zod.deferred) fn();
|
|
639
|
+
return inst;
|
|
640
|
+
}
|
|
641
|
+
Object.defineProperty(_, "init", { value: init$1 });
|
|
642
|
+
Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
|
|
643
|
+
if (params?.Parent && inst instanceof params.Parent) return true;
|
|
644
|
+
return inst?._zod?.traits?.has(name);
|
|
645
|
+
} });
|
|
646
|
+
Object.defineProperty(_, "name", { value: name });
|
|
647
|
+
return _;
|
|
648
|
+
}
|
|
649
|
+
const $brand = Symbol("zod_brand");
|
|
650
|
+
var $ZodAsyncError = class extends Error {
|
|
651
|
+
constructor() {
|
|
652
|
+
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
const globalConfig = {};
|
|
656
|
+
function config(newConfig) {
|
|
657
|
+
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
658
|
+
return globalConfig;
|
|
659
|
+
}
|
|
660
|
+
function getEnumValues(entries) {
|
|
661
|
+
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
662
|
+
const values = Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
663
|
+
return values;
|
|
664
|
+
}
|
|
665
|
+
function jsonStringifyReplacer(_, value) {
|
|
666
|
+
if (typeof value === "bigint") return value.toString();
|
|
667
|
+
return value;
|
|
668
|
+
}
|
|
669
|
+
function cached(getter) {
|
|
670
|
+
const set = false;
|
|
671
|
+
return { get value() {
|
|
672
|
+
{
|
|
673
|
+
const value = getter();
|
|
674
|
+
Object.defineProperty(this, "value", { value });
|
|
675
|
+
return value;
|
|
676
|
+
}
|
|
677
|
+
} };
|
|
678
|
+
}
|
|
679
|
+
function cleanRegex(source) {
|
|
680
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
681
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
682
|
+
return source.slice(start, end);
|
|
683
|
+
}
|
|
684
|
+
function defineLazy(object$1, key, getter) {
|
|
685
|
+
const set = false;
|
|
686
|
+
Object.defineProperty(object$1, key, {
|
|
687
|
+
get() {
|
|
688
|
+
{
|
|
689
|
+
const value = getter();
|
|
690
|
+
object$1[key] = value;
|
|
691
|
+
return value;
|
|
692
|
+
}
|
|
693
|
+
},
|
|
694
|
+
set(v) {
|
|
695
|
+
Object.defineProperty(object$1, key, { value: v });
|
|
696
|
+
},
|
|
697
|
+
configurable: true
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
function assignProp$1(target, prop, value) {
|
|
701
|
+
Object.defineProperty(target, prop, {
|
|
702
|
+
value,
|
|
703
|
+
writable: true,
|
|
704
|
+
enumerable: true,
|
|
705
|
+
configurable: true
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
function mergeDefs(...defs) {
|
|
709
|
+
const mergedDescriptors = {};
|
|
710
|
+
for (const def of defs) {
|
|
711
|
+
const descriptors = Object.getOwnPropertyDescriptors(def);
|
|
712
|
+
Object.assign(mergedDescriptors, descriptors);
|
|
713
|
+
}
|
|
714
|
+
return Object.defineProperties({}, mergedDescriptors);
|
|
715
|
+
}
|
|
716
|
+
function esc(str) {
|
|
717
|
+
return JSON.stringify(str);
|
|
718
|
+
}
|
|
719
|
+
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
|
|
720
|
+
function isObject(data) {
|
|
721
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
722
|
+
}
|
|
723
|
+
const allowsEval = cached(() => {
|
|
724
|
+
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
725
|
+
try {
|
|
726
|
+
const F = Function;
|
|
727
|
+
new F("");
|
|
728
|
+
return true;
|
|
729
|
+
} catch (_) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
function isPlainObject$2(o) {
|
|
734
|
+
if (isObject(o) === false) return false;
|
|
735
|
+
const ctor = o.constructor;
|
|
736
|
+
if (ctor === void 0) return true;
|
|
737
|
+
const prot = ctor.prototype;
|
|
738
|
+
if (isObject(prot) === false) return false;
|
|
739
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
const propertyKeyTypes = new Set([
|
|
743
|
+
"string",
|
|
744
|
+
"number",
|
|
745
|
+
"symbol"
|
|
746
|
+
]);
|
|
747
|
+
function escapeRegex(str) {
|
|
748
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
749
|
+
}
|
|
750
|
+
function clone(inst, def, params) {
|
|
751
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
752
|
+
if (!def || params?.parent) cl._zod.parent = inst;
|
|
753
|
+
return cl;
|
|
754
|
+
}
|
|
755
|
+
function normalizeParams(_params) {
|
|
756
|
+
const params = _params;
|
|
757
|
+
if (!params) return {};
|
|
758
|
+
if (typeof params === "string") return { error: () => params };
|
|
759
|
+
if (params?.message !== void 0) {
|
|
760
|
+
if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
|
|
761
|
+
params.error = params.message;
|
|
762
|
+
}
|
|
763
|
+
delete params.message;
|
|
764
|
+
if (typeof params.error === "string") return {
|
|
765
|
+
...params,
|
|
766
|
+
error: () => params.error
|
|
767
|
+
};
|
|
768
|
+
return params;
|
|
769
|
+
}
|
|
770
|
+
function optionalKeys(shape) {
|
|
771
|
+
return Object.keys(shape).filter((k) => {
|
|
772
|
+
return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
const NUMBER_FORMAT_RANGES = {
|
|
776
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
777
|
+
int32: [-2147483648, 2147483647],
|
|
778
|
+
uint32: [0, 4294967295],
|
|
779
|
+
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
780
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
781
|
+
};
|
|
782
|
+
function extend$1(schema, shape) {
|
|
783
|
+
if (!isPlainObject$2(shape)) throw new Error("Invalid input to extend: expected a plain object");
|
|
784
|
+
const def = mergeDefs(schema._zod.def, {
|
|
785
|
+
get shape() {
|
|
786
|
+
const _shape = {
|
|
787
|
+
...schema._zod.def.shape,
|
|
788
|
+
...shape
|
|
789
|
+
};
|
|
790
|
+
assignProp$1(this, "shape", _shape);
|
|
791
|
+
return _shape;
|
|
792
|
+
},
|
|
793
|
+
checks: []
|
|
794
|
+
});
|
|
795
|
+
return clone(schema, def);
|
|
796
|
+
}
|
|
797
|
+
function aborted(x, startIndex = 0) {
|
|
798
|
+
for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
function prefixIssues(path, issues) {
|
|
802
|
+
return issues.map((iss) => {
|
|
803
|
+
var _a;
|
|
804
|
+
(_a = iss).path ?? (_a.path = []);
|
|
805
|
+
iss.path.unshift(path);
|
|
806
|
+
return iss;
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function unwrapMessage(message) {
|
|
810
|
+
return typeof message === "string" ? message : message?.message;
|
|
811
|
+
}
|
|
812
|
+
function finalizeIssue(iss, ctx, config$1) {
|
|
813
|
+
const full = {
|
|
814
|
+
...iss,
|
|
815
|
+
path: iss.path ?? []
|
|
816
|
+
};
|
|
817
|
+
if (!iss.message) {
|
|
818
|
+
const message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
|
|
819
|
+
full.message = message;
|
|
820
|
+
}
|
|
821
|
+
delete full.inst;
|
|
822
|
+
delete full.continue;
|
|
823
|
+
if (!ctx?.reportInput) delete full.input;
|
|
824
|
+
return full;
|
|
825
|
+
}
|
|
826
|
+
function issue(...args) {
|
|
827
|
+
const [iss, input, inst] = args;
|
|
828
|
+
if (typeof iss === "string") return {
|
|
829
|
+
message: iss,
|
|
830
|
+
code: "custom",
|
|
831
|
+
input,
|
|
832
|
+
inst
|
|
833
|
+
};
|
|
834
|
+
return { ...iss };
|
|
835
|
+
}
|
|
836
|
+
const initializer = (inst, def) => {
|
|
837
|
+
inst.name = "$ZodError";
|
|
838
|
+
Object.defineProperty(inst, "_zod", {
|
|
839
|
+
value: inst._zod,
|
|
840
|
+
enumerable: false
|
|
841
|
+
});
|
|
842
|
+
Object.defineProperty(inst, "issues", {
|
|
843
|
+
value: def,
|
|
844
|
+
enumerable: false
|
|
845
|
+
});
|
|
846
|
+
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
847
|
+
Object.defineProperty(inst, "toString", {
|
|
848
|
+
value: () => inst.message,
|
|
849
|
+
enumerable: false
|
|
850
|
+
});
|
|
851
|
+
};
|
|
852
|
+
const $ZodError = $constructor("$ZodError", initializer);
|
|
853
|
+
const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
854
|
+
const _parse = (_Err) => (schema, value, _ctx, _params) => {
|
|
855
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
856
|
+
const result = schema._zod.run({
|
|
857
|
+
value,
|
|
858
|
+
issues: []
|
|
859
|
+
}, ctx);
|
|
860
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
861
|
+
if (result.issues.length) {
|
|
862
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
863
|
+
captureStackTrace(e, _params?.callee);
|
|
864
|
+
throw e;
|
|
865
|
+
}
|
|
866
|
+
return result.value;
|
|
867
|
+
};
|
|
868
|
+
const parse$2 = /* @__PURE__ */ _parse($ZodRealError);
|
|
869
|
+
const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
|
|
870
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
871
|
+
let result = schema._zod.run({
|
|
872
|
+
value,
|
|
873
|
+
issues: []
|
|
874
|
+
}, ctx);
|
|
875
|
+
if (result instanceof Promise) result = await result;
|
|
876
|
+
if (result.issues.length) {
|
|
877
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
878
|
+
captureStackTrace(e, params?.callee);
|
|
879
|
+
throw e;
|
|
880
|
+
}
|
|
881
|
+
return result.value;
|
|
882
|
+
};
|
|
883
|
+
const parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
|
|
884
|
+
const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
885
|
+
const ctx = _ctx ? {
|
|
886
|
+
..._ctx,
|
|
887
|
+
async: false
|
|
888
|
+
} : { async: false };
|
|
889
|
+
const result = schema._zod.run({
|
|
890
|
+
value,
|
|
891
|
+
issues: []
|
|
892
|
+
}, ctx);
|
|
893
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
894
|
+
return result.issues.length ? {
|
|
895
|
+
success: false,
|
|
896
|
+
error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
897
|
+
} : {
|
|
898
|
+
success: true,
|
|
899
|
+
data: result.value
|
|
900
|
+
};
|
|
901
|
+
};
|
|
902
|
+
const safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
903
|
+
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
904
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
905
|
+
let result = schema._zod.run({
|
|
906
|
+
value,
|
|
907
|
+
issues: []
|
|
908
|
+
}, ctx);
|
|
909
|
+
if (result instanceof Promise) result = await result;
|
|
910
|
+
return result.issues.length ? {
|
|
911
|
+
success: false,
|
|
912
|
+
error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
913
|
+
} : {
|
|
914
|
+
success: true,
|
|
915
|
+
data: result.value
|
|
916
|
+
};
|
|
917
|
+
};
|
|
918
|
+
const safeParseAsync = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
919
|
+
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
920
|
+
const date = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
|
|
921
|
+
const string$1 = (params) => {
|
|
922
|
+
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
923
|
+
return /* @__PURE__ */ new RegExp(`^${regex}$`);
|
|
924
|
+
};
|
|
925
|
+
const number$1 = /^-?\d+(?:\.\d+)?/i;
|
|
926
|
+
const boolean$1 = /true|false/i;
|
|
927
|
+
const _null$2 = /null/i;
|
|
928
|
+
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
929
|
+
var _a;
|
|
930
|
+
inst._zod ?? (inst._zod = {});
|
|
931
|
+
inst._zod.def = def;
|
|
932
|
+
(_a = inst._zod).onattach ?? (_a.onattach = []);
|
|
933
|
+
});
|
|
934
|
+
var Doc = class {
|
|
935
|
+
constructor(args = []) {
|
|
936
|
+
this.content = [];
|
|
937
|
+
this.indent = 0;
|
|
938
|
+
if (this) this.args = args;
|
|
939
|
+
}
|
|
940
|
+
indented(fn) {
|
|
941
|
+
this.indent += 1;
|
|
942
|
+
fn(this);
|
|
943
|
+
this.indent -= 1;
|
|
944
|
+
}
|
|
945
|
+
write(arg) {
|
|
946
|
+
if (typeof arg === "function") {
|
|
947
|
+
arg(this, { execution: "sync" });
|
|
948
|
+
arg(this, { execution: "async" });
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
const content = arg;
|
|
952
|
+
const lines = content.split("\n").filter((x) => x);
|
|
953
|
+
const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
|
|
954
|
+
const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
|
|
955
|
+
for (const line of dedented) this.content.push(line);
|
|
956
|
+
}
|
|
957
|
+
compile() {
|
|
958
|
+
const F = Function;
|
|
959
|
+
const args = this?.args;
|
|
960
|
+
const content = this?.content ?? [``];
|
|
961
|
+
const lines = [...content.map((x) => ` ${x}`)];
|
|
962
|
+
return new F(...args, lines.join("\n"));
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
const version = {
|
|
966
|
+
major: 4,
|
|
967
|
+
minor: 0,
|
|
968
|
+
patch: 10
|
|
969
|
+
};
|
|
970
|
+
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
971
|
+
var _a;
|
|
972
|
+
inst ?? (inst = {});
|
|
973
|
+
inst._zod.def = def;
|
|
974
|
+
inst._zod.bag = inst._zod.bag || {};
|
|
975
|
+
inst._zod.version = version;
|
|
976
|
+
const checks = [...inst._zod.def.checks ?? []];
|
|
977
|
+
if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
|
|
978
|
+
for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
|
|
979
|
+
if (checks.length === 0) {
|
|
980
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
981
|
+
inst._zod.deferred?.push(() => {
|
|
982
|
+
inst._zod.run = inst._zod.parse;
|
|
983
|
+
});
|
|
984
|
+
} else {
|
|
985
|
+
const runChecks = (payload, checks$1, ctx) => {
|
|
986
|
+
let isAborted = aborted(payload);
|
|
987
|
+
let asyncResult;
|
|
988
|
+
for (const ch of checks$1) {
|
|
989
|
+
if (ch._zod.def.when) {
|
|
990
|
+
const shouldRun = ch._zod.def.when(payload);
|
|
991
|
+
if (!shouldRun) continue;
|
|
992
|
+
} else if (isAborted) continue;
|
|
993
|
+
const currLen = payload.issues.length;
|
|
994
|
+
const _ = ch._zod.check(payload);
|
|
995
|
+
if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
|
|
996
|
+
if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
997
|
+
await _;
|
|
998
|
+
const nextLen = payload.issues.length;
|
|
999
|
+
if (nextLen === currLen) return;
|
|
1000
|
+
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
1001
|
+
});
|
|
1002
|
+
else {
|
|
1003
|
+
const nextLen = payload.issues.length;
|
|
1004
|
+
if (nextLen === currLen) continue;
|
|
1005
|
+
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (asyncResult) return asyncResult.then(() => {
|
|
1009
|
+
return payload;
|
|
1010
|
+
});
|
|
1011
|
+
return payload;
|
|
1012
|
+
};
|
|
1013
|
+
inst._zod.run = (payload, ctx) => {
|
|
1014
|
+
const result = inst._zod.parse(payload, ctx);
|
|
1015
|
+
if (result instanceof Promise) {
|
|
1016
|
+
if (ctx.async === false) throw new $ZodAsyncError();
|
|
1017
|
+
return result.then((result$1) => runChecks(result$1, checks, ctx));
|
|
1018
|
+
}
|
|
1019
|
+
return runChecks(result, checks, ctx);
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
inst["~standard"] = {
|
|
1023
|
+
validate: (value) => {
|
|
1024
|
+
try {
|
|
1025
|
+
const r = safeParse(inst, value);
|
|
1026
|
+
return r.success ? { value: r.data } : { issues: r.error?.issues };
|
|
1027
|
+
} catch (_) {
|
|
1028
|
+
return safeParseAsync(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
vendor: "zod",
|
|
1032
|
+
version: 1
|
|
1033
|
+
};
|
|
1034
|
+
});
|
|
1035
|
+
const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
1036
|
+
$ZodType.init(inst, def);
|
|
1037
|
+
inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
|
|
1038
|
+
inst._zod.parse = (payload, _) => {
|
|
1039
|
+
if (def.coerce) try {
|
|
1040
|
+
payload.value = String(payload.value);
|
|
1041
|
+
} catch (_$1) {}
|
|
1042
|
+
if (typeof payload.value === "string") return payload;
|
|
1043
|
+
payload.issues.push({
|
|
1044
|
+
expected: "string",
|
|
1045
|
+
code: "invalid_type",
|
|
1046
|
+
input: payload.value,
|
|
1047
|
+
inst
|
|
1048
|
+
});
|
|
1049
|
+
return payload;
|
|
1050
|
+
};
|
|
1051
|
+
});
|
|
1052
|
+
const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
1053
|
+
$ZodType.init(inst, def);
|
|
1054
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
|
|
1055
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1056
|
+
if (def.coerce) try {
|
|
1057
|
+
payload.value = Number(payload.value);
|
|
1058
|
+
} catch (_) {}
|
|
1059
|
+
const input = payload.value;
|
|
1060
|
+
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
|
|
1061
|
+
const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
|
|
1062
|
+
payload.issues.push({
|
|
1063
|
+
expected: "number",
|
|
1064
|
+
code: "invalid_type",
|
|
1065
|
+
input,
|
|
1066
|
+
inst,
|
|
1067
|
+
...received ? { received } : {}
|
|
1068
|
+
});
|
|
1069
|
+
return payload;
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
1073
|
+
$ZodType.init(inst, def);
|
|
1074
|
+
inst._zod.pattern = boolean$1;
|
|
1075
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1076
|
+
if (def.coerce) try {
|
|
1077
|
+
payload.value = Boolean(payload.value);
|
|
1078
|
+
} catch (_) {}
|
|
1079
|
+
const input = payload.value;
|
|
1080
|
+
if (typeof input === "boolean") return payload;
|
|
1081
|
+
payload.issues.push({
|
|
1082
|
+
expected: "boolean",
|
|
1083
|
+
code: "invalid_type",
|
|
1084
|
+
input,
|
|
1085
|
+
inst
|
|
1086
|
+
});
|
|
1087
|
+
return payload;
|
|
1088
|
+
};
|
|
1089
|
+
});
|
|
1090
|
+
const $ZodNull = /* @__PURE__ */ $constructor("$ZodNull", (inst, def) => {
|
|
1091
|
+
$ZodType.init(inst, def);
|
|
1092
|
+
inst._zod.pattern = _null$2;
|
|
1093
|
+
inst._zod.values = new Set([null]);
|
|
1094
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1095
|
+
const input = payload.value;
|
|
1096
|
+
if (input === null) return payload;
|
|
1097
|
+
payload.issues.push({
|
|
1098
|
+
expected: "null",
|
|
1099
|
+
code: "invalid_type",
|
|
1100
|
+
input,
|
|
1101
|
+
inst
|
|
1102
|
+
});
|
|
1103
|
+
return payload;
|
|
1104
|
+
};
|
|
1105
|
+
});
|
|
1106
|
+
const $ZodAny = /* @__PURE__ */ $constructor("$ZodAny", (inst, def) => {
|
|
1107
|
+
$ZodType.init(inst, def);
|
|
1108
|
+
inst._zod.parse = (payload) => payload;
|
|
1109
|
+
});
|
|
1110
|
+
const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
|
|
1111
|
+
$ZodType.init(inst, def);
|
|
1112
|
+
inst._zod.parse = (payload) => payload;
|
|
1113
|
+
});
|
|
1114
|
+
function handleArrayResult(result, final, index) {
|
|
1115
|
+
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
1116
|
+
final.value[index] = result.value;
|
|
1117
|
+
}
|
|
1118
|
+
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
1119
|
+
$ZodType.init(inst, def);
|
|
1120
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1121
|
+
const input = payload.value;
|
|
1122
|
+
if (!Array.isArray(input)) {
|
|
1123
|
+
payload.issues.push({
|
|
1124
|
+
expected: "array",
|
|
1125
|
+
code: "invalid_type",
|
|
1126
|
+
input,
|
|
1127
|
+
inst
|
|
1128
|
+
});
|
|
1129
|
+
return payload;
|
|
1130
|
+
}
|
|
1131
|
+
payload.value = Array(input.length);
|
|
1132
|
+
const proms = [];
|
|
1133
|
+
for (let i = 0; i < input.length; i++) {
|
|
1134
|
+
const item = input[i];
|
|
1135
|
+
const result = def.element._zod.run({
|
|
1136
|
+
value: item,
|
|
1137
|
+
issues: []
|
|
1138
|
+
}, ctx);
|
|
1139
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i)));
|
|
1140
|
+
else handleArrayResult(result, payload, i);
|
|
1141
|
+
}
|
|
1142
|
+
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1143
|
+
return payload;
|
|
1144
|
+
};
|
|
1145
|
+
});
|
|
1146
|
+
function handlePropertyResult(result, final, key, input) {
|
|
1147
|
+
if (result.issues.length) final.issues.push(...prefixIssues(key, result.issues));
|
|
1148
|
+
if (result.value === void 0) {
|
|
1149
|
+
if (key in input) final.value[key] = void 0;
|
|
1150
|
+
} else final.value[key] = result.value;
|
|
1151
|
+
}
|
|
1152
|
+
const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
1153
|
+
$ZodType.init(inst, def);
|
|
1154
|
+
const _normalized = cached(() => {
|
|
1155
|
+
const keys = Object.keys(def.shape);
|
|
1156
|
+
for (const k of keys) if (!(def.shape[k] instanceof $ZodType)) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
|
1157
|
+
const okeys = optionalKeys(def.shape);
|
|
1158
|
+
return {
|
|
1159
|
+
shape: def.shape,
|
|
1160
|
+
keys,
|
|
1161
|
+
keySet: new Set(keys),
|
|
1162
|
+
numKeys: keys.length,
|
|
1163
|
+
optionalKeys: new Set(okeys)
|
|
1164
|
+
};
|
|
1165
|
+
});
|
|
1166
|
+
defineLazy(inst._zod, "propValues", () => {
|
|
1167
|
+
const shape = def.shape;
|
|
1168
|
+
const propValues = {};
|
|
1169
|
+
for (const key in shape) {
|
|
1170
|
+
const field = shape[key]._zod;
|
|
1171
|
+
if (field.values) {
|
|
1172
|
+
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
1173
|
+
for (const v of field.values) propValues[key].add(v);
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
return propValues;
|
|
1177
|
+
});
|
|
1178
|
+
const generateFastpass = (shape) => {
|
|
1179
|
+
const doc = new Doc([
|
|
1180
|
+
"shape",
|
|
1181
|
+
"payload",
|
|
1182
|
+
"ctx"
|
|
1183
|
+
]);
|
|
1184
|
+
const normalized = _normalized.value;
|
|
1185
|
+
const parseStr = (key) => {
|
|
1186
|
+
const k = esc(key);
|
|
1187
|
+
return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
1188
|
+
};
|
|
1189
|
+
doc.write(`const input = payload.value;`);
|
|
1190
|
+
const ids = Object.create(null);
|
|
1191
|
+
let counter = 0;
|
|
1192
|
+
for (const key of normalized.keys) ids[key] = `key_${counter++}`;
|
|
1193
|
+
doc.write(`const newResult = {}`);
|
|
1194
|
+
for (const key of normalized.keys) {
|
|
1195
|
+
const id = ids[key];
|
|
1196
|
+
const k = esc(key);
|
|
1197
|
+
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
1198
|
+
doc.write(`
|
|
1199
|
+
if (${id}.issues.length) {
|
|
1200
|
+
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
1201
|
+
...iss,
|
|
1202
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
1203
|
+
})));
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
if (${id}.value === undefined) {
|
|
1207
|
+
if (${k} in input) {
|
|
1208
|
+
newResult[${k}] = undefined;
|
|
1209
|
+
}
|
|
1210
|
+
} else {
|
|
1211
|
+
newResult[${k}] = ${id}.value;
|
|
1212
|
+
}
|
|
1213
|
+
`);
|
|
1214
|
+
}
|
|
1215
|
+
doc.write(`payload.value = newResult;`);
|
|
1216
|
+
doc.write(`return payload;`);
|
|
1217
|
+
const fn = doc.compile();
|
|
1218
|
+
return (payload, ctx) => fn(shape, payload, ctx);
|
|
1219
|
+
};
|
|
1220
|
+
let fastpass;
|
|
1221
|
+
const isObject$1 = isObject;
|
|
1222
|
+
const jit = !globalConfig.jitless;
|
|
1223
|
+
const allowsEval$1 = allowsEval;
|
|
1224
|
+
const fastEnabled = jit && allowsEval$1.value;
|
|
1225
|
+
const catchall = def.catchall;
|
|
1226
|
+
let value;
|
|
1227
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1228
|
+
value ?? (value = _normalized.value);
|
|
1229
|
+
const input = payload.value;
|
|
1230
|
+
if (!isObject$1(input)) {
|
|
1231
|
+
payload.issues.push({
|
|
1232
|
+
expected: "object",
|
|
1233
|
+
code: "invalid_type",
|
|
1234
|
+
input,
|
|
1235
|
+
inst
|
|
1236
|
+
});
|
|
1237
|
+
return payload;
|
|
1238
|
+
}
|
|
1239
|
+
const proms = [];
|
|
1240
|
+
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
|
|
1241
|
+
if (!fastpass) fastpass = generateFastpass(def.shape);
|
|
1242
|
+
payload = fastpass(payload, ctx);
|
|
1243
|
+
} else {
|
|
1244
|
+
payload.value = {};
|
|
1245
|
+
const shape = value.shape;
|
|
1246
|
+
for (const key of value.keys) {
|
|
1247
|
+
const el = shape[key];
|
|
1248
|
+
const r = el._zod.run({
|
|
1249
|
+
value: input[key],
|
|
1250
|
+
issues: []
|
|
1251
|
+
}, ctx);
|
|
1252
|
+
if (r instanceof Promise) proms.push(r.then((r$1) => handlePropertyResult(r$1, payload, key, input)));
|
|
1253
|
+
else handlePropertyResult(r, payload, key, input);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1257
|
+
const unrecognized = [];
|
|
1258
|
+
const keySet = value.keySet;
|
|
1259
|
+
const _catchall = catchall._zod;
|
|
1260
|
+
const t = _catchall.def.type;
|
|
1261
|
+
for (const key of Object.keys(input)) {
|
|
1262
|
+
if (keySet.has(key)) continue;
|
|
1263
|
+
if (t === "never") {
|
|
1264
|
+
unrecognized.push(key);
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
const r = _catchall.run({
|
|
1268
|
+
value: input[key],
|
|
1269
|
+
issues: []
|
|
1270
|
+
}, ctx);
|
|
1271
|
+
if (r instanceof Promise) proms.push(r.then((r$1) => handlePropertyResult(r$1, payload, key, input)));
|
|
1272
|
+
else handlePropertyResult(r, payload, key, input);
|
|
1273
|
+
}
|
|
1274
|
+
if (unrecognized.length) payload.issues.push({
|
|
1275
|
+
code: "unrecognized_keys",
|
|
1276
|
+
keys: unrecognized,
|
|
1277
|
+
input,
|
|
1278
|
+
inst
|
|
1279
|
+
});
|
|
1280
|
+
if (!proms.length) return payload;
|
|
1281
|
+
return Promise.all(proms).then(() => {
|
|
1282
|
+
return payload;
|
|
1283
|
+
});
|
|
1284
|
+
};
|
|
1285
|
+
});
|
|
1286
|
+
function handleUnionResults(results, final, inst, ctx) {
|
|
1287
|
+
for (const result of results) if (result.issues.length === 0) {
|
|
1288
|
+
final.value = result.value;
|
|
1289
|
+
return final;
|
|
1290
|
+
}
|
|
1291
|
+
const nonaborted = results.filter((r) => !aborted(r));
|
|
1292
|
+
if (nonaborted.length === 1) {
|
|
1293
|
+
final.value = nonaborted[0].value;
|
|
1294
|
+
return nonaborted[0];
|
|
1295
|
+
}
|
|
1296
|
+
final.issues.push({
|
|
1297
|
+
code: "invalid_union",
|
|
1298
|
+
input: final.value,
|
|
1299
|
+
inst,
|
|
1300
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
1301
|
+
});
|
|
1302
|
+
return final;
|
|
1303
|
+
}
|
|
1304
|
+
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
1305
|
+
$ZodType.init(inst, def);
|
|
1306
|
+
defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
|
|
1307
|
+
defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
|
|
1308
|
+
defineLazy(inst._zod, "values", () => {
|
|
1309
|
+
if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
1310
|
+
return void 0;
|
|
1311
|
+
});
|
|
1312
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1313
|
+
if (def.options.every((o) => o._zod.pattern)) {
|
|
1314
|
+
const patterns = def.options.map((o) => o._zod.pattern);
|
|
1315
|
+
return /* @__PURE__ */ new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
1316
|
+
}
|
|
1317
|
+
return void 0;
|
|
1318
|
+
});
|
|
1319
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1320
|
+
let async = false;
|
|
1321
|
+
const results = [];
|
|
1322
|
+
for (const option of def.options) {
|
|
1323
|
+
const result = option._zod.run({
|
|
1324
|
+
value: payload.value,
|
|
1325
|
+
issues: []
|
|
1326
|
+
}, ctx);
|
|
1327
|
+
if (result instanceof Promise) {
|
|
1328
|
+
results.push(result);
|
|
1329
|
+
async = true;
|
|
1330
|
+
} else {
|
|
1331
|
+
if (result.issues.length === 0) return result;
|
|
1332
|
+
results.push(result);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
if (!async) return handleUnionResults(results, payload, inst, ctx);
|
|
1336
|
+
return Promise.all(results).then((results$1) => {
|
|
1337
|
+
return handleUnionResults(results$1, payload, inst, ctx);
|
|
1338
|
+
});
|
|
1339
|
+
};
|
|
1340
|
+
});
|
|
1341
|
+
const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
1342
|
+
$ZodType.init(inst, def);
|
|
1343
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1344
|
+
const input = payload.value;
|
|
1345
|
+
if (!isPlainObject$2(input)) {
|
|
1346
|
+
payload.issues.push({
|
|
1347
|
+
expected: "record",
|
|
1348
|
+
code: "invalid_type",
|
|
1349
|
+
input,
|
|
1350
|
+
inst
|
|
1351
|
+
});
|
|
1352
|
+
return payload;
|
|
1353
|
+
}
|
|
1354
|
+
const proms = [];
|
|
1355
|
+
if (def.keyType._zod.values) {
|
|
1356
|
+
const values = def.keyType._zod.values;
|
|
1357
|
+
payload.value = {};
|
|
1358
|
+
for (const key of values) if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
1359
|
+
const result = def.valueType._zod.run({
|
|
1360
|
+
value: input[key],
|
|
1361
|
+
issues: []
|
|
1362
|
+
}, ctx);
|
|
1363
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => {
|
|
1364
|
+
if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
|
|
1365
|
+
payload.value[key] = result$1.value;
|
|
1366
|
+
}));
|
|
1367
|
+
else {
|
|
1368
|
+
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
1369
|
+
payload.value[key] = result.value;
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
let unrecognized;
|
|
1373
|
+
for (const key in input) if (!values.has(key)) {
|
|
1374
|
+
unrecognized = unrecognized ?? [];
|
|
1375
|
+
unrecognized.push(key);
|
|
1376
|
+
}
|
|
1377
|
+
if (unrecognized && unrecognized.length > 0) payload.issues.push({
|
|
1378
|
+
code: "unrecognized_keys",
|
|
1379
|
+
input,
|
|
1380
|
+
inst,
|
|
1381
|
+
keys: unrecognized
|
|
1382
|
+
});
|
|
1383
|
+
} else {
|
|
1384
|
+
payload.value = {};
|
|
1385
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
1386
|
+
if (key === "__proto__") continue;
|
|
1387
|
+
const keyResult = def.keyType._zod.run({
|
|
1388
|
+
value: key,
|
|
1389
|
+
issues: []
|
|
1390
|
+
}, ctx);
|
|
1391
|
+
if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
|
|
1392
|
+
if (keyResult.issues.length) {
|
|
1393
|
+
payload.issues.push({
|
|
1394
|
+
origin: "record",
|
|
1395
|
+
code: "invalid_key",
|
|
1396
|
+
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
1397
|
+
input: key,
|
|
1398
|
+
path: [key],
|
|
1399
|
+
inst
|
|
1400
|
+
});
|
|
1401
|
+
payload.value[keyResult.value] = keyResult.value;
|
|
1402
|
+
continue;
|
|
1403
|
+
}
|
|
1404
|
+
const result = def.valueType._zod.run({
|
|
1405
|
+
value: input[key],
|
|
1406
|
+
issues: []
|
|
1407
|
+
}, ctx);
|
|
1408
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => {
|
|
1409
|
+
if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
|
|
1410
|
+
payload.value[keyResult.value] = result$1.value;
|
|
1411
|
+
}));
|
|
1412
|
+
else {
|
|
1413
|
+
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
1414
|
+
payload.value[keyResult.value] = result.value;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1419
|
+
return payload;
|
|
1420
|
+
};
|
|
1421
|
+
});
|
|
1422
|
+
const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
1423
|
+
$ZodType.init(inst, def);
|
|
1424
|
+
const values = getEnumValues(def.entries);
|
|
1425
|
+
const valuesSet = new Set(values);
|
|
1426
|
+
inst._zod.values = valuesSet;
|
|
1427
|
+
inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
|
|
1428
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1429
|
+
const input = payload.value;
|
|
1430
|
+
if (valuesSet.has(input)) return payload;
|
|
1431
|
+
payload.issues.push({
|
|
1432
|
+
code: "invalid_value",
|
|
1433
|
+
values,
|
|
1434
|
+
input,
|
|
1435
|
+
inst
|
|
1436
|
+
});
|
|
1437
|
+
return payload;
|
|
1438
|
+
};
|
|
1439
|
+
});
|
|
1440
|
+
const $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
|
|
1441
|
+
$ZodType.init(inst, def);
|
|
1442
|
+
if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
|
|
1443
|
+
inst._zod.values = new Set(def.values);
|
|
1444
|
+
inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
|
|
1445
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1446
|
+
const input = payload.value;
|
|
1447
|
+
if (inst._zod.values.has(input)) return payload;
|
|
1448
|
+
payload.issues.push({
|
|
1449
|
+
code: "invalid_value",
|
|
1450
|
+
values: def.values,
|
|
1451
|
+
input,
|
|
1452
|
+
inst
|
|
1453
|
+
});
|
|
1454
|
+
return payload;
|
|
1455
|
+
};
|
|
1456
|
+
});
|
|
1457
|
+
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
1458
|
+
$ZodType.init(inst, def);
|
|
1459
|
+
inst._zod.optin = "optional";
|
|
1460
|
+
inst._zod.optout = "optional";
|
|
1461
|
+
defineLazy(inst._zod, "values", () => {
|
|
1462
|
+
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
1463
|
+
});
|
|
1464
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1465
|
+
const pattern = def.innerType._zod.pattern;
|
|
1466
|
+
return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
1467
|
+
});
|
|
1468
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1469
|
+
if (def.innerType._zod.optin === "optional") return def.innerType._zod.run(payload, ctx);
|
|
1470
|
+
if (payload.value === void 0) return payload;
|
|
1471
|
+
return def.innerType._zod.run(payload, ctx);
|
|
1472
|
+
};
|
|
1473
|
+
});
|
|
1474
|
+
const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
|
|
1475
|
+
$ZodType.init(inst, def);
|
|
1476
|
+
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
1477
|
+
defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
|
|
1478
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1479
|
+
const pattern = def.innerType._zod.pattern;
|
|
1480
|
+
return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
|
|
1481
|
+
});
|
|
1482
|
+
defineLazy(inst._zod, "values", () => {
|
|
1483
|
+
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
|
|
1484
|
+
});
|
|
1485
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1486
|
+
if (payload.value === null) return payload;
|
|
1487
|
+
return def.innerType._zod.run(payload, ctx);
|
|
1488
|
+
};
|
|
1489
|
+
});
|
|
1490
|
+
const $ZodLazy = /* @__PURE__ */ $constructor("$ZodLazy", (inst, def) => {
|
|
1491
|
+
$ZodType.init(inst, def);
|
|
1492
|
+
defineLazy(inst._zod, "innerType", () => def.getter());
|
|
1493
|
+
defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
|
|
1494
|
+
defineLazy(inst._zod, "propValues", () => inst._zod.innerType._zod.propValues);
|
|
1495
|
+
defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin);
|
|
1496
|
+
defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout);
|
|
1497
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1498
|
+
const inner = inst._zod.innerType;
|
|
1499
|
+
return inner._zod.run(payload, ctx);
|
|
1500
|
+
};
|
|
1501
|
+
});
|
|
1502
|
+
const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
1503
|
+
$ZodCheck.init(inst, def);
|
|
1504
|
+
$ZodType.init(inst, def);
|
|
1505
|
+
inst._zod.parse = (payload, _) => {
|
|
1506
|
+
return payload;
|
|
1507
|
+
};
|
|
1508
|
+
inst._zod.check = (payload) => {
|
|
1509
|
+
const input = payload.value;
|
|
1510
|
+
const r = def.fn(input);
|
|
1511
|
+
if (r instanceof Promise) return r.then((r$1) => handleRefineResult(r$1, payload, input, inst));
|
|
1512
|
+
handleRefineResult(r, payload, input, inst);
|
|
1513
|
+
return;
|
|
1514
|
+
};
|
|
1515
|
+
});
|
|
1516
|
+
function handleRefineResult(result, payload, input, inst) {
|
|
1517
|
+
if (!result) {
|
|
1518
|
+
const _iss = {
|
|
1519
|
+
code: "custom",
|
|
1520
|
+
input,
|
|
1521
|
+
inst,
|
|
1522
|
+
path: [...inst._zod.def.path ?? []],
|
|
1523
|
+
continue: !inst._zod.def.abort
|
|
1524
|
+
};
|
|
1525
|
+
if (inst._zod.def.params) _iss.params = inst._zod.def.params;
|
|
1526
|
+
payload.issues.push(issue(_iss));
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
function _string(Class, params) {
|
|
1530
|
+
return new Class({
|
|
1531
|
+
type: "string",
|
|
1532
|
+
...normalizeParams(params)
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
function _number(Class, params) {
|
|
1536
|
+
return new Class({
|
|
1537
|
+
type: "number",
|
|
1538
|
+
checks: [],
|
|
1539
|
+
...normalizeParams(params)
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
function _boolean(Class, params) {
|
|
1543
|
+
return new Class({
|
|
1544
|
+
type: "boolean",
|
|
1545
|
+
...normalizeParams(params)
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
function _null$1(Class, params) {
|
|
1549
|
+
return new Class({
|
|
1550
|
+
type: "null",
|
|
1551
|
+
...normalizeParams(params)
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
function _any(Class) {
|
|
1555
|
+
return new Class({ type: "any" });
|
|
1556
|
+
}
|
|
1557
|
+
function _unknown(Class) {
|
|
1558
|
+
return new Class({ type: "unknown" });
|
|
1559
|
+
}
|
|
1560
|
+
function _custom(Class, fn, _params) {
|
|
1561
|
+
const norm = normalizeParams(_params);
|
|
1562
|
+
norm.abort ?? (norm.abort = true);
|
|
1563
|
+
const schema = new Class({
|
|
1564
|
+
type: "custom",
|
|
1565
|
+
check: "custom",
|
|
1566
|
+
fn,
|
|
1567
|
+
...norm
|
|
1568
|
+
});
|
|
1569
|
+
return schema;
|
|
1570
|
+
}
|
|
1571
|
+
const ZodMiniType = /* @__PURE__ */ $constructor("ZodMiniType", (inst, def) => {
|
|
1572
|
+
if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
|
|
1573
|
+
$ZodType.init(inst, def);
|
|
1574
|
+
inst.def = def;
|
|
1575
|
+
inst.parse = (data, params) => parse$2(inst, data, params, { callee: inst.parse });
|
|
1576
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
1577
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
1578
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
1579
|
+
inst.check = (...checks) => {
|
|
1580
|
+
return inst.clone({
|
|
1581
|
+
...def,
|
|
1582
|
+
checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
|
|
1583
|
+
check: ch,
|
|
1584
|
+
def: { check: "custom" },
|
|
1585
|
+
onattach: []
|
|
1586
|
+
} } : ch)]
|
|
1587
|
+
});
|
|
1588
|
+
};
|
|
1589
|
+
inst.clone = (_def, params) => clone(inst, _def, params);
|
|
1590
|
+
inst.brand = () => inst;
|
|
1591
|
+
inst.register = ((reg, meta) => {
|
|
1592
|
+
reg.add(inst, meta);
|
|
1593
|
+
return inst;
|
|
1594
|
+
});
|
|
1595
|
+
});
|
|
1596
|
+
const ZodMiniString = /* @__PURE__ */ $constructor("ZodMiniString", (inst, def) => {
|
|
1597
|
+
$ZodString.init(inst, def);
|
|
1598
|
+
ZodMiniType.init(inst, def);
|
|
1599
|
+
});
|
|
1600
|
+
function string(params) {
|
|
1601
|
+
return _string(ZodMiniString, params);
|
|
1602
|
+
}
|
|
1603
|
+
const ZodMiniNumber = /* @__PURE__ */ $constructor("ZodMiniNumber", (inst, def) => {
|
|
1604
|
+
$ZodNumber.init(inst, def);
|
|
1605
|
+
ZodMiniType.init(inst, def);
|
|
1606
|
+
});
|
|
1607
|
+
function number(params) {
|
|
1608
|
+
return _number(ZodMiniNumber, params);
|
|
1609
|
+
}
|
|
1610
|
+
const ZodMiniBoolean = /* @__PURE__ */ $constructor("ZodMiniBoolean", (inst, def) => {
|
|
1611
|
+
$ZodBoolean.init(inst, def);
|
|
1612
|
+
ZodMiniType.init(inst, def);
|
|
1613
|
+
});
|
|
1614
|
+
function boolean(params) {
|
|
1615
|
+
return _boolean(ZodMiniBoolean, params);
|
|
1616
|
+
}
|
|
1617
|
+
const ZodMiniNull = /* @__PURE__ */ $constructor("ZodMiniNull", (inst, def) => {
|
|
1618
|
+
$ZodNull.init(inst, def);
|
|
1619
|
+
ZodMiniType.init(inst, def);
|
|
1620
|
+
});
|
|
1621
|
+
function _null(params) {
|
|
1622
|
+
return _null$1(ZodMiniNull, params);
|
|
1623
|
+
}
|
|
1624
|
+
const ZodMiniAny = /* @__PURE__ */ $constructor("ZodMiniAny", (inst, def) => {
|
|
1625
|
+
$ZodAny.init(inst, def);
|
|
1626
|
+
ZodMiniType.init(inst, def);
|
|
1627
|
+
});
|
|
1628
|
+
function any() {
|
|
1629
|
+
return _any(ZodMiniAny);
|
|
1630
|
+
}
|
|
1631
|
+
const ZodMiniUnknown = /* @__PURE__ */ $constructor("ZodMiniUnknown", (inst, def) => {
|
|
1632
|
+
$ZodUnknown.init(inst, def);
|
|
1633
|
+
ZodMiniType.init(inst, def);
|
|
1634
|
+
});
|
|
1635
|
+
function unknown() {
|
|
1636
|
+
return _unknown(ZodMiniUnknown);
|
|
1637
|
+
}
|
|
1638
|
+
const ZodMiniArray = /* @__PURE__ */ $constructor("ZodMiniArray", (inst, def) => {
|
|
1639
|
+
$ZodArray.init(inst, def);
|
|
1640
|
+
ZodMiniType.init(inst, def);
|
|
1641
|
+
});
|
|
1642
|
+
function array(element, params) {
|
|
1643
|
+
return new ZodMiniArray({
|
|
1644
|
+
type: "array",
|
|
1645
|
+
element,
|
|
1646
|
+
...normalizeParams(params)
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
const ZodMiniObject = /* @__PURE__ */ $constructor("ZodMiniObject", (inst, def) => {
|
|
1650
|
+
$ZodObject.init(inst, def);
|
|
1651
|
+
ZodMiniType.init(inst, def);
|
|
1652
|
+
defineLazy(inst, "shape", () => def.shape);
|
|
1653
|
+
});
|
|
1654
|
+
function object(shape, params) {
|
|
1655
|
+
const def = {
|
|
1656
|
+
type: "object",
|
|
1657
|
+
get shape() {
|
|
1658
|
+
assignProp$1(this, "shape", { ...shape });
|
|
1659
|
+
return this.shape;
|
|
1660
|
+
},
|
|
1661
|
+
...normalizeParams(params)
|
|
1662
|
+
};
|
|
1663
|
+
return new ZodMiniObject(def);
|
|
1664
|
+
}
|
|
1665
|
+
function looseObject(shape, params) {
|
|
1666
|
+
return new ZodMiniObject({
|
|
1667
|
+
type: "object",
|
|
1668
|
+
get shape() {
|
|
1669
|
+
assignProp$1(this, "shape", { ...shape });
|
|
1670
|
+
return this.shape;
|
|
1671
|
+
},
|
|
1672
|
+
catchall: unknown(),
|
|
1673
|
+
...normalizeParams(params)
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
function extend(schema, shape) {
|
|
1677
|
+
return extend$1(schema, shape);
|
|
1678
|
+
}
|
|
1679
|
+
const ZodMiniUnion = /* @__PURE__ */ $constructor("ZodMiniUnion", (inst, def) => {
|
|
1680
|
+
$ZodUnion.init(inst, def);
|
|
1681
|
+
ZodMiniType.init(inst, def);
|
|
1682
|
+
});
|
|
1683
|
+
function union(options, params) {
|
|
1684
|
+
return new ZodMiniUnion({
|
|
1685
|
+
type: "union",
|
|
1686
|
+
options,
|
|
1687
|
+
...normalizeParams(params)
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
const ZodMiniRecord = /* @__PURE__ */ $constructor("ZodMiniRecord", (inst, def) => {
|
|
1691
|
+
$ZodRecord.init(inst, def);
|
|
1692
|
+
ZodMiniType.init(inst, def);
|
|
1693
|
+
});
|
|
1694
|
+
function record(keyType, valueType, params) {
|
|
1695
|
+
return new ZodMiniRecord({
|
|
1696
|
+
type: "record",
|
|
1697
|
+
keyType,
|
|
1698
|
+
valueType,
|
|
1699
|
+
...normalizeParams(params)
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
const ZodMiniEnum = /* @__PURE__ */ $constructor("ZodMiniEnum", (inst, def) => {
|
|
1703
|
+
$ZodEnum.init(inst, def);
|
|
1704
|
+
ZodMiniType.init(inst, def);
|
|
1705
|
+
});
|
|
1706
|
+
function _enum(values, params) {
|
|
1707
|
+
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
|
|
1708
|
+
return new ZodMiniEnum({
|
|
1709
|
+
type: "enum",
|
|
1710
|
+
entries,
|
|
1711
|
+
...normalizeParams(params)
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1714
|
+
const ZodMiniLiteral = /* @__PURE__ */ $constructor("ZodMiniLiteral", (inst, def) => {
|
|
1715
|
+
$ZodLiteral.init(inst, def);
|
|
1716
|
+
ZodMiniType.init(inst, def);
|
|
1717
|
+
});
|
|
1718
|
+
function literal(value, params) {
|
|
1719
|
+
return new ZodMiniLiteral({
|
|
1720
|
+
type: "literal",
|
|
1721
|
+
values: Array.isArray(value) ? value : [value],
|
|
1722
|
+
...normalizeParams(params)
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
const ZodMiniOptional = /* @__PURE__ */ $constructor("ZodMiniOptional", (inst, def) => {
|
|
1726
|
+
$ZodOptional.init(inst, def);
|
|
1727
|
+
ZodMiniType.init(inst, def);
|
|
1728
|
+
});
|
|
1729
|
+
function optional(innerType) {
|
|
1730
|
+
return new ZodMiniOptional({
|
|
1731
|
+
type: "optional",
|
|
1732
|
+
innerType
|
|
1733
|
+
});
|
|
1734
|
+
}
|
|
1735
|
+
const ZodMiniNullable = /* @__PURE__ */ $constructor("ZodMiniNullable", (inst, def) => {
|
|
1736
|
+
$ZodNullable.init(inst, def);
|
|
1737
|
+
ZodMiniType.init(inst, def);
|
|
1738
|
+
});
|
|
1739
|
+
function nullable(innerType) {
|
|
1740
|
+
return new ZodMiniNullable({
|
|
1741
|
+
type: "nullable",
|
|
1742
|
+
innerType
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
const ZodMiniLazy = /* @__PURE__ */ $constructor("ZodMiniLazy", (inst, def) => {
|
|
1746
|
+
$ZodLazy.init(inst, def);
|
|
1747
|
+
ZodMiniType.init(inst, def);
|
|
1748
|
+
});
|
|
1749
|
+
function _lazy(getter) {
|
|
1750
|
+
return new ZodMiniLazy({
|
|
1751
|
+
type: "lazy",
|
|
1752
|
+
getter
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
const ZodMiniCustom = /* @__PURE__ */ $constructor("ZodMiniCustom", (inst, def) => {
|
|
1756
|
+
$ZodCustom.init(inst, def);
|
|
1757
|
+
ZodMiniType.init(inst, def);
|
|
1758
|
+
});
|
|
1759
|
+
function custom(fn, _params) {
|
|
1760
|
+
return _custom(ZodMiniCustom, fn ?? (() => true), _params);
|
|
1761
|
+
}
|
|
1762
|
+
function _instanceof(cls, params = { error: `Input not instance of ${cls.name}` }) {
|
|
1763
|
+
const inst = custom((data) => data instanceof cls, params);
|
|
1764
|
+
inst._zod.bag.Class = cls;
|
|
1765
|
+
return inst;
|
|
1766
|
+
}
|
|
1767
|
+
var DuplexClosedError = class extends Error {
|
|
1768
|
+
constructor(reason) {
|
|
1769
|
+
super(`The duplex channel was closed unexpectedly. Reason: ${reason}`);
|
|
1770
|
+
this.name = "DuplexClosedError";
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
var WaitTimeoutError = class extends Error {
|
|
1774
|
+
constructor(timeout) {
|
|
1775
|
+
super(`Waited for next task for ${timeout}ms, but no data was received.`);
|
|
1776
|
+
this.name = "WaitTimeoutError";
|
|
1777
|
+
}
|
|
1778
|
+
};
|
|
1779
|
+
function waitNextTask(duplex, options = {}) {
|
|
1780
|
+
return new Promise((resolve, reject) => {
|
|
1781
|
+
let timeoutId;
|
|
1782
|
+
const cleanup = () => {
|
|
1783
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
1784
|
+
offData();
|
|
1785
|
+
offClose();
|
|
1786
|
+
};
|
|
1787
|
+
const offData = duplex.onData.on((data) => {
|
|
1788
|
+
if (!options.filter || options.filter(data)) {
|
|
1789
|
+
cleanup();
|
|
1790
|
+
resolve(data);
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1793
|
+
const offClose = duplex.onClose.on((reason) => {
|
|
1794
|
+
cleanup();
|
|
1795
|
+
reject(new DuplexClosedError(reason));
|
|
1796
|
+
});
|
|
1797
|
+
if (options.timeout) timeoutId = setTimeout(() => {
|
|
1798
|
+
cleanup();
|
|
1799
|
+
reject(new WaitTimeoutError(options.timeout));
|
|
1800
|
+
}, options.timeout);
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
const zEvalTask = object({
|
|
1804
|
+
type: literal("eval"),
|
|
1805
|
+
taskId: string(),
|
|
1806
|
+
code: string(),
|
|
1807
|
+
status: _enum([
|
|
1808
|
+
"initial",
|
|
1809
|
+
"pending",
|
|
1810
|
+
"fulfilled",
|
|
1811
|
+
"rejected"
|
|
1812
|
+
]),
|
|
1813
|
+
result: any(),
|
|
1814
|
+
done: boolean()
|
|
1815
|
+
});
|
|
1816
|
+
async function doEval(duplex, initialTask) {
|
|
1817
|
+
const output = {
|
|
1818
|
+
...initialTask,
|
|
1819
|
+
status: "pending"
|
|
1820
|
+
};
|
|
1821
|
+
try {
|
|
1822
|
+
const result = await (async () => eval(output.code))();
|
|
1823
|
+
output.status = "fulfilled";
|
|
1824
|
+
output.result = result;
|
|
1825
|
+
} catch (e) {
|
|
1826
|
+
output.status = "rejected";
|
|
1827
|
+
output.result = e instanceof Error ? {
|
|
1828
|
+
message: e.message,
|
|
1829
|
+
name: e.name,
|
|
1830
|
+
stack: e.stack
|
|
1831
|
+
} : e;
|
|
1832
|
+
} finally {
|
|
1833
|
+
output.done = true;
|
|
1834
|
+
duplex.sendData(output);
|
|
1835
|
+
duplex.close("done");
|
|
1836
|
+
}
|
|
1837
|
+
}
|
|
1838
|
+
const createRunCodeInBrowser = (runner) => {
|
|
1839
|
+
return async (dir, code) => {
|
|
1840
|
+
const initialTask = {
|
|
1841
|
+
type: "eval",
|
|
1842
|
+
taskId: crypto.randomUUID(),
|
|
1843
|
+
code,
|
|
1844
|
+
status: "initial",
|
|
1845
|
+
result: null,
|
|
1846
|
+
done: false
|
|
1847
|
+
};
|
|
1848
|
+
const duplex = await runner({
|
|
1849
|
+
dir,
|
|
1850
|
+
initialTask
|
|
1851
|
+
});
|
|
1852
|
+
try {
|
|
1853
|
+
const finalTask = await waitNextTask(duplex, {
|
|
1854
|
+
filter: (task) => task.done,
|
|
1855
|
+
timeout: 3e4
|
|
1856
|
+
});
|
|
1857
|
+
if (finalTask.status === "rejected") throw finalTask.result;
|
|
1858
|
+
else return finalTask.result;
|
|
1859
|
+
} finally {
|
|
1860
|
+
duplex.close();
|
|
1861
|
+
}
|
|
1862
|
+
};
|
|
1863
|
+
};
|
|
1864
|
+
const zBaseFetchTask = object({
|
|
1865
|
+
type: literal("fetch"),
|
|
1866
|
+
taskId: string()
|
|
1867
|
+
});
|
|
1868
|
+
const zFetchInitialCommand = extend(zBaseFetchTask, {
|
|
1869
|
+
status: literal("initial"),
|
|
1870
|
+
url: string(),
|
|
1871
|
+
init: optional(any()),
|
|
1872
|
+
done: literal(false)
|
|
1873
|
+
});
|
|
1874
|
+
const zFetchGetFullBodyCommand = extend(zBaseFetchTask, {
|
|
1875
|
+
sub_command: literal("getFullBody"),
|
|
1876
|
+
format: _enum(["json", "text"])
|
|
1877
|
+
});
|
|
1878
|
+
const zFetchRequestChunkCommand = extend(zBaseFetchTask, { sub_command: literal("requestChunk") });
|
|
1879
|
+
const zFetchRespondedEvent = extend(zBaseFetchTask, {
|
|
1880
|
+
status: literal("responded"),
|
|
1881
|
+
response: object({
|
|
1882
|
+
headers: record(string()),
|
|
1883
|
+
ok: boolean(),
|
|
1884
|
+
status: number(),
|
|
1885
|
+
statusText: string()
|
|
1886
|
+
}),
|
|
1887
|
+
done: literal(false)
|
|
1888
|
+
});
|
|
1889
|
+
const zFetchFulfilledEvent = extend(zBaseFetchTask, {
|
|
1890
|
+
status: literal("fulfilled"),
|
|
1891
|
+
result: any(),
|
|
1892
|
+
done: literal(true)
|
|
1893
|
+
});
|
|
1894
|
+
const zFetchChunkEvent = extend(zBaseFetchTask, {
|
|
1895
|
+
status: literal("chunk"),
|
|
1896
|
+
payload: _instanceof(Uint8Array),
|
|
1897
|
+
done: literal(false)
|
|
1898
|
+
});
|
|
1899
|
+
const zFetchChunkEndEvent = extend(zBaseFetchTask, {
|
|
1900
|
+
status: literal("chunk_end"),
|
|
1901
|
+
done: literal(true)
|
|
1902
|
+
});
|
|
1903
|
+
const zFetchErrorEvent = extend(zBaseFetchTask, {
|
|
1904
|
+
status: union([literal("rejected"), literal("chunk_error")]),
|
|
1905
|
+
error: any(),
|
|
1906
|
+
done: literal(true)
|
|
1907
|
+
});
|
|
1908
|
+
const zFetchTask = union([
|
|
1909
|
+
zFetchInitialCommand,
|
|
1910
|
+
zFetchGetFullBodyCommand,
|
|
1911
|
+
zFetchRequestChunkCommand,
|
|
1912
|
+
zFetchRespondedEvent,
|
|
1913
|
+
zFetchFulfilledEvent,
|
|
1914
|
+
zFetchChunkEvent,
|
|
1915
|
+
zFetchChunkEndEvent,
|
|
1916
|
+
zFetchErrorEvent
|
|
1917
|
+
]);
|
|
1918
|
+
async function doFetch(duplex, initialTask) {
|
|
1919
|
+
let bodyReader;
|
|
1920
|
+
try {
|
|
1921
|
+
const response = await fetch(initialTask.url, initialTask.init);
|
|
1922
|
+
bodyReader = response.body?.getReader();
|
|
1923
|
+
const responseHeaders = {};
|
|
1924
|
+
response.headers.forEach((value, key) => responseHeaders[key] = value);
|
|
1925
|
+
duplex.sendData({
|
|
1926
|
+
type: "fetch",
|
|
1927
|
+
taskId: initialTask.taskId,
|
|
1928
|
+
status: "responded",
|
|
1929
|
+
response: {
|
|
1930
|
+
headers: responseHeaders,
|
|
1931
|
+
ok: response.ok,
|
|
1932
|
+
status: response.status,
|
|
1933
|
+
statusText: response.statusText
|
|
1934
|
+
},
|
|
1935
|
+
done: false
|
|
1936
|
+
});
|
|
1937
|
+
while (duplex.currentState === "open") {
|
|
1938
|
+
const commandTask = await waitNextTask(duplex, { timeout: 6e4 });
|
|
1939
|
+
if ("sub_command" in commandTask) switch (commandTask.sub_command) {
|
|
1940
|
+
case "getFullBody":
|
|
1941
|
+
const body = commandTask.format === "json" ? await response.json() : await response.text();
|
|
1942
|
+
duplex.sendData({
|
|
1943
|
+
type: "fetch",
|
|
1944
|
+
taskId: initialTask.taskId,
|
|
1945
|
+
status: "fulfilled",
|
|
1946
|
+
result: body,
|
|
1947
|
+
done: true
|
|
1948
|
+
});
|
|
1949
|
+
return;
|
|
1950
|
+
case "requestChunk":
|
|
1951
|
+
if (!bodyReader) {
|
|
1952
|
+
duplex.sendData({
|
|
1953
|
+
type: "fetch",
|
|
1954
|
+
taskId: initialTask.taskId,
|
|
1955
|
+
status: "chunk_error",
|
|
1956
|
+
error: "Response body is not readable.",
|
|
1957
|
+
done: true
|
|
1958
|
+
});
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
const { done, value } = await bodyReader.read();
|
|
1962
|
+
if (done) {
|
|
1963
|
+
duplex.sendData({
|
|
1964
|
+
type: "fetch",
|
|
1965
|
+
taskId: initialTask.taskId,
|
|
1966
|
+
status: "chunk_end",
|
|
1967
|
+
done: true
|
|
1968
|
+
});
|
|
1969
|
+
return;
|
|
1970
|
+
}
|
|
1971
|
+
duplex.sendData({
|
|
1972
|
+
type: "fetch",
|
|
1973
|
+
taskId: initialTask.taskId,
|
|
1974
|
+
status: "chunk",
|
|
1975
|
+
payload: value,
|
|
1976
|
+
done: false
|
|
1977
|
+
});
|
|
1978
|
+
break;
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
} catch (e) {
|
|
1982
|
+
duplex.sendData({
|
|
1983
|
+
type: "fetch",
|
|
1984
|
+
taskId: initialTask.taskId,
|
|
1985
|
+
status: "rejected",
|
|
1986
|
+
error: e instanceof Error ? {
|
|
1987
|
+
message: e.message,
|
|
1988
|
+
stack: e.stack
|
|
1989
|
+
} : e,
|
|
1990
|
+
done: true
|
|
1991
|
+
});
|
|
1992
|
+
} finally {
|
|
1993
|
+
if (bodyReader) bodyReader.cancel().catch(() => {});
|
|
1994
|
+
duplex.close("done");
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
var require_ms = __commonJSMin((exports, module) => {
|
|
1998
|
+
var s = 1e3;
|
|
1999
|
+
var m = s * 60;
|
|
2000
|
+
var h = m * 60;
|
|
2001
|
+
var d = h * 24;
|
|
2002
|
+
var w = d * 7;
|
|
2003
|
+
var y = d * 365.25;
|
|
2004
|
+
module.exports = function(val, options) {
|
|
2005
|
+
options = options || {};
|
|
2006
|
+
var type = typeof val;
|
|
2007
|
+
if (type === "string" && val.length > 0) return parse$1(val);
|
|
2008
|
+
else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
|
|
2009
|
+
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
|
|
2010
|
+
};
|
|
2011
|
+
function parse$1(str) {
|
|
2012
|
+
str = String(str);
|
|
2013
|
+
if (str.length > 100) return;
|
|
2014
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
2015
|
+
if (!match) return;
|
|
2016
|
+
var n = parseFloat(match[1]);
|
|
2017
|
+
var type = (match[2] || "ms").toLowerCase();
|
|
2018
|
+
switch (type) {
|
|
2019
|
+
case "years":
|
|
2020
|
+
case "year":
|
|
2021
|
+
case "yrs":
|
|
2022
|
+
case "yr":
|
|
2023
|
+
case "y": return n * y;
|
|
2024
|
+
case "weeks":
|
|
2025
|
+
case "week":
|
|
2026
|
+
case "w": return n * w;
|
|
2027
|
+
case "days":
|
|
2028
|
+
case "day":
|
|
2029
|
+
case "d": return n * d;
|
|
2030
|
+
case "hours":
|
|
2031
|
+
case "hour":
|
|
2032
|
+
case "hrs":
|
|
2033
|
+
case "hr":
|
|
2034
|
+
case "h": return n * h;
|
|
2035
|
+
case "minutes":
|
|
2036
|
+
case "minute":
|
|
2037
|
+
case "mins":
|
|
2038
|
+
case "min":
|
|
2039
|
+
case "m": return n * m;
|
|
2040
|
+
case "seconds":
|
|
2041
|
+
case "second":
|
|
2042
|
+
case "secs":
|
|
2043
|
+
case "sec":
|
|
2044
|
+
case "s": return n * s;
|
|
2045
|
+
case "milliseconds":
|
|
2046
|
+
case "millisecond":
|
|
2047
|
+
case "msecs":
|
|
2048
|
+
case "msec":
|
|
2049
|
+
case "ms": return n;
|
|
2050
|
+
default: return void 0;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
function fmtShort(ms) {
|
|
2054
|
+
var msAbs = Math.abs(ms);
|
|
2055
|
+
if (msAbs >= d) return Math.round(ms / d) + "d";
|
|
2056
|
+
if (msAbs >= h) return Math.round(ms / h) + "h";
|
|
2057
|
+
if (msAbs >= m) return Math.round(ms / m) + "m";
|
|
2058
|
+
if (msAbs >= s) return Math.round(ms / s) + "s";
|
|
2059
|
+
return ms + "ms";
|
|
2060
|
+
}
|
|
2061
|
+
function fmtLong(ms) {
|
|
2062
|
+
var msAbs = Math.abs(ms);
|
|
2063
|
+
if (msAbs >= d) return plural(ms, msAbs, d, "day");
|
|
2064
|
+
if (msAbs >= h) return plural(ms, msAbs, h, "hour");
|
|
2065
|
+
if (msAbs >= m) return plural(ms, msAbs, m, "minute");
|
|
2066
|
+
if (msAbs >= s) return plural(ms, msAbs, s, "second");
|
|
2067
|
+
return ms + " ms";
|
|
2068
|
+
}
|
|
2069
|
+
function plural(ms, msAbs, n, name) {
|
|
2070
|
+
var isPlural = msAbs >= n * 1.5;
|
|
2071
|
+
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
var require_common = __commonJSMin((exports, module) => {
|
|
2075
|
+
function setup(env) {
|
|
2076
|
+
createDebug.debug = createDebug;
|
|
2077
|
+
createDebug.default = createDebug;
|
|
2078
|
+
createDebug.coerce = coerce;
|
|
2079
|
+
createDebug.disable = disable;
|
|
2080
|
+
createDebug.enable = enable;
|
|
2081
|
+
createDebug.enabled = enabled;
|
|
2082
|
+
createDebug.humanize = require_ms();
|
|
2083
|
+
createDebug.destroy = destroy;
|
|
2084
|
+
Object.keys(env).forEach((key) => {
|
|
2085
|
+
createDebug[key] = env[key];
|
|
2086
|
+
});
|
|
2087
|
+
createDebug.names = [];
|
|
2088
|
+
createDebug.skips = [];
|
|
2089
|
+
createDebug.formatters = {};
|
|
2090
|
+
function selectColor(namespace) {
|
|
2091
|
+
let hash = 0;
|
|
2092
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
2093
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
2094
|
+
hash |= 0;
|
|
2095
|
+
}
|
|
2096
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
2097
|
+
}
|
|
2098
|
+
createDebug.selectColor = selectColor;
|
|
2099
|
+
function createDebug(namespace) {
|
|
2100
|
+
let prevTime;
|
|
2101
|
+
let enableOverride = null;
|
|
2102
|
+
let namespacesCache;
|
|
2103
|
+
let enabledCache;
|
|
2104
|
+
function debug(...args) {
|
|
2105
|
+
if (!debug.enabled) return;
|
|
2106
|
+
const self = debug;
|
|
2107
|
+
const curr = Number(/* @__PURE__ */ new Date());
|
|
2108
|
+
const ms = curr - (prevTime || curr);
|
|
2109
|
+
self.diff = ms;
|
|
2110
|
+
self.prev = prevTime;
|
|
2111
|
+
self.curr = curr;
|
|
2112
|
+
prevTime = curr;
|
|
2113
|
+
args[0] = createDebug.coerce(args[0]);
|
|
2114
|
+
if (typeof args[0] !== "string") args.unshift("%O");
|
|
2115
|
+
let index = 0;
|
|
2116
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
2117
|
+
if (match === "%%") return "%";
|
|
2118
|
+
index++;
|
|
2119
|
+
const formatter = createDebug.formatters[format];
|
|
2120
|
+
if (typeof formatter === "function") {
|
|
2121
|
+
const val = args[index];
|
|
2122
|
+
match = formatter.call(self, val);
|
|
2123
|
+
args.splice(index, 1);
|
|
2124
|
+
index--;
|
|
2125
|
+
}
|
|
2126
|
+
return match;
|
|
2127
|
+
});
|
|
2128
|
+
createDebug.formatArgs.call(self, args);
|
|
2129
|
+
const logFn = self.log || createDebug.log;
|
|
2130
|
+
logFn.apply(self, args);
|
|
2131
|
+
}
|
|
2132
|
+
debug.namespace = namespace;
|
|
2133
|
+
debug.useColors = createDebug.useColors();
|
|
2134
|
+
debug.color = createDebug.selectColor(namespace);
|
|
2135
|
+
debug.extend = extend$2;
|
|
2136
|
+
debug.destroy = createDebug.destroy;
|
|
2137
|
+
Object.defineProperty(debug, "enabled", {
|
|
2138
|
+
enumerable: true,
|
|
2139
|
+
configurable: false,
|
|
2140
|
+
get: () => {
|
|
2141
|
+
if (enableOverride !== null) return enableOverride;
|
|
2142
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
2143
|
+
namespacesCache = createDebug.namespaces;
|
|
2144
|
+
enabledCache = createDebug.enabled(namespace);
|
|
2145
|
+
}
|
|
2146
|
+
return enabledCache;
|
|
2147
|
+
},
|
|
2148
|
+
set: (v) => {
|
|
2149
|
+
enableOverride = v;
|
|
2150
|
+
}
|
|
2151
|
+
});
|
|
2152
|
+
if (typeof createDebug.init === "function") createDebug.init(debug);
|
|
2153
|
+
return debug;
|
|
2154
|
+
}
|
|
2155
|
+
function extend$2(namespace, delimiter) {
|
|
2156
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
2157
|
+
newDebug.log = this.log;
|
|
2158
|
+
return newDebug;
|
|
2159
|
+
}
|
|
2160
|
+
function enable(namespaces) {
|
|
2161
|
+
createDebug.save(namespaces);
|
|
2162
|
+
createDebug.namespaces = namespaces;
|
|
2163
|
+
createDebug.names = [];
|
|
2164
|
+
createDebug.skips = [];
|
|
2165
|
+
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
2166
|
+
for (const ns of split) if (ns[0] === "-") createDebug.skips.push(ns.slice(1));
|
|
2167
|
+
else createDebug.names.push(ns);
|
|
2168
|
+
}
|
|
2169
|
+
function matchesTemplate(search, template) {
|
|
2170
|
+
let searchIndex = 0;
|
|
2171
|
+
let templateIndex = 0;
|
|
2172
|
+
let starIndex = -1;
|
|
2173
|
+
let matchIndex = 0;
|
|
2174
|
+
while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) if (template[templateIndex] === "*") {
|
|
2175
|
+
starIndex = templateIndex;
|
|
2176
|
+
matchIndex = searchIndex;
|
|
2177
|
+
templateIndex++;
|
|
2178
|
+
} else {
|
|
2179
|
+
searchIndex++;
|
|
2180
|
+
templateIndex++;
|
|
2181
|
+
}
|
|
2182
|
+
else if (starIndex !== -1) {
|
|
2183
|
+
templateIndex = starIndex + 1;
|
|
2184
|
+
matchIndex++;
|
|
2185
|
+
searchIndex = matchIndex;
|
|
2186
|
+
} else return false;
|
|
2187
|
+
while (templateIndex < template.length && template[templateIndex] === "*") templateIndex++;
|
|
2188
|
+
return templateIndex === template.length;
|
|
2189
|
+
}
|
|
2190
|
+
function disable() {
|
|
2191
|
+
const namespaces = [...createDebug.names, ...createDebug.skips.map((namespace) => "-" + namespace)].join(",");
|
|
2192
|
+
createDebug.enable("");
|
|
2193
|
+
return namespaces;
|
|
2194
|
+
}
|
|
2195
|
+
function enabled(name) {
|
|
2196
|
+
for (const skip of createDebug.skips) if (matchesTemplate(name, skip)) return false;
|
|
2197
|
+
for (const ns of createDebug.names) if (matchesTemplate(name, ns)) return true;
|
|
2198
|
+
return false;
|
|
2199
|
+
}
|
|
2200
|
+
function coerce(val) {
|
|
2201
|
+
if (val instanceof Error) return val.stack || val.message;
|
|
2202
|
+
return val;
|
|
2203
|
+
}
|
|
2204
|
+
function destroy() {
|
|
2205
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
2206
|
+
}
|
|
2207
|
+
createDebug.enable(createDebug.load());
|
|
2208
|
+
return createDebug;
|
|
2209
|
+
}
|
|
2210
|
+
module.exports = setup;
|
|
2211
|
+
});
|
|
2212
|
+
var require_browser = __commonJSMin((exports, module) => {
|
|
2213
|
+
exports.formatArgs = formatArgs$1;
|
|
2214
|
+
exports.save = save$1;
|
|
2215
|
+
exports.load = load$1;
|
|
2216
|
+
exports.useColors = useColors$1;
|
|
2217
|
+
exports.storage = localstorage();
|
|
2218
|
+
exports.destroy = (() => {
|
|
2219
|
+
let warned = false;
|
|
2220
|
+
return () => {
|
|
2221
|
+
if (!warned) {
|
|
2222
|
+
warned = true;
|
|
2223
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
})();
|
|
2227
|
+
exports.colors = [
|
|
2228
|
+
"#0000CC",
|
|
2229
|
+
"#0000FF",
|
|
2230
|
+
"#0033CC",
|
|
2231
|
+
"#0033FF",
|
|
2232
|
+
"#0066CC",
|
|
2233
|
+
"#0066FF",
|
|
2234
|
+
"#0099CC",
|
|
2235
|
+
"#0099FF",
|
|
2236
|
+
"#00CC00",
|
|
2237
|
+
"#00CC33",
|
|
2238
|
+
"#00CC66",
|
|
2239
|
+
"#00CC99",
|
|
2240
|
+
"#00CCCC",
|
|
2241
|
+
"#00CCFF",
|
|
2242
|
+
"#3300CC",
|
|
2243
|
+
"#3300FF",
|
|
2244
|
+
"#3333CC",
|
|
2245
|
+
"#3333FF",
|
|
2246
|
+
"#3366CC",
|
|
2247
|
+
"#3366FF",
|
|
2248
|
+
"#3399CC",
|
|
2249
|
+
"#3399FF",
|
|
2250
|
+
"#33CC00",
|
|
2251
|
+
"#33CC33",
|
|
2252
|
+
"#33CC66",
|
|
2253
|
+
"#33CC99",
|
|
2254
|
+
"#33CCCC",
|
|
2255
|
+
"#33CCFF",
|
|
2256
|
+
"#6600CC",
|
|
2257
|
+
"#6600FF",
|
|
2258
|
+
"#6633CC",
|
|
2259
|
+
"#6633FF",
|
|
2260
|
+
"#66CC00",
|
|
2261
|
+
"#66CC33",
|
|
2262
|
+
"#9900CC",
|
|
2263
|
+
"#9900FF",
|
|
2264
|
+
"#9933CC",
|
|
2265
|
+
"#9933FF",
|
|
2266
|
+
"#99CC00",
|
|
2267
|
+
"#99CC33",
|
|
2268
|
+
"#CC0000",
|
|
2269
|
+
"#CC0033",
|
|
2270
|
+
"#CC0066",
|
|
2271
|
+
"#CC0099",
|
|
2272
|
+
"#CC00CC",
|
|
2273
|
+
"#CC00FF",
|
|
2274
|
+
"#CC3300",
|
|
2275
|
+
"#CC3333",
|
|
2276
|
+
"#CC3366",
|
|
2277
|
+
"#CC3399",
|
|
2278
|
+
"#CC33CC",
|
|
2279
|
+
"#CC33FF",
|
|
2280
|
+
"#CC6600",
|
|
2281
|
+
"#CC6633",
|
|
2282
|
+
"#CC9900",
|
|
2283
|
+
"#CC9933",
|
|
2284
|
+
"#CCCC00",
|
|
2285
|
+
"#CCCC33",
|
|
2286
|
+
"#FF0000",
|
|
2287
|
+
"#FF0033",
|
|
2288
|
+
"#FF0066",
|
|
2289
|
+
"#FF0099",
|
|
2290
|
+
"#FF00CC",
|
|
2291
|
+
"#FF00FF",
|
|
2292
|
+
"#FF3300",
|
|
2293
|
+
"#FF3333",
|
|
2294
|
+
"#FF3366",
|
|
2295
|
+
"#FF3399",
|
|
2296
|
+
"#FF33CC",
|
|
2297
|
+
"#FF33FF",
|
|
2298
|
+
"#FF6600",
|
|
2299
|
+
"#FF6633",
|
|
2300
|
+
"#FF9900",
|
|
2301
|
+
"#FF9933",
|
|
2302
|
+
"#FFCC00",
|
|
2303
|
+
"#FFCC33"
|
|
2304
|
+
];
|
|
2305
|
+
function useColors$1() {
|
|
2306
|
+
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return true;
|
|
2307
|
+
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return false;
|
|
2308
|
+
let m$1;
|
|
2309
|
+
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && (m$1 = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m$1[1], 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
2310
|
+
}
|
|
2311
|
+
function formatArgs$1(args) {
|
|
2312
|
+
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
|
|
2313
|
+
if (!this.useColors) return;
|
|
2314
|
+
const c = "color: " + this.color;
|
|
2315
|
+
args.splice(1, 0, c, "color: inherit");
|
|
2316
|
+
let index = 0;
|
|
2317
|
+
let lastC = 0;
|
|
2318
|
+
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
2319
|
+
if (match === "%%") return;
|
|
2320
|
+
index++;
|
|
2321
|
+
if (match === "%c") lastC = index;
|
|
2322
|
+
});
|
|
2323
|
+
args.splice(lastC, 0, c);
|
|
2324
|
+
}
|
|
2325
|
+
exports.log = console.debug || console.log || (() => {});
|
|
2326
|
+
function save$1(namespaces) {
|
|
2327
|
+
try {
|
|
2328
|
+
if (namespaces) exports.storage.setItem("debug", namespaces);
|
|
2329
|
+
else exports.storage.removeItem("debug");
|
|
2330
|
+
} catch (error) {}
|
|
2331
|
+
}
|
|
2332
|
+
function load$1() {
|
|
2333
|
+
let r;
|
|
2334
|
+
try {
|
|
2335
|
+
r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
|
|
2336
|
+
} catch (error) {}
|
|
2337
|
+
if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
|
|
2338
|
+
return r;
|
|
2339
|
+
}
|
|
2340
|
+
function localstorage() {
|
|
2341
|
+
try {
|
|
2342
|
+
return localStorage;
|
|
2343
|
+
} catch (error) {}
|
|
2344
|
+
}
|
|
2345
|
+
module.exports = require_common()(exports);
|
|
2346
|
+
const { formatters: formatters$1 } = module.exports;
|
|
2347
|
+
formatters$1.j = function(v) {
|
|
2348
|
+
try {
|
|
2349
|
+
return JSON.stringify(v);
|
|
2350
|
+
} catch (error) {
|
|
2351
|
+
return "[UnexpectedJSONParseError]: " + error.message;
|
|
2352
|
+
}
|
|
2353
|
+
};
|
|
2354
|
+
});
|
|
2355
|
+
var require_node = __commonJSMin((exports, module) => {
|
|
2356
|
+
const tty = __require("tty");
|
|
2357
|
+
const util = __require("util");
|
|
2358
|
+
exports.init = init;
|
|
2359
|
+
exports.log = log;
|
|
2360
|
+
exports.formatArgs = formatArgs;
|
|
2361
|
+
exports.save = save;
|
|
2362
|
+
exports.load = load;
|
|
2363
|
+
exports.useColors = useColors;
|
|
2364
|
+
exports.destroy = util.deprecate(() => {}, "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
2365
|
+
exports.colors = [
|
|
2366
|
+
6,
|
|
2367
|
+
2,
|
|
2368
|
+
3,
|
|
2369
|
+
4,
|
|
2370
|
+
5,
|
|
2371
|
+
1
|
|
2372
|
+
];
|
|
2373
|
+
try {
|
|
2374
|
+
const supportsColor = __require("supports-color");
|
|
2375
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) exports.colors = [
|
|
2376
|
+
20,
|
|
2377
|
+
21,
|
|
2378
|
+
26,
|
|
2379
|
+
27,
|
|
2380
|
+
32,
|
|
2381
|
+
33,
|
|
2382
|
+
38,
|
|
2383
|
+
39,
|
|
2384
|
+
40,
|
|
2385
|
+
41,
|
|
2386
|
+
42,
|
|
2387
|
+
43,
|
|
2388
|
+
44,
|
|
2389
|
+
45,
|
|
2390
|
+
56,
|
|
2391
|
+
57,
|
|
2392
|
+
62,
|
|
2393
|
+
63,
|
|
2394
|
+
68,
|
|
2395
|
+
69,
|
|
2396
|
+
74,
|
|
2397
|
+
75,
|
|
2398
|
+
76,
|
|
2399
|
+
77,
|
|
2400
|
+
78,
|
|
2401
|
+
79,
|
|
2402
|
+
80,
|
|
2403
|
+
81,
|
|
2404
|
+
92,
|
|
2405
|
+
93,
|
|
2406
|
+
98,
|
|
2407
|
+
99,
|
|
2408
|
+
112,
|
|
2409
|
+
113,
|
|
2410
|
+
128,
|
|
2411
|
+
129,
|
|
2412
|
+
134,
|
|
2413
|
+
135,
|
|
2414
|
+
148,
|
|
2415
|
+
149,
|
|
2416
|
+
160,
|
|
2417
|
+
161,
|
|
2418
|
+
162,
|
|
2419
|
+
163,
|
|
2420
|
+
164,
|
|
2421
|
+
165,
|
|
2422
|
+
166,
|
|
2423
|
+
167,
|
|
2424
|
+
168,
|
|
2425
|
+
169,
|
|
2426
|
+
170,
|
|
2427
|
+
171,
|
|
2428
|
+
172,
|
|
2429
|
+
173,
|
|
2430
|
+
178,
|
|
2431
|
+
179,
|
|
2432
|
+
184,
|
|
2433
|
+
185,
|
|
2434
|
+
196,
|
|
2435
|
+
197,
|
|
2436
|
+
198,
|
|
2437
|
+
199,
|
|
2438
|
+
200,
|
|
2439
|
+
201,
|
|
2440
|
+
202,
|
|
2441
|
+
203,
|
|
2442
|
+
204,
|
|
2443
|
+
205,
|
|
2444
|
+
206,
|
|
2445
|
+
207,
|
|
2446
|
+
208,
|
|
2447
|
+
209,
|
|
2448
|
+
214,
|
|
2449
|
+
215,
|
|
2450
|
+
220,
|
|
2451
|
+
221
|
|
2452
|
+
];
|
|
2453
|
+
} catch (error) {}
|
|
2454
|
+
exports.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
2455
|
+
return /^debug_/i.test(key);
|
|
2456
|
+
}).reduce((obj, key) => {
|
|
2457
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
2458
|
+
return k.toUpperCase();
|
|
2459
|
+
});
|
|
2460
|
+
let val = process.env[key];
|
|
2461
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
|
|
2462
|
+
else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
|
|
2463
|
+
else if (val === "null") val = null;
|
|
2464
|
+
else val = Number(val);
|
|
2465
|
+
obj[prop] = val;
|
|
2466
|
+
return obj;
|
|
2467
|
+
}, {});
|
|
2468
|
+
function useColors() {
|
|
2469
|
+
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
2470
|
+
}
|
|
2471
|
+
function formatArgs(args) {
|
|
2472
|
+
const { namespace: name, useColors: useColors$2 } = this;
|
|
2473
|
+
if (useColors$2) {
|
|
2474
|
+
const c = this.color;
|
|
2475
|
+
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
2476
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
2477
|
+
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
2478
|
+
args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
|
|
2479
|
+
} else args[0] = getDate() + name + " " + args[0];
|
|
2480
|
+
}
|
|
2481
|
+
function getDate() {
|
|
2482
|
+
if (exports.inspectOpts.hideDate) return "";
|
|
2483
|
+
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
2484
|
+
}
|
|
2485
|
+
function log(...args) {
|
|
2486
|
+
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
|
|
2487
|
+
}
|
|
2488
|
+
function save(namespaces) {
|
|
2489
|
+
if (namespaces) process.env.DEBUG = namespaces;
|
|
2490
|
+
else delete process.env.DEBUG;
|
|
2491
|
+
}
|
|
2492
|
+
function load() {
|
|
2493
|
+
return process.env.DEBUG;
|
|
2494
|
+
}
|
|
2495
|
+
function init(debug) {
|
|
2496
|
+
debug.inspectOpts = {};
|
|
2497
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
2498
|
+
for (let i = 0; i < keys.length; i++) debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
2499
|
+
}
|
|
2500
|
+
module.exports = require_common()(exports);
|
|
2501
|
+
const { formatters } = module.exports;
|
|
2502
|
+
formatters.o = function(v) {
|
|
2503
|
+
this.inspectOpts.colors = this.useColors;
|
|
2504
|
+
return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
2505
|
+
};
|
|
2506
|
+
formatters.O = function(v) {
|
|
2507
|
+
this.inspectOpts.colors = this.useColors;
|
|
2508
|
+
return util.inspect(v, this.inspectOpts);
|
|
2509
|
+
};
|
|
2510
|
+
});
|
|
2511
|
+
var require_src = __commonJSMin((exports, module) => {
|
|
2512
|
+
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) module.exports = require_browser();
|
|
2513
|
+
else module.exports = require_node();
|
|
2514
|
+
});
|
|
2515
|
+
var MessageProcessor = class {
|
|
2516
|
+
party;
|
|
2517
|
+
constructor(party) {
|
|
2518
|
+
this.party = party;
|
|
2519
|
+
}
|
|
2520
|
+
process(message, currentState, currentLocalAck) {
|
|
2521
|
+
const actions = [];
|
|
2522
|
+
let newState = currentState;
|
|
2523
|
+
let newLocalAck = currentLocalAck;
|
|
2524
|
+
if (message.from === this.party || message.seq <= currentLocalAck) return {
|
|
2525
|
+
actions,
|
|
2526
|
+
newState,
|
|
2527
|
+
newLocalAck
|
|
2528
|
+
};
|
|
2529
|
+
newLocalAck = message.seq;
|
|
2530
|
+
actions.push({
|
|
2531
|
+
type: "emit",
|
|
2532
|
+
event: message.type,
|
|
2533
|
+
payload: message.payload
|
|
2534
|
+
});
|
|
2535
|
+
switch (currentState) {
|
|
2536
|
+
case "opening":
|
|
2537
|
+
if (this.party === "handler" && message.type === "init") {
|
|
2538
|
+
newState = "open";
|
|
2539
|
+
const initPayload = message.payload;
|
|
2540
|
+
if (initPayload?.initial_payload !== void 0) actions.push({
|
|
2541
|
+
type: "emit",
|
|
2542
|
+
event: "data",
|
|
2543
|
+
payload: initPayload.initial_payload
|
|
2544
|
+
});
|
|
2545
|
+
actions.push({
|
|
2546
|
+
type: "emit",
|
|
2547
|
+
event: "open"
|
|
2548
|
+
});
|
|
2549
|
+
actions.push({
|
|
2550
|
+
type: "send",
|
|
2551
|
+
messageType: "ack",
|
|
2552
|
+
payload: null
|
|
2553
|
+
});
|
|
2554
|
+
} else if (this.party === "initiator" && message.type === "ack") {
|
|
2555
|
+
newState = "open";
|
|
2556
|
+
actions.push({
|
|
2557
|
+
type: "emit",
|
|
2558
|
+
event: "open"
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
break;
|
|
2562
|
+
case "open":
|
|
2563
|
+
if (message.type === "fin") {
|
|
2564
|
+
newState = "closing";
|
|
2565
|
+
actions.push({
|
|
2566
|
+
type: "send",
|
|
2567
|
+
messageType: "fin_ack",
|
|
2568
|
+
payload: null
|
|
2569
|
+
});
|
|
2570
|
+
newState = "closed";
|
|
2571
|
+
actions.push({
|
|
2572
|
+
type: "emit",
|
|
2573
|
+
event: "close"
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
break;
|
|
2577
|
+
case "closing":
|
|
2578
|
+
if (message.type === "fin_ack" || message.type === "fin") {
|
|
2579
|
+
newState = "closed";
|
|
2580
|
+
actions.push({
|
|
2581
|
+
type: "emit",
|
|
2582
|
+
event: "close"
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
break;
|
|
2586
|
+
case "closed": break;
|
|
2587
|
+
}
|
|
2588
|
+
return {
|
|
2589
|
+
actions,
|
|
2590
|
+
newState,
|
|
2591
|
+
newLocalAck
|
|
2592
|
+
};
|
|
2593
|
+
}
|
|
2594
|
+
};
|
|
2595
|
+
var import_src$1 = __toESM(require_src(), 1);
|
|
2596
|
+
var FsDuplex = class {
|
|
2597
|
+
party;
|
|
2598
|
+
json;
|
|
2599
|
+
readerLog;
|
|
2600
|
+
writerLog;
|
|
2601
|
+
processor;
|
|
2602
|
+
state = "opening";
|
|
2603
|
+
localSeq = 0;
|
|
2604
|
+
localAck = 0;
|
|
2605
|
+
log;
|
|
2606
|
+
onOpen = pureEvent();
|
|
2607
|
+
onClose = pureEvent();
|
|
2608
|
+
onError = pureEvent();
|
|
2609
|
+
onData = pureEvent();
|
|
2610
|
+
get currentState() {
|
|
2611
|
+
return this.state;
|
|
2612
|
+
}
|
|
2613
|
+
constructor(party, json, readerLog, writerLog) {
|
|
2614
|
+
this.party = party;
|
|
2615
|
+
this.json = json;
|
|
2616
|
+
this.readerLog = readerLog;
|
|
2617
|
+
this.writerLog = writerLog;
|
|
2618
|
+
this.processor = new MessageProcessor(party);
|
|
2619
|
+
this.log = (0, import_src$1.default)(`jixo:fs-duplex:${party}`);
|
|
2620
|
+
this.log("Created.");
|
|
2621
|
+
}
|
|
2622
|
+
async handleIncomingData() {
|
|
2623
|
+
const lines = await this.readerLog.readNewLines();
|
|
2624
|
+
for (const line of lines) {
|
|
2625
|
+
if (!line.trim()) continue;
|
|
2626
|
+
try {
|
|
2627
|
+
if (this.state === "closed") return;
|
|
2628
|
+
const message = this.json.parse(line);
|
|
2629
|
+
this.log("Received message: %o", message);
|
|
2630
|
+
const result = this.processor.process(message, this.state, this.localAck);
|
|
2631
|
+
for (const action of result.actions) this._executeAction(action);
|
|
2632
|
+
if (this.state !== result.newState) {
|
|
2633
|
+
this.log("State change: %s -> %s", this.state, result.newState);
|
|
2634
|
+
this.state = result.newState;
|
|
2635
|
+
}
|
|
2636
|
+
this.localAck = result.newLocalAck;
|
|
2637
|
+
} catch (error) {
|
|
2638
|
+
this.onError.emit(error instanceof Error ? error : new Error(String(error)));
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
sendData(payload) {
|
|
2643
|
+
this._sendMessage("data", payload);
|
|
2644
|
+
}
|
|
2645
|
+
init(initial_payload) {
|
|
2646
|
+
if (this.party !== "initiator") throw new Error("Only the initiator can start the connection with init().");
|
|
2647
|
+
this._sendMessage("init", { initial_payload });
|
|
2648
|
+
}
|
|
2649
|
+
close(reason = "done") {
|
|
2650
|
+
this.log("Close called with reason: %s. Current state: %s", reason, this.state);
|
|
2651
|
+
if (this.state === "closing" || this.state === "closed") return;
|
|
2652
|
+
this.state = "closing";
|
|
2653
|
+
this.log("State change: %s", this.state);
|
|
2654
|
+
this._sendMessage("fin", { reason });
|
|
2655
|
+
if (reason === "timeout" || reason === "error") {
|
|
2656
|
+
this.state = "closed";
|
|
2657
|
+
this.log("State change: %s (immediate due to %s)", this.state, reason);
|
|
2658
|
+
this.onClose.emit(reason);
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
_sendMessage(type, payload) {
|
|
2662
|
+
if (this.state === "closed") return;
|
|
2663
|
+
if (this.state === "closing" && type !== "fin" && type !== "fin_ack") return;
|
|
2664
|
+
this.localSeq++;
|
|
2665
|
+
const message = {
|
|
2666
|
+
from: this.party,
|
|
2667
|
+
seq: this.localSeq,
|
|
2668
|
+
ack: this.localAck,
|
|
2669
|
+
type,
|
|
2670
|
+
payload
|
|
2671
|
+
};
|
|
2672
|
+
this.log("Sending message: %o", message);
|
|
2673
|
+
const line = this.json.stringify(message);
|
|
2674
|
+
this.writerLog.append(line).catch((err) => this.onError.emit(err));
|
|
2675
|
+
}
|
|
2676
|
+
_executeAction(action) {
|
|
2677
|
+
this.log("Executing action: %o", action);
|
|
2678
|
+
if (action.type === "emit") switch (action.event) {
|
|
2679
|
+
case "open":
|
|
2680
|
+
this.onOpen.emit();
|
|
2681
|
+
break;
|
|
2682
|
+
case "close":
|
|
2683
|
+
this.state = "closed";
|
|
2684
|
+
this.log("State change: %s", this.state);
|
|
2685
|
+
this.onClose.emit("graceful");
|
|
2686
|
+
break;
|
|
2687
|
+
case "data":
|
|
2688
|
+
this.onData.emit(action.payload);
|
|
2689
|
+
break;
|
|
2690
|
+
}
|
|
2691
|
+
else if (action.type === "send") this._sendMessage(action.messageType, action.payload);
|
|
2692
|
+
}
|
|
2693
|
+
};
|
|
2694
|
+
var BrowserHeartbeatWriter = class {
|
|
2695
|
+
filename;
|
|
2696
|
+
helper;
|
|
2697
|
+
interval;
|
|
2698
|
+
timer = null;
|
|
2699
|
+
constructor(filename, helper, interval = 2e3) {
|
|
2700
|
+
this.filename = filename;
|
|
2701
|
+
this.helper = helper;
|
|
2702
|
+
this.interval = interval;
|
|
2703
|
+
}
|
|
2704
|
+
start() {
|
|
2705
|
+
if (this.timer) return;
|
|
2706
|
+
this._writeHeartbeat();
|
|
2707
|
+
this.timer = setInterval(() => this._writeHeartbeat(), this.interval);
|
|
2708
|
+
}
|
|
2709
|
+
stop() {
|
|
2710
|
+
if (this.timer) {
|
|
2711
|
+
clearInterval(this.timer);
|
|
2712
|
+
this.timer = null;
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
async _writeHeartbeat() {
|
|
2716
|
+
try {
|
|
2717
|
+
const handle = await this.helper.getFileHandle(this.filename);
|
|
2718
|
+
const writer = await handle.createWritable();
|
|
2719
|
+
await writer.write(String(Date.now()));
|
|
2720
|
+
await writer.close();
|
|
2721
|
+
} catch (error) {
|
|
2722
|
+
console.error("Failed to write heartbeat:", error);
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
};
|
|
2726
|
+
var import_src = __toESM(require_src(), 1);
|
|
2727
|
+
const nodeLog = (0, import_src.default)("jixo:fs-duplex:node-log");
|
|
2728
|
+
const browserLog = (0, import_src.default)("jixo:fs-duplex:browser-log");
|
|
2729
|
+
var BrowserAppendOnlyLog = class {
|
|
2730
|
+
filename;
|
|
2731
|
+
helper;
|
|
2732
|
+
readOffset = 0;
|
|
2733
|
+
lineBuffer = "";
|
|
2734
|
+
constructor(filename, helper) {
|
|
2735
|
+
this.filename = filename;
|
|
2736
|
+
this.helper = helper;
|
|
2737
|
+
browserLog("Constructed for file: %s", this.filename);
|
|
2738
|
+
}
|
|
2739
|
+
async start() {
|
|
2740
|
+
return Promise.resolve();
|
|
2741
|
+
}
|
|
2742
|
+
async stop() {
|
|
2743
|
+
this.readOffset = 0;
|
|
2744
|
+
this.lineBuffer = "";
|
|
2745
|
+
return Promise.resolve();
|
|
2746
|
+
}
|
|
2747
|
+
async append(line) {
|
|
2748
|
+
const handle = await this.helper.getFileHandle(this.filename);
|
|
2749
|
+
const file = await handle.getFile();
|
|
2750
|
+
const writer = await handle.createWritable({ keepExistingData: true });
|
|
2751
|
+
await writer.seek(file.size);
|
|
2752
|
+
await writer.write(line + "\n");
|
|
2753
|
+
await writer.close();
|
|
2754
|
+
}
|
|
2755
|
+
async readNewLines() {
|
|
2756
|
+
try {
|
|
2757
|
+
const handle = await this.helper.getFileHandle(this.filename);
|
|
2758
|
+
const file = await handle.getFile();
|
|
2759
|
+
const slice = file.slice(this.readOffset);
|
|
2760
|
+
const newContent = await slice.text();
|
|
2761
|
+
if (newContent.length === 0) return [];
|
|
2762
|
+
browserLog("Detected %d new chars in %s", newContent.length, this.filename);
|
|
2763
|
+
this.readOffset += slice.size;
|
|
2764
|
+
this.lineBuffer += newContent;
|
|
2765
|
+
const lines = this.lineBuffer.split("\n");
|
|
2766
|
+
if (this.lineBuffer.at(-1) !== "\n") this.lineBuffer = lines.pop() || "";
|
|
2767
|
+
else {
|
|
2768
|
+
this.lineBuffer = "";
|
|
2769
|
+
lines.pop();
|
|
2770
|
+
}
|
|
2771
|
+
return lines.filter((line) => line);
|
|
2772
|
+
} catch (e) {
|
|
2773
|
+
if (e.name === "NotFoundError") return [];
|
|
2774
|
+
browserLog("Error reading file %s: %O", this.filename, e);
|
|
2775
|
+
throw e;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
};
|
|
2779
|
+
var BrowserFsDuplex = class extends FsDuplex {
|
|
2780
|
+
heartbeatWriter;
|
|
2781
|
+
pollerId = null;
|
|
2782
|
+
isPolling = false;
|
|
2783
|
+
filepaths;
|
|
2784
|
+
helper;
|
|
2785
|
+
constructor(party, json, filenamePrefix, helper) {
|
|
2786
|
+
const prefixBasename = filenamePrefix.split("/").pop();
|
|
2787
|
+
const readFile = party === "handler" ? `${prefixBasename}.in.jsonl` : `${prefixBasename}.out.jsonl`;
|
|
2788
|
+
const writeFile = party === "handler" ? `${prefixBasename}.out.jsonl` : `${prefixBasename}.in.jsonl`;
|
|
2789
|
+
const heartbeatFile = `${prefixBasename}.heartbeat.json`;
|
|
2790
|
+
const readerLog = new BrowserAppendOnlyLog(readFile, helper);
|
|
2791
|
+
const writerLog = new BrowserAppendOnlyLog(writeFile, helper);
|
|
2792
|
+
super(party, json, readerLog, writerLog);
|
|
2793
|
+
this.helper = helper;
|
|
2794
|
+
this.heartbeatWriter = new BrowserHeartbeatWriter(heartbeatFile, helper);
|
|
2795
|
+
this.filepaths = {
|
|
2796
|
+
read: readFile,
|
|
2797
|
+
write: writeFile,
|
|
2798
|
+
heartbeat: heartbeatFile
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
async start() {
|
|
2802
|
+
if (this.pollerId) return;
|
|
2803
|
+
await this.readerLog.start();
|
|
2804
|
+
await this.writerLog.start();
|
|
2805
|
+
this.heartbeatWriter.start();
|
|
2806
|
+
this._poll();
|
|
2807
|
+
}
|
|
2808
|
+
async stop() {
|
|
2809
|
+
if (this.pollerId) {
|
|
2810
|
+
clearTimeout(this.pollerId);
|
|
2811
|
+
this.pollerId = null;
|
|
2812
|
+
}
|
|
2813
|
+
this.heartbeatWriter.stop();
|
|
2814
|
+
await this.readerLog.stop();
|
|
2815
|
+
await this.writerLog.stop();
|
|
2816
|
+
}
|
|
2817
|
+
close(reason = "done") {
|
|
2818
|
+
if (this.currentState === "closing" || this.currentState === "closed") return;
|
|
2819
|
+
this.heartbeatWriter.stop();
|
|
2820
|
+
super.close(reason);
|
|
2821
|
+
}
|
|
2822
|
+
async destroy() {
|
|
2823
|
+
this.log("Destroying...");
|
|
2824
|
+
await this.stop();
|
|
2825
|
+
await Promise.all([
|
|
2826
|
+
this.helper.removeFile(this.filepaths.read).catch(() => {}),
|
|
2827
|
+
this.helper.removeFile(this.filepaths.write).catch(() => {}),
|
|
2828
|
+
this.helper.removeFile(this.filepaths.heartbeat).catch(() => {})
|
|
2829
|
+
]);
|
|
2830
|
+
this.log("Destroyed.");
|
|
2831
|
+
}
|
|
2832
|
+
_poll() {
|
|
2833
|
+
if (this.currentState === "closed") return;
|
|
2834
|
+
this.pollerId = setTimeout(async () => {
|
|
2835
|
+
if (!this.pollerId || this.isPolling) return;
|
|
2836
|
+
this.isPolling = true;
|
|
2837
|
+
try {
|
|
2838
|
+
await this.handleIncomingData();
|
|
2839
|
+
} catch (e) {
|
|
2840
|
+
this.onError.emit(e instanceof Error ? e : new Error(String(e)));
|
|
2841
|
+
this.close("error");
|
|
2842
|
+
} finally {
|
|
2843
|
+
this.isPolling = false;
|
|
2844
|
+
if (this.currentState !== "closed") this._poll();
|
|
2845
|
+
}
|
|
2846
|
+
}, 200);
|
|
2847
|
+
}
|
|
2848
|
+
};
|
|
2849
|
+
var DoubleIndexedKV = class {
|
|
2850
|
+
constructor() {
|
|
2851
|
+
this.keyToValue = /* @__PURE__ */ new Map();
|
|
2852
|
+
this.valueToKey = /* @__PURE__ */ new Map();
|
|
2853
|
+
}
|
|
2854
|
+
set(key, value) {
|
|
2855
|
+
this.keyToValue.set(key, value);
|
|
2856
|
+
this.valueToKey.set(value, key);
|
|
2857
|
+
}
|
|
2858
|
+
getByKey(key) {
|
|
2859
|
+
return this.keyToValue.get(key);
|
|
2860
|
+
}
|
|
2861
|
+
getByValue(value) {
|
|
2862
|
+
return this.valueToKey.get(value);
|
|
2863
|
+
}
|
|
2864
|
+
clear() {
|
|
2865
|
+
this.keyToValue.clear();
|
|
2866
|
+
this.valueToKey.clear();
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
var Registry = class {
|
|
2870
|
+
constructor(generateIdentifier) {
|
|
2871
|
+
this.generateIdentifier = generateIdentifier;
|
|
2872
|
+
this.kv = new DoubleIndexedKV();
|
|
2873
|
+
}
|
|
2874
|
+
register(value, identifier) {
|
|
2875
|
+
if (this.kv.getByValue(value)) return;
|
|
2876
|
+
if (!identifier) identifier = this.generateIdentifier(value);
|
|
2877
|
+
this.kv.set(identifier, value);
|
|
2878
|
+
}
|
|
2879
|
+
clear() {
|
|
2880
|
+
this.kv.clear();
|
|
2881
|
+
}
|
|
2882
|
+
getIdentifier(value) {
|
|
2883
|
+
return this.kv.getByValue(value);
|
|
2884
|
+
}
|
|
2885
|
+
getValue(identifier) {
|
|
2886
|
+
return this.kv.getByKey(identifier);
|
|
2887
|
+
}
|
|
2888
|
+
};
|
|
2889
|
+
var ClassRegistry = class extends Registry {
|
|
2890
|
+
constructor() {
|
|
2891
|
+
super((c) => c.name);
|
|
2892
|
+
this.classToAllowedProps = /* @__PURE__ */ new Map();
|
|
2893
|
+
}
|
|
2894
|
+
register(value, options) {
|
|
2895
|
+
if (typeof options === "object") {
|
|
2896
|
+
if (options.allowProps) this.classToAllowedProps.set(value, options.allowProps);
|
|
2897
|
+
super.register(value, options.identifier);
|
|
2898
|
+
} else super.register(value, options);
|
|
2899
|
+
}
|
|
2900
|
+
getAllowedProps(value) {
|
|
2901
|
+
return this.classToAllowedProps.get(value);
|
|
2902
|
+
}
|
|
2903
|
+
};
|
|
2904
|
+
function valuesOfObj(record$1) {
|
|
2905
|
+
if ("values" in Object) return Object.values(record$1);
|
|
2906
|
+
const values = [];
|
|
2907
|
+
for (const key in record$1) if (record$1.hasOwnProperty(key)) values.push(record$1[key]);
|
|
2908
|
+
return values;
|
|
2909
|
+
}
|
|
2910
|
+
function find(record$1, predicate) {
|
|
2911
|
+
const values = valuesOfObj(record$1);
|
|
2912
|
+
if ("find" in values) return values.find(predicate);
|
|
2913
|
+
const valuesNotNever = values;
|
|
2914
|
+
for (let i = 0; i < valuesNotNever.length; i++) {
|
|
2915
|
+
const value = valuesNotNever[i];
|
|
2916
|
+
if (predicate(value)) return value;
|
|
2917
|
+
}
|
|
2918
|
+
return void 0;
|
|
2919
|
+
}
|
|
2920
|
+
function forEach(record$1, run) {
|
|
2921
|
+
Object.entries(record$1).forEach(([key, value]) => run(value, key));
|
|
2922
|
+
}
|
|
2923
|
+
function includes(arr, value) {
|
|
2924
|
+
return arr.indexOf(value) !== -1;
|
|
2925
|
+
}
|
|
2926
|
+
function findArr(record$1, predicate) {
|
|
2927
|
+
for (let i = 0; i < record$1.length; i++) {
|
|
2928
|
+
const value = record$1[i];
|
|
2929
|
+
if (predicate(value)) return value;
|
|
2930
|
+
}
|
|
2931
|
+
return void 0;
|
|
2932
|
+
}
|
|
2933
|
+
var CustomTransformerRegistry = class {
|
|
2934
|
+
constructor() {
|
|
2935
|
+
this.transfomers = {};
|
|
2936
|
+
}
|
|
2937
|
+
register(transformer) {
|
|
2938
|
+
this.transfomers[transformer.name] = transformer;
|
|
2939
|
+
}
|
|
2940
|
+
findApplicable(v) {
|
|
2941
|
+
return find(this.transfomers, (transformer) => transformer.isApplicable(v));
|
|
2942
|
+
}
|
|
2943
|
+
findByName(name) {
|
|
2944
|
+
return this.transfomers[name];
|
|
2945
|
+
}
|
|
2946
|
+
};
|
|
2947
|
+
const getType$1 = (payload) => Object.prototype.toString.call(payload).slice(8, -1);
|
|
2948
|
+
const isUndefined$1 = (payload) => typeof payload === "undefined";
|
|
2949
|
+
const isNull$1 = (payload) => payload === null;
|
|
2950
|
+
const isPlainObject$1 = (payload) => {
|
|
2951
|
+
if (typeof payload !== "object" || payload === null) return false;
|
|
2952
|
+
if (payload === Object.prototype) return false;
|
|
2953
|
+
if (Object.getPrototypeOf(payload) === null) return true;
|
|
2954
|
+
return Object.getPrototypeOf(payload) === Object.prototype;
|
|
2955
|
+
};
|
|
2956
|
+
const isEmptyObject = (payload) => isPlainObject$1(payload) && Object.keys(payload).length === 0;
|
|
2957
|
+
const isArray$1 = (payload) => Array.isArray(payload);
|
|
2958
|
+
const isString = (payload) => typeof payload === "string";
|
|
2959
|
+
const isNumber = (payload) => typeof payload === "number" && !isNaN(payload);
|
|
2960
|
+
const isBoolean = (payload) => typeof payload === "boolean";
|
|
2961
|
+
const isRegExp = (payload) => payload instanceof RegExp;
|
|
2962
|
+
const isMap = (payload) => payload instanceof Map;
|
|
2963
|
+
const isSet = (payload) => payload instanceof Set;
|
|
2964
|
+
const isSymbol = (payload) => getType$1(payload) === "Symbol";
|
|
2965
|
+
const isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
|
|
2966
|
+
const isError = (payload) => payload instanceof Error;
|
|
2967
|
+
const isNaNValue = (payload) => typeof payload === "number" && isNaN(payload);
|
|
2968
|
+
const isPrimitive = (payload) => isBoolean(payload) || isNull$1(payload) || isUndefined$1(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
|
2969
|
+
const isBigint = (payload) => typeof payload === "bigint";
|
|
2970
|
+
const isInfinite = (payload) => payload === Infinity || payload === -Infinity;
|
|
2971
|
+
const isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
|
|
2972
|
+
const isURL = (payload) => payload instanceof URL;
|
|
2973
|
+
const escapeKey = (key) => key.replace(/\./g, "\\.");
|
|
2974
|
+
const stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
|
|
2975
|
+
const parsePath = (string$2) => {
|
|
2976
|
+
const result = [];
|
|
2977
|
+
let segment = "";
|
|
2978
|
+
for (let i = 0; i < string$2.length; i++) {
|
|
2979
|
+
let char = string$2.charAt(i);
|
|
2980
|
+
const isEscapedDot = char === "\\" && string$2.charAt(i + 1) === ".";
|
|
2981
|
+
if (isEscapedDot) {
|
|
2982
|
+
segment += ".";
|
|
2983
|
+
i++;
|
|
2984
|
+
continue;
|
|
2985
|
+
}
|
|
2986
|
+
const isEndOfSegment = char === ".";
|
|
2987
|
+
if (isEndOfSegment) {
|
|
2988
|
+
result.push(segment);
|
|
2989
|
+
segment = "";
|
|
2990
|
+
continue;
|
|
2991
|
+
}
|
|
2992
|
+
segment += char;
|
|
2993
|
+
}
|
|
2994
|
+
const lastSegment = segment;
|
|
2995
|
+
result.push(lastSegment);
|
|
2996
|
+
return result;
|
|
2997
|
+
};
|
|
2998
|
+
function simpleTransformation(isApplicable, annotation, transform, untransform) {
|
|
2999
|
+
return {
|
|
3000
|
+
isApplicable,
|
|
3001
|
+
annotation,
|
|
3002
|
+
transform,
|
|
3003
|
+
untransform
|
|
3004
|
+
};
|
|
3005
|
+
}
|
|
3006
|
+
const simpleRules = [
|
|
3007
|
+
simpleTransformation(isUndefined$1, "undefined", () => null, () => void 0),
|
|
3008
|
+
simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => {
|
|
3009
|
+
if (typeof BigInt !== "undefined") return BigInt(v);
|
|
3010
|
+
console.error("Please add a BigInt polyfill.");
|
|
3011
|
+
return v;
|
|
3012
|
+
}),
|
|
3013
|
+
simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
|
|
3014
|
+
simpleTransformation(isError, "Error", (v, superJson) => {
|
|
3015
|
+
const baseError = {
|
|
3016
|
+
name: v.name,
|
|
3017
|
+
message: v.message
|
|
3018
|
+
};
|
|
3019
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
3020
|
+
baseError[prop] = v[prop];
|
|
3021
|
+
});
|
|
3022
|
+
return baseError;
|
|
3023
|
+
}, (v, superJson) => {
|
|
3024
|
+
const e = new Error(v.message);
|
|
3025
|
+
e.name = v.name;
|
|
3026
|
+
e.stack = v.stack;
|
|
3027
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
3028
|
+
e[prop] = v[prop];
|
|
3029
|
+
});
|
|
3030
|
+
return e;
|
|
3031
|
+
}),
|
|
3032
|
+
simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => {
|
|
3033
|
+
const body = regex.slice(1, regex.lastIndexOf("/"));
|
|
3034
|
+
const flags = regex.slice(regex.lastIndexOf("/") + 1);
|
|
3035
|
+
return new RegExp(body, flags);
|
|
3036
|
+
}),
|
|
3037
|
+
simpleTransformation(isSet, "set", (v) => [...v.values()], (v) => new Set(v)),
|
|
3038
|
+
simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
|
|
3039
|
+
simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => {
|
|
3040
|
+
if (isNaNValue(v)) return "NaN";
|
|
3041
|
+
if (v > 0) return "Infinity";
|
|
3042
|
+
else return "-Infinity";
|
|
3043
|
+
}, Number),
|
|
3044
|
+
simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
|
|
3045
|
+
return "-0";
|
|
3046
|
+
}, Number),
|
|
3047
|
+
simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v))
|
|
3048
|
+
];
|
|
3049
|
+
function compositeTransformation(isApplicable, annotation, transform, untransform) {
|
|
3050
|
+
return {
|
|
3051
|
+
isApplicable,
|
|
3052
|
+
annotation,
|
|
3053
|
+
transform,
|
|
3054
|
+
untransform
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
const symbolRule = compositeTransformation((s$1, superJson) => {
|
|
3058
|
+
if (isSymbol(s$1)) {
|
|
3059
|
+
const isRegistered = !!superJson.symbolRegistry.getIdentifier(s$1);
|
|
3060
|
+
return isRegistered;
|
|
3061
|
+
}
|
|
3062
|
+
return false;
|
|
3063
|
+
}, (s$1, superJson) => {
|
|
3064
|
+
const identifier = superJson.symbolRegistry.getIdentifier(s$1);
|
|
3065
|
+
return ["symbol", identifier];
|
|
3066
|
+
}, (v) => v.description, (_, a, superJson) => {
|
|
3067
|
+
const value = superJson.symbolRegistry.getValue(a[1]);
|
|
3068
|
+
if (!value) throw new Error("Trying to deserialize unknown symbol");
|
|
3069
|
+
return value;
|
|
3070
|
+
});
|
|
3071
|
+
const constructorToName = [
|
|
3072
|
+
Int8Array,
|
|
3073
|
+
Uint8Array,
|
|
3074
|
+
Int16Array,
|
|
3075
|
+
Uint16Array,
|
|
3076
|
+
Int32Array,
|
|
3077
|
+
Uint32Array,
|
|
3078
|
+
Float32Array,
|
|
3079
|
+
Float64Array,
|
|
3080
|
+
Uint8ClampedArray
|
|
3081
|
+
].reduce((obj, ctor) => {
|
|
3082
|
+
obj[ctor.name] = ctor;
|
|
3083
|
+
return obj;
|
|
3084
|
+
}, {});
|
|
3085
|
+
const typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a) => {
|
|
3086
|
+
const ctor = constructorToName[a[1]];
|
|
3087
|
+
if (!ctor) throw new Error("Trying to deserialize unknown typed array");
|
|
3088
|
+
return new ctor(v);
|
|
3089
|
+
});
|
|
3090
|
+
function isInstanceOfRegisteredClass(potentialClass, superJson) {
|
|
3091
|
+
if (potentialClass?.constructor) {
|
|
3092
|
+
const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
|
|
3093
|
+
return isRegistered;
|
|
3094
|
+
}
|
|
3095
|
+
return false;
|
|
3096
|
+
}
|
|
3097
|
+
const classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
|
|
3098
|
+
const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
|
|
3099
|
+
return ["class", identifier];
|
|
3100
|
+
}, (clazz, superJson) => {
|
|
3101
|
+
const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
|
|
3102
|
+
if (!allowedProps) return { ...clazz };
|
|
3103
|
+
const result = {};
|
|
3104
|
+
allowedProps.forEach((prop) => {
|
|
3105
|
+
result[prop] = clazz[prop];
|
|
3106
|
+
});
|
|
3107
|
+
return result;
|
|
3108
|
+
}, (v, a, superJson) => {
|
|
3109
|
+
const clazz = superJson.classRegistry.getValue(a[1]);
|
|
3110
|
+
if (!clazz) throw new Error(`Trying to deserialize unknown class '${a[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
|
|
3111
|
+
return Object.assign(Object.create(clazz.prototype), v);
|
|
3112
|
+
});
|
|
3113
|
+
const customRule = compositeTransformation((value, superJson) => {
|
|
3114
|
+
return !!superJson.customTransformerRegistry.findApplicable(value);
|
|
3115
|
+
}, (value, superJson) => {
|
|
3116
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
3117
|
+
return ["custom", transformer.name];
|
|
3118
|
+
}, (value, superJson) => {
|
|
3119
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
3120
|
+
return transformer.serialize(value);
|
|
3121
|
+
}, (v, a, superJson) => {
|
|
3122
|
+
const transformer = superJson.customTransformerRegistry.findByName(a[1]);
|
|
3123
|
+
if (!transformer) throw new Error("Trying to deserialize unknown custom value");
|
|
3124
|
+
return transformer.deserialize(v);
|
|
3125
|
+
});
|
|
3126
|
+
const compositeRules = [
|
|
3127
|
+
classRule,
|
|
3128
|
+
symbolRule,
|
|
3129
|
+
customRule,
|
|
3130
|
+
typedArrayRule
|
|
3131
|
+
];
|
|
3132
|
+
const transformValue = (value, superJson) => {
|
|
3133
|
+
const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
|
|
3134
|
+
if (applicableCompositeRule) return {
|
|
3135
|
+
value: applicableCompositeRule.transform(value, superJson),
|
|
3136
|
+
type: applicableCompositeRule.annotation(value, superJson)
|
|
3137
|
+
};
|
|
3138
|
+
const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
|
|
3139
|
+
if (applicableSimpleRule) return {
|
|
3140
|
+
value: applicableSimpleRule.transform(value, superJson),
|
|
3141
|
+
type: applicableSimpleRule.annotation
|
|
3142
|
+
};
|
|
3143
|
+
return void 0;
|
|
3144
|
+
};
|
|
3145
|
+
const simpleRulesByAnnotation = {};
|
|
3146
|
+
simpleRules.forEach((rule) => {
|
|
3147
|
+
simpleRulesByAnnotation[rule.annotation] = rule;
|
|
3148
|
+
});
|
|
3149
|
+
const untransformValue = (json, type, superJson) => {
|
|
3150
|
+
if (isArray$1(type)) switch (type[0]) {
|
|
3151
|
+
case "symbol": return symbolRule.untransform(json, type, superJson);
|
|
3152
|
+
case "class": return classRule.untransform(json, type, superJson);
|
|
3153
|
+
case "custom": return customRule.untransform(json, type, superJson);
|
|
3154
|
+
case "typed-array": return typedArrayRule.untransform(json, type, superJson);
|
|
3155
|
+
default: throw new Error("Unknown transformation: " + type);
|
|
3156
|
+
}
|
|
3157
|
+
else {
|
|
3158
|
+
const transformation = simpleRulesByAnnotation[type];
|
|
3159
|
+
if (!transformation) throw new Error("Unknown transformation: " + type);
|
|
3160
|
+
return transformation.untransform(json, superJson);
|
|
3161
|
+
}
|
|
3162
|
+
};
|
|
3163
|
+
const getNthKey = (value, n) => {
|
|
3164
|
+
if (n > value.size) throw new Error("index out of bounds");
|
|
3165
|
+
const keys = value.keys();
|
|
3166
|
+
while (n > 0) {
|
|
3167
|
+
keys.next();
|
|
3168
|
+
n--;
|
|
3169
|
+
}
|
|
3170
|
+
return keys.next().value;
|
|
3171
|
+
};
|
|
3172
|
+
function validatePath(path) {
|
|
3173
|
+
if (includes(path, "__proto__")) throw new Error("__proto__ is not allowed as a property");
|
|
3174
|
+
if (includes(path, "prototype")) throw new Error("prototype is not allowed as a property");
|
|
3175
|
+
if (includes(path, "constructor")) throw new Error("constructor is not allowed as a property");
|
|
3176
|
+
}
|
|
3177
|
+
const getDeep = (object$1, path) => {
|
|
3178
|
+
validatePath(path);
|
|
3179
|
+
for (let i = 0; i < path.length; i++) {
|
|
3180
|
+
const key = path[i];
|
|
3181
|
+
if (isSet(object$1)) object$1 = getNthKey(object$1, +key);
|
|
3182
|
+
else if (isMap(object$1)) {
|
|
3183
|
+
const row = +key;
|
|
3184
|
+
const type = +path[++i] === 0 ? "key" : "value";
|
|
3185
|
+
const keyOfRow = getNthKey(object$1, row);
|
|
3186
|
+
switch (type) {
|
|
3187
|
+
case "key":
|
|
3188
|
+
object$1 = keyOfRow;
|
|
3189
|
+
break;
|
|
3190
|
+
case "value":
|
|
3191
|
+
object$1 = object$1.get(keyOfRow);
|
|
3192
|
+
break;
|
|
3193
|
+
}
|
|
3194
|
+
} else object$1 = object$1[key];
|
|
3195
|
+
}
|
|
3196
|
+
return object$1;
|
|
3197
|
+
};
|
|
3198
|
+
const setDeep = (object$1, path, mapper) => {
|
|
3199
|
+
validatePath(path);
|
|
3200
|
+
if (path.length === 0) return mapper(object$1);
|
|
3201
|
+
let parent = object$1;
|
|
3202
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
3203
|
+
const key = path[i];
|
|
3204
|
+
if (isArray$1(parent)) {
|
|
3205
|
+
const index = +key;
|
|
3206
|
+
parent = parent[index];
|
|
3207
|
+
} else if (isPlainObject$1(parent)) parent = parent[key];
|
|
3208
|
+
else if (isSet(parent)) {
|
|
3209
|
+
const row = +key;
|
|
3210
|
+
parent = getNthKey(parent, row);
|
|
3211
|
+
} else if (isMap(parent)) {
|
|
3212
|
+
const isEnd = i === path.length - 2;
|
|
3213
|
+
if (isEnd) break;
|
|
3214
|
+
const row = +key;
|
|
3215
|
+
const type = +path[++i] === 0 ? "key" : "value";
|
|
3216
|
+
const keyOfRow = getNthKey(parent, row);
|
|
3217
|
+
switch (type) {
|
|
3218
|
+
case "key":
|
|
3219
|
+
parent = keyOfRow;
|
|
3220
|
+
break;
|
|
3221
|
+
case "value":
|
|
3222
|
+
parent = parent.get(keyOfRow);
|
|
3223
|
+
break;
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
const lastKey = path[path.length - 1];
|
|
3228
|
+
if (isArray$1(parent)) parent[+lastKey] = mapper(parent[+lastKey]);
|
|
3229
|
+
else if (isPlainObject$1(parent)) parent[lastKey] = mapper(parent[lastKey]);
|
|
3230
|
+
if (isSet(parent)) {
|
|
3231
|
+
const oldValue = getNthKey(parent, +lastKey);
|
|
3232
|
+
const newValue = mapper(oldValue);
|
|
3233
|
+
if (oldValue !== newValue) {
|
|
3234
|
+
parent.delete(oldValue);
|
|
3235
|
+
parent.add(newValue);
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
if (isMap(parent)) {
|
|
3239
|
+
const row = +path[path.length - 2];
|
|
3240
|
+
const keyToRow = getNthKey(parent, row);
|
|
3241
|
+
const type = +lastKey === 0 ? "key" : "value";
|
|
3242
|
+
switch (type) {
|
|
3243
|
+
case "key": {
|
|
3244
|
+
const newKey = mapper(keyToRow);
|
|
3245
|
+
parent.set(newKey, parent.get(keyToRow));
|
|
3246
|
+
if (newKey !== keyToRow) parent.delete(keyToRow);
|
|
3247
|
+
break;
|
|
3248
|
+
}
|
|
3249
|
+
case "value": {
|
|
3250
|
+
parent.set(keyToRow, mapper(parent.get(keyToRow)));
|
|
3251
|
+
break;
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
return object$1;
|
|
3256
|
+
};
|
|
3257
|
+
function traverse(tree, walker$1, origin = []) {
|
|
3258
|
+
if (!tree) return;
|
|
3259
|
+
if (!isArray$1(tree)) {
|
|
3260
|
+
forEach(tree, (subtree, key) => traverse(subtree, walker$1, [...origin, ...parsePath(key)]));
|
|
3261
|
+
return;
|
|
3262
|
+
}
|
|
3263
|
+
const [nodeValue, children] = tree;
|
|
3264
|
+
if (children) forEach(children, (child, key) => {
|
|
3265
|
+
traverse(child, walker$1, [...origin, ...parsePath(key)]);
|
|
3266
|
+
});
|
|
3267
|
+
walker$1(nodeValue, origin);
|
|
3268
|
+
}
|
|
3269
|
+
function applyValueAnnotations(plain, annotations, superJson) {
|
|
3270
|
+
traverse(annotations, (type, path) => {
|
|
3271
|
+
plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
|
|
3272
|
+
});
|
|
3273
|
+
return plain;
|
|
3274
|
+
}
|
|
3275
|
+
function applyReferentialEqualityAnnotations(plain, annotations) {
|
|
3276
|
+
function apply(identicalPaths, path) {
|
|
3277
|
+
const object$1 = getDeep(plain, parsePath(path));
|
|
3278
|
+
identicalPaths.map(parsePath).forEach((identicalObjectPath) => {
|
|
3279
|
+
plain = setDeep(plain, identicalObjectPath, () => object$1);
|
|
3280
|
+
});
|
|
3281
|
+
}
|
|
3282
|
+
if (isArray$1(annotations)) {
|
|
3283
|
+
const [root, other] = annotations;
|
|
3284
|
+
root.forEach((identicalPath) => {
|
|
3285
|
+
plain = setDeep(plain, parsePath(identicalPath), () => plain);
|
|
3286
|
+
});
|
|
3287
|
+
if (other) forEach(other, apply);
|
|
3288
|
+
} else forEach(annotations, apply);
|
|
3289
|
+
return plain;
|
|
3290
|
+
}
|
|
3291
|
+
const isDeep = (object$1, superJson) => isPlainObject$1(object$1) || isArray$1(object$1) || isMap(object$1) || isSet(object$1) || isInstanceOfRegisteredClass(object$1, superJson);
|
|
3292
|
+
function addIdentity(object$1, path, identities) {
|
|
3293
|
+
const existingSet = identities.get(object$1);
|
|
3294
|
+
if (existingSet) existingSet.push(path);
|
|
3295
|
+
else identities.set(object$1, [path]);
|
|
3296
|
+
}
|
|
3297
|
+
function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
3298
|
+
const result = {};
|
|
3299
|
+
let rootEqualityPaths = void 0;
|
|
3300
|
+
identitites.forEach((paths) => {
|
|
3301
|
+
if (paths.length <= 1) return;
|
|
3302
|
+
if (!dedupe) paths = paths.map((path) => path.map(String)).sort((a, b) => a.length - b.length);
|
|
3303
|
+
const [representativePath, ...identicalPaths] = paths;
|
|
3304
|
+
if (representativePath.length === 0) rootEqualityPaths = identicalPaths.map(stringifyPath);
|
|
3305
|
+
else result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
|
|
3306
|
+
});
|
|
3307
|
+
if (rootEqualityPaths) if (isEmptyObject(result)) return [rootEqualityPaths];
|
|
3308
|
+
else return [rootEqualityPaths, result];
|
|
3309
|
+
else return isEmptyObject(result) ? void 0 : result;
|
|
3310
|
+
}
|
|
3311
|
+
const walker = (object$1, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
3312
|
+
const primitive = isPrimitive(object$1);
|
|
3313
|
+
if (!primitive) {
|
|
3314
|
+
addIdentity(object$1, path, identities);
|
|
3315
|
+
const seen = seenObjects.get(object$1);
|
|
3316
|
+
if (seen) return dedupe ? { transformedValue: null } : seen;
|
|
3317
|
+
}
|
|
3318
|
+
if (!isDeep(object$1, superJson)) {
|
|
3319
|
+
const transformed$1 = transformValue(object$1, superJson);
|
|
3320
|
+
const result$1 = transformed$1 ? {
|
|
3321
|
+
transformedValue: transformed$1.value,
|
|
3322
|
+
annotations: [transformed$1.type]
|
|
3323
|
+
} : { transformedValue: object$1 };
|
|
3324
|
+
if (!primitive) seenObjects.set(object$1, result$1);
|
|
3325
|
+
return result$1;
|
|
3326
|
+
}
|
|
3327
|
+
if (includes(objectsInThisPath, object$1)) return { transformedValue: null };
|
|
3328
|
+
const transformationResult = transformValue(object$1, superJson);
|
|
3329
|
+
const transformed = transformationResult?.value ?? object$1;
|
|
3330
|
+
const transformedValue = isArray$1(transformed) ? [] : {};
|
|
3331
|
+
const innerAnnotations = {};
|
|
3332
|
+
forEach(transformed, (value, index) => {
|
|
3333
|
+
if (index === "__proto__" || index === "constructor" || index === "prototype") throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
3334
|
+
const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object$1], seenObjects);
|
|
3335
|
+
transformedValue[index] = recursiveResult.transformedValue;
|
|
3336
|
+
if (isArray$1(recursiveResult.annotations)) innerAnnotations[index] = recursiveResult.annotations;
|
|
3337
|
+
else if (isPlainObject$1(recursiveResult.annotations)) forEach(recursiveResult.annotations, (tree, key) => {
|
|
3338
|
+
innerAnnotations[escapeKey(index) + "." + key] = tree;
|
|
3339
|
+
});
|
|
3340
|
+
});
|
|
3341
|
+
const result = isEmptyObject(innerAnnotations) ? {
|
|
3342
|
+
transformedValue,
|
|
3343
|
+
annotations: !!transformationResult ? [transformationResult.type] : void 0
|
|
3344
|
+
} : {
|
|
3345
|
+
transformedValue,
|
|
3346
|
+
annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
|
|
3347
|
+
};
|
|
3348
|
+
if (!primitive) seenObjects.set(object$1, result);
|
|
3349
|
+
return result;
|
|
3350
|
+
};
|
|
3351
|
+
function getType(payload) {
|
|
3352
|
+
return Object.prototype.toString.call(payload).slice(8, -1);
|
|
3353
|
+
}
|
|
3354
|
+
function isArray(payload) {
|
|
3355
|
+
return getType(payload) === "Array";
|
|
3356
|
+
}
|
|
3357
|
+
function isPlainObject(payload) {
|
|
3358
|
+
if (getType(payload) !== "Object") return false;
|
|
3359
|
+
const prototype = Object.getPrototypeOf(payload);
|
|
3360
|
+
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
|
3361
|
+
}
|
|
3362
|
+
function isNull(payload) {
|
|
3363
|
+
return getType(payload) === "Null";
|
|
3364
|
+
}
|
|
3365
|
+
function isOneOf(a, b, c, d$1, e) {
|
|
3366
|
+
return (value) => a(value) || b(value) || !!c && c(value) || !!d$1 && d$1(value) || !!e && e(value);
|
|
3367
|
+
}
|
|
3368
|
+
function isUndefined(payload) {
|
|
3369
|
+
return getType(payload) === "Undefined";
|
|
3370
|
+
}
|
|
3371
|
+
const isNullOrUndefined = isOneOf(isNull, isUndefined);
|
|
3372
|
+
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
|
3373
|
+
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
|
|
3374
|
+
if (propType === "enumerable") carry[key] = newVal;
|
|
3375
|
+
if (includeNonenumerable && propType === "nonenumerable") Object.defineProperty(carry, key, {
|
|
3376
|
+
value: newVal,
|
|
3377
|
+
enumerable: false,
|
|
3378
|
+
writable: true,
|
|
3379
|
+
configurable: true
|
|
3380
|
+
});
|
|
3381
|
+
}
|
|
3382
|
+
function copy(target, options = {}) {
|
|
3383
|
+
if (isArray(target)) return target.map((item) => copy(item, options));
|
|
3384
|
+
if (!isPlainObject(target)) return target;
|
|
3385
|
+
const props = Object.getOwnPropertyNames(target);
|
|
3386
|
+
const symbols = Object.getOwnPropertySymbols(target);
|
|
3387
|
+
return [...props, ...symbols].reduce((carry, key) => {
|
|
3388
|
+
if (isArray(options.props) && !options.props.includes(key)) return carry;
|
|
3389
|
+
const val = target[key];
|
|
3390
|
+
const newVal = copy(val, options);
|
|
3391
|
+
assignProp(carry, key, newVal, target, options.nonenumerable);
|
|
3392
|
+
return carry;
|
|
3393
|
+
}, {});
|
|
3394
|
+
}
|
|
3395
|
+
var SuperJSON = class {
|
|
3396
|
+
constructor({ dedupe = false } = {}) {
|
|
3397
|
+
this.classRegistry = new ClassRegistry();
|
|
3398
|
+
this.symbolRegistry = new Registry((s$1) => s$1.description ?? "");
|
|
3399
|
+
this.customTransformerRegistry = new CustomTransformerRegistry();
|
|
3400
|
+
this.allowedErrorProps = [];
|
|
3401
|
+
this.dedupe = dedupe;
|
|
3402
|
+
}
|
|
3403
|
+
serialize(object$1) {
|
|
3404
|
+
const identities = /* @__PURE__ */ new Map();
|
|
3405
|
+
const output = walker(object$1, identities, this, this.dedupe);
|
|
3406
|
+
const res = { json: output.transformedValue };
|
|
3407
|
+
if (output.annotations) res.meta = {
|
|
3408
|
+
...res.meta,
|
|
3409
|
+
values: output.annotations
|
|
3410
|
+
};
|
|
3411
|
+
const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
|
|
3412
|
+
if (equalityAnnotations) res.meta = {
|
|
3413
|
+
...res.meta,
|
|
3414
|
+
referentialEqualities: equalityAnnotations
|
|
3415
|
+
};
|
|
3416
|
+
return res;
|
|
3417
|
+
}
|
|
3418
|
+
deserialize(payload) {
|
|
3419
|
+
const { json, meta } = payload;
|
|
3420
|
+
let result = copy(json);
|
|
3421
|
+
if (meta?.values) result = applyValueAnnotations(result, meta.values, this);
|
|
3422
|
+
if (meta?.referentialEqualities) result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities);
|
|
3423
|
+
return result;
|
|
3424
|
+
}
|
|
3425
|
+
stringify(object$1) {
|
|
3426
|
+
return JSON.stringify(this.serialize(object$1));
|
|
3427
|
+
}
|
|
3428
|
+
parse(string$2) {
|
|
3429
|
+
return this.deserialize(JSON.parse(string$2));
|
|
3430
|
+
}
|
|
3431
|
+
registerClass(v, options) {
|
|
3432
|
+
this.classRegistry.register(v, options);
|
|
3433
|
+
}
|
|
3434
|
+
registerSymbol(v, identifier) {
|
|
3435
|
+
this.symbolRegistry.register(v, identifier);
|
|
3436
|
+
}
|
|
3437
|
+
registerCustom(transformer, name) {
|
|
3438
|
+
this.customTransformerRegistry.register({
|
|
3439
|
+
name,
|
|
3440
|
+
...transformer
|
|
3441
|
+
});
|
|
3442
|
+
}
|
|
3443
|
+
allowErrorProps(...props) {
|
|
3444
|
+
this.allowedErrorProps.push(...props);
|
|
3445
|
+
}
|
|
3446
|
+
};
|
|
3447
|
+
SuperJSON.defaultInstance = new SuperJSON();
|
|
3448
|
+
SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
|
|
3449
|
+
SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
|
|
3450
|
+
SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
|
|
3451
|
+
SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
|
|
3452
|
+
SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
|
|
3453
|
+
SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
|
|
3454
|
+
SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
|
|
3455
|
+
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
|
3456
|
+
const serialize = SuperJSON.serialize;
|
|
3457
|
+
const deserialize = SuperJSON.deserialize;
|
|
3458
|
+
const stringify = SuperJSON.stringify;
|
|
3459
|
+
const parse = SuperJSON.parse;
|
|
3460
|
+
const registerClass = SuperJSON.registerClass;
|
|
3461
|
+
const registerCustom = SuperJSON.registerCustom;
|
|
3462
|
+
const registerSymbol = SuperJSON.registerSymbol;
|
|
3463
|
+
const allowErrorProps = SuperJSON.allowErrorProps;
|
|
3464
|
+
const superjsonInstance = new SuperJSON();
|
|
3465
|
+
superjsonInstance.registerCustom({
|
|
3466
|
+
isApplicable: typeof SharedArrayBuffer !== "undefined" ? (v) => v instanceof ArrayBuffer || v instanceof SharedArrayBuffer : (v) => v instanceof ArrayBuffer,
|
|
3467
|
+
serialize: (v) => binary_to_base64_string(new Uint8Array(v)),
|
|
3468
|
+
deserialize: (v) => str_to_base64_binary(v).buffer
|
|
3469
|
+
}, "ArrayBuffer");
|
|
3470
|
+
superjsonInstance.registerCustom({
|
|
3471
|
+
isApplicable: (v) => v instanceof DataView,
|
|
3472
|
+
serialize: (v) => {
|
|
3473
|
+
return binary_to_base64_string(new Uint8Array(v.buffer, v.byteOffset, v.byteLength));
|
|
3474
|
+
},
|
|
3475
|
+
deserialize: (v) => {
|
|
3476
|
+
const buf = str_to_base64_binary(v);
|
|
3477
|
+
return new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
3478
|
+
}
|
|
3479
|
+
}, "DataView");
|
|
3480
|
+
superjsonInstance.registerCustom({
|
|
3481
|
+
isApplicable: (v) => v instanceof Date,
|
|
3482
|
+
serialize: (v) => {
|
|
3483
|
+
const time = +v;
|
|
3484
|
+
return Number.isNaN(time) ? null : time;
|
|
3485
|
+
},
|
|
3486
|
+
deserialize: (v) => /* @__PURE__ */ new Date(v == null ? NaN : +v)
|
|
3487
|
+
}, "Date");
|
|
3488
|
+
[
|
|
3489
|
+
"Int8Array",
|
|
3490
|
+
"Uint8Array",
|
|
3491
|
+
"Uint8ClampedArray",
|
|
3492
|
+
"Int16Array",
|
|
3493
|
+
"Uint16Array",
|
|
3494
|
+
"Int32Array",
|
|
3495
|
+
"Uint32Array",
|
|
3496
|
+
"Float32Array",
|
|
3497
|
+
"Float64Array",
|
|
3498
|
+
"BigInt64Array",
|
|
3499
|
+
"BigUint64Array"
|
|
3500
|
+
].forEach((TypedArrayCtorName) => {
|
|
3501
|
+
const TypedArrayCtor = globalThis[TypedArrayCtorName];
|
|
3502
|
+
if (typeof TypedArrayCtor !== "function") return;
|
|
3503
|
+
superjsonInstance.registerCustom({
|
|
3504
|
+
isApplicable: (v) => {
|
|
3505
|
+
return ArrayBuffer.isView(v) && Object.getPrototypeOf(v) === TypedArrayCtor.prototype;
|
|
3506
|
+
},
|
|
3507
|
+
serialize: (v) => {
|
|
3508
|
+
return `${v.byteLength},${binary_to_base64_string(v instanceof Uint8Array ? v : new Uint8Array(v.buffer, v.byteOffset, v.byteLength))}`;
|
|
3509
|
+
},
|
|
3510
|
+
deserialize: (v) => {
|
|
3511
|
+
const splitIndex = v.indexOf(",");
|
|
3512
|
+
const len = +v.slice(splitIndex);
|
|
3513
|
+
const base64 = v.slice(splitIndex + 1);
|
|
3514
|
+
if (TypedArrayCtor === Uint8Array) return str_to_base64_binary(base64);
|
|
3515
|
+
const res = new TypedArrayCtor(len);
|
|
3516
|
+
const u8a = new Uint8Array(res.buffer);
|
|
3517
|
+
u8a.set(str_to_base64_binary(base64));
|
|
3518
|
+
return res;
|
|
3519
|
+
}
|
|
3520
|
+
}, TypedArrayCtorName);
|
|
3521
|
+
});
|
|
3522
|
+
const superjson = superjsonInstance;
|
|
3523
|
+
const zModels = object({
|
|
3524
|
+
object: string(),
|
|
3525
|
+
data: array(object({
|
|
3526
|
+
id: string(),
|
|
3527
|
+
object: string(),
|
|
3528
|
+
created: number(),
|
|
3529
|
+
owned_by: string(),
|
|
3530
|
+
active: boolean(),
|
|
3531
|
+
context_window: number(),
|
|
3532
|
+
public_apps: _null(),
|
|
3533
|
+
max_completion_tokens: number(),
|
|
3534
|
+
features: object({
|
|
3535
|
+
chat: boolean(),
|
|
3536
|
+
tools: boolean(),
|
|
3537
|
+
json_mode: boolean(),
|
|
3538
|
+
max_input_images: number(),
|
|
3539
|
+
transcription: boolean(),
|
|
3540
|
+
audio_translation: boolean(),
|
|
3541
|
+
is_batch_enabled: boolean()
|
|
3542
|
+
}),
|
|
3543
|
+
metadata: looseObject({ display_name: string() }),
|
|
3544
|
+
terms_url: nullable(string()),
|
|
3545
|
+
is_terms_required: boolean(),
|
|
3546
|
+
is_terms_accepted: nullable(boolean())
|
|
3547
|
+
}))
|
|
3548
|
+
});
|
|
3549
|
+
const zSession = object({
|
|
3550
|
+
time: number(),
|
|
3551
|
+
headers: record(string(), string()),
|
|
3552
|
+
models: zModels.shape.data
|
|
3553
|
+
});
|
|
3554
|
+
const zTask = union([_lazy(() => zEvalTask), _lazy(() => zFetchTask)]);
|
|
3555
|
+
const getWindowId = /* @__PURE__ */ func_remember(() => {
|
|
3556
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
3557
|
+
const key = sessionStorage.key(i);
|
|
3558
|
+
if (key && key.endsWith("_window_id")) try {
|
|
3559
|
+
return JSON.parse(sessionStorage.getItem(key));
|
|
3560
|
+
} catch {}
|
|
3561
|
+
}
|
|
3562
|
+
const windowId = crypto.randomUUID();
|
|
3563
|
+
sessionStorage.setItem(`groq_2_jixo_window_id`, windowId);
|
|
3564
|
+
return windowId;
|
|
3565
|
+
});
|
|
3566
|
+
let capturedDataPromise;
|
|
3567
|
+
async function captureAndHold() {
|
|
3568
|
+
if (capturedDataPromise) return capturedDataPromise;
|
|
3569
|
+
capturedDataPromise = new Promise(async (resolve, reject) => {
|
|
3570
|
+
const originalFetch = window.fetch;
|
|
3571
|
+
const headers = {};
|
|
3572
|
+
let resolved = false;
|
|
3573
|
+
window.fetch = function(...args) {
|
|
3574
|
+
const request = new Request(...args);
|
|
3575
|
+
const auth = request.headers.get("Authorization");
|
|
3576
|
+
const org = request.headers.get("groq-organization");
|
|
3577
|
+
if (auth && org) {
|
|
3578
|
+
Object.assign(headers, {
|
|
3579
|
+
Authorization: auth,
|
|
3580
|
+
"groq-organization": org
|
|
3581
|
+
});
|
|
3582
|
+
resolved = true;
|
|
3583
|
+
}
|
|
3584
|
+
return originalFetch.call(this, request);
|
|
3585
|
+
};
|
|
3586
|
+
const triggerFetch = async () => {
|
|
3587
|
+
while (!resolved) {
|
|
3588
|
+
document.dispatchEvent(new Event("visibilitychange"));
|
|
3589
|
+
await delay(500);
|
|
3590
|
+
}
|
|
3591
|
+
};
|
|
3592
|
+
console.log(`初始化中,通常5秒内能完成...`);
|
|
3593
|
+
await triggerFetch();
|
|
3594
|
+
while (!resolved) await delay(100);
|
|
3595
|
+
try {
|
|
3596
|
+
const modelsResponse = await originalFetch("https://api.groq.com/internal/v1/models", { headers });
|
|
3597
|
+
const modelsJson = await modelsResponse.json();
|
|
3598
|
+
const models = zModels.parse(modelsJson).data;
|
|
3599
|
+
resolve({
|
|
3600
|
+
headers,
|
|
3601
|
+
models
|
|
3602
|
+
});
|
|
3603
|
+
} catch (error) {
|
|
3604
|
+
reject(error);
|
|
3605
|
+
}
|
|
3606
|
+
});
|
|
3607
|
+
return capturedDataPromise;
|
|
3608
|
+
}
|
|
3609
|
+
const initializeSession = /* @__PURE__ */ func_remember(async () => {
|
|
3610
|
+
try {
|
|
3611
|
+
const { headers, models } = await captureAndHold();
|
|
3612
|
+
const fs = await getEasyFs();
|
|
3613
|
+
const windowId = getWindowId();
|
|
3614
|
+
setInterval(() => {
|
|
3615
|
+
const session = {
|
|
3616
|
+
time: Date.now(),
|
|
3617
|
+
headers,
|
|
3618
|
+
models
|
|
3619
|
+
};
|
|
3620
|
+
fs.writeFile(`${windowId}.groq-session.json`, JSON.stringify(session));
|
|
3621
|
+
}, 1e3);
|
|
3622
|
+
console.log("Session initialized and heartbeat started.");
|
|
3623
|
+
} catch (error) {
|
|
3624
|
+
initializeSession.reset();
|
|
3625
|
+
console.error("Failed to initialize session:", error);
|
|
3626
|
+
}
|
|
3627
|
+
});
|
|
3628
|
+
const taskHandlers = {
|
|
3629
|
+
eval: doEval,
|
|
3630
|
+
fetch: doFetch
|
|
3631
|
+
};
|
|
3632
|
+
var FsHelper = class {
|
|
3633
|
+
constructor(fs) {
|
|
3634
|
+
this.fs = fs;
|
|
3635
|
+
}
|
|
3636
|
+
async getFileHandle(filename) {
|
|
3637
|
+
const dirHandle = this.fs._dirHandle;
|
|
3638
|
+
if (!dirHandle) throw new Error("EasyFS is not initialized with a DirectoryHandle.");
|
|
3639
|
+
return dirHandle.getFileHandle(filename, { create: true });
|
|
3640
|
+
}
|
|
3641
|
+
async removeFile(filename) {
|
|
3642
|
+
const dirHandle = this.fs._dirHandle;
|
|
3643
|
+
if (!dirHandle) throw new Error("EasyFS is not initialized with a DirectoryHandle.");
|
|
3644
|
+
await dirHandle.removeEntry(filename);
|
|
3645
|
+
}
|
|
3646
|
+
};
|
|
3647
|
+
const active_tasks = /* @__PURE__ */ new Set();
|
|
3648
|
+
async function handleTask(fs, filenamePrefix, initialContent) {
|
|
3649
|
+
const initialTask = superjson.parse(initialContent);
|
|
3650
|
+
const handler = taskHandlers[initialTask.type];
|
|
3651
|
+
if (!handler) {
|
|
3652
|
+
console.warn(`No handler for task type: ${initialTask.type}`);
|
|
3653
|
+
active_tasks.delete(filenamePrefix);
|
|
3654
|
+
await fs.rm(`${filenamePrefix}.in.jsonl`).catch(() => {});
|
|
3655
|
+
return;
|
|
3656
|
+
}
|
|
3657
|
+
const helper = new FsHelper(fs);
|
|
3658
|
+
const duplex = new BrowserFsDuplex("handler", superjson, filenamePrefix, helper);
|
|
3659
|
+
try {
|
|
3660
|
+
console.log(`Processing task for prefix: ${filenamePrefix}`);
|
|
3661
|
+
duplex.onClose.on((reason) => {
|
|
3662
|
+
console.log(`Connection for ${filenamePrefix} closed. Reason: ${reason}. Cleaning up from active_tasks.`);
|
|
3663
|
+
active_tasks.delete(filenamePrefix);
|
|
3664
|
+
});
|
|
3665
|
+
duplex.onError.on((err) => {
|
|
3666
|
+
console.error(`Error on duplex for ${filenamePrefix}:`, err);
|
|
3667
|
+
});
|
|
3668
|
+
await duplex.start();
|
|
3669
|
+
await handler(duplex, initialTask);
|
|
3670
|
+
} catch (e) {
|
|
3671
|
+
console.error(`Error processing task ${filenamePrefix}:`, e);
|
|
3672
|
+
if (duplex.currentState !== "closed") duplex.close("error");
|
|
3673
|
+
} finally {
|
|
3674
|
+
await duplex.destroy();
|
|
3675
|
+
console.log(`Task ${filenamePrefix} finished and resources destroyed.`);
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
const processTasks = async () => {
|
|
3679
|
+
const fs = await getEasyFs();
|
|
3680
|
+
const windowId = getWindowId();
|
|
3681
|
+
const taskFiles = (await fs.readdir("")).filter((name) => name.startsWith(`${windowId}.`) && name.endsWith(".groq-task.in.jsonl"));
|
|
3682
|
+
for (const filename of taskFiles) {
|
|
3683
|
+
const filenamePrefix = filename.replace(/\.in\.jsonl$/, "");
|
|
3684
|
+
if (active_tasks.has(filenamePrefix)) continue;
|
|
3685
|
+
active_tasks.add(filenamePrefix);
|
|
3686
|
+
const content = await fs.readFileText(filename);
|
|
3687
|
+
const firstLine = content.split("\n")[0];
|
|
3688
|
+
if (firstLine) handleTask(fs, filenamePrefix, firstLine);
|
|
3689
|
+
else {
|
|
3690
|
+
active_tasks.delete(filenamePrefix);
|
|
3691
|
+
fs.rm(filename).catch(() => {});
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
};
|
|
3695
|
+
const sync = async (fps = 1) => {
|
|
3696
|
+
await initializeSession();
|
|
3697
|
+
console.log("%c会话初始化成功!", styles.success);
|
|
3698
|
+
while (true) {
|
|
3699
|
+
await processTasks();
|
|
3700
|
+
await delay(1e3 / fps);
|
|
3701
|
+
}
|
|
3702
|
+
};
|
|
3703
|
+
(async () => {
|
|
3704
|
+
const aborted$1 = await prepareDirHandle().then(() => false, (e) => {
|
|
3705
|
+
if (e instanceof Error && e.name === "AbortError") return true;
|
|
3706
|
+
});
|
|
3707
|
+
if (aborted$1) {
|
|
3708
|
+
console.warn("用户取消了脚本运行");
|
|
3709
|
+
return;
|
|
3710
|
+
}
|
|
3711
|
+
sync();
|
|
3712
|
+
keepWeakup();
|
|
3713
|
+
Object.assign(window, { extractChat });
|
|
3714
|
+
})();
|