@celljs/web 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +39 -1
  2. package/cell.yml +0 -3
  3. package/esm/browser/module.d.ts +1 -1
  4. package/esm/common/module.d.ts +1 -1
  5. package/esm/common/pipe/index.d.ts +1 -1
  6. package/esm/common/pipe/index.js +1 -1
  7. package/esm/common/pipe/index.js.map +1 -1
  8. package/esm/common/pipe/type-conversion-pipe.d.ts +12 -0
  9. package/esm/common/pipe/type-conversion-pipe.js +43 -0
  10. package/esm/common/pipe/type-conversion-pipe.js.map +1 -0
  11. package/esm/common/pipe/validation-errors.d.ts +11 -2
  12. package/esm/common/pipe/validation-errors.js +2 -0
  13. package/esm/common/pipe/validation-errors.js.map +1 -1
  14. package/esm/node/body/body-middleware.d.ts +4 -6
  15. package/esm/node/body/body-middleware.js +6 -16
  16. package/esm/node/body/body-middleware.js.map +1 -1
  17. package/esm/node/body/body-parser.d.ts +32 -0
  18. package/esm/node/body/body-parser.js +205 -0
  19. package/esm/node/body/body-parser.js.map +1 -0
  20. package/esm/node/body/body-protocol.d.ts +15 -0
  21. package/esm/node/body/form-util.d.ts +15 -0
  22. package/esm/node/body/form-util.js +120 -0
  23. package/esm/node/body/form-util.js.map +1 -0
  24. package/esm/node/body/index.d.ts +2 -0
  25. package/esm/node/body/index.js +2 -0
  26. package/esm/node/body/index.js.map +1 -1
  27. package/esm/node/cookies/cookies-factory.js +2 -6
  28. package/esm/node/cookies/cookies-factory.js.map +1 -1
  29. package/esm/node/cookies/cookies-protocol.d.ts +25 -2
  30. package/esm/node/cookies/cookies.d.ts +17 -0
  31. package/esm/node/cookies/cookies.js +137 -0
  32. package/esm/node/cookies/cookies.js.map +1 -0
  33. package/esm/node/cookies/index.d.ts +1 -0
  34. package/esm/node/cookies/index.js +1 -0
  35. package/esm/node/cookies/index.js.map +1 -1
  36. package/esm/node/cors/cors-middleware.d.ts +11 -3
  37. package/esm/node/cors/cors-middleware.js +108 -14
  38. package/esm/node/cors/cors-middleware.js.map +1 -1
  39. package/esm/node/cors/cors-protocol.d.ts +23 -0
  40. package/esm/node/error/error-handler-provider.js +3 -7
  41. package/esm/node/error/error-handler-provider.js.map +1 -1
  42. package/esm/node/health/health-middleware.js +1 -1
  43. package/esm/node/health/health-middleware.js.map +1 -1
  44. package/esm/node/http/http-protocol.d.ts +29 -5
  45. package/esm/node/http/http-protocol.js.map +1 -1
  46. package/esm/node/http/http-request.d.ts +41 -0
  47. package/esm/node/http/http-request.js +106 -0
  48. package/esm/node/http/http-request.js.map +1 -0
  49. package/esm/node/http/index.d.ts +1 -0
  50. package/esm/node/http/index.js +1 -0
  51. package/esm/node/http/index.js.map +1 -1
  52. package/esm/node/index.d.ts +1 -0
  53. package/esm/node/index.js +1 -0
  54. package/esm/node/index.js.map +1 -1
  55. package/esm/node/matcher/index.d.ts +1 -0
  56. package/esm/node/matcher/index.js +1 -0
  57. package/esm/node/matcher/index.js.map +1 -1
  58. package/esm/node/matcher/path-pattern.d.ts +23 -0
  59. package/esm/node/matcher/path-pattern.js +115 -0
  60. package/esm/node/matcher/path-pattern.js.map +1 -0
  61. package/esm/node/matcher/request-matcher.d.ts +2 -2
  62. package/esm/node/matcher/request-matcher.js +8 -9
  63. package/esm/node/matcher/request-matcher.js.map +1 -1
  64. package/esm/node/module.d.ts +1 -1
  65. package/esm/node/server/http-server.d.ts +13 -0
  66. package/esm/node/server/http-server.js +32 -0
  67. package/esm/node/server/http-server.js.map +1 -0
  68. package/esm/node/server/index.d.ts +1 -0
  69. package/esm/node/server/index.js +2 -0
  70. package/esm/node/server/index.js.map +1 -0
  71. package/esm/node/session/session-manager.js +1 -2
  72. package/esm/node/session/session-manager.js.map +1 -1
  73. package/esm/node/session/session-store.js +1 -2
  74. package/esm/node/session/session-store.js.map +1 -1
  75. package/esm/node/session/session.d.ts +3 -2
  76. package/esm/node/session/session.js +4 -10
  77. package/esm/node/session/session.js.map +1 -1
  78. package/lib/browser/module.d.ts +1 -1
  79. package/lib/common/module.d.ts +1 -1
  80. package/lib/common/pipe/index.d.ts +1 -1
  81. package/lib/common/pipe/index.d.ts.map +1 -1
  82. package/lib/common/pipe/index.js +1 -1
  83. package/lib/common/pipe/index.js.map +1 -1
  84. package/lib/common/pipe/type-conversion-pipe.d.ts +13 -0
  85. package/lib/common/pipe/type-conversion-pipe.d.ts.map +1 -0
  86. package/lib/common/pipe/type-conversion-pipe.js +46 -0
  87. package/lib/common/pipe/type-conversion-pipe.js.map +1 -0
  88. package/lib/common/pipe/type-conversion-pipe.spec.d.ts +2 -0
  89. package/lib/common/pipe/type-conversion-pipe.spec.d.ts.map +1 -0
  90. package/lib/common/pipe/type-conversion-pipe.spec.js +36 -0
  91. package/lib/common/pipe/type-conversion-pipe.spec.js.map +1 -0
  92. package/lib/common/pipe/validation-errors.d.ts +11 -2
  93. package/lib/common/pipe/validation-errors.d.ts.map +1 -1
  94. package/lib/common/pipe/validation-errors.js +2 -0
  95. package/lib/common/pipe/validation-errors.js.map +1 -1
  96. package/lib/node/body/body-middleware.d.ts +4 -6
  97. package/lib/node/body/body-middleware.d.ts.map +1 -1
  98. package/lib/node/body/body-middleware.js +4 -13
  99. package/lib/node/body/body-middleware.js.map +1 -1
  100. package/lib/node/body/body-middleware.spec.js +78 -12
  101. package/lib/node/body/body-middleware.spec.js.map +1 -1
  102. package/lib/node/body/body-parser.d.ts +33 -0
  103. package/lib/node/body/body-parser.d.ts.map +1 -0
  104. package/lib/node/body/body-parser.js +210 -0
  105. package/lib/node/body/body-parser.js.map +1 -0
  106. package/lib/node/body/body-protocol.d.ts +15 -0
  107. package/lib/node/body/body-protocol.d.ts.map +1 -1
  108. package/lib/node/body/form-util.d.ts +16 -0
  109. package/lib/node/body/form-util.d.ts.map +1 -0
  110. package/lib/node/body/form-util.js +123 -0
  111. package/lib/node/body/form-util.js.map +1 -0
  112. package/lib/node/body/form-util.spec.d.ts +2 -0
  113. package/lib/node/body/form-util.spec.d.ts.map +1 -0
  114. package/lib/node/body/form-util.spec.js +44 -0
  115. package/lib/node/body/form-util.spec.js.map +1 -0
  116. package/lib/node/body/index.d.ts +2 -0
  117. package/lib/node/body/index.d.ts.map +1 -1
  118. package/lib/node/body/index.js +2 -0
  119. package/lib/node/body/index.js.map +1 -1
  120. package/lib/node/cookies/cookies-factory.d.ts.map +1 -1
  121. package/lib/node/cookies/cookies-factory.js +2 -9
  122. package/lib/node/cookies/cookies-factory.js.map +1 -1
  123. package/lib/node/cookies/cookies-protocol.d.ts +25 -2
  124. package/lib/node/cookies/cookies-protocol.d.ts.map +1 -1
  125. package/lib/node/cookies/cookies.d.ts +18 -0
  126. package/lib/node/cookies/cookies.d.ts.map +1 -0
  127. package/lib/node/cookies/cookies.js +141 -0
  128. package/lib/node/cookies/cookies.js.map +1 -0
  129. package/lib/node/cookies/cookies.spec.d.ts +2 -0
  130. package/lib/node/cookies/cookies.spec.d.ts.map +1 -0
  131. package/lib/node/cookies/cookies.spec.js +73 -0
  132. package/lib/node/cookies/cookies.spec.js.map +1 -0
  133. package/lib/node/cookies/index.d.ts +1 -0
  134. package/lib/node/cookies/index.d.ts.map +1 -1
  135. package/lib/node/cookies/index.js +1 -0
  136. package/lib/node/cookies/index.js.map +1 -1
  137. package/lib/node/cors/cors-middleware.d.ts +11 -3
  138. package/lib/node/cors/cors-middleware.d.ts.map +1 -1
  139. package/lib/node/cors/cors-middleware.js +106 -15
  140. package/lib/node/cors/cors-middleware.js.map +1 -1
  141. package/lib/node/cors/cors-middleware.spec.d.ts +2 -0
  142. package/lib/node/cors/cors-middleware.spec.d.ts.map +1 -0
  143. package/lib/node/cors/cors-middleware.spec.js +56 -0
  144. package/lib/node/cors/cors-middleware.spec.js.map +1 -0
  145. package/lib/node/cors/cors-protocol.d.ts +23 -0
  146. package/lib/node/cors/cors-protocol.d.ts.map +1 -1
  147. package/lib/node/error/error-handler-provider.d.ts.map +1 -1
  148. package/lib/node/error/error-handler-provider.js +2 -5
  149. package/lib/node/error/error-handler-provider.js.map +1 -1
  150. package/lib/node/health/health-middleware.js +1 -1
  151. package/lib/node/health/health-middleware.js.map +1 -1
  152. package/lib/node/http/http-protocol.d.ts +29 -5
  153. package/lib/node/http/http-protocol.d.ts.map +1 -1
  154. package/lib/node/http/http-protocol.js.map +1 -1
  155. package/lib/node/http/http-request.d.ts +42 -0
  156. package/lib/node/http/http-request.d.ts.map +1 -0
  157. package/lib/node/http/http-request.js +110 -0
  158. package/lib/node/http/http-request.js.map +1 -0
  159. package/lib/node/http/http-request.spec.d.ts +2 -0
  160. package/lib/node/http/http-request.spec.d.ts.map +1 -0
  161. package/lib/node/http/http-request.spec.js +65 -0
  162. package/lib/node/http/http-request.spec.js.map +1 -0
  163. package/lib/node/http/index.d.ts +1 -0
  164. package/lib/node/http/index.d.ts.map +1 -1
  165. package/lib/node/http/index.js +1 -0
  166. package/lib/node/http/index.js.map +1 -1
  167. package/lib/node/index.d.ts +1 -0
  168. package/lib/node/index.d.ts.map +1 -1
  169. package/lib/node/index.js +1 -0
  170. package/lib/node/index.js.map +1 -1
  171. package/lib/node/matcher/index.d.ts +1 -0
  172. package/lib/node/matcher/index.d.ts.map +1 -1
  173. package/lib/node/matcher/index.js +1 -0
  174. package/lib/node/matcher/index.js.map +1 -1
  175. package/lib/node/matcher/path-pattern.d.ts +24 -0
  176. package/lib/node/matcher/path-pattern.d.ts.map +1 -0
  177. package/lib/node/matcher/path-pattern.js +119 -0
  178. package/lib/node/matcher/path-pattern.js.map +1 -0
  179. package/lib/node/matcher/path-pattern.spec.d.ts +2 -0
  180. package/lib/node/matcher/path-pattern.spec.d.ts.map +1 -0
  181. package/lib/node/matcher/path-pattern.spec.js +43 -0
  182. package/lib/node/matcher/path-pattern.spec.js.map +1 -0
  183. package/lib/node/matcher/request-matcher.d.ts +2 -2
  184. package/lib/node/matcher/request-matcher.d.ts.map +1 -1
  185. package/lib/node/matcher/request-matcher.js +8 -12
  186. package/lib/node/matcher/request-matcher.js.map +1 -1
  187. package/lib/node/module.d.ts +1 -1
  188. package/lib/node/server/http-server.d.ts +14 -0
  189. package/lib/node/server/http-server.d.ts.map +1 -0
  190. package/lib/node/server/http-server.js +35 -0
  191. package/lib/node/server/http-server.js.map +1 -0
  192. package/lib/node/server/http-server.spec.d.ts +2 -0
  193. package/lib/node/server/http-server.spec.d.ts.map +1 -0
  194. package/lib/node/server/http-server.spec.js +41 -0
  195. package/lib/node/server/http-server.spec.js.map +1 -0
  196. package/lib/node/server/index.d.ts +2 -0
  197. package/lib/node/server/index.d.ts.map +1 -0
  198. package/lib/node/server/index.js +18 -0
  199. package/lib/node/server/index.js.map +1 -0
  200. package/lib/node/session/session-manager.d.ts.map +1 -1
  201. package/lib/node/session/session-manager.js +1 -2
  202. package/lib/node/session/session-manager.js.map +1 -1
  203. package/lib/node/session/session-store.d.ts.map +1 -1
  204. package/lib/node/session/session-store.js +1 -2
  205. package/lib/node/session/session-store.js.map +1 -1
  206. package/lib/node/session/session.d.ts +3 -2
  207. package/lib/node/session/session.d.ts.map +1 -1
  208. package/lib/node/session/session.js +4 -43
  209. package/lib/node/session/session.js.map +1 -1
  210. package/lib/node/session/session.spec.js +7 -1
  211. package/lib/node/session/session.spec.js.map +1 -1
  212. package/package.json +10 -15
  213. package/src/common/pipe/index.ts +1 -1
  214. package/src/common/pipe/type-conversion-pipe.spec.ts +38 -0
  215. package/src/common/pipe/type-conversion-pipe.ts +36 -0
  216. package/src/common/pipe/validation-errors.ts +11 -2
  217. package/src/node/body/body-middleware.spec.ts +93 -14
  218. package/src/node/body/body-middleware.ts +9 -18
  219. package/src/node/body/body-parser.ts +216 -0
  220. package/src/node/body/body-protocol.ts +15 -0
  221. package/src/node/body/form-util.spec.ts +45 -0
  222. package/src/node/body/form-util.ts +132 -0
  223. package/src/node/body/index.ts +2 -0
  224. package/src/node/cookies/cookies-factory.ts +2 -6
  225. package/src/node/cookies/cookies-protocol.ts +28 -3
  226. package/src/node/cookies/cookies.spec.ts +80 -0
  227. package/src/node/cookies/cookies.ts +138 -0
  228. package/src/node/cookies/index.ts +1 -0
  229. package/src/node/cors/cors-middleware.spec.ts +59 -0
  230. package/src/node/cors/cors-middleware.ts +112 -15
  231. package/src/node/cors/cors-protocol.ts +25 -0
  232. package/src/node/error/error-handler-provider.ts +1 -2
  233. package/src/node/health/health-middleware.ts +1 -1
  234. package/src/node/http/http-protocol.ts +29 -5
  235. package/src/node/http/http-request.spec.ts +68 -0
  236. package/src/node/http/http-request.ts +132 -0
  237. package/src/node/http/index.ts +1 -0
  238. package/src/node/index.ts +1 -0
  239. package/src/node/matcher/index.ts +1 -0
  240. package/src/node/matcher/path-pattern.spec.ts +43 -0
  241. package/src/node/matcher/path-pattern.ts +113 -0
  242. package/src/node/matcher/request-matcher.ts +9 -10
  243. package/src/node/server/http-server.spec.ts +45 -0
  244. package/src/node/server/http-server.ts +35 -0
  245. package/src/node/server/index.ts +1 -0
  246. package/src/node/session/session-manager.ts +1 -2
  247. package/src/node/session/session-store.ts +1 -2
  248. package/src/node/session/session.spec.ts +8 -1
  249. package/src/node/session/session.ts +6 -12
  250. package/esm/common/pipe/pipe-transtorm.d.ts +0 -17
  251. package/esm/common/pipe/pipe-transtorm.js +0 -110
  252. package/esm/common/pipe/pipe-transtorm.js.map +0 -1
  253. package/lib/common/pipe/pipe-transtorm.d.ts +0 -18
  254. package/lib/common/pipe/pipe-transtorm.d.ts.map +0 -1
  255. package/lib/common/pipe/pipe-transtorm.js +0 -113
  256. package/lib/common/pipe/pipe-transtorm.js.map +0 -1
  257. package/lib/common/pipe/pipe-transtorm.spec.d.ts +0 -2
  258. package/lib/common/pipe/pipe-transtorm.spec.d.ts.map +0 -1
  259. package/lib/common/pipe/pipe-transtorm.spec.js +0 -69
  260. package/lib/common/pipe/pipe-transtorm.spec.js.map +0 -1
  261. package/src/common/pipe/pipe-transtorm.spec.ts +0 -62
  262. package/src/common/pipe/pipe-transtorm.ts +0 -113
@@ -4,9 +4,10 @@ export declare class SessionImpl implements Session {
4
4
  isNew: boolean;
5
5
  expire: number;
6
6
  maxAge: number;
7
- protected _preHash: string;
7
+ /** The serialized values when the session was created or restored, to tell whether it changed. */
8
+ protected _snapshot: string;
8
9
  constructor(sessionOptions: any, obj?: any);
9
- protected hash(): string;
10
+ protected serialize(): string;
10
11
  toJSON(): any;
11
12
  get changed(): boolean;
12
13
  }
@@ -1,7 +1,4 @@
1
1
  import { generateUUUID } from '@celljs/core/lib/common/utils/uuid';
2
- import * as zlib from 'node:zlib';
3
- // zlib.crc32 exists from Node.js 20.15 (and in Bun); @types/node is pinned to 18 in this repository.
4
- const crc32 = zlib.crc32;
5
2
  export class SessionImpl {
6
3
  constructor(sessionOptions, obj) {
7
4
  this.id = generateUUUID();
@@ -16,10 +13,10 @@ export class SessionImpl {
16
13
  this.expire = sessionOptions.maxAge + Date.now();
17
14
  this.maxAge = sessionOptions.maxAge;
18
15
  }
19
- this._preHash = this.hash();
16
+ this._snapshot = this.serialize();
20
17
  }
21
- hash() {
22
- return String(crc32(JSON.stringify(this.toJSON())));
18
+ serialize() {
19
+ return JSON.stringify(this.toJSON());
23
20
  }
24
21
  toJSON() {
25
22
  const obj = {};
@@ -31,10 +28,7 @@ export class SessionImpl {
31
28
  return obj;
32
29
  }
33
30
  get changed() {
34
- if (this._preHash !== this.hash()) {
35
- return true;
36
- }
37
- return false;
31
+ return this._snapshot !== this.serialize();
38
32
  }
39
33
  }
40
34
  //# sourceMappingURL=session.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/node/session/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAEnE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,qGAAqG;AACrG,MAAM,KAAK,GAAI,IAAmD,CAAC,KAAK,CAAC;AAEzE,MAAM,OAAO,WAAW;IAMpB,YAAY,cAAmB,EAAE,GAAS;QALjC,OAAE,G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
+ declare const _default: import("@celljs/core").ContainerModule;
2
2
  export default _default;
3
3
  //# sourceMappingURL=module.d.ts.map
@@ -1,4 +1,4 @@
1
1
  import './resolver';
2
- declare const _default: import("inversify").interfaces.ContainerModule;
2
+ declare const _default: import("@celljs/core").ContainerModule;
3
3
  export default _default;
4
4
  //# sourceMappingURL=module.d.ts.map
@@ -1,6 +1,6 @@
1
1
  export * from './pipe-manager';
2
2
  export * from './pipe-protocol';
3
3
  export * from './pipe-provider';
4
- export * from './pipe-transtorm';
4
+ export * from './type-conversion-pipe';
5
5
  export * from './validation-errors';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/pipe/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/pipe/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC"}
@@ -17,6 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./pipe-manager"), exports);
18
18
  __exportStar(require("./pipe-protocol"), exports);
19
19
  __exportStar(require("./pipe-provider"), exports);
20
- __exportStar(require("./pipe-transtorm"), exports);
20
+ __exportStar(require("./type-conversion-pipe"), exports);
21
21
  __exportStar(require("./validation-errors"), exports);
22
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/pipe/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,mDAAiC;AACjC,sDAAoC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/pipe/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,kDAAgC;AAChC,kDAAgC;AAChC,yDAAuC;AACvC,sDAAoC"}
@@ -0,0 +1,13 @@
1
+ import { ArgumentMetadata, PipeTransform } from './pipe-protocol';
2
+ /**
3
+ * Converts request data to a `String`, `Number`, `Boolean` or `Date` parameter as class-transformer did:
4
+ * `'5'` → `5`, `'abc'` → `NaN`, `'false'` → `true` (any non-empty string), arrays item by item;
5
+ * `null` and `undefined` stay. Parameters of other types get the data as it is; `@celljs/validation`
6
+ * turns it into instances of the parameter class and validates them.
7
+ */
8
+ export declare class TypeConversionPipe implements PipeTransform<any> {
9
+ readonly priority = 1000;
10
+ transform(value: any, { argType }: ArgumentMetadata): any;
11
+ protected convert(type: Function, value: unknown): unknown;
12
+ }
13
+ //# sourceMappingURL=type-conversion-pipe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-conversion-pipe.d.ts","sourceRoot":"","sources":["../../../src/common/pipe/type-conversion-pipe.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIlE;;;;;GAKG;AACH,qBACa,kBAAmB,YAAW,aAAa,CAAC,GAAG,CAAC;IAEzD,QAAQ,CAAC,QAAQ,QAAQ;IAEzB,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,EAAE,gBAAgB,GAAG,GAAG,CAKxD;IAED,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAWzD;CACJ"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TypeConversionPipe = void 0;
10
+ const core_1 = require("@celljs/core");
11
+ const pipe_protocol_1 = require("./pipe-protocol");
12
+ const TYPES = [String, Number, Boolean, Date];
13
+ /**
14
+ * Converts request data to a `String`, `Number`, `Boolean` or `Date` parameter as class-transformer did:
15
+ * `'5'` → `5`, `'abc'` → `NaN`, `'false'` → `true` (any non-empty string), arrays item by item;
16
+ * `null` and `undefined` stay. Parameters of other types get the data as it is; `@celljs/validation`
17
+ * turns it into instances of the parameter class and validates them.
18
+ */
19
+ let TypeConversionPipe = class TypeConversionPipe {
20
+ constructor() {
21
+ this.priority = 1000;
22
+ }
23
+ transform(value, { argType }) {
24
+ if (!argType || !TYPES.includes(argType) || (value !== null && typeof value === 'object' && !Array.isArray(value))) {
25
+ return value;
26
+ }
27
+ return this.convert(argType, value);
28
+ }
29
+ convert(type, value) {
30
+ if (value === null || value === undefined) {
31
+ return value;
32
+ }
33
+ if (Array.isArray(value)) {
34
+ return value.map(item => this.convert(type, item));
35
+ }
36
+ if (type === Date) {
37
+ return value instanceof Date ? value : new Date(value);
38
+ }
39
+ return type(value);
40
+ }
41
+ };
42
+ exports.TypeConversionPipe = TypeConversionPipe;
43
+ exports.TypeConversionPipe = TypeConversionPipe = __decorate([
44
+ (0, core_1.Component)(pipe_protocol_1.PipeTransform)
45
+ ], TypeConversionPipe);
46
+ //# sourceMappingURL=type-conversion-pipe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-conversion-pipe.js","sourceRoot":"","sources":["../../../src/common/pipe/type-conversion-pipe.ts"],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ACZ,kBAAkB,CAuB9B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type-conversion-pipe.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-conversion-pipe.spec.d.ts","sourceRoot":"","sources":["../../../src/common/pipe/type-conversion-pipe.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const bun_test_1 = require("bun:test");
4
+ const chai_1 = require("chai");
5
+ const node_http_1 = require("node:http");
6
+ const node_net_1 = require("node:net");
7
+ const type_conversion_pipe_1 = require("./type-conversion-pipe");
8
+ class CreateUser {
9
+ }
10
+ (0, bun_test_1.describe)('TypeConversionPipe', () => {
11
+ const pipe = new type_conversion_pipe_1.TypeConversionPipe();
12
+ (0, bun_test_1.it)('converts to primitive parameter types as class-transformer did', () => {
13
+ (0, chai_1.expect)(pipe.transform('5', { argType: Number })).to.equal(5);
14
+ (0, chai_1.expect)(pipe.transform('abc', { argType: Number })).to.be.NaN;
15
+ (0, chai_1.expect)(pipe.transform('', { argType: Number })).to.equal(0);
16
+ (0, chai_1.expect)(pipe.transform(['1', '2'], { argType: Number })).to.deep.equal([1, 2]);
17
+ (0, chai_1.expect)(pipe.transform(5, { argType: String })).to.equal('5');
18
+ (0, chai_1.expect)(pipe.transform('false', { argType: Boolean })).to.equal(true);
19
+ (0, chai_1.expect)(pipe.transform('', { argType: Boolean })).to.equal(false);
20
+ (0, chai_1.expect)(pipe.transform(undefined, { argType: Number })).to.equal(undefined);
21
+ (0, chai_1.expect)(pipe.transform(null, { argType: String })).to.equal(null);
22
+ (0, chai_1.expect)(pipe.transform('2020-01-01', { argType: Date }).toISOString()).to.equal('2020-01-01T00:00:00.000Z');
23
+ });
24
+ (0, bun_test_1.it)('passes everything else as it is', () => {
25
+ const data = { name: 'Tom' };
26
+ (0, chai_1.expect)(pipe.transform(data, { argType: CreateUser })).to.equal(data);
27
+ (0, chai_1.expect)(pipe.transform(data, { argType: Object })).to.equal(data);
28
+ (0, chai_1.expect)(pipe.transform(data, { argType: String })).to.equal(data);
29
+ (0, chai_1.expect)(pipe.transform('5', {})).to.equal('5');
30
+ const request = new node_http_1.IncomingMessage(new node_net_1.Socket());
31
+ const response = new node_http_1.ServerResponse(request);
32
+ (0, chai_1.expect)(pipe.transform(response, { argType: Object })).to.equal(response);
33
+ (0, chai_1.expect)(pipe.transform(request, { argType: String })).to.equal(request);
34
+ });
35
+ });
36
+ //# sourceMappingURL=type-conversion-pipe.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-conversion-pipe.spec.js","sourceRoot":"","sources":["../../../src/common/pipe/type-conversion-pipe.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,yCAA4D;AAC5D,uCAAkC;AAClC,iEAA4D;AAE5D,MAAM,UAAU;CAEf;AAED,IAAA,mBAAQ,EAAC,oBAAoB,EAAE,GAAG,EAAE;IAChC,MAAM,IAAI,GAAG,IAAI,yCAAkB,EAAE,CAAC;IAEtC,IAAA,aAAE,EAAC,gEAAgE,EAAE,GAAG,EAAE;QACtE,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7D,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC;QAC7D,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5D,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,EAA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C,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACrE,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjE,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjE,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,IAAI,2BAAe,CAAC,IAAI,iBAAM,EAAE,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,0BAAc,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACzE,IAAA,aAAM,EAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3E,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,6 +1,15 @@
1
1
  import { CustomError } from '@celljs/core';
2
- import { ValidationError } from 'class-validator';
2
+ /** What class-validator reports for one property (the part Cell reads; the rest is kept as it is). */
3
+ export interface ValidationError {
4
+ property: string;
5
+ value?: unknown;
6
+ constraints?: Record<string, string>;
7
+ children?: ValidationError[];
8
+ [key: string]: unknown;
9
+ }
10
+ /** Request data that failed validation; answers 400 with the errors as JSON (unless `detailedOutputDisabled`). */
3
11
  export declare class ValidationErrors extends CustomError {
4
- constructor(errors?: ValidationError[]);
12
+ readonly errors?: ValidationError[] | undefined;
13
+ constructor(errors?: ValidationError[] | undefined);
5
14
  }
6
15
  //# sourceMappingURL=validation-errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation-errors.d.ts","sourceRoot":"","sources":["../../../src/common/pipe/validation-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,qBAAa,gBAAiB,SAAQ,WAAW;IAE7C,YAAY,MAAM,CAAC,EAAE,eAAe,EAAE,EAErC;CAEJ"}
1
+ {"version":3,"file":"validation-errors.d.ts","sourceRoot":"","sources":["../../../src/common/pipe/validation-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,sGAAsG;AACtG,MAAM,WAAW,eAAe;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,kHAAkH;AAClH,qBAAa,gBAAiB,SAAQ,WAAW;IAEjC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE;IAA/C,YAAqB,MAAM,CAAC,EAAE,eAAe,EAAE,YAAA,EAE9C;CAEJ"}
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ValidationErrors = void 0;
4
4
  const core_1 = require("@celljs/core");
5
+ /** Request data that failed validation; answers 400 with the errors as JSON (unless `detailedOutputDisabled`). */
5
6
  class ValidationErrors extends core_1.CustomError {
6
7
  constructor(errors) {
7
8
  super(errors === undefined ? undefined : JSON.stringify(errors));
9
+ this.errors = errors;
8
10
  }
9
11
  }
10
12
  exports.ValidationErrors = ValidationErrors;
@@ -1 +1 @@
1
- {"version":3,"file":"validation-errors.js","sourceRoot":"","sources":["../../../src/common/pipe/validation-errors.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAG3C,sBAA8B,SAAQ,kBAAW;IAE7C,YAAY,MAA0B;QAClC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;CAEJ"}
1
+ {"version":3,"file":"validation-errors.js","sourceRoot":"","sources":["../../../src/common/pipe/validation-errors.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAW3C,kHAAkH;AAClH,sBAA8B,SAAQ,kBAAW;IAE7C,YAAqB,MAA0B;QAC3C,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;sBADhD,MAAM;IAE3B,CAAC;CAEJ"}
@@ -1,12 +1,10 @@
1
1
  import { Middleware } from '../middleware';
2
2
  import { Context } from '../context';
3
- import { Options } from 'body-parser';
4
- import { HandlerExecutionChain } from '../handler';
3
+ import { BodyOptions } from './body-protocol';
4
+ import { BodyParser } from './body-parser';
5
5
  export declare class BodyMiddleware implements Middleware {
6
- protected handlerExecutionChain: HandlerExecutionChain;
7
- protected readonly options: Options;
8
- /** The four parsers, made once: making them per request cost a noticeable share of each request. */
9
- protected parsers: Middleware[];
6
+ protected readonly options?: BodyOptions;
7
+ protected parser: BodyParser;
10
8
  protected init(): void;
11
9
  handle(ctx: Context, next: () => Promise<void>): Promise<void>;
12
10
  readonly priority: number;
@@ -1 +1 @@
1
- {"version":3,"file":"body-middleware.d.ts","sourceRoot":"","sources":["../../../src/node/body/body-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,UAAU,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAA+B,OAAO,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,qBACa,cAAe,YAAW,UAAU;IAG7C,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGvD,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAEpC,oGAAoG;IACpG,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC;IAGhC,SAAS,CAAC,IAAI,IAAI,IAAI,CAOrB;IAEK,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnE;IAED,QAAQ,CAAC,QAAQ,SAA4B;CAEhD"}
1
+ {"version":3,"file":"body-middleware.d.ts","sourceRoot":"","sources":["../../../src/node/body/body-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAA4B,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,qBACa,cAAe,YAAW,UAAU;IAG7C,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;IAEzC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;IAG7B,SAAS,CAAC,IAAI,IAAI,IAAI,CAErB;IAEK,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGnE;IAED,QAAQ,CAAC,QAAQ,SAA4B;CAEhD"}
@@ -12,30 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BodyMiddleware = void 0;
13
13
  const middleware_1 = require("../middleware");
14
14
  const core_1 = require("@celljs/core");
15
- const body_parser_1 = require("body-parser");
16
15
  const body_protocol_1 = require("./body-protocol");
17
- const handler_1 = require("../handler");
16
+ const body_parser_1 = require("./body-parser");
18
17
  let BodyMiddleware = class BodyMiddleware {
19
18
  constructor() {
20
19
  this.priority = body_protocol_1.BODY_MIDDLEWARE_PRIORITY;
21
20
  }
22
21
  init() {
23
- this.parsers = [
24
- (0, middleware_1.convertExpressMiddleware)((0, body_parser_1.json)({ ...this.options })),
25
- (0, middleware_1.convertExpressMiddleware)((0, body_parser_1.text)({ ...this.options })),
26
- (0, middleware_1.convertExpressMiddleware)((0, body_parser_1.raw)({ ...this.options })),
27
- (0, middleware_1.convertExpressMiddleware)((0, body_parser_1.urlencoded)({ ...this.options, ...{ extended: true } }))
28
- ];
22
+ this.parser = new body_parser_1.BodyParser(this.options);
29
23
  }
30
24
  async handle(ctx, next) {
31
- return this.handlerExecutionChain.execute(this.parsers, next);
25
+ await this.parser.parse(ctx.request, ctx.response);
26
+ return next();
32
27
  }
33
28
  };
34
29
  exports.BodyMiddleware = BodyMiddleware;
35
- __decorate([
36
- (0, core_1.Autowired)(handler_1.HandlerExecutionChain),
37
- __metadata("design:type", Object)
38
- ], BodyMiddleware.prototype, "handlerExecutionChain", void 0);
39
30
  __decorate([
40
31
  (0, core_1.Value)('cell.web.body'),
41
32
  __metadata("design:type", Object)
@@ -1 +1 @@
1
- {"version":3,"file":"body-middleware.js","sourceRoot":"","sources":["../../../src/node/body/body-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAqE;AAErE,uCAA0E;AAC1E,6CAAmE;AACnE,mDAA2D;AAC3D,wCAAm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CAAC,MAAM,GAAG,IAAI,wBAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAY,EAAE,IAAyB;QAChD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;QACnD,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC;CAIJ,CAAA;;AAhBsB;IADlB,IAAA,YAAK,EAAC,eAAe,CAAC;;+CACkB;AAK/B;IADT,IAAA,oBAAa,GAAE;;;;0CAGf;yBAVQ,cAAc;IAD1B,IAAA,gBAAS,EAAC,uBAAU,CAAC;GACT,cAAc,CAmB1B"}
@@ -2,18 +2,84 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const bun_test_1 = require("bun:test");
4
4
  const chai_1 = require("chai");
5
- const body_middleware_1 = require("./body-middleware");
6
- (0, bun_test_1.describe)('BodyMiddleware', () => {
7
- (0, bun_test_1.it)('makes its parsers once, not per request', async () => {
8
- const middleware = new body_middleware_1.BodyMiddleware();
9
- const seen = [];
10
- Object.assign(middleware, { options: { limit: '1kb' }, handlerExecutionChain: { execute: async (parsers) => { seen.push(parsers); } } });
11
- middleware.init();
12
- await middleware.handle({}, async () => undefined);
13
- await middleware.handle({}, async () => undefined);
14
- (0, chai_1.expect)(seen).to.have.length(2);
15
- (0, chai_1.expect)(seen[0]).to.have.length(4);
16
- (0, chai_1.expect)(seen[1]).to.equal(seen[0]);
5
+ const node_http_1 = require("node:http");
6
+ const node_zlib_1 = require("node:zlib");
7
+ const body_parser_1 = require("./body-parser");
8
+ const http_error_1 = require("../error/http-error");
9
+ /** A server that parses each request with the options in the x-options header and answers with what it got. */
10
+ let server;
11
+ let url;
12
+ (0, bun_test_1.beforeAll)(async () => {
13
+ server = (0, node_http_1.createServer)(async (req, res) => {
14
+ const options = JSON.parse(String(req.headers['x-options'] || '{}'));
15
+ try {
16
+ await new body_parser_1.BodyParser(options).parse(req);
17
+ const body = req.body;
18
+ res.setHeader('content-type', 'application/json');
19
+ res.end(JSON.stringify({ type: Buffer.isBuffer(body) ? 'buffer' : typeof body, body: Buffer.isBuffer(body) ? body.toString('hex') : body }));
20
+ }
21
+ catch (error) {
22
+ res.statusCode = error instanceof http_error_1.HttpError ? error.statusCode : 500;
23
+ res.end(String(error.message));
24
+ }
25
+ });
26
+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
27
+ url = `http://127.0.0.1:${server.address().port}/`;
28
+ });
29
+ (0, bun_test_1.afterAll)(() => server.close());
30
+ async function post(body, headers = {}, options = {}) {
31
+ const res = await fetch(url, { method: body === undefined ? 'GET' : 'POST', body, headers: { ...headers, 'x-options': JSON.stringify(options) } });
32
+ const text = await res.text();
33
+ return { status: res.status, ...(res.status === 200 ? JSON.parse(text) : { message: text }) };
34
+ }
35
+ (0, bun_test_1.describe)('BodyParser', () => {
36
+ (0, bun_test_1.it)('parses JSON', async () => {
37
+ (0, chai_1.expect)(await post('{"a":[1,2]}', { 'content-type': 'application/json' })).to.deep.equal({ status: 200, type: 'object', body: { a: [1, 2] } });
38
+ (0, chai_1.expect)(await post('', { 'content-type': 'application/json; charset=utf-8' })).to.deep.include({ status: 200, body: {} });
39
+ });
40
+ (0, bun_test_1.it)('refuses malformed and, when strict, non-object JSON', async () => {
41
+ (0, chai_1.expect)((await post('{a', { 'content-type': 'application/json' })).status).to.equal(400);
42
+ (0, chai_1.expect)((await post('"text"', { 'content-type': 'application/json' })).status).to.equal(400);
43
+ (0, chai_1.expect)(await post('"text"', { 'content-type': 'application/json' }, { strict: false })).to.deep.include({ status: 200, body: 'text' });
44
+ });
45
+ (0, bun_test_1.it)('parses text, raw and forms', async () => {
46
+ (0, chai_1.expect)(await post('héllo', { 'content-type': 'text/plain' })).to.deep.include({ type: 'string', body: 'héllo' });
47
+ (0, chai_1.expect)(await post(new Uint8Array([0xe9]), { 'content-type': 'text/plain; charset=latin1' })).to.deep.include({ body: 'é' });
48
+ (0, chai_1.expect)(await post(new Uint8Array([1, 2, 255]), { 'content-type': 'application/octet-stream' })).to.deep.include({ type: 'buffer', body: '0102ff' });
49
+ (0, chai_1.expect)(await post('a[b]=1&c=x+y', { 'content-type': 'application/x-www-form-urlencoded' })).to.deep.include({ body: { a: { b: '1' }, c: 'x y' } });
50
+ });
51
+ (0, bun_test_1.it)('gives {} to requests without a body or of another type', async () => {
52
+ (0, chai_1.expect)(await post(undefined)).to.deep.include({ status: 200, body: {} });
53
+ (0, chai_1.expect)(await post('<a/>', { 'content-type': 'application/xml' })).to.deep.include({ status: 200, body: {} });
54
+ });
55
+ (0, bun_test_1.it)('decompresses gzip unless inflate is off', async () => {
56
+ const body = new Uint8Array((0, node_zlib_1.gzipSync)('{"zipped":true}'));
57
+ (0, chai_1.expect)(await post(body, { 'content-type': 'application/json', 'content-encoding': 'gzip' })).to.deep.include({ body: { zipped: true } });
58
+ (0, chai_1.expect)((await post(body, { 'content-type': 'application/json', 'content-encoding': 'gzip' }, { inflate: false })).status).to.equal(415);
59
+ (0, chai_1.expect)((await post(body, { 'content-type': 'application/json', 'content-encoding': 'compress' })).status).to.equal(415);
60
+ (0, chai_1.expect)((await post('not gzip', { 'content-type': 'application/json', 'content-encoding': 'gzip' })).status).to.equal(400);
61
+ });
62
+ (0, bun_test_1.it)('refuses bodies over the limit, also after decompression', async () => {
63
+ (0, chai_1.expect)((await post('x'.repeat(2048), { 'content-type': 'text/plain' }, { limit: '1kb' })).status).to.equal(413);
64
+ (0, chai_1.expect)((await post(new Uint8Array((0, node_zlib_1.gzipSync)('x'.repeat(4096))), { 'content-type': 'text/plain', 'content-encoding': 'gzip' }, { limit: '1kb' })).status).to.equal(413);
65
+ (0, chai_1.expect)(await post('x'.repeat(1024), { 'content-type': 'text/plain' }, { limit: '1kb' })).to.deep.include({ status: 200 });
66
+ });
67
+ (0, bun_test_1.it)('refuses unsupported charsets and too many form parameters', async () => {
68
+ (0, chai_1.expect)((await post('{}', { 'content-type': 'application/json; charset=latin1' })).status).to.equal(415);
69
+ (0, chai_1.expect)((await post('a=1', { 'content-type': 'application/x-www-form-urlencoded; charset=latin1' })).status).to.equal(415);
70
+ (0, chai_1.expect)((await post('a=1&b=2&c=3', { 'content-type': 'application/x-www-form-urlencoded' }, { parameterLimit: 2 })).status).to.equal(413);
71
+ });
72
+ (0, bun_test_1.it)('reads sizes', () => {
73
+ (0, chai_1.expect)((0, body_parser_1.parseBytes)('100kb')).to.equal(102400);
74
+ (0, chai_1.expect)((0, body_parser_1.parseBytes)('5mb')).to.equal(5 * 1024 * 1024);
75
+ (0, chai_1.expect)((0, body_parser_1.parseBytes)('1.5KB')).to.equal(1536);
76
+ (0, chai_1.expect)((0, body_parser_1.parseBytes)(10)).to.equal(10);
77
+ (0, chai_1.expect)(() => (0, body_parser_1.parseBytes)('lots')).to.throw(TypeError);
78
+ });
79
+ (0, bun_test_1.it)('leaves a body that was already read', async () => {
80
+ const request = { _body: true, body: 'kept', headers: { 'content-length': '3', 'content-type': 'text/plain' } };
81
+ await new body_parser_1.BodyParser().parse(request);
82
+ (0, chai_1.expect)(request.body).to.equal('kept');
17
83
  });
18
84
  });
19
85
  //# sourceMappingURL=body-middleware.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"body-middleware.spec.js","sourceRoot":"","sources":["../../../src/node/body/body-middleware.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,uDAAmD;AAEnD,IAAA,mBAAQ,EAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,IAAA,aAAE,EAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACrD,MAAM,UAAU,GAAG,IAAI,gCAAc,EAAE,CAAC;QACxC,MAAM,IAAI,GAAc,EAAE,CAAC;QAC3B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,qBAAqB,EAAE,EAA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AAU,EAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAA,aAAM,EAAC,IAAA,wBAAU,EAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACpC,IAAA,aAAM,EAAC,GAAG,EAAE,CAAC,IAAA,wBAAU,EAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACjD,MAAM,OAAO,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,gBAAgB,EAAE,GAAG,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,CAAC;QAChH,MAAM,IAAI,wBAAU,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACtC,IAAA,aAAM,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { Readable } from 'stream';
2
+ import { BodyOptions } from './body-protocol';
3
+ type BodyType = 'json' | 'text' | 'raw' | 'urlencoded';
4
+ /** `'100kb'` → 102400. */
5
+ export declare function parseBytes(value: number | string): number;
6
+ /**
7
+ * Reads the body of a request into `request.body`: JSON (`application/json`), text (`text/plain`), a Buffer
8
+ * (`application/octet-stream`) or a form (`application/x-www-form-urlencoded`, nested with brackets). Other
9
+ * requests get `{}`. Failures are {@link HttpError}s: 400 for a malformed body, 413 for a large one, 415 for
10
+ * an unsupported charset or encoding.
11
+ */
12
+ export declare class BodyParser {
13
+ protected readonly options: BodyOptions;
14
+ protected readonly limit: number;
15
+ protected readonly inflate: boolean;
16
+ protected readonly strict: boolean;
17
+ protected readonly parameterLimit: number;
18
+ protected readonly depth: number;
19
+ constructor(options?: BodyOptions);
20
+ parse(request: any, response?: any): Promise<void>;
21
+ protected contentType(header: string | undefined): {
22
+ type: string;
23
+ charset?: string;
24
+ };
25
+ protected charset(type: BodyType, charset?: string): string;
26
+ protected isKnownCharset(charset: string): boolean;
27
+ protected convert(type: BodyType, body: Buffer, charset: string): unknown;
28
+ protected decoder(request: Readable, encoding: string): Readable;
29
+ /** The body, decompressed, at most `limit` bytes. */
30
+ protected read(request: Readable, headers: Record<string, any>): Promise<Buffer>;
31
+ }
32
+ export {};
33
+ //# sourceMappingURL=body-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-parser.d.ts","sourceRoot":"","sources":["../../../src/node/body/body-parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAK9C,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,YAAY,CAAC;AASvD,0BAA0B;AAC1B,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CASzD;AAED;;;;;GAKG;AACH,qBAAa,UAAU;IAQP,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW;IANnD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IACpC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACnC,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAC1C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEjC,YAA+B,OAAO,GAAE,WAAgB,EAMvD;IAEK,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,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