@znight/http 0.0.0-stage → 0.1.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 (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2333 -2
  3. package/dist/adapter-CGSceVEN.d.mts +876 -0
  4. package/dist/compiler.d.mts +156 -0
  5. package/dist/compiler.mjs +2180 -0
  6. package/dist/compiler.mjs.map +1 -0
  7. package/dist/express.d.mts +39 -0
  8. package/dist/express.mjs +135 -0
  9. package/dist/express.mjs.map +1 -0
  10. package/dist/fastify.d.mts +33 -0
  11. package/dist/fastify.mjs +191 -0
  12. package/dist/fastify.mjs.map +1 -0
  13. package/dist/hono.d.mts +49 -0
  14. package/dist/hono.mjs +319 -0
  15. package/dist/hono.mjs.map +1 -0
  16. package/dist/index.d.mts +1254 -0
  17. package/dist/index.mjs +5618 -0
  18. package/dist/index.mjs.map +1 -0
  19. package/dist/node-BUnkdSsa.mjs +183 -0
  20. package/dist/node-BUnkdSsa.mjs.map +1 -0
  21. package/dist/node-io-BY1ZDLRQ.mjs +1566 -0
  22. package/dist/node-io-BY1ZDLRQ.mjs.map +1 -0
  23. package/dist/node.d.mts +30 -0
  24. package/dist/node.mjs +1 -0
  25. package/dist/path-JI87C4k8.d.mts +109 -0
  26. package/dist/path.d.mts +2 -0
  27. package/dist/path.mjs +245 -0
  28. package/dist/path.mjs.map +1 -0
  29. package/dist/size-D8rsQcV0.mjs +184 -0
  30. package/dist/size-D8rsQcV0.mjs.map +1 -0
  31. package/dist/utils-DCbu3a4w.mjs +27 -0
  32. package/dist/utils-DCbu3a4w.mjs.map +1 -0
  33. package/package.json +142 -4
  34. package/src/adapter.ts +240 -0
  35. package/src/adapters/express.ts +201 -0
  36. package/src/adapters/fastify.ts +280 -0
  37. package/src/adapters/hono.ts +488 -0
  38. package/src/adapters/node-io.ts +368 -0
  39. package/src/adapters/node.ts +135 -0
  40. package/src/adapters/shared.ts +508 -0
  41. package/src/body.ts +135 -0
  42. package/src/coerce.ts +195 -0
  43. package/src/compiler/analyze.ts +1513 -0
  44. package/src/compiler/ast.ts +90 -0
  45. package/src/compiler/coercion.ts +267 -0
  46. package/src/compiler/generate.ts +374 -0
  47. package/src/compiler/index.ts +76 -0
  48. package/src/compiler/model.ts +260 -0
  49. package/src/compiler/route-decorators.ts +405 -0
  50. package/src/compiler/validate.ts +288 -0
  51. package/src/context.ts +533 -0
  52. package/src/cookie-settings.ts +68 -0
  53. package/src/cookie-signer.ts +106 -0
  54. package/src/cookies.ts +726 -0
  55. package/src/cors.ts +349 -0
  56. package/src/decisions.ts +331 -0
  57. package/src/decorators.ts +486 -0
  58. package/src/event-channel.ts +197 -0
  59. package/src/exceptions.ts +257 -0
  60. package/src/files.ts +429 -0
  61. package/src/headers.ts +39 -0
  62. package/src/index.ts +185 -0
  63. package/src/inject-sse.ts +309 -0
  64. package/src/interfaces.ts +101 -0
  65. package/src/metadata.ts +162 -0
  66. package/src/mime.ts +157 -0
  67. package/src/multipart.ts +597 -0
  68. package/src/option-error.ts +31 -0
  69. package/src/path.ts +288 -0
  70. package/src/pipeline.ts +918 -0
  71. package/src/plugin-routes.ts +188 -0
  72. package/src/plugin.ts +1432 -0
  73. package/src/proxy.ts +236 -0
  74. package/src/query.ts +30 -0
  75. package/src/response.ts +240 -0
  76. package/src/router.ts +119 -0
  77. package/src/security-headers.ts +161 -0
  78. package/src/serialize.ts +264 -0
  79. package/src/size.ts +66 -0
  80. package/src/sse-parse.ts +194 -0
  81. package/src/sse.ts +650 -0
  82. package/src/standard-schema.ts +81 -0
  83. package/src/status.ts +78 -0
  84. package/src/stream.ts +200 -0
  85. package/src/tokens.ts +21 -0
  86. package/src/uploads.ts +176 -0
  87. package/src/utils.ts +31 -0
  88. package/src/validate.ts +65 -0
@@ -0,0 +1,156 @@
1
+ import { _ as HttpMethod, y as HttpParamSource } from "./adapter-CGSceVEN.mjs";
2
+ import { ClassRef, CompilerExtension, Location, StaticValue, ValueRef } from "@znight/compiler";
3
+ /** Primitive coercions (`coerce.<kind>`). */
4
+ type ScalarCoercion = "string" | "number" | "integer" | "boolean" | "bigint" | "date";
5
+ /**
6
+ * How a raw value (route parameter, query value, header) is converted to the declared type of a
7
+ * handler parameter.
8
+ */
9
+ type CoercionPlan = {
10
+ readonly kind: ScalarCoercion;
11
+ } | {
12
+ readonly kind: "enum";
13
+ readonly values: readonly (string | number | boolean)[];
14
+ } | {
15
+ readonly kind: "array";
16
+ readonly item: CoercionPlan;
17
+ } | {
18
+ readonly kind: "optional";
19
+ readonly item: CoercionPlan;
20
+ } | {
21
+ readonly kind: "raw";
22
+ };
23
+ /** The coercion of a handler parameter. */
24
+ interface ParamCoercion {
25
+ readonly plan: CoercionPlan;
26
+ /**
27
+ * The coerced value does not have the declared type (branded primitives, enums, `null` without
28
+ * `undefined`): the generated expression is cast with `as never`.
29
+ */
30
+ readonly cast: boolean;
31
+ }
32
+ /** An upload parameter (`@UploadedFile` / `@UploadedFiles`). */
33
+ interface UploadData {
34
+ /** Multipart field; `undefined`: any field. */
35
+ readonly field: string | undefined;
36
+ /** `@UploadedFiles`. */
37
+ readonly multiple: boolean;
38
+ /** A file must be sent (`required` option, else the parameter is not optional). */
39
+ readonly required: boolean;
40
+ /** `maxSize` in bytes (`Infinity` allowed). */
41
+ readonly maxSize: number | undefined;
42
+ /** `maxFiles` (`@UploadedFiles` only). */
43
+ readonly maxFiles: number | undefined;
44
+ /** `mimeTypes` patterns, as written. */
45
+ readonly mimeTypes: readonly string[] | undefined;
46
+ /** The injected value does not have the declared type (`node:buffer` File, `File | null`): `as never`. */
47
+ readonly cast: boolean;
48
+ }
49
+ /** A handler parameter. */
50
+ interface HttpParamData {
51
+ /** Position in the handler signature. */
52
+ readonly index: number;
53
+ /** Parameter name (messages). */
54
+ readonly name: string;
55
+ readonly source: HttpParamSource;
56
+ /** Route parameter name, query key, lower-case header name or cookie name; `undefined` for the whole object. */
57
+ readonly key: string | undefined;
58
+ /** Declared (or inferred) type, formatted for humans. */
59
+ readonly type: string | undefined;
60
+ /** The parameter accepts `undefined` (`?`, `| undefined`, default value). */
61
+ readonly optional: boolean;
62
+ /** Standard Schema validating the value (its output is injected). */
63
+ readonly schema: ValueRef | undefined;
64
+ /** Coercion of a named value without schema. */
65
+ readonly coercion: ParamCoercion | undefined;
66
+ /** Upload parameter (`source` `file` / `files`). */
67
+ readonly upload?: UploadData;
68
+ /**
69
+ * The default value of the handler parameter (`@Query('page') page = 1` → `1`), when it is
70
+ * statically evaluable (literals, `const` references; references to exported bindings are left
71
+ * out). Informational (documentation): the handler applies its own default.
72
+ */
73
+ readonly defaultValue?: StaticValue;
74
+ /** Location of the parameter decorator. */
75
+ readonly location: Location;
76
+ }
77
+ /** A `createRouteDecorator` value (`route.meta[key]`) and the definition of its decorator. */
78
+ interface MetaEntry {
79
+ readonly key: string;
80
+ /** Statically evaluated value; may be or contain references to exported bindings. */
81
+ readonly value: StaticValue;
82
+ /** Location of the decorator usage. */
83
+ readonly location: Location;
84
+ /** Decision group (`options.group ?? key`). */
85
+ readonly group: string;
86
+ /** The group is required (`options.required`). */
87
+ readonly required: boolean;
88
+ /** Display name of the decorator (`Roles`). */
89
+ readonly decorator: string;
90
+ /** Canonical identity of the decorator `const` (`src/auth/access.ts#Roles`). */
91
+ readonly identity: string;
92
+ /** Location of the decorator definition (`export const Roles = createRouteDecorator(...)`). */
93
+ readonly definition: Location;
94
+ }
95
+ /** Options of an `@Sse` route (`HttpRouteDefinition.sse`). */
96
+ interface SseRouteData {
97
+ /** Heartbeat in ms; `0` disables it (`heartbeat: false`). Absent: the plugin default. */
98
+ readonly heartbeat?: number;
99
+ readonly retry?: number;
100
+ readonly maxDuration?: number;
101
+ }
102
+ /** A route: one route decorator of a handler. */
103
+ interface HttpRouteData {
104
+ readonly method: HttpMethod;
105
+ /** Path of the route decorator as written (`undefined` when absent). */
106
+ readonly rawPath: string;
107
+ /** `normalizePath(rawPath)`. */
108
+ readonly path: string;
109
+ /** `joinPaths(controller base path, path)`. */
110
+ readonly fullPath: string;
111
+ readonly handler: string;
112
+ readonly status: number | undefined;
113
+ /** `@Header` entries, lower-case names, in source order. */
114
+ readonly headers: readonly (readonly [string, string])[];
115
+ readonly meta: readonly MetaEntry[];
116
+ readonly guards: readonly ClassRef[];
117
+ readonly interceptors: readonly ClassRef[];
118
+ readonly params: readonly HttpParamData[];
119
+ /** `false` when a parameter could not be analysed (an error was reported; it is missing from `params`). */
120
+ readonly complete: boolean;
121
+ /** `@Validate(S)` on a handler without `@Body()` parameter: the body is validated and discarded. */
122
+ readonly bodySchema: ValueRef | undefined;
123
+ /** `@BodyLimit` of the method (or of the controller), in bytes. */
124
+ readonly bodyLimit: number | undefined;
125
+ readonly rawResponse: boolean;
126
+ /** `@Sse` route: its options (`{}` without options). */
127
+ readonly sse?: SseRouteData;
128
+ /** Location of the route decorator. */
129
+ readonly location: Location;
130
+ /** Location of the path argument (the decorator when absent). */
131
+ readonly pathLocation: Location;
132
+ }
133
+ /** A controller (data stored by `analyzeClass`). */
134
+ interface HttpControllerData {
135
+ /** Provider token of the controller. */
136
+ readonly token: string;
137
+ /** Canonical identity of the class (imported as a type by `invoke`). */
138
+ readonly identity: string;
139
+ readonly displayName: string;
140
+ /** Base path as written. */
141
+ readonly rawBasePath: string;
142
+ /** `normalizePath(rawBasePath)`. */
143
+ readonly basePath: string;
144
+ readonly guards: readonly ClassRef[];
145
+ readonly interceptors: readonly ClassRef[];
146
+ readonly meta: readonly MetaEntry[];
147
+ readonly routes: readonly HttpRouteData[];
148
+ /** Location of `@Controller`. */
149
+ readonly location: Location;
150
+ /** Location of the base path argument (the decorator when absent). */
151
+ readonly pathLocation: Location;
152
+ }
153
+ /** The `@znight/http` compiler extension. */
154
+ declare const http: CompilerExtension<HttpControllerData>;
155
+ export { type CoercionPlan, type HttpControllerData, type HttpParamData, type HttpRouteData, type MetaEntry, type ParamCoercion, type ScalarCoercion, type SseRouteData, type UploadData, http as default };
156
+ //# sourceMappingURL=compiler.d.mts.map