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