effect 4.0.0-beta.84 → 4.0.0-beta.86
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/ChannelSchema.d.ts +8 -8
- package/dist/ChannelSchema.d.ts.map +1 -1
- package/dist/Config.d.ts +2 -2
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +10 -3
- package/dist/Config.js.map +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/Cron.d.ts.map +1 -1
- package/dist/Cron.js +4 -0
- package/dist/Cron.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 +793 -399
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +121 -75
- 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 +207 -157
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaParser.d.ts +24 -24
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +43 -39
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +300 -300
- package/dist/internal/effect.js +16 -17
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/matcher.js +0 -2
- package/dist/internal/matcher.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/representation.js +1 -5
- package/dist/internal/schema/representation.js.map +1 -1
- 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 +9 -9
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +3 -2
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +2 -2
- package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +4 -4
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +13 -6
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpSchema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts +4 -4
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +2 -2
- package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
- package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
- package/dist/unstable/ai/Response.d.ts +2 -2
- package/dist/unstable/ai/Response.d.ts.map +1 -1
- package/dist/unstable/ai/Response.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts +26 -26
- 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/Argument.d.ts +8 -7
- package/dist/unstable/cli/Argument.d.ts.map +1 -1
- package/dist/unstable/cli/Argument.js.map +1 -1
- package/dist/unstable/cli/Flag.d.ts +8 -7
- package/dist/unstable/cli/Flag.d.ts.map +1 -1
- package/dist/unstable/cli/Flag.js.map +1 -1
- package/dist/unstable/cli/Param.d.ts +1806 -168
- package/dist/unstable/cli/Param.d.ts.map +1 -1
- package/dist/unstable/cli/Param.js +0 -70
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/Primitive.d.ts +3 -4
- package/dist/unstable/cli/Primitive.d.ts.map +1 -1
- package/dist/unstable/cli/Primitive.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +0 -22
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/config.d.ts +48 -0
- package/dist/unstable/cli/internal/config.d.ts.map +1 -1
- package/dist/unstable/cli/internal/config.js +0 -6
- package/dist/unstable/cli/internal/config.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -3
- package/dist/unstable/cluster/Reply.d.ts +2 -2
- package/dist/unstable/cluster/Reply.d.ts.map +1 -1
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
- package/dist/unstable/encoding/Msgpack.d.ts +6 -6
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +8 -8
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.d.ts +1 -1
- package/dist/unstable/encoding/Sse.d.ts.map +1 -1
- package/dist/unstable/encoding/Sse.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +22 -22
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.d.ts +15 -15
- package/dist/unstable/http/HttpBody.d.ts +1 -1
- package/dist/unstable/http/HttpBody.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
- package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
- package/dist/unstable/http/HttpMiddleware.js +12 -3
- package/dist/unstable/http/HttpMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +32 -32
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +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/HttpApiSchema.d.ts +13 -6
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js +0 -13
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/internal/otlpProtobuf.js +0 -68
- package/dist/unstable/observability/internal/otlpProtobuf.js.map +1 -1
- package/dist/unstable/observability/internal/protobuf.js +0 -28
- package/dist/unstable/observability/internal/protobuf.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.d.ts +2 -2
- package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
- package/dist/unstable/persistence/Persistable.d.ts +6 -6
- package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.d.ts +3 -3
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +1 -1
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Persistence.d.ts +5 -5
- package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts +2 -2
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +1 -1
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +3 -4
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js +1 -1
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +25 -4
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcMessage.d.ts +7 -0
- package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMessage.js +20 -0
- package/dist/unstable/rpc/RpcMessage.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +2 -2
- 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/rpc/RpcSchema.d.ts +10 -3
- package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSchema.js.map +1 -1
- package/dist/unstable/rpc/RpcWorker.d.ts +3 -3
- package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
- package/dist/unstable/schema/Model.d.ts +2 -2
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +16 -2
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/sql/SqlConnection.d.ts +1 -0
- package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
- package/dist/unstable/sql/SqlConnection.js.map +1 -1
- package/dist/unstable/sql/SqlModel.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts +4 -4
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/sql/SqlSchema.d.ts +5 -5
- package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.d.ts +1 -0
- package/dist/unstable/sql/Statement.d.ts.map +1 -1
- package/dist/unstable/sql/Statement.js +3 -0
- package/dist/unstable/sql/Statement.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +2 -2
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.d.ts +18 -18
- package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts +3 -3
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.d.ts +3 -3
- package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ChannelSchema.ts +9 -9
- package/src/Config.ts +12 -5
- package/src/Context.ts +4 -5
- package/src/Cron.ts +4 -0
- package/src/Layer.ts +4 -4
- package/src/LayerMap.ts +4 -3
- package/src/Random.ts +42 -0
- package/src/Schema.ts +1038 -710
- package/src/SchemaAST.ts +239 -169
- package/src/SchemaParser.ts +85 -77
- package/src/internal/effect.ts +17 -33
- package/src/internal/matcher.ts +0 -5
- package/src/internal/schema/arbitrary.ts +24 -3
- package/src/internal/schema/representation.ts +1 -5
- package/src/internal/schema/schema.ts +1 -1
- package/src/internal/stackTraceLimit.ts +63 -0
- package/src/internal/tracer.ts +4 -3
- package/src/testing/TestSchema.ts +14 -13
- package/src/unstable/ai/AnthropicStructuredOutput.ts +2 -2
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/LanguageModel.ts +7 -7
- package/src/unstable/ai/McpSchema.ts +16 -14
- package/src/unstable/ai/McpServer.ts +7 -7
- package/src/unstable/ai/OpenAiStructuredOutput.ts +2 -2
- package/src/unstable/ai/Response.ts +9 -5
- package/src/unstable/ai/Tool.ts +53 -50
- package/src/unstable/cli/Argument.ts +9 -8
- package/src/unstable/cli/Flag.ts +9 -8
- package/src/unstable/cli/Param.ts +6 -146
- package/src/unstable/cli/Primitive.ts +5 -6
- package/src/unstable/cli/internal/ansi.ts +0 -33
- package/src/unstable/cli/internal/config.ts +0 -8
- package/src/unstable/cli/internal/parser.ts +2 -2
- package/src/unstable/cluster/MessageStorage.ts +1 -1
- package/src/unstable/cluster/Reply.ts +6 -2
- package/src/unstable/devtools/DevToolsSchema.ts +1 -1
- package/src/unstable/encoding/Msgpack.ts +9 -7
- package/src/unstable/encoding/Ndjson.ts +10 -10
- package/src/unstable/encoding/Sse.ts +1 -1
- package/src/unstable/eventlog/Event.ts +3 -3
- package/src/unstable/http/HttpBody.ts +1 -1
- package/src/unstable/http/HttpClientRequest.ts +1 -1
- package/src/unstable/http/HttpIncomingMessage.ts +1 -1
- package/src/unstable/http/HttpMiddleware.ts +12 -3
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +9 -5
- package/src/unstable/httpapi/HttpApiClient.ts +10 -10
- package/src/unstable/httpapi/HttpApiEndpoint.ts +45 -33
- package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
- package/src/unstable/httpapi/HttpApiSchema.ts +16 -43
- package/src/unstable/httpapi/OpenApi.ts +5 -5
- package/src/unstable/observability/internal/otlpProtobuf.ts +0 -75
- package/src/unstable/observability/internal/protobuf.ts +0 -42
- package/src/unstable/persistence/KeyValueStore.ts +2 -2
- package/src/unstable/persistence/Persistable.ts +7 -7
- package/src/unstable/persistence/PersistedQueue.ts +4 -4
- package/src/unstable/persistence/Persistence.ts +5 -5
- package/src/unstable/reactivity/AsyncResult.ts +4 -4
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +1 -1
- package/src/unstable/rpc/Rpc.ts +7 -8
- package/src/unstable/rpc/RpcClient.ts +26 -4
- package/src/unstable/rpc/RpcMessage.ts +19 -0
- package/src/unstable/rpc/RpcMiddleware.ts +6 -5
- package/src/unstable/rpc/RpcSchema.ts +12 -9
- package/src/unstable/rpc/RpcWorker.ts +3 -3
- package/src/unstable/schema/Model.ts +2 -2
- package/src/unstable/schema/VariantSchema.ts +19 -17
- package/src/unstable/sql/SqlConnection.ts +5 -0
- package/src/unstable/sql/SqlModel.ts +2 -2
- package/src/unstable/sql/SqlResolver.ts +6 -6
- package/src/unstable/sql/SqlSchema.ts +5 -5
- package/src/unstable/sql/Statement.ts +11 -0
- package/src/unstable/workflow/Activity.ts +6 -6
- package/src/unstable/workflow/DurableDeferred.ts +33 -33
- package/src/unstable/workflow/Workflow.ts +5 -5
- package/src/unstable/workflow/WorkflowEngine.ts +10 -10
- package/dist/internal/concurrency.d.ts +0 -2
- package/dist/internal/concurrency.d.ts.map +0 -1
- package/dist/internal/concurrency.js +0 -29
- package/dist/internal/concurrency.js.map +0 -1
- package/src/internal/concurrency.ts +0 -52
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
|
-
return tps === this.typeParameters ? this : new Declaration(tps, this.run, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
454
|
+
return tps === this.typeParameters && checks === this.checks && encodingChecks === this.encodingChecks ? 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
|
-
return elements === this.elements && rest === this.rest ? this : new Arrays(this.isMutable, elements, rest, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
1339
|
+
return elements === this.elements && rest === this.rest && checks === this.checks && encodingChecks === this.encodingChecks ? 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,26 +1738,26 @@ 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);
|
|
1704
1751
|
});
|
|
1705
|
-
return props === this.propertySignatures && indexes === this.indexSignatures ? this : new Objects(props, indexes, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
1752
|
+
return props === this.propertySignatures && indexes === this.indexSignatures && checks === this.checks && encodingChecks === this.encodingChecks ? this : new Objects(props, indexes, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
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
|
-
return types === this.types ? this : new Union(types, this.mode, this.annotations, checks, undefined, this.context, encodingChecks);
|
|
2049
|
+
return types === this.types && checks === this.checks && encodingChecks === this.encodingChecks ? 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) {
|
|
@@ -2143,18 +2194,6 @@ export class Suspend extends Base {
|
|
|
2143
2194
|
return getExpected(this.thunk());
|
|
2144
2195
|
}
|
|
2145
2196
|
}
|
|
2146
|
-
/** @internal */
|
|
2147
|
-
export function getEncodingChecks(ast) {
|
|
2148
|
-
switch (ast._tag) {
|
|
2149
|
-
case "Declaration":
|
|
2150
|
-
case "Arrays":
|
|
2151
|
-
case "Objects":
|
|
2152
|
-
case "Union":
|
|
2153
|
-
return ast.encodingChecks;
|
|
2154
|
-
default:
|
|
2155
|
-
return undefined;
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
2197
|
// -----------------------------------------------------------------------------
|
|
2159
2198
|
// Checks
|
|
2160
2199
|
// -----------------------------------------------------------------------------
|
|
@@ -2354,7 +2393,7 @@ export function replaceChecks(ast, checks) {
|
|
|
2354
2393
|
}
|
|
2355
2394
|
/** @internal */
|
|
2356
2395
|
export function appendChecks(ast, checks) {
|
|
2357
|
-
return replaceChecks(ast, ast.checks
|
|
2396
|
+
return replaceChecks(ast, combineChecks(ast.checks, checks));
|
|
2358
2397
|
}
|
|
2359
2398
|
function updateLastLink(encoding, f) {
|
|
2360
2399
|
const links = encoding;
|
|
@@ -2370,6 +2409,13 @@ export function applyToLastLink(f) {
|
|
|
2370
2409
|
return ast => ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, f)) : ast;
|
|
2371
2410
|
}
|
|
2372
2411
|
/** @internal */
|
|
2412
|
+
export function applyToSelfOrLastLinkEncoding(f) {
|
|
2413
|
+
function out(ast) {
|
|
2414
|
+
return ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, out)) : f(ast);
|
|
2415
|
+
}
|
|
2416
|
+
return memoize(out);
|
|
2417
|
+
}
|
|
2418
|
+
/** @internal */
|
|
2373
2419
|
export function middlewareDecoding(ast, middleware) {
|
|
2374
2420
|
return appendTransformation(ast, middleware, toType(ast));
|
|
2375
2421
|
}
|
|
@@ -2465,42 +2511,33 @@ export function decodeTo(from, to, transformation) {
|
|
|
2465
2511
|
return appendTransformation(from, transformation, to);
|
|
2466
2512
|
}
|
|
2467
2513
|
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
|
-
};
|
|
2514
|
+
const literals = [];
|
|
2515
|
+
const parameters = [];
|
|
2516
|
+
function go(ast) {
|
|
2517
|
+
switch (ast._tag) {
|
|
2518
|
+
case "Literal":
|
|
2519
|
+
if (Predicate.isPropertyKey(ast.literal)) {
|
|
2520
|
+
literals.push(ast.literal);
|
|
2521
|
+
}
|
|
2522
|
+
return;
|
|
2523
|
+
case "UniqueSymbol":
|
|
2524
|
+
literals.push(ast.symbol);
|
|
2525
|
+
return;
|
|
2526
|
+
case "Never":
|
|
2527
|
+
return;
|
|
2528
|
+
case "Union":
|
|
2493
2529
|
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);
|
|
2530
|
+
go(ast.types[i]);
|
|
2497
2531
|
}
|
|
2498
|
-
return
|
|
2499
|
-
|
|
2532
|
+
return;
|
|
2533
|
+
default:
|
|
2534
|
+
parameters.push(ast);
|
|
2535
|
+
}
|
|
2500
2536
|
}
|
|
2537
|
+
go(ast);
|
|
2501
2538
|
return {
|
|
2502
|
-
literals
|
|
2503
|
-
parameters
|
|
2539
|
+
literals,
|
|
2540
|
+
parameters
|
|
2504
2541
|
};
|
|
2505
2542
|
}
|
|
2506
2543
|
/** @internal */
|
|
@@ -2565,9 +2602,13 @@ export const toType = /*#__PURE__*/memoize(ast => {
|
|
|
2565
2602
|
}
|
|
2566
2603
|
const out = ast;
|
|
2567
2604
|
const type = out.recur?.(toType) ?? out;
|
|
2568
|
-
|
|
2605
|
+
const encodingChecks = type.encodingChecks;
|
|
2606
|
+
if (encodingChecks) {
|
|
2569
2607
|
return modifyOwnPropertyDescriptors(type, d => {
|
|
2570
2608
|
d.encodingChecks.value = undefined;
|
|
2609
|
+
if (type === ast) {
|
|
2610
|
+
d.checks.value = combineChecks(type.checks, encodingChecks);
|
|
2611
|
+
}
|
|
2571
2612
|
});
|
|
2572
2613
|
}
|
|
2573
2614
|
return type;
|
|
@@ -2651,39 +2692,6 @@ export function containsUndefined(ast) {
|
|
|
2651
2692
|
return false;
|
|
2652
2693
|
}
|
|
2653
2694
|
}
|
|
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
2695
|
function fromConst(ast, value) {
|
|
2688
2696
|
const succeed = Effect.succeedSome(value);
|
|
2689
2697
|
return oinput => {
|
|
@@ -2701,42 +2709,84 @@ function fromRefinement(ast, refinement) {
|
|
|
2701
2709
|
return refinement(oinput.value) ? Effect.succeed(oinput) : Effect.fail(new SchemaIssue.InvalidType(ast, oinput));
|
|
2702
2710
|
};
|
|
2703
2711
|
}
|
|
2712
|
+
function applyTemplateLiteralPartChecks(ast, value, options) {
|
|
2713
|
+
if (options?.disableChecks || ast.checks === undefined) return value;
|
|
2714
|
+
const issues = [];
|
|
2715
|
+
collectIssues(ast.checks, value, issues, ast, options);
|
|
2716
|
+
return issues.length === 0 ? value : undefined;
|
|
2717
|
+
}
|
|
2718
|
+
function segmentTemplateLiteralParts(parts, input, options) {
|
|
2719
|
+
const out = new Array(parts.length);
|
|
2720
|
+
const failures = new Set();
|
|
2721
|
+
function go(i, pos) {
|
|
2722
|
+
if (i === parts.length) return pos === input.length;
|
|
2723
|
+
const key = `${i}/${pos}`;
|
|
2724
|
+
if (failures.has(key)) return false;
|
|
2725
|
+
const part = parts[i];
|
|
2726
|
+
if (i === parts.length - 1) {
|
|
2727
|
+
const s = input.slice(pos);
|
|
2728
|
+
if (part.matchPart(s, options) !== undefined) {
|
|
2729
|
+
out[i] = s;
|
|
2730
|
+
return true;
|
|
2731
|
+
}
|
|
2732
|
+
} else if (part._tag === "Literal") {
|
|
2733
|
+
const s = globalThis.String(part.literal);
|
|
2734
|
+
if (input.startsWith(s, pos) && go(i + 1, pos + s.length)) {
|
|
2735
|
+
out[i] = s;
|
|
2736
|
+
return true;
|
|
2737
|
+
}
|
|
2738
|
+
} else {
|
|
2739
|
+
for (let end = input.length; end >= pos; end--) {
|
|
2740
|
+
const s = input.slice(pos, end);
|
|
2741
|
+
if (part.matchPart(s, options) !== undefined && go(i + 1, end)) {
|
|
2742
|
+
out[i] = s;
|
|
2743
|
+
return true;
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
failures.add(key);
|
|
2748
|
+
return false;
|
|
2749
|
+
}
|
|
2750
|
+
return go(0, 0) ? out : undefined;
|
|
2751
|
+
}
|
|
2704
2752
|
/** @internal */
|
|
2705
2753
|
export const enumsToLiterals = /*#__PURE__*/memoize(ast => {
|
|
2706
2754
|
return new Union(ast.enums.map(e => new Literal(e[1], {
|
|
2707
2755
|
title: e[0]
|
|
2708
2756
|
})), "anyOf");
|
|
2709
2757
|
});
|
|
2710
|
-
|
|
2711
|
-
export function toCodec(f) {
|
|
2712
|
-
function out(ast) {
|
|
2713
|
-
return ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, out)) : f(ast);
|
|
2714
|
-
}
|
|
2715
|
-
return memoize(out);
|
|
2716
|
-
}
|
|
2717
|
-
const indexSignatureParameterFromString = /*#__PURE__*/toCodec(ast => {
|
|
2758
|
+
const parameterFromPropertyKey = /*#__PURE__*/applyToSelfOrLastLinkEncoding(ast => {
|
|
2718
2759
|
switch (ast._tag) {
|
|
2719
2760
|
default:
|
|
2720
2761
|
return ast;
|
|
2721
2762
|
case "Number":
|
|
2722
2763
|
return ast.toCodecStringTree();
|
|
2723
2764
|
case "Union":
|
|
2724
|
-
return ast.recur(
|
|
2765
|
+
return ast.recur(parameterFromPropertyKey);
|
|
2725
2766
|
}
|
|
2726
2767
|
});
|
|
2727
|
-
|
|
2768
|
+
/** @internal */
|
|
2769
|
+
export const parameterFromString = /*#__PURE__*/applyToSelfOrLastLinkEncoding(ast => {
|
|
2728
2770
|
switch (ast._tag) {
|
|
2729
2771
|
default:
|
|
2730
2772
|
return ast;
|
|
2731
|
-
case "
|
|
2732
|
-
case "
|
|
2773
|
+
case "Symbol":
|
|
2774
|
+
case "UniqueSymbol":
|
|
2775
|
+
return ast.toCodecStringTree();
|
|
2776
|
+
case "Union":
|
|
2777
|
+
return ast.recur(parameterFromString);
|
|
2778
|
+
}
|
|
2779
|
+
});
|
|
2780
|
+
const partFromString = /*#__PURE__*/applyToSelfOrLastLinkEncoding(ast => {
|
|
2781
|
+
switch (ast._tag) {
|
|
2782
|
+
default:
|
|
2733
2783
|
return ast;
|
|
2734
|
-
case "BigInt":
|
|
2735
2784
|
case "Number":
|
|
2736
2785
|
case "Literal":
|
|
2786
|
+
case "BigInt":
|
|
2737
2787
|
return ast.toCodecStringTree();
|
|
2738
2788
|
case "Union":
|
|
2739
|
-
return ast.recur(
|
|
2789
|
+
return ast.recur(partFromString);
|
|
2740
2790
|
}
|
|
2741
2791
|
});
|
|
2742
2792
|
/**
|
|
@@ -2745,6 +2795,7 @@ const templateLiteralPartFromString = /*#__PURE__*/toCodec(ast => {
|
|
|
2745
2795
|
*/
|
|
2746
2796
|
export const STRING_PATTERN = "[\\s\\S]*?";
|
|
2747
2797
|
const isStringFiniteRegExp = /*#__PURE__*/new globalThis.RegExp(`^${FINITE_PATTERN}$`);
|
|
2798
|
+
const isStringNumberRegExp = /*#__PURE__*/new globalThis.RegExp(`(?:${FINITE_PATTERN}|Infinity|-Infinity|NaN)`);
|
|
2748
2799
|
/** @internal */
|
|
2749
2800
|
export function isStringFinite(annotations) {
|
|
2750
2801
|
return isPattern(isStringFiniteRegExp, {
|
|
@@ -3015,8 +3066,7 @@ export function isStringTree(u) {
|
|
|
3015
3066
|
}
|
|
3016
3067
|
}
|
|
3017
3068
|
const StringTree = /*#__PURE__*/new Declaration([], () => (input, ast) => isStringTree(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option.some(input))), {
|
|
3018
|
-
expected: "StringTree"
|
|
3019
|
-
toCodecStringTree: () => new Link(unknown, SchemaTransformation.passthrough())
|
|
3069
|
+
expected: "StringTree"
|
|
3020
3070
|
});
|
|
3021
3071
|
/** @internal */
|
|
3022
3072
|
export const unknownToStringTree = /*#__PURE__*/new Link(StringTree, /*#__PURE__*/SchemaTransformation.passthrough());
|