@segmentstream/ontology 0.0.0-stage → 0.92.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 (483) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +1655 -2
  4. package/dist/action.d.ts +193 -0
  5. package/dist/action.js +41 -0
  6. package/dist/agent-chat.d.ts +44 -0
  7. package/dist/agent-chat.js +91 -0
  8. package/dist/agent-task-contract.d.ts +64 -0
  9. package/dist/agent-task-contract.js +15 -0
  10. package/dist/agent-task.d.ts +39 -0
  11. package/dist/agent-task.js +112 -0
  12. package/dist/analyze.d.ts +215 -0
  13. package/dist/analyze.js +2438 -0
  14. package/dist/app-feedback.d.ts +167 -0
  15. package/dist/app-feedback.js +176 -0
  16. package/dist/authoring-input.d.ts +3 -0
  17. package/dist/authoring-input.js +107 -0
  18. package/dist/authoring-names.d.ts +4 -0
  19. package/dist/authoring-names.js +13 -0
  20. package/dist/authoring-records.d.ts +35 -0
  21. package/dist/authoring-records.js +264 -0
  22. package/dist/authoring.d.ts +15 -0
  23. package/dist/authoring.js +331 -0
  24. package/dist/bin/check.d.ts +30 -0
  25. package/dist/bin/check.js +99 -0
  26. package/dist/bin/load.d.ts +48 -0
  27. package/dist/bin/load.js +139 -0
  28. package/dist/bin/main.d.ts +31 -0
  29. package/dist/bin/main.js +121 -0
  30. package/dist/bin/migrate.d.ts +57 -0
  31. package/dist/bin/migrate.js +170 -0
  32. package/dist/bin/output.d.ts +31 -0
  33. package/dist/bin/output.js +84 -0
  34. package/dist/bin.d.ts +2 -0
  35. package/dist/bin.js +31 -0
  36. package/dist/blob.d.ts +52 -0
  37. package/dist/blob.js +87 -0
  38. package/dist/channel-session.d.ts +16 -0
  39. package/dist/channel-session.js +16 -0
  40. package/dist/chat.d.ts +43 -0
  41. package/dist/chat.js +34 -0
  42. package/dist/confirmation.d.ts +46 -0
  43. package/dist/confirmation.js +41 -0
  44. package/dist/connection.d.ts +213 -0
  45. package/dist/connection.js +289 -0
  46. package/dist/deployment.d.ts +35 -0
  47. package/dist/deployment.js +76 -0
  48. package/dist/diagnostics.d.ts +27 -0
  49. package/dist/diagnostics.js +106 -0
  50. package/dist/emails.d.ts +70 -0
  51. package/dist/emails.js +221 -0
  52. package/dist/entity.d.ts +331 -0
  53. package/dist/entity.js +153 -0
  54. package/dist/errors.d.ts +154 -0
  55. package/dist/errors.js +109 -0
  56. package/dist/feedback-config.d.ts +24 -0
  57. package/dist/feedback-config.js +126 -0
  58. package/dist/files.d.ts +39 -0
  59. package/dist/files.js +4 -0
  60. package/dist/groups.d.ts +95 -0
  61. package/dist/groups.js +280 -0
  62. package/dist/index.d.ts +109 -0
  63. package/dist/index.js +70 -0
  64. package/dist/internal/diagnostics.js +594 -0
  65. package/dist/legacy.d.ts +160 -0
  66. package/dist/legacy.js +270 -0
  67. package/dist/manifest-compatibility.d.ts +8 -0
  68. package/dist/manifest-compatibility.js +87 -0
  69. package/dist/manifest.d.ts +3329 -0
  70. package/dist/manifest.js +757 -0
  71. package/dist/me.d.ts +46 -0
  72. package/dist/me.js +109 -0
  73. package/dist/metric-filters.d.ts +48 -0
  74. package/dist/metric-filters.js +252 -0
  75. package/dist/metric-routes.d.ts +132 -0
  76. package/dist/metric-routes.js +498 -0
  77. package/dist/metric.d.ts +172 -0
  78. package/dist/metric.js +132 -0
  79. package/dist/migrate/apply.d.ts +94 -0
  80. package/dist/migrate/apply.js +526 -0
  81. package/dist/migrate/errors.d.ts +46 -0
  82. package/dist/migrate/errors.js +38 -0
  83. package/dist/migrate/index.d.ts +10 -0
  84. package/dist/migrate/index.js +7 -0
  85. package/dist/migrate/model.d.ts +2311 -0
  86. package/dist/migrate/model.js +148 -0
  87. package/dist/migrate/plan.d.ts +51 -0
  88. package/dist/migrate/plan.js +1856 -0
  89. package/dist/migrate/preview.d.ts +13 -0
  90. package/dist/migrate/preview.js +65 -0
  91. package/dist/migrate/storage.d.ts +226 -0
  92. package/dist/migrate/storage.js +774 -0
  93. package/dist/model-metrics.d.ts +22 -0
  94. package/dist/model-metrics.js +545 -0
  95. package/dist/names.d.ts +49 -0
  96. package/dist/names.js +110 -0
  97. package/dist/navigation-artifact.d.ts +13 -0
  98. package/dist/navigation-artifact.js +11 -0
  99. package/dist/navigation-catalog.d.ts +55 -0
  100. package/dist/navigation-catalog.js +297 -0
  101. package/dist/nitro-navigation.d.ts +3 -0
  102. package/dist/nitro-navigation.js +64 -0
  103. package/dist/nitro-workflows.d.ts +108 -0
  104. package/dist/nitro-workflows.js +286 -0
  105. package/dist/nitro.d.ts +40 -0
  106. package/dist/nitro.js +50 -0
  107. package/dist/ontology.d.ts +41 -0
  108. package/dist/ontology.js +46 -0
  109. package/dist/permissions.d.ts +198 -0
  110. package/dist/permissions.js +272 -0
  111. package/dist/property.d.ts +188 -0
  112. package/dist/property.js +301 -0
  113. package/dist/query.d.ts +245 -0
  114. package/dist/query.js +615 -0
  115. package/dist/relationship.d.ts +99 -0
  116. package/dist/relationship.js +33 -0
  117. package/dist/render.d.ts +81 -0
  118. package/dist/render.js +512 -0
  119. package/dist/replication/baseline.d.ts +51 -0
  120. package/dist/replication/baseline.js +215 -0
  121. package/dist/replication/bigquery.d.ts +37 -0
  122. package/dist/replication/bigquery.js +211 -0
  123. package/dist/replication/coverage.d.ts +14 -0
  124. package/dist/replication/coverage.js +53 -0
  125. package/dist/replication/evolution.d.ts +25 -0
  126. package/dist/replication/evolution.js +184 -0
  127. package/dist/replication/identities.d.ts +6 -0
  128. package/dist/replication/identities.js +47 -0
  129. package/dist/replication/legacy-baseline.d.ts +27 -0
  130. package/dist/replication/legacy-baseline.js +109 -0
  131. package/dist/replication/legacy-store.d.ts +19 -0
  132. package/dist/replication/legacy-store.js +63 -0
  133. package/dist/replication/lineage.d.ts +36 -0
  134. package/dist/replication/lineage.js +72 -0
  135. package/dist/replication/migrate.d.ts +21 -0
  136. package/dist/replication/migrate.js +84 -0
  137. package/dist/replication/model.d.ts +52 -0
  138. package/dist/replication/model.js +99 -0
  139. package/dist/replication/scans.d.ts +34 -0
  140. package/dist/replication/scans.js +158 -0
  141. package/dist/replication/schema.d.ts +11 -0
  142. package/dist/replication/schema.js +226 -0
  143. package/dist/replication/shadow-schema.d.ts +4 -0
  144. package/dist/replication/shadow-schema.js +61 -0
  145. package/dist/replication/shadow.d.ts +127 -0
  146. package/dist/replication/shadow.js +614 -0
  147. package/dist/replication/source-replacement.d.ts +33 -0
  148. package/dist/replication/source-replacement.js +76 -0
  149. package/dist/replication/store.d.ts +36 -0
  150. package/dist/replication/store.js +382 -0
  151. package/dist/replication/transaction.d.ts +23 -0
  152. package/dist/replication/transaction.js +88 -0
  153. package/dist/role.d.ts +61 -0
  154. package/dist/role.js +76 -0
  155. package/dist/runtime/action-deadlocks.d.ts +21 -0
  156. package/dist/runtime/action-deadlocks.js +130 -0
  157. package/dist/runtime/action-transactions.d.ts +35 -0
  158. package/dist/runtime/action-transactions.js +54 -0
  159. package/dist/runtime/agent-counters.d.ts +26 -0
  160. package/dist/runtime/agent-counters.js +98 -0
  161. package/dist/runtime/agent-tasks.d.ts +63 -0
  162. package/dist/runtime/agent-tasks.js +120 -0
  163. package/dist/runtime/agents.d.ts +15 -0
  164. package/dist/runtime/agents.js +457 -0
  165. package/dist/runtime/batch-diagnostics.d.ts +22 -0
  166. package/dist/runtime/batch-diagnostics.js +89 -0
  167. package/dist/runtime/batch.d.ts +52 -0
  168. package/dist/runtime/batch.js +534 -0
  169. package/dist/runtime/channel-session-revocation.d.ts +3 -0
  170. package/dist/runtime/channel-session-revocation.js +5 -0
  171. package/dist/runtime/channel-sessions.d.ts +4 -0
  172. package/dist/runtime/channel-sessions.js +61 -0
  173. package/dist/runtime/confirmations.d.ts +29 -0
  174. package/dist/runtime/confirmations.js +57 -0
  175. package/dist/runtime/cursor.d.ts +23 -0
  176. package/dist/runtime/cursor.js +100 -0
  177. package/dist/runtime/deployment.d.ts +7 -0
  178. package/dist/runtime/deployment.js +4 -0
  179. package/dist/runtime/errors.d.ts +118 -0
  180. package/dist/runtime/errors.js +109 -0
  181. package/dist/runtime/federation-tables.d.ts +2 -0
  182. package/dist/runtime/federation-tables.js +20 -0
  183. package/dist/runtime/federation.d.ts +42 -0
  184. package/dist/runtime/federation.js +222 -0
  185. package/dist/runtime/files.d.ts +39 -0
  186. package/dist/runtime/files.js +44 -0
  187. package/dist/runtime/generated-actions.d.ts +37 -0
  188. package/dist/runtime/generated-actions.js +307 -0
  189. package/dist/runtime/history.d.ts +91 -0
  190. package/dist/runtime/history.js +77 -0
  191. package/dist/runtime/ids.d.ts +6 -0
  192. package/dist/runtime/ids.js +39 -0
  193. package/dist/runtime/member-tables.d.ts +8 -0
  194. package/dist/runtime/member-tables.js +33 -0
  195. package/dist/runtime/member-writes.d.ts +78 -0
  196. package/dist/runtime/member-writes.js +202 -0
  197. package/dist/runtime/metric-query.d.ts +19 -0
  198. package/dist/runtime/metric-query.js +411 -0
  199. package/dist/runtime/model.d.ts +67 -0
  200. package/dist/runtime/model.js +150 -0
  201. package/dist/runtime/new-user-hook.d.ts +6 -0
  202. package/dist/runtime/new-user-hook.js +37 -0
  203. package/dist/runtime/oauth.d.ts +9 -0
  204. package/dist/runtime/oauth.js +299 -0
  205. package/dist/runtime/pipeline.d.ts +155 -0
  206. package/dist/runtime/pipeline.js +597 -0
  207. package/dist/runtime/postgres-tls.d.ts +10 -0
  208. package/dist/runtime/postgres-tls.js +14 -0
  209. package/dist/runtime/principals.d.ts +302 -0
  210. package/dist/runtime/principals.js +1307 -0
  211. package/dist/runtime/reads.d.ts +55 -0
  212. package/dist/runtime/reads.js +313 -0
  213. package/dist/runtime/records.d.ts +42 -0
  214. package/dist/runtime/records.js +245 -0
  215. package/dist/runtime/resolve-agent-identity.d.ts +6 -0
  216. package/dist/runtime/resolve-agent-identity.js +181 -0
  217. package/dist/runtime/service-binding.d.ts +18 -0
  218. package/dist/runtime/service-binding.js +266 -0
  219. package/dist/runtime/sign-in-links.d.ts +68 -0
  220. package/dist/runtime/sign-in-links.js +147 -0
  221. package/dist/runtime/sql-runtime.d.ts +131 -0
  222. package/dist/runtime/sql-runtime.js +362 -0
  223. package/dist/runtime/statement.d.ts +18 -0
  224. package/dist/runtime/statement.js +31 -0
  225. package/dist/runtime/user-identities.d.ts +66 -0
  226. package/dist/runtime/user-identities.js +106 -0
  227. package/dist/runtime/user-identity-sql.d.ts +86 -0
  228. package/dist/runtime/user-identity-sql.js +297 -0
  229. package/dist/runtime/user-roles.d.ts +16 -0
  230. package/dist/runtime/user-roles.js +32 -0
  231. package/dist/runtime/validation.d.ts +16 -0
  232. package/dist/runtime/validation.js +26 -0
  233. package/dist/runtime/where.d.ts +57 -0
  234. package/dist/runtime/where.js +404 -0
  235. package/dist/runtime/workflow-admission.d.ts +49 -0
  236. package/dist/runtime/workflow-admission.js +92 -0
  237. package/dist/runtime/workflow-argument-codec.d.ts +10 -0
  238. package/dist/runtime/workflow-argument-codec.js +120 -0
  239. package/dist/runtime/workflow-arguments.d.ts +17 -0
  240. package/dist/runtime/workflow-arguments.js +99 -0
  241. package/dist/runtime/workflow-starts.d.ts +203 -0
  242. package/dist/runtime/workflow-starts.js +493 -0
  243. package/dist/runtime/workflow-users.d.ts +9 -0
  244. package/dist/runtime/workflow-users.js +17 -0
  245. package/dist/runtime/workload.d.ts +25 -0
  246. package/dist/runtime/workload.js +24 -0
  247. package/dist/runtime/writes.d.ts +108 -0
  248. package/dist/runtime/writes.js +491 -0
  249. package/dist/runtime-source.d.ts +22 -0
  250. package/dist/runtime-source.js +28 -0
  251. package/dist/runtime.d.ts +310 -0
  252. package/dist/runtime.js +31 -0
  253. package/dist/server.d.ts +23 -0
  254. package/dist/server.js +107 -0
  255. package/dist/service/agent/attachments.d.ts +33 -0
  256. package/dist/service/agent/attachments.js +228 -0
  257. package/dist/service/agent/authentication.d.ts +22 -0
  258. package/dist/service/agent/authentication.js +58 -0
  259. package/dist/service/agent/confirmations.d.ts +5 -0
  260. package/dist/service/agent/confirmations.js +73 -0
  261. package/dist/service/agent/conversation-routes.d.ts +14 -0
  262. package/dist/service/agent/conversation-routes.js +45 -0
  263. package/dist/service/agent/conversations.d.ts +40 -0
  264. package/dist/service/agent/conversations.js +69 -0
  265. package/dist/service/agent/files.d.ts +12 -0
  266. package/dist/service/agent/files.js +69 -0
  267. package/dist/service/agent/protocol.d.ts +90 -0
  268. package/dist/service/agent/protocol.js +114 -0
  269. package/dist/service/agent/server.d.ts +28 -0
  270. package/dist/service/agent/server.js +374 -0
  271. package/dist/service/agent/task-caller.d.ts +21 -0
  272. package/dist/service/agent/task-caller.js +35 -0
  273. package/dist/service/agent/task-start.d.ts +53 -0
  274. package/dist/service/agent/task-start.js +161 -0
  275. package/dist/service/agent/tasks.d.ts +40 -0
  276. package/dist/service/agent/tasks.js +155 -0
  277. package/dist/service/api.d.ts +50 -0
  278. package/dist/service/api.js +288 -0
  279. package/dist/service/authentication.d.ts +227 -0
  280. package/dist/service/authentication.js +767 -0
  281. package/dist/service/caller-context.d.ts +24 -0
  282. package/dist/service/caller-context.js +6 -0
  283. package/dist/service/catalog.d.ts +42 -0
  284. package/dist/service/catalog.js +66 -0
  285. package/dist/service/channel/provider.d.ts +10 -0
  286. package/dist/service/channel/provider.js +1 -0
  287. package/dist/service/channel/providers/telegram.d.ts +18 -0
  288. package/dist/service/channel/providers/telegram.js +108 -0
  289. package/dist/service/channel/sessions.d.ts +5 -0
  290. package/dist/service/channel/sessions.js +53 -0
  291. package/dist/service/channel/sign-in.d.ts +7 -0
  292. package/dist/service/channel/sign-in.js +78 -0
  293. package/dist/service/chat/archive.d.ts +64 -0
  294. package/dist/service/chat/archive.js +62 -0
  295. package/dist/service/chat/attribution.d.ts +26 -0
  296. package/dist/service/chat/attribution.js +28 -0
  297. package/dist/service/chat/delivery.d.ts +18 -0
  298. package/dist/service/chat/delivery.js +251 -0
  299. package/dist/service/chat/diagnostics.d.ts +2 -0
  300. package/dist/service/chat/diagnostics.js +35 -0
  301. package/dist/service/chat/envelope.d.ts +96 -0
  302. package/dist/service/chat/envelope.js +39 -0
  303. package/dist/service/chat/idempotency.d.ts +19 -0
  304. package/dist/service/chat/idempotency.js +37 -0
  305. package/dist/service/chat/providers/telegram.d.ts +36 -0
  306. package/dist/service/chat/providers/telegram.js +133 -0
  307. package/dist/service/chat/reads.d.ts +25 -0
  308. package/dist/service/chat/reads.js +75 -0
  309. package/dist/service/chat/resolve.d.ts +34 -0
  310. package/dist/service/chat/resolve.js +150 -0
  311. package/dist/service/chat/routes.d.ts +23 -0
  312. package/dist/service/chat/routes.js +75 -0
  313. package/dist/service/chat/schemas.d.ts +43 -0
  314. package/dist/service/chat/schemas.js +31 -0
  315. package/dist/service/config.d.ts +218 -0
  316. package/dist/service/config.js +265 -0
  317. package/dist/service/connection-stream.d.ts +10 -0
  318. package/dist/service/connection-stream.js +191 -0
  319. package/dist/service/connections.d.ts +60 -0
  320. package/dist/service/connections.js +271 -0
  321. package/dist/service/decisions.d.ts +35 -0
  322. package/dist/service/decisions.js +63 -0
  323. package/dist/service/descriptions.d.ts +8 -0
  324. package/dist/service/descriptions.js +20 -0
  325. package/dist/service/discovery-schemas.d.ts +92 -0
  326. package/dist/service/discovery-schemas.js +59 -0
  327. package/dist/service/discovery-search.d.ts +30 -0
  328. package/dist/service/discovery-search.js +95 -0
  329. package/dist/service/discovery.d.ts +37 -0
  330. package/dist/service/discovery.js +436 -0
  331. package/dist/service/docs.d.ts +9 -0
  332. package/dist/service/docs.js +197 -0
  333. package/dist/service/errors.d.ts +145 -0
  334. package/dist/service/errors.js +704 -0
  335. package/dist/service/federation-provider.d.ts +36 -0
  336. package/dist/service/federation-provider.js +110 -0
  337. package/dist/service/federation-server.d.ts +20 -0
  338. package/dist/service/federation-server.js +249 -0
  339. package/dist/service/federation-status.d.ts +40 -0
  340. package/dist/service/federation-status.js +151 -0
  341. package/dist/service/handlers.d.ts +18 -0
  342. package/dist/service/handlers.js +287 -0
  343. package/dist/service/mcp/confirmation.d.ts +68 -0
  344. package/dist/service/mcp/confirmation.js +178 -0
  345. package/dist/service/mcp/find-input.d.ts +12 -0
  346. package/dist/service/mcp/find-input.js +122 -0
  347. package/dist/service/mcp/input-schema.d.ts +6 -0
  348. package/dist/service/mcp/input-schema.js +126 -0
  349. package/dist/service/mcp/listing.d.ts +26 -0
  350. package/dist/service/mcp/listing.js +92 -0
  351. package/dist/service/mcp/metric-tools.d.ts +85 -0
  352. package/dist/service/mcp/metric-tools.js +258 -0
  353. package/dist/service/mcp/request-log.d.ts +5 -0
  354. package/dist/service/mcp/request-log.js +53 -0
  355. package/dist/service/mcp/runtime-policy.d.ts +27 -0
  356. package/dist/service/mcp/runtime-policy.js +62 -0
  357. package/dist/service/mcp/server.d.ts +52 -0
  358. package/dist/service/mcp/server.js +861 -0
  359. package/dist/service/mcp/tools.d.ts +99 -0
  360. package/dist/service/mcp/tools.js +938 -0
  361. package/dist/service/member-file-routes.d.ts +22 -0
  362. package/dist/service/member-file-routes.js +52 -0
  363. package/dist/service/member-files.d.ts +245 -0
  364. package/dist/service/member-files.js +258 -0
  365. package/dist/service/metric-query-platform.d.ts +77 -0
  366. package/dist/service/metric-query-platform.js +198 -0
  367. package/dist/service/metric-query-scopes.d.ts +43 -0
  368. package/dist/service/metric-query-scopes.js +147 -0
  369. package/dist/service/metric-query.d.ts +48 -0
  370. package/dist/service/metric-query.js +200 -0
  371. package/dist/service/name-suggestions.d.ts +3 -0
  372. package/dist/service/name-suggestions.js +38 -0
  373. package/dist/service/navigation-schemas.d.ts +80 -0
  374. package/dist/service/navigation-schemas.js +49 -0
  375. package/dist/service/navigation.d.ts +20 -0
  376. package/dist/service/navigation.js +165 -0
  377. package/dist/service/oauth/protocol.d.ts +70 -0
  378. package/dist/service/oauth/protocol.js +157 -0
  379. package/dist/service/oauth/refresh-replay.d.ts +2 -0
  380. package/dist/service/oauth/refresh-replay.js +20 -0
  381. package/dist/service/oauth/server.d.ts +28 -0
  382. package/dist/service/oauth/server.js +769 -0
  383. package/dist/service/operations.d.ts +170 -0
  384. package/dist/service/operations.js +392 -0
  385. package/dist/service/plan.d.ts +57 -0
  386. package/dist/service/plan.js +96 -0
  387. package/dist/service/rate-limit.d.ts +22 -0
  388. package/dist/service/rate-limit.js +52 -0
  389. package/dist/service/record-reads.d.ts +21 -0
  390. package/dist/service/record-reads.js +155 -0
  391. package/dist/service/replication.d.ts +5 -0
  392. package/dist/service/replication.js +39 -0
  393. package/dist/service/runtime-contract.d.ts +508 -0
  394. package/dist/service/runtime-contract.js +18 -0
  395. package/dist/service/runtime-identity.d.ts +71 -0
  396. package/dist/service/runtime-identity.js +122 -0
  397. package/dist/service/schemas.d.ts +961 -0
  398. package/dist/service/schemas.js +639 -0
  399. package/dist/service/service.d.ts +21 -0
  400. package/dist/service/service.js +526 -0
  401. package/dist/service/warehouse-platform.d.ts +17 -0
  402. package/dist/service/warehouse-platform.js +122 -0
  403. package/dist/service/warehouse-query.d.ts +24 -0
  404. package/dist/service/warehouse-query.js +280 -0
  405. package/dist/service/webhooks.d.ts +106 -0
  406. package/dist/service/webhooks.js +233 -0
  407. package/dist/service/workflow-admission-provider.d.ts +31 -0
  408. package/dist/service/workflow-admission-provider.js +205 -0
  409. package/dist/service/workflow-argument-serialization.d.ts +2 -0
  410. package/dist/service/workflow-argument-serialization.js +14 -0
  411. package/dist/service/workflow-callback.d.ts +22 -0
  412. package/dist/service/workflow-callback.js +75 -0
  413. package/dist/service/workflow-deployment.d.ts +8 -0
  414. package/dist/service/workflow-deployment.js +131 -0
  415. package/dist/service/workflow-diagnostics.d.ts +23 -0
  416. package/dist/service/workflow-diagnostics.js +263 -0
  417. package/dist/service/workflow-errors.d.ts +26 -0
  418. package/dist/service/workflow-errors.js +181 -0
  419. package/dist/service/workflow-logging.d.ts +2 -0
  420. package/dist/service/workflow-logging.js +50 -0
  421. package/dist/service/workflow-queue-fence.d.ts +6 -0
  422. package/dist/service/workflow-queue-fence.js +66 -0
  423. package/dist/service/workflows.d.ts +200 -0
  424. package/dist/service/workflows.js +1549 -0
  425. package/dist/sign-in.d.ts +58 -0
  426. package/dist/sign-in.js +57 -0
  427. package/dist/source.d.ts +30 -0
  428. package/dist/source.js +107 -0
  429. package/dist/start-recovery-contract.d.ts +49 -0
  430. package/dist/start-recovery-contract.js +26 -0
  431. package/dist/start-recovery.d.ts +27 -0
  432. package/dist/start-recovery.js +81 -0
  433. package/dist/storage/api.d.ts +4 -0
  434. package/dist/storage/api.js +40 -0
  435. package/dist/storage/attachments.d.ts +146 -0
  436. package/dist/storage/attachments.js +733 -0
  437. package/dist/storage/authorization.d.ts +38 -0
  438. package/dist/storage/authorization.js +83 -0
  439. package/dist/storage/file-access.d.ts +17 -0
  440. package/dist/storage/file-access.js +8 -0
  441. package/dist/storage/limits.d.ts +12 -0
  442. package/dist/storage/limits.js +17 -0
  443. package/dist/storage/maintenance-auth.d.ts +20 -0
  444. package/dist/storage/maintenance-auth.js +24 -0
  445. package/dist/storage/maintenance.d.ts +11 -0
  446. package/dist/storage/maintenance.js +67 -0
  447. package/dist/storage/neon.d.ts +4 -0
  448. package/dist/storage/neon.js +318 -0
  449. package/dist/storage/operator.d.ts +11 -0
  450. package/dist/storage/operator.js +30 -0
  451. package/dist/storage/provider.d.ts +93 -0
  452. package/dist/storage/provider.js +36 -0
  453. package/dist/storage/sessions.d.ts +184 -0
  454. package/dist/storage/sessions.js +688 -0
  455. package/dist/storage/tables.d.ts +54 -0
  456. package/dist/storage/tables.js +205 -0
  457. package/dist/storage/transfers.d.ts +16 -0
  458. package/dist/storage/transfers.js +153 -0
  459. package/dist/storage/writes.d.ts +7 -0
  460. package/dist/storage/writes.js +88 -0
  461. package/dist/telegram.d.ts +35 -0
  462. package/dist/telegram.js +173 -0
  463. package/dist/user-identity.d.ts +28 -0
  464. package/dist/user-identity.js +106 -0
  465. package/dist/user.d.ts +75 -0
  466. package/dist/user.js +111 -0
  467. package/dist/warehouse-backed.d.ts +6 -0
  468. package/dist/warehouse-backed.js +495 -0
  469. package/dist/webhook-token.d.ts +11 -0
  470. package/dist/webhook-token.js +18 -0
  471. package/dist/webhooks.d.ts +40 -0
  472. package/dist/webhooks.js +55 -0
  473. package/dist/wire.d.ts +10 -0
  474. package/dist/wire.js +35 -0
  475. package/dist/workflow-runtime.d.ts +116 -0
  476. package/dist/workflow-runtime.js +109 -0
  477. package/dist/workflow-topics.d.ts +28 -0
  478. package/dist/workflow-topics.js +28 -0
  479. package/dist/workflow.d.ts +284 -0
  480. package/dist/workflow.js +259 -0
  481. package/dist/workflows.d.ts +24 -0
  482. package/dist/workflows.js +18 -0
  483. package/package.json +127 -4
@@ -0,0 +1,16 @@
1
+ import { Schema } from "effect";
2
+ import type { ValidationIssue } from "./errors.js";
3
+ /** The issues of a schema failure, flattened to `{ path, message }`. */
4
+ export declare function schemaIssues(error: Schema.SchemaError): ReadonlyArray<ValidationIssue>;
5
+ export type Validated<A> = {
6
+ readonly ok: true;
7
+ readonly value: A;
8
+ } | {
9
+ readonly ok: false;
10
+ readonly issues: ReadonlyArray<ValidationIssue>;
11
+ };
12
+ /**
13
+ * Decodes an input, reporting every issue and rejecting unknown keys. The schemas validated here
14
+ * need no services; a schema that does is a defect in the definition.
15
+ */
16
+ export declare function validate<A>(schema: Schema.Top, input: unknown): Validated<A>;
@@ -0,0 +1,26 @@
1
+ import { Result, Schema, SchemaIssue } from "effect";
2
+ const formatter = SchemaIssue.makeFormatterStandardSchemaV1();
3
+ function pathSegment(segment) {
4
+ const key = typeof segment === "object" ? segment.key : segment;
5
+ return typeof key === "number" ? key : String(key);
6
+ }
7
+ /** The issues of a schema failure, flattened to `{ path, message }`. */
8
+ export function schemaIssues(error) {
9
+ return formatter(error.issue).issues.map((issue) => ({
10
+ path: (issue.path ?? []).map(pathSegment),
11
+ message: issue.message,
12
+ }));
13
+ }
14
+ /**
15
+ * Decodes an input, reporting every issue and rejecting unknown keys. The schemas validated here
16
+ * need no services; a schema that does is a defect in the definition.
17
+ */
18
+ export function validate(schema, input) {
19
+ const result = Schema.decodeUnknownResult(schema)(input, {
20
+ errors: "all",
21
+ onExcessProperty: "error",
22
+ });
23
+ return Result.isSuccess(result)
24
+ ? { ok: true, value: result.success }
25
+ : { ok: false, issues: schemaIssues(result.failure) };
26
+ }
@@ -0,0 +1,57 @@
1
+ import { type PermissionHolder, type ScopeWhere } from "../permissions.js";
2
+ import { type FieldFilter, type Where } from "../query.js";
3
+ import { type EntityModel, type FieldModel, type OntologyModel } from "./model.js";
4
+ import { Aliases, Params } from "./statement.js";
5
+ /** Whose scoped permissions a statement honours: the principal's user id and its grants. */
6
+ export interface ScopeReader extends PermissionHolder {
7
+ /** The id of the principal's `user` record: `me` in a scope. */
8
+ readonly id: string;
9
+ }
10
+ /** A scope and the principal whose `me` it means. */
11
+ export interface RowScope {
12
+ readonly reader: ScopeReader;
13
+ readonly where: ScopeWhere;
14
+ }
15
+ /**
16
+ * Compiles a `where` that the entity's query schema accepted into a SQL condition on the table
17
+ * aliased `alias`. Every value is a parameter cast to its column's type.
18
+ */
19
+ export interface WhereContext {
20
+ readonly model: OntologyModel;
21
+ readonly params: Params;
22
+ readonly aliases: Aliases;
23
+ /**
24
+ * The caller of a scoped read. A relationship filter then also requires the related records to
25
+ * be inside the caller's read scope of their entity, so that a filter cannot probe hidden rows.
26
+ * Absent for reads with the action's authority, and for callers that hold no scoped permission.
27
+ */
28
+ readonly reader?: ScopeReader;
29
+ }
30
+ export declare function compileWhere(context: WhereContext, entity: EntityModel, alias: string, where: Where | undefined): string;
31
+ /**
32
+ * Compiles the `where` of a scoped permission on the table aliased `alias`, with `me` as the
33
+ * reader's user id and a path as the set of ids it reaches. A scope is compiled with the platform's
34
+ * authority: its own relationship filters and paths read every row. Anything `check` would have
35
+ * refused (an unknown field, operator or hop, an operand of the wrong type, `me` where a set is
36
+ * expected, or the reverse) matches nothing, and so does a scope the compiler fails on for any
37
+ * other reason: a scope never widens and never fails the statement.
38
+ */
39
+ export declare function compileScope(context: WhereContext, entity: EntityModel, alias: string, scope: RowScope): string;
40
+ /**
41
+ * Whether a scope is a valid `where` of its entity, as {@link compileScope} reads it: `false` for
42
+ * anything that would compile to FALSE as a whole, such as `me` on a field that is not a key or an
43
+ * operand of the wrong type. A scope that leaves the service, such as a metric query's row scope, is
44
+ * checked here first, so that it never means more there than it does to the service's own reads.
45
+ */
46
+ export declare function isWellFormedScope(model: OntologyModel, entity: EntityModel, scope: RowScope): boolean;
47
+ /**
48
+ * The reader's read scope of `entity` as a condition on `alias`, or `undefined` when it reads every
49
+ * record of it.
50
+ */
51
+ export declare function readCondition(context: WhereContext, entity: EntityModel, alias: string): string | undefined;
52
+ /** The reader's read scope of `entity`, or `undefined` without a reader or a scope on it. */
53
+ export declare function readScopeOf(reader: ScopeReader | undefined, entity: EntityModel): RowScope | undefined;
54
+ /** A bare value is `eq`, `null` is `isNull`. JSON values are filters only when every key is one. */
55
+ export declare function fieldFilter(field: FieldModel, condition: unknown): FieldFilter;
56
+ /** The conditions of one field filter, joined with AND. */
57
+ export declare function fieldCondition(params: Params, column: string, field: FieldModel, condition: unknown): string;
@@ -0,0 +1,404 @@
1
+ import { MAX_ME_HOPS, mePathOf } from "../me.js";
2
+ import { readScope } from "../permissions.js";
3
+ import { FILTER_OPERATORS, isFieldFilterOf, MANY_QUANTIFIERS, } from "../query.js";
4
+ import { quoteIdentifier } from "../migrate/storage.js";
5
+ import { User } from "../user.js";
6
+ import { entityModel, } from "./model.js";
7
+ import { bindValue, isRecordId } from "./records.js";
8
+ import { Aliases, columnOf, escapeLike, Params } from "./statement.js";
9
+ import { userHoldsRoleCondition } from "./user-roles.js";
10
+ /** The wire names of filter operators, as scopes are written in the manifest. */
11
+ const WIRE_OPERATORS = {
12
+ is_null: "isNull",
13
+ starts_with: "startsWith",
14
+ has_any: "hasAny",
15
+ };
16
+ const OPERATORS = new Set(FILTER_OPERATORS);
17
+ const QUANTIFIERS = new Set(MANY_QUANTIFIERS);
18
+ function isPlainObject(value) {
19
+ return typeof value === "object" && value !== null && !Array.isArray(value);
20
+ }
21
+ function and(parts) {
22
+ return parts.length === 0 ? "TRUE" : parts.map((part) => `(${part})`).join(" AND ");
23
+ }
24
+ function or(parts) {
25
+ return parts.length === 0 ? "FALSE" : parts.map((part) => `(${part})`).join(" OR ");
26
+ }
27
+ export function compileWhere(context, entity, alias, where) {
28
+ return compile(context, entity, alias, where, false);
29
+ }
30
+ /**
31
+ * Compiles the `where` of a scoped permission on the table aliased `alias`, with `me` as the
32
+ * reader's user id and a path as the set of ids it reaches. A scope is compiled with the platform's
33
+ * authority: its own relationship filters and paths read every row. Anything `check` would have
34
+ * refused (an unknown field, operator or hop, an operand of the wrong type, `me` where a set is
35
+ * expected, or the reverse) matches nothing, and so does a scope the compiler fails on for any
36
+ * other reason: a scope never widens and never fails the statement.
37
+ */
38
+ export function compileScope(context, entity, alias, scope) {
39
+ const bound = context.params.values.length;
40
+ try {
41
+ return compile({ ...context, reader: scope.reader }, entity, alias, scope.where, true);
42
+ }
43
+ catch {
44
+ // The whole scope matches nothing, whatever `not` would have made of its malformed part.
45
+ context.params.values.length = bound;
46
+ return "FALSE";
47
+ }
48
+ }
49
+ /**
50
+ * Whether a scope is a valid `where` of its entity, as {@link compileScope} reads it: `false` for
51
+ * anything that would compile to FALSE as a whole, such as `me` on a field that is not a key or an
52
+ * operand of the wrong type. A scope that leaves the service, such as a metric query's row scope, is
53
+ * checked here first, so that it never means more there than it does to the service's own reads.
54
+ */
55
+ export function isWellFormedScope(model, entity, scope) {
56
+ try {
57
+ compile({ model, params: new Params(), aliases: new Aliases(), reader: scope.reader }, entity, "t", scope.where, true);
58
+ return true;
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ }
64
+ /** A scope `check` would have refused: it compiles to FALSE as a whole. */
65
+ class MalformedScope extends Error {
66
+ }
67
+ function malformed() {
68
+ throw new MalformedScope("The scope is not a valid where of its entity.");
69
+ }
70
+ /**
71
+ * The reader's read scope of `entity` as a condition on `alias`, or `undefined` when it reads every
72
+ * record of it.
73
+ */
74
+ export function readCondition(context, entity, alias) {
75
+ const scope = readScopeOf(context.reader, entity);
76
+ return scope === undefined ? undefined : compileScope(context, entity, alias, scope);
77
+ }
78
+ /** The reader's read scope of `entity`, or `undefined` without a reader or a scope on it. */
79
+ export function readScopeOf(reader, entity) {
80
+ const where = reader === undefined ? undefined : readScope(entity.name, reader);
81
+ return where === undefined || reader === undefined ? undefined : { reader, where };
82
+ }
83
+ function compile(context, entity, alias, where, inScope) {
84
+ if (where === undefined) {
85
+ return inScope ? malformed() : "TRUE";
86
+ }
87
+ // In a scope, an empty where would match every record while counting as scoped.
88
+ if (inScope &&
89
+ (!isPlainObject(where) || mePathOf(where) !== undefined || Object.keys(where).length === 0)) {
90
+ return malformed();
91
+ }
92
+ const parts = [];
93
+ for (const [key, condition] of Object.entries(where)) {
94
+ if (condition === undefined) {
95
+ if (inScope) {
96
+ return malformed();
97
+ }
98
+ continue;
99
+ }
100
+ if ((key === "and" || key === "or") &&
101
+ inScope &&
102
+ (!Array.isArray(condition) || (key === "and" && condition.length === 0))) {
103
+ parts.push(malformed());
104
+ }
105
+ else if (key === "and") {
106
+ parts.push(and(subWheres(condition).map((sub) => compile(context, entity, alias, sub, inScope))));
107
+ }
108
+ else if (key === "or") {
109
+ parts.push(or(subWheres(condition).map((sub) => compile(context, entity, alias, sub, inScope))));
110
+ }
111
+ else if (key === "not") {
112
+ // IS NOT TRUE, so that a condition on an empty field counts as not matching.
113
+ parts.push(`(${compile(context, entity, alias, condition, inScope)}) IS NOT TRUE`);
114
+ }
115
+ else {
116
+ parts.push(memberCondition(context, entity, alias, key, condition, inScope));
117
+ }
118
+ }
119
+ return and(parts);
120
+ }
121
+ function subWheres(condition) {
122
+ return condition;
123
+ }
124
+ function memberCondition(context, entity, alias, key, condition, inScope) {
125
+ const field = entity.fieldsByName.get(key);
126
+ if (field !== undefined) {
127
+ return inScope
128
+ ? scopeFieldCondition(context, columnOf(alias, field.column), field, condition)
129
+ : fieldCondition(context.params, columnOf(alias, field.column), field, condition);
130
+ }
131
+ const link = entity.links.get(key);
132
+ if (link === undefined) {
133
+ if (inScope) {
134
+ return malformed();
135
+ }
136
+ throw new Error(`${entity.name}.${key} is neither a field nor a relationship.`);
137
+ }
138
+ if (inScope && (mePathOf(condition) !== undefined || isOperators(condition))) {
139
+ // A scope compares a to-one relationship by its key: `{ division: { in: me.… } }`.
140
+ const keyField = entity.fieldsByName.get(`${key}_id`);
141
+ return link.via === "key" && keyField !== undefined
142
+ ? scopeFieldCondition(context, columnOf(alias, keyField.column), keyField, condition)
143
+ : malformed();
144
+ }
145
+ if (inScope && !isPlainObject(condition)) {
146
+ return malformed();
147
+ }
148
+ return linkCondition(context, alias, link, condition, inScope);
149
+ }
150
+ /** Whether a condition is an object of filter operators, by their query or wire names. */
151
+ function isOperators(condition) {
152
+ if (!isPlainObject(condition)) {
153
+ return false;
154
+ }
155
+ const keys = Object.keys(condition);
156
+ return (keys.length > 0 && keys.every((key) => OPERATORS.has(key) || Object.hasOwn(WIRE_OPERATORS, key)));
157
+ }
158
+ /** Whether `me` or a path appears anywhere in a value. */
159
+ function holdsMe(value) {
160
+ if (mePathOf(value) !== undefined) {
161
+ return true;
162
+ }
163
+ if (Array.isArray(value)) {
164
+ return value.some(holdsMe);
165
+ }
166
+ return isPlainObject(value) && Object.values(value).some(holdsMe);
167
+ }
168
+ /**
169
+ * A field condition of a scope: as in a query, with wire operator names, plus `me` compared with
170
+ * `eq` or `ne` (or bare) and a path compared with `in`. A marker anywhere else, an operator the
171
+ * field does not take and an operand of the wrong type are malformed: the field's query filter
172
+ * schema validates the conditions without a marker before they compile.
173
+ */
174
+ function scopeFieldCondition(context, column, field, condition) {
175
+ const bare = mePathOf(condition);
176
+ if (bare !== undefined) {
177
+ return meCondition(context, column, field, "eq", bare);
178
+ }
179
+ if (condition === undefined ||
180
+ (isPlainObject(condition) && Object.keys(condition).length === 0)) {
181
+ return malformed();
182
+ }
183
+ const renamed = isPlainObject(condition)
184
+ ? Object.fromEntries(Object.entries(condition).map(([key, value]) => [
185
+ Object.hasOwn(WIRE_OPERATORS, key) ? WIRE_OPERATORS[key] : key,
186
+ value,
187
+ ]))
188
+ : condition;
189
+ const plain = {};
190
+ const parts = [];
191
+ for (const [operator, operand] of Object.entries(fieldFilter(field, renamed))) {
192
+ const hops = mePathOf(operand);
193
+ if (hops !== undefined) {
194
+ parts.push(meCondition(context, column, field, operator, hops));
195
+ }
196
+ else if (holdsMe(operand) || operand === undefined) {
197
+ parts.push(malformed());
198
+ }
199
+ else {
200
+ plain[operator] = operand;
201
+ }
202
+ }
203
+ if (Object.keys(plain).length > 0) {
204
+ if (!isFieldFilterOf(field, plain)) {
205
+ return malformed();
206
+ }
207
+ parts.unshift(fieldCondition(context.params, column, field, plain));
208
+ }
209
+ return and(parts);
210
+ }
211
+ /**
212
+ * `me` compared with a key column (`eq`, `ne`), or a path's set of ids (`in`). The reader's id is
213
+ * one parameter; a path is a chain of `IN (SELECT …)` subqueries walking the relationships from it.
214
+ */
215
+ function meCondition(context, column, field, operator, hops) {
216
+ const reader = context.reader;
217
+ if (field.storage !== "uuid" || reader === undefined || !isRecordId(reader.id)) {
218
+ return malformed();
219
+ }
220
+ if (hops.length === 0) {
221
+ if (operator === "eq") {
222
+ return `${column} = ${context.params.add(reader.id.toLowerCase(), "uuid")}`;
223
+ }
224
+ return operator === "ne"
225
+ ? `${column} IS DISTINCT FROM ${context.params.add(reader.id.toLowerCase(), "uuid")}`
226
+ : malformed();
227
+ }
228
+ if (operator !== "in" || hops.length > MAX_ME_HOPS) {
229
+ return malformed();
230
+ }
231
+ const ids = mePath(context, reader.id.toLowerCase(), hops);
232
+ return ids === undefined ? malformed() : `${column} IN (${ids})`;
233
+ }
234
+ /**
235
+ * The ids a path of relationship names reaches from the reader's `user` record, as a subquery: each
236
+ * hop selects the next entity's ids from the previous hop's. `undefined` when a hop is not a
237
+ * relationship of the entity it starts from.
238
+ */
239
+ function mePath(context, readerId, hops) {
240
+ // Resolve every hop before binding anything: an unused parameter would fail the statement.
241
+ const steps = [];
242
+ let entity = context.model.entities.get(User.name);
243
+ for (const hop of hops) {
244
+ const link = entity?.links.get(hop);
245
+ const target = link === undefined ? undefined : context.model.entities.get(link.target);
246
+ if (entity === undefined || link === undefined || target === undefined) {
247
+ return undefined;
248
+ }
249
+ steps.push({ from: entity, link, to: target });
250
+ entity = target;
251
+ }
252
+ let ids = context.params.add(readerId, "uuid");
253
+ for (const { from, link, to } of steps) {
254
+ const alias = context.aliases.take("m");
255
+ const as = quoteIdentifier(alias);
256
+ if (link.via === "key") {
257
+ ids =
258
+ `SELECT ${columnOf(alias, link.column)} FROM ${quoteIdentifier(from.table)} AS ${as} ` +
259
+ `WHERE ${columnOf(alias, "id")} IN (${ids})`;
260
+ }
261
+ else if (link.via === "inverse-key") {
262
+ ids =
263
+ `SELECT ${columnOf(alias, "id")} FROM ${quoteIdentifier(to.table)} AS ${as} ` +
264
+ `WHERE ${columnOf(alias, link.column)} IN (${ids})`;
265
+ }
266
+ else {
267
+ ids =
268
+ `SELECT ${columnOf(alias, link.otherColumn)} FROM ${quoteIdentifier(link.table)} AS ${as} ` +
269
+ `WHERE ${columnOf(alias, link.selfColumn)} IN (${ids})`;
270
+ }
271
+ }
272
+ return ids;
273
+ }
274
+ /** A bare value is `eq`, `null` is `isNull`. JSON values are filters only when every key is one. */
275
+ export function fieldFilter(field, condition) {
276
+ if (condition === null) {
277
+ return { isNull: true };
278
+ }
279
+ const isFilter = isPlainObject(condition) &&
280
+ (field.storage !== "json" || Object.keys(condition).every((key) => OPERATORS.has(key)));
281
+ return isFilter ? condition : { eq: condition };
282
+ }
283
+ /**
284
+ * The conditions of a list filter, joined with AND. The only list, the user's `roles`, is an
285
+ * `EXISTS` on the role assignments of the row whose id `column` holds.
286
+ */
287
+ function listCondition(params, column, filter) {
288
+ const bind = (value) => params.add(value, "text");
289
+ const parts = [];
290
+ if (filter.has !== undefined) {
291
+ parts.push(userHoldsRoleCondition(column, [bind(filter.has)]));
292
+ }
293
+ if (filter.hasAny !== undefined) {
294
+ parts.push(userHoldsRoleCondition(column, filter.hasAny.map(bind)));
295
+ }
296
+ return and(parts);
297
+ }
298
+ /** The conditions of one field filter, joined with AND. */
299
+ export function fieldCondition(params, column, field, condition) {
300
+ const filter = fieldFilter(field, condition);
301
+ if (field.storage === "list") {
302
+ return listCondition(params, column, filter);
303
+ }
304
+ const bind = (value) => params.add(bindValue(field, value), field.sqlType);
305
+ const parts = [];
306
+ for (const [operator, operand] of Object.entries(filter)) {
307
+ if (operand === undefined) {
308
+ continue;
309
+ }
310
+ switch (operator) {
311
+ case "eq":
312
+ parts.push(`${column} = ${bind(operand)}`);
313
+ break;
314
+ case "ne":
315
+ parts.push(`${column} IS DISTINCT FROM ${bind(operand)}`);
316
+ break;
317
+ case "in": {
318
+ const values = operand;
319
+ parts.push(values.length === 0 ? "FALSE" : `${column} IN (${values.map(bind).join(", ")})`);
320
+ break;
321
+ }
322
+ case "isNull":
323
+ parts.push(operand === true ? `${column} IS NULL` : `${column} IS NOT NULL`);
324
+ break;
325
+ case "contains":
326
+ parts.push(`${column} ILIKE ${params.add(`%${escapeLike(operand)}%`, "text")} ESCAPE '\\'`);
327
+ break;
328
+ case "startsWith":
329
+ parts.push(`${column} ILIKE ${params.add(`${escapeLike(operand)}%`, "text")} ESCAPE '\\'`);
330
+ break;
331
+ case "gt":
332
+ parts.push(`${column} > ${bind(operand)}`);
333
+ break;
334
+ case "gte":
335
+ parts.push(`${column} >= ${bind(operand)}`);
336
+ break;
337
+ case "lt":
338
+ parts.push(`${column} < ${bind(operand)}`);
339
+ break;
340
+ case "lte":
341
+ parts.push(`${column} <= ${bind(operand)}`);
342
+ break;
343
+ case "between": {
344
+ const [low, high] = operand;
345
+ parts.push(`${column} BETWEEN ${bind(low)} AND ${bind(high)}`);
346
+ break;
347
+ }
348
+ default:
349
+ throw new Error(`Unknown filter operator ${operator}.`);
350
+ }
351
+ }
352
+ return and(parts);
353
+ }
354
+ function linkCondition(context, alias, link, condition, inScope) {
355
+ const target = entityModel(context.model, link.target);
356
+ // The caller's own filter sees only the related records the caller may read; a scope's does not.
357
+ const visible = (targetAlias, sub) => {
358
+ const scope = inScope ? undefined : readCondition(context, target, targetAlias);
359
+ return scope === undefined ? sub : `(${sub}) AND (${scope})`;
360
+ };
361
+ if (link.via === "key") {
362
+ const targetAlias = context.aliases.take();
363
+ const sub = compile(context, target, targetAlias, condition, inScope);
364
+ return (`EXISTS (SELECT 1 FROM ${quoteIdentifier(target.table)} AS ${quoteIdentifier(targetAlias)} ` +
365
+ `WHERE ${columnOf(targetAlias, "id")} = ${columnOf(alias, link.column)} AND (${visible(targetAlias, sub)}))`);
366
+ }
367
+ const filter = condition;
368
+ if (inScope &&
369
+ (Object.keys(filter).length === 0 ||
370
+ Object.entries(filter).some(([key, value]) => !QUANTIFIERS.has(key) || value === undefined))) {
371
+ return malformed();
372
+ }
373
+ const parts = [];
374
+ const related = (where, negate) => {
375
+ const targetAlias = context.aliases.take();
376
+ // In a scope, `some: {}` and `none: {}` ask whether any related record exists; `every: {}`,
377
+ // which every record meets, is malformed as any other empty where.
378
+ const anyRecord = inScope && !negate && isPlainObject(where) && Object.keys(where).length === 0;
379
+ const sub = anyRecord ? "TRUE" : compile(context, target, targetAlias, where, inScope);
380
+ return relatedRows(context, alias, link, target, targetAlias, visible(targetAlias, negate ? `(${sub}) IS NOT TRUE` : sub));
381
+ };
382
+ if (filter.some !== undefined) {
383
+ parts.push(`EXISTS (${related(filter.some, false)})`);
384
+ }
385
+ if (filter.none !== undefined) {
386
+ parts.push(`NOT EXISTS (${related(filter.none, false)})`);
387
+ }
388
+ if (filter.every !== undefined) {
389
+ parts.push(`NOT EXISTS (${related(filter.every, true)})`);
390
+ }
391
+ return and(parts);
392
+ }
393
+ /** `SELECT 1` from the records related to the row aliased `alias` that meet `condition`. */
394
+ function relatedRows(context, alias, link, target, targetAlias, condition) {
395
+ const targetTable = `${quoteIdentifier(target.table)} AS ${quoteIdentifier(targetAlias)}`;
396
+ if (link.via === "inverse-key") {
397
+ return (`SELECT 1 FROM ${targetTable} ` +
398
+ `WHERE ${columnOf(targetAlias, link.column)} = ${columnOf(alias, "id")} AND (${condition})`);
399
+ }
400
+ const joinAlias = context.aliases.take("j");
401
+ return (`SELECT 1 FROM ${quoteIdentifier(link.table)} AS ${quoteIdentifier(joinAlias)} ` +
402
+ `JOIN ${targetTable} ON ${columnOf(targetAlias, "id")} = ${columnOf(joinAlias, link.otherColumn)} ` +
403
+ `WHERE ${columnOf(joinAlias, link.selfColumn)} = ${columnOf(alias, "id")} AND (${condition})`);
404
+ }
@@ -0,0 +1,49 @@
1
+ import { Effect } from "effect";
2
+ import type { SqlClient } from "effect/unstable/sql";
3
+ import { DeploymentInterrupted } from "../errors.js";
4
+ import { type OntologyManifest } from "../manifest.js";
5
+ import type { Ontology } from "../ontology.js";
6
+ import { WorkflowRecoveryUnavailable } from "./errors.js";
7
+ export interface WorkflowReservation {
8
+ readonly admissionId?: string;
9
+ readonly runId: string;
10
+ readonly deploymentId: string;
11
+ readonly namespace: string;
12
+ readonly region?: string;
13
+ }
14
+ export interface WorkflowAdmissionKey {
15
+ readonly trigger: string;
16
+ readonly actionId: string;
17
+ readonly recordId: string | null;
18
+ }
19
+ export interface AdmittedWorkflowStart extends WorkflowAdmissionKey {
20
+ readonly commitBy?: number;
21
+ readonly workflow: string;
22
+ readonly workflowId: string;
23
+ readonly input: unknown;
24
+ readonly arguments: ReadonlyArray<unknown>;
25
+ readonly attributes: Readonly<Record<string, string>>;
26
+ readonly reservation: WorkflowReservation;
27
+ }
28
+ /** A short transaction reserves immutable submission input/routing before any provider I/O. */
29
+ export declare function reserveWorkflowStart(sql: SqlClient.SqlClient, ontology: Ontology, proposed: AdmittedWorkflowStart): Effect.Effect<{
30
+ reservation: WorkflowReservation;
31
+ arguments: unknown[];
32
+ workflowId: string;
33
+ attributes: Readonly<Record<string, string>>;
34
+ commitBy?: number;
35
+ workflow: string;
36
+ input: unknown;
37
+ trigger: string;
38
+ actionId: string;
39
+ recordId: string | null;
40
+ }, DeploymentInterrupted | import("effect/unstable/sql/SqlError").SqlError | WorkflowRecoveryUnavailable, never>;
41
+ /** Acceptance is journaled after the provider call, in its own short transaction. */
42
+ export declare function recordWorkflowSubmission(sql: SqlClient.SqlClient, start: AdmittedWorkflowStart): import("effect/unstable/sql/Statement").Statement<object>;
43
+ /**
44
+ * Ontology SDKs 0.86.0 to 0.88.0 refuse every workflow start and step unless `_workflow_admission`
45
+ * holds one row in the `open` phase. Later SDKs do not read it. The migration that publishes a
46
+ * catalog keeps the row open, so a workspace still deployed on those SDKs keeps running and one
47
+ * left closed by their deploy guard opens again.
48
+ */
49
+ export declare function recordWorkflowCatalog(sql: SqlClient.SqlClient, manifest: OntologyManifest): import("effect/unstable/sql/Statement").Statement<object>;
@@ -0,0 +1,92 @@
1
+ import { Effect } from "effect";
2
+ import { randomUUID } from "node:crypto";
3
+ import { DeploymentInterrupted } from "../errors.js";
4
+ import { canonicalJson } from "../manifest.js";
5
+ import { WorkflowRecoveryUnavailable } from "./errors.js";
6
+ import { decodeWorkflowArguments, encodeWorkflowArguments } from "./workflow-arguments.js";
7
+ /** A short transaction reserves immutable submission input/routing before any provider I/O. */
8
+ export function reserveWorkflowStart(sql, ontology, proposed) {
9
+ return sql.withTransaction(Effect.gen(function* () {
10
+ const checkDeadline = Effect.gen(function* () {
11
+ if (proposed.commitBy !== undefined &&
12
+ (!Number.isFinite(proposed.commitBy) || Date.now() >= proposed.commitBy)) {
13
+ return yield* new WorkflowRecoveryUnavailable({
14
+ message: "Workflow recovery coverage expired before admission committed.",
15
+ });
16
+ }
17
+ });
18
+ yield* checkDeadline;
19
+ if (proposed.commitBy !== undefined) {
20
+ yield* sql.unsafe("SELECT set_config('transaction_timeout',$1,true)", [
21
+ String(Math.max(1, Math.floor(proposed.commitBy - Date.now()))),
22
+ ]);
23
+ }
24
+ yield* sql.unsafe(`INSERT INTO _workflow_starts (trigger,action_id,record_id,workflow,input)
25
+ VALUES ($1,$2::uuid,$3::uuid,$4,$5::jsonb)
26
+ ON CONFLICT DO NOTHING`, [
27
+ proposed.trigger,
28
+ proposed.actionId,
29
+ proposed.recordId,
30
+ proposed.workflow,
31
+ canonicalJson(proposed.input),
32
+ ]);
33
+ const [row] = yield* sql.unsafe(`SELECT workflow,input,reservation,arguments,provider_workflow_id,admission_attributes FROM _workflow_starts
34
+ WHERE trigger=$1 AND action_id=$2::uuid AND record_id IS NOT DISTINCT FROM $3::uuid FOR UPDATE`, [proposed.trigger, proposed.actionId, proposed.recordId]);
35
+ if (!row ||
36
+ row.workflow !== proposed.workflow ||
37
+ canonicalJson(row.input) !== canonicalJson(proposed.input)) {
38
+ return yield* new DeploymentInterrupted({
39
+ message: "The workflow admission identity was reused with different immutable input.",
40
+ servedHash: ontology.manifest.hash,
41
+ });
42
+ }
43
+ if (row.reservation && row.arguments && row.provider_workflow_id) {
44
+ yield* checkDeadline;
45
+ return {
46
+ ...proposed,
47
+ reservation: row.reservation,
48
+ arguments: decodeWorkflowArguments(row.arguments),
49
+ workflowId: row.provider_workflow_id,
50
+ attributes: row.admission_attributes ?? {},
51
+ };
52
+ }
53
+ const encodedArguments = encodeWorkflowArguments(proposed.arguments);
54
+ const admitted = {
55
+ ...proposed,
56
+ arguments: decodeWorkflowArguments(encodedArguments),
57
+ reservation: { ...proposed.reservation, admissionId: randomUUID() },
58
+ };
59
+ yield* sql.unsafe(`UPDATE _workflow_starts SET reservation=$4::jsonb, arguments=$5::jsonb,
60
+ provider_workflow_id=$6,admission_attributes=$7::jsonb
61
+ WHERE trigger=$1 AND action_id=$2::uuid AND record_id IS NOT DISTINCT FROM $3::uuid`, [
62
+ proposed.trigger,
63
+ proposed.actionId,
64
+ proposed.recordId,
65
+ canonicalJson(admitted.reservation),
66
+ canonicalJson(encodedArguments),
67
+ proposed.workflowId,
68
+ canonicalJson(proposed.attributes),
69
+ ]);
70
+ yield* checkDeadline;
71
+ return admitted;
72
+ }));
73
+ }
74
+ /** Acceptance is journaled after the provider call, in its own short transaction. */
75
+ export function recordWorkflowSubmission(sql, start) {
76
+ return sql.unsafe(`UPDATE _workflow_starts SET run_id=$4,started_at=COALESCE(started_at,now())
77
+ WHERE trigger=$1 AND action_id=$2::uuid AND record_id IS NOT DISTINCT FROM $3::uuid
78
+ AND reservation->>'runId'=$4`, [start.trigger, start.actionId, start.recordId, start.reservation.runId]);
79
+ }
80
+ // @legacy ontology.workflow-cutover-artifacts
81
+ /**
82
+ * Ontology SDKs 0.86.0 to 0.88.0 refuse every workflow start and step unless `_workflow_admission`
83
+ * holds one row in the `open` phase. Later SDKs do not read it. The migration that publishes a
84
+ * catalog keeps the row open, so a workspace still deployed on those SDKs keeps running and one
85
+ * left closed by their deploy guard opens again.
86
+ */
87
+ export function recordWorkflowCatalog(sql, manifest) {
88
+ return sql.unsafe(`INSERT INTO _workflow_admission(id,contract_hash,catalog_hash)
89
+ VALUES(true,$1,$1) ON CONFLICT(id) DO UPDATE SET catalog_hash=$1,contract_hash=$1,
90
+ phase='open',owner=NULL,target_hash=NULL,deadline=NULL,drained_generation=NULL,
91
+ resume_phase=NULL`, [manifest.hash]);
92
+ }
@@ -0,0 +1,10 @@
1
+ import type { parse, stringify } from "devalue";
2
+ /** Synchronous value codecs only: admission calls these inside its SQL transaction. */
3
+ export interface WorkflowArgumentCodecs {
4
+ readonly reducers: NonNullable<Parameters<typeof stringify>[1]>;
5
+ readonly revivers: NonNullable<Parameters<typeof parse>[1]>;
6
+ }
7
+ /** Server setup supplies the installed SDK's codecs; all bundled copies share the first one. */
8
+ export declare function setWorkflowArgumentCodecs(codecs: WorkflowArgumentCodecs): void;
9
+ /** Resolves locally, without loading the Workflow SDK or consulting a provider. */
10
+ export declare function workflowArgumentCodecs(): WorkflowArgumentCodecs;