@wener/utils 1.1.27 → 1.1.30

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 (324) hide show
  1. package/lib/arrays/MaybeArray.js +36 -25
  2. package/lib/arrays/MaybeArray.js.map +1 -1
  3. package/lib/arrays/arrayFromAsync.js +5 -7
  4. package/lib/arrays/arrayFromAsync.js.map +1 -1
  5. package/lib/asyncs/AsyncInterval.js +11 -12
  6. package/lib/asyncs/AsyncInterval.js.map +1 -1
  7. package/lib/asyncs/MaybePromise.js +3 -0
  8. package/lib/asyncs/MaybePromise.js.map +1 -0
  9. package/lib/asyncs/createAsyncIterator.js +37 -35
  10. package/lib/asyncs/createAsyncIterator.js.map +1 -1
  11. package/lib/asyncs/createLazyPromise.js +59 -60
  12. package/lib/asyncs/createLazyPromise.js.map +1 -1
  13. package/lib/asyncs/firstOfAsyncIterator.js +7 -9
  14. package/lib/asyncs/firstOfAsyncIterator.js.map +1 -1
  15. package/lib/asyncs/generatorOfStream.js +16 -0
  16. package/lib/asyncs/generatorOfStream.js.map +1 -0
  17. package/lib/asyncs/isIterator.js +3 -4
  18. package/lib/asyncs/isIterator.js.map +1 -1
  19. package/lib/asyncs/isPromise.js +3 -4
  20. package/lib/asyncs/isPromise.js.map +1 -1
  21. package/lib/asyncs/isThenable.js +6 -0
  22. package/lib/asyncs/isThenable.js.map +1 -0
  23. package/lib/asyncs/nextOfAsyncIterator.js +20 -14
  24. package/lib/asyncs/nextOfAsyncIterator.js.map +1 -1
  25. package/lib/asyncs/promiseOfCallback.js +17 -0
  26. package/lib/asyncs/promiseOfCallback.js.map +1 -0
  27. package/lib/asyncs/sleep.js +2 -3
  28. package/lib/asyncs/sleep.js.map +1 -1
  29. package/lib/asyncs/timeout.js +22 -26
  30. package/lib/asyncs/timeout.js.map +1 -1
  31. package/lib/browsers/copy.js +47 -45
  32. package/lib/browsers/copy.js.map +1 -1
  33. package/lib/browsers/download.js +38 -27
  34. package/lib/browsers/download.js.map +1 -1
  35. package/lib/browsers/getFileFromDataTransfer.js +41 -28
  36. package/lib/browsers/getFileFromDataTransfer.js.map +1 -1
  37. package/lib/browsers/loaders.js +43 -43
  38. package/lib/browsers/loaders.js.map +1 -1
  39. package/lib/crypto/base.js +5 -4
  40. package/lib/crypto/base.js.map +1 -1
  41. package/lib/crypto/getNodeCrypto.js +14 -13
  42. package/lib/crypto/getNodeCrypto.js.map +1 -1
  43. package/lib/crypto/getRandomValues.js +22 -26
  44. package/lib/crypto/getRandomValues.js.map +1 -1
  45. package/lib/crypto/hashing.js +42 -50
  46. package/lib/crypto/hashing.js.map +1 -1
  47. package/lib/crypto/md5.bench.js +21 -0
  48. package/lib/crypto/md5.bench.js.map +1 -0
  49. package/lib/crypto/md5.d.js +3 -0
  50. package/lib/crypto/md5.d.js.map +1 -0
  51. package/lib/crypto/md5.js +119 -121
  52. package/lib/crypto/md5.js.map +1 -1
  53. package/lib/crypto/pem/pem.js +32 -35
  54. package/lib/crypto/pem/pem.js.map +1 -1
  55. package/lib/crypto/randomUUID.js +12 -11
  56. package/lib/crypto/randomUUID.js.map +1 -1
  57. package/lib/crypto/ulid.js +123 -112
  58. package/lib/crypto/ulid.js.map +1 -1
  59. package/lib/errors/Errors.js +167 -149
  60. package/lib/errors/Errors.js.map +1 -1
  61. package/lib/fetch/createFetchWith.js +20 -23
  62. package/lib/fetch/createFetchWith.js.map +1 -1
  63. package/lib/fetch/createFetchWithLogging.js +20 -16
  64. package/lib/fetch/createFetchWithLogging.js.map +1 -1
  65. package/lib/fetch/createFetchWithRetry.js +61 -65
  66. package/lib/fetch/createFetchWithRetry.js.map +1 -1
  67. package/lib/fetch/dumpRequest.js +39 -42
  68. package/lib/fetch/dumpRequest.js.map +1 -1
  69. package/lib/fetch/dumpResponse.js +13 -20
  70. package/lib/fetch/dumpResponse.js.map +1 -1
  71. package/lib/fetch/index.js +7 -0
  72. package/lib/fetch/index.js.map +1 -0
  73. package/lib/fetch/types.js +3 -0
  74. package/lib/fetch/types.js.map +1 -0
  75. package/lib/http/HttpStatus.js +89 -80
  76. package/lib/http/HttpStatus.js.map +1 -1
  77. package/lib/i18n/createTranslate.js +48 -48
  78. package/lib/i18n/createTranslate.js.map +1 -1
  79. package/lib/index.js +28 -14
  80. package/lib/index.js.map +1 -1
  81. package/lib/io/AbstractEncoding.js +7 -0
  82. package/lib/io/AbstractEncoding.js.map +1 -0
  83. package/lib/io/ArrayBuffer.test-d.js +7 -0
  84. package/lib/io/ArrayBuffer.test-d.js.map +1 -0
  85. package/lib/io/ArrayBuffers.js +198 -172
  86. package/lib/io/ArrayBuffers.js.map +1 -1
  87. package/lib/io/Buffer.js +21 -20
  88. package/lib/io/Buffer.js.map +1 -1
  89. package/lib/io/base64.js +49 -48
  90. package/lib/io/base64.js.map +1 -1
  91. package/lib/io/isBuffer.js +7 -5
  92. package/lib/io/isBuffer.js.map +1 -1
  93. package/lib/io/isTransferable.js +23 -19
  94. package/lib/io/isTransferable.js.map +1 -1
  95. package/lib/isomorphics/getGlobalThis.js +17 -12
  96. package/lib/isomorphics/getGlobalThis.js.map +1 -1
  97. package/lib/isomorphics/structuredClone.js +71 -63
  98. package/lib/isomorphics/structuredClone.js.map +1 -1
  99. package/lib/langs/MaybeFunction.js +7 -7
  100. package/lib/langs/MaybeFunction.js.map +1 -1
  101. package/lib/langs/classOf.js +3 -4
  102. package/lib/langs/classOf.js.map +1 -1
  103. package/lib/langs/deepEqual.js +77 -85
  104. package/lib/langs/deepEqual.js.map +1 -1
  105. package/lib/langs/deepFreeze.js +17 -13
  106. package/lib/langs/deepFreeze.js.map +1 -1
  107. package/lib/langs/hashCode.ignored.js +112 -0
  108. package/lib/langs/hashCode.ignored.js.map +1 -0
  109. package/lib/langs/isClass.js +3 -4
  110. package/lib/langs/isClass.js.map +1 -1
  111. package/lib/langs/isDefined.js +3 -4
  112. package/lib/langs/isDefined.js.map +1 -1
  113. package/lib/langs/isEmptyObject.js +3 -5
  114. package/lib/langs/isEmptyObject.js.map +1 -1
  115. package/lib/langs/isFunction.js +5 -0
  116. package/lib/langs/isFunction.js.map +1 -0
  117. package/lib/langs/isPlainObject.js +7 -8
  118. package/lib/langs/isPlainObject.js.map +1 -1
  119. package/lib/langs/memoize.js +19 -21
  120. package/lib/langs/memoize.js.map +1 -1
  121. package/lib/langs/parseBoolean.js +26 -27
  122. package/lib/langs/parseBoolean.js.map +1 -1
  123. package/lib/langs/shallowClone.js +12 -12
  124. package/lib/langs/shallowClone.js.map +1 -1
  125. package/lib/langs/shallowEqual.js +21 -18
  126. package/lib/langs/shallowEqual.js.map +1 -1
  127. package/lib/libs/ms.js +123 -103
  128. package/lib/libs/ms.js.map +1 -1
  129. package/lib/logging/Logger.js +5 -0
  130. package/lib/logging/Logger.js.map +1 -0
  131. package/lib/logging/createChildLogger.js +12 -14
  132. package/lib/logging/createChildLogger.js.map +1 -1
  133. package/lib/logging/createLogger.js +59 -33
  134. package/lib/logging/createLogger.js.map +1 -1
  135. package/lib/logging/createNoopLogger.js +11 -12
  136. package/lib/logging/createNoopLogger.js.map +1 -1
  137. package/lib/logging/slog.js +143 -0
  138. package/lib/logging/slog.js.map +1 -0
  139. package/lib/maths/clamp.js +20 -20
  140. package/lib/maths/clamp.js.map +1 -1
  141. package/lib/maths/random.js +14 -15
  142. package/lib/maths/random.js.map +1 -1
  143. package/lib/modules/isModule.js +5 -4
  144. package/lib/modules/isModule.js.map +1 -1
  145. package/lib/modules/parseModuleId.js +36 -31
  146. package/lib/modules/parseModuleId.js.map +1 -1
  147. package/lib/objects/get.js +13 -11
  148. package/lib/objects/get.js.map +1 -1
  149. package/lib/objects/get.test-d.js +33 -0
  150. package/lib/objects/get.test-d.js.map +1 -0
  151. package/lib/objects/merge/index.js +3 -0
  152. package/lib/objects/merge/index.js.map +1 -0
  153. package/lib/objects/merge/isMergeableObject.js +11 -10
  154. package/lib/objects/merge/isMergeableObject.js.map +1 -1
  155. package/lib/objects/merge/merge.js +65 -66
  156. package/lib/objects/merge/merge.js.map +1 -1
  157. package/lib/objects/parseObjectPath.js +35 -23
  158. package/lib/objects/parseObjectPath.js.map +1 -1
  159. package/lib/objects/set.js +33 -34
  160. package/lib/objects/set.js.map +1 -1
  161. package/lib/schema/typebox/gen/codegen/common/encoder.js +93 -67
  162. package/lib/schema/typebox/gen/codegen/common/encoder.js.map +1 -1
  163. package/lib/schema/typebox/gen/codegen/common/formatter.js +31 -8
  164. package/lib/schema/typebox/gen/codegen/common/formatter.js.map +1 -1
  165. package/lib/schema/typebox/gen/codegen/common/index.js +5 -0
  166. package/lib/schema/typebox/gen/codegen/common/index.js.map +1 -0
  167. package/lib/schema/typebox/gen/codegen/common/jsdoc.js +109 -60
  168. package/lib/schema/typebox/gen/codegen/common/jsdoc.js.map +1 -1
  169. package/lib/schema/typebox/gen/codegen/expression/compiler.js +359 -317
  170. package/lib/schema/typebox/gen/codegen/expression/compiler.js.map +1 -1
  171. package/lib/schema/typebox/gen/codegen/expression/errors.js +255 -233
  172. package/lib/schema/typebox/gen/codegen/expression/errors.js.map +1 -1
  173. package/lib/schema/typebox/gen/codegen/expression/evaluator.js +249 -236
  174. package/lib/schema/typebox/gen/codegen/expression/evaluator.js.map +1 -1
  175. package/lib/schema/typebox/gen/codegen/expression/expression.js +382 -198
  176. package/lib/schema/typebox/gen/codegen/expression/expression.js.map +1 -1
  177. package/lib/schema/typebox/gen/codegen/expression/index.js +6 -0
  178. package/lib/schema/typebox/gen/codegen/expression/index.js.map +1 -0
  179. package/lib/schema/typebox/gen/codegen/index.js +5 -19
  180. package/lib/schema/typebox/gen/codegen/index.js.map +1 -1
  181. package/lib/schema/typebox/gen/codegen/model/index.js +16 -0
  182. package/lib/schema/typebox/gen/codegen/model/index.js.map +1 -0
  183. package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js +236 -260
  184. package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js.map +1 -1
  185. package/lib/schema/typebox/gen/codegen/model/model-to-expression.js +348 -352
  186. package/lib/schema/typebox/gen/codegen/model/model-to-expression.js.map +1 -1
  187. package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js +214 -242
  188. package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js.map +1 -1
  189. package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js +229 -292
  190. package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js.map +1 -1
  191. package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js +42 -15
  192. package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js.map +1 -1
  193. package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js +168 -168
  194. package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js.map +1 -1
  195. package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js +31 -8
  196. package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js.map +1 -1
  197. package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js +156 -190
  198. package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js.map +1 -1
  199. package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js +215 -249
  200. package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js.map +1 -1
  201. package/lib/schema/typebox/gen/codegen/model/model-to-value.js +37 -13
  202. package/lib/schema/typebox/gen/codegen/model/model-to-value.js.map +1 -1
  203. package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js +201 -242
  204. package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js.map +1 -1
  205. package/lib/schema/typebox/gen/codegen/model/model-to-yup.js +200 -245
  206. package/lib/schema/typebox/gen/codegen/model/model-to-yup.js.map +1 -1
  207. package/lib/schema/typebox/gen/codegen/model/model-to-zod.js +223 -268
  208. package/lib/schema/typebox/gen/codegen/model/model-to-zod.js.map +1 -1
  209. package/lib/schema/typebox/gen/codegen/model/model.js +27 -0
  210. package/lib/schema/typebox/gen/codegen/model/model.js.map +1 -0
  211. package/lib/schema/typebox/gen/codegen/typescript/index.js +4 -0
  212. package/lib/schema/typebox/gen/codegen/typescript/index.js.map +1 -0
  213. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js +43 -40
  214. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js.map +1 -1
  215. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js +592 -616
  216. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js.map +1 -1
  217. package/lib/schema/typebox/gen/index.js +3 -3
  218. package/lib/schema/typebox/gen/index.js.map +1 -1
  219. package/lib/schema/typebox/index.js +3 -3
  220. package/lib/schema/typebox/index.js.map +1 -1
  221. package/lib/schema/typebox/typebox.js +18 -29
  222. package/lib/schema/typebox/typebox.js.map +1 -1
  223. package/lib/server.js +2 -1
  224. package/lib/server.js.map +1 -1
  225. package/lib/servers/crypto/md5.js +3 -5
  226. package/lib/servers/crypto/md5.js.map +1 -1
  227. package/lib/servers/fetch/createFetchWithProxy.js +2 -4
  228. package/lib/servers/fetch/createFetchWithProxy.js.map +1 -1
  229. package/lib/servers/fetch/createFetchWithProxyByNodeFetch.js +34 -34
  230. package/lib/servers/fetch/createFetchWithProxyByNodeFetch.js.map +1 -1
  231. package/lib/servers/fetch/createFetchWithProxyByUndici.js +57 -58
  232. package/lib/servers/fetch/createFetchWithProxyByUndici.js.map +1 -1
  233. package/lib/servers/getPackageDir.js +8 -10
  234. package/lib/servers/getPackageDir.js.map +1 -1
  235. package/lib/servers/jsdom.js +3 -2
  236. package/lib/servers/jsdom.js.map +1 -1
  237. package/lib/servers/node-fetch.js +4 -3
  238. package/lib/servers/node-fetch.js.map +1 -1
  239. package/lib/servers/polyfill/polyfillBrowser.js +17 -0
  240. package/lib/servers/polyfill/polyfillBrowser.js.map +1 -0
  241. package/lib/servers/polyfill/polyfillCrypto.js +8 -10
  242. package/lib/servers/polyfill/polyfillCrypto.js.map +1 -1
  243. package/lib/servers/polyfill/polyfillFetch.js +23 -22
  244. package/lib/servers/polyfill/polyfillFetch.js.map +1 -1
  245. package/lib/servers/polyfill/polyfillJsDom.js +59 -52
  246. package/lib/servers/polyfill/polyfillJsDom.js.map +1 -1
  247. package/lib/servers/polyfill/polyfillWebSocket.js +13 -13
  248. package/lib/servers/polyfill/polyfillWebSocket.js.map +1 -1
  249. package/lib/servers/ws.js +3 -2
  250. package/lib/servers/ws.js.map +1 -1
  251. package/lib/strings/camelCase.js +51 -49
  252. package/lib/strings/camelCase.js.map +1 -1
  253. package/lib/strings/formatBytes.js +41 -15
  254. package/lib/strings/formatBytes.js.map +1 -1
  255. package/lib/strings/renderTemplate.js +27 -20
  256. package/lib/strings/renderTemplate.js.map +1 -1
  257. package/lib/typedoc.js +4 -0
  258. package/lib/typedoc.js.map +1 -0
  259. package/lib/types/global.d.js +2 -0
  260. package/lib/types/global.d.js.map +1 -0
  261. package/lib/types/index.d.js +6 -0
  262. package/lib/types/index.d.js.map +1 -0
  263. package/lib/validations/asserts.js +14 -0
  264. package/lib/validations/asserts.js.map +1 -0
  265. package/lib/validations/isUUID.js +3 -4
  266. package/lib/validations/isUUID.js.map +1 -1
  267. package/lib/validations/parseTimestamp.js +25 -21
  268. package/lib/validations/parseTimestamp.js.map +1 -1
  269. package/package.json +3 -3
  270. package/dist/LICENSE.txt +0 -1
  271. package/dist/cjs/createFetchWith-qhRObsE4.js +0 -2
  272. package/dist/cjs/createFetchWith-qhRObsE4.js.map +0 -1
  273. package/dist/cjs/getGlobalThis-GhffAgiG.js +0 -2
  274. package/dist/cjs/getGlobalThis-GhffAgiG.js.map +0 -1
  275. package/dist/cjs/index.cjs +0 -21
  276. package/dist/cjs/index.cjs.map +0 -1
  277. package/dist/cjs/schema/typebox/gen/index.cjs +0 -118
  278. package/dist/cjs/schema/typebox/gen/index.cjs.map +0 -1
  279. package/dist/cjs/schema/typebox/index.cjs +0 -2
  280. package/dist/cjs/schema/typebox/index.cjs.map +0 -1
  281. package/dist/cjs/server.cjs +0 -2
  282. package/dist/cjs/server.cjs.map +0 -1
  283. package/dist/cjs/servers/jsdom.cjs +0 -2
  284. package/dist/cjs/servers/jsdom.cjs.map +0 -1
  285. package/dist/cjs/servers/node-fetch.cjs +0 -2
  286. package/dist/cjs/servers/node-fetch.cjs.map +0 -1
  287. package/dist/cjs/servers/ws.cjs +0 -2
  288. package/dist/cjs/servers/ws.cjs.map +0 -1
  289. package/dist/esm/createFetchWith-1q1S-Xro.js +0 -2
  290. package/dist/esm/createFetchWith-1q1S-Xro.js.map +0 -1
  291. package/dist/esm/getGlobalThis-A8F-nU7J.js +0 -2
  292. package/dist/esm/getGlobalThis-A8F-nU7J.js.map +0 -1
  293. package/dist/esm/index.js +0 -21
  294. package/dist/esm/index.js.map +0 -1
  295. package/dist/esm/schema/typebox/gen.js +0 -118
  296. package/dist/esm/schema/typebox/gen.js.map +0 -1
  297. package/dist/esm/schema/typebox.js +0 -2
  298. package/dist/esm/schema/typebox.js.map +0 -1
  299. package/dist/esm/server.js +0 -2
  300. package/dist/esm/server.js.map +0 -1
  301. package/dist/esm/servers/jsdom.js +0 -2
  302. package/dist/esm/servers/jsdom.js.map +0 -1
  303. package/dist/esm/servers/node-fetch.js +0 -2
  304. package/dist/esm/servers/node-fetch.js.map +0 -1
  305. package/dist/esm/servers/ws.js +0 -2
  306. package/dist/esm/servers/ws.js.map +0 -1
  307. package/dist/system/createFetchWith-TjUle-dI.js +0 -2
  308. package/dist/system/createFetchWith-TjUle-dI.js.map +0 -1
  309. package/dist/system/getGlobalThis-X5ifUXDI.js +0 -2
  310. package/dist/system/getGlobalThis-X5ifUXDI.js.map +0 -1
  311. package/dist/system/index.js +0 -21
  312. package/dist/system/index.js.map +0 -1
  313. package/dist/system/schema/typebox/gen.js +0 -118
  314. package/dist/system/schema/typebox/gen.js.map +0 -1
  315. package/dist/system/schema/typebox.js +0 -2
  316. package/dist/system/schema/typebox.js.map +0 -1
  317. package/dist/system/server.js +0 -2
  318. package/dist/system/server.js.map +0 -1
  319. package/dist/system/servers/jsdom.js +0 -2
  320. package/dist/system/servers/jsdom.js.map +0 -1
  321. package/dist/system/servers/node-fetch.js +0 -2
  322. package/dist/system/servers/node-fetch.js.map +0 -1
  323. package/dist/system/servers/ws.js +0 -2
  324. package/dist/system/servers/ws.js.map +0 -1
@@ -1,363 +1,359 @@
1
1
  import * as Types from '@sinclair/typebox';
2
2
  import { TypeSystemPolicy } from '@sinclair/typebox/system';
3
- import { Formatter } from '../common/formatter.js';
4
- import '../expression/compiler.js';
5
- import '../expression/errors.js';
6
- import '../expression/evaluator.js';
7
- import { Expression } from '../expression/expression.js';
8
-
9
- class TypeTransformUnknownSchemaError extends Error {
10
- constructor(schema) {
11
- super("TypeTransformUnknownSchemaError: Unknown schema");
12
- this.schema = schema;
13
- }
3
+ import { Formatter } from '../common/formatter';
4
+ import { Expression } from '../expression/index';
5
+ export class TypeTransformUnknownSchemaError extends Error {
6
+ schema;
7
+ constructor(schema){
8
+ super('TypeTransformUnknownSchemaError: Unknown schema');
9
+ this.schema = schema;
10
+ }
14
11
  }
15
- var TypeBoxToExpression;
16
- ((TypeBoxToExpression2) => {
17
- function IsArray(value) {
18
- return globalThis.Array.isArray(value);
19
- }
20
- function IsObject(value) {
21
- return typeof value === "object" && !IsArray(value);
22
- }
23
- function IsNumber(value) {
24
- return typeof value === "number" && !isNaN(value);
25
- }
26
- function IsUndefined(value) {
27
- return value === void 0;
28
- }
29
- function Any(schema, references) {
30
- return Expression.True({ $id: schema.$id });
31
- }
32
- function Array(schema, references) {
33
- return Expression.And(
34
- function* () {
35
- yield Expression.IsArray();
36
- if (IsNumber(schema.maxItems))
37
- yield Expression.Property("length", Expression.LessThanEqual(schema.maxItems));
38
- if (IsNumber(schema.minItems))
39
- yield Expression.Property("length", Expression.GreaterThanEqual(schema.minItems));
40
- yield Expression.Elements(Visit(schema.items, references));
41
- if (schema.uniqueItems === true)
42
- yield Expression.ElementsDistinct();
43
- },
44
- { $id: schema.$id }
45
- );
46
- }
47
- function Boolean(schema, references) {
48
- return Expression.IsBoolean({ $id: schema.$id });
49
- }
50
- function Constructor(schema, references) {
51
- return Expression.Property("prototype", Visit(schema.returns, references), { $id: schema.$id });
52
- }
53
- function Date(schema, references) {
54
- return Expression.And(
55
- function* () {
56
- yield Expression.InstanceOf("Date");
57
- if (IsNumber(schema.maximumTimestamp))
58
- yield Expression.Call("getTime", [], Expression.LessThanEqual(schema.maximumTimestamp));
59
- if (IsNumber(schema.minimumTimestamp))
60
- yield Expression.Call("getTime", [], Expression.GreaterThanEqual(schema.minimumTimestamp));
61
- if (IsNumber(schema.exclusiveMaximumTimestamp))
62
- yield Expression.Call("getTime", [], Expression.LessThan(schema.exclusiveMaximumTimestamp));
63
- if (IsNumber(schema.exclusiveMinimumTimestamp))
64
- yield Expression.Call("getTime", [], Expression.GreaterThan(schema.exclusiveMinimumTimestamp));
65
- },
66
- { $id: schema.$id }
67
- );
68
- }
69
- function Function(schema, references) {
70
- return Expression.IsFunction({ $id: schema.$id });
71
- }
72
- function Intersect(schema, references) {
73
- return Expression.And(
74
- function* () {
75
- for (const inner of schema.allOf) {
76
- yield Visit(inner, references);
77
- }
78
- },
79
- { $id: schema.$id }
80
- );
81
- }
82
- function Integer(schema, references) {
83
- return Expression.And(
84
- function* () {
85
- yield Expression.IsInteger();
86
- if (IsNumber(schema.multipleOf))
87
- yield Expression.MultipleOf(schema.multipleOf);
88
- if (IsNumber(schema.maximum))
89
- yield Expression.LessThanEqual(schema.maximum);
90
- if (IsNumber(schema.minimum))
91
- yield Expression.GreaterThanEqual(schema.minimum);
92
- if (IsNumber(schema.exclusiveMaximum))
93
- yield Expression.LessThan(schema.exclusiveMaximum);
94
- if (IsNumber(schema.exclusiveMinimum))
95
- yield Expression.GreaterThan(schema.exclusiveMinimum);
96
- },
97
- { $id: schema.$id }
98
- );
99
- }
100
- function Literal(schema, references) {
101
- return Expression.Equals(schema.const, { $id: schema.$id });
102
- }
103
- function Never(schema, references) {
104
- return Expression.False({ $id: schema.$id });
105
- }
106
- function Null(schema, references) {
107
- return Expression.IsNull({ $id: schema.$id });
108
- }
109
- function Number(schema, references) {
110
- return Expression.And(
111
- function* () {
112
- yield Expression.IsNumber();
113
- if (TypeSystemPolicy.AllowNaN === false)
114
- yield Expression.IsFinite();
115
- if (IsNumber(schema.multipleOf))
116
- yield Expression.MultipleOf(schema.multipleOf);
117
- if (IsNumber(schema.maximum))
118
- yield Expression.LessThanEqual(schema.maximum);
119
- if (IsNumber(schema.minimum))
120
- yield Expression.GreaterThanEqual(schema.minimum);
121
- if (IsNumber(schema.exclusiveMaximum))
122
- yield Expression.LessThan(schema.exclusiveMaximum);
123
- if (IsNumber(schema.exclusiveMinimum))
124
- yield Expression.GreaterThan(schema.exclusiveMinimum);
125
- },
126
- { $id: schema.$id }
127
- );
128
- }
129
- function Object(schema, references) {
130
- const propertyKeys = globalThis.Object.getOwnPropertyNames(schema.properties);
131
- const requiredKeys = IsArray(schema.required) ? schema.required : [];
132
- const optionalKeys = new Set(propertyKeys);
133
- requiredKeys.forEach((key) => optionalKeys.delete(key));
134
- return Expression.And(
135
- function* () {
136
- yield Expression.IsObject();
137
- yield Expression.Not(Expression.IsNull());
138
- if (TypeSystemPolicy.AllowArrayObject === false)
139
- yield Expression.Not(Expression.IsArray());
140
- if (IsNumber(schema.minProperties))
141
- yield Expression.PropertiesMinimum(schema.minProperties);
142
- if (IsNumber(schema.maxProperties))
143
- yield Expression.PropertiesMaximum(schema.maxProperties);
144
- if (schema.additionalProperties === false) {
145
- if (schema.required && schema.required.length === propertyKeys.length) {
146
- yield Expression.PropertiesLength(propertyKeys.length);
147
- } else {
148
- yield Expression.PropertiesExclude(propertyKeys, Expression.False());
149
- }
150
- }
151
- if (IsObject(schema.additionalProperties)) {
152
- yield Expression.PropertiesExclude(propertyKeys, Visit(schema.additionalProperties, references));
153
- }
154
- for (const propertyKey of requiredKeys) {
155
- yield Expression.Property(propertyKey, Visit(schema.properties[propertyKey], references));
156
- }
157
- for (const propertyKey of optionalKeys) {
158
- yield Expression.Or(function* () {
159
- yield Expression.Not(Expression.KeyIn(propertyKey));
160
- yield Expression.Property(
161
- propertyKey,
162
- Expression.Or(function* () {
163
- yield Expression.Not(Expression.KeyIn(propertyKey));
164
- yield Visit(schema.properties[propertyKey], references);
165
- })
166
- );
167
- });
168
- }
169
- },
170
- { $id: schema.$id }
171
- );
172
- }
173
- function Promise(schema, references) {
174
- return Expression.And(
175
- function* () {
176
- yield Expression.IsObject();
177
- yield Expression.Property("then", Expression.IsFunction());
178
- },
179
- { $id: schema.$id }
180
- );
181
- }
182
- function Record(schema, references) {
183
- const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
184
- return Expression.And(
185
- function* () {
186
- yield Expression.IsObject();
187
- yield Expression.Not(Expression.IsNull());
188
- yield Expression.Not(Expression.InstanceOf("Date"));
189
- if (IsNumber(schema.minProperties))
190
- yield Expression.PropertiesMinimum(schema.minProperties);
191
- if (IsNumber(schema.maxProperties))
192
- yield Expression.PropertiesMaximum(schema.maxProperties);
193
- yield Expression.PropertiesIncludePattern(keyPattern, Visit(valueSchema, references));
194
- if (schema.additionalProperties === false) {
195
- yield Expression.PropertiesExcludePattern(keyPattern, Expression.False());
196
- }
197
- if (IsObject(schema.additionalProperties)) {
198
- yield Expression.PropertiesExcludePattern(keyPattern, Visit(schema.additionalProperties, references));
199
- }
200
- },
201
- { $id: schema.$id }
202
- );
203
- }
204
- function Ref(schema, references) {
205
- return Expression.Ref(schema.$ref);
206
- }
207
- function Self(schema, references) {
208
- return Expression.Ref(schema.$ref, { $id: schema.$id });
209
- }
210
- function String(schema, references) {
211
- return Expression.And(
212
- function* () {
213
- yield Expression.IsString();
214
- if (IsNumber(schema.minLength))
215
- yield Expression.Property("length", Expression.GreaterThanEqual(schema.minLength));
216
- if (IsNumber(schema.maxLength))
217
- yield Expression.Property("length", Expression.LessThanEqual(schema.maxLength));
218
- if (!IsUndefined(schema.pattern))
219
- yield Expression.IsPattern(schema.pattern);
220
- },
221
- { $id: schema.$id }
222
- );
223
- }
224
- function TemplateLiteral(schema, references) {
225
- return Expression.IsPattern(schema.pattern);
226
- }
227
- function Tuple(schema, references) {
228
- return Expression.And(
229
- function* () {
230
- yield Expression.IsArray();
231
- if (schema.items === void 0)
232
- return yield Expression.Property("length", Expression.Equals(0));
233
- if (schema.maxItems)
234
- yield Expression.Property("length", Expression.Equals(schema.maxItems));
235
- yield Expression.And(function* () {
236
- for (let index = 0; index < schema.items.length; index++) {
237
- yield Expression.Index(index, Visit(schema.items[index], references));
238
- }
12
+ export var TypeBoxToExpression;
13
+ (function(TypeBoxToExpression) {
14
+ // --------------------------------------------------------------
15
+ // Guards
16
+ // --------------------------------------------------------------
17
+ function IsArray(value) {
18
+ return globalThis.Array.isArray(value);
19
+ }
20
+ function IsObject(value) {
21
+ return typeof value === 'object' && !IsArray(value);
22
+ }
23
+ function IsNumber(value) {
24
+ return typeof value === 'number' && !isNaN(value);
25
+ }
26
+ function IsString(value) {
27
+ return typeof value === 'string';
28
+ }
29
+ function IsUndefined(value) {
30
+ return value === undefined;
31
+ }
32
+ // --------------------------------------------------------------
33
+ // Conditional: If Then Else
34
+ // --------------------------------------------------------------
35
+ // function* Conditional(schema: Types.TSchema, references: Types.TSchema[]): IterableIterator<Expression> {
36
+ // if (IsUndefined(schema.if)) return
37
+ // const if_expression = Visit(schema.if, references)
38
+ // const then_expression = IsUndefined(schema.then) ? Expression.True() : Visit(schema.then, references)
39
+ // const else_expression = IsUndefined(schema.else) ? Expression.True() : Visit(schema.else, references)
40
+ // yield Expression.IfThenElse(if_expression, then_expression, else_expression)
41
+ // }
42
+ // --------------------------------------------------------------
43
+ // Transform
44
+ // --------------------------------------------------------------
45
+ function Any(schema, references) {
46
+ return Expression.True({
47
+ $id: schema.$id
48
+ });
49
+ }
50
+ function Array(schema, references) {
51
+ return Expression.And(function*() {
52
+ yield Expression.IsArray();
53
+ if (IsNumber(schema.maxItems)) yield Expression.Property('length', Expression.LessThanEqual(schema.maxItems));
54
+ if (IsNumber(schema.minItems)) yield Expression.Property('length', Expression.GreaterThanEqual(schema.minItems));
55
+ yield Expression.Elements(Visit(schema.items, references));
56
+ if (schema.uniqueItems === true) yield Expression.ElementsDistinct();
57
+ }, {
58
+ $id: schema.$id
59
+ });
60
+ }
61
+ function Boolean(schema, references) {
62
+ return Expression.IsBoolean({
63
+ $id: schema.$id
64
+ });
65
+ }
66
+ function Constructor(schema, references) {
67
+ return Expression.Property('prototype', Visit(schema.returns, references), {
68
+ $id: schema.$id
69
+ });
70
+ }
71
+ function Date(schema, references) {
72
+ return Expression.And(function*() {
73
+ yield Expression.InstanceOf('Date');
74
+ if (IsNumber(schema.maximumTimestamp)) yield Expression.Call('getTime', [], Expression.LessThanEqual(schema.maximumTimestamp));
75
+ if (IsNumber(schema.minimumTimestamp)) yield Expression.Call('getTime', [], Expression.GreaterThanEqual(schema.minimumTimestamp));
76
+ if (IsNumber(schema.exclusiveMaximumTimestamp)) yield Expression.Call('getTime', [], Expression.LessThan(schema.exclusiveMaximumTimestamp));
77
+ if (IsNumber(schema.exclusiveMinimumTimestamp)) yield Expression.Call('getTime', [], Expression.GreaterThan(schema.exclusiveMinimumTimestamp));
78
+ }, {
79
+ $id: schema.$id
80
+ });
81
+ }
82
+ function Function(schema, references) {
83
+ return Expression.IsFunction({
84
+ $id: schema.$id
85
+ });
86
+ }
87
+ function Intersect(schema, references) {
88
+ return Expression.And(function*() {
89
+ for (const inner of schema.allOf){
90
+ yield Visit(inner, references);
91
+ }
92
+ }, {
93
+ $id: schema.$id
94
+ });
95
+ }
96
+ function Integer(schema, references) {
97
+ return Expression.And(function*() {
98
+ yield Expression.IsInteger();
99
+ if (IsNumber(schema.multipleOf)) yield Expression.MultipleOf(schema.multipleOf);
100
+ if (IsNumber(schema.maximum)) yield Expression.LessThanEqual(schema.maximum);
101
+ if (IsNumber(schema.minimum)) yield Expression.GreaterThanEqual(schema.minimum);
102
+ if (IsNumber(schema.exclusiveMaximum)) yield Expression.LessThan(schema.exclusiveMaximum);
103
+ if (IsNumber(schema.exclusiveMinimum)) yield Expression.GreaterThan(schema.exclusiveMinimum);
104
+ }, {
105
+ $id: schema.$id
106
+ });
107
+ }
108
+ function Literal(schema, references) {
109
+ return Expression.Equals(schema.const, {
110
+ $id: schema.$id
111
+ });
112
+ }
113
+ function Never(schema, references) {
114
+ return Expression.False({
115
+ $id: schema.$id
116
+ });
117
+ }
118
+ function Null(schema, references) {
119
+ return Expression.IsNull({
120
+ $id: schema.$id
121
+ });
122
+ }
123
+ function Number(schema, references) {
124
+ return Expression.And(function*() {
125
+ yield Expression.IsNumber();
126
+ if (TypeSystemPolicy.AllowNaN === false) yield Expression.IsFinite();
127
+ if (IsNumber(schema.multipleOf)) yield Expression.MultipleOf(schema.multipleOf);
128
+ if (IsNumber(schema.maximum)) yield Expression.LessThanEqual(schema.maximum);
129
+ if (IsNumber(schema.minimum)) yield Expression.GreaterThanEqual(schema.minimum);
130
+ if (IsNumber(schema.exclusiveMaximum)) yield Expression.LessThan(schema.exclusiveMaximum);
131
+ if (IsNumber(schema.exclusiveMinimum)) yield Expression.GreaterThan(schema.exclusiveMinimum);
132
+ }, {
133
+ $id: schema.$id
134
+ });
135
+ }
136
+ function Object(schema, references) {
137
+ const propertyKeys = globalThis.Object.getOwnPropertyNames(schema.properties);
138
+ const requiredKeys = IsArray(schema.required) ? schema.required : [];
139
+ const optionalKeys = new Set(propertyKeys);
140
+ requiredKeys.forEach((key)=>optionalKeys.delete(key));
141
+ return Expression.And(function*() {
142
+ yield Expression.IsObject();
143
+ yield Expression.Not(Expression.IsNull());
144
+ if (TypeSystemPolicy.AllowArrayObject === false) yield Expression.Not(Expression.IsArray());
145
+ if (IsNumber(schema.minProperties)) yield Expression.PropertiesMinimum(schema.minProperties);
146
+ if (IsNumber(schema.maxProperties)) yield Expression.PropertiesMaximum(schema.maxProperties);
147
+ if (schema.additionalProperties === false) {
148
+ if (schema.required && schema.required.length === propertyKeys.length) {
149
+ yield Expression.PropertiesLength(propertyKeys.length);
150
+ } else {
151
+ yield Expression.PropertiesExclude(propertyKeys, Expression.False());
152
+ }
153
+ }
154
+ if (IsObject(schema.additionalProperties)) {
155
+ yield Expression.PropertiesExclude(propertyKeys, Visit(schema.additionalProperties, references));
156
+ }
157
+ for (const propertyKey of requiredKeys){
158
+ yield Expression.Property(propertyKey, Visit(schema.properties[propertyKey], references));
159
+ }
160
+ for (const propertyKey of optionalKeys){
161
+ yield Expression.Or(function*() {
162
+ yield Expression.Not(Expression.KeyIn(propertyKey));
163
+ yield Expression.Property(propertyKey, Expression.Or(function*() {
164
+ yield Expression.Not(Expression.KeyIn(propertyKey));
165
+ yield Visit(schema.properties[propertyKey], references);
166
+ }));
167
+ });
168
+ }
169
+ }, {
170
+ $id: schema.$id
171
+ });
172
+ }
173
+ function Promise(schema, references) {
174
+ return Expression.And(function*() {
175
+ yield Expression.IsObject();
176
+ yield Expression.Property('then', Expression.IsFunction());
177
+ }, {
178
+ $id: schema.$id
179
+ });
180
+ }
181
+ function Record(schema, references) {
182
+ const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
183
+ return Expression.And(function*() {
184
+ yield Expression.IsObject();
185
+ yield Expression.Not(Expression.IsNull());
186
+ yield Expression.Not(Expression.InstanceOf('Date'));
187
+ if (IsNumber(schema.minProperties)) yield Expression.PropertiesMinimum(schema.minProperties);
188
+ if (IsNumber(schema.maxProperties)) yield Expression.PropertiesMaximum(schema.maxProperties);
189
+ yield Expression.PropertiesIncludePattern(keyPattern, Visit(valueSchema, references));
190
+ if (schema.additionalProperties === false) {
191
+ yield Expression.PropertiesExcludePattern(keyPattern, Expression.False());
192
+ }
193
+ if (IsObject(schema.additionalProperties)) {
194
+ yield Expression.PropertiesExcludePattern(keyPattern, Visit(schema.additionalProperties, references));
195
+ }
196
+ }, {
197
+ $id: schema.$id
198
+ });
199
+ }
200
+ function Ref(schema, references) {
201
+ return Expression.Ref(schema.$ref);
202
+ }
203
+ function Self(schema, references) {
204
+ return Expression.Ref(schema.$ref, {
205
+ $id: schema.$id
206
+ });
207
+ }
208
+ function String(schema, references) {
209
+ return Expression.And(function*() {
210
+ yield Expression.IsString();
211
+ if (IsNumber(schema.minLength)) yield Expression.Property('length', Expression.GreaterThanEqual(schema.minLength));
212
+ if (IsNumber(schema.maxLength)) yield Expression.Property('length', Expression.LessThanEqual(schema.maxLength));
213
+ if (!IsUndefined(schema.pattern)) yield Expression.IsPattern(schema.pattern);
214
+ }, {
215
+ $id: schema.$id
216
+ });
217
+ }
218
+ function TemplateLiteral(schema, references) {
219
+ return Expression.IsPattern(schema.pattern);
220
+ }
221
+ function Tuple(schema, references) {
222
+ return Expression.And(function*() {
223
+ yield Expression.IsArray();
224
+ if (schema.items === undefined) return yield Expression.Property('length', Expression.Equals(0));
225
+ if (schema.maxItems) yield Expression.Property('length', Expression.Equals(schema.maxItems));
226
+ yield Expression.And(function*() {
227
+ for(let index = 0; index < schema.items.length; index++){
228
+ yield Expression.Index(index, Visit(schema.items[index], references));
229
+ }
230
+ });
231
+ }, {
232
+ $id: schema.$id
239
233
  });
240
- },
241
- { $id: schema.$id }
242
- );
243
- }
244
- function Undefined(schema, references) {
245
- return Expression.IsUndefined({ $id: schema.$id });
246
- }
247
- function Union(schema, references) {
248
- return Expression.Or(
249
- function* () {
250
- for (const inner of schema.anyOf) {
251
- yield Visit(inner, references);
234
+ }
235
+ function Undefined(schema, references) {
236
+ return Expression.IsUndefined({
237
+ $id: schema.$id
238
+ });
239
+ }
240
+ function Union(schema, references) {
241
+ return Expression.Or(function*() {
242
+ for (const inner of schema.anyOf){
243
+ yield Visit(inner, references);
244
+ }
245
+ }, {
246
+ $id: schema.$id
247
+ });
248
+ }
249
+ function Uint8Array(schema, references) {
250
+ return Expression.And(function*() {
251
+ yield Expression.InstanceOf('Uint8Array');
252
+ if (IsNumber(schema.maxByteLength)) yield Expression.Property('length', Expression.LessThanEqual(schema.maxByteLength));
253
+ if (IsNumber(schema.minByteLength)) yield Expression.Property('length', Expression.GreaterThanEqual(schema.minByteLength));
254
+ }, {
255
+ $id: schema.$id
256
+ });
257
+ }
258
+ function Unknown(schema, references) {
259
+ return Expression.True({
260
+ $id: schema.$id
261
+ });
262
+ }
263
+ function Void(schema, references) {
264
+ return Expression.IsUndefined({
265
+ $id: schema.$id
266
+ });
267
+ }
268
+ function Unresolved(schema, references) {
269
+ return Expression.False({
270
+ unresolved: schema
271
+ });
272
+ }
273
+ function Visit(schema, references) {
274
+ const anyReferences = schema.$id === undefined ? references : [
275
+ schema,
276
+ ...references
277
+ ];
278
+ const anySchema = schema;
279
+ switch(anySchema[Types.Kind]){
280
+ case 'Any':
281
+ return Any(anySchema, anyReferences);
282
+ case 'Array':
283
+ return Array(anySchema, anyReferences);
284
+ case 'Boolean':
285
+ return Boolean(anySchema, anyReferences);
286
+ case 'Constructor':
287
+ return Constructor(anySchema, anyReferences);
288
+ case 'Date':
289
+ return Date(anySchema, anyReferences);
290
+ case 'Function':
291
+ return Function(anySchema, anyReferences);
292
+ case 'Integer':
293
+ return Integer(anySchema, anyReferences);
294
+ case 'Intersect':
295
+ return Intersect(anySchema, anyReferences);
296
+ case 'Literal':
297
+ return Literal(anySchema, anyReferences);
298
+ case 'Never':
299
+ return Never(anySchema, anyReferences);
300
+ case 'Null':
301
+ return Null(anySchema, anyReferences);
302
+ case 'Number':
303
+ return Number(anySchema, anyReferences);
304
+ case 'Object':
305
+ return Object(anySchema, anyReferences);
306
+ case 'Promise':
307
+ return Promise(anySchema, anyReferences);
308
+ case 'Record':
309
+ return Record(anySchema, anyReferences);
310
+ case 'Ref':
311
+ return Ref(anySchema, anyReferences);
312
+ case 'Self':
313
+ return Self(anySchema, anyReferences);
314
+ case 'String':
315
+ return String(anySchema, anyReferences);
316
+ case 'TemplateLiteral':
317
+ return TemplateLiteral(anySchema, anyReferences);
318
+ case 'Tuple':
319
+ return Tuple(anySchema, anyReferences);
320
+ case 'Undefined':
321
+ return Undefined(anySchema, anyReferences);
322
+ case 'Union':
323
+ return Union(anySchema, anyReferences);
324
+ case 'Uint8Array':
325
+ return Uint8Array(anySchema, anyReferences);
326
+ case 'Unknown':
327
+ return Unknown(anySchema, anyReferences);
328
+ case 'Void':
329
+ return Void(anySchema, anyReferences);
330
+ default:
331
+ return Unresolved(schema, anyReferences);
252
332
  }
253
- },
254
- { $id: schema.$id }
255
- );
256
- }
257
- function Uint8Array(schema, references) {
258
- return Expression.And(
259
- function* () {
260
- yield Expression.InstanceOf("Uint8Array");
261
- if (IsNumber(schema.maxByteLength))
262
- yield Expression.Property("length", Expression.LessThanEqual(schema.maxByteLength));
263
- if (IsNumber(schema.minByteLength))
264
- yield Expression.Property("length", Expression.GreaterThanEqual(schema.minByteLength));
265
- },
266
- { $id: schema.$id }
267
- );
268
- }
269
- function Unknown(schema, references) {
270
- return Expression.True({ $id: schema.$id });
271
- }
272
- function Void(schema, references) {
273
- return Expression.IsUndefined({ $id: schema.$id });
274
- }
275
- function Unresolved(schema, references) {
276
- return Expression.False({ unresolved: schema });
277
- }
278
- function Visit(schema, references) {
279
- const anyReferences = schema.$id === void 0 ? references : [schema, ...references];
280
- const anySchema = schema;
281
- switch (anySchema[Types.Kind]) {
282
- case "Any":
283
- return Any(anySchema);
284
- case "Array":
285
- return Array(anySchema, anyReferences);
286
- case "Boolean":
287
- return Boolean(anySchema);
288
- case "Constructor":
289
- return Constructor(anySchema, anyReferences);
290
- case "Date":
291
- return Date(anySchema);
292
- case "Function":
293
- return Function(anySchema);
294
- case "Integer":
295
- return Integer(anySchema);
296
- case "Intersect":
297
- return Intersect(anySchema, anyReferences);
298
- case "Literal":
299
- return Literal(anySchema);
300
- case "Never":
301
- return Never(anySchema);
302
- case "Null":
303
- return Null(anySchema);
304
- case "Number":
305
- return Number(anySchema);
306
- case "Object":
307
- return Object(anySchema, anyReferences);
308
- case "Promise":
309
- return Promise(anySchema);
310
- case "Record":
311
- return Record(anySchema, anyReferences);
312
- case "Ref":
313
- return Ref(anySchema);
314
- case "Self":
315
- return Self(anySchema);
316
- case "String":
317
- return String(anySchema);
318
- case "TemplateLiteral":
319
- return TemplateLiteral(anySchema);
320
- case "Tuple":
321
- return Tuple(anySchema, anyReferences);
322
- case "Undefined":
323
- return Undefined(anySchema);
324
- case "Union":
325
- return Union(anySchema, anyReferences);
326
- case "Uint8Array":
327
- return Uint8Array(anySchema);
328
- case "Unknown":
329
- return Unknown(anySchema);
330
- case "Void":
331
- return Void(anySchema);
332
- default:
333
- return Unresolved(schema);
334
- }
335
- }
336
- function Transform(schema, references = []) {
337
- const expression = Visit(schema, references);
338
- return expression;
339
- }
340
- TypeBoxToExpression2.Transform = Transform;
333
+ }
334
+ function Transform(schema, references = []) {
335
+ const expression = Visit(schema, references);
336
+ return expression;
337
+ }
338
+ TypeBoxToExpression.Transform = Transform;
341
339
  })(TypeBoxToExpression || (TypeBoxToExpression = {}));
342
- var ModelToExpr;
343
- ((ModelToExpr2) => {
344
- function Generate(model) {
345
- const definitions = [];
346
- for (const type of model.types.filter((type2) => Types.TypeGuard.IsSchema(type2))) {
347
- const expression = TypeBoxToExpression.Transform(
348
- type,
349
- model.types.filter((t) => t.$id !== type.$id)
350
- );
351
- delete expression.$id;
352
- definitions.push(`
340
+ export var ModelToExpr;
341
+ (function(ModelToExpr) {
342
+ function Generate(model) {
343
+ const definitions = [];
344
+ for (const type of model.types.filter((type)=>Types.TypeGuard.IsSchema(type))){
345
+ const expression = TypeBoxToExpression.Transform(type, model.types.filter((t)=>t.$id !== type.$id));
346
+ delete expression.$id;
347
+ definitions.push(`
353
348
  export const ${type.$id} = ${JSON.stringify(expression)}
354
349
  `);
350
+ }
351
+ const output = [
352
+ ...definitions
353
+ ];
354
+ return Formatter.Format(output.join('\n\n'));
355
355
  }
356
- const output = [...definitions];
357
- return Formatter.Format(output.join("\n\n"));
358
- }
359
- ModelToExpr2.Generate = Generate;
356
+ ModelToExpr.Generate = Generate;
360
357
  })(ModelToExpr || (ModelToExpr = {}));
361
358
 
362
- export { ModelToExpr, TypeBoxToExpression, TypeTransformUnknownSchemaError };
363
- //# sourceMappingURL=model-to-expression.js.map
359
+ //# sourceMappingURL=model-to-expression.js.map