@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,282 @@
1
+ /**
2
+ * A view, written down.
3
+ *
4
+ * The composer builds views by clicking, and a view built by clicking is UI
5
+ * state: it can be saved and loaded, and that is all. Everything else in
6
+ * tablewalk holds that the *query text* is the single source of truth — it is
7
+ * why filters compose into the bar, why sorting edits the query, why a link
8
+ * carries the whole walk. A view that cannot be written down cannot be
9
+ * hand-edited, diffed in a config file, pasted into a conversation, or
10
+ * explained to someone who does not have the UI open.
11
+ *
12
+ * So a view has a text form, and it is the same language:
13
+ *
14
+ * work_order
15
+ * show reference, total_cost, customer_id.name as customer
16
+ * count work_order_part via work_order_id as parts
17
+ * sum work_order_part.quantity via work_order_id as units
18
+ * where customer_id.country_code = AU and total_cost > 500
19
+ * sort total_cost desc
20
+ * limit 20
21
+ *
22
+ * Only two things here are new: the base table on the front, and the
23
+ * aggregate clauses. Paths, conditions, sort and limit are parsed by
24
+ * `parseViewQuery`, which the composer's filter box already uses — one
25
+ * grammar, not two that drift.
26
+ *
27
+ * Aggregates name the child table and the foreign key column rather than the
28
+ * constraint, because a constraint name is a database artefact nobody reads
29
+ * (`work_order_part_work_order_id_fkey`) and `work_order_part via
30
+ * work_order_id` says the same thing in words that appear in the schema. The
31
+ * pair is unambiguous: two foreign keys from one child to one parent must sit
32
+ * on different columns.
33
+ */
34
+ import { backrefsTo, parseViewQuery, tableAtPrefix } from './view.js';
35
+ import { findTable } from './schema.js';
36
+ const AGGREGATE_FNS = ['count', 'sum', 'min', 'max', 'avg'];
37
+ function viewToText(view, nameConstraint) {
38
+ const lines = [view.base];
39
+ if (view.columns.length) {
40
+ const shown = view.columns.map((c) => (c.alias && c.alias !== c.path ? `${c.path} as ${c.alias}` : c.path));
41
+ lines.push(` show ${shown.join(', ')}`);
42
+ }
43
+ for (const aggregate of view.aggregates ?? []) {
44
+ lines.push(` ${aggregateToText(aggregate, nameConstraint)}`);
45
+ }
46
+ const where = filterToText(view);
47
+ if (where)
48
+ lines.push(` where ${where}`);
49
+ /* A closest-first order (`near`, a similar list's) has no words in the
50
+ grammar; the text keeps the orders it can say, over the same rows. */
51
+ const said = (view.orderBy ?? []).filter((o) => o.near === undefined);
52
+ if (said.length) {
53
+ const parts = said.map((o) => (o.direction === 'desc' ? `${o.path} desc` : o.path));
54
+ lines.push(` sort ${parts.join(', ')}`);
55
+ }
56
+ if (view.limit !== undefined)
57
+ lines.push(` limit ${view.limit}`);
58
+ return lines.join('\n');
59
+ }
60
+ function aggregateToText(aggregate, nameConstraint) {
61
+ /* `via` on the model is a constraint name; the text form names the child
62
+ table and its foreign key column instead. The name is recoverable from
63
+ the pair, and the pair is what a person can read.
64
+
65
+ With no way to resolve it, the constraint name is emitted as-is rather
66
+ than a table and column being invented — wrong-but-readable is worse
67
+ than opaque-but-true. */
68
+ const [table, column] = nameConstraint?.(aggregate.via) ?? [aggregate.via, ''];
69
+ const target = aggregate.fn === 'count' || !aggregate.column ? table : `${table}.${aggregate.column}`;
70
+ const on = aggregate.on ? ` on ${aggregate.on}` : '';
71
+ const alias = aggregate.alias ? ` as ${aggregate.alias}` : '';
72
+ return `${aggregate.fn} ${target} via ${column}${on}${alias}`;
73
+ }
74
+ /** A namer backed by a schema: the form callers with a connection should use. */
75
+ function constraintNamer(schema, view) {
76
+ return (via) => {
77
+ /* An aggregate can hang off a path, not just the base, so every prefix
78
+ the view mentions is a candidate parent. */
79
+ const prefixes = new Set(['', ...(view.aggregates ?? []).map((a) => a.on ?? '')]);
80
+ for (const prefix of prefixes) {
81
+ const parent = tableAtPrefix(schema, view.base, prefix);
82
+ if (!parent)
83
+ continue;
84
+ const candidates = backrefsTo(schema, parent.id);
85
+ const hit = candidates.find((b) => `${b.child}.${b.fk.from.columns.join('+')}` === via) ?? candidates.find((b) => b.fk.name === via);
86
+ if (hit)
87
+ return [hit.fk.from.table, hit.fk.from.columns[0]];
88
+ }
89
+ return undefined;
90
+ };
91
+ }
92
+ /** Render with a schema, so aggregates name real tables and columns. */
93
+ export function viewToTextWithSchema(schema, view) {
94
+ return viewToText(view, constraintNamer(schema, view));
95
+ }
96
+ function filterToText(view) {
97
+ const groups = view.filter?.groups ?? [];
98
+ if (!groups.length)
99
+ return '';
100
+ const rendered = groups.map((group) => group.map(conditionToText).join(' and '));
101
+ // A single group needs no parentheses; several are OR-ed and each is
102
+ // bracketed, matching how the parser reads them back.
103
+ return rendered.length === 1 ? rendered[0] : rendered.map((g) => `(${g})`).join(' or ');
104
+ }
105
+ function conditionToText(condition) {
106
+ const { path, op, value } = condition;
107
+ // An `any`/`no` condition keeps the words it was written in (view.ts).
108
+ if (condition.any !== undefined)
109
+ return path;
110
+ // Another column is written bare: that is how the parser tells it from a value.
111
+ if (condition.other !== undefined)
112
+ return `${path} ${op} ${condition.other}`;
113
+ switch (op) {
114
+ case 'isNull':
115
+ return `${path} is empty`;
116
+ case 'isNotNull':
117
+ return `${path} is not empty`;
118
+ case 'contains':
119
+ return `${path} contains ${quote(value)}`;
120
+ case 'startsWith':
121
+ return `${path} startswith ${quote(value)}`;
122
+ case 'endsWith':
123
+ return `${path} endswith ${quote(value)}`;
124
+ case 'in': {
125
+ const list = Array.isArray(value) ? value : [value];
126
+ return `${path} in (${list.map(quote).join(', ')})`;
127
+ }
128
+ default:
129
+ return `${path} ${op} ${quote(value)}`;
130
+ }
131
+ }
132
+ /** Quote only when the grammar needs it, so the common case stays readable. */
133
+ function quote(value) {
134
+ if (value === null || value === undefined)
135
+ return '""';
136
+ const text = String(value);
137
+ if (typeof value === 'number' || typeof value === 'boolean')
138
+ return text;
139
+ return /^[\w.-]+$/.test(text) ? text : `"${text.replace(/"/g, '')}"`;
140
+ }
141
+ /* ---------- reading ---------- */
142
+ /**
143
+ * An aggregate clause: `count work_order_part via work_order_id as parts`.
144
+ *
145
+ * The function word is only treated as a clause when it is followed by
146
+ * something-then-`via`. A table with a column called `count` or `sum` is not
147
+ * unusual, and eating the word would turn `sum = 3` into a broken aggregate
148
+ * rather than a filter.
149
+ */
150
+ const AGGREGATE_RE = new RegExp(String.raw `\b(${AGGREGATE_FNS.join('|')})\s+([\w.$]+)\s+via\s+([\w$]+)` + String.raw `(?:\s+on\s+([\w.$]+))?(?:\s+as\s+([\w$]+))?`, 'gi');
151
+ /**
152
+ * Parse a written view.
153
+ *
154
+ * The base table and the aggregates are handled here; everything else is
155
+ * handed to `parseViewQuery`, which the composer's filter box already uses.
156
+ * Two parsers for one language is how a language starts disagreeing with
157
+ * itself.
158
+ */
159
+ export function textToView(schema, text, options = {}) {
160
+ const errors = [];
161
+ const body = String(text ?? '').trim();
162
+ if (!body)
163
+ return { errors: [{ message: 'Start with a table name.' }] };
164
+ const baseName = body.split(/\s+/)[0];
165
+ const base = findTable(schema, baseName) ?? schema.tables.find((t) => t.name === baseName);
166
+ if (!base) {
167
+ return { errors: [{ message: `No table called "${baseName}" in this database.`, at: 0 }] };
168
+ }
169
+ const rest = body.slice(baseName.length);
170
+ /* Aggregates are lifted out before the rest is parsed, because
171
+ `parseViewQuery` knows nothing about them and would read `count` as the
172
+ start of a condition. */
173
+ const aggregates = [];
174
+ const remainder = rest.replace(AGGREGATE_RE, (_match, fn, target, viaColumn, on, alias) => {
175
+ /* `app.invoice_line` is one qualified table; `work_order_part.quantity`
176
+ is a table and a column; `app.invoice_line.quantity` is both. A dot
177
+ cannot tell them apart, so the schema does: if the whole target names a
178
+ table there is no column, otherwise the last dot separates them.
179
+
180
+ Splitting on the first dot — the obvious implementation — turned
181
+ `app.invoice_line` into table `app`, and the error it produced named a
182
+ table that does not exist. Postgres schemas are the common case for
183
+ this, which is exactly why it survived until the compiler was pointed
184
+ at a real one. */
185
+ const targetText = String(target);
186
+ const namesTable = (id) => Boolean(findTable(schema, id)) || schema.tables.some((t) => t.name === id);
187
+ let childTable = targetText;
188
+ let childColumn;
189
+ if (!namesTable(targetText)) {
190
+ const lastDot = targetText.lastIndexOf('.');
191
+ if (lastDot > 0) {
192
+ childTable = targetText.slice(0, lastDot);
193
+ childColumn = targetText.slice(lastDot + 1);
194
+ }
195
+ }
196
+ const parent = tableAtPrefix(schema, base.id, on ?? '');
197
+ if (!parent) {
198
+ errors.push({ message: `"${on}" is not a reference path on ${base.name}.` });
199
+ return '';
200
+ }
201
+ const backref = backrefsTo(schema, parent.id).find((b) => b.fk.from.table === childTable && b.fk.from.columns.includes(String(viaColumn)));
202
+ if (!backref) {
203
+ errors.push({
204
+ message: `Nothing in ${childTable}.${viaColumn} points at ${parent.name}. ` + `Try: ${describeBackrefs(schema, parent.id)}`,
205
+ });
206
+ return '';
207
+ }
208
+ if (fn !== 'count' && !childColumn) {
209
+ errors.push({ message: `${fn} needs a column, e.g. ${fn} ${childTable}.amount via ${viaColumn}` });
210
+ return '';
211
+ }
212
+ if (childColumn) {
213
+ const childTableMeta = findTable(schema, backref.fk.from.table);
214
+ if (childTableMeta && !childTableMeta.columns.some((c) => c.name === childColumn)) {
215
+ errors.push({ message: `"${childColumn}" is not a column on ${childTable}.` });
216
+ return '';
217
+ }
218
+ }
219
+ aggregates.push({
220
+ fn: fn.toLowerCase(),
221
+ via: `${backref.child}.${backref.fk.from.columns.join('+')}`,
222
+ on: on || undefined,
223
+ column: childColumn,
224
+ alias: alias || undefined,
225
+ });
226
+ return '';
227
+ });
228
+ /* Aliases are lifted out of the `show` clause before it is parsed.
229
+ `parseViewQuery` validates each entry as a path, and
230
+ `customer_id.name as customer` is not one — the alias is presentation,
231
+ not addressing, and only this layer knows about it. */
232
+ const { text: withoutAliases, aliases } = stripAliases(remainder);
233
+ const parsed = parseViewQuery(schema, base.id, withoutAliases, options.now, {
234
+ /* So `sort invoices desc` parses after `… as invoices` — the alias joins
235
+ the synthetic table for the sort clause, and only the sort clause. */
236
+ aggregateAliases: aggregates.map((a) => a.alias ?? '').filter(Boolean),
237
+ ...(options.me !== undefined ? { me: options.me } : {}),
238
+ });
239
+ errors.push(...parsed.errors);
240
+ const view = {
241
+ id: options.id ?? 'text',
242
+ name: options.name ?? '',
243
+ base: base.id,
244
+ columns: parsed.columns.map((path) => {
245
+ const alias = aliases.get(path);
246
+ return alias ? { path, alias } : { path };
247
+ }),
248
+ aggregates: aggregates.length ? aggregates : undefined,
249
+ filter: parsed.filter.groups.length ? parsed.filter : undefined,
250
+ orderBy: parsed.orderBy.length ? parsed.orderBy : undefined,
251
+ limit: parsed.limit,
252
+ };
253
+ return { view, errors };
254
+ }
255
+ /**
256
+ * Remove ` as <alias>` from every entry of a `show` clause, returning the
257
+ * cleaned text and a path → alias map.
258
+ *
259
+ * Only the show clause: `as` means something else nowhere in this grammar
260
+ * today, but rewriting the whole string would break the moment it does.
261
+ */
262
+ function stripAliases(text) {
263
+ const aliases = new Map();
264
+ const cleaned = text.replace(/\b(show|select)\s+([^]*?)(?=\s+\b(?:where|filter|sort|order\s+by|limit)\b|$)/i, (_match, keyword, list) => {
265
+ const entries = list.split(',').map((entry) => {
266
+ const aliased = entry.trim().match(/^(.*?)\s+as\s+([\w$]+)$/i);
267
+ if (!aliased)
268
+ return entry.trim();
269
+ aliases.set(aliased[1].trim(), aliased[2]);
270
+ return aliased[1].trim();
271
+ });
272
+ return `${keyword} ${entries.join(', ')}`;
273
+ });
274
+ return { text: cleaned, aliases };
275
+ }
276
+ /** A short list of what *would* have worked, for the error to name. */
277
+ function describeBackrefs(schema, parentId) {
278
+ const options = backrefsTo(schema, parentId)
279
+ .slice(0, 3)
280
+ .map((b) => `${b.fk.from.table} via ${b.fk.from.columns[0]}`);
281
+ return options.length ? options.join(', ') : 'nothing points at this table';
282
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The values a column is allowed to hold, when the database says so.
3
+ *
4
+ * A column called `status` typed `text` tells you nothing. A `CHECK (status
5
+ * IN ('draft','open','paid'))` tells you everything — the states the system
6
+ * has, which is often the single most useful fact about a table and the one
7
+ * an agent is most likely to guess wrong. Guessing produces `status =
8
+ * 'OPEN'`, which returns no rows and looks like an empty table rather than a
9
+ * spelling mistake.
10
+ *
11
+ * Every dialect writes the same constraint differently, so the parsing lives
12
+ * here and the adapters bring their own constraint text. This is deliberately
13
+ * a *recogniser*, not a SQL expression parser: it understands the handful of
14
+ * shapes that mean "one of these" and returns nothing for anything else. A
15
+ * partial understanding of `CHECK (total > 0 AND status IN (...))` would be
16
+ * worse than none, because the vocabulary it reported would be presented as
17
+ * the whole rule.
18
+ */
19
+ /**
20
+ * The vocabulary a single CHECK expression pins for one column.
21
+ *
22
+ * Handles the two shapes that mean the same thing:
23
+ * `status IN ('a','b')` — every dialect
24
+ * `((status)::text = ANY ((ARRAY['a'::text, 'b'::text])))` — what Postgres
25
+ * stores instead
26
+ */
27
+ export declare function checkVocabulary(expression: string, column: string): string[] | undefined;
28
+ /**
29
+ * Whether a single CHECK expression pins a column to 0 and 1 — the flag a
30
+ * dialect without a boolean type spells as an integer. The shapes that say
31
+ * exactly that and nothing more:
32
+ * `flag IN (0, 1)`, `flag = 0 OR flag = 1`, `flag BETWEEN 0 AND 1`, and
33
+ * Postgres's stored `(flag = ANY (ARRAY[0, 1]))`
34
+ * (either order, either parenthesising). A check that says more than that
35
+ * (`flag IN (0, 1, 2)`, `flag >= 0`) is no flag.
36
+ */
37
+ export declare function checkFlag(expression: string, column: string): boolean;
38
+ /**
39
+ * What a single CHECK expression says of a text column's length or form, in
40
+ * the two simple shapes a form can check as someone types (textRules.ts):
41
+ * `char_length(name) >= 2` (or `length`, `character_length`, `>`) — the fewest characters;
42
+ * `code ~ '^[A-Z]{3}$'` — a regular expression the value matches somewhere,
43
+ * returned as a whole-value JavaScript pattern, and only where JavaScript reads it.
44
+ * Postgres's stored spelling (`char_length((name)::text) >= 2`) is the same
45
+ * shape once its casts are off. Anything more (an AND, `~*`, a bound above)
46
+ * is no rule: a partial reading would be presented as the whole of it.
47
+ */
48
+ export declare function checkTextRule(expression: string, column: string): {
49
+ min?: number;
50
+ pattern?: string;
51
+ } | undefined;
52
+ /** The columns of a `CREATE TABLE` statement a CHECK pins to 0 and 1 (checkFlag). */
53
+ export declare function flagsFromDDL(ddl: string, columns: string[]): Set<string>;
54
+ /**
55
+ * Every CHECK clause in a `CREATE TABLE` statement, for dialects that keep
56
+ * the statement rather than the constraints — SQLite.
57
+ *
58
+ * Scanned with a depth counter rather than a regex because a check body
59
+ * contains parentheses of its own, and matching to the first `)` truncates
60
+ * `CHECK (status IN ('a','b'))` to `status IN ('a'`.
61
+ */
62
+ export declare function checksIn(ddl: string): string[];
63
+ /**
64
+ * The allowed values for each column of a table, read out of its DDL.
65
+ *
66
+ * Column-level (`status TEXT CHECK (status IN (...))`) and table-level
67
+ * (`CHECK (status IN (...))`) checks are the same text by the time they get
68
+ * here, which is why this asks each check about each column rather than
69
+ * trying to work out which column a check was attached to.
70
+ */
71
+ export declare function vocabularyFromDDL(ddl: string, columns: string[]): Map<string, string[]>;
@@ -0,0 +1,249 @@
1
+ /**
2
+ * The values a column is allowed to hold, when the database says so.
3
+ *
4
+ * A column called `status` typed `text` tells you nothing. A `CHECK (status
5
+ * IN ('draft','open','paid'))` tells you everything — the states the system
6
+ * has, which is often the single most useful fact about a table and the one
7
+ * an agent is most likely to guess wrong. Guessing produces `status =
8
+ * 'OPEN'`, which returns no rows and looks like an empty table rather than a
9
+ * spelling mistake.
10
+ *
11
+ * Every dialect writes the same constraint differently, so the parsing lives
12
+ * here and the adapters bring their own constraint text. This is deliberately
13
+ * a *recogniser*, not a SQL expression parser: it understands the handful of
14
+ * shapes that mean "one of these" and returns nothing for anything else. A
15
+ * partial understanding of `CHECK (total > 0 AND status IN (...))` would be
16
+ * worse than none, because the vocabulary it reported would be presented as
17
+ * the whole rule.
18
+ */
19
+ /** A quoted or bare identifier, as any dialect might write the column. */
20
+ function sameColumn(written, column) {
21
+ const bare = written.trim().replace(/^["`[]|["`\]]$/g, '');
22
+ return bare.toLowerCase() === column.toLowerCase();
23
+ }
24
+ /** `'a'`, `'it''s'`, `'a'::text` — the string literals inside a list. */
25
+ function literals(list) {
26
+ const values = [];
27
+ const pattern = /'((?:[^']|'')*)'(?:::[A-Za-z_" ]+(?:\[\])?)?\s*(,|$)/gy;
28
+ pattern.lastIndex = 0;
29
+ let rest = list.trim();
30
+ let at = 0;
31
+ while (at < rest.length) {
32
+ pattern.lastIndex = at;
33
+ const m = pattern.exec(rest);
34
+ if (!m)
35
+ return undefined;
36
+ values.push(m[1].replace(/''/g, "'"));
37
+ at = pattern.lastIndex;
38
+ while (rest[at] === ' ')
39
+ at += 1;
40
+ }
41
+ return values.length ? values : undefined;
42
+ }
43
+ /**
44
+ * Remove `::type` casts, which Postgres sprays through every stored
45
+ * expression — `(status)::text = ANY ((ARRAY['a'::character varying])::text[])`
46
+ * is `status = ANY (ARRAY['a'])` with six casts in it. Quoted strings are
47
+ * stepped over, so a value that happens to contain `::` survives.
48
+ */
49
+ function stripCasts(text) {
50
+ let out = '';
51
+ let quoted = null;
52
+ for (let i = 0; i < text.length; i += 1) {
53
+ const ch = text[i];
54
+ if (quoted) {
55
+ out += ch;
56
+ if (ch === quoted)
57
+ quoted = null;
58
+ continue;
59
+ }
60
+ if (ch === "'" || ch === '"') {
61
+ quoted = ch;
62
+ out += ch;
63
+ continue;
64
+ }
65
+ if (ch === ':' && text[i + 1] === ':') {
66
+ i += 2;
67
+ while (i < text.length && /[A-Za-z0-9_ "]/.test(text[i]))
68
+ i += 1;
69
+ if (text[i] === '[' && text[i + 1] === ']')
70
+ i += 1;
71
+ else
72
+ i -= 1;
73
+ continue;
74
+ }
75
+ out += ch;
76
+ }
77
+ return out;
78
+ }
79
+ /**
80
+ * The vocabulary a single CHECK expression pins for one column.
81
+ *
82
+ * Handles the two shapes that mean the same thing:
83
+ * `status IN ('a','b')` — every dialect
84
+ * `((status)::text = ANY ((ARRAY['a'::text, 'b'::text])))` — what Postgres
85
+ * stores instead
86
+ */
87
+ export function checkVocabulary(expression, column) {
88
+ const text = stripCasts(expression).trim();
89
+ /* Postgres rewrites `IN` to `= ANY (ARRAY[...])` before storing it, so the
90
+ constraint you wrote is never the constraint you read back. */
91
+ const any = /^[(\s]*([^\s()]+)[)\s]*=\s*ANY\s*[(\s]*ARRAY\s*\[(.*)\][\s)]*$/is.exec(text);
92
+ if (any && sameColumn(any[1], column))
93
+ return literals(any[2]);
94
+ const list = /^[(\s]*([^\s()]+)\s+IN\s*\((.*)\)[\s)]*$/is.exec(text);
95
+ if (list && sameColumn(list[1], column))
96
+ return literals(list[2]);
97
+ return undefined;
98
+ }
99
+ /**
100
+ * Whether a single CHECK expression pins a column to 0 and 1 — the flag a
101
+ * dialect without a boolean type spells as an integer. The shapes that say
102
+ * exactly that and nothing more:
103
+ * `flag IN (0, 1)`, `flag = 0 OR flag = 1`, `flag BETWEEN 0 AND 1`, and
104
+ * Postgres's stored `(flag = ANY (ARRAY[0, 1]))`
105
+ * (either order, either parenthesising). A check that says more than that
106
+ * (`flag IN (0, 1, 2)`, `flag >= 0`) is no flag.
107
+ */
108
+ export function checkFlag(expression, column) {
109
+ const text = unwrap(stripCasts(expression));
110
+ const bits = (list) => {
111
+ const values = list.split(',').map((value) => value
112
+ .trim()
113
+ .replace(/^\(|\)$/g, '')
114
+ .trim());
115
+ return values.length === 2 && new Set(values).size === 2 && values.every((value) => value === '0' || value === '1');
116
+ };
117
+ const list = /^\(?\s*([^\s()]+)\s*\)?\s+IN\s*\(([^()]*)\)$/is.exec(text);
118
+ if (list)
119
+ return sameColumn(list[1], column) && bits(list[2]);
120
+ /* What Postgres stores for the IN list. */
121
+ const any = /^\(?\s*([^\s()]+)\s*\)?\s*=\s*ANY\s*\(\s*ARRAY\s*\[([^\]]*)\]\s*\)$/is.exec(text);
122
+ if (any)
123
+ return sameColumn(any[1], column) && bits(any[2]);
124
+ const between = /^([^\s()]+)\s+BETWEEN\s+0\s+AND\s+1$/is.exec(text);
125
+ if (between)
126
+ return sameColumn(between[1], column);
127
+ const either = /^\(?\s*([^\s()=]+)\s*=\s*([01])\s*\)?\s+OR\s+\(?\s*([^\s()=]+)\s*=\s*([01])\s*\)?$/is.exec(text);
128
+ if (either)
129
+ return sameColumn(either[1], column) && sameColumn(either[3], column) && either[2] !== either[4];
130
+ return false;
131
+ }
132
+ /**
133
+ * What a single CHECK expression says of a text column's length or form, in
134
+ * the two simple shapes a form can check as someone types (textRules.ts):
135
+ * `char_length(name) >= 2` (or `length`, `character_length`, `>`) — the fewest characters;
136
+ * `code ~ '^[A-Z]{3}$'` — a regular expression the value matches somewhere,
137
+ * returned as a whole-value JavaScript pattern, and only where JavaScript reads it.
138
+ * Postgres's stored spelling (`char_length((name)::text) >= 2`) is the same
139
+ * shape once its casts are off. Anything more (an AND, `~*`, a bound above)
140
+ * is no rule: a partial reading would be presented as the whole of it.
141
+ */
142
+ export function checkTextRule(expression, column) {
143
+ const text = unwrap(stripCasts(expression));
144
+ const length = /^(?:char_length|character_length|length)\s*\(\s*\(?\s*([^\s()]+?)\s*\)?\s*\)\s*(>=|>)\s*(\d{1,5})$/i.exec(text);
145
+ if (length) {
146
+ if (!sameColumn(length[1], column))
147
+ return undefined;
148
+ const min = Number(length[3]) + (length[2] === '>' ? 1 : 0);
149
+ return min > 0 ? { min } : undefined;
150
+ }
151
+ const match = /^\(?\s*([^\s()]+)\s*\)?\s*~\s*'((?:[^']|'')*)'$/.exec(text);
152
+ if (!match || !sameColumn(match[1], column))
153
+ return undefined;
154
+ const source = match[2].replace(/''/g, "'");
155
+ /* `~` finds the pattern anywhere; a form's pattern is the whole value. One
156
+ anchored at both ends already is; any other matches with anything around it. */
157
+ const anchored = source.startsWith('^') && source.endsWith('$') && !source.endsWith('\\$');
158
+ const pattern = anchored ? source : `[\\s\\S]*(?:${source})[\\s\\S]*`;
159
+ try {
160
+ new RegExp(`^(?:${pattern})$`, 'u');
161
+ }
162
+ catch {
163
+ return undefined;
164
+ }
165
+ return { pattern };
166
+ }
167
+ /** An expression without the parentheses that wrap the whole of it: `((a IN (0, 1)))` is `a IN (0, 1)`. */
168
+ function unwrap(expression) {
169
+ let text = expression.trim();
170
+ while (text.startsWith('(')) {
171
+ let depth = 0;
172
+ let closes = -1;
173
+ for (let i = 0; i < text.length; i += 1) {
174
+ if (text[i] === '(')
175
+ depth += 1;
176
+ else if (text[i] === ')' && --depth === 0) {
177
+ closes = i;
178
+ break;
179
+ }
180
+ }
181
+ if (closes !== text.length - 1)
182
+ break;
183
+ text = text.slice(1, -1).trim();
184
+ }
185
+ return text;
186
+ }
187
+ /** The columns of a `CREATE TABLE` statement a CHECK pins to 0 and 1 (checkFlag). */
188
+ export function flagsFromDDL(ddl, columns) {
189
+ const checks = checksIn(ddl);
190
+ return new Set(columns.filter((column) => checks.some((check) => checkFlag(check, column))));
191
+ }
192
+ /**
193
+ * Every CHECK clause in a `CREATE TABLE` statement, for dialects that keep
194
+ * the statement rather than the constraints — SQLite.
195
+ *
196
+ * Scanned with a depth counter rather than a regex because a check body
197
+ * contains parentheses of its own, and matching to the first `)` truncates
198
+ * `CHECK (status IN ('a','b'))` to `status IN ('a'`.
199
+ */
200
+ export function checksIn(ddl) {
201
+ const found = [];
202
+ const pattern = /\bCHECK\s*\(/gi;
203
+ let match;
204
+ while ((match = pattern.exec(ddl))) {
205
+ let depth = 1;
206
+ let i = match.index + match[0].length;
207
+ let quoted = null;
208
+ const start = i;
209
+ for (; i < ddl.length && depth > 0; i += 1) {
210
+ const ch = ddl[i];
211
+ if (quoted) {
212
+ if (ch === quoted)
213
+ quoted = null;
214
+ continue;
215
+ }
216
+ if (ch === "'" || ch === '"')
217
+ quoted = ch;
218
+ else if (ch === '(')
219
+ depth += 1;
220
+ else if (ch === ')')
221
+ depth -= 1;
222
+ }
223
+ if (depth === 0)
224
+ found.push(ddl.slice(start, i - 1));
225
+ pattern.lastIndex = i;
226
+ }
227
+ return found;
228
+ }
229
+ /**
230
+ * The allowed values for each column of a table, read out of its DDL.
231
+ *
232
+ * Column-level (`status TEXT CHECK (status IN (...))`) and table-level
233
+ * (`CHECK (status IN (...))`) checks are the same text by the time they get
234
+ * here, which is why this asks each check about each column rather than
235
+ * trying to work out which column a check was attached to.
236
+ */
237
+ export function vocabularyFromDDL(ddl, columns) {
238
+ const found = new Map();
239
+ for (const check of checksIn(ddl)) {
240
+ for (const column of columns) {
241
+ if (found.has(column))
242
+ continue;
243
+ const values = checkVocabulary(check, column);
244
+ if (values)
245
+ found.set(column, values);
246
+ }
247
+ }
248
+ return found;
249
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The day a week starts on where an App is read: its `ui.locale`'s own first
3
+ * day (Sunday in the US, Monday in most of the world), and Monday — ISO's —
4
+ * where the App names no locale. Said as an ISO weekday, 1 (Monday) to 7
5
+ * (Sunday), the number a `week` bucket's SQL takes (filter.ts).
6
+ */
7
+ export declare function localeWeekStart(locale: string | undefined): number;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Which weekday a week starts on in a reader's locale, read once and remembered. Shared by the server's date
3
+ * buckets and the client's charts, so a `week` means the same seven days on both sides.
4
+ */
5
+ const weekStarts = new Map();
6
+ /**
7
+ * The day a week starts on where an App is read: its `ui.locale`'s own first
8
+ * day (Sunday in the US, Monday in most of the world), and Monday — ISO's —
9
+ * where the App names no locale. Said as an ISO weekday, 1 (Monday) to 7
10
+ * (Sunday), the number a `week` bucket's SQL takes (filter.ts).
11
+ */
12
+ export function localeWeekStart(locale) {
13
+ if (!locale)
14
+ return 1;
15
+ /* Asked for every date a request reads, of the same few locales; building
16
+ an Intl.Locale each time was measurable on a busy server. Bounded,
17
+ because a locale can come from a person's own setting. */
18
+ const known = weekStarts.get(locale);
19
+ if (known !== undefined)
20
+ return known;
21
+ if (weekStarts.size >= 64)
22
+ weekStarts.clear();
23
+ const first = readWeekStart(locale);
24
+ weekStarts.set(locale, first);
25
+ return first;
26
+ }
27
+ function readWeekStart(locale) {
28
+ try {
29
+ const tag = new Intl.Locale(locale);
30
+ const first = (tag.getWeekInfo?.() ?? tag.weekInfo)?.firstDay;
31
+ return typeof first === 'number' && Number.isInteger(first) && first >= 1 && first <= 7 ? first : 1;
32
+ }
33
+ catch {
34
+ return 1;
35
+ }
36
+ }
package/mark.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><style>.i{fill:#1c1a17}.a{fill:#6b3fd4}@media (prefers-color-scheme:dark){.i{fill:#f2f0ec}.a{fill:#a88bff}}</style><path class="i" d="M2 4H26V18H22V10H18V28H12V10H8V28H2Z"/><rect class="a" x="20" y="20" width="10" height="8"/></svg>