mirror of
https://github.com/Effect-TS/effect.git
synced 2026-12-02 03:15:52 +08:00
rename map to derive (#162)
This commit is contained in:
+66
-38
@@ -1471,7 +1471,7 @@ const schema: Schema.Struct<{
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.pick(["a"]))
|
||||
}).derive(Struct.pick(["a"]))
|
||||
```
|
||||
|
||||
#### Omit
|
||||
@@ -1491,7 +1491,7 @@ const schema: Schema.Struct<{
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.omit(["b"]))
|
||||
}).derive(Struct.omit(["b"]))
|
||||
```
|
||||
|
||||
#### Merge
|
||||
@@ -1513,7 +1513,7 @@ const schema: Schema.Struct<{
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(
|
||||
}).derive(
|
||||
Struct.merge({
|
||||
c: Schema.Boolean
|
||||
})
|
||||
@@ -1532,7 +1532,7 @@ const original = Schema.Struct({
|
||||
b: Schema.String
|
||||
}).check(SchemaCheck.make(({ a, b }) => a === b, { title: "a === b" }))
|
||||
|
||||
const schema = original.map(Struct.merge({ c: Schema.String }), {
|
||||
const schema = original.derive(Struct.merge({ c: Schema.String }), {
|
||||
preserveChecks: true
|
||||
})
|
||||
|
||||
@@ -1568,7 +1568,7 @@ const schema: Schema.Struct<{
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(
|
||||
}).derive(
|
||||
Struct.evolve({
|
||||
a: (field) => Schema.optionalKey(field)
|
||||
})
|
||||
@@ -1595,7 +1595,7 @@ const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number,
|
||||
c: Schema.Boolean
|
||||
}).map(Struct.map(Schema.optionalKey))
|
||||
}).derive(Struct.map(Schema.optionalKey))
|
||||
```
|
||||
|
||||
#### Mapping a subset of fields at once
|
||||
@@ -1618,7 +1618,7 @@ const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number,
|
||||
c: Schema.Boolean
|
||||
}).map(Struct.mapPick(["a", "c"], Schema.optionalKey))
|
||||
}).derive(Struct.mapPick(["a", "c"], Schema.optionalKey))
|
||||
```
|
||||
|
||||
Or if it's more convenient, you can use `Struct.mapOmit`.
|
||||
@@ -1637,7 +1637,7 @@ const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number,
|
||||
c: Schema.Boolean
|
||||
}).map(Struct.mapOmit(["b"], Schema.optionalKey))
|
||||
}).derive(Struct.mapOmit(["b"], Schema.optionalKey))
|
||||
```
|
||||
|
||||
#### Mapping individual keys
|
||||
@@ -1658,7 +1658,7 @@ const schema: Schema.Struct<{
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(
|
||||
}).derive(
|
||||
Struct.evolveKeys({
|
||||
a: (key) => String.toUpperCase(key)
|
||||
})
|
||||
@@ -1681,7 +1681,7 @@ const schema: Schema.Struct<{
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(
|
||||
}).derive(
|
||||
Struct.renameKeys({
|
||||
a: "A"
|
||||
})
|
||||
@@ -1706,7 +1706,7 @@ const schema: Schema.Struct<{
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(
|
||||
}).derive(
|
||||
Struct.evolveEntries({
|
||||
a: (key, value) => [String.toUpperCase(key), Schema.optionalKey(value)]
|
||||
})
|
||||
@@ -1733,7 +1733,7 @@ const schema: Schema.Struct<{
|
||||
readonly b: Schema.Number;
|
||||
}>
|
||||
*/
|
||||
const schema = A.map(
|
||||
const schema = A.derive(
|
||||
Struct.evolve({
|
||||
a: (field) => Schema.optionalKey(field)
|
||||
})
|
||||
@@ -2165,9 +2165,11 @@ import { Schema, Tuple } from "effect"
|
||||
/*
|
||||
const schema: Schema.Tuple<readonly [Schema.String, Schema.Boolean]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
Tuple.pick([0, 2])
|
||||
)
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(Tuple.pick([0, 2]))
|
||||
```
|
||||
|
||||
#### Omit
|
||||
@@ -2182,9 +2184,11 @@ import { Schema, Tuple } from "effect"
|
||||
/*
|
||||
const schema: Schema.Tuple<readonly [Schema.String, Schema.Boolean]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
Tuple.omit([1])
|
||||
)
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(Tuple.omit([1]))
|
||||
```
|
||||
|
||||
#### Adding Elements
|
||||
@@ -2206,8 +2210,8 @@ const schema: Schema.Tuple<readonly [
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number])
|
||||
.map(Tuple.appendElement(Schema.Boolean)) // adds a single element
|
||||
.map(Tuple.appendElements([Schema.String, Schema.Number])) // adds multiple elements
|
||||
.derive(Tuple.appendElement(Schema.Boolean)) // adds a single element
|
||||
.derive(Tuple.appendElements([Schema.String, Schema.Number])) // adds multiple elements
|
||||
```
|
||||
|
||||
#### Mapping individual elements
|
||||
@@ -2226,7 +2230,11 @@ const schema: Schema.Tuple<readonly [
|
||||
Schema.NullOr<Schema.Boolean>
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(
|
||||
Tuple.evolve([
|
||||
(v) => Schema.NullOr(v),
|
||||
undefined, // no change
|
||||
@@ -2251,9 +2259,11 @@ const schema: Schema.Tuple<readonly [
|
||||
Schema.NullOr<Schema.Boolean>
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
Tuple.map(Schema.NullOr)
|
||||
)
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(Tuple.map(Schema.NullOr))
|
||||
```
|
||||
|
||||
#### Mapping a subset of elements at once
|
||||
@@ -2272,9 +2282,11 @@ const schema: Schema.Tuple<readonly [
|
||||
Schema.NullOr<Schema.Boolean>
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
Tuple.mapPick([0, 2], Schema.NullOr)
|
||||
)
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(Tuple.mapPick([0, 2], Schema.NullOr))
|
||||
```
|
||||
|
||||
Or if it's more convenient, you can use `Tuple.mapOmit`.
|
||||
@@ -2289,9 +2301,11 @@ const schema: Schema.Tuple<readonly [
|
||||
Schema.NullOr<Schema.Boolean>
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
Tuple.mapOmit([1], Schema.NullOr)
|
||||
)
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(Tuple.mapOmit([1], Schema.NullOr))
|
||||
```
|
||||
|
||||
#### Renaming Indices
|
||||
@@ -2310,7 +2324,11 @@ const schema: Schema.Tuple<readonly [
|
||||
Schema.Boolean
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(
|
||||
Tuple.renameIndices(["1", "0"]) // flip the first and second elements
|
||||
)
|
||||
```
|
||||
@@ -2327,7 +2345,11 @@ const schema: Schema.Tuple<readonly [
|
||||
Schema.String
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Tuple([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(
|
||||
Tuple.renameIndices([
|
||||
"2", // last element becomes first
|
||||
"1", // second element keeps its index
|
||||
@@ -2885,8 +2907,8 @@ const schema: Schema.Union<readonly [
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Union([Schema.String, Schema.Number])
|
||||
.map(Tuple.appendElement(Schema.Boolean)) // adds a single member
|
||||
.map(Tuple.appendElements([Schema.String, Schema.Number])) // adds multiple members
|
||||
.derive(Tuple.appendElement(Schema.Boolean)) // adds a single member
|
||||
.derive(Tuple.appendElements([Schema.String, Schema.Number])) // adds multiple members
|
||||
```
|
||||
|
||||
#### Mapping individual members
|
||||
@@ -2905,7 +2927,11 @@ const schema: Schema.Union<readonly [
|
||||
Schema.Array$<Schema.Boolean>
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Union([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(
|
||||
Tuple.evolve([
|
||||
(v) => Schema.Array(v),
|
||||
undefined, // no change
|
||||
@@ -2930,9 +2956,11 @@ const schema: Schema.Union<readonly [
|
||||
Schema.Array$<Schema.Boolean>
|
||||
]>
|
||||
*/
|
||||
const schema = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
Tuple.map(Schema.Array)
|
||||
)
|
||||
const schema = Schema.Union([
|
||||
Schema.String,
|
||||
Schema.Number,
|
||||
Schema.Boolean
|
||||
]).derive(Tuple.map(Schema.Array))
|
||||
```
|
||||
|
||||
## Transformations Redesign
|
||||
|
||||
@@ -945,12 +945,12 @@ describe("Schema", () => {
|
||||
|
||||
describe("merge", () => {
|
||||
it("Struct", () => {
|
||||
const schema = Schema.Struct({ a: Schema.String }).map(Struct.merge({ b: Schema.String }))
|
||||
const schema = Schema.Struct({ a: Schema.String }).derive(Struct.merge({ b: Schema.String }))
|
||||
expect(schema).type.toBe<Schema.Struct<{ readonly a: Schema.String; readonly b: Schema.String }>>()
|
||||
})
|
||||
|
||||
it("overlapping fields", () => {
|
||||
const schema = Schema.Struct({ a: Schema.String, b: Schema.String }).map(
|
||||
const schema = Schema.Struct({ a: Schema.String, b: Schema.String }).derive(
|
||||
Struct.merge({ b: Schema.Number, c: Schema.Number })
|
||||
)
|
||||
expect(schema).type.toBe<
|
||||
@@ -1662,12 +1662,12 @@ describe("Schema", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("Struct.map", () => {
|
||||
describe("Struct.derive", () => {
|
||||
it("evolve", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.evolve({ a: (v) => Schema.optionalKey(v) }))
|
||||
}).derive(Struct.evolve({ a: (v) => Schema.optionalKey(v) }))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1686,7 +1686,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.evolveKeys({ a: (k) => Str.toUpperCase(k) }))
|
||||
}).derive(Struct.evolveKeys({ a: (k) => Str.toUpperCase(k) }))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1706,7 +1706,7 @@ describe("Schema", () => {
|
||||
a: Schema.String,
|
||||
b: Schema.Number,
|
||||
c: Schema.Boolean
|
||||
}).map(Struct.renameKeys({ a: "A", b: "B" }))
|
||||
}).derive(Struct.renameKeys({ a: "A", b: "B" }))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1725,7 +1725,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.evolveEntries({ a: (k, v) => [Str.toUpperCase(k), Schema.optionalKey(v)] }))
|
||||
}).derive(Struct.evolveEntries({ a: (k, v) => [Str.toUpperCase(k), Schema.optionalKey(v)] }))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1744,7 +1744,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.optionalKey))
|
||||
}).derive(Struct.map(Schema.optionalKey))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1763,7 +1763,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.mapPick(["a"], Schema.optionalKey))
|
||||
}).derive(Struct.mapPick(["a"], Schema.optionalKey))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1782,7 +1782,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.mapOmit(["b"], Schema.optionalKey))
|
||||
}).derive(Struct.mapOmit(["b"], Schema.optionalKey))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1801,7 +1801,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.optional))
|
||||
}).derive(Struct.map(Schema.optional))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1820,7 +1820,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.mutableKey))
|
||||
}).derive(Struct.map(Schema.mutableKey))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<{ a: string; b: number }, { a: string; b: number }, never, never>
|
||||
@@ -1834,7 +1834,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.Array(Schema.String),
|
||||
b: Schema.Tuple([Schema.Number])
|
||||
}).map(Struct.map(Schema.mutable))
|
||||
}).derive(Struct.map(Schema.mutable))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1858,8 +1858,8 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.Array(Schema.String),
|
||||
b: Schema.Tuple([Schema.Number])
|
||||
}).map(Struct.map(Schema.mutable))
|
||||
.map(Struct.map(Schema.readonly))
|
||||
}).derive(Struct.map(Schema.mutable))
|
||||
.derive(Struct.map(Schema.readonly))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1883,7 +1883,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.NullOr))
|
||||
}).derive(Struct.map(Schema.NullOr))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1902,7 +1902,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.UndefinedOr))
|
||||
}).derive(Struct.map(Schema.UndefinedOr))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1921,7 +1921,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.NullishOr))
|
||||
}).derive(Struct.map(Schema.NullishOr))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1940,7 +1940,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.Array))
|
||||
}).derive(Struct.map(Schema.Array))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1961,7 +1961,7 @@ describe("Schema", () => {
|
||||
b: Schema.Number
|
||||
})) {}
|
||||
|
||||
const schema = A.map(Struct.map(Schema.Array))
|
||||
const schema = A.derive(Struct.map(Schema.Array))
|
||||
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
@@ -1981,7 +1981,7 @@ describe("Schema", () => {
|
||||
a: Schema.String,
|
||||
b: Schema.FiniteFromString,
|
||||
c: Schema.Boolean
|
||||
}).map(flow(
|
||||
}).derive(flow(
|
||||
Struct.map(Schema.NullOr),
|
||||
Struct.mapPick(["a", "c"], Schema.mutableKey)
|
||||
))
|
||||
@@ -2006,9 +2006,9 @@ describe("Schema", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("Tuple.map", () => {
|
||||
describe("Tuple.derive", () => {
|
||||
it("appendElement", () => {
|
||||
const schema = Schema.Tuple([Schema.String]).map(Tuple.appendElement(Schema.Number))
|
||||
const schema = Schema.Tuple([Schema.String]).derive(Tuple.appendElement(Schema.Number))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [string, number], readonly [string, number], never, never>
|
||||
>()
|
||||
@@ -2016,7 +2016,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("appendElements", () => {
|
||||
const schema = Schema.Tuple([Schema.String]).map(Tuple.appendElements([Schema.Number, Schema.Boolean]))
|
||||
const schema = Schema.Tuple([Schema.String]).derive(Tuple.appendElements([Schema.Number, Schema.Boolean]))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [string, number, boolean], readonly [string, number, boolean], never, never>
|
||||
>()
|
||||
@@ -2024,7 +2024,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("pick", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(Tuple.pick([0, 2]))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(Tuple.pick([0, 2]))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [string, boolean], readonly [string, boolean], never, never>
|
||||
>()
|
||||
@@ -2032,7 +2032,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("omit", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(Tuple.omit([1]))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(Tuple.omit([1]))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [string, boolean], readonly [string, boolean], never, never>
|
||||
>()
|
||||
@@ -2041,7 +2041,7 @@ describe("Schema", () => {
|
||||
|
||||
describe("evolve", () => {
|
||||
it("readonly [string] -> readonly [string?]", () => {
|
||||
const schema = Schema.Tuple([Schema.String]).map(Tuple.evolve([(v) => Schema.optionalKey(v)]))
|
||||
const schema = Schema.Tuple([Schema.String]).derive(Tuple.evolve([(v) => Schema.optionalKey(v)]))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [string?], readonly [string?], never, never>
|
||||
>()
|
||||
@@ -2049,7 +2049,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("readonly [string, number] -> readonly [string, number?]", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).map(
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).derive(
|
||||
Tuple.evolve([undefined, (v) => Schema.optionalKey(v)])
|
||||
)
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
@@ -2063,7 +2063,9 @@ describe("Schema", () => {
|
||||
|
||||
describe("renameIndices", () => {
|
||||
it("partial index mapping", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(Tuple.renameIndices(["1", "0"]))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(
|
||||
Tuple.renameIndices(["1", "0"])
|
||||
)
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [number, string, boolean], readonly [number, string, boolean], never, never>
|
||||
>()
|
||||
@@ -2071,7 +2073,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("full index mapping", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(
|
||||
Tuple.renameIndices(["2", "1", "0"])
|
||||
)
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
@@ -2082,7 +2084,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("optionalKey", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).map(Tuple.map(Schema.optionalKey))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).derive(Tuple.map(Schema.optionalKey))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [string?, number?], readonly [string?, number?], never, never>
|
||||
>()
|
||||
@@ -2092,7 +2094,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("NullOr", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).map(Tuple.map(Schema.NullOr))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).derive(Tuple.map(Schema.NullOr))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<readonly [string | null, number | null], readonly [string | null, number | null], never, never>
|
||||
>()
|
||||
@@ -2102,7 +2104,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("mapPick", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(
|
||||
Tuple.mapPick([0, 2], Schema.NullOr)
|
||||
)
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
@@ -2119,9 +2121,9 @@ describe("Schema", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("Union.map", () => {
|
||||
describe("Union.derive", () => {
|
||||
it("appendElement", () => {
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).map(Tuple.appendElement(Schema.Boolean))
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).derive(Tuple.appendElement(Schema.Boolean))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<string | number | boolean, string | number | boolean, never, never>
|
||||
>()
|
||||
@@ -2129,7 +2131,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("evolve", () => {
|
||||
const schema = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]).derive(
|
||||
Tuple.evolve([
|
||||
(v) => Schema.Array(v),
|
||||
undefined,
|
||||
@@ -2150,7 +2152,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("Array", () => {
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).map(Tuple.map(Schema.Array))
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).derive(Tuple.map(Schema.Array))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
ReadonlyArray<string> | ReadonlyArray<number>,
|
||||
@@ -2163,7 +2165,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("NonEmptyArray", () => {
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).map(Tuple.map(Schema.NonEmptyArray))
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).derive(Tuple.map(Schema.NonEmptyArray))
|
||||
expect(Schema.revealCodec(schema)).type.toBe<
|
||||
Schema.Codec<
|
||||
NonEmptyReadonlyArray<string> | NonEmptyReadonlyArray<number>,
|
||||
@@ -2198,7 +2200,7 @@ describe("Schema", () => {
|
||||
})
|
||||
|
||||
it("Literals.map", () => {
|
||||
const schema = Schema.Literals(["a", "b", "c"]).map(Tuple.evolve([
|
||||
const schema = Schema.Literals(["a", "b", "c"]).derive(Tuple.evolve([
|
||||
(a) => Schema.Struct({ _tag: a, a: Schema.String }),
|
||||
(b) => Schema.Struct({ _tag: b, b: Schema.Number }),
|
||||
(c) => Schema.Struct({ _tag: c, c: Schema.Boolean })
|
||||
|
||||
@@ -1326,7 +1326,7 @@ export interface Struct<Fields extends Struct.Fields> extends
|
||||
* - `preserveChecks` - if `true`, keep any `.check(...)` constraints that
|
||||
* were attached to the original struct. Defaults to `false`.
|
||||
*/
|
||||
map<To extends Struct.Fields>(
|
||||
derive<To extends Struct.Fields>(
|
||||
f: (fields: Fields) => To,
|
||||
options?: {
|
||||
readonly preserveChecks?: boolean | undefined
|
||||
@@ -1341,7 +1341,7 @@ class Struct$<Fields extends Struct.Fields> extends make$<Struct<Fields>> implem
|
||||
// clone to avoid accidental external mutation
|
||||
this.fields = { ...fields }
|
||||
}
|
||||
map<To extends Struct.Fields>(
|
||||
derive<To extends Struct.Fields>(
|
||||
f: (fields: Fields) => To,
|
||||
options?: {
|
||||
readonly preserveChecks?: boolean | undefined
|
||||
@@ -1712,7 +1712,7 @@ export interface Tuple<Elements extends Tuple.Elements> extends
|
||||
* - `preserveChecks` - if `true`, keep any `.check(...)` constraints that
|
||||
* were attached to the original tuple. Defaults to `false`.
|
||||
*/
|
||||
map<To extends Tuple.Elements>(
|
||||
derive<To extends Tuple.Elements>(
|
||||
f: (elements: Elements) => To,
|
||||
options?: {
|
||||
readonly preserveChecks?: boolean | undefined
|
||||
@@ -1728,7 +1728,7 @@ class Tuple$<Elements extends Tuple.Elements> extends make$<Tuple<Elements>> imp
|
||||
this.elements = [...elements] as any
|
||||
}
|
||||
|
||||
map<To extends Tuple.Elements>(
|
||||
derive<To extends Tuple.Elements>(
|
||||
f: (elements: Elements) => To,
|
||||
options?: {
|
||||
readonly preserveChecks?: boolean | undefined
|
||||
@@ -2014,7 +2014,7 @@ export interface Union<Members extends ReadonlyArray<Top>> extends
|
||||
* - `preserveChecks` - if `true`, keep any `.check(...)` constraints that
|
||||
* were attached to the original union. Defaults to `false`.
|
||||
*/
|
||||
map<To extends ReadonlyArray<Top>>(
|
||||
derive<To extends ReadonlyArray<Top>>(
|
||||
f: (members: Members) => To,
|
||||
options?: {
|
||||
readonly preserveChecks?: boolean | undefined
|
||||
@@ -2027,7 +2027,7 @@ class Union$<Members extends ReadonlyArray<Top>> extends make$<Union<Members>> i
|
||||
super(ast, (ast) => new Union$(ast, members))
|
||||
}
|
||||
|
||||
map<To extends ReadonlyArray<Top>>(
|
||||
derive<To extends ReadonlyArray<Top>>(
|
||||
f: (members: Members) => To,
|
||||
options?: {
|
||||
readonly preserveChecks?: boolean | undefined
|
||||
@@ -2075,7 +2075,7 @@ export interface Literals<L extends ReadonlyArray<SchemaAST.Literal>> extends
|
||||
{
|
||||
readonly literals: L
|
||||
readonly members: { readonly [K in keyof L]: Literal<L[K]> }
|
||||
map<To extends ReadonlyArray<Top>>(f: (members: this["members"]) => To): Union<Simplify<Readonly<To>>>
|
||||
derive<To extends ReadonlyArray<Top>>(f: (members: this["members"]) => To): Union<Simplify<Readonly<To>>>
|
||||
}
|
||||
|
||||
class Literals$<L extends ReadonlyArray<SchemaAST.Literal>> extends make$<Literals<L>> implements Literals<L> {
|
||||
@@ -2087,7 +2087,7 @@ class Literals$<L extends ReadonlyArray<SchemaAST.Literal>> extends make$<Litera
|
||||
super(ast, (ast) => new Literals$(ast, literals, members))
|
||||
}
|
||||
|
||||
map<To extends ReadonlyArray<Top>>(f: (members: this["members"]) => To): Union<Simplify<Readonly<To>>> {
|
||||
derive<To extends ReadonlyArray<Top>>(f: (members: this["members"]) => To): Union<Simplify<Readonly<To>>> {
|
||||
return Union(f(this.members))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ describe("Schema", () => {
|
||||
const from = Schema.Struct({
|
||||
a: Schema.String
|
||||
})
|
||||
const schema = from.map(Struct.merge({ b: Schema.String }))
|
||||
const schema = from.derive(Struct.merge({ b: Schema.String }))
|
||||
|
||||
await assertions.decoding.succeed(schema, { a: "a", b: "b" })
|
||||
await assertions.decoding.fail(
|
||||
@@ -598,7 +598,7 @@ describe("Schema", () => {
|
||||
a: Schema.String,
|
||||
b: Schema.String
|
||||
})
|
||||
const schema = from.map(Struct.merge({ b: Schema.Number, c: Schema.Number }))
|
||||
const schema = from.derive(Struct.merge({ b: Schema.Number, c: Schema.Number }))
|
||||
|
||||
await assertions.decoding.succeed(schema, { a: "a", b: 1, c: 2 })
|
||||
await assertions.decoding.fail(
|
||||
@@ -617,7 +617,7 @@ describe("Schema", () => {
|
||||
}).check(
|
||||
SchemaCheck.make(({ a, b }) => a === b, { title: "a === b" })
|
||||
)
|
||||
const schema = from.map(Struct.merge({ c: Schema.String }), { preserveChecks: true })
|
||||
const schema = from.derive(Struct.merge({ c: Schema.String }), { preserveChecks: true })
|
||||
|
||||
await assertions.decoding.succeed(schema, { a: "a", b: "a", c: "c" })
|
||||
await assertions.decoding.fail(
|
||||
@@ -635,7 +635,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.String
|
||||
}).map(Struct.pick(["a"]))
|
||||
}).derive(Struct.pick(["a"]))
|
||||
|
||||
await assertions.decoding.succeed(schema, { a: "a" })
|
||||
})
|
||||
@@ -646,7 +646,7 @@ describe("Schema", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.String
|
||||
}).map(Struct.omit(["b"]))
|
||||
}).derive(Struct.omit(["b"]))
|
||||
|
||||
await assertions.decoding.succeed(schema, { a: "a" })
|
||||
})
|
||||
@@ -4627,12 +4627,12 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("Struct.map", () => {
|
||||
describe("Struct.derive", () => {
|
||||
it("evolve", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.evolve({ a: (v) => Schema.optionalKey(v) }))
|
||||
}).derive(Struct.evolve({ a: (v) => Schema.optionalKey(v) }))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "a"?: string; readonly "b": number }`)
|
||||
|
||||
@@ -4646,7 +4646,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.evolveKeys({ a: (k) => Str.toUpperCase(k) }))
|
||||
}).derive(Struct.evolveKeys({ a: (k) => Str.toUpperCase(k) }))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "A": string; readonly "b": number }`)
|
||||
|
||||
@@ -4661,7 +4661,7 @@ describe("SchemaGetter", () => {
|
||||
a: Schema.String,
|
||||
b: Schema.Number,
|
||||
c: Schema.Boolean
|
||||
}).map(Struct.renameKeys({ a: "A", b: "B" }))
|
||||
}).derive(Struct.renameKeys({ a: "A", b: "B" }))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "A": string; readonly "B": number; readonly "c": boolean }`)
|
||||
|
||||
@@ -4676,7 +4676,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.evolveEntries({ a: (k, v) => [Str.toUpperCase(k), Schema.optionalKey(v)] }))
|
||||
}).derive(Struct.evolveEntries({ a: (k, v) => [Str.toUpperCase(k), Schema.optionalKey(v)] }))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "A"?: string; readonly "b": number }`)
|
||||
|
||||
@@ -4690,7 +4690,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.optionalKey))
|
||||
}).derive(Struct.map(Schema.optionalKey))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "a"?: string; readonly "b"?: number }`)
|
||||
|
||||
@@ -4704,7 +4704,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.mapPick(["a"], Schema.optionalKey))
|
||||
}).derive(Struct.mapPick(["a"], Schema.optionalKey))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "a"?: string; readonly "b": number }`)
|
||||
|
||||
@@ -4718,7 +4718,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.mapOmit(["b"], Schema.optionalKey))
|
||||
}).derive(Struct.mapOmit(["b"], Schema.optionalKey))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "a"?: string; readonly "b": number }`)
|
||||
|
||||
@@ -4732,7 +4732,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.optional))
|
||||
}).derive(Struct.map(Schema.optional))
|
||||
|
||||
strictEqual(
|
||||
SchemaAST.format(schema.ast),
|
||||
@@ -4749,7 +4749,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.mutableKey))
|
||||
}).derive(Struct.map(Schema.mutableKey))
|
||||
|
||||
strictEqual(
|
||||
SchemaAST.format(schema.ast),
|
||||
@@ -4766,7 +4766,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.Array(Schema.String),
|
||||
b: Schema.Tuple([Schema.Number])
|
||||
}).map(Struct.map(Schema.mutable))
|
||||
}).derive(Struct.map(Schema.mutable))
|
||||
|
||||
strictEqual(
|
||||
SchemaAST.format(schema.ast),
|
||||
@@ -4783,8 +4783,8 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.Array(Schema.String),
|
||||
b: Schema.Tuple([Schema.Number])
|
||||
}).map(Struct.map(Schema.mutable))
|
||||
.map(Struct.map(Schema.readonly))
|
||||
}).derive(Struct.map(Schema.mutable))
|
||||
.derive(Struct.map(Schema.readonly))
|
||||
|
||||
strictEqual(
|
||||
SchemaAST.format(schema.ast),
|
||||
@@ -4801,7 +4801,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.NullOr))
|
||||
}).derive(Struct.map(Schema.NullOr))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `{ readonly "a": string | null; readonly "b": number | null }`)
|
||||
|
||||
@@ -4815,7 +4815,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.UndefinedOr))
|
||||
}).derive(Struct.map(Schema.UndefinedOr))
|
||||
|
||||
strictEqual(
|
||||
SchemaAST.format(schema.ast),
|
||||
@@ -4832,7 +4832,7 @@ describe("SchemaGetter", () => {
|
||||
const schema = Schema.Struct({
|
||||
a: Schema.String,
|
||||
b: Schema.Number
|
||||
}).map(Struct.map(Schema.NullishOr))
|
||||
}).derive(Struct.map(Schema.NullishOr))
|
||||
|
||||
strictEqual(
|
||||
SchemaAST.format(schema.ast),
|
||||
@@ -4850,7 +4850,7 @@ describe("SchemaGetter", () => {
|
||||
a: Schema.String,
|
||||
b: Schema.FiniteFromString,
|
||||
c: Schema.Boolean
|
||||
}).map(flow(
|
||||
}).derive(flow(
|
||||
Struct.map(Schema.NullOr),
|
||||
Struct.mapPick(["a", "c"], Schema.mutableKey)
|
||||
))
|
||||
@@ -4868,9 +4868,9 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("Tuple.map", () => {
|
||||
describe("Tuple.derive", () => {
|
||||
it("appendElement", () => {
|
||||
const schema = Schema.Tuple([Schema.String]).map(Tuple.appendElement(Schema.Number))
|
||||
const schema = Schema.Tuple([Schema.String]).derive(Tuple.appendElement(Schema.Number))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [string, number]`)
|
||||
|
||||
@@ -4878,7 +4878,7 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
|
||||
it("appendElements", () => {
|
||||
const schema = Schema.Tuple([Schema.String]).map(Tuple.appendElements([Schema.Number, Schema.Boolean]))
|
||||
const schema = Schema.Tuple([Schema.String]).derive(Tuple.appendElements([Schema.Number, Schema.Boolean]))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [string, number, boolean]`)
|
||||
|
||||
@@ -4886,20 +4886,20 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
|
||||
it("pick", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(Tuple.pick([0, 2]))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(Tuple.pick([0, 2]))
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [string, boolean]`)
|
||||
assertions.schema.elements.equals(schema.elements, [Schema.String, Schema.Boolean])
|
||||
})
|
||||
|
||||
it("omit", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(Tuple.omit([1]))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(Tuple.omit([1]))
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [string, boolean]`)
|
||||
assertions.schema.elements.equals(schema.elements, [Schema.String, Schema.Boolean])
|
||||
})
|
||||
|
||||
describe("evolve", () => {
|
||||
it("readonly [string] -> readonly [string?]", () => {
|
||||
const schema = Schema.Tuple([Schema.String]).map(Tuple.evolve([(v) => Schema.optionalKey(v)]))
|
||||
const schema = Schema.Tuple([Schema.String]).derive(Tuple.evolve([(v) => Schema.optionalKey(v)]))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [string?]`)
|
||||
|
||||
@@ -4907,7 +4907,7 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
|
||||
it("readonly [string, number] -> readonly [string, number?]", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).map(
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).derive(
|
||||
Tuple.evolve([undefined, (v) => Schema.optionalKey(v)])
|
||||
)
|
||||
|
||||
@@ -4919,13 +4919,15 @@ describe("SchemaGetter", () => {
|
||||
|
||||
describe("renameIndices", () => {
|
||||
it("partial index mapping", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(Tuple.renameIndices(["1", "0"]))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(
|
||||
Tuple.renameIndices(["1", "0"])
|
||||
)
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [number, string, boolean]`)
|
||||
assertions.schema.elements.equals(schema.elements, [Schema.Number, Schema.String, Schema.Boolean])
|
||||
})
|
||||
|
||||
it("full index mapping", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number, Schema.Boolean]).derive(
|
||||
Tuple.renameIndices(["2", "1", "0"])
|
||||
)
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [boolean, number, string]`)
|
||||
@@ -4934,7 +4936,7 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
|
||||
it("NullOr", () => {
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).map(Tuple.map(Schema.NullOr))
|
||||
const schema = Schema.Tuple([Schema.String, Schema.Number]).derive(Tuple.map(Schema.NullOr))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `readonly [string | null, number | null]`)
|
||||
|
||||
@@ -4942,9 +4944,9 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("Union.map", () => {
|
||||
describe("Union.derive", () => {
|
||||
it("appendElement", () => {
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).map(Tuple.appendElement(Schema.Boolean))
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).derive(Tuple.appendElement(Schema.Boolean))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `string | number | boolean`)
|
||||
|
||||
@@ -4952,7 +4954,7 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
|
||||
it("evolve", () => {
|
||||
const schema = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]).map(
|
||||
const schema = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]).derive(
|
||||
Tuple.evolve([
|
||||
(v) => Schema.Array(v),
|
||||
undefined,
|
||||
@@ -4970,7 +4972,7 @@ describe("SchemaGetter", () => {
|
||||
})
|
||||
|
||||
it("Array", () => {
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).map(Tuple.map(Schema.Array))
|
||||
const schema = Schema.Union([Schema.String, Schema.Number]).derive(Tuple.map(Schema.Array))
|
||||
|
||||
strictEqual(SchemaAST.format(schema.ast), `ReadonlyArray<string> | ReadonlyArray<number>`)
|
||||
|
||||
@@ -4983,7 +4985,7 @@ describe("SchemaGetter", () => {
|
||||
|
||||
describe("Literals.map", () => {
|
||||
it("evolve", () => {
|
||||
const schema = Schema.Literals(["a", "b", "c"]).map(Tuple.evolve([
|
||||
const schema = Schema.Literals(["a", "b", "c"]).derive(Tuple.evolve([
|
||||
(a) => Schema.Struct({ _tag: a, a: Schema.String }),
|
||||
(b) => Schema.Struct({ _tag: b, b: Schema.Number }),
|
||||
(c) => Schema.Struct({ _tag: c, c: Schema.Boolean })
|
||||
|
||||
Reference in New Issue
Block a user