@dunx/http 1.1.0 → 1.2.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.
package/README.md CHANGED
@@ -133,7 +133,7 @@ render as `a.0`):
133
133
  ### Which validator to use
134
134
 
135
135
  Any of them. This is measured rather than asserted - `bun run validation` in
136
- `tools/bench` runs the same dunx app and the same schema shape with only the library
136
+ `internal/bench` runs the same dunx app and the same schema shape with only the library
137
137
  behind `~standard` changed, and reports what each one costs per request:
138
138
 
139
139
  | Validator | costs | `~standard` |
@@ -176,7 +176,7 @@ const PersonSchema: StandardSchemaV1<unknown, Static<typeof Person>> = {
176
176
  ```
177
177
 
178
178
  Full numbers, methodology and the ajv version:
179
- [`tools/bench/README.md`](../../tools/bench/README.md), "Validation cost".
179
+ [`internal/bench/README.md`](../../internal/bench/README.md), "Validation cost".
180
180
 
181
181
  ## Route metadata and scoped middleware
182
182
 
@@ -349,7 +349,7 @@ request logging costs, and an app whose handlers never log pays it for nothing.
349
349
 
350
350
  `requestBody` and `responseBody` default to **`false`**. Turning either on means a
351
351
  `clone().text()` - a second copy of every payload, buffered and parsed, on the hot
352
- path. Measured in `tools/bench`, both on cost roughly two thirds of the throughput
352
+ path. Measured in `internal/bench`, both on cost roughly two thirds of the throughput
353
353
  on the `validate` scenario. The response body is also the field most likely to
354
354
  carry a secret, so this is the right default twice over.
355
355
 
@@ -371,7 +371,7 @@ HttpFactory.create(AppModule, {
371
371
  });
372
372
  ```
373
373
 
374
- **Even at its cheapest, a log line is not free.** `tools/bench` carries `dunx` and
374
+ **Even at its cheapest, a log line is not free.** `internal/bench` carries `dunx` and
375
375
  `dunx-logging` as separate subjects for exactly this reason: with logging off dunx
376
376
  runs at 81-100% of raw `Bun.serve` depending on the scenario, and with it on, 40-45%.
377
377
  The remainder is `JSON.stringify` plus a `write` per request inside an
@@ -403,7 +403,7 @@ tick for nothing.
403
403
  | `query` and/or `params`, sync validator | no promise at all - read and validated inline |
404
404
  | `body` declared | one promise link, for `req.json()` |
405
405
 
406
- Measured in `tools/bench`: `plaintext` 89.5% -> 97.2% of raw `Bun.serve` when this
406
+ Measured in `internal/bench`: `plaintext` 89.5% -> 97.2% of raw `Bun.serve` when this
407
407
  covered only schema-less routes, and `validate` 84.0% -> 92.3% once it was extended
408
408
  to routes that read input. A handler that *does* return a promise, or a validator
409
409
  that does, is adopted rather than wrapped - nothing about this is conditional on
@@ -0,0 +1,110 @@
1
+ // @bun
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __name = (target, name) => {
6
+ Object.defineProperty(target, "name", {
7
+ value: name,
8
+ enumerable: false,
9
+ configurable: true
10
+ });
11
+ return target;
12
+ };
13
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
14
+ var __typeError = (msg) => {
15
+ throw TypeError(msg);
16
+ };
17
+ var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
18
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
19
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
20
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
21
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
22
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
23
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
24
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
25
+ var __expectFn = (fn) => fn !== undefined && typeof fn !== "function" ? __typeError("Function expected") : fn;
26
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({
27
+ kind: __decoratorStrings[kind],
28
+ name,
29
+ metadata,
30
+ addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null))
31
+ });
32
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
33
+ var __runInitializers = (array, flags, self, value) => {
34
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length;i < n; i++)
35
+ flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
36
+ return value;
37
+ };
38
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
39
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
40
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
41
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
42
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : {
43
+ get [name]() {
44
+ return __privateGet(this, extra);
45
+ },
46
+ set [name](x) {
47
+ __privateSet(this, extra, x);
48
+ }
49
+ }, name));
50
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
51
+ for (var i = decorators.length - 1;i >= 0; i--) {
52
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
53
+ if (k) {
54
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => (name in x) };
55
+ if (k ^ 3)
56
+ access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
57
+ if (k > 2)
58
+ access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
59
+ }
60
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? undefined : { get: desc.get, set: desc.set } : target, ctx);
61
+ done._ = 1;
62
+ if (k ^ 4 || it === undefined)
63
+ __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
64
+ else if (typeof it !== "object" || it === null)
65
+ __typeError("Object expected");
66
+ else
67
+ __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
68
+ }
69
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
70
+ };
71
+
72
+ // src/server/status.ts
73
+ var HttpStatusCode = Object.freeze({
74
+ OK: 200,
75
+ CREATED: 201,
76
+ ACCEPTED: 202,
77
+ NO_CONTENT: 204,
78
+ MOVED_PERMANENTLY: 301,
79
+ FOUND: 302,
80
+ NOT_MODIFIED: 304,
81
+ TEMPORARY_REDIRECT: 307,
82
+ PERMANENT_REDIRECT: 308,
83
+ BAD_REQUEST: 400,
84
+ UNAUTHORIZED: 401,
85
+ PAYMENT_REQUIRED: 402,
86
+ FORBIDDEN: 403,
87
+ NOT_FOUND: 404,
88
+ METHOD_NOT_ALLOWED: 405,
89
+ NOT_ACCEPTABLE: 406,
90
+ REQUEST_TIMEOUT: 408,
91
+ CONFLICT: 409,
92
+ GONE: 410,
93
+ PRECONDITION_FAILED: 412,
94
+ PAYLOAD_TOO_LARGE: 413,
95
+ URI_TOO_LONG: 414,
96
+ UNSUPPORTED_MEDIA_TYPE: 415,
97
+ IM_A_TEAPOT: 418,
98
+ UNPROCESSABLE_ENTITY: 422,
99
+ TOO_MANY_REQUESTS: 429,
100
+ INTERNAL_SERVER_ERROR: 500,
101
+ NOT_IMPLEMENTED: 501,
102
+ BAD_GATEWAY: 502,
103
+ SERVICE_UNAVAILABLE: 503,
104
+ GATEWAY_TIMEOUT: 504
105
+ });
106
+
107
+ export { __decoratorStart, __decoratorMetadata, __runInitializers, __decorateElement, HttpStatusCode };
108
+
109
+ //# debugId=83F76F267D9DFA2264756E2164756E21
110
+ //# sourceMappingURL=chunk-5z96f3gr.js.map
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
5
  "/**\n * Frozen object plus an indexed-access union, not an `enum`. An enum emits a\n * runtime object that no other syntax can produce, which is why the repo bans it -\n * see CLAUDE.md. This gives the same `HttpStatusCode.NOT_FOUND` ergonomics, a\n * narrower type, and erases cleanly.\n */\nexport const HttpStatusCode = Object.freeze({\n OK: 200,\n CREATED: 201,\n ACCEPTED: 202,\n NO_CONTENT: 204,\n MOVED_PERMANENTLY: 301,\n FOUND: 302,\n NOT_MODIFIED: 304,\n TEMPORARY_REDIRECT: 307,\n PERMANENT_REDIRECT: 308,\n BAD_REQUEST: 400,\n UNAUTHORIZED: 401,\n PAYMENT_REQUIRED: 402,\n FORBIDDEN: 403,\n NOT_FOUND: 404,\n METHOD_NOT_ALLOWED: 405,\n NOT_ACCEPTABLE: 406,\n REQUEST_TIMEOUT: 408,\n CONFLICT: 409,\n GONE: 410,\n PRECONDITION_FAILED: 412,\n PAYLOAD_TOO_LARGE: 413,\n URI_TOO_LONG: 414,\n UNSUPPORTED_MEDIA_TYPE: 415,\n IM_A_TEAPOT: 418,\n UNPROCESSABLE_ENTITY: 422,\n TOO_MANY_REQUESTS: 429,\n INTERNAL_SERVER_ERROR: 500,\n NOT_IMPLEMENTED: 501,\n BAD_GATEWAY: 502,\n SERVICE_UNAVAILABLE: 503,\n GATEWAY_TIMEOUT: 504,\n} as const);\n\n/** The status numbers: `200 | 201 | ...`. */\nexport type HttpStatusCode =\n (typeof HttpStatusCode)[keyof typeof HttpStatusCode];\n\n/** The names: `'OK' | 'CREATED' | ...`. */\nexport type HttpStatusName = keyof typeof HttpStatusCode;\n"
6
6
  ],
7
- "mappings": ";;AAMO,IAAM,iBAAiB,OAAO,OAAO;AAAA,EAC1C,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,mBAAmB;AAAA,EACnB,OAAO;AAAA,EACP,cAAc;AAAA,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"debugId": "83F76F267D9DFA2264756E2164756E21",
9
9
  "names": []
10
10
  }
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  HttpStatusCode
4
- } from "./chunk-x80f562w.js";
4
+ } from "./chunk-5z96f3gr.js";
5
5
 
6
6
  // src/client/errors.ts
7
7
  import { AppError } from "@dunx/core";
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { discoverRoutes, joinPath, type DiscoveredRoute, } from './route/discove
3
3
  export type { HttpMethod, RouteMeta, RoutePath } from './route/marker.js';
4
4
  export { ApiHidden, guardsOf, HIDDEN, meta, metaKey, metaOf, mergeMeta, Public, PUBLIC, Roles, ROLES, UNMATCHED, UseGuards, type MetaKey, type MetaRecord, } from './route/metadata.js';
5
5
  export type { InferOutput, Input, RouteInput, RouteSchemas, StandardSchemaIssue, StandardSchemaResult, StandardSchemaV1, } from './route/schema.js';
6
+ export { gatewaysOf, routesOf, type GatewayHandler, type GatewayNode, type RouteInputs, type RouteNode, } from './inspect.js';
6
7
  export { ClientAddress } from './server/client-address.js';
7
8
  export { buildContext, type RouteContext } from './server/context.js';
8
9
  export { preflight, withCors, type CorsOptions, type CorsOrigin, } from './server/cors.js';
@@ -12,6 +13,9 @@ export { REQUEST_ID_HEADER, RequestLoggingMiddleware, type RequestLoggingOptions
12
13
  export { compose, type Middleware, type Next, type RouteHandler, } from './server/middleware.js';
13
14
  export { assertNoCollisions, assertNoGatewayCollisions, buildRoutes, withUpgradeRoutes, type BunRoutes, type GuardResolver, type RouteMethod, type ServeRoutes, } from './server/routes.js';
14
15
  export type { AppSettings } from './server/settings.js';
16
+ export { StaticFiles } from './static/files.js';
17
+ export { StaticModule } from './static/module.js';
18
+ export { normalizePrefix, StaticOptions, type StaticOptionsInit, } from './static/options.js';
15
19
  export { HttpStatusCode, type HttpStatusName } from './server/status.js';
16
20
  export { buildWebSocket, type UpgradeHandler, type WebSocketRuntime, } from './ws/adapter.js';
17
21
  export { Gateway, OnClose, OnDrain, OnMessage, OnOpen, OnPing, OnPong, OnUpgrade, } from './ws/decorators.js';