viell-effect-schema-http 0.1.0 → 0.3.0

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.
Files changed (56) hide show
  1. package/README.md +44 -29
  2. package/dist/concurrency/Interaction.d.ts +7 -1
  3. package/dist/concurrency/Interaction.d.ts.map +1 -1
  4. package/dist/concurrency/Interaction.js.map +1 -1
  5. package/dist/http/Body.d.ts +25 -13
  6. package/dist/http/Body.d.ts.map +1 -1
  7. package/dist/http/Body.js +18 -8
  8. package/dist/http/Body.js.map +1 -1
  9. package/dist/http/Operation.d.ts +276 -13
  10. package/dist/http/Operation.d.ts.map +1 -1
  11. package/dist/http/Operation.js +210 -11
  12. package/dist/http/Operation.js.map +1 -1
  13. package/dist/http/Policy.d.ts +28 -2
  14. package/dist/http/Policy.d.ts.map +1 -1
  15. package/dist/http/Policy.js +28 -2
  16. package/dist/http/Policy.js.map +1 -1
  17. package/dist/http/Request.d.ts +520 -85
  18. package/dist/http/Request.d.ts.map +1 -1
  19. package/dist/http/Request.js +658 -143
  20. package/dist/http/Request.js.map +1 -1
  21. package/dist/http/Response.d.ts +130 -6
  22. package/dist/http/Response.d.ts.map +1 -1
  23. package/dist/http/Response.js +88 -7
  24. package/dist/http/Response.js.map +1 -1
  25. package/dist/http/UrlEncoding.d.ts +24 -7
  26. package/dist/http/UrlEncoding.d.ts.map +1 -1
  27. package/dist/http/UrlEncoding.js +7 -3
  28. package/dist/http/UrlEncoding.js.map +1 -1
  29. package/dist/http/internal/excess.d.ts +44 -0
  30. package/dist/http/internal/excess.d.ts.map +1 -0
  31. package/dist/http/internal/excess.js +231 -0
  32. package/dist/http/internal/excess.js.map +1 -0
  33. package/dist/http/internal/fields.d.ts +17 -4
  34. package/dist/http/internal/fields.d.ts.map +1 -1
  35. package/dist/http/internal/fields.js +11 -6
  36. package/dist/http/internal/fields.js.map +1 -1
  37. package/dist/http/internal/input.d.ts +70 -0
  38. package/dist/http/internal/input.d.ts.map +1 -0
  39. package/dist/http/internal/input.js +93 -0
  40. package/dist/http/internal/input.js.map +1 -0
  41. package/dist/http/internal/shape.d.ts +63 -0
  42. package/dist/http/internal/shape.d.ts.map +1 -0
  43. package/dist/http/internal/shape.js +225 -0
  44. package/dist/http/internal/shape.js.map +1 -0
  45. package/package.json +13 -12
  46. package/src/concurrency/Interaction.ts +7 -1
  47. package/src/http/Body.ts +41 -18
  48. package/src/http/Operation.ts +474 -33
  49. package/src/http/Policy.ts +30 -2
  50. package/src/http/Request.ts +1176 -253
  51. package/src/http/Response.ts +246 -23
  52. package/src/http/UrlEncoding.ts +32 -8
  53. package/src/http/internal/excess.ts +333 -0
  54. package/src/http/internal/fields.ts +37 -9
  55. package/src/http/internal/input.ts +228 -0
  56. package/src/http/internal/shape.ts +359 -0
@@ -0,0 +1,225 @@
1
+ import { Effect, Schema, SchemaAST } from "effect";
2
+ import * as Excess from "./excess.js";
3
+ const holdsUndefined = (ast) => ast._tag === "Undefined" ||
4
+ ast._tag === "Void" ||
5
+ (ast._tag === "Union" && ast.types.some(holdsUndefined));
6
+ /**
7
+ * Whether a field whose encoded side is optional is written all the same, as a decoding default is.
8
+ * The decoded side has to hold a value, and the step that makes the encoded side optional has to
9
+ * hand that value on as it is. A step that decides for itself may write nothing, as
10
+ * `Schema.OptionFromOptionalKey` does for `None` and the `omit` strategy of a default always does.
11
+ */
12
+ const writesOptional = (type) => {
13
+ const decoded = SchemaAST.toType(type);
14
+ const step = type.encoding?.find(({ to }) => SchemaAST.isOptional(to));
15
+ return (!SchemaAST.isOptional(decoded) &&
16
+ !holdsUndefined(decoded) &&
17
+ step?.transformation._tag === "Transformation" &&
18
+ step.transformation.encode._tag === "Passthrough");
19
+ };
20
+ const readObjects = (ast) => {
21
+ const stated = ast.propertySignatures.map(({ name, type }) => [String(name), SchemaAST.toEncoded(type), type]);
22
+ return {
23
+ fields: new Map(stated.map(([name, encoded]) => [name, [encoded]])),
24
+ rest: ast.indexSignatures.map(({ type }) => SchemaAST.toEncoded(type)),
25
+ open: ast.indexSignatures.length > 0,
26
+ required: new Set(stated
27
+ .filter(([, encoded, type]) => (!SchemaAST.isOptional(encoded) && !holdsUndefined(encoded)) ||
28
+ writesOptional(type))
29
+ .map(([name]) => name)),
30
+ };
31
+ };
32
+ /** A union allows what any member allows and always writes what every member writes. */
33
+ const readUnion = (members) => {
34
+ const fields = new Map();
35
+ for (const member of members)
36
+ for (const [name, types] of member.fields)
37
+ fields.set(name, [...(fields.get(name) ?? []), ...types]);
38
+ const [first, ...others] = members;
39
+ return {
40
+ fields,
41
+ rest: members.flatMap(({ rest }) => rest),
42
+ open: members.some(({ open }) => open),
43
+ required: new Set(Array.from(first?.required ?? []).filter((name) => others.every(({ required }) => required.has(name)))),
44
+ };
45
+ };
46
+ /** Read a schema's encoded side. Where names cannot be read, the schema allows any name. */
47
+ const read = (ast) => {
48
+ const end = Excess.encodedEnd(ast);
49
+ return end._tag === "Objects"
50
+ ? readObjects(end)
51
+ : end._tag === "Union"
52
+ ? readUnion(end.types.map(read))
53
+ : { fields: new Map(), rest: [], open: true, required: new Set() };
54
+ };
55
+ const takesList = (ast) => ast._tag === "Arrays" || (ast._tag === "Union" && ast.types.some(takesList));
56
+ /** The single values a field's encoded type takes, looking inside unions and lists. */
57
+ const scalars = (ast) => ast._tag === "Union"
58
+ ? ast.types.flatMap(scalars)
59
+ : ast._tag === "Arrays"
60
+ ? [...ast.elements, ...ast.rest].flatMap(scalars)
61
+ : [ast];
62
+ const readNumber = (text) => {
63
+ if (text === "NaN")
64
+ return Number.NaN;
65
+ const value = Number(text);
66
+ return text.trim() === "" || Number.isNaN(value) ? text : value;
67
+ };
68
+ const readBoolean = (text) => text === "true" ? true : text === "false" ? false : text;
69
+ const readBigInt = (text) => /^-?\d+$/.test(text) ? BigInt(text) : text;
70
+ /**
71
+ * Text reads as `Schema.DateFromString` reads it. A declaration need not refuse an invalid `Date`
72
+ * as `Schema.Date` does, so text with no date in it stays text for the schema to refuse.
73
+ */
74
+ const readDate = (ast) => {
75
+ const takesDate = Schema.is(Schema.make(ast));
76
+ return (text) => {
77
+ const date = new Date(text);
78
+ return !Number.isNaN(date.getTime()) && takesDate(date) ? date : text;
79
+ };
80
+ };
81
+ const readerFor = (ast) => {
82
+ switch (ast._tag) {
83
+ case "Declaration":
84
+ return [readDate(ast)];
85
+ case "Number":
86
+ return [readNumber];
87
+ case "Boolean":
88
+ return [readBoolean];
89
+ case "BigInt":
90
+ return [readBigInt];
91
+ case "Literal":
92
+ return typeof ast.literal === "number"
93
+ ? [readNumber]
94
+ : typeof ast.literal === "boolean"
95
+ ? [readBoolean]
96
+ : typeof ast.literal === "bigint"
97
+ ? [readBigInt]
98
+ : [];
99
+ case "Enum":
100
+ return ast.enums.some(([, value]) => typeof value === "number")
101
+ ? [readNumber]
102
+ : [];
103
+ default:
104
+ return [];
105
+ }
106
+ };
107
+ /**
108
+ * Read wire text as the value a field encodes to, the reverse of how the library writes it. A field
109
+ * that can hold text takes it as it is, and text that reads as nothing else stays text for the
110
+ * schema to refuse.
111
+ */
112
+ const readText = (types, text) => {
113
+ const forms = types.flatMap(scalars);
114
+ if (forms.some(({ _tag }) => _tag === "String"))
115
+ return text;
116
+ for (const reader of forms.flatMap(readerFor)) {
117
+ const value = reader(text);
118
+ if (typeof value !== "string")
119
+ return value;
120
+ }
121
+ return text;
122
+ };
123
+ /** Whether a shape allows a name, given in its compared form. */
124
+ export const allows = (shape, name) => shape.open || shape.names.has(name);
125
+ /** Declared names no bound schema allows. With no schema there is no shape to meet. */
126
+ export const outside = (names, shapes, fold) => shapes.length === 0
127
+ ? []
128
+ : names.filter((name) => !shapes.some((shape) => allows(shape, fold(name))));
129
+ /** The edited names some bound schema always writes. */
130
+ export const required = (names, shapes, fold) => names.filter((name) => shapes.some((shape) => shape.required.has(fold(name))));
131
+ /** The names a schema's output holds a value under, as the schema spells them. */
132
+ const writtenNames = (output) => (Symbol.iterator in output
133
+ ? Array.from(output)
134
+ : Object.entries(output))
135
+ .filter(([, value]) => value !== undefined)
136
+ .map(([name]) => name);
137
+ /**
138
+ * The names a schema's output writes, in their compared form. A name with no value writes nothing,
139
+ * so a default stays, while an empty list is the caller saying there are no entries.
140
+ */
141
+ export const written = (output, fold) => new Set(writtenNames(output).map(fold));
142
+ const noNames = new Set();
143
+ /**
144
+ * The names a raw value does not concern a union under, in their compared form: what another schema
145
+ * took from the caller, and what a schema with no union settles itself. A schema with no choice
146
+ * settles its own defaults, so nothing is left to it by this.
147
+ */
148
+ export const others = (shape, taken, fold) => !shape.chooses || taken === undefined
149
+ ? noNames
150
+ : new Set([
151
+ ...Array.from(taken.fields, (name) => typeof name === "string" ? fold(name) : name),
152
+ ...taken.settled,
153
+ ]);
154
+ /** The record once a schema has added what it took. */
155
+ export const taking = (taken, own) => ({
156
+ fields: new Set([...(taken?.fields ?? []), ...own]),
157
+ settled: taken?.settled ?? new Set(),
158
+ });
159
+ /**
160
+ * What went into `settle` and is gone from what came out, in the spelling it went in with. A schema
161
+ * can write less than it was given, and that must not pass as a group that was built.
162
+ */
163
+ export const lost = (output, defaults, settled, fold) => {
164
+ const kept = written(settled, fold);
165
+ return [...writtenNames(output), ...defaults.map(([name]) => name)].filter((name) => !kept.has(fold(name)));
166
+ };
167
+ /**
168
+ * Read what a schema says about its group, and build what it sends.
169
+ *
170
+ * @remarks
171
+ * `settle` adds defaults to what the schema wrote and takes the whole group through the schema in
172
+ * both directions. A decoder may accept more spellings than its encoder writes, so a default that
173
+ * decodes is not yet what the schema sends.
174
+ *
175
+ * Effect strips what a union member does not state, so the first member that fits part of the group
176
+ * would win over a later one that holds all of it. `settle` therefore looks for such a member first.
177
+ * Without one it takes the looser match, and {@link lost} tells the caller what that left out.
178
+ */
179
+ export const bind = (contract, fold) => {
180
+ const reading = read(contract.ast);
181
+ const spelling = new Map(Array.from(reading.fields.keys(), (name) => [fold(name), name]));
182
+ const decode = Schema.decodeUnknownEffect(contract);
183
+ const encode = Schema.encodeEffect(contract);
184
+ const chooses = Excess.choosesMember(contract.ast);
185
+ const shape = {
186
+ names: new Set(spelling.keys()),
187
+ open: reading.open,
188
+ required: new Set(Array.from(reading.required, fold)),
189
+ chooses,
190
+ };
191
+ /**
192
+ * The caller's fields this schema took: what it wrote, and any it states and the caller gave,
193
+ * which may be written under another name or not at all. What it would lose is not among them.
194
+ */
195
+ const taken = (input, output, losing) => new Set([
196
+ ...writtenNames(output),
197
+ ...Excess.statedFields(contract.ast, input),
198
+ ].filter((name) => !losing.some(([key]) => key === name)));
199
+ const settle = (output, defaults) => {
200
+ if (defaults.length === 0)
201
+ return Effect.succeed(output);
202
+ const values = new Map();
203
+ const pairs = defaults.map(([name, value]) => {
204
+ const spelled = spelling.get(fold(name)) ?? name;
205
+ const types = reading.fields.get(spelled) ?? reading.rest;
206
+ const entry = typeof value === "string" ? readText(types, value) : value;
207
+ values.set(spelled, [...(values.get(spelled) ?? []), entry]);
208
+ return [spelled, entry];
209
+ });
210
+ const record = Object.fromEntries(Array.from(values, ([name, entries]) => [
211
+ name,
212
+ entries.length > 1 ||
213
+ (reading.fields.get(name) ?? reading.rest).some(takesList)
214
+ ? entries
215
+ : entries[0],
216
+ ]));
217
+ const group = Symbol.iterator in output
218
+ ? [...output, ...pairs]
219
+ : { ...output, ...record };
220
+ const through = (options) => Effect.flatMap(decode(group, options), (decoded) => encode(decoded, options));
221
+ return Effect.catch(through({ onExcessProperty: "error" }), () => through());
222
+ };
223
+ return { shape, settle, taken };
224
+ };
225
+ //# sourceMappingURL=shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape.js","sourceRoot":"","sources":["../../../src/http/internal/shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAiCtC,MAAM,cAAc,GAAG,CAAC,GAAkB,EAAW,EAAE,CACrD,GAAG,CAAC,IAAI,KAAK,WAAW;IACxB,GA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,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI;YACJ,OAAO,CAAC,MAAM,GAAG,CAAC;gBAClB,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;gBACxD,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;SACf,CAAC,CACH,CAAC;QACF,MAAM,KAAK,GACT,MAAM,CAAC,QAAQ,IAAI,MAAM;YACvB,CAAC,CAAC,CAAC,GAAI,MAAuC,EAAE,GAAG,KAAK,CAAC;YACzD,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,CAAC,OAAgC,EAAE,EAAE,CACnD,MAAM,CAAC,OAAO,CACZ,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,EACtB,CAAC,OAAO,EAAE,EAAE,CACV,MAAM,CAAC,OAAO,EAAE,OAAO,CAAyC,CACnE,CAAC;QACJ,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAC/D,OAAO,EAAE,CACV,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAClC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viell-effect-schema-http",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Consumer-owned HTTP contracts composed with Effect",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  "type": "module",
16
16
  "sideEffects": false,
17
17
  "engines": {
18
- "node": ">=24 <25"
18
+ "node": ">=24"
19
19
  },
20
20
  "exports": {
21
21
  ".": {
@@ -58,11 +58,11 @@
58
58
  },
59
59
  "main": "./dist/main.js",
60
60
  "types": "./dist/main.d.ts",
61
- "packageManager": "npm@11.19.0",
61
+ "packageManager": "npm@11.19.1",
62
62
  "devEngines": {
63
63
  "packageManager": {
64
64
  "name": "npm",
65
- "version": "^11.19.0",
65
+ "version": "^11.19.1",
66
66
  "onFail": "error"
67
67
  }
68
68
  },
@@ -81,13 +81,14 @@
81
81
  "lint:mdrefine": "mdrefine lint",
82
82
  "test": "vitest run",
83
83
  "test:package": "node scripts/check-package.mjs",
84
- "test:release": "node --test scripts/release.test.mjs",
84
+ "test:release": "node --test scripts/release.test.mjs scripts/registry.test.mjs scripts/live.test.mjs",
85
85
  "release:prepare": "node scripts/prepare-release.mjs",
86
+ "check-live": "node scripts/check-live.mjs",
86
87
  "test:watch": "vitest",
87
88
  "docs:dev": "vitepress dev docs",
88
89
  "docs:build": "vitepress build docs && node scripts/check-doc-links.mjs",
89
90
  "docs:preview": "vite preview --host 127.0.0.1 --outDir docs/.vitepress/dist --base /slop-effect-schema-http/",
90
- "docs:examples": "tsc -p tsconfig.examples.json && node scripts/check-doc-examples.mjs && node examples/guides.mjs && node examples/modules.mjs"
91
+ "docs:examples": "tsc -p tsconfig.examples.json && node scripts/check-doc-examples.mjs && node examples/guides.mjs && node examples/modules.mjs && node examples/recipes.mjs"
91
92
  },
92
93
  "files": [
93
94
  "dist",
@@ -108,20 +109,20 @@
108
109
  "minimatch@10": "11.0.1"
109
110
  },
110
111
  "devDependencies": {
111
- "@effect/vitest": "^4.1.1",
112
+ "@effect/vitest": "^4.1.2",
112
113
  "@eslint/js": "^10.0.1",
113
114
  "@types/node": "^26.6.6",
114
- "effect": "^4.1.1",
115
+ "effect": "^4.1.2",
115
116
  "eslint": "^10.14.0",
116
117
  "eslint-config-prettier": "^10.1.8",
117
- "eslint-plugin-oxlint": "^1.90.0",
118
- "mdrefine": "^0.6.3",
118
+ "eslint-plugin-oxlint": "^1.92.0",
119
+ "mdrefine": "^0.7.1",
119
120
  "npm-run-all2": "^9.0.4",
120
- "oxlint": "^1.90.0",
121
+ "oxlint": "^1.92.0",
121
122
  "prettier": "^3.9.10",
122
123
  "typescript": "^6.0.3",
123
124
  "typescript-eslint": "^8.72.1",
124
125
  "vitepress": "2.0.0-alpha.21",
125
- "vitest": "^5.0.5"
126
+ "vitest": "^5.1.0"
126
127
  }
127
128
  }
@@ -50,7 +50,13 @@ export interface Interaction<in I, out A, out E = never> {
50
50
  export interface Options<I, A> {
51
51
  /** Defaults to `Equal.equals`, which compares plain objects and arrays structurally. */
52
52
  readonly equivalence?: Equivalence.Equivalence<I> | undefined;
53
- /** Whether to retain a success. Defaults to retaining; the result is returned either way. */
53
+ /**
54
+ * Whether to retain a success. Defaults to retaining; the result is returned either way.
55
+ *
56
+ * @remarks
57
+ * Rejecting a result also drops an earlier retained success for equal input, which it replaces.
58
+ * Another input's retained success stays.
59
+ */
54
60
  readonly retain?: ((value: A, input: I) => boolean) | undefined;
55
61
  }
56
62
 
package/src/http/Body.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type HttpClientResponse,
6
6
  type UrlParams,
7
7
  } from "effect/http";
8
+ import * as Inputs from "./internal/input.js";
8
9
 
9
10
  /**
10
11
  * Turn an application value into a finite outgoing HTTP body.
@@ -14,6 +15,7 @@ import {
14
15
  */
15
16
  export interface Encoder<in A, out E = never, out R = never>
16
17
  extends Pipeable.Pipeable {
18
+ /** Turn a value into an outgoing body. */
17
19
  readonly encode: (value: A) => Effect.Effect<HttpBody.HttpBody, E, R>;
18
20
  }
19
21
 
@@ -26,6 +28,7 @@ export interface Encoder<in A, out E = never, out R = never>
26
28
  */
27
29
  export interface Decoder<out A, out E = never, out R = never>
28
30
  extends Pipeable.Pipeable {
31
+ /** Read a response's body into a value. */
29
32
  readonly decode: (
30
33
  response: HttpClientResponse.HttpClientResponse,
31
34
  ) => Effect.Effect<A, E, R>;
@@ -37,7 +40,8 @@ export interface Decoder<out A, out E = never, out R = never>
37
40
  * An encoder and decoder for the same application value.
38
41
  *
39
42
  * @remarks
40
- * Encoding and decoding errors and required services are tracked separately.
43
+ * Encoding and decoding errors and required services are tracked separately. `In` is what encoding
44
+ * takes, which is `A` unless the codec accepts more than it decodes to, as {@link jsonSchema} does.
41
45
  */
42
46
  export interface Codec<
43
47
  A,
@@ -45,9 +49,10 @@ export interface Codec<
45
49
  DecodeError = never,
46
50
  EncodeServices = never,
47
51
  DecodeServices = never,
52
+ In = A,
48
53
  >
49
54
  extends
50
- Encoder<A, EncodeError, EncodeServices>,
55
+ Encoder<In, EncodeError, EncodeServices>,
51
56
  Decoder<A, DecodeError, DecodeServices> {}
52
57
 
53
58
  /**
@@ -82,7 +87,7 @@ export const decoder = <A, E = never, R = never>(
82
87
  *
83
88
  * @remarks
84
89
  * `mediaType` describes the accepted response representation. Outgoing content metadata comes
85
- * from the `HttpBody` returned by `encode`.
90
+ * from the `HttpBody` returned by `encode`. `encode` may take more than `decode` returns.
86
91
  */
87
92
  export const make = <
88
93
  A,
@@ -90,15 +95,16 @@ export const make = <
90
95
  DecodeError = never,
91
96
  EncodeServices = never,
92
97
  DecodeServices = never,
98
+ In = A,
93
99
  >(options: {
94
100
  readonly encode: (
95
- value: A,
101
+ value: In,
96
102
  ) => Effect.Effect<HttpBody.HttpBody, EncodeError, EncodeServices>;
97
103
  readonly decode: (
98
104
  response: HttpClientResponse.HttpClientResponse,
99
105
  ) => Effect.Effect<A, DecodeError, DecodeServices>;
100
106
  readonly mediaType?: string | undefined;
101
- }): Codec<A, EncodeError, DecodeError, EncodeServices, DecodeServices> => ({
107
+ }): Codec<A, EncodeError, DecodeError, EncodeServices, DecodeServices, In> => ({
102
108
  ...Pipeable.Prototype,
103
109
  encode: options.encode,
104
110
  decode: options.decode,
@@ -176,8 +182,9 @@ export const bytes: Codec<Uint8Array, never, HttpClientError.HttpClientError> =
176
182
  * Read and write Web `FormData` as multipart form data.
177
183
  *
178
184
  * @remarks
179
- * The transport supplies the outgoing multipart boundary and its Content-Type. Do not set a
180
- * boundary-less Content-Type manually. Decoding delegates to the HTTP provider.
185
+ * The transport supplies the outgoing multipart boundary and its Content-Type. A Content-Type the
186
+ * request declares replaces it, and without the boundary the body cannot be read. Decoding
187
+ * delegates to the HTTP provider.
181
188
  */
182
189
  export const formData: Codec<FormData, never, HttpClientError.HttpClientError> =
183
190
  make({
@@ -255,7 +262,7 @@ export const mapEffect =
255
262
  * ```ts
256
263
  * import { Schema } from "effect";
257
264
  * import { Body } from "viell-effect-schema-http";
258
- * const numberFromText = Body.text.pipe(Body.schema(Schema.NumberFromString));
265
+ * const numberFromText = Body.text.pipe(Body.schema(Schema.FiniteFromString));
259
266
  * // Decodes the text "42" to the number 42.
260
267
  * ```
261
268
  *
@@ -276,18 +283,26 @@ export const schema = <S extends Schema.Constraint>(contract: S) => {
276
283
  *
277
284
  * @remarks
278
285
  * The schema's encoded type must match the underlying encoder's input. Returns an encoder only;
279
- * use {@link schema} for the decoding direction.
286
+ * use {@link schema} for the decoding direction. The input takes either side of the schema, or a
287
+ * mix by field, as `Request.Input` describes, so a plain object works for a `Schema.Class`, and
288
+ * the underlying encoder receives what the schema writes.
280
289
  */
281
- export const encodeSchema = <S extends Schema.Constraint>(contract: S) => {
282
- const encode = Schema.encodeEffect(contract);
290
+ export const encodeSchema = <S extends Schema.Top>(contract: S) => {
291
+ const encode = Inputs.encoder(contract, Schema.encodeEffect(contract));
283
292
  return <E, R>(
284
293
  self: Encoder<S["Encoded"], E, R>,
285
- ): Encoder<S["Type"], E | Schema.SchemaError, R | S["EncodingServices"]> =>
286
- encoder((value: S["Type"]) => Effect.flatMap(encode(value), self.encode));
294
+ ): Encoder<
295
+ Inputs.Input<S>,
296
+ E | Schema.SchemaError,
297
+ R | S["EncodingServices"] | S["DecodingServices"]
298
+ > =>
299
+ encoder((value: Inputs.Input<S>) =>
300
+ Effect.flatMap(encode(value), self.encode),
301
+ );
287
302
  };
288
303
 
289
304
  /**
290
- * Read and write schema-validated JSON using the schema's application type.
305
+ * Read and write schema-validated JSON, returning the schema's application type.
291
306
  *
292
307
  * @example
293
308
  * ```ts
@@ -299,19 +314,27 @@ export const encodeSchema = <S extends Schema.Constraint>(contract: S) => {
299
314
  * @remarks
300
315
  * Uses `Schema.toCodecJson` to obtain the schema's canonical JSON codec. Encoding failures occur
301
316
  * before dispatch; an operation wraps response decoding failures in `Response.DecodeError`.
317
+ *
318
+ * Encoding takes either side of the schema, or a mix by field, as `Request.Input` describes, and
319
+ * writes the canonical JSON. The encoded side is the schema's own, so a `Schema.Date` field takes a
320
+ * `Date`, not the ISO text JSON carries. Decoding returns the schema's application type, so a class
321
+ * comes back as an instance.
302
322
  */
303
- export const jsonSchema = <S extends Schema.Constraint>(
323
+ export const jsonSchema = <S extends Schema.Top>(
304
324
  contract: S,
305
325
  ): Codec<
306
326
  S["Type"],
307
327
  Schema.SchemaError | HttpBody.HttpBodyError,
308
328
  Schema.SchemaError | HttpClientError.HttpClientError,
309
- S["EncodingServices"],
310
- S["DecodingServices"]
329
+ S["EncodingServices"] | S["DecodingServices"],
330
+ S["DecodingServices"],
331
+ Inputs.Input<S>
311
332
  > => {
312
333
  const codec = Schema.toCodecJson(contract);
334
+ const encode = Inputs.encoder(contract, Schema.encodeEffect(codec));
313
335
  return make({
314
- encode: encodeSchema(codec)(json).encode,
336
+ encode: (value: Inputs.Input<S>) =>
337
+ Effect.flatMap(encode(value), json.encode),
315
338
  decode: json.pipe(schema(codec)).decode,
316
339
  mediaType: json.mediaType,
317
340
  });