@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,22 @@
1
+ import type { ResolvedEntity } from "./analyze.js";
2
+ import type { Diagnostic, DiagnosticCode } from "./diagnostics.js";
3
+ import type { ModelMetricManifest } from "./manifest.js";
4
+ type Report = (code: DiagnosticCode, path: string, message: string, severity?: Diagnostic["severity"]) => void;
5
+ /** The most metrics a model declares. */
6
+ export declare const MAXIMUM_MODEL_METRICS = 50;
7
+ /** The most distinct entity metrics one model metric reads, references expanded. */
8
+ export declare const MAXIMUM_MODEL_METRIC_INPUTS = 10;
9
+ /** The most alignment groups one model metric declares. */
10
+ export declare const MAXIMUM_ALIGNMENT_GROUPS = 5;
11
+ /**
12
+ * Resolves and checks the metrics of the model, `defineOntology({ metrics })`, against the
13
+ * resolved entities, whose metrics were checked first (docs/ontology-aggregates-release-3-spec.md,
14
+ * "Declaring model metrics"). Returns the manifest form of each metric that passed, in declaration
15
+ * order: references expanded, names on the wire, inputs in reading order.
16
+ */
17
+ export declare function resolveModelMetrics(input: {
18
+ readonly metrics: unknown;
19
+ readonly entities: ReadonlyArray<ResolvedEntity>;
20
+ readonly report: Report;
21
+ }): ReadonlyArray<ModelMetricManifest>;
22
+ export {};
@@ -0,0 +1,545 @@
1
+ import { dimensionTypeOf } from "./metric-filters.js";
2
+ import { isRecord, nameToWire } from "./authoring-names.js";
3
+ import { METRIC_AGGREGATES } from "./metric.js";
4
+ import { EARLIER_QUERY_METRICS_ROUTE } from "./legacy.js";
5
+ import { humanize, RESERVED_ENTITY_NAMES, SNAKE_CASE_NAME, toCamelCase } from "./names.js";
6
+ /** The most metrics a model declares. */
7
+ export const MAXIMUM_MODEL_METRICS = 50;
8
+ /** The most distinct entity metrics one model metric reads, references expanded. */
9
+ export const MAXIMUM_MODEL_METRIC_INPUTS = 10;
10
+ /** The most alignment groups one model metric declares. */
11
+ export const MAXIMUM_ALIGNMENT_GROUPS = 5;
12
+ /** The deepest and the largest expression a model metric expands to. */
13
+ const MAXIMUM_DEPTH = 30;
14
+ const MAXIMUM_NODES = 1000;
15
+ const SEPARATOR = ".";
16
+ const UNITS = ["number", "currency", "ratio", "percent"];
17
+ const FORMATS = ["decimal", "currency", "percent"];
18
+ const ARITHMETIC = ["add", "subtract", "multiply", "divide"];
19
+ /** What only an entity metric contains: an aggregate, its condition and the column it reads. */
20
+ const AGGREGATE_NODES = [...METRIC_AGGREGATES, "filtered", "column"];
21
+ const LITERAL = /^[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?$/;
22
+ const NAMES = "Model metrics require unique snake_case names and a description.";
23
+ const AGGREGATES = "Model metrics combine entity metrics; declare the aggregate on its entity.";
24
+ const CYCLE = "Metric references cannot form a cycle.";
25
+ const COMPLEX = "Invalid or overly complex expression.";
26
+ const NO_INPUT = 'A model metric reads at least one entity metric: m.ref("entity.metric").';
27
+ const TOO_MANY_INPUTS = `A model metric reads at most ${MAXIMUM_MODEL_METRIC_INPUTS} entity metrics.`;
28
+ const ALIGNMENT_SHAPE = "align is a list of groups, each naming every entity the metric reads with its property or " +
29
+ 'null, such as [{ sales: "orderDate", plans: "month" }].';
30
+ const ALL_NULL = "An alignment names a property for at least one entity.";
31
+ const NESTED_ALIGN = "align belongs on the model metric, not on an argument of its expression.";
32
+ const NO_WHERE = "A model metric takes no where; declare a filtered metric on the entity and read it.";
33
+ const NO_BALANCE = "A model metric takes no balanceOver; declare the balance on the entity and read it.";
34
+ function isBlank(value) {
35
+ return typeof value !== "string" || value.trim().length === 0;
36
+ }
37
+ /** The wire name of a name that round-trips: `planAttainment` or `plan_attainment`. */
38
+ function wireNameOf(name) {
39
+ const wire = nameToWire(name);
40
+ return SNAKE_CASE_NAME.test(wire) && (name === wire || toCamelCase(wire) === name)
41
+ ? wire
42
+ : undefined;
43
+ }
44
+ /**
45
+ * The declared model metrics under their wire names, each a unique snake_case name, not an
46
+ * entity's and not a route's, with a description. A metric whose name is refused is not resolved
47
+ * further.
48
+ */
49
+ function declare(input) {
50
+ const { metrics, entities, report } = input;
51
+ const declared = new Map();
52
+ for (const [name, metric] of Object.entries(metrics)) {
53
+ const wire = wireNameOf(name);
54
+ const path = `metrics.${wire ?? name}`;
55
+ if (wire === undefined || declared.has(wire) || !isRecord(metric)) {
56
+ report("invalid-metric", path, NAMES);
57
+ continue;
58
+ }
59
+ if (isBlank(metric.description)) {
60
+ report("invalid-metric", path, NAMES);
61
+ }
62
+ if (entities.has(wire)) {
63
+ report("duplicate-name", path, `${wire} is also an entity name.`);
64
+ continue;
65
+ }
66
+ if (RESERVED_ENTITY_NAMES.includes(wire) ||
67
+ wire === EARLIER_QUERY_METRICS_ROUTE) {
68
+ report("reserved-name", path, `${wire} is a reserved name.`);
69
+ continue;
70
+ }
71
+ declared.set(wire, { name: wire, path, metric });
72
+ }
73
+ return declared;
74
+ }
75
+ /** Whether an entity declares a metric, by wire names. */
76
+ function declaresMetric(entity, metric) {
77
+ const metrics = entity?.entity.definition.metrics ?? {};
78
+ return metric !== undefined && Object.hasOwn(metrics, metric);
79
+ }
80
+ /**
81
+ * Expands every model metric: a reference to an entity metric becomes a `metric` node naming
82
+ * `entity.metric` in wire names, and a reference to another model metric that metric's expanded
83
+ * expression. A metric whose expansion fails maps to `undefined`; its reason is reported once, at
84
+ * the metric where it occurs.
85
+ */
86
+ function expandAll(input) {
87
+ const { declared, entities, report } = input;
88
+ const expansions = new Map();
89
+ const pending = new Set();
90
+ const expand = (current) => {
91
+ if (expansions.has(current.name)) {
92
+ return expansions.get(current.name);
93
+ }
94
+ const reported = new Set();
95
+ const references = new Set();
96
+ let failed = false;
97
+ let nodes = 0;
98
+ const refuse = (code, message) => {
99
+ failed = true;
100
+ if (!reported.has(message)) {
101
+ reported.add(message);
102
+ report(code, current.path, message);
103
+ }
104
+ return undefined;
105
+ };
106
+ const unknown = (name) => refuse("unknown-metric", `${current.name} reads ${name}, which the ontology does not declare.`);
107
+ /** A reference: `entity.metric` in TypeScript names per segment, or a model metric's name. */
108
+ const reference = (name, depth) => {
109
+ if (typeof name !== "string" || name.length === 0) {
110
+ return refuse("invalid-metric", "Invalid expression operator or arity.");
111
+ }
112
+ if (name.includes(SEPARATOR)) {
113
+ const wire = name.split(SEPARATOR).map(nameToWire).join(SEPARATOR);
114
+ const [owner, metric, ...rest] = wire.split(SEPARATOR);
115
+ if (rest.length > 0 || !declaresMetric(entities.get(owner ?? ""), metric)) {
116
+ return unknown(wire);
117
+ }
118
+ return { op: "metric", name: wire };
119
+ }
120
+ const wire = nameToWire(name);
121
+ const target = declared.get(wire);
122
+ if (target === undefined) {
123
+ return unknown(wire);
124
+ }
125
+ if (pending.has(wire)) {
126
+ return refuse("circular-metric", CYCLE);
127
+ }
128
+ const inner = expand(target);
129
+ references.add(wire);
130
+ if (inner === undefined) {
131
+ failed = true;
132
+ return undefined;
133
+ }
134
+ nodes += inner.nodes - 1;
135
+ if (depth + inner.depth > MAXIMUM_DEPTH || nodes > MAXIMUM_NODES) {
136
+ return refuse("invalid-metric", COMPLEX);
137
+ }
138
+ return inner.expression;
139
+ };
140
+ const visit = (node, depth) => {
141
+ nodes += 1;
142
+ if (depth > MAXIMUM_DEPTH || nodes > MAXIMUM_NODES || !isRecord(node)) {
143
+ return refuse("invalid-metric", COMPLEX);
144
+ }
145
+ const { op } = node;
146
+ // Options of an argument are not the metric's: only the root declares them.
147
+ if (depth > 0 && node.align !== undefined) {
148
+ refuse("invalid-alignment", NESTED_ALIGN);
149
+ }
150
+ if (AGGREGATE_NODES.includes(op)) {
151
+ return refuse("invalid-metric", AGGREGATES);
152
+ }
153
+ if (node.where !== undefined) {
154
+ refuse("invalid-metric", NO_WHERE);
155
+ }
156
+ if (node.balanceOver !== undefined) {
157
+ refuse("invalid-metric", NO_BALANCE);
158
+ }
159
+ if (op === "metric") {
160
+ return reference(node.name, depth);
161
+ }
162
+ if (op === "literal") {
163
+ const { value } = node;
164
+ if (typeof value !== "string" ||
165
+ value.length >= 100 ||
166
+ !LITERAL.test(value) ||
167
+ !Number.isFinite(Number(value))) {
168
+ return refuse("invalid-metric", "Literals must be finite numbers.");
169
+ }
170
+ return { op: "literal", value };
171
+ }
172
+ if (!ARITHMETIC.includes(op) || !Array.isArray(node.args) || node.args.length !== 2) {
173
+ return refuse("invalid-metric", "Invalid expression operator or arity.");
174
+ }
175
+ const args = node.args.map((arg) => visit(arg, depth + 1));
176
+ const [left, right] = args;
177
+ if (left === undefined || right === undefined) {
178
+ return undefined;
179
+ }
180
+ return { op: op, args: [left, right] };
181
+ };
182
+ pending.add(current.name);
183
+ const expression = visit(current.metric, 0);
184
+ pending.delete(current.name);
185
+ const expansion = failed || expression === undefined
186
+ ? undefined
187
+ : { expression, depth: depthOf(expression), nodes, references: [...references] };
188
+ expansions.set(current.name, expansion);
189
+ return expansion;
190
+ };
191
+ for (const candidate of declared.values()) {
192
+ expand(candidate);
193
+ }
194
+ return expansions;
195
+ }
196
+ function depthOf(expression) {
197
+ return "args" in expression ? 1 + Math.max(...expression.args.map(depthOf)) : 0;
198
+ }
199
+ /** The entity metrics an expanded expression reads, `entity.metric`, each once, in order. */
200
+ function inputsOf(expression) {
201
+ if (expression.op === "metric") {
202
+ return [expression.name];
203
+ }
204
+ return "args" in expression ? [...new Set(expression.args.flatMap(inputsOf))] : [];
205
+ }
206
+ function ownerOf(input) {
207
+ return input.slice(0, input.indexOf(SEPARATOR));
208
+ }
209
+ /**
210
+ * The quantity an expression amounts to, by unit algebra: money times or over a number is money,
211
+ * money over money is a number, money times money is neither, and a sum with money is money.
212
+ * Records in `found` what the arithmetic does with two amounts of money.
213
+ */
214
+ function quantityOf(input) {
215
+ const { expression, currency, found } = input;
216
+ if (expression.op === "metric") {
217
+ return currency(expression.name) ? "money" : "number";
218
+ }
219
+ if (!("args" in expression) || expression.args.length !== 2) {
220
+ return "number";
221
+ }
222
+ const [left, right] = expression.args.map((arg) => quantityOf({ expression: arg, currency, found }));
223
+ if (left === "neither" || right === "neither") {
224
+ return "neither";
225
+ }
226
+ const money = (left === "money" ? 1 : 0) + (right === "money" ? 1 : 0);
227
+ switch (expression.op) {
228
+ case "add":
229
+ case "subtract":
230
+ found.sum ||= money === 2;
231
+ return money > 0 ? "money" : "number";
232
+ case "multiply":
233
+ found.product ||= money === 2;
234
+ return money === 2 ? "neither" : money === 1 ? "money" : "number";
235
+ case "divide":
236
+ found.ratio ||= money === 2;
237
+ if (right === "money") {
238
+ return left === "money" ? "number" : "neither";
239
+ }
240
+ return left;
241
+ default:
242
+ return "number";
243
+ }
244
+ }
245
+ /** Why the declared unit contradicts the arithmetic of the currency inputs, if it does. */
246
+ function unitIssue(input) {
247
+ const { unit, expression, currency } = input;
248
+ const found = { ratio: false, product: false, sum: false };
249
+ const quantity = quantityOf({ expression, currency, found });
250
+ if (unit === "currency" && quantity !== "money" && found.ratio) {
251
+ return "A ratio of two currency metrics is a ratio, not a currency.";
252
+ }
253
+ if (unit === "currency" && quantity !== "money" && found.product) {
254
+ return "A product of two currency metrics is not a currency.";
255
+ }
256
+ if ((unit === "ratio" || unit === "percent") && quantity === "money" && found.sum) {
257
+ return `A sum or difference of currency metrics is a currency, not a ${unit}.`;
258
+ }
259
+ return undefined;
260
+ }
261
+ /** A property an alignment may name: a declared property, or the `id` of a stored entity. */
262
+ function dimensionOf(entity, property) {
263
+ const declared = entity.properties.find((candidate) => candidate.name === property);
264
+ if (declared !== undefined) {
265
+ return { type: declared.definition.type };
266
+ }
267
+ return entity.entity.definition.source === undefined && property === "id"
268
+ ? { type: "text" }
269
+ : undefined;
270
+ }
271
+ /**
272
+ * A model metric's alignment in wire names, each group naming every entity it reads, in reading
273
+ * order, or `undefined` when it is refused.
274
+ */
275
+ function alignmentOf(input) {
276
+ const { metric, read, entities, refuse } = input;
277
+ const declared = metric.metric.align;
278
+ if (declared === undefined) {
279
+ return [];
280
+ }
281
+ if (!Array.isArray(declared) || !declared.every(isRecord)) {
282
+ refuse("invalid-alignment", ALIGNMENT_SHAPE);
283
+ return undefined;
284
+ }
285
+ if (declared.length > 0 && read.length === 1) {
286
+ refuse("invalid-alignment", `${metric.name} reads one entity and needs no alignment.`);
287
+ return undefined;
288
+ }
289
+ if (declared.length > MAXIMUM_ALIGNMENT_GROUPS) {
290
+ refuse("invalid-alignment", `A model metric aligns at most ${MAXIMUM_ALIGNMENT_GROUPS} groups.`);
291
+ return undefined;
292
+ }
293
+ const aligned = new Set();
294
+ const groups = [];
295
+ let valid = true;
296
+ const invalid = (message) => {
297
+ valid = false;
298
+ refuse("invalid-alignment", message);
299
+ };
300
+ for (const group of declared) {
301
+ const members = Object.entries(group).map(([entity, property]) => ({
302
+ entity: nameToWire(entity),
303
+ property,
304
+ }));
305
+ const named = members.map(({ entity }) => entity);
306
+ if (named.length !== read.length ||
307
+ new Set(named).size !== named.length ||
308
+ !named.every((entity) => read.includes(entity))) {
309
+ invalid(`An alignment names every entity ${metric.name} reads exactly once.`);
310
+ continue;
311
+ }
312
+ const typed = [];
313
+ const wire = new Map();
314
+ for (const { entity, property } of members) {
315
+ if (property === null) {
316
+ wire.set(entity, null);
317
+ continue;
318
+ }
319
+ if (typeof property !== "string") {
320
+ invalid(ALIGNMENT_SHAPE);
321
+ continue;
322
+ }
323
+ const name = nameToWire(property);
324
+ const identity = `${entity}${SEPARATOR}${name}`;
325
+ const dimension = dimensionOf(entities.get(entity), name);
326
+ const type = dimension === undefined ? undefined : dimensionTypeOf(dimension.type);
327
+ if (dimension === undefined) {
328
+ invalid(`${entity} has no property ${name}.`);
329
+ continue;
330
+ }
331
+ if (type === undefined) {
332
+ invalid(`${identity} cannot be aligned: JSON and file properties are not dimensions.`);
333
+ continue;
334
+ }
335
+ if (aligned.has(identity)) {
336
+ invalid(`${identity} is aligned twice.`);
337
+ }
338
+ aligned.add(identity);
339
+ typed.push({ identity, type });
340
+ wire.set(entity, name);
341
+ }
342
+ if (members.every(({ property }) => property === null)) {
343
+ invalid(ALL_NULL);
344
+ continue;
345
+ }
346
+ const [first] = typed;
347
+ const differing = typed.find((candidate) => candidate.type !== first?.type);
348
+ if (first !== undefined && differing !== undefined) {
349
+ invalid(`${metric.name} aligns ${first.identity} with ${differing.identity}, whose types differ.`);
350
+ }
351
+ groups.push(Object.fromEntries(read.map((entity) => [entity, wire.get(entity) ?? null])));
352
+ }
353
+ return valid ? groups : undefined;
354
+ }
355
+ /** Whether two groups share a member: one entity aligned through the same property in both. */
356
+ function sharesMember(group, other) {
357
+ return Object.entries(group).some(([entity, property]) => property !== null && other[entity] === property);
358
+ }
359
+ /** Why a group disagrees with a group of a metric it reads, on the entities that one names. */
360
+ function disagreement(input) {
361
+ const { metric, group, source, inherited } = input;
362
+ for (const [entity, member] of Object.entries(inherited)) {
363
+ const own = group[entity] ?? null;
364
+ if (own === member) {
365
+ continue;
366
+ }
367
+ if (own !== null && member !== null) {
368
+ return (`${metric} aligns ${entity}${SEPARATOR}${own}, but ${source}, which it reads, aligns ` +
369
+ `${entity}${SEPARATOR}${member}.`);
370
+ }
371
+ if (own !== null) {
372
+ return (`${metric} aligns ${entity}${SEPARATOR}${own}, but ${source}, which it reads, gives ` +
373
+ `${entity} no counterpart.`);
374
+ }
375
+ return (`${metric} gives ${entity} no counterpart, but ${source}, which it reads, aligns ` +
376
+ `${entity}${SEPARATOR}${member}.`);
377
+ }
378
+ return undefined;
379
+ }
380
+ /**
381
+ * A model metric's effective alignment: its own groups, then every group of the model metrics it
382
+ * reads that it does not restate. A restated group must agree on every entity the read metric
383
+ * reads; an inherited group must name every entity this metric reads.
384
+ */
385
+ function inheritAlignment(input) {
386
+ const { metric, read, own, sources, refuse } = input;
387
+ const groups = [...own];
388
+ let valid = true;
389
+ for (const source of sources) {
390
+ for (const inherited of source.align) {
391
+ const restated = groups.filter((group) => sharesMember(group, inherited));
392
+ const missing = read.find((entity) => !Object.hasOwn(inherited, entity));
393
+ for (const group of restated) {
394
+ const reason = disagreement({ metric, group, source: source.name, inherited });
395
+ if (reason !== undefined) {
396
+ valid = false;
397
+ refuse("invalid-alignment", reason);
398
+ }
399
+ }
400
+ if (restated.length > 0) {
401
+ continue;
402
+ }
403
+ if (missing !== undefined) {
404
+ valid = false;
405
+ refuse("invalid-alignment", `${metric} reads ${source.name}, whose alignment does not name ${missing}; align it ` +
406
+ `in ${metric}.`);
407
+ continue;
408
+ }
409
+ groups.push(Object.fromEntries(read.map((entity) => [entity, inherited[entity] ?? null])));
410
+ }
411
+ }
412
+ if (valid && groups.length > MAXIMUM_ALIGNMENT_GROUPS) {
413
+ refuse("invalid-alignment", `A model metric aligns at most ${MAXIMUM_ALIGNMENT_GROUPS} groups.`);
414
+ return undefined;
415
+ }
416
+ return valid ? groups : undefined;
417
+ }
418
+ function formatOf(unit, format) {
419
+ if (format !== undefined) {
420
+ return format;
421
+ }
422
+ if (unit === "currency") {
423
+ return "currency";
424
+ }
425
+ return unit === "percent" ? "percent" : "decimal";
426
+ }
427
+ /**
428
+ * Resolves and checks the metrics of the model, `defineOntology({ metrics })`, against the
429
+ * resolved entities, whose metrics were checked first (docs/ontology-aggregates-release-3-spec.md,
430
+ * "Declaring model metrics"). Returns the manifest form of each metric that passed, in declaration
431
+ * order: references expanded, names on the wire, inputs in reading order.
432
+ */
433
+ export function resolveModelMetrics(input) {
434
+ const { metrics, report } = input;
435
+ const entities = new Map(input.entities.map((candidate) => [candidate.name, candidate]));
436
+ if (metrics === undefined) {
437
+ return [];
438
+ }
439
+ if (!isRecord(metrics)) {
440
+ report("invalid-metric", "metrics", "metrics maps names to metrics built with m: { planAttainment: m.divide(…) }.");
441
+ return [];
442
+ }
443
+ const count = Object.keys(metrics).length;
444
+ if (count > MAXIMUM_MODEL_METRICS) {
445
+ report("invalid-metric", "metrics", `The ontology declares ${count} model metrics; the limit is ${MAXIMUM_MODEL_METRICS}.`);
446
+ }
447
+ const declared = declare({ metrics, entities, report });
448
+ const expansions = expandAll({ declared, entities, report });
449
+ const resolved = new Map();
450
+ /** A metric, after the model metrics it reads, whose alignment it inherits. */
451
+ const resolve = (metric) => {
452
+ const known = resolved.get(metric.name);
453
+ if (known !== undefined) {
454
+ return known;
455
+ }
456
+ const resolution = resolveMetric({
457
+ metric,
458
+ expansion: expansions.get(metric.name),
459
+ entities,
460
+ report,
461
+ resolveReference: (name) => resolve(declared.get(name)),
462
+ });
463
+ resolved.set(metric.name, resolution);
464
+ return resolution;
465
+ };
466
+ return [...declared.values()].flatMap((metric) => {
467
+ const { manifest } = resolve(metric);
468
+ return manifest === undefined ? [] : [manifest];
469
+ });
470
+ }
471
+ function resolveMetric(input) {
472
+ const { metric, expansion, entities, report, resolveReference } = input;
473
+ if (expansion === undefined) {
474
+ return {};
475
+ }
476
+ let refused = isBlank(metric.metric.description);
477
+ const refuse = (code, message) => {
478
+ refused = true;
479
+ report(code, metric.path, message);
480
+ };
481
+ const { expression } = expansion;
482
+ const { unit, format, label, description } = metric.metric;
483
+ const inputs = inputsOf(expression);
484
+ const read = [...new Set(inputs.map(ownerOf))];
485
+ if (inputs.length === 0) {
486
+ refuse("invalid-metric", NO_INPUT);
487
+ }
488
+ if (inputs.length > MAXIMUM_MODEL_METRIC_INPUTS) {
489
+ refuse("invalid-metric", TOO_MANY_INPUTS);
490
+ }
491
+ if (unit !== undefined && !UNITS.includes(unit)) {
492
+ refuse("invalid-metric", "Invalid metric unit.");
493
+ }
494
+ if (format !== undefined && !FORMATS.includes(format)) {
495
+ refuse("invalid-metric", "Invalid metric format.");
496
+ }
497
+ const currency = (name) => {
498
+ const owner = entities.get(ownerOf(name));
499
+ const declaredMetric = owner?.entity.definition.metrics?.[name.slice(ownerOf(name).length + 1)];
500
+ return declaredMetric?.unit === "currency";
501
+ };
502
+ const issue = unitIssue({ unit, expression, currency });
503
+ if (issue !== undefined) {
504
+ refuse("invalid-metric", issue);
505
+ }
506
+ // A metric that reads nothing has no entities to align.
507
+ const own = read.length === 0 ? undefined : alignmentOf({ metric, read, entities, refuse });
508
+ const sources = expansion.references.map((name) => ({
509
+ name,
510
+ align: resolveReference(name).align,
511
+ }));
512
+ // A read metric whose alignment was refused has said so; this one cannot inherit it.
513
+ const inheritable = sources.every((source) => source.align !== undefined);
514
+ const align = own === undefined || !inheritable
515
+ ? undefined
516
+ : inheritAlignment({
517
+ metric: metric.name,
518
+ read,
519
+ own,
520
+ sources: sources,
521
+ refuse,
522
+ });
523
+ if (read.length === 1 && !refused && align !== undefined) {
524
+ report("single-entity-model-metric", metric.path, `${metric.name} reads one entity; declare it as a metric of ${read[0]}.`, "warning");
525
+ }
526
+ if (align === undefined) {
527
+ return {};
528
+ }
529
+ if (refused) {
530
+ return { align };
531
+ }
532
+ return {
533
+ align,
534
+ manifest: {
535
+ name: metric.name,
536
+ label: typeof label === "string" ? label : humanize(metric.name),
537
+ description: description,
538
+ unit: (unit ?? "number"),
539
+ format: formatOf(unit, format),
540
+ expression: expression,
541
+ inputs,
542
+ align,
543
+ },
544
+ };
545
+ }
@@ -0,0 +1,49 @@
1
+ /** Ontology names: lowercase snake_case. */
2
+ export declare const SNAKE_CASE_NAME: RegExp;
3
+ /** Convert each character once, including acronym boundaries such as HTTPClient. */
4
+ export declare function toSnakeCase(name: string): string;
5
+ export declare function toCamelCase(name: string): string;
6
+ /** Historical property names accepted only as explicit rename sources. */
7
+ export declare const LEGACY_MEMBER_NAME: RegExp;
8
+ /** Stable entity identities, for example `ent_01J9Q4M8ZK`. */
9
+ export declare const ENTITY_ID: RegExp;
10
+ /** Properties every entity has. They are never declared and cannot be redeclared. */
11
+ export declare const SYSTEM_PROPERTIES: readonly ["id", "created_at", "updated_at", "created_by", "updated_by"];
12
+ export type SystemProperty = "id" | "createdAt" | "updatedAt" | "createdBy" | "updatedBy";
13
+ /** Actions the platform generates for every entity; authored actions cannot use these names. */
14
+ export declare const GENERATED_ACTIONS: readonly ["create", "update", "delete", "link", "unlink"];
15
+ /** Prefix of the generated `upsert_by_<property>` actions. */
16
+ export declare const GENERATED_UPSERT_PREFIX = "upsert_by_";
17
+ /** The built-in role every active app user holds. */
18
+ export declare const MEMBER_ROLE = "member";
19
+ /** Implicit human feedback authority; never a stored or assignable role. */
20
+ export declare const FEEDBACK_REPORTER_ROLE = "feedback_reporter";
21
+ /** Suffix reserved for the history table each entity gets. */
22
+ export declare const HISTORY_SUFFIX = "_history";
23
+ /** The combinators of the query language, which take the place of field names in a `where`. */
24
+ export declare const RESERVED_MEMBER_NAMES: readonly ["and", "or", "not"];
25
+ /**
26
+ * The ontology service's route for metric queries across entities, `/api/ontology/query_metrics`,
27
+ * named as the MCP tool is. Each entity with metrics has `/api/ontology/<entity>/query_metrics`.
28
+ */
29
+ export declare const QUERY_METRICS_ROUTE = "query_metrics";
30
+ /** Routes of the ontology service under `/api/ontology/`, which an entity's routes would shadow. */
31
+ export declare const RESERVED_ENTITY_NAMES: readonly ["chat", "query_metrics", "graph", "status", "describe", "openapi", "docs", "mcp", "me", "oauth", "agent", "workflows"];
32
+ /** The MCP tools of every stored entity's reads: `lead_find`, `lead_get` and `lead_history`. */
33
+ export declare const MCP_READ_TOOLS: readonly ["find", "get", "history"];
34
+ /** The MCP tools of the ontology as a whole. No entity tool can take them: they have no underscore. */
35
+ export declare const MCP_GLOBAL_TOOLS: readonly ["discover", "me"];
36
+ /**
37
+ * The metric tools, named as dbt names its MCP tools. Their names have an underscore, so `check`
38
+ * refuses an entity tool that takes one, such as entity `list`'s action `metrics`.
39
+ */
40
+ export declare const MCP_METRIC_TOOLS: readonly ["list_metrics", "get_dimensions", "get_dimension_values", "query_metrics"];
41
+ /** The longest tool name that Claude and OpenAI accept. */
42
+ export declare const MCP_TOOL_NAME_MAX_LENGTH = 64;
43
+ /** The MCP tool of an entity's read or action: `lead_find`, `lead_change_status`. */
44
+ export declare function mcpToolName(entity: string, operation: string): string;
45
+ /** `/api/ontology/<entity>/{id}/history`, which a relationship's traversal would shadow. */
46
+ export declare const RESERVED_RELATIONSHIP_NAMES: readonly ["history"];
47
+ export declare function isSystemProperty(name: string): boolean;
48
+ /** `created_at` → `Created at`, `pilot_request` → `Pilot request`. */
49
+ export declare function humanize(name: string): string;