@mistriwork/engine 0.0.0 → 1.0.0-rc.11

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 (572) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -1
  3. package/dist/adapters/adapter.d.ts +726 -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 +441 -0
  38. package/dist/adapters/postgres.js +1841 -0
  39. package/dist/adapters/postgresCatalog.d.ts +107 -0
  40. package/dist/adapters/postgresCatalog.js +421 -0
  41. package/dist/adapters/postgresCatalogDigest.d.ts +30 -0
  42. package/dist/adapters/postgresCatalogDigest.js +93 -0
  43. package/dist/adapters/postgresCatalogRows.d.ts +64 -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/postgresWriteAhead.d.ts +47 -0
  64. package/dist/adapters/postgresWriteAhead.js +209 -0
  65. package/dist/adapters/replicas.d.ts +70 -0
  66. package/dist/adapters/replicas.js +208 -0
  67. package/dist/adapters/reservedSql.d.ts +38 -0
  68. package/dist/adapters/reservedSql.js +264 -0
  69. package/dist/adapters/rolePrivileges.d.ts +17 -0
  70. package/dist/adapters/rolePrivileges.js +22 -0
  71. package/dist/adapters/scoped/keyRows.d.ts +65 -0
  72. package/dist/adapters/scoped/keyRows.js +179 -0
  73. package/dist/adapters/scoped/keyTypes.d.ts +34 -0
  74. package/dist/adapters/scoped/keyTypes.js +66 -0
  75. package/dist/adapters/scoped/postgresScopeCatalog.d.ts +34 -0
  76. package/dist/adapters/scoped/postgresScopeCatalog.js +457 -0
  77. package/dist/adapters/scoped/postgresTriggers.d.ts +137 -0
  78. package/dist/adapters/scoped/postgresTriggers.js +1545 -0
  79. package/dist/adapters/scoped/scopeTriggers.d.ts +122 -0
  80. package/dist/adapters/scoped/scopeTriggers.js +131 -0
  81. package/dist/adapters/scoped/scopedCommandOperations.d.ts +5 -0
  82. package/dist/adapters/scoped/scopedCommandOperations.js +48 -0
  83. package/dist/adapters/scoped/scopedReads.d.ts +22 -0
  84. package/dist/adapters/scoped/scopedReads.js +192 -0
  85. package/dist/adapters/scoped/scopedTransaction.d.ts +159 -0
  86. package/dist/adapters/scoped/scopedTransaction.js +547 -0
  87. package/dist/adapters/scoped/sqliteScopeCatalog.d.ts +32 -0
  88. package/dist/adapters/scoped/sqliteScopeCatalog.js +420 -0
  89. package/dist/adapters/scoped/sqliteTriggerSession.d.ts +64 -0
  90. package/dist/adapters/scoped/sqliteTriggerSession.js +245 -0
  91. package/dist/adapters/scoped/sqliteTriggers.d.ts +20 -0
  92. package/dist/adapters/scoped/sqliteTriggers.js +822 -0
  93. package/dist/adapters/scoped/storedText.d.ts +45 -0
  94. package/dist/adapters/scoped/storedText.js +61 -0
  95. package/dist/adapters/scoped/triggerEffects.d.ts +98 -0
  96. package/dist/adapters/scoped/triggerEffects.js +189 -0
  97. package/dist/adapters/scoped/triggerProof.d.ts +124 -0
  98. package/dist/adapters/scoped/triggerProof.js +366 -0
  99. package/dist/adapters/scoped/updateGuard.d.ts +3 -0
  100. package/dist/adapters/scoped/updateGuard.js +40 -0
  101. package/dist/adapters/serverSettings.d.ts +45 -0
  102. package/dist/adapters/serverSettings.js +46 -0
  103. package/dist/adapters/snapshotRead.d.ts +8 -0
  104. package/dist/adapters/snapshotRead.js +37 -0
  105. package/dist/adapters/sqlite.d.ts +273 -0
  106. package/dist/adapters/sqlite.js +1557 -0
  107. package/dist/adapters/sqliteCostlyReads.d.ts +33 -0
  108. package/dist/adapters/sqliteCostlyReads.js +49 -0
  109. package/dist/adapters/sqliteDecimals.d.ts +22 -0
  110. package/dist/adapters/sqliteDecimals.js +51 -0
  111. package/dist/adapters/sqliteHandles.d.ts +43 -0
  112. package/dist/adapters/sqliteHandles.js +143 -0
  113. package/dist/adapters/sqliteStatementProcess.d.ts +29 -0
  114. package/dist/adapters/sqliteStatementProcess.js +131 -0
  115. package/dist/adapters/statementControl.d.ts +34 -0
  116. package/dist/adapters/statementControl.js +90 -0
  117. package/dist/adapters/storeHost.d.ts +133 -0
  118. package/dist/adapters/storeHost.js +13 -0
  119. package/dist/adapters/telemetry/drivers.d.ts +21 -0
  120. package/dist/adapters/telemetry/drivers.js +321 -0
  121. package/dist/adapters/telemetry/metrics.d.ts +63 -0
  122. package/dist/adapters/telemetry/metrics.js +122 -0
  123. package/dist/adapters/telemetry/otlp.d.ts +12 -0
  124. package/dist/adapters/telemetry/otlp.js +320 -0
  125. package/dist/adapters/telemetry/otlpEncode.d.ts +48 -0
  126. package/dist/adapters/telemetry/otlpEncode.js +366 -0
  127. package/dist/adapters/telemetry/otlpEnv.d.ts +1 -0
  128. package/dist/adapters/telemetry/otlpEnv.js +12 -0
  129. package/dist/adapters/telemetry/serverTiming.d.ts +83 -0
  130. package/dist/adapters/telemetry/serverTiming.js +503 -0
  131. package/dist/adapters/telemetry/start.d.ts +10 -0
  132. package/dist/adapters/telemetry/start.js +25 -0
  133. package/dist/adapters/telemetry/statement.d.ts +16 -0
  134. package/dist/adapters/telemetry/statement.js +134 -0
  135. package/dist/adapters/telemetry/trace.d.ts +127 -0
  136. package/dist/adapters/telemetry/trace.js +295 -0
  137. package/dist/adapters/writeAhead.d.ts +27 -0
  138. package/dist/adapters/writeAhead.js +46 -0
  139. package/dist/adapters/writeAttribution.d.ts +18 -0
  140. package/dist/adapters/writeAttribution.js +23 -0
  141. package/dist/adapters/writeCapture.d.ts +80 -0
  142. package/dist/adapters/writeCapture.js +20 -0
  143. package/dist/adapters/writeLanes.d.ts +94 -0
  144. package/dist/adapters/writeLanes.js +232 -0
  145. package/dist/engine.d.ts +15 -0
  146. package/dist/engine.js +13 -0
  147. package/dist/server/auth/credentials.d.ts +61 -0
  148. package/dist/server/auth/credentials.js +260 -0
  149. package/dist/server/cacheService.d.ts +50 -0
  150. package/dist/server/cacheService.js +110 -0
  151. package/dist/server/cli/args.d.ts +182 -0
  152. package/dist/server/cli/args.js +348 -0
  153. package/dist/server/cli/bin.d.ts +5 -0
  154. package/dist/server/cli/bin.js +66 -0
  155. package/dist/server/cli/browser.d.ts +15 -0
  156. package/dist/server/cli/browser.js +37 -0
  157. package/dist/server/cli/config.d.ts +50 -0
  158. package/dist/server/cli/config.js +206 -0
  159. package/dist/server/cli/startup.d.ts +36 -0
  160. package/dist/server/cli/startup.js +128 -0
  161. package/dist/server/cli/startupOptions.d.ts +63 -0
  162. package/dist/server/cli/startupOptions.js +143 -0
  163. package/dist/server/cli/subcommand.d.ts +28 -0
  164. package/dist/server/cli/subcommand.js +32 -0
  165. package/dist/server/cli/usage.d.ts +13 -0
  166. package/dist/server/cli/usage.js +31 -0
  167. package/dist/server/clientHttp.d.ts +184 -0
  168. package/dist/server/clientHttp.js +700 -0
  169. package/dist/server/clientSurface.d.ts +128 -0
  170. package/dist/server/clientSurface.js +182 -0
  171. package/dist/server/columnGrants.d.ts +106 -0
  172. package/dist/server/columnGrants.js +741 -0
  173. package/dist/server/compileCache.d.ts +1 -0
  174. package/dist/server/compileCache.js +30 -0
  175. package/dist/server/config/locations.d.ts +1 -0
  176. package/dist/server/config/locations.js +15 -0
  177. package/dist/server/config/profile.d.ts +123 -0
  178. package/dist/server/config/profile.js +236 -0
  179. package/dist/server/configPaths.d.ts +7 -0
  180. package/dist/server/configPaths.js +34 -0
  181. package/dist/server/configSections.d.ts +64 -0
  182. package/dist/server/configSections.js +72 -0
  183. package/dist/server/connectionRedaction.d.ts +30 -0
  184. package/dist/server/connectionRedaction.js +77 -0
  185. package/dist/server/connections.d.ts +358 -0
  186. package/dist/server/connections.js +988 -0
  187. package/dist/server/constraints.d.ts +82 -0
  188. package/dist/server/constraints.js +169 -0
  189. package/dist/server/demo.d.ts +9 -0
  190. package/dist/server/demo.js +554 -0
  191. package/dist/server/devclient.d.ts +108 -0
  192. package/dist/server/devclient.js +361 -0
  193. package/dist/server/evidence.d.ts +55 -0
  194. package/dist/server/evidence.js +323 -0
  195. package/dist/server/hiddenColumns.d.ts +32 -0
  196. package/dist/server/hiddenColumns.js +244 -0
  197. package/dist/server/http/baselineHeaders.d.ts +24 -0
  198. package/dist/server/http/baselineHeaders.js +12 -0
  199. package/dist/server/http/captured.d.ts +35 -0
  200. package/dist/server/http/captured.js +73 -0
  201. package/dist/server/http/clock.d.ts +1 -0
  202. package/dist/server/http/clock.js +14 -0
  203. package/dist/server/http/connectionSource.d.ts +4 -0
  204. package/dist/server/http/connectionSource.js +48 -0
  205. package/dist/server/http/context.d.ts +189 -0
  206. package/dist/server/http/context.js +11 -0
  207. package/dist/server/http/crawlerText.d.ts +15 -0
  208. package/dist/server/http/crawlerText.js +32 -0
  209. package/dist/server/http/dataRoutes.d.ts +88 -0
  210. package/dist/server/http/dataRoutes.js +137 -0
  211. package/dist/server/http/door.d.ts +57 -0
  212. package/dist/server/http/door.js +39 -0
  213. package/dist/server/http/exportRoute.d.ts +15 -0
  214. package/dist/server/http/exportRoute.js +320 -0
  215. package/dist/server/http/firstPaint.d.ts +108 -0
  216. package/dist/server/http/firstPaint.js +262 -0
  217. package/dist/server/http/httpOperationRoutes.d.ts +11 -0
  218. package/dist/server/http/httpOperationRoutes.js +50 -0
  219. package/dist/server/http/pageReads.d.ts +20 -0
  220. package/dist/server/http/pageReads.js +205 -0
  221. package/dist/server/http/pageRoutes.d.ts +39 -0
  222. package/dist/server/http/pageRoutes.js +291 -0
  223. package/dist/server/http/probes.d.ts +22 -0
  224. package/dist/server/http/probes.js +27 -0
  225. package/dist/server/http/rateLimit.d.ts +131 -0
  226. package/dist/server/http/rateLimit.js +351 -0
  227. package/dist/server/http/readRoutes.d.ts +9 -0
  228. package/dist/server/http/readRoutes.js +131 -0
  229. package/dist/server/http/readRouting.d.ts +20 -0
  230. package/dist/server/http/readRouting.js +80 -0
  231. package/dist/server/http/recordCompose.d.ts +67 -0
  232. package/dist/server/http/recordCompose.js +167 -0
  233. package/dist/server/http/recordWrites.d.ts +89 -0
  234. package/dist/server/http/recordWrites.js +298 -0
  235. package/dist/server/http/refusalReport.d.ts +38 -0
  236. package/dist/server/http/refusalReport.js +75 -0
  237. package/dist/server/http/reply.d.ts +130 -0
  238. package/dist/server/http/reply.js +394 -0
  239. package/dist/server/http/requestOrigin.d.ts +11 -0
  240. package/dist/server/http/requestOrigin.js +8 -0
  241. package/dist/server/http/router.d.ts +45 -0
  242. package/dist/server/http/router.js +22 -0
  243. package/dist/server/http/serverCore.d.ts +68 -0
  244. package/dist/server/http/serverCore.js +177 -0
  245. package/dist/server/http/traceRequest.d.ts +30 -0
  246. package/dist/server/http/traceRequest.js +224 -0
  247. package/dist/server/http/trust.d.ts +261 -0
  248. package/dist/server/http/trust.js +472 -0
  249. package/dist/server/http/writeRefusal.d.ts +33 -0
  250. package/dist/server/http/writeRefusal.js +24 -0
  251. package/dist/server/httpConnection.d.ts +49 -0
  252. package/dist/server/httpConnection.js +170 -0
  253. package/dist/server/impact.d.ts +55 -0
  254. package/dist/server/impact.js +47 -0
  255. package/dist/server/journal.d.ts +134 -0
  256. package/dist/server/journal.js +398 -0
  257. package/dist/server/keysetReadHttp.d.ts +52 -0
  258. package/dist/server/keysetReadHttp.js +85 -0
  259. package/dist/server/layouts.d.ts +49 -0
  260. package/dist/server/layouts.js +192 -0
  261. package/dist/server/migrate/cli.d.ts +102 -0
  262. package/dist/server/migrate/cli.js +702 -0
  263. package/dist/server/migrate/database.d.ts +37 -0
  264. package/dist/server/migrate/database.js +247 -0
  265. package/dist/server/migrate/desired.d.ts +76 -0
  266. package/dist/server/migrate/desired.js +292 -0
  267. package/dist/server/migrate/files.d.ts +34 -0
  268. package/dist/server/migrate/files.js +141 -0
  269. package/dist/server/migrate/flyway.d.ts +7 -0
  270. package/dist/server/migrate/flyway.js +69 -0
  271. package/dist/server/migrate/history.d.ts +70 -0
  272. package/dist/server/migrate/history.js +211 -0
  273. package/dist/server/migrate/runner.d.ts +100 -0
  274. package/dist/server/migrate/runner.js +413 -0
  275. package/dist/server/migrate/snapshot.d.ts +30 -0
  276. package/dist/server/migrate/snapshot.js +239 -0
  277. package/dist/server/migrate/target.d.ts +33 -0
  278. package/dist/server/migrate/target.js +82 -0
  279. package/dist/server/openapiDraft.d.ts +25 -0
  280. package/dist/server/openapiDraft.js +171 -0
  281. package/dist/server/operations/diagnostics.d.ts +101 -0
  282. package/dist/server/operations/diagnostics.js +284 -0
  283. package/dist/server/operations/requestMetrics.d.ts +33 -0
  284. package/dist/server/operations/requestMetrics.js +94 -0
  285. package/dist/server/packageVersion.d.ts +1 -0
  286. package/dist/server/packageVersion.js +11 -0
  287. package/dist/server/poolConfig.d.ts +34 -0
  288. package/dist/server/poolConfig.js +114 -0
  289. package/dist/server/product.d.ts +20 -0
  290. package/dist/server/product.js +12 -0
  291. package/dist/server/recordHistoryOperations.d.ts +39 -0
  292. package/dist/server/recordHistoryOperations.js +43 -0
  293. package/dist/server/recordWriteOperations.d.ts +111 -0
  294. package/dist/server/recordWriteOperations.js +329 -0
  295. package/dist/server/resourceReadHttp.d.ts +81 -0
  296. package/dist/server/resourceReadHttp.js +606 -0
  297. package/dist/server/resourceReadOperations.d.ts +147 -0
  298. package/dist/server/resourceReadOperations.js +452 -0
  299. package/dist/server/scaffoldMachine.d.ts +54 -0
  300. package/dist/server/scaffoldMachine.js +184 -0
  301. package/dist/server/seed/cli.d.ts +20 -0
  302. package/dist/server/seed/cli.js +164 -0
  303. package/dist/server/seed/lexicon.d.ts +26 -0
  304. package/dist/server/seed/lexicon.js +585 -0
  305. package/dist/server/seed/seed.d.ts +70 -0
  306. package/dist/server/seed/seed.js +779 -0
  307. package/dist/server/seed/words.d.ts +21 -0
  308. package/dist/server/seed/words.js +164 -0
  309. package/dist/server/serverRequests.d.ts +6 -0
  310. package/dist/server/serverRequests.js +33 -0
  311. package/dist/server/serverTimeouts.d.ts +33 -0
  312. package/dist/server/serverTimeouts.js +32 -0
  313. package/dist/server/shapeonly.d.ts +32 -0
  314. package/dist/server/shapeonly.js +115 -0
  315. package/dist/server/startupWarnings.d.ts +32 -0
  316. package/dist/server/startupWarnings.js +92 -0
  317. package/dist/shared/addressParams.d.ts +28 -0
  318. package/dist/shared/addressParams.js +47 -0
  319. package/dist/shared/aggregate.d.ts +49 -0
  320. package/dist/shared/aggregate.js +107 -0
  321. package/dist/shared/appCards.d.ts +123 -0
  322. package/dist/shared/appCards.js +385 -0
  323. package/dist/shared/appComponents.d.ts +177 -0
  324. package/dist/shared/appComponents.js +422 -0
  325. package/dist/shared/appDocuments.d.ts +43 -0
  326. package/dist/shared/appDocuments.js +131 -0
  327. package/dist/shared/appEmbeds.d.ts +21 -0
  328. package/dist/shared/appEmbeds.js +24 -0
  329. package/dist/shared/appIcons.d.ts +28 -0
  330. package/dist/shared/appIcons.js +223 -0
  331. package/dist/shared/appLinks.d.ts +17 -0
  332. package/dist/shared/appLinks.js +124 -0
  333. package/dist/shared/appListColumns.d.ts +3 -0
  334. package/dist/shared/appListColumns.js +66 -0
  335. package/dist/shared/appLocale.d.ts +36 -0
  336. package/dist/shared/appLocale.js +86 -0
  337. package/dist/shared/appMessages.d.ts +44 -0
  338. package/dist/shared/appMessages.js +78 -0
  339. package/dist/shared/appNoun.d.ts +21 -0
  340. package/dist/shared/appNoun.js +32 -0
  341. package/dist/shared/autoBucket.d.ts +98 -0
  342. package/dist/shared/autoBucket.js +305 -0
  343. package/dist/shared/autoValues.d.ts +25 -0
  344. package/dist/shared/autoValues.js +25 -0
  345. package/dist/shared/breakdown.d.ts +228 -0
  346. package/dist/shared/breakdown.js +570 -0
  347. package/dist/shared/breakdowntext.d.ts +41 -0
  348. package/dist/shared/breakdowntext.js +400 -0
  349. package/dist/shared/builtInThemes.d.ts +2 -0
  350. package/dist/shared/builtInThemes.js +771 -0
  351. package/dist/shared/chartSeparation.d.ts +11 -0
  352. package/dist/shared/chartSeparation.js +58 -0
  353. package/dist/shared/clauses.d.ts +22 -0
  354. package/dist/shared/clauses.js +97 -0
  355. package/dist/shared/columnCaption.d.ts +16 -0
  356. package/dist/shared/columnCaption.js +90 -0
  357. package/dist/shared/commandFieldPath.d.ts +2 -0
  358. package/dist/shared/commandFieldPath.js +7 -0
  359. package/dist/shared/commandWire.d.ts +26 -0
  360. package/dist/shared/commandWire.js +41 -0
  361. package/dist/shared/computed.d.ts +161 -0
  362. package/dist/shared/computed.js +378 -0
  363. package/dist/shared/computedParse.d.ts +13 -0
  364. package/dist/shared/computedParse.js +278 -0
  365. package/dist/shared/computedValue.d.ts +47 -0
  366. package/dist/shared/computedValue.js +191 -0
  367. package/dist/shared/connection.d.ts +30 -0
  368. package/dist/shared/connection.js +1 -0
  369. package/dist/shared/csv.d.ts +20 -0
  370. package/dist/shared/csv.js +63 -0
  371. package/dist/shared/dashLayout.d.ts +30 -0
  372. package/dist/shared/dashLayout.js +132 -0
  373. package/dist/shared/dashboardAsks.d.ts +93 -0
  374. package/dist/shared/dashboardAsks.js +129 -0
  375. package/dist/shared/dashboardTrend.d.ts +20 -0
  376. package/dist/shared/dashboardTrend.js +50 -0
  377. package/dist/shared/decimals.d.ts +37 -0
  378. package/dist/shared/decimals.js +148 -0
  379. package/dist/shared/declaredReferences.d.ts +50 -0
  380. package/dist/shared/declaredReferences.js +202 -0
  381. package/dist/shared/definedFields.d.ts +63 -0
  382. package/dist/shared/definedFields.js +103 -0
  383. package/dist/shared/definedValues.d.ts +63 -0
  384. package/dist/shared/definedValues.js +184 -0
  385. package/dist/shared/displayDefaults.d.ts +135 -0
  386. package/dist/shared/displayDefaults.js +543 -0
  387. package/dist/shared/dueDate.d.ts +6 -0
  388. package/dist/shared/dueDate.js +6 -0
  389. package/dist/shared/duration.d.ts +4 -0
  390. package/dist/shared/duration.js +23 -0
  391. package/dist/shared/fileBounds.d.ts +9 -0
  392. package/dist/shared/fileBounds.js +9 -0
  393. package/dist/shared/filter.d.ts +238 -0
  394. package/dist/shared/filter.js +332 -0
  395. package/dist/shared/firstPaint.d.ts +24 -0
  396. package/dist/shared/firstPaint.js +33 -0
  397. package/dist/shared/form.d.ts +21 -0
  398. package/dist/shared/form.js +25 -0
  399. package/dist/shared/formValues.d.ts +104 -0
  400. package/dist/shared/formValues.js +352 -0
  401. package/dist/shared/funnel.d.ts +45 -0
  402. package/dist/shared/funnel.js +108 -0
  403. package/dist/shared/httpOperations.d.ts +48 -0
  404. package/dist/shared/httpOperations.js +9 -0
  405. package/dist/shared/iconGlyphs.d.ts +4 -0
  406. package/dist/shared/iconGlyphs.js +151 -0
  407. package/dist/shared/iconWeights.d.ts +3 -0
  408. package/dist/shared/iconWeights.js +162 -0
  409. package/dist/shared/imageWidths.d.ts +32 -0
  410. package/dist/shared/imageWidths.js +38 -0
  411. package/dist/shared/keysetPage.d.ts +64 -0
  412. package/dist/shared/keysetPage.js +161 -0
  413. package/dist/shared/like.d.ts +20 -0
  414. package/dist/shared/like.js +29 -0
  415. package/dist/shared/listEmpty.d.ts +12 -0
  416. package/dist/shared/listEmpty.js +36 -0
  417. package/dist/shared/listFilters.d.ts +28 -0
  418. package/dist/shared/listFilters.js +84 -0
  419. package/dist/shared/listPresentations.d.ts +199 -0
  420. package/dist/shared/listPresentations.js +7 -0
  421. package/dist/shared/listQuestion.d.ts +52 -0
  422. package/dist/shared/listQuestion.js +137 -0
  423. package/dist/shared/lookPalettes.d.ts +62 -0
  424. package/dist/shared/lookPalettes.js +306 -0
  425. package/dist/shared/maskQuoted.d.ts +24 -0
  426. package/dist/shared/maskQuoted.js +48 -0
  427. package/dist/shared/mentionLabel.d.ts +19 -0
  428. package/dist/shared/mentionLabel.js +38 -0
  429. package/dist/shared/mentionLookup.d.ts +17 -0
  430. package/dist/shared/mentionLookup.js +64 -0
  431. package/dist/shared/menuCounts.d.ts +16 -0
  432. package/dist/shared/menuCounts.js +74 -0
  433. package/dist/shared/model.d.ts +79 -0
  434. package/dist/shared/model.js +153 -0
  435. package/dist/shared/money.d.ts +53 -0
  436. package/dist/shared/money.js +98 -0
  437. package/dist/shared/moneyEntry.d.ts +7 -0
  438. package/dist/shared/moneyEntry.js +27 -0
  439. package/dist/shared/mount.d.ts +118 -0
  440. package/dist/shared/mount.js +248 -0
  441. package/dist/shared/niceTicks.d.ts +26 -0
  442. package/dist/shared/niceTicks.js +50 -0
  443. package/dist/shared/order.d.ts +59 -0
  444. package/dist/shared/order.js +133 -0
  445. package/dist/shared/page.d.ts +135 -0
  446. package/dist/shared/page.js +1187 -0
  447. package/dist/shared/pageAnatomy.d.ts +99 -0
  448. package/dist/shared/pageAnatomy.js +370 -0
  449. package/dist/shared/pageConfig.d.ts +25 -0
  450. package/dist/shared/pageConfig.js +1308 -0
  451. package/dist/shared/pageEmptyActions.d.ts +12 -0
  452. package/dist/shared/pageEmptyActions.js +20 -0
  453. package/dist/shared/pageLayouts.d.ts +72 -0
  454. package/dist/shared/pageLayouts.js +205 -0
  455. package/dist/shared/pageModel.d.ts +785 -0
  456. package/dist/shared/pageModel.js +121 -0
  457. package/dist/shared/pagePaths.d.ts +180 -0
  458. package/dist/shared/pagePaths.js +869 -0
  459. package/dist/shared/pagePlans.d.ts +52 -0
  460. package/dist/shared/pagePlans.js +108 -0
  461. package/dist/shared/pageRoutes.d.ts +9 -0
  462. package/dist/shared/pageRoutes.js +9 -0
  463. package/dist/shared/query.d.ts +166 -0
  464. package/dist/shared/query.js +1302 -0
  465. package/dist/shared/queryDates.d.ts +12 -0
  466. package/dist/shared/queryDates.js +101 -0
  467. package/dist/shared/queryOperands.d.ts +99 -0
  468. package/dist/shared/queryOperands.js +131 -0
  469. package/dist/shared/reads.d.ts +103 -0
  470. package/dist/shared/reads.js +154 -0
  471. package/dist/shared/recordLabel.d.ts +51 -0
  472. package/dist/shared/recordLabel.js +123 -0
  473. package/dist/shared/recordReadKeys.d.ts +30 -0
  474. package/dist/shared/recordReadKeys.js +51 -0
  475. package/dist/shared/recordReads.d.ts +268 -0
  476. package/dist/shared/recordReads.js +368 -0
  477. package/dist/shared/recordview.d.ts +198 -0
  478. package/dist/shared/recordview.js +356 -0
  479. package/dist/shared/referenceModel.d.ts +58 -0
  480. package/dist/shared/referenceModel.js +194 -0
  481. package/dist/shared/refusal.d.ts +80 -0
  482. package/dist/shared/refusal.js +184 -0
  483. package/dist/shared/relatedCreate.d.ts +30 -0
  484. package/dist/shared/relatedCreate.js +162 -0
  485. package/dist/shared/resourceHttp.d.ts +464 -0
  486. package/dist/shared/resourceHttp.js +1 -0
  487. package/dist/shared/richText.d.ts +85 -0
  488. package/dist/shared/richText.js +305 -0
  489. package/dist/shared/rollups.d.ts +143 -0
  490. package/dist/shared/rollups.js +64 -0
  491. package/dist/shared/rowScope.d.ts +72 -0
  492. package/dist/shared/rowScope.js +376 -0
  493. package/dist/shared/runtimeTables.d.ts +44 -0
  494. package/dist/shared/runtimeTables.js +79 -0
  495. package/dist/shared/schema.d.ts +529 -0
  496. package/dist/shared/schema.js +627 -0
  497. package/dist/shared/schematext.d.ts +38 -0
  498. package/dist/shared/schematext.js +101 -0
  499. package/dist/shared/scopeCatalog.d.ts +29 -0
  500. package/dist/shared/scopeCatalog.js +472 -0
  501. package/dist/shared/servedApp.d.ts +686 -0
  502. package/dist/shared/servedApp.js +45 -0
  503. package/dist/shared/sessionLease.d.ts +34 -0
  504. package/dist/shared/sessionLease.js +3 -0
  505. package/dist/shared/shape.d.ts +55 -0
  506. package/dist/shared/shape.js +168 -0
  507. package/dist/shared/slug.d.ts +1 -0
  508. package/dist/shared/slug.js +12 -0
  509. package/dist/shared/sortText.d.ts +14 -0
  510. package/dist/shared/sortText.js +26 -0
  511. package/dist/shared/sqlRelation.d.ts +4 -0
  512. package/dist/shared/sqlRelation.js +8 -0
  513. package/dist/shared/sqlsaved.d.ts +44 -0
  514. package/dist/shared/sqlsaved.js +63 -0
  515. package/dist/shared/stitchedPaths.d.ts +27 -0
  516. package/dist/shared/stitchedPaths.js +38 -0
  517. package/dist/shared/structuredFilter.d.ts +22 -0
  518. package/dist/shared/structuredFilter.js +1 -0
  519. package/dist/shared/subtitlePath.d.ts +20 -0
  520. package/dist/shared/subtitlePath.js +24 -0
  521. package/dist/shared/suggest.d.ts +18 -0
  522. package/dist/shared/suggest.js +59 -0
  523. package/dist/shared/tableSizing.d.ts +4 -0
  524. package/dist/shared/tableSizing.js +9 -0
  525. package/dist/shared/tagLists.d.ts +57 -0
  526. package/dist/shared/tagLists.js +34 -0
  527. package/dist/shared/textRules.d.ts +54 -0
  528. package/dist/shared/textRules.js +133 -0
  529. package/dist/shared/theme.d.ts +94 -0
  530. package/dist/shared/theme.js +800 -0
  531. package/dist/shared/themeColor.d.ts +34 -0
  532. package/dist/shared/themeColor.js +109 -0
  533. package/dist/shared/themeFaces.d.ts +30 -0
  534. package/dist/shared/themeFaces.js +42 -0
  535. package/dist/shared/themeInk.d.ts +20 -0
  536. package/dist/shared/themeInk.js +52 -0
  537. package/dist/shared/themeLooks.d.ts +9 -0
  538. package/dist/shared/themeLooks.js +572 -0
  539. package/dist/shared/themeParts.d.ts +26 -0
  540. package/dist/shared/themeParts.js +71 -0
  541. package/dist/shared/themePartsCheck.d.ts +21 -0
  542. package/dist/shared/themePartsCheck.js +91 -0
  543. package/dist/shared/themePresets.d.ts +85 -0
  544. package/dist/shared/themePresets.js +139 -0
  545. package/dist/shared/themeRecipeWords.d.ts +156 -0
  546. package/dist/shared/themeRecipeWords.js +156 -0
  547. package/dist/shared/themeRecipes.d.ts +213 -0
  548. package/dist/shared/themeRecipes.js +234 -0
  549. package/dist/shared/themeResolve.d.ts +55 -0
  550. package/dist/shared/themeResolve.js +52 -0
  551. package/dist/shared/themeTokens.d.ts +107 -0
  552. package/dist/shared/themeTokens.js +116 -0
  553. package/dist/shared/themeType.d.ts +38 -0
  554. package/dist/shared/themeType.js +205 -0
  555. package/dist/shared/unitWord.d.ts +4 -0
  556. package/dist/shared/unitWord.js +37 -0
  557. package/dist/shared/view.d.ts +195 -0
  558. package/dist/shared/view.js +987 -0
  559. package/dist/shared/viewLabels.d.ts +47 -0
  560. package/dist/shared/viewLabels.js +459 -0
  561. package/dist/shared/viewPaths.d.ts +248 -0
  562. package/dist/shared/viewPaths.js +294 -0
  563. package/dist/shared/viewtext.d.ts +57 -0
  564. package/dist/shared/viewtext.js +282 -0
  565. package/dist/shared/vocabulary.d.ts +71 -0
  566. package/dist/shared/vocabulary.js +249 -0
  567. package/dist/shared/weekStart.d.ts +7 -0
  568. package/dist/shared/weekStart.js +36 -0
  569. package/mark.svg +1 -0
  570. package/package.json +266 -3
  571. package/schema/model.d.ts +298 -0
  572. package/schema/theme.d.ts +587 -0
@@ -0,0 +1,547 @@
1
+ import { Refusal } from '../adapter.js';
2
+ import { buildWhere } from '../../shared/filter.js';
3
+ import { recordRefusalCause } from '../../shared/refusal.js';
4
+ import { coerceForColumn, columnKind } from '../../shared/schema.js';
5
+ import { blockingTriggers, firedBy, sayRuns, sayTriggers, sayWrite } from './scopeTriggers.js';
6
+ import { detachStoredText, overlaid, storedText, storedTextOf } from './storedText.js';
7
+ /** A foreign key's name in ScopeCatalog.references: its table, name and columns, each side. */
8
+ export const referenceKey = (fk) => JSON.stringify([fk.from.table, fk.name, fk.from.columns, fk.to.table, fk.to.columns]);
9
+ /** Whether a failure is the database's foreign key refusing a write: SQLite's SQLITE_CONSTRAINT_FOREIGNKEY, PostgreSQL's 23503. */
10
+ export const isForeignKeyViolation = (error) => {
11
+ const { code, errcode } = (error ?? {});
12
+ return errcode === 787 || code === '23503';
13
+ };
14
+ /**
15
+ * A foreign key's refusal of a scoped write, said as a hidden parent's is: the database's own error says whether the
16
+ * row it points at exists (and, on PostgreSQL, its key, a default's part of it included), which the principal's rows
17
+ * may hide. Whichever statement it came from, at the statement or at COMMIT for a deferred one, it is the one
18
+ * refusal; what the operator reads names the constraint and nothing of the row.
19
+ */
20
+ export const foreignKeyRefusal = (error) => {
21
+ const constraint = error?.constraint;
22
+ return recordRefusalCause(new ScopeRefusal('This operation is not available in the current row scope.'), `The database's foreign key${typeof constraint === 'string' ? ` ${JSON.stringify(constraint)}` : ''} refused the write: a row it points at is not in the principal's rows, or does not exist.`);
23
+ };
24
+ /** A table's triggers as a refusal names them: `the trigger "audit_order"`, `the triggers "a", "b"`. */
25
+ export const triggerNames = (names) => `the trigger${names.length === 1 ? '' : 's'} ${names.map((name) => JSON.stringify(name)).join(', ')}`;
26
+ /* The trigger vocabulary, for `mistri check` (commandTriggerChecks.ts), which says the same refusal ahead of time. */
27
+ export { blocksEveryWrite, sayBlocked, sayRuns, sayTriggers } from './scopeTriggers.js';
28
+ /** The keyed-effect judge (triggerEffects.ts), loaded where it is used: a process that never meets a named trigger never loads it. */
29
+ export const loadTriggerEffects = () => import('./triggerEffects.js');
30
+ /**
31
+ * The count of rows of `fk.from.table` that reference the `fk.to.table` row
32
+ * `key` names, as the database's own foreign key matches them, and so as its
33
+ * cascade would reach them.
34
+ *
35
+ * A foreign key compares a reference as the parent key compares: SQLite
36
+ * applies the parent column's affinity and collation to the child's value
37
+ * (an untyped child column holding the number 7 references the text key
38
+ * '7'), PostgreSQL the parent's collation where the child's is the default.
39
+ * The child counted by its own column (`child.col = ?`) compares as the child
40
+ * does, and missed such a reference, which the delete's cascade then reached.
41
+ * Here each parent column is the left side of a join, where both engines take
42
+ * its affinity and collation as the foreign key does; where two collations
43
+ * conflict, PostgreSQL refuses the count, and the delete with it.
44
+ */
45
+ export function referencesStatement(schema, fk, key, style) {
46
+ const relation = (id) => {
47
+ const table = schema.tables.find((table) => table.id === id);
48
+ if (!table)
49
+ throw new Refusal('This operation is not available in the current row scope.');
50
+ return `${style.quote(table.schema)}.${style.quote(table.name)}`;
51
+ };
52
+ const on = fk.to.columns.map((column, index) => `p.${style.quote(column)} = c.${style.quote(fk.from.columns[index])}`).join(' AND ');
53
+ const where = buildWhere(key, style, 1, (name) => `p.${style.quote(name)}`);
54
+ if (!where.text)
55
+ throw new Refusal('This operation is not available in the current row scope.');
56
+ return {
57
+ text: `SELECT COUNT(*) AS n FROM ${relation(fk.from.table)} AS c JOIN ${relation(fk.to.table)} AS p ON ${on}${where.text}`,
58
+ params: where.params,
59
+ };
60
+ }
61
+ /** The tables where `scope` is exactly `bound`, and the bound admits rows at all: nothing in it is hidden there. */
62
+ export function wholeWithin(scope, bound) {
63
+ return new Set(Object.keys(bound).filter((table) => bound[table] !== false && Object.hasOwn(scope, table) && JSON.stringify(scope[table]) === JSON.stringify(bound[table])));
64
+ }
65
+ /** A bound names exactly the scope's tables: it bounds that scope, never another. */
66
+ export function sameTables(scope, bound) {
67
+ const tables = Object.keys(scope);
68
+ return tables.length === Object.keys(bound).length && tables.every((table) => Object.hasOwn(bound, table));
69
+ }
70
+ /* The caller hears one sentence, whatever the rule: which row a scope hides,
71
+ and that it exists, is what the scope keeps. The rule and the row are
72
+ recorded for the operator (shared/refusal.ts) — a command that failed here
73
+ used to answer a bare 503 with nothing anywhere saying which check it was. */
74
+ /** A write the row scope refuses: for good, for this request — outside the principal's rows, off the footprint, on a
75
+ * table it cannot bound. Its own class so the executor can say it as forbidden rather than as a while (503); the
76
+ * words stay value-free, the reason recorded beneath them for the owner. */
77
+ export class ScopeRefusal extends Refusal {
78
+ }
79
+ const refuse = (reason) => {
80
+ throw recordRefusalCause(new ScopeRefusal('This operation is not available in the current row scope.'), reason);
81
+ };
82
+ const keyText = (key) => Object.entries(key)
83
+ .map(([column, value]) => `${column} ${JSON.stringify(value)}`)
84
+ .join(', ');
85
+ const comparable = (value) => typeof value === 'string' || (typeof value === 'number' && Number.isFinite(value));
86
+ /* A value for a number column as the write sends it: "" is NULL, "7.0" is 7 (sqlite.ts and postgres.ts coerce every
87
+ value by its column's type before binding it). Only numbers: a parent check binds what it is given, and a number
88
+ is where the given text and the written value part. */
89
+ const asWritten = (type, value) => type !== undefined && columnKind(type) === 'number' && typeof value === 'string' ? coerceForColumn(type, value) : value;
90
+ /* A value a PostgreSQL reference compared through its foreign key's equality (Condition.equality) is bound as text and
91
+ read by the column's type: a boolean as its word. Every other type a reference may be (keyTypes.ts) the driver reads
92
+ as a string or a number already, which is its text. */
93
+ const asBound = (value) => (typeof value === 'boolean' ? String(value) : value);
94
+ /* Two values a check binds name the same parent: identical, or, where both are bound as text read by the column's type
95
+ (Condition.equality), the same text — a given 7 and the stored "7" are the one parameter. */
96
+ const sameBound = (a, b, equality) => a === b ||
97
+ (equality &&
98
+ (typeof a === 'string' || typeof a === 'number') &&
99
+ (typeof b === 'string' || typeof b === 'number') &&
100
+ String(a) === String(b));
101
+ /** `scope` with each child rule's key conditions on a reference to a table in `made` extended by those rows' keys. */
102
+ function withOwnRows(schema, scope, made) {
103
+ const out = { ...scope };
104
+ for (const [table, rule] of Object.entries(scope)) {
105
+ if (typeof rule !== 'object')
106
+ continue;
107
+ const extra = new Map();
108
+ for (const fk of schema.foreignKeys) {
109
+ // A composite reference is named by no single condition: it is left as the policy said it.
110
+ if (fk.from.table !== table || fk.from.columns.length !== 1)
111
+ continue;
112
+ const rows = made.get(fk.to.table);
113
+ if (!rows?.length)
114
+ continue;
115
+ const values = rows.map((row) => row[fk.to.columns[0]]).filter(comparable);
116
+ if (values.length)
117
+ extra.set(fk.from.columns[0], [...(extra.get(fk.from.columns[0]) ?? []), ...values]);
118
+ }
119
+ if (!extra.size)
120
+ continue;
121
+ out[table] = {
122
+ ...rule,
123
+ groups: rule.groups.map((group) => group.map((condition) => {
124
+ const added = extra.get(condition.column);
125
+ if (!added || condition.other !== undefined || condition.any !== undefined)
126
+ return condition;
127
+ if (condition.op === '=' && comparable(condition.value))
128
+ return { ...condition, op: 'in', value: [condition.value, ...added] };
129
+ if (condition.op === 'in' && Array.isArray(condition.value))
130
+ return { ...condition, value: [...condition.value, ...added] };
131
+ return condition;
132
+ })),
133
+ };
134
+ }
135
+ return out;
136
+ }
137
+ /** Runs INSIDE a single queued operation. The supplied guards retain actual
138
+ * stored scalar types, not display conversions (a blob label is not a key).
139
+ * This capability deliberately refuses side effects it cannot bound. */
140
+ export function createScopedTransaction(catalog, records, reads, guards, locks, bound, own, triggers) {
141
+ /* The rows this transaction inserted inside the principal's rows, by table, and the reads that count them in
142
+ (ScopeOwnRows). Rebuilt on each such insert; until the first, the reads are the ones resolved for the request. */
143
+ const made = new Map();
144
+ const madeBy = (table, row) => {
145
+ if (!own)
146
+ return;
147
+ made.set(table.id, [...(made.get(table.id) ?? []), row]);
148
+ const scope = withOwnRows(catalog.schema, own.scope, made);
149
+ reads = own.reads(scope, false);
150
+ guards = own.reads(scope, true);
151
+ };
152
+ const target = (id, write) => {
153
+ const table = catalog.schema.tables.find((table) => table.id === id);
154
+ if (!table)
155
+ return refuse(`"${id}" is not in this write's footprint: a command writes only the tables it declares.`);
156
+ if (catalog.hierarchy?.has(id))
157
+ return refuse(`"${id}" is part of a partition or inheritance hierarchy, which writes under a row policy do not support yet.`);
158
+ const triggers = catalog.writable.has(id) ? undefined : catalog.triggered?.get(id);
159
+ if (triggers) {
160
+ /* A trigger does what no row policy bounds, so a scoped write fires none but those proven to validate their own
161
+ row. Decided per write: an update of a column no `UPDATE OF` names fires nothing. The refusal names the
162
+ trigger, or the owner is left guessing why a table they declared written is not. */
163
+ const foldCase = catalog.schema.dialect === 'sqlite';
164
+ // A trigger the App names and the proof accepts runs, its effects proven per write (triggerProof.ts).
165
+ const blocking = blockingTriggers(triggers, write, foldCase)
166
+ .filter((trigger) => !proof?.accepts(id, trigger))
167
+ .map((trigger) => ({ ...trigger, why: proof?.unaccepted(id, trigger) ?? trigger.why }));
168
+ if (blocking.length)
169
+ return refuse(`"${id}" cannot be written under a row policy: ${sayWrite(write)} ${sayRuns(blocking)} ${sayTriggers(blocking)}, whose effects the policy cannot bound. ` +
170
+ `A trigger that only checks NEW and OLD and raises does not block a write; mistri check names each command one blocks.`);
171
+ if (firedBy(triggers, write, foldCase).length)
172
+ locks?.relied?.(table);
173
+ }
174
+ else if (!catalog.writable.has(id)) {
175
+ const by = catalog.blockedBy?.get(id);
176
+ return refuse(by
177
+ ? `"${id}" cannot be written under a row policy: it has ${by}, whose writes the policy cannot bound.`
178
+ : `"${id}" is read-only in this scope: the command does not declare it written, or the principal's rows do not admit writing it.`);
179
+ }
180
+ if (!table.columns.some((column) => column.primaryKey))
181
+ return refuse(`"${id}" has no primary key, so a scoped write cannot prove which row it changed.`);
182
+ const unkeyed = catalog.unkeyed?.get(id);
183
+ if (unkeyed)
184
+ return refuse(`${unkeyed}.`);
185
+ return table;
186
+ };
187
+ const keyFilter = (table, key) => {
188
+ const pk = table.columns.filter((column) => column.primaryKey).map((column) => column.name);
189
+ if (!key || Object.keys(key).length !== pk.length || !pk.every((column) => Object.hasOwn(key, column) && comparable(key[column]))) {
190
+ return refuse(`A key for "${table.id}" names exactly its primary key (${pk.join(', ')}), each a text or a number.`);
191
+ }
192
+ return { groups: [pk.map((column) => ({ column, op: '=', value: key[column] }))] };
193
+ };
194
+ /* A row by its key, read after its lock. Lock before looking: the guard's
195
+ snapshot is then the row no other writer can move until this transaction
196
+ ends, so what the scope checks is what the write will change. Where the
197
+ writer sends together, the read leaves right behind the lock, in its
198
+ flight; the server runs it only once the lock is granted. */
199
+ /* A row by its key, with its reference columns' stored text beside it where the engine reads one (storedText.ts):
200
+ every check that takes a value from a stored row binds that text, never the driver's reading of it. */
201
+ const readStored = async (table, filter, within) => {
202
+ const texts = storedTextOf(catalog.schema, table);
203
+ const result = await within.query({ table: table.id, filter, limit: 2, offset: 0, ...(texts ? { storedText: true } : {}) });
204
+ return { ...result, rows: result.rows.map((row) => detachStoredText(texts, row)) };
205
+ };
206
+ const lockedRead = async (table, filter, within) => {
207
+ const locked = locks?.target(table, filter);
208
+ const read = () => readStored(table, filter, within);
209
+ if (!locks?.together) {
210
+ await locked;
211
+ return read();
212
+ }
213
+ const sent = read();
214
+ // Both heard before either is judged: the lock's failure, if it failed, is the one said.
215
+ await Promise.allSettled([locked, sent]);
216
+ await locked;
217
+ return sent;
218
+ };
219
+ const one = (table, key, result) => {
220
+ if (result.rows.length !== 1) {
221
+ return refuse(`The "${table.id}" row ${keyText(key)} is outside the principal's rows: the row policy (or tenant) does not admit it, before or after this write.`);
222
+ }
223
+ const row = result.rows[0];
224
+ // Null / opaque / nonportable keys cannot prove stored-row identity.
225
+ keyFilter(table, Object.fromEntries(table.columns.filter((column) => column.primaryKey).map((column) => [column.name, row[column.name]])));
226
+ return row;
227
+ };
228
+ const stored = async (table, key, within = guards) => one(table, key, await lockedRead(table, keyFilter(table, key), within));
229
+ /* Every reference a write makes must land on a row the principal reads:
230
+ all of a new row's, and of an updated row only those whose columns the
231
+ update sets. A reference the update leaves as it was is not this write's
232
+ to vouch for — it was made before, and refusing over it refused every
233
+ edit of a row whose unrelated parent (a lender's relationship manager on
234
+ a dealer) lies outside the scope, while telling the caller that it does.
235
+
236
+ Each reference is checked by its parent's lock, then that parent's count
237
+ under the principal's rows; a reference that cannot be checked ends the
238
+ list, refused there, so the checks before it still speak first.
239
+
240
+ The references a write names are checked before it is sent, not only
241
+ after: the database's own foreign key answers a parent that does not
242
+ exist with its error, at the statement, while a parent that exists and
243
+ is hidden passed the statement and was refused after it. The two
244
+ answers told a hidden row from a missing one. Checked first, both are
245
+ the one refusal below. `given` keeps to the references whose every
246
+ column the write names; the rest (a default, a value a trigger sets)
247
+ are checked after the statement as before.
248
+
249
+ A reference is checked as the database's foreign key compares it
250
+ (ScopeCatalog.references), with the value the write sends: a check that
251
+ compared otherwise found one parent where the foreign key found
252
+ another, a hidden one (a char(3) value against a text key on
253
+ PostgreSQL, whose foreign key drops its padding; a REAL column's 7.0
254
+ against a TEXT key on SQLite). A value the write sends as NULL ("" for
255
+ a number) points at nothing. And a row that names itself as its own
256
+ parent by the key it gives (`{id: 1, parent_id: 1}`) is that parent:
257
+ it exists once the statement has run, and is checked after it. */
258
+ const comparisonOf = (fk) => {
259
+ const said = catalog.references?.get(referenceKey(fk));
260
+ if (said)
261
+ return said;
262
+ if (catalog.references)
263
+ return {
264
+ refused: `"${fk.from.table}".${fk.from.columns.join('+')} has a foreign key whose comparison was not read with the catalog.`,
265
+ };
266
+ const child = catalog.schema.tables.find((table) => table.id === fk.from.table);
267
+ return { columns: fk.from.columns.map((name) => ({ type: child?.columns.find((column) => column.name === name)?.type ?? '' })) };
268
+ };
269
+ /* A reference with a generated column (the catalog marks one unwritable: PostgreSQL's attgenerated, SQLite's
270
+ table_xinfo hidden 2 or 3) moves with whatever column its expression reads, which no update names: an update of
271
+ `x` re-pointed `k GENERATED ALWAYS AS (x + 1) REFERENCES p` at a hidden parent, checked by nobody. So every update
272
+ touches it, and it is checked after the statement, from the row as stored; before the statement its value is not
273
+ known (what the row held is not what the update leaves), so a check of what a write gives leaves it out. */
274
+ const generated = (table, name) => table.columns.find((column) => column.name === name)?.writable === false;
275
+ const generatedIn = (table, fk) => fk.from.columns.some((name) => generated(table, name));
276
+ const parentChecks = (table, row, set, given = false) => {
277
+ const checks = [];
278
+ for (const fk of catalog.schema.foreignKeys.filter((fk) => fk.from.table === table.id &&
279
+ (!set || fk.from.columns.some((column) => set.has(column)) || (!given && generatedIn(table, fk))) &&
280
+ (!given || (!generatedIn(table, fk) && fk.from.columns.every((column) => Object.hasOwn(row, column) && row[column] !== undefined))))) {
281
+ const compared = comparisonOf(fk);
282
+ // A value the row holds as stored is bound as the text it was read as (storedText.ts); one given, as given.
283
+ const texts = storedText(row);
284
+ const values = fk.from.columns.map((column, index) => {
285
+ const compares = 'columns' in compared ? compared.columns[index] : undefined;
286
+ if (compares?.equality && texts && Object.hasOwn(texts, column) && Object.hasOwn(row, column))
287
+ return texts[column];
288
+ const value = asWritten(compares?.type, row[column]);
289
+ return compares?.equality ? asBound(value) : value;
290
+ });
291
+ if (values.some((value) => value === null))
292
+ continue;
293
+ if ('refused' in compared) {
294
+ checks.push({ refused: compared.refused });
295
+ break;
296
+ }
297
+ const unsupported = values.findIndex((value) => !comparable(value));
298
+ if (unsupported !== -1) {
299
+ checks.push({
300
+ refused: `"${table.id}".${fk.from.columns[unsupported]} holds a value of a type a scoped write does not support for a reference: a check could not bind it as the foreign key compares it.`,
301
+ });
302
+ break;
303
+ }
304
+ if (given &&
305
+ fk.to.table === table.id &&
306
+ fk.to.columns.every((column, index) => Object.hasOwn(row, column) &&
307
+ asWritten(table.columns.find((candidate) => candidate.name === column)?.type, row[column]) === values[index]))
308
+ continue;
309
+ // Parent columns stay on the SQL left-hand side so SQLite's parent
310
+ // affinity and collation, rather than JavaScript equality, decide.
311
+ const filter = {
312
+ groups: [
313
+ fk.to.columns.map((column, index) => {
314
+ const equality = compared.columns[index]?.equality;
315
+ return { column, op: '=', value: values[index], ...(equality ? { equality } : {}) };
316
+ }),
317
+ ],
318
+ };
319
+ const parent = catalog.schema.tables.find((table) => table.id === fk.to.table);
320
+ if (!parent) {
321
+ checks.push({
322
+ refused: `"${table.id}" references "${fk.to.table}", which is not in this write's footprint: declare it read by the command.`,
323
+ });
324
+ break;
325
+ }
326
+ checks.push({ fk, values, filter, parent });
327
+ }
328
+ return checks;
329
+ };
330
+ /** Whether a check binds every value as text read by its column's type (Condition.equality): PostgreSQL's. */
331
+ const bindsText = (check) => check.filter.groups[0].every((condition) => condition.equality);
332
+ const unseen = (check) => `"${check.fk.from.table}".${check.fk.from.columns.join('+')} points at the "${check.fk.to.table}" row ${keyText(Object.fromEntries(check.fk.to.columns.map((column, index) => [column, check.values[index]])))}, which the principal's rows do not include (or the command does not declare "${check.fk.to.table}" read).`;
333
+ /** The checks sent at once (locks.together): each parent's lock, then its count, every answer heard. */
334
+ const ask = (checks) => checks.map((check) => {
335
+ if ('refused' in check)
336
+ return check;
337
+ const locked = locks?.parent(check.parent, check.filter) ?? Promise.resolve();
338
+ const counted = guards.count(check.fk.to.table, check.filter);
339
+ locked.catch(() => { });
340
+ counted.catch(() => { });
341
+ return { ...check, locked, counted };
342
+ });
343
+ /* Checks asked ahead of the row they are for (built from what the write
344
+ returned, or from what an update sets), used only where they name exactly
345
+ the references the row as stored holds: the same statements, sent sooner. */
346
+ const sameChecks = (asked, checks) => asked.length === checks.length &&
347
+ asked.every((guess, index) => {
348
+ const check = checks[index];
349
+ if ('refused' in guess || 'refused' in check)
350
+ return 'refused' in guess && 'refused' in check && guess.refused === check.refused;
351
+ return guess.fk === check.fk && guess.values.every((value, at) => sameBound(value, check.values[at], bindsText(check)));
352
+ });
353
+ /* References this transaction has proven: each parent locked and counted inside the principal's rows, which holds
354
+ until COMMIT (the lock), so the same reference is not asked again after the write that made it. */
355
+ const proven = [];
356
+ const unproven = (checks) => checks.filter((check) => 'refused' in check ||
357
+ !proven.some((done) => done.fk === check.fk && done.values.every((value, at) => sameBound(value, check.values[at], bindsText(check)))));
358
+ const verify = async (checks, guessed) => {
359
+ if (!locks?.together) {
360
+ for (const check of checks) {
361
+ if ('refused' in check)
362
+ return refuse(check.refused);
363
+ // A parent's visibility must hold until commit, not just at this read.
364
+ await locks?.parent(check.parent, check.filter);
365
+ if ((await guards.count(check.fk.to.table, check.filter)) !== 1)
366
+ return refuse(unseen(check));
367
+ proven.push(check);
368
+ }
369
+ return;
370
+ }
371
+ const asked = guessed && sameChecks(guessed, checks) ? guessed : ask(checks);
372
+ // Every answer is heard before any is judged: nothing is left in flight behind a refusal.
373
+ await Promise.allSettled(asked.flatMap((check) => ('refused' in check ? [] : [check.locked, check.counted])));
374
+ for (const check of asked) {
375
+ if ('refused' in check)
376
+ return refuse(check.refused);
377
+ await check.locked;
378
+ if ((await check.counted) !== 1)
379
+ return refuse(unseen(check));
380
+ proven.push(check);
381
+ }
382
+ };
383
+ const parents = async (table, row, set, guessed, given = false) => verify(unproven(parentChecks(table, row, set, given)), guessed);
384
+ /**
385
+ * Before a write: the references it names, checked as `parents` checks them. Where the writer sends together, the
386
+ * checks leave ahead of the write, in its flight, and `write` is sent behind them before any is judged: the server
387
+ * runs them first, and a refused one is said whatever the write then answered (a foreign key's error included).
388
+ */
389
+ const parentsFirst = async (checks, write) => {
390
+ if (!locks?.together) {
391
+ await verify(checks);
392
+ return write();
393
+ }
394
+ const asked = ask(checks);
395
+ const sent = write();
396
+ await Promise.allSettled([sent, ...asked.flatMap((check) => ('refused' in check ? [] : [check.locked, check.counted]))]);
397
+ await verify(checks, asked);
398
+ return sent;
399
+ };
400
+ /* Triggers the App names: each write that fires one proves its effects' keys first and the rest right after the
401
+ statement, with the transaction's own locks and guards (triggerProof.ts). */
402
+ const proof = triggers
403
+ ? triggers.prove(triggers.acceptance, {
404
+ tables: catalog.schema.tables,
405
+ foreignKeys: catalog.schema.foreignKeys,
406
+ triggered: catalog.triggered,
407
+ foldCase: catalog.schema.dialect === 'sqlite',
408
+ scope: triggers.scope,
409
+ guards: () => guards,
410
+ lockedRead,
411
+ read: (table, filter) => readStored(table, filter, guards),
412
+ parents: (table, row, set) => parents(table, row, set),
413
+ parentsBefore: (table, row, set) => parents(table, row, set, undefined, true),
414
+ ...(locks ? { holdParent: (table, filter) => locks.parent(table, filter) } : {}),
415
+ ...(locks?.relied ? { relied: (table) => locks.relied(table) } : {}),
416
+ ...(triggers.watch ? { watch: triggers.watch } : {}),
417
+ refuse,
418
+ })
419
+ : undefined;
420
+ /* The statements themselves. A foreign key that refuses one answers as a hidden parent does (foreignKeyRefusal):
421
+ the checks before a write compare what it names, and this is everything they cannot see — a default's part of a
422
+ reference, a value a trigger writes, a deferred check. */
423
+ const statement = (sent) => sent.catch((error) => {
424
+ throw isForeignKeyViolation(error) ? foreignKeyRefusal(error) : error;
425
+ });
426
+ const insertRow = (request) => statement(records.insert(request));
427
+ const updateRow = (request) => statement(records.update(request));
428
+ const afterward = async (afterwards, images) => {
429
+ for (const next of afterwards ?? [])
430
+ await next(images);
431
+ };
432
+ return Object.freeze({
433
+ query: (request) => reads.query(request),
434
+ count: (table, filter) => reads.count(table, filter),
435
+ /* Under the principal's rows, as `count` reads: never the writer's own unscoped aggregate. */
436
+ ...(reads.aggregate
437
+ ? {
438
+ aggregate: (request) => reads.aggregate ? reads.aggregate(request) : refuse('This scope cannot aggregate.'),
439
+ }
440
+ : {}),
441
+ async insert(request) {
442
+ const table = target(request.table, { kind: 'insert' });
443
+ const afterwards = proof && (await proof.before(table, { kind: 'insert' }, proof.images.insert(table, request.values)));
444
+ const given = unproven(parentChecks(table, request.values ?? {}, undefined, true));
445
+ if (!locks?.together)
446
+ await verify(given);
447
+ const result = locks?.together ? await parentsFirst(given, () => insertRow(request)) : await insertRow(request);
448
+ const filter = keyFilter(table, result.key);
449
+ /* The new row locked and read back, and where the writer sends together
450
+ its references checked in the same flight, from the row the INSERT
451
+ returned (parents uses them only where the stored row holds exactly
452
+ those). No other transaction can see this row yet, so its lock is
453
+ granted at once and the read answers what a count before it would. */
454
+ const read = lockedRead(table, filter, guards);
455
+ const guessed = locks?.together && result.row ? ask(unproven(parentChecks(table, result.row))) : undefined;
456
+ read.catch(() => { });
457
+ const found = await read;
458
+ // Inside the bound and outside the principal's rows: the command's own row, answered by its key and what it wrote.
459
+ if (bound && found.rows.length !== 1) {
460
+ const within = await stored(table, result.key, bound.reads);
461
+ await parents(table, within, undefined, guessed);
462
+ await afterward(afterwards, { new: within, old: null });
463
+ return { key: result.key, applied: result.applied, sql: result.sql };
464
+ }
465
+ const row = one(table, result.key, found);
466
+ await parents(table, row, undefined, guessed);
467
+ await afterward(afterwards, { new: row, old: null });
468
+ madeBy(table, row);
469
+ return result;
470
+ },
471
+ async update(request) {
472
+ const table = target(request.table, { kind: 'update', set: Object.keys(request.values ?? {}) });
473
+ const protectedColumns = new Set([
474
+ ...table.columns.filter((column) => column.primaryKey).map((column) => column.name),
475
+ ...catalog.schema.foreignKeys.filter((fk) => fk.to.table === table.id).flatMap((fk) => fk.to.columns),
476
+ ]);
477
+ const moved = Object.keys(request.values ?? {}).filter((column) => protectedColumns.has(column));
478
+ if (moved.length)
479
+ return refuse(`A scoped update may not change "${table.id}".${moved.join(', ')}: a key, or a column another table references.`);
480
+ const before = await stored(table, request.key);
481
+ const set = new Set(Object.keys(request.values ?? {}));
482
+ const afterwards = proof && (await proof.before(table, { kind: 'update', set: [...set] }, proof.images.update(table, before, request.values)));
483
+ // What the update sets is given; every other column of a reference it sets in part is as stored, bound as its text.
484
+ const given = unproven(parentChecks(table, overlaid(before, request.values), set, true));
485
+ if (!locks?.together)
486
+ await verify(given);
487
+ /* The row read again after the write, sent the moment the write is: it
488
+ reads what the write wrote, and leaves in the write's round trip, with
489
+ the references the write sets checked ahead of it, as the row will
490
+ hold them. A reference refused is the answer whatever the write said;
491
+ otherwise a write that fails aborts the read too, and the write's
492
+ failure is the one thrown. */
493
+ const after = {};
494
+ const withdraw = locks?.behind?.(table, () => {
495
+ after.row = stored(table, request.key);
496
+ after.row.catch(() => { });
497
+ });
498
+ let result;
499
+ try {
500
+ // The references it sets leave ahead of it, in its flight (parentsFirst).
501
+ result = locks?.together ? await parentsFirst(given, () => updateRow(request)) : await updateRow(request);
502
+ }
503
+ finally {
504
+ withdraw?.();
505
+ }
506
+ if (result.affected !== 1)
507
+ return refuse(`The update of "${table.id}" changed ${result.affected} rows, not one.`);
508
+ const now = await (after.row ?? stored(table, request.key));
509
+ /* A key or a referenced column the database generates moves with the columns its expression reads, which the
510
+ names above cannot catch: one that moved is refused, whatever a cascade or the foreign key made of it. */
511
+ const shifted = [...protectedColumns].filter((column) => generated(table, column) && JSON.stringify(before[column]) !== JSON.stringify(now[column]));
512
+ if (shifted.length)
513
+ return refuse(`A scoped update may not change "${table.id}".${shifted.join(', ')}: a key, or a column another table references, generated from the columns it sets.`);
514
+ await parents(table, now, set);
515
+ await afterward(afterwards, { new: now, old: before });
516
+ return result;
517
+ },
518
+ async remove(request) {
519
+ const table = target(request.table, { kind: 'delete' });
520
+ const children = catalog.schema.foreignKeys.filter((fk) => fk.to.table === table.id);
521
+ const hidden = children.find((fk) => !bound?.whole.has(fk.from.table));
522
+ if (hidden)
523
+ return refuse(`A scoped command may not delete from "${table.id}": "${hidden.from.table}" references it, and a hidden row might.`);
524
+ const row = await stored(table, request.key);
525
+ /* Locked first (stored), so no reference can be made to it while these
526
+ are counted: across every row of each table, on the writer itself,
527
+ since the principal sees every row the bound holds there and a row
528
+ outside the bound pointing in is the one a cascade must never reach. */
529
+ for (const fk of children) {
530
+ const values = fk.to.columns.map((column) => row[column]);
531
+ if (values.some((value) => value === null))
532
+ continue;
533
+ if (!values.every(comparable))
534
+ return refuse(`"${table.id}".${fk.to.columns.join('+')} holds a value that is not a text or a number.`);
535
+ const key = { groups: [Object.entries(request.key).map(([column, value]) => ({ column, op: '=', value }))] };
536
+ if ((await bound?.references(fk, key)) !== 0)
537
+ return refuse(`A scoped command may not delete the "${table.id}" row ${keyText(request.key)}: "${fk.from.table}" still references it.`);
538
+ }
539
+ const afterwards = proof && (await proof.before(table, { kind: 'delete' }, proof.images.delete(row)));
540
+ const result = await statement(records.remove(request));
541
+ if (result.affected !== 1)
542
+ return refuse(`The delete from "${table.id}" removed ${result.affected} rows, not one.`);
543
+ await afterward(afterwards, { new: null, old: row });
544
+ return result;
545
+ },
546
+ });
547
+ }
@@ -0,0 +1,32 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import { type DatabaseSchema } from '../../shared/schema.js';
3
+ import { type ScopeCatalog } from './scopedTransaction.js';
4
+ import type { EffectCatalog, resolveTriggerEffects } from './triggerEffects.js';
5
+ export type SqliteScopeCatalog = ScopeCatalog;
6
+ /** Call only on the writer inside BEGIN IMMEDIATE. No cached/public catalog,
7
+ * estimates or data scans: the lease's physical metadata is the authority.
8
+ * A non-writable table remains in the graph so hidden dependents cannot vanish.
9
+ */
10
+ export declare function readSqliteScopeCatalog(db: DatabaseSync, resolve?: typeof resolveTriggerEffects): SqliteScopeCatalog;
11
+ /**
12
+ * How a key equality in a trigger compares on SQLite (triggerEffects.ts): each column's affinity, which decides what
13
+ * a value is converted to before it is compared, and its collation, which `NEW.code = code` takes from the column on
14
+ * its left; and the primary key as a key only where its index compares each column under that column's own
15
+ * collation (`PRIMARY KEY (code COLLATE NOCASE)` on a BINARY column is unique under one and found under the other).
16
+ * And the conflict clause a table declares other than ABORT, which a trigger's write runs under when the statement
17
+ * that fired it is a delete (triggerEffects.ts). Read where effects are judged, inside the writer's BEGIN IMMEDIATE.
18
+ */
19
+ export declare function sqliteKeyFacts(db: DatabaseSync): Pick<EffectCatalog, 'keys' | 'comparison' | 'conflicts'>;
20
+ /**
21
+ * For `mistri check`: the tables a scoped write cannot target for what they are rather than their triggers — a
22
+ * virtual table and its shadow tables, whose module writes them (scanSqliteScopeCatalog keeps them out of
23
+ * `writable`) — read on the reader, so check refuses an effect on one as the write does.
24
+ */
25
+ export declare function sqliteBlockedTables(db: DatabaseSync): ReadonlyMap<string, string>;
26
+ /** Metadata-only read attestation inside the caller's owned snapshot. Exposes
27
+ * no writer eligibility. Keep every non-engine table and dependency, including
28
+ * private/unmapped objects, so an unknown business edge cannot disappear. */
29
+ export declare function readSqliteReadCatalog(db: DatabaseSync): {
30
+ schema: DatabaseSchema;
31
+ readable: ReadonlySet<string>;
32
+ };