@ozanarslan/corpus 0.0.1

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 (87) hide show
  1. package/LICENSE.txt +20 -0
  2. package/README.md +337 -0
  3. package/dist/App/index.d.ts +377 -0
  4. package/dist/App/index.d.ts.map +1 -0
  5. package/dist/C.namespace.d.ts +27 -0
  6. package/dist/C.namespace.d.ts.map +1 -0
  7. package/dist/Config/index.d.ts +163 -0
  8. package/dist/Config/index.d.ts.map +1 -0
  9. package/dist/Context/ContextAccess/index.d.ts +50 -0
  10. package/dist/Context/ContextAccess/index.d.ts.map +1 -0
  11. package/dist/Context/index.d.ts +162 -0
  12. package/dist/Context/index.d.ts.map +1 -0
  13. package/dist/Controller/index.d.ts +164 -0
  14. package/dist/Controller/index.d.ts.map +1 -0
  15. package/dist/Cookies/index.d.ts +81 -0
  16. package/dist/Cookies/index.d.ts.map +1 -0
  17. package/dist/Cors/index.d.ts +135 -0
  18. package/dist/Cors/index.d.ts.map +1 -0
  19. package/dist/Exception/index.d.ts +85 -0
  20. package/dist/Exception/index.d.ts.map +1 -0
  21. package/dist/Globals/AppsRegistry/index.d.ts +48 -0
  22. package/dist/Globals/AppsRegistry/index.d.ts.map +1 -0
  23. package/dist/Globals/ParsersRegistry/index.d.ts +93 -0
  24. package/dist/Globals/ParsersRegistry/index.d.ts.map +1 -0
  25. package/dist/Globals/index.d.ts +109 -0
  26. package/dist/Globals/index.d.ts.map +1 -0
  27. package/dist/Headers/index.d.ts +208 -0
  28. package/dist/Headers/index.d.ts.map +1 -0
  29. package/dist/Middleware/index.d.ts +125 -0
  30. package/dist/Middleware/index.d.ts.map +1 -0
  31. package/dist/ParserBase/BodyParser/index.d.ts +138 -0
  32. package/dist/ParserBase/BodyParser/index.d.ts.map +1 -0
  33. package/dist/ParserBase/FormDataParser/index.d.ts +57 -0
  34. package/dist/ParserBase/FormDataParser/index.d.ts.map +1 -0
  35. package/dist/ParserBase/SchemaParser/index.d.ts +143 -0
  36. package/dist/ParserBase/SchemaParser/index.d.ts.map +1 -0
  37. package/dist/ParserBase/SearchParamsParser/index.d.ts +61 -0
  38. package/dist/ParserBase/SearchParamsParser/index.d.ts.map +1 -0
  39. package/dist/ParserBase/URLParamsParser/index.d.ts +32 -0
  40. package/dist/ParserBase/URLParamsParser/index.d.ts.map +1 -0
  41. package/dist/ParserBase/index.d.ts +92 -0
  42. package/dist/ParserBase/index.d.ts.map +1 -0
  43. package/dist/RateLimiter/index.d.ts +321 -0
  44. package/dist/RateLimiter/index.d.ts.map +1 -0
  45. package/dist/Request/index.d.ts +81 -0
  46. package/dist/Request/index.d.ts.map +1 -0
  47. package/dist/Res/index.d.ts +353 -0
  48. package/dist/Res/index.d.ts.map +1 -0
  49. package/dist/RouteBase/BundleRoute/index.d.ts +268 -0
  50. package/dist/RouteBase/BundleRoute/index.d.ts.map +1 -0
  51. package/dist/RouteBase/FileRoute/index.d.ts +121 -0
  52. package/dist/RouteBase/FileRoute/index.d.ts.map +1 -0
  53. package/dist/RouteBase/Route/index.d.ts +83 -0
  54. package/dist/RouteBase/Route/index.d.ts.map +1 -0
  55. package/dist/RouteBase/StaticRoute/index.d.ts +149 -0
  56. package/dist/RouteBase/StaticRoute/index.d.ts.map +1 -0
  57. package/dist/RouteBase/WebSocketRoute/index.d.ts +117 -0
  58. package/dist/RouteBase/WebSocketRoute/index.d.ts.map +1 -0
  59. package/dist/RouteBase/index.d.ts +206 -0
  60. package/dist/RouteBase/index.d.ts.map +1 -0
  61. package/dist/Server/index.d.ts +44 -0
  62. package/dist/Server/index.d.ts.map +1 -0
  63. package/dist/XFile/index.d.ts +202 -0
  64. package/dist/XFile/index.d.ts.map +1 -0
  65. package/dist/exports.d.ts +11 -0
  66. package/dist/exports.d.ts.map +1 -0
  67. package/dist/index.d.ts +5 -0
  68. package/dist/index.d.ts.map +1 -0
  69. package/dist/index.js +12 -0
  70. package/dist/index.js.map +47 -0
  71. package/dist/initialize.d.ts +22 -0
  72. package/dist/initialize.d.ts.map +1 -0
  73. package/dist/utils/assert.d.ts +7 -0
  74. package/dist/utils/assert.d.ts.map +1 -0
  75. package/dist/utils/is.d.ts +17 -0
  76. package/dist/utils/is.d.ts.map +1 -0
  77. package/dist/utils/lazy.d.ts +27 -0
  78. package/dist/utils/lazy.d.ts.map +1 -0
  79. package/dist/utils/logger.d.ts +31 -0
  80. package/dist/utils/logger.d.ts.map +1 -0
  81. package/dist/utils/object.d.ts +20 -0
  82. package/dist/utils/object.d.ts.map +1 -0
  83. package/dist/utils/path.d.ts +6 -0
  84. package/dist/utils/path.d.ts.map +1 -0
  85. package/dist/utils/tuple.d.ts +3 -0
  86. package/dist/utils/tuple.d.ts.map +1 -0
  87. package/package.json +57 -0
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Content-type-driven body reading for requests and responses alike.
3
+ *
4
+ * {@link BodyParser} is the implementation behind
5
+ * {@link ParsersRegistry.bodyParser}, which {@link App} uses to fill
6
+ * {@link Context.body}. It classifies the `Content-Type` header, then delegates
7
+ * structured payloads to {@link SearchParamsParser} and {@link FormDataParser}
8
+ * through the registry, so nesting and coercion rules stay identical across
9
+ * query strings, form posts and JSON.
10
+ *
11
+ * @module BodyParser
12
+ */
13
+ import { Res } from "../../Res";
14
+ /**
15
+ * What {@link BodyParser.parse} can produce.
16
+ *
17
+ * Structured types yield an object or an array, textual types a string, binary
18
+ * types the undrained stream so it can be piped rather than buffered, and a
19
+ * binary body that turned out to be absent yields `null`.
20
+ */
21
+ type ParsedBody = Record<string, unknown> | Array<unknown> | string | ReadableStream<Uint8Array> | null;
22
+ /**
23
+ * The public shape of a body parser, implemented by {@link BodyParser}.
24
+ *
25
+ * Assign an alternative implementation to
26
+ * {@link ParsersRegistry.bodyParser} through {@link setParsersRegistry} to
27
+ * replace body handling framework-wide.
28
+ */
29
+ interface BodyParserInterface {
30
+ /**
31
+ * Reads and decodes a body according to its `Content-Type`.
32
+ *
33
+ * @param received - The request, response or {@link Res} to read from.
34
+ * @returns The decoded body.
35
+ */
36
+ parse(received: Request | Response | Res): Promise<ParsedBody>;
37
+ }
38
+ /**
39
+ * Default {@link BodyParserInterface} implementation.
40
+ *
41
+ * Reads are non-destructive for caller-supplied inputs: the body is cloned
42
+ * before being drained, so a {@link Middleware} can inspect a body and still
43
+ * leave it readable downstream. Empty bodies resolve to a null-prototype object
44
+ * from {@link createSafeObject} rather than a plain `{}`, which is what keeps a
45
+ * `__proto__` key in a payload from reaching `Object.prototype`.
46
+ */
47
+ declare class BodyParser implements BodyParserInterface {
48
+ /**
49
+ * Reads a body and decodes it according to its `Content-Type`. This can be
50
+ * used for both request and response bodies.
51
+ *
52
+ * A {@link Res} is converted with {@link Res.toNativeResponse} first. The
53
+ * content type is read from that source rather than from the clone, because
54
+ * Bun derives it lazily for `FormData`-backed requests and a clone taken
55
+ * before the derivation does not carry it. The clone itself is skipped for a
56
+ * {@link Res}-derived response, which is freshly constructed and unshared.
57
+ *
58
+ * @param received - The request, response or {@link Res} whose body to read.
59
+ * @returns The decoded {@link ParsedBody}. A body-less input yields an empty
60
+ * safe object.
61
+ * @throws {@link Exception} with {@link Status.BAD_REQUEST} when the payload is
62
+ * malformed for its declared type — a `SyntaxError` from decoding is
63
+ * attributed to the client, and the offending content type is attached to the
64
+ * exception. Any other error propagates unchanged.
65
+ */
66
+ parse(received: Request | Response | Res): Promise<ParsedBody>;
67
+ /**
68
+ * Decodes an `application/json` body.
69
+ *
70
+ * @param input - The cloned request or response to drain.
71
+ * @returns The parsed value, or an empty safe object when the body is blank —
72
+ * an empty payload is treated as "nothing sent" rather than as a syntax error.
73
+ * @throws `SyntaxError` on malformed JSON, which {@link BodyParser.parse}
74
+ * converts into a {@link Status.BAD_REQUEST} {@link Exception}.
75
+ */
76
+ private getJsonBody;
77
+ /**
78
+ * Decodes an `application/x-www-form-urlencoded` body.
79
+ *
80
+ * The pairs are handed to {@link ParsersRegistry.searchParamsParser}, so a
81
+ * form post and a query string with the same shape produce the same object,
82
+ * including bracket nesting and repeated keys.
83
+ *
84
+ * @param input - The cloned request or response to drain.
85
+ * @returns The parsed object, or an empty safe object when the body is blank.
86
+ * Falls back to flat `URLSearchParams` entries if no search params parser is
87
+ * registered.
88
+ */
89
+ private getFormUrlEncodedBody;
90
+ /**
91
+ * Decodes a `multipart/form-data` body, delegating to
92
+ * {@link ParsersRegistry.formDataParser} so uploaded files and nested field
93
+ * names are handled consistently.
94
+ *
95
+ * @param input - The cloned request or response to drain.
96
+ * @returns The parsed object, or flat `FormData` entries if no form data
97
+ * parser is registered.
98
+ */
99
+ private getFormDataBody;
100
+ /**
101
+ * Decodes a textual body, honouring the `charset` parameter of the content
102
+ * type.
103
+ *
104
+ * `Body.text()` always decodes as UTF-8 per the fetch spec, ignoring the
105
+ * declared charset, so anything other than UTF-8 is decoded from the raw bytes
106
+ * with a matching `TextDecoder`. An unrecognised charset label falls back to
107
+ * UTF-8 rather than failing the request.
108
+ *
109
+ * @param input - The cloned request or response to drain.
110
+ * @param contentType - The full header value, used to extract `charset`.
111
+ * @returns The decoded text.
112
+ */
113
+ private getTextBody;
114
+ /**
115
+ * Passes a binary body through undrained, so large uploads can be streamed
116
+ * instead of buffered into memory.
117
+ *
118
+ * @param input - The cloned request or response.
119
+ * @returns The body stream, or `null` if there is none.
120
+ */
121
+ private getBinaryBody;
122
+ /**
123
+ * Handles a body whose content type matched nothing in
124
+ * {@link CONTENT_TYPE_MAP}, including requests that declared no type at all.
125
+ *
126
+ * The body is decoded as text and JSON is attempted opportunistically, so a
127
+ * client that omits its `Content-Type` still gets structured data. A failed
128
+ * parse is not an error here — the raw text is returned instead.
129
+ *
130
+ * @param input - The cloned request or response to drain.
131
+ * @param contentType - The full header value, forwarded for charset handling.
132
+ * @returns The parsed JSON value, the raw text, or an empty safe object when
133
+ * the body is blank.
134
+ */
135
+ private getUnknownBody;
136
+ }
137
+ export { type BodyParserInterface, BodyParser };
138
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ParserBase/BodyParser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,EAAE,GAAG,EAAU,MAAM,OAAO,CAAC;AAWpC;;;;;;GAMG;AACH,KAAK,UAAU,GACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,KAAK,CAAC,OAAO,CAAC,GACd,MAAM,GACN,cAAc,CAAC,UAAU,CAAC,GAC1B,IAAI,CAAC;AAER;;;;;;GAMG;AACH,UAAU,mBAAmB;IAC5B;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,GAAG,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC/D;AAiCD;;;;;;;;GAQG;AACH,cAAM,UAAW,YAAW,mBAAmB;IAC9C;;;;;;;;;;;;;;;;;OAiBG;IACG,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,GAAG,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC;IAwCpE;;;;;;;;OAQG;YACW,WAAW;IAQzB;;;;;;;;;;;OAWG;YACW,qBAAqB;IASnC;;;;;;;;OAQG;YACW,eAAe;IAO7B;;;;;;;;;;;;OAYG;YACW,WAAW;IAuBzB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;;;;;;;;;OAYG;YACW,cAAc;CAY5B;AAED,OAAO,EAAE,KAAK,mBAAmB,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Parsing `multipart/form-data` into a nested object.
3
+ *
4
+ * {@link FormDataParser} is the default {@link ParsersRegistry.formDataParser},
5
+ * reached through {@link BodyParser} rather than called directly. It applies the
6
+ * same bracket-notation nesting as {@link SearchParamsParser}, so a form post
7
+ * and a query string with matching field names produce the same shape — the
8
+ * difference is that a form can also carry files, which are kept as `File`
9
+ * objects instead of being coerced.
10
+ *
11
+ * @module FormDataParser
12
+ */
13
+ import { ParserBase } from "..";
14
+ /**
15
+ * Turns a `FormData` into a nested object.
16
+ *
17
+ * Field names are read as paths through {@link ParserBase.parseKey}, so
18
+ * `user[address][city]` and `tags[0]` build the objects and arrays they
19
+ * describe. Repeated names collect into an array, which is how a multi-select or
20
+ * a multi-file input arrives without any bracket notation at all.
21
+ *
22
+ * Values are coerced through {@link ParserBase.tryParseJSON}, so `"true"` and
23
+ * `"42"` arrive as a boolean and a number rather than as strings. Files are
24
+ * exempt — a `File` is passed through untouched.
25
+ */
26
+ declare class FormDataParser extends ParserBase<FormData> {
27
+ /**
28
+ * Parses form data into a nested object.
29
+ *
30
+ * @param formData - The form data to parse, typically from
31
+ * `Request.formData()`.
32
+ * @returns The nested object, built on a null prototype by
33
+ * {@link createSafeObject} so a `__proto__` field name cannot reach
34
+ * `Object.prototype`.
35
+ */
36
+ parse(formData: FormData): Record<string, unknown>;
37
+ /**
38
+ * Writes a value at a path, creating the containers it passes through.
39
+ *
40
+ * Each missing level is created as an array when the next path part is a
41
+ * number and as an object otherwise, so the shape follows the field name
42
+ * rather than being guessed after the fact.
43
+ *
44
+ * The final slot collects rather than overwrites: an empty slot takes the
45
+ * value, a slot already holding an array appends, and a slot holding a single
46
+ * value is promoted to an array. That is what makes repeated field names
47
+ * accumulate — order of arrival is preserved.
48
+ *
49
+ * @param result - The object being built up.
50
+ * @param parts - The path from {@link ParserBase.parseKey}; numbers mean array
51
+ * indices, strings mean object keys.
52
+ * @param value - The value to write, already coerced or left as a `File`.
53
+ */
54
+ private setDeep;
55
+ }
56
+ export { FormDataParser };
57
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ParserBase/FormDataParser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;;;;;;;;;;GAWG;AACH,cAAM,cAAe,SAAQ,UAAU,CAAC,QAAQ,CAAC;IAChD;;;;;;;;OAQG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAYlD;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,OAAO;CAoCf;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Request validation against the schemas declared in a {@link RouteConfig}.
3
+ *
4
+ * Schemas are taken as [Standard Schema](https://standardschema.dev), so any
5
+ * library implementing that spec works — Zod, Valibot, ArkType and others —
6
+ * without corpus depending on any of them. The same interface also supplies the
7
+ * inferred types that flow into {@link Context}, so declaring a schema both
8
+ * validates the request and types the handler.
9
+ *
10
+ * {@link App} calls this after each surface is parsed, so what a handler sees on
11
+ * {@link Context.body}, {@link Context.search} and {@link Context.params} is
12
+ * already validated. A failure raises {@link Status.UNPROCESSABLE_ENTITY} with a
13
+ * message naming the offending fields, so the client is told what was wrong
14
+ * rather than just that something was.
15
+ *
16
+ * @module SchemaParser
17
+ */
18
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
19
+ import type { RouteConfig } from "../../RouteBase";
20
+ import type { Prettify } from "../../utils/object";
21
+ /**
22
+ * Any Standard Schema validator producing `T`. This is the type
23
+ * {@link RouteConfig} fields accept.
24
+ *
25
+ * @typeParam T - What the schema validates to.
26
+ */
27
+ type Schema<T = unknown> = StandardSchemaV1<unknown, T>;
28
+ /**
29
+ * The type a schema accepts as input, before transformation.
30
+ *
31
+ * @typeParam T - The schema.
32
+ */
33
+ type InferSchemaIn<T extends Schema> = StandardSchemaV1.InferInput<T>;
34
+ /**
35
+ * The type a schema produces after validation. This is what a route's
36
+ * {@link Context} fields are typed as.
37
+ *
38
+ * @typeParam T - The schema.
39
+ */
40
+ type InferSchemaOut<T extends Schema> = StandardSchemaV1.InferOutput<T>;
41
+ /** The validation failures a schema reports. */
42
+ type ValidationIssues = readonly StandardSchemaV1.Issue[];
43
+ /** If you prefer to put all schemas into a single object, this will be helpful */
44
+ type InferModel<T extends Record<string, any>> = {
45
+ [K in keyof T as K extends "prototype" ? never : K]: T[K] extends RouteConfig<any, any, any, any> ? Prettify<(T[K]["body"] extends Schema ? {
46
+ body: InferSchemaOut<T[K]["body"]>;
47
+ } : {}) & (T[K]["search"] extends Schema ? {
48
+ search: InferSchemaOut<T[K]["search"]>;
49
+ } : {}) & (T[K]["params"] extends Schema ? {
50
+ params: InferSchemaOut<T[K]["params"]>;
51
+ } : {}) & (T[K]["response"] extends Schema ? {
52
+ response: InferSchemaOut<T[K]["response"]>;
53
+ } : {})> : T[K] extends Schema ? InferSchemaOut<T[K]> : never;
54
+ };
55
+ /**
56
+ * The public shape of a schema parser, implemented by {@link SchemaParser}.
57
+ * Assign an alternative to {@link ParsersRegistry.schemaParser} to change how
58
+ * validation failures are reported.
59
+ */
60
+ interface SchemaParserInterface {
61
+ /**
62
+ * Validates a value against a schema.
63
+ *
64
+ * @param label - Names the surface being validated, for the error message.
65
+ * @param input - The value to validate.
66
+ * @param schema - The schema. Omitting it passes the value through unchanged.
67
+ * @returns The validated value.
68
+ */
69
+ parse<T = Record<string, unknown>>(label: string, input: unknown, schema?: Schema<T>): Promise<T>;
70
+ /**
71
+ * Validates a value against a synchronous schema.
72
+ *
73
+ * @param label - Names the surface being validated, for the error message.
74
+ * @param input - The value to validate.
75
+ * @param schema - The schema. Omitting it passes the value through unchanged.
76
+ * @returns The validated value.
77
+ */
78
+ parseSync<T = Record<string, unknown>>(label: string, input: unknown, schema?: Schema<T>): T;
79
+ }
80
+ /**
81
+ * Default {@link SchemaParserInterface} implementation.
82
+ *
83
+ * A missing schema is not an error — the value passes through untouched, which
84
+ * is what makes {@link RouteConfig} entirely optional.
85
+ */
86
+ declare class SchemaParser implements SchemaParserInterface {
87
+ /**
88
+ * Validates a value against a schema.
89
+ *
90
+ * This is what {@link App} uses during the request lifecycle, since a schema
91
+ * may validate asynchronously.
92
+ *
93
+ * @param label - Names the surface being validated — `"body"`, `"search"` or
94
+ * `"params"` — and appears in the error message.
95
+ * @param data - The value to validate, already parsed from the request.
96
+ * @param schema - The schema from the route's {@link RouteConfig}. Omitting it
97
+ * returns the data as-is.
98
+ * @returns The validated value, with whatever transformations the schema
99
+ * applies.
100
+ * @throws {@link Exception} with {@link Status.UNPROCESSABLE_ENTITY} when
101
+ * validation fails, carrying the rejected data as exception data.
102
+ */
103
+ parse<T = Record<string, unknown>>(label: string, data: unknown, schema?: Schema<T>): Promise<T>;
104
+ /**
105
+ * Validates a value without awaiting, for callers that cannot be async.
106
+ *
107
+ * Whether a schema validates synchronously is not visible in its type, so it
108
+ * is detected at runtime: a validator that returns a promise is rejected
109
+ * outright rather than having its result silently used as a value.
110
+ *
111
+ * @param label - Names the surface being validated, and appears in the error
112
+ * message.
113
+ * @param data - The value to validate.
114
+ * @param schema - The schema. Omitting it returns the data as-is.
115
+ * @returns The validated value.
116
+ * @throws {@link Error} when the schema validates asynchronously — use
117
+ * {@link SchemaParser.parse} instead.
118
+ * @throws {@link Exception} with {@link Status.UNPROCESSABLE_ENTITY} when
119
+ * validation fails.
120
+ */
121
+ parseSync<T = Record<string, unknown>>(label: string, data: unknown, schema?: Schema<T>): T;
122
+ /**
123
+ * Renders validation issues into the message sent to the client.
124
+ *
125
+ * Each issue is reported as `in <label> <path> (received <value>): <message>`,
126
+ * so a client can see which field failed and what it actually sent — a
127
+ * schema's own message alone rarely says which field it came from. Path
128
+ * segments are joined with dots, and the offending value is looked up by
129
+ * walking the original data along that path. Issues with no path are global to
130
+ * the surface and keep their message unadorned.
131
+ *
132
+ * Override this to change the wording or to withhold the received values.
133
+ *
134
+ * @param label - Names the surface being validated.
135
+ * @param data - The value that failed, walked to find each reported value.
136
+ * @param issues - The failures the schema reported.
137
+ * @returns One line per issue, newline-joined, or an empty string when there
138
+ * are none.
139
+ */
140
+ issuesToErrorMessage(label: string, data: unknown, issues: ValidationIssues): string;
141
+ }
142
+ export { type SchemaParserInterface, SchemaParser, type Schema, type InferSchemaIn, type InferSchemaOut, type ValidationIssues, type InferModel, };
143
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ParserBase/SchemaParser/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Parsing a query string into a nested object.
3
+ *
4
+ * {@link SearchParamsParser} is the default
5
+ * {@link ParsersRegistry.searchParamsParser}. It fills {@link Context.search},
6
+ * and {@link BodyParser} also routes `application/x-www-form-urlencoded` bodies
7
+ * through it, so a query string and a form post with matching field names
8
+ * produce the same shape.
9
+ *
10
+ * @module SearchParamsParser
11
+ */
12
+ import { ParserBase } from "..";
13
+ /**
14
+ * Turns `URLSearchParams` into a nested object.
15
+ *
16
+ * Keys are read as paths through {@link ParserBase.parseKey}, so
17
+ * `?filter[status]=open&tags[0]=a` builds the objects and arrays it describes.
18
+ * Repeated keys collect into an array, which is how `?tag=a&tag=b` arrives
19
+ * without any bracket notation.
20
+ *
21
+ * Values are coerced through {@link ParserBase.tryParseJSON}, so `?page=2` and
22
+ * `?active=true` arrive as a number and a boolean rather than as strings.
23
+ */
24
+ declare class SearchParamsParser extends ParserBase<URLSearchParams> {
25
+ /**
26
+ * Parses a query string into a nested object.
27
+ *
28
+ * @param searchParams - The parameters to parse.
29
+ * @returns The nested object, built on a null prototype by
30
+ * {@link createSafeObject} so a `__proto__` key in the query string cannot
31
+ * reach `Object.prototype`.
32
+ */
33
+ parse(searchParams: URLSearchParams): Record<string, unknown>;
34
+ /**
35
+ * Writes a value at a path, creating the containers it passes through.
36
+ *
37
+ * Each missing level is created as an array when the next path part is a
38
+ * number and as an object otherwise, so the shape follows the key rather than
39
+ * being guessed after the fact. A scalar already occupying a level that must
40
+ * be descended into is replaced — query strings are client-controlled and
41
+ * arrive in arbitrary order, so `?a=1&a[b]=2` is resolved by letting the
42
+ * structured key win rather than throwing.
43
+ *
44
+ * The final slot collects rather than overwrites: an empty slot takes the
45
+ * value, a slot already holding an array appends, and a slot holding a single
46
+ * value is promoted to an array. That is what makes repeated keys accumulate,
47
+ * in arrival order.
48
+ *
49
+ * Deliberately kept separate from {@link FormDataParser}'s near-identical
50
+ * method: the two sources differ in what they can carry, and sharing the code
51
+ * would tie their behaviour together.
52
+ *
53
+ * @param result - The object being built up.
54
+ * @param parts - The path from {@link ParserBase.parseKey}; numbers mean array
55
+ * indices, strings mean object keys.
56
+ * @param value - The value to write, already coerced.
57
+ */
58
+ private setDeep;
59
+ }
60
+ export { SearchParamsParser };
61
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ParserBase/SearchParamsParser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;;;;;;;;;GAUG;AACH,cAAM,kBAAmB,SAAQ,UAAU,CAAC,eAAe,CAAC;IAC3D;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAY7D;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CAAC,OAAO;CAmCf;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Parsing path parameters into typed values.
3
+ *
4
+ * {@link URLParamsParser} is the default
5
+ * {@link ParsersRegistry.urlParamsParser}. It fills {@link Context.params} from
6
+ * the raw values Bun's router matched, decoding and coercing each one.
7
+ *
8
+ * @module URLParamsParser
9
+ */
10
+ import { ParserBase } from "..";
11
+ /**
12
+ * Turns matched path parameters into a typed object.
13
+ *
14
+ * The flattest of the parsers: path parameters are named by the route pattern,
15
+ * so there is no nesting to recover — no bracket notation, no repeated keys.
16
+ * Each value is percent-decoded and then coerced through
17
+ * {@link ParserBase.tryParseJSON}, so `/users/42` yields a number rather than a
18
+ * string.
19
+ */
20
+ declare class URLParamsParser extends ParserBase<Record<string, string>> {
21
+ /**
22
+ * Parses matched path parameters.
23
+ *
24
+ * @param input - The raw parameters from the router, including the `*` key
25
+ * that {@link App} lifts out of a wildcard endpoint.
26
+ * @returns The decoded, coerced parameters, on a null prototype from
27
+ * {@link createSafeObject}.
28
+ */
29
+ parse(input: Record<string, string>): Record<string, unknown>;
30
+ }
31
+ export { URLParamsParser };
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ParserBase/URLParamsParser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;;;;;;;GAQG;AACH,cAAM,eAAgB,SAAQ,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/D;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAO7D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The shared base for the input parsers that turn flat key/value pairs into
3
+ * nested objects.
4
+ *
5
+ * {@link URLParamsParser}, {@link SearchParamsParser} and
6
+ * {@link FormDataParser} all face the same problem: a source that only carries
7
+ * strings paired with strings, where structure has to be recovered from the key
8
+ * itself and types from the value. {@link ParserBase} supplies both halves —
9
+ * {@link ParserBase.parseKey} for the bracket notation and
10
+ * {@link ParserBase.tryParseJSON} for value coercion — so the three agree on
11
+ * what `user[roles][0]=admin` means regardless of which surface it arrived on.
12
+ *
13
+ * Subclass it to add a parser of your own, then register it through
14
+ * {@link setParsersRegistry}.
15
+ *
16
+ * @module ParserBase
17
+ */
18
+ /**
19
+ * The public shape of an input parser. This is the type
20
+ * {@link ParsersRegistry.urlParamsParser}, {@link ParsersRegistry.searchParamsParser}
21
+ * and {@link ParsersRegistry.formDataParser} hold, so a replacement need only
22
+ * satisfy the contract rather than extend {@link ParserBase}.
23
+ *
24
+ * @typeParam T - The input the parser accepts — `URLSearchParams`, `FormData`,
25
+ * or a record of raw path parameters.
26
+ */
27
+ interface ParserBaseInterface<T> {
28
+ /**
29
+ * Converts the input into a nested object.
30
+ *
31
+ * @param input - The source to parse.
32
+ * @returns The parsed object.
33
+ */
34
+ parse(input: T): Record<string, unknown>;
35
+ }
36
+ /**
37
+ * Base class for the input parsers.
38
+ *
39
+ * It provides the key and value handling; each subclass supplies
40
+ * {@link ParserBase.parse} for its own source and does the writing, since how
41
+ * repeated keys collect differs between a query string and a form.
42
+ *
43
+ * @typeParam T - The input the parser accepts.
44
+ */
45
+ declare abstract class ParserBase<T> implements ParserBaseInterface<T> {
46
+ /**
47
+ * Converts the input into a nested object. Implemented per source.
48
+ *
49
+ * @param input - The source to parse.
50
+ * @returns The parsed object.
51
+ */
52
+ abstract parse(input: T): Record<string, unknown>;
53
+ /**
54
+ * Narrows a value to an indexable container so a path segment can be written
55
+ * into it.
56
+ *
57
+ * Purely a readability helper for the traversal loops — the value is used
58
+ * as-is, nothing is constructed.
59
+ *
60
+ * @param current - The level currently being written into.
61
+ * @returns The same value, typed for index access.
62
+ */
63
+ protected newContainer(current: unknown): Record<string | number, unknown>;
64
+ /**
65
+ * Splits a key into the path it describes.
66
+ *
67
+ * Dot and bracket notation are treated as equivalent, so `a[0].b[1][c]` and
68
+ * `a.0.b.1.c` both yield `["a", 0, "b", 1, "c"]`. A purely numeric segment
69
+ * becomes a number, which is how the subclasses know to create an array rather
70
+ * than an object at that level — subject to {@link ARRAY_INDEX_LIMIT}, above
71
+ * which the segment stays a string key.
72
+ *
73
+ * @param key - The raw field name.
74
+ * @returns The path segments: numbers for array indices, strings for object
75
+ * keys.
76
+ */
77
+ protected parseKey(key: string): (string | number)[];
78
+ /**
79
+ * Coerces a raw string value into whatever it represents.
80
+ *
81
+ * Since every value from these sources arrives as a string, `"42"`, `"true"`
82
+ * and `"null"` are decoded to their JSON equivalents. Anything that is not
83
+ * valid JSON — ordinary text, most of the time — is returned unchanged rather
84
+ * than treated as an error.
85
+ *
86
+ * @param value - The raw string value.
87
+ * @returns The decoded value, or the original string.
88
+ */
89
+ protected tryParseJSON(value: string): unknown;
90
+ }
91
+ export { type ParserBaseInterface, ParserBase };
92
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ParserBase/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;GAQG;AACH,UAAU,mBAAmB,CAAC,CAAC;IAC9B;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAWD;;;;;;;;GAQG;AACH,uBAAe,UAAU,CAAC,CAAC,CAAE,YAAW,mBAAmB,CAAC,CAAC,CAAC;IAC7D;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEjD;;;;;;;;;OASG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC;IAI1E;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE;IAepD;;;;;;;;;;OAUG;IACH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAO9C;AAED,OAAO,EAAE,KAAK,mBAAmB,EAAE,UAAU,EAAE,CAAC"}