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,1469 +0,0 @@
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
- }