effect 4.0.0-beta.22 → 4.0.0-beta.24
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/Schema.d.ts +21 -0
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +61 -17
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +30 -14
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +2 -0
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/ServiceMap.d.ts +1 -0
- package/dist/ServiceMap.d.ts.map +1 -1
- package/dist/ServiceMap.js.map +1 -1
- package/dist/internal/schema/representation.js +40 -103
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +80 -2
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +170 -0
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/package.json +1 -1
- package/src/Schema.ts +98 -18
- package/src/SchemaAST.ts +29 -19
- package/src/SchemaRepresentation.ts +2 -0
- package/src/ServiceMap.ts +1 -0
- package/src/internal/schema/representation.ts +37 -90
- package/src/unstable/http/HttpClient.ts +290 -2
- package/src/unstable/httpapi/HttpApi.ts +1 -1
- package/src/unstable/httpapi/OpenApi.ts +1 -1
package/dist/Schema.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import * as Arr from "./Array.js";
|
|
5
5
|
import * as BigDecimal_ from "./BigDecimal.js";
|
|
6
6
|
import * as Cause_ from "./Cause.js";
|
|
7
|
+
import * as Chunk_ from "./Chunk.js";
|
|
7
8
|
import * as Data from "./Data.js";
|
|
8
9
|
import * as DateTime from "./DateTime.js";
|
|
9
10
|
import * as Duration_ from "./Duration.js";
|
|
@@ -1248,17 +1249,6 @@ export function TaggedStruct(value, fields) {
|
|
|
1248
1249
|
...fields
|
|
1249
1250
|
});
|
|
1250
1251
|
}
|
|
1251
|
-
/** @internal */
|
|
1252
|
-
export function _getTagValueIfPropertyKey(tag, ast) {
|
|
1253
|
-
const ps = ast.propertySignatures.find(p => p.name === tag);
|
|
1254
|
-
if (ps) {
|
|
1255
|
-
if (AST.isLiteral(ps.type) && Predicate.isPropertyKey(ps.type.literal)) {
|
|
1256
|
-
return ps.type.literal;
|
|
1257
|
-
} else if (AST.isUniqueSymbol(ps.type)) {
|
|
1258
|
-
return ps.type.symbol;
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
1252
|
/**
|
|
1263
1253
|
* @since 4.0.0
|
|
1264
1254
|
* @experimental
|
|
@@ -1280,15 +1270,16 @@ export function toTaggedUnion(tag) {
|
|
|
1280
1270
|
if (AST.isUnion(ast) && "members" in schema && globalThis.Array.isArray(schema.members) && schema.members.every(isSchema)) {
|
|
1281
1271
|
return schema.members.forEach(walk);
|
|
1282
1272
|
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1273
|
+
const sentinels = AST.collectSentinels(ast);
|
|
1274
|
+
if (sentinels.length > 0) {
|
|
1275
|
+
const literal = sentinels.find(s => s.key === tag)?.literal;
|
|
1276
|
+
if (Predicate.isPropertyKey(literal)) {
|
|
1277
|
+
cases[literal] = schema;
|
|
1278
|
+
guards[literal] = is(toType(schema));
|
|
1288
1279
|
return;
|
|
1289
1280
|
}
|
|
1290
1281
|
}
|
|
1291
|
-
throw new globalThis.Error("No literal found");
|
|
1282
|
+
throw new globalThis.Error("No literal or unique symbol found");
|
|
1292
1283
|
}
|
|
1293
1284
|
function match() {
|
|
1294
1285
|
if (arguments.length === 1) {
|
|
@@ -3838,6 +3829,58 @@ export function HashSet(value) {
|
|
|
3838
3829
|
value
|
|
3839
3830
|
});
|
|
3840
3831
|
}
|
|
3832
|
+
/**
|
|
3833
|
+
* Creates a schema that validates a `Chunk` where values must conform to the
|
|
3834
|
+
* provided schema.
|
|
3835
|
+
*
|
|
3836
|
+
* @category Chunk
|
|
3837
|
+
* @since 4.0.0
|
|
3838
|
+
*/
|
|
3839
|
+
export function Chunk(value) {
|
|
3840
|
+
const schema = declareConstructor()([value], ([value]) => {
|
|
3841
|
+
const values = Array(value);
|
|
3842
|
+
return (input, ast, options) => {
|
|
3843
|
+
if (Chunk_.isChunk(input)) {
|
|
3844
|
+
return Effect.mapBothEager(Parser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
3845
|
+
onSuccess: Chunk_.fromIterable,
|
|
3846
|
+
onFailure: issue => new Issue.Composite(ast, Option_.some(input), [new Issue.Pointer(["values"], issue)])
|
|
3847
|
+
});
|
|
3848
|
+
}
|
|
3849
|
+
return Effect.fail(new Issue.InvalidType(ast, Option_.some(input)));
|
|
3850
|
+
};
|
|
3851
|
+
}, {
|
|
3852
|
+
typeConstructor: {
|
|
3853
|
+
_tag: "effect/Chunk"
|
|
3854
|
+
},
|
|
3855
|
+
generation: {
|
|
3856
|
+
runtime: `Schema.Chunk(?)`,
|
|
3857
|
+
Type: `Chunk.Chunk<?>`
|
|
3858
|
+
},
|
|
3859
|
+
expected: "Chunk",
|
|
3860
|
+
toCodec: ([value]) => link()(Array(value), Transformation.transform({
|
|
3861
|
+
decode: Chunk_.fromIterable,
|
|
3862
|
+
encode: Arr.fromIterable
|
|
3863
|
+
})),
|
|
3864
|
+
toArbitrary: ([value]) => (fc, ctx) => {
|
|
3865
|
+
return fc.oneof(ctx?.isSuspend ? {
|
|
3866
|
+
maxDepth: 2,
|
|
3867
|
+
depthIdentifier: "Chunk"
|
|
3868
|
+
} : {}, fc.constant([]), fc.array(value, ctx?.constraints?.array)).map(Chunk_.fromIterable);
|
|
3869
|
+
},
|
|
3870
|
+
toEquivalence: ([value]) => Chunk_.makeEquivalence(value),
|
|
3871
|
+
toFormatter: ([value]) => t => {
|
|
3872
|
+
const size = Chunk_.size(t);
|
|
3873
|
+
if (size === 0) {
|
|
3874
|
+
return "Chunk(0) {}";
|
|
3875
|
+
}
|
|
3876
|
+
const values = globalThis.Array.from(t).sort().map(v => `${value(v)}`);
|
|
3877
|
+
return `Chunk(${size}) { ${values.join(", ")} }`;
|
|
3878
|
+
}
|
|
3879
|
+
});
|
|
3880
|
+
return make(schema.ast, {
|
|
3881
|
+
value
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3841
3884
|
/**
|
|
3842
3885
|
* @since 4.0.0
|
|
3843
3886
|
*/
|
|
@@ -4893,6 +4936,7 @@ function getClassSchemaFactory(from, identifier, annotations) {
|
|
|
4893
4936
|
toCodec: ([from]) => new AST.Link(from.ast, transformation),
|
|
4894
4937
|
toArbitrary: ([from]) => () => from.map(args => new self(args)),
|
|
4895
4938
|
toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
|
|
4939
|
+
"~sentinels": AST.collectSentinels(from.ast),
|
|
4896
4940
|
...annotations
|
|
4897
4941
|
}));
|
|
4898
4942
|
memo = from.pipe(decodeTo(to, transformation));
|