effect 4.0.0-beta.50 → 4.0.0-beta.52
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/BigDecimal.d.ts.map +1 -1
- package/dist/BigDecimal.js +18 -14
- package/dist/BigDecimal.js.map +1 -1
- package/dist/BigInt.d.ts.map +1 -1
- package/dist/BigInt.js +4 -4
- package/dist/BigInt.js.map +1 -1
- package/dist/Brand.d.ts +2 -4
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js.map +1 -1
- package/dist/Data.js +2 -2
- package/dist/Data.js.map +1 -1
- package/dist/Duration.js +1 -1
- package/dist/Duration.js.map +1 -1
- package/dist/Schema.d.ts +77 -10
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +119 -18
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +6 -0
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +216 -229
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +3 -5
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +3 -2
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.d.ts.map +1 -1
- package/dist/SchemaIssue.js +29 -11
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.js +14 -2
- package/dist/SchemaParser.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +142 -65
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -2
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +37 -0
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +7 -0
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +2 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +2 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cluster/Runners.d.ts.map +1 -1
- package/dist/unstable/cluster/Runners.js +3 -2
- package/dist/unstable/cluster/Runners.js.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlMessageStorage.js +1 -0
- package/dist/unstable/cluster/SqlMessageStorage.js.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.d.ts.map +1 -1
- package/dist/unstable/cluster/SqlRunnerStorage.js +6 -6
- package/dist/unstable/cluster/SqlRunnerStorage.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventJournal.js +9 -8
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js +6 -5
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -1
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +6 -5
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +11 -6
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +5 -6
- 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 +17 -18
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +1 -2
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +28 -8
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +28 -15
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +4 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +2 -2
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -10
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +2 -11
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/observability/OtlpMetrics.js +1 -1
- package/dist/unstable/observability/OtlpMetrics.js.map +1 -1
- package/dist/unstable/observability/internal/protobuf.js +4 -4
- package/dist/unstable/observability/internal/protobuf.js.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.d.ts +11 -0
- package/dist/unstable/rpc/RpcSerialization.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcSerialization.js +14 -9
- package/dist/unstable/rpc/RpcSerialization.js.map +1 -1
- package/package.json +1 -1
- package/src/BigDecimal.ts +20 -16
- package/src/BigInt.ts +4 -4
- package/src/Brand.ts +2 -4
- package/src/Data.ts +1 -1
- package/src/Duration.ts +1 -1
- package/src/Schema.ts +183 -23
- package/src/SchemaAST.ts +315 -267
- package/src/SchemaGetter.ts +4 -6
- package/src/SchemaIssue.ts +28 -15
- package/src/SchemaParser.ts +8 -2
- package/src/index.ts +3 -0
- package/src/internal/effect.ts +196 -69
- package/src/internal/schema/representation.ts +1 -2
- package/src/internal/schema/schema.ts +43 -0
- package/src/unstable/ai/McpServer.ts +8 -0
- package/src/unstable/cli/index.ts +2 -0
- package/src/unstable/cluster/Runners.ts +8 -5
- package/src/unstable/cluster/SqlMessageStorage.ts +1 -0
- package/src/unstable/cluster/SqlRunnerStorage.ts +12 -6
- package/src/unstable/eventlog/SqlEventJournal.ts +10 -2
- package/src/unstable/eventlog/SqlEventLogServerEncrypted.ts +8 -3
- package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +9 -3
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/HttpApiBuilder.ts +13 -6
- package/src/unstable/httpapi/HttpApiClient.ts +5 -6
- package/src/unstable/httpapi/HttpApiEndpoint.ts +6 -7
- package/src/unstable/httpapi/HttpApiError.ts +43 -22
- package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
- package/src/unstable/httpapi/OpenApi.ts +3 -15
- package/src/unstable/observability/OtlpMetrics.ts +1 -1
- package/src/unstable/observability/internal/protobuf.ts +4 -4
- package/src/unstable/rpc/RpcSerialization.ts +41 -36
- package/dist/internal/schema/to-codec.d.ts +0 -2
- package/dist/internal/schema/to-codec.d.ts.map +0 -1
- package/dist/internal/schema/to-codec.js +0 -126
- package/dist/internal/schema/to-codec.js.map +0 -1
- package/src/internal/schema/to-codec.ts +0 -138
package/dist/Schema.js
CHANGED
|
@@ -96,7 +96,7 @@ import * as Equal from "./Equal.js";
|
|
|
96
96
|
import * as Equivalence from "./Equivalence.js";
|
|
97
97
|
import * as Exit_ from "./Exit.js";
|
|
98
98
|
import { format, formatPropertyKey } from "./Formatter.js";
|
|
99
|
-
import { identity } from "./Function.js";
|
|
99
|
+
import { identity, memoize } from "./Function.js";
|
|
100
100
|
import * as HashMap_ from "./HashMap.js";
|
|
101
101
|
import * as HashSet_ from "./HashSet.js";
|
|
102
102
|
import * as core from "./internal/core.js";
|
|
@@ -106,7 +106,6 @@ import * as InternalEquivalence from "./internal/schema/equivalence.js";
|
|
|
106
106
|
import * as InternalStandard from "./internal/schema/representation.js";
|
|
107
107
|
import * as InternalSchema from "./internal/schema/schema.js";
|
|
108
108
|
import { SchemaError } from "./internal/schema/schema.js";
|
|
109
|
-
import * as InternalToCodec from "./internal/schema/to-codec.js";
|
|
110
109
|
import * as JsonPatch from "./JsonPatch.js";
|
|
111
110
|
import * as JsonSchema from "./JsonSchema.js";
|
|
112
111
|
import { remainder } from "./Number.js";
|
|
@@ -2441,7 +2440,6 @@ export function instanceOf(constructor, annotations) {
|
|
|
2441
2440
|
* Used when building low-level AST transformations that bridge two schema types.
|
|
2442
2441
|
*
|
|
2443
2442
|
* @since 4.0.0
|
|
2444
|
-
* @experimental
|
|
2445
2443
|
*/
|
|
2446
2444
|
export function link() {
|
|
2447
2445
|
return (encodeTo, transformation) => {
|
|
@@ -2454,18 +2452,47 @@ export function link() {
|
|
|
2454
2452
|
/**
|
|
2455
2453
|
* Creates a custom filter check from a predicate function. The predicate
|
|
2456
2454
|
* receives the input value, the schema's AST, and parse options, and returns
|
|
2457
|
-
*
|
|
2455
|
+
* a value of type {@link FilterOutput}.
|
|
2456
|
+
*
|
|
2457
|
+
* **Example** (Failure at a nested path)
|
|
2458
2458
|
*
|
|
2459
|
-
* **Example** (Custom filter check)
|
|
2460
2459
|
* ```ts
|
|
2461
2460
|
* import { Schema } from "effect"
|
|
2462
2461
|
*
|
|
2463
|
-
*
|
|
2464
|
-
*
|
|
2465
|
-
*
|
|
2462
|
+
* const schema = Schema.Struct({ password: Schema.String, confirmPassword: Schema.String }).check(
|
|
2463
|
+
* Schema.makeFilter((o) =>
|
|
2464
|
+
* o.password === o.confirmPassword
|
|
2465
|
+
* ? undefined
|
|
2466
|
+
* : { path: ["password"], issue: "password and confirmPassword must match" }
|
|
2467
|
+
* )
|
|
2466
2468
|
* )
|
|
2467
2469
|
*
|
|
2468
|
-
*
|
|
2470
|
+
* console.log(String(Schema.decodeUnknownExit(schema)({ password: "123456", confirmPassword: "1234567" })))
|
|
2471
|
+
* // Failure(Cause([Fail(SchemaError: password and confirmPassword must match
|
|
2472
|
+
* // at ["password"])]))
|
|
2473
|
+
* ```
|
|
2474
|
+
*
|
|
2475
|
+
* **Example** (Reporting multiple failures at once)
|
|
2476
|
+
*
|
|
2477
|
+
* ```ts
|
|
2478
|
+
* import { Schema } from "effect"
|
|
2479
|
+
*
|
|
2480
|
+
* const schema = Schema.Struct({ a: Schema.Finite, b: Schema.Finite, c: Schema.Finite }).check(
|
|
2481
|
+
* Schema.makeFilter((o) => {
|
|
2482
|
+
* const issues: Array<Schema.FilterIssue> = []
|
|
2483
|
+
* if (o.a > 0) {
|
|
2484
|
+
* if (o.b <= 0) issues.push({ path: ["b"], issue: "b must be greater than 0" })
|
|
2485
|
+
* if (o.c <= 0) issues.push({ path: ["c"], issue: "c must be greater than 0" })
|
|
2486
|
+
* }
|
|
2487
|
+
* return issues
|
|
2488
|
+
* })
|
|
2489
|
+
* )
|
|
2490
|
+
*
|
|
2491
|
+
* console.log(String(Schema.decodeUnknownExit(schema)({ a: 1, b: 0, c: 0 })))
|
|
2492
|
+
* // Failure(Cause([Fail(SchemaError: b must be greater than 0
|
|
2493
|
+
* // at ["b"]
|
|
2494
|
+
* // c must be greater than 0
|
|
2495
|
+
* // at ["c"])]))
|
|
2469
2496
|
* ```
|
|
2470
2497
|
*
|
|
2471
2498
|
* @category Checks Constructors
|
|
@@ -5287,6 +5314,7 @@ export const Duration = /*#__PURE__*/declare(Duration_.isDuration, {
|
|
|
5287
5314
|
toFormatter: () => globalThis.String,
|
|
5288
5315
|
toEquivalence: () => Duration_.Equivalence
|
|
5289
5316
|
});
|
|
5317
|
+
const bigint0 = /*#__PURE__*/globalThis.BigInt(0);
|
|
5290
5318
|
/**
|
|
5291
5319
|
* A transformation schema that decodes a non-negative `bigint` into a
|
|
5292
5320
|
* `Duration`, treating the `bigint` value as the duration in nanoseconds.
|
|
@@ -5300,7 +5328,7 @@ export const Duration = /*#__PURE__*/declare(Duration_.isDuration, {
|
|
|
5300
5328
|
* @category Duration
|
|
5301
5329
|
* @since 4.0.0
|
|
5302
5330
|
*/
|
|
5303
|
-
export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualToBigInt(
|
|
5331
|
+
export const DurationFromNanos = /*#__PURE__*/BigInt.check(isGreaterThanOrEqualToBigInt(bigint0)).pipe(/*#__PURE__*/decodeTo(Duration, Transformation.durationFromNanos));
|
|
5304
5332
|
/**
|
|
5305
5333
|
* A transformation schema that decodes a non-negative (possibly infinite)
|
|
5306
5334
|
* integer into a `Duration`, treating the integer value as the duration in
|
|
@@ -6782,7 +6810,60 @@ export function toJsonSchemaDocument(schema, options) {
|
|
|
6782
6810
|
* @since 4.0.0
|
|
6783
6811
|
*/
|
|
6784
6812
|
export function toCodecJson(schema) {
|
|
6785
|
-
return make(
|
|
6813
|
+
return make(toCodecJsonTop(schema.ast));
|
|
6814
|
+
}
|
|
6815
|
+
const toCodecJsonTop = /*#__PURE__*/AST.toCodec(ast => {
|
|
6816
|
+
const out = toCodecJsonBase(ast, toCodecJsonTop);
|
|
6817
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out;
|
|
6818
|
+
});
|
|
6819
|
+
function toCodecJsonBase(ast, recur) {
|
|
6820
|
+
switch (ast._tag) {
|
|
6821
|
+
case "Declaration":
|
|
6822
|
+
{
|
|
6823
|
+
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec;
|
|
6824
|
+
if (Predicate.isFunction(getLink)) {
|
|
6825
|
+
const tps = AST.isDeclaration(ast) ? ast.typeParameters.map(tp => InternalSchema.make(AST.toEncoded(tp))) : [];
|
|
6826
|
+
const link = getLink(tps);
|
|
6827
|
+
const to = recur(link.to);
|
|
6828
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
6829
|
+
}
|
|
6830
|
+
return AST.replaceEncoding(ast, [AST.unknownToNull]);
|
|
6831
|
+
}
|
|
6832
|
+
case "Unknown":
|
|
6833
|
+
case "ObjectKeyword":
|
|
6834
|
+
return AST.replaceEncoding(ast, [AST.unknownToJson]);
|
|
6835
|
+
case "Undefined":
|
|
6836
|
+
case "Void":
|
|
6837
|
+
case "Literal":
|
|
6838
|
+
case "Number":
|
|
6839
|
+
return ast.toCodecJson();
|
|
6840
|
+
case "UniqueSymbol":
|
|
6841
|
+
case "Symbol":
|
|
6842
|
+
case "BigInt":
|
|
6843
|
+
return ast.toCodecStringTree();
|
|
6844
|
+
case "Objects":
|
|
6845
|
+
{
|
|
6846
|
+
if (ast.propertySignatures.some(ps => typeof ps.name !== "string")) {
|
|
6847
|
+
throw new globalThis.Error("Objects property names must be strings", {
|
|
6848
|
+
cause: ast
|
|
6849
|
+
});
|
|
6850
|
+
}
|
|
6851
|
+
return ast.recur(recur);
|
|
6852
|
+
}
|
|
6853
|
+
case "Union":
|
|
6854
|
+
{
|
|
6855
|
+
const sortedTypes = InternalSchema.jsonReorder(ast.types);
|
|
6856
|
+
if (sortedTypes !== ast.types) {
|
|
6857
|
+
return new AST.Union(sortedTypes, ast.mode, ast.annotations, ast.checks, ast.encoding, ast.context).recur(recur);
|
|
6858
|
+
}
|
|
6859
|
+
return ast.recur(recur);
|
|
6860
|
+
}
|
|
6861
|
+
case "Arrays":
|
|
6862
|
+
case "Suspend":
|
|
6863
|
+
return ast.recur(recur);
|
|
6864
|
+
}
|
|
6865
|
+
// `Schema.Any` is used as an escape hatch
|
|
6866
|
+
return ast;
|
|
6786
6867
|
}
|
|
6787
6868
|
/**
|
|
6788
6869
|
* Derives an isomorphism codec from a schema. The encoded form is the
|
|
@@ -6792,14 +6873,34 @@ export function toCodecJson(schema) {
|
|
|
6792
6873
|
* @since 4.0.0
|
|
6793
6874
|
*/
|
|
6794
6875
|
export function toCodecIso(schema) {
|
|
6795
|
-
return make(
|
|
6876
|
+
return make(toCodecIsoTop(AST.toType(schema.ast)));
|
|
6796
6877
|
}
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6878
|
+
const toCodecIsoTop = /*#__PURE__*/memoize(ast => {
|
|
6879
|
+
const out = toCodecIsoBase(ast, toCodecIsoTop);
|
|
6880
|
+
return out !== ast && AST.isOptional(ast) ? AST.optionalKeyLastLink(out) : out;
|
|
6881
|
+
});
|
|
6882
|
+
function toCodecIsoBase(ast, recur) {
|
|
6883
|
+
switch (ast._tag) {
|
|
6884
|
+
case "Declaration":
|
|
6885
|
+
{
|
|
6886
|
+
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec;
|
|
6887
|
+
if (Predicate.isFunction(getLink)) {
|
|
6888
|
+
const link = getLink(ast.typeParameters.map(tp => InternalSchema.make(tp)));
|
|
6889
|
+
const to = recur(link.to);
|
|
6890
|
+
return AST.replaceEncoding(ast, to === link.to ? [link] : [new AST.Link(to, link.transformation)]);
|
|
6891
|
+
}
|
|
6892
|
+
return ast;
|
|
6893
|
+
}
|
|
6894
|
+
case "Arrays":
|
|
6895
|
+
case "Objects":
|
|
6896
|
+
case "Union":
|
|
6897
|
+
case "Suspend":
|
|
6898
|
+
return ast.recur(recur);
|
|
6802
6899
|
}
|
|
6900
|
+
return ast;
|
|
6901
|
+
}
|
|
6902
|
+
export function toCodecStringTree(schema, options) {
|
|
6903
|
+
return make(toCodecEnsureArray(options?.keepDeclarations === true ? serializerStringTreeKeepDeclarations(schema.ast) : serializerStringTree(schema.ast)));
|
|
6803
6904
|
}
|
|
6804
6905
|
/**
|
|
6805
6906
|
* Derives an XML encoder from a codec. Encodes a value to an XML string by
|
|
@@ -6919,7 +7020,7 @@ function getStringTreePriority(ast) {
|
|
|
6919
7020
|
return 1;
|
|
6920
7021
|
}
|
|
6921
7022
|
}
|
|
6922
|
-
const treeReorder = /*#__PURE__*/
|
|
7023
|
+
const treeReorder = /*#__PURE__*/InternalSchema.makeReorder(getStringTreePriority);
|
|
6923
7024
|
function serializerTree(ast, recur, onMissingAnnotation) {
|
|
6924
7025
|
switch (ast._tag) {
|
|
6925
7026
|
case "Declaration":
|