@kevisual/router 0.0.51 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/router-browser.d.ts +15 -0
- package/dist/router-browser.js +306 -60
- package/dist/router.d.ts +30 -4
- package/dist/router.js +791 -66
- package/package.json +16 -18
- package/src/app.ts +9 -0
- package/src/auto/index.ts +19 -0
- package/src/index.ts +4 -2
- package/src/modules/chat.ts +57 -0
- package/src/route.ts +29 -1
- package/src/server/server-base.ts +5 -1
- package/src/server/server-bun.ts +1 -0
- package/src/server/server-type.ts +1 -1
- package/src/server/ws-server.ts +2 -1
- package/src/test/chat.ts +1 -1
- package/auto.ts +0 -19
- package/dist/router-sign.d.ts +0 -16
- package/dist/router-sign.js +0 -14052
- package/src/chat.ts +0 -40
- package/src/io.ts +0 -6
- package/src/router-simple-lib.ts +0 -3
- package/src/sign.ts +0 -59
- package/src/static.ts +0 -97
package/dist/router.js
CHANGED
|
@@ -3,7 +3,7 @@ import require$$2 from 'node:http';
|
|
|
3
3
|
import require$$1$1 from 'node:https';
|
|
4
4
|
import http2 from 'node:http2';
|
|
5
5
|
import url from 'node:url';
|
|
6
|
-
import require$$0$3
|
|
6
|
+
import require$$0$3 from 'node:events';
|
|
7
7
|
import require$$3 from 'node:net';
|
|
8
8
|
import require$$4 from 'node:tls';
|
|
9
9
|
import require$$0$2 from 'node:stream';
|
|
@@ -292,6 +292,7 @@ class Route {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
class QueryRouter {
|
|
295
|
+
appId = '';
|
|
295
296
|
routes;
|
|
296
297
|
maxNextRoute = 40;
|
|
297
298
|
context = {}; // default context for call
|
|
@@ -642,6 +643,21 @@ class QueryRouter {
|
|
|
642
643
|
hasRoute(path, key = '') {
|
|
643
644
|
return this.routes.find((r) => r.path === path && r.key === key);
|
|
644
645
|
}
|
|
646
|
+
findRoute(opts) {
|
|
647
|
+
const { path, key, id } = opts || {};
|
|
648
|
+
return this.routes.find((r) => {
|
|
649
|
+
if (id) {
|
|
650
|
+
return r.id === id;
|
|
651
|
+
}
|
|
652
|
+
if (path) {
|
|
653
|
+
if (key !== undefined) {
|
|
654
|
+
return r.path === path && r.key === key;
|
|
655
|
+
}
|
|
656
|
+
return r.path === path;
|
|
657
|
+
}
|
|
658
|
+
return false;
|
|
659
|
+
});
|
|
660
|
+
}
|
|
645
661
|
createRouteList(force = false, filter) {
|
|
646
662
|
const hasListRoute = this.hasRoute('router', 'list');
|
|
647
663
|
if (!hasListRoute || force) {
|
|
@@ -649,7 +665,7 @@ class QueryRouter {
|
|
|
649
665
|
description: '列出当前应用下的所有的路由信息',
|
|
650
666
|
run: async (ctx) => {
|
|
651
667
|
const list = this.getList(filter);
|
|
652
|
-
ctx.body = list;
|
|
668
|
+
ctx.body = { list };
|
|
653
669
|
},
|
|
654
670
|
});
|
|
655
671
|
this.add(listRoute);
|
|
@@ -681,6 +697,12 @@ class QueryRouterServer extends QueryRouter {
|
|
|
681
697
|
super();
|
|
682
698
|
this.handle = this.getHandle(this, opts?.handleFn, opts?.context);
|
|
683
699
|
this.setContext({ needSerialize: false, ...opts?.context });
|
|
700
|
+
if (opts?.appId) {
|
|
701
|
+
this.appId = opts.appId;
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
this.appId = nanoid$1(16);
|
|
705
|
+
}
|
|
684
706
|
}
|
|
685
707
|
setHandle(wrapperFn, ctx) {
|
|
686
708
|
this.handle = this.getHandle(this, wrapperFn, ctx);
|
|
@@ -1174,6 +1196,360 @@ const parseIfJson = (input) => {
|
|
|
1174
1196
|
return str;
|
|
1175
1197
|
};
|
|
1176
1198
|
|
|
1199
|
+
function getDefaultExportFromCjs (x) {
|
|
1200
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
var eventemitter3 = {exports: {}};
|
|
1204
|
+
|
|
1205
|
+
var hasRequiredEventemitter3;
|
|
1206
|
+
|
|
1207
|
+
function requireEventemitter3 () {
|
|
1208
|
+
if (hasRequiredEventemitter3) return eventemitter3.exports;
|
|
1209
|
+
hasRequiredEventemitter3 = 1;
|
|
1210
|
+
(function (module) {
|
|
1211
|
+
|
|
1212
|
+
var has = Object.prototype.hasOwnProperty
|
|
1213
|
+
, prefix = '~';
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* Constructor to create a storage for our `EE` objects.
|
|
1217
|
+
* An `Events` instance is a plain object whose properties are event names.
|
|
1218
|
+
*
|
|
1219
|
+
* @constructor
|
|
1220
|
+
* @private
|
|
1221
|
+
*/
|
|
1222
|
+
function Events() {}
|
|
1223
|
+
|
|
1224
|
+
//
|
|
1225
|
+
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
1226
|
+
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
1227
|
+
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
1228
|
+
// character to make sure that the built-in object properties are not
|
|
1229
|
+
// overridden or used as an attack vector.
|
|
1230
|
+
//
|
|
1231
|
+
if (Object.create) {
|
|
1232
|
+
Events.prototype = Object.create(null);
|
|
1233
|
+
|
|
1234
|
+
//
|
|
1235
|
+
// This hack is needed because the `__proto__` property is still inherited in
|
|
1236
|
+
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
1237
|
+
//
|
|
1238
|
+
if (!new Events().__proto__) prefix = false;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Representation of a single event listener.
|
|
1243
|
+
*
|
|
1244
|
+
* @param {Function} fn The listener function.
|
|
1245
|
+
* @param {*} context The context to invoke the listener with.
|
|
1246
|
+
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
1247
|
+
* @constructor
|
|
1248
|
+
* @private
|
|
1249
|
+
*/
|
|
1250
|
+
function EE(fn, context, once) {
|
|
1251
|
+
this.fn = fn;
|
|
1252
|
+
this.context = context;
|
|
1253
|
+
this.once = once || false;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Add a listener for a given event.
|
|
1258
|
+
*
|
|
1259
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
1260
|
+
* @param {(String|Symbol)} event The event name.
|
|
1261
|
+
* @param {Function} fn The listener function.
|
|
1262
|
+
* @param {*} context The context to invoke the listener with.
|
|
1263
|
+
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
1264
|
+
* @returns {EventEmitter}
|
|
1265
|
+
* @private
|
|
1266
|
+
*/
|
|
1267
|
+
function addListener(emitter, event, fn, context, once) {
|
|
1268
|
+
if (typeof fn !== 'function') {
|
|
1269
|
+
throw new TypeError('The listener must be a function');
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
var listener = new EE(fn, context || emitter, once)
|
|
1273
|
+
, evt = prefix ? prefix + event : event;
|
|
1274
|
+
|
|
1275
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
1276
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
1277
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
1278
|
+
|
|
1279
|
+
return emitter;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Clear event by name.
|
|
1284
|
+
*
|
|
1285
|
+
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
1286
|
+
* @param {(String|Symbol)} evt The Event name.
|
|
1287
|
+
* @private
|
|
1288
|
+
*/
|
|
1289
|
+
function clearEvent(emitter, evt) {
|
|
1290
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
1291
|
+
else delete emitter._events[evt];
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
1296
|
+
* `EventEmitter` interface.
|
|
1297
|
+
*
|
|
1298
|
+
* @constructor
|
|
1299
|
+
* @public
|
|
1300
|
+
*/
|
|
1301
|
+
function EventEmitter() {
|
|
1302
|
+
this._events = new Events();
|
|
1303
|
+
this._eventsCount = 0;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* Return an array listing the events for which the emitter has registered
|
|
1308
|
+
* listeners.
|
|
1309
|
+
*
|
|
1310
|
+
* @returns {Array}
|
|
1311
|
+
* @public
|
|
1312
|
+
*/
|
|
1313
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
1314
|
+
var names = []
|
|
1315
|
+
, events
|
|
1316
|
+
, name;
|
|
1317
|
+
|
|
1318
|
+
if (this._eventsCount === 0) return names;
|
|
1319
|
+
|
|
1320
|
+
for (name in (events = this._events)) {
|
|
1321
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
if (Object.getOwnPropertySymbols) {
|
|
1325
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
return names;
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Return the listeners registered for a given event.
|
|
1333
|
+
*
|
|
1334
|
+
* @param {(String|Symbol)} event The event name.
|
|
1335
|
+
* @returns {Array} The registered listeners.
|
|
1336
|
+
* @public
|
|
1337
|
+
*/
|
|
1338
|
+
EventEmitter.prototype.listeners = function listeners(event) {
|
|
1339
|
+
var evt = prefix ? prefix + event : event
|
|
1340
|
+
, handlers = this._events[evt];
|
|
1341
|
+
|
|
1342
|
+
if (!handlers) return [];
|
|
1343
|
+
if (handlers.fn) return [handlers.fn];
|
|
1344
|
+
|
|
1345
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
1346
|
+
ee[i] = handlers[i].fn;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
return ee;
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* Return the number of listeners listening to a given event.
|
|
1354
|
+
*
|
|
1355
|
+
* @param {(String|Symbol)} event The event name.
|
|
1356
|
+
* @returns {Number} The number of listeners.
|
|
1357
|
+
* @public
|
|
1358
|
+
*/
|
|
1359
|
+
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
1360
|
+
var evt = prefix ? prefix + event : event
|
|
1361
|
+
, listeners = this._events[evt];
|
|
1362
|
+
|
|
1363
|
+
if (!listeners) return 0;
|
|
1364
|
+
if (listeners.fn) return 1;
|
|
1365
|
+
return listeners.length;
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
/**
|
|
1369
|
+
* Calls each of the listeners registered for a given event.
|
|
1370
|
+
*
|
|
1371
|
+
* @param {(String|Symbol)} event The event name.
|
|
1372
|
+
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
1373
|
+
* @public
|
|
1374
|
+
*/
|
|
1375
|
+
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
1376
|
+
var evt = prefix ? prefix + event : event;
|
|
1377
|
+
|
|
1378
|
+
if (!this._events[evt]) return false;
|
|
1379
|
+
|
|
1380
|
+
var listeners = this._events[evt]
|
|
1381
|
+
, len = arguments.length
|
|
1382
|
+
, args
|
|
1383
|
+
, i;
|
|
1384
|
+
|
|
1385
|
+
if (listeners.fn) {
|
|
1386
|
+
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
1387
|
+
|
|
1388
|
+
switch (len) {
|
|
1389
|
+
case 1: return listeners.fn.call(listeners.context), true;
|
|
1390
|
+
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
1391
|
+
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
1392
|
+
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
1393
|
+
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
1394
|
+
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
1398
|
+
args[i - 1] = arguments[i];
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
listeners.fn.apply(listeners.context, args);
|
|
1402
|
+
} else {
|
|
1403
|
+
var length = listeners.length
|
|
1404
|
+
, j;
|
|
1405
|
+
|
|
1406
|
+
for (i = 0; i < length; i++) {
|
|
1407
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
1408
|
+
|
|
1409
|
+
switch (len) {
|
|
1410
|
+
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
1411
|
+
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
1412
|
+
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
1413
|
+
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
1414
|
+
default:
|
|
1415
|
+
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
1416
|
+
args[j - 1] = arguments[j];
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
return true;
|
|
1425
|
+
};
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Add a listener for a given event.
|
|
1429
|
+
*
|
|
1430
|
+
* @param {(String|Symbol)} event The event name.
|
|
1431
|
+
* @param {Function} fn The listener function.
|
|
1432
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
1433
|
+
* @returns {EventEmitter} `this`.
|
|
1434
|
+
* @public
|
|
1435
|
+
*/
|
|
1436
|
+
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
1437
|
+
return addListener(this, event, fn, context, false);
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1440
|
+
/**
|
|
1441
|
+
* Add a one-time listener for a given event.
|
|
1442
|
+
*
|
|
1443
|
+
* @param {(String|Symbol)} event The event name.
|
|
1444
|
+
* @param {Function} fn The listener function.
|
|
1445
|
+
* @param {*} [context=this] The context to invoke the listener with.
|
|
1446
|
+
* @returns {EventEmitter} `this`.
|
|
1447
|
+
* @public
|
|
1448
|
+
*/
|
|
1449
|
+
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
1450
|
+
return addListener(this, event, fn, context, true);
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
/**
|
|
1454
|
+
* Remove the listeners of a given event.
|
|
1455
|
+
*
|
|
1456
|
+
* @param {(String|Symbol)} event The event name.
|
|
1457
|
+
* @param {Function} fn Only remove the listeners that match this function.
|
|
1458
|
+
* @param {*} context Only remove the listeners that have this context.
|
|
1459
|
+
* @param {Boolean} once Only remove one-time listeners.
|
|
1460
|
+
* @returns {EventEmitter} `this`.
|
|
1461
|
+
* @public
|
|
1462
|
+
*/
|
|
1463
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
1464
|
+
var evt = prefix ? prefix + event : event;
|
|
1465
|
+
|
|
1466
|
+
if (!this._events[evt]) return this;
|
|
1467
|
+
if (!fn) {
|
|
1468
|
+
clearEvent(this, evt);
|
|
1469
|
+
return this;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
var listeners = this._events[evt];
|
|
1473
|
+
|
|
1474
|
+
if (listeners.fn) {
|
|
1475
|
+
if (
|
|
1476
|
+
listeners.fn === fn &&
|
|
1477
|
+
(!once || listeners.once) &&
|
|
1478
|
+
(!context || listeners.context === context)
|
|
1479
|
+
) {
|
|
1480
|
+
clearEvent(this, evt);
|
|
1481
|
+
}
|
|
1482
|
+
} else {
|
|
1483
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
1484
|
+
if (
|
|
1485
|
+
listeners[i].fn !== fn ||
|
|
1486
|
+
(once && !listeners[i].once) ||
|
|
1487
|
+
(context && listeners[i].context !== context)
|
|
1488
|
+
) {
|
|
1489
|
+
events.push(listeners[i]);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
//
|
|
1494
|
+
// Reset the array, or remove it completely if we have no more listeners.
|
|
1495
|
+
//
|
|
1496
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
1497
|
+
else clearEvent(this, evt);
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
return this;
|
|
1501
|
+
};
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* Remove all listeners, or those of the specified event.
|
|
1505
|
+
*
|
|
1506
|
+
* @param {(String|Symbol)} [event] The event name.
|
|
1507
|
+
* @returns {EventEmitter} `this`.
|
|
1508
|
+
* @public
|
|
1509
|
+
*/
|
|
1510
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
1511
|
+
var evt;
|
|
1512
|
+
|
|
1513
|
+
if (event) {
|
|
1514
|
+
evt = prefix ? prefix + event : event;
|
|
1515
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
1516
|
+
} else {
|
|
1517
|
+
this._events = new Events();
|
|
1518
|
+
this._eventsCount = 0;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
return this;
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
//
|
|
1525
|
+
// Alias methods names because people roll like that.
|
|
1526
|
+
//
|
|
1527
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
1528
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
1529
|
+
|
|
1530
|
+
//
|
|
1531
|
+
// Expose the prefix.
|
|
1532
|
+
//
|
|
1533
|
+
EventEmitter.prefixed = prefix;
|
|
1534
|
+
|
|
1535
|
+
//
|
|
1536
|
+
// Allow `EventEmitter` to be imported as module namespace.
|
|
1537
|
+
//
|
|
1538
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
1539
|
+
|
|
1540
|
+
//
|
|
1541
|
+
// Expose the module.
|
|
1542
|
+
//
|
|
1543
|
+
{
|
|
1544
|
+
module.exports = EventEmitter;
|
|
1545
|
+
}
|
|
1546
|
+
} (eventemitter3));
|
|
1547
|
+
return eventemitter3.exports;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
var eventemitter3Exports = requireEventemitter3();
|
|
1551
|
+
var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
|
|
1552
|
+
|
|
1177
1553
|
// 实现函数
|
|
1178
1554
|
function createHandleCtx(req, res) {
|
|
1179
1555
|
// 用于存储所有的 Set-Cookie 字符串
|
|
@@ -1419,6 +1795,10 @@ class ServerBase {
|
|
|
1419
1795
|
end({ code: 500, message: `${type} server is error` });
|
|
1420
1796
|
}
|
|
1421
1797
|
}
|
|
1798
|
+
/**
|
|
1799
|
+
* 根据emitter提醒关闭ws连接
|
|
1800
|
+
* @param ws
|
|
1801
|
+
*/
|
|
1422
1802
|
async onWsClose(ws) {
|
|
1423
1803
|
const id = ws?.data?.id || '';
|
|
1424
1804
|
if (id) {
|
|
@@ -1436,10 +1816,6 @@ class ServerBase {
|
|
|
1436
1816
|
}
|
|
1437
1817
|
}
|
|
1438
1818
|
|
|
1439
|
-
function getDefaultExportFromCjs (x) {
|
|
1440
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
1819
|
var constants;
|
|
1444
1820
|
var hasRequiredConstants;
|
|
1445
1821
|
|
|
@@ -6390,6 +6766,8 @@ class WsServerBase {
|
|
|
6390
6766
|
});
|
|
6391
6767
|
this.server.sendConnected(ws);
|
|
6392
6768
|
this.wss.on('close', () => {
|
|
6769
|
+
// @ts-ignore
|
|
6770
|
+
ws?.data?.close?.();
|
|
6393
6771
|
this.server.onWsClose(ws);
|
|
6394
6772
|
});
|
|
6395
6773
|
});
|
|
@@ -6731,6 +7109,7 @@ class BunServer extends ServerBase {
|
|
|
6731
7109
|
},
|
|
6732
7110
|
close: (ws) => {
|
|
6733
7111
|
// WebSocket 连接关闭
|
|
7112
|
+
ws?.data?.close?.();
|
|
6734
7113
|
this.onWsClose(ws);
|
|
6735
7114
|
},
|
|
6736
7115
|
},
|
|
@@ -6995,6 +7374,11 @@ const NUMBER_FORMAT_RANGES = {
|
|
|
6995
7374
|
};
|
|
6996
7375
|
function pick(schema, mask) {
|
|
6997
7376
|
const currDef = schema._zod.def;
|
|
7377
|
+
const checks = currDef.checks;
|
|
7378
|
+
const hasChecks = checks && checks.length > 0;
|
|
7379
|
+
if (hasChecks) {
|
|
7380
|
+
throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
7381
|
+
}
|
|
6998
7382
|
const def = mergeDefs(schema._zod.def, {
|
|
6999
7383
|
get shape() {
|
|
7000
7384
|
const newShape = {};
|
|
@@ -7015,6 +7399,11 @@ function pick(schema, mask) {
|
|
|
7015
7399
|
}
|
|
7016
7400
|
function omit(schema, mask) {
|
|
7017
7401
|
const currDef = schema._zod.def;
|
|
7402
|
+
const checks = currDef.checks;
|
|
7403
|
+
const hasChecks = checks && checks.length > 0;
|
|
7404
|
+
if (hasChecks) {
|
|
7405
|
+
throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
7406
|
+
}
|
|
7018
7407
|
const def = mergeDefs(schema._zod.def, {
|
|
7019
7408
|
get shape() {
|
|
7020
7409
|
const newShape = { ...schema._zod.def.shape };
|
|
@@ -7040,7 +7429,14 @@ function extend(schema, shape) {
|
|
|
7040
7429
|
const checks = schema._zod.def.checks;
|
|
7041
7430
|
const hasChecks = checks && checks.length > 0;
|
|
7042
7431
|
if (hasChecks) {
|
|
7043
|
-
|
|
7432
|
+
// Only throw if new shape overlaps with existing shape
|
|
7433
|
+
// Use getOwnPropertyDescriptor to check key existence without accessing values
|
|
7434
|
+
const existingShape = schema._zod.def.shape;
|
|
7435
|
+
for (const key in shape) {
|
|
7436
|
+
if (Object.getOwnPropertyDescriptor(existingShape, key) !== undefined) {
|
|
7437
|
+
throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
7438
|
+
}
|
|
7439
|
+
}
|
|
7044
7440
|
}
|
|
7045
7441
|
const def = mergeDefs(schema._zod.def, {
|
|
7046
7442
|
get shape() {
|
|
@@ -7048,7 +7444,6 @@ function extend(schema, shape) {
|
|
|
7048
7444
|
assignProp(this, "shape", _shape); // self-caching
|
|
7049
7445
|
return _shape;
|
|
7050
7446
|
},
|
|
7051
|
-
checks: [],
|
|
7052
7447
|
});
|
|
7053
7448
|
return clone(schema, def);
|
|
7054
7449
|
}
|
|
@@ -7056,15 +7451,13 @@ function safeExtend(schema, shape) {
|
|
|
7056
7451
|
if (!isPlainObject(shape)) {
|
|
7057
7452
|
throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
7058
7453
|
}
|
|
7059
|
-
const def = {
|
|
7060
|
-
...schema._zod.def,
|
|
7454
|
+
const def = mergeDefs(schema._zod.def, {
|
|
7061
7455
|
get shape() {
|
|
7062
7456
|
const _shape = { ...schema._zod.def.shape, ...shape };
|
|
7063
7457
|
assignProp(this, "shape", _shape); // self-caching
|
|
7064
7458
|
return _shape;
|
|
7065
7459
|
},
|
|
7066
|
-
|
|
7067
|
-
};
|
|
7460
|
+
});
|
|
7068
7461
|
return clone(schema, def);
|
|
7069
7462
|
}
|
|
7070
7463
|
function merge(a, b) {
|
|
@@ -7082,6 +7475,12 @@ function merge(a, b) {
|
|
|
7082
7475
|
return clone(a, def);
|
|
7083
7476
|
}
|
|
7084
7477
|
function partial(Class, schema, mask) {
|
|
7478
|
+
const currDef = schema._zod.def;
|
|
7479
|
+
const checks = currDef.checks;
|
|
7480
|
+
const hasChecks = checks && checks.length > 0;
|
|
7481
|
+
if (hasChecks) {
|
|
7482
|
+
throw new Error(".partial() cannot be used on object schemas containing refinements");
|
|
7483
|
+
}
|
|
7085
7484
|
const def = mergeDefs(schema._zod.def, {
|
|
7086
7485
|
get shape() {
|
|
7087
7486
|
const oldShape = schema._zod.def.shape;
|
|
@@ -7151,7 +7550,6 @@ function required(Class, schema, mask) {
|
|
|
7151
7550
|
assignProp(this, "shape", shape); // self-caching
|
|
7152
7551
|
return shape;
|
|
7153
7552
|
},
|
|
7154
|
-
checks: [],
|
|
7155
7553
|
});
|
|
7156
7554
|
return clone(schema, def);
|
|
7157
7555
|
}
|
|
@@ -7401,7 +7799,8 @@ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?:
|
|
|
7401
7799
|
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
7402
7800
|
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
7403
7801
|
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
|
7404
|
-
|
|
7802
|
+
// E.164: leading digit must be 1-9; total digits (excluding '+') between 7-15
|
|
7803
|
+
const e164 = /^\+[1-9]\d{6,14}$/;
|
|
7405
7804
|
// 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])))`;
|
|
7406
7805
|
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])))`;
|
|
7407
7806
|
const date$1 = /*@__PURE__*/ new RegExp(`^${dateSource}$`);
|
|
@@ -7436,7 +7835,7 @@ const string$1 = (params) => {
|
|
|
7436
7835
|
return new RegExp(`^${regex}$`);
|
|
7437
7836
|
};
|
|
7438
7837
|
const integer = /^-?\d+$/;
|
|
7439
|
-
const number$1 = /^-?\d+(?:\.\d+)
|
|
7838
|
+
const number$1 = /^-?\d+(?:\.\d+)?$/;
|
|
7440
7839
|
const boolean$1 = /^(?:true|false)$/i;
|
|
7441
7840
|
// regex for string with no uppercase letters
|
|
7442
7841
|
const lowercase = /^[^A-Z]*$/;
|
|
@@ -7475,7 +7874,7 @@ const $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst,
|
|
|
7475
7874
|
payload.issues.push({
|
|
7476
7875
|
origin,
|
|
7477
7876
|
code: "too_big",
|
|
7478
|
-
maximum: def.value,
|
|
7877
|
+
maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
7479
7878
|
input: payload.value,
|
|
7480
7879
|
inclusive: def.inclusive,
|
|
7481
7880
|
inst,
|
|
@@ -7503,7 +7902,7 @@ const $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan",
|
|
|
7503
7902
|
payload.issues.push({
|
|
7504
7903
|
origin,
|
|
7505
7904
|
code: "too_small",
|
|
7506
|
-
minimum: def.value,
|
|
7905
|
+
minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
7507
7906
|
input: payload.value,
|
|
7508
7907
|
inclusive: def.inclusive,
|
|
7509
7908
|
inst,
|
|
@@ -7591,6 +7990,7 @@ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat"
|
|
|
7591
7990
|
note: "Integers must be within the safe integer range.",
|
|
7592
7991
|
inst,
|
|
7593
7992
|
origin,
|
|
7993
|
+
inclusive: true,
|
|
7594
7994
|
continue: !def.abort,
|
|
7595
7995
|
});
|
|
7596
7996
|
}
|
|
@@ -7603,6 +8003,7 @@ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat"
|
|
|
7603
8003
|
note: "Integers must be within the safe integer range.",
|
|
7604
8004
|
inst,
|
|
7605
8005
|
origin,
|
|
8006
|
+
inclusive: true,
|
|
7606
8007
|
continue: !def.abort,
|
|
7607
8008
|
});
|
|
7608
8009
|
}
|
|
@@ -7626,7 +8027,9 @@ const $ZodCheckNumberFormat = /*@__PURE__*/ $constructor("$ZodCheckNumberFormat"
|
|
|
7626
8027
|
input,
|
|
7627
8028
|
code: "too_big",
|
|
7628
8029
|
maximum,
|
|
8030
|
+
inclusive: true,
|
|
7629
8031
|
inst,
|
|
8032
|
+
continue: !def.abort,
|
|
7630
8033
|
});
|
|
7631
8034
|
}
|
|
7632
8035
|
};
|
|
@@ -7889,8 +8292,8 @@ class Doc {
|
|
|
7889
8292
|
|
|
7890
8293
|
const version = {
|
|
7891
8294
|
major: 4,
|
|
7892
|
-
minor:
|
|
7893
|
-
patch:
|
|
8295
|
+
minor: 3,
|
|
8296
|
+
patch: 5,
|
|
7894
8297
|
};
|
|
7895
8298
|
|
|
7896
8299
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
@@ -8000,7 +8403,8 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
|
8000
8403
|
return runChecks(result, checks, ctx);
|
|
8001
8404
|
};
|
|
8002
8405
|
}
|
|
8003
|
-
|
|
8406
|
+
// Lazy initialize ~standard to avoid creating objects for every schema
|
|
8407
|
+
defineLazy(inst, "~standard", () => ({
|
|
8004
8408
|
validate: (value) => {
|
|
8005
8409
|
try {
|
|
8006
8410
|
const r = safeParse$1(inst, value);
|
|
@@ -8012,7 +8416,7 @@ const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
|
8012
8416
|
},
|
|
8013
8417
|
vendor: "zod",
|
|
8014
8418
|
version: 1,
|
|
8015
|
-
};
|
|
8419
|
+
}));
|
|
8016
8420
|
});
|
|
8017
8421
|
const $ZodString = /*@__PURE__*/ $constructor("$ZodString", (inst, def) => {
|
|
8018
8422
|
$ZodType.init(inst, def);
|
|
@@ -8441,8 +8845,12 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
|
|
|
8441
8845
|
return payload; //handleArrayResultsAsync(parseResults, final);
|
|
8442
8846
|
};
|
|
8443
8847
|
});
|
|
8444
|
-
function handlePropertyResult(result, final, key, input) {
|
|
8848
|
+
function handlePropertyResult(result, final, key, input, isOptionalOut) {
|
|
8445
8849
|
if (result.issues.length) {
|
|
8850
|
+
// For optional-out schemas, ignore errors on absent keys
|
|
8851
|
+
if (isOptionalOut && !(key in input)) {
|
|
8852
|
+
return;
|
|
8853
|
+
}
|
|
8446
8854
|
final.issues.push(...prefixIssues(key, result.issues));
|
|
8447
8855
|
}
|
|
8448
8856
|
if (result.value === undefined) {
|
|
@@ -8476,6 +8884,7 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
8476
8884
|
const keySet = def.keySet;
|
|
8477
8885
|
const _catchall = def.catchall._zod;
|
|
8478
8886
|
const t = _catchall.def.type;
|
|
8887
|
+
const isOptionalOut = _catchall.optout === "optional";
|
|
8479
8888
|
for (const key in input) {
|
|
8480
8889
|
if (keySet.has(key))
|
|
8481
8890
|
continue;
|
|
@@ -8485,10 +8894,10 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
8485
8894
|
}
|
|
8486
8895
|
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
|
|
8487
8896
|
if (r instanceof Promise) {
|
|
8488
|
-
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
|
|
8897
|
+
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
|
|
8489
8898
|
}
|
|
8490
8899
|
else {
|
|
8491
|
-
handlePropertyResult(r, payload, key, input);
|
|
8900
|
+
handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
8492
8901
|
}
|
|
8493
8902
|
}
|
|
8494
8903
|
if (unrecognized.length) {
|
|
@@ -8556,12 +8965,13 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
|
|
|
8556
8965
|
const shape = value.shape;
|
|
8557
8966
|
for (const key of value.keys) {
|
|
8558
8967
|
const el = shape[key];
|
|
8968
|
+
const isOptionalOut = el._zod.optout === "optional";
|
|
8559
8969
|
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
|
|
8560
8970
|
if (r instanceof Promise) {
|
|
8561
|
-
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
|
|
8971
|
+
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
|
|
8562
8972
|
}
|
|
8563
8973
|
else {
|
|
8564
|
-
handlePropertyResult(r, payload, key, input);
|
|
8974
|
+
handlePropertyResult(r, payload, key, input, isOptionalOut);
|
|
8565
8975
|
}
|
|
8566
8976
|
}
|
|
8567
8977
|
if (!catchall) {
|
|
@@ -8593,8 +9003,33 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
8593
9003
|
for (const key of normalized.keys) {
|
|
8594
9004
|
const id = ids[key];
|
|
8595
9005
|
const k = esc(key);
|
|
9006
|
+
const schema = shape[key];
|
|
9007
|
+
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
8596
9008
|
doc.write(`const ${id} = ${parseStr(key)};`);
|
|
8597
|
-
|
|
9009
|
+
if (isOptionalOut) {
|
|
9010
|
+
// For optional-out schemas, ignore errors on absent keys
|
|
9011
|
+
doc.write(`
|
|
9012
|
+
if (${id}.issues.length) {
|
|
9013
|
+
if (${k} in input) {
|
|
9014
|
+
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
9015
|
+
...iss,
|
|
9016
|
+
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
9017
|
+
})));
|
|
9018
|
+
}
|
|
9019
|
+
}
|
|
9020
|
+
|
|
9021
|
+
if (${id}.value === undefined) {
|
|
9022
|
+
if (${k} in input) {
|
|
9023
|
+
newResult[${k}] = undefined;
|
|
9024
|
+
}
|
|
9025
|
+
} else {
|
|
9026
|
+
newResult[${k}] = ${id}.value;
|
|
9027
|
+
}
|
|
9028
|
+
|
|
9029
|
+
`);
|
|
9030
|
+
}
|
|
9031
|
+
else {
|
|
9032
|
+
doc.write(`
|
|
8598
9033
|
if (${id}.issues.length) {
|
|
8599
9034
|
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
|
|
8600
9035
|
...iss,
|
|
@@ -8602,7 +9037,6 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
8602
9037
|
})));
|
|
8603
9038
|
}
|
|
8604
9039
|
|
|
8605
|
-
|
|
8606
9040
|
if (${id}.value === undefined) {
|
|
8607
9041
|
if (${k} in input) {
|
|
8608
9042
|
newResult[${k}] = undefined;
|
|
@@ -8612,6 +9046,7 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
8612
9046
|
}
|
|
8613
9047
|
|
|
8614
9048
|
`);
|
|
9049
|
+
}
|
|
8615
9050
|
}
|
|
8616
9051
|
doc.write(`payload.value = newResult;`);
|
|
8617
9052
|
doc.write(`return payload;`);
|
|
@@ -8778,11 +9213,38 @@ function mergeValues(a, b) {
|
|
|
8778
9213
|
return { valid: false, mergeErrorPath: [] };
|
|
8779
9214
|
}
|
|
8780
9215
|
function handleIntersectionResults(result, left, right) {
|
|
8781
|
-
|
|
8782
|
-
|
|
9216
|
+
// Track which side(s) report each key as unrecognized
|
|
9217
|
+
const unrecKeys = new Map();
|
|
9218
|
+
let unrecIssue;
|
|
9219
|
+
for (const iss of left.issues) {
|
|
9220
|
+
if (iss.code === "unrecognized_keys") {
|
|
9221
|
+
unrecIssue ?? (unrecIssue = iss);
|
|
9222
|
+
for (const k of iss.keys) {
|
|
9223
|
+
if (!unrecKeys.has(k))
|
|
9224
|
+
unrecKeys.set(k, {});
|
|
9225
|
+
unrecKeys.get(k).l = true;
|
|
9226
|
+
}
|
|
9227
|
+
}
|
|
9228
|
+
else {
|
|
9229
|
+
result.issues.push(iss);
|
|
9230
|
+
}
|
|
9231
|
+
}
|
|
9232
|
+
for (const iss of right.issues) {
|
|
9233
|
+
if (iss.code === "unrecognized_keys") {
|
|
9234
|
+
for (const k of iss.keys) {
|
|
9235
|
+
if (!unrecKeys.has(k))
|
|
9236
|
+
unrecKeys.set(k, {});
|
|
9237
|
+
unrecKeys.get(k).r = true;
|
|
9238
|
+
}
|
|
9239
|
+
}
|
|
9240
|
+
else {
|
|
9241
|
+
result.issues.push(iss);
|
|
9242
|
+
}
|
|
8783
9243
|
}
|
|
8784
|
-
|
|
8785
|
-
|
|
9244
|
+
// Report only keys unrecognized by BOTH sides
|
|
9245
|
+
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
|
|
9246
|
+
if (bothKeys.length && unrecIssue) {
|
|
9247
|
+
result.issues.push({ ...unrecIssue, keys: bothKeys });
|
|
8786
9248
|
}
|
|
8787
9249
|
if (aborted(result))
|
|
8788
9250
|
return result;
|
|
@@ -8867,6 +9329,17 @@ const $ZodOptional = /*@__PURE__*/ $constructor("$ZodOptional", (inst, def) => {
|
|
|
8867
9329
|
return def.innerType._zod.run(payload, ctx);
|
|
8868
9330
|
};
|
|
8869
9331
|
});
|
|
9332
|
+
const $ZodExactOptional = /*@__PURE__*/ $constructor("$ZodExactOptional", (inst, def) => {
|
|
9333
|
+
// Call parent init - inherits optin/optout = "optional"
|
|
9334
|
+
$ZodOptional.init(inst, def);
|
|
9335
|
+
// Override values/pattern to NOT add undefined
|
|
9336
|
+
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
9337
|
+
defineLazy(inst._zod, "pattern", () => def.innerType._zod.pattern);
|
|
9338
|
+
// Override parse to just delegate (no undefined handling)
|
|
9339
|
+
inst._zod.parse = (payload, ctx) => {
|
|
9340
|
+
return def.innerType._zod.run(payload, ctx);
|
|
9341
|
+
};
|
|
9342
|
+
});
|
|
8870
9343
|
const $ZodNullable = /*@__PURE__*/ $constructor("$ZodNullable", (inst, def) => {
|
|
8871
9344
|
$ZodType.init(inst, def);
|
|
8872
9345
|
defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
|
|
@@ -9089,9 +9562,6 @@ class $ZodRegistry {
|
|
|
9089
9562
|
const meta = _meta[0];
|
|
9090
9563
|
this._map.set(schema, meta);
|
|
9091
9564
|
if (meta && typeof meta === "object" && "id" in meta) {
|
|
9092
|
-
if (this._idmap.has(meta.id)) {
|
|
9093
|
-
throw new Error(`ID ${meta.id} already exists in the registry`);
|
|
9094
|
-
}
|
|
9095
9565
|
this._idmap.set(meta.id, schema);
|
|
9096
9566
|
}
|
|
9097
9567
|
return this;
|
|
@@ -9132,12 +9602,14 @@ function registry() {
|
|
|
9132
9602
|
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
9133
9603
|
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
9134
9604
|
|
|
9605
|
+
// @__NO_SIDE_EFFECTS__
|
|
9135
9606
|
function _string(Class, params) {
|
|
9136
9607
|
return new Class({
|
|
9137
9608
|
type: "string",
|
|
9138
9609
|
...normalizeParams(params),
|
|
9139
9610
|
});
|
|
9140
9611
|
}
|
|
9612
|
+
// @__NO_SIDE_EFFECTS__
|
|
9141
9613
|
function _email(Class, params) {
|
|
9142
9614
|
return new Class({
|
|
9143
9615
|
type: "string",
|
|
@@ -9147,6 +9619,7 @@ function _email(Class, params) {
|
|
|
9147
9619
|
...normalizeParams(params),
|
|
9148
9620
|
});
|
|
9149
9621
|
}
|
|
9622
|
+
// @__NO_SIDE_EFFECTS__
|
|
9150
9623
|
function _guid(Class, params) {
|
|
9151
9624
|
return new Class({
|
|
9152
9625
|
type: "string",
|
|
@@ -9156,6 +9629,7 @@ function _guid(Class, params) {
|
|
|
9156
9629
|
...normalizeParams(params),
|
|
9157
9630
|
});
|
|
9158
9631
|
}
|
|
9632
|
+
// @__NO_SIDE_EFFECTS__
|
|
9159
9633
|
function _uuid(Class, params) {
|
|
9160
9634
|
return new Class({
|
|
9161
9635
|
type: "string",
|
|
@@ -9165,6 +9639,7 @@ function _uuid(Class, params) {
|
|
|
9165
9639
|
...normalizeParams(params),
|
|
9166
9640
|
});
|
|
9167
9641
|
}
|
|
9642
|
+
// @__NO_SIDE_EFFECTS__
|
|
9168
9643
|
function _uuidv4(Class, params) {
|
|
9169
9644
|
return new Class({
|
|
9170
9645
|
type: "string",
|
|
@@ -9175,6 +9650,7 @@ function _uuidv4(Class, params) {
|
|
|
9175
9650
|
...normalizeParams(params),
|
|
9176
9651
|
});
|
|
9177
9652
|
}
|
|
9653
|
+
// @__NO_SIDE_EFFECTS__
|
|
9178
9654
|
function _uuidv6(Class, params) {
|
|
9179
9655
|
return new Class({
|
|
9180
9656
|
type: "string",
|
|
@@ -9185,6 +9661,7 @@ function _uuidv6(Class, params) {
|
|
|
9185
9661
|
...normalizeParams(params),
|
|
9186
9662
|
});
|
|
9187
9663
|
}
|
|
9664
|
+
// @__NO_SIDE_EFFECTS__
|
|
9188
9665
|
function _uuidv7(Class, params) {
|
|
9189
9666
|
return new Class({
|
|
9190
9667
|
type: "string",
|
|
@@ -9195,6 +9672,7 @@ function _uuidv7(Class, params) {
|
|
|
9195
9672
|
...normalizeParams(params),
|
|
9196
9673
|
});
|
|
9197
9674
|
}
|
|
9675
|
+
// @__NO_SIDE_EFFECTS__
|
|
9198
9676
|
function _url(Class, params) {
|
|
9199
9677
|
return new Class({
|
|
9200
9678
|
type: "string",
|
|
@@ -9204,6 +9682,7 @@ function _url(Class, params) {
|
|
|
9204
9682
|
...normalizeParams(params),
|
|
9205
9683
|
});
|
|
9206
9684
|
}
|
|
9685
|
+
// @__NO_SIDE_EFFECTS__
|
|
9207
9686
|
function _emoji(Class, params) {
|
|
9208
9687
|
return new Class({
|
|
9209
9688
|
type: "string",
|
|
@@ -9213,6 +9692,7 @@ function _emoji(Class, params) {
|
|
|
9213
9692
|
...normalizeParams(params),
|
|
9214
9693
|
});
|
|
9215
9694
|
}
|
|
9695
|
+
// @__NO_SIDE_EFFECTS__
|
|
9216
9696
|
function _nanoid(Class, params) {
|
|
9217
9697
|
return new Class({
|
|
9218
9698
|
type: "string",
|
|
@@ -9222,6 +9702,7 @@ function _nanoid(Class, params) {
|
|
|
9222
9702
|
...normalizeParams(params),
|
|
9223
9703
|
});
|
|
9224
9704
|
}
|
|
9705
|
+
// @__NO_SIDE_EFFECTS__
|
|
9225
9706
|
function _cuid(Class, params) {
|
|
9226
9707
|
return new Class({
|
|
9227
9708
|
type: "string",
|
|
@@ -9231,6 +9712,7 @@ function _cuid(Class, params) {
|
|
|
9231
9712
|
...normalizeParams(params),
|
|
9232
9713
|
});
|
|
9233
9714
|
}
|
|
9715
|
+
// @__NO_SIDE_EFFECTS__
|
|
9234
9716
|
function _cuid2(Class, params) {
|
|
9235
9717
|
return new Class({
|
|
9236
9718
|
type: "string",
|
|
@@ -9240,6 +9722,7 @@ function _cuid2(Class, params) {
|
|
|
9240
9722
|
...normalizeParams(params),
|
|
9241
9723
|
});
|
|
9242
9724
|
}
|
|
9725
|
+
// @__NO_SIDE_EFFECTS__
|
|
9243
9726
|
function _ulid(Class, params) {
|
|
9244
9727
|
return new Class({
|
|
9245
9728
|
type: "string",
|
|
@@ -9249,6 +9732,7 @@ function _ulid(Class, params) {
|
|
|
9249
9732
|
...normalizeParams(params),
|
|
9250
9733
|
});
|
|
9251
9734
|
}
|
|
9735
|
+
// @__NO_SIDE_EFFECTS__
|
|
9252
9736
|
function _xid(Class, params) {
|
|
9253
9737
|
return new Class({
|
|
9254
9738
|
type: "string",
|
|
@@ -9258,6 +9742,7 @@ function _xid(Class, params) {
|
|
|
9258
9742
|
...normalizeParams(params),
|
|
9259
9743
|
});
|
|
9260
9744
|
}
|
|
9745
|
+
// @__NO_SIDE_EFFECTS__
|
|
9261
9746
|
function _ksuid(Class, params) {
|
|
9262
9747
|
return new Class({
|
|
9263
9748
|
type: "string",
|
|
@@ -9267,6 +9752,7 @@ function _ksuid(Class, params) {
|
|
|
9267
9752
|
...normalizeParams(params),
|
|
9268
9753
|
});
|
|
9269
9754
|
}
|
|
9755
|
+
// @__NO_SIDE_EFFECTS__
|
|
9270
9756
|
function _ipv4(Class, params) {
|
|
9271
9757
|
return new Class({
|
|
9272
9758
|
type: "string",
|
|
@@ -9276,6 +9762,7 @@ function _ipv4(Class, params) {
|
|
|
9276
9762
|
...normalizeParams(params),
|
|
9277
9763
|
});
|
|
9278
9764
|
}
|
|
9765
|
+
// @__NO_SIDE_EFFECTS__
|
|
9279
9766
|
function _ipv6(Class, params) {
|
|
9280
9767
|
return new Class({
|
|
9281
9768
|
type: "string",
|
|
@@ -9285,6 +9772,7 @@ function _ipv6(Class, params) {
|
|
|
9285
9772
|
...normalizeParams(params),
|
|
9286
9773
|
});
|
|
9287
9774
|
}
|
|
9775
|
+
// @__NO_SIDE_EFFECTS__
|
|
9288
9776
|
function _cidrv4(Class, params) {
|
|
9289
9777
|
return new Class({
|
|
9290
9778
|
type: "string",
|
|
@@ -9294,6 +9782,7 @@ function _cidrv4(Class, params) {
|
|
|
9294
9782
|
...normalizeParams(params),
|
|
9295
9783
|
});
|
|
9296
9784
|
}
|
|
9785
|
+
// @__NO_SIDE_EFFECTS__
|
|
9297
9786
|
function _cidrv6(Class, params) {
|
|
9298
9787
|
return new Class({
|
|
9299
9788
|
type: "string",
|
|
@@ -9303,6 +9792,7 @@ function _cidrv6(Class, params) {
|
|
|
9303
9792
|
...normalizeParams(params),
|
|
9304
9793
|
});
|
|
9305
9794
|
}
|
|
9795
|
+
// @__NO_SIDE_EFFECTS__
|
|
9306
9796
|
function _base64(Class, params) {
|
|
9307
9797
|
return new Class({
|
|
9308
9798
|
type: "string",
|
|
@@ -9312,6 +9802,7 @@ function _base64(Class, params) {
|
|
|
9312
9802
|
...normalizeParams(params),
|
|
9313
9803
|
});
|
|
9314
9804
|
}
|
|
9805
|
+
// @__NO_SIDE_EFFECTS__
|
|
9315
9806
|
function _base64url(Class, params) {
|
|
9316
9807
|
return new Class({
|
|
9317
9808
|
type: "string",
|
|
@@ -9321,6 +9812,7 @@ function _base64url(Class, params) {
|
|
|
9321
9812
|
...normalizeParams(params),
|
|
9322
9813
|
});
|
|
9323
9814
|
}
|
|
9815
|
+
// @__NO_SIDE_EFFECTS__
|
|
9324
9816
|
function _e164(Class, params) {
|
|
9325
9817
|
return new Class({
|
|
9326
9818
|
type: "string",
|
|
@@ -9330,6 +9822,7 @@ function _e164(Class, params) {
|
|
|
9330
9822
|
...normalizeParams(params),
|
|
9331
9823
|
});
|
|
9332
9824
|
}
|
|
9825
|
+
// @__NO_SIDE_EFFECTS__
|
|
9333
9826
|
function _jwt(Class, params) {
|
|
9334
9827
|
return new Class({
|
|
9335
9828
|
type: "string",
|
|
@@ -9339,6 +9832,7 @@ function _jwt(Class, params) {
|
|
|
9339
9832
|
...normalizeParams(params),
|
|
9340
9833
|
});
|
|
9341
9834
|
}
|
|
9835
|
+
// @__NO_SIDE_EFFECTS__
|
|
9342
9836
|
function _isoDateTime(Class, params) {
|
|
9343
9837
|
return new Class({
|
|
9344
9838
|
type: "string",
|
|
@@ -9350,6 +9844,7 @@ function _isoDateTime(Class, params) {
|
|
|
9350
9844
|
...normalizeParams(params),
|
|
9351
9845
|
});
|
|
9352
9846
|
}
|
|
9847
|
+
// @__NO_SIDE_EFFECTS__
|
|
9353
9848
|
function _isoDate(Class, params) {
|
|
9354
9849
|
return new Class({
|
|
9355
9850
|
type: "string",
|
|
@@ -9358,6 +9853,7 @@ function _isoDate(Class, params) {
|
|
|
9358
9853
|
...normalizeParams(params),
|
|
9359
9854
|
});
|
|
9360
9855
|
}
|
|
9856
|
+
// @__NO_SIDE_EFFECTS__
|
|
9361
9857
|
function _isoTime(Class, params) {
|
|
9362
9858
|
return new Class({
|
|
9363
9859
|
type: "string",
|
|
@@ -9367,6 +9863,7 @@ function _isoTime(Class, params) {
|
|
|
9367
9863
|
...normalizeParams(params),
|
|
9368
9864
|
});
|
|
9369
9865
|
}
|
|
9866
|
+
// @__NO_SIDE_EFFECTS__
|
|
9370
9867
|
function _isoDuration(Class, params) {
|
|
9371
9868
|
return new Class({
|
|
9372
9869
|
type: "string",
|
|
@@ -9375,6 +9872,7 @@ function _isoDuration(Class, params) {
|
|
|
9375
9872
|
...normalizeParams(params),
|
|
9376
9873
|
});
|
|
9377
9874
|
}
|
|
9875
|
+
// @__NO_SIDE_EFFECTS__
|
|
9378
9876
|
function _number(Class, params) {
|
|
9379
9877
|
return new Class({
|
|
9380
9878
|
type: "number",
|
|
@@ -9382,6 +9880,7 @@ function _number(Class, params) {
|
|
|
9382
9880
|
...normalizeParams(params),
|
|
9383
9881
|
});
|
|
9384
9882
|
}
|
|
9883
|
+
// @__NO_SIDE_EFFECTS__
|
|
9385
9884
|
function _int(Class, params) {
|
|
9386
9885
|
return new Class({
|
|
9387
9886
|
type: "number",
|
|
@@ -9391,28 +9890,33 @@ function _int(Class, params) {
|
|
|
9391
9890
|
...normalizeParams(params),
|
|
9392
9891
|
});
|
|
9393
9892
|
}
|
|
9893
|
+
// @__NO_SIDE_EFFECTS__
|
|
9394
9894
|
function _boolean(Class, params) {
|
|
9395
9895
|
return new Class({
|
|
9396
9896
|
type: "boolean",
|
|
9397
9897
|
...normalizeParams(params),
|
|
9398
9898
|
});
|
|
9399
9899
|
}
|
|
9900
|
+
// @__NO_SIDE_EFFECTS__
|
|
9400
9901
|
function _any(Class) {
|
|
9401
9902
|
return new Class({
|
|
9402
9903
|
type: "any",
|
|
9403
9904
|
});
|
|
9404
9905
|
}
|
|
9906
|
+
// @__NO_SIDE_EFFECTS__
|
|
9405
9907
|
function _unknown(Class) {
|
|
9406
9908
|
return new Class({
|
|
9407
9909
|
type: "unknown",
|
|
9408
9910
|
});
|
|
9409
9911
|
}
|
|
9912
|
+
// @__NO_SIDE_EFFECTS__
|
|
9410
9913
|
function _never(Class, params) {
|
|
9411
9914
|
return new Class({
|
|
9412
9915
|
type: "never",
|
|
9413
9916
|
...normalizeParams(params),
|
|
9414
9917
|
});
|
|
9415
9918
|
}
|
|
9919
|
+
// @__NO_SIDE_EFFECTS__
|
|
9416
9920
|
function _lt(value, params) {
|
|
9417
9921
|
return new $ZodCheckLessThan({
|
|
9418
9922
|
check: "less_than",
|
|
@@ -9421,6 +9925,7 @@ function _lt(value, params) {
|
|
|
9421
9925
|
inclusive: false,
|
|
9422
9926
|
});
|
|
9423
9927
|
}
|
|
9928
|
+
// @__NO_SIDE_EFFECTS__
|
|
9424
9929
|
function _lte(value, params) {
|
|
9425
9930
|
return new $ZodCheckLessThan({
|
|
9426
9931
|
check: "less_than",
|
|
@@ -9429,6 +9934,7 @@ function _lte(value, params) {
|
|
|
9429
9934
|
inclusive: true,
|
|
9430
9935
|
});
|
|
9431
9936
|
}
|
|
9937
|
+
// @__NO_SIDE_EFFECTS__
|
|
9432
9938
|
function _gt(value, params) {
|
|
9433
9939
|
return new $ZodCheckGreaterThan({
|
|
9434
9940
|
check: "greater_than",
|
|
@@ -9437,6 +9943,7 @@ function _gt(value, params) {
|
|
|
9437
9943
|
inclusive: false,
|
|
9438
9944
|
});
|
|
9439
9945
|
}
|
|
9946
|
+
// @__NO_SIDE_EFFECTS__
|
|
9440
9947
|
function _gte(value, params) {
|
|
9441
9948
|
return new $ZodCheckGreaterThan({
|
|
9442
9949
|
check: "greater_than",
|
|
@@ -9445,6 +9952,7 @@ function _gte(value, params) {
|
|
|
9445
9952
|
inclusive: true,
|
|
9446
9953
|
});
|
|
9447
9954
|
}
|
|
9955
|
+
// @__NO_SIDE_EFFECTS__
|
|
9448
9956
|
function _multipleOf(value, params) {
|
|
9449
9957
|
return new $ZodCheckMultipleOf({
|
|
9450
9958
|
check: "multiple_of",
|
|
@@ -9452,6 +9960,7 @@ function _multipleOf(value, params) {
|
|
|
9452
9960
|
value,
|
|
9453
9961
|
});
|
|
9454
9962
|
}
|
|
9963
|
+
// @__NO_SIDE_EFFECTS__
|
|
9455
9964
|
function _maxLength(maximum, params) {
|
|
9456
9965
|
const ch = new $ZodCheckMaxLength({
|
|
9457
9966
|
check: "max_length",
|
|
@@ -9460,6 +9969,7 @@ function _maxLength(maximum, params) {
|
|
|
9460
9969
|
});
|
|
9461
9970
|
return ch;
|
|
9462
9971
|
}
|
|
9972
|
+
// @__NO_SIDE_EFFECTS__
|
|
9463
9973
|
function _minLength(minimum, params) {
|
|
9464
9974
|
return new $ZodCheckMinLength({
|
|
9465
9975
|
check: "min_length",
|
|
@@ -9467,6 +9977,7 @@ function _minLength(minimum, params) {
|
|
|
9467
9977
|
minimum,
|
|
9468
9978
|
});
|
|
9469
9979
|
}
|
|
9980
|
+
// @__NO_SIDE_EFFECTS__
|
|
9470
9981
|
function _length(length, params) {
|
|
9471
9982
|
return new $ZodCheckLengthEquals({
|
|
9472
9983
|
check: "length_equals",
|
|
@@ -9474,6 +9985,7 @@ function _length(length, params) {
|
|
|
9474
9985
|
length,
|
|
9475
9986
|
});
|
|
9476
9987
|
}
|
|
9988
|
+
// @__NO_SIDE_EFFECTS__
|
|
9477
9989
|
function _regex(pattern, params) {
|
|
9478
9990
|
return new $ZodCheckRegex({
|
|
9479
9991
|
check: "string_format",
|
|
@@ -9482,6 +9994,7 @@ function _regex(pattern, params) {
|
|
|
9482
9994
|
pattern,
|
|
9483
9995
|
});
|
|
9484
9996
|
}
|
|
9997
|
+
// @__NO_SIDE_EFFECTS__
|
|
9485
9998
|
function _lowercase(params) {
|
|
9486
9999
|
return new $ZodCheckLowerCase({
|
|
9487
10000
|
check: "string_format",
|
|
@@ -9489,6 +10002,7 @@ function _lowercase(params) {
|
|
|
9489
10002
|
...normalizeParams(params),
|
|
9490
10003
|
});
|
|
9491
10004
|
}
|
|
10005
|
+
// @__NO_SIDE_EFFECTS__
|
|
9492
10006
|
function _uppercase(params) {
|
|
9493
10007
|
return new $ZodCheckUpperCase({
|
|
9494
10008
|
check: "string_format",
|
|
@@ -9496,6 +10010,7 @@ function _uppercase(params) {
|
|
|
9496
10010
|
...normalizeParams(params),
|
|
9497
10011
|
});
|
|
9498
10012
|
}
|
|
10013
|
+
// @__NO_SIDE_EFFECTS__
|
|
9499
10014
|
function _includes(includes, params) {
|
|
9500
10015
|
return new $ZodCheckIncludes({
|
|
9501
10016
|
check: "string_format",
|
|
@@ -9504,6 +10019,7 @@ function _includes(includes, params) {
|
|
|
9504
10019
|
includes,
|
|
9505
10020
|
});
|
|
9506
10021
|
}
|
|
10022
|
+
// @__NO_SIDE_EFFECTS__
|
|
9507
10023
|
function _startsWith(prefix, params) {
|
|
9508
10024
|
return new $ZodCheckStartsWith({
|
|
9509
10025
|
check: "string_format",
|
|
@@ -9512,6 +10028,7 @@ function _startsWith(prefix, params) {
|
|
|
9512
10028
|
prefix,
|
|
9513
10029
|
});
|
|
9514
10030
|
}
|
|
10031
|
+
// @__NO_SIDE_EFFECTS__
|
|
9515
10032
|
function _endsWith(suffix, params) {
|
|
9516
10033
|
return new $ZodCheckEndsWith({
|
|
9517
10034
|
check: "string_format",
|
|
@@ -9520,6 +10037,7 @@ function _endsWith(suffix, params) {
|
|
|
9520
10037
|
suffix,
|
|
9521
10038
|
});
|
|
9522
10039
|
}
|
|
10040
|
+
// @__NO_SIDE_EFFECTS__
|
|
9523
10041
|
function _overwrite(tx) {
|
|
9524
10042
|
return new $ZodCheckOverwrite({
|
|
9525
10043
|
check: "overwrite",
|
|
@@ -9527,25 +10045,31 @@ function _overwrite(tx) {
|
|
|
9527
10045
|
});
|
|
9528
10046
|
}
|
|
9529
10047
|
// normalize
|
|
10048
|
+
// @__NO_SIDE_EFFECTS__
|
|
9530
10049
|
function _normalize(form) {
|
|
9531
10050
|
return _overwrite((input) => input.normalize(form));
|
|
9532
10051
|
}
|
|
9533
10052
|
// trim
|
|
10053
|
+
// @__NO_SIDE_EFFECTS__
|
|
9534
10054
|
function _trim() {
|
|
9535
10055
|
return _overwrite((input) => input.trim());
|
|
9536
10056
|
}
|
|
9537
10057
|
// toLowerCase
|
|
10058
|
+
// @__NO_SIDE_EFFECTS__
|
|
9538
10059
|
function _toLowerCase() {
|
|
9539
10060
|
return _overwrite((input) => input.toLowerCase());
|
|
9540
10061
|
}
|
|
9541
10062
|
// toUpperCase
|
|
10063
|
+
// @__NO_SIDE_EFFECTS__
|
|
9542
10064
|
function _toUpperCase() {
|
|
9543
10065
|
return _overwrite((input) => input.toUpperCase());
|
|
9544
10066
|
}
|
|
9545
10067
|
// slugify
|
|
10068
|
+
// @__NO_SIDE_EFFECTS__
|
|
9546
10069
|
function _slugify() {
|
|
9547
10070
|
return _overwrite((input) => slugify(input));
|
|
9548
10071
|
}
|
|
10072
|
+
// @__NO_SIDE_EFFECTS__
|
|
9549
10073
|
function _array(Class, element, params) {
|
|
9550
10074
|
return new Class({
|
|
9551
10075
|
type: "array",
|
|
@@ -9557,6 +10081,7 @@ function _array(Class, element, params) {
|
|
|
9557
10081
|
});
|
|
9558
10082
|
}
|
|
9559
10083
|
// same as _custom but defaults to abort:false
|
|
10084
|
+
// @__NO_SIDE_EFFECTS__
|
|
9560
10085
|
function _refine(Class, fn, _params) {
|
|
9561
10086
|
const schema = new Class({
|
|
9562
10087
|
type: "custom",
|
|
@@ -9566,6 +10091,7 @@ function _refine(Class, fn, _params) {
|
|
|
9566
10091
|
});
|
|
9567
10092
|
return schema;
|
|
9568
10093
|
}
|
|
10094
|
+
// @__NO_SIDE_EFFECTS__
|
|
9569
10095
|
function _superRefine(fn) {
|
|
9570
10096
|
const ch = _check((payload) => {
|
|
9571
10097
|
payload.addIssue = (issue$1) => {
|
|
@@ -9588,6 +10114,7 @@ function _superRefine(fn) {
|
|
|
9588
10114
|
});
|
|
9589
10115
|
return ch;
|
|
9590
10116
|
}
|
|
10117
|
+
// @__NO_SIDE_EFFECTS__
|
|
9591
10118
|
function _check(fn, params) {
|
|
9592
10119
|
const ch = new $ZodCheck({
|
|
9593
10120
|
check: "custom",
|
|
@@ -9654,14 +10181,7 @@ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
|
9654
10181
|
schemaPath: [..._params.schemaPath, schema],
|
|
9655
10182
|
path: _params.path,
|
|
9656
10183
|
};
|
|
9657
|
-
|
|
9658
|
-
if (parent) {
|
|
9659
|
-
// schema was cloned from another schema
|
|
9660
|
-
result.ref = parent;
|
|
9661
|
-
process$1(parent, ctx, params);
|
|
9662
|
-
ctx.seen.get(parent).isParent = true;
|
|
9663
|
-
}
|
|
9664
|
-
else if (schema._zod.processJSONSchema) {
|
|
10184
|
+
if (schema._zod.processJSONSchema) {
|
|
9665
10185
|
schema._zod.processJSONSchema(ctx, result.schema, params);
|
|
9666
10186
|
}
|
|
9667
10187
|
else {
|
|
@@ -9672,6 +10192,14 @@ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
|
9672
10192
|
}
|
|
9673
10193
|
processor(schema, ctx, _json, params);
|
|
9674
10194
|
}
|
|
10195
|
+
const parent = schema._zod.parent;
|
|
10196
|
+
if (parent) {
|
|
10197
|
+
// Also set ref if processor didn't (for inheritance)
|
|
10198
|
+
if (!result.ref)
|
|
10199
|
+
result.ref = parent;
|
|
10200
|
+
process$1(parent, ctx, params);
|
|
10201
|
+
ctx.seen.get(parent).isParent = true;
|
|
10202
|
+
}
|
|
9675
10203
|
}
|
|
9676
10204
|
// metadata
|
|
9677
10205
|
const meta = ctx.metadataRegistry.get(schema);
|
|
@@ -9697,6 +10225,18 @@ function extractDefs(ctx, schema
|
|
|
9697
10225
|
const root = ctx.seen.get(schema);
|
|
9698
10226
|
if (!root)
|
|
9699
10227
|
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
10228
|
+
// Track ids to detect duplicates across different schemas
|
|
10229
|
+
const idToSchema = new Map();
|
|
10230
|
+
for (const entry of ctx.seen.entries()) {
|
|
10231
|
+
const id = ctx.metadataRegistry.get(entry[0])?.id;
|
|
10232
|
+
if (id) {
|
|
10233
|
+
const existing = idToSchema.get(id);
|
|
10234
|
+
if (existing && existing !== entry[0]) {
|
|
10235
|
+
throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
|
|
10236
|
+
}
|
|
10237
|
+
idToSchema.set(id, entry[0]);
|
|
10238
|
+
}
|
|
10239
|
+
}
|
|
9700
10240
|
// returns a ref to the schema
|
|
9701
10241
|
// defId will be empty if the ref points to an external schema (or #)
|
|
9702
10242
|
const makeURI = (entry) => {
|
|
@@ -9798,43 +10338,84 @@ function extractDefs(ctx, schema
|
|
|
9798
10338
|
}
|
|
9799
10339
|
}
|
|
9800
10340
|
function finalize(ctx, schema) {
|
|
9801
|
-
//
|
|
9802
|
-
// iterate over seen map;
|
|
9803
10341
|
const root = ctx.seen.get(schema);
|
|
9804
10342
|
if (!root)
|
|
9805
10343
|
throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
9806
|
-
// flatten
|
|
10344
|
+
// flatten refs - inherit properties from parent schemas
|
|
9807
10345
|
const flattenRef = (zodSchema) => {
|
|
9808
10346
|
const seen = ctx.seen.get(zodSchema);
|
|
10347
|
+
// already processed
|
|
10348
|
+
if (seen.ref === null)
|
|
10349
|
+
return;
|
|
9809
10350
|
const schema = seen.def ?? seen.schema;
|
|
9810
10351
|
const _cached = { ...schema };
|
|
9811
|
-
// already seen
|
|
9812
|
-
if (seen.ref === null) {
|
|
9813
|
-
return;
|
|
9814
|
-
}
|
|
9815
|
-
// flatten ref if defined
|
|
9816
10352
|
const ref = seen.ref;
|
|
9817
|
-
seen.ref = null; // prevent recursion
|
|
10353
|
+
seen.ref = null; // prevent infinite recursion
|
|
9818
10354
|
if (ref) {
|
|
9819
10355
|
flattenRef(ref);
|
|
10356
|
+
const refSeen = ctx.seen.get(ref);
|
|
10357
|
+
const refSchema = refSeen.schema;
|
|
9820
10358
|
// merge referenced schema into current
|
|
9821
|
-
const refSchema = ctx.seen.get(ref).schema;
|
|
9822
10359
|
if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
|
|
10360
|
+
// older drafts can't combine $ref with other properties
|
|
9823
10361
|
schema.allOf = schema.allOf ?? [];
|
|
9824
10362
|
schema.allOf.push(refSchema);
|
|
9825
10363
|
}
|
|
9826
10364
|
else {
|
|
9827
10365
|
Object.assign(schema, refSchema);
|
|
9828
|
-
|
|
10366
|
+
}
|
|
10367
|
+
// restore child's own properties (child wins)
|
|
10368
|
+
Object.assign(schema, _cached);
|
|
10369
|
+
const isParentRef = zodSchema._zod.parent === ref;
|
|
10370
|
+
// For parent chain, child is a refinement - remove parent-only properties
|
|
10371
|
+
if (isParentRef) {
|
|
10372
|
+
for (const key in schema) {
|
|
10373
|
+
if (key === "$ref" || key === "allOf")
|
|
10374
|
+
continue;
|
|
10375
|
+
if (!(key in _cached)) {
|
|
10376
|
+
delete schema[key];
|
|
10377
|
+
}
|
|
10378
|
+
}
|
|
10379
|
+
}
|
|
10380
|
+
// When ref was extracted to $defs, remove properties that match the definition
|
|
10381
|
+
if (refSchema.$ref) {
|
|
10382
|
+
for (const key in schema) {
|
|
10383
|
+
if (key === "$ref" || key === "allOf")
|
|
10384
|
+
continue;
|
|
10385
|
+
if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) {
|
|
10386
|
+
delete schema[key];
|
|
10387
|
+
}
|
|
10388
|
+
}
|
|
10389
|
+
}
|
|
10390
|
+
}
|
|
10391
|
+
// If parent was extracted (has $ref), propagate $ref to this schema
|
|
10392
|
+
// This handles cases like: readonly().meta({id}).describe()
|
|
10393
|
+
// where processor sets ref to innerType but parent should be referenced
|
|
10394
|
+
const parent = zodSchema._zod.parent;
|
|
10395
|
+
if (parent && parent !== ref) {
|
|
10396
|
+
// Ensure parent is processed first so its def has inherited properties
|
|
10397
|
+
flattenRef(parent);
|
|
10398
|
+
const parentSeen = ctx.seen.get(parent);
|
|
10399
|
+
if (parentSeen?.schema.$ref) {
|
|
10400
|
+
schema.$ref = parentSeen.schema.$ref;
|
|
10401
|
+
// De-duplicate with parent's definition
|
|
10402
|
+
if (parentSeen.def) {
|
|
10403
|
+
for (const key in schema) {
|
|
10404
|
+
if (key === "$ref" || key === "allOf")
|
|
10405
|
+
continue;
|
|
10406
|
+
if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) {
|
|
10407
|
+
delete schema[key];
|
|
10408
|
+
}
|
|
10409
|
+
}
|
|
10410
|
+
}
|
|
9829
10411
|
}
|
|
9830
10412
|
}
|
|
9831
10413
|
// execute overrides
|
|
9832
|
-
|
|
9833
|
-
|
|
9834
|
-
|
|
9835
|
-
|
|
9836
|
-
|
|
9837
|
-
});
|
|
10414
|
+
ctx.override({
|
|
10415
|
+
zodSchema: zodSchema,
|
|
10416
|
+
jsonSchema: schema,
|
|
10417
|
+
path: seen.path ?? [],
|
|
10418
|
+
});
|
|
9838
10419
|
};
|
|
9839
10420
|
for (const entry of [...ctx.seen.entries()].reverse()) {
|
|
9840
10421
|
flattenRef(entry[0]);
|
|
@@ -9887,8 +10468,8 @@ function finalize(ctx, schema) {
|
|
|
9887
10468
|
value: {
|
|
9888
10469
|
...schema["~standard"],
|
|
9889
10470
|
jsonSchema: {
|
|
9890
|
-
input: createStandardJSONSchemaMethod(schema, "input"),
|
|
9891
|
-
output: createStandardJSONSchemaMethod(schema, "output"),
|
|
10471
|
+
input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
|
|
10472
|
+
output: createStandardJSONSchemaMethod(schema, "output", ctx.processors),
|
|
9892
10473
|
},
|
|
9893
10474
|
},
|
|
9894
10475
|
enumerable: false,
|
|
@@ -9967,9 +10548,9 @@ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
|
9967
10548
|
extractDefs(ctx, schema);
|
|
9968
10549
|
return finalize(ctx, schema);
|
|
9969
10550
|
};
|
|
9970
|
-
const createStandardJSONSchemaMethod = (schema, io) => (params) => {
|
|
10551
|
+
const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
|
|
9971
10552
|
const { libraryOptions, target } = params ?? {};
|
|
9972
|
-
const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors
|
|
10553
|
+
const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors });
|
|
9973
10554
|
process$1(schema, ctx);
|
|
9974
10555
|
extractDefs(ctx, schema);
|
|
9975
10556
|
return finalize(ctx, schema);
|
|
@@ -9997,6 +10578,11 @@ const stringProcessor = (schema, ctx, _json, _params) => {
|
|
|
9997
10578
|
json.format = formatMap[format] ?? format;
|
|
9998
10579
|
if (json.format === "")
|
|
9999
10580
|
delete json.format; // empty format is not valid
|
|
10581
|
+
// JSON Schema format: "time" requires a full time with offset or Z
|
|
10582
|
+
// z.iso.time() does not include timezone information, so format: "time" should never be used
|
|
10583
|
+
if (format === "time") {
|
|
10584
|
+
delete json.format;
|
|
10585
|
+
}
|
|
10000
10586
|
}
|
|
10001
10587
|
if (contentEncoding)
|
|
10002
10588
|
json.contentEncoding = contentEncoding;
|
|
@@ -10358,8 +10944,11 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
|
10358
10944
|
...(def.checks ?? []),
|
|
10359
10945
|
...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
|
|
10360
10946
|
],
|
|
10361
|
-
})
|
|
10947
|
+
}), {
|
|
10948
|
+
parent: true,
|
|
10949
|
+
});
|
|
10362
10950
|
};
|
|
10951
|
+
inst.with = inst.check;
|
|
10363
10952
|
inst.clone = (def, params) => clone(inst, def, params);
|
|
10364
10953
|
inst.brand = () => inst;
|
|
10365
10954
|
inst.register = ((reg, meta) => {
|
|
@@ -10387,6 +10976,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
|
10387
10976
|
inst.overwrite = (fn) => inst.check(_overwrite(fn));
|
|
10388
10977
|
// wrappers
|
|
10389
10978
|
inst.optional = () => optional(inst);
|
|
10979
|
+
inst.exactOptional = () => exactOptional(inst);
|
|
10390
10980
|
inst.nullable = () => nullable(inst);
|
|
10391
10981
|
inst.nullish = () => optional(nullable(inst));
|
|
10392
10982
|
inst.nonoptional = (params) => nonoptional(inst, params);
|
|
@@ -10423,6 +11013,7 @@ const ZodType = /*@__PURE__*/ $constructor("ZodType", (inst, def) => {
|
|
|
10423
11013
|
// helpers
|
|
10424
11014
|
inst.isOptional = () => inst.safeParse(undefined).success;
|
|
10425
11015
|
inst.isNullable = () => inst.safeParse(null).success;
|
|
11016
|
+
inst.apply = (fn) => fn(inst);
|
|
10426
11017
|
return inst;
|
|
10427
11018
|
});
|
|
10428
11019
|
/** @internal */
|
|
@@ -10828,6 +11419,18 @@ function optional(innerType) {
|
|
|
10828
11419
|
innerType: innerType,
|
|
10829
11420
|
});
|
|
10830
11421
|
}
|
|
11422
|
+
const ZodExactOptional = /*@__PURE__*/ $constructor("ZodExactOptional", (inst, def) => {
|
|
11423
|
+
$ZodExactOptional.init(inst, def);
|
|
11424
|
+
ZodType.init(inst, def);
|
|
11425
|
+
inst._zod.processJSONSchema = (ctx, json, params) => optionalProcessor(inst, ctx, json, params);
|
|
11426
|
+
inst.unwrap = () => inst._zod.def.innerType;
|
|
11427
|
+
});
|
|
11428
|
+
function exactOptional(innerType) {
|
|
11429
|
+
return new ZodExactOptional({
|
|
11430
|
+
type: "optional",
|
|
11431
|
+
innerType: innerType,
|
|
11432
|
+
});
|
|
11433
|
+
}
|
|
10831
11434
|
const ZodNullable = /*@__PURE__*/ $constructor("ZodNullable", (inst, def) => {
|
|
10832
11435
|
$ZodNullable.init(inst, def);
|
|
10833
11436
|
ZodType.init(inst, def);
|
|
@@ -11124,6 +11727,7 @@ class QueryUtil {
|
|
|
11124
11727
|
* U - Route Context的扩展类型
|
|
11125
11728
|
*/
|
|
11126
11729
|
class App {
|
|
11730
|
+
appId;
|
|
11127
11731
|
router;
|
|
11128
11732
|
server;
|
|
11129
11733
|
constructor(opts) {
|
|
@@ -11142,6 +11746,13 @@ class App {
|
|
|
11142
11746
|
router.setContext({ needSerialize: true, ...opts?.routerContext });
|
|
11143
11747
|
this.router = router;
|
|
11144
11748
|
this.server = server;
|
|
11749
|
+
if (opts?.appId) {
|
|
11750
|
+
this.appId = opts.appId;
|
|
11751
|
+
}
|
|
11752
|
+
else {
|
|
11753
|
+
this.appId = nanoid$1(16);
|
|
11754
|
+
}
|
|
11755
|
+
router.appId = this.appId;
|
|
11145
11756
|
}
|
|
11146
11757
|
listen(...args) {
|
|
11147
11758
|
// @ts-ignore
|
|
@@ -11223,4 +11834,118 @@ class App {
|
|
|
11223
11834
|
}
|
|
11224
11835
|
}
|
|
11225
11836
|
|
|
11226
|
-
|
|
11837
|
+
const getRuntime = () => {
|
|
11838
|
+
// @ts-ignore
|
|
11839
|
+
if (typeof Deno !== 'undefined') {
|
|
11840
|
+
return { isDeno: true, engine: 'deno' };
|
|
11841
|
+
}
|
|
11842
|
+
// @ts-ignore
|
|
11843
|
+
if (typeof Bun !== 'undefined') {
|
|
11844
|
+
return { isBun: true, engine: 'bun' };
|
|
11845
|
+
}
|
|
11846
|
+
return { isNode: true, engine: 'node' };
|
|
11847
|
+
};
|
|
11848
|
+
|
|
11849
|
+
const glob = async (match = './*.ts', { cwd = process.cwd() } = {}) => {
|
|
11850
|
+
const fs = await import('node:fs');
|
|
11851
|
+
const path = await import('node:path');
|
|
11852
|
+
// 将 glob 模式转换为正则表达式
|
|
11853
|
+
const globToRegex = (pattern) => {
|
|
11854
|
+
const escaped = pattern
|
|
11855
|
+
.replace(/\./g, '\\.')
|
|
11856
|
+
.replace(/\*\*/g, '__DOUBLE_STAR__') // 临时替换 **
|
|
11857
|
+
.replace(/\*/g, '[^/]*') // * 匹配除 / 外的任意字符
|
|
11858
|
+
.replace(/__DOUBLE_STAR__/g, '.*') // ** 匹配任意字符包括 /
|
|
11859
|
+
.replace(/\?/g, '[^/]'); // ? 匹配除 / 外的单个字符
|
|
11860
|
+
return new RegExp(`^${escaped}$`);
|
|
11861
|
+
};
|
|
11862
|
+
// 递归读取目录
|
|
11863
|
+
const readDirRecursive = async (dir) => {
|
|
11864
|
+
const files = [];
|
|
11865
|
+
try {
|
|
11866
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
11867
|
+
for (const entry of entries) {
|
|
11868
|
+
const fullPath = path.join(dir, entry.name);
|
|
11869
|
+
if (entry.isFile()) {
|
|
11870
|
+
files.push(fullPath);
|
|
11871
|
+
}
|
|
11872
|
+
else if (entry.isDirectory()) {
|
|
11873
|
+
// 递归搜索子目录
|
|
11874
|
+
const subFiles = await readDirRecursive(fullPath);
|
|
11875
|
+
files.push(...subFiles);
|
|
11876
|
+
}
|
|
11877
|
+
}
|
|
11878
|
+
}
|
|
11879
|
+
catch (error) {
|
|
11880
|
+
// 忽略无法访问的目录
|
|
11881
|
+
}
|
|
11882
|
+
return files;
|
|
11883
|
+
};
|
|
11884
|
+
// 解析模式是否包含递归搜索
|
|
11885
|
+
const hasRecursive = match.includes('**');
|
|
11886
|
+
try {
|
|
11887
|
+
let allFiles = [];
|
|
11888
|
+
if (hasRecursive) {
|
|
11889
|
+
// 处理递归模式
|
|
11890
|
+
const basePath = match.split('**')[0];
|
|
11891
|
+
const startDir = path.resolve(cwd, basePath || '.');
|
|
11892
|
+
allFiles = await readDirRecursive(startDir);
|
|
11893
|
+
}
|
|
11894
|
+
else {
|
|
11895
|
+
// 处理非递归模式
|
|
11896
|
+
const dir = path.resolve(cwd, path.dirname(match));
|
|
11897
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
11898
|
+
for (const entry of entries) {
|
|
11899
|
+
if (entry.isFile()) {
|
|
11900
|
+
allFiles.push(path.join(dir, entry.name));
|
|
11901
|
+
}
|
|
11902
|
+
}
|
|
11903
|
+
}
|
|
11904
|
+
// 创建相对于 cwd 的匹配模式
|
|
11905
|
+
const normalizedMatch = path.resolve(cwd, match);
|
|
11906
|
+
const regex = globToRegex(normalizedMatch);
|
|
11907
|
+
// 过滤匹配的文件
|
|
11908
|
+
const matchedFiles = allFiles.filter(file => {
|
|
11909
|
+
const normalizedFile = path.resolve(file);
|
|
11910
|
+
return regex.test(normalizedFile);
|
|
11911
|
+
});
|
|
11912
|
+
return matchedFiles;
|
|
11913
|
+
}
|
|
11914
|
+
catch (error) {
|
|
11915
|
+
console.error(`Error in glob pattern "${match}":`, error);
|
|
11916
|
+
return [];
|
|
11917
|
+
}
|
|
11918
|
+
};
|
|
11919
|
+
|
|
11920
|
+
const getMatchFiles = async (match = './*.ts', { cwd = process.cwd() } = {}) => {
|
|
11921
|
+
const runtime = getRuntime();
|
|
11922
|
+
if (runtime.isNode) {
|
|
11923
|
+
console.error(`Node.js is not supported`);
|
|
11924
|
+
return [];
|
|
11925
|
+
}
|
|
11926
|
+
if (runtime.isDeno) {
|
|
11927
|
+
// Deno 环境下
|
|
11928
|
+
return await glob(match);
|
|
11929
|
+
}
|
|
11930
|
+
if (runtime.isBun) {
|
|
11931
|
+
// Bun 环境下
|
|
11932
|
+
// @ts-ignore
|
|
11933
|
+
const { Glob } = await import('bun');
|
|
11934
|
+
const path = await import('node:path');
|
|
11935
|
+
// @ts-ignore
|
|
11936
|
+
const glob = new Glob(match, { cwd, absolute: true, onlyFiles: true });
|
|
11937
|
+
const files = [];
|
|
11938
|
+
for await (const file of glob.scan('.')) {
|
|
11939
|
+
files.push(path.join(cwd, file));
|
|
11940
|
+
}
|
|
11941
|
+
// @ts-ignore
|
|
11942
|
+
return Array.from(files);
|
|
11943
|
+
}
|
|
11944
|
+
return [];
|
|
11945
|
+
};
|
|
11946
|
+
const loadTS = async (match = './*.ts', { cwd = process.cwd(), load } = {}) => {
|
|
11947
|
+
const files = await getMatchFiles(match, { cwd });
|
|
11948
|
+
return Promise.all(files.map((file) => (load ? load(file) : import(file))));
|
|
11949
|
+
};
|
|
11950
|
+
|
|
11951
|
+
export { App, Connect, CustomError, Mini, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, define, handleServer, loadTS, util };
|