effect 4.0.0-beta.83 → 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/Array.d.ts +64 -64
- package/dist/Array.js +26 -26
- package/dist/Cache.d.ts +1 -1
- package/dist/Cache.js +1 -1
- package/dist/Cause.d.ts +68 -68
- package/dist/Cause.js +47 -47
- package/dist/Channel.d.ts +5 -5
- package/dist/Channel.js +3 -3
- package/dist/Clock.d.ts +1 -1
- package/dist/Clock.js +1 -1
- package/dist/Combiner.d.ts +9 -9
- package/dist/Combiner.js +8 -8
- package/dist/Config.d.ts +15 -94
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +22 -70
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +58 -74
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +66 -41
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Console.d.ts +1 -1
- package/dist/Console.js +1 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +4 -3
- package/dist/Context.js.map +1 -1
- package/dist/Data.d.ts +15 -15
- package/dist/Data.js +3 -3
- package/dist/DateTime.d.ts +6 -6
- package/dist/DateTime.js +2 -2
- package/dist/Duration.d.ts +3 -3
- package/dist/Duration.js +3 -3
- package/dist/Effect.d.ts +84 -45
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +72 -33
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +7 -7
- package/dist/Equal.js +5 -5
- package/dist/Equivalence.d.ts +17 -17
- package/dist/Equivalence.js +13 -13
- package/dist/Exit.d.ts +3 -3
- package/dist/Exit.js +3 -3
- package/dist/Formatter.d.ts +5 -5
- package/dist/Formatter.js +4 -4
- package/dist/Function.d.ts +10 -10
- package/dist/Function.js +3 -3
- package/dist/HashMap.d.ts +3 -3
- package/dist/HashMap.js +1 -1
- package/dist/Iterable.d.ts +6 -6
- package/dist/Iterable.js +2 -2
- package/dist/JsonPatch.d.ts +2 -2
- package/dist/Layer.d.ts +1 -1
- package/dist/Layer.js +5 -4
- 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/Logger.d.ts +1 -1
- package/dist/Logger.js +1 -1
- package/dist/Match.d.ts +8 -8
- package/dist/Match.js +8 -8
- package/dist/Metric.d.ts +3 -3
- package/dist/Metric.js +3 -3
- package/dist/Optic.d.ts +30 -30
- package/dist/Optic.js +12 -12
- package/dist/Option.d.ts +7 -7
- package/dist/Option.js +7 -7
- package/dist/Order.d.ts +23 -23
- package/dist/Order.js +20 -20
- package/dist/Pool.d.ts +1 -1
- package/dist/Pool.js +1 -1
- package/dist/Predicate.d.ts +88 -88
- package/dist/Predicate.js +47 -47
- package/dist/PubSub.d.ts +3 -3
- package/dist/PubSub.js +3 -3
- 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/Reducer.d.ts +1 -1
- package/dist/Reducer.js +1 -1
- package/dist/Result.d.ts +18 -18
- package/dist/Result.js +8 -8
- package/dist/Runtime.d.ts +1 -1
- package/dist/Runtime.js +1 -1
- package/dist/Schema.d.ts +313 -126
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +316 -127
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +9 -8
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +203 -140
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +48 -48
- package/dist/SchemaGetter.js +44 -44
- package/dist/SchemaIssue.d.ts +3 -3
- package/dist/SchemaIssue.js +3 -3
- package/dist/SchemaParser.d.ts +122 -22
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +186 -50
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +96 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +20 -20
- package/dist/SchemaTransformation.js +18 -18
- package/dist/Stream.d.ts +3 -3
- package/dist/Stream.js +2 -2
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +1 -1
- package/dist/String.js +1 -1
- package/dist/Struct.d.ts +1 -1
- package/dist/Struct.js +1 -1
- package/dist/Types.d.ts +13 -13
- package/dist/internal/effect.js +33 -20
- 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/schema/cause.d.ts +2 -0
- package/dist/internal/schema/cause.d.ts.map +1 -0
- package/dist/internal/schema/cause.js +24 -0
- package/dist/internal/schema/cause.js.map +1 -0
- package/dist/internal/schema/schema.d.ts +8 -4
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +21 -8
- package/dist/internal/schema/schema.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/testing/TestSchema.d.ts +3 -3
- package/dist/testing/TestSchema.js +1 -1
- package/dist/unstable/ai/AiError.d.ts +1 -1
- package/dist/unstable/ai/AiError.js +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.js +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/cli/Prompt.js +2 -2
- package/dist/unstable/cli/Prompt.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/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/persistence/PersistedQueue.js +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.js +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js +3 -4
- package/dist/unstable/rpc/RpcGroup.js.map +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/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +15 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +1 -0
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +1 -0
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +65 -65
- package/src/Cache.ts +1 -1
- package/src/Cause.ts +68 -68
- package/src/Channel.ts +5 -5
- package/src/Clock.ts +1 -1
- package/src/Combiner.ts +9 -9
- package/src/Config.ts +40 -108
- package/src/ConfigProvider.ts +139 -100
- package/src/Console.ts +1 -1
- package/src/Context.ts +4 -5
- package/src/Data.ts +15 -15
- package/src/DateTime.ts +6 -6
- package/src/Duration.ts +3 -3
- package/src/Effect.ts +89 -45
- package/src/Equal.ts +7 -7
- package/src/Equivalence.ts +17 -17
- package/src/Exit.ts +3 -3
- package/src/Formatter.ts +5 -5
- package/src/Function.ts +10 -10
- package/src/HashMap.ts +3 -3
- package/src/Iterable.ts +6 -6
- package/src/JsonPatch.ts +2 -2
- package/src/Layer.ts +5 -5
- package/src/LayerMap.ts +4 -3
- package/src/Logger.ts +1 -1
- package/src/Match.ts +8 -8
- package/src/Metric.ts +3 -3
- package/src/Optic.ts +30 -30
- package/src/Option.ts +7 -7
- package/src/Order.ts +23 -23
- package/src/Pool.ts +1 -1
- package/src/Predicate.ts +88 -88
- package/src/PubSub.ts +3 -3
- package/src/Random.ts +42 -0
- package/src/Reducer.ts +1 -1
- package/src/Result.ts +20 -20
- package/src/Runtime.ts +1 -1
- package/src/Schema.ts +389 -153
- package/src/SchemaAST.ts +237 -148
- package/src/SchemaGetter.ts +48 -48
- package/src/SchemaIssue.ts +3 -3
- package/src/SchemaParser.ts +197 -58
- package/src/SchemaRepresentation.ts +73 -3
- package/src/SchemaTransformation.ts +20 -20
- package/src/Stream.ts +4 -4
- package/src/String.ts +1 -1
- package/src/Struct.ts +1 -1
- package/src/Types.ts +13 -13
- package/src/internal/effect.ts +40 -21
- package/src/internal/schema/arbitrary.ts +23 -2
- package/src/internal/schema/cause.ts +26 -0
- package/src/internal/schema/schema.ts +36 -10
- package/src/internal/stackTraceLimit.ts +63 -0
- package/src/internal/tracer.ts +4 -3
- package/src/testing/TestSchema.ts +3 -3
- package/src/unstable/ai/AiError.ts +1 -1
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/Tool.ts +4 -3
- package/src/unstable/cli/Prompt.ts +1 -1
- package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -3
- package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
- package/src/unstable/persistence/PersistedQueue.ts +1 -1
- package/src/unstable/rpc/Rpc.ts +1 -1
- package/src/unstable/rpc/RpcGroup.ts +3 -4
- package/src/unstable/rpc/RpcMiddleware.ts +4 -3
- package/src/unstable/sql/SqlResolver.ts +15 -2
- package/src/unstable/workflow/Activity.ts +2 -0
- package/src/unstable/workflow/WorkflowEngine.ts +1 -1
package/dist/SchemaAST.js
CHANGED
|
@@ -19,10 +19,10 @@ import { memoize } from "./Function.js";
|
|
|
19
19
|
import { effectIsExit, iterateEager } from "./internal/effect.js";
|
|
20
20
|
import * as internalRecord from "./internal/record.js";
|
|
21
21
|
import * as InternalAnnotations from "./internal/schema/annotations.js";
|
|
22
|
+
import * as InternalSchemaCause from "./internal/schema/cause.js";
|
|
22
23
|
import * as Option from "./Option.js";
|
|
23
24
|
import * as Pipeable from "./Pipeable.js";
|
|
24
25
|
import * as Predicate from "./Predicate.js";
|
|
25
|
-
import * as RegEx from "./RegExp.js";
|
|
26
26
|
import * as Result from "./Result.js";
|
|
27
27
|
import * as SchemaGetter from "./SchemaGetter.js";
|
|
28
28
|
import * as SchemaIssue from "./SchemaIssue.js";
|
|
@@ -449,17 +449,17 @@ export class Declaration extends Base {
|
|
|
449
449
|
return Effect.mapEager(run(oinput.value, this, options), Option.some);
|
|
450
450
|
};
|
|
451
451
|
}
|
|
452
|
-
|
|
452
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
453
453
|
const tps = mapOrSame(this.typeParameters, recur);
|
|
454
454
|
return tps === this.typeParameters ? this : new Declaration(tps, this.run, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
455
455
|
}
|
|
456
456
|
/** @internal */
|
|
457
457
|
recur(recur) {
|
|
458
|
-
return this.
|
|
458
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
459
459
|
}
|
|
460
460
|
/** @internal */
|
|
461
461
|
flip(recur) {
|
|
462
|
-
return this.
|
|
462
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
463
463
|
}
|
|
464
464
|
/** @internal */
|
|
465
465
|
getExpected() {
|
|
@@ -782,11 +782,12 @@ function isTemplateLiteralPart(ast) {
|
|
|
782
782
|
case "String":
|
|
783
783
|
case "Number":
|
|
784
784
|
case "BigInt":
|
|
785
|
+
return true;
|
|
785
786
|
case "Literal":
|
|
786
787
|
case "TemplateLiteral":
|
|
787
|
-
return
|
|
788
|
+
return ast.checks === undefined;
|
|
788
789
|
case "Union":
|
|
789
|
-
return ast.types.every(isTemplateLiteralPart);
|
|
790
|
+
return ast.checks === undefined && ast.types.every(isTemplateLiteralPart);
|
|
790
791
|
default:
|
|
791
792
|
return false;
|
|
792
793
|
}
|
|
@@ -797,8 +798,7 @@ function isTemplateLiteralPart(ast) {
|
|
|
797
798
|
*
|
|
798
799
|
* **Details**
|
|
799
800
|
*
|
|
800
|
-
* `parts` is an array of AST nodes; each part contributes to
|
|
801
|
-
* 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
|
|
802
802
|
* strings at runtime.
|
|
803
803
|
*
|
|
804
804
|
* @see {@link isTemplateLiteral}
|
|
@@ -837,14 +837,17 @@ export class TemplateLiteral extends Base {
|
|
|
837
837
|
return "string";
|
|
838
838
|
}
|
|
839
839
|
/** @internal */
|
|
840
|
+
matchPart(s, options) {
|
|
841
|
+
return segmentTemplateLiteralParts(this.encodedParts, s, options) === undefined ? undefined : s;
|
|
842
|
+
}
|
|
843
|
+
/** @internal */
|
|
840
844
|
asTemplateLiteralParser() {
|
|
841
|
-
const tuple = new Arrays(false, this.parts.map(
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
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);
|
|
846
849
|
return Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), {
|
|
847
|
-
message: `Expected a
|
|
850
|
+
message: `Expected a string matching template literal parts, got ${format(s)}`
|
|
848
851
|
}));
|
|
849
852
|
}), SchemaGetter.transform(parts => parts.join(""))));
|
|
850
853
|
}
|
|
@@ -920,6 +923,10 @@ export class Literal extends Base {
|
|
|
920
923
|
return fromConst(this, this.literal);
|
|
921
924
|
}
|
|
922
925
|
/** @internal */
|
|
926
|
+
matchPart(s, _options) {
|
|
927
|
+
return s === globalThis.String(this.literal) ? this.literal : undefined;
|
|
928
|
+
}
|
|
929
|
+
/** @internal */
|
|
923
930
|
toCodecJson() {
|
|
924
931
|
return typeof this.literal === "bigint" ? literalToString(this) : this;
|
|
925
932
|
}
|
|
@@ -952,6 +959,10 @@ export class String extends Base {
|
|
|
952
959
|
return fromRefinement(this, Predicate.isString);
|
|
953
960
|
}
|
|
954
961
|
/** @internal */
|
|
962
|
+
matchPart(s, options) {
|
|
963
|
+
return applyTemplateLiteralPartChecks(this, s, options);
|
|
964
|
+
}
|
|
965
|
+
/** @internal */
|
|
955
966
|
getExpected() {
|
|
956
967
|
return "string";
|
|
957
968
|
}
|
|
@@ -996,6 +1007,17 @@ export class Number extends Base {
|
|
|
996
1007
|
return fromRefinement(this, Predicate.isNumber);
|
|
997
1008
|
}
|
|
998
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 */
|
|
999
1021
|
toCodecJson() {
|
|
1000
1022
|
if (this.checks && (hasCheck(this.checks, "isFinite") || hasCheck(this.checks, "isInt"))) {
|
|
1001
1023
|
return this;
|
|
@@ -1100,6 +1122,10 @@ export class Symbol extends Base {
|
|
|
1100
1122
|
return fromRefinement(this, Predicate.isSymbol);
|
|
1101
1123
|
}
|
|
1102
1124
|
/** @internal */
|
|
1125
|
+
matchKey(s, options) {
|
|
1126
|
+
return applyTemplateLiteralPartChecks(this, s, options);
|
|
1127
|
+
}
|
|
1128
|
+
/** @internal */
|
|
1103
1129
|
toCodecStringTree() {
|
|
1104
1130
|
return replaceEncoding(this, [symbolToString]);
|
|
1105
1131
|
}
|
|
@@ -1147,6 +1173,10 @@ export class BigInt extends Base {
|
|
|
1147
1173
|
return fromRefinement(this, Predicate.isBigInt);
|
|
1148
1174
|
}
|
|
1149
1175
|
/** @internal */
|
|
1176
|
+
matchPart(s, options) {
|
|
1177
|
+
return isStringBigIntRegExp.test(s) ? applyTemplateLiteralPartChecks(this, globalThis.BigInt(s), options) : undefined;
|
|
1178
|
+
}
|
|
1179
|
+
/** @internal */
|
|
1150
1180
|
toCodecStringTree() {
|
|
1151
1181
|
return replaceEncoding(this, [bigIntToString]);
|
|
1152
1182
|
}
|
|
@@ -1303,18 +1333,18 @@ export class Arrays extends Base {
|
|
|
1303
1333
|
return Option.some(state.output);
|
|
1304
1334
|
});
|
|
1305
1335
|
}
|
|
1306
|
-
|
|
1336
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
1307
1337
|
const elements = mapOrSame(this.elements, recur);
|
|
1308
1338
|
const rest = mapOrSame(this.rest, recur);
|
|
1309
1339
|
return elements === this.elements && rest === this.rest ? this : new Arrays(this.isMutable, elements, rest, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
1310
1340
|
}
|
|
1311
1341
|
/** @internal */
|
|
1312
1342
|
recur(recur) {
|
|
1313
|
-
return this.
|
|
1343
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
1314
1344
|
}
|
|
1315
1345
|
/** @internal */
|
|
1316
1346
|
flip(recur) {
|
|
1317
|
-
return this.
|
|
1347
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
1318
1348
|
}
|
|
1319
1349
|
/** @internal */
|
|
1320
1350
|
getExpected() {
|
|
@@ -1353,15 +1383,18 @@ const resolveConcurrency = value => {
|
|
|
1353
1383
|
} : undefined;
|
|
1354
1384
|
};
|
|
1355
1385
|
const wrapPropertyKeyIssue = (s, ast, key, exit) => {
|
|
1356
|
-
|
|
1357
|
-
if (Result.isFailure(issueResult)) {
|
|
1386
|
+
if (exit.cause.reasons.length === 0) {
|
|
1358
1387
|
return exit;
|
|
1359
1388
|
}
|
|
1360
|
-
const issue =
|
|
1389
|
+
const issue = InternalSchemaCause.getSchemaIssue(exit.cause);
|
|
1390
|
+
if (issue === undefined) {
|
|
1391
|
+
return Exit.failCause(Cause.map(exit.cause, issue => new SchemaIssue.Composite(ast, s.oinput, [new SchemaIssue.Pointer([key], issue)])));
|
|
1392
|
+
}
|
|
1393
|
+
const pointer = new SchemaIssue.Pointer([key], issue);
|
|
1361
1394
|
if (s.options.errors === "all") {
|
|
1362
|
-
if (s.issues) s.issues.push(
|
|
1395
|
+
if (s.issues) s.issues.push(pointer);else s.issues = [pointer];
|
|
1363
1396
|
} else {
|
|
1364
|
-
return Exit.fail(new SchemaIssue.Composite(ast, s.oinput, [
|
|
1397
|
+
return Exit.fail(new SchemaIssue.Composite(ast, s.oinput, [pointer]));
|
|
1365
1398
|
}
|
|
1366
1399
|
};
|
|
1367
1400
|
/**
|
|
@@ -1369,30 +1402,29 @@ const wrapPropertyKeyIssue = (s, ast, key, exit) => {
|
|
|
1369
1402
|
* @internal
|
|
1370
1403
|
*/
|
|
1371
1404
|
export const FINITE_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
|
|
1372
|
-
const isNumberStringRegExp = /*#__PURE__*/new globalThis.RegExp(`(?:${FINITE_PATTERN}|Infinity|-Infinity|NaN)`);
|
|
1373
1405
|
/**
|
|
1374
1406
|
* Returns the object keys that match the index signature parameter schema.
|
|
1375
1407
|
* @internal
|
|
1376
1408
|
*/
|
|
1377
|
-
export function getIndexSignatureKeys(input, parameter) {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
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
|
+
}
|
|
1395
1426
|
}
|
|
1427
|
+
return go(parameterFromPropertyKey(toEncoded(parameter)));
|
|
1396
1428
|
}
|
|
1397
1429
|
/**
|
|
1398
1430
|
* Represents a named property within an {@link Objects} node.
|
|
@@ -1441,6 +1473,22 @@ export class KeyValueCombiner {
|
|
|
1441
1473
|
return new KeyValueCombiner(this.encode, this.decode);
|
|
1442
1474
|
}
|
|
1443
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
|
+
}
|
|
1444
1492
|
/**
|
|
1445
1493
|
* Represents an index signature entry within an {@link Objects} node.
|
|
1446
1494
|
*
|
|
@@ -1471,6 +1519,9 @@ export class IndexSignature {
|
|
|
1471
1519
|
type;
|
|
1472
1520
|
merge;
|
|
1473
1521
|
constructor(parameter, type, merge) {
|
|
1522
|
+
if (!isIndexSignatureParameter(parameter)) {
|
|
1523
|
+
throw new Error(`Invalid index signature parameter ${parameter._tag}`);
|
|
1524
|
+
}
|
|
1474
1525
|
this.parameter = parameter;
|
|
1475
1526
|
this.type = type;
|
|
1476
1527
|
this.merge = merge;
|
|
@@ -1566,7 +1617,7 @@ export class Objects extends Base {
|
|
|
1566
1617
|
}
|
|
1567
1618
|
const parseIndexes = indexCount > 0 ? iterateEager()({
|
|
1568
1619
|
onItem: Effect.fnUntracedEager(function* (s, [key, is]) {
|
|
1569
|
-
const parserKey = recur(
|
|
1620
|
+
const parserKey = recur(parameterFromPropertyKey(is.parameter));
|
|
1570
1621
|
const effKey = parserKey(Option.some(key), s.options);
|
|
1571
1622
|
const exitKey = effectIsExit(effKey) ? effKey : yield* Effect.exit(effKey);
|
|
1572
1623
|
if (exitKey._tag === "Failure") {
|
|
@@ -1661,7 +1712,7 @@ export class Objects extends Base {
|
|
|
1661
1712
|
const keyPairs = Arr.empty();
|
|
1662
1713
|
for (let i = 0; i < indexCount; i++) {
|
|
1663
1714
|
const is = ast.indexSignatures[i];
|
|
1664
|
-
const keys = getIndexSignatureKeys(input, is.parameter);
|
|
1715
|
+
const keys = getIndexSignatureKeys(input, is.parameter, options);
|
|
1665
1716
|
for (let j = 0; j < keys.length; j++) {
|
|
1666
1717
|
const key = keys[j];
|
|
1667
1718
|
keyPairs.push([key, is]);
|
|
@@ -1687,13 +1738,13 @@ export class Objects extends Base {
|
|
|
1687
1738
|
return Option.some(out);
|
|
1688
1739
|
});
|
|
1689
1740
|
}
|
|
1690
|
-
|
|
1741
|
+
_rebuild(recur, recurParameter, flipMerge, checks, encodingChecks) {
|
|
1691
1742
|
const props = mapOrSame(this.propertySignatures, ps => {
|
|
1692
1743
|
const t = recur(ps.type);
|
|
1693
1744
|
return t === ps.type ? ps : new PropertySignature(ps.name, t);
|
|
1694
1745
|
});
|
|
1695
1746
|
const indexes = mapOrSame(this.indexSignatures, is => {
|
|
1696
|
-
const p =
|
|
1747
|
+
const p = recurParameter(is.parameter);
|
|
1697
1748
|
const t = recur(is.type);
|
|
1698
1749
|
const merge = flipMerge ? is.merge?.flip() : is.merge;
|
|
1699
1750
|
return p === is.parameter && t === is.type && merge === is.merge ? is : new IndexSignature(p, t, merge);
|
|
@@ -1702,11 +1753,11 @@ export class Objects extends Base {
|
|
|
1702
1753
|
}
|
|
1703
1754
|
/** @internal */
|
|
1704
1755
|
flip(recur) {
|
|
1705
|
-
return this.
|
|
1756
|
+
return this._rebuild(recur, recur, true, this.encodingChecks, this.checks);
|
|
1706
1757
|
}
|
|
1707
1758
|
/** @internal */
|
|
1708
|
-
recur(recur) {
|
|
1709
|
-
return this.
|
|
1759
|
+
recur(recur, recurParameter = recur) {
|
|
1760
|
+
return this._rebuild(recur, recurParameter, false, this.checks, this.encodingChecks);
|
|
1710
1761
|
}
|
|
1711
1762
|
/** @internal */
|
|
1712
1763
|
getExpected() {
|
|
@@ -1735,14 +1786,10 @@ const parseProperties = /*#__PURE__*/iterateEager()({
|
|
|
1735
1786
|
}
|
|
1736
1787
|
}
|
|
1737
1788
|
});
|
|
1738
|
-
function
|
|
1739
|
-
if (!
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
if (!b.checks) {
|
|
1743
|
-
return checks;
|
|
1744
|
-
}
|
|
1745
|
-
return [...checks, ...b.checks];
|
|
1789
|
+
function combineChecks(a, b) {
|
|
1790
|
+
if (!a) return b;
|
|
1791
|
+
if (!b) return a;
|
|
1792
|
+
return [...a, ...b];
|
|
1746
1793
|
}
|
|
1747
1794
|
/** @internal */
|
|
1748
1795
|
export function struct(fields, checks, annotations) {
|
|
@@ -1770,10 +1817,10 @@ export function structWithRest(ast, records) {
|
|
|
1770
1817
|
let propertySignatures = ast.propertySignatures;
|
|
1771
1818
|
let indexSignatures = ast.indexSignatures;
|
|
1772
1819
|
let checks = ast.checks;
|
|
1773
|
-
for (const
|
|
1774
|
-
propertySignatures = propertySignatures.concat(
|
|
1775
|
-
indexSignatures = indexSignatures.concat(
|
|
1776
|
-
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);
|
|
1777
1824
|
}
|
|
1778
1825
|
return new Objects(propertySignatures, indexSignatures, undefined, checks);
|
|
1779
1826
|
}
|
|
@@ -1997,17 +2044,25 @@ export class Union extends Base {
|
|
|
1997
2044
|
});
|
|
1998
2045
|
};
|
|
1999
2046
|
}
|
|
2000
|
-
|
|
2047
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
2001
2048
|
const types = mapOrSame(this.types, recur);
|
|
2002
2049
|
return types === this.types ? this : new Union(types, this.mode, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
2003
2050
|
}
|
|
2004
2051
|
/** @internal */
|
|
2005
2052
|
recur(recur) {
|
|
2006
|
-
return this.
|
|
2053
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
2007
2054
|
}
|
|
2008
2055
|
/** @internal */
|
|
2009
2056
|
flip(recur) {
|
|
2010
|
-
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;
|
|
2011
2066
|
}
|
|
2012
2067
|
/** @internal */
|
|
2013
2068
|
getExpected(getExpected) {
|
|
@@ -2046,11 +2101,11 @@ const parseUnion = /*#__PURE__*/iterateEager()({
|
|
|
2046
2101
|
},
|
|
2047
2102
|
step(s, candidate, exit) {
|
|
2048
2103
|
if (exit._tag === "Failure") {
|
|
2049
|
-
const
|
|
2050
|
-
if (
|
|
2104
|
+
const issue = InternalSchemaCause.getSchemaIssue(exit.cause);
|
|
2105
|
+
if (issue === undefined) {
|
|
2051
2106
|
return exit;
|
|
2052
2107
|
}
|
|
2053
|
-
if (s.issues) s.issues.push(
|
|
2108
|
+
if (s.issues) s.issues.push(issue);else s.issues = [issue];
|
|
2054
2109
|
} else {
|
|
2055
2110
|
if (s.out && s.ast.mode === "oneOf") {
|
|
2056
2111
|
s.successes.push(candidate);
|
|
@@ -2094,7 +2149,7 @@ export function memoizeThunk(f) {
|
|
|
2094
2149
|
* define recursive or mutually recursive schemas without infinite loops at
|
|
2095
2150
|
* construction time.
|
|
2096
2151
|
*
|
|
2097
|
-
* **Example** (
|
|
2152
|
+
* **Example** (Defining recursive schema ASTs)
|
|
2098
2153
|
*
|
|
2099
2154
|
* ```ts
|
|
2100
2155
|
* import { Schema, SchemaAST } from "effect"
|
|
@@ -2350,7 +2405,7 @@ export function replaceChecks(ast, checks) {
|
|
|
2350
2405
|
}
|
|
2351
2406
|
/** @internal */
|
|
2352
2407
|
export function appendChecks(ast, checks) {
|
|
2353
|
-
return replaceChecks(ast, ast.checks
|
|
2408
|
+
return replaceChecks(ast, combineChecks(ast.checks, checks));
|
|
2354
2409
|
}
|
|
2355
2410
|
function updateLastLink(encoding, f) {
|
|
2356
2411
|
const links = encoding;
|
|
@@ -2461,42 +2516,33 @@ export function decodeTo(from, to, transformation) {
|
|
|
2461
2516
|
return appendTransformation(from, transformation, to);
|
|
2462
2517
|
}
|
|
2463
2518
|
function parseParameter(ast) {
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
return {
|
|
2480
|
-
literals: [],
|
|
2481
|
-
parameters: [ast]
|
|
2482
|
-
};
|
|
2483
|
-
case "Union":
|
|
2484
|
-
{
|
|
2485
|
-
const out = {
|
|
2486
|
-
literals: [],
|
|
2487
|
-
parameters: []
|
|
2488
|
-
};
|
|
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":
|
|
2489
2534
|
for (let i = 0; i < ast.types.length; i++) {
|
|
2490
|
-
|
|
2491
|
-
out.literals = out.literals.concat(parsed.literals);
|
|
2492
|
-
out.parameters = out.parameters.concat(parsed.parameters);
|
|
2535
|
+
go(ast.types[i]);
|
|
2493
2536
|
}
|
|
2494
|
-
return
|
|
2495
|
-
|
|
2537
|
+
return;
|
|
2538
|
+
default:
|
|
2539
|
+
parameters.push(ast);
|
|
2540
|
+
}
|
|
2496
2541
|
}
|
|
2542
|
+
go(ast);
|
|
2497
2543
|
return {
|
|
2498
|
-
literals
|
|
2499
|
-
parameters
|
|
2544
|
+
literals,
|
|
2545
|
+
parameters
|
|
2500
2546
|
};
|
|
2501
2547
|
}
|
|
2502
2548
|
/** @internal */
|
|
@@ -2647,39 +2693,6 @@ export function containsUndefined(ast) {
|
|
|
2647
2693
|
return false;
|
|
2648
2694
|
}
|
|
2649
2695
|
}
|
|
2650
|
-
function getTemplateLiteralSource(ast, top) {
|
|
2651
|
-
return ast.encodedParts.map(part => handleTemplateLiteralASTPartParens(part, getTemplateLiteralASTPartPattern(part), top)).join("");
|
|
2652
|
-
}
|
|
2653
|
-
/** @internal */
|
|
2654
|
-
export const getTemplateLiteralRegExp = /*#__PURE__*/memoize(ast => {
|
|
2655
|
-
return new globalThis.RegExp(`^${getTemplateLiteralSource(ast, true)}$`);
|
|
2656
|
-
});
|
|
2657
|
-
function getTemplateLiteralASTPartPattern(part) {
|
|
2658
|
-
switch (part._tag) {
|
|
2659
|
-
case "Literal":
|
|
2660
|
-
return RegEx.escape(globalThis.String(part.literal));
|
|
2661
|
-
case "String":
|
|
2662
|
-
return STRING_PATTERN;
|
|
2663
|
-
case "Number":
|
|
2664
|
-
return FINITE_PATTERN;
|
|
2665
|
-
case "BigInt":
|
|
2666
|
-
return BIGINT_PATTERN;
|
|
2667
|
-
case "TemplateLiteral":
|
|
2668
|
-
return getTemplateLiteralSource(part, false);
|
|
2669
|
-
case "Union":
|
|
2670
|
-
return part.types.map(getTemplateLiteralASTPartPattern).join("|");
|
|
2671
|
-
}
|
|
2672
|
-
}
|
|
2673
|
-
function handleTemplateLiteralASTPartParens(part, s, top) {
|
|
2674
|
-
if (isUnion(part)) {
|
|
2675
|
-
if (!top) {
|
|
2676
|
-
return `(?:${s})`;
|
|
2677
|
-
}
|
|
2678
|
-
} else if (!top) {
|
|
2679
|
-
return s;
|
|
2680
|
-
}
|
|
2681
|
-
return `(${s})`;
|
|
2682
|
-
}
|
|
2683
2696
|
function fromConst(ast, value) {
|
|
2684
2697
|
const succeed = Effect.succeedSome(value);
|
|
2685
2698
|
return oinput => {
|
|
@@ -2697,6 +2710,46 @@ function fromRefinement(ast, refinement) {
|
|
|
2697
2710
|
return refinement(oinput.value) ? Effect.succeed(oinput) : Effect.fail(new SchemaIssue.InvalidType(ast, oinput));
|
|
2698
2711
|
};
|
|
2699
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
|
+
}
|
|
2700
2753
|
/** @internal */
|
|
2701
2754
|
export const enumsToLiterals = /*#__PURE__*/memoize(ast => {
|
|
2702
2755
|
return new Union(ast.enums.map(e => new Literal(e[1], {
|
|
@@ -2710,29 +2763,38 @@ export function toCodec(f) {
|
|
|
2710
2763
|
}
|
|
2711
2764
|
return memoize(out);
|
|
2712
2765
|
}
|
|
2713
|
-
const
|
|
2766
|
+
const parameterFromPropertyKey = /*#__PURE__*/toCodec(ast => {
|
|
2714
2767
|
switch (ast._tag) {
|
|
2715
2768
|
default:
|
|
2716
2769
|
return ast;
|
|
2717
2770
|
case "Number":
|
|
2718
2771
|
return ast.toCodecStringTree();
|
|
2719
2772
|
case "Union":
|
|
2720
|
-
return ast.recur(
|
|
2773
|
+
return ast.recur(parameterFromPropertyKey);
|
|
2721
2774
|
}
|
|
2722
2775
|
});
|
|
2723
|
-
|
|
2776
|
+
/** @internal */
|
|
2777
|
+
export const parameterFromString = /*#__PURE__*/toCodec(ast => {
|
|
2724
2778
|
switch (ast._tag) {
|
|
2725
2779
|
default:
|
|
2726
2780
|
return ast;
|
|
2727
|
-
case "
|
|
2728
|
-
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:
|
|
2729
2791
|
return ast;
|
|
2730
|
-
case "BigInt":
|
|
2731
2792
|
case "Number":
|
|
2732
2793
|
case "Literal":
|
|
2794
|
+
case "BigInt":
|
|
2733
2795
|
return ast.toCodecStringTree();
|
|
2734
2796
|
case "Union":
|
|
2735
|
-
return ast.recur(
|
|
2797
|
+
return ast.recur(partFromString);
|
|
2736
2798
|
}
|
|
2737
2799
|
});
|
|
2738
2800
|
/**
|
|
@@ -2741,6 +2803,7 @@ const templateLiteralPartFromString = /*#__PURE__*/toCodec(ast => {
|
|
|
2741
2803
|
*/
|
|
2742
2804
|
export const STRING_PATTERN = "[\\s\\S]*?";
|
|
2743
2805
|
const isStringFiniteRegExp = /*#__PURE__*/new globalThis.RegExp(`^${FINITE_PATTERN}$`);
|
|
2806
|
+
const isStringNumberRegExp = /*#__PURE__*/new globalThis.RegExp(`(?:${FINITE_PATTERN}|Infinity|-Infinity|NaN)`);
|
|
2744
2807
|
/** @internal */
|
|
2745
2808
|
export function isStringFinite(annotations) {
|
|
2746
2809
|
return isPattern(isStringFiniteRegExp, {
|