@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,524 @@
1
+ /**
2
+ * One transaction's own handle on a leased PostgreSQL client.
3
+ *
4
+ * A writer's client is pooled: the same object serves one transaction after
5
+ * another. Something true of one transaction only — the membership rows its
6
+ * fence locked, held to its end (tenantWriteSource.ts) — must
7
+ * therefore be kept on an object that is that transaction's alone: made at
8
+ * its BEGIN, used for every statement it sends, dropped with it. Never on the
9
+ * client, and never keyed by a pool connection.
10
+ *
11
+ * It also counts the rollbacks that pass through it. A `ROLLBACK TO
12
+ * SAVEPOINT` undoes everything since the savepoint, the locks taken there
13
+ * included, so whatever was established before it is no longer vouched for.
14
+ * Any statement that says ROLLBACK anywhere counts, a string literal
15
+ * included: a false count only costs a repeated check.
16
+ */
17
+ import { pipelines } from './postgresPool.js';
18
+ import { EpochCache } from './epochCache.js';
19
+ const transactions = new WeakMap();
20
+ /* What leaves answers sent ahead standing: a read or a row or table lock.
21
+ Anything else — this transaction's own write, a savepoint, a notification,
22
+ a statement that fails — may change what they read, and they are dropped,
23
+ to be asked again in their turn. */
24
+ const KEEPS = /^\s*(?:SELECT|WITH|LOCK)\b/i;
25
+ const CHANGES = /\b(?:INSERT\s+INTO|DELETE\s+FROM|MERGE\s+INTO|UPDATE\s+(?:ONLY\s+)?[^\s(]+\s+SET|ROLLBACK|pg_notify|nextval|setval)\b/i;
26
+ /* A row lock asked in its turn: answers read ahead of it were read before it
27
+ was granted, so they are dropped (a read after a lock sees what the lock
28
+ waited for). A table LOCK pins a catalog, not rows, and leaves them. */
29
+ const ROW_LOCK = /\bFOR\s+(?:NO\s+KEY\s+UPDATE|UPDATE|KEY\s+SHARE|SHARE)\b/i;
30
+ const textOf = (request) => typeof request === 'string' ? request : request && typeof request === 'object' ? request.text : undefined;
31
+ /** What a statement says, as the key an answer sent ahead is found by; undefined for one that cannot be compared. */
32
+ function said(args) {
33
+ const [request, params] = args;
34
+ try {
35
+ if (typeof request === 'string')
36
+ return JSON.stringify([request, params ?? []]);
37
+ if (request && typeof request === 'object' && typeof request.text === 'string') {
38
+ const { text, values, rowMode } = request;
39
+ return JSON.stringify([text, values ?? params ?? [], rowMode ?? null]);
40
+ }
41
+ }
42
+ catch {
43
+ /* A value JSON cannot say (a bigint): asked in its turn. */
44
+ }
45
+ return undefined;
46
+ }
47
+ export function transactionHandle(client, origin) {
48
+ const state = {
49
+ origin,
50
+ count: 0,
51
+ pipelines: pipelines(client),
52
+ ahead: new Map(),
53
+ report: { sent: 0, taken: 0, missed: 0, left: [], redone: 0, answered: 0, asked: [] },
54
+ generation: 0,
55
+ held: new Map(),
56
+ send: (...args) => client.query(...args),
57
+ tail: [],
58
+ riders: [],
59
+ };
60
+ // Every argument passes through as given: a statement with no parameters
61
+ // stays one the simple protocol may carry.
62
+ const query = ((...args) => {
63
+ const text = textOf(args[0]);
64
+ // Counted before it is sent: a rollback that fails half way still counts.
65
+ if (typeof text !== 'string' || /\bROLLBACK\b/i.test(text))
66
+ state.count += 1;
67
+ if (state.ahead.size) {
68
+ const key = said(args);
69
+ const waiting = key === undefined ? undefined : state.ahead.get(key);
70
+ if (waiting?.length) {
71
+ const answer = waiting.shift();
72
+ if (!waiting.length)
73
+ state.ahead.delete(key);
74
+ state.report.taken += 1;
75
+ return answer;
76
+ }
77
+ }
78
+ // A rollback of the whole transaction: what waited for its COMMIT is never sent.
79
+ if (typeof text === 'string' && /^\s*ROLLBACK\s*;?\s*$/i.test(text)) {
80
+ state.tail = [];
81
+ state.riders = [];
82
+ }
83
+ // A transaction that changes the catalog itself no longer stands on the version it read: it reads one again.
84
+ if (typeof text === 'string' && changesCatalog(text))
85
+ catalogVersions.delete(handle);
86
+ // What waited for the COMMIT leaves in front of whatever leaves next, in its order.
87
+ const tail = state.tail.length ? state.tail.splice(0) : undefined;
88
+ const changes = !!tail || typeof text !== 'string' || !KEEPS.test(text) || CHANGES.test(text);
89
+ if (changes)
90
+ state.generation += 1;
91
+ if (state.ahead.size) {
92
+ const first = typeof text === 'string' ? text.replace(/\s+/g, ' ').slice(0, 120) : '(not a statement)';
93
+ if (changes || ROW_LOCK.test(text)) {
94
+ state.report.asked.push(`dropped by: ${first}`);
95
+ drop(state);
96
+ }
97
+ else {
98
+ state.report.missed += 1;
99
+ state.report.asked.push(first);
100
+ }
101
+ }
102
+ const before = tail?.map((statement) => state.send(...statement));
103
+ const commit = typeof text === 'string' && /^\s*COMMIT\s*;?\s*$/i.test(text);
104
+ let answer = before && commit ? commitBehind(client, before, args) : client.query(...args);
105
+ if (state.riders.length && typeof text === 'string')
106
+ for (const rider of state.riders.filter((candidate) => candidate.match(text))) {
107
+ state.riders.splice(state.riders.indexOf(rider), 1);
108
+ rider.ride();
109
+ }
110
+ // A submittable or a callback's query answers no promise: it is passed back as it is.
111
+ if (typeof answer?.catch !== 'function')
112
+ return answer;
113
+ if (before)
114
+ answer = behind(before, answer, commit);
115
+ // A statement that fails aborts the transaction: nothing sent ahead of it can be taken after, nor any row read before it trusted.
116
+ return answer.catch((error) => {
117
+ state.generation += 1;
118
+ drop(state);
119
+ if (state.origin && suspectsStores(error))
120
+ forgetAttestations(state.origin, handle, error);
121
+ throw error;
122
+ });
123
+ });
124
+ const handle = Object.freeze({ query });
125
+ transactions.set(handle, state);
126
+ return handle;
127
+ }
128
+ /**
129
+ * Send statements now that the transaction will ask for later, so they leave
130
+ * in the flight already going out (behind its BEGIN) instead of each in a
131
+ * round trip of its own. Each answer is kept for the first later query that
132
+ * says exactly the same thing, and given to it once; the query then sends
133
+ * nothing. Only reads and locks are sent ahead, in the order the transaction
134
+ * would ask them, and every kept answer is dropped the moment the transaction
135
+ * sends anything else — a write of its own, a rollback to a savepoint — so a
136
+ * read after this transaction's own change is always asked again.
137
+ *
138
+ * The caller awaits the returned answers before it relies on any of them: one
139
+ * that failed has aborted the transaction, which then begins again without
140
+ * them (nothing has used them yet). On a client that does not pipeline
141
+ * nothing is sent: each would cost its own round trip either way.
142
+ */
143
+ export function sendAhead(client, statements) {
144
+ const state = transactions.get(client);
145
+ if (!state?.pipelines)
146
+ return [];
147
+ state.report.sent += statements.length;
148
+ return statements.map((statement) => {
149
+ const args = typeof statement === 'string' ? [statement] : statement.values?.length ? [statement.text, [...statement.values]] : [statement.text];
150
+ const key = said(args);
151
+ const answer = state.send(...args);
152
+ // Heard here, so one never used never rejects unheard; whoever takes it hears its failure.
153
+ answer.catch(() => { });
154
+ if (key !== undefined) {
155
+ const waiting = state.ahead.get(key);
156
+ if (waiting)
157
+ waiting.push(answer);
158
+ else
159
+ state.ahead.set(key, [answer]);
160
+ }
161
+ return answer;
162
+ });
163
+ }
164
+ /**
165
+ * Whether an answer sent ahead still waits for exactly `statement`: asking it
166
+ * then sends nothing. False once a statement of the transaction's own has
167
+ * dropped it, or where nothing was sent ahead.
168
+ */
169
+ export function waitsAhead(client, statement) {
170
+ const state = transactions.get(client);
171
+ if (!state?.ahead.size)
172
+ return false;
173
+ const key = said(statement.values?.length ? [statement.text, [...statement.values]] : [statement.text]);
174
+ return key !== undefined && (state.ahead.get(key)?.length ?? 0) > 0;
175
+ }
176
+ /**
177
+ * Send a read now that a caller will answer later reads from itself (a row
178
+ * read in full, answered by projection: scoped/keyRows.ts), rather than the
179
+ * handle answering one identical query with it. `take` says it answered one,
180
+ * so a read never used is reported left like any statement sent ahead.
181
+ * Undefined where the client does not pipeline.
182
+ */
183
+ export function holdAhead(client, statement) {
184
+ const state = transactions.get(client);
185
+ if (!state?.pipelines)
186
+ return undefined;
187
+ state.report.sent += 1;
188
+ const args = typeof statement === 'string' ? [statement] : statement.values?.length ? [statement.text, [...statement.values]] : [statement.text];
189
+ const key = said(args) ?? String(args[0]);
190
+ const answer = state.send(...args);
191
+ answer.catch(() => { });
192
+ const entry = { taken: false };
193
+ state.held.set(key, entry);
194
+ return {
195
+ answer,
196
+ take: () => {
197
+ state.report.answered += 1;
198
+ if (!entry.taken)
199
+ state.report.taken += 1;
200
+ entry.taken = true;
201
+ },
202
+ };
203
+ }
204
+ /**
205
+ * The transaction's statement generation: a number that moves with every
206
+ * statement sent through its handle that is not a read or a lock (a write, a
207
+ * savepoint, a rollback, a notification) and with every one that fails.
208
+ * Something read while it stood still was read in a transaction that has
209
+ * changed nothing since. Undefined for anything that is not a handle.
210
+ */
211
+ export const generationOf = (client) => transactions.get(client)?.generation;
212
+ /** Whether statements sent ahead on this transaction leave in one flight: its client pipelines. */
213
+ export const sendsAhead = (client) => transactions.get(client)?.pipelines === true;
214
+ function drop(state) {
215
+ for (const [key, waiting] of state.ahead)
216
+ for (let i = 0; i < waiting.length; i++)
217
+ state.report.left.push(key);
218
+ state.ahead.clear();
219
+ }
220
+ /* A COMMIT sent behind writes that waited for it, unless one of them never
221
+ reached the server. A write the server refuses aborts the transaction
222
+ there, and the COMMIT is answered as a ROLLBACK; but one the driver refused
223
+ as it was handed over (a value it cannot send, a fault in its query) was
224
+ never sent at all, and a COMMIT behind it would commit everything else. Such
225
+ a refusal is heard within the turn it was asked, so the COMMIT waits that
226
+ turn, which costs no round trip: nothing has come back from the server yet. */
227
+ function commitBehind(client, before, args) {
228
+ let refused;
229
+ for (const sent of before)
230
+ sent.catch((reason) => void (refused ??= { reason }));
231
+ return new Promise((turn) => setImmediate(turn)).then(() => {
232
+ if (!refused)
233
+ return client.query(...args);
234
+ const { reason } = refused;
235
+ const fail = () => {
236
+ throw new RolledBackAtCommit(reason);
237
+ };
238
+ return client.query('ROLLBACK').then(fail, fail);
239
+ });
240
+ }
241
+ /* What a statement sent behind writes that waited for it answers: the first of
242
+ those writes that failed, if one did (the statement then failed only because
243
+ the transaction was aborted, or, a COMMIT, was answered as a ROLLBACK),
244
+ else its own answer. Every answer is heard. */
245
+ function behind(before, answer, commit) {
246
+ return Promise.allSettled([...before, answer]).then((settled) => {
247
+ const failed = settled.slice(0, -1).find((outcome) => outcome.status === 'rejected');
248
+ if (failed)
249
+ throw commit ? new RolledBackAtCommit(failed.reason) : failed.reason;
250
+ const own = settled[settled.length - 1];
251
+ if (own.status === 'rejected')
252
+ throw own.reason;
253
+ return own.value;
254
+ });
255
+ }
256
+ /**
257
+ * A COMMIT that the server answered as a ROLLBACK, because a write sent in
258
+ * front of it in the same flight (beforeCommit) failed: nothing committed.
259
+ * `cause` is that write's own failure.
260
+ */
261
+ export class RolledBackAtCommit extends Error {
262
+ cause;
263
+ constructor(cause) {
264
+ super('The transaction rolled back at its COMMIT: a write sent with it failed.');
265
+ this.cause = cause;
266
+ this.name = 'RolledBackAtCommit';
267
+ }
268
+ }
269
+ /**
270
+ * Queue writes whose answers nothing reads before COMMIT (a receipt, its
271
+ * audit, a live change and its notification), to leave with the next
272
+ * statement the transaction sends — its COMMIT, at best — in the same flight
273
+ * instead of a round trip each. A write that fails then fails what it was
274
+ * sent with: the statement behind it throws the write's own failure, and a
275
+ * COMMIT throws RolledBackAtCommit (nothing committed). False where the
276
+ * client does not pipeline or is not a transaction's handle: the caller sends
277
+ * them in their turn.
278
+ */
279
+ export function beforeCommit(client, statements) {
280
+ const state = transactions.get(client);
281
+ if (!state?.pipelines)
282
+ return false;
283
+ for (const statement of statements)
284
+ state.tail.push(typeof statement === 'string' ? [statement] : statement.values?.length ? [statement.text, [...statement.values]] : [statement.text]);
285
+ return true;
286
+ }
287
+ /**
288
+ * Run `ride` the moment the transaction sends a statement `match` accepts (a
289
+ * write the caller is about to wait on), so what `ride` sends leaves right
290
+ * behind it, in its flight, and reads what it wrote. Answers a withdraw: true
291
+ * when `ride` had not run (it never will now). Undefined where the client
292
+ * does not pipeline: the caller asks in its turn.
293
+ */
294
+ export function behindWrite(client, match, ride) {
295
+ const state = transactions.get(client);
296
+ if (!state?.pipelines)
297
+ return undefined;
298
+ const rider = { match, ride };
299
+ state.riders.push(rider);
300
+ return () => {
301
+ const at = state.riders.indexOf(rider);
302
+ if (at < 0)
303
+ return false;
304
+ state.riders.splice(at, 1);
305
+ return true;
306
+ };
307
+ }
308
+ /** Drop every answer sent ahead and not yet taken, and count a beginning again without them (one failed). */
309
+ export function redoWithoutAhead(client) {
310
+ const state = transactions.get(client);
311
+ if (!state)
312
+ return;
313
+ state.ahead.clear();
314
+ state.held.clear();
315
+ state.generation += 1;
316
+ state.report.redone += 1;
317
+ }
318
+ /** What became of this transaction's statements sent ahead, those still waiting counted as left; undefined for anything else. */
319
+ export function aheadReport(client) {
320
+ const state = transactions.get(client);
321
+ if (!state)
322
+ return undefined;
323
+ drop(state);
324
+ for (const [key, entry] of state.held)
325
+ if (!entry.taken)
326
+ state.report.left.push(key);
327
+ state.held.clear();
328
+ return { ...state.report, left: [...state.report.left], asked: [...state.report.asked] };
329
+ }
330
+ /** The same transaction seen through `query`, which must send every
331
+ * statement on through `client` (a caller's checkpoints around each one):
332
+ * so the rollbacks are still counted by the handle, and what the transaction
333
+ * has established is still found. On a bare client, a bare view. */
334
+ export function transactionView(client, query) {
335
+ const view = Object.freeze({ query });
336
+ const state = transactions.get(client);
337
+ if (state)
338
+ transactions.set(view, state);
339
+ return view;
340
+ }
341
+ /** The transaction a handle or view belongs to, as an object only they
342
+ * share; undefined for a bare client, so nothing is kept on one. */
343
+ export function transactionOf(client) {
344
+ return transactions.get(client);
345
+ }
346
+ /* ---------- runtime stores, attested once per adapter ---------- */
347
+ /* What each adapter has attested of its runtime stores (the journal, the tenant
348
+ store, the event store...), by a key the store chooses. A store is
349
+ attested in full when an adapter first uses it, which is when the process
350
+ opens it, and not again: a GRANT or DDL on a runtime table made later is
351
+ seen at the next start, or when a statement fails the way a moved catalog
352
+ fails one (suspectsStores), which forgets them all and has the next use
353
+ attest in full again. The database role is the boundary (reservedSql.ts),
354
+ as it always was for what happens between two checks. */
355
+ const attestations = new WeakMap();
356
+ /** A statement failed for a table, column or privilege that is not what it was, or a reference that broke: a runtime store may have moved. */
357
+ export function suspectsStores(error) {
358
+ const code = error?.code;
359
+ return movedCatalog(code) || code === '23503';
360
+ }
361
+ /* A table, column or privilege that is not what it was: the catalog itself moved. A reference that broke (23503)
362
+ is that too only where a store grew a key it should not have, which the version moves with; it is far more often
363
+ an App's own row naming one that is not there, and forgets one adapter's attestations, never the process's. */
364
+ const movedCatalog = (code) => code === '42P01' || code === '42703' || code === '42501';
365
+ export const attestedOn = (origin, key) => attestations.get(origin)?.has(key) === true;
366
+ export function keepAttestedOn(origin, key) {
367
+ let kept = attestations.get(origin);
368
+ if (!kept)
369
+ attestations.set(origin, (kept = new Set()));
370
+ kept.add(key);
371
+ }
372
+ export const forgetAttestations = (origin, client, error) => {
373
+ attestations.delete(origin);
374
+ /* What `client`'s transaction stood on, shared under the version it read, is dropped with it when the catalog
375
+ moved under it. Only that: a transaction that read no version (one whose epoch probe failed on a database
376
+ without the store) stood on none. */
377
+ const read = client && catalogVersions.get(client);
378
+ if (read && movedCatalog(error?.code))
379
+ sharedAttestations.forget(read.database);
380
+ };
381
+ /* A tenant App's start opened a dozen adapters and read snapshots on one database — startup's checks, a trial
382
+ enrollment and the host's, each read source — and each attested the same stores in full: on Ignition 42 layout
383
+ descriptions and 32 ownership checks, one round trip each. What a full attestation reads of the catalog — the
384
+ layout, the owners, grants and objects of the runtime schema, the roles — is what the catalog digest and the
385
+ schema epoch move with (postgresCatalogDigest.ts, postgresSchemaEpoch.ts), so one that passed stands for any
386
+ transaction on the same database that read the same exact version before attesting: kept here by the database
387
+ and that version, and asked of nothing else. The store's meta row — which App, source and store it is bound to —
388
+ is data the digest does not see, and the next adapter to open must see it changed: an adapter that finds the
389
+ catalog attested reads it again (`rebound`), one statement, and a row that no longer binds attests in full, which
390
+ refuses. A store that names no such read is not shared. A transaction that read no exact version — a time-filed
391
+ one, or none — attests as before.
392
+
393
+ Filed only where the attestation saw the version it is filed under. A snapshot's every statement sees the catalog
394
+ its first one did. A write's (READ COMMITTED) each sees what had committed when it ran, so DDL committing between
395
+ its version read and its attestation would be filed under a version it never saw, for a snapshot begun before the
396
+ DDL to find; it reads the version again after attesting (`reread`) and files only if it has not moved. */
397
+ const sharedAttestations = new EpochCache(32);
398
+ /* DDL, or code that may run it, where a statement may begin: the start of the message, after a `;`, or after a
399
+ comment, block (nested or not) or line, so a comment before it hides nothing. A word that only looks like one
400
+ there (a column at the start of a line) costs a transaction its sharing, never its correctness. */
401
+ const CATALOG_WRITE = /(?:^|;|\*\/|\n)\s*(?:(?:CREATE|ALTER|DROP|GRANT|REVOKE|REASSIGN|SECURITY\s+LABEL|IMPORT\s+FOREIGN|CALL)\b|DO\s*(?:\$|'|LANGUAGE\b))/i;
402
+ /** Whether a message may change the catalog: DDL, or code that may run it. */
403
+ export const changesCatalog = (text) => CATALOG_WRITE.test(text);
404
+ const catalogVersions = new WeakMap();
405
+ /* How a transaction on an adapter's handle that read no exact version — the epoch store absent, so a write's
406
+ catalog answers are time-filed — reads one when it first has a store to attest: the digest, one statement where
407
+ each store's attestation is two. */
408
+ const catalogReaders = new WeakMap();
409
+ /** Say the exact catalog version `client`'s transaction read, before anything it attests: its digest or its epoch.
410
+ * `reread` reads it again, for a transaction whose statements each see the latest commit (READ COMMITTED); a
411
+ * snapshot's needs none. Undefined unsays it, for a transaction begun again on the same client that read none. */
412
+ export function noteCatalogVersion(client, database, version, reread) {
413
+ if (version === undefined)
414
+ catalogVersions.delete(client);
415
+ else
416
+ catalogVersions.set(client, Object.freeze({ database, version, ...(reread ? { reread } : {}) }));
417
+ }
418
+ /** How a transaction on `origin`'s handles reads an exact catalog version of `database` when it has read none. */
419
+ export function readsCatalogVersion(origin, database, read) {
420
+ catalogReaders.set(origin, Object.freeze({ database, read }));
421
+ }
422
+ /** The adapter a handle's transaction runs on, as transactionHandle was told; undefined for anything else. */
423
+ const transactionOrigin = (client) => transactions.get(client)?.origin;
424
+ /**
425
+ * Attest a runtime store in full (`full`, which refuses) unless the adapter
426
+ * this transaction runs on attested it under `key` already, or any transaction
427
+ * on the same database did under the exact catalog version this one read
428
+ * (sharedAttestations) — read now, if it read none and its adapter says how —
429
+ * and its meta row still binds it (`rebound`, without which nothing is shared).
430
+ * Otherwise, off a handle or on one made without an adapter, always in full.
431
+ */
432
+ export async function attestOnce(client, key, full, rebound) {
433
+ const origin = transactionOrigin(client);
434
+ if (origin && attestedOn(origin, key))
435
+ return;
436
+ if (!rebound) {
437
+ await full();
438
+ if (origin)
439
+ keepAttestedOn(origin, key);
440
+ return;
441
+ }
442
+ let read = catalogVersions.get(client);
443
+ const reader = origin && !read ? catalogReaders.get(origin) : undefined;
444
+ if (reader) {
445
+ // An adapter's handle is a write's: READ COMMITTED.
446
+ noteCatalogVersion(client, reader.database, await reader.read(client), () => reader.read(client));
447
+ read = catalogVersions.get(client);
448
+ }
449
+ if (!read || !sharedAttestations.get(read.version, read.database)?.has(key) || !(await rebound())) {
450
+ await full();
451
+ if (read && (!read.reread || (await read.reread()) === read.version)) {
452
+ const kept = sharedAttestations.get(read.version, read.database) ?? sharedAttestations.set(read.version, read.database, new Set());
453
+ kept.add(key);
454
+ }
455
+ }
456
+ if (origin)
457
+ keepAttestedOn(origin, key);
458
+ }
459
+ /** How many rollbacks have passed through this transaction's handle; undefined
460
+ * for anything that is not one. */
461
+ export function transactionRollbacks(client) {
462
+ return transactions.get(client)?.count;
463
+ }
464
+ /**
465
+ * Statements asked together and answered in order, on a transaction's handle
466
+ * or view: one round trip where its client pipelines (a writer's,
467
+ * postgresPool.ts), one each where it does not, with the same answers.
468
+ *
469
+ * Only inside the transaction — the handle's BEGIN sent first, on this handle
470
+ * or as the first statement here. There a statement that fails aborts the
471
+ * transaction, and every one sent behind it fails without effect ("current
472
+ * transaction is aborted"), so nothing runs that depended on one that did not;
473
+ * outside a transaction block each would commit on its own, which is why a
474
+ * bare client is refused. Every answer is awaited before this returns or
475
+ * throws, so the connection is never left mid-pipeline, and the first failure
476
+ * in order is the one thrown: the ones behind it only say it happened.
477
+ *
478
+ * `check` reads each answer as it arrives, in order, before the next one is
479
+ * read: a check that throws is the failure (the caller rolls the transaction
480
+ * back), and no later answer reaches a check. Behind a transaction-mode pooler
481
+ * (PgBouncer) a pipeline stays on its one server connection: the server says
482
+ * it is idle only after the COMMIT or ROLLBACK that ends the transaction, which
483
+ * this never sends ahead of a statement that could still fail.
484
+ */
485
+ export async function pipelined(client, statements, check) {
486
+ const state = transactions.get(client);
487
+ if (!state)
488
+ throw new TypeError('pipelined() runs on a transaction handle, inside its transaction.');
489
+ const ask = (statement) => (typeof statement === 'string'
490
+ ? client.query(statement)
491
+ : statement.values?.length
492
+ ? client.query(statement.text, [...statement.values])
493
+ : client.query(statement.text));
494
+ const answers = [];
495
+ if (!state.pipelines) {
496
+ for (const [index, statement] of statements.entries()) {
497
+ const answer = await ask(statement);
498
+ check?.(answer, index);
499
+ answers.push(answer);
500
+ }
501
+ return answers;
502
+ }
503
+ const sent = statements.map(ask);
504
+ // Each is handled here, so one behind a failure never rejects unheard.
505
+ const settled = await Promise.allSettled(sent);
506
+ let failure;
507
+ for (const [index, outcome] of settled.entries()) {
508
+ if (failure)
509
+ continue;
510
+ if (outcome.status === 'rejected')
511
+ failure = { error: outcome.reason };
512
+ else
513
+ try {
514
+ check?.(outcome.value, index);
515
+ answers.push(outcome.value);
516
+ }
517
+ catch (error) {
518
+ failure = { error };
519
+ }
520
+ }
521
+ if (failure)
522
+ throw failure.error;
523
+ return answers;
524
+ }
@@ -0,0 +1,30 @@
1
+ /** Runtime state, by an adapter id that may carry the schema: anything in the runtime schema, and a
2
+ * reserved name anywhere (an App table may not take one, so it is refused as runtime state too). */
3
+ export declare const isRuntimeRelation: (id: string) => boolean;
4
+ /** `schema.table`, both halves quoted. */
5
+ export declare function qualified(at: {
6
+ schema: string;
7
+ name: string;
8
+ }): string;
9
+ /** Keep the password out of the label, the logs and the UI. */
10
+ export declare function redact(connectionString: string): string;
11
+ /**
12
+ * The `pg` options for a connection URL. libpq's `sslrootcert=system` means
13
+ * "verify against the system's CAs", which PlanetScale's own strings carry;
14
+ * pg-connection-string reads every `sslrootcert` as a file path and fails on
15
+ * `system`. Strip it and ask for a verified connection: Node checks the
16
+ * certificate chain and the host name against its default roots, which is
17
+ * verify-full. A string's own `sslmode` still wins, as it does for pg; none of
18
+ * its values weakens this, because `disable` is the operator's word.
19
+ */
20
+ export declare function pgConnectionOptions(connectionString: string): {
21
+ connectionString: string;
22
+ ssl?: {
23
+ rejectUnauthorized: true;
24
+ };
25
+ };
26
+ /** One value, made safe to send as JSON. See `toJsonSafe` for the row form. */
27
+ export declare function valueSafe(v: unknown): unknown;
28
+ /** As toJsonSafe, but a blob stays its bytes: a file download asked for them (`QueryRequest.binary`). */
29
+ export declare function withBytes(row: Record<string, unknown>): Record<string, unknown>;
30
+ export declare function toJsonSafe(row: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,75 @@
1
+ /** PostgreSQL identifiers, connection labels, and JSON-safe result values. */
2
+ import { POSTGRES_STYLE } from '../shared/filter.js';
3
+ import { isRuntimeRelation as inRuntimeSchema, isRuntimeTable } from '../shared/runtimeTables.js';
4
+ /** Runtime state, by an adapter id that may carry the schema: anything in the runtime schema, and a
5
+ * reserved name anywhere (an App table may not take one, so it is refused as runtime state too). */
6
+ export const isRuntimeRelation = (id) => {
7
+ const dot = id.indexOf('.');
8
+ return (isRuntimeTable(id) || isRuntimeTable(id.slice(dot + 1)) || (dot > 0 && inRuntimeSchema('postgres', id.slice(0, dot), id.slice(dot + 1))));
9
+ };
10
+ /** `schema.table`, both halves quoted. */
11
+ export function qualified(at) {
12
+ return `${POSTGRES_STYLE.quote(at.schema)}.${POSTGRES_STYLE.quote(at.name)}`;
13
+ }
14
+ /** Keep the password out of the label, the logs and the UI. */
15
+ export function redact(connectionString) {
16
+ try {
17
+ const url = new URL(connectionString);
18
+ return `${url.hostname}${url.pathname}`;
19
+ }
20
+ catch {
21
+ return 'postgres';
22
+ }
23
+ }
24
+ /**
25
+ * The `pg` options for a connection URL. libpq's `sslrootcert=system` means
26
+ * "verify against the system's CAs", which PlanetScale's own strings carry;
27
+ * pg-connection-string reads every `sslrootcert` as a file path and fails on
28
+ * `system`. Strip it and ask for a verified connection: Node checks the
29
+ * certificate chain and the host name against its default roots, which is
30
+ * verify-full. A string's own `sslmode` still wins, as it does for pg; none of
31
+ * its values weakens this, because `disable` is the operator's word.
32
+ */
33
+ export function pgConnectionOptions(connectionString) {
34
+ const at = connectionString.indexOf('?');
35
+ if (at < 0 || !/(^|[?&])sslrootcert=system(&|$)/i.test(connectionString.slice(at)))
36
+ return { connectionString };
37
+ const query = connectionString
38
+ .slice(at + 1)
39
+ .split('&')
40
+ .filter((pair) => !/^sslrootcert=system$/i.test(pair))
41
+ .join('&');
42
+ const stripped = connectionString.slice(0, at) + (query ? `?${query}` : '');
43
+ // `disable` is the operator's word: the root is dropped but no TLS is asked for.
44
+ if (/(^|&)sslmode=disable(&|$)/i.test(query))
45
+ return { connectionString: stripped };
46
+ return { connectionString: stripped, ssl: { rejectUnauthorized: true } };
47
+ }
48
+ /** One value, made safe to send as JSON. See `toJsonSafe` for the row form. */
49
+ export function valueSafe(v) {
50
+ if (typeof v === 'bigint')
51
+ return v.toString();
52
+ if (v instanceof Uint8Array)
53
+ return `<${v.byteLength} bytes>`;
54
+ if (v instanceof Date)
55
+ return v.toISOString();
56
+ return v;
57
+ }
58
+ /** As toJsonSafe, but a blob stays its bytes: a file download asked for them (`QueryRequest.binary`). */
59
+ export function withBytes(row) {
60
+ return Object.fromEntries(Object.entries(row).map(([key, value]) => [key, value instanceof Uint8Array ? value : valueSafe(value)]));
61
+ }
62
+ export function toJsonSafe(row) {
63
+ const out = {};
64
+ for (const [k, v] of Object.entries(row)) {
65
+ if (typeof v === 'bigint')
66
+ out[k] = v.toString();
67
+ else if (v instanceof Uint8Array)
68
+ out[k] = `<${v.byteLength} bytes>`;
69
+ else if (v instanceof Date)
70
+ out[k] = v.toISOString();
71
+ else
72
+ out[k] = v;
73
+ }
74
+ return out;
75
+ }