effect 4.0.0-beta.84 → 4.0.0-beta.85
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/Context.d.ts.map +1 -1
- package/dist/Context.js +4 -3
- package/dist/Context.js.map +1 -1
- package/dist/Layer.js +4 -3
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js +4 -3
- package/dist/LayerMap.js.map +1 -1
- package/dist/Random.d.ts +31 -0
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +32 -0
- package/dist/Random.js.map +1 -1
- package/dist/Schema.d.ts +48 -6
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +31 -11
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +8 -7
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +190 -131
- package/dist/SchemaAST.js.map +1 -1
- package/dist/internal/effect.js +10 -10
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/arbitrary.js +17 -1
- package/dist/internal/schema/arbitrary.js.map +1 -1
- package/dist/internal/stackTraceLimit.d.ts +2 -0
- package/dist/internal/stackTraceLimit.d.ts.map +1 -0
- package/dist/internal/stackTraceLimit.js +40 -0
- package/dist/internal/stackTraceLimit.js.map +1 -0
- package/dist/internal/tracer.d.ts.map +1 -1
- package/dist/internal/tracer.js +4 -3
- package/dist/internal/tracer.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +4 -5
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +4 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js +4 -3
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/package.json +1 -1
- package/src/Context.ts +4 -5
- package/src/Layer.ts +4 -4
- package/src/LayerMap.ts +4 -3
- package/src/Random.ts +42 -0
- package/src/Schema.ts +75 -22
- package/src/SchemaAST.ts +217 -137
- package/src/internal/effect.ts +11 -11
- package/src/internal/schema/arbitrary.ts +23 -2
- package/src/internal/stackTraceLimit.ts +63 -0
- package/src/internal/tracer.ts +4 -3
- package/src/unstable/ai/Tool.ts +4 -3
- package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -3
- package/src/unstable/persistence/PersistedQueue.ts +1 -1
- package/src/unstable/rpc/RpcMiddleware.ts +4 -3
package/dist/SchemaAST.js
CHANGED
|
@@ -23,7 +23,6 @@ import * as InternalSchemaCause from "./internal/schema/cause.js";
|
|
|
23
23
|
import * as Option from "./Option.js";
|
|
24
24
|
import * as Pipeable from "./Pipeable.js";
|
|
25
25
|
import * as Predicate from "./Predicate.js";
|
|
26
|
-
import * as RegEx from "./RegExp.js";
|
|
27
26
|
import * as Result from "./Result.js";
|
|
28
27
|
import * as SchemaGetter from "./SchemaGetter.js";
|
|
29
28
|
import * as SchemaIssue from "./SchemaIssue.js";
|
|
@@ -450,17 +449,17 @@ export class Declaration extends Base {
|
|
|
450
449
|
return Effect.mapEager(run(oinput.value, this, options), Option.some);
|
|
451
450
|
};
|
|
452
451
|
}
|
|
453
|
-
|
|
452
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
454
453
|
const tps = mapOrSame(this.typeParameters, recur);
|
|
455
454
|
return tps === this.typeParameters ? this : new Declaration(tps, this.run, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
456
455
|
}
|
|
457
456
|
/** @internal */
|
|
458
457
|
recur(recur) {
|
|
459
|
-
return this.
|
|
458
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
460
459
|
}
|
|
461
460
|
/** @internal */
|
|
462
461
|
flip(recur) {
|
|
463
|
-
return this.
|
|
462
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
464
463
|
}
|
|
465
464
|
/** @internal */
|
|
466
465
|
getExpected() {
|
|
@@ -783,11 +782,12 @@ function isTemplateLiteralPart(ast) {
|
|
|
783
782
|
case "String":
|
|
784
783
|
case "Number":
|
|
785
784
|
case "BigInt":
|
|
785
|
+
return true;
|
|
786
786
|
case "Literal":
|
|
787
787
|
case "TemplateLiteral":
|
|
788
|
-
return
|
|
788
|
+
return ast.checks === undefined;
|
|
789
789
|
case "Union":
|
|
790
|
-
return ast.types.every(isTemplateLiteralPart);
|
|
790
|
+
return ast.checks === undefined && ast.types.every(isTemplateLiteralPart);
|
|
791
791
|
default:
|
|
792
792
|
return false;
|
|
793
793
|
}
|
|
@@ -798,8 +798,7 @@ function isTemplateLiteralPart(ast) {
|
|
|
798
798
|
*
|
|
799
799
|
* **Details**
|
|
800
800
|
*
|
|
801
|
-
* `parts` is an array of AST nodes; each part contributes to
|
|
802
|
-
* template literal pattern. A regex is derived from the parts to validate
|
|
801
|
+
* `parts` is an array of AST nodes; each part contributes to matching
|
|
803
802
|
* strings at runtime.
|
|
804
803
|
*
|
|
805
804
|
* @see {@link isTemplateLiteral}
|
|
@@ -838,14 +837,17 @@ export class TemplateLiteral extends Base {
|
|
|
838
837
|
return "string";
|
|
839
838
|
}
|
|
840
839
|
/** @internal */
|
|
840
|
+
matchPart(s, options) {
|
|
841
|
+
return segmentTemplateLiteralParts(this.encodedParts, s, options) === undefined ? undefined : s;
|
|
842
|
+
}
|
|
843
|
+
/** @internal */
|
|
841
844
|
asTemplateLiteralParser() {
|
|
842
|
-
const tuple = new Arrays(false, this.parts.map(
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
if (match) return Effect.succeed(match.slice(1, this.parts.length + 1));
|
|
845
|
+
const tuple = new Arrays(false, this.parts.map(partFromString), []);
|
|
846
|
+
return decodeTo(string, tuple, new SchemaTransformation.Transformation(SchemaGetter.transformOrFail((s, options) => {
|
|
847
|
+
const segments = segmentTemplateLiteralParts(this.encodedParts, s, options);
|
|
848
|
+
if (segments !== undefined) return Effect.succeed(segments);
|
|
847
849
|
return Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), {
|
|
848
|
-
message: `Expected a
|
|
850
|
+
message: `Expected a string matching template literal parts, got ${format(s)}`
|
|
849
851
|
}));
|
|
850
852
|
}), SchemaGetter.transform(parts => parts.join(""))));
|
|
851
853
|
}
|
|
@@ -921,6 +923,10 @@ export class Literal extends Base {
|
|
|
921
923
|
return fromConst(this, this.literal);
|
|
922
924
|
}
|
|
923
925
|
/** @internal */
|
|
926
|
+
matchPart(s, _options) {
|
|
927
|
+
return s === globalThis.String(this.literal) ? this.literal : undefined;
|
|
928
|
+
}
|
|
929
|
+
/** @internal */
|
|
924
930
|
toCodecJson() {
|
|
925
931
|
return typeof this.literal === "bigint" ? literalToString(this) : this;
|
|
926
932
|
}
|
|
@@ -953,6 +959,10 @@ export class String extends Base {
|
|
|
953
959
|
return fromRefinement(this, Predicate.isString);
|
|
954
960
|
}
|
|
955
961
|
/** @internal */
|
|
962
|
+
matchPart(s, options) {
|
|
963
|
+
return applyTemplateLiteralPartChecks(this, s, options);
|
|
964
|
+
}
|
|
965
|
+
/** @internal */
|
|
956
966
|
getExpected() {
|
|
957
967
|
return "string";
|
|
958
968
|
}
|
|
@@ -997,6 +1007,17 @@ export class Number extends Base {
|
|
|
997
1007
|
return fromRefinement(this, Predicate.isNumber);
|
|
998
1008
|
}
|
|
999
1009
|
/** @internal */
|
|
1010
|
+
matchKey(s, options) {
|
|
1011
|
+
return this._match(isStringNumberRegExp, s, options);
|
|
1012
|
+
}
|
|
1013
|
+
/** @internal */
|
|
1014
|
+
matchPart(s, options) {
|
|
1015
|
+
return this._match(isStringFiniteRegExp, s, options);
|
|
1016
|
+
}
|
|
1017
|
+
_match(regexp, s, options) {
|
|
1018
|
+
return regexp.test(s) ? applyTemplateLiteralPartChecks(this, globalThis.Number(s), options) : undefined;
|
|
1019
|
+
}
|
|
1020
|
+
/** @internal */
|
|
1000
1021
|
toCodecJson() {
|
|
1001
1022
|
if (this.checks && (hasCheck(this.checks, "isFinite") || hasCheck(this.checks, "isInt"))) {
|
|
1002
1023
|
return this;
|
|
@@ -1101,6 +1122,10 @@ export class Symbol extends Base {
|
|
|
1101
1122
|
return fromRefinement(this, Predicate.isSymbol);
|
|
1102
1123
|
}
|
|
1103
1124
|
/** @internal */
|
|
1125
|
+
matchKey(s, options) {
|
|
1126
|
+
return applyTemplateLiteralPartChecks(this, s, options);
|
|
1127
|
+
}
|
|
1128
|
+
/** @internal */
|
|
1104
1129
|
toCodecStringTree() {
|
|
1105
1130
|
return replaceEncoding(this, [symbolToString]);
|
|
1106
1131
|
}
|
|
@@ -1148,6 +1173,10 @@ export class BigInt extends Base {
|
|
|
1148
1173
|
return fromRefinement(this, Predicate.isBigInt);
|
|
1149
1174
|
}
|
|
1150
1175
|
/** @internal */
|
|
1176
|
+
matchPart(s, options) {
|
|
1177
|
+
return isStringBigIntRegExp.test(s) ? applyTemplateLiteralPartChecks(this, globalThis.BigInt(s), options) : undefined;
|
|
1178
|
+
}
|
|
1179
|
+
/** @internal */
|
|
1151
1180
|
toCodecStringTree() {
|
|
1152
1181
|
return replaceEncoding(this, [bigIntToString]);
|
|
1153
1182
|
}
|
|
@@ -1304,18 +1333,18 @@ export class Arrays extends Base {
|
|
|
1304
1333
|
return Option.some(state.output);
|
|
1305
1334
|
});
|
|
1306
1335
|
}
|
|
1307
|
-
|
|
1336
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
1308
1337
|
const elements = mapOrSame(this.elements, recur);
|
|
1309
1338
|
const rest = mapOrSame(this.rest, recur);
|
|
1310
1339
|
return elements === this.elements && rest === this.rest ? this : new Arrays(this.isMutable, elements, rest, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
1311
1340
|
}
|
|
1312
1341
|
/** @internal */
|
|
1313
1342
|
recur(recur) {
|
|
1314
|
-
return this.
|
|
1343
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
1315
1344
|
}
|
|
1316
1345
|
/** @internal */
|
|
1317
1346
|
flip(recur) {
|
|
1318
|
-
return this.
|
|
1347
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
1319
1348
|
}
|
|
1320
1349
|
/** @internal */
|
|
1321
1350
|
getExpected() {
|
|
@@ -1373,30 +1402,29 @@ const wrapPropertyKeyIssue = (s, ast, key, exit) => {
|
|
|
1373
1402
|
* @internal
|
|
1374
1403
|
*/
|
|
1375
1404
|
export const FINITE_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
|
|
1376
|
-
const isNumberStringRegExp = /*#__PURE__*/new globalThis.RegExp(`(?:${FINITE_PATTERN}|Infinity|-Infinity|NaN)`);
|
|
1377
1405
|
/**
|
|
1378
1406
|
* Returns the object keys that match the index signature parameter schema.
|
|
1379
1407
|
* @internal
|
|
1380
1408
|
*/
|
|
1381
|
-
export function getIndexSignatureKeys(input, parameter) {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
return [];
|
|
1409
|
+
export function getIndexSignatureKeys(input, parameter, options = defaultParseOptions) {
|
|
1410
|
+
let stringKeys;
|
|
1411
|
+
let symbolKeys;
|
|
1412
|
+
function go(parameter) {
|
|
1413
|
+
switch (parameter._tag) {
|
|
1414
|
+
case "String":
|
|
1415
|
+
case "TemplateLiteral":
|
|
1416
|
+
return (stringKeys ??= Object.keys(input)).filter(k => parameter.matchPart(k, options) !== undefined);
|
|
1417
|
+
case "Number":
|
|
1418
|
+
return (stringKeys ??= Object.keys(input)).filter(k => parameter.matchKey(k, options) !== undefined);
|
|
1419
|
+
case "Symbol":
|
|
1420
|
+
return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter(k => parameter.matchKey(k, options) !== undefined);
|
|
1421
|
+
case "Union":
|
|
1422
|
+
return [...new Set(parameter.types.flatMap(go))];
|
|
1423
|
+
default:
|
|
1424
|
+
return [];
|
|
1425
|
+
}
|
|
1399
1426
|
}
|
|
1427
|
+
return go(parameterFromPropertyKey(toEncoded(parameter)));
|
|
1400
1428
|
}
|
|
1401
1429
|
/**
|
|
1402
1430
|
* Represents a named property within an {@link Objects} node.
|
|
@@ -1445,6 +1473,22 @@ export class KeyValueCombiner {
|
|
|
1445
1473
|
return new KeyValueCombiner(this.encode, this.decode);
|
|
1446
1474
|
}
|
|
1447
1475
|
}
|
|
1476
|
+
function isIndexSignatureParameterSide(ast) {
|
|
1477
|
+
switch (ast._tag) {
|
|
1478
|
+
case "String":
|
|
1479
|
+
case "Number":
|
|
1480
|
+
case "Symbol":
|
|
1481
|
+
case "TemplateLiteral":
|
|
1482
|
+
return true;
|
|
1483
|
+
case "Union":
|
|
1484
|
+
return ast.types.every(isIndexSignatureParameterSide);
|
|
1485
|
+
default:
|
|
1486
|
+
return false;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
function isIndexSignatureParameter(ast) {
|
|
1490
|
+
return isIndexSignatureParameterSide(ast) && isIndexSignatureParameterSide(toEncoded(ast));
|
|
1491
|
+
}
|
|
1448
1492
|
/**
|
|
1449
1493
|
* Represents an index signature entry within an {@link Objects} node.
|
|
1450
1494
|
*
|
|
@@ -1475,6 +1519,9 @@ export class IndexSignature {
|
|
|
1475
1519
|
type;
|
|
1476
1520
|
merge;
|
|
1477
1521
|
constructor(parameter, type, merge) {
|
|
1522
|
+
if (!isIndexSignatureParameter(parameter)) {
|
|
1523
|
+
throw new Error(`Invalid index signature parameter ${parameter._tag}`);
|
|
1524
|
+
}
|
|
1478
1525
|
this.parameter = parameter;
|
|
1479
1526
|
this.type = type;
|
|
1480
1527
|
this.merge = merge;
|
|
@@ -1570,7 +1617,7 @@ export class Objects extends Base {
|
|
|
1570
1617
|
}
|
|
1571
1618
|
const parseIndexes = indexCount > 0 ? iterateEager()({
|
|
1572
1619
|
onItem: Effect.fnUntracedEager(function* (s, [key, is]) {
|
|
1573
|
-
const parserKey = recur(
|
|
1620
|
+
const parserKey = recur(parameterFromPropertyKey(is.parameter));
|
|
1574
1621
|
const effKey = parserKey(Option.some(key), s.options);
|
|
1575
1622
|
const exitKey = effectIsExit(effKey) ? effKey : yield* Effect.exit(effKey);
|
|
1576
1623
|
if (exitKey._tag === "Failure") {
|
|
@@ -1665,7 +1712,7 @@ export class Objects extends Base {
|
|
|
1665
1712
|
const keyPairs = Arr.empty();
|
|
1666
1713
|
for (let i = 0; i < indexCount; i++) {
|
|
1667
1714
|
const is = ast.indexSignatures[i];
|
|
1668
|
-
const keys = getIndexSignatureKeys(input, is.parameter);
|
|
1715
|
+
const keys = getIndexSignatureKeys(input, is.parameter, options);
|
|
1669
1716
|
for (let j = 0; j < keys.length; j++) {
|
|
1670
1717
|
const key = keys[j];
|
|
1671
1718
|
keyPairs.push([key, is]);
|
|
@@ -1691,13 +1738,13 @@ export class Objects extends Base {
|
|
|
1691
1738
|
return Option.some(out);
|
|
1692
1739
|
});
|
|
1693
1740
|
}
|
|
1694
|
-
|
|
1741
|
+
_rebuild(recur, recurParameter, flipMerge, checks, encodingChecks) {
|
|
1695
1742
|
const props = mapOrSame(this.propertySignatures, ps => {
|
|
1696
1743
|
const t = recur(ps.type);
|
|
1697
1744
|
return t === ps.type ? ps : new PropertySignature(ps.name, t);
|
|
1698
1745
|
});
|
|
1699
1746
|
const indexes = mapOrSame(this.indexSignatures, is => {
|
|
1700
|
-
const p =
|
|
1747
|
+
const p = recurParameter(is.parameter);
|
|
1701
1748
|
const t = recur(is.type);
|
|
1702
1749
|
const merge = flipMerge ? is.merge?.flip() : is.merge;
|
|
1703
1750
|
return p === is.parameter && t === is.type && merge === is.merge ? is : new IndexSignature(p, t, merge);
|
|
@@ -1706,11 +1753,11 @@ export class Objects extends Base {
|
|
|
1706
1753
|
}
|
|
1707
1754
|
/** @internal */
|
|
1708
1755
|
flip(recur) {
|
|
1709
|
-
return this.
|
|
1756
|
+
return this._rebuild(recur, recur, true, this.encodingChecks, this.checks);
|
|
1710
1757
|
}
|
|
1711
1758
|
/** @internal */
|
|
1712
|
-
recur(recur) {
|
|
1713
|
-
return this.
|
|
1759
|
+
recur(recur, recurParameter = recur) {
|
|
1760
|
+
return this._rebuild(recur, recurParameter, false, this.checks, this.encodingChecks);
|
|
1714
1761
|
}
|
|
1715
1762
|
/** @internal */
|
|
1716
1763
|
getExpected() {
|
|
@@ -1739,14 +1786,10 @@ const parseProperties = /*#__PURE__*/iterateEager()({
|
|
|
1739
1786
|
}
|
|
1740
1787
|
}
|
|
1741
1788
|
});
|
|
1742
|
-
function
|
|
1743
|
-
if (!
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
if (!b.checks) {
|
|
1747
|
-
return checks;
|
|
1748
|
-
}
|
|
1749
|
-
return [...checks, ...b.checks];
|
|
1789
|
+
function combineChecks(a, b) {
|
|
1790
|
+
if (!a) return b;
|
|
1791
|
+
if (!b) return a;
|
|
1792
|
+
return [...a, ...b];
|
|
1750
1793
|
}
|
|
1751
1794
|
/** @internal */
|
|
1752
1795
|
export function struct(fields, checks, annotations) {
|
|
@@ -1774,10 +1817,10 @@ export function structWithRest(ast, records) {
|
|
|
1774
1817
|
let propertySignatures = ast.propertySignatures;
|
|
1775
1818
|
let indexSignatures = ast.indexSignatures;
|
|
1776
1819
|
let checks = ast.checks;
|
|
1777
|
-
for (const
|
|
1778
|
-
propertySignatures = propertySignatures.concat(
|
|
1779
|
-
indexSignatures = indexSignatures.concat(
|
|
1780
|
-
checks =
|
|
1820
|
+
for (const record of records) {
|
|
1821
|
+
propertySignatures = propertySignatures.concat(record.propertySignatures);
|
|
1822
|
+
indexSignatures = indexSignatures.concat(record.indexSignatures);
|
|
1823
|
+
checks = combineChecks(checks, record.checks);
|
|
1781
1824
|
}
|
|
1782
1825
|
return new Objects(propertySignatures, indexSignatures, undefined, checks);
|
|
1783
1826
|
}
|
|
@@ -2001,17 +2044,25 @@ export class Union extends Base {
|
|
|
2001
2044
|
});
|
|
2002
2045
|
};
|
|
2003
2046
|
}
|
|
2004
|
-
|
|
2047
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
2005
2048
|
const types = mapOrSame(this.types, recur);
|
|
2006
2049
|
return types === this.types ? this : new Union(types, this.mode, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
2007
2050
|
}
|
|
2008
2051
|
/** @internal */
|
|
2009
2052
|
recur(recur) {
|
|
2010
|
-
return this.
|
|
2053
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
2011
2054
|
}
|
|
2012
2055
|
/** @internal */
|
|
2013
2056
|
flip(recur) {
|
|
2014
|
-
return this.
|
|
2057
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
2058
|
+
}
|
|
2059
|
+
/** @internal */
|
|
2060
|
+
matchPart(s, options) {
|
|
2061
|
+
for (const type of this.types) {
|
|
2062
|
+
const out = type.matchPart(s, options);
|
|
2063
|
+
if (out !== undefined) return out;
|
|
2064
|
+
}
|
|
2065
|
+
return undefined;
|
|
2015
2066
|
}
|
|
2016
2067
|
/** @internal */
|
|
2017
2068
|
getExpected(getExpected) {
|
|
@@ -2354,7 +2405,7 @@ export function replaceChecks(ast, checks) {
|
|
|
2354
2405
|
}
|
|
2355
2406
|
/** @internal */
|
|
2356
2407
|
export function appendChecks(ast, checks) {
|
|
2357
|
-
return replaceChecks(ast, ast.checks
|
|
2408
|
+
return replaceChecks(ast, combineChecks(ast.checks, checks));
|
|
2358
2409
|
}
|
|
2359
2410
|
function updateLastLink(encoding, f) {
|
|
2360
2411
|
const links = encoding;
|
|
@@ -2465,42 +2516,33 @@ export function decodeTo(from, to, transformation) {
|
|
|
2465
2516
|
return appendTransformation(from, transformation, to);
|
|
2466
2517
|
}
|
|
2467
2518
|
function parseParameter(ast) {
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
return {
|
|
2484
|
-
literals: [],
|
|
2485
|
-
parameters: [ast]
|
|
2486
|
-
};
|
|
2487
|
-
case "Union":
|
|
2488
|
-
{
|
|
2489
|
-
const out = {
|
|
2490
|
-
literals: [],
|
|
2491
|
-
parameters: []
|
|
2492
|
-
};
|
|
2519
|
+
const literals = [];
|
|
2520
|
+
const parameters = [];
|
|
2521
|
+
function go(ast) {
|
|
2522
|
+
switch (ast._tag) {
|
|
2523
|
+
case "Literal":
|
|
2524
|
+
if (Predicate.isPropertyKey(ast.literal)) {
|
|
2525
|
+
literals.push(ast.literal);
|
|
2526
|
+
}
|
|
2527
|
+
return;
|
|
2528
|
+
case "UniqueSymbol":
|
|
2529
|
+
literals.push(ast.symbol);
|
|
2530
|
+
return;
|
|
2531
|
+
case "Never":
|
|
2532
|
+
return;
|
|
2533
|
+
case "Union":
|
|
2493
2534
|
for (let i = 0; i < ast.types.length; i++) {
|
|
2494
|
-
|
|
2495
|
-
out.literals = out.literals.concat(parsed.literals);
|
|
2496
|
-
out.parameters = out.parameters.concat(parsed.parameters);
|
|
2535
|
+
go(ast.types[i]);
|
|
2497
2536
|
}
|
|
2498
|
-
return
|
|
2499
|
-
|
|
2537
|
+
return;
|
|
2538
|
+
default:
|
|
2539
|
+
parameters.push(ast);
|
|
2540
|
+
}
|
|
2500
2541
|
}
|
|
2542
|
+
go(ast);
|
|
2501
2543
|
return {
|
|
2502
|
-
literals
|
|
2503
|
-
parameters
|
|
2544
|
+
literals,
|
|
2545
|
+
parameters
|
|
2504
2546
|
};
|
|
2505
2547
|
}
|
|
2506
2548
|
/** @internal */
|
|
@@ -2651,39 +2693,6 @@ export function containsUndefined(ast) {
|
|
|
2651
2693
|
return false;
|
|
2652
2694
|
}
|
|
2653
2695
|
}
|
|
2654
|
-
function getTemplateLiteralSource(ast, top) {
|
|
2655
|
-
return ast.encodedParts.map(part => handleTemplateLiteralASTPartParens(part, getTemplateLiteralASTPartPattern(part), top)).join("");
|
|
2656
|
-
}
|
|
2657
|
-
/** @internal */
|
|
2658
|
-
export const getTemplateLiteralRegExp = /*#__PURE__*/memoize(ast => {
|
|
2659
|
-
return new globalThis.RegExp(`^${getTemplateLiteralSource(ast, true)}$`);
|
|
2660
|
-
});
|
|
2661
|
-
function getTemplateLiteralASTPartPattern(part) {
|
|
2662
|
-
switch (part._tag) {
|
|
2663
|
-
case "Literal":
|
|
2664
|
-
return RegEx.escape(globalThis.String(part.literal));
|
|
2665
|
-
case "String":
|
|
2666
|
-
return STRING_PATTERN;
|
|
2667
|
-
case "Number":
|
|
2668
|
-
return FINITE_PATTERN;
|
|
2669
|
-
case "BigInt":
|
|
2670
|
-
return BIGINT_PATTERN;
|
|
2671
|
-
case "TemplateLiteral":
|
|
2672
|
-
return getTemplateLiteralSource(part, false);
|
|
2673
|
-
case "Union":
|
|
2674
|
-
return part.types.map(getTemplateLiteralASTPartPattern).join("|");
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
function handleTemplateLiteralASTPartParens(part, s, top) {
|
|
2678
|
-
if (isUnion(part)) {
|
|
2679
|
-
if (!top) {
|
|
2680
|
-
return `(?:${s})`;
|
|
2681
|
-
}
|
|
2682
|
-
} else if (!top) {
|
|
2683
|
-
return s;
|
|
2684
|
-
}
|
|
2685
|
-
return `(${s})`;
|
|
2686
|
-
}
|
|
2687
2696
|
function fromConst(ast, value) {
|
|
2688
2697
|
const succeed = Effect.succeedSome(value);
|
|
2689
2698
|
return oinput => {
|
|
@@ -2701,6 +2710,46 @@ function fromRefinement(ast, refinement) {
|
|
|
2701
2710
|
return refinement(oinput.value) ? Effect.succeed(oinput) : Effect.fail(new SchemaIssue.InvalidType(ast, oinput));
|
|
2702
2711
|
};
|
|
2703
2712
|
}
|
|
2713
|
+
function applyTemplateLiteralPartChecks(ast, value, options) {
|
|
2714
|
+
if (options?.disableChecks || ast.checks === undefined) return value;
|
|
2715
|
+
const issues = [];
|
|
2716
|
+
collectIssues(ast.checks, value, issues, ast, options);
|
|
2717
|
+
return issues.length === 0 ? value : undefined;
|
|
2718
|
+
}
|
|
2719
|
+
function segmentTemplateLiteralParts(parts, input, options) {
|
|
2720
|
+
const out = new Array(parts.length);
|
|
2721
|
+
const failures = new Set();
|
|
2722
|
+
function go(i, pos) {
|
|
2723
|
+
if (i === parts.length) return pos === input.length;
|
|
2724
|
+
const key = `${i}/${pos}`;
|
|
2725
|
+
if (failures.has(key)) return false;
|
|
2726
|
+
const part = parts[i];
|
|
2727
|
+
if (i === parts.length - 1) {
|
|
2728
|
+
const s = input.slice(pos);
|
|
2729
|
+
if (part.matchPart(s, options) !== undefined) {
|
|
2730
|
+
out[i] = s;
|
|
2731
|
+
return true;
|
|
2732
|
+
}
|
|
2733
|
+
} else if (part._tag === "Literal") {
|
|
2734
|
+
const s = globalThis.String(part.literal);
|
|
2735
|
+
if (input.startsWith(s, pos) && go(i + 1, pos + s.length)) {
|
|
2736
|
+
out[i] = s;
|
|
2737
|
+
return true;
|
|
2738
|
+
}
|
|
2739
|
+
} else {
|
|
2740
|
+
for (let end = input.length; end >= pos; end--) {
|
|
2741
|
+
const s = input.slice(pos, end);
|
|
2742
|
+
if (part.matchPart(s, options) !== undefined && go(i + 1, end)) {
|
|
2743
|
+
out[i] = s;
|
|
2744
|
+
return true;
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
failures.add(key);
|
|
2749
|
+
return false;
|
|
2750
|
+
}
|
|
2751
|
+
return go(0, 0) ? out : undefined;
|
|
2752
|
+
}
|
|
2704
2753
|
/** @internal */
|
|
2705
2754
|
export const enumsToLiterals = /*#__PURE__*/memoize(ast => {
|
|
2706
2755
|
return new Union(ast.enums.map(e => new Literal(e[1], {
|
|
@@ -2714,29 +2763,38 @@ export function toCodec(f) {
|
|
|
2714
2763
|
}
|
|
2715
2764
|
return memoize(out);
|
|
2716
2765
|
}
|
|
2717
|
-
const
|
|
2766
|
+
const parameterFromPropertyKey = /*#__PURE__*/toCodec(ast => {
|
|
2718
2767
|
switch (ast._tag) {
|
|
2719
2768
|
default:
|
|
2720
2769
|
return ast;
|
|
2721
2770
|
case "Number":
|
|
2722
2771
|
return ast.toCodecStringTree();
|
|
2723
2772
|
case "Union":
|
|
2724
|
-
return ast.recur(
|
|
2773
|
+
return ast.recur(parameterFromPropertyKey);
|
|
2725
2774
|
}
|
|
2726
2775
|
});
|
|
2727
|
-
|
|
2776
|
+
/** @internal */
|
|
2777
|
+
export const parameterFromString = /*#__PURE__*/toCodec(ast => {
|
|
2728
2778
|
switch (ast._tag) {
|
|
2729
2779
|
default:
|
|
2730
2780
|
return ast;
|
|
2731
|
-
case "
|
|
2732
|
-
case "
|
|
2781
|
+
case "Symbol":
|
|
2782
|
+
case "UniqueSymbol":
|
|
2783
|
+
return ast.toCodecStringTree();
|
|
2784
|
+
case "Union":
|
|
2785
|
+
return ast.recur(parameterFromString);
|
|
2786
|
+
}
|
|
2787
|
+
});
|
|
2788
|
+
const partFromString = /*#__PURE__*/toCodec(ast => {
|
|
2789
|
+
switch (ast._tag) {
|
|
2790
|
+
default:
|
|
2733
2791
|
return ast;
|
|
2734
|
-
case "BigInt":
|
|
2735
2792
|
case "Number":
|
|
2736
2793
|
case "Literal":
|
|
2794
|
+
case "BigInt":
|
|
2737
2795
|
return ast.toCodecStringTree();
|
|
2738
2796
|
case "Union":
|
|
2739
|
-
return ast.recur(
|
|
2797
|
+
return ast.recur(partFromString);
|
|
2740
2798
|
}
|
|
2741
2799
|
});
|
|
2742
2800
|
/**
|
|
@@ -2745,6 +2803,7 @@ const templateLiteralPartFromString = /*#__PURE__*/toCodec(ast => {
|
|
|
2745
2803
|
*/
|
|
2746
2804
|
export const STRING_PATTERN = "[\\s\\S]*?";
|
|
2747
2805
|
const isStringFiniteRegExp = /*#__PURE__*/new globalThis.RegExp(`^${FINITE_PATTERN}$`);
|
|
2806
|
+
const isStringNumberRegExp = /*#__PURE__*/new globalThis.RegExp(`(?:${FINITE_PATTERN}|Infinity|-Infinity|NaN)`);
|
|
2748
2807
|
/** @internal */
|
|
2749
2808
|
export function isStringFinite(annotations) {
|
|
2750
2809
|
return isPattern(isStringFiniteRegExp, {
|