@segmentstream/ontology 0.0.0-stage → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (483) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +2 -0
  3. package/README.md +1655 -2
  4. package/dist/action.d.ts +193 -0
  5. package/dist/action.js +41 -0
  6. package/dist/agent-chat.d.ts +44 -0
  7. package/dist/agent-chat.js +91 -0
  8. package/dist/agent-task-contract.d.ts +64 -0
  9. package/dist/agent-task-contract.js +15 -0
  10. package/dist/agent-task.d.ts +39 -0
  11. package/dist/agent-task.js +112 -0
  12. package/dist/analyze.d.ts +215 -0
  13. package/dist/analyze.js +2438 -0
  14. package/dist/app-feedback.d.ts +167 -0
  15. package/dist/app-feedback.js +176 -0
  16. package/dist/authoring-input.d.ts +3 -0
  17. package/dist/authoring-input.js +107 -0
  18. package/dist/authoring-names.d.ts +4 -0
  19. package/dist/authoring-names.js +13 -0
  20. package/dist/authoring-records.d.ts +35 -0
  21. package/dist/authoring-records.js +264 -0
  22. package/dist/authoring.d.ts +15 -0
  23. package/dist/authoring.js +331 -0
  24. package/dist/bin/check.d.ts +30 -0
  25. package/dist/bin/check.js +99 -0
  26. package/dist/bin/load.d.ts +48 -0
  27. package/dist/bin/load.js +139 -0
  28. package/dist/bin/main.d.ts +31 -0
  29. package/dist/bin/main.js +121 -0
  30. package/dist/bin/migrate.d.ts +57 -0
  31. package/dist/bin/migrate.js +170 -0
  32. package/dist/bin/output.d.ts +31 -0
  33. package/dist/bin/output.js +84 -0
  34. package/dist/bin.d.ts +2 -0
  35. package/dist/bin.js +31 -0
  36. package/dist/blob.d.ts +52 -0
  37. package/dist/blob.js +87 -0
  38. package/dist/channel-session.d.ts +16 -0
  39. package/dist/channel-session.js +16 -0
  40. package/dist/chat.d.ts +43 -0
  41. package/dist/chat.js +34 -0
  42. package/dist/confirmation.d.ts +46 -0
  43. package/dist/confirmation.js +41 -0
  44. package/dist/connection.d.ts +213 -0
  45. package/dist/connection.js +289 -0
  46. package/dist/deployment.d.ts +35 -0
  47. package/dist/deployment.js +76 -0
  48. package/dist/diagnostics.d.ts +27 -0
  49. package/dist/diagnostics.js +106 -0
  50. package/dist/emails.d.ts +70 -0
  51. package/dist/emails.js +221 -0
  52. package/dist/entity.d.ts +331 -0
  53. package/dist/entity.js +153 -0
  54. package/dist/errors.d.ts +154 -0
  55. package/dist/errors.js +109 -0
  56. package/dist/feedback-config.d.ts +24 -0
  57. package/dist/feedback-config.js +126 -0
  58. package/dist/files.d.ts +39 -0
  59. package/dist/files.js +4 -0
  60. package/dist/groups.d.ts +95 -0
  61. package/dist/groups.js +280 -0
  62. package/dist/index.d.ts +109 -0
  63. package/dist/index.js +70 -0
  64. package/dist/internal/diagnostics.js +594 -0
  65. package/dist/legacy.d.ts +160 -0
  66. package/dist/legacy.js +270 -0
  67. package/dist/manifest-compatibility.d.ts +8 -0
  68. package/dist/manifest-compatibility.js +87 -0
  69. package/dist/manifest.d.ts +3329 -0
  70. package/dist/manifest.js +757 -0
  71. package/dist/me.d.ts +46 -0
  72. package/dist/me.js +109 -0
  73. package/dist/metric-filters.d.ts +48 -0
  74. package/dist/metric-filters.js +252 -0
  75. package/dist/metric-routes.d.ts +132 -0
  76. package/dist/metric-routes.js +498 -0
  77. package/dist/metric.d.ts +172 -0
  78. package/dist/metric.js +132 -0
  79. package/dist/migrate/apply.d.ts +94 -0
  80. package/dist/migrate/apply.js +526 -0
  81. package/dist/migrate/errors.d.ts +46 -0
  82. package/dist/migrate/errors.js +38 -0
  83. package/dist/migrate/index.d.ts +10 -0
  84. package/dist/migrate/index.js +7 -0
  85. package/dist/migrate/model.d.ts +2311 -0
  86. package/dist/migrate/model.js +148 -0
  87. package/dist/migrate/plan.d.ts +51 -0
  88. package/dist/migrate/plan.js +1856 -0
  89. package/dist/migrate/preview.d.ts +13 -0
  90. package/dist/migrate/preview.js +65 -0
  91. package/dist/migrate/storage.d.ts +226 -0
  92. package/dist/migrate/storage.js +774 -0
  93. package/dist/model-metrics.d.ts +22 -0
  94. package/dist/model-metrics.js +545 -0
  95. package/dist/names.d.ts +49 -0
  96. package/dist/names.js +110 -0
  97. package/dist/navigation-artifact.d.ts +13 -0
  98. package/dist/navigation-artifact.js +11 -0
  99. package/dist/navigation-catalog.d.ts +55 -0
  100. package/dist/navigation-catalog.js +297 -0
  101. package/dist/nitro-navigation.d.ts +3 -0
  102. package/dist/nitro-navigation.js +64 -0
  103. package/dist/nitro-workflows.d.ts +108 -0
  104. package/dist/nitro-workflows.js +286 -0
  105. package/dist/nitro.d.ts +40 -0
  106. package/dist/nitro.js +50 -0
  107. package/dist/ontology.d.ts +41 -0
  108. package/dist/ontology.js +46 -0
  109. package/dist/permissions.d.ts +198 -0
  110. package/dist/permissions.js +272 -0
  111. package/dist/property.d.ts +188 -0
  112. package/dist/property.js +301 -0
  113. package/dist/query.d.ts +245 -0
  114. package/dist/query.js +615 -0
  115. package/dist/relationship.d.ts +99 -0
  116. package/dist/relationship.js +33 -0
  117. package/dist/render.d.ts +81 -0
  118. package/dist/render.js +512 -0
  119. package/dist/replication/baseline.d.ts +51 -0
  120. package/dist/replication/baseline.js +215 -0
  121. package/dist/replication/bigquery.d.ts +37 -0
  122. package/dist/replication/bigquery.js +211 -0
  123. package/dist/replication/coverage.d.ts +14 -0
  124. package/dist/replication/coverage.js +53 -0
  125. package/dist/replication/evolution.d.ts +25 -0
  126. package/dist/replication/evolution.js +184 -0
  127. package/dist/replication/identities.d.ts +6 -0
  128. package/dist/replication/identities.js +47 -0
  129. package/dist/replication/legacy-baseline.d.ts +27 -0
  130. package/dist/replication/legacy-baseline.js +109 -0
  131. package/dist/replication/legacy-store.d.ts +19 -0
  132. package/dist/replication/legacy-store.js +63 -0
  133. package/dist/replication/lineage.d.ts +36 -0
  134. package/dist/replication/lineage.js +72 -0
  135. package/dist/replication/migrate.d.ts +21 -0
  136. package/dist/replication/migrate.js +84 -0
  137. package/dist/replication/model.d.ts +52 -0
  138. package/dist/replication/model.js +99 -0
  139. package/dist/replication/scans.d.ts +34 -0
  140. package/dist/replication/scans.js +158 -0
  141. package/dist/replication/schema.d.ts +11 -0
  142. package/dist/replication/schema.js +226 -0
  143. package/dist/replication/shadow-schema.d.ts +4 -0
  144. package/dist/replication/shadow-schema.js +61 -0
  145. package/dist/replication/shadow.d.ts +127 -0
  146. package/dist/replication/shadow.js +614 -0
  147. package/dist/replication/source-replacement.d.ts +33 -0
  148. package/dist/replication/source-replacement.js +76 -0
  149. package/dist/replication/store.d.ts +36 -0
  150. package/dist/replication/store.js +382 -0
  151. package/dist/replication/transaction.d.ts +23 -0
  152. package/dist/replication/transaction.js +88 -0
  153. package/dist/role.d.ts +61 -0
  154. package/dist/role.js +76 -0
  155. package/dist/runtime/action-deadlocks.d.ts +21 -0
  156. package/dist/runtime/action-deadlocks.js +130 -0
  157. package/dist/runtime/action-transactions.d.ts +35 -0
  158. package/dist/runtime/action-transactions.js +54 -0
  159. package/dist/runtime/agent-counters.d.ts +26 -0
  160. package/dist/runtime/agent-counters.js +98 -0
  161. package/dist/runtime/agent-tasks.d.ts +63 -0
  162. package/dist/runtime/agent-tasks.js +120 -0
  163. package/dist/runtime/agents.d.ts +15 -0
  164. package/dist/runtime/agents.js +457 -0
  165. package/dist/runtime/batch-diagnostics.d.ts +22 -0
  166. package/dist/runtime/batch-diagnostics.js +89 -0
  167. package/dist/runtime/batch.d.ts +52 -0
  168. package/dist/runtime/batch.js +534 -0
  169. package/dist/runtime/channel-session-revocation.d.ts +3 -0
  170. package/dist/runtime/channel-session-revocation.js +5 -0
  171. package/dist/runtime/channel-sessions.d.ts +4 -0
  172. package/dist/runtime/channel-sessions.js +61 -0
  173. package/dist/runtime/confirmations.d.ts +29 -0
  174. package/dist/runtime/confirmations.js +57 -0
  175. package/dist/runtime/cursor.d.ts +23 -0
  176. package/dist/runtime/cursor.js +100 -0
  177. package/dist/runtime/deployment.d.ts +7 -0
  178. package/dist/runtime/deployment.js +4 -0
  179. package/dist/runtime/errors.d.ts +118 -0
  180. package/dist/runtime/errors.js +109 -0
  181. package/dist/runtime/federation-tables.d.ts +2 -0
  182. package/dist/runtime/federation-tables.js +20 -0
  183. package/dist/runtime/federation.d.ts +42 -0
  184. package/dist/runtime/federation.js +222 -0
  185. package/dist/runtime/files.d.ts +39 -0
  186. package/dist/runtime/files.js +44 -0
  187. package/dist/runtime/generated-actions.d.ts +37 -0
  188. package/dist/runtime/generated-actions.js +307 -0
  189. package/dist/runtime/history.d.ts +91 -0
  190. package/dist/runtime/history.js +77 -0
  191. package/dist/runtime/ids.d.ts +6 -0
  192. package/dist/runtime/ids.js +39 -0
  193. package/dist/runtime/member-tables.d.ts +8 -0
  194. package/dist/runtime/member-tables.js +33 -0
  195. package/dist/runtime/member-writes.d.ts +78 -0
  196. package/dist/runtime/member-writes.js +202 -0
  197. package/dist/runtime/metric-query.d.ts +19 -0
  198. package/dist/runtime/metric-query.js +411 -0
  199. package/dist/runtime/model.d.ts +67 -0
  200. package/dist/runtime/model.js +150 -0
  201. package/dist/runtime/new-user-hook.d.ts +6 -0
  202. package/dist/runtime/new-user-hook.js +37 -0
  203. package/dist/runtime/oauth.d.ts +9 -0
  204. package/dist/runtime/oauth.js +299 -0
  205. package/dist/runtime/pipeline.d.ts +155 -0
  206. package/dist/runtime/pipeline.js +597 -0
  207. package/dist/runtime/postgres-tls.d.ts +10 -0
  208. package/dist/runtime/postgres-tls.js +14 -0
  209. package/dist/runtime/principals.d.ts +302 -0
  210. package/dist/runtime/principals.js +1307 -0
  211. package/dist/runtime/reads.d.ts +55 -0
  212. package/dist/runtime/reads.js +313 -0
  213. package/dist/runtime/records.d.ts +42 -0
  214. package/dist/runtime/records.js +245 -0
  215. package/dist/runtime/resolve-agent-identity.d.ts +6 -0
  216. package/dist/runtime/resolve-agent-identity.js +181 -0
  217. package/dist/runtime/service-binding.d.ts +18 -0
  218. package/dist/runtime/service-binding.js +266 -0
  219. package/dist/runtime/sign-in-links.d.ts +68 -0
  220. package/dist/runtime/sign-in-links.js +147 -0
  221. package/dist/runtime/sql-runtime.d.ts +131 -0
  222. package/dist/runtime/sql-runtime.js +362 -0
  223. package/dist/runtime/statement.d.ts +18 -0
  224. package/dist/runtime/statement.js +31 -0
  225. package/dist/runtime/user-identities.d.ts +66 -0
  226. package/dist/runtime/user-identities.js +106 -0
  227. package/dist/runtime/user-identity-sql.d.ts +86 -0
  228. package/dist/runtime/user-identity-sql.js +297 -0
  229. package/dist/runtime/user-roles.d.ts +16 -0
  230. package/dist/runtime/user-roles.js +32 -0
  231. package/dist/runtime/validation.d.ts +16 -0
  232. package/dist/runtime/validation.js +26 -0
  233. package/dist/runtime/where.d.ts +57 -0
  234. package/dist/runtime/where.js +404 -0
  235. package/dist/runtime/workflow-admission.d.ts +49 -0
  236. package/dist/runtime/workflow-admission.js +92 -0
  237. package/dist/runtime/workflow-argument-codec.d.ts +10 -0
  238. package/dist/runtime/workflow-argument-codec.js +120 -0
  239. package/dist/runtime/workflow-arguments.d.ts +17 -0
  240. package/dist/runtime/workflow-arguments.js +99 -0
  241. package/dist/runtime/workflow-starts.d.ts +203 -0
  242. package/dist/runtime/workflow-starts.js +493 -0
  243. package/dist/runtime/workflow-users.d.ts +9 -0
  244. package/dist/runtime/workflow-users.js +17 -0
  245. package/dist/runtime/workload.d.ts +25 -0
  246. package/dist/runtime/workload.js +24 -0
  247. package/dist/runtime/writes.d.ts +108 -0
  248. package/dist/runtime/writes.js +491 -0
  249. package/dist/runtime-source.d.ts +22 -0
  250. package/dist/runtime-source.js +28 -0
  251. package/dist/runtime.d.ts +310 -0
  252. package/dist/runtime.js +31 -0
  253. package/dist/server.d.ts +23 -0
  254. package/dist/server.js +107 -0
  255. package/dist/service/agent/attachments.d.ts +33 -0
  256. package/dist/service/agent/attachments.js +228 -0
  257. package/dist/service/agent/authentication.d.ts +22 -0
  258. package/dist/service/agent/authentication.js +58 -0
  259. package/dist/service/agent/confirmations.d.ts +5 -0
  260. package/dist/service/agent/confirmations.js +73 -0
  261. package/dist/service/agent/conversation-routes.d.ts +14 -0
  262. package/dist/service/agent/conversation-routes.js +45 -0
  263. package/dist/service/agent/conversations.d.ts +40 -0
  264. package/dist/service/agent/conversations.js +69 -0
  265. package/dist/service/agent/files.d.ts +12 -0
  266. package/dist/service/agent/files.js +69 -0
  267. package/dist/service/agent/protocol.d.ts +90 -0
  268. package/dist/service/agent/protocol.js +114 -0
  269. package/dist/service/agent/server.d.ts +28 -0
  270. package/dist/service/agent/server.js +374 -0
  271. package/dist/service/agent/task-caller.d.ts +21 -0
  272. package/dist/service/agent/task-caller.js +35 -0
  273. package/dist/service/agent/task-start.d.ts +53 -0
  274. package/dist/service/agent/task-start.js +161 -0
  275. package/dist/service/agent/tasks.d.ts +40 -0
  276. package/dist/service/agent/tasks.js +155 -0
  277. package/dist/service/api.d.ts +50 -0
  278. package/dist/service/api.js +288 -0
  279. package/dist/service/authentication.d.ts +227 -0
  280. package/dist/service/authentication.js +767 -0
  281. package/dist/service/caller-context.d.ts +24 -0
  282. package/dist/service/caller-context.js +6 -0
  283. package/dist/service/catalog.d.ts +42 -0
  284. package/dist/service/catalog.js +66 -0
  285. package/dist/service/channel/provider.d.ts +10 -0
  286. package/dist/service/channel/provider.js +1 -0
  287. package/dist/service/channel/providers/telegram.d.ts +18 -0
  288. package/dist/service/channel/providers/telegram.js +108 -0
  289. package/dist/service/channel/sessions.d.ts +5 -0
  290. package/dist/service/channel/sessions.js +53 -0
  291. package/dist/service/channel/sign-in.d.ts +7 -0
  292. package/dist/service/channel/sign-in.js +78 -0
  293. package/dist/service/chat/archive.d.ts +64 -0
  294. package/dist/service/chat/archive.js +62 -0
  295. package/dist/service/chat/attribution.d.ts +26 -0
  296. package/dist/service/chat/attribution.js +28 -0
  297. package/dist/service/chat/delivery.d.ts +18 -0
  298. package/dist/service/chat/delivery.js +251 -0
  299. package/dist/service/chat/diagnostics.d.ts +2 -0
  300. package/dist/service/chat/diagnostics.js +35 -0
  301. package/dist/service/chat/envelope.d.ts +96 -0
  302. package/dist/service/chat/envelope.js +39 -0
  303. package/dist/service/chat/idempotency.d.ts +19 -0
  304. package/dist/service/chat/idempotency.js +37 -0
  305. package/dist/service/chat/providers/telegram.d.ts +36 -0
  306. package/dist/service/chat/providers/telegram.js +133 -0
  307. package/dist/service/chat/reads.d.ts +25 -0
  308. package/dist/service/chat/reads.js +75 -0
  309. package/dist/service/chat/resolve.d.ts +34 -0
  310. package/dist/service/chat/resolve.js +150 -0
  311. package/dist/service/chat/routes.d.ts +23 -0
  312. package/dist/service/chat/routes.js +75 -0
  313. package/dist/service/chat/schemas.d.ts +43 -0
  314. package/dist/service/chat/schemas.js +31 -0
  315. package/dist/service/config.d.ts +218 -0
  316. package/dist/service/config.js +265 -0
  317. package/dist/service/connection-stream.d.ts +10 -0
  318. package/dist/service/connection-stream.js +191 -0
  319. package/dist/service/connections.d.ts +60 -0
  320. package/dist/service/connections.js +271 -0
  321. package/dist/service/decisions.d.ts +35 -0
  322. package/dist/service/decisions.js +63 -0
  323. package/dist/service/descriptions.d.ts +8 -0
  324. package/dist/service/descriptions.js +20 -0
  325. package/dist/service/discovery-schemas.d.ts +92 -0
  326. package/dist/service/discovery-schemas.js +59 -0
  327. package/dist/service/discovery-search.d.ts +30 -0
  328. package/dist/service/discovery-search.js +95 -0
  329. package/dist/service/discovery.d.ts +37 -0
  330. package/dist/service/discovery.js +436 -0
  331. package/dist/service/docs.d.ts +9 -0
  332. package/dist/service/docs.js +197 -0
  333. package/dist/service/errors.d.ts +145 -0
  334. package/dist/service/errors.js +704 -0
  335. package/dist/service/federation-provider.d.ts +36 -0
  336. package/dist/service/federation-provider.js +110 -0
  337. package/dist/service/federation-server.d.ts +20 -0
  338. package/dist/service/federation-server.js +249 -0
  339. package/dist/service/federation-status.d.ts +40 -0
  340. package/dist/service/federation-status.js +151 -0
  341. package/dist/service/handlers.d.ts +18 -0
  342. package/dist/service/handlers.js +287 -0
  343. package/dist/service/mcp/confirmation.d.ts +68 -0
  344. package/dist/service/mcp/confirmation.js +178 -0
  345. package/dist/service/mcp/find-input.d.ts +12 -0
  346. package/dist/service/mcp/find-input.js +122 -0
  347. package/dist/service/mcp/input-schema.d.ts +6 -0
  348. package/dist/service/mcp/input-schema.js +126 -0
  349. package/dist/service/mcp/listing.d.ts +26 -0
  350. package/dist/service/mcp/listing.js +92 -0
  351. package/dist/service/mcp/metric-tools.d.ts +85 -0
  352. package/dist/service/mcp/metric-tools.js +258 -0
  353. package/dist/service/mcp/request-log.d.ts +5 -0
  354. package/dist/service/mcp/request-log.js +53 -0
  355. package/dist/service/mcp/runtime-policy.d.ts +27 -0
  356. package/dist/service/mcp/runtime-policy.js +62 -0
  357. package/dist/service/mcp/server.d.ts +52 -0
  358. package/dist/service/mcp/server.js +861 -0
  359. package/dist/service/mcp/tools.d.ts +99 -0
  360. package/dist/service/mcp/tools.js +938 -0
  361. package/dist/service/member-file-routes.d.ts +22 -0
  362. package/dist/service/member-file-routes.js +52 -0
  363. package/dist/service/member-files.d.ts +245 -0
  364. package/dist/service/member-files.js +258 -0
  365. package/dist/service/metric-query-platform.d.ts +77 -0
  366. package/dist/service/metric-query-platform.js +198 -0
  367. package/dist/service/metric-query-scopes.d.ts +43 -0
  368. package/dist/service/metric-query-scopes.js +147 -0
  369. package/dist/service/metric-query.d.ts +48 -0
  370. package/dist/service/metric-query.js +200 -0
  371. package/dist/service/name-suggestions.d.ts +3 -0
  372. package/dist/service/name-suggestions.js +38 -0
  373. package/dist/service/navigation-schemas.d.ts +80 -0
  374. package/dist/service/navigation-schemas.js +49 -0
  375. package/dist/service/navigation.d.ts +20 -0
  376. package/dist/service/navigation.js +165 -0
  377. package/dist/service/oauth/protocol.d.ts +70 -0
  378. package/dist/service/oauth/protocol.js +157 -0
  379. package/dist/service/oauth/refresh-replay.d.ts +2 -0
  380. package/dist/service/oauth/refresh-replay.js +20 -0
  381. package/dist/service/oauth/server.d.ts +28 -0
  382. package/dist/service/oauth/server.js +769 -0
  383. package/dist/service/operations.d.ts +170 -0
  384. package/dist/service/operations.js +392 -0
  385. package/dist/service/plan.d.ts +57 -0
  386. package/dist/service/plan.js +96 -0
  387. package/dist/service/rate-limit.d.ts +22 -0
  388. package/dist/service/rate-limit.js +52 -0
  389. package/dist/service/record-reads.d.ts +21 -0
  390. package/dist/service/record-reads.js +155 -0
  391. package/dist/service/replication.d.ts +5 -0
  392. package/dist/service/replication.js +39 -0
  393. package/dist/service/runtime-contract.d.ts +508 -0
  394. package/dist/service/runtime-contract.js +18 -0
  395. package/dist/service/runtime-identity.d.ts +71 -0
  396. package/dist/service/runtime-identity.js +122 -0
  397. package/dist/service/schemas.d.ts +961 -0
  398. package/dist/service/schemas.js +639 -0
  399. package/dist/service/service.d.ts +21 -0
  400. package/dist/service/service.js +526 -0
  401. package/dist/service/warehouse-platform.d.ts +17 -0
  402. package/dist/service/warehouse-platform.js +122 -0
  403. package/dist/service/warehouse-query.d.ts +24 -0
  404. package/dist/service/warehouse-query.js +280 -0
  405. package/dist/service/webhooks.d.ts +106 -0
  406. package/dist/service/webhooks.js +233 -0
  407. package/dist/service/workflow-admission-provider.d.ts +31 -0
  408. package/dist/service/workflow-admission-provider.js +205 -0
  409. package/dist/service/workflow-argument-serialization.d.ts +2 -0
  410. package/dist/service/workflow-argument-serialization.js +14 -0
  411. package/dist/service/workflow-callback.d.ts +22 -0
  412. package/dist/service/workflow-callback.js +75 -0
  413. package/dist/service/workflow-deployment.d.ts +8 -0
  414. package/dist/service/workflow-deployment.js +131 -0
  415. package/dist/service/workflow-diagnostics.d.ts +23 -0
  416. package/dist/service/workflow-diagnostics.js +263 -0
  417. package/dist/service/workflow-errors.d.ts +26 -0
  418. package/dist/service/workflow-errors.js +181 -0
  419. package/dist/service/workflow-logging.d.ts +2 -0
  420. package/dist/service/workflow-logging.js +50 -0
  421. package/dist/service/workflow-queue-fence.d.ts +6 -0
  422. package/dist/service/workflow-queue-fence.js +66 -0
  423. package/dist/service/workflows.d.ts +200 -0
  424. package/dist/service/workflows.js +1549 -0
  425. package/dist/sign-in.d.ts +58 -0
  426. package/dist/sign-in.js +57 -0
  427. package/dist/source.d.ts +30 -0
  428. package/dist/source.js +107 -0
  429. package/dist/start-recovery-contract.d.ts +49 -0
  430. package/dist/start-recovery-contract.js +26 -0
  431. package/dist/start-recovery.d.ts +27 -0
  432. package/dist/start-recovery.js +81 -0
  433. package/dist/storage/api.d.ts +4 -0
  434. package/dist/storage/api.js +40 -0
  435. package/dist/storage/attachments.d.ts +146 -0
  436. package/dist/storage/attachments.js +733 -0
  437. package/dist/storage/authorization.d.ts +38 -0
  438. package/dist/storage/authorization.js +83 -0
  439. package/dist/storage/file-access.d.ts +17 -0
  440. package/dist/storage/file-access.js +8 -0
  441. package/dist/storage/limits.d.ts +12 -0
  442. package/dist/storage/limits.js +17 -0
  443. package/dist/storage/maintenance-auth.d.ts +20 -0
  444. package/dist/storage/maintenance-auth.js +24 -0
  445. package/dist/storage/maintenance.d.ts +11 -0
  446. package/dist/storage/maintenance.js +67 -0
  447. package/dist/storage/neon.d.ts +4 -0
  448. package/dist/storage/neon.js +318 -0
  449. package/dist/storage/operator.d.ts +11 -0
  450. package/dist/storage/operator.js +30 -0
  451. package/dist/storage/provider.d.ts +93 -0
  452. package/dist/storage/provider.js +36 -0
  453. package/dist/storage/sessions.d.ts +184 -0
  454. package/dist/storage/sessions.js +688 -0
  455. package/dist/storage/tables.d.ts +54 -0
  456. package/dist/storage/tables.js +205 -0
  457. package/dist/storage/transfers.d.ts +16 -0
  458. package/dist/storage/transfers.js +153 -0
  459. package/dist/storage/writes.d.ts +7 -0
  460. package/dist/storage/writes.js +88 -0
  461. package/dist/telegram.d.ts +35 -0
  462. package/dist/telegram.js +173 -0
  463. package/dist/user-identity.d.ts +28 -0
  464. package/dist/user-identity.js +106 -0
  465. package/dist/user.d.ts +75 -0
  466. package/dist/user.js +111 -0
  467. package/dist/warehouse-backed.d.ts +6 -0
  468. package/dist/warehouse-backed.js +495 -0
  469. package/dist/webhook-token.d.ts +11 -0
  470. package/dist/webhook-token.js +18 -0
  471. package/dist/webhooks.d.ts +40 -0
  472. package/dist/webhooks.js +55 -0
  473. package/dist/wire.d.ts +10 -0
  474. package/dist/wire.js +35 -0
  475. package/dist/workflow-runtime.d.ts +116 -0
  476. package/dist/workflow-runtime.js +109 -0
  477. package/dist/workflow-topics.d.ts +28 -0
  478. package/dist/workflow-topics.js +28 -0
  479. package/dist/workflow.d.ts +284 -0
  480. package/dist/workflow.js +259 -0
  481. package/dist/workflows.d.ts +24 -0
  482. package/dist/workflows.js +18 -0
  483. package/package.json +127 -4
@@ -0,0 +1,498 @@
1
+ import { User } from "./user.js";
2
+ /** A route follows at most this many to-one relationships. */
3
+ export const MAXIMUM_HOPS = 2;
4
+ const SEPARATOR = ".";
5
+ const COUNT_WORDS = ["no", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
6
+ /**
7
+ * The JSON Schema pattern of a metric query's name: `entity.member`, or a route of at most
8
+ * {@link MAXIMUM_HOPS} relationships from a metric entity, in snake_case segments.
9
+ */
10
+ export const METRIC_QUERY_NAME_PATTERN = `^[a-z][a-z0-9_]*(?:\\.[a-z][a-z0-9_]*){1,${MAXIMUM_HOPS + 1}}$`;
11
+ /** The built-in User is never replicated, so no route passes through it or ends at it. */
12
+ export function isBuiltInUser(entity) {
13
+ return entity === User.name;
14
+ }
15
+ // The refusals that route resolution shares with backend-next's planner, word for word.
16
+ export function hopLimitMessage() {
17
+ return `A path follows at most ${COUNT_WORDS[MAXIMUM_HOPS]} relationships.`;
18
+ }
19
+ export function userPathMessage() {
20
+ return "Paths cannot follow relationships to User.";
21
+ }
22
+ export function unknownRelationshipMessage(input) {
23
+ return `${input.entity} has no relationship ${input.relationship}.`;
24
+ }
25
+ /** A `rel.many`, or an inverse, which is to-many from the side that names it. */
26
+ export function toManySegmentMessage(input) {
27
+ return `${input.relationship} is not a to-one relationship of ${input.entity}.`;
28
+ }
29
+ export function unknownPropertyMessage(input) {
30
+ return `${input.entity} has no property ${input.property}.`;
31
+ }
32
+ /** A bare metric name that is not a metric of the model. */
33
+ export function unknownModelMetricMessage(name) {
34
+ return `The ontology has no metric named ${name}.`;
35
+ }
36
+ /** A filter that applies to some entities a model metric reads and cannot reach another. */
37
+ export function partialFilterMessage(input) {
38
+ return (`${input.filter} does not apply to ${input.entity}, which ${input.metric} reads; align the ` +
39
+ "properties in the metric, or request its inputs instead.");
40
+ }
41
+ function entitiesByName(manifest) {
42
+ return new Map(manifest.entities.map((entity) => [entity.name, entity]));
43
+ }
44
+ /**
45
+ * The relationships a route may follow from an entity: its declared `rel.one`s, never an inverse,
46
+ * to entities of the manifest other than User.
47
+ */
48
+ function edgesOf(entities, name) {
49
+ return (entities.get(name)?.relationships ?? [])
50
+ .filter((relationship) => relationship.cardinality === "one")
51
+ .filter((relationship) => entities.has(relationship.to) && !isBuiltInUser(relationship.to))
52
+ .map((relationship) => ({ relationship: relationship.name, target: relationship.to }));
53
+ }
54
+ function routesFrom(entities, from) {
55
+ const shortest = new Map();
56
+ let frontier = [{ relationships: [], entities: [from] }];
57
+ for (let hops = 1; hops <= MAXIMUM_HOPS; hops++) {
58
+ frontier = frontier.flatMap((route) => edgesOf(entities, route.entities.at(-1))
59
+ .filter((edge) => !route.entities.includes(edge.target))
60
+ .map((edge) => ({
61
+ relationships: [...route.relationships, edge.relationship],
62
+ entities: [...route.entities, edge.target],
63
+ })));
64
+ const reachedSooner = new Set(shortest.keys());
65
+ for (const route of frontier) {
66
+ const target = route.entities.at(-1);
67
+ if (!reachedSooner.has(target)) {
68
+ shortest.set(target, [...(shortest.get(target) ?? []), route]);
69
+ }
70
+ }
71
+ }
72
+ return shortest;
73
+ }
74
+ /**
75
+ * Every entity one entity reaches, with the shortest routes there, in the order they are first
76
+ * reached. Routes follow one to {@link MAXIMUM_HOPS} declared `rel.one`s, never inverses, never
77
+ * through User, and never visit an entity twice; several routes to one target are listed in
78
+ * declaration order. These are the routes metric query resolution weighs.
79
+ */
80
+ export function shortestRoutesFrom(manifest, from) {
81
+ return routesFrom(entitiesByName(manifest), from);
82
+ }
83
+ /** The shortest routes from one entity to another, under {@link shortestRoutesFrom}'s rules. */
84
+ export function shortestRoutes(manifest, input) {
85
+ return shortestRoutesFrom(manifest, input.from).get(input.to) ?? [];
86
+ }
87
+ /** Ends resolution with the reason the request is refused. It never leaves this module. */
88
+ class Refusal extends Error {
89
+ reason;
90
+ constructor(reason) {
91
+ super(reason);
92
+ this.reason = reason;
93
+ }
94
+ }
95
+ function refuse(reason) {
96
+ throw new Refusal(reason);
97
+ }
98
+ /**
99
+ * The ontology's entities and metrics of the model by name, and the shortest routes from each
100
+ * metric entity.
101
+ */
102
+ class RouteCatalog {
103
+ entities;
104
+ metrics;
105
+ routes = new Map();
106
+ constructor(manifest) {
107
+ this.entities = entitiesByName(manifest);
108
+ this.metrics = new Map((manifest.metrics ?? []).map((metric) => [metric.name, metric]));
109
+ }
110
+ entity(name) {
111
+ return this.entities.get(name) ?? refuse(`${name} is not an entity of this ontology.`);
112
+ }
113
+ /** A metric of the model; a manifest before version 8 declares none. */
114
+ modelMetric(name) {
115
+ return this.metrics.get(name) ?? refuse(unknownModelMetricMessage(name));
116
+ }
117
+ /** Declared properties, and the `id` of a stored entity, which its replication view carries. */
118
+ hasProperty(entity, property) {
119
+ const stored = entity.source === undefined && !entity.builtIn;
120
+ return (entity.properties.some((candidate) => candidate.name === property) ||
121
+ (stored && property === "id"));
122
+ }
123
+ /** Whether `name` is the inverse of a relationship that another entity declares to this one. */
124
+ hasInverse(entity, name) {
125
+ return [...this.entities.values()].some((owner) => owner.relationships.some((relationship) => relationship.to === entity.name && relationship.inverse === name));
126
+ }
127
+ shortestRoutes(input) {
128
+ const { from, to } = input;
129
+ const reached = this.routes.get(from) ?? routesFrom(this.entities, from);
130
+ this.routes.set(from, reached);
131
+ return reached.get(to) ?? [];
132
+ }
133
+ }
134
+ /**
135
+ * The requested metrics, by entity. A bare name is a metric of the model, which reads the
136
+ * entities of its inputs; `entity.metric` is a metric of the entity.
137
+ */
138
+ function requestedMetrics(input) {
139
+ const { catalog, metrics } = input;
140
+ const entities = new Map();
141
+ const model = [];
142
+ const metricEntity = (name) => {
143
+ const existing = entities.get(name);
144
+ if (existing !== undefined) {
145
+ return existing;
146
+ }
147
+ const created = { entity: catalog.entity(name).name, requested: [], inputs: [], readers: [] };
148
+ entities.set(name, created);
149
+ return created;
150
+ };
151
+ if (metrics.length === 0) {
152
+ refuse("Request at least one metric.");
153
+ }
154
+ for (const [index, name] of metrics.entries()) {
155
+ const segments = name.split(SEPARATOR);
156
+ if (metrics.indexOf(name) !== index) {
157
+ refuse(`${name} is requested twice.`);
158
+ }
159
+ if (segments.length === 1 && name.length > 0) {
160
+ const metric = catalog.modelMetric(name);
161
+ model.push(metric);
162
+ for (const qualified of metric.inputs) {
163
+ const owner = metricEntity(qualified.slice(0, qualified.indexOf(SEPARATOR)));
164
+ owner.inputs.push(qualified.slice(qualified.indexOf(SEPARATOR) + 1));
165
+ if (!owner.readers.includes(metric)) {
166
+ owner.readers.push(metric);
167
+ }
168
+ }
169
+ continue;
170
+ }
171
+ if (segments.length !== 2 || segments.some((segment) => segment.length === 0)) {
172
+ refuse(`${name} is not a metric name; write <entity>.<metric>.`);
173
+ }
174
+ const [entityName, metric] = segments;
175
+ const entity = catalog.entity(entityName);
176
+ if (!(entity.metrics ?? []).some((candidate) => candidate.name === metric)) {
177
+ refuse(`${entityName} has no metric ${metric}.`);
178
+ }
179
+ metricEntity(entityName).requested.push(metric);
180
+ }
181
+ return { entities, model };
182
+ }
183
+ /** The entities a model metric reads, each once, in the order of its inputs. */
184
+ export function inputEntities(metric) {
185
+ return [...new Set(metric.inputs.map((input) => input.slice(0, input.indexOf(SEPARATOR))))];
186
+ }
187
+ /**
188
+ * Parses an identity, `entity.property`, or a route form, `root.relationship[.relationship].property`,
189
+ * whose root must own a requested metric. A written route follows the same relationships as a
190
+ * resolved one: declared `rel.one`s, never through User, never visiting an entity twice.
191
+ */
192
+ function parseName(input) {
193
+ const { catalog, roots, name } = input;
194
+ const segments = name.split(SEPARATOR);
195
+ if (segments.length < 2 || segments.some((segment) => segment.length === 0)) {
196
+ refuse(`${name} is not a valid name; write <entity>.<property> or a route from a metric entity.`);
197
+ }
198
+ if (segments.length > MAXIMUM_HOPS + 2) {
199
+ refuse(hopLimitMessage());
200
+ }
201
+ const [rootName, ...rest] = segments;
202
+ const relationships = rest.slice(0, -1);
203
+ const property = rest.at(-1);
204
+ let entity = catalog.entity(rootName);
205
+ if (relationships.length > 0 && !roots.has(rootName)) {
206
+ refuse(`${name} is written as a route from ${rootName}, which owns no requested metric.`);
207
+ }
208
+ const entities = [entity.name];
209
+ for (const relationshipName of relationships) {
210
+ const relationship = entity.relationships.find((candidate) => candidate.name === relationshipName);
211
+ const segment = { entity: entity.name, relationship: relationshipName };
212
+ if (relationship === undefined) {
213
+ refuse(catalog.hasInverse(entity, relationshipName)
214
+ ? toManySegmentMessage(segment)
215
+ : unknownRelationshipMessage(segment));
216
+ }
217
+ if (relationship.cardinality !== "one") {
218
+ refuse(toManySegmentMessage(segment));
219
+ }
220
+ if (isBuiltInUser(relationship.to)) {
221
+ refuse(userPathMessage());
222
+ }
223
+ const target = catalog.entity(relationship.to);
224
+ if (entities.includes(target.name)) {
225
+ refuse(`${name} visits ${target.name} twice; a route never revisits an entity.`);
226
+ }
227
+ entities.push(target.name);
228
+ entity = target;
229
+ }
230
+ if (!catalog.hasProperty(entity, property)) {
231
+ refuse(unknownPropertyMessage({ entity: entity.name, property }));
232
+ }
233
+ const identity = `${entity.name}${SEPARATOR}${property}`;
234
+ if (relationships.length === 0) {
235
+ return { name, target: entity.name, property, identity };
236
+ }
237
+ return {
238
+ name,
239
+ target: entity.name,
240
+ property,
241
+ identity,
242
+ written: { root: rootName, route: { relationships, entities } },
243
+ };
244
+ }
245
+ /**
246
+ * The route one metric entity takes to a requested name: the written route when the name is a route
247
+ * form rooted at the entity; no relationship when the name is the entity's own property, which
248
+ * always wins; otherwise the shortest routes.
249
+ */
250
+ function resolveName(input) {
251
+ const { catalog, from, requested } = input;
252
+ if (requested.written?.root === from) {
253
+ return { kind: "resolved", route: requested.written.route };
254
+ }
255
+ if (requested.target === from) {
256
+ return { kind: "resolved", route: { relationships: [], entities: [from] } };
257
+ }
258
+ const routes = catalog.shortestRoutes({ from, to: requested.target });
259
+ if (routes.length === 0) {
260
+ return { kind: "unreachable" };
261
+ }
262
+ if (routes.length > 1) {
263
+ return { kind: "ambiguous", routes };
264
+ }
265
+ return { kind: "resolved", route: routes[0] };
266
+ }
267
+ /**
268
+ * The member of an entity in the group of a model metric's alignment that an identity belongs to:
269
+ * a property, `null` when the entity has no counterpart, or `undefined` when no group has the
270
+ * identity.
271
+ */
272
+ function memberOf(input) {
273
+ const { metric, entity, identity } = input;
274
+ const group = metric.align.find((candidate) => Object.entries(candidate).some(([owner, property]) => property !== null && `${owner}${SEPARATOR}${property}` === identity));
275
+ if (group === undefined || !Object.hasOwn(group, entity)) {
276
+ return undefined;
277
+ }
278
+ return group[entity] ?? null;
279
+ }
280
+ /**
281
+ * How the requested model metrics that read an entity align a requested name: the entity's own
282
+ * member of the group the name's identity belongs to, `null` when the entity has no counterpart, or
283
+ * `undefined` when none of them aligns it. Two that align it differently are refused: the entity
284
+ * computes its inputs once.
285
+ */
286
+ function alignedMember(input) {
287
+ const { entity, requested } = input;
288
+ let aligned;
289
+ for (const reader of entity.readers) {
290
+ const member = memberOf({
291
+ metric: reader,
292
+ entity: entity.entity,
293
+ identity: requested.identity,
294
+ });
295
+ if (member === undefined) {
296
+ continue;
297
+ }
298
+ if (aligned !== undefined && aligned.member !== member) {
299
+ refuse(`${requested.identity} is aligned differently by ${aligned.by} and ${reader.name}.`);
300
+ }
301
+ aligned ??= { by: reader.name, member };
302
+ }
303
+ return aligned?.member;
304
+ }
305
+ function resolveFor(input) {
306
+ const { catalog, entity, requested } = input;
307
+ const member = alignedMember({ entity, requested });
308
+ if (member !== undefined) {
309
+ return { kind: "aligned", path: member };
310
+ }
311
+ return resolveName({ catalog, from: entity.entity, requested });
312
+ }
313
+ /**
314
+ * Two requested dimensions that are members of one alignment group of a requested model metric
315
+ * would group each of its entities twice by the same property.
316
+ */
317
+ function refuseAlignedTwice(input) {
318
+ const { model, dimensions } = input;
319
+ for (const metric of model) {
320
+ for (const group of metric.align) {
321
+ const members = dimensions.filter(({ identity }) => Object.entries(group).some(([entity, property]) => property !== null && `${entity}${SEPARATOR}${property}` === identity));
322
+ const [first, second] = members;
323
+ if (first !== undefined && second !== undefined) {
324
+ refuse(`${second.identity} is aligned with ${first.identity}; request one of them.`);
325
+ }
326
+ }
327
+ }
328
+ }
329
+ /**
330
+ * A dimension that a metric entity cannot reach, named after its first requested metric, or after
331
+ * the first requested model metric that reads it.
332
+ */
333
+ function unreachableMessage(entity, identity) {
334
+ const [requested] = entity.requested;
335
+ if (requested !== undefined) {
336
+ return `${entity.entity}${SEPARATOR}${requested} cannot reach ${identity}.`;
337
+ }
338
+ return `${entity.readers[0]?.name} reads ${entity.entity}, which cannot reach ${identity}.`;
339
+ }
340
+ function ambiguousRoute(input) {
341
+ const { from, requested, routes } = input;
342
+ const count = COUNT_WORDS[routes.length] ?? String(routes.length);
343
+ const listed = routes.map((route) => route.relationships.join(SEPARATOR)).join(", ");
344
+ const placeholder = routes[0].relationships.map(() => "<relationship>").join(SEPARATOR);
345
+ return (`${from} reaches ${requested.target} in ${count} ways (${listed}); ` +
346
+ `write the route as ${from}.${placeholder}.${requested.property}.`);
347
+ }
348
+ /** A list of names. Callers validate requests first; this keeps any other value from throwing. */
349
+ function namesOf(field, value) {
350
+ if (!Array.isArray(value) || value.some((name) => typeof name !== "string")) {
351
+ refuse(`${field} must contain names written as entity.member.`);
352
+ }
353
+ return value;
354
+ }
355
+ function pathOf(route, property) {
356
+ return [...route.relationships, property].join(SEPARATOR);
357
+ }
358
+ /**
359
+ * Resolves the names of a model-level metric query against a manifest
360
+ * (docs/ontology-aggregates-spec.md, "Resolution"). It is the one place names and routes resolve: backend-next plans each metric
361
+ * entity from it, and the ontology service checks `<entity>:read` on every entity it touches.
362
+ *
363
+ * Pure: it reads only the manifest. It does not check partitions, currency, replication or metric
364
+ * operators, nor add scope parents, which the planner adds along the same relative path.
365
+ */
366
+ export function resolveMetricRoutes(manifest, names) {
367
+ try {
368
+ return { ok: true, ...resolve(new RouteCatalog(manifest), names) };
369
+ }
370
+ catch (error) {
371
+ if (error instanceof Refusal) {
372
+ return { ok: false, reason: error.reason };
373
+ }
374
+ throw error;
375
+ }
376
+ }
377
+ function resolve(catalog, names) {
378
+ const metricNames = namesOf("metrics", names.metrics);
379
+ const dimensionNames = namesOf("dimensions", names.dimensions ?? []);
380
+ const filterNames = namesOf("filters", names.filters ?? []);
381
+ const requested = requestedMetrics({ catalog, metrics: metricNames });
382
+ const groups = requested.entities;
383
+ const touched = new Set(groups.keys());
384
+ const dimensions = dimensionNames.map((name) => parseName({ catalog, roots: groups, name }));
385
+ for (const [index, dimension] of dimensions.entries()) {
386
+ if (dimensions.findIndex((other) => other.identity === dimension.identity) !== index) {
387
+ refuse(`${dimension.identity} is requested twice.`);
388
+ }
389
+ }
390
+ refuseAlignedTwice({ model: requested.model, dimensions });
391
+ const { granularityOf } = names;
392
+ const bucketed = granularityOf === undefined
393
+ ? undefined
394
+ : (dimensions.find((dimension) => dimension.name === granularityOf || dimension.identity === granularityOf) ?? refuse("granularityOf must name a requested dimension."));
395
+ // Several filters may share a dimension; each distinct name resolves once.
396
+ const filters = [...new Set(filterNames)].map((name) => parseName({ catalog, roots: groups, name }));
397
+ // The entity a filter names is touched even where the filter does not apply, and so is every
398
+ // entity of a written route.
399
+ for (const filter of filters) {
400
+ touched.add(filter.target);
401
+ filter.written?.route.entities.forEach((entity) => touched.add(entity));
402
+ }
403
+ const routed = [...groups.values()].map((entity) => {
404
+ const dimensionRoutes = dimensions.map((dimension) => {
405
+ const resolution = resolveFor({ catalog, entity, requested: dimension });
406
+ if (resolution.kind === "aligned") {
407
+ return { identity: dimension.identity, path: resolution.path };
408
+ }
409
+ if (resolution.kind === "unreachable") {
410
+ refuse(unreachableMessage(entity, dimension.identity));
411
+ }
412
+ if (resolution.kind === "ambiguous") {
413
+ refuse(ambiguousRoute({ from: entity.entity, requested: dimension, routes: resolution.routes }));
414
+ }
415
+ resolution.route.entities.forEach((visited) => touched.add(visited));
416
+ return {
417
+ identity: dimension.identity,
418
+ path: pathOf(resolution.route, dimension.property),
419
+ };
420
+ });
421
+ return { entity, dimensionRoutes };
422
+ });
423
+ const reach = new Map();
424
+ const entities = routed.map(({ entity, dimensionRoutes }) => {
425
+ const applied = [];
426
+ const unappliedFilters = [];
427
+ const reached = new Map();
428
+ for (const filter of filters) {
429
+ const resolution = resolveFor({ catalog, entity, requested: filter });
430
+ if (resolution.kind === "aligned") {
431
+ if (resolution.path === null) {
432
+ unappliedFilters.push(filter.name);
433
+ reached.set(filter.name, "noCounterpart");
434
+ }
435
+ else {
436
+ applied.push({ name: filter.name, path: resolution.path });
437
+ reached.set(filter.name, "applied");
438
+ }
439
+ continue;
440
+ }
441
+ if (resolution.kind === "ambiguous") {
442
+ refuse(ambiguousRoute({ from: entity.entity, requested: filter, routes: resolution.routes }));
443
+ }
444
+ if (resolution.kind === "unreachable") {
445
+ unappliedFilters.push(filter.name);
446
+ reached.set(filter.name, "unreachable");
447
+ continue;
448
+ }
449
+ resolution.route.entities.forEach((visited) => touched.add(visited));
450
+ applied.push({ name: filter.name, path: pathOf(resolution.route, filter.property) });
451
+ reached.set(filter.name, "applied");
452
+ }
453
+ reach.set(entity.entity, reached);
454
+ const bucketedPath = bucketed === undefined
455
+ ? undefined
456
+ : dimensionRoutes.find((route) => route.identity === bucketed.identity)?.path;
457
+ return {
458
+ entity: entity.entity,
459
+ metrics: [...new Set([...entity.requested, ...entity.inputs])],
460
+ dimensions: dimensionRoutes,
461
+ filters: applied,
462
+ unappliedFilters,
463
+ ...(bucketedPath === undefined || bucketedPath === null
464
+ ? {}
465
+ : { granularityOf: bucketedPath }),
466
+ };
467
+ });
468
+ const model = requested.model.map((metric) => ({
469
+ name: metric.name,
470
+ inputs: metric.inputs,
471
+ entities: inputEntities(metric),
472
+ }));
473
+ for (const filter of filters) {
474
+ // A model metric's inputs are filtered alike, or the filter is refused: a filtered numerator
475
+ // over an unfiltered denominator would answer another question. Only the metric's own
476
+ // alignment may say that an entity it reads has no counterpart.
477
+ for (const metric of requested.model) {
478
+ const states = inputEntities(metric).map((entity) => {
479
+ const state = reach.get(entity)?.get(filter.name);
480
+ const exempt = state === "noCounterpart" &&
481
+ memberOf({ metric, entity, identity: filter.identity }) === null;
482
+ return { entity, state: state === "noCounterpart" && !exempt ? "unreachable" : state };
483
+ });
484
+ const missed = states.find(({ state }) => state === "unreachable");
485
+ if (missed !== undefined && states.some(({ state }) => state === "applied")) {
486
+ refuse(partialFilterMessage({
487
+ filter: filter.name,
488
+ entity: missed.entity,
489
+ metric: metric.name,
490
+ }));
491
+ }
492
+ }
493
+ if (entities.every((routes) => routes.unappliedFilters.includes(filter.name))) {
494
+ refuse(`No metric can reach ${filter.name}.`);
495
+ }
496
+ }
497
+ return { entities, touched: [...touched].sort(), model };
498
+ }
@@ -0,0 +1,172 @@
1
+ import type { MetricQueryValue, MetricConditionOperator } from "./metric-filters.js";
2
+ /**
3
+ * A condition on the rows an aggregate reads: a property of the metric's own entity, in TypeScript
4
+ * names, and an operator with literal values, as a request filter takes them.
5
+ */
6
+ export interface MetricCondition {
7
+ readonly property: string;
8
+ readonly operator: MetricConditionOperator;
9
+ readonly value?: MetricQueryValue;
10
+ readonly values?: ReadonlyArray<MetricQueryValue>;
11
+ }
12
+ /**
13
+ * A condition as a `filtered` expression holds it: like a `column` expression, it names a property
14
+ * until `metricExpression` maps it to the property's column for the manifest.
15
+ */
16
+ export interface MetricColumnCondition {
17
+ readonly column: string;
18
+ readonly operator: MetricConditionOperator;
19
+ readonly value?: MetricQueryValue;
20
+ readonly values?: ReadonlyArray<MetricQueryValue>;
21
+ }
22
+ /** The aggregates a metric expression may contain, `count` included. */
23
+ export declare const METRIC_AGGREGATES: readonly ["count", "sum", "countDistinct", "avg", "min", "max"];
24
+ export type MetricExpression = {
25
+ readonly op: "count";
26
+ } | {
27
+ readonly op: "column" | "metric";
28
+ readonly name: string;
29
+ } | {
30
+ readonly op: "literal";
31
+ readonly value: string;
32
+ } | {
33
+ readonly op: "sum" | "countDistinct" | "avg" | "min" | "max" | "add" | "subtract" | "multiply" | "divide";
34
+ readonly args: ReadonlyArray<MetricExpression>;
35
+ }
36
+ /**
37
+ * One aggregate over the rows that meet every condition. The condition wraps the aggregate, so a
38
+ * platform that does not know `filtered` cannot compute the aggregate unfiltered.
39
+ */
40
+ | {
41
+ readonly op: "filtered";
42
+ readonly args: ReadonlyArray<MetricExpression>;
43
+ readonly where: ReadonlyArray<MetricColumnCondition>;
44
+ };
45
+ export interface MetricOptions {
46
+ readonly description: string;
47
+ readonly label?: string;
48
+ readonly unit?: "number" | "currency" | "ratio" | "percent";
49
+ readonly format?: "decimal" | "currency" | "percent";
50
+ }
51
+ /** What an aggregate declares about the rows it reads, beside a metric's options. */
52
+ export interface AggregateDeclarations {
53
+ /** 1–10 conditions on properties of the entity, all of which the rows read must meet. */
54
+ readonly where?: ReadonlyArray<MetricCondition>;
55
+ /**
56
+ * The date or timestamp property the entity's rows are snapshots over, such as a daily stock
57
+ * table's date. Summing snapshots over days would overstate the balance, so a request must group
58
+ * by the property or filter it to one day. Arithmetic and references over the aggregate inherit
59
+ * it.
60
+ */
61
+ readonly balanceOver?: string;
62
+ }
63
+ /**
64
+ * The options of `count`, `sum`, `countDistinct`, `avg`, `min` and `max`: a metric's options with
65
+ * the aggregate's declarations, or the declarations alone for an aggregate that is an argument of
66
+ * arithmetic.
67
+ */
68
+ export type AggregateOptions = (MetricOptions & AggregateDeclarations) | AggregateDeclarations;
69
+ export type Metric = MetricExpression & Partial<MetricOptions> & {
70
+ /** An aggregate's conditions, as its builder's `where` option declares them. */
71
+ readonly where?: ReadonlyArray<MetricCondition | MetricColumnCondition>;
72
+ /** An aggregate's balance property, as its builder's `balanceOver` option declares it. */
73
+ readonly balanceOver?: string;
74
+ /** A metric of an entity reads that entity's rows only: alignment is for model metrics. */
75
+ readonly align?: never;
76
+ };
77
+ export type Metrics = Readonly<Record<string, Metric>>;
78
+ /**
79
+ * One group of a model metric's alignment: every entity the metric reads, by its TypeScript name,
80
+ * with its property that stands for the others', or `null` when the entity has no counterpart, as a
81
+ * current snapshot has no date.
82
+ */
83
+ export type AlignmentGroup = Readonly<Record<string, string | null>>;
84
+ /** The options of a model metric: a metric's options and how its entities' properties align. */
85
+ export interface ModelMetricOptions extends MetricOptions {
86
+ /**
87
+ * At most 5 groups of properties that stand for one another across the entities the metric
88
+ * reads, such as a sales date and a plan month. A request that groups or filters by one member of
89
+ * a group reads each entity through its own member. Properties of one group share a type, and a
90
+ * property appears in one group at most.
91
+ */
92
+ readonly align?: ReadonlyArray<AlignmentGroup>;
93
+ }
94
+ /**
95
+ * A metric of the model, declared in `defineOntology({ metrics })`: arithmetic over metrics of
96
+ * entities, `m.ref("entity.metric")`, and over other model metrics, `m.ref("name")`. It reads
97
+ * entity metrics and aggregates no rows of its own.
98
+ */
99
+ export type ModelMetric = MetricExpression & Partial<MetricOptions> & {
100
+ readonly align?: ReadonlyArray<AlignmentGroup>;
101
+ };
102
+ export type ModelMetrics = Readonly<Record<string, ModelMetric>>;
103
+ /** A model metric's options that declare an alignment, which only model metrics take. */
104
+ type AlignedOptions = ModelMetricOptions & {
105
+ readonly align: ReadonlyArray<AlignmentGroup>;
106
+ };
107
+ /**
108
+ * An argument of arithmetic: any expression but one that declares an alignment, which belongs on
109
+ * the model metric itself.
110
+ */
111
+ type Argument = MetricExpression & {
112
+ readonly align?: never;
113
+ };
114
+ /** Arithmetic of two expressions; with `align` among its options, a model metric. */
115
+ interface Arithmetic {
116
+ (left: Argument, right: Argument, options: AlignedOptions): ModelMetric;
117
+ (left: Argument, right: Argument, options?: MetricOptions): Metric;
118
+ }
119
+ /** A reference to another metric; with `align` among its options, a model metric. */
120
+ interface Reference {
121
+ (name: string, options: AlignedOptions): ModelMetric;
122
+ (name: string, options?: MetricOptions): Metric;
123
+ }
124
+ /**
125
+ * Arithmetic combines aggregates; references name another metric of the same entity. Every
126
+ * aggregate takes `where`, conditions on properties of the entity that the rows it reads must meet,
127
+ * and `balanceOver`, the date its rows are snapshots over. In `defineOntology({ metrics })`,
128
+ * references name metrics of entities, `m.ref("sales.revenue")`, or other model metrics, and
129
+ * arithmetic and references take `align`.
130
+ */
131
+ export declare const m: {
132
+ readonly count: (options?: AggregateOptions) => Metric;
133
+ /** The sum of an integer or number property. */
134
+ readonly sum: (property: string, options?: AggregateOptions) => Metric;
135
+ /**
136
+ * The number of distinct non-null values of a text, email, url, select, integer, date or timestamp
137
+ * property. Distinct counts do not add up across groups.
138
+ */
139
+ readonly countDistinct: (property: string, options?: AggregateOptions) => Metric;
140
+ /** The average of an integer or number property, ignoring nulls. Averages do not add up. */
141
+ readonly avg: (property: string, options?: AggregateOptions) => Metric;
142
+ /** The least value of an integer or number property. Minimums do not add up. */
143
+ readonly min: (property: string, options?: AggregateOptions) => Metric;
144
+ /** The greatest value of an integer or number property. Maximums do not add up. */
145
+ readonly max: (property: string, options?: AggregateOptions) => Metric;
146
+ readonly ref: Reference;
147
+ readonly literal: (value: number | string, options?: MetricOptions) => Metric;
148
+ readonly add: Arithmetic;
149
+ readonly subtract: Arithmetic;
150
+ readonly multiply: Arithmetic;
151
+ readonly divide: Arithmetic;
152
+ };
153
+ /** The conditions an expression declares: an aggregate's `where` option, or a `filtered` node's. */
154
+ export declare function conditionsOf(value: Metric | MetricExpression): ReadonlyArray<MetricCondition | MetricColumnCondition> | undefined;
155
+ /** The balance property an expression node declares: an aggregate's `balanceOver` option. */
156
+ export declare function balanceOf(value: Metric | MetricExpression): unknown;
157
+ /**
158
+ * The balance properties a metric's own aggregates declare, top-level or inside arithmetic and
159
+ * `filtered` expressions, without duplicates. References are not followed: the platform inherits a
160
+ * referenced metric's balance itself.
161
+ */
162
+ export declare function balancesOf(value: Metric | MetricExpression): ReadonlyArray<string>;
163
+ /** The property a condition names: `property` as authored, `column` in a `filtered` expression. */
164
+ export declare function conditionProperty(condition: object): unknown;
165
+ /**
166
+ * Strip authoring options and resolve logical properties to physical columns for the manifest: a
167
+ * warehouse-backed property's `column`, or a stored property's replication view column, which is its
168
+ * wire name. An aggregate's `where` becomes the `filtered` expression that wraps it, its conditions
169
+ * naming columns too.
170
+ */
171
+ export declare function metricExpression(value: MetricExpression, columns: ReadonlyMap<string, string>): MetricExpression;
172
+ export {};