viell-effect-schema-http 0.1.0-rc.1 → 0.2.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 (62) hide show
  1. package/README.md +93 -48
  2. package/dist/concurrency/Interaction.d.ts +39 -6
  3. package/dist/concurrency/Interaction.d.ts.map +1 -1
  4. package/dist/concurrency/Interaction.js +25 -4
  5. package/dist/concurrency/Interaction.js.map +1 -1
  6. package/dist/http/Body.d.ts +142 -22
  7. package/dist/http/Body.d.ts.map +1 -1
  8. package/dist/http/Body.js +118 -14
  9. package/dist/http/Body.js.map +1 -1
  10. package/dist/http/Operation.d.ts +332 -12
  11. package/dist/http/Operation.d.ts.map +1 -1
  12. package/dist/http/Operation.js +255 -9
  13. package/dist/http/Operation.js.map +1 -1
  14. package/dist/http/Policy.d.ts +49 -13
  15. package/dist/http/Policy.d.ts.map +1 -1
  16. package/dist/http/Policy.js +32 -10
  17. package/dist/http/Policy.js.map +1 -1
  18. package/dist/http/Request.d.ts +661 -79
  19. package/dist/http/Request.d.ts.map +1 -1
  20. package/dist/http/Request.js +762 -120
  21. package/dist/http/Request.js.map +1 -1
  22. package/dist/http/Response.d.ts +200 -11
  23. package/dist/http/Response.d.ts.map +1 -1
  24. package/dist/http/Response.js +149 -10
  25. package/dist/http/Response.js.map +1 -1
  26. package/dist/http/Transport.d.ts +59 -11
  27. package/dist/http/Transport.d.ts.map +1 -1
  28. package/dist/http/Transport.js +46 -9
  29. package/dist/http/Transport.js.map +1 -1
  30. package/dist/http/UrlEncoding.d.ts +81 -9
  31. package/dist/http/UrlEncoding.d.ts.map +1 -1
  32. package/dist/http/UrlEncoding.js +41 -5
  33. package/dist/http/UrlEncoding.js.map +1 -1
  34. package/dist/http/internal/fields.d.ts +17 -4
  35. package/dist/http/internal/fields.d.ts.map +1 -1
  36. package/dist/http/internal/fields.js +11 -6
  37. package/dist/http/internal/fields.js.map +1 -1
  38. package/dist/http/internal/input.d.ts +39 -0
  39. package/dist/http/internal/input.d.ts.map +1 -0
  40. package/dist/http/internal/input.js +40 -0
  41. package/dist/http/internal/input.js.map +1 -0
  42. package/dist/http/internal/shape.d.ts +44 -0
  43. package/dist/http/internal/shape.d.ts.map +1 -0
  44. package/dist/http/internal/shape.js +179 -0
  45. package/dist/http/internal/shape.js.map +1 -0
  46. package/dist/main.d.ts +24 -0
  47. package/dist/main.d.ts.map +1 -1
  48. package/dist/main.js +24 -0
  49. package/dist/main.js.map +1 -1
  50. package/package.json +13 -13
  51. package/src/concurrency/Interaction.ts +39 -6
  52. package/src/http/Body.ts +158 -27
  53. package/src/http/Operation.ts +530 -32
  54. package/src/http/Policy.ts +49 -13
  55. package/src/http/Request.ts +1241 -227
  56. package/src/http/Response.ts +316 -28
  57. package/src/http/Transport.ts +59 -11
  58. package/src/http/UrlEncoding.ts +89 -10
  59. package/src/http/internal/fields.ts +37 -9
  60. package/src/http/internal/input.ts +123 -0
  61. package/src/http/internal/shape.ts +279 -0
  62. package/src/main.ts +24 -0
@@ -1,27 +1,75 @@
1
1
  import { Context, Effect, Option } from "effect";
2
2
  import { Headers, type HttpClientRequest, type HttpClientResponse } from "effect/http";
3
- /** Physical header lines in order, with their original spelling and repetition. */
3
+ /**
4
+ * Ordered header name/value pairs, preserving supplied spelling and repeated lines.
5
+ *
6
+ * @remarks
7
+ * These are declarations or provider observations. Sending separate lines requires provider
8
+ * support; normalized headers cannot reveal their original line boundaries.
9
+ */
4
10
  export type Lines = ReadonlyArray<readonly [string, string]>;
5
- /** The header collections accepted by `effect/http`, expanded here without combining repeated values. */
11
+ /**
12
+ * The header collection shapes accepted by Effect's `Headers.Input`.
13
+ *
14
+ * @remarks
15
+ * Use {@link entries} to expand them without combining repeated values.
16
+ */
6
17
  export type HeaderInput = Headers.Input;
7
- /** Expand a header collection into ordered lines. Array values become repeated lines. */
18
+ /**
19
+ * Expand a supported header collection into ordered name/value lines.
20
+ *
21
+ * @remarks
22
+ * Record array values become repeated lines; `undefined` fields are omitted.
23
+ */
8
24
  export declare const entries: (input: HeaderInput) => Lines;
9
- /** The normalized view used by native middleware: lowercase names, repeated values joined with `, `. */
25
+ /**
26
+ * Produce Effect's normalized header view from ordered lines.
27
+ *
28
+ * @remarks
29
+ * Names become lowercase and repeated values are joined with `, `. This loses line boundaries;
30
+ * keep the original lines when a provider can send them.
31
+ */
10
32
  export declare const toHeaders: (lines: Lines) => Headers.Headers;
11
33
  /**
12
- * Keep the original lines of every field whose normalized value is unchanged; changed or added native
13
- * fields replace them field by field.
34
+ * Preserve original header lines where native middleware left the normalized value unchanged.
35
+ *
36
+ * @remarks
37
+ * Changed or added native fields replace those fields' original lines. Removed fields disappear.
38
+ * For a provider handling an operation, prefer {@link headerLines} to obtain the original lines
39
+ * from the current Effect context.
14
40
  */
15
41
  export declare const reconcile: (lines: Lines, headers: Headers.Headers) => Lines;
16
- /** The request header lines of the current operation evaluation. Operations provide it to each attempt. */
42
+ /**
43
+ * The original request header lines available during an operation's attempt.
44
+ *
45
+ * @remarks
46
+ * Operations supply this context reference to the client. It defaults to an empty array outside
47
+ * that context. Providers should read it through {@link headerLines}.
48
+ */
17
49
  export declare const HeaderLines: Context.Reference<Lines>;
18
- /** For custom HttpClient providers: the lines to send, reconciled with the request after native middleware. */
50
+ /**
51
+ * Get the header lines a custom provider should send after native middleware edits.
52
+ *
53
+ * @remarks
54
+ * Reads {@link HeaderLines} and reconciles it with the native request. Fetch does not gain
55
+ * separate-line support from this helper.
56
+ */
19
57
  export declare const headerLines: (request: HttpClientRequest.HttpClientRequest) => Effect.Effect<Lines>;
20
58
  /**
21
- * For custom HttpClient providers: attach a snapshot of the observed response lines before returning the
22
- * response. Native headers are unchanged.
59
+ * Attach the header lines a custom provider observed to its native response.
60
+ *
61
+ * @remarks
62
+ * Copies the supplied lines, mutates the response with that snapshot, and returns the same
63
+ * response object. Normalized headers and received bytes are unchanged. Attach only information
64
+ * the provider actually observed; do not split normalized values to guess original lines.
23
65
  */
24
66
  export declare const withResponseHeaders: (response: HttpClientResponse.HttpClientResponse, lines: Lines) => HttpClientResponse.HttpClientResponse;
25
- /** The provider-attached response lines. `None` means none were supplied; normalized values are never split. */
67
+ /**
68
+ * Read the original response lines attached by a supporting provider.
69
+ *
70
+ * @remarks
71
+ * Returns `None` when none were supplied, not when the response necessarily has no headers.
72
+ * Normalized header values are never split to reconstruct lines.
73
+ */
26
74
  export declare const responseHeaderLines: (response: HttpClientResponse.HttpClientResponse) => Option.Option<Lines>;
27
75
  //# sourceMappingURL=Transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Transport.d.ts","sourceRoot":"","sources":["../../src/http/Transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,OAAO,EACP,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAErB,mFAAmF;AACnF,MAAM,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7D,yGAAyG;AACzG,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC;AAExC,yFAAyF;AACzF,eAAO,MAAM,OAAO,GAAI,OAAO,WAAW,KAAG,KAUtC,CAAC;AAER,wGAAwG;AACxG,eAAO,MAAM,SAAS,GAAI,OAAO,KAAK,KAAG,OAAO,CAAC,OAWhD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,KAAK,EAAE,SAAS,OAAO,CAAC,OAAO,KAAG,KASlE,CAAC;AAEF,2GAA2G;AAC3G,eAAO,MAAM,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,CAGhD,CAAC;AAEF,+GAA+G;AAC/G,eAAO,MAAM,WAAW,GACtB,SAAS,iBAAiB,CAAC,iBAAiB,KAC3C,MAAM,CAAC,MAAM,CAAC,KAAK,CACiD,CAAC;AAM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BAAkB,EAC/C,OAAO,KAAK,KACX,kBAAkB,CAAC,kBAMrB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,kBAAkB,CAAC,kBAAkB,KAC9C,MAAM,CAAC,MAAM,CAAC,KAAK,CAKnB,CAAC"}
@@ -1,6 +1,11 @@
1
1
  import { Context, Effect, Option } from "effect";
2
2
  import { Headers, } from "effect/http";
3
- /** Expand a header collection into ordered lines. Array values become repeated lines. */
3
+ /**
4
+ * Expand a supported header collection into ordered name/value lines.
5
+ *
6
+ * @remarks
7
+ * Record array values become repeated lines; `undefined` fields are omitted.
8
+ */
4
9
  export const entries = (input) => Symbol.iterator in input
5
10
  ? Array.from(input, ([name, value]) => [name, value])
6
11
  : Object.entries(input).flatMap(([name, value]) => value === undefined
@@ -8,7 +13,13 @@ export const entries = (input) => Symbol.iterator in input
8
13
  : typeof value === "string"
9
14
  ? [[name, value]]
10
15
  : value.map((line) => [name, line]));
11
- /** The normalized view used by native middleware: lowercase names, repeated values joined with `, `. */
16
+ /**
17
+ * Produce Effect's normalized header view from ordered lines.
18
+ *
19
+ * @remarks
20
+ * Names become lowercase and repeated values are joined with `, `. This loses line boundaries;
21
+ * keep the original lines when a provider can send them.
22
+ */
12
23
  export const toHeaders = (lines) => {
13
24
  const grouped = new Map();
14
25
  for (const [name, value] of lines) {
@@ -22,8 +33,12 @@ export const toHeaders = (lines) => {
22
33
  return Headers.fromInput(Array.from(grouped, ([key, values]) => [key, values.join(", ")]));
23
34
  };
24
35
  /**
25
- * Keep the original lines of every field whose normalized value is unchanged; changed or added native
26
- * fields replace them field by field.
36
+ * Preserve original header lines where native middleware left the normalized value unchanged.
37
+ *
38
+ * @remarks
39
+ * Changed or added native fields replace those fields' original lines. Removed fields disappear.
40
+ * For a provider handling an operation, prefer {@link headerLines} to obtain the original lines
41
+ * from the current Effect context.
27
42
  */
28
43
  export const reconcile = (lines, headers) => {
29
44
  const original = toHeaders(lines);
@@ -33,14 +48,30 @@ export const reconcile = (lines, headers) => {
33
48
  ...Object.entries(headers).filter(([name]) => !preserved.has(name)),
34
49
  ];
35
50
  };
36
- /** The request header lines of the current operation evaluation. Operations provide it to each attempt. */
51
+ /**
52
+ * The original request header lines available during an operation's attempt.
53
+ *
54
+ * @remarks
55
+ * Operations supply this context reference to the client. It defaults to an empty array outside
56
+ * that context. Providers should read it through {@link headerLines}.
57
+ */
37
58
  export const HeaderLines = Context.Reference("viell-effect-schema-http/Transport/HeaderLines", { defaultValue: () => [] });
38
- /** For custom HttpClient providers: the lines to send, reconciled with the request after native middleware. */
59
+ /**
60
+ * Get the header lines a custom provider should send after native middleware edits.
61
+ *
62
+ * @remarks
63
+ * Reads {@link HeaderLines} and reconciles it with the native request. Fetch does not gain
64
+ * separate-line support from this helper.
65
+ */
39
66
  export const headerLines = (request) => Effect.map(HeaderLines, (lines) => reconcile(lines, request.headers));
40
67
  const ResponseHeaderLines = Symbol.for("viell-effect-schema-http/Transport/ResponseHeaderLines");
41
68
  /**
42
- * For custom HttpClient providers: attach a snapshot of the observed response lines before returning the
43
- * response. Native headers are unchanged.
69
+ * Attach the header lines a custom provider observed to its native response.
70
+ *
71
+ * @remarks
72
+ * Copies the supplied lines, mutates the response with that snapshot, and returns the same
73
+ * response object. Normalized headers and received bytes are unchanged. Attach only information
74
+ * the provider actually observed; do not split normalized values to guess original lines.
44
75
  */
45
76
  export const withResponseHeaders = (response, lines) => {
46
77
  Object.defineProperty(response, ResponseHeaderLines, {
@@ -49,6 +80,12 @@ export const withResponseHeaders = (response, lines) => {
49
80
  });
50
81
  return response;
51
82
  };
52
- /** The provider-attached response lines. `None` means none were supplied; normalized values are never split. */
83
+ /**
84
+ * Read the original response lines attached by a supporting provider.
85
+ *
86
+ * @remarks
87
+ * Returns `None` when none were supplied, not when the response necessarily has no headers.
88
+ * Normalized header values are never split to reconstruct lines.
89
+ */
53
90
  export const responseHeaderLines = (response) => Option.fromUndefinedOr(response[ResponseHeaderLines]);
54
91
  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KAAK,CAAU,CAAC;QAC3D,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,QAA+C,EACzB,EAAE,CACxB,MAAM,CAAC,eAAe,CACnB,QAAuD,CACtD,mBAAmB,CACpB,CACF,CAAC"}
@@ -1,22 +1,94 @@
1
1
  import { Context, Layer } from "effect";
2
- /** Ordered query entries. `null` is a bare key (`?wsdl`); an empty string is an empty value (`?wsdl=`). */
2
+ /**
3
+ * Ordered decoded query entries, including repeated names.
4
+ *
5
+ * @remarks
6
+ * `null` is a bare key (`?preview`); `""` is an empty value (`?preview=`).
7
+ */
3
8
  export type Query = ReadonlyArray<readonly [string, string | null]>;
4
- /** A scalar query value. `null` is a bare key and `undefined` omits the entry. */
5
- export type QueryValue = string | number | bigint | boolean | null | undefined;
6
- /** The encoded shapes a query schema may produce: a record or ordered pairs, with scalar or array values. */
9
+ /**
10
+ * A scalar query value before conversion to URL text.
11
+ *
12
+ * @remarks
13
+ * `null` keeps a bare key and `undefined` omits an entry. A `Date` becomes its ISO text, and other
14
+ * values are converted to strings. An invalid `Date` has no ISO text, so it goes out as
15
+ * `String(value)`, and a schema such as `Schema.Date` refuses it before that.
16
+ */
17
+ export type QueryValue = string | number | bigint | boolean | Date | null | undefined;
18
+ /**
19
+ * A record or iterable of query pairs accepted as a schema's encoded output.
20
+ *
21
+ * @remarks
22
+ * Array values expand to repeated entries. Use ordered pairs to control order across names.
23
+ */
7
24
  export type QueryInput = Readonly<Record<string, QueryValue | ReadonlyArray<QueryValue>>> | Iterable<readonly [string, QueryValue | ReadonlyArray<QueryValue>]>;
8
- /** Expand a query collection into ordered entries, preserving repetition. */
25
+ /**
26
+ * Expand query input into ordered decoded entries, preserving repetitions.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { UrlEncoding } from "viell-effect-schema-http";
31
+ * const entries = UrlEncoding.queryEntries({ tag: ["one", "two"], preview: null });
32
+ * // [["tag", "one"], ["tag", "two"], ["preview", null]]
33
+ * ```
34
+ *
35
+ * @remarks
36
+ * Omits `undefined`, keeps `null`, writes a `Date` as ISO text, and converts other scalar values to
37
+ * strings. URL escaping happens later through the query renderer.
38
+ */
9
39
  export declare const queryEntries: (input: QueryInput) => Query;
10
- /** The policy that renders path values, query entries, and the final URL. */
40
+ /**
41
+ * Functions that render path values, query entries and the final request URL.
42
+ *
43
+ * @remarks
44
+ * The default policy is available without setup. Provide {@link layer} to replace it for a
45
+ * service that needs another URL representation.
46
+ */
11
47
  export interface Service {
48
+ /** Escape one dynamic path value; a template or renderer supplies the text between values. */
12
49
  readonly path: (value: string) => string;
50
+ /**
51
+ * Render ordered query entries without a leading `?`.
52
+ *
53
+ * @remarks
54
+ * Text written in a request's constructor stays as written and is not passed here. Where it
55
+ * stands between other entries, each run of them is rendered by a separate call, keeping the
56
+ * order of the query. A request with no entries gets one call with an empty array, and a query
57
+ * made only of written text gets no call, so add a fixed entry with `Request.setQuery` in a
58
+ * shared transform rather than here.
59
+ */
13
60
  readonly query: (entries: Query) => string;
61
+ /**
62
+ * Combine the base origin/prefix and the request's rendered path or absolute URL.
63
+ *
64
+ * @remarks
65
+ * Both arrive without a fragment. A fragment in the result is moved after the query.
66
+ */
14
67
  readonly join: (base: string, path: string) => string;
15
68
  }
16
- /** Percent-encode without canonicalizing: empty strings and dot segments survive this policy boundary. */
69
+ /**
70
+ * Percent-encode path values and query fields, and join a base URL with a request path.
71
+ *
72
+ * @remarks
73
+ * Uses `encodeURIComponent`, preserving bare keys, empty values, repetition and order.
74
+ * An absolute request URL bypasses the base. Otherwise joining removes one boundary slash from
75
+ * each side before inserting `/`. Dot segments and empty path values are not normalized here;
76
+ * the HTTP provider's later URL processing may normalize them.
77
+ */
17
78
  export declare const defaults: Service;
18
- /** The URL encoding used during request materialization. Defaults to {@link defaults}. */
79
+ /**
80
+ * The Effect context reference used to render request URLs.
81
+ *
82
+ * @remarks
83
+ * Uses {@link defaults} unless replaced. The value is read during request preparation.
84
+ */
19
85
  export declare const UrlEncoding: Context.Reference<Service>;
20
- /** Replace the URL encoding through ordinary Layer composition. */
86
+ /**
87
+ * Supply an alternative URL-rendering policy through an Effect layer.
88
+ *
89
+ * @remarks
90
+ * Provide it around request compilation or operation execution. Renderer exceptions become
91
+ * `Request.InvalidRequest`. Provider URL processing still applies after library rendering.
92
+ */
21
93
  export declare const layer: (service: Service) => Layer.Layer<never>;
22
94
  //# sourceMappingURL=UrlEncoding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UrlEncoding.d.ts","sourceRoot":"","sources":["../../src/http/UrlEncoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAExC,2GAA2G;AAC3G,MAAM,MAAM,KAAK,GAAG,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAEpE,kFAAkF;AAClF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAE/E,6GAA6G;AAC7G,MAAM,MAAM,UAAU,GAClB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,GAChE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAExE,6EAA6E;AAC7E,eAAO,MAAM,YAAY,GAAI,OAAO,UAAU,KAAG,KAWhD,CAAC;AAEF,6EAA6E;AAC7E,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,MAA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ACH,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,MAAM,CAAC;IAC3C;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACvD;AAID;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,EAAE,OAetB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC,OAAO,CAG/C,CAAC;AAEL;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAAI,SAAS,OAAO,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CACrB,CAAC"}
@@ -1,13 +1,38 @@
1
1
  import { Context, Layer } from "effect";
2
- /** Expand a query collection into ordered entries, preserving repetition. */
2
+ /** The URL text of a value that has one. */
3
+ const queryText = (value) => value instanceof Date && !Number.isNaN(value.getTime())
4
+ ? value.toISOString()
5
+ : String(value);
6
+ /**
7
+ * Expand query input into ordered decoded entries, preserving repetitions.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { UrlEncoding } from "viell-effect-schema-http";
12
+ * const entries = UrlEncoding.queryEntries({ tag: ["one", "two"], preview: null });
13
+ * // [["tag", "one"], ["tag", "two"], ["preview", null]]
14
+ * ```
15
+ *
16
+ * @remarks
17
+ * Omits `undefined`, keeps `null`, writes a `Date` as ISO text, and converts other scalar values to
18
+ * strings. URL escaping happens later through the query renderer.
19
+ */
3
20
  export const queryEntries = (input) => {
4
21
  const entries = Symbol.iterator in input ? Array.from(input) : Object.entries(input);
5
22
  return entries.flatMap(([key, value]) => (Array.isArray(value) ? value : [value]).flatMap((entry) => entry === undefined
6
23
  ? []
7
- : [[key, entry === null ? null : String(entry)]]));
24
+ : [[key, entry === null ? null : queryText(entry)]]));
8
25
  };
9
26
  const absolute = /^[a-z][a-z\d+.-]*:\/\//i;
10
- /** Percent-encode without canonicalizing: empty strings and dot segments survive this policy boundary. */
27
+ /**
28
+ * Percent-encode path values and query fields, and join a base URL with a request path.
29
+ *
30
+ * @remarks
31
+ * Uses `encodeURIComponent`, preserving bare keys, empty values, repetition and order.
32
+ * An absolute request URL bypasses the base. Otherwise joining removes one boundary slash from
33
+ * each side before inserting `/`. Dot segments and empty path values are not normalized here;
34
+ * the HTTP provider's later URL processing may normalize them.
35
+ */
11
36
  export const defaults = {
12
37
  path: encodeURIComponent,
13
38
  query: (entries) => entries
@@ -23,10 +48,21 @@ export const defaults = {
23
48
  return `${base.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
24
49
  },
25
50
  };
26
- /** The URL encoding used during request materialization. Defaults to {@link defaults}. */
51
+ /**
52
+ * The Effect context reference used to render request URLs.
53
+ *
54
+ * @remarks
55
+ * Uses {@link defaults} unless replaced. The value is read during request preparation.
56
+ */
27
57
  export const UrlEncoding = Context.Reference("viell-effect-schema-http/UrlEncoding", {
28
58
  defaultValue: () => defaults,
29
59
  });
30
- /** Replace the URL encoding through ordinary Layer composition. */
60
+ /**
61
+ * Supply an alternative URL-rendering policy through an Effect layer.
62
+ *
63
+ * @remarks
64
+ * Provide it around request compilation or operation execution. Renderer exceptions become
65
+ * `Request.InvalidRequest`. Provider URL processing still applies after library rendering.
66
+ */
31
67
  export const layer = (service) => Layer.succeed(UrlEncoding, service);
32
68
  //# sourceMappingURL=UrlEncoding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UrlEncoding.js","sourceRoot":"","sources":["../../src/http/UrlEncoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAaxC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAiB,EAAS,EAAE;IACvD,MAAM,OAAO,GACX,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CA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KAAK,GAAG,CAAC,OAAgB,EAAsB,EAAE,CAC5D,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,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<readonly [string, Value<A>]>;
5
- /** Replace a name at its first position and drop its later entries, or append a new entry. */
6
- export declare const set: <A>(fields: Fields<A>, name: string, value: Value<A>) => Fields<A>;
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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AC,MAAM,EAAE,CAAC,CAAC,CAO5B,CAAC"}
@@ -1,13 +1,18 @@
1
- /** Replace a name at its first position and drop its later entries, or append a new entry. */
2
- export const set = (fields, name, value) => {
3
- const position = fields.findIndex(([key]) => key === name);
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, [name, value]];
6
- return fields.flatMap((entry, index) => index === position ? [[name, value]] : entry[0] === name ? [] : [entry]);
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":"AAMA,8FAA8F;AAC9F,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,MAAiB,EACjB,IAAY,EACZ,KAAe,EACJ,EAAE;IACb,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC;IAC3D,IAAI,QAAQ,GAAG,CAAC;QAAE,OAAO,CAAC,GAAG,MAAM,E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AAe,EACJ,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3C,wHAAwH;AACxH,MAAM,CAAC,MAAM,MAAM,GAAG,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,39 @@
1
+ import { Effect, Schema } from "effect";
2
+ /** What a schema's constructor takes. This is the one place that names the `~`-prefixed key. */
3
+ type ConstructorInput<S extends Schema.Top> = S["~type.make.in"];
4
+ /** A field's type on the encoded side, in whichever union members have it. */
5
+ type EncodedField<B, K> = B extends unknown ? K extends keyof B ? B[K] : never : never;
6
+ /**
7
+ * Either side of a schema, chosen field by field. A list is a value, so it has no fields, and an
8
+ * object whose encoded side is not one, such as a `Date` from text, has none to choose from.
9
+ */
10
+ type Fieldwise<A, B> = A extends ReadonlyArray<unknown> ? never : A extends object ? B extends object ? {
11
+ readonly [K in keyof A]: A[K] | EncodedField<B, K>;
12
+ } : never : never;
13
+ /** Every key of every member. `keyof` on a union keeps only the keys all its members share. */
14
+ type KeysOf<T> = T extends unknown ? keyof T : never;
15
+ /**
16
+ * Leave out the sides when the mix takes everything they do, which an editor would show three times.
17
+ *
18
+ * @remarks
19
+ * Assignability is not enough on its own, because a stray key in a literal is an error against the
20
+ * mix even when the value is assignable to it. A renamed field needs its side for that reason, and
21
+ * a field the mix requires and one side leaves out needs its side too.
22
+ */
23
+ type Merged<Sides, Mix> = [Sides] extends [Mix] ? [KeysOf<Sides>] extends [KeysOf<Mix>] ? Mix : Sides | Mix : Sides | Mix;
24
+ type EitherSide<A, B> = [A, B] extends [B, A] ? A : Merged<A | B, Fieldwise<A, B>>;
25
+ /** What a schema-backed input takes: its decoded side, its encoded side, or a mix by field. */
26
+ export type Input<S extends Schema.Top> = EitherSide<ConstructorInput<S>, S["Encoded"]>;
27
+ /**
28
+ * Bring a value on either side of a schema to its decoded side.
29
+ *
30
+ * @remarks
31
+ * A value that fits the decoded side is read as decoded, so it is encoded once. Anything else goes
32
+ * through the decoder as a whole, then field by field. Both routes validate, and a value that fits
33
+ * neither fails with the decoded side's error, so existing failures read the same.
34
+ */
35
+ export declare const toDecoded: <S extends Schema.Top>(contract: S) => (input: Input<S>) => Effect.Effect<S["Type"], Schema.SchemaError, S["DecodingServices"]>;
36
+ /** Bring a value to the schema's decoded side, then write it. */
37
+ export declare const encoder: <S extends Schema.Top, A, R>(contract: S, write: (value: S["Type"]) => Effect.Effect<A, Schema.SchemaError, R>) => (input: Input<S>) => Effect.Effect<A, Schema.SchemaError, R | S["DecodingServices"]>;
38
+ export {};
39
+ //# 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,EAAa,MAAM,QAAQ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SAAS,MAAM,CAAC,GAAG,IAAI,UAAU,CAClD,gBAAgB,CAAC,CAAC,CAAC,EACnB,CAAC,CAAC,SAAS,CAAC,CACb,CAAC;AAeF;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,MAqBvD,OAAO,KAAK,CAAC,CAAC,CAAC,KACd,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,kBAAkB,CAAC,CAWtE,CAAC;AAMF,iEAAiE;AACjE,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAChD,UAAU,CAAC,EACX,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,MAIlE,OAAO,KAAK,CAAC,CAAC,CAAC,KACd,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,kBAAkB,CAAC,CAElE,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Effect, Schema, SchemaAST } from "effect";
2
+ /** The fields of a struct or class, as they are declared, with each field's own encoding. */
3
+ const fieldsOf = (ast) => ast._tag === "Objects"
4
+ ? ast.propertySignatures
5
+ : ast._tag === "Declaration" && ast.encoding !== undefined
6
+ ? fieldsOf(ast.encoding[0].to)
7
+ : [];
8
+ /**
9
+ * Bring a value on either side of a schema to its decoded side.
10
+ *
11
+ * @remarks
12
+ * A value that fits the decoded side is read as decoded, so it is encoded once. Anything else goes
13
+ * through the decoder as a whole, then field by field. Both routes validate, and a value that fits
14
+ * neither fails with the decoded side's error, so existing failures read the same.
15
+ */
16
+ export const toDecoded = (contract) => {
17
+ const make = (input) => Effect.mapError(contract.makeEffect(input), (issue) => new Schema.SchemaError(issue));
18
+ const decode = Schema.decodeUnknownEffect(contract);
19
+ const byField = Effect.fnUntraced(function* (input) {
20
+ const output = { ...input };
21
+ for (const { name, type } of fieldsOf(contract.ast))
22
+ if (output[name] !== undefined)
23
+ output[name] = yield* fromPart(type, output[name]);
24
+ return yield* make(output);
25
+ });
26
+ const byMember = (input) => contract.ast._tag === "Union"
27
+ ? Effect.firstSuccessOf(contract.ast.types.map((member) => fromPart(member, input)))
28
+ : byField(input);
29
+ return (input) => Effect.catch(make(input), (failure) => Effect.mapError(Effect.catch(decode(input), (encodedFailure) => typeof input === "object" && input !== null
30
+ ? byMember(input)
31
+ : Effect.fail(encodedFailure)), () => failure));
32
+ };
33
+ /** Read a field or union member, which may be on either side of its own schema. */
34
+ const fromPart = (ast, value) => toDecoded(Schema.make(ast))(value);
35
+ /** Bring a value to the schema's decoded side, then write it. */
36
+ export const encoder = (contract, write) => {
37
+ const decoded = toDecoded(contract);
38
+ return (input) => Effect.flatMap(decoded(input), write);
39
+ };
40
+ //# 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,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAoDnD,6FAA6F;AAC7F,MAAM,QAAQ,GAAG,CACf,GAAkB,EAIjB,EAAE,CACH,GAAG,CAAC,IAAI,KAAK,SAAS;IACpB,CAAC,CAAC,GAAG,CAAC,kBAAkB;IACxB,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,aAAa,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS;QACxD,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9B,CAAC,CAAC,EAAE,CAAC;AAEX;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAuB,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,CACb,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,CAC7C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QACzC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;QACjB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAChC,EACD,GAAG,EAAE,CAAC,OAAO,CACd,CACqE,CAAC;AAC7E,CAAC,CAAC;AAEF,mFAAmF;AACnF,MAAM,QAAQ,GAAG,CAAC,GAAkB,EAAE,KAAc,EAAE,EAAE,CACtD,SAAS,CAAC,MAAM,CAAC,IAAI,CAAa,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAEjD,iEAAiE;AACjE,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,QAAW,EACX,KAAoE,EACpE,EAAE;IACF,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IACpC,OAAO,CACL,KAAe,EACkD,EAAE,CACnE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { Effect, Schema } from "effect";
2
+ import type { Fold } from "./fields.js";
3
+ /** What one schema says about its field group. Names are wire names, in their compared form. */
4
+ export interface Shape {
5
+ /** The names the schema states. */
6
+ readonly names: ReadonlySet<string>;
7
+ /** Whether it allows names it does not state, as a record or a list of pairs does. */
8
+ readonly open: boolean;
9
+ /** The names it always writes, so a raw edit of one could never reach the client. */
10
+ readonly required: ReadonlySet<string>;
11
+ }
12
+ /** Whether a shape allows a name, given in its compared form. */
13
+ export declare const allows: (shape: Shape, name: string) => boolean;
14
+ /** Declared names no bound schema allows. With no schema there is no shape to meet. */
15
+ export declare const outside: (names: ReadonlyArray<string>, shapes: ReadonlyArray<Shape>, fold: Fold) => ReadonlyArray<string>;
16
+ /** The edited names some bound schema always writes. */
17
+ export declare const required: (names: ReadonlyArray<string>, shapes: ReadonlyArray<Shape>, fold: Fold) => ReadonlyArray<string>;
18
+ /**
19
+ * The names a schema's output writes, in their compared form. A name with no value writes nothing,
20
+ * so a default stays, while an empty list is the caller saying there are no entries.
21
+ */
22
+ export declare const written: (output: object, fold: Fold) => ReadonlySet<string>;
23
+ /**
24
+ * What went into `settle` and is gone from what came out, in the spelling it went in with. A schema
25
+ * can write less than it was given, and that must not pass as a group that was built.
26
+ */
27
+ export declare const lost: (output: object, defaults: ReadonlyArray<readonly [string, unknown]>, settled: object, fold: Fold) => ReadonlyArray<string>;
28
+ /**
29
+ * Read what a schema says about its group, and build what it sends.
30
+ *
31
+ * @remarks
32
+ * `settle` adds defaults to what the schema wrote and takes the whole group through the schema in
33
+ * both directions. A decoder may accept more spellings than its encoder writes, so a default that
34
+ * decodes is not yet what the schema sends.
35
+ *
36
+ * Effect strips what a union member does not state, so the first member that fits part of the group
37
+ * would win over a later one that holds all of it. `settle` therefore looks for such a member first.
38
+ * Without one it takes the looser match, and {@link lost} tells the caller what that left out.
39
+ */
40
+ export declare const bind: <S extends Schema.Constraint>(contract: S, fold: Fold) => {
41
+ shape: Shape;
42
+ settle: <W extends object, A>(output: W, defaults: ReadonlyArray<readonly [string, A]>) => Effect.Effect<W, Schema.SchemaError, S["DecodingServices"] | S["EncodingServices"]>;
43
+ };
44
+ //# 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,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;IACt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