@mistriwork/engine 0.0.0-stage → 1.0.0-rc.10

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 (546) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -2
  3. package/dist/adapters/adapter.d.ts +693 -0
  4. package/dist/adapters/adapter.js +444 -0
  5. package/dist/adapters/cache/cacheStore.d.ts +75 -0
  6. package/dist/adapters/cache/cacheStore.js +160 -0
  7. package/dist/adapters/cache/resp.d.ts +52 -0
  8. package/dist/adapters/cache/resp.js +237 -0
  9. package/dist/adapters/commands/canonicalJson.d.ts +19 -0
  10. package/dist/adapters/commands/canonicalJson.js +154 -0
  11. package/dist/adapters/connect.d.ts +29 -0
  12. package/dist/adapters/connect.js +40 -0
  13. package/dist/adapters/connectionBudget.d.ts +101 -0
  14. package/dist/adapters/connectionBudget.js +128 -0
  15. package/dist/adapters/dbLatency.d.ts +35 -0
  16. package/dist/adapters/dbLatency.js +79 -0
  17. package/dist/adapters/epochCache.d.ts +50 -0
  18. package/dist/adapters/epochCache.js +85 -0
  19. package/dist/adapters/http/egress.d.ts +48 -0
  20. package/dist/adapters/http/egress.js +175 -0
  21. package/dist/adapters/http/httpAdapter.d.ts +71 -0
  22. package/dist/adapters/http/httpAdapter.js +512 -0
  23. package/dist/adapters/http/httpDescription.d.ts +32 -0
  24. package/dist/adapters/http/httpDescription.js +246 -0
  25. package/dist/adapters/http/openapi.d.ts +98 -0
  26. package/dist/adapters/http/openapi.js +487 -0
  27. package/dist/adapters/layoutRefusal.d.ts +24 -0
  28. package/dist/adapters/layoutRefusal.js +35 -0
  29. package/dist/adapters/net/networkPolicy.d.ts +44 -0
  30. package/dist/adapters/net/networkPolicy.js +123 -0
  31. package/dist/adapters/net/untrustedDatabase.d.ts +18 -0
  32. package/dist/adapters/net/untrustedDatabase.js +120 -0
  33. package/dist/adapters/poolAdmission.d.ts +43 -0
  34. package/dist/adapters/poolAdmission.js +184 -0
  35. package/dist/adapters/poolMetrics.d.ts +121 -0
  36. package/dist/adapters/poolMetrics.js +185 -0
  37. package/dist/adapters/postgres.d.ts +436 -0
  38. package/dist/adapters/postgres.js +1890 -0
  39. package/dist/adapters/postgresCatalog.d.ts +96 -0
  40. package/dist/adapters/postgresCatalog.js +387 -0
  41. package/dist/adapters/postgresCatalogDigest.d.ts +30 -0
  42. package/dist/adapters/postgresCatalogDigest.js +87 -0
  43. package/dist/adapters/postgresCatalogRows.d.ts +62 -0
  44. package/dist/adapters/postgresCatalogRows.js +37 -0
  45. package/dist/adapters/postgresDates.d.ts +1 -0
  46. package/dist/adapters/postgresDates.js +39 -0
  47. package/dist/adapters/postgresMaintenance.d.ts +33 -0
  48. package/dist/adapters/postgresMaintenance.js +179 -0
  49. package/dist/adapters/postgresPool.d.ts +255 -0
  50. package/dist/adapters/postgresPool.js +838 -0
  51. package/dist/adapters/postgresPooler.d.ts +28 -0
  52. package/dist/adapters/postgresPooler.js +267 -0
  53. package/dist/adapters/postgresReadCatalog.d.ts +31 -0
  54. package/dist/adapters/postgresReadCatalog.js +226 -0
  55. package/dist/adapters/postgresReadSnapshot.d.ts +46 -0
  56. package/dist/adapters/postgresReadSnapshot.js +133 -0
  57. package/dist/adapters/postgresSchemaEpoch.d.ts +24 -0
  58. package/dist/adapters/postgresSchemaEpoch.js +149 -0
  59. package/dist/adapters/postgresTransactionHandle.d.ts +173 -0
  60. package/dist/adapters/postgresTransactionHandle.js +524 -0
  61. package/dist/adapters/postgresValues.d.ts +30 -0
  62. package/dist/adapters/postgresValues.js +75 -0
  63. package/dist/adapters/replicas.d.ts +70 -0
  64. package/dist/adapters/replicas.js +208 -0
  65. package/dist/adapters/reservedSql.d.ts +38 -0
  66. package/dist/adapters/reservedSql.js +264 -0
  67. package/dist/adapters/rolePrivileges.d.ts +17 -0
  68. package/dist/adapters/rolePrivileges.js +22 -0
  69. package/dist/adapters/scoped/keyRows.d.ts +65 -0
  70. package/dist/adapters/scoped/keyRows.js +173 -0
  71. package/dist/adapters/scoped/postgresScopeCatalog.d.ts +16 -0
  72. package/dist/adapters/scoped/postgresScopeCatalog.js +117 -0
  73. package/dist/adapters/scoped/scopedCommandOperations.d.ts +5 -0
  74. package/dist/adapters/scoped/scopedCommandOperations.js +48 -0
  75. package/dist/adapters/scoped/scopedReads.d.ts +20 -0
  76. package/dist/adapters/scoped/scopedReads.js +174 -0
  77. package/dist/adapters/scoped/scopedTransaction.d.ts +89 -0
  78. package/dist/adapters/scoped/scopedTransaction.js +303 -0
  79. package/dist/adapters/scoped/sqliteScopeCatalog.d.ts +16 -0
  80. package/dist/adapters/scoped/sqliteScopeCatalog.js +241 -0
  81. package/dist/adapters/scoped/updateGuard.d.ts +3 -0
  82. package/dist/adapters/scoped/updateGuard.js +40 -0
  83. package/dist/adapters/serverSettings.d.ts +45 -0
  84. package/dist/adapters/serverSettings.js +46 -0
  85. package/dist/adapters/sqlite.d.ts +262 -0
  86. package/dist/adapters/sqlite.js +1434 -0
  87. package/dist/adapters/sqliteCostlyReads.d.ts +33 -0
  88. package/dist/adapters/sqliteCostlyReads.js +49 -0
  89. package/dist/adapters/sqliteDecimals.d.ts +22 -0
  90. package/dist/adapters/sqliteDecimals.js +57 -0
  91. package/dist/adapters/sqliteHandles.d.ts +43 -0
  92. package/dist/adapters/sqliteHandles.js +143 -0
  93. package/dist/adapters/sqliteStatementProcess.d.ts +29 -0
  94. package/dist/adapters/sqliteStatementProcess.js +131 -0
  95. package/dist/adapters/statementControl.d.ts +34 -0
  96. package/dist/adapters/statementControl.js +90 -0
  97. package/dist/adapters/storeHost.d.ts +130 -0
  98. package/dist/adapters/storeHost.js +13 -0
  99. package/dist/adapters/telemetry/drivers.d.ts +21 -0
  100. package/dist/adapters/telemetry/drivers.js +321 -0
  101. package/dist/adapters/telemetry/metrics.d.ts +63 -0
  102. package/dist/adapters/telemetry/metrics.js +122 -0
  103. package/dist/adapters/telemetry/otlp.d.ts +12 -0
  104. package/dist/adapters/telemetry/otlp.js +320 -0
  105. package/dist/adapters/telemetry/otlpEncode.d.ts +48 -0
  106. package/dist/adapters/telemetry/otlpEncode.js +366 -0
  107. package/dist/adapters/telemetry/otlpEnv.d.ts +1 -0
  108. package/dist/adapters/telemetry/otlpEnv.js +12 -0
  109. package/dist/adapters/telemetry/serverTiming.d.ts +83 -0
  110. package/dist/adapters/telemetry/serverTiming.js +503 -0
  111. package/dist/adapters/telemetry/start.d.ts +10 -0
  112. package/dist/adapters/telemetry/start.js +25 -0
  113. package/dist/adapters/telemetry/statement.d.ts +16 -0
  114. package/dist/adapters/telemetry/statement.js +134 -0
  115. package/dist/adapters/telemetry/trace.d.ts +127 -0
  116. package/dist/adapters/telemetry/trace.js +295 -0
  117. package/dist/adapters/writeAhead.d.ts +27 -0
  118. package/dist/adapters/writeAhead.js +46 -0
  119. package/dist/adapters/writeAttribution.d.ts +18 -0
  120. package/dist/adapters/writeAttribution.js +23 -0
  121. package/dist/adapters/writeCapture.d.ts +73 -0
  122. package/dist/adapters/writeCapture.js +20 -0
  123. package/dist/adapters/writeLanes.d.ts +94 -0
  124. package/dist/adapters/writeLanes.js +232 -0
  125. package/dist/engine.d.ts +15 -0
  126. package/dist/engine.js +13 -0
  127. package/dist/server/auth/credentials.d.ts +61 -0
  128. package/dist/server/auth/credentials.js +260 -0
  129. package/dist/server/cacheService.d.ts +50 -0
  130. package/dist/server/cacheService.js +110 -0
  131. package/dist/server/cli/args.d.ts +176 -0
  132. package/dist/server/cli/args.js +342 -0
  133. package/dist/server/cli/bin.d.ts +5 -0
  134. package/dist/server/cli/bin.js +66 -0
  135. package/dist/server/cli/browser.d.ts +15 -0
  136. package/dist/server/cli/browser.js +37 -0
  137. package/dist/server/cli/config.d.ts +50 -0
  138. package/dist/server/cli/config.js +206 -0
  139. package/dist/server/cli/startup.d.ts +36 -0
  140. package/dist/server/cli/startup.js +128 -0
  141. package/dist/server/cli/startupOptions.d.ts +63 -0
  142. package/dist/server/cli/startupOptions.js +143 -0
  143. package/dist/server/cli/subcommand.d.ts +28 -0
  144. package/dist/server/cli/subcommand.js +32 -0
  145. package/dist/server/cli/usage.d.ts +13 -0
  146. package/dist/server/cli/usage.js +31 -0
  147. package/dist/server/clientHttp.d.ts +184 -0
  148. package/dist/server/clientHttp.js +700 -0
  149. package/dist/server/clientSurface.d.ts +128 -0
  150. package/dist/server/clientSurface.js +182 -0
  151. package/dist/server/columnGrants.d.ts +103 -0
  152. package/dist/server/columnGrants.js +730 -0
  153. package/dist/server/compileCache.d.ts +1 -0
  154. package/dist/server/compileCache.js +30 -0
  155. package/dist/server/config/locations.d.ts +1 -0
  156. package/dist/server/config/locations.js +15 -0
  157. package/dist/server/configPaths.d.ts +7 -0
  158. package/dist/server/configPaths.js +34 -0
  159. package/dist/server/configSections.d.ts +64 -0
  160. package/dist/server/configSections.js +72 -0
  161. package/dist/server/connectionRedaction.d.ts +30 -0
  162. package/dist/server/connectionRedaction.js +77 -0
  163. package/dist/server/connections.d.ts +353 -0
  164. package/dist/server/connections.js +978 -0
  165. package/dist/server/constraints.d.ts +82 -0
  166. package/dist/server/constraints.js +169 -0
  167. package/dist/server/demo.d.ts +9 -0
  168. package/dist/server/demo.js +554 -0
  169. package/dist/server/devclient.d.ts +108 -0
  170. package/dist/server/devclient.js +361 -0
  171. package/dist/server/evidence.d.ts +55 -0
  172. package/dist/server/evidence.js +323 -0
  173. package/dist/server/hiddenColumns.d.ts +32 -0
  174. package/dist/server/hiddenColumns.js +238 -0
  175. package/dist/server/http/baselineHeaders.d.ts +24 -0
  176. package/dist/server/http/baselineHeaders.js +12 -0
  177. package/dist/server/http/captured.d.ts +35 -0
  178. package/dist/server/http/captured.js +73 -0
  179. package/dist/server/http/clock.d.ts +1 -0
  180. package/dist/server/http/clock.js +14 -0
  181. package/dist/server/http/connectionSource.d.ts +4 -0
  182. package/dist/server/http/connectionSource.js +48 -0
  183. package/dist/server/http/context.d.ts +189 -0
  184. package/dist/server/http/context.js +11 -0
  185. package/dist/server/http/crawlerText.d.ts +15 -0
  186. package/dist/server/http/crawlerText.js +32 -0
  187. package/dist/server/http/dataRoutes.d.ts +88 -0
  188. package/dist/server/http/dataRoutes.js +137 -0
  189. package/dist/server/http/door.d.ts +57 -0
  190. package/dist/server/http/door.js +39 -0
  191. package/dist/server/http/exportRoute.d.ts +15 -0
  192. package/dist/server/http/exportRoute.js +320 -0
  193. package/dist/server/http/firstPaint.d.ts +108 -0
  194. package/dist/server/http/firstPaint.js +262 -0
  195. package/dist/server/http/httpOperationRoutes.d.ts +11 -0
  196. package/dist/server/http/httpOperationRoutes.js +50 -0
  197. package/dist/server/http/pageReads.d.ts +20 -0
  198. package/dist/server/http/pageReads.js +205 -0
  199. package/dist/server/http/pageRoutes.d.ts +39 -0
  200. package/dist/server/http/pageRoutes.js +291 -0
  201. package/dist/server/http/probes.d.ts +22 -0
  202. package/dist/server/http/probes.js +27 -0
  203. package/dist/server/http/rateLimit.d.ts +131 -0
  204. package/dist/server/http/rateLimit.js +351 -0
  205. package/dist/server/http/readRoutes.d.ts +9 -0
  206. package/dist/server/http/readRoutes.js +131 -0
  207. package/dist/server/http/readRouting.d.ts +20 -0
  208. package/dist/server/http/readRouting.js +80 -0
  209. package/dist/server/http/recordCompose.d.ts +67 -0
  210. package/dist/server/http/recordCompose.js +167 -0
  211. package/dist/server/http/recordWrites.d.ts +89 -0
  212. package/dist/server/http/recordWrites.js +298 -0
  213. package/dist/server/http/refusalReport.d.ts +38 -0
  214. package/dist/server/http/refusalReport.js +63 -0
  215. package/dist/server/http/reply.d.ts +130 -0
  216. package/dist/server/http/reply.js +394 -0
  217. package/dist/server/http/requestOrigin.d.ts +11 -0
  218. package/dist/server/http/requestOrigin.js +8 -0
  219. package/dist/server/http/router.d.ts +45 -0
  220. package/dist/server/http/router.js +22 -0
  221. package/dist/server/http/serverCore.d.ts +68 -0
  222. package/dist/server/http/serverCore.js +177 -0
  223. package/dist/server/http/traceRequest.d.ts +30 -0
  224. package/dist/server/http/traceRequest.js +224 -0
  225. package/dist/server/http/trust.d.ts +261 -0
  226. package/dist/server/http/trust.js +472 -0
  227. package/dist/server/http/writeRefusal.d.ts +33 -0
  228. package/dist/server/http/writeRefusal.js +24 -0
  229. package/dist/server/httpConnection.d.ts +49 -0
  230. package/dist/server/httpConnection.js +170 -0
  231. package/dist/server/impact.d.ts +55 -0
  232. package/dist/server/impact.js +47 -0
  233. package/dist/server/journal.d.ts +134 -0
  234. package/dist/server/journal.js +398 -0
  235. package/dist/server/keysetReadHttp.d.ts +52 -0
  236. package/dist/server/keysetReadHttp.js +85 -0
  237. package/dist/server/layouts.d.ts +49 -0
  238. package/dist/server/layouts.js +192 -0
  239. package/dist/server/migrate/cli.d.ts +55 -0
  240. package/dist/server/migrate/cli.js +517 -0
  241. package/dist/server/migrate/database.d.ts +37 -0
  242. package/dist/server/migrate/database.js +247 -0
  243. package/dist/server/migrate/desired.d.ts +76 -0
  244. package/dist/server/migrate/desired.js +292 -0
  245. package/dist/server/migrate/files.d.ts +34 -0
  246. package/dist/server/migrate/files.js +141 -0
  247. package/dist/server/migrate/flyway.d.ts +7 -0
  248. package/dist/server/migrate/flyway.js +69 -0
  249. package/dist/server/migrate/history.d.ts +70 -0
  250. package/dist/server/migrate/history.js +211 -0
  251. package/dist/server/migrate/runner.d.ts +100 -0
  252. package/dist/server/migrate/runner.js +409 -0
  253. package/dist/server/migrate/snapshot.d.ts +30 -0
  254. package/dist/server/migrate/snapshot.js +239 -0
  255. package/dist/server/migrate/target.d.ts +33 -0
  256. package/dist/server/migrate/target.js +82 -0
  257. package/dist/server/openapiDraft.d.ts +25 -0
  258. package/dist/server/openapiDraft.js +171 -0
  259. package/dist/server/operations/diagnostics.d.ts +101 -0
  260. package/dist/server/operations/diagnostics.js +284 -0
  261. package/dist/server/operations/requestMetrics.d.ts +33 -0
  262. package/dist/server/operations/requestMetrics.js +94 -0
  263. package/dist/server/packageVersion.d.ts +1 -0
  264. package/dist/server/packageVersion.js +11 -0
  265. package/dist/server/poolConfig.d.ts +34 -0
  266. package/dist/server/poolConfig.js +114 -0
  267. package/dist/server/product.d.ts +20 -0
  268. package/dist/server/product.js +12 -0
  269. package/dist/server/recordHistoryOperations.d.ts +39 -0
  270. package/dist/server/recordHistoryOperations.js +43 -0
  271. package/dist/server/recordWriteOperations.d.ts +111 -0
  272. package/dist/server/recordWriteOperations.js +329 -0
  273. package/dist/server/resourceReadHttp.d.ts +81 -0
  274. package/dist/server/resourceReadHttp.js +606 -0
  275. package/dist/server/resourceReadOperations.d.ts +147 -0
  276. package/dist/server/resourceReadOperations.js +452 -0
  277. package/dist/server/scaffoldMachine.d.ts +54 -0
  278. package/dist/server/scaffoldMachine.js +184 -0
  279. package/dist/server/seed/cli.d.ts +20 -0
  280. package/dist/server/seed/cli.js +164 -0
  281. package/dist/server/seed/lexicon.d.ts +26 -0
  282. package/dist/server/seed/lexicon.js +585 -0
  283. package/dist/server/seed/seed.d.ts +70 -0
  284. package/dist/server/seed/seed.js +779 -0
  285. package/dist/server/seed/words.d.ts +21 -0
  286. package/dist/server/seed/words.js +164 -0
  287. package/dist/server/serverRequests.d.ts +6 -0
  288. package/dist/server/serverRequests.js +33 -0
  289. package/dist/server/serverTimeouts.d.ts +33 -0
  290. package/dist/server/serverTimeouts.js +32 -0
  291. package/dist/server/shapeonly.d.ts +32 -0
  292. package/dist/server/shapeonly.js +110 -0
  293. package/dist/server/startupWarnings.d.ts +32 -0
  294. package/dist/server/startupWarnings.js +92 -0
  295. package/dist/shared/addressParams.d.ts +28 -0
  296. package/dist/shared/addressParams.js +47 -0
  297. package/dist/shared/appCards.d.ts +123 -0
  298. package/dist/shared/appCards.js +385 -0
  299. package/dist/shared/appComponents.d.ts +177 -0
  300. package/dist/shared/appComponents.js +422 -0
  301. package/dist/shared/appDocuments.d.ts +43 -0
  302. package/dist/shared/appDocuments.js +131 -0
  303. package/dist/shared/appEmbeds.d.ts +21 -0
  304. package/dist/shared/appEmbeds.js +24 -0
  305. package/dist/shared/appIcons.d.ts +28 -0
  306. package/dist/shared/appIcons.js +223 -0
  307. package/dist/shared/appLinks.d.ts +17 -0
  308. package/dist/shared/appLinks.js +124 -0
  309. package/dist/shared/appListColumns.d.ts +3 -0
  310. package/dist/shared/appListColumns.js +66 -0
  311. package/dist/shared/appLocale.d.ts +36 -0
  312. package/dist/shared/appLocale.js +86 -0
  313. package/dist/shared/appMessages.d.ts +44 -0
  314. package/dist/shared/appMessages.js +78 -0
  315. package/dist/shared/appNoun.d.ts +21 -0
  316. package/dist/shared/appNoun.js +32 -0
  317. package/dist/shared/autoBucket.d.ts +98 -0
  318. package/dist/shared/autoBucket.js +305 -0
  319. package/dist/shared/autoValues.d.ts +25 -0
  320. package/dist/shared/autoValues.js +25 -0
  321. package/dist/shared/breakdown.d.ts +228 -0
  322. package/dist/shared/breakdown.js +557 -0
  323. package/dist/shared/breakdowntext.d.ts +41 -0
  324. package/dist/shared/breakdowntext.js +400 -0
  325. package/dist/shared/builtInThemes.d.ts +2 -0
  326. package/dist/shared/builtInThemes.js +771 -0
  327. package/dist/shared/chartSeparation.d.ts +11 -0
  328. package/dist/shared/chartSeparation.js +58 -0
  329. package/dist/shared/clauses.d.ts +22 -0
  330. package/dist/shared/clauses.js +97 -0
  331. package/dist/shared/columnCaption.d.ts +16 -0
  332. package/dist/shared/columnCaption.js +90 -0
  333. package/dist/shared/commandFieldPath.d.ts +2 -0
  334. package/dist/shared/commandFieldPath.js +7 -0
  335. package/dist/shared/commandWire.d.ts +26 -0
  336. package/dist/shared/commandWire.js +41 -0
  337. package/dist/shared/computed.d.ts +161 -0
  338. package/dist/shared/computed.js +378 -0
  339. package/dist/shared/computedParse.d.ts +13 -0
  340. package/dist/shared/computedParse.js +278 -0
  341. package/dist/shared/computedValue.d.ts +47 -0
  342. package/dist/shared/computedValue.js +191 -0
  343. package/dist/shared/connection.d.ts +30 -0
  344. package/dist/shared/connection.js +1 -0
  345. package/dist/shared/csv.d.ts +20 -0
  346. package/dist/shared/csv.js +63 -0
  347. package/dist/shared/dashLayout.d.ts +30 -0
  348. package/dist/shared/dashLayout.js +132 -0
  349. package/dist/shared/dashboardAsks.d.ts +93 -0
  350. package/dist/shared/dashboardAsks.js +129 -0
  351. package/dist/shared/dashboardTrend.d.ts +20 -0
  352. package/dist/shared/dashboardTrend.js +50 -0
  353. package/dist/shared/declaredReferences.d.ts +50 -0
  354. package/dist/shared/declaredReferences.js +202 -0
  355. package/dist/shared/definedFields.d.ts +63 -0
  356. package/dist/shared/definedFields.js +103 -0
  357. package/dist/shared/definedValues.d.ts +63 -0
  358. package/dist/shared/definedValues.js +184 -0
  359. package/dist/shared/displayDefaults.d.ts +135 -0
  360. package/dist/shared/displayDefaults.js +529 -0
  361. package/dist/shared/dueDate.d.ts +6 -0
  362. package/dist/shared/dueDate.js +6 -0
  363. package/dist/shared/duration.d.ts +4 -0
  364. package/dist/shared/duration.js +23 -0
  365. package/dist/shared/fileBounds.d.ts +9 -0
  366. package/dist/shared/fileBounds.js +9 -0
  367. package/dist/shared/filter.d.ts +217 -0
  368. package/dist/shared/filter.js +305 -0
  369. package/dist/shared/firstPaint.d.ts +24 -0
  370. package/dist/shared/firstPaint.js +33 -0
  371. package/dist/shared/form.d.ts +21 -0
  372. package/dist/shared/form.js +25 -0
  373. package/dist/shared/formValues.d.ts +104 -0
  374. package/dist/shared/formValues.js +352 -0
  375. package/dist/shared/funnel.d.ts +45 -0
  376. package/dist/shared/funnel.js +108 -0
  377. package/dist/shared/httpOperations.d.ts +48 -0
  378. package/dist/shared/httpOperations.js +9 -0
  379. package/dist/shared/iconGlyphs.d.ts +4 -0
  380. package/dist/shared/iconGlyphs.js +151 -0
  381. package/dist/shared/iconWeights.d.ts +3 -0
  382. package/dist/shared/iconWeights.js +162 -0
  383. package/dist/shared/imageWidths.d.ts +32 -0
  384. package/dist/shared/imageWidths.js +38 -0
  385. package/dist/shared/keysetPage.d.ts +64 -0
  386. package/dist/shared/keysetPage.js +161 -0
  387. package/dist/shared/like.d.ts +20 -0
  388. package/dist/shared/like.js +29 -0
  389. package/dist/shared/listEmpty.d.ts +12 -0
  390. package/dist/shared/listEmpty.js +36 -0
  391. package/dist/shared/listFilters.d.ts +28 -0
  392. package/dist/shared/listFilters.js +84 -0
  393. package/dist/shared/listPresentations.d.ts +199 -0
  394. package/dist/shared/listPresentations.js +7 -0
  395. package/dist/shared/listQuestion.d.ts +52 -0
  396. package/dist/shared/listQuestion.js +137 -0
  397. package/dist/shared/lookPalettes.d.ts +62 -0
  398. package/dist/shared/lookPalettes.js +306 -0
  399. package/dist/shared/maskQuoted.d.ts +24 -0
  400. package/dist/shared/maskQuoted.js +48 -0
  401. package/dist/shared/mentionLabel.d.ts +19 -0
  402. package/dist/shared/mentionLabel.js +38 -0
  403. package/dist/shared/mentionLookup.d.ts +17 -0
  404. package/dist/shared/mentionLookup.js +64 -0
  405. package/dist/shared/menuCounts.d.ts +16 -0
  406. package/dist/shared/menuCounts.js +74 -0
  407. package/dist/shared/model.d.ts +79 -0
  408. package/dist/shared/model.js +153 -0
  409. package/dist/shared/money.d.ts +44 -0
  410. package/dist/shared/money.js +81 -0
  411. package/dist/shared/moneyEntry.d.ts +7 -0
  412. package/dist/shared/moneyEntry.js +27 -0
  413. package/dist/shared/mount.d.ts +118 -0
  414. package/dist/shared/mount.js +248 -0
  415. package/dist/shared/niceTicks.d.ts +26 -0
  416. package/dist/shared/niceTicks.js +50 -0
  417. package/dist/shared/order.d.ts +59 -0
  418. package/dist/shared/order.js +133 -0
  419. package/dist/shared/page.d.ts +135 -0
  420. package/dist/shared/page.js +1187 -0
  421. package/dist/shared/pageAnatomy.d.ts +99 -0
  422. package/dist/shared/pageAnatomy.js +370 -0
  423. package/dist/shared/pageConfig.d.ts +25 -0
  424. package/dist/shared/pageConfig.js +1308 -0
  425. package/dist/shared/pageEmptyActions.d.ts +12 -0
  426. package/dist/shared/pageEmptyActions.js +20 -0
  427. package/dist/shared/pageLayouts.d.ts +72 -0
  428. package/dist/shared/pageLayouts.js +205 -0
  429. package/dist/shared/pageModel.d.ts +785 -0
  430. package/dist/shared/pageModel.js +121 -0
  431. package/dist/shared/pagePaths.d.ts +180 -0
  432. package/dist/shared/pagePaths.js +869 -0
  433. package/dist/shared/pagePlans.d.ts +52 -0
  434. package/dist/shared/pagePlans.js +108 -0
  435. package/dist/shared/pageRoutes.d.ts +9 -0
  436. package/dist/shared/pageRoutes.js +9 -0
  437. package/dist/shared/query.d.ts +166 -0
  438. package/dist/shared/query.js +1302 -0
  439. package/dist/shared/queryDates.d.ts +12 -0
  440. package/dist/shared/queryDates.js +101 -0
  441. package/dist/shared/queryOperands.d.ts +99 -0
  442. package/dist/shared/queryOperands.js +131 -0
  443. package/dist/shared/reads.d.ts +103 -0
  444. package/dist/shared/reads.js +154 -0
  445. package/dist/shared/recordLabel.d.ts +51 -0
  446. package/dist/shared/recordLabel.js +123 -0
  447. package/dist/shared/recordReadKeys.d.ts +30 -0
  448. package/dist/shared/recordReadKeys.js +51 -0
  449. package/dist/shared/recordReads.d.ts +268 -0
  450. package/dist/shared/recordReads.js +368 -0
  451. package/dist/shared/recordview.d.ts +198 -0
  452. package/dist/shared/recordview.js +356 -0
  453. package/dist/shared/referenceModel.d.ts +58 -0
  454. package/dist/shared/referenceModel.js +194 -0
  455. package/dist/shared/refusal.d.ts +64 -0
  456. package/dist/shared/refusal.js +144 -0
  457. package/dist/shared/relatedCreate.d.ts +30 -0
  458. package/dist/shared/relatedCreate.js +162 -0
  459. package/dist/shared/resourceHttp.d.ts +464 -0
  460. package/dist/shared/resourceHttp.js +1 -0
  461. package/dist/shared/richText.d.ts +85 -0
  462. package/dist/shared/richText.js +305 -0
  463. package/dist/shared/rollups.d.ts +143 -0
  464. package/dist/shared/rollups.js +64 -0
  465. package/dist/shared/rowScope.d.ts +72 -0
  466. package/dist/shared/rowScope.js +376 -0
  467. package/dist/shared/runtimeTables.d.ts +44 -0
  468. package/dist/shared/runtimeTables.js +79 -0
  469. package/dist/shared/schema.d.ts +523 -0
  470. package/dist/shared/schema.js +627 -0
  471. package/dist/shared/schematext.d.ts +38 -0
  472. package/dist/shared/schematext.js +101 -0
  473. package/dist/shared/scopeCatalog.d.ts +29 -0
  474. package/dist/shared/scopeCatalog.js +468 -0
  475. package/dist/shared/servedApp.d.ts +681 -0
  476. package/dist/shared/servedApp.js +45 -0
  477. package/dist/shared/sessionLease.d.ts +34 -0
  478. package/dist/shared/sessionLease.js +3 -0
  479. package/dist/shared/shape.d.ts +55 -0
  480. package/dist/shared/shape.js +168 -0
  481. package/dist/shared/slug.d.ts +1 -0
  482. package/dist/shared/slug.js +12 -0
  483. package/dist/shared/sortText.d.ts +14 -0
  484. package/dist/shared/sortText.js +26 -0
  485. package/dist/shared/sqlRelation.d.ts +4 -0
  486. package/dist/shared/sqlRelation.js +8 -0
  487. package/dist/shared/sqlsaved.d.ts +44 -0
  488. package/dist/shared/sqlsaved.js +63 -0
  489. package/dist/shared/stitchedPaths.d.ts +27 -0
  490. package/dist/shared/stitchedPaths.js +38 -0
  491. package/dist/shared/structuredFilter.d.ts +22 -0
  492. package/dist/shared/structuredFilter.js +1 -0
  493. package/dist/shared/subtitlePath.d.ts +20 -0
  494. package/dist/shared/subtitlePath.js +24 -0
  495. package/dist/shared/suggest.d.ts +18 -0
  496. package/dist/shared/suggest.js +59 -0
  497. package/dist/shared/tableSizing.d.ts +4 -0
  498. package/dist/shared/tableSizing.js +9 -0
  499. package/dist/shared/tagLists.d.ts +57 -0
  500. package/dist/shared/tagLists.js +34 -0
  501. package/dist/shared/textRules.d.ts +54 -0
  502. package/dist/shared/textRules.js +133 -0
  503. package/dist/shared/theme.d.ts +94 -0
  504. package/dist/shared/theme.js +800 -0
  505. package/dist/shared/themeColor.d.ts +34 -0
  506. package/dist/shared/themeColor.js +109 -0
  507. package/dist/shared/themeFaces.d.ts +30 -0
  508. package/dist/shared/themeFaces.js +42 -0
  509. package/dist/shared/themeInk.d.ts +20 -0
  510. package/dist/shared/themeInk.js +52 -0
  511. package/dist/shared/themeLooks.d.ts +9 -0
  512. package/dist/shared/themeLooks.js +572 -0
  513. package/dist/shared/themeParts.d.ts +26 -0
  514. package/dist/shared/themeParts.js +71 -0
  515. package/dist/shared/themePartsCheck.d.ts +21 -0
  516. package/dist/shared/themePartsCheck.js +91 -0
  517. package/dist/shared/themePresets.d.ts +85 -0
  518. package/dist/shared/themePresets.js +139 -0
  519. package/dist/shared/themeRecipeWords.d.ts +156 -0
  520. package/dist/shared/themeRecipeWords.js +156 -0
  521. package/dist/shared/themeRecipes.d.ts +213 -0
  522. package/dist/shared/themeRecipes.js +234 -0
  523. package/dist/shared/themeResolve.d.ts +55 -0
  524. package/dist/shared/themeResolve.js +52 -0
  525. package/dist/shared/themeTokens.d.ts +107 -0
  526. package/dist/shared/themeTokens.js +116 -0
  527. package/dist/shared/themeType.d.ts +38 -0
  528. package/dist/shared/themeType.js +205 -0
  529. package/dist/shared/unitWord.d.ts +4 -0
  530. package/dist/shared/unitWord.js +37 -0
  531. package/dist/shared/view.d.ts +195 -0
  532. package/dist/shared/view.js +987 -0
  533. package/dist/shared/viewLabels.d.ts +47 -0
  534. package/dist/shared/viewLabels.js +459 -0
  535. package/dist/shared/viewPaths.d.ts +248 -0
  536. package/dist/shared/viewPaths.js +294 -0
  537. package/dist/shared/viewtext.d.ts +57 -0
  538. package/dist/shared/viewtext.js +282 -0
  539. package/dist/shared/vocabulary.d.ts +71 -0
  540. package/dist/shared/vocabulary.js +249 -0
  541. package/dist/shared/weekStart.d.ts +7 -0
  542. package/dist/shared/weekStart.js +36 -0
  543. package/mark.svg +1 -0
  544. package/package.json +261 -4
  545. package/schema/model.d.ts +298 -0
  546. package/schema/theme.d.ts +587 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The seam an App store stands on: what a dialect adapter lends the stores
3
+ * that live in its database — the notification inbox, branding, the record
4
+ * history, the command journal and a public placement's — without knowing
5
+ * any of them.
6
+ *
7
+ * The stores are the App framework's (packages/mistri/src/server/stores/appStores.ts and
8
+ * the store folders under src/adapters); the adapter is the engine's, and the
9
+ * database browser opens the same adapter with no App framework installed.
10
+ * So the adapter offers its clients, its write queue and the schema-epoch
11
+ * cache it already keeps, and a store names its own meta row when it asks
12
+ * for an attested read. The adapter learns no store's tables from here.
13
+ *
14
+ * A host is kept beside its adapter rather than on it: a facade or a proxy
15
+ * that forwards an adapter's methods does not forward its host, so only the
16
+ * adapter that was constructed can lend its writer.
17
+ */
18
+ import type { DatabaseSync } from 'node:sqlite';
19
+ import type { TransactionOperations, WriteTransaction } from './adapter.js';
20
+ import type { PostgresReadSnapshot, PostgresTransactionVerifier } from './postgres.js';
21
+ import type { PgQuery } from './postgresPool.js';
22
+ import type { PostgresScopeCatalog } from './scoped/postgresScopeCatalog.js';
23
+ import type { SqliteScopeCatalog } from './scoped/sqliteScopeCatalog.js';
24
+ import type { DatabaseSchema } from '../shared/schema.js';
25
+ import type { RowScope } from '../shared/rowScope.js';
26
+ /** A reserved store's meta row: the one row whose version says the layout, and the cache key its attestation is kept under. */
27
+ export interface StoreMeta {
28
+ readonly name: string;
29
+ readonly table: string;
30
+ readonly version: number;
31
+ }
32
+ /**
33
+ * A journal kept in a write transaction beside its records: the command
34
+ * journal, or a public placement's. The adapter runs the transaction — its
35
+ * BEGIN, the schema epoch, the scope, the drain, the COMMIT and the outcome —
36
+ * and the journal is the App framework's: its tables, the SQL that attests
37
+ * them and the object a command writes its receipt through.
38
+ */
39
+ interface TransactionJournal<W, C, J> {
40
+ /** The meta row read with the schema epoch, so the layout is attested once per epoch; without one, it is attested in every transaction. */
41
+ readonly meta?: StoreMeta;
42
+ /** The layout attested on the writer, after BEGIN and before the scope catalog is read: an unmigrated or altered layout refuses without a write. */
43
+ attest(writer: W): void | Promise<void>;
44
+ /** A scoped transaction's admission, after the scope catalog is read and verified, before the callback. */
45
+ admit?(writer: W, catalog: C, scope: RowScope): void | Promise<void>;
46
+ /** A journal that writes exactly fixed rows (a public intake's): its scoped records pass through this, and no new parent is counted into the principal's scope. */
47
+ fixedRecords?(records: WriteTransaction): WriteTransaction;
48
+ /** The journal over the writer and the operation queue its records share; `verified` is a verified scoped transaction's fence. */
49
+ open(writer: W, operations: TransactionOperations, verified?: () => void): J;
50
+ /** What a failed transaction throws, told whether it might have committed. */
51
+ failure(error: unknown, outcome: 'unknown' | 'not_applied'): unknown;
52
+ /**
53
+ * The statements the journal's first lookup of `receipt` sends, exactly, so
54
+ * they leave behind the transaction's BEGIN (writeAhead.ts): none for a
55
+ * receipt it would refuse. Its shape is the journal's own.
56
+ */
57
+ ahead?(receipt: unknown): readonly (string | Readonly<{
58
+ text: string;
59
+ values?: readonly unknown[];
60
+ }>)[];
61
+ }
62
+ export type PostgresTransactionJournal<J> = TransactionJournal<PgQuery, PostgresScopeCatalog, J>;
63
+ export type SqliteTransactionJournal<J> = TransactionJournal<DatabaseSync, SqliteScopeCatalog, J>;
64
+ /** How a journal transaction is shaped: ordinary, or over a row scope. */
65
+ export interface JournalTransactionOptions<V> {
66
+ /** A row-scoped transaction: the scope's records, with the catalog evidence handed to the callback. */
67
+ readonly scope?: RowScope;
68
+ /** The outer bound the scope sits inside (scopedTransaction.ts ScopeBound), over the same tables. */
69
+ readonly bound?: RowScope;
70
+ /** A verified scoped transaction's trusted host check; its failures are not the journal's. */
71
+ readonly verify?: V;
72
+ /** A verified ordinary transaction's trusted host check, after BEGIN and again before COMMIT. */
73
+ readonly ordinaryVerify?: () => unknown;
74
+ }
75
+ /** The callback: the records, the journal, and a scoped transaction's catalog evidence (absent in an ordinary one). */
76
+ export type JournalRun<J, T> = (records: WriteTransaction, journal: J, catalog?: DatabaseSchema) => Promise<T>;
77
+ export interface PostgresStoreHost {
78
+ readonly dialect: 'postgres';
79
+ withReadClient<T>(work: (client: PgQuery) => Promise<T>): Promise<T>;
80
+ withWriteClient<T>(work: (client: PgQuery) => Promise<T>): Promise<T>;
81
+ /** `read`, told whether the store's layout stands attested under the schema epoch read first on `client`. */
82
+ attestedStore<T>(client: PgQuery, store: StoreMeta, read: (attested: boolean) => Promise<T>): Promise<T>;
83
+ /** Whether this is the constructed adapter over the connections it was built with: the only one a verified transaction runs on. */
84
+ verifiedSource(): boolean;
85
+ /** Records and a journal in one transaction (PostgresAdapter.journalTransaction). */
86
+ journalTransaction<J, T>(journal: PostgresTransactionJournal<J>, run: JournalRun<J, T>, options?: JournalTransactionOptions<PostgresTransactionVerifier>): Promise<T>;
87
+ /** Whether the connection names any replica: where it names none, `onHealthyReplicas` can only answer nothing, and a caller can skip the question that needs it. */
88
+ hasReplicas(): boolean;
89
+ /** `work` on each healthy replica, failures left out; none where the connection names no replicas. */
90
+ onHealthyReplicas<T>(work: (client: PgQuery) => Promise<T>): Promise<T[]>;
91
+ /** One read-only snapshot on an observed reader (PostgresAdapter.readSnapshot). */
92
+ readSnapshot<T>(run: (snapshot: PostgresReadSnapshot) => Promise<T>): Promise<T>;
93
+ }
94
+ export interface SqliteStoreHost {
95
+ readonly dialect: 'sqlite';
96
+ /** The read-only handle. */
97
+ reader(): DatabaseSync;
98
+ /** `work` in the write queue, on the writer. */
99
+ queueWrite<T>(work: (write: DatabaseSync) => T | Promise<T>): Promise<T>;
100
+ /** As PostgresStoreHost's, synchronous, on `db` (the reader unless a writer is named). */
101
+ attestedStore<T>(store: StoreMeta, read: (attested: boolean) => T, db?: DatabaseSync): T;
102
+ /** The file, for a reader of its own (a receipt's recovery). */
103
+ file(): string;
104
+ closed(): boolean;
105
+ /** Refuses once the path names another file than the one opened. */
106
+ assertWriteIdentity(): void;
107
+ /** Records and a journal in one transaction (SqliteAdapter.transact). */
108
+ journalTransaction<J, T>(journal: SqliteTransactionJournal<J>, run: JournalRun<J, T>, options?: JournalTransactionOptions<(db: DatabaseSync, catalog: SqliteScopeCatalog) => void>): Promise<T>;
109
+ }
110
+ export type StoreHost = PostgresStoreHost | SqliteStoreHost;
111
+ /** The adapter's constructor only: the host it lends its stores. */
112
+ export declare function lendStoreHost(adapter: object, host: StoreHost): void;
113
+ /** The host a constructed adapter lent, or undefined for anything else (a facade, a proxy, an HTTP source). */
114
+ export declare const storeHostOf: (adapter: unknown) => StoreHost | undefined;
115
+ /**
116
+ * An engine wrapper that narrows what an adapter's writes may touch (hidden
117
+ * columns) lends the view here, so a store that runs work in its own
118
+ * transactions — the command journal — hands that work the narrowed records
119
+ * and catalog and never the adapter's own. The wrapper cannot carry the
120
+ * store's members itself: the engine does not name the stores.
121
+ */
122
+ interface WriteView {
123
+ readonly over: object;
124
+ records(records: WriteTransaction): WriteTransaction;
125
+ catalog(catalog: DatabaseSchema): DatabaseSchema;
126
+ }
127
+ /** The wrapper's constructor only. */
128
+ export declare function lendWriteView(wrapped: object, view: WriteView): void;
129
+ export declare const writeViewOf: (wrapped: unknown) => WriteView | undefined;
130
+ export {};
@@ -0,0 +1,13 @@
1
+ const hosts = new WeakMap();
2
+ /** The adapter's constructor only: the host it lends its stores. */
3
+ export function lendStoreHost(adapter, host) {
4
+ hosts.set(adapter, Object.freeze(host));
5
+ }
6
+ /** The host a constructed adapter lent, or undefined for anything else (a facade, a proxy, an HTTP source). */
7
+ export const storeHostOf = (adapter) => typeof adapter === 'object' && adapter !== null ? hosts.get(adapter) : undefined;
8
+ const views = new WeakMap();
9
+ /** The wrapper's constructor only. */
10
+ export function lendWriteView(wrapped, view) {
11
+ views.set(wrapped, Object.freeze(view));
12
+ }
13
+ export const writeViewOf = (wrapped) => typeof wrapped === 'object' && wrapped !== null ? views.get(wrapped) : undefined;
@@ -0,0 +1,21 @@
1
+ /** The plan of a statement the observer recorded, run read-only; undefined when it can no longer be asked. */
2
+ export declare function explainStatement(spanId: string): Promise<string[] | undefined>;
3
+ /** Wrap the drivers once, for the life of the process. */
4
+ export declare function instrumentDrivers(): void;
5
+ interface PgClientLike {
6
+ query(...args: unknown[]): unknown;
7
+ connectionParameters?: Record<string, unknown>;
8
+ }
9
+ type PgClientClass = {
10
+ prototype: PgClientLike;
11
+ } & (new (config: unknown) => PgClientLike & {
12
+ connect(): Promise<void>;
13
+ end(): Promise<void>;
14
+ });
15
+ export declare function instrumentPg(pg: {
16
+ Client?: PgClientClass;
17
+ Pool?: {
18
+ prototype: Record<string, unknown>;
19
+ };
20
+ }): void;
21
+ export {};
@@ -0,0 +1,321 @@
1
+ /**
2
+ * A span for every statement the process runs, whichever of the three
3
+ * drivers runs it: node:sqlite and pg.
4
+ *
5
+ * At the driver, not in each adapter, because statements reach the database
6
+ * from dozens of places — the adapters, the command journal, the auth store,
7
+ * the job and event stores — and a span added to each would be a span
8
+ * forgotten in the next. Wrapping the driver's own `query` is also how the
9
+ * vendors' agents do it (dd-trace, OneAgent), and the wrappers chain: each
10
+ * keeps the function it found, so an agent loaded first or last still sees
11
+ * every call, and the modules keep their identity.
12
+ *
13
+ * Installed only when something listens (start.ts), and a statement is a
14
+ * span only inside another one — a request, a job, a command. Startup's
15
+ * catalog reads are not a trace anyone asked for.
16
+ *
17
+ * What travels: `db.system.name`, `db.operation.name`, `db.collection.name`,
18
+ * `db.query.summary` (statement.ts). What stays local, for the dev observer:
19
+ * the text, the parameters, the rows returned, the transaction, and a way to
20
+ * EXPLAIN it later.
21
+ */
22
+ import { AsyncResource } from 'node:async_hooks';
23
+ import { createRequire } from 'node:module';
24
+ import { DatabaseSync, StatementSync } from 'node:sqlite';
25
+ import { startSpan, observing, currentSpan } from './trace.js';
26
+ import { summarizeStatement } from './statement.js';
27
+ /** How to EXPLAIN a statement the observer shows, by its span. Bounded, and filled only while observing. */
28
+ const explainers = new Map();
29
+ const EXPLAINERS = 4000;
30
+ function keepExplainer(spanId, explain) {
31
+ explainers.set(spanId, explain);
32
+ if (explainers.size > EXPLAINERS)
33
+ explainers.delete(explainers.keys().next().value);
34
+ }
35
+ /** The plan of a statement the observer recorded, run read-only; undefined when it can no longer be asked. */
36
+ export async function explainStatement(spanId) {
37
+ const explain = explainers.get(spanId);
38
+ return explain ? explain() : undefined;
39
+ }
40
+ const EXPLAINABLE = new Set(['SELECT', 'WITH']);
41
+ /** A statement's span, begun but not made current: a statement has no children. The caller ends it. */
42
+ function beginStatement(dialect, text, params, explain) {
43
+ const { operation, table, summary } = summarizeStatement(text);
44
+ const span = startSpan(summary, {
45
+ kind: 'client',
46
+ childOnly: true,
47
+ attributes: {
48
+ 'db.system.name': dialect,
49
+ 'db.operation.name': operation,
50
+ 'db.collection.name': table,
51
+ 'db.query.summary': summary,
52
+ },
53
+ });
54
+ if (span.recording) {
55
+ span.detail(() => ({
56
+ sql: text.length > 20_000 ? `${text.slice(0, 20_000)}…` : text,
57
+ ...(params !== undefined ? { params: Array.isArray(params) ? params.slice(0, 200) : params } : {}),
58
+ }));
59
+ if (observing() && EXPLAINABLE.has(operation)) {
60
+ const explainer = explain?.(span);
61
+ if (explainer)
62
+ keepExplainer(span.spanId, explainer);
63
+ }
64
+ }
65
+ return span;
66
+ }
67
+ /** Settle a statement's span with its promise. */
68
+ function settle(span, out) {
69
+ if (!out || typeof out.then !== 'function') {
70
+ span.end();
71
+ return out;
72
+ }
73
+ return out.then((result) => {
74
+ noteRows(span, result);
75
+ span.end();
76
+ return result;
77
+ }, (error) => {
78
+ span.fail(errorKind(error), error);
79
+ span.end();
80
+ throw error;
81
+ });
82
+ }
83
+ const rowsOf = (result) => {
84
+ if (Array.isArray(result))
85
+ return result.length;
86
+ if (result && typeof result === 'object') {
87
+ const r = result;
88
+ if (typeof r.rowCount === 'number')
89
+ return r.rowCount;
90
+ if (Array.isArray(r.rows))
91
+ return r.rows.length;
92
+ if (typeof r.affectedRows === 'number')
93
+ return r.affectedRows;
94
+ if (typeof r.changes === 'number' || typeof r.changes === 'bigint')
95
+ return Number(r.changes);
96
+ }
97
+ return undefined;
98
+ };
99
+ const noteRows = (span, result) => {
100
+ const rows = rowsOf(result);
101
+ if (rows !== undefined) {
102
+ span.setAttribute('db.response.returned_rows', rows);
103
+ span.detail(() => ({ rows }));
104
+ }
105
+ };
106
+ let installed = false;
107
+ /** Wrap the drivers once, for the life of the process. */
108
+ export function instrumentDrivers() {
109
+ if (installed)
110
+ return;
111
+ installed = true;
112
+ instrumentSqlite();
113
+ const require = createRequire(import.meta.url);
114
+ try {
115
+ instrumentPg(require('pg'));
116
+ }
117
+ catch {
118
+ /* pg is optional */
119
+ }
120
+ }
121
+ /**
122
+ * A pool's checkout, bound to whoever asked for it. A pool that is full
123
+ * queues the waiter and calls it back when another request releases its
124
+ * connection — from inside that request's release, and so inside its async
125
+ * context. `pool.query` asks through that callback, so without this its
126
+ * statement was counted in the releasing request's trace (a finished one,
127
+ * often) and never in its own, and a busy row-policy App's traces showed
128
+ * N+1 patterns that were only other requests' lookups. A promise checkout
129
+ * needs nothing: `await` resumes in the awaiting context.
130
+ */
131
+ function bindCheckouts(proto, method) {
132
+ const original = proto?.[method];
133
+ if (!proto || typeof original !== 'function')
134
+ return;
135
+ proto[method] = function (...args) {
136
+ const at = args.findIndex((arg) => typeof arg === 'function');
137
+ // Bound whether or not a span is current: a waiter outside any request must not land in the releaser's either.
138
+ if (at >= 0)
139
+ args[at] = AsyncResource.bind(args[at]);
140
+ return original.apply(this, args);
141
+ };
142
+ }
143
+ /* ---------- node:sqlite ---------- */
144
+ const statementDb = new WeakMap();
145
+ const sqliteTx = new WeakMap();
146
+ let sqliteIds = 0;
147
+ function sqliteTransaction(db) {
148
+ if (!db)
149
+ return undefined;
150
+ let state = sqliteTx.get(db);
151
+ if (!state)
152
+ sqliteTx.set(db, (state = { n: 0, open: false, id: ++sqliteIds }));
153
+ let inside = false;
154
+ try {
155
+ inside = db.isTransaction;
156
+ }
157
+ catch {
158
+ return undefined;
159
+ }
160
+ if (inside && !state.open)
161
+ state.n++;
162
+ state.open = inside;
163
+ return inside ? `sqlite:${state.id}/tx${state.n}` : undefined;
164
+ }
165
+ function instrumentSqlite() {
166
+ const prepare = DatabaseSync.prototype.prepare;
167
+ DatabaseSync.prototype.prepare = function (...args) {
168
+ const statement = prepare.apply(this, args);
169
+ if (currentSpan())
170
+ statementDb.set(statement, new WeakRef(this));
171
+ return statement;
172
+ };
173
+ const exec = DatabaseSync.prototype.exec;
174
+ DatabaseSync.prototype.exec = function (sql) {
175
+ if (!currentSpan())
176
+ return exec.call(this, sql);
177
+ const span = beginStatement('sqlite', sql, undefined);
178
+ try {
179
+ const out = exec.call(this, sql);
180
+ const tx = sqliteTransaction(this);
181
+ if (tx)
182
+ span.detail(() => ({ transaction: tx }));
183
+ return out;
184
+ }
185
+ catch (error) {
186
+ span.fail(errorKind(error), error);
187
+ throw error;
188
+ }
189
+ finally {
190
+ span.end();
191
+ }
192
+ };
193
+ for (const method of ['all', 'get', 'run']) {
194
+ const original = StatementSync.prototype[method];
195
+ StatementSync.prototype[method] = function (...args) {
196
+ if (!currentSpan())
197
+ return original.apply(this, args);
198
+ const db = statementDb.get(this)?.deref();
199
+ const text = this.sourceSQL;
200
+ const ref = statementDb.get(this);
201
+ const span = beginStatement('sqlite', text, args, () => ref
202
+ ? () => {
203
+ const target = ref.deref();
204
+ if (!target || !target.isOpen)
205
+ return Promise.resolve(['The database this ran on is closed.']);
206
+ const rows = prepare.call(target, `EXPLAIN QUERY PLAN ${text}`).all(...args);
207
+ const depth = new Map();
208
+ return Promise.resolve(rows.map((row) => {
209
+ const level = (depth.get(row.parent) ?? -1) + 1;
210
+ depth.set(row.id, level);
211
+ return `${' '.repeat(level)}${row.detail}`;
212
+ }));
213
+ }
214
+ : undefined);
215
+ try {
216
+ const tx = sqliteTransaction(db);
217
+ const result = original.apply(this, args);
218
+ if (method === 'get') {
219
+ span.setAttribute('db.response.returned_rows', result === undefined ? 0 : 1);
220
+ span.detail(() => ({ rows: result === undefined ? 0 : 1 }));
221
+ }
222
+ else
223
+ noteRows(span, result);
224
+ if (tx)
225
+ span.detail(() => ({ transaction: tx }));
226
+ return result;
227
+ }
228
+ catch (error) {
229
+ span.fail(errorKind(error), error);
230
+ throw error;
231
+ }
232
+ finally {
233
+ span.end();
234
+ }
235
+ };
236
+ }
237
+ }
238
+ const pgTx = new WeakMap();
239
+ let pgIds = 0;
240
+ export function instrumentPg(pg) {
241
+ bindCheckouts(pg?.Pool?.prototype, 'connect');
242
+ const Client = pg?.Client;
243
+ if (!Client?.prototype?.query)
244
+ return;
245
+ const query = Client.prototype.query;
246
+ Client.prototype.query = function (...args) {
247
+ const [config, values] = args;
248
+ const submittable = config && typeof config === 'object' && typeof config.submit === 'function';
249
+ if (!currentSpan() || submittable)
250
+ return query.apply(this, args);
251
+ const text = typeof config === 'string' ? config : String(config?.text ?? '');
252
+ const params = typeof values === 'function' || values === undefined ? config?.values : values;
253
+ let state = pgTx.get(this);
254
+ if (!state)
255
+ pgTx.set(this, (state = { n: 0, open: false, id: ++pgIds }));
256
+ const head = text.trimStart().slice(0, 20).toUpperCase();
257
+ if (/^(BEGIN|START TRANSACTION)/.test(head)) {
258
+ state.n++;
259
+ state.open = true;
260
+ }
261
+ const tx = state.open ? `pg:${state.id}/tx${state.n}` : undefined;
262
+ if (/^(COMMIT|ROLLBACK|END)\b/.test(head) && !head.startsWith('ROLLBACK TO'))
263
+ state.open = false;
264
+ const settings = this.connectionParameters;
265
+ const span = beginStatement('postgresql', text, params, () => settings ? pgExplainer(Client, { ...settings }, text, params) : undefined);
266
+ if (tx)
267
+ span.detail(() => ({ transaction: tx }));
268
+ const callbackAt = args.findIndex((arg) => typeof arg === 'function');
269
+ if (callbackAt >= 0) {
270
+ const done = args[callbackAt];
271
+ args[callbackAt] = (error, result) => {
272
+ if (error)
273
+ span.fail(errorKind(error), error);
274
+ else
275
+ noteRows(span, result);
276
+ span.end();
277
+ done(error, result);
278
+ };
279
+ try {
280
+ return query.apply(this, args);
281
+ }
282
+ catch (error) {
283
+ span.fail(errorKind(error), error);
284
+ span.end();
285
+ throw error;
286
+ }
287
+ }
288
+ return settle(span, query.apply(this, args));
289
+ };
290
+ }
291
+ function pgExplainer(Client, settings, text, params) {
292
+ return async () => {
293
+ // Its own connection, read-only: the one the statement ran on may be in someone's transaction now.
294
+ const probe = new Client({
295
+ user: settings.user,
296
+ password: settings.password,
297
+ host: settings.host,
298
+ port: settings.port,
299
+ database: settings.database,
300
+ ssl: settings.ssl,
301
+ options: settings.options,
302
+ connectionTimeoutMillis: 5000,
303
+ });
304
+ await probe.connect();
305
+ try {
306
+ await probe.query('BEGIN READ ONLY');
307
+ await probe.query("SET LOCAL statement_timeout = '5s'");
308
+ const plan = (await probe.query(`EXPLAIN ${text}`, Array.isArray(params) ? params : []));
309
+ return plan.rows.map((row) => String(Object.values(row)[0]));
310
+ }
311
+ finally {
312
+ await probe.query('ROLLBACK').catch(() => { });
313
+ await probe.end().catch(() => { });
314
+ }
315
+ };
316
+ }
317
+ /** A driver error's travelling name: its SQLSTATE or errno name when it has one (never its message). */
318
+ function errorKind(error) {
319
+ const code = error?.code;
320
+ return typeof code === 'string' && /^[A-Z0-9_]{1,40}$/.test(code) ? code : 'DatabaseError';
321
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The process's metrics, kept only while an exporter wants them.
3
+ *
4
+ * Instruments are declared here, once, with their OpenTelemetry names and
5
+ * units, so a dashboard built on Datadog or Dynatrace finds the standard
6
+ * `http.server.request.duration` where it looks for it. Their attributes are
7
+ * the same travelling kind a span's are — a route template, a status, a
8
+ * command id, an outcome — and never a value from a request: every series
9
+ * is bounded by what the App declares.
10
+ *
11
+ * With no exporter, `record` returns at its first line. Cumulative
12
+ * temporality, which every OTLP backend accepts; the exporter reads a
13
+ * snapshot on its interval.
14
+ */
15
+ import type { AttributeValue } from './trace.js';
16
+ import type { Metric, MetricPoint } from './otlpEncode.js';
17
+ type Attrs = Readonly<Record<string, AttributeValue | undefined>>;
18
+ type Kind = Metric['kind'];
19
+ declare const gauges: Array<() => Array<{
20
+ name: string;
21
+ description: string;
22
+ unit: string;
23
+ kind: 'gauge' | 'updown';
24
+ points: MetricPoint[];
25
+ }>>;
26
+ declare class Instrument {
27
+ readonly name: string;
28
+ readonly description: string;
29
+ readonly unit: string;
30
+ readonly kind: Kind;
31
+ readonly bounds: readonly number[];
32
+ readonly series: Map<string, {
33
+ attributes: Record<string, AttributeValue>;
34
+ value: number;
35
+ count: number;
36
+ sum: number;
37
+ buckets: number[];
38
+ min: number;
39
+ max: number;
40
+ }>;
41
+ constructor(name: string, description: string, unit: string, kind: Kind, bounds?: readonly number[]);
42
+ record(value: number, attributes?: Attrs): void;
43
+ snapshot(time: number): Metric | undefined;
44
+ }
45
+ export declare const metrics: {
46
+ /** `http.server.request.duration`: by method, route template and status. */
47
+ httpDuration: Instrument;
48
+ /** Business commands by id and outcome (applied, replayed, not_applied, unknown) and refusal code. */
49
+ commands: Instrument;
50
+ commandDuration: Instrument;
51
+ /** `db.client.operation.duration`: by system, operation and table. */
52
+ dbDuration: Instrument;
53
+ /** Job attempts by job and outcome code; lag from due to claimed. */
54
+ jobAttempts: Instrument;
55
+ jobLag: Instrument;
56
+ /** Outbound calls (webhooks, HTTP sources, email) by kind and outcome. */
57
+ outbound: Instrument;
58
+ };
59
+ /** A gauge read when the exporter reads: the pools, the caches, the sessions. */
60
+ export declare function observeGauges(read: (typeof gauges)[number]): () => void;
61
+ export declare function enableMetrics(): void;
62
+ export declare function snapshotMetrics(): Metric[];
63
+ export {};
@@ -0,0 +1,122 @@
1
+ /** Seconds, as the conventions ask for durations; the bounds are theirs for HTTP. */
2
+ const DURATION_BOUNDS = [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10];
3
+ /** Series per instrument. Past it a new combination is dropped, not a process's memory. */
4
+ const SERIES = 2000;
5
+ let on = false;
6
+ const started = Date.now();
7
+ const instruments = new Map();
8
+ const gauges = [];
9
+ class Instrument {
10
+ name;
11
+ description;
12
+ unit;
13
+ kind;
14
+ bounds;
15
+ series = new Map();
16
+ constructor(name, description, unit, kind, bounds = DURATION_BOUNDS) {
17
+ this.name = name;
18
+ this.description = description;
19
+ this.unit = unit;
20
+ this.kind = kind;
21
+ this.bounds = bounds;
22
+ }
23
+ record(value, attributes = {}) {
24
+ if (!on || !Number.isFinite(value))
25
+ return;
26
+ const clean = Object.fromEntries(Object.entries(attributes).filter(([, v]) => v !== undefined));
27
+ const key = JSON.stringify(Object.entries(clean).sort(([a], [b]) => a.localeCompare(b)));
28
+ let entry = this.series.get(key);
29
+ if (!entry) {
30
+ if (this.series.size >= SERIES)
31
+ return;
32
+ entry = {
33
+ attributes: clean,
34
+ value: 0,
35
+ count: 0,
36
+ sum: 0,
37
+ buckets: Array.from({ length: this.bounds.length + 1 }, () => 0),
38
+ min: Infinity,
39
+ max: -Infinity,
40
+ };
41
+ this.series.set(key, entry);
42
+ }
43
+ if (this.kind === 'histogram') {
44
+ entry.count++;
45
+ entry.sum += value;
46
+ entry.min = Math.min(entry.min, value);
47
+ entry.max = Math.max(entry.max, value);
48
+ let slot = this.bounds.findIndex((bound) => value <= bound);
49
+ if (slot < 0)
50
+ slot = this.bounds.length;
51
+ entry.buckets[slot]++;
52
+ }
53
+ else
54
+ entry.value += value;
55
+ }
56
+ snapshot(time) {
57
+ if (!this.series.size)
58
+ return undefined;
59
+ const points = [...this.series.values()].map((entry) => this.kind === 'histogram'
60
+ ? {
61
+ attributes: entry.attributes,
62
+ count: entry.count,
63
+ sum: entry.sum,
64
+ bounds: this.bounds,
65
+ buckets: entry.buckets,
66
+ ...(entry.count ? { min: entry.min, max: entry.max } : {}),
67
+ }
68
+ : { attributes: entry.attributes, value: entry.value });
69
+ return { name: this.name, description: this.description, unit: this.unit, kind: this.kind, points, start: started, time };
70
+ }
71
+ }
72
+ function instrument(name, description, unit, kind, bounds) {
73
+ const made = new Instrument(name, description, unit, kind, bounds);
74
+ instruments.set(name, made);
75
+ return made;
76
+ }
77
+ export const metrics = {
78
+ /** `http.server.request.duration`: by method, route template and status. */
79
+ httpDuration: instrument('http.server.request.duration', 'Duration of HTTP server requests.', 's', 'histogram'),
80
+ /** Business commands by id and outcome (applied, replayed, not_applied, unknown) and refusal code. */
81
+ commands: instrument('mistri.command.executions', 'Business command executions by outcome.', '{execution}', 'counter'),
82
+ commandDuration: instrument('mistri.command.duration', 'Duration of business command executions.', 's', 'histogram'),
83
+ /** `db.client.operation.duration`: by system, operation and table. */
84
+ dbDuration: instrument('db.client.operation.duration', 'Duration of database client operations.', 's', 'histogram'),
85
+ /** Job attempts by job and outcome code; lag from due to claimed. */
86
+ jobAttempts: instrument('mistri.job.attempts', 'Job attempts by outcome.', '{attempt}', 'counter'),
87
+ jobLag: instrument('mistri.job.lag', 'Time from a job being due to its attempt starting.', 's', 'histogram', [0.1, 0.5, 1, 5, 10, 30, 60, 300, 900, 3600]),
88
+ /** Outbound calls (webhooks, HTTP sources, email) by kind and outcome. */
89
+ outbound: instrument('mistri.outbound.calls', 'Outbound calls by kind and outcome.', '{call}', 'counter'),
90
+ };
91
+ /** A gauge read when the exporter reads: the pools, the caches, the sessions. */
92
+ export function observeGauges(read) {
93
+ gauges.push(read);
94
+ return () => {
95
+ const at = gauges.indexOf(read);
96
+ if (at >= 0)
97
+ gauges.splice(at, 1);
98
+ };
99
+ }
100
+ export function enableMetrics() {
101
+ on = true;
102
+ }
103
+ export function snapshotMetrics() {
104
+ const time = Date.now();
105
+ const out = [];
106
+ for (const each of instruments.values()) {
107
+ const metric = each.snapshot(time);
108
+ if (metric)
109
+ out.push(metric);
110
+ }
111
+ for (const read of gauges) {
112
+ try {
113
+ for (const gauge of read())
114
+ if (gauge.points.length)
115
+ out.push({ ...gauge, start: started, time });
116
+ }
117
+ catch {
118
+ /* a gauge that cannot be read is left out */
119
+ }
120
+ }
121
+ return out;
122
+ }