@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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 @blue-labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # @blue-labs/language
2
+
3
+ @blue-labs/language is a comprehensive library for working with the Blue language, a simple YAML-based language that supports inheritance. This library has been rewritten from the original Java version, which can be found [here](https://github.com/bluecontract/blue-language-java). The rewritten parts are located in the `src/lib` directory, while the rest of the code includes additional helper functions designed for TypeScript, enabling better manipulation and management of Blue objects.
4
+
5
+ ## Installation
6
+
7
+ To install the library, use npm or yarn:
8
+
9
+ ```bash
10
+ npm install @blue-labs/language
11
+ # or
12
+ yarn add @blue-labs/language
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Here are the key features and services provided by the @blue-labs/language library:
18
+
19
+ ### Services
20
+
21
+ - **Base58Sha256Provider**
22
+ - A hash provider used in `BlueIdCalculator` for calculating blueId.
23
+ - **BlueIdCalculator**
24
+ - Service for calculating blueId.
25
+ - **BlueIdToCid**
26
+ - Service to calculate CIDv1 used as id in IPFS from the provided blueId.
27
+ - **JsonCanonicalizer**
28
+ - Service for calculating the canonical form of a given value.
29
+
30
+ ### Schemas
31
+
32
+ - **blueIdSchema**
33
+ - A schema defined in Zod, describing blueId.
34
+ - **blueObjectSchema**
35
+ - A schema defined in Zod, describing a BlueObject.
36
+
37
+ ### Functions
38
+
39
+ - **calculateBlueId**
40
+ - Calculates blueId for a given JSON like value.
41
+ - **enrichWithBlueId**
42
+ - Enriches a given BlueObject with calculated blueId.
43
+ - **getBlueObjectProperties**
44
+ - Returns properties of a BlueObject that are not specific to this object.
45
+ - **getBlueObjectTypeLabel**
46
+ - Retrieves the type label of a BlueObject based on its type, value, or items.
47
+ - **isBlueObjectResolved**
48
+ - Checks if a BlueObject is fully resolved or if there is something apart from blueId.
49
+
50
+ ### Predicates
51
+
52
+ - **hasBlueObjectBlueIdDefined**
53
+ - Predicate to check if blueId is defined.
54
+ - **hasBlueObjectItemsDefined**
55
+ - Predicate to check if items are defined.
56
+ - **hasBlueObjectNameDefined**
57
+ - Predicate to check if name is defined.
58
+ - **hasBlueObjectTypeDefined**
59
+ - Predicate to check if type is defined.
60
+ - **hasBlueObjectValueDefined**
61
+ - Predicate to check if value is defined.
62
+ - **isBlueObject**
63
+ - Predicate to check if a value is of type BlueObject.
64
+
65
+ ### Normalization
66
+
67
+ - **normalizeToBlueObject**
68
+ - Normalizes a given JSON value to a BlueObject.
69
+
70
+ ### Helpers
71
+
72
+ - **resolveBlueObjectItems**
73
+ - Resolves BlueObject items in order from last to first.
74
+ - **yamlBlueDump**
75
+ - Loads YAML.
76
+ - **yamlBlueParse**
77
+ - Parses YAML.
78
+
79
+ ## Blue Language Overview
80
+
81
+ Blue language is a simple YAML-based language that supports inheritance. Below are some key aspects:
82
+
83
+ ### Base Type
84
+
85
+ Every node in Blue is of this type. If any node does not specify a `type`, it is considered to be of this base type by default.
86
+
87
+ ### Known Blue Types
88
+
89
+ - **Text**: A basic text type.
90
+ - **Integer**: A basic integer type.
91
+ - **Number**: A basic number type.
92
+ - **Boolean**: A basic boolean type. If value is not specified, it means false.
93
+ - **Type**: A type that can reference other types. To be used only for `type` attribute definition.
94
+
95
+ ### Example
96
+
97
+ ```yaml
98
+ name:
99
+ value: Pet
100
+ description: Name of the pet. Every pet must have a name.
101
+ description: A base type for all pets.
102
+ abstract: true
103
+ age:
104
+ description: The age of the pet in years.
105
+ type: Integer
106
+
107
+ ---
108
+ name:
109
+ value: Dog
110
+ description: If we want to put more fields for Text, Integer, Number, Boolean, or Type elements, we can use `value` instead of inline approach like everywhere else here.
111
+ abstract: true
112
+ type: Pet
113
+ breed:
114
+ description: The breed of the dog.
115
+ type: Text
116
+ isTrained:
117
+ description: Indicates if the dog is trained.
118
+ type: Boolean
119
+ ```
120
+
121
+ For more detailed information, refer to the [Blue Language documentation](https://github.com/bluecontract/blue-language-java).
122
+
123
+ ## Changelog
124
+
125
+ The [Changelog](https://github.com/bluecontract/blue-js/blob/main/CHANGELOG.md) is regularly updated to reflect what's changed in each new release.
126
+
127
+ ## Contributing
128
+
129
+ We welcome contributions! Please read our [Contributing Guide](https://github.com/bluecontract/blue-js/blob/main/CONTRIBUTING.md) to learn about how you can contribute.
130
+
131
+ ## License
132
+
133
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
@@ -0,0 +1,5 @@
1
+ export { type BlueNode, type UrlFetchStrategy, BlueIdCalculator, JsonCanonicalizer, BlueIdToCid, Base58Sha256Provider, TypeSchemaResolver, Blue, } from './lib';
2
+ export * from './schema';
3
+ export * from './schema/annotations';
4
+ export * from './utils';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,IAAI,GACL,MAAM,OAAO,CAAC;AACf,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";var pn=Object.defineProperty;var fn=(n,e,t)=>e in n?pn(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var u=(n,e,t)=>fn(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@blue-labs/shared-utils"),l=require("zod"),yn=require("bs58"),U=require("big.js"),C=require("radash"),mn=require("js-sha256"),gn=require("crypto"),bn=require("base32.js"),Y=require("js-yaml"),Bt=n=>n&&n.__esModule?n:{default:n},ce=Bt(yn),ct=Bt(gn);class wn{static get(e,t,r,s=!0){if(p.isNullable(t)||!t.startsWith("/"))throw new Error(`Invalid path: ${t}`);if(t==="/"){const i=e.getValue();return s&&i!==void 0?i:e}const o=t.substring(1).split("/");return this.getRecursive(e,o,0,r,s)}static getRecursive(e,t,r,s,o){if(r===t.length-1&&!o)return this.getNodeForSegment(e,t[r],s,!1);if(r===t.length){const c=e.getValue();return o&&c!==void 0?c:e}const i=t[r],a=this.getNodeForSegment(e,i,s,!0);if(a)return this.getRecursive(a,t,r+1,s,o)}static getNodeForSegment(e,t,r,s){let o;const i=e.getProperties();if(i&&t in i)o=i[t];else switch(t){case"name":{const a=e.getName();o=p.isNonNullable(a)?new d().setValue(a):new d;break}case"description":{const a=e.getDescription();o=p.isNonNullable(a)?new d().setValue(a):new d;break}case"type":o=e.getType()??new d;break;case"itemType":o=e.getItemType()??new d;break;case"keyType":o=e.getKeyType()??new d;break;case"valueType":o=e.getValueType()??new d;break;case"value":{const a=e.getValue();o=new d().setValue(a??null);break}case"blueId":{const a=e.getBlueId();o=p.isNonNullable(a)?new d().setValue(a):new d;break}case"blue":o=e.getBlue();break;case"items":{const a=e.getItems();o=new d().setItems(a);break}case"properties":{const a=e.getProperties();o=new d().setProperties(a);break}case"contracts":{const a=e.getContracts();o=new d().setContracts(a);break}default:{if(/^\d+$/.test(t)){const a=parseInt(t,10),c=e.getItems();c&&a>=0&&a<c.length?o=c[a]:o=void 0}else o=void 0;break}}if(o)return s&&r?this.link(o,r):o}static link(e,t){const r=t(e);return p.isNonNullable(r)?r:e}}class A extends U{constructor(e){super(e)}}class D extends U{constructor(e){super(e)}}const Q="name",G="description",Ee="type",He="itemType",Qe="keyType",Ge="valueType",Ce="value",Xe="items",K="blueId",et="blue",Ae="contracts",Tn=[Q,G,Ee,He,Qe,Ge,Ce,Xe,K,et,Ae],En="Text",In="Double",vn="Integer",Bn="Boolean",Nn="List",Pn="Dictionary",Sn=[En,In,vn,Bn],Nt=[...Sn,Nn,Pn],fe="F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP",ye="68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L",me="DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8",ge="EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo",Cn="G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB",An="294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA",On=[fe,ye,me,ge],tt=[...On,Cn,An];Object.fromEntries(Nt.map((n,e)=>[n,tt[e]]));Object.fromEntries(tt.map((n,e)=>[n,Nt[e]]));const j=class j{constructor(e){u(this,"name");u(this,"description");u(this,"type");u(this,"itemType");u(this,"keyType");u(this,"valueType");u(this,"value");u(this,"items");u(this,"properties");u(this,"contracts");u(this,"blueId");u(this,"blue");u(this,"inlineValue",!1);this.name=e}getName(){return this.name}setName(e){return this.name=e,this}getDescription(){return this.description}setDescription(e){return this.description=e,this}getType(){return this.type}setType(e){return typeof e=="string"?this.type=new j().setValue(e).setInlineValue(!0):this.type=e,this}getItemType(){return this.itemType}setItemType(e){return typeof e=="string"?this.itemType=new j().setValue(e).setInlineValue(!0):this.itemType=e,this}getKeyType(){return this.keyType}setKeyType(e){return typeof e=="string"?this.keyType=new j().setValue(e).setInlineValue(!0):this.keyType=e,this}getValueType(){return this.valueType}setValueType(e){return typeof e=="string"?this.valueType=new j().setValue(e).setInlineValue(!0):this.valueType=e,this}getValue(){var t;const e=(t=this.type)==null?void 0:t.getBlueId();if(p.isNonNullable(e)&&p.isNonNullable(this.value)){if(e===me&&typeof this.value=="string")return new A(this.value);if(e===ye&&typeof this.value=="string"){const r=new D(this.value),s=parseFloat(r.toString());return new D(s.toString())}else if(e===ge&&typeof this.value=="string")return this.value.toLowerCase()==="true"}return this.value}setValue(e){return typeof e=="number"?e%1===0?this.value=new A(e.toString()):this.value=new D(e.toString()):this.value=e,this}getItems(){return this.items}setItems(e){return this.items=e,this}addItems(...e){return this.items||(this.items=[]),this.items.push(...e),this}getProperties(){return this.properties}setProperties(e){return this.properties=e,this}addProperty(e,t){return this.properties||(this.properties={}),this.properties[e]=t,this}getContracts(){return this.contracts}setContracts(e){return this.contracts=e,this}addContract(e,t){return this.contracts||(this.contracts={}),this.contracts[e]=t,this}getBlueId(){return this.blueId}setBlueId(e){return this.blueId=e,this}getBlue(){return this.blue}setBlue(e){return this.blue=e,this}isInlineValue(){return this.inlineValue}setInlineValue(e){return this.inlineValue=e,this}get(e,t){return wn.get(this,e,t)}clone(){var t,r,s,o,i,a;const e=new j(this.name);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(Object.entries(this.properties).map(([c,h])=>[c,h.clone()]))),this.contracts&&(e.contracts=Object.fromEntries(Object.entries(this.contracts).map(([c,h])=>[c,h.clone()]))),e.blueId=this.blueId,e.blue=(a=this.blue)==null?void 0:a.clone(),e.inlineValue=this.inlineValue,e}toString(){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}}`}};u(j,"INTEGER",new j("Integer"));let d=j;class J{static isPotentialBlueId(e){if(!e||e.length===0||!this.BLUE_ID_PATTERN.test(e))return!1;const t=e.split("#"),r=t[0],s=r.length;if(s<this.MIN_BLUE_ID_LENGTH||s>this.MAX_BLUE_ID_LENGTH)return!1;try{if(ce.default.decode(r).length!==32)return!1}catch{return!1}if(t.length>1)try{if(Number(t[1])<0)return!1}catch{return!1}return!0}}u(J,"MIN_BLUE_ID_LENGTH",41),u(J,"MAX_BLUE_ID_LENGTH",45),u(J,"BLUE_ID_PATTERN",/^[1-9A-HJ-NP-Za-km-z]{41,45}(?:#\d+)?$/);const kn=l.z.string().max(J.MAX_BLUE_ID_LENGTH,{message:"Blue Id has a maximum length of 45 characters"}).min(J.MIN_BLUE_ID_LENGTH,{message:"Blue Id has a minimum length of 41 characters"}).refine(n=>{try{return ce.default.decode(n),!0}catch{return!1}},{message:"Blue Id must be a valid Base58 string"}),X=l.z.lazy(()=>l.z.record(l.z.unknown()).and(l.z.object({blueId:l.z.string().optional(),name:l.z.string().optional(),description:l.z.string().optional(),type:X.optional(),value:l.z.union([l.z.string(),l.z.number(),l.z.boolean()]).optional().nullable(),items:l.z.array(X).optional()}))),be=l.z.object({blueId:l.z.string().optional(),name:l.z.string().optional(),description:l.z.string().optional(),type:X.optional()}),Dn=be.extend({value:l.z.string().optional()}),xn=be.extend({value:l.z.number().optional()}),Vn=be.extend({value:l.z.boolean().optional()}),jn=be.extend({items:l.z.array(l.z.string()).optional()}),Fn=n=>X.safeParse(n).success,Pt=n=>p.isNonNullable(n)&&"blueId"in n&&p.isNonNullable(n.blueId),zn=n=>p.isNonNullable(n)&&"name"in n&&p.isNonNullable(n.name),St=n=>p.isNonNullable(n)&&"items"in n&&p.isNonNullable(n.items),Ct=n=>p.isNonNullable(n)&&"type"in n&&p.isNonNullable(n.type),At=n=>p.isNonNullable(n)&&"value"in n&&p.isNonNullable(n.value),Mn=(n,e)=>n.required({type:!0}).safeParse(e).success,O=n=>n instanceof U,ue=n=>O(n)&&n instanceof A,Rn=n=>O(n)&&n instanceof D,$n=l.z.lazy(()=>l.z.record(he)),Zn=l.z.lazy(()=>l.z.union([l.z.array(he),l.z.array(he).readonly()])),he=l.z.lazy(()=>l.z.union([p.jsonPrimitiveSchema,$n,Zn,l.z.instanceof(U)])),nt=n=>C.isObject(n)&&!C.isArray(n)&&!p.isReadonlyArray(n)&&!O(n),rt=n=>C.isArray(n)||p.isReadonlyArray(n),Un=n=>rt(n)||nt(n)||O(n)||p.isJsonPrimitive(n);class w{static deserialize(e){return w.handleNode(e)}static handleNode(e){if(e===void 0)throw new Error("This is not a valid JSON-like value. Found 'undefined' as a value.");if(nt(e)){const t=new d,r={},s={};return Object.entries(e).forEach(([o,i])=>{switch(o){case Q:if(i==null)t.setName(void 0);else{if(typeof i!="string")throw new Error(`The ${Q} field must be a string.`);t.setName(i)}break;case G:if(i==null)t.setDescription(void 0);else{if(typeof i!="string")throw new Error(`The ${G} field must be a string.`);t.setDescription(i)}break;case Ee:t.setType(w.handleNode(i));break;case He:t.setItemType(w.handleNode(i));break;case Qe:t.setKeyType(w.handleNode(i));break;case Ge:t.setValueType(w.handleNode(i));break;case Ce:t.setValue(w.handleValue(i));break;case K:if(typeof i!="string")throw new Error(`The ${K} field must be a string.`);t.setBlueId(i);break;case Xe:t.setItems(w.handleArray(i));break;case et:t.setBlue(w.handleNode(i));break;case Ae:C.isObject(i)&&!C.isArray(i)&&!p.isReadonlyArray(i)&&Object.entries(i).forEach(([a,c])=>{s[a]=w.handleNode(c)});break;default:r[o]=w.handleNode(i);break}}),Object.keys(r).length>0&&t.setProperties(r),Object.keys(s).length>0&&t.setContracts(s),t}else{if(rt(e))return new d().setItems(w.handleArray(e));{const t=e;return new d().setValue(w.handleValue(t)).setInlineValue(!0)}}}static handleValue(e){if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="number"||O(e))if(ue(e)||Number.isSafeInteger(e)){const t=new A(e.toString()),r=Number.MIN_SAFE_INTEGER,s=Number.MAX_SAFE_INTEGER;return t.lt(r)?new A(r.toString()):t.gt(s)?new A(s.toString()):t}else{const t=parseFloat(e.toString());return new D(t.toString())}else if(typeof e=="boolean")return e;throw new Error(`Can't handle node: ${JSON.stringify(e)}`)}static handleArray(e){if(e!=null){if(C.isObject(e)&&!Array.isArray(e))return[w.handleNode(e)];if(Array.isArray(e))return e.map(w.handleNode);throw new Error("Expected an array node")}}}function qn(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var De,ut;function Ln(){return ut||(ut=1,De=function n(e){if(typeof e=="number"&&isNaN(e))throw new Error("NaN is not allowed");if(typeof e=="number"&&!isFinite(e))throw new Error("Infinity is not allowed");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)=>{if(e[s]===void 0||typeof e[s]=="symbol")return r;const o=r.length===0?"":",";return`${r}${o}${n(s)}:${n(e[s])}`},"")}}`}),De}var _n=Ln();const Wn=qn(_n);class Ot{static canonicalize(e){return Wn(e)}}const Jn=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,Ne=class Ne{constructor(){u(this,"browserCrypto");this.browserCrypto=this.initBrowserCrypto()}static getInstance(){return this.instance||(this.instance=new Ne),this.instance}initBrowserCrypto(){return Jn?null:"crypto"in globalThis?globalThis.crypto:null}hasNodeCrypto(){return!!ct.default.createHash}getBrowserCrypto(){return this.browserCrypto}getNodeCrypto(){return ct.default}};u(Ne,"instance");let Me=Ne;class kt{constructor(){u(this,"cryptoEnv",Me.getInstance())}applySync(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):this.sha256SyncBrowser(t);return ce.default.encode(new Uint8Array(r))}async apply(e){const t=this.canonicalizeInput(e),r=this.cryptoEnv.hasNodeCrypto()?this.sha256Sync(t):await this.sha256Async(t);return ce.default.encode(new Uint8Array(r))}canonicalizeInput(e){const t=Ot.canonicalize(e);if(typeof t!="string")throw new Error("Canonized value must be a string");return t}sha256Sync(e){const t=this.cryptoEnv.getNodeCrypto();if(!t)throw new Error("Synchronous SHA-256 is not available in this environment");return t.createHash("sha256").update(e).digest()}sha256SyncBrowser(e){return mn.sha256.arrayBuffer(e)}async sha256Async(e){if(this.cryptoEnv.hasNodeCrypto())return this.sha256Sync(e);const t=this.cryptoEnv.getBrowserCrypto();if(!t)throw new Error("crypto is not available in this environment");const s=new TextEncoder().encode(e);return t.subtle.digest("SHA-256",s)}}class B{static get(e,t="official"){var H;const r=e.getValue(),s=this.handleValue(r);if(s!==void 0&&t==="simple")return s;const o=(H=e.getItems())==null?void 0:H.map(N=>B.get(N,t));if(o!==void 0&&t==="simple")return o;const i=e.getName(),a=e.getDescription();if(t==="original"&&i===void 0&&a===void 0){if(s!==void 0)return s;if(o!==void 0)return o}const c={};i!==void 0&&(c[Q]=i),a!==void 0&&(c[G]=a);const h=e.getType();if(t==="official"&&r!==void 0&&h===void 0){const N=this.inferTypeBlueId(r);N!==null&&(c[Ee]={[K]:N})}else h!==void 0&&(c[Ee]=B.get(h,t));const f=e.getItemType();f!==void 0&&(c[He]=B.get(f,t));const g=e.getKeyType();g!==void 0&&(c[Qe]=B.get(g,t));const b=e.getValueType();b!==void 0&&(c[Ge]=B.get(b,t)),s!==void 0&&(c[Ce]=s),o!==void 0&&(c[Xe]=o);const y=e.getBlueId();y!==void 0&&(c[K]=y);const m=e.getBlue();m!==void 0&&(c[et]=m);const E=e.getContracts();if(E!==void 0){const N={};Object.entries(E).forEach(([ie,Te])=>{N[ie]=B.get(Te,t)}),c[Ae]=N}const I=e.getProperties();return I!==void 0&&Object.entries(I).forEach(([N,ie])=>{c[N]=B.get(ie,t)}),c}static handleValue(e){if(O(e)){if(ue(e)){const t=new U(Number.MIN_SAFE_INTEGER.toString()),r=new U(Number.MAX_SAFE_INTEGER.toString());if(e.lt(t)||e.gt(r))return e.toString()}return e.toNumber()}return e}static inferTypeBlueId(e){return typeof e=="string"?fe:O(e)?ue(e)?me:ye:typeof e=="boolean"?ge:null}}const Kn=n=>p.isJsonPrimitive(n)&&p.isNonNullable(n),$=class ${constructor(e){u(this,"hashProvider");this.hashProvider=e}static calculateBlueId(e){if(Array.isArray(e)){const r=e.map(s=>B.get(s));return $.INSTANCE.calculate(r)}const t=B.get(e);return $.INSTANCE.calculate(t)}static calculateBlueIdSync(e){if(Array.isArray(e)){const r=e.map(s=>B.get(s));return $.INSTANCE.calculateSync(r)}const t=B.get(e);return $.INSTANCE.calculateSync(t)}calculate(e){const t=this.cleanStructure(e);if(t===void 0)throw new Error("Object after cleaning cannot be null or undefined.");return this.internalCalculate(t,!1)}calculateSync(e){const t=this.cleanStructure(e);if(t===void 0)throw new Error("Object after cleaning cannot be null or undefined.");return this.internalCalculate(t,!0)}internalCalculate(e,t){return Kn(e)||O(e)?this.applyHash(e.toString(),t):Array.isArray(e)||p.isReadonlyArray(e)?this.calculateList(e,t):this.calculateMap(e,t)}calculateMap(e,t){if(e[K]!==void 0)return e[K];const s=Object.keys(e).map(i=>{const a=e[i];if([Q,Ce,G].includes(i))return t?[i,a]:Promise.resolve([i,a]);{const c=this.internalCalculate(a,t);return t?[i,{blueId:c}]:Promise.resolve(c).then(h=>[i,{blueId:h}])}}),o=i=>{const a={};for(const[c,h]of i)a[c]=h;return this.applyHash(a,t)};return t?o(s):Promise.all(s).then(o)}calculateList(e,t){if(e.length===0)throw new Error("Cannot calculate BlueId for an empty list.");let r=this.internalCalculate(e[0],t);const s=(o,i)=>t?this.applyHash([{blueId:o},{blueId:i}],!0):Promise.all([o,i]).then(([a,c])=>this.applyHash([{blueId:a},{blueId:c}],!1));for(let o=1;o<e.length;o++){const i=this.internalCalculate(e[o],t);r=s(r,i)}return r}applyHash(e,t){return t?this.hashProvider.applySync(e):this.hashProvider.apply(e)}cleanStructure(e){if(e!=null){if(p.isJsonPrimitive(e)||O(e))return e;if(Array.isArray(e)||p.isReadonlyArray(e)){const t=e.map(r=>this.cleanStructure(r)).filter(p.isNonNullable);return t.length>0?t:void 0}else if(typeof e=="object"){const t={};for(const r in e){const s=this.cleanStructure(e[r]);s!=null&&(t[r]=s)}return Object.keys(t).length>0?t:void 0}else return e}}};u($,"INSTANCE",new $(new kt));let x=$;class Yn{static convert(e){const t=ce.default.decode(e),r=new Uint8Array(2+t.length);r[0]=18,r[1]=32,r.set(t,2);const s=new Uint8Array(2+r.length);return s[0]=1,s[1]=85,s.set(r,2),"b"+new bn.Encoder({type:"rfc4648",lc:!0}).write(s).finalize().replace(/=/g,"")}}const Re=new WeakMap;function ne(n,e){const t=Re.get(n)||{};return Re.set(n,{...t,...e}),n}const k=n=>Re.get(n),Dt=n=>e=>{const t=k(e);return ne(e,{...t,blueDescription:n})},xt=n=>{const e=k(n);return p.isNonNullable(e)&&C.isString(e.blueDescription)?e.blueDescription:null},Hn=n=>Dt(n)(l.z.string().optional()),Qn=l.z.union([l.z.string(),l.z.boolean()]),Vt=n=>e=>{const t=k(e);return ne(e,{...t,blueId:n})},jt=n=>{const e=k(n),t=Qn.safeParse(e==null?void 0:e.blueId);return t.success?t.data:null},Gn=n=>Vt(n??!0)(l.z.string()),Ft=n=>e=>{const t=k(e);return ne(e,{...t,blueName:n})},zt=n=>{const e=k(n);return p.isNonNullable(e)&&C.isString(e.blueName)?e.blueName:null},Xn=n=>{const e=l.z.string().optional();return Ft(n)(e)},Mt=()=>n=>{const e=k(n);return ne(n,{...e,blueNode:!0})},Rt=n=>{const e=k(n);return p.isNonNullable(e)&&p.isNonNullable(e.blueNode)&&e.blueNode===!0?e.blueNode:null},$e=n=>!!Rt(n),M=()=>{const n=l.z.instanceof(d);return Mt()(n)},Ze="extendedFrom",$t=({schema:n,baseSchema:e})=>{const t=k(n)||{};return ne(n,{...t,[Ze]:e})},Zt=n=>{const e=k(n);return p.isNonNullable(e)&&e[Ze]?e[Ze]:null},st=(n,e)=>{const t=Zt(n);return p.isNullable(t)?!1:(t==null?void 0:t._def)===(e==null?void 0:e._def)?!0:st(t,e)},er=n=>new Proxy(n,{get(e,t,r){return t==="extend"?function(...s){const o=e.extend(...s);return $t({schema:o,baseSchema:e})}:Reflect.get(e,t,r)}}),tr=l.z.object({value:l.z.array(l.z.string()).optional(),defaultValue:l.z.string().optional()}),Ut=n=>{const e=k(n),t=tr.passthrough().safeParse(e==null?void 0:e.typeBlueId);return t.success?t.data:null},v=n=>e=>{const t=k(e),r=typeof n=="string"?{value:[n]}:n,s=er(e);return ne(s,{...t,typeBlueId:{...(t==null?void 0:t.typeBlueId)||{},...r}})};class Oe{static resolveBlueId(e){var o;const t=Ut(e);if(p.isNullable(t))return null;const r=t.defaultValue;if(p.isNonNullable(r))return r;const s=(o=t.value)==null?void 0:o[0];return p.isNonNullable(s)?s:Oe.getRepositoryBlueId(t,e)}static getRepositoryBlueId(e,t){throw new Error("Not implemented")}}class nr{constructor(e){u(this,"blueIdMap",new Map);for(const t of e)this.registerSchema(t)}registerSchema(e){const t=Oe.resolveBlueId(e);if(p.isNonNullable(t)){if(this.blueIdMap.has(t))throw new Error(`Duplicate BlueId value: ${t}`);this.blueIdMap.set(t,e)}}resolveSchema(e){const t=this.getEffectiveBlueId(e);return p.isNullable(t)?null:this.blueIdMap.get(t)}getEffectiveBlueId(e){const t=e.getType();return p.isNonNullable(t)&&p.isNonNullable(t.getBlueId())?t.getBlueId():p.isNonNullable(t)?x.calculateBlueIdSync(t):null}getBlueIdMap(){return new Map(this.blueIdMap)}}class V{static transform(e,t){const r=t(e.clone()),s=r.getType();s!==void 0&&r.setType(V.transform(s,t));const o=r.getItemType();o!==void 0&&r.setItemType(V.transform(o,t));const i=r.getKeyType();i!==void 0&&r.setKeyType(V.transform(i,t));const a=r.getValueType();a!==void 0&&r.setValueType(V.transform(a,t));const c=r.getItems();if(c!==void 0){const g=c.map(b=>V.transform(b,t));r.setItems(g)}const h=r.getProperties();if(h!==void 0){const g=Object.keys(h).reduce((b,y)=>(b[y]=V.transform(h[y],t),b),{});r.setProperties(g)}const f=r.getContracts();if(f!==void 0){const g=Object.keys(f).reduce((b,y)=>(b[y]=V.transform(f[y],t),b),{});r.setContracts(g)}return r}}class qt{static convertValue(e,t){var o;const r=(o=e.getType())==null?void 0:o.getBlueId(),s=e.getValue();return p.isNullable(s)?this.isPrimitive(t)?this.getDefaultPrimitiveValue(t):s:fe===r?this.convertFromString(String(s),t):ye===r||s instanceof D?this.convertFromBigDecimal(new D(s==null?void 0:s.toString()),t):me===r||s instanceof A?this.convertFromBigInteger(new A(s==null?void 0:s.toString()),t):ge===r||typeof s=="boolean"?this.convertFromBoolean(!!s,t):this.convertFromString(String(s),t)}static convertFromString(e,t){if(!t||t instanceof l.ZodString||t instanceof l.ZodEnum||t instanceof l.ZodNativeEnum)return e;if(t instanceof l.ZodNumber)return Number(e);if(t instanceof l.ZodBoolean)return e.toLowerCase()==="true";if(t instanceof l.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert String to ${t.constructor.name}`)}static convertFromBigDecimal(e,t){if(t instanceof l.ZodNumber)return e.toNumber();if(t instanceof l.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t.constructor.name}`)}static convertFromBigInteger(e,t){if(t instanceof l.ZodNumber)return e.toNumber();if(t instanceof l.ZodBigInt)return BigInt(e.toString());if(t instanceof l.ZodString)return e.toString();throw new Error(`Cannot convert Number to ${t.constructor.name}`)}static convertFromBoolean(e,t){if(!t||t instanceof l.ZodBoolean)return e;if(t instanceof l.ZodString)return e.toString();if(t instanceof l.ZodNumber)return Number(e);if(t instanceof l.ZodBigInt)return BigInt(e);throw new Error(`Cannot convert Boolean to ${t.constructor.name}`)}static isPrimitive(e){return e?e instanceof l.ZodString||e instanceof l.ZodNumber||e instanceof l.ZodBoolean||e instanceof l.ZodBigInt:!1}static getDefaultPrimitiveValue(e){if(!e)return null;if(e instanceof l.ZodNumber)return 0;if(e instanceof l.ZodBoolean)return!1;if(e instanceof l.ZodString)return"";throw new Error(`Unsupported primitive type: ${e.constructor.name}`)}}class rr{convert(e,t){return qt.convertValue(e,t)}}class sr{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof l.ZodAny||e instanceof l.ZodObject||e instanceof l.ZodRecord||e instanceof l.ZodMap||e instanceof l.ZodUnknown}convert(e,t){return this.convertFields(e,t)}convertFields(e,t){if(t instanceof l.ZodIntersection){const r=t._def.left,s=t._def.right,o=this.convert(e,r),i=this.convert(e,s);return{...o,...i}}if(t instanceof l.ZodUnion)throw new Error("Union not supported");if(t instanceof l.ZodObject)return Object.keys(t.shape).reduce((s,o)=>{const i=e.getProperties(),a=t.shape[o],c=jt(a);if(p.isNonNullable(c)){const m=C.isString(c)?c:o,E=i==null?void 0:i[m],I=E?x.calculateBlueIdSync(E):void 0;return s[o]=I,s}const h=zt(a);if(p.isNonNullable(h)){const m=i==null?void 0:i[h];return s[o]=m==null?void 0:m.getName(),s}const f=xt(a);if(p.isNonNullable(f)){const m=i==null?void 0:i[f];return s[o]=m==null?void 0:m.getDescription(),s}if(o==="name"){const m=e.getName();return s[o]=m,s}if(o==="description"){const m=e.getDescription();return s[o]=m,s}const g=e.getContracts();if(o==="contracts"&&p.isNonNullable(g)&&this.canHandleStructuredData(a)){const m=Object.fromEntries(Object.entries(g).map(([I,H])=>[I,B.get(H)])),E=w.deserialize(m);s[o]=this.nodeToObjectConverter.convert(E,a)}const b=i==null?void 0:i[o];if(p.isNullable(b))return s;const y=this.nodeToObjectConverter.convert(b,a);return s[o]=y,s},{});throw new Error("Unknown schema type, "+t.constructor.name)}}class or{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t.element;return r.map(i=>this.nodeToObjectConverter.convert(i,s))}}class ir{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t._def.valueType,o=r.map(i=>this.nodeToObjectConverter.convert(i,s));return new Set(o)}}class ar{constructor(e){this.nodeToObjectConverter=e}canHandleStructuredData(e){return e instanceof l.ZodAny||e instanceof l.ZodObject||e instanceof l.ZodRecord||e instanceof l.ZodMap||e instanceof l.ZodUnknown}convert(e,t){const r=t.keySchema,s=t.valueSchema,o=new Map,i=e.getName();p.isNonNullable(i)&&o.set(Q,i);const a=e.getDescription();p.isNonNullable(a)&&o.set(G,a);const c=e.getContracts();if(p.isNonNullable(c)&&this.canHandleStructuredData(s)){let f=!1;const g=Object.entries(c).reduce((b,[y,m])=>{try{const E=this.nodeToObjectConverter.convert(m,s);E!=null&&!Number.isNaN(E)&&(b[y]=E,f=!0)}catch{}return b},{});f&&o.set(Ae,g)}const h=e.getProperties();return p.isNonNullable(h)&&Object.entries(h).forEach(([f,g])=>{const b=new d().setValue(f);b.setType(new d().setBlueId(fe));const y=qt.convertValue(b,r),m=this.nodeToObjectConverter.convert(g,s);o.set(y,m)}),t instanceof l.ZodRecord?Object.fromEntries(o):o}}class lr{convert(e){return B.get(e)}}class cr{convert(e){return B.get(e)}}class ur{constructor(e){this.nodeToObjectConverter=e}convert(e,t){const r=e.getItems();if(!r)return;const s=t.items;return r.map((i,a)=>this.nodeToObjectConverter.convert(i,s[a]))}}const hr=l.z.union([l.z.literal("ZodString"),l.z.literal("ZodNumber"),l.z.literal("ZodBoolean"),l.z.literal("ZodBigInt"),l.z.literal("ZodArray"),l.z.literal("ZodSet"),l.z.literal("ZodMap"),l.z.literal("ZodRecord"),l.z.literal("ZodObject"),l.z.literal("ZodEnum"),l.z.literal("ZodNativeEnum"),l.z.literal("ZodUnknown"),l.z.literal("ZodAny"),l.z.literal("ZodTuple")]);class dr{constructor(e){u(this,"converters",new Map);u(this,"complexObjectConverter");this.nodeToObjectConverter=e,this.registerConverters(),this.complexObjectConverter=new sr(this.nodeToObjectConverter)}registerConverters(){const e=new rr,t=new or(this.nodeToObjectConverter),r=new ur(this.nodeToObjectConverter),s=new ir(this.nodeToObjectConverter),o=new ar(this.nodeToObjectConverter);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 lr),this.converters.set("ZodAny",new cr),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)}getConverter(e){const t=this.getSchemaTypeName(e);return this.converters.get(t)??this.complexObjectConverter}isWrapperType(e){return e instanceof l.ZodOptional||e instanceof l.ZodNullable||e instanceof l.ZodReadonly||e instanceof l.ZodBranded||e instanceof l.ZodEffects||e instanceof l.ZodLazy}getSchemaTypeName(e){if(this.isWrapperType(e))return e instanceof l.ZodEffects?this.getSchemaTypeName(e.innerType()):e instanceof l.ZodLazy?this.getSchemaTypeName(e.schema):this.getSchemaTypeName(e.unwrap());const t=e.constructor.name;try{return hr.parse(t)}catch{throw new Error(`Schema type name ${t} is not supported`)}}}class Lt{constructor(e){u(this,"converterFactory");this.typeSchemaResolver=e,this.converterFactory=new dr(this)}convert(e,t){var i;const r=(i=this.typeSchemaResolver)==null?void 0:i.resolveSchema(e),s=this.unwrapSchema(t);if($e(s))return e;let o=s;return p.isNonNullable(r)&&st(r,s)&&(o=r),this.convertWithType(e,o)}convertWithType(e,t){return this.converterFactory.getConverter(t).convert(e,t)}isWrapperType(e){return e instanceof l.ZodOptional||e instanceof l.ZodNullable||e instanceof l.ZodReadonly||e instanceof l.ZodBranded||e instanceof l.ZodEffects||e instanceof l.ZodLazy}unwrapSchema(e){return $e(e)?e:this.isWrapperType(e)?e instanceof l.ZodEffects?this.unwrapSchema(e.innerType()):e instanceof l.ZodLazy?this.unwrapSchema(e.schema):this.unwrapSchema(e.unwrap()):e}}class ke{fetchFirstByBlueId(e){const t=this.fetchByBlueId(e);return t&&t.length>0?t[0]:null}}function pr(n){return new class extends ke{fetchByBlueId(e){return n(e)}}}class fr extends ke{constructor(t){super();u(this,"nodeProviders");this.nodeProviders=t}fetchByBlueId(t){for(const r of this.nodeProviders){const s=r.fetchByBlueId(t);if(s&&s.length>0)return s}return[]}fetchFirstByBlueId(t){for(const r of this.nodeProviders){const s=r.fetchFirstByBlueId(t);if(s)return s}return null}getNodeProviders(){return this.nodeProviders}}const xe=Y.types.float.options,yr={...xe,construct:n=>{const e=n.replace(/_/g,"").toLowerCase();if(!p.isPreciseNumberString(e))return new D(e);if(xe.construct)return xe.construct(n)}},mr=new Y.Type("tag:yaml.org,2002:float",yr),Ve=Y.types.int.options,gr={...Ve,construct:n=>{let e=n;if(e.indexOf("_")!==-1&&(e=e.replace(/_/g,"")),!p.isPreciseNumberString(e))return new A(e);if(Ve.construct)return Ve.construct(n)}},br=new Y.Type("tag:yaml.org,2002:int",gr),_t=Y.CORE_SCHEMA.extend({implicit:[mr,br]}),ee=n=>{const e=Y.load(n,{schema:_t});return e===void 0?void 0:e},wr=n=>Y.dump(n,{schema:_t,replacer:(e,t)=>{if(O(t)){if(ue(t)){const r=new U(Number.MIN_SAFE_INTEGER.toString()),s=new U(Number.MAX_SAFE_INTEGER.toString());if(t.lt(r)||t.gt(s))return t.toString()}return t.toNumber()}return t}}),Wt=`- type:
2
+ blueId: 27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo
3
+ mappings:
4
+ Text: F92yo19rCcbBoBSpUA5LRxpfDejJDAaP1PRxxbWAraVP
5
+ Double: 68ryJtnmui4j5rCZWUnkZ3DChtmEb7Z9F8atn1mBSM3L
6
+ Integer: DHmxTkFbXePZHCHCYmQr2dSzcNLcryFVjXVHkdQrrZr8
7
+ Boolean: EL6AjrbJsxTWRTPzY8WR8Y2zAMXRbydQj83PcZwuAHbo
8
+ List: G8wmfjEqugPEEXByMYWJXiEdbLToPRWNQEekNxrxfQWB
9
+ Dictionary: 294NBTj2mFRL3RB4kDRUSckwGg7Kzj6T8CTAFeR1kcSA
10
+ - type:
11
+ blueId: FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4
12
+ `,Tr=`name: Transformation
13
+ description: TODO`,Er=`name: Infer Basic Types For Untyped Values
14
+ type:
15
+ blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
16
+ description: This transformation infers type details for Text, Integer, Number and Boolean.`,Ir=`name: Replace Inline Types with BlueIds
17
+ type:
18
+ blueId: Ct1SGRGw1i47qjzm1ruiUdSZofeV6WevPTGuieVvbRS4
19
+ description: This transformation replaces`,vr=[Wt,Tr,Er,Ir];class Br extends ke{constructor(){super();u(this,"blueIdToNodesMap",new Map);this.load()}fetchByBlueId(t){return this.blueIdToNodesMap.get(t)||[]}load(){for(const t of vr){const r=ee(t);if(r===void 0){console.error(`This content file is not valid YAML: ${t}`);continue}if(Array.isArray(r)){const s=r.map(i=>w.deserialize(i)),o=x.calculateBlueIdSync(s);this.blueIdToNodesMap.set(o,s)}else{const s=w.deserialize(r),o=x.calculateBlueIdSync(s);this.blueIdToNodesMap.set(o,[s])}}}}const Pe=class Pe extends ke{constructor(){super();u(this,"nodeProvider");this.nodeProvider=new Br}fetchByBlueId(t){return this.nodeProvider.fetchByBlueId(t)}};u(Pe,"INSTANCE",new Pe);let Ue=Pe;class de{static wrap(e){return new fr([Ue.INSTANCE,e])}}const Jt=n=>n instanceof d||Array.isArray(n)&&n.every(e=>e instanceof d)?n:C.isArray(n)?n.map(e=>w.deserialize(e)):w.deserialize(n),Kt=async n=>{const e=Jt(n);return x.calculateBlueId(e)},Nr=n=>{const e=Jt(n);return x.calculateBlueIdSync(e)},qe=async n=>{if(Pt(n))return n;try{const e=he.parse(n),t=await Kt(e);return{...n,blueId:t}}catch(e){throw new Error(`Failed enriching object with Blue ID: ${e}`)}},Pr=n=>n==null?void 0:n.items,Sr=n=>n==null?void 0:n.value,Cr=n=>p.isNullable(n)?{}:C.omit(n,Tn),Ar=n=>Ct(n)?n.type.name??null:At(n)?C.pascal(typeof n.value):St(n)?"List":null,Yt=n=>p.isNonNullable(n)&&Object.keys(C.omit(n,["blueId"])).length>0,Or=n=>{try{const e=w.deserialize(n),t=B.get(e);return X.parse(t)}catch(e){throw new Error(`Failed transforming JSON-like value to BlueObject: ${e}`)}},Le=async n=>{const{resolveFunction:e,signal:t=new AbortController().signal,omitItems:r}=n,s=n.count??n.items.length;let o=await C.map(n.items,async a=>await qe(a));const i=Math.max((o==null?void 0:o.length)-s,0);for(let a=o.length-1;a>=i;a--)if(!Yt(o[a])){const c=await e(o[a],{signal:t});if(Array.isArray(c))return Le({...n,items:[...o.slice(0,a),...c,...o.slice(a+1)]});const h=await qe(c);if(r!=null&&r.includes(h.blueId))return Le({...n,items:[...o.slice(0,a),...o.slice(a+1)]});o=[...o.slice(0,a),h,...o.slice(a+1)]}return o};function ae(n){try{const e=new URL(n);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}class kr{process(e){return V.transform(e,this.inferType.bind(this))}inferType(e){const t=e.getType(),r=e.getValue();return p.isNullable(t)&&p.isNonNullable(r)&&(typeof r=="string"?e.setType(new d().setBlueId(fe)):typeof r=="bigint"||ue(r)?e.setType(new d().setBlueId(me)):Rn(r)?e.setType(new d().setBlueId(ye)):typeof r=="boolean"&&e.setType(new d().setBlueId(ge))),e}}const le=class le{constructor(e){u(this,"mappings",new Map);if(e instanceof d){const r=e.getProperties();if(r&&r[le.MAPPINGS]){const o=r[le.MAPPINGS].getProperties();o&&Object.entries(o).forEach(([i,a])=>{const c=a.getValue();typeof c=="string"&&this.mappings.set(i,c)})}}else this.mappings=e}process(e){return V.transform(e,this.transformNode.bind(this))}transformNode(e){const t=e.clone();return this.transformTypeField(t,t.getType()),this.transformTypeField(t,t.getItemType()),this.transformTypeField(t,t.getKeyType()),this.transformTypeField(t,t.getValueType()),t}transformTypeField(e,t){if(t&&t.isInlineValue()&&t.getValue()!==void 0){const r=String(t.getValue());if(this.mappings.has(r)){const s=this.mappings.get(r);if(s){const o=new d().setBlueId(s);t===e.getType()?e.setType(o):t===e.getItemType()?e.setItemType(o):t===e.getKeyType()?e.setKeyType(o):t===e.getValueType()&&e.setValueType(o)}}}}};u(le,"MAPPINGS","mappings");let _e=le;class Dr{constructor(e,t){u(this,"nodeProvider");u(this,"strategy");this.nodeProvider=de.wrap(e),this.strategy=t||"THROW_EXCEPTION"}extend(e,t){this.extendNode(e,t,"")}extendNode(e,t,r,s=!1){if(!s){if(!t.shouldExtendPathSegment(r,e))return;t.enterPathSegment(r,e)}try{const o=e.getBlueId();if(o&&!(o in tt)){const y=this.fetchNode(e);if(y&&y.length>0)if(y.length===1){const m=y[0];this.mergeNodes(e,m)}else{const m=y.map(I=>I.clone()),E=new d().setItems(m);this.mergeNodes(e,E)}}const i=e.getType();i&&this.extendNode(i,t,"type",!0);const a=e.getItemType();a&&this.extendNode(a,t,"itemType",!0);const c=e.getKeyType();c&&this.extendNode(c,t,"keyType",!0);const h=e.getValueType();h&&this.extendNode(h,t,"valueType",!0);const f=e.getProperties();f&&Object.entries(f).forEach(([y,m])=>{this.extendNode(m,t,y,!1)});const g=e.getContracts();g&&Object.entries(g).forEach(([y,m])=>{this.extendNode(m,t,y,!1)});const b=e.getItems();if(b&&b.length>0){this.reconstructList(b);for(let y=0;y<b.length;y++)this.extendNode(b[y],t,String(y),!1)}}finally{s||t.exitPathSegment()}}reconstructList(e){for(;e.length>0;){const t=e[0],r=t==null?void 0:t.getBlueId();if(!r)break;const s=this.nodeProvider.fetchByBlueId(r);if(!s||s.length===1)break;e.shift(),e.unshift(...s)}}fetchNode(e){const t=e.getBlueId();if(!t){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No blueId found for node: ${e.getName()}`)}const r=this.nodeProvider.fetchByBlueId(t);if(!r||r.length===0){if(this.strategy==="RETURN_EMPTY")return null;throw new Error(`No content found for blueId: ${e.getBlueId()}`)}return r}mergeNodes(e,t){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())}}class xr{}function ht(n,e){const t=n.split(e),r=[...t].reverse().findIndex(o=>o!==""),s=r===-1?0:t.length-r;return t.slice(0,s)}class Ht extends xr{constructor(t,r){super();u(this,"allowedPaths");u(this,"maxDepth");u(this,"currentPath",[]);this.allowedPaths=t,this.maxDepth=r}shouldExtendPathSegment(t){if(this.currentPath.length>=this.maxDepth)return!1;const r=this.normalizePath(this.getCurrentFullPath()+"/"+t);return this.isAllowedPath(r)}shouldMergePathSegment(t){return this.shouldExtendPathSegment(t)}isAllowedPath(t){for(const r of this.allowedPaths)if(this.matchesAllowedPath(r,t))return!0;return!1}matchesAllowedPath(t,r){const s=ht(t,"/"),o=ht(r,"/");if(o.length>s.length)return!1;for(let i=1;i<o.length;i++)if(s[i]!=="*"&&s[i]!==o[i])return!1;return!0}enterPathSegment(t){this.currentPath.push(t)}exitPathSegment(){this.currentPath.length>0&&this.currentPath.pop()}getCurrentFullPath(){return"/"+this.currentPath.join("/")}normalizePath(t){return"/"+t.split("/").filter(r=>r!=="").join("/")}static withMaxDepth(t){return new dt().setMaxDepth(t).addPath("*").build()}static withSinglePath(t){return new dt().addPath(t).build()}}class dt{constructor(){u(this,"allowedPaths",new Set);u(this,"maxDepth",Number.MAX_SAFE_INTEGER)}addPath(e){return this.allowedPaths.add(e),this}setMaxDepth(e){return this.maxDepth=e,this}build(){return new Ht(this.allowedPaths,this.maxDepth)}}const z={"MyOS Timeline Channel":"MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R","MyOS Timeline Entry":"uDxZ7dr6Eo2MkKoutP5qxkh3uxQCS1VAptiCPc2R7B7f","MyOS Agent":"AgentBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V","MyOS Agent Channel":"AgentCh4nn3lBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V","MyOS Agent Event":"AgentEv3ntBlu3Id7dr6Eo2MkKoutP5qxkh3uxQCS1V"},T={Channel:"2RMkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc","Timeline Channel":"RMkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2","Composite Timeline Channel":"qxkh3uMkKoutP5DxZ7dr6Eo27B7fuxQCS1VAptiCPc2R","MyOS Timeline Channel":"MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R","Sequential Workflow":"h3uDxZ7dr6Eo27B7fuxMkKoutP5qxkQCS1VAptiCPc2R","Sequential Workflow Step":"6EoMkKoutP5DxZ7drqxkh3u27B7fuxQCS1VAptiCPc2R","Process Embedded":"DxZ7dr6EoMkKoutP5qxkh3u27B7fuxQCS1VAptiCPc2R","Embedded Node Channel":"MkKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2","Document Update Channel":"MkKoutP5qxkh3uDQCS1VAptiCPc2xZ7dr6Eo27B7fux","Channel Event Checkpoint":"o27B7fuxMkKoutPh3uDxZ7dr6E5qxkQCS1VAptiCPc2R","Update Document":"7fuxMkKoutPh3uDxZ7dr6E5qxkQCS1VAptiCPc2R","Trigger Event":"kQCS1VAp7fuxMkKoutPh3uDxZ7dr6E5qxtiCPc2R","Json Patch Entry":"EnUQeMiMa2wHFW3JbeSPvdgfpL6qZYCR29m3SfeHsKSY","JavaScript Code":"MkKoutPDxZ7dr6Eo5qxkh3u27B7fuxQCS1VAptiCPc2R","Timeline Entry":"uDxZ7dr6Eo27B7fMkKoutP5qxkh3uxQCS1VAptiCPc2R",Operation:"OpKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiCPc2R","Sequential Workflow Operation":"SeqOpKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiC","Operation Request":"OpReqKoutP5qxkh3uDxZ7dr6Eo27B7fuxQCS1VAptiC"},we=v(T.Channel)(l.z.object({name:l.z.string().optional(),description:l.z.string().optional()})),Vr=v(T["Composite Timeline Channel"])(we.extend({channels:l.z.array(l.z.string()).optional()})),jr=v(T["Document Update Channel"])(we.extend({path:l.z.string().optional()})),pt=v(T["Embedded Node Channel"])(we.extend({path:l.z.string().optional()})),Fr=v(T.Operation)(l.z.object({request:M().optional(),description:l.z.string().optional(),channel:l.z.string().optional()})),zr=v(T["Operation Request"])(l.z.object({operation:l.z.string().optional(),request:M(),document:l.z.object({blueId:l.z.string().optional()}).optional(),allowNewerVersion:l.z.boolean().optional()})),We=v(T["Process Embedded"])(l.z.object({paths:l.z.array(l.z.string()).optional()})),Je=v(T["Sequential Workflow"])(l.z.object({steps:l.z.array(M()).optional(),channel:l.z.string().optional()})),Mr=v(T["Sequential Workflow Operation"])(Je.omit({channel:!0}).extend({operation:l.z.string().optional()})),Qt=v(T["Timeline Channel"])(we.extend({timelineId:l.z.string().optional()})),Ie=v(T["Timeline Entry"])(l.z.object({timelineId:l.z.string().optional(),timelinePrev:l.z.string().optional(),thread:l.z.string().optional(),threadPrev:l.z.string().optional(),message:M(),signature:l.z.string().optional()})),je=v(T["Trigger Event"])(l.z.object({event:M()})),Rr=v(T["Json Patch Entry"])(l.z.object({name:l.z.string().optional(),description:l.z.string().optional(),val:M().optional(),op:l.z.string().optional(),path:l.z.string().optional()})),Fe=v(T["Update Document"])(l.z.object({changeset:l.z.array(Rr)})),$r=v(z["MyOS Timeline Channel"])(Qt.extend({account:l.z.string().optional(),email:l.z.string().optional()})),Zr=v(z["MyOS Timeline Entry"])(Ie.extend({account:l.z.string().optional(),email:l.z.string().optional()})),Ur=v(z["MyOS Agent"])(l.z.object({agentId:l.z.string().optional()})),qr=v(z["MyOS Agent Channel"])(we.extend({agent:Ur.optional(),event:M().optional()})),Lr=v(z["MyOS Agent Event"])(l.z.object({agentId:l.z.string().optional(),id:l.z.number().optional(),timestamp:l.z.number().optional(),event:M().optional()}));class _{static initialize(...e){this.blueIdsCollections=[...e]}static registerBlueIds(...e){this.blueIdsCollections.push(...e)}static generateMappingsYaml(e="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo"){const t={};for(const s of this.blueIdsCollections)Object.assign(t,s);const r=Object.entries(t).map(([s,o])=>` ${s}: ${o}`).join(`
20
+ `);return`- type:
21
+ blueId: ${e}
22
+ mappings:
23
+ ${r}`}static getAllBlueIds(){const e={};for(const t of this.blueIdsCollections)Object.assign(e,t);return e}static getAllBlueIdNames(){return Object.keys(this.getAllBlueIds())}static clear(){this.blueIdsCollections=[]}static getCollectionCount(){return this.blueIdsCollections.length}static getTotalBlueIdCount(){return Object.keys(this.getAllBlueIds()).length}}u(_,"blueIdsCollections",[]);const Se=class Se{constructor(e,t){u(this,"processorProvider");u(this,"nodeProvider");u(this,"defaultSimpleBlue",null);t?(this.processorProvider=e,this.nodeProvider=de.wrap(t)):(this.processorProvider=Se.getStandardProvider(),this.nodeProvider=de.wrap(e)),_.initialize(T,z),this.loadDefaultSimpleBlue()}static registerBlueIds(...e){_.registerBlueIds(...e)}static resetBlueIdsToDefaults(){_.clear(),_.initialize(T,z)}static getAllRegisteredBlueIds(){return _.getAllBlueIds()}preprocess(e){return this.preprocessWithOptions(e,null)}preprocessWithDefaultBlue(e){return this.preprocessWithOptions(e,this.defaultSimpleBlue)}preprocessWithOptions(e,t){let r=e.clone(),s=r.getBlue();if(!s&&t&&(s=t.clone()),s){new Dr(this.nodeProvider).extend(s,Ht.withSinglePath("/*"));const o=s.getItems();if(o&&o.length>0){for(const i of o){const a=this.processorProvider.getProcessor(i);if(a)r=a.process(r);else throw new Error(`No processor found for transformation: ${i}`)}r.setBlue(void 0)}}return r}static getStandardProvider(){return{getProcessor(e){var o;const t="27B7fuxQCS1VAptiCPc2RMkKoutP5qxkh3uDxZ7dr6Eo",r="FGYuTXwaoSKfZmpTysLTLsb8WzSqf43384rKZDkXhxD4",s=(o=e.getType())==null?void 0:o.getBlueId();if(t===s)return new _e(e);if(r===s)return new kr}}}enrichDefaultBlue(e){const t=_.generateMappingsYaml();return`
24
+ ${e}
25
+ ${t}
26
+ `}loadDefaultSimpleBlue(){const e=this.enrichDefaultBlue(Wt);try{const t=ee(e);if(t)this.defaultSimpleBlue=w.deserialize(t);else throw new Error("Failed to parse default Blue content")}catch(t){throw new Error(`Error loading default Blue: ${t}`)}}};u(Se,"DEFAULT_BLUE_BLUE_ID","FREHAAGDZSzpnoTUoCQ86bBmxbVCULMjvx9JZM6fyqT1");let ve=Se;class _r{constructor(e,t){u(this,"preprocessingAliases",new Map);u(this,"urlContentFetcher");e&&(this.preprocessingAliases=new Map(e)),this.urlContentFetcher=t}process(e){const t=this.getBlueNodeValue(e);if(t){const r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(J.isPotentialBlueId(t))return this.handleBlueId(r,t);throw ae(t)?new Error(`URL '${t}' detected. Use the async version of this method to fetch the content.`):new Error(`Invalid blue value: ${t}`)}return e}async processAsync(e){const t=this.getBlueNodeValue(e);if(t){const r=e.clone();if(this.preprocessingAliases.has(t))return this.handleAliasValue(r,t);if(J.isPotentialBlueId(t))return this.handleBlueId(r,t);if(ae(t)&&this.urlContentFetcher)try{const s=await this.fetchFromUrl(t);return s&&r.setBlue(new d().setItems(s)),r}catch(s){throw s instanceof Error?new Error(`Failed to fetch from URL '${t}'.
27
+ ${s.message}`):s}else throw ae(t)?new Error(`UrlContentFetcher not provided for URL: ${t}`):new Error(`Invalid blue value: ${t}`)}return e}getBlueNodeValue(e){const t=e.getBlue(),r=t==null?void 0:t.getValue();return r&&typeof r=="string"?r:null}handleAliasValue(e,t){return e.setBlue(new d().setBlueId(this.preprocessingAliases.get(t))),e}handleBlueId(e,t){return e.setBlue(new d().setBlueId(t)),e}async fetchFromUrl(e){if(!this.urlContentFetcher)throw new Error(`UrlContentFetcher not provided for URL: ${e}`);return await this.urlContentFetcher.fetchAndCache(e)}getPreprocessingAliases(){return new Map(this.preprocessingAliases)}setPreprocessingAliases(e){return this.preprocessingAliases=new Map(e),this}addPreprocessingAliases(e){return e.forEach((t,r)=>{this.preprocessingAliases.set(r,t)}),this}setUrlContentFetcher(e){return this.urlContentFetcher=e,this}getUrlContentFetcher(){return this.urlContentFetcher}}const Wr={fetchUrl:async n=>{throw new Error(`You must provide a custom UrlFetchStrategy to fetch content from URL: ${n}`)}};class Jr{constructor(e){u(this,"cache",new Map);u(this,"fetchStrategy");u(this,"enabled",!1);u(this,"allowedDomains",[]);this.fetchStrategy=e||Wr}validateUrl(e){if(!ae(e))throw new Error(`Invalid URL: ${e}`);return!0}isDomainAllowed(e){if(this.allowedDomains.length===0)return!0;try{const t=new URL(e);return this.allowedDomains.some(r=>t.hostname===r||t.hostname.endsWith(`.${r}`))}catch{return!1}}getFromCache(e){try{return this.validateUrl(e),this.cache.get(e)||[]}catch{return[]}}async fetchAndCache(e){if(this.validateUrl(e),!this.enabled)throw new Error("URL fetching is disabled. Enable it using the enableFetching method.");if(!this.isDomainAllowed(e))throw new Error(`Domain not allowed for URL: ${e}.`);let t;try{t=await this.fetchStrategy.fetchUrl(e)}catch(a){throw new Error(`Error fetching from URL: ${e}`,{cause:a})}const{data:r,contentType:s}=t;let o;if(s.includes("application/json")||s.includes("text/yaml")||s.includes("application/yaml")||s.includes("text/plain"))o=ee(r);else throw new Error(`Unsupported content type from URL: ${s}`);if(o===void 0)throw new Error(`Failed to parse content from URL: ${e}`);let i;return Array.isArray(o)?i=o.map(a=>w.deserialize(a)):i=[w.deserialize(o)],this.cache.set(e,i),i}prefetchUrl(e,t){try{this.validateUrl(e),this.cache.set(e,t)}catch{}}clearCache(){this.cache.clear()}setFetchStrategy(e){return this.fetchStrategy=e,this}getFetchStrategy(){return this.fetchStrategy}enableFetching(){return this.enabled=!0,this.allowedDomains=[],this}enableFetchingForDomains(e){return this.enabled=!0,this.allowedDomains=[...e],this}disableFetching(){return this.enabled=!1,this}isFetchingEnabled(){return this.enabled}getAllowedDomains(){return[...this.allowedDomains]}allowDomain(e){return this.allowedDomains.includes(e)||this.allowedDomains.push(e),this}disallowDomain(e){return this.allowedDomains=this.allowedDomains.filter(t=>t!==e),this}clearAllowedDomains(){return this.allowedDomains=[],this}}const Kr=(n,e)=>({on:(t,r)=>({end:()=>r(null)})});async function Yr(n){return new Promise((e,t)=>{Kr().on("error",t).end()})}const Z=(...n)=>n.map((e,t)=>{if(typeof e!="string")return"";if(t===0&&e==="/")return"/";const r=t>0?e.replace(/^\/+/,""):e;return t<n.length-1?r.replace(/\/+$/,""):r}).filter(Boolean).join("/").replace(/\/{2,}/g,"/");class Gt{constructor(e,t,r,s){u(this,"actions",[]);this.getDocument=e,this.taskInfo=t,this.blue=r,this.onFlush=s}get(e){const t=this.getDocument(),r=Z(this.taskInfo.nodePath,e);return t.get(r)}addPatch(e){this.actions.push({kind:"patch",patch:{...e,path:Z(this.taskInfo.nodePath,e.path)}})}emitEvent(e){const t=this.taskInfo.event,r=t.trace??[],s={...e,originNodePath:e.originNodePath??this.taskInfo.nodePath,rootEvent:e.rootEvent??t.rootEvent??t,trace:[...r]};this.actions.push({kind:"event",event:s})}async flush(){var t;if(!this.actions.length)return[];const e=[...this.actions];return this.actions.length=0,await((t=this.onFlush)==null?void 0:t.call(this,e)),e}getNodePath(){return this.taskInfo.nodePath}resolvePath(e){return Z(this.taskInfo.nodePath,e)}getTaskInfo(){return this.taskInfo}getBlue(){return this.blue}loadExternalModule(e){if(!/^https?:\/\//.test(e))throw new Error("Only http/https URLs are allowed");return Yr()}loadBlueContent(e){throw new Error("Not implemented")}}class Xt extends Error{constructor(e,t){super(`Cannot apply patch ${JSON.stringify(e)}`),this.patch=e,this.cause=t,this.name="PatchApplicationError"}}class en extends Error{constructor(e,t,r){super(`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}")`),this.patch=e,this.offendingPath=t,this.contractNodePath=r,this.name="EmbeddedDocumentModificationError"}}class ft extends Error{constructor(e,t){super(`Failed to evaluate expression "${e}"`),this.code=e,this.cause=t,this.name="ExpressionEvaluationError"}}class yt extends Error{constructor(e,t){super(`Failed to evaluate code block "${e}"`),this.code=e,this.cause=t,this.name="CodeBlockEvaluationError"}}class q{static isTypeOf(e,t){var o;const r=Oe.resolveBlueId(t),s=(o=e.getType())==null?void 0:o.getBlueId();return p.isNullable(r)||p.isNullable(s)?!1:r===s}}const L=n=>!!n&&typeof n=="object"&&!Array.isArray(n)&&!(n instanceof d),F=n=>n instanceof A||n instanceof D,Hr=n=>n.replace(/~1/g,"/").replace(/~0/g,"~");function re(n){if(n==="/")return[];if(!n.startsWith("/"))throw new Error(`Path must start with '/': ${n}`);return n.split("/").slice(1).map(Hr)}function te(n){if(n==="-")return-1;const e=typeof n=="number"?n:parseInt(n,10);if(isNaN(e))throw new Error(`Invalid array index (NaN) from '${n}'`);if(!Number.isFinite(e))throw new Error(`Invalid array index '${n}' results in non-finite number ${e}`);return e}function tn(n,e,t,r=!0){switch(e){case"name":return t?r?n.getName()??null:n:n.getName();case"description":return t?r?n.getDescription():n:n.getDescription();case"type":return n.getType();case"itemType":return n.getItemType();case"keyType":return n.getKeyType();case"valueType":return n.getValueType();case"value":return t?r?n.getValue()??null:n:n.getValue();case"blueId":return t?r?n.getBlueId()??null:n:n.getBlueId();case"blue":return n.getBlue();case"items":return n.getItems();case"properties":return n.getProperties();case"contracts":return n.getContracts();default:return}}function mt(n,e,t=!0){if(n instanceof d){const r=tn(n,e,!0,t);if(r!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(e))return r;if(/^-?\d+$/.test(e)&&e!=="-"){const o=n.getItems(),i=parseInt(e,10);return o&&i>=0&&i<o.length?o[i]:void 0}const s=n.getProperties();return s&&e in s?s[e]:void 0}if(Array.isArray(n)){if(e==="-")return;const r=te(e);return r>=0&&r<n.length?n[r]:void 0}if(L(n))return n[e]}function se(n,e){if(e.length===0)return{parent:n,key:"value",actualTarget:n.getValue()??n};let t=n;for(let s=0;s<e.length-1;++s){const o=e[s],i=mt(t,o);if(i===void 0)throw new Error(`Cannot resolve '/${e.slice(0,s+1).join("/")}'`);t=i}const r=e[e.length-1];if(t instanceof d){const s=mt(t,r,!1);if((typeof s!="object"||s===null||F(s))&&!(s instanceof d)&&!Array.isArray(s)&&["name","description","value","blueId"].includes(r))return{parent:t,key:r,actualTarget:s}}return Array.isArray(t)&&r==="-"?{parent:t,key:"-"}:t instanceof d&&t.getItems()&&r==="-"?{parent:t,key:"-"}:{parent:t,key:Array.isArray(t)?te(r):r}}function ot(n,e){var t;if(n instanceof d){const r=e,s=tn(n,r,!1);if(s!==void 0||["name","description","type","itemType","keyType","valueType","value","blueId","blue","items","properties","contracts"].includes(r))return s;if(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e)){const o=n.getItems(),i=typeof e=="number"?e:parseInt(e,10);if(o&&i>=0&&i<o.length)return o[i]}return(t=n.getProperties())==null?void 0:t[r]}return Array.isArray(n)||L(n)?n[e]:n}function P(n){if(n instanceof d)return n;if(n===null||typeof n=="string"||typeof n=="number"||typeof n=="boolean"||F(n))return w.deserialize(n);const e=Ke(n);return w.deserialize(e)}function Ke(n){if(n===void 0)return null;if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(Ke);const e={};for(const[t,r]of Object.entries(n))e[t]=Ke(r);return e}function it(n,e,t){if(n instanceof d){const r=e;switch(r){case"name":n.setName(t);return;case"description":n.setDescription(t);return;case"type":n.setType(t instanceof d||typeof t=="string"||t===void 0?t:P(t));return;case"itemType":n.setItemType(t instanceof d||typeof t=="string"||t===void 0?t:P(t));return;case"keyType":n.setKeyType(t instanceof d||typeof t=="string"||t===void 0?t:P(t));return;case"valueType":n.setValueType(t instanceof d||typeof t=="string"||t===void 0?t:P(t));return;case"value":{const s=t;n.setValue(s===void 0?null:s);return}case"blueId":n.setBlueId(t);return;case"blue":n.setBlue(t instanceof d||t===void 0?t:P(t));return;case"items":n.setItems(t);return;case"properties":n.setProperties(t);return;case"contracts":n.setContracts(t);return;default:{if(t===void 0){const s=n.getProperties();s&&r in s&&delete s[r]}else n.getProperties()||n.setProperties({}),n.addProperty(r,t instanceof d?t:P(t));return}}}Array.isArray(n)?n.splice(te(e),1):L(n)&&(t===void 0?delete n[e]:n[e]=t)}function Qr(n,e,t,r){let s=-1;if(e!=="-"&&(s=typeof e=="number"?e:parseInt(e,10),isNaN(s)))throw new Error(`Invalid numeric key for BlueNode item operation: ${e}`);if(s<-1)throw new Error(`Invalid array index for BlueNode items: ${s}`);let o=n.getItems();if(o||(o=[],n.setItems(o)),!r&&s!==-1&&s>o.length)throw new Error(`ADD operation failed: Target array index '${s}' is greater than array length ${o.length}.`);if(e==="-")o.push(t);else if(r){if(s>=0)if(s<o.length)o[s]=t;else{for(let i=o.length;i<s;i++)o.push(w.deserialize(null));o.push(t)}}else o.splice(s,0,t)}function Be(n,e,t,r){if(Array.isArray(n)){const s=e==="-"?n.length:te(e);if(!r&&s>n.length)throw new Error(`ADD operation failed: Target array index '${s}' is greater than array length ${n.length}. Path involving key '${e}'.`);if(s<0&&e!=="-")throw new Error(`Invalid negative array index: ${e}`);const o=P(t);if(r){if(s>=0&&s<n.length)n[s]=o;else if(s>=n.length){for(let i=n.length;i<s;i++)n.push(w.deserialize(null));n.push(o)}}else n.splice(s,0,o);return}if(n instanceof d){e==="-"||typeof e=="number"&&!isNaN(e)||typeof e=="string"&&/^\d+$/.test(e)?Qr(n,e,P(t),r):it(n,e,t);return}if(L(n)){n[e]=P(t);return}throw new Error(`Cannot insert into parent of type ${typeof n}`)}function Gr(n,e){if(Array.isArray(n)){const t=te(e);t===-1&&e==="-"?n.length>0&&n.pop():t>=0&&t<n.length&&n.splice(t,1);return}if(n instanceof d){if(typeof e=="number"||typeof e=="string"&&/^-?\d+$/.test(e)){const t=n.getItems();if(t){const r=te(e);r===-1&&e==="-"?t.length>0&&t.pop():r>=0&&r<t.length&&t.splice(r,1),t.length===0&&n.setItems(void 0);return}}it(n,e,void 0)}else L(n)&&delete n[e]}function Ye(n){if(n instanceof d)return n.clone();if(Array.isArray(n))return n.map(t=>Ye(t));if(L(n)){const e={};return Object.keys(n).forEach(t=>{e[t]=Ye(n[t])}),e}return n}function W(n,e){if(n===e||n instanceof d&&(n.isInlineValue()||n.getValue()!==void 0)&&W(n.getValue()??null,e)||e instanceof d&&(e.isInlineValue()||e.getValue()!==void 0)&&W(n,e.getValue()??null))return!0;if(n instanceof d&&e instanceof d||F(n)&&F(e)||F(n)&&typeof e=="number"||typeof n=="number"&&F(e))return n.toString()===e.toString();if(Array.isArray(n)&&Array.isArray(e))return n.length===e.length&&n.every((t,r)=>W(t,e[r]));if(L(n)&&L(e)){const t=Object.keys(n),r=Object.keys(e);return t.length===r.length&&t.every(s=>W(n[s],e[s]))}return!1}function nn(n,e){const{parent:t,key:r}=se(n,re(e));return ot(t,r)}function rn(n,e,t){const r=re(e);if(r.length===0&&e==="/"){const i=P(t);n.setValue(i.getValue()??null),i.getItems()?n.setItems(i.getItems()):n.setItems(void 0);return}const{parent:s,key:o}=se(n,r);Be(s,o,t,!0)}function Xr(n,e,t){const r=re(e);if(r.length===0&&e==="/"){if(n.getItems()&&Array.isArray(t)){const i=P(t);i.getItems()?(n.setItems(i.getItems()),n.setValue(null)):(n.setValue(i.getValue()??null),n.setItems(void 0))}else{const i=P(t);n.setValue(i.getValue()??null),i.getItems()&&n.setItems(i.getItems())}return!0}const{parent:s,key:o}=se(n,r);return Be(s,o,t,!1),!0}function es(n,e,t){const r=re(e);if(r.length===0&&e==="/"){const a=P(t);return n.setValue(a.getValue()??null),a.getItems()?n.setItems(a.getItems()):n.setItems(void 0),!0}const{parent:s,key:o,actualTarget:i}=se(n,r);if(i!==void 0&&s instanceof d)it(s,o,t);else{const a=ot(s,o),c=Array.isArray(s)||s instanceof d&&s.getItems()&&(typeof o=="number"||typeof o=="string"&&/^\d+$/.test(o));if(a===void 0){if(c)throw new Error(`REPLACE failed: Target array index '${o.toString()}' is out of bounds or does not exist at path '${e}'.`);Be(s,o,t,!0)}else Be(s,o,t,!0)}return!0}function sn(n,e){const t=re(e);if(t.length===0&&e==="/")return n.setValue(null),n.setItems(void 0),n.setProperties(void 0),!0;const{parent:r,key:s}=se(n,t);return Gr(r,s),!0}function ts(n,e,t){const r=Ye(nn(n,e));return rn(n,t,r),!0}function ns(n,e,t){const r=re(e),{parent:s,key:o}=se(n,r),i=ot(s,o);if(i===void 0)throw new Error(`MOVE failed: 'from' location '${e}' does not exist.`);return sn(n,e)?(rn(n,t,i),!0):!1}function rs(n,e,t){const r=nn(n,e);let s=t;if(r instanceof d)if((t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||F(t))&&(r.isInlineValue()||r.getValue()!==void 0)){if(!W(r.getValue()??null,t))throw new Error(`TEST failed at '${e}': Expected ${JSON.stringify(t)}, got ${JSON.stringify(r.getValue()??null)}`);return!0}else typeof t=="object"&&!(t instanceof d)&&(s=P(t));else if(F(r)&&typeof t=="number")r instanceof A?s=new A(t.toString()):r instanceof D&&(s=new D(t.toString()));else if((r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")&&F(t)){const o=t;!W(r,o.toString())&&(typeof r=="number"&&parseFloat(o.toString()))}if(!W(r,s)){const o=r instanceof d?r.toString():JSON.stringify(r),i=s instanceof d?s.toString():JSON.stringify(s);throw new Error(`TEST failed at '${e}': Expected ${i}, got ${o}`)}return!0}function ss(n,e){switch(e.op){case"add":return Xr(n,e.path,e.val);case"replace":return es(n,e.path,e.val);case"remove":return sn(n,e.path);case"copy":return ts(n,e.from,e.path);case"move":return ns(n,e.from,e.path);case"test":return rs(n,e.path,e.val)}}function os(n,e,t=!1){const r=t?n:n.clone();return ss(r,e),r}function at(n){if(Object.isFrozen(n))return n;Object.freeze(n);for(const e of Object.getOwnPropertyNames(n)){const t=n[e];p.isNonNullable(t)&&typeof t=="object"&&at(t)}return n}const is=new Lt;function lt(n,e="/",t=[]){const r=n.getContracts()??{};for(const[s,o]of Object.entries(r))if(q.isTypeOf(o,We)){const c=is.convert(o,We).paths??[];for(const h of c)t.push({absPath:Z(e,h),contractPath:Z(e,`contracts/${s}`)})}for(const[s,o]of Object.entries(n.getProperties()??{}))lt(o,Z(e,s),t);return t}function gt(n,e){return n===e||n.startsWith(e.endsWith("/")?e:e+"/")}function bt(n,e){if(!e.length)return n;let t=n.clone();for(const r of e)try{t=os(t,r,!0)}catch(s){throw new Xt(r,s)}return at(t)}function S(n){return n!=null}function pe(n){return n instanceof d}class as{constructor(e=[],t=(r,s)=>r<s?-1:r>s?1:0){u(this,"data");u(this,"length");u(this,"compare");if(this.data=e,this.length=this.data.length,this.compare=t,this.length>0)for(let r=(this.length>>1)-1;r>=0;r--)this._down(r)}push(e){this.data.push(e),this._up(this.length++)}pop(){if(this.length===0)return;const e=this.data[0],t=this.data.pop();return--this.length>0&&(this.data[0]=t,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:t,compare:r}=this,s=t[e];for(;e>0;){const o=e-1>>1,i=t[o];if(r(s,i)>=0)break;t[e]=i,e=o}t[e]=s}_down(e){const{data:t,compare:r}=this,s=this.length>>1,o=t[e];for(;e<s;){let i=(e<<1)+1;const a=i+1;if(a<this.length&&r(t[a],t[i])<0&&(i=a),r(t[i],o)>=0)break;t[e]=t[i],e=i}t[e]=o}}const ls=(n,e,t,r,s,o)=>[-n,e,t,r,s,o],cs=(n,e)=>{for(let t=0;t<n.key.length;t++){const r=n.key[t],s=e.key[t];if(r!==s)return typeof r=="number"&&typeof s=="number"?r-s:typeof r=="string"&&typeof s=="string"?r.localeCompare(s):0}return 0};class us{constructor(){u(this,"queue");this.queue=new as([],cs)}push(e){this.queue.push(e)}pop(){return this.queue.pop()}get length(){return this.queue.length}}class hs{constructor(e=[]){u(this,"processors",new Map);u(this,"typeOrder",new Map);e.forEach((t,r)=>this.register(t,r))}register(e,t){if(this.processors.has(e.contractBlueId))throw new Error(`Processor for ${e.contractType} already registered`);this.processors.set(e.contractBlueId,e),this.typeOrder.has(e.contractBlueId)||this.typeOrder.set(e.contractBlueId,t??this.typeOrder.size)}get(e){if(!e)return;const t=e.getBlueId();if(t)return this.processors.get(t)}orderOf(e){if(!e)return 0;const t=e.getBlueId();return t?this.typeOrder.get(t)??0:0}values(){return this.processors.values()}}class ds{constructor(){u(this,"isEnabled");this.isEnabled=process.env.TRACE_BLUE_ENABLED==="true"}makeHop(e,t){return`${e}#${t}`}shouldTrace(){return this.isEnabled}addHop(e,t,r){if(!this.shouldTrace())return{...e};const s=[...e.trace??[],this.makeHop(t,r)];return{...e,trace:s}}getTrace(e){return e.trace??[]}clearTrace(e){return{...e,trace:[]}}isTracingEnabled(){return this.isEnabled}}const ps=64;class fs{constructor(e,t,r,s,o){u(this,"traceManager");this.blue=e,this.registry=t,this.queue=r,this.getNextTaskId=s,this.getNextEventSeq=o,this.traceManager=new ds}async route(e,t,r,s,o=0){var c;if(r.seq===void 0&&(r.seq=this.getNextEventSeq()),t.length===0){if(r.dispatchPath){const h=r.dispatchPath.split("/").filter(Boolean),f={...r};return delete f.dispatchPath,this.route(e,h,f,s,o)}if(r.source==="channel"&&r.originNodePath&&r.originNodePath!=="/"){const h=((c=r.originNodePath)==null?void 0:c.split("/").filter(Boolean))??[];return this.route(e,h,r,s,o)}}const i=Z("/",t.join("/")),a=e.get(i);pe(a)&&await this.traverseContracts({doc:e,node:a,nodePath:i,event:r,afterTaskId:s,pathSegments:t,inlineDepth:o})}async traverseContracts(e){const{doc:t,node:r,nodePath:s,event:o,afterTaskId:i,pathSegments:a,inlineDepth:c}=e;if(!this.shouldSkipForChannel(o,s))for(const[h,f]of Object.entries(r.getContracts()??{})){if(!f.getType())continue;const g=this.registry.get(f.getType());if(!g){console.warn(`No processor registered for contract: ${h}`);continue}const b={nodePath:s,contractName:h,contractNode:f,event:o},y=new Gt(()=>t,b,this.blue);if(g.supports(o,f,y,h))switch(g.role){case"adapter":await this.processAdapter({cp:g,event:o,contractNode:f,ctx:y,contractName:h,doc:t,afterTaskId:i,inlineDepth:c});break;case"handler":this.scheduleHandler({contractNode:f,contractName:h,nodePath:s,event:o,depth:a.length,afterTaskId:i});break}}}async processAdapter(e){var m;const{cp:t,event:r,contractNode:s,ctx:o,contractName:i,doc:a,afterTaskId:c,inlineDepth:h}=e;if(h>=ps)throw new Error("Adapter recursion limit reached");const f=this.traceManager.addHop(r,((m=o.getTaskInfo())==null?void 0:m.nodePath)??"",i);await t.handle(f,s,o,i);const g=await o.flush();if(g.find(E=>E.kind==="patch"))throw new Error(`Contract "${i}" (adapter) attempted to patch the document`);const y=g.filter(E=>E.kind==="event");for(const E of y)await this.route(a,[],E.event,c,h+1)}scheduleHandler(e){const{contractNode:t,contractName:r,nodePath:s,event:o,depth:i,afterTaskId:a}=e,c=t.getType();if(!c){console.warn(`Contract node type is not defined for: ${r}`);return}const h=this.registry.orderOf(c),f=t.get("/order"),g=O(f)?f.toNumber():0,b=this.getNextTaskId()+a,y=ls(i,o.seq,h,g,r,b),m=this.traceManager.addHop(o,s,r);this.queue.push({key:y,nodePath:s,contractName:r,contractNode:t,event:m})}shouldSkipForChannel(e,t){return e.source==="channel"&&!!e.originNodePath&&e.originNodePath!==t}}const ys=(n,e,t)=>{(t instanceof Xt||t instanceof en)&&console.error(`[Blue] Failed to apply patches for contract "${n}" on event ${JSON.stringify(e)}`,t)};function wt(n){const e=n.clone(),t=r=>{var o;if(!pe(r))return;const s=r.getContracts();s&&(!s.checkpoint||((o=s.checkpoint.getType())==null?void 0:o.getBlueId())!==T["Channel Event Checkpoint"])&&r.addContract("checkpoint",w.deserialize({type:{name:"Channel Event Checkpoint",blueId:T["Channel Event Checkpoint"]},lastEvents:{}}))};t(e);for(const{absPath:r}of lt(e)){const s=e.get(r);pe(s)&&t(s)}return at(e)}class ms{constructor(e){u(this,"contractType","Channel Event Checkpoint");u(this,"contractBlueId",T["Channel Event Checkpoint"]);u(this,"role","handler");this.cache=e}supports(e){var t,r;return e.source==="channel"&&((t=e.rootEvent)==null?void 0:t.payload)===e.payload&&((r=e.rootEvent)==null?void 0:r.source)==="external"}async handle(e,t,r){var i;if(!e.channelName||!((i=e.rootEvent)!=null&&i.seq))return;const s=await r.getBlue().calculateBlueId(e.rootEvent.payload),o=r.getNodePath().replace(/\/contracts\/checkpoint$/,"");this.cache.record(o,e,s)}init(){return[]}}const Tt=(n,e)=>n.get(e)!==void 0;class gs{constructor(){u(this,"firstSeen",new Map)}record(e,t,r){const s=e;this.firstSeen.has(s)||this.firstSeen.set(s,{docBase:e,event:t,eventBlueId:r})}flush(e){const t=[];for(const{docBase:r,event:s,eventBlueId:o}of this.firstSeen.values()){if(!s.channelName)continue;const i=Z(r,"contracts/checkpoint/lastEvents",s.channelName),a=`${i}/blueId`;Tt(e,i)?t.push({op:Tt(e,a)?"replace":"add",path:a,val:o}):t.push({op:"add",path:i,val:{blueId:o}})}return t}clear(){this.firstSeen.clear()}}class bs{constructor(e,t=[]){u(this,"taskCounter",0);u(this,"eventCounter",0);u(this,"registry");u(this,"queue");u(this,"router");u(this,"checkpointCache",new gs);this.blue=e,this.registry=new hs(t),this.queue=new us,this.router=new fs(this.blue,this.registry,this.queue,()=>++this.taskCounter,()=>++this.eventCounter),this.register(new ms(this.checkpointCache),9999)}register(e,t){this.registry.register(e,t)}async initialise(e){e=wt(e);const t=await this.bootstrapContracts(e);for(const r of t)await this.router.route(e,[],r,0);return this.drainQueue(e)}async processEvents(e,t){let r=wt(e);const s=[];for(const o of t)try{const i={payload:o,source:"external"};await this.router.route(r,[],i,0);const a=await this.drainQueue(r);r=a.state,s.push(...a.emitted);const c=this.checkpointCache.flush(r);c.length&&(r=bt(r,c))}finally{this.checkpointCache.clear()}return{state:r,emitted:s}}async bootstrapContracts(e){const t=[],r=e.getContracts();if(!r)return t;for(const[,s]of Object.entries(r)){const o=this.registry.get(s.getType());o!=null&&o.init&&t.push(...await o.init(s))}return t}async drainQueue(e){var i;let t=e;const r=[],s=1e4;let o=0;for(;this.queue.length;){if(++o>s)throw new Error("Possible cycle – too many iterations");const a=this.queue.pop(),{nodePath:c,contractName:h,contractNode:f,event:g}=a,b=t.get(c);if(!pe(b)||!((i=b.getContracts())!=null&&i[h])||!f.getType())continue;const y=this.registry.get(f.getType());if(!y){console.warn(`No processor registered for contract: ${h}`);continue}const m=new Gt(()=>t,a,this.blue,async E=>{for(const I of E)if(I.kind==="patch"){const H=lt(t);for(const N of H){const ie=I.patch.op==="move"||I.patch.op==="copy"?[I.patch.from,I.patch.path]:[I.patch.path],Te=m.getNodePath(),un=ie.some(dn=>gt(dn,N.absPath)),hn=gt(Te,N.absPath);if(un&&!hn)throw new en(I.patch,N.absPath,Te)}try{t=bt(t,[I.patch])}catch(N){throw ys(h,g,N),N}}else I.kind==="event"&&(r.push(I.event.payload),await this.router.route(t,[],I.event,a.key[5]))});await y.handle(g,f,m,h),await m.flush()}return{state:t,emitted:r}}}class oe{constructor(){u(this,"role","adapter")}baseSupports(e){return e.source!=="channel"}init(){return[]}}class ws extends oe{constructor(){super(...arguments);u(this,"contractType","Composite Timeline Channel");u(this,"contractBlueId",T["Composite Timeline Channel"])}supports(t,r,s){const o=s.getBlue().nodeToSchemaOutput(r,Vr);return!o.channels||!t.channelName?!1:o.channels.includes(t.channelName)}handle(t,r,s,o){s.emitEvent({payload:t.payload,channelName:o,source:"channel"})}}class Ts extends oe{constructor(){super(...arguments);u(this,"contractType","Document Update Channel");u(this,"contractBlueId",T["Document Update Channel"])}supports(t,r,s,o){if(!this.baseSupports(t))return!1;const i=s.getBlue().nodeToSchemaOutput(r,jr),a=t.payload.path;if(!a||t.channelName===o)return!1;const c=i.path;return p.isNonNullable(c)&&a===s.resolvePath(c)}handle(t,r,s,o){const i=t.payload;i&&s.emitEvent({payload:i,channelName:o,source:"channel"})}}class Es extends oe{constructor(){super(...arguments);u(this,"contractType","Embedded Node Channel");u(this,"contractBlueId",T["Embedded Node Channel"])}supports(t,r,s){if(!this.baseSupports(t))return!1;const o=s.getBlue().nodeToSchemaOutput(r,pt);return S(t.originNodePath)&&S(o.path)&&t.originNodePath===s.resolvePath(o.path)}handle(t,r,s,o){const i=s.getBlue().nodeToSchemaOutput(r,pt),{originNodePath:a,payload:c}=t;S(i.path)&&a===s.resolvePath(i.path)&&s.emitEvent({payload:c,channelName:o,source:"channel"})}}const Et=n=>n.payload.type==="Timeline Entry"||n.payload.type==="MyOS Timeline Entry";class Is extends oe{constructor(){super(...arguments);u(this,"contractType","MyOS Timeline Channel");u(this,"contractBlueId",z["MyOS Timeline Channel"])}supports(t,r,s){if(!this.baseSupports(t)||!Et(t))return!1;const o=s.getBlue(),i=o.jsonValueToNode(t.payload),a=o.nodeToSchemaOutput(i,Zr),c=s.getBlue().nodeToSchemaOutput(r,$r),h=S(c.timelineId)&&S(a.timelineId),f=S(c.account)&&S(a.account),g=S(c.email)&&S(a.email);return h&&a.timelineId===c.timelineId||f&&a.account===c.account||g&&a.email===c.email}handle(t,r,s,o){Et(t)&&s.emitEvent({payload:t.payload,channelName:o,source:"channel"})}}class vs extends oe{constructor(){super(...arguments);u(this,"contractType","MyOS Agent Channel");u(this,"contractBlueId",z["MyOS Agent Channel"])}supports(t,r,s){if(!this.baseSupports(t))return!1;try{const{myosAgentEvent:o,myosAgentChannel:i}=this.parseEventAndChannel(t,r,s);return this.isAgentMatch(o,i)&&this.isEventPatternMatch(o,i,s)}catch(o){return console.warn("Error in MyOSAgentChannelProcessor.supports:",o),!1}}handle(t,r,s,o){s.emitEvent({payload:t.payload,channelName:o,source:"channel"})}parseEventAndChannel(t,r,s){const o=s.getBlue(),i=o.jsonValueToNode(t.payload),a=o.nodeToSchemaOutput(i,Lr),c=o.nodeToSchemaOutput(r,qr);return{myosAgentEvent:a,myosAgentChannel:c}}isAgentMatch(t,r){var i;const s=t.agentId,o=(i=r.agent)==null?void 0:i.agentId;return S(s)&&S(o)&&s===o}isEventPatternMatch(t,r,s){const o=r.event;if(!o)return!0;const i=t.event;if(!i)return!1;try{const a=s.getBlue(),c=a.nodeToJson(i),h=a.nodeToJson(o);return p.deepContains(c,h)}catch(a){return console.warn("Error during event pattern matching:",a),!1}}}class Bs{constructor(){u(this,"contractType","Operation");u(this,"contractBlueId",T.Operation);u(this,"role","adapter")}supports(e,t,r,s){const i=r.getBlue().nodeToSchemaOutput(t,Fr),a=this.parseEventPayload(e,r);return S(a==null?void 0:a.operation)&&a.operation===s&&e.source==="channel"&&e.channelName===i.channel}async handle(e,t,r,s){r.emitEvent({payload:e.payload,channelName:s,source:"channel"})}init(){return[]}parseEventPayload(e,t){const r=t.getBlue(),s=r.jsonValueToNode(e.payload);if(q.isTypeOf(s,Ie)){const o=r.nodeToSchemaOutput(s,Ie);return r.nodeToSchemaOutput(o.message,zr)}return null}}class Ns{constructor(){u(this,"contractType","Process Embedded");u(this,"role","adapter");u(this,"contractBlueId",T["Process Embedded"])}supports(e){return e.source!=="channel"}handle(e,t,r){const s=r.getBlue().nodeToSchemaOutput(t,We);for(const o of s.paths??[])r.emitEvent({...e,dispatchPath:r.resolvePath(o)})}init(){return[]}}const on=!process.env.SKIP_ISOLATED_VM;let R=null;if(on)try{R=require("isolated-vm")}catch{console.warn("isolated-vm not available, using fallback evaluation method")}function It(n){return/\bimport\s.+\sfrom\s+['"][^'"]+['"]/.test(n)||/\bexport\s+/.test(n)}class an{static async evaluate({code:e,ctx:t,bindings:r={},options:s={}}){return!R||!on?this.evaluateSimple(e,r,s):this.evaluateSecure(e,r,t,s)}static async evaluateSimple(e,t,r={}){if(It(e))throw new Error("Static import/export syntax requires isolated-vm – start Node without SKIP_ISOLATED_VM.");try{if(r.isCodeBlock){const s=Object.keys(t);return await(await new Function(...s,`return async function codeBlock(${s.join(", ")}) { ${e} }`)(...s.map(a=>t[a])))(...s.map(a=>t[a]))}else return new Function(...Object.keys(t),`return ${e};`)(...Object.values(t))}catch(s){throw r.isCodeBlock?new yt(e,s):new ft(e,s)}}static async evaluateSecure(e,t,r,s={}){if(!R)throw new Error("isolated-vm not available");const o=new R.Isolate({memoryLimit:32}),i=await o.createContext(),a=i.global;try{await this.setupIsolateEnvironment(a,t);const c=new Map,h=this.createModuleResolver(o,i,c,r);return It(e)?await this.evaluateESModule(o,i,e,s,h):await this.evaluateSimpleScript(o,i,e,t,s)}catch(c){throw s.isCodeBlock?new yt(e,c):new ft(e,c)}finally{i.release(),o.dispose()}}static async setupIsolateEnvironment(e,t){if(!R)throw new Error("isolated-vm not available");const r=new R.Callback((...s)=>console.log(...s));await e.set("log",r);for(const[s,o]of Object.entries(t))typeof o=="function"?await e.set(s,new R.Callback(o)):await e.set(s,new R.ExternalCopy(o).copyInto())}static createModuleResolver(e,t,r,s){return async o=>{if(r.has(o))return r.get(o);if(o.startsWith("blue:")){const i=o.slice(5),a=s.loadBlueContent;if(typeof a!="function")throw new Error(`ProcessingContext is missing a loadBlueContent(blueId) implementation (needed for ${o})`);const c=await a(i),h=await e.compileModule(c);return r.set(o,h),await h.instantiate(t,this.createModuleResolver(e,t,r,s)),h}if(/^https?:\/\//.test(o)){let i;if(typeof s.loadExternalModule=="function")i=await s.loadExternalModule(o);else throw new Error(`ProcessingContext is missing a loadExternalModule(url) implementation (needed for ${o})`);const a=await e.compileModule(i);return r.set(o,a),await a.instantiate(t,this.createModuleResolver(e,t,r,s)),a}throw new Error(`Unsupported module specifier "${o}"`)}}static async evaluateSimpleScript(e,t,r,s,o){const i=Object.keys(s).join(", "),a=Object.keys(s).map(f=>f),c=`(async (${i}) => { ${o.isCodeBlock?r:`return (${r});`} })(${a.join(", ")})`;return await(await e.compileScript(c)).run(t,{timeout:o.timeout??500,promise:!0,copy:!0,release:!0})}static async evaluateESModule(e,t,r,s,o){let i=r;if(s.isCodeBlock){const h=/^\s*(import\s.+?;|export\s.+?;)/gm,f=(r.match(h)||[]).join(`
28
+ `),g=r.replace(h,"").trim();i=`
29
+ ${f}
30
+ const run = function() {
31
+ ${g}
32
+ };
33
+ export default run();
34
+ `}const a=await e.compileModule(i);return await a.instantiate(t,o),await a.evaluate({timeout:s.timeout??500,promise:!0,reference:!0,release:!0}),await a.namespace.get("default",{timeout:s.timeout??500,promise:!0,copy:!0,release:!0})}}class ln{static createStandardBindings(e,t,r){const s=e.getBlue();return{document:o=>{const i=e.get(o);return O(i)?i.toNumber():pe(i)?s.nodeToJson(i,"original"):i},event:t.payload,steps:r}}}class Ps{constructor(){u(this,"stepType","Update Document")}supports(e){return q.isTypeOf(e,Fe)}async evaluateChangeValue(e,t,r,s){const o=e==null?void 0:e.getValue();if(typeof o=="string"&&o.startsWith("${")&&o.endsWith("}")){const i=o.slice(2,-1);return await an.evaluate({code:i,ctx:t,bindings:ln.createStandardBindings(t,r,s)})}return e}async execute(e,t,r,s,o){if(!q.isTypeOf(e,Fe))return;const i=r.getBlue().nodeToSchemaOutput(e,Fe);for(const a of i.changeset??[])if(a.path){if(a.op==="replace"||a.op==="add"){const c=await this.evaluateChangeValue(a.val,r,t,o);r.addPatch({op:a.op,path:a.path,val:c}),r.emitEvent({payload:{type:"Document Update",op:a.op,path:r.resolvePath(a.path),val:c}})}a.op==="remove"&&(r.addPatch({op:a.op,path:a.path}),r.emitEvent({payload:{type:"Document Update",op:a.op,path:r.resolvePath(a.path),val:null}}))}}}class Ss{constructor(){u(this,"stepType","Trigger Event")}supports(e){return q.isTypeOf(e,je)}async execute(e,t,r){if(!q.isTypeOf(e,je))return;const s=r.getBlue().nodeToSchemaOutput(e,je),o=B.get(s.event,"simple");r.emitEvent({payload:o})}}const ze=v(T["JavaScript Code"])(l.z.object({code:l.z.string().optional()}));class Cs{constructor(){u(this,"stepType","JavaScript Code")}supports(e){return q.isTypeOf(e,ze)}async execute(e,t,r,s,o){if(!q.isTypeOf(e,ze))return;const a=r.getBlue().nodeToSchemaOutput(e,ze);if(!a.code)throw new Error("JavaScript code is required");const c=await an.evaluate({code:a.code,ctx:r,bindings:ln.createStandardBindings(r,t,o),options:{isCodeBlock:!0,timeout:500}});if(c&&typeof c=="object"&&"events"in c){const h=c;if(Array.isArray(h.events))for(const f of h.events)r.emitEvent({payload:f})}return c}}const As=[new Ps,new Ss,new Cs];class cn{constructor(e=As){u(this,"contractType","Sequential Workflow");u(this,"contractBlueId",T["Sequential Workflow"]);u(this,"role","handler");u(this,"executors",[]);this.executors=e}registerExecutor(e){this.executors.push(e)}supports(e,t,r){const i=r.getBlue().nodeToSchemaOutput(t,Je).channel;return e.source==="channel"&&e.channelName===i}async handle(e,t,r,s){const i=r.getBlue().nodeToSchemaOutput(t,Je),a={},c=i.steps;for(const[h,f]of(c??[]).entries()){const g=this.executors.find(y=>y.supports(f));if(!g)throw new Error(`Unsupported workflow step type "${f.getType()}"`);const b=await g.execute(f,e,r,s,a);if(b!==void 0){const y=f.getName(),m=typeof y=="string"?y:`Step${h+1}`;a[m]=b}await r.flush()}}init(){return[]}}class Os{constructor(e){u(this,"contractType","Sequential Workflow Operation");u(this,"contractBlueId",T["Sequential Workflow Operation"]);u(this,"role","handler");u(this,"sequentialWorkflowProcessor");this.sequentialWorkflowProcessor=e||new cn}supports(e,t,r){const i=r.getBlue().nodeToSchemaOutput(t,Mr).operation,a=e.channelName;return e.source==="channel"&&p.isNonNullable(a)&&p.isNonNullable(i)&&a===i}async handle(e,t,r,s){try{await this.sequentialWorkflowProcessor.handle(e,t,r,s)}catch(o){throw console.error("Error in SequentialWorkflowOperationProcessor.handle:",o),o}}}const vt=n=>n.payload.type==="Timeline Entry";class ks extends oe{constructor(){super(...arguments);u(this,"contractType","Timeline Channel");u(this,"contractBlueId",T["Timeline Channel"])}supports(t,r,s){if(!this.baseSupports(t)||!vt(t))return!1;const o=s.getBlue(),i=o.jsonValueToNode(t.payload),a=o.nodeToSchemaOutput(i,Ie),c=s.getBlue().nodeToSchemaOutput(r,Qt);return S(c.timelineId)&&S(a.timelineId)&&a.timelineId===c.timelineId}handle(t,r,s,o){vt(t)&&s.emitEvent({payload:t.payload,channelName:o,source:"channel"})}}class Ds{constructor(e={}){u(this,"nodeProvider");u(this,"typeSchemaResolver");u(this,"blueDirectivePreprocessor");u(this,"urlContentFetcher");u(this,"documentProcessor");u(this,"prepareForBlueIdCalculation",async e=>e instanceof d||Array.isArray(e)&&e.every(t=>t instanceof d)?e:Array.isArray(e)?await Promise.all(e.map(r=>this.jsonValueToNodeAsync(r))):this.jsonValueToNodeAsync(e));u(this,"calculateBlueId",async e=>{const t=await this.prepareForBlueIdCalculation(e);return x.calculateBlueId(t)});u(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));const{nodeProvider:t,typeSchemaResolver:r=null,urlFetchStrategy:s}=e,o=pr(()=>[]);this.nodeProvider=de.wrap(t||o),this.typeSchemaResolver=r,this.urlContentFetcher=new Jr(s),this.blueDirectivePreprocessor=new _r(void 0,this.urlContentFetcher),this.documentProcessor=new bs(this,[new Ns,new Es,new Ts,new ks,new Is,new vs,new ws,new Bs,new cn,new Os])}nodeToJson(e,t="official"){return B.get(e,t)}nodeToSchemaOutput(e,t){return new Lt(this.typeSchemaResolver).convert(e,t)}async process(e,t){return await this.documentProcessor.initialise(e),this.documentProcessor.processEvents(e,t)}jsonValueToNode(e){return this.preprocess(w.deserialize(e))}async jsonValueToNodeAsync(e){return this.preprocessAsync(w.deserialize(e))}yamlToNode(e){const t=ee(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNode(t)}async yamlToNodeAsync(e){const t=ee(e);if(!t)throw new Error("Failed to parse YAML to JSON");return this.jsonValueToNodeAsync(t)}calculateBlueIdSync(e){const t=this.prepareForBlueIdCalculationSync(e);return x.calculateBlueIdSync(t)}addPreprocessingAliases(e){this.blueDirectivePreprocessor.addPreprocessingAliases(e)}preprocess(e){const t=this.blueDirectivePreprocessor.process(e);return new ve(this.nodeProvider).preprocessWithDefaultBlue(t)}async preprocessAsync(e){const t=await this.blueDirectivePreprocessor.processAsync(e);return new ve(this.nodeProvider).preprocessWithDefaultBlue(t)}getNodeProvider(){return this.nodeProvider}setNodeProvider(e){return this.nodeProvider=de.wrap(e),this}getTypeSchemaResolver(){return this.typeSchemaResolver}setTypeSchemaResolver(e){return this.typeSchemaResolver=e,this}getUrlContentFetcher(){return this.urlContentFetcher}setUrlFetchStrategy(e){return this.urlContentFetcher.setFetchStrategy(e),this}enablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.enableFetching(),this}enablePreprocessingDirectivesFetchForDomains(e){return this.urlContentFetcher.enableFetchingForDomains(e),this}allowUrlFetchingForDomain(e){return this.urlContentFetcher.allowDomain(e),this}disallowUrlFetchingForDomain(e){return this.urlContentFetcher.disallowDomain(e),this}getAllowedUrlFetchingDomains(){return this.urlContentFetcher.getAllowedDomains()}disablePreprocessingDirectivesFetchForUrls(){return this.urlContentFetcher.disableFetching(),this}isPreprocessingDirectivesFetchForUrlsEnabled(){return this.urlContentFetcher.isFetchingEnabled()}getPreprocessingAliases(){return this.blueDirectivePreprocessor.getPreprocessingAliases()}setPreprocessingAliases(e){return this.blueDirectivePreprocessor.setPreprocessingAliases(e),this}}exports.Base58Sha256Provider=kt;exports.Blue=Ds;exports.BlueIdCalculator=x;exports.BlueIdToCid=Yn;exports.JsonCanonicalizer=Ot;exports.TypeSchemaResolver=nr;exports.baseBlueObjectSchema=be;exports.blueDescriptionField=Hn;exports.blueIdField=Gn;exports.blueIdSchema=kn;exports.blueNameField=Xn;exports.blueNodeField=M;exports.blueObjectBooleanValueSchema=Vn;exports.blueObjectNumberValueSchema=xn;exports.blueObjectSchema=X;exports.blueObjectStringListItemsSchema=jn;exports.blueObjectStringValueSchema=Dn;exports.calculateBlueId=Kt;exports.calculateBlueIdSync=Nr;exports.enrichWithBlueId=qe;exports.getBlueDescriptionAnnotation=xt;exports.getBlueIdAnnotation=jt;exports.getBlueNameAnnotation=zt;exports.getBlueNodeAnnotation=Rt;exports.getBlueObjectItems=Pr;exports.getBlueObjectProperties=Cr;exports.getBlueObjectTypeLabel=Ar;exports.getBlueObjectValue=Sr;exports.getExtendedFromSchemaAnnotation=Zt;exports.getTypeBlueIdAnnotation=Ut;exports.hasBlueObjectBlueIdDefined=Pt;exports.hasBlueObjectItemsDefined=St;exports.hasBlueObjectNameDefined=zn;exports.hasBlueObjectTypeDefined=Ct;exports.hasBlueObjectValueDefined=At;exports.isBlueNodeSchema=$e;exports.isBlueObject=Fn;exports.isBlueObjectResolved=Yt;exports.isGivenBlueObjectTypeSchema=Mn;exports.isJsonBlueArray=rt;exports.isJsonBlueObject=nt;exports.isJsonBlueValue=Un;exports.isSchemaExtendedFrom=st;exports.isUrl=ae;exports.jsonBlueValueSchema=he;exports.normalizeToBlueObject=Or;exports.resolveBlueObjectItems=Le;exports.withBlueDescription=Dt;exports.withBlueId=Vt;exports.withBlueName=Ft;exports.withBlueNode=Mt;exports.withExtendedFromSchema=$t;exports.withTypeBlueId=v;exports.yamlBlueDump=wr;exports.yamlBlueParse=ee;