lakutata 2.0.70 → 2.0.72

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 (379) hide show
  1. package/com/cacher.cjs +4 -8
  2. package/com/cacher.mjs +4 -8
  3. package/com/database.cjs +6 -10
  4. package/com/database.mjs +6 -10
  5. package/com/docker.cjs +19 -23
  6. package/com/docker.mjs +15 -19
  7. package/com/entrypoint.cjs +1 -5
  8. package/com/entrypoint.mjs +1 -5
  9. package/com/logger.cjs +4 -8
  10. package/com/logger.mjs +4 -8
  11. package/com/monitor.cjs +1 -5
  12. package/com/monitor.mjs +1 -5
  13. package/decorator/ctrl.cjs +1 -5
  14. package/decorator/ctrl.mjs +1 -5
  15. package/decorator/di.cjs +0 -4
  16. package/decorator/di.mjs +0 -4
  17. package/decorator/dto.cjs +0 -4
  18. package/decorator/dto.mjs +0 -4
  19. package/decorator/orm.cjs +17 -21
  20. package/decorator/orm.mjs +11 -15
  21. package/dtos.cjs +69 -0
  22. package/dtos.d.ts +19 -0
  23. package/dtos.mjs +59 -0
  24. package/helper.cjs +20 -20
  25. package/helper.d.ts +11 -1
  26. package/helper.mjs +4 -6
  27. package/lakutata.cjs +15 -19
  28. package/lakutata.d.ts +1 -1
  29. package/lakutata.mjs +5 -9
  30. package/orm.cjs +20 -24
  31. package/orm.mjs +22 -26
  32. package/package.json +6 -1
  33. package/provider/database.cjs +6 -10
  34. package/provider/database.mjs +6 -10
  35. package/provider/passwordHash.cjs +0 -4
  36. package/provider/passwordHash.mjs +0 -4
  37. package/src/components/Database.cjs +6 -10
  38. package/src/components/Database.mjs +6 -10
  39. package/src/components/Logger.cjs +4 -8
  40. package/src/components/Logger.mjs +4 -8
  41. package/src/components/cacher/Cacher.cjs +8 -12
  42. package/src/components/cacher/Cacher.mjs +12 -16
  43. package/src/components/cacher/adapters/CreateFileCacheAdapter.cjs +4 -6
  44. package/src/components/cacher/adapters/CreateFileCacheAdapter.mjs +4 -6
  45. package/src/components/cacher/options/FileCacheOptions.cjs +6 -10
  46. package/src/components/cacher/options/FileCacheOptions.mjs +0 -4
  47. package/src/components/cacher/options/MemcacheCacheOptions.cjs +0 -4
  48. package/src/components/cacher/options/MemcacheCacheOptions.mjs +0 -4
  49. package/src/components/cacher/options/MongoCacheOptions.cjs +0 -4
  50. package/src/components/cacher/options/MongoCacheOptions.mjs +0 -4
  51. package/src/components/cacher/options/MysqlCacheOptions.cjs +0 -4
  52. package/src/components/cacher/options/MysqlCacheOptions.mjs +11 -15
  53. package/src/components/cacher/options/PostgresCacheOptions.cjs +0 -4
  54. package/src/components/cacher/options/PostgresCacheOptions.mjs +0 -4
  55. package/src/components/cacher/options/RedisCacheOptions.cjs +0 -4
  56. package/src/components/cacher/options/RedisCacheOptions.mjs +0 -4
  57. package/src/components/cacher/options/SqliteCacheOptions.cjs +0 -4
  58. package/src/components/cacher/options/SqliteCacheOptions.mjs +6 -10
  59. package/src/components/docker/ConnectionOptionsBuilder.cjs +15 -19
  60. package/src/components/docker/ConnectionOptionsBuilder.mjs +15 -19
  61. package/src/components/docker/Docker.cjs +15 -19
  62. package/src/components/docker/Docker.mjs +15 -19
  63. package/src/components/docker/lib/DockerContainer.cjs +22 -26
  64. package/src/components/docker/lib/DockerContainer.mjs +19 -23
  65. package/src/components/docker/lib/DockerContainerTTY.cjs +15 -19
  66. package/src/components/docker/lib/DockerContainerTTY.mjs +15 -19
  67. package/src/components/docker/lib/DockerImage.cjs +8 -12
  68. package/src/components/docker/lib/DockerImage.mjs +0 -4
  69. package/src/components/docker/options/DockerPruneOptions.cjs +0 -4
  70. package/src/components/docker/options/DockerPruneOptions.mjs +0 -4
  71. package/src/components/docker/options/auth/DockerAuthOptions.cjs +0 -4
  72. package/src/components/docker/options/auth/DockerAuthOptions.mjs +0 -4
  73. package/src/components/docker/options/container/ContainerCommitOptions.cjs +3 -7
  74. package/src/components/docker/options/container/ContainerCommitOptions.mjs +0 -4
  75. package/src/components/docker/options/container/ContainerCreateTTYOptions.cjs +4 -8
  76. package/src/components/docker/options/container/ContainerCreateTTYOptions.mjs +0 -4
  77. package/src/components/docker/options/container/ContainerExecOptions.cjs +0 -4
  78. package/src/components/docker/options/container/ContainerExecOptions.mjs +2 -6
  79. package/src/components/docker/options/container/ContainerExportDirectoryOptions.cjs +0 -4
  80. package/src/components/docker/options/container/ContainerExportDirectoryOptions.mjs +0 -4
  81. package/src/components/docker/options/container/ContainerKillOptions.cjs +0 -4
  82. package/src/components/docker/options/container/ContainerKillOptions.mjs +2 -6
  83. package/src/components/docker/options/container/ContainerLogsOptions.cjs +0 -4
  84. package/src/components/docker/options/container/ContainerLogsOptions.mjs +0 -4
  85. package/src/components/docker/options/container/ContainerRemoveOptions.cjs +0 -4
  86. package/src/components/docker/options/container/ContainerRemoveOptions.mjs +0 -4
  87. package/src/components/docker/options/container/ContainerSettingOptions.cjs +0 -4
  88. package/src/components/docker/options/container/ContainerSettingOptions.mjs +0 -4
  89. package/src/components/docker/options/container/ContainerStopOptions.cjs +0 -4
  90. package/src/components/docker/options/container/ContainerStopOptions.mjs +0 -4
  91. package/src/components/docker/options/container/ContainerTTYConsoleSizeOptions.cjs +0 -4
  92. package/src/components/docker/options/container/ContainerTTYConsoleSizeOptions.mjs +0 -4
  93. package/src/components/docker/options/image/ImageBuildOptions.cjs +2 -6
  94. package/src/components/docker/options/image/ImageBuildOptions.mjs +2 -6
  95. package/src/components/docker/options/image/ImageExportOptions.cjs +0 -4
  96. package/src/components/docker/options/image/ImageExportOptions.mjs +0 -4
  97. package/src/components/docker/options/image/ImageImportOptions.cjs +0 -4
  98. package/src/components/docker/options/image/ImageImportOptions.mjs +0 -4
  99. package/src/components/docker/options/image/ImagePullOptions.cjs +0 -4
  100. package/src/components/docker/options/image/ImagePullOptions.mjs +0 -4
  101. package/src/components/docker/options/image/ImagePushOptions.cjs +0 -4
  102. package/src/components/docker/options/image/ImagePushOptions.mjs +0 -4
  103. package/src/components/docker/options/image/ImageRemoveOptions.cjs +3 -7
  104. package/src/components/docker/options/image/ImageRemoveOptions.mjs +0 -4
  105. package/src/components/docker/options/image/ImageTagOptions.cjs +0 -4
  106. package/src/components/docker/options/image/ImageTagOptions.mjs +0 -4
  107. package/src/components/docker/options/network/NetworkCreateOptions.cjs +0 -4
  108. package/src/components/docker/options/network/NetworkCreateOptions.mjs +0 -4
  109. package/src/components/entrypoint/Entrypoint.cjs +98 -102
  110. package/src/components/entrypoint/Entrypoint.mjs +53 -57
  111. package/src/components/entrypoint/lib/AccessControl.cjs +0 -4
  112. package/src/components/entrypoint/lib/AccessControl.mjs +0 -4
  113. package/src/components/entrypoint/lib/AccessControlRule.cjs +0 -4
  114. package/src/components/entrypoint/lib/AccessControlRule.mjs +0 -4
  115. package/src/components/entrypoint/lib/Controller.cjs +0 -4
  116. package/src/components/entrypoint/lib/Controller.mjs +0 -4
  117. package/src/components/monitor/AliveMonitor.cjs +0 -4
  118. package/src/components/monitor/AliveMonitor.mjs +0 -4
  119. package/src/components/monitor/CpuMonitor.cjs +1 -5
  120. package/src/components/monitor/CpuMonitor.mjs +1 -5
  121. package/src/components/monitor/EventLoopMonitor.cjs +0 -4
  122. package/src/components/monitor/EventLoopMonitor.mjs +0 -4
  123. package/src/components/monitor/HttpRequestMonitor.cjs +1 -5
  124. package/src/components/monitor/HttpRequestMonitor.mjs +1 -5
  125. package/src/components/monitor/MemoryMonitor.cjs +1 -5
  126. package/src/components/monitor/MemoryMonitor.mjs +1 -5
  127. package/src/decorators/ctrl/CLIAction.cjs +5 -9
  128. package/src/decorators/ctrl/CLIAction.mjs +1 -5
  129. package/src/decorators/ctrl/HTTPAction.cjs +8 -12
  130. package/src/decorators/ctrl/HTTPAction.mjs +1 -5
  131. package/src/decorators/ctrl/ServiceAction.cjs +1 -5
  132. package/src/decorators/ctrl/ServiceAction.mjs +5 -9
  133. package/src/decorators/ctrl/http/DELETE.cjs +1 -5
  134. package/src/decorators/ctrl/http/DELETE.mjs +1 -5
  135. package/src/decorators/ctrl/http/GET.cjs +1 -5
  136. package/src/decorators/ctrl/http/GET.mjs +1 -5
  137. package/src/decorators/ctrl/http/HEAD.cjs +1 -5
  138. package/src/decorators/ctrl/http/HEAD.mjs +1 -5
  139. package/src/decorators/ctrl/http/OPTIONS.cjs +1 -5
  140. package/src/decorators/ctrl/http/OPTIONS.mjs +4 -8
  141. package/src/decorators/ctrl/http/PATCH.cjs +1 -5
  142. package/src/decorators/ctrl/http/PATCH.mjs +1 -5
  143. package/src/decorators/ctrl/http/POST.cjs +1 -5
  144. package/src/decorators/ctrl/http/POST.mjs +1 -5
  145. package/src/decorators/ctrl/http/PUT.cjs +1 -5
  146. package/src/decorators/ctrl/http/PUT.mjs +1 -5
  147. package/src/decorators/di/Configurable.cjs +1 -5
  148. package/src/decorators/di/Configurable.mjs +0 -4
  149. package/src/decorators/di/Inject.cjs +8 -12
  150. package/src/decorators/di/Inject.mjs +7 -11
  151. package/src/decorators/dto/Accept.cjs +0 -4
  152. package/src/decorators/dto/Accept.mjs +0 -4
  153. package/src/decorators/dto/Expect.cjs +0 -4
  154. package/src/decorators/dto/Expect.mjs +4 -8
  155. package/src/decorators/dto/IndexSignature.cjs +0 -4
  156. package/src/decorators/dto/IndexSignature.mjs +4 -8
  157. package/src/decorators/dto/Return.cjs +0 -4
  158. package/src/decorators/dto/Return.mjs +0 -4
  159. package/src/decorators/orm/AfterInsert.cjs +11 -15
  160. package/src/decorators/orm/AfterInsert.mjs +17 -21
  161. package/src/decorators/orm/AfterLoad.cjs +15 -19
  162. package/src/decorators/orm/AfterLoad.mjs +20 -24
  163. package/src/decorators/orm/AfterRecover.cjs +15 -19
  164. package/src/decorators/orm/AfterRecover.mjs +16 -20
  165. package/src/decorators/orm/AfterRemove.cjs +15 -19
  166. package/src/decorators/orm/AfterRemove.mjs +16 -20
  167. package/src/decorators/orm/AfterSoftRemove.cjs +11 -15
  168. package/src/decorators/orm/AfterSoftRemove.mjs +16 -20
  169. package/src/decorators/orm/AfterUpdate.cjs +11 -15
  170. package/src/decorators/orm/AfterUpdate.mjs +17 -21
  171. package/src/decorators/orm/BeforeInsert.cjs +17 -21
  172. package/src/decorators/orm/BeforeInsert.mjs +15 -19
  173. package/src/decorators/orm/BeforeRecover.cjs +17 -21
  174. package/src/decorators/orm/BeforeRecover.mjs +13 -17
  175. package/src/decorators/orm/BeforeRemove.cjs +17 -21
  176. package/src/decorators/orm/BeforeRemove.mjs +13 -17
  177. package/src/decorators/orm/BeforeSoftRemove.cjs +17 -21
  178. package/src/decorators/orm/BeforeSoftRemove.mjs +13 -17
  179. package/src/decorators/orm/BeforeUpdate.cjs +15 -19
  180. package/src/decorators/orm/BeforeUpdate.mjs +15 -19
  181. package/src/decorators/orm/Check.cjs +11 -15
  182. package/src/decorators/orm/Check.mjs +11 -15
  183. package/src/decorators/orm/ChildEntity.cjs +16 -20
  184. package/src/decorators/orm/ChildEntity.mjs +13 -17
  185. package/src/decorators/orm/Column.cjs +28 -32
  186. package/src/decorators/orm/Column.mjs +11 -15
  187. package/src/decorators/orm/CreateDateColumn.cjs +13 -17
  188. package/src/decorators/orm/CreateDateColumn.mjs +11 -15
  189. package/src/decorators/orm/DeleteDateColumn.cjs +13 -17
  190. package/src/decorators/orm/DeleteDateColumn.mjs +11 -15
  191. package/src/decorators/orm/Entity.cjs +15 -19
  192. package/src/decorators/orm/Entity.mjs +15 -19
  193. package/src/decorators/orm/EventSubscriber.cjs +11 -15
  194. package/src/decorators/orm/EventSubscriber.mjs +11 -15
  195. package/src/decorators/orm/Exclusion.cjs +11 -15
  196. package/src/decorators/orm/Exclusion.mjs +15 -19
  197. package/src/decorators/orm/Generated.cjs +15 -19
  198. package/src/decorators/orm/Generated.mjs +11 -15
  199. package/src/decorators/orm/Index.cjs +16 -20
  200. package/src/decorators/orm/Index.mjs +29 -33
  201. package/src/decorators/orm/JoinColumn.cjs +15 -19
  202. package/src/decorators/orm/JoinColumn.mjs +11 -15
  203. package/src/decorators/orm/JoinTable.cjs +11 -15
  204. package/src/decorators/orm/JoinTable.mjs +15 -19
  205. package/src/decorators/orm/ManyToMany.cjs +18 -22
  206. package/src/decorators/orm/ManyToMany.mjs +22 -26
  207. package/src/decorators/orm/ManyToOne.cjs +21 -25
  208. package/src/decorators/orm/ManyToOne.mjs +22 -26
  209. package/src/decorators/orm/ObjectIdColumn.cjs +11 -15
  210. package/src/decorators/orm/ObjectIdColumn.mjs +11 -15
  211. package/src/decorators/orm/OneToMany.cjs +18 -22
  212. package/src/decorators/orm/OneToMany.mjs +11 -15
  213. package/src/decorators/orm/OneToOne.cjs +20 -24
  214. package/src/decorators/orm/OneToOne.mjs +11 -15
  215. package/src/decorators/orm/PrimaryColumn.cjs +15 -19
  216. package/src/decorators/orm/PrimaryColumn.mjs +11 -15
  217. package/src/decorators/orm/PrimaryGeneratedColumn.cjs +11 -15
  218. package/src/decorators/orm/PrimaryGeneratedColumn.mjs +13 -17
  219. package/src/decorators/orm/RelationId.cjs +16 -20
  220. package/src/decorators/orm/RelationId.mjs +17 -21
  221. package/src/decorators/orm/TableInheritance.cjs +13 -17
  222. package/src/decorators/orm/TableInheritance.mjs +11 -15
  223. package/src/decorators/orm/Tree.cjs +11 -15
  224. package/src/decorators/orm/Tree.mjs +11 -15
  225. package/src/decorators/orm/TreeChildren.cjs +11 -15
  226. package/src/decorators/orm/TreeChildren.mjs +20 -24
  227. package/src/decorators/orm/TreeLevelColumn.cjs +11 -15
  228. package/src/decorators/orm/TreeLevelColumn.mjs +11 -15
  229. package/src/decorators/orm/TreeParent.cjs +11 -15
  230. package/src/decorators/orm/TreeParent.mjs +11 -15
  231. package/src/decorators/orm/Unique.cjs +18 -22
  232. package/src/decorators/orm/Unique.mjs +11 -15
  233. package/src/decorators/orm/UpdateDateColumn.cjs +13 -17
  234. package/src/decorators/orm/UpdateDateColumn.mjs +17 -21
  235. package/src/decorators/orm/VersionColumn.cjs +11 -15
  236. package/src/decorators/orm/VersionColumn.mjs +11 -15
  237. package/src/decorators/orm/ViewColumn.cjs +11 -15
  238. package/src/decorators/orm/ViewColumn.mjs +11 -15
  239. package/src/decorators/orm/ViewEntity.cjs +11 -15
  240. package/src/decorators/orm/ViewEntity.mjs +11 -15
  241. package/src/decorators/orm/VirtualColumn.cjs +11 -15
  242. package/src/decorators/orm/VirtualColumn.mjs +11 -15
  243. package/src/dto/PaginationResultDTO.cjs +74 -0
  244. package/src/dto/PaginationResultDTO.mjs +68 -0
  245. package/src/dto/PaginationSearchDTO.cjs +69 -0
  246. package/src/dto/PaginationSearchDTO.mjs +63 -0
  247. package/src/lib/base/BaseObject.cjs +0 -4
  248. package/src/lib/base/BaseObject.mjs +0 -4
  249. package/src/lib/base/Context.cjs +0 -4
  250. package/src/lib/base/Context.mjs +5 -9
  251. package/src/lib/base/internal/ActionOptions.cjs +0 -4
  252. package/src/lib/base/internal/ActionOptions.mjs +6 -10
  253. package/src/lib/base/internal/ApplicationConfigLoader.cjs +0 -4
  254. package/src/lib/base/internal/ApplicationConfigLoader.mjs +0 -4
  255. package/src/lib/base/internal/ControllerEntrypoint.cjs +1 -1
  256. package/src/lib/base/internal/ControllerEntrypoint.mjs +1 -1
  257. package/src/lib/base/internal/DataValidator.cjs +11 -12
  258. package/src/lib/base/internal/DataValidator.mjs +116 -117
  259. package/src/lib/base/internal/FlexibleDTO.cjs +0 -4
  260. package/src/lib/base/internal/FlexibleDTO.mjs +4 -8
  261. package/src/lib/base/internal/GetActionDTOAndOptions.cjs +7 -11
  262. package/src/lib/base/internal/GetActionDTOAndOptions.mjs +0 -4
  263. package/src/lib/base/internal/MethodValidation.cjs +25 -29
  264. package/src/lib/base/internal/MethodValidation.mjs +0 -4
  265. package/src/lib/base/internal/ModuleConfigLoader.cjs +0 -4
  266. package/src/lib/base/internal/ModuleConfigLoader.mjs +21 -25
  267. package/src/lib/base/internal/ObjectConfiguration.cjs +0 -4
  268. package/src/lib/base/internal/ObjectConfiguration.mjs +12 -16
  269. package/src/lib/base/internal/ObjectSchemaValidation.cjs +0 -4
  270. package/src/lib/base/internal/ObjectSchemaValidation.mjs +0 -4
  271. package/src/lib/base/internal/ObjectType.cjs +0 -4
  272. package/src/lib/base/internal/ObjectType.mjs +0 -4
  273. package/src/lib/context/CLIContext.cjs +0 -4
  274. package/src/lib/context/CLIContext.mjs +0 -4
  275. package/src/lib/context/HTTPContext.cjs +0 -4
  276. package/src/lib/context/HTTPContext.mjs +4 -8
  277. package/src/lib/context/ServiceContext.cjs +0 -4
  278. package/src/lib/context/ServiceContext.mjs +0 -4
  279. package/src/lib/core/Application.cjs +5 -9
  280. package/src/lib/core/Application.mjs +5 -9
  281. package/src/lib/core/Component.cjs +0 -4
  282. package/src/lib/core/Component.mjs +0 -4
  283. package/src/lib/core/Container.cjs +0 -4
  284. package/src/lib/core/Container.mjs +0 -4
  285. package/src/lib/core/DTO.cjs +0 -4
  286. package/src/lib/core/DTO.mjs +0 -4
  287. package/src/lib/core/Module.cjs +1 -5
  288. package/src/lib/core/Module.mjs +1 -5
  289. package/src/lib/core/Provider.cjs +0 -4
  290. package/src/lib/core/Provider.mjs +0 -4
  291. package/src/lib/helpers/IsSymbol.cjs +0 -4
  292. package/src/lib/helpers/IsSymbol.mjs +0 -4
  293. package/src/lib/helpers/NonceStr.cjs +1 -1
  294. package/src/lib/helpers/NonceStr.mjs +1 -1
  295. package/src/lib/helpers/ObjectHash.cjs +1 -1
  296. package/src/lib/helpers/ObjectHash.mjs +1 -1
  297. package/src/lib/helpers/Paginator.cjs +11 -0
  298. package/src/lib/helpers/Paginator.mjs +5 -0
  299. package/src/lib/helpers/RandomString.cjs +1 -1
  300. package/src/lib/helpers/RandomString.mjs +1 -1
  301. package/src/lib/helpers/Statistics.cjs +1 -1
  302. package/src/lib/helpers/Statistics.mjs +1 -1
  303. package/src/lib/ioc/DependencyInjectionContainer.cjs +28 -32
  304. package/src/lib/ioc/DependencyInjectionContainer.mjs +17 -21
  305. package/src/lib/ioc/Errors.cjs +0 -4
  306. package/src/lib/ioc/Errors.mjs +4 -8
  307. package/src/lib/ioc/ListModules.cjs +100 -104
  308. package/src/lib/ioc/ListModules.mjs +0 -4
  309. package/src/lib/ioc/LoadModules.cjs +27 -31
  310. package/src/lib/ioc/LoadModules.mjs +5 -9
  311. package/src/lib/ioc/Resolvers.cjs +6 -10
  312. package/src/lib/ioc/Resolvers.mjs +3 -7
  313. package/src/lib/ioc/Utils.cjs +0 -4
  314. package/src/lib/ioc/Utils.mjs +0 -4
  315. package/src/lib/validation/VLD.cjs +4096 -3158
  316. package/src/lib/validation/VLD.mjs +2807 -1887
  317. package/src/lib/validation/interfaces/BigIntSchema.cjs +1 -0
  318. package/src/lib/validation/interfaces/BigIntSchema.mjs +1 -0
  319. package/src/lib/validation/types/NoNestedArrays.cjs +1 -0
  320. package/src/lib/validation/types/NoNestedArrays.mjs +1 -0
  321. package/src/lib/validation/types/Primitives.cjs +1 -0
  322. package/src/lib/validation/types/Primitives.mjs +1 -0
  323. package/src/lib/validation/types/UnwrapSchemaLikeWithoutArray.cjs +1 -0
  324. package/src/lib/validation/types/UnwrapSchemaLikeWithoutArray.mjs +1 -0
  325. package/src/options/ApplicationOptions.cjs +0 -4
  326. package/src/options/ApplicationOptions.mjs +0 -4
  327. package/src/options/LoadAnonymousObjectOptions.cjs +0 -4
  328. package/src/options/LoadAnonymousObjectOptions.mjs +0 -4
  329. package/src/options/LoadNamedObjectOptions.cjs +0 -4
  330. package/src/options/LoadNamedObjectOptions.mjs +0 -4
  331. package/src/options/LoadObjectOptions.cjs +0 -4
  332. package/src/options/LoadObjectOptions.mjs +0 -4
  333. package/src/options/ModuleLoadObjectsOptions.cjs +0 -4
  334. package/src/options/ModuleLoadObjectsOptions.mjs +0 -4
  335. package/src/options/ModuleOptions.cjs +0 -4
  336. package/src/options/ModuleOptions.mjs +0 -4
  337. package/src/options/OverridableNamedObjectOptions.cjs +0 -4
  338. package/src/options/OverridableNamedObjectOptions.mjs +0 -4
  339. package/src/options/OverridableObjectOptions.cjs +0 -4
  340. package/src/options/OverridableObjectOptions.mjs +0 -4
  341. package/src/providers/Database.cjs +6 -10
  342. package/src/providers/Database.mjs +6 -10
  343. package/src/providers/PasswordHash.cjs +13 -17
  344. package/src/providers/PasswordHash.mjs +208 -212
  345. package/vendor/Package.10.cjs +9 -1
  346. package/vendor/Package.10.mjs +9 -1
  347. package/vendor/Package.102.cjs +48831 -0
  348. package/vendor/Package.102.mjs +48767 -0
  349. package/vendor/Package.11.cjs +86 -0
  350. package/vendor/Package.11.mjs +80 -0
  351. package/vendor/Package.12.cjs +3 -5
  352. package/vendor/Package.12.mjs +3 -5
  353. package/vendor/Package.122.cjs +1 -48833
  354. package/vendor/Package.122.mjs +1 -48771
  355. package/vendor/Package.13.cjs +1 -7
  356. package/vendor/Package.13.mjs +1 -7
  357. package/vendor/Package.14.cjs +2247 -1
  358. package/vendor/Package.14.mjs +2139 -1
  359. package/vendor/Package.15.cjs +14057 -1
  360. package/vendor/Package.15.mjs +14031 -1
  361. package/vendor/Package.16.cjs +1 -2247
  362. package/vendor/Package.16.mjs +1 -2139
  363. package/vendor/Package.17.cjs +46794 -12601
  364. package/vendor/Package.17.mjs +46762 -12584
  365. package/vendor/Package.18.cjs +1 -1
  366. package/vendor/Package.18.mjs +1 -1
  367. package/vendor/Package.2.cjs +1633 -2052
  368. package/vendor/Package.2.mjs +2147 -2566
  369. package/vendor/Package.62.cjs +2 -2
  370. package/vendor/Package.62.mjs +2 -2
  371. package/vendor/Package.8.cjs +2 -0
  372. package/vendor/Package.8.mjs +2 -0
  373. package/vendor/TypeDef.internal.5.d.ts +2422 -2041
  374. package/vendor/Package.132.cjs +0 -87
  375. package/vendor/Package.132.mjs +0 -79
  376. package/vendor/Package.19.cjs +0 -48247
  377. package/vendor/Package.19.mjs +0 -48204
  378. package/vendor/Package.20.cjs +0 -3
  379. package/vendor/Package.20.mjs +0 -1
@@ -1,5 +1,62 @@
1
1
  import './TypeDef.internal.2.js';
2
2
 
3
+ /** The Standard Schema interface. */
4
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
5
+ /** The Standard Schema properties. */
6
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
7
+ }
8
+ declare namespace StandardSchemaV1 {
9
+ /** The Standard Schema properties interface. */
10
+ export interface Props<Input = unknown, Output = Input> {
11
+ /** The version number of the standard. */
12
+ readonly version: 1;
13
+ /** The vendor name of the schema library. */
14
+ readonly vendor: string;
15
+ /** Validates unknown input values. */
16
+ readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
17
+ /** Inferred types associated with the schema. */
18
+ readonly types?: Types<Input, Output> | undefined;
19
+ }
20
+ /** The result interface of the validate function. */
21
+ export type Result<Output> = SuccessResult<Output> | FailureResult;
22
+ /** The result interface if validation succeeds. */
23
+ export interface SuccessResult<Output> {
24
+ /** The typed output value. */
25
+ readonly value: Output;
26
+ /** The non-existent issues. */
27
+ readonly issues?: undefined;
28
+ }
29
+ /** The result interface if validation fails. */
30
+ export interface FailureResult {
31
+ /** The issues of failed validation. */
32
+ readonly issues: ReadonlyArray<Issue>;
33
+ }
34
+ /** The issue interface of the failure output. */
35
+ export interface Issue {
36
+ /** The error message of the issue. */
37
+ readonly message: string;
38
+ /** The path of the issue, if any. */
39
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
40
+ }
41
+ /** The path segment interface of the issue. */
42
+ export interface PathSegment {
43
+ /** The key representing a path segment. */
44
+ readonly key: PropertyKey;
45
+ }
46
+ /** The Standard Schema types interface. */
47
+ export interface Types<Input = unknown, Output = Input> {
48
+ /** The input type of the schema. */
49
+ readonly input: Input;
50
+ /** The output type of the schema. */
51
+ readonly output: Output;
52
+ }
53
+ /** Infers the input type of a Standard Schema. */
54
+ export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
55
+ /** Infers the output type of a Standard Schema. */
56
+ export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
57
+ export { };
58
+ }
59
+
3
60
  // The following definitions have been copied (almost) as-is from:
4
61
  // https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hapi__joi
5
62
  //
@@ -9,2358 +66,2651 @@ import './TypeDef.internal.2.js';
9
66
  //
10
67
  // TypeScript Version: 2.8
11
68
 
12
- // TODO express type of Schema in a type-parameter (.default, .valid, .example etc)
69
+
13
70
 
14
71
  declare namespace Joi {
15
- type Types =
16
- | 'any'
17
- | 'alternatives'
18
- | 'array'
19
- | 'boolean'
20
- | 'binary'
21
- | 'date'
22
- | 'function'
23
- | 'link'
24
- | 'number'
25
- | 'object'
26
- | 'string'
27
- | 'symbol';
28
-
29
- type BasicType = boolean | number | string | any[] | object | null;
30
-
31
- type LanguageMessages = Record<string, string | Record<string, string>>;
32
-
33
- type PresenceMode = 'optional' | 'required' | 'forbidden';
34
-
35
- interface ErrorFormattingOptions {
36
- /**
37
- * when true, error message templates will escape special characters to HTML entities, for security purposes.
38
- *
39
- * @default false
40
- */
41
- escapeHtml?: boolean;
42
- /**
43
- * defines the value used to set the label context variable.
44
- */
45
- label?: 'path' | 'key' | false;
46
- /**
47
- * The preferred language code for error messages.
48
- * The value is matched against keys at the root of the messages object, and then the error code as a child key of that.
49
- * Can be a reference to the value, global context, or local context which is the root value passed to the validation function.
50
- *
51
- * Note that references to the value are usually not what you want as they move around the value structure relative to where the error happens.
52
- * Instead, either use the global context, or the absolute value (e.g. `Joi.ref('/variable')`)
53
- */
54
- language?: keyof LanguageMessages;
55
- /**
56
- * when false, skips rendering error templates. Useful when error messages are generated elsewhere to save processing time.
57
- *
58
- * @default true
59
- */
60
- render?: boolean;
61
- /**
62
- * when true, the main error will possess a stack trace, otherwise it will be disabled.
63
- * Defaults to false for performances reasons. Has no effect on platforms other than V8/node.js as it uses the Stack trace API.
64
- *
65
- * @default false
66
- */
67
- stack?: boolean;
68
- /**
69
- * overrides the way values are wrapped (e.g. `[]` around arrays, `""` around labels).
70
- * Each key can be set to a string with one (same character before and after the value) or two characters (first character
71
- * before and second character after), or `false` to disable wrapping.
72
- */
73
- wrap?: {
74
- /**
75
- * the characters used around `{#label}` references. Defaults to `'"'`.
76
- *
77
- * @default '"'
78
- */
79
- label?: string | false,
80
-
81
- /**
82
- * the characters used around array values. Defaults to `'[]'`
83
- *
84
- * @default '[]'
85
- */
86
- array?: string | false
87
-
88
- /**
89
- * the characters used around array string values. Defaults to no wrapping.
90
- *
91
- * @default false
92
- */
93
- string?: string | false
94
- };
95
- }
72
+ type Types =
73
+ | "any"
74
+ | "alternatives"
75
+ | "array"
76
+ | "boolean"
77
+ | "binary"
78
+ | "date"
79
+ | "function"
80
+ | "link"
81
+ | "number"
82
+ | "object"
83
+ | "string"
84
+ | "symbol";
96
85
 
97
- interface BaseValidationOptions {
98
- /**
99
- * when true, stops validation on the first error, otherwise returns all the errors found.
100
- *
101
- * @default true
102
- */
103
- abortEarly?: boolean;
104
- /**
105
- * when true, allows object to contain unknown keys which are ignored.
106
- *
107
- * @default false
108
- */
109
- allowUnknown?: boolean;
110
- /**
111
- * when true, return artifacts alongside the value.
112
- *
113
- * @default false
114
- */
115
- artifacts?: boolean;
116
- /**
117
- * when true, schema caching is enabled (for schemas with explicit caching rules).
118
- *
119
- * @default false
120
- */
121
- cache?: boolean;
122
- /**
123
- * provides an external data set to be used in references
124
- */
125
- context?: Context;
126
- /**
127
- * when true, attempts to cast values to the required types (e.g. a string to a number).
128
- *
129
- * @default true
130
- */
131
- convert?: boolean;
132
- /**
133
- * sets the string format used when converting dates to strings in error messages and casting.
134
- *
135
- * @default 'iso'
136
- */
137
- dateFormat?: 'date' | 'iso' | 'string' | 'time' | 'utc';
138
- /**
139
- * when true, valid results and throw errors are decorated with a debug property which includes an array of the validation steps used to generate the returned result.
140
- *
141
- * @default false
142
- */
143
- debug?: boolean;
144
- /**
145
- * error formatting settings.
146
- */
147
- errors?: ErrorFormattingOptions;
148
- /**
149
- * if false, the external rules set with `any.external()` are ignored, which is required to ignore any external validations in synchronous mode (or an exception is thrown).
150
- *
151
- * @default true
152
- */
153
- externals?: boolean;
154
- /**
155
- * when true, do not apply default values.
156
- *
157
- * @default false
158
- */
159
- noDefaults?: boolean;
160
- /**
161
- * when true, inputs are shallow cloned to include non-enumerable properties.
162
- *
163
- * @default false
164
- */
165
- nonEnumerables?: boolean;
166
- /**
167
- * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'.
168
- *
169
- * @default 'optional'
170
- */
171
- presence?: PresenceMode;
172
- /**
173
- * when true, ignores unknown keys with a function value.
174
- *
175
- * @default false
176
- */
177
- skipFunctions?: boolean;
178
- /**
179
- * remove unknown elements from objects and arrays.
180
- * - when true, all unknown elements will be removed
181
- * - when an object:
182
- * - objects - set to true to remove unknown keys from objects
183
- *
184
- * @default false
185
- */
186
- stripUnknown?: boolean | { arrays?: boolean; objects?: boolean };
187
- }
86
+ type BasicType = boolean | number | string | any[] | object | null;
188
87
 
189
- interface ValidationOptions extends BaseValidationOptions {
190
- /**
191
- * overrides individual error messages. Defaults to no override (`{}`).
192
- * Messages use the same rules as templates.
193
- * Variables in double braces `{{var}}` are HTML escaped if the option `errors.escapeHtml` is set to true.
194
- *
195
- * @default {}
196
- */
197
- messages?: LanguageMessages;
198
- }
88
+ type LanguageMessages = Record<string, string | Record<string, string>>;
199
89
 
200
- interface AsyncValidationOptions extends ValidationOptions {
201
- /**
202
- * when true, artifacts are returned alongside the value (i.e. `{ value, artifacts }`)
203
- *
204
- * @default false
205
- */
206
- artifacts?: boolean;
207
- /**
208
- * when true, warnings are returned alongside the value (i.e. `{ value, warning }`).
209
- *
210
- * @default false
211
- */
212
- warnings?: boolean;
213
- }
90
+ type PresenceMode = "optional" | "required" | "forbidden";
214
91
 
215
- interface LanguageMessageTemplate {
216
- source: string;
217
- rendered: string;
218
- }
92
+ interface ErrorFormattingOptions {
93
+ /**
94
+ * when true, error message templates will escape special characters to HTML entities, for security purposes.
95
+ *
96
+ * @default false
97
+ */
98
+ escapeHtml?: boolean;
99
+ /**
100
+ * defines the value used to set the label context variable.
101
+ */
102
+ label?: "path" | "key" | false;
103
+ /**
104
+ * The preferred language code for error messages.
105
+ * The value is matched against keys at the root of the messages object, and then the error code as a child key of that.
106
+ * Can be a reference to the value, global context, or local context which is the root value passed to the validation function.
107
+ *
108
+ * Note that references to the value are usually not what you want as they move around the value structure relative to where the error happens.
109
+ * Instead, either use the global context, or the absolute value (e.g. `Joi.ref('/variable')`)
110
+ */
111
+ language?: keyof LanguageMessages;
112
+ /**
113
+ * when false, skips rendering error templates. Useful when error messages are generated elsewhere to save processing time.
114
+ *
115
+ * @default true
116
+ */
117
+ render?: boolean;
118
+ /**
119
+ * when true, the main error will possess a stack trace, otherwise it will be disabled.
120
+ * Defaults to false for performances reasons. Has no effect on platforms other than V8/node.js as it uses the Stack trace API.
121
+ *
122
+ * @default false
123
+ */
124
+ stack?: boolean;
125
+ /**
126
+ * overrides the way values are wrapped (e.g. `[]` around arrays, `""` around labels).
127
+ * Each key can be set to a string with one (same character before and after the value) or two characters (first character
128
+ * before and second character after), or `false` to disable wrapping.
129
+ */
130
+ wrap?: {
131
+ /**
132
+ * the characters used around `{#label}` references. Defaults to `'"'`.
133
+ *
134
+ * @default '"'
135
+ */
136
+ label?: string | false;
137
+
138
+ /**
139
+ * the characters used around array values. Defaults to `'[]'`
140
+ *
141
+ * @default '[]'
142
+ */
143
+ array?: string | false;
144
+
145
+ /**
146
+ * the characters used around array string values. Defaults to no wrapping.
147
+ *
148
+ * @default false
149
+ */
150
+ string?: string | false;
151
+ };
152
+ }
219
153
 
220
- interface ErrorValidationOptions extends BaseValidationOptions {
221
- messages?: Record<string, LanguageMessageTemplate>;
222
- }
154
+ interface BaseValidationOptions {
155
+ /**
156
+ * when true, stops validation on the first error, otherwise returns all the errors found.
157
+ *
158
+ * @default true
159
+ */
160
+ abortEarly?: boolean;
161
+ /**
162
+ * when true, allows object to contain unknown keys which are ignored.
163
+ *
164
+ * @default false
165
+ */
166
+ allowUnknown?: boolean;
167
+ /**
168
+ * when true, return artifacts alongside the value.
169
+ *
170
+ * @default false
171
+ */
172
+ artifacts?: boolean;
173
+ /**
174
+ * when true, schema caching is enabled (for schemas with explicit caching rules).
175
+ *
176
+ * @default false
177
+ */
178
+ cache?: boolean;
179
+ /**
180
+ * provides an external data set to be used in references
181
+ */
182
+ context?: Context;
183
+ /**
184
+ * when true, attempts to cast values to the required types (e.g. a string to a number).
185
+ *
186
+ * @default true
187
+ */
188
+ convert?: boolean;
189
+ /**
190
+ * sets the string format used when converting dates to strings in error messages and casting.
191
+ *
192
+ * @default 'iso'
193
+ */
194
+ dateFormat?: "date" | "iso" | "string" | "time" | "utc";
195
+ /**
196
+ * when true, valid results and throw errors are decorated with a debug property which includes an array of the validation steps used to generate the returned result.
197
+ *
198
+ * @default false
199
+ */
200
+ debug?: boolean;
201
+ /**
202
+ * error formatting settings.
203
+ */
204
+ errors?: ErrorFormattingOptions;
205
+ /**
206
+ * if false, the external rules set with `any.external()` are ignored, which is required to ignore any external validations in synchronous mode (or an exception is thrown).
207
+ *
208
+ * @default true
209
+ */
210
+ externals?: boolean;
211
+ /**
212
+ * when true, do not apply default values.
213
+ *
214
+ * @default false
215
+ */
216
+ noDefaults?: boolean;
217
+ /**
218
+ * when true, inputs are shallow cloned to include non-enumerable properties.
219
+ *
220
+ * @default false
221
+ */
222
+ nonEnumerables?: boolean;
223
+ /**
224
+ * sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'.
225
+ *
226
+ * @default 'optional'
227
+ */
228
+ presence?: PresenceMode;
229
+ /**
230
+ * when true, ignores unknown keys with a function value.
231
+ *
232
+ * @default false
233
+ */
234
+ skipFunctions?: boolean;
235
+ /**
236
+ * remove unknown elements from objects and arrays.
237
+ * - when true, all unknown elements will be removed
238
+ * - when an object:
239
+ * - objects - set to true to remove unknown keys from objects
240
+ *
241
+ * @default false
242
+ */
243
+ stripUnknown?: boolean | { arrays?: boolean; objects?: boolean };
244
+ }
223
245
 
224
- interface RenameOptions {
225
- /**
226
- * if true, does not delete the old key name, keeping both the new and old keys in place.
227
- *
228
- * @default false
229
- */
230
- alias?: boolean;
231
- /**
232
- * if true, allows renaming multiple keys to the same destination where the last rename wins.
233
- *
234
- * @default false
235
- */
236
- multiple?: boolean;
237
- /**
238
- * if true, allows renaming a key over an existing key.
239
- *
240
- * @default false
241
- */
242
- override?: boolean;
243
- /**
244
- * if true, skip renaming of a key if it's undefined.
245
- *
246
- * @default false
247
- */
248
- ignoreUndefined?: boolean;
249
- }
246
+ interface ValidationOptions extends BaseValidationOptions {
247
+ /**
248
+ * overrides individual error messages. Defaults to no override (`{}`).
249
+ * Messages use the same rules as templates.
250
+ * Variables in double braces `{{var}}` are HTML escaped if the option `errors.escapeHtml` is set to true.
251
+ *
252
+ * @default {}
253
+ */
254
+ messages?: LanguageMessages;
255
+ }
250
256
 
251
- interface TopLevelDomainOptions {
252
- /**
253
- * - `true` to use the IANA list of registered TLDs. This is the default value.
254
- * - `false` to allow any TLD not listed in the `deny` list, if present.
255
- * - A `Set` or array of the allowed TLDs. Cannot be used together with `deny`.
256
- */
257
- allow?: Set<string> | string[] | boolean;
258
- /**
259
- * - A `Set` or array of the forbidden TLDs. Cannot be used together with a custom `allow` list.
260
- */
261
- deny?: Set<string> | string[];
262
- }
257
+ interface AsyncValidationOptions extends ValidationOptions {
258
+ /**
259
+ * when true, artifacts are returned alongside the value (i.e. `{ value, artifacts }`)
260
+ *
261
+ * @default false
262
+ */
263
+ artifacts?: boolean;
264
+ /**
265
+ * when true, warnings are returned alongside the value (i.e. `{ value, warning }`).
266
+ *
267
+ * @default false
268
+ */
269
+ warnings?: boolean;
270
+ }
263
271
 
264
- interface HierarchySeparatorOptions {
265
- /**
266
- * overrides the default `.` hierarchy separator. Set to false to treat the key as a literal value.
267
- *
268
- * @default '.'
269
- */
270
- separator?: string | false;
271
- }
272
+ interface LanguageMessageTemplate {
273
+ source: string;
274
+ rendered: string;
275
+ }
272
276
 
273
- interface DependencyOptions extends HierarchySeparatorOptions {
274
- /**
275
- * overrides the default check for a present value.
276
- *
277
- * @default (resolved) => resolved !== undefined
278
- */
279
- isPresent?: (resolved: any) => boolean;
280
- }
277
+ interface ErrorValidationOptions extends BaseValidationOptions {
278
+ messages?: Record<string, LanguageMessageTemplate>;
279
+ }
281
280
 
282
- interface EmailOptions {
283
- /**
284
- * if `true`, domains ending with a `.` character are permitted
285
- *
286
- * @default false
287
- */
288
- allowFullyQualified?: boolean;
289
- /**
290
- * If `true`, Unicode characters are permitted
291
- *
292
- * @default true
293
- */
294
- allowUnicode?: boolean;
295
- /**
296
- * if `true`, ignore invalid email length errors.
297
- *
298
- * @default false
299
- */
300
- ignoreLength?: boolean;
301
- /**
302
- * if true, allows multiple email addresses in a single string, separated by , or the separator characters.
303
- *
304
- * @default false
305
- */
306
- multiple?: boolean;
307
- /**
308
- * when multiple is true, overrides the default , separator. String can be a single character or multiple separator characters.
309
- *
310
- * @default ','
311
- */
312
- separator?: string | string[];
313
- /**
314
- * Options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the [IANA registry](http://data.iana.org/TLD/tlds-alpha-by-domain.txt)
315
- *
316
- * @default { allow: true }
317
- */
318
- tlds?: TopLevelDomainOptions | false;
319
- /**
320
- * Number of segments required for the domain. Be careful since some domains, such as `io`, directly allow email.
321
- *
322
- * @default 2
323
- */
324
- minDomainSegments?: number;
325
- /**
326
- * The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
327
- *
328
- * @default Infinity
329
- */
330
- maxDomainSegments?: number;
331
- }
281
+ interface RenameOptions {
282
+ /**
283
+ * if true, does not delete the old key name, keeping both the new and old keys in place.
284
+ *
285
+ * @default false
286
+ */
287
+ alias?: boolean;
288
+ /**
289
+ * if true, allows renaming multiple keys to the same destination where the last rename wins.
290
+ *
291
+ * @default false
292
+ */
293
+ multiple?: boolean;
294
+ /**
295
+ * if true, allows renaming a key over an existing key.
296
+ *
297
+ * @default false
298
+ */
299
+ override?: boolean;
300
+ /**
301
+ * if true, skip renaming of a key if it's undefined.
302
+ *
303
+ * @default false
304
+ */
305
+ ignoreUndefined?: boolean;
306
+ }
332
307
 
333
- interface DomainOptions {
334
- /**
335
- * if `true`, domains ending with a `.` character are permitted
336
- *
337
- * @default false
338
- */
339
- allowFullyQualified?: boolean;
340
- /**
341
- * If `true`, Unicode characters are permitted
342
- *
343
- * @default true
344
- */
345
- allowUnicode?: boolean;
308
+ interface TopLevelDomainOptions {
309
+ /**
310
+ * - `true` to use the IANA list of registered TLDs. This is the default value.
311
+ * - `false` to allow any TLD not listed in the `deny` list, if present.
312
+ * - A `Set` or array of the allowed TLDs. Cannot be used together with `deny`.
313
+ */
314
+ allow?: Set<string> | string[] | boolean;
315
+ /**
316
+ * - A `Set` or array of the forbidden TLDs. Cannot be used together with a custom `allow` list.
317
+ */
318
+ deny?: Set<string> | string[];
319
+ }
346
320
 
347
- /**
348
- * Options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the [IANA registry](http://data.iana.org/TLD/tlds-alpha-by-domain.txt)
349
- *
350
- * @default { allow: true }
351
- */
352
- tlds?: TopLevelDomainOptions | false;
353
- /**
354
- * Number of segments required for the domain.
355
- *
356
- * @default 2
357
- */
358
- minDomainSegments?: number;
359
- /**
360
- * The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
361
- *
362
- * @default Infinity
363
- */
364
- maxDomainSegments?: number;
365
- }
321
+ interface HierarchySeparatorOptions {
322
+ /**
323
+ * overrides the default `.` hierarchy separator. Set to false to treat the key as a literal value.
324
+ *
325
+ * @default '.'
326
+ */
327
+ separator?: string | false;
328
+ }
366
329
 
367
- interface HexOptions {
368
- /**
369
- * hex decoded representation must be byte aligned.
370
- * @default false
371
- */
372
- byteAligned?: boolean;
373
- /**
374
- * controls whether the prefix `0x` or `0X` is allowed (or required) on hex strings.
375
- * When `true`, the prefix must be provided.
376
- * When `false`, the prefix is forbidden.
377
- * When `optional`, the prefix is allowed but not required.
378
- *
379
- * @default false
380
- */
381
- prefix?: boolean | 'optional';
382
- }
330
+ interface DependencyOptions extends HierarchySeparatorOptions {
331
+ /**
332
+ * overrides the default check for a present value.
333
+ *
334
+ * @default (resolved) => resolved !== undefined
335
+ */
336
+ isPresent?: (resolved: any) => boolean;
337
+ }
383
338
 
384
- interface IpOptions {
385
- /**
386
- * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture
387
- */
388
- version?: string | string[];
389
- /**
390
- * Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden
391
- */
392
- cidr?: PresenceMode;
393
- }
339
+ interface EmailOptions {
340
+ /**
341
+ * if `true`, domains ending with a `.` character are permitted
342
+ *
343
+ * @default false
344
+ */
345
+ allowFullyQualified?: boolean;
346
+ /**
347
+ * If `true`, Unicode characters are permitted
348
+ *
349
+ * @default true
350
+ */
351
+ allowUnicode?: boolean;
352
+ /**
353
+ * If `true`, underscores (`_`) are allowed in the domain name
354
+ *
355
+ * @default false
356
+ */
357
+ allowUnderscore?: boolean;
358
+ /**
359
+ * if `true`, ignore invalid email length errors.
360
+ *
361
+ * @default false
362
+ */
363
+ ignoreLength?: boolean;
364
+ /**
365
+ * if true, allows multiple email addresses in a single string, separated by , or the separator characters.
366
+ *
367
+ * @default false
368
+ */
369
+ multiple?: boolean;
370
+ /**
371
+ * when multiple is true, overrides the default , separator. String can be a single character or multiple separator characters.
372
+ *
373
+ * @default ','
374
+ */
375
+ separator?: string | string[];
376
+ /**
377
+ * Options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the [IANA registry](http://data.iana.org/TLD/tlds-alpha-by-domain.txt)
378
+ *
379
+ * @default { allow: true }
380
+ */
381
+ tlds?: TopLevelDomainOptions | false;
382
+ /**
383
+ * Number of segments required for the domain. Be careful since some domains, such as `io`, directly allow email.
384
+ *
385
+ * @default 2
386
+ */
387
+ minDomainSegments?: number;
388
+ /**
389
+ * The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
390
+ *
391
+ * @default Infinity
392
+ */
393
+ maxDomainSegments?: number;
394
+ }
394
395
 
395
- type GuidVersions = 'uuidv1' | 'uuidv2' | 'uuidv3' | 'uuidv4' | 'uuidv5' | 'uuidv6' | 'uuidv7' | 'uuidv8';
396
+ interface DomainOptions {
397
+ /**
398
+ * if `true`, domains ending with a `.` character are permitted
399
+ *
400
+ * @default false
401
+ */
402
+ allowFullyQualified?: boolean;
403
+ /**
404
+ * If `true`, Unicode characters are permitted
405
+ *
406
+ * @default true
407
+ */
408
+ allowUnicode?: boolean;
409
+ /**
410
+ * If `true`, underscores (`_`) are allowed in the domain name
411
+ *
412
+ * @default false
413
+ */
414
+ allowUnderscore?: boolean;
415
+ /**
416
+ * Options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the [IANA registry](http://data.iana.org/TLD/tlds-alpha-by-domain.txt)
417
+ *
418
+ * @default { allow: true }
419
+ */
420
+ tlds?: TopLevelDomainOptions | false;
421
+ /**
422
+ * Number of segments required for the domain.
423
+ *
424
+ * @default 2
425
+ */
426
+ minDomainSegments?: number;
427
+ /**
428
+ * The maximum number of domain segments (e.g. `x.y.z` has 3 segments) allowed. Defaults to no limit.
429
+ *
430
+ * @default Infinity
431
+ */
432
+ maxDomainSegments?: number;
433
+ }
396
434
 
397
- interface GuidOptions {
398
- version?: GuidVersions[] | GuidVersions;
399
- separator?: boolean | '-' | ':';
400
- }
435
+ interface HexOptions {
436
+ /**
437
+ * hex decoded representation must be byte aligned.
438
+ * @default false
439
+ */
440
+ byteAligned?: boolean;
441
+ /**
442
+ * controls whether the prefix `0x` or `0X` is allowed (or required) on hex strings.
443
+ * When `true`, the prefix must be provided.
444
+ * When `false`, the prefix is forbidden.
445
+ * When `optional`, the prefix is allowed but not required.
446
+ *
447
+ * @default false
448
+ */
449
+ prefix?: boolean | "optional";
450
+ }
401
451
 
402
- interface UriOptions {
403
- /**
404
- * Specifies one or more acceptable Schemes, should only include the scheme name.
405
- * Can be an Array or String (strings are automatically escaped for use in a Regular Expression).
406
- */
407
- scheme?: string | RegExp | Array<string | RegExp>;
408
- /**
409
- * Allow relative URIs.
410
- *
411
- * @default false
412
- */
413
- allowRelative?: boolean;
414
- /**
415
- * Restrict only relative URIs.
416
- *
417
- * @default false
418
- */
419
- relativeOnly?: boolean;
420
- /**
421
- * Allows unencoded square brackets inside the query string.
422
- * This is NOT RFC 3986 compliant but query strings like abc[]=123&abc[]=456 are very common these days.
423
- *
424
- * @default false
425
- */
426
- allowQuerySquareBrackets?: boolean;
427
- /**
428
- * Validate the domain component using the options specified in `string.domain()`.
429
- */
430
- domain?: DomainOptions;
431
- /**
432
- * Encode URI before validation.
433
- *
434
- * @default false
435
- */
436
- encodeUri?: boolean;
437
- }
452
+ interface IpOptions {
453
+ /**
454
+ * One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture
455
+ */
456
+ version?: string | string[];
457
+ /**
458
+ * Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden
459
+ */
460
+ cidr?: PresenceMode;
461
+ }
462
+
463
+ type GuidVersions =
464
+ | "uuidv1"
465
+ | "uuidv2"
466
+ | "uuidv3"
467
+ | "uuidv4"
468
+ | "uuidv5"
469
+ | "uuidv6"
470
+ | "uuidv7"
471
+ | "uuidv8";
472
+
473
+ interface GuidOptions {
474
+ version?: GuidVersions[] | GuidVersions;
475
+ separator?: boolean | "-" | ":";
476
+ /**
477
+ * Defines the allowed or required GUID wrapper characters where:
478
+ * - `undefined` - (default) the GUID can be optionally wrapped with `{}`, `[]`, or `()`. The opening and closing characters must be a matching pair.
479
+ * - `true` - the GUID must be wrapped with `{}`, `[]`, or `()`. The opening and closing characters must be a matching pair.
480
+ * - `false` - wrapper characters are not allowed.
481
+ * - `'['`, `'{'`, or `'('` - a specific wrapper is required (e.g., if `wrapper` is `'['`, the GUID must be enclosed in square brackets).
482
+ */
483
+ wrapper?: true | false | "[" | "{" | "(" | undefined;
484
+ }
438
485
 
439
- interface DataUriOptions {
440
- /**
441
- * optional parameter defaulting to true which will require `=` padding if true or make padding optional if false
442
- *
443
- * @default true
444
- */
445
- paddingRequired?: boolean;
446
- }
486
+ interface UriOptions {
487
+ /**
488
+ * Specifies one or more acceptable Schemes, should only include the scheme name.
489
+ * Can be an Array or String (strings are automatically escaped for use in a Regular Expression).
490
+ */
491
+ scheme?: string | RegExp | Array<string | RegExp>;
492
+ /**
493
+ * Allow relative URIs.
494
+ *
495
+ * @default false
496
+ */
497
+ allowRelative?: boolean;
498
+ /**
499
+ * Restrict only relative URIs.
500
+ *
501
+ * @default false
502
+ */
503
+ relativeOnly?: boolean;
504
+ /**
505
+ * Allows unencoded square brackets inside the query string.
506
+ * This is NOT RFC 3986 compliant but query strings like abc[]=123&abc[]=456 are very common these days.
507
+ *
508
+ * @default false
509
+ */
510
+ allowQuerySquareBrackets?: boolean;
511
+ /**
512
+ * Validate the domain component using the options specified in `string.domain()`.
513
+ */
514
+ domain?: DomainOptions;
515
+ /**
516
+ * Encode URI before validation.
517
+ *
518
+ * @default false
519
+ */
520
+ encodeUri?: boolean;
521
+ }
447
522
 
448
- interface Base64Options extends Pick<DataUriOptions, 'paddingRequired'> {
449
- /**
450
- * if true, uses the URI-safe base64 format which replaces `+` with `-` and `\` with `_`.
451
- *
452
- * @default false
453
- */
454
- urlSafe?: boolean;
455
- }
523
+ interface DataUriOptions {
524
+ /**
525
+ * optional parameter defaulting to true which will require `=` padding if true or make padding optional if false
526
+ *
527
+ * @default true
528
+ */
529
+ paddingRequired?: boolean;
530
+ }
456
531
 
457
- interface SwitchCases {
458
- /**
459
- * the required condition joi type.
460
- */
461
- is: SchemaLike;
462
- /**
463
- * the alternative schema type if the condition is true.
464
- */
465
- then: SchemaLike;
466
- }
532
+ interface Base64Options extends Pick<DataUriOptions, "paddingRequired"> {
533
+ /**
534
+ * if true, uses the URI-safe base64 format which replaces `+` with `-` and `\` with `_`.
535
+ *
536
+ * @default false
537
+ */
538
+ urlSafe?: boolean;
539
+ }
467
540
 
468
- interface SwitchDefault {
469
- /**
470
- * the alternative schema type if no cases matched.
471
- * Only one otherwise statement is allowed in switch as the last array item.
472
- */
473
- otherwise: SchemaLike;
474
- }
541
+ interface SwitchCases {
542
+ /**
543
+ * the required condition joi type.
544
+ */
545
+ is: SchemaLike;
546
+ /**
547
+ * the alternative schema type if the condition is true.
548
+ */
549
+ then: SchemaLike;
550
+ }
475
551
 
476
- interface WhenOptions {
477
- /**
478
- * the required condition joi type.
479
- */
480
- is?: SchemaLike;
552
+ interface SwitchDefault {
553
+ /**
554
+ * the alternative schema type if no cases matched.
555
+ * Only one otherwise statement is allowed in switch as the last array item.
556
+ */
557
+ otherwise: SchemaLike;
558
+ }
481
559
 
482
- /**
483
- * the negative version of `is` (`then` and `otherwise` have reverse
484
- * roles).
485
- */
486
- not?: SchemaLike;
560
+ interface WhenOptions<ThenSchema = any, OtherwiseSchema = any> {
561
+ /**
562
+ * the required condition joi type.
563
+ */
564
+ is?: SchemaLike;
487
565
 
488
- /**
489
- * the alternative schema type if the condition is true. Required if otherwise or switch are missing.
490
- */
491
- then?: SchemaLike;
566
+ /**
567
+ * the negative version of `is` (`then` and `otherwise` have reverse
568
+ * roles).
569
+ */
570
+ not?: SchemaLike;
492
571
 
493
- /**
494
- * the alternative schema type if the condition is false. Required if then or switch are missing.
495
- */
496
- otherwise?: SchemaLike;
572
+ /**
573
+ * the alternative schema type if the condition is true. Required if otherwise or switch are missing.
574
+ */
575
+ then?: SchemaLike<ThenSchema>;
497
576
 
498
- /**
499
- * the list of cases. Required if then is missing. Required if then or otherwise are missing.
500
- */
501
- switch?: Array<SwitchCases | SwitchDefault>;
577
+ /**
578
+ * the alternative schema type if the condition is false. Required if then or switch are missing.
579
+ */
580
+ otherwise?: SchemaLike<OtherwiseSchema>;
502
581
 
503
- /**
504
- * whether to stop applying further conditions if the condition is true.
505
- */
506
- break?: boolean;
507
- }
582
+ /**
583
+ * the list of cases. Required if then is missing. Required if then or otherwise are missing.
584
+ */
585
+ switch?: Array<SwitchCases | SwitchDefault>;
508
586
 
509
- interface WhenSchemaOptions {
510
- /**
511
- * the alternative schema type if the condition is true. Required if otherwise is missing.
512
- */
513
- then?: SchemaLike;
514
- /**
515
- * the alternative schema type if the condition is false. Required if then is missing.
516
- */
517
- otherwise?: SchemaLike;
518
- }
587
+ /**
588
+ * whether to stop applying further conditions if the condition is true.
589
+ */
590
+ break?: boolean;
591
+ }
519
592
 
520
- interface Cache {
521
- /**
522
- * Add an item to the cache.
523
- *
524
- * Note that key and value can be anything including objects, array, etc.
525
- */
526
- set(key: any, value: any): void;
593
+ interface WhenSchemaOptions<ThenSchema = any, OtherwiseSchema = any> {
594
+ /**
595
+ * the alternative schema type if the condition is true. Required if otherwise is missing.
596
+ */
597
+ then?: SchemaLike<ThenSchema>;
598
+ /**
599
+ * the alternative schema type if the condition is false. Required if then is missing.
600
+ */
601
+ otherwise?: SchemaLike<OtherwiseSchema>;
602
+ }
527
603
 
528
- /**
529
- * Retrieve an item from the cache.
530
- *
531
- * Note that key and value can be anything including objects, array, etc.
532
- */
533
- get(key: any): any;
534
- }
535
- interface CacheProvisionOptions {
536
- /**
537
- * number of items to store in the cache before the least used items are dropped.
538
- *
539
- * @default 1000
540
- */
541
- max: number;
542
- }
604
+ interface Cache {
605
+ /**
606
+ * Add an item to the cache.
607
+ *
608
+ * Note that key and value can be anything including objects, array, etc.
609
+ */
610
+ set(key: any, value: any): void;
543
611
 
544
- interface CacheConfiguration {
545
- /**
546
- * Provisions a simple LRU cache for caching simple inputs (`undefined`, `null`, strings, numbers, and booleans).
547
- */
548
- provision(options?: CacheProvisionOptions): void;
549
- }
612
+ /**
613
+ * Retrieve an item from the cache.
614
+ *
615
+ * Note that key and value can be anything including objects, array, etc.
616
+ */
617
+ get(key: any): any;
618
+ }
619
+ interface CacheProvisionOptions {
620
+ /**
621
+ * number of items to store in the cache before the least used items are dropped.
622
+ *
623
+ * @default 1000
624
+ */
625
+ max: number;
626
+ }
550
627
 
551
- interface CompileOptions {
552
- /**
553
- * If true and the provided schema is (or contains parts) using an older version of joi, will return a compiled schema that is compatible with the older version.
554
- * If false, the schema is always compiled using the current version and if older schema components are found, an error is thrown.
555
- */
556
- legacy: boolean;
557
- }
628
+ interface CacheConfiguration {
629
+ /**
630
+ * Provisions a simple LRU cache for caching simple inputs (`undefined`, `null`, strings, numbers, and booleans).
631
+ */
632
+ provision(options?: CacheProvisionOptions): void;
633
+ }
558
634
 
559
- interface IsSchemaOptions {
560
- /**
561
- * If true, will identify schemas from older versions of joi, otherwise will throw an error.
562
- *
563
- * @default false
564
- */
565
- legacy: boolean;
566
- }
635
+ interface CompileOptions {
636
+ /**
637
+ * If true and the provided schema is (or contains parts) using an older version of joi, will return a compiled schema that is compatible with the older version.
638
+ * If false, the schema is always compiled using the current version and if older schema components are found, an error is thrown.
639
+ */
640
+ legacy: boolean;
641
+ }
567
642
 
568
- interface ReferenceOptions extends HierarchySeparatorOptions {
569
- /**
570
- * a function with the signature `function(value)` where `value` is the resolved reference value and the return value is the adjusted value to use.
571
- * Note that the adjust feature will not perform any type validation on the adjusted value and it must match the value expected by the rule it is used in.
572
- * Cannot be used with `map`.
573
- *
574
- * @example `(value) => value + 5`
575
- */
576
- adjust?: (value: any) => any;
643
+ interface IsSchemaOptions {
644
+ /**
645
+ * If true, will identify schemas from older versions of joi, otherwise will throw an error.
646
+ *
647
+ * @default false
648
+ */
649
+ legacy: boolean;
650
+ }
577
651
 
578
- /**
579
- * an array of array pairs using the format `[[key, value], [key, value]]` used to maps the resolved reference value to another value.
580
- * If the resolved value is not in the map, it is returned as-is.
581
- * Cannot be used with `adjust`.
582
- */
583
- map?: Array<[any, any]>;
652
+ interface ReferenceOptions extends HierarchySeparatorOptions {
653
+ /**
654
+ * a function with the signature `function(value)` where `value` is the resolved reference value and the return value is the adjusted value to use.
655
+ * Note that the adjust feature will not perform any type validation on the adjusted value and it must match the value expected by the rule it is used in.
656
+ * Cannot be used with `map`.
657
+ *
658
+ * @example `(value) => value + 5`
659
+ */
660
+ adjust?: (value: any) => any;
584
661
 
585
- /**
586
- * overrides default prefix characters.
587
- */
588
- prefix?: {
589
- /**
590
- * references to the globally provided context preference.
591
- *
592
- * @default '$'
593
- */
594
- global?: string;
595
-
596
- /**
597
- * references to error-specific or rule specific context.
598
- *
599
- * @default '#'
600
- */
601
- local?: string;
602
-
603
- /**
604
- * references to the root value being validated.
605
- *
606
- * @default '/'
607
- */
608
- root?: string;
609
- };
662
+ /**
663
+ * an array of array pairs using the format `[[key, value], [key, value]]` used to maps the resolved reference value to another value.
664
+ * If the resolved value is not in the map, it is returned as-is.
665
+ * Cannot be used with `adjust`.
666
+ */
667
+ map?: Array<[any, any]>;
610
668
 
611
- /**
612
- * If set to a number, sets the reference relative starting point.
613
- * Cannot be combined with separator prefix characters.
614
- * Defaults to the reference key prefix (or 1 if none present)
615
- */
616
- ancestor?: number;
669
+ /**
670
+ * overrides default prefix characters.
671
+ */
672
+ prefix?: {
673
+ /**
674
+ * references to the globally provided context preference.
675
+ *
676
+ * @default '$'
677
+ */
678
+ global?: string;
679
+
680
+ /**
681
+ * references to error-specific or rule specific context.
682
+ *
683
+ * @default '#'
684
+ */
685
+ local?: string;
686
+
687
+ /**
688
+ * references to the root value being validated.
689
+ *
690
+ * @default '/'
691
+ */
692
+ root?: string;
693
+ };
617
694
 
618
- /**
619
- * creates an in-reference.
620
- */
621
- in?: boolean;
695
+ /**
696
+ * If set to a number, sets the reference relative starting point.
697
+ * Cannot be combined with separator prefix characters.
698
+ * Defaults to the reference key prefix (or 1 if none present)
699
+ */
700
+ ancestor?: number;
622
701
 
623
- /**
624
- * when true, the reference resolves by reaching into maps and sets.
625
- */
626
- iterables?: boolean;
702
+ /**
703
+ * creates an in-reference.
704
+ */
705
+ in?: boolean;
627
706
 
628
- /**
629
- * when true, the value of the reference is used instead of its name in error messages
630
- * and template rendering. Defaults to false.
631
- */
632
- render?: boolean;
633
- }
707
+ /**
708
+ * when true, the reference resolves by reaching into maps and sets.
709
+ */
710
+ iterables?: boolean;
634
711
 
635
- interface StringRegexOptions {
636
- /**
637
- * optional pattern name.
638
- */
639
- name?: string;
712
+ /**
713
+ * when true, the value of the reference is used instead of its name in error messages
714
+ * and template rendering. Defaults to false.
715
+ */
716
+ render?: boolean;
717
+ }
640
718
 
641
- /**
642
- * when true, the provided pattern will be disallowed instead of required.
643
- *
644
- * @default false
645
- */
646
- invert?: boolean;
647
- }
719
+ interface StringRegexOptions {
720
+ /**
721
+ * optional pattern name.
722
+ */
723
+ name?: string;
648
724
 
649
- interface RuleOptions {
650
- /**
651
- * if true, the rules will not be replaced by the same unique rule later.
652
- *
653
- * For example, `Joi.number().min(1).rule({ keep: true }).min(2)` will keep both `min()` rules instead of the later rule overriding the first.
654
- *
655
- * @default false
656
- */
657
- keep?: boolean;
725
+ /**
726
+ * when true, the provided pattern will be disallowed instead of required.
727
+ *
728
+ * @default false
729
+ */
730
+ invert?: boolean;
731
+ }
658
732
 
659
- /**
660
- * a single message string or a messages object where each key is an error code and corresponding message string as value.
661
- *
662
- * The object is the same as the messages used as an option in `any.validate()`.
663
- * The strings can be plain messages or a message template.
664
- */
665
- message?: string | LanguageMessages;
733
+ interface RuleOptions {
734
+ /**
735
+ * if true, the rules will not be replaced by the same unique rule later.
736
+ *
737
+ * For example, `Joi.number().min(1).rule({ keep: true }).min(2)` will keep both `min()` rules instead of the later rule overriding the first.
738
+ *
739
+ * @default false
740
+ */
741
+ keep?: boolean;
666
742
 
667
- /**
668
- * if true, turns any error generated by the ruleset to warnings.
669
- */
670
- warn?: boolean;
671
- }
743
+ /**
744
+ * a single message string or a messages object where each key is an error code and corresponding message string as value.
745
+ *
746
+ * The object is the same as the messages used as an option in `any.validate()`.
747
+ * The strings can be plain messages or a message template.
748
+ */
749
+ message?: string | LanguageMessages;
672
750
 
673
- interface ErrorReport extends Error {
674
- code: string;
675
- flags: Record<string, ExtensionFlag>;
676
- path: string[];
677
- prefs: ErrorValidationOptions;
678
- messages: LanguageMessages;
679
- state: State;
680
- value: any;
681
- local: any;
682
- }
751
+ /**
752
+ * if true, turns any error generated by the ruleset to warnings.
753
+ */
754
+ warn?: boolean;
755
+ }
756
+
757
+ interface ErrorReport extends Error {
758
+ code: string;
759
+ flags: Record<string, ExtensionFlag>;
760
+ path: string[];
761
+ prefs: ErrorValidationOptions;
762
+ messages: LanguageMessages;
763
+ state: State;
764
+ value: any;
765
+ local: any;
766
+ }
683
767
 
684
- interface ValidationError extends Error {
685
- name: 'ValidationError';
768
+ interface ValidationError extends Error {
769
+ name: "ValidationError";
686
770
 
687
- isJoi: boolean;
771
+ isJoi: boolean;
688
772
 
689
- /**
690
- * array of errors.
691
- */
692
- details: ValidationErrorItem[];
773
+ /**
774
+ * array of errors.
775
+ */
776
+ details: ValidationErrorItem[];
693
777
 
694
- /**
695
- * function that returns a string with an annotated version of the object pointing at the places where errors occurred.
696
- *
697
- * NOTE: This method does not exist in browser builds of Joi
698
- *
699
- * @param stripColors - if truthy, will strip the colors out of the output.
700
- */
701
- annotate(stripColors?: boolean): string;
778
+ /**
779
+ * function that returns a string with an annotated version of the object pointing at the places where errors occurred.
780
+ *
781
+ * NOTE: This method does not exist in browser builds of Joi
782
+ *
783
+ * @param stripColors - if truthy, will strip the colors out of the output.
784
+ */
785
+ annotate(stripColors?: boolean): string;
702
786
 
703
- _original: any;
704
- }
787
+ _original: any;
788
+ }
705
789
 
706
- interface ValidationErrorItem {
707
- message: string;
708
- path: Array<string | number>;
709
- type: string;
710
- context?: Context;
711
- }
790
+ interface ValidationErrorItem {
791
+ message: string;
792
+ path: Array<string | number>;
793
+ type: string;
794
+ context?: Context;
795
+ }
712
796
 
713
- type ValidationErrorFunction = (errors: ErrorReport[]) => string | ValidationErrorItem | Error | ErrorReport[];
797
+ type ValidationErrorFunction = (
798
+ errors: ErrorReport[]
799
+ ) => string | ValidationErrorItem | Error | ErrorReport[];
714
800
 
715
- interface ValidationWarning {
716
- message: string;
801
+ interface ValidationWarning {
802
+ message: string;
717
803
 
718
- details: ValidationErrorItem[];
719
- }
804
+ details: ValidationErrorItem[];
805
+ }
720
806
 
721
- type ValidationResult<TSchema = any> = {
807
+ type ValidationResult<TSchema = any> =
808
+ | {
722
809
  error: undefined;
723
810
  warning?: ValidationError;
724
811
  value: TSchema;
725
- } | {
812
+ }
813
+ | {
726
814
  error: ValidationError;
727
815
  warning?: ValidationError;
728
816
  value: any;
729
- }
817
+ };
730
818
 
731
- interface CreateErrorOptions {
732
- flags?: boolean;
733
- messages?: LanguageMessages;
734
- }
819
+ interface CreateErrorOptions {
820
+ flags?: boolean;
821
+ messages?: LanguageMessages;
822
+ }
735
823
 
736
- interface ModifyOptions {
737
- each?: boolean;
738
- once?: boolean;
739
- ref?: boolean;
740
- schema?: boolean;
741
- }
824
+ interface ModifyOptions {
825
+ each?: boolean;
826
+ once?: boolean;
827
+ ref?: boolean;
828
+ schema?: boolean;
829
+ }
742
830
 
743
- interface MutateRegisterOptions {
744
- family?: any;
745
- key?: any;
746
- }
831
+ interface MutateRegisterOptions {
832
+ family?: any;
833
+ key?: any;
834
+ }
747
835
 
748
- interface SetFlagOptions {
749
- clone: boolean;
750
- }
836
+ interface SetFlagOptions {
837
+ clone: boolean;
838
+ }
751
839
 
752
- interface CustomHelpers<V = any> {
753
- schema: ExtensionBoundSchema;
754
- state: State;
755
- prefs: ValidationOptions;
756
- original: V;
757
- warn: (code: string, local?: Context) => void;
758
- error: (code: string, local?: Context, localState?: State) => ErrorReport;
759
- message: (messages: LanguageMessages, local?: Context) => ErrorReport;
760
- }
840
+ interface CustomHelpers<V = any> {
841
+ schema: ExtensionBoundSchema;
842
+ state: State;
843
+ prefs: ValidationOptions;
844
+ original: V;
845
+ warn: (code: string, local?: Context) => void;
846
+ error: (code: string, local?: Context, localState?: State) => ErrorReport;
847
+ message: (messages: LanguageMessages, local?: Context) => ErrorReport;
848
+ }
761
849
 
762
- type CustomValidator<V = any, R = V> = (value: V, helpers: CustomHelpers<R>) => R | ErrorReport;
763
-
764
- interface ExternalHelpers<V = any> {
765
- schema: ExtensionBoundSchema;
766
- linked: ExtensionBoundSchema | null;
767
- state: State;
768
- prefs: ValidationOptions;
769
- original: V;
770
- warn: (code: string, local?: Context) => void;
771
- error: (code: string, local?: Context) => ErrorReport;
772
- message: (messages: LanguageMessages, local?: Context) => ErrorReport;
773
- }
850
+ type CustomValidator<V = any, R = V> = (
851
+ value: V,
852
+ helpers: CustomHelpers<R>
853
+ ) => R | ErrorReport;
774
854
 
775
- type ExternalValidationFunction<V = any, R = V> = (value: V, helpers: ExternalHelpers<R>) => R | undefined;
776
-
777
- type SchemaLikeWithoutArray = string | number | boolean | null | Schema | SchemaMap;
778
- type SchemaLike = SchemaLikeWithoutArray | object;
779
-
780
- type NullableType<T> = undefined | null | T
781
-
782
- type IsPrimitiveSubset<T> =
783
- [T] extends [string]
784
- ? true
785
- : [T] extends [number]
786
- ? true
787
- : [T] extends [bigint]
788
- ? true
789
- : [T] extends [boolean]
790
- ? true
791
- : [T] extends [symbol]
792
- ? true
793
- : [T] extends [null]
794
- ? true
795
- : [T] extends [undefined]
796
- ? true
797
- : false;
798
-
799
- type IsUnion<T, U extends T = T> =
800
- T extends unknown ? [U] extends [T] ? false : true : false;
801
-
802
- type IsNonPrimitiveSubsetUnion<T> = true extends IsUnion<T> ? true extends IsPrimitiveSubset<T> ? false : true : false;
803
-
804
- type ObjectPropertiesSchema<T = any> =
805
- true extends IsNonPrimitiveSubsetUnion<Exclude<T, undefined | null>>
806
- ? Joi.AlternativesSchema
807
- : T extends NullableType<string>
808
- ? Joi.StringSchema
809
- : T extends NullableType<number>
810
- ? Joi.NumberSchema
811
- : T extends NullableType<bigint>
812
- ? Joi.NumberSchema
813
- : T extends NullableType<boolean>
814
- ? Joi.BooleanSchema
815
- : T extends NullableType<Date>
816
- ? Joi.DateSchema
817
- : T extends NullableType<Buffer>
818
- ? Joi.BinarySchema
819
- : T extends NullableType<Array<any>>
820
- ? Joi.ArraySchema
821
- : T extends NullableType<object>
822
- ? (StrictSchemaMap<T> | ObjectSchema<T>)
823
- : never
824
-
825
- type PartialSchemaMap<TSchema = any> = {
826
- [key in keyof TSchema]?: SchemaLike | SchemaLike[];
827
- }
855
+ interface ExternalHelpers<V = any> {
856
+ schema: ExtensionBoundSchema;
857
+ linked: ExtensionBoundSchema | null;
858
+ state: State;
859
+ prefs: ValidationOptions;
860
+ original: V;
861
+ warn: (code: string, local?: Context) => void;
862
+ error: (code: string, local?: Context) => ErrorReport;
863
+ message: (messages: LanguageMessages, local?: Context) => ErrorReport;
864
+ }
865
+
866
+ type ExternalValidationFunction<V = any, R = V> = (
867
+ value: V,
868
+ helpers: ExternalHelpers<R>
869
+ ) => R | undefined;
870
+
871
+ type Primitives = string | number | boolean | bigint | symbol | null;
872
+
873
+ type SchemaLikeWithoutArray<TSchema = any> = Exclude<
874
+ Primitives | Schema<TSchema> | SchemaMap<TSchema>,
875
+ any[]
876
+ >;
877
+ type SchemaLike<TSchema = any> = SchemaLikeWithoutArray<TSchema> | object;
878
+
879
+ type NullableType<T> = undefined | null | T;
880
+
881
+ type IsPrimitiveSubset<T> = [T] extends [string]
882
+ ? true
883
+ : [T] extends [number]
884
+ ? true
885
+ : [T] extends [bigint]
886
+ ? true
887
+ : [T] extends [boolean]
888
+ ? true
889
+ : [T] extends [symbol]
890
+ ? true
891
+ : [T] extends [null]
892
+ ? true
893
+ : [T] extends [undefined]
894
+ ? true
895
+ : false;
896
+
897
+ type IsUnion<T, U extends T = T> = T extends unknown
898
+ ? [U] extends [T]
899
+ ? false
900
+ : true
901
+ : false;
902
+
903
+ type IsNonPrimitiveSubsetUnion<T> = true extends IsUnion<T>
904
+ ? true extends IsPrimitiveSubset<T>
905
+ ? false
906
+ : true
907
+ : false;
908
+
909
+ type ObjectPropertiesSchema<T = any> = true extends IsNonPrimitiveSubsetUnion<
910
+ Exclude<T, undefined | null>
911
+ >
912
+ ? Joi.AlternativesSchema
913
+ : T extends NullableType<string>
914
+ ? Joi.StringSchema
915
+ : T extends NullableType<number>
916
+ ? Joi.NumberSchema
917
+ : T extends NullableType<bigint>
918
+ ? Joi.NumberSchema
919
+ : T extends NullableType<boolean>
920
+ ? Joi.BooleanSchema
921
+ : T extends NullableType<Date>
922
+ ? Joi.DateSchema
923
+ : T extends NullableType<Buffer>
924
+ ? Joi.BinarySchema
925
+ : T extends NullableType<Array<any>>
926
+ ? Joi.ArraySchema
927
+ : T extends NullableType<object>
928
+ ? StrictSchemaMap<T> | ObjectSchema<T>
929
+ : never;
930
+
931
+ type PartialSchemaMap<TSchema = any> = {
932
+ [key in keyof TSchema]?: SchemaLike | SchemaLike[];
933
+ };
828
934
 
829
- type StrictSchemaMap<TSchema = any> = {
830
- [key in keyof TSchema]-?: ObjectPropertiesSchema<TSchema[key]>
935
+ type StrictSchemaMap<TSchema = any> = {
936
+ [key in keyof TSchema]-?: ObjectPropertiesSchema<TSchema[key]>;
937
+ };
938
+
939
+ type SchemaMap<TSchema = any, isStrict = false> = isStrict extends true
940
+ ? StrictSchemaMap<TSchema>
941
+ : PartialSchemaMap<TSchema>;
942
+
943
+ type Schema<P = any> =
944
+ | AnySchema<P>
945
+ | ArraySchema<P>
946
+ | AlternativesSchema<P>
947
+ | BinarySchema<P>
948
+ | BooleanSchema<P>
949
+ | DateSchema<P>
950
+ | FunctionSchema<P>
951
+ | NumberSchema<P>
952
+ | ObjectSchema<P>
953
+ | StringSchema<P>
954
+ | LinkSchema<P>
955
+ | SymbolSchema<P>;
956
+
957
+ type SchemaFunction = (schema: Schema) => Schema;
958
+
959
+ interface AddRuleOptions {
960
+ name: string;
961
+ args?: {
962
+ [key: string]: any;
831
963
  };
964
+ }
832
965
 
833
- type SchemaMap<TSchema = any, isStrict = false> = isStrict extends true ? StrictSchemaMap<TSchema> : PartialSchemaMap<TSchema>
834
-
835
- type Schema<P = any> =
836
- | AnySchema<P>
837
- | ArraySchema<P>
838
- | AlternativesSchema<P>
839
- | BinarySchema<P>
840
- | BooleanSchema<P>
841
- | DateSchema<P>
842
- | FunctionSchema<P>
843
- | NumberSchema<P>
844
- | ObjectSchema<P>
845
- | StringSchema<P>
846
- | LinkSchema<P>
847
- | SymbolSchema<P>;
848
-
849
- type SchemaFunction = (schema: Schema) => Schema;
850
-
851
- interface AddRuleOptions {
852
- name: string;
853
- args?: {
854
- [key: string]: any;
855
- };
856
- }
857
-
858
- interface GetRuleOptions {
859
- args?: Record<string, any>;
860
- method?: string;
861
- name: string;
862
- operator?: string;
863
- }
966
+ interface GetRuleOptions {
967
+ args?: Record<string, any>;
968
+ method?: string;
969
+ name: string;
970
+ operator?: string;
971
+ }
864
972
 
865
- interface SchemaInternals {
866
- /**
867
- * Parent schema object.
868
- */
869
- $_super: Schema;
973
+ interface SchemaInternals {
974
+ /**
975
+ * Parent schema object.
976
+ */
977
+ $_super: Schema;
870
978
 
871
- /**
872
- * Terms of current schema.
873
- */
874
- $_terms: Record<string, any>;
979
+ /**
980
+ * Terms of current schema.
981
+ */
982
+ $_terms: Record<string, any>;
875
983
 
876
- /**
877
- * Adds a rule to current validation schema.
878
- */
879
- $_addRule(rule: string | AddRuleOptions): Schema;
984
+ /**
985
+ * Adds a rule to current validation schema.
986
+ */
987
+ $_addRule(rule: string | AddRuleOptions): Schema;
880
988
 
881
- /**
882
- * Internally compiles schema.
883
- */
884
- $_compile(schema: SchemaLike, options?: CompileOptions): Schema;
989
+ /**
990
+ * Internally compiles schema.
991
+ */
992
+ $_compile(schema: SchemaLike, options?: CompileOptions): Schema;
885
993
 
886
- /**
887
- * Creates a joi error object.
888
- */
889
- $_createError(
890
- code: string,
891
- value: any,
892
- context: Context,
893
- state: State,
894
- prefs: ValidationOptions,
895
- options?: CreateErrorOptions,
896
- ): Err;
994
+ /**
995
+ * Creates a joi error object.
996
+ */
997
+ $_createError(
998
+ code: string,
999
+ value: any,
1000
+ context: Context,
1001
+ state: State,
1002
+ prefs: ValidationOptions,
1003
+ options?: CreateErrorOptions
1004
+ ): Err;
897
1005
 
898
- /**
899
- * Get value from given flag.
900
- */
901
- $_getFlag(name: string): any;
1006
+ /**
1007
+ * Get value from given flag.
1008
+ */
1009
+ $_getFlag(name: string): any;
902
1010
 
903
- /**
904
- * Retrieve some rule configuration.
905
- */
906
- $_getRule(name: string): GetRuleOptions | undefined;
1011
+ /**
1012
+ * Retrieve some rule configuration.
1013
+ */
1014
+ $_getRule(name: string): GetRuleOptions | undefined;
907
1015
 
908
- $_mapLabels(path: string | string[]): string;
1016
+ $_mapLabels(path: string | string[]): string;
909
1017
 
910
- /**
911
- * Returns true if validations runs fine on given value.
912
- */
913
- $_match(value: any, state: State, prefs: ValidationOptions): boolean;
1018
+ /**
1019
+ * Returns true if validations runs fine on given value.
1020
+ */
1021
+ $_match(value: any, state: State, prefs: ValidationOptions): boolean;
914
1022
 
915
- $_modify(options?: ModifyOptions): Schema;
1023
+ $_modify(options?: ModifyOptions): Schema;
916
1024
 
917
- /**
918
- * Resets current schema.
919
- */
920
- $_mutateRebuild(): this;
1025
+ /**
1026
+ * Resets current schema.
1027
+ */
1028
+ $_mutateRebuild(): this;
921
1029
 
922
- $_mutateRegister(schema: Schema, options?: MutateRegisterOptions): void;
1030
+ $_mutateRegister(schema: Schema, options?: MutateRegisterOptions): void;
923
1031
 
924
- /**
925
- * Get value from given property.
926
- */
927
- $_property(name: string): any;
1032
+ /**
1033
+ * Get value from given property.
1034
+ */
1035
+ $_property(name: string): any;
928
1036
 
929
- /**
930
- * Get schema at given path.
931
- */
932
- $_reach(path: string[]): Schema;
1037
+ /**
1038
+ * Get schema at given path.
1039
+ */
1040
+ $_reach(path: string[]): Schema;
933
1041
 
934
- /**
935
- * Get current schema root references.
936
- */
937
- $_rootReferences(): any;
1042
+ /**
1043
+ * Get current schema root references.
1044
+ */
1045
+ $_rootReferences(): any;
938
1046
 
939
- /**
940
- * Set flag to given value.
941
- */
942
- $_setFlag(flag: string, value: any, options?: SetFlagOptions): void;
1047
+ /**
1048
+ * Set flag to given value.
1049
+ */
1050
+ $_setFlag(flag: string, value: any, options?: SetFlagOptions): void;
943
1051
 
944
- /**
945
- * Runs internal validations against given value.
946
- */
947
- $_validate(value: any, state: State, prefs: ValidationOptions): ValidationResult;
948
- }
1052
+ /**
1053
+ * Runs internal validations against given value.
1054
+ */
1055
+ $_validate(
1056
+ value: any,
1057
+ state: State,
1058
+ prefs: ValidationOptions
1059
+ ): ValidationResult;
1060
+ }
949
1061
 
950
- interface AnySchema<TSchema = any> extends SchemaInternals {
951
- /**
952
- * Flags of current schema.
953
- */
954
- _flags: Record<string, any>;
1062
+ interface AnySchema<TSchema = any>
1063
+ extends SchemaInternals,
1064
+ StandardSchemaV1<TSchema> {
1065
+ /**
1066
+ * Flags of current schema.
1067
+ */
1068
+ _flags: Record<string, any>;
955
1069
 
956
- /**
957
- * Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
958
- */
959
- $: this;
1070
+ /**
1071
+ * Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
1072
+ */
1073
+ $: this;
960
1074
 
961
- /**
962
- * Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
963
- */
964
- ruleset: this;
1075
+ /**
1076
+ * Starts a ruleset in order to apply multiple rule options. The set ends when `rule()`, `keep()`, `message()`, or `warn()` is called.
1077
+ */
1078
+ ruleset: this;
965
1079
 
966
- type?: Types | string;
1080
+ type?: Types | string;
967
1081
 
968
- /**
969
- * Whitelists a value
970
- */
971
- allow(...values: any[]): this;
1082
+ /**
1083
+ * Whitelists a value
1084
+ */
1085
+ allow(...values: any[]): this;
972
1086
 
973
- /**
974
- * Assign target alteration options to a schema that are applied when `any.tailor()` is called.
975
- * @param targets - an object where each key is a target name, and each value is a function that takes an schema and returns an schema.
976
- */
977
- alter(targets: Record<string, (schema: this) => Schema>): this;
1087
+ /**
1088
+ * Assign target alteration options to a schema that are applied when `any.tailor()` is called.
1089
+ * @param targets - an object where each key is a target name, and each value is a function that takes an schema and returns an schema.
1090
+ */
1091
+ alter(targets: Record<string, (schema: this) => Schema>): this;
978
1092
 
979
- /**
980
- * Assigns the schema an artifact id which is included in the validation result if the rule passed validation.
981
- * @param id - any value other than undefined which will be returned as-is in the result artifacts map.
982
- */
983
- artifact(id: any): this;
1093
+ /**
1094
+ * Assigns the schema an artifact id which is included in the validation result if the rule passed validation.
1095
+ * @param id - any value other than undefined which will be returned as-is in the result artifacts map.
1096
+ */
1097
+ artifact(id: any): this;
984
1098
 
985
- /**
986
- * By default, some Joi methods to function properly need to rely on the Joi instance they are attached to because
987
- * they use `this` internally.
988
- * So `Joi.string()` works but if you extract the function from it and call `string()` it won't.
989
- * `bind()` creates a new Joi instance where all the functions relying on `this` are bound to the Joi instance.
990
- */
991
- bind(): this;
1099
+ /**
1100
+ * By default, some Joi methods to function properly need to rely on the Joi instance they are attached to because
1101
+ * they use `this` internally.
1102
+ * So `Joi.string()` works but if you extract the function from it and call `string()` it won't.
1103
+ * `bind()` creates a new Joi instance where all the functions relying on `this` are bound to the Joi instance.
1104
+ */
1105
+ bind(): this;
992
1106
 
993
- /**
994
- * Adds caching to the schema which will attempt to cache the validation results (success and failures) of incoming inputs.
995
- * If no cache is passed, a default cache is provisioned by using `cache.provision()` internally.
996
- */
997
- cache(cache?: Cache): this;
1107
+ /**
1108
+ * Adds caching to the schema which will attempt to cache the validation results (success and failures) of incoming inputs.
1109
+ * If no cache is passed, a default cache is provisioned by using `cache.provision()` internally.
1110
+ */
1111
+ cache(cache?: Cache): this;
998
1112
 
999
- /**
1000
- * Casts the validated value to the specified type.
1001
- */
1002
- cast(to: 'map' | 'number' | 'set' | 'string'): this;
1113
+ /**
1114
+ * Casts the validated value to the specified type.
1115
+ */
1116
+ cast(to: "map" | "number" | "set" | "string"): this;
1003
1117
 
1004
- /**
1005
- * Returns a new type that is the result of adding the rules of one type to another.
1006
- */
1007
- concat(schema: this): this;
1118
+ /**
1119
+ * Returns a new type that is the result of adding the rules of one type to another.
1120
+ */
1121
+ concat(schema: this): this;
1008
1122
 
1009
- /**
1010
- * Adds a custom validation function.
1011
- */
1012
- custom(fn: CustomValidator, description?: string): this;
1123
+ /**
1124
+ * Adds a custom validation function.
1125
+ */
1126
+ custom(fn: CustomValidator, description?: string): this;
1013
1127
 
1014
- /**
1015
- * Sets a default value if the original value is `undefined` where:
1016
- * @param value - the default value. One of:
1017
- * - a literal value (string, number, object, etc.)
1018
- * - a [references](#refkey-options)
1019
- * - a function which returns the default value using the signature `function(parent, helpers)` where:
1020
- * - `parent` - a clone of the object containing the value being validated. Note that since specifying a
1021
- * `parent` argument performs cloning, do not declare format arguments if you are not using them.
1022
- * - `helpers` - same as those described in [`any.custom()`](anycustomermethod_description)
1023
- *
1024
- * When called without any `value` on an object schema type, a default value will be automatically generated
1025
- * based on the default values of the object keys.
1026
- *
1027
- * Note that if value is an object, any changes to the object after `default()` is called will change the
1028
- * reference and any future assignment.
1029
- */
1030
- default(value?: BasicType | Reference | ((parent: any, helpers: CustomHelpers) => BasicType | Reference)): this;
1128
+ /**
1129
+ * Sets a default value if the original value is `undefined` where:
1130
+ * @param value - the default value. One of:
1131
+ * - a literal value (string, number, object, etc.)
1132
+ * - a [references](#refkey-options)
1133
+ * - a function which returns the default value using the signature `function(parent, helpers)` where:
1134
+ * - `parent` - a clone of the object containing the value being validated. Note that since specifying a
1135
+ * `parent` argument performs cloning, do not declare format arguments if you are not using them.
1136
+ * - `helpers` - same as those described in [`any.custom()`](anycustomermethod_description)
1137
+ *
1138
+ * When called without any `value` on an object schema type, a default value will be automatically generated
1139
+ * based on the default values of the object keys.
1140
+ *
1141
+ * Note that if value is an object, any changes to the object after `default()` is called will change the
1142
+ * reference and any future assignment.
1143
+ */
1144
+ default(
1145
+ value?:
1146
+ | BasicType
1147
+ | Reference
1148
+ | ((parent: any, helpers: CustomHelpers) => BasicType | Reference)
1149
+ ): this;
1031
1150
 
1032
- /**
1033
- * Returns a plain object representing the schema's rules and properties
1034
- */
1035
- describe(): Description;
1151
+ /**
1152
+ * Returns a plain object representing the schema's rules and properties
1153
+ */
1154
+ describe(): Description;
1036
1155
 
1037
- /**
1038
- * Annotates the key
1039
- */
1040
- description(desc: string): this;
1156
+ /**
1157
+ * Annotates the key
1158
+ */
1159
+ description(desc: string): this;
1041
1160
 
1042
- /**
1043
- * Disallows values.
1044
- */
1045
- disallow(...values: any[]): this;
1161
+ /**
1162
+ * Disallows values.
1163
+ */
1164
+ disallow(...values: any[]): this;
1046
1165
 
1047
- /**
1048
- * Considers anything that matches the schema to be empty (undefined).
1049
- * @param schema - any object or joi schema to match. An undefined schema unsets that rule.
1050
- */
1051
- empty(schema?: SchemaLike): this;
1166
+ /**
1167
+ * Considers anything that matches the schema to be empty (undefined). Overrides any previous calls to empty.
1168
+ * @param schema - an object, value, or joi schema to match or an array of objects, values, and joi schemas to match. An undefined schema unsets that rule.
1169
+ */
1170
+ empty(schema?: SchemaLike): this;
1052
1171
 
1053
- /**
1054
- * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
1055
- */
1056
- equal(...values: any[]): this;
1172
+ /**
1173
+ * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
1174
+ */
1175
+ equal(...values: any[]): this;
1057
1176
 
1058
- /**
1059
- * Overrides the default joi error with a custom error if the rule fails where:
1060
- * @param err - can be:
1061
- * an instance of `Error` - the override error.
1062
- * a `function(errors)`, taking an array of errors as argument, where it must either:
1063
- * return a `string` - substitutes the error message with this text
1064
- * return a single ` object` or an `Array` of it, where:
1065
- * `type` - optional parameter providing the type of the error (eg. `number.min`).
1066
- * `message` - optional parameter if `template` is provided, containing the text of the error.
1067
- * `template` - optional parameter if `message` is provided, containing a template string, using the same format as usual joi language errors.
1068
- * `context` - optional parameter, to provide context to your error if you are using the `template`.
1069
- * return an `Error` - same as when you directly provide an `Error`, but you can customize the error message based on the errors.
1070
- *
1071
- * Note that if you provide an `Error`, it will be returned as-is, unmodified and undecorated with any of the
1072
- * normal joi error properties. If validation fails and another error is found before the error
1073
- * override, that error will be returned and the override will be ignored (unless the `abortEarly`
1074
- * option has been set to `false`).
1075
- */
1076
- error(err: Error | ValidationErrorFunction): this;
1177
+ /**
1178
+ * Overrides the default joi error with a custom error if the rule fails where:
1179
+ * @param err - can be:
1180
+ * an instance of `Error` - the override error.
1181
+ * a `function(errors)`, taking an array of errors as argument, where it must either:
1182
+ * return a `string` - substitutes the error message with this text
1183
+ * return a single ` object` or an `Array` of it, where:
1184
+ * `type` - optional parameter providing the type of the error (eg. `number.min`).
1185
+ * `message` - optional parameter if `template` is provided, containing the text of the error.
1186
+ * `template` - optional parameter if `message` is provided, containing a template string, using the same format as usual joi language errors.
1187
+ * `context` - optional parameter, to provide context to your error if you are using the `template`.
1188
+ * return an `Error` - same as when you directly provide an `Error`, but you can customize the error message based on the errors.
1189
+ *
1190
+ * Note that if you provide an `Error`, it will be returned as-is, unmodified and undecorated with any of the
1191
+ * normal joi error properties. If validation fails and another error is found before the error
1192
+ * override, that error will be returned and the override will be ignored (unless the `abortEarly`
1193
+ * option has been set to `false`).
1194
+ */
1195
+ error(err: Error | ValidationErrorFunction): this;
1077
1196
 
1078
- /**
1079
- * Annotates the key with an example value, must be valid.
1080
- */
1081
- example(value: any, options?: { override: boolean }): this;
1197
+ /**
1198
+ * Annotates the key with an example value, must be valid.
1199
+ */
1200
+ example(value: any, options?: { override: boolean }): this;
1082
1201
 
1083
- /**
1084
- * Marks a key as required which will not allow undefined as value. All keys are optional by default.
1085
- */
1086
- exist(): this;
1202
+ /**
1203
+ * Marks a key as required which will not allow undefined as value. All keys are optional by default.
1204
+ */
1205
+ exist(): this;
1087
1206
 
1088
- /**
1089
- * Adds an external validation rule.
1090
- *
1091
- * Note that external validation rules are only called after the all other validation rules for the entire schema (from the value root) are checked.
1092
- * This means that any changes made to the value by the external rules are not available to any other validation rules during the non-external validation phase.
1093
- * If schema validation failed, no external validation rules are called.
1094
- */
1095
- external(method: ExternalValidationFunction, description?: string): this;
1207
+ /**
1208
+ * Adds an external validation rule.
1209
+ *
1210
+ * Note that external validation rules are only called after the all other validation rules for the entire schema (from the value root) are checked.
1211
+ * This means that any changes made to the value by the external rules are not available to any other validation rules during the non-external validation phase.
1212
+ * If schema validation failed, no external validation rules are called.
1213
+ */
1214
+ external(method: ExternalValidationFunction, description?: string): this;
1096
1215
 
1097
- /**
1098
- * Returns a sub-schema based on a path of object keys or schema ids.
1099
- *
1100
- * @param path - a dot `.` separated path string or a pre-split array of path keys. The keys must match the sub-schema id or object key (if no id was explicitly set).
1101
- */
1102
- extract(path: string | string[]): Schema;
1216
+ /**
1217
+ * Returns a sub-schema based on a path of object keys or schema ids.
1218
+ *
1219
+ * @param path - a dot `.` separated path string or a pre-split array of path keys. The keys must match the sub-schema id or object key (if no id was explicitly set).
1220
+ */
1221
+ extract(path: string | string[]): Schema;
1103
1222
 
1104
- /**
1105
- * Sets a failover value if the original value fails passing validation.
1106
- *
1107
- * @param value - the failover value. value supports references. value may be assigned a function which returns the default value.
1108
- *
1109
- * If value is specified as a function that accepts a single parameter, that parameter will be a context object that can be used to derive the resulting value.
1110
- * Note that if value is an object, any changes to the object after `failover()` is called will change the reference and any future assignment.
1111
- * Use a function when setting a dynamic value (e.g. the current time).
1112
- * Using a function with a single argument performs some internal cloning which has a performance impact.
1113
- * If you do not need access to the context, define the function without any arguments.
1114
- */
1115
- failover(value: any): this;
1223
+ /**
1224
+ * Sets a failover value if the original value fails passing validation.
1225
+ *
1226
+ * @param value - the failover value. value supports references. value may be assigned a function which returns the default value.
1227
+ *
1228
+ * If value is specified as a function that accepts a single parameter, that parameter will be a context object that can be used to derive the resulting value.
1229
+ * Note that if value is an object, any changes to the object after `failover()` is called will change the reference and any future assignment.
1230
+ * Use a function when setting a dynamic value (e.g. the current time).
1231
+ * Using a function with a single argument performs some internal cloning which has a performance impact.
1232
+ * If you do not need access to the context, define the function without any arguments.
1233
+ */
1234
+ failover(value: any): this;
1116
1235
 
1117
- /**
1118
- * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
1119
- */
1120
- forbidden(): this;
1236
+ /**
1237
+ * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
1238
+ */
1239
+ forbidden(): this;
1121
1240
 
1122
- /**
1123
- * Returns a new schema where each of the path keys listed have been modified.
1124
- *
1125
- * @param key - an array of key strings, a single key string, or an array of arrays of pre-split key strings.
1126
- * @param adjuster - a function which must return a modified schema.
1127
- */
1128
- fork(key: string | string[] | string[][], adjuster: SchemaFunction): this;
1241
+ /**
1242
+ * Returns a new schema where each of the path keys listed have been modified.
1243
+ *
1244
+ * @param key - an array of key strings, a single key string, or an array of arrays of pre-split key strings.
1245
+ * @param adjuster - a function which must return a modified schema.
1246
+ */
1247
+ fork(key: string | string[] | string[][], adjuster: SchemaFunction): this;
1129
1248
 
1130
- /**
1131
- * Sets a schema id for reaching into the schema via `any.extract()`.
1132
- * If no id is set, the schema id defaults to the object key it is associated with.
1133
- * If the schema is used in an array or alternatives type and no id is set, the schema in unreachable.
1134
- */
1135
- id(name?: string): this;
1249
+ /**
1250
+ * Sets a schema id for reaching into the schema via `any.extract()`.
1251
+ * If no id is set, the schema id defaults to the object key it is associated with.
1252
+ * If the schema is used in an array or alternatives type and no id is set, the schema in unreachable.
1253
+ */
1254
+ id(name?: string): this;
1136
1255
 
1137
- /**
1138
- * Disallows values.
1139
- */
1140
- invalid(...values: any[]): this;
1256
+ /**
1257
+ * Disallows values.
1258
+ */
1259
+ invalid(...values: any[]): this;
1141
1260
 
1142
- /**
1143
- * Same as `rule({ keep: true })`.
1144
- *
1145
- * Note that `keep()` will terminate the current ruleset and cannot be followed by another rule option.
1146
- * Use `rule()` to apply multiple rule options.
1147
- */
1148
- keep(): this;
1261
+ /**
1262
+ * Returns a boolean indicating whether this schema contains a rule that requires asynchronous validation.
1263
+ */
1264
+ isAsync(): boolean;
1149
1265
 
1150
- /**
1151
- * Overrides the key name in error messages.
1152
- */
1153
- label(name: string): this;
1266
+ /**
1267
+ * Same as `rule({ keep: true })`.
1268
+ *
1269
+ * Note that `keep()` will terminate the current ruleset and cannot be followed by another rule option.
1270
+ * Use `rule()` to apply multiple rule options.
1271
+ */
1272
+ keep(): this;
1154
1273
 
1155
- /**
1156
- * Same as `rule({ message })`.
1157
- *
1158
- * Note that `message()` will terminate the current ruleset and cannot be followed by another rule option.
1159
- * Use `rule()` to apply multiple rule options.
1160
- */
1161
- message(message: string): this;
1274
+ /**
1275
+ * Overrides the key name in error messages.
1276
+ */
1277
+ label(name: string): this;
1162
1278
 
1163
- /**
1164
- * Same as `any.prefs({ messages })`.
1165
- * Note that while `any.message()` applies only to the last rule or ruleset, `any.messages()` applies to the entire schema.
1166
- */
1167
- messages(messages: LanguageMessages): this;
1279
+ /**
1280
+ * Same as `rule({ message })`.
1281
+ *
1282
+ * Note that `message()` will terminate the current ruleset and cannot be followed by another rule option.
1283
+ * Use `rule()` to apply multiple rule options.
1284
+ */
1285
+ message(message: string): this;
1168
1286
 
1169
- /**
1170
- * Attaches metadata to the key.
1171
- */
1172
- meta(meta: object): this;
1287
+ /**
1288
+ * Same as `any.prefs({ messages })`.
1289
+ * Note that while `any.message()` applies only to the last rule or ruleset, `any.messages()` applies to the entire schema.
1290
+ */
1291
+ messages(messages: LanguageMessages): this;
1173
1292
 
1174
- /**
1175
- * Disallows values.
1176
- */
1177
- not(...values: any[]): this;
1293
+ /**
1294
+ * Attaches metadata to the key.
1295
+ */
1296
+ meta(meta: object): this;
1178
1297
 
1179
- /**
1180
- * Annotates the key
1181
- */
1182
- note(...notes: string[]): this;
1298
+ /**
1299
+ * Disallows values.
1300
+ */
1301
+ not(...values: any[]): this;
1183
1302
 
1184
- /**
1185
- * Requires the validated value to match of the provided `any.allow()` values.
1186
- * It has not effect when called together with `any.valid()` since it already sets the requirements.
1187
- * When used with `any.allow()` it converts it to an `any.valid()`.
1188
- */
1189
- only(): this;
1303
+ /**
1304
+ * Annotates the key
1305
+ */
1306
+ note(...notes: string[]): this;
1190
1307
 
1191
- /**
1192
- * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
1193
- */
1194
- optional(): this;
1308
+ /**
1309
+ * Requires the validated value to match of the provided `any.allow()` values.
1310
+ * It has not effect when called together with `any.valid()` since it already sets the requirements.
1311
+ * When used with `any.allow()` it converts it to an `any.valid()`.
1312
+ */
1313
+ only(): this;
1195
1314
 
1196
- /**
1197
- * Overrides the global validate() options for the current key and any sub-key.
1198
- */
1199
- options(options: ValidationOptions): this;
1315
+ /**
1316
+ * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
1317
+ */
1318
+ optional(): this;
1200
1319
 
1201
- /**
1202
- * Overrides the global validate() options for the current key and any sub-key.
1203
- */
1204
- prefs(options: ValidationOptions): this;
1320
+ /**
1321
+ * Overrides the global validate() options for the current key and any sub-key.
1322
+ */
1323
+ options(options: ValidationOptions): this;
1205
1324
 
1206
- /**
1207
- * Overrides the global validate() options for the current key and any sub-key.
1208
- */
1209
- preferences(options: ValidationOptions): this;
1325
+ /**
1326
+ * Overrides the global validate() options for the current key and any sub-key.
1327
+ */
1328
+ prefs(options: ValidationOptions): this;
1210
1329
 
1211
- /**
1212
- * Sets the presence mode for the schema.
1213
- */
1214
- presence(mode: PresenceMode): this;
1330
+ /**
1331
+ * Overrides the global validate() options for the current key and any sub-key.
1332
+ */
1333
+ preferences(options: ValidationOptions): this;
1215
1334
 
1216
- /**
1217
- * Outputs the original untouched value instead of the casted value.
1218
- */
1219
- raw(enabled?: boolean): this;
1335
+ /**
1336
+ * Sets the presence mode for the schema.
1337
+ */
1338
+ presence(mode: PresenceMode): this;
1220
1339
 
1221
- /**
1222
- * Marks a key as required which will not allow undefined as value. All keys are optional by default.
1223
- */
1224
- required(): this;
1340
+ /**
1341
+ * Outputs the original untouched value instead of the casted value.
1342
+ */
1343
+ raw(enabled?: boolean): this;
1225
1344
 
1226
- /**
1227
- * Applies a set of rule options to the current ruleset or last rule added.
1228
- *
1229
- * When applying rule options, the last rule (e.g. `min()`) is used unless there is an active ruleset defined (e.g. `$.min().max()`)
1230
- * in which case the options are applied to all the provided rules.
1231
- * Once `rule()` is called, the previous rules can no longer be modified and any active ruleset is terminated.
1232
- *
1233
- * Rule modifications can only be applied to supported rules.
1234
- * Most of the `any` methods do not support rule modifications because they are implemented using schema flags (e.g. `required()`) or special
1235
- * internal implementation (e.g. `valid()`).
1236
- * In those cases, use the `any.messages()` method to override the error codes for the errors you want to customize.
1237
- */
1238
- rule(options: RuleOptions): this;
1345
+ /**
1346
+ * Marks a key as required which will not allow undefined as value. All keys are optional by default.
1347
+ */
1348
+ required(): this;
1239
1349
 
1240
- /**
1241
- * Registers a schema to be used by descendants of the current schema in named link references.
1242
- */
1243
- shared(ref: Schema): this;
1350
+ /**
1351
+ * Applies a set of rule options to the current ruleset or last rule added.
1352
+ *
1353
+ * When applying rule options, the last rule (e.g. `min()`) is used unless there is an active ruleset defined (e.g. `$.min().max()`)
1354
+ * in which case the options are applied to all the provided rules.
1355
+ * Once `rule()` is called, the previous rules can no longer be modified and any active ruleset is terminated.
1356
+ *
1357
+ * Rule modifications can only be applied to supported rules.
1358
+ * Most of the `any` methods do not support rule modifications because they are implemented using schema flags (e.g. `required()`) or special
1359
+ * internal implementation (e.g. `valid()`).
1360
+ * In those cases, use the `any.messages()` method to override the error codes for the errors you want to customize.
1361
+ */
1362
+ rule(options: RuleOptions): this;
1244
1363
 
1245
- /**
1246
- * Sets the options.convert options to false which prevent type casting for the current key and any child keys.
1247
- */
1248
- strict(isStrict?: boolean): this;
1364
+ /**
1365
+ * Registers a schema to be used by descendants of the current schema in named link references.
1366
+ */
1367
+ shared(ref: Schema): this;
1249
1368
 
1250
- /**
1251
- * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output.
1252
- * @param [enabled=true] - if true, the value is stripped, otherwise the validated value is retained. Defaults to true.
1253
- */
1254
- strip(enabled?: boolean): this;
1369
+ /**
1370
+ * Sets the options.convert options to false which prevent type casting for the current key and any child keys.
1371
+ */
1372
+ strict(isStrict?: boolean): this;
1255
1373
 
1256
- /**
1257
- * Annotates the key
1258
- */
1259
- tag(...tags: string[]): this;
1374
+ /**
1375
+ * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output.
1376
+ * @param [enabled=true] - if true, the value is stripped, otherwise the validated value is retained. Defaults to true.
1377
+ */
1378
+ strip(enabled?: boolean): this;
1260
1379
 
1261
- /**
1262
- * Applies any assigned target alterations to a copy of the schema that were applied via `any.alter()`.
1263
- */
1264
- tailor(targets: string | string[]): Schema;
1380
+ /**
1381
+ * Annotates the key
1382
+ */
1383
+ tag(...tags: string[]): this;
1265
1384
 
1266
- /**
1267
- * Annotates the key with an unit name.
1268
- */
1269
- unit(name: string): this;
1385
+ /**
1386
+ * Applies any assigned target alterations to a copy of the schema that were applied via `any.alter()`.
1387
+ */
1388
+ tailor(targets: string | string[]): Schema;
1270
1389
 
1271
- /**
1272
- * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
1273
- */
1274
- valid(...values: any[]): this;
1390
+ /**
1391
+ * Annotates the key with an unit name.
1392
+ */
1393
+ unit(name: string): this;
1275
1394
 
1276
- /**
1277
- * Validates a value using the schema and options.
1278
- */
1279
- validate(value: any, options?: ValidationOptions): ValidationResult<TSchema>;
1395
+ /**
1396
+ * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
1397
+ */
1398
+ valid(...values: any[]): this;
1280
1399
 
1281
- /**
1282
- * Validates a value using the schema and options.
1283
- */
1284
- validateAsync<TOpts extends AsyncValidationOptions>(
1285
- value: any,
1286
- options?: TOpts
1287
- ): Promise<
1288
- TOpts extends { artifacts: true } | { warnings: true }
1289
- ? { value: TSchema } & (TOpts extends { artifacts: true }
1400
+ /**
1401
+ * Validates a value using the schema and options.
1402
+ */
1403
+ validate(
1404
+ value: any,
1405
+ options?: ValidationOptions
1406
+ ): ValidationResult<TSchema>;
1407
+
1408
+ /**
1409
+ * Validates a value using the schema and options.
1410
+ */
1411
+ validateAsync<TOpts extends AsyncValidationOptions>(
1412
+ value: any,
1413
+ options?: TOpts
1414
+ ): Promise<
1415
+ TOpts extends { artifacts: true } | { warnings: true }
1416
+ ? { value: TSchema } & (TOpts extends { artifacts: true }
1290
1417
  ? { artifacts: Map<any, string[][]> }
1291
1418
  : {}) &
1292
1419
  (TOpts extends { warnings: true }
1293
1420
  ? { warning: ValidationWarning }
1294
1421
  : {})
1295
- : TSchema
1296
- >;
1297
-
1298
- /**
1299
- * Same as `rule({ warn: true })`.
1300
- * Note that `warn()` will terminate the current ruleset and cannot be followed by another rule option.
1301
- * Use `rule()` to apply multiple rule options.
1302
- */
1303
- warn(): this;
1422
+ : TSchema
1423
+ >;
1304
1424
 
1305
- /**
1306
- * Generates a warning.
1307
- * When calling `any.validateAsync()`, set the `warning` option to true to enable warnings.
1308
- * Warnings are reported separately from errors alongside the result value via the warning key (i.e. `{ value, warning }`).
1309
- * Warning are always included when calling `any.validate()`.
1310
- */
1311
- warning(code: string, context: Context): this;
1312
-
1313
- /**
1314
- * Converts the type into an alternatives type where the conditions are merged into the type definition where:
1315
- */
1316
- when(ref: string | Reference, options: WhenOptions | WhenOptions[]): this;
1317
-
1318
- /**
1319
- * Converts the type into an alternatives type where the conditions are merged into the type definition where:
1320
- */
1321
- when(ref: Schema, options: WhenSchemaOptions): this;
1322
- }
1323
-
1324
- interface Description {
1325
- type?: Types | string;
1326
- label?: string;
1327
- description?: string;
1328
- flags?: object;
1329
- notes?: string[];
1330
- tags?: string[];
1331
- metas?: any[];
1332
- example?: any[];
1333
- valids?: any[];
1334
- invalids?: any[];
1335
- unit?: string;
1336
- options?: ValidationOptions;
1337
- [key: string]: any;
1338
- }
1425
+ /**
1426
+ * Same as `rule({ warn: true })`.
1427
+ * Note that `warn()` will terminate the current ruleset and cannot be followed by another rule option.
1428
+ * Use `rule()` to apply multiple rule options.
1429
+ */
1430
+ warn(): this;
1339
1431
 
1340
- interface Context {
1341
- [key: string]: any;
1342
- key?: string;
1343
- label?: string;
1344
- value?: any;
1345
- }
1432
+ /**
1433
+ * Generates a warning.
1434
+ * When calling `any.validateAsync()`, set the `warning` option to true to enable warnings.
1435
+ * Warnings are reported separately from errors alongside the result value via the warning key (i.e. `{ value, warning }`).
1436
+ * Warning are always included when calling `any.validate()`.
1437
+ */
1438
+ warning(code: string, context: Context): this;
1346
1439
 
1347
- interface State {
1348
- key?: string;
1349
- path?: (string | number)[];
1350
- parent?: any;
1351
- reference?: any;
1352
- ancestors?: any;
1353
- localize?(...args: any[]): State;
1354
- }
1440
+ /**
1441
+ * Converts the type into an alternatives type where the conditions are merged into the type definition where:
1442
+ */
1443
+ when(ref: string | Reference, options: WhenOptions | WhenOptions[]): this;
1355
1444
 
1356
- interface BooleanSchema<TSchema = boolean> extends AnySchema<TSchema> {
1357
- /**
1358
- * Allows for additional values to be considered valid booleans by converting them to false during validation.
1359
- * String comparisons are by default case insensitive,
1360
- * see `boolean.sensitive()` to change this behavior.
1361
- * @param values - strings, numbers or arrays of them
1362
- */
1363
- falsy(...values: Array<string | number | null>): this;
1445
+ /**
1446
+ * Converts the type into an alternatives type where the conditions are merged into the type definition where:
1447
+ */
1448
+ when(ref: Schema, options: WhenSchemaOptions): this;
1449
+ }
1450
+
1451
+ interface Description {
1452
+ type?: Types | string;
1453
+ label?: string;
1454
+ description?: string;
1455
+ flags?: object;
1456
+ notes?: string[];
1457
+ tags?: string[];
1458
+ metas?: any[];
1459
+ example?: any[];
1460
+ valids?: any[];
1461
+ invalids?: any[];
1462
+ unit?: string;
1463
+ options?: ValidationOptions;
1464
+ [key: string]: any;
1465
+ }
1466
+
1467
+ interface Context {
1468
+ [key: string]: any;
1469
+ key?: string;
1470
+ label?: string;
1471
+ value?: any;
1472
+ }
1364
1473
 
1365
- /**
1366
- * Allows the values provided to truthy and falsy as well as the "true" and "false" default conversion
1367
- * (when not in `strict()` mode) to be matched in a case insensitive manner.
1368
- */
1369
- sensitive(enabled?: boolean): this;
1474
+ interface State {
1475
+ key?: string;
1476
+ path?: (string | number)[];
1477
+ parent?: any;
1478
+ reference?: any;
1479
+ ancestors?: any;
1480
+ localize?(...args: any[]): State;
1481
+ }
1370
1482
 
1371
- /**
1372
- * Allows for additional values to be considered valid booleans by converting them to true during validation.
1373
- * String comparisons are by default case insensitive, see `boolean.sensitive()` to change this behavior.
1374
- * @param values - strings, numbers or arrays of them
1375
- */
1376
- truthy(...values: Array<string | number | null>): this;
1377
- }
1483
+ interface BooleanSchema<TSchema = boolean> extends AnySchema<TSchema> {
1484
+ /**
1485
+ * Allows for additional values to be considered valid booleans by converting them to false during validation.
1486
+ * String comparisons are by default case insensitive,
1487
+ * see `boolean.sensitive()` to change this behavior.
1488
+ * @param values - strings, numbers or arrays of them
1489
+ */
1490
+ falsy(...values: Array<string | number | null>): this;
1378
1491
 
1379
- interface NumberSchema<TSchema = number> extends AnySchema<TSchema> {
1380
- /**
1381
- * Specifies that the value must be greater than limit.
1382
- * It can also be a reference to another field.
1383
- */
1384
- greater(limit: number | Reference): this;
1492
+ /**
1493
+ * Allows the values provided to truthy and falsy as well as the "true" and "false" default conversion
1494
+ * (when not in `strict()` mode) to be matched in a case insensitive manner.
1495
+ */
1496
+ sensitive(enabled?: boolean): this;
1385
1497
 
1386
- /**
1387
- * Requires the number to be an integer (no floating point).
1388
- */
1389
- integer(): this;
1498
+ /**
1499
+ * Allows for additional values to be considered valid booleans by converting them to true during validation.
1500
+ * String comparisons are by default case insensitive, see `boolean.sensitive()` to change this behavior.
1501
+ * @param values - strings, numbers or arrays of them
1502
+ */
1503
+ truthy(...values: Array<string | number | null>): this;
1504
+ }
1390
1505
 
1391
- /**
1392
- * Specifies that the value must be less than limit.
1393
- * It can also be a reference to another field.
1394
- */
1395
- less(limit: number | Reference): this;
1506
+ interface NumberSchema<TSchema = number> extends AnySchema<TSchema> {
1507
+ /**
1508
+ * Specifies that the value must be greater than limit.
1509
+ * It can also be a reference to another field.
1510
+ */
1511
+ greater(limit: number | Reference): this;
1396
1512
 
1397
- /**
1398
- * Specifies the maximum value.
1399
- * It can also be a reference to another field.
1400
- */
1401
- max(limit: number | Reference): this;
1513
+ /**
1514
+ * Requires the number to be an integer (no floating point).
1515
+ */
1516
+ integer(): this;
1402
1517
 
1403
- /**
1404
- * Specifies the minimum value.
1405
- * It can also be a reference to another field.
1406
- */
1407
- min(limit: number | Reference): this;
1518
+ /**
1519
+ * Specifies that the value must be less than limit.
1520
+ * It can also be a reference to another field.
1521
+ */
1522
+ less(limit: number | Reference): this;
1408
1523
 
1409
- /**
1410
- * Specifies that the value must be a multiple of base.
1411
- */
1412
- multiple(base: number | Reference): this;
1524
+ /**
1525
+ * Specifies the maximum value.
1526
+ * It can also be a reference to another field.
1527
+ */
1528
+ max(limit: number | Reference): this;
1413
1529
 
1414
- /**
1415
- * Requires the number to be negative.
1416
- */
1417
- negative(): this;
1530
+ /**
1531
+ * Specifies the minimum value.
1532
+ * It can also be a reference to another field.
1533
+ */
1534
+ min(limit: number | Reference): this;
1418
1535
 
1419
- /**
1420
- * Requires the number to be a TCP port, so between 0 and 65535.
1421
- */
1422
- port(): this;
1536
+ /**
1537
+ * Specifies that the value must be a multiple of base.
1538
+ */
1539
+ multiple(base: number | Reference): this;
1423
1540
 
1424
- /**
1425
- * Requires the number to be positive.
1426
- */
1427
- positive(): this;
1541
+ /**
1542
+ * Requires the number to be negative.
1543
+ */
1544
+ negative(): this;
1428
1545
 
1429
- /**
1430
- * Specifies the maximum number of decimal places where:
1431
- * @param limit - the maximum number of decimal places allowed.
1432
- */
1433
- precision(limit: number): this;
1546
+ /**
1547
+ * Requires the number to be a TCP port, so between 0 and 65535.
1548
+ */
1549
+ port(): this;
1434
1550
 
1435
- /**
1436
- * Requires the number to be negative or positive.
1437
- */
1438
- sign(sign: 'positive' | 'negative'): this;
1551
+ /**
1552
+ * Requires the number to be positive.
1553
+ */
1554
+ positive(): this;
1439
1555
 
1440
- /**
1441
- * Allows the number to be outside of JavaScript's safety range (Number.MIN_SAFE_INTEGER & Number.MAX_SAFE_INTEGER).
1442
- */
1443
- unsafe(enabled?: any): this;
1444
- }
1556
+ /**
1557
+ * Specifies the maximum number of decimal places where:
1558
+ * @param limit - the maximum number of decimal places allowed.
1559
+ */
1560
+ precision(limit: number): this;
1445
1561
 
1446
- interface StringSchema<TSchema = string> extends AnySchema<TSchema> {
1447
- /**
1448
- * Requires the string value to only contain a-z, A-Z, and 0-9.
1449
- */
1450
- alphanum(): this;
1562
+ /**
1563
+ * Requires the number to be negative or positive.
1564
+ */
1565
+ sign(sign: "positive" | "negative"): this;
1451
1566
 
1452
- /**
1453
- * Requires the string value to be a valid base64 string; does not check the decoded value.
1454
- */
1455
- base64(options?: Base64Options): this;
1567
+ /**
1568
+ * Allows the number to be outside of JavaScript's safety range (Number.MIN_SAFE_INTEGER & Number.MAX_SAFE_INTEGER).
1569
+ */
1570
+ unsafe(enabled?: any): this;
1571
+ }
1456
1572
 
1457
- /**
1458
- * Sets the required string case.
1459
- */
1460
- case(direction: 'upper' | 'lower'): this;
1573
+ interface StringSchema<TSchema = string> extends AnySchema<TSchema> {
1574
+ /**
1575
+ * Requires the string value to only contain a-z, A-Z, and 0-9.
1576
+ */
1577
+ alphanum(): this;
1461
1578
 
1462
- /**
1463
- * Requires the number to be a credit card number (Using Luhn Algorithm).
1464
- */
1465
- creditCard(): this;
1579
+ /**
1580
+ * Requires the string value to be a valid base64 string; does not check the decoded value.
1581
+ */
1582
+ base64(options?: Base64Options): this;
1466
1583
 
1467
- /**
1468
- * Requires the string value to be a valid data URI string.
1469
- */
1470
- dataUri(options?: DataUriOptions): this;
1584
+ /**
1585
+ * Sets the required string case.
1586
+ */
1587
+ case(direction: "upper" | "lower"): this;
1471
1588
 
1472
- /**
1473
- * Requires the string value to be a valid domain.
1474
- */
1475
- domain(options?: DomainOptions): this;
1589
+ /**
1590
+ * Requires the number to be a credit card number (Using Luhn Algorithm).
1591
+ */
1592
+ creditCard(): this;
1476
1593
 
1477
- /**
1478
- * Requires the string value to be a valid email address.
1479
- */
1480
- email(options?: EmailOptions): this;
1594
+ /**
1595
+ * Requires the string value to be a valid data URI string.
1596
+ */
1597
+ dataUri(options?: DataUriOptions): this;
1481
1598
 
1482
- /**
1483
- * Requires the string value to be a valid GUID.
1484
- */
1485
- guid(options?: GuidOptions): this;
1599
+ /**
1600
+ * Requires the string value to be a valid domain.
1601
+ */
1602
+ domain(options?: DomainOptions): this;
1486
1603
 
1487
- /**
1488
- * Requires the string value to be a valid hexadecimal string.
1489
- */
1490
- hex(options?: HexOptions): this;
1604
+ /**
1605
+ * Requires the string value to be a valid email address.
1606
+ */
1607
+ email(options?: EmailOptions): this;
1491
1608
 
1492
- /**
1493
- * Requires the string value to be a valid hostname as per RFC1123.
1494
- */
1495
- hostname(): this;
1609
+ /**
1610
+ * Requires the string value to be a valid GUID.
1611
+ */
1612
+ guid(options?: GuidOptions): this;
1496
1613
 
1497
- /**
1498
- * Allows the value to match any whitelist of blacklist item in a case insensitive comparison.
1499
- */
1500
- insensitive(): this;
1614
+ /**
1615
+ * Requires the string value to be a valid hexadecimal string.
1616
+ */
1617
+ hex(options?: HexOptions): this;
1501
1618
 
1502
- /**
1503
- * Requires the string value to be a valid ip address.
1504
- */
1505
- ip(options?: IpOptions): this;
1619
+ /**
1620
+ * Requires the string value to be a valid hostname as per RFC1123.
1621
+ */
1622
+ hostname(): this;
1506
1623
 
1507
- /**
1508
- * Requires the string value to be in valid ISO 8601 date format.
1509
- */
1510
- isoDate(): this;
1624
+ /**
1625
+ * Allows the value to match any whitelist of blacklist item in a case insensitive comparison.
1626
+ */
1627
+ insensitive(): this;
1511
1628
 
1512
- /**
1513
- * Requires the string value to be in valid ISO 8601 duration format.
1514
- */
1515
- isoDuration(): this;
1629
+ /**
1630
+ * Requires the string value to be a valid ip address.
1631
+ */
1632
+ ip(options?: IpOptions): this;
1516
1633
 
1517
- /**
1518
- * Specifies the exact string length required
1519
- * @param limit - the required string length. It can also be a reference to another field.
1520
- * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1521
- */
1522
- length(limit: number | Reference, encoding?: string): this;
1634
+ /**
1635
+ * Requires the string value to be in valid ISO 8601 date format.
1636
+ */
1637
+ isoDate(): this;
1523
1638
 
1524
- /**
1525
- * Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase.
1526
- */
1527
- lowercase(): this;
1639
+ /**
1640
+ * Requires the string value to be in valid ISO 8601 duration format.
1641
+ */
1642
+ isoDuration(): this;
1528
1643
 
1529
- /**
1530
- * Specifies the maximum number of string characters.
1531
- * @param limit - the maximum number of string characters allowed. It can also be a reference to another field.
1532
- * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1533
- */
1534
- max(limit: number | Reference, encoding?: string): this;
1644
+ /**
1645
+ * Specifies the exact string length required
1646
+ * @param limit - the required string length. It can also be a reference to another field.
1647
+ * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1648
+ */
1649
+ length(limit: number | Reference, encoding?: string): this;
1535
1650
 
1536
- /**
1537
- * Specifies the minimum number string characters.
1538
- * @param limit - the minimum number of string characters required. It can also be a reference to another field.
1539
- * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1540
- */
1541
- min(limit: number | Reference, encoding?: string): this;
1651
+ /**
1652
+ * Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase.
1653
+ */
1654
+ lowercase(): this;
1542
1655
 
1543
- /**
1544
- * Requires the string value to be in a unicode normalized form. If the validation convert option is on (enabled by default), the string will be normalized.
1545
- * @param [form='NFC'] - The unicode normalization form to use. Valid values: NFC [default], NFD, NFKC, NFKD
1546
- */
1547
- normalize(form?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD'): this;
1656
+ /**
1657
+ * Specifies the maximum number of string characters.
1658
+ * @param limit - the maximum number of string characters allowed. It can also be a reference to another field.
1659
+ * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1660
+ */
1661
+ max(limit: number | Reference, encoding?: string): this;
1548
1662
 
1549
- /**
1550
- * Defines a regular expression rule.
1551
- * @param pattern - a regular expression object the string value must match against.
1552
- * @param options - optional, can be:
1553
- * Name for patterns (useful with multiple patterns). Defaults to 'required'.
1554
- * An optional configuration object with the following supported properties:
1555
- * name - optional pattern name.
1556
- * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
1557
- */
1558
- pattern(pattern: RegExp, options?: string | StringRegexOptions): this;
1663
+ /**
1664
+ * Specifies the minimum number string characters.
1665
+ * @param limit - the minimum number of string characters required. It can also be a reference to another field.
1666
+ * @param encoding - if specified, the string length is calculated in bytes using the provided encoding.
1667
+ */
1668
+ min(limit: number | Reference, encoding?: string): this;
1559
1669
 
1560
- /**
1561
- * Defines a regular expression rule.
1562
- * @param pattern - a regular expression object the string value must match against.
1563
- * @param options - optional, can be:
1564
- * Name for patterns (useful with multiple patterns). Defaults to 'required'.
1565
- * An optional configuration object with the following supported properties:
1566
- * name - optional pattern name.
1567
- * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
1568
- */
1569
- regex(pattern: RegExp, options?: string | StringRegexOptions): this;
1670
+ /**
1671
+ * Requires the string value to be in a unicode normalized form. If the validation convert option is on (enabled by default), the string will be normalized.
1672
+ * @param [form='NFC'] - The unicode normalization form to use. Valid values: NFC [default], NFD, NFKC, NFKD
1673
+ */
1674
+ normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD"): this;
1570
1675
 
1571
- /**
1572
- * Replace characters matching the given pattern with the specified replacement string where:
1573
- * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced.
1574
- * @param replacement - the string that will replace the pattern.
1575
- */
1576
- replace(pattern: RegExp | string, replacement: string): this;
1676
+ /**
1677
+ * Defines a regular expression rule.
1678
+ * @param pattern - a regular expression object the string value must match against.
1679
+ * @param options - optional, can be:
1680
+ * Name for patterns (useful with multiple patterns). Defaults to 'required'.
1681
+ * An optional configuration object with the following supported properties:
1682
+ * name - optional pattern name.
1683
+ * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
1684
+ */
1685
+ pattern(pattern: RegExp, options?: string | StringRegexOptions): this;
1577
1686
 
1578
- /**
1579
- * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _.
1580
- */
1581
- token(): this;
1687
+ /**
1688
+ * Defines a regular expression rule.
1689
+ * @param pattern - a regular expression object the string value must match against.
1690
+ * @param options - optional, can be:
1691
+ * Name for patterns (useful with multiple patterns). Defaults to 'required'.
1692
+ * An optional configuration object with the following supported properties:
1693
+ * name - optional pattern name.
1694
+ * invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.
1695
+ */
1696
+ regex(pattern: RegExp, options?: string | StringRegexOptions): this;
1582
1697
 
1583
- /**
1584
- * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed.
1585
- * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of trim by providing a falsy value.
1586
- */
1587
- trim(enabled?: any): this;
1698
+ /**
1699
+ * Replace characters matching the given pattern with the specified replacement string where:
1700
+ * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced.
1701
+ * @param replacement - the string that will replace the pattern.
1702
+ */
1703
+ replace(pattern: RegExp | string, replacement: string): this;
1588
1704
 
1589
- /**
1590
- * Specifies whether the string.max() limit should be used as a truncation.
1591
- * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of truncate by providing a falsy value.
1592
- */
1593
- truncate(enabled?: boolean): this;
1705
+ /**
1706
+ * Requires the string value to only contain a-z, A-Z, 0-9, and underscore _.
1707
+ */
1708
+ token(): this;
1594
1709
 
1595
- /**
1596
- * Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase.
1597
- */
1598
- uppercase(): this;
1710
+ /**
1711
+ * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed.
1712
+ * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of trim by providing a falsy value.
1713
+ */
1714
+ trim(enabled?: any): this;
1599
1715
 
1600
- /**
1601
- * Requires the string value to be a valid RFC 3986 URI.
1602
- */
1603
- uri(options?: UriOptions): this;
1716
+ /**
1717
+ * Specifies whether the string.max() limit should be used as a truncation.
1718
+ * @param [enabled=true] - optional parameter defaulting to true which allows you to reset the behavior of truncate by providing a falsy value.
1719
+ */
1720
+ truncate(enabled?: boolean): this;
1604
1721
 
1605
- /**
1606
- * Requires the string value to be a valid GUID.
1607
- */
1608
- uuid(options?: GuidOptions): this;
1609
- }
1722
+ /**
1723
+ * Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase.
1724
+ */
1725
+ uppercase(): this;
1610
1726
 
1611
- interface SymbolSchema<TSchema = Symbol> extends AnySchema<TSchema> {
1612
- // TODO: support number and symbol index
1613
- map(iterable: Iterable<[string | number | boolean | symbol, symbol]> | { [key: string]: symbol }): this;
1614
- }
1727
+ /**
1728
+ * Requires the string value to be a valid RFC 3986 URI.
1729
+ */
1730
+ uri(options?: UriOptions): this;
1615
1731
 
1616
- interface ArraySortOptions {
1617
- /**
1618
- * @default 'ascending'
1619
- */
1620
- order?: 'ascending' | 'descending';
1621
- by?: string | Reference;
1622
- }
1732
+ /**
1733
+ * Requires the string value to be a valid GUID.
1734
+ */
1735
+ uuid(options?: GuidOptions): this;
1736
+ }
1623
1737
 
1624
- interface ArrayUniqueOptions extends HierarchySeparatorOptions {
1625
- /**
1626
- * if true, undefined values for the dot notation string comparator will not cause the array to fail on uniqueness.
1627
- *
1628
- * @default false
1629
- */
1630
- ignoreUndefined?: boolean;
1631
- }
1738
+ interface SymbolSchema<TSchema = Symbol> extends AnySchema<TSchema> {
1739
+ // TODO: support number and symbol index
1740
+ map(
1741
+ iterable:
1742
+ | Iterable<[string | number | boolean | symbol, symbol]>
1743
+ | { [key: string]: symbol }
1744
+ ): this;
1745
+ }
1632
1746
 
1633
- type ComparatorFunction = (a: any, b: any) => boolean;
1747
+ interface ArraySortOptions {
1748
+ /**
1749
+ * @default 'ascending'
1750
+ */
1751
+ order?: "ascending" | "descending";
1752
+ by?: string | Reference;
1753
+ }
1634
1754
 
1635
- interface ArraySchema<TSchema = any[]> extends AnySchema<TSchema> {
1636
- /**
1637
- * Verifies that an assertion passes for at least one item in the array, where:
1638
- * `schema` - the validation rules required to satisfy the assertion. If the `schema` includes references, they are resolved against
1639
- * the array item being tested, not the value of the `ref` target.
1640
- */
1641
- has(schema: SchemaLike): this;
1755
+ interface ArrayUniqueOptions extends HierarchySeparatorOptions {
1756
+ /**
1757
+ * if true, undefined values for the dot notation string comparator will not cause the array to fail on uniqueness.
1758
+ *
1759
+ * @default false
1760
+ */
1761
+ ignoreUndefined?: boolean;
1762
+ }
1642
1763
 
1643
- /**
1644
- * List the types allowed for the array values.
1645
- * If a given type is .required() then there must be a matching item in the array.
1646
- * If a type is .forbidden() then it cannot appear in the array.
1647
- * Required items can be added multiple times to signify that multiple items must be found.
1648
- * Errors will contain the number of items that didn't match.
1649
- * Any unmatched item having a label will be mentioned explicitly.
1650
- *
1651
- * @param type - a joi schema object to validate each array item against.
1652
- */
1653
- items(...types: SchemaLikeWithoutArray[]): this;
1764
+ type ComparatorFunction = (a: any, b: any) => boolean;
1654
1765
 
1655
- /**
1656
- * Specifies the exact number of items in the array.
1657
- */
1658
- length(limit: number | Reference): this;
1766
+ type UnwrapSchemaLikeWithoutArray<T> = T extends SchemaLikeWithoutArray<
1767
+ infer U
1768
+ >
1769
+ ? U
1770
+ : never;
1659
1771
 
1660
- /**
1661
- * Specifies the maximum number of items in the array.
1662
- */
1663
- max(limit: number | Reference): this;
1772
+ type NoNestedArrays<T extends readonly unknown[]> = Extract<
1773
+ T[number],
1774
+ readonly unknown[]
1775
+ > extends never
1776
+ ? T
1777
+ : never;
1664
1778
 
1665
- /**
1666
- * Specifies the minimum number of items in the array.
1667
- */
1668
- min(limit: number | Reference): this;
1779
+ interface ArraySchema<TSchema = any[]> extends AnySchema<TSchema> {
1780
+ /**
1781
+ * Verifies that an assertion passes for at least one item in the array, where:
1782
+ * `schema` - the validation rules required to satisfy the assertion. If the `schema` includes references, they are resolved against
1783
+ * the array item being tested, not the value of the `ref` target.
1784
+ */
1785
+ has(schema: SchemaLike): this;
1669
1786
 
1670
- /**
1671
- * Lists the types in sequence order for the array values where:
1672
- * @param type - a joi schema object to validate against each array item in sequence order. type can be multiple values passed as individual arguments.
1673
- * If a given type is .required() then there must be a matching item with the same index position in the array.
1674
- * Errors will contain the number of items that didn't match.
1675
- * Any unmatched item having a label will be mentioned explicitly.
1676
- */
1677
- ordered(...types: SchemaLikeWithoutArray[]): this;
1787
+ /**
1788
+ * List the types allowed for the array values.
1789
+ * If a given type is .required() then there must be a matching item in the array.
1790
+ * If a type is .forbidden() then it cannot appear in the array.
1791
+ * Required items can be added multiple times to signify that multiple items must be found.
1792
+ * Errors will contain the number of items that didn't match.
1793
+ * Any unmatched item having a label will be mentioned explicitly.
1794
+ *
1795
+ * @param type - a joi schema object to validate each array item against.
1796
+ */
1797
+ items<A>(a: SchemaLikeWithoutArray<A>): ArraySchema<A[]>;
1798
+ items<A, B>(
1799
+ a: SchemaLikeWithoutArray<A>,
1800
+ b: SchemaLikeWithoutArray<B>
1801
+ ): ArraySchema<(A | B)[]>;
1802
+ items<A, B, C>(
1803
+ a: SchemaLikeWithoutArray<A>,
1804
+ b: SchemaLikeWithoutArray<B>,
1805
+ c: SchemaLikeWithoutArray<C>
1806
+ ): ArraySchema<(A | B | C)[]>;
1807
+ items<A, B, C, D>(
1808
+ a: SchemaLikeWithoutArray<A>,
1809
+ b: SchemaLikeWithoutArray<B>,
1810
+ c: SchemaLikeWithoutArray<C>,
1811
+ d: SchemaLikeWithoutArray<D>
1812
+ ): ArraySchema<(A | B | C | D)[]>;
1813
+ items<A, B, C, D, E>(
1814
+ a: SchemaLikeWithoutArray<A>,
1815
+ b: SchemaLikeWithoutArray<B>,
1816
+ c: SchemaLikeWithoutArray<C>,
1817
+ d: SchemaLikeWithoutArray<D>,
1818
+ e: SchemaLikeWithoutArray<E>
1819
+ ): ArraySchema<(A | B | C | D | E)[]>;
1820
+ items<A, B, C, D, E, F>(
1821
+ a: SchemaLikeWithoutArray<A>,
1822
+ b: SchemaLikeWithoutArray<B>,
1823
+ c: SchemaLikeWithoutArray<C>,
1824
+ d: SchemaLikeWithoutArray<D>,
1825
+ e: SchemaLikeWithoutArray<E>,
1826
+ f: SchemaLikeWithoutArray<F>
1827
+ ): ArraySchema<(A | B | C | D | E | F)[]>;
1828
+ items<
1829
+ TItems,
1830
+ TTItems extends SchemaLikeWithoutArray<TItems>[] = SchemaLikeWithoutArray<TItems>[]
1831
+ >(
1832
+ ...types: NoNestedArrays<TTItems>
1833
+ ): ArraySchema<
1834
+ {
1835
+ [I in keyof TTItems]: UnwrapSchemaLikeWithoutArray<TTItems[I]>;
1836
+ }[number][]
1837
+ >;
1678
1838
 
1679
- /**
1680
- * Allow single values to be checked against rules as if it were provided as an array.
1681
- * enabled can be used with a falsy value to go back to the default behavior.
1682
- */
1683
- single(enabled?: any): this;
1839
+ /**
1840
+ * Specifies the exact number of items in the array.
1841
+ */
1842
+ length(limit: number | Reference): this;
1684
1843
 
1685
- /**
1686
- * Sorts the array by given order.
1687
- */
1688
- sort(options?: ArraySortOptions): this;
1844
+ /**
1845
+ * Specifies the maximum number of items in the array.
1846
+ */
1847
+ max(limit: number | Reference): this;
1689
1848
 
1690
- /**
1691
- * Allow this array to be sparse.
1692
- * enabled can be used with a falsy value to go back to the default behavior.
1693
- */
1694
- sparse(enabled?: any): this;
1849
+ /**
1850
+ * Specifies the minimum number of items in the array.
1851
+ */
1852
+ min(limit: number | Reference): this;
1695
1853
 
1696
- /**
1697
- * Requires the array values to be unique.
1698
- * Remember that if you provide a custom comparator function,
1699
- * different types can be passed as parameter depending on the rules you set on items.
1700
- * Be aware that a deep equality is performed on elements of the array having a type of object,
1701
- * a performance penalty is to be expected for this kind of operation.
1702
- */
1703
- unique(comparator?: string | ComparatorFunction, options?: ArrayUniqueOptions): this;
1704
- }
1854
+ /**
1855
+ * Lists the types in sequence order for the array values where:
1856
+ * @param type - a joi schema object to validate against each array item in sequence order. type can be multiple values passed as individual arguments.
1857
+ * If a given type is .required() then there must be a matching item with the same index position in the array.
1858
+ * Errors will contain the number of items that didn't match.
1859
+ * Any unmatched item having a label will be mentioned explicitly.
1860
+ */
1861
+ ordered(...types: SchemaLikeWithoutArray[]): this;
1705
1862
 
1706
- interface ObjectPatternOptions {
1707
- fallthrough?: boolean;
1708
- matches: SchemaLike | Reference;
1709
- }
1863
+ /**
1864
+ * Allow single values to be checked against rules as if it were provided as an array.
1865
+ * enabled can be used with a falsy value to go back to the default behavior.
1866
+ */
1867
+ single(enabled?: any): this;
1710
1868
 
1711
- interface ObjectSchema<TSchema = any> extends AnySchema<TSchema> {
1712
- /**
1713
- * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well.
1714
- *
1715
- * Optional settings must be the last argument.
1716
- */
1717
- and(...peers: Array<string | DependencyOptions>): this;
1869
+ /**
1870
+ * Sorts the array by given order.
1871
+ */
1872
+ sort(options?: ArraySortOptions): this;
1718
1873
 
1719
- /**
1720
- * Appends the allowed object keys. If schema is null, undefined, or {}, no changes will be applied.
1721
- */
1722
- append(schema?: SchemaMap<TSchema>): this;
1723
- append<TSchemaExtended = any, T = TSchemaExtended>(schema?: SchemaMap<T>): ObjectSchema<T>
1874
+ /**
1875
+ * Allow this array to be sparse.
1876
+ * enabled can be used with a falsy value to go back to the default behavior.
1877
+ */
1878
+ sparse(enabled?: any): this;
1724
1879
 
1725
- /**
1726
- * Verifies an assertion where.
1727
- */
1728
- assert(ref: string | Reference, schema: SchemaLike, message?: string): this;
1880
+ /**
1881
+ * Requires the array values to be unique.
1882
+ * Remember that if you provide a custom comparator function,
1883
+ * different types can be passed as parameter depending on the rules you set on items.
1884
+ * Be aware that a deep equality is performed on elements of the array having a type of object,
1885
+ * a performance penalty is to be expected for this kind of operation.
1886
+ */
1887
+ unique(
1888
+ comparator?: string | ComparatorFunction,
1889
+ options?: ArrayUniqueOptions
1890
+ ): this;
1891
+ }
1729
1892
 
1730
- /**
1731
- * Requires the object to be an instance of a given constructor.
1732
- *
1733
- * @param constructor - the constructor function that the object must be an instance of.
1734
- * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name.
1735
- */
1736
- // tslint:disable-next-line:ban-types
1737
- instance(constructor: Function, name?: string): this;
1893
+ interface ObjectPatternOptions {
1894
+ fallthrough?: boolean;
1895
+ matches: SchemaLike | Reference;
1896
+ }
1738
1897
 
1739
- /**
1740
- * Sets or extends the allowed object keys.
1741
- */
1742
- keys(schema?: SchemaMap<TSchema>): this;
1898
+ interface ObjectSchema<TSchema = any> extends AnySchema<TSchema> {
1899
+ /**
1900
+ * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well.
1901
+ *
1902
+ * Optional settings must be the last argument.
1903
+ */
1904
+ and(...peers: Array<string | DependencyOptions>): this;
1743
1905
 
1744
- /**
1745
- * Specifies the exact number of keys in the object.
1746
- */
1747
- length(limit: number): this;
1906
+ /**
1907
+ * Appends the allowed object keys. If schema is null, undefined, or {}, no changes will be applied.
1908
+ */
1909
+ append(schema?: SchemaMap<TSchema>): this;
1910
+ append<TSchemaExtended = any, T = TSchemaExtended>(
1911
+ schema?: SchemaMap<T>
1912
+ ): ObjectSchema<T>;
1748
1913
 
1749
- /**
1750
- * Specifies the maximum number of keys in the object.
1751
- */
1752
- max(limit: number | Reference): this;
1914
+ /**
1915
+ * Verifies an assertion where.
1916
+ */
1917
+ assert(ref: string | Reference, schema: SchemaLike, message?: string): this;
1753
1918
 
1754
- /**
1755
- * Specifies the minimum number of keys in the object.
1756
- */
1757
- min(limit: number | Reference): this;
1919
+ /**
1920
+ * Requires the object to be an instance of a given constructor.
1921
+ *
1922
+ * @param constructor - the constructor function that the object must be an instance of.
1923
+ * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name.
1924
+ */
1925
+ // tslint:disable-next-line:ban-types
1926
+ instance(constructor: Function, name?: string): this;
1758
1927
 
1759
- /**
1760
- * Defines a relationship between keys where not all peers can be present at the same time.
1761
- *
1762
- * Optional settings must be the last argument.
1763
- */
1764
- nand(...peers: Array<string | DependencyOptions>): this;
1928
+ /**
1929
+ * Sets or extends the allowed object keys.
1930
+ */
1931
+ keys(schema?: SchemaMap<TSchema>): this;
1765
1932
 
1766
- /**
1767
- * Defines a relationship between keys where one of the peers is required (and more than one is allowed).
1768
- *
1769
- * Optional settings must be the last argument.
1770
- */
1771
- or(...peers: Array<string | DependencyOptions>): this;
1933
+ /**
1934
+ * Specifies the exact number of keys in the object.
1935
+ */
1936
+ length(limit: number): this;
1772
1937
 
1773
- /**
1774
- * Defines an exclusive relationship between a set of keys where only one is allowed but none are required.
1775
- *
1776
- * Optional settings must be the last argument.
1777
- */
1778
- oxor(...peers: Array<string | DependencyOptions>): this;
1938
+ /**
1939
+ * Specifies the maximum number of keys in the object.
1940
+ */
1941
+ max(limit: number | Reference): this;
1779
1942
 
1780
- /**
1781
- * Specify validation rules for unknown keys matching a pattern.
1782
- *
1783
- * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names
1784
- * @param schema - the schema object matching keys must validate against
1785
- */
1786
- pattern(pattern: RegExp | SchemaLike, schema: SchemaLike, options?: ObjectPatternOptions): this;
1943
+ /**
1944
+ * Specifies the minimum number of keys in the object.
1945
+ */
1946
+ min(limit: number | Reference): this;
1787
1947
 
1788
- /**
1789
- * Requires the object to be a Joi reference.
1790
- */
1791
- ref(): this;
1948
+ /**
1949
+ * Defines a relationship between keys where not all peers can be present at the same time.
1950
+ *
1951
+ * Optional settings must be the last argument.
1952
+ */
1953
+ nand(...peers: Array<string | DependencyOptions>): this;
1792
1954
 
1793
- /**
1794
- * Requires the object to be a `RegExp` object.
1795
- */
1796
- regex(): this;
1955
+ /**
1956
+ * Defines a relationship between keys where one of the peers is required (and more than one is allowed).
1957
+ *
1958
+ * Optional settings must be the last argument.
1959
+ */
1960
+ or(...peers: Array<string | DependencyOptions>): this;
1797
1961
 
1798
- /**
1799
- * Renames a key to another name (deletes the renamed key).
1800
- */
1801
- rename(from: string | RegExp, to: string, options?: RenameOptions): this;
1962
+ /**
1963
+ * Defines an exclusive relationship between a set of keys where only one is allowed but none are required.
1964
+ *
1965
+ * Optional settings must be the last argument.
1966
+ */
1967
+ oxor(...peers: Array<string | DependencyOptions>): this;
1802
1968
 
1803
- /**
1804
- * Requires the object to be a Joi schema instance.
1805
- */
1806
- schema(type?: SchemaLike): this;
1969
+ /**
1970
+ * Specify validation rules for unknown keys matching a pattern.
1971
+ *
1972
+ * @param pattern - a pattern that can be either a regular expression or a joi schema that will be tested against the unknown key names
1973
+ * @param schema - the schema object matching keys must validate against
1974
+ */
1975
+ pattern(
1976
+ pattern: RegExp | SchemaLike,
1977
+ schema: SchemaLike,
1978
+ options?: ObjectPatternOptions
1979
+ ): this;
1807
1980
 
1808
- /**
1809
- * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children).
1810
- */
1811
- unknown(allow?: boolean): this;
1981
+ /**
1982
+ * Requires the object to be a Joi reference.
1983
+ */
1984
+ ref(): this;
1812
1985
 
1813
- /**
1814
- * Requires the presence of other keys whenever the specified key is present.
1815
- */
1816
- with(key: string, peers: string | string[], options?: DependencyOptions): this;
1986
+ /**
1987
+ * Requires the object to be a `RegExp` object.
1988
+ */
1989
+ regex(): this;
1817
1990
 
1818
- /**
1819
- * Forbids the presence of other keys whenever the specified is present.
1820
- */
1821
- without(key: string, peers: string | string[], options?: DependencyOptions): this;
1991
+ /**
1992
+ * Renames a key to another name (deletes the renamed key).
1993
+ */
1994
+ rename(from: string | RegExp, to: string, options?: RenameOptions): this;
1822
1995
 
1823
- /**
1824
- * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time.
1825
- *
1826
- * Optional settings must be the last argument.
1827
- */
1828
- xor(...peers: Array<string | DependencyOptions>): this;
1829
- }
1996
+ /**
1997
+ * Requires the object to be a Joi schema instance.
1998
+ */
1999
+ schema(type?: SchemaLike): this;
1830
2000
 
1831
- interface BinarySchema<TSchema = Buffer> extends AnySchema<TSchema> {
1832
- /**
1833
- * Sets the string encoding format if a string input is converted to a buffer.
1834
- */
1835
- encoding(encoding: string): this;
2001
+ /**
2002
+ * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children).
2003
+ */
2004
+ unknown(allow?: boolean): this;
1836
2005
 
1837
- /**
1838
- * Specifies the minimum length of the buffer.
1839
- */
1840
- min(limit: number | Reference): this;
2006
+ /**
2007
+ * Requires the presence of other keys whenever the specified key is present.
2008
+ */
2009
+ with(
2010
+ key: string,
2011
+ peers: string | string[],
2012
+ options?: DependencyOptions
2013
+ ): this;
1841
2014
 
1842
- /**
1843
- * Specifies the maximum length of the buffer.
1844
- */
1845
- max(limit: number | Reference): this;
2015
+ /**
2016
+ * Forbids the presence of other keys whenever the specified is present.
2017
+ */
2018
+ without(
2019
+ key: string,
2020
+ peers: string | string[],
2021
+ options?: DependencyOptions
2022
+ ): this;
1846
2023
 
1847
- /**
1848
- * Specifies the exact length of the buffer:
1849
- */
1850
- length(limit: number | Reference): this;
1851
- }
2024
+ /**
2025
+ * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time.
2026
+ *
2027
+ * Optional settings must be the last argument.
2028
+ */
2029
+ xor(...peers: Array<string | DependencyOptions>): this;
2030
+ }
1852
2031
 
1853
- interface DateSchema<TSchema = Date> extends AnySchema<TSchema> {
1854
- /**
1855
- * Specifies that the value must be greater than date.
1856
- * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1857
- * allowing to explicitly ensure a date is either in the past or in the future.
1858
- * It can also be a reference to another field.
1859
- */
1860
- greater(date: 'now' | Date | number | string | Reference): this;
2032
+ interface BinarySchema<TSchema = Buffer> extends AnySchema<TSchema> {
2033
+ /**
2034
+ * Sets the string encoding format if a string input is converted to a buffer.
2035
+ */
2036
+ encoding(encoding: string): this;
1861
2037
 
1862
- /**
1863
- * Requires the string value to be in valid ISO 8601 date format.
1864
- */
1865
- iso(): this;
2038
+ /**
2039
+ * Specifies the minimum length of the buffer.
2040
+ */
2041
+ min(limit: number | Reference): this;
1866
2042
 
1867
- /**
1868
- * Specifies that the value must be less than date.
1869
- * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1870
- * allowing to explicitly ensure a date is either in the past or in the future.
1871
- * It can also be a reference to another field.
1872
- */
1873
- less(date: 'now' | Date | number | string | Reference): this;
2043
+ /**
2044
+ * Specifies the maximum length of the buffer.
2045
+ */
2046
+ max(limit: number | Reference): this;
1874
2047
 
1875
- /**
1876
- * Specifies the oldest date allowed.
1877
- * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1878
- * allowing to explicitly ensure a date is either in the past or in the future.
1879
- * It can also be a reference to another field.
1880
- */
1881
- min(date: 'now' | Date | number | string | Reference): this;
2048
+ /**
2049
+ * Specifies the exact length of the buffer:
2050
+ */
2051
+ length(limit: number | Reference): this;
2052
+ }
1882
2053
 
1883
- /**
1884
- * Specifies the latest date allowed.
1885
- * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
1886
- * allowing to explicitly ensure a date is either in the past or in the future.
1887
- * It can also be a reference to another field.
1888
- */
1889
- max(date: 'now' | Date | number | string | Reference): this;
2054
+ interface DateSchema<TSchema = Date> extends AnySchema<TSchema> {
2055
+ /**
2056
+ * Specifies that the value must be greater than date.
2057
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
2058
+ * allowing to explicitly ensure a date is either in the past or in the future.
2059
+ * It can also be a reference to another field.
2060
+ */
2061
+ greater(date: "now" | Date | number | string | Reference): this;
1890
2062
 
1891
- /**
1892
- * Requires the value to be a timestamp interval from Unix Time.
1893
- * @param type - the type of timestamp (allowed values are unix or javascript [default])
1894
- */
1895
- timestamp(type?: 'javascript' | 'unix'): this;
1896
- }
2063
+ /**
2064
+ * Requires the string value to be in valid ISO 8601 date format.
2065
+ */
2066
+ iso(): this;
1897
2067
 
1898
- interface FunctionSchema<TSchema = Function> extends ObjectSchema<TSchema> {
1899
- /**
1900
- * Specifies the arity of the function where:
1901
- * @param n - the arity expected.
1902
- */
1903
- arity(n: number): this;
2068
+ /**
2069
+ * Specifies that the value must be less than date.
2070
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
2071
+ * allowing to explicitly ensure a date is either in the past or in the future.
2072
+ * It can also be a reference to another field.
2073
+ */
2074
+ less(date: "now" | Date | number | string | Reference): this;
1904
2075
 
1905
- /**
1906
- * Requires the function to be a class.
1907
- */
1908
- class(): this;
2076
+ /**
2077
+ * Specifies the oldest date allowed.
2078
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
2079
+ * allowing to explicitly ensure a date is either in the past or in the future.
2080
+ * It can also be a reference to another field.
2081
+ */
2082
+ min(date: "now" | Date | number | string | Reference): this;
1909
2083
 
1910
- /**
1911
- * Specifies the minimal arity of the function where:
1912
- * @param n - the minimal arity expected.
1913
- */
1914
- minArity(n: number): this;
2084
+ /**
2085
+ * Specifies the latest date allowed.
2086
+ * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date,
2087
+ * allowing to explicitly ensure a date is either in the past or in the future.
2088
+ * It can also be a reference to another field.
2089
+ */
2090
+ max(date: "now" | Date | number | string | Reference): this;
1915
2091
 
1916
- /**
1917
- * Specifies the minimal arity of the function where:
1918
- * @param n - the minimal arity expected.
1919
- */
1920
- maxArity(n: number): this;
1921
- }
2092
+ /**
2093
+ * Requires the value to be a timestamp interval from Unix Time.
2094
+ * @param type - the type of timestamp (allowed values are unix or javascript [default])
2095
+ */
2096
+ timestamp(type?: "javascript" | "unix"): this;
2097
+ }
1922
2098
 
1923
- interface AlternativesSchema<TSchema = any> extends AnySchema<TSchema> {
1924
- /**
1925
- * Adds a conditional alternative schema type, either based on another key value, or a schema peeking into the current value.
1926
- */
1927
- conditional(ref: string | Reference, options: WhenOptions | WhenOptions[]): this;
1928
- conditional(ref: Schema, options: WhenSchemaOptions): this;
2099
+ interface FunctionSchema<TSchema = Function> extends ObjectSchema<TSchema> {
2100
+ /**
2101
+ * Specifies the arity of the function where:
2102
+ * @param n - the arity expected.
2103
+ */
2104
+ arity(n: number): this;
1929
2105
 
1930
- /**
1931
- * Requires the validated value to match a specific set of the provided alternative.try() schemas.
1932
- * Cannot be combined with `alternatives.conditional()`.
1933
- */
1934
- match(mode: 'any' | 'all' | 'one'): this;
2106
+ /**
2107
+ * Requires the function to be a class.
2108
+ */
2109
+ class(): this;
1935
2110
 
1936
- /**
1937
- * Adds an alternative schema type for attempting to match against the validated value.
1938
- */
1939
- try(...types: SchemaLikeWithoutArray[]): this;
1940
- }
2111
+ /**
2112
+ * Specifies the minimal arity of the function where:
2113
+ * @param n - the minimal arity expected.
2114
+ */
2115
+ minArity(n: number): this;
1941
2116
 
1942
- interface LinkSchema<TSchema = any> extends AnySchema<TSchema> {
1943
- /**
1944
- * Same as `any.concat()` but the schema is merged after the link is resolved which allows merging with schemas of the same type as the resolved link.
1945
- * Will throw an exception during validation if the merged types are not compatible.
1946
- */
1947
- concat(schema: Schema): this;
2117
+ /**
2118
+ * Specifies the minimal arity of the function where:
2119
+ * @param n - the minimal arity expected.
2120
+ */
2121
+ maxArity(n: number): this;
2122
+ }
1948
2123
 
1949
- /**
1950
- * Initializes the schema after constructions for cases where the schema has to be constructed first and then initialized.
1951
- * If `ref` was not passed to the constructor, `link.ref()` must be called prior to usage.
1952
- */
1953
- ref(ref: string): this;
1954
- }
2124
+ interface AlternativesSchema<TSchema = any> extends AnySchema<TSchema> {
2125
+ /**
2126
+ * Adds a conditional alternative schema type, either based on another key value, or a schema peeking into the current value.
2127
+ */
2128
+ conditional<ThenSchema, OtherwiseSchema>(
2129
+ ref: string | Reference,
2130
+ options: WhenOptions | WhenOptions[]
2131
+ ): AlternativesSchema<ThenSchema | OtherwiseSchema>;
2132
+ conditional<ThenSchema, OtherwiseSchema>(
2133
+ ref: Schema,
2134
+ options: WhenSchemaOptions<ThenSchema, OtherwiseSchema>
2135
+ ): AlternativesSchema<ThenSchema | OtherwiseSchema>;
1955
2136
 
1956
- interface Reference extends Exclude<ReferenceOptions, 'prefix'> {
1957
- depth: number;
1958
- type: string;
1959
- key: string;
1960
- root: string;
1961
- path: string[];
1962
- display: string;
1963
- toString(): string;
1964
- }
2137
+ /**
2138
+ * Requires the validated value to match a specific set of the provided alternative.try() schemas.
2139
+ * Cannot be combined with `alternatives.conditional()`.
2140
+ */
2141
+ match(mode: "any" | "all" | "one"): this;
1965
2142
 
1966
- type ExtensionBoundSchema = Schema & SchemaInternals;
2143
+ /**
2144
+ * Adds an alternative schema type for attempting to match against the validated value.
2145
+ */
2146
+ try<A>(a: SchemaLikeWithoutArray<A>): AlternativesSchema<A>;
2147
+ try<A, B>(
2148
+ a: SchemaLikeWithoutArray<A>,
2149
+ b: SchemaLikeWithoutArray<B>
2150
+ ): AlternativesSchema<A | B>;
2151
+ try<A, B, C>(
2152
+ a: SchemaLikeWithoutArray<A>,
2153
+ b: SchemaLikeWithoutArray<B>,
2154
+ c: SchemaLikeWithoutArray<C>
2155
+ ): AlternativesSchema<A | B | C>;
2156
+ try<A, B, C, D>(
2157
+ a: SchemaLikeWithoutArray<A>,
2158
+ b: SchemaLikeWithoutArray<B>,
2159
+ c: SchemaLikeWithoutArray<C>,
2160
+ d: SchemaLikeWithoutArray<D>
2161
+ ): AlternativesSchema<A | B | C | D>;
2162
+ try<A, B, C, D, E>(
2163
+ a: SchemaLikeWithoutArray<A>,
2164
+ b: SchemaLikeWithoutArray<B>,
2165
+ c: SchemaLikeWithoutArray<C>,
2166
+ d: SchemaLikeWithoutArray<D>,
2167
+ e: SchemaLikeWithoutArray<E>
2168
+ ): AlternativesSchema<A | B | C | D | E>;
2169
+ try<A, B, C, D, E, F>(
2170
+ a: SchemaLikeWithoutArray<A>,
2171
+ b: SchemaLikeWithoutArray<B>,
2172
+ c: SchemaLikeWithoutArray<C>,
2173
+ d: SchemaLikeWithoutArray<D>,
2174
+ e: SchemaLikeWithoutArray<E>,
2175
+ f: SchemaLikeWithoutArray<F>
2176
+ ): AlternativesSchema<A | B | C | D | E | F>;
2177
+ try(...types: SchemaLikeWithoutArray[]): this;
2178
+ }
1967
2179
 
1968
- interface RuleArgs {
1969
- name: string;
1970
- ref?: boolean;
1971
- assert?: ((value: any) => boolean) | AnySchema;
1972
- message?: string;
2180
+ interface LinkSchema<TSchema = any> extends AnySchema<TSchema> {
2181
+ /**
2182
+ * Same as `any.concat()` but the schema is merged after the link is resolved which allows merging with schemas of the same type as the resolved link.
2183
+ * Will throw an exception during validation if the merged types are not compatible.
2184
+ */
2185
+ concat(schema: Schema): this;
1973
2186
 
1974
- /**
1975
- * Undocumented properties
1976
- */
1977
- normalize?(value: any): any;
1978
- }
2187
+ /**
2188
+ * Initializes the schema after constructions for cases where the schema has to be constructed first and then initialized.
2189
+ * If `ref` was not passed to the constructor, `link.ref()` must be called prior to usage.
2190
+ */
2191
+ ref(ref: string): this;
2192
+ }
1979
2193
 
1980
- type RuleMethod = (...args: any[]) => any;
2194
+ interface Reference extends Exclude<ReferenceOptions, "prefix"> {
2195
+ depth: number;
2196
+ type: string;
2197
+ key: string;
2198
+ root: string;
2199
+ path: string[];
2200
+ display: string;
2201
+ toString(): string;
2202
+ }
1981
2203
 
1982
- interface ExtensionRule {
1983
- /**
1984
- * alternative name for this rule.
1985
- */
1986
- alias?: string;
1987
- /**
1988
- * whether rule supports multiple invocations.
1989
- */
1990
- multi?: boolean;
1991
- /**
1992
- * Dual rule: converts or validates.
1993
- */
1994
- convert?: boolean;
1995
- /**
1996
- * list of arguments accepted by `method`.
1997
- */
1998
- args?: Array<RuleArgs | string>;
1999
- /**
2000
- * rule body.
2001
- */
2002
- method?: RuleMethod | false;
2003
- /**
2004
- * validation function.
2005
- */
2006
- validate?(value: any, helpers: any, args: Record<string, any>, options: any): any;
2204
+ type ExtensionBoundSchema = Schema & SchemaInternals;
2007
2205
 
2008
- /**
2009
- * undocumented flags.
2010
- */
2011
- priority?: boolean;
2012
- manifest?: boolean;
2013
- }
2206
+ interface RuleArgs {
2207
+ name: string;
2208
+ ref?: boolean;
2209
+ assert?: ((value: any) => boolean) | AnySchema;
2210
+ message?: string;
2014
2211
 
2015
- interface CoerceResult {
2016
- errors?: ErrorReport[];
2017
- value?: any;
2018
- }
2212
+ /**
2213
+ * Undocumented properties
2214
+ */
2215
+ normalize?(value: any): any;
2216
+ }
2019
2217
 
2020
- type CoerceFunction = (value: any, helpers: CustomHelpers) => CoerceResult;
2218
+ type RuleMethod = (...args: any[]) => any;
2021
2219
 
2022
- interface CoerceObject {
2023
- method: CoerceFunction;
2024
- from?: string | string[];
2025
- }
2220
+ interface ExtensionRule {
2221
+ /**
2222
+ * alternative name for this rule.
2223
+ */
2224
+ alias?: string;
2225
+ /**
2226
+ * whether rule supports multiple invocations.
2227
+ */
2228
+ multi?: boolean;
2229
+ /**
2230
+ * Dual rule: converts or validates.
2231
+ */
2232
+ convert?: boolean;
2233
+ /**
2234
+ * list of arguments accepted by `method`.
2235
+ */
2236
+ args?: Array<RuleArgs | string>;
2237
+ /**
2238
+ * rule body.
2239
+ */
2240
+ method?: RuleMethod | false;
2241
+ /**
2242
+ * validation function.
2243
+ */
2244
+ validate?(
2245
+ value: any,
2246
+ helpers: any,
2247
+ args: Record<string, any>,
2248
+ options: any
2249
+ ): any;
2026
2250
 
2027
- interface ExtensionFlag {
2028
- setter?: string;
2029
- default?: any;
2030
- }
2251
+ /**
2252
+ * undocumented flags.
2253
+ */
2254
+ priority?: boolean;
2255
+ manifest?: boolean;
2256
+ }
2031
2257
 
2032
- interface ExtensionTermManifest {
2033
- mapped: {
2034
- from: string;
2035
- to: string;
2036
- };
2037
- }
2258
+ interface CoerceResult {
2259
+ errors?: ErrorReport[];
2260
+ value?: any;
2261
+ }
2038
2262
 
2039
- interface ExtensionTerm {
2040
- init: any[] | null;
2041
- register?: any;
2042
- manifest?: Record<string, 'schema' | 'single' | ExtensionTermManifest>;
2043
- }
2263
+ type CoerceFunction = (value: any, helpers: CustomHelpers) => CoerceResult;
2044
2264
 
2045
- interface Extension {
2046
- type: string | RegExp;
2047
- args?(...args: SchemaLike[]): Schema;
2048
- base?: Schema;
2049
- coerce?: CoerceFunction | CoerceObject;
2050
- flags?: Record<string, ExtensionFlag>;
2051
- manifest?: {
2052
- build?(obj: ExtensionBoundSchema, desc: Record<string, any>): any;
2053
- };
2054
- messages?: LanguageMessages | string;
2055
- modifiers?: Record<string, (rule: any, enabled?: boolean) => any>;
2056
- overrides?: Record<string, (value: any) => Schema>;
2057
- prepare?(value: any, helpers: CustomHelpers): any;
2058
- rebuild?(schema: ExtensionBoundSchema): void;
2059
- rules?: Record<string, ExtensionRule & ThisType<SchemaInternals>>;
2060
- terms?: Record<string, ExtensionTerm>;
2061
- validate?(value: any, helpers: CustomHelpers): any;
2265
+ interface CoerceObject {
2266
+ method: CoerceFunction;
2267
+ from?: string | string[];
2268
+ }
2062
2269
 
2063
- /**
2064
- * undocumented options
2065
- */
2066
- cast?: Record<string, { from(value: any): any; to(value: any, helpers: CustomHelpers): any }>;
2067
- properties?: Record<string, any>;
2068
- }
2270
+ interface ExtensionFlag {
2271
+ setter?: string;
2272
+ default?: any;
2273
+ }
2069
2274
 
2070
- type ExtensionFactory = (joi: Root) => Extension;
2275
+ interface ExtensionTermManifest {
2276
+ mapped: {
2277
+ from: string;
2278
+ to: string;
2279
+ };
2280
+ }
2281
+
2282
+ interface ExtensionTerm {
2283
+ init: any[] | null;
2284
+ register?: any;
2285
+ manifest?: Record<string, "schema" | "single" | ExtensionTermManifest>;
2286
+ }
2287
+
2288
+ interface Extension {
2289
+ type: string | RegExp;
2290
+ args?(...args: SchemaLike[]): Schema;
2291
+ base?: Schema;
2292
+ coerce?: CoerceFunction | CoerceObject;
2293
+ flags?: Record<string, ExtensionFlag>;
2294
+ manifest?: {
2295
+ build?(obj: ExtensionBoundSchema, desc: Record<string, any>): any;
2296
+ };
2297
+ messages?: LanguageMessages | string;
2298
+ modifiers?: Record<string, (rule: any, enabled?: boolean) => any>;
2299
+ overrides?: Record<string, (value: any) => Schema>;
2300
+ prepare?(value: any, helpers: CustomHelpers): any;
2301
+ rebuild?(schema: ExtensionBoundSchema): void;
2302
+ rules?: Record<string, ExtensionRule & ThisType<SchemaInternals>>;
2303
+ terms?: Record<string, ExtensionTerm>;
2304
+ validate?(value: any, helpers: CustomHelpers): any;
2071
2305
 
2072
- interface Err {
2073
- toString(): string;
2074
- }
2306
+ /**
2307
+ * undocumented options
2308
+ */
2309
+ cast?: Record<
2310
+ string,
2311
+ { from(value: any): any; to(value: any, helpers: CustomHelpers): any }
2312
+ >;
2313
+ properties?: Record<string, any>;
2314
+ }
2075
2315
 
2076
- // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2316
+ type ExtensionFactory = (joi: Root) => Extension;
2077
2317
 
2078
- interface Root {
2079
- /**
2080
- * Current version of the joi package.
2081
- */
2082
- version: string;
2318
+ interface Err {
2319
+ toString(): string;
2320
+ }
2083
2321
 
2084
- ValidationError: new (message: string, details: ValidationErrorItem[], original: any) => ValidationError;
2322
+ // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2085
2323
 
2086
- /**
2087
- * Generates a schema object that matches any data type.
2088
- */
2089
- any<TSchema = any>(): AnySchema<TSchema>;
2324
+ interface Root {
2325
+ /**
2326
+ * Current version of the joi package.
2327
+ */
2328
+ version: string;
2090
2329
 
2091
- /**
2092
- * Generates a schema object that matches an array data type.
2093
- */
2094
- array<TSchema = any[]>(): ArraySchema<TSchema>;
2330
+ ValidationError: new (
2331
+ message: string,
2332
+ details: ValidationErrorItem[],
2333
+ original: any
2334
+ ) => ValidationError;
2095
2335
 
2096
- /**
2097
- * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via boolean().
2098
- */
2099
- bool<TSchema = boolean>(): BooleanSchema<TSchema>;
2336
+ /**
2337
+ * Generates a schema object that matches any data type.
2338
+ */
2339
+ any<TSchema = any>(): AnySchema<TSchema>;
2100
2340
 
2101
- /**
2102
- * Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool().
2103
- */
2104
- boolean<TSchema = boolean>(): BooleanSchema<TSchema>;
2341
+ /**
2342
+ * Generates a schema object that matches an array data type.
2343
+ */
2344
+ array<TSchema = any[]>(): ArraySchema<TSchema>;
2105
2345
 
2106
- /**
2107
- * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers).
2108
- */
2109
- binary<TSchema = Buffer>(): BinarySchema<TSchema>;
2346
+ /**
2347
+ * Generates a schema object that matches a boolean data type (as well as the strings 'true' and 'false'). Can also be called via boolean().
2348
+ */
2349
+ bool<TSchema = boolean>(): BooleanSchema<TSchema>;
2110
2350
 
2111
- /**
2112
- * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds).
2113
- */
2114
- date<TSchema = Date>(): DateSchema<TSchema>;
2351
+ /**
2352
+ * Generates a schema object that matches a boolean data type (as well as the strings 'true' and 'false'). Can also be called via bool().
2353
+ */
2354
+ boolean<TSchema = boolean>(): BooleanSchema<TSchema>;
2115
2355
 
2116
- /**
2117
- * Generates a schema object that matches a function type.
2118
- */
2119
- func<TSchema = Function>(): FunctionSchema<TSchema>;
2356
+ /**
2357
+ * Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers).
2358
+ */
2359
+ binary<TSchema = Buffer>(): BinarySchema<TSchema>;
2120
2360
 
2121
- /**
2122
- * Generates a schema object that matches a function type.
2123
- */
2124
- function<TSchema = Function>(): FunctionSchema<TSchema>;
2361
+ /**
2362
+ * Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds).
2363
+ */
2364
+ date<TSchema = Date>(): DateSchema<TSchema>;
2125
2365
 
2126
- /**
2127
- * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers).
2128
- */
2129
- number<TSchema = number>(): NumberSchema<TSchema>;
2366
+ /**
2367
+ * Generates a schema object that matches a function type.
2368
+ */
2369
+ func<TSchema = Function>(): FunctionSchema<TSchema>;
2130
2370
 
2131
- /**
2132
- * Generates a schema object that matches an object data type (as well as JSON strings that have been parsed into objects).
2133
- */
2134
- // tslint:disable-next-line:no-unnecessary-generics
2135
- object<TSchema = any, isStrict = false, T = TSchema>(schema?: SchemaMap<T, isStrict>): ObjectSchema<TSchema>;
2371
+ /**
2372
+ * Generates a schema object that matches a function type.
2373
+ */
2374
+ function<TSchema = Function>(): FunctionSchema<TSchema>;
2136
2375
 
2137
- /**
2138
- * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow('').
2139
- */
2140
- string<TSchema = string>(): StringSchema<TSchema>;
2376
+ /**
2377
+ * Generates a schema object that matches a number data type (as well as strings that can be converted to numbers).
2378
+ */
2379
+ number<TSchema = number>(): NumberSchema<TSchema>;
2141
2380
 
2142
- /**
2143
- * Generates a schema object that matches any symbol.
2144
- */
2145
- symbol<TSchema = Symbol>(): SymbolSchema<TSchema>;
2381
+ /**
2382
+ * Generates a schema object that matches an object data type (as well as JSON strings that have been parsed into objects).
2383
+ */
2384
+ // tslint:disable-next-line:no-unnecessary-generics
2385
+ object<TSchema = any, isStrict = false, T = TSchema>(
2386
+ schema?: SchemaMap<T, isStrict>
2387
+ ): ObjectSchema<TSchema>;
2146
2388
 
2147
- /**
2148
- * Generates a type that will match one of the provided alternative schemas
2149
- */
2150
- alternatives<TSchema = any>(types: SchemaLike[]): AlternativesSchema<TSchema>;
2151
- alternatives<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
2389
+ /**
2390
+ * Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow('').
2391
+ */
2392
+ string<TSchema = string>(): StringSchema<TSchema>;
2152
2393
 
2153
- /**
2154
- * Alias for `alternatives`
2155
- */
2156
- alt<TSchema = any>(types: SchemaLike[]): AlternativesSchema<TSchema>;
2157
- alt<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
2394
+ /**
2395
+ * Generates a schema object that matches any symbol.
2396
+ */
2397
+ symbol<TSchema = Symbol>(): SymbolSchema<TSchema>;
2158
2398
 
2159
- /**
2160
- * Links to another schema node and reuses it for validation, typically for creative recursive schemas.
2161
- *
2162
- * @param ref - the reference to the linked schema node.
2163
- * Cannot reference itself or its children as well as other links.
2164
- * Links can be expressed in relative terms like value references (`Joi.link('...')`),
2165
- * in absolute terms from the schema run-time root (`Joi.link('/a')`),
2166
- * or using schema ids implicitly using object keys or explicitly using `any.id()` (`Joi.link('#a.b.c')`).
2167
- */
2168
- link<TSchema = any>(ref?: string): LinkSchema<TSchema>;
2399
+ /**
2400
+ * Generates a type that will match one of the provided alternative schemas
2401
+ */
2402
+ alternatives<A, B>(
2403
+ params: [SchemaLike<A>, SchemaLike<B>]
2404
+ ): AlternativesSchema<A | B>;
2405
+ alternatives<A, B, C>(
2406
+ params: [SchemaLike<A>, SchemaLike<B>, SchemaLike<C>]
2407
+ ): AlternativesSchema<A | B | C>;
2408
+ alternatives<A, B, C, D>(
2409
+ params: [SchemaLike<A>, SchemaLike<B>, SchemaLike<C>, SchemaLike<D>]
2410
+ ): AlternativesSchema<A | B | C | D>;
2411
+ alternatives<A, B, C, D, E>(
2412
+ params: [
2413
+ SchemaLike<A>,
2414
+ SchemaLike<B>,
2415
+ SchemaLike<C>,
2416
+ SchemaLike<D>,
2417
+ SchemaLike<E>
2418
+ ]
2419
+ ): AlternativesSchema<A | B | C | D | E>;
2420
+ alternatives<A, B>(
2421
+ a: SchemaLike<A>,
2422
+ b: SchemaLike<B>
2423
+ ): AlternativesSchema<A | B>;
2424
+ alternatives<A, B, C>(
2425
+ a: SchemaLike<A>,
2426
+ b: SchemaLike<B>,
2427
+ c: SchemaLike<C>
2428
+ ): AlternativesSchema<A | B | C>;
2429
+ alternatives<A, B, C, D>(
2430
+ a: SchemaLike<A>,
2431
+ b: SchemaLike<B>,
2432
+ c: SchemaLike<C>,
2433
+ d: SchemaLike<D>
2434
+ ): AlternativesSchema<A | B | C | D>;
2435
+ alternatives<A, B, C, D, E>(
2436
+ a: SchemaLike<A>,
2437
+ b: SchemaLike<B>,
2438
+ c: SchemaLike<C>,
2439
+ d: SchemaLike<D>,
2440
+ e: SchemaLike<E>
2441
+ ): AlternativesSchema<A | B | C | D | E>;
2442
+ alternatives<TSchema = any>(
2443
+ types: SchemaLike<TSchema>[]
2444
+ ): AlternativesSchema<TSchema>;
2445
+ alternatives<TSchema = any>(
2446
+ ...types: SchemaLike<TSchema>[]
2447
+ ): AlternativesSchema<TSchema>;
2169
2448
 
2170
- /**
2171
- * Validates a value against a schema and throws if validation fails.
2172
- *
2173
- * @param value - the value to validate.
2174
- * @param schema - the schema object.
2175
- * @param message - optional message string prefix added in front of the error message. may also be an Error object.
2176
- */
2177
- assert(value: any, schema: Schema, options?: ValidationOptions): void;
2178
- assert(value: any, schema: Schema, message: string | Error, options?: ValidationOptions): void;
2449
+ /**
2450
+ * Alias for `alternatives`
2451
+ */
2452
+ alt<A, B>(
2453
+ params: [SchemaLike<A>, SchemaLike<B>]
2454
+ ): AlternativesSchema<A | B>;
2455
+ alt<A, B, C>(
2456
+ params: [SchemaLike<A>, SchemaLike<B>, SchemaLike<C>]
2457
+ ): AlternativesSchema<A | B | C>;
2458
+ alt<A, B, C, D>(
2459
+ params: [SchemaLike<A>, SchemaLike<B>, SchemaLike<C>, SchemaLike<D>]
2460
+ ): AlternativesSchema<A | B | C | D>;
2461
+ alt<A, B, C, D, E>(
2462
+ params: [
2463
+ SchemaLike<A>,
2464
+ SchemaLike<B>,
2465
+ SchemaLike<C>,
2466
+ SchemaLike<D>,
2467
+ SchemaLike<E>
2468
+ ]
2469
+ ): AlternativesSchema<A | B | C | D | E>;
2470
+ alt<A, B>(a: SchemaLike<A>, b: SchemaLike<B>): AlternativesSchema<A | B>;
2471
+ alt<A, B, C>(
2472
+ a: SchemaLike<A>,
2473
+ b: SchemaLike<B>,
2474
+ c: SchemaLike<C>
2475
+ ): AlternativesSchema<A | B | C>;
2476
+ alt<A, B, C, D>(
2477
+ a: SchemaLike<A>,
2478
+ b: SchemaLike<B>,
2479
+ c: SchemaLike<C>,
2480
+ d: SchemaLike<D>
2481
+ ): AlternativesSchema<A | B | C | D>;
2482
+ alt<A, B, C, D, E>(
2483
+ a: SchemaLike<A>,
2484
+ b: SchemaLike<B>,
2485
+ c: SchemaLike<C>,
2486
+ d: SchemaLike<D>,
2487
+ e: SchemaLike<E>
2488
+ ): AlternativesSchema<A | B | C | D | E>;
2489
+ alt<TSchema = any>(types: SchemaLike[]): AlternativesSchema<TSchema>;
2490
+ alt<TSchema = any>(...types: SchemaLike[]): AlternativesSchema<TSchema>;
2491
+
2492
+ /**
2493
+ * Links to another schema node and reuses it for validation, typically for creative recursive schemas.
2494
+ *
2495
+ * @param ref - the reference to the linked schema node.
2496
+ * Cannot reference itself or its children as well as other links.
2497
+ * Links can be expressed in relative terms like value references (`Joi.link('...')`),
2498
+ * in absolute terms from the schema run-time root (`Joi.link('/a')`),
2499
+ * or using schema ids implicitly using object keys or explicitly using `any.id()` (`Joi.link('#a.b.c')`).
2500
+ */
2501
+ link<TSchema = any>(ref?: string): LinkSchema<TSchema>;
2179
2502
 
2180
- /**
2181
- * Validates a value against a schema, returns valid object, and throws if validation fails.
2182
- *
2183
- * @param value - the value to validate.
2184
- * @param schema - the schema object.
2185
- * @param message - optional message string prefix added in front of the error message. may also be an Error object.
2186
- */
2187
- attempt<TSchema extends Schema>(value: any, schema: TSchema, options?: ValidationOptions): TSchema extends Schema<infer Value> ? Value : never;
2188
- attempt<TSchema extends Schema>(value: any, schema: TSchema, message: string | Error, options?: ValidationOptions): TSchema extends Schema<infer Value> ? Value : never;
2503
+ /**
2504
+ * Validates a value against a schema and throws if validation fails.
2505
+ *
2506
+ * @param value - the value to validate.
2507
+ * @param schema - the schema object.
2508
+ * @param message - optional message string prefix added in front of the error message. may also be an Error object.
2509
+ */
2510
+ assert(value: any, schema: Schema, options?: ValidationOptions): void;
2511
+ assert(
2512
+ value: any,
2513
+ schema: Schema,
2514
+ message: string | Error,
2515
+ options?: ValidationOptions
2516
+ ): void;
2189
2517
 
2190
- cache: CacheConfiguration;
2518
+ /**
2519
+ * Validates a value against a schema, returns valid object, and throws if validation fails.
2520
+ *
2521
+ * @param value - the value to validate.
2522
+ * @param schema - the schema object.
2523
+ * @param message - optional message string prefix added in front of the error message. may also be an Error object.
2524
+ */
2525
+ attempt<TSchema extends Schema>(
2526
+ value: any,
2527
+ schema: TSchema,
2528
+ options?: ValidationOptions
2529
+ ): TSchema extends Schema<infer Value> ? Value : never;
2530
+ attempt<TSchema extends Schema>(
2531
+ value: any,
2532
+ schema: TSchema,
2533
+ message: string | Error,
2534
+ options?: ValidationOptions
2535
+ ): TSchema extends Schema<infer Value> ? Value : never;
2191
2536
 
2192
- /**
2193
- * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object).
2194
- */
2195
- compile(schema: SchemaLike, options?: CompileOptions): Schema;
2537
+ cache: CacheConfiguration;
2196
2538
 
2197
- /**
2198
- * Checks if the provided preferences are valid.
2199
- *
2200
- * Throws an exception if the prefs object is invalid.
2201
- *
2202
- * The method is provided to perform inputs validation for the `any.validate()` and `any.validateAsync()` methods.
2203
- * Validation is not performed automatically for performance reasons. Instead, manually validate the preferences passed once and reuse.
2204
- */
2205
- checkPreferences(prefs: ValidationOptions): void;
2539
+ /**
2540
+ * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object).
2541
+ */
2542
+ compile(schema: SchemaLike, options?: CompileOptions): Schema;
2206
2543
 
2207
- /**
2208
- * Creates a custom validation schema.
2209
- */
2210
- custom(fn: CustomValidator, description?: string): Schema;
2544
+ /**
2545
+ * Checks if the provided preferences are valid.
2546
+ *
2547
+ * Throws an exception if the prefs object is invalid.
2548
+ *
2549
+ * The method is provided to perform inputs validation for the `any.validate()` and `any.validateAsync()` methods.
2550
+ * Validation is not performed automatically for performance reasons. Instead, manually validate the preferences passed once and reuse.
2551
+ */
2552
+ checkPreferences(prefs: ValidationOptions): void;
2211
2553
 
2212
- /**
2213
- * Creates a new Joi instance that will apply defaults onto newly created schemas
2214
- * through the use of the fn function that takes exactly one argument, the schema being created.
2215
- *
2216
- * @param fn - The function must always return a schema, even if untransformed.
2217
- */
2218
- defaults(fn: SchemaFunction): Root;
2554
+ /**
2555
+ * Creates a custom validation schema.
2556
+ */
2557
+ custom(fn: CustomValidator, description?: string): Schema;
2219
2558
 
2220
- /**
2221
- * Generates a dynamic expression using a template string.
2222
- */
2223
- expression(template: string, options?: ReferenceOptions): any;
2559
+ /**
2560
+ * Creates a new Joi instance that will apply defaults onto newly created schemas
2561
+ * through the use of the fn function that takes exactly one argument, the schema being created.
2562
+ *
2563
+ * @param fn - The function must always return a schema, even if untransformed.
2564
+ */
2565
+ defaults(fn: SchemaFunction): Root;
2224
2566
 
2225
- /**
2226
- * Creates a new Joi instance customized with the extension(s) you provide included.
2227
- */
2228
- extend(...extensions: Array<Extension | ExtensionFactory>): any;
2567
+ /**
2568
+ * Generates a dynamic expression using a template string.
2569
+ */
2570
+ expression(template: string, options?: ReferenceOptions): any;
2229
2571
 
2230
- /**
2231
- * Creates a reference that when resolved, is used as an array of values to match against the rule.
2232
- */
2233
- in(ref: string, options?: ReferenceOptions): Reference;
2572
+ /**
2573
+ * Creates a new Joi instance customized with the extension(s) you provide included.
2574
+ */
2575
+ extend(...extensions: Array<Extension | ExtensionFactory>): any;
2234
2576
 
2235
- /**
2236
- * Checks whether or not the provided argument is an instance of ValidationError
2237
- */
2238
- isError(error: any): error is ValidationError;
2577
+ /**
2578
+ * Creates a reference that when resolved, is used as an array of values to match against the rule.
2579
+ */
2580
+ in(ref: string, options?: ReferenceOptions): Reference;
2239
2581
 
2240
- /**
2241
- * Checks whether or not the provided argument is an expression.
2242
- */
2243
- isExpression(expression: any): boolean;
2582
+ /**
2583
+ * Checks whether or not the provided argument is an instance of ValidationError
2584
+ */
2585
+ isError(error: any): error is ValidationError;
2244
2586
 
2245
- /**
2246
- * Checks whether or not the provided argument is a reference. It's especially useful if you want to post-process error messages.
2247
- */
2248
- isRef(ref: any): ref is Reference;
2587
+ /**
2588
+ * Checks whether or not the provided argument is an expression.
2589
+ */
2590
+ isExpression(expression: any): boolean;
2249
2591
 
2250
- /**
2251
- * Checks whether or not the provided argument is a joi schema.
2252
- */
2253
- isSchema(schema: any, options?: CompileOptions): schema is AnySchema;
2592
+ /**
2593
+ * Checks whether or not the provided argument is a reference. It's especially useful if you want to post-process error messages.
2594
+ */
2595
+ isRef(ref: any): ref is Reference;
2254
2596
 
2255
- /**
2256
- * A special value used with `any.allow()`, `any.invalid()`, and `any.valid()` as the first value to reset any previously set values.
2257
- */
2258
- override: symbol;
2597
+ /**
2598
+ * Checks whether or not the provided argument is a joi schema.
2599
+ */
2600
+ isSchema(schema: any, options?: CompileOptions): schema is AnySchema;
2259
2601
 
2260
- /**
2261
- * Generates a reference to the value of the named key.
2262
- */
2263
- ref(key: string, options?: ReferenceOptions): Reference;
2602
+ /**
2603
+ * A special value used with `any.allow()`, `any.invalid()`, and `any.valid()` as the first value to reset any previously set values.
2604
+ */
2605
+ override: symbol;
2264
2606
 
2265
- /**
2266
- * Returns an object where each key is a plain joi schema type.
2267
- * Useful for creating type shortcuts using deconstruction.
2268
- * Note that the types are already formed and do not need to be called as functions (e.g. `string`, not `string()`).
2269
- */
2270
- types(): {
2271
- alternatives: AlternativesSchema;
2272
- any: AnySchema;
2273
- array: ArraySchema;
2274
- binary: BinarySchema;
2275
- boolean: BooleanSchema;
2276
- date: DateSchema;
2277
- function: FunctionSchema;
2278
- link: LinkSchema;
2279
- number: NumberSchema;
2280
- object: ObjectSchema;
2281
- string: StringSchema;
2282
- symbol: SymbolSchema;
2283
- };
2607
+ /**
2608
+ * Generates a reference to the value of the named key.
2609
+ */
2610
+ ref(key: string, options?: ReferenceOptions): Reference;
2284
2611
 
2285
- /**
2286
- * Generates a dynamic expression using a template string.
2287
- */
2288
- x(template: string, options?: ReferenceOptions): any;
2612
+ /**
2613
+ * Returns an object where each key is a plain joi schema type.
2614
+ * Useful for creating type shortcuts using deconstruction.
2615
+ * Note that the types are already formed and do not need to be called as functions (e.g. `string`, not `string()`).
2616
+ */
2617
+ types(): {
2618
+ alternatives: AlternativesSchema;
2619
+ any: AnySchema;
2620
+ array: ArraySchema;
2621
+ binary: BinarySchema;
2622
+ boolean: BooleanSchema;
2623
+ date: DateSchema;
2624
+ function: FunctionSchema;
2625
+ link: LinkSchema;
2626
+ number: NumberSchema;
2627
+ object: ObjectSchema;
2628
+ string: StringSchema;
2629
+ symbol: SymbolSchema;
2630
+ };
2289
2631
 
2290
- // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2291
- // Below are undocumented APIs. use at your own risk
2292
- // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2632
+ /**
2633
+ * Generates a dynamic expression using a template string.
2634
+ */
2635
+ x(template: string, options?: ReferenceOptions): any;
2293
2636
 
2294
- /**
2295
- * Whitelists a value
2296
- */
2297
- allow(...values: any[]): Schema;
2637
+ // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2638
+ // Below are undocumented APIs. use at your own risk
2639
+ // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
2298
2640
 
2299
- /**
2300
- * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
2301
- */
2302
- valid(...values: any[]): Schema;
2303
- equal(...values: any[]): Schema;
2641
+ /**
2642
+ * Whitelists a value
2643
+ */
2644
+ allow(...values: any[]): Schema;
2304
2645
 
2305
- /**
2306
- * Blacklists a value
2307
- */
2308
- invalid(...values: any[]): Schema;
2309
- disallow(...values: any[]): Schema;
2310
- not(...values: any[]): Schema;
2646
+ /**
2647
+ * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
2648
+ */
2649
+ valid(...values: any[]): Schema;
2650
+ equal(...values: any[]): Schema;
2311
2651
 
2312
- /**
2313
- * Marks a key as required which will not allow undefined as value. All keys are optional by default.
2314
- */
2315
- required(): Schema;
2652
+ /**
2653
+ * Blacklists a value
2654
+ */
2655
+ invalid(...values: any[]): Schema;
2656
+ disallow(...values: any[]): Schema;
2657
+ not(...values: any[]): Schema;
2316
2658
 
2317
- /**
2318
- * Alias of `required`.
2319
- */
2320
- exist(): Schema;
2659
+ /**
2660
+ * Marks a key as required which will not allow undefined as value. All keys are optional by default.
2661
+ */
2662
+ required(): Schema;
2321
2663
 
2322
- /**
2323
- * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
2324
- */
2325
- optional(): Schema;
2664
+ /**
2665
+ * Alias of `required`.
2666
+ */
2667
+ exist(): Schema;
2326
2668
 
2327
- /**
2328
- * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
2329
- */
2330
- forbidden(): Schema;
2669
+ /**
2670
+ * Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
2671
+ */
2672
+ optional(): Schema;
2331
2673
 
2332
- /**
2333
- * Overrides the global validate() options for the current key and any sub-key.
2334
- */
2335
- preferences(options: ValidationOptions): Schema;
2674
+ /**
2675
+ * Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
2676
+ */
2677
+ forbidden(): Schema;
2336
2678
 
2337
- /**
2338
- * Overrides the global validate() options for the current key and any sub-key.
2339
- */
2340
- prefs(options: ValidationOptions): Schema;
2679
+ /**
2680
+ * Overrides the global validate() options for the current key and any sub-key.
2681
+ */
2682
+ preferences(options: ValidationOptions): Schema;
2341
2683
 
2342
- /**
2343
- * Converts the type into an alternatives type where the conditions are merged into the type definition where:
2344
- */
2345
- when(ref: string | Reference, options: WhenOptions | WhenOptions[]): AlternativesSchema;
2346
- when(ref: Schema, options: WhenSchemaOptions): AlternativesSchema;
2684
+ /**
2685
+ * Overrides the global validate() options for the current key and any sub-key.
2686
+ */
2687
+ prefs(options: ValidationOptions): Schema;
2347
2688
 
2348
- /**
2349
- * Unsure, maybe alias for `compile`?
2350
- */
2351
- build(...args: any[]): any;
2689
+ /**
2690
+ * Converts the type into an alternatives type where the conditions are merged into the type definition where:
2691
+ */
2692
+ when(
2693
+ ref: string | Reference,
2694
+ options: WhenOptions | WhenOptions[]
2695
+ ): AlternativesSchema;
2696
+ when(ref: Schema, options: WhenSchemaOptions): AlternativesSchema;
2352
2697
 
2353
- /**
2354
- * Unsure, maybe alias for `preferences`?
2355
- */
2356
- options(...args: any[]): any;
2698
+ /**
2699
+ * Unsure, maybe alias for `compile`?
2700
+ */
2701
+ build(...args: any[]): any;
2357
2702
 
2358
- /**
2359
- * Unsure, maybe leaked from `@hapi/lab/coverage/initialize`
2360
- */
2361
- trace(...args: any[]): any;
2362
- untrace(...args: any[]): any;
2363
- }
2703
+ /**
2704
+ * Unsure, maybe alias for `preferences`?
2705
+ */
2706
+ options(...args: any[]): any;
2707
+
2708
+ /**
2709
+ * Unsure, maybe leaked from `@hapi/lab/coverage/initialize`
2710
+ */
2711
+ trace(...args: any[]): any;
2712
+ untrace(...args: any[]): any;
2713
+ }
2364
2714
  }
2365
2715
 
2366
2716
  declare const Joi: Joi.Root;
@@ -3184,10 +3534,16 @@ type StrictSchemaMap<TSchema = any> = {
3184
3534
 
3185
3535
  type SchemaMap<TSchema = any, isStrict = false> = isStrict extends true ? StrictSchemaMap<TSchema> : PartialSchemaMap<TSchema>;
3186
3536
 
3187
- type SchemaLikeWithoutArray = string | number | boolean | null | Schema$1 | SchemaMap;
3537
+ type Primitives = string | number | boolean | bigint | symbol | null;
3538
+
3539
+ type SchemaLikeWithoutArray<TSchema = any> = Exclude<Primitives | Schema$1<TSchema> | SchemaMap<TSchema>, any[]>;
3188
3540
 
3189
3541
  type SchemaLike = SchemaLikeWithoutArray | object;
3190
3542
 
3543
+ type NoNestedArrays<T extends readonly unknown[]> = Extract<T[number], readonly unknown[]> extends never ? T : never;
3544
+
3545
+ type UnwrapSchemaLikeWithoutArray<T> = T extends SchemaLikeWithoutArray<infer U> ? U : never;
3546
+
3191
3547
  interface ArraySchema<TSchema = any[]> extends AnySchema<TSchema> {
3192
3548
  /**
3193
3549
  * Verifies that an assertion passes for at least one item in the array, where:
@@ -3203,9 +3559,17 @@ interface ArraySchema<TSchema = any[]> extends AnySchema<TSchema> {
3203
3559
  * Errors will contain the number of items that didn't match.
3204
3560
  * Any unmatched item having a label will be mentioned explicitly.
3205
3561
  *
3206
- * @param types - a joi schema object to validate each array item against.
3207
- */
3208
- items(...types: SchemaLikeWithoutArray[]): this;
3562
+ * @param type - a joi schema object to validate each array item against.
3563
+ */
3564
+ items<A>(a: SchemaLikeWithoutArray<A>): ArraySchema<A[]>;
3565
+ items<A, B>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>): ArraySchema<(A | B)[]>;
3566
+ items<A, B, C>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>): ArraySchema<(A | B | C)[]>;
3567
+ items<A, B, C, D>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>, d: SchemaLikeWithoutArray<D>): ArraySchema<(A | B | C | D)[]>;
3568
+ items<A, B, C, D, E>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>, d: SchemaLikeWithoutArray<D>, e: SchemaLikeWithoutArray<E>): ArraySchema<(A | B | C | D | E)[]>;
3569
+ items<A, B, C, D, E, F>(a: SchemaLikeWithoutArray<A>, b: SchemaLikeWithoutArray<B>, c: SchemaLikeWithoutArray<C>, d: SchemaLikeWithoutArray<D>, e: SchemaLikeWithoutArray<E>, f: SchemaLikeWithoutArray<F>): ArraySchema<(A | B | C | D | E | F)[]>;
3570
+ items<TItems, TTItems extends SchemaLikeWithoutArray<TItems>[] = SchemaLikeWithoutArray<TItems>[]>(...types: NoNestedArrays<TTItems>): ArraySchema<{
3571
+ [I in keyof TTItems]: UnwrapSchemaLikeWithoutArray<TTItems[I]>;
3572
+ }[number][]>;
3209
3573
  /**
3210
3574
  * Specifies the exact number of items in the array.
3211
3575
  */
@@ -3816,6 +4180,18 @@ interface AnySchema<TSchema = any> {
3816
4180
  when(ref: Schema$1, options: WhenSchemaOptions): this;
3817
4181
  }
3818
4182
 
4183
+ interface BigIntSchema<T = bigint> extends AnySchema<T> {
4184
+ greater(limit: bigint | Reference): this;
4185
+ less(limit: bigint | Reference): this;
4186
+ max(limit: bigint | Reference): this;
4187
+ min(limit: bigint | Reference): this;
4188
+ multiple(base: bigint | Reference): this;
4189
+ negative(): this;
4190
+ port(): this;
4191
+ positive(): this;
4192
+ sign(sign: 'positive' | 'negative'): this;
4193
+ }
4194
+
3819
4195
  declare class DataValidator {
3820
4196
  /**
3821
4197
  * 任意类型验证
@@ -3832,6 +4208,11 @@ declare class DataValidator {
3832
4208
  * @constructor
3833
4209
  */
3834
4210
  static Number<TSchema = number>(): NumberSchema<TSchema>;
4211
+ /**
4212
+ * 大数类型验证
4213
+ * @constructor
4214
+ */
4215
+ static BigInt<TSchema = bigint>(): BigIntSchema<TSchema>;
3835
4216
  /**
3836
4217
  * 布尔类型验证
3837
4218
  * @constructor
@@ -4145,4 +4526,4 @@ declare class DTO extends DataValidator {
4145
4526
  }
4146
4527
 
4147
4528
  export { DTO };
4148
- export type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, CustomValidator, DateSchema, FunctionSchema, JSONSchema, LinkSchema, NumberSchema, ObjectSchema, Reference, ReferenceOptions, Schema$1 as Schema, SchemaFunction, SchemaLike, StringSchema, SymbolSchema, ValidationOptions };
4529
+ export type { AlternativesSchema, AnySchema, ArraySchema, BigIntSchema, BinarySchema, BooleanSchema, CustomValidator, DateSchema, FunctionSchema, JSONSchema, LinkSchema, NoNestedArrays, NumberSchema, ObjectSchema, Primitives, Reference, ReferenceOptions, Schema$1 as Schema, SchemaFunction, SchemaLike, SchemaLikeWithoutArray, StringSchema, SymbolSchema, UnwrapSchemaLikeWithoutArray, ValidationOptions };