@vertesia/workflow 0.24.0-dev.202601221707

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 (490) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +65 -0
  3. package/bin/bundle-workflows.mjs +39 -0
  4. package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js +33 -0
  5. package/lib/cjs/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -0
  6. package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +73 -0
  7. package/lib/cjs/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -0
  8. package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js +19 -0
  9. package/lib/cjs/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -0
  10. package/lib/cjs/activities/chunkDocument.js +85 -0
  11. package/lib/cjs/activities/chunkDocument.js.map +1 -0
  12. package/lib/cjs/activities/copyParentArtifacts.js +127 -0
  13. package/lib/cjs/activities/copyParentArtifacts.js.map +1 -0
  14. package/lib/cjs/activities/createDocumentFromOther.js +64 -0
  15. package/lib/cjs/activities/createDocumentFromOther.js.map +1 -0
  16. package/lib/cjs/activities/executeInteraction.js +194 -0
  17. package/lib/cjs/activities/executeInteraction.js.map +1 -0
  18. package/lib/cjs/activities/extractDocumentText.js +156 -0
  19. package/lib/cjs/activities/extractDocumentText.js.map +1 -0
  20. package/lib/cjs/activities/generateDocumentProperties.js +83 -0
  21. package/lib/cjs/activities/generateDocumentProperties.js.map +1 -0
  22. package/lib/cjs/activities/generateEmbeddings.js +257 -0
  23. package/lib/cjs/activities/generateEmbeddings.js.map +1 -0
  24. package/lib/cjs/activities/generateOrAssignContentType.js +125 -0
  25. package/lib/cjs/activities/generateOrAssignContentType.js.map +1 -0
  26. package/lib/cjs/activities/getObjectFromStore.js +20 -0
  27. package/lib/cjs/activities/getObjectFromStore.js.map +1 -0
  28. package/lib/cjs/activities/handleError.js +22 -0
  29. package/lib/cjs/activities/handleError.js.map +1 -0
  30. package/lib/cjs/activities/index-dsl.js +51 -0
  31. package/lib/cjs/activities/index-dsl.js.map +1 -0
  32. package/lib/cjs/activities/index.js +21 -0
  33. package/lib/cjs/activities/index.js.map +1 -0
  34. package/lib/cjs/activities/media/prepareAudio.js +239 -0
  35. package/lib/cjs/activities/media/prepareAudio.js.map +1 -0
  36. package/lib/cjs/activities/media/prepareVideo.js +429 -0
  37. package/lib/cjs/activities/media/prepareVideo.js.map +1 -0
  38. package/lib/cjs/activities/media/processPdfWithTextract.js +103 -0
  39. package/lib/cjs/activities/media/processPdfWithTextract.js.map +1 -0
  40. package/lib/cjs/activities/media/saveGladiaTranscription.js +81 -0
  41. package/lib/cjs/activities/media/saveGladiaTranscription.js.map +1 -0
  42. package/lib/cjs/activities/media/transcribeMediaWithGladia.js +82 -0
  43. package/lib/cjs/activities/media/transcribeMediaWithGladia.js.map +1 -0
  44. package/lib/cjs/activities/notifyWebhook.js +158 -0
  45. package/lib/cjs/activities/notifyWebhook.js.map +1 -0
  46. package/lib/cjs/activities/rateLimiter.js +30 -0
  47. package/lib/cjs/activities/rateLimiter.js.map +1 -0
  48. package/lib/cjs/activities/renditions/generateImageRendition.js +66 -0
  49. package/lib/cjs/activities/renditions/generateImageRendition.js.map +1 -0
  50. package/lib/cjs/activities/renditions/generateVideoRendition.js +200 -0
  51. package/lib/cjs/activities/renditions/generateVideoRendition.js.map +1 -0
  52. package/lib/cjs/activities/setDocumentStatus.js +15 -0
  53. package/lib/cjs/activities/setDocumentStatus.js.map +1 -0
  54. package/lib/cjs/conversion/TextractProcessor.js +417 -0
  55. package/lib/cjs/conversion/TextractProcessor.js.map +1 -0
  56. package/lib/cjs/conversion/image.js +149 -0
  57. package/lib/cjs/conversion/image.js.map +1 -0
  58. package/lib/cjs/conversion/markitdown.js +42 -0
  59. package/lib/cjs/conversion/markitdown.js.map +1 -0
  60. package/lib/cjs/conversion/mutool.js +147 -0
  61. package/lib/cjs/conversion/mutool.js.map +1 -0
  62. package/lib/cjs/conversion/pandoc.js +39 -0
  63. package/lib/cjs/conversion/pandoc.js.map +1 -0
  64. package/lib/cjs/dsl/conditions.js +81 -0
  65. package/lib/cjs/dsl/conditions.js.map +1 -0
  66. package/lib/cjs/dsl/dsl-workflow.js +343 -0
  67. package/lib/cjs/dsl/dsl-workflow.js.map +1 -0
  68. package/lib/cjs/dsl/dslProxyActivities.js +23 -0
  69. package/lib/cjs/dsl/dslProxyActivities.js.map +1 -0
  70. package/lib/cjs/dsl/projections.js +59 -0
  71. package/lib/cjs/dsl/projections.js.map +1 -0
  72. package/lib/cjs/dsl/setup/ActivityContext.js +122 -0
  73. package/lib/cjs/dsl/setup/ActivityContext.js.map +1 -0
  74. package/lib/cjs/dsl/setup/fetch/DataProvider.js +51 -0
  75. package/lib/cjs/dsl/setup/fetch/DataProvider.js.map +1 -0
  76. package/lib/cjs/dsl/setup/fetch/index.js +16 -0
  77. package/lib/cjs/dsl/setup/fetch/index.js.map +1 -0
  78. package/lib/cjs/dsl/setup/fetch/providers.js +67 -0
  79. package/lib/cjs/dsl/setup/fetch/providers.js.map +1 -0
  80. package/lib/cjs/dsl/test/test-child-workflow.js +10 -0
  81. package/lib/cjs/dsl/test/test-child-workflow.js.map +1 -0
  82. package/lib/cjs/dsl/validation.js +122 -0
  83. package/lib/cjs/dsl/validation.js.map +1 -0
  84. package/lib/cjs/dsl/vars.js +341 -0
  85. package/lib/cjs/dsl/vars.js.map +1 -0
  86. package/lib/cjs/dsl/walk.js +100 -0
  87. package/lib/cjs/dsl/walk.js.map +1 -0
  88. package/lib/cjs/dsl.js +20 -0
  89. package/lib/cjs/dsl.js.map +1 -0
  90. package/lib/cjs/errors.js +79 -0
  91. package/lib/cjs/errors.js.map +1 -0
  92. package/lib/cjs/index.js +56 -0
  93. package/lib/cjs/index.js.map +1 -0
  94. package/lib/cjs/iterative-generation/activities/extractToc.js +47 -0
  95. package/lib/cjs/iterative-generation/activities/extractToc.js.map +1 -0
  96. package/lib/cjs/iterative-generation/activities/finalizeOutput.js +72 -0
  97. package/lib/cjs/iterative-generation/activities/finalizeOutput.js.map +1 -0
  98. package/lib/cjs/iterative-generation/activities/generatePart.js +78 -0
  99. package/lib/cjs/iterative-generation/activities/generatePart.js.map +1 -0
  100. package/lib/cjs/iterative-generation/activities/generateToc.js +86 -0
  101. package/lib/cjs/iterative-generation/activities/generateToc.js.map +1 -0
  102. package/lib/cjs/iterative-generation/activities/index.js +12 -0
  103. package/lib/cjs/iterative-generation/activities/index.js.map +1 -0
  104. package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js +56 -0
  105. package/lib/cjs/iterative-generation/iterativeGenerationWorkflow.js.map +1 -0
  106. package/lib/cjs/iterative-generation/types.js +5 -0
  107. package/lib/cjs/iterative-generation/types.js.map +1 -0
  108. package/lib/cjs/iterative-generation/utils.js +121 -0
  109. package/lib/cjs/iterative-generation/utils.js.map +1 -0
  110. package/lib/cjs/package.json +3 -0
  111. package/lib/cjs/result-types.js +10 -0
  112. package/lib/cjs/result-types.js.map +1 -0
  113. package/lib/cjs/system/notifyWebhookWorkflow.js +53 -0
  114. package/lib/cjs/system/notifyWebhookWorkflow.js.map +1 -0
  115. package/lib/cjs/system/recalculateEmbeddingsWorkflow.js +33 -0
  116. package/lib/cjs/system/recalculateEmbeddingsWorkflow.js.map +1 -0
  117. package/lib/cjs/utils/auth.js +15 -0
  118. package/lib/cjs/utils/auth.js.map +1 -0
  119. package/lib/cjs/utils/blobs.js +64 -0
  120. package/lib/cjs/utils/blobs.js.map +1 -0
  121. package/lib/cjs/utils/chunks.js +14 -0
  122. package/lib/cjs/utils/chunks.js.map +1 -0
  123. package/lib/cjs/utils/client.js +31 -0
  124. package/lib/cjs/utils/client.js.map +1 -0
  125. package/lib/cjs/utils/expand-vars.js +33 -0
  126. package/lib/cjs/utils/expand-vars.js.map +1 -0
  127. package/lib/cjs/utils/memory.js +65 -0
  128. package/lib/cjs/utils/memory.js.map +1 -0
  129. package/lib/cjs/utils/renditions.js +88 -0
  130. package/lib/cjs/utils/renditions.js.map +1 -0
  131. package/lib/cjs/utils/storage.js +54 -0
  132. package/lib/cjs/utils/storage.js.map +1 -0
  133. package/lib/cjs/utils/tokens.js +38 -0
  134. package/lib/cjs/utils/tokens.js.map +1 -0
  135. package/lib/cjs/vars.js +20 -0
  136. package/lib/cjs/vars.js.map +1 -0
  137. package/lib/cjs/workflows.js +15 -0
  138. package/lib/cjs/workflows.js.map +1 -0
  139. package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js +30 -0
  140. package/lib/esm/activities/advanced/createDocumentTypeFromInteractionRun.js.map +1 -0
  141. package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js +70 -0
  142. package/lib/esm/activities/advanced/createOrUpdateDocumentFromInteractionRun.js.map +1 -0
  143. package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js +16 -0
  144. package/lib/esm/activities/advanced/updateDocumentFromInteractionRun.js.map +1 -0
  145. package/lib/esm/activities/chunkDocument.js +82 -0
  146. package/lib/esm/activities/chunkDocument.js.map +1 -0
  147. package/lib/esm/activities/copyParentArtifacts.js +124 -0
  148. package/lib/esm/activities/copyParentArtifacts.js.map +1 -0
  149. package/lib/esm/activities/createDocumentFromOther.js +58 -0
  150. package/lib/esm/activities/createDocumentFromOther.js.map +1 -0
  151. package/lib/esm/activities/executeInteraction.js +190 -0
  152. package/lib/esm/activities/executeInteraction.js.map +1 -0
  153. package/lib/esm/activities/extractDocumentText.js +153 -0
  154. package/lib/esm/activities/extractDocumentText.js.map +1 -0
  155. package/lib/esm/activities/generateDocumentProperties.js +80 -0
  156. package/lib/esm/activities/generateDocumentProperties.js.map +1 -0
  157. package/lib/esm/activities/generateEmbeddings.js +254 -0
  158. package/lib/esm/activities/generateEmbeddings.js.map +1 -0
  159. package/lib/esm/activities/generateOrAssignContentType.js +122 -0
  160. package/lib/esm/activities/generateOrAssignContentType.js.map +1 -0
  161. package/lib/esm/activities/getObjectFromStore.js +17 -0
  162. package/lib/esm/activities/getObjectFromStore.js.map +1 -0
  163. package/lib/esm/activities/handleError.js +19 -0
  164. package/lib/esm/activities/handleError.js.map +1 -0
  165. package/lib/esm/activities/index-dsl.js +25 -0
  166. package/lib/esm/activities/index-dsl.js.map +1 -0
  167. package/lib/esm/activities/index.js +5 -0
  168. package/lib/esm/activities/index.js.map +1 -0
  169. package/lib/esm/activities/media/prepareAudio.js +200 -0
  170. package/lib/esm/activities/media/prepareAudio.js.map +1 -0
  171. package/lib/esm/activities/media/prepareVideo.js +390 -0
  172. package/lib/esm/activities/media/prepareVideo.js.map +1 -0
  173. package/lib/esm/activities/media/processPdfWithTextract.js +99 -0
  174. package/lib/esm/activities/media/processPdfWithTextract.js.map +1 -0
  175. package/lib/esm/activities/media/saveGladiaTranscription.js +78 -0
  176. package/lib/esm/activities/media/saveGladiaTranscription.js.map +1 -0
  177. package/lib/esm/activities/media/transcribeMediaWithGladia.js +79 -0
  178. package/lib/esm/activities/media/transcribeMediaWithGladia.js.map +1 -0
  179. package/lib/esm/activities/notifyWebhook.js +155 -0
  180. package/lib/esm/activities/notifyWebhook.js.map +1 -0
  181. package/lib/esm/activities/rateLimiter.js +27 -0
  182. package/lib/esm/activities/rateLimiter.js.map +1 -0
  183. package/lib/esm/activities/renditions/generateImageRendition.js +63 -0
  184. package/lib/esm/activities/renditions/generateImageRendition.js.map +1 -0
  185. package/lib/esm/activities/renditions/generateVideoRendition.js +194 -0
  186. package/lib/esm/activities/renditions/generateVideoRendition.js.map +1 -0
  187. package/lib/esm/activities/setDocumentStatus.js +12 -0
  188. package/lib/esm/activities/setDocumentStatus.js.map +1 -0
  189. package/lib/esm/conversion/TextractProcessor.js +410 -0
  190. package/lib/esm/conversion/TextractProcessor.js.map +1 -0
  191. package/lib/esm/conversion/image.js +143 -0
  192. package/lib/esm/conversion/image.js.map +1 -0
  193. package/lib/esm/conversion/markitdown.js +36 -0
  194. package/lib/esm/conversion/markitdown.js.map +1 -0
  195. package/lib/esm/conversion/mutool.js +139 -0
  196. package/lib/esm/conversion/mutool.js.map +1 -0
  197. package/lib/esm/conversion/pandoc.js +36 -0
  198. package/lib/esm/conversion/pandoc.js.map +1 -0
  199. package/lib/esm/dsl/conditions.js +75 -0
  200. package/lib/esm/dsl/conditions.js.map +1 -0
  201. package/lib/esm/dsl/dsl-workflow.js +336 -0
  202. package/lib/esm/dsl/dsl-workflow.js.map +1 -0
  203. package/lib/esm/dsl/dslProxyActivities.js +20 -0
  204. package/lib/esm/dsl/dslProxyActivities.js.map +1 -0
  205. package/lib/esm/dsl/projections.js +55 -0
  206. package/lib/esm/dsl/projections.js.map +1 -0
  207. package/lib/esm/dsl/setup/ActivityContext.js +117 -0
  208. package/lib/esm/dsl/setup/ActivityContext.js.map +1 -0
  209. package/lib/esm/dsl/setup/fetch/DataProvider.js +47 -0
  210. package/lib/esm/dsl/setup/fetch/DataProvider.js.map +1 -0
  211. package/lib/esm/dsl/setup/fetch/index.js +12 -0
  212. package/lib/esm/dsl/setup/fetch/index.js.map +1 -0
  213. package/lib/esm/dsl/setup/fetch/providers.js +61 -0
  214. package/lib/esm/dsl/setup/fetch/providers.js.map +1 -0
  215. package/lib/esm/dsl/test/test-child-workflow.js +5 -0
  216. package/lib/esm/dsl/test/test-child-workflow.js.map +1 -0
  217. package/lib/esm/dsl/validation.js +118 -0
  218. package/lib/esm/dsl/validation.js.map +1 -0
  219. package/lib/esm/dsl/vars.js +335 -0
  220. package/lib/esm/dsl/vars.js.map +1 -0
  221. package/lib/esm/dsl/walk.js +96 -0
  222. package/lib/esm/dsl/walk.js.map +1 -0
  223. package/lib/esm/dsl.js +4 -0
  224. package/lib/esm/dsl.js.map +1 -0
  225. package/lib/esm/errors.js +69 -0
  226. package/lib/esm/errors.js.map +1 -0
  227. package/lib/esm/index.js +38 -0
  228. package/lib/esm/index.js.map +1 -0
  229. package/lib/esm/iterative-generation/activities/extractToc.js +44 -0
  230. package/lib/esm/iterative-generation/activities/extractToc.js.map +1 -0
  231. package/lib/esm/iterative-generation/activities/finalizeOutput.js +69 -0
  232. package/lib/esm/iterative-generation/activities/finalizeOutput.js.map +1 -0
  233. package/lib/esm/iterative-generation/activities/generatePart.js +75 -0
  234. package/lib/esm/iterative-generation/activities/generatePart.js.map +1 -0
  235. package/lib/esm/iterative-generation/activities/generateToc.js +83 -0
  236. package/lib/esm/iterative-generation/activities/generateToc.js.map +1 -0
  237. package/lib/esm/iterative-generation/activities/index.js +5 -0
  238. package/lib/esm/iterative-generation/activities/index.js.map +1 -0
  239. package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js +53 -0
  240. package/lib/esm/iterative-generation/iterativeGenerationWorkflow.js.map +1 -0
  241. package/lib/esm/iterative-generation/types.js +2 -0
  242. package/lib/esm/iterative-generation/types.js.map +1 -0
  243. package/lib/esm/iterative-generation/utils.js +112 -0
  244. package/lib/esm/iterative-generation/utils.js.map +1 -0
  245. package/lib/esm/result-types.js +7 -0
  246. package/lib/esm/result-types.js.map +1 -0
  247. package/lib/esm/system/notifyWebhookWorkflow.js +50 -0
  248. package/lib/esm/system/notifyWebhookWorkflow.js.map +1 -0
  249. package/lib/esm/system/recalculateEmbeddingsWorkflow.js +30 -0
  250. package/lib/esm/system/recalculateEmbeddingsWorkflow.js.map +1 -0
  251. package/lib/esm/utils/auth.js +8 -0
  252. package/lib/esm/utils/auth.js.map +1 -0
  253. package/lib/esm/utils/blobs.js +54 -0
  254. package/lib/esm/utils/blobs.js.map +1 -0
  255. package/lib/esm/utils/chunks.js +9 -0
  256. package/lib/esm/utils/chunks.js.map +1 -0
  257. package/lib/esm/utils/client.js +27 -0
  258. package/lib/esm/utils/client.js.map +1 -0
  259. package/lib/esm/utils/expand-vars.js +30 -0
  260. package/lib/esm/utils/expand-vars.js.map +1 -0
  261. package/lib/esm/utils/memory.js +55 -0
  262. package/lib/esm/utils/memory.js.map +1 -0
  263. package/lib/esm/utils/renditions.js +80 -0
  264. package/lib/esm/utils/renditions.js.map +1 -0
  265. package/lib/esm/utils/storage.js +45 -0
  266. package/lib/esm/utils/storage.js.map +1 -0
  267. package/lib/esm/utils/tokens.js +34 -0
  268. package/lib/esm/utils/tokens.js.map +1 -0
  269. package/lib/esm/vars.js +4 -0
  270. package/lib/esm/vars.js.map +1 -0
  271. package/lib/esm/workflows.js +8 -0
  272. package/lib/esm/workflows.js.map +1 -0
  273. package/lib/tsconfig.tsbuildinfo +1 -0
  274. package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts +17 -0
  275. package/lib/types/activities/advanced/createDocumentTypeFromInteractionRun.d.ts.map +1 -0
  276. package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts +39 -0
  277. package/lib/types/activities/advanced/createOrUpdateDocumentFromInteractionRun.d.ts.map +1 -0
  278. package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts +19 -0
  279. package/lib/types/activities/advanced/updateDocumentFromInteractionRun.d.ts.map +1 -0
  280. package/lib/types/activities/chunkDocument.d.ts +33 -0
  281. package/lib/types/activities/chunkDocument.d.ts.map +1 -0
  282. package/lib/types/activities/copyParentArtifacts.d.ts +19 -0
  283. package/lib/types/activities/copyParentArtifacts.d.ts.map +1 -0
  284. package/lib/types/activities/createDocumentFromOther.d.ts +21 -0
  285. package/lib/types/activities/createDocumentFromOther.d.ts.map +1 -0
  286. package/lib/types/activities/executeInteraction.d.ts +61 -0
  287. package/lib/types/activities/executeInteraction.d.ts.map +1 -0
  288. package/lib/types/activities/extractDocumentText.d.ts +10 -0
  289. package/lib/types/activities/extractDocumentText.d.ts.map +1 -0
  290. package/lib/types/activities/generateDocumentProperties.d.ts +32 -0
  291. package/lib/types/activities/generateDocumentProperties.d.ts.map +1 -0
  292. package/lib/types/activities/generateEmbeddings.d.ts +53 -0
  293. package/lib/types/activities/generateEmbeddings.d.ts.map +1 -0
  294. package/lib/types/activities/generateOrAssignContentType.d.ts +44 -0
  295. package/lib/types/activities/generateOrAssignContentType.d.ts.map +1 -0
  296. package/lib/types/activities/getObjectFromStore.d.ts +14 -0
  297. package/lib/types/activities/getObjectFromStore.d.ts.map +1 -0
  298. package/lib/types/activities/handleError.d.ts +6 -0
  299. package/lib/types/activities/handleError.d.ts.map +1 -0
  300. package/lib/types/activities/index-dsl.d.ts +25 -0
  301. package/lib/types/activities/index-dsl.d.ts.map +1 -0
  302. package/lib/types/activities/index.d.ts +5 -0
  303. package/lib/types/activities/index.d.ts.map +1 -0
  304. package/lib/types/activities/media/prepareAudio.d.ts +25 -0
  305. package/lib/types/activities/media/prepareAudio.d.ts.map +1 -0
  306. package/lib/types/activities/media/prepareVideo.d.ts +30 -0
  307. package/lib/types/activities/media/prepareVideo.d.ts.map +1 -0
  308. package/lib/types/activities/media/processPdfWithTextract.d.ts +26 -0
  309. package/lib/types/activities/media/processPdfWithTextract.d.ts.map +1 -0
  310. package/lib/types/activities/media/saveGladiaTranscription.d.ts +14 -0
  311. package/lib/types/activities/media/saveGladiaTranscription.d.ts.map +1 -0
  312. package/lib/types/activities/media/transcribeMediaWithGladia.d.ts +19 -0
  313. package/lib/types/activities/media/transcribeMediaWithGladia.d.ts.map +1 -0
  314. package/lib/types/activities/notifyWebhook.d.ts +27 -0
  315. package/lib/types/activities/notifyWebhook.d.ts.map +1 -0
  316. package/lib/types/activities/rateLimiter.d.ts +11 -0
  317. package/lib/types/activities/rateLimiter.d.ts.map +1 -0
  318. package/lib/types/activities/renditions/generateImageRendition.d.ts +14 -0
  319. package/lib/types/activities/renditions/generateImageRendition.d.ts.map +1 -0
  320. package/lib/types/activities/renditions/generateVideoRendition.d.ts +15 -0
  321. package/lib/types/activities/renditions/generateVideoRendition.d.ts.map +1 -0
  322. package/lib/types/activities/setDocumentStatus.d.ts +15 -0
  323. package/lib/types/activities/setDocumentStatus.d.ts.map +1 -0
  324. package/lib/types/conversion/TextractProcessor.d.ts +45 -0
  325. package/lib/types/conversion/TextractProcessor.d.ts.map +1 -0
  326. package/lib/types/conversion/image.d.ts +13 -0
  327. package/lib/types/conversion/image.d.ts.map +1 -0
  328. package/lib/types/conversion/markitdown.d.ts +2 -0
  329. package/lib/types/conversion/markitdown.d.ts.map +1 -0
  330. package/lib/types/conversion/mutool.d.ts +19 -0
  331. package/lib/types/conversion/mutool.d.ts.map +1 -0
  332. package/lib/types/conversion/pandoc.d.ts +2 -0
  333. package/lib/types/conversion/pandoc.d.ts.map +1 -0
  334. package/lib/types/dsl/conditions.d.ts +2 -0
  335. package/lib/types/dsl/conditions.d.ts.map +1 -0
  336. package/lib/types/dsl/dsl-workflow.d.ts +5 -0
  337. package/lib/types/dsl/dsl-workflow.d.ts.map +1 -0
  338. package/lib/types/dsl/dslProxyActivities.d.ts +10 -0
  339. package/lib/types/dsl/dslProxyActivities.d.ts.map +1 -0
  340. package/lib/types/dsl/projections.d.ts +4 -0
  341. package/lib/types/dsl/projections.d.ts.map +1 -0
  342. package/lib/types/dsl/setup/ActivityContext.d.ts +17 -0
  343. package/lib/types/dsl/setup/ActivityContext.d.ts.map +1 -0
  344. package/lib/types/dsl/setup/fetch/DataProvider.d.ts +9 -0
  345. package/lib/types/dsl/setup/fetch/DataProvider.d.ts.map +1 -0
  346. package/lib/types/dsl/setup/fetch/index.d.ts +6 -0
  347. package/lib/types/dsl/setup/fetch/index.d.ts.map +1 -0
  348. package/lib/types/dsl/setup/fetch/providers.d.ts +25 -0
  349. package/lib/types/dsl/setup/fetch/providers.d.ts.map +1 -0
  350. package/lib/types/dsl/test/test-child-workflow.d.ts +4 -0
  351. package/lib/types/dsl/test/test-child-workflow.d.ts.map +1 -0
  352. package/lib/types/dsl/validation.d.ts +4 -0
  353. package/lib/types/dsl/validation.d.ts.map +1 -0
  354. package/lib/types/dsl/vars.d.ts +48 -0
  355. package/lib/types/dsl/vars.d.ts.map +1 -0
  356. package/lib/types/dsl/walk.d.ts +18 -0
  357. package/lib/types/dsl/walk.d.ts.map +1 -0
  358. package/lib/types/dsl.d.ts +4 -0
  359. package/lib/types/dsl.d.ts.map +1 -0
  360. package/lib/types/errors.d.ts +37 -0
  361. package/lib/types/errors.d.ts.map +1 -0
  362. package/lib/types/index.d.ts +37 -0
  363. package/lib/types/index.d.ts.map +1 -0
  364. package/lib/types/iterative-generation/activities/extractToc.d.ts +10 -0
  365. package/lib/types/iterative-generation/activities/extractToc.d.ts.map +1 -0
  366. package/lib/types/iterative-generation/activities/finalizeOutput.d.ts +3 -0
  367. package/lib/types/iterative-generation/activities/finalizeOutput.d.ts.map +1 -0
  368. package/lib/types/iterative-generation/activities/generatePart.d.ts +3 -0
  369. package/lib/types/iterative-generation/activities/generatePart.d.ts.map +1 -0
  370. package/lib/types/iterative-generation/activities/generateToc.d.ts +4 -0
  371. package/lib/types/iterative-generation/activities/generateToc.d.ts.map +1 -0
  372. package/lib/types/iterative-generation/activities/index.d.ts +5 -0
  373. package/lib/types/iterative-generation/activities/index.d.ts.map +1 -0
  374. package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts +3 -0
  375. package/lib/types/iterative-generation/iterativeGenerationWorkflow.d.ts.map +1 -0
  376. package/lib/types/iterative-generation/types.d.ts +79 -0
  377. package/lib/types/iterative-generation/types.d.ts.map +1 -0
  378. package/lib/types/iterative-generation/utils.d.ts +26 -0
  379. package/lib/types/iterative-generation/utils.d.ts.map +1 -0
  380. package/lib/types/result-types.d.ts +22 -0
  381. package/lib/types/result-types.d.ts.map +1 -0
  382. package/lib/types/system/notifyWebhookWorkflow.d.ts +8 -0
  383. package/lib/types/system/notifyWebhookWorkflow.d.ts.map +1 -0
  384. package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts +25 -0
  385. package/lib/types/system/recalculateEmbeddingsWorkflow.d.ts.map +1 -0
  386. package/lib/types/utils/auth.d.ts +4 -0
  387. package/lib/types/utils/auth.d.ts.map +1 -0
  388. package/lib/types/utils/blobs.d.ts +7 -0
  389. package/lib/types/utils/blobs.d.ts.map +1 -0
  390. package/lib/types/utils/chunks.d.ts +9 -0
  391. package/lib/types/utils/chunks.d.ts.map +1 -0
  392. package/lib/types/utils/client.d.ts +8 -0
  393. package/lib/types/utils/client.d.ts.map +1 -0
  394. package/lib/types/utils/expand-vars.d.ts +8 -0
  395. package/lib/types/utils/expand-vars.d.ts.map +1 -0
  396. package/lib/types/utils/memory.d.ts +8 -0
  397. package/lib/types/utils/memory.d.ts.map +1 -0
  398. package/lib/types/utils/renditions.d.ts +23 -0
  399. package/lib/types/utils/renditions.d.ts.map +1 -0
  400. package/lib/types/utils/storage.d.ts +16 -0
  401. package/lib/types/utils/storage.d.ts.map +1 -0
  402. package/lib/types/utils/tokens.d.ts +11 -0
  403. package/lib/types/utils/tokens.d.ts.map +1 -0
  404. package/lib/types/vars.d.ts +3 -0
  405. package/lib/types/vars.d.ts.map +1 -0
  406. package/lib/types/workflows.d.ts +8 -0
  407. package/lib/types/workflows.d.ts.map +1 -0
  408. package/lib/workflows-bundle.js +17213 -0
  409. package/package.json +146 -0
  410. package/src/activities/advanced/createDocumentTypeFromInteractionRun.ts +55 -0
  411. package/src/activities/advanced/createOrUpdateDocumentFromInteractionRun.ts +119 -0
  412. package/src/activities/advanced/updateDocumentFromInteractionRun.ts +35 -0
  413. package/src/activities/chunkDocument.ts +146 -0
  414. package/src/activities/copyParentArtifacts.ts +162 -0
  415. package/src/activities/createDocumentFromOther.ts +92 -0
  416. package/src/activities/executeInteraction.ts +300 -0
  417. package/src/activities/extractDocumentText.ts +205 -0
  418. package/src/activities/generateDocumentProperties.ts +120 -0
  419. package/src/activities/generateEmbeddings.ts +387 -0
  420. package/src/activities/generateOrAssignContentType.ts +218 -0
  421. package/src/activities/getObjectFromStore.ts +31 -0
  422. package/src/activities/handleError.ts +25 -0
  423. package/src/activities/index-dsl.ts +25 -0
  424. package/src/activities/index.ts +4 -0
  425. package/src/activities/media/prepareAudio.ts +334 -0
  426. package/src/activities/media/prepareVideo.ts +622 -0
  427. package/src/activities/media/processPdfWithTextract.ts +141 -0
  428. package/src/activities/media/saveGladiaTranscription.ts +128 -0
  429. package/src/activities/media/transcribeMediaWithGladia.ts +117 -0
  430. package/src/activities/notifyWebhook.test.ts +134 -0
  431. package/src/activities/notifyWebhook.ts +199 -0
  432. package/src/activities/rateLimiter.ts +41 -0
  433. package/src/activities/renditions/generateImageRendition.ts +111 -0
  434. package/src/activities/renditions/generateVideoRendition.ts +293 -0
  435. package/src/activities/setDocumentStatus.ts +25 -0
  436. package/src/conversion/TextractProcessor.ts +506 -0
  437. package/src/conversion/image.test.ts +118 -0
  438. package/src/conversion/image.ts +168 -0
  439. package/src/conversion/markitdown.ts +41 -0
  440. package/src/conversion/mutool.test.ts +74 -0
  441. package/src/conversion/mutool.ts +180 -0
  442. package/src/conversion/pandoc.test.ts +24 -0
  443. package/src/conversion/pandoc.ts +40 -0
  444. package/src/dsl/conditions.ts +76 -0
  445. package/src/dsl/dsl-workflow.test.ts +58 -0
  446. package/src/dsl/dsl-workflow.ts +397 -0
  447. package/src/dsl/dslProxyActivities.ts +38 -0
  448. package/src/dsl/ms.d.ts +11 -0
  449. package/src/dsl/projections.test.ts +159 -0
  450. package/src/dsl/projections.ts +72 -0
  451. package/src/dsl/setup/ActivityContext.ts +178 -0
  452. package/src/dsl/setup/fetch/DataProvider.ts +45 -0
  453. package/src/dsl/setup/fetch/index.ts +19 -0
  454. package/src/dsl/setup/fetch/providers.ts +67 -0
  455. package/src/dsl/test/test-child-workflow.ts +6 -0
  456. package/src/dsl/validation.test.ts +257 -0
  457. package/src/dsl/validation.ts +125 -0
  458. package/src/dsl/vars.test.ts +245 -0
  459. package/src/dsl/vars.ts +340 -0
  460. package/src/dsl/walk.test.ts +81 -0
  461. package/src/dsl/walk.ts +103 -0
  462. package/src/dsl/workflow-exec-child.test.ts +273 -0
  463. package/src/dsl/workflow-fetch.test.ts +138 -0
  464. package/src/dsl/workflow-import.test.ts +89 -0
  465. package/src/dsl/workflow.test.ts +122 -0
  466. package/src/dsl.ts +3 -0
  467. package/src/errors.ts +101 -0
  468. package/src/index.ts +41 -0
  469. package/src/iterative-generation/activities/extractToc.ts +63 -0
  470. package/src/iterative-generation/activities/finalizeOutput.ts +100 -0
  471. package/src/iterative-generation/activities/generatePart.ts +123 -0
  472. package/src/iterative-generation/activities/generateToc.ts +116 -0
  473. package/src/iterative-generation/activities/index.ts +4 -0
  474. package/src/iterative-generation/iterativeGenerationWorkflow.ts +68 -0
  475. package/src/iterative-generation/types.ts +99 -0
  476. package/src/iterative-generation/utils.ts +126 -0
  477. package/src/result-types.ts +25 -0
  478. package/src/system/notifyWebhookWorkflow.ts +70 -0
  479. package/src/system/recalculateEmbeddingsWorkflow.ts +41 -0
  480. package/src/utils/auth.ts +10 -0
  481. package/src/utils/blobs.ts +59 -0
  482. package/src/utils/chunks.ts +17 -0
  483. package/src/utils/client.ts +46 -0
  484. package/src/utils/expand-vars.ts +31 -0
  485. package/src/utils/memory.ts +61 -0
  486. package/src/utils/renditions.ts +127 -0
  487. package/src/utils/storage.ts +60 -0
  488. package/src/utils/tokens.ts +44 -0
  489. package/src/vars.ts +3 -0
  490. package/src/workflows.ts +7 -0
@@ -0,0 +1,245 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { Vars } from "./vars.ts";
3
+
4
+ describe('Workflow vars', () => {
5
+
6
+ test('access initial variables', () => {
7
+ const vars = new Vars({
8
+ objectId: "123",
9
+ timestamp: 123456,
10
+ });
11
+ expect(vars.getValue("objectId")).toBe("123");
12
+ expect(vars.getValue("timestamp")).toBe(123456);
13
+ expect(vars.getValue("foo")).toBeUndefined();
14
+ })
15
+
16
+ test('set and access variables', () => {
17
+ const vars = new Vars({
18
+ objectId: "123",
19
+ timestamp: 123456,
20
+ });
21
+ expect(vars.getValue("objectId")).toBe("123");
22
+ vars.setValue("objectId", "456");
23
+ expect(vars.getValue("objectId")).toBe("456");
24
+ })
25
+
26
+ test('access and modify ref variables', () => {
27
+ const vars = new Vars({
28
+ objectId: "123",
29
+ config: {
30
+ name: "foo",
31
+ },
32
+ objectIdAlias: "${objectId}",
33
+ configNameAlias: "${config.name}",
34
+ });
35
+ expect(vars.getValue("objectIdAlias")).toBe("123");
36
+ expect(vars.getValue("configNameAlias")).toBe("foo");
37
+ vars.setValue("objectId", "456");
38
+ vars.getValue("config").name = "bar";
39
+ expect(vars.getValue("objectIdAlias")).toBe("456");
40
+ expect(vars.getValue("configNameAlias")).toBe("bar");
41
+ })
42
+
43
+ test('replace literal with ref', () => {
44
+ const vars = new Vars({
45
+ objectId: "123",
46
+ otherId: "1234",
47
+ });
48
+ expect(vars.getValue("objectId")).toBe("123");
49
+ expect(vars.getValue("otherId")).toBe("1234");
50
+ vars.setValue("objectId", "456");
51
+ vars.load({ "otherId": "${objectId}" });
52
+ expect(vars.getValue("objectId")).toBe("456");
53
+ expect(vars.getValue("otherId")).toBe("456");
54
+ });
55
+
56
+ test("undefined ref variable", () => {
57
+ const vars = new Vars({
58
+ otherId: "${objectId}",
59
+ });
60
+ expect(vars.getValue("otherId")).toBeUndefined();
61
+ })
62
+
63
+ test("default values", () => {
64
+ const vars = new Vars({
65
+ squote: "${objectId ?? '123'}",
66
+ dquote: "${objectId ?? \"123\"}",
67
+ number: "${objectId ?? 123}",
68
+ boolean: "${objectId ?? true}",
69
+ array: "${objectId ?? [1,2]}",
70
+ });
71
+ // object value and path expression are not supported
72
+ expect(vars.getValue("squote")).toBe("123");
73
+ expect(vars.getValue("dquote")).toBe("123");
74
+ expect(vars.getValue("number")).toBe(123);
75
+ expect(vars.getValue("boolean")).toBe(true);
76
+ expect(vars.getValue("array")).toEqual([1, 2]);
77
+ })
78
+
79
+ test("array map", () => {
80
+ const vars = new Vars({
81
+ docs: [{ text: "hello" }, { text: "world" }],
82
+ });
83
+ // object valus and path expression are not supported
84
+ expect(vars.getValue("docs.text").join(' ')).toBe("hello world");
85
+ })
86
+
87
+ test("resolveParams", () => {
88
+ const vars = new Vars({
89
+ objectIds: ["123", "456"],
90
+ objectId: "123",
91
+ data: { message: "hello" },
92
+ });
93
+ const params = {
94
+ query: {
95
+ _id: "${objectId}",
96
+ data: "${data}",
97
+ },
98
+ secondDocId: "${objectIds.1}",
99
+ secondDocIdByBracket: "${objectIds[1]}",
100
+ }
101
+ const resolved = vars.resolveParams(params);
102
+ expect(Object.keys(resolved).length).toBe(3);
103
+ expect(resolved.query).toBeTypeOf("object");
104
+ expect(resolved.query._id).toBe("123");
105
+ expect(resolved.query.data).toBeTypeOf("object");
106
+ expect(resolved.query.data.message).toBe("hello");
107
+ expect(resolved.secondDocId).toBe("456");
108
+ expect(resolved.secondDocIdByBracket).toBe("456");
109
+
110
+ });
111
+
112
+ test("resolve", () => {
113
+ const vars = new Vars({
114
+ objectId: "123",
115
+ message: "hello",
116
+ prompt_data: { message: "${message}" },
117
+ data2: "${prompt_data}",
118
+ unknown: "${notdefined}"
119
+ });
120
+ const resolved = vars.resolve();
121
+ console.log('@@@@@@@@@@@@@@@@@@@', resolved);
122
+ expect(Object.keys(resolved).length).toBe(4); // since unknown will be undefined it will not be included
123
+ expect(resolved.objectId).toBe("123");
124
+ expect(resolved.prompt_data).toBeTypeOf("object");
125
+ expect(resolved.prompt_data.message).toBe("hello");
126
+ expect(resolved.data2).toBeTypeOf("object");
127
+ expect(resolved.data2.message).toBe("hello");
128
+ expect(resolved.unknown).toBeUndefined();
129
+ });
130
+
131
+
132
+ test("createImportVars", () => {
133
+ const vars = new Vars({
134
+ person: { name: "John", age: 30 },
135
+ objectId: "123",
136
+ data: { message: "hello" },
137
+ data2: "${data}",
138
+ });
139
+ const params = vars.createImportVars(["data2", { "name": "person.name", "age": "person.age" }, { message: "data.message" }]);
140
+ expect(Object.keys(params).length).toBe(4);
141
+ expect(params.name).toBe("John");
142
+ expect(params.age).toBe(30);
143
+ expect(params.message).toBe("hello");
144
+ expect(params.data2).toStrictEqual({ message: "hello" });
145
+ });
146
+
147
+ test("evaluate null and exists conditions", () => {
148
+ const vars = new Vars({
149
+ objectId: "123",
150
+ docType: {
151
+ id: "bla",
152
+ idNull: null,
153
+ }
154
+ });
155
+ expect(vars.match({ objectId: { $exists: true } })).toBe(true);
156
+ expect(vars.match({ objectId: { $exists: false } })).toBe(false);
157
+ expect(vars.match({ objectIds: { $exists: true } })).toBe(false);
158
+ expect(vars.match({ objectIds: { $exists: false } })).toBe(true);
159
+ expect(vars.match({ "docType.id": { $exists: true } })).toBe(true);
160
+ expect(vars.match({ "docType.idNull": { $exists: true } })).toBe(true);
161
+
162
+ expect(vars.match({ objectId: { $null: true } })).toBe(false);
163
+ expect(vars.match({ objectId: { $null: false } })).toBe(true);
164
+ expect(vars.match({ objectIds: { $null: false } })).toBe(false);
165
+ expect(vars.match({ objectIds: { $null: true } })).toBe(true);
166
+ expect(vars.match({ "docType.id": { $null: true } })).toBe(false);
167
+ expect(vars.match({ "docType.idNull": { $null: true } })).toBe(true);
168
+ });
169
+
170
+ test("evaluate $eq conditions", () => {
171
+ const vars = new Vars({
172
+ objectId: "123",
173
+ otherId: "${objectId}",
174
+ config: {
175
+ name: { foo: "bar" },
176
+ tags: ["a", "b", "c"]
177
+ }
178
+ });
179
+ expect(vars.match({ objectId: { $eq: "123" } })).toBe(true);
180
+ expect(vars.match({ objectId: { $eq: "456" } })).toBe(false);
181
+ expect(vars.match({ objectId: { $ne: "123" } })).toBe(false);
182
+ expect(vars.match({ objectId: { $ne: "456" } })).toBe(true);
183
+
184
+ expect(vars.match({ otherId: { $eq: "123" } })).toBe(true);
185
+ expect(vars.match({ otherId: { $eq: "456" } })).toBe(false);
186
+ expect(vars.match({ otherId: { $ne: "123" } })).toBe(false);
187
+ expect(vars.match({ otherId: { $ne: "456" } })).toBe(true);
188
+
189
+ expect(vars.match({ "config": { $eq: { name: { foo: "bar" }, tags: ["a", "b", "c"] } } })).toBe(true);
190
+ });
191
+
192
+ test("evaluate $regexp conditions", () => {
193
+ const vars = new Vars({
194
+ expr: "a=2",
195
+ });
196
+ expect(vars.match({ expr: { $regexp: "^.*\\s*=\\s*.*$" } })).toBe(true);
197
+ });
198
+
199
+ test("evaluate string compare conditions", () => {
200
+ const vars = new Vars({
201
+ expr: "<tag />",
202
+ });
203
+ expect(vars.match({ expr: { $startsWith: "<" } })).toBe(true);
204
+ expect(vars.match({ expr: { $contains: "tag" } })).toBe(true);
205
+ expect(vars.match({ expr: { $endsWith: "/>" } })).toBe(true);
206
+ });
207
+
208
+ test("evaluate $in conditions", () => {
209
+ const vars = new Vars({
210
+ name: "foo",
211
+ });
212
+ expect(vars.match({ name: { $in: ["foo", "bar"] } })).toBe(true);
213
+ expect(vars.match({ name: { $nin: ["hello", "world"] } })).toBe(true);
214
+ });
215
+
216
+ test("evaluate $lt, $gt conditions", () => {
217
+ const vars = new Vars({
218
+ value: 5,
219
+ });
220
+ expect(vars.match({ value: { $lt: 6 } })).toBe(true);
221
+ expect(vars.match({ value: { $gt: 4 } })).toBe(true);
222
+ expect(vars.match({ value: { $lte: 5 } })).toBe(true);
223
+ expect(vars.match({ value: { $gte: 5 } })).toBe(true);
224
+ });
225
+
226
+ test("evaluate $or conditions", () => {
227
+ const vars = new Vars({
228
+ value: 5,
229
+ name: "foo"
230
+ });
231
+ expect(vars.match({ value: { $or: [{ $lt: 4 }, { $gt: 6 }] } })).toBe(false);
232
+ expect(vars.match({ name: { $or: [{ $eq: "bar" }, { $eq: "foo" }] } })).toBe(true);
233
+ expect(vars.match({ name: { $or: [{ $eq: "bar" }, { $eq: "fooo" }] } })).toBe(false);
234
+ });
235
+
236
+ test("evaluate nested conditions", () => {
237
+ const vars = new Vars({
238
+ config: {
239
+ name: "foo",
240
+ },
241
+ });
242
+ expect(vars.match({ "config.name": { $eq: "foo" } })).toBe(true);
243
+ });
244
+
245
+ });
@@ -0,0 +1,340 @@
1
+ import { ImportSpec } from "@vertesia/common";
2
+ import { matchCondition } from "./conditions.js";
3
+ import { ObjectKey, ObjectVisitor, ObjectWalker } from "./walk.js";
4
+
5
+ const FALLBACK_VALUE_SEP = "??";
6
+
7
+ function decodeLiteralValue(value: string) {
8
+ if (value.startsWith("'") && value.endsWith("'")) {
9
+ value = '"' + value.slice(1, -1).replace(/(?<!\\)"/g, '\\"') + '"'
10
+ }
11
+ return JSON.parse(value);
12
+ }
13
+
14
+ export function splitPath(path: string) {
15
+ if (path.indexOf('[') > -1) { // support array like paths
16
+ path = path.replace(/\[(\d+)\]/g, '.$1');
17
+ }
18
+ return path.split('.');
19
+ }
20
+
21
+ /**
22
+ * Get the property named by "name" of the given object
23
+ * If an array is indexed using a string key then a map is done and an array with the content of the properties with that name are returned
24
+ * Ex: docs.text => will return an array of text properties of the docs array
25
+ * @param object the object
26
+ * @param name the name of the property.
27
+ * @returns the property value
28
+ */
29
+ function _prop(object: any, name: string) {
30
+ if (object === undefined) {
31
+ return undefined;
32
+ }
33
+ object = _valueOf(object); // resolve Value objects
34
+ if (Array.isArray(object)) {
35
+ const index = +name;
36
+ if (isNaN(index)) {
37
+ // map array to property
38
+ return object.map(item => item[name]);
39
+ } else {
40
+ return _valueOf(object[index]);
41
+ }
42
+ } else {
43
+ return _valueOf(object[name]);
44
+ }
45
+
46
+ }
47
+
48
+ function _valueOf(value: any) {
49
+ return value instanceof Value ? value.value : value;
50
+ }
51
+
52
+ export function resolveField(object: any, path: string[]) {
53
+ let p = object as any;
54
+ if (!p) return p;
55
+ if (!path.length) return _valueOf(p);
56
+ const last = path.length - 1;
57
+ for (let i = 0; i < last; i++) {
58
+ p = _prop(p, path[i])
59
+ if (!p) {
60
+ return undefined;
61
+ }
62
+ }
63
+ return _prop(p, path[last]);
64
+ }
65
+
66
+ abstract class Value<T = any> {
67
+ abstract value: T;
68
+ abstract stringify(): string;
69
+ }
70
+ class LiteralValue<T = any> extends Value<T> {
71
+ constructor(public value: T) {
72
+ super();
73
+ }
74
+ stringify() {
75
+ return String(this.value);
76
+ }
77
+ }
78
+
79
+ class RefValue extends Value {
80
+ constructor(public vars: Vars, public path: string[], public defaultValue?: any) {
81
+ super();
82
+ }
83
+ get value() {
84
+ const v = this.vars.getValueFromPath(this.path);
85
+ if (v === undefined) {
86
+ if (this.defaultValue !== undefined) {
87
+ return this.defaultValue;
88
+ } else {
89
+ return this.vars.preserveRefs ? this.stringify() : undefined;
90
+ }
91
+ } else {
92
+ return v;
93
+ }
94
+ }
95
+
96
+ stringify() {
97
+ return "${" + this.path.join('.') + "}";
98
+ }
99
+ }
100
+
101
+ class ExprValue extends Value {
102
+ constructor(public vars: Vars, public parts: Value[]) {
103
+ super();
104
+ }
105
+ get value() {
106
+ const out: string[] = [];
107
+ for (const seg of this.parts) {
108
+ const v = seg.value;
109
+ if (v !== undefined) {
110
+ out.push(String(seg.value));
111
+ }
112
+ }
113
+ return out.join('');
114
+ }
115
+
116
+ stringify() {
117
+ const out = [];
118
+ for (const seg of this.parts) {
119
+ out.push(seg.stringify());
120
+ }
121
+ return "${" + out.join('') + "}";
122
+ }
123
+
124
+ }
125
+
126
+
127
+ export class Vars {
128
+ map: Record<string, any>;
129
+ /**
130
+ * This property is used when resolving params. It contains the list of references that should not be resolved to their value
131
+ * but instead they need to return the string representation of the expression to be able to regenerate another Vars instance with the same expression
132
+ */
133
+ //TODO this feature is no more used - it was replaced by importVars so we can now delete `preserveRefs`
134
+ preserveRefs: Set<string> | undefined;
135
+
136
+ constructor(vars?: Record<string, any>) {
137
+ this.map = vars ? this.parse(vars) : {};
138
+ }
139
+
140
+ parse(vars: Record<string, any>): Record<string, any> {
141
+ return new ObjectWalker().map(vars, (_key, value) => {
142
+ if (typeof value === 'string') {
143
+ return this.createValue(this, value);
144
+ } else {
145
+ return value;
146
+ }
147
+ });
148
+ }
149
+
150
+ load(vars: Record<string, any>) {
151
+ const toAppend = this.parse(vars);
152
+ this.map = Object.assign(this.map, toAppend);
153
+ return this;
154
+ }
155
+
156
+ /**
157
+ * Set a literal value (cannot set a ref)
158
+ * To add refs use `append()`
159
+ * @param name
160
+ * @param value
161
+ */
162
+ setValue(name: string, value: any) {
163
+ this.map[name] = value;
164
+ }
165
+
166
+ getValue(path: string) {
167
+ return resolveField(this.map, splitPath(path));
168
+ }
169
+
170
+ getValueFromPath(path: string[]) {
171
+ return resolveField(this.map, path);
172
+ }
173
+
174
+ has(name: string) {
175
+ return this.map[name] !== undefined;
176
+ }
177
+
178
+ match(match: Record<string, any>) {
179
+ for (const name of Object.keys(match)) {
180
+ const value = this.getValue(name);
181
+ if (!matchCondition(value, match[name])) {
182
+ return false;
183
+ }
184
+ }
185
+ return true;
186
+ }
187
+
188
+ resolveParams(params: Record<string, any>, preserveRefs?: Set<string>) {
189
+ this.preserveRefs = preserveRefs;
190
+ try {
191
+ return new ObjectWalker().map(params, (_key, value) => {
192
+ if (typeof value === 'string') {
193
+ const v = this.createValue(this, value)
194
+ return v instanceof Value ? v.value : v;
195
+ } else {
196
+ return value;
197
+ }
198
+ });
199
+ } finally {
200
+ this.preserveRefs = undefined;
201
+ }
202
+ }
203
+
204
+ resolve(preserveRefs?: Set<string>): Record<string, any> {
205
+ function map(_key: ObjectKey, value: any) {
206
+ if (value instanceof Value) {
207
+ const v = value.value;
208
+ if (v && typeof v === 'object') {
209
+ if (Array.isArray(v) || v.constructor === Object) {
210
+ // an array or plain object - recurse into the
211
+ // value to find other nested Ref values if any...
212
+ return new ObjectWalker().map(v, map);
213
+ }
214
+ } else {
215
+ return v;
216
+ }
217
+ } else {
218
+ return value
219
+ }
220
+ }
221
+ try {
222
+ this.preserveRefs = preserveRefs;
223
+ return new ObjectWalker().map(this.map, map);
224
+ } finally {
225
+ this.preserveRefs = undefined;
226
+ }
227
+ }
228
+
229
+ createRefValue(ref: string) {
230
+ const index = ref.indexOf(FALLBACK_VALUE_SEP);
231
+ let defaultValue: any;
232
+ if (index > -1) {
233
+ defaultValue = decodeLiteralValue(ref.substring(index + FALLBACK_VALUE_SEP.length).trim());
234
+ ref = ref.substring(0, index).trim();
235
+ }
236
+ if (ref === '.' || ref.indexOf('..') > -1) {
237
+ throw new Error("Invalid variable reference: " + ref)
238
+ }
239
+ return new RefValue(this, splitPath(ref), defaultValue);
240
+ }
241
+
242
+ createValue(vars: Vars, obj: any) {
243
+ if (!obj) {
244
+ return obj;
245
+ }
246
+ if (typeof obj === 'string') {
247
+ if (obj.indexOf('${') > -1) {
248
+ const segments = obj.split(/(\${[^}]+})/);
249
+ if (segments.length === 1) {
250
+ const seg = segments[0];
251
+ return this.createRefValue(seg.substring(2, seg.length - 1));
252
+ }
253
+ const parts: Value[] = [];
254
+ for (const seg of segments) {
255
+ if (seg === '') continue;
256
+ if (seg.startsWith('${') && seg.endsWith('}')) {
257
+ parts.push(this.createRefValue(seg.substring(2, seg.length - 1)));
258
+ } else {
259
+ parts.push(new LiteralValue(seg));
260
+ }
261
+ }
262
+ if (parts.length === 1) {
263
+ return parts[0];
264
+ } else {
265
+ return new ExprValue(vars, parts);
266
+ }
267
+ } else {
268
+ return obj;
269
+ }
270
+ } else {
271
+ return obj;
272
+ }
273
+ }
274
+
275
+ createImportVars(importSpec: ImportSpec | undefined) {
276
+ if (!importSpec || importSpec.length === 0) {
277
+ return {};
278
+ }
279
+ const result: Record<string, any> = {};
280
+
281
+ for (const importVar of importSpec) {
282
+ if (typeof importVar === "string") {
283
+ addImportVar(importVar, undefined, this, result);
284
+ } else {
285
+ for (const key of Object.keys(importVar)) {
286
+ addImportVar(importVar[key], key, this, result);
287
+ }
288
+ }
289
+ }
290
+ return result;
291
+ }
292
+
293
+ getUnknownReferences(obj: any) {
294
+ const visitor = new UnknownReferencesVisitor(this);
295
+ new ObjectWalker().walk(obj, visitor);
296
+ return visitor.result;
297
+ }
298
+ }
299
+
300
+ function addImportVar(varPath: string, asName: string | undefined, vars: Vars, result: Record<string, any>) {
301
+ let isRequired = false;
302
+ if (varPath.endsWith("!")) {
303
+ isRequired = true;
304
+ varPath = varPath.slice(0, -1);
305
+ }
306
+ let value = vars.getValue(varPath);
307
+ if (value === undefined && isRequired) {
308
+ throw new Error(`Import variable ${varPath} is required but not found`);
309
+ }
310
+ result[asName || varPath] = value;
311
+ }
312
+
313
+
314
+ class UnknownReferencesVisitor implements ObjectVisitor {
315
+
316
+ result: { name: string, expression: string }[] = [];
317
+
318
+ constructor(public vars: Vars) {
319
+ }
320
+
321
+ onValue(_key: ObjectKey, value: any) {
322
+ const vars = this.vars;
323
+ if (typeof value === "string") {
324
+ const v = vars.createValue(vars, value);
325
+ if (v instanceof ExprValue) {
326
+ for (const p of v.parts) {
327
+ if (p instanceof RefValue) {
328
+ if (!vars.has(p.path[0])) {
329
+ this.result.push({ name: p.path.join('.'), expression: p.stringify() });
330
+ }
331
+ }
332
+ }
333
+ } else if (v instanceof RefValue) {
334
+ if (!vars.has(v.path[0])) {
335
+ this.result.push({ name: v.path.join('.'), expression: v.stringify() });
336
+ }
337
+ }
338
+ }
339
+ }
340
+ }
@@ -0,0 +1,81 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { ObjectWalker } from "./walk.ts";
3
+
4
+ describe('walk object', () => {
5
+
6
+ test('find string values', () => {
7
+ const obj = {
8
+ name: "foo",
9
+ age: 42,
10
+ children: [{
11
+ name: "bar",
12
+ age: 12,
13
+ },
14
+ {
15
+ name: "baz",
16
+ age: 15,
17
+ }],
18
+ folder: {
19
+ subfolder: {
20
+ name: "file",
21
+ }
22
+ }
23
+ }
24
+ const values = ["foo", "bar", "baz", "file"].sort().join(',');
25
+ const found: string[] = [];
26
+ new ObjectWalker().walk(obj, {
27
+ onValue(key, value) {
28
+ if (typeof value === "string") {
29
+ found.push(value);
30
+ }
31
+ }
32
+ })
33
+ expect(found.sort().join(',')).toBe(values);
34
+ })
35
+
36
+ test('map numbers to string values', () => {
37
+ const obj = {
38
+ name: "foo",
39
+ age: 42,
40
+ children: [{
41
+ name: "bar",
42
+ age: 12,
43
+ },
44
+ {
45
+ name: "baz",
46
+ age: 15,
47
+ }],
48
+ folder: {
49
+ subfolder: {
50
+ name: 123,
51
+ }
52
+ }
53
+ }
54
+ const r = new ObjectWalker().map(obj, (_key, value) => {
55
+ if (typeof value === "number") {
56
+ return String(value)
57
+ }
58
+ return value;
59
+ });
60
+ expect(r.age).toBe("42");
61
+ expect(r.children[0].age).toBe("12");
62
+ expect(r.children[1].age).toBe("15");
63
+ expect(r.folder.subfolder.name).toBe("123");
64
+ })
65
+
66
+ test('map numbers in an array to string values', () => {
67
+ const obj = [123, { x: 1 }, { y: 2 }, { z: 3 }]
68
+ const r = new ObjectWalker().map(obj, (_key, value) => {
69
+ if (typeof value === "number") {
70
+ return String(value)
71
+ }
72
+ return value;
73
+ });
74
+ expect(r.length).toBe(4);
75
+ expect(r[0]).toBe("123");
76
+ expect(r[1].x).toBe("1");
77
+ expect(r[2].y).toBe("2");
78
+ expect(r[3].z).toBe("3");
79
+ })
80
+
81
+ })