@segmentstream/ontology 0.0.0-stage → 0.92.1

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,99 @@
1
+ import { formatDiagnostics } from "../diagnostics.js";
2
+ import { formatManifest } from "../manifest.js";
3
+ import { renderCatalog } from "../render.js";
4
+ import { describeError, EXIT_CODES } from "./output.js";
5
+ function plural(count, noun) {
6
+ return `${count} ${noun}${count === 1 ? "" : "s"}`;
7
+ }
8
+ function listed(count, names) {
9
+ return names.length === 0 ? String(count) : `${count} (${names.join(", ")})`;
10
+ }
11
+ /** Counts and names of what the manifest declares, the built-in `User` and `member` included. */
12
+ export function catalogSummary(manifest) {
13
+ const entities = manifest.entities.map((entity) => entity.name);
14
+ const properties = manifest.entities.reduce((count, entity) => count + entity.properties.length, 0);
15
+ const relationships = manifest.entities.flatMap((entity) => entity.relationships.map((relationship) => `${entity.name}.${relationship.name}`));
16
+ const actions = manifest.entities.flatMap((entity) => entity.actions.map((action) => `${entity.name}.${action.name}`));
17
+ const roles = manifest.roles.map((role) => role.name);
18
+ const workflows = (manifest.workflows ?? []).map((workflow) => workflow.name);
19
+ return [
20
+ `Entities: ${listed(entities.length, entities)}`,
21
+ `Properties: ${properties}`,
22
+ `Relationships: ${listed(relationships.length, relationships)}`,
23
+ `Actions: ${listed(actions.length, actions)}`,
24
+ `Roles: ${listed(roles.length, roles)}`,
25
+ ...(manifest.feedback === undefined
26
+ ? []
27
+ : [
28
+ `Feedback: ${manifest.feedback.enabled ? "enabled" : "disabled"}; ` +
29
+ `files: ${manifest.feedback.files ? "enabled" : "disabled"} ` +
30
+ "(explicit setting or another non-feedback blob); " +
31
+ `builders: ${manifest.feedback.builders.join(", ") || "none"}`,
32
+ ]),
33
+ ...(workflows.length > 0 ? [`Workflows: ${listed(workflows.length, workflows)}`] : []),
34
+ `Manifest hash: ${manifest.hash}`,
35
+ "",
36
+ ].join("\n");
37
+ }
38
+ function reportDiagnostics(entry, diagnostics, output) {
39
+ if (diagnostics.length === 0) {
40
+ return;
41
+ }
42
+ const count = (severity) => diagnostics.filter((diagnostic) => diagnostic.severity === severity).length;
43
+ const notes = count("info");
44
+ const counts = [
45
+ plural(count("error"), "error"),
46
+ plural(count("warning"), "warning"),
47
+ ...(notes > 0 ? [plural(notes, "note")] : []),
48
+ ];
49
+ output.stderr(`${formatDiagnostics(diagnostics)}\n`);
50
+ output.stderr(`${entry}: ${counts.join(", ")}.\n`);
51
+ }
52
+ /**
53
+ * Loads the ontology and reports every diagnostic on stderr. Returns the loaded ontology, or
54
+ * undefined when it does not load or has errors.
55
+ */
56
+ export async function loadCheckedOntology(entry, dependencies) {
57
+ const { load, output } = dependencies;
58
+ const loaded = await load(entry);
59
+ if (loaded._tag === "Failed") {
60
+ const lines = [
61
+ loaded.reason,
62
+ ...(loaded.error === undefined ? [] : [describeError(loaded.error, { stack: true })]),
63
+ ...(loaded.hint === undefined ? [] : [loaded.hint]),
64
+ ];
65
+ output.stderr(`${lines.join("\n")}\n`);
66
+ return undefined;
67
+ }
68
+ const hasErrors = loaded.diagnostics.some((diagnostic) => diagnostic.severity === "error");
69
+ reportDiagnostics(entry, loaded.diagnostics, output);
70
+ return loaded._tag === "Loaded" && !hasErrors ? loaded : undefined;
71
+ }
72
+ /**
73
+ * `segmentstream-ontology check`: loads the ontology as the deploy pipeline does, reports what
74
+ * `check` found and prints the catalog summary, the manifest or the catalog prose. Diagnostics go to
75
+ * stderr; any error fails the command.
76
+ */
77
+ export async function checkCommand(input, dependencies) {
78
+ const { output } = dependencies;
79
+ const loaded = await loadCheckedOntology(input.entry, dependencies);
80
+ if (loaded === undefined) {
81
+ return EXIT_CODES.failed;
82
+ }
83
+ if (Object.values(loaded.ontology.signIn.channels ?? {}).includes("open")) {
84
+ output.stderr("Agent notice/limits checks skipped: agent config is not visible to ontology check.\n");
85
+ }
86
+ switch (input.format) {
87
+ case "manifest":
88
+ // As `defineOntology` built it, with any field this SDK's contract does not know.
89
+ output.stdout(formatManifest(loaded.ontology.manifest));
90
+ break;
91
+ case "catalog":
92
+ output.stdout(renderCatalog(loaded.manifest));
93
+ break;
94
+ case "summary":
95
+ output.stdout(catalogSummary(loaded.manifest));
96
+ break;
97
+ }
98
+ return EXIT_CODES.ok;
99
+ }
@@ -0,0 +1,48 @@
1
+ import { Diagnostic } from "../diagnostics.js";
2
+ import { OntologyManifest } from "../manifest.js";
3
+ import type { Ontology } from "../ontology.js";
4
+ /** The entry the commands load when none is given: run them in the workspace's `ontology/` folder. */
5
+ export declare const DEFAULT_ENTRY = "./index.ts";
6
+ /** Imports an ES module by its file URL and returns its namespace. */
7
+ export type ModuleImport = (url: string) => Promise<unknown>;
8
+ export type LoadResult = {
9
+ readonly _tag: "Loaded";
10
+ readonly entry: string;
11
+ readonly ontology: Ontology;
12
+ /** The default export's manifest, validated against this SDK's model contract. */
13
+ readonly manifest: OntologyManifest;
14
+ /** What `check` reported while `defineOntology` ran: warnings only, since it did not throw. */
15
+ readonly diagnostics: ReadonlyArray<Diagnostic>;
16
+ } | {
17
+ /** `defineOntology` threw: the definition has errors. */
18
+ readonly _tag: "Invalid";
19
+ readonly entry: string;
20
+ readonly diagnostics: ReadonlyArray<Diagnostic>;
21
+ } | {
22
+ readonly _tag: "Failed";
23
+ readonly entry: string;
24
+ readonly reason: string;
25
+ /** The original error, when there is one: a module that does not compile or throws. */
26
+ readonly error?: unknown;
27
+ /** A likely cause the original error does not name. */
28
+ readonly hint?: string;
29
+ };
30
+ export type OntologyLoader = (entry: string) => Promise<LoadResult>;
31
+ /**
32
+ * Imports a module the way the deploy pipeline's evaluator does under `node --import tsx`: the
33
+ * pinned tsx loader's ES module and CommonJS hooks are registered for the whole process, without a
34
+ * namespace, so TypeScript and extensionless relative imports resolve alike, and the ontology's
35
+ * `@segmentstream/ontology` and `effect` imports load the same modules as the binary's when
36
+ * they resolve to the same files.
37
+ */
38
+ export declare const importWithTsx: ModuleImport;
39
+ /**
40
+ * Loads the module at `entry`, relative to `cwd`, and returns its default export when it is an
41
+ * ontology. The diagnostics are those `check` reported inside `defineOntology`, in the copy of the
42
+ * SDK the ontology imports, which is the copy the deploy pipeline evaluates it with; when
43
+ * `defineOntology` threw, those of `InvalidOntology`. Any other failure keeps the original error.
44
+ */
45
+ export declare function loadOntology(input: {
46
+ readonly entry: string;
47
+ readonly cwd: string;
48
+ }, importModule: ModuleImport): Promise<LoadResult>;
@@ -0,0 +1,139 @@
1
+ import { readFile, stat } from "node:fs/promises";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ import { Result, Schema } from "effect";
5
+ import { Diagnostic } from "../diagnostics.js";
6
+ import { OntologyManifest } from "../manifest.js";
7
+ /** The entry the commands load when none is given: run them in the workspace's `ontology/` folder. */
8
+ export const DEFAULT_ENTRY = "./index.ts";
9
+ const Diagnostics = Schema.Array(Diagnostic);
10
+ // defineOntology exposes the decoded model, not the snake_case JSON written to disk.
11
+ const validateManifest = Schema.decodeUnknownResult(Schema.toType(OntologyManifest));
12
+ let registration;
13
+ /**
14
+ * Imports a module the way the deploy pipeline's evaluator does under `node --import tsx`: the
15
+ * pinned tsx loader's ES module and CommonJS hooks are registered for the whole process, without a
16
+ * namespace, so TypeScript and extensionless relative imports resolve alike, and the ontology's
17
+ * `@segmentstream/ontology` and `effect` imports load the same modules as the binary's when
18
+ * they resolve to the same files.
19
+ */
20
+ export const importWithTsx = async (url) => {
21
+ registration ??= Promise.all([
22
+ import("tsx/esm/api").then((tsx) => tsx.register()),
23
+ import("tsx/cjs/api").then((tsx) => tsx.register()),
24
+ ]);
25
+ await registration;
26
+ return import(url);
27
+ };
28
+ /** The `type` of the package that holds `path`: `commonjs` when its package.json has none. */
29
+ async function packageType(path) {
30
+ let directory = dirname(path);
31
+ for (;;) {
32
+ const manifest = await readFile(join(directory, "package.json"), "utf8").catch(() => undefined);
33
+ if (manifest !== undefined) {
34
+ const type = JSON.parse(manifest)?.type;
35
+ return typeof type === "string" ? type : "commonjs";
36
+ }
37
+ const parent = dirname(directory);
38
+ if (parent === directory) {
39
+ return undefined;
40
+ }
41
+ directory = parent;
42
+ }
43
+ }
44
+ /**
45
+ * Outside an ES module package, tsx compiles the entry to CommonJS, which cannot import the SDK;
46
+ * the errors Node reports then do not say so. The deploy pipeline fails the same way.
47
+ */
48
+ async function moduleTypeHint(path) {
49
+ const type = await packageType(path).catch(() => undefined);
50
+ if (type === "module") {
51
+ return undefined;
52
+ }
53
+ return 'The ontology is an ES module: its package.json must set "type": "module".';
54
+ }
55
+ function isRecord(value) {
56
+ return typeof value === "object" && value !== null;
57
+ }
58
+ /** `defineOntology` throws `InvalidOntology`; another copy of the SDK may have thrown it. */
59
+ function invalidOntologyDiagnostics(error) {
60
+ if (!isRecord(error) || error._tag !== "InvalidOntology") {
61
+ return undefined;
62
+ }
63
+ return Schema.is(Diagnostics)(error.diagnostics) ? error.diagnostics : undefined;
64
+ }
65
+ /**
66
+ * The shape of `defineOntology`'s result. The ontology may import another copy of the SDK than the
67
+ * binary's, so neither `instanceof` nor entity identity can tell.
68
+ */
69
+ function isOntology(value) {
70
+ if (!isRecord(value) || !isRecord(value.config) || !isRecord(value.manifest)) {
71
+ return false;
72
+ }
73
+ return (Array.isArray(value.config.entities) &&
74
+ Array.isArray(value.entities) &&
75
+ Schema.is(Diagnostics)(value.warnings));
76
+ }
77
+ async function isFile(path) {
78
+ try {
79
+ return (await stat(path)).isFile();
80
+ }
81
+ catch {
82
+ return false;
83
+ }
84
+ }
85
+ /**
86
+ * Loads the module at `entry`, relative to `cwd`, and returns its default export when it is an
87
+ * ontology. The diagnostics are those `check` reported inside `defineOntology`, in the copy of the
88
+ * SDK the ontology imports, which is the copy the deploy pipeline evaluates it with; when
89
+ * `defineOntology` threw, those of `InvalidOntology`. Any other failure keeps the original error.
90
+ */
91
+ export async function loadOntology(input, importModule) {
92
+ const { entry } = input;
93
+ const path = resolve(input.cwd, entry);
94
+ if (!(await isFile(path))) {
95
+ return { _tag: "Failed", entry, reason: `${entry} does not exist or is not a file.` };
96
+ }
97
+ let namespace;
98
+ try {
99
+ namespace = await importModule(pathToFileURL(path).href);
100
+ }
101
+ catch (error) {
102
+ const diagnostics = invalidOntologyDiagnostics(error);
103
+ if (diagnostics !== undefined) {
104
+ return { _tag: "Invalid", entry, diagnostics };
105
+ }
106
+ const hint = await moduleTypeHint(path);
107
+ return {
108
+ _tag: "Failed",
109
+ entry,
110
+ reason: `${entry} failed to load.`,
111
+ error,
112
+ ...(hint === undefined ? {} : { hint }),
113
+ };
114
+ }
115
+ const ontology = isRecord(namespace) ? namespace.default : undefined;
116
+ if (!isOntology(ontology)) {
117
+ return {
118
+ _tag: "Failed",
119
+ entry,
120
+ reason: `${entry} must default-export the result of defineOntology(...).`,
121
+ };
122
+ }
123
+ const manifest = validateManifest(ontology.manifest);
124
+ if (Result.isFailure(manifest)) {
125
+ return {
126
+ _tag: "Failed",
127
+ entry,
128
+ reason: `The manifest of ${entry} does not match this SDK's manifest contract.`,
129
+ error: manifest.failure,
130
+ };
131
+ }
132
+ return {
133
+ _tag: "Loaded",
134
+ entry,
135
+ ontology,
136
+ manifest: manifest.success,
137
+ diagnostics: ontology.warnings,
138
+ };
139
+ }
@@ -0,0 +1,31 @@
1
+ import { Redacted } from "effect";
2
+ import { type CheckFormat } from "./check.js";
3
+ import { type OntologyLoader } from "./load.js";
4
+ import { type OwnerConnection } from "./migrate.js";
5
+ import { type ExitCode, type Output } from "./output.js";
6
+ export declare const USAGE = "Usage: segmentstream-ontology <command> [entry] [options]\n\nRun the commands in the workspace's ontology/ folder. The entry is the module that\ndefault-exports defineOntology(...); it defaults to ./index.ts.\n\nCommands:\n check [entry] Load the ontology, report its diagnostics and summarize the catalog.\n --manifest Print the manifest JSON instead of the summary.\n --catalog Print the catalog as prose instead of the summary.\n\n migrate [entry] Plan the migration against the catalog recorded in the database and\n apply it. Dropping entities, properties or relationships is refused.\n --database-url <url>\n The owner connection string (ontology_owner, direct). Defaults to\n SEGMENTSTREAM_ONTOLOGY_MIGRATE_URL.\n --plan Print the plan with its SQL and apply nothing.\n With SEGMENTSTREAM_WORKSPACE_ID set, it also reconciles the workflow\n users with the ontology's workflows, as deploy does.\n\nOptions:\n -h, --help Show this help.\n\nExit codes: 0 success, 1 errors or failure, 2 migration refused, 64 usage error.\n";
7
+ export type CommandLine = {
8
+ readonly _tag: "Help";
9
+ } | {
10
+ readonly _tag: "Usage";
11
+ readonly message: string;
12
+ } | {
13
+ readonly _tag: "Check";
14
+ readonly entry: string;
15
+ readonly format: CheckFormat;
16
+ } | {
17
+ readonly _tag: "Migrate";
18
+ readonly entry: string;
19
+ readonly planOnly: boolean;
20
+ readonly databaseUrl: Redacted.Redacted<string> | undefined;
21
+ };
22
+ /** Reads the command line. Errors name options and commands, never a value. */
23
+ export declare function parseCommandLine(args: ReadonlyArray<string>): CommandLine;
24
+ export interface MainDependencies {
25
+ readonly environment: Readonly<Record<string, string | undefined>>;
26
+ readonly output: Output;
27
+ readonly load: OntologyLoader;
28
+ readonly connect: OwnerConnection;
29
+ }
30
+ /** Runs one command line and returns the process exit code. */
31
+ export declare function runMain(args: ReadonlyArray<string>, dependencies: MainDependencies): Promise<ExitCode>;
@@ -0,0 +1,121 @@
1
+ import { parseArgs } from "node:util";
2
+ import { Redacted } from "effect";
3
+ import { checkCommand } from "./check.js";
4
+ import { DEFAULT_ENTRY } from "./load.js";
5
+ import { MIGRATE_URL_VARIABLE, migrateCommand, WORKSPACE_ID_VARIABLE, } from "./migrate.js";
6
+ import { EXIT_CODES } from "./output.js";
7
+ export const USAGE = `Usage: segmentstream-ontology <command> [entry] [options]
8
+
9
+ Run the commands in the workspace's ontology/ folder. The entry is the module that
10
+ default-exports defineOntology(...); it defaults to ${DEFAULT_ENTRY}.
11
+
12
+ Commands:
13
+ check [entry] Load the ontology, report its diagnostics and summarize the catalog.
14
+ --manifest Print the manifest JSON instead of the summary.
15
+ --catalog Print the catalog as prose instead of the summary.
16
+
17
+ migrate [entry] Plan the migration against the catalog recorded in the database and
18
+ apply it. Dropping entities, properties or relationships is refused.
19
+ --database-url <url>
20
+ The owner connection string (ontology_owner, direct). Defaults to
21
+ ${MIGRATE_URL_VARIABLE}.
22
+ --plan Print the plan with its SQL and apply nothing.
23
+ With ${WORKSPACE_ID_VARIABLE} set, it also reconciles the workflow
24
+ users with the ontology's workflows, as deploy does.
25
+
26
+ Options:
27
+ -h, --help Show this help.
28
+
29
+ Exit codes: 0 success, 1 errors or failure, 2 migration refused, 64 usage error.
30
+ `;
31
+ const OPTIONS = {
32
+ help: { type: "boolean", short: "h" },
33
+ manifest: { type: "boolean" },
34
+ catalog: { type: "boolean" },
35
+ plan: { type: "boolean" },
36
+ "database-url": { type: "string" },
37
+ };
38
+ /** The options each command accepts besides `--help`. */
39
+ const COMMAND_OPTIONS = new Map([
40
+ ["check", ["manifest", "catalog"]],
41
+ ["migrate", ["plan", "database-url"]],
42
+ ]);
43
+ function usage(message) {
44
+ return { _tag: "Usage", message };
45
+ }
46
+ /** A connection string in place of a command or entry would be echoed back; it is a credential. */
47
+ function looksLikeUrl(argument) {
48
+ return /^[a-z][a-z0-9+.-]*:\/\//i.test(argument);
49
+ }
50
+ function checkFormat(values) {
51
+ if (values.manifest === true) {
52
+ return "manifest";
53
+ }
54
+ return values.catalog === true ? "catalog" : "summary";
55
+ }
56
+ const parse = (args) => parseArgs({ args, options: OPTIONS, allowPositionals: true, strict: true });
57
+ /** Reads the command line. Errors name options and commands, never a value. */
58
+ export function parseCommandLine(args) {
59
+ let parsed;
60
+ try {
61
+ parsed = parse([...args]);
62
+ }
63
+ catch (error) {
64
+ // parseArgs names the option, never its value.
65
+ return usage(error instanceof Error ? error.message : String(error));
66
+ }
67
+ const { values, positionals } = parsed;
68
+ const [command, ...entries] = positionals;
69
+ if (values.help === true || command === "help") {
70
+ return { _tag: "Help" };
71
+ }
72
+ if (positionals.some(looksLikeUrl)) {
73
+ return usage("Commands and entries are not URLs. Pass the connection string with --database-url.");
74
+ }
75
+ if (command === undefined) {
76
+ return usage("Name a command: check or migrate.");
77
+ }
78
+ const accepted = COMMAND_OPTIONS.get(command);
79
+ if (accepted === undefined) {
80
+ return usage(`Unknown command "${command}". The commands are check and migrate.`);
81
+ }
82
+ const given = Object.keys(values).filter((name) => name !== "help");
83
+ const foreign = given.find((name) => !accepted.includes(name));
84
+ if (foreign !== undefined) {
85
+ return usage(`${command} does not take --${foreign}.`);
86
+ }
87
+ if (entries.length > 1) {
88
+ return usage(`${command} takes one entry at most.`);
89
+ }
90
+ const entry = entries[0] ?? DEFAULT_ENTRY;
91
+ if (command === "check") {
92
+ if (values.manifest === true && values.catalog === true) {
93
+ return usage("check takes --manifest or --catalog, not both.");
94
+ }
95
+ return { _tag: "Check", entry, format: checkFormat(values) };
96
+ }
97
+ const databaseUrl = values["database-url"];
98
+ return {
99
+ _tag: "Migrate",
100
+ entry,
101
+ planOnly: values.plan === true,
102
+ databaseUrl: databaseUrl === undefined ? undefined : Redacted.make(databaseUrl),
103
+ };
104
+ }
105
+ /** Runs one command line and returns the process exit code. */
106
+ export async function runMain(args, dependencies) {
107
+ const { output } = dependencies;
108
+ const commandLine = parseCommandLine(args);
109
+ switch (commandLine._tag) {
110
+ case "Help":
111
+ output.stdout(USAGE);
112
+ return EXIT_CODES.ok;
113
+ case "Usage":
114
+ output.stderr(`${commandLine.message}\n\n${USAGE}`);
115
+ return EXIT_CODES.usage;
116
+ case "Check":
117
+ return checkCommand(commandLine, dependencies);
118
+ case "Migrate":
119
+ return migrateCommand({ ...commandLine, environment: dependencies.environment }, dependencies);
120
+ }
121
+ }
@@ -0,0 +1,57 @@
1
+ import { type Layer, Redacted } from "effect";
2
+ import { SqlClient } from "effect/unstable/sql";
3
+ import { type SqlError } from "effect/unstable/sql/SqlError";
4
+ import { type MigrationPlan } from "../migrate/model.js";
5
+ import type { OntologyLoader } from "./load.js";
6
+ import { type ExitCode, type Output } from "./output.js";
7
+ /**
8
+ * The owner connection string `migrate` reads when `--database-url` is not given: `ontology_owner`
9
+ * over a direct connection. `SEGMENTSTREAM_ONTOLOGY_DATABASE_URL`, the service's pooled
10
+ * `ontology_app` role, cannot change the schema and is never read here.
11
+ */
12
+ export declare const MIGRATE_URL_VARIABLE = "SEGMENTSTREAM_ONTOLOGY_MIGRATE_URL";
13
+ /**
14
+ * The workspace whose workflow users `migrate` reconciles with the ontology's workflows, as deploy
15
+ * does. Without it, workflow users are left as they are.
16
+ */
17
+ export declare const WORKSPACE_ID_VARIABLE = "SEGMENTSTREAM_WORKSPACE_ID";
18
+ /** A dedicated connection for one migration, closed when the command ends. */
19
+ export type OwnerConnection = (url: Redacted.Redacted<string>) => Layer.Layer<SqlClient.SqlClient, SqlError>;
20
+ export interface MigrateInput {
21
+ readonly entry: string;
22
+ /** Print the plan and apply nothing. */
23
+ readonly planOnly: boolean;
24
+ /** `--database-url`; it takes precedence over the environment. */
25
+ readonly databaseUrl: Redacted.Redacted<string> | undefined;
26
+ readonly environment: Readonly<Record<string, string | undefined>>;
27
+ }
28
+ export interface MigrateDependencies {
29
+ readonly load: OntologyLoader;
30
+ readonly connect: OwnerConnection;
31
+ readonly output: Output;
32
+ }
33
+ /** `@effect/sql-pg` on the owner connection string, configured as the deploy pipeline's migrator. */
34
+ export declare const connectOwnerDatabase: OwnerConnection;
35
+ type ResolvedUrl = {
36
+ readonly _tag: "Resolved";
37
+ readonly url: Redacted.Redacted<string>;
38
+ } | {
39
+ readonly _tag: "Unusable";
40
+ readonly message: string;
41
+ };
42
+ /**
43
+ * The connection string from `--database-url`, else from the environment. Messages name where it
44
+ * came from, never its value.
45
+ */
46
+ export declare function resolveDatabaseUrl(input: MigrateInput): ResolvedUrl;
47
+ /** Where the plan starts and ends, and each step; with `sql`, each step's statements too. */
48
+ export declare function formatPlan(plan: MigrationPlan, options: {
49
+ readonly sql: boolean;
50
+ }): string;
51
+ /**
52
+ * `segmentstream-ontology migrate`: checks the ontology, plans the migration against the catalog
53
+ * recorded in the database and applies it with the SDK's planner and applier, the code the deploy
54
+ * pipeline runs. Removed declarations retain their storage. Nothing it writes contains the connection string.
55
+ */
56
+ export declare function migrateCommand(input: MigrateInput, dependencies: MigrateDependencies): Promise<ExitCode>;
57
+ export {};
@@ -0,0 +1,170 @@
1
+ import * as PgClient from "@effect/sql-pg/PgClient";
2
+ import { Cause, Effect, Redacted } from "effect";
3
+ import { SqlClient } from "effect/unstable/sql";
4
+ import { isSqlError } from "effect/unstable/sql/SqlError";
5
+ import { applyMigration, readCatalog, readRetainedStorage, readRuntimeTables, readHistoryActivityIndexes, readStorageNames, } from "../migrate/apply.js";
6
+ import { MigrationRefused } from "../migrate/errors.js";
7
+ import { isNoopMigration } from "../migrate/model.js";
8
+ import { planMigration } from "../migrate/plan.js";
9
+ import { loadCheckedOntology } from "./check.js";
10
+ import { postgresTls } from "../runtime/postgres-tls.js";
11
+ import { describeError, EXIT_CODES, redactedOutput } from "./output.js";
12
+ /**
13
+ * The owner connection string `migrate` reads when `--database-url` is not given: `ontology_owner`
14
+ * over a direct connection. `SEGMENTSTREAM_ONTOLOGY_DATABASE_URL`, the service's pooled
15
+ * `ontology_app` role, cannot change the schema and is never read here.
16
+ */
17
+ export const MIGRATE_URL_VARIABLE = "SEGMENTSTREAM_ONTOLOGY_MIGRATE_URL";
18
+ /**
19
+ * The workspace whose workflow users `migrate` reconciles with the ontology's workflows, as deploy
20
+ * does. Without it, workflow users are left as they are.
21
+ */
22
+ export const WORKSPACE_ID_VARIABLE = "SEGMENTSTREAM_WORKSPACE_ID";
23
+ /** `@effect/sql-pg` on the owner connection string, configured as the deploy pipeline's migrator. */
24
+ export const connectOwnerDatabase = (url) => PgClient.layer({
25
+ url,
26
+ ssl: postgresTls(url),
27
+ maxConnections: 1,
28
+ applicationName: "segmentstream-ontology-migrate",
29
+ transformJson: false,
30
+ });
31
+ /**
32
+ * The connection string from `--database-url`, else from the environment. Messages name where it
33
+ * came from, never its value.
34
+ */
35
+ export function resolveDatabaseUrl(input) {
36
+ const fromFlag = input.databaseUrl === undefined ? undefined : Redacted.value(input.databaseUrl);
37
+ const value = (fromFlag ?? input.environment[MIGRATE_URL_VARIABLE] ?? "").trim();
38
+ const source = fromFlag === undefined ? MIGRATE_URL_VARIABLE : "--database-url";
39
+ if (value === "") {
40
+ return {
41
+ _tag: "Unusable",
42
+ message: "migrate needs the owner connection string: pass --database-url <url> or set " +
43
+ `${MIGRATE_URL_VARIABLE}. It never reads SEGMENTSTREAM_ONTOLOGY_DATABASE_URL, the ` +
44
+ "service's role, which cannot change the schema.",
45
+ };
46
+ }
47
+ const protocol = URL.canParse(value) ? new URL(value).protocol : undefined;
48
+ if (protocol !== "postgres:" && protocol !== "postgresql:") {
49
+ return {
50
+ _tag: "Unusable",
51
+ message: `${source} must be a postgres:// or postgresql:// connection string.`,
52
+ };
53
+ }
54
+ return { _tag: "Resolved", url: Redacted.make(value) };
55
+ }
56
+ function indent(text, prefix) {
57
+ return text
58
+ .split("\n")
59
+ .map((line) => `${prefix}${line}`)
60
+ .join("\n");
61
+ }
62
+ function stepNoun(steps) {
63
+ return steps === 1 ? "step" : "steps";
64
+ }
65
+ function formatRefusals(refusals) {
66
+ const lines = refusals.map((refusal) => `refused ${refusal.path}: ${refusal.message} [${refusal.code}]`);
67
+ const noun = refusals.length === 1 ? "refusal" : "refusals";
68
+ return `${lines.join("\n")}\nThe plan has ${refusals.length} ${noun}; nothing was applied.\n`;
69
+ }
70
+ /** Where the plan starts and ends, and each step; with `sql`, each step's statements too. */
71
+ export function formatPlan(plan, options) {
72
+ const lines = [
73
+ `Current: ${plan.currentHash ?? "none (the database has no ontology catalog)"}`,
74
+ `Target: ${plan.target.hash}`,
75
+ plan.steps.length === 0
76
+ ? "No schema steps."
77
+ : `${plan.steps.length} ${stepNoun(plan.steps.length)}:`,
78
+ ];
79
+ for (const [index, step] of plan.steps.entries()) {
80
+ const traits = [
81
+ step.classification,
82
+ ...(step.transactional ? [] : ["outside the transaction"]),
83
+ ];
84
+ lines.push(` ${index + 1}. [${traits.join(", ")}] ${step.description}`);
85
+ if (options.sql) {
86
+ lines.push(...step.sql.map((statement) => `${indent(statement.trim(), " ")};`));
87
+ }
88
+ }
89
+ return `${lines.join("\n")}\n`;
90
+ }
91
+ function migrateDatabase(input) {
92
+ const { output, target } = input;
93
+ const options = input.workspaceId === undefined ? {} : { workspaceId: input.workspaceId };
94
+ return Effect.gen(function* () {
95
+ const sql = yield* SqlClient.SqlClient;
96
+ const current = yield* readCatalog({ sql });
97
+ const retained = yield* readRetainedStorage({ sql });
98
+ const existingTables = yield* readRuntimeTables({ sql });
99
+ const existingHistoryActivityIndexes = yield* readHistoryActivityIndexes({ sql });
100
+ const existingStorage = yield* readStorageNames({ sql });
101
+ const plan = planMigration({
102
+ current,
103
+ retained,
104
+ target,
105
+ existingTables,
106
+ existingHistoryActivityIndexes,
107
+ existingStorage,
108
+ });
109
+ output.stdout(formatPlan(plan, { sql: input.planOnly }));
110
+ if (plan.refusals.length > 0) {
111
+ output.stderr(formatRefusals(plan.refusals));
112
+ return EXIT_CODES.refused;
113
+ }
114
+ if (input.planOnly) {
115
+ output.stdout(isNoopMigration(plan)
116
+ ? `The database already records ${plan.target.hash}; nothing to apply.\n`
117
+ : "Nothing was applied (--plan).\n");
118
+ return EXIT_CODES.ok;
119
+ }
120
+ if (isNoopMigration(plan)) {
121
+ // Like deploy, a no-op plan still reconciles the workflow users.
122
+ yield* applyMigration(plan, { sql, ...options });
123
+ output.stdout(`The database already records ${plan.target.hash}; nothing to apply.\n`);
124
+ return EXIT_CODES.ok;
125
+ }
126
+ const result = yield* applyMigration(plan, { sql, ...options });
127
+ output.stdout(`Applied ${result.appliedSteps} ${stepNoun(result.appliedSteps)}. ` +
128
+ `The database records ${result.hash}.\n`);
129
+ return EXIT_CODES.ok;
130
+ });
131
+ }
132
+ /** Reports a failure with its original explanation; the output it writes to is redacted. */
133
+ function reportFailure(error, output) {
134
+ if (error instanceof MigrationRefused) {
135
+ output.stderr(formatRefusals(error.refusals));
136
+ return EXIT_CODES.refused;
137
+ }
138
+ if (isSqlError(error)) {
139
+ output.stderr(`The migration failed: ${describeError(error)}\n`);
140
+ return EXIT_CODES.failed;
141
+ }
142
+ // MigrationFailed names the step and keeps the database's explanation as its cause;
143
+ // CatalogMismatch asks to plan again; CatalogInvalid keeps what did not decode.
144
+ output.stderr(`${describeError(error)}\n`);
145
+ return EXIT_CODES.failed;
146
+ }
147
+ /**
148
+ * `segmentstream-ontology migrate`: checks the ontology, plans the migration against the catalog
149
+ * recorded in the database and applies it with the SDK's planner and applier, the code the deploy
150
+ * pipeline runs. Removed declarations retain their storage. Nothing it writes contains the connection string.
151
+ */
152
+ export async function migrateCommand(input, dependencies) {
153
+ const databaseUrl = resolveDatabaseUrl(input);
154
+ if (databaseUrl._tag === "Unusable") {
155
+ dependencies.output.stderr(`${databaseUrl.message}\n`);
156
+ return EXIT_CODES.usage;
157
+ }
158
+ const output = redactedOutput(dependencies.output, Redacted.value(databaseUrl.url));
159
+ const loaded = await loadCheckedOntology(input.entry, { load: dependencies.load, output });
160
+ if (loaded === undefined) {
161
+ return EXIT_CODES.failed;
162
+ }
163
+ const migration = migrateDatabase({
164
+ target: loaded.manifest,
165
+ planOnly: input.planOnly,
166
+ workspaceId: input.environment[WORKSPACE_ID_VARIABLE]?.trim() || undefined,
167
+ output,
168
+ }).pipe(Effect.provide(dependencies.connect(databaseUrl.url)), Effect.catchCause((cause) => Effect.sync(() => reportFailure(Cause.squash(cause), output))));
169
+ return Effect.runPromise(migration);
170
+ }