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.
- package/README.md +44 -29
- package/dist/concurrency/Interaction.d.ts +7 -1
- package/dist/concurrency/Interaction.d.ts.map +1 -1
- package/dist/concurrency/Interaction.js.map +1 -1
- package/dist/http/Body.d.ts +25 -13
- package/dist/http/Body.d.ts.map +1 -1
- package/dist/http/Body.js +18 -8
- package/dist/http/Body.js.map +1 -1
- package/dist/http/Operation.d.ts +276 -13
- package/dist/http/Operation.d.ts.map +1 -1
- package/dist/http/Operation.js +210 -11
- package/dist/http/Operation.js.map +1 -1
- package/dist/http/Policy.d.ts +28 -2
- package/dist/http/Policy.d.ts.map +1 -1
- package/dist/http/Policy.js +28 -2
- package/dist/http/Policy.js.map +1 -1
- package/dist/http/Request.d.ts +520 -85
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +658 -143
- package/dist/http/Request.js.map +1 -1
- package/dist/http/Response.d.ts +130 -6
- package/dist/http/Response.d.ts.map +1 -1
- package/dist/http/Response.js +88 -7
- package/dist/http/Response.js.map +1 -1
- package/dist/http/UrlEncoding.d.ts +24 -7
- package/dist/http/UrlEncoding.d.ts.map +1 -1
- package/dist/http/UrlEncoding.js +7 -3
- package/dist/http/UrlEncoding.js.map +1 -1
- package/dist/http/internal/excess.d.ts +44 -0
- package/dist/http/internal/excess.d.ts.map +1 -0
- package/dist/http/internal/excess.js +231 -0
- package/dist/http/internal/excess.js.map +1 -0
- package/dist/http/internal/fields.d.ts +17 -4
- package/dist/http/internal/fields.d.ts.map +1 -1
- package/dist/http/internal/fields.js +11 -6
- package/dist/http/internal/fields.js.map +1 -1
- package/dist/http/internal/input.d.ts +70 -0
- package/dist/http/internal/input.d.ts.map +1 -0
- package/dist/http/internal/input.js +93 -0
- package/dist/http/internal/input.js.map +1 -0
- package/dist/http/internal/shape.d.ts +63 -0
- package/dist/http/internal/shape.d.ts.map +1 -0
- package/dist/http/internal/shape.js +225 -0
- package/dist/http/internal/shape.js.map +1 -0
- package/package.json +13 -12
- package/src/concurrency/Interaction.ts +7 -1
- package/src/http/Body.ts +41 -18
- package/src/http/Operation.ts +474 -33
- package/src/http/Policy.ts +30 -2
- package/src/http/Request.ts +1176 -253
- package/src/http/Response.ts +246 -23
- package/src/http/UrlEncoding.ts +32 -8
- package/src/http/internal/excess.ts +333 -0
- package/src/http/internal/fields.ts +37 -9
- package/src/http/internal/input.ts +228 -0
- package/src/http/internal/shape.ts +359 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { Equal, Schema, SchemaAST, SchemaIssue } from "effect";
|
|
2
|
+
/** Parse options that make a schema refuse what it would strip. */
|
|
3
|
+
export const strict = { onExcessProperty: "error" };
|
|
4
|
+
/**
|
|
5
|
+
* The node a schema's encoding ends at. `toEncoded` gives the same names, but it flattens each
|
|
6
|
+
* field's own encoding away, and that encoding is how a field says what it writes.
|
|
7
|
+
*/
|
|
8
|
+
export const encodedEnd = (ast) => {
|
|
9
|
+
const last = ast.encoding?.at(-1);
|
|
10
|
+
return last === undefined ? ast : encodedEnd(last.to);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The parts of a schema this can see. What a declaration holds, as an `Option` or a `Map` does, is
|
|
14
|
+
* not among them: nothing here can reach it, so the schema's own reading applies there.
|
|
15
|
+
*/
|
|
16
|
+
const partsOf = (ast) => {
|
|
17
|
+
switch (ast._tag) {
|
|
18
|
+
case "Objects":
|
|
19
|
+
return [...ast.propertySignatures, ...ast.indexSignatures].map(({ type }) => type);
|
|
20
|
+
case "Arrays":
|
|
21
|
+
return [...ast.elements, ...ast.rest];
|
|
22
|
+
case "Union":
|
|
23
|
+
return ast.types;
|
|
24
|
+
default:
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/** Whether a schema can read an object's keys, and so can strip one of them. */
|
|
29
|
+
const readsKeys = (ast) => ast._tag === "Objects" ||
|
|
30
|
+
ast._tag === "ObjectKeyword" ||
|
|
31
|
+
ast._tag === "Suspend" ||
|
|
32
|
+
ast._tag === "Unknown" ||
|
|
33
|
+
ast._tag === "Any" ||
|
|
34
|
+
partsOf(ast).some(readsKeys) ||
|
|
35
|
+
(ast.encoding ?? []).some(({ to }) => readsKeys(to));
|
|
36
|
+
/** A choice of member: a union between objects, or a suspended schema, which may not exist yet. */
|
|
37
|
+
const isMemberChoice = (ast) => ast._tag === "Suspend" ||
|
|
38
|
+
(ast._tag === "Union" && ast.types.filter(readsKeys).length > 1);
|
|
39
|
+
/**
|
|
40
|
+
* A choice of side: two ends that do not state the same names, as a renamed field's do, or an
|
|
41
|
+
* encoded end with a rest. A value on the encoded side can then fit the decoded side by losing the
|
|
42
|
+
* names it holds. An encoded side with no keys, such as text, has none to lose.
|
|
43
|
+
*/
|
|
44
|
+
const isSideChoice = (ast) => {
|
|
45
|
+
const end = encodedEnd(ast);
|
|
46
|
+
if (end === ast || !readsKeys(end))
|
|
47
|
+
return false;
|
|
48
|
+
const decoded = fieldsOf(ast).map(({ name }) => name);
|
|
49
|
+
const encoded = fieldsOf(end).map(({ name }) => name);
|
|
50
|
+
return (decoded.length !== encoded.length ||
|
|
51
|
+
decoded.some((name) => !encoded.includes(name)) ||
|
|
52
|
+
(end._tag === "Objects" && end.indexSignatures.length > 0));
|
|
53
|
+
};
|
|
54
|
+
const holding = (isChoice) => {
|
|
55
|
+
const holds = (ast) => isChoice(ast) ||
|
|
56
|
+
partsOf(ast).some(holds) ||
|
|
57
|
+
(ast.encoding ?? []).some(({ to }) => holds(to));
|
|
58
|
+
return holds;
|
|
59
|
+
};
|
|
60
|
+
/** The fields of a struct or class, as they are declared, with each field's own encoding. */
|
|
61
|
+
export const fieldsOf = (ast) => ast._tag === "Objects"
|
|
62
|
+
? ast.propertySignatures
|
|
63
|
+
: ast._tag === "Declaration" && ast.encoding !== undefined
|
|
64
|
+
? fieldsOf(ast.encoding[0].to)
|
|
65
|
+
: [];
|
|
66
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
67
|
+
/** A plain object or a list, which can be taken apart. A class instance needs a reason to be. */
|
|
68
|
+
const isPlain = (value) => {
|
|
69
|
+
if (!isObject(value))
|
|
70
|
+
return false;
|
|
71
|
+
if (Array.isArray(value))
|
|
72
|
+
return true;
|
|
73
|
+
const prototype = Object.getPrototypeOf(value);
|
|
74
|
+
return prototype === Object.prototype || prototype === null;
|
|
75
|
+
};
|
|
76
|
+
const keysOf = (value) => Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key));
|
|
77
|
+
/** Whether a side only holds literals, and this value is none of them. */
|
|
78
|
+
const refuses = (side, value) => side._tag === "Literal"
|
|
79
|
+
? side.literal !== value
|
|
80
|
+
: side._tag === "Union" &&
|
|
81
|
+
side.types.every((member) => refuses(member, value));
|
|
82
|
+
/** Whether a literal field refuses a value on every side, which a tag can rule out by. */
|
|
83
|
+
const refusesLiteral = (type, value) => [type, ...(type.encoding ?? []).map(({ to }) => to)].every((side) => refuses(side, value));
|
|
84
|
+
/** Whether a member's tag rules it out for a value, as Effect's union does before it reads one. */
|
|
85
|
+
const ruledOut = (member, value) => isObject(value) &&
|
|
86
|
+
fieldsOf(member).some(({ name, type }) => !SchemaAST.isOptional(type) &&
|
|
87
|
+
value[name] !== undefined &&
|
|
88
|
+
refusesLiteral(type, value[name]));
|
|
89
|
+
/** The schemas a value can be read against here: each member its tag leaves, on each side. */
|
|
90
|
+
const sidesOf = (ast, value) => [
|
|
91
|
+
...(ast._tag === "Union"
|
|
92
|
+
? ast.types
|
|
93
|
+
.filter((member) => !ruledOut(member, value))
|
|
94
|
+
.flatMap((member) => sidesOf(member, value))
|
|
95
|
+
: ast._tag === "Suspend"
|
|
96
|
+
? sidesOf(ast.thunk(), value)
|
|
97
|
+
: [ast]),
|
|
98
|
+
...(ast.encoding ?? []).flatMap(({ to }) => sidesOf(to, value)),
|
|
99
|
+
];
|
|
100
|
+
/** The schemas of what these sides hold under one key. */
|
|
101
|
+
const typesAt = (sides, key) => sides.flatMap((side) => {
|
|
102
|
+
if (side._tag === "Arrays") {
|
|
103
|
+
const element = side.elements[Number(key)];
|
|
104
|
+
return element === undefined ? side.rest : [element];
|
|
105
|
+
}
|
|
106
|
+
return side._tag === "Objects"
|
|
107
|
+
? [
|
|
108
|
+
...side.propertySignatures
|
|
109
|
+
.filter(({ name }) => name === key)
|
|
110
|
+
.map(({ type }) => type),
|
|
111
|
+
...side.indexSignatures.map(({ type }) => type),
|
|
112
|
+
]
|
|
113
|
+
: [];
|
|
114
|
+
});
|
|
115
|
+
/** The names on a schema's decoded side, which a value can use as well as the wire names. */
|
|
116
|
+
const decodedNames = (ast, value) => ast._tag === "Union"
|
|
117
|
+
? ast.types
|
|
118
|
+
.filter((member) => !ruledOut(member, value))
|
|
119
|
+
.flatMap((member) => decodedNames(member, value))
|
|
120
|
+
: ast._tag === "Suspend"
|
|
121
|
+
? decodedNames(ast.thunk(), value)
|
|
122
|
+
: fieldsOf(ast).map(({ name }) => String(name));
|
|
123
|
+
/** Whether these sides leave a value's keys open, so none can be called unstated. */
|
|
124
|
+
const leaveKeysOpen = (sides) => sides.some(({ _tag }) => _tag === "Any" || _tag === "Unknown" || _tag === "ObjectKeyword") || !sides.some(({ _tag }) => _tag === "Objects" || _tag === "Arrays");
|
|
125
|
+
/**
|
|
126
|
+
* The names a struct here reads from a value although they are no keys of it, as an accessor on a
|
|
127
|
+
* class is. A strict read only counts keys as excess, so it would strip such a field with no error.
|
|
128
|
+
*/
|
|
129
|
+
const unlisted = (sides, value) => Array.isArray(value)
|
|
130
|
+
? []
|
|
131
|
+
: Array.from(new Set(sides.flatMap(fieldsOf).map(({ name }) => name))).filter((name) => name !== "__proto__" &&
|
|
132
|
+
value[name] !== undefined &&
|
|
133
|
+
!Object.prototype.propertyIsEnumerable.call(value, name));
|
|
134
|
+
/**
|
|
135
|
+
* Whether only a struct can read a value here. A struct builds a plain object from any object, so a
|
|
136
|
+
* class instance loses nothing by becoming one. A declaration may need the instance itself, so
|
|
137
|
+
* there it keeps its keys, and stays an instance unless something in it has to change.
|
|
138
|
+
*/
|
|
139
|
+
const readAsStruct = (sides, open) => !open && !sides.some(({ _tag }) => _tag === "Declaration");
|
|
140
|
+
/** Bring a value's {@link unlisted} fields out as keys, at any depth, and take out what `drops` says. */
|
|
141
|
+
const rewriting = (drops) => {
|
|
142
|
+
const rewrite = (types, value) => {
|
|
143
|
+
if (types.length === 0 || !isObject(value))
|
|
144
|
+
return value;
|
|
145
|
+
const sides = types.flatMap((type) => sidesOf(type, value));
|
|
146
|
+
const hidden = unlisted(sides, value);
|
|
147
|
+
const open = leaveKeysOpen(sides);
|
|
148
|
+
const plain = isPlain(value);
|
|
149
|
+
const asStruct = !plain && readAsStruct(sides, open);
|
|
150
|
+
const isList = Array.isArray(value);
|
|
151
|
+
const keys = [...keysOf(value), ...hidden];
|
|
152
|
+
const entries = keys.flatMap((key) => {
|
|
153
|
+
const item = value[key];
|
|
154
|
+
const inner = typesAt(sides, key);
|
|
155
|
+
return (plain || asStruct) &&
|
|
156
|
+
!isList &&
|
|
157
|
+
drops(item, open || inner.length > 0)
|
|
158
|
+
? []
|
|
159
|
+
: [[key, rewrite(inner, item)]];
|
|
160
|
+
});
|
|
161
|
+
const same = !asStruct &&
|
|
162
|
+
hidden.length === 0 &&
|
|
163
|
+
entries.length === keys.length &&
|
|
164
|
+
entries.every(([key, item]) => item === value[key]);
|
|
165
|
+
return same
|
|
166
|
+
? value
|
|
167
|
+
: isList
|
|
168
|
+
? entries.map(([, item]) => item)
|
|
169
|
+
: Object.fromEntries(entries);
|
|
170
|
+
};
|
|
171
|
+
return rewrite;
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* What a caller means by a value, at any depth of plain objects and lists: no key set to `undefined`,
|
|
175
|
+
* which holds nothing, and no key the schema does not state, which a struct would strip anyway. A
|
|
176
|
+
* member a tag has ruled out states nothing. Returns `value` itself if there is nothing to change.
|
|
177
|
+
*/
|
|
178
|
+
export const normalised = rewriting((item, stated) => item === undefined || !stated);
|
|
179
|
+
/** A value as the caller gave it, but for what {@link unlisted} brings out as keys. */
|
|
180
|
+
export const exposed = rewriting(() => false);
|
|
181
|
+
/** The fields of a group the caller gave and a schema states, under either of their names. */
|
|
182
|
+
export const statedFields = (ast, value) => {
|
|
183
|
+
if (!isObject(value) || Array.isArray(value))
|
|
184
|
+
return [];
|
|
185
|
+
const sides = sidesOf(ast, value);
|
|
186
|
+
return [...keysOf(value), ...unlisted(sides, value)].filter((key) => value[key] !== undefined && typesAt(sides, key).length > 0);
|
|
187
|
+
};
|
|
188
|
+
const has = (value, key) => isObject(value) && key in value && value[key] !== undefined;
|
|
189
|
+
const at = (value, key) => isObject(value) ? value[key] : undefined;
|
|
190
|
+
/** Whether a value's keys mean something here: it is plain, or a struct here reads it. */
|
|
191
|
+
const comparable = (sides, value) => isPlain(value) || sides.some(({ _tag }) => _tag === "Objects");
|
|
192
|
+
/**
|
|
193
|
+
* What a read lost from `given`, a {@link normalised} value, by comparing it with what came out. A
|
|
194
|
+
* field has to be in the decoded value or in what was written. Under a name a member decodes, what
|
|
195
|
+
* was written has to be what was given too, because that name can be another field's on the wire.
|
|
196
|
+
* What this cannot see into, such as text or a `Map`, is left to the schema's own reading.
|
|
197
|
+
*/
|
|
198
|
+
export const missing = (types, given, value, output, path = []) => {
|
|
199
|
+
if (!isObject(given))
|
|
200
|
+
return [];
|
|
201
|
+
const sides = types.flatMap((type) => sidesOf(type, given));
|
|
202
|
+
if (!comparable(sides, given))
|
|
203
|
+
return [];
|
|
204
|
+
const decoded = new Set(types.flatMap((type) => decodedNames(type, given)));
|
|
205
|
+
const holdsAsWritten = (key) => has(output, key) &&
|
|
206
|
+
(!isObject(value) ||
|
|
207
|
+
!decoded.has(String(key)) ||
|
|
208
|
+
Equal.equals(at(output, key), given[key]));
|
|
209
|
+
return keysOf(given).flatMap((key) => {
|
|
210
|
+
const here = [...path, Array.isArray(given) ? Number(key) : key];
|
|
211
|
+
return given[key] === undefined || has(value, key) || holdsAsWritten(key)
|
|
212
|
+
? missing(typesAt(sides, key), given[key], at(value, key), at(output, key), here)
|
|
213
|
+
: [here];
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
const notHeld = new SchemaIssue.InvalidValue({
|
|
217
|
+
message: "The schema cannot keep this field with the rest of the value",
|
|
218
|
+
});
|
|
219
|
+
/** A refusal that names the fields and, like any other schema failure here, leaves out values. */
|
|
220
|
+
export const refusal = (ast, [first, ...others]) => new Schema.SchemaError(new SchemaIssue.Composite(ast, [
|
|
221
|
+
new SchemaIssue.Pointer(first, notHeld),
|
|
222
|
+
...others.map((path) => new SchemaIssue.Pointer(path, notHeld)),
|
|
223
|
+
]));
|
|
224
|
+
/** Whether a schema holds a choice of member, which only a stacked schema can settle for it. */
|
|
225
|
+
export const choosesMember = holding(isMemberChoice);
|
|
226
|
+
/**
|
|
227
|
+
* Whether a schema holds a choice that can cost a field, of member or of side, anywhere it can be
|
|
228
|
+
* seen. Any other schema skips the strict pass. `Schema.NullOr` around a struct has no such choice.
|
|
229
|
+
*/
|
|
230
|
+
export const choosing = holding((ast) => isMemberChoice(ast) || isSideChoice(ast));
|
|
231
|
+
//# sourceMappingURL=excess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excess.js","sourceRoot":"","sources":["../../../src/http/internal/excess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAO/D,mEAAmE;AACnE,MAAM,CAAC,MAAM,MAAM,GAA2B,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;AAE5E;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAO,EAAE;IAC1C,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC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AAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,YAAY,CAAC;IAC3C,OAAO,EAAE,8DAA8D;CACxE,CAAC,CAAC;AAEH,kGAAkG;AAClG,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,GAAQ,EACR,CAAC,KAAK,EAAE,GAAG,MAAM,CAA0C,EACvC,EAAE,CACtB,IAAI,MAAM,CAAC,WAAW,CACpB,IAAI,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE;IAC7B,IAAI,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC;IACvC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;CAChE,CAAC,CACH,CAAC;AAEJ,gGAAgG;AAChG,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAErD;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAC7B,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,CAClD,CAAC"}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
/** A field value, or a computation that stays data until materialization. `undefined` omits the field. */
|
|
2
2
|
export type Value<A = string> = A | (() => A | undefined);
|
|
3
|
+
/**
|
|
4
|
+
* One declaration. A query entry written in a request's constructor also keeps that text. An edit
|
|
5
|
+
* makes a new entry, so the text falls away with the old one.
|
|
6
|
+
*/
|
|
7
|
+
export type Field<A = string> = readonly [
|
|
8
|
+
name: string,
|
|
9
|
+
value: Value<A>,
|
|
10
|
+
written?: string
|
|
11
|
+
];
|
|
3
12
|
/** Ordered declarations. Entries preserve repetition and their order across names. */
|
|
4
|
-
export type Fields<A = string> = ReadonlyArray<
|
|
5
|
-
/**
|
|
6
|
-
export
|
|
13
|
+
export type Fields<A = string> = ReadonlyArray<Field<A>>;
|
|
14
|
+
/** The form two names are compared in. Entries keep their own spelling. */
|
|
15
|
+
export type Fold = (name: string) => string;
|
|
16
|
+
/** Put values at a name's first position and drop its later entries, or append new entries. */
|
|
17
|
+
export declare const replace: <A>(fields: Fields<A>, name: string, values: ReadonlyArray<Value<A>>, fold?: Fold) => Fields<A>;
|
|
18
|
+
/** Replace a name with one value. */
|
|
19
|
+
export declare const set: <A>(fields: Fields<A>, name: string, value: Value<A>, fold?: Fold) => Fields<A>;
|
|
7
20
|
export declare const append: <A>(fields: Fields<A>, name: string, value: Value<A>) => Fields<A>;
|
|
8
21
|
/** Without a value, remove the whole name. With one, remove matching static entries without evaluating computations. */
|
|
9
|
-
export declare const remove: <A>(fields: Fields<A>, name: string, value?: A) => Fields<A>;
|
|
22
|
+
export declare const remove: <A>(fields: Fields<A>, name: string, value?: A, fold?: Fold) => Fields<A>;
|
|
10
23
|
/** Evaluate every surviving computation once, omitting `undefined` results. */
|
|
11
24
|
export declare const resolve: <A extends string | null>(fields: Fields<A>) => Array<readonly [string, A]>;
|
|
12
25
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/http/internal/fields.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;AAE1D,sFAAsF;AACtF,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,MAAM,IAAI,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/http/internal/fields.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS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AI,EAC7C,QAAQ,MAAM,CAAC,CAAC,CAAC,KAChB,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAO5B,CAAC"}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const exact = (name) => name;
|
|
2
|
+
/** Put values at a name's first position and drop its later entries, or append new entries. */
|
|
3
|
+
export const replace = (fields, name, values, fold = exact) => {
|
|
4
|
+
const folded = fold(name);
|
|
5
|
+
const position = fields.findIndex(([key]) => fold(key) === folded);
|
|
6
|
+
const entries = values.map((value) => [name, value]);
|
|
4
7
|
if (position < 0)
|
|
5
|
-
return [...fields,
|
|
6
|
-
return fields.flatMap((entry, index) => index === position ?
|
|
8
|
+
return [...fields, ...entries];
|
|
9
|
+
return fields.flatMap((entry, index) => index === position ? entries : fold(entry[0]) === folded ? [] : [entry]);
|
|
7
10
|
};
|
|
11
|
+
/** Replace a name with one value. */
|
|
12
|
+
export const set = (fields, name, value, fold = exact) => replace(fields, name, [value], fold);
|
|
8
13
|
export const append = (fields, name, value) => [...fields, [name, value]];
|
|
9
14
|
/** Without a value, remove the whole name. With one, remove matching static entries without evaluating computations. */
|
|
10
|
-
export const remove = (fields, name, value) => fields.filter(([key, entry]) => key !== name || (value !== undefined && entry !== value));
|
|
15
|
+
export const remove = (fields, name, value, fold = exact) => fields.filter(([key, entry]) => fold(key) !== fold(name) || (value !== undefined && entry !== value));
|
|
11
16
|
/** Evaluate every surviving computation once, omitting `undefined` results. */
|
|
12
17
|
export const resolve = (fields) => {
|
|
13
18
|
const output = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/http/internal/fields.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../src/http/internal/fields.ts"],"names":[],"mappings":"AAmBA,MAAM,KAAK,GAAS,CAAC,IAAI,EAAE,EAAE,CAAC,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AG,CACpB,MAAiB,EACjB,IAAY,EACZ,KAAS,EACT,OAAa,KAAK,EACP,EAAE,CACb,MAAM,CAAC,MAAM,CACX,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACf,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK,CAAC,CACvE,CAAC;AAEJ,+EAA+E;AAC/E,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,MAAiB,EACY,EAAE;IAC/B,MAAM,MAAM,GAAgC,EAAE,CAAC;IAC/C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/D,IAAI,QAAQ,KAAK,SAAS;YAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Effect, Schema, type SchemaAST } from "effect";
|
|
2
|
+
import * as Excess from "./excess.js";
|
|
3
|
+
/** What a schema's constructor takes. This is the one place that names the `~`-prefixed key. */
|
|
4
|
+
type ConstructorInput<S extends Schema.Top> = S["~type.make.in"];
|
|
5
|
+
/** A field's type on the encoded side, in whichever union members have it. */
|
|
6
|
+
type EncodedField<B, K> = B extends unknown ? K extends keyof B ? B[K] : never : never;
|
|
7
|
+
/**
|
|
8
|
+
* Either side of a schema, chosen field by field. A list is a value, so it has no fields, and an
|
|
9
|
+
* object whose encoded side is not one, such as a `Date` from text, has none to choose from.
|
|
10
|
+
*/
|
|
11
|
+
type Fieldwise<A, B> = A extends ReadonlyArray<unknown> ? never : A extends object ? B extends object ? {
|
|
12
|
+
readonly [K in keyof A]: A[K] | EncodedField<B, K>;
|
|
13
|
+
} : never : never;
|
|
14
|
+
/** Every key of every member. `keyof` on a union keeps only the keys all its members share. */
|
|
15
|
+
type KeysOf<T> = T extends unknown ? keyof T : never;
|
|
16
|
+
/**
|
|
17
|
+
* Leave out the sides when the mix takes everything they do, which an editor would show three times.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Assignability is not enough on its own, because a stray key in a literal is an error against the
|
|
21
|
+
* mix even when the value is assignable to it. A renamed field needs its side for that reason, and
|
|
22
|
+
* a field the mix requires and one side leaves out needs its side too.
|
|
23
|
+
*/
|
|
24
|
+
type Merged<Sides, Mix> = [Sides] extends [Mix] ? [KeysOf<Sides>] extends [KeysOf<Mix>] ? Mix : Sides | Mix : Sides | Mix;
|
|
25
|
+
type EitherSide<A, B> = [A, B] extends [B, A] ? A : Merged<A | B, Fieldwise<A, B>>;
|
|
26
|
+
/** What a schema-backed input takes: its decoded side, its encoded side, or a mix by field. */
|
|
27
|
+
export type Input<S extends Schema.Top> = EitherSide<ConstructorInput<S>, S["Encoded"]>;
|
|
28
|
+
/**
|
|
29
|
+
* Bring a value on either side of a schema to its decoded side.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* A value that fits the decoded side is read as decoded, so it is encoded once. Anything else goes
|
|
33
|
+
* through the decoder as a whole, then field by field. Both routes validate, and a value that fits
|
|
34
|
+
* neither fails with the decoded side's error, so existing failures read the same. `options` go to
|
|
35
|
+
* every parse.
|
|
36
|
+
*/
|
|
37
|
+
export declare const toDecoded: <S extends Schema.Top>(contract: S, options?: SchemaAST.ParseOptions) => (input: Input<S>) => Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"]>;
|
|
38
|
+
/** What a schema wrote, and the fields of its input it would lose, which may be held elsewhere. */
|
|
39
|
+
export interface Written<A> {
|
|
40
|
+
readonly output: A;
|
|
41
|
+
readonly lost: ReadonlyArray<Excess.Path>;
|
|
42
|
+
}
|
|
43
|
+
/** Takes a decoded value out through a schema, as the options say. */
|
|
44
|
+
type Write<S extends Schema.Top, A, R> = (value: S["Type"], options?: SchemaAST.ParseOptions) => Effect.Effect<A, Schema.SchemaError, R>;
|
|
45
|
+
/**
|
|
46
|
+
* Bring a value to the schema's decoded side, then write it, and say what that would lose.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* Effect takes the first union member that fits and strips what that member does not state, on the
|
|
50
|
+
* decoded side and again when it encodes, so a later member that holds everything would lose to an
|
|
51
|
+
* earlier one that holds part of it. A value on a schema's encoded side can lose to its decoded side
|
|
52
|
+
* in the same way, where the two state different names. So a schema with either choice reads what
|
|
53
|
+
* the caller means strictly, through both steps, and a read that passes has stripped nothing.
|
|
54
|
+
*
|
|
55
|
+
* A value that cannot be read that way is read as Effect reads it, and the result is compared with
|
|
56
|
+
* what went in, so what is lost is what actually went, not what a failure suggests would. The write
|
|
57
|
+
* is strict first, because a loose write can choose another member and lose what the read kept.
|
|
58
|
+
*
|
|
59
|
+
* A schema with neither choice skips all of this, so a plain struct costs what it always did.
|
|
60
|
+
*/
|
|
61
|
+
export declare const reader: <S extends Schema.Top, A, R>(contract: S, write: Write<S, A, R>) => (input: Input<S>) => Effect.Effect<Written<A>, Schema.SchemaError, R | S["DecodingServices"]>;
|
|
62
|
+
/**
|
|
63
|
+
* Refuse the fields a schema would lose, unless another schema in the group took them. Only a field
|
|
64
|
+
* of the group itself can be taken, so one further down a value stays lost.
|
|
65
|
+
*/
|
|
66
|
+
export declare const refuseLost: (contract: Schema.Top, lost: ReadonlyArray<Excess.Path>, taken?: ReadonlySet<PropertyKey>) => Effect.Effect<void, Schema.SchemaError>;
|
|
67
|
+
/** Bring a value to the schema's decoded side and write it, with nothing else to hold what it loses. */
|
|
68
|
+
export declare const encoder: <S extends Schema.Top, A, R>(contract: S, write: Write<S, A, R>) => (input: EitherSide<ConstructorInput<S>, S["Encoded"]>) => Effect.Effect<A, Schema.SchemaError, R | S["DecodingServices"]>;
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/http/internal/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAEtC,gGAAgG;AAChG,KAAK,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,eAAe,CAAC,CAAC;AAEjE,8EAA8E;AAC9E,KAAK,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,OAAO,GACvC,CAAC,SAAS,MAAM,CAAC,GACf,CAAC,CAAC,CAAC,CAAC,GACJ,KAAK,GACP,KAAK,CAAC;AAEV;;;GAGG;AACH,KAAK,SAAS,CAAC,CAAC,EAAE,CAAC,IACjB,CAAC,SAAS,aAAa,CAAC,OAAO,CAAC,GAC5B,KAAK,GACL,CAAC,SAAS,MAAM,GACd,CAAC,SAAS,MAAM,GACd;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;CAAE,GACtD,KAAK,GACP,KAAK,CAAC;AAEd,+FAA+F;AAC/F,KAAK,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC;AAErD;;;;;;;GAOG;AACH,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,GAC3C,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GACnC,GAAG,GACH,KAAK,GAAG,GAAG,GACb,K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,EAAE,CAAC,EAC/C,UAAU,CAAC,EACX,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,aAKJ,KAAK,CAAC,CAAC,CAAC,6EAqC1B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,CAAC,GAAG,EACpB,MAAM,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAChC,QAAQ,WAAW,CAAC,WAAW,CAAC,KAC/B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,CAOxC,CAAC;AAEF,wGAAwG;AACxG,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAChD,UAAU,CAAC,EACX,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,8HAUtB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import * as Excess from "./excess.js";
|
|
3
|
+
/**
|
|
4
|
+
* Bring a value on either side of a schema to its decoded side.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A value that fits the decoded side is read as decoded, so it is encoded once. Anything else goes
|
|
8
|
+
* through the decoder as a whole, then field by field. Both routes validate, and a value that fits
|
|
9
|
+
* neither fails with the decoded side's error, so existing failures read the same. `options` go to
|
|
10
|
+
* every parse.
|
|
11
|
+
*/
|
|
12
|
+
export const toDecoded = (contract, options) => {
|
|
13
|
+
const making = options && { parseOptions: options };
|
|
14
|
+
const make = (input) => Effect.mapError(contract.makeEffect(input, making), (issue) => new Schema.SchemaError(issue));
|
|
15
|
+
const decode = Schema.decodeUnknownEffect(contract);
|
|
16
|
+
const byField = Effect.fnUntraced(function* (input) {
|
|
17
|
+
const output = { ...input };
|
|
18
|
+
// A field need not be a key, as an accessor on a class is not, so it comes from `input`.
|
|
19
|
+
const fields = input;
|
|
20
|
+
for (const { name, type } of Excess.fieldsOf(contract.ast))
|
|
21
|
+
if (fields[name] !== undefined)
|
|
22
|
+
output[name] = yield* fromPart(type, fields[name], options);
|
|
23
|
+
return yield* make(output);
|
|
24
|
+
});
|
|
25
|
+
const byMember = (input) => contract.ast._tag === "Union" && contract.ast.types.length > 0
|
|
26
|
+
? Effect.firstSuccessOf(contract.ast.types.map((member) => fromPart(member, input, options)))
|
|
27
|
+
: byField(input);
|
|
28
|
+
return (input) => Effect.catch(make(input), (failure) => Effect.mapError(Effect.catch(decode(input, options), (encodedFailure) => typeof input === "object" && input !== null
|
|
29
|
+
? byMember(input)
|
|
30
|
+
: Effect.fail(encodedFailure)), () => failure));
|
|
31
|
+
};
|
|
32
|
+
/** Read a field or union member, which may be on either side of its own schema. */
|
|
33
|
+
const fromPart = (ast, value, options) => toDecoded(Schema.make(ast), options)(value);
|
|
34
|
+
/** Bring a value to the schema's decoded side, then write it, as Effect reads it. */
|
|
35
|
+
const stripping = (contract, write) => {
|
|
36
|
+
const decoded = toDecoded(contract);
|
|
37
|
+
return (input) => Effect.flatMap(decoded(input), write);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Bring a value to the schema's decoded side, then write it, and say what that would lose.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Effect takes the first union member that fits and strips what that member does not state, on the
|
|
44
|
+
* decoded side and again when it encodes, so a later member that holds everything would lose to an
|
|
45
|
+
* earlier one that holds part of it. A value on a schema's encoded side can lose to its decoded side
|
|
46
|
+
* in the same way, where the two state different names. So a schema with either choice reads what
|
|
47
|
+
* the caller means strictly, through both steps, and a read that passes has stripped nothing.
|
|
48
|
+
*
|
|
49
|
+
* A value that cannot be read that way is read as Effect reads it, and the result is compared with
|
|
50
|
+
* what went in, so what is lost is what actually went, not what a failure suggests would. The write
|
|
51
|
+
* is strict first, because a loose write can choose another member and lose what the read kept.
|
|
52
|
+
*
|
|
53
|
+
* A schema with neither choice skips all of this, so a plain struct costs what it always did.
|
|
54
|
+
*/
|
|
55
|
+
export const reader = (contract, write) => {
|
|
56
|
+
const stripped = stripping(contract, write);
|
|
57
|
+
const keepsAll = (output) => ({ output, lost: [] });
|
|
58
|
+
if (!Excess.choosing(contract.ast))
|
|
59
|
+
return (input) => Effect.map(stripped(input), keepsAll);
|
|
60
|
+
const decoded = toDecoded(contract);
|
|
61
|
+
const exact = toDecoded(contract, Excess.strict);
|
|
62
|
+
const kept = (input) => Effect.flatMap(exact(input), (value) => write(value, Excess.strict));
|
|
63
|
+
const compared = (input, given) => Effect.flatMap(decoded(input), (value) => Effect.map(Effect.catch(write(value, Excess.strict), () => write(value)), (output) => ({
|
|
64
|
+
output,
|
|
65
|
+
lost: Excess.missing([contract.ast], given, value, output),
|
|
66
|
+
})));
|
|
67
|
+
return (input) => {
|
|
68
|
+
const given = Excess.normalised([contract.ast], input);
|
|
69
|
+
// A strict read cannot see a field outside a value's keys, so it may not fall back on `input`.
|
|
70
|
+
const seen = (given === input ? input : Excess.exposed([contract.ast], input));
|
|
71
|
+
return Effect.catch(Effect.map(given === input
|
|
72
|
+
? kept(input)
|
|
73
|
+
: Effect.catch(kept(given), () => kept(seen)), keepsAll), () => compared(input, given));
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Refuse the fields a schema would lose, unless another schema in the group took them. Only a field
|
|
78
|
+
* of the group itself can be taken, so one further down a value stays lost.
|
|
79
|
+
*/
|
|
80
|
+
export const refuseLost = (contract, lost, taken) => {
|
|
81
|
+
const [first, ...others] = lost.filter((path) => path.length > 1 || taken?.has(path[0]) !== true);
|
|
82
|
+
return first === undefined
|
|
83
|
+
? Effect.void
|
|
84
|
+
: Effect.fail(Excess.refusal(contract.ast, [first, ...others]));
|
|
85
|
+
};
|
|
86
|
+
/** Bring a value to the schema's decoded side and write it, with nothing else to hold what it loses. */
|
|
87
|
+
export const encoder = (contract, write) => {
|
|
88
|
+
if (!Excess.choosing(contract.ast))
|
|
89
|
+
return stripping(contract, write);
|
|
90
|
+
const read = reader(contract, write);
|
|
91
|
+
return (input) => Effect.flatMap(read(input), ({ output, lost }) => Effect.as(refuseLost(contract, lost), output));
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../../src/http/internal/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAoDtC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,QAAW,EACX,OAAgC,EAChC,EAAE;IACF,MAAM,MAAM,GAAG,OAAO,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;IACpD,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,EAAE,CAC9B,MAAM,CAAC,QAAQ,CACb,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,EAClC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CACzC,CAAC;IACJ,MAAM,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAa;QACxD,MAAM,MAAM,GAAiC,EAAE,GAAG,KAAK,EAAE,CAAC;QAC1D,yFAAyF;QACzF,MAAM,MAAM,GAAiC,KAAc,CAAC;QAC5D,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;YACxD,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS;gBAC5B,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,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C,IAAI,CAAC,CAAC,CAAE,CAAC,KAAK,IAAI,CAC3D,CAAC;IACF,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,MAAM,CAAC,IAAI;QACb,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,wGAAwG;AACxG,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,QAAW,EACX,KAAqB,EACrB,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACtE,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CACL,KAAe,EACkD,EAAE,CACnE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,CAC/C,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAC9C,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import * as Excess from "./excess.js";
|
|
3
|
+
import type { Fold } from "./fields.js";
|
|
4
|
+
/** What one schema says about its field group. Names are wire names, in their compared form. */
|
|
5
|
+
export interface Shape {
|
|
6
|
+
/** The names the schema states. */
|
|
7
|
+
readonly names: ReadonlySet<string>;
|
|
8
|
+
/** Whether it allows names it does not state, as a record or a list of pairs does. */
|
|
9
|
+
readonly open: boolean;
|
|
10
|
+
/** The names it always writes, so a raw edit of one could never reach the client. */
|
|
11
|
+
readonly required: ReadonlySet<string>;
|
|
12
|
+
/** Whether it holds a union that can lose a field, which a stacked schema may take. */
|
|
13
|
+
readonly chooses: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** What the schemas stacked on a group have told each other. */
|
|
16
|
+
export interface Taken {
|
|
17
|
+
/** The fields of the caller's input a schema took. Only this says a field is not lost. */
|
|
18
|
+
readonly fields: ReadonlySet<PropertyKey>;
|
|
19
|
+
/** The compared names schemas with no union allow. Each settles a raw value under its names. */
|
|
20
|
+
readonly settled: ReadonlySet<string>;
|
|
21
|
+
}
|
|
22
|
+
/** Whether a shape allows a name, given in its compared form. */
|
|
23
|
+
export declare const allows: (shape: Shape, name: string) => boolean;
|
|
24
|
+
/** Declared names no bound schema allows. With no schema there is no shape to meet. */
|
|
25
|
+
export declare const outside: (names: ReadonlyArray<string>, shapes: ReadonlyArray<Shape>, fold: Fold) => ReadonlyArray<string>;
|
|
26
|
+
/** The edited names some bound schema always writes. */
|
|
27
|
+
export declare const required: (names: ReadonlyArray<string>, shapes: ReadonlyArray<Shape>, fold: Fold) => ReadonlyArray<string>;
|
|
28
|
+
/**
|
|
29
|
+
* The names a schema's output writes, in their compared form. A name with no value writes nothing,
|
|
30
|
+
* so a default stays, while an empty list is the caller saying there are no entries.
|
|
31
|
+
*/
|
|
32
|
+
export declare const written: (output: object, fold: Fold) => ReadonlySet<string>;
|
|
33
|
+
/**
|
|
34
|
+
* The names a raw value does not concern a union under, in their compared form: what another schema
|
|
35
|
+
* took from the caller, and what a schema with no union settles itself. A schema with no choice
|
|
36
|
+
* settles its own defaults, so nothing is left to it by this.
|
|
37
|
+
*/
|
|
38
|
+
export declare const others: (shape: Shape, taken: Taken | undefined, fold: Fold) => ReadonlySet<PropertyKey>;
|
|
39
|
+
/** The record once a schema has added what it took. */
|
|
40
|
+
export declare const taking: (taken: Taken | undefined, own: ReadonlySet<PropertyKey>) => Taken;
|
|
41
|
+
/**
|
|
42
|
+
* What went into `settle` and is gone from what came out, in the spelling it went in with. A schema
|
|
43
|
+
* can write less than it was given, and that must not pass as a group that was built.
|
|
44
|
+
*/
|
|
45
|
+
export declare const lost: (output: object, defaults: ReadonlyArray<readonly [string, unknown]>, settled: object, fold: Fold) => ReadonlyArray<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Read what a schema says about its group, and build what it sends.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* `settle` adds defaults to what the schema wrote and takes the whole group through the schema in
|
|
51
|
+
* both directions. A decoder may accept more spellings than its encoder writes, so a default that
|
|
52
|
+
* decodes is not yet what the schema sends.
|
|
53
|
+
*
|
|
54
|
+
* Effect strips what a union member does not state, so the first member that fits part of the group
|
|
55
|
+
* would win over a later one that holds all of it. `settle` therefore looks for such a member first.
|
|
56
|
+
* Without one it takes the looser match, and {@link lost} tells the caller what that left out.
|
|
57
|
+
*/
|
|
58
|
+
export declare const bind: <S extends Schema.Constraint>(contract: S, fold: Fold) => {
|
|
59
|
+
shape: Shape;
|
|
60
|
+
settle: <W extends object, A>(output: W, defaults: ReadonlyArray<readonly [string, A]>) => Effect.Effect<W, Schema.SchemaError, S["DecodingServices"] | S["EncodingServices"]>;
|
|
61
|
+
taken: (input: unknown, output: object, losing: ReadonlyArray<Excess.Path>) => ReadonlySet<PropertyKey>;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=shape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../../src/http/internal/shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAa,MAAM,QAAQ,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,gGAAgG;AAChG,MAAM,WAAW,KAAK;IACpB,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,sFAAsF;IACtF,QAAQ,CAAC,IAAI,EAAE,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