@mionjs/run-types 0.8.7 → 0.8.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 (362) hide show
  1. package/.dist/cjs/index.d.ts +1 -0
  2. package/.dist/cjs/index.d.ts.map +1 -0
  3. package/.dist/cjs/src/constants.d.ts +1 -0
  4. package/.dist/cjs/src/constants.d.ts.map +1 -0
  5. package/.dist/cjs/src/constants.functions.d.ts +1 -0
  6. package/.dist/cjs/src/constants.functions.d.ts.map +1 -0
  7. package/.dist/cjs/src/constants.kind.d.ts +1 -0
  8. package/.dist/cjs/src/constants.kind.d.ts.map +1 -0
  9. package/.dist/cjs/src/createRunType.d.ts +1 -0
  10. package/.dist/cjs/src/createRunType.d.ts.map +1 -0
  11. package/.dist/cjs/src/createRunTypeFunctions.d.ts +1 -0
  12. package/.dist/cjs/src/createRunTypeFunctions.d.ts.map +1 -0
  13. package/.dist/cjs/src/formats.runtype.d.ts +1 -0
  14. package/.dist/cjs/src/formats.runtype.d.ts.map +1 -0
  15. package/.dist/cjs/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts +1 -0
  16. package/.dist/cjs/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts.map +1 -0
  17. package/.dist/cjs/src/jitCompilers/binary/fromBinary.d.ts +1 -0
  18. package/.dist/cjs/src/jitCompilers/binary/fromBinary.d.ts.map +1 -0
  19. package/.dist/cjs/src/jitCompilers/binary/toBinary.d.ts +1 -0
  20. package/.dist/cjs/src/jitCompilers/binary/toBinary.d.ts.map +1 -0
  21. package/.dist/cjs/src/jitCompilers/equalsHelpers.d.ts +1 -0
  22. package/.dist/cjs/src/jitCompilers/equalsHelpers.d.ts.map +1 -0
  23. package/.dist/cjs/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts +1 -0
  24. package/.dist/cjs/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts.map +1 -0
  25. package/.dist/cjs/src/jitCompilers/json/stringifyJson.d.ts +1 -0
  26. package/.dist/cjs/src/jitCompilers/json/stringifyJson.d.ts.map +1 -0
  27. package/.dist/cjs/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts +1 -0
  28. package/.dist/cjs/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts.map +1 -0
  29. package/.dist/cjs/src/jitCompilers/json/toJsCode.d.ts +1 -0
  30. package/.dist/cjs/src/jitCompilers/json/toJsCode.d.ts.map +1 -0
  31. package/.dist/cjs/src/lib/baseRunTypeFormat.d.ts +1 -0
  32. package/.dist/cjs/src/lib/baseRunTypeFormat.d.ts.map +1 -0
  33. package/.dist/cjs/src/lib/baseRunTypes.d.ts +1 -0
  34. package/.dist/cjs/src/lib/baseRunTypes.d.ts.map +1 -0
  35. package/.dist/cjs/src/lib/createJitFunction.d.ts +1 -0
  36. package/.dist/cjs/src/lib/createJitFunction.d.ts.map +1 -0
  37. package/.dist/cjs/src/lib/dkProxy.d.ts +1 -0
  38. package/.dist/cjs/src/lib/dkProxy.d.ts.map +1 -0
  39. package/.dist/cjs/src/lib/formats.d.ts +1 -0
  40. package/.dist/cjs/src/lib/formats.d.ts.map +1 -0
  41. package/.dist/cjs/src/lib/guards.d.ts +1 -0
  42. package/.dist/cjs/src/lib/guards.d.ts.map +1 -0
  43. package/.dist/cjs/src/lib/jitFnCompiler.d.ts +1 -0
  44. package/.dist/cjs/src/lib/jitFnCompiler.d.ts.map +1 -0
  45. package/.dist/cjs/src/lib/jitFnsRegistry.d.ts +1 -0
  46. package/.dist/cjs/src/lib/jitFnsRegistry.d.ts.map +1 -0
  47. package/.dist/cjs/src/lib/typeId.d.ts +1 -0
  48. package/.dist/cjs/src/lib/typeId.d.ts.map +1 -0
  49. package/.dist/cjs/src/lib/utils.d.ts +1 -0
  50. package/.dist/cjs/src/lib/utils.d.ts.map +1 -0
  51. package/.dist/cjs/src/mocking/constants.mock.d.ts +1 -0
  52. package/.dist/cjs/src/mocking/constants.mock.d.ts.map +1 -0
  53. package/.dist/cjs/src/mocking/mockRegistry.d.ts +1 -0
  54. package/.dist/cjs/src/mocking/mockRegistry.d.ts.map +1 -0
  55. package/.dist/cjs/src/mocking/mockType.d.ts +1 -0
  56. package/.dist/cjs/src/mocking/mockType.d.ts.map +1 -0
  57. package/.dist/cjs/src/mocking/mockUtils.d.ts +1 -0
  58. package/.dist/cjs/src/mocking/mockUtils.d.ts.map +1 -0
  59. package/.dist/cjs/src/nodes/atomic/any.d.ts +1 -0
  60. package/.dist/cjs/src/nodes/atomic/any.d.ts.map +1 -0
  61. package/.dist/cjs/src/nodes/atomic/bigInt.d.ts +1 -0
  62. package/.dist/cjs/src/nodes/atomic/bigInt.d.ts.map +1 -0
  63. package/.dist/cjs/src/nodes/atomic/boolean.d.ts +1 -0
  64. package/.dist/cjs/src/nodes/atomic/boolean.d.ts.map +1 -0
  65. package/.dist/cjs/src/nodes/atomic/date.d.ts +1 -0
  66. package/.dist/cjs/src/nodes/atomic/date.d.ts.map +1 -0
  67. package/.dist/cjs/src/nodes/atomic/enum.d.ts +1 -0
  68. package/.dist/cjs/src/nodes/atomic/enum.d.ts.map +1 -0
  69. package/.dist/cjs/src/nodes/atomic/enumMember.d.ts +1 -0
  70. package/.dist/cjs/src/nodes/atomic/enumMember.d.ts.map +1 -0
  71. package/.dist/cjs/src/nodes/atomic/literal.d.ts +1 -0
  72. package/.dist/cjs/src/nodes/atomic/literal.d.ts.map +1 -0
  73. package/.dist/cjs/src/nodes/atomic/never.d.ts +1 -0
  74. package/.dist/cjs/src/nodes/atomic/never.d.ts.map +1 -0
  75. package/.dist/cjs/src/nodes/atomic/null.d.ts +1 -0
  76. package/.dist/cjs/src/nodes/atomic/null.d.ts.map +1 -0
  77. package/.dist/cjs/src/nodes/atomic/number.d.ts +1 -0
  78. package/.dist/cjs/src/nodes/atomic/number.d.ts.map +1 -0
  79. package/.dist/cjs/src/nodes/atomic/object.d.ts +1 -0
  80. package/.dist/cjs/src/nodes/atomic/object.d.ts.map +1 -0
  81. package/.dist/cjs/src/nodes/atomic/regexp.d.ts +1 -0
  82. package/.dist/cjs/src/nodes/atomic/regexp.d.ts.map +1 -0
  83. package/.dist/cjs/src/nodes/atomic/string.d.ts +1 -0
  84. package/.dist/cjs/src/nodes/atomic/string.d.ts.map +1 -0
  85. package/.dist/cjs/src/nodes/atomic/symbol.d.ts +1 -0
  86. package/.dist/cjs/src/nodes/atomic/symbol.d.ts.map +1 -0
  87. package/.dist/cjs/src/nodes/atomic/undefined.d.ts +1 -0
  88. package/.dist/cjs/src/nodes/atomic/undefined.d.ts.map +1 -0
  89. package/.dist/cjs/src/nodes/atomic/unknown.d.ts +1 -0
  90. package/.dist/cjs/src/nodes/atomic/unknown.d.ts.map +1 -0
  91. package/.dist/cjs/src/nodes/atomic/void.d.ts +1 -0
  92. package/.dist/cjs/src/nodes/atomic/void.d.ts.map +1 -0
  93. package/.dist/cjs/src/nodes/collection/class.d.ts +1 -0
  94. package/.dist/cjs/src/nodes/collection/class.d.ts.map +1 -0
  95. package/.dist/cjs/src/nodes/collection/functionParams.d.ts +1 -0
  96. package/.dist/cjs/src/nodes/collection/functionParams.d.ts.map +1 -0
  97. package/.dist/cjs/src/nodes/collection/interface.d.ts +1 -0
  98. package/.dist/cjs/src/nodes/collection/interface.d.ts.map +1 -0
  99. package/.dist/cjs/src/nodes/collection/intersection.d.ts +1 -0
  100. package/.dist/cjs/src/nodes/collection/intersection.d.ts.map +1 -0
  101. package/.dist/cjs/src/nodes/collection/tuple.d.ts +1 -0
  102. package/.dist/cjs/src/nodes/collection/tuple.d.ts.map +1 -0
  103. package/.dist/cjs/src/nodes/collection/union.d.ts +1 -0
  104. package/.dist/cjs/src/nodes/collection/union.d.ts.map +1 -0
  105. package/.dist/cjs/src/nodes/collection/unionDiscriminator.d.ts +1 -0
  106. package/.dist/cjs/src/nodes/collection/unionDiscriminator.d.ts.map +1 -0
  107. package/.dist/cjs/src/nodes/function/function.d.ts +1 -0
  108. package/.dist/cjs/src/nodes/function/function.d.ts.map +1 -0
  109. package/.dist/cjs/src/nodes/member/array.d.ts +1 -0
  110. package/.dist/cjs/src/nodes/member/array.d.ts.map +1 -0
  111. package/.dist/cjs/src/nodes/member/callSignature.d.ts +1 -0
  112. package/.dist/cjs/src/nodes/member/callSignature.d.ts.map +1 -0
  113. package/.dist/cjs/src/nodes/member/genericMember.d.ts +1 -0
  114. package/.dist/cjs/src/nodes/member/genericMember.d.ts.map +1 -0
  115. package/.dist/cjs/src/nodes/member/indexProperty.d.ts +1 -0
  116. package/.dist/cjs/src/nodes/member/indexProperty.d.ts.map +1 -0
  117. package/.dist/cjs/src/nodes/member/method.d.ts +1 -0
  118. package/.dist/cjs/src/nodes/member/method.d.ts.map +1 -0
  119. package/.dist/cjs/src/nodes/member/methodSignature.d.ts +1 -0
  120. package/.dist/cjs/src/nodes/member/methodSignature.d.ts.map +1 -0
  121. package/.dist/cjs/src/nodes/member/param.d.ts +1 -0
  122. package/.dist/cjs/src/nodes/member/param.d.ts.map +1 -0
  123. package/.dist/cjs/src/nodes/member/property.d.ts +1 -0
  124. package/.dist/cjs/src/nodes/member/property.d.ts.map +1 -0
  125. package/.dist/cjs/src/nodes/member/restParams.d.ts +1 -0
  126. package/.dist/cjs/src/nodes/member/restParams.d.ts.map +1 -0
  127. package/.dist/cjs/src/nodes/member/tupleMember.d.ts +1 -0
  128. package/.dist/cjs/src/nodes/member/tupleMember.d.ts.map +1 -0
  129. package/.dist/cjs/src/nodes/native/Iterable.d.ts +1 -0
  130. package/.dist/cjs/src/nodes/native/Iterable.d.ts.map +1 -0
  131. package/.dist/cjs/src/nodes/native/map.d.ts +1 -0
  132. package/.dist/cjs/src/nodes/native/map.d.ts.map +1 -0
  133. package/.dist/cjs/src/nodes/native/nonSerializable.d.ts +1 -0
  134. package/.dist/cjs/src/nodes/native/nonSerializable.d.ts.map +1 -0
  135. package/.dist/cjs/src/nodes/native/promise.d.ts +1 -0
  136. package/.dist/cjs/src/nodes/native/promise.d.ts.map +1 -0
  137. package/.dist/cjs/src/nodes/native/set.d.ts +1 -0
  138. package/.dist/cjs/src/nodes/native/set.d.ts.map +1 -0
  139. package/.dist/cjs/src/run-types-pure-fns.d.ts +1 -0
  140. package/.dist/cjs/src/run-types-pure-fns.d.ts.map +1 -0
  141. package/.dist/cjs/src/types.d.ts +1 -0
  142. package/.dist/cjs/src/types.d.ts.map +1 -0
  143. package/.dist/esm/index.d.ts +1 -0
  144. package/.dist/esm/index.d.ts.map +1 -0
  145. package/.dist/esm/src/constants.d.ts +1 -0
  146. package/.dist/esm/src/constants.d.ts.map +1 -0
  147. package/.dist/esm/src/constants.functions.d.ts +1 -0
  148. package/.dist/esm/src/constants.functions.d.ts.map +1 -0
  149. package/.dist/esm/src/constants.kind.d.ts +1 -0
  150. package/.dist/esm/src/constants.kind.d.ts.map +1 -0
  151. package/.dist/esm/src/createRunType.d.ts +1 -0
  152. package/.dist/esm/src/createRunType.d.ts.map +1 -0
  153. package/.dist/esm/src/createRunTypeFunctions.d.ts +1 -0
  154. package/.dist/esm/src/createRunTypeFunctions.d.ts.map +1 -0
  155. package/.dist/esm/src/formats.runtype.d.ts +1 -0
  156. package/.dist/esm/src/formats.runtype.d.ts.map +1 -0
  157. package/.dist/esm/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts +1 -0
  158. package/.dist/esm/src/jitCompilers/binary/binarySpec/binaryHelpers.d.ts.map +1 -0
  159. package/.dist/esm/src/jitCompilers/binary/fromBinary.d.ts +1 -0
  160. package/.dist/esm/src/jitCompilers/binary/fromBinary.d.ts.map +1 -0
  161. package/.dist/esm/src/jitCompilers/binary/toBinary.d.ts +1 -0
  162. package/.dist/esm/src/jitCompilers/binary/toBinary.d.ts.map +1 -0
  163. package/.dist/esm/src/jitCompilers/equalsHelpers.d.ts +1 -0
  164. package/.dist/esm/src/jitCompilers/equalsHelpers.d.ts.map +1 -0
  165. package/.dist/esm/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts +1 -0
  166. package/.dist/esm/src/jitCompilers/json/jsonSpec/jsonHelpers.d.ts.map +1 -0
  167. package/.dist/esm/src/jitCompilers/json/stringifyJson.d.ts +1 -0
  168. package/.dist/esm/src/jitCompilers/json/stringifyJson.d.ts.map +1 -0
  169. package/.dist/esm/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts +1 -0
  170. package/.dist/esm/src/jitCompilers/json/stringifySpec/stringifyHelpers.d.ts.map +1 -0
  171. package/.dist/esm/src/jitCompilers/json/toJsCode.d.ts +1 -0
  172. package/.dist/esm/src/jitCompilers/json/toJsCode.d.ts.map +1 -0
  173. package/.dist/esm/src/lib/baseRunTypeFormat.d.ts +1 -0
  174. package/.dist/esm/src/lib/baseRunTypeFormat.d.ts.map +1 -0
  175. package/.dist/esm/src/lib/baseRunTypes.d.ts +1 -0
  176. package/.dist/esm/src/lib/baseRunTypes.d.ts.map +1 -0
  177. package/.dist/esm/src/lib/createJitFunction.d.ts +1 -0
  178. package/.dist/esm/src/lib/createJitFunction.d.ts.map +1 -0
  179. package/.dist/esm/src/lib/dkProxy.d.ts +1 -0
  180. package/.dist/esm/src/lib/dkProxy.d.ts.map +1 -0
  181. package/.dist/esm/src/lib/formats.d.ts +1 -0
  182. package/.dist/esm/src/lib/formats.d.ts.map +1 -0
  183. package/.dist/esm/src/lib/guards.d.ts +1 -0
  184. package/.dist/esm/src/lib/guards.d.ts.map +1 -0
  185. package/.dist/esm/src/lib/jitFnCompiler.d.ts +1 -0
  186. package/.dist/esm/src/lib/jitFnCompiler.d.ts.map +1 -0
  187. package/.dist/esm/src/lib/jitFnsRegistry.d.ts +1 -0
  188. package/.dist/esm/src/lib/jitFnsRegistry.d.ts.map +1 -0
  189. package/.dist/esm/src/lib/typeId.d.ts +1 -0
  190. package/.dist/esm/src/lib/typeId.d.ts.map +1 -0
  191. package/.dist/esm/src/lib/utils.d.ts +1 -0
  192. package/.dist/esm/src/lib/utils.d.ts.map +1 -0
  193. package/.dist/esm/src/mocking/constants.mock.d.ts +1 -0
  194. package/.dist/esm/src/mocking/constants.mock.d.ts.map +1 -0
  195. package/.dist/esm/src/mocking/mockRegistry.d.ts +1 -0
  196. package/.dist/esm/src/mocking/mockRegistry.d.ts.map +1 -0
  197. package/.dist/esm/src/mocking/mockType.d.ts +1 -0
  198. package/.dist/esm/src/mocking/mockType.d.ts.map +1 -0
  199. package/.dist/esm/src/mocking/mockUtils.d.ts +1 -0
  200. package/.dist/esm/src/mocking/mockUtils.d.ts.map +1 -0
  201. package/.dist/esm/src/nodes/atomic/any.d.ts +1 -0
  202. package/.dist/esm/src/nodes/atomic/any.d.ts.map +1 -0
  203. package/.dist/esm/src/nodes/atomic/bigInt.d.ts +1 -0
  204. package/.dist/esm/src/nodes/atomic/bigInt.d.ts.map +1 -0
  205. package/.dist/esm/src/nodes/atomic/boolean.d.ts +1 -0
  206. package/.dist/esm/src/nodes/atomic/boolean.d.ts.map +1 -0
  207. package/.dist/esm/src/nodes/atomic/date.d.ts +1 -0
  208. package/.dist/esm/src/nodes/atomic/date.d.ts.map +1 -0
  209. package/.dist/esm/src/nodes/atomic/enum.d.ts +1 -0
  210. package/.dist/esm/src/nodes/atomic/enum.d.ts.map +1 -0
  211. package/.dist/esm/src/nodes/atomic/enumMember.d.ts +1 -0
  212. package/.dist/esm/src/nodes/atomic/enumMember.d.ts.map +1 -0
  213. package/.dist/esm/src/nodes/atomic/literal.d.ts +1 -0
  214. package/.dist/esm/src/nodes/atomic/literal.d.ts.map +1 -0
  215. package/.dist/esm/src/nodes/atomic/never.d.ts +1 -0
  216. package/.dist/esm/src/nodes/atomic/never.d.ts.map +1 -0
  217. package/.dist/esm/src/nodes/atomic/null.d.ts +1 -0
  218. package/.dist/esm/src/nodes/atomic/null.d.ts.map +1 -0
  219. package/.dist/esm/src/nodes/atomic/number.d.ts +1 -0
  220. package/.dist/esm/src/nodes/atomic/number.d.ts.map +1 -0
  221. package/.dist/esm/src/nodes/atomic/object.d.ts +1 -0
  222. package/.dist/esm/src/nodes/atomic/object.d.ts.map +1 -0
  223. package/.dist/esm/src/nodes/atomic/regexp.d.ts +1 -0
  224. package/.dist/esm/src/nodes/atomic/regexp.d.ts.map +1 -0
  225. package/.dist/esm/src/nodes/atomic/string.d.ts +1 -0
  226. package/.dist/esm/src/nodes/atomic/string.d.ts.map +1 -0
  227. package/.dist/esm/src/nodes/atomic/symbol.d.ts +1 -0
  228. package/.dist/esm/src/nodes/atomic/symbol.d.ts.map +1 -0
  229. package/.dist/esm/src/nodes/atomic/undefined.d.ts +1 -0
  230. package/.dist/esm/src/nodes/atomic/undefined.d.ts.map +1 -0
  231. package/.dist/esm/src/nodes/atomic/unknown.d.ts +1 -0
  232. package/.dist/esm/src/nodes/atomic/unknown.d.ts.map +1 -0
  233. package/.dist/esm/src/nodes/atomic/void.d.ts +1 -0
  234. package/.dist/esm/src/nodes/atomic/void.d.ts.map +1 -0
  235. package/.dist/esm/src/nodes/collection/class.d.ts +1 -0
  236. package/.dist/esm/src/nodes/collection/class.d.ts.map +1 -0
  237. package/.dist/esm/src/nodes/collection/functionParams.d.ts +1 -0
  238. package/.dist/esm/src/nodes/collection/functionParams.d.ts.map +1 -0
  239. package/.dist/esm/src/nodes/collection/interface.d.ts +1 -0
  240. package/.dist/esm/src/nodes/collection/interface.d.ts.map +1 -0
  241. package/.dist/esm/src/nodes/collection/intersection.d.ts +1 -0
  242. package/.dist/esm/src/nodes/collection/intersection.d.ts.map +1 -0
  243. package/.dist/esm/src/nodes/collection/tuple.d.ts +1 -0
  244. package/.dist/esm/src/nodes/collection/tuple.d.ts.map +1 -0
  245. package/.dist/esm/src/nodes/collection/union.d.ts +1 -0
  246. package/.dist/esm/src/nodes/collection/union.d.ts.map +1 -0
  247. package/.dist/esm/src/nodes/collection/unionDiscriminator.d.ts +1 -0
  248. package/.dist/esm/src/nodes/collection/unionDiscriminator.d.ts.map +1 -0
  249. package/.dist/esm/src/nodes/function/function.d.ts +1 -0
  250. package/.dist/esm/src/nodes/function/function.d.ts.map +1 -0
  251. package/.dist/esm/src/nodes/member/array.d.ts +1 -0
  252. package/.dist/esm/src/nodes/member/array.d.ts.map +1 -0
  253. package/.dist/esm/src/nodes/member/callSignature.d.ts +1 -0
  254. package/.dist/esm/src/nodes/member/callSignature.d.ts.map +1 -0
  255. package/.dist/esm/src/nodes/member/genericMember.d.ts +1 -0
  256. package/.dist/esm/src/nodes/member/genericMember.d.ts.map +1 -0
  257. package/.dist/esm/src/nodes/member/indexProperty.d.ts +1 -0
  258. package/.dist/esm/src/nodes/member/indexProperty.d.ts.map +1 -0
  259. package/.dist/esm/src/nodes/member/method.d.ts +1 -0
  260. package/.dist/esm/src/nodes/member/method.d.ts.map +1 -0
  261. package/.dist/esm/src/nodes/member/methodSignature.d.ts +1 -0
  262. package/.dist/esm/src/nodes/member/methodSignature.d.ts.map +1 -0
  263. package/.dist/esm/src/nodes/member/param.d.ts +1 -0
  264. package/.dist/esm/src/nodes/member/param.d.ts.map +1 -0
  265. package/.dist/esm/src/nodes/member/property.d.ts +1 -0
  266. package/.dist/esm/src/nodes/member/property.d.ts.map +1 -0
  267. package/.dist/esm/src/nodes/member/restParams.d.ts +1 -0
  268. package/.dist/esm/src/nodes/member/restParams.d.ts.map +1 -0
  269. package/.dist/esm/src/nodes/member/tupleMember.d.ts +1 -0
  270. package/.dist/esm/src/nodes/member/tupleMember.d.ts.map +1 -0
  271. package/.dist/esm/src/nodes/native/Iterable.d.ts +1 -0
  272. package/.dist/esm/src/nodes/native/Iterable.d.ts.map +1 -0
  273. package/.dist/esm/src/nodes/native/map.d.ts +1 -0
  274. package/.dist/esm/src/nodes/native/map.d.ts.map +1 -0
  275. package/.dist/esm/src/nodes/native/nonSerializable.d.ts +1 -0
  276. package/.dist/esm/src/nodes/native/nonSerializable.d.ts.map +1 -0
  277. package/.dist/esm/src/nodes/native/promise.d.ts +1 -0
  278. package/.dist/esm/src/nodes/native/promise.d.ts.map +1 -0
  279. package/.dist/esm/src/nodes/native/set.d.ts +1 -0
  280. package/.dist/esm/src/nodes/native/set.d.ts.map +1 -0
  281. package/.dist/esm/src/run-types-pure-fns.d.ts +1 -0
  282. package/.dist/esm/src/run-types-pure-fns.d.ts.map +1 -0
  283. package/.dist/esm/src/types.d.ts +1 -0
  284. package/.dist/esm/src/types.d.ts.map +1 -0
  285. package/index.ts +70 -0
  286. package/package.json +8 -4
  287. package/src/constants.functions.ts +196 -0
  288. package/src/constants.kind.ts +76 -0
  289. package/src/constants.ts +85 -0
  290. package/src/createRunType.ts +323 -0
  291. package/src/createRunTypeFunctions.ts +93 -0
  292. package/src/formats.runtype.ts +35 -0
  293. package/src/jitCompilers/binary/binarySPEC.md +138 -0
  294. package/src/jitCompilers/binary/binarySpec/binaryHelpers.ts +118 -0
  295. package/src/jitCompilers/binary/fromBinary.ts +492 -0
  296. package/src/jitCompilers/binary/toBinary.ts +435 -0
  297. package/src/jitCompilers/equalsHelpers.ts +62 -0
  298. package/src/jitCompilers/json/jsonSpec/jsonHelpers.ts +64 -0
  299. package/src/jitCompilers/json/stringifyJson.ts +475 -0
  300. package/src/jitCompilers/json/stringifySpec/stringifyHelpers.ts +59 -0
  301. package/src/jitCompilers/json/toJsCode.ts +182 -0
  302. package/src/jitCompilers/serialization-suite.ts +1637 -0
  303. package/src/jitCompilers/xyz-Template/fromXYZ.ts +211 -0
  304. package/src/jitCompilers/xyz-Template/toXYZ.ts +216 -0
  305. package/src/jitCompilers/xyz-Template/xyzReadme.md +6 -0
  306. package/src/jitCompilers/xyz-Template/xyzSpec/xyzHelpers.ts +66 -0
  307. package/src/lib/baseRunTypeFormat.ts +320 -0
  308. package/src/lib/baseRunTypes.ts +367 -0
  309. package/src/lib/createJitFunction.ts +87 -0
  310. package/src/lib/dkProxy.ts +47 -0
  311. package/src/lib/formats.ts +144 -0
  312. package/src/lib/guards.ts +290 -0
  313. package/src/lib/jitFnCompiler.ts +783 -0
  314. package/src/lib/jitFnsRegistry.ts +53 -0
  315. package/src/lib/typeId.ts +225 -0
  316. package/src/lib/utils.ts +402 -0
  317. package/src/mocking/constants.mock.ts +87 -0
  318. package/src/mocking/mockRegistry.ts +20 -0
  319. package/src/mocking/mockType.ts +354 -0
  320. package/src/mocking/mockUtils.ts +82 -0
  321. package/src/nodes/atomic/any.ts +22 -0
  322. package/src/nodes/atomic/bigInt.ts +26 -0
  323. package/src/nodes/atomic/boolean.ts +26 -0
  324. package/src/nodes/atomic/date.ts +26 -0
  325. package/src/nodes/atomic/enum.ts +23 -0
  326. package/src/nodes/atomic/enumMember.ts +29 -0
  327. package/src/nodes/atomic/literal.ts +125 -0
  328. package/src/nodes/atomic/never.ts +26 -0
  329. package/src/nodes/atomic/null.ts +26 -0
  330. package/src/nodes/atomic/number.ts +26 -0
  331. package/src/nodes/atomic/object.ts +20 -0
  332. package/src/nodes/atomic/regexp.ts +29 -0
  333. package/src/nodes/atomic/string.ts +20 -0
  334. package/src/nodes/atomic/symbol.ts +31 -0
  335. package/src/nodes/atomic/undefined.ts +23 -0
  336. package/src/nodes/atomic/unknown.ts +10 -0
  337. package/src/nodes/atomic/void.ts +26 -0
  338. package/src/nodes/collection/class.ts +36 -0
  339. package/src/nodes/collection/functionParams.ts +42 -0
  340. package/src/nodes/collection/interface.ts +300 -0
  341. package/src/nodes/collection/intersection.ts +30 -0
  342. package/src/nodes/collection/tuple.ts +80 -0
  343. package/src/nodes/collection/union.ts +205 -0
  344. package/src/nodes/collection/unionDiscriminator.ts +259 -0
  345. package/src/nodes/function/function.ts +166 -0
  346. package/src/nodes/member/array.ts +150 -0
  347. package/src/nodes/member/callSignature.ts +34 -0
  348. package/src/nodes/member/genericMember.ts +63 -0
  349. package/src/nodes/member/indexProperty.ts +125 -0
  350. package/src/nodes/member/method.ts +30 -0
  351. package/src/nodes/member/methodSignature.ts +31 -0
  352. package/src/nodes/member/param.ts +22 -0
  353. package/src/nodes/member/property.ts +75 -0
  354. package/src/nodes/member/restParams.ts +22 -0
  355. package/src/nodes/member/tupleMember.ts +93 -0
  356. package/src/nodes/native/Iterable.ts +153 -0
  357. package/src/nodes/native/map.ts +91 -0
  358. package/src/nodes/native/nonSerializable.ts +42 -0
  359. package/src/nodes/native/promise.ts +43 -0
  360. package/src/nodes/native/set.ts +56 -0
  361. package/src/run-types-pure-fns.ts +116 -0
  362. package/src/types.ts +206 -0
@@ -0,0 +1,53 @@
1
+ /* ########
2
+ * 2025 mion
3
+ * Author: Ma-jerez
4
+ * License: MIT
5
+ * The software is provided "as is", without warranty of any kind.
6
+ * ######## */
7
+
8
+ import type {JitFnID} from '../types.ts';
9
+ import {JitFnSettings, jitFunctionList, jitFunctionsById} from '../constants.functions.ts';
10
+
11
+ type resolvedCompiler = {
12
+ jitFnSettings: JitFnSettings;
13
+ compiler: (...args: any[]) => any;
14
+ };
15
+
16
+ const jitFunctionsRegistry: Map<string, resolvedCompiler> = new Map();
17
+ const nativeIds: Set<string> = new Set(jitFunctionList.filter((f) => !f.import).map((f) => f.id));
18
+
19
+ export async function registerJitFunctionCompiler(jitFnSettings: JitFnSettings): Promise<(...args: any[]) => any> {
20
+ const existing = jitFunctionsRegistry.get(jitFnSettings.id);
21
+ if (nativeIds.has(jitFnSettings.id))
22
+ throw new Error(`Jit function ${jitFnSettings.name} is native and can not be registered`);
23
+ if (existing) return existing.compiler;
24
+ if (!jitFnSettings.import) throw new Error(`Jit function ${jitFnSettings.name} has no import function`);
25
+ try {
26
+ const newFn = await jitFnSettings.import();
27
+ jitFunctionsRegistry.set(jitFnSettings.id, {
28
+ jitFnSettings: jitFnSettings,
29
+ compiler: newFn,
30
+ });
31
+ return newFn;
32
+ } catch (e: any) {
33
+ console.warn(e);
34
+ throw new Error(`Error loading jit function ${jitFnSettings.name}: ${e?.message}`);
35
+ }
36
+ }
37
+
38
+ /** synchronous version of loadRegisteredFunction, throws an error if the function has not been loaded */
39
+ export function getJitFunctionCompiler(jitFnSettings: JitFnSettings): (...args: any[]) => any {
40
+ const existing = jitFunctionsRegistry.get(jitFnSettings.id);
41
+ if (existing) return existing.compiler;
42
+ throw new Error(`Function ${jitFnSettings.name} has not been loaded.`);
43
+ }
44
+
45
+ export function getJitFnSettings(fnID: JitFnID): JitFnSettings {
46
+ const fnConfig = jitFunctionsById[fnID] || jitFunctionsRegistry.get(fnID)?.jitFnSettings;
47
+ if (fnConfig === undefined) throw new Error(`Unknown jit function id: ${fnID}`);
48
+ return fnConfig;
49
+ }
50
+
51
+ export function getJITFnName(fnID: JitFnID): string {
52
+ return getJitFnSettings(fnID).name;
53
+ }
@@ -0,0 +1,225 @@
1
+ /* ########
2
+ * 2024 mion
3
+ * Author: Ma-jerez
4
+ * License: MIT
5
+ * The software is provided "as is", without warranty of any kind.
6
+ * ######## */
7
+
8
+ import {Type, TypeIndexSignature, TypeProperty, ReflectionKind, TypeClass, typeAnnotation} from '@deepkit/type';
9
+ import {MAX_STACK_DEPTH, TypeFormatParams} from '@mionjs/core';
10
+ import {ReflectionSubKind} from '../constants.kind.ts';
11
+ import {hasType, hasTypes, hasParameters} from './guards.ts';
12
+ import {getFormatterFromCache, defaultIgnoreFormatProps} from './formats.ts';
13
+ import {typeParamsToString} from './utils.ts';
14
+ import type {FormatAnnotation, SrcType, StrNumber} from '../types.ts';
15
+
16
+ /** Type with optional cached _typeId and _formatId properties - compatible with SrcType */
17
+ export type TypeWithCachedIds = Type & Pick<Partial<SrcType>, '_typeId' | '_formatId'>;
18
+
19
+ /** Generates a unique type ID directly from a deepkit Type object. Caches result in type._typeId */
20
+ export function createTypeId(type: TypeWithCachedIds, stack: Type[] = []): StrNumber {
21
+ if (type._typeId !== undefined) return type._typeId;
22
+ const typeId = _createTypeId(type, stack);
23
+ (type as any)._typeId = typeId;
24
+ return typeId;
25
+ }
26
+
27
+ function _createTypeId(type: Type, stack: Type[]): StrNumber {
28
+ if (stack.length > MAX_STACK_DEPTH) {
29
+ throw new Error(`Max stack depth exceeded while computing type ID. This usually indicates a circular type reference.`);
30
+ }
31
+ const circularId = checkCircularAndGetRefId(type, stack);
32
+ if (circularId !== undefined) return circularId;
33
+ const kind = (type as any).subKind || type.kind;
34
+ const baseTypeId = computeBaseTypeId(type, kind, stack);
35
+ const formatId = computeDeepkitFormatID(type as TypeWithCachedIds);
36
+ if (formatId) return `${baseTypeId}${formatId}`;
37
+ return baseTypeId;
38
+ }
39
+
40
+ function computeBaseTypeId(type: Type, kind: number, stack: Type[]): StrNumber {
41
+ const subKind = (type as any).subKind;
42
+ if (subKind === ReflectionSubKind.params) return computeParamsTypeId(type, stack);
43
+
44
+ switch (type.kind) {
45
+ // Atomic types - just return the kind
46
+ case ReflectionKind.any:
47
+ case ReflectionKind.bigint:
48
+ case ReflectionKind.boolean:
49
+ case ReflectionKind.never:
50
+ case ReflectionKind.null:
51
+ case ReflectionKind.number:
52
+ case ReflectionKind.object:
53
+ case ReflectionKind.regexp:
54
+ case ReflectionKind.string:
55
+ case ReflectionKind.symbol:
56
+ case ReflectionKind.undefined:
57
+ case ReflectionKind.unknown:
58
+ case ReflectionKind.void:
59
+ case ReflectionKind.enum:
60
+ case ReflectionKind.enumMember:
61
+ case ReflectionKind.promise:
62
+ return kind;
63
+ case ReflectionKind.literal: {
64
+ const literal = (type as any).literal;
65
+ return `${kind}:${String(literal)}`;
66
+ }
67
+ // Collection types - contain multiple child types
68
+ case ReflectionKind.union:
69
+ case ReflectionKind.intersection:
70
+ case ReflectionKind.objectLiteral:
71
+ case ReflectionKind.tuple:
72
+ return computeCollectionTypeId(type, stack);
73
+ // Member types - contain a single child type
74
+ case ReflectionKind.array:
75
+ case ReflectionKind.property:
76
+ case ReflectionKind.propertySignature:
77
+ case ReflectionKind.tupleMember:
78
+ case ReflectionKind.parameter:
79
+ case ReflectionKind.rest:
80
+ case ReflectionKind.indexSignature:
81
+ return computeMemberTypeId(type, stack);
82
+ // Function types
83
+ case ReflectionKind.function: {
84
+ const parent = type.parent;
85
+ const name = (type as any).name;
86
+ if (name && parent && (parent.kind === ReflectionKind.objectLiteral || parent.kind === ReflectionKind.class)) {
87
+ return `${ReflectionKind.function}${String(name)}`;
88
+ }
89
+ return ReflectionKind.function;
90
+ }
91
+ case ReflectionKind.method:
92
+ case ReflectionKind.methodSignature:
93
+ case ReflectionKind.callSignature:
94
+ return computeFunctionTypeId(type);
95
+ // Class types
96
+ case ReflectionKind.class:
97
+ return computeClassTypeId(type as TypeClass, stack);
98
+ default:
99
+ if (hasTypes(type)) return computeCollectionTypeId(type, stack);
100
+ if (hasType(type)) return computeMemberTypeId(type, stack);
101
+ return kind;
102
+ }
103
+ }
104
+
105
+ function computeCollectionTypeId(type: Type, stack: Type[]): StrNumber {
106
+ const types = (type as any).types as Type[] | undefined;
107
+ if (!Array.isArray(types)) return (type as any).subKind || type.kind;
108
+ stack.push(type);
109
+ const childIds: StrNumber[] = [];
110
+ for (const childType of types) childIds.push(_createTypeId(childType, stack));
111
+ stack.pop();
112
+ const isTuple = type.kind === ReflectionKind.tuple;
113
+ const groupID = isTuple ? `[${childIds.join(',')}]` : `{${childIds.join(',')}}`;
114
+ const kind = (type as any).subKind || type.kind;
115
+ return `${kind}${groupID}`;
116
+ }
117
+
118
+ function computeMemberTypeId(type: Type, stack: Type[]): StrNumber {
119
+ const memberType = (type as any).type as Type | undefined;
120
+ if (!memberType || typeof memberType.kind !== 'number') return (type as any).subKind || type.kind;
121
+ const isRest = memberType.kind === ReflectionKind.rest;
122
+ const isTupleParam = type.kind === ReflectionKind.tupleMember || type.kind === ReflectionKind.parameter;
123
+ const hasDefault = isTupleParam && (type as any).default !== undefined;
124
+ const optional = (type as any).optional || type.kind === ReflectionKind.indexSignature || isRest || hasDefault ? '?' : '';
125
+ const propName =
126
+ (type as TypeProperty).name?.toString() || (type as TypeIndexSignature).index?.kind || (type as any).subKind || type.kind;
127
+ const kindID = `${propName}${optional}`;
128
+ const circularId = checkCircularAndGetRefId(type, stack);
129
+ if (circularId) return `${kindID}:${circularId}`;
130
+ stack.push(type);
131
+ const memberTypeId = _createTypeId(memberType, stack);
132
+ stack.pop();
133
+ return `${kindID}:${memberTypeId}`;
134
+ }
135
+
136
+ function computeFunctionTypeId(type: Type): StrNumber {
137
+ const kind = ReflectionKind.function;
138
+ const parent = type.parent;
139
+ const name = (type as any).name;
140
+ let baseId: string;
141
+ if (name && parent && (parent.kind === ReflectionKind.objectLiteral || parent.kind === ReflectionKind.class)) {
142
+ baseId = `${kind}${String(name)}`;
143
+ } else {
144
+ baseId = String(kind);
145
+ }
146
+ const isOptional = !!(type as any).optional;
147
+ return isOptional ? `${baseId}:?` : baseId;
148
+ }
149
+
150
+ function computeClassTypeId(type: TypeClass, stack: Type[]): StrNumber {
151
+ if (type.classType === Date) return ReflectionSubKind.date;
152
+ if (type.classType === Map) {
153
+ const args = type.arguments;
154
+ if (!args || args.length !== 2) return ReflectionSubKind.map;
155
+ stack.push(type);
156
+ const keyTypeId = _createTypeId(args[0], stack);
157
+ const valueTypeId = _createTypeId(args[1], stack);
158
+ stack.pop();
159
+ return `${ReflectionSubKind.map}{${ReflectionSubKind.mapKey}:${keyTypeId},${ReflectionSubKind.mapValue}:${valueTypeId}}`;
160
+ }
161
+ if (type.classType === Set) {
162
+ const args = type.arguments;
163
+ if (!args || args.length !== 1) return ReflectionSubKind.set;
164
+ stack.push(type);
165
+ const itemTypeId = _createTypeId(args[0], stack);
166
+ stack.pop();
167
+ return `${ReflectionSubKind.set}{${ReflectionSubKind.setItem}:${itemTypeId}}`;
168
+ }
169
+ const kind = (type as any).subKind || type.kind;
170
+ const types = (type as any).types as Type[] | undefined;
171
+ if (Array.isArray(types) && types.length > 0) {
172
+ stack.push(type);
173
+ const childIds = types.map((t) => _createTypeId(t, stack));
174
+ stack.pop();
175
+ return `${kind}{${childIds.join(',')}}`;
176
+ }
177
+ return kind;
178
+ }
179
+
180
+ function computeParamsTypeId(type: Type, stack: Type[]): StrNumber {
181
+ if (!hasParameters(type)) return (type as any).subKind || type.kind;
182
+ const circularId = checkCircularAndGetRefId(type, stack);
183
+ if (circularId) return circularId;
184
+ stack.push(type);
185
+ const childIds: StrNumber[] = [];
186
+ for (const param of type.parameters) childIds.push(_createTypeId(param, stack));
187
+ stack.pop();
188
+ const kind = (type as any).subKind || type.kind;
189
+ return `${kind}{${childIds.join(',')}}`;
190
+ }
191
+
192
+ function checkCircularAndGetRefId(type: Type, stack: Type[]): StrNumber | undefined {
193
+ const inStackIndex = stack.findIndex((t) => {
194
+ if (t === type) return true;
195
+ return t.id && type.id && t.id === type.id;
196
+ });
197
+ if (inStackIndex >= 0) {
198
+ const name = type.typeName || '';
199
+ return '$' + type.kind + `_${inStackIndex}` + name;
200
+ }
201
+ return undefined;
202
+ }
203
+
204
+ /** Computes the format ID from a deepkit Type. Caches result in type._formatId */
205
+ export function computeDeepkitFormatID(deepkitType: TypeWithCachedIds): string | undefined {
206
+ if (deepkitType._formatId !== undefined) return deepkitType._formatId || undefined;
207
+ const annotations = typeAnnotation.getAnnotations(deepkitType);
208
+ if (annotations.length === 0) {
209
+ (deepkitType as any)._formatId = '';
210
+ return undefined;
211
+ }
212
+ for (const annotation of annotations) {
213
+ const formatAnnotation = annotation as FormatAnnotation;
214
+ if (!formatAnnotation.name) continue;
215
+ const formatter = getFormatterFromCache(deepkitType.kind, formatAnnotation.name);
216
+ if (!formatter) continue;
217
+ const params = typeAnnotation.getOption(deepkitType, formatAnnotation.name) as TypeFormatParams;
218
+ if (!params) continue;
219
+ const formatId = `<${typeParamsToString(params, defaultIgnoreFormatProps)}>`;
220
+ (deepkitType as any)._formatId = formatId;
221
+ return formatId;
222
+ }
223
+ (deepkitType as any)._formatId = '';
224
+ return undefined;
225
+ }
@@ -0,0 +1,402 @@
1
+ /* ########
2
+ * 2024 mion
3
+ * Author: Ma-jerez
4
+ * License: MIT
5
+ * The software is provided "as is", without warranty of any kind.
6
+ * ######## */
7
+
8
+ import {ReflectionKind} from '@deepkit/type';
9
+ import type {Type, TypeFunction, TypeParameter, TypeTuple, TypeTupleMember} from '@deepkit/type';
10
+ import type {CompiledPureFunction, TypeFormatValue} from '@mionjs/core';
11
+ import type {AnyClass, JitFnID, RunType} from '../types.ts';
12
+ import type {BaseRunType, CollectionRunType, MemberRunType} from './baseRunTypes.ts';
13
+ import type {JitFnCompiler, JitErrorsFnCompiler} from './jitFnCompiler.ts';
14
+ import type {PropertyRunType} from '../nodes/member/property.ts';
15
+ import {createHashLiteral} from '@mionjs/core';
16
+ import {validPropertyNameRegExp} from '../constants.ts';
17
+ import {ReflectionSubKind} from '../constants.kind.ts';
18
+ import {getJitFnSettings} from './jitFnsRegistry.ts';
19
+ import type {JitCode} from '../types.ts';
20
+
21
+ export function toLiteral(value: number | string | boolean | undefined | null | bigint | RegExp | symbol): string {
22
+ switch (typeof value) {
23
+ case 'number':
24
+ return `${value}`;
25
+ case 'string':
26
+ return JSON.stringify(value);
27
+ case 'boolean':
28
+ return value ? 'true' : 'false';
29
+ case 'undefined':
30
+ return 'undefined';
31
+ case 'bigint':
32
+ return `${value}n`;
33
+ case 'symbol':
34
+ return `Symbol(${toLiteral(value.description)})`;
35
+ case 'object':
36
+ if (value === null) return 'null';
37
+ if (value instanceof RegExp) return value.toString();
38
+ throw new Error(`Unsupported literal type ${value}`);
39
+ default:
40
+ throw new Error(`Unsupported literal type ${value}`);
41
+ }
42
+ }
43
+
44
+ export function arrayToLiteral(value: any[]): string {
45
+ return `[${arrayToArgumentsLiteral(value)}]`;
46
+ }
47
+
48
+ export function arrayToArgumentsLiteral(value: any[]): string {
49
+ return value.map((v) => `${toLiteral(v)}`).join(', ');
50
+ }
51
+
52
+ export function isFunctionKind(kind: ReflectionKind): boolean {
53
+ return (
54
+ kind === ReflectionKind.callSignature ||
55
+ kind === ReflectionKind.method ||
56
+ kind === ReflectionKind.function ||
57
+ kind === ReflectionKind.methodSignature ||
58
+ kind === ReflectionKind.indexSignature
59
+ );
60
+ }
61
+
62
+ export function isClass(cls: AnyClass | any): cls is AnyClass {
63
+ return (
64
+ typeof cls === 'function' &&
65
+ cls.prototype &&
66
+ cls.prototype.constructor === cls &&
67
+ cls.prototype.constructor.name &&
68
+ cls.toString().startsWith('class')
69
+ );
70
+ }
71
+
72
+ export function isSameJitType(a: RunType, b: RunType): boolean {
73
+ if (a === b) return true;
74
+ if (a.src.kind !== b.src.kind) return false;
75
+ return a.getTypeID() === b.getTypeID();
76
+ }
77
+
78
+ export function isSameJitCompiler(a: JitFnCompiler, b: JitFnCompiler): boolean {
79
+ return a.fnID === b.fnID && isSameJitType(a.rootType, b.rootType);
80
+ }
81
+
82
+ export function memorize<Fn extends (...args: any[]) => any>(fn: Fn): Fn {
83
+ let cached: undefined | any;
84
+ return ((...args: any[]) => {
85
+ if (!cached) cached = fn(...args);
86
+ return cached;
87
+ }) as Fn;
88
+ }
89
+
90
+ export function isSafePropName(name: string | number | symbol): boolean {
91
+ return (typeof name === 'string' && validPropertyNameRegExp.test(name)) || typeof name === 'number';
92
+ }
93
+
94
+ export function sanitizePropName(name: string | number | symbol): string {
95
+ const sName = typeof name === 'string' ? name : String(name);
96
+ return sName.replace(/[^a-zA-Z0-9_$]/g, '_');
97
+ }
98
+
99
+ export function getPropVarName(name: string | number | symbol): string | number {
100
+ if (typeof name === 'symbol') return name.toString();
101
+ return name;
102
+ }
103
+ export function getPropLiteral(name: string | number | symbol): string | number {
104
+ return toLiteral(name);
105
+ }
106
+ export function useArrayAccessorForProp(name: string | number | symbol): boolean {
107
+ if (typeof name === 'number') return true;
108
+ return !isSafePropName(name);
109
+ }
110
+
111
+ export function getPropIndex(src: Type): number {
112
+ const parent = src.parent;
113
+ if (!parent) return -1;
114
+ const types = (parent as {types: Type[]}).types;
115
+ if (types) return types.indexOf(src);
116
+ return 0;
117
+ }
118
+
119
+ export function getParamIndex(src: TypeParameter | TypeTupleMember): number {
120
+ const parent = src.parent as TypeFunction | TypeTuple;
121
+ if (!parent) return -1;
122
+ if ((parent as TypeFunction).parameters) return (parent as TypeFunction).parameters.indexOf(src as TypeParameter);
123
+ if ((parent as TypeTuple).types) return (parent as TypeTuple).types.indexOf(src as TypeTupleMember);
124
+ return 0;
125
+ }
126
+
127
+ export function childIsExpression(childJCode: JitCode, child: BaseRunType): boolean {
128
+ return childJCode.type === 'E' || !child.isJitInlined();
129
+ }
130
+
131
+ // ######### To literal with context ########
132
+
133
+ const maxStringLength = 10;
134
+
135
+ /**
136
+ * Transforms values into a literal string to be used in JIT code.
137
+ * ie: {total: 5, name: 'hello'} gets transformed into teh string '{total: 5, name: "hello"}' that can be used as JIT code.
138
+ * Some literals are automatically added to the context to reduce code size. in this case the reference to the context variable is returned.
139
+ * Otherwise the literal is returned.
140
+ *
141
+ * Important this is intended for actual immutable literals, if two empty arrays are passed they will be transformed into the same reference.
142
+ * so those object or arrays should never be modified in jit code. //TODO: investigate using object.freeze
143
+ *
144
+ * @param comp
145
+ * @param params
146
+ * @param ignoreProps
147
+ * @param isDependencies
148
+ * @returns
149
+ */
150
+ export function toLiteralInContext(
151
+ // if compiled is passed it is assumed that the params are dependencies and will be transformed into code
152
+ comp: JitFnCompiler | JitErrorsFnCompiler,
153
+ params: TypeFormatValue | Record<string, string | CompiledPureFunction>,
154
+ // TODO: somewhere the ignoreProps are not passed and we still outputting 'samples' and 'sampleChars' to jit code were is not needed
155
+ ignoreProps: string[] = [],
156
+ isDependencies = false
157
+ ): string {
158
+ switch (true) {
159
+ case typeof params === 'string': {
160
+ const literal = toLiteral(params);
161
+ // if string is longer than 10 chars we add it as a new variable in the context to reduce code size
162
+ if (params.length > maxStringLength) {
163
+ const hash = createHashLiteral(params);
164
+ const strName = hash;
165
+ if (!comp.hasContextItem(strName)) comp.setContextItem(strName, `const ${strName} = ${literal}`);
166
+ return strName;
167
+ }
168
+ return literal;
169
+ }
170
+ case typeof params === 'number':
171
+ return `${params}`;
172
+ case typeof params === 'boolean':
173
+ return params ? 'true' : 'false';
174
+ case params instanceof RegExp: {
175
+ // if param is a regexp we add it as a new variable in the context (so we are not creating a new regexp on each call)
176
+ const regCode = params.toString();
177
+ const hash = createHashLiteral(regCode);
178
+ const regName = hash;
179
+ if (!comp.hasContextItem(regName)) comp.setContextItem(regName, `const ${regName} = ${regCode}`);
180
+ return regName;
181
+ }
182
+ case Array.isArray(params): {
183
+ // arrays are added to the context as a new variable
184
+ const arrCode = `[${params.map((v) => toLiteralInContext(comp, v, ignoreProps, isDependencies)).join(',')}]`;
185
+ const hash = createHashLiteral(arrCode);
186
+ const arrName = hash;
187
+ if (!comp.hasContextItem(arrName)) comp.setContextItem(arrName, `const ${arrName} = ${arrCode}`);
188
+
189
+ return arrName;
190
+ }
191
+ case typeof params === 'object': {
192
+ // objects are added to the context as a new variable
193
+ const entriesLiterals = Object.entries(params).map(([k, v]) => {
194
+ if (ignoreProps.includes(k) || typeof v === 'undefined') return undefined;
195
+ const propName = isSafePropName(k) ? k : toLiteral(k);
196
+ if (!isDependencies) return `${propName}:${toLiteralInContext(comp, v, ignoreProps, isDependencies)}`;
197
+ return `${propName}:${dependencyValueToLiteral(comp, v)}`;
198
+ });
199
+ const objCode = `{${entriesLiterals.filter(Boolean).join(',')}}`;
200
+ const hash = createHashLiteral(objCode);
201
+ const objName = hash;
202
+ if (!comp.hasContextItem(objName)) comp.setContextItem(objName, `const ${objName} = ${objCode}`);
203
+ return objName;
204
+ }
205
+ case typeof params === 'bigint':
206
+ return toLiteral(params);
207
+ default:
208
+ throw new Error(`Unsupported type format params ${params}`);
209
+ }
210
+ }
211
+
212
+ export function dependencyValueToLiteral(comp: JitFnCompiler | JitErrorsFnCompiler | undefined, propVal: any): string {
213
+ if (
214
+ typeof propVal === 'object' &&
215
+ propVal !== null &&
216
+ 'createJitFn' in propVal &&
217
+ 'namespace' in propVal &&
218
+ 'fnName' in propVal
219
+ ) {
220
+ // propVal is a CompiledPureFunction
221
+ if (!comp) throw new Error('Dependencies must be pure functions or code');
222
+ comp.addPureFnDependency(propVal);
223
+ return `utl.getPureFn(${toLiteral(propVal.namespace)}, ${toLiteral(propVal.fnName)})`;
224
+ }
225
+ if (typeof propVal === 'string') return propVal;
226
+ throw new Error('Dependencies must be CompiledPureFunction objects or code strings');
227
+ }
228
+
229
+ export function typeParamsToString(
230
+ params: TypeFormatValue | Record<string, string | CompiledPureFunction>,
231
+ ignoreProps: string[]
232
+ ): string {
233
+ switch (true) {
234
+ case typeof params === 'string':
235
+ return toLiteral(params);
236
+ case typeof params === 'number':
237
+ return `${params}`;
238
+ case typeof params === 'boolean':
239
+ return params ? 'true' : 'false';
240
+ case params instanceof RegExp:
241
+ return params.toString();
242
+ case Array.isArray(params):
243
+ return `[${params.map((v) => typeParamsToString(v, ignoreProps)).join(', ')}]`;
244
+ case typeof params === 'object': {
245
+ const entriesLiterals = Object.entries(params).map(([k, v]) => {
246
+ if (ignoreProps.includes(k) || typeof v === 'undefined') return undefined;
247
+ return `${k}:${typeParamsToString(v, ignoreProps)}`;
248
+ });
249
+ return `{${entriesLiterals.filter(Boolean).join(',')}}`;
250
+ }
251
+ case typeof params === 'bigint':
252
+ return `${params}n`;
253
+ default:
254
+ throw new Error(`Unsupported type format params ${params}`);
255
+ }
256
+ }
257
+ export function getFormatterHash(rt: BaseRunType): string {
258
+ const literal = rt.getFormatTypeID();
259
+ if (!literal) throw new Error('Formatter JIT ID not found');
260
+ return createHashLiteral(literal);
261
+ }
262
+
263
+ /** Complexity of each type family, we can add more types and weights here if we want to optimize further */
264
+ const familyComplexity = {
265
+ A: 2,
266
+ M: 20, // member usually involves iteration
267
+ C: 10, // collection usually involves calling and extra jit function
268
+ F: 10_000_000,
269
+ }; // function should go always last
270
+ const typesComplexity = {
271
+ [ReflectionKind.indexSignature]: 20, // index involves traversing all object keys
272
+ [ReflectionKind.array]: 30, // array involves iterating all items
273
+ [ReflectionKind.property]: 0, // property involves just checking a single property
274
+ [ReflectionKind.propertySignature]: 0, // property involves just checking a single property
275
+ [ReflectionKind.boolean]: 1, // boolean is fast to check
276
+ [ReflectionKind.null]: 1, // null is fast to check
277
+ [ReflectionKind.undefined]: 1, // undefined is fast to check
278
+ [ReflectionKind.enum]: 20, // enum can involve checking multiple values
279
+ };
280
+ const subTypesComplexity = {
281
+ [ReflectionSubKind.date]: 3,
282
+ };
283
+
284
+ /**
285
+ * Returns an arbitrary complexity number for a runType, this depends on the type family and the complexity of all children.
286
+ * There might be better options to get the type complexity, as this also depends on the runtime operation and the compiled operation.
287
+ * but this is an initial approximation.
288
+ */
289
+ export function getTotalComplexity(comp: JitFnCompiler, rt: BaseRunType, stack: BaseRunType[] = []): number {
290
+ if (!rt) return 0;
291
+ if (stack.includes(rt)) return 0;
292
+ stack.push(rt);
293
+ let result = 0;
294
+ const subKindC = rt.src.subKind ? subTypesComplexity[rt.src.subKind] : undefined;
295
+ const typeC = subKindC || typesComplexity[rt.src.kind];
296
+ const familyC = rt.getFamily();
297
+ if (familyC === 'A') result = typeC || familyComplexity.A;
298
+ else if (familyC === 'M') {
299
+ const childRT = (rt as MemberRunType<any>).getJitChild(comp);
300
+ if (!childRT) return typeC ?? familyComplexity.M;
301
+ const childC = getTotalComplexity(comp, childRT, stack);
302
+ result = (typeC ?? familyComplexity.M) + childC;
303
+ } else if (familyC === 'C') {
304
+ const childrenC = (rt as CollectionRunType<any>)
305
+ .getJitChildren(comp)
306
+ .map((child) => getTotalComplexity(comp, child, stack));
307
+ const totalChildrenC = childrenC.reduce((acc, childC) => acc + childC, 0);
308
+ result = (typeC ?? familyComplexity.C) + totalChildrenC;
309
+ } else {
310
+ result = typeC ?? familyComplexity.F;
311
+ }
312
+ stack.pop();
313
+ return result;
314
+ }
315
+
316
+ /**
317
+ * Sort runTypes by complexity, ascending. this way less complex code can be executed first.
318
+ * This could help to fail fast and avoid unnecessary checks.
319
+ */
320
+ export function sortRunTypeByComplexity(comp: JitFnCompiler, a: BaseRunType, b: BaseRunType): number {
321
+ if (a.getFamily() === 'M' && b.getFamily() === 'M') {
322
+ const aIsDiscriminator = (a as PropertyRunType).isUnionDiscriminator;
323
+ const bIsDiscriminator = (b as PropertyRunType).isUnionDiscriminator;
324
+ if (aIsDiscriminator && !bIsDiscriminator) return -1;
325
+ if (!aIsDiscriminator && bIsDiscriminator) return 1;
326
+ }
327
+ if (b.getFamily() === 'M' && (b as PropertyRunType).isUnionDiscriminator) return 1;
328
+ const aTotal = getTotalComplexity(comp, a);
329
+ const bTotal = getTotalComplexity(comp, b);
330
+ return aTotal - bTotal;
331
+ }
332
+
333
+ export function sortDiscriminatorsFirst(a: BaseRunType, b: BaseRunType): number {
334
+ if (a.getFamily() === 'M' && b.getFamily() === 'M') {
335
+ const aIsDiscriminator = (a as PropertyRunType).isUnionDiscriminator;
336
+ const bIsDiscriminator = (b as PropertyRunType).isUnionDiscriminator;
337
+ if (aIsDiscriminator && !bIsDiscriminator) return -1;
338
+ if (!aIsDiscriminator && bIsDiscriminator) return 1;
339
+ }
340
+ return 0;
341
+ }
342
+
343
+ export function createIfElseFn(): (isEnd?: boolean) => string {
344
+ let isFirst = true;
345
+ return (end = false) => {
346
+ const elseIf = end ? 'else' : 'else if';
347
+ const iF = isFirst ? 'if' : elseIf;
348
+ isFirst = false;
349
+ return iF;
350
+ };
351
+ }
352
+
353
+ export function getJitFnArgCallVarName(parentComp: JitFnCompiler, rt: BaseRunType, idFnToCall: JitFnID, argKey: string): string {
354
+ const fnConfig = getJitFnSettings(idFnToCall);
355
+ const defaultArgVal = fnConfig.jitDefaultArgs[argKey];
356
+ // vλl is a special case because it is the only arg that changes based on the stack
357
+ if (argKey === 'vλl' && fnConfig.noInitialVλl) return 'undefined'; // when no initial vλl is required, we pass undefined
358
+ if (argKey === 'vλl') return parentComp.getCurrentStackItem().vλl; // when vλl is required we pass the current stack item
359
+
360
+ // first check if the arg is provided by the context
361
+ const varNameFromContext = parentComp.getChildrenCallArgs(idFnToCall)?.[argKey];
362
+ if (varNameFromContext) return varNameFromContext;
363
+ // then check if the arg is provided by the parent function
364
+ const varNameFromParent = parentComp.args[argKey];
365
+ if (varNameFromParent) return varNameFromParent;
366
+ // if neither the parent nor the context has the arg, we create a new default value in the context
367
+ // if there is no default value, we can't call the function
368
+ if (!defaultArgVal)
369
+ throw new Error(
370
+ `Can not call jit function ${idFnToCall} because it requires argument ${argKey} but it is not provided,
371
+ neither in the parent function nor in the function context and there is no default value for it.`
372
+ );
373
+ const defaultName = fnConfig.jitArgs[argKey];
374
+ const optsVarName = `${defaultName}_${idFnToCall}0`; // we don't need to use nestLevel as value is the same for all calls
375
+ parentComp.setContextItem(optsVarName, `const ${optsVarName} = ${defaultArgVal}`);
376
+ return optsVarName;
377
+ }
378
+
379
+ /**
380
+ * Returns true if the parent of the runType is of the given kind.
381
+ * handles special case of union types, as we need to check the parent of the union.
382
+ * @param rt
383
+ * @param kind
384
+ * @returns
385
+ */
386
+ export function parentIs(rt: BaseRunType, kind: ReflectionKind | ReflectionKind[]): boolean {
387
+ const parentRT = rt.getParent();
388
+ if (!parentRT) return false;
389
+ if (parentRT.src.kind === ReflectionKind.union) return parentIs(parentRT, kind);
390
+ if (Array.isArray(kind) ? kind.includes(parentRT.src.kind) : parentRT.src.kind === kind) return true;
391
+ return false;
392
+ }
393
+
394
+ /** Add full stop to code if needed */
395
+ export function addFullStop(code: string): string {
396
+ if (!code) return code;
397
+ const lastChar = code.length - 1;
398
+ const hasFullStop = code[lastChar] === ';';
399
+ if (hasFullStop) return code;
400
+ const hasBlockClose = code[lastChar] === '}';
401
+ return hasBlockClose ? code : `${code};`;
402
+ }