@adobe/data 0.1.2

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/README.md +310 -0
  2. package/assembly/index.d.ts +30 -0
  3. package/assembly/index.js +18 -0
  4. package/assembly/index.wasm +0 -0
  5. package/assembly/index.wasm.map +1 -0
  6. package/assembly-test/assembly.test.d.ts +1 -0
  7. package/assembly-test/assembly.test.js +29 -0
  8. package/assembly-test/assembly.test.js.map +1 -0
  9. package/cache/async-cache.d.ts +15 -0
  10. package/cache/async-cache.js +23 -0
  11. package/cache/async-cache.js.map +1 -0
  12. package/cache/blob-store.d.ts +94 -0
  13. package/cache/blob-store.js +191 -0
  14. package/cache/blob-store.js.map +1 -0
  15. package/cache/blob-store.test.d.ts +1 -0
  16. package/cache/blob-store.test.js +142 -0
  17. package/cache/blob-store.test.js.map +1 -0
  18. package/cache/data-cache.d.ts +38 -0
  19. package/cache/data-cache.js +96 -0
  20. package/cache/data-cache.js.map +1 -0
  21. package/cache/data-cache.test.d.ts +1 -0
  22. package/cache/data-cache.test.js +50 -0
  23. package/cache/data-cache.test.js.map +1 -0
  24. package/cache/expiring-data-cache.d.ts +6 -0
  25. package/cache/expiring-data-cache.js +49 -0
  26. package/cache/expiring-data-cache.js.map +1 -0
  27. package/cache/expiring-data-cache.test.d.ts +1 -0
  28. package/cache/expiring-data-cache.test.js +62 -0
  29. package/cache/expiring-data-cache.test.js.map +1 -0
  30. package/cache/fallback-async-cache.d.ts +7 -0
  31. package/cache/fallback-async-cache.js +22 -0
  32. package/cache/fallback-async-cache.js.map +1 -0
  33. package/cache/functions/bind-functions.d.ts +6 -0
  34. package/cache/functions/bind-functions.js +33 -0
  35. package/cache/functions/bind-functions.js.map +1 -0
  36. package/cache/functions/functions.test.d.ts +1 -0
  37. package/cache/functions/functions.test.js +79 -0
  38. package/cache/functions/functions.test.js.map +1 -0
  39. package/cache/functions/get-cached.d.ts +11 -0
  40. package/cache/functions/get-cached.js +49 -0
  41. package/cache/functions/get-cached.js.map +1 -0
  42. package/cache/functions/get-cached.test.d.ts +1 -0
  43. package/cache/functions/get-cached.test.js +96 -0
  44. package/cache/functions/get-cached.test.js.map +1 -0
  45. package/cache/functions/hashing/blob-to-hash.d.ts +4 -0
  46. package/cache/functions/hashing/blob-to-hash.js +44 -0
  47. package/cache/functions/hashing/blob-to-hash.js.map +1 -0
  48. package/cache/functions/hashing/buffer-to-hash.d.ts +4 -0
  49. package/cache/functions/hashing/buffer-to-hash.js +33 -0
  50. package/cache/functions/hashing/buffer-to-hash.js.map +1 -0
  51. package/cache/functions/hashing/hashing.test.d.ts +1 -0
  52. package/cache/functions/hashing/hashing.test.js +95 -0
  53. package/cache/functions/hashing/hashing.test.js.map +1 -0
  54. package/cache/functions/hashing/index.d.ts +4 -0
  55. package/cache/functions/hashing/index.js +26 -0
  56. package/cache/functions/hashing/index.js.map +1 -0
  57. package/cache/functions/hashing/json-to-hash.d.ts +4 -0
  58. package/cache/functions/hashing/json-to-hash.js +29 -0
  59. package/cache/functions/hashing/json-to-hash.js.map +1 -0
  60. package/cache/functions/hashing/string-to-hash.d.ts +4 -0
  61. package/cache/functions/hashing/string-to-hash.js +37 -0
  62. package/cache/functions/hashing/string-to-hash.js.map +1 -0
  63. package/cache/functions/index.d.ts +5 -0
  64. package/cache/functions/index.js +29 -0
  65. package/cache/functions/index.js.map +1 -0
  66. package/cache/functions/memoize.d.ts +12 -0
  67. package/cache/functions/memoize.js +48 -0
  68. package/cache/functions/memoize.js.map +1 -0
  69. package/cache/functions/omit.d.ts +1 -0
  70. package/cache/functions/omit.js +29 -0
  71. package/cache/functions/omit.js.map +1 -0
  72. package/cache/functions/prevent-parallel-execution.d.ts +7 -0
  73. package/cache/functions/prevent-parallel-execution.js +25 -0
  74. package/cache/functions/prevent-parallel-execution.js.map +1 -0
  75. package/cache/functions/types.d.ts +1 -0
  76. package/cache/functions/types.js +23 -0
  77. package/cache/functions/types.js.map +1 -0
  78. package/cache/get-persistent-cache.d.ts +12 -0
  79. package/cache/get-persistent-cache.js +23 -0
  80. package/cache/get-persistent-cache.js.map +1 -0
  81. package/cache/index.d.ts +3 -0
  82. package/cache/index.js +25 -0
  83. package/cache/index.js.map +1 -0
  84. package/cache/managed-array.d.ts +23 -0
  85. package/cache/managed-array.js +160 -0
  86. package/cache/managed-array.js.map +1 -0
  87. package/cache/managed-async-cache.browser.test.d.ts +1 -0
  88. package/cache/managed-async-cache.browser.test.js +50 -0
  89. package/cache/managed-async-cache.browser.test.js.map +1 -0
  90. package/cache/managed-async-cache.d.ts +4 -0
  91. package/cache/managed-async-cache.js +45 -0
  92. package/cache/managed-async-cache.js.map +1 -0
  93. package/cache/memory-allocator.d.ts +23 -0
  94. package/cache/memory-allocator.js +94 -0
  95. package/cache/memory-allocator.js.map +1 -0
  96. package/cache/memory-async-cache.d.ts +6 -0
  97. package/cache/memory-async-cache.js +23 -0
  98. package/cache/memory-async-cache.js.map +1 -0
  99. package/core/data.d.ts +22 -0
  100. package/core/data.js +52 -0
  101. package/core/data.js.map +1 -0
  102. package/core/data.test.d.ts +1 -0
  103. package/core/data.test.js +48 -0
  104. package/core/data.test.js.map +1 -0
  105. package/core/functions/array-equals.d.ts +1 -0
  106. package/core/functions/array-equals.js +34 -0
  107. package/core/functions/array-equals.js.map +1 -0
  108. package/core/functions/deep-merge.d.ts +31 -0
  109. package/core/functions/deep-merge.js +51 -0
  110. package/core/functions/deep-merge.js.map +1 -0
  111. package/core/functions/deep-merge.test.d.ts +1 -0
  112. package/core/functions/deep-merge.test.js +94 -0
  113. package/core/functions/deep-merge.test.js.map +1 -0
  114. package/core/functions/index.d.ts +4 -0
  115. package/core/functions/index.js +26 -0
  116. package/core/functions/index.js.map +1 -0
  117. package/core/functions/is-async-generator.d.ts +1 -0
  118. package/core/functions/is-async-generator.js +25 -0
  119. package/core/functions/is-async-generator.js.map +1 -0
  120. package/core/functions/is-promise.d.ts +1 -0
  121. package/core/functions/is-promise.js +26 -0
  122. package/core/functions/is-promise.js.map +1 -0
  123. package/core/functions/with-validation.d.ts +5 -0
  124. package/core/functions/with-validation.js +38 -0
  125. package/core/functions/with-validation.js.map +1 -0
  126. package/core/functions/with-validation.test.d.ts +1 -0
  127. package/core/functions/with-validation.test.js +96 -0
  128. package/core/functions/with-validation.test.js.map +1 -0
  129. package/core/index.d.ts +3 -0
  130. package/core/index.js +25 -0
  131. package/core/index.js.map +1 -0
  132. package/core/schema.d.ts +86 -0
  133. package/core/schema.js +33 -0
  134. package/core/schema.js.map +1 -0
  135. package/core/schema.test.d.ts +1 -0
  136. package/core/schema.test.js +16 -0
  137. package/core/schema.test.js.map +1 -0
  138. package/ecs/action-ecs/action-ecs.d.ts +19 -0
  139. package/ecs/action-ecs/action-ecs.js +203 -0
  140. package/ecs/action-ecs/action-ecs.js.map +1 -0
  141. package/ecs/action-ecs/action-ecs.test.d.ts +1 -0
  142. package/ecs/action-ecs/action-ecs.test.js +362 -0
  143. package/ecs/action-ecs/action-ecs.test.js.map +1 -0
  144. package/ecs/action-ecs/action-types.d.ts +106 -0
  145. package/ecs/action-ecs/action-types.js +19 -0
  146. package/ecs/action-ecs/action-types.js.map +1 -0
  147. package/ecs/action-ecs/index.d.ts +2 -0
  148. package/ecs/action-ecs/index.js +23 -0
  149. package/ecs/action-ecs/index.js.map +1 -0
  150. package/ecs/core-ecs/core-ecs-serialization.test.d.ts +1 -0
  151. package/ecs/core-ecs/core-ecs-serialization.test.js +230 -0
  152. package/ecs/core-ecs/core-ecs-serialization.test.js.map +1 -0
  153. package/ecs/core-ecs/core-ecs-types.d.ts +141 -0
  154. package/ecs/core-ecs/core-ecs-types.js +23 -0
  155. package/ecs/core-ecs/core-ecs-types.js.map +1 -0
  156. package/ecs/core-ecs/core-ecs.d.ts +7 -0
  157. package/ecs/core-ecs/core-ecs.js +492 -0
  158. package/ecs/core-ecs/core-ecs.js.map +1 -0
  159. package/ecs/core-ecs/core-ecs.test.d.ts +1 -0
  160. package/ecs/core-ecs/core-ecs.test.js +404 -0
  161. package/ecs/core-ecs/core-ecs.test.js.map +1 -0
  162. package/ecs/core-ecs/index.d.ts +1 -0
  163. package/ecs/core-ecs/index.js +2 -0
  164. package/ecs/core-ecs/index.js.map +1 -0
  165. package/ecs/ecs/ecs-types.d.ts +132 -0
  166. package/ecs/ecs/ecs-types.js +23 -0
  167. package/ecs/ecs/ecs-types.js.map +1 -0
  168. package/ecs/ecs/ecs-where-functions.d.ts +6 -0
  169. package/ecs/ecs/ecs-where-functions.js +91 -0
  170. package/ecs/ecs/ecs-where-functions.js.map +1 -0
  171. package/ecs/ecs/ecs.d.ts +13 -0
  172. package/ecs/ecs/ecs.js +177 -0
  173. package/ecs/ecs/ecs.js.map +1 -0
  174. package/ecs/ecs/ecs.test.d.ts +1 -0
  175. package/ecs/ecs/ecs.test.js +399 -0
  176. package/ecs/ecs/ecs.test.js.map +1 -0
  177. package/ecs/ecs/index.d.ts +3 -0
  178. package/ecs/ecs/index.js +3 -0
  179. package/ecs/ecs/index.js.map +1 -0
  180. package/ecs/index.d.ts +4 -0
  181. package/ecs/index.js +26 -0
  182. package/ecs/index.js.map +1 -0
  183. package/ecs/transaction-ecs/index.d.ts +2 -0
  184. package/ecs/transaction-ecs/index.js +24 -0
  185. package/ecs/transaction-ecs/index.js.map +1 -0
  186. package/ecs/transaction-ecs/transaction-ecs.d.ts +11 -0
  187. package/ecs/transaction-ecs/transaction-ecs.js +184 -0
  188. package/ecs/transaction-ecs/transaction-ecs.js.map +1 -0
  189. package/ecs/transaction-ecs/transaction-ecs.test.d.ts +1 -0
  190. package/ecs/transaction-ecs/transaction-ecs.test.js +599 -0
  191. package/ecs/transaction-ecs/transaction-ecs.test.js.map +1 -0
  192. package/ecs/transaction-ecs/transaction-types.d.ts +135 -0
  193. package/ecs/transaction-ecs/transaction-types.js +2 -0
  194. package/ecs/transaction-ecs/transaction-types.js.map +1 -0
  195. package/ecs/transaction-ecs/transactions.d.ts +5 -0
  196. package/ecs/transaction-ecs/transactions.js +158 -0
  197. package/ecs/transaction-ecs/transactions.js.map +1 -0
  198. package/index.d.ts +1 -0
  199. package/index.js +23 -0
  200. package/index.js.map +1 -0
  201. package/observe/create-observable-event.d.ts +10 -0
  202. package/observe/create-observable-event.js +22 -0
  203. package/observe/create-observable-event.js.map +1 -0
  204. package/observe/create-observable-state.d.ts +7 -0
  205. package/observe/create-observable-state.js +27 -0
  206. package/observe/create-observable-state.js.map +1 -0
  207. package/observe/create-persisted-state.d.ts +11 -0
  208. package/observe/create-persisted-state.js +31 -0
  209. package/observe/create-persisted-state.js.map +1 -0
  210. package/observe/create-persisted-state.test.d.ts +1 -0
  211. package/observe/create-persisted-state.test.js +124 -0
  212. package/observe/create-persisted-state.test.js.map +1 -0
  213. package/observe/from-array.d.ts +5 -0
  214. package/observe/from-array.js +30 -0
  215. package/observe/from-array.js.map +1 -0
  216. package/observe/from-constant.d.ts +5 -0
  217. package/observe/from-constant.js +12 -0
  218. package/observe/from-constant.js.map +1 -0
  219. package/observe/from-element-id.d.ts +7 -0
  220. package/observe/from-element-id.js +70 -0
  221. package/observe/from-element-id.js.map +1 -0
  222. package/observe/from-element-properties-and-events.d.ts +2 -0
  223. package/observe/from-element-properties-and-events.js +18 -0
  224. package/observe/from-element-properties-and-events.js.map +1 -0
  225. package/observe/from-element-property.d.ts +11 -0
  226. package/observe/from-element-property.js +60 -0
  227. package/observe/from-element-property.js.map +1 -0
  228. package/observe/from-promise-with-error.d.ts +7 -0
  229. package/observe/from-promise-with-error.js +27 -0
  230. package/observe/from-promise-with-error.js.map +1 -0
  231. package/observe/from-promise.d.ts +6 -0
  232. package/observe/from-promise.js +22 -0
  233. package/observe/from-promise.js.map +1 -0
  234. package/observe/from-properties.d.ts +10 -0
  235. package/observe/from-properties.js +33 -0
  236. package/observe/from-properties.js.map +1 -0
  237. package/observe/index.d.ts +27 -0
  238. package/observe/index.js +49 -0
  239. package/observe/index.js.map +1 -0
  240. package/observe/observe.test.d.ts +7 -0
  241. package/observe/observe.test.js +417 -0
  242. package/observe/observe.test.js.map +1 -0
  243. package/observe/to-promise.d.ts +8 -0
  244. package/observe/to-promise.js +18 -0
  245. package/observe/to-promise.js.map +1 -0
  246. package/observe/to-properties.d.ts +11 -0
  247. package/observe/to-properties.js +9 -0
  248. package/observe/to-properties.js.map +1 -0
  249. package/observe/types.d.ts +17 -0
  250. package/observe/types.js +2 -0
  251. package/observe/types.js.map +1 -0
  252. package/observe/with-async-map.d.ts +6 -0
  253. package/observe/with-async-map.js +12 -0
  254. package/observe/with-async-map.js.map +1 -0
  255. package/observe/with-cache.d.ts +6 -0
  256. package/observe/with-cache.js +33 -0
  257. package/observe/with-cache.js.map +1 -0
  258. package/observe/with-copy.d.ts +5 -0
  259. package/observe/with-copy.js +10 -0
  260. package/observe/with-copy.js.map +1 -0
  261. package/observe/with-deduplicate-data.d.ts +7 -0
  262. package/observe/with-deduplicate-data.js +18 -0
  263. package/observe/with-deduplicate-data.js.map +1 -0
  264. package/observe/with-deduplicate.d.ts +6 -0
  265. package/observe/with-deduplicate.js +19 -0
  266. package/observe/with-deduplicate.js.map +1 -0
  267. package/observe/with-default.d.ts +6 -0
  268. package/observe/with-default.js +21 -0
  269. package/observe/with-default.js.map +1 -0
  270. package/observe/with-map-data.d.ts +7 -0
  271. package/observe/with-map-data.js +32 -0
  272. package/observe/with-map-data.js.map +1 -0
  273. package/observe/with-map.d.ts +5 -0
  274. package/observe/with-map.js +11 -0
  275. package/observe/with-map.js.map +1 -0
  276. package/observe/with-optional.d.ts +5 -0
  277. package/observe/with-optional.js +20 -0
  278. package/observe/with-optional.js.map +1 -0
  279. package/observe/with-unwrap.d.ts +5 -0
  280. package/observe/with-unwrap.js +26 -0
  281. package/observe/with-unwrap.js.map +1 -0
  282. package/package.json +105 -0
  283. package/perftest/ecs-perf.d.ts +49 -0
  284. package/perftest/ecs-perf.js +230 -0
  285. package/perftest/ecs-perf.js.map +1 -0
  286. package/perftest/helper-functions.d.ts +1 -0
  287. package/perftest/helper-functions.js +31 -0
  288. package/perftest/helper-functions.js.map +1 -0
  289. package/perftest/horizon-perf.d.ts +22 -0
  290. package/perftest/horizon-perf.js +126 -0
  291. package/perftest/horizon-perf.js.map +1 -0
  292. package/perftest/index.d.ts +1 -0
  293. package/perftest/index.js +35 -0
  294. package/perftest/index.js.map +1 -0
  295. package/perftest/perf-test.d.ts +18 -0
  296. package/perftest/perf-test.js +124 -0
  297. package/perftest/perf-test.js.map +1 -0
  298. package/perftest/vanilla-perf.d.ts +38 -0
  299. package/perftest/vanilla-perf.js +128 -0
  300. package/perftest/vanilla-perf.js.map +1 -0
  301. package/schemas/index.d.ts +1 -0
  302. package/schemas/index.js +23 -0
  303. package/schemas/index.js.map +1 -0
  304. package/schemas/schemas.d.ts +45 -0
  305. package/schemas/schemas.js +39 -0
  306. package/schemas/schemas.js.map +1 -0
  307. package/service/add-observable-actions.d.ts +29 -0
  308. package/service/add-observable-actions.js +108 -0
  309. package/service/add-observable-actions.js.map +1 -0
  310. package/service/index.d.ts +4 -0
  311. package/service/index.js +26 -0
  312. package/service/index.js.map +1 -0
  313. package/service/progressive-result.d.ts +96 -0
  314. package/service/progressive-result.js +99 -0
  315. package/service/progressive-result.js.map +1 -0
  316. package/service/sequential-action.d.ts +18 -0
  317. package/service/sequential-action.js +45 -0
  318. package/service/sequential-action.js.map +1 -0
  319. package/service/service.d.ts +4 -0
  320. package/service/service.js +26 -0
  321. package/service/service.js.map +1 -0
  322. package/tsconfig.tsbuildinfo +1 -0
  323. package/types/index.d.ts +1 -0
  324. package/types/index.js +23 -0
  325. package/types/index.js.map +1 -0
  326. package/types/types.d.ts +61 -0
  327. package/types/types.js +27 -0
  328. package/types/types.js.map +1 -0
@@ -0,0 +1,31 @@
1
+ import { type Data } from '../data.js';
2
+ /**
3
+ * Uses datacache to store results so we can avoid expensive recomputations of the same input.
4
+ * This function also uses preventParallelExecution to prevent multiple executions of the same function at the same time with the same arguments.
5
+ * @param fn The function to memoize by storing results in the DataCache.
6
+ * @param version The version of this function. If the function changes this must also change
7
+ * to avoid returning stale results from an older version of the function.
8
+ * @param name The name of this function which should be application unique to avoid hash collisions.
9
+ * @returns A function with the same signature but memoized results.
10
+ */
11
+ /**
12
+ * Recursively merges 2 pieces of `Data`, returns new `Data`.
13
+ * Inputs are not mutated.
14
+ *
15
+ * @param {Data} a First piece of `Data`.
16
+ * @param {Data} b The second piece of `Data`.
17
+ * @returns {Object} Returns new `Data`.
18
+ * @example
19
+ *
20
+ * const one = {
21
+ * 'a': [{ 'b': 2 }, { 'd': 4 }]
22
+ * };
23
+ *
24
+ * const other = {
25
+ * 'a': [{ 'c': 3 }, { 'e': 5 }]
26
+ * };
27
+ *
28
+ * deepMerge(one, other);
29
+ * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
30
+ */
31
+ export declare const deepMerge: <A extends Data, B extends Data>(a: A, b: B) => A & B;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Uses datacache to store results so we can avoid expensive recomputations of the same input.
3
+ * This function also uses preventParallelExecution to prevent multiple executions of the same function at the same time with the same arguments.
4
+ * @param fn The function to memoize by storing results in the DataCache.
5
+ * @param version The version of this function. If the function changes this must also change
6
+ * to avoid returning stale results from an older version of the function.
7
+ * @param name The name of this function which should be application unique to avoid hash collisions.
8
+ * @returns A function with the same signature but memoized results.
9
+ */
10
+ /**
11
+ * Recursively merges 2 pieces of `Data`, returns new `Data`.
12
+ * Inputs are not mutated.
13
+ *
14
+ * @param {Data} a First piece of `Data`.
15
+ * @param {Data} b The second piece of `Data`.
16
+ * @returns {Object} Returns new `Data`.
17
+ * @example
18
+ *
19
+ * const one = {
20
+ * 'a': [{ 'b': 2 }, { 'd': 4 }]
21
+ * };
22
+ *
23
+ * const other = {
24
+ * 'a': [{ 'c': 3 }, { 'e': 5 }]
25
+ * };
26
+ *
27
+ * deepMerge(one, other);
28
+ * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
29
+ */
30
+ export const deepMerge = (a, b) => {
31
+ // Handle null/undefined cases
32
+ if (a == null)
33
+ return b;
34
+ // Handle primitive values
35
+ if (typeof a !== 'object' || typeof b !== 'object')
36
+ return b;
37
+ // Handle arrays
38
+ if (Array.isArray(a) && Array.isArray(b)) {
39
+ return [...a, ...b];
40
+ }
41
+ // Handle objects
42
+ const result = { ...a };
43
+ for (const key in b) {
44
+ if (Object.prototype.hasOwnProperty.call(b, key)) {
45
+ const value = b[key];
46
+ result[key] = deepMerge(a[key], value);
47
+ }
48
+ }
49
+ return result;
50
+ };
51
+ //# sourceMappingURL=deep-merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-merge.js","sourceRoot":"","sources":["../../../src/core/functions/deep-merge.ts"],"names":[],"mappings":"AAuBA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAiC,CAAI,EAAE,CAAI,EAAS,EAAE;IAC3E,8BAA8B;IAC9B,IAAI,CAAC,IAAI,IAAI;QAAE,OAAO,CAAU,CAAC;IAEjC,0BAA0B;IAC1B,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAU,CAAC;IAEtE,gBAAgB;IAChB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAqB,CAAC;IAC1C,CAAC;IAED,iBAAiB;IACjB,MAAM,MAAM,GAAG,EAAE,GAAG,CAAC,EAA0B,CAAC;IAChD,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC;QACpB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;YACjD,MAAM,KAAK,GAAI,CAA0B,CAAC,GAAG,CAAC,CAAC;YAC/C,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAE,CAA0B,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IACD,OAAO,MAAe,CAAC;AACzB,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,94 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ import { deepMerge } from './deep-merge.js';
23
+ import { assert } from 'riteway/vitest';
24
+ import { describe, test } from 'vitest';
25
+ describe('deepMerge', () => {
26
+ test('should merge two objects', () => {
27
+ const a = { a: 1, b: 2 };
28
+ const b = { c: 3, d: 4 };
29
+ assert({
30
+ given: 'two objects without overlapping keys',
31
+ should: 'merge them',
32
+ actual: deepMerge(a, b),
33
+ expected: { a: 1, b: 2, c: 3, d: 4 },
34
+ });
35
+ });
36
+ test('should merge two objects with overlapping keys', () => {
37
+ const a = { a: 1, b: 2 };
38
+ const b = { b: 3, c: 4 };
39
+ assert({
40
+ given: 'two objects with overlapping keys',
41
+ should: 'merge them',
42
+ actual: deepMerge(a, b),
43
+ expected: { a: 1, b: 3, c: 4 },
44
+ });
45
+ });
46
+ test('should merge two objects with overlapping keys and arrays', () => {
47
+ const a = { a: 1, b: [1, 2] };
48
+ const b = { b: [3, 4], c: 4 };
49
+ assert({
50
+ given: 'two objects with overlapping keys and arrays',
51
+ should: 'merge them',
52
+ actual: deepMerge(a, b),
53
+ expected: { a: 1, b: [1, 2, 3, 4], c: 4 },
54
+ });
55
+ });
56
+ test('should merge two nested objects with overlapping keys', () => {
57
+ const a = { a: 1, b: { c: 2, d: 3 } };
58
+ const b = { b: { d: 4, e: 5 }, c: 6 };
59
+ assert({
60
+ given: 'two nested objects with overlapping keys',
61
+ should: 'merge them',
62
+ actual: deepMerge(a, b),
63
+ expected: { a: 1, b: { c: 2, d: 4, e: 5 }, c: 6 },
64
+ });
65
+ });
66
+ test('should merge two objects with null values', () => {
67
+ const a = { a: null, b: 2 };
68
+ const b = { b: null, c: 4 };
69
+ assert({
70
+ given: 'two objects with null values',
71
+ should: 'merge them',
72
+ actual: deepMerge(a, b),
73
+ expected: { a: null, b: null, c: 4 },
74
+ });
75
+ });
76
+ test('should merge two objects with undefined values', () => {
77
+ const a = { a: undefined, b: 2 };
78
+ const b = { b: undefined, c: 4 };
79
+ assert({
80
+ given: 'two objects with undefined values',
81
+ should: 'merge them',
82
+ actual: deepMerge(a, b),
83
+ expected: { a: undefined, b: undefined, c: 4 },
84
+ });
85
+ });
86
+ test('should not mutate the original objects', () => {
87
+ const a = { a: 1, b: 2 };
88
+ const b = { b: 3, c: 4 };
89
+ deepMerge(a, b);
90
+ assert({ given: 'the original objects', should: 'not be mutated', actual: a, expected: { a: 1, b: 2 } });
91
+ assert({ given: 'the original objects', should: 'not be mutated', actual: b, expected: { b: 3, c: 4 } });
92
+ });
93
+ });
94
+ //# sourceMappingURL=deep-merge.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-merge.test.js","sourceRoot":"","sources":["../../../src/core/functions/deep-merge.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AACX,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAExC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACpC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC;YACL,KAAK,EAAE,sCAAsC;YAC7C,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;YACvB,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;SACrC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,gDAAgD,EAAE,GAAG,EAAE;QAC1D,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC;YACL,KAAK,EAAE,mCAAmC;YAC1C,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;YACv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C,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACzB,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAChB,MAAM,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACzG,MAAM,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3G,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './array-equals.js';
2
+ export * from './is-async-generator.js';
3
+ export * from './deep-merge.js';
4
+ export * from './with-validation.js';
@@ -0,0 +1,26 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ export * from './array-equals.js';
23
+ export * from './is-async-generator.js';
24
+ export * from './deep-merge.js';
25
+ export * from './with-validation.js';
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/functions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1 @@
1
+ export declare function isAsyncGenerator<T>(value: any): value is AsyncGenerator<T>;
@@ -0,0 +1,25 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ export function isAsyncGenerator(value) {
23
+ return value && typeof value[Symbol.asyncIterator] === 'function';
24
+ }
25
+ //# sourceMappingURL=is-async-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-async-generator.js","sourceRoot":"","sources":["../../../src/core/functions/is-async-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,MAAM,UAAU,gBAAgB,CAAI,KAAU;IAC1C,OAAO,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,CAAC;AACtE,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function isPromise<T = unknown>(obj: unknown): obj is Promise<T>;
@@ -0,0 +1,26 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ export function isPromise(obj) {
23
+ const maybePromise = obj;
24
+ return (!!maybePromise && (typeof maybePromise === 'object' || typeof maybePromise === 'function') && typeof maybePromise?.then === 'function');
25
+ }
26
+ //# sourceMappingURL=is-promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-promise.js","sourceRoot":"","sources":["../../../src/core/functions/is-promise.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,MAAM,UAAU,SAAS,CAAc,GAAY;IAC/C,MAAM,YAAY,GAAG,GAAsC,CAAC;IAC5D,OAAO,CACH,CAAC,CAAC,YAAY,IAAI,CAAC,OAAO,YAAY,KAAK,QAAQ,IAAI,OAAO,YAAY,KAAK,UAAU,CAAC,IAAI,OAAO,YAAY,EAAE,IAAI,KAAK,UAAU,CACzI,CAAC;AACN,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Schema, FromSchema } from '../../index.js';
2
+ /**
3
+ * Creates a function which can wrap another function and validate the input against a JSON Schema.
4
+ */
5
+ export declare function withValidation<T extends Schema>(schema: T): <F extends (arg: FromSchema<T>) => any>(fn: F) => F;
@@ -0,0 +1,38 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ import { Validator } from '@cfworker/json-schema';
23
+ /**
24
+ * Creates a function which can wrap another function and validate the input against a JSON Schema.
25
+ */
26
+ export function withValidation(schema) {
27
+ const validator = new Validator(schema);
28
+ return function (fn) {
29
+ return function (arg) {
30
+ const validation = validator.validate(arg);
31
+ if (!validation.valid) {
32
+ throw new Error(`Validation failed: ${JSON.stringify(validation.errors)}`);
33
+ }
34
+ return fn.call(this, arg);
35
+ };
36
+ };
37
+ }
38
+ //# sourceMappingURL=with-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-validation.js","sourceRoot":"","sources":["../../../src/core/functions/with-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AACX,OAAO,EAAE,SAAS,EAAwB,MAAM,uBAAuB,CAAC;AAGxE;;GAEG;AACH,MAAM,UAAU,cAAc,CAAmB,MAAS;IACtD,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,MAAoB,CAAC,CAAC;IAEtD,OAAO,UAAiD,EAAK;QACzD,OAAO,UAAqB,GAAkB;YAC1C,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAE3C,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CACX,sBAAsB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAC5D,CAAC;YACN,CAAC;YAED,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC9B,CAAM,CAAC;IACX,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,96 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ import { describe, it, expect } from 'vitest';
23
+ import { withValidation } from './with-validation.js';
24
+ // Define a test schema
25
+ const userSchema = {
26
+ type: 'object',
27
+ properties: {
28
+ name: { type: 'string' },
29
+ age: { type: 'number' },
30
+ foo: { type: 'string' },
31
+ email: { type: 'string', format: 'email' }
32
+ },
33
+ required: ['name', 'age', 'email']
34
+ };
35
+ describe('withValidation', () => {
36
+ it('should pass validation for valid input', () => {
37
+ const createUser = withValidation(userSchema)((user) => user);
38
+ const validUser = {
39
+ name: 'John Doe',
40
+ age: 30,
41
+ email: 'john@example.com'
42
+ };
43
+ expect(() => createUser(validUser)).not.toThrow();
44
+ expect(createUser(validUser)).toEqual(validUser);
45
+ });
46
+ it('should throw error for invalid input', () => {
47
+ const createUser = withValidation(userSchema)((user) => user);
48
+ const invalidUser = {
49
+ name: 'John Doe',
50
+ age: '30', // Should be a number
51
+ email: 'not-an-email'
52
+ };
53
+ expect(() => createUser(invalidUser)).toThrow(/Validation failed/);
54
+ });
55
+ it('should throw error for missing required fields', () => {
56
+ const createUser = withValidation(userSchema)((user) => user);
57
+ const incompleteUser = {
58
+ name: 'John Doe',
59
+ // Missing age and email
60
+ };
61
+ expect(() => createUser(incompleteUser)).toThrow(/Validation failed/);
62
+ });
63
+ it('should preserve function return type', () => {
64
+ const processUser = withValidation(userSchema)((user) => ({
65
+ ...user,
66
+ processed: true
67
+ }));
68
+ const result = processUser({
69
+ name: 'John Doe',
70
+ age: 30,
71
+ email: 'john@example.com'
72
+ });
73
+ expect(result).toEqual({
74
+ name: 'John Doe',
75
+ age: 30,
76
+ email: 'john@example.com',
77
+ processed: true
78
+ });
79
+ });
80
+ it("should pass 'this' context to the wrapped function", () => {
81
+ const context = { value: 42 };
82
+ const fn = function (user) {
83
+ return this.value;
84
+ };
85
+ const wrapped = withValidation(userSchema)(fn);
86
+ const validUser = {
87
+ name: 'Jane Doe',
88
+ age: 25,
89
+ email: 'jane@example.com'
90
+ };
91
+ // Bind context and call
92
+ const result = wrapped.call(context, validUser);
93
+ expect(result).toBe(42);
94
+ });
95
+ });
96
+ //# sourceMappingURL=with-validation.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-validation.test.js","sourceRoot":"","sources":["../../../src/core/functions/with-validation.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AACX,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,uBAAuB;AACvB,MAAM,UAAU,GAAG;IACf,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxB,GAAG,EAAE,EAAE,IAAI,EAAE,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E,SAAS,CAAC,CAAC;QAChD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./data.js";
2
+ export * from "./schema.js";
3
+ export * from "./functions/index.js";
package/core/index.js ADDED
@@ -0,0 +1,25 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ export * from "./data.js";
23
+ export * from "./schema.js";
24
+ export * from "./functions/index.js";
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAEX,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,86 @@
1
+ import { DeepReadonly } from "../types/types.js";
2
+ export type Schema = {
3
+ type?: 'number' | 'integer' | 'string' | 'boolean' | 'null' | 'array' | 'object';
4
+ minimum?: number;
5
+ precision?: 1 | 2;
6
+ default?: any;
7
+ maximum?: number;
8
+ pattern?: string;
9
+ minItems?: number;
10
+ maxItems?: number;
11
+ items?: Schema;
12
+ properties?: {
13
+ readonly [key: string]: Schema;
14
+ };
15
+ required?: readonly string[];
16
+ additionalProperties?: boolean | Schema;
17
+ oneOf?: readonly Schema[];
18
+ const?: any;
19
+ enum?: readonly any[];
20
+ };
21
+ export type FromSchema<T, Depth extends number = 5> = DeepReadonly<Depth extends 0 ? any : T extends {
22
+ const: infer Const;
23
+ } ? Const : T extends {
24
+ enum: infer Enum;
25
+ } ? Enum extends ReadonlyArray<any> ? Enum[number] : never : T extends {
26
+ oneOf: infer Schemas;
27
+ } ? Schemas extends ReadonlyArray<Schema> ? FromOneOfSchema<Schemas, Decrement<Depth>> : never : T extends {
28
+ type: 'number' | 'integer';
29
+ } ? number : T extends {
30
+ type: 'string';
31
+ } ? string : T extends {
32
+ type: 'boolean';
33
+ } ? boolean : T extends {
34
+ type: 'null';
35
+ } ? null : T extends {
36
+ type: 'array';
37
+ } | {
38
+ items: any;
39
+ } ? FromSchemaArray<T, Decrement<Depth>> : T extends {
40
+ type: 'object';
41
+ } | {
42
+ properties: any;
43
+ } ? FromSchemaObject<T, Decrement<Depth>> : any>;
44
+ type Decrement<N extends number> = ((...x: any[]) => void) extends (arg: any, ...rest: infer R) => void ? R['length'] : never;
45
+ type FromSchemaArray<T, Depth extends number> = T extends {
46
+ items: infer Items;
47
+ } ? T extends {
48
+ minItems: infer Min;
49
+ maxItems: infer Max;
50
+ } ? Equal<Min, Max> extends true ? BuildTuple<FromSchema<Items, Depth>, Min> : FromSchema<Items, Depth>[] : FromSchema<Items, Depth>[] : any[];
51
+ type BuildTuple<T, N, R extends unknown[] = []> = R['length'] extends N ? R : BuildTuple<T, N, [...R, T]>;
52
+ type FromSchemaObject<T extends Schema, Depth extends number> = T extends {
53
+ properties: infer P;
54
+ } ? Simplify<{
55
+ [K in RequiredKeys<T>]: FromSchema<P[K], Depth>;
56
+ } & {
57
+ [K in OptionalKeys<T>]?: FromSchema<P[K], Depth>;
58
+ } & (T extends {
59
+ additionalProperties: infer AP;
60
+ } ? AP extends false ? {} : AP extends Schema ? {
61
+ [key: string]: FromSchema<AP, Depth>;
62
+ } : {
63
+ [key: string]: any;
64
+ } : {
65
+ [key: string]: any;
66
+ })> : T extends {
67
+ additionalProperties: infer AP;
68
+ } ? AP extends Schema ? {
69
+ [key: string]: FromSchema<AP, Depth>;
70
+ } : {
71
+ [key: string]: any;
72
+ } : {
73
+ [key: string]: any;
74
+ };
75
+ type RequiredKeys<T> = T extends {
76
+ required: infer R;
77
+ } ? R extends readonly (infer K)[] ? K extends string ? K : never : never : never;
78
+ type OptionalKeys<T> = T extends {
79
+ properties: infer P;
80
+ } ? Exclude<keyof P, RequiredKeys<T>> : never;
81
+ type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? true : false;
82
+ type Simplify<T> = T extends infer O ? {
83
+ [K in keyof O]: O[K];
84
+ } : never;
85
+ type FromOneOfSchema<Schemas extends ReadonlyArray<Schema>, Depth extends number> = Schemas[number] extends infer S ? S extends Schema ? FromSchema<S, Depth> : never : never;
86
+ export {};
package/core/schema.js ADDED
@@ -0,0 +1,33 @@
1
+ /*MIT License
2
+
3
+ © Copyright 2025 Adobe. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.*/
22
+ const mySchema = {
23
+ type: 'object',
24
+ properties: {
25
+ a: { type: 'number' },
26
+ b: { type: 'string' },
27
+ c: { enum: [1, 2, 3] }
28
+ },
29
+ required: ['a', 'c'],
30
+ additionalProperties: false,
31
+ };
32
+ export {};
33
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;WAoBW;AAqJX,MAAM,QAAQ,GAAG;IACf,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrB,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;KACvB;IACD,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;IACpB,oBAAoB,EAAE,KAAK;CACF,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { describe, it } from "vitest";
2
+ describe("Schema", () => {
3
+ it("should provide compile time and runtime type validation", () => {
4
+ const mySchema = {
5
+ type: "object",
6
+ required: ["name", "aspect"],
7
+ properties: {
8
+ name: { type: "string" },
9
+ age: { type: "integer", minimum: 0 },
10
+ aspect: { enum: ["landscape", "portrait"] },
11
+ },
12
+ additionalProperties: false,
13
+ };
14
+ });
15
+ });
16
+ //# sourceMappingURL=schema.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.test.js","sourceRoot":"","sources":["../../src/core/schema.test.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEtC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,QAAQ,GAAG;YACf,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;YAC5B,UAAU,EAAE;gBACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACxB,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;gBACpC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE;aAC5C;YACD,oBAAoB,EAAE,KAAK;SACF,CAAC;IAiB9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}