@croct/sdk 0.17.7 → 0.17.8

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 (409) hide show
  1. package/activeRecord.cjs.map +1 -0
  2. package/activeRecord.d.ts +8 -4
  3. package/activeRecord.js +115 -106
  4. package/activeRecord.js.map +1 -1
  5. package/apiKey.cjs.map +1 -0
  6. package/apiKey.d.ts +4 -2
  7. package/apiKey.js +152 -141
  8. package/apiKey.js.map +1 -1
  9. package/base64Url.cjs.map +1 -0
  10. package/base64Url.d.ts +4 -2
  11. package/base64Url.js +8 -15
  12. package/base64Url.js.map +1 -1
  13. package/cache/cache.cjs.map +1 -0
  14. package/cache/cache.d.ts +6 -4
  15. package/cache/cache.js +9 -10
  16. package/cache/cache.js.map +1 -1
  17. package/cache/cookieCache.cjs.map +1 -0
  18. package/cache/cookieCache.d.ts +6 -3
  19. package/cache/cookieCache.js +52 -54
  20. package/cache/cookieCache.js.map +1 -1
  21. package/cache/fallbackCache.cjs.map +1 -0
  22. package/cache/fallbackCache.d.ts +5 -2
  23. package/cache/fallbackCache.js +20 -21
  24. package/cache/fallbackCache.js.map +1 -1
  25. package/cache/inMemoryCache.cjs.map +1 -0
  26. package/cache/inMemoryCache.d.ts +5 -2
  27. package/cache/inMemoryCache.js +15 -17
  28. package/cache/inMemoryCache.js.map +1 -1
  29. package/cache/index.cjs.map +1 -0
  30. package/cache/index.d.ts +4 -4
  31. package/cache/index.js +9 -11
  32. package/cache/index.js.map +1 -1
  33. package/cache/localStorageCache.cjs.map +1 -0
  34. package/cache/localStorageCache.d.ts +5 -2
  35. package/cache/localStorageCache.js +55 -63
  36. package/cache/localStorageCache.js.map +1 -1
  37. package/channel/channel.cjs.map +1 -0
  38. package/channel/channel.d.ts +8 -6
  39. package/channel/channel.js +21 -22
  40. package/channel/channel.js.map +1 -1
  41. package/channel/encodedChannel.cjs.map +1 -0
  42. package/channel/encodedChannel.d.ts +6 -3
  43. package/channel/encodedChannel.js +13 -14
  44. package/channel/encodedChannel.js.map +1 -1
  45. package/channel/guaranteedChannel.cjs.map +1 -0
  46. package/channel/guaranteedChannel.d.ts +9 -7
  47. package/channel/guaranteedChannel.js +74 -73
  48. package/channel/guaranteedChannel.js.map +1 -1
  49. package/channel/httpBeaconChannel.cjs.map +1 -0
  50. package/channel/httpBeaconChannel.d.ts +9 -6
  51. package/channel/httpBeaconChannel.js +82 -83
  52. package/channel/httpBeaconChannel.js.map +1 -1
  53. package/channel/index.cjs.map +1 -0
  54. package/channel/index.d.ts +12 -7
  55. package/channel/index.js +15 -17
  56. package/channel/index.js.map +1 -1
  57. package/channel/queuedChannel.cjs.map +1 -0
  58. package/channel/queuedChannel.d.ts +7 -4
  59. package/channel/queuedChannel.js +87 -97
  60. package/channel/queuedChannel.js.map +1 -1
  61. package/channel/retryChannel.cjs.map +1 -0
  62. package/channel/retryChannel.d.ts +7 -5
  63. package/channel/retryChannel.js +58 -57
  64. package/channel/retryChannel.js.map +1 -1
  65. package/channel/sandboxChannel.cjs.map +1 -0
  66. package/channel/sandboxChannel.d.ts +5 -2
  67. package/channel/sandboxChannel.js +34 -35
  68. package/channel/sandboxChannel.js.map +1 -1
  69. package/cid/assigner.cjs.map +1 -0
  70. package/cid/assigner.d.ts +3 -1
  71. package/cid/assigner.js +0 -2
  72. package/cid/assigner.js.map +1 -1
  73. package/cid/cachedAssigner.cjs.map +1 -0
  74. package/cid/cachedAssigner.d.ts +7 -5
  75. package/cid/cachedAssigner.js +37 -43
  76. package/cid/cachedAssigner.js.map +1 -1
  77. package/cid/fixedAssigner.cjs.map +1 -0
  78. package/cid/fixedAssigner.d.ts +5 -2
  79. package/cid/fixedAssigner.js +9 -10
  80. package/cid/fixedAssigner.js.map +1 -1
  81. package/cid/index.cjs.map +1 -0
  82. package/cid/index.d.ts +6 -4
  83. package/cid/index.js +9 -11
  84. package/cid/index.js.map +1 -1
  85. package/cid/remoteAssigner.cjs.map +1 -0
  86. package/cid/remoteAssigner.d.ts +6 -3
  87. package/cid/remoteAssigner.js +36 -37
  88. package/cid/remoteAssigner.js.map +1 -1
  89. package/constants.cjs.map +1 -0
  90. package/constants.d.ts +6 -4
  91. package/constants.js +10 -7
  92. package/constants.js.map +1 -1
  93. package/container.cjs.map +1 -0
  94. package/container.d.ts +28 -15
  95. package/container.js +269 -252
  96. package/container.js.map +1 -1
  97. package/contentFetcher.cjs.map +1 -0
  98. package/contentFetcher.d.ts +17 -14
  99. package/contentFetcher.js +156 -163
  100. package/contentFetcher.js.map +1 -1
  101. package/context.cjs.map +1 -0
  102. package/context.d.ts +13 -9
  103. package/context.js +80 -81
  104. package/context.js.map +1 -1
  105. package/error.cjs.map +1 -0
  106. package/error.d.ts +4 -2
  107. package/error.js +21 -21
  108. package/error.js.map +1 -1
  109. package/evaluator.cjs.map +1 -0
  110. package/evaluator.d.ts +18 -16
  111. package/evaluator.js +179 -179
  112. package/evaluator.js.map +1 -1
  113. package/eventManager.cjs.map +1 -0
  114. package/eventManager.d.ts +8 -6
  115. package/eventManager.js +24 -26
  116. package/eventManager.js.map +1 -1
  117. package/eventSubjectProcessor.cjs.map +1 -0
  118. package/eventSubjectProcessor.d.ts +16 -3
  119. package/eventSubjectProcessor.js +53 -59
  120. package/eventSubjectProcessor.js.map +1 -1
  121. package/facade/contentFetcherFacade.cjs.map +1 -0
  122. package/facade/contentFetcherFacade.d.ts +16 -7
  123. package/facade/contentFetcherFacade.js +32 -35
  124. package/facade/contentFetcherFacade.js.map +1 -1
  125. package/facade/evaluatorFacade.cjs.map +1 -0
  126. package/facade/evaluatorFacade.d.ts +17 -10
  127. package/facade/evaluatorFacade.js +56 -60
  128. package/facade/evaluatorFacade.js.map +1 -1
  129. package/facade/index.cjs.map +1 -0
  130. package/facade/index.d.ts +29 -7
  131. package/facade/index.js +19 -19
  132. package/facade/index.js.map +1 -1
  133. package/facade/sdkFacade.cjs.map +1 -0
  134. package/facade/sdkFacade.d.ts +33 -15
  135. package/facade/sdkFacade.js +201 -214
  136. package/facade/sdkFacade.js.map +1 -1
  137. package/facade/sessionFacade.cjs.map +1 -0
  138. package/facade/sessionFacade.d.ts +18 -3
  139. package/facade/sessionFacade.js +10 -11
  140. package/facade/sessionFacade.js.map +1 -1
  141. package/facade/sessionPatch.cjs.map +1 -0
  142. package/facade/sessionPatch.d.ts +17 -4
  143. package/facade/sessionPatch.js +22 -24
  144. package/facade/sessionPatch.js.map +1 -1
  145. package/facade/trackerFacade.cjs.map +1 -0
  146. package/facade/trackerFacade.d.ts +17 -4
  147. package/facade/trackerFacade.js +67 -57
  148. package/facade/trackerFacade.js.map +1 -1
  149. package/facade/userFacade.cjs.map +1 -0
  150. package/facade/userFacade.d.ts +21 -4
  151. package/facade/userFacade.js +17 -18
  152. package/facade/userFacade.js.map +1 -1
  153. package/facade/userPatch.cjs.map +1 -0
  154. package/facade/userPatch.d.ts +17 -4
  155. package/facade/userPatch.js +22 -24
  156. package/facade/userPatch.js.map +1 -1
  157. package/help.cjs.map +1 -0
  158. package/help.d.ts +3 -1
  159. package/help.js +19 -23
  160. package/help.js.map +1 -1
  161. package/index.cjs.map +1 -0
  162. package/index.d.ts +25 -3
  163. package/index.js +7 -7
  164. package/index.js.map +1 -1
  165. package/logging/consoleLogger.cjs.map +1 -0
  166. package/logging/consoleLogger.d.ts +5 -2
  167. package/logging/consoleLogger.js +23 -24
  168. package/logging/consoleLogger.js.map +1 -1
  169. package/logging/filteredLogger.cjs.map +1 -0
  170. package/logging/filteredLogger.d.ts +8 -5
  171. package/logging/filteredLogger.js +36 -37
  172. package/logging/filteredLogger.js.map +1 -1
  173. package/logging/index.cjs.map +1 -0
  174. package/logging/index.d.ts +5 -5
  175. package/logging/index.js +11 -13
  176. package/logging/index.js.map +1 -1
  177. package/logging/logger.cjs.map +1 -0
  178. package/logging/logger.d.ts +4 -2
  179. package/logging/logger.js +0 -2
  180. package/logging/logger.js.map +1 -1
  181. package/logging/namespacedLogger.cjs.map +1 -0
  182. package/logging/namespacedLogger.d.ts +5 -2
  183. package/logging/namespacedLogger.js +22 -23
  184. package/logging/namespacedLogger.js.map +1 -1
  185. package/logging/nullLogger.cjs.map +1 -0
  186. package/logging/nullLogger.d.ts +5 -2
  187. package/logging/nullLogger.js +11 -16
  188. package/logging/nullLogger.js.map +1 -1
  189. package/namespacedStorage.cjs.map +1 -0
  190. package/namespacedStorage.d.ts +3 -1
  191. package/namespacedStorage.js +51 -52
  192. package/namespacedStorage.js.map +1 -1
  193. package/package.json +60 -6
  194. package/patch.cjs.map +1 -0
  195. package/patch.d.ts +6 -4
  196. package/patch.js +0 -2
  197. package/patch.js.map +1 -1
  198. package/queue/capacityRestrictedQueue.cjs.map +1 -0
  199. package/queue/capacityRestrictedQueue.d.ts +5 -2
  200. package/queue/capacityRestrictedQueue.js +31 -32
  201. package/queue/capacityRestrictedQueue.js.map +1 -1
  202. package/queue/inMemoryQueue.cjs.map +1 -0
  203. package/queue/inMemoryQueue.d.ts +5 -2
  204. package/queue/inMemoryQueue.js +32 -34
  205. package/queue/inMemoryQueue.js.map +1 -1
  206. package/queue/index.cjs.map +1 -0
  207. package/queue/index.d.ts +6 -5
  208. package/queue/index.js +11 -13
  209. package/queue/index.js.map +1 -1
  210. package/queue/monitoredQueue.cjs.map +1 -0
  211. package/queue/monitoredQueue.d.ts +8 -5
  212. package/queue/monitoredQueue.js +104 -110
  213. package/queue/monitoredQueue.js.map +1 -1
  214. package/queue/persistentQueue.cjs.map +1 -0
  215. package/queue/persistentQueue.d.ts +5 -2
  216. package/queue/persistentQueue.js +52 -54
  217. package/queue/persistentQueue.js.map +1 -1
  218. package/queue/queue.cjs.map +1 -0
  219. package/queue/queue.d.ts +3 -1
  220. package/queue/queue.js +0 -2
  221. package/queue/queue.js.map +1 -1
  222. package/retry/arbitraryPolicy.cjs.map +1 -0
  223. package/retry/arbitraryPolicy.d.ts +5 -2
  224. package/retry/arbitraryPolicy.js +14 -15
  225. package/retry/arbitraryPolicy.js.map +1 -1
  226. package/retry/backoffPolicy.cjs.map +1 -0
  227. package/retry/backoffPolicy.d.ts +5 -3
  228. package/retry/backoffPolicy.js +52 -50
  229. package/retry/backoffPolicy.js.map +1 -1
  230. package/retry/index.cjs.map +1 -0
  231. package/retry/index.d.ts +5 -5
  232. package/retry/index.js +11 -13
  233. package/retry/index.js.map +1 -1
  234. package/retry/maxAttemptsPolicy.cjs.map +1 -0
  235. package/retry/maxAttemptsPolicy.d.ts +5 -2
  236. package/retry/maxAttemptsPolicy.js +17 -18
  237. package/retry/maxAttemptsPolicy.js.map +1 -1
  238. package/retry/neverPolicy.cjs.map +1 -0
  239. package/retry/neverPolicy.d.ts +5 -2
  240. package/retry/neverPolicy.js +9 -10
  241. package/retry/neverPolicy.js.map +1 -1
  242. package/retry/policy.cjs.map +1 -0
  243. package/retry/policy.d.ts +3 -1
  244. package/retry/policy.js +0 -2
  245. package/retry/policy.js.map +1 -1
  246. package/schema/attributeSchema.cjs.map +1 -0
  247. package/schema/attributeSchema.d.ts +6 -2
  248. package/schema/attributeSchema.js +7 -7
  249. package/schema/attributeSchema.js.map +1 -1
  250. package/schema/contentFetcherSchemas.cjs.map +1 -0
  251. package/schema/contentFetcherSchemas.d.ts +6 -2
  252. package/schema/contentFetcherSchemas.js +24 -21
  253. package/schema/contentFetcherSchemas.js.map +1 -1
  254. package/schema/contentSchemas.cjs.map +1 -0
  255. package/schema/contentSchemas.d.ts +6 -2
  256. package/schema/contentSchemas.js +45 -45
  257. package/schema/contentSchemas.js.map +1 -1
  258. package/schema/contextSchemas.cjs.map +1 -0
  259. package/schema/contextSchemas.d.ts +6 -2
  260. package/schema/contextSchemas.js +6 -6
  261. package/schema/contextSchemas.js.map +1 -1
  262. package/schema/ecommerceSchemas.cjs.map +1 -0
  263. package/schema/ecommerceSchemas.d.ts +10 -6
  264. package/schema/ecommerceSchemas.js +176 -172
  265. package/schema/ecommerceSchemas.js.map +1 -1
  266. package/schema/evaluatorSchemas.cjs.map +1 -0
  267. package/schema/evaluatorSchemas.d.ts +6 -2
  268. package/schema/evaluatorSchemas.js +46 -30
  269. package/schema/evaluatorSchemas.js.map +1 -1
  270. package/schema/eventSchemas.cjs.map +1 -0
  271. package/schema/eventSchemas.d.ts +16 -12
  272. package/schema/eventSchemas.js +125 -102
  273. package/schema/eventSchemas.js.map +1 -1
  274. package/schema/index.cjs.map +1 -0
  275. package/schema/index.d.ts +14 -11
  276. package/schema/index.js +11 -14
  277. package/schema/index.js.map +1 -1
  278. package/schema/loggerSchema.cjs.map +1 -0
  279. package/schema/loggerSchema.d.ts +6 -2
  280. package/schema/loggerSchema.js +13 -13
  281. package/schema/loggerSchema.js.map +1 -1
  282. package/schema/operationSchemas.cjs.map +1 -0
  283. package/schema/operationSchemas.d.ts +14 -10
  284. package/schema/operationSchemas.js +85 -69
  285. package/schema/operationSchemas.js.map +1 -1
  286. package/schema/sdkFacadeSchemas.cjs.map +1 -0
  287. package/schema/sdkFacadeSchemas.d.ts +6 -2
  288. package/schema/sdkFacadeSchemas.js +65 -51
  289. package/schema/sdkFacadeSchemas.js.map +1 -1
  290. package/schema/sdkSchemas.cjs.map +1 -0
  291. package/schema/sdkSchemas.d.ts +8 -4
  292. package/schema/sdkSchemas.js +80 -78
  293. package/schema/sdkSchemas.js.map +1 -1
  294. package/schema/tokenSchema.cjs.map +1 -0
  295. package/schema/tokenSchema.d.ts +6 -2
  296. package/schema/tokenSchema.js +41 -38
  297. package/schema/tokenSchema.js.map +1 -1
  298. package/schema/userSchema.cjs.map +1 -0
  299. package/schema/userSchema.d.ts +6 -2
  300. package/schema/userSchema.js +183 -134
  301. package/schema/userSchema.js.map +1 -1
  302. package/sdk.cjs.map +1 -0
  303. package/sdk.d.ts +28 -14
  304. package/sdk.js +106 -108
  305. package/sdk.js.map +1 -1
  306. package/sdkEvents.cjs.map +1 -0
  307. package/sdkEvents.d.ts +10 -5
  308. package/sdkEvents.js +0 -2
  309. package/sdkEvents.js.map +1 -1
  310. package/sourceLocation.cjs.map +1 -0
  311. package/sourceLocation.d.ts +7 -5
  312. package/sourceLocation.js +56 -57
  313. package/sourceLocation.js.map +1 -1
  314. package/tab.cjs.map +1 -0
  315. package/tab.d.ts +9 -7
  316. package/tab.js +93 -90
  317. package/tab.js.map +1 -1
  318. package/token/cachedTokenStore.cjs.map +1 -0
  319. package/token/cachedTokenStore.d.ts +8 -3
  320. package/token/cachedTokenStore.js +22 -24
  321. package/token/cachedTokenStore.js.map +1 -1
  322. package/token/inMemoryTokenStore.cjs.map +1 -0
  323. package/token/inMemoryTokenStore.d.ts +7 -2
  324. package/token/inMemoryTokenStore.js +12 -13
  325. package/token/inMemoryTokenStore.js.map +1 -1
  326. package/token/index.cjs.map +1 -0
  327. package/token/index.d.ts +7 -4
  328. package/token/index.js +9 -11
  329. package/token/index.js.map +1 -1
  330. package/token/replicatedTokenStore.cjs.map +1 -0
  331. package/token/replicatedTokenStore.d.ts +7 -2
  332. package/token/replicatedTokenStore.js +14 -15
  333. package/token/replicatedTokenStore.js.map +1 -1
  334. package/token/token.cjs.map +1 -0
  335. package/token/token.d.ts +11 -8
  336. package/token/token.js +212 -195
  337. package/token/token.js.map +1 -1
  338. package/tracker.cjs.map +1 -0
  339. package/tracker.d.ts +20 -13
  340. package/tracker.js +307 -307
  341. package/tracker.js.map +1 -1
  342. package/trackingEvents.cjs.map +1 -0
  343. package/trackingEvents.d.ts +65 -62
  344. package/trackingEvents.js +57 -56
  345. package/trackingEvents.js.map +1 -1
  346. package/transformer.cjs.map +1 -0
  347. package/transformer.d.ts +4 -2
  348. package/transformer.js +5 -6
  349. package/transformer.js.map +1 -1
  350. package/utilityTypes.cjs.map +1 -0
  351. package/utilityTypes.d.ts +4 -2
  352. package/utilityTypes.js +0 -2
  353. package/utilityTypes.js.map +1 -1
  354. package/uuid.cjs.map +1 -0
  355. package/uuid.d.ts +3 -1
  356. package/uuid.js +27 -32
  357. package/uuid.js.map +1 -1
  358. package/validation/arrayType.cjs.map +1 -0
  359. package/validation/arrayType.d.ts +5 -3
  360. package/validation/arrayType.js +45 -41
  361. package/validation/arrayType.js.map +1 -1
  362. package/validation/booleanType.cjs.map +1 -0
  363. package/validation/booleanType.d.ts +5 -2
  364. package/validation/booleanType.js +19 -16
  365. package/validation/booleanType.js.map +1 -1
  366. package/validation/functionType.cjs.map +1 -0
  367. package/validation/functionType.d.ts +5 -2
  368. package/validation/functionType.js +19 -16
  369. package/validation/functionType.js.map +1 -1
  370. package/validation/index.cjs.map +1 -0
  371. package/validation/index.d.ts +12 -12
  372. package/validation/index.js +27 -29
  373. package/validation/index.js.map +1 -1
  374. package/validation/jsonType.cjs.map +1 -0
  375. package/validation/jsonType.d.ts +8 -6
  376. package/validation/jsonType.js +89 -82
  377. package/validation/jsonType.js.map +1 -1
  378. package/validation/mixedSchema.cjs.map +1 -0
  379. package/validation/mixedSchema.d.ts +5 -2
  380. package/validation/mixedSchema.js +5 -7
  381. package/validation/mixedSchema.js.map +1 -1
  382. package/validation/nullType.cjs.map +1 -0
  383. package/validation/nullType.d.ts +5 -2
  384. package/validation/nullType.js +19 -16
  385. package/validation/nullType.js.map +1 -1
  386. package/validation/numberType.cjs.map +1 -0
  387. package/validation/numberType.d.ts +5 -3
  388. package/validation/numberType.js +40 -32
  389. package/validation/numberType.js.map +1 -1
  390. package/validation/objectType.cjs.map +1 -0
  391. package/validation/objectType.d.ts +5 -3
  392. package/validation/objectType.js +84 -85
  393. package/validation/objectType.js.map +1 -1
  394. package/validation/schema.cjs.map +1 -0
  395. package/validation/schema.d.ts +5 -3
  396. package/validation/schema.js +8 -9
  397. package/validation/schema.js.map +1 -1
  398. package/validation/stringType.cjs.map +1 -0
  399. package/validation/stringType.d.ts +5 -3
  400. package/validation/stringType.js +74 -70
  401. package/validation/stringType.js.map +1 -1
  402. package/validation/unionType.cjs.map +1 -0
  403. package/validation/unionType.d.ts +5 -2
  404. package/validation/unionType.js +37 -35
  405. package/validation/unionType.js.map +1 -1
  406. package/validation/violation.cjs.map +1 -0
  407. package/validation/violation.d.ts +4 -2
  408. package/validation/violation.js +18 -18
  409. package/validation/violation.js.map +1 -1
@@ -1,109 +1,116 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsonType = exports.JsonPrimitiveType = exports.JsonArrayType = exports.JsonObjectType = void 0;
4
- const schema_1 = require("./schema");
5
- const violation_1 = require("./violation");
1
+ import { Violation } from "./schema";
2
+ import { describe, formatPath } from "./violation";
6
3
  function isJsonPrimitive(value) {
7
- return value === null || typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number';
4
+ return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number";
8
5
  }
9
6
  function isPlainObject(value) {
10
- return Object.prototype
11
- .toString
12
- .call(value) === '[object Object]';
7
+ return Object.prototype.toString.call(value) === "[object Object]";
13
8
  }
14
9
  function isJsonArray(value) {
15
- return Array.isArray(value) && value.every(isJsonValue);
10
+ return Array.isArray(value) && value.every(isJsonValue);
16
11
  }
17
12
  function isJsonObject(value) {
18
- return isPlainObject(value) && Object.values(value).every(isJsonValue);
13
+ return isPlainObject(value) && Object.values(value).every(isJsonValue);
19
14
  }
20
15
  function isJsonValue(value) {
21
- return isJsonPrimitive(value) || isJsonArray(value) || isJsonObject(value);
16
+ return isJsonPrimitive(value) || isJsonArray(value) || isJsonObject(value);
22
17
  }
23
18
  class JsonObjectType {
24
- constructor(definition = {}) {
25
- this.definition = definition;
19
+ constructor(definition = {}) {
20
+ this.definition = definition;
21
+ }
22
+ getTypes() {
23
+ return ["object"];
24
+ }
25
+ isValidType(value) {
26
+ return isPlainObject(value);
27
+ }
28
+ validate(value, path = []) {
29
+ if (!isJsonObject(value)) {
30
+ throw new Violation(
31
+ `Expected a JSON object at path '${formatPath(path)}', actual ${describe(value)}.`,
32
+ path,
33
+ { type: "object" }
34
+ );
26
35
  }
27
- getTypes() {
28
- return ['object'];
36
+ if (this.definition.properties === void 0 && this.definition.propertyNames === void 0) {
37
+ return;
29
38
  }
30
- isValidType(value) {
31
- return isPlainObject(value);
32
- }
33
- validate(value, path = []) {
34
- if (!isJsonObject(value)) {
35
- throw new schema_1.Violation(`Expected a JSON object at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'object' });
36
- }
37
- if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
38
- return;
39
- }
40
- for (const [entryName, entryValue] of Object.entries(value)) {
41
- const propertyPath = path.concat([entryName]);
42
- if (this.definition.propertyNames !== undefined) {
43
- this.definition
44
- .propertyNames
45
- .validate(entryName, propertyPath);
46
- }
47
- if (this.definition.properties !== undefined) {
48
- this.definition
49
- .properties
50
- .validate(entryValue, path.concat([entryName]));
51
- }
52
- }
39
+ for (const [entryName, entryValue] of Object.entries(value)) {
40
+ const propertyPath = path.concat([entryName]);
41
+ if (this.definition.propertyNames !== void 0) {
42
+ this.definition.propertyNames.validate(entryName, propertyPath);
43
+ }
44
+ if (this.definition.properties !== void 0) {
45
+ this.definition.properties.validate(entryValue, path.concat([entryName]));
46
+ }
53
47
  }
48
+ }
54
49
  }
55
- exports.JsonObjectType = JsonObjectType;
56
50
  class JsonArrayType {
57
- constructor(definition = {}) {
58
- this.definition = definition;
59
- }
60
- getTypes() {
61
- return ['array'];
51
+ constructor(definition = {}) {
52
+ this.definition = definition;
53
+ }
54
+ getTypes() {
55
+ return ["array"];
56
+ }
57
+ isValidType(value) {
58
+ return Array.isArray(value);
59
+ }
60
+ validate(value, path = []) {
61
+ if (!isJsonArray(value)) {
62
+ throw new Violation(
63
+ `Expected a JSON array at path '${formatPath(path)}', actual ${describe(value)}.`,
64
+ path,
65
+ { type: "array" }
66
+ );
62
67
  }
63
- isValidType(value) {
64
- return Array.isArray(value);
68
+ if (this.definition.items === void 0) {
69
+ return;
65
70
  }
66
- validate(value, path = []) {
67
- if (!isJsonArray(value)) {
68
- throw new schema_1.Violation(`Expected a JSON array at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'array' });
69
- }
70
- if (this.definition.items === undefined) {
71
- return;
72
- }
73
- for (let index = 0; index < value.length; index++) {
74
- this.definition
75
- .items
76
- .validate(value[index], path.concat([index.toString()]));
77
- }
71
+ for (let index = 0; index < value.length; index++) {
72
+ this.definition.items.validate(value[index], path.concat([index.toString()]));
78
73
  }
74
+ }
79
75
  }
80
- exports.JsonArrayType = JsonArrayType;
81
76
  class JsonPrimitiveType {
82
- getTypes() {
83
- return ['null', 'number', 'string', 'boolean'];
84
- }
85
- isValidType(value) {
86
- return isJsonPrimitive(value);
87
- }
88
- validate(value, path = []) {
89
- if (!this.isValidType(value)) {
90
- throw new schema_1.Violation(`Expected a JSON primitive at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: this.getTypes().join('|') });
91
- }
77
+ getTypes() {
78
+ return ["null", "number", "string", "boolean"];
79
+ }
80
+ isValidType(value) {
81
+ return isJsonPrimitive(value);
82
+ }
83
+ validate(value, path = []) {
84
+ if (!this.isValidType(value)) {
85
+ throw new Violation(
86
+ `Expected a JSON primitive at path '${formatPath(path)}', actual ${describe(value)}.`,
87
+ path,
88
+ { type: this.getTypes().join("|") }
89
+ );
92
90
  }
91
+ }
93
92
  }
94
- exports.JsonPrimitiveType = JsonPrimitiveType;
95
93
  class JsonType {
96
- getTypes() {
97
- return ['null', 'number', 'string', 'boolean', 'array', 'object'];
98
- }
99
- isValidType(value) {
100
- return isJsonPrimitive(value) || Array.isArray(value) || isPlainObject(value);
101
- }
102
- validate(value, path = []) {
103
- if (!isJsonValue(value)) {
104
- throw new schema_1.Violation(`Expected a JSON value at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: this.getTypes().join('|') });
105
- }
94
+ getTypes() {
95
+ return ["null", "number", "string", "boolean", "array", "object"];
96
+ }
97
+ isValidType(value) {
98
+ return isJsonPrimitive(value) || Array.isArray(value) || isPlainObject(value);
99
+ }
100
+ validate(value, path = []) {
101
+ if (!isJsonValue(value)) {
102
+ throw new Violation(
103
+ `Expected a JSON value at path '${formatPath(path)}', actual ${describe(value)}.`,
104
+ path,
105
+ { type: this.getTypes().join("|") }
106
+ );
106
107
  }
108
+ }
107
109
  }
108
- exports.JsonType = JsonType;
110
+ export {
111
+ JsonArrayType,
112
+ JsonObjectType,
113
+ JsonPrimitiveType,
114
+ JsonType
115
+ };
109
116
  //# sourceMappingURL=jsonType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsonType.js","sourceRoot":"","sources":["../src/validation/jsonType.ts"],"names":[],"mappings":";;;AACA,qCAAuD;AACvD,2CAAiD;AAEjD,SAAS,eAAe,CAAC,KAAc;IACnC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AAClH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACjC,OAAO,MAAM,CAAC,SAAS;SAClB,QAAQ;SACR,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC;AAC3C,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAChC,OAAO,aAAa,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAC/B,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;AAC/E,CAAC;AAOD,MAAa,cAAc;IAGvB,YAAmB,aAAmC,EAAE;QACpD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,QAAQ;QACX,OAAO,CAAC,QAAQ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AAC,KAAK,CAAC,GAAG,EACrF,IAAI,EACJ,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAC,CACpC,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AAlBD,8CAkBC;AAED,MAAa,QAAQ;IACV,QAAQ;QACX,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtE,CAAC;IAEM,WAAW,CAAC,KAAc;QAC7B,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;IAClF,CAAC;IAEM,QAAQ,CAAC,KAAc,EAAE,OAAiB,EAAE;QAC/C,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,kBAAS,CACf,kCAAkC,IAAA,sBAAU,EAAC,IAAI,CAAC,aAAa,IAAA,oBAAQ,EAAC,KAAK,CAAC,GAAG,EACjF,IAAI,EACJ,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAC,CACpC,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AAlBD,4BAkBC"}
1
+ {"version":3,"sources":["../src/validation/jsonType.ts"],"sourcesContent":["import {JsonArray, JsonObject, JsonPrimitive, JsonValue} from '@croct/json';\nimport {Schema, TypeSchema, Violation} from './schema';\nimport {describe, formatPath} from './violation';\n\nfunction isJsonPrimitive(value: unknown): value is JsonPrimitive {\n return value === null || typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number';\n}\n\nfunction isPlainObject(value: unknown): value is object {\n return Object.prototype\n .toString\n .call(value) === '[object Object]';\n}\n\nfunction isJsonArray(value: unknown): value is JsonArray {\n return Array.isArray(value) && value.every(isJsonValue);\n}\n\nfunction isJsonObject(value: unknown): value is JsonObject {\n return isPlainObject(value) && Object.values(value).every(isJsonValue);\n}\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n return isJsonPrimitive(value) || isJsonArray(value) || isJsonObject(value);\n}\n\ntype JsonObjectDefinition = {\n properties?: Schema,\n propertyNames?: Schema,\n};\n\nexport class JsonObjectType implements TypeSchema {\n private readonly definition: JsonObjectDefinition;\n\n public constructor(definition: JsonObjectDefinition = {}) {\n this.definition = definition;\n }\n\n public getTypes(): string[] {\n return ['object'];\n }\n\n public isValidType(value: unknown): boolean {\n return isPlainObject(value);\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!isJsonObject(value)) {\n throw new Violation(\n `Expected a JSON object at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: 'object'},\n );\n }\n\n if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {\n return;\n }\n\n for (const [entryName, entryValue] of Object.entries(value)) {\n const propertyPath = path.concat([entryName]);\n\n if (this.definition.propertyNames !== undefined) {\n this.definition\n .propertyNames\n .validate(entryName, propertyPath);\n }\n\n if (this.definition.properties !== undefined) {\n this.definition\n .properties\n .validate(entryValue, path.concat([entryName]));\n }\n }\n }\n}\n\ntype JsonArrayDefinition = {\n items?: Schema,\n};\n\nexport class JsonArrayType implements TypeSchema {\n private readonly definition: JsonArrayDefinition;\n\n public constructor(definition: JsonArrayDefinition = {}) {\n this.definition = definition;\n }\n\n public getTypes(): string[] {\n return ['array'];\n }\n\n public isValidType(value: unknown): boolean {\n return Array.isArray(value);\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!isJsonArray(value)) {\n throw new Violation(\n `Expected a JSON array at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: 'array'},\n );\n }\n\n if (this.definition.items === undefined) {\n return;\n }\n\n for (let index = 0; index < value.length; index++) {\n this.definition\n .items\n .validate(value[index], path.concat([index.toString()]));\n }\n }\n}\n\nexport class JsonPrimitiveType implements TypeSchema {\n public getTypes(): string[] {\n return ['null', 'number', 'string', 'boolean'];\n }\n\n public isValidType(value: unknown): boolean {\n return isJsonPrimitive(value);\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!this.isValidType(value)) {\n throw new Violation(\n `Expected a JSON primitive at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: this.getTypes().join('|')},\n );\n }\n }\n}\n\nexport class JsonType implements TypeSchema {\n public getTypes(): string[] {\n return ['null', 'number', 'string', 'boolean', 'array', 'object'];\n }\n\n public isValidType(value: unknown): boolean {\n return isJsonPrimitive(value) || Array.isArray(value) || isPlainObject(value);\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!isJsonValue(value)) {\n throw new Violation(\n `Expected a JSON value at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: this.getTypes().join('|')},\n );\n }\n }\n}\n"],"mappings":"AACA,SAA4B,iBAAgB;AAC5C,SAAQ,UAAU,kBAAiB;AAEnC,SAAS,gBAAgB,OAAwC;AAC7D,SAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa,OAAO,UAAU;AACzG;AAEA,SAAS,cAAc,OAAiC;AACpD,SAAO,OAAO,UACT,SACA,KAAK,KAAK,MAAM;AACzB;AAEA,SAAS,YAAY,OAAoC;AACrD,SAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM,WAAW;AAC1D;AAEA,SAAS,aAAa,OAAqC;AACvD,SAAO,cAAc,KAAK,KAAK,OAAO,OAAO,KAAK,EAAE,MAAM,WAAW;AACzE;AAEA,SAAS,YAAY,OAAoC;AACrD,SAAO,gBAAgB,KAAK,KAAK,YAAY,KAAK,KAAK,aAAa,KAAK;AAC7E;AAOO,MAAM,eAAqC;AAAA,EAGvC,YAAY,aAAmC,CAAC,GAAG;AACtD,SAAK,aAAa;AAAA,EACtB;AAAA,EAEO,WAAqB;AACxB,WAAO,CAAC,QAAQ;AAAA,EACpB;AAAA,EAEO,YAAY,OAAyB;AACxC,WAAO,cAAc,KAAK;AAAA,EAC9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AS,MAAM,KAAK,GAAG,KAAK,OAAO,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,IAC/D;AAAA,EACJ;AACJ;AAEO,MAAM,kBAAwC;AAAA,EAC1C,WAAqB;AACxB,WAAO,CAAC,QAAQ,UAAU,UAAU,SAAS;AAAA,EACjD;AAAA,EAEO,YAAY,OAAyB;AACxC,WAAO,gBAAgB,KAAK;AAAA,EAChC;AAAA,EAEO,SAAS,OAAgB,OAAiB,CAAC,GAAS;AACvD,QAAI,CAAC,KAAK,YAAY,KAAK,GAAG;AAC1B,YAAM,IAAI;AAAA,QACN,sCAAsC,WAAW,IAAI,CAAC,aAAa,SAAS,KAAK,CAAC;AAAA,QAClF;AAAA,QACA,EAAC,MAAM,KAAK,SAAS,EAAE,KAAK,GAAG,EAAC;AAAA,MACpC;AAAA,IACJ;AAAA,EACJ;AACJ;AAEO,MAAM,SAA+B;AAAA,EACjC,WAAqB;AACxB,WAAO,CAAC,QAAQ,UAAU,UAAU,WAAW,SAAS,QAAQ;AAAA,EACpE;AAAA,EAEO,YAAY,OAAyB;AACxC,WAAO,gBAAgB,KAAK,KAAK,MAAM,QAAQ,KAAK,KAAK,cAAc,KAAK;AAAA,EAChF;AAAA,EAEO,SAAS,OAAgB,OAAiB,CAAC,GAAS;AACvD,QAAI,CAAC,YAAY,KAAK,GAAG;AACrB,YAAM,IAAI;AAAA,QACN,kCAAkC,WAAW,IAAI,CAAC,aAAa,SAAS,KAAK,CAAC;AAAA,QAC9E;AAAA,QACA,EAAC,MAAM,KAAK,SAAS,EAAE,KAAK,GAAG,EAAC;AAAA,MACpC;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validation/mixedSchema.ts"],"sourcesContent":["import {Schema} from './schema';\n\nexport class MixedSchema implements Schema {\n public validate(): void {\n // always valid\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,YAA8B;AAAA,EAChC,WAAiB;AAAA,EAExB;AACJ;","names":[]}
@@ -1,4 +1,7 @@
1
- import { Schema } from './schema';
2
- export declare class MixedSchema implements Schema {
1
+ import { Schema } from './schema.js';
2
+
3
+ declare class MixedSchema implements Schema {
3
4
  validate(): void;
4
5
  }
6
+
7
+ export { MixedSchema };
@@ -1,10 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MixedSchema = void 0;
4
1
  class MixedSchema {
5
- validate() {
6
- // always valid
7
- }
2
+ validate() {
3
+ }
8
4
  }
9
- exports.MixedSchema = MixedSchema;
5
+ export {
6
+ MixedSchema
7
+ };
10
8
  //# sourceMappingURL=mixedSchema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mixedSchema.js","sourceRoot":"","sources":["../src/validation/mixedSchema.ts"],"names":[],"mappings":";;;AAEA,MAAa,WAAW;IACb,QAAQ;QACX,eAAe;IACnB,CAAC;CACJ;AAJD,kCAIC"}
1
+ {"version":3,"sources":["../src/validation/mixedSchema.ts"],"sourcesContent":["import {Schema} from './schema';\n\nexport class MixedSchema implements Schema {\n public validate(): void {\n // always valid\n }\n}\n"],"mappings":"AAEO,MAAM,YAA8B;AAAA,EAChC,WAAiB;AAAA,EAExB;AACJ;","names":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validation/nullType.ts"],"sourcesContent":["import {TypeSchema, Violation} from './schema';\nimport {describe, formatPath} from './violation';\n\nexport class NullType implements TypeSchema {\n public getTypes(): string[] {\n return ['null'];\n }\n\n public isValidType(value: unknown): value is null {\n return value === null;\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!this.isValidType(value)) {\n throw new Violation(\n `Expected value of type null at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: 'null'},\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AACpC,uBAAmC;AAE5B,MAAM,SAA+B;AAAA,EACjC,WAAqB;AACxB,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,EAEO,YAAY,OAA+B;AAC9C,WAAO,UAAU;AAAA,EACrB;AAAA,EAEO,SAAS,OAAgB,OAAiB,CAAC,GAAS;AACvD,QAAI,CAAC,KAAK,YAAY,KAAK,GAAG;AAC1B,YAAM,IAAI;AAAA,QACN,4CAAwC,6BAAW,IAAI,CAAC,iBAAa,2BAAS,KAAK,CAAC;AAAA,QACpF;AAAA,QACA,EAAC,MAAM,OAAM;AAAA,MACjB;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
@@ -1,6 +1,9 @@
1
- import { TypeSchema } from './schema';
2
- export declare class NullType implements TypeSchema {
1
+ import { TypeSchema } from './schema.js';
2
+
3
+ declare class NullType implements TypeSchema {
3
4
  getTypes(): string[];
4
5
  isValidType(value: unknown): value is null;
5
6
  validate(value: unknown, path?: string[]): void;
6
7
  }
8
+
9
+ export { NullType };
@@ -1,20 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NullType = void 0;
4
- const schema_1 = require("./schema");
5
- const violation_1 = require("./violation");
1
+ import { Violation } from "./schema";
2
+ import { describe, formatPath } from "./violation";
6
3
  class NullType {
7
- getTypes() {
8
- return ['null'];
9
- }
10
- isValidType(value) {
11
- return value === null;
12
- }
13
- validate(value, path = []) {
14
- if (!this.isValidType(value)) {
15
- throw new schema_1.Violation(`Expected value of type null at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: 'null' });
16
- }
4
+ getTypes() {
5
+ return ["null"];
6
+ }
7
+ isValidType(value) {
8
+ return value === null;
9
+ }
10
+ validate(value, path = []) {
11
+ if (!this.isValidType(value)) {
12
+ throw new Violation(
13
+ `Expected value of type null at path '${formatPath(path)}', actual ${describe(value)}.`,
14
+ path,
15
+ { type: "null" }
16
+ );
17
17
  }
18
+ }
18
19
  }
19
- exports.NullType = NullType;
20
+ export {
21
+ NullType
22
+ };
20
23
  //# sourceMappingURL=nullType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nullType.js","sourceRoot":"","sources":["../src/validation/nullType.ts"],"names":[],"mappings":";;;AAAA,qCAA+C;AAC/C,2CAAiD;AAEjD,MAAa,QAAQ;IACV,QAAQ;QACX,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAEM,WAAW,CAAC,KAAc;QAC7B,OAAO,KAAK,KAAK,IAAI,CAAC;IAC1B,CAAC;IAEM,QAAQ,CAAC,KAAc,EAAE,OAAiB,EAAE;QAC/C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,kBAAS,CACf,wCAAwC,IAAA,sBAAU,EAAC,IAAI,CAAC,aAAa,IAAA,oBAAQ,EAAC,KAAK,CAAC,GAAG,EACvF,IAAI,EACJ,EAAC,IAAI,EAAE,MAAM,EAAC,CACjB,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AAlBD,4BAkBC"}
1
+ {"version":3,"sources":["../src/validation/nullType.ts"],"sourcesContent":["import {TypeSchema, Violation} from './schema';\nimport {describe, formatPath} from './violation';\n\nexport class NullType implements TypeSchema {\n public getTypes(): string[] {\n return ['null'];\n }\n\n public isValidType(value: unknown): value is null {\n return value === null;\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!this.isValidType(value)) {\n throw new Violation(\n `Expected value of type null at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: 'null'},\n );\n }\n }\n}\n"],"mappings":"AAAA,SAAoB,iBAAgB;AACpC,SAAQ,UAAU,kBAAiB;AAE5B,MAAM,SAA+B;AAAA,EACjC,WAAqB;AACxB,WAAO,CAAC,MAAM;AAAA,EAClB;AAAA,EAEO,YAAY,OAA+B;AAC9C,WAAO,UAAU;AAAA,EACrB;AAAA,EAEO,SAAS,OAAgB,OAAiB,CAAC,GAAS;AACvD,QAAI,CAAC,KAAK,YAAY,KAAK,GAAG;AAC1B,YAAM,IAAI;AAAA,QACN,wCAAwC,WAAW,IAAI,CAAC,aAAa,SAAS,KAAK,CAAC;AAAA,QACpF;AAAA,QACA,EAAC,MAAM,OAAM;AAAA,MACjB;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validation/numberType.ts"],"sourcesContent":["import {TypeSchema, Violation} from './schema';\nimport {describe, formatPath} from './violation';\n\ntype NumberDefinition = {\n integer: boolean,\n minimum: number,\n maximum: number,\n};\n\nexport class NumberType implements TypeSchema {\n private readonly definition: NumberDefinition;\n\n public constructor(definition: Partial<NumberDefinition> = {}) {\n this.definition = {\n ...definition,\n integer: definition.integer ?? false,\n minimum: definition.minimum ?? Number.NEGATIVE_INFINITY,\n maximum: definition.maximum ?? Number.POSITIVE_INFINITY,\n };\n }\n\n public getTypes(): string[] {\n return [this.definition.integer ? 'integer' : 'number'];\n }\n\n public isValidType(value: unknown): value is number {\n return typeof value === 'number' && (!this.definition.integer || Number.isInteger(value));\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!this.isValidType(value)) {\n const type = this.getTypes()[0];\n\n throw new Violation(\n `Expected value of type ${type} at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: type},\n );\n }\n\n if (value < this.definition.minimum) {\n throw new Violation(\n `Expected a value greater than or equal to ${this.definition.minimum} `\n + `at path '${formatPath(path)}', actual ${value}.`,\n path,\n {limit: this.definition.minimum},\n );\n }\n\n if (value > this.definition.maximum) {\n throw new Violation(\n `Expected a value less than or equal to ${this.definition.maximum} `\n + `at path '${formatPath(path)}', actual ${value}.`,\n path,\n {limit: this.definition.maximum},\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AACpC,uBAAmC;AAQ5B,MAAM,WAAiC;AAAA,EAGnC,YAAY,aAAwC,CAAC,GAAG;AAC3D,SAAK,aAAa;AAAA,MACd,GAAG;AAAA,MACH,SAAS,WAAW,WAAW;AAAA,MAC/B,SAAS,WAAW,WAAW,OAAO;AAAA,MACtC,SAAS,WAAW,WAAW,OAAO;AAAA,IAC1C;AAAA,EACJ;AAAA,EAEO,WAAqB;AACxB,WAAO,CAAC,KAAK,WAAW,UAAU,YAAY,QAAQ;AAAA,EAC1D;AAAA,EAEO,YAAY,OAAiC;AAChD,WAAO,OAAO,UAAU,aAAa,CAAC,KAAK,WAAW,WAAW,OAAO,UAAU,KAAK;AAAA,EAC3F;AAAA,EAEO,SAAS,OAAgB,OAAiB,CAAC,GAAS;AACvD,QAAI,CAAC,KAAK,YAAY,KAAK,GAAG;AAC1B,YAAM,OAAO,KAAK,SAAS,EAAE,CAAC;AAE9B,YAAM,IAAI;AAAA,QACN,0BAA0B,IAAI,iBAAa,6BAAW,IAAI,CAAC,iBAAa,2BAAS,KAAK,CAAC;AAAA,QACvF;AAAA,QACA,EAAC,KAAU;AAAA,MACf;AAAA,IACJ;AAEA,QAAI,QAAQ,KAAK,WAAW,SAAS;AACjC,YAAM,IAAI;AAAA,QACN,6CAA6C,KAAK,WAAW,OAAO,iBACtD,6BAAW,IAAI,CAAC,aAAa,KAAK;AAAA,QAChD;AAAA,QACA,EAAC,OAAO,KAAK,WAAW,QAAO;AAAA,MACnC;AAAA,IACJ;AAEA,QAAI,QAAQ,KAAK,WAAW,SAAS;AACjC,YAAM,IAAI;AAAA,QACN,0CAA0C,KAAK,WAAW,OAAO,iBACnD,6BAAW,IAAI,CAAC,aAAa,KAAK;AAAA,QAChD;AAAA,QACA,EAAC,OAAO,KAAK,WAAW,QAAO;AAAA,MACnC;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
@@ -1,14 +1,16 @@
1
- import { TypeSchema } from './schema';
1
+ import { TypeSchema } from './schema.js';
2
+
2
3
  type NumberDefinition = {
3
4
  integer: boolean;
4
5
  minimum: number;
5
6
  maximum: number;
6
7
  };
7
- export declare class NumberType implements TypeSchema {
8
+ declare class NumberType implements TypeSchema {
8
9
  private readonly definition;
9
10
  constructor(definition?: Partial<NumberDefinition>);
10
11
  getTypes(): string[];
11
12
  isValidType(value: unknown): value is number;
12
13
  validate(value: unknown, path?: string[]): void;
13
14
  }
14
- export {};
15
+
16
+ export { NumberType };
@@ -1,38 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NumberType = void 0;
4
- const schema_1 = require("./schema");
5
- const violation_1 = require("./violation");
1
+ import { Violation } from "./schema";
2
+ import { describe, formatPath } from "./violation";
6
3
  class NumberType {
7
- constructor(definition = {}) {
8
- var _a, _b, _c;
9
- this.definition = {
10
- ...definition,
11
- integer: (_a = definition.integer) !== null && _a !== void 0 ? _a : false,
12
- minimum: (_b = definition.minimum) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY,
13
- maximum: (_c = definition.maximum) !== null && _c !== void 0 ? _c : Number.POSITIVE_INFINITY,
14
- };
4
+ constructor(definition = {}) {
5
+ this.definition = {
6
+ ...definition,
7
+ integer: definition.integer ?? false,
8
+ minimum: definition.minimum ?? Number.NEGATIVE_INFINITY,
9
+ maximum: definition.maximum ?? Number.POSITIVE_INFINITY
10
+ };
11
+ }
12
+ getTypes() {
13
+ return [this.definition.integer ? "integer" : "number"];
14
+ }
15
+ isValidType(value) {
16
+ return typeof value === "number" && (!this.definition.integer || Number.isInteger(value));
17
+ }
18
+ validate(value, path = []) {
19
+ if (!this.isValidType(value)) {
20
+ const type = this.getTypes()[0];
21
+ throw new Violation(
22
+ `Expected value of type ${type} at path '${formatPath(path)}', actual ${describe(value)}.`,
23
+ path,
24
+ { type }
25
+ );
15
26
  }
16
- getTypes() {
17
- return [this.definition.integer ? 'integer' : 'number'];
27
+ if (value < this.definition.minimum) {
28
+ throw new Violation(
29
+ `Expected a value greater than or equal to ${this.definition.minimum} at path '${formatPath(path)}', actual ${value}.`,
30
+ path,
31
+ { limit: this.definition.minimum }
32
+ );
18
33
  }
19
- isValidType(value) {
20
- return typeof value === 'number' && (!this.definition.integer || Number.isInteger(value));
21
- }
22
- validate(value, path = []) {
23
- if (!this.isValidType(value)) {
24
- const type = this.getTypes()[0];
25
- throw new schema_1.Violation(`Expected value of type ${type} at path '${(0, violation_1.formatPath)(path)}', actual ${(0, violation_1.describe)(value)}.`, path, { type: type });
26
- }
27
- if (value < this.definition.minimum) {
28
- throw new schema_1.Violation(`Expected a value greater than or equal to ${this.definition.minimum} `
29
- + `at path '${(0, violation_1.formatPath)(path)}', actual ${value}.`, path, { limit: this.definition.minimum });
30
- }
31
- if (value > this.definition.maximum) {
32
- throw new schema_1.Violation(`Expected a value less than or equal to ${this.definition.maximum} `
33
- + `at path '${(0, violation_1.formatPath)(path)}', actual ${value}.`, path, { limit: this.definition.maximum });
34
- }
34
+ if (value > this.definition.maximum) {
35
+ throw new Violation(
36
+ `Expected a value less than or equal to ${this.definition.maximum} at path '${formatPath(path)}', actual ${value}.`,
37
+ path,
38
+ { limit: this.definition.maximum }
39
+ );
35
40
  }
41
+ }
36
42
  }
37
- exports.NumberType = NumberType;
43
+ export {
44
+ NumberType
45
+ };
38
46
  //# sourceMappingURL=numberType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"numberType.js","sourceRoot":"","sources":["../src/validation/numberType.ts"],"names":[],"mappings":";;;AAAA,qCAA+C;AAC/C,2CAAiD;AAQjD,MAAa,UAAU;IAGnB,YAAmB,aAAwC,EAAE;;QACzD,IAAI,CAAC,UAAU,GAAG;YACd,GAAG,UAAU;YACb,OAAO,EAAE,MAAA,UAAU,CAAC,OAAO,mCAAI,KAAK;YACpC,OAAO,EAAE,MAAA,UAAU,CAAC,OAAO,mCAAI,MAAM,CAAC,iBAAiB;YACvD,OAAO,EAAE,MAAA,UAAU,CAAC,OAAO,mCAAI,MAAM,CAAC,iBAAiB;SAC1D,CAAC;IACN,CAAC;IAEM,QAAQ;QACX,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,C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AC;CACJ;AAjDD,gCAiDC"}
1
+ {"version":3,"sources":["../src/validation/numberType.ts"],"sourcesContent":["import {TypeSchema, Violation} from './schema';\nimport {describe, formatPath} from './violation';\n\ntype NumberDefinition = {\n integer: boolean,\n minimum: number,\n maximum: number,\n};\n\nexport class NumberType implements TypeSchema {\n private readonly definition: NumberDefinition;\n\n public constructor(definition: Partial<NumberDefinition> = {}) {\n this.definition = {\n ...definition,\n integer: definition.integer ?? false,\n minimum: definition.minimum ?? Number.NEGATIVE_INFINITY,\n maximum: definition.maximum ?? Number.POSITIVE_INFINITY,\n };\n }\n\n public getTypes(): string[] {\n return [this.definition.integer ? 'integer' : 'number'];\n }\n\n public isValidType(value: unknown): value is number {\n return typeof value === 'number' && (!this.definition.integer || Number.isInteger(value));\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!this.isValidType(value)) {\n const type = this.getTypes()[0];\n\n throw new Violation(\n `Expected value of type ${type} at path '${formatPath(path)}', actual ${describe(value)}.`,\n path,\n {type: type},\n );\n }\n\n if (value < this.definition.minimum) {\n throw new Violation(\n `Expected a value greater than or equal to ${this.definition.minimum} `\n + `at path '${formatPath(path)}', actual ${value}.`,\n path,\n {limit: this.definition.minimum},\n );\n }\n\n if (value > this.definition.maximum) {\n throw new Violation(\n `Expected a value less than or equal to ${this.definition.maximum} `\n + `at path '${formatPath(path)}', actual ${value}.`,\n path,\n {limit: this.definition.maximum},\n );\n }\n }\n}\n"],"mappings":"AAAA,SAAoB,iBAAgB;AACpC,SAAQ,UAAU,kBAAiB;AAQ5B,MAAM,WAAiC;AAAA,EAGnC,YAAY,aAAwC,CAAC,GAAG;AAC3D,SAAK,aAAa;AAAA,MACd,GAAG;AAAA,MACH,SAAS,WAAW,WAAW;AAAA,MAC/B,SAAS,WAAW,WAAW,OAAO;AAAA,MACtC,SAAS,WAAW,WAAW,OAAO;AAAA,IAC1C;AAAA,EACJ;AAAA,EAEO,WAAqB;AACxB,WAAO,CAAC,KAAK,WAAW,UAAU,YAAY,QAAQ;AAAA,EAC1D;AAAA,EAEO,YAAY,OAAiC;AAChD,WAAO,OAAO,UAAU,aAAa,CAAC,KAAK,WAAW,WAAW,OAAO,UAAU,KAAK;AAAA,EAC3F;AAAA,EAEO,SAAS,OAAgB,OAAiB,CAAC,GAAS;AACvD,QAAI,CAAC,KAAK,YAAY,KAAK,GAAG;AAC1B,YAAM,OAAO,KAAK,SAAS,EAAE,CAAC;AAE9B,YAAM,IAAI;AAAA,QACN,0BAA0B,IAAI,aAAa,WAAW,IAAI,CAAC,aAAa,SAAS,KAAK,CAAC;AAAA,QACvF;AAAA,QACA,EAAC,KAAU;AAAA,MACf;AAAA,IACJ;AAEA,QAAI,QAAQ,KAAK,WAAW,SAAS;AACjC,YAAM,IAAI;AAAA,QACN,6CAA6C,KAAK,WAAW,OAAO,aACtD,WAAW,IAAI,CAAC,aAAa,KAAK;AAAA,QAChD;AAAA,QACA,EAAC,OAAO,KAAK,WAAW,QAAO;AAAA,MACnC;AAAA,IACJ;AAEA,QAAI,QAAQ,KAAK,WAAW,SAAS;AACjC,YAAM,IAAI;AAAA,QACN,0CAA0C,KAAK,WAAW,OAAO,aACnD,WAAW,IAAI,CAAC,aAAa,KAAK;AAAA,QAChD;AAAA,QACA,EAAC,OAAO,KAAK,WAAW,QAAO;AAAA,MACnC;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/validation/objectType.ts"],"sourcesContent":["import {Schema, TypeSchema, Violation} from './schema';\nimport {MixedSchema} from './mixedSchema';\nimport {describe, formatPath} from './violation';\n\ntype ObjectDefinition = {\n type?: {new (...args: any): any},\n properties: {[key: string]: Schema},\n additionalProperties: boolean | Schema,\n subtypes?: {\n discriminator: string,\n schemas: {[key: string]: ObjectType},\n },\n propertyNames: Schema,\n required: string[],\n minProperties: number,\n maxProperties: number,\n};\n\nexport class ObjectType implements TypeSchema {\n private readonly definition: ObjectDefinition;\n\n public constructor(schema: Partial<ObjectDefinition> = {}) {\n this.definition = {\n ...schema,\n properties: schema.properties ?? {},\n required: schema.required ?? [],\n additionalProperties: schema.additionalProperties ?? false,\n propertyNames: schema.propertyNames ?? new MixedSchema(),\n minProperties: schema.minProperties ?? -1,\n maxProperties: schema.maxProperties ?? -1,\n };\n }\n\n public getTypes(): string[] {\n if (this.definition.type !== undefined) {\n return [this.definition.type.name];\n }\n\n return ['object'];\n }\n\n public isValidType(value: unknown): value is object {\n if (this.definition.type !== undefined) {\n return value instanceof this.definition.type;\n }\n\n return Object.prototype\n .toString\n .call(value) === '[object Object]';\n }\n\n public validate(value: unknown, path: string[] = []): void {\n if (!this.isValidType(value)) {\n const [type] = this.getTypes();\n\n throw new Violation(\n `Expected value of type ${type} at path '${formatPath(path)}', `\n + `actual ${describe(value)}.`,\n path,\n {type: type},\n );\n }\n\n const entries = Object.entries(value);\n\n const {minProperties, maxProperties} = this.definition;\n\n if (minProperties >= 0 && minProperties > entries.length) {\n throw new Violation(\n `Expected ${minProperties === maxProperties ? 'exactly' : 'at least'} `\n + `${minProperties} ${minProperties === 1 ? 'entry' : 'entries'} `\n + `at path '${formatPath(path)}', actual ${entries.length}.`,\n path,\n {limit: minProperties},\n );\n }\n\n if (maxProperties >= 0 && maxProperties < entries.length) {\n throw new Violation(\n `Expected ${minProperties === maxProperties ? 'exactly' : 'at most'} `\n + `${maxProperties} ${maxProperties === 1 ? 'entry' : 'entries'} `\n + `at path '${formatPath(path)}', actual ${entries.length}.`,\n path,\n {limit: maxProperties},\n );\n }\n\n const additionalProperties: {[key: string]: any} = {...value};\n\n for (const property of this.definition.required) {\n if (!(property in value)) {\n throw new Violation(`Missing property '${formatPath(path.concat([property]))}'.`, path, {\n required: property,\n });\n }\n }\n\n for (const [entryName, entryValue] of entries) {\n const propertyPath = path.concat([entryName]);\n\n this.definition\n .propertyNames\n .validate(entryName, propertyPath);\n\n const propertyRule = this.definition.properties[entryName];\n\n if (propertyRule !== undefined) {\n propertyRule.validate(entryValue, propertyPath);\n\n delete additionalProperties[entryName];\n\n continue;\n }\n\n if (this.definition.additionalProperties === false) {\n throw new Violation(`Unknown property '${formatPath(propertyPath)}'.`, propertyPath, {\n additionalProperty: entryName,\n });\n }\n\n if (this.definition.additionalProperties !== true) {\n this.definition\n .additionalProperties\n .validate(entryValue, propertyPath);\n }\n }\n\n const {subtypes} = this.definition;\n\n if (subtypes !== undefined) {\n const type = (value as any)[subtypes.discriminator];\n\n if (type !== undefined && subtypes.schemas[type] !== undefined) {\n subtypes.schemas[type].validate(additionalProperties, path);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA4C;AAC5C,yBAA0B;AAC1B,uBAAmC;AAgB5B,MAAM,WAAiC;AAAA,EAGnC,YAAY,SAAoC,CAAC,GAAG;AACvD,SAAK,aAAa;AAAA,MACd,GAAG;AAAA,MACH,YAAY,OAAO,cAAc,CAAC;AAAA,MAClC,UAAU,OAAO,YAAY,CAAC;AAAA,MAC9B,sBAAsB,OAAO,wBAAwB;AAAA,MACrD,eAAe,OAAO,iBAAiB,IAAI,+BAAY;AAAA,MACvD,eAAe,OAAO,iBAAiB;AAAA,MACvC,eAAe,OAAO,iBAAiB;AAAA,IAC3C;AAAA,EACJ;AAAA,EAEO,WAAqB;AACxB,QAAI,KAAK,WAAW,SAAS,QAAW;AACpC,aAAO,CAAC,KAAK,WAAW,KAAK,IAAI;AAAA,IACrC;AAEA,WAAO,CAAC,QAAQ;AAAA,EACpB;AAAA,EAEO,YAAY,OAAiC;AAChD,QAAI,KAAK,WAAW,SAAS,QAAW;AACpC,aAAO,iBAAiB,KAAK,WAAW;AAAA,IAC5C;AAEA,WAAO,OAAO,UACT,SACA,KAAK,KAAK,MAAM;AAAA,EACzB;AAAA,EAEO,SAAS,OAAgB,OAAiB,CAAC,GAAS;AACvD,QAAI,CAAC,KAAK,YAAY,KAAK,GAAG;AAC1B,YAAM,CAAC,IAAI,IAAI,KA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UAAI,iBAAiB,QAAW;AAC5B,qBAAa,SAAS,YAAY,YAAY;AAE9C,eAAO,qBAAqB,SAAS;AAErC;AAAA,MACJ;AAEA,UAAI,KAAK,WAAW,yBAAyB,OAAO;AAChD,cAAM,IAAI,wBAAU,yBAAqB,6BAAW,YAAY,CAAC,MAAM,cAAc;AAAA,UACjF,oBAAoB;AAAA,QACxB,CAAC;AAAA,MACL;AAEA,UAAI,KAAK,WAAW,yBAAyB,MAAM;AAC/C,aAAK,WACA,qBACA,SAAS,YAAY,YAAY;AAAA,MAC1C;AAAA,IACJ;AAEA,UAAM,EAAC,SAAQ,IAAI,KAAK;AAExB,QAAI,aAAa,QAAW;AACxB,YAAM,OAAQ,MAAc,SAAS,aAAa;AAElD,UAAI,SAAS,UAAa,SAAS,QAAQ,IAAI,MAAM,QAAW;AAC5D,iBAAS,QAAQ,IAAI,EAAE,SAAS,sBAAsB,IAAI;AAAA,MAC9D;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
@@ -1,4 +1,5 @@
1
- import { Schema, TypeSchema } from './schema';
1
+ import { TypeSchema, Schema } from './schema.js';
2
+
2
3
  type ObjectDefinition = {
3
4
  type?: {
4
5
  new (...args: any): any;
@@ -18,11 +19,12 @@ type ObjectDefinition = {
18
19
  minProperties: number;
19
20
  maxProperties: number;
20
21
  };
21
- export declare class ObjectType implements TypeSchema {
22
+ declare class ObjectType implements TypeSchema {
22
23
  private readonly definition;
23
24
  constructor(schema?: Partial<ObjectDefinition>);
24
25
  getTypes(): string[];
25
26
  isValidType(value: unknown): value is object;
26
27
  validate(value: unknown, path?: string[]): void;
27
28
  }
28
- export {};
29
+
30
+ export { ObjectType };