ovr 7.0.0-next.2 → 7.0.0-next.21
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/CHANGELOG.md +1157 -0
- package/dist/auth/client-source.d.ts +2 -2
- package/dist/auth/client-source.d.ts.map +1 -1
- package/dist/auth/client-source.js +2 -2
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +7 -4
- package/dist/auth/configure.d.ts +21 -8
- package/dist/auth/configure.d.ts.map +1 -1
- package/dist/auth/configure.js +172 -6
- package/dist/auth/index.d.ts +48 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +19 -0
- package/dist/auth/passkey.d.ts +14 -2
- package/dist/auth/passkey.d.ts.map +1 -1
- package/dist/auth/passkey.js +18 -5
- package/dist/auth/state.d.ts +6 -0
- package/dist/auth/state.d.ts.map +1 -1
- package/dist/auth/state.js +28 -5
- package/dist/auth/storage.d.ts +38 -0
- package/dist/auth/storage.d.ts.map +1 -1
- package/dist/auth/storage.js +60 -3
- package/dist/context/index.d.ts +4 -4
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +6 -3
- package/dist/form/index.d.ts +239 -31
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +657 -66
- package/dist/markdown/index.d.ts +6 -1
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +180 -9
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +154 -57
- package/dist/schema/index.d.ts +88 -19
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +32 -11
- package/dist/util/index.d.ts +12 -0
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +19 -0
- package/package.json +2 -1
- package/src/auth/client-source.ts +2 -2
- package/src/auth/client.ts +7 -4
- package/src/auth/configure.ts +189 -13
- package/src/auth/index.ts +44 -0
- package/src/auth/passkey.ts +25 -7
- package/src/auth/state.ts +32 -7
- package/src/auth/storage.ts +66 -3
- package/src/context/index.ts +14 -6
- package/src/form/index.ts +1174 -195
- package/src/markdown/index.ts +203 -12
- package/src/mcp/index.ts +205 -72
- package/src/schema/index.ts +195 -52
- package/src/util/index.ts +23 -0
package/src/schema/index.ts
CHANGED
|
@@ -188,6 +188,12 @@ export namespace Schema {
|
|
|
188
188
|
| {
|
|
189
189
|
readonly type: "string" | "boolean" | "number" | "bigint" | "date";
|
|
190
190
|
readonly message?: string | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* A number's message when there is no value, where `message` is
|
|
193
|
+
* for a value that is not a number. A number field sets it, since
|
|
194
|
+
* text sent to it is not a field left empty.
|
|
195
|
+
*/
|
|
196
|
+
readonly missing?: string | undefined;
|
|
191
197
|
}
|
|
192
198
|
| {
|
|
193
199
|
readonly type: "literal";
|
|
@@ -747,7 +753,11 @@ export class Schema<Output>
|
|
|
747
753
|
return (v, path) =>
|
|
748
754
|
Number.isFinite(v) // isFinite checks type
|
|
749
755
|
? { data: v }
|
|
750
|
-
: Schema.#issue(
|
|
756
|
+
: Schema.#issue(
|
|
757
|
+
"number",
|
|
758
|
+
path,
|
|
759
|
+
(v === undefined && def.missing) || def.message,
|
|
760
|
+
);
|
|
751
761
|
case "date":
|
|
752
762
|
return (v, path) =>
|
|
753
763
|
v instanceof Date && !Number.isNaN(v.getTime())
|
|
@@ -924,7 +934,8 @@ export class Schema<Output>
|
|
|
924
934
|
*/
|
|
925
935
|
static #test(check: Schema.Check): (value: any) => boolean {
|
|
926
936
|
switch (check.name) {
|
|
927
|
-
// a string has between length / 2 and length code points, count only
|
|
937
|
+
// a string has between length / 2 and length code points, count only
|
|
938
|
+
// between. An array is checked by its number of items.
|
|
928
939
|
case "min": {
|
|
929
940
|
const min = Number(check.value);
|
|
930
941
|
|
|
@@ -932,7 +943,9 @@ export class Schema<Output>
|
|
|
932
943
|
typeof v === "string"
|
|
933
944
|
? v.length >= min * 2 ||
|
|
934
945
|
(v.length >= min && Schema.#length(v) >= min)
|
|
935
|
-
: v
|
|
946
|
+
: Array.isArray(v)
|
|
947
|
+
? v.length >= min
|
|
948
|
+
: v >= check.value;
|
|
936
949
|
}
|
|
937
950
|
case "max": {
|
|
938
951
|
const max = Number(check.value);
|
|
@@ -941,7 +954,9 @@ export class Schema<Output>
|
|
|
941
954
|
typeof v === "string"
|
|
942
955
|
? v.length <= max ||
|
|
943
956
|
(v.length <= max * 2 && Schema.#length(v) <= max)
|
|
944
|
-
: v
|
|
957
|
+
: Array.isArray(v)
|
|
958
|
+
? v.length <= max
|
|
959
|
+
: v <= check.value;
|
|
945
960
|
}
|
|
946
961
|
case "int":
|
|
947
962
|
return Number.isSafeInteger;
|
|
@@ -956,6 +971,20 @@ export class Schema<Output>
|
|
|
956
971
|
}
|
|
957
972
|
}
|
|
958
973
|
|
|
974
|
+
/**
|
|
975
|
+
* @param value Bound of `min()` or `max()`
|
|
976
|
+
* @returns The bound as people read it in a message: a string's is a
|
|
977
|
+
* number of characters, a number's or an array's stands alone
|
|
978
|
+
*/
|
|
979
|
+
#amount(value: number | bigint) {
|
|
980
|
+
let def: Schema.Def = this.def;
|
|
981
|
+
while ("inner" in def) def = def.inner.def;
|
|
982
|
+
|
|
983
|
+
return def.type === "string"
|
|
984
|
+
? `${value} character${Number(value) === 1 ? "" : "s"}`
|
|
985
|
+
: String(value);
|
|
986
|
+
}
|
|
987
|
+
|
|
959
988
|
/**
|
|
960
989
|
* @param value String
|
|
961
990
|
* @returns Number of Unicode code points, a surrogate pair counts once
|
|
@@ -1195,15 +1224,19 @@ export class Schema<Output>
|
|
|
1195
1224
|
if (typeof check.value !== "number") return;
|
|
1196
1225
|
|
|
1197
1226
|
const min = check.name === "min";
|
|
1198
|
-
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1227
|
+
// a string's length and an array's items are counted
|
|
1228
|
+
const length = schema.type === "string" || schema.type === "array";
|
|
1229
|
+
const key =
|
|
1230
|
+
schema.type === "string"
|
|
1231
|
+
? `${check.name}Length`
|
|
1232
|
+
: schema.type === "array"
|
|
1233
|
+
? `${check.name}Items`
|
|
1234
|
+
: (schema.type === "number" || schema.type === "integer") &&
|
|
1235
|
+
(min ? "minimum" : "maximum");
|
|
1203
1236
|
|
|
1204
1237
|
if (!key) return;
|
|
1205
1238
|
|
|
1206
|
-
//
|
|
1239
|
+
// counts are integers, so fractional bounds round inward
|
|
1207
1240
|
const value = length
|
|
1208
1241
|
? min
|
|
1209
1242
|
? Math.max(0, Math.ceil(check.value))
|
|
@@ -1291,15 +1324,17 @@ export class Schema<Output>
|
|
|
1291
1324
|
* @template T Field tag name
|
|
1292
1325
|
* @template U Field input type attribute
|
|
1293
1326
|
* @template V Field option values
|
|
1327
|
+
* @template I What each item of a list field is
|
|
1294
1328
|
* @returns Optional field
|
|
1295
1329
|
*/
|
|
1296
1330
|
optional<
|
|
1297
1331
|
T extends Field.Tag,
|
|
1298
1332
|
U extends Field.Type,
|
|
1299
1333
|
V extends Field.Options | undefined,
|
|
1334
|
+
I extends Field.Item | undefined,
|
|
1300
1335
|
>(
|
|
1301
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1302
|
-
): Field.Instance<Output | undefined, T, U, V>;
|
|
1336
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1337
|
+
): Field.Instance<Output | undefined, T, U, V, undefined, I>;
|
|
1303
1338
|
/**
|
|
1304
1339
|
* @returns Optional schema
|
|
1305
1340
|
*/
|
|
@@ -1312,15 +1347,17 @@ export class Schema<Output>
|
|
|
1312
1347
|
* @template T Field tag name
|
|
1313
1348
|
* @template U Field input type attribute
|
|
1314
1349
|
* @template V Field option values
|
|
1350
|
+
* @template I What each item of a list field is
|
|
1315
1351
|
* @returns Nullable field
|
|
1316
1352
|
*/
|
|
1317
1353
|
nullable<
|
|
1318
1354
|
T extends Field.Tag,
|
|
1319
1355
|
U extends Field.Type,
|
|
1320
1356
|
V extends Field.Options | undefined,
|
|
1357
|
+
I extends Field.Item | undefined,
|
|
1321
1358
|
>(
|
|
1322
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1323
|
-
): Field.Instance<Output | null, T, U, V>;
|
|
1359
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1360
|
+
): Field.Instance<Output | null, T, U, V, undefined, I>;
|
|
1324
1361
|
/**
|
|
1325
1362
|
* @returns Nullable schema
|
|
1326
1363
|
*/
|
|
@@ -1333,15 +1370,17 @@ export class Schema<Output>
|
|
|
1333
1370
|
* @template T Field tag name
|
|
1334
1371
|
* @template U Field input type attribute
|
|
1335
1372
|
* @template V Field option values
|
|
1373
|
+
* @template I What each item of a list field is
|
|
1336
1374
|
* @returns Nullish field
|
|
1337
1375
|
*/
|
|
1338
1376
|
nullish<
|
|
1339
1377
|
T extends Field.Tag,
|
|
1340
1378
|
U extends Field.Type,
|
|
1341
1379
|
V extends Field.Options | undefined,
|
|
1380
|
+
I extends Field.Item | undefined,
|
|
1342
1381
|
>(
|
|
1343
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1344
|
-
): Field.Instance<Output | null | undefined, T, U, V>;
|
|
1382
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1383
|
+
): Field.Instance<Output | null | undefined, T, U, V, undefined, I>;
|
|
1345
1384
|
/**
|
|
1346
1385
|
* @returns Nullish schema
|
|
1347
1386
|
*/
|
|
@@ -1357,6 +1396,7 @@ export class Schema<Output>
|
|
|
1357
1396
|
* @template T Field tag name
|
|
1358
1397
|
* @template U Field input type attribute
|
|
1359
1398
|
* @template V Field option values
|
|
1399
|
+
* @template I What each item of a list field is
|
|
1360
1400
|
* @param value Default value to use when input is undefined
|
|
1361
1401
|
* @returns Field with default
|
|
1362
1402
|
*/
|
|
@@ -1364,10 +1404,11 @@ export class Schema<Output>
|
|
|
1364
1404
|
T extends Field.Tag,
|
|
1365
1405
|
U extends Field.Type,
|
|
1366
1406
|
V extends Field.Options | undefined,
|
|
1407
|
+
I extends Field.Item | undefined,
|
|
1367
1408
|
>(
|
|
1368
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1409
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1369
1410
|
value: Output,
|
|
1370
|
-
): Field.Instance<Output, T, U, V>;
|
|
1411
|
+
): Field.Instance<Output, T, U, V, undefined, I>;
|
|
1371
1412
|
/**
|
|
1372
1413
|
* @param value Default value to use when input is undefined
|
|
1373
1414
|
* @returns Schema with default
|
|
@@ -1381,6 +1422,7 @@ export class Schema<Output>
|
|
|
1381
1422
|
* @template T Field tag name
|
|
1382
1423
|
* @template U Field input type attribute
|
|
1383
1424
|
* @template V Field option values
|
|
1425
|
+
* @template I What each item of a list field is
|
|
1384
1426
|
* @param fn Preprocess function to run before parsing
|
|
1385
1427
|
* @returns Schema that preprocesses input before parsing
|
|
1386
1428
|
*/
|
|
@@ -1388,10 +1430,11 @@ export class Schema<Output>
|
|
|
1388
1430
|
T extends Field.Tag,
|
|
1389
1431
|
U extends Field.Type,
|
|
1390
1432
|
V extends Field.Options | undefined,
|
|
1433
|
+
I extends Field.Item | undefined,
|
|
1391
1434
|
>(
|
|
1392
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1435
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1393
1436
|
fn: (value: unknown) => unknown,
|
|
1394
|
-
): Field.Instance<Output, T, U, V>;
|
|
1437
|
+
): Field.Instance<Output, T, U, V, undefined, I>;
|
|
1395
1438
|
/**
|
|
1396
1439
|
* @param fn Preprocess function to run before parsing
|
|
1397
1440
|
* @returns Schema that preprocesses input before parsing
|
|
@@ -1409,6 +1452,7 @@ export class Schema<Output>
|
|
|
1409
1452
|
* @template T Field tag name
|
|
1410
1453
|
* @template U Field input type attribute
|
|
1411
1454
|
* @template V Field option values
|
|
1455
|
+
* @template I What each item of a list field is
|
|
1412
1456
|
* @param fn Transform function to apply to parsed output
|
|
1413
1457
|
* @returns Transformed field
|
|
1414
1458
|
*/
|
|
@@ -1417,10 +1461,11 @@ export class Schema<Output>
|
|
|
1417
1461
|
T extends Field.Tag,
|
|
1418
1462
|
U extends Field.Type,
|
|
1419
1463
|
V extends Field.Options | undefined,
|
|
1464
|
+
I extends Field.Item | undefined,
|
|
1420
1465
|
>(
|
|
1421
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1466
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1422
1467
|
fn: (value: Output) => O,
|
|
1423
|
-
): Field.Instance<O, T, U, V>;
|
|
1468
|
+
): Field.Instance<O, T, U, V, undefined, I>;
|
|
1424
1469
|
/**
|
|
1425
1470
|
* @template O Output type after transformation
|
|
1426
1471
|
* @param fn Transform function to apply to parsed output
|
|
@@ -1436,6 +1481,7 @@ export class Schema<Output>
|
|
|
1436
1481
|
* @template T Field tag name
|
|
1437
1482
|
* @template U Field input type attribute
|
|
1438
1483
|
* @template V Field option values
|
|
1484
|
+
* @template I What each item of a list field is
|
|
1439
1485
|
* @param next Schema to validate the result with
|
|
1440
1486
|
* @returns Piped field
|
|
1441
1487
|
*/
|
|
@@ -1444,10 +1490,11 @@ export class Schema<Output>
|
|
|
1444
1490
|
T extends Field.Tag,
|
|
1445
1491
|
U extends Field.Type,
|
|
1446
1492
|
V extends Field.Options | undefined,
|
|
1493
|
+
I extends Field.Item | undefined,
|
|
1447
1494
|
>(
|
|
1448
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1495
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1449
1496
|
next: Schema<O>,
|
|
1450
|
-
): Field.Instance<O, T, U, V>;
|
|
1497
|
+
): Field.Instance<O, T, U, V, undefined, I>;
|
|
1451
1498
|
/**
|
|
1452
1499
|
* @template O Output type after pipe
|
|
1453
1500
|
* @param next Schema to validate the result with
|
|
@@ -1465,6 +1512,7 @@ export class Schema<Output>
|
|
|
1465
1512
|
* @template T Field tag name
|
|
1466
1513
|
* @template U Field input type attribute
|
|
1467
1514
|
* @template V Field option values
|
|
1515
|
+
* @template I What each item of a list field is
|
|
1468
1516
|
* @param schema Schema to validate the parsed JSON value with
|
|
1469
1517
|
* @param message Issue message when invalid
|
|
1470
1518
|
* @returns Parsed JSON field
|
|
@@ -1474,11 +1522,12 @@ export class Schema<Output>
|
|
|
1474
1522
|
T extends Field.Tag,
|
|
1475
1523
|
U extends Field.Type,
|
|
1476
1524
|
V extends Field.Options | undefined,
|
|
1525
|
+
I extends Field.Item | undefined,
|
|
1477
1526
|
>(
|
|
1478
|
-
this: Field.Instance<string, T, U, V>,
|
|
1527
|
+
this: Field.Instance<string, T, U, V, undefined, I>,
|
|
1479
1528
|
schema: Schema<O>,
|
|
1480
1529
|
message?: string,
|
|
1481
|
-
): Field.Instance<O, T, U, V>;
|
|
1530
|
+
): Field.Instance<O, T, U, V, undefined, I>;
|
|
1482
1531
|
/**
|
|
1483
1532
|
* Parse a JSON string and validate the parsed value with the provided schema.
|
|
1484
1533
|
*
|
|
@@ -1499,6 +1548,7 @@ export class Schema<Output>
|
|
|
1499
1548
|
* @template T Field tag name
|
|
1500
1549
|
* @template U Field input type attribute
|
|
1501
1550
|
* @template V Field option values
|
|
1551
|
+
* @template I What each item of a list field is
|
|
1502
1552
|
* @param message Issue message when invalid
|
|
1503
1553
|
* @returns Email field
|
|
1504
1554
|
*/
|
|
@@ -1506,10 +1556,11 @@ export class Schema<Output>
|
|
|
1506
1556
|
T extends Field.Tag,
|
|
1507
1557
|
U extends Field.Type,
|
|
1508
1558
|
V extends Field.Options | undefined,
|
|
1559
|
+
I extends Field.Item | undefined,
|
|
1509
1560
|
>(
|
|
1510
|
-
this: Field.Instance<string, T, U, V>,
|
|
1561
|
+
this: Field.Instance<string, T, U, V, undefined, I>,
|
|
1511
1562
|
message?: string,
|
|
1512
|
-
): Field.Instance<string, T, U, V>;
|
|
1563
|
+
): Field.Instance<string, T, U, V, undefined, I>;
|
|
1513
1564
|
/**
|
|
1514
1565
|
* Validate an input is a valid email string using
|
|
1515
1566
|
* [Reasonable Email Regex by Colin McDonnell](https://colinhacks.com/essays/reasonable-email-regex).
|
|
@@ -1528,6 +1579,7 @@ export class Schema<Output>
|
|
|
1528
1579
|
* @template T Field tag name
|
|
1529
1580
|
* @template U Field input type attribute
|
|
1530
1581
|
* @template V Field option values
|
|
1582
|
+
* @template I What each item of a list field is
|
|
1531
1583
|
* @param message Issue message when invalid
|
|
1532
1584
|
* @returns UUID field
|
|
1533
1585
|
*/
|
|
@@ -1535,10 +1587,11 @@ export class Schema<Output>
|
|
|
1535
1587
|
T extends Field.Tag,
|
|
1536
1588
|
U extends Field.Type,
|
|
1537
1589
|
V extends Field.Options | undefined,
|
|
1590
|
+
I extends Field.Item | undefined,
|
|
1538
1591
|
>(
|
|
1539
|
-
this: Field.Instance<string, T, U, V>,
|
|
1592
|
+
this: Field.Instance<string, T, U, V, undefined, I>,
|
|
1540
1593
|
message?: string,
|
|
1541
|
-
): Field.Instance<string, T, U, V>;
|
|
1594
|
+
): Field.Instance<string, T, U, V, undefined, I>;
|
|
1542
1595
|
/**
|
|
1543
1596
|
* Validate an input is a UUID string of any version.
|
|
1544
1597
|
*
|
|
@@ -1556,6 +1609,7 @@ export class Schema<Output>
|
|
|
1556
1609
|
* @template T Field tag name
|
|
1557
1610
|
* @template U Field input type attribute
|
|
1558
1611
|
* @template V Field option values
|
|
1612
|
+
* @template I What each item of a list field is
|
|
1559
1613
|
* @param message Issue message when invalid
|
|
1560
1614
|
* @returns URL field
|
|
1561
1615
|
*/
|
|
@@ -1563,10 +1617,11 @@ export class Schema<Output>
|
|
|
1563
1617
|
T extends Field.Tag,
|
|
1564
1618
|
U extends Field.Type,
|
|
1565
1619
|
V extends Field.Options | undefined,
|
|
1620
|
+
I extends Field.Item | undefined,
|
|
1566
1621
|
>(
|
|
1567
|
-
this: Field.Instance<string, T, U, V>,
|
|
1622
|
+
this: Field.Instance<string, T, U, V, undefined, I>,
|
|
1568
1623
|
message?: string,
|
|
1569
|
-
): Field.Instance<string, T, U, V>;
|
|
1624
|
+
): Field.Instance<string, T, U, V, undefined, I>;
|
|
1570
1625
|
/**
|
|
1571
1626
|
* Validate an input is a valid URL string.
|
|
1572
1627
|
*
|
|
@@ -1584,6 +1639,7 @@ export class Schema<Output>
|
|
|
1584
1639
|
* @template T Field tag name
|
|
1585
1640
|
* @template U Field input type attribute
|
|
1586
1641
|
* @template V Field option values
|
|
1642
|
+
* @template I What each item of a list field is
|
|
1587
1643
|
* @param message Issue message when invalid
|
|
1588
1644
|
* @returns Integer field
|
|
1589
1645
|
*/
|
|
@@ -1591,10 +1647,11 @@ export class Schema<Output>
|
|
|
1591
1647
|
T extends Field.Tag,
|
|
1592
1648
|
U extends Field.Type,
|
|
1593
1649
|
V extends Field.Options | undefined,
|
|
1650
|
+
I extends Field.Item | undefined,
|
|
1594
1651
|
>(
|
|
1595
|
-
this: Field.Instance<number, T, U, V>,
|
|
1652
|
+
this: Field.Instance<number, T, U, V, undefined, I>,
|
|
1596
1653
|
message?: string,
|
|
1597
|
-
): Field.Instance<number, T, U, V>;
|
|
1654
|
+
): Field.Instance<number, T, U, V, undefined, I>;
|
|
1598
1655
|
/**
|
|
1599
1656
|
* Validate an input is a safe integer.
|
|
1600
1657
|
*
|
|
@@ -1615,6 +1672,7 @@ export class Schema<Output>
|
|
|
1615
1672
|
* @template T Field tag name
|
|
1616
1673
|
* @template U Field input type attribute
|
|
1617
1674
|
* @template V Field option values
|
|
1675
|
+
* @template I What each item of a list field is
|
|
1618
1676
|
* @param value Minimum value or length
|
|
1619
1677
|
* @param message Issue message when invalid
|
|
1620
1678
|
* @returns Refined field
|
|
@@ -1623,17 +1681,19 @@ export class Schema<Output>
|
|
|
1623
1681
|
T extends Field.Tag,
|
|
1624
1682
|
U extends Field.Type,
|
|
1625
1683
|
V extends Field.Options | undefined,
|
|
1684
|
+
I extends Field.Item | undefined,
|
|
1626
1685
|
>(
|
|
1627
|
-
this: Field.Instance<string, T, U, V>,
|
|
1686
|
+
this: Field.Instance<string, T, U, V, undefined, I>,
|
|
1628
1687
|
value: number,
|
|
1629
1688
|
message?: string,
|
|
1630
|
-
): Field.Instance<string, T, U, V>;
|
|
1689
|
+
): Field.Instance<string, T, U, V, undefined, I>;
|
|
1631
1690
|
/**
|
|
1632
1691
|
* Validate an input is greater than or equal to the minimum.
|
|
1633
1692
|
*
|
|
1634
1693
|
* @template T Field tag name
|
|
1635
1694
|
* @template U Field input type attribute
|
|
1636
1695
|
* @template V Field option values
|
|
1696
|
+
* @template I What each item of a list field is
|
|
1637
1697
|
* @param value Minimum value
|
|
1638
1698
|
* @param message Issue message when invalid
|
|
1639
1699
|
* @returns Refined field
|
|
@@ -1642,17 +1702,19 @@ export class Schema<Output>
|
|
|
1642
1702
|
T extends Field.Tag,
|
|
1643
1703
|
U extends Field.Type,
|
|
1644
1704
|
V extends Field.Options | undefined,
|
|
1705
|
+
I extends Field.Item | undefined,
|
|
1645
1706
|
>(
|
|
1646
|
-
this: Field.Instance<number, T, U, V>,
|
|
1707
|
+
this: Field.Instance<number, T, U, V, undefined, I>,
|
|
1647
1708
|
value: number,
|
|
1648
1709
|
message?: string,
|
|
1649
|
-
): Field.Instance<number, T, U, V>;
|
|
1710
|
+
): Field.Instance<number, T, U, V, undefined, I>;
|
|
1650
1711
|
/**
|
|
1651
1712
|
* Validate an input is greater than or equal to the minimum.
|
|
1652
1713
|
*
|
|
1653
1714
|
* @template T Field tag name
|
|
1654
1715
|
* @template U Field input type attribute
|
|
1655
1716
|
* @template V Field option values
|
|
1717
|
+
* @template I What each item of a list field is
|
|
1656
1718
|
* @param value Minimum value
|
|
1657
1719
|
* @param message Issue message when invalid
|
|
1658
1720
|
* @returns Refined field
|
|
@@ -1661,11 +1723,12 @@ export class Schema<Output>
|
|
|
1661
1723
|
T extends Field.Tag,
|
|
1662
1724
|
U extends Field.Type,
|
|
1663
1725
|
V extends Field.Options | undefined,
|
|
1726
|
+
I extends Field.Item | undefined,
|
|
1664
1727
|
>(
|
|
1665
|
-
this: Field.Instance<bigint, T, U, V>,
|
|
1728
|
+
this: Field.Instance<bigint, T, U, V, undefined, I>,
|
|
1666
1729
|
value: bigint,
|
|
1667
1730
|
message?: string,
|
|
1668
|
-
): Field.Instance<bigint, T, U, V>;
|
|
1731
|
+
): Field.Instance<bigint, T, U, V, undefined, I>;
|
|
1669
1732
|
/**
|
|
1670
1733
|
* Validate an input is greater than or equal to the minimum.
|
|
1671
1734
|
*
|
|
@@ -1693,10 +1756,46 @@ export class Schema<Output>
|
|
|
1693
1756
|
* @returns Refined schema
|
|
1694
1757
|
*/
|
|
1695
1758
|
min(this: Schema<bigint>, value: bigint, message?: string): Schema<bigint>;
|
|
1759
|
+
/**
|
|
1760
|
+
* Validate a list has no fewer items than the minimum.
|
|
1761
|
+
*
|
|
1762
|
+
* @template A Array type
|
|
1763
|
+
* @template T Field tag name
|
|
1764
|
+
* @template U Field input type attribute
|
|
1765
|
+
* @template V Field option values
|
|
1766
|
+
* @template I What each item of a list field is
|
|
1767
|
+
* @param value Minimum number of items
|
|
1768
|
+
* @param message Issue message when invalid
|
|
1769
|
+
* @returns Refined field
|
|
1770
|
+
*/
|
|
1771
|
+
min<
|
|
1772
|
+
A extends unknown[],
|
|
1773
|
+
T extends Field.Tag,
|
|
1774
|
+
U extends Field.Type,
|
|
1775
|
+
V extends Field.Options | undefined,
|
|
1776
|
+
I extends Field.Item | undefined,
|
|
1777
|
+
>(
|
|
1778
|
+
this: Field.Instance<A, T, U, V, undefined, I>,
|
|
1779
|
+
value: number,
|
|
1780
|
+
message?: string,
|
|
1781
|
+
): Field.Instance<A, T, U, V, undefined, I>;
|
|
1782
|
+
/**
|
|
1783
|
+
* Validate an array has no fewer items than the minimum.
|
|
1784
|
+
*
|
|
1785
|
+
* @template A Array type
|
|
1786
|
+
* @param value Minimum number of items
|
|
1787
|
+
* @param message Issue message when invalid
|
|
1788
|
+
* @returns Refined schema
|
|
1789
|
+
*/
|
|
1790
|
+
min<A extends unknown[]>(
|
|
1791
|
+
this: Schema<A>,
|
|
1792
|
+
value: number,
|
|
1793
|
+
message?: string,
|
|
1794
|
+
): Schema<A>;
|
|
1696
1795
|
min(
|
|
1697
|
-
this: Schema<string | number | bigint>,
|
|
1796
|
+
this: Schema<string | number | bigint | unknown[]>,
|
|
1698
1797
|
value: number | bigint,
|
|
1699
|
-
message = `
|
|
1798
|
+
message = `At least ${this.#amount(value)}`,
|
|
1700
1799
|
) {
|
|
1701
1800
|
return this.#check({ name: "min", value, message });
|
|
1702
1801
|
}
|
|
@@ -1710,6 +1809,7 @@ export class Schema<Output>
|
|
|
1710
1809
|
* @template T Field tag name
|
|
1711
1810
|
* @template U Field input type attribute
|
|
1712
1811
|
* @template V Field option values
|
|
1812
|
+
* @template I What each item of a list field is
|
|
1713
1813
|
* @param value Maximum value or length
|
|
1714
1814
|
* @param message Issue message when invalid
|
|
1715
1815
|
* @returns Refined field
|
|
@@ -1718,17 +1818,19 @@ export class Schema<Output>
|
|
|
1718
1818
|
T extends Field.Tag,
|
|
1719
1819
|
U extends Field.Type,
|
|
1720
1820
|
V extends Field.Options | undefined,
|
|
1821
|
+
I extends Field.Item | undefined,
|
|
1721
1822
|
>(
|
|
1722
|
-
this: Field.Instance<string, T, U, V>,
|
|
1823
|
+
this: Field.Instance<string, T, U, V, undefined, I>,
|
|
1723
1824
|
value: number,
|
|
1724
1825
|
message?: string,
|
|
1725
|
-
): Field.Instance<string, T, U, V>;
|
|
1826
|
+
): Field.Instance<string, T, U, V, undefined, I>;
|
|
1726
1827
|
/**
|
|
1727
1828
|
* Validate an input is less than or equal to the maximum.
|
|
1728
1829
|
*
|
|
1729
1830
|
* @template T Field tag name
|
|
1730
1831
|
* @template U Field input type attribute
|
|
1731
1832
|
* @template V Field option values
|
|
1833
|
+
* @template I What each item of a list field is
|
|
1732
1834
|
* @param value Maximum value
|
|
1733
1835
|
* @param message Issue message when invalid
|
|
1734
1836
|
* @returns Refined field
|
|
@@ -1737,17 +1839,19 @@ export class Schema<Output>
|
|
|
1737
1839
|
T extends Field.Tag,
|
|
1738
1840
|
U extends Field.Type,
|
|
1739
1841
|
V extends Field.Options | undefined,
|
|
1842
|
+
I extends Field.Item | undefined,
|
|
1740
1843
|
>(
|
|
1741
|
-
this: Field.Instance<number, T, U, V>,
|
|
1844
|
+
this: Field.Instance<number, T, U, V, undefined, I>,
|
|
1742
1845
|
value: number,
|
|
1743
1846
|
message?: string,
|
|
1744
|
-
): Field.Instance<number, T, U, V>;
|
|
1847
|
+
): Field.Instance<number, T, U, V, undefined, I>;
|
|
1745
1848
|
/**
|
|
1746
1849
|
* Validate an input is less than or equal to the maximum.
|
|
1747
1850
|
*
|
|
1748
1851
|
* @template T Field tag name
|
|
1749
1852
|
* @template U Field input type attribute
|
|
1750
1853
|
* @template V Field option values
|
|
1854
|
+
* @template I What each item of a list field is
|
|
1751
1855
|
* @param value Maximum value
|
|
1752
1856
|
* @param message Issue message when invalid
|
|
1753
1857
|
* @returns Refined field
|
|
@@ -1756,11 +1860,12 @@ export class Schema<Output>
|
|
|
1756
1860
|
T extends Field.Tag,
|
|
1757
1861
|
U extends Field.Type,
|
|
1758
1862
|
V extends Field.Options | undefined,
|
|
1863
|
+
I extends Field.Item | undefined,
|
|
1759
1864
|
>(
|
|
1760
|
-
this: Field.Instance<bigint, T, U, V>,
|
|
1865
|
+
this: Field.Instance<bigint, T, U, V, undefined, I>,
|
|
1761
1866
|
value: bigint,
|
|
1762
1867
|
message?: string,
|
|
1763
|
-
): Field.Instance<bigint, T, U, V>;
|
|
1868
|
+
): Field.Instance<bigint, T, U, V, undefined, I>;
|
|
1764
1869
|
/**
|
|
1765
1870
|
* Validate an input is less than or equal to the maximum.
|
|
1766
1871
|
*
|
|
@@ -1788,10 +1893,46 @@ export class Schema<Output>
|
|
|
1788
1893
|
* @returns Refined schema
|
|
1789
1894
|
*/
|
|
1790
1895
|
max(this: Schema<bigint>, value: bigint, message?: string): Schema<bigint>;
|
|
1896
|
+
/**
|
|
1897
|
+
* Validate a list has no more items than the maximum.
|
|
1898
|
+
*
|
|
1899
|
+
* @template A Array type
|
|
1900
|
+
* @template T Field tag name
|
|
1901
|
+
* @template U Field input type attribute
|
|
1902
|
+
* @template V Field option values
|
|
1903
|
+
* @template I What each item of a list field is
|
|
1904
|
+
* @param value Maximum number of items
|
|
1905
|
+
* @param message Issue message when invalid
|
|
1906
|
+
* @returns Refined field
|
|
1907
|
+
*/
|
|
1908
|
+
max<
|
|
1909
|
+
A extends unknown[],
|
|
1910
|
+
T extends Field.Tag,
|
|
1911
|
+
U extends Field.Type,
|
|
1912
|
+
V extends Field.Options | undefined,
|
|
1913
|
+
I extends Field.Item | undefined,
|
|
1914
|
+
>(
|
|
1915
|
+
this: Field.Instance<A, T, U, V, undefined, I>,
|
|
1916
|
+
value: number,
|
|
1917
|
+
message?: string,
|
|
1918
|
+
): Field.Instance<A, T, U, V, undefined, I>;
|
|
1919
|
+
/**
|
|
1920
|
+
* Validate an array has no more items than the maximum.
|
|
1921
|
+
*
|
|
1922
|
+
* @template A Array type
|
|
1923
|
+
* @param value Maximum number of items
|
|
1924
|
+
* @param message Issue message when invalid
|
|
1925
|
+
* @returns Refined schema
|
|
1926
|
+
*/
|
|
1927
|
+
max<A extends unknown[]>(
|
|
1928
|
+
this: Schema<A>,
|
|
1929
|
+
value: number,
|
|
1930
|
+
message?: string,
|
|
1931
|
+
): Schema<A>;
|
|
1791
1932
|
max(
|
|
1792
|
-
this: Schema<string | number | bigint>,
|
|
1933
|
+
this: Schema<string | number | bigint | unknown[]>,
|
|
1793
1934
|
value: number | bigint,
|
|
1794
|
-
message = `
|
|
1935
|
+
message = `At most ${this.#amount(value)}`,
|
|
1795
1936
|
) {
|
|
1796
1937
|
return this.#check({ name: "max", value, message });
|
|
1797
1938
|
}
|
|
@@ -1800,6 +1941,7 @@ export class Schema<Output>
|
|
|
1800
1941
|
* @template T Field tag name
|
|
1801
1942
|
* @template U Field input type attribute
|
|
1802
1943
|
* @template V Field option values
|
|
1944
|
+
* @template I What each item of a list field is
|
|
1803
1945
|
* @param check Validation function that returns `false` to fail
|
|
1804
1946
|
* @param message Issue message when invalid
|
|
1805
1947
|
* @returns Refined field
|
|
@@ -1808,11 +1950,12 @@ export class Schema<Output>
|
|
|
1808
1950
|
T extends Field.Tag,
|
|
1809
1951
|
U extends Field.Type,
|
|
1810
1952
|
V extends Field.Options | undefined,
|
|
1953
|
+
I extends Field.Item | undefined,
|
|
1811
1954
|
>(
|
|
1812
|
-
this: Field.Instance<Output, T, U, V>,
|
|
1955
|
+
this: Field.Instance<Output, T, U, V, undefined, I>,
|
|
1813
1956
|
check: (value: Output) => boolean,
|
|
1814
1957
|
message: string,
|
|
1815
|
-
): Field.Instance<Output, T, U, V>;
|
|
1958
|
+
): Field.Instance<Output, T, U, V, undefined, I>;
|
|
1816
1959
|
/**
|
|
1817
1960
|
* @param check Validation function that returns `false` to fail
|
|
1818
1961
|
* @param message Issue message when invalid
|
package/src/util/index.ts
CHANGED
|
@@ -395,3 +395,26 @@ export class Time {
|
|
|
395
395
|
static readonly day = 24 * 60 * 60 * 1000;
|
|
396
396
|
static readonly week = 7 * 24 * 60 * 60 * 1000;
|
|
397
397
|
}
|
|
398
|
+
|
|
399
|
+
/** Descriptions written for people and agents */
|
|
400
|
+
export class Prose {
|
|
401
|
+
/**
|
|
402
|
+
* Joins parts of a description into sentences. A part without its own
|
|
403
|
+
* end gets a period before the next, and parts joined end as a sentence.
|
|
404
|
+
* A single part is kept as written.
|
|
405
|
+
*
|
|
406
|
+
* @param parts Parts, empty ones skipped
|
|
407
|
+
* @returns The description, or an empty string
|
|
408
|
+
*/
|
|
409
|
+
static join(...parts: (string | undefined)[]) {
|
|
410
|
+
const given = parts.filter((part): part is string => Boolean(part));
|
|
411
|
+
const ended = (part: string) => /[.!?]$/.test(part);
|
|
412
|
+
let joined = given.reduce(
|
|
413
|
+
(text, part) =>
|
|
414
|
+
text ? `${text}${ended(text) ? "" : "."} ${part}` : part,
|
|
415
|
+
"",
|
|
416
|
+
);
|
|
417
|
+
if (given.length > 1 && !ended(joined)) joined += ".";
|
|
418
|
+
return joined;
|
|
419
|
+
}
|
|
420
|
+
}
|