@mistriwork/engine 0.0.0 → 1.0.0-rc.9

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 +16 -1
  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 +62 -0
  386. package/dist/shared/keysetPage.js +159 -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 +262 -3
  545. package/schema/model.d.ts +298 -0
  546. package/schema/theme.d.ts +587 -0
@@ -0,0 +1,554 @@
1
+ /**
2
+ * Build the demo database.
3
+ *
4
+ * Lives in `src/` (not `test/`) because it ships: `tablewalk --demo` builds
5
+ * one of these at runtime so a new install has something to walk without
6
+ * hunting for a database first. `test/make-demo-db.ts` re-exports it, so the
7
+ * suite and `npm run demo` keep the path they have always used.
8
+ *
9
+ * A demo that ships as a binary file is a demo nobody can review, so this
10
+ * writes one from source instead. The shape is chosen to exercise the parts
11
+ * of the tool that are easy to get wrong: a self-referencing key, a composite
12
+ * key, a view, a nullable reference, and one table that several others point
13
+ * at so the reverse-reference panel has something to say.
14
+ */
15
+ import { DatabaseSync } from 'node:sqlite';
16
+ import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';
17
+ import { dirname, join } from 'node:path';
18
+ import { tmpdir } from 'node:os';
19
+ import { productEnv } from './product.js';
20
+ const SCHEMA = `
21
+ CREATE TABLE country (
22
+ code TEXT PRIMARY KEY,
23
+ name TEXT NOT NULL
24
+ );
25
+
26
+ CREATE TABLE customer (
27
+ id INTEGER PRIMARY KEY,
28
+ name TEXT NOT NULL,
29
+ email TEXT,
30
+ country_code TEXT REFERENCES country(code),
31
+ credit_limit REAL DEFAULT 0,
32
+ active INTEGER NOT NULL DEFAULT 1,
33
+ signed_up DATE
34
+ );
35
+
36
+ -- Self-referencing: an employee reports to an employee. The graph view has to
37
+ -- handle an edge whose two ends are the same table without looping forever.
38
+ CREATE TABLE employee (
39
+ id INTEGER PRIMARY KEY,
40
+ first_name TEXT NOT NULL,
41
+ last_name TEXT NOT NULL,
42
+ title TEXT,
43
+ manager_id INTEGER REFERENCES employee(id),
44
+ hired_on DATE
45
+ );
46
+
47
+ CREATE TABLE invoice (
48
+ id INTEGER PRIMARY KEY,
49
+ customer_id INTEGER NOT NULL REFERENCES customer(id),
50
+ sold_by INTEGER REFERENCES employee(id),
51
+ invoice_date DATE NOT NULL,
52
+ total REAL NOT NULL DEFAULT 0,
53
+ -- A CHECK, not a lookup table: this is how most schemas in the wild spell
54
+ -- an enum, and to anything reading the catalog it is an untyped TEXT column
55
+ -- unless the constraint is read too.
56
+ status TEXT NOT NULL DEFAULT 'issued'
57
+ CHECK (status IN ('draft','issued','paid','void'))
58
+ );
59
+
60
+ CREATE TABLE product (
61
+ sku TEXT PRIMARY KEY,
62
+ name TEXT NOT NULL,
63
+ unit_price REAL NOT NULL
64
+ );
65
+
66
+ -- Composite primary key AND a composite-capable child, so PRAGMA collapsing
67
+ -- and multi-column reverse lookups both get exercised.
68
+ CREATE TABLE invoice_line (
69
+ invoice_id INTEGER NOT NULL REFERENCES invoice(id),
70
+ line_no INTEGER NOT NULL,
71
+ sku TEXT NOT NULL REFERENCES product(sku),
72
+ quantity INTEGER NOT NULL DEFAULT 1,
73
+ PRIMARY KEY (invoice_id, line_no)
74
+ );
75
+
76
+ CREATE TABLE shipment (
77
+ id INTEGER PRIMARY KEY,
78
+ invoice_id INTEGER NOT NULL,
79
+ line_no INTEGER NOT NULL,
80
+ shipped_on DATE,
81
+ FOREIGN KEY (invoice_id, line_no) REFERENCES invoice_line(invoice_id, line_no)
82
+ );
83
+
84
+ CREATE VIEW customer_totals AS
85
+ SELECT c.id, c.name, COUNT(i.id) AS invoices, COALESCE(SUM(i.total), 0) AS lifetime
86
+ FROM customer c LEFT JOIN invoice i ON i.customer_id = c.id
87
+ GROUP BY c.id, c.name;
88
+ `;
89
+ const DATA = `
90
+ INSERT INTO country VALUES ('AU','Australia'), ('NZ','New Zealand'), ('GB','United Kingdom');
91
+
92
+ INSERT INTO customer (id, name, email, country_code, credit_limit, active, signed_up) VALUES
93
+ (1,'Harbour Freight','ops@harbourfreight.example','AU',5000,1,'2023-02-11'),
94
+ (2,'Kereru Coffee','hello@kereru.example','NZ',1200,1,'2024-06-30'),
95
+ (3,'Pennine Tools','accounts@pennine.example','GB',0,0,'2022-11-05'),
96
+ (4,'Dry Creek Vineyards',NULL,'AU',9000,1,'2025-01-19'),
97
+ (5,'Southerly Logistics','ap@southerly.example',NULL,2500,1,'2025-09-02');
98
+
99
+ INSERT INTO employee (id, first_name, last_name, title, manager_id, hired_on) VALUES
100
+ (1,'Ada','Fraser','Managing Director',NULL,'2019-03-01'),
101
+ (2,'Miles','Okonkwo','Sales Manager',1,'2020-07-15'),
102
+ (3,'Rina','Petrova','Account Executive',2,'2022-01-10'),
103
+ (4,'Tom','Whitfield','Account Executive',2,'2023-08-22'),
104
+ (5,'Joan','Alvarez','Support Lead',1,'2021-05-04');
105
+
106
+ INSERT INTO product VALUES
107
+ ('SKU-100','Bench Vice 150mm',249.00),
108
+ ('SKU-200','Torque Wrench',389.50),
109
+ ('SKU-300','Impact Driver',179.95),
110
+ ('SKU-400','Socket Set 42pc',129.00);
111
+
112
+ INSERT INTO invoice (id, customer_id, sold_by, invoice_date, total) VALUES
113
+ (1001,1,3,'2025-03-14',627.95),
114
+ (1002,1,3,'2025-07-02',389.50),
115
+ (1003,2,4,'2025-08-19',258.00),
116
+ (1004,4,3,'2026-01-08',1247.40),
117
+ (1005,4,4,'2026-05-21',179.95),
118
+ (1006,5,NULL,'2026-07-30',908.00),
119
+ -- Deliberately has no lines. An aggregate over no children must count 0
120
+ -- and sum to null, and without a childless parent in the fixture that
121
+ -- distinction cannot be tested at all.
122
+ (1007,3,4,'2026-08-02',0);
123
+
124
+ INSERT INTO invoice_line VALUES
125
+ (1001,1,'SKU-100',1),(1001,2,'SKU-300',2),
126
+ (1002,1,'SKU-200',1),
127
+ (1003,1,'SKU-400',2),
128
+ (1004,1,'SKU-200',2),(1004,2,'SKU-300',1),(1004,3,'SKU-400',2),
129
+ (1005,1,'SKU-300',1),
130
+ (1006,1,'SKU-100',2),(1006,2,'SKU-200',1);
131
+
132
+ INSERT INTO shipment (id, invoice_id, line_no, shipped_on) VALUES
133
+ (1,1001,1,'2025-03-16'),(2,1001,2,'2025-03-16'),
134
+ (3,1002,1,'2025-07-04'),(4,1004,1,'2026-01-10'),(5,1004,2,NULL);
135
+ `;
136
+ /**
137
+ * Where `--demo` builds its database. A fixed `$TMPDIR/tablewalk-demo.db` was
138
+ * a machine-global path that every boot deletes and rebuilds, so two people —
139
+ * or two test runs, or a run beside a demo someone left open — silently
140
+ * corrupted each other. Observed as twelve browser failures that looked
141
+ * exactly like flakes. One directory per process instead, the same move the
142
+ * PostgreSQL fixtures already made.
143
+ *
144
+ * `TABLEWALK_DEMO_DB` (`MISTRI_DEMO_DB` under mistri, product.ts) names the file instead, for a caller that has to read
145
+ * the database it served — the browser suite does — or wants one that
146
+ * survives the process.
147
+ */
148
+ let chosen;
149
+ export function demoDatabaseFile() {
150
+ const named = productEnv('DEMO_DB')?.trim();
151
+ if (named)
152
+ return named;
153
+ if (chosen)
154
+ return chosen;
155
+ const directory = mkdtempSync(join(tmpdir(), 'tablewalk-demo-'));
156
+ // The demo is disposable by definition: nothing here outlives the process
157
+ // that built it, and leaving a directory per run in $TMPDIR would be litter.
158
+ process.on('exit', () => {
159
+ try {
160
+ rmSync(directory, { recursive: true, force: true });
161
+ }
162
+ catch {
163
+ /* going away anyway */
164
+ }
165
+ });
166
+ return (chosen = join(directory, 'demo.db'));
167
+ }
168
+ export function makeDemoDatabase(file) {
169
+ mkdirSync(dirname(file), { recursive: true });
170
+ rmSync(file, { force: true });
171
+ const db = new DatabaseSync(file);
172
+ db.exec('PRAGMA foreign_keys = ON');
173
+ db.exec(SCHEMA);
174
+ db.exec(DATA);
175
+ db.close();
176
+ }
177
+ /* ---------- bulk seeding ----------
178
+
179
+ Opt-in, and deterministic. The small fixture above is what the test suite
180
+ asserts against — `customer` has exactly five rows and several tests say so
181
+ — so bulk data is layered on top by request rather than by default.
182
+
183
+ Determinism comes from a seeded generator rather than Math.random: the same
184
+ scale always produces the same database, so a screenshot, a row count or a
185
+ reported bug can be reproduced exactly. */
186
+ /** mulberry32 — small, fast, and good enough for plausible-looking data. */
187
+ function rng(seed) {
188
+ let a = seed >>> 0;
189
+ return () => {
190
+ a = (a + 0x6d2b79f5) >>> 0;
191
+ let t = Math.imul(a ^ (a >>> 15), 1 | a);
192
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
193
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
194
+ };
195
+ }
196
+ const FIRST = [
197
+ 'Ada',
198
+ 'Miles',
199
+ 'Rina',
200
+ 'Tom',
201
+ 'Joan',
202
+ 'Priya',
203
+ 'Hugo',
204
+ 'Wren',
205
+ 'Kofi',
206
+ 'Ines',
207
+ 'Bo',
208
+ 'Yuki',
209
+ 'Omar',
210
+ 'Lena',
211
+ 'Fitz',
212
+ 'Nadia',
213
+ 'Ravi',
214
+ 'Signe',
215
+ 'Cormac',
216
+ 'Tess',
217
+ ];
218
+ const LAST = [
219
+ 'Fraser',
220
+ 'Okonkwo',
221
+ 'Petrova',
222
+ 'Whitfield',
223
+ 'Alvarez',
224
+ 'Nair',
225
+ 'Lindqvist',
226
+ 'Baptiste',
227
+ 'Mensah',
228
+ 'Duarte',
229
+ 'Kirby',
230
+ 'Tanaka',
231
+ 'Haddad',
232
+ 'Vogel',
233
+ 'Moss',
234
+ 'Rahman',
235
+ 'Iyer',
236
+ 'Bergen',
237
+ 'Doyle',
238
+ 'Whelan',
239
+ ];
240
+ const NOUN = [
241
+ 'Freight',
242
+ 'Coffee',
243
+ 'Tools',
244
+ 'Vineyards',
245
+ 'Logistics',
246
+ 'Foundry',
247
+ 'Provisions',
248
+ 'Marine',
249
+ 'Timber',
250
+ 'Electrics',
251
+ 'Joinery',
252
+ 'Bakery',
253
+ 'Optics',
254
+ 'Fabrication',
255
+ 'Roasters',
256
+ 'Surveying',
257
+ 'Plumbing',
258
+ 'Glassworks',
259
+ ];
260
+ const PLACE = [
261
+ 'Harbour',
262
+ 'Pennine',
263
+ 'Dry Creek',
264
+ 'Southerly',
265
+ 'Kereru',
266
+ 'Otway',
267
+ 'Blackwood',
268
+ 'Fitzroy',
269
+ 'Kaimai',
270
+ 'Torrens',
271
+ 'Mallee',
272
+ 'Waikato',
273
+ 'Bendigo',
274
+ 'Arthurs',
275
+ 'Nullarbor',
276
+ 'Kimberley',
277
+ ];
278
+ const TITLES = [
279
+ 'Account Executive',
280
+ 'Sales Manager',
281
+ 'Support Lead',
282
+ 'Field Technician',
283
+ 'Operations Analyst',
284
+ 'Warehouse Lead',
285
+ 'Credit Controller',
286
+ 'Regional Manager',
287
+ ];
288
+ /* The countries a seeded demo spreads its customers over, beyond the three the
289
+ fixture declares. Real places with real names, because a column of `CC-07`
290
+ teaches nothing about what a grouped answer looks like. */
291
+ const MORE_COUNTRIES = [
292
+ ['IE', 'Ireland'],
293
+ ['CA', 'Canada'],
294
+ ['US', 'United States'],
295
+ ['DE', 'Germany'],
296
+ ['FR', 'France'],
297
+ ['ES', 'Spain'],
298
+ ['IT', 'Italy'],
299
+ ['NL', 'Netherlands'],
300
+ ['SE', 'Sweden'],
301
+ ['NO', 'Norway'],
302
+ ['JP', 'Japan'],
303
+ ['SG', 'Singapore'],
304
+ ['ZA', 'South Africa'],
305
+ ['BR', 'Brazil'],
306
+ ['IN', 'India'],
307
+ ];
308
+ const GEAR = [
309
+ 'Bench Vice',
310
+ 'Torque Wrench',
311
+ 'Impact Driver',
312
+ 'Socket Set',
313
+ 'Angle Grinder',
314
+ 'Circular Saw',
315
+ 'Air Compressor',
316
+ 'Bandsaw',
317
+ 'Drill Press',
318
+ 'Welder',
319
+ 'Lathe Chuck',
320
+ 'Caliper Set',
321
+ ];
322
+ /* A deliberately awkward table, created only when seeding.
323
+
324
+ Everything here is something that is easy to get wrong and easy to miss:
325
+ twenty-seven columns so the grid has to scroll and the column chooser has
326
+ to be usable; *two* self-references, because code that handles one often
327
+ assumes there is only one; eight outgoing keys and two incoming, so the
328
+ neighbourhood diagram has to lay out both directions at once; and three
329
+ separate references to the same table, which a naive reverse-reference
330
+ count collapses into one.
331
+
332
+ It is kept out of the base fixture on purpose — several tests assert the
333
+ exact table list, and that assertion is worth keeping honest. */
334
+ const WIDE_SCHEMA = `
335
+ CREATE TABLE work_order (
336
+ id INTEGER PRIMARY KEY,
337
+ reference TEXT NOT NULL,
338
+ parent_id INTEGER REFERENCES work_order(id),
339
+ supersedes_id INTEGER REFERENCES work_order(id),
340
+ customer_id INTEGER NOT NULL REFERENCES customer(id),
341
+ raised_by INTEGER REFERENCES employee(id),
342
+ assigned_to INTEGER REFERENCES employee(id),
343
+ approved_by INTEGER REFERENCES employee(id),
344
+ country_code TEXT REFERENCES country(code),
345
+ product_sku TEXT REFERENCES product(sku),
346
+ invoice_id INTEGER REFERENCES invoice(id),
347
+ -- A CHECK rather than a bare TEXT column, because that is how most SQLite
348
+ -- and Postgres schemas actually spell an enum -- and it is the vocabulary
349
+ -- the table tool reports and the insert form offers.
350
+ status TEXT NOT NULL DEFAULT 'open'
351
+ CHECK (status IN ('open','scheduled','in_progress','awaiting_parts','on_hold','completed','cancelled')),
352
+ priority INTEGER NOT NULL DEFAULT 3,
353
+ is_urgent INTEGER NOT NULL DEFAULT 0,
354
+ is_billable INTEGER NOT NULL DEFAULT 1,
355
+ opened_on DATE NOT NULL,
356
+ due_on DATE,
357
+ closed_on DATE,
358
+ estimated_hours REAL,
359
+ actual_hours REAL,
360
+ labour_cost REAL NOT NULL DEFAULT 0,
361
+ parts_cost REAL NOT NULL DEFAULT 0,
362
+ total_cost REAL NOT NULL DEFAULT 0,
363
+ site_address TEXT,
364
+ external_ref TEXT,
365
+ notes TEXT,
366
+ sys_updated_at TIMESTAMP NOT NULL
367
+ );
368
+
369
+ CREATE INDEX work_order_customer_idx ON work_order (customer_id, status);
370
+ CREATE INDEX work_order_opened_idx ON work_order (opened_on);
371
+
372
+ CREATE TABLE work_order_note (
373
+ id INTEGER PRIMARY KEY,
374
+ work_order_id INTEGER NOT NULL REFERENCES work_order(id),
375
+ author_id INTEGER REFERENCES employee(id),
376
+ written_on DATE NOT NULL,
377
+ body TEXT NOT NULL
378
+ );
379
+
380
+ CREATE TABLE work_order_part (
381
+ work_order_id INTEGER NOT NULL REFERENCES work_order(id),
382
+ line_no INTEGER NOT NULL,
383
+ sku TEXT NOT NULL REFERENCES product(sku),
384
+ quantity INTEGER NOT NULL DEFAULT 1,
385
+ PRIMARY KEY (work_order_id, line_no)
386
+ );
387
+ `;
388
+ const STATUSES = ['open', 'scheduled', 'in_progress', 'awaiting_parts', 'on_hold', 'completed', 'cancelled'];
389
+ const STREETS = ['Wharf Rd', 'Kembla St', 'Beach Pde', 'Rundle Ml', 'Flinders Ln', 'Cuba St', 'Vulcan Ln'];
390
+ const NOTE_TEXT = [
391
+ 'Attended site, isolated the unit and confirmed the fault reported by the customer.',
392
+ 'Parts ordered from the supplier. Lead time quoted as five working days.',
393
+ 'Customer requested the visit be rescheduled to the following week.',
394
+ 'Work completed and signed off on site. No further action required.',
395
+ ];
396
+ export function seedDemoDatabase(file, { scale = 1000, seed = 20260822 } = {}) {
397
+ const db = new DatabaseSync(file);
398
+ const random = rng(seed);
399
+ const pick = (list) => list[Math.floor(random() * list.length)];
400
+ const between = (lo, hi) => lo + Math.floor(random() * (hi - lo + 1));
401
+ /* More countries, but only when seeding.
402
+
403
+ The small fixture has three, which is right for it — several tests count
404
+ that table. It is wrong for a demo: "which countries have the most
405
+ customers" is one of the questions `breakdown` exists to answer and one
406
+ of the examples in the README, and three groups does not show what a
407
+ breakdown is for. Inserted here rather than in the fixture so the tests
408
+ that assert three keep asserting three.
409
+
410
+ `INSERT OR IGNORE`, so seeding a database twice is not an error. */
411
+ const insertCountry = db.prepare('INSERT OR IGNORE INTO country (code, name) VALUES (?, ?)');
412
+ for (const [code, name] of MORE_COUNTRIES)
413
+ insertCountry.run(code, name);
414
+ const countries = db.prepare('SELECT code FROM country').all().map((r) => r.code);
415
+ /* One transaction for the whole load. Without it SQLite commits per
416
+ statement and a hundred thousand rows takes minutes instead of seconds. */
417
+ db.exec('BEGIN');
418
+ try {
419
+ const employees = Math.max(8, Math.round(scale / 12));
420
+ const insertEmployee = db.prepare('INSERT INTO employee (first_name, last_name, title, manager_id, hired_on) VALUES (?, ?, ?, ?, ?)');
421
+ for (let i = 0; i < employees; i++) {
422
+ // Managers are drawn from employees already inserted, so the
423
+ // self-reference always points backwards and never dangles.
424
+ const managerId = i < 3 ? null : between(1, 3 + Math.floor(i / 4));
425
+ insertEmployee.run(pick(FIRST), pick(LAST), pick(TITLES), managerId, `${between(2018, 2026)}-${String(between(1, 12)).padStart(2, '0')}-${String(between(1, 28)).padStart(2, '0')}`);
426
+ }
427
+ const employeeCount = Number(db.prepare('SELECT COUNT(*) AS n FROM employee').get().n);
428
+ const insertProduct = db.prepare('INSERT INTO product (sku, name, unit_price) VALUES (?, ?, ?)');
429
+ const products = Math.max(20, Math.round(scale / 4));
430
+ const skus = [];
431
+ for (let i = 0; i < products; i++) {
432
+ const sku = `SKU-${String(1000 + i)}`;
433
+ skus.push(sku);
434
+ insertProduct.run(sku, `${pick(GEAR)} ${between(50, 900)}mm`, Math.round(random() * 90000) / 100);
435
+ }
436
+ const insertCustomer = db.prepare('INSERT INTO customer (name, email, country_code, credit_limit, active, signed_up) VALUES (?, ?, ?, ?, ?, ?)');
437
+ for (let i = 0; i < scale; i++) {
438
+ const name = `${pick(PLACE)} ${pick(NOUN)}`;
439
+ // Roughly one in nine has no email and one in eleven no country, so the
440
+ // null rendering and `is empty` filters have something to find.
441
+ const email = random() < 0.11 ? null : `${name.toLowerCase().replace(/[^a-z]+/g, '.')}@example.com`;
442
+ insertCustomer.run(name, email, random() < 0.09 ? null : pick(countries), between(0, 40) * 250, random() < 0.18 ? 0 : 1, `${between(2021, 2026)}-${String(between(1, 12)).padStart(2, '0')}-${String(between(1, 28)).padStart(2, '0')}`);
443
+ }
444
+ const customerCount = Number(db.prepare('SELECT COUNT(*) AS n FROM customer').get().n);
445
+ const insertInvoice = db.prepare('INSERT INTO invoice (customer_id, sold_by, invoice_date, total, status) VALUES (?, ?, ?, ?, ?)');
446
+ /* A spread of statuses, weighted the way a ledger actually looks: mostly
447
+ settled, a working set outstanding, a few never finished.
448
+
449
+ Without this every seeded invoice took the column default and the demo
450
+ answered `invoice count by status` — the first example in the README —
451
+ with a single group of eighteen thousand. The CHECK constraint on the
452
+ column lists four values; a demo that only ever shows one of them
453
+ teaches nothing about the column, the constraint, or the breakdown. */
454
+ const STATUSES = [
455
+ ['paid', 0.62],
456
+ ['issued', 0.24],
457
+ ['draft', 0.11],
458
+ ['void', 0.03],
459
+ ];
460
+ const statusFor = () => {
461
+ let r = random();
462
+ for (const [name, share] of STATUSES) {
463
+ if (r < share)
464
+ return name;
465
+ r -= share;
466
+ }
467
+ return 'issued';
468
+ };
469
+ const insertLine = db.prepare('INSERT INTO invoice_line (invoice_id, line_no, sku, quantity) VALUES (?, ?, ?, ?)');
470
+ const insertShipment = db.prepare('INSERT INTO shipment (invoice_id, line_no, shipped_on) VALUES (?, ?, ?)');
471
+ const invoices = scale * 6;
472
+ let nextInvoiceId = Number(db.prepare('SELECT COALESCE(MAX(id), 0) + 1 AS n FROM invoice').get().n);
473
+ for (let i = 0; i < invoices; i++) {
474
+ const id = nextInvoiceId++;
475
+ const date = `${between(2023, 2026)}-${String(between(1, 12)).padStart(2, '0')}-${String(between(1, 28)).padStart(2, '0')}`;
476
+ let total = 0;
477
+ const lines = between(1, 6);
478
+ insertInvoice.run(between(1, customerCount), random() < 0.08 ? null : between(1, employeeCount), date, 0, statusFor());
479
+ for (let line = 1; line <= lines; line++) {
480
+ const quantity = between(1, 12);
481
+ insertLine.run(id, line, pick(skus), quantity);
482
+ total += quantity * between(50, 900);
483
+ // Most lines ship; some are pending, and a few shipped rows carry a
484
+ // null date so the date column has nulls to render.
485
+ if (random() < 0.72) {
486
+ insertShipment.run(id, line, random() < 0.1 ? null : date);
487
+ }
488
+ }
489
+ db.prepare('UPDATE invoice SET total = ? WHERE id = ?').run(total, id);
490
+ }
491
+ db.exec('COMMIT');
492
+ }
493
+ catch (err) {
494
+ db.exec('ROLLBACK');
495
+ db.close();
496
+ throw err;
497
+ }
498
+ seedWorkOrders(db, random, pick, between, scale);
499
+ /* ANALYZE so the planner has statistics, and so anything reading row
500
+ estimates sees real numbers rather than zeros. */
501
+ db.exec('ANALYZE');
502
+ db.close();
503
+ }
504
+ /**
505
+ * The wide table, its notes and its parts.
506
+ *
507
+ * Split out because it is a different shape of data from the invoice chain
508
+ * above, and because the interesting part is the reference pattern rather
509
+ * than the volume.
510
+ */
511
+ function seedWorkOrders(db, random, pick, between, scale) {
512
+ db.exec(WIDE_SCHEMA);
513
+ const customers = Number(db.prepare('SELECT COUNT(*) AS n FROM customer').get().n);
514
+ const employees = Number(db.prepare('SELECT COUNT(*) AS n FROM employee').get().n);
515
+ const invoices = Number(db.prepare('SELECT MAX(id) AS n FROM invoice').get().n);
516
+ const skus = db.prepare('SELECT sku FROM product').all().map((r) => r.sku);
517
+ const countries = db.prepare('SELECT code FROM country').all().map((r) => r.code);
518
+ const orders = Math.max(50, scale * 3);
519
+ const date = (fromYear) => `${between(fromYear, 2026)}-${String(between(1, 12)).padStart(2, '0')}-${String(between(1, 28)).padStart(2, '0')}`;
520
+ db.exec('BEGIN');
521
+ const insert = db.prepare(`
522
+ INSERT INTO work_order (
523
+ reference, parent_id, supersedes_id, customer_id, raised_by, assigned_to, approved_by,
524
+ country_code, product_sku, invoice_id, status, priority, is_urgent, is_billable,
525
+ opened_on, due_on, closed_on, estimated_hours, actual_hours,
526
+ labour_cost, parts_cost, total_cost, site_address, external_ref, notes, sys_updated_at
527
+ ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`);
528
+ for (let i = 1; i <= orders; i++) {
529
+ const status = pick(STATUSES);
530
+ const closed = status === 'completed' || status === 'cancelled';
531
+ const estimated = Math.round(random() * 400) / 10;
532
+ const actual = closed ? Math.round(estimated * (0.6 + random()) * 10) / 10 : null;
533
+ const labour = Math.round((actual ?? 0) * between(80, 190) * 100) / 100;
534
+ const parts = Math.round(random() * 250000) / 100;
535
+ /* Parents and predecessors point only at rows already inserted, so both
536
+ self-references stay acyclic — a cycle here would be legal SQL and a
537
+ trap for anything that walks the graph. */
538
+ const parent = i > 10 && random() < 0.22 ? between(1, i - 1) : null;
539
+ const supersedes = i > 20 && random() < 0.1 ? between(1, i - 1) : null;
540
+ insert.run(`WO-${String(100000 + i)}`, parent, supersedes, between(1, customers), random() < 0.05 ? null : between(1, employees), random() < 0.15 ? null : between(1, employees), closed && random() < 0.8 ? between(1, employees) : null, random() < 0.12 ? null : pick(countries), random() < 0.3 ? null : pick(skus), random() < 0.55 && invoices ? between(1001, invoices) : null, status, between(1, 5), random() < 0.18 ? 1 : 0, random() < 0.85 ? 1 : 0, date(2023), random() < 0.9 ? date(2024) : null, closed ? date(2024) : null, estimated, actual, labour, parts, Math.round((labour + parts) * 100) / 100, `${between(1, 400)} ${pick(STREETS)}`, random() < 0.4 ? `EXT-${between(10000, 99999)}` : null, random() < 0.5 ? pick(NOTE_TEXT) : null, `${date(2025)}T${String(between(0, 23)).padStart(2, '0')}:${String(between(0, 59)).padStart(2, '0')}:00`);
541
+ }
542
+ const insertNote = db.prepare('INSERT INTO work_order_note (work_order_id, author_id, written_on, body) VALUES (?,?,?,?)');
543
+ const insertPart = db.prepare('INSERT INTO work_order_part (work_order_id, line_no, sku, quantity) VALUES (?,?,?,?)');
544
+ for (let id = 1; id <= orders; id++) {
545
+ for (let n = 0; n < between(0, 4); n++) {
546
+ insertNote.run(id, random() < 0.1 ? null : between(1, employees), date(2024), pick(NOTE_TEXT));
547
+ }
548
+ const parts = between(0, 5);
549
+ for (let line = 1; line <= parts; line++) {
550
+ insertPart.run(id, line, pick(skus), between(1, 20));
551
+ }
552
+ }
553
+ db.exec('COMMIT');
554
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * The client, served from source.
3
+ *
4
+ * The published package serves dist/client, which `vite build` wrote at
5
+ * publish time, and never reaches this file's import. Under tsx — `npm run
6
+ * dev`, `npm start`, every test suite — the client directory is the source
7
+ * tree, and since the source imports the TypeScript under src/shared it
8
+ * cannot go to a browser as it is. So the server hands static requests to
9
+ * Vite in middleware mode: each module is transformed on request, an edit
10
+ * reloads the page, and nothing has to be built first.
11
+ *
12
+ * The signal is the file this module was loaded from. `.ts` means tsx, and
13
+ * source; `.js` means the build, and dist/client. It is not the presence of
14
+ * a `src` directory in the path, which a user's install could have.
15
+ */
16
+ import type { EventEmitter } from 'node:events';
17
+ import type { IncomingMessage, Server, ServerResponse } from 'node:http';
18
+ import type { ViteDevServer } from 'vite';
19
+ export declare const FROM_SOURCE: boolean;
20
+ /**
21
+ * The page a product's server sends: the folder Vite serves from source (its index.html), the one the build left,
22
+ * and the workspace whose vite.config.ts, dependency cache and files Vite may use. The kit owns the page and says
23
+ * where it is (@mistriwork/kit/clientFiles.js); the engine serves whatever it is handed.
24
+ */
25
+ export interface ClientFiles {
26
+ source: string;
27
+ built: string;
28
+ workspace: string;
29
+ }
30
+ /** Whether the client is served through Vite. Source by default; the browser
31
+ * suite sets MISTRI_BUILT_CLIENT=1 so a server under tsx sends dist/client,
32
+ * which one `npm run build` made, instead of each server owning a Vite. Only
33
+ * the client's serving reads this — the rest of what FROM_SOURCE decides (the
34
+ * component SDK's exports, the console's components, the observer) stays on
35
+ * source, since those files sit beside the sources and not beside the build. */
36
+ export declare const SOURCE_CLIENT: boolean;
37
+ interface Vite {
38
+ middlewares: (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => void;
39
+ transformIndexHtml(url: string, html: string): Promise<string>;
40
+ /** A client module run on the server: the public pages' renderer (publicRender.ts). */
41
+ ssrLoadModule?(url: string): Promise<Record<string, unknown>>;
42
+ close(): Promise<void>;
43
+ closeHmr(): Promise<void>;
44
+ /** The hot-reload socket Vite's client falls back to (`devSocket`), for the page's connect-src. */
45
+ readonly socket?: string;
46
+ }
47
+ /**
48
+ * The socket Vite's client opens when its first, on the page's own origin,
49
+ * fails: `__HMR_DIRECT_TARGET__`, which Vite writes into `/@vite/client` from
50
+ * the same configuration, read here by the same rule. Where the page's origin
51
+ * carries the socket (a server tablewalk listens on, attachDevClient) the
52
+ * first one opens and `'self'` admits it. Where it does not — an App mounted
53
+ * in a host's server (embed/handler.ts), whose server never listens and whose
54
+ * host does not pass an upgrade on — the client tries this one, and a policy
55
+ * of `'self'` alone refused it. Without a protocol configured the client uses
56
+ * the page's, so both are named for the one host, port and path.
57
+ */
58
+ export declare function devSocket(config: Pick<ViteDevServer['config'], 'base' | 'server'>): string;
59
+ /** A retired source host never reactivates its dependency watcher. */
60
+ export declare function ownDevClient(created: Pick<ViteDevServer, 'watcher' | 'middlewares' | 'transformIndexHtml' | 'close'> & {
61
+ ws?: Pick<ViteDevServer['ws'], 'close'>;
62
+ ssrLoadModule?: ViteDevServer['ssrLoadModule'];
63
+ config?: Pick<ViteDevServer['config'], 'base' | 'server'>;
64
+ }, afterClose?: () => Promise<void>): Vite;
65
+ /** Shared middleware providers, with their HMR sockets owned by one HTTP
66
+ * server. A late factory belongs to its captured generation, never a restart. */
67
+ export declare function createDevClientHosts(): {
68
+ attach(server: Server): void;
69
+ closeHmr(server: Server): Promise<void>;
70
+ retire(server: Server): Promise<void>;
71
+ get(load: (owner: Server | undefined) => Promise<Vite>, base?: string): Promise<Vite>;
72
+ };
73
+ /**
74
+ * Told which server the pages are on, so hot reloads can share its port
75
+ * rather than opening a second listener that two test servers would then
76
+ * fight over — and so Vite, whose file watcher would keep a process alive,
77
+ * is closed once every server that used it has closed.
78
+ */
79
+ export declare function attachDevClient(server: Server): void;
80
+ /** Stop upgraded sockets before awaiting HTTP close, retaining the renderer
81
+ * until accepted HTTP responses have drained. Does not create a provider. */
82
+ export declare function closeDevClientHmr(server: Server): Promise<void>;
83
+ /** Release the source renderer after accepted HTTP responses have drained. */
84
+ export declare function retireDevClient(server: Server): Promise<void>;
85
+ export declare function sweepDevCaches(root: string): Promise<void>;
86
+ /**
87
+ * What Vite's file watcher may look at: the package whose client it serves,
88
+ * and nothing outside it. Vite watches its root and adds every file it loads
89
+ * from beyond it (src/shared, src/adapters, package.json) whatever its path,
90
+ * and chokidar follows links and, for a path gone by the time it looks,
91
+ * watches the nearest folder still there. Nothing bounded where that could
92
+ * lead: on a CI runner a served App's watcher reached /run and stat-ed udev's
93
+ * self-referring links (ELOOP). An App's own code never goes through this
94
+ * Vite (its components are compiled by appComponents.ts), so everything an
95
+ * edit can reload lives under the package root; the rest is ignored. Both
96
+ * spellings of the root, since module ids are real paths.
97
+ */
98
+ export declare function outsidePackage(packageRoot: string): (path: string) => boolean;
99
+ /**
100
+ * A watcher error is not the server's: chokidar emits 'error' for a path it
101
+ * cannot stat, and Vite listens for none, so the first one was an uncaught
102
+ * exception that took every page down with it. Say it once and keep serving;
103
+ * the watcher goes on with the paths it could read.
104
+ */
105
+ export declare function quietWatcherErrors(watcher: Pick<EventEmitter, 'on'>, warn?: (message: string) => void): void;
106
+ /** The Vite dev server, created on the first static request and kept. */
107
+ export declare function devClient(files: Pick<ClientFiles, 'source' | 'workspace'>, base?: string): Promise<Vite>;
108
+ export {};