exisjs 0.7.5 → 0.7.7

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 (321) hide show
  1. package/dist/cli/commands/build.d.ts.map +1 -1
  2. package/dist/cli/commands/build.js +12 -0
  3. package/dist/cli/commands/build.js.map +1 -1
  4. package/dist/cli/commands/clean.d.ts +5 -0
  5. package/dist/cli/commands/clean.d.ts.map +1 -0
  6. package/dist/cli/commands/clean.js +30 -0
  7. package/dist/cli/commands/clean.js.map +1 -0
  8. package/dist/cli/commands/dev.d.ts.map +1 -1
  9. package/dist/cli/commands/dev.js +171 -86
  10. package/dist/cli/commands/dev.js.map +1 -1
  11. package/dist/cli/commands/generate.d.ts +6 -1
  12. package/dist/cli/commands/generate.d.ts.map +1 -1
  13. package/dist/cli/commands/generate.js +57 -2
  14. package/dist/cli/commands/generate.js.map +1 -1
  15. package/dist/cli/commands/start.d.ts.map +1 -1
  16. package/dist/cli/commands/start.js +54 -16
  17. package/dist/cli/commands/start.js.map +1 -1
  18. package/dist/cli/index.js +26 -3
  19. package/dist/cli/index.js.map +1 -1
  20. package/dist/cli/manifest.d.ts +1 -0
  21. package/dist/cli/manifest.d.ts.map +1 -1
  22. package/dist/cli/manifest.js +264 -33
  23. package/dist/cli/manifest.js.map +1 -1
  24. package/dist/cli/resolve-aliases.d.ts +1 -1
  25. package/dist/cli/resolve-aliases.d.ts.map +1 -1
  26. package/dist/cli/resolve-aliases.js +30 -13
  27. package/dist/cli/resolve-aliases.js.map +1 -1
  28. package/dist/config/config.d.ts +3 -1
  29. package/dist/config/config.d.ts.map +1 -1
  30. package/dist/config/config.js +9 -0
  31. package/dist/config/config.js.map +1 -1
  32. package/dist/config/types.d.ts +6 -0
  33. package/dist/config/types.d.ts.map +1 -1
  34. package/dist/cron/expressions.d.ts +45 -0
  35. package/dist/cron/expressions.d.ts.map +1 -0
  36. package/dist/cron/expressions.js +87 -0
  37. package/dist/cron/expressions.js.map +1 -0
  38. package/dist/cron/index.d.ts +6 -0
  39. package/dist/cron/index.d.ts.map +1 -0
  40. package/dist/cron/index.js +22 -0
  41. package/dist/cron/index.js.map +1 -0
  42. package/dist/cron/job.d.ts +50 -0
  43. package/dist/cron/job.d.ts.map +1 -0
  44. package/dist/cron/job.js +247 -0
  45. package/dist/cron/job.js.map +1 -0
  46. package/dist/cron/manager.d.ts +105 -0
  47. package/dist/cron/manager.d.ts.map +1 -0
  48. package/dist/cron/manager.js +245 -0
  49. package/dist/cron/manager.js.map +1 -0
  50. package/dist/cron/parser.d.ts +22 -0
  51. package/dist/cron/parser.d.ts.map +1 -0
  52. package/dist/cron/parser.js +269 -0
  53. package/dist/cron/parser.js.map +1 -0
  54. package/dist/cron/types.d.ts +76 -0
  55. package/dist/cron/types.d.ts.map +1 -0
  56. package/dist/cron/types.js +3 -0
  57. package/dist/cron/types.js.map +1 -0
  58. package/dist/decorators/constants.d.ts +2 -0
  59. package/dist/decorators/constants.d.ts.map +1 -1
  60. package/dist/decorators/constants.js +3 -1
  61. package/dist/decorators/constants.js.map +1 -1
  62. package/dist/decorators/core.d.ts +29 -11
  63. package/dist/decorators/core.d.ts.map +1 -1
  64. package/dist/decorators/core.js +49 -11
  65. package/dist/decorators/core.js.map +1 -1
  66. package/dist/decorators/cron.d.ts +57 -0
  67. package/dist/decorators/cron.d.ts.map +1 -0
  68. package/dist/decorators/cron.js +143 -0
  69. package/dist/decorators/cron.js.map +1 -0
  70. package/dist/decorators/index.d.ts +2 -0
  71. package/dist/decorators/index.d.ts.map +1 -1
  72. package/dist/decorators/index.js +2 -0
  73. package/dist/decorators/index.js.map +1 -1
  74. package/dist/decorators/middleware.d.ts +65 -2
  75. package/dist/decorators/middleware.d.ts.map +1 -1
  76. package/dist/decorators/middleware.js +148 -62
  77. package/dist/decorators/middleware.js.map +1 -1
  78. package/dist/decorators/params.d.ts +102 -2
  79. package/dist/decorators/params.d.ts.map +1 -1
  80. package/dist/decorators/params.js +105 -3
  81. package/dist/decorators/params.js.map +1 -1
  82. package/dist/decorators/response.d.ts.map +1 -1
  83. package/dist/decorators/response.js +32 -22
  84. package/dist/decorators/response.js.map +1 -1
  85. package/dist/decorators/routing.d.ts +81 -16
  86. package/dist/decorators/routing.d.ts.map +1 -1
  87. package/dist/decorators/routing.js +81 -16
  88. package/dist/decorators/routing.js.map +1 -1
  89. package/dist/di/container.d.ts.map +1 -1
  90. package/dist/di/container.js +6 -1
  91. package/dist/di/container.js.map +1 -1
  92. package/dist/docs/content/cli/commands.mdx +1 -1
  93. package/dist/docs/content/controllers.mdx +127 -10
  94. package/dist/docs/content/cron.mdx +196 -0
  95. package/dist/docs/content/decorators.mdx +22 -4
  96. package/dist/docs/content/errors.mdx +58 -9
  97. package/dist/docs/content/introduction.mdx +7 -7
  98. package/dist/docs/content/middleware.mdx +269 -6
  99. package/dist/docs/content/requests.mdx +180 -6
  100. package/dist/docs/content/responses.mdx +283 -32
  101. package/dist/docs/content/routing.mdx +46 -0
  102. package/dist/docs/content/swagger.mdx +228 -0
  103. package/dist/docs/content/validation.mdx +190 -11
  104. package/dist/docs/reference/context.mdx +11 -0
  105. package/dist/docs/reference/cron.mdx +300 -0
  106. package/dist/docs/reference/decorators.mdx +22 -4
  107. package/dist/docs/reference/error.mdx +88 -0
  108. package/dist/docs/reference/logger.mdx +175 -43
  109. package/dist/docs/reference/middleware.mdx +31 -0
  110. package/dist/docs/reference/router.mdx +22 -0
  111. package/dist/docs/reference/swagger.mdx +143 -0
  112. package/dist/docs/reference/validator.mdx +83 -23
  113. package/dist/error/errors.d.ts.map +1 -1
  114. package/dist/error/errors.js +95 -43
  115. package/dist/error/errors.js.map +1 -1
  116. package/dist/error/index.d.ts +1 -0
  117. package/dist/error/index.d.ts.map +1 -1
  118. package/dist/error/index.js +11 -1
  119. package/dist/error/index.js.map +1 -1
  120. package/dist/error/overlay.d.ts +42 -0
  121. package/dist/error/overlay.d.ts.map +1 -0
  122. package/dist/error/overlay.js +306 -0
  123. package/dist/error/overlay.js.map +1 -0
  124. package/dist/index.d.ts +1 -0
  125. package/dist/index.d.ts.map +1 -1
  126. package/dist/index.js +22 -1
  127. package/dist/index.js.map +1 -1
  128. package/dist/lib/start-server.js +33 -7
  129. package/dist/lib/start-server.js.map +1 -1
  130. package/dist/logger/index.d.ts +1 -1
  131. package/dist/logger/index.d.ts.map +1 -1
  132. package/dist/logger/index.js +9 -1
  133. package/dist/logger/index.js.map +1 -1
  134. package/dist/middleware/guard.d.ts +2 -2
  135. package/dist/middleware/guard.d.ts.map +1 -1
  136. package/dist/middleware/guard.js.map +1 -1
  137. package/dist/middleware/ip-filter.d.ts +1 -0
  138. package/dist/middleware/ip-filter.d.ts.map +1 -1
  139. package/dist/middleware/ip-filter.js +2 -0
  140. package/dist/middleware/ip-filter.js.map +1 -1
  141. package/dist/middleware/middleware.d.ts +2 -2
  142. package/dist/middleware/middleware.d.ts.map +1 -1
  143. package/dist/middleware/middleware.js +20 -2
  144. package/dist/middleware/middleware.js.map +1 -1
  145. package/dist/middleware/security.d.ts +43 -1
  146. package/dist/middleware/security.d.ts.map +1 -1
  147. package/dist/middleware/security.js +101 -0
  148. package/dist/middleware/security.js.map +1 -1
  149. package/dist/response/index.d.ts +229 -6
  150. package/dist/response/index.d.ts.map +1 -1
  151. package/dist/response/index.js +272 -2
  152. package/dist/response/index.js.map +1 -1
  153. package/dist/router/boundary.d.ts +41 -11
  154. package/dist/router/boundary.d.ts.map +1 -1
  155. package/dist/router/boundary.js +24 -2
  156. package/dist/router/boundary.js.map +1 -1
  157. package/dist/router/controller-registrar.d.ts.map +1 -1
  158. package/dist/router/controller-registrar.js +108 -4
  159. package/dist/router/controller-registrar.js.map +1 -1
  160. package/dist/router/index.d.ts +2 -2
  161. package/dist/router/index.d.ts.map +1 -1
  162. package/dist/router/index.js +2 -1
  163. package/dist/router/index.js.map +1 -1
  164. package/dist/router/route-builder.d.ts +262 -65
  165. package/dist/router/route-builder.d.ts.map +1 -1
  166. package/dist/router/route-builder.js +181 -23
  167. package/dist/router/route-builder.js.map +1 -1
  168. package/dist/router/route-scanner.d.ts +6 -0
  169. package/dist/router/route-scanner.d.ts.map +1 -1
  170. package/dist/router/route-scanner.js +71 -792
  171. package/dist/router/route-scanner.js.map +1 -1
  172. package/dist/router/router.d.ts.map +1 -1
  173. package/dist/router/router.js +62 -17
  174. package/dist/router/router.js.map +1 -1
  175. package/dist/router/scanner/boundary-loader.d.ts +18 -0
  176. package/dist/router/scanner/boundary-loader.d.ts.map +1 -0
  177. package/dist/router/scanner/boundary-loader.js +539 -0
  178. package/dist/router/scanner/boundary-loader.js.map +1 -0
  179. package/dist/router/scanner/cron-mounter.d.ts +15 -0
  180. package/dist/router/scanner/cron-mounter.d.ts.map +1 -0
  181. package/dist/router/scanner/cron-mounter.js +216 -0
  182. package/dist/router/scanner/cron-mounter.js.map +1 -0
  183. package/dist/router/scanner/error-mounter.d.ts +14 -0
  184. package/dist/router/scanner/error-mounter.d.ts.map +1 -0
  185. package/dist/router/scanner/error-mounter.js +200 -0
  186. package/dist/router/scanner/error-mounter.js.map +1 -0
  187. package/dist/router/scanner/fs-scanner.d.ts +25 -0
  188. package/dist/router/scanner/fs-scanner.d.ts.map +1 -0
  189. package/dist/router/scanner/fs-scanner.js +115 -0
  190. package/dist/router/scanner/fs-scanner.js.map +1 -0
  191. package/dist/router/scanner/functional-compiler.d.ts +9 -0
  192. package/dist/router/scanner/functional-compiler.d.ts.map +1 -0
  193. package/dist/router/scanner/functional-compiler.js +233 -0
  194. package/dist/router/scanner/functional-compiler.js.map +1 -0
  195. package/dist/router/scanner/index.d.ts +9 -0
  196. package/dist/router/scanner/index.d.ts.map +1 -0
  197. package/dist/router/scanner/index.js +19 -0
  198. package/dist/router/scanner/index.js.map +1 -0
  199. package/dist/router/types.d.ts +23 -0
  200. package/dist/router/types.d.ts.map +1 -1
  201. package/dist/server/app.d.ts +3 -0
  202. package/dist/server/app.d.ts.map +1 -1
  203. package/dist/server/app.js +13 -0
  204. package/dist/server/app.js.map +1 -1
  205. package/dist/server/bootstrapper.d.ts.map +1 -1
  206. package/dist/server/bootstrapper.js +91 -30
  207. package/dist/server/bootstrapper.js.map +1 -1
  208. package/dist/server/cluster.d.ts.map +1 -1
  209. package/dist/server/cluster.js +13 -2
  210. package/dist/server/cluster.js.map +1 -1
  211. package/dist/server/context.d.ts +8 -0
  212. package/dist/server/context.d.ts.map +1 -1
  213. package/dist/server/context.js +50 -6
  214. package/dist/server/context.js.map +1 -1
  215. package/dist/server/helpers/body-parser.d.ts +18 -0
  216. package/dist/server/helpers/body-parser.d.ts.map +1 -0
  217. package/dist/server/helpers/body-parser.js +246 -0
  218. package/dist/server/helpers/body-parser.js.map +1 -0
  219. package/dist/server/helpers/cookie.d.ts +4 -0
  220. package/dist/server/helpers/cookie.d.ts.map +1 -0
  221. package/dist/server/helpers/cookie.js +61 -0
  222. package/dist/server/helpers/cookie.js.map +1 -0
  223. package/dist/server/helpers/etag.d.ts +3 -0
  224. package/dist/server/helpers/etag.d.ts.map +1 -0
  225. package/dist/server/helpers/etag.js +25 -0
  226. package/dist/server/helpers/etag.js.map +1 -0
  227. package/dist/server/helpers/index.d.ts +6 -0
  228. package/dist/server/helpers/index.d.ts.map +1 -0
  229. package/dist/server/helpers/index.js +21 -0
  230. package/dist/server/helpers/index.js.map +1 -0
  231. package/dist/server/helpers/ip.d.ts +9 -0
  232. package/dist/server/helpers/ip.d.ts.map +1 -0
  233. package/dist/server/helpers/ip.js +62 -0
  234. package/dist/server/helpers/ip.js.map +1 -0
  235. package/dist/server/helpers/stream.d.ts +4 -0
  236. package/dist/server/helpers/stream.d.ts.map +1 -0
  237. package/dist/server/helpers/stream.js +193 -0
  238. package/dist/server/helpers/stream.js.map +1 -0
  239. package/dist/server/lifecycle.d.ts +22 -0
  240. package/dist/server/lifecycle.d.ts.map +1 -0
  241. package/dist/server/lifecycle.js +106 -0
  242. package/dist/server/lifecycle.js.map +1 -0
  243. package/dist/server/request-handler.d.ts +1 -0
  244. package/dist/server/request-handler.d.ts.map +1 -1
  245. package/dist/server/request-handler.js +27 -17
  246. package/dist/server/request-handler.js.map +1 -1
  247. package/dist/server/request.d.ts +1 -139
  248. package/dist/server/request.d.ts.map +1 -1
  249. package/dist/server/request.js +37 -433
  250. package/dist/server/request.js.map +1 -1
  251. package/dist/server/response.d.ts +112 -156
  252. package/dist/server/response.d.ts.map +1 -1
  253. package/dist/server/response.js +129 -279
  254. package/dist/server/response.js.map +1 -1
  255. package/dist/swagger/decorators.d.ts +81 -0
  256. package/dist/swagger/decorators.d.ts.map +1 -0
  257. package/dist/swagger/decorators.js +172 -0
  258. package/dist/swagger/decorators.js.map +1 -0
  259. package/dist/swagger/generator.d.ts +19 -0
  260. package/dist/swagger/generator.d.ts.map +1 -0
  261. package/dist/swagger/generator.js +344 -0
  262. package/dist/swagger/generator.js.map +1 -0
  263. package/dist/swagger/index.d.ts +31 -0
  264. package/dist/swagger/index.d.ts.map +1 -0
  265. package/dist/swagger/index.js +53 -0
  266. package/dist/swagger/index.js.map +1 -0
  267. package/dist/swagger/mounter.d.ts +7 -0
  268. package/dist/swagger/mounter.d.ts.map +1 -0
  269. package/dist/swagger/mounter.js +56 -0
  270. package/dist/swagger/mounter.js.map +1 -0
  271. package/dist/swagger/types.d.ts +190 -0
  272. package/dist/swagger/types.d.ts.map +1 -0
  273. package/dist/swagger/types.js +3 -0
  274. package/dist/swagger/types.js.map +1 -0
  275. package/dist/swagger/ui.d.ts +6 -0
  276. package/dist/swagger/ui.d.ts.map +1 -0
  277. package/dist/swagger/ui.js +118 -0
  278. package/dist/swagger/ui.js.map +1 -0
  279. package/dist/testing/index.d.ts.map +1 -1
  280. package/dist/testing/index.js +6 -1
  281. package/dist/testing/index.js.map +1 -1
  282. package/dist/testing/mocks.d.ts.map +1 -1
  283. package/dist/testing/mocks.js +15 -3
  284. package/dist/testing/mocks.js.map +1 -1
  285. package/dist/utils/logger.d.ts +8 -0
  286. package/dist/utils/logger.d.ts.map +1 -1
  287. package/dist/utils/logger.js +184 -1
  288. package/dist/utils/logger.js.map +1 -1
  289. package/dist/validator/builder.d.ts +223 -0
  290. package/dist/validator/builder.d.ts.map +1 -0
  291. package/dist/validator/builder.js +517 -0
  292. package/dist/validator/builder.js.map +1 -0
  293. package/dist/validator/engine.d.ts +19 -0
  294. package/dist/validator/engine.d.ts.map +1 -0
  295. package/dist/validator/engine.js +568 -0
  296. package/dist/validator/engine.js.map +1 -0
  297. package/dist/validator/error.d.ts +12 -0
  298. package/dist/validator/error.d.ts.map +1 -0
  299. package/dist/validator/error.js +63 -0
  300. package/dist/validator/error.js.map +1 -0
  301. package/dist/validator/pagination.d.ts +40 -0
  302. package/dist/validator/pagination.d.ts.map +1 -0
  303. package/dist/validator/pagination.js +60 -0
  304. package/dist/validator/pagination.js.map +1 -0
  305. package/dist/validator/tex-types.d.ts +2 -1
  306. package/dist/validator/tex-types.d.ts.map +1 -1
  307. package/dist/validator/tex-types.js +2 -1
  308. package/dist/validator/tex-types.js.map +1 -1
  309. package/dist/validator/tex.d.ts +6 -142
  310. package/dist/validator/tex.d.ts.map +1 -1
  311. package/dist/validator/tex.js +14 -733
  312. package/dist/validator/tex.js.map +1 -1
  313. package/dist/validator/types.d.ts +83 -0
  314. package/dist/validator/types.d.ts.map +1 -0
  315. package/dist/validator/types.js +3 -0
  316. package/dist/validator/types.js.map +1 -0
  317. package/package.json +8 -4
  318. package/dist/dev/error-overlay.d.ts +0 -3
  319. package/dist/dev/error-overlay.d.ts.map +0 -1
  320. package/dist/dev/error-overlay.js +0 -118
  321. package/dist/dev/error-overlay.js.map +0 -1
@@ -1,736 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tex = exports.TexEngine = exports.ValidatorError = exports.TexBuilder = void 0;
4
- exports.paginate = paginate;
5
- exports.getPaginationSkip = getPaginationSkip;
6
- const rs_1 = require("@exisjs/rs");
7
- const tex_types_1 = require("./tex-types");
8
- class TexBuilder {
9
- string(opts) {
10
- let base = 'string';
11
- if (opts?.optional)
12
- base += '?';
13
- if (opts?.nullable)
14
- base += ' | nullable';
15
- if (opts?.nullish)
16
- base += ' | nullish';
17
- if (opts?.min !== undefined)
18
- base += ` | min:${opts.min}`;
19
- if (opts?.max !== undefined)
20
- base += ` | max:${opts.max}`;
21
- if (opts?.trim)
22
- base += ' | trim';
23
- if (opts?.collapseWhitespace)
24
- base += ' | collapseWhitespace';
25
- if (opts?.toLowerCase)
26
- base += ' | lowercase';
27
- if (opts?.toUpperCase)
28
- base += ' | uppercase';
29
- if (opts?.escapeHtml)
30
- base += ' | escapeHtml';
31
- if (opts?.stripHtml)
32
- base += ' | stripHtml';
33
- if (opts?.slugify)
34
- base += ' | slugify';
35
- if (opts?.mask)
36
- base += ' | mask';
37
- if (opts?.preventSql)
38
- base += ' | preventSql';
39
- if (opts?.preventTraversal)
40
- base += ' | preventTraversal';
41
- return new tex_types_1.TexType(base);
42
- }
43
- number(opts) {
44
- let base = 'number';
45
- if (opts?.optional)
46
- base += '?';
47
- if (opts?.nullable)
48
- base += ' | nullable';
49
- if (opts?.nullish)
50
- base += ' | nullish';
51
- if (opts?.coerce)
52
- base += ' | coerce';
53
- if (opts?.min !== undefined)
54
- base += ` | min:${opts.min}`;
55
- if (opts?.max !== undefined)
56
- base += ` | max:${opts.max}`;
57
- if (opts?.default !== undefined)
58
- base += ` | default:${opts.default}`;
59
- return new tex_types_1.TexType(base);
60
- }
61
- boolean(opts) {
62
- let base = 'boolean';
63
- if (opts?.optional)
64
- base += '?';
65
- if (opts?.nullable)
66
- base += ' | nullable';
67
- if (opts?.nullish)
68
- base += ' | nullish';
69
- if (opts?.coerce)
70
- base += ' | coerce';
71
- return new tex_types_1.TexType(base);
72
- }
73
- email(opts) {
74
- let base = 'email';
75
- if (opts?.optional)
76
- base += '?';
77
- if (opts?.nullable)
78
- base += ' | nullable';
79
- if (opts?.nullish)
80
- base += ' | nullish';
81
- if (opts?.trim)
82
- base += ' | trim';
83
- if (opts?.toLowerCase)
84
- base += ' | lowercase';
85
- if (opts?.mask)
86
- base += ' | mask';
87
- return new tex_types_1.TexType(base);
88
- }
89
- uuid(opts) {
90
- let base = 'uuid';
91
- if (opts?.optional)
92
- base += '?';
93
- if (opts?.nullable)
94
- base += ' | nullable';
95
- if (opts?.nullish)
96
- base += ' | nullish';
97
- if (opts?.version)
98
- base += ` | version:${opts.version}`;
99
- return new tex_types_1.TexType(base);
100
- }
101
- cuid(opts) {
102
- let base = 'cuid';
103
- if (opts?.optional)
104
- base += '?';
105
- if (opts?.nullable)
106
- base += ' | nullable';
107
- if (opts?.nullish)
108
- base += ' | nullish';
109
- return new tex_types_1.TexType(base);
110
- }
111
- creditCard(opts) {
112
- let base = 'creditcard';
113
- if (opts?.optional)
114
- base += '?';
115
- if (opts?.nullable)
116
- base += ' | nullable';
117
- if (opts?.nullish)
118
- base += ' | nullish';
119
- if (opts?.mask)
120
- base += ' | mask';
121
- return new tex_types_1.TexType(base);
122
- }
123
- password(opts) {
124
- let base = 'password';
125
- if (opts?.optional)
126
- base += '?';
127
- if (opts?.nullable)
128
- base += ' | nullable';
129
- if (opts?.nullish)
130
- base += ' | nullish';
131
- if (opts?.min !== undefined)
132
- base += ` | min:${opts.min}`;
133
- if (opts?.max !== undefined)
134
- base += ` | max:${opts.max}`;
135
- if (opts?.requireNumbers)
136
- base += ' | requireNumbers';
137
- if (opts?.requireSymbols)
138
- base += ' | requireSymbols';
139
- if (opts?.requireUppercase)
140
- base += ' | requireUppercase';
141
- if (opts?.requireLowercase)
142
- base += ' | requireLowercase';
143
- return new tex_types_1.TexType(base);
144
- }
145
- array(schema, opts) {
146
- let resolvedItem = schema;
147
- if (typeof schema === 'object' &&
148
- schema !== null &&
149
- !(schema instanceof tex_types_1.TexType) &&
150
- !(schema instanceof TexEngine)) {
151
- resolvedItem = this.object(schema);
152
- }
153
- const itemSchema = resolvedItem instanceof TexEngine
154
- ? `object<${JSON.stringify(resolvedItem.getCompiledSchema())}>`
155
- : resolvedItem instanceof tex_types_1.TexType
156
- ? resolvedItem._raw
157
- : resolvedItem;
158
- let base = `array<${itemSchema}>`;
159
- if (opts?.optional)
160
- base += '?';
161
- if (opts?.nullable)
162
- base += ' | nullable';
163
- if (opts?.nullish)
164
- base += ' | nullish';
165
- if (opts?.min !== undefined)
166
- base += ` | min:${opts.min}`;
167
- if (opts?.max !== undefined)
168
- base += ` | max:${opts.max}`;
169
- if (opts?.dedupe)
170
- base += ' | dedupe';
171
- if (opts?.coerce)
172
- base += ' | coerce';
173
- const res = new tex_types_1.TexType(base);
174
- res._item = resolvedItem;
175
- return res;
176
- }
177
- enum(values, opts) {
178
- let base = `enum:${values.join(',')}`;
179
- if (opts?.optional)
180
- base += '?';
181
- if (opts?.nullable)
182
- base += ' | nullable';
183
- if (opts?.nullish)
184
- base += ' | nullish';
185
- if (opts?.default)
186
- base += ` | default:${opts.default}`;
187
- return new tex_types_1.TexType(base);
188
- }
189
- literal(value, opts) {
190
- let base = `literal:${value}`;
191
- if (opts?.optional)
192
- base += '?';
193
- if (opts?.nullable)
194
- base += ' | nullable';
195
- if (opts?.nullish)
196
- base += ' | nullish';
197
- return new tex_types_1.TexType(base);
198
- }
199
- union(schemas, opts) {
200
- const items = schemas.map((s) => (s instanceof tex_types_1.TexType ? s._raw : s));
201
- let base = items.join(' || ');
202
- if (opts?.optional)
203
- base = `(${base})?`;
204
- if (opts?.nullable)
205
- base += ' | nullable';
206
- if (opts?.nullish)
207
- base += ' | nullish';
208
- return new tex_types_1.TexType(base);
209
- }
210
- date(opts) {
211
- let base = 'date';
212
- if (opts?.optional)
213
- base += '?';
214
- if (opts?.nullable)
215
- base += ' | nullable';
216
- if (opts?.nullish)
217
- base += ' | nullish';
218
- if (opts?.coerce)
219
- base += ' | coerce';
220
- if (opts?.minDate)
221
- base += ` | minDate:${opts.minDate}`;
222
- if (opts?.maxDate)
223
- base += ` | maxDate:${opts.maxDate}`;
224
- return new tex_types_1.TexType(base);
225
- }
226
- record(schema, opts) {
227
- const itemSchema = schema instanceof tex_types_1.TexType ? schema._raw : schema;
228
- let base = `record<${itemSchema}>`;
229
- if (opts?.optional)
230
- base += '?';
231
- if (opts?.nullable)
232
- base += ' | nullable';
233
- if (opts?.nullish)
234
- base += ' | nullish';
235
- return new tex_types_1.TexType(base);
236
- }
237
- any(opts) {
238
- let base = 'any';
239
- if (opts?.optional)
240
- base += '?';
241
- if (opts?.nullable)
242
- base += ' | nullable';
243
- if (opts?.nullish)
244
- base += ' | nullish';
245
- return new tex_types_1.TexType(base);
246
- }
247
- file(opts) {
248
- let base = 'file';
249
- if (opts?.optional)
250
- base += '?';
251
- if (opts?.nullable)
252
- base += ' | nullable';
253
- if (opts?.nullish)
254
- base += ' | nullish';
255
- if (opts?.maxSize)
256
- base += ` | maxSize:${opts.maxSize}`;
257
- if (opts?.mimeTypes)
258
- base += ` | mimeTypes:${opts.mimeTypes.join(',')}`;
259
- return new tex_types_1.TexType(base);
260
- }
261
- object(schema, opts) {
262
- const compiledSchema = {};
263
- for (const [key, value] of Object.entries(schema)) {
264
- if (value instanceof TexEngine) {
265
- compiledSchema[key] =
266
- `object<${JSON.stringify(value.getCompiledSchema())}>`;
267
- }
268
- else if (value instanceof tex_types_1.TexType) {
269
- compiledSchema[key] = value._raw;
270
- }
271
- else {
272
- compiledSchema[key] = value;
273
- }
274
- }
275
- return new TexEngine(compiledSchema, schema, opts?.strict);
276
- }
277
- pagination(options) {
278
- const defaultLimit = options?.defaultLimit ?? 10;
279
- const maxLimit = options?.maxLimit ?? 100;
280
- return this.object({
281
- page: this.number({ optional: true, coerce: true, min: 1, default: 1 }),
282
- limit: this.number({
283
- optional: true,
284
- coerce: true,
285
- min: 1,
286
- max: maxLimit,
287
- default: defaultLimit,
288
- }),
289
- sort: this.string({ optional: true, trim: true }),
290
- order: this.enum(['asc', 'desc'], { optional: true }),
291
- });
292
- }
293
- }
294
- exports.TexBuilder = TexBuilder;
295
- class ValidatorError extends Error {
296
- constructor(errors) {
297
- super('Validation Error: ' +
298
- errors.map((e) => `${e.path}: ${e.message}`).join(', '));
299
- this.errors = errors;
300
- this.name = 'ValidatorError';
301
- }
302
- }
303
- exports.ValidatorError = ValidatorError;
304
- class TexEngine {
305
- constructor(schema, rawSchema, strict = false, isOptional = false) {
306
- this._isOptional = false;
307
- this.schema = schema;
308
- this.rawSchema = rawSchema;
309
- this.strict = strict;
310
- this._isOptional = isOptional;
311
- this.validator = new rs_1.TexValidator(schema, strict);
312
- }
313
- getCompiledSchema() {
314
- return this.schema;
315
- }
316
- optional() {
317
- return new TexEngine(this.schema, this.rawSchema, this.strict, true);
318
- }
319
- partial() {
320
- const newSchema = {};
321
- const newRaw = {};
322
- for (const [key, val] of Object.entries(this.schema)) {
323
- newSchema[key] = val.includes('?') ? val : `${val}?`;
324
- const rawVal = this.rawSchema[key];
325
- if (rawVal instanceof tex_types_1.TexType) {
326
- newRaw[key] = new tex_types_1.TexType(newSchema[key]);
327
- newRaw[key].sanitizers = rawVal.sanitizers;
328
- newRaw[key].refinements = rawVal.refinements;
329
- }
330
- else if (rawVal instanceof TexEngine) {
331
- newRaw[key] = rawVal.optional();
332
- }
333
- else {
334
- newRaw[key] = newSchema[key];
335
- }
336
- }
337
- return new TexEngine(newSchema, newRaw, this.strict, this._isOptional);
338
- }
339
- pick(keys) {
340
- const newSchema = {};
341
- const newRaw = {};
342
- for (const key of keys) {
343
- if (this.schema[key]) {
344
- newSchema[key] = this.schema[key];
345
- newRaw[key] = this.rawSchema[key];
346
- }
347
- }
348
- return new TexEngine(newSchema, newRaw, this.strict, this._isOptional);
349
- }
350
- omit(keys) {
351
- const newSchema = {};
352
- const newRaw = {};
353
- for (const [key, val] of Object.entries(this.schema)) {
354
- if (!keys.includes(key)) {
355
- newSchema[key] = val;
356
- newRaw[key] = this.rawSchema[key];
357
- }
358
- }
359
- return new TexEngine(newSchema, newRaw, this.strict, this._isOptional);
360
- }
361
- parse(data) {
362
- // 1. Run pre-validation sanitizers on the raw payload (if it's an object)
363
- if (data && typeof data === 'object') {
364
- for (const [key, val] of Object.entries(this.rawSchema)) {
365
- if (typeof data[key] === 'string' && data[key].trim() === '') {
366
- const raw = val instanceof tex_types_1.TexType ? val._raw : String(val);
367
- if (raw.includes('optional') ||
368
- raw.includes('nullable') ||
369
- raw.includes('nullish') ||
370
- raw.includes('?') ||
371
- val?._isOptional) {
372
- if (raw.includes('nullable') &&
373
- !raw.includes('optional') &&
374
- !raw.includes('nullish')) {
375
- data[key] = null;
376
- }
377
- else {
378
- delete data[key];
379
- }
380
- }
381
- }
382
- if (data[key] !== undefined && data[key] !== null) {
383
- if (val instanceof tex_types_1.TexType && val._raw.startsWith('date')) {
384
- if (val._raw.includes('coerce')) {
385
- if (typeof data[key] === 'string' ||
386
- typeof data[key] === 'number') {
387
- const d = new Date(data[key]);
388
- if (isNaN(d.getTime())) {
389
- throw new ValidatorError([
390
- { path: key, message: 'Must be a valid date' },
391
- ]);
392
- }
393
- data[key] = d;
394
- }
395
- }
396
- if (!(data[key] instanceof Date) &&
397
- typeof data[key] !== 'string' &&
398
- typeof data[key] !== 'number') {
399
- throw new ValidatorError([
400
- { path: key, message: 'Must be a valid date' },
401
- ]);
402
- }
403
- if (data[key] instanceof Date && isNaN(data[key].getTime())) {
404
- throw new ValidatorError([
405
- { path: key, message: 'Must be a valid date' },
406
- ]);
407
- }
408
- if (val._raw.includes('minDate:')) {
409
- const minStr = val._raw.match(/minDate:([^\s|]+)/)?.[1];
410
- if (minStr &&
411
- new Date(data[key]).getTime() < new Date(minStr).getTime()) {
412
- throw new ValidatorError([
413
- { path: key, message: `Date must be after ${minStr}` },
414
- ]);
415
- }
416
- }
417
- if (val._raw.includes('maxDate:')) {
418
- const maxStr = val._raw.match(/maxDate:([^\s|]+)/)?.[1];
419
- if (maxStr &&
420
- new Date(data[key]).getTime() > new Date(maxStr).getTime()) {
421
- throw new ValidatorError([
422
- { path: key, message: `Date must be before ${maxStr}` },
423
- ]);
424
- }
425
- }
426
- }
427
- if (val instanceof tex_types_1.TexType &&
428
- val._raw.startsWith('array<') &&
429
- val._raw.includes('coerce')) {
430
- if (!Array.isArray(data[key])) {
431
- if (typeof data[key] === 'string') {
432
- const parts = data[key].includes(',')
433
- ? data[key].split(',').map((s) => s.trim())
434
- : [data[key]];
435
- if (val._raw.startsWith('array<number')) {
436
- data[key] = parts.map((p) => {
437
- const n = Number(p);
438
- return isNaN(n) ? p : n;
439
- });
440
- }
441
- else if (val._raw.startsWith('array<boolean')) {
442
- data[key] = parts.map((p) => {
443
- if (p.toLowerCase() === 'true')
444
- return true;
445
- if (p.toLowerCase() === 'false')
446
- return false;
447
- return p;
448
- });
449
- }
450
- else {
451
- data[key] = parts;
452
- }
453
- }
454
- else {
455
- data[key] = [data[key]];
456
- }
457
- }
458
- else {
459
- if (val._raw.startsWith('array<number')) {
460
- data[key] = data[key].map((item) => {
461
- if (typeof item === 'string') {
462
- const n = Number(item);
463
- return isNaN(n) ? item : n;
464
- }
465
- return item;
466
- });
467
- }
468
- else if (val._raw.startsWith('array<boolean')) {
469
- data[key] = data[key].map((item) => {
470
- if (typeof item === 'string') {
471
- if (item.toLowerCase() === 'true')
472
- return true;
473
- if (item.toLowerCase() === 'false')
474
- return false;
475
- }
476
- return item;
477
- });
478
- }
479
- }
480
- }
481
- if (val instanceof tex_types_1.TexType && val.sanitizers.length > 0) {
482
- for (const s of val.sanitizers) {
483
- if (data[key] === undefined || data[key] === null)
484
- break;
485
- data[key] = s(data[key]);
486
- }
487
- }
488
- const itemSchema = val?._item;
489
- if (itemSchema && Array.isArray(data[key])) {
490
- if (itemSchema instanceof tex_types_1.TexType &&
491
- itemSchema.sanitizers.length > 0) {
492
- for (let i = 0; i < data[key].length; i++) {
493
- if (data[key][i] !== undefined && data[key][i] !== null) {
494
- for (const s of itemSchema.sanitizers) {
495
- if (data[key][i] === undefined || data[key][i] === null)
496
- break;
497
- data[key][i] = s(data[key][i]);
498
- }
499
- }
500
- }
501
- }
502
- }
503
- }
504
- }
505
- }
506
- // 2. Rust Validation
507
- let parsedData;
508
- try {
509
- parsedData = this.validator.parse(data);
510
- }
511
- catch (err) {
512
- if (data === process.env &&
513
- (process.env.__EXIS_SKIP_ENV_CHECK === 'true' ||
514
- process.env.EXIS_SKIP_ENV_CHECK === 'true')) {
515
- const mock = { ...data };
516
- for (const [key, val] of Object.entries(this.rawSchema)) {
517
- if (mock[key] === undefined) {
518
- const raw = val instanceof tex_types_1.TexType ? val._raw : String(val);
519
- if (raw.includes('number'))
520
- mock[key] = 0;
521
- else if (raw.includes('boolean'))
522
- mock[key] = false;
523
- else if (raw.includes('array'))
524
- mock[key] = [];
525
- else
526
- mock[key] = `mock_${key}`;
527
- }
528
- }
529
- return mock;
530
- }
531
- let path = 'root';
532
- let message = err.message || 'Validation failed';
533
- if (message.startsWith('Missing required field: ')) {
534
- path = message.replace('Missing required field: ', '').trim();
535
- message = 'Expected value, received undefined';
536
- }
537
- else if (message.startsWith("Field '")) {
538
- const match = message.match(/Field '([^']+)' (.+)/);
539
- if (match) {
540
- path = match[1];
541
- message = match[2].charAt(0).toUpperCase() + match[2].slice(1);
542
- }
543
- }
544
- else if (message.startsWith("Strict mode error: Unknown field '")) {
545
- const match = message.match(/Strict mode error: Unknown field '([^']+)'/);
546
- if (match) {
547
- path = match[1];
548
- message = 'Unknown field not allowed in strict mode';
549
- }
550
- }
551
- throw new ValidatorError([{ path, message }]);
552
- }
553
- // Preserve coerced Date objects
554
- if (parsedData && typeof parsedData === 'object') {
555
- for (const [key, val] of Object.entries(this.rawSchema)) {
556
- if (val instanceof tex_types_1.TexType &&
557
- val._raw.startsWith('date') &&
558
- val._raw.includes('coerce') &&
559
- data[key] instanceof Date) {
560
- parsedData[key] = data[key];
561
- }
562
- }
563
- }
564
- // 3. Post-validation synchronous refinements
565
- const errors = [];
566
- if (parsedData && typeof parsedData === 'object') {
567
- for (const [key, val] of Object.entries(this.rawSchema)) {
568
- if (parsedData[key] !== undefined) {
569
- const isNullableField = val instanceof tex_types_1.TexType &&
570
- (val._raw.includes('nullable') || val._raw.includes('nullish'));
571
- if (parsedData[key] === null && isNullableField) {
572
- continue;
573
- }
574
- if (val instanceof tex_types_1.TexType && val.refinements.length > 0) {
575
- for (const r of val.refinements) {
576
- if (!r.async && !r.fn(parsedData[key])) {
577
- const msg = typeof r.message === 'function'
578
- ? r.message(parsedData[key])
579
- : r.message || 'Invalid value';
580
- errors.push({ path: key, message: msg });
581
- }
582
- }
583
- }
584
- const itemSchema = val?._item;
585
- if (itemSchema && Array.isArray(parsedData[key])) {
586
- if (itemSchema instanceof tex_types_1.TexType &&
587
- itemSchema.refinements.length > 0) {
588
- const isItemNullable = itemSchema._raw.includes('nullable') ||
589
- itemSchema._raw.includes('nullish');
590
- for (let i = 0; i < parsedData[key].length; i++) {
591
- if (parsedData[key][i] === null && isItemNullable)
592
- continue;
593
- for (const r of itemSchema.refinements) {
594
- if (!r.async && !r.fn(parsedData[key][i])) {
595
- const msg = typeof r.message === 'function'
596
- ? r.message(parsedData[key][i])
597
- : r.message || 'Invalid value';
598
- errors.push({ path: `${key}[${i}]`, message: msg });
599
- }
600
- }
601
- }
602
- }
603
- }
604
- }
605
- }
606
- }
607
- if (errors.length > 0)
608
- throw new ValidatorError(errors);
609
- return parsedData;
610
- }
611
- async parseAsync(data) {
612
- const parsed = this.parse(data); // Handles sync sanitizers + rust + sync refine
613
- const errors = [];
614
- if (parsed && typeof parsed === 'object') {
615
- await Promise.all(Object.entries(this.rawSchema).map(async ([key, val]) => {
616
- const valData = parsed[key];
617
- const isNullableField = val instanceof tex_types_1.TexType &&
618
- (val._raw.includes('nullable') || val._raw.includes('nullish'));
619
- if (valData === null && isNullableField)
620
- return;
621
- if (valData !== undefined &&
622
- val instanceof tex_types_1.TexType &&
623
- val.refinements.length > 0) {
624
- for (const r of val.refinements) {
625
- if (r.async && !(await r.fn(valData))) {
626
- const msg = typeof r.message === 'function'
627
- ? r.message(valData)
628
- : r.message || 'Invalid value';
629
- errors.push({ path: key, message: msg });
630
- }
631
- }
632
- }
633
- }));
634
- }
635
- if (errors.length > 0)
636
- throw new ValidatorError(errors);
637
- return parsed;
638
- }
639
- toMongoSchema() {
640
- const schemaDef = {};
641
- for (const [key, rawDef] of Object.entries(this.schema)) {
642
- const typeStr = rawDef.split('|')[0].trim();
643
- const isOptional = typeStr.endsWith('?');
644
- const baseType = typeStr.replace('?', '');
645
- const field = {};
646
- if (baseType.startsWith('string') ||
647
- baseType.startsWith('email') ||
648
- baseType.startsWith('uuid') ||
649
- baseType.startsWith('cuid') ||
650
- baseType.startsWith('password'))
651
- field.type = String;
652
- else if (baseType.startsWith('number'))
653
- field.type = Number;
654
- else if (baseType.startsWith('boolean'))
655
- field.type = Boolean;
656
- else if (baseType.startsWith('date'))
657
- field.type = Date;
658
- else
659
- field.type = Object; // 'Mixed' essentially or nested
660
- if (!isOptional)
661
- field.required = true;
662
- schemaDef[key] = field;
663
- }
664
- return schemaDef;
665
- }
666
- toOpenApi() {
667
- const properties = {};
668
- const required = [];
669
- for (const [key, rawDef] of Object.entries(this.schema)) {
670
- const typeStr = rawDef.split('|')[0].trim();
671
- const isOptional = typeStr.endsWith('?');
672
- const baseType = typeStr.replace('?', '');
673
- const prop = {};
674
- if (baseType.startsWith('string') ||
675
- baseType.startsWith('uuid') ||
676
- baseType.startsWith('cuid') ||
677
- baseType.startsWith('password'))
678
- prop.type = 'string';
679
- else if (baseType.startsWith('email')) {
680
- prop.type = 'string';
681
- prop.format = 'email';
682
- }
683
- else if (baseType.startsWith('number'))
684
- prop.type = 'number';
685
- else if (baseType.startsWith('boolean'))
686
- prop.type = 'boolean';
687
- else if (baseType.startsWith('date'))
688
- prop.type = 'string';
689
- else if (baseType.startsWith('array<'))
690
- prop.type = 'array';
691
- else if (baseType.startsWith('enum:'))
692
- prop.type = 'string'; // Simplification
693
- else
694
- prop.type = 'object';
695
- properties[key] = prop;
696
- if (!isOptional)
697
- required.push(key);
698
- }
699
- const result = { type: 'object', properties };
700
- if (required.length > 0)
701
- result.required = required;
702
- return result;
703
- }
704
- }
705
- exports.TexEngine = TexEngine;
706
- exports.tex = new TexBuilder();
707
- function paginate(data, total, options = {}) {
708
- const page = Math.max(1, Number(options.page) || 1);
709
- const limit = Math.max(1, Number(options.limit) || 20);
710
- const totalPages = Math.ceil(total / limit);
711
- const hasNext = page < totalPages;
712
- const hasPrev = page > 1;
713
- return {
714
- data,
715
- pagination: {
716
- page,
717
- limit,
718
- total,
719
- totalPages,
720
- hasNextPage: hasNext,
721
- hasPrevPage: hasPrev,
722
- hasNext,
723
- hasPrev,
724
- },
725
- };
726
- }
727
- function getPaginationSkip(query = {}) {
728
- const page = Math.max(1, Number(query.page) || 1);
729
- const limit = Math.max(1, Number(query.limit) || 20);
730
- return {
731
- skip: (page - 1) * limit,
732
- limit,
733
- page,
734
- };
735
- }
3
+ exports.getPaginationSkip = exports.paginate = exports.formatReceivedValue = exports.getNestedValue = exports.ValidatorError = exports.TexEngine = exports.tex = exports.TexBuilder = void 0;
4
+ const builder_1 = require("./builder");
5
+ var builder_2 = require("./builder");
6
+ Object.defineProperty(exports, "TexBuilder", { enumerable: true, get: function () { return builder_2.TexBuilder; } });
7
+ exports.tex = new builder_1.TexBuilder();
8
+ var engine_1 = require("./engine");
9
+ Object.defineProperty(exports, "TexEngine", { enumerable: true, get: function () { return engine_1.TexEngine; } });
10
+ var error_1 = require("./error");
11
+ Object.defineProperty(exports, "ValidatorError", { enumerable: true, get: function () { return error_1.ValidatorError; } });
12
+ Object.defineProperty(exports, "getNestedValue", { enumerable: true, get: function () { return error_1.getNestedValue; } });
13
+ Object.defineProperty(exports, "formatReceivedValue", { enumerable: true, get: function () { return error_1.formatReceivedValue; } });
14
+ var pagination_1 = require("./pagination");
15
+ Object.defineProperty(exports, "paginate", { enumerable: true, get: function () { return pagination_1.paginate; } });
16
+ Object.defineProperty(exports, "getPaginationSkip", { enumerable: true, get: function () { return pagination_1.getPaginationSkip; } });
736
17
  //# sourceMappingURL=tex.js.map