@blue-labs/language 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +133 -0
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +34 -0
  6. package/dist/index.mjs +4476 -0
  7. package/dist/lib/Blue.d.ts +99 -0
  8. package/dist/lib/Blue.d.ts.map +1 -0
  9. package/dist/lib/NodeProvider.d.ts +26 -0
  10. package/dist/lib/NodeProvider.d.ts.map +1 -0
  11. package/dist/lib/index.d.ts +9 -0
  12. package/dist/lib/index.d.ts.map +1 -0
  13. package/dist/lib/mapping/AnyConverter.d.ts +6 -0
  14. package/dist/lib/mapping/AnyConverter.d.ts.map +1 -0
  15. package/dist/lib/mapping/ArrayConverter.d.ts +10 -0
  16. package/dist/lib/mapping/ArrayConverter.d.ts.map +1 -0
  17. package/dist/lib/mapping/ComplexObjectConverter.d.ts +15 -0
  18. package/dist/lib/mapping/ComplexObjectConverter.d.ts.map +1 -0
  19. package/dist/lib/mapping/Converter.d.ts +6 -0
  20. package/dist/lib/mapping/Converter.d.ts.map +1 -0
  21. package/dist/lib/mapping/ConverterFactory.d.ts +14 -0
  22. package/dist/lib/mapping/ConverterFactory.d.ts.map +1 -0
  23. package/dist/lib/mapping/MapConverter.d.ts +14 -0
  24. package/dist/lib/mapping/MapConverter.d.ts.map +1 -0
  25. package/dist/lib/mapping/NodeToObjectConverter.d.ts +13 -0
  26. package/dist/lib/mapping/NodeToObjectConverter.d.ts.map +1 -0
  27. package/dist/lib/mapping/NullConverter.d.ts +5 -0
  28. package/dist/lib/mapping/NullConverter.d.ts.map +1 -0
  29. package/dist/lib/mapping/PrimitiveConverter.d.ts +7 -0
  30. package/dist/lib/mapping/PrimitiveConverter.d.ts.map +1 -0
  31. package/dist/lib/mapping/SetConverter.d.ts +10 -0
  32. package/dist/lib/mapping/SetConverter.d.ts.map +1 -0
  33. package/dist/lib/mapping/TupleConverter.d.ts +13 -0
  34. package/dist/lib/mapping/TupleConverter.d.ts.map +1 -0
  35. package/dist/lib/mapping/UnknownConverter.d.ts +6 -0
  36. package/dist/lib/mapping/UnknownConverter.d.ts.map +1 -0
  37. package/dist/lib/mapping/ValueConverter.d.ts +12 -0
  38. package/dist/lib/mapping/ValueConverter.d.ts.map +1 -0
  39. package/dist/lib/mapping/__tests__/schema/contract.d.ts +364 -0
  40. package/dist/lib/mapping/__tests__/schema/contract.d.ts.map +1 -0
  41. package/dist/lib/mapping/__tests__/schema/doctor.d.ts +19 -0
  42. package/dist/lib/mapping/__tests__/schema/doctor.d.ts.map +1 -0
  43. package/dist/lib/mapping/__tests__/schema/index.d.ts +3389 -0
  44. package/dist/lib/mapping/__tests__/schema/index.d.ts.map +1 -0
  45. package/dist/lib/mapping/__tests__/schema/nurse.d.ts +19 -0
  46. package/dist/lib/mapping/__tests__/schema/nurse.d.ts.map +1 -0
  47. package/dist/lib/mapping/__tests__/schema/person.d.ts +15 -0
  48. package/dist/lib/mapping/__tests__/schema/person.d.ts.map +1 -0
  49. package/dist/lib/mapping/__tests__/schema/personDictionaryExample.d.ts +75 -0
  50. package/dist/lib/mapping/__tests__/schema/personDictionaryExample.d.ts.map +1 -0
  51. package/dist/lib/mapping/__tests__/schema/personListExample.d.ts +61 -0
  52. package/dist/lib/mapping/__tests__/schema/personListExample.d.ts.map +1 -0
  53. package/dist/lib/mapping/__tests__/schema/personObjectExample.d.ts +61 -0
  54. package/dist/lib/mapping/__tests__/schema/personObjectExample.d.ts.map +1 -0
  55. package/dist/lib/mapping/__tests__/schema/personValueExample.d.ts +25 -0
  56. package/dist/lib/mapping/__tests__/schema/personValueExample.d.ts.map +1 -0
  57. package/dist/lib/mapping/__tests__/schema/x.d.ts +67 -0
  58. package/dist/lib/mapping/__tests__/schema/x.d.ts.map +1 -0
  59. package/dist/lib/mapping/__tests__/schema/x1.d.ts +73 -0
  60. package/dist/lib/mapping/__tests__/schema/x1.d.ts.map +1 -0
  61. package/dist/lib/mapping/__tests__/schema/x11.d.ts +80 -0
  62. package/dist/lib/mapping/__tests__/schema/x11.d.ts.map +1 -0
  63. package/dist/lib/mapping/__tests__/schema/x12.d.ts +80 -0
  64. package/dist/lib/mapping/__tests__/schema/x12.d.ts.map +1 -0
  65. package/dist/lib/mapping/__tests__/schema/x2.d.ts +67 -0
  66. package/dist/lib/mapping/__tests__/schema/x2.d.ts.map +1 -0
  67. package/dist/lib/mapping/__tests__/schema/x3.d.ts +77 -0
  68. package/dist/lib/mapping/__tests__/schema/x3.d.ts.map +1 -0
  69. package/dist/lib/mapping/__tests__/schema/xSubscription.d.ts +10 -0
  70. package/dist/lib/mapping/__tests__/schema/xSubscription.d.ts.map +1 -0
  71. package/dist/lib/mapping/__tests__/schema/y.d.ts +990 -0
  72. package/dist/lib/mapping/__tests__/schema/y.d.ts.map +1 -0
  73. package/dist/lib/mapping/__tests__/schema/y1.d.ts +1381 -0
  74. package/dist/lib/mapping/__tests__/schema/y1.d.ts.map +1 -0
  75. package/dist/lib/mapping/index.d.ts +4 -0
  76. package/dist/lib/mapping/index.d.ts.map +1 -0
  77. package/dist/lib/mapping/serializeBlueAnnotated.d.ts +3 -0
  78. package/dist/lib/mapping/serializeBlueAnnotated.d.ts.map +1 -0
  79. package/dist/lib/model/BigDecimalNumber.d.ts +9 -0
  80. package/dist/lib/model/BigDecimalNumber.d.ts.map +1 -0
  81. package/dist/lib/model/BigIntegerNumber.d.ts +9 -0
  82. package/dist/lib/model/BigIntegerNumber.d.ts.map +1 -0
  83. package/dist/lib/model/Node.d.ts +53 -0
  84. package/dist/lib/model/Node.d.ts.map +1 -0
  85. package/dist/lib/model/NodeDeserializer.d.ts +8 -0
  86. package/dist/lib/model/NodeDeserializer.d.ts.map +1 -0
  87. package/dist/lib/model/index.d.ts +5 -0
  88. package/dist/lib/model/index.d.ts.map +1 -0
  89. package/dist/lib/preprocess/BlueDirectivePreprocessor.d.ts +85 -0
  90. package/dist/lib/preprocess/BlueDirectivePreprocessor.d.ts.map +1 -0
  91. package/dist/lib/preprocess/Preprocessor.d.ts +68 -0
  92. package/dist/lib/preprocess/Preprocessor.d.ts.map +1 -0
  93. package/dist/lib/preprocess/index.d.ts +5 -0
  94. package/dist/lib/preprocess/index.d.ts.map +1 -0
  95. package/dist/lib/preprocess/interfaces.d.ts +24 -0
  96. package/dist/lib/preprocess/interfaces.d.ts.map +1 -0
  97. package/dist/lib/preprocess/processor/InferBasicTypesForUntypedValues.d.ts +20 -0
  98. package/dist/lib/preprocess/processor/InferBasicTypesForUntypedValues.d.ts.map +1 -0
  99. package/dist/lib/preprocess/processor/ReplaceInlineValuesForTypeAttributesWithImports.d.ts +23 -0
  100. package/dist/lib/preprocess/processor/ReplaceInlineValuesForTypeAttributesWithImports.d.ts.map +1 -0
  101. package/dist/lib/preprocess/processor/index.d.ts +3 -0
  102. package/dist/lib/preprocess/processor/index.d.ts.map +1 -0
  103. package/dist/lib/preprocess/utils/BlueIdsMappingGenerator.d.ts +53 -0
  104. package/dist/lib/preprocess/utils/BlueIdsMappingGenerator.d.ts.map +1 -0
  105. package/dist/lib/processor/BlueDocumentProcessor.d.ts +54 -0
  106. package/dist/lib/processor/BlueDocumentProcessor.d.ts.map +1 -0
  107. package/dist/lib/processor/context.d.ts +21 -0
  108. package/dist/lib/processor/context.d.ts.map +1 -0
  109. package/dist/lib/processor/processors/BaseChannelProcessor.d.ts +27 -0
  110. package/dist/lib/processor/processors/BaseChannelProcessor.d.ts.map +1 -0
  111. package/dist/lib/processor/processors/ChannelEventCheckpointProcessor.d.ts +13 -0
  112. package/dist/lib/processor/processors/ChannelEventCheckpointProcessor.d.ts.map +1 -0
  113. package/dist/lib/processor/processors/CompositeTimelineChannelProcessor.d.ts +9 -0
  114. package/dist/lib/processor/processors/CompositeTimelineChannelProcessor.d.ts.map +1 -0
  115. package/dist/lib/processor/processors/DocumentUpdateChannelProcessor.d.ts +9 -0
  116. package/dist/lib/processor/processors/DocumentUpdateChannelProcessor.d.ts.map +1 -0
  117. package/dist/lib/processor/processors/EmbeddedNodeChannelProcessor.d.ts +9 -0
  118. package/dist/lib/processor/processors/EmbeddedNodeChannelProcessor.d.ts.map +1 -0
  119. package/dist/lib/processor/processors/MyOSAgentChannelProcessor.d.ts +60 -0
  120. package/dist/lib/processor/processors/MyOSAgentChannelProcessor.d.ts.map +1 -0
  121. package/dist/lib/processor/processors/MyOSTimelineChannelProcessor.d.ts +9 -0
  122. package/dist/lib/processor/processors/MyOSTimelineChannelProcessor.d.ts.map +1 -0
  123. package/dist/lib/processor/processors/OperationProcessor.d.ts +11 -0
  124. package/dist/lib/processor/processors/OperationProcessor.d.ts.map +1 -0
  125. package/dist/lib/processor/processors/ProcessEmbeddedProcessor.d.ts +10 -0
  126. package/dist/lib/processor/processors/ProcessEmbeddedProcessor.d.ts.map +1 -0
  127. package/dist/lib/processor/processors/SequentialWorkflowOperationProcessor.d.ts +12 -0
  128. package/dist/lib/processor/processors/SequentialWorkflowOperationProcessor.d.ts.map +1 -0
  129. package/dist/lib/processor/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts +15 -0
  130. package/dist/lib/processor/processors/SequentialWorkflowProcessor/SequentialWorkflowProcessor.d.ts.map +1 -0
  131. package/dist/lib/processor/processors/SequentialWorkflowProcessor/index.d.ts +2 -0
  132. package/dist/lib/processor/processors/SequentialWorkflowProcessor/index.d.ts.map +1 -0
  133. package/dist/lib/processor/processors/SequentialWorkflowProcessor/steps/JavaScriptCodeExecutor.d.ts +8 -0
  134. package/dist/lib/processor/processors/SequentialWorkflowProcessor/steps/JavaScriptCodeExecutor.d.ts.map +1 -0
  135. package/dist/lib/processor/processors/SequentialWorkflowProcessor/steps/TriggerEventExecutor.d.ts +8 -0
  136. package/dist/lib/processor/processors/SequentialWorkflowProcessor/steps/TriggerEventExecutor.d.ts.map +1 -0
  137. package/dist/lib/processor/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts +12 -0
  138. package/dist/lib/processor/processors/SequentialWorkflowProcessor/steps/UpdateDocumentExecutor.d.ts.map +1 -0
  139. package/dist/lib/processor/processors/SequentialWorkflowProcessor/types.d.ts +7 -0
  140. package/dist/lib/processor/processors/SequentialWorkflowProcessor/types.d.ts.map +1 -0
  141. package/dist/lib/processor/processors/SequentialWorkflowProcessor/utils/BindingsFactory.d.ts +12 -0
  142. package/dist/lib/processor/processors/SequentialWorkflowProcessor/utils/BindingsFactory.d.ts.map +1 -0
  143. package/dist/lib/processor/processors/SequentialWorkflowProcessor/utils/ExpressionEvaluator.d.ts +59 -0
  144. package/dist/lib/processor/processors/SequentialWorkflowProcessor/utils/ExpressionEvaluator.d.ts.map +1 -0
  145. package/dist/lib/processor/processors/TimelineChannelProcessor.d.ts +9 -0
  146. package/dist/lib/processor/processors/TimelineChannelProcessor.d.ts.map +1 -0
  147. package/dist/lib/processor/processors/index.d.ts +12 -0
  148. package/dist/lib/processor/processors/index.d.ts.map +1 -0
  149. package/dist/lib/processor/queue/TaskKey.d.ts +22 -0
  150. package/dist/lib/processor/queue/TaskKey.d.ts.map +1 -0
  151. package/dist/lib/processor/queue/TaskQueue.d.ts +31 -0
  152. package/dist/lib/processor/queue/TaskQueue.d.ts.map +1 -0
  153. package/dist/lib/processor/registry/ContractRegistry.d.ts +47 -0
  154. package/dist/lib/processor/registry/ContractRegistry.d.ts.map +1 -0
  155. package/dist/lib/processor/routing/EventRouter.d.ts +51 -0
  156. package/dist/lib/processor/routing/EventRouter.d.ts.map +1 -0
  157. package/dist/lib/processor/types.d.ts +112 -0
  158. package/dist/lib/processor/types.d.ts.map +1 -0
  159. package/dist/lib/processor/utils/CheckpointCache.d.ts +9 -0
  160. package/dist/lib/processor/utils/CheckpointCache.d.ts.map +1 -0
  161. package/dist/lib/processor/utils/EventTraceManager.d.ts +46 -0
  162. package/dist/lib/processor/utils/EventTraceManager.d.ts.map +1 -0
  163. package/dist/lib/processor/utils/checkpoint.d.ts +3 -0
  164. package/dist/lib/processor/utils/checkpoint.d.ts.map +1 -0
  165. package/dist/lib/processor/utils/document.d.ts +19 -0
  166. package/dist/lib/processor/utils/document.d.ts.map +1 -0
  167. package/dist/lib/processor/utils/exceptions.d.ts +28 -0
  168. package/dist/lib/processor/utils/exceptions.d.ts.map +1 -0
  169. package/dist/lib/processor/utils/fetchText.d.ts +2 -0
  170. package/dist/lib/processor/utils/fetchText.d.ts.map +1 -0
  171. package/dist/lib/processor/utils/logPatchError.d.ts +3 -0
  172. package/dist/lib/processor/utils/logPatchError.d.ts.map +1 -0
  173. package/dist/lib/processor/utils/path.d.ts +2 -0
  174. package/dist/lib/processor/utils/path.d.ts.map +1 -0
  175. package/dist/lib/processor/utils/typeGuard.d.ts +5 -0
  176. package/dist/lib/processor/utils/typeGuard.d.ts.map +1 -0
  177. package/dist/lib/provider/BaseContentNodeProvider.d.ts +9 -0
  178. package/dist/lib/provider/BaseContentNodeProvider.d.ts.map +1 -0
  179. package/dist/lib/provider/BootstrapProvider.d.ts +13 -0
  180. package/dist/lib/provider/BootstrapProvider.d.ts.map +1 -0
  181. package/dist/lib/provider/InMemoryNodeProvider.d.ts +13 -0
  182. package/dist/lib/provider/InMemoryNodeProvider.d.ts.map +1 -0
  183. package/dist/lib/provider/SequentialNodeProvider.d.ts +14 -0
  184. package/dist/lib/provider/SequentialNodeProvider.d.ts.map +1 -0
  185. package/dist/lib/provider/UrlContentFetcher.d.ts +65 -0
  186. package/dist/lib/provider/UrlContentFetcher.d.ts.map +1 -0
  187. package/dist/lib/provider/index.d.ts +6 -0
  188. package/dist/lib/provider/index.d.ts.map +1 -0
  189. package/dist/lib/utils/Base58Sha256Provider.d.ts +11 -0
  190. package/dist/lib/utils/Base58Sha256Provider.d.ts.map +1 -0
  191. package/dist/lib/utils/BlueIdCalculator.d.ts +22 -0
  192. package/dist/lib/utils/BlueIdCalculator.d.ts.map +1 -0
  193. package/dist/lib/utils/BlueIdResolver.d.ts +9 -0
  194. package/dist/lib/utils/BlueIdResolver.d.ts.map +1 -0
  195. package/dist/lib/utils/BlueIdToCid.d.ts +4 -0
  196. package/dist/lib/utils/BlueIdToCid.d.ts.map +1 -0
  197. package/dist/lib/utils/BlueIds.d.ts +7 -0
  198. package/dist/lib/utils/BlueIds.d.ts.map +1 -0
  199. package/dist/lib/utils/CidToBlueId.d.ts +4 -0
  200. package/dist/lib/utils/CidToBlueId.d.ts.map +1 -0
  201. package/dist/lib/utils/CryptoEnvironment.d.ts +13 -0
  202. package/dist/lib/utils/CryptoEnvironment.d.ts.map +1 -0
  203. package/dist/lib/utils/JsonCanonicalizer.d.ts +4 -0
  204. package/dist/lib/utils/JsonCanonicalizer.d.ts.map +1 -0
  205. package/dist/lib/utils/NodeExtender.d.ts +31 -0
  206. package/dist/lib/utils/NodeExtender.d.ts.map +1 -0
  207. package/dist/lib/utils/NodePatch/NodePatch.d.ts +28 -0
  208. package/dist/lib/utils/NodePatch/NodePatch.d.ts.map +1 -0
  209. package/dist/lib/utils/NodePatch/index.d.ts +2 -0
  210. package/dist/lib/utils/NodePatch/index.d.ts.map +1 -0
  211. package/dist/lib/utils/NodePatch/patch-operations.d.ts +8 -0
  212. package/dist/lib/utils/NodePatch/patch-operations.d.ts.map +1 -0
  213. package/dist/lib/utils/NodePatch/patch-utils.d.ts +34 -0
  214. package/dist/lib/utils/NodePatch/patch-utils.d.ts.map +1 -0
  215. package/dist/lib/utils/NodePathAccessor.d.ts +8 -0
  216. package/dist/lib/utils/NodePathAccessor.d.ts.map +1 -0
  217. package/dist/lib/utils/NodeProviderWrapper.d.ts +13 -0
  218. package/dist/lib/utils/NodeProviderWrapper.d.ts.map +1 -0
  219. package/dist/lib/utils/NodeToMapListOrValue.d.ts +24 -0
  220. package/dist/lib/utils/NodeToMapListOrValue.d.ts.map +1 -0
  221. package/dist/lib/utils/NodeTransformer.d.ts +14 -0
  222. package/dist/lib/utils/NodeTransformer.d.ts.map +1 -0
  223. package/dist/lib/utils/Properties.d.ts +31 -0
  224. package/dist/lib/utils/Properties.d.ts.map +1 -0
  225. package/dist/lib/utils/TinyQueue.d.ts +12 -0
  226. package/dist/lib/utils/TinyQueue.d.ts.map +1 -0
  227. package/dist/lib/utils/TypeSchema.d.ts +6 -0
  228. package/dist/lib/utils/TypeSchema.d.ts.map +1 -0
  229. package/dist/lib/utils/TypeSchemaResolver.d.ts +11 -0
  230. package/dist/lib/utils/TypeSchemaResolver.d.ts.map +1 -0
  231. package/dist/lib/utils/__tests__/calculateCID.d.ts +3 -0
  232. package/dist/lib/utils/__tests__/calculateCID.d.ts.map +1 -0
  233. package/dist/lib/utils/index.d.ts +10 -0
  234. package/dist/lib/utils/index.d.ts.map +1 -0
  235. package/dist/lib/utils/limits/Limits.d.ts +31 -0
  236. package/dist/lib/utils/limits/Limits.d.ts.map +1 -0
  237. package/dist/lib/utils/limits/NoLimits.d.ts +25 -0
  238. package/dist/lib/utils/limits/NoLimits.d.ts.map +1 -0
  239. package/dist/lib/utils/limits/PathLimits.d.ts +100 -0
  240. package/dist/lib/utils/limits/PathLimits.d.ts.map +1 -0
  241. package/dist/lib/utils/limits/index.d.ts +9 -0
  242. package/dist/lib/utils/limits/index.d.ts.map +1 -0
  243. package/dist/repo/core/blue-ids/index.d.ts +21 -0
  244. package/dist/repo/core/blue-ids/index.d.ts.map +1 -0
  245. package/dist/repo/core/index.d.ts +191 -0
  246. package/dist/repo/core/index.d.ts.map +1 -0
  247. package/dist/repo/core/schema/Channel.d.ts +13 -0
  248. package/dist/repo/core/schema/Channel.d.ts.map +1 -0
  249. package/dist/repo/core/schema/CompositeTimelineChannel.d.ts +17 -0
  250. package/dist/repo/core/schema/CompositeTimelineChannel.d.ts.map +1 -0
  251. package/dist/repo/core/schema/DocumentUpdateChannel.d.ts +17 -0
  252. package/dist/repo/core/schema/DocumentUpdateChannel.d.ts.map +1 -0
  253. package/dist/repo/core/schema/EmbeddedNodeChannel.d.ts +17 -0
  254. package/dist/repo/core/schema/EmbeddedNodeChannel.d.ts.map +1 -0
  255. package/dist/repo/core/schema/JavaScriptCode.d.ts +10 -0
  256. package/dist/repo/core/schema/JavaScriptCode.d.ts.map +1 -0
  257. package/dist/repo/core/schema/JsonPatchEntry.d.ts +22 -0
  258. package/dist/repo/core/schema/JsonPatchEntry.d.ts.map +1 -0
  259. package/dist/repo/core/schema/Operation.d.ts +16 -0
  260. package/dist/repo/core/schema/Operation.d.ts.map +1 -0
  261. package/dist/repo/core/schema/OperationRequest.d.ts +29 -0
  262. package/dist/repo/core/schema/OperationRequest.d.ts.map +1 -0
  263. package/dist/repo/core/schema/ProcessEmbedded.d.ts +10 -0
  264. package/dist/repo/core/schema/ProcessEmbedded.d.ts.map +1 -0
  265. package/dist/repo/core/schema/SequentialWorkflow.d.ts +13 -0
  266. package/dist/repo/core/schema/SequentialWorkflow.d.ts.map +1 -0
  267. package/dist/repo/core/schema/SequentialWorkflowOperation.d.ts +15 -0
  268. package/dist/repo/core/schema/SequentialWorkflowOperation.d.ts.map +1 -0
  269. package/dist/repo/core/schema/SequentialWorkflowStep.d.ts +13 -0
  270. package/dist/repo/core/schema/SequentialWorkflowStep.d.ts.map +1 -0
  271. package/dist/repo/core/schema/TimelineChannel.d.ts +17 -0
  272. package/dist/repo/core/schema/TimelineChannel.d.ts.map +1 -0
  273. package/dist/repo/core/schema/TimelineEntry.d.ts +25 -0
  274. package/dist/repo/core/schema/TimelineEntry.d.ts.map +1 -0
  275. package/dist/repo/core/schema/TriggerEvent.d.ts +10 -0
  276. package/dist/repo/core/schema/TriggerEvent.d.ts.map +1 -0
  277. package/dist/repo/core/schema/UpdateDocument.d.ts +40 -0
  278. package/dist/repo/core/schema/UpdateDocument.d.ts.map +1 -0
  279. package/dist/repo/core/schema/index.d.ts +14 -0
  280. package/dist/repo/core/schema/index.d.ts.map +1 -0
  281. package/dist/repo/myos/blue-ids/index.d.ts +8 -0
  282. package/dist/repo/myos/blue-ids/index.d.ts.map +1 -0
  283. package/dist/repo/myos/index.d.ts +99 -0
  284. package/dist/repo/myos/index.d.ts.map +1 -0
  285. package/dist/repo/myos/schema/MyOSAgent.d.ts +10 -0
  286. package/dist/repo/myos/schema/MyOSAgent.d.ts.map +1 -0
  287. package/dist/repo/myos/schema/MyOSAgentChannel.d.ts +30 -0
  288. package/dist/repo/myos/schema/MyOSAgentChannel.d.ts.map +1 -0
  289. package/dist/repo/myos/schema/MyOSAgentEvent.d.ts +19 -0
  290. package/dist/repo/myos/schema/MyOSAgentEvent.d.ts.map +1 -0
  291. package/dist/repo/myos/schema/MyOSTimelineChannel.d.ts +24 -0
  292. package/dist/repo/myos/schema/MyOSTimelineChannel.d.ts.map +1 -0
  293. package/dist/repo/myos/schema/MyOSTimelineEntry.d.ts +32 -0
  294. package/dist/repo/myos/schema/MyOSTimelineEntry.d.ts.map +1 -0
  295. package/dist/repo/myos/schema/index.d.ts +6 -0
  296. package/dist/repo/myos/schema/index.d.ts.map +1 -0
  297. package/dist/schema/annotations/annotations.d.ts +10 -0
  298. package/dist/schema/annotations/annotations.d.ts.map +1 -0
  299. package/dist/schema/annotations/blueDescription.d.ts +5 -0
  300. package/dist/schema/annotations/blueDescription.d.ts.map +1 -0
  301. package/dist/schema/annotations/blueId.d.ts +5 -0
  302. package/dist/schema/annotations/blueId.d.ts.map +1 -0
  303. package/dist/schema/annotations/blueName.d.ts +5 -0
  304. package/dist/schema/annotations/blueName.d.ts.map +1 -0
  305. package/dist/schema/annotations/blueNode.d.ts +7 -0
  306. package/dist/schema/annotations/blueNode.d.ts.map +1 -0
  307. package/dist/schema/annotations/extends.d.ts +8 -0
  308. package/dist/schema/annotations/extends.d.ts.map +1 -0
  309. package/dist/schema/annotations/index.d.ts +7 -0
  310. package/dist/schema/annotations/index.d.ts.map +1 -0
  311. package/dist/schema/annotations/typeBlueId/index.d.ts +2 -0
  312. package/dist/schema/annotations/typeBlueId/index.d.ts.map +1 -0
  313. package/dist/schema/annotations/typeBlueId/proxySchema.d.ts +3 -0
  314. package/dist/schema/annotations/typeBlueId/proxySchema.d.ts.map +1 -0
  315. package/dist/schema/annotations/typeBlueId/typeBlueId.d.ts +19 -0
  316. package/dist/schema/annotations/typeBlueId/typeBlueId.d.ts.map +1 -0
  317. package/dist/schema/blueId.d.ts +4 -0
  318. package/dist/schema/blueId.d.ts.map +1 -0
  319. package/dist/schema/blueObjectPredicates.d.ts +11 -0
  320. package/dist/schema/blueObjectPredicates.d.ts.map +1 -0
  321. package/dist/schema/generated/blueObject.d.ts +37 -0
  322. package/dist/schema/generated/blueObject.d.ts.map +1 -0
  323. package/dist/schema/generated/blueObject.zod.d.ts +100 -0
  324. package/dist/schema/generated/blueObject.zod.d.ts.map +1 -0
  325. package/dist/schema/generated/index.d.ts +3 -0
  326. package/dist/schema/generated/index.d.ts.map +1 -0
  327. package/dist/schema/index.d.ts +5 -0
  328. package/dist/schema/index.d.ts.map +1 -0
  329. package/dist/schema/jsonBlue.d.ts +18 -0
  330. package/dist/schema/jsonBlue.d.ts.map +1 -0
  331. package/dist/types/index.d.ts +2 -0
  332. package/dist/types/index.d.ts.map +1 -0
  333. package/dist/types/zod.d.ts +5 -0
  334. package/dist/types/zod.d.ts.map +1 -0
  335. package/dist/utils/blueId/calculateBlueId.d.ts +15 -0
  336. package/dist/utils/blueId/calculateBlueId.d.ts.map +1 -0
  337. package/dist/utils/blueId/index.d.ts +2 -0
  338. package/dist/utils/blueId/index.d.ts.map +1 -0
  339. package/dist/utils/blueObject/enrichWithBlueId.d.ts +11 -0
  340. package/dist/utils/blueObject/enrichWithBlueId.d.ts.map +1 -0
  341. package/dist/utils/blueObject/getBlueObjectProperties.d.ts +6 -0
  342. package/dist/utils/blueObject/getBlueObjectProperties.d.ts.map +1 -0
  343. package/dist/utils/blueObject/getBlueObjectTypeLabel.d.ts +6 -0
  344. package/dist/utils/blueObject/getBlueObjectTypeLabel.d.ts.map +1 -0
  345. package/dist/utils/blueObject/getters.d.ts +7 -0
  346. package/dist/utils/blueObject/getters.d.ts.map +1 -0
  347. package/dist/utils/blueObject/index.d.ts +8 -0
  348. package/dist/utils/blueObject/index.d.ts.map +1 -0
  349. package/dist/utils/blueObject/isBlueObjectResolved.d.ts +3 -0
  350. package/dist/utils/blueObject/isBlueObjectResolved.d.ts.map +1 -0
  351. package/dist/utils/blueObject/normalizeToBlueObject.d.ts +10 -0
  352. package/dist/utils/blueObject/normalizeToBlueObject.d.ts.map +1 -0
  353. package/dist/utils/blueObject/resolveBlueObjectItems.d.ts +24 -0
  354. package/dist/utils/blueObject/resolveBlueObjectItems.d.ts.map +1 -0
  355. package/dist/utils/bs58/bs58.d.ts +3 -0
  356. package/dist/utils/bs58/bs58.d.ts.map +1 -0
  357. package/dist/utils/bs58/index.d.ts +2 -0
  358. package/dist/utils/bs58/index.d.ts.map +1 -0
  359. package/dist/utils/deepFreeze.d.ts +8 -0
  360. package/dist/utils/deepFreeze.d.ts.map +1 -0
  361. package/dist/utils/index.d.ts +5 -0
  362. package/dist/utils/index.d.ts.map +1 -0
  363. package/dist/utils/typeGuards/index.d.ts +2 -0
  364. package/dist/utils/typeGuards/index.d.ts.map +1 -0
  365. package/dist/utils/typeGuards/isBigNumber.d.ts +6 -0
  366. package/dist/utils/typeGuards/isBigNumber.d.ts.map +1 -0
  367. package/dist/utils/url.d.ts +7 -0
  368. package/dist/utils/url.d.ts.map +1 -0
  369. package/dist/utils/yamlBlue/dump.d.ts +5 -0
  370. package/dist/utils/yamlBlue/dump.d.ts.map +1 -0
  371. package/dist/utils/yamlBlue/index.d.ts +3 -0
  372. package/dist/utils/yamlBlue/index.d.ts.map +1 -0
  373. package/dist/utils/yamlBlue/parse.d.ts +9 -0
  374. package/dist/utils/yamlBlue/parse.d.ts.map +1 -0
  375. package/dist/utils/yamlBlue/schema.d.ts +3 -0
  376. package/dist/utils/yamlBlue/schema.d.ts.map +1 -0
  377. package/dist/utils/yamlBlue/type/float.d.ts +3 -0
  378. package/dist/utils/yamlBlue/type/float.d.ts.map +1 -0
  379. package/dist/utils/yamlBlue/type/int.d.ts +3 -0
  380. package/dist/utils/yamlBlue/type/int.d.ts.map +1 -0
  381. package/package.json +52 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,4476 @@
1
+ var yn = Object.defineProperty;
2
+ var mn = (n, e, t) => e in n ? yn(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var l = (n, e, t) => mn(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { isNullable as D, isNonNullable as y, jsonPrimitiveSchema as gn, isReadonlyArray as ce, isJsonPrimitive as st, isPreciseNumberString as Vt, deepContains as wn } from "@blue-labs/shared-utils";
5
+ import { z as u, ZodString as Q, ZodEnum as Tn, ZodNativeEnum as bn, ZodNumber as G, ZodBoolean as Ee, ZodBigInt as Ie, ZodAny as Ft, ZodObject as Je, ZodRecord as Ke, ZodMap as Mt, ZodUnknown as jt, ZodIntersection as En, ZodUnion as In, ZodOptional as Rt, ZodNullable as $t, ZodReadonly as Ut, ZodBranded as Zt, ZodEffects as Pe, ZodLazy as Be } from "zod";
6
+ import le from "bs58";
7
+ import Z from "big.js";
8
+ import { isObject as Ye, isArray as Ve, isString as ot, omit as qt, pascal as vn, map as Pn } from "radash";
9
+ import { sha256 as Bn } from "js-sha256";
10
+ import mt from "crypto";
11
+ import Cn from "base32.js";
12
+ import z from "js-yaml";
13
+ class Sn {
14
+ static get(e, t, r, s = !0) {
15
+ if (D(t) || !t.startsWith("/"))
16
+ throw new Error(`Invalid path: ${t}`);
17
+ if (t === "/") {
18
+ const i = e.getValue();
19
+ return s && i !== void 0 ? i : e;
20
+ }
21
+ const o = t.substring(1).split("/");
22
+ return this.getRecursive(
23
+ e,
24
+ o,
25
+ 0,
26
+ r,
27
+ s
28
+ );
29
+ }
30
+ static getRecursive(e, t, r, s, o) {
31
+ if (r === t.length - 1 && !o)
32
+ return this.getNodeForSegment(
33
+ e,
34
+ t[r],
35
+ s,
36
+ !1
37
+ );
38
+ if (r === t.length) {
39
+ const c = e.getValue();
40
+ return o && c !== void 0 ? c : e;
41
+ }
42
+ const i = t[r], a = this.getNodeForSegment(
43
+ e,
44
+ i,
45
+ s,
46
+ !0
47
+ );
48
+ if (a)
49
+ return this.getRecursive(
50
+ a,
51
+ t,
52
+ r + 1,
53
+ s,
54
+ o
55
+ );
56
+ }
57
+ static getNodeForSegment(e, t, r, s) {
58
+ let o;
59
+ const i = e.getProperties();
60
+ if (i && t in i)
61
+ o = i[t];
62
+ else
63
+ switch (t) {
64
+ case "name": {
65
+ const a = e.getName();
66
+ o = y(a) ? new d().setValue(a) : new d();
67
+ break;
68
+ }
69
+ case "description": {
70
+ const a = e.getDescription();
71
+ o = y(a) ? new d().setValue(a) : new d();
72
+ break;
73
+ }
74
+ case "type":
75
+ o = e.getType() ?? new d();
76
+ break;
77
+ case "itemType":
78
+ o = e.getItemType() ?? new d();
79
+ break;
80
+ case "keyType":
81
+ o = e.getKeyType() ?? new d();
82
+ break;
83
+ case "valueType":
84
+ o = e.getValueType() ?? new d();
85
+ break;
86
+ case "value": {
87
+ const a = e.getValue();
88
+ o = new d().setValue(a ?? null);
89
+ break;
90
+ }
91
+ case "blueId": {
92
+ const a = e.getBlueId();
93
+ o = y(a) ? new d().setValue(a) : new d();
94
+ break;
95
+ }
96
+ case "blue":
97
+ o = e.getBlue();
98
+ break;
99
+ case "items": {
100
+ const a = e.getItems();
101
+ o = new d().setItems(a);
102
+ break;
103
+ }
104
+ case "properties": {
105
+ const a = e.getProperties();
106
+ o = new d().setProperties(a);
107
+ break;
108
+ }
109
+ case "contracts": {
110
+ const a = e.getContracts();
111
+ o = new d().setContracts(a);
112
+ break;
113
+ }
114
+ default: {
115
+ if (/^\d+$/.test(t)) {
116
+ const a = parseInt(t, 10), c = e.getItems();
117
+ c && a >= 0 && a < c.length ? o = c[a] : o = void 0;
118
+ } else
119
+ o = void 0;
120
+ break;
121
+ }
122
+ }
123
+ if (o)
124
+ return s && r ? this.link(o, r) : o;
125
+ }
126
+ static link(e, t) {
127
+ const r = t(e);
128
+ return y(r) ? r : e;
129
+ }
130
+ }
131
+ class N extends Z {
132
+ constructor(e) {
133
+ super(e);
134
+ }
135
+ }
136
+ class k extends Z {
137
+ constructor(e) {
138
+ super(e);
139
+ }
140
+ }
141
+ const X = "name", ee = "description", Ce = "type", it = "itemType", at = "keyType", ct = "valueType", Fe = "value", lt = "items", Y = "blueId", ut = "blue", Me = "contracts", Nn = [
142
+ X,
143
+ ee,
144
+ Ce,
145
+ it,
146
+ at,
147
+ ct,
148
+ Fe,
149
+ lt,
150
+ Y,
151
+ ut,
152
+ Me
153
+ ], An = "Text", On = "Double", kn = "Integer", xn = "Boolean", Dn = "List", Vn = "Dictionary", Fn = [
154
+ An,
155
+ On,
156
+ kn,
157
+ xn
158
+ ], Lt = [...Fn, Dn, Vn], ye = "F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP", me = "68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L", ge = "DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8", we = "EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo", Mn = "G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB", jn = "294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA", Rn = [
159
+ ye,
160
+ me,
161
+ ge,
162
+ we
163
+ ], ht = [
164
+ ...Rn,
165
+ Mn,
166
+ jn
167
+ ];
168
+ Object.fromEntries(
169
+ Lt.map((n, e) => [n, ht[e]])
170
+ );
171
+ Object.fromEntries(
172
+ ht.map((n, e) => [n, Lt[e]])
173
+ );
174
+ const F = class F {
175
+ constructor(e) {
176
+ l(this, "name");
177
+ l(this, "description");
178
+ l(this, "type");
179
+ l(this, "itemType");
180
+ l(this, "keyType");
181
+ l(this, "valueType");
182
+ l(this, "value");
183
+ l(this, "items");
184
+ l(this, "properties");
185
+ l(this, "contracts");
186
+ l(this, "blueId");
187
+ l(this, "blue");
188
+ l(this, "inlineValue", !1);
189
+ this.name = e;
190
+ }
191
+ getName() {
192
+ return this.name;
193
+ }
194
+ setName(e) {
195
+ return this.name = e, this;
196
+ }
197
+ getDescription() {
198
+ return this.description;
199
+ }
200
+ setDescription(e) {
201
+ return this.description = e, this;
202
+ }
203
+ getType() {
204
+ return this.type;
205
+ }
206
+ setType(e) {
207
+ return typeof e == "string" ? this.type = new F().setValue(e).setInlineValue(!0) : this.type = e, this;
208
+ }
209
+ getItemType() {
210
+ return this.itemType;
211
+ }
212
+ setItemType(e) {
213
+ return typeof e == "string" ? this.itemType = new F().setValue(e).setInlineValue(!0) : this.itemType = e, this;
214
+ }
215
+ getKeyType() {
216
+ return this.keyType;
217
+ }
218
+ setKeyType(e) {
219
+ return typeof e == "string" ? this.keyType = new F().setValue(e).setInlineValue(!0) : this.keyType = e, this;
220
+ }
221
+ getValueType() {
222
+ return this.valueType;
223
+ }
224
+ setValueType(e) {
225
+ return typeof e == "string" ? this.valueType = new F().setValue(e).setInlineValue(!0) : this.valueType = e, this;
226
+ }
227
+ getValue() {
228
+ var t;
229
+ const e = (t = this.type) == null ? void 0 : t.getBlueId();
230
+ if (y(e) && y(this.value)) {
231
+ if (e === ge && typeof this.value == "string")
232
+ return new N(this.value);
233
+ if (e === me && typeof this.value == "string") {
234
+ const r = new k(this.value), s = parseFloat(r.toString());
235
+ return new k(s.toString());
236
+ } else if (e === we && typeof this.value == "string")
237
+ return this.value.toLowerCase() === "true";
238
+ }
239
+ return this.value;
240
+ }
241
+ setValue(e) {
242
+ return typeof e == "number" ? e % 1 === 0 ? this.value = new N(e.toString()) : this.value = new k(e.toString()) : this.value = e, this;
243
+ }
244
+ getItems() {
245
+ return this.items;
246
+ }
247
+ setItems(e) {
248
+ return this.items = e, this;
249
+ }
250
+ addItems(...e) {
251
+ return this.items || (this.items = []), this.items.push(...e), this;
252
+ }
253
+ getProperties() {
254
+ return this.properties;
255
+ }
256
+ setProperties(e) {
257
+ return this.properties = e, this;
258
+ }
259
+ addProperty(e, t) {
260
+ return this.properties || (this.properties = {}), this.properties[e] = t, this;
261
+ }
262
+ getContracts() {
263
+ return this.contracts;
264
+ }
265
+ setContracts(e) {
266
+ return this.contracts = e, this;
267
+ }
268
+ addContract(e, t) {
269
+ return this.contracts || (this.contracts = {}), this.contracts[e] = t, this;
270
+ }
271
+ getBlueId() {
272
+ return this.blueId;
273
+ }
274
+ setBlueId(e) {
275
+ return this.blueId = e, this;
276
+ }
277
+ getBlue() {
278
+ return this.blue;
279
+ }
280
+ setBlue(e) {
281
+ return this.blue = e, this;
282
+ }
283
+ isInlineValue() {
284
+ return this.inlineValue;
285
+ }
286
+ setInlineValue(e) {
287
+ return this.inlineValue = e, this;
288
+ }
289
+ get(e, t) {
290
+ return Sn.get(this, e, t);
291
+ }
292
+ clone() {
293
+ var t, r, s, o, i, a;
294
+ const e = new F(this.name);
295
+ return e.description = this.description, e.type = (t = this.type) == null ? void 0 : t.clone(), e.itemType = (r = this.itemType) == null ? void 0 : r.clone(), e.keyType = (s = this.keyType) == null ? void 0 : s.clone(), e.valueType = (o = this.valueType) == null ? void 0 : o.clone(), e.value = this.value, e.items = (i = this.items) == null ? void 0 : i.map((c) => c.clone()), this.properties && (e.properties = Object.fromEntries(
296
+ Object.entries(this.properties).map(([c, h]) => [c, h.clone()])
297
+ )), this.contracts && (e.contracts = Object.fromEntries(
298
+ Object.entries(this.contracts).map(([c, h]) => [c, h.clone()])
299
+ )), e.blueId = this.blueId, e.blue = (a = this.blue) == null ? void 0 : a.clone(), e.inlineValue = this.inlineValue, e;
300
+ }
301
+ toString() {
302
+ return `BlueNode{name='${this.name}', description='${this.description}', type=${this.type}, itemType=${this.itemType}, keyType=${this.keyType}, valueType=${this.valueType}, value=${this.value}, items=${this.items}, properties=${this.properties}, contracts=${this.contracts}, blueId='${this.blueId}', blue=${this.blue}, inlineValue=${this.inlineValue}}`;
303
+ }
304
+ };
305
+ l(F, "INTEGER", new F("Integer"));
306
+ let d = F;
307
+ class K {
308
+ static isPotentialBlueId(e) {
309
+ if (!e || e.length === 0 || !this.BLUE_ID_PATTERN.test(e))
310
+ return !1;
311
+ const t = e.split("#"), r = t[0], s = r.length;
312
+ if (s < this.MIN_BLUE_ID_LENGTH || s > this.MAX_BLUE_ID_LENGTH)
313
+ return !1;
314
+ try {
315
+ if (le.decode(r).length !== 32)
316
+ return !1;
317
+ } catch {
318
+ return !1;
319
+ }
320
+ if (t.length > 1)
321
+ try {
322
+ if (Number(t[1]) < 0)
323
+ return !1;
324
+ } catch {
325
+ return !1;
326
+ }
327
+ return !0;
328
+ }
329
+ }
330
+ l(K, "MIN_BLUE_ID_LENGTH", 41), l(K, "MAX_BLUE_ID_LENGTH", 45), l(K, "BLUE_ID_PATTERN", /^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/);
331
+ const zs = u.string().max(K.MAX_BLUE_ID_LENGTH, {
332
+ message: "Blue Id has a maximum length of 45 characters"
333
+ }).min(K.MIN_BLUE_ID_LENGTH, {
334
+ message: "Blue Id has a minimum length of 41 characters"
335
+ }).refine(
336
+ (n) => {
337
+ try {
338
+ return le.decode(n), !0;
339
+ } catch {
340
+ return !1;
341
+ }
342
+ },
343
+ {
344
+ message: "Blue Id must be a valid Base58 string"
345
+ }
346
+ ), ue = u.lazy(
347
+ () => u.record(u.unknown()).and(
348
+ u.object({
349
+ blueId: u.string().optional(),
350
+ name: u.string().optional(),
351
+ description: u.string().optional(),
352
+ type: ue.optional(),
353
+ value: u.union([u.string(), u.number(), u.boolean()]).optional().nullable(),
354
+ items: u.array(ue).optional()
355
+ })
356
+ )
357
+ ), je = u.object({
358
+ blueId: u.string().optional(),
359
+ name: u.string().optional(),
360
+ description: u.string().optional(),
361
+ type: ue.optional()
362
+ }), Hs = je.extend({
363
+ value: u.string().optional()
364
+ }), Qs = je.extend({
365
+ value: u.number().optional()
366
+ }), Gs = je.extend({
367
+ value: u.boolean().optional()
368
+ }), Xs = je.extend({
369
+ items: u.array(u.string()).optional()
370
+ }), eo = (n) => ue.safeParse(n).success, $n = (n) => y(n) && "blueId" in n && y(n.blueId), to = (n) => y(n) && "name" in n && y(n.name), Un = (n) => y(n) && "items" in n && y(n.items), Zn = (n) => y(n) && "type" in n && y(n.type), qn = (n) => y(n) && "value" in n && y(n.value), no = (n, e) => n.required({ type: !0 }).safeParse(e).success, A = (n) => n instanceof Z, he = (n) => A(n) && n instanceof N, Ln = (n) => A(n) && n instanceof k, _n = u.lazy(
371
+ () => u.record(Se)
372
+ ), Wn = u.lazy(
373
+ () => u.union([
374
+ u.array(Se),
375
+ u.array(Se).readonly()
376
+ ])
377
+ ), Se = u.lazy(
378
+ () => u.union([
379
+ gn,
380
+ _n,
381
+ Wn,
382
+ u.instanceof(Z)
383
+ ])
384
+ ), _t = (n) => Ye(n) && !Ve(n) && !ce(n) && !A(n), Wt = (n) => Ve(n) || ce(n), ro = (n) => Wt(n) || _t(n) || A(n) || st(n);
385
+ class T {
386
+ static deserialize(e) {
387
+ return T.handleNode(e);
388
+ }
389
+ static handleNode(e) {
390
+ if (e === void 0)
391
+ throw new Error(
392
+ "This is not a valid JSON-like value. Found 'undefined' as a value."
393
+ );
394
+ if (_t(e)) {
395
+ const t = new d(), r = {}, s = {};
396
+ return Object.entries(e).forEach(([o, i]) => {
397
+ switch (o) {
398
+ case X:
399
+ if (i == null)
400
+ t.setName(void 0);
401
+ else {
402
+ if (typeof i != "string")
403
+ throw new Error(`The ${X} field must be a string.`);
404
+ t.setName(i);
405
+ }
406
+ break;
407
+ case ee:
408
+ if (i == null)
409
+ t.setDescription(void 0);
410
+ else {
411
+ if (typeof i != "string")
412
+ throw new Error(
413
+ `The ${ee} field must be a string.`
414
+ );
415
+ t.setDescription(i);
416
+ }
417
+ break;
418
+ case Ce:
419
+ t.setType(T.handleNode(i));
420
+ break;
421
+ case it:
422
+ t.setItemType(T.handleNode(i));
423
+ break;
424
+ case at:
425
+ t.setKeyType(T.handleNode(i));
426
+ break;
427
+ case ct:
428
+ t.setValueType(T.handleNode(i));
429
+ break;
430
+ case Fe:
431
+ t.setValue(T.handleValue(i));
432
+ break;
433
+ case Y:
434
+ if (typeof i != "string")
435
+ throw new Error(`The ${Y} field must be a string.`);
436
+ t.setBlueId(i);
437
+ break;
438
+ case lt:
439
+ t.setItems(T.handleArray(i));
440
+ break;
441
+ case ut:
442
+ t.setBlue(T.handleNode(i));
443
+ break;
444
+ case Me:
445
+ Ye(i) && !Ve(i) && !ce(i) && Object.entries(i).forEach(([a, c]) => {
446
+ s[a] = T.handleNode(c);
447
+ });
448
+ break;
449
+ default:
450
+ r[o] = T.handleNode(i);
451
+ break;
452
+ }
453
+ }), Object.keys(r).length > 0 && t.setProperties(r), Object.keys(s).length > 0 && t.setContracts(s), t;
454
+ } else {
455
+ if (Wt(e))
456
+ return new d().setItems(T.handleArray(e));
457
+ {
458
+ const t = e;
459
+ return new d().setValue(T.handleValue(t)).setInlineValue(!0);
460
+ }
461
+ }
462
+ }
463
+ static handleValue(e) {
464
+ if (e == null)
465
+ return null;
466
+ if (typeof e == "string")
467
+ return e;
468
+ if (typeof e == "number" || A(e))
469
+ if (he(e) || Number.isSafeInteger(e)) {
470
+ const t = new N(e.toString()), r = Number.MIN_SAFE_INTEGER, s = Number.MAX_SAFE_INTEGER;
471
+ return t.lt(r) ? new N(r.toString()) : t.gt(s) ? new N(s.toString()) : t;
472
+ } else {
473
+ const t = parseFloat(e.toString());
474
+ return new k(t.toString());
475
+ }
476
+ else if (typeof e == "boolean")
477
+ return e;
478
+ throw new Error(`Can't handle node: ${JSON.stringify(e)}`);
479
+ }
480
+ static handleArray(e) {
481
+ if (e != null) {
482
+ if (Ye(e) && !Array.isArray(e))
483
+ return [T.handleNode(e)];
484
+ if (Array.isArray(e))
485
+ return e.map(T.handleNode);
486
+ throw new Error("Expected an array node");
487
+ }
488
+ }
489
+ }
490
+ function Jn(n) {
491
+ return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
492
+ }
493
+ var Ue, gt;
494
+ function Kn() {
495
+ return gt || (gt = 1, Ue = function n(e) {
496
+ if (typeof e == "number" && isNaN(e))
497
+ throw new Error("NaN is not allowed");
498
+ if (typeof e == "number" && !isFinite(e))
499
+ throw new Error("Infinity is not allowed");
500
+ return e === null || typeof e != "object" ? JSON.stringify(e) : e.toJSON instanceof Function ? n(e.toJSON()) : Array.isArray(e) ? `[${e.reduce((s, o, i) => `${s}${i === 0 ? "" : ","}${n(o === void 0 || typeof o == "symbol" ? null : o)}`, "")}]` : `{${Object.keys(e).sort().reduce((r, s) => {
501
+ if (e[s] === void 0 || typeof e[s] == "symbol")
502
+ return r;
503
+ const o = r.length === 0 ? "" : ",";
504
+ return `${r}${o}${n(s)}:${n(e[s])}`;
505
+ }, "")}}`;
506
+ }), Ue;
507
+ }
508
+ var Yn = Kn();
509
+ const zn = /* @__PURE__ */ Jn(Yn);
510
+ class Hn {
511
+ static canonicalize(e) {
512
+ return zn(e);
513
+ }
514
+ }
515
+ const Qn = typeof process < "u" && process.versions != null && process.versions.node != null, ke = class ke {
516
+ constructor() {
517
+ l(this, "browserCrypto");
518
+ this.browserCrypto = this.initBrowserCrypto();
519
+ }
520
+ static getInstance() {
521
+ return this.instance || (this.instance = new ke()), this.instance;
522
+ }
523
+ initBrowserCrypto() {
524
+ return Qn ? null : "crypto" in globalThis ? globalThis.crypto : null;
525
+ }
526
+ hasNodeCrypto() {
527
+ return !!mt.createHash;
528
+ }
529
+ getBrowserCrypto() {
530
+ return this.browserCrypto;
531
+ }
532
+ getNodeCrypto() {
533
+ return mt;
534
+ }
535
+ };
536
+ l(ke, "instance");
537
+ let ze = ke;
538
+ class Gn {
539
+ constructor() {
540
+ l(this, "cryptoEnv", ze.getInstance());
541
+ }
542
+ applySync(e) {
543
+ const t = this.canonicalizeInput(e), r = this.cryptoEnv.hasNodeCrypto() ? this.sha256Sync(t) : this.sha256SyncBrowser(t);
544
+ return le.encode(new Uint8Array(r));
545
+ }
546
+ async apply(e) {
547
+ const t = this.canonicalizeInput(e), r = this.cryptoEnv.hasNodeCrypto() ? this.sha256Sync(t) : await this.sha256Async(t);
548
+ return le.encode(new Uint8Array(r));
549
+ }
550
+ canonicalizeInput(e) {
551
+ const t = Hn.canonicalize(e);
552
+ if (typeof t != "string")
553
+ throw new Error("Canonized value must be a string");
554
+ return t;
555
+ }
556
+ sha256Sync(e) {
557
+ const t = this.cryptoEnv.getNodeCrypto();
558
+ if (!t)
559
+ throw new Error(
560
+ "Synchronous SHA-256 is not available in this environment"
561
+ );
562
+ return t.createHash("sha256").update(e).digest();
563
+ }
564
+ sha256SyncBrowser(e) {
565
+ return Bn.arrayBuffer(e);
566
+ }
567
+ async sha256Async(e) {
568
+ if (this.cryptoEnv.hasNodeCrypto())
569
+ return this.sha256Sync(e);
570
+ const t = this.cryptoEnv.getBrowserCrypto();
571
+ if (!t)
572
+ throw new Error("crypto is not available in this environment");
573
+ const s = new TextEncoder().encode(e);
574
+ return t.subtle.digest("SHA-256", s);
575
+ }
576
+ }
577
+ class P {
578
+ /**
579
+ * Converts a BlueNode to a JSON representation based on the specified strategy.
580
+ *
581
+ * @param node - The BlueNode to convert.
582
+ * @param strategy - The conversion strategy to use. Defaults to 'official'.
583
+ * - `'official'`: Always returns complete objects with type information and metadata
584
+ * - `'simple'`: Returns unwrapped values/arrays when possible, objects when metadata exists
585
+ * - `'original'`: Returns simple values when no name/description, otherwise full objects
586
+ * @returns A JSON representation of the node.
587
+ */
588
+ static get(e, t = "official") {
589
+ var H;
590
+ const r = e.getValue(), s = this.handleValue(r);
591
+ if (s !== void 0 && t === "simple")
592
+ return s;
593
+ const o = (H = e.getItems()) == null ? void 0 : H.map((B) => P.get(B, t));
594
+ if (o !== void 0 && t === "simple")
595
+ return o;
596
+ const i = e.getName(), a = e.getDescription();
597
+ if (t === "original" && i === void 0 && a === void 0) {
598
+ if (s !== void 0)
599
+ return s;
600
+ if (o !== void 0)
601
+ return o;
602
+ }
603
+ const c = {};
604
+ i !== void 0 && (c[X] = i), a !== void 0 && (c[ee] = a);
605
+ const h = e.getType();
606
+ if (t === "official" && r !== void 0 && h === void 0) {
607
+ const B = this.inferTypeBlueId(r);
608
+ B !== null && (c[Ce] = { [Y]: B });
609
+ } else h !== void 0 && (c[Ce] = P.get(h, t));
610
+ const p = e.getItemType();
611
+ p !== void 0 && (c[it] = P.get(p, t));
612
+ const g = e.getKeyType();
613
+ g !== void 0 && (c[at] = P.get(g, t));
614
+ const w = e.getValueType();
615
+ w !== void 0 && (c[ct] = P.get(w, t)), s !== void 0 && (c[Fe] = s), o !== void 0 && (c[lt] = o);
616
+ const f = e.getBlueId();
617
+ f !== void 0 && (c[Y] = f);
618
+ const m = e.getBlue();
619
+ m !== void 0 && (c[ut] = m);
620
+ const E = e.getContracts();
621
+ if (E !== void 0) {
622
+ const B = {};
623
+ Object.entries(E).forEach(([ie, be]) => {
624
+ B[ie] = P.get(be, t);
625
+ }), c[Me] = B;
626
+ }
627
+ const I = e.getProperties();
628
+ return I !== void 0 && Object.entries(I).forEach(([B, ie]) => {
629
+ c[B] = P.get(ie, t);
630
+ }), c;
631
+ }
632
+ static handleValue(e) {
633
+ if (A(e)) {
634
+ if (he(e)) {
635
+ const t = new Z(Number.MIN_SAFE_INTEGER.toString()), r = new Z(Number.MAX_SAFE_INTEGER.toString());
636
+ if (e.lt(t) || e.gt(r))
637
+ return e.toString();
638
+ }
639
+ return e.toNumber();
640
+ }
641
+ return e;
642
+ }
643
+ static inferTypeBlueId(e) {
644
+ return typeof e == "string" ? ye : A(e) ? he(e) ? ge : me : typeof e == "boolean" ? we : null;
645
+ }
646
+ }
647
+ const Xn = (n) => st(n) && y(n), $ = class $ {
648
+ constructor(e) {
649
+ l(this, "hashProvider");
650
+ this.hashProvider = e;
651
+ }
652
+ static calculateBlueId(e) {
653
+ if (Array.isArray(e)) {
654
+ const r = e.map((s) => P.get(s));
655
+ return $.INSTANCE.calculate(r);
656
+ }
657
+ const t = P.get(e);
658
+ return $.INSTANCE.calculate(t);
659
+ }
660
+ static calculateBlueIdSync(e) {
661
+ if (Array.isArray(e)) {
662
+ const r = e.map((s) => P.get(s));
663
+ return $.INSTANCE.calculateSync(r);
664
+ }
665
+ const t = P.get(e);
666
+ return $.INSTANCE.calculateSync(t);
667
+ }
668
+ // public static calculateBlueIdForNodes(nodes: BlueNode[]) {
669
+ // const objects = nodes.map((node) => NodeToMapListOrValue.get(node));
670
+ // return BlueIdCalculator.INSTANCE.calculate(objects);
671
+ // }
672
+ // public static calculateBlueIdSyncForNodes(nodes: BlueNode[]) {
673
+ // const objects = nodes.map((node) => NodeToMapListOrValue.get(node));
674
+ // return BlueIdCalculator.INSTANCE.calculateSync(objects);
675
+ // }
676
+ calculate(e) {
677
+ const t = this.cleanStructure(e);
678
+ if (t === void 0)
679
+ throw new Error("Object after cleaning cannot be null or undefined.");
680
+ return this.internalCalculate(t, !1);
681
+ }
682
+ calculateSync(e) {
683
+ const t = this.cleanStructure(e);
684
+ if (t === void 0)
685
+ throw new Error("Object after cleaning cannot be null or undefined.");
686
+ return this.internalCalculate(t, !0);
687
+ }
688
+ // Internal method to calculate BlueId recursively
689
+ internalCalculate(e, t) {
690
+ return Xn(e) || A(e) ? this.applyHash(e.toString(), t) : Array.isArray(e) || ce(e) ? this.calculateList(e, t) : this.calculateMap(e, t);
691
+ }
692
+ calculateMap(e, t) {
693
+ if (e[Y] !== void 0)
694
+ return e[Y];
695
+ const s = Object.keys(e).map((i) => {
696
+ const a = e[i];
697
+ if ([X, Fe, ee].includes(i))
698
+ return t ? [i, a] : Promise.resolve([i, a]);
699
+ {
700
+ const c = this.internalCalculate(a, t);
701
+ return t ? [i, { blueId: c }] : Promise.resolve(c).then((h) => [
702
+ i,
703
+ { blueId: h }
704
+ ]);
705
+ }
706
+ }), o = (i) => {
707
+ const a = {};
708
+ for (const [c, h] of i)
709
+ a[c] = h;
710
+ return this.applyHash(a, t);
711
+ };
712
+ return t ? o(s) : Promise.all(s).then(o);
713
+ }
714
+ calculateList(e, t) {
715
+ if (e.length === 0)
716
+ throw new Error("Cannot calculate BlueId for an empty list.");
717
+ let r = this.internalCalculate(
718
+ e[0],
719
+ t
720
+ );
721
+ const s = (o, i) => t ? this.applyHash(
722
+ [{ blueId: o }, { blueId: i }],
723
+ !0
724
+ ) : Promise.all([o, i]).then(
725
+ ([a, c]) => this.applyHash([{ blueId: a }, { blueId: c }], !1)
726
+ );
727
+ for (let o = 1; o < e.length; o++) {
728
+ const i = this.internalCalculate(e[o], t);
729
+ r = s(r, i);
730
+ }
731
+ return r;
732
+ }
733
+ // Method to apply the hash provider to a value
734
+ applyHash(e, t) {
735
+ return t ? this.hashProvider.applySync(e) : this.hashProvider.apply(e);
736
+ }
737
+ // Method to clean the input structure by removing null or undefined values
738
+ cleanStructure(e) {
739
+ if (e != null) {
740
+ if (st(e) || A(e))
741
+ return e;
742
+ if (Array.isArray(e) || ce(e)) {
743
+ const t = e.map((r) => this.cleanStructure(r)).filter(y);
744
+ return t.length > 0 ? t : void 0;
745
+ } else if (typeof e == "object") {
746
+ const t = {};
747
+ for (const r in e) {
748
+ const s = this.cleanStructure(e[r]);
749
+ s != null && (t[r] = s);
750
+ }
751
+ return Object.keys(t).length > 0 ? t : void 0;
752
+ } else
753
+ return e;
754
+ }
755
+ }
756
+ };
757
+ l($, "INSTANCE", new $(new Gn()));
758
+ let V = $;
759
+ class so {
760
+ static convert(e) {
761
+ const t = le.decode(e), r = new Uint8Array(2 + t.length);
762
+ r[0] = 18, r[1] = 32, r.set(t, 2);
763
+ const s = new Uint8Array(2 + r.length);
764
+ return s[0] = 1, s[1] = 85, s.set(r, 2), "b" + new Cn.Encoder({ type: "rfc4648", lc: !0 }).write(s).finalize().replace(/=/g, "");
765
+ }
766
+ }
767
+ const He = /* @__PURE__ */ new WeakMap();
768
+ function ne(n, e) {
769
+ const t = He.get(n) || {};
770
+ return He.set(n, { ...t, ...e }), n;
771
+ }
772
+ const O = (n) => He.get(n), er = (n) => (e) => {
773
+ const t = O(e);
774
+ return ne(e, {
775
+ ...t,
776
+ blueDescription: n
777
+ });
778
+ }, tr = (n) => {
779
+ const e = O(n);
780
+ return y(e) && ot(e.blueDescription) ? e.blueDescription : null;
781
+ }, oo = (n) => er(n)(u.string().optional()), nr = u.union([u.string(), u.boolean()]), rr = (n) => (e) => {
782
+ const t = O(e);
783
+ return ne(e, {
784
+ ...t,
785
+ blueId: n
786
+ });
787
+ }, sr = (n) => {
788
+ const e = O(n), t = nr.safeParse(e == null ? void 0 : e.blueId);
789
+ return t.success ? t.data : null;
790
+ }, io = (n) => rr(n ?? !0)(u.string()), or = (n) => (e) => {
791
+ const t = O(e);
792
+ return ne(e, {
793
+ ...t,
794
+ blueName: n
795
+ });
796
+ }, ir = (n) => {
797
+ const e = O(n);
798
+ return y(e) && ot(e.blueName) ? e.blueName : null;
799
+ }, ao = (n) => {
800
+ const e = u.string().optional();
801
+ return or(n)(e);
802
+ }, ar = () => (n) => {
803
+ const e = O(n);
804
+ return ne(n, {
805
+ ...e,
806
+ blueNode: !0
807
+ });
808
+ }, cr = (n) => {
809
+ const e = O(n);
810
+ return y(e) && y(e.blueNode) && e.blueNode === !0 ? e.blueNode : null;
811
+ }, wt = (n) => !!cr(n), _ = () => {
812
+ const n = u.instanceof(d);
813
+ return ar()(n);
814
+ }, Qe = "extendedFrom", lr = ({
815
+ schema: n,
816
+ baseSchema: e
817
+ }) => {
818
+ const t = O(n) || {};
819
+ return ne(n, {
820
+ ...t,
821
+ [Qe]: e
822
+ });
823
+ }, ur = (n) => {
824
+ const e = O(n);
825
+ return y(e) && e[Qe] ? e[Qe] : null;
826
+ }, Jt = (n, e) => {
827
+ const t = ur(n);
828
+ return D(t) ? !1 : (t == null ? void 0 : t._def) === (e == null ? void 0 : e._def) ? !0 : Jt(t, e);
829
+ }, hr = (n) => new Proxy(n, {
830
+ get(e, t, r) {
831
+ return t === "extend" ? function(...s) {
832
+ const o = e.extend(...s);
833
+ return lr({
834
+ schema: o,
835
+ baseSchema: e
836
+ });
837
+ } : Reflect.get(e, t, r);
838
+ }
839
+ }), dr = u.object({
840
+ value: u.array(u.string()).optional(),
841
+ defaultValue: u.string().optional()
842
+ }), pr = (n) => {
843
+ const e = O(n), t = dr.passthrough().safeParse(e == null ? void 0 : e.typeBlueId);
844
+ return t.success ? t.data : null;
845
+ }, v = (n) => (e) => {
846
+ const t = O(e), r = typeof n == "string" ? { value: [n] } : n, s = hr(e);
847
+ return ne(s, {
848
+ ...t,
849
+ typeBlueId: {
850
+ ...(t == null ? void 0 : t.typeBlueId) || {},
851
+ ...r
852
+ }
853
+ });
854
+ };
855
+ class Re {
856
+ static resolveBlueId(e) {
857
+ var o;
858
+ const t = pr(e);
859
+ if (D(t))
860
+ return null;
861
+ const r = t.defaultValue;
862
+ if (y(r))
863
+ return r;
864
+ const s = (o = t.value) == null ? void 0 : o[0];
865
+ return y(s) ? s : Re.getRepositoryBlueId(t, e);
866
+ }
867
+ static getRepositoryBlueId(e, t) {
868
+ throw new Error("Not implemented");
869
+ }
870
+ }
871
+ class co {
872
+ constructor(e) {
873
+ l(this, "blueIdMap", /* @__PURE__ */ new Map());
874
+ for (const t of e)
875
+ this.registerSchema(t);
876
+ }
877
+ registerSchema(e) {
878
+ const t = Re.resolveBlueId(e);
879
+ if (y(t)) {
880
+ if (this.blueIdMap.has(t))
881
+ throw new Error(`Duplicate BlueId value: ${t}`);
882
+ this.blueIdMap.set(t, e);
883
+ }
884
+ }
885
+ resolveSchema(e) {
886
+ const t = this.getEffectiveBlueId(e);
887
+ return D(t) ? null : this.blueIdMap.get(t);
888
+ }
889
+ getEffectiveBlueId(e) {
890
+ const t = e.getType();
891
+ return y(t) && y(t.getBlueId()) ? t.getBlueId() : y(t) ? V.calculateBlueIdSync(t) : null;
892
+ }
893
+ getBlueIdMap() {
894
+ return new Map(this.blueIdMap);
895
+ }
896
+ }
897
+ class x {
898
+ /**
899
+ * Transforms a node and all its child nodes using the provided transformer function
900
+ * @param node - The node to transform
901
+ * @param transformer - The transformer function to apply to each node
902
+ * @returns The transformed node
903
+ */
904
+ static transform(e, t) {
905
+ const r = t(e.clone()), s = r.getType();
906
+ s !== void 0 && r.setType(x.transform(s, t));
907
+ const o = r.getItemType();
908
+ o !== void 0 && r.setItemType(
909
+ x.transform(o, t)
910
+ );
911
+ const i = r.getKeyType();
912
+ i !== void 0 && r.setKeyType(
913
+ x.transform(i, t)
914
+ );
915
+ const a = r.getValueType();
916
+ a !== void 0 && r.setValueType(
917
+ x.transform(a, t)
918
+ );
919
+ const c = r.getItems();
920
+ if (c !== void 0) {
921
+ const g = c.map(
922
+ (w) => x.transform(w, t)
923
+ );
924
+ r.setItems(g);
925
+ }
926
+ const h = r.getProperties();
927
+ if (h !== void 0) {
928
+ const g = Object.keys(h).reduce(
929
+ (w, f) => (w[f] = x.transform(h[f], t), w),
930
+ {}
931
+ );
932
+ r.setProperties(g);
933
+ }
934
+ const p = r.getContracts();
935
+ if (p !== void 0) {
936
+ const g = Object.keys(p).reduce((w, f) => (w[f] = x.transform(p[f], t), w), {});
937
+ r.setContracts(g);
938
+ }
939
+ return r;
940
+ }
941
+ }
942
+ class Kt {
943
+ static convertValue(e, t) {
944
+ var o;
945
+ const r = (o = e.getType()) == null ? void 0 : o.getBlueId(), s = e.getValue();
946
+ return D(s) ? this.isPrimitive(t) ? this.getDefaultPrimitiveValue(t) : s : ye === r ? this.convertFromString(String(s), t) : me === r || s instanceof k ? this.convertFromBigDecimal(
947
+ new k(s == null ? void 0 : s.toString()),
948
+ t
949
+ ) : ge === r || s instanceof N ? this.convertFromBigInteger(
950
+ new N(s == null ? void 0 : s.toString()),
951
+ t
952
+ ) : we === r || typeof s == "boolean" ? this.convertFromBoolean(!!s, t) : this.convertFromString(String(s), t);
953
+ }
954
+ static convertFromString(e, t) {
955
+ if (!t || t instanceof Q || t instanceof Tn || t instanceof bn)
956
+ return e;
957
+ if (t instanceof G)
958
+ return Number(e);
959
+ if (t instanceof Ee)
960
+ return e.toLowerCase() === "true";
961
+ if (t instanceof Ie)
962
+ return BigInt(e);
963
+ throw new Error(
964
+ `Cannot convert String to ${t.constructor.name}`
965
+ );
966
+ }
967
+ static convertFromBigDecimal(e, t) {
968
+ if (t instanceof G)
969
+ return e.toNumber();
970
+ if (t instanceof Q)
971
+ return e.toString();
972
+ throw new Error(
973
+ `Cannot convert Number to ${t.constructor.name}`
974
+ );
975
+ }
976
+ static convertFromBigInteger(e, t) {
977
+ if (t instanceof G)
978
+ return e.toNumber();
979
+ if (t instanceof Ie)
980
+ return BigInt(e.toString());
981
+ if (t instanceof Q)
982
+ return e.toString();
983
+ throw new Error(
984
+ `Cannot convert Number to ${t.constructor.name}`
985
+ );
986
+ }
987
+ static convertFromBoolean(e, t) {
988
+ if (!t || t instanceof Ee)
989
+ return e;
990
+ if (t instanceof Q)
991
+ return e.toString();
992
+ if (t instanceof G)
993
+ return Number(e);
994
+ if (t instanceof Ie)
995
+ return BigInt(e);
996
+ throw new Error(
997
+ `Cannot convert Boolean to ${t.constructor.name}`
998
+ );
999
+ }
1000
+ static isPrimitive(e) {
1001
+ return e ? e instanceof Q || e instanceof G || e instanceof Ee || e instanceof Ie : !1;
1002
+ }
1003
+ static getDefaultPrimitiveValue(e) {
1004
+ if (!e) return null;
1005
+ if (e instanceof G)
1006
+ return 0;
1007
+ if (e instanceof Ee)
1008
+ return !1;
1009
+ if (e instanceof Q)
1010
+ return "";
1011
+ throw new Error(
1012
+ `Unsupported primitive type: ${e.constructor.name}`
1013
+ );
1014
+ }
1015
+ }
1016
+ class fr {
1017
+ convert(e, t) {
1018
+ return Kt.convertValue(e, t);
1019
+ }
1020
+ }
1021
+ class yr {
1022
+ constructor(e) {
1023
+ this.nodeToObjectConverter = e;
1024
+ }
1025
+ /**
1026
+ * Check if the valueSchema can handle structured data (contracts should be processed specially)
1027
+ */
1028
+ canHandleStructuredData(e) {
1029
+ return e instanceof Ft || e instanceof Je || e instanceof Ke || e instanceof Mt || e instanceof jt;
1030
+ }
1031
+ convert(e, t) {
1032
+ return this.convertFields(e, t);
1033
+ }
1034
+ convertFields(e, t) {
1035
+ if (t instanceof En) {
1036
+ const r = t._def.left, s = t._def.right, o = this.convert(e, r), i = this.convert(e, s);
1037
+ return { ...o, ...i };
1038
+ }
1039
+ if (t instanceof In)
1040
+ throw new Error("Union not supported");
1041
+ if (t instanceof Je)
1042
+ return Object.keys(t.shape).reduce((s, o) => {
1043
+ const i = e.getProperties(), a = t.shape[o], c = sr(a);
1044
+ if (y(c)) {
1045
+ const m = ot(c) ? c : o, E = i == null ? void 0 : i[m], I = E ? V.calculateBlueIdSync(E) : void 0;
1046
+ return s[o] = I, s;
1047
+ }
1048
+ const h = ir(a);
1049
+ if (y(h)) {
1050
+ const m = i == null ? void 0 : i[h];
1051
+ return s[o] = m == null ? void 0 : m.getName(), s;
1052
+ }
1053
+ const p = tr(a);
1054
+ if (y(p)) {
1055
+ const m = i == null ? void 0 : i[p];
1056
+ return s[o] = m == null ? void 0 : m.getDescription(), s;
1057
+ }
1058
+ if (o === "name") {
1059
+ const m = e.getName();
1060
+ return s[o] = m, s;
1061
+ }
1062
+ if (o === "description") {
1063
+ const m = e.getDescription();
1064
+ return s[o] = m, s;
1065
+ }
1066
+ const g = e.getContracts();
1067
+ if (o === "contracts" && y(g) && this.canHandleStructuredData(a)) {
1068
+ const m = Object.fromEntries(
1069
+ Object.entries(g).map(([I, H]) => [
1070
+ I,
1071
+ P.get(H)
1072
+ ])
1073
+ ), E = T.deserialize(m);
1074
+ s[o] = this.nodeToObjectConverter.convert(
1075
+ E,
1076
+ a
1077
+ );
1078
+ }
1079
+ const w = i == null ? void 0 : i[o];
1080
+ if (D(w))
1081
+ return s;
1082
+ const f = this.nodeToObjectConverter.convert(
1083
+ w,
1084
+ a
1085
+ );
1086
+ return s[o] = f, s;
1087
+ }, {});
1088
+ throw new Error("Unknown schema type, " + t.constructor.name);
1089
+ }
1090
+ }
1091
+ class mr {
1092
+ constructor(e) {
1093
+ this.nodeToObjectConverter = e;
1094
+ }
1095
+ convert(e, t) {
1096
+ const r = e.getItems();
1097
+ if (!r)
1098
+ return;
1099
+ const s = t.element;
1100
+ return r.map(
1101
+ (i) => this.nodeToObjectConverter.convert(i, s)
1102
+ );
1103
+ }
1104
+ }
1105
+ class gr {
1106
+ constructor(e) {
1107
+ this.nodeToObjectConverter = e;
1108
+ }
1109
+ convert(e, t) {
1110
+ const r = e.getItems();
1111
+ if (!r)
1112
+ return;
1113
+ const s = t._def.valueType, o = r.map(
1114
+ (i) => this.nodeToObjectConverter.convert(i, s)
1115
+ );
1116
+ return new Set(o);
1117
+ }
1118
+ }
1119
+ class wr {
1120
+ constructor(e) {
1121
+ this.nodeToObjectConverter = e;
1122
+ }
1123
+ /**
1124
+ * Check if the valueSchema can handle structured data (contracts should be processed specially)
1125
+ */
1126
+ canHandleStructuredData(e) {
1127
+ return e instanceof Ft || e instanceof Je || e instanceof Ke || e instanceof Mt || e instanceof jt;
1128
+ }
1129
+ convert(e, t) {
1130
+ const r = t.keySchema, s = t.valueSchema, o = /* @__PURE__ */ new Map(), i = e.getName();
1131
+ y(i) && o.set(X, i);
1132
+ const a = e.getDescription();
1133
+ y(a) && o.set(ee, a);
1134
+ const c = e.getContracts();
1135
+ if (y(c) && this.canHandleStructuredData(s)) {
1136
+ let p = !1;
1137
+ const g = Object.entries(c).reduce(
1138
+ (w, [f, m]) => {
1139
+ try {
1140
+ const E = this.nodeToObjectConverter.convert(
1141
+ m,
1142
+ s
1143
+ );
1144
+ E != null && !Number.isNaN(E) && (w[f] = E, p = !0);
1145
+ } catch {
1146
+ }
1147
+ return w;
1148
+ },
1149
+ {}
1150
+ );
1151
+ p && o.set(Me, g);
1152
+ }
1153
+ const h = e.getProperties();
1154
+ return y(h) && Object.entries(h).forEach(([p, g]) => {
1155
+ const w = new d().setValue(p);
1156
+ w.setType(new d().setBlueId(ye));
1157
+ const f = Kt.convertValue(w, r), m = this.nodeToObjectConverter.convert(g, s);
1158
+ o.set(f, m);
1159
+ }), t instanceof Ke ? Object.fromEntries(o) : o;
1160
+ }
1161
+ }
1162
+ class Tr {
1163
+ convert(e) {
1164
+ return P.get(e);
1165
+ }
1166
+ }
1167
+ class br {
1168
+ convert(e) {
1169
+ return P.get(e);
1170
+ }
1171
+ }
1172
+ class Er {
1173
+ constructor(e) {
1174
+ this.nodeToObjectConverter = e;
1175
+ }
1176
+ convert(e, t) {
1177
+ const r = e.getItems();
1178
+ if (!r)
1179
+ return;
1180
+ const s = t.items;
1181
+ return r.map(
1182
+ (i, a) => this.nodeToObjectConverter.convert(i, s[a])
1183
+ );
1184
+ }
1185
+ }
1186
+ const Ir = u.union([
1187
+ u.literal("ZodString"),
1188
+ u.literal("ZodNumber"),
1189
+ u.literal("ZodBoolean"),
1190
+ u.literal("ZodBigInt"),
1191
+ u.literal("ZodArray"),
1192
+ u.literal("ZodSet"),
1193
+ u.literal("ZodMap"),
1194
+ u.literal("ZodRecord"),
1195
+ u.literal("ZodObject"),
1196
+ u.literal("ZodEnum"),
1197
+ u.literal("ZodNativeEnum"),
1198
+ u.literal("ZodUnknown"),
1199
+ u.literal("ZodAny"),
1200
+ u.literal("ZodTuple")
1201
+ ]);
1202
+ class vr {
1203
+ constructor(e) {
1204
+ l(this, "converters", /* @__PURE__ */ new Map());
1205
+ l(this, "complexObjectConverter");
1206
+ this.nodeToObjectConverter = e, this.registerConverters(), this.complexObjectConverter = new yr(
1207
+ this.nodeToObjectConverter
1208
+ );
1209
+ }
1210
+ registerConverters() {
1211
+ const e = new fr(), t = new mr(this.nodeToObjectConverter), r = new Er(this.nodeToObjectConverter), s = new gr(this.nodeToObjectConverter), o = new wr(this.nodeToObjectConverter);
1212
+ this.converters.set("ZodString", e), this.converters.set("ZodNumber", e), this.converters.set("ZodBoolean", e), this.converters.set("ZodBigInt", e), this.converters.set("ZodEnum", e), this.converters.set("ZodNativeEnum", e), this.converters.set("ZodUnknown", new Tr()), this.converters.set("ZodAny", new br()), this.converters.set("ZodArray", t), this.converters.set("ZodTuple", r), this.converters.set("ZodSet", s), this.converters.set("ZodMap", o), this.converters.set("ZodRecord", o), this.converters.set("ZodObject", this.complexObjectConverter);
1213
+ }
1214
+ getConverter(e) {
1215
+ const t = this.getSchemaTypeName(e);
1216
+ return this.converters.get(t) ?? this.complexObjectConverter;
1217
+ }
1218
+ isWrapperType(e) {
1219
+ return e instanceof Rt || e instanceof $t || e instanceof Ut || e instanceof Zt || e instanceof Pe || e instanceof Be;
1220
+ }
1221
+ getSchemaTypeName(e) {
1222
+ if (this.isWrapperType(e))
1223
+ return e instanceof Pe ? this.getSchemaTypeName(e.innerType()) : e instanceof Be ? this.getSchemaTypeName(e.schema) : this.getSchemaTypeName(e.unwrap());
1224
+ const t = e.constructor.name;
1225
+ try {
1226
+ return Ir.parse(t);
1227
+ } catch {
1228
+ throw new Error(`Schema type name ${t} is not supported`);
1229
+ }
1230
+ }
1231
+ }
1232
+ class Yt {
1233
+ constructor(e) {
1234
+ l(this, "converterFactory");
1235
+ this.typeSchemaResolver = e, this.converterFactory = new vr(this);
1236
+ }
1237
+ convert(e, t) {
1238
+ var i;
1239
+ const r = (i = this.typeSchemaResolver) == null ? void 0 : i.resolveSchema(e), s = this.unwrapSchema(t);
1240
+ if (wt(s))
1241
+ return e;
1242
+ let o = s;
1243
+ return y(r) && Jt(r, s) && (o = r), this.convertWithType(e, o);
1244
+ }
1245
+ convertWithType(e, t) {
1246
+ return this.converterFactory.getConverter(t).convert(e, t);
1247
+ }
1248
+ isWrapperType(e) {
1249
+ return e instanceof Rt || e instanceof $t || e instanceof Ut || e instanceof Zt || e instanceof Pe || e instanceof Be;
1250
+ }
1251
+ unwrapSchema(e) {
1252
+ return wt(e) ? e : this.isWrapperType(e) ? e instanceof Pe ? this.unwrapSchema(e.innerType()) : e instanceof Be ? this.unwrapSchema(e.schema) : this.unwrapSchema(e.unwrap()) : e;
1253
+ }
1254
+ }
1255
+ class $e {
1256
+ /**
1257
+ * Fetches the first node associated with the given Blue ID
1258
+ * Default implementation that takes the first node from fetchByBlueId result
1259
+ *
1260
+ * @param blueId - The Blue ID to fetch nodes for
1261
+ * @returns The first node found for the Blue ID, or null if none exist
1262
+ */
1263
+ fetchFirstByBlueId(e) {
1264
+ const t = this.fetchByBlueId(e);
1265
+ return t && t.length > 0 ? t[0] : null;
1266
+ }
1267
+ }
1268
+ function Pr(n) {
1269
+ return new class extends $e {
1270
+ fetchByBlueId(e) {
1271
+ return n(e);
1272
+ }
1273
+ }();
1274
+ }
1275
+ class Br extends $e {
1276
+ constructor(t) {
1277
+ super();
1278
+ l(this, "nodeProviders");
1279
+ this.nodeProviders = t;
1280
+ }
1281
+ fetchByBlueId(t) {
1282
+ for (const r of this.nodeProviders) {
1283
+ const s = r.fetchByBlueId(t);
1284
+ if (s && s.length > 0)
1285
+ return s;
1286
+ }
1287
+ return [];
1288
+ }
1289
+ // Override fetchFirstByBlueId for more efficient implementation
1290
+ // In Java, this would call the default implementation, but we optimize here
1291
+ fetchFirstByBlueId(t) {
1292
+ for (const r of this.nodeProviders) {
1293
+ const s = r.fetchFirstByBlueId(t);
1294
+ if (s)
1295
+ return s;
1296
+ }
1297
+ return null;
1298
+ }
1299
+ getNodeProviders() {
1300
+ return this.nodeProviders;
1301
+ }
1302
+ }
1303
+ const Ze = z.types.float.options, Cr = {
1304
+ ...Ze,
1305
+ construct: (n) => {
1306
+ const e = n.replace(/_/g, "").toLowerCase();
1307
+ if (!Vt(e))
1308
+ return new k(e);
1309
+ if (Ze.construct)
1310
+ return Ze.construct(n);
1311
+ }
1312
+ }, Sr = new z.Type("tag:yaml.org,2002:float", Cr), qe = z.types.int.options, Nr = {
1313
+ ...qe,
1314
+ construct: (n) => {
1315
+ let e = n;
1316
+ if (e.indexOf("_") !== -1 && (e = e.replace(/_/g, "")), !Vt(e))
1317
+ return new N(e);
1318
+ if (qe.construct)
1319
+ return qe.construct(n);
1320
+ }
1321
+ }, Ar = new z.Type("tag:yaml.org,2002:int", Nr), zt = z.CORE_SCHEMA.extend({
1322
+ implicit: [Sr, Ar]
1323
+ }), de = (n) => {
1324
+ const e = z.load(n, { schema: zt });
1325
+ return e === void 0 ? void 0 : e;
1326
+ }, lo = (n) => z.dump(n, {
1327
+ schema: zt,
1328
+ replacer: (e, t) => {
1329
+ if (A(t)) {
1330
+ if (he(t)) {
1331
+ const r = new Z(Number.MIN_SAFE_INTEGER.toString()), s = new Z(Number.MAX_SAFE_INTEGER.toString());
1332
+ if (t.lt(r) || t.gt(s))
1333
+ return t.toString();
1334
+ }
1335
+ return t.toNumber();
1336
+ }
1337
+ return t;
1338
+ }
1339
+ }), Ht = `- type:
1340
+ blueId: 27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo
1341
+ mappings:
1342
+ Text: F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP
1343
+ Double: 68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L
1344
+ Integer: DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8
1345
+ Boolean: EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo
1346
+ List: G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB
1347
+ Dictionary: 294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA
1348
+ - type:
1349
+ blueId: FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4
1350
+ `, Or = `name: Transformation
1351
+ description: TODO`, kr = `name: Infer Basic Types For Untyped Values
1352
+ type:
1353
+ blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
1354
+ description: This transformation infers type details for Text, Integer, Number and Boolean.`, xr = `name: Replace Inline Types with BlueIds
1355
+ type:
1356
+ blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
1357
+ description: This transformation replaces`, Dr = [
1358
+ Ht,
1359
+ Or,
1360
+ kr,
1361
+ xr
1362
+ ];
1363
+ class Vr extends $e {
1364
+ constructor() {
1365
+ super();
1366
+ l(this, "blueIdToNodesMap", /* @__PURE__ */ new Map());
1367
+ this.load();
1368
+ }
1369
+ fetchByBlueId(t) {
1370
+ return this.blueIdToNodesMap.get(t) || [];
1371
+ }
1372
+ load() {
1373
+ for (const t of Dr) {
1374
+ const r = de(t);
1375
+ if (r === void 0) {
1376
+ console.error(`This content file is not valid YAML: ${t}`);
1377
+ continue;
1378
+ }
1379
+ if (Array.isArray(r)) {
1380
+ const s = r.map(
1381
+ (i) => T.deserialize(i)
1382
+ ), o = V.calculateBlueIdSync(s);
1383
+ this.blueIdToNodesMap.set(o, s);
1384
+ } else {
1385
+ const s = T.deserialize(r), o = V.calculateBlueIdSync(s);
1386
+ this.blueIdToNodesMap.set(o, [s]);
1387
+ }
1388
+ }
1389
+ }
1390
+ }
1391
+ const xe = class xe extends $e {
1392
+ constructor() {
1393
+ super();
1394
+ l(this, "nodeProvider");
1395
+ this.nodeProvider = new Vr();
1396
+ }
1397
+ fetchByBlueId(t) {
1398
+ return this.nodeProvider.fetchByBlueId(t);
1399
+ }
1400
+ };
1401
+ l(xe, "INSTANCE", new xe());
1402
+ let Ge = xe;
1403
+ class pe {
1404
+ /**
1405
+ * Wraps a NodeProvider with a SequentialNodeProvider that includes bootstrap providers
1406
+ * @param originalProvider - The original NodeProvider to wrap
1407
+ * @returns A wrapped NodeProvider that includes bootstrap providers
1408
+ */
1409
+ static wrap(e) {
1410
+ return new Br([
1411
+ Ge.INSTANCE,
1412
+ e
1413
+ ]);
1414
+ }
1415
+ }
1416
+ const Qt = (n) => n instanceof d || Array.isArray(n) && n.every((e) => e instanceof d) ? n : Ve(n) ? n.map((e) => T.deserialize(e)) : T.deserialize(n), Fr = async (n) => {
1417
+ const e = Qt(n);
1418
+ return V.calculateBlueId(e);
1419
+ }, uo = (n) => {
1420
+ const e = Qt(n);
1421
+ return V.calculateBlueIdSync(e);
1422
+ }, Tt = async (n) => {
1423
+ if ($n(n))
1424
+ return n;
1425
+ try {
1426
+ const e = Se.parse(n), t = await Fr(e);
1427
+ return {
1428
+ ...n,
1429
+ blueId: t
1430
+ };
1431
+ } catch (e) {
1432
+ throw new Error(`Failed enriching object with Blue ID: ${e}`);
1433
+ }
1434
+ }, ho = (n) => n == null ? void 0 : n.items, po = (n) => n == null ? void 0 : n.value, fo = (n) => D(n) ? {} : qt(
1435
+ n,
1436
+ Nn
1437
+ ), yo = (n) => Zn(n) ? n.type.name ?? null : qn(n) ? vn(typeof n.value) : Un(n) ? "List" : null, Mr = (n) => y(n) && Object.keys(qt(n, ["blueId"])).length > 0, mo = (n) => {
1438
+ try {
1439
+ const e = T.deserialize(n), t = P.get(e);
1440
+ return ue.parse(t);
1441
+ } catch (e) {
1442
+ throw new Error(
1443
+ `Failed transforming JSON-like value to BlueObject: ${e}`
1444
+ );
1445
+ }
1446
+ }, bt = async (n) => {
1447
+ const {
1448
+ resolveFunction: e,
1449
+ signal: t = new AbortController().signal,
1450
+ omitItems: r
1451
+ } = n, s = n.count ?? n.items.length;
1452
+ let o = await Pn(n.items, async (a) => await Tt(a));
1453
+ const i = Math.max((o == null ? void 0 : o.length) - s, 0);
1454
+ for (let a = o.length - 1; a >= i; a--)
1455
+ if (!Mr(o[a])) {
1456
+ const c = await e(o[a], { signal: t });
1457
+ if (Array.isArray(c))
1458
+ return bt({
1459
+ ...n,
1460
+ items: [
1461
+ ...o.slice(0, a),
1462
+ ...c,
1463
+ ...o.slice(a + 1)
1464
+ ]
1465
+ });
1466
+ const h = await Tt(c);
1467
+ if (r != null && r.includes(h.blueId))
1468
+ return bt({
1469
+ ...n,
1470
+ items: [...o.slice(0, a), ...o.slice(a + 1)]
1471
+ });
1472
+ o = [
1473
+ ...o.slice(0, a),
1474
+ h,
1475
+ ...o.slice(a + 1)
1476
+ ];
1477
+ }
1478
+ return o;
1479
+ };
1480
+ function ve(n) {
1481
+ try {
1482
+ const e = new URL(n);
1483
+ return e.protocol === "http:" || e.protocol === "https:";
1484
+ } catch {
1485
+ return !1;
1486
+ }
1487
+ }
1488
+ class jr {
1489
+ /**
1490
+ * Process a document node to infer basic types for untyped values
1491
+ * @param document - The document to process
1492
+ * @returns The processed document
1493
+ */
1494
+ process(e) {
1495
+ return x.transform(e, this.inferType.bind(this));
1496
+ }
1497
+ /**
1498
+ * Infer a basic type for a node
1499
+ * @param node - The node to infer a type for
1500
+ * @returns The node with the inferred type
1501
+ */
1502
+ inferType(e) {
1503
+ const t = e.getType(), r = e.getValue();
1504
+ return D(t) && y(r) && (typeof r == "string" ? e.setType(new d().setBlueId(ye)) : typeof r == "bigint" || he(r) ? e.setType(new d().setBlueId(ge)) : Ln(r) ? e.setType(new d().setBlueId(me)) : typeof r == "boolean" && e.setType(new d().setBlueId(we))), e;
1505
+ }
1506
+ }
1507
+ const ae = class ae {
1508
+ /**
1509
+ * Creates a new processor with the given transformation node or mappings
1510
+ * @param transformationOrMappings - The transformation node or mappings to use
1511
+ */
1512
+ constructor(e) {
1513
+ l(this, "mappings", /* @__PURE__ */ new Map());
1514
+ if (e instanceof d) {
1515
+ const r = e.getProperties();
1516
+ if (r && r[ae.MAPPINGS]) {
1517
+ const o = r[ae.MAPPINGS].getProperties();
1518
+ o && Object.entries(o).forEach(([i, a]) => {
1519
+ const c = a.getValue();
1520
+ typeof c == "string" && this.mappings.set(i, c);
1521
+ });
1522
+ }
1523
+ } else
1524
+ this.mappings = e;
1525
+ }
1526
+ /**
1527
+ * Process a document node to replace inline values for type attributes with imports
1528
+ * @param document - The document to process
1529
+ * @returns The processed document
1530
+ */
1531
+ process(e) {
1532
+ return x.transform(e, this.transformNode.bind(this));
1533
+ }
1534
+ transformNode(e) {
1535
+ const t = e.clone();
1536
+ return this.transformTypeField(t, t.getType()), this.transformTypeField(t, t.getItemType()), this.transformTypeField(t, t.getKeyType()), this.transformTypeField(t, t.getValueType()), t;
1537
+ }
1538
+ transformTypeField(e, t) {
1539
+ if (t && t.isInlineValue() && t.getValue() !== void 0) {
1540
+ const r = String(t.getValue());
1541
+ if (this.mappings.has(r)) {
1542
+ const s = this.mappings.get(r);
1543
+ if (s) {
1544
+ const o = new d().setBlueId(s);
1545
+ t === e.getType() ? e.setType(o) : t === e.getItemType() ? e.setItemType(o) : t === e.getKeyType() ? e.setKeyType(o) : t === e.getValueType() && e.setValueType(o);
1546
+ }
1547
+ }
1548
+ }
1549
+ }
1550
+ };
1551
+ l(ae, "MAPPINGS", "mappings");
1552
+ let Xe = ae;
1553
+ class Rr {
1554
+ /**
1555
+ * Creates a new NodeExtender with the specified NodeProvider and optional strategy
1556
+ * @param nodeProvider - The NodeProvider to use for resolving nodes
1557
+ * @param strategy - The strategy to use for missing elements (defaults to THROW_EXCEPTION)
1558
+ */
1559
+ constructor(e, t) {
1560
+ l(this, "nodeProvider");
1561
+ l(this, "strategy");
1562
+ this.nodeProvider = pe.wrap(e), this.strategy = t || "THROW_EXCEPTION";
1563
+ }
1564
+ /**
1565
+ * Extends a node with its resolved references
1566
+ * @param node - The node to extend
1567
+ * @param limits - The limits to apply when extending
1568
+ */
1569
+ extend(e, t) {
1570
+ this.extendNode(e, t, "");
1571
+ }
1572
+ extendNode(e, t, r, s = !1) {
1573
+ if (!s) {
1574
+ if (!t.shouldExtendPathSegment(r, e))
1575
+ return;
1576
+ t.enterPathSegment(r, e);
1577
+ }
1578
+ try {
1579
+ const o = e.getBlueId();
1580
+ if (o && !(o in ht)) {
1581
+ const f = this.fetchNode(e);
1582
+ if (f && f.length > 0)
1583
+ if (f.length === 1) {
1584
+ const m = f[0];
1585
+ this.mergeNodes(e, m);
1586
+ } else {
1587
+ const m = f.map((I) => I.clone()), E = new d().setItems(m);
1588
+ this.mergeNodes(e, E);
1589
+ }
1590
+ }
1591
+ const i = e.getType();
1592
+ i && this.extendNode(i, t, "type", !0);
1593
+ const a = e.getItemType();
1594
+ a && this.extendNode(a, t, "itemType", !0);
1595
+ const c = e.getKeyType();
1596
+ c && this.extendNode(c, t, "keyType", !0);
1597
+ const h = e.getValueType();
1598
+ h && this.extendNode(h, t, "valueType", !0);
1599
+ const p = e.getProperties();
1600
+ p && Object.entries(p).forEach(([f, m]) => {
1601
+ this.extendNode(m, t, f, !1);
1602
+ });
1603
+ const g = e.getContracts();
1604
+ g && Object.entries(g).forEach(([f, m]) => {
1605
+ this.extendNode(m, t, f, !1);
1606
+ });
1607
+ const w = e.getItems();
1608
+ if (w && w.length > 0) {
1609
+ this.reconstructList(w);
1610
+ for (let f = 0; f < w.length; f++)
1611
+ this.extendNode(w[f], t, String(f), !1);
1612
+ }
1613
+ } finally {
1614
+ s || t.exitPathSegment();
1615
+ }
1616
+ }
1617
+ reconstructList(e) {
1618
+ for (; e.length > 0; ) {
1619
+ const t = e[0], r = t == null ? void 0 : t.getBlueId();
1620
+ if (!r)
1621
+ break;
1622
+ const s = this.nodeProvider.fetchByBlueId(r);
1623
+ if (!s || s.length === 1)
1624
+ break;
1625
+ e.shift(), e.unshift(...s);
1626
+ }
1627
+ }
1628
+ fetchNode(e) {
1629
+ const t = e.getBlueId();
1630
+ if (!t) {
1631
+ if (this.strategy === "RETURN_EMPTY")
1632
+ return null;
1633
+ throw new Error(`No blueId found for node: ${e.getName()}`);
1634
+ }
1635
+ const r = this.nodeProvider.fetchByBlueId(t);
1636
+ if (!r || r.length === 0) {
1637
+ if (this.strategy === "RETURN_EMPTY")
1638
+ return null;
1639
+ throw new Error(`No content found for blueId: ${e.getBlueId()}`);
1640
+ }
1641
+ return r;
1642
+ }
1643
+ mergeNodes(e, t) {
1644
+ e.setName(t.getName()), e.setDescription(t.getDescription()), e.setType(t.getType()), e.setItemType(t.getItemType()), e.setKeyType(t.getKeyType()), e.setValueType(t.getValueType()), e.setValue(t.getValue() ?? null), e.setItems(t.getItems()), e.setProperties(t.getProperties()), e.setContracts(t.getContracts());
1645
+ }
1646
+ }
1647
+ class $r {
1648
+ }
1649
+ function Et(n, e) {
1650
+ const t = n.split(e), r = [...t].reverse().findIndex((o) => o !== ""), s = r === -1 ? 0 : t.length - r;
1651
+ return t.slice(0, s);
1652
+ }
1653
+ class Gt extends $r {
1654
+ /**
1655
+ * Creates path limits with the specified paths and max depth
1656
+ * @param allowedPaths - The paths to limit extension to
1657
+ * @param maxDepth - The maximum depth of paths to allow
1658
+ */
1659
+ constructor(t, r) {
1660
+ super();
1661
+ l(this, "allowedPaths");
1662
+ l(this, "maxDepth");
1663
+ l(this, "currentPath", []);
1664
+ this.allowedPaths = t, this.maxDepth = r;
1665
+ }
1666
+ /**
1667
+ * Determines if a path segment should be extended
1668
+ * @param pathSegment - The path segment
1669
+ * @returns True if the segment should be extended, false otherwise
1670
+ */
1671
+ shouldExtendPathSegment(t) {
1672
+ if (this.currentPath.length >= this.maxDepth)
1673
+ return !1;
1674
+ const r = this.normalizePath(
1675
+ this.getCurrentFullPath() + "/" + t
1676
+ );
1677
+ return this.isAllowedPath(r);
1678
+ }
1679
+ /**
1680
+ * Determines if a path segment should be merged
1681
+ * @param pathSegment - The path segment
1682
+ * @returns True if the segment should be merged, false otherwise
1683
+ */
1684
+ shouldMergePathSegment(t) {
1685
+ return this.shouldExtendPathSegment(t);
1686
+ }
1687
+ /**
1688
+ * Checks if a path is allowed
1689
+ * @param path - The path to check
1690
+ * @returns True if the path is allowed, false otherwise
1691
+ */
1692
+ isAllowedPath(t) {
1693
+ for (const r of this.allowedPaths)
1694
+ if (this.matchesAllowedPath(r, t))
1695
+ return !0;
1696
+ return !1;
1697
+ }
1698
+ /**
1699
+ * Checks if a path matches an allowed path pattern
1700
+ * @param allowedPath - The allowed path pattern
1701
+ * @param path - The path to check
1702
+ * @returns True if the path matches the allowed path pattern, false otherwise
1703
+ */
1704
+ matchesAllowedPath(t, r) {
1705
+ const s = Et(t, "/"), o = Et(r, "/");
1706
+ if (o.length > s.length)
1707
+ return !1;
1708
+ for (let i = 1; i < o.length; i++)
1709
+ if (s[i] !== "*" && s[i] !== o[i])
1710
+ return !1;
1711
+ return !0;
1712
+ }
1713
+ /**
1714
+ * Enters a path segment
1715
+ * @param pathSegment - The path segment
1716
+ */
1717
+ enterPathSegment(t) {
1718
+ this.currentPath.push(t);
1719
+ }
1720
+ /**
1721
+ * Exits a path segment
1722
+ */
1723
+ exitPathSegment() {
1724
+ this.currentPath.length > 0 && this.currentPath.pop();
1725
+ }
1726
+ /**
1727
+ * Gets the current full path
1728
+ * @returns The current full path
1729
+ */
1730
+ getCurrentFullPath() {
1731
+ return "/" + this.currentPath.join("/");
1732
+ }
1733
+ /**
1734
+ * Normalizes a path
1735
+ * @param path - The path to normalize
1736
+ * @returns The normalized path
1737
+ */
1738
+ normalizePath(t) {
1739
+ return "/" + t.split("/").filter((r) => r !== "").join("/");
1740
+ }
1741
+ /**
1742
+ * Creates path limits with a maximum depth
1743
+ * @param maxDepth - The maximum depth
1744
+ * @returns The path limits
1745
+ */
1746
+ static withMaxDepth(t) {
1747
+ return new It().setMaxDepth(t).addPath("*").build();
1748
+ }
1749
+ /**
1750
+ * Creates path limits with a single path
1751
+ * @param path - The path to limit extension to
1752
+ * @returns The path limits
1753
+ */
1754
+ static withSinglePath(t) {
1755
+ return new It().addPath(t).build();
1756
+ }
1757
+ }
1758
+ class It {
1759
+ constructor() {
1760
+ l(this, "allowedPaths", /* @__PURE__ */ new Set());
1761
+ l(this, "maxDepth", Number.MAX_SAFE_INTEGER);
1762
+ }
1763
+ /**
1764
+ * Adds a path to the allowed paths
1765
+ * @param path - The path to add
1766
+ * @returns The builder
1767
+ */
1768
+ addPath(e) {
1769
+ return this.allowedPaths.add(e), this;
1770
+ }
1771
+ /**
1772
+ * Sets the maximum depth
1773
+ * @param maxDepth - The maximum depth
1774
+ * @returns The builder
1775
+ */
1776
+ setMaxDepth(e) {
1777
+ return this.maxDepth = e, this;
1778
+ }
1779
+ /**
1780
+ * Builds the PathLimits
1781
+ * @returns The built PathLimits
1782
+ */
1783
+ build() {
1784
+ return new Gt(this.allowedPaths, this.maxDepth);
1785
+ }
1786
+ }
1787
+ const j = {
1788
+ "MyOS Timeline Channel": "MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R",
1789
+ "MyOS Timeline Entry": "uDxZ7dr6Eo2MkKoutP5qxkh3uxQCS1VAptiCPc2R7B7f",
1790
+ "MyOS Agent": "AgentBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V",
1791
+ "MyOS Agent Channel": "AgentCh4nn3lBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V",
1792
+ "MyOS Agent Event": "AgentEv3ntBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V"
1793
+ }, b = {
1794
+ Channel: "2RMkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc",
1795
+ "Timeline Channel": "RMkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2",
1796
+ "Composite Timeline Channel": "qxkh3uMkKoutP5DxZ7dr6Eo27B7fuxQCS1VAptiCPc2R",
1797
+ "MyOS Timeline Channel": "MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R",
1798
+ "Sequential Workflow": "h3uDxZ7dr6Eo27B7fuxMkKoutP5qxkQCS1VAptiCPc2R",
1799
+ "Sequential Workflow Step": "6EoMkKoutP5DxZ7drqxkh3u27B7fuxQCS1VAptiCPc2R",
1800
+ "Process Embedded": "DxZ7dr6EoMkKoutP5qxkh3u27B7fuxQCS1VAptiCPc2R",
1801
+ "Embedded Node Channel": "MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2",
1802
+ "Document Update Channel": "MkKoutP5qxkh3uDQCS1VAptiCPc2xZ7dr6Eo27B7fux",
1803
+ "Channel Event Checkpoint": "o27B7fuxMkKoutPh3uDxZ7dr6E5qxkQCS1VAptiCPc2R",
1804
+ "Update Document": "7fuxMkKoutPh3uDxZ7dr6E5qxkQCS1VAptiCPc2R",
1805
+ "Trigger Event": "kQCS1VAp7fuxMkKoutPh3uDxZ7dr6E5qxtiCPc2R",
1806
+ "Json Patch Entry": "EnUQeMiMa2wHFW3JbeSPvdgfpL6qZYCR29m3SfeHsKSY",
1807
+ "JavaScript Code": "MkKoutPDxZ7dr6Eo5qxkh3u27B7fuxQCS1VAptiCPc2R",
1808
+ "Timeline Entry": "uDxZ7dr6Eo27B7fMkKoutP5qxkh3uxQCS1VAptiCPc2R",
1809
+ Operation: "OpKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R",
1810
+ "Sequential Workflow Operation": "SeqOpKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiC",
1811
+ "Operation Request": "OpReqKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiC"
1812
+ }, Te = v(b.Channel)(
1813
+ u.object({
1814
+ name: u.string().optional(),
1815
+ description: u.string().optional()
1816
+ })
1817
+ ), Ur = v(
1818
+ b["Composite Timeline Channel"]
1819
+ )(
1820
+ Te.extend({
1821
+ channels: u.array(u.string()).optional()
1822
+ })
1823
+ ), Zr = v(
1824
+ b["Document Update Channel"]
1825
+ )(
1826
+ Te.extend({
1827
+ path: u.string().optional()
1828
+ })
1829
+ ), vt = v(
1830
+ b["Embedded Node Channel"]
1831
+ )(
1832
+ Te.extend({
1833
+ path: u.string().optional()
1834
+ })
1835
+ ), qr = v(b.Operation)(
1836
+ u.object({
1837
+ request: _().optional(),
1838
+ description: u.string().optional(),
1839
+ channel: u.string().optional()
1840
+ })
1841
+ ), Lr = v(
1842
+ b["Operation Request"]
1843
+ )(
1844
+ u.object({
1845
+ operation: u.string().optional(),
1846
+ request: _(),
1847
+ document: u.object({
1848
+ blueId: u.string().optional()
1849
+ }).optional(),
1850
+ allowNewerVersion: u.boolean().optional()
1851
+ })
1852
+ ), et = v(
1853
+ b["Process Embedded"]
1854
+ )(
1855
+ u.object({
1856
+ paths: u.array(u.string()).optional()
1857
+ })
1858
+ ), tt = v(
1859
+ b["Sequential Workflow"]
1860
+ )(
1861
+ u.object({
1862
+ steps: u.array(_()).optional(),
1863
+ channel: u.string().optional()
1864
+ })
1865
+ ), _r = v(
1866
+ b["Sequential Workflow Operation"]
1867
+ )(
1868
+ tt.omit({
1869
+ channel: !0
1870
+ }).extend({
1871
+ operation: u.string().optional()
1872
+ })
1873
+ ), Xt = v(
1874
+ b["Timeline Channel"]
1875
+ )(
1876
+ Te.extend({
1877
+ timelineId: u.string().optional()
1878
+ })
1879
+ ), Ne = v(b["Timeline Entry"])(
1880
+ u.object({
1881
+ timelineId: u.string().optional(),
1882
+ timelinePrev: u.string().optional(),
1883
+ thread: u.string().optional(),
1884
+ threadPrev: u.string().optional(),
1885
+ message: _(),
1886
+ signature: u.string().optional()
1887
+ })
1888
+ ), Le = v(b["Trigger Event"])(
1889
+ u.object({
1890
+ event: _()
1891
+ })
1892
+ ), Wr = v(b["Json Patch Entry"])(
1893
+ u.object({
1894
+ name: u.string().optional(),
1895
+ description: u.string().optional(),
1896
+ val: _().optional(),
1897
+ op: u.string().optional(),
1898
+ path: u.string().optional()
1899
+ })
1900
+ ), _e = v(b["Update Document"])(
1901
+ u.object({
1902
+ changeset: u.array(Wr)
1903
+ })
1904
+ ), Jr = v(
1905
+ j["MyOS Timeline Channel"]
1906
+ )(
1907
+ Xt.extend({
1908
+ account: u.string().optional(),
1909
+ email: u.string().optional()
1910
+ })
1911
+ ), Kr = v(
1912
+ j["MyOS Timeline Entry"]
1913
+ )(
1914
+ Ne.extend({
1915
+ account: u.string().optional(),
1916
+ email: u.string().optional()
1917
+ })
1918
+ ), Yr = v(j["MyOS Agent"])(
1919
+ u.object({
1920
+ agentId: u.string().optional()
1921
+ })
1922
+ ), zr = v(
1923
+ j["MyOS Agent Channel"]
1924
+ )(
1925
+ Te.extend({
1926
+ agent: Yr.optional(),
1927
+ event: _().optional()
1928
+ })
1929
+ ), Hr = v(j["MyOS Agent Event"])(
1930
+ u.object({
1931
+ agentId: u.string().optional(),
1932
+ id: u.number().optional(),
1933
+ timestamp: u.number().optional(),
1934
+ event: _().optional()
1935
+ })
1936
+ );
1937
+ class W {
1938
+ /**
1939
+ * Initializes the generator with default BlueIds collections
1940
+ * @param defaultCollections - Array of default BlueIds objects to initialize with
1941
+ */
1942
+ static initialize(...e) {
1943
+ this.blueIdsCollections = [...e];
1944
+ }
1945
+ /**
1946
+ * Registers additional BlueIds collections for mapping generation
1947
+ * @param blueIdsCollections - Array of BlueIds objects to register
1948
+ */
1949
+ static registerBlueIds(...e) {
1950
+ this.blueIdsCollections.push(...e);
1951
+ }
1952
+ /**
1953
+ * Generates YAML mappings section from all registered BlueIds collections
1954
+ * @param transformationBlueId - The BlueId for the transformation type (defaults to the standard one)
1955
+ * @returns YAML string with mappings for all BlueIds
1956
+ */
1957
+ static generateMappingsYaml(e = "27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo") {
1958
+ const t = {};
1959
+ for (const s of this.blueIdsCollections)
1960
+ Object.assign(t, s);
1961
+ const r = Object.entries(t).map(([s, o]) => ` ${s}: ${o}`).join(`
1962
+ `);
1963
+ return `- type:
1964
+ blueId: ${e}
1965
+ mappings:
1966
+ ${r}`;
1967
+ }
1968
+ /**
1969
+ * Gets all currently registered BlueIds as a merged object
1970
+ * @returns Merged object containing all BlueIds from all collections
1971
+ */
1972
+ static getAllBlueIds() {
1973
+ const e = {};
1974
+ for (const t of this.blueIdsCollections)
1975
+ Object.assign(e, t);
1976
+ return e;
1977
+ }
1978
+ /**
1979
+ * Gets the names of all registered BlueIds
1980
+ * @returns Array of all BlueId names
1981
+ */
1982
+ static getAllBlueIdNames() {
1983
+ return Object.keys(this.getAllBlueIds());
1984
+ }
1985
+ /**
1986
+ * Clears all registered BlueIds collections
1987
+ */
1988
+ static clear() {
1989
+ this.blueIdsCollections = [];
1990
+ }
1991
+ /**
1992
+ * Gets the count of registered BlueIds collections
1993
+ * @returns Number of registered collections
1994
+ */
1995
+ static getCollectionCount() {
1996
+ return this.blueIdsCollections.length;
1997
+ }
1998
+ /**
1999
+ * Gets the total count of unique BlueIds across all collections
2000
+ * @returns Number of unique BlueIds
2001
+ */
2002
+ static getTotalBlueIdCount() {
2003
+ return Object.keys(this.getAllBlueIds()).length;
2004
+ }
2005
+ }
2006
+ l(W, "blueIdsCollections", []);
2007
+ const De = class De {
2008
+ /**
2009
+ * Creates a new Preprocessor with the specified provider and NodeProvider or just NodeProvider
2010
+ * @param processorProviderOrNodeProvider - The TransformationProcessorProvider or NodeProvider to use
2011
+ * @param nodeProvider - The NodeProvider to use for resolving nodes (optional)
2012
+ */
2013
+ constructor(e, t) {
2014
+ l(this, "processorProvider");
2015
+ l(this, "nodeProvider");
2016
+ l(this, "defaultSimpleBlue", null);
2017
+ t ? (this.processorProvider = e, this.nodeProvider = pe.wrap(t)) : (this.processorProvider = De.getStandardProvider(), this.nodeProvider = pe.wrap(
2018
+ e
2019
+ )), W.initialize(b, j), this.loadDefaultSimpleBlue();
2020
+ }
2021
+ /**
2022
+ * Registers additional BlueIds collections for dynamic mapping generation
2023
+ * @param blueIdsCollections - Array of BlueIds objects to register
2024
+ */
2025
+ static registerBlueIds(...e) {
2026
+ W.registerBlueIds(...e);
2027
+ }
2028
+ /**
2029
+ * Resets BlueIds collections to defaults (core and myos only)
2030
+ */
2031
+ static resetBlueIdsToDefaults() {
2032
+ W.clear(), W.initialize(b, j);
2033
+ }
2034
+ /**
2035
+ * Gets all currently registered BlueIds
2036
+ * @returns Merged object containing all BlueIds from all collections
2037
+ */
2038
+ static getAllRegisteredBlueIds() {
2039
+ return W.getAllBlueIds();
2040
+ }
2041
+ /**
2042
+ * Preprocesses a document node
2043
+ * @param document - The document node to preprocess
2044
+ * @returns The preprocessed document
2045
+ */
2046
+ preprocess(e) {
2047
+ return this.preprocessWithOptions(e, null);
2048
+ }
2049
+ /**
2050
+ * Preprocesses a document node using the default Blue node
2051
+ * @param document - The document node to preprocess
2052
+ * @returns The preprocessed document
2053
+ */
2054
+ preprocessWithDefaultBlue(e) {
2055
+ return this.preprocessWithOptions(e, this.defaultSimpleBlue);
2056
+ }
2057
+ /**
2058
+ * Preprocesses a document node with the specified default Blue node
2059
+ * @param document - The document node to preprocess
2060
+ * @param defaultBlue - The default Blue node to use if the document doesn't have one
2061
+ * @returns The preprocessed document
2062
+ */
2063
+ preprocessWithOptions(e, t) {
2064
+ let r = e.clone(), s = r.getBlue();
2065
+ if (!s && t && (s = t.clone()), s) {
2066
+ new Rr(this.nodeProvider).extend(
2067
+ s,
2068
+ Gt.withSinglePath("/*")
2069
+ );
2070
+ const o = s.getItems();
2071
+ if (o && o.length > 0) {
2072
+ for (const i of o) {
2073
+ const a = this.processorProvider.getProcessor(i);
2074
+ if (a)
2075
+ r = a.process(r);
2076
+ else
2077
+ throw new Error(
2078
+ `No processor found for transformation: ${i}`
2079
+ );
2080
+ }
2081
+ r.setBlue(void 0);
2082
+ }
2083
+ }
2084
+ return r;
2085
+ }
2086
+ /**
2087
+ * Gets the standard transformation processor provider
2088
+ * @returns The standard provider
2089
+ */
2090
+ static getStandardProvider() {
2091
+ return {
2092
+ getProcessor(e) {
2093
+ var o;
2094
+ const t = "27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo", r = "FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4", s = (o = e.getType()) == null ? void 0 : o.getBlueId();
2095
+ if (t === s)
2096
+ return new Xe(
2097
+ e
2098
+ );
2099
+ if (r === s)
2100
+ return new jr();
2101
+ }
2102
+ };
2103
+ }
2104
+ /**
2105
+ * Enriches the default Blue YAML with dynamic BlueIds mappings
2106
+ * @param defaultBlue - The base default Blue YAML content
2107
+ * @returns Enriched YAML content with dynamic mappings
2108
+ */
2109
+ enrichDefaultBlue(e) {
2110
+ const t = W.generateMappingsYaml();
2111
+ return `
2112
+ ${e}
2113
+ ${t}
2114
+ `;
2115
+ }
2116
+ /**
2117
+ * Loads the default simple Blue node
2118
+ */
2119
+ loadDefaultSimpleBlue() {
2120
+ const e = this.enrichDefaultBlue(Ht);
2121
+ try {
2122
+ const t = de(e);
2123
+ if (t)
2124
+ this.defaultSimpleBlue = T.deserialize(t);
2125
+ else
2126
+ throw new Error("Failed to parse default Blue content");
2127
+ } catch (t) {
2128
+ throw new Error(`Error loading default Blue: ${t}`);
2129
+ }
2130
+ }
2131
+ };
2132
+ l(De, "DEFAULT_BLUE_BLUE_ID", "FREHAAGDZSzpnoTUoCQ86bBmxbVCULMjvx9JZM6fyqT1");
2133
+ let Ae = De;
2134
+ class Qr {
2135
+ /**
2136
+ * Creates a new BlueDirectivePreprocessor
2137
+ *
2138
+ * @param preprocessingAliases - Map of alias values to BlueIds (optional)
2139
+ * @param urlContentFetcher - UrlContentFetcher for fetching URL content
2140
+ */
2141
+ constructor(e, t) {
2142
+ l(this, "preprocessingAliases", /* @__PURE__ */ new Map());
2143
+ l(this, "urlContentFetcher");
2144
+ e && (this.preprocessingAliases = new Map(e)), this.urlContentFetcher = t;
2145
+ }
2146
+ /**
2147
+ * Processes a node's blue directive synchronously
2148
+ *
2149
+ * @param node - The node to process
2150
+ * @returns The node with processed blue directive
2151
+ */
2152
+ process(e) {
2153
+ const t = this.getBlueNodeValue(e);
2154
+ if (t) {
2155
+ const r = e.clone();
2156
+ if (this.preprocessingAliases.has(t))
2157
+ return this.handleAliasValue(r, t);
2158
+ if (K.isPotentialBlueId(t))
2159
+ return this.handleBlueId(r, t);
2160
+ throw ve(t) ? new Error(
2161
+ `URL '${t}' detected. Use the async version of this method to fetch the content.`
2162
+ ) : new Error(`Invalid blue value: ${t}`);
2163
+ }
2164
+ return e;
2165
+ }
2166
+ /**
2167
+ * Processes a node's blue directive asynchronously, with support for URL fetching
2168
+ *
2169
+ * @param node - The node to process
2170
+ * @returns Promise that resolves to the node with processed blue directive
2171
+ */
2172
+ async processAsync(e) {
2173
+ const t = this.getBlueNodeValue(e);
2174
+ if (t) {
2175
+ const r = e.clone();
2176
+ if (this.preprocessingAliases.has(t))
2177
+ return this.handleAliasValue(r, t);
2178
+ if (K.isPotentialBlueId(t))
2179
+ return this.handleBlueId(r, t);
2180
+ if (ve(t) && this.urlContentFetcher)
2181
+ try {
2182
+ const s = await this.fetchFromUrl(t);
2183
+ return s && r.setBlue(new d().setItems(s)), r;
2184
+ } catch (s) {
2185
+ throw s instanceof Error ? new Error(
2186
+ `Failed to fetch from URL '${t}'.
2187
+ ${s.message}`
2188
+ ) : s;
2189
+ }
2190
+ else throw ve(t) ? new Error(
2191
+ `UrlContentFetcher not provided for URL: ${t}`
2192
+ ) : new Error(`Invalid blue value: ${t}`);
2193
+ }
2194
+ return e;
2195
+ }
2196
+ /**
2197
+ * Gets the blue node value if it exists and is a string
2198
+ * @param node - The node to get the blue value from
2199
+ * @returns The blue node value or null if it doesn't exist or isn't a string
2200
+ */
2201
+ getBlueNodeValue(e) {
2202
+ const t = e.getBlue(), r = t == null ? void 0 : t.getValue();
2203
+ return r && typeof r == "string" ? r : null;
2204
+ }
2205
+ /**
2206
+ * Handles a blue value that is an alias
2207
+ * @param node - The cloned node to modify
2208
+ * @param value - The alias value
2209
+ * @returns The modified node
2210
+ */
2211
+ handleAliasValue(e, t) {
2212
+ return e.setBlue(
2213
+ new d().setBlueId(this.preprocessingAliases.get(t))
2214
+ ), e;
2215
+ }
2216
+ /**
2217
+ * Handles a blue value that is a potential BlueId
2218
+ * @param node - The cloned node to modify
2219
+ * @param value - The BlueId value
2220
+ * @returns The modified node
2221
+ */
2222
+ handleBlueId(e, t) {
2223
+ return e.setBlue(new d().setBlueId(t)), e;
2224
+ }
2225
+ /**
2226
+ * Fetches content from a URL
2227
+ * @param url - The URL to fetch from
2228
+ * @returns Promise that resolves to the fetched BlueNodes or null if fetch fails
2229
+ */
2230
+ async fetchFromUrl(e) {
2231
+ if (!this.urlContentFetcher)
2232
+ throw new Error(`UrlContentFetcher not provided for URL: ${e}`);
2233
+ return await this.urlContentFetcher.fetchAndCache(e);
2234
+ }
2235
+ /**
2236
+ * Gets the current preprocessing aliases
2237
+ * @returns Map of aliases to BlueIds
2238
+ */
2239
+ getPreprocessingAliases() {
2240
+ return new Map(this.preprocessingAliases);
2241
+ }
2242
+ /**
2243
+ * Sets the preprocessing aliases
2244
+ * @param aliases - Map of aliases to set
2245
+ * @returns this instance for chaining
2246
+ */
2247
+ setPreprocessingAliases(e) {
2248
+ return this.preprocessingAliases = new Map(e), this;
2249
+ }
2250
+ /**
2251
+ * Adds preprocessing aliases to the map
2252
+ * @param aliases - Map of aliases to add
2253
+ * @returns this instance for chaining
2254
+ */
2255
+ addPreprocessingAliases(e) {
2256
+ return e.forEach((t, r) => {
2257
+ this.preprocessingAliases.set(r, t);
2258
+ }), this;
2259
+ }
2260
+ /**
2261
+ * Updates the URL content fetcher
2262
+ * @param urlContentFetcher - The UrlContentFetcher to use
2263
+ * @returns this instance for chaining
2264
+ */
2265
+ setUrlContentFetcher(e) {
2266
+ return this.urlContentFetcher = e, this;
2267
+ }
2268
+ /**
2269
+ * Gets the current URL content fetcher
2270
+ * @returns The current UrlContentFetcher or undefined
2271
+ */
2272
+ getUrlContentFetcher() {
2273
+ return this.urlContentFetcher;
2274
+ }
2275
+ }
2276
+ const Gr = {
2277
+ fetchUrl: async (n) => {
2278
+ throw new Error(
2279
+ `You must provide a custom UrlFetchStrategy to fetch content from URL: ${n}`
2280
+ );
2281
+ }
2282
+ };
2283
+ class Xr {
2284
+ constructor(e) {
2285
+ // Cache to avoid repeated network requests for the same URL
2286
+ l(this, "cache", /* @__PURE__ */ new Map());
2287
+ l(this, "fetchStrategy");
2288
+ l(this, "enabled", !1);
2289
+ l(this, "allowedDomains", []);
2290
+ this.fetchStrategy = e || Gr;
2291
+ }
2292
+ validateUrl(e) {
2293
+ if (!ve(e))
2294
+ throw new Error(`Invalid URL: ${e}`);
2295
+ return !0;
2296
+ }
2297
+ isDomainAllowed(e) {
2298
+ if (this.allowedDomains.length === 0)
2299
+ return !0;
2300
+ try {
2301
+ const t = new URL(e);
2302
+ return this.allowedDomains.some(
2303
+ (r) => t.hostname === r || t.hostname.endsWith(`.${r}`)
2304
+ );
2305
+ } catch {
2306
+ return !1;
2307
+ }
2308
+ }
2309
+ getFromCache(e) {
2310
+ try {
2311
+ return this.validateUrl(e), this.cache.get(e) || [];
2312
+ } catch {
2313
+ return [];
2314
+ }
2315
+ }
2316
+ async fetchAndCache(e) {
2317
+ if (this.validateUrl(e), !this.enabled)
2318
+ throw new Error(
2319
+ "URL fetching is disabled. Enable it using the enableFetching method."
2320
+ );
2321
+ if (!this.isDomainAllowed(e))
2322
+ throw new Error(`Domain not allowed for URL: ${e}.`);
2323
+ let t;
2324
+ try {
2325
+ t = await this.fetchStrategy.fetchUrl(e);
2326
+ } catch (a) {
2327
+ throw new Error(`Error fetching from URL: ${e}`, { cause: a });
2328
+ }
2329
+ const { data: r, contentType: s } = t;
2330
+ let o;
2331
+ if (s.includes("application/json") || s.includes("text/yaml") || s.includes("application/yaml") || s.includes("text/plain"))
2332
+ o = de(r);
2333
+ else
2334
+ throw new Error(`Unsupported content type from URL: ${s}`);
2335
+ if (o === void 0)
2336
+ throw new Error(`Failed to parse content from URL: ${e}`);
2337
+ let i;
2338
+ return Array.isArray(o) ? i = o.map((a) => T.deserialize(a)) : i = [T.deserialize(o)], this.cache.set(e, i), i;
2339
+ }
2340
+ prefetchUrl(e, t) {
2341
+ try {
2342
+ this.validateUrl(e), this.cache.set(e, t);
2343
+ } catch {
2344
+ }
2345
+ }
2346
+ clearCache() {
2347
+ this.cache.clear();
2348
+ }
2349
+ setFetchStrategy(e) {
2350
+ return this.fetchStrategy = e, this;
2351
+ }
2352
+ getFetchStrategy() {
2353
+ return this.fetchStrategy;
2354
+ }
2355
+ /**
2356
+ * Enables fetching for all URLs
2357
+ * @returns This instance for chaining
2358
+ */
2359
+ enableFetching() {
2360
+ return this.enabled = !0, this.allowedDomains = [], this;
2361
+ }
2362
+ /**
2363
+ * Enables fetching for specific domains only
2364
+ * @param domains Array of allowed domains
2365
+ * @returns This instance for chaining
2366
+ */
2367
+ enableFetchingForDomains(e) {
2368
+ return this.enabled = !0, this.allowedDomains = [...e], this;
2369
+ }
2370
+ /**
2371
+ * Disables all URL fetching
2372
+ * @returns This instance for chaining
2373
+ */
2374
+ disableFetching() {
2375
+ return this.enabled = !1, this;
2376
+ }
2377
+ isFetchingEnabled() {
2378
+ return this.enabled;
2379
+ }
2380
+ /**
2381
+ * Gets the list of allowed domains
2382
+ * An empty list means all domains are allowed when fetching is enabled
2383
+ * @returns Array of allowed domains
2384
+ */
2385
+ getAllowedDomains() {
2386
+ return [...this.allowedDomains];
2387
+ }
2388
+ /**
2389
+ * Adds a domain to the allowed domains list
2390
+ * @param domain Domain to allow
2391
+ * @returns This instance for chaining
2392
+ */
2393
+ allowDomain(e) {
2394
+ return this.allowedDomains.includes(e) || this.allowedDomains.push(e), this;
2395
+ }
2396
+ /**
2397
+ * Removes a domain from the allowed domains list
2398
+ * @param domain Domain to disallow
2399
+ * @returns This instance for chaining
2400
+ */
2401
+ disallowDomain(e) {
2402
+ return this.allowedDomains = this.allowedDomains.filter((t) => t !== e), this;
2403
+ }
2404
+ /**
2405
+ * Clears all allowed domains, meaning all domains will be allowed when fetching is enabled
2406
+ * @returns This instance for chaining
2407
+ */
2408
+ clearAllowedDomains() {
2409
+ return this.allowedDomains = [], this;
2410
+ }
2411
+ }
2412
+ const es = (n, e) => ({
2413
+ on: (t, r) => ({ end: () => r(null) })
2414
+ });
2415
+ async function ts(n) {
2416
+ return new Promise((e, t) => {
2417
+ es().on("error", t).end();
2418
+ });
2419
+ }
2420
+ const U = (...n) => n.map((e, t) => {
2421
+ if (typeof e != "string") return "";
2422
+ if (t === 0 && e === "/") return "/";
2423
+ const r = t > 0 ? e.replace(/^\/+/, "") : e;
2424
+ return t < n.length - 1 ? r.replace(/\/+$/, "") : r;
2425
+ }).filter(Boolean).join("/").replace(/\/{2,}/g, "/");
2426
+ class en {
2427
+ constructor(e, t, r, s) {
2428
+ l(this, "actions", []);
2429
+ this.getDocument = e, this.taskInfo = t, this.blue = r, this.onFlush = s;
2430
+ }
2431
+ get(e) {
2432
+ const t = this.getDocument(), r = U(this.taskInfo.nodePath, e);
2433
+ return t.get(r);
2434
+ }
2435
+ addPatch(e) {
2436
+ this.actions.push({
2437
+ kind: "patch",
2438
+ patch: {
2439
+ ...e,
2440
+ path: U(this.taskInfo.nodePath, e.path)
2441
+ }
2442
+ });
2443
+ }
2444
+ emitEvent(e) {
2445
+ const t = this.taskInfo.event, r = t.trace ?? [], s = {
2446
+ ...e,
2447
+ originNodePath: e.originNodePath ?? this.taskInfo.nodePath,
2448
+ rootEvent: e.rootEvent ?? t.rootEvent ?? t,
2449
+ trace: [...r]
2450
+ };
2451
+ this.actions.push({ kind: "event", event: s });
2452
+ }
2453
+ async flush() {
2454
+ var t;
2455
+ if (!this.actions.length) return [];
2456
+ const e = [...this.actions];
2457
+ return this.actions.length = 0, await ((t = this.onFlush) == null ? void 0 : t.call(this, e)), e;
2458
+ }
2459
+ getNodePath() {
2460
+ return this.taskInfo.nodePath;
2461
+ }
2462
+ resolvePath(e) {
2463
+ return U(this.taskInfo.nodePath, e);
2464
+ }
2465
+ getTaskInfo() {
2466
+ return this.taskInfo;
2467
+ }
2468
+ getBlue() {
2469
+ return this.blue;
2470
+ }
2471
+ /* TODO: Move to a separate interface */
2472
+ loadExternalModule(e) {
2473
+ if (!/^https?:\/\//.test(e))
2474
+ throw new Error("Only http/https URLs are allowed");
2475
+ return ts();
2476
+ }
2477
+ loadBlueContent(e) {
2478
+ throw new Error("Not implemented");
2479
+ }
2480
+ }
2481
+ class tn extends Error {
2482
+ constructor(e, t) {
2483
+ super(`Cannot apply patch ${JSON.stringify(e)}`), this.patch = e, this.cause = t, this.name = "PatchApplicationError";
2484
+ }
2485
+ }
2486
+ class nn extends Error {
2487
+ constructor(e, t, r) {
2488
+ super(
2489
+ `Patch ${JSON.stringify(e)} touches "${e.op === "move" || e.op === "copy" ? `${e.from} → ${e.path}` : e.path}" which is inside embedded document "${t}" (Process Embedded @ "${r}")`
2490
+ ), this.patch = e, this.offendingPath = t, this.contractNodePath = r, this.name = "EmbeddedDocumentModificationError";
2491
+ }
2492
+ }
2493
+ class Pt extends Error {
2494
+ constructor(e, t) {
2495
+ super(`Failed to evaluate expression "${e}"`), this.code = e, this.cause = t, this.name = "ExpressionEvaluationError";
2496
+ }
2497
+ }
2498
+ class Bt extends Error {
2499
+ constructor(e, t) {
2500
+ super(`Failed to evaluate code block "${e}"`), this.code = e, this.cause = t, this.name = "CodeBlockEvaluationError";
2501
+ }
2502
+ }
2503
+ class q {
2504
+ static isTypeOf(e, t) {
2505
+ var o;
2506
+ const r = Re.resolveBlueId(t), s = (o = e.getType()) == null ? void 0 : o.getBlueId();
2507
+ return D(r) || D(s) ? !1 : r === s;
2508
+ }
2509
+ }
2510
+ const L = (n) => !!n && typeof n == "object" && !Array.isArray(n) && !(n instanceof d), M = (n) => n instanceof N || n instanceof k, ns = (n) => n.replace(/~1/g, "/").replace(/~0/g, "~");
2511
+ function re(n) {
2512
+ if (n === "/") return [];
2513
+ if (!n.startsWith("/"))
2514
+ throw new Error(`Path must start with '/': ${n}`);
2515
+ return n.split("/").slice(1).map(ns);
2516
+ }
2517
+ function te(n) {
2518
+ if (n === "-") return -1;
2519
+ const e = typeof n == "number" ? n : parseInt(n, 10);
2520
+ if (isNaN(e))
2521
+ throw new Error(`Invalid array index (NaN) from '${n}'`);
2522
+ if (!Number.isFinite(e))
2523
+ throw new Error(
2524
+ `Invalid array index '${n}' results in non-finite number ${e}`
2525
+ );
2526
+ return e;
2527
+ }
2528
+ function rn(n, e, t, r = !0) {
2529
+ switch (e) {
2530
+ case "name":
2531
+ return t ? r ? n.getName() ?? null : n : n.getName();
2532
+ case "description":
2533
+ return t ? r ? n.getDescription() : n : n.getDescription();
2534
+ case "type":
2535
+ return n.getType();
2536
+ case "itemType":
2537
+ return n.getItemType();
2538
+ case "keyType":
2539
+ return n.getKeyType();
2540
+ case "valueType":
2541
+ return n.getValueType();
2542
+ case "value":
2543
+ return t ? r ? n.getValue() ?? null : n : n.getValue();
2544
+ case "blueId":
2545
+ return t ? r ? n.getBlueId() ?? null : n : n.getBlueId();
2546
+ case "blue":
2547
+ return n.getBlue();
2548
+ case "items":
2549
+ return n.getItems();
2550
+ case "properties":
2551
+ return n.getProperties();
2552
+ case "contracts":
2553
+ return n.getContracts();
2554
+ default:
2555
+ return;
2556
+ }
2557
+ }
2558
+ function Ct(n, e, t = !0) {
2559
+ if (n instanceof d) {
2560
+ const r = rn(
2561
+ n,
2562
+ e,
2563
+ !0,
2564
+ t
2565
+ );
2566
+ if (r !== void 0 || [
2567
+ "name",
2568
+ "description",
2569
+ "type",
2570
+ "itemType",
2571
+ "keyType",
2572
+ "valueType",
2573
+ "value",
2574
+ "blueId",
2575
+ "blue",
2576
+ "items",
2577
+ "properties",
2578
+ "contracts"
2579
+ ].includes(e))
2580
+ return r;
2581
+ if (/^-?\d+$/.test(e) && e !== "-") {
2582
+ const o = n.getItems(), i = parseInt(e, 10);
2583
+ return o && i >= 0 && i < o.length ? o[i] : void 0;
2584
+ }
2585
+ const s = n.getProperties();
2586
+ return s && e in s ? s[e] : void 0;
2587
+ }
2588
+ if (Array.isArray(n)) {
2589
+ if (e === "-") return;
2590
+ const r = te(e);
2591
+ return r >= 0 && r < n.length ? n[r] : void 0;
2592
+ }
2593
+ if (L(n)) return n[e];
2594
+ }
2595
+ function se(n, e) {
2596
+ if (e.length === 0)
2597
+ return {
2598
+ parent: n,
2599
+ key: "value",
2600
+ actualTarget: n.getValue() ?? n
2601
+ };
2602
+ let t = n;
2603
+ for (let s = 0; s < e.length - 1; ++s) {
2604
+ const o = e[s], i = Ct(t, o);
2605
+ if (i === void 0)
2606
+ throw new Error(`Cannot resolve '/${e.slice(0, s + 1).join("/")}'`);
2607
+ t = i;
2608
+ }
2609
+ const r = e[e.length - 1];
2610
+ if (t instanceof d) {
2611
+ const s = Ct(t, r, !1);
2612
+ if ((typeof s != "object" || s === null || M(s)) && !(s instanceof d) && !Array.isArray(s) && ["name", "description", "value", "blueId"].includes(r))
2613
+ return {
2614
+ parent: t,
2615
+ key: r,
2616
+ actualTarget: s
2617
+ };
2618
+ }
2619
+ return Array.isArray(t) && r === "-" ? { parent: t, key: "-" } : t instanceof d && t.getItems() && r === "-" ? { parent: t, key: "-" } : {
2620
+ parent: t,
2621
+ key: Array.isArray(t) ? te(r) : r
2622
+ };
2623
+ }
2624
+ function dt(n, e) {
2625
+ var t;
2626
+ if (n instanceof d) {
2627
+ const r = e, s = rn(n, r, !1);
2628
+ if (s !== void 0 || [
2629
+ "name",
2630
+ "description",
2631
+ "type",
2632
+ "itemType",
2633
+ "keyType",
2634
+ "valueType",
2635
+ "value",
2636
+ "blueId",
2637
+ "blue",
2638
+ "items",
2639
+ "properties",
2640
+ "contracts"
2641
+ ].includes(r))
2642
+ return s;
2643
+ if (typeof e == "number" || typeof e == "string" && /^\d+$/.test(e)) {
2644
+ const o = n.getItems(), i = typeof e == "number" ? e : parseInt(e, 10);
2645
+ if (o && i >= 0 && i < o.length) return o[i];
2646
+ }
2647
+ return (t = n.getProperties()) == null ? void 0 : t[r];
2648
+ }
2649
+ return Array.isArray(n) || L(n) ? n[e] : n;
2650
+ }
2651
+ function C(n) {
2652
+ if (n instanceof d) return n;
2653
+ if (n === null || typeof n == "string" || typeof n == "number" || typeof n == "boolean" || M(n))
2654
+ return T.deserialize(n);
2655
+ const e = nt(n);
2656
+ return T.deserialize(e);
2657
+ }
2658
+ function nt(n) {
2659
+ if (n === void 0) return null;
2660
+ if (n === null || typeof n != "object") return n;
2661
+ if (Array.isArray(n)) return n.map(nt);
2662
+ const e = {};
2663
+ for (const [t, r] of Object.entries(n))
2664
+ e[t] = nt(r);
2665
+ return e;
2666
+ }
2667
+ function pt(n, e, t) {
2668
+ if (n instanceof d) {
2669
+ const r = e;
2670
+ switch (r) {
2671
+ case "name":
2672
+ n.setName(t);
2673
+ return;
2674
+ case "description":
2675
+ n.setDescription(t);
2676
+ return;
2677
+ case "type":
2678
+ n.setType(
2679
+ t instanceof d || typeof t == "string" || t === void 0 ? t : C(t)
2680
+ );
2681
+ return;
2682
+ case "itemType":
2683
+ n.setItemType(
2684
+ t instanceof d || typeof t == "string" || t === void 0 ? t : C(t)
2685
+ );
2686
+ return;
2687
+ case "keyType":
2688
+ n.setKeyType(
2689
+ t instanceof d || typeof t == "string" || t === void 0 ? t : C(t)
2690
+ );
2691
+ return;
2692
+ case "valueType":
2693
+ n.setValueType(
2694
+ t instanceof d || typeof t == "string" || t === void 0 ? t : C(t)
2695
+ );
2696
+ return;
2697
+ case "value": {
2698
+ const s = t;
2699
+ n.setValue(s === void 0 ? null : s);
2700
+ return;
2701
+ }
2702
+ case "blueId":
2703
+ n.setBlueId(t);
2704
+ return;
2705
+ case "blue":
2706
+ n.setBlue(
2707
+ t instanceof d || t === void 0 ? t : C(t)
2708
+ );
2709
+ return;
2710
+ case "items":
2711
+ n.setItems(t);
2712
+ return;
2713
+ case "properties":
2714
+ n.setProperties(t);
2715
+ return;
2716
+ case "contracts":
2717
+ n.setContracts(t);
2718
+ return;
2719
+ default: {
2720
+ if (t === void 0) {
2721
+ const s = n.getProperties();
2722
+ s && r in s && delete s[r];
2723
+ } else
2724
+ n.getProperties() || n.setProperties({}), n.addProperty(r, t instanceof d ? t : C(t));
2725
+ return;
2726
+ }
2727
+ }
2728
+ }
2729
+ Array.isArray(n) ? n.splice(te(e), 1) : L(n) && (t === void 0 ? delete n[e] : n[e] = t);
2730
+ }
2731
+ function rs(n, e, t, r) {
2732
+ let s = -1;
2733
+ if (e !== "-" && (s = typeof e == "number" ? e : parseInt(e, 10), isNaN(s)))
2734
+ throw new Error(
2735
+ `Invalid numeric key for BlueNode item operation: ${e}`
2736
+ );
2737
+ if (s < -1)
2738
+ throw new Error(`Invalid array index for BlueNode items: ${s}`);
2739
+ let o = n.getItems();
2740
+ if (o || (o = [], n.setItems(o)), !r && s !== -1 && s > o.length)
2741
+ throw new Error(
2742
+ `ADD operation failed: Target array index '${s}' is greater than array length ${o.length}.`
2743
+ );
2744
+ if (e === "-")
2745
+ o.push(t);
2746
+ else if (r) {
2747
+ if (s >= 0)
2748
+ if (s < o.length) o[s] = t;
2749
+ else {
2750
+ for (let i = o.length; i < s; i++)
2751
+ o.push(T.deserialize(null));
2752
+ o.push(t);
2753
+ }
2754
+ } else
2755
+ o.splice(s, 0, t);
2756
+ }
2757
+ function Oe(n, e, t, r) {
2758
+ if (Array.isArray(n)) {
2759
+ const s = e === "-" ? n.length : te(e);
2760
+ if (!r && s > n.length)
2761
+ throw new Error(
2762
+ `ADD operation failed: Target array index '${s}' is greater than array length ${n.length}. Path involving key '${e}'.`
2763
+ );
2764
+ if (s < 0 && e !== "-")
2765
+ throw new Error(`Invalid negative array index: ${e}`);
2766
+ const o = C(t);
2767
+ if (r) {
2768
+ if (s >= 0 && s < n.length) n[s] = o;
2769
+ else if (s >= n.length) {
2770
+ for (let i = n.length; i < s; i++)
2771
+ n.push(T.deserialize(null));
2772
+ n.push(o);
2773
+ }
2774
+ } else
2775
+ n.splice(s, 0, o);
2776
+ return;
2777
+ }
2778
+ if (n instanceof d) {
2779
+ e === "-" || typeof e == "number" && !isNaN(e) || typeof e == "string" && /^\d+$/.test(e) ? rs(n, e, C(t), r) : pt(n, e, t);
2780
+ return;
2781
+ }
2782
+ if (L(n)) {
2783
+ n[e] = C(t);
2784
+ return;
2785
+ }
2786
+ throw new Error(`Cannot insert into parent of type ${typeof n}`);
2787
+ }
2788
+ function ss(n, e) {
2789
+ if (Array.isArray(n)) {
2790
+ const t = te(e);
2791
+ t === -1 && e === "-" ? n.length > 0 && n.pop() : t >= 0 && t < n.length && n.splice(t, 1);
2792
+ return;
2793
+ }
2794
+ if (n instanceof d) {
2795
+ if (typeof e == "number" || typeof e == "string" && /^-?\d+$/.test(e)) {
2796
+ const t = n.getItems();
2797
+ if (t) {
2798
+ const r = te(e);
2799
+ r === -1 && e === "-" ? t.length > 0 && t.pop() : r >= 0 && r < t.length && t.splice(r, 1), t.length === 0 && n.setItems(void 0);
2800
+ return;
2801
+ }
2802
+ }
2803
+ pt(n, e, void 0);
2804
+ } else L(n) && delete n[e];
2805
+ }
2806
+ function rt(n) {
2807
+ if (n instanceof d) return n.clone();
2808
+ if (Array.isArray(n))
2809
+ return n.map((t) => rt(t));
2810
+ if (L(n)) {
2811
+ const e = {};
2812
+ return Object.keys(n).forEach((t) => {
2813
+ e[t] = rt(n[t]);
2814
+ }), e;
2815
+ }
2816
+ return n;
2817
+ }
2818
+ function J(n, e) {
2819
+ if (n === e || n instanceof d && (n.isInlineValue() || n.getValue() !== void 0) && J(n.getValue() ?? null, e) || e instanceof d && (e.isInlineValue() || e.getValue() !== void 0) && J(n, e.getValue() ?? null))
2820
+ return !0;
2821
+ if (n instanceof d && e instanceof d || M(n) && M(e) || M(n) && typeof e == "number" || typeof n == "number" && M(e))
2822
+ return n.toString() === e.toString();
2823
+ if (Array.isArray(n) && Array.isArray(e))
2824
+ return n.length === e.length && n.every((t, r) => J(t, e[r]));
2825
+ if (L(n) && L(e)) {
2826
+ const t = Object.keys(n), r = Object.keys(e);
2827
+ return t.length === r.length && t.every((s) => J(n[s], e[s]));
2828
+ }
2829
+ return !1;
2830
+ }
2831
+ function sn(n, e) {
2832
+ const { parent: t, key: r } = se(n, re(e));
2833
+ return dt(t, r);
2834
+ }
2835
+ function on(n, e, t) {
2836
+ const r = re(e);
2837
+ if (r.length === 0 && e === "/") {
2838
+ const i = C(t);
2839
+ n.setValue(i.getValue() ?? null), i.getItems() ? n.setItems(i.getItems()) : n.setItems(void 0);
2840
+ return;
2841
+ }
2842
+ const { parent: s, key: o } = se(n, r);
2843
+ Oe(s, o, t, !0);
2844
+ }
2845
+ function os(n, e, t) {
2846
+ const r = re(e);
2847
+ if (r.length === 0 && e === "/") {
2848
+ if (n.getItems() && Array.isArray(t)) {
2849
+ const i = C(t);
2850
+ i.getItems() ? (n.setItems(i.getItems()), n.setValue(null)) : (n.setValue(i.getValue() ?? null), n.setItems(void 0));
2851
+ } else {
2852
+ const i = C(t);
2853
+ n.setValue(i.getValue() ?? null), i.getItems() && n.setItems(i.getItems());
2854
+ }
2855
+ return !0;
2856
+ }
2857
+ const { parent: s, key: o } = se(n, r);
2858
+ return Oe(s, o, t, !1), !0;
2859
+ }
2860
+ function is(n, e, t) {
2861
+ const r = re(e);
2862
+ if (r.length === 0 && e === "/") {
2863
+ const a = C(t);
2864
+ return n.setValue(a.getValue() ?? null), a.getItems() ? n.setItems(a.getItems()) : n.setItems(void 0), !0;
2865
+ }
2866
+ const { parent: s, key: o, actualTarget: i } = se(n, r);
2867
+ if (i !== void 0 && s instanceof d)
2868
+ pt(s, o, t);
2869
+ else {
2870
+ const a = dt(s, o), c = Array.isArray(s) || s instanceof d && s.getItems() && (typeof o == "number" || typeof o == "string" && /^\d+$/.test(o));
2871
+ if (a === void 0) {
2872
+ if (c)
2873
+ throw new Error(
2874
+ `REPLACE failed: Target array index '${o.toString()}' is out of bounds or does not exist at path '${e}'.`
2875
+ );
2876
+ Oe(s, o, t, !0);
2877
+ } else
2878
+ Oe(s, o, t, !0);
2879
+ }
2880
+ return !0;
2881
+ }
2882
+ function an(n, e) {
2883
+ const t = re(e);
2884
+ if (t.length === 0 && e === "/")
2885
+ return n.setValue(null), n.setItems(void 0), n.setProperties(void 0), !0;
2886
+ const { parent: r, key: s } = se(n, t);
2887
+ return ss(r, s), !0;
2888
+ }
2889
+ function as(n, e, t) {
2890
+ const r = rt(sn(n, e));
2891
+ return on(n, t, r), !0;
2892
+ }
2893
+ function cs(n, e, t) {
2894
+ const r = re(e), { parent: s, key: o } = se(n, r), i = dt(s, o);
2895
+ if (i === void 0)
2896
+ throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);
2897
+ return an(n, e) ? (on(n, t, i), !0) : !1;
2898
+ }
2899
+ function ls(n, e, t) {
2900
+ const r = sn(n, e);
2901
+ let s = t;
2902
+ if (r instanceof d)
2903
+ if ((t === null || typeof t == "string" || typeof t == "number" || typeof t == "boolean" || M(t)) && (r.isInlineValue() || r.getValue() !== void 0)) {
2904
+ if (!J(r.getValue() ?? null, t))
2905
+ throw new Error(
2906
+ `TEST failed at '${e}': Expected ${JSON.stringify(
2907
+ t
2908
+ )}, got ${JSON.stringify(r.getValue() ?? null)}`
2909
+ );
2910
+ return !0;
2911
+ } else typeof t == "object" && !(t instanceof d) && (s = C(t));
2912
+ else if (M(r) && typeof t == "number")
2913
+ r instanceof N ? s = new N(t.toString()) : r instanceof k && (s = new k(t.toString()));
2914
+ else if ((r === null || typeof r == "string" || typeof r == "number" || typeof r == "boolean") && M(t)) {
2915
+ const o = t;
2916
+ !J(r, o.toString()) && (typeof r == "number" && parseFloat(o.toString()));
2917
+ }
2918
+ if (!J(r, s)) {
2919
+ const o = r instanceof d ? r.toString() : JSON.stringify(r), i = s instanceof d ? s.toString() : JSON.stringify(s);
2920
+ throw new Error(
2921
+ `TEST failed at '${e}': Expected ${i}, got ${o}`
2922
+ );
2923
+ }
2924
+ return !0;
2925
+ }
2926
+ function us(n, e) {
2927
+ switch (e.op) {
2928
+ case "add":
2929
+ return os(n, e.path, e.val);
2930
+ case "replace":
2931
+ return is(n, e.path, e.val);
2932
+ case "remove":
2933
+ return an(n, e.path);
2934
+ case "copy":
2935
+ return as(n, e.from, e.path);
2936
+ case "move":
2937
+ return cs(n, e.from, e.path);
2938
+ case "test":
2939
+ return ls(n, e.path, e.val);
2940
+ }
2941
+ }
2942
+ function hs(n, e, t = !1) {
2943
+ const r = t ? n : n.clone();
2944
+ return us(r, e), r;
2945
+ }
2946
+ function ft(n) {
2947
+ if (Object.isFrozen(n))
2948
+ return n;
2949
+ Object.freeze(n);
2950
+ for (const e of Object.getOwnPropertyNames(n)) {
2951
+ const t = n[e];
2952
+ y(t) && typeof t == "object" && ft(t);
2953
+ }
2954
+ return n;
2955
+ }
2956
+ const ds = new Yt();
2957
+ function yt(n, e = "/", t = []) {
2958
+ const r = n.getContracts() ?? {};
2959
+ for (const [s, o] of Object.entries(r))
2960
+ if (q.isTypeOf(
2961
+ o,
2962
+ et
2963
+ )) {
2964
+ const c = ds.convert(o, et).paths ?? [];
2965
+ for (const h of c)
2966
+ t.push({
2967
+ absPath: U(e, h),
2968
+ contractPath: U(e, `contracts/${s}`)
2969
+ });
2970
+ }
2971
+ for (const [s, o] of Object.entries(n.getProperties() ?? {}))
2972
+ yt(o, U(e, s), t);
2973
+ return t;
2974
+ }
2975
+ function St(n, e) {
2976
+ return n === e || n.startsWith(e.endsWith("/") ? e : e + "/");
2977
+ }
2978
+ function Nt(n, e) {
2979
+ if (!e.length) return n;
2980
+ let t = n.clone();
2981
+ for (const r of e)
2982
+ try {
2983
+ t = hs(t, r, !0);
2984
+ } catch (s) {
2985
+ throw new tn(r, s);
2986
+ }
2987
+ return ft(t);
2988
+ }
2989
+ function S(n) {
2990
+ return n != null;
2991
+ }
2992
+ function fe(n) {
2993
+ return n instanceof d;
2994
+ }
2995
+ class ps {
2996
+ constructor(e = [], t = (r, s) => r < s ? -1 : r > s ? 1 : 0) {
2997
+ l(this, "data");
2998
+ l(this, "length");
2999
+ l(this, "compare");
3000
+ if (this.data = e, this.length = this.data.length, this.compare = t, this.length > 0)
3001
+ for (let r = (this.length >> 1) - 1; r >= 0; r--) this._down(r);
3002
+ }
3003
+ push(e) {
3004
+ this.data.push(e), this._up(this.length++);
3005
+ }
3006
+ pop() {
3007
+ if (this.length === 0) return;
3008
+ const e = this.data[0], t = this.data.pop();
3009
+ return --this.length > 0 && (this.data[0] = t, this._down(0)), e;
3010
+ }
3011
+ peek() {
3012
+ return this.data[0];
3013
+ }
3014
+ _up(e) {
3015
+ const { data: t, compare: r } = this, s = t[e];
3016
+ for (; e > 0; ) {
3017
+ const o = e - 1 >> 1, i = t[o];
3018
+ if (r(s, i) >= 0) break;
3019
+ t[e] = i, e = o;
3020
+ }
3021
+ t[e] = s;
3022
+ }
3023
+ _down(e) {
3024
+ const { data: t, compare: r } = this, s = this.length >> 1, o = t[e];
3025
+ for (; e < s; ) {
3026
+ let i = (e << 1) + 1;
3027
+ const a = i + 1;
3028
+ if (a < this.length && r(t[a], t[i]) < 0 && (i = a), r(t[i], o) >= 0) break;
3029
+ t[e] = t[i], e = i;
3030
+ }
3031
+ t[e] = o;
3032
+ }
3033
+ }
3034
+ const fs = (n, e, t, r, s, o) => [
3035
+ -n,
3036
+ e,
3037
+ t,
3038
+ r,
3039
+ s,
3040
+ o
3041
+ ], ys = (n, e) => {
3042
+ for (let t = 0; t < n.key.length; t++) {
3043
+ const r = n.key[t], s = e.key[t];
3044
+ if (r !== s)
3045
+ return typeof r == "number" && typeof s == "number" ? r - s : typeof r == "string" && typeof s == "string" ? r.localeCompare(s) : 0;
3046
+ }
3047
+ return 0;
3048
+ };
3049
+ class ms {
3050
+ /**
3051
+ * Creates a new task queue with the task key comparator
3052
+ */
3053
+ constructor() {
3054
+ l(this, "queue");
3055
+ this.queue = new ps([], ys);
3056
+ }
3057
+ /**
3058
+ * Adds a task to the queue
3059
+ *
3060
+ * @param task - The task to add
3061
+ */
3062
+ push(e) {
3063
+ this.queue.push(e);
3064
+ }
3065
+ /**
3066
+ * Removes and returns the highest priority task
3067
+ *
3068
+ * @returns The highest priority task or undefined if queue is empty
3069
+ */
3070
+ pop() {
3071
+ return this.queue.pop();
3072
+ }
3073
+ /**
3074
+ * Gets the number of tasks in the queue
3075
+ */
3076
+ get length() {
3077
+ return this.queue.length;
3078
+ }
3079
+ }
3080
+ class gs {
3081
+ /**
3082
+ * Creates a new contract registry
3083
+ *
3084
+ * @param list - Initial list of processors to register
3085
+ */
3086
+ constructor(e = []) {
3087
+ l(this, "processors", /* @__PURE__ */ new Map());
3088
+ l(this, "typeOrder", /* @__PURE__ */ new Map());
3089
+ e.forEach((t, r) => this.register(t, r));
3090
+ }
3091
+ /**
3092
+ * Registers a new contract processor
3093
+ *
3094
+ * @param proc - The processor to register
3095
+ * @param orderHint - Optional priority value for execution order
3096
+ * @throws Error if a processor for the same contract type is already registered
3097
+ */
3098
+ register(e, t) {
3099
+ if (this.processors.has(e.contractBlueId))
3100
+ throw new Error(`Processor for ${e.contractType} already registered`);
3101
+ this.processors.set(e.contractBlueId, e), this.typeOrder.has(e.contractBlueId) || this.typeOrder.set(e.contractBlueId, t ?? this.typeOrder.size);
3102
+ }
3103
+ /**
3104
+ * Gets a processor by contract type node
3105
+ *
3106
+ * @param typeNode - The contract type node
3107
+ * @returns The associated processor or undefined
3108
+ */
3109
+ get(e) {
3110
+ if (!e) return;
3111
+ const t = e.getBlueId();
3112
+ if (t)
3113
+ return this.processors.get(t);
3114
+ }
3115
+ /**
3116
+ * Gets the order priority for a contract type node
3117
+ *
3118
+ * @param typeNode - The contract type node
3119
+ * @returns The priority value (0 if not found)
3120
+ */
3121
+ orderOf(e) {
3122
+ if (!e) return 0;
3123
+ const t = e.getBlueId();
3124
+ return t ? this.typeOrder.get(t) ?? 0 : 0;
3125
+ }
3126
+ /**
3127
+ * Gets all registered processors
3128
+ *
3129
+ * @returns Iterator of all registered processors
3130
+ */
3131
+ values() {
3132
+ return this.processors.values();
3133
+ }
3134
+ }
3135
+ class ws {
3136
+ constructor() {
3137
+ l(this, "isEnabled");
3138
+ this.isEnabled = process.env.TRACE_BLUE_ENABLED === "true";
3139
+ }
3140
+ /**
3141
+ * Creates a hop entry for the trace
3142
+ * @param nodePath - The path to the node
3143
+ * @param contractName - The name of the contract
3144
+ * @returns A formatted hop string
3145
+ */
3146
+ makeHop(e, t) {
3147
+ return `${e}#${t}`;
3148
+ }
3149
+ /**
3150
+ * Checks if tracing is enabled
3151
+ * @returns Whether tracing is enabled
3152
+ */
3153
+ shouldTrace() {
3154
+ return this.isEnabled;
3155
+ }
3156
+ /**
3157
+ * Adds a hop to the event's trace if tracing is enabled
3158
+ * @param event - The event to add the trace to
3159
+ * @param nodePath - The path to the node
3160
+ * @param contractName - The name of the contract
3161
+ * @returns A new event with the updated trace
3162
+ */
3163
+ addHop(e, t, r) {
3164
+ if (!this.shouldTrace())
3165
+ return { ...e };
3166
+ const s = [
3167
+ ...e.trace ?? [],
3168
+ this.makeHop(t, r)
3169
+ ];
3170
+ return {
3171
+ ...e,
3172
+ trace: s
3173
+ };
3174
+ }
3175
+ /**
3176
+ * Gets the current trace for an event
3177
+ * @param event - The event to get the trace for
3178
+ * @returns The current trace array or an empty array if none exists
3179
+ */
3180
+ getTrace(e) {
3181
+ return e.trace ?? [];
3182
+ }
3183
+ /**
3184
+ * Clears the trace for an event
3185
+ * @param event - The event to clear the trace for
3186
+ * @returns A new event with an empty trace
3187
+ */
3188
+ clearTrace(e) {
3189
+ return {
3190
+ ...e,
3191
+ trace: []
3192
+ };
3193
+ }
3194
+ /**
3195
+ * Checks if tracing is enabled globally
3196
+ * @returns Whether tracing is enabled
3197
+ */
3198
+ isTracingEnabled() {
3199
+ return this.isEnabled;
3200
+ }
3201
+ }
3202
+ const Ts = 64;
3203
+ class bs {
3204
+ /**
3205
+ * Creates a new event router
3206
+ *
3207
+ * @param registry - Contract registry for looking up processors
3208
+ * @param queue - Task queue for scheduling handlers
3209
+ * @param getNextTaskId - Function to get the next task ID
3210
+ * @param getNextEventSeq - Function to get the next event sequence number
3211
+ */
3212
+ constructor(e, t, r, s, o) {
3213
+ l(this, "traceManager");
3214
+ this.blue = e, this.registry = t, this.queue = r, this.getNextTaskId = s, this.getNextEventSeq = o, this.traceManager = new ws();
3215
+ }
3216
+ /**
3217
+ * Routes an event to matching contracts in the document
3218
+ *
3219
+ * @param doc - The document to route events in
3220
+ * @param pathSegments - Path segments to the current node
3221
+ * @param event - The event to route
3222
+ * @param afterTaskId - Minimum task ID to use
3223
+ * @param inlineDepth - Current adapter recursion depth
3224
+ */
3225
+ async route(e, t, r, s, o = 0) {
3226
+ var c;
3227
+ if (r.seq === void 0 && (r.seq = this.getNextEventSeq()), t.length === 0) {
3228
+ if (r.dispatchPath) {
3229
+ const h = r.dispatchPath.split("/").filter(Boolean), p = { ...r };
3230
+ return delete p.dispatchPath, this.route(e, h, p, s, o);
3231
+ }
3232
+ if (r.source === "channel" && r.originNodePath && r.originNodePath !== "/") {
3233
+ const h = ((c = r.originNodePath) == null ? void 0 : c.split("/").filter(Boolean)) ?? [];
3234
+ return this.route(e, h, r, s, o);
3235
+ }
3236
+ }
3237
+ const i = U("/", t.join("/")), a = e.get(i);
3238
+ fe(a) && await this.traverseContracts({
3239
+ doc: e,
3240
+ node: a,
3241
+ nodePath: i,
3242
+ event: r,
3243
+ afterTaskId: s,
3244
+ pathSegments: t,
3245
+ inlineDepth: o
3246
+ });
3247
+ }
3248
+ /**
3249
+ * Traverses contracts at the current node and routes to matching ones
3250
+ */
3251
+ async traverseContracts(e) {
3252
+ const {
3253
+ doc: t,
3254
+ node: r,
3255
+ nodePath: s,
3256
+ event: o,
3257
+ afterTaskId: i,
3258
+ pathSegments: a,
3259
+ inlineDepth: c
3260
+ } = e;
3261
+ if (!this.shouldSkipForChannel(o, s))
3262
+ for (const [h, p] of Object.entries(
3263
+ r.getContracts() ?? {}
3264
+ )) {
3265
+ if (!p.getType()) continue;
3266
+ const g = this.registry.get(p.getType());
3267
+ if (!g) {
3268
+ console.warn(`No processor registered for contract: ${h}`);
3269
+ continue;
3270
+ }
3271
+ const w = {
3272
+ nodePath: s,
3273
+ contractName: h,
3274
+ contractNode: p,
3275
+ event: o
3276
+ }, f = new en(() => t, w, this.blue);
3277
+ if (g.supports(o, p, f, h))
3278
+ switch (g.role) {
3279
+ case "adapter":
3280
+ await this.processAdapter({
3281
+ cp: g,
3282
+ event: o,
3283
+ contractNode: p,
3284
+ ctx: f,
3285
+ contractName: h,
3286
+ doc: t,
3287
+ afterTaskId: i,
3288
+ inlineDepth: c
3289
+ });
3290
+ break;
3291
+ case "handler":
3292
+ this.scheduleHandler({
3293
+ contractNode: p,
3294
+ contractName: h,
3295
+ nodePath: s,
3296
+ event: o,
3297
+ depth: a.length,
3298
+ afterTaskId: i
3299
+ });
3300
+ break;
3301
+ }
3302
+ }
3303
+ }
3304
+ /**
3305
+ * Processes an adapter contract and routes any emitted events
3306
+ */
3307
+ async processAdapter(e) {
3308
+ var m;
3309
+ const {
3310
+ cp: t,
3311
+ event: r,
3312
+ contractNode: s,
3313
+ ctx: o,
3314
+ contractName: i,
3315
+ doc: a,
3316
+ afterTaskId: c,
3317
+ inlineDepth: h
3318
+ } = e;
3319
+ if (h >= Ts)
3320
+ throw new Error("Adapter recursion limit reached");
3321
+ const p = this.traceManager.addHop(
3322
+ r,
3323
+ ((m = o.getTaskInfo()) == null ? void 0 : m.nodePath) ?? "",
3324
+ i
3325
+ );
3326
+ await t.handle(p, s, o, i);
3327
+ const g = await o.flush();
3328
+ if (g.find((E) => E.kind === "patch"))
3329
+ throw new Error(
3330
+ `Contract "${i}" (adapter) attempted to patch the document`
3331
+ );
3332
+ const f = g.filter((E) => E.kind === "event");
3333
+ for (const E of f)
3334
+ await this.route(a, [], E.event, c, h + 1);
3335
+ }
3336
+ /**
3337
+ * Schedules a handler contract for future execution
3338
+ */
3339
+ scheduleHandler(e) {
3340
+ const { contractNode: t, contractName: r, nodePath: s, event: o, depth: i, afterTaskId: a } = e, c = t.getType();
3341
+ if (!c) {
3342
+ console.warn(`Contract node type is not defined for: ${r}`);
3343
+ return;
3344
+ }
3345
+ const h = this.registry.orderOf(c), p = t.get("/order"), g = A(p) ? p.toNumber() : 0, w = this.getNextTaskId() + a, f = fs(
3346
+ i,
3347
+ o.seq,
3348
+ h,
3349
+ g,
3350
+ r,
3351
+ w
3352
+ ), m = this.traceManager.addHop(o, s, r);
3353
+ this.queue.push({
3354
+ key: f,
3355
+ nodePath: s,
3356
+ contractName: r,
3357
+ contractNode: t,
3358
+ event: m
3359
+ });
3360
+ }
3361
+ /**
3362
+ * Checks if an event should be skipped because it came from another channel node
3363
+ */
3364
+ shouldSkipForChannel(e, t) {
3365
+ return e.source === "channel" && !!e.originNodePath && e.originNodePath !== t;
3366
+ }
3367
+ }
3368
+ const Es = (n, e, t) => {
3369
+ (t instanceof tn || t instanceof nn) && console.error(
3370
+ `[Blue] Failed to apply patches for contract "${n}" on event ${JSON.stringify(e)}`,
3371
+ t
3372
+ );
3373
+ };
3374
+ function At(n) {
3375
+ const e = n.clone(), t = (r) => {
3376
+ var o;
3377
+ if (!fe(r)) return;
3378
+ const s = r.getContracts();
3379
+ s && (!s.checkpoint || ((o = s.checkpoint.getType()) == null ? void 0 : o.getBlueId()) !== b["Channel Event Checkpoint"]) && r.addContract(
3380
+ "checkpoint",
3381
+ T.deserialize({
3382
+ type: {
3383
+ name: "Channel Event Checkpoint",
3384
+ blueId: b["Channel Event Checkpoint"]
3385
+ },
3386
+ lastEvents: {}
3387
+ })
3388
+ );
3389
+ };
3390
+ t(e);
3391
+ for (const { absPath: r } of yt(e)) {
3392
+ const s = e.get(r);
3393
+ fe(s) && t(s);
3394
+ }
3395
+ return ft(e);
3396
+ }
3397
+ class Is {
3398
+ constructor(e) {
3399
+ l(this, "contractType", "Channel Event Checkpoint");
3400
+ l(this, "contractBlueId", b["Channel Event Checkpoint"]);
3401
+ l(this, "role", "handler");
3402
+ this.cache = e;
3403
+ }
3404
+ supports(e) {
3405
+ var t, r;
3406
+ return e.source === "channel" && ((t = e.rootEvent) == null ? void 0 : t.payload) === e.payload && ((r = e.rootEvent) == null ? void 0 : r.source) === "external";
3407
+ }
3408
+ async handle(e, t, r) {
3409
+ var i;
3410
+ if (!e.channelName || !((i = e.rootEvent) != null && i.seq)) return;
3411
+ const s = await r.getBlue().calculateBlueId(e.rootEvent.payload), o = r.getNodePath().replace(/\/contracts\/checkpoint$/, "");
3412
+ this.cache.record(o, e, s);
3413
+ }
3414
+ init() {
3415
+ return [];
3416
+ }
3417
+ }
3418
+ const Ot = (n, e) => n.get(e) !== void 0;
3419
+ class vs {
3420
+ constructor() {
3421
+ l(this, "firstSeen", /* @__PURE__ */ new Map());
3422
+ }
3423
+ record(e, t, r) {
3424
+ const s = e;
3425
+ this.firstSeen.has(s) || this.firstSeen.set(s, { docBase: e, event: t, eventBlueId: r });
3426
+ }
3427
+ /** Turn cached data into JSON-Patch ops */
3428
+ flush(e) {
3429
+ const t = [];
3430
+ for (const { docBase: r, event: s, eventBlueId: o } of this.firstSeen.values()) {
3431
+ if (!s.channelName) continue;
3432
+ const i = U(
3433
+ r,
3434
+ "contracts/checkpoint/lastEvents",
3435
+ s.channelName
3436
+ ), a = `${i}/blueId`;
3437
+ Ot(e, i) ? t.push({
3438
+ op: Ot(e, a) ? "replace" : "add",
3439
+ path: a,
3440
+ val: o
3441
+ }) : t.push({
3442
+ op: "add",
3443
+ path: i,
3444
+ val: { blueId: o }
3445
+ });
3446
+ }
3447
+ return t;
3448
+ }
3449
+ clear() {
3450
+ this.firstSeen.clear();
3451
+ }
3452
+ }
3453
+ class Ps {
3454
+ /**
3455
+ * Creates a new document processor
3456
+ *
3457
+ * @param processors - Initial list of processors to register
3458
+ */
3459
+ constructor(e, t = []) {
3460
+ l(this, "taskCounter", 0);
3461
+ l(this, "eventCounter", 0);
3462
+ l(this, "registry");
3463
+ l(this, "queue");
3464
+ l(this, "router");
3465
+ l(this, "checkpointCache", new vs());
3466
+ this.blue = e, this.registry = new gs(t), this.queue = new ms(), this.router = new bs(
3467
+ this.blue,
3468
+ this.registry,
3469
+ this.queue,
3470
+ () => ++this.taskCounter,
3471
+ () => ++this.eventCounter
3472
+ ), this.register(
3473
+ new Is(this.checkpointCache),
3474
+ 9999
3475
+ );
3476
+ }
3477
+ /**
3478
+ * Registers a new contract processor
3479
+ *
3480
+ * @param cp - The processor to register
3481
+ * @param orderHint - Optional priority value for execution order
3482
+ */
3483
+ register(e, t) {
3484
+ this.registry.register(e, t);
3485
+ }
3486
+ /**
3487
+ * Initializes a document and runs all init events
3488
+ *
3489
+ * @param document - The document to initialize
3490
+ * @returns Processing result with final state and emitted events
3491
+ */
3492
+ async initialise(e) {
3493
+ e = At(e);
3494
+ const t = await this.bootstrapContracts(e);
3495
+ for (const r of t)
3496
+ await this.router.route(e, [], r, 0);
3497
+ return this.drainQueue(e);
3498
+ }
3499
+ /**
3500
+ * Processes a batch of events against the document
3501
+ *
3502
+ * @param document - The document to process events against
3503
+ * @param incoming - List of event payloads to process
3504
+ * @returns Processing result with final state and emitted events
3505
+ */
3506
+ async processEvents(e, t) {
3507
+ let r = At(e);
3508
+ const s = [];
3509
+ for (const o of t)
3510
+ try {
3511
+ const i = { payload: o, source: "external" };
3512
+ await this.router.route(r, [], i, 0);
3513
+ const a = await this.drainQueue(r);
3514
+ r = a.state, s.push(...a.emitted);
3515
+ const c = this.checkpointCache.flush(r);
3516
+ c.length && (r = Nt(r, c));
3517
+ } finally {
3518
+ this.checkpointCache.clear();
3519
+ }
3520
+ return { state: r, emitted: s };
3521
+ }
3522
+ /**
3523
+ * Collects initialization events from contract processors
3524
+ */
3525
+ async bootstrapContracts(e) {
3526
+ const t = [], r = e.getContracts();
3527
+ if (!r)
3528
+ return t;
3529
+ for (const [, s] of Object.entries(r)) {
3530
+ const o = this.registry.get(s.getType());
3531
+ o != null && o.init && t.push(...await o.init(s));
3532
+ }
3533
+ return t;
3534
+ }
3535
+ /**
3536
+ * Drains the task queue and applies all actions
3537
+ */
3538
+ async drainQueue(e) {
3539
+ var i;
3540
+ let t = e;
3541
+ const r = [], s = 1e4;
3542
+ let o = 0;
3543
+ for (; this.queue.length; ) {
3544
+ if (++o > s)
3545
+ throw new Error("Possible cycle – too many iterations");
3546
+ const a = this.queue.pop(), { nodePath: c, contractName: h, contractNode: p, event: g } = a, w = t.get(c);
3547
+ if (!fe(w) || !((i = w.getContracts()) != null && i[h]) || !p.getType()) continue;
3548
+ const f = this.registry.get(p.getType());
3549
+ if (!f) {
3550
+ console.warn(`No processor registered for contract: ${h}`);
3551
+ continue;
3552
+ }
3553
+ const m = new en(
3554
+ () => t,
3555
+ a,
3556
+ this.blue,
3557
+ async (E) => {
3558
+ for (const I of E)
3559
+ if (I.kind === "patch") {
3560
+ const H = yt(t);
3561
+ for (const B of H) {
3562
+ const ie = I.patch.op === "move" || I.patch.op === "copy" ? [I.patch.from, I.patch.path] : [I.patch.path], be = m.getNodePath(), dn = ie.some(
3563
+ (fn) => St(fn, B.absPath)
3564
+ ), pn = St(
3565
+ be,
3566
+ B.absPath
3567
+ );
3568
+ if (dn && !pn)
3569
+ throw new nn(
3570
+ I.patch,
3571
+ B.absPath,
3572
+ be
3573
+ );
3574
+ }
3575
+ try {
3576
+ t = Nt(t, [I.patch]);
3577
+ } catch (B) {
3578
+ throw Es(h, g, B), B;
3579
+ }
3580
+ } else I.kind === "event" && (r.push(I.event.payload), await this.router.route(t, [], I.event, a.key[5]));
3581
+ }
3582
+ );
3583
+ await f.handle(g, p, m, h), await m.flush();
3584
+ }
3585
+ return { state: t, emitted: r };
3586
+ }
3587
+ }
3588
+ class oe {
3589
+ constructor() {
3590
+ l(this, "role", "adapter");
3591
+ }
3592
+ /**
3593
+ * Base implementation of supports that checks if the event is not from a channel
3594
+ * Derived classes should call this method first in their supports implementation
3595
+ */
3596
+ baseSupports(e) {
3597
+ return e.source !== "channel";
3598
+ }
3599
+ /**
3600
+ * Base implementation that returns empty array
3601
+ * Can be overridden by derived classes if needed
3602
+ */
3603
+ init() {
3604
+ return [];
3605
+ }
3606
+ }
3607
+ class Bs extends oe {
3608
+ constructor() {
3609
+ super(...arguments);
3610
+ l(this, "contractType", "Composite Timeline Channel");
3611
+ l(this, "contractBlueId", b["Composite Timeline Channel"]);
3612
+ }
3613
+ supports(t, r, s) {
3614
+ const o = s.getBlue().nodeToSchemaOutput(r, Ur);
3615
+ return !o.channels || !t.channelName ? !1 : o.channels.includes(t.channelName);
3616
+ }
3617
+ handle(t, r, s, o) {
3618
+ s.emitEvent({
3619
+ payload: t.payload,
3620
+ channelName: o,
3621
+ source: "channel"
3622
+ });
3623
+ }
3624
+ }
3625
+ class Cs extends oe {
3626
+ constructor() {
3627
+ super(...arguments);
3628
+ l(this, "contractType", "Document Update Channel");
3629
+ l(this, "contractBlueId", b["Document Update Channel"]);
3630
+ }
3631
+ supports(t, r, s, o) {
3632
+ if (!this.baseSupports(t)) return !1;
3633
+ const i = s.getBlue().nodeToSchemaOutput(r, Zr), a = t.payload.path;
3634
+ if (!a || t.channelName === o) return !1;
3635
+ const c = i.path;
3636
+ return y(c) && a === s.resolvePath(c);
3637
+ }
3638
+ handle(t, r, s, o) {
3639
+ const i = t.payload;
3640
+ i && s.emitEvent({
3641
+ payload: i,
3642
+ channelName: o,
3643
+ source: "channel"
3644
+ });
3645
+ }
3646
+ }
3647
+ class Ss extends oe {
3648
+ constructor() {
3649
+ super(...arguments);
3650
+ l(this, "contractType", "Embedded Node Channel");
3651
+ l(this, "contractBlueId", b["Embedded Node Channel"]);
3652
+ }
3653
+ supports(t, r, s) {
3654
+ if (!this.baseSupports(t)) return !1;
3655
+ const o = s.getBlue().nodeToSchemaOutput(r, vt);
3656
+ return S(t.originNodePath) && S(o.path) && t.originNodePath === s.resolvePath(o.path);
3657
+ }
3658
+ handle(t, r, s, o) {
3659
+ const i = s.getBlue().nodeToSchemaOutput(r, vt), { originNodePath: a, payload: c } = t;
3660
+ S(i.path) && a === s.resolvePath(i.path) && s.emitEvent({
3661
+ payload: c,
3662
+ channelName: o,
3663
+ source: "channel"
3664
+ });
3665
+ }
3666
+ }
3667
+ const kt = (n) => n.payload.type === "Timeline Entry" || n.payload.type === "MyOS Timeline Entry";
3668
+ class Ns extends oe {
3669
+ constructor() {
3670
+ super(...arguments);
3671
+ l(this, "contractType", "MyOS Timeline Channel");
3672
+ l(this, "contractBlueId", j["MyOS Timeline Channel"]);
3673
+ }
3674
+ supports(t, r, s) {
3675
+ if (!this.baseSupports(t) || !kt(t)) return !1;
3676
+ const o = s.getBlue(), i = o.jsonValueToNode(t.payload), a = o.nodeToSchemaOutput(
3677
+ i,
3678
+ Kr
3679
+ ), c = s.getBlue().nodeToSchemaOutput(r, Jr), h = S(c.timelineId) && S(a.timelineId), p = S(c.account) && S(a.account), g = S(c.email) && S(a.email);
3680
+ return h && a.timelineId === c.timelineId || p && a.account === c.account || g && a.email === c.email;
3681
+ }
3682
+ handle(t, r, s, o) {
3683
+ kt(t) && s.emitEvent({
3684
+ payload: t.payload,
3685
+ channelName: o,
3686
+ source: "channel"
3687
+ });
3688
+ }
3689
+ }
3690
+ class As extends oe {
3691
+ constructor() {
3692
+ super(...arguments);
3693
+ l(this, "contractType", "MyOS Agent Channel");
3694
+ l(this, "contractBlueId", j["MyOS Agent Channel"]);
3695
+ }
3696
+ supports(t, r, s) {
3697
+ if (!this.baseSupports(t)) return !1;
3698
+ try {
3699
+ const { myosAgentEvent: o, myosAgentChannel: i } = this.parseEventAndChannel(
3700
+ t,
3701
+ r,
3702
+ s
3703
+ );
3704
+ return this.isAgentMatch(o, i) && this.isEventPatternMatch(o, i, s);
3705
+ } catch (o) {
3706
+ return console.warn("Error in MyOSAgentChannelProcessor.supports:", o), !1;
3707
+ }
3708
+ }
3709
+ handle(t, r, s, o) {
3710
+ s.emitEvent({
3711
+ payload: t.payload,
3712
+ channelName: o,
3713
+ source: "channel"
3714
+ });
3715
+ }
3716
+ /**
3717
+ * Parses and validates the event payload and channel configuration
3718
+ * @throws {Error} If schema validation fails
3719
+ */
3720
+ parseEventAndChannel(t, r, s) {
3721
+ const o = s.getBlue(), i = o.jsonValueToNode(t.payload), a = o.nodeToSchemaOutput(
3722
+ i,
3723
+ Hr
3724
+ ), c = o.nodeToSchemaOutput(
3725
+ r,
3726
+ zr
3727
+ );
3728
+ return { myosAgentEvent: a, myosAgentChannel: c };
3729
+ }
3730
+ /**
3731
+ * Checks if the agent IDs match between event and channel
3732
+ * @param myosAgentEvent - The parsed agent event
3733
+ * @param myosAgentChannel - The parsed agent channel configuration
3734
+ * @returns true if both have valid agent IDs and they match
3735
+ */
3736
+ isAgentMatch(t, r) {
3737
+ var i;
3738
+ const s = t.agentId, o = (i = r.agent) == null ? void 0 : i.agentId;
3739
+ return S(s) && S(o) && s === o;
3740
+ }
3741
+ /**
3742
+ * Checks if the event pattern matches the channel's event filter
3743
+ *
3744
+ * @param myosAgentEvent - The parsed agent event
3745
+ * @param myosAgentChannel - The parsed agent channel configuration
3746
+ * @param ctx - Processing context for Blue instance access
3747
+ * @returns true if the event matches the channel's filter criteria
3748
+ *
3749
+ * **Matching Logic:**
3750
+ * - If no event pattern is specified in channel → matches all events
3751
+ * - If channel has event pattern but incoming event has no event data → no match
3752
+ * - Otherwise → uses deep containment matching (event must contain all channel pattern fields)
3753
+ */
3754
+ isEventPatternMatch(t, r, s) {
3755
+ const o = r.event;
3756
+ if (!o)
3757
+ return !0;
3758
+ const i = t.event;
3759
+ if (!i)
3760
+ return !1;
3761
+ try {
3762
+ const a = s.getBlue(), c = a.nodeToJson(i), h = a.nodeToJson(o);
3763
+ return wn(c, h);
3764
+ } catch (a) {
3765
+ return console.warn("Error during event pattern matching:", a), !1;
3766
+ }
3767
+ }
3768
+ }
3769
+ class Os {
3770
+ constructor() {
3771
+ l(this, "contractType", "Operation");
3772
+ l(this, "contractBlueId", b.Operation);
3773
+ l(this, "role", "adapter");
3774
+ }
3775
+ supports(e, t, r, s) {
3776
+ const i = r.getBlue().nodeToSchemaOutput(t, qr), a = this.parseEventPayload(e, r);
3777
+ return S(a == null ? void 0 : a.operation) && a.operation === s && e.source === "channel" && e.channelName === i.channel;
3778
+ }
3779
+ async handle(e, t, r, s) {
3780
+ r.emitEvent({
3781
+ payload: e.payload,
3782
+ channelName: s,
3783
+ source: "channel"
3784
+ });
3785
+ }
3786
+ init() {
3787
+ return [];
3788
+ }
3789
+ parseEventPayload(e, t) {
3790
+ const r = t.getBlue(), s = r.jsonValueToNode(e.payload);
3791
+ if (q.isTypeOf(s, Ne)) {
3792
+ const o = r.nodeToSchemaOutput(
3793
+ s,
3794
+ Ne
3795
+ );
3796
+ return r.nodeToSchemaOutput(
3797
+ o.message,
3798
+ Lr
3799
+ );
3800
+ }
3801
+ return null;
3802
+ }
3803
+ }
3804
+ class ks {
3805
+ constructor() {
3806
+ l(this, "contractType", "Process Embedded");
3807
+ l(this, "role", "adapter");
3808
+ l(this, "contractBlueId", b["Process Embedded"]);
3809
+ }
3810
+ supports(e) {
3811
+ return e.source !== "channel";
3812
+ }
3813
+ handle(e, t, r) {
3814
+ const s = r.getBlue().nodeToSchemaOutput(t, et);
3815
+ for (const o of s.paths ?? [])
3816
+ r.emitEvent({
3817
+ ...e,
3818
+ dispatchPath: r.resolvePath(o)
3819
+ });
3820
+ }
3821
+ init() {
3822
+ return [];
3823
+ }
3824
+ }
3825
+ const cn = !process.env.SKIP_ISOLATED_VM;
3826
+ let R = null;
3827
+ if (cn)
3828
+ try {
3829
+ R = require("isolated-vm");
3830
+ } catch {
3831
+ console.warn("isolated-vm not available, using fallback evaluation method");
3832
+ }
3833
+ function xt(n) {
3834
+ return /\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(n) || /\bexport\s+/.test(n);
3835
+ }
3836
+ class ln {
3837
+ /**
3838
+ * Main evaluation method - chooses between secure and simple evaluation strategies
3839
+ */
3840
+ static async evaluate({
3841
+ code: e,
3842
+ ctx: t,
3843
+ bindings: r = {},
3844
+ options: s = {}
3845
+ }) {
3846
+ return !R || !cn ? this.evaluateSimple(e, r, s) : this.evaluateSecure(e, r, t, s);
3847
+ }
3848
+ /**
3849
+ * Fallback evaluation using Node's Function constructor
3850
+ * Used when isolated-vm is not available
3851
+ */
3852
+ static async evaluateSimple(e, t, r = {}) {
3853
+ if (xt(e))
3854
+ throw new Error(
3855
+ "Static import/export syntax requires isolated-vm – start Node without SKIP_ISOLATED_VM."
3856
+ );
3857
+ try {
3858
+ if (r.isCodeBlock) {
3859
+ const s = Object.keys(t);
3860
+ return await (await new Function(
3861
+ ...s,
3862
+ `return async function codeBlock(${s.join(
3863
+ ", "
3864
+ )}) { ${e} }`
3865
+ )(
3866
+ ...s.map((a) => t[a])
3867
+ ))(...s.map((a) => t[a]));
3868
+ } else
3869
+ return new Function(
3870
+ ...Object.keys(t),
3871
+ `return ${e};`
3872
+ )(...Object.values(t));
3873
+ } catch (s) {
3874
+ throw r.isCodeBlock ? new Bt(e, s) : new Pt(e, s);
3875
+ }
3876
+ }
3877
+ /**
3878
+ * Secure evaluation using isolated-vm with support for ES modules
3879
+ */
3880
+ static async evaluateSecure(e, t, r, s = {}) {
3881
+ if (!R) throw new Error("isolated-vm not available");
3882
+ const o = new R.Isolate({ memoryLimit: 32 }), i = await o.createContext(), a = i.global;
3883
+ try {
3884
+ await this.setupIsolateEnvironment(a, t);
3885
+ const c = /* @__PURE__ */ new Map(), h = this.createModuleResolver(
3886
+ o,
3887
+ i,
3888
+ c,
3889
+ r
3890
+ );
3891
+ return xt(e) ? await this.evaluateESModule(
3892
+ o,
3893
+ i,
3894
+ e,
3895
+ s,
3896
+ h
3897
+ ) : await this.evaluateSimpleScript(
3898
+ o,
3899
+ i,
3900
+ e,
3901
+ t,
3902
+ s
3903
+ );
3904
+ } catch (c) {
3905
+ throw s.isCodeBlock ? new Bt(e, c) : new Pt(e, c);
3906
+ } finally {
3907
+ i.release(), o.dispose();
3908
+ }
3909
+ }
3910
+ /**
3911
+ * Setup the isolated VM environment with necessary host functions and data
3912
+ */
3913
+ static async setupIsolateEnvironment(e, t) {
3914
+ if (!R) throw new Error("isolated-vm not available");
3915
+ const r = new R.Callback(
3916
+ (...s) => console.log(...s)
3917
+ );
3918
+ await e.set("log", r);
3919
+ for (const [s, o] of Object.entries(t))
3920
+ typeof o == "function" ? await e.set(
3921
+ s,
3922
+ new R.Callback(o)
3923
+ ) : await e.set(s, new R.ExternalCopy(o).copyInto());
3924
+ }
3925
+ /**
3926
+ * Create module resolver function for handling imports
3927
+ */
3928
+ static createModuleResolver(e, t, r, s) {
3929
+ return async (o) => {
3930
+ if (r.has(o)) return r.get(o);
3931
+ if (o.startsWith("blue:")) {
3932
+ const i = o.slice(5), a = s.loadBlueContent;
3933
+ if (typeof a != "function")
3934
+ throw new Error(
3935
+ `ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${o})`
3936
+ );
3937
+ const c = await a(i), h = await e.compileModule(c);
3938
+ return r.set(o, h), await h.instantiate(
3939
+ t,
3940
+ this.createModuleResolver(e, t, r, s)
3941
+ ), h;
3942
+ }
3943
+ if (/^https?:\/\//.test(o)) {
3944
+ let i;
3945
+ if (typeof s.loadExternalModule == "function")
3946
+ i = await s.loadExternalModule(o);
3947
+ else
3948
+ throw new Error(
3949
+ `ProcessingContext is missing a loadExternalModule(url) implementation (needed for ${o})`
3950
+ );
3951
+ const a = await e.compileModule(i);
3952
+ return r.set(o, a), await a.instantiate(
3953
+ t,
3954
+ this.createModuleResolver(e, t, r, s)
3955
+ ), a;
3956
+ }
3957
+ throw new Error(`Unsupported module specifier "${o}"`);
3958
+ };
3959
+ }
3960
+ /**
3961
+ * Evaluate code as a simple script (no imports/exports)
3962
+ */
3963
+ static async evaluateSimpleScript(e, t, r, s, o) {
3964
+ const i = Object.keys(s).join(", "), a = Object.keys(s).map((p) => p), c = `(async (${i}) => { ${o.isCodeBlock ? r : `return (${r});`} })(${a.join(", ")})`;
3965
+ return await (await e.compileScript(c)).run(t, {
3966
+ timeout: o.timeout ?? 500,
3967
+ promise: !0,
3968
+ copy: !0,
3969
+ release: !0
3970
+ });
3971
+ }
3972
+ /**
3973
+ * Evaluate code as an ES module with import/export support
3974
+ */
3975
+ static async evaluateESModule(e, t, r, s, o) {
3976
+ let i = r;
3977
+ if (s.isCodeBlock) {
3978
+ const h = /^\s*(import\s.+?;|export\s.+?;)/gm, p = (r.match(h) || []).join(
3979
+ `
3980
+ `
3981
+ ), g = r.replace(h, "").trim();
3982
+ i = `
3983
+ ${p}
3984
+ const run = function() {
3985
+ ${g}
3986
+ };
3987
+ export default run();
3988
+ `;
3989
+ }
3990
+ const a = await e.compileModule(i);
3991
+ return await a.instantiate(t, o), await a.evaluate({
3992
+ timeout: s.timeout ?? 500,
3993
+ promise: !0,
3994
+ reference: !0,
3995
+ release: !0
3996
+ }), await a.namespace.get("default", {
3997
+ timeout: s.timeout ?? 500,
3998
+ promise: !0,
3999
+ copy: !0,
4000
+ release: !0
4001
+ });
4002
+ }
4003
+ }
4004
+ class un {
4005
+ /**
4006
+ * Creates standard bindings for workflow step execution
4007
+ */
4008
+ static createStandardBindings(e, t, r) {
4009
+ const s = e.getBlue();
4010
+ return {
4011
+ document: (o) => {
4012
+ const i = e.get(o);
4013
+ return A(i) ? i.toNumber() : fe(i) ? s.nodeToJson(i, "original") : i;
4014
+ },
4015
+ event: t.payload,
4016
+ steps: r
4017
+ };
4018
+ }
4019
+ }
4020
+ class xs {
4021
+ constructor() {
4022
+ l(this, "stepType", "Update Document");
4023
+ }
4024
+ supports(e) {
4025
+ return q.isTypeOf(e, _e);
4026
+ }
4027
+ async evaluateChangeValue(e, t, r, s) {
4028
+ const o = e == null ? void 0 : e.getValue();
4029
+ if (typeof o == "string" && o.startsWith("${") && o.endsWith("}")) {
4030
+ const i = o.slice(2, -1);
4031
+ return await ln.evaluate({
4032
+ code: i,
4033
+ ctx: t,
4034
+ bindings: un.createStandardBindings(
4035
+ t,
4036
+ r,
4037
+ s
4038
+ )
4039
+ });
4040
+ }
4041
+ return e;
4042
+ }
4043
+ async execute(e, t, r, s, o) {
4044
+ if (!q.isTypeOf(e, _e)) return;
4045
+ const i = r.getBlue().nodeToSchemaOutput(e, _e);
4046
+ for (const a of i.changeset ?? [])
4047
+ if (a.path) {
4048
+ if (a.op === "replace" || a.op === "add") {
4049
+ const c = await this.evaluateChangeValue(
4050
+ a.val,
4051
+ r,
4052
+ t,
4053
+ o
4054
+ );
4055
+ r.addPatch({
4056
+ op: a.op,
4057
+ path: a.path,
4058
+ val: c
4059
+ }), r.emitEvent({
4060
+ payload: {
4061
+ type: "Document Update",
4062
+ op: a.op,
4063
+ path: r.resolvePath(a.path),
4064
+ val: c
4065
+ }
4066
+ });
4067
+ }
4068
+ a.op === "remove" && (r.addPatch({ op: a.op, path: a.path }), r.emitEvent({
4069
+ payload: {
4070
+ type: "Document Update",
4071
+ op: a.op,
4072
+ path: r.resolvePath(a.path),
4073
+ val: null
4074
+ }
4075
+ }));
4076
+ }
4077
+ }
4078
+ }
4079
+ class Ds {
4080
+ constructor() {
4081
+ l(this, "stepType", "Trigger Event");
4082
+ }
4083
+ supports(e) {
4084
+ return q.isTypeOf(e, Le);
4085
+ }
4086
+ async execute(e, t, r) {
4087
+ if (!q.isTypeOf(e, Le)) return;
4088
+ const s = r.getBlue().nodeToSchemaOutput(e, Le), o = P.get(
4089
+ s.event,
4090
+ "simple"
4091
+ );
4092
+ r.emitEvent({
4093
+ payload: o
4094
+ });
4095
+ }
4096
+ }
4097
+ const We = v(b["JavaScript Code"])(
4098
+ u.object({
4099
+ code: u.string().optional()
4100
+ })
4101
+ );
4102
+ class Vs {
4103
+ constructor() {
4104
+ l(this, "stepType", "JavaScript Code");
4105
+ }
4106
+ supports(e) {
4107
+ return q.isTypeOf(e, We);
4108
+ }
4109
+ async execute(e, t, r, s, o) {
4110
+ if (!q.isTypeOf(e, We)) return;
4111
+ const a = r.getBlue().nodeToSchemaOutput(
4112
+ e,
4113
+ We
4114
+ );
4115
+ if (!a.code)
4116
+ throw new Error("JavaScript code is required");
4117
+ const c = await ln.evaluate({
4118
+ code: a.code,
4119
+ ctx: r,
4120
+ bindings: un.createStandardBindings(r, t, o),
4121
+ options: {
4122
+ isCodeBlock: !0,
4123
+ timeout: 500
4124
+ }
4125
+ });
4126
+ if (c && typeof c == "object" && "events" in c) {
4127
+ const h = c;
4128
+ if (Array.isArray(h.events))
4129
+ for (const p of h.events)
4130
+ r.emitEvent({
4131
+ payload: p
4132
+ });
4133
+ }
4134
+ return c;
4135
+ }
4136
+ }
4137
+ const Fs = [
4138
+ new xs(),
4139
+ new Ds(),
4140
+ new Vs()
4141
+ ];
4142
+ class hn {
4143
+ constructor(e = Fs) {
4144
+ l(this, "contractType", "Sequential Workflow");
4145
+ l(this, "contractBlueId", b["Sequential Workflow"]);
4146
+ l(this, "role", "handler");
4147
+ l(this, "executors", []);
4148
+ this.executors = e;
4149
+ }
4150
+ /** allow registering custom step executors */
4151
+ registerExecutor(e) {
4152
+ this.executors.push(e);
4153
+ }
4154
+ supports(e, t, r) {
4155
+ const i = r.getBlue().nodeToSchemaOutput(
4156
+ t,
4157
+ tt
4158
+ ).channel;
4159
+ return e.source === "channel" && e.channelName === i;
4160
+ }
4161
+ async handle(e, t, r, s) {
4162
+ const i = r.getBlue().nodeToSchemaOutput(
4163
+ t,
4164
+ tt
4165
+ ), a = {}, c = i.steps;
4166
+ for (const [h, p] of (c ?? []).entries()) {
4167
+ const g = this.executors.find((f) => f.supports(p));
4168
+ if (!g)
4169
+ throw new Error(`Unsupported workflow step type "${p.getType()}"`);
4170
+ const w = await g.execute(
4171
+ p,
4172
+ e,
4173
+ r,
4174
+ s,
4175
+ a
4176
+ );
4177
+ if (w !== void 0) {
4178
+ const f = p.getName(), m = typeof f == "string" ? f : `Step${h + 1}`;
4179
+ a[m] = w;
4180
+ }
4181
+ await r.flush();
4182
+ }
4183
+ }
4184
+ init() {
4185
+ return [];
4186
+ }
4187
+ }
4188
+ class Ms {
4189
+ constructor(e) {
4190
+ l(this, "contractType", "Sequential Workflow Operation");
4191
+ l(this, "contractBlueId", b["Sequential Workflow Operation"]);
4192
+ l(this, "role", "handler");
4193
+ l(this, "sequentialWorkflowProcessor");
4194
+ this.sequentialWorkflowProcessor = e || new hn();
4195
+ }
4196
+ supports(e, t, r) {
4197
+ const i = r.getBlue().nodeToSchemaOutput(
4198
+ t,
4199
+ _r
4200
+ ).operation, a = e.channelName;
4201
+ return e.source === "channel" && y(a) && y(i) && a === i;
4202
+ }
4203
+ async handle(e, t, r, s) {
4204
+ try {
4205
+ await this.sequentialWorkflowProcessor.handle(e, t, r, s);
4206
+ } catch (o) {
4207
+ throw console.error(
4208
+ "Error in SequentialWorkflowOperationProcessor.handle:",
4209
+ o
4210
+ ), o;
4211
+ }
4212
+ }
4213
+ }
4214
+ const Dt = (n) => n.payload.type === "Timeline Entry";
4215
+ class js extends oe {
4216
+ constructor() {
4217
+ super(...arguments);
4218
+ l(this, "contractType", "Timeline Channel");
4219
+ l(this, "contractBlueId", b["Timeline Channel"]);
4220
+ }
4221
+ supports(t, r, s) {
4222
+ if (!this.baseSupports(t) || !Dt(t)) return !1;
4223
+ const o = s.getBlue(), i = o.jsonValueToNode(t.payload), a = o.nodeToSchemaOutput(
4224
+ i,
4225
+ Ne
4226
+ ), c = s.getBlue().nodeToSchemaOutput(r, Xt);
4227
+ return S(c.timelineId) && S(a.timelineId) && a.timelineId === c.timelineId;
4228
+ }
4229
+ handle(t, r, s, o) {
4230
+ Dt(t) && s.emitEvent({
4231
+ payload: t.payload,
4232
+ channelName: o,
4233
+ source: "channel"
4234
+ });
4235
+ }
4236
+ }
4237
+ class go {
4238
+ constructor(e = {}) {
4239
+ l(this, "nodeProvider");
4240
+ l(this, "typeSchemaResolver");
4241
+ l(this, "blueDirectivePreprocessor");
4242
+ l(this, "urlContentFetcher");
4243
+ l(this, "documentProcessor");
4244
+ l(this, "prepareForBlueIdCalculation", async (e) => e instanceof d || Array.isArray(e) && e.every((t) => t instanceof d) ? e : Array.isArray(e) ? await Promise.all(
4245
+ e.map((r) => this.jsonValueToNodeAsync(r))
4246
+ ) : this.jsonValueToNodeAsync(e));
4247
+ l(this, "calculateBlueId", async (e) => {
4248
+ const t = await this.prepareForBlueIdCalculation(e);
4249
+ return V.calculateBlueId(t);
4250
+ });
4251
+ l(this, "prepareForBlueIdCalculationSync", (e) => e instanceof d || Array.isArray(e) && e.every((t) => t instanceof d) ? e : Array.isArray(e) ? e.map((t) => this.jsonValueToNode(t)) : this.jsonValueToNode(e));
4252
+ const {
4253
+ nodeProvider: t,
4254
+ typeSchemaResolver: r = null,
4255
+ urlFetchStrategy: s
4256
+ } = e, o = Pr(() => []);
4257
+ this.nodeProvider = pe.wrap(
4258
+ t || o
4259
+ ), this.typeSchemaResolver = r, this.urlContentFetcher = new Xr(s), this.blueDirectivePreprocessor = new Qr(
4260
+ void 0,
4261
+ this.urlContentFetcher
4262
+ ), this.documentProcessor = new Ps(this, [
4263
+ new ks(),
4264
+ // channels
4265
+ new Ss(),
4266
+ new Cs(),
4267
+ new js(),
4268
+ new Ns(),
4269
+ new As(),
4270
+ new Bs(),
4271
+ new Os(),
4272
+ // sequential workflows
4273
+ new hn(),
4274
+ new Ms()
4275
+ ]);
4276
+ }
4277
+ /**
4278
+ * Converts a BlueNode to a JSON representation based on the specified strategy.
4279
+ *
4280
+ * @param node - The BlueNode to convert.
4281
+ * @param strategy - The conversion strategy to use. See {@link NodeToMapListOrValue.get} for detailed strategy descriptions.
4282
+ * @returns A JSON representation of the node.
4283
+ */
4284
+ nodeToJson(e, t = "official") {
4285
+ return P.get(e, t);
4286
+ }
4287
+ nodeToSchemaOutput(e, t) {
4288
+ return new Yt(this.typeSchemaResolver).convert(e, t);
4289
+ }
4290
+ async process(e, t) {
4291
+ return await this.documentProcessor.initialise(e), this.documentProcessor.processEvents(e, t);
4292
+ }
4293
+ jsonValueToNode(e) {
4294
+ return this.preprocess(T.deserialize(e));
4295
+ }
4296
+ async jsonValueToNodeAsync(e) {
4297
+ return this.preprocessAsync(T.deserialize(e));
4298
+ }
4299
+ yamlToNode(e) {
4300
+ const t = de(e);
4301
+ if (!t)
4302
+ throw new Error("Failed to parse YAML to JSON");
4303
+ return this.jsonValueToNode(t);
4304
+ }
4305
+ async yamlToNodeAsync(e) {
4306
+ const t = de(e);
4307
+ if (!t)
4308
+ throw new Error("Failed to parse YAML to JSON");
4309
+ return this.jsonValueToNodeAsync(t);
4310
+ }
4311
+ calculateBlueIdSync(e) {
4312
+ const t = this.prepareForBlueIdCalculationSync(e);
4313
+ return V.calculateBlueIdSync(t);
4314
+ }
4315
+ addPreprocessingAliases(e) {
4316
+ this.blueDirectivePreprocessor.addPreprocessingAliases(e);
4317
+ }
4318
+ preprocess(e) {
4319
+ const t = this.blueDirectivePreprocessor.process(e);
4320
+ return new Ae(this.nodeProvider).preprocessWithDefaultBlue(
4321
+ t
4322
+ );
4323
+ }
4324
+ async preprocessAsync(e) {
4325
+ const t = await this.blueDirectivePreprocessor.processAsync(
4326
+ e
4327
+ );
4328
+ return new Ae(this.nodeProvider).preprocessWithDefaultBlue(
4329
+ t
4330
+ );
4331
+ }
4332
+ getNodeProvider() {
4333
+ return this.nodeProvider;
4334
+ }
4335
+ setNodeProvider(e) {
4336
+ return this.nodeProvider = pe.wrap(e), this;
4337
+ }
4338
+ getTypeSchemaResolver() {
4339
+ return this.typeSchemaResolver;
4340
+ }
4341
+ setTypeSchemaResolver(e) {
4342
+ return this.typeSchemaResolver = e, this;
4343
+ }
4344
+ getUrlContentFetcher() {
4345
+ return this.urlContentFetcher;
4346
+ }
4347
+ setUrlFetchStrategy(e) {
4348
+ return this.urlContentFetcher.setFetchStrategy(e), this;
4349
+ }
4350
+ /**
4351
+ * Enables fetching content from URLs in blue directives for all domains.
4352
+ * By default, URL fetching is disabled for security reasons.
4353
+ * This clears any domain restrictions that may have been set.
4354
+ *
4355
+ * @returns This instance for chaining
4356
+ */
4357
+ enablePreprocessingDirectivesFetchForUrls() {
4358
+ return this.urlContentFetcher.enableFetching(), this;
4359
+ }
4360
+ /**
4361
+ * Enables fetching content from URLs in blue directives only for specified domains.
4362
+ * By default, URL fetching is disabled for security reasons.
4363
+ *
4364
+ * @param domains Array of domains to allow (e.g. ['example.com', 'api.github.com'])
4365
+ * @returns This instance for chaining
4366
+ */
4367
+ enablePreprocessingDirectivesFetchForDomains(e) {
4368
+ return this.urlContentFetcher.enableFetchingForDomains(e), this;
4369
+ }
4370
+ /**
4371
+ * Adds a domain to the list of allowed domains for URL fetching.
4372
+ *
4373
+ * @param domain Domain to allow (e.g. 'example.com')
4374
+ * @returns This instance for chaining
4375
+ */
4376
+ allowUrlFetchingForDomain(e) {
4377
+ return this.urlContentFetcher.allowDomain(e), this;
4378
+ }
4379
+ /**
4380
+ * Removes a domain from the list of allowed domains for URL fetching.
4381
+ *
4382
+ * @param domain Domain to disallow
4383
+ * @returns This instance for chaining
4384
+ */
4385
+ disallowUrlFetchingForDomain(e) {
4386
+ return this.urlContentFetcher.disallowDomain(e), this;
4387
+ }
4388
+ /**
4389
+ * Gets the list of domains allowed for URL fetching.
4390
+ * An empty list means all domains are allowed when fetching is enabled.
4391
+ *
4392
+ * @returns Array of allowed domains
4393
+ */
4394
+ getAllowedUrlFetchingDomains() {
4395
+ return this.urlContentFetcher.getAllowedDomains();
4396
+ }
4397
+ /**
4398
+ * Disables fetching content from URLs in blue directives.
4399
+ *
4400
+ * @returns This instance for chaining
4401
+ */
4402
+ disablePreprocessingDirectivesFetchForUrls() {
4403
+ return this.urlContentFetcher.disableFetching(), this;
4404
+ }
4405
+ /**
4406
+ * Checks if URL fetching is enabled for blue directives
4407
+ *
4408
+ * @returns true if URL fetching is enabled, false otherwise
4409
+ */
4410
+ isPreprocessingDirectivesFetchForUrlsEnabled() {
4411
+ return this.urlContentFetcher.isFetchingEnabled();
4412
+ }
4413
+ getPreprocessingAliases() {
4414
+ return this.blueDirectivePreprocessor.getPreprocessingAliases();
4415
+ }
4416
+ setPreprocessingAliases(e) {
4417
+ return this.blueDirectivePreprocessor.setPreprocessingAliases(e), this;
4418
+ }
4419
+ }
4420
+ export {
4421
+ Gn as Base58Sha256Provider,
4422
+ go as Blue,
4423
+ V as BlueIdCalculator,
4424
+ so as BlueIdToCid,
4425
+ Hn as JsonCanonicalizer,
4426
+ co as TypeSchemaResolver,
4427
+ je as baseBlueObjectSchema,
4428
+ oo as blueDescriptionField,
4429
+ io as blueIdField,
4430
+ zs as blueIdSchema,
4431
+ ao as blueNameField,
4432
+ _ as blueNodeField,
4433
+ Gs as blueObjectBooleanValueSchema,
4434
+ Qs as blueObjectNumberValueSchema,
4435
+ ue as blueObjectSchema,
4436
+ Xs as blueObjectStringListItemsSchema,
4437
+ Hs as blueObjectStringValueSchema,
4438
+ Fr as calculateBlueId,
4439
+ uo as calculateBlueIdSync,
4440
+ Tt as enrichWithBlueId,
4441
+ tr as getBlueDescriptionAnnotation,
4442
+ sr as getBlueIdAnnotation,
4443
+ ir as getBlueNameAnnotation,
4444
+ cr as getBlueNodeAnnotation,
4445
+ ho as getBlueObjectItems,
4446
+ fo as getBlueObjectProperties,
4447
+ yo as getBlueObjectTypeLabel,
4448
+ po as getBlueObjectValue,
4449
+ ur as getExtendedFromSchemaAnnotation,
4450
+ pr as getTypeBlueIdAnnotation,
4451
+ $n as hasBlueObjectBlueIdDefined,
4452
+ Un as hasBlueObjectItemsDefined,
4453
+ to as hasBlueObjectNameDefined,
4454
+ Zn as hasBlueObjectTypeDefined,
4455
+ qn as hasBlueObjectValueDefined,
4456
+ wt as isBlueNodeSchema,
4457
+ eo as isBlueObject,
4458
+ Mr as isBlueObjectResolved,
4459
+ no as isGivenBlueObjectTypeSchema,
4460
+ Wt as isJsonBlueArray,
4461
+ _t as isJsonBlueObject,
4462
+ ro as isJsonBlueValue,
4463
+ Jt as isSchemaExtendedFrom,
4464
+ ve as isUrl,
4465
+ Se as jsonBlueValueSchema,
4466
+ mo as normalizeToBlueObject,
4467
+ bt as resolveBlueObjectItems,
4468
+ er as withBlueDescription,
4469
+ rr as withBlueId,
4470
+ or as withBlueName,
4471
+ ar as withBlueNode,
4472
+ lr as withExtendedFromSchema,
4473
+ v as withTypeBlueId,
4474
+ lo as yamlBlueDump,
4475
+ de as yamlBlueParse
4476
+ };