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