@pithy-sh/core 0.9.0 → 0.11.0

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 (298) hide show
  1. package/dist/access/access.d.ts +172 -0
  2. package/dist/access/access.d.ts.map +1 -0
  3. package/dist/access/access.js +147 -0
  4. package/dist/access/acting.d.ts +49 -0
  5. package/dist/access/acting.d.ts.map +1 -0
  6. package/dist/access/acting.js +21 -0
  7. package/dist/access/policyCheck.d.ts +33 -0
  8. package/dist/access/policyCheck.d.ts.map +1 -0
  9. package/dist/access/policyCheck.js +48 -0
  10. package/dist/access/usage.d.ts +83 -0
  11. package/dist/access/usage.d.ts.map +1 -0
  12. package/dist/access/usage.js +104 -0
  13. package/dist/access/visibility.d.ts +66 -0
  14. package/dist/access/visibility.d.ts.map +1 -0
  15. package/dist/access/visibility.js +86 -0
  16. package/dist/asyncapi/document.d.ts +46 -0
  17. package/dist/asyncapi/document.d.ts.map +1 -0
  18. package/dist/asyncapi/document.js +115 -0
  19. package/dist/audit/auditEvent.d.ts +5 -0
  20. package/dist/audit/auditEvent.d.ts.map +1 -1
  21. package/dist/audit/auditEvent.js +2 -0
  22. package/dist/capability/bindings.d.ts +47 -2
  23. package/dist/capability/bindings.d.ts.map +1 -1
  24. package/dist/capability/bindings.js +117 -7
  25. package/dist/capability/capability.d.ts +105 -28
  26. package/dist/capability/capability.d.ts.map +1 -1
  27. package/dist/capability/composition.d.ts.map +1 -1
  28. package/dist/capability/composition.js +5 -1
  29. package/dist/capability/manifest.d.ts +2 -1
  30. package/dist/capability/manifest.d.ts.map +1 -1
  31. package/dist/capability/manifest.js +1 -1
  32. package/dist/capability/settings.d.ts +96 -4
  33. package/dist/capability/settings.d.ts.map +1 -1
  34. package/dist/capability/settings.js +85 -4
  35. package/dist/cli/command.d.ts +364 -0
  36. package/dist/cli/command.d.ts.map +1 -0
  37. package/dist/cli/command.js +418 -0
  38. package/dist/cli/commandCatalog.generated.d.ts +2437 -0
  39. package/dist/cli/commandCatalog.generated.d.ts.map +1 -0
  40. package/dist/cli/commandCatalog.generated.js +2564 -0
  41. package/dist/cli/commandFacts.d.ts +164 -0
  42. package/dist/cli/commandFacts.d.ts.map +1 -0
  43. package/dist/cli/commandFacts.js +216 -0
  44. package/dist/controlPlane/capability.d.ts.map +1 -1
  45. package/dist/controlPlane/capability.js +12 -2
  46. package/dist/controlPlane/context.d.ts +5 -0
  47. package/dist/controlPlane/context.d.ts.map +1 -1
  48. package/dist/controlPlane/context.js +3 -1
  49. package/dist/controlPlane/data/connection.d.ts +47 -0
  50. package/dist/controlPlane/data/connection.d.ts.map +1 -1
  51. package/dist/controlPlane/data/connection.js +55 -1
  52. package/dist/controlPlane/error/errors.d.ts.map +1 -1
  53. package/dist/controlPlane/error/errors.js +4 -3
  54. package/dist/controlPlane/http/cors.d.ts +4 -4
  55. package/dist/controlPlane/http/cors.js +4 -4
  56. package/dist/controlPlane/http/guard.d.ts +11 -0
  57. package/dist/controlPlane/http/guard.d.ts.map +1 -1
  58. package/dist/controlPlane/http/guard.js +28 -2
  59. package/dist/controlPlane/http/handlers.d.ts +60 -0
  60. package/dist/controlPlane/http/handlers.d.ts.map +1 -1
  61. package/dist/controlPlane/http/handlers.js +31 -2
  62. package/dist/controlPlane/http/readiness.d.ts +33 -0
  63. package/dist/controlPlane/http/readiness.d.ts.map +1 -0
  64. package/dist/controlPlane/http/readiness.js +39 -0
  65. package/dist/controlPlane/http/responses.d.ts +147 -0
  66. package/dist/controlPlane/http/responses.d.ts.map +1 -1
  67. package/dist/controlPlane/http/responses.js +61 -4
  68. package/dist/controlPlane/http/routes.d.ts +2 -1
  69. package/dist/controlPlane/http/routes.d.ts.map +1 -1
  70. package/dist/controlPlane/http/routes.js +50 -9
  71. package/dist/controlPlane/http/verify.d.ts.map +1 -1
  72. package/dist/controlPlane/http/verify.js +2 -1
  73. package/dist/controlPlane/migrationState/migrationState.d.ts +102 -0
  74. package/dist/controlPlane/migrationState/migrationState.d.ts.map +1 -0
  75. package/dist/controlPlane/migrationState/migrationState.js +142 -0
  76. package/dist/controlPlane/migrations/0003_connection_principal.d.ts +21 -0
  77. package/dist/controlPlane/migrations/0003_connection_principal.d.ts.map +1 -0
  78. package/dist/controlPlane/migrations/0003_connection_principal.js +33 -0
  79. package/dist/controlPlane/scope/scope.d.ts +13 -2
  80. package/dist/controlPlane/scope/scope.d.ts.map +1 -1
  81. package/dist/controlPlane/scope/scope.js +14 -3
  82. package/dist/createBackend.d.ts +7 -0
  83. package/dist/createBackend.d.ts.map +1 -1
  84. package/dist/createBackend.js +41 -6
  85. package/dist/createEntrypoint.d.ts.map +1 -1
  86. package/dist/createEntrypoint.js +5 -3
  87. package/dist/entitlement/allowance.d.ts +25 -0
  88. package/dist/entitlement/allowance.d.ts.map +1 -0
  89. package/dist/entitlement/allowance.js +80 -0
  90. package/dist/entitlement/entitlement.d.ts +41 -0
  91. package/dist/entitlement/entitlement.d.ts.map +1 -1
  92. package/dist/entitlement/meter.d.ts +57 -0
  93. package/dist/entitlement/meter.d.ts.map +1 -0
  94. package/dist/entitlement/meter.js +13 -0
  95. package/dist/entitlement/require.js +1 -1
  96. package/dist/error/cause.d.ts +16 -116
  97. package/dist/error/cause.d.ts.map +1 -1
  98. package/dist/error/cause.js +19 -153
  99. package/dist/error/http.d.ts +184 -0
  100. package/dist/error/http.d.ts.map +1 -1
  101. package/dist/error/payload.d.ts +368 -0
  102. package/dist/error/payload.d.ts.map +1 -1
  103. package/dist/error/payload.js +126 -4
  104. package/dist/error/pithyError.d.ts +44 -0
  105. package/dist/error/pithyError.d.ts.map +1 -1
  106. package/dist/error/pithyError.js +56 -1
  107. package/dist/error/unresolved.d.ts +265 -0
  108. package/dist/error/unresolved.d.ts.map +1 -0
  109. package/dist/error/unresolved.js +599 -0
  110. package/dist/error/wire.d.ts +20 -0
  111. package/dist/error/wire.d.ts.map +1 -0
  112. package/dist/error/wire.js +19 -0
  113. package/dist/http/authContext.d.ts +7 -0
  114. package/dist/http/authContext.d.ts.map +1 -1
  115. package/dist/http/authContext.js +8 -1
  116. package/dist/http/oidcWebhook.d.ts +3 -3
  117. package/dist/http/oidcWebhook.js +3 -3
  118. package/dist/http/routeContract.js +1 -1
  119. package/dist/http/routeSpec.d.ts +66 -0
  120. package/dist/http/routeSpec.d.ts.map +1 -0
  121. package/dist/http/routeSpec.js +40 -0
  122. package/dist/http/sameOrigin.d.ts +1 -1
  123. package/dist/http/sameOrigin.js +1 -1
  124. package/dist/http/scopeGates.d.ts +20 -0
  125. package/dist/http/scopeGates.d.ts.map +1 -0
  126. package/dist/http/scopeGates.js +36 -0
  127. package/dist/http/signedWebhook.d.ts +3 -3
  128. package/dist/http/signedWebhook.js +3 -3
  129. package/dist/http/socket.d.ts +52 -0
  130. package/dist/http/socket.d.ts.map +1 -0
  131. package/dist/http/socket.js +2 -0
  132. package/dist/http/subprotocol.d.ts +29 -0
  133. package/dist/http/subprotocol.d.ts.map +1 -0
  134. package/dist/http/subprotocol.js +37 -0
  135. package/dist/http/validation.d.ts +40 -8
  136. package/dist/http/validation.d.ts.map +1 -1
  137. package/dist/http/validation.js +25 -1
  138. package/dist/index.d.ts +1 -1
  139. package/dist/index.d.ts.map +1 -1
  140. package/dist/index.js +4 -4
  141. package/dist/logger/record.d.ts +107 -0
  142. package/dist/logger/record.d.ts.map +1 -1
  143. package/dist/migrations/bookkeeping.d.ts +21 -0
  144. package/dist/migrations/bookkeeping.d.ts.map +1 -1
  145. package/dist/migrations/bookkeeping.js +32 -3
  146. package/dist/migrations/capabilitySets.d.ts +23 -0
  147. package/dist/migrations/capabilitySets.d.ts.map +1 -0
  148. package/dist/migrations/capabilitySets.js +74 -0
  149. package/dist/migrations/groups.d.ts +140 -0
  150. package/dist/migrations/groups.d.ts.map +1 -0
  151. package/dist/migrations/groups.js +191 -0
  152. package/dist/migrations/migrateStep.d.ts +13 -0
  153. package/dist/migrations/migrateStep.d.ts.map +1 -0
  154. package/dist/migrations/migrateStep.js +20 -0
  155. package/dist/migrations/owner.d.ts +7 -0
  156. package/dist/migrations/owner.d.ts.map +1 -1
  157. package/dist/migrations/owner.js +11 -7
  158. package/dist/migrations/registry.d.ts +26 -0
  159. package/dist/migrations/registry.d.ts.map +1 -1
  160. package/dist/migrations/registry.js +38 -7
  161. package/dist/migrations/retained.js +2 -2
  162. package/dist/migrations/runner.d.ts +76 -5
  163. package/dist/migrations/runner.d.ts.map +1 -1
  164. package/dist/migrations/runner.js +130 -19
  165. package/dist/migrations/state.d.ts +60 -0
  166. package/dist/migrations/state.d.ts.map +1 -0
  167. package/dist/migrations/state.js +46 -0
  168. package/dist/naming/domains.d.ts +17 -0
  169. package/dist/naming/domains.d.ts.map +1 -1
  170. package/dist/naming/domains.js +62 -4
  171. package/dist/naming/environment.d.ts.map +1 -1
  172. package/dist/naming/environment.js +2 -1
  173. package/dist/naming/feature.d.ts +27 -5
  174. package/dist/naming/feature.d.ts.map +1 -1
  175. package/dist/naming/feature.js +36 -6
  176. package/dist/naming/limits.d.ts +47 -3
  177. package/dist/naming/limits.d.ts.map +1 -1
  178. package/dist/naming/limits.js +47 -3
  179. package/dist/naming/packageName.d.ts +17 -0
  180. package/dist/naming/packageName.d.ts.map +1 -0
  181. package/dist/naming/packageName.js +22 -0
  182. package/dist/naming/provisionScope.d.ts +6 -0
  183. package/dist/naming/provisionScope.d.ts.map +1 -1
  184. package/dist/naming/provisionScope.js +10 -4
  185. package/dist/naming/resourceNames.d.ts +21 -2
  186. package/dist/naming/resourceNames.d.ts.map +1 -1
  187. package/dist/naming/resourceNames.js +21 -3
  188. package/dist/openapi/document.d.ts +106 -0
  189. package/dist/openapi/document.d.ts.map +1 -0
  190. package/dist/openapi/document.js +314 -0
  191. package/dist/openapi/routeGroups.d.ts +8 -0
  192. package/dist/openapi/routeGroups.d.ts.map +1 -0
  193. package/dist/openapi/routeGroups.js +23 -0
  194. package/dist/seed/writeD1.d.ts +7 -1
  195. package/dist/seed/writeD1.d.ts.map +1 -1
  196. package/dist/seed/writeD1.js +9 -3
  197. package/dist/seed/writeKv.d.ts +2 -0
  198. package/dist/seed/writeKv.d.ts.map +1 -1
  199. package/dist/seed/writeKv.js +6 -2
  200. package/dist/text/comments.js +66 -4
  201. package/dist/text/literals.d.ts +43 -0
  202. package/dist/text/literals.d.ts.map +1 -0
  203. package/dist/text/literals.js +293 -0
  204. package/dist/version.generated.d.ts +1 -1
  205. package/dist/version.generated.d.ts.map +1 -1
  206. package/dist/version.generated.js +1 -1
  207. package/dist/worker/serviceLoopback.d.ts +36 -0
  208. package/dist/worker/serviceLoopback.d.ts.map +1 -0
  209. package/dist/worker/serviceLoopback.js +74 -0
  210. package/dist/workflow/dispatchRoute.d.ts.map +1 -1
  211. package/dist/workflow/dispatchRoute.js +12 -6
  212. package/dist/workflow/faults.d.ts +12 -1
  213. package/dist/workflow/faults.d.ts.map +1 -1
  214. package/dist/workflow/faults.js +24 -18
  215. package/dist/workflow/hostEnv.d.ts +1 -0
  216. package/dist/workflow/hostEnv.d.ts.map +1 -1
  217. package/dist/workflow/hostEnv.js +4 -2
  218. package/dist/workflow/loopback.d.ts.map +1 -1
  219. package/dist/workflow/loopback.js +2 -1
  220. package/package.json +4 -4
  221. package/src/access/access.ts +298 -0
  222. package/src/access/acting.ts +59 -0
  223. package/src/access/policyCheck.ts +77 -0
  224. package/src/access/usage.ts +141 -0
  225. package/src/access/visibility.ts +109 -0
  226. package/src/asyncapi/document.ts +164 -0
  227. package/src/audit/auditEvent.ts +4 -0
  228. package/src/capability/bindings.ts +159 -13
  229. package/src/capability/capability.ts +106 -29
  230. package/src/capability/composition.ts +2 -1
  231. package/src/capability/settings.ts +165 -4
  232. package/src/cli/command.ts +865 -0
  233. package/src/cli/commandCatalog.generated.ts +2723 -0
  234. package/src/cli/commandFacts.ts +220 -0
  235. package/src/controlPlane/capability.ts +25 -1
  236. package/src/controlPlane/context.ts +4 -0
  237. package/src/controlPlane/data/connection.ts +90 -0
  238. package/src/controlPlane/error/errors.ts +10 -3
  239. package/src/controlPlane/http/cors.ts +4 -4
  240. package/src/controlPlane/http/guard.ts +35 -2
  241. package/src/controlPlane/http/handlers.ts +41 -0
  242. package/src/controlPlane/http/readiness.ts +50 -0
  243. package/src/controlPlane/http/responses.ts +140 -2
  244. package/src/controlPlane/http/routes.ts +82 -10
  245. package/src/controlPlane/http/verify.ts +2 -0
  246. package/src/controlPlane/migrationState/migrationState.ts +200 -0
  247. package/src/controlPlane/migrations/0003_connection_principal.ts +37 -0
  248. package/src/controlPlane/scope/scope.ts +14 -2
  249. package/src/createBackend.ts +59 -8
  250. package/src/createEntrypoint.ts +9 -3
  251. package/src/entitlement/allowance.ts +85 -0
  252. package/src/entitlement/entitlement.ts +38 -0
  253. package/src/entitlement/meter.ts +69 -0
  254. package/src/entitlement/require.ts +1 -1
  255. package/src/error/cause.ts +18 -181
  256. package/src/error/payload.ts +270 -4
  257. package/src/error/pithyError.ts +76 -0
  258. package/src/error/unresolved.ts +853 -0
  259. package/src/error/wire.ts +40 -0
  260. package/src/http/authContext.ts +13 -1
  261. package/src/http/oidcWebhook.ts +3 -3
  262. package/src/http/routeContract.ts +1 -1
  263. package/src/http/routeSpec.ts +81 -0
  264. package/src/http/sameOrigin.ts +1 -1
  265. package/src/http/scopeGates.ts +34 -0
  266. package/src/http/signedWebhook.ts +3 -3
  267. package/src/http/socket.ts +55 -0
  268. package/src/http/subprotocol.ts +47 -0
  269. package/src/http/validation.ts +50 -8
  270. package/src/index.ts +1 -0
  271. package/src/migrations/bookkeeping.ts +39 -2
  272. package/src/migrations/capabilitySets.ts +87 -0
  273. package/src/migrations/groups.ts +295 -0
  274. package/src/migrations/migrateStep.ts +19 -0
  275. package/src/migrations/owner.ts +10 -6
  276. package/src/migrations/registry.ts +46 -2
  277. package/src/migrations/retained.ts +2 -2
  278. package/src/migrations/runner.ts +214 -22
  279. package/src/migrations/state.ts +94 -0
  280. package/src/naming/domains.ts +75 -16
  281. package/src/naming/environment.ts +2 -1
  282. package/src/naming/feature.ts +46 -7
  283. package/src/naming/limits.ts +35 -3
  284. package/src/naming/packageName.ts +20 -0
  285. package/src/naming/provisionScope.ts +21 -2
  286. package/src/naming/resourceNames.ts +52 -5
  287. package/src/openapi/document.ts +412 -0
  288. package/src/openapi/routeGroups.ts +25 -0
  289. package/src/seed/writeD1.ts +13 -4
  290. package/src/seed/writeKv.ts +6 -2
  291. package/src/text/comments.ts +56 -4
  292. package/src/text/literals.ts +294 -0
  293. package/src/version.generated.ts +1 -1
  294. package/src/worker/serviceLoopback.ts +105 -0
  295. package/src/workflow/dispatchRoute.ts +13 -6
  296. package/src/workflow/faults.ts +56 -27
  297. package/src/workflow/hostEnv.ts +9 -1
  298. package/src/workflow/loopback.ts +2 -1
@@ -56,6 +56,29 @@ export declare const LogRecord: z.ZodObject<{
56
56
  message: z.ZodString;
57
57
  code: z.ZodString;
58
58
  }, z.core.$strip>>;
59
+ }, z.core.$strip>, z.ZodObject<{
60
+ message: z.ZodString;
61
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
62
+ action: z.ZodOptional<z.ZodString>;
63
+ detail: z.ZodOptional<z.ZodString>;
64
+ code: z.ZodLiteral<"input/required">;
65
+ status: z.ZodLiteral<400>;
66
+ flag: z.ZodNullable<z.ZodString>;
67
+ choices: z.ZodOptional<z.ZodArray<z.ZodString>>;
68
+ }, z.core.$strip>, z.ZodObject<{
69
+ message: z.ZodString;
70
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
71
+ action: z.ZodOptional<z.ZodString>;
72
+ detail: z.ZodOptional<z.ZodString>;
73
+ code: z.ZodLiteral<"core/precondition_failed">;
74
+ status: z.ZodLiteral<412>;
75
+ }, z.core.$strip>, z.ZodObject<{
76
+ message: z.ZodString;
77
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
78
+ action: z.ZodOptional<z.ZodString>;
79
+ detail: z.ZodOptional<z.ZodString>;
80
+ code: z.ZodLiteral<"core/person_required">;
81
+ status: z.ZodLiteral<403>;
59
82
  }, z.core.$strip>, z.ZodObject<{
60
83
  message: z.ZodString;
61
84
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -287,6 +310,20 @@ export declare const LogRecord: z.ZodObject<{
287
310
  detail: z.ZodOptional<z.ZodString>;
288
311
  code: z.ZodLiteral<"turnstile/config">;
289
312
  status: z.ZodLiteral<500>;
313
+ }, z.core.$strip>, z.ZodObject<{
314
+ message: z.ZodString;
315
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
316
+ action: z.ZodOptional<z.ZodString>;
317
+ detail: z.ZodOptional<z.ZodString>;
318
+ code: z.ZodLiteral<"turnstile/analytics_window">;
319
+ status: z.ZodLiteral<400>;
320
+ }, z.core.$strip>, z.ZodObject<{
321
+ message: z.ZodString;
322
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
323
+ action: z.ZodOptional<z.ZodString>;
324
+ detail: z.ZodOptional<z.ZodString>;
325
+ code: z.ZodLiteral<"turnstile/analytics_unavailable">;
326
+ status: z.ZodLiteral<409>;
290
327
  }, z.core.$strip>, z.ZodObject<{
291
328
  message: z.ZodString;
292
329
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -308,6 +345,13 @@ export declare const LogRecord: z.ZodObject<{
308
345
  detail: z.ZodOptional<z.ZodString>;
309
346
  code: z.ZodLiteral<"media/not_found">;
310
347
  status: z.ZodLiteral<404>;
348
+ }, z.core.$strip>, z.ZodObject<{
349
+ message: z.ZodString;
350
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
351
+ action: z.ZodOptional<z.ZodString>;
352
+ detail: z.ZodOptional<z.ZodString>;
353
+ code: z.ZodLiteral<"media/forbidden">;
354
+ status: z.ZodLiteral<403>;
311
355
  }, z.core.$strip>, z.ZodObject<{
312
356
  message: z.ZodString;
313
357
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -329,6 +373,20 @@ export declare const LogRecord: z.ZodObject<{
329
373
  detail: z.ZodOptional<z.ZodString>;
330
374
  code: z.ZodLiteral<"media/enrichment_failed">;
331
375
  status: z.ZodLiteral<500>;
376
+ }, z.core.$strip>, z.ZodObject<{
377
+ message: z.ZodString;
378
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
379
+ action: z.ZodOptional<z.ZodString>;
380
+ detail: z.ZodOptional<z.ZodString>;
381
+ code: z.ZodLiteral<"media/analytics_window">;
382
+ status: z.ZodLiteral<400>;
383
+ }, z.core.$strip>, z.ZodObject<{
384
+ message: z.ZodString;
385
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
386
+ action: z.ZodOptional<z.ZodString>;
387
+ detail: z.ZodOptional<z.ZodString>;
388
+ code: z.ZodLiteral<"media/analytics_unavailable">;
389
+ status: z.ZodLiteral<409>;
332
390
  }, z.core.$strip>, z.ZodObject<{
333
391
  message: z.ZodString;
334
392
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -763,6 +821,20 @@ export declare const LogRecord: z.ZodObject<{
763
821
  detail: z.ZodOptional<z.ZodString>;
764
822
  code: z.ZodLiteral<"payments/subscription_change_refused">;
765
823
  status: z.ZodLiteral<409>;
824
+ }, z.core.$strip>, z.ZodObject<{
825
+ message: z.ZodString;
826
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
827
+ action: z.ZodOptional<z.ZodString>;
828
+ detail: z.ZodOptional<z.ZodString>;
829
+ code: z.ZodLiteral<"payments/override_stale">;
830
+ status: z.ZodLiteral<409>;
831
+ }, z.core.$strip>, z.ZodObject<{
832
+ message: z.ZodString;
833
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
834
+ action: z.ZodOptional<z.ZodString>;
835
+ detail: z.ZodOptional<z.ZodString>;
836
+ code: z.ZodLiteral<"payments/quota_exceeded">;
837
+ status: z.ZodLiteral<402>;
766
838
  }, z.core.$strip>, z.ZodObject<{
767
839
  message: z.ZodString;
768
840
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -847,6 +919,41 @@ export declare const LogRecord: z.ZodObject<{
847
919
  detail: z.ZodOptional<z.ZodString>;
848
920
  code: z.ZodLiteral<"organization/nomination_invalid">;
849
921
  status: z.ZodLiteral<400>;
922
+ }, z.core.$strip>, z.ZodObject<{
923
+ message: z.ZodString;
924
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
925
+ action: z.ZodOptional<z.ZodString>;
926
+ detail: z.ZodOptional<z.ZodString>;
927
+ code: z.ZodLiteral<"artifacts/not_found">;
928
+ status: z.ZodLiteral<404>;
929
+ }, z.core.$strip>, z.ZodObject<{
930
+ message: z.ZodString;
931
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
932
+ action: z.ZodOptional<z.ZodString>;
933
+ detail: z.ZodOptional<z.ZodString>;
934
+ code: z.ZodLiteral<"artifacts/forbidden">;
935
+ status: z.ZodLiteral<403>;
936
+ }, z.core.$strip>, z.ZodObject<{
937
+ message: z.ZodString;
938
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
939
+ action: z.ZodOptional<z.ZodString>;
940
+ detail: z.ZodOptional<z.ZodString>;
941
+ code: z.ZodLiteral<"artifacts/invalid_name">;
942
+ status: z.ZodLiteral<400>;
943
+ }, z.core.$strip>, z.ZodObject<{
944
+ message: z.ZodString;
945
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
946
+ action: z.ZodOptional<z.ZodString>;
947
+ detail: z.ZodOptional<z.ZodString>;
948
+ code: z.ZodLiteral<"artifacts/name_taken">;
949
+ status: z.ZodLiteral<409>;
950
+ }, z.core.$strip>, z.ZodObject<{
951
+ message: z.ZodString;
952
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
953
+ action: z.ZodOptional<z.ZodString>;
954
+ detail: z.ZodOptional<z.ZodString>;
955
+ code: z.ZodLiteral<"artifacts/invalid_config">;
956
+ status: z.ZodLiteral<400>;
850
957
  }, z.core.$strip>, z.ZodObject<{
851
958
  message: z.ZodString;
852
959
  params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
@@ -1 +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;AA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capability has to ship it.
18
18
  */
19
19
  export declare const MIGRATION_OWNER_TABLE = "pithy_migrations_owner";
20
+ /**
21
+ * Which run applied each migration — one row per applied migration, written by the runner from the
22
+ * `MigrationResult[]` Kysely hands back (`./groups`). Beside the ledger for the same reason the owner
23
+ * stamp is: Kysely creates `pithy_migrations` and its insert sets `name` and `timestamp` only, so there
24
+ * is nowhere in it to put a group — and a group is not a migration, so a rollback or a full reset must
25
+ * not remove the table. A reversed group's own rows go; the table stays.
26
+ */
27
+ export declare const MIGRATION_GROUP_TABLE = "pithy_migrations_groups";
20
28
  /** The D1 dialect Pithy migrates through: stock kysely-d1, with the `sqlite_master`-only introspector. */
21
29
  export declare class D1MigrationDialect extends D1Dialect {
22
30
  createIntrospector(db: Kysely<unknown>): DatabaseIntrospector;
23
31
  }
24
32
  /** A Kysely over one D1 binding, with Pithy's dialect and `CamelCasePlugin` — the one way in. */
25
33
  export declare function migrationKysely<DB = unknown>(database: D1Database): Kysely<DB>;
34
+ /**
35
+ * The applied migrations, **in the order Kysely steps down from them** — oldest first, tip last.
36
+ *
37
+ * Kysely's `Migrator` sorts the ledger by `timestamp`, breaks a tie on the name, and reverses that list to
38
+ * decide what the next `migrateDown()` reverses. So anything that asks *is this the top of the chain* has
39
+ * to read the same order: concluding it from the order some other table was written in answers a different
40
+ * question, and the answer only differs in the cases that matter (`./groups`, #694).
41
+ *
42
+ * Empty when the ledger table does not exist — a database nothing has migrated. Existence is checked
43
+ * against `sqlite_master`, a plain select D1 permits, rather than by catching the read's error, so a
44
+ * genuine read failure surfaces instead of being read as "nothing applied".
45
+ */
46
+ export declare function appliedMigrationChain<DB>(db: Kysely<DB>): Promise<string[]>;
26
47
  //# sourceMappingURL=bookkeeping.d.ts.map
@@ -1 +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;AAC5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;CACF;AAED,iGAAiG;AACjG,wBAAgB,eAAe,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC,CAE9E;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAcjF"}
@@ -1,6 +1,6 @@
1
1
  // SPDX-FileCopyrightText: 2026 Pithy
2
2
  // SPDX-License-Identifier: MIT
3
- import { CamelCasePlugin, Kysely } from "kysely";
3
+ import { CamelCasePlugin, Kysely, sql } from "kysely";
4
4
  import { D1Dialect } from "kysely-d1";
5
5
  //#region src/migrations/bookkeeping.ts
6
6
  /**
@@ -16,11 +16,20 @@ const MIGRATION_LOCK_TABLE = "pithy_migrations_lock";
16
16
  * migration, so a rollback or a full reset must not remove it, and no capability has to ship it.
17
17
  */
18
18
  const MIGRATION_OWNER_TABLE = "pithy_migrations_owner";
19
+ /**
20
+ * Which run applied each migration — one row per applied migration, written by the runner from the
21
+ * `MigrationResult[]` Kysely hands back (`./groups`). Beside the ledger for the same reason the owner
22
+ * stamp is: Kysely creates `pithy_migrations` and its insert sets `name` and `timestamp` only, so there
23
+ * is nowhere in it to put a group — and a group is not a migration, so a rollback or a full reset must
24
+ * not remove the table. A reversed group's own rows go; the table stays.
25
+ */
26
+ const MIGRATION_GROUP_TABLE = "pithy_migrations_groups";
19
27
  /** Pithy's bookkeeping tables — hidden by the introspector the way Kysely hides its own defaults. */
20
28
  const INTERNAL_TABLES = [
21
29
  MIGRATION_TABLE,
22
30
  MIGRATION_LOCK_TABLE,
23
- MIGRATION_OWNER_TABLE
31
+ MIGRATION_OWNER_TABLE,
32
+ MIGRATION_GROUP_TABLE
24
33
  ];
25
34
  /** Table names from `sqlite_master` only — no pragma joins, no column metadata. */
26
35
  var D1Introspector = class {
@@ -55,5 +64,25 @@ function migrationKysely(database) {
55
64
  plugins: [new CamelCasePlugin()]
56
65
  });
57
66
  }
67
+ /**
68
+ * The applied migrations, **in the order Kysely steps down from them** — oldest first, tip last.
69
+ *
70
+ * Kysely's `Migrator` sorts the ledger by `timestamp`, breaks a tie on the name, and reverses that list to
71
+ * decide what the next `migrateDown()` reverses. So anything that asks *is this the top of the chain* has
72
+ * to read the same order: concluding it from the order some other table was written in answers a different
73
+ * question, and the answer only differs in the cases that matter (`./groups`, #694).
74
+ *
75
+ * Empty when the ledger table does not exist — a database nothing has migrated. Existence is checked
76
+ * against `sqlite_master`, a plain select D1 permits, rather than by catching the read's error, so a
77
+ * genuine read failure surfaces instead of being read as "nothing applied".
78
+ */
79
+ async function appliedMigrationChain(db) {
80
+ if ((await sql`select name from sqlite_master where type = 'table' and name = ${"pithy_migrations"}`.execute(db)).rows.length === 0) return [];
81
+ const { rows } = await sql`select name, timestamp from ${sql.table(MIGRATION_TABLE)}`.execute(db);
82
+ return [...rows].sort((left, right) => {
83
+ const elapsed = new Date(left.timestamp).getTime() - new Date(right.timestamp).getTime();
84
+ return elapsed === 0 ? left.name.localeCompare(right.name) : elapsed;
85
+ }).map((row) => row.name);
86
+ }
58
87
  //#endregion
59
- export { D1MigrationDialect, MIGRATION_LOCK_TABLE, MIGRATION_OWNER_TABLE, MIGRATION_TABLE, migrationKysely };
88
+ export { D1MigrationDialect, MIGRATION_GROUP_TABLE, MIGRATION_LOCK_TABLE, MIGRATION_OWNER_TABLE, MIGRATION_TABLE, appliedMigrationChain, migrationKysely };
@@ -0,0 +1,23 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { MigrationProvider } from "kysely/migration";
4
+ import type { Capability } from "../capability/capability";
5
+ import { type NamespacedMigrations } from "./registry";
6
+ /**
7
+ * Every capability's per-database migration set (`DatabaseSpec.migrations`, namespaced by capability
8
+ * name), in composition order — the raw material {@link buildRegistryFromCapabilities}, the CLI's
9
+ * fan-out runner and the control-plane seam all build on. The runner needs the sets rather than a
10
+ * finished provider because two Workers can be bound to one physical D1: their sets merge into a single
11
+ * ordered provider so that database migrates once, with every Worker's capabilities in it. A Worker
12
+ * composes only its own, which is why the seam's `undeclared` is relative to that Worker. Migrations
13
+ * without a `migrationOrder` fail here, attributed to their capability.
14
+ */
15
+ export declare function collectMigrationSets(capabilities: Capability[]): NamespacedMigrations[];
16
+ /**
17
+ * Compose every capability's per-database migration sets (`DatabaseSpec.migrations`,
18
+ * namespaced by capability name) into one ordered provider per database. A database
19
+ * nobody migrates gets no provider; migrations without a `migrationOrder` fail here,
20
+ * attributed to their capability.
21
+ */
22
+ export declare function buildRegistryFromCapabilities(capabilities: Capability[]): Record<string, MigrationProvider>;
23
+ //# sourceMappingURL=capabilitySets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilitySets.d.ts","sourceRoot":"","sources":["../../src/migrations/capabilitySets.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAA2B,KAAK,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAsChF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,UAAU,EAAE,GAAG,oBAAoB,EAAE,CAsBvF;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAE3G"}
@@ -0,0 +1,74 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import { InternalError } from "../error/pithyError.js";
4
+ import { createMigrationRegistry } from "./registry.js";
5
+ //#region src/migrations/capabilitySets.ts
6
+ /**
7
+ * **Where a capability's migrations become a registry's sets — one function, composed twice (#729).**
8
+ *
9
+ * `pithy migrate` and `pithy doctor` compose these sets from the project on disk; the Worker composes them
10
+ * from the capabilities it was built with, to answer `GET {basePath}/migrations`. It lived in the CLI until
11
+ * the Worker needed it too. It reads nothing but `Capability.databases`, so it belongs in core — and if
12
+ * the two sides composed with two functions, `pithy doctor` and the route could disagree about one
13
+ * environment with nothing to say which was wrong.
14
+ */
15
+ /**
16
+ * A retained declaration must name a table this slice declares, beside the migrations that create it.
17
+ *
18
+ * A misspelled key would count a table that does not exist, find no rows, and let the `down` through —
19
+ * the refusal quietly off for the one table it was written for. And retention on a slice with no
20
+ * migrations has no `down` to be recorded on, so nothing would ever enforce it. Both are an author's mistake,
21
+ * caught where the declaration is read rather than discovered when a vault is empty (#588).
22
+ */
23
+ function assertRetainedDeclared(capability, database, spec) {
24
+ const retained = spec.retained ?? [];
25
+ if (retained.length === 0) return;
26
+ const unknown = retained.filter((table) => !(table in spec.tables));
27
+ if (unknown.length > 0) throw new InternalError({
28
+ message: `Capability "${capability}" retains ${unknown.map((table) => `"${table}"`).join(", ")} in database "${database}", which its tables do not declare.`,
29
+ action: "Name tables from that database spec's tables in retained."
30
+ });
31
+ if (!spec.migrations || Object.keys(spec.migrations).length === 0) throw new InternalError({
32
+ message: `Capability "${capability}" retains tables in database "${database}" but ships no migrations for it.`,
33
+ action: "Declare retained beside the migrations that create those tables."
34
+ });
35
+ }
36
+ /**
37
+ * Every capability's per-database migration set (`DatabaseSpec.migrations`, namespaced by capability
38
+ * name), in composition order — the raw material {@link buildRegistryFromCapabilities}, the CLI's
39
+ * fan-out runner and the control-plane seam all build on. The runner needs the sets rather than a
40
+ * finished provider because two Workers can be bound to one physical D1: their sets merge into a single
41
+ * ordered provider so that database migrates once, with every Worker's capabilities in it. A Worker
42
+ * composes only its own, which is why the seam's `undeclared` is relative to that Worker. Migrations
43
+ * without a `migrationOrder` fail here, attributed to their capability.
44
+ */
45
+ function collectMigrationSets(capabilities) {
46
+ const sets = [];
47
+ for (const capability of capabilities) for (const [database, spec] of Object.entries(capability.databases ?? {})) {
48
+ assertRetainedDeclared(capability.name, database, spec);
49
+ if (!spec.migrations) continue;
50
+ if (spec.migrationOrder === void 0) throw new InternalError({
51
+ message: `Capability "${capability.name}" has migrations for database "${database}" but no migrationOrder.`,
52
+ action: "Set migrationOrder on that database spec (core low, app high)."
53
+ });
54
+ sets.push({
55
+ database,
56
+ namespace: capability.name,
57
+ order: spec.migrationOrder,
58
+ migrations: spec.migrations,
59
+ ...spec.retained && spec.retained.length > 0 ? { retained: spec.retained } : {}
60
+ });
61
+ }
62
+ return sets;
63
+ }
64
+ /**
65
+ * Compose every capability's per-database migration sets (`DatabaseSpec.migrations`,
66
+ * namespaced by capability name) into one ordered provider per database. A database
67
+ * nobody migrates gets no provider; migrations without a `migrationOrder` fail here,
68
+ * attributed to their capability.
69
+ */
70
+ function buildRegistryFromCapabilities(capabilities) {
71
+ return createMigrationRegistry(collectMigrationSets(capabilities));
72
+ }
73
+ //#endregion
74
+ export { buildRegistryFromCapabilities, collectMigrationSets };
@@ -0,0 +1,140 @@
1
+ // SPDX-FileCopyrightText: 2026 Pithy
2
+ // SPDX-License-Identifier: MIT
3
+ import type { D1Database } from "@cloudflare/workers-types";
4
+ import { z } from "zod";
5
+ /**
6
+ * **Which run applied each migration — the group a rollback names (#694).**
7
+ *
8
+ * `pithy migrate --rollback` used to step back one migration in every database the environment binds, and
9
+ * nothing recorded what a single run had applied. So reversing a deploy that moved three migrations was
10
+ * three invocations and the count came from outside the tool — a human's memory, or a CI log read under
11
+ * pressure. Every run belongs to a group now: the caller's own `--group <value>`, or a generated ISO-8601
12
+ * timestamp, recorded here against every migration the run applies, in every database it touches.
13
+ *
14
+ * **It cannot live in the ledger.** `pithy_migrations` is Kysely's own table, renamed off its default
15
+ * (`./bookkeeping`); Kysely creates it and its insert sets `name` and `timestamp` only. So the group sits
16
+ * in a table *beside* it, written by the runner from the `MigrationResult[]` Kysely hands back — the same
17
+ * placement, and the same reasoning, as `pithy_migrations_owner`: it is not a migration, so no capability
18
+ * ships it, `--rollback` cannot step it back, and `pithy seed --redo`'s full reset cannot wipe it. What a
19
+ * reversal removes is the reversed migrations' own rows, which is bookkeeping catching up with the ledger.
20
+ *
21
+ * **The rows say which run; the ledger says which order.** Every applied migration is recorded here as it
22
+ * applies and forgotten as it is reversed, so these rows are the membership. Where a group *sits* is a
23
+ * question about the ledger, though, because the ledger is what Kysely steps down from — so {@link
24
+ * readGroupPosition} reads both (`appliedMigrationChain`) and compares the group against the chain's tail.
25
+ * Reading the group table alone would answer from the order this table happened to be written in, and the
26
+ * two differ in exactly the cases that matter: a migration applied with no group row at all.
27
+ *
28
+ * **What it cannot see, it names.** A migration applied before this table existed carries no row, and so
29
+ * does one a `seed --redo` reset reapplied or one whose group write failed. Such a migration over a group
30
+ * buries it — reversing the group would reverse a migration nobody recorded — and the position says so by
31
+ * name rather than calling the group reversible. Reading is cheap and additive: one group row per applied
32
+ * migration, and the table is created on the first run that applies anything.
33
+ */
34
+ /** One applied migration and the run that applied it. The three columns are the whole table. */
35
+ export declare const MigrationGroupRecord: z.ZodObject<{
36
+ groupKey: z.ZodString;
37
+ migration: z.ZodString;
38
+ appliedAt: z.ZodCodec<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodDate]>, z.ZodDate>;
39
+ }, z.core.$strip>;
40
+ export type MigrationGroupRecord = z.output<typeof MigrationGroupRecord>;
41
+ /** One group as it stands in one database: what it applied here, and when it last did. */
42
+ export interface MigrationGroup {
43
+ /** The group's value — what `--rollback --group` takes back. */
44
+ group: string;
45
+ /**
46
+ * When this group last applied something here. A group extended by a retry carries the later moment,
47
+ * because that is the one that decides which group is newest.
48
+ */
49
+ appliedAt: Date;
50
+ /** The migrations this group applied in this database, in the order they were applied. */
51
+ migrations: string[];
52
+ }
53
+ /**
54
+ * Where a group sits in one database's chain — the question a rollback asks before it reverses anything.
55
+ *
56
+ * Three states, kept apart because they are three different answers. `absent` is *this database applied
57
+ * nothing under that group*, which for a group spanning two databases is ordinary and not a refusal.
58
+ * `buried` is the refusal: Kysely steps down from the tip, so reversing it would mean reversing the
59
+ * migrations over it, from groups nobody named.
60
+ */
61
+ export type GroupPosition = {
62
+ state: "absent";
63
+ } | {
64
+ /** The group's migrations are the top of this database's chain. */
65
+ state: "top";
66
+ /** Them, in the order they will be reversed — newest first. */
67
+ migrations: string[];
68
+ } | {
69
+ /** Something else sits over the group, or inside it. */
70
+ state: "buried";
71
+ /**
72
+ * The groups in the way, newest first: applied over its newest migration, or inside it by a run that
73
+ * came between two of its own. A group extended after another ran names that one.
74
+ */
75
+ above: string[];
76
+ /**
77
+ * The migrations in the way that no group claims, newest first — an older kit's, a reset's re-apply, or
78
+ * a run whose group write failed. They bury the group as surely as another group does, and nothing can
79
+ * be reversed by group while one of them is at the tip.
80
+ */
81
+ ungrouped: string[];
82
+ /**
83
+ * The group whose own migrations *are* the contiguous tip here, when there is one — the only group a
84
+ * refusal may name as reversible. Absent when the tip is interleaved or ungrouped, which is the state
85
+ * where naming anything would print a command that refuses in its turn.
86
+ */
87
+ top?: string;
88
+ };
89
+ /** What {@link recordMigrationGroup} writes: the group, what it applied, and when. */
90
+ export interface RecordGroupOptions {
91
+ /** The group every migration in this call was applied under. */
92
+ group: string;
93
+ /** The migrations applied, in application order. Empty writes nothing at all. */
94
+ migrations: readonly string[];
95
+ /** When they applied. Defaults to now; passed explicitly by tests and by a caller that stamps a run. */
96
+ at?: Date;
97
+ }
98
+ /**
99
+ * The group a run with no `--group` belongs to: an **ISO-8601 timestamp**, `2026-10-03T19:52:47.611Z`.
100
+ *
101
+ * A timestamp rather than a date, because one run is one group. Date-only would silently merge two
102
+ * unrelated runs on a busy day into one group, and reversing it would then undo more than the caller did.
103
+ * The precision costs nothing, it sorts lexicographically into chronological order, and it tells an
104
+ * operator *when* without their having named anything.
105
+ */
106
+ export declare function generatedMigrationGroup(now?: Date): string;
107
+ /**
108
+ * Record a group against the migrations a run just applied, creating the table on demand. Idempotent in
109
+ * the only sense that matters: a migration applies once, so a name arrives here once — and a second call
110
+ * under the same group **extends** it, which is the retry case a release whose migrate half-failed needs.
111
+ */
112
+ export declare function recordMigrationGroup(database: D1Database, options: RecordGroupOptions): Promise<void>;
113
+ /**
114
+ * Every group this database records, oldest first by when each last applied something — and so the last
115
+ * entry is the newest group, which is what a rollback with no `--group` names. Empty for a database
116
+ * nothing has grouped, and reading creates nothing.
117
+ */
118
+ export declare function readMigrationGroups(database: D1Database): Promise<MigrationGroup[]>;
119
+ /**
120
+ * Where `group` sits in this database's chain — see {@link GroupPosition}.
121
+ *
122
+ * The test is *is this group the tail of the **ledger***, not *is it the newest by timestamp*: a group
123
+ * extended after another run has the later timestamp and still has that run's migration inside it, so
124
+ * reversing it would reverse the other group's work. Hence the two halves of one rule — nothing applied
125
+ * over the group's newest migration, and nothing applied inside it between two of its own.
126
+ *
127
+ * **Against the ledger, because the ledger is what comes down.** `migrateDown()` steps the ledger's tip,
128
+ * so a group whose rows are the tail of the *group table* is still buried when an ungrouped migration sits
129
+ * over it in the ledger — and that state is reachable from the ordinary dev loop, where `seed --redo`'s
130
+ * reset reapplies a pending migration under no group at all. Asked of the group table alone, this returned
131
+ * `top`, the `down` reversed a migration nobody asked about, and the refusal arrived after the damage.
132
+ */
133
+ export declare function readGroupPosition(database: D1Database, group: string): Promise<GroupPosition>;
134
+ /**
135
+ * Forget the group rows of migrations that are no longer applied — what a reversal writes once the `down`
136
+ * has run. By migration name alone, because the ledger's name is unique: one applied migration, one row.
137
+ * A database with no group table has nothing to forget.
138
+ */
139
+ export declare function forgetMigrationGroups(database: D1Database, migrations: readonly string[]): Promise<void>;
140
+ //# sourceMappingURL=groups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../../src/migrations/groups.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAG5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;;;;;;;;;;;;;;;;;;;;;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