@pithy-sh/core 0.1.1 → 0.1.3

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 (393) hide show
  1. package/dist/address/address.d.ts +57 -0
  2. package/dist/address/address.d.ts.map +1 -0
  3. package/dist/address/address.js +71 -0
  4. package/dist/audit/auditEvent.d.ts +89 -0
  5. package/dist/audit/auditEvent.d.ts.map +1 -0
  6. package/dist/audit/auditEvent.js +69 -0
  7. package/dist/audit/recorder.d.ts +18 -0
  8. package/dist/audit/recorder.d.ts.map +1 -0
  9. package/dist/audit/recorder.js +8 -0
  10. package/dist/capability/bindings.d.ts +62 -0
  11. package/dist/capability/bindings.d.ts.map +1 -0
  12. package/dist/capability/bindings.js +97 -0
  13. package/dist/capability/capability.d.ts +501 -0
  14. package/dist/capability/capability.d.ts.map +1 -0
  15. package/dist/capability/capability.js +16 -0
  16. package/dist/capability/client.d.ts +70 -0
  17. package/dist/capability/client.d.ts.map +1 -0
  18. package/dist/capability/client.js +86 -0
  19. package/dist/capability/compose.d.ts +25 -0
  20. package/dist/capability/compose.d.ts.map +1 -0
  21. package/dist/capability/compose.js +54 -0
  22. package/dist/capability/composition.d.ts +26 -0
  23. package/dist/capability/composition.d.ts.map +1 -0
  24. package/dist/capability/composition.js +84 -0
  25. package/dist/capability/config.d.ts +7 -0
  26. package/dist/capability/config.d.ts.map +1 -0
  27. package/dist/capability/config.js +14 -0
  28. package/dist/capability/devSecret.d.ts +32 -0
  29. package/dist/capability/devSecret.d.ts.map +1 -0
  30. package/dist/capability/devSecret.js +28 -0
  31. package/dist/capability/manifest.d.ts +298 -0
  32. package/dist/capability/manifest.d.ts.map +1 -0
  33. package/dist/capability/manifest.js +356 -0
  34. package/dist/capability/secretOrigin.d.ts +121 -0
  35. package/dist/capability/secretOrigin.d.ts.map +1 -0
  36. package/dist/capability/secretOrigin.js +134 -0
  37. package/dist/capability/settings.d.ts +119 -0
  38. package/dist/capability/settings.d.ts.map +1 -0
  39. package/dist/capability/settings.js +66 -0
  40. package/dist/capability/validateBindings.d.ts +4 -0
  41. package/dist/capability/validateBindings.d.ts.map +1 -0
  42. package/dist/capability/validateBindings.js +34 -0
  43. package/dist/capability/vanishingKey.d.ts +31 -0
  44. package/dist/capability/vanishingKey.d.ts.map +1 -0
  45. package/dist/capability/vanishingKey.js +79 -0
  46. package/dist/controlPlane/audit/actions.d.ts +70 -0
  47. package/dist/controlPlane/audit/actions.d.ts.map +1 -0
  48. package/dist/controlPlane/audit/actions.js +76 -0
  49. package/dist/controlPlane/capability.d.ts +47 -0
  50. package/dist/controlPlane/capability.d.ts.map +1 -0
  51. package/dist/controlPlane/capability.js +138 -0
  52. package/dist/controlPlane/config/config.d.ts +19 -0
  53. package/dist/controlPlane/config/config.d.ts.map +1 -0
  54. package/dist/controlPlane/config/config.js +85 -0
  55. package/dist/controlPlane/context.d.ts +27 -0
  56. package/dist/controlPlane/context.d.ts.map +1 -0
  57. package/dist/controlPlane/context.js +29 -0
  58. package/dist/controlPlane/data/connection.d.ts +79 -0
  59. package/dist/controlPlane/data/connection.d.ts.map +1 -0
  60. package/dist/controlPlane/data/connection.js +55 -0
  61. package/dist/controlPlane/data/keyLifecycle.d.ts +62 -0
  62. package/dist/controlPlane/data/keyLifecycle.d.ts.map +1 -0
  63. package/dist/controlPlane/data/keyLifecycle.js +126 -0
  64. package/dist/controlPlane/data/replay.d.ts +18 -0
  65. package/dist/controlPlane/data/replay.d.ts.map +1 -0
  66. package/dist/controlPlane/data/replay.js +20 -0
  67. package/dist/controlPlane/data/tables.d.ts +34 -0
  68. package/dist/controlPlane/data/tables.d.ts.map +1 -0
  69. package/dist/controlPlane/data/tables.js +37 -0
  70. package/dist/controlPlane/discovery/adminRoute.d.ts +313 -0
  71. package/dist/controlPlane/discovery/adminRoute.d.ts.map +1 -0
  72. package/dist/controlPlane/discovery/adminRoute.js +136 -0
  73. package/dist/controlPlane/discovery/configuration.d.ts +108 -0
  74. package/dist/controlPlane/discovery/configuration.d.ts.map +1 -0
  75. package/dist/controlPlane/discovery/configuration.js +187 -0
  76. package/dist/controlPlane/discovery/drift.d.ts +64 -0
  77. package/dist/controlPlane/discovery/drift.d.ts.map +1 -0
  78. package/dist/controlPlane/discovery/drift.js +58 -0
  79. package/dist/controlPlane/discovery/health.d.ts +99 -0
  80. package/dist/controlPlane/discovery/health.d.ts.map +1 -0
  81. package/dist/controlPlane/discovery/health.js +151 -0
  82. package/dist/controlPlane/discovery/healthSummary.d.ts +236 -0
  83. package/dist/controlPlane/discovery/healthSummary.d.ts.map +1 -0
  84. package/dist/controlPlane/discovery/healthSummary.js +278 -0
  85. package/dist/controlPlane/error/errors.d.ts +67 -0
  86. package/dist/controlPlane/error/errors.d.ts.map +1 -0
  87. package/dist/controlPlane/error/errors.js +79 -0
  88. package/dist/controlPlane/http/cors.d.ts +112 -0
  89. package/dist/controlPlane/http/cors.d.ts.map +1 -0
  90. package/dist/controlPlane/http/cors.js +192 -0
  91. package/dist/controlPlane/http/guard.d.ts +77 -0
  92. package/dist/controlPlane/http/guard.d.ts.map +1 -0
  93. package/dist/controlPlane/http/guard.js +142 -0
  94. package/dist/controlPlane/http/handlers.d.ts +179 -0
  95. package/dist/controlPlane/http/handlers.d.ts.map +1 -0
  96. package/dist/controlPlane/http/handlers.js +245 -0
  97. package/dist/controlPlane/http/responses.d.ts +99 -0
  98. package/dist/controlPlane/http/responses.d.ts.map +1 -0
  99. package/dist/controlPlane/http/responses.js +63 -0
  100. package/dist/controlPlane/http/routes.d.ts +40 -0
  101. package/dist/controlPlane/http/routes.d.ts.map +1 -0
  102. package/dist/controlPlane/http/routes.js +83 -0
  103. package/dist/controlPlane/http/schemas.d.ts +39 -0
  104. package/dist/controlPlane/http/schemas.d.ts.map +1 -0
  105. package/dist/controlPlane/http/schemas.js +31 -0
  106. package/dist/controlPlane/http/verify.d.ts +84 -0
  107. package/dist/controlPlane/http/verify.d.ts.map +1 -0
  108. package/dist/controlPlane/http/verify.js +65 -0
  109. package/dist/controlPlane/migrations/0001_init.d.ts +51 -0
  110. package/dist/controlPlane/migrations/0001_init.d.ts.map +1 -0
  111. package/dist/controlPlane/migrations/0001_init.js +65 -0
  112. package/dist/controlPlane/replay/d1Guard.d.ts +29 -0
  113. package/dist/controlPlane/replay/d1Guard.d.ts.map +1 -0
  114. package/dist/controlPlane/replay/d1Guard.js +39 -0
  115. package/dist/controlPlane/replay/guard.d.ts +52 -0
  116. package/dist/controlPlane/replay/guard.d.ts.map +1 -0
  117. package/dist/controlPlane/replay/guard.js +0 -0
  118. package/dist/controlPlane/replay/kvGuard.d.ts +99 -0
  119. package/dist/controlPlane/replay/kvGuard.d.ts.map +1 -0
  120. package/dist/controlPlane/replay/kvGuard.js +101 -0
  121. package/dist/controlPlane/scope/scope.d.ts +68 -0
  122. package/dist/controlPlane/scope/scope.d.ts.map +1 -0
  123. package/dist/controlPlane/scope/scope.js +63 -0
  124. package/dist/controlPlane/token/base64url.d.ts +10 -0
  125. package/dist/controlPlane/token/base64url.d.ts.map +1 -0
  126. package/dist/controlPlane/token/base64url.js +48 -0
  127. package/dist/controlPlane/token/claims.d.ts +83 -0
  128. package/dist/controlPlane/token/claims.d.ts.map +1 -0
  129. package/dist/controlPlane/token/claims.js +86 -0
  130. package/dist/controlPlane/token/digest.d.ts +44 -0
  131. package/dist/controlPlane/token/digest.d.ts.map +1 -0
  132. package/dist/controlPlane/token/digest.js +56 -0
  133. package/dist/controlPlane/token/jws.d.ts +52 -0
  134. package/dist/controlPlane/token/jws.d.ts.map +1 -0
  135. package/dist/controlPlane/token/jws.js +65 -0
  136. package/dist/controlPlane/token/mint.d.ts +56 -0
  137. package/dist/controlPlane/token/mint.d.ts.map +1 -0
  138. package/dist/controlPlane/token/mint.js +55 -0
  139. package/dist/controlPlane/wire.d.ts +122 -0
  140. package/dist/controlPlane/wire.d.ts.map +1 -0
  141. package/dist/controlPlane/wire.js +123 -0
  142. package/dist/createBackend.d.ts +58 -0
  143. package/dist/createBackend.d.ts.map +1 -0
  144. package/dist/createBackend.js +170 -0
  145. package/dist/createEntrypoint.d.ts +53 -0
  146. package/dist/createEntrypoint.d.ts.map +1 -0
  147. package/dist/createEntrypoint.js +52 -0
  148. package/dist/data/boundParameters.d.ts +83 -0
  149. package/dist/data/boundParameters.d.ts.map +1 -0
  150. package/dist/data/boundParameters.js +162 -0
  151. package/dist/data/codecs.d.ts +34 -0
  152. package/dist/data/codecs.d.ts.map +1 -0
  153. package/dist/data/codecs.js +135 -0
  154. package/dist/data/cursor.d.ts +81 -0
  155. package/dist/data/cursor.d.ts.map +1 -0
  156. package/dist/data/cursor.js +104 -0
  157. package/dist/data/databases.d.ts +55 -0
  158. package/dist/data/databases.d.ts.map +1 -0
  159. package/dist/data/databases.js +32 -0
  160. package/dist/data/db.d.ts +42 -0
  161. package/dist/data/db.d.ts.map +1 -0
  162. package/dist/data/db.js +24 -0
  163. package/dist/data/withD1Retry.d.ts +91 -0
  164. package/dist/data/withD1Retry.d.ts.map +1 -0
  165. package/dist/data/withD1Retry.js +152 -0
  166. package/dist/entitlement/entitlement.d.ts +118 -0
  167. package/dist/entitlement/entitlement.d.ts.map +1 -0
  168. package/dist/entitlement/entitlement.js +59 -0
  169. package/dist/entitlement/gateScan.d.ts +26 -0
  170. package/dist/entitlement/gateScan.d.ts.map +1 -0
  171. package/dist/entitlement/gateScan.js +96 -0
  172. package/dist/entitlement/require.d.ts +12 -0
  173. package/dist/entitlement/require.d.ts.map +1 -0
  174. package/dist/entitlement/require.js +123 -0
  175. package/dist/env/ambient.d.ts +52 -0
  176. package/dist/env/ambient.d.ts.map +1 -0
  177. package/dist/env/ambient.js +35 -0
  178. package/dist/env/ci.d.ts +36 -0
  179. package/dist/env/ci.d.ts.map +1 -0
  180. package/dist/env/ci.js +40 -0
  181. package/dist/env/stem.d.ts +23 -0
  182. package/dist/env/stem.d.ts.map +1 -0
  183. package/dist/env/stem.js +29 -0
  184. package/dist/error/cause.d.ts +143 -0
  185. package/dist/error/cause.d.ts.map +1 -0
  186. package/dist/error/cause.js +192 -0
  187. package/dist/error/client.d.ts +35 -0
  188. package/dist/error/client.d.ts.map +1 -0
  189. package/dist/error/client.js +38 -0
  190. package/dist/error/extend.d.ts +101 -0
  191. package/dist/error/extend.d.ts.map +1 -0
  192. package/dist/error/extend.js +76 -0
  193. package/dist/error/http.d.ts +1516 -0
  194. package/dist/error/http.d.ts.map +1 -0
  195. package/dist/error/http.js +72 -0
  196. package/dist/error/payload.d.ts +3034 -0
  197. package/dist/error/payload.d.ts.map +1 -0
  198. package/dist/error/payload.js +1110 -0
  199. package/dist/error/pithyError.d.ts +154 -0
  200. package/dist/error/pithyError.d.ts.map +1 -0
  201. package/dist/error/pithyError.js +197 -0
  202. package/dist/error/terminal.d.ts +28 -0
  203. package/dist/error/terminal.d.ts.map +1 -0
  204. package/dist/error/terminal.js +33 -0
  205. package/dist/http/authContext.d.ts +21 -0
  206. package/dist/http/authContext.d.ts.map +1 -0
  207. package/dist/http/authContext.js +23 -0
  208. package/dist/http/routeContract.d.ts +39 -0
  209. package/dist/http/routeContract.d.ts.map +1 -0
  210. package/dist/http/routeContract.js +82 -0
  211. package/dist/http/sameOrigin.d.ts +47 -0
  212. package/dist/http/sameOrigin.d.ts.map +1 -0
  213. package/dist/http/sameOrigin.js +24 -0
  214. package/dist/http/signedWebhook.d.ts +225 -0
  215. package/dist/http/signedWebhook.d.ts.map +1 -0
  216. package/dist/http/signedWebhook.js +247 -0
  217. package/dist/http/validation.d.ts +37 -0
  218. package/dist/http/validation.d.ts.map +1 -0
  219. package/dist/http/validation.js +14 -0
  220. package/dist/http/verification.d.ts +10 -0
  221. package/dist/http/verification.d.ts.map +1 -0
  222. package/dist/http/verification.js +17 -0
  223. package/dist/i18n/acceptLanguage.d.ts +22 -0
  224. package/dist/i18n/acceptLanguage.d.ts.map +1 -0
  225. package/dist/i18n/acceptLanguage.js +55 -0
  226. package/dist/i18n/catalog.d.ts +39 -0
  227. package/dist/i18n/catalog.d.ts.map +1 -0
  228. package/dist/i18n/catalog.js +57 -0
  229. package/dist/i18n/locale.d.ts +74 -0
  230. package/dist/i18n/locale.d.ts.map +1 -0
  231. package/dist/i18n/locale.js +109 -0
  232. package/dist/i18n/localeMarker.d.ts +29 -0
  233. package/dist/i18n/localeMarker.d.ts.map +1 -0
  234. package/dist/i18n/localeMarker.js +112 -0
  235. package/dist/i18n/match.d.ts +26 -0
  236. package/dist/i18n/match.d.ts.map +1 -0
  237. package/dist/i18n/match.js +88 -0
  238. package/dist/i18n/registry.d.ts +25 -0
  239. package/dist/i18n/registry.d.ts.map +1 -0
  240. package/dist/i18n/registry.js +51 -0
  241. package/dist/i18n/translator.d.ts +107 -0
  242. package/dist/i18n/translator.d.ts.map +1 -0
  243. package/dist/i18n/translator.js +80 -0
  244. package/dist/index.d.ts +32 -0
  245. package/dist/index.d.ts.map +1 -0
  246. package/dist/index.js +17 -0
  247. package/dist/kv/kv.d.ts +166 -0
  248. package/dist/kv/kv.d.ts.map +1 -0
  249. package/dist/kv/kv.js +261 -0
  250. package/dist/kv/namespaces.d.ts +58 -0
  251. package/dist/kv/namespaces.d.ts.map +1 -0
  252. package/dist/kv/namespaces.js +40 -0
  253. package/dist/logger/local.d.ts +41 -0
  254. package/dist/logger/local.d.ts.map +1 -0
  255. package/dist/logger/local.js +45 -0
  256. package/dist/logger/logger.d.ts +56 -0
  257. package/dist/logger/logger.d.ts.map +1 -0
  258. package/dist/logger/logger.js +83 -0
  259. package/dist/logger/record.d.ts +919 -0
  260. package/dist/logger/record.d.ts.map +1 -0
  261. package/dist/logger/record.js +79 -0
  262. package/dist/logger/worker.d.ts +74 -0
  263. package/dist/logger/worker.d.ts.map +1 -0
  264. package/dist/logger/worker.js +54 -0
  265. package/dist/migrations/batch.d.ts +10 -0
  266. package/dist/migrations/batch.d.ts.map +1 -0
  267. package/dist/migrations/batch.js +193 -0
  268. package/dist/migrations/bookkeeping.d.ts +24 -0
  269. package/dist/migrations/bookkeeping.d.ts.map +1 -0
  270. package/dist/migrations/bookkeeping.js +57 -0
  271. package/dist/migrations/owner.d.ts +41 -0
  272. package/dist/migrations/owner.d.ts.map +1 -0
  273. package/dist/migrations/owner.js +105 -0
  274. package/dist/migrations/registry.d.ts +36 -0
  275. package/dist/migrations/registry.d.ts.map +1 -0
  276. package/dist/migrations/registry.js +70 -0
  277. package/dist/migrations/runner.d.ts +67 -0
  278. package/dist/migrations/runner.d.ts.map +1 -0
  279. package/dist/migrations/runner.js +218 -0
  280. package/dist/naming/domains.d.ts +108 -0
  281. package/dist/naming/domains.d.ts.map +1 -0
  282. package/dist/naming/domains.js +156 -0
  283. package/dist/naming/environment.d.ts +118 -0
  284. package/dist/naming/environment.d.ts.map +1 -0
  285. package/dist/naming/environment.js +190 -0
  286. package/dist/naming/feature.d.ts +68 -0
  287. package/dist/naming/feature.d.ts.map +1 -0
  288. package/dist/naming/feature.js +106 -0
  289. package/dist/naming/limits.d.ts +229 -0
  290. package/dist/naming/limits.d.ts.map +1 -0
  291. package/dist/naming/limits.js +187 -0
  292. package/dist/naming/provisionScope.d.ts +91 -0
  293. package/dist/naming/provisionScope.d.ts.map +1 -0
  294. package/dist/naming/provisionScope.js +65 -0
  295. package/dist/naming/resource.d.ts +169 -0
  296. package/dist/naming/resource.d.ts.map +1 -0
  297. package/dist/naming/resource.js +220 -0
  298. package/dist/naming/resourceNames.d.ts +83 -0
  299. package/dist/naming/resourceNames.d.ts.map +1 -0
  300. package/dist/naming/resourceNames.js +102 -0
  301. package/dist/naming/segment.d.ts +29 -0
  302. package/dist/naming/segment.d.ts.map +1 -0
  303. package/dist/naming/segment.js +31 -0
  304. package/dist/projection/asRead.d.ts +72 -0
  305. package/dist/projection/asRead.d.ts.map +1 -0
  306. package/dist/projection/asRead.js +169 -0
  307. package/dist/projection/published.d.ts +95 -0
  308. package/dist/projection/published.d.ts.map +1 -0
  309. package/dist/projection/published.js +114 -0
  310. package/dist/schema/describedness.d.ts +55 -0
  311. package/dist/schema/describedness.d.ts.map +1 -0
  312. package/dist/schema/describedness.js +180 -0
  313. package/dist/seed/compose.d.ts +41 -0
  314. package/dist/seed/compose.d.ts.map +1 -0
  315. package/dist/seed/compose.js +51 -0
  316. package/dist/seed/devLogin.d.ts +50 -0
  317. package/dist/seed/devLogin.d.ts.map +1 -0
  318. package/dist/seed/devLogin.js +52 -0
  319. package/dist/seed/exampleIdentities.d.ts +58 -0
  320. package/dist/seed/exampleIdentities.d.ts.map +1 -0
  321. package/dist/seed/exampleIdentities.js +26 -0
  322. package/dist/seed/metadata.d.ts +20 -0
  323. package/dist/seed/metadata.d.ts.map +1 -0
  324. package/dist/seed/metadata.js +27 -0
  325. package/dist/seed/seed.d.ts +264 -0
  326. package/dist/seed/seed.d.ts.map +1 -0
  327. package/dist/seed/seed.js +37 -0
  328. package/dist/seed/seededRows.d.ts +26 -0
  329. package/dist/seed/seededRows.d.ts.map +1 -0
  330. package/dist/seed/seededRows.js +20 -0
  331. package/dist/seed/writeD1.d.ts +43 -0
  332. package/dist/seed/writeD1.d.ts.map +1 -0
  333. package/dist/seed/writeD1.js +73 -0
  334. package/dist/seed/writeKv.d.ts +29 -0
  335. package/dist/seed/writeKv.d.ts.map +1 -0
  336. package/dist/seed/writeKv.js +63 -0
  337. package/dist/semver/semver.d.ts +62 -0
  338. package/dist/semver/semver.d.ts.map +1 -0
  339. package/dist/semver/semver.js +137 -0
  340. package/dist/text/comments.d.ts +62 -0
  341. package/dist/text/comments.d.ts.map +1 -0
  342. package/dist/text/comments.js +161 -0
  343. package/dist/version.generated.d.ts +5 -0
  344. package/dist/version.generated.d.ts.map +1 -0
  345. package/dist/version.generated.js +7 -0
  346. package/dist/worker/health.d.ts +39 -0
  347. package/dist/worker/health.d.ts.map +1 -0
  348. package/dist/worker/health.js +41 -0
  349. package/dist/worker/identity.d.ts +191 -0
  350. package/dist/worker/identity.d.ts.map +1 -0
  351. package/dist/worker/identity.js +162 -0
  352. package/dist/workflow/bindings.d.ts +41 -0
  353. package/dist/workflow/bindings.d.ts.map +1 -0
  354. package/dist/workflow/bindings.js +53 -0
  355. package/dist/workflow/dispatch.d.ts +98 -0
  356. package/dist/workflow/dispatch.d.ts.map +1 -0
  357. package/dist/workflow/dispatch.js +148 -0
  358. package/dist/workflow/dispatchRoute.d.ts +80 -0
  359. package/dist/workflow/dispatchRoute.d.ts.map +1 -0
  360. package/dist/workflow/dispatchRoute.js +134 -0
  361. package/dist/workflow/faults.d.ts +97 -0
  362. package/dist/workflow/faults.d.ts.map +1 -0
  363. package/dist/workflow/faults.js +111 -0
  364. package/dist/workflow/host.d.ts +176 -0
  365. package/dist/workflow/host.d.ts.map +1 -0
  366. package/dist/workflow/host.js +116 -0
  367. package/dist/workflow/hostEntry.d.ts +50 -0
  368. package/dist/workflow/hostEntry.d.ts.map +1 -0
  369. package/dist/workflow/hostEntry.js +24 -0
  370. package/dist/workflow/hostEnv.d.ts +143 -0
  371. package/dist/workflow/hostEnv.d.ts.map +1 -0
  372. package/dist/workflow/hostEnv.js +170 -0
  373. package/dist/workflow/loopback.d.ts +52 -0
  374. package/dist/workflow/loopback.d.ts.map +1 -0
  375. package/dist/workflow/loopback.js +76 -0
  376. package/dist/workflow/naming.d.ts +79 -0
  377. package/dist/workflow/naming.d.ts.map +1 -0
  378. package/dist/workflow/naming.js +138 -0
  379. package/dist/workflow/register.d.ts +19 -0
  380. package/dist/workflow/register.d.ts.map +1 -0
  381. package/dist/workflow/register.js +40 -0
  382. package/dist/workflow/schemas.d.ts +44 -0
  383. package/dist/workflow/schemas.d.ts.map +1 -0
  384. package/dist/workflow/schemas.js +43 -0
  385. package/dist/workflow/spec.d.ts +81 -0
  386. package/dist/workflow/spec.d.ts.map +1 -0
  387. package/dist/workflow/spec.js +0 -0
  388. package/dist/workflow/stepMessage.d.ts +122 -0
  389. package/dist/workflow/stepMessage.d.ts.map +1 -0
  390. package/dist/workflow/stepMessage.js +152 -0
  391. package/package.json +20 -9
  392. package/src/capability/manifest.ts +21 -0
  393. package/src/version.generated.ts +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/logger/record.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;GAKG;AAEH,4GAA4G;AAC5G,eAAO,MAAM,QAAQ;;;;;EAE4F,CAAC;AAClH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEjD;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAgD,CAAC;AAEtG;;;;GAIG;AACH,eAAO,MAAM,SAAS,wCAEsF,CAAC;AAC7G,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAW+E,CAAC;AACtG,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC;AAmBnD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAMzD"}
@@ -0,0 +1,79 @@
1
+ import { ErrorPayload } from "../error/payload.js";
2
+ import { z } from "zod";
3
+ //#region src/logger/record.ts
4
+ /**
5
+ * The logger object model. A log call is a **record**, not a formatted line — `{ level, msg, ...fields }`
6
+ * — so both adapters (local diagnostics, CF-native) serialize the same structured shape rather than
7
+ * re-parsing text. The schema IS the documentation: every field carries a `.describe()`, like any other
8
+ * Pithy boundary. Log copy follows the brand voice — the `msg` is one pithy line; data lives in `fields`.
9
+ */
10
+ /** The four severities, low to high. `debug` is dev diagnostics; `error` is a failure that was observed. */
11
+ const LogLevel = z.enum([
12
+ "debug",
13
+ "info",
14
+ "warn",
15
+ "error"
16
+ ]).describe("Log severity, low to high: `debug` < `info` < `warn` < `error`. The threshold a logger filters on.");
17
+ /**
18
+ * Numeric rank per level, for threshold filtering — a logger drops any record ranked below its level.
19
+ * Not a schema (it is a lookup table), so the meta-test that polices `.describe()` skips it.
20
+ */
21
+ const LOG_LEVEL_ORDER = {
22
+ debug: 10,
23
+ info: 20,
24
+ warn: 30,
25
+ error: 40
26
+ };
27
+ /**
28
+ * Structured fields carried on a record — the data half of a log. Arbitrary JSON-ish values keyed by
29
+ * name (`{ userId, elapsed, request }`); an adapter renders or serializes them. The reserved key
30
+ * `error` may carry a `PithyError` or `ErrorPayload`; the engine lifts it into {@link LogRecord.error}.
31
+ */
32
+ const LogFields = z.record(z.string(), z.unknown()).describe("Structured, arbitrary fields carried on a log record — the queryable data half of a log call.");
33
+ /**
34
+ * One finished log record — what an adapter's sink receives. This is the on-the-wire structured shape
35
+ * CF Workers Logs indexes per line and the local adapter renders. `error` carries the **full**
36
+ * `ErrorPayload` including `detail`: a log is an internal surface (the same side of the boundary as
37
+ * audit `detail`), the inverse of the HTTP codec which strips it. A logger is never wired to a client.
38
+ */
39
+ const LogRecord = z.object({
40
+ level: LogLevel.describe("The severity of this record."),
41
+ msg: z.string().describe("The one-line, brand-voice message. No data — data lives in `fields`."),
42
+ time: z.number().int().describe("When the record was made, as a millisecond epoch."),
43
+ name: z.string().nullish().describe("The emitting logger's namespace (from `child(name)`), if any."),
44
+ fields: LogFields.nullish().describe("Structured fields carried on this record, if any were supplied."),
45
+ error: ErrorPayload.nullish().describe("The full error payload — `detail` included — when the call carried a PithyError. Internal only.")
46
+ }).describe("One structured log record: an adapter's sink serializes or renders exactly this shape.");
47
+ /**
48
+ * A JSON replacer that keeps serialization total: `BigInt` becomes a string, and a repeated object
49
+ * reference (a cycle) becomes `"[Circular]"`. A logger must never throw — an unserializable field in a
50
+ * log call must not crash the caller — so both adapters serialize through {@link serializeRecord}.
51
+ */
52
+ function safeReplacer() {
53
+ const seen = /* @__PURE__ */ new WeakSet();
54
+ return (_key, value) => {
55
+ if (typeof value === "bigint") return value.toString();
56
+ if (typeof value === "object" && value !== null) {
57
+ if (seen.has(value)) return "[Circular]";
58
+ seen.add(value);
59
+ }
60
+ return value;
61
+ };
62
+ }
63
+ /**
64
+ * Serialize a record to one JSON line, tolerating cycles and `BigInt` so a log call is crash-proof. If
65
+ * even the safe pass fails, fall back to the always-serializable core fields — never throw.
66
+ */
67
+ function serializeRecord(record) {
68
+ try {
69
+ return JSON.stringify(record, safeReplacer());
70
+ } catch {
71
+ return JSON.stringify({
72
+ level: record.level,
73
+ msg: record.msg,
74
+ time: record.time
75
+ });
76
+ }
77
+ }
78
+ //#endregion
79
+ export { LOG_LEVEL_ORDER, LogFields, LogLevel, LogRecord, serializeRecord };
@@ -0,0 +1,74 @@
1
+ import { type Logger } from "./logger";
2
+ import type { LogFields, LogLevel, LogRecord } from "./record";
3
+ /**
4
+ * Mode 2 — CF-native structured logs, for a deployed Worker. Each log emits as **one per-line
5
+ * structured record** Cloudflare Workers Logs indexes and can query — not one buried per-request blob.
6
+ * With `observability.enabled` on in the generated `wrangler.jsonc`, these are queryable in the
7
+ * dashboard with zero adopter setup. The `transport` hook fans the same records to a tail-consumer
8
+ * Worker or Logpush without touching any call site.
9
+ */
10
+ /** Options for {@link createWorkerLogger}. */
11
+ export interface WorkerLoggerOptions {
12
+ /** The threshold. Defaults to `info` — a deployed Worker is quieter than local dev. */
13
+ level?: LogLevel;
14
+ /**
15
+ * The tail/Logpush plug point: called with every finished record after it is emitted, so records can
16
+ * fan to a tail-consumer or Logpush unchanged. Enabling it changes no log call site.
17
+ */
18
+ transport?: (record: LogRecord) => void;
19
+ /**
20
+ * How a record reaches Workers Logs. Defaults to a single crash-proof JSON line via `console.log`,
21
+ * which Workers Logs indexes as structured JSON. Injectable for tests.
22
+ */
23
+ emit?: (record: LogRecord) => void;
24
+ /** Fields bound onto every record (e.g. `env`, `version`). */
25
+ fields?: LogFields;
26
+ /** A starting namespace. */
27
+ name?: string;
28
+ /** The clock, injectable for tests. */
29
+ now?: () => number;
30
+ }
31
+ /**
32
+ * Build a Mode 2 CF-native logger. The sink emits one structured line to Workers Logs, then hands the
33
+ * same record to `transport` when one is configured. The record shape is unchanged whether or not a
34
+ * transport is attached — tail/Logpush readiness is by construction.
35
+ */
36
+ export declare function createWorkerLogger(options?: WorkerLoggerOptions): Logger;
37
+ /** The per-request correlation fields bound onto every Worker-side record. Resolved from the request. */
38
+ export interface RequestContext {
39
+ /** A stable id for this request (the CF ray id, or a generated uuid). */
40
+ request: string;
41
+ /** The HTTP method. */
42
+ method: string;
43
+ /** The request path. */
44
+ path: string;
45
+ /** The environment name (`dev` | `staging` | `production`), from config. */
46
+ env: string;
47
+ /** The deployed Worker version id, when the version-metadata binding is present. */
48
+ version?: string;
49
+ }
50
+ /**
51
+ * Derive a per-request logger by binding {@link RequestContext} onto `base` — so every record the
52
+ * handler emits auto-carries `request`/`method`/`path`/`env`/`version` with no caller effort. Uses the
53
+ * nameless `child` form, leaving the logger's namespace free for a capability to claim.
54
+ */
55
+ export declare function bindRequestContext(base: Logger, context: RequestContext): Logger;
56
+ /** The per-run correlation fields bound onto every record a Workflow emits. Resolved from the run's event and env. */
57
+ export interface WorkflowContext {
58
+ /** The deployed Workflow name, from `event.workflowName`. */
59
+ workflow: string;
60
+ /** This run's instance id, from `event.instanceId` — what the dashboard and `wrangler workflows` key on. */
61
+ instance: string;
62
+ /** The environment name (`dev` | `staging` | `prod`), from the host's `ENVIRONMENT` var. */
63
+ env: string;
64
+ /** The deployed Worker version id, when the version-metadata binding is present. */
65
+ version?: string;
66
+ }
67
+ /**
68
+ * Derive a per-run logger by binding {@link WorkflowContext} onto `base` — the Workflow peer of
69
+ * {@link bindRequestContext}, so a durable run correlates the way a request already does. A run has no
70
+ * method or path; it has an instance, and that is the id anyone reading Workflows Logs searches by. Uses
71
+ * the nameless `child` form, leaving the logger's namespace free for a capability to claim.
72
+ */
73
+ export declare function bindWorkflowContext(base: Logger, context: WorkflowContext): Logger;
74
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/logger/worker.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG/D;;;;;;GAMG;AAEH,8CAA8C;AAC9C,MAAM,WAAW,mBAAmB;IAClC,uFAAuF;IACvF,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC;;;OAGG;IACH,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;IACnC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAgB5E;AAED,yGAAyG;AACzG,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,GAAG,EAAE,MAAM,CAAC;IACZ,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM,CAShF;AAED,sHAAsH;AACtH,MAAM,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,4GAA4G;IAC5G,QAAQ,EAAE,MAAM,CAAC;IACjB,4FAA4F;IAC5F,GAAG,EAAE,MAAM,CAAC;IACZ,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAQlF"}
@@ -0,0 +1,54 @@
1
+ import { serializeRecord } from "./record.js";
2
+ import { createLogger } from "./logger.js";
3
+ //#region src/logger/worker.ts
4
+ /**
5
+ * Build a Mode 2 CF-native logger. The sink emits one structured line to Workers Logs, then hands the
6
+ * same record to `transport` when one is configured. The record shape is unchanged whether or not a
7
+ * transport is attached — tail/Logpush readiness is by construction.
8
+ */
9
+ function createWorkerLogger(options = {}) {
10
+ const emit = options.emit ?? ((record) => console.log(serializeRecord(record)));
11
+ const { transport } = options;
12
+ return createLogger({
13
+ level: options.level ?? "info",
14
+ name: options.name,
15
+ fields: options.fields,
16
+ now: options.now,
17
+ sink: (record) => {
18
+ emit(record);
19
+ transport?.(record);
20
+ }
21
+ });
22
+ }
23
+ /**
24
+ * Derive a per-request logger by binding {@link RequestContext} onto `base` — so every record the
25
+ * handler emits auto-carries `request`/`method`/`path`/`env`/`version` with no caller effort. Uses the
26
+ * nameless `child` form, leaving the logger's namespace free for a capability to claim.
27
+ */
28
+ function bindRequestContext(base, context) {
29
+ const fields = {
30
+ request: context.request,
31
+ method: context.method,
32
+ path: context.path,
33
+ env: context.env
34
+ };
35
+ if (context.version !== void 0) fields.version = context.version;
36
+ return base.child(void 0, fields);
37
+ }
38
+ /**
39
+ * Derive a per-run logger by binding {@link WorkflowContext} onto `base` — the Workflow peer of
40
+ * {@link bindRequestContext}, so a durable run correlates the way a request already does. A run has no
41
+ * method or path; it has an instance, and that is the id anyone reading Workflows Logs searches by. Uses
42
+ * the nameless `child` form, leaving the logger's namespace free for a capability to claim.
43
+ */
44
+ function bindWorkflowContext(base, context) {
45
+ const fields = {
46
+ workflow: context.workflow,
47
+ instance: context.instance,
48
+ env: context.env
49
+ };
50
+ if (context.version !== void 0) fields.version = context.version;
51
+ return base.child(void 0, fields);
52
+ }
53
+ //#endregion
54
+ export { bindRequestContext, bindWorkflowContext, createWorkerLogger };
@@ -0,0 +1,10 @@
1
+ import type { D1Database } from "@cloudflare/workers-types";
2
+ import type { MigrationProvider } from "kysely/migration";
3
+ /**
4
+ * Wrap a provider so every migration it yields applies and reverses in one round trip each.
5
+ *
6
+ * Applied at the runner's seam rather than inside each capability, so a migration author writes
7
+ * ordinary Kysely and gets this for free — including adopters, who are the ones paying for it.
8
+ */
9
+ export declare function batchedProvider(provider: MigrationProvider, database: D1Database): MigrationProvider;
10
+ //# sourceMappingURL=batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/migrations/batch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,2BAA2B,CAAC;AAGjF,OAAO,KAAK,EAAa,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA4MrE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,iBAAiB,EAAE,QAAQ,EAAE,UAAU,GAAG,iBAAiB,CASpG"}
@@ -0,0 +1,193 @@
1
+ import { D1MigrationDialect } from "./bookkeeping.js";
2
+ import { CamelCasePlugin, Kysely } from "kysely";
3
+ //#region src/migrations/batch.ts
4
+ /**
5
+ * **One round trip per migration, instead of one per statement.**
6
+ *
7
+ * `kysely-d1` executes every compiled query as its own `prepare().bind().all()`, so a capability's
8
+ * `0001_init` — nineteen tables and thirty-eight indexes, composed — cost fifty-seven hops to D1.
9
+ * Measured against a real composed application in the Workers runtime: 1,028ms and 68 round trips to
10
+ * migrate, 2,041ms per drop-and-rebuild. An adopter following the kit's own advice (Workers-runtime
11
+ * tests against real D1, not mocks) pays that once per test that needs a clean database; in
12
+ * `pithy-sh/dashboard` it was 78% of total wall time, and the setup floor it left put ordinary test
13
+ * bodies within reach of the 5,000ms timeout (`pithy-sh/pithy#368`).
14
+ *
15
+ * `d1.batch()` sends many statements in one round trip, in order, in one implicit transaction. A
16
+ * migration's statements are already ordered and already a unit, which is the shape `batch` exists
17
+ * for. So a migration body runs against a Kysely whose driver **queues** its statements and sends
18
+ * them as one batch when the body returns.
19
+ *
20
+ * ## Only DDL is queued, and that is the whole safety argument
21
+ *
22
+ * A queued statement's result is returned to the migration body before the statement has run, so it
23
+ * cannot carry rows, a row count, or an insert id. Rather than document that as a caveat, the queue
24
+ * only takes statements that **have no such result to carry** — `create`/`drop`/`alter` on a table,
25
+ * index, view, schema or type. Everything else — every select, insert, update, delete, and every raw
26
+ * `sql` template, whose shape is not knowable from its node — **flushes the queue and then executes
27
+ * on its own**, exactly as before. Ordering is therefore preserved unconditionally: a read always
28
+ * sees every statement written before it.
29
+ *
30
+ * The consequence worth stating: a migration that interleaves data with DDL is split into several
31
+ * batches, one per run of consecutive DDL. It is still correct and still faster; it is simply not one
32
+ * transaction. Every migration the kit ships is pure DDL and is one batch.
33
+ *
34
+ * ## Failure semantics, which did change
35
+ *
36
+ * Before: a migration failing at its k-th statement left statements 1..k-1 applied, with no ledger
37
+ * row — a half-applied migration, the thing a chain exists to prevent. After: the batch is the unit,
38
+ * so a failure anywhere in it rolls back all of it and the ledger still records nothing. The
39
+ * migration is all-or-nothing.
40
+ *
41
+ * What did **not** change is anything across a migration boundary. Each `up`/`down` builds its own
42
+ * queue and flushes before returning, so no statement of one migration can share a batch with
43
+ * another's, and the ledger row is written by Kysely's `Migrator` on the ordinary path afterwards.
44
+ * A chain that fails at its third migration still has its first two applied and recorded, and the
45
+ * error still names them. Batching across migrations would make a partial chain unrepresentable in
46
+ * the ledger, which is worse than slow.
47
+ */
48
+ /**
49
+ * Compiled-query kinds with no result a migration body could read — the only ones safe to queue.
50
+ * SQLite ignores schemas and types, but the nodes exist and cost nothing to name.
51
+ */
52
+ const QUEUEABLE_KINDS = /* @__PURE__ */ new Set([
53
+ "CreateTableNode",
54
+ "DropTableNode",
55
+ "CreateIndexNode",
56
+ "DropIndexNode",
57
+ "AlterTableNode",
58
+ "CreateViewNode",
59
+ "DropViewNode",
60
+ "CreateSchemaNode",
61
+ "DropSchemaNode",
62
+ "CreateTypeNode",
63
+ "DropTypeNode"
64
+ ]);
65
+ /** Statements waiting for their one round trip. Ordered; flushed as a single `d1.batch()`. */
66
+ var StatementQueue = class {
67
+ #database;
68
+ #pending = [];
69
+ constructor(database) {
70
+ this.#database = database;
71
+ }
72
+ add(query) {
73
+ this.#pending.push(query);
74
+ }
75
+ /**
76
+ * Send everything queued, in order, as one batch — and nothing at all when nothing is queued, so a
77
+ * flush is always safe to call. Cleared before the call, so a failed batch is not retried by a
78
+ * later flush.
79
+ */
80
+ async flush() {
81
+ if (this.#pending.length === 0) return;
82
+ const pending = this.#pending;
83
+ this.#pending = [];
84
+ const statements = pending.map((query) => this.#database.prepare(query.sql).bind(...query.parameters));
85
+ await this.#database.batch(statements);
86
+ }
87
+ };
88
+ /** Queues what it can, and flushes before anything it cannot — see the module note. */
89
+ var QueueingConnection = class {
90
+ #direct;
91
+ #queue;
92
+ constructor(direct, queue) {
93
+ this.#direct = direct;
94
+ this.#queue = queue;
95
+ }
96
+ async executeQuery(query) {
97
+ if (QUEUEABLE_KINDS.has(query.query.kind)) {
98
+ this.#queue.add(query);
99
+ return { rows: [] };
100
+ }
101
+ await this.#queue.flush();
102
+ return this.#direct.executeQuery(query);
103
+ }
104
+ streamQuery(query, chunkSize) {
105
+ return this.#direct.streamQuery(query, chunkSize);
106
+ }
107
+ };
108
+ /** The stock D1 driver, with every connection wrapped in the queue. Transactions stay unsupported. */
109
+ var QueueingDriver = class {
110
+ #inner;
111
+ #queue;
112
+ #inners = /* @__PURE__ */ new WeakMap();
113
+ constructor(inner, queue) {
114
+ this.#inner = inner;
115
+ this.#queue = queue;
116
+ }
117
+ async init() {
118
+ await this.#inner.init();
119
+ }
120
+ async acquireConnection() {
121
+ const inner = await this.#inner.acquireConnection();
122
+ const wrapped = new QueueingConnection(inner, this.#queue);
123
+ this.#inners.set(wrapped, inner);
124
+ return wrapped;
125
+ }
126
+ async beginTransaction(connection, settings) {
127
+ await this.#inner.beginTransaction(this.#unwrap(connection), settings);
128
+ }
129
+ async commitTransaction(connection) {
130
+ await this.#inner.commitTransaction(this.#unwrap(connection));
131
+ }
132
+ async rollbackTransaction(connection) {
133
+ await this.#inner.rollbackTransaction(this.#unwrap(connection));
134
+ }
135
+ async releaseConnection(connection) {
136
+ await this.#inner.releaseConnection(this.#unwrap(connection));
137
+ }
138
+ async destroy() {
139
+ await this.#inner.destroy();
140
+ }
141
+ #unwrap(connection) {
142
+ return this.#inners.get(connection) ?? connection;
143
+ }
144
+ };
145
+ /** Pithy's D1 dialect — same compiler, same `sqlite_master`-only introspector — driving the queue. */
146
+ var QueueingD1Dialect = class extends D1MigrationDialect {
147
+ #queue;
148
+ constructor(database, queue) {
149
+ super({ database });
150
+ this.#queue = queue;
151
+ }
152
+ createDriver() {
153
+ return new QueueingDriver(super.createDriver(), this.#queue);
154
+ }
155
+ };
156
+ /**
157
+ * Run one migration body against a queueing Kysely and send its statements as one batch.
158
+ *
159
+ * The `db` Kysely's `Migrator` would have passed is deliberately not used: it is the instance that
160
+ * also writes the ledger, and the ledger row must stay on the ordinary path so that a failed batch
161
+ * leaves no record of having applied. Same binding, same `CamelCasePlugin`, same dialect — a
162
+ * migration body cannot tell the difference except in how many hops it costs.
163
+ */
164
+ async function batchBody(body, database) {
165
+ const queue = new StatementQueue(database);
166
+ await body(new Kysely({
167
+ dialect: new QueueingD1Dialect(database, queue),
168
+ plugins: [new CamelCasePlugin()]
169
+ }));
170
+ await queue.flush();
171
+ }
172
+ /** One migration, both directions batched. A migration with no `down` still has none. */
173
+ function batchMigration(migration, database) {
174
+ const down = migration.down;
175
+ return {
176
+ up: async () => batchBody((db) => migration.up(db), database),
177
+ ...down ? { down: async () => batchBody((db) => down(db), database) } : {}
178
+ };
179
+ }
180
+ /**
181
+ * Wrap a provider so every migration it yields applies and reverses in one round trip each.
182
+ *
183
+ * Applied at the runner's seam rather than inside each capability, so a migration author writes
184
+ * ordinary Kysely and gets this for free — including adopters, who are the ones paying for it.
185
+ */
186
+ function batchedProvider(provider, database) {
187
+ return { getMigrations: async () => {
188
+ const migrations = await provider.getMigrations();
189
+ return Object.fromEntries(Object.entries(migrations).map(([name, migration]) => [name, batchMigration(migration, database)]));
190
+ } };
191
+ }
192
+ //#endregion
193
+ export { batchedProvider };
@@ -0,0 +1,24 @@
1
+ import type { D1Database } from "@cloudflare/workers-types";
2
+ import type { DatabaseIntrospector } from "kysely";
3
+ import { Kysely } from "kysely";
4
+ import { D1Dialect } from "kysely-d1";
5
+ /**
6
+ * The applied-migration ledger. Renamed off Kysely's `kysely_migration` default: an adopter running
7
+ * their own Kysely migrations on the same D1 would otherwise collide on it (principle 1).
8
+ */
9
+ export declare const MIGRATION_TABLE = "pithy_migrations";
10
+ /** The migration lock, renamed off Kysely's `kysely_migration_lock` default for the same reason. */
11
+ export declare const MIGRATION_LOCK_TABLE = "pithy_migrations_lock";
12
+ /**
13
+ * The owning project's stamp — one row, written by `claimMigrationOwnership`, read by `pithy migrate`
14
+ * before it applies anything. Deliberately *beside* the ledger rather than inside it: it is not a
15
+ * migration, so a rollback or a full reset must not remove it, and no capability has to ship it.
16
+ */
17
+ export declare const MIGRATION_OWNER_TABLE = "pithy_migrations_owner";
18
+ /** The D1 dialect Pithy migrates through: stock kysely-d1, with the `sqlite_master`-only introspector. */
19
+ export declare class D1MigrationDialect extends D1Dialect {
20
+ createIntrospector(db: Kysely<unknown>): DatabaseIntrospector;
21
+ }
22
+ /** A Kysely over one D1 binding, with Pithy's dialect and `CamelCasePlugin` — the one way in. */
23
+ export declare function migrationKysely<DB = unknown>(database: D1Database): Kysely<DB>;
24
+ //# sourceMappingURL=bookkeeping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bookkeeping.d.ts","sourceRoot":"","sources":["../../src/migrations/bookkeeping.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAA0D,MAAM,QAAQ,CAAC;AAC3G,OAAO,EAAmB,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAsBtC;;;GAGG;AACH,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAElD,oGAAoG;AACpG,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAgC9D,0GAA0G;AAC1G,qBAAa,kBAAmB,SAAQ,SAAS;IACtC,kBAAkB,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,oBAAoB,CAErE;CACF;AAED,iGAAiG;AACjG,wBAAgB,eAAe,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC,CAE9E"}
@@ -0,0 +1,57 @@
1
+ import { CamelCasePlugin, Kysely } from "kysely";
2
+ import { D1Dialect } from "kysely-d1";
3
+ //#region src/migrations/bookkeeping.ts
4
+ /**
5
+ * The applied-migration ledger. Renamed off Kysely's `kysely_migration` default: an adopter running
6
+ * their own Kysely migrations on the same D1 would otherwise collide on it (principle 1).
7
+ */
8
+ const MIGRATION_TABLE = "pithy_migrations";
9
+ /** The migration lock, renamed off Kysely's `kysely_migration_lock` default for the same reason. */
10
+ const MIGRATION_LOCK_TABLE = "pithy_migrations_lock";
11
+ /**
12
+ * The owning project's stamp — one row, written by `claimMigrationOwnership`, read by `pithy migrate`
13
+ * before it applies anything. Deliberately *beside* the ledger rather than inside it: it is not a
14
+ * migration, so a rollback or a full reset must not remove it, and no capability has to ship it.
15
+ */
16
+ const MIGRATION_OWNER_TABLE = "pithy_migrations_owner";
17
+ /** Pithy's bookkeeping tables — hidden by the introspector the way Kysely hides its own defaults. */
18
+ const INTERNAL_TABLES = [
19
+ MIGRATION_TABLE,
20
+ MIGRATION_LOCK_TABLE,
21
+ MIGRATION_OWNER_TABLE
22
+ ];
23
+ /** Table names from `sqlite_master` only — no pragma joins, no column metadata. */
24
+ var D1Introspector = class {
25
+ #db;
26
+ constructor(db) {
27
+ this.#db = db;
28
+ }
29
+ async getSchemas() {
30
+ return [];
31
+ }
32
+ async getTables(options = { withInternalKyselyTables: false }) {
33
+ let query = this.#db.selectFrom("sqlite_master").where("type", "in", ["table", "view"]).where("name", "not like", "sqlite_%").select(["name", "type"]).orderBy("name");
34
+ if (!options.withInternalKyselyTables) query = query.where("name", "not in", INTERNAL_TABLES);
35
+ return (await query.execute()).map((row) => ({
36
+ name: row.name,
37
+ isView: row.type === "view",
38
+ isForeign: false,
39
+ columns: []
40
+ }));
41
+ }
42
+ };
43
+ /** The D1 dialect Pithy migrates through: stock kysely-d1, with the `sqlite_master`-only introspector. */
44
+ var D1MigrationDialect = class extends D1Dialect {
45
+ createIntrospector(db) {
46
+ return new D1Introspector(db);
47
+ }
48
+ };
49
+ /** A Kysely over one D1 binding, with Pithy's dialect and `CamelCasePlugin` — the one way in. */
50
+ function migrationKysely(database) {
51
+ return new Kysely({
52
+ dialect: new D1MigrationDialect({ database }),
53
+ plugins: [new CamelCasePlugin()]
54
+ });
55
+ }
56
+ //#endregion
57
+ export { D1MigrationDialect, MIGRATION_LOCK_TABLE, MIGRATION_OWNER_TABLE, MIGRATION_TABLE, migrationKysely };
@@ -0,0 +1,41 @@
1
+ import type { D1Database } from "@cloudflare/workers-types";
2
+ import { z } from "zod";
3
+ /** The recorded owner of a database: who stamped it, and when. */
4
+ export declare const MigrationOwner: z.ZodObject<{
5
+ project: z.ZodString;
6
+ stampedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
7
+ }, z.core.$strip>;
8
+ export type MigrationOwner = z.output<typeof MigrationOwner>;
9
+ /** How a claim resolved: the database had no owner, or it already had this one. */
10
+ export type OwnershipOutcome = "adopted" | "confirmed";
11
+ /** The result of a successful claim — a refused one throws instead. */
12
+ export interface ProjectOwnership {
13
+ /** The claiming project, which is now (or already was) the recorded owner. */
14
+ project: string;
15
+ /** `adopted` on the first migrate of a database, `confirmed` on every run after it. */
16
+ outcome: OwnershipOutcome;
17
+ /** When the owner was first recorded — the original stamp, not this run. */
18
+ stampedAt: Date;
19
+ }
20
+ /** Who is claiming, and how to name the database if the claim is refused. */
21
+ export interface ClaimOwnershipOptions {
22
+ /** The claiming project — the root `pithy.config.ts` `name`, kebab-cased (`requireProjectName`). */
23
+ project: string;
24
+ /** The binding this database is reached by (`DB`), so a refusal names it. Optional. */
25
+ binding?: string;
26
+ }
27
+ /**
28
+ * The project recorded as this database's owner, or `undefined` when none is — read-only, creating
29
+ * nothing. `pithy doctor` and any other reporter reads the stamp through this; only
30
+ * {@link claimMigrationOwnership} writes it.
31
+ */
32
+ export declare function readMigrationOwner(database: D1Database): Promise<MigrationOwner | undefined>;
33
+ /**
34
+ * Claim a database for a project, or refuse it to a foreign one. Idempotent and safe to re-run: an
35
+ * unstamped database is adopted (nothing has shipped, so a first run has no ambiguity to preserve),
36
+ * the owning project re-claims as a no-op, and any other project throws a `core/conflict` naming both
37
+ * projects. The insert is `on conflict do nothing` against a fixed primary key and is followed by a
38
+ * re-read, so two runs racing the very first claim settle on one owner rather than two rows.
39
+ */
40
+ export declare function claimMigrationOwnership(database: D1Database, options: ClaimOwnershipOptions): Promise<ProjectOwnership>;
41
+ //# sourceMappingURL=owner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner.d.ts","sourceRoot":"","sources":["../../src/migrations/owner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA2BxB,kEAAkE;AAClE,eAAO,MAAM,cAAc;;;iBAOuF,CAAC;AACnH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAa7D,mFAAmF;AACnF,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,WAAW,CAAC;AAEvD,uEAAuE;AACvE,MAAM,WAAW,gBAAgB;IAC/B,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAC;IAChB,uFAAuF;IACvF,OAAO,EAAE,gBAAgB,CAAC;IAC1B,4EAA4E;IAC5E,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,6EAA6E;AAC7E,MAAM,WAAW,qBAAqB;IACpC,oGAAoG;IACpG,OAAO,EAAE,MAAM,CAAC;IAChB,uFAAuF;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA8BD;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAElG;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,gBAAgB,CAAC,CA0C3B"}