@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,331 @@
1
+ import type { BlobUpload, BlobValue } from "./blob.js";
2
+ import { Effect, type Schema } from "effect";
3
+ import { type EarlierQueryMetricsName, type EarlierFreshMetricQueryOptions, type EarlierMetricsField, type EarlierMetricsName } from "./legacy.js";
4
+ import type { Metrics } from "./metric.js";
5
+ import type { WarehouseSource } from "./source.js";
6
+ import type { UserHandle } from "./user.js";
7
+ import { type Action, type Actions } from "./action.js";
8
+ import type { ConnectionError } from "./connection.js";
9
+ import type { ActionError, ActionRejected, Conflict, NotFound, ScopeViolated } from "./errors.js";
10
+ import { type AnyProperty } from "./property.js";
11
+ import type { AnyRelationship, ManyRelationship, OneRelationship } from "./relationship.js";
12
+ import { OntologyActions, OntologyReads, OntologyWrites, type BatchOptions, type BatchRecordResult, type BatchResult, type BatchSummaryResult, type FindOptions, type FreshMetricQueryOptions, type GetOptions, type ActionRunOptions, type UpsertResult } from "./runtime.js";
13
+ export declare const EntityTypeId: unique symbol;
14
+ export type Properties = {
15
+ readonly [name: string]: AnyProperty;
16
+ };
17
+ export type Relationships = {
18
+ readonly [name: string]: AnyRelationship;
19
+ };
20
+ export type NoRelationships = Readonly<Record<never, never>>;
21
+ /** Fields every record has. They are never declared. */
22
+ export interface SystemFields {
23
+ /** A UUID. */
24
+ readonly id: string;
25
+ /** ISO 8601 timestamps. */
26
+ readonly createdAt: string;
27
+ readonly updatedAt: string;
28
+ /** The `user` who created or last updated the record; `null` when the platform wrote it. */
29
+ readonly createdBy: string | null;
30
+ readonly updatedBy: string | null;
31
+ }
32
+ /** A record id, or a record. */
33
+ export type RecordRef = string | {
34
+ readonly id: string;
35
+ };
36
+ type Simplify<T> = {
37
+ [K in keyof T]: T[K];
38
+ } & {};
39
+ type Unwrapped<S> = S extends Schema.optionalKey<infer Inner> ? Inner : S;
40
+ type IsOptional<S> = S extends {
41
+ readonly "~type.optionality": "optional";
42
+ } ? true : false;
43
+ type ValueOf<S> = S extends {
44
+ readonly Type: infer T;
45
+ } ? IsOptional<S> extends true ? T | null : T : never;
46
+ type WriteValueOf<S> = NonNullable<ValueOf<S>> extends BlobValue ? BlobUpload | (null extends ValueOf<S> ? null : never) : ValueOf<S>;
47
+ type RequiredOnCreate<S> = IsOptional<S> extends true ? false : S extends {
48
+ readonly "~ontology.defaulted": true;
49
+ } ? false : true;
50
+ type KeysWhere<T, Condition> = {
51
+ [K in keyof T]-?: T[K] extends Condition ? K : never;
52
+ }[keyof T] & string;
53
+ type RequiredPropertyKeys<P> = {
54
+ [K in keyof P]-?: RequiredOnCreate<P[K]> extends true ? K : never;
55
+ }[keyof P] & string;
56
+ /** Relationships declared with `on`: matched by value, so with no `<relationship>Id`. */
57
+ type MatchedKeys<R> = KeysWhere<R, {
58
+ readonly "~ontology.matched": true;
59
+ }>;
60
+ /** `rel.one` relationships that hold a `<relationship>Id` key. */
61
+ type OneKeys<R> = Exclude<KeysWhere<R, OneRelationship>, MatchedKeys<R>>;
62
+ type RequiredOneKeys<R> = Exclude<KeysWhere<R, OneRelationship<false>>, MatchedKeys<R>>;
63
+ type ManyKeys<R> = KeysWhere<R, ManyRelationship>;
64
+ /** Relationships `find` can include and filter through. */
65
+ type LinkKeys<R> = Exclude<keyof R & string, MatchedKeys<R>>;
66
+ type UniqueKeys<P> = {
67
+ [K in keyof P]-?: Unwrapped<P[K]> extends {
68
+ readonly "~ontology.unique": true;
69
+ } ? K : never;
70
+ }[keyof P] & string;
71
+ type RelationshipIds<R> = {
72
+ readonly [K in OneKeys<R> as `${K}Id`]: R[K] extends OneRelationship<true> ? string | null : string;
73
+ };
74
+ /**
75
+ * A record of the entity: system fields, declared properties, and `<relationship>Id` per `rel.one`
76
+ * between stored entities.
77
+ */
78
+ export type EntityRecord<P, R> = Simplify<SystemFields & {
79
+ readonly [K in keyof P]: ValueOf<P[K]>;
80
+ } & RelationshipIds<R>>;
81
+ /**
82
+ * Values for `create` and `upsertBy`. Properties without a default are required unless optional;
83
+ * relationships take ids by relationship name (`{ lead: lead.id }`), `rel.many` a list of ids.
84
+ */
85
+ export type CreateValues<P, R> = Simplify<{
86
+ readonly [K in RequiredPropertyKeys<P>]: WriteValueOf<P[K]>;
87
+ } & {
88
+ readonly [K in Exclude<keyof P, RequiredPropertyKeys<P>>]?: WriteValueOf<P[K]>;
89
+ } & {
90
+ readonly [K in RequiredOneKeys<R>]: string;
91
+ } & {
92
+ readonly [K in Exclude<OneKeys<R>, RequiredOneKeys<R>>]?: string | null;
93
+ } & {
94
+ readonly [K in ManyKeys<R>]?: ReadonlyArray<string>;
95
+ }>;
96
+ /** Values for `update`. Handlers may write `managed` properties; the generated `update` may not. */
97
+ export type UpdateValues<P, R> = Simplify<{
98
+ readonly [K in keyof P]?: WriteValueOf<P[K]>;
99
+ } & {
100
+ readonly [K in OneKeys<R>]?: R[K] extends OneRelationship<true> ? string | null : string;
101
+ } & {
102
+ readonly [K in ManyKeys<R>]?: ReadonlyArray<string>;
103
+ }>;
104
+ type BlobKeys<P> = {
105
+ [K in keyof P]-?: NonNullable<ValueOf<P[K]>> extends BlobValue ? K : never;
106
+ }[keyof P] & string;
107
+ type UnsupportedBatchKeys<P, R> = BlobKeys<P> | ManyKeys<R>;
108
+ /** Create values for a batch: ordinary properties and stored `rel.one` assignments only. */
109
+ export type BatchCreateValues<P, R> = Simplify<Omit<CreateValues<P, R>, UnsupportedBatchKeys<P, R>> & {
110
+ readonly [K in UnsupportedBatchKeys<P, R>]?: never;
111
+ }>;
112
+ /** Patch values for a batch. Blob and collection assignments use single-record methods. */
113
+ export type BatchUpdateValues<P, R> = Simplify<Omit<UpdateValues<P, R>, UnsupportedBatchKeys<P, R>> & {
114
+ readonly [K in UnsupportedBatchKeys<P, R>]?: never;
115
+ }>;
116
+ /** Ordinary declared properties accepted as upsert keys; unique declarations are checked at runtime. */
117
+ export type BatchKey<P> = Exclude<keyof P & string, BlobKeys<P>>;
118
+ /** Upsert inputs must explicitly supply non-null values for every selected conflict key. */
119
+ export type BatchUpsertValues<P, R, K extends BatchKey<P>> = Simplify<Omit<BatchCreateValues<P, R>, K> & {
120
+ readonly [Key in K]: NonNullable<WriteValueOf<P[Key]>>;
121
+ }>;
122
+ export interface BatchUpdateRecord<P, R> {
123
+ readonly id: string;
124
+ readonly values: BatchUpdateValues<P, R>;
125
+ }
126
+ interface EntityUpsertManyInput<P, R, K extends BatchKey<P>> extends BatchOptions {
127
+ readonly on: readonly [K, ...K[]];
128
+ readonly records: ReadonlyArray<BatchUpsertValues<P, R, NoInfer<K>>>;
129
+ }
130
+ type BatchWriteError = ActionRejected | Conflict | NotFound | ScopeViolated;
131
+ /** Fields a fresh metric query groups by: declared properties and `<relationship>Id` keys. */
132
+ export type MetricQueryGroupKey<P, R> = Exclude<keyof P & string, BlobKeys<P>> | (keyof RelationshipIds<R> & string);
133
+ /** The options of an entity's fresh metric query, its metrics under either of their names. */
134
+ export type FreshMetricQueryInput<P, R, Metric extends string, Group extends string> = FreshMetricQueryOptions<EntityRecord<P, R>, LinkKeys<R>, Metric, Group> | EarlierFreshMetricQueryOptions<EntityRecord<P, R>, LinkKeys<R>, Metric, Group>;
135
+ /**
136
+ * One row of a fresh metric query: the grouped fields, typed as the record's, and each metric as a
137
+ * decimal string, or `null` where the warehouse's value is null too.
138
+ */
139
+ export type FreshMetricQueryRow<Record, Group extends keyof Record, Metric extends string> = Simplify<{
140
+ readonly [K in Group]: Record[K];
141
+ } & {
142
+ readonly [K in Metric]: string | null;
143
+ }>;
144
+ /**
145
+ * Fields an index may cover: declared properties, system properties and `rel.one` relationships
146
+ * between stored entities.
147
+ */
148
+ export type IndexField<P, R> = (keyof P & string) | keyof SystemFields | OneKeys<R>;
149
+ /** An index: the covered fields in order, or the fields with options. */
150
+ export type IndexDefinition<Field extends string = string> = ReadonlyArray<Field> | {
151
+ readonly properties: ReadonlyArray<Field>;
152
+ readonly unique?: boolean;
153
+ };
154
+ /** The metrics of an entity that declares none. */
155
+ type NoMetrics = Readonly<Record<never, never>>;
156
+ export interface EntityDefinition<P extends Properties, R extends Relationships, M extends Metrics = Metrics> extends EarlierMetricsField<M> {
157
+ /** The stable identity. It never changes; a changed id is a new entity. */
158
+ readonly id: string;
159
+ readonly label: string;
160
+ readonly plural: string;
161
+ /** The property that names a record in lists, pickers and prose. */
162
+ readonly title: keyof P & string;
163
+ readonly description: string;
164
+ readonly properties: P;
165
+ readonly source?: WarehouseSource;
166
+ readonly metrics?: M;
167
+ readonly relationships?: R;
168
+ readonly indexes?: ReadonlyArray<IndexDefinition<IndexField<P, R>>>;
169
+ /** A Markdown file with process knowledge, relative to the ontology folder. */
170
+ readonly guide?: string;
171
+ /** The entity's previous name, for one deploy, so that the table is renamed instead of replaced. */
172
+ readonly renamedFrom?: string;
173
+ /**
174
+ * Who writes the entity's records. `"generated"`, the default, adds the generated `create`,
175
+ * `update`, `delete`, `upsert_by_<property>` and, with a `rel.many`, `link` and `unlink`.
176
+ * `"actions"` adds none of them: only the entity's authored actions write its records, and no
177
+ * generated `link` or `unlink` reaches its `rel.many` links from either side. Deleting a record
178
+ * on the other side still removes that record's own links, as it removes every reference to it.
179
+ * Reads stay the same. Stored entities only.
180
+ */
181
+ readonly writes?: EntityWrites;
182
+ }
183
+ /** Who writes an entity's records; see {@link EntityDefinition.writes}. */
184
+ export type EntityWrites = "generated" | "actions";
185
+ /** The actions of an entity before `.actions(…)` adds any. */
186
+ export type NoActions = Readonly<Record<never, never>>;
187
+ /**
188
+ * What an authored action handle names besides its definition: the entity it belongs to and its key
189
+ * in `.actions(…)`, as declared, so `after(name, Lead.actions.changeStatus, …)` can name the action
190
+ * in the manifest, and type-level only, the entity's record type for the trigger's record.
191
+ */
192
+ export interface ActionHandle<EntityName extends string = string, Key extends string = string, EntityType = unknown> {
193
+ /** The entity's name as declared: `lead`. */
194
+ readonly entity: EntityName;
195
+ /** The action's key in `.actions(…)`: `changeStatus`. */
196
+ readonly name: Key;
197
+ /** Type-level only: the record type of the action's entity, as `typeof Lead.Type`. */
198
+ readonly "~ontology.record": EntityType;
199
+ }
200
+ /**
201
+ * An authored action as an entity handle exposes it: its definition, its {@link ActionHandle}
202
+ * names, and callable as an Effect that runs it as the current caller, through the same path as its
203
+ * HTTP route, with its permission check and history. Calling it requires {@link OntologyActions},
204
+ * which a workflow step's `run` provides; inside an action handler the call does not type-check.
205
+ */
206
+ export type ActionInvoker<A, EntityName extends string = string, Key extends string = string, EntityType = unknown> = A extends Action<infer Input, infer Result> ? A & ActionHandle<EntityName, Key, EntityType> & ((input: Input["Type"], options?: ActionRunOptions) => Effect.Effect<Result, ActionError | ConnectionError, OntologyActions>) : A;
207
+ /** The authored actions of an entity handle, each an {@link ActionInvoker}. */
208
+ export type InvocableActions<A, EntityName extends string = string, EntityType = unknown> = {
209
+ readonly [K in keyof A]: ActionInvoker<A[K], EntityName, K & string, EntityType>;
210
+ };
211
+ /**
212
+ * `entity(…).actions((self) => ({ … }))`: declares the entity's actions next to its definition and
213
+ * returns the entity with `actions` typed as the returned object, so `typeof Lead.actions` carries
214
+ * every action's input and result types.
215
+ *
216
+ * Inside the callback, refer to the entity being defined as `self`, never as the constant it is
217
+ * being assigned to: `self` is the entity without actions, with the same `ref`, `properties` and
218
+ * data access. Naming the constant (`Lead.ref` inside `Lead`'s own actions) is a TypeScript
219
+ * self-reference error, because the constant's type depends on the callback's result. Other
220
+ * entities may be named as usual inside handlers. The callback runs once, when `.actions` is called.
221
+ */
222
+ export interface ActionsBuilder<Name extends string, P extends Properties, R extends Relationships, M extends Metrics = Metrics, W extends EntityWrites = EntityWrites> {
223
+ <const A extends Actions>(define: (self: Entity<Name, P, R, NoActions, M, W>) => A): Entity<Name, P, R, InvocableActions<A, Name, EntityRecord<P, R>>, M, W>;
224
+ }
225
+ /**
226
+ * An entity as `entity()` returns it: no actions yet, and `actions` is the builder that adds them.
227
+ * It has no keys, so it reads as an empty set of actions.
228
+ */
229
+ export type DraftEntity<Name extends string, P extends Properties, R extends Relationships, M extends Metrics = Metrics, W extends EntityWrites = EntityWrites> = Entity<Name, P, R, ActionsBuilder<Name, P, R, M, W>, M, W>;
230
+ /**
231
+ * An entity: its definition, the record type (`typeof Lead.Type`), a reference schema for action
232
+ * inputs (`Lead.ref`), its actions, and data access for action handlers. `M` is the type of its
233
+ * declared metrics, which typed metric query clients read from `definition.metrics`.
234
+ */
235
+ export interface Entity<Name extends string = string, P extends Properties = Properties, R extends Relationships = Relationships, A extends object = NoActions, M extends Metrics = Metrics, W extends EntityWrites = EntityWrites> extends EarlierQueryMetricsName<P, R, M> {
236
+ readonly [EntityTypeId]: typeof EntityTypeId;
237
+ /** The API name and the table name. */
238
+ readonly name: Name;
239
+ readonly definition: EntityDefinition<P, R, M>;
240
+ /**
241
+ * Type-level only: who writes the records, as `definition.writes` declares it, so typed clients
242
+ * leave out the generated writes of an entity that declares `writes: "actions"`.
243
+ */
244
+ readonly "~ontology.writes": W;
245
+ readonly properties: P;
246
+ readonly relationships: R;
247
+ /** The authored actions by name, as declared with `.actions(…)`. */
248
+ readonly actions: A;
249
+ /** Type-level only: the record type, as `typeof Lead.Type`. */
250
+ readonly Type: EntityRecord<P, R>;
251
+ /** A reference to one of this entity's records, by id, for action inputs. */
252
+ readonly ref: Schema.Codec<string>;
253
+ get(record: RecordRef, options?: GetOptions): Effect.Effect<EntityRecord<P, R>, NotFound, OntologyReads>;
254
+ find(options?: FindOptions<EntityRecord<P, R>, LinkKeys<R>>): Effect.Effect<ReadonlyArray<EntityRecord<P, R>>, never, OntologyReads>;
255
+ /**
256
+ * A fresh metric query: computes metrics the entity declares over the records `where` matches,
257
+ * in the action's transaction, so it counts the action's own writes: one row per `groupBy`
258
+ * group, or one row without it. Metrics mean what the warehouse computes, over every record
259
+ * `where` matches. `where` must match an indexed field with `eq` or `in`. It locks nothing: lock
260
+ * the record the decision depends on with `forUpdate`.
261
+ */
262
+ queryMetrics<const Metric extends keyof M & string, const Group extends MetricQueryGroupKey<P, R> = never>(options: FreshMetricQueryInput<P, R, Metric, Group>): Effect.Effect<ReadonlyArray<FreshMetricQueryRow<EntityRecord<P, R>, Group, Metric>>, never, OntologyReads>;
263
+ create(values: CreateValues<P, R>): Effect.Effect<EntityRecord<P, R>, Conflict | NotFound | ScopeViolated, OntologyWrites>;
264
+ update(record: RecordRef, values: UpdateValues<P, R>): Effect.Effect<EntityRecord<P, R>, Conflict | NotFound | ScopeViolated, OntologyWrites>;
265
+ upsertBy(property: UniqueKeys<P>, values: CreateValues<P, R>): Effect.Effect<UpsertResult<EntityRecord<P, R>>, Conflict | NotFound | ScopeViolated, OntologyWrites>;
266
+ /** Atomically create records. Defaults to returning one record result per input, in order. */
267
+ createMany(records: ReadonlyArray<BatchCreateValues<P, R>>, options: {
268
+ readonly returning: "summary";
269
+ }): Effect.Effect<BatchSummaryResult, BatchWriteError, OntologyWrites>;
270
+ createMany(records: ReadonlyArray<BatchCreateValues<P, R>>, options?: {
271
+ readonly returning?: "records";
272
+ }): Effect.Effect<BatchRecordResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
273
+ createMany(records: ReadonlyArray<BatchCreateValues<P, R>>, options?: BatchOptions): Effect.Effect<BatchResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
274
+ /** Atomically patch distinct record IDs; values equal to the locked record remain unchanged. */
275
+ updateMany(records: ReadonlyArray<BatchUpdateRecord<P, R>>, options: {
276
+ readonly returning: "summary";
277
+ }): Effect.Effect<BatchSummaryResult, BatchWriteError, OntologyWrites>;
278
+ updateMany(records: ReadonlyArray<BatchUpdateRecord<P, R>>, options?: {
279
+ readonly returning?: "records";
280
+ }): Effect.Effect<BatchRecordResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
281
+ updateMany(records: ReadonlyArray<BatchUpdateRecord<P, R>>, options?: BatchOptions): Effect.Effect<BatchResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
282
+ /** Atomically insert or patch by a declared unique property or compound unique index. */
283
+ upsertMany<const K extends BatchKey<P>>(input: EntityUpsertManyInput<P, R, K> & {
284
+ readonly returning: "summary";
285
+ }): Effect.Effect<BatchSummaryResult, BatchWriteError, OntologyWrites>;
286
+ upsertMany<const K extends BatchKey<P>>(input: EntityUpsertManyInput<P, R, K> & {
287
+ readonly returning?: "records";
288
+ }): Effect.Effect<BatchRecordResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
289
+ upsertMany<const K extends BatchKey<P>>(input: EntityUpsertManyInput<P, R, K>): Effect.Effect<BatchResult<EntityRecord<P, R>>, BatchWriteError, OntologyWrites>;
290
+ delete(record: RecordRef): Effect.Effect<void, Conflict | NotFound | ScopeViolated, OntologyWrites>;
291
+ link(relationship: ManyKeys<R>, record: RecordRef, target: RecordRef): Effect.Effect<void, NotFound | ScopeViolated, OntologyWrites>;
292
+ unlink(relationship: ManyKeys<R>, record: RecordRef, target: RecordRef): Effect.Effect<void, NotFound | ScopeViolated, OntologyWrites>;
293
+ }
294
+ /**
295
+ * Any entity, whatever its properties, relationships and actions. The built-in `User` is listed on
296
+ * its own: its member writes make it more than an {@link Entity}, which TypeScript then compares
297
+ * member by member.
298
+ */
299
+ export type AnyStoredEntity = Entity<string, any, any, any> | UserHandle<any>;
300
+ export type AnyEntity = AnyStoredEntity | WarehouseBackedEntity<string, any, any, Metrics>;
301
+ interface WarehouseBackedEntity<Name extends string, P extends Properties, R extends Relationships, M extends Metrics> extends EarlierMetricsName<M> {
302
+ readonly [EntityTypeId]: typeof EntityTypeId;
303
+ readonly name: Name;
304
+ readonly definition: EntityDefinition<P, R> & {
305
+ readonly source: WarehouseSource;
306
+ readonly metrics?: M;
307
+ };
308
+ readonly properties: P;
309
+ readonly relationships: R;
310
+ readonly actions: NoActions;
311
+ readonly metrics: M;
312
+ readonly Type: {
313
+ readonly id: string;
314
+ } & {
315
+ readonly [K in keyof P]: ValueOf<P[K]> | null;
316
+ };
317
+ }
318
+ /**
319
+ * Declares an entity. Add its actions with `.actions((self) => ({ … }))`; see {@link ActionsBuilder}.
320
+ * The data access methods delegate to {@link OntologyReads} and {@link OntologyWrites}, which the
321
+ * ontology service provides to actions.
322
+ */
323
+ export declare function entity<const Name extends string, const P extends Properties, const R extends Relationships = NoRelationships, const M extends Metrics = NoMetrics>(name: Name, definition: EntityDefinition<P, R> & {
324
+ readonly source: WarehouseSource;
325
+ readonly metrics?: M;
326
+ } & EarlierMetricsField<M>): WarehouseBackedEntity<Name, P, R, M>;
327
+ export declare function entity<const Name extends string, const P extends Properties, const R extends Relationships = NoRelationships, const M extends Metrics = NoMetrics, const W extends EntityWrites = "generated">(name: Name, definition: EntityDefinition<P, R, M> & {
328
+ readonly writes?: W;
329
+ }): DraftEntity<Name, P, R, M, W>;
330
+ export declare function isEntity(value: unknown): value is AnyEntity;
331
+ export {};
package/dist/entity.js ADDED
@@ -0,0 +1,153 @@
1
+ import { Effect } from "effect";
2
+ import { withCurrentFreshMetricQueryNames, withEarlierQueryMetricsName, withCurrentDefinitionNames, withEarlierMetricsName, } from "./legacy.js";
3
+ import { isAction } from "./action.js";
4
+ import { p } from "./property.js";
5
+ import { metricQueryRowFromWire, metricQueryToWire, recordFromWire, valuesToWire, findToWire, } from "./authoring-records.js";
6
+ import { toSnakeCase } from "./names.js";
7
+ import { OntologyActions, OntologyReads, OntologyWrites, } from "./runtime.js";
8
+ export const EntityTypeId = Symbol.for("@segmentstream/ontology/Entity");
9
+ /**
10
+ * The action, callable: `Lead.actions.addNote(input)` runs it through {@link OntologyActions}. It
11
+ * carries `entity` and `name` as declared; a function's own `name` is read-only, so it is redefined.
12
+ */
13
+ function invocable(entity, name, definition) {
14
+ const invoke = (input, options) => Effect.flatMap(OntologyActions, (actions) => actions.run({
15
+ entity: toSnakeCase(entity),
16
+ action: toSnakeCase(name),
17
+ input,
18
+ ...(options === undefined ? {} : { options }),
19
+ }));
20
+ return Object.defineProperties(Object.assign(invoke, definition), {
21
+ entity: { value: entity },
22
+ name: { value: name },
23
+ });
24
+ }
25
+ function idOf(record) {
26
+ return typeof record === "string" ? record : record.id;
27
+ }
28
+ export function entity(name, definition) {
29
+ // Workspace code written for an earlier SDK may name fields, such as the metrics, by earlier names.
30
+ definition = withCurrentDefinitionNames(definition);
31
+ if (definition.source !== undefined) {
32
+ const metrics = definition.metrics ?? {};
33
+ return {
34
+ [EntityTypeId]: EntityTypeId,
35
+ name,
36
+ definition,
37
+ properties: definition.properties,
38
+ relationships: definition.relationships ?? {},
39
+ actions: {},
40
+ metrics,
41
+ ...withEarlierMetricsName(metrics),
42
+ };
43
+ }
44
+ const batchFromWire = (result) => "items" in result
45
+ ? {
46
+ ...result,
47
+ items: result.items.map((item) => ({
48
+ ...item,
49
+ record: recordFromWire(item.record, definition),
50
+ })),
51
+ }
52
+ : result;
53
+ const createMany = ((records, options) => withWrites((runtime) => runtime.createMany({
54
+ entity: toSnakeCase(name),
55
+ records: records.map((values) => valuesToWire(values, definition)),
56
+ ...(options?.returning === undefined ? {} : { returning: options.returning }),
57
+ })).pipe(Effect.map(batchFromWire)));
58
+ const updateMany = ((records, options) => withWrites((runtime) => runtime.updateMany({
59
+ entity: toSnakeCase(name),
60
+ records: records.map(({ id, values }) => ({
61
+ id,
62
+ values: valuesToWire(values, definition),
63
+ })),
64
+ ...(options?.returning === undefined ? {} : { returning: options.returning }),
65
+ })).pipe(Effect.map(batchFromWire)));
66
+ const upsertMany = ((input) => withWrites((runtime) => runtime.upsertMany({
67
+ entity: toSnakeCase(name),
68
+ on: input.on.map(toSnakeCase),
69
+ records: input.records.map((values) => valuesToWire(values, definition)),
70
+ ...(input.returning === undefined ? {} : { returning: input.returning }),
71
+ })).pipe(Effect.map(batchFromWire)));
72
+ const queryMetrics = ((authored) => Effect.suspend(() => {
73
+ const options = withCurrentFreshMetricQueryNames(authored);
74
+ return withReads((runtime) => runtime.queryMetrics({
75
+ entity: toSnakeCase(name),
76
+ options: metricQueryToWire(options, definition),
77
+ })).pipe(Effect.map((rows) => rows.map((row) => metricQueryRowFromWire(row, options.metrics, definition))));
78
+ }));
79
+ const handle = {
80
+ [EntityTypeId]: EntityTypeId,
81
+ name,
82
+ definition,
83
+ properties: definition.properties,
84
+ relationships: definition.relationships ?? {},
85
+ ref: p.ref(name),
86
+ createMany,
87
+ updateMany,
88
+ upsertMany,
89
+ get: (record, options) => withReads((runtime) => runtime.get({
90
+ entity: toSnakeCase(name),
91
+ id: idOf(record),
92
+ ...(options?.forUpdate === true ? { forUpdate: true } : {}),
93
+ })).pipe(Effect.map((record) => recordFromWire(record, definition))),
94
+ find: (options) => withReads((runtime) => runtime.find({ entity: toSnakeCase(name), options: findToWire(options ?? {}, definition) })).pipe(Effect.map((records) => records.map((record) => recordFromWire(record, definition)))),
95
+ queryMetrics,
96
+ ...withEarlierQueryMetricsName(queryMetrics),
97
+ create: (values) => withWrites((runtime) => runtime.create({ entity: toSnakeCase(name), values: valuesToWire(values, definition) })).pipe(Effect.map((record) => recordFromWire(record, definition))),
98
+ update: (record, values) => withWrites((runtime) => runtime.update({
99
+ entity: toSnakeCase(name),
100
+ id: idOf(record),
101
+ values: valuesToWire(values, definition),
102
+ })).pipe(Effect.map((record) => recordFromWire(record, definition))),
103
+ upsertBy: (property, values) => withWrites((runtime) => runtime.upsertBy({
104
+ entity: toSnakeCase(name),
105
+ property: toSnakeCase(property),
106
+ values: valuesToWire(values, definition),
107
+ })).pipe(Effect.map((result) => ({
108
+ ...result,
109
+ record: recordFromWire(result.record, definition),
110
+ }))),
111
+ delete: (record) => withWrites((runtime) => runtime.delete({ entity: toSnakeCase(name), id: idOf(record) })),
112
+ link: (relationship, record, target) => withWrites((runtime) => runtime.link({
113
+ entity: toSnakeCase(name),
114
+ relationship: toSnakeCase(relationship),
115
+ id: idOf(record),
116
+ targetId: idOf(target),
117
+ })),
118
+ unlink: (relationship, record, target) => withWrites((runtime) => runtime.unlink({
119
+ entity: toSnakeCase(name),
120
+ relationship: toSnakeCase(relationship),
121
+ id: idOf(record),
122
+ targetId: idOf(target),
123
+ })),
124
+ };
125
+ // Every form of the entity shares `definition`, which is how defineOntology recognises them.
126
+ const self = { ...handle, actions: {} };
127
+ const defineActions = (define) => {
128
+ const defined = define(self);
129
+ // A value that is not an object of actions stays as it is, for `check` to report.
130
+ const actions = typeof defined === "object" && defined !== null && !Array.isArray(defined)
131
+ ? Object.fromEntries(Object.entries(defined).map(([key, value]) => [
132
+ key,
133
+ isAction(value) ? invocable(name, key, value) : value,
134
+ ]))
135
+ : defined;
136
+ return { ...handle, actions };
137
+ };
138
+ return { ...handle, actions: defineActions };
139
+ }
140
+ /**
141
+ * Runs one read. The runtime decodes records against the entity's definition, so the result is typed
142
+ * as the entity's records here.
143
+ */
144
+ function withReads(operation) {
145
+ return Effect.flatMap(OntologyReads, operation);
146
+ }
147
+ /** Runs one write, typed as {@link withReads} types a read. */
148
+ function withWrites(operation) {
149
+ return Effect.flatMap(OntologyWrites, operation);
150
+ }
151
+ export function isEntity(value) {
152
+ return typeof value === "object" && value !== null && EntityTypeId in value;
153
+ }
@@ -0,0 +1,154 @@
1
+ import { Schema } from "effect";
2
+ /** Safe batch failure locations: zero-based input indices and wire field names. */
3
+ export declare const BatchErrorDetails: Schema.Struct<{
4
+ readonly indices: Schema.$Array<Schema.Int>;
5
+ readonly fields: Schema.optionalKey<Schema.$Array<Schema.String>>;
6
+ }>;
7
+ export type BatchErrorDetails = typeof BatchErrorDetails.Type;
8
+ /**
9
+ * The platform limit that refused a file upload or attachment, with the numbers a caller needs to
10
+ * explain it in its own words. `usedBytes` counts current and retained historical file revisions,
11
+ * reserved uploads and live agent attachments.
12
+ */
13
+ export declare const LimitErrorDetails: Schema.Union<readonly [Schema.Struct<{
14
+ readonly kind: Schema.Literal<"storage_quota">;
15
+ readonly usedBytes: Schema.Int;
16
+ readonly requestedBytes: Schema.Int;
17
+ readonly quotaBytes: Schema.Int;
18
+ }>, Schema.Struct<{
19
+ readonly kind: Schema.Literal<"pending_uploads">;
20
+ readonly pending: Schema.Int;
21
+ readonly max: Schema.Int;
22
+ /** The caller's open uploads, oldest first, which it can store with their actions or cancel. */
23
+ readonly uploads: Schema.optionalKey<Schema.$Array<Schema.Struct<{
24
+ readonly id: Schema.String;
25
+ readonly filename: Schema.String;
26
+ readonly expiresAt: Schema.String;
27
+ }>>>;
28
+ }>, Schema.Struct<{
29
+ readonly kind: Schema.Literal<"member_attachments">;
30
+ readonly live: Schema.Int;
31
+ readonly max: Schema.Int;
32
+ }>]>;
33
+ export type LimitErrorDetails = typeof LimitErrorDetails.Type;
34
+ declare const ActionRejected_base: Schema.Class<ActionRejected, Schema.TaggedStruct<"ActionRejected", {
35
+ readonly message: Schema.String;
36
+ readonly cause: Schema.optionalKey<Schema.Unknown>;
37
+ readonly batch: Schema.optionalKey<Schema.Struct<{
38
+ readonly indices: Schema.$Array<Schema.Int>;
39
+ readonly fields: Schema.optionalKey<Schema.$Array<Schema.String>>;
40
+ }>>;
41
+ readonly limit: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
42
+ readonly kind: Schema.Literal<"storage_quota">;
43
+ readonly usedBytes: Schema.Int;
44
+ readonly requestedBytes: Schema.Int;
45
+ readonly quotaBytes: Schema.Int;
46
+ }>, Schema.Struct<{
47
+ readonly kind: Schema.Literal<"pending_uploads">;
48
+ readonly pending: Schema.Int;
49
+ readonly max: Schema.Int;
50
+ /** The caller's open uploads, oldest first, which it can store with their actions or cancel. */
51
+ readonly uploads: Schema.optionalKey<Schema.$Array<Schema.Struct<{
52
+ readonly id: Schema.String;
53
+ readonly filename: Schema.String;
54
+ readonly expiresAt: Schema.String;
55
+ }>>>;
56
+ }>, Schema.Struct<{
57
+ readonly kind: Schema.Literal<"member_attachments">;
58
+ readonly live: Schema.Int;
59
+ readonly max: Schema.Int;
60
+ }>]>>;
61
+ }>, import("effect/Cause").YieldableError>;
62
+ /**
63
+ * An action refused the request for a business reason. The message is written for the caller and is
64
+ * returned to them.
65
+ */
66
+ export declare class ActionRejected extends ActionRejected_base {
67
+ }
68
+ declare const PermissionDenied_base: Schema.Class<PermissionDenied, Schema.TaggedStruct<"PermissionDenied", {
69
+ readonly message: Schema.String;
70
+ /** The permission that is missing, for example `lead:changeStatus`. */
71
+ readonly permission: Schema.optionalKey<Schema.String>;
72
+ /**
73
+ * Refused only because the running ontology and the database catalog differ, as while a
74
+ * deployment migrates. The caller retries the same request.
75
+ */
76
+ readonly updating: Schema.optionalKey<Schema.Literal<true>>;
77
+ }>, import("effect/Cause").YieldableError>;
78
+ /**
79
+ * The principal's roles do not grant a permission the request requires. The service answers 403
80
+ * with `<permission> is required.`; the message stays in the logs.
81
+ */
82
+ export declare class PermissionDenied extends PermissionDenied_base {
83
+ }
84
+ declare const DeploymentSwitching_base: Schema.Class<DeploymentSwitching, Schema.TaggedStruct<"DeploymentSwitching", {
85
+ readonly message: Schema.String;
86
+ readonly retryAfter: Schema.Number;
87
+ readonly generation: Schema.optionalKey<Schema.String>;
88
+ }>, import("effect/Cause").YieldableError>;
89
+ /**
90
+ * A bounded deployment transition, which ontology SDKs 0.86.0 to 0.88.0 raised while their deploy
91
+ * guard paused workflow starts. Nothing raises it now; it is kept to read their recorded failures.
92
+ */
93
+ export declare class DeploymentSwitching extends DeploymentSwitching_base {
94
+ }
95
+ declare const DeploymentInterrupted_base: Schema.Class<DeploymentInterrupted, Schema.TaggedStruct<"DeploymentInterrupted", {
96
+ readonly message: Schema.String;
97
+ readonly servedHash: Schema.String;
98
+ readonly appliedHash: Schema.optionalKey<Schema.String>;
99
+ readonly servedDeploymentId: Schema.optionalKey<Schema.String>;
100
+ readonly appliedDeploymentId: Schema.optionalKey<Schema.String>;
101
+ }>, import("effect/Cause").YieldableError>;
102
+ /** This deployment cannot safely execute against the applied catalog. Retrying cannot repair it. */
103
+ export declare class DeploymentInterrupted extends DeploymentInterrupted_base {
104
+ }
105
+ declare const Conflict_base: Schema.Class<Conflict, Schema.TaggedStruct<"Conflict", {
106
+ readonly entity: Schema.String;
107
+ readonly message: Schema.String;
108
+ readonly property: Schema.optionalKey<Schema.String>;
109
+ /**
110
+ * Seconds until the same request may succeed, set while another attempt holds the record, such
111
+ * as an upload whose storage call failed mid-flight.
112
+ */
113
+ readonly retryAfter: Schema.optionalKey<Schema.Int>;
114
+ readonly batch: Schema.optionalKey<Schema.Struct<{
115
+ readonly indices: Schema.$Array<Schema.Int>;
116
+ readonly fields: Schema.optionalKey<Schema.$Array<Schema.String>>;
117
+ }>>;
118
+ }>, import("effect/Cause").YieldableError>;
119
+ /** The write conflicts with existing data, for example a duplicate value of a unique property. */
120
+ export declare class Conflict extends Conflict_base {
121
+ }
122
+ declare const NotFound_base: Schema.Class<NotFound, Schema.TaggedStruct<"NotFound", {
123
+ readonly entity: Schema.String;
124
+ readonly id: Schema.String;
125
+ readonly message: Schema.String;
126
+ readonly batch: Schema.optionalKey<Schema.Struct<{
127
+ readonly indices: Schema.$Array<Schema.Int>;
128
+ readonly fields: Schema.optionalKey<Schema.$Array<Schema.String>>;
129
+ }>>;
130
+ }>, import("effect/Cause").YieldableError>;
131
+ /** The record does not exist. */
132
+ export declare class NotFound extends NotFound_base {
133
+ }
134
+ declare const ScopeViolated_base: Schema.Class<ScopeViolated, Schema.TaggedStruct<"ScopeViolated", {
135
+ readonly entity: Schema.String;
136
+ readonly id: Schema.optionalKey<Schema.String>;
137
+ /** The scoped permission, for example `staff_member:update`. */
138
+ readonly permission: Schema.String;
139
+ readonly message: Schema.String;
140
+ readonly batch: Schema.optionalKey<Schema.Struct<{
141
+ readonly indices: Schema.$Array<Schema.Int>;
142
+ readonly fields: Schema.optionalKey<Schema.$Array<Schema.String>>;
143
+ }>>;
144
+ }>, import("effect/Cause").YieldableError>;
145
+ /**
146
+ * A write would leave a record outside the scope of the permission that allowed it: the record
147
+ * matched the role's `where` before the change and does not after it. The service answers 403 with
148
+ * the entity and the permission; the scope's `where` and the values stay out of the response.
149
+ */
150
+ export declare class ScopeViolated extends ScopeViolated_base {
151
+ }
152
+ /** The failures an action handler may produce. */
153
+ export type ActionError = ActionRejected | PermissionDenied | DeploymentSwitching | DeploymentInterrupted | Conflict | NotFound | ScopeViolated;
154
+ export {};