@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,37 @@
1
+ /**
2
+ * The rows PostgreSQL's catalog queries return, as the adapter's
3
+ * introspection reads them, and the two readings it makes of them: a
4
+ * column's value vocabulary from its CHECK constraints, and the planner's row
5
+ * estimate. `postgresCatalog.ts` holds the queries; this holds their shapes.
6
+ */
7
+ import { checkTextRule, checkVocabulary } from '../shared/vocabulary.js';
8
+ /** What the checks say of a text column's length and form (vocabulary.ts checkTextRule), the first of each. */
9
+ export function checkedText(checks, column) {
10
+ const found = {};
11
+ for (const check of checks) {
12
+ const rule = checkTextRule(check, column);
13
+ if (rule?.min !== undefined && found.min === undefined)
14
+ found.min = rule.min;
15
+ if (rule?.pattern !== undefined && found.pattern === undefined)
16
+ found.pattern = rule.pattern;
17
+ }
18
+ return found;
19
+ }
20
+ /** The first check that pins this column's values, if any does. */
21
+ export function firstVocabulary(checks, column) {
22
+ for (const check of checks) {
23
+ const values = checkVocabulary(check, column);
24
+ if (values)
25
+ return values;
26
+ }
27
+ return undefined;
28
+ }
29
+ /** PostgreSQL's negative catalog estimate means unknown, not an empty table. */
30
+ export function postgresRowEstimate(value) {
31
+ if (typeof value !== 'number' && typeof value !== 'string')
32
+ return undefined;
33
+ if (typeof value === 'string' && !value.trim())
34
+ return undefined;
35
+ const count = Number(value);
36
+ return Number.isFinite(count) && count >= 0 ? Math.round(count) : undefined;
37
+ }
@@ -0,0 +1 @@
1
+ export declare function keepDatesAsText(pg: unknown): void;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Hand dates and timestamps back as the text the server stores.
3
+ *
4
+ * `pg` parses `timestamp without time zone` into a JavaScript `Date`, which
5
+ * has no such thing as "without time zone" — so it reads the value in the
6
+ * *process's* offset and prints it back in UTC. A row written 09:00 came out
7
+ * of this adapter as `2026-08-01T13:00:00.000Z`: not a formatting difference,
8
+ * a different time, on a value the column explicitly says has no zone. `pg` has
9
+ * no option to return date strings, so the parsers are replaced instead.
10
+ *
11
+ * `timestamptz` is included even though it is a real instant. Its text form
12
+ * carries the offset, which is more information than a `Date` rendered in
13
+ * whatever zone the browser happens to be in — and tablewalk's job is to show
14
+ * what is stored.
15
+ *
16
+ * Set on the module, because that is the only place `pg` keeps them. Done
17
+ * once, and idempotent, so opening a second connection does not repeat it.
18
+ */
19
+ const PG_DATE_OIDS = [
20
+ 1082, // date
21
+ 1083, // time
22
+ 1114, // timestamp without time zone
23
+ 1184, // timestamp with time zone
24
+ 1266, // time with time zone
25
+ ];
26
+ let datesKept = false;
27
+ export function keepDatesAsText(pg) {
28
+ if (datesKept)
29
+ return;
30
+ const mod = pg;
31
+ const types = mod.types ?? mod.default?.types;
32
+ /* A `pg` that does not expose `types` is one this cannot fix, and a
33
+ connection is worth more than a formatting guarantee. */
34
+ if (!types?.setTypeParser)
35
+ return;
36
+ for (const oid of PG_DATE_OIDS)
37
+ types.setTypeParser(oid, (value) => value);
38
+ datesKept = true;
39
+ }
@@ -0,0 +1,33 @@
1
+ import type { PgQuery } from './postgresPool.js';
2
+ export declare const MIGRATION_LOCK = "7431627679384207";
3
+ /** One private client for `run`, ended after it: a store's few statements outside any pool (the validation record's). */
4
+ export declare function withPostgresClient<T>(url: string, run: (client: PgQuery) => Promise<T>): Promise<T>;
5
+ /** One maintenance transaction under the shared migration lock, on a private
6
+ * client: the journal migration and the event-store provisioning both run
7
+ * their existence check and DDL inside it, so neither can race the other. */
8
+ export declare function withPostgresMaintenanceTransaction<T>(url: string, run: (client: PgQuery) => Promise<T>): Promise<T>;
9
+ /**
10
+ * The runtime schema (shared/runtimeTables.ts), created where it is absent and
11
+ * private to the role that made it: a new schema grants PUBLIC nothing, and the
12
+ * REVOKE says so whatever the server's default privileges add. Existence is read
13
+ * first because CREATE SCHEMA checks the database privilege before IF NOT EXISTS,
14
+ * and a suite's control role, granted CREATE on the schema, may hold none.
15
+ * Returns whether this call created it.
16
+ */
17
+ export declare function ensurePostgresRuntimeSchema(client: PgQuery): Promise<boolean>;
18
+ /**
19
+ * What makes a store's part of the runtime schema not this role's alone, as
20
+ * sentences; empty when it is. The schema: owned by this role (or, for a
21
+ * suite's flag or experiment control running as its own role, `delegated`,
22
+ * granted USAGE and CREATE on it by the owner); no privilege on it for PUBLIC
23
+ * or any other role, except the roles that own a control store's tables
24
+ * (RUNTIME_CONTROL_PREFIXES), whose grant is that delegation; and nothing in it
25
+ * but tables, sequences and the runtime's own trigger functions, since Better
26
+ * Auth resolves its unqualified names through it. The store's own relations,
27
+ * the ones named under `prefix`: owned by this role, with no privilege held on
28
+ * them or their columns by any other. A grant on `public`, a reporting role's
29
+ * `SELECT ON ALL TABLES IN SCHEMA public`, reaches none of this.
30
+ */
31
+ export declare function postgresRuntimeSchemaProblems(client: PgQuery, prefix: string, options?: {
32
+ delegated?: boolean;
33
+ }): Promise<string[]>;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * One maintenance transaction under the shared migration lock, on a private
3
+ * client: every reserved store's migration, the schema epoch's provisioning
4
+ * among them, runs its existence check and DDL inside it, so no two race.
5
+ *
6
+ * Engine, because the epoch store (postgresSchemaEpoch.ts) is the engine's
7
+ * and provisions under this lock; the App stores' migrations import it too.
8
+ */
9
+ import { Refusal } from './adapter.js';
10
+ import { pgConnectionOptions } from './postgresValues.js';
11
+ import { RUNTIME_CONTROL_PREFIXES, RUNTIME_SCHEMA, RUNTIME_SCHEMA_FUNCTIONS } from '../shared/runtimeTables.js';
12
+ /* A single key for every migration of every tablewalk journal on the server:
13
+ two operators running the step at once serialise instead of racing the
14
+ existence check. Arbitrary, fixed, and unlikely to collide with an
15
+ application's own advisory locks. */
16
+ export const MIGRATION_LOCK = '7431627679384207';
17
+ const CONNECT_TIMEOUT_MS = 15_000;
18
+ /** How long a maintenance transaction waits for the shared migration lock before it says who it is waiting for: a holder that never lets go must not stall a boot forever. */
19
+ const LOCK_WAIT_MS = 60_000;
20
+ /** One private client for `run`, ended after it: a store's few statements outside any pool (the validation record's). */
21
+ export async function withPostgresClient(url, run) {
22
+ return withClient(url, run);
23
+ }
24
+ async function withClient(url, run) {
25
+ if (typeof url !== 'string' || !/^postgres(ql)?:\/\//i.test(url))
26
+ throw new Refusal('Command journal migration requires a postgres:// URL.');
27
+ const specifier = 'pg';
28
+ const pg = (await import(specifier).catch(() => {
29
+ throw new Error('Postgres support needs the "pg" package. Install it with: npm install pg');
30
+ }));
31
+ const Client = pg.Client ?? pg.default?.Client;
32
+ if (!Client)
33
+ throw new Error('Could not find a Client export in the "pg" package.');
34
+ /* A host that does not answer fails the connect instead of stalling a boot. */
35
+ const client = new Client({ ...pgConnectionOptions(url), connectionTimeoutMillis: CONNECT_TIMEOUT_MS });
36
+ /* pg emits 'error' on a connection that drops while it is idle between statements (a failover, a proxy reset); with
37
+ no listener that is an uncaught exception and takes the server down. A statement running on it, or the next one,
38
+ rejects with the same loss, so nothing is swallowed that the caller would not see. */
39
+ client.on('error', () => { });
40
+ await client.connect();
41
+ try {
42
+ return await run(client);
43
+ }
44
+ finally {
45
+ await client.end().catch(() => { });
46
+ }
47
+ }
48
+ /** One maintenance transaction under the shared migration lock, on a private
49
+ * client: the journal migration and the event-store provisioning both run
50
+ * their existence check and DDL inside it, so neither can race the other. */
51
+ export async function withPostgresMaintenanceTransaction(url, run) {
52
+ return withClient(url, async (client) => {
53
+ await client.query('BEGIN');
54
+ try {
55
+ // lock_timeout bounds an advisory-lock wait too; it ends with this transaction.
56
+ await client.query(`SET LOCAL lock_timeout = '${LOCK_WAIT_MS}ms'`);
57
+ try {
58
+ await client.query('SELECT pg_advisory_xact_lock($1::bigint)', [MIGRATION_LOCK]);
59
+ }
60
+ catch (error) {
61
+ if (error.code === '55P03') {
62
+ throw new Refusal(`Another migration or maintenance step has held the shared migration lock for ${LOCK_WAIT_MS / 1000}s. Try again when it has finished.`);
63
+ }
64
+ throw error;
65
+ }
66
+ // Every store this runs provisions into the runtime schema; a refusal rolls the schema back with the rest.
67
+ await ensurePostgresRuntimeSchema(client);
68
+ const result = await run(client);
69
+ await client.query('COMMIT');
70
+ return result;
71
+ }
72
+ catch (error) {
73
+ await client.query('ROLLBACK').catch(() => {
74
+ /* Preserve the maintenance failure. */
75
+ });
76
+ throw error;
77
+ }
78
+ });
79
+ }
80
+ /**
81
+ * The runtime schema (shared/runtimeTables.ts), created where it is absent and
82
+ * private to the role that made it: a new schema grants PUBLIC nothing, and the
83
+ * REVOKE says so whatever the server's default privileges add. Existence is read
84
+ * first because CREATE SCHEMA checks the database privilege before IF NOT EXISTS,
85
+ * and a suite's control role, granted CREATE on the schema, may hold none.
86
+ * Returns whether this call created it.
87
+ */
88
+ export async function ensurePostgresRuntimeSchema(client) {
89
+ if ((await client.query('SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = $1', [RUNTIME_SCHEMA])).rows.length)
90
+ return false;
91
+ await client.query(`CREATE SCHEMA IF NOT EXISTS ${RUNTIME_SCHEMA}`);
92
+ await client.query(`REVOKE ALL ON SCHEMA ${RUNTIME_SCHEMA} FROM PUBLIC`);
93
+ return true;
94
+ }
95
+ /* A role the store may belong to: the connecting role itself, or a role
96
+ whose privileges it inherits, so a deployment can migrate as one member
97
+ of an owning group and run as another. A superuser is an implicit member
98
+ of every role, which would make every owner pass, so for a superuser
99
+ only itself counts. PUBLIC (grantee 0) is never ours. */
100
+ const ours = (role) => `COALESCE(${role} = me.oid OR (NOT me.rolsuper AND ${role} <> 0 AND pg_catalog.pg_has_role(me.oid, ${role}, 'USAGE')), false)`;
101
+ /**
102
+ * What makes a store's part of the runtime schema not this role's alone, as
103
+ * sentences; empty when it is. The schema: owned by this role (or, for a
104
+ * suite's flag or experiment control running as its own role, `delegated`,
105
+ * granted USAGE and CREATE on it by the owner); no privilege on it for PUBLIC
106
+ * or any other role, except the roles that own a control store's tables
107
+ * (RUNTIME_CONTROL_PREFIXES), whose grant is that delegation; and nothing in it
108
+ * but tables, sequences and the runtime's own trigger functions, since Better
109
+ * Auth resolves its unqualified names through it. The store's own relations,
110
+ * the ones named under `prefix`: owned by this role, with no privilege held on
111
+ * them or their columns by any other. A grant on `public`, a reporting role's
112
+ * `SELECT ON ALL TABLES IN SCHEMA public`, reaches none of this.
113
+ */
114
+ export async function postgresRuntimeSchemaProblems(client, prefix, options = {}) {
115
+ const row = (await client.query(`WITH me AS (SELECT r.oid, r.rolsuper FROM pg_catalog.pg_roles r WHERE r.rolname = CURRENT_USER),
116
+ ns AS (SELECT n.oid, n.nspowner, n.nspacl FROM pg_catalog.pg_namespace n WHERE n.nspname = $1),
117
+ acl AS (SELECT a.grantee, a.privilege_type FROM ns, pg_catalog.aclexplode(COALESCE(ns.nspacl, pg_catalog.acldefault('n', ns.nspowner))) a),
118
+ control AS (SELECT DISTINCT c.relowner AS role FROM ns, pg_catalog.pg_class c
119
+ WHERE c.relnamespace = ns.oid AND pg_catalog.lower(c.relname) LIKE ANY ($4::text[])),
120
+ rel AS (SELECT c.oid, c.relowner, c.relacl FROM ns, pg_catalog.pg_class c
121
+ WHERE c.relnamespace = ns.oid AND pg_catalog.lower(pg_catalog.substr(c.relname, 1, $3)) = $2)
122
+ SELECT EXISTS (SELECT 1 FROM ns) AS present,
123
+ COALESCE((SELECT ${ours('ns.nspowner')} FROM ns, me), false) AS owned,
124
+ COALESCE((SELECT pg_catalog.has_schema_privilege(ns.oid, 'CREATE') AND pg_catalog.has_schema_privilege(ns.oid, 'USAGE') FROM ns), false) AS granted,
125
+ EXISTS (SELECT 1 FROM acl, ns, me WHERE acl.privilege_type = 'CREATE' AND acl.grantee <> ns.nspowner AND NOT ${ours('acl.grantee')}
126
+ AND acl.grantee NOT IN (SELECT role FROM control)) AS "foreignCreate",
127
+ EXISTS (SELECT 1 FROM acl, ns, me WHERE acl.grantee <> ns.nspowner AND NOT ${ours('acl.grantee')}
128
+ AND acl.grantee NOT IN (SELECT role FROM control)) AS "foreignUsage",
129
+ EXISTS (SELECT 1 FROM rel, me WHERE NOT ${ours('rel.relowner')}) AS "foreignOwner",
130
+ EXISTS (SELECT 1 FROM rel, me, pg_catalog.aclexplode(rel.relacl) a WHERE NOT ${ours('a.grantee')})
131
+ OR EXISTS (SELECT 1 FROM rel, me, pg_catalog.pg_attribute t, pg_catalog.aclexplode(t.attacl) a
132
+ WHERE t.attrelid = rel.oid AND NOT ${ours('a.grantee')}) AS "foreignGrant",
133
+ COALESCE((SELECT (SELECT count(*) FROM pg_catalog.pg_proc WHERE pronamespace = ns.oid AND proname <> ALL ($5::text[]))
134
+ + (SELECT count(*) FROM pg_catalog.pg_operator WHERE oprnamespace = ns.oid)
135
+ + (SELECT count(*) FROM pg_catalog.pg_type t WHERE t.typnamespace = ns.oid AND t.typrelid = 0
136
+ AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_type e
137
+ WHERE e.oid = t.typelem AND e.typrelid <> 0 AND e.typarray = t.oid))
138
+ + (SELECT count(*) FROM pg_catalog.pg_collation WHERE collnamespace = ns.oid)
139
+ + (SELECT count(*) FROM pg_catalog.pg_conversion WHERE connamespace = ns.oid)
140
+ + (SELECT count(*) FROM pg_catalog.pg_opclass WHERE opcnamespace = ns.oid)
141
+ + (SELECT count(*) FROM pg_catalog.pg_opfamily WHERE opfnamespace = ns.oid)
142
+ + (SELECT count(*) FROM pg_catalog.pg_ts_config WHERE cfgnamespace = ns.oid)
143
+ + (SELECT count(*) FROM pg_catalog.pg_ts_dict WHERE dictnamespace = ns.oid)
144
+ + (SELECT count(*) FROM pg_catalog.pg_ts_parser WHERE prsnamespace = ns.oid)
145
+ + (SELECT count(*) FROM pg_catalog.pg_ts_template WHERE tmplnamespace = ns.oid)
146
+ + (SELECT count(*) FROM pg_catalog.pg_statistic_ext WHERE stxnamespace = ns.oid)
147
+ + (SELECT count(*) FROM pg_catalog.pg_extension WHERE extnamespace = ns.oid)
148
+ FROM ns), 0)::int AS objects,
149
+ EXISTS (SELECT 1 FROM ns, pg_catalog.pg_constraint k JOIN pg_catalog.pg_class f ON f.oid = k.confrelid
150
+ WHERE k.contype = 'f' AND (k.connamespace = ns.oid) <> (f.relnamespace = ns.oid)) AS "crossing"`, [
151
+ RUNTIME_SCHEMA,
152
+ prefix.toLowerCase(),
153
+ prefix.length,
154
+ RUNTIME_CONTROL_PREFIXES.map((each) => `${each.replaceAll('_', '\\_')}%`),
155
+ RUNTIME_SCHEMA_FUNCTIONS,
156
+ ])).rows[0];
157
+ if (!row)
158
+ return ['its catalog could not be read'];
159
+ if (row.present !== true)
160
+ return [`the "${RUNTIME_SCHEMA}" schema is missing`];
161
+ const problems = [];
162
+ if (row.owned !== true && !(options.delegated === true && row.granted === true))
163
+ problems.push('it is owned by another role');
164
+ if (row.foreignCreate !== false)
165
+ problems.push('another role may create objects in it');
166
+ else if (row.foreignUsage !== false)
167
+ problems.push('another role may use it');
168
+ if (row.foreignOwner !== false)
169
+ problems.push('a relation in it is owned by another role');
170
+ if (row.foreignGrant !== false)
171
+ problems.push('another role holds privileges on its tables');
172
+ if (row.objects !== 0)
173
+ problems.push("it holds functions, operators, types or other objects besides the store's tables");
174
+ // No store's table references a business table or is referenced by one: such a key would be a dependency between the
175
+ // App's data and the runtime's that neither catalog shows, and could hold back a delete the App never sees refused.
176
+ if (row.crossing !== false)
177
+ problems.push('a foreign key crosses between it and another schema');
178
+ return problems;
179
+ }
@@ -0,0 +1,255 @@
1
+ import { type PoolerMode, type PoolRoleStats } from './poolMetrics.js';
2
+ import type { NetworkPolicy } from './net/networkPolicy.js';
3
+ export interface PgResult<Row> {
4
+ rows: Row[];
5
+ fields: Array<{
6
+ name: string;
7
+ }>;
8
+ rowCount: number | null;
9
+ }
10
+ export interface PgQuery {
11
+ query(text: string, params?: unknown[]): Promise<PgResult<Record<string, unknown>>>;
12
+ query(config: {
13
+ text: string;
14
+ values?: unknown[];
15
+ rowMode?: string;
16
+ queryMode?: 'extended';
17
+ }): Promise<PgResult<unknown[]>>;
18
+ }
19
+ export interface PgClient extends PgQuery {
20
+ release(destroy?: boolean | Error): void;
21
+ /** Native clients expose checkout-local lifecycle events. Optional only for
22
+ * legacy test/load adapters; observed snapshot checkouts require both. */
23
+ on?(event: 'error' | 'end', listener: () => void): unknown;
24
+ off?(event: 'error' | 'end', listener: () => void): unknown;
25
+ /** The backend this client talks to: what a cancel names. */
26
+ readonly processID?: number | null;
27
+ }
28
+ export interface PgPool extends PgQuery {
29
+ connect(): Promise<PgClient>;
30
+ end(): Promise<void>;
31
+ on(event: 'error', listener: (error: Error) => void): void;
32
+ }
33
+ export interface PgPoolOptions {
34
+ connectionString?: string;
35
+ ssl?: {
36
+ rejectUnauthorized: true;
37
+ };
38
+ max: number;
39
+ connectionTimeoutMillis: number;
40
+ idleTimeoutMillis: number;
41
+ /** Idle clients the pool keeps past `idleTimeoutMillis`. */
42
+ min?: number;
43
+ /** Idle clients do not keep the process alive on their own. */
44
+ allowExitOnIdle?: boolean;
45
+ onConnect(client: PgQuery): Promise<void>;
46
+ /** Send each query as it is asked, without waiting for the one before to be answered (node-postgres 8.21+). */
47
+ pipeline?: boolean;
48
+ }
49
+ type PgPoolLoader = () => Promise<unknown>;
50
+ /** This lease's client pipelines: several queries asked at once leave together. */
51
+ export declare const pipelines: (client: PgQuery) => boolean;
52
+ /** `wrapper` sends through `client` and nothing else: it pipelines where `client` does. */
53
+ export declare const pipelinesAs: (wrapper: PgQuery, client: PgQuery) => void;
54
+ /** The database browser's reader pool size unless a connection or the command line says otherwise.
55
+ * An App's is balanced against its writers (appReaders). */
56
+ export declare const DEFAULT_READERS = 4;
57
+ /** The most readers one database's pool may hold. Past this, a pooler in front of the server is the tool. */
58
+ export declare const MAX_READERS = 64;
59
+ /** Whether `value` is a reader pool size a manager accepts: a whole number from 1 to 64. */
60
+ export declare function isReaderCount(value: unknown): value is number;
61
+ export interface PgConnectionOptions {
62
+ /** Reader connections held at once, 1–64. The process default when absent. */
63
+ readonly readers?: number;
64
+ /** Writer connections held at once, 1–64, where writes are keyed (writeLanes.ts); one where they are serial. */
65
+ readonly writers?: number;
66
+ /** How long a writer waits for a lock. The process's (`--lock-timeout`) when absent. */
67
+ readonly lockTimeoutMs?: number;
68
+ /** What sits between this process and the server. The process default when absent. */
69
+ readonly pooler?: PoolerMode;
70
+ /** The statement cap every lease runs under. Only tests lower it. */
71
+ readonly capMs?: number;
72
+ /** How long a checkout may queue behind a full pool before it is refused as busy (poolMetrics.ts). Only tests change it. */
73
+ readonly queueWaitMs?: number;
74
+ /** How many checkouts per pool connection may queue before the next is refused. Only tests change it. */
75
+ readonly queuePerConnection?: number;
76
+ /** Read replicas of this database, by URL: lag-tolerant reads go to them in turn (replicas.ts). */
77
+ readonly replicas?: readonly string[];
78
+ /** Set when an untrusted client typed the address: it is dialled sealed, through this policy (untrustedDatabase.ts). */
79
+ readonly network?: NetworkPolicy;
80
+ /**
81
+ * Readers send each query as it is asked, as writers do: for an owner that
82
+ * asks several statements of one snapshot at once and waits on them in
83
+ * order (a tenant read source, `readSnapshot`'s `ahead`). Off for every
84
+ * other reader, whose callers ask one statement at a time anyway.
85
+ */
86
+ readonly pipelineReads?: boolean;
87
+ /** What server timing calls this database (serverTiming.ts): `app` unless a replica's manager says otherwise. */
88
+ readonly timingLabel?: string;
89
+ /** False for a replica's manager, whose readers its primary's manager has already counted (connectionBudget.ts). */
90
+ readonly counted?: boolean;
91
+ /** Only readers are ever opened here (a tenant App's replica): the budget counts them and no writer. */
92
+ readonly readersOnly?: boolean;
93
+ }
94
+ /** An App's reader pool where none was chosen: as wide as its writers, at least the balanced size for `cores`
95
+ * (this machine's, unless a deployment check asks for another's). */
96
+ export declare function appReaders(writers: number, cores?: number): number;
97
+ /**
98
+ * The defaults every manager in this process takes when it names none: the
99
+ * command line's `--read-pool` and `--pooler`. Server-wide on purpose
100
+ * (serverSettings.ts): besides the registry's adapters, tenant sources, the
101
+ * job host and startup checks open pools of their own on the same databases,
102
+ * and a transaction-mode pooler in front of one of them has to be honored by
103
+ * every one; a per-connection switch would reach only some. Called once, at
104
+ * startup; whatever it leaves unsaid returns to the built-in default. The
105
+ * reader count stays unset until a manager is made: the write order, which
106
+ * says whether this is an App, is configured after the flags are read.
107
+ */
108
+ export declare function configurePostgresPools(options: {
109
+ readers?: number;
110
+ pooler?: PoolerMode;
111
+ }): void;
112
+ /** The defaults, as this server's settings leave them. */
113
+ export declare function postgresPoolDefaults(): Readonly<{
114
+ readers: number;
115
+ pooler: PoolerMode;
116
+ }>;
117
+ /** Separate bounded pools keep browsing read-only and transactions on one lease. */
118
+ export declare class PgConnectionManager {
119
+ private readonly connectionString;
120
+ private readonly onLoad;
121
+ private readonly load;
122
+ private reader?;
123
+ private writer?;
124
+ private background?;
125
+ /** The pools once they exist, for the meters' physical counts. */
126
+ private readonly opened;
127
+ private closed;
128
+ private readonly gauges;
129
+ private closing?;
130
+ /** What sits between this process and the server, for every lease of this manager. */
131
+ readonly pooler: PoolerMode;
132
+ private readonly capMs;
133
+ private readonly lockMs;
134
+ private readonly queueWaitMs;
135
+ private readonly queuePerConnection;
136
+ private readonly meters;
137
+ /** The line each person-facing role's checkouts wait in, turn by turn across accounts (poolAdmission.ts). */
138
+ private readonly admissions;
139
+ private readonly reads;
140
+ /** This database's replicas, each a manager of its own whose writers are never opened. */
141
+ private readonly replicas?;
142
+ private readonly network?;
143
+ private readonly pipelineReads;
144
+ private readonly timingLabel;
145
+ /** A pool the server refused another connection, held at what it had until the timer lets it ask again. */
146
+ private readonly limitHolds;
147
+ /** When each pool last said it reached the connection limit: once a spell, not once a checkout. */
148
+ private readonly limitSaid;
149
+ /** Gives back what this manager told the connection budget it may hold (connectionBudget.ts). */
150
+ private readonly releaseBudget;
151
+ constructor(connectionString: string, onLoad?: (pg: unknown) => void, load?: PgPoolLoader, options?: PgConnectionOptions);
152
+ /**
153
+ * A handle for single statements on the reader pool. Each statement leases
154
+ * a client of its own for exactly its length, which is what `pool.query`
155
+ * did — so the checkout is metered, a cancel knows which client to stop,
156
+ * and behind a transaction-mode pooler the statement runs inside a
157
+ * read-only transaction of its own.
158
+ */
159
+ read(): Promise<PgQuery>;
160
+ /** Native snapshot owners opt into callback drain after cancellation. A
161
+ * callback must settle after its driver operations are destroyed; arbitrary
162
+ * never-settling application work cannot offer a bounded drain guarantee. */
163
+ withReadClient<T>(run: (client: PgQuery) => Promise<T>, destroyAfter?: boolean, drainCancelled?: boolean): Promise<T>;
164
+ /** Private native snapshot seam: guard observes this exact checkout, not
165
+ * instantaneous remote-server health. Ordinary read/write behavior is unchanged. */
166
+ withObservedReadClient<T>(run: (client: PgQuery, current: () => void) => Promise<T>): Promise<T>;
167
+ /** A writer for one transaction: from the writer pool, or inside background work (asBackgroundWork) the background writer. */
168
+ withWriteClient<T>(run: (client: PgQuery) => Promise<T>, destroyAfter?: boolean): Promise<T>;
169
+ /** The meters of the pools opened so far, readers first, then each replica's readers. Readable after close. */
170
+ stats(): readonly PoolRoleStats[];
171
+ /** Whether this database names any replica. */
172
+ hasReplicas(): boolean;
173
+ /**
174
+ * `work` on each replica in use now, its failures left out: what live sync
175
+ * asks of every healthy replica before it tells readers of a change, so a
176
+ * refetch it sets off reads a replica that has the change (server/live).
177
+ */
178
+ onHealthyReplicas<T>(work: (client: PgQuery) => Promise<T>): Promise<T[]>;
179
+ /** Each replica: whether it is in use now, and how many reads it answered and handed back to the primary. */
180
+ replicaHealth(): ReadonlyArray<{
181
+ replica: number;
182
+ healthy: boolean;
183
+ served: number;
184
+ fellBack: number;
185
+ }>;
186
+ close(): Promise<void>;
187
+ private dialOptions;
188
+ private assertOpen;
189
+ private pool;
190
+ private createPool;
191
+ private withClient;
192
+ /**
193
+ * A connection, or PoolBusy once what is left of the queue-wait budget, `waitMs`, is spent. The driver
194
+ * cannot withdraw a request it has queued, so one that arrives late is given
195
+ * straight back to the pool rather than leaked.
196
+ */
197
+ private connectWithin;
198
+ /**
199
+ * `pool.connect()`, within the connections the server allows. Refused
200
+ * another one (53300), the pool is held at the connections it has, so this
201
+ * checkout and the next wait for one of them as they would behind a full
202
+ * pool, and it asks for more again after LIMIT_HOLD_MS; holding none, the
203
+ * checkout is refused as busy. A refusal at open leased nothing, so nothing
204
+ * on any connection moved: a tenant writer stays open on it
205
+ * (tenantWriteSource.ts). It used to rise as a database fault, and a
206
+ * tenant writer closed for it and reopened into the same refusal, again and
207
+ * again, with two commands in three failing at three users while its one
208
+ * connection sat idle (a field report: pools sized past the role's limit).
209
+ */
210
+ private connectHeld;
211
+ /** Holds `pool` at the connections it has (pg-pool reads `options.max` at each checkout), says so once a spell, and returns how many. */
212
+ private holdAtLimit;
213
+ /**
214
+ * Stop what backend `pid` is running, with pg_cancel_backend from a
215
+ * connection of its own: the pool's may all be busy, one of them with the
216
+ * statement being stopped. Best effort — a cancel that cannot connect
217
+ * leaves the statement to its cap.
218
+ */
219
+ private cancel;
220
+ private endPools;
221
+ }
222
+ /** The pool shape a holder of a shared manager names: the sizes, and whether its readers pipeline. */
223
+ export type SharedPoolShape = Pick<PgConnectionOptions, 'readers' | 'writers' | 'pipelineReads' | 'readersOnly'>;
224
+ /** The reader and writer counts a manager takes for `shape`: its own, else the process's (`--read-pool`, `--write-pool`) or the defaults. */
225
+ export declare function poolSizes(shape?: Pick<SharedPoolShape, 'readers' | 'writers'>): {
226
+ readers: number;
227
+ writers: number;
228
+ };
229
+ /**
230
+ * The manager every holder of `url` with this `shape` shares, instead of one
231
+ * each. Every pool sized for its process and blind to its neighbors was how a
232
+ * tenant App came to hold `3R + 6W + 5` connections on one database — its
233
+ * reader, discovery, writer, administration and support each with a manager of
234
+ * their own (docs/postgresql.md) — while each sat mostly idle: a field
235
+ * deployment whose role allowed eighteen ran fixed four-and-four pools and
236
+ * still could not fit. Shared, the readers and writers are one pool for all of
237
+ * them, sized once, and counted once (connectionBudget.ts).
238
+ *
239
+ * What sharing leaves alone: each holder keeps its own write lanes
240
+ * (writeLanes.ts), so per-record order is what it was; and a manager is shared
241
+ * only with holders that would have built the same one — the URL, the sizes
242
+ * after the process defaults, the pooler, the lock wait and the load hook all
243
+ * in the key — so a handler mounted with settings of its own never borrows
244
+ * another's pools.
245
+ *
246
+ * Each call is one holder. The handle is the manager behind a proxy whose
247
+ * `close` lets that holder go — once, however often it is called — and the
248
+ * pools close with the last holder; everything else is the manager's own, so
249
+ * the handle passes wherever a manager does (`instanceof` too).
250
+ */
251
+ export declare function sharedPgConnections(url: string, shape?: SharedPoolShape, onLoad?: (pg: unknown) => void): PgConnectionManager;
252
+ /** What a runtime store leases for each of its transactions: one writer
253
+ * client, returned (or destroyed, on failure) before the call resolves. */
254
+ export type PgWriteClientSource = Pick<PgConnectionManager, 'withWriteClient'>;
255
+ export {};