@ls-stack/utils 3.65.0 → 3.67.0

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 (336) hide show
  1. package/dist/{arrayUtils.d.cts → arrayUtils.d.mts} +24 -23
  2. package/dist/arrayUtils.mjs +249 -0
  3. package/dist/assertions-qMxfVhSu.mjs +207 -0
  4. package/dist/{assertions.d.ts → assertions.d.mts} +4 -3
  5. package/dist/assertions.mjs +3 -0
  6. package/dist/asyncQueue.d.mts +497 -0
  7. package/dist/asyncQueue.mjs +757 -0
  8. package/dist/{awaitDebounce.d.cts → awaitDebounce.d.mts} +11 -6
  9. package/dist/awaitDebounce.mjs +54 -0
  10. package/dist/{cache.d.ts → cache.d.mts} +76 -68
  11. package/dist/cache.mjs +355 -0
  12. package/dist/castValues-DfICShCc.mjs +19 -0
  13. package/dist/{castValues.d.cts → castValues.d.mts} +3 -2
  14. package/dist/castValues.mjs +3 -0
  15. package/dist/{concurrentCalls.d.ts → concurrentCalls.d.mts} +74 -65
  16. package/dist/concurrentCalls.mjs +295 -0
  17. package/dist/consoleFmt.d.mts +55 -0
  18. package/dist/consoleFmt.mjs +63 -0
  19. package/dist/conversions-DTmwEMIu.mjs +12 -0
  20. package/dist/conversions.d.mts +4 -0
  21. package/dist/conversions.mjs +3 -0
  22. package/dist/createThrottleController.d.mts +18 -0
  23. package/dist/createThrottleController.mjs +40 -0
  24. package/dist/debounce.d.mts +47 -0
  25. package/dist/debounce.mjs +117 -0
  26. package/dist/dedent.d.mts +74 -0
  27. package/dist/dedent.mjs +80 -0
  28. package/dist/deepEqual-C7EZEixx.mjs +78 -0
  29. package/dist/{deepEqual.d.cts → deepEqual.d.mts} +3 -2
  30. package/dist/deepEqual.mjs +3 -0
  31. package/dist/{deepReplaceValues.d.cts → deepReplaceValues.d.mts} +4 -3
  32. package/dist/deepReplaceValues.mjs +61 -0
  33. package/dist/diffParser.d.mts +79 -0
  34. package/dist/diffParser.mjs +424 -0
  35. package/dist/enhancedMap.d.mts +21 -0
  36. package/dist/enhancedMap.mjs +69 -0
  37. package/dist/exhaustiveMatch.d.mts +10 -0
  38. package/dist/exhaustiveMatch.mjs +48 -0
  39. package/dist/{filterObjectOrArrayKeys.d.cts → filterObjectOrArrayKeys.d.mts} +15 -8
  40. package/dist/filterObjectOrArrayKeys.mjs +497 -0
  41. package/dist/{getAutoIncrementId.d.cts → getAutoIncrementId.d.mts} +9 -5
  42. package/dist/getAutoIncrementId.mjs +53 -0
  43. package/dist/{getCompositeKey.d.cts → getCompositeKey.d.mts} +3 -2
  44. package/dist/getCompositeKey.mjs +50 -0
  45. package/dist/{getValueStableKey.d.cts → getValueStableKey.d.mts} +5 -3
  46. package/dist/getValueStableKey.mjs +17 -0
  47. package/dist/{hash.d.cts → hash.d.mts} +3 -2
  48. package/dist/hash.mjs +28 -0
  49. package/dist/interpolate.d.mts +17 -0
  50. package/dist/interpolate.mjs +28 -0
  51. package/dist/{iteratorUtils.d.cts → iteratorUtils.d.mts} +5 -4
  52. package/dist/iteratorUtils.mjs +39 -0
  53. package/dist/keepPrevIfUnchanged.d.mts +12 -0
  54. package/dist/keepPrevIfUnchanged.mjs +9 -0
  55. package/dist/keyedMap.d.mts +76 -0
  56. package/dist/keyedMap.mjs +139 -0
  57. package/dist/keyedSet.d.mts +77 -0
  58. package/dist/keyedSet.mjs +129 -0
  59. package/dist/{levenshtein.d.cts → levenshtein.d.mts} +3 -2
  60. package/dist/levenshtein.mjs +121 -0
  61. package/dist/main.d.mts +4 -0
  62. package/dist/main.mjs +7 -0
  63. package/dist/matchPath.d.mts +50 -0
  64. package/dist/matchPath.mjs +81 -0
  65. package/dist/mathUtils-BDP1lM_z.mjs +81 -0
  66. package/dist/{mathUtils.d.cts → mathUtils.d.mts} +3 -2
  67. package/dist/mathUtils.mjs +3 -0
  68. package/dist/{mutationUtils.d.cts → mutationUtils.d.mts} +6 -5
  69. package/dist/mutationUtils.mjs +44 -0
  70. package/dist/{objUtils.d.ts → objUtils.d.mts} +8 -6
  71. package/dist/objUtils.mjs +115 -0
  72. package/dist/parallelAsyncCalls.d.mts +83 -0
  73. package/dist/parallelAsyncCalls.mjs +121 -0
  74. package/dist/partialEqual.d.mts +139 -0
  75. package/dist/partialEqual.mjs +1055 -0
  76. package/dist/promiseUtils.d.mts +9 -0
  77. package/dist/promiseUtils.mjs +17 -0
  78. package/dist/regexUtils.d.mts +18 -0
  79. package/dist/regexUtils.mjs +34 -0
  80. package/dist/{retryOnError.d.cts → retryOnError.d.mts} +38 -37
  81. package/dist/retryOnError.mjs +91 -0
  82. package/dist/{runShellCmd.d.ts → runShellCmd.d.mts} +24 -15
  83. package/dist/runShellCmd.mjs +151 -0
  84. package/dist/{safeJson.d.cts → safeJson.d.mts} +3 -2
  85. package/dist/safeJson.mjs +30 -0
  86. package/dist/{saferTyping.d.cts → saferTyping.d.mts} +4 -3
  87. package/dist/saferTyping.mjs +45 -0
  88. package/dist/serializeXML.d.mts +23 -0
  89. package/dist/serializeXML.mjs +74 -0
  90. package/dist/{shallowEqual.d.cts → shallowEqual.d.mts} +3 -2
  91. package/dist/shallowEqual.mjs +54 -0
  92. package/dist/sleep.d.mts +4 -0
  93. package/dist/sleep.mjs +7 -0
  94. package/dist/stringUtils-DjhWOiYn.mjs +113 -0
  95. package/dist/{stringUtils.d.cts → stringUtils.d.mts} +3 -2
  96. package/dist/stringUtils.mjs +3 -0
  97. package/dist/{testUtils.d.ts → testUtils.d.mts} +83 -52
  98. package/dist/testUtils.mjs +310 -0
  99. package/dist/{throttle.d.ts → throttle.d.mts} +18 -17
  100. package/dist/throttle.mjs +102 -0
  101. package/dist/time-sr2lhQRw.mjs +67 -0
  102. package/dist/{time.d.ts → time.d.mts} +8 -7
  103. package/dist/time.mjs +3 -0
  104. package/dist/{timers.d.cts → timers.d.mts} +22 -13
  105. package/dist/timers.mjs +220 -0
  106. package/dist/{tsResult.d.cts → tsResult.d.mts} +52 -48
  107. package/dist/tsResult.mjs +142 -0
  108. package/dist/typeGuards-B1mzA-Rz.mjs +128 -0
  109. package/dist/{typeGuards.d.cts → typeGuards.d.mts} +3 -2
  110. package/dist/typeGuards.mjs +3 -0
  111. package/dist/{typeUtils.d.ts → typeUtils.d.mts} +13 -34
  112. package/dist/typeUtils.mjs +1 -0
  113. package/dist/{typedStrings.d.cts → typedStrings.d.mts} +5 -4
  114. package/dist/typedStrings.mjs +131 -0
  115. package/dist/typingFnUtils-Bb8drgKF.mjs +101 -0
  116. package/dist/{typingFnUtils.d.cts → typingFnUtils.d.mts} +13 -22
  117. package/dist/typingFnUtils.mjs +3 -0
  118. package/dist/{typingTestUtils.d.cts → typingTestUtils.d.mts} +11 -15
  119. package/dist/typingTestUtils.mjs +80 -0
  120. package/dist/typingUtils.d.mts +20 -0
  121. package/dist/typingUtils.mjs +1 -0
  122. package/dist/yamlStringify.d.mts +17 -0
  123. package/dist/yamlStringify.mjs +189 -0
  124. package/package.json +65 -242
  125. package/dist/arrayUtils.cjs +0 -229
  126. package/dist/arrayUtils.d.ts +0 -171
  127. package/dist/arrayUtils.js +0 -42
  128. package/dist/assertions.cjs +0 -107
  129. package/dist/assertions.d.cts +0 -192
  130. package/dist/assertions.js +0 -25
  131. package/dist/asyncQueue.cjs +0 -672
  132. package/dist/asyncQueue.d.cts +0 -488
  133. package/dist/asyncQueue.d.ts +0 -488
  134. package/dist/asyncQueue.js +0 -631
  135. package/dist/awaitDebounce.cjs +0 -106
  136. package/dist/awaitDebounce.d.ts +0 -41
  137. package/dist/awaitDebounce.js +0 -28
  138. package/dist/cache.cjs +0 -367
  139. package/dist/cache.d.cts +0 -228
  140. package/dist/cache.js +0 -19
  141. package/dist/castValues.cjs +0 -50
  142. package/dist/castValues.d.ts +0 -4
  143. package/dist/castValues.js +0 -8
  144. package/dist/chunk-5DZT3Z5Z.js +0 -8
  145. package/dist/chunk-6FBIEPWU.js +0 -96
  146. package/dist/chunk-6FIBVC2P.js +0 -56
  147. package/dist/chunk-7CQPOM5I.js +0 -100
  148. package/dist/chunk-B6DNOZCP.js +0 -369
  149. package/dist/chunk-BM4PYVOX.js +0 -109
  150. package/dist/chunk-C2SVCIWE.js +0 -57
  151. package/dist/chunk-CCUPDGSZ.js +0 -132
  152. package/dist/chunk-DBOWTYR4.js +0 -49
  153. package/dist/chunk-DFXNVEH6.js +0 -14
  154. package/dist/chunk-DX2524CZ.js +0 -314
  155. package/dist/chunk-GMJTLFM6.js +0 -60
  156. package/dist/chunk-IATIXMCE.js +0 -20
  157. package/dist/chunk-II4R3VVX.js +0 -25
  158. package/dist/chunk-JF2MDHOJ.js +0 -40
  159. package/dist/chunk-JQFUKJU5.js +0 -71
  160. package/dist/chunk-MI4UE2PQ.js +0 -561
  161. package/dist/chunk-PUKVXYYL.js +0 -52
  162. package/dist/chunk-QQS7I7ZL.js +0 -16
  163. package/dist/chunk-VAAMRG4K.js +0 -20
  164. package/dist/chunk-WFQJUJTC.js +0 -182
  165. package/dist/chunk-ZXIKIA5B.js +0 -178
  166. package/dist/concurrentCalls.cjs +0 -406
  167. package/dist/concurrentCalls.d.cts +0 -116
  168. package/dist/concurrentCalls.js +0 -346
  169. package/dist/consoleFmt.cjs +0 -85
  170. package/dist/consoleFmt.d.cts +0 -54
  171. package/dist/consoleFmt.d.ts +0 -54
  172. package/dist/consoleFmt.js +0 -60
  173. package/dist/conversions.cjs +0 -44
  174. package/dist/conversions.d.cts +0 -3
  175. package/dist/conversions.d.ts +0 -3
  176. package/dist/conversions.js +0 -6
  177. package/dist/createThrottleController.cjs +0 -193
  178. package/dist/createThrottleController.d.cts +0 -13
  179. package/dist/createThrottleController.d.ts +0 -13
  180. package/dist/createThrottleController.js +0 -61
  181. package/dist/debounce.cjs +0 -157
  182. package/dist/debounce.d.cts +0 -46
  183. package/dist/debounce.d.ts +0 -46
  184. package/dist/debounce.js +0 -8
  185. package/dist/dedent.cjs +0 -104
  186. package/dist/dedent.d.cts +0 -73
  187. package/dist/dedent.d.ts +0 -73
  188. package/dist/dedent.js +0 -79
  189. package/dist/deepEqual.cjs +0 -96
  190. package/dist/deepEqual.d.ts +0 -21
  191. package/dist/deepEqual.js +0 -8
  192. package/dist/deepReplaceValues.cjs +0 -87
  193. package/dist/deepReplaceValues.d.ts +0 -27
  194. package/dist/deepReplaceValues.js +0 -7
  195. package/dist/enhancedMap.cjs +0 -131
  196. package/dist/enhancedMap.d.cts +0 -20
  197. package/dist/enhancedMap.d.ts +0 -20
  198. package/dist/enhancedMap.js +0 -10
  199. package/dist/exhaustiveMatch.cjs +0 -66
  200. package/dist/exhaustiveMatch.d.cts +0 -9
  201. package/dist/exhaustiveMatch.d.ts +0 -9
  202. package/dist/exhaustiveMatch.js +0 -40
  203. package/dist/filterObjectOrArrayKeys.cjs +0 -619
  204. package/dist/filterObjectOrArrayKeys.d.ts +0 -88
  205. package/dist/filterObjectOrArrayKeys.js +0 -9
  206. package/dist/getAutoIncrementId.cjs +0 -44
  207. package/dist/getAutoIncrementId.d.ts +0 -46
  208. package/dist/getAutoIncrementId.js +0 -18
  209. package/dist/getCompositeKey.cjs +0 -86
  210. package/dist/getCompositeKey.d.ts +0 -11
  211. package/dist/getCompositeKey.js +0 -8
  212. package/dist/getValueStableKey.cjs +0 -89
  213. package/dist/getValueStableKey.d.ts +0 -15
  214. package/dist/getValueStableKey.js +0 -11
  215. package/dist/hash.cjs +0 -57
  216. package/dist/hash.d.ts +0 -7
  217. package/dist/hash.js +0 -32
  218. package/dist/interpolate.cjs +0 -88
  219. package/dist/interpolate.d.cts +0 -11
  220. package/dist/interpolate.d.ts +0 -11
  221. package/dist/interpolate.js +0 -46
  222. package/dist/iteratorUtils.cjs +0 -73
  223. package/dist/iteratorUtils.d.ts +0 -10
  224. package/dist/iteratorUtils.js +0 -44
  225. package/dist/keepPrevIfUnchanged.cjs +0 -102
  226. package/dist/keepPrevIfUnchanged.d.cts +0 -7
  227. package/dist/keepPrevIfUnchanged.d.ts +0 -7
  228. package/dist/keepPrevIfUnchanged.js +0 -7
  229. package/dist/keyedMap.cjs +0 -224
  230. package/dist/keyedMap.d.cts +0 -75
  231. package/dist/keyedMap.d.ts +0 -75
  232. package/dist/keyedMap.js +0 -145
  233. package/dist/keyedSet.cjs +0 -205
  234. package/dist/keyedSet.d.cts +0 -76
  235. package/dist/keyedSet.d.ts +0 -76
  236. package/dist/keyedSet.js +0 -126
  237. package/dist/levenshtein.cjs +0 -180
  238. package/dist/levenshtein.d.ts +0 -5
  239. package/dist/levenshtein.js +0 -153
  240. package/dist/main.cjs +0 -32
  241. package/dist/main.d.cts +0 -3
  242. package/dist/main.d.ts +0 -3
  243. package/dist/main.js +0 -7
  244. package/dist/matchPath.cjs +0 -155
  245. package/dist/matchPath.d.cts +0 -53
  246. package/dist/matchPath.d.ts +0 -53
  247. package/dist/matchPath.js +0 -108
  248. package/dist/mathUtils.cjs +0 -81
  249. package/dist/mathUtils.d.ts +0 -54
  250. package/dist/mathUtils.js +0 -22
  251. package/dist/mutationUtils.cjs +0 -153
  252. package/dist/mutationUtils.d.ts +0 -15
  253. package/dist/mutationUtils.js +0 -55
  254. package/dist/objUtils.cjs +0 -242
  255. package/dist/objUtils.d.cts +0 -28
  256. package/dist/objUtils.js +0 -38
  257. package/dist/parallelAsyncCalls.cjs +0 -162
  258. package/dist/parallelAsyncCalls.d.cts +0 -82
  259. package/dist/parallelAsyncCalls.d.ts +0 -82
  260. package/dist/parallelAsyncCalls.js +0 -126
  261. package/dist/partialEqual.cjs +0 -1196
  262. package/dist/partialEqual.d.cts +0 -141
  263. package/dist/partialEqual.d.ts +0 -141
  264. package/dist/partialEqual.js +0 -1168
  265. package/dist/promiseUtils.cjs +0 -38
  266. package/dist/promiseUtils.d.cts +0 -8
  267. package/dist/promiseUtils.d.ts +0 -8
  268. package/dist/promiseUtils.js +0 -6
  269. package/dist/regexUtils.cjs +0 -60
  270. package/dist/regexUtils.d.cts +0 -17
  271. package/dist/regexUtils.d.ts +0 -17
  272. package/dist/regexUtils.js +0 -33
  273. package/dist/retryOnError.cjs +0 -130
  274. package/dist/retryOnError.d.ts +0 -83
  275. package/dist/retryOnError.js +0 -101
  276. package/dist/runShellCmd.cjs +0 -127
  277. package/dist/runShellCmd.d.cts +0 -90
  278. package/dist/runShellCmd.js +0 -98
  279. package/dist/safeJson.cjs +0 -45
  280. package/dist/safeJson.d.ts +0 -16
  281. package/dist/safeJson.js +0 -8
  282. package/dist/saferTyping.cjs +0 -52
  283. package/dist/saferTyping.d.ts +0 -47
  284. package/dist/saferTyping.js +0 -23
  285. package/dist/serializeXML.cjs +0 -154
  286. package/dist/serializeXML.d.cts +0 -22
  287. package/dist/serializeXML.d.ts +0 -22
  288. package/dist/serializeXML.js +0 -116
  289. package/dist/shallowEqual.cjs +0 -88
  290. package/dist/shallowEqual.d.ts +0 -4
  291. package/dist/shallowEqual.js +0 -63
  292. package/dist/sleep.cjs +0 -32
  293. package/dist/sleep.d.cts +0 -3
  294. package/dist/sleep.d.ts +0 -3
  295. package/dist/sleep.js +0 -6
  296. package/dist/stringUtils.cjs +0 -155
  297. package/dist/stringUtils.d.ts +0 -55
  298. package/dist/stringUtils.js +0 -50
  299. package/dist/testUtils.cjs +0 -1490
  300. package/dist/testUtils.d.cts +0 -133
  301. package/dist/testUtils.js +0 -359
  302. package/dist/throttle.cjs +0 -282
  303. package/dist/throttle.d.cts +0 -98
  304. package/dist/throttle.js +0 -38
  305. package/dist/time.cjs +0 -152
  306. package/dist/time.d.cts +0 -25
  307. package/dist/time.js +0 -38
  308. package/dist/timers.cjs +0 -194
  309. package/dist/timers.d.ts +0 -121
  310. package/dist/timers.js +0 -156
  311. package/dist/tsResult.cjs +0 -226
  312. package/dist/tsResult.d.ts +0 -114
  313. package/dist/tsResult.js +0 -180
  314. package/dist/typeGuards.cjs +0 -70
  315. package/dist/typeGuards.d.ts +0 -111
  316. package/dist/typeGuards.js +0 -18
  317. package/dist/typeUtils.cjs +0 -18
  318. package/dist/typeUtils.d.cts +0 -61
  319. package/dist/typeUtils.js +0 -0
  320. package/dist/typedStrings.cjs +0 -90
  321. package/dist/typedStrings.d.ts +0 -163
  322. package/dist/typedStrings.js +0 -57
  323. package/dist/typingFnUtils.cjs +0 -96
  324. package/dist/typingFnUtils.d.ts +0 -100
  325. package/dist/typingFnUtils.js +0 -30
  326. package/dist/typingTestUtils.cjs +0 -52
  327. package/dist/typingTestUtils.d.ts +0 -79
  328. package/dist/typingTestUtils.js +0 -27
  329. package/dist/typingUtils.cjs +0 -18
  330. package/dist/typingUtils.d.cts +0 -35
  331. package/dist/typingUtils.d.ts +0 -35
  332. package/dist/typingUtils.js +0 -0
  333. package/dist/yamlStringify.cjs +0 -423
  334. package/dist/yamlStringify.d.cts +0 -10
  335. package/dist/yamlStringify.d.ts +0 -10
  336. package/dist/yamlStringify.js +0 -9
@@ -0,0 +1,1055 @@
1
+ import { r as exhaustiveCheck } from "./assertions-qMxfVhSu.mjs";
2
+ import { err, ok } from "t-result";
3
+
4
+ //#region src/partialEqual.ts
5
+ const has = Object.prototype.hasOwnProperty;
6
+ function createComparison(type) {
7
+ return { "~sc": type };
8
+ }
9
+ const match = {
10
+ noExtraKeys: (partialShape) => createComparison(["withNoExtraKeys", partialShape]),
11
+ deepNoExtraKeys: (partialShape) => createComparison(["withDeepNoExtraKeys", partialShape]),
12
+ noExtraDefinedKeys: (partialShape) => createComparison(["noExtraDefinedKeys", partialShape]),
13
+ deepNoExtraDefinedKeys: (partialShape) => createComparison(["deepNoExtraDefinedKeys", partialShape]),
14
+ hasType: {
15
+ string: createComparison(["hasType", "string"]),
16
+ number: createComparison(["hasType", "number"]),
17
+ boolean: createComparison(["hasType", "boolean"]),
18
+ object: createComparison(["hasType", "object"]),
19
+ array: createComparison(["hasType", "array"]),
20
+ function: createComparison(["hasType", "function"])
21
+ },
22
+ isInstanceOf: (constructor) => createComparison(["isInstanceOf", constructor]),
23
+ str: {
24
+ contains: (substring) => createComparison(["strContains", substring]),
25
+ startsWith: (substring) => createComparison(["strStartsWith", substring]),
26
+ endsWith: (substring) => createComparison(["strEndsWith", substring]),
27
+ matchesRegex: (regex) => createComparison(["strMatchesRegex", regex])
28
+ },
29
+ num: {
30
+ isGreaterThan: (value) => createComparison(["numIsGreaterThan", value]),
31
+ isGreaterThanOrEqual: (value) => createComparison(["numIsGreaterThanOrEqual", value]),
32
+ isLessThan: (value) => createComparison(["numIsLessThan", value]),
33
+ isLessThanOrEqual: (value) => createComparison(["numIsLessThanOrEqual", value]),
34
+ isInRange: (value) => createComparison(["numIsInRange", value])
35
+ },
36
+ array: {
37
+ contains: (elements) => createComparison(["arrayContains", elements]),
38
+ containsInOrder: (elements) => createComparison(["arrayContainsInOrder", elements]),
39
+ startsWith: (elements) => createComparison(["arrayStartsWith", elements]),
40
+ endsWith: (elements) => createComparison(["arrayEndsWith", elements]),
41
+ length: (n) => createComparison(["arrayLength", n]),
42
+ minLength: (n) => createComparison(["arrayMinLength", n]),
43
+ maxLength: (n) => createComparison(["arrayMaxLength", n]),
44
+ includes: (element) => createComparison(["arrayIncludes", element]),
45
+ every: (matcher) => createComparison(["arrayEvery", matcher["~sc"]]),
46
+ some: (matcher) => createComparison(["arraySome", matcher["~sc"]])
47
+ },
48
+ jsonString: { hasPartial: (value) => createComparison(["jsonStringHasPartial", value]) },
49
+ equal: (value) => createComparison(["deepEqual", value]),
50
+ partialEqual: (value) => createComparison(["partialEqual", value]),
51
+ custom: (isEqual) => createComparison(["custom", isEqual]),
52
+ keyNotBePresent: createComparison(["keyNotBePresent", null]),
53
+ any: (...values) => createComparison(["any", values.map((v) => {
54
+ if (isComparison(v)) return v["~sc"];
55
+ if (typeof v === "object" && v !== null) return ["partialEqual", v];
56
+ return ["deepEqual", v];
57
+ })]),
58
+ all: (...values) => createComparison(["all", values.map((v) => {
59
+ if (isComparison(v)) return v["~sc"];
60
+ if (typeof v === "object" && v !== null) return ["partialEqual", v];
61
+ return ["deepEqual", v];
62
+ })]),
63
+ key: {
64
+ any: "$pqkc:any$",
65
+ anyOther: "$pqkc:anyOther$",
66
+ numeric: "$pqkc:numeric$",
67
+ startingWith: (substring) => `$pqkc:startingWith:${substring}$`,
68
+ endingWith: (substring) => `$pqkc:endingWith:${substring}$`,
69
+ containing: (substring) => `$pqkc:contains:${substring}$`,
70
+ matchingRegex: (regex) => `$pqkc:matchesRegex:${regex}$`
71
+ },
72
+ not: {
73
+ hasType: {
74
+ string: createComparison(["not", ["hasType", "string"]]),
75
+ number: createComparison(["not", ["hasType", "number"]]),
76
+ boolean: createComparison(["not", ["hasType", "boolean"]]),
77
+ object: createComparison(["not", ["hasType", "object"]]),
78
+ array: createComparison(["not", ["hasType", "array"]]),
79
+ function: createComparison(["not", ["hasType", "function"]])
80
+ },
81
+ keyNotBePresent: createComparison(["not", ["keyNotBePresent", null]]),
82
+ isInstanceOf: (constructor) => createComparison(["not", ["isInstanceOf", constructor]]),
83
+ str: {
84
+ contains: (substring) => createComparison(["not", ["strContains", substring]]),
85
+ startsWith: (substring) => createComparison(["not", ["strStartsWith", substring]]),
86
+ endsWith: (substring) => createComparison(["not", ["strEndsWith", substring]]),
87
+ matchesRegex: (regex) => createComparison(["not", ["strMatchesRegex", regex]])
88
+ },
89
+ num: {
90
+ isGreaterThan: (value) => createComparison(["not", ["numIsGreaterThan", value]]),
91
+ isGreaterThanOrEqual: (value) => createComparison(["not", ["numIsGreaterThanOrEqual", value]]),
92
+ isLessThan: (value) => createComparison(["not", ["numIsLessThan", value]]),
93
+ isLessThanOrEqual: (value) => createComparison(["not", ["numIsLessThanOrEqual", value]]),
94
+ isInRange: (value) => createComparison(["not", ["numIsInRange", value]])
95
+ },
96
+ array: {
97
+ contains: (elements) => createComparison(["not", ["arrayContains", elements]]),
98
+ containsInOrder: (elements) => createComparison(["not", ["arrayContainsInOrder", elements]]),
99
+ startsWith: (elements) => createComparison(["not", ["arrayStartsWith", elements]]),
100
+ endsWith: (elements) => createComparison(["not", ["arrayEndsWith", elements]]),
101
+ length: (n) => createComparison(["not", ["arrayLength", n]]),
102
+ minLength: (n) => createComparison(["not", ["arrayMinLength", n]]),
103
+ maxLength: (n) => createComparison(["not", ["arrayMaxLength", n]]),
104
+ includes: (element) => createComparison(["not", ["arrayIncludes", element]]),
105
+ every: (matcher) => createComparison(["not", ["arrayEvery", matcher["~sc"]]]),
106
+ some: (matcher) => createComparison(["not", ["arraySome", matcher["~sc"]]])
107
+ },
108
+ jsonString: { hasPartial: (value) => createComparison(["not", ["jsonStringHasPartial", value]]) },
109
+ equal: (value) => createComparison(["not", ["deepEqual", value]]),
110
+ partialEqual: (value) => createComparison(["not", ["partialEqual", value]]),
111
+ custom: (value) => createComparison(["not", ["custom", value]]),
112
+ any: (...values) => createComparison(["not", ["any", values.map((v) => {
113
+ if (isComparison(v)) return v["~sc"];
114
+ if (typeof v === "object" && v !== null) return ["partialEqual", v];
115
+ return ["deepEqual", v];
116
+ })]]),
117
+ all: (...values) => createComparison(["not", ["all", values.map((v) => {
118
+ if (isComparison(v)) return v["~sc"];
119
+ if (typeof v === "object" && v !== null) return ["partialEqual", v];
120
+ return ["deepEqual", v];
121
+ })]]),
122
+ noExtraKeys: (partialShape) => createComparison(["not", ["withNoExtraKeys", partialShape]]),
123
+ deepNoExtraKeys: (partialShape) => createComparison(["not", ["withDeepNoExtraKeys", partialShape]]),
124
+ noExtraDefinedKeys: (partialShape) => createComparison(["not", ["noExtraDefinedKeys", partialShape]]),
125
+ deepNoExtraDefinedKeys: (partialShape) => createComparison(["not", ["deepNoExtraDefinedKeys", partialShape]]),
126
+ key: {
127
+ any: "$pqkc-not:any$",
128
+ anyOther: "$pqkc-not:anyOther$",
129
+ numeric: "$pqkc-not:numeric$",
130
+ startingWith: (substring) => `$pqkc-not:startingWith:${substring}$`,
131
+ endingWith: (substring) => `$pqkc-not:endingWith:${substring}$`,
132
+ containing: (substring) => `$pqkc-not:contains:${substring}$`,
133
+ matchingRegex: (regex) => `$pqkc-not:matchesRegex:${regex}$`
134
+ }
135
+ }
136
+ };
137
+ function isComparison(value) {
138
+ return value && typeof value === "object" && "~sc" in value;
139
+ }
140
+ function isKeyMatcher(key) {
141
+ return typeof key === "string" && (key.startsWith("$pqkc:") || key.startsWith("$pqkc-not:"));
142
+ }
143
+ function parseKeyMatcher(key) {
144
+ if (!isKeyMatcher(key)) return null;
145
+ const negated = key.startsWith("$pqkc-not:");
146
+ const prefix = negated ? "$pqkc-not:" : "$pqkc:";
147
+ if (!key.endsWith("$")) return null;
148
+ const content = key.slice(prefix.length, -1);
149
+ if (content === "any") return {
150
+ type: "any",
151
+ negated
152
+ };
153
+ if (content === "anyOther") return {
154
+ type: "anyOther",
155
+ negated
156
+ };
157
+ if (content === "numeric") return {
158
+ type: "numeric",
159
+ negated
160
+ };
161
+ if (content.startsWith("startingWith:")) return {
162
+ type: "startingWith",
163
+ parameter: content.slice(13),
164
+ negated
165
+ };
166
+ if (content.startsWith("endingWith:")) return {
167
+ type: "endingWith",
168
+ parameter: content.slice(11),
169
+ negated
170
+ };
171
+ if (content.startsWith("contains:")) return {
172
+ type: "contains",
173
+ parameter: content.slice(9),
174
+ negated
175
+ };
176
+ if (content.startsWith("matchesRegex:")) {
177
+ const regexStr = content.slice(13);
178
+ try {
179
+ if (regexStr.startsWith("/") && regexStr.lastIndexOf("/") > 0) {
180
+ const lastSlashIndex = regexStr.lastIndexOf("/");
181
+ const pattern = regexStr.slice(1, lastSlashIndex);
182
+ const flags = regexStr.slice(lastSlashIndex + 1);
183
+ return {
184
+ type: "matchesRegex",
185
+ parameter: new RegExp(pattern, flags),
186
+ negated
187
+ };
188
+ } else return {
189
+ type: "matchesRegex",
190
+ parameter: new RegExp(regexStr),
191
+ negated
192
+ };
193
+ } catch {
194
+ return null;
195
+ }
196
+ }
197
+ return null;
198
+ }
199
+ function keyMatchesPattern(key, matcher) {
200
+ let matches = false;
201
+ switch (matcher.type) {
202
+ case "any":
203
+ matches = true;
204
+ break;
205
+ case "anyOther":
206
+ matches = true;
207
+ break;
208
+ case "numeric":
209
+ matches = /^\d+$/.test(key);
210
+ break;
211
+ case "startingWith":
212
+ matches = key.startsWith(matcher.parameter);
213
+ break;
214
+ case "endingWith":
215
+ matches = key.endsWith(matcher.parameter);
216
+ break;
217
+ case "contains":
218
+ matches = key.includes(matcher.parameter);
219
+ break;
220
+ case "matchesRegex":
221
+ matches = matcher.parameter.test(key);
222
+ break;
223
+ }
224
+ return matcher.negated ? !matches : matches;
225
+ }
226
+ function executeComparison(target, comparison, context) {
227
+ const [type, value] = comparison;
228
+ switch (type) {
229
+ case "strStartsWith":
230
+ if (typeof target !== "string") {
231
+ addError(context, {
232
+ message: `Expected string starting with "${value}"`,
233
+ received: target
234
+ });
235
+ return false;
236
+ }
237
+ if (!target.startsWith(value)) {
238
+ addError(context, {
239
+ message: `Expected string starting with "${value}"`,
240
+ received: target
241
+ });
242
+ return false;
243
+ }
244
+ return true;
245
+ case "strEndsWith":
246
+ if (typeof target !== "string") {
247
+ addError(context, {
248
+ message: `Expected string ending with "${value}"`,
249
+ received: target
250
+ });
251
+ return false;
252
+ }
253
+ if (!target.endsWith(value)) {
254
+ addError(context, {
255
+ message: `Expected string ending with "${value}"`,
256
+ received: target
257
+ });
258
+ return false;
259
+ }
260
+ return true;
261
+ case "strContains":
262
+ if (typeof target !== "string") {
263
+ addError(context, {
264
+ message: `Expected string containing "${value}"`,
265
+ received: target
266
+ });
267
+ return false;
268
+ }
269
+ if (!target.includes(value)) {
270
+ addError(context, {
271
+ message: `Expected string containing "${value}"`,
272
+ received: target
273
+ });
274
+ return false;
275
+ }
276
+ return true;
277
+ case "strMatchesRegex":
278
+ if (typeof target !== "string") {
279
+ addError(context, {
280
+ message: `Expected string matching regex ${value}`,
281
+ received: target
282
+ });
283
+ return false;
284
+ }
285
+ if (!value.test(target)) {
286
+ addError(context, {
287
+ message: `Expected string matching regex ${value}`,
288
+ received: target
289
+ });
290
+ return false;
291
+ }
292
+ return true;
293
+ case "hasType": {
294
+ let actualType;
295
+ if (value === "array") actualType = Array.isArray(target) ? "array" : typeof target;
296
+ else if (value === "object") if (target === null || Array.isArray(target)) actualType = "not-object";
297
+ else actualType = typeof target;
298
+ else actualType = typeof target;
299
+ if (actualType !== value) {
300
+ addError(context, {
301
+ message: `Expected type ${value}`,
302
+ received: target
303
+ });
304
+ return false;
305
+ }
306
+ return true;
307
+ }
308
+ case "deepEqual":
309
+ if (!deepEqual(target, value)) {
310
+ addError(context, {
311
+ message: "Values are not deeply equal",
312
+ received: target,
313
+ expected: value
314
+ });
315
+ return false;
316
+ }
317
+ return true;
318
+ case "numIsGreaterThan":
319
+ if (typeof target !== "number" || target <= value) {
320
+ addError(context, {
321
+ message: `Expected number greater than ${value}`,
322
+ received: target
323
+ });
324
+ return false;
325
+ }
326
+ return true;
327
+ case "numIsGreaterThanOrEqual":
328
+ if (typeof target !== "number" || target < value) {
329
+ addError(context, {
330
+ message: `Expected number greater than or equal to ${value}`,
331
+ received: target
332
+ });
333
+ return false;
334
+ }
335
+ return true;
336
+ case "numIsLessThan":
337
+ if (typeof target !== "number" || target >= value) {
338
+ addError(context, {
339
+ message: `Expected number less than ${value}`,
340
+ received: target
341
+ });
342
+ return false;
343
+ }
344
+ return true;
345
+ case "numIsLessThanOrEqual":
346
+ if (typeof target !== "number" || target > value) {
347
+ addError(context, {
348
+ message: `Expected number less than or equal to ${value}`,
349
+ received: target
350
+ });
351
+ return false;
352
+ }
353
+ return true;
354
+ case "numIsInRange":
355
+ if (typeof target !== "number" || target < value[0] || target > value[1]) {
356
+ addError(context, {
357
+ message: `Expected number in range [${value[0]}, ${value[1]}]`,
358
+ received: target
359
+ });
360
+ return false;
361
+ }
362
+ return true;
363
+ case "jsonStringHasPartial":
364
+ if (typeof target !== "string") {
365
+ addError(context, {
366
+ message: "Expected JSON string",
367
+ received: target
368
+ });
369
+ return false;
370
+ }
371
+ try {
372
+ if (!partialEqualInternal(JSON.parse(target), value, context)) return false;
373
+ } catch {
374
+ addError(context, {
375
+ message: "Expected valid JSON string",
376
+ received: target
377
+ });
378
+ return false;
379
+ }
380
+ return true;
381
+ case "partialEqual": return partialEqualInternal(target, value, context);
382
+ case "custom": {
383
+ const result = value(target);
384
+ if (result !== true) {
385
+ addError(context, {
386
+ message: `Custom validation failed ${typeof result === "object" ? `: ${result.error}` : ""}`,
387
+ received: target
388
+ });
389
+ return false;
390
+ }
391
+ return true;
392
+ }
393
+ case "isInstanceOf":
394
+ if (!(target instanceof value)) {
395
+ addError(context, {
396
+ message: `Expected instance of ${value.name}`,
397
+ received: target
398
+ });
399
+ return false;
400
+ }
401
+ return true;
402
+ case "keyNotBePresent":
403
+ addError(context, {
404
+ message: "This property should not be present",
405
+ received: target
406
+ });
407
+ return false;
408
+ case "not":
409
+ if (executeComparison(target, value, {
410
+ errors: [],
411
+ path: context.path
412
+ })) {
413
+ addError(context, {
414
+ message: "Expected negated condition to fail",
415
+ received: target,
416
+ expected: { "not match": value }
417
+ });
418
+ return false;
419
+ }
420
+ return true;
421
+ case "any":
422
+ for (const subComparison of value) if (executeComparison(target, subComparison, {
423
+ errors: [],
424
+ path: context.path
425
+ })) return true;
426
+ addError(context, {
427
+ message: "None of the alternative comparisons matched",
428
+ received: target,
429
+ expected: { matchAny: value }
430
+ });
431
+ return false;
432
+ case "all": {
433
+ let allMatch = true;
434
+ for (const subComparison of value) if (!executeComparison(target, subComparison, context)) allMatch = false;
435
+ return allMatch;
436
+ }
437
+ case "withNoExtraKeys": return checkNoExtraKeys(target, value, context, false);
438
+ case "withDeepNoExtraKeys": return checkNoExtraKeys(target, value, context, true);
439
+ case "noExtraDefinedKeys": return checkNoExtraDefinedKeys(target, value, context, false);
440
+ case "deepNoExtraDefinedKeys": return checkNoExtraDefinedKeys(target, value, context, true);
441
+ case "arrayContains":
442
+ if (!Array.isArray(target)) {
443
+ addError(context, {
444
+ message: "Expected array",
445
+ received: target
446
+ });
447
+ return false;
448
+ }
449
+ for (const element of value) {
450
+ let found = false;
451
+ for (const targetElement of target) if (partialEqualInternal(targetElement, element, {
452
+ errors: [],
453
+ path: context.path
454
+ })) {
455
+ found = true;
456
+ break;
457
+ }
458
+ if (!found) {
459
+ addError(context, {
460
+ message: "Array does not contain expected element",
461
+ received: target,
462
+ expected: element
463
+ });
464
+ return false;
465
+ }
466
+ }
467
+ return true;
468
+ case "arrayContainsInOrder": {
469
+ if (!Array.isArray(target)) {
470
+ addError(context, {
471
+ message: "Expected array",
472
+ received: target
473
+ });
474
+ return false;
475
+ }
476
+ let targetIndex = 0;
477
+ for (const element of value) {
478
+ let found = false;
479
+ for (let i = targetIndex; i < target.length; i++) {
480
+ const tempContext = {
481
+ errors: [],
482
+ path: context.path
483
+ };
484
+ if (partialEqualInternal(target[i], element, tempContext)) {
485
+ targetIndex = i + 1;
486
+ found = true;
487
+ break;
488
+ }
489
+ }
490
+ if (!found) {
491
+ addError(context, {
492
+ message: "Array does not contain expected elements in order",
493
+ received: target,
494
+ expected: value
495
+ });
496
+ return false;
497
+ }
498
+ }
499
+ return true;
500
+ }
501
+ case "arrayStartsWith": {
502
+ if (!Array.isArray(target)) {
503
+ addError(context, {
504
+ message: "Expected array",
505
+ received: target
506
+ });
507
+ return false;
508
+ }
509
+ if (target.length < value.length) {
510
+ addError(context, {
511
+ message: `Array too short: expected to start with ${value.length} elements, got ${target.length}`,
512
+ received: target,
513
+ expected: value
514
+ });
515
+ return false;
516
+ }
517
+ let allMatch = true;
518
+ for (let i = 0; i < value.length; i++) {
519
+ const oldPath = context.path;
520
+ context.path = [...oldPath, `[${i}]`];
521
+ const result = partialEqualInternal(target[i], value[i], context);
522
+ context.path = oldPath;
523
+ if (!result) allMatch = false;
524
+ }
525
+ return allMatch;
526
+ }
527
+ case "arrayEndsWith": {
528
+ if (!Array.isArray(target)) {
529
+ addError(context, {
530
+ message: "Expected array",
531
+ received: target
532
+ });
533
+ return false;
534
+ }
535
+ if (target.length < value.length) {
536
+ addError(context, {
537
+ message: `Array too short: expected to end with ${value.length} elements, got ${target.length}`,
538
+ received: target,
539
+ expected: value
540
+ });
541
+ return false;
542
+ }
543
+ let allMatch = true;
544
+ const startIndex = target.length - value.length;
545
+ for (let i = 0; i < value.length; i++) {
546
+ const oldPath = context.path;
547
+ context.path = [...oldPath, `[${startIndex + i}]`];
548
+ const result = partialEqualInternal(target[startIndex + i], value[i], context);
549
+ context.path = oldPath;
550
+ if (!result) allMatch = false;
551
+ }
552
+ return allMatch;
553
+ }
554
+ case "arrayLength":
555
+ if (!Array.isArray(target)) {
556
+ addError(context, {
557
+ message: "Expected array",
558
+ received: target
559
+ });
560
+ return false;
561
+ }
562
+ if (target.length !== value) {
563
+ addError(context, {
564
+ message: `Expected array length ${value}, got ${target.length}`,
565
+ received: target
566
+ });
567
+ return false;
568
+ }
569
+ return true;
570
+ case "arrayMinLength":
571
+ if (!Array.isArray(target)) {
572
+ addError(context, {
573
+ message: "Expected array",
574
+ received: target
575
+ });
576
+ return false;
577
+ }
578
+ if (target.length < value) {
579
+ addError(context, {
580
+ message: `Expected array with at least ${value} elements, got ${target.length}`,
581
+ received: target
582
+ });
583
+ return false;
584
+ }
585
+ return true;
586
+ case "arrayMaxLength":
587
+ if (!Array.isArray(target)) {
588
+ addError(context, {
589
+ message: "Expected array",
590
+ received: target
591
+ });
592
+ return false;
593
+ }
594
+ if (target.length > value) {
595
+ addError(context, {
596
+ message: `Expected array with at most ${value} elements, got ${target.length}`,
597
+ received: target
598
+ });
599
+ return false;
600
+ }
601
+ return true;
602
+ case "arrayIncludes": {
603
+ if (!Array.isArray(target)) {
604
+ addError(context, {
605
+ message: "Expected array",
606
+ received: target
607
+ });
608
+ return false;
609
+ }
610
+ let found = false;
611
+ for (const targetElement of target) if (partialEqualInternal(targetElement, value, {
612
+ errors: [],
613
+ path: context.path
614
+ })) {
615
+ found = true;
616
+ break;
617
+ }
618
+ if (!found) {
619
+ addError(context, {
620
+ message: "Array does not include expected element",
621
+ received: target,
622
+ expected: value
623
+ });
624
+ return false;
625
+ }
626
+ return true;
627
+ }
628
+ case "arrayEvery": {
629
+ if (!Array.isArray(target)) {
630
+ addError(context, {
631
+ message: "Expected array",
632
+ received: target
633
+ });
634
+ return false;
635
+ }
636
+ let allMatch = true;
637
+ for (let i = 0; i < target.length; i++) {
638
+ const oldPath = context.path;
639
+ context.path = [...oldPath, `[${i}]`];
640
+ const result = executeComparison(target[i], value, context);
641
+ context.path = oldPath;
642
+ if (!result) allMatch = false;
643
+ }
644
+ return allMatch;
645
+ }
646
+ case "arraySome":
647
+ if (!Array.isArray(target)) {
648
+ addError(context, {
649
+ message: "Expected array",
650
+ received: target
651
+ });
652
+ return false;
653
+ }
654
+ for (let i = 0; i < target.length; i++) {
655
+ const tempContext = {
656
+ errors: [],
657
+ path: [...context.path, `[${i}]`]
658
+ };
659
+ if (executeComparison(target[i], value, tempContext)) return true;
660
+ }
661
+ addError(context, {
662
+ message: "No array element matches the condition",
663
+ received: target
664
+ });
665
+ return false;
666
+ default: throw exhaustiveCheck(type);
667
+ }
668
+ }
669
+ function formatPath(path) {
670
+ if (path.length === 0) return "";
671
+ let result = path[0] || "";
672
+ for (let i = 1; i < path.length; i++) {
673
+ const segment = path[i];
674
+ if (segment && segment.startsWith("[") && segment.endsWith("]")) result += segment;
675
+ else if (segment) if (result) result += `.${segment}`;
676
+ else result += segment;
677
+ }
678
+ return result;
679
+ }
680
+ function addError(context, error) {
681
+ context.errors.push({
682
+ path: formatPath(context.path),
683
+ ...error
684
+ });
685
+ }
686
+ function deepEqual(a, b) {
687
+ if (a === b) return true;
688
+ if (Number.isNaN(a) && Number.isNaN(b)) return true;
689
+ if (a === null || b === null) return false;
690
+ if (typeof a !== typeof b) return false;
691
+ if (Array.isArray(a) && Array.isArray(b)) {
692
+ if (a.length !== b.length) return false;
693
+ for (let i = 0; i < a.length; i++) if (!deepEqual(a[i], b[i])) return false;
694
+ return true;
695
+ }
696
+ if (typeof a === "object") {
697
+ const keysA = Object.keys(a);
698
+ const keysB = Object.keys(b);
699
+ if (keysA.length !== keysB.length) return false;
700
+ for (const key of keysA) if (!has.call(b, key) || !deepEqual(a[key], b[key])) return false;
701
+ return true;
702
+ }
703
+ return false;
704
+ }
705
+ function partialEqualInternal(target, sub, context) {
706
+ if (isComparison(sub)) return executeComparison(target, sub["~sc"], context);
707
+ if (isComparison(sub) && sub["~sc"][0] === "keyNotBePresent") {
708
+ addError(context, {
709
+ message: "This property should not be present",
710
+ received: target
711
+ });
712
+ return false;
713
+ }
714
+ if (target === sub) return true;
715
+ if (Number.isNaN(target) && Number.isNaN(sub)) return true;
716
+ if (target === null || sub === null || target === void 0 || sub === void 0) {
717
+ if (target !== sub) {
718
+ addError(context, {
719
+ message: "Value mismatch",
720
+ received: target,
721
+ expected: sub
722
+ });
723
+ return false;
724
+ }
725
+ return true;
726
+ }
727
+ if (target instanceof Date && sub instanceof Date) {
728
+ if (target.getTime() !== sub.getTime()) {
729
+ addError(context, {
730
+ message: "Date mismatch",
731
+ received: target,
732
+ expected: sub
733
+ });
734
+ return false;
735
+ }
736
+ return true;
737
+ }
738
+ if (target instanceof RegExp && sub instanceof RegExp) {
739
+ if (target.source !== sub.source || target.flags !== sub.flags) {
740
+ addError(context, {
741
+ message: "RegExp mismatch",
742
+ received: target,
743
+ expected: sub
744
+ });
745
+ return false;
746
+ }
747
+ return true;
748
+ }
749
+ if (target instanceof Set && sub instanceof Set) {
750
+ if (sub.size > target.size) {
751
+ addError(context, {
752
+ message: "Set too small",
753
+ received: target,
754
+ expected: sub
755
+ });
756
+ return false;
757
+ }
758
+ for (const subValue of sub) {
759
+ let found = false;
760
+ for (const targetValue of target) if (partialEqualInternal(targetValue, subValue, {
761
+ errors: [],
762
+ path: context.path
763
+ })) {
764
+ found = true;
765
+ break;
766
+ }
767
+ if (!found) {
768
+ addError(context, {
769
+ message: "Set element not found",
770
+ received: target,
771
+ expected: sub
772
+ });
773
+ return false;
774
+ }
775
+ }
776
+ return true;
777
+ }
778
+ if (target instanceof Map && sub instanceof Map) {
779
+ if (sub.size > target.size) {
780
+ addError(context, {
781
+ message: "Map has less entries than expected",
782
+ received: `${target.size} entries`,
783
+ expected: `${sub.size} entries`
784
+ });
785
+ return false;
786
+ }
787
+ for (const [subKey, subValue] of sub) {
788
+ let found = false;
789
+ for (const [targetKey, targetValue] of target) {
790
+ const tempContextKey = {
791
+ errors: [],
792
+ path: context.path
793
+ };
794
+ const tempContextValue = {
795
+ errors: [],
796
+ path: context.path
797
+ };
798
+ if (partialEqualInternal(targetKey, subKey, tempContextKey) && partialEqualInternal(targetValue, subValue, tempContextValue)) {
799
+ found = true;
800
+ break;
801
+ }
802
+ }
803
+ if (!found) {
804
+ addError(context, {
805
+ message: "Map entry not found",
806
+ received: target,
807
+ expected: sub
808
+ });
809
+ return false;
810
+ }
811
+ }
812
+ return true;
813
+ }
814
+ if (typeof target !== typeof sub) {
815
+ addError(context, {
816
+ message: "Value mismatch",
817
+ received: target,
818
+ expected: sub
819
+ });
820
+ return false;
821
+ }
822
+ if (Array.isArray(sub)) {
823
+ if (!Array.isArray(target)) {
824
+ addError(context, {
825
+ message: "Expected array",
826
+ received: target,
827
+ expected: sub
828
+ });
829
+ return false;
830
+ }
831
+ if (target.length < sub.length) {
832
+ addError(context, {
833
+ message: `Array too short: expected at least ${sub.length} elements, got ${target.length}`,
834
+ received: target,
835
+ expected: sub
836
+ });
837
+ return false;
838
+ }
839
+ let allMatch = true;
840
+ for (let i = 0; i < sub.length; i++) {
841
+ const oldPath = context.path;
842
+ context.path = [...oldPath, `[${i}]`];
843
+ const result = partialEqualInternal(target[i], sub[i], context);
844
+ context.path = oldPath;
845
+ if (!result) allMatch = false;
846
+ }
847
+ return allMatch;
848
+ }
849
+ if (typeof sub === "object") {
850
+ if (typeof target !== "object" || Array.isArray(target)) {
851
+ addError(context, {
852
+ message: "Expected object",
853
+ received: target,
854
+ expected: sub
855
+ });
856
+ return false;
857
+ }
858
+ let allMatch = true;
859
+ const regularKeys = [];
860
+ const keyMatchers = [];
861
+ for (const key of Object.keys(sub)) if (isKeyMatcher(key)) {
862
+ const matcher = parseKeyMatcher(key);
863
+ if (matcher) keyMatchers.push({
864
+ key,
865
+ matcher,
866
+ value: sub[key]
867
+ });
868
+ } else regularKeys.push(key);
869
+ const explicitlySpecifiedKeys = /* @__PURE__ */ new Set();
870
+ for (const key of regularKeys) {
871
+ explicitlySpecifiedKeys.add(key);
872
+ if (isComparison(sub[key]) && sub[key]["~sc"][0] === "keyNotBePresent") {
873
+ if (has.call(target, key)) {
874
+ const oldPath$1 = context.path;
875
+ context.path = [...oldPath$1, key];
876
+ addError(context, {
877
+ message: "Key should not be present",
878
+ received: target[key]
879
+ });
880
+ context.path = oldPath$1;
881
+ allMatch = false;
882
+ }
883
+ continue;
884
+ }
885
+ if (!has.call(target, key)) {
886
+ if (isComparison(sub[key])) {
887
+ const comparison = sub[key]["~sc"];
888
+ if (comparison[0] === "any") {
889
+ if (comparison[1].some((comp) => comp[0] === "keyNotBePresent")) continue;
890
+ }
891
+ }
892
+ const oldPath$1 = context.path;
893
+ context.path = [...oldPath$1, key];
894
+ addError(context, {
895
+ message: "Missing property",
896
+ expected: sub[key],
897
+ received: { objectWithKeys: Object.keys(target) }
898
+ });
899
+ context.path = oldPath$1;
900
+ allMatch = false;
901
+ continue;
902
+ }
903
+ const oldPath = context.path;
904
+ context.path = [...oldPath, key];
905
+ const result = partialEqualInternal(target[key], sub[key], context);
906
+ context.path = oldPath;
907
+ if (!result) allMatch = false;
908
+ }
909
+ for (const { matcher, value } of keyMatchers) {
910
+ let foundMatch = false;
911
+ const matchedKeys = [];
912
+ if (matcher.type === "anyOther") {
913
+ for (const targetKey of Object.keys(target)) if (!explicitlySpecifiedKeys.has(targetKey)) {
914
+ if (keyMatchesPattern(targetKey, matcher)) {
915
+ foundMatch = true;
916
+ matchedKeys.push(targetKey);
917
+ const oldPath = context.path;
918
+ context.path = [...oldPath, targetKey];
919
+ const result = partialEqualInternal(target[targetKey], value, context);
920
+ context.path = oldPath;
921
+ if (!result) allMatch = false;
922
+ }
923
+ }
924
+ } else if (matcher.type === "any") {
925
+ let anyKeyMatched = false;
926
+ for (const targetKey of Object.keys(target)) if (keyMatchesPattern(targetKey, matcher)) {
927
+ foundMatch = true;
928
+ matchedKeys.push(targetKey);
929
+ explicitlySpecifiedKeys.add(targetKey);
930
+ const tempContext = {
931
+ errors: [],
932
+ path: [...context.path, targetKey]
933
+ };
934
+ if (partialEqualInternal(target[targetKey], value, tempContext)) {
935
+ anyKeyMatched = true;
936
+ break;
937
+ }
938
+ }
939
+ if (foundMatch && !anyKeyMatched) {
940
+ addError(context, {
941
+ message: `No keys matching pattern had the expected value`,
942
+ received: {
943
+ keysChecked: matchedKeys,
944
+ availableKeys: Object.keys(target)
945
+ }
946
+ });
947
+ allMatch = false;
948
+ }
949
+ } else for (const targetKey of Object.keys(target)) if (keyMatchesPattern(targetKey, matcher)) {
950
+ foundMatch = true;
951
+ matchedKeys.push(targetKey);
952
+ explicitlySpecifiedKeys.add(targetKey);
953
+ const oldPath = context.path;
954
+ context.path = [...oldPath, targetKey];
955
+ const result = partialEqualInternal(target[targetKey], value, context);
956
+ context.path = oldPath;
957
+ if (!result) allMatch = false;
958
+ }
959
+ if (!foundMatch) {
960
+ addError(context, {
961
+ message: `No keys found matching pattern: ${matcher.type === "anyOther" ? "anyOther (keys not explicitly specified)" : `${matcher.type}${matcher.parameter ? ` (${matcher.parameter})` : ""}`}`,
962
+ received: {
963
+ availableKeys: Object.keys(target),
964
+ explicitKeys: Array.from(explicitlySpecifiedKeys)
965
+ }
966
+ });
967
+ allMatch = false;
968
+ }
969
+ }
970
+ return allMatch;
971
+ }
972
+ if (target !== sub) {
973
+ addError(context, {
974
+ message: "Value mismatch",
975
+ received: target,
976
+ expected: sub
977
+ });
978
+ return false;
979
+ }
980
+ return true;
981
+ }
982
+ function checkNoExtraKeys(target, partialShape, context, deep) {
983
+ if (typeof target !== "object" || target === null || Array.isArray(target)) {
984
+ addError(context, {
985
+ message: "Expected object for key validation",
986
+ received: target
987
+ });
988
+ return false;
989
+ }
990
+ if (!partialEqualInternal(target, partialShape, context)) return false;
991
+ const allowedKeys = new Set(Object.keys(partialShape));
992
+ for (const key of Object.keys(target)) if (!allowedKeys.has(key)) {
993
+ const oldPath = context.path;
994
+ context.path = [...oldPath, key];
995
+ addError(context, {
996
+ message: `Extra key "${key}" should not be present`,
997
+ received: target[key]
998
+ });
999
+ context.path = oldPath;
1000
+ return false;
1001
+ }
1002
+ if (deep) {
1003
+ for (const key of Object.keys(partialShape)) if (typeof partialShape[key] === "object" && partialShape[key] !== null && !Array.isArray(partialShape[key]) && !isComparison(partialShape[key])) {
1004
+ const oldPath = context.path;
1005
+ context.path = [...oldPath, key];
1006
+ const result = checkNoExtraKeys(target[key], partialShape[key], context, true);
1007
+ context.path = oldPath;
1008
+ if (!result) return false;
1009
+ }
1010
+ }
1011
+ return true;
1012
+ }
1013
+ function checkNoExtraDefinedKeys(target, partialShape, context, deep) {
1014
+ if (typeof target !== "object" || target === null || Array.isArray(target)) {
1015
+ addError(context, {
1016
+ message: "Expected object for key validation",
1017
+ received: target
1018
+ });
1019
+ return false;
1020
+ }
1021
+ if (!partialEqualInternal(target, partialShape, context)) return false;
1022
+ const allowedKeys = new Set(Object.keys(partialShape));
1023
+ for (const key of Object.keys(target)) if (!allowedKeys.has(key) && target[key] !== void 0) {
1024
+ const oldPath = context.path;
1025
+ context.path = [...oldPath, key];
1026
+ addError(context, {
1027
+ message: `Extra defined key "${key}" should not be present`,
1028
+ received: target[key]
1029
+ });
1030
+ context.path = oldPath;
1031
+ return false;
1032
+ }
1033
+ if (deep) {
1034
+ for (const key of Object.keys(partialShape)) if (typeof partialShape[key] === "object" && partialShape[key] !== null && !Array.isArray(partialShape[key]) && !isComparison(partialShape[key])) {
1035
+ const oldPath = context.path;
1036
+ context.path = [...oldPath, key];
1037
+ const result = checkNoExtraDefinedKeys(target[key], partialShape[key], context, true);
1038
+ context.path = oldPath;
1039
+ if (!result) return false;
1040
+ }
1041
+ }
1042
+ return true;
1043
+ }
1044
+ function partialEqual(target, sub, returnErrors) {
1045
+ const context = {
1046
+ errors: [],
1047
+ path: []
1048
+ };
1049
+ const result = partialEqualInternal(target, sub, context);
1050
+ if (returnErrors) return result ? ok(void 0) : err(context.errors);
1051
+ return result;
1052
+ }
1053
+
1054
+ //#endregion
1055
+ export { match, partialEqual };