reqon-dsl 0.2.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 (388) hide show
  1. package/.claude/settings.local.json +31 -0
  2. package/.claude/skills/api-integration.md +125 -0
  3. package/.claude/skills/database-schema.md +51 -0
  4. package/.claude/skills/dsl-design.md +80 -0
  5. package/.claude/skills/property-testing.md +143 -0
  6. package/.claude/skills/reqon/SKILL.md +44 -0
  7. package/.claude/skills/reqon/references/examples.md +206 -0
  8. package/.claude/skills/reqon/references/syntax.md +263 -0
  9. package/.claude/skills/vscode-extension.md +113 -0
  10. package/.github/dependabot.yml +32 -0
  11. package/.github/pull_request_template.md +21 -0
  12. package/.github/workflows/ci.yml +174 -0
  13. package/.github/workflows/release.yml +73 -0
  14. package/CLAUDE.md +72 -0
  15. package/CONTRIBUTING.md +161 -0
  16. package/README.md +235 -0
  17. package/TODO.md +51 -0
  18. package/dist/ast/index.d.ts +1 -0
  19. package/dist/ast/index.js +1 -0
  20. package/dist/ast/nodes.d.ts +237 -0
  21. package/dist/ast/nodes.js +12 -0
  22. package/dist/auth/auth.test.d.ts +1 -0
  23. package/dist/auth/auth.test.js +255 -0
  24. package/dist/auth/circuit-breaker.d.ts +115 -0
  25. package/dist/auth/circuit-breaker.js +267 -0
  26. package/dist/auth/credentials.d.ts +91 -0
  27. package/dist/auth/credentials.js +169 -0
  28. package/dist/auth/index.d.ts +5 -0
  29. package/dist/auth/index.js +8 -0
  30. package/dist/auth/oauth2-provider.d.ts +41 -0
  31. package/dist/auth/oauth2-provider.js +131 -0
  32. package/dist/auth/rate-limiter.d.ts +61 -0
  33. package/dist/auth/rate-limiter.js +380 -0
  34. package/dist/auth/token-store.d.ts +30 -0
  35. package/dist/auth/token-store.js +148 -0
  36. package/dist/auth/types.d.ts +142 -0
  37. package/dist/auth/types.js +1 -0
  38. package/dist/cli.d.ts +2 -0
  39. package/dist/cli.js +270 -0
  40. package/dist/errors/errors.test.d.ts +1 -0
  41. package/dist/errors/errors.test.js +165 -0
  42. package/dist/errors/index.d.ts +83 -0
  43. package/dist/errors/index.js +159 -0
  44. package/dist/execution/execution.test.d.ts +1 -0
  45. package/dist/execution/execution.test.js +246 -0
  46. package/dist/execution/index.d.ts +4 -0
  47. package/dist/execution/index.js +2 -0
  48. package/dist/execution/state.d.ts +136 -0
  49. package/dist/execution/state.js +82 -0
  50. package/dist/execution/store.d.ts +52 -0
  51. package/dist/execution/store.js +120 -0
  52. package/dist/index.d.ts +27 -0
  53. package/dist/index.js +57 -0
  54. package/dist/integration.test.d.ts +1 -0
  55. package/dist/integration.test.js +168 -0
  56. package/dist/interpreter/context.d.ts +15 -0
  57. package/dist/interpreter/context.js +29 -0
  58. package/dist/interpreter/evaluator.d.ts +5 -0
  59. package/dist/interpreter/evaluator.js +223 -0
  60. package/dist/interpreter/evaluator.test.d.ts +1 -0
  61. package/dist/interpreter/evaluator.test.js +512 -0
  62. package/dist/interpreter/executor.d.ts +131 -0
  63. package/dist/interpreter/executor.js +663 -0
  64. package/dist/interpreter/fetch-handler.d.ts +43 -0
  65. package/dist/interpreter/fetch-handler.js +203 -0
  66. package/dist/interpreter/http.d.ts +57 -0
  67. package/dist/interpreter/http.js +210 -0
  68. package/dist/interpreter/http.test.d.ts +1 -0
  69. package/dist/interpreter/http.test.js +299 -0
  70. package/dist/interpreter/index.d.ts +7 -0
  71. package/dist/interpreter/index.js +7 -0
  72. package/dist/interpreter/pagination.d.ts +63 -0
  73. package/dist/interpreter/pagination.js +155 -0
  74. package/dist/interpreter/progress.test.d.ts +1 -0
  75. package/dist/interpreter/progress.test.js +216 -0
  76. package/dist/interpreter/schema-matcher.d.ts +16 -0
  77. package/dist/interpreter/schema-matcher.js +136 -0
  78. package/dist/interpreter/schema-matcher.test.d.ts +1 -0
  79. package/dist/interpreter/schema-matcher.test.js +122 -0
  80. package/dist/interpreter/signals.d.ts +57 -0
  81. package/dist/interpreter/signals.js +73 -0
  82. package/dist/interpreter/step-handlers/for-handler.d.ts +17 -0
  83. package/dist/interpreter/step-handlers/for-handler.js +51 -0
  84. package/dist/interpreter/step-handlers/index.d.ts +8 -0
  85. package/dist/interpreter/step-handlers/index.js +8 -0
  86. package/dist/interpreter/step-handlers/map-handler.d.ts +10 -0
  87. package/dist/interpreter/step-handlers/map-handler.js +20 -0
  88. package/dist/interpreter/step-handlers/match-handler.d.ts +27 -0
  89. package/dist/interpreter/step-handlers/match-handler.js +61 -0
  90. package/dist/interpreter/step-handlers/store-handler.d.ts +13 -0
  91. package/dist/interpreter/step-handlers/store-handler.js +66 -0
  92. package/dist/interpreter/step-handlers/types.d.ts +15 -0
  93. package/dist/interpreter/step-handlers/types.js +1 -0
  94. package/dist/interpreter/step-handlers/validate-handler.d.ts +10 -0
  95. package/dist/interpreter/step-handlers/validate-handler.js +26 -0
  96. package/dist/interpreter/step-handlers/webhook-handler.d.ts +36 -0
  97. package/dist/interpreter/step-handlers/webhook-handler.js +104 -0
  98. package/dist/lexer/index.d.ts +10 -0
  99. package/dist/lexer/index.js +12 -0
  100. package/dist/lexer/lexer.d.ts +24 -0
  101. package/dist/lexer/lexer.js +264 -0
  102. package/dist/lexer/lexer.test.d.ts +1 -0
  103. package/dist/lexer/lexer.test.js +259 -0
  104. package/dist/lexer/tokens.d.ts +69 -0
  105. package/dist/lexer/tokens.js +146 -0
  106. package/dist/loader/index.d.ts +36 -0
  107. package/dist/loader/index.js +220 -0
  108. package/dist/loader/loader.test.d.ts +1 -0
  109. package/dist/loader/loader.test.js +287 -0
  110. package/dist/oas/index.d.ts +4 -0
  111. package/dist/oas/index.js +2 -0
  112. package/dist/oas/loader.d.ts +21 -0
  113. package/dist/oas/loader.js +82 -0
  114. package/dist/oas/oas.test.d.ts +1 -0
  115. package/dist/oas/oas.test.js +218 -0
  116. package/dist/oas/validator.d.ts +12 -0
  117. package/dist/oas/validator.js +227 -0
  118. package/dist/parser/base.d.ts +33 -0
  119. package/dist/parser/base.js +97 -0
  120. package/dist/parser/expressions.d.ts +27 -0
  121. package/dist/parser/expressions.js +248 -0
  122. package/dist/parser/expressions.test.d.ts +1 -0
  123. package/dist/parser/expressions.test.js +378 -0
  124. package/dist/parser/index.d.ts +3 -0
  125. package/dist/parser/index.js +3 -0
  126. package/dist/parser/match.test.d.ts +1 -0
  127. package/dist/parser/match.test.js +254 -0
  128. package/dist/parser/parser.d.ts +68 -0
  129. package/dist/parser/parser.js +1229 -0
  130. package/dist/parser/parser.test.d.ts +1 -0
  131. package/dist/parser/parser.test.js +333 -0
  132. package/dist/parser/schedule.test.d.ts +1 -0
  133. package/dist/parser/schedule.test.js +241 -0
  134. package/dist/plugin.d.ts +35 -0
  135. package/dist/plugin.js +68 -0
  136. package/dist/scheduler/cron-parser.d.ts +32 -0
  137. package/dist/scheduler/cron-parser.js +198 -0
  138. package/dist/scheduler/cron-parser.test.d.ts +1 -0
  139. package/dist/scheduler/cron-parser.test.js +188 -0
  140. package/dist/scheduler/index.d.ts +3 -0
  141. package/dist/scheduler/index.js +2 -0
  142. package/dist/scheduler/scheduler.d.ts +81 -0
  143. package/dist/scheduler/scheduler.js +376 -0
  144. package/dist/scheduler/types.d.ts +65 -0
  145. package/dist/scheduler/types.js +1 -0
  146. package/dist/stores/factory.d.ts +36 -0
  147. package/dist/stores/factory.js +73 -0
  148. package/dist/stores/file.d.ts +60 -0
  149. package/dist/stores/file.js +173 -0
  150. package/dist/stores/file.test.d.ts +1 -0
  151. package/dist/stores/file.test.js +165 -0
  152. package/dist/stores/index.d.ts +6 -0
  153. package/dist/stores/index.js +5 -0
  154. package/dist/stores/memory.d.ts +19 -0
  155. package/dist/stores/memory.js +51 -0
  156. package/dist/stores/memory.test.d.ts +1 -0
  157. package/dist/stores/memory.test.js +157 -0
  158. package/dist/stores/postgrest.d.ts +55 -0
  159. package/dist/stores/postgrest.js +217 -0
  160. package/dist/stores/stores.test.d.ts +1 -0
  161. package/dist/stores/stores.test.js +158 -0
  162. package/dist/stores/types.d.ts +31 -0
  163. package/dist/stores/types.js +26 -0
  164. package/dist/sync/index.d.ts +4 -0
  165. package/dist/sync/index.js +2 -0
  166. package/dist/sync/state.d.ts +69 -0
  167. package/dist/sync/state.js +66 -0
  168. package/dist/sync/store.d.ts +49 -0
  169. package/dist/sync/store.js +93 -0
  170. package/dist/sync/sync.test.d.ts +1 -0
  171. package/dist/sync/sync.test.js +221 -0
  172. package/dist/utils/async.d.ts +7 -0
  173. package/dist/utils/async.js +9 -0
  174. package/dist/utils/file.d.ts +38 -0
  175. package/dist/utils/file.js +92 -0
  176. package/dist/utils/index.d.ts +4 -0
  177. package/dist/utils/index.js +4 -0
  178. package/dist/utils/logger.d.ts +34 -0
  179. package/dist/utils/logger.js +39 -0
  180. package/dist/utils/path.d.ts +12 -0
  181. package/dist/utils/path.js +41 -0
  182. package/dist/webhook/index.d.ts +8 -0
  183. package/dist/webhook/index.js +7 -0
  184. package/dist/webhook/server.d.ts +84 -0
  185. package/dist/webhook/server.js +319 -0
  186. package/dist/webhook/store.d.ts +67 -0
  187. package/dist/webhook/store.js +193 -0
  188. package/dist/webhook/types.d.ts +88 -0
  189. package/dist/webhook/types.js +6 -0
  190. package/docusaurus/README.md +41 -0
  191. package/docusaurus/docs/advanced/execution-state.md +283 -0
  192. package/docusaurus/docs/advanced/extending-reqon.md +388 -0
  193. package/docusaurus/docs/advanced/multi-file-missions.md +250 -0
  194. package/docusaurus/docs/advanced/parallel-execution.md +353 -0
  195. package/docusaurus/docs/api-reference.md +443 -0
  196. package/docusaurus/docs/authentication/api-key.md +339 -0
  197. package/docusaurus/docs/authentication/basic.md +276 -0
  198. package/docusaurus/docs/authentication/bearer.md +282 -0
  199. package/docusaurus/docs/authentication/oauth2.md +317 -0
  200. package/docusaurus/docs/authentication/overview.md +251 -0
  201. package/docusaurus/docs/cli.md +229 -0
  202. package/docusaurus/docs/core-concepts/actions.md +286 -0
  203. package/docusaurus/docs/core-concepts/missions.md +264 -0
  204. package/docusaurus/docs/core-concepts/schemas.md +353 -0
  205. package/docusaurus/docs/core-concepts/sources.md +339 -0
  206. package/docusaurus/docs/core-concepts/stores.md +332 -0
  207. package/docusaurus/docs/dsl-syntax/expressions.md +361 -0
  208. package/docusaurus/docs/dsl-syntax/fetch.md +293 -0
  209. package/docusaurus/docs/dsl-syntax/for-loops.md +324 -0
  210. package/docusaurus/docs/dsl-syntax/map.md +345 -0
  211. package/docusaurus/docs/dsl-syntax/match.md +387 -0
  212. package/docusaurus/docs/dsl-syntax/pipelines.md +397 -0
  213. package/docusaurus/docs/dsl-syntax/validate.md +401 -0
  214. package/docusaurus/docs/error-handling/dead-letter-queues.md +399 -0
  215. package/docusaurus/docs/error-handling/flow-control.md +337 -0
  216. package/docusaurus/docs/error-handling/retry-strategies.md +368 -0
  217. package/docusaurus/docs/examples.md +488 -0
  218. package/docusaurus/docs/getting-started.md +256 -0
  219. package/docusaurus/docs/http/circuit-breaker.md +401 -0
  220. package/docusaurus/docs/http/incremental-sync.md +394 -0
  221. package/docusaurus/docs/http/pagination.md +361 -0
  222. package/docusaurus/docs/http/rate-limiting.md +383 -0
  223. package/docusaurus/docs/http/requests.md +328 -0
  224. package/docusaurus/docs/http/retry.md +402 -0
  225. package/docusaurus/docs/intro.md +90 -0
  226. package/docusaurus/docs/openapi/loading-specs.md +305 -0
  227. package/docusaurus/docs/openapi/operation-calls.md +314 -0
  228. package/docusaurus/docs/openapi/overview.md +212 -0
  229. package/docusaurus/docs/openapi/response-validation.md +344 -0
  230. package/docusaurus/docs/scheduling/cron.md +305 -0
  231. package/docusaurus/docs/scheduling/daemon-mode.md +317 -0
  232. package/docusaurus/docs/scheduling/intervals.md +289 -0
  233. package/docusaurus/docs/scheduling/overview.md +231 -0
  234. package/docusaurus/docs/stores/custom-adapters.md +376 -0
  235. package/docusaurus/docs/stores/file.md +236 -0
  236. package/docusaurus/docs/stores/memory.md +193 -0
  237. package/docusaurus/docs/stores/overview.md +274 -0
  238. package/docusaurus/docs/stores/postgrest.md +316 -0
  239. package/docusaurus/docusaurus.config.ts +148 -0
  240. package/docusaurus/package-lock.json +18029 -0
  241. package/docusaurus/package.json +47 -0
  242. package/docusaurus/sidebars.ts +155 -0
  243. package/docusaurus/src/components/HomepageFeatures/index.tsx +105 -0
  244. package/docusaurus/src/components/HomepageFeatures/styles.module.css +12 -0
  245. package/docusaurus/src/css/custom.css +169 -0
  246. package/docusaurus/src/pages/index.module.css +48 -0
  247. package/docusaurus/src/pages/index.tsx +110 -0
  248. package/docusaurus/src/pages/markdown-page.md +7 -0
  249. package/docusaurus/static/.nojekyll +0 -0
  250. package/docusaurus/static/img/docusaurus-social-card.jpg +0 -0
  251. package/docusaurus/static/img/docusaurus.png +0 -0
  252. package/docusaurus/static/img/favicon.ico +0 -0
  253. package/docusaurus/static/img/logo.svg +10 -0
  254. package/docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
  255. package/docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
  256. package/docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
  257. package/docusaurus/tsconfig.json +8 -0
  258. package/examples/README.md +112 -0
  259. package/examples/error-handling/README.md +150 -0
  260. package/examples/error-handling/payment-processor.vague +287 -0
  261. package/examples/github-sync/README.md +74 -0
  262. package/examples/github-sync/fetch-issues.vague +47 -0
  263. package/examples/github-sync/fetch-prs.vague +40 -0
  264. package/examples/github-sync/mission.vague +101 -0
  265. package/examples/github-sync/normalize.vague +70 -0
  266. package/examples/jsonplaceholder/README.md +28 -0
  267. package/examples/jsonplaceholder/posts.vague +48 -0
  268. package/examples/petstore/README.md +35 -0
  269. package/examples/petstore/openapi.yaml +97 -0
  270. package/examples/petstore/sync.vague +52 -0
  271. package/examples/temporal-comparison/README.md +297 -0
  272. package/examples/temporal-comparison/reconciliation.vague +355 -0
  273. package/examples/temporal-comparison/temporal/activities/index.ts +8 -0
  274. package/examples/temporal-comparison/temporal/activities/shipstation.ts +225 -0
  275. package/examples/temporal-comparison/temporal/activities/shopify.ts +257 -0
  276. package/examples/temporal-comparison/temporal/activities/storage.ts +198 -0
  277. package/examples/temporal-comparison/temporal/activities/stripe.ts +169 -0
  278. package/examples/temporal-comparison/temporal/activities/validation.ts +205 -0
  279. package/examples/temporal-comparison/temporal/client/schedule.ts +218 -0
  280. package/examples/temporal-comparison/temporal/config/retry.ts +63 -0
  281. package/examples/temporal-comparison/temporal/types/index.ts +129 -0
  282. package/examples/temporal-comparison/temporal/workers/main.ts +130 -0
  283. package/examples/temporal-comparison/temporal/workflows/orderReconciliation.ts +262 -0
  284. package/examples/xero/README.md +88 -0
  285. package/examples/xero/invoices.vague +189 -0
  286. package/package.json +40 -0
  287. package/src/api-integration.test.ts +954 -0
  288. package/src/ast/index.ts +1 -0
  289. package/src/ast/nodes.ts +310 -0
  290. package/src/auth/auth.test.ts +326 -0
  291. package/src/auth/circuit-breaker.test.ts +390 -0
  292. package/src/auth/circuit-breaker.ts +379 -0
  293. package/src/auth/credentials.test.ts +273 -0
  294. package/src/auth/credentials.ts +246 -0
  295. package/src/auth/index.ts +40 -0
  296. package/src/auth/oauth2-provider.ts +177 -0
  297. package/src/auth/rate-limiter.ts +459 -0
  298. package/src/auth/token-store.ts +177 -0
  299. package/src/auth/types.ts +159 -0
  300. package/src/benchmark/e2e.bench.ts +288 -0
  301. package/src/benchmark/evaluator.bench.ts +331 -0
  302. package/src/benchmark/fixtures.ts +295 -0
  303. package/src/benchmark/index.ts +108 -0
  304. package/src/benchmark/lexer.bench.ts +69 -0
  305. package/src/benchmark/parser.bench.ts +103 -0
  306. package/src/benchmark/resilience.bench.ts +193 -0
  307. package/src/benchmark/store.bench.ts +147 -0
  308. package/src/benchmark/utils.ts +230 -0
  309. package/src/cli.ts +313 -0
  310. package/src/errors/errors.test.ts +234 -0
  311. package/src/errors/index.ts +223 -0
  312. package/src/execution/execution.test.ts +307 -0
  313. package/src/execution/index.ts +21 -0
  314. package/src/execution/state.ts +207 -0
  315. package/src/execution/store.ts +188 -0
  316. package/src/index.ts +169 -0
  317. package/src/integration.test.ts +192 -0
  318. package/src/interpreter/context.ts +57 -0
  319. package/src/interpreter/evaluator.test.ts +796 -0
  320. package/src/interpreter/evaluator.ts +245 -0
  321. package/src/interpreter/executor.ts +946 -0
  322. package/src/interpreter/fetch-handler.ts +302 -0
  323. package/src/interpreter/http.test.ts +423 -0
  324. package/src/interpreter/http.ts +308 -0
  325. package/src/interpreter/index.ts +32 -0
  326. package/src/interpreter/pagination.ts +207 -0
  327. package/src/interpreter/progress.test.ts +276 -0
  328. package/src/interpreter/schema-matcher.test.ts +160 -0
  329. package/src/interpreter/schema-matcher.ts +168 -0
  330. package/src/interpreter/signals.ts +73 -0
  331. package/src/interpreter/step-handlers/for-handler.ts +65 -0
  332. package/src/interpreter/step-handlers/index.ts +17 -0
  333. package/src/interpreter/step-handlers/map-handler.ts +24 -0
  334. package/src/interpreter/step-handlers/match-handler.ts +101 -0
  335. package/src/interpreter/step-handlers/store-handler.ts +78 -0
  336. package/src/interpreter/step-handlers/types.ts +17 -0
  337. package/src/interpreter/step-handlers/validate-handler.ts +30 -0
  338. package/src/interpreter/step-handlers/webhook-handler.ts +142 -0
  339. package/src/lexer/index.ts +18 -0
  340. package/src/lexer/lexer.test.ts +316 -0
  341. package/src/lexer/tokens.ts +179 -0
  342. package/src/loader/index.ts +288 -0
  343. package/src/loader/loader.test.ts +360 -0
  344. package/src/oas/index.ts +4 -0
  345. package/src/oas/loader.ts +126 -0
  346. package/src/oas/oas.test.ts +254 -0
  347. package/src/oas/validator.ts +299 -0
  348. package/src/parser/base.ts +124 -0
  349. package/src/parser/expressions.test.ts +525 -0
  350. package/src/parser/expressions.ts +314 -0
  351. package/src/parser/index.ts +3 -0
  352. package/src/parser/match.test.ts +296 -0
  353. package/src/parser/parser.test.ts +739 -0
  354. package/src/parser/parser.ts +1469 -0
  355. package/src/parser/schedule.test.ts +287 -0
  356. package/src/parser/webhook.test.ts +248 -0
  357. package/src/plugin.ts +83 -0
  358. package/src/scheduler/cron-parser.test.ts +236 -0
  359. package/src/scheduler/cron-parser.ts +236 -0
  360. package/src/scheduler/index.ts +10 -0
  361. package/src/scheduler/scheduler.ts +443 -0
  362. package/src/scheduler/types.ts +71 -0
  363. package/src/stores/factory.ts +104 -0
  364. package/src/stores/file.test.ts +276 -0
  365. package/src/stores/file.ts +211 -0
  366. package/src/stores/index.ts +6 -0
  367. package/src/stores/memory.test.ts +238 -0
  368. package/src/stores/memory.ts +63 -0
  369. package/src/stores/postgrest.test.ts +488 -0
  370. package/src/stores/postgrest.ts +263 -0
  371. package/src/stores/stores.test.ts +197 -0
  372. package/src/stores/types.ts +58 -0
  373. package/src/sync/index.ts +16 -0
  374. package/src/sync/state.ts +126 -0
  375. package/src/sync/store.ts +139 -0
  376. package/src/sync/sync.test.ts +271 -0
  377. package/src/utils/async.ts +10 -0
  378. package/src/utils/file.ts +106 -0
  379. package/src/utils/index.ts +14 -0
  380. package/src/utils/logger.ts +53 -0
  381. package/src/utils/path.ts +47 -0
  382. package/src/webhook/index.ts +15 -0
  383. package/src/webhook/server.test.ts +253 -0
  384. package/src/webhook/server.ts +389 -0
  385. package/src/webhook/store.ts +239 -0
  386. package/src/webhook/types.ts +93 -0
  387. package/tsconfig.json +17 -0
  388. package/vitest.config.ts +39 -0
@@ -0,0 +1,1469 @@
1
+ import { TokenType, type Expression, type SchemaDefinition, type FieldDefinition, type Token } from 'vague-lang';
2
+ import { ReqonTokenType } from '../lexer/tokens.js';
3
+ import { ReqonExpressionParser } from './expressions.js';
4
+ import type {
5
+ ReqonProgram,
6
+ Statement,
7
+ MissionDefinition,
8
+ SourceDefinition,
9
+ SourceConfig,
10
+ AuthConfig,
11
+ StoreDefinition,
12
+ ActionDefinition,
13
+ ActionStep,
14
+ FetchStep,
15
+ ForStep,
16
+ MapStep,
17
+ ValidateStep,
18
+ StoreStep,
19
+ MatchStep,
20
+ MatchArm,
21
+ FlowDirective,
22
+ LetStep,
23
+ WebhookStep,
24
+ WebhookStorageConfig,
25
+ PaginationConfig,
26
+ RetryConfig,
27
+ FieldMapping,
28
+ ValidationConstraint,
29
+ StoreOptions,
30
+ PipelineDefinition,
31
+ PipelineStage,
32
+ OperationRef,
33
+ ScheduleDefinition,
34
+ IntervalSchedule,
35
+ ScheduleRetryConfig,
36
+ SinceConfig,
37
+ RateLimitSourceConfig,
38
+ CircuitBreakerSourceConfig,
39
+ } from '../ast/nodes.js';
40
+
41
+ export class ReqonParser extends ReqonExpressionParser {
42
+ constructor(tokens: Token[], source?: string, filePath?: string) {
43
+ super(tokens, source, filePath);
44
+ }
45
+
46
+ parse(): ReqonProgram {
47
+ const statements: Statement[] = [];
48
+
49
+ while (!this.isAtEnd()) {
50
+ const stmt = this.parseStatement();
51
+ if (stmt) statements.push(stmt);
52
+ }
53
+
54
+ return { type: 'ReqonProgram', statements };
55
+ }
56
+
57
+ private parseStatement(): Statement | null {
58
+ // Reqon-specific statements
59
+ if (this.check(ReqonTokenType.MISSION)) return this.parseMission();
60
+ if (this.check(ReqonTokenType.SOURCE)) return this.parseSource();
61
+ if (this.check(ReqonTokenType.STORE)) return this.parseStoreDefinition();
62
+ if (this.check(ReqonTokenType.ACTION)) return this.parseAction();
63
+
64
+ // Vague statements (schema, import, let, etc.)
65
+ if (this.check(TokenType.SCHEMA)) return this.parseSchema();
66
+ if (this.check(TokenType.IMPORT)) return this.parseImport();
67
+ if (this.check(TokenType.LET)) return this.parseLet();
68
+
69
+ throw this.error(`Unexpected token: ${this.peek().value}`);
70
+ }
71
+
72
+ // ============================================
73
+ // Mission definition
74
+ // ============================================
75
+
76
+ private parseMission(): MissionDefinition {
77
+ this.consume(ReqonTokenType.MISSION, "Expected 'mission'");
78
+ const name = this.consume(TokenType.IDENTIFIER, 'Expected mission name').value;
79
+
80
+ this.consume(TokenType.LBRACE, "Expected '{'");
81
+
82
+ const sources: SourceDefinition[] = [];
83
+ const stores: StoreDefinition[] = [];
84
+ const schemas: SchemaDefinition[] = [];
85
+ const actions: ActionDefinition[] = [];
86
+ let pipeline: PipelineDefinition | undefined;
87
+ let schedule: ScheduleDefinition | undefined;
88
+
89
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
90
+ if (this.check(ReqonTokenType.SOURCE)) {
91
+ sources.push(this.parseSource());
92
+ } else if (this.check(ReqonTokenType.STORE)) {
93
+ stores.push(this.parseStoreDefinition());
94
+ } else if (this.check(TokenType.SCHEMA)) {
95
+ schemas.push(this.parseSchema());
96
+ } else if (this.check(ReqonTokenType.ACTION)) {
97
+ actions.push(this.parseAction());
98
+ } else if (this.check(ReqonTokenType.RUN)) {
99
+ pipeline = this.parsePipeline();
100
+ } else if (this.check(ReqonTokenType.SCHEDULE)) {
101
+ schedule = this.parseSchedule();
102
+ } else {
103
+ throw this.error(`Unexpected token in mission: ${this.peek().value}`);
104
+ }
105
+ this.match(TokenType.COMMA);
106
+ }
107
+
108
+ this.consume(TokenType.RBRACE, "Expected '}'");
109
+
110
+ if (!pipeline) {
111
+ throw this.error('Mission must have a run pipeline');
112
+ }
113
+
114
+ // Build sets of defined names for validation
115
+ const definedStores = new Set(stores.map((s) => s.name));
116
+ const definedActions = new Set(actions.map((a) => a.name));
117
+ const definedSources = new Set(sources.map((s) => s.name));
118
+
119
+ // Validate all references
120
+ this.validateActionReferences(actions, definedStores, definedSources, definedActions);
121
+ this.validatePipelineReferences(pipeline, definedActions);
122
+
123
+ return {
124
+ type: 'MissionDefinition',
125
+ name,
126
+ schedule,
127
+ sources,
128
+ stores,
129
+ schemas,
130
+ actions,
131
+ pipeline,
132
+ };
133
+ }
134
+
135
+ /**
136
+ * Validate that all store, source, and action references in actions exist
137
+ */
138
+ private validateActionReferences(
139
+ actions: ActionDefinition[],
140
+ definedStores: Set<string>,
141
+ definedSources: Set<string>,
142
+ definedActions: Set<string>
143
+ ): void {
144
+ for (const action of actions) {
145
+ this.validateStepsReferences(
146
+ action.steps,
147
+ definedStores,
148
+ definedSources,
149
+ definedActions,
150
+ action.name
151
+ );
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Recursively validate store, source, and action references in action steps
157
+ */
158
+ private validateStepsReferences(
159
+ steps: ActionStep[],
160
+ definedStores: Set<string>,
161
+ definedSources: Set<string>,
162
+ definedActions: Set<string>,
163
+ actionName: string
164
+ ): void {
165
+ for (const step of steps) {
166
+ if (step.type === 'StoreStep') {
167
+ if (!definedStores.has(step.target)) {
168
+ throw this.error(
169
+ `Store '${step.target}' is not defined. ` +
170
+ `Available stores: ${[...definedStores].join(', ') || 'none'}`
171
+ );
172
+ }
173
+ } else if (step.type === 'FetchStep') {
174
+ // Validate source reference if specified
175
+ if (step.source && !definedSources.has(step.source)) {
176
+ throw this.error(
177
+ `Source '${step.source}' is not defined. ` +
178
+ `Available sources: ${[...definedSources].join(', ') || 'none'}`
179
+ );
180
+ }
181
+ // Validate operationRef source if present
182
+ if (step.operationRef && !definedSources.has(step.operationRef.source)) {
183
+ throw this.error(
184
+ `Source '${step.operationRef.source}' is not defined. ` +
185
+ `Available sources: ${[...definedSources].join(', ') || 'none'}`
186
+ );
187
+ }
188
+ } else if (step.type === 'ForStep') {
189
+ // Recursively validate nested steps
190
+ this.validateStepsReferences(
191
+ step.steps,
192
+ definedStores,
193
+ definedSources,
194
+ definedActions,
195
+ actionName
196
+ );
197
+ } else if (step.type === 'MatchStep') {
198
+ // Validate steps in match arms
199
+ for (const arm of step.arms) {
200
+ if (arm.steps) {
201
+ this.validateStepsReferences(
202
+ arm.steps,
203
+ definedStores,
204
+ definedSources,
205
+ definedActions,
206
+ actionName
207
+ );
208
+ }
209
+ // Validate jump target in flow directive
210
+ if (arm.flow?.type === 'jump' && !definedActions.has(arm.flow.action)) {
211
+ throw this.error(
212
+ `Action '${arm.flow.action}' referenced in jump is not defined. ` +
213
+ `Available actions: ${[...definedActions].join(', ') || 'none'}`
214
+ );
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Validate that all action references in the pipeline exist
223
+ */
224
+ private validatePipelineReferences(
225
+ pipeline: PipelineDefinition,
226
+ definedActions: Set<string>
227
+ ): void {
228
+ for (const stage of pipeline.stages) {
229
+ if (stage.action) {
230
+ if (!definedActions.has(stage.action)) {
231
+ throw this.error(
232
+ `Action '${stage.action}' is not defined. ` +
233
+ `Available actions: ${[...definedActions].join(', ') || 'none'}`
234
+ );
235
+ }
236
+ }
237
+ if (stage.actions) {
238
+ for (const actionName of stage.actions) {
239
+ if (!definedActions.has(actionName)) {
240
+ throw this.error(
241
+ `Action '${actionName}' is not defined. ` +
242
+ `Available actions: ${[...definedActions].join(', ') || 'none'}`
243
+ );
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ // ============================================
251
+ // Schedule definition
252
+ // ============================================
253
+
254
+ private parseSchedule(): ScheduleDefinition {
255
+ this.consume(ReqonTokenType.SCHEDULE, "Expected 'schedule'");
256
+ this.consume(TokenType.COLON, "Expected ':'");
257
+
258
+ let scheduleType: ScheduleDefinition['scheduleType'];
259
+ let interval: IntervalSchedule | undefined;
260
+ let cronExpression: string | undefined;
261
+ let runAt: string | undefined;
262
+ let timezone: string | undefined;
263
+ let maxConcurrency: number | undefined;
264
+ let skipIfRunning: boolean | undefined;
265
+ let retryOnFailure: ScheduleRetryConfig | undefined;
266
+
267
+ // Determine schedule type
268
+ if (this.check(ReqonTokenType.EVERY)) {
269
+ // Interval-based: schedule: every 6 hours
270
+ scheduleType = 'interval';
271
+ interval = this.parseIntervalSchedule();
272
+ } else if (this.check(ReqonTokenType.CRON)) {
273
+ // Cron-based: schedule: cron "0 */6 * * *"
274
+ scheduleType = 'cron';
275
+ this.advance(); // consume 'cron'
276
+ cronExpression = this.consume(TokenType.STRING, 'Expected cron expression string').value;
277
+ } else if (this.check(ReqonTokenType.AT)) {
278
+ // One-time: schedule: at "2025-01-20 09:00 UTC"
279
+ scheduleType = 'once';
280
+ this.advance(); // consume 'at'
281
+ runAt = this.consume(TokenType.STRING, 'Expected datetime string').value;
282
+ } else {
283
+ throw this.error(`Expected 'every', 'cron', or 'at' for schedule type`);
284
+ }
285
+
286
+ // Optional configuration block
287
+ if (this.match(TokenType.LBRACE)) {
288
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
289
+ // Handle keyword tokens that can appear as option keys
290
+ let key: string;
291
+ if (this.check(ReqonTokenType.RETRY)) {
292
+ this.advance();
293
+ key = 'retry';
294
+ } else {
295
+ key = this.consume(TokenType.IDENTIFIER, 'Expected schedule option key').value;
296
+ }
297
+ this.consume(TokenType.COLON, "Expected ':'");
298
+
299
+ switch (key) {
300
+ case 'timezone':
301
+ timezone = this.consume(TokenType.STRING, 'Expected timezone string').value;
302
+ break;
303
+ case 'maxConcurrency':
304
+ maxConcurrency = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
305
+ break;
306
+ case 'skipIfRunning':
307
+ skipIfRunning = this.match(TokenType.TRUE);
308
+ if (!skipIfRunning) {
309
+ this.consume(TokenType.FALSE, "Expected 'true' or 'false'");
310
+ }
311
+ break;
312
+ case 'retry':
313
+ retryOnFailure = this.parseScheduleRetryConfig();
314
+ break;
315
+ default:
316
+ throw this.error(`Unknown schedule option: ${key}`);
317
+ }
318
+
319
+ this.match(TokenType.COMMA);
320
+ }
321
+ this.consume(TokenType.RBRACE, "Expected '}'");
322
+ }
323
+
324
+ return {
325
+ type: 'ScheduleDefinition',
326
+ scheduleType,
327
+ interval,
328
+ cronExpression,
329
+ runAt,
330
+ timezone,
331
+ maxConcurrency,
332
+ skipIfRunning,
333
+ retryOnFailure,
334
+ };
335
+ }
336
+
337
+ private parseIntervalSchedule(): IntervalSchedule {
338
+ this.consume(ReqonTokenType.EVERY, "Expected 'every'");
339
+ const value = parseInt(this.consume(TokenType.NUMBER, 'Expected interval value').value, 10);
340
+
341
+ let unit: IntervalSchedule['unit'];
342
+ const unitToken = this.advance();
343
+
344
+ switch (unitToken.type) {
345
+ case ReqonTokenType.SECONDS:
346
+ unit = 'seconds';
347
+ break;
348
+ case ReqonTokenType.MINUTES:
349
+ unit = 'minutes';
350
+ break;
351
+ case ReqonTokenType.HOURS:
352
+ unit = 'hours';
353
+ break;
354
+ case ReqonTokenType.DAYS:
355
+ unit = 'days';
356
+ break;
357
+ case ReqonTokenType.WEEKS:
358
+ unit = 'weeks';
359
+ break;
360
+ default:
361
+ throw this.error(`Expected time unit (seconds, minutes, hours, days, weeks), got: ${unitToken.value}`);
362
+ }
363
+
364
+ return { value, unit };
365
+ }
366
+
367
+ private parseScheduleRetryConfig(): ScheduleRetryConfig {
368
+ this.consume(TokenType.LBRACE, "Expected '{'");
369
+
370
+ let maxRetries = 3;
371
+ let delaySeconds = 60;
372
+
373
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
374
+ const key = this.consume(TokenType.IDENTIFIER, 'Expected retry option').value;
375
+ this.consume(TokenType.COLON, "Expected ':'");
376
+
377
+ switch (key) {
378
+ case 'maxRetries':
379
+ maxRetries = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
380
+ break;
381
+ case 'delaySeconds':
382
+ delaySeconds = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
383
+ break;
384
+ default:
385
+ throw this.error(`Unknown retry option: ${key}`);
386
+ }
387
+
388
+ this.match(TokenType.COMMA);
389
+ }
390
+
391
+ this.consume(TokenType.RBRACE, "Expected '}'");
392
+
393
+ return { maxRetries, delaySeconds };
394
+ }
395
+
396
+ // ============================================
397
+ // Source definition
398
+ // ============================================
399
+
400
+ private parseSource(): SourceDefinition {
401
+ this.consume(ReqonTokenType.SOURCE, "Expected 'source'");
402
+ const name = this.consume(TokenType.IDENTIFIER, 'Expected source name').value;
403
+
404
+ // Check for 'from' clause (OAS spec path)
405
+ let specPath: string | undefined;
406
+ if (this.match(ReqonTokenType.FROM)) {
407
+ specPath = this.consume(TokenType.STRING, 'Expected OAS spec path').value;
408
+ }
409
+
410
+ this.consume(TokenType.LBRACE, "Expected '{'");
411
+ const config = this.parseSourceConfig(specPath !== undefined);
412
+ this.consume(TokenType.RBRACE, "Expected '}'");
413
+
414
+ return { type: 'SourceDefinition', name, specPath, config };
415
+ }
416
+
417
+ private parseSourceConfig(hasOAS = false): SourceConfig {
418
+ let auth: AuthConfig | undefined;
419
+ let base: string | undefined;
420
+ let validateResponses: boolean | undefined;
421
+ let rateLimit: RateLimitSourceConfig | undefined;
422
+ let circuitBreaker: CircuitBreakerSourceConfig | undefined;
423
+ const headers: Record<string, Expression> = {};
424
+
425
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
426
+ const key = this.consume(TokenType.IDENTIFIER, 'Expected config key').value;
427
+ this.consume(TokenType.COLON, "Expected ':'");
428
+
429
+ if (key === 'auth') {
430
+ auth = this.parseAuthConfig();
431
+ } else if (key === 'base') {
432
+ base = this.consume(TokenType.STRING, 'Expected base URL string').value;
433
+ } else if (key === 'validateResponses') {
434
+ validateResponses = this.match(TokenType.TRUE);
435
+ if (!validateResponses) {
436
+ this.consume(TokenType.FALSE, "Expected 'true' or 'false'");
437
+ }
438
+ } else if (key === 'headers') {
439
+ this.consume(TokenType.LBRACE, "Expected '{'");
440
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
441
+ const headerName = this.consume(TokenType.STRING, 'Expected header name').value;
442
+ this.consume(TokenType.COLON, "Expected ':'");
443
+ headers[headerName] = this.parseExpression();
444
+ this.match(TokenType.COMMA);
445
+ }
446
+ this.consume(TokenType.RBRACE, "Expected '}'");
447
+ } else if (key === 'rateLimit') {
448
+ rateLimit = this.parseRateLimitConfig();
449
+ } else if (key === 'circuitBreaker') {
450
+ circuitBreaker = this.parseCircuitBreakerConfig();
451
+ }
452
+
453
+ this.match(TokenType.COMMA);
454
+ }
455
+
456
+ if (!auth) throw this.error('Source must have auth config');
457
+ // Base URL is only required if not using OAS
458
+ if (!base && !hasOAS) throw this.error('Source must have base URL (or use OAS spec)');
459
+
460
+ return {
461
+ auth,
462
+ base,
463
+ validateResponses,
464
+ headers: Object.keys(headers).length > 0 ? headers : undefined,
465
+ rateLimit,
466
+ circuitBreaker,
467
+ };
468
+ }
469
+
470
+ private parseRateLimitConfig(): RateLimitSourceConfig {
471
+ this.consume(TokenType.LBRACE, "Expected '{'");
472
+
473
+ const config: RateLimitSourceConfig = {};
474
+
475
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
476
+ const key = this.consume(TokenType.IDENTIFIER, 'Expected rate limit option').value;
477
+ this.consume(TokenType.COLON, "Expected ':'");
478
+
479
+ switch (key) {
480
+ case 'strategy':
481
+ config.strategy = this.consume(TokenType.IDENTIFIER, 'Expected strategy').value as 'pause' | 'throttle' | 'fail';
482
+ break;
483
+ case 'maxWait':
484
+ config.maxWait = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
485
+ break;
486
+ case 'fallbackRpm':
487
+ config.fallbackRpm = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
488
+ break;
489
+ default:
490
+ throw this.error(`Unknown rate limit option: ${key}`);
491
+ }
492
+
493
+ this.match(TokenType.COMMA);
494
+ }
495
+
496
+ this.consume(TokenType.RBRACE, "Expected '}'");
497
+
498
+ return config;
499
+ }
500
+
501
+ private parseCircuitBreakerConfig(): CircuitBreakerSourceConfig {
502
+ this.consume(TokenType.LBRACE, "Expected '{'");
503
+
504
+ const config: CircuitBreakerSourceConfig = {};
505
+
506
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
507
+ const key = this.consume(TokenType.IDENTIFIER, 'Expected circuit breaker option').value;
508
+ this.consume(TokenType.COLON, "Expected ':'");
509
+
510
+ switch (key) {
511
+ case 'failureThreshold':
512
+ config.failureThreshold = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
513
+ break;
514
+ case 'resetTimeout':
515
+ config.resetTimeout = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
516
+ break;
517
+ case 'successThreshold':
518
+ config.successThreshold = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
519
+ break;
520
+ case 'failureWindow':
521
+ config.failureWindow = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
522
+ break;
523
+ default:
524
+ throw this.error(`Unknown circuit breaker option: ${key}`);
525
+ }
526
+
527
+ this.match(TokenType.COMMA);
528
+ }
529
+
530
+ this.consume(TokenType.RBRACE, "Expected '}'");
531
+
532
+ return config;
533
+ }
534
+
535
+ private parseAuthConfig(): AuthConfig {
536
+ const typeToken = this.advance();
537
+ let type: AuthConfig['type'];
538
+
539
+ switch (typeToken.type) {
540
+ case ReqonTokenType.OAUTH2:
541
+ type = 'oauth2';
542
+ break;
543
+ case ReqonTokenType.BEARER:
544
+ type = 'bearer';
545
+ break;
546
+ case ReqonTokenType.BASIC:
547
+ type = 'basic';
548
+ break;
549
+ case ReqonTokenType.API_KEY:
550
+ type = 'api_key';
551
+ break;
552
+ case ReqonTokenType.NONE:
553
+ type = 'none';
554
+ break;
555
+ default:
556
+ throw this.error(`Unknown auth type: ${typeToken.value}`);
557
+ }
558
+
559
+ return { type };
560
+ }
561
+
562
+ // ============================================
563
+ // Store definition
564
+ // ============================================
565
+
566
+ private parseStoreDefinition(): StoreDefinition {
567
+ this.consume(ReqonTokenType.STORE, "Expected 'store'");
568
+ const name = this.consumeIdentifier('Expected store name').value;
569
+ this.consume(TokenType.COLON, "Expected ':'");
570
+
571
+ let storeType: StoreDefinition['storeType'];
572
+ const typeToken = this.advance();
573
+
574
+ switch (typeToken.type) {
575
+ case ReqonTokenType.NOSQL:
576
+ storeType = 'nosql';
577
+ break;
578
+ case ReqonTokenType.SQL:
579
+ storeType = 'sql';
580
+ break;
581
+ case ReqonTokenType.MEMORY:
582
+ storeType = 'memory';
583
+ break;
584
+ default:
585
+ throw this.error(`Unknown store type: ${typeToken.value}`);
586
+ }
587
+
588
+ this.consume(TokenType.LPAREN, "Expected '('");
589
+ const target = this.consume(TokenType.STRING, 'Expected target name').value;
590
+ this.consume(TokenType.RPAREN, "Expected ')'");
591
+
592
+ return { type: 'StoreDefinition', name, storeType, target };
593
+ }
594
+
595
+ // ============================================
596
+ // Action definition
597
+ // ============================================
598
+
599
+ private parseAction(): ActionDefinition {
600
+ this.consume(ReqonTokenType.ACTION, "Expected 'action'");
601
+ const name = this.consume(TokenType.IDENTIFIER, 'Expected action name').value;
602
+
603
+ this.consume(TokenType.LBRACE, "Expected '{'");
604
+ const steps: ActionStep[] = [];
605
+
606
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
607
+ steps.push(this.parseActionStep());
608
+ this.match(TokenType.COMMA);
609
+ }
610
+
611
+ this.consume(TokenType.RBRACE, "Expected '}'");
612
+
613
+ return { type: 'ActionDefinition', name, steps };
614
+ }
615
+
616
+ private parseActionStep(): ActionStep {
617
+ if (this.check(ReqonTokenType.CALL)) return this.parseCallStep();
618
+ // Shorthand: get "/path", post "/path", etc.
619
+ if (this.checkHttpMethod()) return this.parseHttpMethodStep();
620
+ if (this.check(ReqonTokenType.FOR)) return this.parseForStep();
621
+ if (this.check(ReqonTokenType.MAP)) return this.parseMapStep();
622
+ if (this.check(TokenType.VALIDATE)) return this.parseValidateStep();
623
+ if (this.check(ReqonTokenType.STORE)) return this.parseStoreStep();
624
+ if (this.check(TokenType.MATCH)) return this.parseMatchStep();
625
+ if (this.check(TokenType.LET)) return this.parseLetStep();
626
+ if (this.check(ReqonTokenType.WAIT)) return this.parseWaitStep();
627
+
628
+ throw this.error(`Expected action step, got: ${this.peek().value}`);
629
+ }
630
+
631
+ private checkHttpMethod(): boolean {
632
+ const t = this.peek().type;
633
+ return (
634
+ t === ReqonTokenType.GET ||
635
+ t === ReqonTokenType.POST ||
636
+ t === ReqonTokenType.PUT ||
637
+ t === ReqonTokenType.PATCH ||
638
+ t === ReqonTokenType.DELETE
639
+ );
640
+ }
641
+
642
+ /**
643
+ * Parse HTTP method syntax: get "/path" { options }
644
+ */
645
+ private parseHttpMethodStep(): FetchStep {
646
+ const methodToken = this.advance();
647
+ let method: FetchStep['method'];
648
+
649
+ switch (methodToken.type) {
650
+ case ReqonTokenType.GET:
651
+ method = 'GET';
652
+ break;
653
+ case ReqonTokenType.POST:
654
+ method = 'POST';
655
+ break;
656
+ case ReqonTokenType.PUT:
657
+ method = 'PUT';
658
+ break;
659
+ case ReqonTokenType.PATCH:
660
+ method = 'PATCH';
661
+ break;
662
+ case ReqonTokenType.DELETE:
663
+ method = 'DELETE';
664
+ break;
665
+ default:
666
+ throw this.error(`Unexpected HTTP method token: ${methodToken.value}`);
667
+ }
668
+
669
+ const path = this.parseExpression();
670
+
671
+ // Parse optional config block (same as parseFetchStep)
672
+ let source: string | undefined;
673
+ let body: Expression | undefined;
674
+ let headers: Record<string, Expression> | undefined;
675
+ let paginate: PaginationConfig | undefined;
676
+ let until: Expression | undefined;
677
+ let retry: RetryConfig | undefined;
678
+ let since: SinceConfig | undefined;
679
+
680
+ if (this.match(TokenType.LBRACE)) {
681
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
682
+ let key: string;
683
+ if (this.check(ReqonTokenType.SOURCE)) {
684
+ this.advance();
685
+ key = 'source';
686
+ } else if (this.check(ReqonTokenType.PAGINATE)) {
687
+ this.advance();
688
+ key = 'paginate';
689
+ } else if (this.check(ReqonTokenType.UNTIL)) {
690
+ this.advance();
691
+ key = 'until';
692
+ } else if (this.check(ReqonTokenType.RETRY)) {
693
+ this.advance();
694
+ key = 'retry';
695
+ } else if (this.check(ReqonTokenType.SINCE)) {
696
+ this.advance();
697
+ key = 'since';
698
+ } else {
699
+ key = this.consume(TokenType.IDENTIFIER, 'Expected option key').value;
700
+ }
701
+ this.consume(TokenType.COLON, "Expected ':'");
702
+
703
+ switch (key) {
704
+ case 'source':
705
+ source = this.consume(TokenType.IDENTIFIER, 'Expected source name').value;
706
+ break;
707
+ case 'body':
708
+ body = this.parseExpression();
709
+ break;
710
+ case 'paginate':
711
+ paginate = this.parsePaginationConfig();
712
+ break;
713
+ case 'until':
714
+ until = this.parseExpression();
715
+ break;
716
+ case 'retry':
717
+ retry = this.parseRetryConfig();
718
+ break;
719
+ case 'since':
720
+ since = this.parseSinceConfig();
721
+ break;
722
+ default:
723
+ throw this.error(`Unknown fetch option: ${key}`);
724
+ }
725
+
726
+ this.match(TokenType.COMMA);
727
+ }
728
+ this.consume(TokenType.RBRACE, "Expected '}'");
729
+ }
730
+
731
+ return {
732
+ type: 'FetchStep',
733
+ method,
734
+ path,
735
+ source,
736
+ body,
737
+ headers,
738
+ paginate,
739
+ until,
740
+ retry,
741
+ since,
742
+ };
743
+ }
744
+
745
+ // ============================================
746
+ // Call step (OAS operationId)
747
+ // ============================================
748
+
749
+ /**
750
+ * Parse OAS-style call: call Source.operationId { options }
751
+ * For direct HTTP requests, use: get "/path", post "/path", etc.
752
+ */
753
+ private parseCallStep(): FetchStep {
754
+ this.consume(ReqonTokenType.CALL, "Expected 'call'");
755
+
756
+ // OAS-style: call Source.operationId
757
+ const sourceName = this.consume(TokenType.IDENTIFIER, 'Expected source name').value;
758
+ this.consume(TokenType.DOT, "Expected '.'");
759
+ const opId = this.consume(TokenType.IDENTIFIER, 'Expected operationId').value;
760
+ const operationRef: OperationRef = { source: sourceName, operationId: opId };
761
+
762
+ let source: string | undefined;
763
+ let body: Expression | undefined;
764
+ let headers: Record<string, Expression> | undefined;
765
+ let paginate: PaginationConfig | undefined;
766
+ let until: Expression | undefined;
767
+ let retry: RetryConfig | undefined;
768
+ let since: SinceConfig | undefined;
769
+
770
+ if (this.match(TokenType.LBRACE)) {
771
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
772
+ // Accept keyword tokens as option keys
773
+ let key: string;
774
+ if (this.check(ReqonTokenType.SOURCE)) {
775
+ this.advance();
776
+ key = 'source';
777
+ } else if (this.check(ReqonTokenType.PAGINATE)) {
778
+ this.advance();
779
+ key = 'paginate';
780
+ } else if (this.check(ReqonTokenType.UNTIL)) {
781
+ this.advance();
782
+ key = 'until';
783
+ } else if (this.check(ReqonTokenType.RETRY)) {
784
+ this.advance();
785
+ key = 'retry';
786
+ } else if (this.check(ReqonTokenType.SINCE)) {
787
+ this.advance();
788
+ key = 'since';
789
+ } else {
790
+ key = this.consume(TokenType.IDENTIFIER, 'Expected option key').value;
791
+ }
792
+ this.consume(TokenType.COLON, "Expected ':'");
793
+
794
+ switch (key) {
795
+ case 'source':
796
+ source = this.consume(TokenType.IDENTIFIER, 'Expected source name').value;
797
+ break;
798
+ case 'body':
799
+ body = this.parseExpression();
800
+ break;
801
+ case 'paginate':
802
+ paginate = this.parsePaginationConfig();
803
+ break;
804
+ case 'until':
805
+ until = this.parseExpression();
806
+ break;
807
+ case 'retry':
808
+ retry = this.parseRetryConfig();
809
+ break;
810
+ case 'since':
811
+ since = this.parseSinceConfig();
812
+ break;
813
+ default:
814
+ throw this.error(`Unknown fetch option: ${key}`);
815
+ }
816
+
817
+ this.match(TokenType.COMMA);
818
+ }
819
+ this.consume(TokenType.RBRACE, "Expected '}'");
820
+ }
821
+
822
+ return {
823
+ type: 'FetchStep',
824
+ operationRef,
825
+ source,
826
+ body,
827
+ headers,
828
+ paginate,
829
+ until,
830
+ retry,
831
+ since,
832
+ };
833
+ }
834
+
835
+ private parseSinceConfig(): SinceConfig {
836
+ // since: lastSync
837
+ // since: lastSync("custom-key")
838
+ // since: lastSync { param: "modified_since", format: "unix" }
839
+
840
+ if (this.check(ReqonTokenType.LAST_SYNC)) {
841
+ this.advance();
842
+
843
+ let key: string | undefined;
844
+ let param: string | undefined;
845
+ let format: SinceConfig['format'];
846
+ let updateFrom: string | undefined;
847
+
848
+ // Check for optional key: lastSync("key")
849
+ if (this.match(TokenType.LPAREN)) {
850
+ key = this.consume(TokenType.STRING, 'Expected checkpoint key').value;
851
+ this.consume(TokenType.RPAREN, "Expected ')'");
852
+ }
853
+
854
+ // Check for optional config block
855
+ if (this.match(TokenType.LBRACE)) {
856
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
857
+ const optionKey = this.consume(TokenType.IDENTIFIER, 'Expected option key').value;
858
+ this.consume(TokenType.COLON, "Expected ':'");
859
+
860
+ switch (optionKey) {
861
+ case 'param':
862
+ param = this.consume(TokenType.STRING, 'Expected param name').value;
863
+ break;
864
+ case 'format':
865
+ format = this.consume(TokenType.IDENTIFIER, 'Expected format').value as SinceConfig['format'];
866
+ break;
867
+ case 'updateFrom':
868
+ updateFrom = this.consume(TokenType.STRING, 'Expected field path').value;
869
+ break;
870
+ default:
871
+ throw this.error(`Unknown since option: ${optionKey}`);
872
+ }
873
+
874
+ this.match(TokenType.COMMA);
875
+ }
876
+ this.consume(TokenType.RBRACE, "Expected '}'");
877
+ }
878
+
879
+ return {
880
+ type: 'lastSync',
881
+ key,
882
+ param,
883
+ format,
884
+ updateFrom,
885
+ };
886
+ }
887
+
888
+ // since: <expression> - custom expression for the timestamp
889
+ const expression = this.parseExpression();
890
+ return {
891
+ type: 'expression',
892
+ expression,
893
+ };
894
+ }
895
+
896
+ private parsePaginationConfig(): PaginationConfig {
897
+ const typeToken = this.advance();
898
+ let type: PaginationConfig['type'];
899
+
900
+ switch (typeToken.type) {
901
+ case ReqonTokenType.OFFSET:
902
+ type = 'offset';
903
+ break;
904
+ case ReqonTokenType.CURSOR:
905
+ type = 'cursor';
906
+ break;
907
+ case ReqonTokenType.PAGE:
908
+ type = 'page';
909
+ break;
910
+ default:
911
+ throw this.error(`Unknown pagination type: ${typeToken.value}`);
912
+ }
913
+
914
+ this.consume(TokenType.LPAREN, "Expected '('");
915
+ // Accept keyword tokens as param names (e.g., 'page', 'offset', 'cursor')
916
+ let param: string;
917
+ if (this.check(ReqonTokenType.PAGE)) {
918
+ param = this.advance().value;
919
+ } else if (this.check(ReqonTokenType.OFFSET)) {
920
+ param = this.advance().value;
921
+ } else if (this.check(ReqonTokenType.CURSOR)) {
922
+ param = this.advance().value;
923
+ } else {
924
+ param = this.consume(TokenType.IDENTIFIER, 'Expected param name').value;
925
+ }
926
+ this.consume(TokenType.COMMA, "Expected ','");
927
+ const pageSize = parseInt(this.consume(TokenType.NUMBER, 'Expected page size').value, 10);
928
+
929
+ let cursorPath: string | undefined;
930
+ if (type === 'cursor' && this.match(TokenType.COMMA)) {
931
+ cursorPath = this.consume(TokenType.STRING, 'Expected cursor path').value;
932
+ }
933
+
934
+ this.consume(TokenType.RPAREN, "Expected ')'");
935
+
936
+ return { type, param, pageSize, cursorPath };
937
+ }
938
+
939
+ private parseRetryConfig(): RetryConfig {
940
+ this.consume(TokenType.LBRACE, "Expected '{'");
941
+
942
+ let maxAttempts = 3;
943
+ let backoff: RetryConfig['backoff'] = 'exponential';
944
+ let initialDelay = 1000;
945
+ let maxDelay: number | undefined;
946
+
947
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
948
+ const key = this.consume(TokenType.IDENTIFIER, 'Expected retry option').value;
949
+ this.consume(TokenType.COLON, "Expected ':'");
950
+
951
+ switch (key) {
952
+ case 'maxAttempts':
953
+ maxAttempts = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
954
+ break;
955
+ case 'backoff':
956
+ backoff = this.consume(TokenType.IDENTIFIER, 'Expected backoff type').value as RetryConfig['backoff'];
957
+ break;
958
+ case 'initialDelay':
959
+ initialDelay = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
960
+ break;
961
+ case 'maxDelay':
962
+ maxDelay = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
963
+ break;
964
+ }
965
+
966
+ this.match(TokenType.COMMA);
967
+ }
968
+
969
+ this.consume(TokenType.RBRACE, "Expected '}'");
970
+
971
+ return { maxAttempts, backoff, initialDelay, maxDelay };
972
+ }
973
+
974
+ // ============================================
975
+ // For step
976
+ // ============================================
977
+
978
+ private parseForStep(): ForStep {
979
+ this.consume(ReqonTokenType.FOR, "Expected 'for'");
980
+ const variable = this.consumeIdentifier('Expected variable name').value;
981
+ this.consume(TokenType.IN, "Expected 'in'");
982
+ const collection = this.parseExpression();
983
+
984
+ let condition: Expression | undefined;
985
+ if (this.match(TokenType.WHERE)) {
986
+ condition = this.parseExpression();
987
+ }
988
+
989
+ this.consume(TokenType.LBRACE, "Expected '{'");
990
+ const steps: ActionStep[] = [];
991
+
992
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
993
+ steps.push(this.parseActionStep());
994
+ this.match(TokenType.COMMA);
995
+ }
996
+
997
+ this.consume(TokenType.RBRACE, "Expected '}'");
998
+
999
+ return { type: 'ForStep', variable, collection, condition, steps };
1000
+ }
1001
+
1002
+ // ============================================
1003
+ // Map step
1004
+ // ============================================
1005
+
1006
+ private parseMapStep(): MapStep {
1007
+ this.consume(ReqonTokenType.MAP, "Expected 'map'");
1008
+ const source = this.parseExpression();
1009
+ this.consume(TokenType.RIGHT_ARROW, "Expected '->'");
1010
+ const targetSchema = this.consume(TokenType.IDENTIFIER, 'Expected target schema').value;
1011
+
1012
+ this.consume(TokenType.LBRACE, "Expected '{'");
1013
+ const mappings: FieldMapping[] = [];
1014
+
1015
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1016
+ const field = this.consumeIdentifier('Expected field name').value;
1017
+ this.consume(TokenType.COLON, "Expected ':'");
1018
+ const expression = this.parseExpression();
1019
+ mappings.push({ field, expression });
1020
+ this.match(TokenType.COMMA);
1021
+ }
1022
+
1023
+ this.consume(TokenType.RBRACE, "Expected '}'");
1024
+
1025
+ return { type: 'MapStep', source, targetSchema, mappings };
1026
+ }
1027
+
1028
+ // ============================================
1029
+ // Validate step
1030
+ // ============================================
1031
+
1032
+ private parseValidateStep(): ValidateStep {
1033
+ this.consume(TokenType.VALIDATE, "Expected 'validate'");
1034
+ const target = this.parseExpression();
1035
+
1036
+ this.consume(TokenType.LBRACE, "Expected '{'");
1037
+ const constraints: ValidationConstraint[] = [];
1038
+
1039
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1040
+ this.consume(TokenType.ASSUME, "Expected 'assume'");
1041
+ const condition = this.parseExpression();
1042
+
1043
+ let message: string | undefined;
1044
+ let severity: ValidationConstraint['severity'] = 'error';
1045
+
1046
+ // Optional message and severity could be added here
1047
+
1048
+ constraints.push({ type: 'ValidationConstraint', condition, message, severity });
1049
+ this.match(TokenType.COMMA);
1050
+ }
1051
+
1052
+ this.consume(TokenType.RBRACE, "Expected '}'");
1053
+
1054
+ return { type: 'ValidateStep', target, constraints };
1055
+ }
1056
+
1057
+ // ============================================
1058
+ // Store step
1059
+ // ============================================
1060
+
1061
+ private parseStoreStep(): StoreStep {
1062
+ this.consume(ReqonTokenType.STORE, "Expected 'store'");
1063
+
1064
+ // Check for 'each' keyword
1065
+ let isEach = false;
1066
+ if (this.match(ReqonTokenType.EACH)) {
1067
+ isEach = true;
1068
+ }
1069
+
1070
+ const source = this.parseExpression();
1071
+ this.consume(TokenType.RIGHT_ARROW, "Expected '->'");
1072
+ const target = this.consumeIdentifier('Expected store name').value;
1073
+
1074
+ const options: StoreOptions = {};
1075
+
1076
+ if (this.match(TokenType.LBRACE)) {
1077
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1078
+ // Accept keyword tokens as option keys
1079
+ let key: string;
1080
+ if (this.check(ReqonTokenType.KEY)) {
1081
+ this.advance();
1082
+ key = 'key';
1083
+ } else if (this.check(ReqonTokenType.PARTIAL)) {
1084
+ this.advance();
1085
+ key = 'partial';
1086
+ } else if (this.check(ReqonTokenType.UPSERT)) {
1087
+ this.advance();
1088
+ key = 'upsert';
1089
+ } else {
1090
+ key = this.consume(TokenType.IDENTIFIER, 'Expected option key').value;
1091
+ }
1092
+ this.consume(TokenType.COLON, "Expected ':'");
1093
+
1094
+ switch (key) {
1095
+ case 'key':
1096
+ options.key = this.parseExpression();
1097
+ break;
1098
+ case 'partial':
1099
+ options.partial = this.match(TokenType.TRUE);
1100
+ if (!options.partial) {
1101
+ this.consume(TokenType.FALSE, "Expected 'true' or 'false'");
1102
+ }
1103
+ break;
1104
+ case 'upsert':
1105
+ options.upsert = this.match(TokenType.TRUE);
1106
+ if (!options.upsert) {
1107
+ this.consume(TokenType.FALSE, "Expected 'true' or 'false'");
1108
+ }
1109
+ break;
1110
+ }
1111
+
1112
+ this.match(TokenType.COMMA);
1113
+ }
1114
+ this.consume(TokenType.RBRACE, "Expected '}'");
1115
+ }
1116
+
1117
+ return { type: 'StoreStep', source, target, options };
1118
+ }
1119
+
1120
+ // ============================================
1121
+ // Match step (schema overloading)
1122
+ // ============================================
1123
+
1124
+ private parseMatchStep(): MatchStep {
1125
+ this.consume(TokenType.MATCH, "Expected 'match'");
1126
+ const target = this.parseExpression();
1127
+
1128
+ this.consume(TokenType.LBRACE, "Expected '{'");
1129
+ const arms: MatchArm[] = [];
1130
+
1131
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1132
+ arms.push(this.parseMatchArm());
1133
+ this.match(TokenType.COMMA);
1134
+ }
1135
+
1136
+ this.consume(TokenType.RBRACE, "Expected '}'");
1137
+
1138
+ return { type: 'MatchStep', target, arms };
1139
+ }
1140
+
1141
+ private parseMatchArm(): MatchArm {
1142
+ // Schema name or '_' for wildcard
1143
+ const schema = this.consume(TokenType.IDENTIFIER, 'Expected schema name or _').value;
1144
+ this.consume(TokenType.RIGHT_ARROW, "Expected '->'");
1145
+
1146
+ // After -> we have either:
1147
+ // 1. A flow directive (continue, skip, abort, retry, queue, jump)
1148
+ // 2. Steps in braces { ... }
1149
+ // 3. A single step (store, fetch, etc.)
1150
+
1151
+ // Check for flow directives
1152
+ const flow = this.tryParseFlowDirective();
1153
+ if (flow) {
1154
+ return { schema, flow };
1155
+ }
1156
+
1157
+ // Check for step block
1158
+ if (this.check(TokenType.LBRACE)) {
1159
+ this.advance();
1160
+ const steps: ActionStep[] = [];
1161
+
1162
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1163
+ steps.push(this.parseActionStep());
1164
+ this.match(TokenType.COMMA);
1165
+ }
1166
+
1167
+ this.consume(TokenType.RBRACE, "Expected '}'");
1168
+ return { schema, steps };
1169
+ }
1170
+
1171
+ // Single step
1172
+ const step = this.parseActionStep();
1173
+ return { schema, steps: [step] };
1174
+ }
1175
+
1176
+ private tryParseFlowDirective(): FlowDirective | undefined {
1177
+ if (this.match(ReqonTokenType.CONTINUE)) {
1178
+ return { type: 'continue' };
1179
+ }
1180
+
1181
+ if (this.match(ReqonTokenType.SKIP)) {
1182
+ return { type: 'skip' };
1183
+ }
1184
+
1185
+ if (this.match(ReqonTokenType.ABORT)) {
1186
+ let message: string | undefined;
1187
+ if (this.check(TokenType.STRING)) {
1188
+ message = this.advance().value;
1189
+ }
1190
+ return { type: 'abort', message };
1191
+ }
1192
+
1193
+ if (this.match(ReqonTokenType.RETRY)) {
1194
+ let backoff: RetryConfig | undefined;
1195
+ if (this.check(TokenType.LBRACE)) {
1196
+ backoff = this.parseRetryConfig();
1197
+ }
1198
+ return { type: 'retry', backoff };
1199
+ }
1200
+
1201
+ if (this.match(ReqonTokenType.QUEUE)) {
1202
+ let target: string | undefined;
1203
+ if (this.check(TokenType.IDENTIFIER)) {
1204
+ target = this.advance().value;
1205
+ }
1206
+ return { type: 'queue', target };
1207
+ }
1208
+
1209
+ if (this.match(ReqonTokenType.JUMP)) {
1210
+ const action = this.consume(TokenType.IDENTIFIER, 'Expected action name').value;
1211
+ let then: 'retry' | 'continue' | undefined;
1212
+ if (this.match(TokenType.THEN)) {
1213
+ if (this.match(ReqonTokenType.RETRY)) {
1214
+ then = 'retry';
1215
+ } else if (this.match(ReqonTokenType.CONTINUE)) {
1216
+ then = 'continue';
1217
+ } else {
1218
+ throw this.error("Expected 'retry' or 'continue' after 'then'");
1219
+ }
1220
+ }
1221
+ return { type: 'jump', action, then };
1222
+ }
1223
+
1224
+ return undefined;
1225
+ }
1226
+
1227
+ // ============================================
1228
+ // Let step (variable binding)
1229
+ // ============================================
1230
+
1231
+ private parseLetStep(): LetStep {
1232
+ this.consume(TokenType.LET, "Expected 'let'");
1233
+ const name = this.consumeIdentifier('Expected variable name').value;
1234
+ this.consume(TokenType.EQUALS, "Expected '='");
1235
+ const value = this.parseExpression();
1236
+
1237
+ return { type: 'LetStep', name, value };
1238
+ }
1239
+
1240
+ // ============================================
1241
+ // Wait step (webhook support)
1242
+ // ============================================
1243
+
1244
+ /**
1245
+ * Parse wait step: wait { timeout: 60000, path: "/webhooks/callback", ... }
1246
+ * Waits for an external webhook callback before continuing execution
1247
+ */
1248
+ private parseWaitStep(): WebhookStep {
1249
+ this.consume(ReqonTokenType.WAIT, "Expected 'wait'");
1250
+ this.consume(TokenType.LBRACE, "Expected '{'");
1251
+
1252
+ const step: WebhookStep = { type: 'WebhookStep' };
1253
+
1254
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1255
+ // Accept keyword tokens as option keys
1256
+ let key: string;
1257
+ if (this.check(ReqonTokenType.TIMEOUT)) {
1258
+ this.advance();
1259
+ key = 'timeout';
1260
+ } else if (this.check(ReqonTokenType.PATH)) {
1261
+ this.advance();
1262
+ key = 'path';
1263
+ } else if (this.check(ReqonTokenType.EXPECTED_EVENTS)) {
1264
+ this.advance();
1265
+ key = 'expectedEvents';
1266
+ } else if (this.check(ReqonTokenType.EVENT_FILTER)) {
1267
+ this.advance();
1268
+ key = 'eventFilter';
1269
+ } else if (this.check(ReqonTokenType.RETRY)) {
1270
+ this.advance();
1271
+ key = 'retry';
1272
+ } else if (this.check(ReqonTokenType.STORAGE)) {
1273
+ this.advance();
1274
+ key = 'storage';
1275
+ } else {
1276
+ key = this.consume(TokenType.IDENTIFIER, 'Expected option key').value;
1277
+ }
1278
+ this.consume(TokenType.COLON, "Expected ':'");
1279
+
1280
+ switch (key) {
1281
+ case 'timeout':
1282
+ step.timeout = parseInt(this.consume(TokenType.NUMBER, 'Expected timeout value').value, 10);
1283
+ break;
1284
+ case 'path':
1285
+ step.path = this.consume(TokenType.STRING, 'Expected path string').value;
1286
+ break;
1287
+ case 'expectedEvents':
1288
+ step.expectedEvents = parseInt(this.consume(TokenType.NUMBER, 'Expected number').value, 10);
1289
+ break;
1290
+ case 'eventFilter':
1291
+ step.eventFilter = this.parseExpression();
1292
+ break;
1293
+ case 'retry':
1294
+ step.retryOnTimeout = this.parseRetryConfig();
1295
+ break;
1296
+ case 'storage':
1297
+ step.storage = this.parseWebhookStorageConfig();
1298
+ break;
1299
+ default:
1300
+ throw this.error(`Unknown wait option: ${key}`);
1301
+ }
1302
+
1303
+ this.match(TokenType.COMMA);
1304
+ }
1305
+
1306
+ this.consume(TokenType.RBRACE, "Expected '}'");
1307
+
1308
+ return step;
1309
+ }
1310
+
1311
+ /**
1312
+ * Parse webhook storage config: { target: store_name, key: .id }
1313
+ */
1314
+ private parseWebhookStorageConfig(): WebhookStorageConfig {
1315
+ this.consume(TokenType.LBRACE, "Expected '{'");
1316
+
1317
+ let target: string | undefined;
1318
+ let key: Expression | undefined;
1319
+
1320
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1321
+ let optionKey: string;
1322
+ if (this.check(ReqonTokenType.KEY)) {
1323
+ this.advance();
1324
+ optionKey = 'key';
1325
+ } else {
1326
+ optionKey = this.consume(TokenType.IDENTIFIER, 'Expected option key').value;
1327
+ }
1328
+ this.consume(TokenType.COLON, "Expected ':'");
1329
+
1330
+ switch (optionKey) {
1331
+ case 'target':
1332
+ target = this.consume(TokenType.IDENTIFIER, 'Expected store name').value;
1333
+ break;
1334
+ case 'key':
1335
+ key = this.parseExpression();
1336
+ break;
1337
+ default:
1338
+ throw this.error(`Unknown storage option: ${optionKey}`);
1339
+ }
1340
+
1341
+ this.match(TokenType.COMMA);
1342
+ }
1343
+
1344
+ this.consume(TokenType.RBRACE, "Expected '}'");
1345
+
1346
+ if (!target) {
1347
+ throw this.error('Webhook storage must have a target store');
1348
+ }
1349
+
1350
+ return { target, key };
1351
+ }
1352
+
1353
+ // ============================================
1354
+ // Pipeline definition
1355
+ // ============================================
1356
+
1357
+ private parsePipeline(): PipelineDefinition {
1358
+ this.consume(ReqonTokenType.RUN, "Expected 'run'");
1359
+
1360
+ const stages: PipelineStage[] = [];
1361
+
1362
+ // First stage
1363
+ stages.push(this.parsePipelineStage());
1364
+
1365
+ // Subsequent stages with 'then'
1366
+ while (this.match(TokenType.THEN)) {
1367
+ stages.push(this.parsePipelineStage());
1368
+ }
1369
+
1370
+ return { type: 'PipelineDefinition', stages };
1371
+ }
1372
+
1373
+ private parsePipelineStage(): PipelineStage {
1374
+ let condition: Expression | undefined;
1375
+
1376
+ // Check for parallel stage: [Action1, Action2, ...]
1377
+ if (this.match(TokenType.LBRACKET)) {
1378
+ const actions: string[] = [];
1379
+
1380
+ // First action
1381
+ actions.push(this.consume(TokenType.IDENTIFIER, 'Expected action name').value);
1382
+
1383
+ // Additional actions separated by commas
1384
+ while (this.match(TokenType.COMMA)) {
1385
+ actions.push(this.consume(TokenType.IDENTIFIER, 'Expected action name').value);
1386
+ }
1387
+
1388
+ this.consume(TokenType.RBRACKET, "Expected ']'");
1389
+
1390
+ // Optional 'if' condition
1391
+ if (this.match(TokenType.IF)) {
1392
+ condition = this.parseExpression();
1393
+ }
1394
+
1395
+ return { actions, condition };
1396
+ }
1397
+
1398
+ // Single action (sequential)
1399
+ const action = this.consume(TokenType.IDENTIFIER, 'Expected action name').value;
1400
+
1401
+ // Optional 'if' condition
1402
+ if (this.match(TokenType.IF)) {
1403
+ condition = this.parseExpression();
1404
+ }
1405
+
1406
+ return { action, condition };
1407
+ }
1408
+
1409
+ // ============================================
1410
+ // Vague statement parsing (simplified)
1411
+ // ============================================
1412
+
1413
+ private parseSchema(): SchemaDefinition {
1414
+ this.consume(TokenType.SCHEMA, "Expected 'schema'");
1415
+ const name = this.consume(TokenType.IDENTIFIER, 'Expected schema name').value;
1416
+
1417
+ this.consume(TokenType.LBRACE, "Expected '{'");
1418
+ const fields: FieldDefinition[] = [];
1419
+
1420
+ while (!this.check(TokenType.RBRACE) && !this.isAtEnd()) {
1421
+ fields.push(this.parseFieldDefinition());
1422
+ this.match(TokenType.COMMA);
1423
+ }
1424
+
1425
+ this.consume(TokenType.RBRACE, "Expected '}'");
1426
+
1427
+ return {
1428
+ type: 'SchemaDefinition',
1429
+ name,
1430
+ fields,
1431
+ };
1432
+ }
1433
+
1434
+ private parseFieldDefinition(): FieldDefinition {
1435
+ const name = this.consumeIdentifier('Expected field name').value;
1436
+ this.consume(TokenType.COLON, "Expected ':'");
1437
+
1438
+ // Simplified field type parsing - just grab the type name for now
1439
+ // Type names are standard types (string, int, etc.) not HTTP methods
1440
+ const typeName = this.consume(TokenType.IDENTIFIER, 'Expected type').value;
1441
+
1442
+ // Handle optional/nullable type marker (?)
1443
+ this.match(TokenType.QUESTION);
1444
+
1445
+ return {
1446
+ type: 'FieldDefinition',
1447
+ name,
1448
+ fieldType: { type: 'PrimitiveType', name: typeName as 'string' | 'int' | 'decimal' | 'date' | 'boolean' },
1449
+ };
1450
+ }
1451
+
1452
+ private parseImport(): Statement {
1453
+ this.consume(TokenType.IMPORT, "Expected 'import'");
1454
+ const name = this.consume(TokenType.IDENTIFIER, 'Expected import name').value;
1455
+ this.consume(TokenType.FROM, "Expected 'from'");
1456
+ const path = this.consume(TokenType.STRING, 'Expected import path').value;
1457
+
1458
+ return { type: 'ImportStatement', name, path };
1459
+ }
1460
+
1461
+ private parseLet(): Statement {
1462
+ this.consume(TokenType.LET, "Expected 'let'");
1463
+ const name = this.consumeIdentifier('Expected variable name').value;
1464
+ this.consume(TokenType.EQUALS, "Expected '='");
1465
+ const value = this.parseExpression();
1466
+
1467
+ return { type: 'LetStatement', name, value };
1468
+ }
1469
+ }